Imagine++
Mesh.h
1 // ===========================================================================
2 // Imagine++ Libraries
3 // Copyright (C) Imagine
4 // For detailed information: http://imagine.enpc.fr/software
5 // ===========================================================================
6 
7 #ifndef IMAGINE_GRAPHICS_MESH_H
8 #define IMAGINE_GRAPHICS_MESH_H
9 
10 #include "Types.h"
11 #include <vector>
12 #include <cstdlib>
13 
14 #ifdef IMAGINE_OPENGL
15 
16 class QOpenGLShaderProgram;
17 
18 namespace Imagine {
21 
24  {
25  CONSTANT_COLOR,
26  FACE_COLOR,
27  VERTEX_COLOR,
28  FACE_VALUE,
29  VERTEX_VALUE
30  };
31 
34  {
35  FLAT_SHADING,
36  SMOOTH_SHADING
37  };
38 
41  {
42  POINT,
43  LINE,
44  FILL
45  };
46 
48  enum MeshData
49  {
50  VERTEX,
51  TRIANGLE,
52  QUAD
53  };
54 
55  // ====================================================================== //
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57  class MeshInternal; // Private
58 #endif
59 
60  class Mesh;
102  void showMesh(const Mesh& M, bool reinitCam=true);
114  void hideMesh(const Mesh& M, bool reinitCam=true);
115 
150  class Mesh
151  {
152 #ifndef DOXYGEN_SHOULD_SKIP_THIS
153  MeshInternal* priv;
154  int *count;
155  void kill();
156  public:
157  bool operator<(const Mesh& mesh) const; // To put them in a std::set
158  void drawMesh(MeshFaceMode faceMode, QOpenGLShaderProgram* prog,
159  const FVector<float,4>& light) const;
160  FloatPoint3 sum(int& nvertices) const;
161  float spread(const FloatPoint3& center) const;
162 #endif
163  public: /* constructor & destructor */
166  Mesh();
187  Mesh(const FloatPoint3* vertices, int nvertices,
188  const Triangle* triangles=0, int ntriangles=0,
189  const Quad* quads=0, int nquads=0,
190  MeshColorMode colorMode=CONSTANT_COLOR,
191  MeshShadingMode shadingMode=SMOOTH_SHADING,
192  const FloatVector3* normals=0);
213  Mesh(const DoublePoint3 *vertices, int nvertices,
214  const Triangle* triangles=0, int ntriangles=0,
215  const Quad *quads=0, int nquads=0,
216  MeshColorMode colorMode=CONSTANT_COLOR,
217  MeshShadingMode shadingMode=SMOOTH_SHADING,
218  const DoubleVector3* normals=0);
231  Mesh(const std::vector<FloatPoint3>& vertices,
232  const std::vector<Triangle>& triangles=std::vector<Triangle>(),
233  const std::vector<Quad>& quads=std::vector<Quad>(),
234  MeshColorMode colorMode=CONSTANT_COLOR,
235  MeshShadingMode shadingMode=SMOOTH_SHADING,
236  const std::vector<FloatVector3>& normals=std::vector<FloatVector3>());
240  Mesh(const Mesh&);
242  ~Mesh();
243 
249  friend bool readMeshFromObjFile(Mesh& mesh,const std::string& fileName);
250 
254  Mesh& operator=(const Mesh&);
255 
259  bool operator==(const Mesh& mesh) const { return (count==mesh.count); }
263  bool operator!=(const Mesh& mesh) const { return !operator==(mesh); }
264 
265  friend void showMesh(const Mesh& M, bool reinitCam);
266  friend void hideMesh(const Mesh& M, bool reinitCam);
267 
268  public: /* Accessors */
277  void setVertices(const FloatPoint3 *vertices,
278  const FloatVector3 *normals=0);
287  void setVertices(const DoublePoint3 *vertices,
288  const DoubleVector3 *normals=0);
290  const std::vector<FloatPoint3>& vertices() const;
304  void setGeometry(const FloatPoint3 *vertices, int nvertices,
305  const Triangle *triangles=0, int ntriangles=0,
306  const Quad *quads=0, int nquads=0,
307  const FloatVector3 *normals=0);
321  void setGeometry(const DoublePoint3 *vertices, int nvertices,
322  const Triangle *triangles=0, int ntriangles=0,
323  const Quad *quads=0, int nquads=0,
324  const DoubleVector3 *normals=0);
325 
326 
334  void setColor(Color col);
343  void setColors(MeshData data, const Color *col);
358  void setRange(float v0, float v1);
367  void setValues(MeshData data, const float *val);
374  void setDefaultLookupTable();
384  void setLookupTable(Color col0, Color col1);
385 
392  void setOpacity(float opacity);
394  float getOpacity() const;
395 
396  /* Static Convenience Functions*/
397 
408  static Mesh Arrow(const DoublePoint3 &base, const DoubleVector3 &shaft,
409  double r, int resolution=32);
420  static Mesh Cone(const DoublePoint3 &base, const DoubleVector3 &axis,
421  double r, int resolution=32);
430  static Mesh Cube(const DoublePoint3&center, const DoubleVector3&axis1,
431  const DoubleVector3&axis2, const DoubleVector3&axis3);
442  static Mesh Cylinder(const DoublePoint3 &center,
443  const DoubleVector3&axis, double r, int res=32);
452  static Mesh Plane(const DoublePoint3&center,
453  const DoubleVector3&axis1, const DoubleVector3&axis2);
462  static Mesh PointCloud(const DoublePoint3 *points, int n);
472  static Mesh PolyLine(DoublePoint3 *points, int n, bool closed);
482  static Mesh Sphere(const DoublePoint3 &center, double r, int res=24);
483  };
484 
486 } /* namespace Imagine */
487 
488 #endif /* IMAGINE_GRAPHICS_MESH_H */
489 
490 #endif
static Mesh Cube(const DoublePoint3 &center, const DoubleVector3 &axis1, const DoubleVector3 &axis2, const DoubleVector3 &axis3)
Parallelepiped.
static Mesh Arrow(const DoublePoint3 &base, const DoubleVector3 &shaft, double r, int resolution=32)
Arrow.
void setValues(MeshData data, const float *val)
Set values.
Vector of fixed size.
Definition: FVector.h:17
friend void hideMesh(const Mesh &M, bool reinitCam)
Hide mesh.
void setGeometry(const FloatPoint3 *vertices, int nvertices, const Triangle *triangles=0, int ntriangles=0, const Quad *quads=0, int nquads=0, const FloatVector3 *normals=0)
Set geometry (float).
static Mesh Cylinder(const DoublePoint3 &center, const DoubleVector3 &axis, double r, int res=32)
Cylinder.
static Mesh Cone(const DoublePoint3 &base, const DoubleVector3 &axis, double r, int resolution=32)
Cone.
Mesh()
Empty constructor.
bool operator!=(const Mesh &mesh) const
Comparison operator.
Definition: Mesh.h:263
static Mesh PointCloud(const DoublePoint3 *points, int n)
PointCloud.
void setRange(float v0, float v1)
Default LUT.
void setOpacity(float opacity)
Set opacity.
void setVertices(const FloatPoint3 *vertices, const FloatVector3 *normals=0)
Set points (float).
void setColor(Color col)
Set color.
static Mesh Sphere(const DoublePoint3 &center, double r, int res=24)
Sphere.
~Mesh()
Destructor.
MeshShadingMode
Mesh shading mode.
Definition: Mesh.h:33
void setDefaultLookupTable()
Default LUT.
static Mesh Plane(const DoublePoint3 &center, const DoubleVector3 &axis1, const DoubleVector3 &axis2)
Parallelogram.
MeshFaceMode
Mesh display mode.
Definition: Mesh.h:40
float getOpacity() const
Get opacity (from 0=transparent to 1=opaque).
Mesh & operator=(const Mesh &)
Assignment operator.
Array of fixed size.
Definition: FArray.h:17
void setColors(MeshData data, const Color *col)
Set colors.
A mesh representing a 3D object.
Definition: Mesh.h:150
void setLookupTable(Color col0, Color col1)
Set LUT.
const std::vector< FloatPoint3 > & vertices() const
Get points.
bool operator==(const Mesh &mesh) const
Comparison operator.
Definition: Mesh.h:259
static Mesh PolyLine(DoublePoint3 *points, int n, bool closed)
PolyLine.
void hideMesh(const Mesh &M, bool reinitCam=true)
Hide mesh.
friend bool readMeshFromObjFile(Mesh &mesh, const std::string &fileName)
Read mesh from Wavefront OBJ file.
MeshData
Type of mesh data that holds values.
Definition: Mesh.h:48
MeshColorMode
Mesh lighting mode.
Definition: Mesh.h:23
Imagine++ namespace.
Definition: Array.h:7
RED GREEN BLUE color.
Definition: Color.h:26
friend void showMesh(const Mesh &M, bool reinitCam)
Show mesh.
void showMesh(const Mesh &M, bool reinitCam=true)
Show mesh.