| [357fba] | 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 |  | 
|---|
|  | 98 | class BoundaryPointSet *endpoints[2]; | 
|---|
|  | 99 | TriangleMap triangles; | 
|---|
|  | 100 | int TrianglesCount; | 
|---|
|  | 101 | int Nr; | 
|---|
|  | 102 | }; | 
|---|
|  | 103 |  | 
|---|
|  | 104 | ostream & operator << (ostream &ost, BoundaryLineSet &a); | 
|---|
|  | 105 |  | 
|---|
|  | 106 | // ======================================================== class BoundaryTriangleSet ======================================= | 
|---|
|  | 107 |  | 
|---|
|  | 108 | class BoundaryTriangleSet { | 
|---|
|  | 109 | public: | 
|---|
|  | 110 | BoundaryTriangleSet(); | 
|---|
|  | 111 | BoundaryTriangleSet(class BoundaryLineSet *line[3], int number); | 
|---|
|  | 112 | ~BoundaryTriangleSet(); | 
|---|
|  | 113 |  | 
|---|
|  | 114 | void GetNormalVector(Vector &NormalVector); | 
|---|
|  | 115 | bool GetIntersectionInsideTriangle(ofstream *out, Vector *MolCenter, Vector *x, Vector *Intersection); | 
|---|
|  | 116 | bool ContainsBoundaryLine(class BoundaryLineSet *line); | 
|---|
|  | 117 | bool ContainsBoundaryPoint(class BoundaryPointSet *point); | 
|---|
|  | 118 | bool IsPresentTupel(class BoundaryPointSet *Points[3]); | 
|---|
|  | 119 |  | 
|---|
|  | 120 | class BoundaryPointSet *endpoints[3]; | 
|---|
|  | 121 | class BoundaryLineSet *lines[3]; | 
|---|
|  | 122 | Vector NormalVector; | 
|---|
|  | 123 | int Nr; | 
|---|
|  | 124 | }; | 
|---|
|  | 125 |  | 
|---|
|  | 126 | ostream & operator << (ostream &ost, BoundaryTriangleSet &a); | 
|---|
|  | 127 |  | 
|---|
|  | 128 | // =========================================================== class TESSELPOINT =========================================== | 
|---|
|  | 129 |  | 
|---|
|  | 130 | /** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented. | 
|---|
|  | 131 | */ | 
|---|
|  | 132 | class TesselPoint { | 
|---|
|  | 133 | public: | 
|---|
|  | 134 | TesselPoint(); | 
|---|
|  | 135 | ~TesselPoint(); | 
|---|
|  | 136 |  | 
|---|
|  | 137 | Vector *node;   // pointer to position of the dot in space | 
|---|
|  | 138 | int nr;       // index to easierly identify | 
|---|
|  | 139 | char *Name;   // some name to reference to on output | 
|---|
|  | 140 | }; | 
|---|
|  | 141 |  | 
|---|
|  | 142 | ostream & operator << (ostream &ost, const TesselPoint &a); | 
|---|
|  | 143 |  | 
|---|
|  | 144 | // =========================================================== class POINTCLOUD ============================================ | 
|---|
|  | 145 |  | 
|---|
|  | 146 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors. | 
|---|
|  | 147 | * This basically encapsulates a list structure. | 
|---|
|  | 148 | */ | 
|---|
|  | 149 | class PointCloud { | 
|---|
|  | 150 | public: | 
|---|
|  | 151 | PointCloud(); | 
|---|
|  | 152 | ~PointCloud(); | 
|---|
|  | 153 |  | 
|---|
|  | 154 | virtual Vector *GetCenter(ofstream *out) { return NULL; }; | 
|---|
|  | 155 | virtual TesselPoint *GetPoint() { return NULL; }; | 
|---|
|  | 156 | virtual TesselPoint *GetTerminalPoint() { return NULL; }; | 
|---|
|  | 157 | virtual void GoToNext() {}; | 
|---|
|  | 158 | virtual void GoToPrevious() {}; | 
|---|
|  | 159 | virtual void GoToFirst() {}; | 
|---|
|  | 160 | virtual void GoToLast() {}; | 
|---|
|  | 161 | virtual bool IsEmpty() { return false; }; | 
|---|
|  | 162 | virtual bool IsLast() { return false; }; | 
|---|
|  | 163 | }; | 
|---|
|  | 164 |  | 
|---|
|  | 165 | // ======================================================== class CandidateForTesselation ========================================= | 
|---|
|  | 166 |  | 
|---|
|  | 167 | class CandidateForTesselation { | 
|---|
|  | 168 | public : | 
|---|
|  | 169 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter); | 
|---|
|  | 170 | ~CandidateForTesselation(); | 
|---|
|  | 171 |  | 
|---|
|  | 172 | TesselPoint *point; | 
|---|
|  | 173 | BoundaryLineSet *BaseLine; | 
|---|
|  | 174 | Vector OptCenter; | 
|---|
|  | 175 | Vector OtherOptCenter; | 
|---|
|  | 176 | }; | 
|---|
|  | 177 |  | 
|---|
|  | 178 | // =========================================================== class TESSELATION =========================================== | 
|---|
|  | 179 |  | 
|---|
|  | 180 | /** Contains the envelope to a PointCloud. | 
|---|
|  | 181 | */ | 
|---|
|  | 182 | class Tesselation { | 
|---|
|  | 183 | public: | 
|---|
|  | 184 |  | 
|---|
|  | 185 | Tesselation(); | 
|---|
|  | 186 | ~Tesselation(); | 
|---|
|  | 187 |  | 
|---|
|  | 188 | void AddPoint(TesselPoint *Walker); | 
|---|
|  | 189 | void AddTrianglePoint(TesselPoint* Candidate, int n); | 
|---|
|  | 190 | void AddTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n); | 
|---|
|  | 191 | void AlwaysAddTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n); | 
|---|
|  | 192 | void AddTriangle(); | 
|---|
|  | 193 | bool IsInside(Vector *pointer); | 
|---|
|  | 194 | class BoundaryPointSet *GetCommonEndpoint(class BoundaryLineSet * line1, class BoundaryLineSet * line2); | 
|---|
|  | 195 |  | 
|---|
|  | 196 | // concave envelope | 
|---|
|  | 197 | void Find_starting_triangle(ofstream *out, const double RADIUS, class LinkedCell *LC); | 
|---|
|  | 198 | 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); | 
|---|
|  | 199 | 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); | 
|---|
|  | 200 | bool Find_next_suitable_triangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC); | 
|---|
|  | 201 | int CheckPresenceOfTriangle(ofstream *out, class TesselPoint *Candidates[3]); | 
|---|
|  | 202 |  | 
|---|
|  | 203 | // convex envelope | 
|---|
|  | 204 | class BoundaryTriangleSet * FindClosestTriangleToPoint(ofstream *out, Vector *x); | 
|---|
|  | 205 | void TesselateOnBoundary(ofstream *out, PointCloud *cloud); | 
|---|
|  | 206 | void GuessStartingTriangle(ofstream *out); | 
|---|
|  | 207 | bool InsertStraddlingPoints(ofstream *out, PointCloud *cloud); | 
|---|
|  | 208 | bool CorrectConcaveBaselines(ofstream *out); | 
|---|
|  | 209 |  | 
|---|
|  | 210 | PointMap PointsOnBoundary; | 
|---|
|  | 211 | LineMap LinesOnBoundary; | 
|---|
|  | 212 | TriangleMap TrianglesOnBoundary; | 
|---|
|  | 213 | int PointsOnBoundaryCount; | 
|---|
|  | 214 | int LinesOnBoundaryCount; | 
|---|
|  | 215 | int TrianglesOnBoundaryCount; | 
|---|
|  | 216 |  | 
|---|
|  | 217 | private: | 
|---|
|  | 218 | class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions | 
|---|
|  | 219 | class BoundaryPointSet *BPS[2]; | 
|---|
|  | 220 | class BoundaryLineSet *BLS[3]; | 
|---|
|  | 221 | class BoundaryTriangleSet *BTS; | 
|---|
|  | 222 | }; | 
|---|
|  | 223 |  | 
|---|
|  | 224 | bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3]); | 
|---|
|  | 225 | bool sortCandidates(class CandidateForTesselation* candidate1, class CandidateForTesselation* candidate2); | 
|---|
|  | 226 |  | 
|---|
|  | 227 |  | 
|---|
|  | 228 | #endif /* TESSELATION_HPP_ */ | 
|---|