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