source: src/tesselation.hpp@ 147339

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 147339 was f1ef60a, checked in by Frederik Heber <heber@…>, 15 years ago

Attempt to fix tesselation for case 1_2-dimethylbenzene.

  • The issue is still the strongly degenerated end of the molecule, that is very flat.
  • new function: Tesselation::HasOtherBaselineBetterCandidate() - checks whether for the two other baselines of a proposed triangle there isn't an even better candidate
  • Tesselation::FindNextSuitableTriangle() uses the above function.
  • FindNonConvexBorder() - instead of jumping to end() if a new line was attempted, we jump to the beginning but only if new line was created succesfully.
  • DoSingleStepOutput reactived for this debugging.
  • Where the newly installed tesselations did only fail for this molecule, now they fail for all and some segfault. Only this runs through cleanly.

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

  • Property mode set to 100644
File size: 11.3 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
26#include "atom_particleinfo.hpp"
27#include "helpers.hpp"
28#include "vector.hpp"
29
30/****************************************** forward declarations *****************************/
31
32class BoundaryPointSet;
33class BoundaryLineSet;
34class BoundaryTriangleSet;
35class LinkedCell;
36class TesselPoint;
37class PointCloud;
38class Tesselation;
39
40/********************************************** definitions *********************************/
41
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
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 *>
55
56#define LineMap multimap < int, class BoundaryLineSet * >
57#define LinePair pair < int, class BoundaryLineSet * >
58#define LineTestPair pair < LineMap::iterator, bool >
59
60#define TriangleMap map < int, class BoundaryTriangleSet * >
61#define TrianglePair pair < int, class BoundaryTriangleSet * >
62#define TriangleTestPair pair < TrianglePair::iterator, bool >
63
64#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
65#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
66
67/********************************************** declarations *******************************/
68
69template <typename T> void SetEndpointsOrdered(T endpoints[2], T endpoint1, T endpoint2)
70{
71 if (endpoint1->Nr < endpoint2->Nr) {
72 endpoints[0] = endpoint1;
73 endpoints[1] = endpoint2;
74 } else {
75 endpoints[0] = endpoint2;
76 endpoints[1] = endpoint1;
77 }
78};
79
80// ======================================================== class BoundaryPointSet =========================================
81
82class BoundaryPointSet {
83 public:
84 BoundaryPointSet();
85 BoundaryPointSet(TesselPoint * Walker);
86 ~BoundaryPointSet();
87
88 void AddLine(class BoundaryLineSet *line);
89
90 LineMap lines;
91 int LinesCount;
92 TesselPoint *node;
93 double value;
94 int Nr;
95};
96
97ostream & operator << (ostream &ost, const BoundaryPointSet &a);
98
99// ======================================================== class BoundaryLineSet ==========================================
100
101class BoundaryLineSet {
102 public:
103 BoundaryLineSet();
104 BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
105 ~BoundaryLineSet();
106
107 void AddTriangle(class BoundaryTriangleSet *triangle);
108 bool IsConnectedTo(class BoundaryLineSet *line);
109 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
110 bool CheckConvexityCriterion();
111 class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
112
113 class BoundaryPointSet *endpoints[2];
114 TriangleMap triangles;
115 int Nr;
116};
117
118ostream & operator << (ostream &ost, const BoundaryLineSet &a);
119
120// ======================================================== class BoundaryTriangleSet =======================================
121
122class BoundaryTriangleSet {
123 public:
124 BoundaryTriangleSet();
125 BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
126 ~BoundaryTriangleSet();
127
128 void GetNormalVector(Vector &NormalVector);
129 void GetCenter(Vector *center);
130 bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
131 bool ContainsBoundaryLine(class BoundaryLineSet *line);
132 bool ContainsBoundaryPoint(class BoundaryPointSet *point);
133 bool ContainsBoundaryPoint(class TesselPoint *point);
134 class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
135 bool IsPresentTupel(class BoundaryPointSet *Points[3]);
136 bool IsPresentTupel(class BoundaryTriangleSet *T);
137
138 class BoundaryPointSet *endpoints[3];
139 class BoundaryLineSet *lines[3];
140 Vector NormalVector;
141 int Nr;
142};
143
144ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
145
146// =========================================================== class TESSELPOINT ===========================================
147
148/** Is a single point of the set of Vectors, also a super-class to be inherited and and its functions to be implemented.
149 */
150class TesselPoint : virtual public ParticleInfo {
151public:
152 TesselPoint();
153 virtual ~TesselPoint();
154
155 Vector *node; // pointer to position of the dot in space
156
157 virtual ostream & operator << (ostream &ost);
158};
159
160ostream & 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 */
167class PointCloud {
168public:
169 PointCloud();
170 virtual ~PointCloud();
171
172 virtual Vector *GetCenter() const { return NULL; };
173 virtual TesselPoint *GetPoint() const { return NULL; };
174 virtual TesselPoint *GetTerminalPoint() const { return NULL; };
175 virtual void GoToNext() const {};
176 virtual void GoToPrevious() const {};
177 virtual void GoToFirst() const {};
178 virtual void GoToLast() const {};
179 virtual bool IsEmpty() const { return false; };
180 virtual bool IsEnd() const { return false; };
181};
182
183// ======================================================== class CandidateForTesselation =========================================
184
185class 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 */
200class Tesselation : public PointCloud {
201 public:
202
203 Tesselation();
204 virtual ~Tesselation();
205
206 void AddTesselationPoint(TesselPoint* Candidate, const int n);
207 void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
208 void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
209 void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
210 void AddTesselationTriangle();
211 void AddTesselationTriangle(const int nr);
212 void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
213 void RemoveTesselationLine(class BoundaryLineSet *line);
214 void RemoveTesselationPoint(class BoundaryPointSet *point);
215
216
217 // concave envelope
218 void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
219 void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
220 void FindThirdPointForTesselation(Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, class BoundaryLineSet *BaseLine, const class TesselPoint * const ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC) const;
221 bool FindNextSuitableTriangle(BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
222 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
223 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
224
225 // convex envelope
226 void TesselateOnBoundary(const PointCloud * const cloud);
227 void GuessStartingTriangle();
228 bool InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC);
229 double RemovePointFromTesselatedSurface(class BoundaryPointSet *point);
230 class BoundaryLineSet * FlipBaseline(class BoundaryLineSet *Base);
231 double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
232 class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
233 map<int, int> * FindAllDegeneratedTriangles();
234 map<int, int> * FindAllDegeneratedLines();
235 void RemoveDegeneratedTriangles();
236 void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
237
238 set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
239 set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
240 list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
241 list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
242 list<TesselPoint*> * GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference = NULL) const;
243 class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
244 list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
245 list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
246 class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
247 bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
248 bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
249 bool AddBoundaryPoint(TesselPoint * Walker, const int n);
250
251 // print for debugging
252 void PrintAllBoundaryPoints(ofstream *out) const;
253 void PrintAllBoundaryLines(ofstream *out) const;
254 void PrintAllBoundaryTriangles(ofstream *out) const;
255
256 // store envelope in file
257 void Output(const char *filename, const PointCloud * const cloud);
258
259 PointMap PointsOnBoundary;
260 LineMap LinesOnBoundary;
261 TriangleMap TrianglesOnBoundary;
262 int PointsOnBoundaryCount;
263 int LinesOnBoundaryCount;
264 int TrianglesOnBoundaryCount;
265
266 // PointCloud implementation for PointsOnBoundary
267 virtual Vector *GetCenter(ofstream *out) const;
268 virtual TesselPoint *GetPoint() const;
269 virtual TesselPoint *GetTerminalPoint() const;
270 virtual void GoToNext() const;
271 virtual void GoToPrevious() const;
272 virtual void GoToFirst() const;
273 virtual void GoToLast() const;
274 virtual bool IsEmpty() const;
275 virtual bool IsEnd() const;
276
277 class BoundaryPointSet *BPS[2];
278 class BoundaryLineSet *BLS[3];
279 class BoundaryTriangleSet *BTS;
280 class BoundaryTriangleSet *LastTriangle;
281 int TriangleFilesWritten;
282
283 private:
284 mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
285
286 mutable PointMap::const_iterator InternalPointer;
287
288 bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
289};
290
291
292#endif /* TESSELATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.