Fade2.5D Documentation pages v2.16.8
Delaunay Features
Zone2.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 // unclear to you.
14 //
15 // Support: https://www.geom.at/contact/
16 // Project: https://www.geom.at/fade2d/html/
17 
19 
20 #pragma once
21 
22 #include "common.h"
23 #include "freeFunctions.h"
24 #include "FadeExport.h"
25 #include "Bbox2.h"
26 #include "Edge2.h"
27 #include "Segment2.h"
28 #include "UserPredicates.h"
29 #include "MsgBase.h"
30 #include "VtkWriter.h"
31 #include "CompPolygon.h"
32 #include "PolygonClipper.h"
33 
34 
35 #if GEOM_PSEUDO3D==GEOM_TRUE
36  namespace GEOM_FADE25D {
37 #elif GEOM_PSEUDO3D==GEOM_FALSE
38  namespace GEOM_FADE2D {
39 #else
40  #error GEOM_PSEUDO3D is not defined
41 #endif
42 
43 class ZoneShooter; // FWD
44 class ConstraintSegment2; // FWD
45 class Fade_2D; // FWD
46 
55 {
59 };
60 
61 
62 
69 enum SegmentSelectionType
70 {
71  SST_CONSTRAINT,
72  SST_INCIRCLE,
73  SST_IN_OR_ONCIRCLE
74 };
75 
76 
77 
78 class Progress; // FWD
79 class Dt2; // Fwd
80 class ConstraintGraph2; // Fwd
81 class Triangle2; // Fwd
82 class Point2; // Fwd
83 class Visualizer2; // Fwd
84 class Visualizer3; // Fwd
85 
86 
87 
98 class CLASS_DECLSPEC Zone2
99 {
100 public:
102  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_);
104  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,ConstraintGraph2* pConstraintGraph_);
106  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_);
108  Zone2(Dt2* pDt_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_,ZoneLocation zoneLoc_,std::vector<Point2>& vStartPoints);
110  ~Zone2();
122  bool hasOn(const Point2& p);
123 
124 
137 
138 #if GEOM_PSEUDO3D==GEOM_TRUE
146 #endif
147 
160  bool hasOnBoundary(const Point2& p);
161 
173  Triangle2* locate(const Point2& p);
174 
211  bool shiftToZone(const Point2& q, double tolerance, Point2& result);
212 
213 
239  bool save(const char* filename);
240 
264  bool save(std::ostream& stream);
265 
266 
276  void exportZone(FadeExport& fadeExport,bool bWithCustomIndices) const;
277 
278 
279 
300  void getOffsetBoundary(double offset,std::vector<Segment2>& vOffsetBoundary,double mergeAngleDeg=10.0,double angleStepDeg=20.0) const;
301 
323  Zone2* createOffsetZone(Fade_2D* pFade,double offset,double mergeAngleDeg=10,double angleStep=20.0) const;
324 
325 
326 
357  Zone2* morphOpen(Fade_2D* pFade,double offset,double mergeAngleDeg=10.0,double angleStep=20.0) const;
358 
359 
383  Zone2* morphClose(Fade_2D* pFade,double offset,double mergeAngleDeg=10.0,double angleStep=20.0) const;
384 
385 
393  void subscribe(MsgType msgType,MsgBase* pMsg);
394 
395 
403  void unsubscribe(MsgType msgType,MsgBase* pMsg);
404 
411  ZoneLocation getZoneLocation() const;
412 
413 
428 
429 
443  void show(const char* filename,const Colorname& zoneFillColor=CTRANSPARENT,const Colorname& zoneEdgeColor=CBLACK,const Colorname& nonZoneFillColor=CTRANSPARENT,const Colorname& nonZoneEdgeColor=CTRANSPARENT,const Colorname& constraintEdgeColor=CTRANSPARENT) const;
444 
458  void show(Visualizer2* pVisualizer,const Colorname& zoneFillColor=CTRANSPARENT,const Colorname& zoneEdgeColor=CBLACK,const Colorname& nonZoneFillColor=CTRANSPARENT,const Colorname& nonZoneEdgeColor=CTRANSPARENT,const Colorname& constraintEdgeColor=CTRANSPARENT) const;
459 
460 
469  void show(const char* filename,bool bShowFull,bool bWithConstraints) const;
470 
481  void show(Visualizer2* pVisualizer,bool bShowFull,bool bWithConstraints) const;
482 
492  void showVtk(const char* filename,VtkColor zoneColor,VtkColor nonZoneColor=VTK_TRANSPARENT,VtkColor constraintColor=VTK_TRANSPARENT) const;
493 
505  void showVtk(VtkWriter* pVtk,VtkColor zoneColor,VtkColor nonZoneColor=VTK_TRANSPARENT,VtkColor constraintColor=VTK_TRANSPARENT) const;
506 
507 
508 
509 
510 
511 #if GEOM_PSEUDO3D==GEOM_TRUE
521  void showGeomview(const char* filename,const char* color) const;
531  void showGeomview(Visualizer3* pVis,const char* color) const;
532 
534  void analyzeAngles(const char* name="");
535 
546  void smoothing(int numIterations=2,bool bWithXY=true);
547 
548 
573  void smoothing2(int numIterations,bool bWithXY,bool bWithConstraintZ);
596 
598  /*
599  * This function is deprecated but kept for backwards compatibility.
600  * Better use slopeValleyRidgeOptimization() (see above)
601  *
602  * Optimize Valleys and Ridges
603  *
604  * A Delaunay triangulation is not unique when when 2 or more triangles
605  * share a common circumcircle. As a consequence the four corners of
606  * a rectangle can be triangulated in two different ways: Either the
607  * diagonal proceeds from the lower left to the upper right corner
608  * or it connects the other two corners. Both solutions are valid and
609  * an arbitrary one is applied when points are triangulated. To improve
610  * the repeatability and for reasons of visual appearance this method
611  * unifies such diagonals such that they point from the lower left to
612  * the upper right corner (or in horizontal direction).\n
613  *
614  * Moreover a Delaunay triangulation does not take the z-value into
615  * account and thus valleys and ridges may be disturbed. The present
616  * method flips diagonals such that they point from the lower left to
617  * the upper right corner of a quad. And if the 2.5D lengths of the
618  * diagonals are significantly different, then the shorter one is
619  * applied.
620  *
621  * @param tolerance2D is 0 when only exact cases of more than 3 points
622  * on a common circumcircle shall be changed. But in practice input
623  * data can be disturbed by noise and tiny rounding errors such that
624  * grid points are not exactly on a grid. The numeric error is computed
625  * as \f$error=\frac{abs(diagonalA-diagonalB)}{max(diagonalA,diagonalB)}\f$.
626  * and \p tolerance2D is an upper threshold to allow modification despite
627  * such tiny inaccuracies.
628  * @param lowerThreshold25D is used to take also the heights of the
629  * involved points into account. For example, the points\n
630  * \n
631  * Point_2 a(0,0,0);\n
632  * Point_2 b(10,0,0);\n
633  * Point_2 c(10,10,0);\n
634  * Point_2 d(0,10,1000);\n
635  * \n
636  * can form the triangles (a,b,c) and (a,c,d) or the triangles (a,b,d)
637  * and (d,b,c) but (a,c) is obviousy the better diagonal because the
638  * points a,b,c share the same elevation while d is at z=1000.
639  * Technically spoken, the diagonal with the smaller 2.5D-length is
640  * applied if the both, the 2D error is below \p tolerance2D and the
641  * 2.5D error is above \p lowerThreshold25D. The 2.5D
642  * criterion has priority over the 2D criterion.
643  *
644  */
645  void optimizeValleysAndRidges(double tolerance2D,double lowerThreshold25D);
646 #endif
647 
648 
666  void unifyGrid(double tolerance);
667 
669  bool assignDt2(Dt2* pDt_);
670 
678  void getTriangles(std::vector<Triangle2*>& vTriangles) const;
679 
683  void getVertices(std::vector<Point2*>& vVertices_) const;
684 
685 
690  void statistics(const char* s) const;
691 
692 
700 
708  size_t getNumberOfTriangles() const;
709 
710 
714  void getConstraintGraphs(std::vector<ConstraintGraph2*>& vConstraintGraphs_) const;
715 
717  Dt2* getDelaunayTriangulation() const;
718 
725  size_t numberOfConstraintGraphs() const;
726 
728  void debug(const char* name="");
729 
733 
734  // Deprecated, replaced by getBorderEdges() but kept for
735  // backwards-compatibility.
738  void getBoundaryEdges(std::vector<Edge2>& vEdges) const;
739 
756  void getComponentPolygons(std::vector<CompPolygon>& vCompPolygons) const;
757 
758 
768  void getBoundarySegments(std::vector<Segment2>& vSegments) const;
780  double getArea2D() const;
781 
782 
783 #if GEOM_PSEUDO3D==GEOM_TRUE
791  double getArea25D() const;
792 #endif
793 
803 void getBorderEdges(std::vector<Edge2>& vBorderEdgesOut) const;
804 
813  void writeObj(const char* filename) const;
814 
815 #ifndef SKIPTHREADS
816 #if GEOM_PSEUDO3D==GEOM_TRUE
817 
829  bool writePly(const char* filename,bool bASCII=false) const;
830 
842  bool writePly(std::ostream& os,bool bASCII=false) const;
843 #endif
844 #endif
845 
846 
862  void getReplicationData( SegmentSelectionType segmentSelectionType,
863  std::vector<Point2>& vPoints,
864  std::vector<Segment2>& vInnerSegments,
865  std::vector<Segment2>& vBoundarySegments
866  ) const;
867 
868 
869 protected:
870  Zone2& operator=(const Zone2&);
871  // Optimization techniques
873  void optMode_standard_sub(std::vector<Triangle2*>& vT,std::vector<Triangle2*>& vChangedT);
875  void optMode_standard();
877  double optMode_prioq(double noEdgeBelowDih,bool bWithProgress);
879  void getEdgesForOptimization(double noEdgeBelowDegree,std::vector<Edge2>& vEdges);
881  void optMode_simulatedAnnealing();
883  void optMode_simulatedAnnealing_sub(std::vector<Edge2>& vUniqueEdges,double temperature);
885  void removeConstraintEdges(std::vector<Edge2>& vEdges) const;
887  Zone2(const Zone2&);
889  void getTriangles_RESULT(std::vector<Triangle2*>& vTriangles) const;
891  void initWorkspace(bool bInside,std::set<std::pair<Point2*,Point2*> >& sNoGrowEdges,std::vector<Triangle2*>& vWorkspace) const;
893  void bfsFromWorkspace(std::vector<Triangle2*>& vWorkspace,std::set<std::pair<Point2*,Point2*> >& sNoGrowEdges,std::vector<Triangle2*>& vTriangles) const;
895  Zone2* ctbz_treatCC(std::vector<Triangle2*>& vOneCC);
896  // Data
898  Dt2* pDt;
900  Progress* pZoneProgress;
902  ZoneShooter* pZoneShooter;
904  ZoneLocation zoneLoc;
905  CLASS_DECLSPEC
906  friend Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
907  CLASS_DECLSPEC
908  friend Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
909  CLASS_DECLSPEC
910  friend Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
911  CLASS_DECLSPEC
912  friend Zone2* zoneSymmetricDifference(Zone2* pZone0,Zone2* pZone1);
913 
920  CLASS_DECLSPEC
921  friend Zone2* peelOffIf(Zone2* pZone, UserPredicateT* pPredicate,bool bVerbose); // Depricated!
922 
923 
943  CLASS_DECLSPEC
944  friend Zone2* peelOffIf(Zone2* pZone, bool bAvoidSplit,PeelPredicateTS* pPredicate);
945 
946 
947 
948 private:
949 #ifndef __MINGW32__
950 #ifdef _WIN32
951 #pragma warning(push)
952 #pragma warning(disable:4251)
953 #endif
954 #endif
955  std::vector<ConstraintGraph2*> vConstraintGraphs;
956  std::vector<Point2> vStartPoints;
957  std::vector<Zone2*> vInputZones;
958 
959 #ifndef __MINGW32__
960 #ifdef _WIN32
961 #pragma warning(pop)
962 #endif
963 #endif
964 };
965 
966 // Free functions
984 CLASS_DECLSPEC
985 Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
986 
1005 CLASS_DECLSPEC
1006 Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
1007 
1008 
1027 CLASS_DECLSPEC
1029 
1030 
1045 CLASS_DECLSPEC
1046 Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
1047 
1048 
1049 
1050 
1051 
1052 
1053 } // (namespace)
Colorname
Predefined colors for convenience.
Definition: Color.h:36
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
CLASS_DECLSPEC Zone2 * zoneSymmetricDifference(Zone2 *pZone0, Zone2 *pZone1)
Computes the symmetric difference between two Zone2 objects.
CLASS_DECLSPEC Zone2 * zoneIntersection(Zone2 *pZone0, Zone2 *pZone1)
Computes the intersection of two Zone2 objects.
OptimizationMode
Definition: Zone2.h:55
@ OPTMODE_BEST
Best quality but quite time consuming.
Definition: Zone2.h:58
@ OPTMODE_STANDARD
Fastest optimization mode.
Definition: Zone2.h:56
@ OPTMODE_BETTER
Considerably better quality and still fast.
Definition: Zone2.h:57
CLASS_DECLSPEC Zone2 * zoneUnion(Zone2 *pZone0, Zone2 *pZone1)
Computes the union of two Zone2 objects.
CLASS_DECLSPEC Zone2 * zoneDifference(Zone2 *pZone0, Zone2 *pZone1)
Computes the difference between two Zone2 objects.
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
MsgBase, a base class for message subscriber classes.
Definition: MsgBase.h:55
User-defined peel predicate.
Definition: UserPredicates.h:57
Represents a 2.5D point.
Definition: Point2.h:76
Represents a triangle in a triangulation.
Definition: Triangle2.h:59
User-defined predicate (deprecated)
Definition: UserPredicates.h:38
A PDF and Postscript Writer for 2D Visualization.
Definition: Visualizer2.h:60
Visualizer3 is a 3D scene writer for the Geomview viewer.
Definition: Visualizer3.h:45
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:99
bool hasOn(const Point2 &p)
Checks if a point lies on the zone.
void subscribe(MsgType msgType, MsgBase *pMsg)
Registers a message receiver.
void unsubscribe(MsgType msgType, MsgBase *pMsg)
Unregisters a message receiver.
size_t getNumberOfTriangles() const
Get the number of triangles.
ConstraintGraph2 * getConstraintGraph() const
Get the associated constraint.
Bbox2 getBoundingBox() const
Compute the bounding box.
CLASS_DECLSPEC friend Zone2 * zoneSymmetricDifference(Zone2 *pZone0, Zone2 *pZone1)
Computes the symmetric difference between two Zone2 objects.
void show(Visualizer2 *pVisualizer, const Colorname &zoneFillColor=CTRANSPARENT, const Colorname &zoneEdgeColor=CBLACK, const Colorname &nonZoneFillColor=CTRANSPARENT, const Colorname &nonZoneEdgeColor=CTRANSPARENT, const Colorname &constraintEdgeColor=CTRANSPARENT) const
Postscript- and PDF visualization.
void getComponentPolygons(std::vector< CompPolygon > &vCompPolygons) const
Get connected components.
bool save(std::ostream &stream)
Save the zone.
CLASS_DECLSPEC friend Zone2 * zoneUnion(Zone2 *pZone0, Zone2 *pZone1)
Computes the union of two Zone2 objects.
ZoneLocation getZoneLocation() const
Get the zone location.
double getMedianEdgeLength25D()
Get the median 2.5D edge length.
void getOffsetBoundary(double offset, std::vector< Segment2 > &vOffsetBoundary, double mergeAngleDeg=10.0, double angleStepDeg=20.0) const
Get the offset boundary of a shape.
void unifyGrid(double tolerance)
Unify Grid.
void getTriangles(std::vector< Triangle2 * > &vTriangles) const
Get the triangles of the zone.
void getConstraintGraphs(std::vector< ConstraintGraph2 * > &vConstraintGraphs_) const
Get the associated constraint graphs.
void show(Visualizer2 *pVisualizer, bool bShowFull, bool bWithConstraints) const
Postscript- and PDF-visualization.
void exportZone(FadeExport &fadeExport, bool bWithCustomIndices) const
Export triangles from a zone.
void showGeomview(const char *filename, const char *color) const
Geomview visualization.
double getMedianEdgeLength2D()
Get the median 2D edge length.
double getArea2D() const
Get 2D Area.
Triangle2 * locate(const Point2 &p)
Locates the triangle containing the given point within the zone.
void getVertices(std::vector< Point2 * > &vVertices_) const
Get the vertices of the zone.
bool shiftToZone(const Point2 &q, double tolerance, Point2 &result)
Finds a point close to the query that lies inside the zone.
bool writePly(std::ostream &os, bool bASCII=false) const
Write the Zone2 to a *.ply file.
void smoothing2(int numIterations, bool bWithXY, bool bWithConstraintZ)
Smooths the vertices of the zone.
void showVtk(VtkWriter *pVtk, VtkColor zoneColor, VtkColor nonZoneColor=VTK_TRANSPARENT, VtkColor constraintColor=VTK_TRANSPARENT) const
VTK visualization.
Zone2 * morphClose(Fade_2D *pFade, double offset, double mergeAngleDeg=10.0, double angleStep=20.0) const
Morphological closing to bridge small gaps in the Zone2.
ConstraintSegment2 * getNearbyBoundaryConstraint(Point2 &p, double tolerance)
Locates the nearest boundary ConstraintSegment2 of the Zone2.
Zone2 * convertToBoundedZone()
Convert a zone to a bounded zone.
CLASS_DECLSPEC friend Zone2 * peelOffIf(Zone2 *pZone, bool bAvoidSplit, PeelPredicateTS *pPredicate)
Peel off undesired border triangles.
void showVtk(const char *filename, VtkColor zoneColor, VtkColor nonZoneColor=VTK_TRANSPARENT, VtkColor constraintColor=VTK_TRANSPARENT) const
VTK visualization.
double getArea25D() const
Get 2.5D Area.
Zone2 * createOffsetZone(Fade_2D *pFade, double offset, double mergeAngleDeg=10, double angleStep=20.0) const
Creates an offset zone.
void getBorderEdges(std::vector< Edge2 > &vBorderEdgesOut) const
Get border edges.
void showGeomview(Visualizer3 *pVis, const char *color) const
Geomview visualization.
CLASS_DECLSPEC friend Zone2 * zoneDifference(Zone2 *pZone0, Zone2 *pZone1)
Computes the difference between two Zone2 objects.
size_t numberOfConstraintGraphs() const
Get the number of ConstraintGraph2 objects.
void writeObj(const char *filename) const
Write the Zone2 to an .obj file.
Zone2 * morphOpen(Fade_2D *pFade, double offset, double mergeAngleDeg=10.0, double angleStep=20.0) const
Morphological opening to remove small details.
void show(const char *filename, bool bShowFull, bool bWithConstraints) const
Postscript- and PDF-visualization.
void statistics(const char *s) const
Prints statistics.
bool save(const char *filename)
Save the zone.
bool writePly(const char *filename, bool bASCII=false) const
Write the Zone2 to a *.ply file.
void getBoundarySegments(std::vector< Segment2 > &vSegments) const
Get the boundaries as segments.
bool hasOnBoundary(const Point2 &p)
Checks if a point lies on the boundary of the zone.
void smoothing(int numIterations=2, bool bWithXY=true)
Smoothing.
void show(const char *filename, const Colorname &zoneFillColor=CTRANSPARENT, const Colorname &zoneEdgeColor=CBLACK, const Colorname &nonZoneFillColor=CTRANSPARENT, const Colorname &nonZoneEdgeColor=CTRANSPARENT, const Colorname &constraintEdgeColor=CTRANSPARENT) const
Postscript- and PDF visualization.
void slopeValleyRidgeOptimization(OptimizationMode om=OPTMODE_BETTER)
Optimize Slopes, Valleys, and Ridges.
CLASS_DECLSPEC friend Zone2 * peelOffIf(Zone2 *pZone, UserPredicateT *pPredicate, bool bVerbose)
Peel off undesired border triangles (deprecated)
CLASS_DECLSPEC friend Zone2 * zoneIntersection(Zone2 *pZone0, Zone2 *pZone1)
Computes the intersection of two Zone2 objects.
FadeExport is a simple struct to export triangulation data.
Definition: FadeExport.h:49