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 |
|
---|
26 | #include "atom_particleinfo.hpp"
|
---|
27 | #include "helpers.hpp"
|
---|
28 | #include "vector.hpp"
|
---|
29 |
|
---|
30 | /****************************************** forward declarations *****************************/
|
---|
31 |
|
---|
32 | class BoundaryPointSet;
|
---|
33 | class BoundaryLineSet;
|
---|
34 | class BoundaryTriangleSet;
|
---|
35 | class LinkedCell;
|
---|
36 | class TesselPoint;
|
---|
37 | class PointCloud;
|
---|
38 | class Tesselation;
|
---|
39 |
|
---|
40 | /********************************************** definitions *********************************/
|
---|
41 |
|
---|
42 | #define DoTecplotOutput 1
|
---|
43 | #define DoRaster3DOutput 1
|
---|
44 | #define DoVRMLOutput 1
|
---|
45 | #define TecplotSuffix ".dat"
|
---|
46 | #define Raster3DSuffix ".r3d"
|
---|
47 | #define VRMLSUffix ".wrl"
|
---|
48 |
|
---|
49 | // ======================================================= some template functions =========================================
|
---|
50 |
|
---|
51 | #define PointMap map < int, class BoundaryPointSet * >
|
---|
52 | #define PointPair pair < int, class BoundaryPointSet * >
|
---|
53 | #define PointTestPair pair < PointMap::iterator, bool >
|
---|
54 | #define CandidateList list <class CandidateForTesselation *>
|
---|
55 | #define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
|
---|
56 |
|
---|
57 | #define LineMap multimap < int, class BoundaryLineSet * >
|
---|
58 | #define LinePair pair < int, class BoundaryLineSet * >
|
---|
59 | #define LineTestPair pair < LineMap::iterator, bool >
|
---|
60 |
|
---|
61 | #define TriangleMap map < int, class BoundaryTriangleSet * >
|
---|
62 | #define TrianglePair pair < int, class BoundaryTriangleSet * >
|
---|
63 | #define TriangleTestPair pair < TrianglePair::iterator, bool >
|
---|
64 |
|
---|
65 | #define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
66 | #define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
67 |
|
---|
68 | /********************************************** declarations *******************************/
|
---|
69 |
|
---|
70 | template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
|
---|
71 | {
|
---|
72 | if (endpoint1->Nr < endpoint2->Nr) {
|
---|
73 | endpoints[0] = endpoint1;
|
---|
74 | endpoints[1] = endpoint2;
|
---|
75 | } else {
|
---|
76 | endpoints[0] = endpoint2;
|
---|
77 | endpoints[1] = endpoint1;
|
---|
78 | }
|
---|
79 | };
|
---|
80 |
|
---|
81 | // ======================================================== class BoundaryPointSet =========================================
|
---|
82 |
|
---|
83 | class BoundaryPointSet {
|
---|
84 | public:
|
---|
85 | BoundaryPointSet();
|
---|
86 | BoundaryPointSet(TesselPoint * Walker);
|
---|
87 | ~BoundaryPointSet();
|
---|
88 |
|
---|
89 | void AddLine(class BoundaryLineSet *line);
|
---|
90 |
|
---|
91 | LineMap lines;
|
---|
92 | int LinesCount;
|
---|
93 | TesselPoint *node;
|
---|
94 | double value;
|
---|
95 | int Nr;
|
---|
96 | };
|
---|
97 |
|
---|
98 | ostream & operator << (ostream &ost, const BoundaryPointSet &a);
|
---|
99 |
|
---|
100 | // ======================================================== class BoundaryLineSet ==========================================
|
---|
101 |
|
---|
102 | class BoundaryLineSet {
|
---|
103 | public:
|
---|
104 | BoundaryLineSet();
|
---|
105 | BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
|
---|
106 | ~BoundaryLineSet();
|
---|
107 |
|
---|
108 | void AddTriangle(class BoundaryTriangleSet *triangle);
|
---|
109 | bool IsConnectedTo(class BoundaryLineSet *line);
|
---|
110 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
111 | bool CheckConvexityCriterion();
|
---|
112 | class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
|
---|
113 |
|
---|
114 | class BoundaryPointSet *endpoints[2];
|
---|
115 | TriangleMap triangles;
|
---|
116 | int Nr;
|
---|
117 | bool skipped;
|
---|
118 | };
|
---|
119 |
|
---|
120 | ostream & operator << (ostream &ost, const BoundaryLineSet &a);
|
---|
121 |
|
---|
122 | // ======================================================== class BoundaryTriangleSet =======================================
|
---|
123 |
|
---|
124 | class BoundaryTriangleSet {
|
---|
125 | public:
|
---|
126 | BoundaryTriangleSet();
|
---|
127 | BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
|
---|
128 | ~BoundaryTriangleSet();
|
---|
129 |
|
---|
130 | void GetNormalVector(Vector &NormalVector);
|
---|
131 | void GetCenter(Vector *center);
|
---|
132 | bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
|
---|
133 | bool ContainsBoundaryLine(class BoundaryLineSet *line);
|
---|
134 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
135 | bool ContainsBoundaryPoint(class TesselPoint *point);
|
---|
136 | class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
|
---|
137 | bool IsPresentTupel(class BoundaryPointSet *Points[3]);
|
---|
138 | bool IsPresentTupel(class BoundaryTriangleSet *T);
|
---|
139 |
|
---|
140 | class BoundaryPointSet *endpoints[3];
|
---|
141 | class BoundaryLineSet *lines[3];
|
---|
142 | Vector NormalVector;
|
---|
143 | int Nr;
|
---|
144 | };
|
---|
145 |
|
---|
146 | ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
|
---|
147 |
|
---|
148 | // =========================================================== class TESSELPOINT ===========================================
|
---|
149 |
|
---|
150 | /** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
|
---|
151 | */
|
---|
152 | class TesselPoint : virtual public ParticleInfo {
|
---|
153 | public:
|
---|
154 | TesselPoint();
|
---|
155 | virtual ~TesselPoint();
|
---|
156 |
|
---|
157 | Vector *node; // pointer to position of the dot in space
|
---|
158 |
|
---|
159 | virtual ostream & operator << (ostream &ost);
|
---|
160 | };
|
---|
161 |
|
---|
162 | ostream & operator << (ostream &ost, const TesselPoint &a);
|
---|
163 |
|
---|
164 | // =========================================================== class POINTCLOUD ============================================
|
---|
165 |
|
---|
166 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
|
---|
167 | * This basically encapsulates a list structure.
|
---|
168 | */
|
---|
169 | class PointCloud {
|
---|
170 | public:
|
---|
171 | PointCloud();
|
---|
172 | virtual ~PointCloud();
|
---|
173 |
|
---|
174 | virtual const char * const GetName() const { return "unknown"; };
|
---|
175 | virtual Vector *GetCenter() const { return NULL; };
|
---|
176 | virtual TesselPoint *GetPoint() const { return NULL; };
|
---|
177 | virtual TesselPoint *GetTerminalPoint() const { return NULL; };
|
---|
178 | virtual void GoToNext() const {};
|
---|
179 | virtual void GoToPrevious() const {};
|
---|
180 | virtual void GoToFirst() const {};
|
---|
181 | virtual void GoToLast() const {};
|
---|
182 | virtual bool IsEmpty() const { return true; };
|
---|
183 | virtual bool IsEnd() const { return true; };
|
---|
184 | };
|
---|
185 |
|
---|
186 | // ======================================================== class CandidateForTesselation =========================================
|
---|
187 |
|
---|
188 | class CandidateForTesselation {
|
---|
189 | public :
|
---|
190 | CandidateForTesselation(BoundaryLineSet* currentBaseLine);
|
---|
191 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
|
---|
192 | ~CandidateForTesselation();
|
---|
193 |
|
---|
194 | TesselPoint *point;
|
---|
195 | BoundaryLineSet *BaseLine;
|
---|
196 | Vector OptCenter;
|
---|
197 | Vector OtherOptCenter;
|
---|
198 | double ShortestAngle;
|
---|
199 | double OtherShortestAngle;
|
---|
200 | };
|
---|
201 |
|
---|
202 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
|
---|
203 |
|
---|
204 | // =========================================================== class TESSELATION ===========================================
|
---|
205 |
|
---|
206 | /** Contains the envelope to a PointCloud.
|
---|
207 | */
|
---|
208 | class Tesselation : public PointCloud {
|
---|
209 | public:
|
---|
210 |
|
---|
211 | Tesselation();
|
---|
212 | virtual ~Tesselation();
|
---|
213 |
|
---|
214 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
---|
215 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
---|
216 | void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
217 | void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
218 | void AddTesselationTriangle();
|
---|
219 | void AddTesselationTriangle(const int nr);
|
---|
220 | void AddCandidateTriangle(CandidateForTesselation &CandidateLine);
|
---|
221 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
222 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
223 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
224 |
|
---|
225 |
|
---|
226 | // concave envelope
|
---|
227 | void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
|
---|
228 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
---|
229 | void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, class BoundaryLineSet *BaseLine, const class TesselPoint * const ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC) const;
|
---|
230 | bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
|
---|
231 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
---|
232 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
---|
233 |
|
---|
234 | // convex envelope
|
---|
235 | void TesselateOnBoundary(const PointCloud * const cloud);
|
---|
236 | void GuessStartingTriangle();
|
---|
237 | bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
|
---|
238 | double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
|
---|
239 | class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
|
---|
240 | double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
|
---|
241 | class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
|
---|
242 | map<int, int> * FindAllDegeneratedTriangles();
|
---|
243 | map<int, int> * FindAllDegeneratedLines();
|
---|
244 | void RemoveDegeneratedTriangles();
|
---|
245 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
|
---|
246 |
|
---|
247 | set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
|
---|
248 | set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
|
---|
249 | list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
250 | list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
251 | list<TesselPoint*> * GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference = NULL) const;
|
---|
252 | class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
---|
253 | list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
|
---|
254 | list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
|
---|
255 | class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
|
---|
256 | bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
|
---|
257 | bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
|
---|
258 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
---|
259 |
|
---|
260 | // print for debugging
|
---|
261 | void PrintAllBoundaryPoints(ofstream *out) const;
|
---|
262 | void PrintAllBoundaryLines(ofstream *out) const;
|
---|
263 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
---|
264 |
|
---|
265 | // store envelope in file
|
---|
266 | void Output(const char *filename, const PointCloud * const cloud);
|
---|
267 |
|
---|
268 | PointMap PointsOnBoundary;
|
---|
269 | LineMap LinesOnBoundary;
|
---|
270 | CandidateMap OpenLines;
|
---|
271 | TriangleMap TrianglesOnBoundary;
|
---|
272 | int PointsOnBoundaryCount;
|
---|
273 | int LinesOnBoundaryCount;
|
---|
274 | int TrianglesOnBoundaryCount;
|
---|
275 |
|
---|
276 | // PointCloud implementation for PointsOnBoundary
|
---|
277 | virtual Vector *GetCenter(ofstream *out) const;
|
---|
278 | virtual TesselPoint *GetPoint() const;
|
---|
279 | virtual TesselPoint *GetTerminalPoint() const;
|
---|
280 | virtual void GoToNext() const;
|
---|
281 | virtual void GoToPrevious() const;
|
---|
282 | virtual void GoToFirst() const;
|
---|
283 | virtual void GoToLast() const;
|
---|
284 | virtual bool IsEmpty() const;
|
---|
285 | virtual bool IsEnd() const;
|
---|
286 |
|
---|
287 | class BoundaryPointSet *BPS[2];
|
---|
288 | class BoundaryLineSet *BLS[3];
|
---|
289 | class BoundaryTriangleSet *BTS;
|
---|
290 | class BoundaryTriangleSet *LastTriangle;
|
---|
291 | int TriangleFilesWritten;
|
---|
292 |
|
---|
293 | private:
|
---|
294 | mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
295 |
|
---|
296 | mutable PointMap::const_iterator InternalPointer;
|
---|
297 |
|
---|
298 | bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
|
---|
299 | };
|
---|
300 |
|
---|
301 |
|
---|
302 | #endif /* TESSELATION_HPP_ */
|
---|