source: src/tesselation.hpp@ d4fa23

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

Merge branch 'ConcaveHull' of ssh://stud64d-02/home/metzler/workspace/espack into Ticket14

Conflicts:

molecuilder/src/boundary.cpp
molecuilder/src/tesselation.cpp

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