00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __FIREVISION_FVUTILS_BASE_VISION_MASTER_H_
00025 #define __FIREVISION_FVUTILS_BASE_VISION_MASTER_H_
00026
00027 #include <fvutils/color/colorspaces.h>
00028 #include <cams/control/control.h>
00029 #include <core/utils/refptr.h>
00030 #include <core/exceptions/software.h>
00031
00032 #include <typeinfo>
00033
00034 namespace fawkes {
00035 class Thread;
00036 class TypeMismatchException;
00037 }
00038
00039 namespace firevision {
00040 #if 0
00041 }
00042 #endif
00043
00044 class Camera;
00045
00046 class VisionMaster
00047 {
00048 public:
00049 virtual ~VisionMaster();
00050
00051 virtual Camera * register_for_camera(const char *camera_string,
00052 fawkes::Thread *thread,
00053 colorspace_t cspace = YUV422_PLANAR) = 0;
00054 virtual Camera * register_for_raw_camera(const char *camera_string,
00055 fawkes::Thread *thread) = 0;
00056 virtual void unregister_thread(fawkes::Thread *thread) = 0;
00057
00058 virtual CameraControl *acquire_camctrl(const char *cam_string) = 0;
00059 virtual void release_camctrl(CameraControl *cc) = 0;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 template <class CC>
00074 CC *
00075 acquire_camctrl(const char *camera_string);
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 template <class CC>
00102 CC *
00103 acquire_camctrl(const char *camera_string, CC *&cc);
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 template <class CC>
00116 CC *
00117 register_for_raw_camera(const char *camera_string, fawkes::Thread *thread);
00118
00119
00120 protected:
00121 virtual CameraControl *acquire_camctrl(const char *cam_string,
00122 const std::type_info &typeinf) = 0;
00123
00124 };
00125
00126 template <class CC>
00127 CC *
00128 VisionMaster::acquire_camctrl(const char *camera_string, CC *&cc)
00129 {
00130 const std::type_info &t = typeid(CC);
00131 CameraControl *pcc = acquire_camctrl(camera_string, t);
00132 CC *tcc = dynamic_cast<CC *>(pcc);
00133 if (tcc) {
00134 if (cc) cc = tcc;
00135 return tcc;
00136 } else {
00137 release_camctrl(tcc);
00138 throw fawkes::TypeMismatchException("CameraControl defined by string does "
00139 "not match desired type");
00140 }
00141 }
00142
00143
00144 template <class CC>
00145 CC *
00146 VisionMaster::acquire_camctrl(const char *camera_string)
00147 {
00148 const std::type_info &t = typeid(CC);
00149 CameraControl *pcc = acquire_camctrl(camera_string, t);
00150 CC *tcc = dynamic_cast<CC *>(pcc);
00151 if (tcc) {
00152 return tcc;
00153 } else {
00154 release_camctrl(tcc);
00155 throw fawkes::TypeMismatchException("CameraControl defined by string does "
00156 "not match desired type");
00157 }
00158 }
00159
00160 template <class CC>
00161 CC *
00162 VisionMaster::register_for_raw_camera(const char *camera_string, fawkes::Thread *thread)
00163 {
00164 Camera *camera = register_for_raw_camera(camera_string, thread);
00165 CC *tcc = dynamic_cast<CC *>(camera);
00166 if (tcc) {
00167 return tcc;
00168 } else {
00169 unregister_thread(thread);
00170 throw fawkes::TypeMismatchException("Camera defined by string does "
00171 "not match desired type");
00172 }
00173 }
00174
00175 }
00176
00177 #endif