Fawkes API Fawkes Development Version
factory.cpp
1
2/***************************************************************************
3 * factory.cpp - Camera control factory
4 *
5 * Created: Fri Jun 15 13:11:28 2007
6 * Copyright 2005-2009 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 <core/exceptions/software.h>
25#include <fvcams/cam_exceptions.h>
26#include <fvcams/control/color.h>
27#include <fvcams/control/dummy.h>
28#include <fvcams/control/effect.h>
29#include <fvcams/control/factory.h>
30#include <fvcams/control/focus.h>
31#include <fvcams/control/image.h>
32#include <fvcams/control/pantilt.h>
33#include <fvcams/control/source.h>
34#include <fvcams/control/zoom.h>
35#include <fvutils/system/camargp.h>
36
37#ifdef HAVE_VISCA_CTRL
38# include <fvcams/control/visca.h>
39#endif
40#ifdef HAVE_EVID100P_CTRL
41# include <fvcams/control/sony_evid100p.h>
42#endif
43#ifdef HAVE_DPPTU_CTRL
44# include <fvcams/control/dp_ptu.h>
45#endif
46
47#include <typeinfo>
48
49using namespace std;
50
51namespace firevision {
52
53/** @class CameraControlFactory <fvcams/control/factory.h>
54 * Camera control factory.
55 * This camera control factory provides access to all camera controls in a unified way.
56 * You just supply a camera argument string and depending on the camera ID and compile-time
57 * support of camera control types an instance of the desired camera control is
58 * returned or otherwise an exception is thrown. See instance() for a list of
59 * supported camera control types.
60 *
61 * @author Tim Niemueller
62 */
63
64/** Get camera control instance with parameters from given camera argument parser.
65 * This is a convenience method and works like instace(const char *as).
66 * @param cap camera argument parser
67 * @return camera instance
68 * @exception UnknownCameraControlTypeException thrown if camera type is not known or
69 * was not available at build time.
70 */
71CameraControl *
73{
74 CameraControl *c = NULL;
75
76 // ######
77 if (cap->cam_type() == "evid100p") {
78#ifdef HAVE_EVID100P_CTRL
79 c = new SonyEviD100PControl(cap);
80#else
81 throw UnknownCameraControlTypeException("No EviD100P/Visca support at compile time");
82#endif
83 }
84
85 // ######
86 if (cap->cam_type() == "dpptu") {
87#ifdef HAVE_DPPTU_CTRL
88 c = new DPPTUControl(cap);
89#else
90 throw UnknownCameraControlTypeException("No DPPTU support at compile time");
91#endif
92 }
93
94 // ######
95 if (cap->cam_type() == "dummy") {
96 c = new DummyCameraControl();
97 }
98
99 if (c == NULL) {
101 }
102
103 return c;
104}
105
106/** Get camera control instance.
107 * Get an instance of a camera of the given type. The argument string determines
108 * the type of camera to open.
109 * Supported camera types:
110 * - evid100p, SonyEviD100PControl, compiled if HAVE_EVID100P_CTRL is defined in fvconf.mk
111 * - dpptu, DPPTUControl, compiled if HAVE_DPPTU_CTRL is defined in fvconf.mk
112 * @param as camera argument string
113 * @return camera control instance of requested type
114 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could
115 * not be instantiated. This could be either to a misspelled camera ID, generally
116 * missing support or unset definition due to configuration in fvconf.mk or missing
117 * libraries and camera support compile-time autodetection.
118 */
121{
123 try {
124 return instance(cap);
126 throw;
127 }
128}
129
130/** Get camera control instance.
131 * Get an instance of a camera control from the passed camera.
132 * It is tried to cast the camera to the appropriate camera control type. If that
133 * succeeds the camera control is returned, otherwise an exception is thrown.
134 * @param camera camera to cast
135 * @return camera control instance.
136 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could
137 * not be instantiated. This could be either to a misspelled camera ID, generally
138 * missing support or unset definition due to configuration in fvconf.mk or missing
139 * libraries and camera support compile-time autodetection.
140 */
143{
144 CameraControl *c = dynamic_cast<CameraControl *>(camera);
145 if (c) {
146 return c;
147 } else {
148 throw fawkes::TypeMismatchException("Camera does not provide requested camera control");
149 }
150}
151
152/** Get camera control instance.
153 * Get an instance of a camera of the given type based on the given camera.
154 * It is tried to cast the camera to the appropriate camera control type. If that
155 * succeeds the camera control is returned, otherwise an exception is thrown.
156 * @param typeinf type info for the intended type of the camera control
157 * @param camera camera to cast
158 * @return camera control instance of requested type
159 * @exception UnknownCameraControlTypeException thrown, if the desired camera control could
160 * not be instantiated. This could be either to a misspelled camera ID, generally
161 * missing support or unset definition due to configuration in fvconf.mk or missing
162 * libraries and camera support compile-time autodetection.
163 */
165CameraControlFactory::instance(const std::type_info &typeinf, Camera *camera)
166{
167 CameraControl *c = NULL;
168
169 if (typeid(CameraControlColor) == typeinf) {
170 c = dynamic_cast<CameraControlColor *>(camera);
171
172 } else if (typeid(CameraControlImage) == typeinf) {
173 c = dynamic_cast<CameraControlImage *>(camera);
174
175 } else if (typeid(CameraControlPanTilt) == typeinf) {
176 c = dynamic_cast<CameraControlPanTilt *>(camera);
177
178 } else if (typeid(CameraControlFocus) == typeinf) {
179 c = dynamic_cast<CameraControlFocus *>(camera);
180
181 } else if (typeid(CameraControlZoom) == typeinf) {
182 c = dynamic_cast<CameraControlZoom *>(camera);
183
184 } else if (typeid(CameraControlEffect) == typeinf) {
185 c = dynamic_cast<CameraControlEffect *>(camera);
186
187 } else if (typeid(CameraControlSource) == typeinf) {
188 c = dynamic_cast<CameraControlSource *>(camera);
189
190 } else {
192 }
193
194 if (c) {
195 return c;
196 } else {
197 throw fawkes::TypeMismatchException("Camera does not provide requested camera control");
198 }
199}
200
201} // end namespace firevision
Camera argument parser.
Definition: camargp.h:36
std::string cam_type() const
Get camera type.
Definition: camargp.cpp:122
Camera color control interface.
Definition: color.h:33
Camera effect control interface.
Definition: effect.h:33
static CameraControl * instance(const char *as)
Get camera control instance.
Definition: factory.cpp:120
Camera focus control interface.
Definition: focus.h:33
Camera image control interface.
Definition: image.h:33
Camera pan/tilt control interface.
Definition: pantilt.h:33
Camera source control interface.
Definition: source.h:33
Camera zoom control interface.
Definition: zoom.h:33
Camera control interface base class.
Definition: control.h:31
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:33
Plain dummy control.
Definition: dummy.h:47
Sony Evi D100P pan/tilt control.
Definition: sony_evid100p.h:39
Unknown camera control exception.