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