DGtal 1.4.0
Loading...
Searching...
No Matches
TriangulatedSurface.h
1
17#pragma once
18
31#if defined(TriangulatedSurface_RECURSES)
32#error Recursive header files inclusion detected in TriangulatedSurface.h
33#else // defined(TriangulatedSurface_RECURSES)
35#define TriangulatedSurface_RECURSES
36
37#if !defined TriangulatedSurface_h
39#define TriangulatedSurface_h
40
42// Inclusions
43#include <iostream>
44#include <set>
45#include <map>
46#include "DGtal/base/Common.h"
47#include "DGtal/base/OwningOrAliasingPtr.h"
48#include "DGtal/base/IntegerSequenceIterator.h"
49#include "DGtal/topology/HalfEdgeDataStructure.h"
51
52namespace DGtal
53{
54
56 // template class TriangulatedSurface
84 template <typename TPoint>
86 {
87 public:
88 typedef TPoint Point;
96 typedef std::vector<Point> PositionsStorage;
97 typedef std::vector<Triangle> TriangleStorage;
98
99 // Required by CUndirectedSimpleLocalGraph
101 typedef std::set<Vertex> VertexSet;
102 template <typename Value> struct VertexMap {
103 typedef typename std::map<Vertex, Value> Type;
104 };
105
106 // Required by CUndirectedSimpleGraph
109
110 // Required for CCombinatorialSurface
113 typedef std::vector<Arc> ArcRange;
114 typedef std::vector<Face> FaceRange;
115 typedef std::vector<Vertex> VertexRange;
116
118
127 template <typename TData>
130 typedef TData Data;
131 typedef std::vector<Data> Storage;
132
135
140 IndexedPropertyMap( const Self& aSurface, Size s, Data def_data = Data() )
141 : mySurface( &aSurface ),
142 myData( Storage( s, def_data ) )
143 {}
144
152 IndexedPropertyMap( const Self& aSurface,
153 Storage& aStorage )
154 : mySurface( &aSurface ),
155 myData( &aStorage, false )
156 {}
157
159 const Self& surface() const
160 {
161 ASSERT( isValid() );
162 return *mySurface;
163 }
164
168 const Data& operator()( Argument v ) const
169 {
170 ASSERT( isValid() && v < myData->size() );
171 return (*myData)[ v ];
172 }
173
177 const Data& operator[]( Argument v ) const
178 {
179 ASSERT( isValid() && v < myData->size() );
180 return (*myData)[ v ];
181 }
182
187 {
188 ASSERT( isValid() && v < myData->size() );
189 return (*myData)[ v ];
190 }
191
193 bool isValid() const { return mySurface != 0; }
194
196 Size size() const { return myData->size(); }
197
199 Storage& storage() { return *myData; }
200
202 const Storage& storage() const { return *myData; }
203
204 private:
209 };
210
212
213 protected:
215
216 // ----------------------- Standard services ------------------------------
217 public:
218
223
228
230 void clear();
231
238 bool build();
239
243 VertexIndex addVertex( const Point& vdata );
244
248
252
255 const HalfEdgeDataStructure& heds() const { return myHEDS; }
256
257 // ------------------------- standard services ------------------------------
258 public:
260 Size nbArcs() const { return myHEDS.nbHalfEdges(); }
261
263 Size nbVertices() const { return myHEDS.nbVertices(); }
264
266 Size nbEdges() const { return myHEDS.nbEdges(); }
267
269 Size nbFaces() const { return myHEDS.nbFaces(); }
270
274 long Euler() const { return myHEDS.Euler(); }
275
279 {
280 return PositionsMap( *this, myPositions );
281 }
282
284 template <typename AnyData>
289
292 template <typename AnyData>
294 {
295 return IndexedPropertyMap< AnyData >( *this, nbVertices(), value );
296 }
297
299 template <typename AnyData>
304
307 template <typename AnyData>
309 {
310 return IndexedPropertyMap< AnyData >( *this, nbEdges(), value );
311 }
312
314 template <typename AnyData>
319
322 template <typename AnyData>
324 {
325 return IndexedPropertyMap< AnyData >( *this, nbFaces(), value );
326 }
327
335 const Point& position( Vertex v ) const;
336
337 // ----------------------- Undirected simple graph services -------------------------
338 public:
342 Size size() const;
343
351
357 Size degree( const Vertex & v ) const;
358
370 template <typename OutputIterator>
371 void
372 writeNeighbors( OutputIterator &it ,
373 const Vertex & v ) const;
374
391 template <typename OutputIterator, typename VertexPredicate>
392 void
393 writeNeighbors( OutputIterator &it ,
394 const Vertex & v,
395 const VertexPredicate & pred) const;
396
399 { return ConstIterator( 0 ); }
400
403 { return ConstIterator( nbVertices() ); }
404
405 // ----------------------- CombinatorialSurface --------------------------
406 public:
407
412 ArcRange outArcs( const Vertex & v ) const;
413
418 ArcRange inArcs( const Vertex & v ) const;
419
425
430 Vertex head( const Arc & a ) const;
431
436 Vertex tail( const Arc & a ) const;
437
442 Arc opposite( const Arc & a ) const;
443
450 Arc next( const Arc & a ) const;
451
459 Arc arc( const Vertex & t, const Vertex & h ) const;
460
471 Face faceAroundArc( const Arc & a ) const;
472
481 FaceRange facesAroundArc( const Arc & a ) const;
482
493
503 ArcRange arcsAroundFace( const Face & f ) const;
504
510 bool isVertexBoundary( const Vertex& v ) const;
511
518 bool isArcBoundary( const Arc& v ) const;
519
535
544
553
567
568 // ----------------------- Other services ---------------------------------
569 public:
570
580 bool isFlippable( const Arc a ) const;
581
593 void flip( const Arc a );
594
607 Vertex split( const Arc a, const Point& data );
608
617 bool isMergeable( const Arc a ) const;
618
640 Vertex merge( const Arc a, const Point& data );
641
642 // ----------------------- Interface --------------------------------------
643 public:
644
649 void selfDisplay ( std::ostream & out ) const;
650
655 bool isValid() const;
656
657 // ------------------------- Protected Datas ------------------------------
658 protected:
667
668 // ------------------------- Private Datas --------------------------------
669 private:
670
671 // ------------------------- Hidden services ------------------------------
672 protected:
673
674 private:
675
676 // ------------------------- Internals ------------------------------------
677 private:
678
679 }; // end of class TriangulatedSurface
680
681
688 template <typename TPoint>
689 std::ostream&
690 operator<< ( std::ostream & out, const TriangulatedSurface<TPoint> & object );
691
692} // namespace DGtal
693
694
696// Includes inline functions.
697#include "DGtal/shapes/TriangulatedSurface.ih"
698
699// //
701
702#endif // !defined TriangulatedSurface_h
703
704#undef TriangulatedSurface_RECURSES
705#endif // else defined(TriangulatedSurface_RECURSES)
Aim: This class represents an half-edge data structure, which is a structure for representing the top...
Index HalfEdgeIndex
The type used for numbering half-edges (alias)
Index FaceIndex
The type for numbering faces.
Index EdgeIndex
The type for numbering edges.
std::size_t Index
The type used for numbering half-edges (an offset an the half-edges structure).
Index VertexIndex
The type for numbering vertices.
std::size_t Size
The type for counting elements.
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it,...
Aim: This class describes a smart pointer that is, given the constructor called by the user,...
Aim: Represents a triangulated surface. The topology is stored with a half-edge data structure....
void selfDisplay(std::ostream &out) const
Size degree(const Vertex &v) const
VertexRange verticesOfFacesAroundArc(const Arc a) const
VertexRange allBoundaryVertices() const
HalfEdgeDataStructure::HalfEdgeIndex Arc
void clear()
Clears everything.
void writeNeighbors(OutputIterator &it, const Vertex &v) const
std::vector< Vertex > VertexRange
HalfEdgeDataStructure::FaceIndex Face
Vertex head(const Arc &a) const
bool isFlippable(const Arc a) const
Arc arc(const Vertex &t, const Vertex &h) const
TriangleStorage myTriangles
Stores the triangles.
ArcRange arcsAroundFace(const Face &f) const
HalfEdgeDataStructure myHEDS
The half-edge data structure that stores the topology of the mesh.
ArcRange allBoundaryArcs() const
HalfEdgeDataStructure::VertexIndex VertexIndex
const HalfEdgeDataStructure & heds() const
IntegerSequenceIterator< VertexIndex > ConstIterator
BOOST_STATIC_CONSTANT(Face, INVALID_FACE=HALF_EDGE_INVALID_INDEX)
IndexedPropertyMap< AnyData > makeFaceMap() const
IndexedPropertyMap< AnyData > makeVertexMap(AnyData value) const
FaceRange facesAroundVertex(const Vertex &v) const
Vertex merge(const Arc a, const Point &data)
ArcRange allArcs() const
FaceRange allFaces() const
IndexedPropertyMap< AnyData > makeEdgeMap() const
PositionsStorage myPositions
Stores the information for each Vertex.
std::vector< Point > PositionsStorage
void flip(const Arc a)
Arc opposite(const Arc &a) const
HalfEdgeDataStructure::Index Index
VertexRange allVertices() const
VertexIndex addVertex(const Point &vdata)
HalfEdgeDataStructure::Triangle Triangle
void writeNeighbors(OutputIterator &it, const Vertex &v, const VertexPredicate &pred) const
Vertex tail(const Arc &a) const
HalfEdgeDataStructure::EdgeIndex EdgeIndex
bool isMergeable(const Arc a) const
HalfEdgeDataStructure & heds()
Arc next(const Arc &a) const
ArcRange outArcs(const Vertex &v) const
HalfEdgeDataStructure::HalfEdge HalfEdge
FaceIndex addTriangle(VertexIndex v0, VertexIndex v1, VertexIndex v2)
bool isHEDSValid
Indicates if the half-edge structure has been created/updated.
bool isArcBoundary(const Arc &v) const
IndexedPropertyMap< AnyData > makeFaceMap(AnyData value) const
std::vector< Triangle > TriangleStorage
IndexedPropertyMap< AnyData > makeVertexMap() const
VertexRange verticesAroundFace(const Face &f) const
ArcRange inArcs(const Vertex &v) const
bool isVertexBoundary(const Vertex &v) const
HalfEdgeDataStructure::Size Size
Point & position(Vertex v)
IndexedPropertyMap< Point > PositionsMap
IndexedPropertyMap< AnyData > makeEdgeMap(AnyData value) const
FaceRange facesAroundArc(const Arc &a) const
const Point & position(Vertex v) const
HalfEdgeDataStructure::FaceIndex FaceIndex
Face faceAroundArc(const Arc &a) const
TriangulatedSurface< TPoint > Self
Vertex split(const Arc a, const Point &data)
DGtal is the top-level namespace which contains all DGtal functions and types.
static std::size_t const HALF_EDGE_INVALID_INDEX
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Represents an unoriented triangle as three vertices.
const Self * mySurface
The associated polygonal surface.
IndexedPropertyMap()
Default constructor. The object is invalid.
OwningOrAliasingPtr< Storage > myData
An owned or aliased pointer to the vector of data.
IndexedPropertyMap(const Self &aSurface, Storage &aStorage)
IndexedPropertyMap(const Self &aSurface, Size s, Data def_data=Data())