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