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 }
IMPLEMENTS_SERIALIZABLE(CSetOfTexturedTriangles, CRenderizableDisplayList, mrpt::opengl) CSetOfTexturedTriangles
A renderizable object suitable for rendering with OpenGL's display lists.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:87
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define MRPT_START
Definition: exceptions.h:262
#define MRPT_END
Definition: exceptions.h:266
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
#define GL_SMOOTH
Definition: glew.h:635
#define GL_TRIANGLES
Definition: glew.h:276
GLAPI void GLAPIENTRY glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
GLAPI void GLAPIENTRY glBegin(GLenum mode)
GLAPI void GLAPIENTRY glVertex3f(GLfloat x, GLfloat y, GLfloat z)
GLAPI void GLAPIENTRY glTexCoord2d(GLdouble s, GLdouble t)
GLAPI void GLAPIENTRY glEnd(void)
GLAPI void GLAPIENTRY glShadeModel(GLenum mode)
GLdouble GLdouble t
Definition: glext.h:3689
GLfloat GLfloat v1
Definition: glext.h:4105
GLenum GLsizei n
Definition: glext.h:5074
GLbyte GLbyte bz
Definition: glext.h:6105
const GLdouble * v
Definition: glext.h:3678
GLenum GLint GLint y
Definition: glext.h:3538
GLuint in
Definition: glext.h:7274
GLenum GLint x
Definition: glext.h:3538
GLfloat GLfloat GLfloat v2
Definition: glext.h:4107
GLdouble GLdouble z
Definition: glext.h:3872
GLfloat GLfloat GLfloat GLfloat v3
Definition: glext.h:4109
GLbyte by
Definition: glext.h:6105
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
This base provides a set of functions for maths stuff.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:16
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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.
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.
unsigned __int32 uint32_t
Definition: rptypes.h:47
unsigned char uint8_t
Definition: rptypes.h:41
Lightweight 3D point.
double x
X,Y,Z coordinates.
void writeToStream(mrpt::serialization::CArchive &out) const
void readFromStream(mrpt::serialization::CArchive &in)
void readFromStream(mrpt::serialization::CArchive &in)
void writeToStream(mrpt::serialization::CArchive &out) const



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST