Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * factory.cpp - Camera control factory 00004 * 00005 * Created: Fri Jun 15 13:11:28 2007 00006 * Copyright 2005-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 #include <fvcams/control/factory.h> 00025 #include <fvutils/system/camargp.h> 00026 #include <core/exceptions/software.h> 00027 00028 #include <fvcams/control/color.h> 00029 #include <fvcams/control/image.h> 00030 #include <fvcams/control/effect.h> 00031 #include <fvcams/control/focus.h> 00032 #include <fvcams/control/pantilt.h> 00033 #include <fvcams/control/zoom.h> 00034 #include <fvcams/control/source.h> 00035 #include <fvcams/control/dummy.h> 00036 #include <fvcams/cam_exceptions.h> 00037 00038 #ifdef HAVE_VISCA_CTRL 00039 #include <fvcams/control/visca.h> 00040 #endif 00041 #ifdef HAVE_EVID100P_CTRL 00042 #include <fvcams/control/sony_evid100p.h> 00043 #endif 00044 #ifdef HAVE_DPPTU_CTRL 00045 #include <fvcams/control/dp_ptu.h> 00046 #endif 00047 00048 #include <typeinfo> 00049 00050 using namespace std; 00051 00052 namespace firevision { 00053 #if 0 /* just to make Emacs auto-indent happy */ 00054 } 00055 #endif 00056 00057 /** @class CameraControlFactory <fvcams/control/factory.h> 00058 * Camera control factory. 00059 * This camera control factory provides access to all camera controls in a unified way. 00060 * You just supply a camera argument string and depending on the camera ID and compile-time 00061 * support of camera control types an instance of the desired camera control is 00062 * returned or otherwise an exception is thrown. See instance() for a list of 00063 * supported camera control types. 00064 * 00065 * @author Tim Niemueller 00066 */ 00067 00068 /** Get camera control instance with parameters from given camera argument parser. 00069 * This is a convenience method and works like instace(const char *as). 00070 * @param cap camera argument parser 00071 * @return camera instance 00072 * @exception UnknownCameraControlTypeException thrown if camera type is not known or 00073 * was not available at build time. 00074 */ 00075 CameraControl * 00076 CameraControlFactory::instance(const CameraArgumentParser *cap) 00077 { 00078 CameraControl *c = NULL; 00079 00080 // ###### 00081 if ( cap->cam_type() == "evid100p" ) { 00082 #ifdef HAVE_EVID100P_CTRL 00083 c = new SonyEviD100PControl(cap); 00084 #else 00085 throw UnknownCameraControlTypeException("No EviD100P/Visca support at compile time"); 00086 #endif 00087 } 00088 00089 // ###### 00090 if ( cap->cam_type() == "dpptu" ) { 00091 #ifdef HAVE_DPPTU_CTRL 00092 c = new DPPTUControl(cap); 00093 #else 00094 throw UnknownCameraControlTypeException("No DPPTU support at compile time"); 00095 #endif 00096 } 00097 00098 // ###### 00099 if ( cap->cam_type() == "dummy" ) { 00100 c = new DummyCameraControl(); 00101 } 00102 00103 if ( c == NULL ) { 00104 throw UnknownCameraControlTypeException(); 00105 } 00106 00107 return c; 00108 } 00109 00110 00111 /** Get camera control instance. 00112 * Get an instance of a camera of the given type. The argument string determines 00113 * the type of camera to open. 00114 * Supported camera types: 00115 * - evid100p, SonyEviD100PControl, compiled if HAVE_EVID100P_CTRL is defined in fvconf.mk 00116 * - dpptu, DPPTUControl, compiled if HAVE_DPPTU_CTRL is defined in fvconf.mk 00117 * @param as camera argument string 00118 * @return camera control instance of requested type 00119 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could 00120 * not be instantiated. This could be either to a misspelled camera ID, generally 00121 * missing support or unset definition due to configuration in fvconf.mk or missing 00122 * libraries and camera support compile-time autodetection. 00123 */ 00124 CameraControl * 00125 CameraControlFactory::instance(const char *as) 00126 { 00127 CameraArgumentParser *cap = new CameraArgumentParser(as); 00128 try { 00129 return instance(cap); 00130 } catch (UnknownCameraControlTypeException &e) { 00131 throw; 00132 } 00133 } 00134 00135 00136 /** Get camera control instance. 00137 * Get an instance of a camera control from the passed camera. 00138 * It is tried to cast the camera to the appropriate camera control type. If that 00139 * succeeds the camera control is returned, otherwise an exception is thrown. 00140 * @param camera camera to cast 00141 * @return camera control instance. 00142 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could 00143 * not be instantiated. This could be either to a misspelled camera ID, generally 00144 * missing support or unset definition due to configuration in fvconf.mk or missing 00145 * libraries and camera support compile-time autodetection. 00146 */ 00147 CameraControl * 00148 CameraControlFactory::instance(Camera *camera) 00149 { 00150 CameraControl *c = dynamic_cast<CameraControl *>(camera); 00151 if (c) { 00152 return c; 00153 } else { 00154 throw fawkes::TypeMismatchException("Camera does not provide requested camera control"); 00155 } 00156 } 00157 00158 00159 /** Get camera control instance. 00160 * Get an instance of a camera of the given type based on the given camera. 00161 * It is tried to cast the camera to the appropriate camera control type. If that 00162 * succeeds the camera control is returned, otherwise an exception is thrown. 00163 * @param typeinf type info for the intended type of the camera control 00164 * @param camera camera to cast 00165 * @return camera control instance of requested type 00166 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could 00167 * not be instantiated. This could be either to a misspelled camera ID, generally 00168 * missing support or unset definition due to configuration in fvconf.mk or missing 00169 * libraries and camera support compile-time autodetection. 00170 */ 00171 CameraControl * 00172 CameraControlFactory::instance(const std::type_info &typeinf, Camera *camera) 00173 { 00174 CameraControl *c = NULL; 00175 00176 if (typeid(CameraControlColor) == typeinf) { 00177 c = dynamic_cast<CameraControlColor *>(camera); 00178 00179 } else if (typeid(CameraControlImage) == typeinf) { 00180 c = dynamic_cast<CameraControlImage *>(camera); 00181 00182 } else if (typeid(CameraControlPanTilt) == typeinf) { 00183 c = dynamic_cast<CameraControlPanTilt *>(camera); 00184 00185 } else if (typeid(CameraControlFocus) == typeinf) { 00186 c = dynamic_cast<CameraControlFocus *>(camera); 00187 00188 } else if (typeid(CameraControlZoom) == typeinf) { 00189 c = dynamic_cast<CameraControlZoom *>(camera); 00190 00191 } else if (typeid(CameraControlEffect) == typeinf) { 00192 c = dynamic_cast<CameraControlEffect *>(camera); 00193 00194 } else if (typeid(CameraControlSource) == typeinf) { 00195 c = dynamic_cast<CameraControlSource *>(camera); 00196 00197 } else { 00198 throw UnknownCameraControlTypeException(); 00199 } 00200 00201 if (c) { 00202 return c; 00203 } else { 00204 throw fawkes::TypeMismatchException("Camera does not provide requested camera control"); 00205 } 00206 } 00207 00208 } // end namespace firevision