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:
39  "Demo of video textures with MRPT's OpenGL objects", 640, 480);
40 
41  // XY Grid
42  opengl::CGridPlaneXY::Ptr gl_ground =
43  mrpt::make_aligned_shared<opengl::CGridPlaneXY>(-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  mrpt::make_aligned_shared<opengl::CTexturedPlane>(
49  0, 1, 0, 0.75); // 4/3 aspect ratio
50  opengl::CTexturedPlane::Ptr gl_plane2 =
51  mrpt::make_aligned_shared<opengl::CTexturedPlane>(0, 1, 0, 0.75);
52  opengl::CTexturedPlane::Ptr gl_plane3 =
53  mrpt::make_aligned_shared<opengl::CTexturedPlane>(0, 1, 0, 0.75);
54 
55  gl_plane1->setPose(
56  mrpt::poses::CPose3D(0, 0, 1, DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90)));
57  gl_plane2->setPose(
58  mrpt::poses::CPose3D(1, 0, 1, DEG2RAD(120), DEG2RAD(0), DEG2RAD(-90)));
59  gl_plane3->setPose(
60  mrpt::poses::CPose3D(0, 0, 1, DEG2RAD(60), DEG2RAD(0), DEG2RAD(-90)));
61 
62  win.setCameraZoom(5);
63 
64  // Insert objects in scene:
65  {
66  COpenGLScene::Ptr& theScene = win.get3DSceneAndLock();
67  theScene->insert(gl_ground);
68  theScene->insert(gl_plane1);
69  theScene->insert(gl_plane2);
70  theScene->insert(gl_plane3);
71  // IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
72  win.unlockAccess3DScene();
73  }
74  win.repaint();
75 
76  cout << "Close the window to end.\n";
77  while (win.isOpen())
78  {
79  win.addTextMessage(5, 5, format("%.02fFPS", win.getRenderingFPS()));
80  std::this_thread::sleep_for(1ms);
81 
82  // Grab new video frame:
83  CObservation::Ptr obs = cam->getNextFrame();
84  if (obs)
85  {
86  if (IS_CLASS(obs, CObservationImage))
87  {
89  std::dynamic_pointer_cast<CObservationImage>(obs);
90  win.get3DSceneAndLock();
91  gl_plane1->assignImage(o->image);
92  gl_plane2->assignImage(o->image);
93  gl_plane3->assignImage(o->image);
94  win.unlockAccess3DScene();
95  win.repaint();
96  }
97  }
98  }
99 }
100 
101 // ------------------------------------------------------
102 // MAIN
103 // ------------------------------------------------------
104 int main()
105 {
106  try
107  {
108  TestOpenGLVideo();
109 
110  return 0;
111  }
112  catch (std::exception& e)
113  {
114  std::cout << "MRPT exception caught: " << e.what() << std::endl;
115  return -1;
116  }
117  catch (...)
118  {
119  printf("Untyped exception!!");
120  return -1;
121  }
122 }
DEG2RAD
#define DEG2RAD
Definition: core/include/mrpt/core/bits_math.h:59
mrpt::obs::CObservation::Ptr
std::shared_ptr< CObservation > Ptr
Definition: CObservation.h:45
mrpt::opengl::CGridPlaneXY::Ptr
std::shared_ptr< CGridPlaneXY > Ptr
Definition: CGridPlaneXY.h:34
format
GLenum GLsizei GLenum format
Definition: glext.h:3531
mrpt::opengl::CTexturedPlane::Ptr
std::shared_ptr< CTexturedPlane > Ptr
Definition: CTexturedPlane.h:24
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
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::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
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::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