Fade2D Documentation pages v2.14
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 "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 "sortMT.h"
32 
33 
34 #if GEOM_PSEUDO3D==GEOM_TRUE
35  namespace GEOM_FADE25D {
36 #elif GEOM_PSEUDO3D==GEOM_FALSE
37  namespace GEOM_FADE2D {
38 #else
39  #error GEOM_PSEUDO3D is not defined
40 #endif
41 
50 {
54 };
55 
56 class Progress; // FWD
57 class Dt2; // Fwd
58 class ConstraintGraph2; // Fwd
59 class Triangle2; // Fwd
60 class Point2; // Fwd
61 class Visualizer2; // Fwd
62 class Visualizer3; // Fwd
63 
64 
77 struct CLASS_DECLSPEC CompPolygon
78 {
79  CompPolygon();
80  CompPolygon(const CompPolygon& other);
81  CompPolygon& operator=(const CompPolygon& other);
82  ~CompPolygon();
83  // Data
84  std::vector<Triangle2*>* pvCC;
85  std::vector<Edge2>* pvOuterPolygon;
86  std::vector<std::vector<Edge2> >* pvvHolePolygons;
87 };
88 
95 class CLASS_DECLSPEC Zone2
96 {
97 public:
99  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_);
101  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,ConstraintGraph2* pConstraintGraph_);
103  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_);
105  Zone2(Dt2* pDt_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_,ZoneLocation zoneLoc_,std::vector<Point2>& vStartPoints);
107  ~Zone2();
108 
128  bool save(const char* filename);
129 
148  bool save(std::ostream& stream);
149 
150 
157  void exportZone(FadeExport& fadeExport,bool bWithCustomIndices) const;
158 
159 
160 
161 
167  void subscribe(MsgType msgType,MsgBase* pMsg);
173  void unsubscribe(MsgType msgType,MsgBase* pMsg);
184  ZoneLocation getZoneLocation() const;
185 
199 
207  void show(const char* filename,bool bShowFull,bool bWithConstraints) const;
208 
216  void show(Visualizer2* pVisualizer,bool bShowFull,bool bWithConstraints) const;
217 
218 
219 
227  void showVtk(const char* filename,VtkColor zoneColor,VtkColor nonZoneColor=VTK_TRANSPARENT,VtkColor constraintColor=VTK_TRANSPARENT) const;
228 
229 
239  void showVtk(VtkWriter* pVtk,VtkColor zoneColor,VtkColor nonZoneColor=VTK_TRANSPARENT,VtkColor constraintColor=VTK_TRANSPARENT) const;
240 
241 
242 
243 #if GEOM_PSEUDO3D==GEOM_TRUE
250  void showGeomview(const char* filename,const char* color) const;
257  void showGeomview(Visualizer3* pVis,const char* color) const;
258 
260  void analyzeAngles(const char* name="");
261 
274  void smoothing(int numIterations=2,bool bWithXY=true);
275 
276 
297  void slopeValleyRidgeOptimization(OptimizationMode om=OPTMODE_BETTER);
298 
300  /*
301  * This function is deprecated but kept for backwards compatibility.
302  * Better use slopeValleyRidgeOptimization() (see above)
303  *
304  * Optimize Valleys and Ridges
305  *
306  * A Delaunay triangulation is not unique when when 2 or more triangles
307  * share a common circumcircle. As a consequence the four corners of
308  * a rectangle can be triangulated in two different ways: Either the
309  * diagonal proceeds from the lower left to the upper right corner
310  * or it connects the other two corners. Both solutions are valid and
311  * an arbitrary one is applied when points are triangulated. To improve
312  * the repeatability and for reasons of visual appearance this method
313  * unifies such diagonals such that they point from the lower left to
314  * the upper right corner (or in horizontal direction).\n
315  *
316  * Moreover a Delaunay triangulation does not take the z-value into
317  * account and thus valleys and ridges may be disturbed. The present
318  * method flips diagonals such that they point from the lower left to
319  * the upper right corner of a quad. And if the 2.5D lengths of the
320  * diagonals are significantly different, then the shorter one is
321  * applied.
322  *
323  * @param tolerance2D is 0 when only exact cases of more than 3 points
324  * on a common circumcircle shall be changed. But in practice input
325  * data can be disturbed by noise and tiny rounding errors such that
326  * grid points are not exactly on a grid. The numeric error is computed
327  * as \f$error=\frac{abs(diagonalA-diagonalB)}{max(diagonalA,diagonalB)}\f$.
328  * and \p tolerance2D is an upper threshold to allow modification despite
329  * such tiny inaccuracies.
330  * @param lowerThreshold25D is used to take also the heights of the
331  * involved points into account. For example, the points\n
332  * \n
333  * Point_2 a(0,0,0);\n
334  * Point_2 b(10,0,0);\n
335  * Point_2 c(10,10,0);\n
336  * Point_2 d(0,10,1000);\n
337  * \n
338  * can form the triangles (a,b,c) and (a,c,d) or the triangles (a,b,d)
339  * and (d,b,c) but (a,c) is obviousy the better diagonal because the
340  * points a,b,c share the same elevation while d is at z=1000.
341  * Technically spoken, the diagonal with the smaller 2.5D-length is
342  * applied if the both, the 2D error is below \p tolerance2D and the
343  * 2.5D error is above \p lowerThreshold25D. The 2.5D
344  * criterion has priority over the 2D criterion.
345  *
346  */
347  void optimizeValleysAndRidges(double tolerance2D,double lowerThreshold25D);
348 #endif
349 
372  void unifyGrid(double tolerance);
373 
375  bool assignDt2(Dt2* pDt_);
376 
387  void getTriangles(std::vector<Triangle2*>& vTriangles_) const;
388 
392  void getVertices(std::vector<Point2*>& vVertices_) const;
393 
394 
399  void statistics(const char* s) const;
400 
401 
407 
412  size_t getNumberOfTriangles() const;
413 
414 
418  void getConstraintGraphs(std::vector<ConstraintGraph2*>& vConstraintGraphs_) const;
419 
421  Dt2* getDelaunayTriangulation() const;
422 
427  size_t numberOfConstraintGraphs() const;
428 
431  void debug(const char* name="");
432 
436 
437  // Deprecated, replaced by getBorderEdges() but kept for
438  // backwards-compatibility.
441  void getBoundaryEdges(std::vector<Edge2>& vEdges) const;
442 
453  void getComponentPolygons(std::vector<CompPolygon>& vCompPolygons) const;
454 
460  void getBoundarySegments(std::vector<Segment2>& vSegments) const;
461 
474  double getArea2D() const;
475 
476 
477 #if GEOM_PSEUDO3D==GEOM_TRUE
485  double getArea25D() const;
486 #endif
487 
491  void getBorderEdges(std::vector<Edge2>& vBorderEdgesOut) const;
492 
499  void writeObj(const char* outFilename) const;
500 
501 #ifndef SKIPTHREADS
502 #if GEOM_PSEUDO3D==GEOM_TRUE
510  bool writePly(const char* filename,bool bASCII=false) const;
518  bool writePly(std::ostream& os,bool bASCII=false) const;
519 #endif
520 #endif
521 
522 
523 
524 protected:
525 
526 
527 
528 
529  Zone2& operator=(const Zone2&);
530  // Optimization techniques
532  void optMode_standard_sub(std::vector<Triangle2*>& vT,std::vector<Triangle2*>& vChangedT);
534  void optMode_standard();
536  double optMode_prioq(double noEdgeBelowDih,bool bWithProgress);
538  void getEdgesForOptimization(double noEdgeBelowDegree,std::vector<Edge2>& vEdges);
540  void optMode_simulatedAnnealing();
542  void optMode_simulatedAnnealing_sub(std::vector<Edge2>& vUniqueEdges,double temperature);
543 
545  void removeConstraintEdges(std::vector<Edge2>& vEdges) const;
546 
548  Zone2(const Zone2&);
550  void getTriangles_RESULT(std::vector<Triangle2*>& vTriangles) const;
552  void initWorkspace(bool bInside,std::vector<Triangle2*>& vWorkspace) const;
554  void bfsFromWorkspace(std::vector<Triangle2*>& vWorkspace,std::vector<Triangle2*>& vTriangles) const;
556  Zone2* ctbz_treatCC(std::vector<Triangle2*>& vOneCC);
557  // Data
559  Dt2* pDt;
561  Progress* pZoneProgress;
563  ZoneLocation zoneLoc;
564  CLASS_DECLSPEC
565  friend Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
566  CLASS_DECLSPEC
567  friend Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
568  CLASS_DECLSPEC
569  friend Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
570  CLASS_DECLSPEC
571  friend Zone2* zoneSymmetricDifference(Zone2* pZone0,Zone2* pZone1);
572  // This version is deprecated (but still valid) in favor of the
573  // version that takes a PeelPredicateTS.
590  CLASS_DECLSPEC
591  friend Zone2* peelOffIf(Zone2* pZone, UserPredicateT* pPredicate,bool bVerbose);
605  CLASS_DECLSPEC
606  friend Zone2* peelOffIf(Zone2* pZone, bool bAvoidSplit,PeelPredicateTS* pPredicate);
607 
608 
609 
610 private:
611 #ifndef __MINGW32__
612 #ifdef _WIN32
613 #pragma warning(push)
614 #pragma warning(disable:4251)
615 #endif
616 #endif
617  std::vector<ConstraintGraph2*> vConstraintGraphs;
618  std::vector<Point2> vStartPoints;
619  std::vector<Zone2*> vInputZones;
620 
621 #ifndef __MINGW32__
622 #ifdef _WIN32
623 #pragma warning(pop)
624 #endif
625 #endif
626 };
627 
628 // Free functions
629 
634 CLASS_DECLSPEC
635 Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
640 CLASS_DECLSPEC
641 Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
646 CLASS_DECLSPEC
647 Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
653 CLASS_DECLSPEC
655 
656 
657 
658 
659 } // (namespace)
VtkColor
Enumeration of colors used by the VTKWriter.
Definition: VtkWriter.h:39
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:50
@ OPTMODE_STANDARD
Fastest optimization mode.
Definition: Zone2.h:51
@ OPTMODE_BEST
Best quality but quite time consuming.
Definition: Zone2.h:53
@ OPTMODE_BETTER
Considerably better quality and still fast.
Definition: Zone2.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
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 PDF- and Postscript writer.
Definition: Visualizer2.h:54
A writer for the VTK file format.
Definition: VtkWriter.h:62
Zone2 is a certain defined area of a triangulation.
Definition: Zone2.h:96
friend Zone2 * peelOffIf(Zone2 *pZone, UserPredicateT *pPredicate, bool bVerbose)
Peel off border triangles (deprecated)
ConstraintGraph2 * getConstraintGraph() const
Get the associated constraint.
bool save(std::ostream &stream)
Save the zone.
Bbox2 getBoundingBox() const
Compute the bounding box.
void showVtk(const char *filename, VtkColor zoneColor, VtkColor nonZoneColor=VTK_TRANSPARENT, VtkColor constraintColor=VTK_TRANSPARENT) const
VTK visualization.
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- and PDF-visualization.
void show(const char *filename, bool bShowFull, bool bWithConstraints) const
Postscript- and PDF-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.
void exportZone(FadeExport &fadeExport, bool bWithCustomIndices) const
Export triangles from a zone.
friend Zone2 * zoneUnion(Zone2 *pZone0, Zone2 *pZone1)
Compute the union of two zones.
void showVtk(VtkWriter *pVtk, VtkColor zoneColor, VtkColor nonZoneColor=VTK_TRANSPARENT, VtkColor constraintColor=VTK_TRANSPARENT) const
VTK visualization.
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:78
std::vector< std::vector< Edge2 > > * pvvHolePolygons
Ordered hole polygons.
Definition: Zone2.h:86
std::vector< Edge2 > * pvOuterPolygon
Ordered outer polygon.
Definition: Zone2.h:85
std::vector< Triangle2 * > * pvCC
Connected component of triangles (connection along edges, not just vertices)
Definition: Zone2.h:84
FadeExport is a simple struct to export triangulation data.
Definition: FadeExport.h:43