Main MRPT website > C++ reference for MRPT 1.5.6
CSetOfTexturedTriangles.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 
13 #include <mrpt/utils/CStream.h>
14 
15 #include "opengl_internals.h"
16 
17 using namespace std;
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 using namespace mrpt::utils;
21 using namespace mrpt::math;
22 
24 
25 /*---------------------------------------------------------------
26  ~CTexturedPlane
27  ---------------------------------------------------------------*/
29 {
30 }
31 
32 /*---------------------------------------------------------------
33  render
34  ---------------------------------------------------------------*/
35 void CSetOfTexturedTriangles::render_texturedobj() const
36 {
37 #if MRPT_HAS_OPENGL_GLUT
39 
41 
43 
44  float ax, ay, az, bx, by, bz;
45 
47  for (it = m_triangles.begin(); it != m_triangles.end(); ++it)
48  {
49  // Compute the normal vector:
50  // ---------------------------------
51  ax = it->m_v2.m_x - it->m_v1.m_x;
52  ay = it->m_v2.m_y - it->m_v1.m_y;
53  az = it->m_v2.m_z - it->m_v1.m_z;
54 
55  bx = it->m_v3.m_x - it->m_v1.m_x;
56  by = it->m_v3.m_y - it->m_v1.m_y;
57  bz = it->m_v3.m_z - it->m_v1.m_z;
58 
59  glNormal3f(ay * bz - az * by, -ax * bz + az * bx, ax * by - ay * bx);
60 
61  glTexCoord2d(float(it->m_v1.m_u)/r_width, float(it->m_v1.m_v)/r_height); glVertex3f(it->m_v1.m_x, it->m_v1.m_y, it->m_v1.m_z);
62  glTexCoord2d(float(it->m_v2.m_u)/r_width, float(it->m_v2.m_v)/r_height); glVertex3f(it->m_v2.m_x, it->m_v2.m_y, it->m_v2.m_z);
63  glTexCoord2d(float(it->m_v3.m_u)/r_width, float(it->m_v3.m_v)/r_height); glVertex3f(it->m_v3.m_x, it->m_v3.m_y, it->m_v3.m_z);
64  }
65 
66  glEnd();
67 
68  MRPT_END
69 #endif
70 }
71 
72 /*---------------------------------------------------------------
73  Implements the writing to a CStream capability of
74  CSerializable objects
75  ---------------------------------------------------------------*/
76 void CSetOfTexturedTriangles::writeToStream(mrpt::utils::CStream &out, int *version) const
77 {
78  if (version)
79  *version = 2;
80  else
81  {
82  uint32_t n;
83 
84  writeToStreamRender(out);
85  writeToStreamTexturedObject(out);
86 
87  n = (uint32_t)m_triangles.size();
88 
89  out << n;
90 
91  for (uint32_t i=0;i<n;i++)
92  m_triangles[i].writeToStream(out);
93  }
94 }
95 
96 /*---------------------------------------------------------------
97  Implements the reading from a CStream capability of
98  CSerializable objects
99  ---------------------------------------------------------------*/
100 void CSetOfTexturedTriangles::readFromStream(mrpt::utils::CStream &in, int version)
101 {
102  switch(version)
103  {
104  case 0:
105  case 1:
106  case 2:
107  {
108  readFromStreamRender(in);
109  if (version>=2)
110  {
111  readFromStreamTexturedObject(in);
112  }
113  else
114  { // Old version.
115  in >> CTexturedObject::m_textureImage;
116  in >> CTexturedObject::m_enableTransparency;
117  if (CTexturedObject::m_enableTransparency)
118  {
119  in >> CTexturedObject::m_textureImageAlpha;
120  assignImage( CTexturedObject::m_textureImage, CTexturedObject::m_textureImageAlpha );
121  }
122  else
123  assignImage( CTexturedObject::m_textureImage );
124  }
125 
126  uint32_t n;
127  in >> n;
128  m_triangles.resize(n);
129 
130  for (uint32_t i=0;i<n;i++)
131  m_triangles[i].readFromStream(in);
132 
133  } break;
134  default:
136  };
137  CRenderizableDisplayList::notifyChange();
138 }
139 
140 bool CSetOfTexturedTriangles::traceRay(const mrpt::poses::CPose3D &o, double &dist) const
141 {
143  throw std::runtime_error("TODO: TraceRay not implemented in CSetOfTexturedTriangles");
144 }
145 
146 void CSetOfTexturedTriangles::getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const
147 {
148  bb_min = mrpt::math::TPoint3D(std::numeric_limits<double>::max(),std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
149  bb_max = mrpt::math::TPoint3D(-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max(),-std::numeric_limits<double>::max());
150 
151  for (size_t i=0;i<m_triangles.size();i++)
152  {
153  const TTriangle &t=m_triangles[i];
154 
155  keep_min(bb_min.x, t.m_v1.m_x); keep_max(bb_max.x, t.m_v1.m_x);
156  keep_min(bb_min.y, t.m_v1.m_y); keep_max(bb_max.y, t.m_v1.m_y);
157  keep_min(bb_min.z, t.m_v1.m_z); keep_max(bb_max.z, t.m_v1.m_z);
158 
159  keep_min(bb_min.x, t.m_v2.m_x); keep_max(bb_max.x, t.m_v2.m_x);
160  keep_min(bb_min.y, t.m_v2.m_y); keep_max(bb_max.y, t.m_v2.m_y);
161  keep_min(bb_min.z, t.m_v2.m_z); keep_max(bb_max.z, t.m_v2.m_z);
162 
163  keep_min(bb_min.x, t.m_v3.m_x); keep_max(bb_max.x, t.m_v3.m_x);
164  keep_min(bb_min.y, t.m_v3.m_y); keep_max(bb_max.y, t.m_v3.m_y);
165  keep_min(bb_min.z, t.m_v3.m_z); keep_max(bb_max.z, t.m_v3.m_z);
166  }
167 
168  // Convert to coordinates of my parent:
169  m_pose.composePoint(bb_min, bb_min);
170  m_pose.composePoint(bb_max, bb_max);
171 }
172 
173 
174 CSetOfTexturedTriangles::TVertex::TVertex( ) :
175  m_x(0.0), m_y(0.0), m_z(0.0), m_u(0), m_v(0)
176 { }
177 
179  m_x(x), m_y(y), m_z(z), m_u(u), m_v(v)
180 { }
181 
183  out << m_x << m_y << m_z << m_u << m_v;
184 }
186  in >> m_x >> m_y >> m_z >> m_u >> m_v;
187 }
188 
190 { }
191 
193  m_v1(v1), m_v2(v2), m_v3(v3)
194 { }
195 
197  m_v1.writeToStream(out); m_v2.writeToStream(out); m_v3.writeToStream(out);
198 }
200  m_v1.readFromStream(in); m_v2.readFromStream(in); m_v3.readFromStream(in);
201 }
202 
203 
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
GLdouble GLdouble t
Definition: glext.h:3610
GLdouble GLdouble z
Definition: glext.h:3734
GLbyte GLbyte bz
Definition: glext.h:5451
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
bool BASE_IMPEXP traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons&#39; properties.
Definition: geometry.cpp:1996
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
GLenum GLsizei n
Definition: glext.h:4618
#define GL_TRIANGLES
Definition: glew.h:272
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
double z
X,Y,Z coordinates.
void writeToStream(mrpt::utils::CStream &out) const
#define GL_SMOOTH
Definition: glew.h:631
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
void writeToStream(mrpt::utils::CStream &out) const
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_END
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
GLfloat GLfloat GLfloat GLfloat v3
Definition: glext.h:3924
int version
Definition: mrpt_jpeglib.h:898
GLAPI void GLAPIENTRY glBegin(GLenum mode)
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
Definition: bits.h:176
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
#define MRPT_START
const GLdouble * v
Definition: glext.h:3603
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLfloat GLfloat v1
Definition: glext.h:3922
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
Definition: bits.h:171
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
GLuint in
Definition: glext.h:6301
The namespace for 3D scene representation and rendering.
GLAPI void GLAPIENTRY glEnd(void)
GLenum GLint GLint y
Definition: glext.h:3516
GLbyte by
Definition: glext.h:5451
GLAPI void GLAPIENTRY glTexCoord2d(GLdouble s, GLdouble t)
GLfloat GLfloat GLfloat v2
Definition: glext.h:3923
GLenum GLint x
Definition: glext.h:3516
Lightweight 3D point.
unsigned __int32 uint32_t
Definition: rptypes.h:49



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019