Fade2D Documentation pages v2.16.7
Delaunay Features
Fade_2D.h
Go to the documentation of this file.
1 // Copyright (C) Geom Software e.U, Bernhard Kornberger, Graz/Austria
2 //
3 // This file is part of the Fade2D library. The student license is free
4 // of charge and covers personal non-commercial research. Licensees
5 // holding a commercial license may use this file in accordance with
6 // the Commercial License Agreement.
7 //
8 // This software is provided AS IS with NO WARRANTY OF ANY KIND,
9 // INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
10 // FOR A PARTICULAR PURPOSE.
11 //
12 // Please contact the author if any conditions of this licensing are
13 // not clear to you.
14 //
15 // Author: Bernhard Kornberger, bkorn (at) geom.at
16 // http://www.geom.at
17 
18 
23 #pragma once
24 
25 #include "common.h"
26 #include "freeFunctions.h"
27 #ifndef FADE2D_EXPORT
28  #include "License.h"
29 #endif
30 #include "Point2.h"
31 #include "Triangle2.h"
33 #include "Visualizer2.h"
34 #include "VtkWriter.h"
35 #include "Zone2.h"
36 #include "ConstraintGraph2.h"
37 #include "Performance.h"
38 #include "MeshGenParams.h"
39 #include "MsgBase.h"
40 #include "SegmentChecker.h"
41 #include "testDataGenerators.h"
42 #include "FadeExport.h"
43 #include "Voronoi2.h"
44 #include "PolygonClipper.h"
45 
46 #if GEOM_PSEUDO3D==GEOM_TRUE
47  #include "IsoContours.h"
48  #include "EfficientModel.h"
49  #include "CutAndFill.h"
50  #include "Visualizer3.h"
51  #include "CloudPrepare.h"
52 #endif
53 
54 
55 
56 #if GEOM_PSEUDO3D==GEOM_TRUE
57  namespace GEOM_FADE25D {
58 #elif GEOM_PSEUDO3D==GEOM_FALSE
59  namespace GEOM_FADE2D {
60 #else
61  #error GEOM_PSEUDO3D is not defined
62 #endif
63 
64 
65 
66 class Dt2; // Forward
67 class Visualizer3; // Forward
68 
69 
121 class CLASS_DECLSPEC Fade_2D
122 {
123 public:
129  explicit Fade_2D(unsigned numExpectedVertices=3);
130 
140 Fade_2D(Fade_2D& other,std::vector<Zone2*> vZoneIn=std::vector<Zone2*>(),std::vector<Zone2*> vZoneOut=std::vector<Zone2*>());
141 
144 
160  bool saveTriangulation(const char* filename,std::vector<Zone2*>& vSaveZones);
161 
162 
178  bool saveTriangulation(std::ostream& stream,std::vector<Zone2*>& vSaveZones);
179 
204  bool saveZones(const char* filename,std::vector<Zone2*>& vSaveZones);
205 
206 
231  bool saveZones(std::ostream& stream,std::vector<Zone2*>& vSaveZones);
232 
233 
234 
249  bool load(const char* filename,std::vector<Zone2*>& vZones);
250 
251 
266  bool load(std::istream& stream,std::vector<Zone2*>& vZones);
267 
268 
286  void exportTriangulation(FadeExport& fadeExport,bool bWithCustomIndices,bool bClear);
287 
305  bool checkValidity(bool bCheckEmptyCircleProperty,const char* msg) const;
306 
307 
315  int setNumCPU(int numCPU);
316 
317 
336 
337 
353  void setFastMode(bool bFast);
354 
355 
360  void statistics(const char* s) const;
361 
374  void show(const char* filename,bool bWithConstraints=true) const;
375 
376 
394  void show(Visualizer2* pVis,bool bWithConstraints=true) const;
395 
396 
409  void showVtk(const char* filename,VtkColor color,VtkColor constraintColor=VTK_TRANSPARENT) const;
410 
426  void showVtk(VtkWriter* pVtkWriter,VtkColor color,VtkColor constraintColor=VTK_TRANSPARENT) const;
427 
428 
429 #if GEOM_PSEUDO3D==GEOM_TRUE
440  void showGeomview(const char* filename, const char* color="1 1 1 0.5") const;
441 
452  void showGeomview(Visualizer3* pVis, const char* color="1 1 1 0.5") const;
453 #endif
454 
462  void remove(Point2* pVertex);
463 
471  void remove(std::vector<Point2*>& vPoints);
472 
473 
478  void reset();
479 
489  void getConvexHull(bool bAllVertices,std::vector<Point2*>& vConvexHullPointsOut);
490 
491 #if GEOM_PSEUDO3D==GEOM_TRUE
516  void insert(CloudPrepare* pCloudPrepare,bool bClear=true);
517 #endif
518 
519 
535  Point2* insert(const Point2& p);
536 
545  void insert(const std::vector<Point2>& vInputPoints);
546 
547 
548 
564  void insert(const std::vector<Point2>& vInputPoints,std::vector<Point2*>& vHandles);
565 
566 #if GEOM_PSEUDO3D==GEOM_TRUE
579 #else
592 #endif
593  void insert(int numPoints,double * aCoordinates,Point2 ** aHandles);
594 
595 
596 
610  double measureTriangulationTime(const std::vector<Point2>& vPoints);
611 
612 
613 
614 
636  Triangle2* locate(const Point2& p);
637 
638 
650 
651 #if GEOM_PSEUDO3D==GEOM_TRUE
652 
672  bool getHeight(double x,double y,double& heightOut,Triangle2* pApproxT=NULL,double tolerance=0) const;
673 #endif
674 
691  void refine( Zone2* pZone,
692  double minAngleDegree,
693  double minEdgeLength,
694  double maxEdgeLength,
695  bool bAllowConstraintSplitting
696  );
697 
734  void refineAdvanced(MeshGenParams* pParameters);
735 
736 
737 
738 
739 
740 
752  size_t numberOfPoints() const;
753 
760  size_t numberOfTriangles() const;
761 
762 
770  void getTrianglePointers(std::vector<Triangle2*>& vAllTriangles) const;
771 
783 void getVertexPointers(std::vector<Point2*>& vAllPoints) const;
784 
795 
814 
815 
828  bool hasArea() const;
829 
835  bool is2D() const;
836 
849 
850 #if GEOM_PSEUDO3D==GEOM_TRUE
857  double getMedianEdgeLength25D();
858 #endif
859 
860 
916 #if GEOM_PSEUDO3D==GEOM_TRUE
917  ConstraintGraph2* createConstraint(
918  std::vector<Segment2>& vSegments,
919  ConstraintInsertionStrategy cis=CIS_CONSTRAINED_DELAUNAY,
920  bool bOrientedSegments=false,
921  bool bUseHeightOfLatest=false
922  );
923 #else
925  std::vector<Segment2>& vSegments,
927  bool bOrientedSegments=false
928  );
929 #endif
930 
931 
932 
933 
934 
957  Zone2* createZone(ConstraintGraph2* pConstraintGraph,ZoneLocation zoneLoc,bool bVerbose=true);
958 
959 #if GEOM_PSEUDO3D==GEOM_TRUE
981  Zone2* getPeeledZone(double angleThreshold,bool bAvoidSplit);
982 #endif
983 
984 
1001  Zone2* createZone(const std::vector<ConstraintGraph2*>& vConstraintGraphs,ZoneLocation zoneLoc,const Point2& startPoint,bool bVerbose=true);
1002 
1003 
1020  Zone2* createZone(ConstraintGraph2* pConstraintGraph,ZoneLocation zoneLoc,const Point2& startPoint,bool bVerbose=true);
1021 
1022 
1035  Zone2* createZone( std::vector<Triangle2*>& vTriangles,bool bVerbose=true );
1036 
1037 
1038 
1051  void deleteZone(Zone2* pZone);
1052 
1053 
1074 
1088 
1089 
1102  bool isConstraint(Triangle2* pT,int ith) const;
1103 
1112 void getAliveConstraintSegments(std::vector<ConstraintSegment2*>& vAliveConstraintSegments) const;
1113 
1116  void getAliveAndDeadConstraintSegments(std::vector<ConstraintSegment2*>& vAllConstraintSegments) const;
1117 
1127 
1138  void getIncidentTriangles(Point2* pVtx,std::vector<Triangle2*>& vIncidentT) const;
1139 
1140 
1151  void getIncidentVertices(Point2* pVtx,std::vector<Point2*>& vAdjVtx) const;
1152 
1153 
1162  void writeObj(const char* filename) const;
1163 
1164 #ifndef SKIPTHREADS
1165 #if GEOM_PSEUDO3D==GEOM_TRUE
1166 
1178  bool writePly(const char* filename,bool bASCII=false) const;
1179 
1180 
1192  bool writePly(std::ostream& os,bool bASCII=false) const;
1193 #endif
1194 #endif
1195 
1196 
1205  void writeObj(const char* filename,Zone2* pZone) const;
1206 
1213  void writeWebScene(const char* path) const;
1214 
1223 void writeWebScene(const char* path,Zone2* pZone) const;
1224 
1225 
1233 void subscribe(MsgType msgType,MsgBase* pMsg);
1234 
1235 
1236 
1244 void unsubscribe(MsgType msgType,MsgBase* pMsg);
1245 
1256  bool isConstraint(Point2* p0,Point2* p1) const;
1257 
1267  bool isConstraint(Point2* pVtx) const;
1268 
1270  void printLicense() const;
1271 
1273  bool checkZoneQuality(Zone2* pZone,double minAngle,const char* name,const AcceptExperimentalFeature& accept);
1275  void setName(const char* s);
1277  std::string getName() const;
1278 
1279 
1303  Zone2* importTriangles( std::vector<Point2>& vPoints,
1304  bool bReorientIfNeeded,
1305  bool bCreateExtendedBoundingBox
1306  );
1307 
1308 
1330  Zone2* importTriangles_robust(std::vector<Point2>& vPoints);
1331 
1332 #ifndef SKIPTHREADS
1333 #if GEOM_PSEUDO3D==GEOM_TRUE
1346  Zone2* importTrianglesFromPly(const char* filename);
1347 
1360  Zone2* importTrianglesFromPly(std::istream& is);
1361 #endif
1362 #endif
1363 
1373 Orientation2 getOrientation(const Point2& p0,const Point2& p1,const Point2& p2);
1374 
1405  void cutTriangles( const Point2& knifeStart,
1406  const Point2& knifeEnd,
1407  bool bTurnEdgesIntoConstraints);
1408 
1421  void cutTriangles( std::vector<Segment2>& vSegments,
1422  bool bTurnEdgesIntoConstraints);
1423 
1424 
1432 Zone2* createZone_cookieCutter(std::vector<Segment2>& vSegments,bool bProtectEdges);
1433  void getZones(std::vector<Zone2*>& vZones) const;
1442 
1443 
1451  Zone2* createZone_cookieCutter( std::vector<Segment2>& vSegments,
1452  bool bProtectEdges,
1453  ConstraintGraph2*& pProtectedEdgesCG,
1454  ConstraintGraph2*& pBoundaryCG);
1455 
1456 
1477  Zone2* createZone_cookieCutter2( std::vector<Segment2>& vSegments,
1478  bool bProtectEdges,
1479  ConstraintGraph2*& pProtectedEdgesCG,
1480  ConstraintGraph2*& pBoundaryCG);
1499  Zone2* createZone_cookieCutter2( std::vector<Segment2>& vSegments,
1500  bool bProtectEdges);
1501 
1544 #if GEOM_PSEUDO3D==GEOM_TRUE
1545  bool drape( std::vector<Segment2>& vSegmentsIn,
1546  std::vector<Segment2>& vSegmentsOut,
1547  double zTolerance,
1548  double offTolerance=0.0,
1549  bool bKeepOffSegments=false) const;
1550 #else
1551  bool drape( std::vector<Segment2>& vSegmentsIn,
1552  std::vector<Segment2>& vSegmentsOut,
1553  double offTolerance=0.0,
1554  bool bKeepOffSegments=false) const;
1555 #endif
1556 
1557 
1558 
1559 
1565 void getDirectedEdges(std::vector<Edge2>& vDirectedEdgesOut) const;
1566 
1573 void getUndirectedEdges(std::vector<Edge2>& vUndirectedEdgesOut) const;
1574 
1576  /* Deprecated: Use setNumCPU() instead. This method is kept for
1577  * compatibility with existing applications. Internally it calls
1578  * setNumCPU(0) to automatically determine and use the number of
1579  * available CPU cores.
1580  */
1581  void enableMultithreading();
1582  // Development functions, not for public use
1584  void internal(int au,int fu,const char* s="");
1586  Dt2* getImpl();
1588  void setDev(const char* s,int ival,double dval);
1589 
1590 protected:
1592  void initFade(unsigned numExpectedVertices);
1594  Fade_2D& operator=(const Fade_2D&); // No assignment allowed
1596  Dt2* pImpl;
1597 }; // end of class
1598 
1599 
1607 inline void copyFade(Fade_2D& dt0,std::vector<Zone2*>& vZones0,Fade_2D& dt1,std::vector<Zone2*>& vZones1)
1608 {
1609  std::stringstream ss;
1610  dt0.saveTriangulation(ss,vZones0);
1611  dt1.load(ss,vZones1);
1612 }
1613 
1614 
1615 
1616 
1617 } // (namespace)
1618 
ConstraintInsertionStrategy
Enum defining the available strategies for inserting constraints.
Definition: ConstraintSegment2.h:44
void copyFade(Fade_2D &dt0, std::vector< Zone2 * > &vZones0, Fade_2D &dt1, std::vector< Zone2 * > &vZones1)
Copy a Fade_2D object and selected Zone2 objects.
Definition: Fade_2D.h:1607
MsgType
Message types for the message system.
Definition: MsgBase.h:40
VtkColor
Enumeration of colors used by the VTKWriter class to represent various colors in the VTK file format.
Definition: VtkWriter.h:39
A 2D axis-aligned bounding box.
Definition: Bbox2.h:39
A constraint graph is a collection of constraint edges (ConstraintSegment2).
Definition: ConstraintGraph2.h:56
A ConstraintSegment2 represents a constraint edge between two vertices of a Delaunay triangulation.
Definition: ConstraintSegment2.h:71
Fade_2D is a class that contains a Delaunay triangulation.
Definition: Fade_2D.h:122
Triangle2 * getAdjacentTriangle(Point2 *p0, Point2 *p1) const
Get the adjacent triangle of an oriented edge.
void insert(const std::vector< Point2 > &vInputPoints, std::vector< Point2 * > &vHandles)
Insert points from a std::vector<Point2> and store pointers in vHandles.
bool drape(std::vector< Segment2 > &vSegmentsIn, std::vector< Segment2 > &vSegmentsOut, double offTolerance=0.0, bool bKeepOffSegments=false) const
Drape segments onto a surface.
void unsubscribe(MsgType msgType, MsgBase *pMsg)
Unregisters a message receiver.
int setNumCPU(int numCPU)
Set the number of CPU cores for multithreading (deprecated)
void setFastMode(bool bFast)
Set fast mode.
void getIncidentVertices(Point2 *pVtx, std::vector< Point2 * > &vAdjVtx) const
Get adjacent vertices.
void show(const char *filename, bool bWithConstraints=true) const
Draws the triangulation as a PostScript or PDF file.
void getConvexHull(bool bAllVertices, std::vector< Point2 * > &vConvexHullPointsOut)
Compute the convex hull.
void subscribe(MsgType msgType, MsgBase *pMsg)
Registers a message receiver.
bool hasArea() const
Check if the triangulation contains any triangles.
Zone2 * importTriangles_robust(std::vector< Point2 > &vPoints)
Import Triangles - Robust (Error-tolerant version)
Orientation2 getOrientation(const Point2 &p0, const Point2 &p1, const Point2 &p2)
Compute the orientation of 3 points.
void show(Visualizer2 *pVis, bool bWithConstraints=true) const
Draws the triangulation as a PostScript or PDF file.
void getUndirectedEdges(std::vector< Edge2 > &vUndirectedEdgesOut) const
Get undirected edges.
ConstraintGraph2 * createConstraint(std::vector< Segment2 > &vSegments, ConstraintInsertionStrategy cis, bool bOrientedSegments=false)
Insert constraint edges (edges, polyline or polygon) .
void insert(const std::vector< Point2 > &vInputPoints)
Insert a vector of points.
double measureTriangulationTime(const std::vector< Point2 > &vPoints)
Measure the Delaunay triangulation time.
Zone2 * createZone(ConstraintGraph2 *pConstraintGraph, ZoneLocation zoneLoc, const Point2 &startPoint, bool bVerbose=true)
Create a Zone2 bounded by a ConstraintGraph2 object by growing from a seed point.
void writeWebScene(const char *path, Zone2 *pZone) const
Create a scene of a Zone2 that can be viewed in a web browser.
void writeObj(const char *filename, Zone2 *pZone) const
Write a Zone2 an .obj file.
bool load(std::istream &stream, std::vector< Zone2 * > &vZones)
Load a triangulation from a binary file.
void getVertexPointers(std::vector< Point2 * > &vAllPoints) const
Get pointers to all vertices.
void writeObj(const char *filename) const
Write the current triangulation to an .obj file.
Bbox2 computeBoundingBox() const
Computes the axis-aligned bounding box of the triangulation.
Zone2 * createZone(const std::vector< ConstraintGraph2 * > &vConstraintGraphs, ZoneLocation zoneLoc, const Point2 &startPoint, bool bVerbose=true)
Create a Zone2 bounded by multiple ConstraintGraph2 objects by growing from a seed point.
void getTrianglePointers(std::vector< Triangle2 * > &vAllTriangles) const
Get pointers to all triangles.
Fade_2D(Fade_2D &other, std::vector< Zone2 * > vZoneIn=std::vector< Zone2 * >(), std::vector< Zone2 * > vZoneOut=std::vector< Zone2 * >())
Copy constructor.
void showVtk(VtkWriter *pVtkWriter, VtkColor color, VtkColor constraintColor=VTK_TRANSPARENT) const
Draws the triangulation using the VTK file format.
Point2 * insert(const Point2 &p)
Insert a single point.
void printLicense() const
Prints license information.
Fade_2D(unsigned numExpectedVertices=3)
Constructor of the triangulation class.
ConstraintSegment2 * getConstraintSegment(Point2 *p0, Point2 *p1) const
Retrieve a ConstraintSegment2.
void remove(Point2 *pVertex)
Remove a single vertex.
void getIncidentTriangles(Point2 *pVtx, std::vector< Triangle2 * > &vIncidentT) const
Get incident triangles.
bool saveTriangulation(const char *filename, std::vector< Zone2 * > &vSaveZones)
Save a triangulation to a binary file.
Zone2 * createZone(ConstraintGraph2 *pConstraintGraph, ZoneLocation zoneLoc, bool bVerbose=true)
Create a Zone2 .
Voronoi2 * getVoronoiDiagram()
Get the Voronoi diagram of the triangulation.
Point2 * getNearestNeighbor(const Point2 &p)
Get nearest neighbor.
bool saveZones(std::ostream &stream, std::vector< Zone2 * > &vSaveZones)
Save zones to a binary file.
bool saveTriangulation(std::ostream &stream, std::vector< Zone2 * > &vSaveZones)
Save a triangulation to a binary file.
void applyConstraintsAndZones()
Apply conforming constraints and zones (deprecated!)
void reset()
Reset the triangulation.
size_t numberOfPoints() const
Number of points.
~Fade_2D()
Destructor.
Zone2 * createZone_cookieCutter(std::vector< Segment2 > &vSegments, bool bProtectEdges, ConstraintGraph2 *&pProtectedEdgesCG, ConstraintGraph2 *&pBoundaryCG)
Cookie Cutter (deprecated)
void getAliveAndDeadConstraintSegments(std::vector< ConstraintSegment2 * > &vAllConstraintSegments) const
Get all (alive and dead) constraint segments.
void getDirectedEdges(std::vector< Edge2 > &vDirectedEdgesOut) const
Get directed edges Edges are counterclockwise oriented around their triangle. The present method retu...
double getMedianEdgeLength2D()
Get the median 2D edge length.
void refineAdvanced(MeshGenParams *pParameters)
Delaunay refinement and grid meshing.
bool isConstraint(Point2 *pVtx) const
Check if a vertex is a constraint vertex.
bool load(const char *filename, std::vector< Zone2 * > &vZones)
Load a triangulation from a binary file.
Zone2 * createZone_cookieCutter2(std::vector< Segment2 > &vSegments, bool bProtectEdges)
Cookie Cutter2.
void cutTriangles(const Point2 &knifeStart, const Point2 &knifeEnd, bool bTurnEdgesIntoConstraints)
Cut through a triangulation.
void exportTriangulation(FadeExport &fadeExport, bool bWithCustomIndices, bool bClear)
Export triangulation data.
void statistics(const char *s) const
Statistics.
Point2 * getVertexPointer(const Point2 &p)
Get vertex pointer.
void getAliveConstraintSegments(std::vector< ConstraintSegment2 * > &vAliveConstraintSegments) const
Get active (alive) constraint segments.
void refine(Zone2 *pZone, double minAngleDegree, double minEdgeLength, double maxEdgeLength, bool bAllowConstraintSplitting)
Delaunay refinement.
void cutTriangles(std::vector< Segment2 > &vSegments, bool bTurnEdgesIntoConstraints)
Cut through a triangulation.
bool checkValidity(bool bCheckEmptyCircleProperty, const char *msg) const
Checks the validity of the triangulation.
Zone2 * createZone_cookieCutter(std::vector< Segment2 > &vSegments, bool bProtectEdges)
Cookie Cutter (deprecated)
bool saveZones(const char *filename, std::vector< Zone2 * > &vSaveZones)
Save zones to a binary file.
bool isConstraint(Triangle2 *pT, int ith) const
Check if an edge is a constraint edge.
bool isConstraint(Point2 *p0, Point2 *p1) const
Check if an edge is a constraint edge.
void writeWebScene(const char *path) const
Create a scene of a triangulation that can be viewed in a web browser.
void remove(std::vector< Point2 * > &vPoints)
Remove vertices.
void insert(int numPoints, double *aCoordinates, Point2 **aHandles)
Insert points from an array.
void showVtk(const char *filename, VtkColor color, VtkColor constraintColor=VTK_TRANSPARENT) const
Draws the triangulation using the VTK file format.
Zone2 * importTriangles(std::vector< Point2 > &vPoints, bool bReorientIfNeeded, bool bCreateExtendedBoundingBox)
Import Triangles (deprecated in favor of the robust version)
Zone2 * createZone_cookieCutter2(std::vector< Segment2 > &vSegments, bool bProtectEdges, ConstraintGraph2 *&pProtectedEdgesCG, ConstraintGraph2 *&pBoundaryCG)
Cookie Cutter2.
size_t numberOfTriangles() const
Number of triangles.
void deleteZone(Zone2 *pZone)
Delete a Zone2 object.
Zone2 * createZone(std::vector< Triangle2 * > &vTriangles, bool bVerbose=true)
Create a Zone2 defined by a vector of triangles.
Triangle2 * locate(const Point2 &p)
Locate a triangle that contains p.
Parameters for the mesh generator.
Definition: MeshGenParams.h:59
MsgBase, a base class for message subscriber classes.
Definition: MsgBase.h:55
Represents a 2D point.
Definition: Point2.h:61
Represents a triangle in a triangulation.
Definition: Triangle2.h:59
A PDF and Postscript Writer for 2D Visualization.
Definition: Visualizer2.h:60
Voronoi diagram.
Definition: Voronoi2.h:63
A class for writing data to the VTK file format for visualization purposes.
Definition: VtkWriter.h:76
Represents a defined area within a triangulation.
Definition: Zone2.h:82
FadeExport is a simple struct to export triangulation data.
Definition: FadeExport.h:49