Fawkes API Fawkes Development Version
factory.cpp
1
2/***************************************************************************
3 * factory.cpp - Camera factory
4 *
5 * Created: Wed Apr 11 15:37:45 2007
6 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <fvcams/factory.h>
25#include <fvutils/system/camargp.h>
26
27#ifdef HAVE_FIREWIRE_CAM
28# include <fvcams/firewire.h>
29#endif
30#ifdef HAVE_LEUTRON_CAM
31# include <fvcams/leutron.h>
32#endif
33#ifdef HAVE_FILELOADER_CAM
34# include <fvcams/fileloader.h>
35#endif
36#ifdef HAVE_SHMEM_CAM
37# include <fvcams/shmem.h>
38#endif
39#ifdef HAVE_NETWORK_CAM
40# include <fvcams/net.h>
41#endif
42#ifdef HAVE_V4L_CAM
43# include <fvcams/v4l.h>
44#endif
45#ifdef HAVE_V4L1_CAM
46# include <fvcams/v4l1.h>
47#endif
48#ifdef HAVE_V4L2_CAM
49# include <fvcams/v4l2.h>
50#endif
51#ifdef HAVE_NAO_CAM
52# include <fvcams/nao.h>
53#endif
54#ifdef HAVE_BUMBLEBEE2_CAM
55# include <fvcams/bumblebee2.h>
56#endif
57#ifdef HAVE_PIKE_CAM
58# include <fvcams/pike.h>
59#endif
60#ifdef HAVE_KINECT_CAM
61# include <fvcams/kinect.h>
62#endif
63
64using namespace std;
65
66namespace firevision {
67
68/** @class CameraFactory <fvcams/factory.h>
69 * Camera factory.
70 * This camera factory provides access to all cameras in a unified way. You just
71 * supply a camera argument string and depending on the camera ID and compile-time
72 * support of camera types an instance of the desired camera is returned or otherwise
73 * an exception is thrown. See instance() for a list of supported camera types.
74 *
75 * @author Tim Niemueller
76 */
77
78/** Get camera instance with parameters from given camera argument parser.
79 * This is a convenience method and works like instace(const char *as).
80 * @param cap camera argument parser
81 * @return camera instance
82 * @exception UnknownCameraTypeException thrown if camera type is not known or
83 * was not available at build time.
84 */
85Camera *
87{
88 Camera *c = NULL;
89
90 // ######
91 if (cap->cam_type() == "firewire") {
92#ifdef HAVE_FIREWIRE_CAM
93 c = new FirewireCamera(cap);
94#else
95 throw UnknownCameraTypeException("No firewire support at compile time");
96#endif
97 }
98
99 // ######
100 if (cap->cam_type() == "leutron") {
101#ifdef HAVE_LEUTRON_CAM
102 c = new LeutronCamera();
103#else
104 throw UnknownCameraTypeException("No Leutron support at compile time");
105#endif
106 }
107
108 // ######
109 if (cap->cam_type() == "file") {
110#ifdef HAVE_FILELOADER_CAM
111 c = new FileLoader(cap);
112#else
113 throw UnknownCameraTypeException("No file loader support at compile time");
114#endif
115 }
116
117 // ######
118 if (cap->cam_type() == "shmem") {
119#ifdef HAVE_SHMEM_CAM
120 c = new SharedMemoryCamera(cap);
121#else
122 throw UnknownCameraTypeException("No shared memory support at compile time");
123#endif
124 }
125
126 // ######
127 if (cap->cam_type() == "net") {
128#ifdef HAVE_NETWORK_CAM
129 c = new NetworkCamera(cap);
130#else
131 throw UnknownCameraTypeException("No network support at compile time");
132#endif
133 }
134
135 // ######
136 if (cap->cam_type() == "v4l") {
137#ifdef HAVE_V4L_CAM
138 c = new V4LCamera(cap);
139#else
140 throw UnknownCameraTypeException("No video4linux support at compile time");
141#endif
142 }
143
144 // ######
145 if (cap->cam_type() == "v4l1") {
146#ifdef HAVE_V4L1_CAM
147 c = new V4L1Camera(cap);
148#else
149 throw UnknownCameraTypeException("No video4linux1 support at compile time");
150#endif
151 }
152
153 // ######
154 if (cap->cam_type() == "v4l2") {
155#ifdef HAVE_V4L2_CAM
156 c = new V4L2Camera(cap);
157#else
158 throw UnknownCameraTypeException("No video4linux2 support at compile time");
159#endif
160 }
161
162 // ######
163 if (cap->cam_type() == "nao") {
164#ifdef HAVE_NAO_CAM
165 c = new NaoCamera(cap);
166#else
167 throw UnknownCameraTypeException("No nao camera support at compile time");
168#endif
169 }
170
171 // ######
172 if (cap->cam_type() == "bumblebee2") {
173#ifdef HAVE_BUMBLEBEE2_CAM
174 c = new Bumblebee2Camera(cap);
175#else
176 throw UnknownCameraTypeException("No Bumblebee 2 support at compile time");
177#endif
178 }
179
180 // ######
181 if (cap->cam_type() == "swissranger") {
182 throw UnknownCameraTypeException("SwissRanger support has been removed permanently");
183 }
184
185 // ######
186 if (cap->cam_type() == "pike") {
187#ifdef HAVE_PIKE_CAM
188 c = new PikeCamera(cap);
189#else
190 throw UnknownCameraTypeException("No Bumblebee 2 support at compile time");
191#endif
192 }
193
194 // ######
195 if (cap->cam_type() == "kinect") {
196#ifdef HAVE_KINECT_CAM
197 c = new KinectCamera(cap);
198#else
199 throw UnknownCameraTypeException("No Kinect support at compile time");
200#endif
201 }
202
203 if (c == NULL) {
205 }
206
207 return c;
208}
209
210/** Get camera instance.
211 * Get an instance of a camera of the given type. The argument string determines
212 * the type of camera to open.
213 * Supported camera types:
214 * - firewire, FirewireCamera, compiled if HAVE_FIREWIRE_CAM is defined in fvconf.mk
215 * - leutron, LeutronCamera, compiled if HAVE_LEUTRON_CAM is defined in fvconf.mk
216 * - file, FileLoader, compiled if HAVE_FILELOADER_CAM is defined in fvconf.mk
217 * - shmem, SharedMemoryCamera, compiled if HAVE_SHMEM_CAM is defined in fvconf.mk
218 * - net, NetworkCamera, compiled if HAVE_NETWORK_CAM is defined in fvconf.mk
219 * - v4l, V4LCamera, compiled if HAVE_V4L_CAM is defined in fvconf.mk
220 * @param as camera argument string
221 * @return camera instance of requested type
222 * @exception UnknownCameraTypeException thrown, if the desired camera could
223 * not be instantiated. This could be either to a misspelled camera ID, generally
224 * missing support or unset definition due to configuration in fvconf.mk or missing
225 * libraries and camera support compile-time autodetection.
226 */
227Camera *
229{
231 try {
232 Camera *cam = instance(cap);
233 delete cap;
234 return cam;
235 } catch (UnknownCameraTypeException &e) {
236 delete cap;
237 throw;
238 }
239}
240
241} // end namespace firevision
Bumblebee2 camera.
Definition: bumblebee2.h:35
Camera argument parser.
Definition: camargp.h:36
std::string cam_type() const
Get camera type.
Definition: camargp.cpp:122
static Camera * instance(const char *as)
Get camera instance.
Definition: factory.cpp:228
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:33
Load images from files.
Definition: fileloader.h:38
Firewire camera.
Definition: firewire.h:41
Access the Microsoft Kinect camera using the freenect driver.
Definition: kinect.h:56
Cameras accessed through Leutron framegrabber.
Definition: leutron.h:35
Video4Linux 2 camera with Nao-specific extensions.
Definition: nao.h:43
Network camera.
Definition: net.h:41
Pike camera.
Definition: pike.h:32
Shared memory camera.
Definition: shmem.h:36
Unknown camera type exception.
Video4Linux 1 camera implementation.
Definition: v4l1.h:36
Video4Linux 2 camera access implementation.
Definition: v4l2.h:43
General Video4Linux camera implementation.
Definition: v4l.h:35