vision_master.h
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 class Camera;
00035 namespace fawkes {
00036 class Thread;
00037 class TypeMismatchException;
00038 }
00039
00040 class VisionMaster
00041 {
00042 public:
00043 virtual ~VisionMaster();
00044
00045 virtual Camera * register_for_camera(const char *camera_string,
00046 fawkes::Thread *thread,
00047 colorspace_t cspace = YUV422_PLANAR) = 0;
00048 virtual Camera * register_for_raw_camera(const char *camera_string,
00049 fawkes::Thread *thread) = 0;
00050 virtual void unregister_thread(fawkes::Thread *thread) = 0;
00051
00052 virtual CameraControl *acquire_camctrl(const char *cam_string) = 0;
00053 virtual void release_camctrl(CameraControl *cc) = 0;
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 template <class CC>
00068 CC *
00069 acquire_camctrl(const char *camera_string);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 template <class CC>
00096 CC *
00097 acquire_camctrl(const char *camera_string, CC *&cc);
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 template <class CC>
00109 CC *
00110 register_for_raw_camera(const char *camera_string, fawkes::Thread *thread);
00111
00112
00113 protected:
00114 virtual CameraControl *acquire_camctrl(const char *cam_string,
00115 const std::type_info &typeinf) = 0;
00116
00117 };
00118
00119 template <class CC>
00120 CC *
00121 VisionMaster::acquire_camctrl(const char *camera_string, CC *&cc)
00122 {
00123 const std::type_info &t = typeid(CC);
00124 CameraControl *pcc = acquire_camctrl(camera_string, t);
00125 CC *tcc = dynamic_cast<CC *>(pcc);
00126 if (tcc) {
00127 if (cc) cc = tcc;
00128 return tcc;
00129 } else {
00130 release_camctrl(tcc);
00131 throw fawkes::TypeMismatchException("CameraControl defined by string does "
00132 "not match desired type");
00133 }
00134 }
00135
00136
00137 template <class CC>
00138 CC *
00139 VisionMaster::acquire_camctrl(const char *camera_string)
00140 {
00141 const std::type_info &t = typeid(CC);
00142 CameraControl *pcc = acquire_camctrl(camera_string, t);
00143 CC *tcc = dynamic_cast<CC *>(pcc);
00144 if (tcc) {
00145 return tcc;
00146 } else {
00147 release_camctrl(tcc);
00148 throw fawkes::TypeMismatchException("CameraControl defined by string does "
00149 "not match desired type");
00150 }
00151 }
00152
00153 template <class CC>
00154 CC *
00155 VisionMaster::register_for_raw_camera(const char *camera_string, fawkes::Thread *thread)
00156 {
00157 Camera *camera = register_for_raw_camera(camera_string, thread);
00158 CC *tcc = dynamic_cast<CC *>(camera);
00159 if (tcc) {
00160 return tcc;
00161 } else {
00162 unregister_thread(thread);
00163 throw fawkes::TypeMismatchException("Camera defined by string does "
00164 "not match desired type");
00165 }
00166 }
00167
00168 #endif