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/img/CImage.h>
13 #include <mrpt/opengl/CText.h>
14 #include <iostream>
15 
16 #include <mrpt/examples_config.h>
18  MRPT_EXAMPLES_BASE_DIRECTORY +
19  std::string("img_basic_example/frame_color.jpg"));
20 
21 using namespace std;
22 using namespace mrpt;
23 using namespace mrpt::gui;
24 using namespace mrpt::opengl;
25 using namespace mrpt::math;
26 using namespace mrpt::img;
27 
28 // ------------------------------------------------------
29 // TextureSizes_test
30 // ------------------------------------------------------
31 void TextureSizes_test()
32 {
33  // Prepare a few test images: color & BW, random size and 2^N size.
34  // -------------------------------------------------------------------
35  CImage imgCol_N, imgBW_N;
36  CImage imgCol_2N, imgBW_2N;
37 
38  if (!imgCol_N.loadFromFile(myTestFile))
39  {
40  cerr << "Cannot load " << myTestFile << endl;
41  return;
42  }
43 
44  imgCol_N.scaleImage(imgCol_2N, 512, 512);
45 
46  imgCol_N.grayscale(imgBW_N);
47  imgCol_2N.grayscale(imgBW_2N);
48 
49  // Masks:
50  const int W = imgCol_N.getWidth();
51  const int H = imgCol_N.getHeight();
52 
53  CImage transpMask_N(W, H, CH_GRAY);
54  for (int y = 0; y < H; y++)
55  for (int x = 0; x < W; x++)
56  *transpMask_N(x, y) = (((x + y) >> 5) & 1) ? 240 : 10;
57 
58  CImage transpMask_2N;
59  transpMask_N.scaleImage(transpMask_2N, 512, 512);
60 
61  cout << "Loaded image size: " << imgCol_N.getWidth() << "x"
62  << imgCol_N.getHeight() << endl;
63  cout << "2^N image size : " << imgCol_2N.getWidth() << "x"
64  << imgCol_2N.getHeight() << endl;
65 
66  CDisplayWindow3D win("Test of MRPT's OpenGL textures", 640, 480);
67 
68  COpenGLScene::Ptr& theScene = win.get3DSceneAndLock();
69 
70  double off_x = 0;
71  const double off_y_label = 4;
72  const double STEP_X = 15;
73 
74  if (1)
75  {
77  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
78  obj->assignImage(imgCol_N);
79  obj->setLocation(off_x, 0, 0);
80  theScene->insert(obj);
81 
82  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
83  "Color texture, random size, w/o transp");
84  gl_txt->setLocation(off_x, off_y_label, 0);
85  theScene->insert(gl_txt);
86  }
87  off_x += STEP_X;
88 
89  if (1)
90  {
92  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
93  obj->assignImage(imgCol_N, transpMask_N);
94  obj->setLocation(off_x, 0, 0);
95  theScene->insert(obj);
96 
97  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
98  "Color texture, random size, with transp");
99  gl_txt->setLocation(off_x, off_y_label, 0);
100  theScene->insert(gl_txt);
101  }
102  off_x += STEP_X;
103 
104  if (1)
105  {
107  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
108  obj->assignImage(imgBW_N);
109  obj->setLocation(off_x, 0, 0);
110  theScene->insert(obj);
111 
112  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
113  "B/W texture, random size, w/o transp");
114  gl_txt->setLocation(off_x, off_y_label, 0);
115  theScene->insert(gl_txt);
116  }
117  off_x += STEP_X;
118 
119  if (1)
120  {
122  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
123  obj->assignImage(imgBW_N, transpMask_N);
124  obj->setLocation(off_x, 0, 0);
125  theScene->insert(obj);
126 
127  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
128  "B/W texture, random size, with transp");
129  gl_txt->setLocation(off_x, off_y_label, 0);
130  theScene->insert(gl_txt);
131  }
132  off_x += STEP_X;
133 
134  if (1)
135  {
137  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
138  obj->assignImage(imgCol_2N);
139  obj->setLocation(off_x, 0, 0);
140  theScene->insert(obj);
141 
142  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
143  "Color texture, 2^N size, w/o transp");
144  gl_txt->setLocation(off_x, off_y_label, 0);
145  theScene->insert(gl_txt);
146  }
147  off_x += STEP_X;
148 
149  if (1)
150  {
152  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
153  obj->assignImage(imgCol_2N, transpMask_2N);
154  obj->setLocation(off_x, 0, 0);
155  theScene->insert(obj);
156 
157  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
158  "Color texture, 2^N size, with transp");
159  gl_txt->setLocation(off_x, off_y_label, 0);
160  theScene->insert(gl_txt);
161  }
162  off_x += STEP_X;
163 
164  if (1)
165  {
167  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
168  obj->assignImage(imgBW_2N);
169  obj->setLocation(off_x, 0, 0);
170  theScene->insert(obj);
171 
172  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
173  "B/W texture, 2^N size, w/o transp");
174  gl_txt->setLocation(off_x, off_y_label, 0);
175  theScene->insert(gl_txt);
176  }
177  off_x += STEP_X;
178 
179  if (1)
180  {
182  mrpt::make_aligned_shared<opengl::CTexturedPlane>(-3, 3, -3, 3);
183  obj->assignImage(imgBW_2N, transpMask_2N);
184  obj->setLocation(off_x, 0, 0);
185  theScene->insert(obj);
186 
187  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
188  "B/W texture, 2^N size, with transp");
189  gl_txt->setLocation(off_x, off_y_label, 0);
190  theScene->insert(gl_txt);
191  }
192  off_x += STEP_X;
193 
194  win.setCameraZoom(150);
195  win.setCameraAzimuthDeg(90);
196 
197  // IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
198  win.unlockAccess3DScene();
199  win.repaint();
200 
201  cout << "Close the window to end.\n";
202  while (win.isOpen())
203  {
204  win.addTextMessage(5, 5, format("%.02fFPS", win.getRenderingFPS()));
205  std::this_thread::sleep_for(2ms);
206  win.repaint();
207  }
208 }
209 
210 // ------------------------------------------------------
211 // MAIN
212 // ------------------------------------------------------
213 int main()
214 {
215  try
216  {
218 
219  return 0;
220  }
221  catch (std::exception& e)
222  {
223  std::cout << "MRPT exception caught: " << e.what() << std::endl;
224  return -1;
225  }
226  catch (...)
227  {
228  printf("Untyped exception!!");
229  return -1;
230  }
231 }
TextureSizes_test
void TextureSizes_test()
Definition: vision_stereo_rectify/test.cpp:31
format
GLenum GLsizei GLenum format
Definition: glext.h:3531
mrpt::img::CImage::getWidth
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:864
mrpt::img::CImage::scaleImage
void scaleImage(unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
Scales this image to a new size, interpolating as needed.
Definition: CImage.cpp:2217
mrpt::opengl::CTexturedPlane::Ptr
std::shared_ptr< CTexturedPlane > Ptr
Definition: CTexturedPlane.h:24
obj
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
mrpt::img::CImage::grayscale
CImage grayscale() const
Returns a grayscale version of the image, or itself if it is already a grayscale image.
Definition: CImage.cpp:994
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
CDisplayWindow3D.h
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::img
Definition: CCanvas.h:17
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
myTestFile
const std::string myTestFile(MRPT_EXAMPLES_BASE_DIRECTORY+std::string("img_basic_example/frame_color.jpg"))
mrpt::img::CImage::getHeight
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:892
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:61
CImage.h
mrpt::img::CImage::loadFromFile
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
Definition: CImage.cpp:271
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
CH_GRAY
#define CH_GRAY
Definition: img/CImage.h:44
y
GLenum GLint GLint y
Definition: glext.h:3538
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117
x
GLenum GLint x
Definition: glext.h:3538
CTexturedPlane.h
CText.h
mrpt::opengl::CText::Ptr
std::shared_ptr< CText > Ptr
Definition: CText.h:40



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