Fade2D Documentation pages v1.86
Delaunay Features
Zone2.h
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 #pragma once
19 
20 #include "common.h"
21 #include "Bbox2.h"
22 #include "Edge2.h"
23 #include "Segment2.h"
24 #include "UserPredicates.h"
25 #include "MsgBase.h"
26 
27 
28 
29 #if GEOM_PSEUDO3D==GEOM_TRUE
30  namespace GEOM_FADE25D {
31 #elif GEOM_PSEUDO3D==GEOM_FALSE
32  namespace GEOM_FADE2D {
33 #else
34  #error GEOM_PSEUDO3D is not defined
35 #endif
36 
37 
38 enum OptimizationMode
39 {
40  OPTMODE_STANDARD,
41  OPTMODE_BETTER,
42  OPTMODE_BEST
43 };
44 
45 class Progress; // FWD
46 class Dt2; // Fwd
47 class ConstraintGraph2; // Fwd
48 class Triangle2; // Fwd
49 class Point2; // Fwd
50 class Visualizer2; // Fwd
51 class Visualizer3; // Fwd
60 class CLASS_DECLSPEC Zone2
61 {
62 public:
64  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_);
66  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,ConstraintGraph2* pConstraintGraph_);
68  Zone2(Dt2* pDt_,ZoneLocation zoneLoc_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_);
70  Zone2(Dt2* pDt_,const std::vector<ConstraintGraph2*>& vConstraintGraphs_,ZoneLocation zoneLoc_,std::vector<Point2>& vStartPoints);
72  ~Zone2();
73 
92  bool save(const char* filename);
93 
99  void subscribe(MsgType msgType,MsgBase* pMsg);
105  void unsubscribe(MsgType msgType,MsgBase* pMsg);
116  ZoneLocation getZoneLocation() const;
117 
130  Zone2* convertToBoundedZone();
131 
139  void show(const char* postscriptFilename,bool bShowFull,bool bWithConstraints) const;
140 
148  void show(Visualizer2* pVisualizer,bool bShowFull,bool bWithConstraints) const;
149 
150 
151 
152 
153 
154 #if GEOM_PSEUDO3D==GEOM_TRUE
155 
161  void showGeomview(const char* filename,const char* color) const;
168  void showGeomview(Visualizer3* pVis,const char* color) const;
169 
171  void analyzeAngles(const char* name="");
172 
185  void smoothing(int numIterations=2);
186 
207  void slopeValleyRidgeOptimization(OptimizationMode om=OPTMODE_BETTER);
208 
210  /*
211  * This function is deprecated but kept for backwards compatibility.
212  * Better use slopeValleyRidgeOptimization() (see above)
213  *
214  * Optimize Valleys and Ridges
215  *
216  * A Delaunay triangulation is not unique when when 2 or more triangles
217  * share a common circumcircle. As a consequence the four corners of
218  * a rectangle can be triangulated in two different ways: Either the
219  * diagonal proceeds from the lower left to the upper right corner
220  * or it connects the other two corners. Both solutions are valid and
221  * an arbitrary one is applied when points are triangulated. To improve
222  * the repeatability and for reasons of visual appearance this method
223  * unifies such diagonals such that they point from the lower left to
224  * the upper right corner (or in horizontal direction).\n
225  *
226  * Moreover a Delaunay triangulation does not take the z-value into
227  * account and thus valleys and ridges may be disturbed. The present
228  * method flips diagonals such that they point from the lower left to
229  * the upper right corner of a quad. And if the 2.5D lengths of the
230  * diagonals are significantly different, then the shorter one is
231  * applied.
232  *
233  * @param tolerance2D is 0 when only exact cases of more than 3 points
234  * on a common circumcircle shall be changed. But in practice input
235  * data can be disturbed by noise and tiny rounding errors such that
236  * grid points are not exactly on a grid. The numeric error is computed
237  * as \f$error=\frac{abs(diagonalA-diagonalB)}{max(diagonalA,diagonalB)}\f$.
238  * and \p tolerance2D is an upper threshold to allow modification despite
239  * such tiny inaccuracies.
240  * @param lowerThreshold25D is used to take also the heights of the
241  * involved points into account. For example, the points\n
242  * \n
243  * Point_2 a(0,0,0);\n
244  * Point_2 b(10,0,0);\n
245  * Point_2 c(10,10,0);\n
246  * Point_2 d(0,10,1000);\n
247  * \n
248  * can form the triangles (a,b,c) and (a,c,d) or the triangles (a,b,d)
249  * and (d,b,c) but (a,c) is obviousy the better diagonal because the
250  * points a,b,c share the same elevation while d is at z=1000.
251  * Technically spoken, the diagonal with the smaller 2.5D-length is
252  * applied if the both, the 2D error is below \p tolerance2D and the
253  * 2.5D error is above \p lowerThreshold25D. The 2.5D
254  * criterion has priority over the 2D criterion.
255  *
256  */
257  void optimizeValleysAndRidges(double tolerance2D,double lowerThreshold25D);
258 #endif
259 
282  void unifyGrid(double tolerance);
283 
285  bool assignDt2(Dt2* pDt_);
286 
297  void getTriangles(std::vector<Triangle2*>& vTriangles_) const;
298 
302  void getVertices(std::vector<Point2*>& vVertices_) const;
303 
304 
309  void statistics(const char* s) const;
310 
311 
316  ConstraintGraph2* getConstraintGraph() const;
317 
322  size_t getNumberOfTriangles() const;
323 
324 
328  void getConstraintGraphs(std::vector<ConstraintGraph2*>& vConstraintGraphs_) const;
329 
331  Dt2* getDelaunayTriangulation() const;
332 
337  size_t numberOfConstraintGraphs() const;
338 
341  void debug(const char* name="");
342 
345  Bbox2 getBoundingBox() const;
346 
349  void getBoundaryEdges(std::vector<Edge2>& vEdges) const;
350 
353  void getBoundarySegments(std::vector<Segment2>& vSegments) const;
354 
367  double getArea2D() const;
368 
369 
370 #if GEOM_PSEUDO3D==GEOM_TRUE
371 
378  double getArea25D() const;
379 #endif
380 
384  void getBorderEdges(std::vector<Edge2>& vBorderEdgesOut) const;
385 
392  void writeObj(const char* outFilename) const;
393 
394 
395 
396 protected:
397  // Optimization techniques
399  void optMode_standard_sub(std::vector<Triangle2*>& vT,std::vector<Triangle2*>& vChangedT);
401  void optMode_standard();
403  double optMode_prioq(double noEdgeBelowDih,bool bWithProgress);
405  void getEdgesForOptimization(double noEdgeBelowDegree,std::vector<Edge2>& vEdges);
407  void optMode_simulatedAnnealing();
409  void optMode_simulatedAnnealing_sub(std::vector<Edge2>& vUniqueEdges,double temperature);
410 
411 
413  Zone2(const Zone2&);
415  void getTriangles_RESULT(std::vector<Triangle2*>& vTriangles) const;
417  void initWorkspace(bool bInside,std::vector<Triangle2*>& vWorkspace) const;
419  void bfsFromWorkspace(std::vector<Triangle2*>& vWorkspace,std::vector<Triangle2*>& vTriangles) const;
421  Zone2* ctbz_treatCC(std::vector<Triangle2*>& vOneCC);
422  // Data
423  Dt2* pDt;
424  Progress* pZoneProgress;
425  ZoneLocation zoneLoc;
426  CLASS_DECLSPEC
427  friend Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
428  CLASS_DECLSPEC
429  friend Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
430  CLASS_DECLSPEC
431  friend Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
432  CLASS_DECLSPEC
433  friend Zone2* zoneSymmetricDifference(Zone2* pZone0,Zone2* pZone1);
434  CLASS_DECLSPEC
435  friend Zone2* peelOffIf(Zone2* pZone, UserPredicateT* pPredicate,bool bVerbose);
436 
437 private:
438 #ifdef _WIN32
439 #pragma warning(push)
440 #pragma warning(disable:4251)
441 #endif
442  std::vector<ConstraintGraph2*> vConstraintGraphs;
443  std::vector<Point2> vStartPoints;
444  std::vector<Zone2*> vInputZones;
445 #ifdef _WIN32
446 #pragma warning(pop)
447 #endif
448 
449 };
450 
451 // Free functions
452 
457 CLASS_DECLSPEC
458 Zone2* zoneUnion(Zone2* pZone0,Zone2* pZone1);
463 CLASS_DECLSPEC
464 Zone2* zoneIntersection(Zone2* pZone0,Zone2* pZone1);
469 CLASS_DECLSPEC
470 Zone2* zoneDifference(Zone2* pZone0,Zone2* pZone1);
476 CLASS_DECLSPEC
477 Zone2* zoneSymmetricDifference(Zone2* pZone0,Zone2* pZone1);
478 
479 
480 
481 
482 } // (namespace)
GEOM_FADE2D::MsgBase
MsgBase, a base class for message subscriber classes.
Definition: MsgBase.h:45
GEOM_FADE2D::Zone2
Zone2 is a certain defined area of a triangulation.
Definition: Zone2.h:60
GEOM_FADE2D::ConstraintGraph2
ConstraintGraph2 is a set of Constraint Edges (ConstraintSegment2)
Definition: ConstraintGraph2.h:50
GEOM_FADE2D::Visualizer2
Visualizer2 is a general Postscript writer. It draws the objects Point2, Segment2,...
Definition: Visualizer2.h:54
GEOM_FADE2D::getArea2D
double getArea2D(Point2 *p0, Point2 *p1, Point2 *p2)
Get 2D area of a triangle.
Bbox2.h
GEOM_FADE2D::UserPredicateT
User defined predicate.
Definition: UserPredicates.h:36
GEOM_FADE2D::Bbox2
Bbox2 is an axis aligned 2D bounding box.
Definition: Bbox2.h:36