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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020