source: src/tesselation.hpp@ 5e8f82

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 5e8f82 was fad93c, checked in by Frederik Heber <heber@…>, 16 years ago

The finding of the degenerated polygons' endpoints was not yet correct, fixed.

  • PROBLEM: we always looked for quadragons as atomic units of degenerated polygons, however for aromatic rings there may actually be no quadrons sub parts but only a a hexagon to be found.
  • Tesselation::CorrectAllDegeneratedPolygons(): rename ListofFourse -> ListofDegeneratedPolygons
  • FIX: Tesselation::CorrectAllDegeneratedPolygons(): Number of simply degenerated polygons was returned instead of number of degenerated polygons
  • Rewritten Tesselation::CorrectAllDegeneratedPolygons() in the following manner (which is also a lot faster than before):
    1. Go through all BoundaryPoints
    2. Check whether they have two triangles with anti-parallel NormalVectors, indicating that this point is part of a degenerated polygon.
    3. Combine endpoint candidates based on whether there is a BoundaryLineSet in between, then put them into the same polygon.
    4. Proceed with 3. until all candidates have been put into BoundaryPolygonSets
    5. continue with the unchanged remainder on this new "ListofFours" (our list of degenerated polygons).
  • Property mode set to 100644
File size: 13.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 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 PointMap map < int, class BoundaryPointSet * >
55#define PointSet set < class BoundaryPointSet * >
56#define PointList list < class BoundaryPointSet * >
57#define PointPair pair < int, class BoundaryPointSet * >
58#define PointTestPair pair < PointMap::iterator, bool >
59
60#define CandidateList list <class CandidateForTesselation *>
61#define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
62
63#define LineMap multimap < int, class BoundaryLineSet * >
64#define LineSet set < class BoundaryLineSet * >
65#define LineList list < class BoundaryLineSet * >
66#define LinePair pair < int, class BoundaryLineSet * >
67#define LineTestPair pair < LineMap::iterator, bool >
68
69#define TriangleMap map < int, class BoundaryTriangleSet * >
70#define TriangleSet set < class BoundaryTriangleSet * >
71#define TriangleList list < class BoundaryTriangleSet * >
72#define TrianglePair pair < int, class BoundaryTriangleSet * >
73#define TriangleTestPair pair < TrianglePair::iterator, bool >
74
75#define PolygonMap map < int, class BoundaryPolygonSet * >
76#define PolygonSet set < class BoundaryPolygonSet * >
77#define PolygonList list < class BoundaryPolygonSet * >
78
79#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
80#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
81
82#define TesselPointList list <TesselPoint *>
83#define TesselPointSet set <TesselPoint *>
84
85/********************************************** declarations *******************************/
86
87template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
88{
89 if (endpoint1->Nr < endpoint2->Nr) {
90 endpoints[0] = endpoint1;
91 endpoints[1] = endpoint2;
92 } else {
93 endpoints[0] = endpoint2;
94 endpoints[1] = endpoint1;
95 }
96};
97
98// ======================================================== class BoundaryPointSet =========================================
99
100class BoundaryPointSet {
101 public:
102 BoundaryPointSet();
103 BoundaryPointSet(TesselPoint * Walker);
104 ~BoundaryPointSet();
105
106 void AddLine(class BoundaryLineSet *line);
107
108 LineMap lines;
109 int LinesCount;
110 TesselPoint *node;
111 double value;
112 int Nr;
113};
114
115ostream & operator << (ostream &ost, const BoundaryPointSet &a);
116
117// ======================================================== class BoundaryLineSet ==========================================
118
119class BoundaryLineSet {
120 public:
121 BoundaryLineSet();
122 BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
123 ~BoundaryLineSet();
124
125 void AddTriangle(class BoundaryTriangleSet *triangle);
126 bool IsConnectedTo(class BoundaryLineSet *line);
127 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
128 bool CheckConvexityCriterion();
129 class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
130
131 class BoundaryPointSet *endpoints[2];
132 TriangleMap triangles;
133 int Nr;
134 bool skipped;
135};
136
137ostream & operator << (ostream &ost, const BoundaryLineSet &a);
138
139// ======================================================== class BoundaryTriangleSet =======================================
140
141class BoundaryTriangleSet {
142 public:
143 BoundaryTriangleSet();
144 BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
145 ~BoundaryTriangleSet();
146
147 void GetNormalVector(Vector &NormalVector);
148 void GetCenter(Vector *center);
149 bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
150 bool ContainsBoundaryLine(class BoundaryLineSet *line);
151 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
152 bool ContainsBoundaryPoint(class TesselPoint *point);
153 class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
154 bool IsPresentTupel(class BoundaryPointSet *Points[3]);
155 bool IsPresentTupel(class BoundaryTriangleSet *T);
156
157 class BoundaryPointSet *endpoints[3];
158 class BoundaryLineSet *lines[3];
159 Vector NormalVector;
160 int Nr;
161};
162
163ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
164
165
166// ======================================================== class BoundaryTriangleSet =======================================
167
168/** Set of BoundaryPointSet.
169 * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
170 * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
171 * class (i.e. no allocation, no deletion).
172 * \note we assume that the set of endpoints reside (more or less) on a plane.
173 */
174class BoundaryPolygonSet {
175 public:
176 BoundaryPolygonSet();
177 ~BoundaryPolygonSet();
178
179 Vector * GetNormalVector(const Vector &NormalVector) const;
180 void GetCenter(Vector *center) const;
181 bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
182 bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
183 bool ContainsBoundaryPoint(const TesselPoint * const point) const;
184 bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
185 bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
186 bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
187 bool ContainsPresentTupel(const PointSet &endpoints) const;
188 TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
189 bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
190
191 PointSet endpoints;
192 int Nr;
193};
194
195ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
196
197// =========================================================== class TESSELPOINT ===========================================
198
199/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
200 */
201class TesselPoint : virtual public ParticleInfo {
202public:
203 TesselPoint();
204 virtual ~TesselPoint();
205
206 Vector *node; // pointer to position of the dot in space
207
208 virtual ostream & operator << (ostream &ost);
209};
210
211ostream & operator << (ostream &ost, const TesselPoint &a);
212
213// =========================================================== class POINTCLOUD ============================================
214
215/** Super-class for all point clouds structures, also molecules. They have to inherit this structure and implement the virtual function to access the Vectors.
216 * This basically encapsulates a list structure.
217 */
218class PointCloud {
219public:
220 PointCloud();
221 virtual ~PointCloud();
222
223 virtual const char * const GetName() const { return "unknown"; };
224 virtual Vector *GetCenter() const { return NULL; };
225 virtual TesselPoint *GetPoint() const { return NULL; };
226 virtual TesselPoint *GetTerminalPoint() const { return NULL; };
227 virtual void GoToNext() const {};
228 virtual void GoToPrevious() const {};
229 virtual void GoToFirst() const {};
230 virtual void GoToLast() const {};
231 virtual bool IsEmpty() const { return true; };
232 virtual bool IsEnd() const { return true; };
233};
234
235// ======================================================== class CandidateForTesselation =========================================
236
237class CandidateForTesselation {
238 public :
239 CandidateForTesselation(BoundaryLineSet* currentBaseLine);
240 CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
241 ~CandidateForTesselation();
242
243 TesselPointList pointlist;
244 BoundaryLineSet *BaseLine;
245 Vector OptCenter;
246 Vector OtherOptCenter;
247 double ShortestAngle;
248 double OtherShortestAngle;
249};
250
251ostream & operator <<(ostream &ost, const CandidateForTesselation &a);
252
253// =========================================================== class TESSELATION ===========================================
254
255/** Contains the envelope to a PointCloud.
256 */
257class Tesselation : public PointCloud {
258 public:
259
260 Tesselation();
261 virtual ~Tesselation();
262
263 void AddTesselationPoint(TesselPoint* Candidate, const int n);
264 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
265 void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
266 void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
267 void AddTesselationTriangle();
268 void AddTesselationTriangle(const int nr);
269 void AddCandidateTriangle(CandidateForTesselation CandidateLine);
270 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
271 void RemoveTesselationLine(class BoundaryLineSet *line);
272 void RemoveTesselationPoint(class BoundaryPointSet *point);
273
274
275 // concave envelope
276 void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
277 void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
278 void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
279 bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
280 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
281 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
282
283 // convex envelope
284 void TesselateOnBoundary(const PointCloud * const cloud);
285 void GuessStartingTriangle();
286 bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
287 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
288 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
289 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
290 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
291 map<int, int> * FindAllDegeneratedTriangles();
292 map<int, int> * FindAllDegeneratedLines();
293 void RemoveDegeneratedTriangles();
294 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
295 int CorrectAllDegeneratedPolygons();
296
297 set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
298 set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
299 list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
300 list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
301 list<TesselPoint*> * GetCircleOfSetOfPoints(set<TesselPoint*> *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
302 class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
303 list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
304 list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
305 class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
306 bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
307 bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
308 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
309
310 // print for debugging
311 void PrintAllBoundaryPoints(ofstream *out) const;
312 void PrintAllBoundaryLines(ofstream *out) const;
313 void PrintAllBoundaryTriangles(ofstream *out) const;
314
315 // store envelope in file
316 void Output(const char *filename, const PointCloud * const cloud);
317
318 PointMap PointsOnBoundary;
319 LineMap LinesOnBoundary;
320 CandidateMap OpenLines;
321 TriangleMap TrianglesOnBoundary;
322 int PointsOnBoundaryCount;
323 int LinesOnBoundaryCount;
324 int TrianglesOnBoundaryCount;
325
326 // PointCloud implementation for PointsOnBoundary
327 virtual Vector *GetCenter(ofstream *out) const;
328 virtual TesselPoint *GetPoint() const;
329 virtual TesselPoint *GetTerminalPoint() const;
330 virtual void GoToNext() const;
331 virtual void GoToPrevious() const;
332 virtual void GoToFirst() const;
333 virtual void GoToLast() const;
334 virtual bool IsEmpty() const;
335 virtual bool IsEnd() const;
336
337 class BoundaryPointSet *BPS[2];
338 class BoundaryLineSet *BLS[3];
339 class BoundaryTriangleSet *BTS;
340 class BoundaryTriangleSet *LastTriangle;
341 int TriangleFilesWritten;
342
343 private:
344 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
345
346 mutable PointMap::const_iterator InternalPointer;
347
348 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
349};
350
351
352#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.