Robotics Library  0.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Dc1394Camera.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the Technische Universitaet Muenchen nor the names of
14 // its contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef _RL_HAL_DC1394CAMERA_H_
31 #define _RL_HAL_DC1394CAMERA_H_
32 
33 #include <string>
34 
35 #if (LIBDC1394_VERSION_MAJOR > 10)
36 #include <dc1394/dc1394.h>
37 #else
38 #include <libdc1394/dc1394_control.h>
39 #include <libraw1394/raw1394.h>
40 #endif
41 
42 #include "Camera.h"
43 
44 namespace rl
45 {
46  namespace hal
47  {
48  class Dc1394Camera : public Camera
49  {
50  public:
52  {
53 #if (LIBDC1394_VERSION_MAJOR > 10)
54  COLOR_CODING_MONO8 = ::DC1394_COLOR_CODING_MONO8,
55 #else
56  COLOR_CODING_MONO8 = ::COLOR_FORMAT7_MONO8,
57 #endif
68  };
69 
70  enum Feature
71  {
72 #if (LIBDC1394_VERSION_MAJOR > 10)
73  FEATURE_BRIGHTNESS = ::DC1394_FEATURE_BRIGHTNESS,
74 #else
76 #endif
98  };
99 
101  {
102 #if (LIBDC1394_VERSION_MAJOR > 10)
103  FEATURE_MODE_MANUAL = ::DC1394_FEATURE_MODE_MANUAL,
104 #else
106 #endif
109  };
110 
112  {
113 #if (LIBDC1394_VERSION_MAJOR > 10)
114  FRAMERATE_1_875 = ::DC1394_FRAMERATE_1_875,
115 #else
117 #endif
125  };
126 
127  enum IsoSpeed
128  {
129 #if (LIBDC1394_VERSION_MAJOR > 10)
130  ISO_SPEED_100 = ::DC1394_ISO_SPEED_100,
131 #else
132  ISO_SPEED_100 = ::SPEED_100,
133 #endif
139  };
140 
142  {
143 #if (LIBDC1394_VERSION_MAJOR > 10)
144  OPERATION_MODE_LEGACY = ::DC1394_OPERATION_MODE_LEGACY,
145 #else
147 #endif
149  };
150 
152  {
153 #if (LIBDC1394_VERSION_MAJOR > 10)
154  VIDEO_MODE_160x120_YUV444 = ::DC1394_VIDEO_MODE_160x120_YUV444,
155 #else
156  VIDEO_MODE_160x120_YUV444 = ::MODE_160x120_YUV444,
157 #endif
164 #if (LIBDC1394_VERSION_MAJOR > 10)
166 #else
167  VIDEO_MODE_800x600_YUV422 = ::MODE_800x600_YUV422,
168 #endif
176 #if (LIBDC1394_VERSION_MAJOR > 10)
178 #else
179  VIDEO_MODE_1280x960_YUV422 = ::MODE_1280x960_YUV422,
180 #endif
188 #if (LIBDC1394_VERSION_MAJOR > 10)
190 #else
191  VIDEO_MODE_EXIF = ::MODE_EXIF,
192 #endif
193 #if (LIBDC1394_VERSION_MAJOR > 10)
195 #else
196  VIDEO_MODE_FORMAT7_0 = ::MODE_FORMAT7_0,
197 #endif
205  };
206 
207  Dc1394Camera(const ::std::string& filename = "", const unsigned int& node = 0);
208 
209  virtual ~Dc1394Camera();
210 
211  void close();
212 
213  unsigned int getBitsPerPixel() const;
214 
215  unsigned int getColorCodingDepth() const;
216 
217  unsigned int getHeight() const;
218 
219  bool getFeatureAbsoluteControl(const Feature& feature) const;
220 
221  void getFeatureBoundaries(const Feature& feature, unsigned int& min, unsigned int& max) const;
222 
223  void getFeatureBoundariesAbsolute(const Feature& feature, float& min, float& max) const;
224 
225  FeatureMode getFeatureMode(const Feature& feature) const;
226 
227  void getFeatureModes(const Feature& feature, bool& hasManual, bool& hasAuto, bool& hasOnePushAuto) const;
228 
229  unsigned int getFeatureValue(const Feature& feature) const;
230 
231  float getFeatureValueAbsolute(const Feature& feature) const;
232 
233  ::std::string getFilename() const;
234 
235  void getFormat7(VideoMode& videoMode, ColorCoding& colorCoding, unsigned int& left, unsigned int& top, unsigned int& width, unsigned int& height) const;
236 
237  void getFormat7MaximumImageSize(const unsigned int& mode, unsigned int& width, unsigned& height) const;
238 
239  Framerate getFramerate() const;
240 
241  unsigned int getNode() const;
242 
243  int getNumCameras() const;
244 
246 
247  unsigned int getPort() const;
248 
249  unsigned int getSize() const;
250 
251  IsoSpeed getSpeed() const;
252 
253  VideoMode getVideoMode() const;
254 
255  unsigned int getWidth() const;
256 
257  void grab(unsigned char* image);
258 
259  bool hasFeatureAbsoluteControl(const Feature& feature) const;
260 
261  bool isFeatureEnabled(const Feature& feature) const;
262 
263  bool isFeaturePresent(const Feature& feature) const;
264 
265  bool isFeatureReadable(const Feature& feature) const;
266 
267  bool isFeatureSwitchable(const Feature& feature) const;
268 
269  void open();
270 
271  void reset();
272 
273  void setFeatureAbsoluteControl(const Feature& feature, const bool& doOn);
274 
275  void setFeatureEnabled(const Feature& feature, const bool& doOn);
276 
277  void setFeatureMode(const Feature& feature, const FeatureMode& mode);
278 
279  void setFeatureValue(const Feature& feature, const unsigned int& value);
280 
281  void setFeatureValueAbsolute(const Feature& feature, const float& value);
282 
283  void setFilename(const ::std::string& filename);
284 
285  void setFormat7(const VideoMode& videoMode, const ColorCoding& colorCoding, const unsigned int& left, const unsigned int& top, const unsigned int& width, const unsigned int& height);
286 
287  void setFramerate(const Framerate& framerate);
288 
289  void setNode(const unsigned int& node);
290 
291  void setOperationMode(const OperationMode& mode);
292 
293  void setPort(const unsigned int& port);
294 
295  void setSpeed(const IsoSpeed& speed);
296 
297  void setVideoMode(const VideoMode& mode);
298 
299  void start();
300 
301  void step();
302 
303  void stop();
304 
305  protected:
306 
307  private:
308 #if (LIBDC1394_VERSION_MAJOR > 10)
309  unsigned int buffer;
310 
311  dc1394camera_t* camera;
312 
313  int cameras;
314 
316 
317  dc1394_t* dc1394;
318 
319  ::std::string filename;
320 
321  dc1394video_frame_t* frame;
322 
324 
325  unsigned int height;
326 
327  unsigned int left;
328 
329  unsigned int node;
330 
331  unsigned int speed;
332 
333  unsigned int top;
334 
336 
337  unsigned int width;
338 #else
339  unsigned int buffer;
340 
341  dc1394_cameracapture camera;
342 
343  int cameras;
344 
345  unsigned int channel;
346 
348 
349  unsigned int drop;
350 
351  ::std::string filename;
352 
354 
355  raw1394handle_t handle;
356 
357  unsigned int height;
358 
359  dc1394_camerainfo info;
360 
361  unsigned int left;
362 
363  unsigned int node;
364 
365  nodeid_t* nodes;
366 
367  unsigned int port;
368 
369  unsigned int speed;
370 
371  unsigned int top;
372 
374 
375  unsigned int width;
376 #endif
377  };
378  }
379 }
380 
381 #endif // _RL_HAL_DC1394CAMERA_H_