source: molecuilder/src/tesselation.hpp@ 25e17e9

Last change on this file since 25e17e9 was f07455, checked in by Frederik Heber <heber@…>, 15 years ago

FIX: Tesselation::FindStartingTriangle() returns false when no triangle could have been created.

  • this may act in the future as the beginning to some mean of increasing radii or another way to find a starting triangle.
  • Property mode set to 100644
File size: 16.0 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
[a732ff]44#define DoRaster3DOutput 1
[6dd8d3]45#define DoVRMLOutput 0
[60cbe5]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
[478683]90#define ListOfTesselPointList list<list <TesselPoint *> *>
91
[c43766]92enum centers {Opt, OtherOpt};
93
[17b3a5c]94/********************************************** declarations *******************************/
[834ff3]95
96template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
97{
98 if (endpoint1->Nr < endpoint2->Nr) {
99 endpoints[0] = endpoint1;
100 endpoints[1] = endpoint2;
101 } else {
102 endpoints[0] = endpoint2;
103 endpoints[1] = endpoint1;
104 }
105};
106
107// ======================================================== class BoundaryPointSet =========================================
108
109class BoundaryPointSet {
110 public:
111 BoundaryPointSet();
[1aa2a5]112 BoundaryPointSet(TesselPoint * const Walker);
[834ff3]113 ~BoundaryPointSet();
114
[1aa2a5]115 void AddLine(BoundaryLineSet * const line);
[834ff3]116
117 LineMap lines;
118 int LinesCount;
119 TesselPoint *node;
[eb58a7]120 double value;
[834ff3]121 int Nr;
122};
123
[a9b2a0a]124ostream & operator << (ostream &ost, const BoundaryPointSet &a);
[834ff3]125
126// ======================================================== class BoundaryLineSet ==========================================
127
128class BoundaryLineSet {
129 public:
130 BoundaryLineSet();
[1aa2a5]131 BoundaryLineSet(BoundaryPointSet * const Point[2], const int number);
132 BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number);
[834ff3]133 ~BoundaryLineSet();
134
[1aa2a5]135 void AddTriangle(BoundaryTriangleSet * const triangle);
136 bool IsConnectedTo(const BoundaryLineSet * const line) const;
137 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
138 bool CheckConvexityCriterion() const;
139 class BoundaryPointSet *GetOtherEndpoint(const BoundaryPointSet * const point) const;
[834ff3]140
141 class BoundaryPointSet *endpoints[2];
142 TriangleMap triangles;
143 int Nr;
[4af89b]144 bool skipped;
[834ff3]145};
146
[a9b2a0a]147ostream & operator << (ostream &ost, const BoundaryLineSet &a);
[834ff3]148
149// ======================================================== class BoundaryTriangleSet =======================================
150
151class BoundaryTriangleSet {
152 public:
153 BoundaryTriangleSet();
[1aa2a5]154 BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number);
[834ff3]155 ~BoundaryTriangleSet();
156
[1aa2a5]157 void GetNormalVector(const Vector &NormalVector);
158 void GetCenter(Vector * const center) const;
159 bool GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const;
160 double GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const;
161 bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
162 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
163 bool ContainsBoundaryPoint(const TesselPoint * const point) const;
164 class BoundaryPointSet *GetThirdEndpoint(const BoundaryLineSet * const line) const;
165 bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
166 bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
[834ff3]167
168 class BoundaryPointSet *endpoints[3];
169 class BoundaryLineSet *lines[3];
170 Vector NormalVector;
[65f1dba]171 Vector SphereCenter;
[834ff3]172 int Nr;
173};
174
[a9b2a0a]175ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
[834ff3]176
[f7490d]177
178// ======================================================== class BoundaryTriangleSet =======================================
179
180/** Set of BoundaryPointSet.
181 * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
182 * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
183 * class (i.e. no allocation, no deletion).
184 * \note we assume that the set of endpoints reside (more or less) on a plane.
185 */
186class BoundaryPolygonSet {
187 public:
188 BoundaryPolygonSet();
189 ~BoundaryPolygonSet();
190
191 Vector * GetNormalVector(const Vector &NormalVector) const;
192 void GetCenter(Vector *center) const;
193 bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
194 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
195 bool ContainsBoundaryPoint(const TesselPoint * const point) const;
196 bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
197 bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
198 bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
199 bool ContainsPresentTupel(const PointSet &endpoints) const;
[ea3627]200 TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
[f7490d]201 bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
202
203 PointSet endpoints;
204 int Nr;
205};
206
207ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
208
[834ff3]209// =========================================================== class TESSELPOINT ===========================================
210
211/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
212 */
[6b937bd]213class TesselPoint : virtual public ParticleInfo {
[834ff3]214public:
215 TesselPoint();
[0cf171]216 virtual ~TesselPoint();
[834ff3]217
218 Vector *node; // pointer to position of the dot in space
[0cf171]219
220 virtual ostream & operator << (ostream &ost);
[834ff3]221};
222
223ostream & operator << (ostream &ost, const TesselPoint &a);
224
225// =========================================================== class POINTCLOUD ============================================
226
227/** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
228 * This basically encapsulates a list structure.
229 */
230class PointCloud {
231public:
232 PointCloud();
[f4a346]233 virtual ~PointCloud();
[834ff3]234
[cc9225]235 virtual const char * const GetName() const { return "unknown"; };
[543ce4]236 virtual Vector *GetCenter() const { return NULL; };
[a9b2a0a]237 virtual TesselPoint *GetPoint() const { return NULL; };
238 virtual TesselPoint *GetTerminalPoint() const { return NULL; };
[ff4611]239 virtual int GetMaxId() const { return 0; };
[a9b2a0a]240 virtual void GoToNext() const {};
241 virtual void GoToPrevious() const {};
242 virtual void GoToFirst() const {};
243 virtual void GoToLast() const {};
[cc9225]244 virtual bool IsEmpty() const { return true; };
245 virtual bool IsEnd() const { return true; };
[834ff3]246};
247
248// ======================================================== class CandidateForTesselation =========================================
249
250class CandidateForTesselation {
251 public :
[4af89b]252 CandidateForTesselation(BoundaryLineSet* currentBaseLine);
[a732ff]253 CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, BoundaryPointSet *point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
[834ff3]254 ~CandidateForTesselation();
255
[6dd8d3]256 bool CheckValidity(const double RADIUS, const LinkedCell *LC) const;
257
[be2997]258 TesselPointList pointlist;
[a732ff]259 const BoundaryLineSet * BaseLine;
260 const BoundaryPointSet * ThirdPoint;
261 const BoundaryTriangleSet *T;
262 Vector OldCenter;
[834ff3]263 Vector OptCenter;
264 Vector OtherOptCenter;
[4af89b]265 double ShortestAngle;
266 double OtherShortestAngle;
[834ff3]267};
268
[4af89b]269ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
270
[834ff3]271// =========================================================== class TESSELATION ===========================================
272
273/** Contains the envelope to a PointCloud.
274 */
[0cf171]275class Tesselation : public PointCloud {
[834ff3]276 public:
277
278 Tesselation();
[0cf171]279 virtual ~Tesselation();
[834ff3]280
[a9b2a0a]281 void AddTesselationPoint(TesselPoint* Candidate, const int n);
[09d3b8]282 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
[086db0]283 void AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
[7c2ebb]284 void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
285 void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
[eb58a7]286 void AddTesselationTriangle();
[a9b2a0a]287 void AddTesselationTriangle(const int nr);
[c43766]288 void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
[60612f]289 void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
[7c2ebb]290 void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
[eb58a7]291 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
292 void RemoveTesselationLine(class BoundaryLineSet *line);
293 void RemoveTesselationPoint(class BoundaryPointSet *point);
[c43766]294 bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const;
[eb58a7]295
[834ff3]296
297 // concave envelope
[f07455]298 bool FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
[a9b2a0a]299 void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
[086db0]300 void FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
301 bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
[c43766]302 bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList);
[09d3b8]303 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
[543ce4]304 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
[834ff3]305
306 // convex envelope
[543ce4]307 void TesselateOnBoundary(const PointCloud * const cloud);
308 void GuessStartingTriangle();
309 bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
310 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
311 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
312 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
313 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
[478683]314 IndexToIndex * FindAllDegeneratedTriangles();
315 IndexToIndex * FindAllDegeneratedLines();
[d6b011]316 void RemoveDegeneratedTriangles();
[543ce4]317 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
[f7490d]318 int CorrectAllDegeneratedPolygons();
[eb58a7]319
[478683]320 TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
321 TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
322 ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
323 ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
324 TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
325 TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const;
326 class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
327 TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
328 TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
329 BoundaryTriangleSet * FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
[afa056]330 bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
[478683]331 double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
[f7b476]332 double GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const;
333 BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const;
[a9b2a0a]334 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
[a1acc5]335 DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
[eda56a]336 BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
[f4a346]337
[27459a]338 // print for debugging
[a9b2a0a]339 void PrintAllBoundaryPoints(ofstream *out) const;
340 void PrintAllBoundaryLines(ofstream *out) const;
341 void PrintAllBoundaryTriangles(ofstream *out) const;
[27459a]342
[60cbe5]343 // store envelope in file
[543ce4]344 void Output(const char *filename, const PointCloud * const cloud);
[27459a]345
[834ff3]346 PointMap PointsOnBoundary;
347 LineMap LinesOnBoundary;
[4af89b]348 CandidateMap OpenLines;
[834ff3]349 TriangleMap TrianglesOnBoundary;
350 int PointsOnBoundaryCount;
351 int LinesOnBoundaryCount;
352 int TrianglesOnBoundaryCount;
353
[0cf171]354 // PointCloud implementation for PointsOnBoundary
[a9b2a0a]355 virtual Vector *GetCenter(ofstream *out) const;
356 virtual TesselPoint *GetPoint() const;
357 virtual TesselPoint *GetTerminalPoint() const;
358 virtual void GoToNext() const;
359 virtual void GoToPrevious() const;
360 virtual void GoToFirst() const;
361 virtual void GoToLast() const;
362 virtual bool IsEmpty() const;
363 virtual bool IsEnd() const;
[0cf171]364
[834ff3]365 class BoundaryPointSet *BPS[2];
366 class BoundaryLineSet *BLS[3];
367 class BoundaryTriangleSet *BTS;
[60cbe5]368 class BoundaryTriangleSet *LastTriangle;
369 int TriangleFilesWritten;
[0cf171]370
[70c4567]371 private:
[09d3b8]372 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
[70c4567]373
[a9b2a0a]374 mutable PointMap::const_iterator InternalPointer;
[09d3b8]375
[be2997]376 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
[c43766]377 void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
[834ff3]378};
379
380
381#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.