source: molecuilder/src/tesselation.hpp@ 3aa635

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

Multi-Candidate-Add included and incorporated class Info into boundary.cpp, tesselation.cpp and tesselationhelpers.cpp

  • class Info incorporation:
    • (almost) all functions of boundary.cpp, tesselation.cpp and tesselationhelpers.cpp now begins with class Info FunctionName(func);
  • Property mode set to 100644
File size: 11.8 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>
[834ff3]25
[2e2a70]26#include "atom_particleinfo.hpp"
[6b937bd]27#include "helpers.hpp"
[2e2a70]28#include "vector.hpp"
[834ff3]29
[17b3a5c]30/****************************************** forward declarations *****************************/
31
[834ff3]32class BoundaryPointSet;
33class BoundaryLineSet;
34class BoundaryTriangleSet;
[17b3a5c]35class LinkedCell;
[834ff3]36class TesselPoint;
37class PointCloud;
38class Tesselation;
39
[17b3a5c]40/********************************************** definitions *********************************/
41
[60cbe5]42#define DoTecplotOutput 1
43#define DoRaster3DOutput 1
44#define DoVRMLOutput 1
45#define TecplotSuffix ".dat"
46#define Raster3DSuffix ".r3d"
47#define VRMLSUffix ".wrl"
48
[834ff3]49// ======================================================= some template functions =========================================
50
51#define PointMap map < int, class BoundaryPointSet * >
52#define PointPair pair < int, class BoundaryPointSet * >
53#define PointTestPair pair < PointMap::iterator, bool >
54#define CandidateList list <class CandidateForTesselation *>
[4af89b]55#define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
[834ff3]56
57#define LineMap multimap < int, class BoundaryLineSet * >
58#define LinePair pair < int, class BoundaryLineSet * >
59#define LineTestPair pair < LineMap::iterator, bool >
60
61#define TriangleMap map < int, class BoundaryTriangleSet * >
62#define TrianglePair pair < int, class BoundaryTriangleSet * >
63#define TriangleTestPair pair < TrianglePair::iterator, bool >
64
65#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
66#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
67
[be2997]68#define TesselPointList list <TesselPoint *>
69
[17b3a5c]70/********************************************** declarations *******************************/
[834ff3]71
72template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
73{
74 if (endpoint1->Nr < endpoint2->Nr) {
75 endpoints[0] = endpoint1;
76 endpoints[1] = endpoint2;
77 } else {
78 endpoints[0] = endpoint2;
79 endpoints[1] = endpoint1;
80 }
81};
82
83// ======================================================== class BoundaryPointSet =========================================
84
85class BoundaryPointSet {
86 public:
87 BoundaryPointSet();
[a9b2a0a]88 BoundaryPointSet(TesselPoint * Walker);
[834ff3]89 ~BoundaryPointSet();
90
91 void AddLine(class BoundaryLineSet *line);
92
93 LineMap lines;
94 int LinesCount;
95 TesselPoint *node;
[eb58a7]96 double value;
[834ff3]97 int Nr;
98};
99
[a9b2a0a]100ostream & operator << (ostream &ost, const BoundaryPointSet &a);
[834ff3]101
102// ======================================================== class BoundaryLineSet ==========================================
103
104class BoundaryLineSet {
105 public:
106 BoundaryLineSet();
[a9b2a0a]107 BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
[834ff3]108 ~BoundaryLineSet();
109
110 void AddTriangle(class BoundaryTriangleSet *triangle);
111 bool IsConnectedTo(class BoundaryLineSet *line);
112 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
[543ce4]113 bool CheckConvexityCriterion();
[eeefb3]114 class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
[834ff3]115
116 class BoundaryPointSet *endpoints[2];
117 TriangleMap triangles;
118 int Nr;
[4af89b]119 bool skipped;
[834ff3]120};
121
[a9b2a0a]122ostream & operator << (ostream &ost, const BoundaryLineSet &a);
[834ff3]123
124// ======================================================== class BoundaryTriangleSet =======================================
125
126class BoundaryTriangleSet {
127 public:
128 BoundaryTriangleSet();
129 BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
130 ~BoundaryTriangleSet();
131
132 void GetNormalVector(Vector &NormalVector);
[60cbe5]133 void GetCenter(Vector *center);
[543ce4]134 bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
[834ff3]135 bool ContainsBoundaryLine(class BoundaryLineSet *line);
136 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
[daf956]137 bool ContainsBoundaryPoint(class TesselPoint *point);
[eeefb3]138 class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
[834ff3]139 bool IsPresentTupel(class BoundaryPointSet *Points[3]);
[60cbe5]140 bool IsPresentTupel(class BoundaryTriangleSet *T);
[834ff3]141
142 class BoundaryPointSet *endpoints[3];
143 class BoundaryLineSet *lines[3];
144 Vector NormalVector;
145 int Nr;
146};
147
[a9b2a0a]148ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
[834ff3]149
150// =========================================================== class TESSELPOINT ===========================================
151
152/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
153 */
[6b937bd]154class TesselPoint : virtual public ParticleInfo {
[834ff3]155public:
156 TesselPoint();
[0cf171]157 virtual ~TesselPoint();
[834ff3]158
159 Vector *node; // pointer to position of the dot in space
[0cf171]160
161 virtual ostream & operator << (ostream &ost);
[834ff3]162};
163
164ostream & operator << (ostream &ost, const TesselPoint &a);
165
166// =========================================================== class POINTCLOUD ============================================
167
168/** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
169 * This basically encapsulates a list structure.
170 */
171class PointCloud {
172public:
173 PointCloud();
[f4a346]174 virtual ~PointCloud();
[834ff3]175
[cc9225]176 virtual const char * const GetName() const { return "unknown"; };
[543ce4]177 virtual Vector *GetCenter() const { return NULL; };
[a9b2a0a]178 virtual TesselPoint *GetPoint() const { return NULL; };
179 virtual TesselPoint *GetTerminalPoint() const { return NULL; };
180 virtual void GoToNext() const {};
181 virtual void GoToPrevious() const {};
182 virtual void GoToFirst() const {};
183 virtual void GoToLast() const {};
[cc9225]184 virtual bool IsEmpty() const { return true; };
185 virtual bool IsEnd() const { return true; };
[834ff3]186};
187
188// ======================================================== class CandidateForTesselation =========================================
189
190class CandidateForTesselation {
191 public :
[4af89b]192 CandidateForTesselation(BoundaryLineSet* currentBaseLine);
[834ff3]193 CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
194 ~CandidateForTesselation();
195
[be2997]196 TesselPointList pointlist;
[834ff3]197 BoundaryLineSet *BaseLine;
198 Vector OptCenter;
199 Vector OtherOptCenter;
[4af89b]200 double ShortestAngle;
201 double OtherShortestAngle;
[834ff3]202};
203
[4af89b]204ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
205
[834ff3]206// =========================================================== class TESSELATION ===========================================
207
208/** Contains the envelope to a PointCloud.
209 */
[0cf171]210class Tesselation : public PointCloud {
[834ff3]211 public:
212
213 Tesselation();
[0cf171]214 virtual ~Tesselation();
[834ff3]215
[a9b2a0a]216 void AddTesselationPoint(TesselPoint* Candidate, const int n);
[09d3b8]217 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
[a9b2a0a]218 void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
219 void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
[eb58a7]220 void AddTesselationTriangle();
[a9b2a0a]221 void AddTesselationTriangle(const int nr);
[be2997]222 void AddCandidateTriangle(CandidateForTesselation CandidateLine);
[eb58a7]223 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
224 void RemoveTesselationLine(class BoundaryLineSet *line);
225 void RemoveTesselationPoint(class BoundaryPointSet *point);
226
[834ff3]227
228 // concave envelope
[543ce4]229 void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
[a9b2a0a]230 void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
[be2997]231 void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
[4af89b]232 bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
[09d3b8]233 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
[543ce4]234 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
[834ff3]235
236 // convex envelope
[543ce4]237 void TesselateOnBoundary(const PointCloud * const cloud);
238 void GuessStartingTriangle();
239 bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
240 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
241 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
242 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
243 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
[60cbe5]244 map<int, int> * FindAllDegeneratedTriangles();
245 map<int, int> * FindAllDegeneratedLines();
[d6b011]246 void RemoveDegeneratedTriangles();
[543ce4]247 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
[eb58a7]248
[543ce4]249 set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
250 set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
251 list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
252 list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
253 list<TesselPoint*> * GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference = NULL) const;
[a9b2a0a]254 class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
255 list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
[543ce4]256 list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
257 class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
258 bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
259 bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
[a9b2a0a]260 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
[f4a346]261
[27459a]262 // print for debugging
[a9b2a0a]263 void PrintAllBoundaryPoints(ofstream *out) const;
264 void PrintAllBoundaryLines(ofstream *out) const;
265 void PrintAllBoundaryTriangles(ofstream *out) const;
[27459a]266
[60cbe5]267 // store envelope in file
[543ce4]268 void Output(const char *filename, const PointCloud * const cloud);
[27459a]269
[834ff3]270 PointMap PointsOnBoundary;
271 LineMap LinesOnBoundary;
[4af89b]272 CandidateMap OpenLines;
[834ff3]273 TriangleMap TrianglesOnBoundary;
274 int PointsOnBoundaryCount;
275 int LinesOnBoundaryCount;
276 int TrianglesOnBoundaryCount;
277
[0cf171]278 // PointCloud implementation for PointsOnBoundary
[a9b2a0a]279 virtual Vector *GetCenter(ofstream *out) const;
280 virtual TesselPoint *GetPoint() const;
281 virtual TesselPoint *GetTerminalPoint() const;
282 virtual void GoToNext() const;
283 virtual void GoToPrevious() const;
284 virtual void GoToFirst() const;
285 virtual void GoToLast() const;
286 virtual bool IsEmpty() const;
287 virtual bool IsEnd() const;
[0cf171]288
[834ff3]289 class BoundaryPointSet *BPS[2];
290 class BoundaryLineSet *BLS[3];
291 class BoundaryTriangleSet *BTS;
[60cbe5]292 class BoundaryTriangleSet *LastTriangle;
293 int TriangleFilesWritten;
[0cf171]294
[70c4567]295 private:
[09d3b8]296 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
[70c4567]297
[a9b2a0a]298 mutable PointMap::const_iterator InternalPointer;
[09d3b8]299
[be2997]300 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
[834ff3]301};
302
303
304#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.