source: molecuilder/src/tesselation.hpp@ 844cf5

Last change on this file since 844cf5 was 70c4567, checked in by Frederik Heber <heber@…>, 16 years ago

New function ConvexizeNonconvexEnvelope() to calculate the volume of a non-convex envelope.

The central idea is that the volume of a convex envelope is easy to determine as a sum of pyramids with respect to a center inside the envelope. Hence, if we can "reduce" the non-convex envelope to a convex one in such a way that we know the added volume, we may determine the volume of a non-convex envelope.
The nice side effect is that we may use our Find_non_convex_border() algorithm to calculate also the convex envelope.

  • We go through all BoundaryPoints and check whether one of its Baselines does not fulfill the ConvexCriterion. If so, we remove it, as it can not be a boundary point on the convex envelope, and re-construct the attached triangles. The added volume is a general tetraeder, whose formula is known.
  • FIX: Find_convex_border() - We check whether AddPoint is successful or not.
  • builder.cpp: case 'o' - changed to use ConvexizeNonconvexEnvelope() instead of Find_convex_border()
  • Tesselation:AddPoint() - now takes second argument which is the index for BPS and always set BPS to either the newly created or the already present point. Return argument discerns between new and already present point.
  • Tesselation::BPS, BLS, BTS are now public not private. We have to access them from ConvexizeNonconvexEnvelope()
  • Property mode set to 100644
File size: 9.2 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// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <map>
21#include <list>
22
23
24#include "helpers.hpp"
25#include "linkedcell.hpp"
26#include "tesselationhelpers.hpp"
27#include "vector.hpp"
28
29class BoundaryPointSet;
30class BoundaryLineSet;
31class BoundaryTriangleSet;
32class TesselPoint;
33class PointCloud;
34class Tesselation;
35
36// ======================================================= some template functions =========================================
37
38#define PointMap map < int, class BoundaryPointSet * >
39#define PointPair pair < int, class BoundaryPointSet * >
40#define PointTestPair pair < PointMap::iterator, bool >
41#define CandidateList list <class CandidateForTesselation *>
42
43#define LineMap multimap < int, class BoundaryLineSet * >
44#define LinePair pair < int, class BoundaryLineSet * >
45#define LineTestPair pair < LineMap::iterator, bool >
46
47#define TriangleMap map < int, class BoundaryTriangleSet * >
48#define TrianglePair pair < int, class BoundaryTriangleSet * >
49#define TriangleTestPair pair < TrianglePair::iterator, bool >
50
51#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
52#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
53
54
55
56template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
57{
58 if (endpoint1->Nr < endpoint2->Nr) {
59 endpoints[0] = endpoint1;
60 endpoints[1] = endpoint2;
61 } else {
62 endpoints[0] = endpoint2;
63 endpoints[1] = endpoint1;
64 }
65};
66
67// ======================================================== class BoundaryPointSet =========================================
68
69class BoundaryPointSet {
70 public:
71 BoundaryPointSet();
72 BoundaryPointSet(TesselPoint *Walker);
73 ~BoundaryPointSet();
74
75 void AddLine(class BoundaryLineSet *line);
76
77 LineMap lines;
78 int LinesCount;
79 TesselPoint *node;
80 int Nr;
81};
82
83ostream & operator << (ostream &ost, BoundaryPointSet &a);
84
85// ======================================================== class BoundaryLineSet ==========================================
86
87class BoundaryLineSet {
88 public:
89 BoundaryLineSet();
90 BoundaryLineSet(class BoundaryPointSet *Point[2], int number);
91 ~BoundaryLineSet();
92
93 void AddTriangle(class BoundaryTriangleSet *triangle);
94 bool IsConnectedTo(class BoundaryLineSet *line);
95 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
96 bool CheckConvexityCriterion(ofstream *out);
97 class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
98
99 class BoundaryPointSet *endpoints[2];
100 TriangleMap triangles;
101 int Nr;
102};
103
104ostream & operator << (ostream &ost, BoundaryLineSet &a);
105
106// ======================================================== class BoundaryTriangleSet =======================================
107
108class BoundaryTriangleSet {
109 public:
110 BoundaryTriangleSet();
111 BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
112 ~BoundaryTriangleSet();
113
114 void GetNormalVector(Vector &NormalVector);
115 bool GetIntersectionInsideTriangle(ofstream *out, Vector *MolCenter, Vector *x, Vector *Intersection);
116 bool ContainsBoundaryLine(class BoundaryLineSet *line);
117 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
118 class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
119 bool IsPresentTupel(class BoundaryPointSet *Points[3]);
120 void GetCenter(Vector *center);
121
122 class BoundaryPointSet *endpoints[3];
123 class BoundaryLineSet *lines[3];
124 Vector NormalVector;
125 int Nr;
126};
127
128ostream & operator << (ostream &ost, BoundaryTriangleSet &a);
129
130// =========================================================== class TESSELPOINT ===========================================
131
132/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
133 */
134class TesselPoint {
135public:
136 TesselPoint();
137 virtual ~TesselPoint();
138
139 Vector *node; // pointer to position of the dot in space
140 int nr; // index to easierly identify
141 char *Name; // some name to reference to on output
142
143 virtual ostream & operator << (ostream &ost);
144};
145
146ostream & operator << (ostream &ost, const TesselPoint &a);
147
148// =========================================================== class POINTCLOUD ============================================
149
150/** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
151 * This basically encapsulates a list structure.
152 */
153class PointCloud {
154public:
155 PointCloud();
156 virtual ~PointCloud();
157
158 virtual Vector *GetCenter(ofstream *out) { return NULL; };
159 virtual TesselPoint *GetPoint() { return NULL; };
160 virtual TesselPoint *GetTerminalPoint() { return NULL; };
161 virtual void GoToNext() {};
162 virtual void GoToPrevious() {};
163 virtual void GoToFirst() {};
164 virtual void GoToLast() {};
165 virtual bool IsEmpty() { return false; };
166 virtual bool IsEnd() { return false; };
167};
168
169// ======================================================== class CandidateForTesselation =========================================
170
171class CandidateForTesselation {
172 public :
173 CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
174 ~CandidateForTesselation();
175
176 TesselPoint *point;
177 BoundaryLineSet *BaseLine;
178 Vector OptCenter;
179 Vector OtherOptCenter;
180};
181
182// =========================================================== class TESSELATION ===========================================
183
184/** Contains the envelope to a PointCloud.
185 */
186class Tesselation : public PointCloud {
187 public:
188
189 Tesselation();
190 virtual ~Tesselation();
191
192 bool AddPoint(TesselPoint *Walker, int n);
193 void AddTrianglePoint(TesselPoint* Candidate, int n);
194 void AddTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n);
195 void AlwaysAddTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n);
196 void AddTriangle();
197 bool IsInside(Vector *pointer);
198 class BoundaryPointSet *GetCommonEndpoint(class BoundaryLineSet * line1, class BoundaryLineSet * line2);
199
200 // concave envelope
201 void Find_starting_triangle(ofstream *out, const double RADIUS, class LinkedCell *LC);
202 void Find_second_point_for_Tesselation(class TesselPoint* a, class TesselPoint* Candidate, Vector Oben, class TesselPoint*& Opt_Candidate, double Storage[3], double RADIUS, class LinkedCell *LC);
203 void Find_third_point_for_Tesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, class LinkedCell *LC);
204 bool Find_next_suitable_triangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC);
205 int CheckPresenceOfTriangle(ofstream *out, class TesselPoint *Candidates[3]);
206
207 // convex envelope
208 void TesselateOnBoundary(ofstream *out, PointCloud *cloud);
209 void GuessStartingTriangle(ofstream *out);
210 bool InsertStraddlingPoints(ofstream *out, PointCloud *cloud, LinkedCell *LC);
211 bool CorrectConcaveBaselines(ofstream *out);
212
213 list<TesselPoint*> * getCircleOfConnectedPoints(ofstream *out, TesselPoint* Point, Vector* Reference);
214 list<BoundaryTriangleSet*> *FindTriangles(TesselPoint* Points[3]);
215 list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(ofstream *out, Vector *x, LinkedCell* LC);
216 class BoundaryTriangleSet * FindClosestTriangleToPoint(ofstream *out, Vector *x, LinkedCell* LC);
217 bool IsInnerPoint(ofstream *out, Vector Point, LinkedCell* LC);
218 bool IsInnerPoint(ofstream *out, TesselPoint *Point, LinkedCell* LC);
219
220 PointMap PointsOnBoundary;
221 LineMap LinesOnBoundary;
222 TriangleMap TrianglesOnBoundary;
223 int PointsOnBoundaryCount;
224 int LinesOnBoundaryCount;
225 int TrianglesOnBoundaryCount;
226
227 // PointCloud implementation for PointsOnBoundary
228 virtual Vector *GetCenter(ofstream *out);
229 virtual TesselPoint *GetPoint();
230 virtual TesselPoint *GetTerminalPoint();
231 virtual void GoToNext();
232 virtual void GoToPrevious();
233 virtual void GoToFirst();
234 virtual void GoToLast();
235 virtual bool IsEmpty();
236 virtual bool IsEnd();
237
238 class BoundaryPointSet *BPS[2];
239 class BoundaryLineSet *BLS[3];
240 class BoundaryTriangleSet *BTS;
241
242 private:
243 class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
244
245 PointMap::iterator InternalPointer;
246};
247
248bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3]);
249bool sortCandidates(class CandidateForTesselation* candidate1, class CandidateForTesselation* candidate2);
250TesselPoint* findClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC);
251TesselPoint* findSecondClosestPoint(const Vector*, LinkedCell*);
252double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector);
253
254#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.