1 | /*
|
---|
2 | * tesselation.hpp
|
---|
3 | *
|
---|
4 | * The tesselation class is meant to contain the envelope (concave, convex or neither) of a set of Vectors.
|
---|
5 | * As we actually mean this stuff for atoms, we have to encapsulate it all a bit.
|
---|
6 | *
|
---|
7 | * Created on: Aug 3, 2009
|
---|
8 | * Author: heber
|
---|
9 | */
|
---|
10 |
|
---|
11 | #ifndef TESSELATION_HPP_
|
---|
12 | #define TESSELATION_HPP_
|
---|
13 |
|
---|
14 | using namespace std;
|
---|
15 |
|
---|
16 | /*********************************************** includes ***********************************/
|
---|
17 |
|
---|
18 | // include config.h
|
---|
19 | #ifdef HAVE_CONFIG_H
|
---|
20 | #include <config.h>
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #include <map>
|
---|
24 | #include <list>
|
---|
25 | #include <set>
|
---|
26 | #include <stack>
|
---|
27 |
|
---|
28 | #include "BoundaryMaps.hpp"
|
---|
29 | #include "BoundaryPointSet.hpp"
|
---|
30 | #include "PointCloud.hpp"
|
---|
31 | #include "TesselPoint.hpp"
|
---|
32 | #include "atom_particleinfo.hpp"
|
---|
33 | #include "Helpers/helpers.hpp"
|
---|
34 | #include "LinearAlgebra/Vector.hpp"
|
---|
35 |
|
---|
36 |
|
---|
37 | /****************************************** forward declarations *****************************/
|
---|
38 |
|
---|
39 | class BoundaryPointSet;
|
---|
40 | class BoundaryLineSet;
|
---|
41 | class BoundaryTriangleSet;
|
---|
42 | class CandidateForTesselation;
|
---|
43 | class LinkedCell;
|
---|
44 | class Tesselation;
|
---|
45 | class Plane;
|
---|
46 |
|
---|
47 | /********************************************** definitions *********************************/
|
---|
48 |
|
---|
49 | enum { DoTecplotOutput=1 };
|
---|
50 | enum { DoRaster3DOutput=1 };
|
---|
51 | enum { DoVRMLOutput=0 };
|
---|
52 |
|
---|
53 | extern "C" const char *TecplotSuffix;
|
---|
54 | extern "C" const char *Raster3DSuffix;
|
---|
55 | extern "C" const char *VRMLSUffix;
|
---|
56 |
|
---|
57 | extern "C" const double ParallelEpsilon;
|
---|
58 |
|
---|
59 | // ======================================================= some template functions =========================================
|
---|
60 |
|
---|
61 | /********************************************** declarations *******************************/
|
---|
62 |
|
---|
63 | // =========================================================== class TESSELATION ===========================================
|
---|
64 |
|
---|
65 | /** Contains the envelope to a PointCloud.
|
---|
66 | */
|
---|
67 | class Tesselation : public PointCloud {
|
---|
68 | public:
|
---|
69 |
|
---|
70 | Tesselation();
|
---|
71 | virtual ~Tesselation();
|
---|
72 |
|
---|
73 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
---|
74 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
---|
75 | void AddTesselationLine(const Vector * OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
76 | void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
77 | void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
|
---|
78 | void AddTesselationTriangle();
|
---|
79 | void AddTesselationTriangle(const int nr);
|
---|
80 | void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
|
---|
81 | void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
|
---|
82 | void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
|
---|
83 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
84 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
85 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
86 | bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const;
|
---|
87 |
|
---|
88 |
|
---|
89 | // concave envelope
|
---|
90 | bool FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
|
---|
91 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
---|
92 | void FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
|
---|
93 | bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
|
---|
94 | bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList);
|
---|
95 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
---|
96 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
---|
97 |
|
---|
98 | // convex envelope
|
---|
99 | void TesselateOnBoundary(const PointCloud * const cloud);
|
---|
100 | void GuessStartingTriangle();
|
---|
101 | bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
|
---|
102 | double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
|
---|
103 | class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
|
---|
104 | double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
|
---|
105 | class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
|
---|
106 | IndexToIndex * FindAllDegeneratedTriangles();
|
---|
107 | IndexToIndex * FindAllDegeneratedLines();
|
---|
108 | void RemoveDegeneratedTriangles();
|
---|
109 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
|
---|
110 | int CorrectAllDegeneratedPolygons();
|
---|
111 |
|
---|
112 | TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
|
---|
113 | TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
|
---|
114 | ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
115 | ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
116 | TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
|
---|
117 | TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
|
---|
118 | class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
---|
119 | TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
|
---|
120 | TriangleList * FindClosestTrianglesToVector(const Vector &x, const LinkedCell* LC) const;
|
---|
121 | BoundaryTriangleSet * FindClosestTriangleToVector(const Vector &x, const LinkedCell* LC) const;
|
---|
122 | bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
|
---|
123 | double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
|
---|
124 | double GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const;
|
---|
125 | BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const;
|
---|
126 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
---|
127 | DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector &x, const LinkedCell* LC) const;
|
---|
128 | BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector &x, const LinkedCell* LC) const;
|
---|
129 |
|
---|
130 | // print for debugging
|
---|
131 | void PrintAllBoundaryPoints(ofstream *out) const;
|
---|
132 | void PrintAllBoundaryLines(ofstream *out) const;
|
---|
133 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
---|
134 |
|
---|
135 | // store envelope in file
|
---|
136 | void Output(const char *filename, const PointCloud * const cloud);
|
---|
137 |
|
---|
138 | PointMap PointsOnBoundary;
|
---|
139 | LineMap LinesOnBoundary;
|
---|
140 | CandidateMap OpenLines;
|
---|
141 | TriangleMap TrianglesOnBoundary;
|
---|
142 | int PointsOnBoundaryCount;
|
---|
143 | int LinesOnBoundaryCount;
|
---|
144 | int TrianglesOnBoundaryCount;
|
---|
145 |
|
---|
146 | typedef PointMap::iterator iterator;
|
---|
147 | typedef PointMap::const_iterator const_iterator;
|
---|
148 | TesselPoint * getValue(const_iterator &rhs) const;
|
---|
149 | TesselPoint * getValue(iterator &rhs) const;
|
---|
150 | iterator begin() { return PointsOnBoundary.begin(); }
|
---|
151 | const_iterator begin() const { return PointsOnBoundary.begin(); }
|
---|
152 | iterator end() { return PointsOnBoundary.end(); }
|
---|
153 | const_iterator end() const { return PointsOnBoundary.end(); }
|
---|
154 | // PointCloud implementation for PointsOnBoundary
|
---|
155 | virtual Vector *GetCenter(ofstream *out) const;
|
---|
156 | virtual TesselPoint *GetPoint() const;
|
---|
157 | virtual void GoToNext() const;
|
---|
158 | virtual void GoToFirst() const;
|
---|
159 | virtual bool IsEmpty() const;
|
---|
160 | virtual bool IsEnd() const;
|
---|
161 |
|
---|
162 | class BoundaryPointSet *BPS[2];
|
---|
163 | class BoundaryLineSet *BLS[3];
|
---|
164 | class BoundaryTriangleSet *BTS;
|
---|
165 | class BoundaryTriangleSet *LastTriangle;
|
---|
166 | int TriangleFilesWritten;
|
---|
167 |
|
---|
168 | private:
|
---|
169 | static const double HULLEPSILON; //!< TODO: Get rid of HULLEPSILON, points to numerical instabilities
|
---|
170 |
|
---|
171 | mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
172 |
|
---|
173 | mutable PointMap::const_iterator InternalPointer;
|
---|
174 |
|
---|
175 | //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
|
---|
176 | void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
|
---|
177 | };
|
---|
178 |
|
---|
179 |
|
---|
180 | #endif /* TESSELATION_HPP_ */
|
---|