source: molecuilder/src/tesselation.hpp@ 7b991d

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

Attempt to fix the tesselation::IsInnerPoint().

We try the IsInnerPoint() as follows:

  1. Find nearest BoundaryPoints - working
  2. Find Closest BoundaryLine's - working
  3. Find closest Triangle that is well aligned (wrt to NormalVector and Distance) - unsure whether correctly working
  4. Check whether alignment is on boundary or inside/outside - working
  5. If on boundary, we check whether it's inside of triangle by intersecting with boundary lines - not working

Hence, we code a wrapper for GSL routines, to - finally - allow for solution of linear system of equations.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 14.6 KB
RevLine 
[834ff3]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
[17b3a5c]15/*********************************************** includes ***********************************/
16
[834ff3]17// include config.h
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include <map>
23#include <list>
[d6b011]24#include <set>
[ea3627]25#include <stack>
[834ff3]26
[2e2a70]27#include "atom_particleinfo.hpp"
[6b937bd]28#include "helpers.hpp"
[2e2a70]29#include "vector.hpp"
[834ff3]30
[17b3a5c]31/****************************************** forward declarations *****************************/
32
[834ff3]33class BoundaryPointSet;
34class BoundaryLineSet;
35class BoundaryTriangleSet;
[17b3a5c]36class LinkedCell;
[834ff3]37class TesselPoint;
38class PointCloud;
39class Tesselation;
40
[17b3a5c]41/********************************************** definitions *********************************/
42
[60cbe5]43#define DoTecplotOutput 1
44#define DoRaster3DOutput 1
45#define DoVRMLOutput 1
46#define TecplotSuffix ".dat"
47#define Raster3DSuffix ".r3d"
48#define VRMLSUffix ".wrl"
49
[246a3c]50#define ParallelEpsilon 1e-3
51
[834ff3]52// ======================================================= some template functions =========================================
53
[eda56a]54#define IndexToIndex map <int, int>
55
[834ff3]56#define PointMap map < int, class BoundaryPointSet * >
[f7490d]57#define PointSet set < class BoundaryPointSet * >
58#define PointList list < class BoundaryPointSet * >
[834ff3]59#define PointPair pair < int, class BoundaryPointSet * >
60#define PointTestPair pair < PointMap::iterator, bool >
[f7490d]61
[834ff3]62#define CandidateList list <class CandidateForTesselation *>
[4af89b]63#define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
[834ff3]64
65#define LineMap multimap < int, class BoundaryLineSet * >
[f7490d]66#define LineSet set < class BoundaryLineSet * >
67#define LineList list < class BoundaryLineSet * >
[834ff3]68#define LinePair pair < int, class BoundaryLineSet * >
69#define LineTestPair pair < LineMap::iterator, bool >
70
71#define TriangleMap map < int, class BoundaryTriangleSet * >
[f7490d]72#define TriangleSet set < class BoundaryTriangleSet * >
73#define TriangleList list < class BoundaryTriangleSet * >
[834ff3]74#define TrianglePair pair < int, class BoundaryTriangleSet * >
75#define TriangleTestPair pair < TrianglePair::iterator, bool >
76
[f7490d]77#define PolygonMap map < int, class BoundaryPolygonSet * >
78#define PolygonSet set < class BoundaryPolygonSet * >
79#define PolygonList list < class BoundaryPolygonSet * >
80
[a1acc5]81#define DistanceToPointMap multimap <double, class BoundaryPointSet * >
82#define DistanceToPointPair pair <double, class BoundaryPointSet * >
[eda56a]83
[834ff3]84#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
85#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
86
[be2997]87#define TesselPointList list <TesselPoint *>
[f7490d]88#define TesselPointSet set <TesselPoint *>
[be2997]89
[17b3a5c]90/********************************************** declarations *******************************/
[834ff3]91
92template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
93{
94 if (endpoint1->Nr < endpoint2->Nr) {
95 endpoints[0] = endpoint1;
96 endpoints[1] = endpoint2;
97 } else {
98 endpoints[0] = endpoint2;
99 endpoints[1] = endpoint1;
100 }
101};
102
103// ======================================================== class BoundaryPointSet =========================================
104
105class BoundaryPointSet {
106 public:
107 BoundaryPointSet();
[a9b2a0a]108 BoundaryPointSet(TesselPoint * Walker);
[834ff3]109 ~BoundaryPointSet();
110
111 void AddLine(class BoundaryLineSet *line);
112
113 LineMap lines;
114 int LinesCount;
115 TesselPoint *node;
[eb58a7]116 double value;
[834ff3]117 int Nr;
118};
119
[a9b2a0a]120ostream & operator << (ostream &ost, const BoundaryPointSet &a);
[834ff3]121
122// ======================================================== class BoundaryLineSet ==========================================
123
124class BoundaryLineSet {
125 public:
126 BoundaryLineSet();
[a9b2a0a]127 BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
[834ff3]128 ~BoundaryLineSet();
129
130 void AddTriangle(class BoundaryTriangleSet *triangle);
131 bool IsConnectedTo(class BoundaryLineSet *line);
132 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
[543ce4]133 bool CheckConvexityCriterion();
[eeefb3]134 class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
[834ff3]135
136 class BoundaryPointSet *endpoints[2];
137 TriangleMap triangles;
138 int Nr;
[4af89b]139 bool skipped;
[834ff3]140};
141
[a9b2a0a]142ostream & operator << (ostream &ost, const BoundaryLineSet &a);
[834ff3]143
144// ======================================================== class BoundaryTriangleSet =======================================
145
146class BoundaryTriangleSet {
147 public:
148 BoundaryTriangleSet();
149 BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
150 ~BoundaryTriangleSet();
151
152 void GetNormalVector(Vector &NormalVector);
[60cbe5]153 void GetCenter(Vector *center);
[543ce4]154 bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
[834ff3]155 bool ContainsBoundaryLine(class BoundaryLineSet *line);
156 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
[daf956]157 bool ContainsBoundaryPoint(class TesselPoint *point);
[eeefb3]158 class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
[834ff3]159 bool IsPresentTupel(class BoundaryPointSet *Points[3]);
[60cbe5]160 bool IsPresentTupel(class BoundaryTriangleSet *T);
[834ff3]161
162 class BoundaryPointSet *endpoints[3];
163 class BoundaryLineSet *lines[3];
164 Vector NormalVector;
[65f1dba]165 Vector SphereCenter;
[834ff3]166 int Nr;
167};
168
[a9b2a0a]169ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
[834ff3]170
[f7490d]171
172// ======================================================== class BoundaryTriangleSet =======================================
173
174/** Set of BoundaryPointSet.
175 * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
176 * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
177 * class (i.e. no allocation, no deletion).
178 * \note we assume that the set of endpoints reside (more or less) on a plane.
179 */
180class BoundaryPolygonSet {
181 public:
182 BoundaryPolygonSet();
183 ~BoundaryPolygonSet();
184
185 Vector * GetNormalVector(const Vector &NormalVector) const;
186 void GetCenter(Vector *center) const;
187 bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
188 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
189 bool ContainsBoundaryPoint(const TesselPoint * const point) const;
190 bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
191 bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
192 bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
193 bool ContainsPresentTupel(const PointSet &endpoints) const;
[ea3627]194 TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
[f7490d]195 bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
196
197 PointSet endpoints;
198 int Nr;
199};
200
201ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
202
[834ff3]203// =========================================================== class TESSELPOINT ===========================================
204
205/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
206 */
[6b937bd]207class TesselPoint : virtual public ParticleInfo {
[834ff3]208public:
209 TesselPoint();
[0cf171]210 virtual ~TesselPoint();
[834ff3]211
212 Vector *node; // pointer to position of the dot in space
[0cf171]213
214 virtual ostream & operator << (ostream &ost);
[834ff3]215};
216
217ostream & operator << (ostream &ost, const TesselPoint &a);
218
219// =========================================================== class POINTCLOUD ============================================
220
221/** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
222 * This basically encapsulates a list structure.
223 */
224class PointCloud {
225public:
226 PointCloud();
[f4a346]227 virtual ~PointCloud();
[834ff3]228
[cc9225]229 virtual const char * const GetName() const { return "unknown"; };
[543ce4]230 virtual Vector *GetCenter() const { return NULL; };
[a9b2a0a]231 virtual TesselPoint *GetPoint() const { return NULL; };
232 virtual TesselPoint *GetTerminalPoint() const { return NULL; };
[ff4611]233 virtual int GetMaxId() const { return 0; };
[a9b2a0a]234 virtual void GoToNext() const {};
235 virtual void GoToPrevious() const {};
236 virtual void GoToFirst() const {};
237 virtual void GoToLast() const {};
[cc9225]238 virtual bool IsEmpty() const { return true; };
239 virtual bool IsEnd() const { return true; };
[834ff3]240};
241
242// ======================================================== class CandidateForTesselation =========================================
243
244class CandidateForTesselation {
245 public :
[4af89b]246 CandidateForTesselation(BoundaryLineSet* currentBaseLine);
[834ff3]247 CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
248 ~CandidateForTesselation();
249
[be2997]250 TesselPointList pointlist;
[834ff3]251 BoundaryLineSet *BaseLine;
252 Vector OptCenter;
253 Vector OtherOptCenter;
[4af89b]254 double ShortestAngle;
255 double OtherShortestAngle;
[834ff3]256};
257
[4af89b]258ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
259
[834ff3]260// =========================================================== class TESSELATION ===========================================
261
262/** Contains the envelope to a PointCloud.
263 */
[0cf171]264class Tesselation : public PointCloud {
[834ff3]265 public:
266
267 Tesselation();
[0cf171]268 virtual ~Tesselation();
[834ff3]269
[a9b2a0a]270 void AddTesselationPoint(TesselPoint* Candidate, const int n);
[09d3b8]271 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
[a9b2a0a]272 void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
273 void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
[eb58a7]274 void AddTesselationTriangle();
[a9b2a0a]275 void AddTesselationTriangle(const int nr);
[be2997]276 void AddCandidateTriangle(CandidateForTesselation CandidateLine);
[eb58a7]277 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
278 void RemoveTesselationLine(class BoundaryLineSet *line);
279 void RemoveTesselationPoint(class BoundaryPointSet *point);
280
[834ff3]281
282 // concave envelope
[543ce4]283 void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
[a9b2a0a]284 void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
[be2997]285 void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
[4af89b]286 bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
[09d3b8]287 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
[543ce4]288 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
[834ff3]289
290 // convex envelope
[543ce4]291 void TesselateOnBoundary(const PointCloud * const cloud);
292 void GuessStartingTriangle();
293 bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
294 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
295 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
296 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
297 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
[60cbe5]298 map<int, int> * FindAllDegeneratedTriangles();
299 map<int, int> * FindAllDegeneratedLines();
[d6b011]300 void RemoveDegeneratedTriangles();
[543ce4]301 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
[f7490d]302 int CorrectAllDegeneratedPolygons();
[eb58a7]303
[543ce4]304 set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
305 set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
306 list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
307 list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
[013ad57]308 list<TesselPoint*> * GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
[ff4611]309 list<TesselPoint*> * GetCircleOfConnectedTriangles(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const;
[a9b2a0a]310 class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
311 list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
[543ce4]312 list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
313 class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
[ff4611]314 bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC, const double epsilon = -MYEPSILON) const;
[a9b2a0a]315 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
[a1acc5]316 DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
[eda56a]317 BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
318 TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
319 BoundaryTriangleSet* FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
[f4a346]320
[27459a]321 // print for debugging
[a9b2a0a]322 void PrintAllBoundaryPoints(ofstream *out) const;
323 void PrintAllBoundaryLines(ofstream *out) const;
324 void PrintAllBoundaryTriangles(ofstream *out) const;
[27459a]325
[60cbe5]326 // store envelope in file
[543ce4]327 void Output(const char *filename, const PointCloud * const cloud);
[27459a]328
[834ff3]329 PointMap PointsOnBoundary;
330 LineMap LinesOnBoundary;
[4af89b]331 CandidateMap OpenLines;
[834ff3]332 TriangleMap TrianglesOnBoundary;
333 int PointsOnBoundaryCount;
334 int LinesOnBoundaryCount;
335 int TrianglesOnBoundaryCount;
336
[0cf171]337 // PointCloud implementation for PointsOnBoundary
[a9b2a0a]338 virtual Vector *GetCenter(ofstream *out) const;
339 virtual TesselPoint *GetPoint() const;
340 virtual TesselPoint *GetTerminalPoint() const;
341 virtual void GoToNext() const;
342 virtual void GoToPrevious() const;
343 virtual void GoToFirst() const;
344 virtual void GoToLast() const;
345 virtual bool IsEmpty() const;
346 virtual bool IsEnd() const;
[0cf171]347
[834ff3]348 class BoundaryPointSet *BPS[2];
349 class BoundaryLineSet *BLS[3];
350 class BoundaryTriangleSet *BTS;
[60cbe5]351 class BoundaryTriangleSet *LastTriangle;
352 int TriangleFilesWritten;
[0cf171]353
[70c4567]354 private:
[09d3b8]355 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
[70c4567]356
[a9b2a0a]357 mutable PointMap::const_iterator InternalPointer;
[09d3b8]358
[be2997]359 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
[834ff3]360};
361
362
363#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.