Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_Controller_PMD.cpp
1 #ifdef WIN32
2 // workaround for wx 2.6.x redefiniton of _CRT_SECURE_NO_DEPRECATE
3 // fixed in wx 2.7.2
4 # pragma warning(disable: 4005)
5 #endif
6 
7 #include "VideoSource_Controller_PMD.hh"
8 
9 #ifdef WIN32
10 # include <Base/Common/getopt_W32.h>
11 #endif
12 
13 #include <iostream>
14 #include <Base/Image/ImageIO.hh>
15 #include <Image/Camera.hh>
16 #include <Gui/StringConv.hh>
17 
18 using namespace std;
19 using namespace BIAS;
20 
21 BEGIN_EVENT_TABLE(VideoSource_Controller_PMD, wxFrame)
22  EVT_BUTTON(ID_HIDE, VideoSource_Controller_PMD::OnHide)
23  EVT_CHECKBOX( ID_CHECK_SHOWDEPTH, VideoSource_Controller_PMD::OnCheckShowDepth )
24  EVT_COMBOBOX(ID_MOD, VideoSource_Controller_PMD::OnModFreq)
25  EVT_COMMAND_SCROLL(ID_DIST, VideoSource_Controller_PMD::OnDistance)
26  EVT_SCROLL_THUMBRELEASE( VideoSource_Controller_PMD::OnIntegration)
27  EVT_BUTTON(ID_BUTTON_UPDATE, VideoSource_Controller_PMD::OnUpdate)
28 END_EVENT_TABLE()
29 
30 
31 
32 
34 VideoSource_Controller_PMD(VideoSource *cam, wxWindow *parent, const std::string &title)
35  : VideoSource_Controller_Base(parent, -1, AsciiToWx(title)
36  ,wxDefaultPosition,wxSize(500,500),wxSTAY_ON_TOP |wxCAPTION)
37 {
38 
39  Cam_ = dynamic_cast<VideoSource_PMD*>(cam);
40  //now it is in milliseconds for one image
41  min_integrationTime_=0; max_integrationTime_=120;
42  min_distanceOffset_=0; max_distanceOffset_=1500;
43 
44  Initialize();
45 
46  SetDistanceOffsetRange(min_distanceOffset_, max_distanceOffset_);
47  SetIntegrationTimeRange(min_integrationTime_, max_integrationTime_);
48 
49  Update();
50 }
51 
52 
53 
54 VideoSource_Controller_PMD::
55 ~VideoSource_Controller_PMD()
56 {
57 
58 }
59 
60 void VideoSource_Controller_PMD::
61 Initialize(){
62 
63  sliderBox_ShGa_Visible = true;
64  vBoxVisible = true;
65 
66  wxSize SlSize(100,200);
67  wxSize BtSize(55,30);
68 
69  wxBoxSizer *slInt = new wxBoxSizer(wxVERTICAL);
70  wxStaticText *tInt = new wxStaticText(this,ID_TEXT, wxT("Integration Time \n[ms]"));
71  SliderIntegration = new wxSlider(this, ID_INT, 0, min_integrationTime_,
72  max_integrationTime_,
73  wxDefaultPosition,SlSize,
74  wxSL_VERTICAL | wxSL_LABELS | wxSL_RIGHT,
75  wxDefaultValidator, wxT("Int"));
76 
77  SliderIntegration->Enable(true);
78  slInt->Add(tInt,0,wxALL,2);
79  slInt->Add(SliderIntegration,0, wxALL,2);
80 
81  checkBoxShowDepth = new wxCheckBox( this, ID_CHECK_SHOWDEPTH, wxT("Show Depth"), wxDefaultPosition, wxDefaultSize, 0 );
82 
83  wxBoxSizer *slMod = new wxBoxSizer(wxVERTICAL);
84  wxStaticText *tMod = new wxStaticText(this,ID_TEXT, wxT("Modulation Freq"));
85  wxSize comboSize(150,25);
86  wxString choices[10] = {wxT("MF_60MHz"),
87  wxT("MF_40MHz"),
88  wxT("MF_31MHz"),
89  wxT("MF_30MHz"),
90  wxT("MF_29MHz"),
91  wxT("MF_21MHz"),
92  wxT("MF_20MHz"),
93  wxT("MF_19MHz"),
94  wxT("MF_15MHz"),
95  wxT("MF_10MHz")};
96  comboBoxModFreq = new wxComboBox(this,ID_MOD,wxT("ModFreq"),wxDefaultPosition,
97  comboSize,10,choices,wxCB_READONLY);
98  comboBoxModFreq->SetSelection(6,6);
99  comboBoxModFreq->SetValue(wxT("MF_20MHz"));
100 
101  comboBoxModFreq->Enable(true);
102  slMod->Add(tMod,0,wxALL,2);
103  slMod->Add(comboBoxModFreq,0, wxALL,2);
104 
105  slMod->Add( checkBoxShowDepth, 0, wxALL, 5 );
106 
107 
108  wxBoxSizer *slDist = new wxBoxSizer(wxVERTICAL);
109  wxStaticText *tDist = new wxStaticText(this,ID_TEXT, wxT("Distance Offset"));
110  SliderDistanceOffset = new wxSlider(this, ID_DIST, 0, 0, 30000,
111  wxDefaultPosition,SlSize,
112  wxSL_VERTICAL | wxSL_LABELS | wxSL_RIGHT,
113  wxDefaultValidator, wxT("Dist"));
114 
115  SliderDistanceOffset->Enable(true);
116  slDist->Add(tDist,0,wxALL,2);
117  slDist->Add(SliderDistanceOffset,0, wxALL,2);
118 
119 
120  showButton = new wxButton(this, ID_HIDE, wxT("Hide"),
121  wxDefaultPosition,BtSize);
122  update_Button = new wxButton(this, ID_BUTTON_UPDATE,
123  wxT("UPDATE"),wxDefaultPosition,BtSize);
124 
125  vBox = new wxBoxSizer(wxHORIZONTAL);
126  vBox->Add(showButton,0,wxALIGN_LEFT | wxBOTTOM);
127  vBox->Add(update_Button, 0, wxALIGN_RIGHT | wxBOTTOM);
128 
129  wxBoxSizer *sl = new wxBoxSizer(wxHORIZONTAL);
130 
131  sl->Add(slMod,0,wxALL,2);
132  sl->Add(slInt,0,wxALL,2);
133  sl->Add(slDist,0,wxALL,2);
134 
135  sliderBox_ShGa = new wxBoxSizer(wxVERTICAL);
136  sliderBox_ShGa->Add(sl,0,wxALL, 2);
137  sliderBox_ShGa->Add(vBox,0,wxALL,2);
138 
139  vBox->SetSizeHints(this);
140  this->SetSizer(sliderBox_ShGa);
141  SetAutoLayout(true);
142  Layout();
143  Fit();
144  Update();
145  Show(TRUE);
146 }
147 
148 void VideoSource_Controller_PMD::
149 SetVideoSource(BIAS::VideoSource *cam){
150  Cam_ = dynamic_cast<BIAS::VideoSource_PMD*>(cam);
151 }
152 
153 
154 void VideoSource_Controller_PMD::
155 OnHide(wxCommandEvent& event){
156  Show(false);
157 }
158 
159 void VideoSource_Controller_PMD::
160 OnClose(wxCloseEvent& event) {
161 
162  Show(false);
163 }
164 
165 void VideoSource_Controller_PMD::
166 OnIntegration(wxScrollEvent& event) {
167  double value = SliderIntegration->GetValue();
168  //cout<<"Value from Integrationtime Slider:"<<value<<endl;
169  if (Cam_!= NULL) {
170  //SetIntegrationTime in ms
171  Cam_->SetIntegrationTimeMS(unsigned(rint(value)));
172  }
173 }
174 
175 
176 void VideoSource_Controller_PMD::
177 OnDistance(wxScrollEvent& event) {
178  double value = SliderDistanceOffset->GetValue();
179  if (Cam_!= NULL) {
180  Cam_->SetDistanceOffset(unsigned(rint(value)));
181  }
182 }
183 
184 
185 
186 void VideoSource_Controller_PMD::
187 Update() {
188  if (Cam_!= NULL) {
189  unsigned int currentInt = 0;
190  Cam_->GetIntegrationTimeMS(currentInt);
191  //cout<<"Cam says integration:"<<currentInt<<endl;
192  SliderIntegration->SetValue(currentInt);
193  Cam_->GetDistanceOffset(currentInt);
194  SliderDistanceOffset->SetValue(currentInt);
195  }
196 }
197 
198 void VideoSource_Controller_PMD::
199 OnUpdate(wxCommandEvent& event) {
200  Update();
201 }
202 
203 void VideoSource_Controller_PMD::
204 SetDistanceOffsetRange(unsigned int min,unsigned int max)
205 {
206  SliderDistanceOffset->SetRange(min,max);
207 }
208 
209 void VideoSource_Controller_PMD::
210 SetIntegrationTimeRange(unsigned int min,unsigned int max)
211 {
212  SliderIntegration->SetRange(min,max);
213 }
214 
215 
216 void VideoSource_Controller_PMD::
217 OnCheckShowDepth(wxCommandEvent& event) {
218  Cam_->GrabImageReturnsDepth(event.IsChecked());
219 }
220 
221 
222 void VideoSource_Controller_PMD::
223 OnModFreq(wxCommandEvent& event) {
224  std::string text = WxToAscii(comboBoxModFreq->GetValue());
225  unsigned int freq = 20000000; //20Mhz
226 
227  if(text.compare("MF_60MHz") == 0)
228  freq = 60000000;
229  else if(text.compare("MF_40MHz") == 0)
230  freq = 40000000;
231  else if(text.compare("MF_31MHz") == 0)
232  freq = 31000000;
233  else if(text.compare("MF_30MHz") == 0)
234  freq = 30000000;
235  else if(text.compare("MF_29MHz") == 0)
236  freq = 29000000;
237  else if(text.compare("MF_21MHz") == 0)
238  freq = 21000000;
239  else if(text.compare("MF_20MHz") == 0)
240  freq = 20000000;
241  else if(text.compare("MF_19MHz") == 0)
242  freq = 19000000;
243  else if(text.compare("MF_15MHz") == 0)
244  freq = 15000000;
245  else if(text.compare("MF_10MHz") == 0)
246  freq = 10000000;
247 
248  if (Cam_!= NULL) {
249  Cam_->SetModulationFrequency(freq);
250  }
251 }
Defines a common interface to different devices.
Support for CamCube usb cam.