Fade2D Documentation pages v1.90
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 // not clear to you.
14 //
15 // Author: Bernhard Kornberger, bkorn (at) geom.at
16 // http://www.geom.at
17 
19 
20 #pragma once
21 
22 #include "common.h"
23 #include "freeFunctions.h"
24 #include "Bbox2.h"
25 #include "Edge2.h"
26 #include "Segment2.h"
27 #include "UserPredicates.h"
28 #include "MsgBase.h"
29 
30 
31 
32 #if GEOM_PSEUDO3D==GEOM_TRUE
33  namespace GEOM_FADE25D {
34 #elif GEOM_PSEUDO3D==GEOM_FALSE
35  namespace GEOM_FADE2D {
36 #else
37  #error GEOM_PSEUDO3D is not defined
38 #endif
39 
48 {
52 };
53 
54 class Progress; // FWD
55 class Dt2; // Fwd
56 class ConstraintGraph2; // Fwd
57 class Triangle2; // Fwd
58 class Point2; // Fwd
59 class Visualizer2; // Fwd
60 class Visualizer3; // Fwd
61 
62 
72 struct CLASS_DECLSPEC CompPolygon
73 {
74  CompPolygon();
75  CompPolygon(const CompPolygon& other);
76  CompPolygon& operator=(const CompPolygon& other);
77  ~CompPolygon();
78  // Data
79  std::vector<Triangle2*>* pvCC;
80  std::vector<Edge2>* pvOuterPolygon;
81  std::vector<std::vector<Edge2> >* pvvHolePolygons;
82 };
83 
90 class CLASS_DECLSPEC Zone2
91 {
92 public:
94  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_);
96  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,ConstraintGraph2* pConstraintGraph_);
98  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_);
100  Zone2(Dt2* pDt_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_,ZoneLocation zoneLoc_,std::vector<Point2>& vStartPoints);
102  ~Zone2();
103 
123  bool save(const char* filename);
124 
143  bool save(std::ostream& stream);
144 
145 
151  void subscribe(MsgType msgType,MsgBase* pMsg);
157  void unsubscribe(MsgType msgType,MsgBase* pMsg);
168  ZoneLocation getZoneLocation() const;
169 
183 
191  void show(const char* postscriptFilename,bool bShowFull,bool bWithConstraints) const;
192 
200  void show(Visualizer2* pVisualizer,bool bShowFull,bool bWithConstraints) const;
201 
202 
203 
204 
205 
206 #if GEOM_PSEUDO3D==GEOM_TRUE
213  void showGeomview(const char* filename,const char* color) const;
220  void showGeomview(Visualizer3* pVis,const char* color) const;
221 
223  void analyzeAngles(const char* name="");
224 
237  void smoothing(int numIterations=2);
238 
259  void slopeValleyRidgeOptimization(OptimizationMode om=OPTMODE_BETTER);
260 
262  /*
263  * This function is deprecated but kept for backwards compatibility.
264  * Better use slopeValleyRidgeOptimization() (see above)
265  *
266  * Optimize Valleys and Ridges
267  *
268  * A Delaunay triangulation is not unique when when 2 or more triangles
269  * share a common circumcircle. As a consequence the four corners of
270  * a rectangle can be triangulated in two different ways: Either the
271  * diagonal proceeds from the lower left to the upper right corner
272  * or it connects the other two corners. Both solutions are valid and
273  * an arbitrary one is applied when points are triangulated. To improve
274  * the repeatability and for reasons of visual appearance this method
275  * unifies such diagonals such that they point from the lower left to
276  * the upper right corner (or in horizontal direction).\n
277  *
278  * Moreover a Delaunay triangulation does not take the z-value into
279  * account and thus valleys and ridges may be disturbed. The present
280  * method flips diagonals such that they point from the lower left to
281  * the upper right corner of a quad. And if the 2.5D lengths of the
282  * diagonals are significantly different, then the shorter one is
283  * applied.
284  *
285  * @param tolerance2D is 0 when only exact cases of more than 3 points
286  * on a common circumcircle shall be changed. But in practice input
287  * data can be disturbed by noise and tiny rounding errors such that
288  * grid points are not exactly on a grid. The numeric error is computed
289  * as \f$error=\frac{abs(diagonalA-diagonalB)}{max(diagonalA,diagonalB)}\f$.
290  * and \p tolerance2D is an upper threshold to allow modification despite
291  * such tiny inaccuracies.
292  * @param lowerThreshold25D is used to take also the heights of the
293  * involved points into account. For example, the points\n
294  * \n
295  * Point_2 a(0,0,0);\n
296  * Point_2 b(10,0,0);\n
297  * Point_2 c(10,10,0);\n
298  * Point_2 d(0,10,1000);\n
299  * \n
300  * can form the triangles (a,b,c) and (a,c,d) or the triangles (a,b,d)
301  * and (d,b,c) but (a,c) is obviousy the better diagonal because the
302  * points a,b,c share the same elevation while d is at z=1000.
303  * Technically spoken, the diagonal with the smaller 2.5D-length is
304  * applied if the both, the 2D error is below \p tolerance2D and the
305  * 2.5D error is above \p lowerThreshold25D. The 2.5D
306  * criterion has priority over the 2D criterion.
307  *
308  */
309  void optimizeValleysAndRidges(double tolerance2D,double lowerThreshold25D);
310 #endif
311 
334  void unifyGrid(double tolerance);
335 
337  bool assignDt2(Dt2* pDt_);
338 
349  void getTriangles(std::vector<Triangle2*>& vTriangles_) const;
350 
354  void getVertices(std::vector<Point2*>& vVertices_) const;
355 
356 
361  void statistics(const char* s) const;
362 
363 
369 
374  size_t getNumberOfTriangles() const;
375 
376 
380  void getConstraintGraphs(std::vector<ConstraintGraph2*>& vConstraintGraphs_) const;
381 
383  Dt2* getDelaunayTriangulation() const;
384 
389  size_t numberOfConstraintGraphs() const;
390 
393  void debug(const char* name="");
394 
398 
405  void getBoundaryEdges(std::vector<Edge2>& vEdges) const;
406 
417  void getComponentPolygons(std::vector<CompPolygon>& vCompPolygons) const;
418 
424  void getBoundarySegments(std::vector<Segment2>& vSegments) const;
425 
438  double getArea2D() const;
439 
440 
441 #if GEOM_PSEUDO3D==GEOM_TRUE
449  double getArea25D() const;
450 #endif
451 
455  void getBorderEdges(std::vector<Edge2>& vBorderEdgesOut) const;
456 
463  void writeObj(const char* outFilename) const;
464 
465 
466 
467 protected:
468  // Optimization techniques
470  void optMode_standard_sub(std::vector<Triangle2*>& vT,std::vector<Triangle2*>& vChangedT);
472  void optMode_standard();
474  double optMode_prioq(double noEdgeBelowDih,bool bWithProgress);
476  void getEdgesForOptimization(double noEdgeBelowDegree,std::vector<Edge2>& vEdges);
478  void optMode_simulatedAnnealing();
480  void optMode_simulatedAnnealing_sub(std::vector<Edge2>& vUniqueEdges,double temperature);
481 
482 
484  Zone2(const Zone2&);
486  void getTriangles_RESULT(std::vector<Triangle2*>& vTriangles) const;
488  void initWorkspace(bool bInside,std::vector<Triangle2*>& vWorkspace) const;
490  void bfsFromWorkspace(std::vector<Triangle2*>& vWorkspace,std::vector<Triangle2*>& vTriangles) const;
492  Zone2* ctbz_treatCC(std::vector<Triangle2*>& vOneCC);
493  // Data
495  Dt2* pDt;
497  Progress* pZoneProgress;
499  ZoneLocation zoneLoc;
500  CLASS_DECLSPEC
501  friend Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
502  CLASS_DECLSPEC
503  friend Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
504  CLASS_DECLSPEC
505  friend Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
506  CLASS_DECLSPEC
507  friend Zone2* zoneSymmetricDifference(Zone2* pZone0,Zone2* pZone1);
508  // This version is deprecated (but still valid) in favor of the
509  // version that takes a PeelPredicateTS.
526  CLASS_DECLSPEC
527  friend Zone2* peelOffIf(Zone2* pZone, UserPredicateT* pPredicate,bool bVerbose);
541  CLASS_DECLSPEC
542  friend Zone2* peelOffIf(Zone2* pZone, bool bAvoidSplit,PeelPredicateTS* pPredicate);
543 
544 
545 
546 private:
547 #ifdef _WIN32
548 #pragma warning(push)
549 #pragma warning(disable:4251)
550 #endif
551  std::vector<ConstraintGraph2*> vConstraintGraphs;
552  std::vector<Point2> vStartPoints;
553  std::vector<Zone2*> vInputZones;
554 #ifdef _WIN32
555 #pragma warning(pop)
556 #endif
557 
558 };
559 
560 // Free functions
561 
566 CLASS_DECLSPEC
567 Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
572 CLASS_DECLSPEC
573 Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
578 CLASS_DECLSPEC
579 Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
585 CLASS_DECLSPEC
587 
588 
589 
590 
591 } // (namespace)
Zone2 * zoneSymmetricDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the symmetric difference of two zones.
Zone2 * zoneDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the difference of two zones.
Zone2 * zoneUnion(Zone2 *pZone0, Zone2 *pZone1)
Compute the union of two zones.
Zone2 * zoneIntersection(Zone2 *pZone0, Zone2 *pZone1)
Compute the intersection of two zones.
OptimizationMode
Definition: Zone2.h:48
@ OPTMODE_STANDARD
Fastest optimization mode.
Definition: Zone2.h:49
@ OPTMODE_BEST
Best quality but quite time consuming.
Definition: Zone2.h:51
@ OPTMODE_BETTER
Considerably better quality and still fast.
Definition: Zone2.h:50
Bbox2 is an axis aligned 2D bounding box.
Definition: Bbox2.h:37
ConstraintGraph2 is a set of Constraint Edges (ConstraintSegment2)
Definition: ConstraintGraph2.h:52
MsgBase, a base class for message subscriber classes.
Definition: MsgBase.h:47
User-defined peel predicate.
Definition: UserPredicates.h:60
User-defined predicate (deprecated)
Definition: UserPredicates.h:39
Visualizer2 is a general Postscript writer. It draws the objects Point2, Segment2,...
Definition: Visualizer2.h:56
Zone2 is a certain defined area of a triangulation.
Definition: Zone2.h:91
friend Zone2 * peelOffIf(Zone2 *pZone, UserPredicateT *pPredicate, bool bVerbose)
Peel off border triangles (deprecated)
ConstraintGraph2 * getConstraintGraph() const
Get the associated constraint.
void show(const char *postscriptFilename, bool bShowFull, bool bWithConstraints) const
Postscript visualization.
bool save(std::ostream &stream)
Save the zone.
Bbox2 getBoundingBox() const
Compute the bounding box.
void getBoundaryEdges(std::vector< Edge2 > &vEdges) const
Compute the boundary edges.
double getArea2D() const
Get 2D Area.
void writeObj(const char *outFilename) const
Write the zone to *.obj Writes the triangles of the present Zone2 to an *.obj file (The *....
size_t numberOfConstraintGraphs() const
Get a the number of ConstraintGraph2 objects.
friend Zone2 * zoneIntersection(Zone2 *pZone0, Zone2 *pZone1)
Compute the intersection of two zones.
void getTriangles(std::vector< Triangle2 * > &vTriangles_) const
Get the triangles of the zone.
void getComponentPolygons(std::vector< CompPolygon > &vCompPolygons) const
Get connected components and their boundary polygons.
void show(Visualizer2 *pVisualizer, bool bShowFull, bool bWithConstraints) const
Postscript visualization.
void subscribe(MsgType msgType, MsgBase *pMsg)
Register a message receiver.
void getBoundarySegments(std::vector< Segment2 > &vSegments) const
Compute the boundary segments.
void getConstraintGraphs(std::vector< ConstraintGraph2 * > &vConstraintGraphs_) const
Get the associated constraint graphs.
friend Zone2 * zoneSymmetricDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the symmetric difference of two zones.
ZoneLocation getZoneLocation() const
Get the zone location.
void getVertices(std::vector< Point2 * > &vVertices_) const
Get the vertices of the zone.
friend Zone2 * zoneUnion(Zone2 *pZone0, Zone2 *pZone1)
Compute the union of two zones.
void unsubscribe(MsgType msgType, MsgBase *pMsg)
Unregister a message receiver.
void debug(const char *name="")
Development function.
size_t getNumberOfTriangles() const
Get the number of triangles.
friend Zone2 * peelOffIf(Zone2 *pZone, bool bAvoidSplit, PeelPredicateTS *pPredicate)
Peel off border triangles.
bool save(const char *filename)
Save the zone.
Zone2 * convertToBoundedZone()
Convert a zone to a bounded zone.
void unifyGrid(double tolerance)
void statistics(const char *s) const
void getBorderEdges(std::vector< Edge2 > &vBorderEdgesOut) const
Get border edges.
friend Zone2 * zoneDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the difference of two zones.
Connected component with boundary- and hole polygons.
Definition: Zone2.h:73
std::vector< std::vector< Edge2 > > * pvvHolePolygons
Sorted hole polygons.
Definition: Zone2.h:81
std::vector< Edge2 > * pvOuterPolygon
Sorted outer polygon.
Definition: Zone2.h:80
std::vector< Triangle2 * > * pvCC
One connected component of triangles (connection is meant along edges, not just vertices)
Definition: Zone2.h:79