| [357fba] | 1 | /*
 | 
|---|
 | 2 |  * tesselation.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
| [d74077] | 4 |  *  The tesselation class is meant to contain the envelope (concave, convex or neither) of a set of Vectors.
 | 
|---|
 | 5 |  *  As we actually mean this stuff for atoms, we have to encapsulate it all a bit.
 | 
|---|
| [357fba] | 6 |  *
 | 
|---|
 | 7 |  *  Created on: Aug 3, 2009
 | 
|---|
 | 8 |  *      Author: heber
 | 
|---|
 | 9 |  */
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | #ifndef TESSELATION_HPP_
 | 
|---|
 | 12 | #define TESSELATION_HPP_
 | 
|---|
 | 13 | 
 | 
|---|
 | 14 | using namespace std;
 | 
|---|
 | 15 | 
 | 
|---|
| [f66195] | 16 | /*********************************************** includes ***********************************/
 | 
|---|
 | 17 | 
 | 
|---|
| [357fba] | 18 | // include config.h
 | 
|---|
 | 19 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 20 | #include <config.h>
 | 
|---|
 | 21 | #endif
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 | #include <map>
 | 
|---|
 | 24 | #include <list>
 | 
|---|
| [7c14ec] | 25 | #include <set>
 | 
|---|
| [856098] | 26 | #include <stack>
 | 
|---|
| [357fba] | 27 | 
 | 
|---|
| [d74077] | 28 | #include "BoundaryMaps.hpp"
 | 
|---|
| [af2c424] | 29 | #include "BoundaryPointSet.hpp"
 | 
|---|
| [d74077] | 30 | #include "PointCloud.hpp"
 | 
|---|
 | 31 | #include "TesselPoint.hpp"
 | 
|---|
| [6b919f8] | 32 | #include "atom_particleinfo.hpp"
 | 
|---|
| [952f38] | 33 | #include "Helpers/helpers.hpp"
 | 
|---|
| [57f243] | 34 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [357fba] | 35 | 
 | 
|---|
| [d74077] | 36 | 
 | 
|---|
| [f66195] | 37 | /****************************************** forward declarations *****************************/
 | 
|---|
 | 38 | 
 | 
|---|
| [357fba] | 39 | class BoundaryPointSet;
 | 
|---|
 | 40 | class BoundaryLineSet;
 | 
|---|
 | 41 | class BoundaryTriangleSet;
 | 
|---|
| [d74077] | 42 | class CandidateForTesselation;
 | 
|---|
| [f66195] | 43 | class LinkedCell;
 | 
|---|
| [357fba] | 44 | class Tesselation;
 | 
|---|
| [d4c9ae] | 45 | class Plane;
 | 
|---|
| [357fba] | 46 | 
 | 
|---|
| [f66195] | 47 | /********************************************** definitions *********************************/
 | 
|---|
 | 48 | 
 | 
|---|
| [88b400] | 49 | enum { DoTecplotOutput=1 };
 | 
|---|
 | 50 | enum { DoRaster3DOutput=1 };
 | 
|---|
 | 51 | enum { DoVRMLOutput=0 };
 | 
|---|
| [57066a] | 52 | 
 | 
|---|
| [88b400] | 53 | extern "C" const char *TecplotSuffix;
 | 
|---|
 | 54 | extern "C" const char *Raster3DSuffix;
 | 
|---|
 | 55 | extern "C" const char *VRMLSUffix;
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 | extern "C" const double ParallelEpsilon;
 | 
|---|
| [fad93c] | 58 | 
 | 
|---|
| [357fba] | 59 | // ======================================================= some template functions =========================================
 | 
|---|
 | 60 | 
 | 
|---|
| [f66195] | 61 | /********************************************** declarations *******************************/
 | 
|---|
| [357fba] | 62 | 
 | 
|---|
 | 63 | // =========================================================== class TESSELATION ===========================================
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | /** Contains the envelope to a PointCloud.
 | 
|---|
 | 66 |  */
 | 
|---|
| [5c7bf8] | 67 | class Tesselation : public PointCloud {
 | 
|---|
| [357fba] | 68 |   public:
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 |     Tesselation();
 | 
|---|
| [5c7bf8] | 71 |     virtual ~Tesselation();
 | 
|---|
| [357fba] | 72 | 
 | 
|---|
| [776b64] | 73 |     void AddTesselationPoint(TesselPoint* Candidate, const int n);
 | 
|---|
| [f1ef60a] | 74 |     void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
 | 
|---|
| [d74077] | 75 |     void AddTesselationLine(const Vector * OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
 | 
|---|
| [474961] | 76 |     void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
 | 
|---|
 | 77 |     void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
 | 
|---|
| [16d866] | 78 |     void AddTesselationTriangle();
 | 
|---|
| [776b64] | 79 |     void AddTesselationTriangle(const int nr);
 | 
|---|
| [6613ec] | 80 |     void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
 | 
|---|
| [711ac2] | 81 |     void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
 | 
|---|
| [474961] | 82 |     void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
 | 
|---|
| [16d866] | 83 |     void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
 | 
|---|
 | 84 |     void RemoveTesselationLine(class BoundaryLineSet *line);
 | 
|---|
 | 85 |     void RemoveTesselationPoint(class BoundaryPointSet *point);
 | 
|---|
| [6613ec] | 86 |     bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const;
 | 
|---|
| [16d866] | 87 | 
 | 
|---|
| [357fba] | 88 | 
 | 
|---|
 | 89 |     // concave envelope
 | 
|---|
| [ce70970] | 90 |     bool FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
 | 
|---|
| [776b64] | 91 |     void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
 | 
|---|
| [f07f86d] | 92 |     void FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
 | 
|---|
 | 93 |     bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
 | 
|---|
| [6613ec] | 94 |     bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList);
 | 
|---|
| [f1ef60a] | 95 |     int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
 | 
|---|
| [e138de] | 96 |     class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
 | 
|---|
| [357fba] | 97 | 
 | 
|---|
 | 98 |     // convex envelope
 | 
|---|
| [e138de] | 99 |     void TesselateOnBoundary(const PointCloud * const cloud);
 | 
|---|
 | 100 |     void GuessStartingTriangle();
 | 
|---|
 | 101 |     bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
 | 
|---|
 | 102 |     double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
 | 
|---|
 | 103 |     class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
 | 
|---|
 | 104 |     double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
 | 
|---|
 | 105 |     class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
 | 
|---|
| [244a84] | 106 |     IndexToIndex * FindAllDegeneratedTriangles();
 | 
|---|
 | 107 |     IndexToIndex * FindAllDegeneratedLines();
 | 
|---|
| [7c14ec] | 108 |     void RemoveDegeneratedTriangles();
 | 
|---|
| [e138de] | 109 |     void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
 | 
|---|
| [262bae] | 110 |     int CorrectAllDegeneratedPolygons();
 | 
|---|
| [16d866] | 111 | 
 | 
|---|
| [244a84] | 112 |     TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
 | 
|---|
 | 113 |     TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
 | 
|---|
 | 114 |     ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
 | 
|---|
 | 115 |     ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
 | 
|---|
| [d74077] | 116 |     TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
 | 
|---|
 | 117 |     TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
 | 
|---|
| [244a84] | 118 |     class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
 | 
|---|
 | 119 |     TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
 | 
|---|
| [d74077] | 120 |     TriangleList * FindClosestTrianglesToVector(const Vector &x, const LinkedCell* LC) const;
 | 
|---|
 | 121 |     BoundaryTriangleSet * FindClosestTriangleToVector(const Vector &x, const LinkedCell* LC) const;
 | 
|---|
| [241485] | 122 |     bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
 | 
|---|
| [244a84] | 123 |     double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
 | 
|---|
| [8db598] | 124 |     double GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const;
 | 
|---|
 | 125 |     BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const;
 | 
|---|
| [776b64] | 126 |     bool AddBoundaryPoint(TesselPoint * Walker, const int n);
 | 
|---|
| [d74077] | 127 |     DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector &x, const LinkedCell* LC) const;
 | 
|---|
 | 128 |     BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector &x, const LinkedCell* LC) const;
 | 
|---|
| [ab1932] | 129 | 
 | 
|---|
| [0077b5] | 130 |     // print for debugging
 | 
|---|
| [776b64] | 131 |     void PrintAllBoundaryPoints(ofstream *out) const;
 | 
|---|
 | 132 |     void PrintAllBoundaryLines(ofstream *out) const;
 | 
|---|
 | 133 |     void PrintAllBoundaryTriangles(ofstream *out) const;
 | 
|---|
| [0077b5] | 134 | 
 | 
|---|
| [57066a] | 135 |     // store envelope in file
 | 
|---|
| [e138de] | 136 |     void Output(const char *filename, const PointCloud * const cloud);
 | 
|---|
| [0077b5] | 137 | 
 | 
|---|
| [357fba] | 138 |     PointMap PointsOnBoundary;
 | 
|---|
 | 139 |     LineMap LinesOnBoundary;
 | 
|---|
| [1e168b] | 140 |     CandidateMap OpenLines;
 | 
|---|
| [357fba] | 141 |     TriangleMap TrianglesOnBoundary;
 | 
|---|
 | 142 |     int PointsOnBoundaryCount;
 | 
|---|
 | 143 |     int LinesOnBoundaryCount;
 | 
|---|
 | 144 |     int TrianglesOnBoundaryCount;
 | 
|---|
 | 145 | 
 | 
|---|
| [af2c424] | 146 |     typedef PointMap::iterator iterator;
 | 
|---|
 | 147 |     typedef PointMap::const_iterator const_iterator;
 | 
|---|
 | 148 |     TesselPoint * getValue(const_iterator &rhs) const;
 | 
|---|
 | 149 |     TesselPoint * getValue(iterator &rhs) const;
 | 
|---|
 | 150 |     iterator begin() { return PointsOnBoundary.begin(); }
 | 
|---|
 | 151 |     const_iterator begin() const { return PointsOnBoundary.begin(); }
 | 
|---|
 | 152 |     iterator end() { return PointsOnBoundary.end(); }
 | 
|---|
 | 153 |     const_iterator end() const { return PointsOnBoundary.end(); }
 | 
|---|
| [5c7bf8] | 154 |     // PointCloud implementation for PointsOnBoundary
 | 
|---|
| [776b64] | 155 |     virtual Vector *GetCenter(ofstream *out) const;
 | 
|---|
 | 156 |     virtual TesselPoint *GetPoint() const;
 | 
|---|
 | 157 |     virtual void GoToNext() const;
 | 
|---|
 | 158 |     virtual void GoToFirst() const;
 | 
|---|
 | 159 |     virtual bool IsEmpty() const;
 | 
|---|
 | 160 |     virtual bool IsEnd() const;
 | 
|---|
| [5c7bf8] | 161 | 
 | 
|---|
| [357fba] | 162 |     class BoundaryPointSet *BPS[2];
 | 
|---|
 | 163 |     class BoundaryLineSet *BLS[3];
 | 
|---|
 | 164 |     class BoundaryTriangleSet *BTS;
 | 
|---|
| [57066a] | 165 |     class BoundaryTriangleSet *LastTriangle;
 | 
|---|
 | 166 |     int TriangleFilesWritten;
 | 
|---|
| [5c7bf8] | 167 | 
 | 
|---|
| [08ef35] | 168 |   private:
 | 
|---|
| [88b400] | 169 |     static const double HULLEPSILON; //!< TODO: Get rid of HULLEPSILON, points to numerical instabilities
 | 
|---|
 | 170 | 
 | 
|---|
| [f1ef60a] | 171 |     mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
 | 
|---|
| [08ef35] | 172 | 
 | 
|---|
| [776b64] | 173 |     mutable PointMap::const_iterator InternalPointer;
 | 
|---|
| [f1ef60a] | 174 | 
 | 
|---|
| [f67b6e] | 175 |     //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
 | 
|---|
| [6613ec] | 176 |     void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
 | 
|---|
| [357fba] | 177 | };
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 | 
 | 
|---|
 | 180 | #endif /* TESSELATION_HPP_ */
 | 
|---|