| 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 "BoundaryMaps.hpp"
|
|---|
| 29 | #include "PointCloud.hpp"
|
|---|
| 30 | #include "TesselPoint.hpp"
|
|---|
| 31 | #include "atom_particleinfo.hpp"
|
|---|
| 32 | #include "Helpers/helpers.hpp"
|
|---|
| 33 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | /****************************************** forward declarations *****************************/
|
|---|
| 37 |
|
|---|
| 38 | class BoundaryPointSet;
|
|---|
| 39 | class BoundaryLineSet;
|
|---|
| 40 | class BoundaryTriangleSet;
|
|---|
| 41 | class CandidateForTesselation;
|
|---|
| 42 | class LinkedCell;
|
|---|
| 43 | class Tesselation;
|
|---|
| 44 | class Plane;
|
|---|
| 45 |
|
|---|
| 46 | /********************************************** definitions *********************************/
|
|---|
| 47 |
|
|---|
| 48 | enum { DoTecplotOutput=1 };
|
|---|
| 49 | enum { DoRaster3DOutput=1 };
|
|---|
| 50 | enum { DoVRMLOutput=0 };
|
|---|
| 51 |
|
|---|
| 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;
|
|---|
| 57 |
|
|---|
| 58 | // ======================================================= some template functions =========================================
|
|---|
| 59 |
|
|---|
| 60 | /********************************************** declarations *******************************/
|
|---|
| 61 |
|
|---|
| 62 | // =========================================================== class TESSELATION ===========================================
|
|---|
| 63 |
|
|---|
| 64 | /** Contains the envelope to a PointCloud.
|
|---|
| 65 | */
|
|---|
| 66 | class Tesselation : public PointCloud {
|
|---|
| 67 | public:
|
|---|
| 68 |
|
|---|
| 69 | Tesselation();
|
|---|
| 70 | virtual ~Tesselation();
|
|---|
| 71 |
|
|---|
| 72 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
|---|
| 73 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
|---|
| 74 | void AddTesselationLine(const Vector * OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
|---|
| 75 | void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
|---|
| 76 | void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
|
|---|
| 77 | void AddTesselationTriangle();
|
|---|
| 78 | void AddTesselationTriangle(const int nr);
|
|---|
| 79 | void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
|
|---|
| 80 | void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
|
|---|
| 81 | void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
|
|---|
| 82 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
|---|
| 83 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
|---|
| 84 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
|---|
| 85 | bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const;
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | // concave envelope
|
|---|
| 89 | bool FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
|
|---|
| 90 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
|---|
| 91 | 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;
|
|---|
| 92 | bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
|
|---|
| 93 | bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList);
|
|---|
| 94 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
|---|
| 95 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
|---|
| 96 |
|
|---|
| 97 | // convex envelope
|
|---|
| 98 | void TesselateOnBoundary(const PointCloud * const cloud);
|
|---|
| 99 | void GuessStartingTriangle();
|
|---|
| 100 | bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
|
|---|
| 101 | double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
|
|---|
| 102 | class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
|
|---|
| 103 | double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
|
|---|
| 104 | class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
|
|---|
| 105 | IndexToIndex * FindAllDegeneratedTriangles();
|
|---|
| 106 | IndexToIndex * FindAllDegeneratedLines();
|
|---|
| 107 | void RemoveDegeneratedTriangles();
|
|---|
| 108 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
|
|---|
| 109 | int CorrectAllDegeneratedPolygons();
|
|---|
| 110 |
|
|---|
| 111 | TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
|
|---|
| 112 | TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
|
|---|
| 113 | ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
|---|
| 114 | ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
|---|
| 115 | TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
|
|---|
| 116 | TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
|
|---|
| 117 | class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
|---|
| 118 | TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
|
|---|
| 119 | TriangleList * FindClosestTrianglesToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 120 | BoundaryTriangleSet * FindClosestTriangleToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 121 | bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
|
|---|
| 122 | double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
|
|---|
| 123 | double GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const;
|
|---|
| 124 | BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const;
|
|---|
| 125 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
|---|
| 126 | DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 127 | BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector &x, const LinkedCell* LC) const;
|
|---|
| 128 |
|
|---|
| 129 | // print for debugging
|
|---|
| 130 | void PrintAllBoundaryPoints(ofstream *out) const;
|
|---|
| 131 | void PrintAllBoundaryLines(ofstream *out) const;
|
|---|
| 132 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
|---|
| 133 |
|
|---|
| 134 | // store envelope in file
|
|---|
| 135 | void Output(const char *filename, const PointCloud * const cloud);
|
|---|
| 136 |
|
|---|
| 137 | PointMap PointsOnBoundary;
|
|---|
| 138 | LineMap LinesOnBoundary;
|
|---|
| 139 | CandidateMap OpenLines;
|
|---|
| 140 | TriangleMap TrianglesOnBoundary;
|
|---|
| 141 | int PointsOnBoundaryCount;
|
|---|
| 142 | int LinesOnBoundaryCount;
|
|---|
| 143 | int TrianglesOnBoundaryCount;
|
|---|
| 144 |
|
|---|
| 145 | // PointCloud implementation for PointsOnBoundary
|
|---|
| 146 | virtual Vector *GetCenter(ofstream *out) const;
|
|---|
| 147 | virtual TesselPoint *GetPoint() const;
|
|---|
| 148 | virtual void GoToNext() const;
|
|---|
| 149 | virtual void GoToFirst() const;
|
|---|
| 150 | virtual bool IsEmpty() const;
|
|---|
| 151 | virtual bool IsEnd() const;
|
|---|
| 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 |
|
|---|
| 171 | #endif /* TESSELATION_HPP_ */
|
|---|