Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_SwissRanger.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __BIASVIDEOSOURCE_SWISSRANGER_HH__
26 #define __BIASVIDEOSOURCE_SWISSRANGER_HH__
27 
28 #include <VideoSource/VideoSource_Base.hh>
29 #include <Image/Camera.hh>
30 #include <bias_config.h>
31 #include <vector>
32 #include <Base/Common/W32Compat.hh>
33 
34 //this is needed because DWORD is used in header
35 typedef unsigned long DWORD;
36 
37 #include <libMesaSR.h>
38 
39 namespace BIAS {
40 
41  /** @class VideoSource_SwissRanger
42  @ingroup g_videosource
43  @brief Support for SwissRanger usb cam
44  @author fkellner 10/2007 */
45  class BIASVideoSource_EXPORT VideoSource_SwissRanger : public VideoSource {
46 
47  public:
50 
51  /** \brief try to open first unused PMD-camera
52  \return 0 on success, -1 of opening failed, -2 if opening
53  failed because of wrong image width */
54  virtual int OpenDevice();
55  /** \brief try to open a specific camera-device
56  \return 0 on success, -1 of opening failed, -2 if opening
57  failed because of wrong image width */
58  virtual int OpenDevice(int camNr);
59  /** \brief close an active camera */
60  virtual int CloseDevice();
61 
62  /** \brief no needed for PreGrab now, does not do anything */
63  virtual int PreGrab();
64  /** \brief no needed for PostGrab now, does not do anything */
65  virtual int PostGrab();
66 
67  /** \brief Dummy function, does not do anything*/
68  virtual int GetCapabilities(VideoSourceCapabilities &caps);
69  /** \brief Dummy function, does not do anything*/
70  virtual int GetCapabilities(const char *device, VideoSourceCapabilities &caps);
71 
72  /** \brief Returns current framerate */
73  double GetFPS();
74 
75  /** \brief Init the grey image to grab to*/
76  virtual int InitImage(ImageBase &img);
77  /** \brief Init the depth image to grab to*/
78  virtual int InitDepthImage(ImageBase &img);
79 
80  /** Returns the 2D image, and reads depth and modulation coefficients */
81  virtual int GrabSingle(Camera<unsigned char> &image);
82 
83  /** \brief Set IntegrationTime (as uchar 0-255)*/
84  virtual int SetIntegrationTime(const unsigned char inttime);
85 
86  /** \brief Get IntegrationTime (as uchar 0-255)*/
87  virtual int GetIntegrationTime(unsigned char &val) {
88  val = integrationTime_;
89  return 0;
90  }
91 
92  /** \brief Set IntegrationTime in ms (gets clipped to min/max for camera)*/
93  virtual int SetIntegrationTimeMS(float inttime);
94 
95  /** \brief Get IntegrationTime in ms*/
96  virtual int GetIntegrationTimeMS(float &inttime);
97 
98  /** \brief Set the Modulation frequency (from defines.h)
99  MF_40MHz=0, //!<SR3k: maximal range 3.75m
100  MF_30MHz=1, //!<SR3k, SR4k: maximal range 5m
101  MF_21MHz=2, //!<SR3k: maximal range 7.14m
102  MF_20MHz=3, //!<SR3k: maximal range 7.5m
103  MF_19MHz=4, //!<SR3k: maximal range 7.89m
104  MF_60MHz=5, //!<SR4k: maximal range 2.5m \intDoc{frequency}
105  MF_15MHz=6, //!<SR4k: maximal range 10m \intDoc{frequency}
106  MF_10MHz=7, //!<SR4k: maximal range 15m \intDoc{frequency}
107  MF_29MHz=8, //!<SR4k: maximal range 5.17m
108  MF_31MHz=9, //!<SR4k: maximal range 4.84m
109  MF_LAST=10};
110  */
111  int SetModulationFrequency(ModulationFrq dModulationFrequency);
112 
113  /** \brief Get the Modulation frequency*/
114  int GetModulationFrequency(unsigned int &val) {
115  val = modulationFrequency_;
116  return 0;
117  }
118 
119  /** \brief Set Amplitude Threshold */
120  int SetAmplitudeThreshold(const unsigned short val) {
121  amplitudeThreshold_ = val;
122  return SR_SetAmplitudeThreshold(srCam_, amplitudeThreshold_);
123  }
124 
125  /** \brief Get Amplitude Threshold */
126  inline int GetAmplitudeThreshold(unsigned short &val) {
127  val = amplitudeThreshold_;
128  return 0;
129  }
130 
131  /** \brief Set Saturation Threshold */
132  int SetSaturationThreshold(const unsigned short val) {
133  saturationThreshold_ = val;
134  return SR_SetAmplitudeThreshold(srCam_, saturationThreshold_);
135  }
136 
137  /** \brief Get Saturation Threshold */
138  inline int GetSaturationThreshold(unsigned short &val) {
139  val = saturationThreshold_;
140  return 0;
141  }
142 
143  /** \briefSet Distance Offset */
144  int SetDistanceOffset(const unsigned short val) {
145  distanceOffset_ = val;
146  return SR_SetDistanceOffset(srCam_, distanceOffset_);
147  }
148 
149  /** \brief Get Distance Offset */
150  int GetDistanceOffset(unsigned short &val) {
151  val = distanceOffset_;
152  return 0;
153  }
154 
155  /** \brief Returns the depth image. Must be called after GrabSingle() */
156  inline int GrabSingleDepth(Camera<float> &image)
157  {
158  if (!DepthImgF_.IsEmpty()) {
159  image = DepthImgF_;
160  return 0;
161  }
162  return -1;
163  }
164 
165  /** \brief Returns the amplitude image. Must be called after GrabSingle() */
167  {
168  if (!ModCoeffImg_.IsEmpty()) {
169  image = ModCoeffImg_;
170  return 0;
171  }
172  return -1;
173  }
174  /** \brief Sets whether to generate new UIDS for each image */
175  void SetGenerateNewUIDs(bool s) {
176  BIASWARNONCE("Always generating new UUIDS for Swissranger images.");
177  }
178 
179  /** \brief Sets the autoillumination default settings on or off*/
180  inline int SetAutoIllumination(const bool on) {
181  if (on)
182  return SetAutoIllumination(5, 255, 10, 45);
183  else
184  return SetAutoIllumination(0xff, 0, 0, 0);
185  }
186 
187  /** \brief Sets the autoillumination settings */
188  inline int SetAutoIllumination(const unsigned char minIntTime,
189  const unsigned char maxIntTime,
190  const unsigned char percentOverPos,
191  const unsigned char desiredPos) {
192  return SR_SetAutoExposure(srCam_, minIntTime, maxIntTime,
193  percentOverPos, desiredPos);
194  }
195 
196  // /** \brief Sets the scattering filter */
197  // inline int SetScatteringFilter(const unsigned char blkSzX,
198  // const unsigned char blkSzY) {
199  // return SR_SetScatteringFilter(srCam_, blkSzX, blkSzY);
200  // }
201 
202  /** \brief Ensure latest frame calls grab twice to really get
203  * current image instead of buffered image.*/
204  void EnsureLatestFrame(const bool ensure) {
205  bEnsureLatestFrame_ = ensure;
206  }
207  /** \brief Sets whether a call to GrabSingle should return the depth image */
208  void GrabImageReturnsDepth(bool on) {
209  bGrabImageReturnsDepth_ = on;
210  }
211 
212  /** \brief returns the version of the used software */
213  int GetSoftwareVersion(std::string& version);
214 
215  /** \brief returns the device string of the camera */
216  int GetDeviceString(std::string& device);
217 
218 
219  protected:
220  void ConvertImageFloatToCharNormalized_(const Image<float> src, Image<unsigned char> &dst, bool useMaxDist=false);
221  void ConvertRawImageToFloat_(const unsigned short* data, Image<float> &dst);
222  void ConvertRawImage_(const unsigned short* data, Image<float> &dst);
223 
224  void SetMaxDist_();
225 
226  /// uses libusb directly to reset the device in case of failure on open
227  void ResetUsbDeviceConnection_();
228 
230  unsigned short amplitudeThreshold_;
231  unsigned short saturationThreshold_;
232  unsigned char integrationTime_;
233  unsigned short distanceOffset_;
234  ModulationFrq modulationFrequency_;
235 
236  // bIsOpen_ indicates successful OpenDevice,
237  // bRetryOpen_ will be set false after first try so OpenDevice fails if it has to try more than twice
238  bool bIsOpen_, bRetryOpen_;
239 
240  //MIP images, holding grabbed data
244 
245  CMesaDevice* srCam_;
246 
247  ImgEntry * imgEntryArray;
248 
249  const unsigned short* dataDepth_;
250  const unsigned short* dataAmp_;
251  float* modcoeff_;
252  unsigned int serialNumber_;
253  float max_dist_;
255  //size_t bufSz_;
256  CamType camType_;
257  };
258 
259 }
260 
261 #endif //__VIDEOSOURCE_SWISSRANGER_HH__
262 
int SetDistanceOffset(const unsigned short val)
Distance Offset
Defines a common interface to different devices.
virtual int GetIntegrationTime(unsigned char &val)
Get IntegrationTime (as uchar 0-255)
int GetModulationFrequency(unsigned int &val)
Get the Modulation frequency.
int SetSaturationThreshold(const unsigned short val)
Set Saturation Threshold.
Support for SwissRanger usb cam.
int SetAutoIllumination(const unsigned char minIntTime, const unsigned char maxIntTime, const unsigned char percentOverPos, const unsigned char desiredPos)
Sets the autoillumination settings.
int GetDistanceOffset(unsigned short &val)
Get Distance Offset.
int GrabSingleModCoeff(Camera< float > &image)
Returns the amplitude image.
int GetSaturationThreshold(unsigned short &val)
Get Saturation Threshold.
BIAS::Camera< unsigned char > DepthImg_
void GrabImageReturnsDepth(bool on)
Sets whether a call to GrabSingle should return the depth image.
int SetAmplitudeThreshold(const unsigned short val)
Set Amplitude Threshold.
void EnsureLatestFrame(const bool ensure)
Sets the scattering filter.
int GetAmplitudeThreshold(unsigned short &val)
Get Amplitude Threshold.
int GrabSingleDepth(Camera< float > &image)
Returns the depth image.
Checks for VideoSource capabilities.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
int SetAutoIllumination(const bool on)
Sets the autoillumination default settings on or off.
void SetGenerateNewUIDs(bool s)
Sets whether to generate new UIDS for each image.