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