source: src/tesselation.hpp@ 71b20e

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

Attempt to fix the embedding.

Basically it would be working, but there was some failures with the FindClosestTriangleToPoint() routines.
We get triangles wrong if we start looking for the closest point. Actually, we should really look at each
triangle and check the distance. Now, we look at least at each line, but code is unfinished and crashes at the end
unexplainedly.

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