source: molecuilder/src/tesselation.hpp@ 65f1dba

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

Fix attempts of the Tesselation.

One problem still remains:

  • degenerated triangles are created more than two times.

The following has been changed:

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