[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>
|
---|
[af374d] | 25 | #include <stack>
|
---|
[357fba] | 26 |
|
---|
[6b919f8] | 27 | #include "atom_particleinfo.hpp"
|
---|
[4455f4] | 28 | #include "helpers.hpp"
|
---|
[6b919f8] | 29 | #include "vector.hpp"
|
---|
[357fba] | 30 |
|
---|
[f66195] | 31 | /****************************************** forward declarations *****************************/
|
---|
| 32 |
|
---|
[357fba] | 33 | class BoundaryPointSet;
|
---|
| 34 | class BoundaryLineSet;
|
---|
| 35 | class BoundaryTriangleSet;
|
---|
[f66195] | 36 | class LinkedCell;
|
---|
[357fba] | 37 | class TesselPoint;
|
---|
| 38 | class PointCloud;
|
---|
| 39 | class Tesselation;
|
---|
| 40 |
|
---|
[f66195] | 41 | /********************************************** definitions *********************************/
|
---|
| 42 |
|
---|
[57066a] | 43 | #define DoTecplotOutput 1
|
---|
| 44 | #define DoRaster3DOutput 1
|
---|
| 45 | #define DoVRMLOutput 1
|
---|
| 46 | #define TecplotSuffix ".dat"
|
---|
| 47 | #define Raster3DSuffix ".r3d"
|
---|
| 48 | #define VRMLSUffix ".wrl"
|
---|
| 49 |
|
---|
[357fba] | 50 | // ======================================================= some template functions =========================================
|
---|
| 51 |
|
---|
| 52 | #define PointMap map < int, class BoundaryPointSet * >
|
---|
[262bae] | 53 | #define PointSet set < class BoundaryPointSet * >
|
---|
| 54 | #define PointList list < class BoundaryPointSet * >
|
---|
[357fba] | 55 | #define PointPair pair < int, class BoundaryPointSet * >
|
---|
| 56 | #define PointTestPair pair < PointMap::iterator, bool >
|
---|
[262bae] | 57 |
|
---|
[357fba] | 58 | #define CandidateList list <class CandidateForTesselation *>
|
---|
[1e168b] | 59 | #define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
|
---|
[357fba] | 60 |
|
---|
| 61 | #define LineMap multimap < int, class BoundaryLineSet * >
|
---|
[262bae] | 62 | #define LineSet set < class BoundaryLineSet * >
|
---|
| 63 | #define LineList list < class BoundaryLineSet * >
|
---|
[357fba] | 64 | #define LinePair pair < int, class BoundaryLineSet * >
|
---|
| 65 | #define LineTestPair pair < LineMap::iterator, bool >
|
---|
| 66 |
|
---|
| 67 | #define TriangleMap map < int, class BoundaryTriangleSet * >
|
---|
[262bae] | 68 | #define TriangleSet set < class BoundaryTriangleSet * >
|
---|
| 69 | #define TriangleList list < class BoundaryTriangleSet * >
|
---|
[357fba] | 70 | #define TrianglePair pair < int, class BoundaryTriangleSet * >
|
---|
| 71 | #define TriangleTestPair pair < TrianglePair::iterator, bool >
|
---|
| 72 |
|
---|
[262bae] | 73 | #define PolygonMap map < int, class BoundaryPolygonSet * >
|
---|
| 74 | #define PolygonSet set < class BoundaryPolygonSet * >
|
---|
| 75 | #define PolygonList list < class BoundaryPolygonSet * >
|
---|
| 76 |
|
---|
[357fba] | 77 | #define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
| 78 | #define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
| 79 |
|
---|
[f67b6e] | 80 | #define TesselPointList list <TesselPoint *>
|
---|
[262bae] | 81 | #define TesselPointSet set <TesselPoint *>
|
---|
[f67b6e] | 82 |
|
---|
[f66195] | 83 | /********************************************** declarations *******************************/
|
---|
[357fba] | 84 |
|
---|
| 85 | template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
|
---|
| 86 | {
|
---|
| 87 | if (endpoint1->Nr < endpoint2->Nr) {
|
---|
| 88 | endpoints[0] = endpoint1;
|
---|
| 89 | endpoints[1] = endpoint2;
|
---|
| 90 | } else {
|
---|
| 91 | endpoints[0] = endpoint2;
|
---|
| 92 | endpoints[1] = endpoint1;
|
---|
| 93 | }
|
---|
| 94 | };
|
---|
| 95 |
|
---|
| 96 | // ======================================================== class BoundaryPointSet =========================================
|
---|
| 97 |
|
---|
| 98 | class BoundaryPointSet {
|
---|
| 99 | public:
|
---|
| 100 | BoundaryPointSet();
|
---|
[776b64] | 101 | BoundaryPointSet(TesselPoint * Walker);
|
---|
[357fba] | 102 | ~BoundaryPointSet();
|
---|
| 103 |
|
---|
| 104 | void AddLine(class BoundaryLineSet *line);
|
---|
| 105 |
|
---|
| 106 | LineMap lines;
|
---|
| 107 | int LinesCount;
|
---|
| 108 | TesselPoint *node;
|
---|
[16d866] | 109 | double value;
|
---|
[357fba] | 110 | int Nr;
|
---|
| 111 | };
|
---|
| 112 |
|
---|
[776b64] | 113 | ostream & operator << (ostream &ost, const BoundaryPointSet &a);
|
---|
[357fba] | 114 |
|
---|
| 115 | // ======================================================== class BoundaryLineSet ==========================================
|
---|
| 116 |
|
---|
| 117 | class BoundaryLineSet {
|
---|
| 118 | public:
|
---|
| 119 | BoundaryLineSet();
|
---|
[776b64] | 120 | BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
|
---|
[357fba] | 121 | ~BoundaryLineSet();
|
---|
| 122 |
|
---|
| 123 | void AddTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 124 | bool IsConnectedTo(class BoundaryLineSet *line);
|
---|
| 125 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
[e138de] | 126 | bool CheckConvexityCriterion();
|
---|
[62bb91] | 127 | class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
|
---|
[357fba] | 128 |
|
---|
| 129 | class BoundaryPointSet *endpoints[2];
|
---|
| 130 | TriangleMap triangles;
|
---|
| 131 | int Nr;
|
---|
[1e168b] | 132 | bool skipped;
|
---|
[357fba] | 133 | };
|
---|
| 134 |
|
---|
[776b64] | 135 | ostream & operator << (ostream &ost, const BoundaryLineSet &a);
|
---|
[357fba] | 136 |
|
---|
| 137 | // ======================================================== class BoundaryTriangleSet =======================================
|
---|
| 138 |
|
---|
| 139 | class BoundaryTriangleSet {
|
---|
| 140 | public:
|
---|
| 141 | BoundaryTriangleSet();
|
---|
| 142 | BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
|
---|
| 143 | ~BoundaryTriangleSet();
|
---|
| 144 |
|
---|
| 145 | void GetNormalVector(Vector &NormalVector);
|
---|
[57066a] | 146 | void GetCenter(Vector *center);
|
---|
[e138de] | 147 | bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
|
---|
[357fba] | 148 | bool ContainsBoundaryLine(class BoundaryLineSet *line);
|
---|
| 149 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
[7dea7c] | 150 | bool ContainsBoundaryPoint(class TesselPoint *point);
|
---|
[62bb91] | 151 | class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
|
---|
[357fba] | 152 | bool IsPresentTupel(class BoundaryPointSet *Points[3]);
|
---|
[57066a] | 153 | bool IsPresentTupel(class BoundaryTriangleSet *T);
|
---|
[357fba] | 154 |
|
---|
| 155 | class BoundaryPointSet *endpoints[3];
|
---|
| 156 | class BoundaryLineSet *lines[3];
|
---|
| 157 | Vector NormalVector;
|
---|
| 158 | int Nr;
|
---|
| 159 | };
|
---|
| 160 |
|
---|
[776b64] | 161 | ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
|
---|
[357fba] | 162 |
|
---|
[262bae] | 163 |
|
---|
| 164 | // ======================================================== class BoundaryTriangleSet =======================================
|
---|
| 165 |
|
---|
| 166 | /** Set of BoundaryPointSet.
|
---|
| 167 | * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
|
---|
| 168 | * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
|
---|
| 169 | * class (i.e. no allocation, no deletion).
|
---|
| 170 | * \note we assume that the set of endpoints reside (more or less) on a plane.
|
---|
| 171 | */
|
---|
| 172 | class BoundaryPolygonSet {
|
---|
| 173 | public:
|
---|
| 174 | BoundaryPolygonSet();
|
---|
| 175 | ~BoundaryPolygonSet();
|
---|
| 176 |
|
---|
| 177 | Vector * GetNormalVector(const Vector &NormalVector) const;
|
---|
| 178 | void GetCenter(Vector *center) const;
|
---|
| 179 | bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
|
---|
| 180 | bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
|
---|
| 181 | bool ContainsBoundaryPoint(const TesselPoint * const point) const;
|
---|
| 182 | bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
|
---|
| 183 | bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
|
---|
| 184 | bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
|
---|
| 185 | bool ContainsPresentTupel(const PointSet &endpoints) const;
|
---|
[af374d] | 186 | TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
|
---|
[262bae] | 187 | bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
|
---|
| 188 |
|
---|
| 189 | PointSet endpoints;
|
---|
| 190 | int Nr;
|
---|
| 191 | };
|
---|
| 192 |
|
---|
| 193 | ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
|
---|
| 194 |
|
---|
[357fba] | 195 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 196 |
|
---|
| 197 | /** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
|
---|
| 198 | */
|
---|
[4455f4] | 199 | class TesselPoint : virtual public ParticleInfo {
|
---|
[357fba] | 200 | public:
|
---|
| 201 | TesselPoint();
|
---|
[5c7bf8] | 202 | virtual ~TesselPoint();
|
---|
[357fba] | 203 |
|
---|
| 204 | Vector *node; // pointer to position of the dot in space
|
---|
[5c7bf8] | 205 |
|
---|
| 206 | virtual ostream & operator << (ostream &ost);
|
---|
[357fba] | 207 | };
|
---|
| 208 |
|
---|
| 209 | ostream & operator << (ostream &ost, const TesselPoint &a);
|
---|
| 210 |
|
---|
| 211 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 212 |
|
---|
| 213 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
|
---|
| 214 | * This basically encapsulates a list structure.
|
---|
| 215 | */
|
---|
| 216 | class PointCloud {
|
---|
| 217 | public:
|
---|
| 218 | PointCloud();
|
---|
[ab1932] | 219 | virtual ~PointCloud();
|
---|
[357fba] | 220 |
|
---|
[6a7f78c] | 221 | virtual const char * const GetName() const { return "unknown"; };
|
---|
[e138de] | 222 | virtual Vector *GetCenter() const { return NULL; };
|
---|
[776b64] | 223 | virtual TesselPoint *GetPoint() const { return NULL; };
|
---|
| 224 | virtual TesselPoint *GetTerminalPoint() const { return NULL; };
|
---|
| 225 | virtual void GoToNext() const {};
|
---|
| 226 | virtual void GoToPrevious() const {};
|
---|
| 227 | virtual void GoToFirst() const {};
|
---|
| 228 | virtual void GoToLast() const {};
|
---|
[6a7f78c] | 229 | virtual bool IsEmpty() const { return true; };
|
---|
| 230 | virtual bool IsEnd() const { return true; };
|
---|
[357fba] | 231 | };
|
---|
| 232 |
|
---|
| 233 | // ======================================================== class CandidateForTesselation =========================================
|
---|
| 234 |
|
---|
| 235 | class CandidateForTesselation {
|
---|
| 236 | public :
|
---|
[1e168b] | 237 | CandidateForTesselation(BoundaryLineSet* currentBaseLine);
|
---|
[357fba] | 238 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
|
---|
| 239 | ~CandidateForTesselation();
|
---|
| 240 |
|
---|
[f67b6e] | 241 | TesselPointList pointlist;
|
---|
[357fba] | 242 | BoundaryLineSet *BaseLine;
|
---|
| 243 | Vector OptCenter;
|
---|
| 244 | Vector OtherOptCenter;
|
---|
[1e168b] | 245 | double ShortestAngle;
|
---|
| 246 | double OtherShortestAngle;
|
---|
[357fba] | 247 | };
|
---|
| 248 |
|
---|
[1e168b] | 249 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
|
---|
| 250 |
|
---|
[357fba] | 251 | // =========================================================== class TESSELATION ===========================================
|
---|
| 252 |
|
---|
| 253 | /** Contains the envelope to a PointCloud.
|
---|
| 254 | */
|
---|
[5c7bf8] | 255 | class Tesselation : public PointCloud {
|
---|
[357fba] | 256 | public:
|
---|
| 257 |
|
---|
| 258 | Tesselation();
|
---|
[5c7bf8] | 259 | virtual ~Tesselation();
|
---|
[357fba] | 260 |
|
---|
[776b64] | 261 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
---|
[f1ef60a] | 262 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
---|
[776b64] | 263 | void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
| 264 | void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
[16d866] | 265 | void AddTesselationTriangle();
|
---|
[776b64] | 266 | void AddTesselationTriangle(const int nr);
|
---|
[f67b6e] | 267 | void AddCandidateTriangle(CandidateForTesselation CandidateLine);
|
---|
[16d866] | 268 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 269 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
| 270 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
| 271 |
|
---|
[357fba] | 272 |
|
---|
| 273 | // concave envelope
|
---|
[e138de] | 274 | void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
|
---|
[776b64] | 275 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
---|
[f67b6e] | 276 | void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
|
---|
[1e168b] | 277 | bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
|
---|
[f1ef60a] | 278 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
---|
[e138de] | 279 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
---|
[357fba] | 280 |
|
---|
| 281 | // convex envelope
|
---|
[e138de] | 282 | void TesselateOnBoundary(const PointCloud * const cloud);
|
---|
| 283 | void GuessStartingTriangle();
|
---|
| 284 | bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
|
---|
| 285 | double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
|
---|
| 286 | class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
|
---|
| 287 | double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
|
---|
| 288 | class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
|
---|
[57066a] | 289 | map<int, int> * FindAllDegeneratedTriangles();
|
---|
| 290 | map<int, int> * FindAllDegeneratedLines();
|
---|
[7c14ec] | 291 | void RemoveDegeneratedTriangles();
|
---|
[e138de] | 292 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
|
---|
[262bae] | 293 | int CorrectAllDegeneratedPolygons();
|
---|
[16d866] | 294 |
|
---|
[e138de] | 295 | set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
|
---|
| 296 | set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
|
---|
| 297 | list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
| 298 | list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
[27bd2f] | 299 | list<TesselPoint*> * GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
|
---|
[776b64] | 300 | class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
---|
| 301 | list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
|
---|
[e138de] | 302 | list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
|
---|
| 303 | class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
|
---|
| 304 | bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
|
---|
| 305 | bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
|
---|
[776b64] | 306 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
---|
[ab1932] | 307 |
|
---|
[0077b5] | 308 | // print for debugging
|
---|
[776b64] | 309 | void PrintAllBoundaryPoints(ofstream *out) const;
|
---|
| 310 | void PrintAllBoundaryLines(ofstream *out) const;
|
---|
| 311 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
---|
[0077b5] | 312 |
|
---|
[57066a] | 313 | // store envelope in file
|
---|
[e138de] | 314 | void Output(const char *filename, const PointCloud * const cloud);
|
---|
[0077b5] | 315 |
|
---|
[357fba] | 316 | PointMap PointsOnBoundary;
|
---|
| 317 | LineMap LinesOnBoundary;
|
---|
[1e168b] | 318 | CandidateMap OpenLines;
|
---|
[357fba] | 319 | TriangleMap TrianglesOnBoundary;
|
---|
| 320 | int PointsOnBoundaryCount;
|
---|
| 321 | int LinesOnBoundaryCount;
|
---|
| 322 | int TrianglesOnBoundaryCount;
|
---|
| 323 |
|
---|
[5c7bf8] | 324 | // PointCloud implementation for PointsOnBoundary
|
---|
[776b64] | 325 | virtual Vector *GetCenter(ofstream *out) const;
|
---|
| 326 | virtual TesselPoint *GetPoint() const;
|
---|
| 327 | virtual TesselPoint *GetTerminalPoint() const;
|
---|
| 328 | virtual void GoToNext() const;
|
---|
| 329 | virtual void GoToPrevious() const;
|
---|
| 330 | virtual void GoToFirst() const;
|
---|
| 331 | virtual void GoToLast() const;
|
---|
| 332 | virtual bool IsEmpty() const;
|
---|
| 333 | virtual bool IsEnd() const;
|
---|
[5c7bf8] | 334 |
|
---|
[357fba] | 335 | class BoundaryPointSet *BPS[2];
|
---|
| 336 | class BoundaryLineSet *BLS[3];
|
---|
| 337 | class BoundaryTriangleSet *BTS;
|
---|
[57066a] | 338 | class BoundaryTriangleSet *LastTriangle;
|
---|
| 339 | int TriangleFilesWritten;
|
---|
[5c7bf8] | 340 |
|
---|
[08ef35] | 341 | private:
|
---|
[f1ef60a] | 342 | mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
[08ef35] | 343 |
|
---|
[776b64] | 344 | mutable PointMap::const_iterator InternalPointer;
|
---|
[f1ef60a] | 345 |
|
---|
[f67b6e] | 346 | //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
|
---|
[357fba] | 347 | };
|
---|
| 348 |
|
---|
| 349 |
|
---|
| 350 | #endif /* TESSELATION_HPP_ */
|
---|