Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
15#include <Eigen/Dense>
16
17using Eigen::Array;
18using Eigen::Dynamic;
19
20namespace mrpt
21{
22 namespace opengl
23 {
24 // This must be added to any CSerializable derived class:
26
27 /** A 3D mesh composed of Triangles and/or Quads.
28 * A typical usage example would be a 3D model of an object.
29 * \sa opengl::COpenGLScene,opengl::CMesh,opengl::CAssimpModel
30 *
31 * <div align="center">
32 * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
33 * <tr> <td> mrpt::opengl::CMesh3D </td> <td> \image html preview_CMesh3D.png </td> </tr>
34 * </table>
35 * </div>
36 *
37 * \ingroup mrpt_opengl_grp
38 */
40 {
42
43 typedef int f_verts[4];
44 typedef float coord3D[3];
45
46 protected:
47
48 bool m_enableTransparency;
49 bool m_antiAliasing;
50 bool m_showEdges;
51 bool m_showFaces;
52 bool m_showVertices;
53 bool m_computeNormals;
54 float m_lineWidth;
55 float m_pointSize;
56
57 //Data
58 unsigned int m_num_verts; //!< Number of vertices of the mesh
59 unsigned int m_num_faces; //!< Number of faces of the mesh
60 bool *m_is_quad; //!< Pointer storing whether a face is a quad (1) or a triangle (0)
61 f_verts *m_face_verts; //!< Pointer storing the vertices that compose each face. Size: 4 x num_faces (4 for the possible max number - quad)
62 coord3D *m_vert_coords; //!< Pointer storing the coordinates of the vertices. Size: 3 x num_vertices
63 coord3D *m_normals; //!< Pointer storing the face normals. Size: 3 x num_faces
64
65 //Colors
66 float edge_color[4]; //!< Color of the edges (when shown)
67 float face_color[4]; //!< Color of the faces (when shown)
68 float vert_color[4]; //!< Color of the vertices (when shown)
69 mrpt::utils::TColormap m_colorMap; //Not used yet. I leave it here in case I want to use it in the future
70
71 public:
72
73 void enableTransparency(bool v) { m_enableTransparency = v; CRenderizableDisplayList::notifyChange(); }
74 void enableAntiAliasing(bool v) { m_antiAliasing = v; CRenderizableDisplayList::notifyChange(); }
75 void enableShowEdges(bool v) { m_showEdges = v; CRenderizableDisplayList::notifyChange(); }
76 void enableShowFaces(bool v) { m_showFaces = v; CRenderizableDisplayList::notifyChange(); }
77 void enableShowVertices(bool v) { m_showVertices = v; CRenderizableDisplayList::notifyChange(); }
78 void enableFaceNormals(bool v) { m_computeNormals = v; CRenderizableDisplayList::notifyChange(); }
79
80 /** Load a 3D mesh. The arguments indicate:
81 - num_verts: Number of vertices of the mesh
82 - num_faces: Number of faces of the mesh
83 - verts_per_face: An array (pointer) with the number of vertices of each face. The elements must be set either to 3 (triangle) or 4 (quad).
84 - face_verts: An array (pointer) with the vertices of each face. The vertices of each face must be consecutive in this array.
85 - vert_coords: An array (pointer) with the coordinates of each vertex. The xyz coordinates of each vertex must be consecutive in this array.
86 */
87 void loadMesh(unsigned int num_verts, unsigned int num_faces, int *verts_per_face, int *face_verts, float *vert_coords);
88
89 /** Load a 3D mesh. The arguments indicate:
90 - num_verts: Number of vertices of the mesh
91 - num_faces: Number of faces of the mesh
92 - is_quad: A binary array (Eigen) saying whether the face is a quad (1) or a triangle (0)
93 - face_verts: An array (Eigen) with the vertices of each face. For every column (face), each row contains the num of a vertex. The fourth does not need
94 to be filled if the face is a triangle.
95 - vert_coords: An array (Eigen) with the coordinates of each vertex. For every column (vertex), each row contains the xyz coordinates of the vertex.
96 */
97 void loadMesh(unsigned int num_verts, unsigned int num_faces, const Array<bool, 1, Dynamic> &is_quad, const Array<int, 4, Dynamic> &face_verts, const Array<float, 3, Dynamic> &vert_coords);
98
99 void setEdgeColor(float r, float g, float b, float a = 1.f);
100 void setFaceColor(float r, float g, float b, float a = 1.f);
101 void setVertColor(float r, float g, float b, float a = 1.f);
102 void setLineWidth(float lw) { m_lineWidth = lw; }
103 void setPointSize(float ps) { m_pointSize = ps; }
104
105
106 /** Class factory
107 */
108 static CMesh3DPtr Create(bool enableTransparency, bool enableShowEdges, bool enableShowFaces, bool enableShowVertices);
109
110 /** Render
111 */
113
114 /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent.
115 */
116 void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
117
118
119 private:
120 /** Constructor
121 */
122 CMesh3D(bool enableTransparency = false, bool antiAliasing = false, bool enableShowEdges = true, bool enableShowFaces = true, bool enableShowVertices = false) :
123 m_enableTransparency(enableTransparency),
124 m_antiAliasing(antiAliasing),
125 m_showEdges(enableShowEdges),
126 m_showFaces(enableShowFaces),
127 m_showVertices(enableShowVertices),
128 m_computeNormals(true),
129 m_lineWidth( 2.f ),
130 m_pointSize( 6.f ),
131 m_colorMap( mrpt::utils::cmJET )
132 {
133 m_color.R = 1.f; m_color.G = 0.f; m_color.B = 0.f; m_color.A = 1.f;
134 edge_color[0] = 0.9f; edge_color[1] = 0.9f; edge_color[2] = 0.9f; edge_color[3] = 1.f;
135 face_color[0] = 0.7f; face_color[1] = 0.7f; face_color[2] = 0.8f; face_color[3] = 1.f;
136 vert_color[0] = 0.3f; vert_color[1] = 0.3f; vert_color[2] = 0.3f; vert_color[3] = 1.f;
137 m_num_faces = 0;
138 m_num_verts = 0;
139 }
140 /** Private, virtual destructor: only can be deleted from smart pointers
141 */
142 virtual ~CMesh3D() { }
143
144 };
145 DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CMesh3D, CRenderizableDisplayList, OPENGL_IMPEXP )
146
147 } // end namespace
148
149} // End of namespace
150
151#endif
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
A 3D mesh composed of Triangles and/or Quads.
Definition: CMesh3D.h:40
void enableShowVertices(bool v)
Definition: CMesh3D.h:77
void loadMesh(unsigned int num_verts, unsigned int num_faces, const Array< bool, 1, Dynamic > &is_quad, const Array< int, 4, Dynamic > &face_verts, const Array< float, 3, Dynamic > &vert_coords)
Load a 3D mesh.
void setLineWidth(float lw)
Definition: CMesh3D.h:102
void loadMesh(unsigned int num_verts, unsigned int num_faces, int *verts_per_face, int *face_verts, float *vert_coords)
Load a 3D mesh.
void enableShowFaces(bool v)
Definition: CMesh3D.h:76
void enableFaceNormals(bool v)
Definition: CMesh3D.h:78
void setEdgeColor(float r, float g, float b, float a=1.f)
void enableShowEdges(bool v)
Definition: CMesh3D.h:75
void setFaceColor(float r, float g, float b, float a=1.f)
static CMesh3DPtr Create(bool enableTransparency, bool enableShowEdges, bool enableShowFaces, bool enableShowVertices)
Class factory.
virtual ~CMesh3D()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CMesh3D.h:142
void render_dl() const MRPT_OVERRIDE
Render.
void setVertColor(float r, float g, float b, float a=1.f)
void enableAntiAliasing(bool v)
Definition: CMesh3D.h:74
void setPointSize(float ps)
Definition: CMesh3D.h:103
A renderizable object suitable for rendering with OpenGL's display lists.
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28
struct OPENGL_IMPEXP CMesh3DPtr
Definition: CMesh3D.h:25
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.5 for MRPT 1.4.0 SVN: at Sun Dec 25 21:25:12 UTC 2022