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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019