source: src/tesselationhelpers.cpp@ 76c0d6

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 76c0d6 was 76c0d6, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'StructureRefactoring' into stable

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/periodentafel.cpp

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