Main MRPT website > C++ reference for MRPT 1.9.9
CMesh3D.h
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 #ifndef opengl_CMesh3D_H
11 #define opengl_CMesh3D_H
12 
14 #include <mrpt/utils/color_maps.h>
15 #include <Eigen/Dense>
16 
17 using Eigen::Array;
18 using Eigen::Dynamic;
19 
20 namespace mrpt
21 {
22 namespace opengl
23 {
24 /** A 3D mesh composed of Triangles and/or Quads.
25  * A typical usage example would be a 3D model of an object.
26  * \sa opengl::COpenGLScene,opengl::CMesh,opengl::CAssimpModel
27  *
28  * <div align="center">
29  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
30  * border-style: solid;">
31  * <tr> <td> mrpt::opengl::CMesh3D </td> <td> \image html preview_CMesh3D.png
32  * </td> </tr>
33  * </table>
34  * </div>
35  *
36  * \ingroup mrpt_opengl_grp
37  */
39 {
41 
42  typedef int f_verts[4];
43  typedef float coord3D[3];
44 
45  protected:
52  float m_lineWidth;
53  float m_pointSize;
54 
55  // Data
56  /** Number of vertices of the mesh */
57  unsigned int m_num_verts;
58  /** Number of faces of the mesh */
59  unsigned int m_num_faces;
60  /** Pointer storing whether a face is a quad (1) or a triangle (0) */
61  bool* m_is_quad;
62  /** Pointer storing the vertices that compose each face. Size: 4 x num_faces
63  * (4 for the possible max number - quad) */
65  /** Pointer storing the coordinates of the vertices. Size: 3 x num_vertices
66  */
68  /** Pointer storing the face normals. Size: 3 x num_faces */
70 
71  // Colors
72  /** Color of the edges (when shown) */
73  float edge_color[4];
74  /** Color of the faces (when shown) */
75  float face_color[4];
76  /** Color of the vertices (when shown) */
77  float vert_color[4];
78  mrpt::utils::TColormap m_colorMap; // Not used yet. I leave it here in case
79  // I want to use it in the future
80 
81  public:
82  void enableTransparency(bool v)
83  {
86  }
87  void enableAntiAliasing(bool v)
88  {
89  m_antiAliasing = v;
91  }
92  void enableShowEdges(bool v)
93  {
94  m_showEdges = v;
96  }
97  void enableShowFaces(bool v)
98  {
99  m_showFaces = v;
101  }
103  {
104  m_showVertices = v;
106  }
107  void enableFaceNormals(bool v)
108  {
111  }
112 
113  /** Load a 3D mesh. The arguments indicate:
114  - num_verts: Number of vertices of the mesh
115  - num_faces: Number of faces of the mesh
116  - verts_per_face: An array (pointer) with the number of vertices of each
117  face. The elements must be set either to 3 (triangle) or 4 (quad).
118  - face_verts: An array (pointer) with the vertices of each face. The
119  vertices of each face must be consecutive in this array.
120  - vert_coords: An array (pointer) with the coordinates of each vertex.
121  The xyz coordinates of each vertex must be consecutive in this array.
122  */
123  void loadMesh(
124  unsigned int num_verts, unsigned int num_faces, int* verts_per_face,
125  int* face_verts, float* vert_coords);
126 
127  /** Load a 3D mesh. The arguments indicate:
128  - num_verts: Number of vertices of the mesh
129  - num_faces: Number of faces of the mesh
130  - is_quad: A binary array (Eigen) saying whether the face is a quad (1)
131  or a triangle (0)
132  - face_verts: An array (Eigen) with the vertices of each face. For every
133  column (face), each row contains the num of a vertex. The fourth does not
134  need
135  to be filled if the face is a triangle.
136  - vert_coords: An array (Eigen) with the coordinates of each vertex. For
137  every column (vertex), each row contains the xyz coordinates of the
138  vertex.
139  */
140  void loadMesh(
141  unsigned int num_verts, unsigned int num_faces,
142  const Array<bool, 1, Dynamic>& is_quad,
143  const Array<int, 4, Dynamic>& face_verts,
144  const Array<float, 3, Dynamic>& vert_coords);
145 
146  void setEdgeColor(float r, float g, float b, float a = 1.f);
147  void setFaceColor(float r, float g, float b, float a = 1.f);
148  void setVertColor(float r, float g, float b, float a = 1.f);
149  void setLineWidth(float lw) { m_lineWidth = lw; }
150  void setPointSize(float ps) { m_pointSize = ps; }
151  /** Class factory
152  */
153  static CMesh3D::Ptr Create(
155  bool enableShowVertices);
156 
157  /** Render
158  */
159  void render_dl() const override;
160 
161  /** Evaluates the bounding box of this object (including possible children)
162  * in the coordinate frame of the object parent.
163  */
164  void getBoundingBox(
165  mrpt::math::TPoint3D& bb_min,
166  mrpt::math::TPoint3D& bb_max) const override;
167 
168  /** Constructor */
169  CMesh3D(
170  bool enableTransparency = false, bool antiAliasing = false,
171  bool enableShowEdges = true, bool enableShowFaces = true,
172  bool enableShowVertices = false);
173  /** Private, virtual destructor: only can be deleted from smart pointers */
174  virtual ~CMesh3D();
175 };
176 
177 } // end namespace
178 
179 } // End of namespace
180 
181 #endif
mrpt::utils::TColormap m_colorMap
Definition: CMesh3D.h:78
void setLineWidth(float lw)
Definition: CMesh3D.h:149
TColormap
Different colormaps for use in mrpt::utils::colormap()
Definition: color_maps.h:31
unsigned int m_num_verts
Number of vertices of the mesh.
Definition: CMesh3D.h:57
void render_dl() const override
Render.
Definition: CMesh3D.cpp:235
float face_color[4]
Color of the faces (when shown)
Definition: CMesh3D.h:75
std::shared_ptr< CMesh3D > Ptr
Definition: CMesh3D.h:40
void enableTransparency(bool v)
Definition: CMesh3D.h:82
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
void setPointSize(float ps)
Definition: CMesh3D.h:150
A 3D mesh composed of Triangles and/or Quads.
Definition: CMesh3D.h:38
void enableShowEdges(bool v)
Definition: CMesh3D.h:92
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
bool m_enableTransparency
Definition: CMesh3D.h:46
static Ptr Create(Args &&... args)
Definition: CMesh3D.h:40
void setVertColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:486
CMesh3D(bool enableTransparency=false, bool antiAliasing=false, bool enableShowEdges=true, bool enableShowFaces=true, bool enableShowVertices=false)
Constructor.
Definition: CMesh3D.cpp:27
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
void loadMesh(unsigned int num_verts, unsigned int num_faces, int *verts_per_face, int *face_verts, float *vert_coords)
Load a 3D mesh.
Definition: CMesh3D.cpp:61
unsigned int m_num_faces
Number of faces of the mesh.
Definition: CMesh3D.h:59
void enableAntiAliasing(bool v)
Definition: CMesh3D.h:87
float coord3D[3]
Definition: CMesh3D.h:43
void setFaceColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:478
void enableFaceNormals(bool v)
Definition: CMesh3D.h:107
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
virtual ~CMesh3D()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CMesh3D.cpp:60
void enableShowFaces(bool v)
Definition: CMesh3D.h:97
bool * m_is_quad
Pointer storing whether a face is a quad (1) or a triangle (0)
Definition: CMesh3D.h:61
coord3D * m_normals
Pointer storing the face normals.
Definition: CMesh3D.h:69
Lightweight 3D point.
float vert_color[4]
Color of the vertices (when shown)
Definition: CMesh3D.h:77
void setEdgeColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:470
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
Definition: CMesh3D.cpp:434
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
void enableShowVertices(bool v)
Definition: CMesh3D.h:102
coord3D * m_vert_coords
Pointer storing the coordinates of the vertices.
Definition: CMesh3D.h:67
f_verts * m_face_verts
Pointer storing the vertices that compose each face.
Definition: CMesh3D.h:64
float edge_color[4]
Color of the edges (when shown)
Definition: CMesh3D.h:73



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019