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
16class QOpenGLShaderProgram;
17
18namespace 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
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 */
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&);
243
249 friend bool readMeshFromObjFile(Mesh& mesh,const std::string& fileName);
250
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 */
278 const FloatVector3 *normals=0);
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);
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
Array of fixed size.
Definition: FArray.h:17
Vector of fixed size.
Definition: FVector.h:17
A mesh representing a 3D object.
Definition: Mesh.h:151
friend void hideMesh(const Mesh &M, bool reinitCam)
Hide mesh.
Mesh(const DoublePoint3 *vertices, int nvertices, const Triangle *triangles=0, int ntriangles=0, const Quad *quads=0, int nquads=0, MeshColorMode colorMode=CONSTANT_COLOR, MeshShadingMode shadingMode=SMOOTH_SHADING, const DoubleVector3 *normals=0)
Constructor (double).
Mesh()
Empty constructor.
static Mesh Sphere(const DoublePoint3 &center, double r, int res=24)
Sphere.
void setValues(MeshData data, const float *val)
Set values.
void setColors(MeshData data, const Color *col)
Set colors.
const std::vector< FloatPoint3 > & vertices() const
Get points.
void setColor(Color col)
Set color.
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).
void setVertices(const FloatPoint3 *vertices, const FloatVector3 *normals=0)
Set points (float).
void setDefaultLookupTable()
Default LUT.
Mesh(const std::vector< FloatPoint3 > &vertices, const std::vector< Triangle > &triangles=std::vector< Triangle >(), const std::vector< Quad > &quads=std::vector< Quad >(), MeshColorMode colorMode=CONSTANT_COLOR, MeshShadingMode shadingMode=SMOOTH_SHADING, const std::vector< FloatVector3 > &normals=std::vector< FloatVector3 >())
Constructor (float vectors).
static Mesh Cone(const DoublePoint3 &base, const DoubleVector3 &axis, double r, int resolution=32)
Cone.
void setLookupTable(Color col0, Color col1)
Set LUT.
~Mesh()
Destructor.
static Mesh PolyLine(DoublePoint3 *points, int n, bool closed)
PolyLine.
float getOpacity() const
Get opacity (from 0=transparent to 1=opaque).
friend bool readMeshFromObjFile(Mesh &mesh, const std::string &fileName)
Read mesh from Wavefront OBJ file.
void setVertices(const DoublePoint3 *vertices, const DoubleVector3 *normals=0)
Set points (double).
static Mesh PointCloud(const DoublePoint3 *points, int n)
PointCloud.
static Mesh Cylinder(const DoublePoint3 &center, const DoubleVector3 &axis, double r, int res=32)
Cylinder.
Mesh(const Mesh &)
Copy constructor.
bool operator==(const Mesh &mesh) const
Comparison operator.
Definition: Mesh.h:259
Mesh & operator=(const Mesh &)
Assignment operator.
static Mesh Arrow(const DoublePoint3 &base, const DoubleVector3 &shaft, double r, int resolution=32)
Arrow.
void setGeometry(const DoublePoint3 *vertices, int nvertices, const Triangle *triangles=0, int ntriangles=0, const Quad *quads=0, int nquads=0, const DoubleVector3 *normals=0)
Set geometry (double).
Mesh(const FloatPoint3 *vertices, int nvertices, const Triangle *triangles=0, int ntriangles=0, const Quad *quads=0, int nquads=0, MeshColorMode colorMode=CONSTANT_COLOR, MeshShadingMode shadingMode=SMOOTH_SHADING, const FloatVector3 *normals=0)
Constructor (float).
void setOpacity(float opacity)
Set opacity.
static Mesh Cube(const DoublePoint3 &center, const DoubleVector3 &axis1, const DoubleVector3 &axis2, const DoubleVector3 &axis3)
Parallelepiped.
friend void showMesh(const Mesh &M, bool reinitCam)
Show mesh.
static Mesh Plane(const DoublePoint3 &center, const DoubleVector3 &axis1, const DoubleVector3 &axis2)
Parallelogram.
void setRange(float v0, float v1)
Default LUT.
bool operator!=(const Mesh &mesh) const
Comparison operator.
Definition: Mesh.h:263
RED GREEN BLUE color.
Definition: Color.h:26
void hideMesh(const Mesh &M, bool reinitCam=true)
Hide mesh.
void showMesh(const Mesh &M, bool reinitCam=true)
Show mesh.
MeshFaceMode
Mesh display mode.
Definition: Mesh.h:41
MeshData
Type of mesh data that holds values.
Definition: Mesh.h:49
MeshShadingMode
Mesh shading mode.
Definition: Mesh.h:34
MeshColorMode
Mesh lighting mode.
Definition: Mesh.h:24
Imagine++ namespace.