| 1 | /*
|
|---|
| 2 | * tesselation.hpp
|
|---|
| 3 | *
|
|---|
| 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.
|
|---|
| 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 |
|
|---|
| 16 | /*********************************************** includes ***********************************/
|
|---|
| 17 |
|
|---|
| 18 | // include config.h
|
|---|
| 19 | #ifdef HAVE_CONFIG_H
|
|---|
| 20 | #include <config.h>
|
|---|
| 21 | #endif
|
|---|
| 22 |
|
|---|
| 23 | #include <map>
|
|---|
| 24 | #include <list>
|
|---|
| 25 | #include <set>
|
|---|
| 26 | #include <stack>
|
|---|
| 27 |
|
|---|
| 28 | #include "atom_particleinfo.hpp"
|
|---|
| 29 | #include "BoundaryMaps.hpp"
|
|---|
| 30 | #include "BoundaryPointSet.hpp"
|
|---|
| 31 | #include "Helpers/helpers.hpp"
|
|---|
| 32 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 33 | #include "TesselPoint.hpp"
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | /****************************************** forward declarations *****************************/
|
|---|
| 37 |
|
|---|
| 38 | class BoundaryPointSet;
|
|---|
| 39 | class BoundaryLineSet;
|
|---|
| 40 | class BoundaryTriangleSet;
|
|---|
| 41 | class CandidateForTesselation;
|
|---|
| 42 | class IPointCloud;
|
|---|
| 43 | class LinkedCell;
|
|---|
| 44 | class Plane;
|
|---|
| 45 | class Tesselation;
|
|---|
| 46 |
|
|---|
| 47 | /********************************************** definitions *********************************/
|
|---|
| 48 |
|
|---|
| 49 | enum { DoTecplotOutput=1 };
|
|---|
| 50 | enum { DoRaster3DOutput=1 };
|
|---|
| 51 | enum { DoVRMLOutput=0 };
|
|---|
| 52 |
|
|---|
| 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;
|
|---|
| 58 |
|
|---|
| 59 | // ======================================================= some template functions =========================================
|
|---|
| 60 |
|
|---|
| 61 | /********************************************** declarations *******************************/
|
|---|
| 62 |
|
|---|
| 63 | // =========================================================== class TESSELATION ===========================================
|
|---|
| 64 |
|
|---|
| 65 | /** Is iterable container of TesselPoints.
|
|---|
| 66 | */
|
|---|
| 67 | class Tesselation {
|
|---|
| 68 | public:
|
|---|
| 69 |
|
|---|
| 70 | Tesselation();
|
|---|
| 71 | virtual ~Tesselation();
|
|---|
| 72 |
|
|---|
| 73 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
|---|
| 74 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
|---|
| 75 | void AddTesselationLine(const Vector * OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
|---|
| 76 | void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
|---|
| 77 | void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
|
|---|
| 78 | void AddTesselationTriangle();
|
|---|
| 79 | void AddTesselationTriangle(const int nr);
|
|---|
| 80 | void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
|
|---|
| 81 | void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
|
|---|
| 82 | void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
|
|---|
| 83 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
|---|
| 84 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
|---|
| 85 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
|---|
| 86 | bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const;
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | // concave envelope
|
|---|
| 90 | bool FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
|
|---|
| 91 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
|---|
| 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);
|
|---|
| 94 | bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList);
|
|---|
| 95 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
|---|
| 96 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
|---|
| 97 |
|
|---|
| 98 | // convex envelope
|
|---|
| 99 | void TesselateOnBoundary(IPointCloud & cloud);
|
|---|
| 100 | void GuessStartingTriangle();
|
|---|
| 101 | bool InsertStraddlingPoints(IPointCloud & 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);
|
|---|
| 106 | IndexToIndex * FindAllDegeneratedTriangles();
|
|---|
| 107 | IndexToIndex * FindAllDegeneratedLines();
|
|---|
| 108 | void RemoveDegeneratedTriangles();
|
|---|
| 109 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
|
|---|
| 110 | int CorrectAllDegeneratedPolygons();
|
|---|
| 111 |
|
|---|
| 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;
|
|---|
| 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;
|
|---|
| 118 | class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
|---|
| 119 | TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
|
|---|
| 120 | TriangleList * FindClosestTrianglesToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 121 | BoundaryTriangleSet * FindClosestTriangleToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 122 | bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
|
|---|
| 123 | double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
|
|---|
| 124 | double GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const;
|
|---|
| 125 | BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const;
|
|---|
| 126 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
|---|
| 127 | DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 128 | BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 129 |
|
|---|
| 130 | // print for debugging
|
|---|
| 131 | void PrintAllBoundaryPoints(ofstream *out) const;
|
|---|
| 132 | void PrintAllBoundaryLines(ofstream *out) const;
|
|---|
| 133 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
|---|
| 134 |
|
|---|
| 135 | // store envelope in file
|
|---|
| 136 | void Output(const char *filename, IPointCloud & cloud);
|
|---|
| 137 |
|
|---|
| 138 | PointMap PointsOnBoundary;
|
|---|
| 139 | LineMap LinesOnBoundary;
|
|---|
| 140 | CandidateMap OpenLines;
|
|---|
| 141 | TriangleMap TrianglesOnBoundary;
|
|---|
| 142 | int PointsOnBoundaryCount;
|
|---|
| 143 | int LinesOnBoundaryCount;
|
|---|
| 144 | int TrianglesOnBoundaryCount;
|
|---|
| 145 |
|
|---|
| 146 | typedef PointMap::iterator iterator;
|
|---|
| 147 | typedef PointMap::const_iterator const_iterator;
|
|---|
| 148 | iterator begin() { return PointsOnBoundary.begin(); }
|
|---|
| 149 | const_iterator begin() const { return PointsOnBoundary.begin(); }
|
|---|
| 150 | iterator end() { return PointsOnBoundary.end(); }
|
|---|
| 151 | const_iterator end() const { return PointsOnBoundary.end(); }
|
|---|
| 152 |
|
|---|
| 153 | class BoundaryPointSet *BPS[2];
|
|---|
| 154 | class BoundaryLineSet *BLS[3];
|
|---|
| 155 | class BoundaryTriangleSet *BTS;
|
|---|
| 156 | class BoundaryTriangleSet *LastTriangle;
|
|---|
| 157 | int TriangleFilesWritten;
|
|---|
| 158 |
|
|---|
| 159 | private:
|
|---|
| 160 | static const double HULLEPSILON; //!< TODO: Get rid of HULLEPSILON, points to numerical instabilities
|
|---|
| 161 |
|
|---|
| 162 | mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
|---|
| 163 |
|
|---|
| 164 | mutable PointMap::const_iterator InternalPointer;
|
|---|
| 165 |
|
|---|
| 166 | //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
|
|---|
| 167 | void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
|
|---|
| 168 | };
|
|---|
| 169 |
|
|---|
| 170 | #endif /* TESSELATION_HPP_ */
|
|---|