Fade2D Documentation pages v1.97
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 
24 #pragma once
25 
26 #include "common.h"
27 #include "freeFunctions.h"
28 #ifndef FADE2D_EXPORT
29  #include "License.h"
30 #endif
31 #include "Point2.h"
32 #include "Triangle2.h"
34 #include "Visualizer2.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 
45 #if GEOM_PSEUDO3D==GEOM_TRUE
46  #include "IsoContours.h"
47  #include "EfficientModel.h"
48  #include "CutAndFill.h"
49  #include "CloudPrepare.h"
50 #endif
51 
52 
53 
54 #if GEOM_PSEUDO3D==GEOM_TRUE
55  namespace GEOM_FADE25D {
56 #elif GEOM_PSEUDO3D==GEOM_FALSE
57  namespace GEOM_FADE2D {
58 #else
59  #error GEOM_PSEUDO3D is not defined
60 #endif
61 
62 
63 
64 class Dt2; // Forward
65 class Visualizer3; // Forward
66 
67 
72 class CLASS_DECLSPEC Fade_2D
73 {
74 public:
81  explicit Fade_2D(unsigned numExpectedVertices=3)
82  {
83  initFade(numExpectedVertices);
84  }
87 
88 
89 
90 
108  bool saveTriangulation(const char* filename,std::vector<Zone2*>& vSaveZones);
109 
127  bool saveTriangulation(std::ostream& stream,std::vector<Zone2*>& vSaveZones);
128 
129 
152  bool saveZones(const char* filename,std::vector<Zone2*>& vSaveZones);
153 
154 
177  bool saveZones(std::ostream& stream,std::vector<Zone2*>& vSaveZones);
178 
179 
191  bool load(const char* filename,std::vector<Zone2*>& vZones);
192 
193 
205  bool load(std::istream& stream,std::vector<Zone2*>& vZones);
206 
207 
217  void exportTriangulation(FadeExport& fadeExport,bool bWithCustomIndices,bool bClear);
218 
219 
232  bool checkValidity(bool bCheckEmptyCircleProperty,const char* msg) const;
233 
255  int setNumCPU(int numCPU);
256 
263 
278  void setFastMode(bool bFast);
279 
280 
285  void statistics(const char* s) const;
286 
297  void show(const char* postscriptFilename,bool bWithConstraints=true) const;
298 
299 
312  void show(Visualizer2* pVis,bool bWithConstraints=true) const;
313 
314 #if GEOM_PSEUDO3D==GEOM_TRUE
322  void showGeomview(const char* filename, const char* color="1 1 1 0.5") const;
323 
331  void showGeomview(Visualizer3* pVis, const char* color="1 1 1 0.5") const;
332 
333 
334 #endif
335 
345  void remove(Point2* pVertex);
346 
347 
360  void getConvexHull(bool bAllVertices,std::vector<Point2*>& vConvexHullPointsOut);
361 
362 #if GEOM_PSEUDO3D==GEOM_TRUE
380  void insert(CloudPrepare* pCloudPrepare,bool bClear=true);
381 #endif
382 
396  Point2* insert(const Point2& p);
397 
406  void insert(const std::vector<Point2>& vInputPoints);
407 
422  void insert(const std::vector<Point2>& vInputPoints,std::vector<Point2*>& vHandles);
423 
424 #if GEOM_PSEUDO3D==GEOM_TRUE
433 #else
442 #endif
443  void insert(int numPoints,double * aCoordinates,Point2 ** aHandles);
444 
445 
462  double measureTriangulationTime(std::vector<Point2>& vPoints);
463 
464 
465 
480  Triangle2* locate(const Point2& p);
481 
482 
492 
493 #if GEOM_PSEUDO3D==GEOM_TRUE
519  bool getHeight(double x,double y,double& heightOut,Triangle2* pApproxT=NULL,double tolerance=0) const;
520 #endif
521 
537  void refine( Zone2* pZone,
538  double minAngleDegree,
539  double minEdgeLength,
540  double maxEdgeLength,
541  bool bAllowConstraintSplitting
542  );
543 
579  void refineAdvanced(MeshGenParams* pParameters);
580 
581 
582 
583 
584 
585 
595  size_t numberOfPoints() const;
596 
603  size_t numberOfTriangles() const;
604 
605 
617  void getTrianglePointers(std::vector<Triangle2*>& vAllTriangles) const;
618 
632  void getVertexPointers(std::vector<Point2*>& vAllPoints) const;
633 
634 
635 
646 
663  bool hasArea() const;
664 
670  bool is2D() const;
671 
672 
728 #if GEOM_PSEUDO3D==GEOM_TRUE
729  ConstraintGraph2* createConstraint(
730  std::vector<Segment2>& vSegments,
732  bool bOrientedSegments=false,
733  bool bUseHeightOfLatest=false
734  );
735 #else
737  std::vector<Segment2>& vSegments,
739  bool bOrientedSegments=false
740  );
741 #endif
742 
743 
744 
745 
746 
769  Zone2* createZone(ConstraintGraph2* pConstraintGraph,ZoneLocation zoneLoc,bool bVerbose=true);
770 
771 
783  Zone2* createZone(const std::vector<ConstraintGraph2*>& vConstraintGraphs,ZoneLocation zoneLoc,const Point2& startPoint,bool bVerbose=true);
784 
797  Zone2* createZone(ConstraintGraph2* pConstraintGraph,ZoneLocation zoneLoc,const Point2& startPoint,bool bVerbose=true);
798 
809  Zone2* createZone( std::vector<Triangle2*>& vTriangles,bool bVerbose=true );
810 
811 
812 
825  void deleteZone(Zone2* pZone);
826 
827 
848 
849 
857 
865  bool isConstraint(Triangle2* pT,int ith) const;
866 
869  void getAliveConstraintSegments(std::vector<ConstraintSegment2*>& vAliveConstraintSegments) const;
870 
873  void getAliveAndDeadConstraintSegments(std::vector<ConstraintSegment2*>& vAllConstraintSegments) const;
874 
883 
884 
889  void getIncidentTriangles(Point2* pVtx,std::vector<Triangle2*>& vIncidentT) const;
890 
895  void getIncidentVertices(Point2* pVtx,std::vector<Point2*>& vIncidentVertices) const;
896 
897 
905  void writeObj(const char* filename) const;
906 
913  void writeObj(const char* filename,Zone2* pZone) const;
914 
915 
921  void writeWebScene(const char* path) const;
922 
928  void writeWebScene(const char* path,Zone2* pZone) const;
929 
935 void subscribe(MsgType msgType,MsgBase* pMsg);
936 
942 void unsubscribe(MsgType msgType,MsgBase* pMsg);
943 
944 
951  bool isConstraint(Point2* p0,Point2* p1) const;
952 
958  bool isConstraint(Point2* pVtx) const;
959 
961  void printLicense() const;
962 
964  bool checkZoneQuality(Zone2* pZone,double minAngle,const char* name,const AcceptExperimentalFeature& accept);
966  void setName(const char* s);
968  std::string getName() const;
969 
970 
992  Zone2* importTriangles( std::vector<Point2>& vPoints,
993  bool bReorientIfNeeded,
994  bool bCreateExtendedBoundingBox
995  );
996 
1001  Orientation2 getOrientation(const Point2& p0,const Point2& p1,const Point2& p2);
1002 
1033  void cutTriangles( const Point2& knifeStart,
1034  const Point2& knifeEnd,
1035  bool bTurnEdgesIntoConstraints);
1036 
1049  void cutTriangles( std::vector<Segment2>& vSegments,
1050  bool bTurnEdgesIntoConstraints);
1051 
1052 
1072  Zone2* createZone_cookieCutter(std::vector<Segment2>& vSegments,bool bProtectEdges);
1073 
1074 
1120 #if GEOM_PSEUDO3D==GEOM_TRUE
1121  bool drape( std::vector<Segment2>& vSegmentsIn,
1122  std::vector<Segment2>& vSegmentsOut,
1123  double zTolerance) const;
1124 #else
1125  bool drape( std::vector<Segment2>& vSegmentsIn,
1126  std::vector<Segment2>& vSegmentsOut) const;
1127 #endif
1128 
1129 
1130 
1131 
1137 void getDirectedEdges(std::vector<Edge2>& vDirectedEdgesOut) const;
1138 
1144 void getUndirectedEdges(std::vector<Edge2>& vUndirectedEdgesOut) const;
1145 
1146 
1147 
1149  /* Deprecated: Use setNumCPU() instead. This method is kept for
1150  * compatibility with existing applications. Internally it calls
1151  * setNumCPU(0) to automatically determine and use the number of
1152  * available CPU cores.
1153  */
1154  void enableMultithreading();
1155  // Development functions, not for public use
1157  void internal(int au,int fu,const char* s="");
1159  Dt2* getImpl();
1161  void setDev(const char* s,int ival,double dval);
1162 
1163 protected:
1165  void initFade(unsigned numExpectedVertices);
1167  Fade_2D(const Fade_2D&); // No copy constructor
1169  Fade_2D& operator=(const Fade_2D&); // No assignment allowed
1171  Dt2* pImpl;
1172 }; // end of class
1173 
1174 
1175 
1176 
1177 
1178 } // (namespace)
1179 
ConstraintInsertionStrategy
Constraint Insertion Strategy determines how a constraint edge shall be inserted:
Definition: ConstraintSegment2.h:52
Bbox2 is an axis aligned 2D bounding box.
Definition: Bbox2.h:37
ConstraintGraph2 is a set of Constraint Edges (ConstraintSegment2)
Definition: ConstraintGraph2.h:52
A ConstraintSegment2 represents a Constraint Edge.
Definition: ConstraintSegment2.h:69
Fade_2D is the Delaunay triangulation main class.
Definition: Fade_2D.h:73
Triangle2 * getAdjacentTriangle(Point2 *p0, Point2 *p1) const
Get adjacent triangle.
void insert(const std::vector< Point2 > &vInputPoints, std::vector< Point2 * > &vHandles)
Insert points from a std::vector and store pointers in vHandles.
void unsubscribe(MsgType msgType, MsgBase *pMsg)
Unregister a message receiver.
int setNumCPU(int numCPU)
Set the number CPU cores for multithreading.
void setFastMode(bool bFast)
Set fast mode.
bool drape(std::vector< Segment2 > &vSegmentsIn, std::vector< Segment2 > &vSegmentsOut) const
Drape segments along a surface.
void getConvexHull(bool bAllVertices, std::vector< Point2 * > &vConvexHullPointsOut)
Compute the convex hull.
void subscribe(MsgType msgType, MsgBase *pMsg)
Register a message receiver.
bool hasArea() const
Check if the triangulation contains triangles (which is the case if at least 3 non-collinear points e...
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 postscript file using an existing Visualizer2 object.
void getUndirectedEdges(std::vector< Edge2 > &vUndirectedEdgesOut) const
Get undirected edges.
ConstraintGraph2 * createConstraint(std::vector< Segment2 > &vSegments, ConstraintInsertionStrategy cis, bool bOrientedSegments=false)
Add constraint edges (edges, polyline, polygon) .
void insert(const std::vector< Point2 > &vInputPoints)
Insert a vector of points.
Zone2 * createZone(ConstraintGraph2 *pConstraintGraph, ZoneLocation zoneLoc, const Point2 &startPoint, bool bVerbose=true)
Create a zone limited by a ConstraintGraph by growing from a start point.
void writeWebScene(const char *path, Zone2 *pZone) const
Write a zone to an *.obj file.
void writeObj(const char *filename, Zone2 *pZone) const
Write a zone to an *.obj file.
bool load(std::istream &stream, std::vector< Zone2 * > &vZones)
Load a triangulation.
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
Compute the axis-aligned bounding box of the points.
Zone2 * createZone(const std::vector< ConstraintGraph2 * > &vConstraintGraphs, ZoneLocation zoneLoc, const Point2 &startPoint, bool bVerbose=true)
Create a zone limited by multiple ConstraintGraph2 objects by growing from a start point.
void getTrianglePointers(std::vector< Triangle2 * > &vAllTriangles) const
Get pointers to all triangles.
Point2 * insert(const Point2 &p)
Insert a single point.
void printLicense() const
Prints license information.
Fade_2D(unsigned numExpectedVertices=3)
Constructor of the main triangulation class.
Definition: Fade_2D.h:81
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.
double measureTriangulationTime(std::vector< Point2 > &vPoints)
Measure the Delaunay triangulation time.
bool saveTriangulation(const char *filename, std::vector< Zone2 * > &vSaveZones)
Save a triangulation.
Zone2 * createZone(ConstraintGraph2 *pConstraintGraph, ZoneLocation zoneLoc, bool bVerbose=true)
Create a zone.
Voronoi2 * getVoronoiDiagram()
Get the Voronoi diagram.
Point2 * getNearestNeighbor(const Point2 &p)
Get nearest neighbor.
bool saveZones(std::ostream &stream, std::vector< Zone2 * > &vSaveZones)
Save zones.
bool saveTriangulation(std::ostream &stream, std::vector< Zone2 * > &vSaveZones)
Save a triangulation.
void applyConstraintsAndZones()
Apply conforming constraints and zones (deprecated!)
size_t numberOfPoints() const
Number of points.
~Fade_2D()
Destructor.
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...
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.
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 from Fade.
void statistics(const char *s) const
Statistics.
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 if a triangulation is valid.
Zone2 * createZone_cookieCutter(std::vector< Segment2 > &vSegments, bool bProtectEdges)
Cookie Cutter The Cookie Cutter cuts out a part of a triangulation and returns it as a Zone2 object.
bool saveZones(const char *filename, std::vector< Zone2 * > &vSaveZones)
Save zones.
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
Write the current triangulation to an *.obj file.
void getIncidentVertices(Point2 *pVtx, std::vector< Point2 * > &vIncidentVertices) const
Get incident vertices.
void insert(int numPoints, double *aCoordinates, Point2 **aHandles)
Insert points from an array.
void show(const char *postscriptFilename, bool bWithConstraints=true) const
Draws the triangulation as postscript file.
Zone2 * importTriangles(std::vector< Point2 > &vPoints, bool bReorientIfNeeded, bool bCreateExtendedBoundingBox)
Import triangles.
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 zone defined by a vector of triangles.
Triangle2 * locate(const Point2 &p)
Locate a triangle which contains p.
Parameters for the mesh generator.
Definition: MeshGenParams.h:58
MsgBase, a base class for message subscriber classes.
Definition: MsgBase.h:47
Point.
Definition: Point2.h:43
Triangle.
Definition: Triangle2.h:59
Visualizer2 is a general Postscript writer. It draws the objects Point2, Segment2,...
Definition: Visualizer2.h:56
Voronoi diagram.
Definition: Voronoi2.h:56
Zone2 is a certain defined area of a triangulation.
Definition: Zone2.h:92
FadeExport is a simple struct to export triangulation data.
Definition: FadeExport.h:43