source: src/tesselationhelpers.cpp@ c6efc1

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

Declared the Vector class as single point spaces

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