source: src/tesselation.hpp@ f8bd7d

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 Candidate_v1.7.0 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 f8bd7d was 09898c, checked in by Frederik Heber <heber@…>, 16 years ago

Changes to BoundaryTriangleSet and CandidateForTesselation.

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

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