Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ShowCamWxFrame.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 "ShowCamWxFrame.hh"
26 #include "ShowCamWxThreads.hh"
27 #include "ShowCamWxFormat7Frame.hh"
28 
29 //logos
30 //#include <img/miplogochars64x64.xpm>
31 #include <img/miplogochars32x32.xpm>
32 #include <wx/artprov.h>
33 #include <wx/aboutdlg.h>
34 #include <VideoSource/VideoSourceCapabilities.hh>
35 #include <Tools/BIASShowCamWX/ShowCamWxVideoSourceFactory.hh>
36 #include <Gui/wxTwoFilesInputDialog.h>
37 
38 using namespace BIAS;
39 using namespace std;
40 
41 #define PARAM_FILE_NAME "ShowCamWx.param"
42 #define BUFFER_SIZE 50
43 
44 //#define AUTOSCAN
45 
46 BEGIN_EVENT_TABLE(ShowCamWxFrame, wxFrame)
47 
48  EVT_CLOSE ( ShowCamWxFrame::OnWindowClose)
49  EVT_KEY_DOWN ( ShowCamWxFrame::OnKey)
50  EVT_MENU (wxID_ABOUT, ShowCamWxFrame::OnAbout)
51  EVT_MENU (wxID_EXIT, ShowCamWxFrame::OnQuit)
52  EVT_MENU (ID_Grab, ShowCamWxFrame::OnGrab)
53  EVT_MENU (ID_GrabContinuous, ShowCamWxFrame::OnGrabContinuous)
54  EVT_MENU (ID_GrabToStream, ShowCamWxFrame::OnGrabToStream)
55  EVT_MENU (ID_Show1, ShowCamWxFrame::OnShowImage)
56  EVT_MENU (ID_Show2, ShowCamWxFrame::OnShowImage)
57  EVT_MENU (ID_Show3, ShowCamWxFrame::OnShowImage)
58  EVT_MENU (ID_Show4, ShowCamWxFrame::OnShowImage)
59  EVT_MENU (ID_Show5, ShowCamWxFrame::OnShowImage)
60  EVT_MENU (ID_Show6, ShowCamWxFrame::OnShowImage)
61  EVT_MENU (ID_Show7, ShowCamWxFrame::OnShowImage)
62  EVT_MENU (ID_Show8, ShowCamWxFrame::OnShowImage)
63  EVT_MENU (ID_Show9, ShowCamWxFrame::OnShowImage)
64  EVT_MENU (ID_Controller, ShowCamWxFrame::OnShowController)
65  EVT_MENU (ID_SaveParameters, ShowCamWxFrame::OnSaveParameters)
66  EVT_MENU (ID_ShowParameters, ShowCamWxFrame::OnShowParameters)
67  EVT_MENU (ID_FindIEEE1394, ShowCamWxFrame::OnFindIEEE1394)
68  EVT_MENU (ID_FindUEYE, ShowCamWxFrame::OnFindUEye)
69  EVT_MENU (ID_FindZess, ShowCamWxFrame::OnFindPMDZess)
70  EVT_MENU (ID_FindPMDTec, ShowCamWxFrame::OnFindPMDTec)
71  EVT_MENU (ID_FindSwissranger, ShowCamWxFrame::OnFindSwissRanger)
72  EVT_MENU (ID_FindKinect, ShowCamWxFrame::OnFindKinect)
73  EVT_MENU (ID_FindOpenNI, ShowCamWxFrame::OnFindOpenNI)
74  EVT_MENU (ID_FindKinect2, ShowCamWxFrame::OnFindKinect2)
75  EVT_MENU (ID_FindWebcams, ShowCamWxFrame::OnFindWebcams)
76  EVT_MENU (ID_OpenFlirController, ShowCamWxFrame::OnOpenFlirController)
77  EVT_MENU (ID_OpenViscaController, ShowCamWxFrame::OnOpenViscaController)
78  EVT_MENU (ID_OpenDPController, ShowCamWxFrame::OnOpenDPController)
79  EVT_TIMER (ID_Timer, ShowCamWxFrame::OnTimer)
80  EVT_CHECKBOX (ID_Fit, ShowCamWxFrame::OnFit)
81  EVT_CHECKBOX (ID_KeepScroll, ShowCamWxFrame::OnKeepScrollPosition)
82  EVT_BUTTON (ID_Grab, ShowCamWxFrame::OnGrab)
83  EVT_BUTTON (ID_GrabContinuous, ShowCamWxFrame::OnGrabContinuous)
84  EVT_BUTTON (ID_GrabToStream, ShowCamWxFrame::OnGrabToStream)
85  EVT_BUTTON (ID_FindWebcams, ShowCamWxFrame::OnFindWebcams)
86  EVT_BUTTON (ID_FindIEEE1394, ShowCamWxFrame::OnFindIEEE1394)
87  EVT_BUTTON (ID_FindPMDTec, ShowCamWxFrame::OnFindPMDTec)
88  EVT_BUTTON (ID_FindSwissranger, ShowCamWxFrame::OnFindSwissRanger)
89  EVT_BUTTON (ID_Controller, ShowCamWxFrame::OnShowController)
90  EVT_BUTTON (ID_HIDE_CAMERALIST, ShowCamWxFrame::OnHideCamerasListBox)
91  EVT_MENU (ID_SHOW_CAMERALIST, ShowCamWxFrame::OnShowCamerasListBox)
92  EVT_LISTBOX_DCLICK(ID_CAMERAS_LISTBOX, ShowCamWxFrame::OnClickCamerasListBox)
93  END_EVENT_TABLE()
94 
95 
96 /****************************************************
97 *****************************************************/
99 ShowCamWxFrame(const wxString& title,
100  const wxPoint& pos, const wxSize& size)
101  : wxFrame((wxFrame*)NULL, -1, title, pos, size) ,
102  ParamGUI () // disable param desctructor warning
103 {
104  // initialize camera names for params
106  SetIcon(wxIcon(miplogochars32x32_xpm));
107  // set default value for class variables
108  bSingleSaveDirCreated_ = false;
109  dSingleDirIndex_ = 0;
110  dDirIndex_=0;
111  tauControllerFrame_ = NULL;
112 #ifdef BIAS_HAVE_PANTILT
113  viscaControllerFrame_ = NULL;
114 #endif
115 
116 #ifdef BIAS_HAVE_PANTILT_DP
117  panTiltControl_=NULL;
118  panTiltControlDialog_=NULL;
119 #endif //BIAS_HAVE_PANTILT_DP
120 
121  paramFrame_ =NULL;
122  OpenedDevices_ = false;
123  InitCameras_ = false;
124  InitParams_ = false;
125  bSaveImages_ = false;
126  bWriteBuffered_ = false;
127  EmptyDevice_ = false;
128  FrameCounter_ = 0;
129  GrabCounter_ = 0;
130  LastWidth_ = 0;
131  LastHeight_ = 0;
132  NumCamSel_ = 0;
133  Win32DCAMNumber_ = 0;
134  ShowXB3_ = 0;
135 #ifdef BIAS_HAVE_DCAM
136  format7Frame_=NULL;
137 #endif
138  FirstCameraID_ = 10000;
139  LastCameraID_ = FirstCameraID_;
140  TimerActive_ = false;
141  ActiveCameras_ = 0;
142 
143  NumOfCams_ = 0;
144  grabMasterThread_ = NULL;
145  menuShow = NULL;
146 
147  CleanedUp_ = false;
148 
149  // set timer delay to 5 ms
150  Delay_ = 25;
151  Timer_.SetOwner(this, ID_Timer);
152 
153  // init images for cameras
154  for (int i = 0; i < NUMBER_CAMERAS; i++)
155  {
156  // init Images
157  CamImg_.push_back(NULL);
158  CamImgMiddle_.push_back(NULL);
159  CamImgRight_.push_back(NULL);
160 
161  CamImgPMDDepth_.push_back(NULL);
162  CamImgPMDAmp_.push_back(NULL);
163  CamImgPMDInt_.push_back(NULL);
164  XB3AllInOne_.push_back(NULL);
165 
166  ThreadInited_.push_back(false);
167  CameraActive_.push_back(false);
168  CameraInitialized_.push_back(false);
169  SetFirewireB_.push_back(false);
170  SetTrigger_.push_back(false);
171  SetUserMode_.push_back(true);
172  SelectedFps_.push_back(15.0);
173  Format7LeftTop_.push_back(Vector2<int>(0,0));
174  Format7WidthHeight_.push_back(Vector2<int>(0,0));
175  Format7BpP_.push_back(0);
176  Format7ColorMode_.push_back(0);
177 
178  grabSingleThread_.push_back(NULL);
179  saveThreads_.push_back(NULL);
180 
181  grabMasterThread_ = NULL;
182 
183  // Ringbuffer for writing images
184  BufferAccess_.push_back(NULL);
185  WriteIndex_.push_back(0);
186  ReadIndex_.push_back(BUFFER_SIZE-1);
187 
188  ImageBuffer_.push_back(new vector<Camera<unsigned char>* > );
189  ImageBufferMiddle_.push_back(new vector<Camera<unsigned char>* >);
190  ImageBufferRight_.push_back(new vector<Camera<unsigned char>* >);
191  ImageBufferPMDDepth_.push_back(new vector<Camera<float>* >);
192  ImageBufferPMDAmp_.push_back(new vector<Camera<float>* >);
193  ImageBufferPMDInt_.push_back(new vector<Camera<float>* >);
194 
195  for(int j=0;j<BUFFER_SIZE;j++){
196  ImageBuffer_[i]->push_back(NULL);
197  ImageBufferMiddle_[i]->push_back(NULL);
198  ImageBufferRight_[i]->push_back(NULL);
199  ImageBufferPMDDepth_[i]->push_back(NULL);
200  ImageBufferPMDAmp_[i]->push_back(NULL);
201  ImageBufferPMDInt_[i]->push_back(NULL);
202  }
203 
204  ColorModels_.push_back(ImageBase::CM_invalid);
205  ViewColorMode_.push_back(ImageBase::CM_invalid);
206  VideoControllers_.push_back(NULL);
207  std::vector<string> tmp;
208  DeviceChannelNames_.push_back(tmp);
209  DeviceChannel_.push_back(-1);
210 
211 
212  }
213  // create tool bar
214  wxToolBar* toolBar = CreateToolBar();
215  toolBar->SetToolBitmapSize( wxSize( 24,24 ) );
216  toolBar->SetToolSeparation( 0 );
217  toolBar->SetToolPacking( 0 );
218  wxSize smallButtonSize(60,25);
219  wxSize mediumButtonSize(80,25);
220  wxSize largeButtonSize(110,25);
221 
222  pButtonGrab= new wxButton(toolBar, ID_Grab, wxT("Grab"),wxDefaultPosition,smallButtonSize);
223  pButtonGrab->SetToolTip(wxT("Grab single image."));
224  toolBar->AddControl(pButtonGrab);
225 
226  pButtonContinuous= new wxButton(toolBar, ID_GrabContinuous, wxT("Grab Cont."),wxDefaultPosition,mediumButtonSize);
227  pButtonContinuous->SetToolTip(wxT("Toggle grabbing continuously."));
228  toolBar->AddControl(pButtonContinuous);
229 
230  // toolBar->AddCheckTool( ID_GrabContinuous, wxT("Toggle grabbing continuously."),
231  // wxArtProvider::GetIcon(wxART_ERROR ,wxART_TOOLBAR) );
232 
233  pButtonStream= new wxButton(toolBar, ID_GrabToStream, wxT("Grab To Stream"),wxDefaultPosition,largeButtonSize);
234  pButtonStream->SetToolTip(wxT("Toggle grabbing to stream."));
235  toolBar->AddControl(pButtonStream);
236  toolBar->AddSeparator();
237 
238  pButtonIEEE1394= new wxButton(toolBar,ID_FindIEEE1394, wxT("Find IEEE1394"),wxDefaultPosition,largeButtonSize);
239  pButtonIEEE1394->SetToolTip(wxT("Find Firewire IEEE1394 cameras."));
240  toolBar->AddControl(pButtonIEEE1394);
241 #ifdef BIAS_HAVE_V4L
242  pButtonWebCams= new wxButton(toolBar,ID_FindWebcams, wxT("Find V4L"),wxDefaultPosition,largeButtonSize);
243  pButtonWebCams->SetToolTip(wxT("Find V4L Cameras."));
244  toolBar->AddControl(pButtonWebCams);
245 #endif
246 #ifdef BIAS_HAVE_DSHOW
247  pButtonWebCams= new wxButton(toolBar,ID_FindWebcams, wxT("Find DShow"),wxDefaultPosition,largeButtonSize);
248  pButtonWebCams->SetToolTip(wxT("Find DSHOW Cameras."));
249  toolBar->AddControl(pButtonWebCams);
250 #endif
251 #ifdef BIAS_HAVE_SWISSRANGER
252  pButtonSR= new wxButton(toolBar,ID_FindSwissranger, wxT("Find SR"),wxDefaultPosition,smallButtonSize);
253  pButtonSR->SetToolTip(wxT("Find Swissranger ToF cameras."));
254  toolBar->AddControl(pButtonSR);
255 #endif
256 #ifdef BIAS_HAVE_PMD_PMDTec
257  pButtonPMDTec= new wxButton(toolBar,ID_FindPMDTec, wxT("Find PMDTec"),wxDefaultPosition,largeButtonSize);
258  pButtonPMDTec->SetToolTip(wxT("Find PMDTec ToF cameras."));
259  toolBar->AddControl(pButtonPMDTec);
260 #endif
261  toolBar->AddSeparator();
262 
263  pButtonController= new wxButton(toolBar,ID_Controller, wxT("Controller"),wxDefaultPosition,mediumButtonSize);
264  pButtonController->SetToolTip(wxT("Show Videosource Controller"));
265  toolBar->AddControl(pButtonController);
266  toolBar->AddSeparator();
267 
268  pCheckBoxFit = new wxCheckBox(toolBar, ID_Fit, wxT("Fit window"));
269  toolBar->AddControl(pCheckBoxFit);
270  pCheckBoxKeepScrollPosition = new wxCheckBox(toolBar, ID_KeepScroll, wxT("Keep Scroll"));
271  toolBar->AddControl(pCheckBoxKeepScrollPosition);
272  pCheckBoxKeepScrollPosition->SetValue(true);
273  toolBar->Realize();
274 
275 
276  CreateCameraMenu();
277  // create status bar and add status text
278  CreateStatusBar(3);
279  wxString text;
280  text.Printf(wxT("size: %4dx%4d"),0, 0);
281  SetStatusText(text, 1);
282 
283 
284  //a splitter window as top level window
285  splitterWindow_ = new wxSplitterWindow(this,ID_SPLITTER_WINDOW,wxDefaultPosition,
286  wxDefaultSize,wxSP_3D | wxSP_LIVE_UPDATE);
287  splitterWindow_->SetMinimumPaneSize(100);
288 
289  // init image canvas as child of splitterwindow
290  wxSize imageSize(640,480);
291  IC_ = new ImageCanvas(splitterWindow_,GetStatusBar(), 0,-1,wxDefaultPosition,imageSize);
292  IC_->SetEvtHandlerEnabled(true);
293  IC_->KeepScrollPosition(true);
294 
295  cameraListPanel_ = new wxPanel(splitterWindow_);
296  wxString choices[10];
297  for(unsigned i=0;i<10;i++){
298  wxString str; str.Printf(wxT("Camera %d"),i);
299  choices[i] = str;
300  }
301  cameraListBox_ = new wxListBox(cameraListPanel_,ID_CAMERAS_LISTBOX,
302  wxDefaultPosition,wxSize(100,500), 10, choices,wxLB_SINGLE);
303  wxSize buttonSize(50,35);
304  wxButton *hideButton = new wxButton(cameraListPanel_,ID_HIDE_CAMERALIST,
305  wxT("Hide"),wxDefaultPosition,buttonSize);
306 
307  wxFlexGridSizer *rightPanelSizer = new wxFlexGridSizer(2,1,2,2);
308  rightPanelSizer->AddGrowableRow(0);
309  rightPanelSizer->Add(cameraListBox_,1, wxEXPAND |wxALL , 5);
310  rightPanelSizer->Add(hideButton,1, wxALL , 5);
311  cameraListPanel_->SetSizer(rightPanelSizer);
312 
313  //split between notebook and ImagelistPanel
314  splitterWindow_->SplitVertically(IC_,cameraListPanel_,-1);
315 
316  //load test image
317  string img = BIAS_IMG_DIR; img += "mipTestImage.gif";
318  if(BIAS::ImageIO::Load(img,ShowImage_)!=0)
319  {
320  ShowImage_.Init(640,480,3);
321  unsigned char color[3]={255,255,255};
322  ShowImage_.FillImageWithConstValue(color);
323  }
324  IC_->Show(ShowImage_,"Camera Image");
325 
326  // add image canvas to main window
327  wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
328  vbox->Add(splitterWindow_,1, wxEXPAND |wxALL , 5); //|wxFIXED_MINSIZE , 5);
329 
330  SetSizer(vbox);
331  SetAutoLayout(true);
332  SetMinSize(size);
333  Layout();
334  Fit();
335 
336  Timer_.Start(Delay_);
337 }
338 
339 /****************************************************
340 *****************************************************/
343 {
344  // close threads
345  for(int i = 0; i < NUMBER_CAMERAS; i++){
346  if(grabSingleThread_[i] != NULL){
347  delete grabSingleThread_[i];
348  }
349  if(saveThreads_[i] != NULL){
350  delete saveThreads_[i];
351  }
352  }
353 }
354 /****************************************************
355 *****************************************************/
356 void ShowCamWxFrame::
357 InitParams(int &argc, char *argv[])
358 {
359  // initialize color models for cameras
360  vector<string> colorModels;
361  colorModels.push_back("CM_Default");
362  colorModels.push_back("CM_Grey");
363  colorModels.push_back("CM_RGB");
364  colorModels.push_back("CM_BGR");
365  colorModels.push_back("CM_YUYV422");
366  colorModels.push_back("CM_UYVY422");
367  colorModels.push_back("CM_YUV420P");
368  colorModels.push_back("CM_YUV444");
369  colorModels.push_back("CM_YUV411");
370  colorModels.push_back("CM_HSV");
371  colorModels.push_back("CM_HSI_OBS");
372  colorModels.push_back("CM_DV");
373  colorModels.push_back("CM_RGBA");
374  colorModels.push_back("CM_GreyA");
375  colorModels.push_back("CM_Bayer_RGGB");
376  colorModels.push_back("CM_Bayer_GBRG");
377  colorModels.push_back("CM_Bayer_GRBG");
378  colorModels.push_back("CM_Bayer_BGGR");
379  colorModels.push_back("CM_HSL");
380  colorModels.push_back("CM_hsL");
381  colorModels.push_back("CM_SymTensor2x2");
382  colorModels.push_back("CM_BGRA");
383  colorModels.push_back("CM_RGBE");
384 
385 
386 
387  for (int i = 0; i < NUMBER_CAMERAS; i++)
388  {
389  // add nine different cameras to params and set group name
390  stringstream number;
391  number << i + 1;
392  ParamCameras_[i] = AddParamEnum("CameraType" + number.str(),
393  "Type of camera", cameraNames_, 0, NULL, 0, i);
394  ParamColorModel_[i] = AddParamEnum("CameraColorModel" + number.str(),
395  "Color Model for camera", colorModels,
396  0, NULL, 0, i);
397  ParamFPS_[i] = AddParamDouble("CameraFPS" + number.str(),
398  "fps possibilities: 1.875 3.75 7.5 15.0 30.0 60.0 120.0 240.0",
399  0.0, 0.0, 240.0, 0, i);
400  ParamWidth_[i] = AddParamInt("CameraWidth" + number.str(),
401  "Width of camera", 0, 0, 10000, 0, i);
402  ParamHeight_[i] = AddParamInt("CameraHeight" + number.str(),
403  "Height of camera", 0, 0, 10000, 0, i);
404  //ParamSetTop_[i] = AddParamInt();
405  //ParamSetLeft_[i] = AddParamInt();
406  ParamDown_[i] = AddParamInt("CameraDownsampling" + number.str(),
407  "Downsampling of camera", 0, 0, 10, 0, i);
408  ParamPort_[i] = AddParamInt("CameraPort" + number.str(),
409  "Port of NET camera", 0, 0, 100000, 0, i);
410  ParamIP_[i] = AddParamString("CameraIP" + number.str(),
411  "IP of NET camera", "", 0, i);
412  ParamBitFile_[i]= AddParamString("CameraBitFile" + number.str(),
413  "Bit file for usb pmd cameras", "", 0, i);
414  ParamDevice_[i] = AddParamString("CameraDevice" + number.str(),
415  "Device/Interface name of camera",
416  "", 0, i);
417  // every camera gets own group number
418  stringstream text;
419  text<<number.str()<<". Camera";
420  SetGroupName(i, text.str());
421  }
422 #ifdef BIAS_HAVE_PANTILT_DP
423  bUsePanTiltUnit_ = AddParamBool("UsePanTiltUnit","Use the Pan-Tilt-Unit?",false,
424  'p', NUMBER_CAMERAS);
425  stringstream text;
426  text<<"General";
427  SetGroupName(NUMBER_CAMERAS, text.str());
428 #endif
429  // check if param file exists, else create one
430  ifstream ifs(PARAM_FILE_NAME);
431  if (!ifs)
432  WriteParameter(PARAM_FILE_NAME);
433  else
434  {
435  // read param from file
436  ReadParameter(PARAM_FILE_NAME);
437  // update parameters from file with arguments from command line
438  UpdateParameter(argc, argv, PARAM_FILE_NAME);
439  ifs.close();
440  }
441 
442  // get color models for cameras
443  ParseColorModels();
444 
445  InitParams_ = true;
446 }
447 
448 /****************************************************
449 *****************************************************/
450 void ShowCamWxFrame::
451 OnOpenDPController(wxCommandEvent& event){
452 #ifdef BIAS_HAVE_PANTILT_DP
453  bool ret = true;
454  if(panTiltControl_==NULL)
455  ret = InitPanTiltUnit();
456  if(ret && panTiltControlDialog_!=NULL)
457  panTiltControlDialog_->Show(true);
458 #endif
459 }
460 
461 
462 #ifdef BIAS_HAVE_PANTILT_DP
463 /****************************************************
464 *****************************************************/
465 bool ShowCamWxFrame::
466 InitPanTiltUnit()
467 {
468  bool bRet = false;
469 
470  if(panTiltControl_==NULL)
471  panTiltControl_= new DPPanTiltControl();
472 
473  if(panTiltControlDialog_==NULL)
474  panTiltControlDialog_ = new DPPanTiltControlDialog(this, 7651,
475  wxT("Pan-Tilt-Unit Control"));
476 #ifdef WIN32
477  bRet = panTiltControl_->InitPanTiltUnit("COM1");
478 #else
479  bRet = panTiltControl_->InitPanTiltUnit("/dev/ttyUSB0");
480 #endif
481  if(bRet){
482  panTiltControlDialog_->SetDPControl(panTiltControl_);
483  panTiltControlDialog_->Show(true);
484  return true;
485  }
486  else{
487  stringstream txt;
488  txt << "Could not open port for Directed Perception Control";
489  wxMessageDialog errorDialog1(this,AsciiToWx(txt.str().c_str()),
490  wxT("ShowCamWx - Error"),wxICON_ERROR|wxOK);
491  errorDialog1.ShowModal();
492  }
493  return false;
494 }
495 #endif //BIAS_HAVE_PANTILT_DP
496 
497 /****************************************************
498 *****************************************************/
499 void ShowCamWxFrame::
501 {
502  if (!InitParams_){
503  BIASERR("Initialize params first");
504  return;
505  }
506 
507  bool foundCamera = false;
508  for (int i = 0; i < NUMBER_CAMERAS; i++) {
509  Cameras_.push_back(NULL);
510  if (*ParamCameras_[i] != ShowCamWxVideoSourceFactory::NONE)
511  foundCamera = true;
512  }
513 
514 
515  //if there were no cams found, exit and wait for a manual camera scan.
516  if (!foundCamera) {
517  return;
518  }else{
519 #ifndef WIN32
520 # ifdef BIAS_HAVE_DCAM
521  int numDcams = 0;
522 # endif //BIAS_HAVE_DCAM
523  for(int i = 0; i < NUMBER_CAMERAS; i++){
524 
525  stringstream errorText;
526  // scan for dcam camera parameters
527  if(*ParamCameras_[i] == 1){
528 #ifdef BIAS_HAVE_DCAM
529  BIAS::ScanBus(IEEECameraInfo_);
530 
531  if(CameraMenu_ == NULL)
532  CameraMenu_ = new wxMenu;
533  // search for the cam
534  for(unsigned int k=0; k< IEEECameraInfo_.size();k++){
535  if(IEEECameraInfo_[k].camid == atoi((*ParamDevice_[i]).c_str())){
536  // add to menu
537  AddIEEECameraToMenu(i,k,true);
538  }
539  }
540  numDcams++;
541 #else
542  errorText << "DCAM Camera in param file, please enable support in BIAS\n";
543  BIASERR("DCAM Camera in param file, please enable support in BIAS");
544 
545 #endif
546  }
547 #else
548  int NumDcams = 0;
549  for(int i = 0; i < NUMBER_CAMERAS; i++){
550  stringstream errorText;
551  // scan for dcam camera parameters
552  if(*ParamCameras_[i] == 1){
553 #ifdef BIAS_HAVE_DCAM
554  BIAS::ScanBus(IEEECameraInfo_);
555 
556  if(CameraMenu_ == NULL)
557  CameraMenu_ = new wxMenu;
558  // search for the cam
559  for(unsigned int k=0; k< IEEECameraInfo_.size();k++){
560  if(IEEECameraInfo_[k].camid == NumDcams + 1){
561  // add to menu
562  stringstream ss;
563  ss << NumDcams + 1;
564  *ParamDevice_[i] = ss.str();
565  AddIEEECameraToMenu(i,k,true);
566 
567  }
568  }
569  NumDcams++;
570 #else
571  errorText << "DCAM Camera in param file, please enable support in BIAS\n";
572  BIASERR("DCAM Camera in param file, please enable support in BIAS");
573 
574 #endif
575  }
576 #endif
577  if(*ParamCameras_[i] == 2){
578 #ifdef BIAS_HAVE_PMD_PMDTec
579  AddPMDTecCameraToMenu(i,true);
580 #else
581  errorText << "PMDTec Camera in param file, please enable support in BIAS\n";
582  BIASERR("PMDTec Camera in param file, please enable support in BIAS");
583 #endif
584  }
585 
586 
587 
588  if(*ParamCameras_[i] == 3){
589 #ifdef BIAS_HAVE_PMD_PMDZess
590  AddZessCameraToMenu(i,true,"");
591 #else
592  errorText << "PMD Zess Camera in param file, please enable support in BIAS\n";
593  BIASERR("PMD Zess Camera in param file, please enable support in BIAS");
594 #endif
595  }
596 
597  if(*ParamCameras_[i] == 5){
598 #ifdef BIAS_HAVE_UEYE
599  AddUEyeCameraToMenu(i,"", true);
600 #else
601  errorText << "UEYE Camera in param file, please enable support in BIAS\n";
602  BIASERR("UEYE Camera in param file, please enable support in BIAS");
603 #endif
604  }
605 
606  if(*ParamCameras_[i] == 9){
607 #ifdef BIAS_HAVE_SWISSRANGER
608  AddSwissRangerCameraToMenu(i,true);
609 #else
610  errorText << "SwissRanger Camera in param file, please enable support in BIAS\n";
611  BIASERR("SwissRanger Camera in param file, please enable support in BIAS");
612 #endif
613  }
614 
615 
616  if(*ParamCameras_[i] != 0) {
617  cout <<"INIT CAM" << endl;
618  InitCamera(i);
619  }
620  }
621  }
622 
623  InitCameras_ = true;
624 
625  OpenDevices();
626 }
627 
628 /****************************************************
629  *****************************************************/
630 void ShowCamWxFrame::InitCamera(int camindex){
631  int i = camindex;
632  stringstream errorText;
633 
634  BufferAccess_[i] = new wxMutex;
635  WriteIndex_[i] = 0;
636  ReadIndex_[i] = BUFFER_SIZE - 1;
637 
638  if(CamImg_[i] == NULL)
639  CamImg_[i] = new Camera<unsigned char> ;
640 
641  //CamImgCombined_.Release();
642 
643  switch(*ParamCameras_[i]){
645  // Cameras_.push_back(NULL);
646  break;
649  SetFirewireB_[i],
650  SetUserMode_[i],
651  SelectedModeFromMenu(i),
652  SelectedFps_[i],
653  Format7BpP_[i],
654  Format7ColorMode_[i],
655  Format7LeftTop_[i],
656  Format7WidthHeight_[i]
657  );
658  break;
660  Cameras_[i] = ShowCamWxVideoSourceFactory::CreatePMD(sourcePlugin_,procPlugin_);
661  break;
668  Cameras_[i] = ShowCamWxVideoSourceFactory::CreateFromTypeIfSupported(*ParamCameras_[i]);
669  break;
671  if (*ParamBitFile_[i] == "") {
672  BIASERR("Specify bit file for usb pmd camera");
673  Cameras_[i] = NULL;
674  } else {
675  Cameras_[i] = ShowCamWxVideoSourceFactory::CreatePMDZess(*ParamBitFile_[i]);
676  }
677  break;
680  break;
683  break;
686 #ifdef BIAS_HAVE_DCAM
687  dynamic_cast<VideoSource_DCAM_BumbleBee*>(Cameras_[i])->SetStereoDefaultMode(&IEEECameraInfo_[i]);
688 #endif
689  break;
692  break;
693  default: // None
694  //Cameras_.push_back(NULL);
695  break;
696  }
697 
698  // create extra images
699  if (Cameras_[camindex] != NULL) {
700  switch(*ParamCameras_[camindex]) {
702  if(CamImgPMDDepth_[camindex] == NULL)
703  CamImgPMDDepth_[camindex] = new Camera<float> ;
704  if(CamImgPMDAmp_[camindex] == NULL)
705  CamImgPMDAmp_[camindex] = new Camera<float> ;
706  if(CamImgPMDInt_[camindex] == NULL)
707  CamImgPMDInt_[camindex] = new Camera<float> ;
708  break;
710  if(CamImgPMDDepth_[camindex] == NULL)
711  CamImgPMDDepth_[camindex] = new Camera<float> ;
712  if(CamImgPMDAmp_[camindex] == NULL)
713  CamImgPMDAmp_[camindex] = new Camera<float> ;
714  break;
716  ColorModels_[i] = Cameras_[i]->GetColorModel();
717  if(XB3AllInOne_[camindex] == NULL)
718  XB3AllInOne_[camindex] = new Camera<unsigned char> ;
719  if(CamImgMiddle_[camindex] == NULL)
720  CamImgMiddle_[camindex] = new Camera<unsigned char> ;
721  if(CamImgRight_[camindex] == NULL)
722  CamImgRight_[camindex] = new Camera<unsigned char> ;
723  break;
726  if(CamImgPMDDepth_[camindex] == NULL)
727  CamImgPMDDepth_[camindex] = new Camera<float> ;
728  break;
730  if(CamImgPMDDepth_[camindex] == NULL)
731  CamImgPMDDepth_[camindex] = new Camera<float> ;
732  if(CamImgPMDInt_[camindex] == NULL)
733  CamImgPMDInt_[camindex] = new Camera<float> ;
734  break;
735  default: // None
736  //Cameras_.push_back(NULL);
737  break;
738  }
739  }
740 
741  if (Cameras_[i] == NULL) {
742  *ParamCameras_[i] = ShowCamWxVideoSourceFactory::NONE;
743  errorText << cameraNames_[i] << " Camera in param file, please enable support in BIAS\n";
744  //Cameras_.push_back(NULL);
745  BIASERR(cameraNames_[i] << " Camera in param file, please enable support in BIAS");
746  wxMessageDialog errorDialog1(this,
747  AsciiToWx(errorText.str().c_str()),
748  wxT("ShowCamWx - Error"),
749  wxICON_ERROR|wxOK);
750  errorDialog1.ShowModal();
751  }
752 
753  if (*ParamHeight_[i] != 0 && *ParamWidth_[i] != 0 && Cameras_[i] != NULL) {
754  Cameras_[i]->SetSize(*ParamWidth_[i], *ParamHeight_[i]);
755  //cout<<"Setting size to :"<<*ParamWidth_[i]<<", "<< *ParamHeight_[i]<<endl;
756  }
757 
758  if (*ParamFPS_[i] != 0.0 && Cameras_[i] != NULL) {
759  cout<<"Setting "<<i<<". camera fps to "<<*ParamFPS_[i]<<endl;
760  Cameras_[i]->SetFPS((float) *ParamFPS_[i]);
761  }
762 
763  CameraInitialized_[i] = true;
764  }//end Init Cameras
765 
766 
767 
768 /****************************************************
769 *****************************************************/
770 int ShowCamWxFrame::OpenDevice(int camindex) {
771 
772  // we have to check which camera type we have
773  int ret = 0;
774  int i = camindex;
775  if(*ParamCameras_[i] == ShowCamWxVideoSourceFactory::NONE)
776  return -1;
777 
778  if(!CameraInitialized_[i]){
779  InitCamera(i);
780  }
781 
782 
784  if (*ParamDevice_[i] != "") {
785  if (Cameras_[i]->GetCapabilities((*ParamDevice_[i]).c_str(),caps) != 0 ) {
786  BIASERR("Could not get Capabilities for device:"<<*ParamDevice_[i]);
787  }
788  }
789  else{
790  if ( Cameras_[i]->GetCapabilities(caps) != 0 ) {
791  BIASERR("Could not get Capabilities.");
792  }
793  }
794 
795  Cameras_[i]->SetDeviceChannel(DeviceChannel_[i]);
796  Cameras_[i]->SetExternalTrigger(SetTrigger_[i]);
797 
798  ret = 0;
799 
800  switch(*ParamCameras_[i]) {
802  break;
805  if (!CameraInitialized_[i]) {
806  InitCamera(i);
807  }
808 
809  ret = ShowCamWxVideoSourceFactory::OpenDevice(*ParamCameras_[i], Cameras_[i], *ParamDevice_[i]);
810 #ifndef WIN32
811  // check if there are multiple cameras with no device name
812  if (ret == -2) {
813  EmptyDevice_ = true;
814  ret = 0;
815  }
816 
817  if (EmptyDevice_) {
818  stringstream text;
819  text << "Found more than one camera with no device name!\n";
820  // <<"Available cameras:\n"<<cameras.str().c_str();
821  wxMessageDialog errorDialog(this,
822  AsciiToWx(text.str().c_str()),
823  wxT("ShowCamWx - Error"),
824  wxICON_ERROR|wxOK);
825  errorDialog.ShowModal();
826  }
827  if (ret < 0) {
828  stringstream text;
829  text << "Camera DCAM " << i << " could not be opened";
830  wxMessageDialog errorDialog(this,
831  AsciiToWx(text.str().c_str()),
832  wxT("ShowCamWx - Error"),
833  wxICON_ERROR|wxOK);
834  errorDialog.ShowModal();
835  return -1;
836  }
837 #endif // WIN32
838  break;
839 
840  default:
841  if (!CameraInitialized_[i]) {
842  InitCamera(i);
843  }
844  if (ShowCamWxVideoSourceFactory::OpenDevice(*ParamCameras_[i], Cameras_[i], *ParamDevice_[i], *ParamPort_[i]) < 0)
845  {
846  delete Cameras_[i];
847  Cameras_[i] = NULL;
848  stringstream text;
849  text << "Camera " << cameraNames_[ *ParamCameras_[i] ] << " " << i << " could not be opened";
850  wxMessageDialog errorDialog(this,
851  AsciiToWx(text.str().c_str()),
852  wxT("ShowCamWx - Error"),
853  wxICON_ERROR|wxOK);
854  errorDialog.ShowModal();
855  *ParamCameras_[i] = ShowCamWxVideoSourceFactory::NONE;
856  return -1;
857  }
858  break;
859  }
860 
861  // show the correct camera
862  NumCamSel_ = camindex;
863 
864  /************************************************/
865  /******* now init images from cameras *****/
866  if (Cameras_[i] != NULL)
867  {
868  // try to set color model from param file for camera
869  if (ColorModels_[i] != ImageBase::CM_invalid)
870  Cameras_[i]->SetColorModel(ColorModels_[i]);
871 
872  // initialize image for camera and grab
873  Cameras_[i]->InitImage(*CamImg_[i]);
874 
875  switch(*ParamCameras_[i]) {
877  break;
879  ShowCamWxVideoSourceFactory::InitImages(*ParamCameras_[i], Cameras_[i], (ImageBase*)CamImg_[i], (ImageBase*)CamImgMiddle_[i], (ImageBase*)CamImgRight_[i], (ImageBase*)XB3AllInOne_[i]);
880  break;
882  ShowCamWxVideoSourceFactory::InitImages(*ParamCameras_[i], Cameras_[i], (ImageBase*)CamImg_[i], (ImageBase*)CamImgPMDDepth_[i]);
883  break;
888  ShowCamWxVideoSourceFactory::InitImages(*ParamCameras_[i], Cameras_[i], (ImageBase*)CamImgPMDDepth_[i], (ImageBase*)CamImgPMDAmp_[i], (ImageBase*)CamImgPMDInt_[i]);
889  break;
891  ShowCamWxVideoSourceFactory::InitImages(*ParamCameras_[i], Cameras_[i], (ImageBase*)CamImg_[i], (ImageBase*)CamImgPMDDepth_[i], (ImageBase*)CamImgPMDInt_[i]);
892  break;
893  }
894 
895 #ifdef BIAS_DEBUG
896  cout<<"Initialized image with size "<<CamImg_[i]->GetWidth()<<" x "<<CamImg_[i]->GetHeight()
897  <<" and "<<CamImg_[i]->GetChannelCount()<<" color channels"<<endl;
898 #endif
899 
900  ret = Cameras_[i]->PreGrab();
901  if(ret < 0) return ret;
902  Cameras_[i]->SetDebugLevel(1);
903 
904 #ifdef BIAS_HAVE_V4L
905  if(dynamic_cast<VideoSource_V4L*>(Cameras_[i]) != NULL)
906  Cameras_[i]->SetWaitForNew(true);
907 #endif
908 
909  /******* now start the threads for grabbing *****/
910  //check if camera is used
911  if(!ThreadInited_[camindex])
912  ret = CreateGrabThreadForCamera_(i);
913  if(ret < 0) return ret;
914  }// end if Cameras_[i] != NULL
915 
916  /************************************************/
917  // Set CameraActive
918  CameraActive_[camindex] = true;
919  OpenedDevices_ = true;
920 
921  // activate selection of camera
922  if(menuShow != NULL)
923  menuShow->Enable(ID_Show1 + camindex, true);
924 
925  // init and start timer
926  if (!TimerActive_) {
927  StopWatch_.Start();
928  TimerActive_ = true;
929  }
930 
931  ActiveCameras_++;
932  return ret;
933 }
934 
935 /****************************************************
936 *****************************************************/
937 int ShowCamWxFrame::CloseDevice(int camindex) {
938  // close device and reinitialize variables
939  int ret =0;
940  if(grabSingleThread_[camindex] != NULL){
941  ThreadInited_[camindex] = false;
942  grabSingleThread_[camindex]->Delete();
943  //delete grabSingleThread_[camindex];
944  grabSingleThread_[camindex] = NULL;
945  biassleep(1);
946  }
947  bool gmtLocked = false;
948  bool noCamActive = false;
949  if (grabMasterThread_ != NULL && Cameras_[camindex] != NULL) {
950  ServerMutex_[camindex]->Lock();
951  gmtLocked = true;
952  }
953 
954  if(saveThreads_[camindex] != NULL){
955  saveThreads_[camindex]->Delete();
956  delete saveThreads_[camindex];
957  saveThreads_[camindex] = NULL;
958  }
959 
960  if(BufferAccess_[camindex] != NULL){
961  delete BufferAccess_[camindex];
962  BufferAccess_[camindex] = NULL;
963  }
964 
965  WriteIndex_[camindex] = 0;
966  ReadIndex_[camindex] = BUFFER_SIZE - 1;
967 
968  CameraActive_[camindex] = false;
969  CameraInitialized_[camindex] = false;
970 
971  if(CamImg_[camindex]!= NULL){
972  delete CamImg_[camindex];
973  CamImg_[camindex] = NULL;
974  }
975  if(CamImgPMDDepth_[camindex]!= NULL){
976  delete CamImgPMDDepth_[camindex];
977  CamImgPMDDepth_[camindex] = NULL;
978  }
979  if(CamImgPMDAmp_[camindex]!= NULL){
980  delete CamImgPMDAmp_[camindex];
981  CamImgPMDAmp_[camindex] = NULL;
982  }
983  if(CamImgPMDInt_[camindex]!= NULL){
984  delete CamImgPMDInt_[camindex];
985  CamImgPMDInt_[camindex] = NULL;
986  }
987  if(CamImgMiddle_[camindex]!= NULL){
988  delete CamImgMiddle_[camindex];
989  CamImgMiddle_[camindex] = NULL;
990  }
991  if(CamImgRight_[camindex]!= NULL){
992  delete CamImgRight_[camindex];
993  CamImgRight_[camindex] = NULL;
994  }
995  if(XB3AllInOne_[camindex]!= NULL){
996  delete XB3AllInOne_[camindex];
997  XB3AllInOne_[camindex] = NULL;
998  }
999 
1000  if(ViewColorMode_[camindex] != ImageBase::CM_invalid){
1001  ViewColorMode_[camindex] = ImageBase::CM_invalid;
1002  }
1003 
1004  menuShow->Enable(ID_Show1 + camindex, false);
1005 
1006 
1007  if (Cameras_[camindex] != NULL) {
1008  Cameras_[camindex]->PostGrab();
1009  Cameras_[camindex]->CloseDevice();
1010  delete Cameras_[camindex];
1011  Cameras_[camindex] = NULL;
1012  ActiveCameras_--;
1013  noCamActive = (ActiveCameras_ == 0);
1014  }
1015 
1016  if (gmtLocked) {
1017  ServerCondition_[camindex]->Signal();
1018  ServerMutex_[camindex]->Unlock();
1019  }
1020 
1021  // maybe stop and reset timer
1022  if(noCamActive) {
1023  StopWatch_.Stop();
1024  TimerActive_ = false;
1025  if(grabMasterThread_ != NULL){
1026  grabMasterThread_->Delete();
1027  //delete grabMasterThread_;
1028  grabMasterThread_=NULL;
1029  }
1030  if(ServerCondition_[camindex] !=NULL){
1031  delete ServerCondition_[camindex];
1032  ServerCondition_[camindex]=NULL;
1033  }
1034  if(ServerMutex_[camindex] !=NULL){
1035  delete ServerMutex_[camindex];
1036  ServerMutex_[camindex]=NULL;
1037  }
1038  if(ClientsCondition_[camindex] !=NULL){
1039  delete ClientsCondition_[camindex];
1040  ClientsCondition_[camindex]=NULL;
1041  }
1042  if(ClientsMutex_[camindex] !=NULL){
1043  delete ClientsMutex_[camindex];
1044  ClientsMutex_[camindex]=NULL;
1045  }
1046  }
1047  //cout<<"Closed Device :"<<camindex<<endl;
1048  return ret;
1049 }
1050 
1051 /****************************************************
1052 *****************************************************/
1054  if (!InitCameras_) {
1055  BIASERR("Initialize cameras first");
1056  return;
1057  }
1058 
1059  for (int i = 0; i < NUMBER_CAMERAS; i++) {
1060  OpenDevice(i);
1061  }
1062 }
1063 
1064 /****************************************************
1065 *****************************************************/
1067 #ifdef BIAS_HAVE_DCAM
1068  int menuindex = (camindex + 1) * 10000;
1069  // cout<<"Menuindex:"<<menuindex<<endl;
1070  dc1394video_mode_t mode = DC1394_VIDEO_MODE_640x480_MONO8;
1071  bool foundItem = false;
1072 
1073  //Never!! commit such things!!
1074  //return DC1394_VIDEO_MODE_640x480_RGB8;
1075 
1076  while(!foundItem){
1077  menuindex++;
1078  wxMenuItem* menuItem = CameraMenu_->FindItem(menuindex);
1079  if(menuItem!= NULL && menuItem->IsChecked()){
1080  foundItem = true;
1081  }
1082  }
1083 
1084  //cout << "Checked Item: " << (menuindex % 10000 - 1) << endl;
1085  int modeindex = (menuindex % 10000 - 1);
1086 
1087  for(unsigned int k=0; k< IEEECameraInfo_.size();k++){
1088  if(IEEECameraInfo_[k].camid == atoi((*ParamDevice_[camindex]).c_str())){
1089  // add to menu
1090  mode = IEEECameraInfo_[k].videoModes[modeindex];
1091  }
1092  }
1093  cout << "Found mode: " << mode << endl;
1094  return (int)mode;
1095 #else
1096  return -1;
1097 #endif
1098  }
1099 
1100 
1101 /****************************************************
1102 *****************************************************/
1104  // create file menu
1105  wxMenu *menuFile = new wxMenu;
1106  menuFile->Append(ID_Grab, wxT("Grab &single image") );
1107  menuFile->AppendCheckItem(ID_GrabContinuous, wxT("Grab &continuously (Start/Stop)") );
1108  menuFile->AppendCheckItem(ID_GrabToStream, wxT("Grab to stream (Start/Stop)") );
1109  menuFile->AppendSeparator();
1110  menuFile->Append(wxID_EXIT, wxT("E&xit") );
1111 
1112  menuShow = new wxMenu;
1113 
1114  menuShow->Append(ID_Show1, wxT("Camera &1") );
1115  menuShow->Append(ID_Show2, wxT("Camera &2") );
1116  menuShow->Append(ID_Show3, wxT("Camera &3") );
1117  menuShow->Append(ID_Show4, wxT("Camera &4") );
1118  menuShow->Append(ID_Show5, wxT("Camera &5") );
1119  menuShow->Append(ID_Show6, wxT("Camera &6") );
1120  menuShow->Append(ID_Show7, wxT("Camera &7") );
1121  menuShow->Append(ID_Show8, wxT("Camera &8") );
1122  menuShow->Append(ID_Show9, wxT("Camera &9") );
1123  menuShow->AppendSeparator();
1124  menuShow->Append(ID_Controller, wxT("&Controller") );
1125  menuShow->Append(ID_SHOW_CAMERALIST, wxT("Camera &List") );
1126 
1127  if(CameraMenu_ == NULL)
1128  CameraMenu_ = new wxMenu;
1129 
1130 
1131  wxMenu *menuSearchCameras = new wxMenu;
1132  menuSearchCameras->Append(ID_FindIEEE1394, wxT("Scan for IEEE1394 Camera") );
1133  menuSearchCameras->Append(ID_FindUEYE, wxT("Scan for UEYE Camera") );
1134 #ifdef BIAS_HAVE_V4L
1135  menuSearchCameras->Append(ID_FindWebcams, wxT("Scan for Video4Linux cameras") );
1136 #endif
1137 #ifdef BIAS_HAVE_SHOW
1138  menuSearchCameras->Append(ID_FindWebcams, wxT("Scan for DShow cameras") );
1139 #endif
1140  menuSearchCameras->Append(ID_FindSwissranger, wxT("Scan for Swissranger ToF") );
1141  menuSearchCameras->Append(ID_FindZess, wxT("Scan for Zess ToF") );
1142  menuSearchCameras->Append(ID_FindPMDTec, wxT("Scan for PMDTec ToF") );
1143  menuSearchCameras->Append(ID_FindKinect, wxT("Scan for Kinect") );
1144  menuSearchCameras->Append(ID_FindOpenNI, wxT("Scan for OpenNI") );
1145  menuSearchCameras->Append(ID_FindKinect2, wxT("Scan for Kinect2 (freenect2)") );
1146  //menuSearchCameras->Append(ID_FindV4L, wxT("Scan for Video for Linux Camera") );
1147 
1148 
1149  wxMenu *menuParameters = new wxMenu;
1150  menuParameters->Append(ID_SaveParameters, wxT("Save Parameters") );
1151  menuParameters->Append(ID_ShowParameters, wxT("Show Parameters") );
1152 
1153  wxMenu *menuHelp = new wxMenu;
1154  menuHelp->Append(wxID_ABOUT);
1155 
1156  wxMenu *menuSpecial= new wxMenu;
1157  menuSpecial->Append(ID_OpenFlirController, wxT("Open FLIR Thermal Camera Controller") );
1158 #ifdef BIAS_HAVE_PANTILT
1159  menuSpecial->Append(ID_OpenViscaController, wxT("Open Sony VISCA PanTilt Controller") );
1160 #endif
1161 
1162 #ifdef BIAS_HAVE_PANTILT_DP
1163  menuSpecial->Append(ID_OpenDPController, wxT("Directed Percpetion PanTilt Controller") );
1164 #endif
1165 
1166  // add menues to menu bar
1167  wxMenuBar *menuBar = new wxMenuBar;
1168  menuBar->Append(menuFile, wxT("&File"));
1169  menuBar->Append(CameraMenu_, wxT("&Cameras"));
1170  menuBar->Append(menuSearchCameras, wxT("Camera &Scan"));
1171  menuBar->Append(menuParameters, wxT("&Parameters"));
1172  menuBar->Append(menuSpecial, wxT("&Extras"));
1173  menuBar->Append(menuShow, wxT("&Show"));
1174  menuBar->Append(menuHelp, wxT("&Help"));
1175 
1176  SetMenuBar(menuBar);
1177 
1178  // deactivate uninitialized cameras
1179  for (int i = 0; i < NUMBER_CAMERAS; i++) {
1180  if (Cameras_[i] == NULL) {
1181  menuShow->Enable(ID_Show1 + i, false);
1182  }
1183  }
1184 
1185  // fit all components to size of window
1186  Fit();
1187 }
1188 
1189 /****************************************************
1190 *****************************************************/
1192  CameraMenu_ = new wxMenu;
1193 }
1194 
1195 #ifdef BIAS_HAVE_PANTILT_DP
1196 
1197 /****************************************************
1198  *****************************************************/
1199 void ShowCamWxFrame::
1200 GetProjectionFromPanTilt_(BIAS::Projection &projHeader)
1201 {
1202  double pan=0.0, tilt=0.0;
1203  //panTiltControl_->GetCurrentPositionRadiansThreaded(pan, tilt);
1204  panTiltControl_->GetCurrentPositionRadians(pan, tilt);
1205  pan = -pan; // HACK : Flip sign of pan angle!
1206  std::cout<<"Current Position: "<<pan*180.0/M_PI<<", "<<tilt*180.0/M_PI<< " degree"<<std::endl;
1207 
1208  // rotation matrix resulting from panning
1209  BIAS::RMatrix pan_matrix = BIAS::RMatrix(BIAS::Vector3<double>(0,1,0), pan);
1210  // rotation matrix resulting from tilting
1211  BIAS::RMatrix tilt_matrix = BIAS::RMatrix(BIAS::Vector3<double>(1,0,0), tilt);
1212 
1213  // new modelling of ptu pose:
1214  // first, pan ptu
1216 
1217  // tilt ptu
1219 
1220  // identity matrix
1221  BIAS::Matrix3x3<double> id33 = BIAS::Matrix3x3<double>(1,0,0, 0,1,0, 0,0,1);
1222  // translation from rotation joint to camera center
1223  BIAS::Vector3<double> translation(0.0, 0.0, 0.0);
1224  BIAS::Matrix4x4<double> trans_to_camera_center = BIAS::Matrix4x4<double>(id33, translation);
1225 
1226  // calculate complete ptu transformation matrix
1227  BIAS::Matrix4x4<double> ptu_result = tilt_ptu * pan_ptu * trans_to_camera_center;
1228 
1229  // do some hackish access to the translation part of resulting matrix
1230  BIAS::Vector4<double> translation_rotated4 = ptu_result.GetCol(3);
1231  BIAS::Vector3<double> translation_rotated3;
1232  double *translation_rotated4_ptr = translation_rotated4.GetData();
1233  for (int i=0;i<3;i++)
1234  translation_rotated3.GetData()[i] = translation_rotated4_ptr[i];
1235 
1236  // store transformation in dynamic data pool entry
1237  Pose p;
1238  Quaternion<double> panq;
1239  pan_matrix.GetQuaternion(panq);
1240  Quaternion<double> tiltq;
1241  tilt_matrix.GetQuaternion(tiltq);
1242  Quaternion<double> temp = panq * tiltq;
1243  p.SetC(translation_rotated3);
1244  p.SetQ(temp);
1245  KMatrix K;
1246  projHeader.CreatePerspective(p,K,640,480);
1247  cout<<"Projection:"<<projHeader<<endl;
1248 }
1249 #endif
1250 
1251 
1252 /****************************************************
1253 *****************************************************/
1254 void ShowCamWxFrame::
1256 {
1257  bWriteBuffered_=false;
1258 
1259  for (int i = 0; i < NUMBER_CAMERAS; i++){
1260  if(saveThreads_[i]!=NULL && Cameras_[i] != NULL){
1261  // cout<<"Pausing camera :"<<i<<endl;
1262  saveThreads_[i]->Delete();
1263  saveThreads_[i] = NULL;
1264  //cout << "\n\nSaveThread for cam: " << i << " paused\n\n" << endl;
1265  }
1266  }
1267  //for (int i = 0; i < NUMBER_CAMERAS; i++){
1268  // if(saveThreads_[i]!=NULL && Cameras_[i] != NULL){
1269  // saveThreads_[i]->FinishSaving();
1270  // }
1271  //}
1272  cout << "leave StopSavingThreads" << endl;
1273 }
1274 
1275 /****************************************************
1276 *****************************************************/
1277 void ShowCamWxFrame::
1279 {
1280 
1281  //try to create a new directory, skip of already exists
1282  int ret =-1;
1283  while(ret != 0){
1284  stringstream dir;
1285  dir <<"Take"<<FileHandling::LeadingZeroString(dDirIndex_,5)<<"/";
1286  currentSaveDir_ = dir.str().c_str();
1287  #ifdef WIN32
1288  ret = _mkdir(dir.str().c_str());
1289  #else //WIN32
1290  ret = mkdir(dir.str().c_str(), 0755);
1291  #endif //WIN32
1292  dDirIndex_++;
1293  }
1294 
1295  // important!! This triggers the write to buffer in threads!
1296  bWriteBuffered_ = true;
1297 
1298  //create a dummy Projection to save Pan Tilt angles in Image headers
1299  BIAS::Projection projHeader;
1300 
1301  #ifdef BIAS_HAVE_PANTILT_DP
1302  if(*bUsePanTiltUnit_){
1303  GetProjectionFromPanTilt_(projHeader);
1304  }
1305  #endif //BIAS_HAVE_PANTILT_DP
1306 
1307  for (int i = 0; i < NUMBER_CAMERAS; i++){
1308  // check if camera is opened
1309  if(Cameras_[i] != NULL){
1310 
1311  #ifdef BIAS_HAVE_PANTILT_DP
1312  if(*bUsePanTiltUnit_){
1313  (*CamImg_[i]).SetProj(projHeader);
1314  (*CamImg_[i]).UpdateMetaData();
1315  }
1316  #endif //BIAS_HAVE_PANTILT_DP
1317 
1318  if(saveThreads_[i] == NULL){
1319  //Here create ImageSaveThreadForCamera
1320  CreateImageSaveThreadForCamera_(i);
1321  saveThreads_[i]->SetSaveDirectory(currentSaveDir_);
1322  }
1323  else{
1324  // signal thread to save a single image
1325  saveThreads_[i]->SetSaveDirectory(currentSaveDir_);
1326  saveThreads_[i]->ResetCounter();
1327  saveThreads_[i]->Resume();
1328  }
1329  }//end else
1330 
1331  }//end for all cameras
1332 }
1333 
1334 /****************************************************
1335 *****************************************************/
1336 void ShowCamWxFrame::
1338 {
1339  for (int i = 0; i < NUMBER_CAMERAS; i++) {
1340  switch(*ParamColorModel_[i]) {
1341  case 0: ColorModels_[i] = ImageBase::CM_invalid; break;
1342  case 1: ColorModels_[i] = ImageBase::CM_Grey; break;
1343  case 2: ColorModels_[i] = ImageBase::CM_RGB; break;
1344  case 3: ColorModels_[i] = ImageBase::CM_BGR; break;
1345  case 4: ColorModels_[i] = ImageBase::CM_YUYV422; break;
1346  case 5: ColorModels_[i] = ImageBase::CM_UYVY422; break;
1347  case 6: ColorModels_[i] = ImageBase::CM_YUV420P; break;
1348  case 7: ColorModels_[i] = ImageBase::CM_YUV444; break;
1349  case 8: ColorModels_[i] = ImageBase::CM_YUV411; break;
1350  case 9: ColorModels_[i] = ImageBase::CM_HSV; break;
1351  case 10: ColorModels_[i] = ImageBase::CM_HSI_OBS; break;
1352  case 11: ColorModels_[i] = ImageBase::CM_DV; break;
1353  case 12: ColorModels_[i] = ImageBase::CM_RGBA; break;
1354  case 13: ColorModels_[i] = ImageBase::CM_GreyA; break;
1355  case 14: ColorModels_[i] = ImageBase::CM_Bayer_RGGB; break;
1356  case 15: ColorModels_[i] = ImageBase::CM_Bayer_GBRG; break;
1357  case 16: ColorModels_[i] = ImageBase::CM_Bayer_GRBG; break;
1358  case 17: ColorModels_[i] = ImageBase::CM_Bayer_BGGR; break;
1359  case 18: ColorModels_[i] = ImageBase::CM_HSL; break;
1360  case 19: ColorModels_[i] = ImageBase::CM_hsL; break;
1361  case 20: ColorModels_[i] = ImageBase::CM_SymTensor2x2; break;
1362  case 21: ColorModels_[i] = ImageBase::CM_BGRA; break;
1363  case 22: ColorModels_[i] = ImageBase::CM_RGBE; break;
1364  default: ColorModels_[i] = ImageBase::CM_invalid; break;
1365  }
1366  }
1367 }
1368 
1369 /****************************************************
1370  *****************************************************/
1371 void ShowCamWxFrame::
1373 {
1374  // kinect, openni
1375  if (*ParamCameras_[NumCamSel_] == ShowCamWxVideoSourceFactory::KINECT || *ParamCameras_[NumCamSel_] == ShowCamWxVideoSourceFactory::OPENNI) {
1376  unsigned int w = CamImg_[NumCamSel_]->GetWidth()*2;
1377  unsigned int h = CamImg_[NumCamSel_]->GetHeight();
1378  if (!CamImgCombined_.IsEmpty()) {
1379  if (CamImgCombined_.GetColorModel() != ImageBase::CM_RGB
1380  || CamImgCombined_.GetWidth() != w || CamImgCombined_.GetHeight() != h)
1381  {
1382  CamImgCombined_.Release();
1383  }
1384  }
1385  if (CamImgCombined_.IsEmpty()) {
1386  CamImgCombined_.Init(w,h,3);
1387  CamImgCombined_.SetColorModel(ImageBase::CM_RGB);
1388  }
1390  ImageConvert::ToRGB(*CamImg_[NumCamSel_], tmpRgb);
1391 
1392  CamImgCombined_.SetROICorners(0, 0,
1393  CamImg_[NumCamSel_]->GetWidth(),
1394  CamImg_[NumCamSel_]->GetHeight());
1395 
1396  CamImgCombined_.Paste2ROI(tmpRgb);
1397  CamImgCombined_.SetROICorners(CamImg_[NumCamSel_]->GetWidth(),
1398  0,
1399  CamImg_[NumCamSel_]->GetWidth() * 2,
1400  CamImg_[NumCamSel_]->GetHeight());
1401  if(CamImgPMDDepth_[NumCamSel_] != NULL){
1402  BIAS::Camera<float> tmpImg;
1403  BIAS::Camera<unsigned char> tmpImgUC;
1404  tmpImg = *CamImgPMDDepth_[NumCamSel_];
1405  tmpImg.AboveThresholdToValue(7000,7000);
1406  tmpImg.BelowThresholdToValue(1000,1000);
1407  tmpImg.ScaleShiftBetween(0,255);
1408 
1410  BIAS::ImageConvert::ToRGB(tmpImgUC, tmpRgb);
1411  CamImgCombined_.Paste2ROI(tmpRgb);
1412  }
1413  }
1414  // kinect2
1415  else if (*ParamCameras_[NumCamSel_] == ShowCamWxVideoSourceFactory::FREENECT2) {
1416  unsigned int w = 1920;
1417  unsigned int h = 1080 + 424;
1418  if (!CamImgCombined_.IsEmpty()) {
1419  if (CamImgCombined_.GetColorModel() != ImageBase::CM_RGB
1420  || CamImgCombined_.GetWidth() != w || CamImgCombined_.GetHeight() != h)
1421  {
1422  CamImgCombined_.Release();
1423  }
1424  }
1425  if (CamImgCombined_.IsEmpty()) {
1426  CamImgCombined_.Init(w,h,3);
1427  CamImgCombined_.SetColorModel(ImageBase::CM_RGB);
1428  }
1429  CamImgCombined_.SetROICorners(0, 0, 1920, 1080);
1430 
1431  CamImgCombined_.Paste2ROI(*CamImg_[NumCamSel_]);
1432 
1433  BIAS::Camera<float> tmpImg;
1434  BIAS::Camera<unsigned char> tmpImgUC;
1436 
1437  CamImgCombined_.SetROICorners(0, 1080, 512, 1080 + 424);
1438  if(CamImgPMDDepth_[NumCamSel_] != NULL){
1439  tmpImg = *CamImgPMDDepth_[NumCamSel_];
1440  tmpImg.AboveThresholdToValue(7000,7000);
1441  tmpImg.BelowThresholdToValue(0,0);
1442  tmpImg.ScaleShiftBetween(0,255);
1444  BIAS::ImageConvert::ToRGB(tmpImgUC, tmpRgb);
1445  CamImgCombined_.Paste2ROI(tmpRgb);
1446  }
1447  CamImgCombined_.SetROICorners(512, 1080, 512+512, 1080 + 424);
1448  if(CamImgPMDInt_[NumCamSel_] != NULL){
1449  tmpImg = *CamImgPMDInt_[NumCamSel_];
1450  tmpImg.AboveThresholdToValue(20000,20000);
1451  tmpImg.BelowThresholdToValue(0,0);
1452  tmpImg.ScaleShiftBetween(0,255);
1454  BIAS::ImageConvert::ToRGB(tmpImgUC, tmpRgb);
1455  CamImgCombined_.Paste2ROI(tmpRgb);
1456  }
1457  }
1458  // pmd tec
1459  else {
1460  unsigned wImg,wAmp,wDepth,hImg,hAmp,hDepth;
1461  ClientsMutex_[NumCamSel_]->Lock();
1462  BIAS::Camera<float> imgAmp = *CamImgPMDAmp_[NumCamSel_];
1463  BIAS::Camera<float> imgDepth= *CamImgPMDDepth_[NumCamSel_];
1464  BIAS::Camera<unsigned char> img = *CamImg_[NumCamSel_];
1465  ClientsMutex_[NumCamSel_]->Unlock();
1466  wImg = img.GetWidth();
1467  hImg = img.GetHeight();
1468  wAmp = imgAmp.GetWidth();
1469  hAmp = imgAmp.GetHeight();
1470  wDepth = imgDepth.GetWidth();
1471  hDepth = imgDepth.GetHeight();
1472 
1473  if(!CamImgCombined_.IsEmpty()) {
1474  CamImgCombined_.Release();
1475  }
1476  // initialize combined image from pmd usb camera images
1477  CamImgCombined_.Init(wImg + wAmp + wDepth, hImg);
1478  CamImgCombined_.SetColorModel(ImageBase::CM_Grey);
1479  if(wImg > 0 && hImg> 0)
1480  {
1481  CamImgCombined_.SetROICorners(0, 0, wImg,hImg);
1482  CamImgCombined_.Paste2ROI(img);
1483  }
1484 
1485  // add Amp image from pmd usb camera
1486  BIAS::Camera<unsigned char> tmpImgUC;
1487  if(!imgAmp.IsEmpty() && wAmp > 0 && hAmp > 0)
1488  {
1489  CamImgCombined_.SetROICorners(wImg, 0, wImg + wAmp, hAmp);
1490 
1491  imgAmp.ScaleShiftBetween(0,255);
1494  CamImgCombined_.Paste2ROI(tmpImgUC);
1495  }
1496  // add Depth image from pmd usb camera
1497  if(!imgDepth.IsEmpty() && wDepth > 0 && hDepth > 0)
1498  {
1499  CamImgCombined_.SetROICorners(wImg + wAmp, 0,
1500  wImg + wAmp + wDepth, hDepth);
1501 
1502  imgDepth.AboveThresholdToValue(7000,7000);
1503  imgDepth.BelowThresholdToValue(1000,1000);
1504  imgDepth.ScaleShiftBetween(0,255);
1505 
1508  CamImgCombined_.Paste2ROI(tmpImgUC);
1509  }
1510  }
1511 }
1512 
1513 /****************************************************
1514  *****************************************************/
1515 void ShowCamWxFrame::
1516 OnSaveParameters(wxCommandEvent& event){
1517 
1518  wxString fileName;
1519  wxFileDialog dialog(this,wxT("Save Parameters"),wxT(""),wxT(""),
1520  wxT("MIP Parameter files (*.param)|*.param"),
1521  wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1522  int ret = dialog.ShowModal();
1523  if(ret == wxID_OK){
1524  fileName = dialog.GetPath();
1525  WriteParameter(WxToAscii(fileName));
1526  }
1527 }
1528 /****************************************************
1529  *****************************************************/
1530 void ShowCamWxFrame::
1531 OnWindowClose(wxCloseEvent& event){
1532  //cout << "window close event!!!!!!!!" << endl;
1533  CleanUpAndExit();
1534  //Close(true);
1535  Destroy();
1536 }
1537 
1538 /****************************************************
1539  *****************************************************/
1540 void ShowCamWxFrame::
1542 {
1543  if(!CleanedUp_){
1544  // stop timer
1545  Timer_.Stop();
1546 
1547  // close open controller windows
1548  for (unsigned int i = 0; i < VideoControllers_.size(); i++) {
1549  if (VideoControllers_[i] != NULL) {
1550  if (VideoControllers_[i]->IsShown()) {
1551  VideoControllers_[i]->Close();
1552  delete VideoControllers_[i];
1553  }
1554  }
1555  }
1556 
1557  // first delete threads while timer is running
1558  //cout << "start killing threads" << endl;
1559  for (int i = 0; i < NUMBER_CAMERAS; i++) {
1560  CloseDevice(i);
1561  }
1562 
1563  for (unsigned int i = 0; i < ServerMutex_.size();i++) {
1564  if(ServerMutex_[i] != NULL)
1565  delete ServerMutex_[i];
1566  ServerMutex_[i]=NULL;
1567  if(ServerCondition_[i] != NULL)
1568  delete ServerCondition_[i];
1569  ServerCondition_[i] = NULL;
1570  if(ClientsMutex_[i] != NULL)
1571  delete ClientsMutex_[i];
1572  ClientsMutex_[i]=NULL;
1573  if(ClientsCondition_[i] != NULL)
1574  delete ClientsCondition_[i];
1575  ClientsCondition_[i] = NULL;
1576  }
1577 
1578  #ifdef BIAS_HAVE_PANTILT_DP
1579  if(*bUsePanTiltUnit_){
1580  if(panTiltControlDialog_->IsShown())
1581  panTiltControlDialog_->Hide();
1582  delete panTiltControlDialog_;
1583 
1584  if(panTiltControl_ != NULL){
1585  panTiltControl_->SetPosition(0,0);
1586  panTiltControl_->ClosePanTiltUnit();
1587  delete panTiltControl_;
1588  }
1589  }
1590  #endif //BIAS_HAVE_PANTILT_DP
1591 
1592  CleanedUp_ = true;
1593  }
1594 
1595  cout << "Cleaned up successfully" << endl;
1596 }
1597 
1598 /****************************************************
1599  *****************************************************/
1600 void ShowCamWxFrame::OnFit(wxCommandEvent& WXUNUSED(event))
1601 {
1602  if (pCheckBoxKeepScrollPosition != NULL)
1603  {
1604  if (IC_!=NULL){
1605  IC_->KeepScrollPosition(pCheckBoxKeepScrollPosition->IsChecked());
1606  }
1607  }
1608 }
1609 
1610 /****************************************************
1611  *****************************************************/
1612 void ShowCamWxFrame::OnKeepScrollPosition(wxCommandEvent& WXUNUSED(event))
1613 {
1614  if (pCheckBoxKeepScrollPosition != NULL)
1615  {
1616  if (IC_!=NULL){
1617  IC_->KeepScrollPosition(pCheckBoxKeepScrollPosition->IsChecked());
1618  }
1619  }
1620 }
1621 
1622 /****************************************************
1623  *****************************************************/
1624 void ShowCamWxFrame::
1625 OnQuit(wxCommandEvent& event)
1626 {
1627  CleanUpAndExit();
1628  //Close(true);
1629  Destroy();
1630 }
1631 
1632 /****************************************************
1633  *****************************************************/
1634 void ShowCamWxFrame::
1635 OnGrab(wxCommandEvent& event)
1636 {
1637  if(!bSingleSaveDirCreated_){
1638  int ret =-1;
1639 
1640  while(ret != 0){
1641  stringstream dir;
1642  dir <<"SingleTake"<<FileHandling::LeadingZeroString(dSingleDirIndex_,5)<<"/";
1643  currentSingleSaveDir_ = dir.str().c_str();
1644 
1645 #ifdef WIN32
1646  ret = _mkdir(dir.str().c_str());
1647 #else //WIN32
1648  ret = mkdir(dir.str().c_str(), 0755);
1649 #endif //WIN32
1650 
1651  dSingleDirIndex_++;
1652  }
1653  bSingleSaveDirCreated_ = true;
1654  }
1655 
1656  for (int i = 0; i < NUMBER_CAMERAS; i++){
1657  if(Cameras_[i] != NULL){
1658  SaveImageUnthreaded_(i);
1659  }
1660  }
1661  GrabCounter_++;
1662 }
1663 
1664 /****************************************************
1665  *****************************************************/
1666 void ShowCamWxFrame::
1667 OnGrabContinuous(wxCommandEvent& event)
1668 {
1669  // reset counter and enable/disable continuous saving of images
1670  FrameCounter_ = 0;
1671  bSaveImages_ = !bSaveImages_;
1672  bSaveToStream_ = false;
1673  if (bSaveImages_){
1674  StartSavingImagesToDisk();
1675  pButtonContinuous->SetLabel(_T("Stop"));
1676  }
1677  else{
1678  StopSavingImagesToDisk();
1679  pButtonContinuous->SetLabel(_T("Grab Cont."));
1680  }
1681 }
1682 /****************************************************
1683 *****************************************************/
1684 void ShowCamWxFrame::
1685 OnGrabToStream(wxCommandEvent& event)
1686 {
1687  // reset counter and enable/disable continuous saving of images
1688  FrameCounter_ = 0;
1689  bSaveImages_ = !bSaveImages_;
1690  bSaveToStream_ = true;
1691  if (bSaveImages_){
1692  StartSavingImagesToDisk();
1693  pButtonStream->SetLabel(_T("Stop"));
1694  }
1695  else{
1696  StopSavingImagesToDisk();
1697  pButtonStream->SetLabel(_T("Grab to Stream"));
1698  }
1699 }
1700 
1701 /****************************************************
1702 *****************************************************/
1703 void ShowCamWxFrame::OnClickCamerasListBox(wxCommandEvent& event){
1704  int sel = event.GetSelection();
1705  if(sel < NumOfCams_)
1706  NumCamSel_ = sel;
1707 }
1708 /****************************************************
1709 *****************************************************/
1710 void ShowCamWxFrame::OnHideCamerasListBox(wxCommandEvent& event){
1711  splitterWindow_->Unsplit(cameraListPanel_);
1712 }
1713 /****************************************************
1714 *****************************************************/
1715 void ShowCamWxFrame::OnShowCamerasListBox(wxCommandEvent& event){
1716  //split between notebook and ImagelistPanel
1717  splitterWindow_->SplitVertically(IC_,cameraListPanel_,-1);
1718 }
1719 
1720 /****************************************************
1721  *****************************************************/
1722 void ShowCamWxFrame::
1723 OnShowImage(wxCommandEvent& event)
1724 {
1725  NumCamSel_ = event.GetId() - ID_Show1;
1726 }
1727 
1728 
1729 /****************************************************
1730  *****************************************************/
1731 void ShowCamWxFrame::
1732 OnShowController(wxCommandEvent& event)
1733 {
1734  // check if camera is initialized
1735  if (Cameras_[NumCamSel_] != NULL) {
1736  if (VideoControllers_[NumCamSel_] == NULL) {
1737  VideoControllers_[NumCamSel_] =
1738  ShowCamWxVideoSourceFactory::CreateController((ShowCamWxVideoSourceFactory::CameraType)(*ParamCameras_[NumCamSel_]), Cameras_[NumCamSel_], this);
1739  if (VideoControllers_[NumCamSel_] == NULL) {
1740  BIASERR("Controller could not be created");
1741  } else {
1742  VideoControllers_[NumCamSel_]->Show(true);
1743  }
1744  } else {
1745  VideoControllers_[NumCamSel_]->Show(true);
1746  }
1747  }
1748  // camera was not initalized
1749  else {
1750  wxMessageDialog errorDialog(this,
1751  wxT("No correct camera was selected"),
1752  wxT("ShowCamWx - Error"),
1753  wxICON_ERROR|wxOK);
1754  errorDialog.ShowModal();
1755  }
1756 }
1757 
1758 /****************************************************
1759  *****************************************************/
1760 void ShowCamWxFrame::
1761 OnTimer(wxTimerEvent& event)
1762 {
1763  //check if we opened all devices and started the grabthreads
1764  if(!OpenedDevices_){
1765  return;
1766  }
1767  if(grabMasterThread_ != NULL){
1768  double fps = grabMasterThread_->fps_;
1769  FrameCounter_ = grabMasterThread_->FrameCounter_;
1770  wxString text;
1771  text.Printf(wxT("%05d %2.1f fps "),FrameCounter_, fps);
1772  SetStatusText(text, 2);
1773  SelectAndShowCameraImage_();
1774  }
1775  Timer_.Start(Delay_);
1776 }
1777 
1778 /****************************************************
1779 *****************************************************/
1780 void ShowCamWxFrame::
1781 OnOpenFlirController(wxCommandEvent& event){
1782  if(tauControllerFrame_ == NULL){
1783  tauControllerFrame_ = new wxTauControlFrame(this);
1784  tauControllerFrame_->Show();
1785  }
1786  else{
1787  tauControllerFrame_->Show();
1788  }
1789 }
1790 /****************************************************
1791 *****************************************************/
1792 void ShowCamWxFrame::
1793 OnOpenViscaController(wxCommandEvent& event){
1794 
1795 #ifdef BIAS_HAVE_PANTILT
1796  if(viscaControllerFrame_ == NULL){
1797  viscaControllerFrame_ = new wxViscaControlFrame(this);
1798  viscaControllerFrame_->Show();
1799  }
1800  else{
1801  viscaControllerFrame_->Show();
1802  }
1803 #endif
1804 }
1805 
1806 
1807  /****************************************************
1808  *****************************************************/
1809 void ShowCamWxFrame::OnFindIEEE1394(wxCommandEvent& event) {
1810 #ifdef BIAS_HAVE_DCAM
1811  NumIEEECams_ = BIAS::ScanBus(IEEECameraInfo_);
1812 
1813  if (NumIEEECams_ > 0) {
1814  stringstream text;
1815  text << "Found " << NumIEEECams_ << " IEEE1394 Cameras: " << endl << endl;
1816 
1817  for (int i = 0; i < NumIEEECams_; i++) {
1818  text << "Camid: " << IEEECameraInfo_[i].camid << " "
1819  << IEEECameraInfo_[i].vendor << " " << IEEECameraInfo_[i].model
1820  << endl;
1821  }
1822  text<<"\nTrigger them?"<<endl;
1823  wxMessageDialog messageDialog(this, AsciiToWx(text.str().c_str()), wxT("Trigger- IEEE Cameras?"),
1824  wxYES_NO | wxNO_DEFAULT| wxICON_QUESTION);
1825  bool trigger = false;
1826  if(messageDialog.ShowModal() == wxID_YES){
1827  trigger = true;
1828  }
1829 
1830  for (int i = 0; i < NumIEEECams_; i++) {
1831  // check if camera already in Menu...
1832  bool inUse = false;
1833  for(int j = 0; j < NUMBER_CAMERAS; j++){
1834  if(IEEECameraInfo_[i].camid == atoi((*ParamDevice_[j]).c_str())){
1835  inUse = true;
1836  }
1837  }
1838  SetTrigger_[NumOfCams_] = trigger;
1839  // here we have to add the cameras to the menu.
1840  if(!inUse)
1841  AddIEEECameraToMenu(NumOfCams_,i,false);
1842  }
1843 
1844  } else {
1845  wxMessageDialog messageDialog(this, wxT("Sorry, no IEEE Cameras found!!"), wxT("ShowCamWx - IEEE Camera Scan"), wxICON_ERROR | wxOK);
1846  messageDialog.ShowModal();
1847  }
1848 #else
1849  wxMessageDialog messageDialog(this, wxT("Sorry, DCAM support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
1850  messageDialog.ShowModal();
1851 #endif
1852 
1853 }
1854 
1855 /****************************************************
1856  *****************************************************/
1857 void ShowCamWxFrame::OnFindWebcams(wxCommandEvent& event) {
1858 #ifdef BIAS_HAVE_V4L
1859  int ret = 0;
1860  VideoSource* vs = NULL;
1861  vs = new VideoSource_V4L;
1862  string device = "";
1863  int channel =0;
1864 
1865  vector<string> devices;
1866  ((VideoSource_V4L*)vs)->GetAllDevices(devices);
1867 
1868  if (devices.size()==0) {
1869  //Dialogbox
1870  wxMessageDialog messageDialog(this, wxT("Sorry, no V4L devices found!!"), wxT("V4L Scan Error"), wxICON_ERROR | wxOK);
1871  messageDialog.ShowModal();
1872  delete vs;
1873  return;
1874  }
1875  else if(devices.size()>1)
1876  {
1877  device = devices[0];
1878  // show device selector if more than one entry in devices.
1879  wxArrayString array;
1880  stringstream helptext;
1881  helptext << "Select Device: ";
1882  for (unsigned int k = 0; k< devices.size(); k++) {
1883  array.Add(AsciiToWx(devices[k].c_str()));
1884  }
1885 
1886 
1887  wxSingleChoiceDialog choiceDialog(this, wxT("Please choose device"),
1888 #if wxCHECK_VERSION(2, 9, 0)
1889  wxT("Choose Device"), array, (void**)NULL, wxDEFAULT_DIALOG_STYLE
1890 #else
1891  wxT("Choose Device"), array, NULL, wxDEFAULT_DIALOG_STYLE
1892 #endif
1893  | wxRESIZE_BORDER | wxOK | wxCANCEL| wxCENTRE);
1894  choiceDialog.SetSelection(0);
1895  ret = choiceDialog.ShowModal();
1896  if(ret == wxID_OK) {
1897  device = WxToAscii(array.Item(choiceDialog.GetSelection()));
1898  }
1899  else{
1900  delete vs;
1901  return;
1902  }
1903  }
1904 
1905  cout <<"Using: "<<device<<endl;
1907  if ( vs->GetCapabilities(device.c_str(),caps) == 0 ) {
1908  // show selector for Input (composite 0-2, s-video)
1909  //caps.Show();
1910  vs->GetDeviceChannelNames(DeviceChannelNames_[NumOfCams_]);
1911 
1912  if(DeviceChannelNames_[NumOfCams_].size()>0){
1913  wxArrayString array;
1914  stringstream helptext;
1915  helptext << "Select Input Channel: ";
1916  for (unsigned int k = 0; k< DeviceChannelNames_[NumOfCams_].size(); k++) {
1917  array.Add(AsciiToWx(DeviceChannelNames_[NumOfCams_][k].c_str()));
1918  }
1919 
1920  wxSingleChoiceDialog choiceDialog(this, wxT("Please choose channel"),
1921 #if wxCHECK_VERSION(2, 9, 0)
1922  wxT("Choose Channel"), array, (void**)NULL, wxDEFAULT_DIALOG_STYLE
1923 #else
1924  wxT("Choose Channel"), array, NULL, wxDEFAULT_DIALOG_STYLE
1925 #endif
1926  | wxRESIZE_BORDER | wxOK | wxCANCEL| wxCENTRE);
1927  choiceDialog.SetSelection(0);
1928  ret = choiceDialog.ShowModal();
1929  if(ret == wxID_OK){
1930  channel = choiceDialog.GetSelection();
1931  }
1932  else{
1933  delete vs;
1934  return;
1935  }
1936  }
1937  ////////////////////////////////////////////////
1938  vector<VideoSourceCapabilities::ResolutionEntry> re;
1939  caps.GetBestForEachResolution(re);
1940  for (unsigned int i=0;i<re.size();i++){
1941  cout <<" Best for "<<re[i].width<<"x"<<re[i].height<<" is "
1942  <<re[i].colormodel<<" at fps: "<<re[i].fps<<endl;
1943  }
1944  }
1945  else {
1946  //Dialogbox
1947  wxMessageDialog messageDialog(this, wxT("V4L device could not be queried!!"),
1948  wxT("V4L Scan Error"), wxICON_ERROR | wxOK);
1949  messageDialog.ShowModal();
1950  }
1951 
1952  //cout <<"Using Device Channel: "<<channel<<endl;
1953 
1954  DeviceChannel_[NumOfCams_] = channel;
1955  vs->SetDeviceChannel(channel);
1956  ret = vs->OpenDevice(device.c_str());
1957 
1958  if (ret != 0) {
1959  //Dialogbox
1960  wxMessageDialog messageDialog(this, wxT("Sorry, v4l camera could not be opened!!"),
1961  wxT("V4L Camera Scan"), wxICON_ERROR | wxOK);
1962  messageDialog.ShowModal();
1963  delete vs;
1964  return;
1965  }
1966  else
1967  {
1968  stringstream text;
1969  text <<"Found "<<devices.size()<<" V4L Cameras.\n"<<
1970  "Opening first camera by default.\n\n";
1971 
1972  for (unsigned i = 0; i < devices.size(); i++)
1973  text << "Id: " << devices[i] << endl;
1974  text<<"\nTrigger them?"<<endl;
1975 
1976  wxMessageDialog messageDialog(this, AsciiToWx(text.str().c_str()), wxT("Trigger- IEEE Cameras?"),
1977  wxYES_NO | wxNO_DEFAULT| wxICON_QUESTION);
1978  bool trigger = false;
1979  if(messageDialog.ShowModal() == wxID_YES){
1980  trigger = true;
1981  SetTrigger_[NumOfCams_] = trigger;
1982  }
1983 
1984  vs->CloseDevice();
1985  delete vs;
1986  // Add camera and open
1987  AddWebcamToMenu(device,NumOfCams_, false);
1988  }
1989 #endif
1990 
1991 #ifdef BIAS_HAVE_DSHOW
1992  int ret = 0;
1993  VideoSource* vs = NULL;
1994  vs = new VideoSource_DSHOW;
1995  vector<string> devices;
1996  vs->GetAllDevices(devices);
1997 
1998  stringstream text;
1999  if (devices.size() > 0) {
2000  text << "Found " << devices.size() << "DirectShow Cameras: " << endl << endl;
2001  for (unsigned int i = 0; i < devices.size(); i++) {
2002  text << "Identifier: " << devices[i]<<endl;
2003  }
2004  }
2005  else{
2006  text <<"Sorry no DirectShow Cameras found."<<endl;
2007  }
2008  wxArrayString devStrings;
2009  for(unsigned i=0;i<devices.size();i++){
2010  cout<<"Found device:"<<devices[i]<<endl;
2011  devStrings.Add(AsciiToWx(devices[i]));
2012  }
2013 
2014  string camera;
2015  // ask for depth error model
2016  wxSingleChoiceDialog wcbDlg(this, wxT("Select camera."),
2017  wxT("DShow Cameras"), devStrings);
2018  wcbDlg.SetSelection(0);
2019  ret = wcbDlg.ShowModal();
2020  if(ret == wxID_OK){
2021  camera = WxToAscii(devStrings.Item(wcbDlg.GetSelection()));
2022  }
2023  else{
2024  delete vs;
2025  return;
2026  }
2027 
2029  vs->GetCapabilities(caps);
2030  caps.Show();
2031  vector<VideoSourceCapabilities::ResolutionEntry> re;
2032  caps.GetBestForEachResolution(re);
2033  wxArrayString resStrings;
2034  for (unsigned int i=0;i<re.size();i++){
2035  stringstream txt;
2036  txt<<re[i].width<<"x"<<re[i].height<<" with "<<re[i].colormodel;
2037  resStrings.Add(AsciiToWx(txt.str()));
2038  }
2039 
2040  // ask for resolution
2041  int index = -1;
2042  wxSingleChoiceDialog resDlg(this, wxT("Select resolution."),
2043  wxT("Available Configurations"),resStrings);
2044  resDlg.SetSelection(0);
2045  ret = resDlg.ShowModal();
2046  if(ret == wxID_OK){
2047  index = resDlg.GetSelection();
2048  }
2049  else {
2050  delete vs;
2051  return;
2052  }
2053 
2054  *ParamWidth_[NumOfCams_] = re[index].width;
2055  *ParamHeight_[NumOfCams_] = re[index].height;
2056  *ParamColorModel_[NumOfCams_] = re[index].colormodel;
2057 
2058  vs->SetSize(re[index].width,re[index].height);
2059  vs->SetColorModel(re[index].colormodel);
2060 
2061  ret = vs->OpenDevice(camera.c_str());
2062  if (ret!=0) {
2063  wxMessageDialog messageDialog(this, wxT("Sorry, DSHOW camera could not be opened!!"),
2064  wxT("DShow Camera Scan"), wxICON_ERROR | wxOK);
2065  messageDialog.ShowModal();
2066  delete vs;
2067  return;
2068  }
2069 
2070  vs->CloseDevice();
2071  for(unsigned i=0;i<devices.size();i++){
2072  *ParamDevice_[NumOfCams_]=devices[i];
2073  AddWebcamToMenu(devices[i], NumOfCams_, false);
2074  }
2075 #endif
2076 }
2077 
2078  /****************************************************
2079  *****************************************************/
2080 void ShowCamWxFrame::OnFindUEye(wxCommandEvent& event){
2081  // simply try to open ueye
2082 #ifdef BIAS_HAVE_UEYE
2083 
2084  VideoSource_uEye ueye;
2085  std::vector<std::string> ret = ueye.GetDevices();
2086 
2087  if (ret.size() == 0) {
2088  //Dialogbox
2089  wxMessageDialog messageDialog(this, wxT("Sorry, UEYE not found!!"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2090  messageDialog.ShowModal();
2091  } else {
2092  for (unsigned int i=0;i<ret.size();i++) {
2093  // Add camera and open
2094  AddUEyeCameraToMenu(NumOfCams_, ret[i], false);
2095  }
2096  }
2097 #else
2098  wxMessageDialog messageDialog(this, wxT("Sorry, UEYE support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2099  messageDialog.ShowModal();
2100 #endif
2101 
2102 }
2103 /****************************************************
2104 *****************************************************/
2105 void ShowCamWxFrame::OnFindPMDTec(wxCommandEvent& event){
2106  // simply try to open pmdtec
2107 #ifdef BIAS_HAVE_PMD_PMDTec
2108  Cameras_[NumOfCams_] = new VideoSource_PMD;
2109  *ParamCameras_[NumOfCams_] = 2;
2110 
2112  dlg->SetString1(AsciiToWx(BIAS_PMD_PMDTec_SOURCEPLUGIN));
2113  dlg->SetString2(AsciiToWx(BIAS_PMD_PMDTec_PROCPLUGIN));
2114  int ret = dlg->ShowModal();
2115  if(ret == wxID_OK){
2116  sourcePlugin_ = WxToAscii(dlg->GetString1());
2117  procPlugin_ = WxToAscii(dlg->GetString2());
2118  }
2119  else{
2120  sourcePlugin_ =BIAS_PMD_PMDTec_SOURCEPLUGIN;
2121  procPlugin_= BIAS_PMD_PMDTec_PROCPLUGIN;
2122  return;
2123  }
2124 
2125  ret = OpenDevice(NumOfCams_);
2126  if (ret != 0) {
2127  //Dialogbox
2128  wxMessageDialog messageDialog(this, wxT("Sorry, PMDTec Camera not found!!"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2129  messageDialog.ShowModal();
2130  delete Cameras_[NumOfCams_];
2131  } else {
2132  // Add camera and open
2133  AddPMDTecCameraToMenu(NumOfCams_, true);
2134  }
2135 #else
2136  wxMessageDialog messageDialog(this, wxT("Sorry, PMDTec support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2137  messageDialog.ShowModal();
2138 #endif
2139 
2140 }
2141 
2142 
2143  /****************************************************
2144  *****************************************************/
2145 void ShowCamWxFrame::OnFindPMDZess(wxCommandEvent& event){
2146 #ifdef BIAS_HAVE_PMD_PMDZess
2147 
2149  //ask for bitfile
2150  wxTextEntryDialog dialog (this,wxT("Please insert path to bitfile,\n else ShowCamWx will try to open default file"),wxT("Searching for PMD Zess"),wxT(""));
2151  dialog.ShowModal();
2152 
2153  wxString wxStr = dialog.GetValue();
2154  if(wxStr.empty())
2155  wxStr = "C:\\ExternLibs\\PMDZess\\Bitfiles\\default.rbt";
2156 
2157  vs->SetBitFile(wxStr.c_str());
2158 
2159  int ret = vs->OpenDevice();
2160 
2161  if(ret != 0){
2162  wxMessageDialog messageDialog(this, wxT("Sorry, PMD Zess not found!!"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2163  messageDialog.ShowModal();
2164  delete vs;
2165  }else{
2166  vs->CloseDevice();
2167  delete vs;
2168 
2169  // Add camera and open
2170  AddZessCameraToMenu(NumOfCams_, false,wxStr.c_str());
2171  }
2172 #else
2173  wxMessageDialog messageDialog(this, wxT("Sorry, PMD Zess support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2174  messageDialog.ShowModal();
2175 #endif //BIAS_HAVE_PMD_PMDZess
2176 }
2177 
2178 
2179  /****************************************************
2180  *****************************************************/
2181 void ShowCamWxFrame::OnFindSwissRanger(wxCommandEvent& event){
2182 #ifdef BIAS_HAVE_SWISSRANGER
2183  Cameras_[NumOfCams_] = new VideoSource_SwissRanger;
2184  *ParamCameras_[NumOfCams_] = 9;
2185  stringstream message;
2186  message<<"Trigger Swissranger?";
2187  wxMessageDialog dlg (this, wxT("Trigger Swissranger?"),
2188  AsciiToWx(message.str().c_str()),
2189  wxYES_NO | wxNO_DEFAULT| wxICON_QUESTION);
2190  if(dlg.ShowModal() == wxID_YES){
2191  SetTrigger_[NumOfCams_] = true;
2192  }
2193  else{
2194  SetTrigger_[NumOfCams_] = false;
2195  }
2196 
2197 
2198  int ret = OpenDevice(NumOfCams_);
2199 
2200  if (ret != 0) {
2201  //Dialogbox
2202  wxMessageDialog messageDialog(this, wxT("Sorry, SwissRanger not found!!"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2203  messageDialog.ShowModal();
2204  delete Cameras_[NumOfCams_];
2205  } else {
2206  // Add camera and open
2207  AddSwissRangerCameraToMenu(NumOfCams_, true);
2208  }
2209 #else
2210  wxMessageDialog messageDialog(this, wxT("Sorry, SwissRanger support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2211  messageDialog.ShowModal();
2212 #endif
2213 
2214 }
2215 
2216 
2217 /****************************************************
2218  *****************************************************/
2219 void ShowCamWxFrame::OnFindKinect(wxCommandEvent& event){
2220 #ifdef BIAS_HAVE_KINECT
2221  Cameras_[NumOfCams_] = new VideoSource_Kinect;
2222  *ParamCameras_[NumOfCams_] = 12;
2223  SetTrigger_[NumOfCams_] = false;
2224 
2225  int ret = OpenDevice(NumOfCams_);
2226 
2227  if (ret != 0) {
2228  //Dialogbox
2229  wxMessageDialog messageDialog(this, wxT("Sorry, Kinect not found!!"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2230  messageDialog.ShowModal();
2231  delete Cameras_[NumOfCams_];
2232  } else {
2233  // Add camera and open
2234  AddKinectCameraToMenu(NumOfCams_, true);
2235  }
2236 #else
2237  wxMessageDialog messageDialog(this, wxT("Sorry, Kinect support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2238  messageDialog.ShowModal();
2239 #endif
2240 
2241 }
2242 /****************************************************
2243 *****************************************************/
2244 void ShowCamWxFrame::OnFindOpenNI(wxCommandEvent& event){
2245 #ifdef BIAS_HAVE_OPENNI
2246  VideoSource_OpenNI tester;
2247 
2248  for (int i=0;i<tester.GetNumDevices();i++) {
2249  *ParamCameras_[NumOfCams_+i] = ShowCamWxVideoSourceFactory::OPENNI;
2250  stringstream ss;
2251  ss << i;
2252  *ParamDevice_[NumOfCams_+i] = ss.str();
2253  Cameras_[NumOfCams_+i] = new VideoSource_OpenNI;
2254  SetTrigger_[NumOfCams_+i] = false;
2255  }
2256 
2257  for (int i=0;i<tester.GetNumDevices();i++) {
2258  int ret = OpenDevice(NumOfCams_);
2259 
2260  if (ret != 0) {
2261  //Dialogbox
2262  wxMessageDialog messageDialog(this, wxT("Sorry, OpenNI not found!!"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2263  messageDialog.ShowModal();
2264  delete Cameras_[NumOfCams_];
2265  } else {
2266  // Add camera and open
2267  AddOpenNICameraToMenu(NumOfCams_, true);
2268  }
2269  }
2270 #else
2271  wxMessageDialog messageDialog(this, wxT("Sorry, OpenNI support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2272  messageDialog.ShowModal();
2273 #endif
2274 
2275 }
2276 
2277 void ShowCamWxFrame::OnFindKinect2(wxCommandEvent& event){
2278 #ifdef BIAS_HAVE_KINECT2
2279  VideoSource_Kinect2 tester;
2280 
2281  for (int i=0;i<tester.GetNumDevices();i++) {
2282  *ParamCameras_[NumOfCams_+i] = ShowCamWxVideoSourceFactory::FREENECT2;
2283  stringstream ss;
2284  ss << i;
2285  *ParamDevice_[NumOfCams_+i] = ss.str();
2286  Cameras_[NumOfCams_+i] = new VideoSource_Kinect2;
2287  SetTrigger_[NumOfCams_+i] = false;
2288  }
2289 
2290  for (int i=0;i<tester.GetNumDevices();i++) {
2291  int ret = OpenDevice(NumOfCams_);
2292 
2293  if (ret != 0) {
2294  //Dialogbox
2295  wxMessageDialog messageDialog(this, wxT("Sorry, OpenNI not found!!"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2296  messageDialog.ShowModal();
2297  delete Cameras_[NumOfCams_];
2298  } else {
2299  // Add camera and open
2300  AddKinect2CameraToMenu(NumOfCams_, true);
2301  }
2302  }
2303 #else
2304  wxMessageDialog messageDialog(this, wxT("Sorry, OpenNI support not activated in BIAS"), wxT("ShowCamWx - Camera Scan"), wxICON_ERROR | wxOK);
2305  messageDialog.ShowModal();
2306 #endif
2307 
2308 }
2309 
2310 
2311 /****************************************************
2312 *****************************************************/
2313 #ifdef BIAS_HAVE_SWISSRANGER
2314 void ShowCamWxFrame::AddSwissRangerCameraToMenu(int camindex, bool fromFile){
2315  wxMenu* menuItem = new wxMenu;
2316 
2317  int id = (camindex + 1) * 10000;
2318  LastCameraID_ = id;
2319 
2320  id++;
2321  //menuItem->AppendSeparator();
2322  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2323  // connnect with eventhandler
2324  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2325  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2326  //menuItem->Append(subMenuItem);
2327  menuItem->Check(id, true);
2328 
2329  id++;
2330  menuItem->AppendCheckItem(id,wxT("Trigger Camera"));
2331  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2332  wxCommandEventHandler(ShowCamWxFrame::OnChangeTrigger));
2333  menuItem->Check(id, SetTrigger_[camindex]);
2334 
2335  CameraMenu_->Append(LastCameraID_,wxT("SwissRanger"),menuItem);
2336  if(!fromFile){
2337  *ParamCameras_[camindex] = 9;
2338  //OpenDevice(camindex);
2339  }
2340 
2341  NumOfCams_++;
2342 }
2343 #endif
2344 
2345 /****************************************************
2346 *****************************************************/
2347 #ifdef BIAS_HAVE_KINECT
2348 void ShowCamWxFrame::AddKinectCameraToMenu(int camindex, bool fromFile){
2349  wxMenu* menuItem = new wxMenu;
2350 
2351  int id = (camindex + 1) * 10000;
2352  LastCameraID_ = id;
2353 
2354  id++;
2355  //menuItem->AppendSeparator();
2356  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2357  // connnect with eventhandler
2358  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2359  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2360  //menuItem->Append(subMenuItem);
2361  menuItem->Check(id, true);
2362 
2363  CameraMenu_->Append(LastCameraID_,wxT("Kinect"),menuItem);
2364  if(!fromFile){
2365  *ParamCameras_[camindex] = 12;
2366  //OpenDevice(camindex);
2367  }
2368 
2369  NumOfCams_++;
2370 }
2371 #endif
2372 /****************************************************
2373 *****************************************************/
2374 #ifdef BIAS_HAVE_OPENNI
2375 void ShowCamWxFrame::AddOpenNICameraToMenu(int camindex, bool fromFile){
2376  wxMenu* menuItem = new wxMenu;
2377 
2378  int id = (camindex + 1) * 10000;
2379  LastCameraID_ = id;
2380 
2381  id++;
2382  //menuItem->AppendSeparator();
2383  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2384  // connnect with eventhandler
2385  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2386  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2387  //menuItem->Append(subMenuItem);
2388  menuItem->Check(id, true);
2389 
2390  CameraMenu_->Append(LastCameraID_,wxT("OpenNI"),menuItem);
2391  if(!fromFile){
2392  *ParamCameras_[camindex] = 13;
2393  //OpenDevice(camindex);
2394  }
2395 
2396  NumOfCams_++;
2397 }
2398 #endif
2399 
2400 #ifdef BIAS_HAVE_KINECT2
2401 void ShowCamWxFrame::AddKinect2CameraToMenu(int camindex, bool fromFile){
2402  wxMenu* menuItem = new wxMenu;
2403 
2404  int id = (camindex + 1) * 10000;
2405  LastCameraID_ = id;
2406 
2407  id++;
2408  //menuItem->AppendSeparator();
2409  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2410  // connnect with eventhandler
2411  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2412  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2413  //menuItem->Append(subMenuItem);
2414  menuItem->Check(id, true);
2415 
2416  CameraMenu_->Append(LastCameraID_,wxT("Kinect2"),menuItem);
2417  if(!fromFile){
2418  *ParamCameras_[camindex] = ShowCamWxVideoSourceFactory::FREENECT2;
2419  //OpenDevice(camindex);
2420  }
2421 
2422  NumOfCams_++;
2423 }
2424 #endif
2425 
2426 
2427 #ifdef BIAS_HAVE_PMD_PMDTec
2428 void ShowCamWxFrame::AddPMDTecCameraToMenu(int camindex, bool fromFile){
2429  wxMenu* menuItem = new wxMenu;
2430 
2431  int id = (camindex + 1) * 10000;
2432  LastCameraID_ = id;
2433 
2434  id++;
2435  //menuItem->AppendSeparator();
2436  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2437 
2438 
2439  // connnect with eventhandler
2440  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2441  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2442  //menuItem->Append(subMenuItem);
2443  menuItem->Check(id, true);
2444 
2445  id++;
2446  menuItem->AppendCheckItem(id,wxT("Trigger Camera"));
2447  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2448  wxCommandEventHandler(ShowCamWxFrame::OnChangeTrigger));
2449  menuItem->Check(id, SetTrigger_[camindex]);
2450 
2451  CameraMenu_->Append(LastCameraID_,wxT("PMDTec Camera"),menuItem);
2452  if(!fromFile){
2453  *ParamCameras_[camindex] = 2;
2454  //OpenDevice(camindex);
2455  }
2456 
2457  NumOfCams_++;
2458 }
2459 #endif
2460 
2461 /****************************************************
2462 *****************************************************/
2463 #ifdef BIAS_HAVE_PMD_PMDZess
2464 void ShowCamWxFrame::AddZessCameraToMenu(int camindex, bool fromFile, std::string paramFile){
2465  wxMenu* menuItem = new wxMenu;
2466 
2467  int id = (camindex + 1) * 10000;
2468  LastCameraID_ = id;
2469 
2470  id++;
2471  //menuItem->AppendSeparator();
2472  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2473 
2474 
2475  // connnect with eventhandler
2476  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2477  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2478  //menuItem->Append(subMenuItem);
2479  menuItem->Check(id, true);
2480 
2481  id++;
2482  menuItem->AppendCheckItem(id,wxT("Trigger Camera"));
2483  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2484  wxCommandEventHandler(ShowCamWxFrame::OnChangeTrigger));
2485  menuItem->Check(id, SetTrigger_[camindex]);
2486 
2487  CameraMenu_->Append(LastCameraID_,wxT("PMD Zess"),menuItem);
2488  if(!fromFile){
2489  *ParamCameras_[camindex] = 3;
2490  *ParamBitFile_[camindex] = paramFile;
2491  OpenDevice(camindex);
2492  }
2493 
2494  NumOfCams_++;
2495 }
2496 #endif //BIAS_HAVE_PMD_PMDZess
2497 
2498 
2499 /****************************************************
2500 *****************************************************/
2501 void ShowCamWxFrame::AddUEyeCameraToMenu(int camindex, std::string camId, bool fromFile){
2502  wxMenu* menuItem = new wxMenu;
2503 
2504  int id = (camindex + 1) * 10000;
2505  LastCameraID_ = id;
2506  // int ckid = 0;
2507 
2508  // add videomodes
2509  for (int i = 0; i < 6; i++) {
2510  stringstream ss;
2511 
2512  id++;
2513  switch (i) {
2514  case 0:
2515  ss << "1.875 FPS";
2516  break;
2517 
2518  case 1:
2519  ss << "3.75 FPS";
2520  break;
2521 
2522  case 2:
2523  ss << "7.5 FPS";
2524  break;
2525 
2526  case 3:
2527  ss << "15 FPS";
2528  break;
2529 
2530  case 4:
2531  ss << "30 FPS";
2532  break;
2533 
2534  case 5:
2535  ss << "60 FPS";
2536  break;
2537 
2538  default:
2539  break;
2540  }
2541 
2542  menuItem->AppendRadioItem(id,AsciiToWx(ss.str().c_str()));
2543  // connnect with eventhandler
2544  Connect(id, wxEVT_COMMAND_MENU_SELECTED,
2545  wxCommandEventHandler(ShowCamWxFrame::OnChangeVideoMode));
2546 
2547  }
2548  menuItem->Check(id, true);
2549 
2550  id++;
2551  menuItem->AppendSeparator();
2552  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2553 
2554 
2555  // connnect with eventhandler
2556  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2557  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2558 
2559  menuItem->Check(id, true);
2560 
2561  id++;
2562  menuItem->AppendCheckItem(id,wxT("Trigger Camera"));
2563  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2564  wxCommandEventHandler(ShowCamWxFrame::OnChangeTrigger));
2565  menuItem->Check(id, false);
2566 
2567  CameraMenu_->Append(LastCameraID_,wxT("UEYE"),menuItem);
2568  if(!fromFile){
2569  *ParamCameras_[camindex] = 5;
2570  *ParamDevice_[camindex] = camId;
2571  OpenDevice(camindex);
2572  }
2573 
2574  NumOfCams_++;
2575 }
2576 
2577 /****************************************************
2578 *****************************************************/
2579 void ShowCamWxFrame::AddWebcamToMenu(string name, int camindex, bool fromFile){
2580  wxMenu* menuItem = new wxMenu;
2581  //cout<<"Adding camera with camindex:"<<camindex<<" to menu."<<endl;
2582  int id = (camindex + 1) * 10000;
2583  LastCameraID_ = id;
2584  int ckid = -1;
2585  for(int i=0;i<(int)DeviceChannelNames_[camindex].size();i++){
2586  //increase
2587  id++;
2588  if(DeviceChannel_[camindex] == i) ckid = id;
2589 
2590  string s= DeviceChannelNames_[camindex][i];
2591  // check possible framerates
2592  stringstream helptext; helptext<<s;
2593  menuItem->AppendRadioItem(id,AsciiToWx(s.c_str()),AsciiToWx(helptext.str().c_str()));
2594  // connnect with eventhandler
2595  Connect(id, wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(ShowCamWxFrame::OnChangeDeviceChannel));
2596  }
2597  if(ckid!= -1){
2598  menuItem->Check(ckid, true);
2599  menuItem->AppendSeparator();
2600  }
2601  //add activate Camera to menu
2602  id++;
2603  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2604  // connnect with eventhandler
2605  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2606  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2607  menuItem->Check(id, false);
2608 
2609  //add Trigger to menu
2610  id++;
2611  menuItem->AppendCheckItem(id,wxT("Trigger Camera"));
2612  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2613  wxCommandEventHandler(ShowCamWxFrame::OnChangeTrigger));
2614  menuItem->Check(id, SetTrigger_[camindex]);
2615 
2616  //append camera to menu
2617  CameraMenu_->Append(LastCameraID_,AsciiToWx(name),menuItem);
2618  // now call opendevice
2619 
2620  if(!fromFile){
2621  *ParamCameras_[camindex] = 8;
2622  //OpenDevice(camindex);
2623  }
2624  NumOfCams_++;
2625 }
2626 
2627 
2628 /****************************************************
2629 *****************************************************/
2630 #ifdef BIAS_HAVE_DCAM
2631 void ShowCamWxFrame::AddIEEECameraToMenu(int camindex,int IEEEIndex, bool fromFile) {
2632  stringstream camtext;
2633  camtext << IEEECameraInfo_[IEEEIndex].vendor << " " << IEEECameraInfo_[IEEEIndex].model;
2634 
2635  wxMenu* menuItem = new wxMenu;
2636  int id = (camindex + 1) * 10000;
2637  LastCameraID_ = id;
2638  int ckid = 0;
2639 
2640  // add "normal" formats
2641  for (unsigned int j = 0; j < IEEECameraInfo_[IEEEIndex].videoModes.size(); j++) {
2642  id++;
2643 
2644  // get all possible modis...
2645  dc1394video_mode_t mode = IEEECameraInfo_[IEEEIndex].videoModes[j];
2646 
2647  string s;
2649 
2650  if (IEEECameraInfo_[IEEEIndex].bestMode == mode) {
2651  ckid = id;
2652  }
2653 
2654  // check possible framerates
2655  stringstream helptext;
2656  if(mode < DC1394_VIDEO_MODE_EXIF){
2657  helptext << "Supported Fps: ";
2658  for(unsigned int k = 0; k < IEEECameraInfo_[IEEEIndex].framerates[j].size(); k++){
2659  helptext << IEEECameraInfo_[IEEEIndex].framerates[j][k] << ", ";
2660  }
2661  }else{
2662  helptext << "Format 7";
2663  }
2664 
2665  menuItem->AppendRadioItem(id,AsciiToWx(s.c_str()),AsciiToWx(helptext.str().c_str()));
2666 
2667  // connnect with eventhandler
2668  Connect(id, wxEVT_COMMAND_MENU_SELECTED,
2669  wxCommandEventHandler(ShowCamWxFrame::OnChangeVideoMode));
2670  }
2671 
2672  menuItem->Check(ckid, true);
2673  menuItem->AppendSeparator();
2674  if (IEEECameraInfo_[IEEEIndex].b_capable) {
2675  id++;
2676 
2677  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2678  wxCommandEventHandler(ShowCamWxFrame::OnChangeFirewireB));
2679 
2680  menuItem->AppendCheckItem(id,wxT("Activate Firewire B"));
2681  menuItem->Check(id, true);
2682  SetFirewireB_[camindex] = true;
2683  }
2684 
2685 
2686  id++;
2687  menuItem->AppendCheckItem(id,wxT("Activate Camera"));
2688 
2689  // connnect with eventhandler
2690  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2691  wxCommandEventHandler(ShowCamWxFrame::OnChangeActivate));
2692 
2693  if(fromFile)
2694  menuItem->Check(id, true);
2695 
2696 
2697  id++;
2698  menuItem->AppendCheckItem(id,wxT("Trigger Camera"));
2699  Connect(id,wxEVT_COMMAND_MENU_SELECTED,
2700  wxCommandEventHandler(ShowCamWxFrame::OnChangeTrigger));
2701  menuItem->Check(id, SetTrigger_[camindex]);
2702 
2703  CameraMenu_->Append(LastCameraID_, AsciiToWx(camtext.str().c_str()), menuItem);
2704  if(!fromFile){
2705  *ParamCameras_[camindex] = 1;
2706  cout << IEEECameraInfo_[IEEEIndex].model << endl;
2707  if (IEEECameraInfo_[IEEEIndex].model.find("XB3") != string::npos || IEEECameraInfo_[IEEEIndex].model.find("BumbleBee") != string::npos)
2708  *ParamCameras_[camindex] = 10;
2709  std::ostringstream buffer;
2710  buffer << IEEECameraInfo_[IEEEIndex].camid;
2711  *ParamDevice_[camindex] = buffer.str();
2712  }
2713 
2714  SelectedFps_[camindex] = IEEECameraInfo_[IEEEIndex].bestFramerate;
2715 
2716  NumOfCams_++;
2717 }
2718 #endif
2719 
2720 
2721 /****************************************************
2722 *****************************************************/
2723 #ifdef BIAS_HAVE_DCAM
2724 int ShowCamWxFrame::ShowFormat7Selector(int camindex, dc1394video_mode_t mode ){
2725 
2726  //dc1394video_mode_t mode = SelectedModeFromMenu(camindex);
2727  //int maxWidth, maxHeight,minBpP,maxBpP;
2728  //cout<<"Cameras_[camindex]:"<<Cameras_[camindex]<<endl;
2729  cout<<"Camindex:"<<camindex<<endl;
2730 
2731  //if format 7 mode was selected open GUI for parameters
2732  //if(format7Frame_ == NULL){
2733  format7Frame_ = new ShowCamWxFormat7Frame(this,
2734  wxT("Select Format"),wxDefaultPosition,wxSize(550,400));
2735  //}
2736 
2737  // first get
2738  unsigned int IEEEIndex = 0;
2739 
2740  for (unsigned int j = 0; j < IEEECameraInfo_.size(); j++) {
2741  if (IEEECameraInfo_[j].camid == atoi((*ParamDevice_[camindex]).c_str())) {
2742  IEEEIndex = j;
2743  }
2744  }
2745 
2746  unsigned int modeindex = 0;
2747  for(unsigned int j = 0; j < IEEECameraInfo_[IEEEIndex].f7_modes.size();j++){
2748  if(IEEECameraInfo_[IEEEIndex].f7_modes[j] == mode)
2749  modeindex = j;
2750  }
2751 
2752  // set min and max settings
2753  format7Frame_->SetXSize(IEEECameraInfo_[IEEEIndex].f7_unitWidth[modeindex],
2754  IEEECameraInfo_[IEEEIndex].f7_maxWidth[modeindex]);
2755  format7Frame_->SetXOffset(0,IEEECameraInfo_[IEEEIndex].f7_maxWidth[modeindex]);
2756  format7Frame_->SetYSize(IEEECameraInfo_[IEEEIndex].f7_unitHeight[modeindex],
2757  IEEECameraInfo_[IEEEIndex].f7_maxHeight[modeindex]);
2758  format7Frame_->SetYOffset(0,IEEECameraInfo_[IEEEIndex].f7_maxHeight[modeindex]);
2759  format7Frame_->SetBpP(IEEECameraInfo_[IEEEIndex].f7_MinBpP[modeindex],
2760  IEEECameraInfo_[IEEEIndex].f7_MaxBpP[modeindex],
2761  IEEECameraInfo_[IEEEIndex].f7_bestBpP[modeindex]);
2762 
2763  format7Frame_->SetCameraIDandMode(IEEECameraInfo_[IEEEIndex].camid, mode);
2764 
2765 
2766  int ret = format7Frame_->ShowModal();
2767  if (ret == wxID_CANCEL){
2768  ret = -1;
2769  }
2770  if(ret == wxID_OK/* || ret==wxID_CANCEL*/){
2771  Format7LeftTop_[camindex] = Vector2<int>(format7Frame_->xOffset,format7Frame_->yOffset);
2772  Format7WidthHeight_[camindex] = Vector2<int>(format7Frame_->xSize,format7Frame_->ySize);
2773  Format7BpP_[camindex] = format7Frame_->bpp;
2774  Format7ColorMode_[camindex] = format7Frame_->colorMode;
2775  ViewColorMode_[camindex] = format7Frame_->colorModeView;
2776  cout<<"Selection:"<<Format7LeftTop_[camindex]<< " , Colormode: " << ViewColorMode_[camindex] << " " << (int)ViewColorMode_[camindex] << endl;
2777  //format7Frame_ = NULL;
2778  }
2779 
2780  return ret;
2781 }
2782 #endif
2783 
2784 /****************************************************
2785 *****************************************************/
2786 void ShowCamWxFrame::OnChangeDeviceChannel(wxCommandEvent& event){
2787 
2788  //cout<<"Event ID:"<<event.GetId()<<endl;
2789  // probieren den Mode zu setzen und die Kamera neu zu starten...
2790  int camindex = event.GetId() / 10000 - 1;
2791  //cout<<"Camindex:"<<camindex<<endl;
2792  int deviceChannelID = (event.GetId() % 10000) - 1;
2793  //int modeindex = (event.GetId() % 10000) - 1;
2794  switch (*ParamCameras_[camindex]) {
2795  case 8:{
2796  int index = deviceChannelID;
2797  //cout<<"Device Channel:"<<index<<endl;
2798  if (CameraActive_[camindex])
2799  {
2800  CloseDevice(camindex);
2801  biassleep(1);
2802  DeviceChannel_[camindex] = index;
2803  OpenDevice(camindex);
2804  }
2805  else{
2806  DeviceChannel_[camindex] = index;
2807  }
2808  return;
2809 
2810  }
2811  break;
2812  default:
2813  return;
2814  }
2815 }
2816 
2817 /****************************************************
2818 *****************************************************/
2819 void ShowCamWxFrame::OnChangeVideoMode(wxCommandEvent& event) {
2820 
2821  // probieren den Mode zu setzen und die Kamera neu zu starten...
2822  int camindex = event.GetId() / 10000 - 1;
2823  int modeindex = (event.GetId() % 10000) - 1;
2824  SetUserMode_[camindex] = true;
2825 
2826  switch (*ParamCameras_[camindex]) {
2827  case 1:{ // DCAM
2828 #ifdef BIAS_HAVE_DCAM
2829  unsigned int IEEEIndex = 0;
2830 
2831  for (unsigned int j = 0; j < IEEECameraInfo_.size(); j++) {
2832  if (IEEECameraInfo_[j].camid == atoi((*ParamDevice_[camindex]).c_str())) {
2833  IEEEIndex = j;
2834  }
2835  }
2836 
2837  if(IEEECameraInfo_[IEEEIndex].videoModes[modeindex] < DC1394_VIDEO_MODE_EXIF){
2838 
2839  //user has to select framerate from dropdown menu
2840  wxArrayString array;
2841  stringstream helptext;
2842  helptext << "Supported Fps: ";
2843  for (unsigned int k = 0; k
2844  < IEEECameraInfo_[IEEEIndex].framerates[modeindex].size(); k++) {
2845  stringstream fpss;
2846  fpss << IEEECameraInfo_[IEEEIndex].framerates[modeindex][k];
2847  array.Add(AsciiToWx(fpss.str().c_str()));
2848  }
2849 
2850  wxSingleChoiceDialog choiceDialog((wxWindow*)this, wxT("Please choose framerate"),
2851  wxT("Choose Framerate"), array, (char**)NULL,
2852  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL| wxCENTRE);
2853 
2854 
2855  choiceDialog.ShowModal();
2856  int selectedFps = choiceDialog.GetSelection();
2857  SelectedFps_[camindex]
2858  = IEEECameraInfo_[IEEEIndex].framerates[modeindex][selectedFps];
2859 
2860  }
2861  else{
2862  ///////////////////////
2863  //cout<<"Showing selector"<<endl;
2864  int ret = ShowFormat7Selector(camindex,IEEECameraInfo_[IEEEIndex].videoModes[modeindex]);
2865  if(ret < 0)
2866  return;
2867  }
2868 
2869  // if camera is active then restart camera
2870  if (CameraActive_[camindex]) {
2871  CloseDevice(camindex);
2872  // wait some time for the cam to reinitialize
2873  biassleep(1);
2874  OpenDevice(camindex);
2875  } else {
2876  OnChangeActivate(event);
2877  int id = IEEECameraInfo_[IEEEIndex].videoModes.size();
2878  id += (camindex + 1) * 10000 + 1;
2879  if (IEEECameraInfo_[IEEEIndex].b_capable)
2880  id++;
2881  wxMenuItem* item;
2882  item = CameraMenu_->FindItem(id);
2883  item->Check(true);
2884 #ifdef WIN32
2885  CloseDevice(camindex);
2886  Sleep(1);
2887  OpenDevice(camindex);
2888 #endif
2889  }
2890 #endif
2891  }
2892  break;
2893 
2894  case 5:{ // UEYE
2895  // just change framerate
2896  double fps = 0.0;
2897  switch (modeindex) {
2898  case 0:
2899  fps = 1.875;
2900  break;
2901  case 1:
2902  fps = 3.75;
2903  break;
2904  case 2:
2905  fps = 7.5;
2906  break;
2907  case 3:
2908  fps = 15;
2909  break;
2910  case 4:
2911  fps = 30;
2912  break;
2913  case 5:
2914  fps = 60;
2915  break;
2916  default:
2917  break;
2918  }
2919  *ParamFPS_[camindex] = fps;
2920  //dynamic_cast<VideoSource_uEye*>(Cameras_[camindex])->SetFPS(fps);
2921  // restart camera
2922  if (CameraActive_[camindex]) {
2923  CloseDevice(camindex);
2924  // wait some time for the cam to reinitialize
2925  biassleep(1);
2926  OpenDevice(camindex);
2927  }
2928  }
2929  break;
2930  default:
2931  break;
2932  }
2933 }
2934 /****************************************************
2935 *****************************************************/
2936 void ShowCamWxFrame::OnChangeActivate(wxCommandEvent& event){
2937 
2938  int camindex = event.GetId()/10000 -1;
2939  if(CameraActive_[camindex])
2940  CloseDevice(camindex);
2941  else{
2942  //wxCommandEvent e;
2943  // OnChangeVideoMode(e);
2944  OpenDevice(camindex);
2945  }
2946 
2947 }
2948 /****************************************************
2949 *****************************************************/
2950 void ShowCamWxFrame::OnChangeFirewireB(wxCommandEvent& event) {
2951 
2952  int camindex = event.GetId() / 10000 - 1;
2953 
2954  if (SetFirewireB_[camindex]) {
2955  cout<<"Setting 1394b false."<<endl;
2956  SetFirewireB_[camindex] = false;
2957  } else {
2958  cout<<"Setting 1394b true."<<endl;
2959  SetFirewireB_[camindex] = true;
2960  }
2961 
2962  // if camera is active then restart camera
2963  if (CameraActive_[camindex]) {
2964  CloseDevice(camindex);
2965  // wait some time for the cam to reinitialize
2966  biassleep(1);
2967  OpenDevice(camindex);
2968  }
2969 }
2970 
2971 /****************************************************
2972 *****************************************************/
2973 void ShowCamWxFrame::OnChangeTrigger(wxCommandEvent& event){
2974  int camindex = event.GetId() / 10000 - 1;
2975 
2976  if (SetTrigger_[camindex]) {
2977  cout<<"Setting Trigger false."<<endl;
2978  SetTrigger_[camindex] = false;
2979  } else {
2980  cout<<"Setting Trigger true."<<endl;
2981  SetTrigger_[camindex] = true;
2982  }
2983 
2984  // if camera is active then restart camera
2985  if (CameraActive_[camindex]) {
2986  CloseDevice(camindex);
2987  // wait some time for the cam to reinitialize
2988  biassleep(1);
2989  OpenDevice(camindex);
2990  }
2991 }
2992 
2993 /****************************************************
2994 *****************************************************/
2995 void ShowCamWxFrame::
2997  // show camera image in main window if a camera was selected
2998  if (Cameras_[NumCamSel_] != NULL && CamImg_[NumCamSel_] != NULL)
2999  {
3000  unsigned int width;
3001  unsigned int height;
3002  switch (*ParamCameras_[NumCamSel_]) {
3003  case ShowCamWxVideoSourceFactory::KINECT: // kinect
3004  case ShowCamWxVideoSourceFactory::OPENNI: // openni
3005  case ShowCamWxVideoSourceFactory::FREENECT2: // freenect2
3006  case ShowCamWxVideoSourceFactory::PMDUSB: // pmdzess
3007  case ShowCamWxVideoSourceFactory::PMD: // pmdtec Camcube
3008  InitCombinedImage();
3009  ShowImage_ = CamImgCombined_;
3010  break;
3012  if (VideoControllers_[NumCamSel_]!=NULL) {
3013  ShowXB3_ = VideoControllers_[NumCamSel_]->GetSelectedImage();
3014  }
3015  switch(ShowXB3_){
3016  case 1: ShowImage_ = *CamImg_[NumCamSel_]; break;
3017  case 2: ShowImage_ = *CamImgMiddle_[NumCamSel_]; break;
3018  case 3: ShowImage_ = *CamImgRight_[NumCamSel_]; break;
3019  case 4: ShowImage_ = *XB3AllInOne_[NumCamSel_]; break;
3020  case 0: ShowImage_ = *XB3AllInOne_[NumCamSel_];
3021  BIAS::ImageBase tmp = ShowImage_;
3022  ImageConvert::DeinterleaveHorizontal(tmp, ShowImage_);
3023  break;
3024  }
3025  break;
3026  default:
3027  ShowImage_ = *CamImg_[NumCamSel_];
3028  if(ViewColorMode_[NumCamSel_] != ImageBase::CM_invalid){
3029 
3030  //cout << "Integer of ViewMode " << (int)ViewColorMode_[NumCamSel_] << endl;
3031  ShowImage_.SetColorModel((ImageBase::EColorModel)ViewColorMode_[NumCamSel_]);
3032  //cout << "Colormodel: " << ViewColorMode_[NumCamSel_] << endl;
3033  }
3034 /*
3035  // rgb split mode fkeller
3036  BIAS::Camera<unsigned char> src = *CamImg_[NumCamSel_];
3037  src.SetColorModel(ImageBase::CM_Bayer_RGGB);
3038  BIAS::Camera<unsigned char> tmp;
3039  ImageConvert::ToRGB(src,tmp);
3040  ShowImage_ = tmp;
3041  unsigned char **in = tmp.GetImageDataArray();
3042  unsigned char **out = ShowImage_.GetImageDataArray();
3043  unsigned int w=tmp.GetWidth();
3044  unsigned int h=tmp.GetHeight();
3045  for (unsigned int y=0;y<h;y+=2) {
3046  for (unsigned int x=0;x<w;x+=2) {
3047  for (unsigned int c=0;c<3;c++) {
3048  // RGB lower right corner
3049  out [h/2+y/2][(w/2+x/2)*3+c] = in[y][x*3+c];
3050  }
3051  //out [h/2+y/2][(w/2+x/2)*3+2] = 128;
3052  }
3053  }
3054  for (unsigned int y=0;y<h/2;y++) {
3055  for (unsigned int x=0;x<w/2;x++) {
3056  for (unsigned int c=0;c<3;c++) {
3057  // R channel = upper left corner
3058  out[y][x*3+c] = out [h/2+y][(w/2+x)*3+0];
3059  // G channel = upper right corner
3060  out[y][((w/2)+x)*3+c] = out [h/2+y][(w/2+x)*3+1];
3061  // B channel = lower left corner
3062  out[h/2+y][x*3+c] = out [h/2+y][(w/2+x)*3+2];
3063  }
3064  }
3065  }
3066  //BIAS::ImageBase tmp = ShowImage_;
3067  //ImageConvert::ToRGB(*CamImg_[NumCamSel_],ShowImage_);
3068  //cout<<"OT ColorMode:"<<ShowImage_.GetColorModel()<<endl;
3069  */
3070  break;
3071  }
3072 
3073  // downsampling of actual camera image if set by param file
3074  int downSample = *ParamDown_[NumCamSel_];
3075  if (downSample != 0) {
3076  Camera<unsigned char> rescaledImage;
3078  rescale.Downsample(ShowImage_, rescaledImage,
3079  (int)(ShowImage_.GetWidth() / downSample),
3080  (int)(ShowImage_.GetHeight() / downSample));
3081  ShowImage_ = rescaledImage;
3082  }
3083 
3084  /////////////////////////////////////
3085  // get size available for image canvas
3086  width = ShowImage_.GetWidth();
3087  height = ShowImage_.GetHeight();
3088  int widthClient=0, heightClient=0;
3089  IC_->GetSize(&widthClient, &heightClient);
3090  //GetClientSize(&widthClient, &heightClient);
3091  heightClient -= 30;
3092  widthClient -= 5;
3093  if (pCheckBoxFit->IsChecked()) {
3094 
3095  // compute scale that keeps the aspect ratio and the image is fully visible
3096  float xscale = (float)widthClient / width;
3097  float yscale = (float)heightClient / height;
3098  float scale = xscale < yscale ? xscale : yscale;
3099 
3100  IC_->SetScaledImageSize(width * scale, height* scale);
3101  IC_->SetShowScaled(true);
3102  }//fitcheckbox
3103  else{
3104  IC_->SetShowScaled(false);
3105  }
3106 
3107  // set new height or width if changed
3108  if (width != LastWidth_ || height != LastHeight_){
3109  LastWidth_ = width;
3110  LastHeight_ = height;
3111  }
3112 
3113  // show actual camera image on main frame
3114  //cout << "Show Image " << ShowImage_.GetColorModel() << endl;
3115  if (ShowImage_.GetColorModel() != ImageBase::CM_invalid && ShowImage_.GetStorageType() != ImageBase::ST_invalid) {
3116  IC_->Show(ShowImage_, "Camera Image");
3117  }
3118  wxString text;
3119  text.Printf(wxT("size: %4dx%4d"),width,height);
3120  SetStatusText(text, 1);
3121  }
3122 }
3123 
3124 /****************************************************
3125 *****************************************************/
3126 void ShowCamWxFrame::OnKey(wxKeyEvent& event)
3127 {
3128  int code = event.GetKeyCode();
3129 
3130  //cout << "Recieved keycode: " << code << endl;
3131  // grab single shot
3132  wxCommandEvent e;
3133  if(code == 32){
3134  OnGrab(e);
3135  }
3136  // grab continious
3137  if(code == 67){
3138  OnGrabContinuous(e);
3139  }
3140 }
3141 
3142 
3143 /****************************************************
3144 *****************************************************/
3145 void ShowCamWxFrame::
3146 OnShowParameters(wxCommandEvent& event){
3147  ShowParamGUI();
3148 }
3149 
3150 /****************************************************
3151 *****************************************************/
3152 void ShowCamWxFrame::
3153 OnAbout(wxCommandEvent &event)
3154 {
3155  wxString desc;
3156  desc << wxT("This tool biasShowCamWX is part of the\n");
3157  desc << wxT("BIAS library (Basic ImageAlgorithmS)\n");
3158  desc << wxT("It is used to open cameras and grab images to disk.\n\n");
3159 
3160  stringstream text;
3161  text << "Built on " << __DATE__ << " " << __TIME__ << "\n"
3162  // << "from file " << __FILE__ << "\n"
3163  << "GUI using: " << WxToAscii(wxVERSION_STRING)<< "\n";
3164  text<< "Built with support for:\n";
3165 #ifdef BIAS_HAVE_DCAM
3166  text<< "- Firewire/IEEE1394 (CMU).\n";
3167 #endif
3168 #ifdef BIAS_HAVE_DSHOW
3169  text<< "- DirectShow.\n";
3170 #endif
3171 #ifdef BIAS_HAVE_V4L
3172  text<< "- Video4Linux.\n";
3173 #endif
3174 #ifdef BIAS_HAVE_SWISSRANGER
3175  text<< "- Swissranger.\n";
3176 #endif
3177 #ifdef BIAS_HAVE_KINECT
3178  text<< "- Kinect (libfreenect).\n";
3179 #endif
3180 #ifdef BIAS_HAVE_OPENNI
3181  text<< "- Kinect (OpenNI).\n";
3182 #endif
3183 #ifdef BIAS_HAVE_KINECT2
3184  text<< "- Kinect2 (freenect2).\n";
3185 #endif
3186 #ifdef BIAS_HAVE_FFMPEG
3187 text<< "- FFMPEG.\n";
3188 #endif
3189 #ifdef BIAS_HAVE_PMD_PMDTec
3190 text<< "- PMDTec Camcube.\n";
3191 #endif
3192 #ifdef BIAS_HAVE_UEYE
3193 text<< "- IDS Ueye.\n";
3194 #endif
3195 desc<<AsciiToWx(text.str());
3196 
3197  wxString lic = wxT("BIAS is free software; you can redistribute it and/or modify\n \
3198  it under the terms of the GNU Lesser General Public Licence as published by\n \
3199  the Free Software Foundation; either version 2.1 of the Licence, or\n \
3200  (at your option) any later version.\n \
3201  \n \
3202  BIAS is distributed in the hope that it will be useful,\n \
3203  but WITHOUT ANY WARRANTY; without even the implied warranty of\n \
3204  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n \
3205  GNU Lesser General Public Licence for more details.\n \
3206  \n \
3207  You should have received a copy of the GNU Lesser General Public Licence\n \
3208  along with BIAS; if not, write to the Free Software\n \
3209  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
3210 
3211  wxAboutDialogInfo aboutdlg;
3212  aboutdlg.SetDescription( desc );
3213  aboutdlg.SetLicence( lic );
3214  aboutdlg.SetCopyright( wxT("Copyright (C) 2003-20011\n \
3215  Multimediale Systeme der Informationsverarbeitung\n \
3216  Institut fuer Informatik\n \
3217  Christian-Albrechts-Universitaet Kiel") );
3218  aboutdlg.SetWebSite( wxT("http://www.mip.informatik.uni-kiel.de/") );
3219 
3220  wxAboutBox( aboutdlg );
3221 }
3222 
3223 /****************************************************
3224 *****************************************************/
3225 void ShowCamWxFrame::
3227  paramFrame_ = GetFrame(this);
3228  paramFrame_->Show(true);
3229  paramFrame_->Move( wxPoint(500,200));
3230 }
3231 
3232 /****************************************************
3233 *****************************************************/
3234 void ShowCamWxFrame::
3235 SaveImageUnthreaded_(int cameraIndex) {
3236  wxString text;
3237  switch(*ParamCameras_[cameraIndex]) {
3239  text.Printf(wxT("SINGLE-CAM%02d-%05d-int.mip"), cameraIndex, GrabCounter_);
3240  CamImgPMDInt_[cameraIndex]->UpdateMetaData();
3241  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgPMDInt_[cameraIndex]);
3244  CamImg_[cameraIndex]->UpdateMetaData();
3245  text.Printf(wxT("SINGLE-CAM%02d-%05d-grey.mip"), cameraIndex, GrabCounter_);
3246  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImg_[cameraIndex]);
3247 
3248  text.Printf(wxT("SINGLE-CAM%02d-%05d-depth.mip"), cameraIndex, GrabCounter_);
3249  CamImgPMDDepth_[cameraIndex]->UpdateMetaData();
3250  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgPMDDepth_[cameraIndex]);
3251 
3252  text.Printf(wxT("SINGLE-CAM%02d-%05d-amp.mip"), cameraIndex, GrabCounter_);
3253  CamImgPMDAmp_[cameraIndex]->UpdateMetaData();
3254  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgPMDAmp_[cameraIndex]);
3255 
3256  break;
3258  text.Printf(wxT("SINGLE-CAM%02d-left-%05d.mip"), cameraIndex, GrabCounter_);
3259  CamImg_[cameraIndex]->UpdateMetaData();
3260  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImg_[cameraIndex]);
3261 
3262  text.Printf(wxT("SINGLE-CAM%02d-center-%05d.mip"), cameraIndex, GrabCounter_);
3263  CamImgMiddle_[cameraIndex]->UpdateMetaData();
3264  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgMiddle_[cameraIndex]);
3265 
3266  text.Printf(wxT("SINGLE-CAM%02d-right-%05d.mip"), cameraIndex, GrabCounter_);
3267  CamImgRight_[cameraIndex]->UpdateMetaData();
3268  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgRight_[cameraIndex]);
3269  break;
3272  CamImg_[cameraIndex]->UpdateMetaData();
3273  text.Printf(wxT("SINGLE-CAM%02d-%05d-color.mip"), cameraIndex, GrabCounter_);
3274  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImg_[cameraIndex]);
3275 
3276  text.Printf(wxT("SINGLE-CAM%02d-%05d-depth.mip"), cameraIndex, GrabCounter_);
3277  CamImgPMDDepth_[cameraIndex]->UpdateMetaData();
3278  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgPMDDepth_[cameraIndex]);
3279  break;
3281  CamImg_[cameraIndex]->UpdateMetaData();
3282  text.Printf(wxT("SINGLE-CAM%02d-%05d-color.mip"), cameraIndex, GrabCounter_);
3283  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImg_[cameraIndex]);
3284  text.Printf(wxT("SINGLE-CAM%02d-%05d-depth.mip"), cameraIndex, GrabCounter_);
3285  CamImgPMDDepth_[cameraIndex]->UpdateMetaData();
3286  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgPMDDepth_[cameraIndex]);
3287  text.Printf(wxT("SINGLE-CAM%02d-%05d-IR.mip"), cameraIndex, GrabCounter_);
3288  CamImgPMDInt_[cameraIndex]->UpdateMetaData();
3289  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImgPMDInt_[cameraIndex]);
3290  break;
3291  default:
3292  CamImg_[cameraIndex]->UpdateMetaData();
3293  text.Printf(wxT("SINGLE-CAM%02d-%05d.mip"), cameraIndex, GrabCounter_);
3294  ImageIO::Save(currentSingleSaveDir_ + WxToAscii(text), *CamImg_[cameraIndex]);
3295  break;
3296  }
3297 }
3298 
3299 /****************************************************
3300 *****************************************************/
3301 void ShowCamWxFrame::
3303  int i=0;
3304  i = cameraIndex;
3305 #ifdef BIAS_HAVE_SWISSRANGER
3306  if(Cameras_[i] != NULL && dynamic_cast<VideoSource_SwissRanger*>(Cameras_[i]) != NULL){
3307  Cameras_[i]->GrabSingle(*CamImg_[i]);
3308  dynamic_cast<VideoSource_SwissRanger*>
3309  (Cameras_[i])->GrabSingleDepth(*CamImgPMDDepth_[i]);
3310  dynamic_cast<VideoSource_SwissRanger*>
3311  (Cameras_[i])->GrabSingleModCoeff(*CamImgPMDAmp_[i]);
3312  }else
3313 
3314 #endif // BIAS_HAVE_SWISSRANGER
3315 #ifdef BIAS_HAVE_PMD_PMDTec
3316  if(Cameras_[i] != NULL && dynamic_cast<VideoSource_PMD*>(Cameras_[i]) != NULL){
3317  Cameras_[i]->GrabSingle(*CamImg_[i]);
3318  dynamic_cast<VideoSource_PMD*>
3319  (Cameras_[i])->GrabSingleDepth(*CamImgPMDDepth_[i]);
3320  dynamic_cast<VideoSource_PMD*>
3321  (Cameras_[i])->GrabSingleModCoeff(*CamImgPMDAmp_[i]);
3322  dynamic_cast<VideoSource_PMD*>
3323  (Cameras_[i])->GrabSingleIntensity(*CamImgPMDInt_[i]);
3324  }else
3325 
3326 #endif // BIAS_HAVE_SWISSRANGER
3327 
3328  //#ifndef WIN32
3329 #ifdef BIAS_HAVE_DCAM
3330  if(dynamic_cast<VideoSource_DCAM_BumbleBee*>(Cameras_[i]) != NULL){
3331  //cout << "Before Casting" << endl;
3332  (dynamic_cast<VideoSource_DCAM_BumbleBee*>(Cameras_[i]))->
3333  GrabSingle(*XB3AllInOne_[i], *CamImg_[i],*CamImgMiddle_[i],*CamImgRight_[i]);
3334  }else
3335  //#endif
3336 #endif //not WIN32
3337  {
3338  Cameras_[i]->GrabSingle(*CamImg_[i]);
3339  }
3340 }
3341 
3342 
3343 /****************************************************
3344 *****************************************************/
3345 int ShowCamWxFrame::
3347  ServerMutex_.resize(NUMBER_CAMERAS);
3348  ServerCondition_.resize(NUMBER_CAMERAS);
3349  ClientsMutex_.resize(NUMBER_CAMERAS);
3350  ClientsCondition_.resize(NUMBER_CAMERAS);
3351  for (unsigned int i=0;i<NUMBER_CAMERAS;i++) {
3352  ServerMutex_[i]= new wxMutex();
3353  ServerCondition_[i] = new wxCondition(*(ServerMutex_[i]));
3354  ClientsMutex_[i]= new wxMutex();
3355  ClientsCondition_[i] = new wxCondition(*(ClientsMutex_[i]));
3356  }
3357 
3358  grabMasterThread_ = new GrabMasterThread(&Cameras_,
3359  &ClientsCondition_,
3360  &ServerCondition_,
3361  &ClientsMutex_,
3362  &ServerMutex_);
3363  grabMasterThread_->Create();
3364  grabMasterThread_->Run();
3365 #ifndef WIN32
3366  usleep(5);
3367 #else
3368  Sleep(1);
3369 #endif
3370  return 0;
3371 }
3372 
3373 
3374 /****************************************************
3375 *****************************************************/
3376 int ShowCamWxFrame::
3378 
3379  //cout<<"Creating GrabThread for camera:"<<cameraIndex<<endl;
3380  // create new masterthread if none present
3381  bool gmtLock = false;
3382  if (grabMasterThread_ == NULL) {
3383  CreateMasterThread_();
3384  } else {
3385  gmtLock = true;
3386  ServerMutex_[cameraIndex]->Lock();
3387  ClientsMutex_[cameraIndex]->Lock();
3388  }
3389 
3390  //delete thread before creating new one
3391  if(grabSingleThread_[cameraIndex] != NULL){
3392  delete grabSingleThread_[cameraIndex];
3393  grabSingleThread_[cameraIndex] = NULL;
3394  }
3395 
3396  //cout<<"Creating new GrabSingleThread:"<<endl<<flush;
3397  //cout<<"With CamImg="<<CamImg_[cameraIndex]<<endl;
3398  //create new camera thread
3399  grabSingleThread_[cameraIndex] =
3400  new GrabSingleThread(Cameras_[cameraIndex],
3401  ClientsCondition_[cameraIndex],
3402  ServerCondition_[cameraIndex],
3403  ClientsMutex_[cameraIndex],
3404  ServerMutex_[cameraIndex],
3405  cameraIndex,
3406  BufferAccess_[cameraIndex],
3407  bWriteBuffered_,
3408  ReadIndex_[cameraIndex],
3409  WriteIndex_[cameraIndex],
3410  CamImg_[cameraIndex],
3411  CamImgMiddle_[cameraIndex],
3412  CamImgRight_[cameraIndex],
3413  CamImgPMDDepth_[cameraIndex],
3414  CamImgPMDAmp_[cameraIndex],
3415  CamImgPMDInt_[cameraIndex],
3416  XB3AllInOne_[cameraIndex],
3417  ImageBuffer_[cameraIndex],
3418  ImageBufferMiddle_[cameraIndex],
3419  ImageBufferRight_[cameraIndex],
3420  ImageBufferPMDDepth_[cameraIndex],
3421  ImageBufferPMDAmp_[cameraIndex],
3422  ImageBufferPMDInt_[cameraIndex]);
3423 
3424 
3425 
3426  // try to create and start thread
3427  if(grabSingleThread_[cameraIndex]!= NULL && !grabSingleThread_[cameraIndex]->IsAlive()){
3428  if(grabSingleThread_[cameraIndex]->Create()!=wxTHREAD_NO_ERROR) {
3429  BIASERR("Cannot create GrabSingleThread, saving unthreaded");
3430  }
3431  else{
3432  grabSingleThread_[cameraIndex]->Run();
3433  ThreadInited_[cameraIndex] = true;
3434 #ifdef BIAS_DEBUG
3435  // Thread ID ausgeben
3436  std::cout<<"Created GrabSingleThread: "<<cameraIndex<<endl;
3437  cout << "Created Thread with ID: " << grabSingleThread_[cameraIndex]->GetId()
3438  << " for CAM: " << cameraIndex << endl;
3439 #endif
3440  }
3441  }
3442  else if(grabSingleThread_[cameraIndex]== NULL){
3443  BIASERR("Thread:"<<cameraIndex<<" is NULL!");
3444  }
3445  else if(grabSingleThread_[cameraIndex]->IsAlive()){
3446  BIASERR("Thread:"<<cameraIndex<<" is already Alive!");
3447  }
3448 
3449  if (gmtLock) {
3450  ServerMutex_[cameraIndex]->Unlock();
3451  ClientsMutex_[cameraIndex]->Unlock();
3452  }
3453 
3454  return 0;
3455 }
3456 
3457 
3458 
3459 /****************************************************
3460 *****************************************************/
3461 int ShowCamWxFrame::
3463  int i = 0;
3464  i = cameraIndex;
3465  stringstream text;
3466  text<<"CAM"<<FileHandling::LeadingZeroString(i,2);
3467 
3468  // #ifdef BIAS_HAVE_PANTILT_DP
3469  // if(*bUsePanTiltUnit_){
3470  // (*CamImgPMDDepth_[i]).SetProj(projHeader);
3471  // (*CamImgPMDAmp_[i]).SetProj(projHeader);
3472  // (*CamImgPMDAmp_[i]).UpdateMetaData();
3473  // (*CamImgPMDDepth_[i]).UpdateMetaData();
3474  // }
3475  // #endif
3476 
3477  // create new thread
3478  saveThreads_[i] = new ImageSaveThread(text.str(),
3479  *ParamDown_[i],
3480  BufferAccess_[i],
3481  bWriteBuffered_,
3482  ReadIndex_[i],
3483  WriteIndex_[i],
3484  CamImg_[i],
3485  CamImgMiddle_[i],
3486  CamImgRight_[i],
3487  CamImgPMDDepth_[i],
3488  CamImgPMDAmp_[i],
3489  CamImgPMDInt_[i],
3490  ImageBuffer_[i],
3491  ImageBufferMiddle_[i],
3492  ImageBufferRight_[i],
3493  ImageBufferPMDDepth_[i],
3494  ImageBufferPMDAmp_[i],
3495  ImageBufferPMDInt_[i],
3496  bSaveToStream_);
3497 
3498  // init the thread or capture single image
3499  if(saveThreads_[i] != NULL && saveThreads_[i]->Create() != wxTHREAD_NO_ERROR){
3500  BIASERR("Cannot create ImageSaveThread, saving unthreaded");
3501  }//saveThreads_[i] != NULL && saveThreads_[i]->Create()
3502  else{
3503  cout << "Run Thread" << endl;
3504  saveThreads_[i]->SetPriority(100);
3505  saveThreads_[i]->Run();
3506  }
3507  return 0;
3508 }
static VideoSource * CreatePMDZess(std::string bitfile)
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
The main Parameter Gui interface, derived from BIAS::Param and extends this class.
Definition: ParamGUI.hh:88
YUYV422, 2 channels, full luminance Y, subsampled half U,V.
Definition: ImageBase.hh:133
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
Bayer_GRBG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:145
void OnChangeVideoMode(wxCommandEvent &event)
hsl, similar to HSL but euclidean (h,s) for CNCC
Definition: ImageBase.hh:148
int AboveThresholdToValue(StorageType Threshold, StorageType Value)
sets alls pixels with values above Threshold to Value
Definition: Image.cpp:1028
virtual ~ShowCamWxFrame()
Destructor.
void OnShowCamerasListBox(wxCommandEvent &event)
static VideoSource_Controller_Base * CreateController(CameraType type, VideoSource *cam, wxWindow *parent, const std::string &title="", const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE, const wxString &name=wxFrameNameStr)
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn&#39;t change the ...
Definition: Vector3.hh:202
void StartSavingImagesToDisk()
Starts the saving from all images to disk from all activated cameras.
represents Zess PMD camera driver interface TODO: include support for normal images (2DImg_)...
void OnOpenViscaController(wxCommandEvent &event)
Defines a common interface to different devices.
void AddUEyeCameraToMenu(int camindex, std::string camId, bool fromFile)
Adds a ueye camera to the menu.
void OnShowController(wxCommandEvent &event)
void StopSavingImagesToDisk()
Stops the saving from all images to disk from all activated cameras.
void OnFindOpenNI(wxCommandEvent &event)
HSL, similar to HSV but space is a double tipped cone.
Definition: ImageBase.hh:147
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
void CreateMenu()
Creates the menu of the main window.
gray values, 1 channel
Definition: ImageBase.hh:130
void SetDeviceChannel(int channel)
Use channel to select one of many cameras on the same.
Use the Kinect2 class to grab images from the Microsoft Kinect2.
Implementing wxTwoFilesInputDialogInterface.
void AddWebcamToMenu(std::string name, int camindex, bool fromFile)
Adds a v4l or DShow camera to the menu.
Basic controller interface for Directed Perception Pan Tilt Unit.
void OnShowParameters(wxCommandEvent &event)
void InitCamera(int camindex)
try to initialze the device with index camindex
int BIASVideoSource_EXPORT ScanBus(std::stringstream &ofs)
support function to get the number of cameras and IDs of all cameras on one bus
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
Use OpenNI just like the ToF Cameras.
void InitCombinedImage()
Initializes combined image for selected camera (usb pmd)
int BelowThresholdToValue(StorageType Threshold, StorageType Value)
sets alls pixels with values below Threshold to Value
Definition: Image.cpp:1013
void OnFindWebcams(wxCommandEvent &event)
DV, color model used for digital video cameras such as Mini-DV.
Definition: ImageBase.hh:140
void SetC(const Vector3< POSE_TYPE > &C, const Matrix3x3< POSE_TYPE > &cov)
Set translation (resp.
Definition: Pose.cpp:90
void OnShowImage(wxCommandEvent &event)
int ScaleShiftBetween(double Min, double Max)
scales and shifts image so afterwards every pixel has a value between Min and Max ...
Definition: Image.cpp:1118
void OnChangeTrigger(wxCommandEvent &event)
Implementing wxViscaControlFrameInterface.
YUV411, 2 channles, full luminance, 1 U, 1 V.
Definition: ImageBase.hh:137
int ShowFormat7Selector(int camindex, dc1394video_mode_t mode)
Shows the IEEE1394 Format7 selector frame.
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
void OnFindPMDTec(wxCommandEvent &event)
Support for SwissRanger usb cam.
Bayer_RGGB, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:143
display image in wx application, provides zoom and investigation functionality
Definition: ImageCanvas.hh:38
static VideoSource * CreateDCAM(bool firewireB, bool user_mode, int dcam_mode=-1, float fps=-1, int Format7BpP=-1, int Format7ColorMode_=-1, Vector2< int > Format7LeftTop_=Vector2< int >(-1,-1), Vector2< int > Format7WidthHeight=Vector2< int >(-1,-1))
void OnFindPMDZess(wxCommandEvent &event)
Vector< T > GetCol(const int &col) const
return a copy of column &quot;col&quot;, zero based counting
Definition: Matrix.cpp:252
void InitParams(int &argc, char *argv[])
Initializes all paramaters for param file.
int CreateMasterThread_()
Creates the master thread for handling cameras.
void SetQ(const Quaternion< POSE_TYPE > &Q, const Matrix4x4< POSE_TYPE > &cov)
Set rotation (resp.
Definition: Pose.cpp:103
int CreateImageSaveThreadForCamera_(int cameraIndex)
Creates the thread for saving images for a camera.
int Downsample(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
generic downsample function.
Definition: Rescale.cpp:111
unsigned int GetWidth() const
Definition: ImageBase.hh:312
YUV420P, 2 channels, full luminance Y, 1 U, 1 V. Y, U and V are grouped together for better compressi...
Definition: ImageBase.hh:135
void InitCameras()
Initialize cameras with param file.
void ShowParamGUI()
Shows the parameter GUI.
int SelectedModeFromMenu(int camindex)
Selects a mode from the menu of multiple modes are offered for a camera, used e.g.
int GetQuaternion(Quaternion< ROTATION_MATRIX_TYPE > &quat) const
Calculates quaternion representation for this rotation matrix.
std::vector< std::string > GetDevices()
void OpenDevices()
Tries to open all specified camera devices.
invalid not set image storage type
Definition: ImageBase.hh:111
void OnTimer(wxTimerEvent &event)
3D rotation matrix
Definition: RMatrix.hh:49
color values, 3 channels, order: blue,green,red
Definition: ImageBase.hh:132
Bayer_BGGR, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:146
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
class Vector4 contains a Vector of dim.
Definition: Vector4.hh:65
void OnGrabToStream(wxCommandEvent &event)
int CreateGrabThreadForCamera_(int cameraIndex)
Creates the thread for grabbing images for a camera.
Bayer_GBRG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:144
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
Definition: Pose.hh:73
This class extends VideoSource for the use of DirectShow devices you need Microsoft Windows SDK versi...
int GetAllDevices(std::vector< std::string > &devices)
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
void CleanUpAndExit()
called on end to close cams and exit
Support for CamCube usb cam.
virtual int OpenDevice()
selects the first available device to open (e.g.
CM_YUV444, 3 channels, all channels have full data.
Definition: ImageBase.hh:136
void OnFindUEye(wxCommandEvent &event)
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
static int DeinterleaveHorizontal(const BIAS::ImageBase &raw, BIAS::ImageBase &out)
Take Pointgrey X3B packed interleaved raw and store there three contained images side by side keeping...
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
void OnKeepScrollPosition(wxCommandEvent &event)
void OnWindowClose(wxCloseEvent &event)
static VideoSource * CreateFromTypeIfSupported(CameraType type)
void OnAbout(wxCommandEvent &event)
static std::string LeadingZeroString(const int &n, const unsigned int &digits=DEFAULT_LEADING_ZEROS)
Create a string with leading zeroes from number.
void SelectAndShowCameraImage_()
Selects the current image and shows it in image canvas.
unsigned int GetHeight() const
Definition: ImageBase.hh:319
void OnClickCamerasListBox(wxCommandEvent &event)
void OnGrab(wxCommandEvent &event)
void SaveImageUnthreaded_(int cameraIndex)
Save a image from camera with index cameraIndex.
void OnChangeFirewireB(wxCommandEvent &event)
static int OpenDevice(int type, VideoSource *cam, std::string deviceName, int param=-1)
UYVY422, 2 channels, full luminance Y, subsampled half U,V inverse order.
Definition: ImageBase.hh:134
obsolete, HSI is unused and identical to HSL
Definition: ImageBase.hh:139
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
void OnOpenFlirController(wxCommandEvent &event)
void OnGrabContinuous(wxCommandEvent &event)
static std::string VideoModeToString(dc1394video_mode_t mode)
returns a string from a IEEE1394 video mode
SymTensor2x2 The image contains a 2x2 symmetric tensor.
Definition: ImageBase.hh:149
void AddIEEECameraToMenu(int camindex, int IEEEIndex, bool fromFile)
Adds a IEEE1394/Firewire camera to the menu.
void CreateCameraMenu()
Creates the menu for the available cameras.
RGBA, 4 channels, order: red,green,blue,alpha.
Definition: ImageBase.hh:141
virtual int GetAllDevices(std::vector< std::string > &devices)
This class creates a thread which stores an image in a file if rescale is not zero then the stored im...
virtual int OpenDevice()
selects the first available device to open (e.g.
void OnFindSwissRanger(wxCommandEvent &event)
const T * GetData() const
get the data pointer the member function itself is const (before {..}) because it doesn&#39;t change the...
Definition: Vector4.hh:177
void OnFindIEEE1394(wxCommandEvent &event)
void ParseColorModels()
Parses the color models from param file to enum EColorModel.
RGBE color values, 4 channels, RADIANCE hdr format, four low dynamic channels meaning: 3x mantissa (r...
Definition: ImageBase.hh:151
void OnFit(wxCommandEvent &event)
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
void SetBitFile(std::string file)
void OnFindKinect2(wxCommandEvent &event)
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
Definition: KMatrix.hh:48
virtual int CloseDevice()
invalid (not set) image format
Definition: ImageBase.hh:129
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
Checks for VideoSource capabilities.
void OnSaveParameters(wxCommandEvent &event)
HSV, 3 channels, order: hue, sat , value.
Definition: ImageBase.hh:138
Use Kinect with the libfreenect drivers just like the ToF Cameras.
This class extends VideoSource for the use of IDS uEye devices.
void OnHideCamerasListBox(wxCommandEvent &event)
This class extends VideoSource for the use of Video4Linux supported devices like framegrabber, USB cameras.
void OnOpenDPController(wxCommandEvent &event)
void CreatePerspective(const BIAS::Pose &pose, const BIAS::KMatrix &K, int width, int height, BIAS_ProjParaPersp_DISTORTION_TYPE radDistType=DISTYPE_DEF, const std::vector< double > &UndistortionCoefficients=std::vector< double >(4, 0.0))
Create a perspective camera and add to projection.
Definition: Projection.cpp:133
static std::vector< std::string > CameraNames()
virtual int GrabSingle(Camera< unsigned char > &image)
Returns the 2D image, and reads depth and modulation coefficients.
void OnKey(wxKeyEvent &event)
int OpenDevice(int camindex)
try to open the device with index camindex
virtual void GetDeviceChannelNames(std::vector< std::string > &names)
If more than one channel is present, names can be returned here.
void OnQuit(wxCommandEvent &event)
void OnChangeActivate(wxCommandEvent &event)
int SetROICorners(unsigned int UpperLeftX, unsigned int UpperLeftY, unsigned int LowerRightX, unsigned int LowerRightY)
Definition: ImageBase.cpp:1048
GreyA, 2 channels, grey plus Alpha.
Definition: ImageBase.hh:142
void OnFindKinect(wxCommandEvent &event)
void GetBestForEachResolution(std::vector< ResolutionEntry > &res)
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.
virtual int GetCapabilities(VideoSourceCapabilities &caps)
Use this method to learn something about the capabilities of the source (only useful for V4L sources...
void OnChangeDeviceChannel(wxCommandEvent &event)
Implementing wxTauControlFrameInterface.
static int InitImages(int type, VideoSource *cam, ImageBase *im1, ImageBase *im2=NULL, ImageBase *im3=NULL, ImageBase *im4=NULL)
static VideoSource * CreatePMD(std::string sourcePlugin, std::string procPlugin)
BGRA color values, 4 channels, order: blue,green,red,alpha.
Definition: ImageBase.hh:150
virtual int GetNumDevices()
Return the number of available Kinect 2 devices.
void GrabSingleImageUnthreadedFromCamera_(int cameraIndex)
Grabs an image frmo a camera without using threads.
int CloseDevice(int camindex)
try to close the device with index camindex