source: molecuilder/src/tesselation.hpp@ 6b937bd

Last change on this file since 6b937bd was 6b937bd, checked in by Frederik Heber <heber@…>, 16 years ago

Huge Refactoring: class atom split up into several inherited classes.

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