[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 |
|
---|
[6f0841] | 28 | #include "Atom/atom_particleinfo.hpp"
|
---|
[d74077] | 29 | #include "BoundaryMaps.hpp"
|
---|
[af2c424] | 30 | #include "BoundaryPointSet.hpp"
|
---|
[57f243] | 31 | #include "LinearAlgebra/Vector.hpp"
|
---|
[6f0841] | 32 | #include "Atom/TesselPoint.hpp"
|
---|
[357fba] | 33 |
|
---|
[d74077] | 34 |
|
---|
[f66195] | 35 | /****************************************** forward declarations *****************************/
|
---|
| 36 |
|
---|
[357fba] | 37 | class BoundaryPointSet;
|
---|
| 38 | class BoundaryLineSet;
|
---|
| 39 | class BoundaryTriangleSet;
|
---|
[d74077] | 40 | class CandidateForTesselation;
|
---|
[34c43a] | 41 | class IPointCloud;
|
---|
[6bd7e0] | 42 | class LinkedCell_deprecated;
|
---|
[d4c9ae] | 43 | class Plane;
|
---|
[34c43a] | 44 | class Tesselation;
|
---|
[357fba] | 45 |
|
---|
[f66195] | 46 | /********************************************** definitions *********************************/
|
---|
| 47 |
|
---|
[88b400] | 48 | enum { DoTecplotOutput=1 };
|
---|
| 49 | enum { DoRaster3DOutput=1 };
|
---|
| 50 | enum { DoVRMLOutput=0 };
|
---|
[57066a] | 51 |
|
---|
[88b400] | 52 | extern "C" const char *TecplotSuffix;
|
---|
| 53 | extern "C" const char *Raster3DSuffix;
|
---|
| 54 | extern "C" const char *VRMLSUffix;
|
---|
| 55 |
|
---|
| 56 | extern "C" const double ParallelEpsilon;
|
---|
[fad93c] | 57 |
|
---|
[357fba] | 58 | // ======================================================= some template functions =========================================
|
---|
| 59 |
|
---|
[f66195] | 60 | /********************************************** declarations *******************************/
|
---|
[357fba] | 61 |
|
---|
| 62 | // =========================================================== class TESSELATION ===========================================
|
---|
| 63 |
|
---|
[34c43a] | 64 | /** Is iterable container of TesselPoints.
|
---|
[357fba] | 65 | */
|
---|
[34c43a] | 66 | class Tesselation {
|
---|
[357fba] | 67 | public:
|
---|
| 68 |
|
---|
| 69 | Tesselation();
|
---|
[5c7bf8] | 70 | virtual ~Tesselation();
|
---|
[357fba] | 71 |
|
---|
[cc21cd] | 72 | void operator()(IPointCloud & cloud, const double SPHERERADIUS);
|
---|
[ee0032] | 73 | double getVolumeOfConvexEnvelope(const bool IsAngstroem) const;
|
---|
[bdf6c8] | 74 | double getAreaOfEnvelope(const bool IsAngstroem) const;
|
---|
[ee0032] | 75 |
|
---|
[776b64] | 76 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
---|
[f1ef60a] | 77 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
---|
[d74077] | 78 | void AddTesselationLine(const Vector * OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
[474961] | 79 | void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
| 80 | void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
|
---|
[16d866] | 81 | void AddTesselationTriangle();
|
---|
[776b64] | 82 | void AddTesselationTriangle(const int nr);
|
---|
[6613ec] | 83 | void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
|
---|
[6bd7e0] | 84 | void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC);
|
---|
| 85 | void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC);
|
---|
[16d866] | 86 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 87 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
| 88 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
[6bd7e0] | 89 | bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC) const;
|
---|
[16d866] | 90 |
|
---|
[357fba] | 91 |
|
---|
| 92 | // concave envelope
|
---|
[6bd7e0] | 93 | bool FindStartingTriangle(const double RADIUS, const LinkedCell_deprecated *LC);
|
---|
| 94 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell_deprecated *LC);
|
---|
| 95 | void FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdNode, const double RADIUS, const LinkedCell_deprecated *LC) const;
|
---|
| 96 | bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell_deprecated *LC);
|
---|
| 97 | bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell_deprecated *&LCList);
|
---|
[f1ef60a] | 98 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
---|
[e138de] | 99 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
---|
[357fba] | 100 |
|
---|
| 101 | // convex envelope
|
---|
[34c43a] | 102 | void TesselateOnBoundary(IPointCloud & cloud);
|
---|
[e138de] | 103 | void GuessStartingTriangle();
|
---|
[6bd7e0] | 104 | bool InsertStraddlingPoints(IPointCloud & cloud, const LinkedCell_deprecated *LC);
|
---|
[e138de] | 105 | double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
|
---|
| 106 | class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
|
---|
| 107 | double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
|
---|
| 108 | class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
|
---|
[244a84] | 109 | IndexToIndex * FindAllDegeneratedTriangles();
|
---|
| 110 | IndexToIndex * FindAllDegeneratedLines();
|
---|
[7c14ec] | 111 | void RemoveDegeneratedTriangles();
|
---|
[6bd7e0] | 112 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell_deprecated *LC);
|
---|
[262bae] | 113 | int CorrectAllDegeneratedPolygons();
|
---|
[16d866] | 114 |
|
---|
[244a84] | 115 | TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
|
---|
| 116 | TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
|
---|
| 117 | ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
| 118 | ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
[d74077] | 119 | TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
|
---|
| 120 | TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
|
---|
[244a84] | 121 | class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
---|
| 122 | TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
|
---|
[6bd7e0] | 123 | TriangleList * FindClosestTrianglesToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
|
---|
| 124 | BoundaryTriangleSet * FindClosestTriangleToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
|
---|
| 125 | bool IsInnerPoint(const Vector &Point, const LinkedCell_deprecated* const LC) const;
|
---|
[244a84] | 126 | double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
|
---|
[6bd7e0] | 127 | double GetDistanceToSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const;
|
---|
| 128 | BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const;
|
---|
[776b64] | 129 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
---|
[6bd7e0] | 130 | DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
|
---|
| 131 | BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
|
---|
[ab1932] | 132 |
|
---|
[0077b5] | 133 | // print for debugging
|
---|
[776b64] | 134 | void PrintAllBoundaryPoints(ofstream *out) const;
|
---|
| 135 | void PrintAllBoundaryLines(ofstream *out) const;
|
---|
| 136 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
---|
[0077b5] | 137 |
|
---|
[57066a] | 138 | // store envelope in file
|
---|
[34c43a] | 139 | void Output(const char *filename, IPointCloud & cloud);
|
---|
[0077b5] | 140 |
|
---|
[357fba] | 141 | PointMap PointsOnBoundary;
|
---|
| 142 | LineMap LinesOnBoundary;
|
---|
[1e168b] | 143 | CandidateMap OpenLines;
|
---|
[357fba] | 144 | TriangleMap TrianglesOnBoundary;
|
---|
| 145 | int PointsOnBoundaryCount;
|
---|
| 146 | int LinesOnBoundaryCount;
|
---|
| 147 | int TrianglesOnBoundaryCount;
|
---|
| 148 |
|
---|
[af2c424] | 149 | typedef PointMap::iterator iterator;
|
---|
| 150 | typedef PointMap::const_iterator const_iterator;
|
---|
| 151 | iterator begin() { return PointsOnBoundary.begin(); }
|
---|
| 152 | const_iterator begin() const { return PointsOnBoundary.begin(); }
|
---|
| 153 | iterator end() { return PointsOnBoundary.end(); }
|
---|
| 154 | const_iterator end() const { return PointsOnBoundary.end(); }
|
---|
[5c7bf8] | 155 |
|
---|
[357fba] | 156 | class BoundaryPointSet *BPS[2];
|
---|
| 157 | class BoundaryLineSet *BLS[3];
|
---|
| 158 | class BoundaryTriangleSet *BTS;
|
---|
[57066a] | 159 | class BoundaryTriangleSet *LastTriangle;
|
---|
| 160 | int TriangleFilesWritten;
|
---|
[5c7bf8] | 161 |
|
---|
[08ef35] | 162 | private:
|
---|
[88b400] | 163 | static const double HULLEPSILON; //!< TODO: Get rid of HULLEPSILON, points to numerical instabilities
|
---|
| 164 |
|
---|
[f1ef60a] | 165 | mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
[08ef35] | 166 |
|
---|
[776b64] | 167 | mutable PointMap::const_iterator InternalPointer;
|
---|
[f1ef60a] | 168 |
|
---|
[6bd7e0] | 169 | //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell_deprecated * const LC) const;
|
---|
[6613ec] | 170 | void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
|
---|
[357fba] | 171 | };
|
---|
| 172 |
|
---|
| 173 | #endif /* TESSELATION_HPP_ */
|
---|