Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
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_SWISSRANGER_CAM
58
#include <fvcams/swissranger.h>
59
#endif
60
#ifdef HAVE_PIKE_CAM
61
#include <fvcams/pike.h>
62
#endif
63
#ifdef HAVE_KINECT_CAM
64
#include <fvcams/kinect.h>
65
#endif
66
67
using namespace
std;
68
69
namespace
firevision {
70
#if 0
/* just to make Emacs auto-indent happy */
71
}
72
#endif
73
74
/** @class CameraFactory <fvcams/factory.h>
75
* Camera factory.
76
* This camera factory provides access to all cameras in a unified way. You just
77
* supply a camera argument string and depending on the camera ID and compile-time
78
* support of camera types an instance of the desired camera is returned or otherwise
79
* an exception is thrown. See instance() for a list of supported camera types.
80
*
81
* @author Tim Niemueller
82
*/
83
84
/** Get camera instance with parameters from given camera argument parser.
85
* This is a convenience method and works like instace(const char *as).
86
* @param cap camera argument parser
87
* @return camera instance
88
* @exception UnknownCameraTypeException thrown if camera type is not known or
89
* was not available at build time.
90
*/
91
Camera *
92
CameraFactory::instance(
const
CameraArgumentParser
*cap)
93
{
94
Camera
*c = NULL;
95
96
// ######
97
if
( cap->
cam_type
() ==
"firewire"
) {
98
#ifdef HAVE_FIREWIRE_CAM
99
c =
new
FirewireCamera
(cap);
100
#else
101
throw
UnknownCameraTypeException
(
"No firewire support at compile time"
);
102
#endif
103
}
104
105
// ######
106
if
( cap->
cam_type
() ==
"leutron"
) {
107
#ifdef HAVE_LEUTRON_CAM
108
c =
new
LeutronCamera
();
109
#else
110
throw
UnknownCameraTypeException
(
"No Leutron support at compile time"
);
111
#endif
112
}
113
114
// ######
115
if
( cap->
cam_type
() ==
"file"
) {
116
#ifdef HAVE_FILELOADER_CAM
117
c =
new
FileLoader
(cap);
118
#else
119
throw
UnknownCameraTypeException
(
"No file loader support at compile time"
);
120
#endif
121
}
122
123
// ######
124
if
( cap->
cam_type
() ==
"shmem"
) {
125
#ifdef HAVE_SHMEM_CAM
126
c =
new
SharedMemoryCamera
(cap);
127
#else
128
throw
UnknownCameraTypeException
(
"No shared memory support at compile time"
);
129
#endif
130
}
131
132
// ######
133
if
( cap->
cam_type
() ==
"net"
) {
134
#ifdef HAVE_NETWORK_CAM
135
c =
new
NetworkCamera
(cap);
136
#else
137
throw
UnknownCameraTypeException
(
"No network support at compile time"
);
138
#endif
139
}
140
141
// ######
142
if
( cap->
cam_type
() ==
"v4l"
) {
143
#ifdef HAVE_V4L_CAM
144
c =
new
V4LCamera
(cap);
145
#else
146
throw
UnknownCameraTypeException
(
"No video4linux support at compile time"
);
147
#endif
148
}
149
150
// ######
151
if
( cap->
cam_type
() ==
"v4l1"
) {
152
#ifdef HAVE_V4L1_CAM
153
c =
new
V4L1Camera
(cap);
154
#else
155
throw
UnknownCameraTypeException
(
"No video4linux1 support at compile time"
);
156
#endif
157
}
158
159
// ######
160
if
( cap->
cam_type
() ==
"v4l2"
) {
161
#ifdef HAVE_V4L2_CAM
162
c =
new
V4L2Camera
(cap);
163
#else
164
throw
UnknownCameraTypeException
(
"No video4linux2 support at compile time"
);
165
#endif
166
}
167
168
// ######
169
if
( cap->
cam_type
() ==
"nao"
) {
170
#ifdef HAVE_NAO_CAM
171
c =
new
NaoCamera
(cap);
172
#else
173
throw
UnknownCameraTypeException
(
"No nao camera support at compile time"
);
174
#endif
175
}
176
177
// ######
178
if
( cap->
cam_type
() ==
"bumblebee2"
) {
179
#ifdef HAVE_BUMBLEBEE2_CAM
180
c =
new
Bumblebee2Camera
(cap);
181
#else
182
throw
UnknownCameraTypeException
(
"No Bumblebee 2 support at compile time"
);
183
#endif
184
}
185
186
// ######
187
if
( cap->
cam_type
() ==
"swissranger"
) {
188
#ifdef HAVE_SWISSRANGER_CAM
189
c =
new
SwissRangerCamera
(cap);
190
#else
191
throw
UnknownCameraTypeException
(
"No SwissRanger support at compile time"
);
192
#endif
193
}
194
195
// ######
196
if
( cap->
cam_type
() ==
"pike"
) {
197
#ifdef HAVE_PIKE_CAM
198
c =
new
PikeCamera
(cap);
199
#else
200
throw
UnknownCameraTypeException
(
"No Bumblebee 2 support at compile time"
);
201
#endif
202
}
203
204
// ######
205
if
( cap->
cam_type
() ==
"kinect"
) {
206
#ifdef HAVE_KINECT_CAM
207
c =
new
KinectCamera
(cap);
208
#else
209
throw
UnknownCameraTypeException
(
"No Kinect support at compile time"
);
210
#endif
211
}
212
213
if
( c == NULL ) {
214
throw
UnknownCameraTypeException
();
215
}
216
217
return
c;
218
}
219
220
221
/** Get camera instance.
222
* Get an instance of a camera of the given type. The argument string determines
223
* the type of camera to open.
224
* Supported camera types:
225
* - firewire, FirewireCamera, compiled if HAVE_FIREWIRE_CAM is defined in fvconf.mk
226
* - leutron, LeutronCamera, compiled if HAVE_LEUTRON_CAM is defined in fvconf.mk
227
* - file, FileLoader, compiled if HAVE_FILELOADER_CAM is defined in fvconf.mk
228
* - shmem, SharedMemoryCamera, compiled if HAVE_SHMEM_CAM is defined in fvconf.mk
229
* - net, NetworkCamera, compiled if HAVE_NETWORK_CAM is defined in fvconf.mk
230
* - v4l, V4LCamera, compiled if HAVE_V4L_CAM is defined in fvconf.mk
231
* @param as camera argument string
232
* @return camera instance of requested type
233
* @exception UnknownCameraTypeException thrown, if the desired camera could
234
* not be instantiated. This could be either to a misspelled camera ID, generally
235
* missing support or unset definition due to configuration in fvconf.mk or missing
236
* libraries and camera support compile-time autodetection.
237
*/
238
Camera
*
239
CameraFactory::instance(
const
char
*as)
240
{
241
CameraArgumentParser
*cap =
new
CameraArgumentParser
(as);
242
try
{
243
Camera
*cam = instance(cap);
244
delete
cap;
245
return
cam;
246
}
catch
(
UnknownCameraTypeException
&e) {
247
delete
cap;
248
throw
;
249
}
250
}
251
252
}
// end namespace firevision
src
libs
fvcams
factory.cpp
Generated by
1.8.1.2