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 namespace Imagine {
19 
22  {
23  CONSTANT_COLOR,
24  FACE_COLOR,
25  VERTEX_COLOR,
26  FACE_VALUE,
27  VERTEX_VALUE
28  };
29 
32  {
33  FLAT_SHADING,
34  SMOOTH_SHADING
35  };
36 
39  {
40  POINT,
41  LINE,
42  FILL
43  };
44 
46  enum MeshData
47  {
48  VERTEX,
49  TRIANGLE,
50  QUAD
51  };
52 
53  // ====================================================================== //
54 #ifndef DOXYGEN_SHOULD_SKIP_THIS
55  class MeshInternal; // Private
56 #endif
57 
58  class Mesh;
100  void showMesh(const Mesh& M, bool reinitCam=true);
112  void hideMesh(const Mesh& M, bool reinitCam=true);
113 
120  class Mesh
121  {
122 #ifndef DOXYGEN_SHOULD_SKIP_THIS
123  MeshInternal* priv;
124  int *count;
125  void kill();
126  public:
127  bool operator<(const Mesh& mesh) const; // To put them in a std::set
128  void drawMesh(MeshFaceMode front=FILL, MeshFaceMode back=POINT) const;
129  FloatPoint3 sum(int& nvertices) const;
130  float spread(const FloatPoint3& center) const;
131 #endif
132  public: /* constructor & destructor */
135  Mesh();
156  Mesh(const FloatPoint3* vertices, int nvertices,
157  const Triangle* triangles=0, int ntriangles=0,
158  const Quad* quads=0, int nquads=0,
159  MeshColorMode colorMode=CONSTANT_COLOR,
160  MeshShadingMode shadingMode=SMOOTH_SHADING,
161  const FloatVector3* normals=0);
182  Mesh(const DoublePoint3 *vertices, int nvertices,
183  const Triangle* triangles=0, int ntriangles=0,
184  const Quad *quads=0, int nquads=0,
185  MeshColorMode colorMode=CONSTANT_COLOR,
186  MeshShadingMode shadingMode=SMOOTH_SHADING,
187  const DoubleVector3* normals=0);
200  Mesh(const std::vector<FloatPoint3>& vertices,
201  const std::vector<Triangle>& triangles=std::vector<Triangle>(),
202  const std::vector<Quad>& quads=std::vector<Quad>(),
203  MeshColorMode colorMode=CONSTANT_COLOR,
204  MeshShadingMode shadingMode=SMOOTH_SHADING,
205  const std::vector<FloatVector3>& normals=std::vector<FloatVector3>());
209  Mesh(const Mesh&);
211  ~Mesh();
212 
218  friend bool readMeshFromObjFile(Mesh& mesh,const std::string& fileName);
219 
223  Mesh& operator=(const Mesh&);
224 
228  bool operator==(const Mesh& mesh) const { return (count==mesh.count); }
232  bool operator!=(const Mesh& mesh) const { return !operator==(mesh); }
233 
234  friend void showMesh(const Mesh& M, bool reinitCam);
235  friend void hideMesh(const Mesh& M, bool reinitCam);
236 
237  public: /* Accessors */
246  void setVertices(const FloatPoint3 *vertices,
247  const FloatVector3 *normals=0);
256  void setVertices(const DoublePoint3 *vertices,
257  const DoubleVector3 *normals=0);
259  const std::vector<FloatPoint3>& vertices() const;
273  void setGeometry(const FloatPoint3 *vertices, int nvertices,
274  const Triangle *triangles=0, int ntriangles=0,
275  const Quad *quads=0, int nquads=0,
276  const FloatVector3 *normals=0);
290  void setGeometry(const DoublePoint3 *vertices, int nvertices,
291  const Triangle *triangles=0, int ntriangles=0,
292  const Quad *quads=0, int nquads=0,
293  const DoubleVector3 *normals=0);
294 
295 
303  void setColor(Color col);
312  void setColors(MeshData data, const Color *col);
327  void setRange(float v0, float v1);
336  void setValues(MeshData data, const float *val);
343  void setDefaultLookupTable();
353  void setLookupTable(Color col0, Color col1);
354 
361  void setOpacity(float opacity);
363  float getOpacity() const;
364 
365  /* Static Convenience Functions*/
366 
377  static Mesh Arrow(const DoublePoint3 &base, const DoubleVector3 &shaft,
378  double r, int resolution=32);
389  static Mesh Cone(const DoublePoint3 &base, const DoubleVector3 &axis,
390  double r, int resolution=32);
399  static Mesh Cube(const DoublePoint3&center, const DoubleVector3&axis1,
400  const DoubleVector3&axis2, const DoubleVector3&axis3);
411  static Mesh Cylinder(const DoublePoint3 &center,
412  const DoubleVector3&axis, double r, int res=32);
421  static Mesh Plane(const DoublePoint3&center,
422  const DoubleVector3&axis1, const DoubleVector3&axis2);
431  static Mesh PointCloud(const DoublePoint3 *points, int n);
441  static Mesh PolyLine(DoublePoint3 *points, int n, bool closed);
451  static Mesh Sphere(const DoublePoint3 &center, double r, int res=24);
452  };
453 
455 } /* namespace Imagine */
456 
457 #endif /* IMAGINE_GRAPHICS_MESH_H */
458 
459 #endif
static Mesh Cube(const DoublePoint3 &center, const DoubleVector3 &axis1, const DoubleVector3 &axis2, const DoubleVector3 &axis3)
Parallelepiped.
const std::vector< FloatPoint3 > & vertices() const
Get points.
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.
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:31
void setDefaultLookupTable()
Default LUT.
static Mesh Plane(const DoublePoint3 &center, const DoubleVector3 &axis1, const DoubleVector3 &axis2)
Parallelogram.
MeshFaceMode
Mesh display mode.
Definition: Mesh.h:38
Mesh & operator=(const Mesh &)
Assignment operator.
Array of fixed size.
Definition: FArray.h:17
float getOpacity() const
Get opacity (from 0=transparent to 1=opaque).
void setColors(MeshData data, const Color *col)
Set colors.
A mesh representing a 3D object.
Definition: Mesh.h:120
void setLookupTable(Color col0, Color col1)
Set LUT.
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:46
bool operator==(const Mesh &mesh) const
Comparison operator.
Definition: Mesh.h:228
MeshColorMode
Mesh lighting mode.
Definition: Mesh.h:21
Imagine++ namespace.
Definition: Array.h:7
RED GREEN BLUE color.
Definition: Color.h:26
bool operator!=(const Mesh &mesh) const
Comparison operator.
Definition: Mesh.h:232
friend void showMesh(const Mesh &M, bool reinitCam)
Show mesh.
void showMesh(const Mesh &M, bool reinitCam=true)
Show mesh.