source: molecuilder/src/tesselation.hpp@ 01d28a

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

GetDistanceToSurface() separated, filling now with water instead of boron, DissectMoleculeIntoConnectedSubgraphs() now working on list of molecules instead of single one.

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

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