MRPT  1.9.9
CMesh3D.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/img/color_maps.h>
14 #include <array>
15 
16 namespace mrpt::opengl
17 {
18 /** A 3D mesh composed of Triangles and/or Quads.
19  * A typical usage example would be a 3D model of an object.
20  * \sa opengl::COpenGLScene,opengl::CMesh,opengl::CAssimpModel
21  *
22  * <div align="center">
23  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
24  * border-style: solid;">
25  * <tr> <td> mrpt::opengl::CMesh3D </td> <td> \image html preview_CMesh3D.png
26  * </td> </tr>
27  * </table>
28  * </div>
29  *
30  * \ingroup mrpt_opengl_grp
31  */
33 {
35 
36  using f_verts = std::array<int, 4>;
37  using coord3D = mrpt::math::TPoint3Df;
38 
39  protected:
45  bool m_computeNormals{true};
46  float m_lineWidth{2.f};
47  float m_pointSize{6.f};
48 
49  // Data
50  /** Number of vertices of the mesh */
51  unsigned int m_num_verts{0};
52  /** Number of faces of the mesh */
53  unsigned int m_num_faces{0};
54  /** Pointer storing whether a face is a quad (1) or a triangle (0) */
55  std::vector<bool> m_is_quad;
56  /** Pointer storing the vertices that compose each face. Size: 4 x num_faces
57  * (4 for the possible max number - quad) */
58  std::vector<f_verts> m_face_verts;
59 
60  /** Pointer storing the coordinates of the vertices. Size: 3 x num_vertices
61  */
62  std::vector<coord3D> m_vert_coords;
63  /** Pointer storing the face normals. Size: 3 x num_faces */
64  std::vector<coord3D> m_normals;
65 
66  // Colors
67  /** Color of the edges (when shown) */
68  float edge_color[4] = {.9f, .9f, .9f, 1.0f};
69  /** Color of the faces (when shown) */
70  float face_color[4] = {.7f, .7f, .8f, 1.0f};
71  /** Color of the vertices (when shown) */
72  float vert_color[4] = {.3f, .3f, .3f, 1.0f};
74  // Not used yet. I leave it here in case
75  // I want to use it in the future
76 
77  public:
78  void enableTransparency(bool v)
79  {
82  }
83  void enableAntiAliasing(bool v)
84  {
85  m_antiAliasing = v;
87  }
88  void enableShowEdges(bool v)
89  {
90  m_showEdges = v;
92  }
93  void enableShowFaces(bool v)
94  {
95  m_showFaces = v;
97  }
98  void enableShowVertices(bool v)
99  {
100  m_showVertices = v;
102  }
103  void enableFaceNormals(bool v)
104  {
105  m_computeNormals = v;
107  }
108 
109  /** Load a 3D mesh. The arguments indicate:
110  - num_verts: Number of vertices of the mesh
111  - num_faces: Number of faces of the mesh
112  - verts_per_face: An array (pointer) with the number of vertices of each
113  face. The elements must be set either to 3 (triangle) or 4 (quad).
114  - face_verts: An array (pointer) with the vertices of each face. The
115  vertices of each face must be consecutive in this array.
116  - vert_coords: An array (pointer) with the coordinates of each vertex.
117  The xyz coordinates of each vertex must be consecutive in this array.
118  */
119  void loadMesh(
120  unsigned int num_verts, unsigned int num_faces, int* verts_per_face,
121  int* face_verts, float* vert_coords);
122 
123  /** Load a 3D mesh. The arguments indicate:
124  - num_verts: Number of vertices of the mesh
125  - num_faces: Number of faces of the mesh
126  - is_quad: A binary array saying whether the face is a quad (1)
127  or a triangle (0)
128  - face_verts: An array with the vertices of each face. For every
129  column (face), each row contains the num of a vertex. The fourth does not
130  need
131  to be filled if the face is a triangle.
132  - vert_coords: An array with the coordinates of each vertex. For
133  every column (vertex), each row contains the xyz coordinates of the
134  vertex.
135  */
136  void loadMesh(
137  unsigned int num_verts, unsigned int num_faces,
138  const mrpt::math::CMatrixDynamic<bool>& is_quad,
139  const mrpt::math::CMatrixDynamic<int>& face_verts,
140  const mrpt::math::CMatrixDynamic<float>& vert_coords);
141 
142  void setEdgeColor(float r, float g, float b, float a = 1.f);
143  void setFaceColor(float r, float g, float b, float a = 1.f);
144  void setVertColor(float r, float g, float b, float a = 1.f);
145  void setLineWidth(float lw) { m_lineWidth = lw; }
146  void setPointSize(float ps) { m_pointSize = ps; }
147  /** Render
148  */
149  void render_dl() const override;
150 
151  /** Evaluates the bounding box of this object (including possible children)
152  * in the coordinate frame of the object parent.
153  */
154  void getBoundingBox(
156  mrpt::math::TPoint3D& bb_max) const override;
157 
158  /** Constructor */
159  CMesh3D(
160  bool enableTransparency = false, bool antiAliasing = false,
161  bool enableShowEdges = true, bool enableShowFaces = true,
162  bool enableShowVertices = false);
163  /** Private, virtual destructor: only can be deleted from smart pointers */
164  ~CMesh3D() override;
165 };
166 
167 } // namespace mrpt::opengl
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:29
void setLineWidth(float lw)
Definition: CMesh3D.h:145
unsigned int m_num_verts
Number of vertices of the mesh.
Definition: CMesh3D.h:51
void render_dl() const override
Render.
Definition: CMesh3D.cpp:218
std::vector< coord3D > m_vert_coords
Pointer storing the coordinates of the vertices.
Definition: CMesh3D.h:62
float face_color[4]
Color of the faces (when shown)
Definition: CMesh3D.h:70
void enableTransparency(bool v)
Definition: CMesh3D.h:78
STL namespace.
std::vector< f_verts > m_face_verts
Pointer storing the vertices that compose each face.
Definition: CMesh3D.h:58
void setPointSize(float ps)
Definition: CMesh3D.h:146
A 3D mesh composed of Triangles and/or Quads.
Definition: CMesh3D.h:32
void enableShowEdges(bool v)
Definition: CMesh3D.h:88
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
bool m_enableTransparency
Definition: CMesh3D.h:40
void setVertColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:431
Lightweight 3D point (float version).
Definition: TPoint3D.h:21
CMesh3D(bool enableTransparency=false, bool antiAliasing=false, bool enableShowEdges=true, bool enableShowFaces=true, bool enableShowVertices=false)
Constructor.
Definition: CMesh3D.cpp:26
[New in MRPT 1.5.0]
Definition: color_maps.h:35
std::vector< coord3D > m_normals
Pointer storing the face normals.
Definition: CMesh3D.h:64
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:43
unsigned int m_num_faces
Number of faces of the mesh.
Definition: CMesh3D.h:53
void enableAntiAliasing(bool v)
Definition: CMesh3D.h:83
void setFaceColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:423
void enableFaceNormals(bool v)
Definition: CMesh3D.h:103
mrpt::img::TColormap m_colorMap
Definition: CMesh3D.h:73
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
~CMesh3D() override
Private, virtual destructor: only can be deleted from smart pointers.
std::vector< bool > m_is_quad
Pointer storing whether a face is a quad (1) or a triangle (0)
Definition: CMesh3D.h:55
void enableShowFaces(bool v)
Definition: CMesh3D.h:93
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const auto bb_min
Lightweight 3D point.
Definition: TPoint3D.h:90
float vert_color[4]
Color of the vertices (when shown)
Definition: CMesh3D.h:72
void setEdgeColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:415
This template class provides the basic functionality for a general 2D any-size, resizable container o...
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:379
std::array< int, 4 > f_verts
Definition: CMesh3D.h:36
void enableShowVertices(bool v)
Definition: CMesh3D.h:98
float edge_color[4]
Color of the edges (when shown)
Definition: CMesh3D.h:68



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7e629e01a Sat Dec 14 00:05:55 2019 +0100 at sáb dic 14 00:15:10 CET 2019