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