Fade2.5D Documentation pages v2.13
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 "sortMT.h"
31 
32 
33 #if GEOM_PSEUDO3D==GEOM_TRUE
34  namespace GEOM_FADE25D {
35 #elif GEOM_PSEUDO3D==GEOM_FALSE
36  namespace GEOM_FADE2D {
37 #else
38  #error GEOM_PSEUDO3D is not defined
39 #endif
40 
49 {
53 };
54 
55 class Progress; // FWD
56 class Dt2; // Fwd
57 class ConstraintGraph2; // Fwd
58 class Triangle2; // Fwd
59 class Point2; // Fwd
60 class Visualizer2; // Fwd
61 class Visualizer3; // Fwd
62 
63 
76 struct CLASS_DECLSPEC CompPolygon
77 {
78  CompPolygon();
79  CompPolygon(const CompPolygon& other);
80  CompPolygon& operator=(const CompPolygon& other);
81  ~CompPolygon();
82  // Data
83  std::vector<Triangle2*>* pvCC;
84  std::vector<Edge2>* pvOuterPolygon;
85  std::vector<std::vector<Edge2> >* pvvHolePolygons;
86 };
87 
94 class CLASS_DECLSPEC Zone2
95 {
96 public:
98  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_);
100  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,ConstraintGraph2* pConstraintGraph_);
102  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_);
104  Zone2(Dt2* pDt_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_,ZoneLocation zoneLoc_,std::vector<Point2>& vStartPoints);
106  ~Zone2();
107 
127  bool save(const char* filename);
128 
147  bool save(std::ostream& stream);
148 
149 
156  void exportZone(FadeExport& fadeExport,bool bWithCustomIndices) const;
157 
158 
159 
160 
166  void subscribe(MsgType msgType,MsgBase* pMsg);
172  void unsubscribe(MsgType msgType,MsgBase* pMsg);
183  ZoneLocation getZoneLocation() const;
184 
198 
206  void show(const char* postscriptFilename,bool bShowFull,bool bWithConstraints) const;
207 
215  void show(Visualizer2* pVisualizer,bool bShowFull,bool bWithConstraints) const;
216 
217 
218 
219 
220 
221 #if GEOM_PSEUDO3D==GEOM_TRUE
228  void showGeomview(const char* filename,const char* color) const;
235  void showGeomview(Visualizer3* pVis,const char* color) const;
236 
238  void analyzeAngles(const char* name="");
239 
252  void smoothing(int numIterations=2,bool bWithXY=true);
253 
254 
276 
278  /*
279  * This function is deprecated but kept for backwards compatibility.
280  * Better use slopeValleyRidgeOptimization() (see above)
281  *
282  * Optimize Valleys and Ridges
283  *
284  * A Delaunay triangulation is not unique when when 2 or more triangles
285  * share a common circumcircle. As a consequence the four corners of
286  * a rectangle can be triangulated in two different ways: Either the
287  * diagonal proceeds from the lower left to the upper right corner
288  * or it connects the other two corners. Both solutions are valid and
289  * an arbitrary one is applied when points are triangulated. To improve
290  * the repeatability and for reasons of visual appearance this method
291  * unifies such diagonals such that they point from the lower left to
292  * the upper right corner (or in horizontal direction).\n
293  *
294  * Moreover a Delaunay triangulation does not take the z-value into
295  * account and thus valleys and ridges may be disturbed. The present
296  * method flips diagonals such that they point from the lower left to
297  * the upper right corner of a quad. And if the 2.5D lengths of the
298  * diagonals are significantly different, then the shorter one is
299  * applied.
300  *
301  * @param tolerance2D is 0 when only exact cases of more than 3 points
302  * on a common circumcircle shall be changed. But in practice input
303  * data can be disturbed by noise and tiny rounding errors such that
304  * grid points are not exactly on a grid. The numeric error is computed
305  * as \f$error=\frac{abs(diagonalA-diagonalB)}{max(diagonalA,diagonalB)}\f$.
306  * and \p tolerance2D is an upper threshold to allow modification despite
307  * such tiny inaccuracies.
308  * @param lowerThreshold25D is used to take also the heights of the
309  * involved points into account. For example, the points\n
310  * \n
311  * Point_2 a(0,0,0);\n
312  * Point_2 b(10,0,0);\n
313  * Point_2 c(10,10,0);\n
314  * Point_2 d(0,10,1000);\n
315  * \n
316  * can form the triangles (a,b,c) and (a,c,d) or the triangles (a,b,d)
317  * and (d,b,c) but (a,c) is obviousy the better diagonal because the
318  * points a,b,c share the same elevation while d is at z=1000.
319  * Technically spoken, the diagonal with the smaller 2.5D-length is
320  * applied if the both, the 2D error is below \p tolerance2D and the
321  * 2.5D error is above \p lowerThreshold25D. The 2.5D
322  * criterion has priority over the 2D criterion.
323  *
324  */
325  void optimizeValleysAndRidges(double tolerance2D,double lowerThreshold25D);
326 #endif
327 
350  void unifyGrid(double tolerance);
351 
353  bool assignDt2(Dt2* pDt_);
354 
365  void getTriangles(std::vector<Triangle2*>& vTriangles_) const;
366 
370  void getVertices(std::vector<Point2*>& vVertices_) const;
371 
372 
377  void statistics(const char* s) const;
378 
379 
385 
390  size_t getNumberOfTriangles() const;
391 
392 
396  void getConstraintGraphs(std::vector<ConstraintGraph2*>& vConstraintGraphs_) const;
397 
399  Dt2* getDelaunayTriangulation() const;
400 
405  size_t numberOfConstraintGraphs() const;
406 
409  void debug(const char* name="");
410 
414 
415  // Deprecated, replaced by getBorderEdges() but kept for
416  // backwards-compatibility.
419  void getBoundaryEdges(std::vector<Edge2>& vEdges) const;
420 
431  void getComponentPolygons(std::vector<CompPolygon>& vCompPolygons) const;
432 
438  void getBoundarySegments(std::vector<Segment2>& vSegments) const;
439 
452  double getArea2D() const;
453 
454 
455 #if GEOM_PSEUDO3D==GEOM_TRUE
463  double getArea25D() const;
464 #endif
465 
469  void getBorderEdges(std::vector<Edge2>& vBorderEdgesOut) const;
470 
477  void writeObj(const char* outFilename) const;
478 
479 #ifndef SKIPTHREADS
480 #if GEOM_PSEUDO3D==GEOM_TRUE
488  bool writePly(const char* filename,bool bASCII=false) const;
496  bool writePly(std::ostream& os,bool bASCII=false) const;
497 #endif
498 #endif
499 
500 
501 
502 protected:
503 
504 
505 
506 
507  Zone2& operator=(const Zone2&);
508  // Optimization techniques
510  void optMode_standard_sub(std::vector<Triangle2*>& vT,std::vector<Triangle2*>& vChangedT);
512  void optMode_standard();
514  double optMode_prioq(double noEdgeBelowDih,bool bWithProgress);
516  void getEdgesForOptimization(double noEdgeBelowDegree,std::vector<Edge2>& vEdges);
518  void optMode_simulatedAnnealing();
520  void optMode_simulatedAnnealing_sub(std::vector<Edge2>& vUniqueEdges,double temperature);
521 
523  void removeConstraintEdges(std::vector<Edge2>& vEdges) const;
524 
526  Zone2(const Zone2&);
528  void getTriangles_RESULT(std::vector<Triangle2*>& vTriangles) const;
530  void initWorkspace(bool bInside,std::vector<Triangle2*>& vWorkspace) const;
532  void bfsFromWorkspace(std::vector<Triangle2*>& vWorkspace,std::vector<Triangle2*>& vTriangles) const;
534  Zone2* ctbz_treatCC(std::vector<Triangle2*>& vOneCC);
535  // Data
537  Dt2* pDt;
539  Progress* pZoneProgress;
541  ZoneLocation zoneLoc;
542  CLASS_DECLSPEC
543  friend Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
544  CLASS_DECLSPEC
545  friend Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
546  CLASS_DECLSPEC
547  friend Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
548  CLASS_DECLSPEC
549  friend Zone2* zoneSymmetricDifference(Zone2* pZone0,Zone2* pZone1);
550  // This version is deprecated (but still valid) in favor of the
551  // version that takes a PeelPredicateTS.
568  CLASS_DECLSPEC
569  friend Zone2* peelOffIf(Zone2* pZone, UserPredicateT* pPredicate,bool bVerbose);
583  CLASS_DECLSPEC
584  friend Zone2* peelOffIf(Zone2* pZone, bool bAvoidSplit,PeelPredicateTS* pPredicate);
585 
586 
587 
588 private:
589 #ifndef __MINGW32__
590 #ifdef _WIN32
591 #pragma warning(push)
592 #pragma warning(disable:4251)
593 #endif
594 #endif
595  std::vector<ConstraintGraph2*> vConstraintGraphs;
596  std::vector<Point2> vStartPoints;
597  std::vector<Zone2*> vInputZones;
598 
599 #ifndef __MINGW32__
600 #ifdef _WIN32
601 #pragma warning(pop)
602 #endif
603 #endif
604 };
605 
606 // Free functions
607 
612 CLASS_DECLSPEC
613 Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
618 CLASS_DECLSPEC
619 Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
624 CLASS_DECLSPEC
625 Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
631 CLASS_DECLSPEC
633 
634 
635 
636 
637 } // (namespace)
Zone2 * zoneUnion(Zone2 *pZone0, Zone2 *pZone1)
Compute the union of two zones.
Zone2 * zoneDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the difference of two zones.
OptimizationMode
Definition: Zone2.h:49
@ OPTMODE_BEST
Best quality but quite time consuming.
Definition: Zone2.h:52
@ OPTMODE_STANDARD
Fastest optimization mode.
Definition: Zone2.h:50
@ OPTMODE_BETTER
Considerably better quality and still fast.
Definition: Zone2.h:51
Zone2 * zoneSymmetricDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the symmetric difference of two zones.
Zone2 * zoneIntersection(Zone2 *pZone0, Zone2 *pZone1)
Compute the intersection of two zones.
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
Visualizer3 is a 3D scene writer for the Geomview viewer.
Definition: Visualizer3.h:37
Zone2 is a certain defined area of a triangulation.
Definition: Zone2.h:95
void getTriangles(std::vector< Triangle2 * > &vTriangles_) const
Get the triangles of the zone.
void subscribe(MsgType msgType, MsgBase *pMsg)
Register a message receiver.
friend Zone2 * peelOffIf(Zone2 *pZone, UserPredicateT *pPredicate, bool bVerbose)
Peel off border triangles (deprecated)
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.
ConstraintGraph2 * getConstraintGraph() const
Get the associated constraint.
Bbox2 getBoundingBox() const
Compute the bounding box.
void writeObj(const char *outFilename) const
Write the zone to *.obj Writes the triangles of the present Zone2 to an *.obj file (The *....
void getComponentPolygons(std::vector< CompPolygon > &vCompPolygons) const
Get connected components and their boundary polygons.
bool save(std::ostream &stream)
Save the zone.
ZoneLocation getZoneLocation() const
Get the zone location.
void unifyGrid(double tolerance)
void getConstraintGraphs(std::vector< ConstraintGraph2 * > &vConstraintGraphs_) const
Get the associated constraint graphs.
void show(Visualizer2 *pVisualizer, bool bShowFull, bool bWithConstraints) const
Postscript visualization.
void exportZone(FadeExport &fadeExport, bool bWithCustomIndices) const
Export triangles from a zone.
friend Zone2 * zoneIntersection(Zone2 *pZone0, Zone2 *pZone1)
Compute the intersection of two zones.
void showGeomview(const char *filename, const char *color) const
Geomview visualization.
double getArea2D() const
Get 2D Area.
void getVertices(std::vector< Point2 * > &vVertices_) const
Get the vertices of the zone.
bool writePly(std::ostream &os, bool bASCII=false) const
Write the zone to a *.ply file.
Zone2 * convertToBoundedZone()
Convert a zone to a bounded zone.
double getArea25D() const
Get 2.5D Area.
void getBorderEdges(std::vector< Edge2 > &vBorderEdgesOut) const
Get border edges.
void showGeomview(Visualizer3 *pVis, const char *color) const
Geomview visualization.
friend Zone2 * zoneSymmetricDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the symmetric difference of two zones.
void show(const char *postscriptFilename, bool bShowFull, bool bWithConstraints) const
Postscript visualization.
size_t numberOfConstraintGraphs() const
Get a the number of ConstraintGraph2 objects.
friend Zone2 * zoneUnion(Zone2 *pZone0, Zone2 *pZone1)
Compute the union of two zones.
void statistics(const char *s) const
friend Zone2 * peelOffIf(Zone2 *pZone, bool bAvoidSplit, PeelPredicateTS *pPredicate)
Peel off border triangles.
bool save(const char *filename)
Save the zone.
bool writePly(const char *filename, bool bASCII=false) const
Write the zone to a *.ply file.
void getBoundarySegments(std::vector< Segment2 > &vSegments) const
Compute the boundary segments.
void smoothing(int numIterations=2, bool bWithXY=true)
Smoothing.
void slopeValleyRidgeOptimization(OptimizationMode om=OPTMODE_BETTER)
Optimize Slopes, Valleys and Ridges.
friend Zone2 * zoneDifference(Zone2 *pZone0, Zone2 *pZone1)
Compute the difference of two zones.
Connected component with boundary- and hole polygons.
Definition: Zone2.h:77
std::vector< std::vector< Edge2 > > * pvvHolePolygons
Ordered hole polygons.
Definition: Zone2.h:85
std::vector< Edge2 > * pvOuterPolygon
Ordered outer polygon.
Definition: Zone2.h:84
std::vector< Triangle2 * > * pvCC
Connected component of triangles (connection along edges, not just vertices)
Definition: Zone2.h:83
FadeExport is a simple struct to export triangulation data.
Definition: FadeExport.h:43