DGtal  0.9.4.1
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 
148  typedef typename std::size_t Size;
149 
150 
151 
152  // ----------------------- Standard services ------------------------------
153  public:
161  Mesh(bool saveFaceColor=false);
162 
169  Mesh(const DGtal::Color &aColor);
170 
176  Mesh(const std::vector<TPoint> &vertexSet);
177 
181  ~Mesh();
182 
187  Mesh ( const Mesh & other );
188 
194  Mesh & operator= ( const Mesh & other );
195 
196 
197 
198  // --------------- CDrawableWithDisplay3D realization -------------------
199  public:
200 
204  std::string className() const;
205 
206 
207 
208 
209  // ----------------------- Interface --------------------------------------
210  public:
211 
212 
217  void addVertex(const TPoint &vertex);
218 
219 
220 
233  void addTriangularFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3,
234  const DGtal::Color &aColor=DGtal::Color::White);
235 
236 
250  void addQuadFace(unsigned int indexVertex1, unsigned int indexVertex2,
251  unsigned int indexVertex3, unsigned int indexVertex4,
252  const DGtal::Color & aColor=DGtal::Color::White);
253 
254 
263  void addFace(const MeshFace &aFace, const DGtal::Color &aColor=DGtal::Color::White);
264 
265 
272  void removeFaces(const std::vector<unsigned int> &facesIndex);
273 
274 
279  const TPoint & getVertex(unsigned int i) const;
280 
285  TPoint & getVertex(unsigned int i);
286 
287 
288 
293  const MeshFace & getFace(unsigned int i) const;
294 
295 
300  RealPoint getFaceBarycenter(unsigned int i) const;
301 
302 
303 
308  MeshFace & getFace(unsigned int i);
309 
310 
311 
317  const Color & getFaceColor(unsigned int i) const;
318 
319 
320 
324  std::pair<TPoint, TPoint> getBoundingBox() const;
325 
326 
339  void setFaceColor(unsigned int i, const DGtal::Color &aColor) ;
340 
341 
346  bool isStoringFaceColors() const;
347 
348 
354  vertexBegin() const {
355  return myVertexList.begin();
356  }
357 
358 
364  vertexEnd() const {
365  return myVertexList.end();
366  }
367 
368 
373  Iterator
375  return myVertexList.begin();
376  }
377 
378 
379 
384  Iterator
386  return myVertexList.end();
387  }
388 
389 
390 
396  FaceStorage::const_iterator
397  faceBegin() const {
398  return myFaceList.begin();
399  }
400 
401 
402 
408  FaceStorage::const_iterator
409  faceEnd() const {
410  return myFaceList.end();
411  }
412 
413 
419  FaceStorage::iterator
421  return myFaceList.begin();
422  }
423 
424 
425 
431  FaceStorage::iterator
433  return myFaceList.end();
434  }
435 
436 
437 
442  Size nbFaces() const;
443 
448  Size nbVertex() const;
449 
450 
451 
456  void invertVertexFaceOrder();
457 
461  void clearFaces();
462 
467  void changeScale(const double aScale);
468 
474  double subDivideTriangularFaces(const double minArea);
475 
480  unsigned int quadToTriangularFaces();
481 
486  void selfDisplay ( std::ostream & out ) const;
487 
492  bool isValid() const;
493 
494  // ------------------------- Protected Datas ------------------------------
495  private:
496 
497 
498 
499 
500 
501 
502  // ------------------------- Private Datas --------------------------------
503  private:
509 
510 
511 
512 
513 
514  // ------------------------- Mesh generation ------------------------------
515 
516  public:
517 
532  static
533  void
534  createTubularMesh(Mesh<TPoint> &aMesh, const std::vector<TPoint> &aSkeleton, const double aRadius,
535  const double angleStep = 0.2, const DGtal::Color &aMeshColor = DGtal::Color::White );
536 
537 
538 
553  static
554  void
555  createTubularMesh(Mesh<TPoint> &aMesh, const std::vector<TPoint> &aSkeleton, const std::vector<double> &aVectOfRadius,
556  const double angleStep = 0.2, const DGtal::Color &aMeshColor = DGtal::Color::White );
557 
577  template <typename TValue>
578  static
579  void
580  createMeshFromHeightSequence(Mesh<TPoint> &aMesh, const std::vector<TValue> & anValueSequence,
581  const unsigned int lengthSequence,
582  double stepX, double stepY, double stepZ,
583  const DGtal::Color &aMeshColor = DGtal::Color::White );
584 
585 
586 
587 
588 
589 
590 
591 
592 
593  // ------------------------- Internals ------------------------------------
594  private:
595 
596  struct CompPoints
597  {
598  CompPoints(typename TPoint::Dimension d): myDim(d){};
599  bool operator() (const TPoint &p1, const TPoint &p2){return p1[myDim]<p2[myDim];};
600  typename TPoint::Dimension myDim;
601  };
602 
603 
604 
605 
606 
607 
608 
609 
610  }; // end of class Mesh
611 
612 
619  template <typename TPoint>
620  std::ostream&
621  operator<< ( std::ostream & out, const Mesh<TPoint> & object );
622 
623 
624 
625 } // namespace DGtal
626 
627 
629 // Includes inline functions.
630 #include "DGtal/shapes/Mesh.ih"
631 
632 // //
634 
635 #endif // !defined Mesh_h
636 
637 #undef Mesh_RECURSES
638 #endif // else defined(Mesh_RECURSES)
std::vector< TPoint > VertexStorage
Definition: Mesh.h:122
std::vector< unsigned int > MeshFace
Definition: Mesh.h:116
void changeScale(const double aScale)
Size nbVertex() const
MyDigitalSurface::ConstIterator ConstIterator
bool isValid() const
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:505
std::vector< DGtal::Color > ColorStorage
Definition: Mesh.h:132
VertexStorage::const_iterator ConstIterator
Definition: Mesh.h:138
Aim: This class is defined to represent a surface mesh through a set of vertices and faces...
Definition: Mesh.h:91
FaceStorage::const_iterator faceEnd() const
Definition: Mesh.h:409
TPoint Point
Definition: Mesh.h:102
TPoint::Dimension myDim
Definition: Mesh.h:599
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
void selfDisplay(std::ostream &out) const
Iterator vertexBegin()
Definition: Mesh.h:374
ConstIterator vertexBegin() const
Definition: Mesh.h:354
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:599
const TPoint & getVertex(unsigned int i) const
Size nbFaces() const
std::size_t Size
Definition: Mesh.h:148
void addVertex(const TPoint &vertex)
bool isStoringFaceColors() const
ColorStorage myFaceColorList
Definition: Mesh.h:506
VertexStorage::iterator Iterator
Definition: Mesh.h:143
const Color & getFaceColor(unsigned int i) const
std::pair< TPoint, TPoint > getBoundingBox() const
void clearFaces()
FaceStorage myFaceList
Definition: Mesh.h:504
void addTriangularFace(unsigned int indexVertex1, unsigned int indexVertex2, unsigned int indexVertex3, const DGtal::Color &aColor=DGtal::Color::White)
std::vector< MeshFace > FaceStorage
Definition: Mesh.h:127
FaceStorage::iterator faceEnd()
Definition: Mesh.h:432
ConstIterator vertexEnd() const
Definition: Mesh.h:364
DGtal is the top-level namespace which contains all DGtal functions and types.
FaceStorage::const_iterator faceBegin() const
Definition: Mesh.h:397
const MeshFace & getFace(unsigned int i) const
void setFaceColor(unsigned int i, const DGtal::Color &aColor)
Mesh(bool saveFaceColor=false)
CompPoints(typename TPoint::Dimension d)
Definition: Mesh.h:598
RealPoint getFaceBarycenter(unsigned int i) const
unsigned int quadToTriangularFaces()
bool mySaveFaceColor
Definition: Mesh.h:507
void addFace(const MeshFace &aFace, const DGtal::Color &aColor=DGtal::Color::White)
DGtal::PointVector< TPoint::dimension, double > RealPoint
Definition: Mesh.h:109
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)
std::string className() const
Iterator vertexEnd()
Definition: Mesh.h:385
FaceStorage::iterator faceBegin()
Definition: Mesh.h:420
DGtal::Color myDefaultColor
Definition: Mesh.h:508
double subDivideTriangularFaces(const double minArea)
Mesh & operator=(const Mesh &other)