source: src/tesselation.hpp@ 474961

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 474961 was 474961, checked in by Frederik Heber <heber@…>, 15 years ago

New approach to degenerated triangles: Recognize on creation and add both sides at once.

  • Property mode set to 100644
File size: 15.9 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. 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
13using namespace std;
14
15/*********************************************** includes ***********************************/
16
17// include config.h
18#ifdef HAVE_CONFIG_H
19#include <config.h>
20#endif
21
22#include <map>
23#include <list>
24#include <set>
25#include <stack>
26
27#include "atom_particleinfo.hpp"
28#include "helpers.hpp"
29#include "vector.hpp"
30
31/****************************************** forward declarations *****************************/
32
33class BoundaryPointSet;
34class BoundaryLineSet;
35class BoundaryTriangleSet;
36class LinkedCell;
37class TesselPoint;
38class PointCloud;
39class Tesselation;
40
41/********************************************** definitions *********************************/
42
43#define DoTecplotOutput 1
44#define DoRaster3DOutput 1
45#define DoVRMLOutput 0
46#define TecplotSuffix ".dat"
47#define Raster3DSuffix ".r3d"
48#define VRMLSUffix ".wrl"
49
50#define ParallelEpsilon 1e-3
51
52// ======================================================= some template functions =========================================
53
54#define IndexToIndex map <int, int>
55
56#define PointMap map < int, class BoundaryPointSet * >
57#define PointSet set < class BoundaryPointSet * >
58#define PointList list < class BoundaryPointSet * >
59#define PointPair pair < int, class BoundaryPointSet * >
60#define PointTestPair pair < PointMap::iterator, bool >
61
62#define CandidateList list <class CandidateForTesselation *>
63#define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
64
65#define LineMap multimap < int, class BoundaryLineSet * >
66#define LineSet set < class BoundaryLineSet * >
67#define LineList list < class BoundaryLineSet * >
68#define LinePair pair < int, class BoundaryLineSet * >
69#define LineTestPair pair < LineMap::iterator, bool >
70
71#define TriangleMap map < int, class BoundaryTriangleSet * >
72#define TriangleSet set < class BoundaryTriangleSet * >
73#define TriangleList list < class BoundaryTriangleSet * >
74#define TrianglePair pair < int, class BoundaryTriangleSet * >
75#define TriangleTestPair pair < TrianglePair::iterator, bool >
76
77#define PolygonMap map < int, class BoundaryPolygonSet * >
78#define PolygonSet set < class BoundaryPolygonSet * >
79#define PolygonList list < class BoundaryPolygonSet * >
80
81#define DistanceToPointMap multimap <double, class BoundaryPointSet * >
82#define DistanceToPointPair pair <double, class BoundaryPointSet * >
83
84#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
85#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
86
87#define TesselPointList list <TesselPoint *>
88#define TesselPointSet set <TesselPoint *>
89
90#define ListOfTesselPointList list<list <TesselPoint *> *>
91
92/********************************************** declarations *******************************/
93
94template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
95{
96 if (endpoint1->Nr < endpoint2->Nr) {
97 endpoints[0] = endpoint1;
98 endpoints[1] = endpoint2;
99 } else {
100 endpoints[0] = endpoint2;
101 endpoints[1] = endpoint1;
102 }
103};
104
105// ======================================================== class BoundaryPointSet =========================================
106
107class BoundaryPointSet {
108 public:
109 BoundaryPointSet();
110 BoundaryPointSet(TesselPoint * const Walker);
111 ~BoundaryPointSet();
112
113 void AddLine(BoundaryLineSet * const line);
114
115 LineMap lines;
116 int LinesCount;
117 TesselPoint *node;
118 double value;
119 int Nr;
120};
121
122ostream & operator << (ostream &ost, const BoundaryPointSet &a);
123
124// ======================================================== class BoundaryLineSet ==========================================
125
126class BoundaryLineSet {
127 public:
128 BoundaryLineSet();
129 BoundaryLineSet(BoundaryPointSet * const Point[2], const int number);
130 BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number);
131 ~BoundaryLineSet();
132
133 void AddTriangle(BoundaryTriangleSet * const triangle);
134 bool IsConnectedTo(const BoundaryLineSet * const line) const;
135 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
136 bool CheckConvexityCriterion() const;
137 class BoundaryPointSet *GetOtherEndpoint(const BoundaryPointSet * const point) const;
138
139 class BoundaryPointSet *endpoints[2];
140 TriangleMap triangles;
141 int Nr;
142 bool skipped;
143};
144
145ostream & operator << (ostream &ost, const BoundaryLineSet &a);
146
147// ======================================================== class BoundaryTriangleSet =======================================
148
149class BoundaryTriangleSet {
150 public:
151 BoundaryTriangleSet();
152 BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number);
153 ~BoundaryTriangleSet();
154
155 void GetNormalVector(const Vector &NormalVector);
156 void GetCenter(Vector * const center) const;
157 bool GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const;
158 double GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const;
159 bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
160 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
161 bool ContainsBoundaryPoint(const TesselPoint * const point) const;
162 class BoundaryPointSet *GetThirdEndpoint(const BoundaryLineSet * const line) const;
163 bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
164 bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
165 bool CheckDegeneracy(Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC) const;
166 void SetTopNode(const BoundaryTriangleSet * const topnode);
167
168 class BoundaryPointSet *endpoints[3];
169 class BoundaryLineSet *lines[3];
170 const BoundaryTriangleSet *top; //!< triangle was instantiated during tesselation from this triangle
171 double AngleFromTop;
172 Vector NormalVector;
173 Vector SphereCenter;
174 int Nr;
175};
176
177ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
178
179
180// ======================================================== class BoundaryTriangleSet =======================================
181
182/** Set of BoundaryPointSet.
183 * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
184 * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
185 * class (i.e. no allocation, no deletion).
186 * \note we assume that the set of endpoints reside (more or less) on a plane.
187 */
188class BoundaryPolygonSet {
189 public:
190 BoundaryPolygonSet();
191 ~BoundaryPolygonSet();
192
193 Vector * GetNormalVector(const Vector &NormalVector) const;
194 void GetCenter(Vector *center) const;
195 bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
196 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
197 bool ContainsBoundaryPoint(const TesselPoint * const point) const;
198 bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
199 bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
200 bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
201 bool ContainsPresentTupel(const PointSet &endpoints) const;
202 TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
203 bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
204
205 PointSet endpoints;
206 int Nr;
207};
208
209ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
210
211// =========================================================== class TESSELPOINT ===========================================
212
213/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
214 */
215class TesselPoint : virtual public ParticleInfo {
216public:
217 TesselPoint();
218 virtual ~TesselPoint();
219
220 Vector *node; // pointer to position of the dot in space
221
222 virtual ostream & operator << (ostream &ost);
223};
224
225ostream & operator << (ostream &ost, const TesselPoint &a);
226
227// =========================================================== class POINTCLOUD ============================================
228
229/** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
230 * This basically encapsulates a list structure.
231 */
232class PointCloud {
233public:
234 PointCloud();
235 virtual ~PointCloud();
236
237 virtual const char * const GetName() const { return "unknown"; };
238 virtual Vector *GetCenter() const { return NULL; };
239 virtual TesselPoint *GetPoint() const { return NULL; };
240 virtual TesselPoint *GetTerminalPoint() const { return NULL; };
241 virtual int GetMaxId() const { return 0; };
242 virtual void GoToNext() const {};
243 virtual void GoToPrevious() const {};
244 virtual void GoToFirst() const {};
245 virtual void GoToLast() const {};
246 virtual bool IsEmpty() const { return true; };
247 virtual bool IsEnd() const { return true; };
248};
249
250// ======================================================== class CandidateForTesselation =========================================
251
252class CandidateForTesselation {
253 public :
254 CandidateForTesselation(BoundaryLineSet* currentBaseLine);
255 CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, BoundaryPointSet *point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
256 ~CandidateForTesselation();
257
258 bool CheckValidity(const double RADIUS, const LinkedCell *LC) const;
259
260 TesselPointList pointlist;
261 const BoundaryLineSet * BaseLine;
262 const BoundaryPointSet * ThirdPoint;
263 const BoundaryTriangleSet *T;
264 Vector OldCenter;
265 Vector OptCenter;
266 Vector OtherOptCenter;
267 double ShortestAngle;
268 double OtherShortestAngle;
269};
270
271ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
272
273// =========================================================== class TESSELATION ===========================================
274
275/** Contains the envelope to a PointCloud.
276 */
277class Tesselation : public PointCloud {
278 public:
279
280 Tesselation();
281 virtual ~Tesselation();
282
283 void AddTesselationPoint(TesselPoint* Candidate, const int n);
284 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
285 void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
286 void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
287 void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
288 void AddTesselationTriangle();
289 void AddTesselationTriangle(const int nr);
290 void AddCandidateTriangle(TesselPoint *first, TesselPoint *second, TesselPoint *third);
291 void AddDegeneratedTriangle(BoundaryTriangleSet *&triangle, Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC);
292 void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
293 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
294 void RemoveTesselationLine(class BoundaryLineSet *line);
295 void RemoveTesselationPoint(class BoundaryPointSet *point);
296
297
298 // concave envelope
299 void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
300 void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
301 void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
302 bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
303 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
304 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
305
306 // convex envelope
307 void TesselateOnBoundary(const PointCloud * const cloud);
308 void GuessStartingTriangle();
309 bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
310 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
311 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
312 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
313 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
314 IndexToIndex * FindAllDegeneratedTriangles();
315 IndexToIndex * FindAllDegeneratedLines();
316 void RemoveDegeneratedTriangles();
317 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
318 int CorrectAllDegeneratedPolygons();
319
320 TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
321 TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
322 ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
323 ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
324 TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
325 TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const;
326 class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
327 TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
328 TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
329 BoundaryTriangleSet * FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
330 bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
331 double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
332 double GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const;
333 BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const;
334 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
335 DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
336 BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
337
338 // print for debugging
339 void PrintAllBoundaryPoints(ofstream *out) const;
340 void PrintAllBoundaryLines(ofstream *out) const;
341 void PrintAllBoundaryTriangles(ofstream *out) const;
342
343 // store envelope in file
344 void Output(const char *filename, const PointCloud * const cloud);
345
346 PointMap PointsOnBoundary;
347 LineMap LinesOnBoundary;
348 CandidateMap OpenLines;
349 TriangleMap TrianglesOnBoundary;
350 int PointsOnBoundaryCount;
351 int LinesOnBoundaryCount;
352 int TrianglesOnBoundaryCount;
353
354 // PointCloud implementation for PointsOnBoundary
355 virtual Vector *GetCenter(ofstream *out) const;
356 virtual TesselPoint *GetPoint() const;
357 virtual TesselPoint *GetTerminalPoint() const;
358 virtual void GoToNext() const;
359 virtual void GoToPrevious() const;
360 virtual void GoToFirst() const;
361 virtual void GoToLast() const;
362 virtual bool IsEmpty() const;
363 virtual bool IsEnd() const;
364
365 class BoundaryPointSet *BPS[2];
366 class BoundaryLineSet *BLS[3];
367 class BoundaryTriangleSet *BTS;
368 class BoundaryTriangleSet *LastTriangle;
369 int TriangleFilesWritten;
370
371 private:
372 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
373
374 mutable PointMap::const_iterator InternalPointer;
375
376 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
377};
378
379
380#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.