source: src/tesselation.hpp@ 9fb860

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 9fb860 was 97498a, checked in by Frederik Heber <heber@…>, 15 years ago

Attempt to fix the tesselation::IsInnerPoint().

We try the IsInnerPoint() as follows:

  1. Find nearest BoundaryPoints - working
  2. Find Closest BoundaryLine's - working
  3. Find closest Triangle that is well aligned (wrt to NormalVector and Distance) - unsure whether correctly working
  4. Check whether alignment is on boundary or inside/outside - working
  5. If on boundary, we check whether it's inside of triangle by intersecting with boundary lines - not working

Hence, we code a wrapper for GSL routines, to - finally - allow for solution of linear system of equations.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 14.6 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 1
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/********************************************** declarations *******************************/
91
92template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
93{
94 if (endpoint1->Nr < endpoint2->Nr) {
95 endpoints[0] = endpoint1;
96 endpoints[1] = endpoint2;
97 } else {
98 endpoints[0] = endpoint2;
99 endpoints[1] = endpoint1;
100 }
101};
102
103// ======================================================== class BoundaryPointSet =========================================
104
105class BoundaryPointSet {
106 public:
107 BoundaryPointSet();
108 BoundaryPointSet(TesselPoint * Walker);
109 ~BoundaryPointSet();
110
111 void AddLine(class BoundaryLineSet *line);
112
113 LineMap lines;
114 int LinesCount;
115 TesselPoint *node;
116 double value;
117 int Nr;
118};
119
120ostream & operator << (ostream &ost, const BoundaryPointSet &a);
121
122// ======================================================== class BoundaryLineSet ==========================================
123
124class BoundaryLineSet {
125 public:
126 BoundaryLineSet();
127 BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
128 ~BoundaryLineSet();
129
130 void AddTriangle(class BoundaryTriangleSet *triangle);
131 bool IsConnectedTo(class BoundaryLineSet *line);
132 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
133 bool CheckConvexityCriterion();
134 class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
135
136 class BoundaryPointSet *endpoints[2];
137 TriangleMap triangles;
138 int Nr;
139 bool skipped;
140};
141
142ostream & operator << (ostream &ost, const BoundaryLineSet &a);
143
144// ======================================================== class BoundaryTriangleSet =======================================
145
146class BoundaryTriangleSet {
147 public:
148 BoundaryTriangleSet();
149 BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
150 ~BoundaryTriangleSet();
151
152 void GetNormalVector(Vector &NormalVector);
153 void GetCenter(Vector *center);
154 bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
155 bool ContainsBoundaryLine(class BoundaryLineSet *line);
156 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
157 bool ContainsBoundaryPoint(class TesselPoint *point);
158 class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
159 bool IsPresentTupel(class BoundaryPointSet *Points[3]);
160 bool IsPresentTupel(class BoundaryTriangleSet *T);
161
162 class BoundaryPointSet *endpoints[3];
163 class BoundaryLineSet *lines[3];
164 Vector NormalVector;
165 Vector SphereCenter;
166 int Nr;
167};
168
169ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
170
171
172// ======================================================== class BoundaryTriangleSet =======================================
173
174/** Set of BoundaryPointSet.
175 * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
176 * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
177 * class (i.e. no allocation, no deletion).
178 * \note we assume that the set of endpoints reside (more or less) on a plane.
179 */
180class BoundaryPolygonSet {
181 public:
182 BoundaryPolygonSet();
183 ~BoundaryPolygonSet();
184
185 Vector * GetNormalVector(const Vector &NormalVector) const;
186 void GetCenter(Vector *center) const;
187 bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
188 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
189 bool ContainsBoundaryPoint(const TesselPoint * const point) const;
190 bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
191 bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
192 bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
193 bool ContainsPresentTupel(const PointSet &endpoints) const;
194 TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
195 bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
196
197 PointSet endpoints;
198 int Nr;
199};
200
201ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
202
203// =========================================================== class TESSELPOINT ===========================================
204
205/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
206 */
207class TesselPoint : virtual public ParticleInfo {
208public:
209 TesselPoint();
210 virtual ~TesselPoint();
211
212 Vector *node; // pointer to position of the dot in space
213
214 virtual ostream & operator << (ostream &ost);
215};
216
217ostream & operator << (ostream &ost, const TesselPoint &a);
218
219// =========================================================== class POINTCLOUD ============================================
220
221/** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
222 * This basically encapsulates a list structure.
223 */
224class PointCloud {
225public:
226 PointCloud();
227 virtual ~PointCloud();
228
229 virtual const char * const GetName() const { return "unknown"; };
230 virtual Vector *GetCenter() const { return NULL; };
231 virtual TesselPoint *GetPoint() const { return NULL; };
232 virtual TesselPoint *GetTerminalPoint() const { return NULL; };
233 virtual int GetMaxId() const { return 0; };
234 virtual void GoToNext() const {};
235 virtual void GoToPrevious() const {};
236 virtual void GoToFirst() const {};
237 virtual void GoToLast() const {};
238 virtual bool IsEmpty() const { return true; };
239 virtual bool IsEnd() const { return true; };
240};
241
242// ======================================================== class CandidateForTesselation =========================================
243
244class CandidateForTesselation {
245 public :
246 CandidateForTesselation(BoundaryLineSet* currentBaseLine);
247 CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
248 ~CandidateForTesselation();
249
250 TesselPointList pointlist;
251 BoundaryLineSet *BaseLine;
252 Vector OptCenter;
253 Vector OtherOptCenter;
254 double ShortestAngle;
255 double OtherShortestAngle;
256};
257
258ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
259
260// =========================================================== class TESSELATION ===========================================
261
262/** Contains the envelope to a PointCloud.
263 */
264class Tesselation : public PointCloud {
265 public:
266
267 Tesselation();
268 virtual ~Tesselation();
269
270 void AddTesselationPoint(TesselPoint* Candidate, const int n);
271 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
272 void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
273 void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
274 void AddTesselationTriangle();
275 void AddTesselationTriangle(const int nr);
276 void AddCandidateTriangle(CandidateForTesselation CandidateLine);
277 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
278 void RemoveTesselationLine(class BoundaryLineSet *line);
279 void RemoveTesselationPoint(class BoundaryPointSet *point);
280
281
282 // concave envelope
283 void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
284 void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
285 void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
286 bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
287 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
288 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
289
290 // convex envelope
291 void TesselateOnBoundary(const PointCloud * const cloud);
292 void GuessStartingTriangle();
293 bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
294 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
295 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
296 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
297 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
298 map<int, int> * FindAllDegeneratedTriangles();
299 map<int, int> * FindAllDegeneratedLines();
300 void RemoveDegeneratedTriangles();
301 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
302 int CorrectAllDegeneratedPolygons();
303
304 set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
305 set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
306 list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
307 list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
308 list<TesselPoint*> * GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
309 list<TesselPoint*> * GetCircleOfConnectedTriangles(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const;
310 class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
311 list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
312 list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
313 class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
314 bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC, const double epsilon = -MYEPSILON) const;
315 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
316 DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
317 BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
318 TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
319 BoundaryTriangleSet* FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
320
321 // print for debugging
322 void PrintAllBoundaryPoints(ofstream *out) const;
323 void PrintAllBoundaryLines(ofstream *out) const;
324 void PrintAllBoundaryTriangles(ofstream *out) const;
325
326 // store envelope in file
327 void Output(const char *filename, const PointCloud * const cloud);
328
329 PointMap PointsOnBoundary;
330 LineMap LinesOnBoundary;
331 CandidateMap OpenLines;
332 TriangleMap TrianglesOnBoundary;
333 int PointsOnBoundaryCount;
334 int LinesOnBoundaryCount;
335 int TrianglesOnBoundaryCount;
336
337 // PointCloud implementation for PointsOnBoundary
338 virtual Vector *GetCenter(ofstream *out) const;
339 virtual TesselPoint *GetPoint() const;
340 virtual TesselPoint *GetTerminalPoint() const;
341 virtual void GoToNext() const;
342 virtual void GoToPrevious() const;
343 virtual void GoToFirst() const;
344 virtual void GoToLast() const;
345 virtual bool IsEmpty() const;
346 virtual bool IsEnd() const;
347
348 class BoundaryPointSet *BPS[2];
349 class BoundaryLineSet *BLS[3];
350 class BoundaryTriangleSet *BTS;
351 class BoundaryTriangleSet *LastTriangle;
352 int TriangleFilesWritten;
353
354 private:
355 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
356
357 mutable PointMap::const_iterator InternalPointer;
358
359 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
360};
361
362
363#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.