Main MRPT website > C++ reference for MRPT 1.9.9
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-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 "opengl-precomp.h" // Precompiled header
11 
14 
15 #include "opengl_internals.h"
16 
17 using namespace std;
18 using namespace mrpt;
19 using namespace mrpt::opengl;
20 
21 using namespace mrpt::math;
22 
25 
26 /*---------------------------------------------------------------
27  ~CTexturedPlane
28  ---------------------------------------------------------------*/
29 CSetOfTexturedTriangles::~CSetOfTexturedTriangles() {}
30 /*---------------------------------------------------------------
31  render
32  ---------------------------------------------------------------*/
33 void CSetOfTexturedTriangles::render_texturedobj() const
34 {
35 #if MRPT_HAS_OPENGL_GLUT
37 
39 
41 
42  float ax, ay, az, bx, by, bz;
43 
45  for (it = m_triangles.begin(); it != m_triangles.end(); ++it)
46  {
47  // Compute the normal vector:
48  // ---------------------------------
49  ax = it->m_v2.m_x - it->m_v1.m_x;
50  ay = it->m_v2.m_y - it->m_v1.m_y;
51  az = it->m_v2.m_z - it->m_v1.m_z;
52 
53  bx = it->m_v3.m_x - it->m_v1.m_x;
54  by = it->m_v3.m_y - it->m_v1.m_y;
55  bz = it->m_v3.m_z - it->m_v1.m_z;
56 
57  glNormal3f(ay * bz - az * by, -ax * bz + az * bx, ax * by - ay * bx);
58 
60  float(it->m_v1.m_u) / r_width, float(it->m_v1.m_v) / r_height);
61  glVertex3f(it->m_v1.m_x, it->m_v1.m_y, it->m_v1.m_z);
63  float(it->m_v2.m_u) / r_width, float(it->m_v2.m_v) / r_height);
64  glVertex3f(it->m_v2.m_x, it->m_v2.m_y, it->m_v2.m_z);
66  float(it->m_v3.m_u) / r_width, float(it->m_v3.m_v) / r_height);
67  glVertex3f(it->m_v3.m_x, it->m_v3.m_y, it->m_v3.m_z);
68  }
69 
70  glEnd();
71 
72  MRPT_END
73 #endif
74 }
75 
76 uint8_t CSetOfTexturedTriangles::serializeGetVersion() const { return 2; }
77 void CSetOfTexturedTriangles::serializeTo(
79 {
80  uint32_t n;
81 
82  writeToStreamRender(out);
83  writeToStreamTexturedObject(out);
84 
85  n = (uint32_t)m_triangles.size();
86 
87  out << n;
88 
89  for (uint32_t i = 0; i < n; i++) m_triangles[i].writeToStream(out);
90 }
91 
92 void CSetOfTexturedTriangles::serializeFrom(
94 {
95  switch (version)
96  {
97  case 0:
98  case 1:
99  case 2:
100  {
101  readFromStreamRender(in);
102  if (version >= 2)
103  {
104  readFromStreamTexturedObject(in);
105  }
106  else
107  { // Old version.
108  in >> CTexturedObject::m_textureImage;
109  in >> CTexturedObject::m_enableTransparency;
110  if (CTexturedObject::m_enableTransparency)
111  {
112  in >> CTexturedObject::m_textureImageAlpha;
113  assignImage(
114  CTexturedObject::m_textureImage,
115  CTexturedObject::m_textureImageAlpha);
116  }
117  else
118  assignImage(CTexturedObject::m_textureImage);
119  }
120 
121  uint32_t n;
122  in >> n;
123  m_triangles.resize(n);
124 
125  for (uint32_t i = 0; i < n; i++) m_triangles[i].readFromStream(in);
126  }
127  break;
128  default:
130  };
131  CRenderizableDisplayList::notifyChange();
132 }
133 
135  const mrpt::poses::CPose3D& o, double& dist) const
136 {
138  MRPT_UNUSED_PARAM(dist);
139  throw std::runtime_error(
140  "TODO: TraceRay not implemented in CSetOfTexturedTriangles");
141 }
142 
143 void CSetOfTexturedTriangles::getBoundingBox(
144  mrpt::math::TPoint3D& bb_min, mrpt::math::TPoint3D& bb_max) const
145 {
146  bb_min = mrpt::math::TPoint3D(
147  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
148  std::numeric_limits<double>::max());
149  bb_max = mrpt::math::TPoint3D(
150  -std::numeric_limits<double>::max(),
151  -std::numeric_limits<double>::max(),
152  -std::numeric_limits<double>::max());
153 
154  for (size_t i = 0; i < m_triangles.size(); i++)
155  {
156  const TTriangle& t = m_triangles[i];
157 
158  keep_min(bb_min.x, t.m_v1.m_x);
159  keep_max(bb_max.x, t.m_v1.m_x);
160  keep_min(bb_min.y, t.m_v1.m_y);
161  keep_max(bb_max.y, t.m_v1.m_y);
162  keep_min(bb_min.z, t.m_v1.m_z);
163  keep_max(bb_max.z, t.m_v1.m_z);
164 
165  keep_min(bb_min.x, t.m_v2.m_x);
166  keep_max(bb_max.x, t.m_v2.m_x);
167  keep_min(bb_min.y, t.m_v2.m_y);
168  keep_max(bb_max.y, t.m_v2.m_y);
169  keep_min(bb_min.z, t.m_v2.m_z);
170  keep_max(bb_max.z, t.m_v2.m_z);
171 
172  keep_min(bb_min.x, t.m_v3.m_x);
173  keep_max(bb_max.x, t.m_v3.m_x);
174  keep_min(bb_min.y, t.m_v3.m_y);
175  keep_max(bb_max.y, t.m_v3.m_y);
176  keep_min(bb_min.z, t.m_v3.m_z);
177  keep_max(bb_max.z, t.m_v3.m_z);
178  }
179 
180  // Convert to coordinates of my parent:
181  m_pose.composePoint(bb_min, bb_min);
182  m_pose.composePoint(bb_max, bb_max);
183 }
184 
185 CSetOfTexturedTriangles::TVertex::TVertex()
186  : m_x(0.0), m_y(0.0), m_z(0.0), m_u(0), m_v(0)
187 {
188 }
189 
191  float x, float y, float z, uint32_t u, uint32_t v)
192  : m_x(x), m_y(y), m_z(z), m_u(u), m_v(v)
193 {
194 }
195 
198 {
199  out << m_x << m_y << m_z << m_u << m_v;
200 }
203 {
204  in >> m_x >> m_y >> m_z >> m_u >> m_v;
205 }
206 
210  : m_v1(v1), m_v2(v2), m_v3(v3)
211 {
212 }
213 
216 {
217  m_v1.writeToStream(out);
218  m_v2.writeToStream(out);
219  m_v3.writeToStream(out);
220 }
223 {
224  m_v1.readFromStream(in);
225  m_v2.readFromStream(in);
226  m_v3.readFromStream(in);
227 }
n
GLenum GLsizei n
Definition: glext.h:5074
mrpt::keep_min
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: core/include/mrpt/core/bits_math.h:124
CSetOfTexturedTriangles.h
glBegin
GLAPI void GLAPIENTRY glBegin(GLenum mode)
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::opengl::CSetOfTexturedTriangles::TVertex::TVertex
TVertex()
Default constructor
Definition: CSetOfTexturedTriangles.cpp:185
by
GLbyte by
Definition: glext.h:6105
mrpt::opengl::CSetOfTexturedTriangles::TTriangle::TTriangle
TTriangle()
Default constructor.
Definition: CSetOfTexturedTriangles.cpp:207
t
GLdouble GLdouble t
Definition: glext.h:3689
mrpt::opengl::CSetOfTexturedTriangles::TVertex::readFromStream
void readFromStream(mrpt::serialization::CArchive &in)
Definition: CSetOfTexturedTriangles.cpp:201
mrpt::opengl::CSetOfTexturedTriangles::TTriangle::writeToStream
void writeToStream(mrpt::serialization::CArchive &out) const
Definition: CSetOfTexturedTriangles.cpp:214
mrpt::opengl::CSetOfTexturedTriangles::TTriangle::readFromStream
void readFromStream(mrpt::serialization::CArchive &in)
Definition: CSetOfTexturedTriangles.cpp:221
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::math::TPoint3D::z
double z
Definition: lightweight_geom_data.h:385
MRPT_UNUSED_PARAM
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
mrpt::opengl::CSetOfTexturedTriangles::TTriangle
Triangle.
Definition: CSetOfTexturedTriangles.h:47
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
IMPLEMENTS_SERIALIZABLE
IMPLEMENTS_SERIALIZABLE(CSetOfTexturedTriangles, CRenderizableDisplayList, mrpt::opengl) CSetOfTexturedTriangles
Definition: CSetOfTexturedTriangles.cpp:23
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
glVertex3f
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
mrpt::opengl::CSetOfTexturedTriangles::TVertex::writeToStream
void writeToStream(mrpt::serialization::CArchive &out) const
Definition: CSetOfTexturedTriangles.cpp:196
mrpt::math::traceRay
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::math::TPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
Definition: geometry.cpp:2590
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
v
const GLdouble * v
Definition: glext.h:3678
glEnd
GLAPI void GLAPIENTRY glEnd(void)
v1
GLfloat GLfloat v1
Definition: glext.h:4105
GL_TRIANGLES
#define GL_TRIANGLES
Definition: glew.h:276
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
v2
GLfloat GLfloat GLfloat v2
Definition: glext.h:4107
mrpt::keep_max
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: core/include/mrpt/core/bits_math.h:131
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
glShadeModel
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
mrpt::math::TPoint3D::x
double x
X,Y,Z coordinates.
Definition: lightweight_geom_data.h:385
mrpt::opengl::CSetOfTexturedTriangles::TVertex
Triangle vertex.
Definition: CSetOfTexturedTriangles.h:31
v3
GLfloat GLfloat GLfloat GLfloat v3
Definition: glext.h:4109
glNormal3f
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
opengl-precomp.h
mrpt::math::TPoint3D::y
double y
Definition: lightweight_geom_data.h:385
glTexCoord2d
GLAPI void GLAPIENTRY glTexCoord2d(GLdouble s, GLdouble t)
opengl_internals.h
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
z
GLdouble GLdouble z
Definition: glext.h:3872
in
GLuint in
Definition: glext.h:7274
mrpt::opengl::CSetOfTexturedTriangles
A set of textured triangles.
Definition: CSetOfTexturedTriangles.h:23
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
bz
GLbyte GLbyte bz
Definition: glext.h:6105
GL_SMOOTH
#define GL_SMOOTH
Definition: glew.h:635
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
y
GLenum GLint GLint y
Definition: glext.h:3538
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
x
GLenum GLint x
Definition: glext.h:3538



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