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