source: src/Tesselation/tesselation.hpp

Candidate_v1.6.1
Last change on this file was e2396e, checked in by Frederik Heber <heber@…>, 10 years ago

Added check whether all points remain inside surface and whether it is convex to ConvexEnvelopeAction.

  • Property mode set to 100644
File size: 8.8 KB
Line 
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
14using 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/atom_particleinfo.hpp"
29#include "BoundaryMaps.hpp"
30#include "BoundaryPointSet.hpp"
31#include "LinearAlgebra/Vector.hpp"
32#include "Atom/TesselPoint.hpp"
33
34
35/****************************************** forward declarations *****************************/
36
37class BoundaryPointSet;
38class BoundaryLineSet;
39class BoundaryTriangleSet;
40class CandidateForTesselation;
41class IPointCloud;
42class LinkedCell_deprecated;
43class Plane;
44class Tesselation;
45
46/********************************************** definitions *********************************/
47
48enum { DoTecplotOutput=1 };
49enum { DoRaster3DOutput=1 };
50enum { DoVRMLOutput=0 };
51
52extern "C" const char *TecplotSuffix;
53extern "C" const char *Raster3DSuffix;
54extern "C" const char *VRMLSUffix;
55
56extern "C" const double ParallelEpsilon;
57
58// ======================================================= some template functions =========================================
59
60/********************************************** declarations *******************************/
61
62// =========================================================== class TESSELATION ===========================================
63
64/** Is iterable container of TesselPoints.
65 */
66class Tesselation {
67 public:
68
69 Tesselation();
70 virtual ~Tesselation();
71
72 void operator()(IPointCloud & cloud, const double SPHERERADIUS);
73 double getVolumeOfConvexEnvelope(const bool IsAngstroem) const;
74 double getAreaOfEnvelope(const bool IsAngstroem) const;
75
76 void AddTesselationPoint(TesselPoint* Candidate, const int n);
77 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
78 bool AddTesselationLine(const Vector * OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
79 void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
80 void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
81 void AddTesselationTriangle();
82 void AddTesselationTriangle(const int nr);
83 void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
84 void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC);
85 void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC);
86 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
87 void RemoveTesselationLine(class BoundaryLineSet *line);
88 void RemoveTesselationPoint(class BoundaryPointSet *point);
89 bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC) const;
90 bool isConvex() const;
91
92 // concave envelope
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);
98 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
99 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
100
101 // convex envelope
102 void TesselateOnBoundary(IPointCloud & cloud);
103 void GuessStartingTriangle();
104 bool InsertStraddlingPoints(IPointCloud & cloud, const LinkedCell_deprecated *LC);
105 double RemovePointSurroundedByPolygon(
106 TesselPointList *connectedPath,
107 BoundaryPointSet *point);
108 bool CheckAllConcaveInPolygon(
109 const TesselPointList *connectedPath,
110 const BoundaryPointSet *point
111 );
112 double RemoveFullConcavePointFromTesselatedSurface(class BoundaryPointSet *point);
113 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
114 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
115 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
116 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
117 IndexToIndex * FindAllDegeneratedTriangles();
118 IndexToIndex * FindAllDegeneratedLines();
119 void RemoveDegeneratedTriangles();
120 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell_deprecated *LC);
121 int CorrectAllDegeneratedPolygons();
122
123 TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
124 TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
125 ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
126 ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
127 TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
128 TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const;
129 class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
130 TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
131 TriangleList * FindClosestTrianglesToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
132 BoundaryTriangleSet * FindClosestTriangleToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
133 bool IsInnerPoint(const Vector &Point, const LinkedCell_deprecated* const LC) const;
134 Vector getNormal(const Vector &Point, const LinkedCell_deprecated* const LC) const;
135 double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
136 double GetDistanceToSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const;
137 BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const;
138 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
139 DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
140 BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector &x, const LinkedCell_deprecated* LC) const;
141
142 bool IsPointBelowSurroundingPolygon(const BoundaryPointSet *_point) const;
143
144 // print for debugging
145 void PrintAllBoundaryPoints(ofstream *out) const;
146 void PrintAllBoundaryLines(ofstream *out) const;
147 void PrintAllBoundaryTriangles(ofstream *out) const;
148
149 // store envelope in file
150 void Output(const char *filename, IPointCloud & cloud);
151
152 PointMap PointsOnBoundary;
153 LineMap LinesOnBoundary;
154 CandidateMap OpenLines;
155 TriangleMap TrianglesOnBoundary;
156 int PointsOnBoundaryCount;
157 int LinesOnBoundaryCount;
158 int TrianglesOnBoundaryCount;
159
160 typedef PointMap::iterator iterator;
161 typedef PointMap::const_iterator const_iterator;
162 iterator begin() { return PointsOnBoundary.begin(); }
163 const_iterator begin() const { return PointsOnBoundary.begin(); }
164 iterator end() { return PointsOnBoundary.end(); }
165 const_iterator end() const { return PointsOnBoundary.end(); }
166
167 class BoundaryPointSet *BPS[2];
168 class BoundaryLineSet *BLS[3];
169 class BoundaryTriangleSet *BTS;
170 class BoundaryTriangleSet *LastTriangle;
171 int TriangleFilesWritten;
172
173 private:
174 static const double HULLEPSILON; //!< TODO: Get rid of HULLEPSILON, points to numerical instabilities
175
176 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
177
178 mutable PointMap::const_iterator InternalPointer;
179
180 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell_deprecated * const LC) const;
181 void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
182};
183
184#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.