source: src/tesselationhelpers.cpp@ bbbad5

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

converted #define's to enums, consts and typedefs [Meyers, "Effective C++", item 1].

basic changes:

  • #define bla 1.3 -> const double bla = 1.3
  • #define bla "test" -> const char * const bla = "test
  • use class specific constants! (HULLEPSILON)

const int Class::bla = 1.3; (in .cpp)
static const int bla; (in .hpp inside class private section)

  • "enum hack": #define bla 5 -> enum { bla = 5 };
    • if const int bla=5; impossible
    • e.g. necessary if constant is used in array declaration (int blabla[bla];)

details:

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