Main MRPT website > C++ reference for MRPT 1.9.9
test.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 <mrpt/gui.h>
11 #include <mrpt/opengl.h>
13 #include <iostream>
14 
15 using namespace std;
16 using namespace mrpt;
17 using namespace mrpt::gui;
18 using namespace mrpt::opengl;
19 using namespace mrpt::math;
20 using namespace mrpt::obs;
21 
22 // ------------------------------------------------------
23 // TestOpenGLVideo
24 // ------------------------------------------------------
25 void TestOpenGLVideo()
26 {
27  // Show to the user a list of possible camera drivers and creates and open
28  // the selected camera.
29  cout << "Please, select the input video file or camera...\n";
30 
33  if (!cam) return;
34 
35  cout << "Video stream open OK\n";
36 
37  // Create 3D window:
38  CDisplayWindow3D win("#1: Demo of image mode viewport", 320, 240);
39  CDisplayWindow3D win2("#2: Demo of image mode viewport", 500, 400);
40 
41  // Win #1:
42  // Get the smart pointer to the main viewport object in this window:
43  COpenGLViewport::Ptr gl_view_main;
44  {
45  COpenGLScene::Ptr& theScene = win.get3DSceneAndLock();
46  gl_view_main = theScene->getViewport("main");
47  ASSERT_(gl_view_main);
48  // IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
49  win.unlockAccess3DScene();
50  }
51 
52  // Win #2:
53  // Get the smart pointer to the main viewport object in this window:
54  COpenGLViewport::Ptr gl_view_aux;
55  {
56  COpenGLScene::Ptr& theScene = win2.get3DSceneAndLock();
57  theScene->insert(
58  mrpt::make_aligned_shared<mrpt::opengl::CGridPlaneXY>());
59 
60  // Create small auxiliary viewport
61  gl_view_aux = theScene->createViewport("aux");
62 
63  gl_view_aux->setViewportPosition(10, 10, 300, 200);
64  gl_view_aux->setTransparent(true);
65 
66  // IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
67  win2.unlockAccess3DScene();
68  }
69 
70  win.setPos(10, 10);
71  win2.setPos(400, 100);
72 
73  cout << "Close any window to end.\n";
74  while (win.isOpen() && win2.isOpen())
75  {
76  win.addTextMessage(5, 5, format("%.02fFPS", win.getRenderingFPS()));
77  win2.addTextMessage(5, 5, format("%.02fFPS", win2.getRenderingFPS()));
78  std::this_thread::sleep_for(1ms);
79 
80  // Grab new video frame:
81  CObservation::Ptr obs = cam->getNextFrame();
82  if (obs)
83  {
84  if (IS_CLASS(obs, CObservationImage))
85  {
87  std::dynamic_pointer_cast<CObservationImage>(obs);
88  win.get3DSceneAndLock();
89  gl_view_main->setImageView(o->image);
90  win.unlockAccess3DScene();
91  win.repaint();
92 
93  win2.get3DSceneAndLock();
94  gl_view_aux->setImageView_fast(o->image);
95  win2.unlockAccess3DScene();
96  win2.repaint();
97  }
98  }
99  }
100 }
101 
102 // ------------------------------------------------------
103 // MAIN
104 // ------------------------------------------------------
105 int main()
106 {
107  try
108  {
109  TestOpenGLVideo();
110 
111  return 0;
112  }
113  catch (std::exception& e)
114  {
115  std::cout << "MRPT exception caught: " << e.what() << std::endl;
116  return -1;
117  }
118  catch (...)
119  {
120  printf("Untyped exception!!");
121  return -1;
122  }
123 }
mrpt::obs::CObservation::Ptr
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:45
format
GLenum GLsizei GLenum format
Definition: glext.h:3531
TestOpenGLVideo
void TestOpenGLVideo()
Definition: vision_stereo_rectify/test.cpp:25
CCameraSensor.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::obs
This namespace contains representation of robot actions and observations.
Definition: CParticleFilter.h:17
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::hwdrivers::prepareVideoSourceFromUserSelection
CCameraSensor::Ptr prepareVideoSourceFromUserSelection()
Show to the user a list of possible camera drivers and creates and open the selected camera.
Definition: CCameraSensor.cpp:1436
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::obs::CObservationImage::Ptr
std::shared_ptr< CObservationImage > Ptr
Definition: CObservationImage.h:37
IS_CLASS
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
Definition: CObject.h:103
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
opengl.h
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
gui.h
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:61
mrpt::hwdrivers::CCameraSensor::Ptr
std::shared_ptr< CCameraSensor > Ptr
Definition: CCameraSensor.h:351
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::obs::CObservationImage
Declares a class derived from "CObservation" that encapsules an image from a camera,...
Definition: CObservationImage.h:35
mrpt::opengl::COpenGLViewport::Ptr
std::shared_ptr< COpenGLViewport > Ptr
Definition: COpenGLViewport.h:63
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST