Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * factory.cpp - Camera factory 00004 * 00005 * Created: Wed Apr 11 15:37:45 2007 00006 * Copyright 2005-2007 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/factory.h> 00025 #include <fvutils/system/camargp.h> 00026 00027 #ifdef HAVE_FIREWIRE_CAM 00028 #include <fvcams/firewire.h> 00029 #endif 00030 #ifdef HAVE_LEUTRON_CAM 00031 #include <fvcams/leutron.h> 00032 #endif 00033 #ifdef HAVE_FILELOADER_CAM 00034 #include <fvcams/fileloader.h> 00035 #endif 00036 #ifdef HAVE_SHMEM_CAM 00037 #include <fvcams/shmem.h> 00038 #endif 00039 #ifdef HAVE_NETWORK_CAM 00040 #include <fvcams/net.h> 00041 #endif 00042 #ifdef HAVE_V4L_CAM 00043 #include <fvcams/v4l.h> 00044 #endif 00045 #ifdef HAVE_V4L1_CAM 00046 #include <fvcams/v4l1.h> 00047 #endif 00048 #ifdef HAVE_V4L2_CAM 00049 #include <fvcams/v4l2.h> 00050 #endif 00051 #ifdef HAVE_NAO_CAM 00052 #include <fvcams/nao.h> 00053 #endif 00054 #ifdef HAVE_BUMBLEBEE2_CAM 00055 #include <fvcams/bumblebee2.h> 00056 #endif 00057 #ifdef HAVE_SWISSRANGER_CAM 00058 #include <fvcams/swissranger.h> 00059 #endif 00060 #ifdef HAVE_PIKE_CAM 00061 #include <fvcams/pike.h> 00062 #endif 00063 #ifdef HAVE_KINECT_CAM 00064 #include <fvcams/kinect.h> 00065 #endif 00066 00067 using namespace std; 00068 00069 namespace firevision { 00070 #if 0 /* just to make Emacs auto-indent happy */ 00071 } 00072 #endif 00073 00074 /** @class CameraFactory <fvcams/factory.h> 00075 * Camera factory. 00076 * This camera factory provides access to all cameras in a unified way. You just 00077 * supply a camera argument string and depending on the camera ID and compile-time 00078 * support of camera types an instance of the desired camera is returned or otherwise 00079 * an exception is thrown. See instance() for a list of supported camera types. 00080 * 00081 * @author Tim Niemueller 00082 */ 00083 00084 /** Get camera instance with parameters from given camera argument parser. 00085 * This is a convenience method and works like instace(const char *as). 00086 * @param cap camera argument parser 00087 * @return camera instance 00088 * @exception UnknownCameraTypeException thrown if camera type is not known or 00089 * was not available at build time. 00090 */ 00091 Camera * 00092 CameraFactory::instance(const CameraArgumentParser *cap) 00093 { 00094 Camera *c = NULL; 00095 00096 // ###### 00097 if ( cap->cam_type() == "firewire" ) { 00098 #ifdef HAVE_FIREWIRE_CAM 00099 c = new FirewireCamera(cap); 00100 #else 00101 throw UnknownCameraTypeException("No firewire support at compile time"); 00102 #endif 00103 } 00104 00105 // ###### 00106 if ( cap->cam_type() == "leutron" ) { 00107 #ifdef HAVE_LEUTRON_CAM 00108 c = new LeutronCamera(); 00109 #else 00110 throw UnknownCameraTypeException("No Leutron support at compile time"); 00111 #endif 00112 } 00113 00114 // ###### 00115 if ( cap->cam_type() == "file" ) { 00116 #ifdef HAVE_FILELOADER_CAM 00117 c = new FileLoader(cap); 00118 #else 00119 throw UnknownCameraTypeException("No file loader support at compile time"); 00120 #endif 00121 } 00122 00123 // ###### 00124 if ( cap->cam_type() == "shmem" ) { 00125 #ifdef HAVE_SHMEM_CAM 00126 c = new SharedMemoryCamera(cap); 00127 #else 00128 throw UnknownCameraTypeException("No shared memory support at compile time"); 00129 #endif 00130 } 00131 00132 // ###### 00133 if ( cap->cam_type() == "net" ) { 00134 #ifdef HAVE_NETWORK_CAM 00135 c = new NetworkCamera(cap); 00136 #else 00137 throw UnknownCameraTypeException("No network support at compile time"); 00138 #endif 00139 } 00140 00141 // ###### 00142 if ( cap->cam_type() == "v4l" ) { 00143 #ifdef HAVE_V4L_CAM 00144 c = new V4LCamera(cap); 00145 #else 00146 throw UnknownCameraTypeException("No video4linux support at compile time"); 00147 #endif 00148 } 00149 00150 // ###### 00151 if ( cap->cam_type() == "v4l1" ) { 00152 #ifdef HAVE_V4L1_CAM 00153 c = new V4L1Camera(cap); 00154 #else 00155 throw UnknownCameraTypeException("No video4linux1 support at compile time"); 00156 #endif 00157 } 00158 00159 // ###### 00160 if ( cap->cam_type() == "v4l2" ) { 00161 #ifdef HAVE_V4L2_CAM 00162 c = new V4L2Camera(cap); 00163 #else 00164 throw UnknownCameraTypeException("No video4linux2 support at compile time"); 00165 #endif 00166 } 00167 00168 // ###### 00169 if ( cap->cam_type() == "nao" ) { 00170 #ifdef HAVE_NAO_CAM 00171 c = new NaoCamera(cap); 00172 #else 00173 throw UnknownCameraTypeException("No nao camera support at compile time"); 00174 #endif 00175 } 00176 00177 // ###### 00178 if ( cap->cam_type() == "bumblebee2" ) { 00179 #ifdef HAVE_BUMBLEBEE2_CAM 00180 c = new Bumblebee2Camera(cap); 00181 #else 00182 throw UnknownCameraTypeException("No Bumblebee 2 support at compile time"); 00183 #endif 00184 } 00185 00186 // ###### 00187 if ( cap->cam_type() == "swissranger" ) { 00188 #ifdef HAVE_SWISSRANGER_CAM 00189 c = new SwissRangerCamera(cap); 00190 #else 00191 throw UnknownCameraTypeException("No SwissRanger support at compile time"); 00192 #endif 00193 } 00194 00195 // ###### 00196 if ( cap->cam_type() == "pike" ) { 00197 #ifdef HAVE_PIKE_CAM 00198 c = new PikeCamera(cap); 00199 #else 00200 throw UnknownCameraTypeException("No Bumblebee 2 support at compile time"); 00201 #endif 00202 } 00203 00204 // ###### 00205 if ( cap->cam_type() == "kinect" ) { 00206 #ifdef HAVE_KINECT_CAM 00207 c = new KinectCamera(cap); 00208 #else 00209 throw UnknownCameraTypeException("No Kinect support at compile time"); 00210 #endif 00211 } 00212 00213 if ( c == NULL ) { 00214 throw UnknownCameraTypeException(); 00215 } 00216 00217 return c; 00218 } 00219 00220 00221 /** Get camera instance. 00222 * Get an instance of a camera of the given type. The argument string determines 00223 * the type of camera to open. 00224 * Supported camera types: 00225 * - firewire, FirewireCamera, compiled if HAVE_FIREWIRE_CAM is defined in fvconf.mk 00226 * - leutron, LeutronCamera, compiled if HAVE_LEUTRON_CAM is defined in fvconf.mk 00227 * - file, FileLoader, compiled if HAVE_FILELOADER_CAM is defined in fvconf.mk 00228 * - shmem, SharedMemoryCamera, compiled if HAVE_SHMEM_CAM is defined in fvconf.mk 00229 * - net, NetworkCamera, compiled if HAVE_NETWORK_CAM is defined in fvconf.mk 00230 * - v4l, V4LCamera, compiled if HAVE_V4L_CAM is defined in fvconf.mk 00231 * @param as camera argument string 00232 * @return camera instance of requested type 00233 * @exception UnknownCameraTypeException thrown, if the desired camera could 00234 * not be instantiated. This could be either to a misspelled camera ID, generally 00235 * missing support or unset definition due to configuration in fvconf.mk or missing 00236 * libraries and camera support compile-time autodetection. 00237 */ 00238 Camera * 00239 CameraFactory::instance(const char *as) 00240 { 00241 CameraArgumentParser *cap = new CameraArgumentParser(as); 00242 try { 00243 Camera *cam = instance(cap); 00244 delete cap; 00245 return cam; 00246 } catch (UnknownCameraTypeException &e) { 00247 delete cap; 00248 throw; 00249 } 00250 } 00251 00252 } // end namespace firevision