Image Component Library (ICL)
Grabber.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLIO/src/ICLIO/Grabber.h **
10 ** Module : ICLIO **
11 ** Authors: Christof Elbrechter, Michael Goetting, Robert **
12 ** Haschke, Viktor Richter **
13 ** **
14 ** **
15 ** GNU LESSER GENERAL PUBLIC LICENSE **
16 ** This file may be used under the terms of the GNU Lesser General **
17 ** Public License version 3.0 as published by the **
18 ** **
19 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
20 ** included in the packaging of this file. Please review the **
21 ** following information to ensure the license requirements will **
22 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
23 ** **
24 ** The development of this software was supported by the **
25 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
26 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
27 ** Forschungsgemeinschaft (DFG) in the context of the German **
28 ** Excellence Initiative. **
29 ** **
30 ********************************************************************/
31 
32 #pragma once
33 
34 #include <ICLUtils/CompatMacros.h>
35 #include <ICLUtils/SteppingRange.h>
36 #include <ICLUtils/Function.h>
37 #include <ICLUtils/Uncopyable.h>
38 #include <ICLUtils/Configurable.h>
39 #include <ICLUtils/ProgArg.h>
40 #include <ICLUtils/Uncopyable.h>
41 #include <ICLCore/ImgBase.h>
44 
45 #include <string>
46 #include <vector>
47 #include <set>
48 
49 namespace icl {
50  namespace io{
51 
53  namespace{
54  template <class T> inline T grabber_get_null(){ return 0; }
55  template <> inline core::format grabber_get_null<core::format>(){ return (core::format)-1; }
56  template <> inline core::depth grabber_get_null<core::depth>(){ return (core::depth)-1; }
57  template <> inline icl::utils::Size grabber_get_null<icl::utils::Size>(){ return icl::utils::Size::null; }
58 
59  struct grabber_get_xxx_dummy{
60  grabber_get_xxx_dummy(){
61  grabber_get_null<core::format>();
62  grabber_get_null<core::depth>();
63  grabber_get_null<icl::utils::Size>();
64  }
65  };
66  }
67  template <class T> class GrabberHandle;
68  class GenericGrabber;
71 
155  struct Data;
156 
158  Data *data;
159 
160  protected:
162  virtual void setDesiredFormatInternal(core::format fmt);
163 
165  virtual void setDesiredSizeInternal(const utils::Size &size);
166 
168  virtual void setDesiredDepthInternal(core::depth d);
169 
171  virtual core::format getDesiredFormatInternal() const;
172 
174  virtual core::depth getDesiredDepthInternal() const;
175 
177  virtual utils::Size getDesiredSizeInternal() const;
178 
179  public:
180 
182  template<class X> friend class GrabberHandle;
183 
185  friend class GenericGrabber;
186 
188  Grabber();
189 
191  virtual ~Grabber();
192 
194 
195  const core::ImgBase *grab(core::ImgBase **dst=0);
196 
198 
199  template<class T>
200  bool desiredUsed() const{ return false; }
201 
203  template<class T>
204  void useDesired(const T &t){ (void)t;}
205 
207  void useDesired(core::depth d, const utils::Size &size, core::format fmt);
208 
210 
211  template<class T>
212  void ignoreDesired() {
213  useDesired<T>(grabber_get_null<T>());
214  }
215 
217  void ignoreDesired();
218 
220 
221  template<class T>
222  T getDesired() const { return T(); }
223 
226 
228  static std::string translateSteppingRange(const utils::SteppingRange<double>& range);
229 
231  static utils::SteppingRange<double> translateSteppingRange(const std::string &rangeStr);
232 
234  static std::string translateDoubleVec(const std::vector<double> &doubleVec);
235 
237  static std::vector<double> translateDoubleVec(const std::string &doubleVecStr);
238 
240  static std::string translateStringVec(const std::vector<std::string> &stringVec);
241 
243  static std::vector<std::string> translateStringVec(const std::string &stringVecStr);
244 
246 
248 
250  void enableUndistortion(const std::string &filename);
251 
253  void enableUndistortion(const ImageUndistortion &udist);
254 
256 
257  void enableUndistortion(const utils::ProgArg &pa);
258 
260  void enableUndistortion(const core::Img32f &warpMap);
261 
263 
266  void setUndistortionInterpolationMode(core::scalemode mode);
267 
269  void disableUndistortion();
270 
272  bool isUndistortionEnabled() const;
273 
275  const core::Img32f *getUndistortionWarpMap() const;
277 
280 
282 
287  virtual void registerCallback(callback cb);
288 
290  virtual void removeAllCallbacks();
291 
293 
294  virtual void notifyNewImageAvailable(const core::ImgBase *image);
295 
296  protected:
297 
298 
300 
302  virtual const core::ImgBase *acquireImage(){ return NULL; }
303 
305 
306  const core::ImgBase *adaptGrabResult(const core::ImgBase *src, core::ImgBase **dst);
307 
308  private:
310  void processPropertyChange(const utils::Configurable::Property &prop);
311 
312  };
313 
315  template<> inline void Grabber::useDesired<core::format>(const core::format &t) { setDesiredFormatInternal(t); }
316  template<> inline void Grabber::useDesired<core::depth>(const core::depth &t) { setDesiredDepthInternal(t); }
317  template<> inline void Grabber::useDesired<utils::Size>(const utils::Size &t) { setDesiredSizeInternal(t); }
318 
319  template<> inline core::depth Grabber::getDesired<core::depth>() const { return getDesiredDepthInternal(); }
320  template<> inline utils::Size Grabber::getDesired<utils::Size>() const { return getDesiredSizeInternal(); }
321  template<> inline core::format Grabber::getDesired<core::format>() const { return getDesiredFormatInternal(); }
322 
323  template<> inline bool Grabber::desiredUsed<core::format>() const{ return (int)getDesired<core::format>() != -1; }
324  template<> inline bool Grabber::desiredUsed<core::depth>() const{ return (int)getDesired<core::depth>() != -1; }
325  template<> inline bool Grabber::desiredUsed<utils::Size>() const{ return getDesired<utils::Size>() != utils::Size::null; }
326 
327  class ICLIO_API GrabberRegister : utils::Uncopyable {
328  private:
329  utils::Mutex mutex;
330 
331  struct GrabberFunctions{
332  utils::Function<Grabber*,const std::string&> init;
333  utils::Function<const std::vector<GrabberDeviceDescription> &,std::string,bool> list;
334  };
335 
336  // grabber functions map
337  typedef std::map<std::string, GrabberFunctions> GFM;
338  GFM gfm;
339 
340  // grabber bus reset functions map
341  typedef std::map<std::string, utils::Function<void,bool> > GBRM;
342  GBRM gbrm;
343 
344  // grabber device descriptions map
345  typedef std::set<std::string> GDS;
346  GDS gds;
347 
348  // private constructor
349  GrabberRegister(){}
350 
351  public:
352  static GrabberRegister* getInstance();
353 
354  void registerGrabberType(const std::string &grabberid,
355  utils::Function<Grabber *, const std::string &> creator,
356  utils::Function<const std::vector<GrabberDeviceDescription> &,std::string,bool> device_list)
357  ;
358 
359  void registerGrabberBusReset(const std::string &grabberid,
360  utils::Function<void, bool> reset_function)
361  ;
362 
363  void addGrabberDescription(const std::string &grabber_description)
364  ;
365 
366  Grabber* createGrabber(const std::string &grabberid, const std::string &param) ;
367 
368  std::vector<std::string> getRegisteredGrabbers();
369 
370  std::vector<std::string> getGrabberInfos();
371 
372  const std::vector<GrabberDeviceDescription>& getDeviceList(std::string id, std::string hint="", bool rescan=true);
373 
374  void resetGrabberBus(const std::string &id, bool verbose);
375  };
376 
379 
381  #define REGISTER_GRABBER(NAME,CREATE_FUNC,DEVICE_LIST_FUNC,DESCRIPTION) \
382  struct StaticGrabberRegistrationFor_##NAME{ \
383  StaticGrabberRegistrationFor_##NAME(){ \
384  icl::io::GrabberRegister::getInstance() -> registerGrabberType(#NAME, CREATE_FUNC, DEVICE_LIST_FUNC); \
385  icl::io::GrabberRegister::getInstance() -> addGrabberDescription(DESCRIPTION); \
386  } \
387  } staticGrabberRegistrationFor_##NAME;
388 
389  #define REGISTER_GRABBER_BUS_RESET_FUNCTION(NAME,BUS_RESET_FUNC) \
390  struct StaticGrabberBusResetRegistrationFor_##NAME{ \
391  StaticGrabberBusResetRegistrationFor_##NAME(){ \
392  icl::io::GrabberRegister::getInstance() -> registerGrabberBusReset(#NAME, BUS_RESET_FUNC); \
393  } \
394  } staticGrabberBusResetRegistrationFor_##NAME;
395 
396  } // namespace io
397 } // namespace icl
398 
The General Function Template.
Definition: Function.h:284
void useDesired(const T &t)
sets desired parameters (only available for core::depth,utils::Size and core::format)
Definition: Grabber.h:204
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
static const Size null
null is w=0, h=0
Definition: Size.h:64
virtual const core::ImgBase * acquireImage()
main interface method, that is implemented by the actual grabber instances
Definition: Grabber.h:302
utils::Function< void, const core::ImgBase * > callback
new image callback type
Definition: Grabber.h:279
format
determines the color-format, that is associated with the images channels
Definition: Types.h:70
bool desiredUsed() const
returns whether the desired parameter for the given type is used
Definition: Grabber.h:200
T getDesired() const
returns the desired value for the given type T
Definition: Grabber.h:222
class representing a range with defined stepping
Definition: SteppingRange.h:46
const ProgArg pa(const std::string &id, unsigned int subargidx=0)
returns given program argument
Definition: ProgArg.h:304
#define ICLIO_API
Definition: CompatMacros.h:176
Common interface class for all grabbers.
Definition: Grabber.h:153
Size class of the ICL.
Definition: Size.h:61
Programm argument utility class.
Definition: ProgArg.h:80
scalemode
for scaling of Img images theses functions are provided
Definition: Types.h:84
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
void ignoreDesired()
set the grabber to ignore the desired param of type T
Definition: Grabber.h:212
Interface for classes that can be configured from configuration-files and GUI-Components.
Definition: Configurable.h:194
ICLQt_API core::Img< T > grab(const std::string &dev, const std::string &devSpec, const utils::Size &size=utils::Size::null, core::format fmt=core::formatRGB, bool releaseGrabber=false)
grabs a new image from given device (affinity for floats)
Common interface class for all grabbers.
Definition: GenericGrabber.h:55
Data * data
hidden data
Definition: Grabber.h:155
Represents a single property.
Definition: Configurable.h:200
Definition: ImageUndistortion.h:39
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131