source: molecuilder/src/tesselation.hpp@ 0cf171

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

BUGFIXes to Find_convex_... and Find_non_convex_... algorithms

  • Find_non_convex_border() - very first baseline of starting triangle is skipped as it is the most outward.
  • BoundaryLineSet::TrianglesCount is removed and replaced by triangles.size(), as it is redundant and we made mistakes in not reducing TrianglesCount on triangle erase.
  • BoundaryLineSet::CheckConvexityCriterion() - extra check when NormalVector point in the very same directions,
  • BoundaryTriangleSet::GetIntersectionInsideTriangle() - CrossPoint return value is checked, i===3 checked not >3!
  • new stream operator for TesselPoint with single argument.
  • class Tesselation inherits PointCloud and implements all functions (including virtual destructor) in order to have PointsOnBoundary parsable by LinkedCell.
  • Tesselation::InsertStraddlingPoints() - LinkedCell is created for every atom just from the BoundaryPoints and not for all (so that only BoundaryPoints can be found), old triangle is now really deleted, lots of verbosity added and fixed.
  • Tesselation::GetCommonEndpoint() - connectedClosestPoint is deleted lateron, SecondPoint argument but not used.
  • Tesselation::FindClosestPoint() - returns second second closest point in new second argument.
  • Tesselation::getCircleOfConnectedPoints() - we find the BoundaryPoint if possible and just look through its lines if found, plane is centered at closest point and normal is between it and the center of all on circle, getAngle() corrections incorporated and vector is always projected onto circle plane.
  • new function Tesselation findSecondClosestPoint().
  • getAngle() - just receives third vector with which it dedices between [0,pi) and [pi,2pi), the vectors are assumed to be relative to one common center already.
  • 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 void AddPoint(TesselPoint *Walker);
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 private:
239 class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
240 class BoundaryPointSet *BPS[2];
241 class BoundaryLineSet *BLS[3];
242 class BoundaryTriangleSet *BTS;
243
244 PointMap::iterator InternalPointer;
245};
246
247bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3]);
248bool sortCandidates(class CandidateForTesselation* candidate1, class CandidateForTesselation* candidate2);
249TesselPoint* findClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC);
250TesselPoint* findSecondClosestPoint(const Vector*, LinkedCell*);
251double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector);
252
253#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.