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-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
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  using f_verts = int[4];
43  using coord3D = float[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::img::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::opengl::CMesh3D::m_pointSize
float m_pointSize
Definition: CMesh3D.h:53
mrpt::opengl::CMesh3D::setFaceColor
void setFaceColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:440
mrpt::opengl::CMesh3D::m_colorMap
mrpt::img::TColormap m_colorMap
Definition: CMesh3D.h:78
mrpt::opengl::CMesh3D::enableFaceNormals
void enableFaceNormals(bool v)
Definition: CMesh3D.h:107
mrpt::opengl::CMesh3D::loadMesh
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
mrpt::opengl::CMesh3D::m_num_faces
unsigned int m_num_faces
Number of faces of the mesh.
Definition: CMesh3D.h:59
mrpt::img::TColormap
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:31
mrpt::opengl::CMesh3D::~CMesh3D
virtual ~CMesh3D()
Private, virtual destructor: only can be deleted from smart pointers
Definition: CMesh3D.cpp:60
CRenderizableDisplayList.h
color_maps.h
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::opengl::CMesh3D::m_normals
coord3D * m_normals
Pointer storing the face normals.
Definition: CMesh3D.h:69
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
mrpt::opengl::CMesh3D::getBoundingBox
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
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
g
GLubyte g
Definition: glext.h:6279
mrpt::opengl::CMesh3D::f_verts
int[4] f_verts
Definition: CMesh3D.h:42
mrpt::opengl::CMesh3D::m_showVertices
bool m_showVertices
Definition: CMesh3D.h:50
mrpt::opengl::CMesh3D::enableShowVertices
void enableShowVertices(bool v)
Definition: CMesh3D.h:102
mrpt::opengl::CMesh3D::m_vert_coords
coord3D * m_vert_coords
Pointer storing the coordinates of the vertices.
Definition: CMesh3D.h:67
mrpt::opengl::CMesh3D::edge_color
float edge_color[4]
Color of the edges (when shown)
Definition: CMesh3D.h:73
mrpt::opengl::CMesh3D::m_is_quad
bool * m_is_quad
Pointer storing whether a face is a quad (1) or a triangle (0)
Definition: CMesh3D.h:61
v
const GLdouble * v
Definition: glext.h:3678
mrpt::opengl::CMesh3D::enableShowFaces
void enableShowFaces(bool v)
Definition: CMesh3D.h:97
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::opengl::CMesh3D::m_lineWidth
float m_lineWidth
Definition: CMesh3D.h:52
mrpt::opengl::CMesh3D::vert_color
float vert_color[4]
Color of the vertices (when shown)
Definition: CMesh3D.h:77
mrpt::opengl::CMesh3D
A 3D mesh composed of Triangles and/or Quads.
Definition: CMesh3D.h:38
b
GLubyte GLubyte b
Definition: glext.h:6279
mrpt::opengl::CMesh3D::m_face_verts
f_verts * m_face_verts
Pointer storing the vertices that compose each face.
Definition: CMesh3D.h:64
mrpt::opengl::CMesh3D::setEdgeColor
void setEdgeColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:432
mrpt::opengl::CMesh3D::coord3D
float[3] coord3D
Definition: CMesh3D.h:43
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::opengl::CMesh3D::enableTransparency
void enableTransparency(bool v)
Definition: CMesh3D.h:82
mrpt::opengl::CMesh3D::m_num_verts
unsigned int m_num_verts
Number of vertices of the mesh.
Definition: CMesh3D.h:57
mrpt::opengl::CMesh3D::m_enableTransparency
bool m_enableTransparency
Definition: CMesh3D.h:46
mrpt::opengl::CMesh3D::render_dl
void render_dl() const override
Render.
Definition: CMesh3D.cpp:235
img
GLint GLvoid * img
Definition: glext.h:3763
mrpt::opengl::CMesh3D::Create
static Ptr Create(Args &&... args)
Definition: CMesh3D.h:40
mrpt::opengl::CMesh3D::Ptr
std::shared_ptr< CMesh3D > Ptr
Definition: CMesh3D.h:40
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
mrpt::opengl::CMesh3D::setLineWidth
void setLineWidth(float lw)
Definition: CMesh3D.h:149
mrpt::opengl::CMesh3D::m_computeNormals
bool m_computeNormals
Definition: CMesh3D.h:51
mrpt::opengl::CMesh3D::m_showEdges
bool m_showEdges
Definition: CMesh3D.h:48
mrpt::opengl::CMesh3D::face_color
float face_color[4]
Color of the faces (when shown)
Definition: CMesh3D.h:75
mrpt::opengl::CMesh3D::setPointSize
void setPointSize(float ps)
Definition: CMesh3D.h:150
mrpt::opengl::CMesh3D::m_showFaces
bool m_showFaces
Definition: CMesh3D.h:49
mrpt::opengl::CMesh3D::setVertColor
void setVertColor(float r, float g, float b, float a=1.f)
Definition: CMesh3D.cpp:448
mrpt::opengl::CMesh3D::CMesh3D
CMesh3D(bool enableTransparency=false, bool antiAliasing=false, bool enableShowEdges=true, bool enableShowFaces=true, bool enableShowVertices=false)
Constructor.
Definition: CMesh3D.cpp:27
mrpt::opengl::CMesh3D::enableShowEdges
void enableShowEdges(bool v)
Definition: CMesh3D.h:92
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
mrpt::opengl::CMesh3D::m_antiAliasing
bool m_antiAliasing
Definition: CMesh3D.h:47
mrpt::opengl::CMesh3D::enableAntiAliasing
void enableAntiAliasing(bool v)
Definition: CMesh3D.h:87



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