Main MRPT website > C++ reference for MRPT 1.5.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  // This must be added to any CSerializable derived class:
25  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CMesh3D, CRenderizableDisplayList, OPENGL_IMPEXP )
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  */
112  void render_dl() const MRPT_OVERRIDE;
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  CMesh3D(bool enableTransparency = false, bool antiAliasing = false, bool enableShowEdges = true, bool enableShowFaces = true, bool enableShowVertices = false);
122  /** Private, virtual destructor: only can be deleted from smart pointers */
123  virtual ~CMesh3D();
124 
125  };
127 
128  } // end namespace
129 
130 } // End of namespace
131 
132 #endif
void setLineWidth(float lw)
Definition: CMesh3D.h:102
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
TColormap
Different colormaps for use in mrpt::utils::colormap()
Definition: color_maps.h:30
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:103
A 3D mesh composed of Triangles and/or Quads.
Definition: CMesh3D.h:39
void enableShowEdges(bool v)
Definition: CMesh3D.h:75
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#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...
GLubyte g
Definition: glext.h:5575
GLubyte GLubyte b
Definition: glext.h:5575
void enableAntiAliasing(bool v)
Definition: CMesh3D.h:74
void enableFaceNormals(bool v)
Definition: CMesh3D.h:78
const GLdouble * v
Definition: glext.h:3603
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:3618
void enableShowFaces(bool v)
Definition: CMesh3D.h:76
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
GLubyte GLubyte GLubyte a
Definition: glext.h:5575
void enableShowVertices(bool v)
Definition: CMesh3D.h:77



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020