1 | /*
|
---|
2 | * tesselation.hpp
|
---|
3 | *
|
---|
4 | * The tesselation class is meant to contain the envelope (concave, convex or neither) of a set of Vectors. As we actually mean this stuff for atoms, we have to encapsulate it all a bit.
|
---|
5 | *
|
---|
6 | * Created on: Aug 3, 2009
|
---|
7 | * Author: heber
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifndef TESSELATION_HPP_
|
---|
11 | #define TESSELATION_HPP_
|
---|
12 |
|
---|
13 | using namespace std;
|
---|
14 |
|
---|
15 | /*********************************************** includes ***********************************/
|
---|
16 |
|
---|
17 | // include config.h
|
---|
18 | #ifdef HAVE_CONFIG_H
|
---|
19 | #include <config.h>
|
---|
20 | #endif
|
---|
21 |
|
---|
22 | #include <map>
|
---|
23 | #include <list>
|
---|
24 | #include <set>
|
---|
25 | #include <stack>
|
---|
26 |
|
---|
27 | #include "atom_particleinfo.hpp"
|
---|
28 | #include "helpers.hpp"
|
---|
29 | #include "vector.hpp"
|
---|
30 |
|
---|
31 | /****************************************** forward declarations *****************************/
|
---|
32 |
|
---|
33 | class BoundaryPointSet;
|
---|
34 | class BoundaryLineSet;
|
---|
35 | class BoundaryTriangleSet;
|
---|
36 | class LinkedCell;
|
---|
37 | class TesselPoint;
|
---|
38 | class PointCloud;
|
---|
39 | class Tesselation;
|
---|
40 |
|
---|
41 | /********************************************** definitions *********************************/
|
---|
42 |
|
---|
43 | #define DoTecplotOutput 1
|
---|
44 | #define DoRaster3DOutput 1
|
---|
45 | #define DoVRMLOutput 1
|
---|
46 | #define TecplotSuffix ".dat"
|
---|
47 | #define Raster3DSuffix ".r3d"
|
---|
48 | #define VRMLSUffix ".wrl"
|
---|
49 |
|
---|
50 | #define ParallelEpsilon 1e-3
|
---|
51 |
|
---|
52 | // ======================================================= some template functions =========================================
|
---|
53 |
|
---|
54 | #define IndexToIndex map <int, int>
|
---|
55 |
|
---|
56 | #define PointMap map < int, class BoundaryPointSet * >
|
---|
57 | #define PointSet set < class BoundaryPointSet * >
|
---|
58 | #define PointList list < class BoundaryPointSet * >
|
---|
59 | #define PointPair pair < int, class BoundaryPointSet * >
|
---|
60 | #define PointTestPair pair < PointMap::iterator, bool >
|
---|
61 |
|
---|
62 | #define CandidateList list <class CandidateForTesselation *>
|
---|
63 | #define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
|
---|
64 |
|
---|
65 | #define LineMap multimap < int, class BoundaryLineSet * >
|
---|
66 | #define LineSet set < class BoundaryLineSet * >
|
---|
67 | #define LineList list < class BoundaryLineSet * >
|
---|
68 | #define LinePair pair < int, class BoundaryLineSet * >
|
---|
69 | #define LineTestPair pair < LineMap::iterator, bool >
|
---|
70 |
|
---|
71 | #define TriangleMap map < int, class BoundaryTriangleSet * >
|
---|
72 | #define TriangleSet set < class BoundaryTriangleSet * >
|
---|
73 | #define TriangleList list < class BoundaryTriangleSet * >
|
---|
74 | #define TrianglePair pair < int, class BoundaryTriangleSet * >
|
---|
75 | #define TriangleTestPair pair < TrianglePair::iterator, bool >
|
---|
76 |
|
---|
77 | #define PolygonMap map < int, class BoundaryPolygonSet * >
|
---|
78 | #define PolygonSet set < class BoundaryPolygonSet * >
|
---|
79 | #define PolygonList list < class BoundaryPolygonSet * >
|
---|
80 |
|
---|
81 | #define DistanceToPointMap multimap <double, class BoundaryPointSet * >
|
---|
82 | #define DistanceToPointPair pair <double, class BoundaryPointSet * >
|
---|
83 |
|
---|
84 | #define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
85 | #define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
86 |
|
---|
87 | #define TesselPointList list <TesselPoint *>
|
---|
88 | #define TesselPointSet set <TesselPoint *>
|
---|
89 |
|
---|
90 | #define ListOfTesselPointList list<list <TesselPoint *> *>
|
---|
91 |
|
---|
92 | /********************************************** declarations *******************************/
|
---|
93 |
|
---|
94 | template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
|
---|
95 | {
|
---|
96 | if (endpoint1->Nr < endpoint2->Nr) {
|
---|
97 | endpoints[0] = endpoint1;
|
---|
98 | endpoints[1] = endpoint2;
|
---|
99 | } else {
|
---|
100 | endpoints[0] = endpoint2;
|
---|
101 | endpoints[1] = endpoint1;
|
---|
102 | }
|
---|
103 | };
|
---|
104 |
|
---|
105 | // ======================================================== class BoundaryPointSet =========================================
|
---|
106 |
|
---|
107 | class BoundaryPointSet {
|
---|
108 | public:
|
---|
109 | BoundaryPointSet();
|
---|
110 | BoundaryPointSet(TesselPoint * const Walker);
|
---|
111 | ~BoundaryPointSet();
|
---|
112 |
|
---|
113 | void AddLine(BoundaryLineSet * const line);
|
---|
114 |
|
---|
115 | LineMap lines;
|
---|
116 | int LinesCount;
|
---|
117 | TesselPoint *node;
|
---|
118 | double value;
|
---|
119 | int Nr;
|
---|
120 | };
|
---|
121 |
|
---|
122 | ostream & operator << (ostream &ost, const BoundaryPointSet &a);
|
---|
123 |
|
---|
124 | // ======================================================== class BoundaryLineSet ==========================================
|
---|
125 |
|
---|
126 | class BoundaryLineSet {
|
---|
127 | public:
|
---|
128 | BoundaryLineSet();
|
---|
129 | BoundaryLineSet(BoundaryPointSet * const Point[2], const int number);
|
---|
130 | BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number);
|
---|
131 | ~BoundaryLineSet();
|
---|
132 |
|
---|
133 | void AddTriangle(BoundaryTriangleSet * const triangle);
|
---|
134 | bool IsConnectedTo(const BoundaryLineSet * const line) const;
|
---|
135 | bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
|
---|
136 | bool CheckConvexityCriterion() const;
|
---|
137 | class BoundaryPointSet *GetOtherEndpoint(const BoundaryPointSet * const point) const;
|
---|
138 |
|
---|
139 | class BoundaryPointSet *endpoints[2];
|
---|
140 | TriangleMap triangles;
|
---|
141 | int Nr;
|
---|
142 | bool skipped;
|
---|
143 | };
|
---|
144 |
|
---|
145 | ostream & operator << (ostream &ost, const BoundaryLineSet &a);
|
---|
146 |
|
---|
147 | // ======================================================== class BoundaryTriangleSet =======================================
|
---|
148 |
|
---|
149 | class BoundaryTriangleSet {
|
---|
150 | public:
|
---|
151 | BoundaryTriangleSet();
|
---|
152 | BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number);
|
---|
153 | ~BoundaryTriangleSet();
|
---|
154 |
|
---|
155 | void GetNormalVector(const Vector &NormalVector);
|
---|
156 | void GetCenter(Vector * const center) const;
|
---|
157 | bool GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const;
|
---|
158 | double GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const;
|
---|
159 | bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
|
---|
160 | bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
|
---|
161 | bool ContainsBoundaryPoint(const TesselPoint * const point) const;
|
---|
162 | class BoundaryPointSet *GetThirdEndpoint(const BoundaryLineSet * const line) const;
|
---|
163 | bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
|
---|
164 | bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
|
---|
165 |
|
---|
166 | class BoundaryPointSet *endpoints[3];
|
---|
167 | class BoundaryLineSet *lines[3];
|
---|
168 | Vector NormalVector;
|
---|
169 | Vector SphereCenter;
|
---|
170 | int Nr;
|
---|
171 | };
|
---|
172 |
|
---|
173 | ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
|
---|
174 |
|
---|
175 |
|
---|
176 | // ======================================================== class BoundaryTriangleSet =======================================
|
---|
177 |
|
---|
178 | /** Set of BoundaryPointSet.
|
---|
179 | * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
|
---|
180 | * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
|
---|
181 | * class (i.e. no allocation, no deletion).
|
---|
182 | * \note we assume that the set of endpoints reside (more or less) on a plane.
|
---|
183 | */
|
---|
184 | class BoundaryPolygonSet {
|
---|
185 | public:
|
---|
186 | BoundaryPolygonSet();
|
---|
187 | ~BoundaryPolygonSet();
|
---|
188 |
|
---|
189 | Vector * GetNormalVector(const Vector &NormalVector) const;
|
---|
190 | void GetCenter(Vector *center) const;
|
---|
191 | bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
|
---|
192 | bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
|
---|
193 | bool ContainsBoundaryPoint(const TesselPoint * const point) const;
|
---|
194 | bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
|
---|
195 | bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
|
---|
196 | bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
|
---|
197 | bool ContainsPresentTupel(const PointSet &endpoints) const;
|
---|
198 | TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
|
---|
199 | bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
|
---|
200 |
|
---|
201 | PointSet endpoints;
|
---|
202 | int Nr;
|
---|
203 | };
|
---|
204 |
|
---|
205 | ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
|
---|
206 |
|
---|
207 | // =========================================================== class TESSELPOINT ===========================================
|
---|
208 |
|
---|
209 | /** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
|
---|
210 | */
|
---|
211 | class TesselPoint : virtual public ParticleInfo {
|
---|
212 | public:
|
---|
213 | TesselPoint();
|
---|
214 | virtual ~TesselPoint();
|
---|
215 |
|
---|
216 | Vector *node; // pointer to position of the dot in space
|
---|
217 |
|
---|
218 | virtual ostream & operator << (ostream &ost);
|
---|
219 | };
|
---|
220 |
|
---|
221 | ostream & operator << (ostream &ost, const TesselPoint &a);
|
---|
222 |
|
---|
223 | // =========================================================== class POINTCLOUD ============================================
|
---|
224 |
|
---|
225 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
|
---|
226 | * This basically encapsulates a list structure.
|
---|
227 | */
|
---|
228 | class PointCloud {
|
---|
229 | public:
|
---|
230 | PointCloud();
|
---|
231 | virtual ~PointCloud();
|
---|
232 |
|
---|
233 | virtual const char * const GetName() const { return "unknown"; };
|
---|
234 | virtual Vector *GetCenter() const { return NULL; };
|
---|
235 | virtual TesselPoint *GetPoint() const { return NULL; };
|
---|
236 | virtual TesselPoint *GetTerminalPoint() const { return NULL; };
|
---|
237 | virtual int GetMaxId() const { return 0; };
|
---|
238 | virtual void GoToNext() const {};
|
---|
239 | virtual void GoToPrevious() const {};
|
---|
240 | virtual void GoToFirst() const {};
|
---|
241 | virtual void GoToLast() const {};
|
---|
242 | virtual bool IsEmpty() const { return true; };
|
---|
243 | virtual bool IsEnd() const { return true; };
|
---|
244 | };
|
---|
245 |
|
---|
246 | // ======================================================== class CandidateForTesselation =========================================
|
---|
247 |
|
---|
248 | class CandidateForTesselation {
|
---|
249 | public :
|
---|
250 | CandidateForTesselation(BoundaryLineSet* currentBaseLine);
|
---|
251 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
|
---|
252 | ~CandidateForTesselation();
|
---|
253 |
|
---|
254 | TesselPointList pointlist;
|
---|
255 | BoundaryLineSet *BaseLine;
|
---|
256 | Vector OptCenter;
|
---|
257 | Vector OtherOptCenter;
|
---|
258 | double ShortestAngle;
|
---|
259 | double OtherShortestAngle;
|
---|
260 | };
|
---|
261 |
|
---|
262 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
|
---|
263 |
|
---|
264 | // =========================================================== class TESSELATION ===========================================
|
---|
265 |
|
---|
266 | /** Contains the envelope to a PointCloud.
|
---|
267 | */
|
---|
268 | class Tesselation : public PointCloud {
|
---|
269 | public:
|
---|
270 |
|
---|
271 | Tesselation();
|
---|
272 | virtual ~Tesselation();
|
---|
273 |
|
---|
274 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
---|
275 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
---|
276 | void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
277 | void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
278 | void AddTesselationTriangle();
|
---|
279 | void AddTesselationTriangle(const int nr);
|
---|
280 | void AddCandidateTriangle(CandidateForTesselation CandidateLine);
|
---|
281 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
282 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
283 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
284 |
|
---|
285 |
|
---|
286 | // concave envelope
|
---|
287 | void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
|
---|
288 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
---|
289 | void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
|
---|
290 | bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
|
---|
291 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
---|
292 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
---|
293 |
|
---|
294 | // convex envelope
|
---|
295 | void TesselateOnBoundary(const PointCloud * const cloud);
|
---|
296 | void GuessStartingTriangle();
|
---|
297 | bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
|
---|
298 | double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
|
---|
299 | class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
|
---|
300 | double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
|
---|
301 | class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
|
---|
302 | IndexToIndex * FindAllDegeneratedTriangles();
|
---|
303 | IndexToIndex * FindAllDegeneratedLines();
|
---|
304 | void RemoveDegeneratedTriangles();
|
---|
305 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
|
---|
306 | int CorrectAllDegeneratedPolygons();
|
---|
307 |
|
---|
308 | TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
|
---|
309 | TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
|
---|
310 | ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
311 | ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
312 | TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
|
---|
313 | TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const;
|
---|
314 | class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
---|
315 | TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
|
---|
316 | TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
|
---|
317 | BoundaryTriangleSet * FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
|
---|
318 | bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
|
---|
319 | double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
|
---|
320 | double GetDistanceSquaredToSurface(const Vector &Point, const LinkedCell* const LC) const;
|
---|
321 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
---|
322 | DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
|
---|
323 | BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
|
---|
324 |
|
---|
325 | // print for debugging
|
---|
326 | void PrintAllBoundaryPoints(ofstream *out) const;
|
---|
327 | void PrintAllBoundaryLines(ofstream *out) const;
|
---|
328 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
---|
329 |
|
---|
330 | // store envelope in file
|
---|
331 | void Output(const char *filename, const PointCloud * const cloud);
|
---|
332 |
|
---|
333 | PointMap PointsOnBoundary;
|
---|
334 | LineMap LinesOnBoundary;
|
---|
335 | CandidateMap OpenLines;
|
---|
336 | TriangleMap TrianglesOnBoundary;
|
---|
337 | int PointsOnBoundaryCount;
|
---|
338 | int LinesOnBoundaryCount;
|
---|
339 | int TrianglesOnBoundaryCount;
|
---|
340 |
|
---|
341 | // PointCloud implementation for PointsOnBoundary
|
---|
342 | virtual Vector *GetCenter(ofstream *out) const;
|
---|
343 | virtual TesselPoint *GetPoint() const;
|
---|
344 | virtual TesselPoint *GetTerminalPoint() const;
|
---|
345 | virtual void GoToNext() const;
|
---|
346 | virtual void GoToPrevious() const;
|
---|
347 | virtual void GoToFirst() const;
|
---|
348 | virtual void GoToLast() const;
|
---|
349 | virtual bool IsEmpty() const;
|
---|
350 | virtual bool IsEnd() const;
|
---|
351 |
|
---|
352 | class BoundaryPointSet *BPS[2];
|
---|
353 | class BoundaryLineSet *BLS[3];
|
---|
354 | class BoundaryTriangleSet *BTS;
|
---|
355 | class BoundaryTriangleSet *LastTriangle;
|
---|
356 | int TriangleFilesWritten;
|
---|
357 |
|
---|
358 | private:
|
---|
359 | mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
360 |
|
---|
361 | mutable PointMap::const_iterator InternalPointer;
|
---|
362 |
|
---|
363 | //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
|
---|
364 | };
|
---|
365 |
|
---|
366 |
|
---|
367 | #endif /* TESSELATION_HPP_ */
|
---|