Main MRPT website > C++ reference for MRPT 1.5.9
CAxis.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-2017, 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 "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CAxis.h>
13 #include <mrpt/utils/CStream.h>
14 #include <mrpt/system/os.h>
15 #include <mrpt/opengl/gl_utils.h>
16 
17 #include "opengl_internals.h"
18 
19 using namespace mrpt;
20 using namespace mrpt::opengl;
21 using namespace mrpt::system;
22 using namespace mrpt::utils;
23 using namespace std;
24 
26 
28  float xmin,float ymin, float zmin,
29  float xmax, float ymax, float zmax,
30  float frecuency , float lineWidth , bool marks) :
31  m_xmin(xmin),m_ymin(ymin),m_zmin(zmin),
32  m_xmax(xmax),m_ymax(ymax),m_zmax(zmax),
33  m_frequency(frecuency),
34  m_lineWidth(lineWidth),
35  m_textScale(0.25f)
36 {
37  for (int i=0;i<3;i++) m_marks[i] = marks;
38 
39  //x:180, 0, 90
40  m_textRot[0][0] = 180.f; m_textRot[0][1] = 0.f; m_textRot[0][2] = 90.f;
41  //y:90, 0, 90
42  m_textRot[1][0] = 90.f; m_textRot[1][1] = 0.f; m_textRot[1][2] = 90.f;
43  //z:180, 0, 90
44  m_textRot[2][0] = 180.f; m_textRot[2][1] = 0.f; m_textRot[2][2] = 90.f;
45 }
46 
47 
48 CAxisPtr CAxis::Create(
49  float xmin,float ymin, float zmin,
50  float xmax, float ymax, float zmax,
51  float frecuency, float lineWidth, bool marks)
52 {
53  return CAxisPtr( new CAxis( xmin,ymin, zmin, xmax,ymax,zmax,frecuency,lineWidth,marks ) );
54 }
55 
56 void CAxis::render_dl() const
57 {
58 #if MRPT_HAS_OPENGL_GLUT
61 
66 
67  ASSERT_(m_frequency>=0);
68 
69  glLineWidth(m_lineWidth);
71  glBegin( GL_LINES );
72  glColor4ub(m_color.R,m_color.G,m_color.B,m_color.A);
73  //X axis
74  glVertex3f( m_xmin, 0.0f, 0.0f );
75  glVertex3f( m_xmax, 0.0f, 0.0f );
76  //Y axis
77  glVertex3f( 0.0f, m_ymin, 0.0f );
78  glVertex3f( 0.0f, m_ymax, 0.0f);
79  //Z axis
80  glVertex3f( 0.0f, 0.0f, m_zmin );
81  glVertex3f( 0.0f, 0.0f, m_zmax );
82 
83  glEnd();
85 
86  glLineWidth(1.0f);
88 
91 
92  // Draw the "tick marks":
93  char n[50];
94  if (m_marks[0])
95  {
96  // X axis
97  glPushMatrix();
98  glTranslatef(m_xmin,.0f,.05f);
99  for (float i = m_xmin ; i<= m_xmax ; i = i + m_frequency)
100  {
101  os::sprintf(n,50,"%.02f",i);
102  glPushMatrix();
103  glRotatef(m_textRot[0][0],0,0,1);
104  glRotatef(m_textRot[0][1],0,1,0);
105  glRotatef(m_textRot[0][2],1,0,0);
106  gl_utils::glDrawText(n, m_textScale, mrpt::opengl::FILL );
107  glPopMatrix();
108  glTranslatef(m_frequency,0,0);
109  }
110 
111  glPopMatrix();
112  glPushMatrix();
113  glTranslatef(m_xmax+1.0f*m_frequency,0,0);
114  glRotatef(m_textRot[0][0],0,0,1);
115  glRotatef(m_textRot[0][1],0,1,0);
116  glRotatef(m_textRot[0][2],1,0,0);
117  gl_utils::glDrawText("+X", m_textScale*1.2, mrpt::opengl::NICE );
118  glPopMatrix();
119  }
120  if (m_marks[1])
121  {
122  // Y axis
123  glPushMatrix();
124  glTranslatef(.0f,m_ymin,.05f);
125  for (float i = m_ymin ; i<= m_ymax ; i = i + m_frequency)
126  {
127  if (std::abs(i)>1e-4)
128  { // Dont draw the "0" more than once
129  os::sprintf(n,50,"%.02f",i);
130  glPushMatrix();
131  glRotatef(m_textRot[1][0],0,0,1);
132  glRotatef(m_textRot[1][1],0,1,0);
133  glRotatef(m_textRot[1][2],1,0,0);
134  gl_utils::glDrawText(n, m_textScale, mrpt::opengl::FILL );
135  glPopMatrix();
136  }
137  glTranslatef(0,m_frequency,0);
138  }
139 
140  glPopMatrix();
141  glPushMatrix();
142  glTranslatef(0,m_ymax+.5f*m_frequency,0);
143  glRotatef(m_textRot[1][0],0,0,1);
144  glRotatef(m_textRot[1][1],0,1,0);
145  glRotatef(m_textRot[1][2],1,0,0);
146  gl_utils::glDrawText("+Y", m_textScale*1.2, mrpt::opengl::NICE );
147  glPopMatrix();
148  }
149  if (m_marks[2])
150  {
151  // Z axis
152  glPushMatrix();
153  glTranslatef(.0f,.0f,m_zmin);
154  for (float i = m_zmin ; i<= m_zmax ; i = i + m_frequency)
155  {
156  if (std::abs(i)>1e-4)
157  { // Dont draw the "0" more than once
158  glPushMatrix();
159  glRotatef(m_textRot[2][0],0,0,1);
160  glRotatef(m_textRot[2][1],0,1,0);
161  glRotatef(m_textRot[2][2],1,0,0);
162  os::sprintf(n,50,"%.02f",i);
163  gl_utils::glDrawText(n, m_textScale, mrpt::opengl::FILL );
164  glPopMatrix();
165  }
166  glTranslatef(0,0,m_frequency);
167  }
168 
169  glPopMatrix();
170  glPushMatrix();
171  glTranslatef(0,0,m_zmax+0.5f*m_frequency);
172  glRotatef(m_textRot[2][0],0,0,1);
173  glRotatef(m_textRot[2][1],0,1,0);
174  glRotatef(m_textRot[2][2],1,0,0);
175  gl_utils::glDrawText("+Z", m_textScale*1.2, mrpt::opengl::NICE );
176  glPopMatrix();
177  }
178 
180  MRPT_END
181 /*******************************************************/
182 #endif
183 }
184 
185 /*---------------------------------------------------------------
186  Implements the writing to a CStream capability of
187  CSerializable objects
188  ---------------------------------------------------------------*/
190 {
191  if (version)
192  *version = 1;
193  else
194  {
195  writeToStreamRender(out);
196  out << m_xmin << m_ymin << m_zmin;
197  out << m_xmax << m_ymax << m_zmax;
198  out << m_frequency << m_lineWidth;
199  // v1:
200  out << m_marks[0] << m_marks[1] << m_marks[2] << m_textScale;
201  for (int i=0;i<3;i++) for (int j=0;j<3;j++) out << m_textRot[i][j];
202  }
203 }
204 
205 /*---------------------------------------------------------------
206  Implements the reading from a CStream capability of
207  CSerializable objects
208  ---------------------------------------------------------------*/
210 {
211  switch(version)
212  {
213  case 0:
214  case 1:
215  {
216  readFromStreamRender(in);
217  in >> m_xmin >> m_ymin >> m_zmin;
218  in >> m_xmax >> m_ymax >> m_zmax;
219  in >> m_frequency >> m_lineWidth;
220  if (version>=1)
221  {
222  in >> m_marks[0] >> m_marks[1] >> m_marks[2] >> m_textScale;
223  for (int i=0;i<3;i++) for (int j=0;j<3;j++) in >> m_textRot[i][j];
224  }
225  else {
226  bool v;
227  in >> v;
228  for (int i=0;i<3;i++) m_marks[i] = v;
229  m_textScale = 0.25f;
230  }
231  } break;
232  default:
234 
235  };
237 }
238 
240 {
241  bb_min.x = m_xmin;
242  bb_min.y = m_ymin;
243  bb_min.z = m_zmin;
244 
245  bb_max.x = m_xmax;
246  bb_max.y = m_ymax;
247  bb_max.z = m_zmax;
248 
249  // Convert to coordinates of my parent:
250  m_pose.composePoint(bb_min, bb_min);
251  m_pose.composePoint(bb_max, bb_max);
252 }
253 
254 
255 void CAxis::setFrequency(float f)
256 {
257  ASSERT_(f>0);
258  m_frequency=f;
260 }
261 float CAxis::getFrequency() const {
262  return m_frequency;
263 }
264 void CAxis::setLineWidth(float w) {
265  m_lineWidth=w;
267 }
268 float CAxis::getLineWidth() const {
269  return m_lineWidth;
270 }
271 
273  for (int i=0;i<3;i++) m_marks[i]=v;
275 }
276 void CAxis::enableTickMarks(bool show_x, bool show_y, bool show_z)
277 {
278  m_marks[0]=show_x;
279  m_marks[1]=show_y;
280  m_marks[2]=show_z;
282 }
283 void CAxis::setTextScale(float f) {
284  ASSERT_(f>0);
285  m_textScale=f;
287 }
288 float CAxis::getTextScale() const {
289  return m_textScale;
290 }
291 
292 void CAxis::setAxisLimits(float xmin,float ymin, float zmin, float xmax,float ymax, float zmax)
293 {
294  m_xmin=xmin; m_ymin=ymin; m_zmin=zmin;
295  m_xmax=xmax; m_ymax=ymax; m_zmax=zmax;
297 }
298 void CAxis::setTextLabelOrientation(int axis, float yaw_deg, float pitch_deg, float roll_deg)
299 {
300  ASSERT_(axis>=0 && axis<3);
301  m_textRot[axis][0]=yaw_deg;
302  m_textRot[axis][1]=pitch_deg;
303  m_textRot[axis][2]=roll_deg;
304 }
305 void CAxis::getTextLabelOrientation(int axis, float &yaw_deg, float &pitch_deg, float &roll_deg) const
306 {
307  ASSERT_(axis>=0 && axis<3);
308  yaw_deg = m_textRot[axis][0];
309  pitch_deg = m_textRot[axis][1];
310  roll_deg = m_textRot[axis][2];
311 }
float getFrequency() const
Definition: CAxis.cpp:261
mrpt::utils::TPixelCoordf OPENGL_IMPEXP glDrawText(const std::string &text, const double textScale, enum TOpenGLFontStyle style=NICE, double spacing=1.5, double kerning=0.1)
renders a string in GL using the current settings.
Definition: gl_utils.cpp:600
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
GLAPI void GLAPIENTRY glEnable(GLenum cap)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:29
GLAPI void GLAPIENTRY glPopMatrix(void)
GLenum GLsizei n
Definition: glext.h:4618
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
STL namespace.
#define GL_ONE_MINUS_SRC_ALPHA
Definition: glew.h:283
double z
X,Y,Z coordinates.
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
#define GL_LIGHTING
Definition: glew.h:381
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
GLAPI void GLAPIENTRY glBlendFunc(GLenum sfactor, GLenum dfactor)
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
float getTextScale() const
Definition: CAxis.cpp:288
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
void enableTickMarks(bool v=true)
Definition: CAxis.cpp:272
#define MRPT_END
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void setLineWidth(float w)
Definition: CAxis.cpp:264
int version
Definition: mrpt_jpeglib.h:898
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
Definition: CAxis.cpp:239
GLAPI void GLAPIENTRY glBegin(GLenum mode)
#define GL_BLEND
Definition: glew.h:428
void getTextLabelOrientation(int axis, float &yaw_deg, float &pitch_deg, float &roll_deg) const
axis: {0,1,2}=>{X,Y,Z}
Definition: CAxis.cpp:305
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
void render_dl() const MRPT_OVERRIDE
Render.
Definition: CAxis.cpp:56
GLclampd zmax
Definition: glext.h:6808
GLAPI void GLAPIENTRY glTranslatef(GLfloat x, GLfloat y, GLfloat z)
#define MRPT_START
#define GL_SRC_ALPHA
Definition: glew.h:282
const GLdouble * v
Definition: glext.h:3603
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setTextLabelOrientation(int axis, float yaw_deg, float pitch_deg, float roll_deg)
axis: {0,1,2}=>{X,Y,Z}
Definition: CAxis.cpp:298
float getLineWidth() const
Definition: CAxis.cpp:268
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CAxis.cpp:189
void OPENGL_IMPEXP checkOpenGLError()
Checks glGetError and throws an exception if an error situation is found.
Definition: gl_utils.cpp:134
Draw a 3D world axis, with coordinate marks at some regular interval.
Definition: CAxis.h:34
GLuint in
Definition: glext.h:6301
renders glyphs filled with antialiased outlines
Definition: opengl_fonts.h:40
void setFrequency(float f)
Changes the frequency of the "ticks".
Definition: CAxis.cpp:255
The namespace for 3D scene representation and rendering.
#define ASSERT_(f)
GLAPI void GLAPIENTRY glEnd(void)
GLAPI void GLAPIENTRY glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
Definition: CAxis.cpp:209
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:191
#define GL_LINES
Definition: glew.h:269
GLAPI void GLAPIENTRY glPushMatrix(void)
Lightweight 3D point.
void setAxisLimits(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax)
Definition: CAxis.cpp:292
renders glyphs as filled polygons
Definition: opengl_fonts.h:38
GLAPI void GLAPIENTRY glDisable(GLenum cap)
void setTextScale(float f)
Changes the size of text labels (default:0.25)
Definition: CAxis.cpp:283
static CAxisPtr Create()



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020