Fade2.5D Documentation pages v2.15
Delaunay Features
freeFunctions.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 
18 
20 #pragma once
21 #include "Point2.h"
22 #include "Segment2.h"
23 #include "Edge2.h"
24 #include <vector>
25 
26 
27 #if GEOM_PSEUDO3D==GEOM_TRUE
28  namespace GEOM_FADE25D {
29 #elif GEOM_PSEUDO3D==GEOM_FALSE
30  namespace GEOM_FADE2D {
31 #else
32  #error GEOM_PSEUDO3D is not defined
33 #endif
34 
35 class Mesh3; // FWD
36 class Zone2; // FWD
37 
47 CLASS_DECLSPEC
48 void simplifyPolygon(const std::vector<Point2>& vIn,double errBound,std::vector<Point2>& vOut);
49 
50 
51 
53 // *
54 // * <div class="row">
55 // * \image html offset_polygon_without_angle_correction.jpg "Offset polygon without angle correction"
56 // * \image html offset_polygon_90_degrees.jpg "Offset polygon with maximum angle correction factor 1.414 (down to 90 degrees)"
57 // * \image html offset_polygon_18.4_degrees.jpg "Offset polygon with angle correction limited to factor 6.25 (for angles as low as 18.4 degrees)"
58 // * </div>
59 // * \image latex offset_polygon_without_angle_correction.eps "Offset polygon without angle correction" width=4cm
60 // * \image latex offset_polygon_90_degrees.eps "Offset polygon with angle correction factor 1.414 (down to 90 degrees)" width=4cm
61 // * \image latex offset_polygon_18.4_degrees.eps "Offset polygon with angle correction factor 6.25 (for angles as low as 18.4 degrees)" width=4cm
62 // *
63 // *
64 // * @param offset specifies the offset distance (positive or negative)
65 // * @param [in] vOrgPoints are ordered points of a <em>counterclockwise</em>
66 // * polygon (no point repeated)
67 // * @param [out] vOffsetPoints returns points moved outside/inside by a
68 // * positive/negative offset distance (times the angle correction factor)
69 // * @param [in] maxCorrectionFactor is the maximum angle correction
70 // * factor that may be applied to the \p offset value. It's default
71 // * value is 1.0 (no angle correction), lower values are ignored.
72 // * The angle that can be corrected with a certain maxCorrectionFactor
73 // * is computed according to \f$ 2*asin(1.0/maxCorrectionFactor) \f$. This means,
74 // * a maxCorrectionFactor=1.4143 can account for angles down to 90 degrees
75 // * while 2.6132 is required to correct angles as low as 45 degrees.
76 // *
77 // * @note You may want to simplify and smooth the input polygon using
78 // * `simplifyPolygon()` before using this function.
79 // *
80 // * @warning The resuling offset polygon may self-intersect!
81 // */
82 
83 // Deprecated, but kept for backwards compatibility, September 12, 2024: Use the new
84 // method Zone2::getOffsetBoundary() instead, because it removes self-intersections.
85 CLASS_DECLSPEC
87  double offset,
88  const std::vector<Point2>& vOrgPoints,
89  std::vector<Point2>& vOffsetPoints,
90  double maxCorrectionFactor=1.0
91  );
92 
99 CLASS_DECLSPEC
100 void untwistPolygon(std::vector<Segment2>& vPolygon,std::vector<std::vector<Segment2> >& vvPolygon);
101 
102 
119 CLASS_DECLSPEC
120 int setGlobalNumCPU(int numCPU);
121 
128 CLASS_DECLSPEC
130 
131 
132 // Expects _one_ edge-connected component. No problem if the component
133 // forms a ring around a void that touches only at one vertex. But keep
134 // in mind that two completely disjoint borders may exist. This is why
135 // we use sIgnorePairs.
155 CLASS_DECLSPEC
156 void getSortedBoundaryPolygons( std::vector<Triangle2*>& vConnectedComponent,
157  std::vector<Edge2>& vOutsidePolygon,
158  std::vector<std::vector<Edge2> >& vHolePolygons
159  );
160 
161 
179 CLASS_DECLSPEC
180 void pointsToPolyline(std::vector<Point2>& vInPoints,bool bClose,std::vector<Segment2>& vOutSegments);
181 
182 
183 
192 CLASS_DECLSPEC
193 bool isSimplePolygon(std::vector<Segment2>& vSegments);
194 
195 #if GEOM_PSEUDO3D==GEOM_TRUE
207 CLASS_DECLSPEC
209  const Point2& p1,
210  const Point2& p2,
211  bool& bOK);
212 #endif
213 
214 
215 
216 
217 #if GEOM_PSEUDO3D==GEOM_TRUE
227 CLASS_DECLSPEC
228 double getArea25D(const Point2* p0,const Point2* p1,const Point2* p2);
229 #endif
230 
231 
245 CLASS_DECLSPEC
246 double getArea2D(const Point2* p0,const Point2* p1,const Point2* p2);
247 
248 
254 CLASS_DECLSPEC
255 void getDirectedEdges(const std::vector<Triangle2*>& vT,std::vector<Edge2>& vDirectedEdgesOut);
256 
261 CLASS_DECLSPEC
262 void getUndirectedEdges(const std::vector<Triangle2*>& vT,std::vector<Edge2>& vUndirectedEdgesOut);
263 
274 CLASS_DECLSPEC
275 void getConnectedComponents( const std::vector<Triangle2*>& vT,
276  std::vector<std::vector<Triangle2*> >& vvT
277  );
278 
279 
303 CLASS_DECLSPEC
304 bool fillHole( const std::vector<std::pair<Segment2,Vector2> >& vPolygonSegments,
305  bool bWithRefine,
306  bool bVerbose,
307  std::vector<Point2>& vCornersOut
308  );
309 
310 
311 
312 
313 #if GEOM_PSEUDO3D==GEOM_TRUE
332 CLASS_DECLSPEC
333 bool fillHole( const std::vector<Point2>& vMeshCorners,
334  const std::vector<Segment2>& vPolygonSegments,
335  bool bWithRefine,
336  bool bVerbose,
337  std::vector<Point2>& vCornersOut
338  );
339 
357 CLASS_DECLSPEC
358 bool fillHole( Mesh3* pMesh,
359  const std::vector<Edge2>& vPolygonEdges,
360  bool bWithRefine,
361  bool bVerbose,
362  std::vector<Point2>& vCornersOut
363  );
364 #endif
365 
366 
396 CLASS_DECLSPEC
398  const std::vector<Edge2>& vEdgesIn,
399  std::vector<std::vector<Edge2> >& vvPolygonsOut,
400  std::vector<Edge2>& vRemainingOut
401  );
402 
411 CLASS_DECLSPEC
412 void getBorders(const std::vector<Triangle2*>& vT,std::vector<Segment2>& vBorderSegmentsOut);
418 CLASS_DECLSPEC
419 bool sortRing(std::vector<Segment2>& vRing);
420 
421 //CLASS_DECLSPEC
422 //bool temporaryDebug(std::vector<Segment2>& vRing);
423 
430 CLASS_DECLSPEC
431 bool sortRingCCW(std::vector<Segment2>& vRing);
432 
433 
445 CLASS_DECLSPEC
446 Orientation2 getOrientation2(const Point2* p0,const Point2* p1,const Point2* p2);
454 CLASS_DECLSPEC
455 Orientation2 getOrientation2_mt(const Point2* p0,const Point2* p1,const Point2* p2);
456 
458 CLASS_DECLSPEC
459 const char* getString(const Orientation2 ori);
460 
470 CLASS_DECLSPEC
471 const char* getFade2DVersion();
474 CLASS_DECLSPEC
478 CLASS_DECLSPEC
482 CLASS_DECLSPEC
486 CLASS_DECLSPEC
487 bool isRelease();
488 
490 CLASS_DECLSPEC
491 void setLic(
492  const char* l1,
493  const char* l2,
494  const char* dt,
495  const char* s1,
496  const char* s2_
497  );
499 class Lic;
501 Lic* getLic();
502 
518 // READ AND WRITE, ASCII
520 
538 CLASS_DECLSPEC
539 bool writePointsASCII(const char* filename,const std::vector<Point2*>& vPointsIn);
540 
547 CLASS_DECLSPEC
548 bool writePointsASCII(const char* filename,const std::vector<Point2>& vPointsIn);
549 
550 
551 
552 
553 
563 CLASS_DECLSPEC
564 bool readXY(const char* filename,std::vector<Point2>& vPointsOut);
565 
566 #if GEOM_PSEUDO3D==GEOM_TRUE
567 // ONLY 2.5D
573 CLASS_DECLSPEC
574 bool readXYZ(const char* filename,std::vector<Point2>& vPointsOut);
575 #endif
576 
577 
578 
580 // READ AND WRITE, PLY
582 #ifndef SKIPTHREADS
594 CLASS_DECLSPEC
595 bool readPointsPLY(const char* filename,bool bUniquePoints,std::vector<Point2>& vPoints,std::vector<VtxColor>* pVertexColors=NULL);
596 
597 
610 CLASS_DECLSPEC
611 bool readPointsPLY(std::istream& is,bool bUniquePoints,std::vector<Point2>& vPoints,std::vector<VtxColor>* pVertexColors=NULL);
612 
613 
622 CLASS_DECLSPEC
623 bool writePointsPLY(std::ostream& os,std::vector<Point2*>& vPoints,bool bASCII);
624 
625 
634 CLASS_DECLSPEC
635 bool writePointsPLY(const char* filename,std::vector<Point2*>& vPoints,bool bASCII);
636 
637 #endif
638 
639 
640 
642 // READ AND WRITE, BINARY
644 
645 
646 
664 CLASS_DECLSPEC
665 bool writePointsBIN(const char* filename,std::vector<Point2>& vPoints);
666 
684 CLASS_DECLSPEC
685 bool writePointsBIN(const char* filename,std::vector<Point2*>& vPoints);
686 
700 CLASS_DECLSPEC
701 bool readPointsBIN(const char* filename, std::vector<Point2>& vPointsIn,bool bWithHeader=true);
702 
740 CLASS_DECLSPEC
741 bool writeSegmentsBIN(const char* filename,std::vector<Segment2>& vSegmentsIn);
742 
749 CLASS_DECLSPEC
750 bool readSegmentsBIN(const char* filename,std::vector<Segment2>& vSegmentsOut);
751 
752 
753 
754 
755 
756 
758 } // NAMESPACE
Point.
Definition: Point2.h:53
Vector.
Definition: Vector2.h:42
void getSortedBoundaryPolygons(std::vector< Triangle2 * > &vConnectedComponent, std::vector< Edge2 > &vOutsidePolygon, std::vector< std::vector< Edge2 > > &vHolePolygons)
Get sorted boundary polygons.
void untwistPolygon(std::vector< Segment2 > &vPolygon, std::vector< std::vector< Segment2 > > &vvPolygon)
Repair a selfintersecting polygon.
int setGlobalNumCPU(int numCPU)
Set the global number of threads to be used.
void offsetPolygonPoints(double offset, const std::vector< Point2 > &vOrgPoints, std::vector< Point2 > &vOffsetPoints, double maxCorrectionFactor=1.0)
‍**
void simplifyPolygon(const std::vector< Point2 > &vIn, double errBound, std::vector< Point2 > &vOut)
Simplify a polygon.
int getGlobalNumCPU()
Get the global number of threads to be used.
int getMajorVersionNumber()
Get the major version number.
const char * getFade2DVersion()
Get the Fade2D version string.
int getMinorVersionNumber()
Get the minor version number.
int getRevisionNumber()
Get the revision version number.
bool isRelease()
Check if a RELEASE or a DEBUG version is used.
bool readPointsBIN(const char *filename, std::vector< Point2 > &vPointsIn, bool bWithHeader=true)
Read points from a binary file.
bool readXY(const char *filename, std::vector< Point2 > &vPointsOut)
Read (x y) points.
bool readXYZ(const char *filename, std::vector< Point2 > &vPointsOut)
Read (x y z) points.
bool readSegmentsBIN(const char *filename, std::vector< Segment2 > &vSegmentsOut)
Read segments from a binary file.
bool readPointsPLY(std::istream &is, bool bUniquePoints, std::vector< Point2 > &vPoints, std::vector< VtxColor > *pVertexColors=NULL)
Read points from a *.PLY file.
bool writeSegmentsBIN(const char *filename, std::vector< Segment2 > &vSegmentsIn)
Write segments to a binary file.
bool writePointsPLY(const char *filename, std::vector< Point2 * > &vPoints, bool bASCII)
Write points to a *.PLY file.
bool writePointsBIN(const char *filename, std::vector< Point2 * > &vPoints)
Write points to a binary file.
bool writePointsASCII(const char *filename, const std::vector< Point2 > &vPointsIn)
Write points to an ASCII file.
bool isSimplePolygon(std::vector< Segment2 > &vSegments)
isSimplePolygon
void pointsToPolyline(std::vector< Point2 > &vInPoints, bool bClose, std::vector< Segment2 > &vOutSegments)
Points-to-Polyline.
Orientation2 getOrientation2(const Point2 *p0, const Point2 *p1, const Point2 *p2)
Get the orientation of three points.
void getConnectedComponents(const std::vector< Triangle2 * > &vT, std::vector< std::vector< Triangle2 * > > &vvT)
Get connected components.
void getUndirectedEdges(const std::vector< Triangle2 * > &vT, std::vector< Edge2 > &vUndirectedEdgesOut)
Get undirected edges.
double getArea25D(const Point2 *p0, const Point2 *p1, const Point2 *p2)
Get 2.5D area of a triangle.
bool sortRing(std::vector< Segment2 > &vRing)
Sort a vector of Segments.
double getArea2D(const Point2 *p0, const Point2 *p1, const Point2 *p2)
Get 2D area of a triangle.
void getDirectedEdges(const std::vector< Triangle2 * > &vT, std::vector< Edge2 > &vDirectedEdgesOut)
Get directed edges The directed edges of vT are returned in vDirectedEdgesOut. Directed means that ea...
void edgesToPolygons(const std::vector< Edge2 > &vEdgesIn, std::vector< std::vector< Edge2 > > &vvPolygonsOut, std::vector< Edge2 > &vRemainingOut)
Create polygons from a set of edges.
Orientation2 getOrientation2_mt(const Point2 *p0, const Point2 *p1, const Point2 *p2)
Get Orientation2 (MT)
Vector2 getNormalVector(const Point2 &p0, const Point2 &p1, const Point2 &p2, bool &bOK)
Get normal vector.
bool fillHole(Mesh3 *pMesh, const std::vector< Edge2 > &vPolygonEdges, bool bWithRefine, bool bVerbose, std::vector< Point2 > &vCornersOut)
Fill a hole in a 3D mesh with triangles (deprecated)
bool sortRingCCW(std::vector< Segment2 > &vRing)
Sort a vector of Segments.
void getBorders(const std::vector< Triangle2 * > &vT, std::vector< Segment2 > &vBorderSegmentsOut)
Get Borders.