source: src/tesselationhelpers.cpp@ 579a81

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

FIX: GetCenterofCircumcircle() has check for division by zero.

  • Property mode set to 100644
File size: 39.8 KB
Line 
1/*
2 * TesselationHelpers.cpp
3 *
4 * Created on: Aug 3, 2009
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "Helpers/MemDebug.hpp"
14
15#include <fstream>
16
17#include "BoundaryLineSet.hpp"
18#include "BoundaryPointSet.hpp"
19#include "BoundaryPolygonSet.hpp"
20#include "BoundaryTriangleSet.hpp"
21#include "CandidateForTesselation.hpp"
22#include "Helpers/Info.hpp"
23#include "linkedcell.hpp"
24#include "LinearAlgebra/linearsystemofequations.hpp"
25#include "Helpers/Log.hpp"
26#include "tesselation.hpp"
27#include "tesselationhelpers.hpp"
28#include "LinearAlgebra/Vector.hpp"
29#include "LinearAlgebra/Line.hpp"
30#include "LinearAlgebra/vector_ops.hpp"
31#include "Helpers/Verbose.hpp"
32#include "LinearAlgebra/Plane.hpp"
33#include "LinearAlgebra/Matrix.hpp"
34
35void GetSphere(Vector * const center, const Vector &a, const Vector &b, const Vector &c, const double RADIUS)
36{
37 Info FunctionInfo(__func__);
38 Matrix mat;
39 double m11, m12, m13, m14;
40
41 for(int i=0;i<3;i++) {
42 mat.set(i, 0, a[i]);
43 mat.set(i, 1, b[i]);
44 mat.set(i, 2, c[i]);
45 }
46 m11 = mat.determinant();
47
48 for(int i=0;i<3;i++) {
49 mat.set(i, 0, a[i]*a[i] + b[i]*b[i] + c[i]*c[i]);
50 mat.set(i, 1, b[i]);
51 mat.set(i, 2, c[i]);
52 }
53 m12 = mat.determinant();
54
55 for(int i=0;i<3;i++) {
56 mat.set(i, 0, a[i]*a[i] + b[i]*b[i] + c[i]*c[i]);
57 mat.set(i, 1, a[i]);
58 mat.set(i, 2, c[i]);
59 }
60 m13 = mat.determinant();
61
62 for(int i=0;i<3;i++) {
63 mat.set(i, 0, a[i]*a[i] + b[i]*b[i] + c[i]*c[i]);
64 mat.set(i, 1, a[i]);
65 mat.set(i, 2, b[i]);
66 }
67 m14 = mat.determinant();
68
69 if (fabs(m11) < MYEPSILON)
70 DoeLog(1) && (eLog()<< Verbose(1) << "three points are colinear." << endl);
71
72 center->at(0) = 0.5 * m12/ m11;
73 center->at(1) = -0.5 * m13/ m11;
74 center->at(2) = 0.5 * m14/ m11;
75
76 if (fabs(a.distance(*center) - RADIUS) > MYEPSILON)
77 DoeLog(1) && (eLog()<< Verbose(1) << "The given center is further way by " << fabs(a.distance(*center) - RADIUS) << " from a than RADIUS." << endl);
78};
79
80
81
82/**
83 * Function returns center of sphere with RADIUS, which rests on points a, b, c
84 * @param Center this vector will be used for return
85 * @param a vector first point of triangle
86 * @param b vector second point of triangle
87 * @param c vector third point of triangle
88 * @param *Umkreismittelpunkt new center point of circumference
89 * @param Direction vector indicates up/down
90 * @param AlternativeDirection Vector, needed in case the triangles have 90 deg angle
91 * @param Halfplaneindicator double indicates whether Direction is up or down
92 * @param AlternativeIndicator double indicates in case of orthogonal triangles which direction of AlternativeDirection is suitable
93 * @param alpha double angle at a
94 * @param beta double, angle at b
95 * @param gamma, double, angle at c
96 * @param Radius, double
97 * @param Umkreisradius double radius of circumscribing circle
98 */
99void GetCenterOfSphere(Vector* const & Center, const Vector &a, const Vector &b, const Vector &c, Vector * const NewUmkreismittelpunkt, const Vector* const Direction, const Vector* const AlternativeDirection,
100 const double HalfplaneIndicator, const double AlternativeIndicator, const double alpha, const double beta, const double gamma, const double RADIUS, const double Umkreisradius)
101{
102 Info FunctionInfo(__func__);
103 Vector TempNormal, helper;
104 double Restradius;
105 Vector OtherCenter;
106 Center->Zero();
107 helper = sin(2.*alpha) * a;
108 (*Center) += helper;
109 helper = sin(2.*beta) * b;
110 (*Center) += helper;
111 helper = sin(2.*gamma) * c;
112 (*Center) += helper;
113 //*Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ;
114 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
115 (*NewUmkreismittelpunkt) = (*Center);
116 DoLog(1) && (Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n");
117 // Here we calculated center of circumscribing circle, using barycentric coordinates
118 DoLog(1) && (Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n");
119
120 TempNormal = a - b;
121 helper = a - c;
122 TempNormal.VectorProduct(helper);
123 if (fabs(HalfplaneIndicator) < MYEPSILON)
124 {
125 if ((TempNormal.ScalarProduct(*AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(*AlternativeDirection) >0 && AlternativeIndicator <0))
126 {
127 TempNormal *= -1;
128 }
129 }
130 else
131 {
132 if (((TempNormal.ScalarProduct(*Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(*Direction)>0) && (HalfplaneIndicator<0)))
133 {
134 TempNormal *= -1;
135 }
136 }
137
138 TempNormal.Normalize();
139 Restradius = sqrt(RADIUS*RADIUS - Umkreisradius*Umkreisradius);
140 DoLog(1) && (Log() << Verbose(1) << "Height of center of circumference to center of sphere is " << Restradius << ".\n");
141 TempNormal.Scale(Restradius);
142 DoLog(1) && (Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n");
143 (*Center) += TempNormal;
144 DoLog(1) && (Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n");
145 GetSphere(&OtherCenter, a, b, c, RADIUS);
146 DoLog(1) && (Log() << Verbose(1) << "OtherCenter of sphere of circumference is " << OtherCenter << ".\n");
147};
148
149
150/** Constructs the center of the circumcircle defined by three points \a *a, \a *b and \a *c.
151 * \param *Center new center on return
152 * \param *a first point
153 * \param *b second point
154 * \param *c third point
155 */
156void GetCenterofCircumcircle(Vector &Center, const Vector &a, const Vector &b, const Vector &c)
157{
158 Info FunctionInfo(__func__);
159 Vector helper;
160 Vector SideA = b - c;
161 Vector SideB = c - a;
162 Vector SideC = a - b;
163
164 helper[0] = SideA.NormSquared()*(SideB.NormSquared()+SideC.NormSquared() - SideA.NormSquared());
165 helper[1] = SideB.NormSquared()*(SideC.NormSquared()+SideA.NormSquared() - SideB.NormSquared());
166 helper[2] = SideC.NormSquared()*(SideA.NormSquared()+SideB.NormSquared() - SideC.NormSquared());
167
168 Center.Zero();
169 Center += helper[0] * a;
170 Center += helper[1] * b;
171 Center += helper[2] * c;
172 if (fabs(helper[0]+helper[1]+helper[2]) > MYEPSILON)
173 Center.Scale(1./(helper[0]+helper[1]+helper[2]));
174 Log() << Verbose(1) << "INFO: Center (2nd algo) is at " << Center << "." << endl;
175};
176
177/** Returns the parameter "path length" for a given \a NewSphereCenter relative to \a OldSphereCenter on a circle on the plane \a CirclePlaneNormal with center \a CircleCenter and radius \a CircleRadius.
178 * Test whether the \a NewSphereCenter is really on the given plane and in distance \a CircleRadius from \a CircleCenter.
179 * It calculates the angle, making it unique on [0,2.*M_PI) by comparing to SearchDirection.
180 * Also the new center is invalid if it the same as the old one and does not lie right above (\a NormalVector) the base line (\a CircleCenter).
181 * \param CircleCenter Center of the parameter circle
182 * \param CirclePlaneNormal normal vector to plane of the parameter circle
183 * \param CircleRadius radius of the parameter circle
184 * \param NewSphereCenter new center of a circumcircle
185 * \param OldSphereCenter old center of a circumcircle, defining the zero "path length" on the parameter circle
186 * \param NormalVector normal vector
187 * \param SearchDirection search direction to make angle unique on return.
188 * \param HULLEPSILON machine precision for tesselation points
189 * \return Angle between \a NewSphereCenter and \a OldSphereCenter relative to \a CircleCenter, 2.*M_PI if one test fails
190 */
191double GetPathLengthonCircumCircle(const Vector &CircleCenter, const Vector &CirclePlaneNormal, const double CircleRadius, const Vector &NewSphereCenter, const Vector &OldSphereCenter, const Vector &NormalVector, const Vector &SearchDirection, const double HULLEPSILON)
192{
193 Info FunctionInfo(__func__);
194 Vector helper;
195 double radius, alpha;
196
197 Vector RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
198 Vector RelativeNewSphereCenter = NewSphereCenter - CircleCenter;
199 helper = RelativeNewSphereCenter;
200 // test whether new center is on the parameter circle's plane
201 if (fabs(helper.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
202 DoeLog(1) && (eLog()<< Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(CirclePlaneNormal)) << "!" << endl);
203 helper.ProjectOntoPlane(CirclePlaneNormal);
204 }
205 radius = helper.NormSquared();
206 // test whether the new center vector has length of CircleRadius
207 if (fabs(radius - CircleRadius) > HULLEPSILON)
208 DoeLog(1) && (eLog()<< Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
209 alpha = helper.Angle(RelativeOldSphereCenter);
210 // make the angle unique by checking the halfplanes/search direction
211 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON) // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals
212 alpha = 2.*M_PI - alpha;
213 DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl);
214 radius = helper.distance(RelativeOldSphereCenter);
215 helper.ProjectOntoPlane(NormalVector);
216 // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles
217 if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) {
218 DoLog(1) && (Log() << Verbose(1) << "INFO: Distance between old and new center is " << radius << " and between new center and baseline center is " << helper.Norm() << "." << endl);
219 return alpha;
220 } else {
221 DoLog(1) && (Log() << Verbose(1) << "INFO: NewSphereCenter " << RelativeNewSphereCenter << " is too close to RelativeOldSphereCenter" << RelativeOldSphereCenter << "." << endl);
222 return 2.*M_PI;
223 }
224};
225
226struct Intersection {
227 Vector x1;
228 Vector x2;
229 Vector x3;
230 Vector x4;
231};
232
233/** Gets the angle between a point and a reference relative to the provided center.
234 * We have two shanks point and reference between which the angle is calculated
235 * and by scalar product with OrthogonalVector we decide the interval.
236 * @param point to calculate the angle for
237 * @param reference to which to calculate the angle
238 * @param OrthogonalVector points in direction of [pi,2pi] interval
239 *
240 * @return angle between point and reference
241 */
242double GetAngle(const Vector &point, const Vector &reference, const Vector &OrthogonalVector)
243{
244 Info FunctionInfo(__func__);
245 if (reference.IsZero())
246 return M_PI;
247
248 // calculate both angles and correct with in-plane vector
249 if (point.IsZero())
250 return M_PI;
251 double phi = point.Angle(reference);
252 if (OrthogonalVector.ScalarProduct(point) > 0) {
253 phi = 2.*M_PI - phi;
254 }
255
256 DoLog(1) && (Log() << Verbose(1) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl);
257
258 return phi;
259}
260
261
262/** Calculates the volume of a general tetraeder.
263 * \param *a first vector
264 * \param *b second vector
265 * \param *c third vector
266 * \param *d fourth vector
267 * \return \f$ \frac{1}{6} \cdot ((a-d) \times (a-c) \cdot (a-b)) \f$
268 */
269double CalculateVolumeofGeneralTetraeder(const Vector &a, const Vector &b, const Vector &c, const Vector &d)
270{
271 Info FunctionInfo(__func__);
272 Vector Point, TetraederVector[3];
273 double volume;
274
275 TetraederVector[0] = a;
276 TetraederVector[1] = b;
277 TetraederVector[2] = c;
278 for (int j=0;j<3;j++)
279 TetraederVector[j].SubtractVector(d);
280 Point = TetraederVector[0];
281 Point.VectorProduct(TetraederVector[1]);
282 volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2]));
283 return volume;
284};
285
286/** Calculates the area of a general triangle.
287 * We use the Heron's formula of area, [Bronstein, S. 138]
288 * \param &A first vector
289 * \param &B second vector
290 * \param &C third vector
291 * \return \f$ \frac{1}{6} \cdot ((a-d) \times (a-c) \cdot (a-b)) \f$
292 */
293double CalculateAreaofGeneralTriangle(const Vector &A, const Vector &B, const Vector &C)
294{
295 Info FunctionInfo(__func__);
296
297 const double sidea = B.distance(C);
298 const double sideb = A.distance(C);
299 const double sidec = A.distance(B);
300 const double s = (sidea+sideb+sidec)/2.;
301
302 const double area = sqrt(s*(s-sidea)*(s-sideb)*(s-sidec));
303 return area;
304};
305
306
307/** Checks for a new special triangle whether one of its edges is already present with one one triangle connected.
308 * This enforces that special triangles (i.e. degenerated ones) should at last close the open-edge frontier and not
309 * make it bigger (i.e. closing one (the baseline) and opening two new ones).
310 * \param TPS[3] nodes of the triangle
311 * \return true - there is such a line (i.e. creation of degenerated triangle is valid), false - no such line (don't create)
312 */
313bool CheckLineCriteriaForDegeneratedTriangle(const BoundaryPointSet * const nodes[3])
314{
315 Info FunctionInfo(__func__);
316 bool result = false;
317 int counter = 0;
318
319 // check all three points
320 for (int i=0;i<3;i++)
321 for (int j=i+1; j<3; j++) {
322 if (nodes[i] == NULL) {
323 DoLog(1) && (Log() << Verbose(1) << "Node nr. " << i << " is not yet present." << endl);
324 result = true;
325 } else if (nodes[i]->lines.find(nodes[j]->node->nr) != nodes[i]->lines.end()) { // there already is a line
326 LineMap::const_iterator FindLine;
327 pair<LineMap::const_iterator,LineMap::const_iterator> FindPair;
328 FindPair = nodes[i]->lines.equal_range(nodes[j]->node->nr);
329 for (FindLine = FindPair.first; FindLine != FindPair.second; ++FindLine) {
330 // If there is a line with less than two attached triangles, we don't need a new line.
331 if (FindLine->second->triangles.size() < 2) {
332 counter++;
333 break; // increase counter only once per edge
334 }
335 }
336 } else { // no line
337 DoLog(1) && (Log() << Verbose(1) << "The line between " << *nodes[i] << " and " << *nodes[j] << " is not yet present, hence no need for a degenerate triangle." << endl);
338 result = true;
339 }
340 }
341 if ((!result) && (counter > 1)) {
342 DoLog(1) && (Log() << Verbose(1) << "INFO: Degenerate triangle is ok, at least two, here " << counter << ", existing lines are used." << endl);
343 result = true;
344 }
345 return result;
346};
347
348
349///** Sort function for the candidate list.
350// */
351//bool SortCandidates(const CandidateForTesselation* candidate1, const CandidateForTesselation* candidate2)
352//{
353// Info FunctionInfo(__func__);
354// Vector BaseLineVector, OrthogonalVector, helper;
355// if (candidate1->BaseLine != candidate2->BaseLine) { // sanity check
356// DoeLog(1) && (eLog()<< Verbose(1) << "sortCandidates was called for two different baselines: " << candidate1->BaseLine << " and " << candidate2->BaseLine << "." << endl);
357// //return false;
358// exit(1);
359// }
360// // create baseline vector
361// BaseLineVector.CopyVector(candidate1->BaseLine->endpoints[1]->node->node);
362// BaseLineVector.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
363// BaseLineVector.Normalize();
364//
365// // create normal in-plane vector to cope with acos() non-uniqueness on [0,2pi] (note that is pointing in the "right" direction already, hence ">0" test!)
366// helper.CopyVector(candidate1->BaseLine->endpoints[0]->node->node);
367// helper.SubtractVector(candidate1->point->node);
368// OrthogonalVector.CopyVector(&helper);
369// helper.VectorProduct(&BaseLineVector);
370// OrthogonalVector.SubtractVector(&helper);
371// OrthogonalVector.Normalize();
372//
373// // calculate both angles and correct with in-plane vector
374// helper.CopyVector(candidate1->point->node);
375// helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
376// double phi = BaseLineVector.Angle(&helper);
377// if (OrthogonalVector.ScalarProduct(&helper) > 0) {
378// phi = 2.*M_PI - phi;
379// }
380// helper.CopyVector(candidate2->point->node);
381// helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
382// double psi = BaseLineVector.Angle(&helper);
383// if (OrthogonalVector.ScalarProduct(&helper) > 0) {
384// psi = 2.*M_PI - psi;
385// }
386//
387// Log() << Verbose(1) << *candidate1->point << " has angle " << phi << endl;
388// Log() << Verbose(1) << *candidate2->point << " has angle " << psi << endl;
389//
390// // return comparison
391// return phi < psi;
392//};
393
394/**
395 * Finds the point which is second closest to the provided one.
396 *
397 * @param Point to which to find the second closest other point
398 * @param linked cell structure
399 *
400 * @return point which is second closest to the provided one
401 */
402TesselPoint* FindSecondClosestTesselPoint(const Vector& Point, const LinkedCell* const LC)
403{
404 Info FunctionInfo(__func__);
405 TesselPoint* closestPoint = NULL;
406 TesselPoint* secondClosestPoint = NULL;
407 double distance = 1e16;
408 double secondDistance = 1e16;
409 Vector helper;
410 int N[NDIM], Nlower[NDIM], Nupper[NDIM];
411
412 LC->SetIndexToVector(Point); // ignore status as we calculate bounds below sensibly
413 for(int i=0;i<NDIM;i++) // store indices of this cell
414 N[i] = LC->n[i];
415 DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
416
417 LC->GetNeighbourBounds(Nlower, Nupper);
418 //Log() << Verbose(1) << endl;
419 for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
420 for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
421 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
422 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
423 //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
424 if (List != NULL) {
425 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
426 helper = (Point) - ((*Runner)->getPosition());
427 double currentNorm = helper. Norm();
428 if (currentNorm < distance) {
429 // remember second point
430 secondDistance = distance;
431 secondClosestPoint = closestPoint;
432 // mark down new closest point
433 distance = currentNorm;
434 closestPoint = (*Runner);
435 //Log() << Verbose(2) << "INFO: New Second Nearest Neighbour is " << *secondClosestPoint << "." << endl;
436 }
437 }
438 } else {
439 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
440 }
441 }
442
443 return secondClosestPoint;
444};
445
446/**
447 * Finds the point which is closest to the provided one.
448 *
449 * @param Point to which to find the closest other point
450 * @param SecondPoint the second closest other point on return, NULL if none found
451 * @param linked cell structure
452 *
453 * @return point which is closest to the provided one, NULL if none found
454 */
455TesselPoint* FindClosestTesselPoint(const Vector& Point, TesselPoint *&SecondPoint, const LinkedCell* const LC)
456{
457 Info FunctionInfo(__func__);
458 TesselPoint* closestPoint = NULL;
459 SecondPoint = NULL;
460 double distance = 1e16;
461 double secondDistance = 1e16;
462 Vector helper;
463 int N[NDIM], Nlower[NDIM], Nupper[NDIM];
464
465 LC->SetIndexToVector(Point); // ignore status as we calculate bounds below sensibly
466 for(int i=0;i<NDIM;i++) // store indices of this cell
467 N[i] = LC->n[i];
468 DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
469
470 LC->GetNeighbourBounds(Nlower, Nupper);
471 //Log() << Verbose(1) << endl;
472 for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
473 for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
474 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
475 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
476 //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
477 if (List != NULL) {
478 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
479 helper = (Point) - ((*Runner)->getPosition());
480 double currentNorm = helper.NormSquared();
481 if (currentNorm < distance) {
482 secondDistance = distance;
483 SecondPoint = closestPoint;
484 distance = currentNorm;
485 closestPoint = (*Runner);
486 //Log() << Verbose(1) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl;
487 } else if (currentNorm < secondDistance) {
488 secondDistance = currentNorm;
489 SecondPoint = (*Runner);
490 //Log() << Verbose(1) << "INFO: New Second Nearest Neighbour is " << *SecondPoint << "." << endl;
491 }
492 }
493 } else {
494 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
495 }
496 }
497 // output
498 if (closestPoint != NULL) {
499 DoLog(1) && (Log() << Verbose(1) << "Closest point is " << *closestPoint);
500 if (SecondPoint != NULL)
501 DoLog(0) && (Log() << Verbose(0) << " and second closest is " << *SecondPoint);
502 DoLog(0) && (Log() << Verbose(0) << "." << endl);
503 }
504 return closestPoint;
505};
506
507/** Returns the closest point on \a *Base with respect to \a *OtherBase.
508 * \param *out output stream for debugging
509 * \param *Base reference line
510 * \param *OtherBase other base line
511 * \return Vector on reference line that has closest distance
512 */
513Vector * GetClosestPointBetweenLine(const BoundaryLineSet * const Base, const BoundaryLineSet * const OtherBase)
514{
515 Info FunctionInfo(__func__);
516 // construct the plane of the two baselines (i.e. take both their directional vectors)
517 Vector Baseline = (Base->endpoints[1]->node->getPosition()) - (Base->endpoints[0]->node->getPosition());
518 Vector OtherBaseline = (OtherBase->endpoints[1]->node->getPosition()) - (OtherBase->endpoints[0]->node->getPosition());
519 Vector Normal = Baseline;
520 Normal.VectorProduct(OtherBaseline);
521 Normal.Normalize();
522 DoLog(1) && (Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl);
523
524 // project one offset point of OtherBase onto this plane (and add plane offset vector)
525 Vector NewOffset = (OtherBase->endpoints[0]->node->getPosition()) - (Base->endpoints[0]->node->getPosition());
526 NewOffset.ProjectOntoPlane(Normal);
527 NewOffset += (Base->endpoints[0]->node->getPosition());
528 Vector NewDirection = NewOffset + OtherBaseline;
529
530 // calculate the intersection between this projected baseline and Base
531 Vector *Intersection = new Vector;
532 Line line1 = makeLineThrough((Base->endpoints[0]->node->getPosition()),(Base->endpoints[1]->node->getPosition()));
533 Line line2 = makeLineThrough(NewOffset, NewDirection);
534 *Intersection = line1.getIntersection(line2);
535 Normal = (*Intersection) - (Base->endpoints[0]->node->getPosition());
536 DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(Baseline)/Baseline.NormSquared()) << "." << endl);
537
538 return Intersection;
539};
540
541/** Returns the distance to the plane defined by \a *triangle
542 * \param *out output stream for debugging
543 * \param *x Vector to calculate distance to
544 * \param *triangle triangle defining plane
545 * \return distance between \a *x and plane defined by \a *triangle, -1 - if something went wrong
546 */
547double DistanceToTrianglePlane(const Vector *x, const BoundaryTriangleSet * const triangle)
548{
549 Info FunctionInfo(__func__);
550 double distance = 0.;
551 if (x == NULL) {
552 return -1;
553 }
554 distance = x->DistanceToSpace(triangle->getPlane());
555 return distance;
556};
557
558/** Creates the objects in a VRML file.
559 * \param *out output stream for debugging
560 * \param *vrmlfile output stream for tecplot data
561 * \param *Tess Tesselation structure with constructed triangles
562 * \param *mol molecule structure with atom positions
563 */
564void WriteVrmlFile(ofstream * const vrmlfile, const Tesselation * const Tess, const PointCloud * const cloud)
565{
566 Info FunctionInfo(__func__);
567 TesselPoint *Walker = NULL;
568 int i;
569 Vector *center = cloud->GetCenter();
570 if (vrmlfile != NULL) {
571 //Log() << Verbose(1) << "Writing Raster3D file ... ";
572 *vrmlfile << "#VRML V2.0 utf8" << endl;
573 *vrmlfile << "#Created by molecuilder" << endl;
574 *vrmlfile << "#All atoms as spheres" << endl;
575 cloud->GoToFirst();
576 while (!cloud->IsEnd()) {
577 Walker = cloud->GetPoint();
578 *vrmlfile << "Sphere {" << endl << " "; // 2 is sphere type
579 for (i=0;i<NDIM;i++)
580 *vrmlfile << Walker->at(i)-center->at(i) << " ";
581 *vrmlfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour
582 cloud->GoToNext();
583 }
584
585 *vrmlfile << "# All tesselation triangles" << endl;
586 for (TriangleMap::const_iterator TriangleRunner = Tess->TrianglesOnBoundary.begin(); TriangleRunner != Tess->TrianglesOnBoundary.end(); TriangleRunner++) {
587 *vrmlfile << "1" << endl << " "; // 1 is triangle type
588 for (i=0;i<3;i++) { // print each node
589 for (int j=0;j<NDIM;j++) // and for each node all NDIM coordinates
590 *vrmlfile << TriangleRunner->second->endpoints[i]->node->at(j)-center->at(j) << " ";
591 *vrmlfile << "\t";
592 }
593 *vrmlfile << "1. 0. 0." << endl; // red as colour
594 *vrmlfile << "18" << endl << " 0.5 0.5 0.5" << endl; // 18 is transparency type for previous object
595 }
596 } else {
597 DoeLog(1) && (eLog()<< Verbose(1) << "Given vrmlfile is " << vrmlfile << "." << endl);
598 }
599 delete(center);
600};
601
602/** Writes additionally the current sphere (i.e. the last triangle to file).
603 * \param *out output stream for debugging
604 * \param *rasterfile output stream for tecplot data
605 * \param *Tess Tesselation structure with constructed triangles
606 * \param *mol molecule structure with atom positions
607 */
608void IncludeSphereinRaster3D(ofstream * const rasterfile, const Tesselation * const Tess, const PointCloud * const cloud)
609{
610 Info FunctionInfo(__func__);
611 Vector helper;
612
613 if (Tess->LastTriangle != NULL) {
614 // include the current position of the virtual sphere in the temporary raster3d file
615 Vector *center = cloud->GetCenter();
616 // make the circumsphere's center absolute again
617 Vector helper = (1./3.) * ((Tess->LastTriangle->endpoints[0]->node->getPosition()) +
618 (Tess->LastTriangle->endpoints[1]->node->getPosition()) +
619 (Tess->LastTriangle->endpoints[2]->node->getPosition()));
620 helper -= (*center);
621 // and add to file plus translucency object
622 *rasterfile << "# current virtual sphere\n";
623 *rasterfile << "8\n 25.0 0.6 -1.0 -1.0 -1.0 0.2 0 0 0 0\n";
624 *rasterfile << "2\n " << helper[0] << " " << helper[1] << " " << helper[2] << "\t" << 5. << "\t1 0 0\n";
625 *rasterfile << "9\n terminating special property\n";
626 delete(center);
627 }
628};
629
630/** Creates the objects in a raster3d file (renderable with a header.r3d).
631 * \param *out output stream for debugging
632 * \param *rasterfile output stream for tecplot data
633 * \param *Tess Tesselation structure with constructed triangles
634 * \param *mol molecule structure with atom positions
635 */
636void WriteRaster3dFile(ofstream * const rasterfile, const Tesselation * const Tess, const PointCloud * const cloud)
637{
638 Info FunctionInfo(__func__);
639 TesselPoint *Walker = NULL;
640 int i;
641 Vector *center = cloud->GetCenter();
642 if (rasterfile != NULL) {
643 //Log() << Verbose(1) << "Writing Raster3D file ... ";
644 *rasterfile << "# Raster3D object description, created by MoleCuilder" << endl;
645 *rasterfile << "@header.r3d" << endl;
646 *rasterfile << "# All atoms as spheres" << endl;
647 cloud->GoToFirst();
648 while (!cloud->IsEnd()) {
649 Walker = cloud->GetPoint();
650 *rasterfile << "2" << endl << " "; // 2 is sphere type
651 for (int j=0;j<NDIM;j++) { // and for each node all NDIM coordinates
652 const double tmp = Walker->at(j)-center->at(j);
653 *rasterfile << ((fabs(tmp) < MYEPSILON) ? 0 : tmp) << " ";
654 }
655 *rasterfile << "\t0.1\t1. 1. 1." << endl; // radius 0.05 and white as colour
656 cloud->GoToNext();
657 }
658
659 *rasterfile << "# All tesselation triangles" << endl;
660 *rasterfile << "8\n 25. -1. 1. 1. 1. 0.0 0 0 0 2\n SOLID 1.0 0.0 0.0\n BACKFACE 0.3 0.3 1.0 0 0\n";
661 for (TriangleMap::const_iterator TriangleRunner = Tess->TrianglesOnBoundary.begin(); TriangleRunner != Tess->TrianglesOnBoundary.end(); TriangleRunner++) {
662 *rasterfile << "1" << endl << " "; // 1 is triangle type
663 for (i=0;i<3;i++) { // print each node
664 for (int j=0;j<NDIM;j++) { // and for each node all NDIM coordinates
665 const double tmp = TriangleRunner->second->endpoints[i]->node->at(j)-center->at(j);
666 *rasterfile << ((fabs(tmp) < MYEPSILON) ? 0 : tmp) << " ";
667 }
668 *rasterfile << "\t";
669 }
670 *rasterfile << "1. 0. 0." << endl; // red as colour
671 //*rasterfile << "18" << endl << " 0.5 0.5 0.5" << endl; // 18 is transparency type for previous object
672 }
673 *rasterfile << "9\n# terminating special property\n";
674 } else {
675 DoeLog(1) && (eLog()<< Verbose(1) << "Given rasterfile is " << rasterfile << "." << endl);
676 }
677 IncludeSphereinRaster3D(rasterfile, Tess, cloud);
678 delete(center);
679};
680
681/** This function creates the tecplot file, displaying the tesselation of the hull.
682 * \param *out output stream for debugging
683 * \param *tecplot output stream for tecplot data
684 * \param N arbitrary number to differentiate various zones in the tecplot format
685 */
686void WriteTecplotFile(ofstream * const tecplot, const Tesselation * const TesselStruct, const PointCloud * const cloud, const int N)
687{
688 Info FunctionInfo(__func__);
689 if ((tecplot != NULL) && (TesselStruct != NULL)) {
690 // write header
691 *tecplot << "TITLE = \"3D CONVEX SHELL\"" << endl;
692 *tecplot << "VARIABLES = \"X\" \"Y\" \"Z\" \"U\"" << endl;
693 *tecplot << "ZONE T=\"";
694 if (N < 0) {
695 *tecplot << cloud->GetName();
696 } else {
697 *tecplot << N << "-";
698 if (TesselStruct->LastTriangle != NULL) {
699 for (int i=0;i<3;i++)
700 *tecplot << (i==0 ? "" : "_") << TesselStruct->LastTriangle->endpoints[i]->node->getName();
701 } else {
702 *tecplot << "none";
703 }
704 }
705 *tecplot << "\", N=" << TesselStruct->PointsOnBoundary.size() << ", E=" << TesselStruct->TrianglesOnBoundary.size() << ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE" << endl;
706 const int MaxId=cloud->GetMaxId();
707 int *LookupList = new int[MaxId];
708 for (int i=0; i< MaxId ; i++){
709 LookupList[i] = -1;
710 }
711
712 // print atom coordinates
713 int Counter = 1;
714 TesselPoint *Walker = NULL;
715 for (PointMap::const_iterator target = TesselStruct->PointsOnBoundary.begin(); target != TesselStruct->PointsOnBoundary.end(); ++target) {
716 Walker = target->second->node;
717 LookupList[Walker->nr] = Counter++;
718 for (int i=0;i<NDIM;i++) {
719 const double tmp = Walker->at(i);
720 *tecplot << ((fabs(tmp) < MYEPSILON) ? 0 : tmp) << " ";
721 }
722 *tecplot << target->second->value << endl;
723 }
724 *tecplot << endl;
725 // print connectivity
726 DoLog(1) && (Log() << Verbose(1) << "The following triangles were created:" << endl);
727 for (TriangleMap::const_iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) {
728 DoLog(1) && (Log() << Verbose(1) << " " << runner->second->endpoints[0]->node->getName() << "<->" << runner->second->endpoints[1]->node->getName() << "<->" << runner->second->endpoints[2]->node->getName() << endl);
729 *tecplot << LookupList[runner->second->endpoints[0]->node->nr] << " " << LookupList[runner->second->endpoints[1]->node->nr] << " " << LookupList[runner->second->endpoints[2]->node->nr] << endl;
730 }
731 delete[] (LookupList);
732 }
733};
734
735/** Calculates the concavity for each of the BoundaryPointSet's in a Tesselation.
736 * Sets BoundaryPointSet::value equal to the number of connected lines that are not convex.
737 * \param *out output stream for debugging
738 * \param *TesselStruct pointer to Tesselation structure
739 */
740void CalculateConcavityPerBoundaryPoint(const Tesselation * const TesselStruct)
741{
742 Info FunctionInfo(__func__);
743 class BoundaryPointSet *point = NULL;
744 class BoundaryLineSet *line = NULL;
745 class BoundaryTriangleSet *triangle = NULL;
746 double ConcavityPerLine = 0.;
747 double ConcavityPerTriangle = 0.;
748 double area = 0.;
749 double totalarea = 0.;
750
751 for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
752 point = PointRunner->second;
753 DoLog(1) && (Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl);
754
755 // calculate mean concavity over all connected line
756 ConcavityPerLine = 0.;
757 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
758 line = LineRunner->second;
759 //Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
760 ConcavityPerLine -= line->CalculateConvexity();
761 }
762 ConcavityPerLine /= point->lines.size();
763
764 // weigh with total area of the surrounding triangles
765 totalarea = 0.;
766 TriangleSet *triangles = TesselStruct->GetAllTriangles(PointRunner->second);
767 for (TriangleSet::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); ++TriangleRunner) {
768 totalarea += CalculateAreaofGeneralTriangle((*TriangleRunner)->endpoints[0]->node->getPosition() , (*TriangleRunner)->endpoints[1]->node->getPosition() , (*TriangleRunner)->endpoints[2]->node->getPosition());
769 }
770 ConcavityPerLine *= totalarea;
771
772 // calculate mean concavity over all attached triangles
773 ConcavityPerTriangle = 0.;
774 for (TriangleSet::const_iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); ++TriangleRunner) {
775 line = (*TriangleRunner)->GetThirdLine(PointRunner->second);
776 triangle = line->GetOtherTriangle(*TriangleRunner);
777 area = CalculateAreaofGeneralTriangle(triangle->endpoints[0]->node->getPosition() , triangle->endpoints[1]->node->getPosition() , triangle->endpoints[2]->node->getPosition());
778 area += CalculateAreaofGeneralTriangle((*TriangleRunner)->endpoints[0]->node->getPosition() , (*TriangleRunner)->endpoints[1]->node->getPosition() , (*TriangleRunner)->endpoints[2]->node->getPosition());
779 area *= -line->CalculateConvexity();
780 if (area > 0)
781 ConcavityPerTriangle += area;
782// else
783// ConcavityPerTriangle -= area;
784 }
785 ConcavityPerTriangle /= triangles->size()/totalarea;
786 delete(triangles);
787
788 // add up
789 point->value = ConcavityPerLine + ConcavityPerTriangle;
790 }
791};
792
793
794
795/** Calculates the concavity for each of the BoundaryPointSet's in a Tesselation.
796 * Sets BoundaryPointSet::value equal to the nearest distance to convex envelope.
797 * \param *out output stream for debugging
798 * \param *TesselStruct pointer to Tesselation structure
799 * \param *Convex pointer to convex Tesselation structure as reference
800 */
801void CalculateConstrictionPerBoundaryPoint(const Tesselation * const TesselStruct, const Tesselation * const Convex)
802{
803 Info FunctionInfo(__func__);
804 double distance = 0.;
805
806 for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
807 DoeLog(1) && (eLog() << Verbose(1) << "INFO: Current point is " << * PointRunner->second << "." << endl);
808
809 distance = 0.;
810 for (TriangleMap::const_iterator TriangleRunner = Convex->TrianglesOnBoundary.begin(); TriangleRunner != Convex->TrianglesOnBoundary.end(); TriangleRunner++) {
811 const double CurrentDistance = Convex->GetDistanceSquaredToTriangle(PointRunner->second->node->getPosition() , TriangleRunner->second);
812 if (CurrentDistance < distance)
813 distance = CurrentDistance;
814 }
815
816 PointRunner->second->value = distance;
817 }
818};
819
820/** Checks whether each BoundaryLineSet in the Tesselation has two triangles.
821 * \param *out output stream for debugging
822 * \param *TesselStruct
823 * \return true - all have exactly two triangles, false - some not, list is printed to screen
824 */
825bool CheckListOfBaselines(const Tesselation * const TesselStruct)
826{
827 Info FunctionInfo(__func__);
828 LineMap::const_iterator testline;
829 bool result = false;
830 int counter = 0;
831
832 DoLog(1) && (Log() << Verbose(1) << "Check: List of Baselines with not two connected triangles:" << endl);
833 for (testline = TesselStruct->LinesOnBoundary.begin(); testline != TesselStruct->LinesOnBoundary.end(); testline++) {
834 if (testline->second->triangles.size() != 2) {
835 DoLog(2) && (Log() << Verbose(2) << *testline->second << "\t" << testline->second->triangles.size() << endl);
836 counter++;
837 }
838 }
839 if (counter == 0) {
840 DoLog(1) && (Log() << Verbose(1) << "None." << endl);
841 result = true;
842 }
843 return result;
844}
845
846/** Counts the number of triangle pairs that contain the given polygon.
847 * \param *P polygon with endpoints to look for
848 * \param *T set of triangles to create pairs from containing \a *P
849 */
850int CountTrianglePairContainingPolygon(const BoundaryPolygonSet * const P, const TriangleSet * const T)
851{
852 Info FunctionInfo(__func__);
853 // check number of endpoints in *P
854 if (P->endpoints.size() != 4) {
855 DoeLog(1) && (eLog()<< Verbose(1) << "CountTrianglePairContainingPolygon works only on polygons with 4 nodes!" << endl);
856 return 0;
857 }
858
859 // check number of triangles in *T
860 if (T->size() < 2) {
861 DoeLog(1) && (eLog()<< Verbose(1) << "Not enough triangles to have pairs!" << endl);
862 return 0;
863 }
864
865 DoLog(0) && (Log() << Verbose(0) << "Polygon is " << *P << endl);
866 // create each pair, get the endpoints and check whether *P is contained.
867 int counter = 0;
868 PointSet Trianglenodes;
869 class BoundaryPolygonSet PairTrianglenodes;
870 for(TriangleSet::iterator Walker = T->begin(); Walker != T->end(); Walker++) {
871 for (int i=0;i<3;i++)
872 Trianglenodes.insert((*Walker)->endpoints[i]);
873
874 for(TriangleSet::iterator PairWalker = Walker; PairWalker != T->end(); PairWalker++) {
875 if (Walker != PairWalker) { // skip first
876 PairTrianglenodes.endpoints = Trianglenodes;
877 for (int i=0;i<3;i++)
878 PairTrianglenodes.endpoints.insert((*PairWalker)->endpoints[i]);
879 const int size = PairTrianglenodes.endpoints.size();
880 if (size == 4) {
881 DoLog(0) && (Log() << Verbose(0) << " Current pair of triangles: " << **Walker << "," << **PairWalker << " with " << size << " distinct endpoints:" << PairTrianglenodes << endl);
882 // now check
883 if (PairTrianglenodes.ContainsPresentTupel(P)) {
884 counter++;
885 DoLog(0) && (Log() << Verbose(0) << " ACCEPT: Matches with " << *P << endl);
886 } else {
887 DoLog(0) && (Log() << Verbose(0) << " REJECT: No match with " << *P << endl);
888 }
889 } else {
890 DoLog(0) && (Log() << Verbose(0) << " REJECT: Less than four endpoints." << endl);
891 }
892 }
893 }
894 Trianglenodes.clear();
895 }
896 return counter;
897};
898
899/** Checks whether two give polygons have two or more points in common.
900 * \param *P1 first polygon
901 * \param *P2 second polygon
902 * \return true - are connected, false = are note
903 */
904bool ArePolygonsEdgeConnected(const BoundaryPolygonSet * const P1, const BoundaryPolygonSet * const P2)
905{
906 Info FunctionInfo(__func__);
907 int counter = 0;
908 for(PointSet::const_iterator Runner = P1->endpoints.begin(); Runner != P1->endpoints.end(); Runner++) {
909 if (P2->ContainsBoundaryPoint((*Runner))) {
910 counter++;
911 DoLog(1) && (Log() << Verbose(1) << *(*Runner) << " of second polygon is found in the first one." << endl);
912 return true;
913 }
914 }
915 return false;
916};
917
918/** Combines second into the first and deletes the second.
919 * \param *P1 first polygon, contains all nodes on return
920 * \param *&P2 second polygon, is deleted.
921 */
922void CombinePolygons(BoundaryPolygonSet * const P1, BoundaryPolygonSet * &P2)
923{
924 Info FunctionInfo(__func__);
925 pair <PointSet::iterator, bool> Tester;
926 for(PointSet::iterator Runner = P2->endpoints.begin(); Runner != P2->endpoints.end(); Runner++) {
927 Tester = P1->endpoints.insert((*Runner));
928 if (Tester.second)
929 DoLog(0) && (Log() << Verbose(0) << "Inserting endpoint " << *(*Runner) << " into first polygon." << endl);
930 }
931 P2->endpoints.clear();
932 delete(P2);
933};
934
Note: See TracBrowser for help on using the repository browser.