source: src/tesselationhelpers.cpp@ bf3817

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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