Basic Image AlgorithmS Library 2.8.0

VideoSource_Controller_PMD.cpp

00001 #ifdef WIN32
00002 // workaround for wx 2.6.x redefiniton of _CRT_SECURE_NO_DEPRECATE 
00003 // fixed in wx 2.7.2 
00004 #  pragma warning(disable: 4005)
00005 #endif
00006 
00007 #include "VideoSource_Controller_PMD.hh"
00008 
00009 #ifdef WIN32
00010 #  include <Base/Common/getopt_W32.h>  
00011 #endif
00012 
00013 #include <iostream>
00014 #include <Base/Image/ImageIO.hh>
00015 #include <Image/Camera.hh>
00016 #include <Gui/StringConv.hh>
00017 
00018 using namespace std;
00019 using namespace BIAS;
00020 
00021 BEGIN_EVENT_TABLE(VideoSource_Controller_PMD, wxFrame)
00022   EVT_BUTTON(ID_HIDE,       VideoSource_Controller_PMD::OnHide)
00023   EVT_CHECKBOX( ID_CHECK_SHOWDEPTH, VideoSource_Controller_PMD::OnCheckShowDepth )
00024   EVT_COMBOBOX(ID_MOD,            VideoSource_Controller_PMD::OnModFreq)
00025   EVT_COMMAND_SCROLL(ID_DIST,     VideoSource_Controller_PMD::OnDistance)
00026   EVT_SCROLL_THUMBRELEASE( VideoSource_Controller_PMD::OnIntegration)
00027   EVT_BUTTON(ID_BUTTON_UPDATE, VideoSource_Controller_PMD::OnUpdate)
00028 END_EVENT_TABLE()
00029 
00030 
00031 
00032 
00033 VideoSource_Controller_PMD::
00034 VideoSource_Controller_PMD(VideoSource *cam, wxWindow *parent, const std::string &title)
00035   : VideoSource_Controller_Base(parent, -1, AsciiToWx(title)
00036   ,wxDefaultPosition,wxSize(500,500),wxSTAY_ON_TOP |wxCAPTION)
00037 {
00038 
00039   Cam_ = dynamic_cast<VideoSource_PMD*>(cam);
00040   //now it is in milliseconds for one image
00041   min_integrationTime_=0; max_integrationTime_=120;
00042   min_distanceOffset_=0; max_distanceOffset_=1500;
00043 
00044   Initialize();
00045 
00046   SetDistanceOffsetRange(min_distanceOffset_, max_distanceOffset_);
00047   SetIntegrationTimeRange(min_integrationTime_, max_integrationTime_);
00048 
00049   Update();
00050 }
00051 
00052 
00053 
00054 VideoSource_Controller_PMD::
00055 ~VideoSource_Controller_PMD()
00056 {
00057 
00058 }
00059 
00060 void VideoSource_Controller_PMD::
00061 Initialize(){
00062   
00063   sliderBox_ShGa_Visible = true;    
00064   vBoxVisible = true;
00065 
00066   wxSize SlSize(100,200);
00067   wxSize BtSize(55,30);
00068   
00069   wxBoxSizer *slInt = new wxBoxSizer(wxVERTICAL);
00070   wxStaticText *tInt = new wxStaticText(this,ID_TEXT, wxT("Integration Time \n[ms]"));
00071   SliderIntegration = new wxSlider(this, ID_INT, 0, min_integrationTime_, 
00072                                    max_integrationTime_,
00073                                    wxDefaultPosition,SlSize,
00074                                    wxSL_VERTICAL | wxSL_LABELS | wxSL_RIGHT,
00075                                    wxDefaultValidator, wxT("Int"));
00076 
00077   SliderIntegration->Enable(true);
00078   slInt->Add(tInt,0,wxALL,2);  
00079   slInt->Add(SliderIntegration,0, wxALL,2);
00080   
00081   checkBoxShowDepth = new wxCheckBox( this, ID_CHECK_SHOWDEPTH, wxT("Show Depth"), wxDefaultPosition, wxDefaultSize, 0 );
00082  
00083   wxBoxSizer *slMod = new wxBoxSizer(wxVERTICAL);
00084   wxStaticText *tMod = new wxStaticText(this,ID_TEXT, wxT("Modulation Freq"));
00085   wxSize comboSize(150,25);
00086   wxString choices[10] = {wxT("MF_60MHz"),
00087                          wxT("MF_40MHz"), 
00088                          wxT("MF_31MHz"),
00089                          wxT("MF_30MHz"),
00090                          wxT("MF_29MHz"), 
00091                          wxT("MF_21MHz"),
00092                          wxT("MF_20MHz"),
00093                          wxT("MF_19MHz"), 
00094                          wxT("MF_15MHz"),
00095                          wxT("MF_10MHz")};
00096   comboBoxModFreq = new wxComboBox(this,ID_MOD,wxT("ModFreq"),wxDefaultPosition,
00097                                    comboSize,10,choices,wxCB_READONLY);
00098   comboBoxModFreq->SetSelection(6,6);
00099   comboBoxModFreq->SetValue(wxT("MF_20MHz"));
00100 
00101   comboBoxModFreq->Enable(true);
00102   slMod->Add(tMod,0,wxALL,2);  
00103   slMod->Add(comboBoxModFreq,0, wxALL,2);
00104 
00105   slMod->Add( checkBoxShowDepth, 0, wxALL, 5 );
00106 
00107 
00108   wxBoxSizer *slDist = new wxBoxSizer(wxVERTICAL);
00109   wxStaticText *tDist = new wxStaticText(this,ID_TEXT, wxT("Distance Offset"));
00110   SliderDistanceOffset = new wxSlider(this, ID_DIST, 0, 0, 30000,
00111                             wxDefaultPosition,SlSize,
00112                             wxSL_VERTICAL | wxSL_LABELS | wxSL_RIGHT,
00113                             wxDefaultValidator, wxT("Dist"));
00114 
00115   SliderDistanceOffset->Enable(true);
00116   slDist->Add(tDist,0,wxALL,2);  
00117   slDist->Add(SliderDistanceOffset,0, wxALL,2);
00118   
00119 
00120   showButton = new wxButton(this, ID_HIDE, wxT("Hide"),
00121                 wxDefaultPosition,BtSize);
00122   update_Button = new wxButton(this, ID_BUTTON_UPDATE, 
00123                    wxT("UPDATE"),wxDefaultPosition,BtSize);
00124 
00125   vBox = new wxBoxSizer(wxHORIZONTAL);
00126   vBox->Add(showButton,0,wxALIGN_LEFT   | wxBOTTOM);
00127   vBox->Add(update_Button, 0, wxALIGN_RIGHT   | wxBOTTOM); 
00128 
00129   wxBoxSizer *sl = new wxBoxSizer(wxHORIZONTAL);
00130 
00131   sl->Add(slMod,0,wxALL,2);
00132   sl->Add(slInt,0,wxALL,2); 
00133   sl->Add(slDist,0,wxALL,2); 
00134   
00135   sliderBox_ShGa = new wxBoxSizer(wxVERTICAL);
00136   sliderBox_ShGa->Add(sl,0,wxALL, 2);
00137   sliderBox_ShGa->Add(vBox,0,wxALL,2);
00138 
00139   vBox->SetSizeHints(this);
00140   this->SetSizer(sliderBox_ShGa);
00141   SetAutoLayout(true);
00142   Layout();
00143   Fit();
00144   Update();
00145   Show(TRUE);
00146 }
00147 
00148 void VideoSource_Controller_PMD::
00149 SetVideoSource(BIAS::VideoSource *cam){
00150   Cam_ = dynamic_cast<BIAS::VideoSource_PMD*>(cam);
00151 }
00152 
00153 
00154 void VideoSource_Controller_PMD::
00155 OnHide(wxCommandEvent& event){
00156   Show(false);
00157 }
00158 
00159 void VideoSource_Controller_PMD::
00160 OnClose(wxCloseEvent& event) {
00161 
00162   Show(false);
00163 }
00164 
00165 void VideoSource_Controller_PMD::
00166 OnIntegration(wxScrollEvent& event) {
00167   double value = SliderIntegration->GetValue();
00168   //cout<<"Value from Integrationtime Slider:"<<value<<endl;
00169   if (Cam_!= NULL) {
00170     //SetIntegrationTime in ms
00171     Cam_->SetIntegrationTimeMS(unsigned(rint(value)));
00172   }
00173 }
00174 
00175 
00176 void VideoSource_Controller_PMD::
00177 OnDistance(wxScrollEvent& event) {
00178   double value = SliderDistanceOffset->GetValue();
00179   if (Cam_!= NULL) {
00180     Cam_->SetDistanceOffset(unsigned(rint(value)));     
00181   }
00182 }
00183 
00184 
00185 
00186 void VideoSource_Controller_PMD::
00187 Update() {
00188   if (Cam_!= NULL) {
00189     unsigned int currentInt = 0;
00190     Cam_->GetIntegrationTimeMS(currentInt);
00191     //cout<<"Cam says integration:"<<currentInt<<endl;
00192     SliderIntegration->SetValue(currentInt);
00193         Cam_->GetDistanceOffset(currentInt);
00194     SliderDistanceOffset->SetValue(currentInt);
00195   }
00196 }
00197 
00198 void VideoSource_Controller_PMD::
00199 OnUpdate(wxCommandEvent& event) {
00200   Update();
00201 }
00202 
00203 void  VideoSource_Controller_PMD::
00204 SetDistanceOffsetRange(unsigned int min,unsigned int max)
00205 {
00206  SliderDistanceOffset->SetRange(min,max);
00207 }
00208 
00209 void  VideoSource_Controller_PMD::
00210 SetIntegrationTimeRange(unsigned int min,unsigned int max)
00211 {
00212  SliderIntegration->SetRange(min,max);
00213 }
00214 
00215 
00216 void VideoSource_Controller_PMD::
00217 OnCheckShowDepth(wxCommandEvent& event) {
00218   Cam_->GrabImageReturnsDepth(event.IsChecked());
00219 }
00220 
00221 
00222 void VideoSource_Controller_PMD::
00223 OnModFreq(wxCommandEvent& event) {
00224  std::string text = WxToAscii(comboBoxModFreq->GetValue());
00225  unsigned int freq = 20000000; //20Mhz
00226 
00227  if(text.compare("MF_60MHz") == 0)
00228    freq = 60000000;
00229  else if(text.compare("MF_40MHz") == 0)
00230    freq = 40000000;
00231  else if(text.compare("MF_31MHz") == 0)
00232    freq = 31000000;
00233  else if(text.compare("MF_30MHz") == 0)
00234    freq = 30000000;
00235  else if(text.compare("MF_29MHz") == 0)
00236    freq = 29000000;
00237  else if(text.compare("MF_21MHz") == 0)
00238    freq = 21000000;
00239  else if(text.compare("MF_20MHz") == 0)
00240    freq = 20000000;
00241  else if(text.compare("MF_19MHz") == 0)
00242    freq = 19000000;
00243  else if(text.compare("MF_15MHz") == 0)
00244    freq = 15000000;
00245  else if(text.compare("MF_10MHz") == 0)
00246    freq = 10000000;
00247 
00248   if (Cam_!= NULL) {
00249     Cam_->SetModulationFrequency(freq);     
00250   }
00251 }
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends