Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * vision_master.h - FireVision Vision Master 00004 * 00005 * Created: Wed May 30 10:28:06 2007 00006 * Copyright 2006-2009 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __FIREVISION_FVUTILS_BASE_VISION_MASTER_H_ 00025 #define __FIREVISION_FVUTILS_BASE_VISION_MASTER_H_ 00026 00027 #include <fvutils/color/colorspaces.h> 00028 #include <fvcams/control/control.h> 00029 #include <core/utils/refptr.h> 00030 #include <core/exceptions/software.h> 00031 00032 #include <typeinfo> 00033 00034 namespace fawkes { 00035 class Thread; 00036 class TypeMismatchException; 00037 } 00038 00039 namespace firevision { 00040 #if 0 /* just to make Emacs auto-indent happy */ 00041 } 00042 #endif 00043 00044 class Camera; 00045 00046 class VisionMaster 00047 { 00048 public: 00049 virtual ~VisionMaster(); 00050 00051 virtual Camera * register_for_camera(const char *camera_string, 00052 fawkes::Thread *thread, 00053 colorspace_t cspace = YUV422_PLANAR) = 0; 00054 virtual Camera * register_for_raw_camera(const char *camera_string, 00055 fawkes::Thread *thread) = 0; 00056 virtual void unregister_thread(fawkes::Thread *thread) = 0; 00057 00058 virtual CameraControl *acquire_camctrl(const char *cam_string) = 0; 00059 virtual void release_camctrl(CameraControl *cc) = 0; 00060 00061 00062 /** Retrieve a typed camera control instance. 00063 * Like the non-template method this class will try to instantiate the camera 00064 * control based on the camera string (see there for details on the two possible 00065 * contents of the string). The camera control will be verified to be of the 00066 * desired type. 00067 * @param camera_string camera string of camera for the control or the argument 00068 * string for a new instance. See documentation of non-template method. 00069 * @return typed camera control instance 00070 * @exception TypeMismatchException thrown if requested camera control does not 00071 * match the requested type. 00072 */ 00073 template <class CC> 00074 CC * 00075 acquire_camctrl(const char *camera_string); 00076 00077 /** Retrieve a typed camera control instance. 00078 * Like the non-template method this class will try to instantiate the camera 00079 * control based on the camera string (see there for details on the two possible 00080 * contents of the string). The camera control will be verified to be of the 00081 * desired type. 00082 * Unlike the other template method you do not need to explicitly state the type 00083 * of the requested type as it is inferred based on the \p cc argument. You can 00084 * write something like this: 00085 * @code 00086 * CameraControlImage *cci = vision_master->acquire_camctrl("camstring...", cci); 00087 * @endcode 00088 * instead of 00089 * @code 00090 * CameraControlImage *cci = vision_master->acquire_camctrl<CameraControlImage>("camstring..."); 00091 * @endcode 00092 * @param camera_string camera string of camera for the control or the argument 00093 * string for a new instance. See documentation of non-template method. 00094 * @param cc reference to pointer of camera control of the intended type, used 00095 * to automatically infer the template method. On successful return points to 00096 * the camera control instance 00097 * @return typed camera control instance (same as \p cc) 00098 * @exception TypeMismatchException thrown if requested camera control does not 00099 * match the requested type. 00100 */ 00101 template <class CC> 00102 CC * 00103 acquire_camctrl(const char *camera_string, CC *&cc); 00104 00105 00106 /** Get typed raw camera. 00107 * Like the non-template variant this method can be used to get access to 00108 * the raw camera implementation, without going through a proxy. See the other 00109 * method for risks and implication of using the raw device. 00110 * @param camera_string camera that can be used by CameraFactory to open a 00111 * camera. 00112 * @param thread thread to register for this camera 00113 * @return typed raw camera 00114 */ 00115 template <class CC> 00116 CC * 00117 register_for_raw_camera(const char *camera_string, fawkes::Thread *thread); 00118 00119 00120 protected: 00121 virtual CameraControl *acquire_camctrl(const char *cam_string, 00122 const std::type_info &typeinf) = 0; 00123 00124 }; 00125 00126 template <class CC> 00127 CC * 00128 VisionMaster::acquire_camctrl(const char *camera_string, CC *&cc) 00129 { 00130 const std::type_info &t = typeid(CC); 00131 CameraControl *pcc = acquire_camctrl(camera_string, t); 00132 CC *tcc = dynamic_cast<CC *>(pcc); 00133 if (tcc) { 00134 if (cc) cc = tcc; 00135 return tcc; 00136 } else { 00137 release_camctrl(tcc); 00138 throw fawkes::TypeMismatchException("CameraControl defined by string does " 00139 "not match desired type"); 00140 } 00141 } 00142 00143 00144 template <class CC> 00145 CC * 00146 VisionMaster::acquire_camctrl(const char *camera_string) 00147 { 00148 const std::type_info &t = typeid(CC); 00149 CameraControl *pcc = acquire_camctrl(camera_string, t); 00150 CC *tcc = dynamic_cast<CC *>(pcc); 00151 if (tcc) { 00152 return tcc; 00153 } else { 00154 release_camctrl(tcc); 00155 throw fawkes::TypeMismatchException("CameraControl defined by string does " 00156 "not match desired type"); 00157 } 00158 } 00159 00160 template <class CC> 00161 CC * 00162 VisionMaster::register_for_raw_camera(const char *camera_string, fawkes::Thread *thread) 00163 { 00164 Camera *camera = register_for_raw_camera(camera_string, thread); 00165 CC *tcc = dynamic_cast<CC *>(camera); 00166 if (tcc) { 00167 return tcc; 00168 } else { 00169 unregister_thread(thread); 00170 throw fawkes::TypeMismatchException("Camera defined by string does " 00171 "not match desired type"); 00172 } 00173 } 00174 00175 } // end namespace firevision 00176 00177 #endif