DGtal  0.9.2
Mesh.h
1 
17 #pragma once
18 
31 #if defined(Mesh_RECURSES)
32 #error Recursive header files inclusion detected in Mesh.h
33 #else // defined(Mesh_RECURSES)
34 
35 #define Mesh_RECURSES
36 
37 #if !defined Mesh_h
38 
39 #define Mesh_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <vector>
45 #include "DGtal/base/Common.h"
46 #include "DGtal/kernel/PointVector.h"
47 #include "DGtal/io/Color.h"
49 
50 namespace DGtal
51 {
52 
53 
55  // template class Mesh
90  template <typename TPoint >
91  class Mesh
92  {
93 
94 
95  // ----------------------- associated types ------------------------------
96  public:
97 
98 
102  typedef TPoint Point;
103 
104 
105 
110 
111 
116  typedef std::vector<unsigned int> MeshFace;
117 
118 
122  typedef std::vector<TPoint> VertexStorage;
123 
127  typedef std::vector<MeshFace> FaceStorage;
128 
132  typedef std::vector<DGtal::Color> ColorStorage;
133 
134 
138  typedef typename VertexStorage::const_iterator ConstIterator;
139 
143  typedef typename VertexStorage::iterator Iterator;
144 
145 
146 
147 
148  // ----------------------- Standard services ------------------------------
149  public:
157  Mesh(bool saveFaceColor=false);
158 
165  Mesh(const DGtal::Color &aColor);
166 
172  Mesh(const std::vector<TPoint> &vertexSet);
173 
177  ~Mesh();
178 
183  Mesh ( const Mesh & other );
184 
190  Mesh & operator= ( const Mesh & other );
191 
192 
193 
194  // --------------- CDrawableWithDisplay3D realization -------------------
195  public:
196 
200  std::string className() const;
201 
202 
203 
204 
205  // ----------------------- Interface --------------------------------------
206  public:
207 
208 
213  void addVertex(const TPoint &vertex);
214 
215 
216 
229  void addTriangularFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3,
230  const DGtal::Color &aColor=DGtal::Color::White);
231 
232 
246  void addQuadFace(unsigned int indexVertex1, unsigned int indexVertex2,
247  unsigned int indexVertex3, unsigned int indexVertex4,
248  const DGtal::Color & aColor=DGtal::Color::White);
249 
250 
259  void addFace(const MeshFace &aFace, const DGtal::Color &aColor=DGtal::Color::White);
260 
261 
268  void removeFaces(const std::vector<unsigned int> &facesIndex);
269 
270 
275  const TPoint & getVertex(unsigned int i) const;
276 
281  TPoint & getVertex(unsigned int i);
282 
283 
284 
289  const MeshFace & getFace(unsigned int i) const;
290 
291 
296  RealPoint getFaceBarycenter(unsigned int i) const;
297 
298 
299 
304  MeshFace & getFace(unsigned int i);
305 
306 
307 
313  const Color & getFaceColor(unsigned int i) const;
314 
315 
316 
320  std::pair<TPoint, TPoint> getBoundingBox() const;
321 
322 
335  void setFaceColor(unsigned int i, const DGtal::Color &aColor) ;
336 
337 
342  bool isStoringFaceColors() const;
343 
344 
349  ConstIterator
350  vertexBegin() const {
351  return myVertexList.begin();
352  }
353 
354 
359  ConstIterator
360  vertexEnd() const {
361  return myVertexList.end();
362  }
363 
364 
369  Iterator
371  return myVertexList.begin();
372  }
373 
374 
375 
380  Iterator
382  return myVertexList.end();
383  }
384 
385 
386 
392  FaceStorage::const_iterator
393  faceBegin() const {
394  return myFaceList.begin();
395  }
396 
397 
398 
404  FaceStorage::const_iterator
405  faceEnd() const {
406  return myFaceList.end();
407  }
408 
409 
415  FaceStorage::iterator
417  return myFaceList.begin();
418  }
419 
420 
421 
427  FaceStorage::iterator
429  return myFaceList.end();
430  }
431 
432 
433 
438  unsigned int nbFaces() const;
439 
444  unsigned int nbVertex() const;
445 
446 
447 
452  void invertVertexFaceOrder();
453 
457  void clearFaces();
458 
463  void changeScale(const double aScale);
464 
470  double subDivideTriangularFaces(const double minArea);
471 
476  unsigned int quadToTriangularFaces();
477 
482  void selfDisplay ( std::ostream & out ) const;
483 
488  bool isValid() const;
489 
490  // ------------------------- Protected Datas ------------------------------
491  private:
492 
493 
494 
495 
496 
497 
498  // ------------------------- Private Datas --------------------------------
499  private:
500  FaceStorage myFaceList;
501  VertexStorage myVertexList;
502  ColorStorage myFaceColorList;
505 
506 
507 
508 
509 
510  // ------------------------- Mesh generation ------------------------------
511 
512  public:
513 
528  static
529  void
530  createTubularMesh(Mesh<TPoint> &aMesh, const std::vector<TPoint> &aSkeleton, const double aRadius,
531  const double angleStep = 0.2, const DGtal::Color &aMeshColor = DGtal::Color::White );
532 
533 
534 
549  static
550  void
551  createTubularMesh(Mesh<TPoint> &aMesh, const std::vector<TPoint> &aSkeleton, const std::vector<double> &aVectOfRadius,
552  const double angleStep = 0.2, const DGtal::Color &aMeshColor = DGtal::Color::White );
553 
554 
555 
570  template <typename TValue>
571  static
572  void
573  createMeshFromHeightSequence(Mesh<TPoint> &aMesh, const std::vector<TValue> & anValueSequence,
574  const unsigned int lengthSequence,
575  double stepX, double stepY, double stepZ,
576  const DGtal::Color &aMeshColor = DGtal::Color::White );
577 
578 
579 
580 
581 
582 
583 
584 
585 
586  // ------------------------- Internals ------------------------------------
587  private:
588 
589  struct CompPoints
590  {
591  CompPoints(typename TPoint::Dimension d): myDim(d){};
592  bool operator() (const TPoint &p1, const TPoint &p2){return p1[myDim]<p2[myDim];};
593  typename TPoint::Dimension myDim;
594  };
595 
596 
597 
598 
599 
600 
601 
602 
603  }; // end of class Mesh
604 
605 
612  template <typename TPoint>
613  std::ostream&
614  operator<< ( std::ostream & out, const Mesh<TPoint> & object );
615 
616 
617 
618 } // namespace DGtal
619 
620 
622 // Includes inline functions.
623 #include "DGtal/shapes/Mesh.ih"
624 
625 // //
627 
628 #endif // !defined Mesh_h
629 
630 #undef Mesh_RECURSES
631 #endif // else defined(Mesh_RECURSES)
ConstIterator vertexEnd() const
Definition: Mesh.h:360
std::vector< TPoint > VertexStorage
Definition: Mesh.h:122
std::vector< unsigned int > MeshFace
Definition: Mesh.h:116
void changeScale(const double aScale)
const Color & getFaceColor(unsigned int i) const
FaceStorage::const_iterator faceBegin() const
Definition: Mesh.h:393
void addQuadFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, unsigned int indexVertex4, const DGtal::Color &aColor=DGtal::Color::White)
void removeFaces(const std::vector< unsigned int > &facesIndex)
VertexStorage myVertexList
Definition: Mesh.h:501
std::vector< DGtal::Color > ColorStorage
Definition: Mesh.h:132
VertexStorage::const_iterator ConstIterator
Definition: Mesh.h:138
const MeshFace & getFace(unsigned int i) const
Aim: This class is defined to represent a surface mesh through a set of vertices and faces...
Definition: Mesh.h:91
TPoint Point
Definition: Mesh.h:102
TPoint::Dimension myDim
Definition: Mesh.h:592
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
bool isValid() const
Iterator vertexBegin()
Definition: Mesh.h:370
void selfDisplay(std::ostream &out) const
RealPoint getFaceBarycenter(unsigned int i) const
static void createMeshFromHeightSequence(Mesh< TPoint > &aMesh, const std::vector< TValue > &anValueSequence, const unsigned int lengthSequence, double stepX, double stepY, double stepZ, const DGtal::Color &aMeshColor=DGtal::Color::White)
bool operator()(const TPoint &p1, const TPoint &p2)
Definition: Mesh.h:592
unsigned int nbVertex() const
void addVertex(const TPoint &vertex)
ColorStorage myFaceColorList
Definition: Mesh.h:502
unsigned int nbFaces() const
VertexStorage::iterator Iterator
Definition: Mesh.h:143
ConstIterator vertexBegin() const
Definition: Mesh.h:350
void clearFaces()
FaceStorage myFaceList
Definition: Mesh.h:500
void addTriangularFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, const DGtal::Color &aColor=DGtal::Color::White)
std::string className() const
std::vector< MeshFace > FaceStorage
Definition: Mesh.h:127
FaceStorage::iterator faceEnd()
Definition: Mesh.h:428
DGtal is the top-level namespace which contains all DGtal functions and types.
void setFaceColor(unsigned int i, const DGtal::Color &aColor)
Mesh(bool saveFaceColor=false)
CompPoints(typename TPoint::Dimension d)
Definition: Mesh.h:591
bool isStoringFaceColors() const
unsigned int quadToTriangularFaces()
FaceStorage::const_iterator faceEnd() const
Definition: Mesh.h:405
std::pair< TPoint, TPoint > getBoundingBox() const
bool mySaveFaceColor
Definition: Mesh.h:503
void addFace(const MeshFace &aFace, const DGtal::Color &aColor=DGtal::Color::White)
DGtal::PointVector< TPoint::dimension, double > RealPoint
Definition: Mesh.h:109
const TPoint & getVertex(unsigned int i) const
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
static const Color White
Definition: Color.h:390
void invertVertexFaceOrder()
static void createTubularMesh(Mesh< TPoint > &aMesh, const std::vector< TPoint > &aSkeleton, const double aRadius, const double angleStep=0.2, const DGtal::Color &aMeshColor=DGtal::Color::White)
Iterator vertexEnd()
Definition: Mesh.h:381
FaceStorage::iterator faceBegin()
Definition: Mesh.h:416
DGtal::Color myDefaultColor
Definition: Mesh.h:504
double subDivideTriangularFaces(const double minArea)
Mesh & operator=(const Mesh &other)