[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 |
|
---|
[f66195] | 15 | /*********************************************** includes ***********************************/
|
---|
| 16 |
|
---|
[357fba] | 17 | // include config.h
|
---|
| 18 | #ifdef HAVE_CONFIG_H
|
---|
| 19 | #include <config.h>
|
---|
| 20 | #endif
|
---|
| 21 |
|
---|
| 22 | #include <map>
|
---|
| 23 | #include <list>
|
---|
[7c14ec] | 24 | #include <set>
|
---|
[357fba] | 25 |
|
---|
[6b919f8] | 26 | #include "atom_particleinfo.hpp"
|
---|
[4455f4] | 27 | #include "helpers.hpp"
|
---|
[6b919f8] | 28 | #include "vector.hpp"
|
---|
[357fba] | 29 |
|
---|
[f66195] | 30 | /****************************************** forward declarations *****************************/
|
---|
| 31 |
|
---|
[357fba] | 32 | class BoundaryPointSet;
|
---|
| 33 | class BoundaryLineSet;
|
---|
| 34 | class BoundaryTriangleSet;
|
---|
[f66195] | 35 | class LinkedCell;
|
---|
[357fba] | 36 | class TesselPoint;
|
---|
| 37 | class PointCloud;
|
---|
| 38 | class Tesselation;
|
---|
| 39 |
|
---|
[f66195] | 40 | /********************************************** definitions *********************************/
|
---|
| 41 |
|
---|
[57066a] | 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 |
|
---|
[357fba] | 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 *>
|
---|
| 55 |
|
---|
| 56 | #define LineMap multimap < int, class BoundaryLineSet * >
|
---|
| 57 | #define LinePair pair < int, class BoundaryLineSet * >
|
---|
| 58 | #define LineTestPair pair < LineMap::iterator, bool >
|
---|
| 59 |
|
---|
| 60 | #define TriangleMap map < int, class BoundaryTriangleSet * >
|
---|
| 61 | #define TrianglePair pair < int, class BoundaryTriangleSet * >
|
---|
| 62 | #define TriangleTestPair pair < TrianglePair::iterator, bool >
|
---|
| 63 |
|
---|
| 64 | #define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
| 65 | #define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
| 66 |
|
---|
[f66195] | 67 | /********************************************** declarations *******************************/
|
---|
[357fba] | 68 |
|
---|
| 69 | template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
|
---|
| 70 | {
|
---|
| 71 | if (endpoint1->Nr < endpoint2->Nr) {
|
---|
| 72 | endpoints[0] = endpoint1;
|
---|
| 73 | endpoints[1] = endpoint2;
|
---|
| 74 | } else {
|
---|
| 75 | endpoints[0] = endpoint2;
|
---|
| 76 | endpoints[1] = endpoint1;
|
---|
| 77 | }
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | // ======================================================== class BoundaryPointSet =========================================
|
---|
| 81 |
|
---|
| 82 | class BoundaryPointSet {
|
---|
| 83 | public:
|
---|
| 84 | BoundaryPointSet();
|
---|
[776b64] | 85 | BoundaryPointSet(TesselPoint * Walker);
|
---|
[357fba] | 86 | ~BoundaryPointSet();
|
---|
| 87 |
|
---|
| 88 | void AddLine(class BoundaryLineSet *line);
|
---|
| 89 |
|
---|
| 90 | LineMap lines;
|
---|
| 91 | int LinesCount;
|
---|
| 92 | TesselPoint *node;
|
---|
[16d866] | 93 | double value;
|
---|
[357fba] | 94 | int Nr;
|
---|
| 95 | };
|
---|
| 96 |
|
---|
[776b64] | 97 | ostream & operator << (ostream &ost, const BoundaryPointSet &a);
|
---|
[357fba] | 98 |
|
---|
| 99 | // ======================================================== class BoundaryLineSet ==========================================
|
---|
| 100 |
|
---|
| 101 | class BoundaryLineSet {
|
---|
| 102 | public:
|
---|
| 103 | BoundaryLineSet();
|
---|
[776b64] | 104 | BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
|
---|
[357fba] | 105 | ~BoundaryLineSet();
|
---|
| 106 |
|
---|
| 107 | void AddTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 108 | bool IsConnectedTo(class BoundaryLineSet *line);
|
---|
| 109 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
| 110 | bool CheckConvexityCriterion(ofstream *out);
|
---|
[62bb91] | 111 | class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
|
---|
[357fba] | 112 |
|
---|
| 113 | class BoundaryPointSet *endpoints[2];
|
---|
| 114 | TriangleMap triangles;
|
---|
| 115 | int Nr;
|
---|
| 116 | };
|
---|
| 117 |
|
---|
[776b64] | 118 | ostream & operator << (ostream &ost, const BoundaryLineSet &a);
|
---|
[357fba] | 119 |
|
---|
| 120 | // ======================================================== class BoundaryTriangleSet =======================================
|
---|
| 121 |
|
---|
| 122 | class BoundaryTriangleSet {
|
---|
| 123 | public:
|
---|
| 124 | BoundaryTriangleSet();
|
---|
| 125 | BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
|
---|
| 126 | ~BoundaryTriangleSet();
|
---|
| 127 |
|
---|
| 128 | void GetNormalVector(Vector &NormalVector);
|
---|
[57066a] | 129 | void GetCenter(Vector *center);
|
---|
[357fba] | 130 | bool GetIntersectionInsideTriangle(ofstream *out, Vector *MolCenter, Vector *x, Vector *Intersection);
|
---|
| 131 | bool ContainsBoundaryLine(class BoundaryLineSet *line);
|
---|
| 132 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
[7dea7c] | 133 | bool ContainsBoundaryPoint(class TesselPoint *point);
|
---|
[62bb91] | 134 | class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
|
---|
[357fba] | 135 | bool IsPresentTupel(class BoundaryPointSet *Points[3]);
|
---|
[57066a] | 136 | bool IsPresentTupel(class BoundaryTriangleSet *T);
|
---|
[357fba] | 137 |
|
---|
| 138 | class BoundaryPointSet *endpoints[3];
|
---|
| 139 | class BoundaryLineSet *lines[3];
|
---|
| 140 | Vector NormalVector;
|
---|
| 141 | int Nr;
|
---|
| 142 | };
|
---|
| 143 |
|
---|
[776b64] | 144 | ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
|
---|
[357fba] | 145 |
|
---|
| 146 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 147 |
|
---|
| 148 | /** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
|
---|
| 149 | */
|
---|
[4455f4] | 150 | class TesselPoint : virtual public ParticleInfo {
|
---|
[357fba] | 151 | public:
|
---|
| 152 | TesselPoint();
|
---|
[5c7bf8] | 153 | virtual ~TesselPoint();
|
---|
[357fba] | 154 |
|
---|
| 155 | Vector *node; // pointer to position of the dot in space
|
---|
[5c7bf8] | 156 |
|
---|
| 157 | virtual ostream & operator << (ostream &ost);
|
---|
[357fba] | 158 | };
|
---|
| 159 |
|
---|
| 160 | ostream & operator << (ostream &ost, const TesselPoint &a);
|
---|
| 161 |
|
---|
| 162 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 163 |
|
---|
| 164 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
|
---|
| 165 | * This basically encapsulates a list structure.
|
---|
| 166 | */
|
---|
| 167 | class PointCloud {
|
---|
| 168 | public:
|
---|
| 169 | PointCloud();
|
---|
[ab1932] | 170 | virtual ~PointCloud();
|
---|
[357fba] | 171 |
|
---|
[776b64] | 172 | virtual Vector *GetCenter(ofstream *out) const { return NULL; };
|
---|
| 173 | virtual TesselPoint *GetPoint() const { return NULL; };
|
---|
| 174 | virtual TesselPoint *GetTerminalPoint() const { return NULL; };
|
---|
| 175 | virtual void GoToNext() const {};
|
---|
| 176 | virtual void GoToPrevious() const {};
|
---|
| 177 | virtual void GoToFirst() const {};
|
---|
| 178 | virtual void GoToLast() const {};
|
---|
| 179 | virtual bool IsEmpty() const { return false; };
|
---|
| 180 | virtual bool IsEnd() const { return false; };
|
---|
[357fba] | 181 | };
|
---|
| 182 |
|
---|
| 183 | // ======================================================== class CandidateForTesselation =========================================
|
---|
| 184 |
|
---|
| 185 | class CandidateForTesselation {
|
---|
| 186 | public :
|
---|
| 187 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
|
---|
| 188 | ~CandidateForTesselation();
|
---|
| 189 |
|
---|
| 190 | TesselPoint *point;
|
---|
| 191 | BoundaryLineSet *BaseLine;
|
---|
| 192 | Vector OptCenter;
|
---|
| 193 | Vector OtherOptCenter;
|
---|
| 194 | };
|
---|
| 195 |
|
---|
| 196 | // =========================================================== class TESSELATION ===========================================
|
---|
| 197 |
|
---|
| 198 | /** Contains the envelope to a PointCloud.
|
---|
| 199 | */
|
---|
[5c7bf8] | 200 | class Tesselation : public PointCloud {
|
---|
[357fba] | 201 | public:
|
---|
| 202 |
|
---|
| 203 | Tesselation();
|
---|
[5c7bf8] | 204 | virtual ~Tesselation();
|
---|
[357fba] | 205 |
|
---|
[776b64] | 206 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
---|
| 207 | void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
| 208 | void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
[16d866] | 209 | void AddTesselationTriangle();
|
---|
[776b64] | 210 | void AddTesselationTriangle(const int nr);
|
---|
[16d866] | 211 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 212 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
| 213 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
| 214 |
|
---|
[357fba] | 215 |
|
---|
| 216 | // concave envelope
|
---|
[776b64] | 217 | void FindStartingTriangle(ofstream *out, const double RADIUS, const LinkedCell *LC);
|
---|
| 218 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
---|
| 219 | void FindThirdPointForTesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC);
|
---|
| 220 | bool FindNextSuitableTriangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
|
---|
[357fba] | 221 | int CheckPresenceOfTriangle(ofstream *out, class TesselPoint *Candidates[3]);
|
---|
[065e82] | 222 | class BoundaryTriangleSet * GetPresentTriangle(ofstream *out, TesselPoint *Candidates[3]);
|
---|
[357fba] | 223 |
|
---|
| 224 | // convex envelope
|
---|
[776b64] | 225 | void TesselateOnBoundary(ofstream *out, const PointCloud * const cloud);
|
---|
[357fba] | 226 | void GuessStartingTriangle(ofstream *out);
|
---|
[776b64] | 227 | bool InsertStraddlingPoints(ofstream *out, const PointCloud *cloud, const LinkedCell *LC);
|
---|
[16d866] | 228 | double RemovePointFromTesselatedSurface(ofstream *out, class BoundaryPointSet *point);
|
---|
[57066a] | 229 | class BoundaryLineSet * FlipBaseline(ofstream *out, class BoundaryLineSet *Base);
|
---|
| 230 | double PickFarthestofTwoBaselines(ofstream *out, class BoundaryLineSet *Base);
|
---|
[16d866] | 231 | class BoundaryPointSet *IsConvexRectangle(ofstream *out, class BoundaryLineSet *Base);
|
---|
[57066a] | 232 | map<int, int> * FindAllDegeneratedTriangles();
|
---|
| 233 | map<int, int> * FindAllDegeneratedLines();
|
---|
[7c14ec] | 234 | void RemoveDegeneratedTriangles();
|
---|
[57066a] | 235 | void AddBoundaryPointByDegeneratedTriangle(ofstream *out, class TesselPoint *point, LinkedCell *LC);
|
---|
[16d866] | 236 |
|
---|
[776b64] | 237 | set<TesselPoint*> * GetAllConnectedPoints(ofstream *out, const TesselPoint* const Point) const;
|
---|
| 238 | set<BoundaryTriangleSet*> *GetAllTriangles(ofstream *out, const BoundaryPointSet * const Point) const;
|
---|
| 239 | list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(ofstream *out, const TesselPoint* const Point) const;
|
---|
| 240 | list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(ofstream *out, const TesselPoint* const Point) const;
|
---|
| 241 | list<TesselPoint*> * GetCircleOfConnectedPoints(ofstream *out, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
|
---|
| 242 | class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
---|
| 243 | list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
|
---|
| 244 | list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(ofstream *out, const Vector *x, const LinkedCell* LC) const;
|
---|
| 245 | class BoundaryTriangleSet * FindClosestTriangleToPoint(ofstream *out, const Vector *x, const LinkedCell* LC) const;
|
---|
| 246 | bool IsInnerPoint(ofstream *out, const Vector &Point, const LinkedCell* const LC) const;
|
---|
| 247 | bool IsInnerPoint(ofstream *out, const TesselPoint * const Point, const LinkedCell* const LC) const;
|
---|
| 248 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
---|
[ab1932] | 249 |
|
---|
[0077b5] | 250 | // print for debugging
|
---|
[776b64] | 251 | void PrintAllBoundaryPoints(ofstream *out) const;
|
---|
| 252 | void PrintAllBoundaryLines(ofstream *out) const;
|
---|
| 253 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
---|
[0077b5] | 254 |
|
---|
[57066a] | 255 | // store envelope in file
|
---|
[776b64] | 256 | void Output(ofstream *out, const char *filename, const PointCloud * const cloud);
|
---|
[0077b5] | 257 |
|
---|
[357fba] | 258 | PointMap PointsOnBoundary;
|
---|
| 259 | LineMap LinesOnBoundary;
|
---|
| 260 | TriangleMap TrianglesOnBoundary;
|
---|
| 261 | int PointsOnBoundaryCount;
|
---|
| 262 | int LinesOnBoundaryCount;
|
---|
| 263 | int TrianglesOnBoundaryCount;
|
---|
| 264 |
|
---|
[5c7bf8] | 265 | // PointCloud implementation for PointsOnBoundary
|
---|
[776b64] | 266 | virtual Vector *GetCenter(ofstream *out) const;
|
---|
| 267 | virtual TesselPoint *GetPoint() const;
|
---|
| 268 | virtual TesselPoint *GetTerminalPoint() const;
|
---|
| 269 | virtual void GoToNext() const;
|
---|
| 270 | virtual void GoToPrevious() const;
|
---|
| 271 | virtual void GoToFirst() const;
|
---|
| 272 | virtual void GoToLast() const;
|
---|
| 273 | virtual bool IsEmpty() const;
|
---|
| 274 | virtual bool IsEnd() const;
|
---|
[5c7bf8] | 275 |
|
---|
[357fba] | 276 | class BoundaryPointSet *BPS[2];
|
---|
| 277 | class BoundaryLineSet *BLS[3];
|
---|
| 278 | class BoundaryTriangleSet *BTS;
|
---|
[57066a] | 279 | class BoundaryTriangleSet *LastTriangle;
|
---|
| 280 | int TriangleFilesWritten;
|
---|
[5c7bf8] | 281 |
|
---|
[08ef35] | 282 | private:
|
---|
| 283 | class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
| 284 |
|
---|
[776b64] | 285 | mutable PointMap::const_iterator InternalPointer;
|
---|
[357fba] | 286 | };
|
---|
| 287 |
|
---|
| 288 |
|
---|
| 289 | #endif /* TESSELATION_HPP_ */
|
---|