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