Main MRPT website > C++ reference for MRPT 1.9.9
WxUtils.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "gui-precomp.h" // Precompiled headers
11 
12 #include <mrpt/gui/WxUtils.h>
13 #include <mrpt/utils/CImage.h>
14 #include <mrpt/system/filesystem.h>
15 
16 #if MRPT_HAS_WXWIDGETS
17 
18 #include <mrpt/otherlibs/do_opencv_includes.h>
19 
20 using namespace mrpt;
21 using namespace mrpt::gui;
22 using namespace mrpt::utils;
23 using namespace std;
24 
25 //------------------------------------------------------------------------
26 // An auxiliary function for passing MRPT images to wxWidgets images.
27 // The returned object MUST be deleted by hand!
28 //------------------------------------------------------------------------
30 {
31 #if MRPT_HAS_OPENCV
32  IplImage* image = const_cast<IplImage*>(img.getAs<IplImage>());
33  bool free_image_at_end = false;
34 
35  // If the image is GRAYSCALE, we need to convert it into RGB, so do it
36  // manually:
37  if (image->nChannels == 1)
38  {
39  IplImage* new_image =
40  cvCreateImage(cvSize(image->width, image->height), image->depth, 3);
41  new_image->origin = image->origin;
42  cvCvtColor(image, new_image, CV_GRAY2RGB);
43  image = new_image; // Use this new image instead
44  free_image_at_end = true;
45  }
46 
47  int options = 0;
48  if (image->origin == 1) options |= CV_CVTIMG_FLIP;
49  if (image->nChannels == 3 && image->channelSeq[0] == 'B' &&
50  image->channelSeq[2] == 'R')
51  options |= CV_CVTIMG_SWAP_RB;
52  if (options)
53  {
54  IplImage* the_input_img = image;
55 
56  image = cvCreateImage(
57  cvSize(the_input_img->width, the_input_img->height),
58  the_input_img->depth, 3);
59  if (the_input_img->width && the_input_img->height)
60  cvConvertImage(the_input_img, image, options); // convert image
61 
62  if (free_image_at_end) cvReleaseImage(&the_input_img);
63  free_image_at_end = true; // for "image"
64  }
65 
66  int row_in_bytes = image->width * image->nChannels;
67  unsigned char* data = (unsigned char*)malloc(row_in_bytes * image->height);
68 
69  // Copy row by row only if necesary:
70  if (row_in_bytes != image->widthStep)
71  {
72  unsigned char* trg = data;
73  char* src = image->imageData;
74  for (int y = 0; y < image->height;
75  y++, src += image->widthStep, trg += row_in_bytes)
76  memcpy(trg, src, row_in_bytes);
77  }
78  else
79  {
80  memcpy(data, image->imageData, row_in_bytes * image->height);
81  }
82 
83  int w = image->width;
84  int h = image->height;
85 
86  if (free_image_at_end)
87  {
88  cvReleaseImage(&image);
89  }
90 
91  // create and return the object
92  return new wxImage(
93  w, h, data, false); // memory "imgData" will be freed by the object.
94 
95 #else
96  int x, y, lx = img.getWidth(), ly = img.getHeight();
97  unsigned char* imgData = (unsigned char*)malloc(3 * lx * ly);
98  unsigned char* imgPtr = imgData;
99 
100  if (img.isColor())
101  {
102  // Is COLOR
103  if (img.isOriginTopLeft())
104  {
105  for (y = 0; y < ly; y++)
106  {
107  for (x = 0; x < lx; x++)
108  {
109  *(imgPtr++) = *img(x, y, 2);
110  *(imgPtr++) = *img(x, y, 1);
111  *(imgPtr++) = *img(x, y, 0);
112  }
113  }
114  }
115  else
116  {
117  for (y = ly - 1; y >= 0; y--)
118  {
119  for (x = 0; x < lx; x++)
120  {
121  *(imgPtr++) = *img(x, y, 2);
122  *(imgPtr++) = *img(x, y, 1);
123  *(imgPtr++) = *img(x, y, 0);
124  }
125  }
126  }
127  }
128  else
129  {
130  // Is Grayscale:
131  if (img.isOriginTopLeft())
132  {
133  for (y = 0; y < ly; y++)
134  {
135  for (x = 0; x < lx; x++)
136  {
137  unsigned char c = *img(x, y);
138  *(imgPtr++) = c;
139  *(imgPtr++) = c;
140  *(imgPtr++) = c;
141  }
142  }
143  }
144  else
145  {
146  for (y = ly - 1; y >= 0; y--)
147  {
148  for (x = 0; x < lx; x++)
149  {
150  unsigned char c = *img(x, y);
151  *(imgPtr++) = c;
152  *(imgPtr++) = c;
153  *(imgPtr++) = c;
154  }
155  }
156  }
157  }
158  return new wxImage(
159  lx, ly, imgData,
160  false); // memory "imgData" will be freed by the object.
161 #endif
162 }
163 
164 //------------------------------------------------------------------------
165 // An auxiliary function for passing MRPT images to wxWidgets images.
166 // The returned object MUST be deleted by hand!
167 //------------------------------------------------------------------------
169 {
170 #if MRPT_HAS_OPENCV
171  IplImage* image = const_cast<IplImage*>(img.getAs<IplImage>());
172  bool free_image_at_end = false;
173 
174  // If the image is GRAYSCALE, we need to convert it into RGB, so do it
175  // manually:
176  if (image->nChannels == 1)
177  {
178  IplImage* new_image =
179  cvCreateImage(cvSize(image->width, image->height), image->depth, 3);
180  new_image->origin = image->origin;
181  cvCvtColor(image, new_image, CV_GRAY2RGB);
182  image = new_image; // Use this new image instead
183  free_image_at_end = true;
184  }
185 
186  int options = 0;
187  if (image->origin == 1) options |= CV_CVTIMG_FLIP;
188  if (image->nChannels == 3 && image->channelSeq[0] == 'B' &&
189  image->channelSeq[2] == 'R')
190  options |= CV_CVTIMG_SWAP_RB;
191  if (options)
192  {
193  IplImage* the_input_img = image;
194 
195  image = cvCreateImage(
196  cvSize(the_input_img->width, the_input_img->height),
197  the_input_img->depth, 3);
198  cvConvertImage(the_input_img, image, options); // convert image
199 
200  if (free_image_at_end) cvReleaseImage(&the_input_img);
201  free_image_at_end = true; // for "image"
202  }
203 
204  int row_in_bytes = image->width * image->nChannels;
205  unsigned char* data = (unsigned char*)malloc(row_in_bytes * image->height);
206 
207  // Copy row by row only if necesary:
208  if (row_in_bytes != image->widthStep)
209  {
210  unsigned char* trg = data;
211  char* src = image->imageData;
212  for (int y = 0; y < image->height;
213  y++, src += image->widthStep, trg += row_in_bytes)
214  memcpy(trg, src, row_in_bytes);
215  }
216  else
217  {
218  memcpy(data, image->imageData, row_in_bytes * image->height);
219  }
220 
221  int w = image->width;
222  int h = image->height;
223 
224  if (free_image_at_end)
225  {
226  cvReleaseImage(&image);
227  }
228 
229  // create and return the object
230  return new wxBitmap(wxImage(w, h, data, false));
231 #else
232  THROW_EXCEPTION("MRPT compiled without OpenCV")
233 #endif
234 }
235 
236 #if MRPT_HAS_OPENCV
238 {
239  IplImage* image = static_cast<IplImage*>(img);
240 
241  ASSERT_(image);
242  ASSERT_(image->nChannels == 3);
243 
244  // require conversion ?
245  int options = 0;
246  if (image->origin == 1) options |= CV_CVTIMG_FLIP;
247  if (image->channelSeq[0] == 'B' && image->channelSeq[2] == 'R')
248  options |= CV_CVTIMG_SWAP_RB;
249  if (options)
250  cvConvertImage(image, image, options); // convert image "in place"
251 
252  int row_bytes =
253  image->width * image->nChannels * ((image->depth & 255) >> 3);
254 
255  unsigned char* imageData =
256  (unsigned char*)malloc(row_bytes * image->height);
257  ASSERT_(imageData);
258 
259  // copy row by row only if necesary
260  if (row_bytes != image->widthStep)
261  {
262  for (int y = 0; y < image->height; y++)
263  memcpy(
264  (imageData + y * row_bytes),
265  (image->imageData + y * image->widthStep), row_bytes);
266  }
267  else
268  {
269  memcpy(imageData, image->imageData, row_bytes * image->height);
270  }
271 
272  // create and return the object
273  return new wxImage(image->width, image->height, imageData, false);
274 }
275 #endif
276 
277 //------------------------------------------------------------------------
278 // Convert wxImage -> MRPTImage
279 //------------------------------------------------------------------------
281 {
282  CImage* newImg = new CImage();
283 
284  const size_t lx = img.GetWidth();
285  const size_t ly = img.GetHeight();
286 
287  newImg->loadFromMemoryBuffer(
288  lx, ly, true, img.GetData(), true /* swap RB */);
289 
290  return newImg;
291 }
292 
293 //------------------------------------------------------------------------
294 // Convert wxImage -> MRPTImagePtr
295 //------------------------------------------------------------------------
297 {
299 }
300 
301 //------------------------------------------------------------------------
302 // wxMRPTImageControl
303 //------------------------------------------------------------------------
305  wxWindow* parent, wxWindowID winID, int x, int y, int width, int height)
306  : m_img(nullptr)
307 {
308  this->Create(parent, winID, wxPoint(x, y), wxSize(width, height));
309 
310  Connect(wxEVT_PAINT, wxPaintEventHandler(wxMRPTImageControl::OnPaint));
311  Connect(wxEVT_MOTION, wxMouseEventHandler(wxMRPTImageControl::OnMouseMove));
312  Connect(
313  wxID_ANY, wxEVT_LEFT_DOWN,
314  wxMouseEventHandler(wxMRPTImageControl::OnMouseClick));
315 
316  // Connect(wxID_ANY,wxEVT_CHAR,(wxObjectEventFunction)&wxMRPTImageControl::OnChar);
317 }
318 
320 {
321  std::lock_guard<std::mutex> lock(m_img_cs);
322  if (m_img)
323  {
324  delete m_img;
325  m_img = nullptr;
326  }
327 }
328 
329 void wxMRPTImageControl::OnMouseMove(wxMouseEvent& ev)
330 {
331  std::lock_guard<std::mutex> lock(m_mouse_cs);
332  m_last_mouse_point = ev.GetPosition();
333 }
334 
335 void wxMRPTImageControl::OnMouseClick(wxMouseEvent& ev)
336 {
337  std::lock_guard<std::mutex> lock(m_mouse_cs);
338  m_last_mouse_click = ev.GetPosition();
339 }
340 
342 {
343  std::lock_guard<std::mutex> lock(m_img_cs);
344  if (m_img)
345  {
346  delete m_img;
347  m_img = nullptr;
348  }
349 
350  m_img = img;
351 }
352 
354 {
355  wxBitmap* wxImg = MRPTImage2wxBitmap(img);
356 
357  std::lock_guard<std::mutex> lock(m_img_cs);
358  if (m_img)
359  {
360  delete m_img;
361  m_img = nullptr;
362  }
363 
364  m_img = wxImg;
365 }
366 
367 void wxMRPTImageControl::OnPaint(wxPaintEvent& ev)
368 {
369  wxPaintDC dc(this);
370 
371  std::lock_guard<std::mutex> lock(m_img_cs);
372  if (!m_img)
373  {
374  // Erase background:
375  return;
376  }
377 
378  dc.DrawBitmap(*m_img, 0, 0);
379 }
380 
381 void wxMRPTImageControl::GetBitmap(wxBitmap& bmp)
382 {
383  std::lock_guard<std::mutex> lock(m_img_cs);
384  if (!m_img) return;
385  bmp = *m_img;
386 }
387 
388 // *********************************************************************
389 // CPanelCameraSelection
390 // *********************************************************************
391 
392 //(*IdInit(CPanelCameraSelection)
393 const long CPanelCameraSelection::ID_STATICTEXT1 = wxNewId();
394 const long CPanelCameraSelection::ID_SPINCTRL1 = wxNewId();
395 const long CPanelCameraSelection::ID_STATICTEXT3 = wxNewId();
396 const long CPanelCameraSelection::ID_CHOICE1 = wxNewId();
397 const long CPanelCameraSelection::ID_STATICTEXT6 = wxNewId();
398 const long CPanelCameraSelection::ID_CHOICE2 = wxNewId();
399 const long CPanelCameraSelection::ID_PANEL2 = wxNewId();
400 const long CPanelCameraSelection::ID_STATICTEXT7 = wxNewId();
401 const long CPanelCameraSelection::ID_TEXTCTRL1 = wxNewId();
402 const long CPanelCameraSelection::ID_PANEL3 = wxNewId();
403 const long CPanelCameraSelection::ID_TEXTCTRL6 = wxNewId();
404 const long CPanelCameraSelection::ID_PANEL4 = wxNewId();
405 const long CPanelCameraSelection::ID_STATICTEXT8 = wxNewId();
406 const long CPanelCameraSelection::ID_TEXTCTRL2 = wxNewId();
407 const long CPanelCameraSelection::ID_BUTTON7 = wxNewId();
408 const long CPanelCameraSelection::ID_PANEL5 = wxNewId();
409 const long CPanelCameraSelection::ID_STATICTEXT9 = wxNewId();
410 const long CPanelCameraSelection::ID_TEXTCTRL3 = wxNewId();
411 const long CPanelCameraSelection::ID_BUTTON8 = wxNewId();
412 const long CPanelCameraSelection::ID_STATICTEXT5 = wxNewId();
413 const long CPanelCameraSelection::ID_TEXTCTRL7 = wxNewId();
414 const long CPanelCameraSelection::ID_BUTTON9 = wxNewId();
415 const long CPanelCameraSelection::ID_STATICTEXT10 = wxNewId();
416 const long CPanelCameraSelection::ID_TEXTCTRL8 = wxNewId();
417 const long CPanelCameraSelection::ID_STATICTEXT11 = wxNewId();
418 const long CPanelCameraSelection::ID_PANEL6 = wxNewId();
419 const long CPanelCameraSelection::ID_RADIOBOX1 = wxNewId();
420 const long CPanelCameraSelection::ID_CHECKBOX1 = wxNewId();
421 const long CPanelCameraSelection::ID_STATICTEXT2 = wxNewId();
422 const long CPanelCameraSelection::ID_PANEL7 = wxNewId();
423 const long CPanelCameraSelection::ID_RADIOBOX2 = wxNewId();
424 const long CPanelCameraSelection::ID_STATICTEXT4 = wxNewId();
425 const long CPanelCameraSelection::ID_TEXTCTRL4 = wxNewId();
426 const long CPanelCameraSelection::ID_CHECKBOX3 = wxNewId();
427 const long CPanelCameraSelection::ID_CHECKBOX4 = wxNewId();
428 const long CPanelCameraSelection::ID_CHECKBOX5 = wxNewId();
429 const long CPanelCameraSelection::ID_CHECKBOX6 = wxNewId();
430 const long CPanelCameraSelection::ID_PANEL1 = wxNewId();
431 const long CPanelCameraSelection::ID_CHECKBOX7 = wxNewId();
432 const long CPanelCameraSelection::ID_CHECKBOX8 = wxNewId();
433 const long CPanelCameraSelection::ID_CHECKBOX9 = wxNewId();
434 const long CPanelCameraSelection::ID_RADIOBOX3 = wxNewId();
435 const long CPanelCameraSelection::ID_PANEL8 = wxNewId();
436 const long CPanelCameraSelection::ID_NOTEBOOK1 = wxNewId();
437 const long CPanelCameraSelection::ID_CHECKBOX2 = wxNewId();
438 //*)
439 
440 BEGIN_EVENT_TABLE(CPanelCameraSelection, wxPanel)
441 //(*EventTable(CPanelCameraSelection)
442 //*)
443 END_EVENT_TABLE()
444 
445 CPanelCameraSelection::CPanelCameraSelection(wxWindow* parent, wxWindowID id)
446 {
447  //(*Initialize(CPanelCameraSelection)
448  wxStaticBoxSizer* StaticBoxSizer2;
449  wxFlexGridSizer* FlexGridSizer4;
450  wxFlexGridSizer* FlexGridSizer16;
451  wxFlexGridSizer* FlexGridSizer10;
452  wxFlexGridSizer* FlexGridSizer3;
453  wxFlexGridSizer* FlexGridSizer5;
454  wxFlexGridSizer* FlexGridSizer2;
455  wxFlexGridSizer* FlexGridSizer18;
456  wxFlexGridSizer* FlexGridSizer13;
457  wxFlexGridSizer* FlexGridSizer12;
458  wxStaticBoxSizer* StaticBoxSizer1;
459  wxFlexGridSizer* FlexGridSizer1;
460  wxFlexGridSizer* FlexGridSizer11;
461 
462  Create(
463  parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL,
464  _T("id"));
465  FlexGridSizer1 = new wxFlexGridSizer(0, 1, 0, 0);
466  FlexGridSizer1->AddGrowableCol(0);
467  FlexGridSizer1->AddGrowableRow(0);
468  pagesCameras = new wxNotebook(
469  this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0,
470  _T("ID_NOTEBOOK1"));
471  Panel2 = new wxPanel(
472  pagesCameras, ID_PANEL2, wxDefaultPosition, wxDefaultSize,
473  wxTAB_TRAVERSAL, _T("ID_PANEL2"));
474  FlexGridSizer10 = new wxFlexGridSizer(0, 2, 0, 0);
475  FlexGridSizer10->AddGrowableCol(1);
476  StaticText1 = new wxStaticText(
477  Panel2, ID_STATICTEXT1, _("Camera index:"), wxDefaultPosition,
478  wxDefaultSize, 0, _T("ID_STATICTEXT1"));
479  FlexGridSizer10->Add(
480  StaticText1, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
481  opencvCamIndex = new wxSpinCtrl(
482  Panel2, ID_SPINCTRL1, _T("0"), wxDefaultPosition, wxDefaultSize, 0, 0,
483  100, 0, _T("ID_SPINCTRL1"));
484  opencvCamIndex->SetValue(_T("0"));
485  FlexGridSizer10->Add(
486  opencvCamIndex, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
487  StaticText3 = new wxStaticText(
488  Panel2, ID_STATICTEXT3, _("Camera type:"), wxDefaultPosition,
489  wxDefaultSize, 0, _T("ID_STATICTEXT3"));
490  FlexGridSizer10->Add(
491  StaticText3, 1,
492  wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
493  cbOpencvCamType = new wxChoice(
494  Panel2, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 0, 0, 0,
495  wxDefaultValidator, _T("ID_CHOICE1"));
496  cbOpencvCamType->SetSelection(
497  cbOpencvCamType->Append(_("CAMERA_CV_AUTODETECT")));
498  cbOpencvCamType->Append(_("CAMERA_CV_DC1394"));
499  cbOpencvCamType->Append(_("CAMERA_CV_VFL"));
500  cbOpencvCamType->Append(_("CAMERA_CV_VFW"));
501  cbOpencvCamType->Append(_("CAMERA_CV_MIL"));
502  cbOpencvCamType->Append(_("CAMERA_CV_DSHOW"));
503  FlexGridSizer10->Add(
504  cbOpencvCamType, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
505  StaticText6 = new wxStaticText(
506  Panel2, ID_STATICTEXT6, _("Resolution:"), wxDefaultPosition,
507  wxDefaultSize, 0, _T("ID_STATICTEXT6"));
508  FlexGridSizer10->Add(
509  StaticText6, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
510  cbOpencvResolution = new wxChoice(
511  Panel2, ID_CHOICE2, wxDefaultPosition, wxDefaultSize, 0, 0, 0,
512  wxDefaultValidator, _T("ID_CHOICE2"));
513  cbOpencvResolution->SetSelection(cbOpencvResolution->Append(_("default")));
514  cbOpencvResolution->Append(_("320x240"));
515  cbOpencvResolution->Append(_("640x480"));
516  FlexGridSizer10->Add(
517  cbOpencvResolution, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL,
518  5);
519  FlexGridSizer10->Add(
520  -1, -1, 1, wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL,
521  0);
522  Panel2->SetSizer(FlexGridSizer10);
523  FlexGridSizer10->Fit(Panel2);
524  FlexGridSizer10->SetSizeHints(Panel2);
525  Panel3 = new wxPanel(
526  pagesCameras, ID_PANEL3, wxDefaultPosition, wxDefaultSize,
527  wxTAB_TRAVERSAL, _T("ID_PANEL3"));
528  FlexGridSizer11 = new wxFlexGridSizer(0, 1, 0, 0);
529  FlexGridSizer11->AddGrowableCol(0);
530  StaticText7 = new wxStaticText(
531  Panel3, ID_STATICTEXT7, _("IP Camera URL:"), wxDefaultPosition,
532  wxDefaultSize, 0, _T("ID_STATICTEXT7"));
533  FlexGridSizer11->Add(
534  StaticText7, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
535  edIPcamURL = new wxTextCtrl(
536  Panel3, ID_TEXTCTRL1, _("rtsp://192.168.0.1/live.sdp"),
537  wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
538  _T("ID_TEXTCTRL1"));
539  FlexGridSizer11->Add(
540  edIPcamURL, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
541  Panel3->SetSizer(FlexGridSizer11);
542  FlexGridSizer11->Fit(Panel3);
543  FlexGridSizer11->SetSizeHints(Panel3);
544  Panel4 = new wxPanel(
545  pagesCameras, ID_PANEL4, wxDefaultPosition, wxDefaultSize,
546  wxTAB_TRAVERSAL, _T("ID_PANEL4"));
547  FlexGridSizer16 = new wxFlexGridSizer(0, 1, 0, 0);
548  FlexGridSizer16->AddGrowableCol(0);
549  FlexGridSizer16->AddGrowableRow(0);
550  edCustomCamConfig = new wxTextCtrl(
551  Panel4, ID_TEXTCTRL6,
552  _("// Configuration block for the CCameraSensor object.\n// Check out "
553  "its documentation at:\n// "
554  "http://reference.mrpt.org/devel/"
555  "classmrpt_1_1hwdrivers_1_1_c_camera_sensor.html\n\n[CONFIG]"
556  "\ngrabber_type = opencv \ncv_camera_index = 0\ncv_camera_type = "
557  "CAMERA_CV_AUTODETECT\n\n"),
558  wxDefaultPosition, wxDefaultSize,
559  wxTE_MULTILINE | wxHSCROLL | wxTE_DONTWRAP | wxVSCROLL |
560  wxALWAYS_SHOW_SB,
561  wxDefaultValidator, _T("ID_TEXTCTRL6"));
562  wxFont edCustomCamConfigFont =
563  wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT);
564  if (!edCustomCamConfigFont.Ok())
565  edCustomCamConfigFont =
566  wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
567  edCustomCamConfigFont.SetPointSize(7);
568  edCustomCamConfig->SetFont(edCustomCamConfigFont);
569  FlexGridSizer16->Add(
570  edCustomCamConfig, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
571  Panel4->SetSizer(FlexGridSizer16);
572  FlexGridSizer16->Fit(Panel4);
573  FlexGridSizer16->SetSizeHints(Panel4);
574  Panel5 = new wxPanel(
575  pagesCameras, ID_PANEL5, wxDefaultPosition, wxDefaultSize,
576  wxTAB_TRAVERSAL, _T("ID_PANEL5"));
577  FlexGridSizer12 = new wxFlexGridSizer(0, 1, 0, 0);
578  FlexGridSizer12->AddGrowableCol(0);
579  StaticText8 = new wxStaticText(
580  Panel5, ID_STATICTEXT8, _("Video file to open:"), wxDefaultPosition,
581  wxDefaultSize, 0, _T("ID_STATICTEXT8"));
582  FlexGridSizer12->Add(
583  StaticText8, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
584  edVideoFile = new wxTextCtrl(
585  Panel5, ID_TEXTCTRL2, _("test.avi"), wxDefaultPosition, wxDefaultSize,
586  0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
587  FlexGridSizer12->Add(
588  edVideoFile, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
589  btnBrowseVideo = new wxButton(
590  Panel5, ID_BUTTON7, _("Browse..."), wxDefaultPosition, wxDefaultSize, 0,
591  wxDefaultValidator, _T("ID_BUTTON7"));
592  FlexGridSizer12->Add(
593  btnBrowseVideo, 1,
594  wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
595  Panel5->SetSizer(FlexGridSizer12);
596  FlexGridSizer12->Fit(Panel5);
597  FlexGridSizer12->SetSizeHints(Panel5);
598  Panel6 = new wxPanel(
599  pagesCameras, ID_PANEL6, wxDefaultPosition, wxDefaultSize,
600  wxTAB_TRAVERSAL, _T("ID_PANEL6"));
601  FlexGridSizer13 = new wxFlexGridSizer(0, 3, 0, 0);
602  FlexGridSizer13->AddGrowableCol(1);
603  StaticText9 = new wxStaticText(
604  Panel6, ID_STATICTEXT9, _("Rawlog \nfile:"), wxDefaultPosition,
605  wxDefaultSize, 0, _T("ID_STATICTEXT9"));
606  FlexGridSizer13->Add(
607  StaticText9, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
608  edRawlogFile = new wxTextCtrl(
609  Panel6, ID_TEXTCTRL3, _("test.rawlog"), wxDefaultPosition,
610  wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
611  FlexGridSizer13->Add(
612  edRawlogFile, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
613  btnBrowseRawlog = new wxButton(
614  Panel6, ID_BUTTON8, _("Browse..."), wxDefaultPosition, wxDefaultSize, 0,
615  wxDefaultValidator, _T("ID_BUTTON8"));
616  FlexGridSizer13->Add(
617  btnBrowseRawlog, 1,
618  wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
619  StaticText5 = new wxStaticText(
620  Panel6, ID_STATICTEXT5, _("External \nimages:"), wxDefaultPosition,
621  wxDefaultSize, 0, _T("ID_STATICTEXT5"));
622  FlexGridSizer13->Add(
623  StaticText5, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
624  edRawlogImgDir = new wxTextCtrl(
625  Panel6, ID_TEXTCTRL7, _("./Images"), wxDefaultPosition, wxDefaultSize,
626  0, wxDefaultValidator, _T("ID_TEXTCTRL7"));
627  FlexGridSizer13->Add(
628  edRawlogImgDir, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
629  btnBrowseRawlogDir = new wxButton(
630  Panel6, ID_BUTTON9, _("Browse..."), wxDefaultPosition, wxDefaultSize, 0,
631  wxDefaultValidator, _T("ID_BUTTON9"));
632  FlexGridSizer13->Add(
633  btnBrowseRawlogDir, 1,
634  wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
635  StaticText10 = new wxStaticText(
636  Panel6, ID_STATICTEXT10, _("Sensor\nlabel:"), wxDefaultPosition,
637  wxDefaultSize, 0, _T("ID_STATICTEXT10"));
638  FlexGridSizer13->Add(
639  StaticText10, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5);
640  edRawlogLabel = new wxTextCtrl(
641  Panel6, ID_TEXTCTRL8, wxEmptyString, wxDefaultPosition, wxDefaultSize,
642  0, wxDefaultValidator, _T("ID_TEXTCTRL8"));
643  FlexGridSizer13->Add(
644  edRawlogLabel, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
645  StaticText11 = new wxStaticText(
646  Panel6, ID_STATICTEXT11, _("(empty=any)"), wxDefaultPosition,
647  wxDefaultSize, 0, _T("ID_STATICTEXT11"));
648  FlexGridSizer13->Add(
649  StaticText11, 1,
650  wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
651  Panel6->SetSizer(FlexGridSizer13);
652  FlexGridSizer13->Fit(Panel6);
653  FlexGridSizer13->SetSizeHints(Panel6);
654  Panel1 = new wxPanel(
655  pagesCameras, ID_PANEL7, wxDefaultPosition, wxDefaultSize,
656  wxTAB_TRAVERSAL, _T("ID_PANEL7"));
657  FlexGridSizer18 = new wxFlexGridSizer(2, 2, 0, 0);
658  wxString __wxRadioBoxChoices_1[2] = {_("Left"), _("Right")};
659  rbBumblebeeSel = new wxRadioBox(
660  Panel1, ID_RADIOBOX1, _("Select monocular input"), wxDefaultPosition,
661  wxDefaultSize, 2, __wxRadioBoxChoices_1, 1, 0, wxDefaultValidator,
662  _T("ID_RADIOBOX1"));
663  rbBumblebeeSel->SetSelection(0);
664  FlexGridSizer18->Add(
665  rbBumblebeeSel, 1,
666  wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
667  cbBumblebeeRectif = new wxCheckBox(
668  Panel1, ID_CHECKBOX1, _("Use vendor\'s rectify"), wxDefaultPosition,
669  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
670  cbBumblebeeRectif->SetValue(false);
671  FlexGridSizer18->Add(
672  cbBumblebeeRectif, 1, wxALL | wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL,
673  10);
674  FlexGridSizer18->Add(-1, -1, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
675  StaticText2 = new wxStaticText(
676  Panel1, ID_STATICTEXT2, _("(Unchecked = raw images)"),
677  wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
678  FlexGridSizer18->Add(
679  StaticText2, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
680  Panel1->SetSizer(FlexGridSizer18);
681  FlexGridSizer18->Fit(Panel1);
682  FlexGridSizer18->SetSizeHints(Panel1);
683  pnSwissRanger = new wxPanel(
684  pagesCameras, ID_PANEL1, wxDefaultPosition, wxDefaultSize,
685  wxTAB_TRAVERSAL, _T("ID_PANEL1"));
686  FlexGridSizer2 = new wxFlexGridSizer(2, 3, 0, 0);
687  wxString __wxRadioBoxChoices_2[2] = {_("USB"), _("Ethernet")};
688  rbSR_usb = new wxRadioBox(
689  pnSwissRanger, ID_RADIOBOX2, _("Connection"), wxDefaultPosition,
690  wxDefaultSize, 2, __wxRadioBoxChoices_2, 1, 0, wxDefaultValidator,
691  _T("ID_RADIOBOX2"));
692  FlexGridSizer2->Add(
693  rbSR_usb, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
694  StaticText4 = new wxStaticText(
695  pnSwissRanger, ID_STATICTEXT4, _("IP:"), wxDefaultPosition,
696  wxDefaultSize, 0, _T("ID_STATICTEXT4"));
697  FlexGridSizer2->Add(
698  StaticText4, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
699  edSR_IP = new wxTextCtrl(
700  pnSwissRanger, ID_TEXTCTRL4, _("192.168.2.14"), wxDefaultPosition,
701  wxSize(120, -1), 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
702  FlexGridSizer2->Add(
703  edSR_IP, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
704  StaticBoxSizer1 = new wxStaticBoxSizer(
705  wxHORIZONTAL, pnSwissRanger, _("Channels to grab: "));
706  FlexGridSizer3 = new wxFlexGridSizer(4, 1, 0, 0);
707  cbSR_chIntensity = new wxCheckBox(
708  pnSwissRanger, ID_CHECKBOX3, _("Grayscale intensity"),
709  wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator,
710  _T("ID_CHECKBOX3"));
711  cbSR_chIntensity->SetValue(true);
712  cbSR_chIntensity->Disable();
713  FlexGridSizer3->Add(
714  cbSR_chIntensity, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
715  cbSR_ch3D = new wxCheckBox(
716  pnSwissRanger, ID_CHECKBOX4, _("3D point cloud"), wxDefaultPosition,
717  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX4"));
718  cbSR_ch3D->SetValue(false);
719  FlexGridSizer3->Add(cbSR_ch3D, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
720  cbSR_chRange = new wxCheckBox(
721  pnSwissRanger, ID_CHECKBOX5, _("Depth image"), wxDefaultPosition,
722  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX5"));
723  cbSR_chRange->SetValue(false);
724  FlexGridSizer3->Add(
725  cbSR_chRange, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
726  cbSR_chConf = new wxCheckBox(
727  pnSwissRanger, ID_CHECKBOX6, _("Confidence"), wxDefaultPosition,
728  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX6"));
729  cbSR_chConf->SetValue(false);
730  FlexGridSizer3->Add(
731  cbSR_chConf, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
732  StaticBoxSizer1->Add(
733  FlexGridSizer3, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_BOTTOM, 0);
734  FlexGridSizer2->Add(
735  StaticBoxSizer1, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_BOTTOM,
736  5);
737  pnSwissRanger->SetSizer(FlexGridSizer2);
738  FlexGridSizer2->Fit(pnSwissRanger);
739  FlexGridSizer2->SetSizeHints(pnSwissRanger);
740  pnKinect = new wxPanel(
741  pagesCameras, ID_PANEL8, wxDefaultPosition, wxDefaultSize,
742  wxTAB_TRAVERSAL, _T("ID_PANEL8"));
743  FlexGridSizer4 = new wxFlexGridSizer(2, 3, 0, 0);
744  StaticBoxSizer2 =
745  new wxStaticBoxSizer(wxHORIZONTAL, pnKinect, _("Channels to grab: "));
746  FlexGridSizer5 = new wxFlexGridSizer(4, 1, 0, 0);
747  cbKinect_Int = new wxCheckBox(
748  pnKinect, ID_CHECKBOX7, _("Intensity"), wxDefaultPosition,
749  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX7"));
750  cbKinect_Int->SetValue(true);
751  cbKinect_Int->Disable();
752  FlexGridSizer5->Add(
753  cbKinect_Int, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
754  cbKinect_3D = new wxCheckBox(
755  pnKinect, ID_CHECKBOX8, _("3D point cloud"), wxDefaultPosition,
756  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX8"));
757  cbKinect_3D->SetValue(false);
758  FlexGridSizer5->Add(
759  cbKinect_3D, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
760  cbKinect_Depth = new wxCheckBox(
761  pnKinect, ID_CHECKBOX9, _("Depth image"), wxDefaultPosition,
762  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX9"));
763  cbKinect_Depth->SetValue(false);
764  FlexGridSizer5->Add(
765  cbKinect_Depth, 1, wxALL | wxALIGN_LEFT | wxALIGN_BOTTOM, 5);
766  StaticBoxSizer2->Add(
767  FlexGridSizer5, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_BOTTOM, 0);
768  FlexGridSizer4->Add(
769  StaticBoxSizer2, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_BOTTOM,
770  5);
771  wxString __wxRadioBoxChoices_3[2] = {_("RGB camera"), _("IR camera")};
772  rbKinect_int = new wxRadioBox(
773  pnKinect, ID_RADIOBOX3, _("Intensity channel:"), wxDefaultPosition,
774  wxDefaultSize, 2, __wxRadioBoxChoices_3, 1, 0, wxDefaultValidator,
775  _T("ID_RADIOBOX3"));
776  rbKinect_int->SetSelection(0);
777  FlexGridSizer4->Add(
778  rbKinect_int, 1, wxALL | wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL, 5);
779  pnKinect->SetSizer(FlexGridSizer4);
780  FlexGridSizer4->Fit(pnKinect);
781  FlexGridSizer4->SetSizeHints(pnKinect);
782  pagesCameras->AddPage(Panel2, _("Camera (opencv)"), false);
783  pagesCameras->AddPage(Panel3, _("Camera (FFmpeg)"), false);
784  pagesCameras->AddPage(Panel4, _("Camera (custom)"), false);
785  pagesCameras->AddPage(Panel5, _("Video file"), false);
786  pagesCameras->AddPage(Panel6, _("Rawlog file"), false);
787  pagesCameras->AddPage(Panel1, _("Bumblebee"), false);
788  pagesCameras->AddPage(pnSwissRanger, _("SwissRanger ToF"), false);
789  pagesCameras->AddPage(pnKinect, _("Kinect"), false);
790  FlexGridSizer1->Add(
791  pagesCameras, 1, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
792  cbGrayscale = new wxCheckBox(
793  this, ID_CHECKBOX2, _("Capture in grayscale"), wxDefaultPosition,
794  wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
795  cbGrayscale->SetValue(true);
796  FlexGridSizer1->Add(
797  cbGrayscale, 1, wxALL | wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP, 5);
798  SetSizer(FlexGridSizer1);
799  FlexGridSizer1->Fit(this);
800  FlexGridSizer1->SetSizeHints(this);
801 
802  Connect(
803  ID_BUTTON7, wxEVT_COMMAND_BUTTON_CLICKED,
804  (wxObjectEventFunction)&CPanelCameraSelection::OnbtnBrowseVideoClick);
805  Connect(
806  ID_BUTTON8, wxEVT_COMMAND_BUTTON_CLICKED,
807  (wxObjectEventFunction)&CPanelCameraSelection::OnbtnBrowseRawlogClick);
808  Connect(
809  ID_BUTTON9, wxEVT_COMMAND_BUTTON_CLICKED,
810  (wxObjectEventFunction)&CPanelCameraSelection::
811  OnbtnBrowseRawlogDirClick);
812  //*)
813 
814  // end of automatically-generated code above:
815  cbOpencvResolution->Clear();
816  cbOpencvResolution->SetSelection(cbOpencvResolution->Append(_("default")));
817 
818  cbOpencvResolution->Append(_("320x240"));
819  cbOpencvResolution->Append(_("640x480"));
820  cbOpencvResolution->Append(_("800x600"));
821  cbOpencvResolution->Append(_("1024x768"));
822  cbOpencvResolution->Append(_("1280x1024"));
823 }
824 
826 {
827  wxFileDialog dialog(
828  this, wxT("Choose a video to open"), wxT("."), wxT(""),
829  wxT("Video files (*.avi;*.mpg;*.mov)|*.avi;*.mpg;*.mov|All files "
830  "(*.*)|*.*"),
831  wxFD_OPEN | wxFD_FILE_MUST_EXIST);
832 
833  if (dialog.ShowModal() == wxID_OK) edVideoFile->SetValue(dialog.GetPath());
834 }
835 
837 {
838  wxFileDialog dialog(
839  this, wxT("Choose a rawlog to open"), wxT("."), wxT(""),
840  wxT("Rawlog files (*.rawlog;*.rawlog.gz)|*.rawlog;*.rawlog.gz|All "
841  "files (*.*)|*.*"),
842  wxFD_OPEN | wxFD_FILE_MUST_EXIST);
843 
844  if (dialog.ShowModal() == wxID_OK)
845  {
846  edRawlogFile->SetValue(dialog.GetPath());
847 
849  string(edRawlogImgDir->GetValue().mb_str())))
850  {
851  string fil = string(dialog.GetPath().mb_str());
852  string fil_path = mrpt::system::extractFileDirectory(fil);
853  fil_path += "/Images";
854  edRawlogImgDir->SetValue(_U(fil_path.c_str()));
855  }
856  }
857 }
858 
860 {
861  wxDirDialog dialog(
862  this, wxT("Choose the rawlog directory with external images"),
863  edRawlogImgDir->GetValue(), wxDD_DEFAULT_STYLE);
864 
865  if (dialog.ShowModal() == wxID_OK)
866  edRawlogImgDir->SetValue(dialog.GetPath());
867 }
868 
870 {
871  //(*Destroy(CPanelCameraSelection)
872  //*)
873 }
874 
875 /* ------------------------------------------------------------------------
876  writeConfigFromVideoSourcePanel
877  ------------------------------------------------------------------------ */
879  const std::string& sect, mrpt::utils::CConfigFileBase* cfg) const
880 {
881  MRPT_START
882 
883  switch (this->pagesCameras->GetSelection())
884  {
885  // OpenCV:
886  // -----------------------------------
887  case 0:
888  {
889  cfg->write(sect, "grabber_type", "opencv");
890  cfg->write(
891  sect, "cv_camera_index",
892  format("%i", this->opencvCamIndex->GetValue()));
893  cfg->write(
894  sect, "cv_camera_type",
895  string(this->cbOpencvCamType->GetStringSelection().mb_str()));
896 
897  const std::string sRes =
898  std::string(cbOpencvResolution->GetStringSelection().mb_str());
899 
900  if (!sRes.empty())
901  {
902  const size_t p = sRes.find("x");
903  if (p != std::string::npos)
904  {
905  const std::string sW = sRes.substr(0, p);
906  const std::string sH = sRes.substr(p + 1);
907 
908  cfg->write(sect, "cv_frame_width", sW);
909  cfg->write(sect, "cv_frame_height", sH);
910  }
911  }
912  }
913  break;
914 
915  // Camera FFmpeg
916  // -----------------------------------
917  case 1:
918  {
919  cfg->write(sect, "grabber_type", "ffmpeg");
920  cfg->write(
921  sect, "ffmpeg_url",
922  string(this->edIPcamURL->GetValue().mb_str()));
923  }
924  break;
925 
926  // Camera custom
927  // -----------------------------------
928  case 2:
929  {
930  // Replicate the config sections in "edCustomCamConfig" into "cfg":
932  string(edCustomCamConfig->GetValue().mb_str()));
933  vector_string allSects;
934  cfgIn.getAllSections(allSects);
935  for (size_t idxSect = 0; idxSect < allSects.size(); idxSect++)
936  {
937  vector_string keys;
938  cfgIn.getAllKeys(allSects[idxSect], keys);
939  for (size_t i = 0; i < keys.size(); i++)
940  cfg->write(
941  allSects[idxSect], keys[i],
942  cfgIn.read_string(allSects[idxSect], keys[i], ""));
943  }
944  }
945  break;
946 
947  // Video file
948  // -----------------------------------
949  case 3:
950  {
951  cfg->write(sect, "grabber_type", "ffmpeg");
952  cfg->write(
953  sect, "ffmpeg_url",
954  string(this->edVideoFile->GetValue().mb_str()));
955  }
956  break;
957 
958  // Rawlog
959  // -----------------------------------
960  case 4:
961  {
962  cfg->write(sect, "grabber_type", "rawlog");
963  cfg->write(
964  sect, "rawlog_file",
965  string(this->edRawlogFile->GetValue().mb_str()));
966 
967  const string rawlog_lb =
968  string(this->edRawlogLabel->GetValue().mb_str());
969  if (!rawlog_lb.empty())
970  cfg->write(sect, "rawlog_camera_sensor_label", rawlog_lb);
971 
972  CImage::setImagesPathBase(string(this->edRawlogImgDir->GetValue().mb_str()));
973  }
974  break;
975 
976  // Bumblebee
977  // -----------------------------------
978  case 5:
979  {
980  cfg->write(sect, "grabber_type", "bumblebee");
981  if (this->rbBumblebeeSel->GetSelection() < 2)
982  cfg->write(
983  sect, "bumblebee_mono",
984  format("%i\n", (int)this->rbBumblebeeSel->GetSelection()));
985  else
986  { /* Use stereo capture */
987  }
988  cfg->write(sect, "bumblebee_fps", 15);
989  cfg->write(
990  sect, "bumblebee_get_rectified",
991  this->cbBumblebeeRectif->GetValue());
992  }
993  break;
994 
995  // Swissranger
996  // -----------------------------------
997  case 6:
998  {
999  cfg->write(sect, "grabber_type", "swissranger");
1000 
1001  cfg->write(sect, "sr_use_usb", rbSR_usb->GetSelection() == 0);
1002  cfg->write(sect, "sr_IP", string(edSR_IP->GetValue().mb_str()));
1003 
1004  cfg->write(sect, "sr_grab_grayscale", cbSR_chIntensity->GetValue());
1005  cfg->write(sect, "sr_grab_3d", cbSR_ch3D->GetValue());
1006  cfg->write(sect, "sr_grab_range", cbSR_chRange->GetValue());
1007  cfg->write(sect, "sr_grab_confidence", cbSR_chConf->GetValue());
1008  }
1009  break;
1010 
1011  // Kinect
1012  // -----------------------------------
1013  case 7:
1014  {
1015  cfg->write(sect, "grabber_type", "kinect");
1016 
1017  cfg->write(sect, "kinect_grab_intensity", cbKinect_Int->GetValue());
1018  cfg->write(sect, "kinect_grab_3d", cbKinect_3D->GetValue());
1019  cfg->write(sect, "kinect_grab_range", cbKinect_Depth->GetValue());
1020 
1021  cfg->write(
1022  sect, "kinect_video_rgb",
1023  rbKinect_int->GetSelection() == 0 ? 1 : 0);
1024  }
1025  break;
1026 
1027  default:
1028  {
1029  cerr << "[MRPT CPanelCameraSelection] ERROR: Unknown camera "
1030  "selection tab!\n";
1031  THROW_EXCEPTION("Unknown camera selection tab!")
1032  }
1033  }
1034 
1035  // Add grayscale option:
1036  cfg->write(sect, "capture_grayscale", this->cbGrayscale->GetValue());
1037 
1038  MRPT_END
1039 }
1040 
1041 /* ------------------------------------------------------------------------
1042  readConfigIntoVideoSourcePanel
1043  ------------------------------------------------------------------------ */
1045  const std::string& sect, const mrpt::utils::CConfigFileBase* cfg) const
1046 {
1047  MRPT_START
1048 
1049  const std::string grab_type =
1050  cfg->read_string(sect, "grabber_type", "opencv");
1051 
1052  if (grab_type == "opencv")
1053  {
1054  this->pagesCameras->SetSelection(0);
1055 
1056  this->opencvCamIndex->SetValue(
1057  cfg->read_int(sect, "cv_camera_index", 0));
1058  this->cbOpencvCamType->SetStringSelection(
1059  _U(cfg->read_string(sect, "cv_camera_type", "").c_str()));
1060 
1061  const int w = cfg->read_int(sect, "cv_frame_width", 0);
1062 
1063  if (w == 320)
1064  this->cbOpencvResolution->SetSelection(1);
1065  else if (w == 640)
1066  this->cbOpencvResolution->SetSelection(2);
1067  else
1068  this->cbOpencvResolution->SetSelection(0);
1069  }
1070  else if (grab_type == "ffmpeg")
1071  {
1072  // Page: 1 (IP), 3 (file)
1073  const string url =
1074  cfg->read_string(sect, "ffmpeg_url", "rtsp://192.168.0.1/live.sdp");
1075 
1076  if (url.substr(0, 5) == "rtsp:")
1077  {
1078  this->pagesCameras->SetSelection(1);
1079  this->edIPcamURL->SetValue(_U(url.c_str()));
1080  }
1081  else
1082  {
1083  this->pagesCameras->SetSelection(3);
1084  this->edVideoFile->SetValue(_U(url.c_str()));
1085  }
1086  }
1087  else if (grab_type == "rawlog")
1088  {
1089  this->pagesCameras->SetSelection(4);
1090 
1091  this->edRawlogFile->SetValue(
1092  _U(cfg->read_string(sect, "rawlog_file", "").c_str()));
1093 
1094  const string lb =
1095  cfg->read_string(sect, "rawlog_camera_sensor_label", "");
1096  this->edRawlogLabel->SetValue(_U(lb.c_str()));
1097  }
1098  else if (grab_type == "bumblebee")
1099  {
1100  this->pagesCameras->SetSelection(5);
1101 
1102  this->rbBumblebeeSel->SetSelection(
1103  cfg->read_int(sect, "bumblebee_mono", 0));
1104  this->cbBumblebeeRectif->SetValue(
1105  cfg->read_bool(sect, "bumblebee_get_rectified", false));
1106  }
1107  else if (grab_type == "swissranger")
1108  {
1109  this->pagesCameras->SetSelection(6);
1110 
1111  this->rbSR_usb->SetSelection(
1112  cfg->read_bool(sect, "sr_use_usb", true) ? 0 : 1);
1113  this->edSR_IP->SetValue(
1114  _U(cfg->read_string(sect, "sr_IP", "192.168.0.1").c_str()));
1115 
1116  this->cbSR_chIntensity->SetValue(
1117  cfg->read_bool(sect, "sr_grab_grayscale", true));
1118  this->cbSR_ch3D->SetValue(cfg->read_bool(sect, "sr_grab_3d", false));
1119  this->cbSR_chRange->SetValue(
1120  cfg->read_bool(sect, "sr_grab_range", false));
1121  this->cbSR_chConf->SetValue(
1122  cfg->read_bool(sect, "sr_grab_confidence", false));
1123  }
1124  else
1126  "Error: Unknown choice in 'grabber_type': '%s'", grab_type.c_str());
1127 
1128  // Grayscale option:
1129  this->cbGrayscale->SetValue(
1130  cfg->read_bool(sect, "capture_grayscale", false));
1131 
1132  MRPT_END
1133 }
1134 
1136 {
1137  int mod = MRPTKMOD_NONE;
1138  if (ev.AltDown()) mod |= MRPTKMOD_ALT;
1139  if (ev.CmdDown()) mod |= MRPTKMOD_CMD;
1140  if (ev.ControlDown()) mod |= MRPTKMOD_CONTROL;
1141  if (ev.MetaDown()) mod |= MRPTKMOD_META;
1142  if (ev.ShiftDown()) mod |= MRPTKMOD_SHIFT;
1143  return mrptKeyModifier(mod);
1144 }
1145 
1146 #endif // MRPT_HAS_WXWIDGETS
static const long ID_BUTTON9
Definition: WxUtils.h:256
static const long ID_CHOICE1
Definition: WxUtils.h:238
void writeConfigFromVideoSourcePanel(const std::string &sect, mrpt::utils::CConfigFileBase *cfg) const
Definition: WxUtils.cpp:878
bool read_bool(const std::string &section, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
static const long ID_PANEL3
Definition: WxUtils.h:244
void GetBitmap(wxBitmap &bmp)
Definition: WxUtils.cpp:381
#define _U(x)
Definition: WxSubsystem.h:506
void OnbtnBrowseRawlogDirClick(wxCommandEvent &event)
Definition: WxUtils.cpp:859
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
static const long ID_SPINCTRL1
Definition: WxUtils.h:236
void getAllSections(vector_string &sections) const override
Returns a list with all the section names.
static const long ID_STATICTEXT9
Definition: WxUtils.h:251
static const long ID_STATICTEXT1
Definition: WxUtils.h:235
static const long ID_CHECKBOX4
Definition: WxUtils.h:269
#define THROW_EXCEPTION(msg)
static const long ID_RADIOBOX3
Definition: WxUtils.h:276
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
static const long ID_RADIOBOX2
Definition: WxUtils.h:265
void OnMouseMove(wxMouseEvent &ev)
Definition: WxUtils.cpp:329
static const long ID_PANEL1
Definition: WxUtils.h:272
static const long ID_CHECKBOX1
Definition: WxUtils.h:262
static const long ID_TEXTCTRL6
Definition: WxUtils.h:245
mrptKeyModifier
Definition: keycodes.h:159
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glext.h:3551
std::string read_string(const std::string &section, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
static const long ID_NOTEBOOK1
Definition: WxUtils.h:278
STL namespace.
wxMRPTImageControl(wxWindow *parent, wxWindowID winID, int x, int y, int width, int height)
Definition: WxUtils.cpp:304
void readConfigIntoVideoSourcePanel(const std::string &sect, const mrpt::utils::CConfigFileBase *cfg) const
Definition: WxUtils.cpp:1044
static const long ID_CHECKBOX6
Definition: WxUtils.h:271
static const long ID_CHECKBOX5
Definition: WxUtils.h:270
GLuint src
Definition: glext.h:7278
wxImage * IplImage2wxImage(void *img)
Create a wxImage from a IPL image.
Definition: WxUtils.cpp:237
GLenum GLsizei width
Definition: glext.h:3531
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
static const long ID_CHECKBOX3
Definition: WxUtils.h:268
static const long ID_TEXTCTRL8
Definition: WxUtils.h:258
This class allows loading and storing values and vectors of different types from a configuration text...
static const long ID_TEXTCTRL3
Definition: WxUtils.h:252
This class implements a config file-like interface over a memory-stored string list.
int read_int(const std::string &section, const std::string &name, int defaultValue, bool failIfNotFound=false) const
std::vector< std::string > vector_string
A type for passing a vector of strings.
Definition: types_simple.h:33
wxBitmap * MRPTImage2wxBitmap(const mrpt::utils::CImage &img)
Create a wxBitmap from a MRPT image.
Definition: WxUtils.cpp:168
static const long ID_TEXTCTRL1
Definition: WxUtils.h:243
void OnMouseClick(wxMouseEvent &ev)
Definition: WxUtils.cpp:335
void loadFromMemoryBuffer(unsigned int width, unsigned int height, bool color, unsigned char *rawpixels, bool swapRedBlue=false)
Reads the image from raw pixels buffer in memory.
Definition: CImage.cpp:390
#define MRPT_END
static const long ID_CHECKBOX8
Definition: WxUtils.h:274
mrpt::utils::CImage * wxImage2MRPTImage(const wxImage &img)
Create a MRPT image from a wxImage.
Definition: WxUtils.cpp:280
static const long ID_CHECKBOX7
Definition: WxUtils.h:273
const GLubyte * c
Definition: glext.h:6313
GLint GLvoid * img
Definition: glext.h:3763
void OnbtnBrowseVideoClick(wxCommandEvent &event)
Definition: WxUtils.cpp:825
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
static const long ID_CHOICE2
Definition: WxUtils.h:240
std::shared_ptr< CImage > Ptr
Definition: CImage.h:120
static const long ID_STATICTEXT6
Definition: WxUtils.h:239
wxImage * MRPTImage2wxImage(const mrpt::utils::CImage &img)
Create a wxImage from a MRPT image.
Definition: WxUtils.cpp:29
static const long ID_TEXTCTRL2
Definition: WxUtils.h:248
static const long ID_CHECKBOX2
Definition: WxUtils.h:279
static const long ID_PANEL2
Definition: WxUtils.h:241
static const long ID_STATICTEXT3
Definition: WxUtils.h:237
static const long ID_PANEL5
Definition: WxUtils.h:250
GLsizei const GLchar ** string
Definition: glext.h:4101
mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent &ev)
Extracts the key modifiers from a wxKeyEvent.
Definition: WxUtils.cpp:1135
static const long ID_STATICTEXT2
Definition: WxUtils.h:263
static const long ID_STATICTEXT11
Definition: WxUtils.h:259
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void write(const std::string &section, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
static const long ID_STATICTEXT10
Definition: WxUtils.h:257
mrpt::utils::CImage::Ptr wxImage2MRPTImagePtr(const wxImage &img)
Create a MRPT image from a wxImage.
Definition: WxUtils.cpp:296
static const long ID_TEXTCTRL7
Definition: WxUtils.h:255
static const long ID_TEXTCTRL4
Definition: WxUtils.h:267
static const long ID_STATICTEXT5
Definition: WxUtils.h:254
#define ASSERT_(f)
A panel to select the camera input from all the formats supported by MRPT.
Definition: WxUtils.h:173
void OnPaint(wxPaintEvent &ev)
Definition: WxUtils.cpp:367
static const long ID_CHECKBOX9
Definition: WxUtils.h:275
GLenum GLint GLint y
Definition: glext.h:3538
static const long ID_PANEL8
Definition: WxUtils.h:277
static const long ID_RADIOBOX1
Definition: WxUtils.h:261
static const long ID_PANEL4
Definition: WxUtils.h:246
GLenum GLsizei GLenum format
Definition: glext.h:3531
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
static const long ID_PANEL7
Definition: WxUtils.h:264
void OnbtnBrowseRawlogClick(wxCommandEvent &event)
Definition: WxUtils.cpp:836
bool directoryExists(const std::string &fileName)
Test if a given directory exists (it fails if the given path refers to an existing file)...
Definition: filesystem.cpp:136
GLenum GLint x
Definition: glext.h:3538
void getAllKeys(const std::string &section, vector_string &keys) const override
Returs a list with all the keys into a section.
GLenum GLsizei GLsizei height
Definition: glext.h:3554
static const long ID_BUTTON7
Definition: WxUtils.h:249
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
GLfloat GLfloat p
Definition: glext.h:6305
static const long ID_STATICTEXT4
Definition: WxUtils.h:266
static const long ID_STATICTEXT7
Definition: WxUtils.h:242
std::string extractFileDirectory(const std::string &filePath)
Extract the whole path (the directory) of a filename from a complete path plus name plus extension...
Definition: filesystem.cpp:77
void AssignImage(wxBitmap *img)
Assigns this image.
Definition: WxUtils.cpp:341
static const long ID_PANEL6
Definition: WxUtils.h:260
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Definition: os.cpp:355
static const long ID_BUTTON8
Definition: WxUtils.h:253
static const long ID_STATICTEXT8
Definition: WxUtils.h:247



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019