[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;
|
---|
[16d866] | 80 | double value;
|
---|
[357fba] | 81 | int Nr;
|
---|
| 82 | };
|
---|
| 83 |
|
---|
| 84 | ostream & operator << (ostream &ost, BoundaryPointSet &a);
|
---|
| 85 |
|
---|
| 86 | // ======================================================== class BoundaryLineSet ==========================================
|
---|
| 87 |
|
---|
| 88 | class BoundaryLineSet {
|
---|
| 89 | public:
|
---|
| 90 | BoundaryLineSet();
|
---|
| 91 | BoundaryLineSet(class BoundaryPointSet *Point[2], int number);
|
---|
| 92 | ~BoundaryLineSet();
|
---|
| 93 |
|
---|
| 94 | void AddTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 95 | bool IsConnectedTo(class BoundaryLineSet *line);
|
---|
| 96 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
| 97 | bool CheckConvexityCriterion(ofstream *out);
|
---|
[62bb91] | 98 | class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
|
---|
[357fba] | 99 |
|
---|
| 100 | class BoundaryPointSet *endpoints[2];
|
---|
| 101 | TriangleMap triangles;
|
---|
| 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);
|
---|
[62bb91] | 119 | class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
|
---|
[357fba] | 120 | bool IsPresentTupel(class BoundaryPointSet *Points[3]);
|
---|
[62bb91] | 121 | void GetCenter(Vector *center);
|
---|
[357fba] | 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();
|
---|
[5c7bf8] | 138 | virtual ~TesselPoint();
|
---|
[357fba] | 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
|
---|
[5c7bf8] | 143 |
|
---|
| 144 | virtual ostream & operator << (ostream &ost);
|
---|
[357fba] | 145 | };
|
---|
| 146 |
|
---|
| 147 | ostream & operator << (ostream &ost, const TesselPoint &a);
|
---|
| 148 |
|
---|
| 149 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 150 |
|
---|
| 151 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
|
---|
| 152 | * This basically encapsulates a list structure.
|
---|
| 153 | */
|
---|
| 154 | class PointCloud {
|
---|
| 155 | public:
|
---|
| 156 | PointCloud();
|
---|
[ab1932] | 157 | virtual ~PointCloud();
|
---|
[357fba] | 158 |
|
---|
| 159 | virtual Vector *GetCenter(ofstream *out) { return NULL; };
|
---|
| 160 | virtual TesselPoint *GetPoint() { return NULL; };
|
---|
| 161 | virtual TesselPoint *GetTerminalPoint() { return NULL; };
|
---|
| 162 | virtual void GoToNext() {};
|
---|
| 163 | virtual void GoToPrevious() {};
|
---|
| 164 | virtual void GoToFirst() {};
|
---|
| 165 | virtual void GoToLast() {};
|
---|
| 166 | virtual bool IsEmpty() { return false; };
|
---|
[1999d8] | 167 | virtual bool IsEnd() { return false; };
|
---|
[357fba] | 168 | };
|
---|
| 169 |
|
---|
| 170 | // ======================================================== class CandidateForTesselation =========================================
|
---|
| 171 |
|
---|
| 172 | class CandidateForTesselation {
|
---|
| 173 | public :
|
---|
| 174 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
|
---|
| 175 | ~CandidateForTesselation();
|
---|
| 176 |
|
---|
| 177 | TesselPoint *point;
|
---|
| 178 | BoundaryLineSet *BaseLine;
|
---|
| 179 | Vector OptCenter;
|
---|
| 180 | Vector OtherOptCenter;
|
---|
| 181 | };
|
---|
| 182 |
|
---|
| 183 | // =========================================================== class TESSELATION ===========================================
|
---|
| 184 |
|
---|
| 185 | /** Contains the envelope to a PointCloud.
|
---|
| 186 | */
|
---|
[5c7bf8] | 187 | class Tesselation : public PointCloud {
|
---|
[357fba] | 188 | public:
|
---|
| 189 |
|
---|
| 190 | Tesselation();
|
---|
[5c7bf8] | 191 | virtual ~Tesselation();
|
---|
[357fba] | 192 |
|
---|
[16d866] | 193 | void AddTesselationPoint(TesselPoint* Candidate, int n);
|
---|
| 194 | void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n);
|
---|
| 195 | void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, int n);
|
---|
| 196 | void AddTesselationTriangle();
|
---|
| 197 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 198 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
| 199 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
| 200 |
|
---|
[357fba] | 201 | bool IsInside(Vector *pointer);
|
---|
| 202 | class BoundaryPointSet *GetCommonEndpoint(class BoundaryLineSet * line1, class BoundaryLineSet * line2);
|
---|
| 203 |
|
---|
| 204 | // concave envelope
|
---|
| 205 | void Find_starting_triangle(ofstream *out, const double RADIUS, class LinkedCell *LC);
|
---|
| 206 | 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);
|
---|
| 207 | 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);
|
---|
| 208 | bool Find_next_suitable_triangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC);
|
---|
| 209 | int CheckPresenceOfTriangle(ofstream *out, class TesselPoint *Candidates[3]);
|
---|
| 210 |
|
---|
| 211 | // convex envelope
|
---|
| 212 | void TesselateOnBoundary(ofstream *out, PointCloud *cloud);
|
---|
| 213 | void GuessStartingTriangle(ofstream *out);
|
---|
[62bb91] | 214 | bool InsertStraddlingPoints(ofstream *out, PointCloud *cloud, LinkedCell *LC);
|
---|
[16d866] | 215 | double RemovePointFromTesselatedSurface(ofstream *out, class BoundaryPointSet *point);
|
---|
| 216 | bool FlipBaseline(ofstream *out, class BoundaryLineSet *Base);
|
---|
| 217 | bool PickFarthestofTwoBaselines(ofstream *out, class BoundaryLineSet *Base);
|
---|
| 218 | class BoundaryPointSet *IsConvexRectangle(ofstream *out, class BoundaryLineSet *Base);
|
---|
| 219 |
|
---|
[357fba] | 220 |
|
---|
[16d866] | 221 | list<TesselPoint*> * getCircleOfConnectedPoints(ofstream *out, TesselPoint* Point);
|
---|
| 222 | list<TesselPoint*> * getNeighboursonCircleofConnectedPoints(ofstream *out, list<TesselPoint*> *connectedPoints, TesselPoint* Point, Vector* Reference);
|
---|
[ab1932] | 223 | list<BoundaryTriangleSet*> *FindTriangles(TesselPoint* Points[3]);
|
---|
[62bb91] | 224 | list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(ofstream *out, Vector *x, LinkedCell* LC);
|
---|
| 225 | class BoundaryTriangleSet * FindClosestTriangleToPoint(ofstream *out, Vector *x, LinkedCell* LC);
|
---|
| 226 | bool IsInnerPoint(ofstream *out, Vector Point, LinkedCell* LC);
|
---|
| 227 | bool IsInnerPoint(ofstream *out, TesselPoint *Point, LinkedCell* LC);
|
---|
[16d866] | 228 | bool AddBoundaryPoint(TesselPoint *Walker, int n);
|
---|
[ab1932] | 229 |
|
---|
[0077b5] | 230 | // print for debugging
|
---|
| 231 | void PrintAllBoundaryPoints(ofstream *out);
|
---|
| 232 | void PrintAllBoundaryLines(ofstream *out);
|
---|
| 233 | void PrintAllBoundaryTriangles(ofstream *out);
|
---|
| 234 |
|
---|
| 235 |
|
---|
[357fba] | 236 | PointMap PointsOnBoundary;
|
---|
| 237 | LineMap LinesOnBoundary;
|
---|
| 238 | TriangleMap TrianglesOnBoundary;
|
---|
| 239 | int PointsOnBoundaryCount;
|
---|
| 240 | int LinesOnBoundaryCount;
|
---|
| 241 | int TrianglesOnBoundaryCount;
|
---|
| 242 |
|
---|
[5c7bf8] | 243 | // PointCloud implementation for PointsOnBoundary
|
---|
| 244 | virtual Vector *GetCenter(ofstream *out);
|
---|
| 245 | virtual TesselPoint *GetPoint();
|
---|
| 246 | virtual TesselPoint *GetTerminalPoint();
|
---|
| 247 | virtual void GoToNext();
|
---|
| 248 | virtual void GoToPrevious();
|
---|
| 249 | virtual void GoToFirst();
|
---|
| 250 | virtual void GoToLast();
|
---|
| 251 | virtual bool IsEmpty();
|
---|
| 252 | virtual bool IsEnd();
|
---|
| 253 |
|
---|
[357fba] | 254 | class BoundaryPointSet *BPS[2];
|
---|
| 255 | class BoundaryLineSet *BLS[3];
|
---|
| 256 | class BoundaryTriangleSet *BTS;
|
---|
[5c7bf8] | 257 |
|
---|
[08ef35] | 258 | private:
|
---|
| 259 | class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
| 260 |
|
---|
[5c7bf8] | 261 | PointMap::iterator InternalPointer;
|
---|
[357fba] | 262 | };
|
---|
| 263 |
|
---|
| 264 | bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3]);
|
---|
| 265 | bool sortCandidates(class CandidateForTesselation* candidate1, class CandidateForTesselation* candidate2);
|
---|
[5c7bf8] | 266 | TesselPoint* findClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC);
|
---|
| 267 | TesselPoint* findSecondClosestPoint(const Vector*, LinkedCell*);
|
---|
| 268 | double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector);
|
---|
[16d866] | 269 | Vector * GetClosestPointBetweenLine(ofstream *out, class BoundaryLineSet *Base, class BoundaryLineSet *OtherBase);
|
---|
[357fba] | 270 |
|
---|
| 271 | #endif /* TESSELATION_HPP_ */
|
---|