[357fba] | 1 | /*
|
---|
| 2 | * tesselation.hpp
|
---|
| 3 | *
|
---|
| 4 | * The tesselation class is meant to contain the envelope (concave, convex or neither) of a set of Vectors. As we actually mean this stuff for atoms, we have to encapsulate it all a bit.
|
---|
| 5 | *
|
---|
| 6 | * Created on: Aug 3, 2009
|
---|
| 7 | * Author: heber
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #ifndef TESSELATION_HPP_
|
---|
| 11 | #define TESSELATION_HPP_
|
---|
| 12 |
|
---|
| 13 | using namespace std;
|
---|
| 14 |
|
---|
[f66195] | 15 | /*********************************************** includes ***********************************/
|
---|
| 16 |
|
---|
[357fba] | 17 | // include config.h
|
---|
| 18 | #ifdef HAVE_CONFIG_H
|
---|
| 19 | #include <config.h>
|
---|
| 20 | #endif
|
---|
| 21 |
|
---|
| 22 | #include <map>
|
---|
| 23 | #include <list>
|
---|
[7c14ec] | 24 | #include <set>
|
---|
[357fba] | 25 |
|
---|
[6b919f8] | 26 | #include "atom_particleinfo.hpp"
|
---|
[4455f4] | 27 | #include "helpers.hpp"
|
---|
[6b919f8] | 28 | #include "vector.hpp"
|
---|
[357fba] | 29 |
|
---|
[f66195] | 30 | /****************************************** forward declarations *****************************/
|
---|
| 31 |
|
---|
[357fba] | 32 | class BoundaryPointSet;
|
---|
| 33 | class BoundaryLineSet;
|
---|
| 34 | class BoundaryTriangleSet;
|
---|
[f66195] | 35 | class LinkedCell;
|
---|
[357fba] | 36 | class TesselPoint;
|
---|
| 37 | class PointCloud;
|
---|
| 38 | class Tesselation;
|
---|
| 39 |
|
---|
[f66195] | 40 | /********************************************** definitions *********************************/
|
---|
| 41 |
|
---|
[57066a] | 42 | #define DoTecplotOutput 1
|
---|
| 43 | #define DoRaster3DOutput 1
|
---|
| 44 | #define DoVRMLOutput 1
|
---|
| 45 | #define TecplotSuffix ".dat"
|
---|
| 46 | #define Raster3DSuffix ".r3d"
|
---|
| 47 | #define VRMLSUffix ".wrl"
|
---|
| 48 |
|
---|
[357fba] | 49 | // ======================================================= some template functions =========================================
|
---|
| 50 |
|
---|
| 51 | #define PointMap map < int, class BoundaryPointSet * >
|
---|
| 52 | #define PointPair pair < int, class BoundaryPointSet * >
|
---|
| 53 | #define PointTestPair pair < PointMap::iterator, bool >
|
---|
| 54 | #define CandidateList list <class CandidateForTesselation *>
|
---|
[1e168b] | 55 | #define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
|
---|
[357fba] | 56 |
|
---|
| 57 | #define LineMap multimap < int, class BoundaryLineSet * >
|
---|
| 58 | #define LinePair pair < int, class BoundaryLineSet * >
|
---|
| 59 | #define LineTestPair pair < LineMap::iterator, bool >
|
---|
| 60 |
|
---|
| 61 | #define TriangleMap map < int, class BoundaryTriangleSet * >
|
---|
| 62 | #define TrianglePair pair < int, class BoundaryTriangleSet * >
|
---|
| 63 | #define TriangleTestPair pair < TrianglePair::iterator, bool >
|
---|
| 64 |
|
---|
| 65 | #define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
| 66 | #define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
|
---|
| 67 |
|
---|
[f67b6e] | 68 | #define TesselPointList list <TesselPoint *>
|
---|
| 69 |
|
---|
[f66195] | 70 | /********************************************** declarations *******************************/
|
---|
[357fba] | 71 |
|
---|
| 72 | template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
|
---|
| 73 | {
|
---|
| 74 | if (endpoint1->Nr < endpoint2->Nr) {
|
---|
| 75 | endpoints[0] = endpoint1;
|
---|
| 76 | endpoints[1] = endpoint2;
|
---|
| 77 | } else {
|
---|
| 78 | endpoints[0] = endpoint2;
|
---|
| 79 | endpoints[1] = endpoint1;
|
---|
| 80 | }
|
---|
| 81 | };
|
---|
| 82 |
|
---|
| 83 | // ======================================================== class BoundaryPointSet =========================================
|
---|
| 84 |
|
---|
| 85 | class BoundaryPointSet {
|
---|
| 86 | public:
|
---|
| 87 | BoundaryPointSet();
|
---|
[776b64] | 88 | BoundaryPointSet(TesselPoint * Walker);
|
---|
[357fba] | 89 | ~BoundaryPointSet();
|
---|
| 90 |
|
---|
| 91 | void AddLine(class BoundaryLineSet *line);
|
---|
| 92 |
|
---|
| 93 | LineMap lines;
|
---|
| 94 | int LinesCount;
|
---|
| 95 | TesselPoint *node;
|
---|
[16d866] | 96 | double value;
|
---|
[357fba] | 97 | int Nr;
|
---|
| 98 | };
|
---|
| 99 |
|
---|
[776b64] | 100 | ostream & operator << (ostream &ost, const BoundaryPointSet &a);
|
---|
[357fba] | 101 |
|
---|
| 102 | // ======================================================== class BoundaryLineSet ==========================================
|
---|
| 103 |
|
---|
| 104 | class BoundaryLineSet {
|
---|
| 105 | public:
|
---|
| 106 | BoundaryLineSet();
|
---|
[776b64] | 107 | BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
|
---|
[357fba] | 108 | ~BoundaryLineSet();
|
---|
| 109 |
|
---|
| 110 | void AddTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 111 | bool IsConnectedTo(class BoundaryLineSet *line);
|
---|
| 112 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
[e138de] | 113 | bool CheckConvexityCriterion();
|
---|
[62bb91] | 114 | class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
|
---|
[357fba] | 115 |
|
---|
| 116 | class BoundaryPointSet *endpoints[2];
|
---|
| 117 | TriangleMap triangles;
|
---|
| 118 | int Nr;
|
---|
[1e168b] | 119 | bool skipped;
|
---|
[357fba] | 120 | };
|
---|
| 121 |
|
---|
[776b64] | 122 | ostream & operator << (ostream &ost, const BoundaryLineSet &a);
|
---|
[357fba] | 123 |
|
---|
| 124 | // ======================================================== class BoundaryTriangleSet =======================================
|
---|
| 125 |
|
---|
| 126 | class BoundaryTriangleSet {
|
---|
| 127 | public:
|
---|
| 128 | BoundaryTriangleSet();
|
---|
| 129 | BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
|
---|
| 130 | ~BoundaryTriangleSet();
|
---|
| 131 |
|
---|
| 132 | void GetNormalVector(Vector &NormalVector);
|
---|
[57066a] | 133 | void GetCenter(Vector *center);
|
---|
[e138de] | 134 | bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
|
---|
[357fba] | 135 | bool ContainsBoundaryLine(class BoundaryLineSet *line);
|
---|
| 136 | bool ContainsBoundaryPoint(class BoundaryPointSet *point);
|
---|
[7dea7c] | 137 | bool ContainsBoundaryPoint(class TesselPoint *point);
|
---|
[62bb91] | 138 | class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
|
---|
[357fba] | 139 | bool IsPresentTupel(class BoundaryPointSet *Points[3]);
|
---|
[57066a] | 140 | bool IsPresentTupel(class BoundaryTriangleSet *T);
|
---|
[357fba] | 141 |
|
---|
| 142 | class BoundaryPointSet *endpoints[3];
|
---|
| 143 | class BoundaryLineSet *lines[3];
|
---|
| 144 | Vector NormalVector;
|
---|
| 145 | int Nr;
|
---|
| 146 | };
|
---|
| 147 |
|
---|
[776b64] | 148 | ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
|
---|
[357fba] | 149 |
|
---|
| 150 | // =========================================================== class TESSELPOINT ===========================================
|
---|
| 151 |
|
---|
| 152 | /** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
|
---|
| 153 | */
|
---|
[4455f4] | 154 | class TesselPoint : virtual public ParticleInfo {
|
---|
[357fba] | 155 | public:
|
---|
| 156 | TesselPoint();
|
---|
[5c7bf8] | 157 | virtual ~TesselPoint();
|
---|
[357fba] | 158 |
|
---|
| 159 | Vector *node; // pointer to position of the dot in space
|
---|
[5c7bf8] | 160 |
|
---|
| 161 | virtual ostream & operator << (ostream &ost);
|
---|
[357fba] | 162 | };
|
---|
| 163 |
|
---|
| 164 | ostream & operator << (ostream &ost, const TesselPoint &a);
|
---|
| 165 |
|
---|
| 166 | // =========================================================== class POINTCLOUD ============================================
|
---|
| 167 |
|
---|
| 168 | /** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
|
---|
| 169 | * This basically encapsulates a list structure.
|
---|
| 170 | */
|
---|
| 171 | class PointCloud {
|
---|
| 172 | public:
|
---|
| 173 | PointCloud();
|
---|
[ab1932] | 174 | virtual ~PointCloud();
|
---|
[357fba] | 175 |
|
---|
[6a7f78c] | 176 | virtual const char * const GetName() const { return "unknown"; };
|
---|
[e138de] | 177 | virtual Vector *GetCenter() const { return NULL; };
|
---|
[776b64] | 178 | virtual TesselPoint *GetPoint() const { return NULL; };
|
---|
| 179 | virtual TesselPoint *GetTerminalPoint() const { return NULL; };
|
---|
| 180 | virtual void GoToNext() const {};
|
---|
| 181 | virtual void GoToPrevious() const {};
|
---|
| 182 | virtual void GoToFirst() const {};
|
---|
| 183 | virtual void GoToLast() const {};
|
---|
[6a7f78c] | 184 | virtual bool IsEmpty() const { return true; };
|
---|
| 185 | virtual bool IsEnd() const { return true; };
|
---|
[357fba] | 186 | };
|
---|
| 187 |
|
---|
| 188 | // ======================================================== class CandidateForTesselation =========================================
|
---|
| 189 |
|
---|
| 190 | class CandidateForTesselation {
|
---|
| 191 | public :
|
---|
[1e168b] | 192 | CandidateForTesselation(BoundaryLineSet* currentBaseLine);
|
---|
[357fba] | 193 | CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
|
---|
| 194 | ~CandidateForTesselation();
|
---|
| 195 |
|
---|
[f67b6e] | 196 | TesselPointList pointlist;
|
---|
[357fba] | 197 | BoundaryLineSet *BaseLine;
|
---|
| 198 | Vector OptCenter;
|
---|
| 199 | Vector OtherOptCenter;
|
---|
[1e168b] | 200 | double ShortestAngle;
|
---|
| 201 | double OtherShortestAngle;
|
---|
[357fba] | 202 | };
|
---|
| 203 |
|
---|
[1e168b] | 204 | ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
|
---|
| 205 |
|
---|
[357fba] | 206 | // =========================================================== class TESSELATION ===========================================
|
---|
| 207 |
|
---|
| 208 | /** Contains the envelope to a PointCloud.
|
---|
| 209 | */
|
---|
[5c7bf8] | 210 | class Tesselation : public PointCloud {
|
---|
[357fba] | 211 | public:
|
---|
| 212 |
|
---|
| 213 | Tesselation();
|
---|
[5c7bf8] | 214 | virtual ~Tesselation();
|
---|
[357fba] | 215 |
|
---|
[776b64] | 216 | void AddTesselationPoint(TesselPoint* Candidate, const int n);
|
---|
[f1ef60a] | 217 | void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
|
---|
[776b64] | 218 | void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
| 219 | void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
|
---|
[16d866] | 220 | void AddTesselationTriangle();
|
---|
[776b64] | 221 | void AddTesselationTriangle(const int nr);
|
---|
[f67b6e] | 222 | void AddCandidateTriangle(CandidateForTesselation CandidateLine);
|
---|
[16d866] | 223 | void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
|
---|
| 224 | void RemoveTesselationLine(class BoundaryLineSet *line);
|
---|
| 225 | void RemoveTesselationPoint(class BoundaryPointSet *point);
|
---|
| 226 |
|
---|
[357fba] | 227 |
|
---|
| 228 | // concave envelope
|
---|
[e138de] | 229 | void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
|
---|
[776b64] | 230 | void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
|
---|
[f67b6e] | 231 | void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
|
---|
[1e168b] | 232 | bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
|
---|
[f1ef60a] | 233 | int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
|
---|
[e138de] | 234 | class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
|
---|
[357fba] | 235 |
|
---|
| 236 | // convex envelope
|
---|
[e138de] | 237 | void TesselateOnBoundary(const PointCloud * const cloud);
|
---|
| 238 | void GuessStartingTriangle();
|
---|
| 239 | bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
|
---|
| 240 | double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
|
---|
| 241 | class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
|
---|
| 242 | double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
|
---|
| 243 | class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
|
---|
[57066a] | 244 | map<int, int> * FindAllDegeneratedTriangles();
|
---|
| 245 | map<int, int> * FindAllDegeneratedLines();
|
---|
[7c14ec] | 246 | void RemoveDegeneratedTriangles();
|
---|
[e138de] | 247 | void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
|
---|
[16d866] | 248 |
|
---|
[e138de] | 249 | set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
|
---|
| 250 | set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
|
---|
| 251 | list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
| 252 | list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
|
---|
| 253 | list<TesselPoint*> * GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference = NULL) const;
|
---|
[776b64] | 254 | class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
|
---|
| 255 | list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
|
---|
[e138de] | 256 | list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
|
---|
| 257 | class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
|
---|
| 258 | bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
|
---|
| 259 | bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
|
---|
[776b64] | 260 | bool AddBoundaryPoint(TesselPoint * Walker, const int n);
|
---|
[ab1932] | 261 |
|
---|
[0077b5] | 262 | // print for debugging
|
---|
[776b64] | 263 | void PrintAllBoundaryPoints(ofstream *out) const;
|
---|
| 264 | void PrintAllBoundaryLines(ofstream *out) const;
|
---|
| 265 | void PrintAllBoundaryTriangles(ofstream *out) const;
|
---|
[0077b5] | 266 |
|
---|
[57066a] | 267 | // store envelope in file
|
---|
[e138de] | 268 | void Output(const char *filename, const PointCloud * const cloud);
|
---|
[0077b5] | 269 |
|
---|
[357fba] | 270 | PointMap PointsOnBoundary;
|
---|
| 271 | LineMap LinesOnBoundary;
|
---|
[1e168b] | 272 | CandidateMap OpenLines;
|
---|
[357fba] | 273 | TriangleMap TrianglesOnBoundary;
|
---|
| 274 | int PointsOnBoundaryCount;
|
---|
| 275 | int LinesOnBoundaryCount;
|
---|
| 276 | int TrianglesOnBoundaryCount;
|
---|
| 277 |
|
---|
[5c7bf8] | 278 | // PointCloud implementation for PointsOnBoundary
|
---|
[776b64] | 279 | virtual Vector *GetCenter(ofstream *out) const;
|
---|
| 280 | virtual TesselPoint *GetPoint() const;
|
---|
| 281 | virtual TesselPoint *GetTerminalPoint() const;
|
---|
| 282 | virtual void GoToNext() const;
|
---|
| 283 | virtual void GoToPrevious() const;
|
---|
| 284 | virtual void GoToFirst() const;
|
---|
| 285 | virtual void GoToLast() const;
|
---|
| 286 | virtual bool IsEmpty() const;
|
---|
| 287 | virtual bool IsEnd() const;
|
---|
[5c7bf8] | 288 |
|
---|
[357fba] | 289 | class BoundaryPointSet *BPS[2];
|
---|
| 290 | class BoundaryLineSet *BLS[3];
|
---|
| 291 | class BoundaryTriangleSet *BTS;
|
---|
[57066a] | 292 | class BoundaryTriangleSet *LastTriangle;
|
---|
| 293 | int TriangleFilesWritten;
|
---|
[5c7bf8] | 294 |
|
---|
[08ef35] | 295 | private:
|
---|
[f1ef60a] | 296 | mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
|
---|
[08ef35] | 297 |
|
---|
[776b64] | 298 | mutable PointMap::const_iterator InternalPointer;
|
---|
[f1ef60a] | 299 |
|
---|
[f67b6e] | 300 | //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
|
---|
[357fba] | 301 | };
|
---|
| 302 |
|
---|
| 303 |
|
---|
| 304 | #endif /* TESSELATION_HPP_ */
|
---|