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 }
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
CCameraSensor::Ptr prepareVideoSourceFromUserSelection()
Show to the user a list of possible camera drivers and creates and open the selected camera...
void TestOpenGLVideo()
STL namespace.
This base provides a set of functions for maths stuff.
This namespace contains representation of robot actions and observations.
mrpt::gui::CDisplayWindow3D::Ptr win
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
#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:102
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
GLenum GLsizei GLenum format
Definition: glext.h:3531
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020