| 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 |  | 
|---|
| 13 | using namespace std; | 
|---|
| 14 |  | 
|---|
| 15 | // include config.h | 
|---|
| 16 | #ifdef HAVE_CONFIG_H | 
|---|
| 17 | #include <config.h> | 
|---|
| 18 | #endif | 
|---|
| 19 |  | 
|---|
| 20 | #include <map> | 
|---|
| 21 | #include <list> | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 | #include "helpers.hpp" | 
|---|
| 25 | #include "linkedcell.hpp" | 
|---|
| 26 | #include "tesselationhelpers.hpp" | 
|---|
| 27 | #include "vector.hpp" | 
|---|
| 28 |  | 
|---|
| 29 | class BoundaryPointSet; | 
|---|
| 30 | class BoundaryLineSet; | 
|---|
| 31 | class BoundaryTriangleSet; | 
|---|
| 32 | class TesselPoint; | 
|---|
| 33 | class PointCloud; | 
|---|
| 34 | class Tesselation; | 
|---|
| 35 |  | 
|---|
| 36 | // ======================================================= some template functions ========================================= | 
|---|
| 37 |  | 
|---|
| 38 | #define PointMap map < int, class BoundaryPointSet * > | 
|---|
| 39 | #define PointPair pair < int, class BoundaryPointSet * > | 
|---|
| 40 | #define PointTestPair pair < PointMap::iterator, bool > | 
|---|
| 41 | #define CandidateList list <class CandidateForTesselation *> | 
|---|
| 42 |  | 
|---|
| 43 | #define LineMap multimap < int, class BoundaryLineSet * > | 
|---|
| 44 | #define LinePair pair < int, class BoundaryLineSet * > | 
|---|
| 45 | #define LineTestPair pair < LineMap::iterator, bool > | 
|---|
| 46 |  | 
|---|
| 47 | #define TriangleMap map < int, class BoundaryTriangleSet * > | 
|---|
| 48 | #define TrianglePair pair < int, class BoundaryTriangleSet * > | 
|---|
| 49 | #define TriangleTestPair pair < TrianglePair::iterator, bool > | 
|---|
| 50 |  | 
|---|
| 51 | #define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> > | 
|---|
| 52 | #define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> > | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2) | 
|---|
| 57 | { | 
|---|
| 58 | if (endpoint1->Nr < endpoint2->Nr) { | 
|---|
| 59 | endpoints[0] = endpoint1; | 
|---|
| 60 | endpoints[1] = endpoint2; | 
|---|
| 61 | } else { | 
|---|
| 62 | endpoints[0] = endpoint2; | 
|---|
| 63 | endpoints[1] = endpoint1; | 
|---|
| 64 | } | 
|---|
| 65 | }; | 
|---|
| 66 |  | 
|---|
| 67 | // ======================================================== class BoundaryPointSet ========================================= | 
|---|
| 68 |  | 
|---|
| 69 | class BoundaryPointSet { | 
|---|
| 70 | public: | 
|---|
| 71 | BoundaryPointSet(); | 
|---|
| 72 | BoundaryPointSet(TesselPoint *Walker); | 
|---|
| 73 | ~BoundaryPointSet(); | 
|---|
| 74 |  | 
|---|
| 75 | void AddLine(class BoundaryLineSet *line); | 
|---|
| 76 |  | 
|---|
| 77 | LineMap lines; | 
|---|
| 78 | int LinesCount; | 
|---|
| 79 | TesselPoint *node; | 
|---|
| 80 | int Nr; | 
|---|
| 81 | }; | 
|---|
| 82 |  | 
|---|
| 83 | ostream & operator << (ostream &ost, BoundaryPointSet &a); | 
|---|
| 84 |  | 
|---|
| 85 | // ======================================================== class BoundaryLineSet ========================================== | 
|---|
| 86 |  | 
|---|
| 87 | class BoundaryLineSet { | 
|---|
| 88 | public: | 
|---|
| 89 | BoundaryLineSet(); | 
|---|
| 90 | BoundaryLineSet(class BoundaryPointSet *Point[2], int number); | 
|---|
| 91 | ~BoundaryLineSet(); | 
|---|
| 92 |  | 
|---|
| 93 | void AddTriangle(class BoundaryTriangleSet *triangle); | 
|---|
| 94 | bool IsConnectedTo(class BoundaryLineSet *line); | 
|---|
| 95 | bool ContainsBoundaryPoint(class BoundaryPointSet *point); | 
|---|
| 96 | bool CheckConvexityCriterion(ofstream *out); | 
|---|
| 97 | class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *); | 
|---|
| 98 |  | 
|---|
| 99 | class BoundaryPointSet *endpoints[2]; | 
|---|
| 100 | TriangleMap triangles; | 
|---|
| 101 | int TrianglesCount; | 
|---|
| 102 | int Nr; | 
|---|
| 103 | }; | 
|---|
| 104 |  | 
|---|
| 105 | ostream & operator << (ostream &ost, BoundaryLineSet &a); | 
|---|
| 106 |  | 
|---|
| 107 | // ======================================================== class BoundaryTriangleSet ======================================= | 
|---|
| 108 |  | 
|---|
| 109 | class BoundaryTriangleSet { | 
|---|
| 110 | public: | 
|---|
| 111 | BoundaryTriangleSet(); | 
|---|
| 112 | BoundaryTriangleSet(class BoundaryLineSet *line[3], int number); | 
|---|
| 113 | ~BoundaryTriangleSet(); | 
|---|
| 114 |  | 
|---|
| 115 | void GetNormalVector(Vector &NormalVector); | 
|---|
| 116 | bool GetIntersectionInsideTriangle(ofstream *out, Vector *MolCenter, Vector *x, Vector *Intersection); | 
|---|
| 117 | bool ContainsBoundaryLine(class BoundaryLineSet *line); | 
|---|
| 118 | bool ContainsBoundaryPoint(class BoundaryPointSet *point); | 
|---|
| 119 | class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line); | 
|---|
| 120 | bool IsPresentTupel(class BoundaryPointSet *Points[3]); | 
|---|
| 121 | void GetCenter(Vector *center); | 
|---|
| 122 |  | 
|---|
| 123 | class BoundaryPointSet *endpoints[3]; | 
|---|
| 124 | class BoundaryLineSet *lines[3]; | 
|---|
| 125 | Vector NormalVector; | 
|---|
| 126 | int Nr; | 
|---|
| 127 | }; | 
|---|
| 128 |  | 
|---|
| 129 | ostream & operator << (ostream &ost, BoundaryTriangleSet &a); | 
|---|
| 130 |  | 
|---|
| 131 | // =========================================================== class TESSELPOINT =========================================== | 
|---|
| 132 |  | 
|---|
| 133 | /** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented. | 
|---|
| 134 | */ | 
|---|
| 135 | class TesselPoint { | 
|---|
| 136 | public: | 
|---|
| 137 | TesselPoint(); | 
|---|
| 138 | ~TesselPoint(); | 
|---|
| 139 |  | 
|---|
| 140 | Vector *node;   // pointer to position of the dot in space | 
|---|
| 141 | int nr;       // index to easierly identify | 
|---|
| 142 | char *Name;   // some name to reference to on output | 
|---|
| 143 | }; | 
|---|
| 144 |  | 
|---|
| 145 | ostream & operator << (ostream &ost, const TesselPoint &a); | 
|---|
| 146 |  | 
|---|
| 147 | // =========================================================== class POINTCLOUD ============================================ | 
|---|
| 148 |  | 
|---|
| 149 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors. | 
|---|
| 150 | * This basically encapsulates a list structure. | 
|---|
| 151 | */ | 
|---|
| 152 | class PointCloud { | 
|---|
| 153 | public: | 
|---|
| 154 | PointCloud(); | 
|---|
| 155 | virtual ~PointCloud(); | 
|---|
| 156 |  | 
|---|
| 157 | virtual Vector *GetCenter(ofstream *out) { return NULL; }; | 
|---|
| 158 | virtual TesselPoint *GetPoint() { return NULL; }; | 
|---|
| 159 | virtual TesselPoint *GetTerminalPoint() { return NULL; }; | 
|---|
| 160 | virtual void GoToNext() {}; | 
|---|
| 161 | virtual void GoToPrevious() {}; | 
|---|
| 162 | virtual void GoToFirst() {}; | 
|---|
| 163 | virtual void GoToLast() {}; | 
|---|
| 164 | virtual bool IsEmpty() { return false; }; | 
|---|
| 165 | virtual bool IsEnd() { return false; }; | 
|---|
| 166 | }; | 
|---|
| 167 |  | 
|---|
| 168 | // ======================================================== class CandidateForTesselation ========================================= | 
|---|
| 169 |  | 
|---|
| 170 | class CandidateForTesselation { | 
|---|
| 171 | public : | 
|---|
| 172 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter); | 
|---|
| 173 | ~CandidateForTesselation(); | 
|---|
| 174 |  | 
|---|
| 175 | TesselPoint *point; | 
|---|
| 176 | BoundaryLineSet *BaseLine; | 
|---|
| 177 | Vector OptCenter; | 
|---|
| 178 | Vector OtherOptCenter; | 
|---|
| 179 | }; | 
|---|
| 180 |  | 
|---|
| 181 | // =========================================================== class TESSELATION =========================================== | 
|---|
| 182 |  | 
|---|
| 183 | /** Contains the envelope to a PointCloud. | 
|---|
| 184 | */ | 
|---|
| 185 | class Tesselation { | 
|---|
| 186 | public: | 
|---|
| 187 |  | 
|---|
| 188 | Tesselation(); | 
|---|
| 189 | ~Tesselation(); | 
|---|
| 190 |  | 
|---|
| 191 | void AddPoint(TesselPoint *Walker); | 
|---|
| 192 | void AddTrianglePoint(TesselPoint* Candidate, int n); | 
|---|
| 193 | void AddTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n); | 
|---|
| 194 | void AlwaysAddTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n); | 
|---|
| 195 | void AddTriangle(); | 
|---|
| 196 | bool IsInside(Vector *pointer); | 
|---|
| 197 | class BoundaryPointSet *GetCommonEndpoint(class BoundaryLineSet * line1, class BoundaryLineSet * line2); | 
|---|
| 198 |  | 
|---|
| 199 | // concave envelope | 
|---|
| 200 | void Find_starting_triangle(ofstream *out, const double RADIUS, class LinkedCell *LC); | 
|---|
| 201 | void Find_second_point_for_Tesselation(class TesselPoint* a, class TesselPoint* Candidate, Vector Oben, class TesselPoint*& Opt_Candidate, double Storage[3], double RADIUS, class LinkedCell *LC); | 
|---|
| 202 | void Find_third_point_for_Tesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, class LinkedCell *LC); | 
|---|
| 203 | bool Find_next_suitable_triangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC); | 
|---|
| 204 | int CheckPresenceOfTriangle(ofstream *out, class TesselPoint *Candidates[3]); | 
|---|
| 205 |  | 
|---|
| 206 | // convex envelope | 
|---|
| 207 | void TesselateOnBoundary(ofstream *out, PointCloud *cloud); | 
|---|
| 208 | void GuessStartingTriangle(ofstream *out); | 
|---|
| 209 | bool InsertStraddlingPoints(ofstream *out, PointCloud *cloud, LinkedCell *LC); | 
|---|
| 210 | bool CorrectConcaveBaselines(ofstream *out); | 
|---|
| 211 |  | 
|---|
| 212 | list<TesselPoint*> * getCircleOfConnectedPoints(ofstream *out, TesselPoint* Point, Vector* Reference); | 
|---|
| 213 | list<BoundaryTriangleSet*> *FindTriangles(TesselPoint* Points[3]); | 
|---|
| 214 | list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(ofstream *out, Vector *x, LinkedCell* LC); | 
|---|
| 215 | class BoundaryTriangleSet * FindClosestTriangleToPoint(ofstream *out, Vector *x, LinkedCell* LC); | 
|---|
| 216 | bool IsInnerPoint(ofstream *out, Vector Point, LinkedCell* LC); | 
|---|
| 217 | bool IsInnerPoint(ofstream *out, TesselPoint *Point, LinkedCell* LC); | 
|---|
| 218 |  | 
|---|
| 219 | PointMap PointsOnBoundary; | 
|---|
| 220 | LineMap LinesOnBoundary; | 
|---|
| 221 | TriangleMap TrianglesOnBoundary; | 
|---|
| 222 | int PointsOnBoundaryCount; | 
|---|
| 223 | int LinesOnBoundaryCount; | 
|---|
| 224 | int TrianglesOnBoundaryCount; | 
|---|
| 225 |  | 
|---|
| 226 | private: | 
|---|
| 227 | class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions | 
|---|
| 228 | class BoundaryPointSet *BPS[2]; | 
|---|
| 229 | class BoundaryLineSet *BLS[3]; | 
|---|
| 230 | class BoundaryTriangleSet *BTS; | 
|---|
| 231 | }; | 
|---|
| 232 |  | 
|---|
| 233 | bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3]); | 
|---|
| 234 | bool sortCandidates(class CandidateForTesselation* candidate1, class CandidateForTesselation* candidate2); | 
|---|
| 235 | TesselPoint* findClosestPoint(const Vector* Point, LinkedCell* LC); | 
|---|
| 236 | double getAngle(const Vector &point, const Vector &reference, const Vector ¢er, Vector OrthogonalVector); | 
|---|
| 237 |  | 
|---|
| 238 | #endif /* TESSELATION_HPP_ */ | 
|---|