MRPT  2.0.4
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/gui.h>
12 #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:
39  "Demo of video textures with MRPT's OpenGL objects", 640, 480);
40 
41  // XY Grid
42  opengl::CGridPlaneXY::Ptr gl_ground =
43  opengl::CGridPlaneXY::Create(-7, 7, -7, 7, 0, 1);
44  gl_ground->setColor(0.7, 0.7, 0.7);
45 
46  // An opengl plane with the video texture
47  opengl::CTexturedPlane::Ptr gl_plane1 =
48  opengl::CTexturedPlane::Create(0, 1, 0, 0.75); // 4/3 aspect ratio
49  opengl::CTexturedPlane::Ptr gl_plane2 =
50  opengl::CTexturedPlane::Create(0, 1, 0, 0.75);
51  opengl::CTexturedPlane::Ptr gl_plane3 =
52  opengl::CTexturedPlane::Create(0, 1, 0, 0.75);
53 
54  gl_plane1->setPose(
55  mrpt::poses::CPose3D(0, 0, 1, 0.0_deg, 0.0_deg, -90.0_deg));
56  gl_plane2->setPose(
57  mrpt::poses::CPose3D(1, 0, 1, 120.0_deg, 0.0_deg, -90.0_deg));
58  gl_plane3->setPose(
59  mrpt::poses::CPose3D(0, 0, 1, 60.0_deg, 0.0_deg, -90.0_deg));
60 
61  win.setCameraZoom(5);
62 
63  // Insert objects in scene:
64  {
65  COpenGLScene::Ptr& theScene = win.get3DSceneAndLock();
66  theScene->insert(gl_ground);
67  theScene->insert(gl_plane1);
68  theScene->insert(gl_plane2);
69  theScene->insert(gl_plane3);
70  // IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
71  win.unlockAccess3DScene();
72  }
73  win.repaint();
74 
75  cout << "Close the window to end.\n";
76  while (win.isOpen())
77  {
78  win.addTextMessage(5, 5, format("%.02fFPS", win.getRenderingFPS()));
79  std::this_thread::sleep_for(1ms);
80 
81  // Grab new video frame:
82  CObservation::Ptr obs = cam->getNextFrame();
83  if (obs)
84  {
85  if (IS_CLASS(*obs, CObservationImage))
86  {
88  std::dynamic_pointer_cast<CObservationImage>(obs);
89  win.get3DSceneAndLock();
90  gl_plane1->assignImage(o->image);
91  gl_plane2->assignImage(o->image);
92  gl_plane3->assignImage(o->image);
93  win.unlockAccess3DScene();
94  win.repaint();
95  }
96  }
97  }
98 }
99 
100 // ------------------------------------------------------
101 // MAIN
102 // ------------------------------------------------------
103 int main()
104 {
105  try
106  {
107  TestOpenGLVideo();
108 
109  return 0;
110  }
111  catch (const std::exception& e)
112  {
113  std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
114  return -1;
115  }
116  catch (...)
117  {
118  printf("Untyped exception!!");
119  return -1;
120  }
121 }
mrpt::obs::CObservation::Ptr
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:45
mrpt::opengl::CGridPlaneXY::Ptr
std::shared_ptr< mrpt::opengl ::CGridPlaneXY > Ptr
Definition: CGridPlaneXY.h:31
TestOpenGLVideo
void TestOpenGLVideo()
Definition: vision_stereo_rectify/test.cpp:25
mrpt::obs::CObservationImage::Ptr
std::shared_ptr< mrpt::obs ::CObservationImage > Ptr
Definition: CObservationImage.h:34
IS_CLASS
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class.
Definition: CObject.h:146
mrpt::opengl::CTexturedPlane::Ptr
std::shared_ptr< mrpt::opengl ::CTexturedPlane > Ptr
Definition: CTexturedPlane.h:22
CCameraSensor.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
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:1473
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< mrpt::opengl ::COpenGLScene > Ptr
Definition: COpenGLScene.h:58
opengl.h
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
gui.h
mrpt::hwdrivers::CCameraSensor::Ptr
std::shared_ptr< CCameraSensor > Ptr
Definition: CCameraSensor.h:353
mrpt::exception_to_str
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::obs::CObservationImage
Declares a class derived from "CObservation" that encapsules an image from a camera,...
Definition: CObservationImage.h:32
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117
mrpt::format
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 15:15:43 UTC 2020