Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GenericGrabber.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLIO/src/ICLIO/GenericGrabber.h                       **
00010 ** Module : ICLIO                                                  **
00011 ** Authors: Christof Elbrechter, Viktor Richter                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/Macros.h>
00034 #include <ICLUtils/Exception.h>
00035 #include <ICLUtils/Lockable.h>
00036 #include <ICLUtils/ProgArg.h>
00037 #include <ICLUtils/ConfigurableProxy.h>
00038 #include <ICLIO/Grabber.h>
00039 #include <string>
00040 
00041 namespace icl {
00042   namespace io{
00043 
00045 
00051     class ICLIO_API GenericGrabber : public utils::Uncopyable, public utils::ConfigurableProxy{
00052 
00053         Grabber *m_poGrabber; 
00054 
00055         GrabberDeviceDescription m_poDesc; 
00056 
00057         mutable utils::Mutex m_mutex; 
00058 
00059       public:
00060 
00062 
00063         GenericGrabber(const utils::ProgArg &pa) throw (utils::ICLException):m_poGrabber(0){
00064           init(pa);
00065         }
00066 
00068 
00069         GenericGrabber(const std::string &devicePriorityList,
00070                        const std::string &params,
00071                        bool notifyErrors = true) throw (utils::ICLException):m_poGrabber(0){
00072           init(devicePriorityList,params,notifyErrors);
00073         }
00074 
00075 
00077 
00078         GenericGrabber():m_poGrabber(0){}
00079 
00081 
00162         void init(const std::string &devicePriorityList,
00163                   const std::string &params,
00164                   bool notifyErrors = true) throw (utils::ICLException);
00165 
00167         void init(const utils::ProgArg &pa) throw (utils::ICLException);
00168 
00170         static void resetBus(const std::string &deviceList="dc", bool verbose=false);
00171 
00173         std::string getType() const {
00174           utils::Mutex::Locker __lock(m_mutex);
00175           return m_poDesc.type;
00176         }
00177 
00179         Grabber *getGrabber() const {
00180           utils::Mutex::Locker __lock(m_mutex);
00181           return m_poGrabber;
00182         }
00183 
00185         virtual ~GenericGrabber();
00186 
00188 
00189         const core::ImgBase *grab(core::ImgBase **dst = 0){
00190           utils::Mutex::Locker __lock(m_mutex);
00191           ICLASSERT_RETURN_VAL(!isNull(), 0);
00192 
00193           return m_poGrabber->grab(dst);
00194         }
00195 
00197         bool isNull() const { return m_poGrabber == 0; }
00198 
00200         operator bool() const { return !isNull(); }
00201 
00202 
00204         void setDesiredFormatInternal(core::format fmt){
00205           ICLASSERT_RETURN(!isNull());
00206           utils::Mutex::Locker l(m_mutex);
00207           m_poGrabber->setDesiredFormatInternal(fmt);
00208         }
00209 
00211         void setDesiredSizeInternal(const utils::Size &size){
00212           ICLASSERT_RETURN(!isNull());
00213           utils::Mutex::Locker l(m_mutex);
00214           m_poGrabber->setDesiredSizeInternal(size);
00215         }
00216 
00218         void setDesiredDepthInternal(core::depth d){
00219           ICLASSERT_RETURN(!isNull());
00220           utils::Mutex::Locker l(m_mutex);
00221           m_poGrabber->setDesiredDepthInternal(d);
00222         }
00223 
00225         core::format getDesiredFormatInternal() const{
00226           ICLASSERT_RETURN_VAL(!isNull(),(core::format)-1);
00227           utils::Mutex::Locker l(m_mutex);
00228           return m_poGrabber->getDesiredFormatInternal();
00229         }
00230 
00232         core::depth getDesiredDepthInternal() const{
00233           ICLASSERT_RETURN_VAL(!isNull(),(core::depth)-1);
00234           utils::Mutex::Locker l(m_mutex);
00235           return m_poGrabber->getDesiredDepthInternal();
00236         }
00237 
00239         utils::Size getDesiredSizeInternal() const{
00240           ICLASSERT_RETURN_VAL(!isNull(),utils::Size::null);
00241           utils::Mutex::Locker l(m_mutex);
00242           return m_poGrabber->getDesiredSizeInternal();
00243         }
00244 
00246         void registerCallback(Grabber::callback cb){
00247           ICLASSERT_RETURN(!isNull());
00248           utils::Mutex::Locker l(m_mutex);
00249           m_poGrabber->registerCallback(cb);
00250         }
00251 
00253         void removeAllCallbacks(){
00254           ICLASSERT_RETURN(!isNull());
00255           utils::Mutex::Locker l(m_mutex);
00256           m_poGrabber->removeAllCallbacks();
00257         }
00258 
00260 
00261         template<class T>
00262         bool desiredUsed() const{
00263           ICLASSERT_RETURN_VAL(!isNull(),false);
00264           utils::Mutex::Locker l(m_mutex);
00265           return m_poGrabber->desiredUsed<T>();
00266         }
00267 
00269         template<class T>
00270         void useDesired(const T &t){
00271           ICLASSERT_RETURN(!isNull());
00272           utils::Mutex::Locker l(m_mutex);
00273           m_poGrabber->useDesired<T>(t);
00274         }
00275 
00277         void useDesired(core::depth d, const utils::Size &size, core::format fmt){
00278           ICLASSERT_RETURN(!isNull());
00279           utils::Mutex::Locker l(m_mutex);
00280           m_poGrabber->useDesired(d, size, fmt);
00281         }
00282 
00284 
00285         template<class T>
00286         void ignoreDesired() {
00287           ICLASSERT_RETURN(!isNull());
00288           utils::Mutex::Locker l(m_mutex);
00289           m_poGrabber->ignoreDesired<T>();
00290         }
00291 
00293         void ignoreDesired(){
00294           ICLASSERT_RETURN(!isNull());
00295           utils::Mutex::Locker l(m_mutex);
00296           m_poGrabber->ignoreDesired();
00297         }
00298 
00300 
00301         template<class T>
00302         T getDesired() const {
00303           ICLASSERT_RETURN_VAL(!isNull(), T());
00304           utils::Mutex::Locker l(m_mutex);
00305           return m_poGrabber->getDesired<T>();
00306         }
00307 
00309         void enableUndistortion(const std::string &filename){
00310           ICLASSERT_RETURN(!isNull());
00311           utils::Mutex::Locker l(m_mutex);
00312           m_poGrabber->enableUndistortion(filename);
00313         }
00314 
00316         void enableUndistortion(const ImageUndistortion &udist){
00317           ICLASSERT_RETURN(!isNull());
00318           utils::Mutex::Locker l(m_mutex);
00319           m_poGrabber->enableUndistortion(udist);
00320         }
00321 
00323 
00324         void enableUndistortion(const utils::ProgArg &pa){
00325           ICLASSERT_RETURN(!isNull());
00326           utils::Mutex::Locker l(m_mutex);
00327           m_poGrabber->enableUndistortion(pa);
00328         }
00329 
00331         void enableUndistortion(const core::Img32f &warpMap){
00332           ICLASSERT_RETURN(!isNull());
00333           utils::Mutex::Locker l(m_mutex);
00334           m_poGrabber->enableUndistortion(warpMap);
00335         }
00336 
00338 
00341         void setUndistortionInterpolationMode(core::scalemode mode){
00342           ICLASSERT_RETURN(!isNull());
00343           utils::Mutex::Locker l(m_mutex);
00344           m_poGrabber->setUndistortionInterpolationMode(mode);
00345         }
00346 
00348         void disableUndistortion(){
00349           ICLASSERT_RETURN(!isNull());
00350           utils::Mutex::Locker l(m_mutex);
00351           m_poGrabber->disableUndistortion();
00352         }
00353 
00355         bool isUndistortionEnabled() const{
00356           ICLASSERT_RETURN_VAL(!isNull(),false);
00357           utils::Mutex::Locker l(m_mutex);
00358           return m_poGrabber->isUndistortionEnabled();
00359         }
00360 
00362         const core::Img32f *getUndistortionWarpMap() const{
00363           ICLASSERT_RETURN_VAL(!isNull(),0);
00364           utils::Mutex::Locker l(m_mutex);
00365           return m_poGrabber->getUndistortionWarpMap();
00366         }
00367 
00369 
00376         static const std::vector<GrabberDeviceDescription> &getDeviceList(const std::string &filter, bool rescan=true);
00377 
00379 
00380         inline void init(const GrabberDeviceDescription &dev){
00381           init(dev.type,dev.type+"="+dev.id,false);
00382         }
00383     };
00384 
00385   } // namespace io
00386 } 
00387 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines