Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_Controller_SwissRanger.cpp
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 #include <Base/Common/BIASpragmaStart.hh>
26 #ifdef WIN32
27 // workaround for wx 2.6.x redefiniton of _CRT_SECURE_NO_DEPRECATE
28 // fixed in wx 2.7.2
29 # pragma warning(disable: 4005)
30 #endif
31 //include first, avoid macro collision
32 #include <Gui/StringConv.hh>
33 #include <iostream>
34 #include "VideoSource_Controller_SwissRanger.hh"
35 #include <Base/Common/getopt_W32.h>
36 #include <Base/Image/ImageIO.hh>
37 #include <Image/Camera.hh>
38 #include <Gui/StringConv.hh>
39 
40 using namespace std;
41 using namespace BIAS;
42 
43 BEGIN_EVENT_TABLE(VideoSource_Controller_SwissRanger, wxFrame)
44  EVT_BUTTON(ID_HIDE, VideoSource_Controller_SwissRanger::OnHide)
45  EVT_COMMAND_SCROLL(ID_AMP, VideoSource_Controller_SwissRanger::OnAmplitude)
46  EVT_COMMAND_SCROLL(ID_SAT, VideoSource_Controller_SwissRanger::OnSaturation)
47  EVT_COMBOBOX(ID_MOD, VideoSource_Controller_SwissRanger::OnModFreq)
48  EVT_COMMAND_SCROLL(ID_DIST, VideoSource_Controller_SwissRanger::OnDistance)
49  EVT_COMMAND_SCROLL(ID_INT, VideoSource_Controller_SwissRanger::OnIntegration)
50  EVT_BUTTON(ID_BUTTON_UPDATE, VideoSource_Controller_SwissRanger::OnUpdate)
51  EVT_CHECKBOX( ID_CHECK_ENSURELATEST, VideoSource_Controller_SwissRanger::OnCheckEnsureLatest )
52  EVT_CHECKBOX( ID_CHECK_SHOWDEPTH, VideoSource_Controller_SwissRanger::OnCheckShowDepth )
53 END_EVENT_TABLE()
54 
55 
57 VideoSource_Controller_SwissRanger(VideoSource *cam, wxWindow *parent, const std::string& title)
58  : VideoSource_Controller_Base(parent, -1, AsciiToWx(title)
59  ,wxDefaultPosition,wxSize(500,500),wxSTAY_ON_TOP |wxCAPTION)
60 {
61  Cam_ = dynamic_cast<VideoSource_SwissRanger*>(cam);
62 
63  SliderAmplitude = NULL;
64  SliderSaturation = NULL;
65  SliderIntegration = NULL;
66  mIntTimeMs = NULL,mSaturation = NULL,mAmplitude = NULL,mDistance = NULL;
67  SliderDistanceOffset = NULL;
68  comboBoxModFreq = NULL;
69  checkBoxEnsureLatest = NULL;
70  checkBoxShowDepth = NULL;
71  sliderBox_ShGa = NULL;
72  showButton = NULL;
73  update_Button = NULL;
74 
75  min_amplitudeThreshold_=0; max_amplitudeThreshold_=2000;
76  min_saturationThreshold_=0; max_saturationThreshold_=2000;
77  min_integrationTime_=0; max_integrationTime_=0xFF;
78  min_distanceOffset_=0; max_distanceOffset_=10000;
79 
80  //create controls
81  Initialize();
82  //set slider values
83  SetAmplitudeThresholdRange(min_amplitudeThreshold_, max_amplitudeThreshold_);
84  SetSaturationThresholdRange(min_saturationThreshold_, max_saturationThreshold_);
85  SetDistanceOffsetRange(min_distanceOffset_, max_distanceOffset_);
86  SetIntegrationTimeRange(min_integrationTime_, max_integrationTime_);
87 }
88 
89 
90 
91 VideoSource_Controller_SwissRanger::
92 ~VideoSource_Controller_SwissRanger()
93 {}
94 
95 void VideoSource_Controller_SwissRanger::
96 Initialize(){
97 
98  sliderBox_ShGa_Visible = true;
99  vBoxVisible = true;
100 
101  wxSize SlSize(200,35);
102  wxSize BtSize(80,30);
103  wxSize reduzedDefSize(60,wxDefaultSize.y);
104  // the sizer
105  wxFlexGridSizer* itemFlexGridSizer = new wxFlexGridSizer(11, 3, 0, 0);
106  this->SetSizer(itemFlexGridSizer);
107  wxStaticText *tInt = new wxStaticText(this,ID_TEXT, wxT("Integration Time"));
108  SliderIntegration = new wxSlider(this, ID_INT, 0, 0, 30000,
109  wxDefaultPosition,SlSize,
110  wxSL_HORIZONTAL |wxSL_LABELS,
111  wxDefaultValidator, wxT("Int"));
112 
113  SliderIntegration->Enable(true);
114 
115  mIntTimeMs = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, reduzedDefSize, 0 );
116  mIntTimeMs->SetMaxLength( 4 );
117  mIntTimeMs->Enable( false );
118 
119  wxStaticText *tms = new wxStaticText(this,ID_TEXT, wxT("ms"));
120  wxBoxSizer *vbms = new wxBoxSizer(wxHORIZONTAL);
121  vbms->Add(mIntTimeMs,0,wxALIGN_LEFT | wxBOTTOM);
122  vbms->Add(tms, 0, wxALIGN_RIGHT | wxBOTTOM);
123 
124  itemFlexGridSizer->Add(tInt, 0,
125  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
126  itemFlexGridSizer->Add(SliderIntegration, 0,
127  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
128  itemFlexGridSizer->Add(vbms, 0,
129  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
130 
131  wxStaticText *tAmp = new wxStaticText(this,ID_TEXT, wxT("Amplitude Threshold"));
132 
133  SliderAmplitude = new wxSlider(this, ID_AMP, 0, 0, 30000,
134  wxDefaultPosition,SlSize,
135  wxSL_HORIZONTAL | wxSL_LABELS ,
136  wxDefaultValidator, wxT("Amp"));
137  mAmplitude = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
138  mAmplitude->SetMaxLength( 4 );
139  mAmplitude->Enable( false );
140 
141  SliderAmplitude->Enable(true);
142  itemFlexGridSizer->Add(tAmp, 0,
143  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
144  itemFlexGridSizer->Add(SliderAmplitude, 0,
145  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
146  itemFlexGridSizer->Add(mAmplitude, 0,
147  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
148 
149  wxStaticText *tSat = new wxStaticText(this,ID_TEXT, wxT("Saturation Threshold"));
150  SliderSaturation = new wxSlider(this, ID_SAT, 0, 0, 30000,
151  wxDefaultPosition,SlSize,
152  wxSL_HORIZONTAL | wxSL_LABELS,
153  wxDefaultValidator, wxT("Sat"));
154  mSaturation = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
155  mSaturation->SetMaxLength( 4 );
156  mSaturation->Enable( false );
157 
158  SliderSaturation->Enable(true);
159  itemFlexGridSizer->Add(tSat, 0,
160  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
161  itemFlexGridSizer->Add(SliderSaturation, 0,
162  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
163  itemFlexGridSizer->Add(mSaturation, 0,
164  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
165 
166 
167  wxStaticText *tDist = new wxStaticText(this,ID_TEXT, wxT("Distance Offset"));
168  SliderDistanceOffset = new wxSlider(this, ID_DIST, 0, 0, 30000,
169  wxDefaultPosition,SlSize,
170  wxSL_HORIZONTAL | wxSL_LABELS,
171  wxDefaultValidator, wxT("Dist"));
172  SliderDistanceOffset->Enable(true);
173 
174  mDistance = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, reduzedDefSize, 0 );
175  mDistance->SetMaxLength( 4 );
176  mDistance->Enable( false );
177 
178  wxStaticText *tms2 = new wxStaticText(this,ID_TEXT, wxT("mm"));
179  wxBoxSizer *vbmd = new wxBoxSizer(wxHORIZONTAL);
180  vbmd->Add(mDistance,0,wxALIGN_LEFT | wxBOTTOM);
181  vbmd->Add(tms2, 0, wxALIGN_RIGHT | wxBOTTOM);
182 
183  itemFlexGridSizer->Add(tDist, 0,
184  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
185  itemFlexGridSizer->Add(SliderDistanceOffset, 0,
186  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
187  itemFlexGridSizer->Add(vbmd, 0,
188  wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
189 
190 
191  wxBoxSizer *slMod = new wxBoxSizer(wxVERTICAL);
192  wxStaticText *tMod = new wxStaticText(this,ID_TEXT, wxT("Modulation Freq"));
193  wxSize comboSize(150,25);
194  wxString choices[10] = {wxT("MF_60MHz"),
195  wxT("MF_40MHz"),
196  wxT("MF_31MHz"),
197  wxT("MF_30MHz"),
198  wxT("MF_29MHz"),
199  wxT("MF_21MHz"),
200  wxT("MF_20MHz"),
201  wxT("MF_19MHz"),
202  wxT("MF_15MHz"),
203  wxT("MF_10MHz")};
204  comboBoxModFreq = new wxComboBox(this,ID_MOD,wxT("ModFreq"),wxDefaultPosition,
205  comboSize,10,choices,wxCB_READONLY);
206  comboBoxModFreq->SetSelection(6,6);
207  comboBoxModFreq->SetValue(wxT("MF_20MHz"));
208 
209  comboBoxModFreq->Enable(true);
210  slMod->Add(tMod,0,wxALL,2);
211  slMod->Add(comboBoxModFreq,0, wxALL,2);
212 
213  checkBoxEnsureLatest = new wxCheckBox( this, ID_CHECK_ENSURELATEST, wxT("Ensure Latest"), wxDefaultPosition, wxDefaultSize, 0 );
214  checkBoxShowDepth = new wxCheckBox( this, ID_CHECK_SHOWDEPTH, wxT("Show Depth"), wxDefaultPosition, wxDefaultSize, 0 );
215  wxBoxSizer *slCheckBox = new wxBoxSizer(wxVERTICAL);
216  slCheckBox->Add( checkBoxEnsureLatest, 0, wxALL, 5 );
217  slCheckBox->Add( checkBoxShowDepth, 0, wxALL, 5 );
218 
219  wxBoxSizer *slButton = new wxBoxSizer(wxVERTICAL);
220  showButton = new wxButton(this, ID_HIDE, wxT("Hide"),
221  wxDefaultPosition,BtSize);
222  update_Button = new wxButton(this, ID_BUTTON_UPDATE,
223  wxT("Update"),wxDefaultPosition,BtSize);
224 
225  slButton->Add(showButton,0,wxALIGN_LEFT | wxBOTTOM);
226  slButton->Add(update_Button, 0, wxALIGN_RIGHT | wxBOTTOM);
227 
228  itemFlexGridSizer->Add(slMod,0,wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
229  itemFlexGridSizer->Add(slCheckBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
230  itemFlexGridSizer->Add(slButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
231 
232  SetAutoLayout(true);
233  Layout();
234  Fit();
235  Update();
236  Show(TRUE);
237 }
238 
239 void VideoSource_Controller_SwissRanger::
240 SetVideoSource(BIAS::VideoSource *cam){
241  Cam_ = dynamic_cast<BIAS::VideoSource_SwissRanger*>(cam);
242  Initialize();
243 }
244 
245 
246 void VideoSource_Controller_SwissRanger::
247 OnHide(wxCommandEvent& event){
248  Show(false);
249 }
250 
251 void VideoSource_Controller_SwissRanger::
252 OnClose(wxCloseEvent& event) {
253 
254  Show(false);
255 }
256 
257 void VideoSource_Controller_SwissRanger::
258 OnAmplitude(wxScrollEvent& event) {
259  double value = SliderAmplitude->GetValue();
260  if (Cam_!= NULL) {
261  Cam_->SetAmplitudeThreshold((unsigned short)value);
262  wxString tval;
263  unsigned short val;
264  Cam_->GetAmplitudeThreshold(val);
265  tval << val;
266  mAmplitude->SetValue(tval);
267  }
268 }
269 
270 void VideoSource_Controller_SwissRanger::
271 OnSaturation(wxScrollEvent& event) {
272  double value = SliderSaturation->GetValue();
273  if (Cam_!= NULL) {
274  Cam_->SetSaturationThreshold((unsigned short)value);
275  unsigned short val;
276  wxString tval;
277  Cam_->GetSaturationThreshold(val);
278  tval << val;
279  mSaturation->SetValue(tval);
280  }
281 }
282 
283 void VideoSource_Controller_SwissRanger::
284 OnIntegration(wxScrollEvent& event) {
285  double value = SliderIntegration->GetValue();
286  if (Cam_!= NULL) {
287  Cam_->SetIntegrationTime((unsigned char)value);
288  }
289  wxString tval;
290  float fval;
291  Cam_->GetIntegrationTimeMS(fval);
292  tval << fval;
293  mIntTimeMs->SetValue(tval);
294 }
295 
296 void VideoSource_Controller_SwissRanger::
297 OnModFreq(wxCommandEvent& event) {
298  std::string text = WxToAscii(comboBoxModFreq->GetValue());
299  ModulationFrq freq = MF_20MHz;
300 
301  if(text.compare("MF_60MHz") == 0)
302  freq = MF_60MHz;
303  else if(text.compare("MF_40MHz") == 0)
304  freq = MF_40MHz;
305  else if(text.compare("MF_31MHz") == 0)
306  freq = MF_31MHz;
307  else if(text.compare("MF_30MHz") == 0)
308  freq = MF_30MHz;
309  else if(text.compare("MF_29MHz") == 0)
310  freq = MF_29MHz;
311  else if(text.compare("MF_21MHz") == 0)
312  freq = MF_21MHz;
313  else if(text.compare("MF_20MHz") == 0)
314  freq = MF_20MHz;
315  else if(text.compare("MF_19MHz") == 0)
316  freq = MF_19MHz;
317  else if(text.compare("MF_15MHz") == 0)
318  freq = MF_15MHz;
319  else if(text.compare("MF_10MHz") == 0)
320  freq = MF_10MHz;
321 
322  if (Cam_!= NULL) {
323  Cam_->SetModulationFrequency(freq);
324  }
325 }
326 
327 void VideoSource_Controller_SwissRanger::
328 OnDistance(wxScrollEvent& event) {
329  double value = SliderDistanceOffset->GetValue();
330  if (Cam_!= NULL) {
331  Cam_->SetDistanceOffset((unsigned short)value);
332  unsigned short val;
333  wxString tval;
334  Cam_->GetDistanceOffset(val);
335  tval << val;
336  mDistance->SetValue(tval);
337  }
338 }
339 
340 
341 
342 void VideoSource_Controller_SwissRanger::
343 Update() {
344  if (Cam_!= NULL) {
345  unsigned short currentShort =0;
346  unsigned char currentChar =0;
347  unsigned int currentInt = 0;
348 
349  Cam_->GetAmplitudeThreshold(currentShort);
350  SliderAmplitude->SetValue(int(currentShort));
351  Cam_->GetSaturationThreshold(currentShort);
352  SliderSaturation->SetValue(int(currentShort));
353  Cam_->GetIntegrationTime(currentChar);
354  SliderIntegration->SetValue(int(currentChar));
355  Cam_->GetDistanceOffset(currentShort);
356  SliderDistanceOffset->SetValue(int(currentShort));
357  unsigned int freq = MF_20MHz;
358  Cam_->GetModulationFrequency(freq);
359 
360  if(freq == MF_60MHz)
361  currentInt = 0;
362  else if(freq == MF_40MHz)
363  currentInt = 1;
364  else if(freq == MF_31MHz)
365  currentInt = 2;
366  else if(freq == MF_30MHz)
367  currentInt = 3;
368  else if(freq == MF_29MHz)
369  currentInt = 4;
370  else if(freq == MF_21MHz)
371  currentInt = 5;
372  else if(freq == MF_20MHz)
373  currentInt = 6;
374  else if(freq == MF_19MHz)
375  currentInt = 7;
376  else if(freq == MF_15MHz)
377  currentInt = 8;
378  else if(freq == MF_10MHz)
379  currentInt = 9;
380 
381  comboBoxModFreq->SetSelection(currentInt,currentInt);
382  }
383 
384 }
385 
386 void VideoSource_Controller_SwissRanger::
387 OnUpdate(wxCommandEvent& event) {
388  Update();
389 }
390 
391 void VideoSource_Controller_SwissRanger::
392 SetAmplitudeThresholdRange(unsigned int min,unsigned int max)
393 {
394  SliderAmplitude->SetRange(min,max);
395 
396 }
397 
398 void VideoSource_Controller_SwissRanger::
399 SetSaturationThresholdRange(unsigned int min,unsigned int max)
400 {
401  SliderSaturation->SetRange(min,max);
402 
403 }
404 
405 
406 void VideoSource_Controller_SwissRanger::
407 SetDistanceOffsetRange(unsigned int min,unsigned int max)
408 {
409  SliderDistanceOffset->SetRange(min,max);
410 }
411 
412 void VideoSource_Controller_SwissRanger::
413 SetIntegrationTimeRange(unsigned int min,unsigned int max)
414 {
415  SliderIntegration->SetRange(min,max);
416 }
417 
418 void VideoSource_Controller_SwissRanger::
419 OnCheckEnsureLatest(wxCommandEvent& event) {
420  Cam_->EnsureLatestFrame(event.IsChecked());
421 }
422 
423 void VideoSource_Controller_SwissRanger::
424 OnCheckShowDepth(wxCommandEvent& event) {
425  Cam_->GrabImageReturnsDepth(event.IsChecked());
426 }
427 
428 
429 #include <Base/Common/BIASpragmaEnd.hh>
430 
Defines a common interface to different devices.
Support for SwissRanger usb cam.