| [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 |  * tesselation.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 | 
 | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 36 | 
 | 
|---|
| [f66195] | 37 | #include <fstream>
 | 
|---|
| [36166d] | 38 | #include <iomanip>
 | 
|---|
| [47d041] | 39 | #include <sstream>
 | 
|---|
| [f66195] | 40 | 
 | 
|---|
| [53c7fc] | 41 | #include "tesselation.hpp"
 | 
|---|
 | 42 | 
 | 
|---|
| [d74077] | 43 | #include "BoundaryPointSet.hpp"
 | 
|---|
 | 44 | #include "BoundaryLineSet.hpp"
 | 
|---|
 | 45 | #include "BoundaryTriangleSet.hpp"
 | 
|---|
 | 46 | #include "BoundaryPolygonSet.hpp"
 | 
|---|
 | 47 | #include "CandidateForTesselation.hpp"
 | 
|---|
| [34c43a] | 48 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 49 | #include "CodePatterns/Info.hpp"
 | 
|---|
 | 50 | #include "CodePatterns/IteratorAdaptors.hpp"
 | 
|---|
| [ad011c] | 51 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [34c43a] | 52 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
 | 53 | #include "Helpers/helpers.hpp"
 | 
|---|
| [783e88] | 54 | #include "LinearAlgebra/Exceptions.hpp"
 | 
|---|
| [57f243] | 55 | #include "LinearAlgebra/Line.hpp"
 | 
|---|
 | 56 | #include "LinearAlgebra/Plane.hpp"
 | 
|---|
| [783e88] | 57 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 58 | #include "LinearAlgebra/vector_ops.hpp"
 | 
|---|
| [53c7fc] | 59 | #include "LinkedCell/IPointCloud.hpp"
 | 
|---|
 | 60 | #include "LinkedCell/linkedcell.hpp"
 | 
|---|
 | 61 | #include "LinkedCell/PointCloudAdaptor.hpp"
 | 
|---|
| [34c43a] | 62 | #include "tesselationhelpers.hpp"
 | 
|---|
| [6f0841] | 63 | #include "Atom/TesselPoint.hpp"
 | 
|---|
| [34c43a] | 64 | #include "triangleintersectionlist.hpp"
 | 
|---|
| [a0064e] | 65 | 
 | 
|---|
| [57066a] | 66 | class molecule;
 | 
|---|
| [357fba] | 67 | 
 | 
|---|
| [88b400] | 68 | const char *TecplotSuffix=".dat";
 | 
|---|
 | 69 | const char *Raster3DSuffix=".r3d";
 | 
|---|
 | 70 | const char *VRMLSUffix=".wrl";
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | const double ParallelEpsilon=1e-3;
 | 
|---|
 | 73 | const double Tesselation::HULLEPSILON = 1e-9;
 | 
|---|
 | 74 | 
 | 
|---|
| [357fba] | 75 | /** Constructor of class Tesselation.
 | 
|---|
 | 76 |  */
 | 
|---|
| [1e168b] | 77 | Tesselation::Tesselation() :
 | 
|---|
| [97b825] | 78 |   PointsOnBoundaryCount(0),
 | 
|---|
 | 79 |   LinesOnBoundaryCount(0),
 | 
|---|
 | 80 |   TrianglesOnBoundaryCount(0),
 | 
|---|
 | 81 |   LastTriangle(NULL),
 | 
|---|
 | 82 |   TriangleFilesWritten(0),
 | 
|---|
 | 83 |   InternalPointer(PointsOnBoundary.begin())
 | 
|---|
| [357fba] | 84 | {
 | 
|---|
| [ce7bfd] | 85 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 86 | }
 | 
|---|
 | 87 | ;
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 | /** Destructor of class Tesselation.
 | 
|---|
 | 90 |  * We have to free all points, lines and triangles.
 | 
|---|
 | 91 |  */
 | 
|---|
 | 92 | Tesselation::~Tesselation()
 | 
|---|
 | 93 | {
 | 
|---|
| [ce7bfd] | 94 |   //Info FunctionInfo(__func__);
 | 
|---|
 | 95 |   LOG(2, "INFO: Free'ing TesselStruct ... ");
 | 
|---|
| [357fba] | 96 |   for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
 | 
|---|
 | 97 |     if (runner->second != NULL) {
 | 
|---|
 | 98 |       delete (runner->second);
 | 
|---|
 | 99 |       runner->second = NULL;
 | 
|---|
 | 100 |     } else
 | 
|---|
| [47d041] | 101 |       ELOG(1, "The triangle " << runner->first << " has already been free'd.");
 | 
|---|
| [357fba] | 102 |   }
 | 
|---|
| [ce7bfd] | 103 |   LOG(1, "INFO: This envelope was written to file " << TriangleFilesWritten << " times(s).");
 | 
|---|
| [357fba] | 104 | }
 | 
|---|
| [5c7bf8] | 105 | 
 | 
|---|
| [cc21cd] | 106 | /** Performs tesselation of a given point \a cloud with rolling sphere of
 | 
|---|
 | 107 |  * \a SPHERERADIUS.
 | 
|---|
 | 108 |  *
 | 
|---|
 | 109 |  * @param cloud point cloud to tesselate
 | 
|---|
 | 110 |  * @param SPHERERADIUS radius of the rolling sphere
 | 
|---|
 | 111 |  */
 | 
|---|
 | 112 | void Tesselation::operator()(IPointCloud & cloud, const double SPHERERADIUS)
 | 
|---|
 | 113 | {
 | 
|---|
 | 114 |   // create linkedcell
 | 
|---|
 | 115 |         LinkedCell_deprecated *LinkedList = new LinkedCell_deprecated(cloud, 2.*SPHERERADIUS);
 | 
|---|
 | 116 | 
 | 
|---|
 | 117 |   FindStartingTriangle(SPHERERADIUS, LinkedList);
 | 
|---|
 | 118 | 
 | 
|---|
 | 119 |   CandidateForTesselation *baseline = NULL;
 | 
|---|
 | 120 |   BoundaryTriangleSet *T = NULL;
 | 
|---|
 | 121 |   bool OneLoopWithoutSuccessFlag = true;
 | 
|---|
 | 122 |   bool TesselationFailFlag = false;
 | 
|---|
 | 123 |   while ((!OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
 | 
|---|
 | 124 |     // 2a. fill all new OpenLines
 | 
|---|
 | 125 |     for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
 | 
|---|
 | 126 |       baseline = Runner->second;
 | 
|---|
 | 127 |       if (baseline->pointlist.empty()) {
 | 
|---|
 | 128 |         T = (((baseline->BaseLine->triangles.begin()))->second);
 | 
|---|
 | 129 |         //the line is there, so there is a triangle, but only one.
 | 
|---|
 | 130 |         TesselationFailFlag = FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList);
 | 
|---|
 | 131 |       }
 | 
|---|
 | 132 |     }
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 |     // 2b. search for smallest ShortestAngle among all candidates
 | 
|---|
 | 135 |     double ShortestAngle = 4.*M_PI;
 | 
|---|
 | 136 |     for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
 | 
|---|
 | 137 |       if (Runner->second->ShortestAngle < ShortestAngle) {
 | 
|---|
 | 138 |         baseline = Runner->second;
 | 
|---|
 | 139 |         ShortestAngle = baseline->ShortestAngle;
 | 
|---|
 | 140 |       }
 | 
|---|
 | 141 |     }
 | 
|---|
 | 142 |     if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
 | 
|---|
 | 143 |       OneLoopWithoutSuccessFlag = false;
 | 
|---|
 | 144 |     else {
 | 
|---|
 | 145 |       AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
 | 
|---|
 | 146 |     }
 | 
|---|
 | 147 |   }
 | 
|---|
 | 148 | }
 | 
|---|
 | 149 | 
 | 
|---|
| [ee0032] | 150 | /** Determines the volume of a tesselated convex envelope.
 | 
|---|
 | 151 |  *
 | 
|---|
 | 152 |  * @param IsAngstroem unit of length is angstroem or bohr radii
 | 
|---|
 | 153 |  * \return determined volume of envelope assumed being convex
 | 
|---|
 | 154 |  */
 | 
|---|
 | 155 | double Tesselation::getVolumeOfConvexEnvelope(const bool IsAngstroem) const
 | 
|---|
 | 156 | {
 | 
|---|
 | 157 |   double volume = 0.;
 | 
|---|
 | 158 |   Vector x;
 | 
|---|
 | 159 |   Vector y;
 | 
|---|
 | 160 | 
 | 
|---|
 | 161 |   // 6a. Every triangle forms a pyramid with the center of gravity as its peak, sum up the volumes
 | 
|---|
 | 162 |   for (TriangleMap::const_iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++)
 | 
|---|
 | 163 |     { // go through every triangle, calculate volume of its pyramid with CoG as peak
 | 
|---|
 | 164 |       x = runner->second->getEndpoint(0) - runner->second->getEndpoint(1);
 | 
|---|
 | 165 |       const double G = runner->second->getArea();
 | 
|---|
 | 166 |       x = runner->second->getPlane().getNormal();
 | 
|---|
 | 167 |       x.Scale(runner->second->getEndpoint(1).ScalarProduct(x));
 | 
|---|
 | 168 |       const double h = x.Norm(); // distance of CoG to triangle
 | 
|---|
 | 169 |       const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
 | 
|---|
 | 170 |       LOG(1, "INFO: Area of triangle is " << setprecision(10) << G << " "
 | 
|---|
 | 171 |           << (IsAngstroem ? "angstrom" : "atomiclength") << "^2, height is "
 | 
|---|
 | 172 |           << h << " and the volume is " << PyramidVolume << " "
 | 
|---|
 | 173 |           << (IsAngstroem ? "angstrom" : "atomiclength") << "^3.");
 | 
|---|
 | 174 |       volume += PyramidVolume;
 | 
|---|
 | 175 |     }
 | 
|---|
 | 176 |   LOG(0, "RESULT: The summed volume is " << setprecision(6)
 | 
|---|
 | 177 |       << volume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3.");
 | 
|---|
 | 178 | 
 | 
|---|
 | 179 |   return volume;
 | 
|---|
 | 180 | }
 | 
|---|
 | 181 | 
 | 
|---|
| [bdf6c8] | 182 | /** Determines the area of a tesselated envelope.
 | 
|---|
 | 183 |  *
 | 
|---|
 | 184 |  * @param IsAngstroem unit of length is angstroem or bohr radii
 | 
|---|
 | 185 |  * \return determined surface area of the envelope
 | 
|---|
 | 186 |  */
 | 
|---|
 | 187 | double Tesselation::getAreaOfEnvelope(const bool IsAngstroem) const
 | 
|---|
 | 188 | {
 | 
|---|
 | 189 |   double surfacearea = 0.;
 | 
|---|
 | 190 |   Vector x;
 | 
|---|
 | 191 |   Vector y;
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 |   // 6a. Every triangle forms a pyramid with the center of gravity as its peak, sum up the volumes
 | 
|---|
 | 194 |   for (TriangleMap::const_iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++)
 | 
|---|
 | 195 |     { // go through every triangle, calculate volume of its pyramid with CoG as peak
 | 
|---|
 | 196 |                 const double area = runner->second->getArea();
 | 
|---|
 | 197 |                 LOG(1, "INFO: Area of triangle is " << setprecision(10) << area << " "
 | 
|---|
 | 198 |           << (IsAngstroem ? "angstrom" : "atomiclength") << "^2.");
 | 
|---|
 | 199 |       surfacearea += area;
 | 
|---|
 | 200 |     }
 | 
|---|
 | 201 |   LOG(0, "RESULT: The summed surface area is " << setprecision(6)
 | 
|---|
 | 202 |       << surfacearea << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3.");
 | 
|---|
 | 203 | 
 | 
|---|
 | 204 |   return surfacearea;
 | 
|---|
 | 205 | }
 | 
|---|
 | 206 | 
 | 
|---|
 | 207 | 
 | 
|---|
| [357fba] | 208 | /** Gueses first starting triangle of the convex envelope.
 | 
|---|
 | 209 |  * We guess the starting triangle by taking the smallest distance between two points and looking for a fitting third.
 | 
|---|
 | 210 |  * \param *out output stream for debugging
 | 
|---|
 | 211 |  * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
 | 
|---|
 | 212 |  */
 | 
|---|
| [244a84] | 213 | void Tesselation::GuessStartingTriangle()
 | 
|---|
| [357fba] | 214 | {
 | 
|---|
| [ce7bfd] | 215 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 216 |   // 4b. create a starting triangle
 | 
|---|
 | 217 |   // 4b1. create all distances
 | 
|---|
 | 218 |   DistanceMultiMap DistanceMMap;
 | 
|---|
 | 219 |   double distance, tmp;
 | 
|---|
 | 220 |   Vector PlaneVector, TrialVector;
 | 
|---|
 | 221 |   PointMap::iterator A, B, C; // three nodes of the first triangle
 | 
|---|
 | 222 |   A = PointsOnBoundary.begin(); // the first may be chosen arbitrarily
 | 
|---|
 | 223 | 
 | 
|---|
 | 224 |   // with A chosen, take each pair B,C and sort
 | 
|---|
| [6613ec] | 225 |   if (A != PointsOnBoundary.end()) {
 | 
|---|
 | 226 |     B = A;
 | 
|---|
 | 227 |     B++;
 | 
|---|
 | 228 |     for (; B != PointsOnBoundary.end(); B++) {
 | 
|---|
 | 229 |       C = B;
 | 
|---|
 | 230 |       C++;
 | 
|---|
 | 231 |       for (; C != PointsOnBoundary.end(); C++) {
 | 
|---|
| [d74077] | 232 |         tmp = A->second->node->DistanceSquared(B->second->node->getPosition());
 | 
|---|
| [6613ec] | 233 |         distance = tmp * tmp;
 | 
|---|
| [d74077] | 234 |         tmp = A->second->node->DistanceSquared(C->second->node->getPosition());
 | 
|---|
| [6613ec] | 235 |         distance += tmp * tmp;
 | 
|---|
| [d74077] | 236 |         tmp = B->second->node->DistanceSquared(C->second->node->getPosition());
 | 
|---|
| [6613ec] | 237 |         distance += tmp * tmp;
 | 
|---|
 | 238 |         DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
 | 
|---|
 | 239 |       }
 | 
|---|
| [357fba] | 240 |     }
 | 
|---|
| [6613ec] | 241 |   }
 | 
|---|
| [47d041] | 242 | //  // listing distances
 | 
|---|
 | 243 | //  if (DoLog(1)) {
 | 
|---|
 | 244 | //    std::stringstream output;
 | 
|---|
 | 245 | //    output << "Listing DistanceMMap:";
 | 
|---|
 | 246 | //    for(DistanceMultiMap::iterator runner = DistanceMMap.begin(); runner != DistanceMMap.end(); runner++) {
 | 
|---|
 | 247 | //      output << " " << runner->first << "(" << *runner->second.first->second << ", " << *runner->second.second->second << ")";
 | 
|---|
 | 248 | //    }
 | 
|---|
 | 249 | //    LOG(1, output.str());
 | 
|---|
 | 250 | //  }
 | 
|---|
| [357fba] | 251 |   // 4b2. pick three baselines forming a triangle
 | 
|---|
 | 252 |   // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
 | 
|---|
 | 253 |   DistanceMultiMap::iterator baseline = DistanceMMap.begin();
 | 
|---|
| [6613ec] | 254 |   for (; baseline != DistanceMMap.end(); baseline++) {
 | 
|---|
 | 255 |     // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
 | 
|---|
 | 256 |     // 2. next, we have to check whether all points reside on only one side of the triangle
 | 
|---|
 | 257 |     // 3. construct plane vector
 | 
|---|
| [d74077] | 258 |     PlaneVector = Plane(A->second->node->getPosition(),
 | 
|---|
 | 259 |                         baseline->second.first->second->node->getPosition(),
 | 
|---|
 | 260 |                         baseline->second.second->second->node->getPosition()).getNormal();
 | 
|---|
| [47d041] | 261 |     LOG(2, "Plane vector of candidate triangle is " << PlaneVector);
 | 
|---|
| [6613ec] | 262 |     // 4. loop over all points
 | 
|---|
 | 263 |     double sign = 0.;
 | 
|---|
 | 264 |     PointMap::iterator checker = PointsOnBoundary.begin();
 | 
|---|
 | 265 |     for (; checker != PointsOnBoundary.end(); checker++) {
 | 
|---|
 | 266 |       // (neglecting A,B,C)
 | 
|---|
 | 267 |       if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
 | 
|---|
 | 268 |         continue;
 | 
|---|
 | 269 |       // 4a. project onto plane vector
 | 
|---|
| [d74077] | 270 |       TrialVector = (checker->second->node->getPosition() - A->second->node->getPosition());
 | 
|---|
| [8cbb97] | 271 |       distance = TrialVector.ScalarProduct(PlaneVector);
 | 
|---|
| [6613ec] | 272 |       if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
 | 
|---|
 | 273 |         continue;
 | 
|---|
| [47d041] | 274 |       LOG(2, "Projection of " << checker->second->node->getName() << " yields distance of " << distance << ".");
 | 
|---|
| [6613ec] | 275 |       tmp = distance / fabs(distance);
 | 
|---|
 | 276 |       // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
 | 
|---|
 | 277 |       if ((sign != 0) && (tmp != sign)) {
 | 
|---|
 | 278 |         // 4c. If so, break 4. loop and continue with next candidate in 1. loop
 | 
|---|
| [47d041] | 279 |         LOG(2, "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leaves " << checker->second->node->getName() << " outside the convex hull.");
 | 
|---|
| [6613ec] | 280 |         break;
 | 
|---|
 | 281 |       } else { // note the sign for later
 | 
|---|
| [47d041] | 282 |         LOG(2, "Current candidates: " << A->second->node->getName() << "," << baseline->second.first->second->node->getName() << "," << baseline->second.second->second->node->getName() << " leave " << checker->second->node->getName() << " inside the convex hull.");
 | 
|---|
| [6613ec] | 283 |         sign = tmp;
 | 
|---|
 | 284 |       }
 | 
|---|
 | 285 |       // 4d. Check whether the point is inside the triangle (check distance to each node
 | 
|---|
| [d74077] | 286 |       tmp = checker->second->node->DistanceSquared(A->second->node->getPosition());
 | 
|---|
| [6613ec] | 287 |       int innerpoint = 0;
 | 
|---|
| [d74077] | 288 |       if ((tmp < A->second->node->DistanceSquared(baseline->second.first->second->node->getPosition())) && (tmp < A->second->node->DistanceSquared(baseline->second.second->second->node->getPosition())))
 | 
|---|
| [6613ec] | 289 |         innerpoint++;
 | 
|---|
| [d74077] | 290 |       tmp = checker->second->node->DistanceSquared(baseline->second.first->second->node->getPosition());
 | 
|---|
 | 291 |       if ((tmp < baseline->second.first->second->node->DistanceSquared(A->second->node->getPosition())) && (tmp < baseline->second.first->second->node->DistanceSquared(baseline->second.second->second->node->getPosition())))
 | 
|---|
| [6613ec] | 292 |         innerpoint++;
 | 
|---|
| [d74077] | 293 |       tmp = checker->second->node->DistanceSquared(baseline->second.second->second->node->getPosition());
 | 
|---|
 | 294 |       if ((tmp < baseline->second.second->second->node->DistanceSquared(baseline->second.first->second->node->getPosition())) && (tmp < baseline->second.second->second->node->DistanceSquared(A->second->node->getPosition())))
 | 
|---|
| [6613ec] | 295 |         innerpoint++;
 | 
|---|
 | 296 |       // 4e. If so, break 4. loop and continue with next candidate in 1. loop
 | 
|---|
 | 297 |       if (innerpoint == 3)
 | 
|---|
 | 298 |         break;
 | 
|---|
| [357fba] | 299 |     }
 | 
|---|
| [6613ec] | 300 |     // 5. come this far, all on same side? Then break 1. loop and construct triangle
 | 
|---|
 | 301 |     if (checker == PointsOnBoundary.end()) {
 | 
|---|
| [47d041] | 302 |       LOG(2, "Looks like we have a candidate!");
 | 
|---|
| [6613ec] | 303 |       break;
 | 
|---|
| [357fba] | 304 |     }
 | 
|---|
| [6613ec] | 305 |   }
 | 
|---|
 | 306 |   if (baseline != DistanceMMap.end()) {
 | 
|---|
 | 307 |     BPS[0] = baseline->second.first->second;
 | 
|---|
 | 308 |     BPS[1] = baseline->second.second->second;
 | 
|---|
 | 309 |     BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
 | 
|---|
 | 310 |     BPS[0] = A->second;
 | 
|---|
 | 311 |     BPS[1] = baseline->second.second->second;
 | 
|---|
 | 312 |     BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
 | 
|---|
 | 313 |     BPS[0] = baseline->second.first->second;
 | 
|---|
 | 314 |     BPS[1] = A->second;
 | 
|---|
 | 315 |     BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
 | 
|---|
 | 316 | 
 | 
|---|
 | 317 |     // 4b3. insert created triangle
 | 
|---|
 | 318 |     BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
 | 319 |     TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
 | 
|---|
 | 320 |     TrianglesOnBoundaryCount++;
 | 
|---|
 | 321 |     for (int i = 0; i < NDIM; i++) {
 | 
|---|
 | 322 |       LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
 | 
|---|
 | 323 |       LinesOnBoundaryCount++;
 | 
|---|
| [357fba] | 324 |     }
 | 
|---|
| [6613ec] | 325 | 
 | 
|---|
| [47d041] | 326 |     LOG(1, "Starting triangle is " << *BTS << ".");
 | 
|---|
| [6613ec] | 327 |   } else {
 | 
|---|
| [47d041] | 328 |     ELOG(0, "No starting triangle found.");
 | 
|---|
| [6613ec] | 329 |   }
 | 
|---|
| [357fba] | 330 | }
 | 
|---|
 | 331 | ;
 | 
|---|
 | 332 | 
 | 
|---|
 | 333 | /** Tesselates the convex envelope of a cluster from a single starting triangle.
 | 
|---|
 | 334 |  * The starting triangle is made out of three baselines. Each line in the final tesselated cluster may belong to at most
 | 
|---|
 | 335 |  * 2 triangles. Hence, we go through all current lines:
 | 
|---|
 | 336 |  * -# if the lines contains to only one triangle
 | 
|---|
 | 337 |  * -# We search all points in the boundary
 | 
|---|
 | 338 |  *    -# if the triangle is in forward direction of the baseline (at most 90 degrees angle between vector orthogonal to
 | 
|---|
 | 339 |  *       baseline in triangle plane pointing out of the triangle and normal vector of new triangle)
 | 
|---|
 | 340 |  *    -# if the triangle with the baseline and the current point has the smallest of angles (comparison between normal vectors)
 | 
|---|
 | 341 |  *    -# then we have a new triangle, whose baselines we again add (or increase their TriangleCount)
 | 
|---|
 | 342 |  * \param *out output stream for debugging
 | 
|---|
 | 343 |  * \param *configuration for IsAngstroem
 | 
|---|
 | 344 |  * \param *cloud cluster of points
 | 
|---|
 | 345 |  */
 | 
|---|
| [34c43a] | 346 | void Tesselation::TesselateOnBoundary(IPointCloud & cloud)
 | 
|---|
| [357fba] | 347 | {
 | 
|---|
| [ce7bfd] | 348 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 349 |   bool flag;
 | 
|---|
 | 350 |   PointMap::iterator winner;
 | 
|---|
 | 351 |   class BoundaryPointSet *peak = NULL;
 | 
|---|
 | 352 |   double SmallestAngle, TempAngle;
 | 
|---|
 | 353 |   Vector NormalVector, VirtualNormalVector, CenterVector, TempVector, helper, PropagationVector, *Center = NULL;
 | 
|---|
 | 354 |   LineMap::iterator LineChecker[2];
 | 
|---|
 | 355 | 
 | 
|---|
| [34c43a] | 356 |   Center = cloud.GetCenter();
 | 
|---|
| [357fba] | 357 |   // create a first tesselation with the given BoundaryPoints
 | 
|---|
 | 358 |   do {
 | 
|---|
 | 359 |     flag = false;
 | 
|---|
 | 360 |     for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++)
 | 
|---|
| [5c7bf8] | 361 |       if (baseline->second->triangles.size() == 1) {
 | 
|---|
| [357fba] | 362 |         // 5a. go through each boundary point if not _both_ edges between either endpoint of the current line and this point exist (and belong to 2 triangles)
 | 
|---|
 | 363 |         SmallestAngle = M_PI;
 | 
|---|
 | 364 | 
 | 
|---|
 | 365 |         // get peak point with respect to this base line's only triangle
 | 
|---|
 | 366 |         BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
 | 
|---|
| [ce7bfd] | 367 |         LOG(3, "DEBUG: Current baseline is between " << *(baseline->second) << ".");
 | 
|---|
| [357fba] | 368 |         for (int i = 0; i < 3; i++)
 | 
|---|
 | 369 |           if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
 | 
|---|
 | 370 |             peak = BTS->endpoints[i];
 | 
|---|
| [ce7bfd] | 371 |         LOG(3, "DEBUG:    and has peak " << *peak << ".");
 | 
|---|
| [357fba] | 372 | 
 | 
|---|
 | 373 |         // prepare some auxiliary vectors
 | 
|---|
 | 374 |         Vector BaseLineCenter, BaseLine;
 | 
|---|
| [d74077] | 375 |         BaseLineCenter = 0.5 * ((baseline->second->endpoints[0]->node->getPosition()) +
 | 
|---|
 | 376 |                                 (baseline->second->endpoints[1]->node->getPosition()));
 | 
|---|
 | 377 |         BaseLine = (baseline->second->endpoints[0]->node->getPosition()) - (baseline->second->endpoints[1]->node->getPosition());
 | 
|---|
| [357fba] | 378 | 
 | 
|---|
 | 379 |         // offset to center of triangle
 | 
|---|
 | 380 |         CenterVector.Zero();
 | 
|---|
 | 381 |         for (int i = 0; i < 3; i++)
 | 
|---|
| [8f215d] | 382 |           CenterVector += BTS->getEndpoint(i);
 | 
|---|
| [357fba] | 383 |         CenterVector.Scale(1. / 3.);
 | 
|---|
| [47d041] | 384 |         LOG(2, "CenterVector of base triangle is " << CenterVector);
 | 
|---|
| [357fba] | 385 | 
 | 
|---|
 | 386 |         // normal vector of triangle
 | 
|---|
| [273382] | 387 |         NormalVector = (*Center) - CenterVector;
 | 
|---|
| [357fba] | 388 |         BTS->GetNormalVector(NormalVector);
 | 
|---|
| [273382] | 389 |         NormalVector = BTS->NormalVector;
 | 
|---|
| [ce7bfd] | 390 |         LOG(4, "DEBUG: NormalVector of base triangle is " << NormalVector);
 | 
|---|
| [357fba] | 391 | 
 | 
|---|
 | 392 |         // vector in propagation direction (out of triangle)
 | 
|---|
 | 393 |         // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection)
 | 
|---|
| [0a4f7f] | 394 |         PropagationVector = Plane(BaseLine, NormalVector,0).getNormal();
 | 
|---|
| [d74077] | 395 |         TempVector = CenterVector - (baseline->second->endpoints[0]->node->getPosition()); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
 | 
|---|
| [47d041] | 396 |         //LOG(0, "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << ".");
 | 
|---|
| [273382] | 397 |         if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline
 | 
|---|
| [357fba] | 398 |           PropagationVector.Scale(-1.);
 | 
|---|
| [ce7bfd] | 399 |         LOG(4, "DEBUG: PropagationVector of base triangle is " << PropagationVector);
 | 
|---|
| [357fba] | 400 |         winner = PointsOnBoundary.end();
 | 
|---|
 | 401 | 
 | 
|---|
 | 402 |         // loop over all points and calculate angle between normal vector of new and present triangle
 | 
|---|
 | 403 |         for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
 | 
|---|
 | 404 |           if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
 | 
|---|
| [ce7bfd] | 405 |             LOG(4, "DEBUG: Target point is " << *(target->second) << ":");
 | 
|---|
| [357fba] | 406 | 
 | 
|---|
 | 407 |             // first check direction, so that triangles don't intersect
 | 
|---|
| [d74077] | 408 |             VirtualNormalVector = (target->second->node->getPosition()) - BaseLineCenter;
 | 
|---|
| [8cbb97] | 409 |             VirtualNormalVector.ProjectOntoPlane(NormalVector);
 | 
|---|
| [273382] | 410 |             TempAngle = VirtualNormalVector.Angle(PropagationVector);
 | 
|---|
| [ce7bfd] | 411 |             LOG(5, "DEBUG: VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << ".");
 | 
|---|
| [6613ec] | 412 |             if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
 | 
|---|
| [ce7bfd] | 413 |               LOG(5, "DEBUG: Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!");
 | 
|---|
| [357fba] | 414 |               continue;
 | 
|---|
 | 415 |             } else
 | 
|---|
| [ce7bfd] | 416 |               LOG(5, "DEBUG: Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!");
 | 
|---|
| [357fba] | 417 | 
 | 
|---|
 | 418 |             // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
 | 
|---|
 | 419 |             LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first);
 | 
|---|
 | 420 |             LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
 | 
|---|
| [5c7bf8] | 421 |             if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
 | 
|---|
| [ce7bfd] | 422 |               LOG(5, "DEBUG: " << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles.");
 | 
|---|
| [357fba] | 423 |               continue;
 | 
|---|
 | 424 |             }
 | 
|---|
| [5c7bf8] | 425 |             if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
 | 
|---|
| [ce7bfd] | 426 |               LOG(5, "DEBUG: " << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles.");
 | 
|---|
| [357fba] | 427 |               continue;
 | 
|---|
 | 428 |             }
 | 
|---|
 | 429 | 
 | 
|---|
 | 430 |             // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
 | 
|---|
 | 431 |             if ((((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (GetCommonEndpoint(LineChecker[0]->second, LineChecker[1]->second) == peak)))) {
 | 
|---|
| [ce7bfd] | 432 |               LOG(6, "DEBUG: Current target is peak!");
 | 
|---|
| [357fba] | 433 |               continue;
 | 
|---|
 | 434 |             }
 | 
|---|
 | 435 | 
 | 
|---|
 | 436 |             // check for linear dependence
 | 
|---|
| [d74077] | 437 |             TempVector = (baseline->second->endpoints[0]->node->getPosition()) - (target->second->node->getPosition());
 | 
|---|
 | 438 |             helper = (baseline->second->endpoints[1]->node->getPosition()) - (target->second->node->getPosition());
 | 
|---|
| [273382] | 439 |             helper.ProjectOntoPlane(TempVector);
 | 
|---|
| [357fba] | 440 |             if (fabs(helper.NormSquared()) < MYEPSILON) {
 | 
|---|
| [47d041] | 441 |               LOG(2, "Chosen set of vectors is linear dependent.");
 | 
|---|
| [357fba] | 442 |               continue;
 | 
|---|
 | 443 |             }
 | 
|---|
 | 444 | 
 | 
|---|
 | 445 |             // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle
 | 
|---|
 | 446 |             flag = true;
 | 
|---|
| [d74077] | 447 |             VirtualNormalVector = Plane((baseline->second->endpoints[0]->node->getPosition()),
 | 
|---|
 | 448 |                                         (baseline->second->endpoints[1]->node->getPosition()),
 | 
|---|
 | 449 |                                         (target->second->node->getPosition())).getNormal();
 | 
|---|
 | 450 |             TempVector = (1./3.) * ((baseline->second->endpoints[0]->node->getPosition()) +
 | 
|---|
 | 451 |                                     (baseline->second->endpoints[1]->node->getPosition()) +
 | 
|---|
 | 452 |                                     (target->second->node->getPosition()));
 | 
|---|
| [273382] | 453 |             TempVector -= (*Center);
 | 
|---|
| [357fba] | 454 |             // make it always point outward
 | 
|---|
| [273382] | 455 |             if (VirtualNormalVector.ScalarProduct(TempVector) < 0)
 | 
|---|
| [357fba] | 456 |               VirtualNormalVector.Scale(-1.);
 | 
|---|
 | 457 |             // calculate angle
 | 
|---|
| [273382] | 458 |             TempAngle = NormalVector.Angle(VirtualNormalVector);
 | 
|---|
| [ce7bfd] | 459 |             LOG(5, "DEBUG: NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << ".");
 | 
|---|
| [357fba] | 460 |             if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
 | 
|---|
 | 461 |               SmallestAngle = TempAngle;
 | 
|---|
 | 462 |               winner = target;
 | 
|---|
| [ce7bfd] | 463 |               LOG(5, "DEBUG: New winner " << *winner->second->node << " due to smaller angle between normal vectors.");
 | 
|---|
| [357fba] | 464 |             } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
 | 
|---|
 | 465 |               // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
 | 
|---|
| [d74077] | 466 |               helper = (target->second->node->getPosition()) - BaseLineCenter;
 | 
|---|
| [273382] | 467 |               helper.ProjectOntoPlane(BaseLine);
 | 
|---|
| [357fba] | 468 |               // ...the one with the smaller angle is the better candidate
 | 
|---|
| [d74077] | 469 |               TempVector = (target->second->node->getPosition()) - BaseLineCenter;
 | 
|---|
| [273382] | 470 |               TempVector.ProjectOntoPlane(VirtualNormalVector);
 | 
|---|
 | 471 |               TempAngle = TempVector.Angle(helper);
 | 
|---|
| [d74077] | 472 |               TempVector = (winner->second->node->getPosition()) - BaseLineCenter;
 | 
|---|
| [273382] | 473 |               TempVector.ProjectOntoPlane(VirtualNormalVector);
 | 
|---|
 | 474 |               if (TempAngle < TempVector.Angle(helper)) {
 | 
|---|
 | 475 |                 TempAngle = NormalVector.Angle(VirtualNormalVector);
 | 
|---|
| [357fba] | 476 |                 SmallestAngle = TempAngle;
 | 
|---|
 | 477 |                 winner = target;
 | 
|---|
| [ce7bfd] | 478 |                 LOG(5, "DEBUG: New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction.");
 | 
|---|
| [357fba] | 479 |               } else
 | 
|---|
| [ce7bfd] | 480 |                 LOG(5, "DEBUG: Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction.");
 | 
|---|
| [357fba] | 481 |             } else
 | 
|---|
| [ce7bfd] | 482 |               LOG(5, "DEBUG: Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors.");
 | 
|---|
| [357fba] | 483 |           }
 | 
|---|
 | 484 |         } // end of loop over all boundary points
 | 
|---|
 | 485 | 
 | 
|---|
 | 486 |         // 5b. The point of the above whose triangle has the greatest angle with the triangle the current line belongs to (it only belongs to one, remember!): New triangle
 | 
|---|
 | 487 |         if (winner != PointsOnBoundary.end()) {
 | 
|---|
| [ce7bfd] | 488 |           LOG(3, "DEBUG: Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << ".");
 | 
|---|
| [357fba] | 489 |           // create the lins of not yet present
 | 
|---|
 | 490 |           BLS[0] = baseline->second;
 | 
|---|
 | 491 |           // 5c. add lines to the line set if those were new (not yet part of a triangle), delete lines that belong to two triangles)
 | 
|---|
 | 492 |           LineChecker[0] = baseline->second->endpoints[0]->lines.find(winner->first);
 | 
|---|
 | 493 |           LineChecker[1] = baseline->second->endpoints[1]->lines.find(winner->first);
 | 
|---|
 | 494 |           if (LineChecker[0] == baseline->second->endpoints[0]->lines.end()) { // create
 | 
|---|
 | 495 |             BPS[0] = baseline->second->endpoints[0];
 | 
|---|
 | 496 |             BPS[1] = winner->second;
 | 
|---|
 | 497 |             BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
 | 
|---|
 | 498 |             LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[1]));
 | 
|---|
 | 499 |             LinesOnBoundaryCount++;
 | 
|---|
 | 500 |           } else
 | 
|---|
 | 501 |             BLS[1] = LineChecker[0]->second;
 | 
|---|
 | 502 |           if (LineChecker[1] == baseline->second->endpoints[1]->lines.end()) { // create
 | 
|---|
 | 503 |             BPS[0] = baseline->second->endpoints[1];
 | 
|---|
 | 504 |             BPS[1] = winner->second;
 | 
|---|
 | 505 |             BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
 | 
|---|
 | 506 |             LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[2]));
 | 
|---|
 | 507 |             LinesOnBoundaryCount++;
 | 
|---|
 | 508 |           } else
 | 
|---|
 | 509 |             BLS[2] = LineChecker[1]->second;
 | 
|---|
 | 510 |           BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
| [d74077] | 511 |           BTS->GetCenter(helper);
 | 
|---|
| [273382] | 512 |           helper -= (*Center);
 | 
|---|
 | 513 |           helper *= -1;
 | 
|---|
| [62bb91] | 514 |           BTS->GetNormalVector(helper);
 | 
|---|
| [357fba] | 515 |           TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
 | 
|---|
 | 516 |           TrianglesOnBoundaryCount++;
 | 
|---|
 | 517 |         } else {
 | 
|---|
| [47d041] | 518 |           ELOG(2, "I could not determine a winner for this baseline " << *(baseline->second) << ".");
 | 
|---|
| [357fba] | 519 |         }
 | 
|---|
 | 520 | 
 | 
|---|
 | 521 |         // 5d. If the set of lines is not yet empty, go to 5. and continue
 | 
|---|
 | 522 |       } else
 | 
|---|
| [ce7bfd] | 523 |         LOG(3, "DEBUG: Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << ".");
 | 
|---|
| [357fba] | 524 |   } while (flag);
 | 
|---|
 | 525 | 
 | 
|---|
 | 526 |   // exit
 | 
|---|
| [6613ec] | 527 |   delete (Center);
 | 
|---|
 | 528 | }
 | 
|---|
 | 529 | ;
 | 
|---|
| [357fba] | 530 | 
 | 
|---|
| [62bb91] | 531 | /** Inserts all points outside of the tesselated surface into it by adding new triangles.
 | 
|---|
| [357fba] | 532 |  * \param *out output stream for debugging
 | 
|---|
 | 533 |  * \param *cloud cluster of points
 | 
|---|
| [6bd7e0] | 534 |  * \param *LC LinkedCell_deprecated structure to find nearest point quickly
 | 
|---|
| [357fba] | 535 |  * \return true - all straddling points insert, false - something went wrong
 | 
|---|
 | 536 |  */
 | 
|---|
| [6bd7e0] | 537 | bool Tesselation::InsertStraddlingPoints(IPointCloud & cloud, const LinkedCell_deprecated *LC)
 | 
|---|
| [357fba] | 538 | {
 | 
|---|
| [ce7bfd] | 539 |   //Info FunctionInfo(__func__);
 | 
|---|
| [5c7bf8] | 540 |   Vector Intersection, Normal;
 | 
|---|
| [357fba] | 541 |   TesselPoint *Walker = NULL;
 | 
|---|
| [34c43a] | 542 |   Vector *Center = cloud.GetCenter();
 | 
|---|
| [c15ca2] | 543 |   TriangleList *triangles = NULL;
 | 
|---|
| [7dea7c] | 544 |   bool AddFlag = false;
 | 
|---|
| [6bd7e0] | 545 |   LinkedCell_deprecated *BoundaryPoints = NULL;
 | 
|---|
| [bdc91e] | 546 |   bool SuccessFlag = true;
 | 
|---|
| [62bb91] | 547 | 
 | 
|---|
| [34c43a] | 548 |   cloud.GoToFirst();
 | 
|---|
| [caa06ef] | 549 |   PointCloudAdaptor< Tesselation, MapValueIterator<Tesselation::iterator> > newcloud(this, cloud.GetName());
 | 
|---|
| [6bd7e0] | 550 |   BoundaryPoints = new LinkedCell_deprecated(newcloud, 5.);
 | 
|---|
| [34c43a] | 551 |   while (!cloud.IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
 | 
|---|
| [7dea7c] | 552 |     if (AddFlag) {
 | 
|---|
| [6613ec] | 553 |       delete (BoundaryPoints);
 | 
|---|
| [6bd7e0] | 554 |       BoundaryPoints = new LinkedCell_deprecated(newcloud, 5.);
 | 
|---|
| [7dea7c] | 555 |       AddFlag = false;
 | 
|---|
 | 556 |     }
 | 
|---|
| [34c43a] | 557 |     Walker = cloud.GetPoint();
 | 
|---|
| [ce7bfd] | 558 |     LOG(3, "DEBUG: Current point is " << *Walker << ".");
 | 
|---|
| [357fba] | 559 |     // get the next triangle
 | 
|---|
| [d74077] | 560 |     triangles = FindClosestTrianglesToVector(Walker->getPosition(), BoundaryPoints);
 | 
|---|
| [bdc91e] | 561 |     if (triangles != NULL)
 | 
|---|
 | 562 |       BTS = triangles->front();
 | 
|---|
 | 563 |     else
 | 
|---|
 | 564 |       BTS = NULL;
 | 
|---|
 | 565 |     delete triangles;
 | 
|---|
 | 566 |     if ((BTS == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
 | 
|---|
| [ce7bfd] | 567 |       LOG(3, "DEBUG: No triangles found, probably a tesselation point itself.");
 | 
|---|
| [34c43a] | 568 |       cloud.GoToNext();
 | 
|---|
| [62bb91] | 569 |       continue;
 | 
|---|
 | 570 |     } else {
 | 
|---|
| [357fba] | 571 |     }
 | 
|---|
| [ce7bfd] | 572 |     LOG(3, "DEBUG: Closest triangle is " << *BTS << ".");
 | 
|---|
| [357fba] | 573 |     // get the intersection point
 | 
|---|
| [d74077] | 574 |     if (BTS->GetIntersectionInsideTriangle(*Center, Walker->getPosition(), Intersection)) {
 | 
|---|
| [ce7bfd] | 575 |       LOG(3, "DEBUG: We have an intersection at " << Intersection << ".");
 | 
|---|
| [357fba] | 576 |       // we have the intersection, check whether in- or outside of boundary
 | 
|---|
| [d74077] | 577 |       if ((Center->DistanceSquared(Walker->getPosition()) - Center->DistanceSquared(Intersection)) < -MYEPSILON) {
 | 
|---|
| [357fba] | 578 |         // inside, next!
 | 
|---|
| [ce7bfd] | 579 |         LOG(3, "DEBUG: " << *Walker << " is inside wrt triangle " << *BTS << ".");
 | 
|---|
| [357fba] | 580 |       } else {
 | 
|---|
 | 581 |         // outside!
 | 
|---|
| [ce7bfd] | 582 |         LOG(3, "DEBUG: " << *Walker << " is outside wrt triangle " << *BTS << ".");
 | 
|---|
| [357fba] | 583 |         class BoundaryLineSet *OldLines[3], *NewLines[3];
 | 
|---|
 | 584 |         class BoundaryPointSet *OldPoints[3], *NewPoint;
 | 
|---|
 | 585 |         // store the three old lines and old points
 | 
|---|
| [6613ec] | 586 |         for (int i = 0; i < 3; i++) {
 | 
|---|
| [357fba] | 587 |           OldLines[i] = BTS->lines[i];
 | 
|---|
 | 588 |           OldPoints[i] = BTS->endpoints[i];
 | 
|---|
 | 589 |         }
 | 
|---|
| [273382] | 590 |         Normal = BTS->NormalVector;
 | 
|---|
| [357fba] | 591 |         // add Walker to boundary points
 | 
|---|
| [ce7bfd] | 592 |         LOG(3, "DEBUG: Adding " << *Walker << " to BoundaryPoints.");
 | 
|---|
| [7dea7c] | 593 |         AddFlag = true;
 | 
|---|
| [6613ec] | 594 |         if (AddBoundaryPoint(Walker, 0))
 | 
|---|
| [357fba] | 595 |           NewPoint = BPS[0];
 | 
|---|
 | 596 |         else
 | 
|---|
 | 597 |           continue;
 | 
|---|
 | 598 |         // remove triangle
 | 
|---|
| [ce7bfd] | 599 |         LOG(3, "DEBUG: Erasing triangle " << *BTS << ".");
 | 
|---|
| [357fba] | 600 |         TrianglesOnBoundary.erase(BTS->Nr);
 | 
|---|
| [6613ec] | 601 |         delete (BTS);
 | 
|---|
| [357fba] | 602 |         // create three new boundary lines
 | 
|---|
| [6613ec] | 603 |         for (int i = 0; i < 3; i++) {
 | 
|---|
| [357fba] | 604 |           BPS[0] = NewPoint;
 | 
|---|
 | 605 |           BPS[1] = OldPoints[i];
 | 
|---|
 | 606 |           NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
 | 
|---|
| [ce7bfd] | 607 |           LOG(4, "DEBUG: Creating new line " << *NewLines[i] << ".");
 | 
|---|
| [357fba] | 608 |           LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
 | 
|---|
 | 609 |           LinesOnBoundaryCount++;
 | 
|---|
 | 610 |         }
 | 
|---|
 | 611 |         // create three new triangle with new point
 | 
|---|
| [6613ec] | 612 |         for (int i = 0; i < 3; i++) { // find all baselines
 | 
|---|
| [357fba] | 613 |           BLS[0] = OldLines[i];
 | 
|---|
 | 614 |           int n = 1;
 | 
|---|
| [6613ec] | 615 |           for (int j = 0; j < 3; j++) {
 | 
|---|
| [357fba] | 616 |             if (NewLines[j]->IsConnectedTo(BLS[0])) {
 | 
|---|
| [6613ec] | 617 |               if (n > 2) {
 | 
|---|
| [47d041] | 618 |                 ELOG(2, BLS[0] << " connects to all of the new lines?!");
 | 
|---|
| [357fba] | 619 |                 return false;
 | 
|---|
 | 620 |               } else
 | 
|---|
 | 621 |                 BLS[n++] = NewLines[j];
 | 
|---|
 | 622 |             }
 | 
|---|
 | 623 |           }
 | 
|---|
 | 624 |           // create the triangle
 | 
|---|
 | 625 |           BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
| [5c7bf8] | 626 |           Normal.Scale(-1.);
 | 
|---|
 | 627 |           BTS->GetNormalVector(Normal);
 | 
|---|
 | 628 |           Normal.Scale(-1.);
 | 
|---|
| [ce7bfd] | 629 |           LOG(3, "DEBUG: Created new triangle " << *BTS << ".");
 | 
|---|
| [357fba] | 630 |           TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
 | 
|---|
 | 631 |           TrianglesOnBoundaryCount++;
 | 
|---|
 | 632 |         }
 | 
|---|
 | 633 |       }
 | 
|---|
 | 634 |     } else { // something is wrong with FindClosestTriangleToPoint!
 | 
|---|
| [47d041] | 635 |       ELOG(1, "The closest triangle did not produce an intersection!");
 | 
|---|
| [bdc91e] | 636 |       SuccessFlag = false;
 | 
|---|
 | 637 |       break;
 | 
|---|
| [357fba] | 638 |     }
 | 
|---|
| [34c43a] | 639 |     cloud.GoToNext();
 | 
|---|
| [357fba] | 640 |   }
 | 
|---|
 | 641 | 
 | 
|---|
 | 642 |   // exit
 | 
|---|
| [6613ec] | 643 |   delete (Center);
 | 
|---|
| [bdc91e] | 644 |   delete (BoundaryPoints);
 | 
|---|
 | 645 |   return SuccessFlag;
 | 
|---|
| [6613ec] | 646 | }
 | 
|---|
 | 647 | ;
 | 
|---|
| [357fba] | 648 | 
 | 
|---|
| [16d866] | 649 | /** Adds a point to the tesselation::PointsOnBoundary list.
 | 
|---|
| [62bb91] | 650 |  * \param *Walker point to add
 | 
|---|
| [08ef35] | 651 |  * \param n TesselStruct::BPS index to put pointer into
 | 
|---|
 | 652 |  * \return true - new point was added, false - point already present
 | 
|---|
| [357fba] | 653 |  */
 | 
|---|
| [776b64] | 654 | bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
 | 
|---|
| [357fba] | 655 | {
 | 
|---|
| [ce7bfd] | 656 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 657 |   PointTestPair InsertUnique;
 | 
|---|
| [08ef35] | 658 |   BPS[n] = new class BoundaryPointSet(Walker);
 | 
|---|
| [735b1c] | 659 |   InsertUnique = PointsOnBoundary.insert(PointPair(Walker->getNr(), BPS[n]));
 | 
|---|
| [08ef35] | 660 |   if (InsertUnique.second) { // if new point was not present before, increase counter
 | 
|---|
| [357fba] | 661 |     PointsOnBoundaryCount++;
 | 
|---|
| [08ef35] | 662 |     return true;
 | 
|---|
 | 663 |   } else {
 | 
|---|
| [6613ec] | 664 |     delete (BPS[n]);
 | 
|---|
| [08ef35] | 665 |     BPS[n] = InsertUnique.first->second;
 | 
|---|
 | 666 |     return false;
 | 
|---|
| [357fba] | 667 |   }
 | 
|---|
 | 668 | }
 | 
|---|
 | 669 | ;
 | 
|---|
 | 670 | 
 | 
|---|
 | 671 | /** Adds point to Tesselation::PointsOnBoundary if not yet present.
 | 
|---|
 | 672 |  * Tesselation::TPS is set to either this new BoundaryPointSet or to the existing one of not unique.
 | 
|---|
 | 673 |  * @param Candidate point to add
 | 
|---|
 | 674 |  * @param n index for this point in Tesselation::TPS array
 | 
|---|
 | 675 |  */
 | 
|---|
| [776b64] | 676 | void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
 | 
|---|
| [357fba] | 677 | {
 | 
|---|
| [ce7bfd] | 678 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 679 |   PointTestPair InsertUnique;
 | 
|---|
 | 680 |   TPS[n] = new class BoundaryPointSet(Candidate);
 | 
|---|
| [735b1c] | 681 |   InsertUnique = PointsOnBoundary.insert(PointPair(Candidate->getNr(), TPS[n]));
 | 
|---|
| [357fba] | 682 |   if (InsertUnique.second) { // if new point was not present before, increase counter
 | 
|---|
 | 683 |     PointsOnBoundaryCount++;
 | 
|---|
 | 684 |   } else {
 | 
|---|
 | 685 |     delete TPS[n];
 | 
|---|
| [ce7bfd] | 686 |     LOG(4, "DEBUG: Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary.");
 | 
|---|
| [357fba] | 687 |     TPS[n] = (InsertUnique.first)->second;
 | 
|---|
 | 688 |   }
 | 
|---|
 | 689 | }
 | 
|---|
 | 690 | ;
 | 
|---|
 | 691 | 
 | 
|---|
| [f1ef60a] | 692 | /** Sets point to a present Tesselation::PointsOnBoundary.
 | 
|---|
 | 693 |  * Tesselation::TPS is set to the existing one or NULL if not found.
 | 
|---|
 | 694 |  * @param Candidate point to set to
 | 
|---|
 | 695 |  * @param n index for this point in Tesselation::TPS array
 | 
|---|
 | 696 |  */
 | 
|---|
 | 697 | void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
 | 
|---|
 | 698 | {
 | 
|---|
| [ce7bfd] | 699 |   //Info FunctionInfo(__func__);
 | 
|---|
| [735b1c] | 700 |   PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->getNr());
 | 
|---|
| [f1ef60a] | 701 |   if (FindPoint != PointsOnBoundary.end())
 | 
|---|
 | 702 |     TPS[n] = FindPoint->second;
 | 
|---|
 | 703 |   else
 | 
|---|
 | 704 |     TPS[n] = NULL;
 | 
|---|
| [6613ec] | 705 | }
 | 
|---|
 | 706 | ;
 | 
|---|
| [f1ef60a] | 707 | 
 | 
|---|
| [357fba] | 708 | /** Function tries to add line from current Points in BPS to BoundaryLineSet.
 | 
|---|
 | 709 |  * If successful it raises the line count and inserts the new line into the BLS,
 | 
|---|
 | 710 |  * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
 | 
|---|
| [f07f86d] | 711 |  * @param *OptCenter desired OptCenter if there are more than one candidate line
 | 
|---|
| [d5fea7] | 712 |  * @param *candidate third point of the triangle to be, for checking between multiple open line candidates
 | 
|---|
| [357fba] | 713 |  * @param *a first endpoint
 | 
|---|
 | 714 |  * @param *b second endpoint
 | 
|---|
 | 715 |  * @param n index of Tesselation::BLS giving the line with both endpoints
 | 
|---|
 | 716 |  */
 | 
|---|
| [6613ec] | 717 | void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
 | 
|---|
 | 718 | {
 | 
|---|
| [357fba] | 719 |   bool insertNewLine = true;
 | 
|---|
| [735b1c] | 720 |   LineMap::iterator FindLine = a->lines.find(b->node->getNr());
 | 
|---|
| [d5fea7] | 721 |   BoundaryLineSet *WinningLine = NULL;
 | 
|---|
| [b998c3] | 722 |   if (FindLine != a->lines.end()) {
 | 
|---|
| [ce7bfd] | 723 |     LOG(3, "DEBUG: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << ".");
 | 
|---|
| [b998c3] | 724 | 
 | 
|---|
| [6613ec] | 725 |     pair<LineMap::iterator, LineMap::iterator> FindPair;
 | 
|---|
| [735b1c] | 726 |     FindPair = a->lines.equal_range(b->node->getNr());
 | 
|---|
| [357fba] | 727 | 
 | 
|---|
| [6613ec] | 728 |     for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
 | 
|---|
| [ce7bfd] | 729 |       LOG(3, "DEBUG: Checking line " << *(FindLine->second) << " ...");
 | 
|---|
| [357fba] | 730 |       // If there is a line with less than two attached triangles, we don't need a new line.
 | 
|---|
| [d5fea7] | 731 |       if (FindLine->second->triangles.size() == 1) {
 | 
|---|
 | 732 |         CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
 | 
|---|
| [f07f86d] | 733 |         if (!Finder->second->pointlist.empty())
 | 
|---|
| [ce7bfd] | 734 |           LOG(4, "DEBUG: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << ".");
 | 
|---|
| [f07f86d] | 735 |         else
 | 
|---|
| [ce7bfd] | 736 |           LOG(4, "DEBUG: line " << *(FindLine->second) << " is open with no candidate.");
 | 
|---|
| [f07f86d] | 737 |         // get open line
 | 
|---|
| [6613ec] | 738 |         for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
 | 
|---|
| [8cbb97] | 739 |           if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
 | 
|---|
| [ce7bfd] | 740 |             LOG(4, "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << ".");
 | 
|---|
| [6613ec] | 741 |             insertNewLine = false;
 | 
|---|
 | 742 |             WinningLine = FindLine->second;
 | 
|---|
 | 743 |             break;
 | 
|---|
| [b0a5f1] | 744 |           } else {
 | 
|---|
| [ce7bfd] | 745 |             LOG(5, "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << ".");
 | 
|---|
| [6613ec] | 746 |           }
 | 
|---|
| [856098] | 747 |         }
 | 
|---|
| [357fba] | 748 |       }
 | 
|---|
 | 749 |     }
 | 
|---|
 | 750 |   }
 | 
|---|
 | 751 | 
 | 
|---|
 | 752 |   if (insertNewLine) {
 | 
|---|
| [474961] | 753 |     AddNewTesselationTriangleLine(a, b, n);
 | 
|---|
| [d5fea7] | 754 |   } else {
 | 
|---|
 | 755 |     AddExistingTesselationTriangleLine(WinningLine, n);
 | 
|---|
| [357fba] | 756 |   }
 | 
|---|
 | 757 | }
 | 
|---|
 | 758 | ;
 | 
|---|
 | 759 | 
 | 
|---|
 | 760 | /**
 | 
|---|
 | 761 |  * Adds lines from each of the current points in the BPS to BoundaryLineSet.
 | 
|---|
 | 762 |  * Raises the line count and inserts the new line into the BLS.
 | 
|---|
 | 763 |  *
 | 
|---|
 | 764 |  * @param *a first endpoint
 | 
|---|
 | 765 |  * @param *b second endpoint
 | 
|---|
 | 766 |  * @param n index of Tesselation::BLS giving the line with both endpoints
 | 
|---|
 | 767 |  */
 | 
|---|
| [474961] | 768 | void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
 | 
|---|
| [357fba] | 769 | {
 | 
|---|
| [ce7bfd] | 770 |   //Info FunctionInfo(__func__);
 | 
|---|
 | 771 |   LOG(2, "DEBUG: Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << ".");
 | 
|---|
| [357fba] | 772 |   BPS[0] = a;
 | 
|---|
 | 773 |   BPS[1] = b;
 | 
|---|
| [6613ec] | 774 |   BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
 | 
|---|
| [357fba] | 775 |   // add line to global map
 | 
|---|
 | 776 |   LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
 | 
|---|
 | 777 |   // increase counter
 | 
|---|
 | 778 |   LinesOnBoundaryCount++;
 | 
|---|
| [1e168b] | 779 |   // also add to open lines
 | 
|---|
 | 780 |   CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
 | 
|---|
| [6613ec] | 781 |   OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
 | 
|---|
 | 782 | }
 | 
|---|
 | 783 | ;
 | 
|---|
| [357fba] | 784 | 
 | 
|---|
| [474961] | 785 | /** Uses an existing line for a new triangle.
 | 
|---|
 | 786 |  * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
 | 
|---|
 | 787 |  * \param *FindLine the line to add
 | 
|---|
 | 788 |  * \param n index of the line to set in Tesselation::BLS
 | 
|---|
 | 789 |  */
 | 
|---|
 | 790 | void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
 | 
|---|
 | 791 | {
 | 
|---|
| [ce7bfd] | 792 |   //Info FunctionInfo(__func__);
 | 
|---|
 | 793 |   LOG(5, "DEBUG: Using existing line " << *Line);
 | 
|---|
| [474961] | 794 | 
 | 
|---|
 | 795 |   // set endpoints and line
 | 
|---|
 | 796 |   BPS[0] = Line->endpoints[0];
 | 
|---|
 | 797 |   BPS[1] = Line->endpoints[1];
 | 
|---|
 | 798 |   BLS[n] = Line;
 | 
|---|
 | 799 |   // remove existing line from OpenLines
 | 
|---|
 | 800 |   CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
 | 
|---|
 | 801 |   if (CandidateLine != OpenLines.end()) {
 | 
|---|
| [ce7bfd] | 802 |     LOG(6, "DEBUG: Removing line from OpenLines.");
 | 
|---|
| [6613ec] | 803 |     delete (CandidateLine->second);
 | 
|---|
| [474961] | 804 |     OpenLines.erase(CandidateLine);
 | 
|---|
 | 805 |   } else {
 | 
|---|
| [47d041] | 806 |     ELOG(1, "Line exists and is attached to less than two triangles, but not in OpenLines!");
 | 
|---|
| [474961] | 807 |   }
 | 
|---|
| [6613ec] | 808 | }
 | 
|---|
 | 809 | ;
 | 
|---|
| [357fba] | 810 | 
 | 
|---|
| [7dea7c] | 811 | /** Function adds triangle to global list.
 | 
|---|
 | 812 |  * Furthermore, the triangle receives the next free id and id counter \a TrianglesOnBoundaryCount is increased.
 | 
|---|
| [357fba] | 813 |  */
 | 
|---|
| [16d866] | 814 | void Tesselation::AddTesselationTriangle()
 | 
|---|
| [357fba] | 815 | {
 | 
|---|
| [ce7bfd] | 816 |   //Info FunctionInfo(__func__);
 | 
|---|
 | 817 |   LOG(4, "DEBUG: Adding triangle to global TrianglesOnBoundary map.");
 | 
|---|
| [357fba] | 818 | 
 | 
|---|
 | 819 |   // add triangle to global map
 | 
|---|
 | 820 |   TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
 | 
|---|
 | 821 |   TrianglesOnBoundaryCount++;
 | 
|---|
 | 822 | 
 | 
|---|
| [57066a] | 823 |   // set as last new triangle
 | 
|---|
 | 824 |   LastTriangle = BTS;
 | 
|---|
 | 825 | 
 | 
|---|
| [357fba] | 826 |   // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
 | 
|---|
| [6613ec] | 827 | }
 | 
|---|
 | 828 | ;
 | 
|---|
| [16d866] | 829 | 
 | 
|---|
| [7dea7c] | 830 | /** Function adds triangle to global list.
 | 
|---|
| [5309ba] | 831 |  * Furthermore, the triangle number is set to \a Nr.
 | 
|---|
| [735b1c] | 832 |  * \param getNr() triangle number
 | 
|---|
| [7dea7c] | 833 |  */
 | 
|---|
| [776b64] | 834 | void Tesselation::AddTesselationTriangle(const int nr)
 | 
|---|
| [7dea7c] | 835 | {
 | 
|---|
| [ce7bfd] | 836 |   //Info FunctionInfo(__func__);
 | 
|---|
 | 837 |   LOG(4, "DEBUG: Adding triangle to global TrianglesOnBoundary map.");
 | 
|---|
| [7dea7c] | 838 | 
 | 
|---|
 | 839 |   // add triangle to global map
 | 
|---|
 | 840 |   TrianglesOnBoundary.insert(TrianglePair(nr, BTS));
 | 
|---|
 | 841 | 
 | 
|---|
 | 842 |   // set as last new triangle
 | 
|---|
 | 843 |   LastTriangle = BTS;
 | 
|---|
 | 844 | 
 | 
|---|
 | 845 |   // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
 | 
|---|
| [6613ec] | 846 | }
 | 
|---|
 | 847 | ;
 | 
|---|
| [7dea7c] | 848 | 
 | 
|---|
| [16d866] | 849 | /** Removes a triangle from the tesselation.
 | 
|---|
 | 850 |  * Removes itself from the TriangleMap's of its lines, calls for them RemoveTriangleLine() if they are no more connected.
 | 
|---|
 | 851 |  * Removes itself from memory.
 | 
|---|
 | 852 |  * \param *triangle to remove
 | 
|---|
 | 853 |  */
 | 
|---|
 | 854 | void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
 | 
|---|
 | 855 | {
 | 
|---|
| [ce7bfd] | 856 |   //Info FunctionInfo(__func__);
 | 
|---|
| [16d866] | 857 |   if (triangle == NULL)
 | 
|---|
 | 858 |     return;
 | 
|---|
 | 859 |   for (int i = 0; i < 3; i++) {
 | 
|---|
 | 860 |     if (triangle->lines[i] != NULL) {
 | 
|---|
| [ce7bfd] | 861 |       LOG(4, "DEBUG: Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << ".");
 | 
|---|
| [16d866] | 862 |       triangle->lines[i]->triangles.erase(triangle->Nr);
 | 
|---|
| [47d041] | 863 |       std::stringstream output;
 | 
|---|
| [ce7bfd] | 864 |       output << *triangle->lines[i] << " is ";
 | 
|---|
| [16d866] | 865 |       if (triangle->lines[i]->triangles.empty()) {
 | 
|---|
| [47d041] | 866 |         output << "no more attached to any triangle, erasing.";
 | 
|---|
| [6613ec] | 867 |         RemoveTesselationLine(triangle->lines[i]);
 | 
|---|
| [065e82] | 868 |       } else {
 | 
|---|
| [47d041] | 869 |         output << "still attached to another triangle: ";
 | 
|---|
| [6613ec] | 870 |         OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
 | 
|---|
 | 871 |         for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
 | 
|---|
| [47d041] | 872 |           output << "\t[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
 | 
|---|
| [065e82] | 873 |       }
 | 
|---|
| [ce7bfd] | 874 |       LOG(3, "DEBUG: " << output.str());
 | 
|---|
| [6613ec] | 875 |       triangle->lines[i] = NULL; // free'd or not: disconnect
 | 
|---|
| [16d866] | 876 |     } else
 | 
|---|
| [47d041] | 877 |       ELOG(1, "This line " << i << " has already been free'd.");
 | 
|---|
| [16d866] | 878 |   }
 | 
|---|
 | 879 | 
 | 
|---|
 | 880 |   if (TrianglesOnBoundary.erase(triangle->Nr))
 | 
|---|
| [ce7bfd] | 881 |     LOG(3, "DEBUG: Removing triangle Nr. " << triangle->Nr << ".");
 | 
|---|
| [6613ec] | 882 |   delete (triangle);
 | 
|---|
 | 883 | }
 | 
|---|
 | 884 | ;
 | 
|---|
| [16d866] | 885 | 
 | 
|---|
 | 886 | /** Removes a line from the tesselation.
 | 
|---|
 | 887 |  * Removes itself from each endpoints' LineMap, then removes itself from global LinesOnBoundary list and free's the line.
 | 
|---|
 | 888 |  * \param *line line to remove
 | 
|---|
 | 889 |  */
 | 
|---|
 | 890 | void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
 | 
|---|
 | 891 | {
 | 
|---|
| [ce7bfd] | 892 |   //Info FunctionInfo(__func__);
 | 
|---|
| [16d866] | 893 |   int Numbers[2];
 | 
|---|
 | 894 | 
 | 
|---|
 | 895 |   if (line == NULL)
 | 
|---|
 | 896 |     return;
 | 
|---|
| [065e82] | 897 |   // get other endpoint number for finding copies of same line
 | 
|---|
| [16d866] | 898 |   if (line->endpoints[1] != NULL)
 | 
|---|
 | 899 |     Numbers[0] = line->endpoints[1]->Nr;
 | 
|---|
 | 900 |   else
 | 
|---|
 | 901 |     Numbers[0] = -1;
 | 
|---|
 | 902 |   if (line->endpoints[0] != NULL)
 | 
|---|
 | 903 |     Numbers[1] = line->endpoints[0]->Nr;
 | 
|---|
 | 904 |   else
 | 
|---|
 | 905 |     Numbers[1] = -1;
 | 
|---|
 | 906 | 
 | 
|---|
 | 907 |   for (int i = 0; i < 2; i++) {
 | 
|---|
 | 908 |     if (line->endpoints[i] != NULL) {
 | 
|---|
 | 909 |       if (Numbers[i] != -1) { // as there may be multiple lines with same endpoints, we have to go through each and find in the endpoint's line list this line set
 | 
|---|
 | 910 |         pair<LineMap::iterator, LineMap::iterator> erasor = line->endpoints[i]->lines.equal_range(Numbers[i]);
 | 
|---|
 | 911 |         for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
 | 
|---|
 | 912 |           if ((*Runner).second == line) {
 | 
|---|
| [ce7bfd] | 913 |             LOG(4, "DEBUG: Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << ".");
 | 
|---|
| [16d866] | 914 |             line->endpoints[i]->lines.erase(Runner);
 | 
|---|
 | 915 |             break;
 | 
|---|
 | 916 |           }
 | 
|---|
 | 917 |       } else { // there's just a single line left
 | 
|---|
 | 918 |         if (line->endpoints[i]->lines.erase(line->Nr))
 | 
|---|
| [ce7bfd] | 919 |           LOG(4, "DEBUG: Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << ".");
 | 
|---|
| [16d866] | 920 |       }
 | 
|---|
 | 921 |       if (line->endpoints[i]->lines.empty()) {
 | 
|---|
| [ce7bfd] | 922 |         LOG(4, "DEBUG: " << *line->endpoints[i] << " has no more lines it's attached to, erasing.");
 | 
|---|
| [16d866] | 923 |         RemoveTesselationPoint(line->endpoints[i]);
 | 
|---|
| [47d041] | 924 |       } else if (DoLog(0)) {
 | 
|---|
 | 925 |         std::stringstream output;
 | 
|---|
| [ce7bfd] | 926 |         output << "DEBUG: " << *line->endpoints[i] << " has still lines it's attached to: ";
 | 
|---|
| [6613ec] | 927 |         for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
 | 
|---|
| [47d041] | 928 |           output << "[" << *(LineRunner->second) << "] \t";
 | 
|---|
| [ce7bfd] | 929 |         LOG(4, output.str());
 | 
|---|
| [065e82] | 930 |       }
 | 
|---|
| [6613ec] | 931 |       line->endpoints[i] = NULL; // free'd or not: disconnect
 | 
|---|
| [16d866] | 932 |     } else
 | 
|---|
| [ce7bfd] | 933 |       ELOG(4, "DEBUG: Endpoint " << i << " has already been free'd.");
 | 
|---|
| [16d866] | 934 |   }
 | 
|---|
 | 935 |   if (!line->triangles.empty())
 | 
|---|
| [47d041] | 936 |     ELOG(2, "Memory Leak! I " << *line << " am still connected to some triangles.");
 | 
|---|
| [16d866] | 937 | 
 | 
|---|
 | 938 |   if (LinesOnBoundary.erase(line->Nr))
 | 
|---|
| [ce7bfd] | 939 |     LOG(4, "DEBUG: Removing line Nr. " << line->Nr << ".");
 | 
|---|
| [6613ec] | 940 |   delete (line);
 | 
|---|
 | 941 | }
 | 
|---|
 | 942 | ;
 | 
|---|
| [16d866] | 943 | 
 | 
|---|
 | 944 | /** Removes a point from the tesselation.
 | 
|---|
 | 945 |  * Checks whether there are still lines connected, removes from global PointsOnBoundary list, then free's the point.
 | 
|---|
 | 946 |  * \note If a point should be removed, while keep the tesselated surface intact (i.e. closed), use RemovePointFromTesselatedSurface()
 | 
|---|
 | 947 |  * \param *point point to remove
 | 
|---|
 | 948 |  */
 | 
|---|
 | 949 | void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
 | 
|---|
 | 950 | {
 | 
|---|
| [ce7bfd] | 951 |   //Info FunctionInfo(__func__);
 | 
|---|
| [16d866] | 952 |   if (point == NULL)
 | 
|---|
 | 953 |     return;
 | 
|---|
 | 954 |   if (PointsOnBoundary.erase(point->Nr))
 | 
|---|
| [ce7bfd] | 955 |     LOG(4, "DEBUG: Removing point Nr. " << point->Nr << ".");
 | 
|---|
| [6613ec] | 956 |   delete (point);
 | 
|---|
 | 957 | }
 | 
|---|
 | 958 | ;
 | 
|---|
| [f07f86d] | 959 | 
 | 
|---|
 | 960 | /** Checks validity of a given sphere of a candidate line.
 | 
|---|
 | 961 |  * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
 | 
|---|
| [6613ec] | 962 |  * We check CandidateForTesselation::OtherOptCenter
 | 
|---|
 | 963 |  * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
 | 
|---|
| [f07f86d] | 964 |  * \param RADIUS radius of sphere
 | 
|---|
| [6bd7e0] | 965 |  * \param *LC LinkedCell_deprecated structure with other atoms
 | 
|---|
| [f07f86d] | 966 |  * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
 | 
|---|
 | 967 |  */
 | 
|---|
| [6bd7e0] | 968 | bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC) const
 | 
|---|
| [f07f86d] | 969 | {
 | 
|---|
| [ce7bfd] | 970 |   //Info FunctionInfo(__func__);
 | 
|---|
| [f07f86d] | 971 | 
 | 
|---|
| [ce7bfd] | 972 |   LOG(3, "DEBUG: Checking whether sphere contains no others points ...");
 | 
|---|
| [f07f86d] | 973 |   bool flag = true;
 | 
|---|
 | 974 | 
 | 
|---|
| [ce7bfd] | 975 |   LOG(3, "DEBUG: Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30");
 | 
|---|
| [f07f86d] | 976 |   // get all points inside the sphere
 | 
|---|
| [6613ec] | 977 |   TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
 | 
|---|
| [f07f86d] | 978 | 
 | 
|---|
| [ce7bfd] | 979 |   LOG(3, "DEBUG: The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":");
 | 
|---|
| [f07f86d] | 980 |   for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
 | 
|---|
| [ce7bfd] | 981 |     LOG(3, "DEBUG:   " << *(*Runner) << " with distance " << (*Runner)->distance(CandidateLine.OtherOptCenter) << ".");
 | 
|---|
| [f07f86d] | 982 | 
 | 
|---|
 | 983 |   // remove triangles's endpoints
 | 
|---|
| [6613ec] | 984 |   for (int i = 0; i < 2; i++)
 | 
|---|
 | 985 |     ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
 | 
|---|
 | 986 | 
 | 
|---|
 | 987 |   // remove other candidates
 | 
|---|
 | 988 |   for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
 | 
|---|
 | 989 |     ListofPoints->remove(*Runner);
 | 
|---|
| [f07f86d] | 990 | 
 | 
|---|
 | 991 |   // check for other points
 | 
|---|
 | 992 |   if (!ListofPoints->empty()) {
 | 
|---|
| [ce7bfd] | 993 |     LOG(3, "DEBUG: CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere.");
 | 
|---|
| [f07f86d] | 994 |     flag = false;
 | 
|---|
| [ce7bfd] | 995 |     LOG(3, "DEBUG: External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":");
 | 
|---|
| [f07f86d] | 996 |     for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
 | 
|---|
| [ce7bfd] | 997 |       LOG(3, "DEBUG:   " << *(*Runner) << " with distance " << (*Runner)->distance(CandidateLine.OtherOptCenter) << ".");
 | 
|---|
| [f07f86d] | 998 |   }
 | 
|---|
| [6613ec] | 999 |   delete (ListofPoints);
 | 
|---|
| [f07f86d] | 1000 | 
 | 
|---|
 | 1001 |   return flag;
 | 
|---|
| [6613ec] | 1002 | }
 | 
|---|
 | 1003 | ;
 | 
|---|
| [357fba] | 1004 | 
 | 
|---|
| [62bb91] | 1005 | /** Checks whether the triangle consisting of the three points is already present.
 | 
|---|
| [357fba] | 1006 |  * Searches for the points in Tesselation::PointsOnBoundary and checks their
 | 
|---|
 | 1007 |  * lines. If any of the three edges already has two triangles attached, false is
 | 
|---|
 | 1008 |  * returned.
 | 
|---|
 | 1009 |  * \param *out output stream for debugging
 | 
|---|
 | 1010 |  * \param *Candidates endpoints of the triangle candidate
 | 
|---|
 | 1011 |  * \return integer 0 if no triangle exists, 1 if one triangle exists, 2 if two
 | 
|---|
 | 1012 |  *                 triangles exist which is the maximum for three points
 | 
|---|
 | 1013 |  */
 | 
|---|
| [f1ef60a] | 1014 | int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
 | 
|---|
 | 1015 | {
 | 
|---|
| [ce7bfd] | 1016 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 1017 |   int adjacentTriangleCount = 0;
 | 
|---|
 | 1018 |   class BoundaryPointSet *Points[3];
 | 
|---|
 | 1019 | 
 | 
|---|
 | 1020 |   // builds a triangle point set (Points) of the end points
 | 
|---|
 | 1021 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [735b1c] | 1022 |     PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidates[i]->getNr());
 | 
|---|
| [357fba] | 1023 |     if (FindPoint != PointsOnBoundary.end()) {
 | 
|---|
 | 1024 |       Points[i] = FindPoint->second;
 | 
|---|
 | 1025 |     } else {
 | 
|---|
 | 1026 |       Points[i] = NULL;
 | 
|---|
 | 1027 |     }
 | 
|---|
 | 1028 |   }
 | 
|---|
 | 1029 | 
 | 
|---|
 | 1030 |   // checks lines between the points in the Points for their adjacent triangles
 | 
|---|
 | 1031 |   for (int i = 0; i < 3; i++) {
 | 
|---|
 | 1032 |     if (Points[i] != NULL) {
 | 
|---|
 | 1033 |       for (int j = i; j < 3; j++) {
 | 
|---|
 | 1034 |         if (Points[j] != NULL) {
 | 
|---|
| [735b1c] | 1035 |           LineMap::const_iterator FindLine = Points[i]->lines.find(Points[j]->node->getNr());
 | 
|---|
 | 1036 |           for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->getNr()); FindLine++) {
 | 
|---|
| [357fba] | 1037 |             TriangleMap *triangles = &FindLine->second->triangles;
 | 
|---|
| [ce7bfd] | 1038 |             LOG(5, "DEBUG: Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << ".");
 | 
|---|
| [f1ef60a] | 1039 |             for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
 | 
|---|
| [357fba] | 1040 |               if (FindTriangle->second->IsPresentTupel(Points)) {
 | 
|---|
 | 1041 |                 adjacentTriangleCount++;
 | 
|---|
 | 1042 |               }
 | 
|---|
 | 1043 |             }
 | 
|---|
 | 1044 |           }
 | 
|---|
 | 1045 |           // Only one of the triangle lines must be considered for the triangle count.
 | 
|---|
| [ce7bfd] | 1046 |           //LOG(5, "DEBUG: Found " << adjacentTriangleCount << " adjacent triangles for the point set.");
 | 
|---|
| [065e82] | 1047 |           //return adjacentTriangleCount;
 | 
|---|
| [357fba] | 1048 |         }
 | 
|---|
 | 1049 |       }
 | 
|---|
 | 1050 |     }
 | 
|---|
 | 1051 |   }
 | 
|---|
 | 1052 | 
 | 
|---|
| [ce7bfd] | 1053 |   LOG(3, "DEBUG: Found " << adjacentTriangleCount << " adjacent triangles for the point set.");
 | 
|---|
| [357fba] | 1054 |   return adjacentTriangleCount;
 | 
|---|
| [6613ec] | 1055 | }
 | 
|---|
 | 1056 | ;
 | 
|---|
| [357fba] | 1057 | 
 | 
|---|
| [065e82] | 1058 | /** Checks whether the triangle consisting of the three points is already present.
 | 
|---|
 | 1059 |  * Searches for the points in Tesselation::PointsOnBoundary and checks their
 | 
|---|
 | 1060 |  * lines. If any of the three edges already has two triangles attached, false is
 | 
|---|
 | 1061 |  * returned.
 | 
|---|
 | 1062 |  * \param *out output stream for debugging
 | 
|---|
 | 1063 |  * \param *Candidates endpoints of the triangle candidate
 | 
|---|
 | 1064 |  * \return NULL - none found or pointer to triangle
 | 
|---|
 | 1065 |  */
 | 
|---|
| [e138de] | 1066 | class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
 | 
|---|
| [065e82] | 1067 | {
 | 
|---|
| [ce7bfd] | 1068 |   //Info FunctionInfo(__func__);
 | 
|---|
| [065e82] | 1069 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 1070 |   class BoundaryPointSet *Points[3];
 | 
|---|
 | 1071 | 
 | 
|---|
 | 1072 |   // builds a triangle point set (Points) of the end points
 | 
|---|
 | 1073 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [735b1c] | 1074 |     PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->getNr());
 | 
|---|
| [065e82] | 1075 |     if (FindPoint != PointsOnBoundary.end()) {
 | 
|---|
 | 1076 |       Points[i] = FindPoint->second;
 | 
|---|
 | 1077 |     } else {
 | 
|---|
 | 1078 |       Points[i] = NULL;
 | 
|---|
 | 1079 |     }
 | 
|---|
 | 1080 |   }
 | 
|---|
 | 1081 | 
 | 
|---|
 | 1082 |   // checks lines between the points in the Points for their adjacent triangles
 | 
|---|
 | 1083 |   for (int i = 0; i < 3; i++) {
 | 
|---|
 | 1084 |     if (Points[i] != NULL) {
 | 
|---|
 | 1085 |       for (int j = i; j < 3; j++) {
 | 
|---|
 | 1086 |         if (Points[j] != NULL) {
 | 
|---|
| [735b1c] | 1087 |           LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->getNr());
 | 
|---|
 | 1088 |           for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->getNr()); FindLine++) {
 | 
|---|
| [065e82] | 1089 |             TriangleMap *triangles = &FindLine->second->triangles;
 | 
|---|
 | 1090 |             for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
 | 
|---|
 | 1091 |               if (FindTriangle->second->IsPresentTupel(Points)) {
 | 
|---|
 | 1092 |                 if ((triangle == NULL) || (triangle->Nr > FindTriangle->second->Nr))
 | 
|---|
 | 1093 |                   triangle = FindTriangle->second;
 | 
|---|
 | 1094 |               }
 | 
|---|
 | 1095 |             }
 | 
|---|
 | 1096 |           }
 | 
|---|
 | 1097 |           // Only one of the triangle lines must be considered for the triangle count.
 | 
|---|
| [ce7bfd] | 1098 |           //LOG(5, "DEBUG: Found " << adjacentTriangleCount << " adjacent triangles for the point set.");
 | 
|---|
| [065e82] | 1099 |           //return adjacentTriangleCount;
 | 
|---|
 | 1100 |         }
 | 
|---|
 | 1101 |       }
 | 
|---|
 | 1102 |     }
 | 
|---|
 | 1103 |   }
 | 
|---|
 | 1104 | 
 | 
|---|
 | 1105 |   return triangle;
 | 
|---|
| [6613ec] | 1106 | }
 | 
|---|
 | 1107 | ;
 | 
|---|
| [357fba] | 1108 | 
 | 
|---|
| [f1cccd] | 1109 | /** Finds the starting triangle for FindNonConvexBorder().
 | 
|---|
 | 1110 |  * Looks at the outermost point per axis, then FindSecondPointForTesselation()
 | 
|---|
 | 1111 |  * for the second and FindNextSuitablePointViaAngleOfSphere() for the third
 | 
|---|
| [357fba] | 1112 |  * point are called.
 | 
|---|
 | 1113 |  * \param *out output stream for debugging
 | 
|---|
 | 1114 |  * \param RADIUS radius of virtual rolling sphere
 | 
|---|
| [6bd7e0] | 1115 |  * \param *LC LinkedCell_deprecated structure with neighbouring TesselPoint's
 | 
|---|
| [ce70970] | 1116 |  * \return true - a starting triangle has been created, false - no valid triple of points found
 | 
|---|
| [357fba] | 1117 |  */
 | 
|---|
| [6bd7e0] | 1118 | bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell_deprecated *LC)
 | 
|---|
| [357fba] | 1119 | {
 | 
|---|
| [ce7bfd] | 1120 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 1121 |   int i = 0;
 | 
|---|
| [62bb91] | 1122 |   TesselPoint* MaxPoint[NDIM];
 | 
|---|
| [7273fc] | 1123 |   TesselPoint* Temporary;
 | 
|---|
| [f1cccd] | 1124 |   double maxCoordinate[NDIM];
 | 
|---|
| [f07f86d] | 1125 |   BoundaryLineSet *BaseLine = NULL;
 | 
|---|
| [357fba] | 1126 |   Vector helper;
 | 
|---|
 | 1127 |   Vector Chord;
 | 
|---|
 | 1128 |   Vector SearchDirection;
 | 
|---|
| [6613ec] | 1129 |   Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
 | 
|---|
| [b998c3] | 1130 |   Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
 | 
|---|
 | 1131 |   Vector SphereCenter;
 | 
|---|
 | 1132 |   Vector NormalVector;
 | 
|---|
| [357fba] | 1133 | 
 | 
|---|
| [b998c3] | 1134 |   NormalVector.Zero();
 | 
|---|
| [357fba] | 1135 | 
 | 
|---|
 | 1136 |   for (i = 0; i < 3; i++) {
 | 
|---|
| [62bb91] | 1137 |     MaxPoint[i] = NULL;
 | 
|---|
| [467069] | 1138 |     maxCoordinate[i] = -10e30;
 | 
|---|
| [357fba] | 1139 |   }
 | 
|---|
 | 1140 | 
 | 
|---|
| [62bb91] | 1141 |   // 1. searching topmost point with respect to each axis
 | 
|---|
| [6613ec] | 1142 |   for (int i = 0; i < NDIM; i++) { // each axis
 | 
|---|
 | 1143 |     LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
 | 
|---|
| [bdc91e] | 1144 |     const int map[NDIM] = {i, (i + 1) % NDIM, (i + 2) % NDIM};
 | 
|---|
 | 1145 |     for (LC->n[map[1]] = 0; LC->n[map[1]] < LC->N[map[1]]; LC->n[map[1]]++)
 | 
|---|
 | 1146 |       for (LC->n[map[2]] = 0; LC->n[map[2]] < LC->N[map[2]]; LC->n[map[2]]++) {
 | 
|---|
| [34c43a] | 1147 |         const TesselPointSTLList *List = LC->GetCurrentCell();
 | 
|---|
| [47d041] | 1148 |         //LOG(1, "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << ".");
 | 
|---|
| [357fba] | 1149 |         if (List != NULL) {
 | 
|---|
| [34c43a] | 1150 |           for (TesselPointSTLList::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
 | 
|---|
| [d74077] | 1151 |             if ((*Runner)->at(map[0]) > maxCoordinate[map[0]]) {
 | 
|---|
| [ce7bfd] | 1152 |               LOG(4, "DEBUG: New maximal for axis " << map[0] << " node is " << *(*Runner) << " at " << (*Runner)->getPosition() << ".");
 | 
|---|
| [d74077] | 1153 |               maxCoordinate[map[0]] = (*Runner)->at(map[0]);
 | 
|---|
| [bdc91e] | 1154 |               MaxPoint[map[0]] = (*Runner);
 | 
|---|
| [357fba] | 1155 |             }
 | 
|---|
 | 1156 |           }
 | 
|---|
 | 1157 |         } else {
 | 
|---|
| [47d041] | 1158 |           ELOG(1, "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!");
 | 
|---|
| [357fba] | 1159 |         }
 | 
|---|
 | 1160 |       }
 | 
|---|
 | 1161 |   }
 | 
|---|
 | 1162 | 
 | 
|---|
| [47d041] | 1163 |   if (DoLog(1)) {
 | 
|---|
 | 1164 |     std::stringstream output;
 | 
|---|
 | 1165 |     output << "Found maximum coordinates: ";
 | 
|---|
 | 1166 |     for (int i = 0; i < NDIM; i++)
 | 
|---|
 | 1167 |       output << i << ": " << *MaxPoint[i] << "\t";
 | 
|---|
| [ce7bfd] | 1168 |     LOG(3, "DEBUG: " << output.str());
 | 
|---|
| [47d041] | 1169 |   }
 | 
|---|
| [357fba] | 1170 | 
 | 
|---|
 | 1171 |   BTS = NULL;
 | 
|---|
| [6613ec] | 1172 |   for (int k = 0; k < NDIM; k++) {
 | 
|---|
| [b998c3] | 1173 |     NormalVector.Zero();
 | 
|---|
| [0a4f7f] | 1174 |     NormalVector[k] = 1.;
 | 
|---|
| [f07f86d] | 1175 |     BaseLine = new BoundaryLineSet();
 | 
|---|
 | 1176 |     BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
 | 
|---|
| [ce7bfd] | 1177 |     LOG(2, "DEBUG: Coordinates of start node at " << *BaseLine->endpoints[0]->node << ".");
 | 
|---|
| [357fba] | 1178 | 
 | 
|---|
 | 1179 |     double ShortestAngle;
 | 
|---|
 | 1180 |     ShortestAngle = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
 | 
|---|
 | 1181 | 
 | 
|---|
| [cfe56d] | 1182 |     Temporary = NULL;
 | 
|---|
| [f07f86d] | 1183 |     FindSecondPointForTesselation(BaseLine->endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
 | 
|---|
| [711ac2] | 1184 |     if (Temporary == NULL) {
 | 
|---|
 | 1185 |       // have we found a second point?
 | 
|---|
 | 1186 |       delete BaseLine;
 | 
|---|
| [357fba] | 1187 |       continue;
 | 
|---|
| [711ac2] | 1188 |     }
 | 
|---|
| [f07f86d] | 1189 |     BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
 | 
|---|
| [418b5e] | 1190 |     LOG(1, "INFO: Second node is at " << *Temporary << ".");
 | 
|---|
| [357fba] | 1191 | 
 | 
|---|
| [b998c3] | 1192 |     // construct center of circle
 | 
|---|
| [d74077] | 1193 |     CircleCenter = 0.5 * ((BaseLine->endpoints[0]->node->getPosition()) + (BaseLine->endpoints[1]->node->getPosition()));
 | 
|---|
| [418b5e] | 1194 |     LOG(1, "INFO: CircleCenter is at " << CircleCenter << ".");
 | 
|---|
| [b998c3] | 1195 | 
 | 
|---|
 | 1196 |     // construct normal vector of circle
 | 
|---|
| [d74077] | 1197 |     CirclePlaneNormal = (BaseLine->endpoints[0]->node->getPosition()) - (BaseLine->endpoints[1]->node->getPosition());
 | 
|---|
| [418b5e] | 1198 |     LOG(1, "INFO: CirclePlaneNormal is at " << CirclePlaneNormal << ".");
 | 
|---|
| [357fba] | 1199 | 
 | 
|---|
| [b998c3] | 1200 |     double radius = CirclePlaneNormal.NormSquared();
 | 
|---|
| [6613ec] | 1201 |     double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
 | 
|---|
| [b998c3] | 1202 | 
 | 
|---|
| [273382] | 1203 |     NormalVector.ProjectOntoPlane(CirclePlaneNormal);
 | 
|---|
| [b998c3] | 1204 |     NormalVector.Normalize();
 | 
|---|
| [418b5e] | 1205 |     LOG(1, "INFO: NormalVector is at " << NormalVector << ".");
 | 
|---|
| [6613ec] | 1206 |     ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
 | 
|---|
| [b998c3] | 1207 | 
 | 
|---|
| [273382] | 1208 |     SphereCenter = (CircleRadius * NormalVector) +  CircleCenter;
 | 
|---|
| [b998c3] | 1209 |     // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
 | 
|---|
| [357fba] | 1210 | 
 | 
|---|
 | 1211 |     // look in one direction of baseline for initial candidate
 | 
|---|
| [418b5e] | 1212 |     try {
 | 
|---|
 | 1213 |       SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal();  // whether we look "left" first or "right" first is not important ...
 | 
|---|
 | 1214 |     } catch(LinearAlgebraException) {
 | 
|---|
 | 1215 |       ELOG(1, "Vectors are linear dependent: "
 | 
|---|
 | 1216 |           << CirclePlaneNormal << ", " << NormalVector << ".");
 | 
|---|
 | 1217 |       delete BaseLine;
 | 
|---|
 | 1218 |       continue;
 | 
|---|
 | 1219 |     }
 | 
|---|
| [357fba] | 1220 | 
 | 
|---|
| [5c7bf8] | 1221 |     // adding point 1 and point 2 and add the line between them
 | 
|---|
| [ce7bfd] | 1222 |     LOG(2, "DEBUG: Found second point is at " << *BaseLine->endpoints[1]->node << ".");
 | 
|---|
| [357fba] | 1223 | 
 | 
|---|
| [47d041] | 1224 |     //LOG(1, "INFO: OldSphereCenter is at " << helper << ".");
 | 
|---|
| [f07f86d] | 1225 |     CandidateForTesselation OptCandidates(BaseLine);
 | 
|---|
| [b998c3] | 1226 |     FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
 | 
|---|
| [ce7bfd] | 1227 |     {
 | 
|---|
 | 1228 |       std::stringstream output;
 | 
|---|
 | 1229 |       for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++)
 | 
|---|
 | 1230 |         output << *(*it);
 | 
|---|
 | 1231 |       LOG(2, "DEBUG: List of third Points is: " << output.str());
 | 
|---|
| [357fba] | 1232 |     }
 | 
|---|
| [f07f86d] | 1233 |     if (!OptCandidates.pointlist.empty()) {
 | 
|---|
 | 1234 |       BTS = NULL;
 | 
|---|
 | 1235 |       AddCandidatePolygon(OptCandidates, RADIUS, LC);
 | 
|---|
 | 1236 |     } else {
 | 
|---|
 | 1237 |       delete BaseLine;
 | 
|---|
 | 1238 |       continue;
 | 
|---|
| [357fba] | 1239 |     }
 | 
|---|
 | 1240 | 
 | 
|---|
| [711ac2] | 1241 |     if (BTS != NULL) { // we have created one starting triangle
 | 
|---|
 | 1242 |       delete BaseLine;
 | 
|---|
| [357fba] | 1243 |       break;
 | 
|---|
| [711ac2] | 1244 |     } else {
 | 
|---|
| [357fba] | 1245 |       // remove all candidates from the list and then the list itself
 | 
|---|
| [7273fc] | 1246 |       OptCandidates.pointlist.clear();
 | 
|---|
| [357fba] | 1247 |     }
 | 
|---|
| [f07f86d] | 1248 |     delete BaseLine;
 | 
|---|
| [357fba] | 1249 |   }
 | 
|---|
| [ce70970] | 1250 | 
 | 
|---|
 | 1251 |   return (BTS != NULL);
 | 
|---|
| [6613ec] | 1252 | }
 | 
|---|
 | 1253 | ;
 | 
|---|
| [357fba] | 1254 | 
 | 
|---|
| [f1ef60a] | 1255 | /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
 | 
|---|
 | 1256 |  * This is supposed to prevent early closing of the tesselation.
 | 
|---|
| [f67b6e] | 1257 |  * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
 | 
|---|
| [f1ef60a] | 1258 |  * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
 | 
|---|
 | 1259 |  * \param RADIUS radius of sphere
 | 
|---|
| [6bd7e0] | 1260 |  * \param *LC LinkedCell_deprecated structure
 | 
|---|
| [f1ef60a] | 1261 |  * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
 | 
|---|
 | 1262 |  */
 | 
|---|
| [6bd7e0] | 1263 | //bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell_deprecated * const LC) const
 | 
|---|
| [f67b6e] | 1264 | //{
 | 
|---|
| [ce7bfd] | 1265 | //      //Info FunctionInfo(__func__);
 | 
|---|
| [f67b6e] | 1266 | //  bool result = false;
 | 
|---|
 | 1267 | //  Vector CircleCenter;
 | 
|---|
 | 1268 | //  Vector CirclePlaneNormal;
 | 
|---|
 | 1269 | //  Vector OldSphereCenter;
 | 
|---|
 | 1270 | //  Vector SearchDirection;
 | 
|---|
 | 1271 | //  Vector helper;
 | 
|---|
 | 1272 | //  TesselPoint *OtherOptCandidate = NULL;
 | 
|---|
 | 1273 | //  double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
 | 
|---|
 | 1274 | //  double radius, CircleRadius;
 | 
|---|
 | 1275 | //  BoundaryLineSet *Line = NULL;
 | 
|---|
 | 1276 | //  BoundaryTriangleSet *T = NULL;
 | 
|---|
 | 1277 | //
 | 
|---|
 | 1278 | //  // check both other lines
 | 
|---|
| [735b1c] | 1279 | //  PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->getNr());
 | 
|---|
| [f67b6e] | 1280 | //  if (FindPoint != PointsOnBoundary.end()) {
 | 
|---|
 | 1281 | //    for (int i=0;i<2;i++) {
 | 
|---|
| [735b1c] | 1282 | //      LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->getNr());
 | 
|---|
| [f67b6e] | 1283 | //      if (FindLine != (FindPoint->second)->lines.end()) {
 | 
|---|
 | 1284 | //        Line = FindLine->second;
 | 
|---|
| [47d041] | 1285 | //        LOG(0, "Found line " << *Line << ".");
 | 
|---|
| [f67b6e] | 1286 | //        if (Line->triangles.size() == 1) {
 | 
|---|
 | 1287 | //          T = Line->triangles.begin()->second;
 | 
|---|
 | 1288 | //          // construct center of circle
 | 
|---|
 | 1289 | //          CircleCenter.CopyVector(Line->endpoints[0]->node->node);
 | 
|---|
 | 1290 | //          CircleCenter.AddVector(Line->endpoints[1]->node->node);
 | 
|---|
 | 1291 | //          CircleCenter.Scale(0.5);
 | 
|---|
 | 1292 | //
 | 
|---|
 | 1293 | //          // construct normal vector of circle
 | 
|---|
 | 1294 | //          CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
 | 
|---|
 | 1295 | //          CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
 | 
|---|
 | 1296 | //
 | 
|---|
 | 1297 | //          // calculate squared radius of circle
 | 
|---|
 | 1298 | //          radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
 | 
|---|
 | 1299 | //          if (radius/4. < RADIUS*RADIUS) {
 | 
|---|
 | 1300 | //            CircleRadius = RADIUS*RADIUS - radius/4.;
 | 
|---|
 | 1301 | //            CirclePlaneNormal.Normalize();
 | 
|---|
| [47d041] | 1302 | //            //LOG(1, "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << ".");
 | 
|---|
| [f67b6e] | 1303 | //
 | 
|---|
 | 1304 | //            // construct old center
 | 
|---|
 | 1305 | //            GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
 | 
|---|
 | 1306 | //            helper.CopyVector(&T->NormalVector);  // normal vector ensures that this is correct center of the two possible ones
 | 
|---|
 | 1307 | //            radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
 | 
|---|
 | 1308 | //            helper.Scale(sqrt(RADIUS*RADIUS - radius));
 | 
|---|
 | 1309 | //            OldSphereCenter.AddVector(&helper);
 | 
|---|
 | 1310 | //            OldSphereCenter.SubtractVector(&CircleCenter);
 | 
|---|
| [47d041] | 1311 | //            //LOG(1, "INFO: OldSphereCenter is at " << OldSphereCenter << ".");
 | 
|---|
| [f67b6e] | 1312 | //
 | 
|---|
 | 1313 | //            // construct SearchDirection
 | 
|---|
 | 1314 | //            SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
 | 
|---|
 | 1315 | //            helper.CopyVector(Line->endpoints[0]->node->node);
 | 
|---|
 | 1316 | //            helper.SubtractVector(ThirdNode->node);
 | 
|---|
 | 1317 | //            if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
 | 
|---|
 | 1318 | //              SearchDirection.Scale(-1.);
 | 
|---|
 | 1319 | //            SearchDirection.ProjectOntoPlane(&OldSphereCenter);
 | 
|---|
 | 1320 | //            SearchDirection.Normalize();
 | 
|---|
| [47d041] | 1321 | //            LOG(1, "INFO: SearchDirection is " << SearchDirection << ".");
 | 
|---|
| [f67b6e] | 1322 | //            if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
 | 
|---|
 | 1323 | //              // rotated the wrong way!
 | 
|---|
| [47d041] | 1324 | //              ELOG(1, "SearchDirection and RelativeOldSphereCenter are still not orthogonal!");
 | 
|---|
| [f67b6e] | 1325 | //            }
 | 
|---|
 | 1326 | //
 | 
|---|
 | 1327 | //            // add third point
 | 
|---|
 | 1328 | //            FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
 | 
|---|
 | 1329 | //            for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
 | 
|---|
 | 1330 | //              if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
 | 
|---|
 | 1331 | //                continue;
 | 
|---|
| [47d041] | 1332 | //              LOG(1, "INFO: Third point candidate is " << (*it)
 | 
|---|
 | 1333 | //              << " with circumsphere's center at " << (*it)->OptCenter << ".");
 | 
|---|
 | 1334 | //              LOG(1, "INFO: Baseline is " << *BaseRay);
 | 
|---|
| [f67b6e] | 1335 | //
 | 
|---|
 | 1336 | //              // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
 | 
|---|
 | 1337 | //              TesselPoint *PointCandidates[3];
 | 
|---|
 | 1338 | //              PointCandidates[0] = (*it);
 | 
|---|
 | 1339 | //              PointCandidates[1] = BaseRay->endpoints[0]->node;
 | 
|---|
 | 1340 | //              PointCandidates[2] = BaseRay->endpoints[1]->node;
 | 
|---|
 | 1341 | //              bool check=false;
 | 
|---|
 | 1342 | //              int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
 | 
|---|
 | 1343 | //              // If there is no triangle, add it regularly.
 | 
|---|
 | 1344 | //              if (existentTrianglesCount == 0) {
 | 
|---|
 | 1345 | //                SetTesselationPoint((*it), 0);
 | 
|---|
 | 1346 | //                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
 | 
|---|
 | 1347 | //                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
 | 
|---|
 | 1348 | //
 | 
|---|
 | 1349 | //                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
 | 
|---|
 | 1350 | //                  OtherOptCandidate = (*it);
 | 
|---|
 | 1351 | //                  check = true;
 | 
|---|
 | 1352 | //                }
 | 
|---|
 | 1353 | //              } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
 | 
|---|
 | 1354 | //                SetTesselationPoint((*it), 0);
 | 
|---|
 | 1355 | //                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
 | 
|---|
 | 1356 | //                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
 | 
|---|
 | 1357 | //
 | 
|---|
 | 1358 | //                // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
 | 
|---|
 | 1359 | //                // i.e. at least one of the three lines must be present with TriangleCount <= 1
 | 
|---|
 | 1360 | //                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
 | 
|---|
 | 1361 | //                  OtherOptCandidate = (*it);
 | 
|---|
 | 1362 | //                  check = true;
 | 
|---|
 | 1363 | //                }
 | 
|---|
 | 1364 | //              }
 | 
|---|
 | 1365 | //
 | 
|---|
 | 1366 | //              if (check) {
 | 
|---|
 | 1367 | //                if (ShortestAngle > OtherShortestAngle) {
 | 
|---|
| [47d041] | 1368 | //                  LOG(0, "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << ".");
 | 
|---|
| [f67b6e] | 1369 | //                  result = true;
 | 
|---|
 | 1370 | //                  break;
 | 
|---|
 | 1371 | //                }
 | 
|---|
 | 1372 | //              }
 | 
|---|
 | 1373 | //            }
 | 
|---|
 | 1374 | //            delete(OptCandidates);
 | 
|---|
 | 1375 | //            if (result)
 | 
|---|
 | 1376 | //              break;
 | 
|---|
 | 1377 | //          } else {
 | 
|---|
| [47d041] | 1378 | //            LOG(0, "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!");
 | 
|---|
| [f67b6e] | 1379 | //          }
 | 
|---|
 | 1380 | //        } else {
 | 
|---|
| [47d041] | 1381 | //          ELOG(2, "Baseline is connected to two triangles already?");
 | 
|---|
| [f67b6e] | 1382 | //        }
 | 
|---|
 | 1383 | //      } else {
 | 
|---|
| [47d041] | 1384 | //        LOG(1, "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << ".");
 | 
|---|
| [f67b6e] | 1385 | //      }
 | 
|---|
 | 1386 | //    }
 | 
|---|
 | 1387 | //  } else {
 | 
|---|
| [47d041] | 1388 | //    ELOG(1, "Could not find the TesselPoint " << *ThirdNode << ".");
 | 
|---|
| [f67b6e] | 1389 | //  }
 | 
|---|
 | 1390 | //
 | 
|---|
 | 1391 | //  return result;
 | 
|---|
 | 1392 | //};
 | 
|---|
| [357fba] | 1393 | 
 | 
|---|
 | 1394 | /** This function finds a triangle to a line, adjacent to an existing one.
 | 
|---|
 | 1395 |  * @param out output stream for debugging
 | 
|---|
| [1e168b] | 1396 |  * @param CandidateLine current cadndiate baseline to search from
 | 
|---|
| [357fba] | 1397 |  * @param T current triangle which \a Line is edge of
 | 
|---|
 | 1398 |  * @param RADIUS radius of the rolling ball
 | 
|---|
 | 1399 |  * @param N number of found triangles
 | 
|---|
| [6bd7e0] | 1400 |  * @param *LC LinkedCell_deprecated structure with neighbouring points
 | 
|---|
| [357fba] | 1401 |  */
 | 
|---|
| [6bd7e0] | 1402 | bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell_deprecated *LC)
 | 
|---|
| [357fba] | 1403 | {
 | 
|---|
| [ce7bfd] | 1404 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 1405 |   Vector CircleCenter;
 | 
|---|
 | 1406 |   Vector CirclePlaneNormal;
 | 
|---|
| [b998c3] | 1407 |   Vector RelativeSphereCenter;
 | 
|---|
| [357fba] | 1408 |   Vector SearchDirection;
 | 
|---|
 | 1409 |   Vector helper;
 | 
|---|
| [09898c] | 1410 |   BoundaryPointSet *ThirdPoint = NULL;
 | 
|---|
| [357fba] | 1411 |   LineMap::iterator testline;
 | 
|---|
 | 1412 |   double radius, CircleRadius;
 | 
|---|
 | 1413 | 
 | 
|---|
| [6613ec] | 1414 |   for (int i = 0; i < 3; i++)
 | 
|---|
| [09898c] | 1415 |     if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
 | 
|---|
 | 1416 |       ThirdPoint = T.endpoints[i];
 | 
|---|
| [b998c3] | 1417 |       break;
 | 
|---|
 | 1418 |     }
 | 
|---|
| [ce7bfd] | 1419 |   LOG(3, "DEBUG: Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << ".");
 | 
|---|
| [09898c] | 1420 | 
 | 
|---|
 | 1421 |   CandidateLine.T = &T;
 | 
|---|
| [357fba] | 1422 | 
 | 
|---|
 | 1423 |   // construct center of circle
 | 
|---|
| [d74077] | 1424 |   CircleCenter = 0.5 * ((CandidateLine.BaseLine->endpoints[0]->node->getPosition()) +
 | 
|---|
 | 1425 |                         (CandidateLine.BaseLine->endpoints[1]->node->getPosition()));
 | 
|---|
| [357fba] | 1426 | 
 | 
|---|
 | 1427 |   // construct normal vector of circle
 | 
|---|
| [d74077] | 1428 |   CirclePlaneNormal = (CandidateLine.BaseLine->endpoints[0]->node->getPosition()) -
 | 
|---|
 | 1429 |                       (CandidateLine.BaseLine->endpoints[1]->node->getPosition());
 | 
|---|
| [357fba] | 1430 | 
 | 
|---|
 | 1431 |   // calculate squared radius of circle
 | 
|---|
| [273382] | 1432 |   radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal);
 | 
|---|
| [6613ec] | 1433 |   if (radius / 4. < RADIUS * RADIUS) {
 | 
|---|
| [b998c3] | 1434 |     // construct relative sphere center with now known CircleCenter
 | 
|---|
| [273382] | 1435 |     RelativeSphereCenter = T.SphereCenter - CircleCenter;
 | 
|---|
| [b998c3] | 1436 | 
 | 
|---|
| [6613ec] | 1437 |     CircleRadius = RADIUS * RADIUS - radius / 4.;
 | 
|---|
| [357fba] | 1438 |     CirclePlaneNormal.Normalize();
 | 
|---|
| [ce7bfd] | 1439 |     LOG(3, "DEBUG: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << ".");
 | 
|---|
| [357fba] | 1440 | 
 | 
|---|
| [ce7bfd] | 1441 |     LOG(3, "DEBUG: OldSphereCenter is at " << T.SphereCenter << ".");
 | 
|---|
| [b998c3] | 1442 | 
 | 
|---|
 | 1443 |     // construct SearchDirection and an "outward pointer"
 | 
|---|
| [0a4f7f] | 1444 |     SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal();
 | 
|---|
| [d74077] | 1445 |     helper = CircleCenter - (ThirdPoint->node->getPosition());
 | 
|---|
| [273382] | 1446 |     if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
 | 
|---|
| [357fba] | 1447 |       SearchDirection.Scale(-1.);
 | 
|---|
| [ce7bfd] | 1448 |     LOG(3, "DEBUG: SearchDirection is " << SearchDirection << ".");
 | 
|---|
| [273382] | 1449 |     if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) {
 | 
|---|
| [357fba] | 1450 |       // rotated the wrong way!
 | 
|---|
| [ce7bfd] | 1451 |       ELOG(3, "DEBUG: SearchDirection and RelativeOldSphereCenter are still not orthogonal!");
 | 
|---|
| [357fba] | 1452 |     }
 | 
|---|
 | 1453 | 
 | 
|---|
 | 1454 |     // add third point
 | 
|---|
| [09898c] | 1455 |     FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
 | 
|---|
| [357fba] | 1456 | 
 | 
|---|
 | 1457 |   } else {
 | 
|---|
| [ce7bfd] | 1458 |     LOG(3, "DEBUG: Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!");
 | 
|---|
| [357fba] | 1459 |   }
 | 
|---|
 | 1460 | 
 | 
|---|
| [f67b6e] | 1461 |   if (CandidateLine.pointlist.empty()) {
 | 
|---|
| [ce7bfd] | 1462 |     ELOG(4, "DEBUG: Could not find a suitable candidate.");
 | 
|---|
| [357fba] | 1463 |     return false;
 | 
|---|
 | 1464 |   }
 | 
|---|
| [ce7bfd] | 1465 |   {
 | 
|---|
 | 1466 |     std::stringstream output;
 | 
|---|
 | 1467 |     for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it)
 | 
|---|
 | 1468 |       output << " " << *(*it);
 | 
|---|
 | 1469 |     LOG(3, "DEBUG: Third Points are: " << output.str());
 | 
|---|
| [357fba] | 1470 |   }
 | 
|---|
 | 1471 | 
 | 
|---|
| [f67b6e] | 1472 |   return true;
 | 
|---|
| [6613ec] | 1473 | }
 | 
|---|
 | 1474 | ;
 | 
|---|
| [f67b6e] | 1475 | 
 | 
|---|
| [6613ec] | 1476 | /** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
 | 
|---|
| [6bd7e0] | 1477 |  * \param *&LCList atoms in LinkedCell_deprecated list
 | 
|---|
| [6613ec] | 1478 |  * \param RADIUS radius of the virtual sphere
 | 
|---|
 | 1479 |  * \return true - for all open lines without candidates so far, a candidate has been found,
 | 
|---|
 | 1480 |  *         false - at least one open line without candidate still
 | 
|---|
 | 1481 |  */
 | 
|---|
| [6bd7e0] | 1482 | bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell_deprecated *&LCList)
 | 
|---|
| [6613ec] | 1483 | {
 | 
|---|
 | 1484 |   bool TesselationFailFlag = true;
 | 
|---|
 | 1485 |   CandidateForTesselation *baseline = NULL;
 | 
|---|
 | 1486 |   BoundaryTriangleSet *T = NULL;
 | 
|---|
 | 1487 | 
 | 
|---|
 | 1488 |   for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
 | 
|---|
 | 1489 |     baseline = Runner->second;
 | 
|---|
 | 1490 |     if (baseline->pointlist.empty()) {
 | 
|---|
| [6d574a] | 1491 |       ASSERT((baseline->BaseLine->triangles.size() == 1),"Open line without exactly one attached triangle");
 | 
|---|
| [6613ec] | 1492 |       T = (((baseline->BaseLine->triangles.begin()))->second);
 | 
|---|
| [ce7bfd] | 1493 |       LOG(4, "DEBUG: Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T);
 | 
|---|
| [6613ec] | 1494 |       TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
 | 
|---|
 | 1495 |     }
 | 
|---|
 | 1496 |   }
 | 
|---|
 | 1497 |   return TesselationFailFlag;
 | 
|---|
 | 1498 | }
 | 
|---|
 | 1499 | ;
 | 
|---|
| [357fba] | 1500 | 
 | 
|---|
| [1e168b] | 1501 | /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
 | 
|---|
| [f67b6e] | 1502 |  * \param CandidateLine triangle to add
 | 
|---|
| [474961] | 1503 |  * \param RADIUS Radius of sphere
 | 
|---|
| [6bd7e0] | 1504 |  * \param *LC LinkedCell_deprecated structure
 | 
|---|
| [474961] | 1505 |  * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
 | 
|---|
 | 1506 |  * AddTesselationLine() in AddCandidateTriangle()
 | 
|---|
| [1e168b] | 1507 |  */
 | 
|---|
| [6bd7e0] | 1508 | void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC)
 | 
|---|
| [1e168b] | 1509 | {
 | 
|---|
| [ce7bfd] | 1510 |   //Info FunctionInfo(__func__);
 | 
|---|
| [1e168b] | 1511 |   Vector Center;
 | 
|---|
| [27bd2f] | 1512 |   TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
 | 
|---|
| [09898c] | 1513 |   TesselPointList::iterator Runner;
 | 
|---|
 | 1514 |   TesselPointList::iterator Sprinter;
 | 
|---|
| [27bd2f] | 1515 | 
 | 
|---|
 | 1516 |   // fill the set of neighbours
 | 
|---|
| [c15ca2] | 1517 |   TesselPointSet SetOfNeighbours;
 | 
|---|
| [8d2772] | 1518 | 
 | 
|---|
| [27bd2f] | 1519 |   SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
 | 
|---|
 | 1520 |   for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
 | 
|---|
 | 1521 |     SetOfNeighbours.insert(*Runner);
 | 
|---|
| [d74077] | 1522 |   TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->getPosition());
 | 
|---|
| [27bd2f] | 1523 | 
 | 
|---|
| [ce7bfd] | 1524 |   {
 | 
|---|
 | 1525 |     std::stringstream output;
 | 
|---|
 | 1526 |     for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
 | 
|---|
 | 1527 |       output << **TesselRunner;
 | 
|---|
 | 1528 |     LOG(3, "DEBUG: List of Candidates for Turning Point " << *TurningPoint << ":");
 | 
|---|
 | 1529 |   }
 | 
|---|
| [09898c] | 1530 | 
 | 
|---|
 | 1531 |   // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
 | 
|---|
 | 1532 |   Runner = connectedClosestPoints->begin();
 | 
|---|
 | 1533 |   Sprinter = Runner;
 | 
|---|
| [27bd2f] | 1534 |   Sprinter++;
 | 
|---|
| [6613ec] | 1535 |   while (Sprinter != connectedClosestPoints->end()) {
 | 
|---|
| [ce7bfd] | 1536 |     LOG(3, "DEBUG: Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << ".");
 | 
|---|
| [f67b6e] | 1537 | 
 | 
|---|
| [f07f86d] | 1538 |     AddTesselationPoint(TurningPoint, 0);
 | 
|---|
 | 1539 |     AddTesselationPoint(*Runner, 1);
 | 
|---|
 | 1540 |     AddTesselationPoint(*Sprinter, 2);
 | 
|---|
| [1e168b] | 1541 | 
 | 
|---|
| [6613ec] | 1542 |     AddCandidateTriangle(CandidateLine, Opt);
 | 
|---|
| [1e168b] | 1543 | 
 | 
|---|
| [27bd2f] | 1544 |     Runner = Sprinter;
 | 
|---|
 | 1545 |     Sprinter++;
 | 
|---|
| [6613ec] | 1546 |     if (Sprinter != connectedClosestPoints->end()) {
 | 
|---|
 | 1547 |       // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
 | 
|---|
| [f04f11] | 1548 |       FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle
 | 
|---|
| [ce7bfd] | 1549 |       LOG(2, "DEBUG:  There are still more triangles to add.");
 | 
|---|
| [6613ec] | 1550 |     }
 | 
|---|
 | 1551 |     // pick candidates for other open lines as well
 | 
|---|
 | 1552 |     FindCandidatesforOpenLines(RADIUS, LC);
 | 
|---|
 | 1553 | 
 | 
|---|
| [f07f86d] | 1554 |     // check whether we add a degenerate or a normal triangle
 | 
|---|
| [6613ec] | 1555 |     if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
 | 
|---|
| [f07f86d] | 1556 |       // add normal and degenerate triangles
 | 
|---|
| [ce7bfd] | 1557 |       LOG(3, "DEBUG: Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides.");
 | 
|---|
| [6613ec] | 1558 |       AddCandidateTriangle(CandidateLine, OtherOpt);
 | 
|---|
 | 1559 | 
 | 
|---|
 | 1560 |       if (Sprinter != connectedClosestPoints->end()) {
 | 
|---|
 | 1561 |         // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
 | 
|---|
 | 1562 |         FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
 | 
|---|
 | 1563 |       }
 | 
|---|
 | 1564 |       // pick candidates for other open lines as well
 | 
|---|
 | 1565 |       FindCandidatesforOpenLines(RADIUS, LC);
 | 
|---|
| [474961] | 1566 |     }
 | 
|---|
| [6613ec] | 1567 |   }
 | 
|---|
 | 1568 |   delete (connectedClosestPoints);
 | 
|---|
 | 1569 | };
 | 
|---|
| [474961] | 1570 | 
 | 
|---|
| [6613ec] | 1571 | /** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
 | 
|---|
 | 1572 |  * \param *Sprinter next candidate to which internal open lines are set
 | 
|---|
 | 1573 |  * \param *OptCenter OptCenter for this candidate
 | 
|---|
 | 1574 |  */
 | 
|---|
 | 1575 | void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
 | 
|---|
 | 1576 | {
 | 
|---|
| [ce7bfd] | 1577 |   //Info FunctionInfo(__func__);
 | 
|---|
| [6613ec] | 1578 | 
 | 
|---|
| [735b1c] | 1579 |   pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->getNr());
 | 
|---|
| [6613ec] | 1580 |   for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
 | 
|---|
| [ce7bfd] | 1581 |     LOG(4, "DEBUG: Checking line " << *(FindLine->second) << " ...");
 | 
|---|
| [6613ec] | 1582 |     // If there is a line with less than two attached triangles, we don't need a new line.
 | 
|---|
 | 1583 |     if (FindLine->second->triangles.size() == 1) {
 | 
|---|
 | 1584 |       CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
 | 
|---|
 | 1585 |       if (!Finder->second->pointlist.empty())
 | 
|---|
| [ce7bfd] | 1586 |         LOG(4, "DEBUG: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << ".");
 | 
|---|
| [6613ec] | 1587 |       else {
 | 
|---|
| [ce7bfd] | 1588 |         LOG(4, "DEBUG: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter));
 | 
|---|
| [f04f11] | 1589 |         Finder->second->T = BTS;  // is last triangle
 | 
|---|
| [6613ec] | 1590 |         Finder->second->pointlist.push_back(Sprinter);
 | 
|---|
 | 1591 |         Finder->second->ShortestAngle = 0.;
 | 
|---|
| [8cbb97] | 1592 |         Finder->second->OptCenter = *OptCenter;
 | 
|---|
| [6613ec] | 1593 |       }
 | 
|---|
 | 1594 |     }
 | 
|---|
| [f67b6e] | 1595 |   }
 | 
|---|
| [1e168b] | 1596 | };
 | 
|---|
 | 1597 | 
 | 
|---|
| [f07f86d] | 1598 | /** If a given \a *triangle is degenerated, this adds both sides.
 | 
|---|
| [474961] | 1599 |  * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
 | 
|---|
| [f07f86d] | 1600 |  * Note that endpoints are stored in Tesselation::TPS
 | 
|---|
 | 1601 |  * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine
 | 
|---|
| [474961] | 1602 |  * \param RADIUS radius of sphere
 | 
|---|
| [6bd7e0] | 1603 |  * \param *LC pointer to LinkedCell_deprecated structure
 | 
|---|
| [474961] | 1604 |  */
 | 
|---|
| [6bd7e0] | 1605 | void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell_deprecated *LC)
 | 
|---|
| [474961] | 1606 | {
 | 
|---|
| [ce7bfd] | 1607 |   //Info FunctionInfo(__func__);
 | 
|---|
| [f07f86d] | 1608 |   Vector Center;
 | 
|---|
 | 1609 |   CandidateMap::const_iterator CandidateCheck = OpenLines.end();
 | 
|---|
| [711ac2] | 1610 |   BoundaryTriangleSet *triangle = NULL;
 | 
|---|
| [f07f86d] | 1611 | 
 | 
|---|
| [711ac2] | 1612 |   /// 1. Create or pick the lines for the first triangle
 | 
|---|
| [ce7bfd] | 1613 |   LOG(3, "DEBUG: Creating/Picking lines for first triangle ...");
 | 
|---|
| [6613ec] | 1614 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [711ac2] | 1615 |     BLS[i] = NULL;
 | 
|---|
| [ce7bfd] | 1616 |     LOG(3, "DEBUG: Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":");
 | 
|---|
| [6613ec] | 1617 |     AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
 | 
|---|
| [474961] | 1618 |   }
 | 
|---|
| [f07f86d] | 1619 | 
 | 
|---|
| [711ac2] | 1620 |   /// 2. create the first triangle and NormalVector and so on
 | 
|---|
| [ce7bfd] | 1621 |   LOG(3, "DEBUG: Adding first triangle with center at " << CandidateLine.OptCenter << " ...");
 | 
|---|
| [f07f86d] | 1622 |   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
 | 1623 |   AddTesselationTriangle();
 | 
|---|
| [711ac2] | 1624 | 
 | 
|---|
| [f07f86d] | 1625 |   // create normal vector
 | 
|---|
| [d74077] | 1626 |   BTS->GetCenter(Center);
 | 
|---|
| [8cbb97] | 1627 |   Center -= CandidateLine.OptCenter;
 | 
|---|
 | 1628 |   BTS->SphereCenter = CandidateLine.OptCenter;
 | 
|---|
| [f07f86d] | 1629 |   BTS->GetNormalVector(Center);
 | 
|---|
 | 1630 |   // give some verbose output about the whole procedure
 | 
|---|
 | 1631 |   if (CandidateLine.T != NULL)
 | 
|---|
| [ce7bfd] | 1632 |     LOG(2, "DEBUG: --> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << ".");
 | 
|---|
| [f07f86d] | 1633 |   else
 | 
|---|
| [ce7bfd] | 1634 |     LOG(2, "DEBUG: --> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle.");
 | 
|---|
| [f07f86d] | 1635 |   triangle = BTS;
 | 
|---|
 | 1636 | 
 | 
|---|
| [711ac2] | 1637 |   /// 3. Gather candidates for each new line
 | 
|---|
| [ce7bfd] | 1638 |   LOG(3, "DEBUG: Adding candidates to new lines ...");
 | 
|---|
| [6613ec] | 1639 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [ce7bfd] | 1640 |     LOG(4, "DEBUG: Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":");
 | 
|---|
| [f07f86d] | 1641 |     CandidateCheck = OpenLines.find(BLS[i]);
 | 
|---|
 | 1642 |     if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
 | 
|---|
 | 1643 |       if (CandidateCheck->second->T == NULL)
 | 
|---|
 | 1644 |         CandidateCheck->second->T = triangle;
 | 
|---|
 | 1645 |       FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC);
 | 
|---|
| [474961] | 1646 |     }
 | 
|---|
| [f07f86d] | 1647 |   }
 | 
|---|
| [d5fea7] | 1648 | 
 | 
|---|
| [711ac2] | 1649 |   /// 4. Create or pick the lines for the second triangle
 | 
|---|
| [ce7bfd] | 1650 |   LOG(3, "DEBUG: Creating/Picking lines for second triangle ...");
 | 
|---|
| [6613ec] | 1651 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [ce7bfd] | 1652 |     LOG(4, "DEBUG: Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":");
 | 
|---|
| [6613ec] | 1653 |     AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
 | 
|---|
| [474961] | 1654 |   }
 | 
|---|
| [f07f86d] | 1655 | 
 | 
|---|
| [711ac2] | 1656 |   /// 5. create the second triangle and NormalVector and so on
 | 
|---|
| [ce7bfd] | 1657 |   LOG(3, "DEBUG: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ...");
 | 
|---|
| [f07f86d] | 1658 |   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
 | 1659 |   AddTesselationTriangle();
 | 
|---|
| [711ac2] | 1660 | 
 | 
|---|
| [8cbb97] | 1661 |   BTS->SphereCenter = CandidateLine.OtherOptCenter;
 | 
|---|
| [f07f86d] | 1662 |   // create normal vector in other direction
 | 
|---|
| [8cbb97] | 1663 |   BTS->GetNormalVector(triangle->NormalVector);
 | 
|---|
| [f07f86d] | 1664 |   BTS->NormalVector.Scale(-1.);
 | 
|---|
 | 1665 |   // give some verbose output about the whole procedure
 | 
|---|
 | 1666 |   if (CandidateLine.T != NULL)
 | 
|---|
| [ce7bfd] | 1667 |     LOG(2, "DEBUG: --> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << ".");
 | 
|---|
| [f07f86d] | 1668 |   else
 | 
|---|
| [ce7bfd] | 1669 |     LOG(2, "DEBUG: --> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle.");
 | 
|---|
| [f07f86d] | 1670 | 
 | 
|---|
| [711ac2] | 1671 |   /// 6. Adding triangle to new lines
 | 
|---|
| [ce7bfd] | 1672 |   LOG(3, "DEBUG: Adding second triangles to new lines ...");
 | 
|---|
| [6613ec] | 1673 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [ce7bfd] | 1674 |     LOG(4, "DEBUG: Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":");
 | 
|---|
| [711ac2] | 1675 |     CandidateCheck = OpenLines.find(BLS[i]);
 | 
|---|
 | 1676 |     if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
 | 
|---|
 | 1677 |       if (CandidateCheck->second->T == NULL)
 | 
|---|
 | 1678 |         CandidateCheck->second->T = BTS;
 | 
|---|
 | 1679 |     }
 | 
|---|
 | 1680 |   }
 | 
|---|
| [6613ec] | 1681 | }
 | 
|---|
 | 1682 | ;
 | 
|---|
| [474961] | 1683 | 
 | 
|---|
 | 1684 | /** Adds a triangle to the Tesselation structure from three given TesselPoint's.
 | 
|---|
| [f07f86d] | 1685 |  * Note that endpoints are in Tesselation::TPS.
 | 
|---|
 | 1686 |  * \param CandidateLine CandidateForTesselation structure contains other information
 | 
|---|
| [6613ec] | 1687 |  * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
 | 
|---|
| [474961] | 1688 |  */
 | 
|---|
| [6613ec] | 1689 | void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
 | 
|---|
| [474961] | 1690 | {
 | 
|---|
| [ce7bfd] | 1691 |   //Info FunctionInfo(__func__);
 | 
|---|
| [f07f86d] | 1692 |   Vector Center;
 | 
|---|
| [6613ec] | 1693 |   Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
 | 
|---|
| [474961] | 1694 | 
 | 
|---|
 | 1695 |   // add the lines
 | 
|---|
| [6613ec] | 1696 |   AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
 | 
|---|
 | 1697 |   AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
 | 
|---|
 | 1698 |   AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
 | 
|---|
| [474961] | 1699 | 
 | 
|---|
 | 1700 |   // add the triangles
 | 
|---|
 | 1701 |   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
 | 1702 |   AddTesselationTriangle();
 | 
|---|
| [f07f86d] | 1703 | 
 | 
|---|
 | 1704 |   // create normal vector
 | 
|---|
| [d74077] | 1705 |   BTS->GetCenter(Center);
 | 
|---|
| [8cbb97] | 1706 |   Center.SubtractVector(*OptCenter);
 | 
|---|
 | 1707 |   BTS->SphereCenter = *OptCenter;
 | 
|---|
| [f07f86d] | 1708 |   BTS->GetNormalVector(Center);
 | 
|---|
 | 1709 | 
 | 
|---|
 | 1710 |   // give some verbose output about the whole procedure
 | 
|---|
 | 1711 |   if (CandidateLine.T != NULL)
 | 
|---|
| [ce7bfd] | 1712 |     LOG(2, "INFO: --> New" << ((type == OtherOpt) ? " degenerate " : " ") << "triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << ".");
 | 
|---|
| [f07f86d] | 1713 |   else
 | 
|---|
| [ce7bfd] | 1714 |     LOG(2, "INFO: --> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle.");
 | 
|---|
| [6613ec] | 1715 | }
 | 
|---|
 | 1716 | ;
 | 
|---|
| [474961] | 1717 | 
 | 
|---|
| [16d866] | 1718 | /** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
 | 
|---|
 | 1719 |  * We look whether the closest point on \a *Base with respect to the other baseline is outside
 | 
|---|
 | 1720 |  * of the segment formed by both endpoints (concave) or not (convex).
 | 
|---|
 | 1721 |  * \param *out output stream for debugging
 | 
|---|
 | 1722 |  * \param *Base line to be flipped
 | 
|---|
| [57066a] | 1723 |  * \return NULL - convex, otherwise endpoint that makes it concave
 | 
|---|
| [16d866] | 1724 |  */
 | 
|---|
| [e138de] | 1725 | class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
 | 
|---|
| [16d866] | 1726 | {
 | 
|---|
| [ce7bfd] | 1727 |   //Info FunctionInfo(__func__);
 | 
|---|
| [16d866] | 1728 |   class BoundaryPointSet *Spot = NULL;
 | 
|---|
 | 1729 |   class BoundaryLineSet *OtherBase;
 | 
|---|
| [0077b5] | 1730 |   Vector *ClosestPoint;
 | 
|---|
| [16d866] | 1731 | 
 | 
|---|
| [6613ec] | 1732 |   int m = 0;
 | 
|---|
 | 1733 |   for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
 | 
|---|
 | 1734 |     for (int j = 0; j < 3; j++) // all of their endpoints and baselines
 | 
|---|
| [16d866] | 1735 |       if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
 | 
|---|
 | 1736 |         BPS[m++] = runner->second->endpoints[j];
 | 
|---|
| [6613ec] | 1737 |   OtherBase = new class BoundaryLineSet(BPS, -1);
 | 
|---|
| [16d866] | 1738 | 
 | 
|---|
| [ce7bfd] | 1739 |   LOG(3, "DEBUG: Current base line is " << *Base << ".");
 | 
|---|
 | 1740 |   LOG(3, "DEBUG: Other base line is " << *OtherBase << ".");
 | 
|---|
| [16d866] | 1741 | 
 | 
|---|
 | 1742 |   // get the closest point on each line to the other line
 | 
|---|
| [e138de] | 1743 |   ClosestPoint = GetClosestPointBetweenLine(Base, OtherBase);
 | 
|---|
| [16d866] | 1744 | 
 | 
|---|
 | 1745 |   // delete the temporary other base line
 | 
|---|
| [6613ec] | 1746 |   delete (OtherBase);
 | 
|---|
| [16d866] | 1747 | 
 | 
|---|
 | 1748 |   // get the distance vector from Base line to OtherBase line
 | 
|---|
| [0077b5] | 1749 |   Vector DistanceToIntersection[2], BaseLine;
 | 
|---|
 | 1750 |   double distance[2];
 | 
|---|
| [d74077] | 1751 |   BaseLine = (Base->endpoints[1]->node->getPosition()) - (Base->endpoints[0]->node->getPosition());
 | 
|---|
| [6613ec] | 1752 |   for (int i = 0; i < 2; i++) {
 | 
|---|
| [d74077] | 1753 |     DistanceToIntersection[i] = (*ClosestPoint) - (Base->endpoints[i]->node->getPosition());
 | 
|---|
| [273382] | 1754 |     distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]);
 | 
|---|
| [16d866] | 1755 |   }
 | 
|---|
| [6613ec] | 1756 |   delete (ClosestPoint);
 | 
|---|
 | 1757 |   if ((distance[0] * distance[1]) > 0) { // have same sign?
 | 
|---|
| [ce7bfd] | 1758 |     LOG(4, "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave.");
 | 
|---|
| [0077b5] | 1759 |     if (distance[0] < distance[1]) {
 | 
|---|
 | 1760 |       Spot = Base->endpoints[0];
 | 
|---|
 | 1761 |     } else {
 | 
|---|
 | 1762 |       Spot = Base->endpoints[1];
 | 
|---|
 | 1763 |     }
 | 
|---|
| [16d866] | 1764 |     return Spot;
 | 
|---|
| [6613ec] | 1765 |   } else { // different sign, i.e. we are in between
 | 
|---|
| [ce7bfd] | 1766 |     LOG(3, "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex.");
 | 
|---|
| [16d866] | 1767 |     return NULL;
 | 
|---|
 | 1768 |   }
 | 
|---|
 | 1769 | 
 | 
|---|
| [6613ec] | 1770 | }
 | 
|---|
 | 1771 | ;
 | 
|---|
| [16d866] | 1772 | 
 | 
|---|
| [776b64] | 1773 | void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
 | 
|---|
| [0077b5] | 1774 | {
 | 
|---|
| [ce7bfd] | 1775 |   //Info FunctionInfo(__func__);
 | 
|---|
| [0077b5] | 1776 |   // print all lines
 | 
|---|
| [ce7bfd] | 1777 |   std::stringstream output;
 | 
|---|
| [6613ec] | 1778 |   for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
 | 
|---|
| [ce7bfd] | 1779 |     output << " " << *(PointRunner->second);
 | 
|---|
 | 1780 |   LOG(3, "DEBUG: Printing all boundary points for debugging:" << output.str());
 | 
|---|
| [6613ec] | 1781 | }
 | 
|---|
 | 1782 | ;
 | 
|---|
| [0077b5] | 1783 | 
 | 
|---|
| [776b64] | 1784 | void Tesselation::PrintAllBoundaryLines(ofstream *out) const
 | 
|---|
| [0077b5] | 1785 | {
 | 
|---|
| [ce7bfd] | 1786 |   //Info FunctionInfo(__func__);
 | 
|---|
| [0077b5] | 1787 |   // print all lines
 | 
|---|
| [ce7bfd] | 1788 |   std::stringstream output;
 | 
|---|
| [776b64] | 1789 |   for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
 | 
|---|
| [ce7bfd] | 1790 |     output << " " << *(LineRunner->second);
 | 
|---|
 | 1791 |   LOG(3, "DEBUG: Printing all boundary lines for debugging:" << output.str());
 | 
|---|
| [6613ec] | 1792 | }
 | 
|---|
 | 1793 | ;
 | 
|---|
| [0077b5] | 1794 | 
 | 
|---|
| [776b64] | 1795 | void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
 | 
|---|
| [0077b5] | 1796 | {
 | 
|---|
| [ce7bfd] | 1797 |   //Info FunctionInfo(__func__);
 | 
|---|
| [0077b5] | 1798 |   // print all triangles
 | 
|---|
| [ce7bfd] | 1799 |   std::stringstream output;
 | 
|---|
| [776b64] | 1800 |   for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
 | 
|---|
| [ce7bfd] | 1801 |     output << " " << *(TriangleRunner->second);
 | 
|---|
 | 1802 |   LOG(3, "DEBUG: Printing all boundary triangles for debugging:" << output.str());
 | 
|---|
| [6613ec] | 1803 | }
 | 
|---|
 | 1804 | ;
 | 
|---|
| [357fba] | 1805 | 
 | 
|---|
| [16d866] | 1806 | /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
 | 
|---|
| [357fba] | 1807 |  * \param *out output stream for debugging
 | 
|---|
| [16d866] | 1808 |  * \param *Base line to be flipped
 | 
|---|
| [57066a] | 1809 |  * \return volume change due to flipping (0 - then no flipped occured)
 | 
|---|
| [357fba] | 1810 |  */
 | 
|---|
| [e138de] | 1811 | double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
 | 
|---|
| [357fba] | 1812 | {
 | 
|---|
| [ce7bfd] | 1813 |   //Info FunctionInfo(__func__);
 | 
|---|
| [16d866] | 1814 |   class BoundaryLineSet *OtherBase;
 | 
|---|
 | 1815 |   Vector *ClosestPoint[2];
 | 
|---|
| [57066a] | 1816 |   double volume;
 | 
|---|
| [16d866] | 1817 | 
 | 
|---|
| [6613ec] | 1818 |   int m = 0;
 | 
|---|
 | 1819 |   for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
 | 
|---|
 | 1820 |     for (int j = 0; j < 3; j++) // all of their endpoints and baselines
 | 
|---|
| [16d866] | 1821 |       if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
 | 
|---|
 | 1822 |         BPS[m++] = runner->second->endpoints[j];
 | 
|---|
| [6613ec] | 1823 |   OtherBase = new class BoundaryLineSet(BPS, -1);
 | 
|---|
| [62bb91] | 1824 | 
 | 
|---|
| [ce7bfd] | 1825 |   LOG(3, "DEBUG: Current base line is " << *Base << ".");
 | 
|---|
 | 1826 |   LOG(3, "DEBUG: Other base line is " << *OtherBase << ".");
 | 
|---|
| [62bb91] | 1827 | 
 | 
|---|
| [16d866] | 1828 |   // get the closest point on each line to the other line
 | 
|---|
| [e138de] | 1829 |   ClosestPoint[0] = GetClosestPointBetweenLine(Base, OtherBase);
 | 
|---|
 | 1830 |   ClosestPoint[1] = GetClosestPointBetweenLine(OtherBase, Base);
 | 
|---|
| [16d866] | 1831 | 
 | 
|---|
 | 1832 |   // get the distance vector from Base line to OtherBase line
 | 
|---|
| [273382] | 1833 |   Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]);
 | 
|---|
| [16d866] | 1834 | 
 | 
|---|
| [57066a] | 1835 |   // calculate volume
 | 
|---|
| [d74077] | 1836 |   volume = CalculateVolumeofGeneralTetraeder(Base->endpoints[1]->node->getPosition(), OtherBase->endpoints[0]->node->getPosition(), OtherBase->endpoints[1]->node->getPosition(), Base->endpoints[0]->node->getPosition());
 | 
|---|
| [57066a] | 1837 | 
 | 
|---|
| [0077b5] | 1838 |   // delete the temporary other base line and the closest points
 | 
|---|
| [6613ec] | 1839 |   delete (ClosestPoint[0]);
 | 
|---|
 | 1840 |   delete (ClosestPoint[1]);
 | 
|---|
 | 1841 |   delete (OtherBase);
 | 
|---|
| [16d866] | 1842 | 
 | 
|---|
 | 1843 |   if (Distance.NormSquared() < MYEPSILON) { // check for intersection
 | 
|---|
| [ce7bfd] | 1844 |     LOG(3, "REJECT: Both lines have an intersection: Nothing to do.");
 | 
|---|
| [16d866] | 1845 |     return false;
 | 
|---|
 | 1846 |   } else { // check for sign against BaseLineNormal
 | 
|---|
 | 1847 |     Vector BaseLineNormal;
 | 
|---|
| [5c7bf8] | 1848 |     BaseLineNormal.Zero();
 | 
|---|
 | 1849 |     if (Base->triangles.size() < 2) {
 | 
|---|
| [47d041] | 1850 |       ELOG(1, "Less than two triangles are attached to this baseline!");
 | 
|---|
| [57066a] | 1851 |       return 0.;
 | 
|---|
| [5c7bf8] | 1852 |     }
 | 
|---|
 | 1853 |     for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
 | 
|---|
| [ce7bfd] | 1854 |     LOG(4, "DEBUG: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << ".");
 | 
|---|
| [273382] | 1855 |       BaseLineNormal += (runner->second->NormalVector);
 | 
|---|
| [5c7bf8] | 1856 |     }
 | 
|---|
| [6613ec] | 1857 |     BaseLineNormal.Scale(1. / 2.);
 | 
|---|
| [357fba] | 1858 | 
 | 
|---|
| [273382] | 1859 |     if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
 | 
|---|
| [ce7bfd] | 1860 |       LOG(3, "ACCEPT: Other base line would be higher: Flipping baseline.");
 | 
|---|
| [57066a] | 1861 |       // calculate volume summand as a general tetraeder
 | 
|---|
 | 1862 |       return volume;
 | 
|---|
| [6613ec] | 1863 |     } else { // Base higher than OtherBase -> do nothing
 | 
|---|
| [ce7bfd] | 1864 |       LOG(3, "REJECT: Base line is higher: Nothing to do.");
 | 
|---|
| [57066a] | 1865 |       return 0.;
 | 
|---|
| [16d866] | 1866 |     }
 | 
|---|
 | 1867 |   }
 | 
|---|
| [6613ec] | 1868 | }
 | 
|---|
 | 1869 | ;
 | 
|---|
| [357fba] | 1870 | 
 | 
|---|
| [16d866] | 1871 | /** For a given baseline and its two connected triangles, flips the baseline.
 | 
|---|
 | 1872 |  * I.e. we create the new baseline between the other two endpoints of these four
 | 
|---|
 | 1873 |  * endpoints and reconstruct the two triangles accordingly.
 | 
|---|
 | 1874 |  * \param *out output stream for debugging
 | 
|---|
 | 1875 |  * \param *Base line to be flipped
 | 
|---|
| [57066a] | 1876 |  * \return pointer to allocated new baseline - flipping successful, NULL - something went awry
 | 
|---|
| [16d866] | 1877 |  */
 | 
|---|
| [e138de] | 1878 | class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
 | 
|---|
| [16d866] | 1879 | {
 | 
|---|
| [ce7bfd] | 1880 |   //Info FunctionInfo(__func__);
 | 
|---|
| [16d866] | 1881 |   class BoundaryLineSet *OldLines[4], *NewLine;
 | 
|---|
 | 1882 |   class BoundaryPointSet *OldPoints[2];
 | 
|---|
 | 1883 |   Vector BaseLineNormal;
 | 
|---|
 | 1884 |   int OldTriangleNrs[2], OldBaseLineNr;
 | 
|---|
| [6613ec] | 1885 |   int i, m;
 | 
|---|
| [16d866] | 1886 | 
 | 
|---|
 | 1887 |   // calculate NormalVector for later use
 | 
|---|
 | 1888 |   BaseLineNormal.Zero();
 | 
|---|
 | 1889 |   if (Base->triangles.size() < 2) {
 | 
|---|
| [47d041] | 1890 |     ELOG(1, "Less than two triangles are attached to this baseline!");
 | 
|---|
| [57066a] | 1891 |     return NULL;
 | 
|---|
| [16d866] | 1892 |   }
 | 
|---|
 | 1893 |   for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
 | 
|---|
| [47d041] | 1894 |     LOG(1, "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << ".");
 | 
|---|
| [273382] | 1895 |     BaseLineNormal += (runner->second->NormalVector);
 | 
|---|
| [16d866] | 1896 |   }
 | 
|---|
| [6613ec] | 1897 |   BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
 | 
|---|
| [16d866] | 1898 | 
 | 
|---|
 | 1899 |   // get the two triangles
 | 
|---|
 | 1900 |   // gather four endpoints and four lines
 | 
|---|
| [6613ec] | 1901 |   for (int j = 0; j < 4; j++)
 | 
|---|
| [16d866] | 1902 |     OldLines[j] = NULL;
 | 
|---|
| [6613ec] | 1903 |   for (int j = 0; j < 2; j++)
 | 
|---|
| [16d866] | 1904 |     OldPoints[j] = NULL;
 | 
|---|
| [6613ec] | 1905 |   i = 0;
 | 
|---|
 | 1906 |   m = 0;
 | 
|---|
| [47d041] | 1907 | 
 | 
|---|
 | 1908 |   // print OldLines and OldPoints for debugging
 | 
|---|
| [ce7bfd] | 1909 |   if (DoLog(3)) {
 | 
|---|
| [47d041] | 1910 |     std::stringstream output;
 | 
|---|
 | 1911 |     for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
 | 
|---|
 | 1912 |       for (int j = 0; j < 3; j++) // all of their endpoints and baselines
 | 
|---|
 | 1913 |         if (runner->second->lines[j] != Base) // pick not the central baseline
 | 
|---|
 | 1914 |           output << *runner->second->lines[j] << "\t";
 | 
|---|
| [ce7bfd] | 1915 |     LOG(3, "DEBUG: The four old lines are: " << output.str());
 | 
|---|
| [47d041] | 1916 |   }
 | 
|---|
| [ce7bfd] | 1917 |   if (DoLog(3)) {
 | 
|---|
| [47d041] | 1918 |     std::stringstream output;
 | 
|---|
 | 1919 |     for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
 | 
|---|
 | 1920 |       for (int j = 0; j < 3; j++) // all of their endpoints and baselines
 | 
|---|
 | 1921 |         if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
 | 
|---|
 | 1922 |           output << *runner->second->endpoints[j] << "\t";
 | 
|---|
| [ce7bfd] | 1923 |     LOG(3, "DEBUG: The two old points are: " << output.str());
 | 
|---|
| [47d041] | 1924 |   }
 | 
|---|
 | 1925 | 
 | 
|---|
 | 1926 |   // index OldLines and OldPoints
 | 
|---|
| [6613ec] | 1927 |   for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
 | 
|---|
 | 1928 |     for (int j = 0; j < 3; j++) // all of their endpoints and baselines
 | 
|---|
| [47d041] | 1929 |       if (runner->second->lines[j] != Base) // pick not the central baseline
 | 
|---|
| [16d866] | 1930 |         OldLines[i++] = runner->second->lines[j];
 | 
|---|
| [6613ec] | 1931 |   for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
 | 
|---|
 | 1932 |     for (int j = 0; j < 3; j++) // all of their endpoints and baselines
 | 
|---|
| [47d041] | 1933 |       if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
 | 
|---|
| [16d866] | 1934 |         OldPoints[m++] = runner->second->endpoints[j];
 | 
|---|
 | 1935 | 
 | 
|---|
 | 1936 |   // check whether everything is in place to create new lines and triangles
 | 
|---|
| [6613ec] | 1937 |   if (i < 4) {
 | 
|---|
| [47d041] | 1938 |     ELOG(1, "We have not gathered enough baselines!");
 | 
|---|
| [57066a] | 1939 |     return NULL;
 | 
|---|
| [16d866] | 1940 |   }
 | 
|---|
| [6613ec] | 1941 |   for (int j = 0; j < 4; j++)
 | 
|---|
| [16d866] | 1942 |     if (OldLines[j] == NULL) {
 | 
|---|
| [47d041] | 1943 |       ELOG(1, "We have not gathered enough baselines!");
 | 
|---|
| [57066a] | 1944 |       return NULL;
 | 
|---|
| [16d866] | 1945 |     }
 | 
|---|
| [6613ec] | 1946 |   for (int j = 0; j < 2; j++)
 | 
|---|
| [16d866] | 1947 |     if (OldPoints[j] == NULL) {
 | 
|---|
| [47d041] | 1948 |       ELOG(1, "We have not gathered enough endpoints!");
 | 
|---|
| [57066a] | 1949 |       return NULL;
 | 
|---|
| [357fba] | 1950 |     }
 | 
|---|
| [16d866] | 1951 | 
 | 
|---|
 | 1952 |   // remove triangles and baseline removes itself
 | 
|---|
| [ce7bfd] | 1953 |   LOG(3, "DEBUG: Deleting baseline " << *Base << " from global list.");
 | 
|---|
| [16d866] | 1954 |   OldBaseLineNr = Base->Nr;
 | 
|---|
| [6613ec] | 1955 |   m = 0;
 | 
|---|
| [accebe] | 1956 |   // first obtain all triangle to delete ... (otherwise we pull the carpet (Base) from under the for-loop's feet)
 | 
|---|
 | 1957 |   list <BoundaryTriangleSet *> TrianglesOfBase;
 | 
|---|
 | 1958 |   for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); ++runner)
 | 
|---|
 | 1959 |     TrianglesOfBase.push_back(runner->second);
 | 
|---|
 | 1960 |   // .. then delete each triangle (which deletes the line as well)
 | 
|---|
 | 1961 |   for (list <BoundaryTriangleSet *>::iterator runner = TrianglesOfBase.begin(); !TrianglesOfBase.empty(); runner = TrianglesOfBase.begin()) {
 | 
|---|
| [ce7bfd] | 1962 |     LOG(3, "DEBUG: Deleting triangle " << *(*runner) << ".");
 | 
|---|
| [accebe] | 1963 |     OldTriangleNrs[m++] = (*runner)->Nr;
 | 
|---|
 | 1964 |     RemoveTesselationTriangle((*runner));
 | 
|---|
 | 1965 |     TrianglesOfBase.erase(runner);
 | 
|---|
| [16d866] | 1966 |   }
 | 
|---|
 | 1967 | 
 | 
|---|
 | 1968 |   // construct new baseline (with same number as old one)
 | 
|---|
 | 1969 |   BPS[0] = OldPoints[0];
 | 
|---|
 | 1970 |   BPS[1] = OldPoints[1];
 | 
|---|
 | 1971 |   NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
 | 
|---|
 | 1972 |   LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
 | 
|---|
| [ce7bfd] | 1973 |   LOG(3, "DEBUG: Created new baseline " << *NewLine << ".");
 | 
|---|
| [16d866] | 1974 | 
 | 
|---|
 | 1975 |   // construct new triangles with flipped baseline
 | 
|---|
| [6613ec] | 1976 |   i = -1;
 | 
|---|
| [16d866] | 1977 |   if (OldLines[0]->IsConnectedTo(OldLines[2]))
 | 
|---|
| [6613ec] | 1978 |     i = 2;
 | 
|---|
| [16d866] | 1979 |   if (OldLines[0]->IsConnectedTo(OldLines[3]))
 | 
|---|
| [6613ec] | 1980 |     i = 3;
 | 
|---|
 | 1981 |   if (i != -1) {
 | 
|---|
| [16d866] | 1982 |     BLS[0] = OldLines[0];
 | 
|---|
 | 1983 |     BLS[1] = OldLines[i];
 | 
|---|
 | 1984 |     BLS[2] = NewLine;
 | 
|---|
 | 1985 |     BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[0]);
 | 
|---|
 | 1986 |     BTS->GetNormalVector(BaseLineNormal);
 | 
|---|
| [7dea7c] | 1987 |     AddTesselationTriangle(OldTriangleNrs[0]);
 | 
|---|
| [ce7bfd] | 1988 |     LOG(3, "DEBUG: Created new triangle " << *BTS << ".");
 | 
|---|
| [16d866] | 1989 | 
 | 
|---|
| [6613ec] | 1990 |     BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
 | 
|---|
| [16d866] | 1991 |     BLS[1] = OldLines[1];
 | 
|---|
 | 1992 |     BLS[2] = NewLine;
 | 
|---|
 | 1993 |     BTS = new class BoundaryTriangleSet(BLS, OldTriangleNrs[1]);
 | 
|---|
 | 1994 |     BTS->GetNormalVector(BaseLineNormal);
 | 
|---|
| [7dea7c] | 1995 |     AddTesselationTriangle(OldTriangleNrs[1]);
 | 
|---|
| [ce7bfd] | 1996 |     LOG(3, "DEBUG: Created new triangle " << *BTS << ".");
 | 
|---|
| [16d866] | 1997 |   } else {
 | 
|---|
| [47d041] | 1998 |     ELOG(0, "The four old lines do not connect, something's utterly wrong here!");
 | 
|---|
| [57066a] | 1999 |     return NULL;
 | 
|---|
| [357fba] | 2000 |   }
 | 
|---|
| [16d866] | 2001 | 
 | 
|---|
| [57066a] | 2002 |   return NewLine;
 | 
|---|
| [6613ec] | 2003 | }
 | 
|---|
 | 2004 | ;
 | 
|---|
| [16d866] | 2005 | 
 | 
|---|
| [357fba] | 2006 | /** Finds the second point of starting triangle.
 | 
|---|
 | 2007 |  * \param *a first node
 | 
|---|
 | 2008 |  * \param Oben vector indicating the outside
 | 
|---|
| [f1cccd] | 2009 |  * \param OptCandidate reference to recommended candidate on return
 | 
|---|
| [357fba] | 2010 |  * \param Storage[3] array storing angles and other candidate information
 | 
|---|
 | 2011 |  * \param RADIUS radius of virtual sphere
 | 
|---|
| [6bd7e0] | 2012 |  * \param *LC LinkedCell_deprecated structure with neighbouring points
 | 
|---|
| [357fba] | 2013 |  */
 | 
|---|
| [6bd7e0] | 2014 | void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell_deprecated *LC)
 | 
|---|
| [357fba] | 2015 | {
 | 
|---|
| [ce7bfd] | 2016 |   //Info FunctionInfo(__func__);
 | 
|---|
| [357fba] | 2017 |   Vector AngleCheck;
 | 
|---|
| [57066a] | 2018 |   class TesselPoint* Candidate = NULL;
 | 
|---|
| [776b64] | 2019 |   double norm = -1.;
 | 
|---|
 | 2020 |   double angle = 0.;
 | 
|---|
 | 2021 |   int N[NDIM];
 | 
|---|
 | 2022 |   int Nlower[NDIM];
 | 
|---|
 | 2023 |   int Nupper[NDIM];
 | 
|---|
| [357fba] | 2024 | 
 | 
|---|
| [6613ec] | 2025 |   if (LC->SetIndexToNode(a)) { // get cell for the starting point
 | 
|---|
 | 2026 |     for (int i = 0; i < NDIM; i++) // store indices of this cell
 | 
|---|
| [357fba] | 2027 |       N[i] = LC->n[i];
 | 
|---|
 | 2028 |   } else {
 | 
|---|
| [47d041] | 2029 |     ELOG(1, "Point " << *a << " is not found in cell " << LC->index << ".");
 | 
|---|
| [357fba] | 2030 |     return;
 | 
|---|
 | 2031 |   }
 | 
|---|
| [62bb91] | 2032 |   // then go through the current and all neighbouring cells and check the contained points for possible candidates
 | 
|---|
| [6613ec] | 2033 |   for (int i = 0; i < NDIM; i++) {
 | 
|---|
 | 2034 |     Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
 | 
|---|
 | 2035 |     Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
 | 
|---|
| [357fba] | 2036 |   }
 | 
|---|
| [ce7bfd] | 2037 |   LOG(3, "DEBUG: LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :" << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], ");
 | 
|---|
| [357fba] | 2038 | 
 | 
|---|
 | 2039 |   for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
 | 
|---|
 | 2040 |     for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
 | 
|---|
 | 2041 |       for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
 | 
|---|
| [34c43a] | 2042 |         const TesselPointSTLList *List = LC->GetCurrentCell();
 | 
|---|
| [47d041] | 2043 |         //LOG(1, "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << ".");
 | 
|---|
| [357fba] | 2044 |         if (List != NULL) {
 | 
|---|
| [34c43a] | 2045 |           for (TesselPointSTLList::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
 | 
|---|
| [357fba] | 2046 |             Candidate = (*Runner);
 | 
|---|
 | 2047 |             // check if we only have one unique point yet ...
 | 
|---|
 | 2048 |             if (a != Candidate) {
 | 
|---|
 | 2049 |               // Calculate center of the circle with radius RADIUS through points a and Candidate
 | 
|---|
| [f1cccd] | 2050 |               Vector OrthogonalizedOben, aCandidate, Center;
 | 
|---|
| [357fba] | 2051 |               double distance, scaleFactor;
 | 
|---|
 | 2052 | 
 | 
|---|
| [273382] | 2053 |               OrthogonalizedOben = Oben;
 | 
|---|
| [d74077] | 2054 |               aCandidate = (a->getPosition()) - (Candidate->getPosition());
 | 
|---|
| [273382] | 2055 |               OrthogonalizedOben.ProjectOntoPlane(aCandidate);
 | 
|---|
| [357fba] | 2056 |               OrthogonalizedOben.Normalize();
 | 
|---|
| [f1cccd] | 2057 |               distance = 0.5 * aCandidate.Norm();
 | 
|---|
| [357fba] | 2058 |               scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance)));
 | 
|---|
 | 2059 |               OrthogonalizedOben.Scale(scaleFactor);
 | 
|---|
 | 2060 | 
 | 
|---|
| [d74077] | 2061 |               Center = 0.5 * ((Candidate->getPosition()) + (a->getPosition()));
 | 
|---|
| [273382] | 2062 |               Center += OrthogonalizedOben;
 | 
|---|
| [357fba] | 2063 | 
 | 
|---|
| [d74077] | 2064 |               AngleCheck = Center - (a->getPosition());
 | 
|---|
| [f1cccd] | 2065 |               norm = aCandidate.Norm();
 | 
|---|
| [357fba] | 2066 |               // second point shall have smallest angle with respect to Oben vector
 | 
|---|
| [6613ec] | 2067 |               if (norm < RADIUS * 2.) {
 | 
|---|
| [273382] | 2068 |                 angle = AngleCheck.Angle(Oben);
 | 
|---|
| [357fba] | 2069 |                 if (angle < Storage[0]) {
 | 
|---|
| [47d041] | 2070 |                   //LOG(1, "INFO: Old values of Storage is " << Storage[0] << ", " << Storage[1]);
 | 
|---|
| [ce7bfd] | 2071 |                   LOG(4, "DEBUG: Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".");
 | 
|---|
| [f1cccd] | 2072 |                   OptCandidate = Candidate;
 | 
|---|
| [357fba] | 2073 |                   Storage[0] = angle;
 | 
|---|
| [ce7bfd] | 2074 |                   //LOG(4, "DEBUG: Changing something in  Storage is " << Storage[0] << ", " << Storage[1]);
 | 
|---|
| [357fba] | 2075 |                 } else {
 | 
|---|
| [ce7bfd] | 2076 |                   //LOG(4, "DEBUG: Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate);
 | 
|---|
| [357fba] | 2077 |                 }
 | 
|---|
 | 2078 |               } else {
 | 
|---|
| [ce7bfd] | 2079 |                 //LOG(4, "DEBUG: Current candidate is " << *Candidate << ": Refused due to Radius " << norm);
 | 
|---|
| [357fba] | 2080 |               }
 | 
|---|
 | 2081 |             } else {
 | 
|---|
| [ce7bfd] | 2082 |               //LOG(4, "DEBUG: Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << ".");
 | 
|---|
| [357fba] | 2083 |             }
 | 
|---|
 | 2084 |           }
 | 
|---|
 | 2085 |         } else {
 | 
|---|
| [ce7bfd] | 2086 |           LOG(4, "DEBUG: Linked cell list is empty.");
 | 
|---|
| [357fba] | 2087 |         }
 | 
|---|
 | 2088 |       }
 | 
|---|
| [6613ec] | 2089 | }
 | 
|---|
 | 2090 | ;
 | 
|---|
| [357fba] | 2091 | 
 | 
|---|
 | 2092 | /** This recursive function finds a third point, to form a triangle with two given ones.
 | 
|---|
 | 2093 |  * Note that this function is for the starting triangle.
 | 
|---|
 | 2094 |  * The idea is as follows: A sphere with fixed radius is (almost) uniquely defined in space by three points
 | 
|---|
 | 2095 |  * that sit on its boundary. Hence, when two points are given and we look for the (next) third point, then
 | 
|---|
 | 2096 |  * the center of the sphere is still fixed up to a single parameter. The band of possible values
 | 
|---|
 | 2097 |  * describes a circle in 3D-space. The old center of the sphere for the current base triangle gives
 | 
|---|
 | 2098 |  * us the "null" on this circle, the new center of the candidate point will be some way along this
 | 
|---|
 | 2099 |  * circle. The shorter the way the better is the candidate. Note that the direction is clearly given
 | 
|---|
 | 2100 |  * by the normal vector of the base triangle that always points outwards by construction.
 | 
|---|
 | 2101 |  * Hence, we construct a Center of this circle which sits right in the middle of the current base line.
 | 
|---|
 | 2102 |  * We construct the normal vector that defines the plane this circle lies in, it is just in the
 | 
|---|
 | 2103 |  * direction of the baseline. And finally, we need the radius of the circle, which is given by the rest
 | 
|---|
 | 2104 |  * with respect to the length of the baseline and the sphere's fixed \a RADIUS.
 | 
|---|
 | 2105 |  * Note that there is one difficulty: The circumcircle is uniquely defined, but for the circumsphere's center
 | 
|---|
 | 2106 |  * there are two possibilities which becomes clear from the construction as seen below. Hence, we must check
 | 
|---|
 | 2107 |  * both.
 | 
|---|
 | 2108 |  * Note also that the acos() function is not unique on [0, 2.*M_PI). Hence, we need an additional check
 | 
|---|
 | 2109 |  * to decide for one of the two possible angles. Therefore we need a SearchDirection and to make this check
 | 
|---|
 | 2110 |  * sensible we need OldSphereCenter to be orthogonal to it. Either we construct SearchDirection orthogonal
 | 
|---|
 | 2111 |  * right away, or -- what we do here -- we rotate the relative sphere centers such that this orthogonality
 | 
|---|
 | 2112 |  * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether
 | 
|---|
 | 2113 |  * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI).
 | 
|---|
| [f1cccd] | 2114 |  * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa FindStartingTriangle())
 | 
|---|
| [357fba] | 2115 |  * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
 | 
|---|
 | 2116 |  * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
 | 
|---|
| [f67b6e] | 2117 |  * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
 | 
|---|
| [09898c] | 2118 |  * @param ThirdPoint third point to avoid in search
 | 
|---|
| [357fba] | 2119 |  * @param RADIUS radius of sphere
 | 
|---|
| [6bd7e0] | 2120 |  * @param *LC LinkedCell_deprecated structure with neighbouring points
 | 
|---|
| [357fba] | 2121 |  */
 | 
|---|
| [6bd7e0] | 2122 | void Tesselation::FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdPoint, const double RADIUS, const LinkedCell_deprecated *LC) const
 | 
|---|
| [357fba] | 2123 | {
 | 
|---|
| [ce7bfd] | 2124 |   //Info FunctionInfo(__func__);
 | 
|---|
| [6613ec] | 2125 |   Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
 | 
|---|
| [357fba] | 2126 |   Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
 | 
|---|
 | 2127 |   Vector SphereCenter;
 | 
|---|
| [6613ec] | 2128 |   Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
 | 
|---|
 | 2129 |   Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
 | 
|---|
 | 2130 |   Vector NewNormalVector; // normal vector of the Candidate's triangle
 | 
|---|
| [357fba] | 2131 |   Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
 | 
|---|
| [b998c3] | 2132 |   Vector RelativeOldSphereCenter;
 | 
|---|
 | 2133 |   Vector NewPlaneCenter;
 | 
|---|
| [357fba] | 2134 |   double CircleRadius; // radius of this circle
 | 
|---|
 | 2135 |   double radius;
 | 
|---|
| [b998c3] | 2136 |   double otherradius;
 | 
|---|
| [357fba] | 2137 |   double alpha, Otheralpha; // angles (i.e. parameter for the circle).
 | 
|---|
 | 2138 |   int N[NDIM], Nlower[NDIM], Nupper[NDIM];
 | 
|---|
 | 2139 |   TesselPoint *Candidate = NULL;
 | 
|---|
 | 2140 | 
 | 
|---|
| [ce7bfd] | 2141 |   LOG(3, "DEBUG: NormalVector of BaseTriangle is " << NormalVector << ".");
 | 
|---|
| [357fba] | 2142 | 
 | 
|---|
| [09898c] | 2143 |   // copy old center
 | 
|---|
| [8cbb97] | 2144 |   CandidateLine.OldCenter = OldSphereCenter;
 | 
|---|
| [09898c] | 2145 |   CandidateLine.ThirdPoint = ThirdPoint;
 | 
|---|
 | 2146 |   CandidateLine.pointlist.clear();
 | 
|---|
| [357fba] | 2147 | 
 | 
|---|
 | 2148 |   // construct center of circle
 | 
|---|
| [d74077] | 2149 |   CircleCenter = 0.5 * ((CandidateLine.BaseLine->endpoints[0]->node->getPosition()) +
 | 
|---|
 | 2150 |                         (CandidateLine.BaseLine->endpoints[1]->node->getPosition()));
 | 
|---|
| [357fba] | 2151 | 
 | 
|---|
 | 2152 |   // construct normal vector of circle
 | 
|---|
| [d74077] | 2153 |   CirclePlaneNormal = (CandidateLine.BaseLine->endpoints[0]->node->getPosition()) -
 | 
|---|
 | 2154 |                       (CandidateLine.BaseLine->endpoints[1]->node->getPosition());
 | 
|---|
| [357fba] | 2155 | 
 | 
|---|
| [273382] | 2156 |   RelativeOldSphereCenter = OldSphereCenter - CircleCenter;
 | 
|---|
| [b998c3] | 2157 | 
 | 
|---|
| [09898c] | 2158 |   // calculate squared radius TesselPoint *ThirdPoint,f circle
 | 
|---|
| [6613ec] | 2159 |   radius = CirclePlaneNormal.NormSquared() / 4.;
 | 
|---|
 | 2160 |   if (radius < RADIUS * RADIUS) {
 | 
|---|
 | 2161 |     CircleRadius = RADIUS * RADIUS - radius;
 | 
|---|
| [357fba] | 2162 |     CirclePlaneNormal.Normalize();
 | 
|---|
| [ce7bfd] | 2163 |     LOG(3, "DEBUG: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << ".");
 | 
|---|
| [357fba] | 2164 | 
 | 
|---|
 | 2165 |     // test whether old center is on the band's plane
 | 
|---|
| [273382] | 2166 |     if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) {
 | 
|---|
| [47d041] | 2167 |       ELOG(1, "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!");
 | 
|---|
| [273382] | 2168 |       RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal);
 | 
|---|
| [357fba] | 2169 |     }
 | 
|---|
| [b998c3] | 2170 |     radius = RelativeOldSphereCenter.NormSquared();
 | 
|---|
| [357fba] | 2171 |     if (fabs(radius - CircleRadius) < HULLEPSILON) {
 | 
|---|
| [ce7bfd] | 2172 |       LOG(3, "DEBUG: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << ".");
 | 
|---|
| [357fba] | 2173 | 
 | 
|---|
 | 2174 |       // check SearchDirection
 | 
|---|
| [ce7bfd] | 2175 |       LOG(3, "DEBUG: SearchDirection is " << SearchDirection << ".");
 | 
|---|
| [8cbb97] | 2176 |       if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
 | 
|---|
| [47d041] | 2177 |         ELOG(1, "SearchDirection and RelativeOldSphereCenter are not orthogonal!");
 | 
|---|
| [357fba] | 2178 |       }
 | 
|---|
 | 2179 | 
 | 
|---|
| [62bb91] | 2180 |       // get cell for the starting point
 | 
|---|
| [d74077] | 2181 |       if (LC->SetIndexToVector(CircleCenter)) {
 | 
|---|
| [6613ec] | 2182 |         for (int i = 0; i < NDIM; i++) // store indices of this cell
 | 
|---|
 | 2183 |           N[i] = LC->n[i];
 | 
|---|
| [47d041] | 2184 |         //LOG(1, "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << ".");
 | 
|---|
| [357fba] | 2185 |       } else {
 | 
|---|
| [47d041] | 2186 |         ELOG(1, "Vector " << CircleCenter << " is outside of LinkedCell's bounding box.");
 | 
|---|
| [357fba] | 2187 |         return;
 | 
|---|
 | 2188 |       }
 | 
|---|
| [62bb91] | 2189 |       // then go through the current and all neighbouring cells and check the contained points for possible candidates
 | 
|---|
| [ce7bfd] | 2190 | //      if (DoLog(3)) {
 | 
|---|
| [47d041] | 2191 | //        std::stringstream output;
 | 
|---|
 | 2192 | //        output << "LC Intervals:";
 | 
|---|
 | 2193 | //        for (int i = 0; i < NDIM; i++)
 | 
|---|
 | 2194 | //          output << " [" << Nlower[i] << "," << Nupper[i] << "] ";
 | 
|---|
 | 2195 | //        LOG(0, output.str());
 | 
|---|
 | 2196 | //      }
 | 
|---|
| [6613ec] | 2197 |       for (int i = 0; i < NDIM; i++) {
 | 
|---|
 | 2198 |         Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
 | 
|---|
 | 2199 |         Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
 | 
|---|
| [357fba] | 2200 |       }
 | 
|---|
 | 2201 |       for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
 | 
|---|
 | 2202 |         for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
 | 
|---|
 | 2203 |           for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
 | 
|---|
| [34c43a] | 2204 |             const TesselPointSTLList *List = LC->GetCurrentCell();
 | 
|---|
| [47d041] | 2205 |             //LOG(1, "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << ".");
 | 
|---|
| [357fba] | 2206 |             if (List != NULL) {
 | 
|---|
| [34c43a] | 2207 |               for (TesselPointSTLList::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
 | 
|---|
| [357fba] | 2208 |                 Candidate = (*Runner);
 | 
|---|
 | 2209 | 
 | 
|---|
 | 2210 |                 // check for three unique points
 | 
|---|
| [ce7bfd] | 2211 |                 LOG(4, "DEBUG: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << ".");
 | 
|---|
| [6613ec] | 2212 |                 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
 | 
|---|
| [357fba] | 2213 | 
 | 
|---|
| [b998c3] | 2214 |                   // find center on the plane
 | 
|---|
| [d74077] | 2215 |                   GetCenterofCircumcircle(NewPlaneCenter, CandidateLine.BaseLine->endpoints[0]->node->getPosition(), CandidateLine.BaseLine->endpoints[1]->node->getPosition(), Candidate->getPosition());
 | 
|---|
| [ce7bfd] | 2216 |                   LOG(3, "DEBUG: NewPlaneCenter is " << NewPlaneCenter << ".");
 | 
|---|
| [357fba] | 2217 | 
 | 
|---|
| [0a4f7f] | 2218 |                   try {
 | 
|---|
| [d74077] | 2219 |                     NewNormalVector = Plane((CandidateLine.BaseLine->endpoints[0]->node->getPosition()),
 | 
|---|
 | 2220 |                                             (CandidateLine.BaseLine->endpoints[1]->node->getPosition()),
 | 
|---|
 | 2221 |                                             (Candidate->getPosition())).getNormal();
 | 
|---|
| [ce7bfd] | 2222 |                     LOG(3, "DEBUG: NewNormalVector is " << NewNormalVector << ".");
 | 
|---|
| [d74077] | 2223 |                     radius = CandidateLine.BaseLine->endpoints[0]->node->DistanceSquared(NewPlaneCenter);
 | 
|---|
| [ce7bfd] | 2224 |                     LOG(3, "DEBUG: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << ".");
 | 
|---|
 | 2225 |                     LOG(3, "DEBUG: SearchDirection is " << SearchDirection << ".");
 | 
|---|
 | 2226 |                     LOG(3, "DEBUG: Radius of CircumCenterCircle is " << radius << ".");
 | 
|---|
| [6613ec] | 2227 |                     if (radius < RADIUS * RADIUS) {
 | 
|---|
| [d74077] | 2228 |                       otherradius = CandidateLine.BaseLine->endpoints[1]->node->DistanceSquared(NewPlaneCenter);
 | 
|---|
| [620a3f] | 2229 |                       if (fabs(radius - otherradius) < HULLEPSILON) {
 | 
|---|
 | 2230 |                         // construct both new centers
 | 
|---|
| [8cbb97] | 2231 |                         NewSphereCenter = NewPlaneCenter;
 | 
|---|
 | 2232 |                         OtherNewSphereCenter= NewPlaneCenter;
 | 
|---|
 | 2233 |                         helper = NewNormalVector;
 | 
|---|
| [620a3f] | 2234 |                         helper.Scale(sqrt(RADIUS * RADIUS - radius));
 | 
|---|
| [ce7bfd] | 2235 |                         LOG(4, "DEBUG: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << ".");
 | 
|---|
| [8cbb97] | 2236 |                         NewSphereCenter += helper;
 | 
|---|
| [ce7bfd] | 2237 |                         LOG(4, "DEBUG: NewSphereCenter is at " << NewSphereCenter << ".");
 | 
|---|
| [620a3f] | 2238 |                         // OtherNewSphereCenter is created by the same vector just in the other direction
 | 
|---|
 | 2239 |                         helper.Scale(-1.);
 | 
|---|
| [8cbb97] | 2240 |                         OtherNewSphereCenter += helper;
 | 
|---|
| [ce7bfd] | 2241 |                         LOG(4, "DEBUG: OtherNewSphereCenter is at " << OtherNewSphereCenter << ".");
 | 
|---|
| [88b400] | 2242 |                         alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection, HULLEPSILON);
 | 
|---|
 | 2243 |                         Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection, HULLEPSILON);
 | 
|---|
| [b1a6d8] | 2244 |                         if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
 | 
|---|
| [8cbb97] | 2245 |                           if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter))
 | 
|---|
| [b1a6d8] | 2246 |                             alpha = Otheralpha;
 | 
|---|
 | 2247 |                         } else
 | 
|---|
 | 2248 |                           alpha = min(alpha, Otheralpha);
 | 
|---|
| [620a3f] | 2249 |                         // if there is a better candidate, drop the current list and add the new candidate
 | 
|---|
 | 2250 |                         // otherwise ignore the new candidate and keep the list
 | 
|---|
 | 2251 |                         if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
 | 
|---|
 | 2252 |                           if (fabs(alpha - Otheralpha) > MYEPSILON) {
 | 
|---|
| [8cbb97] | 2253 |                             CandidateLine.OptCenter = NewSphereCenter;
 | 
|---|
 | 2254 |                             CandidateLine.OtherOptCenter = OtherNewSphereCenter;
 | 
|---|
| [620a3f] | 2255 |                           } else {
 | 
|---|
| [8cbb97] | 2256 |                             CandidateLine.OptCenter = OtherNewSphereCenter;
 | 
|---|
 | 2257 |                             CandidateLine.OtherOptCenter = NewSphereCenter;
 | 
|---|
| [620a3f] | 2258 |                           }
 | 
|---|
 | 2259 |                           // if there is an equal candidate, add it to the list without clearing the list
 | 
|---|
 | 2260 |                           if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
 | 
|---|
 | 2261 |                             CandidateLine.pointlist.push_back(Candidate);
 | 
|---|
| [ce7bfd] | 2262 |                             LOG(2, "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << ".");
 | 
|---|
| [620a3f] | 2263 |                           } else {
 | 
|---|
 | 2264 |                             // remove all candidates from the list and then the list itself
 | 
|---|
 | 2265 |                             CandidateLine.pointlist.clear();
 | 
|---|
 | 2266 |                             CandidateLine.pointlist.push_back(Candidate);
 | 
|---|
| [ce7bfd] | 2267 |                             LOG(2, "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << ".");
 | 
|---|
| [620a3f] | 2268 |                           }
 | 
|---|
 | 2269 |                           CandidateLine.ShortestAngle = alpha;
 | 
|---|
| [ce7bfd] | 2270 |                           LOG(2, "DEBUG: There are " << CandidateLine.pointlist.size() << " candidates in the list now.");
 | 
|---|
| [357fba] | 2271 |                         } else {
 | 
|---|
| [620a3f] | 2272 |                           if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
 | 
|---|
| [ce7bfd] | 2273 |                             LOG(3, "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " .");
 | 
|---|
| [620a3f] | 2274 |                           } else {
 | 
|---|
| [ce7bfd] | 2275 |                             LOG(3, "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected.");
 | 
|---|
| [620a3f] | 2276 |                           }
 | 
|---|
| [357fba] | 2277 |                         }
 | 
|---|
 | 2278 |                       } else {
 | 
|---|
| [47d041] | 2279 |                         ELOG(0, "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius));
 | 
|---|
| [357fba] | 2280 |                       }
 | 
|---|
 | 2281 |                     } else {
 | 
|---|
| [ce7bfd] | 2282 |                       LOG(3, "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << ".");
 | 
|---|
| [357fba] | 2283 |                     }
 | 
|---|
| [0a4f7f] | 2284 |                   }
 | 
|---|
 | 2285 |                   catch (LinearDependenceException &excp){
 | 
|---|
| [ce7bfd] | 2286 |                     LOG(3, boost::diagnostic_information(excp));
 | 
|---|
 | 2287 |                     LOG(3, "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent.");
 | 
|---|
| [357fba] | 2288 |                   }
 | 
|---|
 | 2289 |                 } else {
 | 
|---|
| [09898c] | 2290 |                   if (ThirdPoint != NULL) {
 | 
|---|
| [ce7bfd] | 2291 |                     LOG(3, "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << ".");
 | 
|---|
| [357fba] | 2292 |                   } else {
 | 
|---|
| [ce7bfd] | 2293 |                     LOG(3, "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << ".");
 | 
|---|
| [357fba] | 2294 |                   }
 | 
|---|
 | 2295 |                 }
 | 
|---|
 | 2296 |               }
 | 
|---|
 | 2297 |             }
 | 
|---|
 | 2298 |           }
 | 
|---|
 | 2299 |     } else {
 | 
|---|
| [47d041] | 2300 |       ELOG(1, "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << ".");
 | 
|---|
| [357fba] | 2301 |     }
 | 
|---|
 | 2302 |   } else {
 | 
|---|
| [09898c] | 2303 |     if (ThirdPoint != NULL)
 | 
|---|
| [ce7bfd] | 2304 |       LOG(3, "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!");
 | 
|---|
| [357fba] | 2305 |     else
 | 
|---|
| [ce7bfd] | 2306 |       LOG(3, "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!");
 | 
|---|
| [357fba] | 2307 |   }
 | 
|---|
 | 2308 | 
 | 
|---|
| [ce7bfd] | 2309 |   LOG(2, "DEBUG: Sorting candidate list ...");
 | 
|---|
| [f67b6e] | 2310 |   if (CandidateLine.pointlist.size() > 1) {
 | 
|---|
 | 2311 |     CandidateLine.pointlist.unique();
 | 
|---|
 | 2312 |     CandidateLine.pointlist.sort(); //SortCandidates);
 | 
|---|
| [357fba] | 2313 |   }
 | 
|---|
| [6613ec] | 2314 | 
 | 
|---|
 | 2315 |   if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
 | 
|---|
| [47d041] | 2316 |     ELOG(0, "There were other points contained in the rolling sphere as well!");
 | 
|---|
| [6613ec] | 2317 |     performCriticalExit();
 | 
|---|
 | 2318 |   }
 | 
|---|
 | 2319 | }
 | 
|---|
 | 2320 | ;
 | 
|---|
| [357fba] | 2321 | 
 | 
|---|
 | 2322 | /** Finds the endpoint two lines are sharing.
 | 
|---|
 | 2323 |  * \param *line1 first line
 | 
|---|
 | 2324 |  * \param *line2 second line
 | 
|---|
 | 2325 |  * \return point which is shared or NULL if none
 | 
|---|
 | 2326 |  */
 | 
|---|
| [776b64] | 2327 | class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
 | 
|---|
| [357fba] | 2328 | {
 | 
|---|
| [ce7bfd] | 2329 |   //Info FunctionInfo(__func__);
 | 
|---|
| [776b64] | 2330 |   const BoundaryLineSet * lines[2] = { line1, line2 };
 | 
|---|
| [357fba] | 2331 |   class BoundaryPointSet *node = NULL;
 | 
|---|
| [c15ca2] | 2332 |   PointMap OrderMap;
 | 
|---|
 | 2333 |   PointTestPair OrderTest;
 | 
|---|
| [357fba] | 2334 |   for (int i = 0; i < 2; i++)
 | 
|---|
 | 2335 |     // for both lines
 | 
|---|
| [6613ec] | 2336 |     for (int j = 0; j < 2; j++) { // for both endpoints
 | 
|---|
 | 2337 |       OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
 | 
|---|
 | 2338 |       if (!OrderTest.second) { // if insertion fails, we have common endpoint
 | 
|---|
 | 2339 |         node = OrderTest.first->second;
 | 
|---|
| [47d041] | 2340 |         LOG(1, "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << ".");
 | 
|---|
| [6613ec] | 2341 |         j = 2;
 | 
|---|
 | 2342 |         i = 2;
 | 
|---|
 | 2343 |         break;
 | 
|---|
| [357fba] | 2344 |       }
 | 
|---|
| [6613ec] | 2345 |     }
 | 
|---|
| [357fba] | 2346 |   return node;
 | 
|---|
| [6613ec] | 2347 | }
 | 
|---|
 | 2348 | ;
 | 
|---|
| [357fba] | 2349 | 
 | 
|---|
| [c15ca2] | 2350 | /** Finds the boundary points that are closest to a given Vector \a *x.
 | 
|---|
| [62bb91] | 2351 |  * \param *out output stream for debugging
 | 
|---|
 | 2352 |  * \param *x Vector to look from
 | 
|---|
| [c15ca2] | 2353 |  * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
 | 
|---|
| [62bb91] | 2354 |  */
 | 
|---|
| [6bd7e0] | 2355 | DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector &x, const LinkedCell_deprecated* LC) const
 | 
|---|
| [62bb91] | 2356 | {
 | 
|---|
| [ce7bfd] | 2357 |   //Info FunctionInfo(__func__);
 | 
|---|
| [71b20e] | 2358 |   PointMap::const_iterator FindPoint;
 | 
|---|
 | 2359 |   int N[NDIM], Nlower[NDIM], Nupper[NDIM];
 | 
|---|
| [62bb91] | 2360 | 
 | 
|---|
 | 2361 |   if (LinesOnBoundary.empty()) {
 | 
|---|
| [47d041] | 2362 |     ELOG(1, "There is no tesselation structure to compare the point with, please create one first.");
 | 
|---|
| [62bb91] | 2363 |     return NULL;
 | 
|---|
 | 2364 |   }
 | 
|---|
| [71b20e] | 2365 | 
 | 
|---|
 | 2366 |   // gather all points close to the desired one
 | 
|---|
 | 2367 |   LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
 | 
|---|
| [6613ec] | 2368 |   for (int i = 0; i < NDIM; i++) // store indices of this cell
 | 
|---|
| [71b20e] | 2369 |     N[i] = LC->n[i];
 | 
|---|
| [ce7bfd] | 2370 |   LOG(2, "DEBUG: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << ".");
 | 
|---|
| [97498a] | 2371 |   DistanceToPointMap * points = new DistanceToPointMap;
 | 
|---|
| [71b20e] | 2372 |   LC->GetNeighbourBounds(Nlower, Nupper);
 | 
|---|
 | 2373 |   for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
 | 
|---|
 | 2374 |     for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
 | 
|---|
 | 2375 |       for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
 | 
|---|
| [34c43a] | 2376 |         const TesselPointSTLList *List = LC->GetCurrentCell();
 | 
|---|
| [47d041] | 2377 |         //LOG(1, "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2]);
 | 
|---|
| [71b20e] | 2378 |         if (List != NULL) {
 | 
|---|
| [34c43a] | 2379 |           for (TesselPointSTLList::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
 | 
|---|
| [735b1c] | 2380 |             FindPoint = PointsOnBoundary.find((*Runner)->getNr());
 | 
|---|
| [97498a] | 2381 |             if (FindPoint != PointsOnBoundary.end()) {
 | 
|---|
| [c29c0a] | 2382 |               // when the closest point is on the edge of a triangle (and hence
 | 
|---|
 | 2383 |               // we find two closes triangles due to it having an adjacent one)
 | 
|---|
 | 2384 |               // we should make sure that both triangles end up in the same entry
 | 
|---|
 | 2385 |               // in the distance multimap. Hence, we round to 6 digit precision.
 | 
|---|
 | 2386 |               const double distance =
 | 
|---|
 | 2387 |                   1e-6*floor(FindPoint->second->node->DistanceSquared(x)*1e+6);
 | 
|---|
 | 2388 |               points->insert(DistanceToPointPair(distance, FindPoint->second));
 | 
|---|
| [ce7bfd] | 2389 |               LOG(3, "DEBUG: Putting " << *FindPoint->second << " into the list.");
 | 
|---|
| [97498a] | 2390 |             }
 | 
|---|
| [71b20e] | 2391 |           }
 | 
|---|
 | 2392 |         } else {
 | 
|---|
| [47d041] | 2393 |           ELOG(1, "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!");
 | 
|---|
| [99593f] | 2394 |         }
 | 
|---|
| [57066a] | 2395 |       }
 | 
|---|
| [62bb91] | 2396 | 
 | 
|---|
| [71b20e] | 2397 |   // check whether we found some points
 | 
|---|
| [c15ca2] | 2398 |   if (points->empty()) {
 | 
|---|
| [47d041] | 2399 |     ELOG(1, "There is no nearest point: too far away from the surface.");
 | 
|---|
| [6613ec] | 2400 |     delete (points);
 | 
|---|
| [c15ca2] | 2401 |     return NULL;
 | 
|---|
 | 2402 |   }
 | 
|---|
 | 2403 |   return points;
 | 
|---|
| [6613ec] | 2404 | }
 | 
|---|
 | 2405 | ;
 | 
|---|
| [c15ca2] | 2406 | 
 | 
|---|
 | 2407 | /** Finds the boundary line that is closest to a given Vector \a *x.
 | 
|---|
 | 2408 |  * \param *out output stream for debugging
 | 
|---|
 | 2409 |  * \param *x Vector to look from
 | 
|---|
 | 2410 |  * \return closest BoundaryLineSet or NULL in degenerate case.
 | 
|---|
 | 2411 |  */
 | 
|---|
| [6bd7e0] | 2412 | BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector &x, const LinkedCell_deprecated* LC) const
 | 
|---|
| [c15ca2] | 2413 | {
 | 
|---|
| [ce7bfd] | 2414 |   //Info FunctionInfo(__func__);
 | 
|---|
| [c15ca2] | 2415 |   // get closest points
 | 
|---|
| [6613ec] | 2416 |   DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
 | 
|---|
| [c15ca2] | 2417 |   if (points == NULL) {
 | 
|---|
| [47d041] | 2418 |     ELOG(1, "There is no nearest point: too far away from the surface.");
 | 
|---|
| [71b20e] | 2419 |     return NULL;
 | 
|---|
 | 2420 |   }
 | 
|---|
| [62bb91] | 2421 | 
 | 
|---|
| [71b20e] | 2422 |   // for each point, check its lines, remember closest
 | 
|---|
| [47d041] | 2423 |   LOG(1, "Finding closest BoundaryLine to " << x << " ... ");
 | 
|---|
| [71b20e] | 2424 |   BoundaryLineSet *ClosestLine = NULL;
 | 
|---|
 | 2425 |   double MinDistance = -1.;
 | 
|---|
 | 2426 |   Vector helper;
 | 
|---|
 | 2427 |   Vector Center;
 | 
|---|
 | 2428 |   Vector BaseLine;
 | 
|---|
| [97498a] | 2429 |   for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
 | 
|---|
| [c15ca2] | 2430 |     for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
 | 
|---|
| [71b20e] | 2431 |       // calculate closest point on line to desired point
 | 
|---|
| [d74077] | 2432 |       helper = 0.5 * (((LineRunner->second)->endpoints[0]->node->getPosition()) +
 | 
|---|
 | 2433 |                       ((LineRunner->second)->endpoints[1]->node->getPosition()));
 | 
|---|
 | 2434 |       Center = (x) - helper;
 | 
|---|
 | 2435 |       BaseLine = ((LineRunner->second)->endpoints[0]->node->getPosition()) -
 | 
|---|
 | 2436 |                  ((LineRunner->second)->endpoints[1]->node->getPosition());
 | 
|---|
| [273382] | 2437 |       Center.ProjectOntoPlane(BaseLine);
 | 
|---|
| [71b20e] | 2438 |       const double distance = Center.NormSquared();
 | 
|---|
 | 2439 |       if ((ClosestLine == NULL) || (distance < MinDistance)) {
 | 
|---|
 | 2440 |         // additionally calculate intersection on line (whether it's on the line section or not)
 | 
|---|
| [d74077] | 2441 |         helper = (x) - ((LineRunner->second)->endpoints[0]->node->getPosition()) - Center;
 | 
|---|
| [273382] | 2442 |         const double lengthA = helper.ScalarProduct(BaseLine);
 | 
|---|
| [d74077] | 2443 |         helper = (x) - ((LineRunner->second)->endpoints[1]->node->getPosition()) - Center;
 | 
|---|
| [273382] | 2444 |         const double lengthB = helper.ScalarProduct(BaseLine);
 | 
|---|
| [6613ec] | 2445 |         if (lengthB * lengthA < 0) { // if have different sign
 | 
|---|
| [71b20e] | 2446 |           ClosestLine = LineRunner->second;
 | 
|---|
 | 2447 |           MinDistance = distance;
 | 
|---|
| [47d041] | 2448 |           LOG(1, "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << ".");
 | 
|---|
| [71b20e] | 2449 |         } else {
 | 
|---|
| [47d041] | 2450 |           LOG(1, "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << ".");
 | 
|---|
| [71b20e] | 2451 |         }
 | 
|---|
 | 2452 |       } else {
 | 
|---|
| [47d041] | 2453 |         LOG(1, "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << ".");
 | 
|---|
| [71b20e] | 2454 |       }
 | 
|---|
| [99593f] | 2455 |     }
 | 
|---|
| [57066a] | 2456 |   }
 | 
|---|
| [6613ec] | 2457 |   delete (points);
 | 
|---|
| [71b20e] | 2458 |   // check whether closest line is "too close" :), then it's inside
 | 
|---|
 | 2459 |   if (ClosestLine == NULL) {
 | 
|---|
| [ce7bfd] | 2460 |     LOG(2, "DEBUG: Is the only point, no one else is closeby.");
 | 
|---|
| [62bb91] | 2461 |     return NULL;
 | 
|---|
| [71b20e] | 2462 |   }
 | 
|---|
| [c15ca2] | 2463 |   return ClosestLine;
 | 
|---|
| [6613ec] | 2464 | }
 | 
|---|
 | 2465 | ;
 | 
|---|
| [c15ca2] | 2466 | 
 | 
|---|
 | 2467 | /** Finds the triangle that is closest to a given Vector \a *x.
 | 
|---|
 | 2468 |  * \param *out output stream for debugging
 | 
|---|
 | 2469 |  * \param *x Vector to look from
 | 
|---|
 | 2470 |  * \return BoundaryTriangleSet of nearest triangle or NULL.
 | 
|---|
 | 2471 |  */
 | 
|---|
| [6bd7e0] | 2472 | TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector &x, const LinkedCell_deprecated* LC) const
 | 
|---|
| [c15ca2] | 2473 | {
 | 
|---|
| [ce7bfd] | 2474 |   //Info FunctionInfo(__func__);
 | 
|---|
| [6613ec] | 2475 |   // get closest points
 | 
|---|
 | 2476 |   DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
 | 
|---|
| [c15ca2] | 2477 |   if (points == NULL) {
 | 
|---|
| [47d041] | 2478 |     ELOG(1, "There is no nearest point: too far away from the surface.");
 | 
|---|
| [c15ca2] | 2479 |     return NULL;
 | 
|---|
 | 2480 |   }
 | 
|---|
 | 2481 | 
 | 
|---|
 | 2482 |   // for each point, check its lines, remember closest
 | 
|---|
| [47d041] | 2483 |   LOG(1, "Finding closest BoundaryTriangle to " << x << " ... ");
 | 
|---|
| [48b47a] | 2484 |   LineSet ClosestLines;
 | 
|---|
| [97498a] | 2485 |   double MinDistance = 1e+16;
 | 
|---|
 | 2486 |   Vector BaseLineIntersection;
 | 
|---|
| [c15ca2] | 2487 |   Vector Center;
 | 
|---|
 | 2488 |   Vector BaseLine;
 | 
|---|
| [97498a] | 2489 |   Vector BaseLineCenter;
 | 
|---|
 | 2490 |   for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
 | 
|---|
| [c15ca2] | 2491 |     for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
 | 
|---|
| [97498a] | 2492 | 
 | 
|---|
| [d74077] | 2493 |       BaseLine = ((LineRunner->second)->endpoints[0]->node->getPosition()) -
 | 
|---|
 | 2494 |                  ((LineRunner->second)->endpoints[1]->node->getPosition());
 | 
|---|
| [97498a] | 2495 |       const double lengthBase = BaseLine.NormSquared();
 | 
|---|
 | 2496 | 
 | 
|---|
| [d74077] | 2497 |       BaseLineIntersection = (x) - ((LineRunner->second)->endpoints[0]->node->getPosition());
 | 
|---|
| [97498a] | 2498 |       const double lengthEndA = BaseLineIntersection.NormSquared();
 | 
|---|
 | 2499 | 
 | 
|---|
| [d74077] | 2500 |       BaseLineIntersection = (x) - ((LineRunner->second)->endpoints[1]->node->getPosition());
 | 
|---|
| [97498a] | 2501 |       const double lengthEndB = BaseLineIntersection.NormSquared();
 | 
|---|
 | 2502 | 
 | 
|---|
| [6613ec] | 2503 |       if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
 | 
|---|
| [a0064e] | 2504 |         const double lengthEnd = std::min(lengthEndA, lengthEndB);
 | 
|---|
| [48b47a] | 2505 |         if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
 | 
|---|
 | 2506 |           ClosestLines.clear();
 | 
|---|
 | 2507 |           ClosestLines.insert(LineRunner->second);
 | 
|---|
 | 2508 |           MinDistance = lengthEnd;
 | 
|---|
| [47d041] | 2509 |           LOG(1, "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << ".");
 | 
|---|
| [6613ec] | 2510 |         } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
 | 
|---|
| [48b47a] | 2511 |           ClosestLines.insert(LineRunner->second);
 | 
|---|
| [47d041] | 2512 |           LOG(1, "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << ".");
 | 
|---|
| [48b47a] | 2513 |         } else { // line is worse
 | 
|---|
| [47d041] | 2514 |           LOG(1, "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << ".");
 | 
|---|
| [97498a] | 2515 |         }
 | 
|---|
 | 2516 |       } else { // intersection is closer, calculate
 | 
|---|
| [c15ca2] | 2517 |         // calculate closest point on line to desired point
 | 
|---|
| [d74077] | 2518 |         BaseLineIntersection = (x) - ((LineRunner->second)->endpoints[1]->node->getPosition());
 | 
|---|
| [273382] | 2519 |         Center = BaseLineIntersection;
 | 
|---|
 | 2520 |         Center.ProjectOntoPlane(BaseLine);
 | 
|---|
 | 2521 |         BaseLineIntersection -= Center;
 | 
|---|
| [97498a] | 2522 |         const double distance = BaseLineIntersection.NormSquared();
 | 
|---|
 | 2523 |         if (Center.NormSquared() > BaseLine.NormSquared()) {
 | 
|---|
| [47d041] | 2524 |           ELOG(0, "Algorithmic error: In second case we have intersection outside of baseline!");
 | 
|---|
| [97498a] | 2525 |         }
 | 
|---|
| [48b47a] | 2526 |         if ((ClosestLines.empty()) || (distance < MinDistance)) {
 | 
|---|
 | 2527 |           ClosestLines.insert(LineRunner->second);
 | 
|---|
| [97498a] | 2528 |           MinDistance = distance;
 | 
|---|
| [47d041] | 2529 |           LOG(1, "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << ".");
 | 
|---|
| [c15ca2] | 2530 |         } else {
 | 
|---|
| [47d041] | 2531 |           LOG(2, "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << ".");
 | 
|---|
| [c15ca2] | 2532 |         }
 | 
|---|
 | 2533 |       }
 | 
|---|
 | 2534 |     }
 | 
|---|
 | 2535 |   }
 | 
|---|
| [6613ec] | 2536 |   delete (points);
 | 
|---|
| [c15ca2] | 2537 | 
 | 
|---|
 | 2538 |   // check whether closest line is "too close" :), then it's inside
 | 
|---|
| [48b47a] | 2539 |   if (ClosestLines.empty()) {
 | 
|---|
| [ce7bfd] | 2540 |     LOG(2, "DEBUG: Is the only point, no one else is closeby.");
 | 
|---|
| [c15ca2] | 2541 |     return NULL;
 | 
|---|
 | 2542 |   }
 | 
|---|
 | 2543 |   TriangleList * candidates = new TriangleList;
 | 
|---|
| [48b47a] | 2544 |   for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
 | 
|---|
 | 2545 |     for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
 | 
|---|
| [6613ec] | 2546 |       candidates->push_back(Runner->second);
 | 
|---|
 | 2547 |     }
 | 
|---|
| [c15ca2] | 2548 |   return candidates;
 | 
|---|
| [6613ec] | 2549 | }
 | 
|---|
 | 2550 | ;
 | 
|---|
| [62bb91] | 2551 | 
 | 
|---|
 | 2552 | /** Finds closest triangle to a point.
 | 
|---|
 | 2553 |  * This basically just takes care of the degenerate case, which is not handled in FindClosestTrianglesToPoint().
 | 
|---|
 | 2554 |  * \param *out output stream for debugging
 | 
|---|
 | 2555 |  * \param *x Vector to look from
 | 
|---|
| [8db598] | 2556 |  * \param &distance contains found distance on return
 | 
|---|
| [62bb91] | 2557 |  * \return list of BoundaryTriangleSet of nearest triangles or NULL.
 | 
|---|
 | 2558 |  */
 | 
|---|
| [6bd7e0] | 2559 | class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector &x, const LinkedCell_deprecated* LC) const
 | 
|---|
| [62bb91] | 2560 | {
 | 
|---|
| [ce7bfd] | 2561 |   //Info FunctionInfo(__func__);
 | 
|---|
| [62bb91] | 2562 |   class BoundaryTriangleSet *result = NULL;
 | 
|---|
| [c15ca2] | 2563 |   TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
 | 
|---|
 | 2564 |   TriangleList candidates;
 | 
|---|
| [57066a] | 2565 |   Vector Center;
 | 
|---|
| [71b20e] | 2566 |   Vector helper;
 | 
|---|
| [62bb91] | 2567 | 
 | 
|---|
| [71b20e] | 2568 |   if ((triangles == NULL) || (triangles->empty()))
 | 
|---|
| [62bb91] | 2569 |     return NULL;
 | 
|---|
 | 2570 | 
 | 
|---|
| [97498a] | 2571 |   // go through all and pick the one with the best alignment to x
 | 
|---|
| [6613ec] | 2572 |   double MinAlignment = 2. * M_PI;
 | 
|---|
| [c15ca2] | 2573 |   for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
 | 
|---|
| [d74077] | 2574 |     (*Runner)->GetCenter(Center);
 | 
|---|
 | 2575 |     helper = (x) - Center;
 | 
|---|
| [273382] | 2576 |     const double Alignment = helper.Angle((*Runner)->NormalVector);
 | 
|---|
| [97498a] | 2577 |     if (Alignment < MinAlignment) {
 | 
|---|
 | 2578 |       result = *Runner;
 | 
|---|
 | 2579 |       MinAlignment = Alignment;
 | 
|---|
| [47d041] | 2580 |       LOG(1, "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << ".");
 | 
|---|
| [71b20e] | 2581 |     } else {
 | 
|---|
| [47d041] | 2582 |       LOG(1, "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << ".");
 | 
|---|
| [57066a] | 2583 |     }
 | 
|---|
 | 2584 |   }
 | 
|---|
| [6613ec] | 2585 |   delete (triangles);
 | 
|---|
| [97498a] | 2586 | 
 | 
|---|
| [62bb91] | 2587 |   return result;
 | 
|---|
| [6613ec] | 2588 | }
 | 
|---|
 | 2589 | ;
 | 
|---|
| [62bb91] | 2590 | 
 | 
|---|
| [9473f6] | 2591 | /** Checks whether the provided Vector is within the Tesselation structure.
 | 
|---|
 | 2592 |  * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
 | 
|---|
 | 2593 |  * @param point of which to check the position
 | 
|---|
| [6bd7e0] | 2594 |  * @param *LC LinkedCell_deprecated structure
 | 
|---|
| [9473f6] | 2595 |  *
 | 
|---|
 | 2596 |  * @return true if the point is inside the Tesselation structure, false otherwise
 | 
|---|
 | 2597 |  */
 | 
|---|
| [6bd7e0] | 2598 | bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell_deprecated* const LC) const
 | 
|---|
| [9473f6] | 2599 | {
 | 
|---|
| [d74077] | 2600 |   TriangleIntersectionList Intersections(Point, this, LC);
 | 
|---|
| [8db598] | 2601 |   return Intersections.IsInside();
 | 
|---|
| [9473f6] | 2602 | }
 | 
|---|
 | 2603 | 
 | 
|---|
| [27888f] | 2604 | Vector Tesselation::getNormal(const Vector &Point, const LinkedCell_deprecated* const LC) const
 | 
|---|
 | 2605 | {
 | 
|---|
 | 2606 |   TriangleIntersectionList Intersections(Point, this, LC);
 | 
|---|
 | 2607 |   BoundaryTriangleSet *triangle = Intersections.GetClosestTriangle();
 | 
|---|
 | 2608 |   if (triangle != NULL) {
 | 
|---|
 | 2609 |     return triangle->NormalVector;
 | 
|---|
 | 2610 |   } else
 | 
|---|
 | 2611 |     return zeroVec;
 | 
|---|
 | 2612 | }
 | 
|---|
 | 2613 | 
 | 
|---|
| [9473f6] | 2614 | /** Returns the distance to the surface given by the tesselation.
 | 
|---|
| [97498a] | 2615 |  * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
 | 
|---|
| [9473f6] | 2616 |  * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
 | 
|---|
 | 2617 |  * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
 | 
|---|
 | 2618 |  * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
 | 
|---|
 | 2619 |  * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
 | 
|---|
 | 2620 |  *  -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
 | 
|---|
 | 2621 |  *  -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
 | 
|---|
 | 2622 |  *  -# If inside, take it to calculate closest distance
 | 
|---|
 | 2623 |  *  -# If not, take intersection with BoundaryLine as distance
 | 
|---|
 | 2624 |  *
 | 
|---|
 | 2625 |  * @note distance is squared despite it still contains a sign to determine in-/outside!
 | 
|---|
| [62bb91] | 2626 |  *
 | 
|---|
 | 2627 |  * @param point of which to check the position
 | 
|---|
| [6bd7e0] | 2628 |  * @param *LC LinkedCell_deprecated structure
 | 
|---|
| [62bb91] | 2629 |  *
 | 
|---|
| [244a84] | 2630 |  * @return >0 if outside, ==0 if on surface, <0 if inside
 | 
|---|
| [62bb91] | 2631 |  */
 | 
|---|
| [244a84] | 2632 | double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
 | 
|---|
| [62bb91] | 2633 | {
 | 
|---|
| [ce7bfd] | 2634 |   //Info FunctionInfo(__func__);
 | 
|---|
| [57066a] | 2635 |   Vector Center;
 | 
|---|
| [71b20e] | 2636 |   Vector helper;
 | 
|---|
| [97498a] | 2637 |   Vector DistanceToCenter;
 | 
|---|
 | 2638 |   Vector Intersection;
 | 
|---|
| [9473f6] | 2639 |   double distance = 0.;
 | 
|---|
| [57066a] | 2640 | 
 | 
|---|
| [244a84] | 2641 |   if (triangle == NULL) {// is boundary point or only point in point cloud?
 | 
|---|
| [47d041] | 2642 |     LOG(1, "No triangle given!");
 | 
|---|
| [244a84] | 2643 |     return -1.;
 | 
|---|
| [71b20e] | 2644 |   } else {
 | 
|---|
| [47d041] | 2645 |     LOG(1, "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << ".");
 | 
|---|
| [57066a] | 2646 |   }
 | 
|---|
 | 2647 | 
 | 
|---|
| [d74077] | 2648 |   triangle->GetCenter(Center);
 | 
|---|
| [47d041] | 2649 |   LOG(2, "INFO: Central point of the triangle is " << Center << ".");
 | 
|---|
| [273382] | 2650 |   DistanceToCenter = Center - Point;
 | 
|---|
| [47d041] | 2651 |   LOG(2, "INFO: Vector from point to test to center is " << DistanceToCenter << ".");
 | 
|---|
| [97498a] | 2652 | 
 | 
|---|
 | 2653 |   // check whether we are on boundary
 | 
|---|
| [273382] | 2654 |   if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) {
 | 
|---|
| [97498a] | 2655 |     // calculate whether inside of triangle
 | 
|---|
| [273382] | 2656 |     DistanceToCenter = Point + triangle->NormalVector; // points outside
 | 
|---|
 | 2657 |     Center = Point - triangle->NormalVector; // points towards MolCenter
 | 
|---|
| [47d041] | 2658 |     LOG(1, "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << ".");
 | 
|---|
| [d74077] | 2659 |     if (triangle->GetIntersectionInsideTriangle(Center, DistanceToCenter, Intersection)) {
 | 
|---|
| [47d041] | 2660 |       LOG(1, Point << " is inner point: sufficiently close to boundary, " << Intersection << ".");
 | 
|---|
| [9473f6] | 2661 |       return 0.;
 | 
|---|
| [97498a] | 2662 |     } else {
 | 
|---|
| [47d041] | 2663 |       LOG(1, Point << " is NOT an inner point: on triangle plane but outside of triangle bounds.");
 | 
|---|
| [97498a] | 2664 |       return false;
 | 
|---|
 | 2665 |     }
 | 
|---|
| [57066a] | 2666 |   } else {
 | 
|---|
| [9473f6] | 2667 |     // calculate smallest distance
 | 
|---|
| [d74077] | 2668 |     distance = triangle->GetClosestPointInsideTriangle(Point, Intersection);
 | 
|---|
| [47d041] | 2669 |     LOG(1, "Closest point on triangle is " << Intersection << ".");
 | 
|---|
| [9473f6] | 2670 | 
 | 
|---|
 | 2671 |     // then check direction to boundary
 | 
|---|
| [273382] | 2672 |     if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) {
 | 
|---|
| [47d041] | 2673 |       LOG(1, Point << " is an inner point, " << distance << " below surface.");
 | 
|---|
| [9473f6] | 2674 |       return -distance;
 | 
|---|
 | 2675 |     } else {
 | 
|---|
| [47d041] | 2676 |       LOG(1, Point << " is NOT an inner point, " << distance << " above surface.");
 | 
|---|
| [9473f6] | 2677 |       return +distance;
 | 
|---|
 | 2678 |     }
 | 
|---|
| [57066a] | 2679 |   }
 | 
|---|
| [6613ec] | 2680 | }
 | 
|---|
 | 2681 | ;
 | 
|---|
| [62bb91] | 2682 | 
 | 
|---|
| [8db598] | 2683 | /** Calculates minimum distance from \a&Point to a tesselated surface.
 | 
|---|
| [244a84] | 2684 |  * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
 | 
|---|
 | 2685 |  * \param &Point point to calculate distance from
 | 
|---|
 | 2686 |  * \param *LC needed for finding closest points fast
 | 
|---|
 | 2687 |  * \return distance squared to closest point on surface
 | 
|---|
 | 2688 |  */
 | 
|---|
| [6bd7e0] | 2689 | double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const
 | 
|---|
| [244a84] | 2690 | {
 | 
|---|
| [ce7bfd] | 2691 |   //Info FunctionInfo(__func__);
 | 
|---|
| [d74077] | 2692 |   TriangleIntersectionList Intersections(Point, this, LC);
 | 
|---|
| [8db598] | 2693 | 
 | 
|---|
 | 2694 |   return Intersections.GetSmallestDistance();
 | 
|---|
| [6613ec] | 2695 | }
 | 
|---|
 | 2696 | ;
 | 
|---|
| [8db598] | 2697 | 
 | 
|---|
 | 2698 | /** Calculates minimum distance from \a&Point to a tesselated surface.
 | 
|---|
 | 2699 |  * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
 | 
|---|
 | 2700 |  * \param &Point point to calculate distance from
 | 
|---|
 | 2701 |  * \param *LC needed for finding closest points fast
 | 
|---|
 | 2702 |  * \return distance squared to closest point on surface
 | 
|---|
 | 2703 |  */
 | 
|---|
| [6bd7e0] | 2704 | BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const
 | 
|---|
| [8db598] | 2705 | {
 | 
|---|
| [ce7bfd] | 2706 |   //Info FunctionInfo(__func__);
 | 
|---|
| [d74077] | 2707 |   TriangleIntersectionList Intersections(Point, this, LC);
 | 
|---|
| [8db598] | 2708 | 
 | 
|---|
 | 2709 |   return Intersections.GetClosestTriangle();
 | 
|---|
| [6613ec] | 2710 | }
 | 
|---|
 | 2711 | ;
 | 
|---|
| [244a84] | 2712 | 
 | 
|---|
| [62bb91] | 2713 | /** Gets all points connected to the provided point by triangulation lines.
 | 
|---|
 | 2714 |  *
 | 
|---|
 | 2715 |  * @param *Point of which get all connected points
 | 
|---|
 | 2716 |  *
 | 
|---|
| [065e82] | 2717 |  * @return set of the all points linked to the provided one
 | 
|---|
| [62bb91] | 2718 |  */
 | 
|---|
| [c15ca2] | 2719 | TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
 | 
|---|
| [62bb91] | 2720 | {
 | 
|---|
| [ce7bfd] | 2721 |   //Info FunctionInfo(__func__);
 | 
|---|
| [6613ec] | 2722 |   TesselPointSet *connectedPoints = new TesselPointSet;
 | 
|---|
| [5c7bf8] | 2723 |   class BoundaryPointSet *ReferencePoint = NULL;
 | 
|---|
| [62bb91] | 2724 |   TesselPoint* current;
 | 
|---|
 | 2725 |   bool takePoint = false;
 | 
|---|
| [5c7bf8] | 2726 |   // find the respective boundary point
 | 
|---|
| [735b1c] | 2727 |   PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->getNr());
 | 
|---|
| [5c7bf8] | 2728 |   if (PointRunner != PointsOnBoundary.end()) {
 | 
|---|
 | 2729 |     ReferencePoint = PointRunner->second;
 | 
|---|
 | 2730 |   } else {
 | 
|---|
| [47d041] | 2731 |     ELOG(2, "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << ".");
 | 
|---|
| [5c7bf8] | 2732 |     ReferencePoint = NULL;
 | 
|---|
 | 2733 |   }
 | 
|---|
| [62bb91] | 2734 | 
 | 
|---|
| [065e82] | 2735 |   // little trick so that we look just through lines connect to the BoundaryPoint
 | 
|---|
| [5c7bf8] | 2736 |   // OR fall-back to look through all lines if there is no such BoundaryPoint
 | 
|---|
| [6613ec] | 2737 |   const LineMap *Lines;
 | 
|---|
 | 2738 |   ;
 | 
|---|
| [5c7bf8] | 2739 |   if (ReferencePoint != NULL)
 | 
|---|
 | 2740 |     Lines = &(ReferencePoint->lines);
 | 
|---|
| [776b64] | 2741 |   else
 | 
|---|
 | 2742 |     Lines = &LinesOnBoundary;
 | 
|---|
 | 2743 |   LineMap::const_iterator findLines = Lines->begin();
 | 
|---|
| [5c7bf8] | 2744 |   while (findLines != Lines->end()) {
 | 
|---|
| [6613ec] | 2745 |     takePoint = false;
 | 
|---|
 | 2746 | 
 | 
|---|
| [735b1c] | 2747 |     if (findLines->second->endpoints[0]->Nr == Point->getNr()) {
 | 
|---|
| [6613ec] | 2748 |       takePoint = true;
 | 
|---|
 | 2749 |       current = findLines->second->endpoints[1]->node;
 | 
|---|
| [735b1c] | 2750 |     } else if (findLines->second->endpoints[1]->Nr == Point->getNr()) {
 | 
|---|
| [6613ec] | 2751 |       takePoint = true;
 | 
|---|
 | 2752 |       current = findLines->second->endpoints[0]->node;
 | 
|---|
 | 2753 |     }
 | 
|---|
| [065e82] | 2754 | 
 | 
|---|
| [6613ec] | 2755 |     if (takePoint) {
 | 
|---|
| [47d041] | 2756 |       LOG(1, "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted.");
 | 
|---|
| [6613ec] | 2757 |       connectedPoints->insert(current);
 | 
|---|
 | 2758 |     }
 | 
|---|
| [62bb91] | 2759 | 
 | 
|---|
| [6613ec] | 2760 |     findLines++;
 | 
|---|
| [62bb91] | 2761 |   }
 | 
|---|
 | 2762 | 
 | 
|---|
| [71b20e] | 2763 |   if (connectedPoints->empty()) { // if have not found any points
 | 
|---|
| [47d041] | 2764 |     ELOG(1, "We have not found any connected points to " << *Point << ".");
 | 
|---|
| [16d866] | 2765 |     return NULL;
 | 
|---|
 | 2766 |   }
 | 
|---|
| [065e82] | 2767 | 
 | 
|---|
| [16d866] | 2768 |   return connectedPoints;
 | 
|---|
| [6613ec] | 2769 | }
 | 
|---|
 | 2770 | ;
 | 
|---|
| [065e82] | 2771 | 
 | 
|---|
 | 2772 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
 | 
|---|
| [16d866] | 2773 |  * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
 | 
|---|
 | 2774 |  * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
 | 
|---|
 | 2775 |  * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
 | 
|---|
 | 2776 |  * triangle we are looking for.
 | 
|---|
 | 2777 |  *
 | 
|---|
 | 2778 |  * @param *out output stream for debugging
 | 
|---|
| [27bd2f] | 2779 |  * @param *SetOfNeighbours all points for which the angle should be calculated
 | 
|---|
| [16d866] | 2780 |  * @param *Point of which get all connected points
 | 
|---|
| [065e82] | 2781 |  * @param *Reference Reference vector for zero angle or NULL for no preference
 | 
|---|
 | 2782 |  * @return list of the all points linked to the provided one
 | 
|---|
| [16d866] | 2783 |  */
 | 
|---|
| [d74077] | 2784 | TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const
 | 
|---|
| [16d866] | 2785 | {
 | 
|---|
| [ce7bfd] | 2786 |   //Info FunctionInfo(__func__);
 | 
|---|
| [16d866] | 2787 |   map<double, TesselPoint*> anglesOfPoints;
 | 
|---|
| [c15ca2] | 2788 |   TesselPointList *connectedCircle = new TesselPointList;
 | 
|---|
| [71b20e] | 2789 |   Vector PlaneNormal;
 | 
|---|
 | 2790 |   Vector AngleZero;
 | 
|---|
 | 2791 |   Vector OrthogonalVector;
 | 
|---|
 | 2792 |   Vector helper;
 | 
|---|
| [6613ec] | 2793 |   const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
 | 
|---|
| [c15ca2] | 2794 |   TriangleList *triangles = NULL;
 | 
|---|
| [71b20e] | 2795 | 
 | 
|---|
 | 2796 |   if (SetOfNeighbours == NULL) {
 | 
|---|
| [47d041] | 2797 |     ELOG(2, "Could not find any connected points!");
 | 
|---|
| [6613ec] | 2798 |     delete (connectedCircle);
 | 
|---|
| [71b20e] | 2799 |     return NULL;
 | 
|---|
 | 2800 |   }
 | 
|---|
 | 2801 | 
 | 
|---|
 | 2802 |   // calculate central point
 | 
|---|
 | 2803 |   triangles = FindTriangles(TrianglePoints);
 | 
|---|
 | 2804 |   if ((triangles != NULL) && (!triangles->empty())) {
 | 
|---|
| [c15ca2] | 2805 |     for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
 | 
|---|
| [273382] | 2806 |       PlaneNormal += (*Runner)->NormalVector;
 | 
|---|
| [71b20e] | 2807 |   } else {
 | 
|---|
| [47d041] | 2808 |     ELOG(0, "Could not find any triangles for point " << *Point << ".");
 | 
|---|
| [71b20e] | 2809 |     performCriticalExit();
 | 
|---|
 | 2810 |   }
 | 
|---|
| [6613ec] | 2811 |   PlaneNormal.Scale(1.0 / triangles->size());
 | 
|---|
| [ce7bfd] | 2812 |   LOG(4, "DEBUG: Calculated PlaneNormal of all circle points is " << PlaneNormal << ".");
 | 
|---|
| [71b20e] | 2813 |   PlaneNormal.Normalize();
 | 
|---|
 | 2814 | 
 | 
|---|
 | 2815 |   // construct one orthogonal vector
 | 
|---|
| [d74077] | 2816 |   AngleZero = (Reference) - (Point->getPosition());
 | 
|---|
 | 2817 |   AngleZero.ProjectOntoPlane(PlaneNormal);
 | 
|---|
 | 2818 |   if ((AngleZero.NormSquared() < MYEPSILON)) {
 | 
|---|
| [ce7bfd] | 2819 |     LOG(4, "DEBUG: Using alternatively " << (*SetOfNeighbours->begin())->getPosition() << " as angle 0 referencer.");
 | 
|---|
| [d74077] | 2820 |     AngleZero = ((*SetOfNeighbours->begin())->getPosition()) - (Point->getPosition());
 | 
|---|
| [273382] | 2821 |     AngleZero.ProjectOntoPlane(PlaneNormal);
 | 
|---|
| [71b20e] | 2822 |     if (AngleZero.NormSquared() < MYEPSILON) {
 | 
|---|
| [47d041] | 2823 |       ELOG(0, "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!");
 | 
|---|
| [71b20e] | 2824 |       performCriticalExit();
 | 
|---|
 | 2825 |     }
 | 
|---|
 | 2826 |   }
 | 
|---|
| [ce7bfd] | 2827 |   LOG(4, "DEBUG: Reference vector on this plane representing angle 0 is " << AngleZero << ".");
 | 
|---|
| [71b20e] | 2828 |   if (AngleZero.NormSquared() > MYEPSILON)
 | 
|---|
| [0a4f7f] | 2829 |     OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
 | 
|---|
| [71b20e] | 2830 |   else
 | 
|---|
| [0a4f7f] | 2831 |     OrthogonalVector.MakeNormalTo(PlaneNormal);
 | 
|---|
| [ce7bfd] | 2832 |   LOG(4, "DEBUG: OrthogonalVector on plane is " << OrthogonalVector << ".");
 | 
|---|
| [71b20e] | 2833 | 
 | 
|---|
 | 2834 |   // go through all connected points and calculate angle
 | 
|---|
| [c15ca2] | 2835 |   for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
 | 
|---|
| [d74077] | 2836 |     helper = ((*listRunner)->getPosition()) - (Point->getPosition());
 | 
|---|
| [273382] | 2837 |     helper.ProjectOntoPlane(PlaneNormal);
 | 
|---|
| [71b20e] | 2838 |     double angle = GetAngle(helper, AngleZero, OrthogonalVector);
 | 
|---|
| [ce7bfd] | 2839 |     LOG(4, "DEBUG" << angle << " for point " << **listRunner << ".");
 | 
|---|
| [6613ec] | 2840 |     anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
 | 
|---|
| [71b20e] | 2841 |   }
 | 
|---|
 | 2842 | 
 | 
|---|
| [6613ec] | 2843 |   for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
 | 
|---|
| [71b20e] | 2844 |     connectedCircle->push_back(AngleRunner->second);
 | 
|---|
 | 2845 |   }
 | 
|---|
 | 2846 | 
 | 
|---|
 | 2847 |   return connectedCircle;
 | 
|---|
 | 2848 | }
 | 
|---|
 | 2849 | 
 | 
|---|
 | 2850 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
 | 
|---|
 | 2851 |  * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
 | 
|---|
 | 2852 |  * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
 | 
|---|
 | 2853 |  * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
 | 
|---|
 | 2854 |  * triangle we are looking for.
 | 
|---|
 | 2855 |  *
 | 
|---|
 | 2856 |  * @param *SetOfNeighbours all points for which the angle should be calculated
 | 
|---|
 | 2857 |  * @param *Point of which get all connected points
 | 
|---|
| [d74077] | 2858 |  * @param *Reference Reference vector for zero angle or (0,0,0) for no preference
 | 
|---|
| [71b20e] | 2859 |  * @return list of the all points linked to the provided one
 | 
|---|
 | 2860 |  */
 | 
|---|
| [d74077] | 2861 | TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const
 | 
|---|
| [71b20e] | 2862 | {
 | 
|---|
| [ce7bfd] | 2863 |   //Info FunctionInfo(__func__);
 | 
|---|
| [71b20e] | 2864 |   map<double, TesselPoint*> anglesOfPoints;
 | 
|---|
| [c15ca2] | 2865 |   TesselPointList *connectedCircle = new TesselPointList;
 | 
|---|
| [065e82] | 2866 |   Vector center;
 | 
|---|
 | 2867 |   Vector PlaneNormal;
 | 
|---|
 | 2868 |   Vector AngleZero;
 | 
|---|
 | 2869 |   Vector OrthogonalVector;
 | 
|---|
 | 2870 |   Vector helper;
 | 
|---|
| [62bb91] | 2871 | 
 | 
|---|
| [27bd2f] | 2872 |   if (SetOfNeighbours == NULL) {
 | 
|---|
| [47d041] | 2873 |     ELOG(2, "Could not find any connected points!");
 | 
|---|
| [6613ec] | 2874 |     delete (connectedCircle);
 | 
|---|
| [99593f] | 2875 |     return NULL;
 | 
|---|
 | 2876 |   }
 | 
|---|
| [a2028e] | 2877 | 
 | 
|---|
| [97498a] | 2878 |   // check whether there's something to do
 | 
|---|
 | 2879 |   if (SetOfNeighbours->size() < 3) {
 | 
|---|
 | 2880 |     for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
 | 
|---|
 | 2881 |       connectedCircle->push_back(*TesselRunner);
 | 
|---|
 | 2882 |     return connectedCircle;
 | 
|---|
 | 2883 |   }
 | 
|---|
 | 2884 | 
 | 
|---|
| [47d041] | 2885 |   LOG(1, "INFO: Point is " << *Point << " and Reference is " << Reference << ".");
 | 
|---|
| [16d866] | 2886 |   // calculate central point
 | 
|---|
| [97498a] | 2887 |   TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
 | 
|---|
 | 2888 |   TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
 | 
|---|
 | 2889 |   TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
 | 
|---|
 | 2890 |   TesselB++;
 | 
|---|
 | 2891 |   TesselC++;
 | 
|---|
 | 2892 |   TesselC++;
 | 
|---|
 | 2893 |   int counter = 0;
 | 
|---|
 | 2894 |   while (TesselC != SetOfNeighbours->end()) {
 | 
|---|
| [d74077] | 2895 |     helper = Plane(((*TesselA)->getPosition()),
 | 
|---|
 | 2896 |                    ((*TesselB)->getPosition()),
 | 
|---|
 | 2897 |                    ((*TesselC)->getPosition())).getNormal();
 | 
|---|
| [ce7bfd] | 2898 |     LOG(5, "DEBUG: Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper);
 | 
|---|
| [97498a] | 2899 |     counter++;
 | 
|---|
 | 2900 |     TesselA++;
 | 
|---|
 | 2901 |     TesselB++;
 | 
|---|
 | 2902 |     TesselC++;
 | 
|---|
| [273382] | 2903 |     PlaneNormal += helper;
 | 
|---|
| [97498a] | 2904 |   }
 | 
|---|
| [47d041] | 2905 |   //LOG(0, "Summed vectors " << center << "; number of points " << connectedPoints.size() << "; scale factor " << counter);
 | 
|---|
| [6613ec] | 2906 |   PlaneNormal.Scale(1.0 / (double) counter);
 | 
|---|
| [47d041] | 2907 |   //  LOG(1, "INFO: Calculated center of all circle points is " << center << ".");
 | 
|---|
| [6613ec] | 2908 |   //
 | 
|---|
 | 2909 |   //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
 | 
|---|
 | 2910 |   //  PlaneNormal.CopyVector(Point->node);
 | 
|---|
 | 2911 |   //  PlaneNormal.SubtractVector(¢er);
 | 
|---|
 | 2912 |   //  PlaneNormal.Normalize();
 | 
|---|
| [ce7bfd] | 2913 |   LOG(4, "DEBUG: Calculated plane normal of circle is " << PlaneNormal << ".");
 | 
|---|
| [62bb91] | 2914 | 
 | 
|---|
 | 2915 |   // construct one orthogonal vector
 | 
|---|
| [d74077] | 2916 |   if (!Reference.IsZero()) {
 | 
|---|
 | 2917 |     AngleZero = (Reference) - (Point->getPosition());
 | 
|---|
| [273382] | 2918 |     AngleZero.ProjectOntoPlane(PlaneNormal);
 | 
|---|
| [a2028e] | 2919 |   }
 | 
|---|
| [d74077] | 2920 |   if ((Reference.IsZero()) || (AngleZero.NormSquared() < MYEPSILON )) {
 | 
|---|
| [ce7bfd] | 2921 |     LOG(4, "DEBUG: Using alternatively " << (*SetOfNeighbours->begin())->getPosition() << " as angle 0 referencer.");
 | 
|---|
| [d74077] | 2922 |     AngleZero = ((*SetOfNeighbours->begin())->getPosition()) - (Point->getPosition());
 | 
|---|
| [273382] | 2923 |     AngleZero.ProjectOntoPlane(PlaneNormal);
 | 
|---|
| [a2028e] | 2924 |     if (AngleZero.NormSquared() < MYEPSILON) {
 | 
|---|
| [47d041] | 2925 |       ELOG(0, "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!");
 | 
|---|
| [a2028e] | 2926 |       performCriticalExit();
 | 
|---|
 | 2927 |     }
 | 
|---|
 | 2928 |   }
 | 
|---|
| [ce7bfd] | 2929 |   LOG(4, "DEBUG: Reference vector on this plane representing angle 0 is " << AngleZero << ".");
 | 
|---|
| [a2028e] | 2930 |   if (AngleZero.NormSquared() > MYEPSILON)
 | 
|---|
| [0a4f7f] | 2931 |     OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal();
 | 
|---|
| [a2028e] | 2932 |   else
 | 
|---|
| [0a4f7f] | 2933 |     OrthogonalVector.MakeNormalTo(PlaneNormal);
 | 
|---|
| [ce7bfd] | 2934 |   LOG(4, "DEBUG: OrthogonalVector on plane is " << OrthogonalVector << ".");
 | 
|---|
| [16d866] | 2935 | 
 | 
|---|
| [5c7bf8] | 2936 |   // go through all connected points and calculate angle
 | 
|---|
| [6613ec] | 2937 |   pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
 | 
|---|
| [c15ca2] | 2938 |   for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
 | 
|---|
| [d74077] | 2939 |     helper = ((*listRunner)->getPosition()) - (Point->getPosition());
 | 
|---|
| [273382] | 2940 |     helper.ProjectOntoPlane(PlaneNormal);
 | 
|---|
| [f1cccd] | 2941 |     double angle = GetAngle(helper, AngleZero, OrthogonalVector);
 | 
|---|
| [97498a] | 2942 |     if (angle > M_PI) // the correction is of no use here (and not desired)
 | 
|---|
| [6613ec] | 2943 |       angle = 2. * M_PI - angle;
 | 
|---|
| [ce7bfd] | 2944 |     LOG(4, "DEBUG: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << ".");
 | 
|---|
| [6613ec] | 2945 |     InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
 | 
|---|
| [c15ca2] | 2946 |     if (!InserterTest.second) {
 | 
|---|
| [47d041] | 2947 |       ELOG(0, "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner));
 | 
|---|
| [c15ca2] | 2948 |       performCriticalExit();
 | 
|---|
 | 2949 |     }
 | 
|---|
| [62bb91] | 2950 |   }
 | 
|---|
 | 2951 | 
 | 
|---|
| [6613ec] | 2952 |   for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
 | 
|---|
| [065e82] | 2953 |     connectedCircle->push_back(AngleRunner->second);
 | 
|---|
 | 2954 |   }
 | 
|---|
| [62bb91] | 2955 | 
 | 
|---|
| [065e82] | 2956 |   return connectedCircle;
 | 
|---|
 | 2957 | }
 | 
|---|
| [62bb91] | 2958 | 
 | 
|---|
| [065e82] | 2959 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path.
 | 
|---|
 | 2960 |  *
 | 
|---|
 | 2961 |  * @param *out output stream for debugging
 | 
|---|
 | 2962 |  * @param *Point of which get all connected points
 | 
|---|
 | 2963 |  * @return list of the all points linked to the provided one
 | 
|---|
 | 2964 |  */
 | 
|---|
| [244a84] | 2965 | ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
 | 
|---|
| [065e82] | 2966 | {
 | 
|---|
| [ce7bfd] | 2967 |   //Info FunctionInfo(__func__);
 | 
|---|
| [065e82] | 2968 |   map<double, TesselPoint*> anglesOfPoints;
 | 
|---|
| [6613ec] | 2969 |   list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
 | 
|---|
| [c15ca2] | 2970 |   TesselPointList *connectedPath = NULL;
 | 
|---|
| [065e82] | 2971 |   Vector center;
 | 
|---|
 | 2972 |   Vector PlaneNormal;
 | 
|---|
 | 2973 |   Vector AngleZero;
 | 
|---|
 | 2974 |   Vector OrthogonalVector;
 | 
|---|
 | 2975 |   Vector helper;
 | 
|---|
 | 2976 |   class BoundaryPointSet *ReferencePoint = NULL;
 | 
|---|
 | 2977 |   class BoundaryPointSet *CurrentPoint = NULL;
 | 
|---|
 | 2978 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 2979 |   class BoundaryLineSet *CurrentLine = NULL;
 | 
|---|
 | 2980 |   class BoundaryLineSet *StartLine = NULL;
 | 
|---|
 | 2981 |   // find the respective boundary point
 | 
|---|
| [735b1c] | 2982 |   PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->getNr());
 | 
|---|
| [065e82] | 2983 |   if (PointRunner != PointsOnBoundary.end()) {
 | 
|---|
 | 2984 |     ReferencePoint = PointRunner->second;
 | 
|---|
 | 2985 |   } else {
 | 
|---|
| [47d041] | 2986 |     ELOG(1, "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << ".");
 | 
|---|
| [065e82] | 2987 |     return NULL;
 | 
|---|
 | 2988 |   }
 | 
|---|
 | 2989 | 
 | 
|---|
| [6613ec] | 2990 |   map<class BoundaryLineSet *, bool> TouchedLine;
 | 
|---|
 | 2991 |   map<class BoundaryTriangleSet *, bool> TouchedTriangle;
 | 
|---|
 | 2992 |   map<class BoundaryLineSet *, bool>::iterator LineRunner;
 | 
|---|
 | 2993 |   map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
 | 
|---|
| [57066a] | 2994 |   for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
 | 
|---|
| [6613ec] | 2995 |     TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
 | 
|---|
| [57066a] | 2996 |     for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
 | 
|---|
| [6613ec] | 2997 |       TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
 | 
|---|
| [57066a] | 2998 |   }
 | 
|---|
| [065e82] | 2999 |   if (!ReferencePoint->lines.empty()) {
 | 
|---|
 | 3000 |     for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) {
 | 
|---|
| [57066a] | 3001 |       LineRunner = TouchedLine.find(runner->second);
 | 
|---|
 | 3002 |       if (LineRunner == TouchedLine.end()) {
 | 
|---|
| [47d041] | 3003 |         ELOG(1, "I could not find " << *runner->second << " in the touched list.");
 | 
|---|
| [57066a] | 3004 |       } else if (!LineRunner->second) {
 | 
|---|
 | 3005 |         LineRunner->second = true;
 | 
|---|
| [c15ca2] | 3006 |         connectedPath = new TesselPointList;
 | 
|---|
| [065e82] | 3007 |         triangle = NULL;
 | 
|---|
 | 3008 |         CurrentLine = runner->second;
 | 
|---|
 | 3009 |         StartLine = CurrentLine;
 | 
|---|
 | 3010 |         CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
 | 
|---|
| [47d041] | 3011 |         LOG(1, "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << ".");
 | 
|---|
| [065e82] | 3012 |         do {
 | 
|---|
 | 3013 |           // push current one
 | 
|---|
| [47d041] | 3014 |           LOG(1, "INFO: Putting " << *CurrentPoint << " at end of path.");
 | 
|---|
| [065e82] | 3015 |           connectedPath->push_back(CurrentPoint->node);
 | 
|---|
 | 3016 | 
 | 
|---|
 | 3017 |           // find next triangle
 | 
|---|
| [57066a] | 3018 |           for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
 | 
|---|
| [47d041] | 3019 |             LOG(1, "INFO: Inspecting triangle " << *Runner->second << ".");
 | 
|---|
| [57066a] | 3020 |             if ((Runner->second != triangle)) { // look for first triangle not equal to old one
 | 
|---|
 | 3021 |               triangle = Runner->second;
 | 
|---|
 | 3022 |               TriangleRunner = TouchedTriangle.find(triangle);
 | 
|---|
 | 3023 |               if (TriangleRunner != TouchedTriangle.end()) {
 | 
|---|
 | 3024 |                 if (!TriangleRunner->second) {
 | 
|---|
 | 3025 |                   TriangleRunner->second = true;
 | 
|---|
| [47d041] | 3026 |                   LOG(1, "INFO: Connecting triangle is " << *triangle << ".");
 | 
|---|
| [57066a] | 3027 |                   break;
 | 
|---|
 | 3028 |                 } else {
 | 
|---|
| [47d041] | 3029 |                   LOG(1, "INFO: Skipping " << *triangle << ", as we have already visited it.");
 | 
|---|
| [57066a] | 3030 |                   triangle = NULL;
 | 
|---|
 | 3031 |                 }
 | 
|---|
 | 3032 |               } else {
 | 
|---|
| [47d041] | 3033 |                 ELOG(1, "I could not find " << *triangle << " in the touched list.");
 | 
|---|
| [57066a] | 3034 |                 triangle = NULL;
 | 
|---|
 | 3035 |               }
 | 
|---|
| [065e82] | 3036 |             }
 | 
|---|
 | 3037 |           }
 | 
|---|
| [57066a] | 3038 |           if (triangle == NULL)
 | 
|---|
 | 3039 |             break;
 | 
|---|
| [065e82] | 3040 |           // find next line
 | 
|---|
| [6613ec] | 3041 |           for (int i = 0; i < 3; i++) {
 | 
|---|
| [065e82] | 3042 |             if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
 | 
|---|
 | 3043 |               CurrentLine = triangle->lines[i];
 | 
|---|
| [47d041] | 3044 |               LOG(1, "INFO: Connecting line is " << *CurrentLine << ".");
 | 
|---|
| [065e82] | 3045 |               break;
 | 
|---|
 | 3046 |             }
 | 
|---|
 | 3047 |           }
 | 
|---|
| [57066a] | 3048 |           LineRunner = TouchedLine.find(CurrentLine);
 | 
|---|
 | 3049 |           if (LineRunner == TouchedLine.end())
 | 
|---|
| [47d041] | 3050 |             ELOG(1, "I could not find " << *CurrentLine << " in the touched list.");
 | 
|---|
| [065e82] | 3051 |           else
 | 
|---|
| [57066a] | 3052 |             LineRunner->second = true;
 | 
|---|
| [065e82] | 3053 |           // find next point
 | 
|---|
 | 3054 |           CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
 | 
|---|
 | 3055 | 
 | 
|---|
 | 3056 |         } while (CurrentLine != StartLine);
 | 
|---|
 | 3057 |         // last point is missing, as it's on start line
 | 
|---|
| [47d041] | 3058 |         LOG(1, "INFO: Putting " << *CurrentPoint << " at end of path.");
 | 
|---|
| [57066a] | 3059 |         if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
 | 
|---|
 | 3060 |           connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
 | 
|---|
| [065e82] | 3061 | 
 | 
|---|
 | 3062 |         ListOfPaths->push_back(connectedPath);
 | 
|---|
 | 3063 |       } else {
 | 
|---|
| [47d041] | 3064 |         LOG(1, "INFO: Skipping " << *runner->second << ", as we have already visited it.");
 | 
|---|
| [065e82] | 3065 |       }
 | 
|---|
 | 3066 |     }
 | 
|---|
 | 3067 |   } else {
 | 
|---|
| [47d041] | 3068 |     ELOG(1, "There are no lines attached to " << *ReferencePoint << ".");
 | 
|---|
| [065e82] | 3069 |   }
 | 
|---|
 | 3070 | 
 | 
|---|
 | 3071 |   return ListOfPaths;
 | 
|---|
| [62bb91] | 3072 | }
 | 
|---|
 | 3073 | 
 | 
|---|
| [065e82] | 3074 | /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed.
 | 
|---|
 | 3075 |  * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths.
 | 
|---|
 | 3076 |  * @param *out output stream for debugging
 | 
|---|
 | 3077 |  * @param *Point of which get all connected points
 | 
|---|
 | 3078 |  * @return list of the closed paths
 | 
|---|
 | 3079 |  */
 | 
|---|
| [244a84] | 3080 | ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
 | 
|---|
| [065e82] | 3081 | {
 | 
|---|
| [ce7bfd] | 3082 |   //Info FunctionInfo(__func__);
 | 
|---|
| [c15ca2] | 3083 |   list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
 | 
|---|
| [6613ec] | 3084 |   list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
 | 
|---|
| [c15ca2] | 3085 |   TesselPointList *connectedPath = NULL;
 | 
|---|
 | 3086 |   TesselPointList *newPath = NULL;
 | 
|---|
| [065e82] | 3087 |   int count = 0;
 | 
|---|
| [c15ca2] | 3088 |   TesselPointList::iterator CircleRunner;
 | 
|---|
 | 3089 |   TesselPointList::iterator CircleStart;
 | 
|---|
| [065e82] | 3090 | 
 | 
|---|
| [6613ec] | 3091 |   for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
 | 
|---|
| [065e82] | 3092 |     connectedPath = *ListRunner;
 | 
|---|
 | 3093 | 
 | 
|---|
| [47d041] | 3094 |     LOG(1, "INFO: Current path is " << connectedPath << ".");
 | 
|---|
| [065e82] | 3095 | 
 | 
|---|
 | 3096 |     // go through list, look for reappearance of starting Point and count
 | 
|---|
 | 3097 |     CircleStart = connectedPath->begin();
 | 
|---|
 | 3098 |     // go through list, look for reappearance of starting Point and create list
 | 
|---|
| [c15ca2] | 3099 |     TesselPointList::iterator Marker = CircleStart;
 | 
|---|
| [065e82] | 3100 |     for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
 | 
|---|
 | 3101 |       if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
 | 
|---|
 | 3102 |         // we have a closed circle from Marker to new Marker
 | 
|---|
| [47d041] | 3103 |         if (DoLog(1)) {
 | 
|---|
 | 3104 |           std::stringstream output;
 | 
|---|
 | 3105 |           output << count + 1 << ". closed path consists of: ";
 | 
|---|
 | 3106 |           for (TesselPointList::iterator CircleSprinter = Marker;
 | 
|---|
 | 3107 |               CircleSprinter != CircleRunner;
 | 
|---|
 | 3108 |               CircleSprinter++)
 | 
|---|
 | 3109 |             output << (**CircleSprinter) << " <-> ";
 | 
|---|
 | 3110 |           LOG(1, output.str());
 | 
|---|
 | 3111 |         }
 | 
|---|
| [c15ca2] | 3112 |         newPath = new TesselPointList;
 | 
|---|
 | 3113 |         TesselPointList::iterator CircleSprinter = Marker;
 | 
|---|
| [47d041] | 3114 |         for (; CircleSprinter != CircleRunner; CircleSprinter++)
 | 
|---|
| [065e82] | 3115 |           newPath->push_back(*CircleSprinter);
 | 
|---|
 | 3116 |         count++;
 | 
|---|
 | 3117 |         Marker = CircleRunner;
 | 
|---|
 | 3118 | 
 | 
|---|
 | 3119 |         // add to list
 | 
|---|
 | 3120 |         ListofClosedPaths->push_back(newPath);
 | 
|---|
 | 3121 |       }
 | 
|---|
 | 3122 |     }
 | 
|---|
 | 3123 |   }
 | 
|---|
| [47d041] | 3124 |   LOG(1, "INFO: " << count << " closed additional path(s) have been created.");
 | 
|---|
| [065e82] | 3125 | 
 | 
|---|
 | 3126 |   // delete list of paths
 | 
|---|
 | 3127 |   while (!ListofPaths->empty()) {
 | 
|---|
 | 3128 |     connectedPath = *(ListofPaths->begin());
 | 
|---|
 | 3129 |     ListofPaths->remove(connectedPath);
 | 
|---|
| [6613ec] | 3130 |     delete (connectedPath);
 | 
|---|
| [065e82] | 3131 |   }
 | 
|---|
| [6613ec] | 3132 |   delete (ListofPaths);
 | 
|---|
| [065e82] | 3133 | 
 | 
|---|
 | 3134 |   // exit
 | 
|---|
 | 3135 |   return ListofClosedPaths;
 | 
|---|
| [6613ec] | 3136 | }
 | 
|---|
 | 3137 | ;
 | 
|---|
| [065e82] | 3138 | 
 | 
|---|
 | 3139 | /** Gets all belonging triangles for a given BoundaryPointSet.
 | 
|---|
 | 3140 |  * \param *out output stream for debugging
 | 
|---|
 | 3141 |  * \param *Point BoundaryPoint
 | 
|---|
 | 3142 |  * \return pointer to allocated list of triangles
 | 
|---|
 | 3143 |  */
 | 
|---|
| [c15ca2] | 3144 | TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
 | 
|---|
| [065e82] | 3145 | {
 | 
|---|
| [ce7bfd] | 3146 |   //Info FunctionInfo(__func__);
 | 
|---|
| [6613ec] | 3147 |   TriangleSet *connectedTriangles = new TriangleSet;
 | 
|---|
| [065e82] | 3148 | 
 | 
|---|
 | 3149 |   if (Point == NULL) {
 | 
|---|
| [47d041] | 3150 |     ELOG(1, "Point given is NULL.");
 | 
|---|
| [065e82] | 3151 |   } else {
 | 
|---|
 | 3152 |     // go through its lines and insert all triangles
 | 
|---|
| [776b64] | 3153 |     for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
 | 
|---|
| [065e82] | 3154 |       for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
 | 
|---|
| [6613ec] | 3155 |         connectedTriangles->insert(TriangleRunner->second);
 | 
|---|
 | 3156 |       }
 | 
|---|
| [065e82] | 3157 |   }
 | 
|---|
 | 3158 | 
 | 
|---|
 | 3159 |   return connectedTriangles;
 | 
|---|
| [6613ec] | 3160 | }
 | 
|---|
 | 3161 | ;
 | 
|---|
| [065e82] | 3162 | 
 | 
|---|
| [16d866] | 3163 | /** Removes a boundary point from the envelope while keeping it closed.
 | 
|---|
| [57066a] | 3164 |  * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz:
 | 
|---|
 | 3165 |  *  -# a closed path(s) of boundary points surrounding the point to be removed is constructed
 | 
|---|
 | 3166 |  *  -# on each closed path, we pick three adjacent points, create a triangle with them and subtract the middle point from the path
 | 
|---|
 | 3167 |  *  -# we advance two points (i.e. the next triangle will start at the ending point of the last triangle) and continue as before
 | 
|---|
 | 3168 |  *  -# the surface is closed, when the path is empty
 | 
|---|
 | 3169 |  * Thereby, we (hopefully) make sure that the removed points remains beneath the surface (this is checked via IsInnerPoint eventually).
 | 
|---|
| [16d866] | 3170 |  * \param *out output stream for debugging
 | 
|---|
 | 3171 |  * \param *point point to be removed
 | 
|---|
 | 3172 |  * \return volume added to the volume inside the tesselated surface by the removal
 | 
|---|
 | 3173 |  */
 | 
|---|
| [6613ec] | 3174 | double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
 | 
|---|
 | 3175 | {
 | 
|---|
| [16d866] | 3176 |   class BoundaryLineSet *line = NULL;
 | 
|---|
 | 3177 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
| [57066a] | 3178 |   Vector OldPoint, NormalVector;
 | 
|---|
| [16d866] | 3179 |   double volume = 0;
 | 
|---|
 | 3180 |   int count = 0;
 | 
|---|
 | 3181 | 
 | 
|---|
| [1d9b7aa] | 3182 |   if (point == NULL) {
 | 
|---|
| [47d041] | 3183 |     ELOG(1, "Cannot remove the point " << point << ", it's NULL!");
 | 
|---|
| [1d9b7aa] | 3184 |     return 0.;
 | 
|---|
 | 3185 |   } else
 | 
|---|
| [ce7bfd] | 3186 |     LOG(4, "DEBUG: Removing point " << *point << " from tesselated boundary ...");
 | 
|---|
| [1d9b7aa] | 3187 | 
 | 
|---|
| [16d866] | 3188 |   // copy old location for the volume
 | 
|---|
| [d74077] | 3189 |   OldPoint = (point->node->getPosition());
 | 
|---|
| [16d866] | 3190 | 
 | 
|---|
 | 3191 |   // get list of connected points
 | 
|---|
 | 3192 |   if (point->lines.empty()) {
 | 
|---|
| [47d041] | 3193 |     ELOG(1, "Cannot remove the point " << *point << ", it's connected to no lines!");
 | 
|---|
| [16d866] | 3194 |     return 0.;
 | 
|---|
 | 3195 |   }
 | 
|---|
 | 3196 | 
 | 
|---|
| [c15ca2] | 3197 |   list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
 | 
|---|
 | 3198 |   TesselPointList *connectedPath = NULL;
 | 
|---|
| [065e82] | 3199 | 
 | 
|---|
 | 3200 |   // gather all triangles
 | 
|---|
| [16d866] | 3201 |   for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
 | 
|---|
| [6613ec] | 3202 |     count += LineRunner->second->triangles.size();
 | 
|---|
| [c15ca2] | 3203 |   TriangleMap Candidates;
 | 
|---|
| [57066a] | 3204 |   for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
 | 
|---|
| [16d866] | 3205 |     line = LineRunner->second;
 | 
|---|
 | 3206 |     for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
 | 
|---|
 | 3207 |       triangle = TriangleRunner->second;
 | 
|---|
| [6613ec] | 3208 |       Candidates.insert(TrianglePair(triangle->Nr, triangle));
 | 
|---|
| [16d866] | 3209 |     }
 | 
|---|
 | 3210 |   }
 | 
|---|
 | 3211 | 
 | 
|---|
| [065e82] | 3212 |   // remove all triangles
 | 
|---|
| [6613ec] | 3213 |   count = 0;
 | 
|---|
| [57066a] | 3214 |   NormalVector.Zero();
 | 
|---|
| [c15ca2] | 3215 |   for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
 | 
|---|
| [47d041] | 3216 |     LOG(1, "INFO: Removing triangle " << *(Runner->second) << ".");
 | 
|---|
| [273382] | 3217 |     NormalVector -= Runner->second->NormalVector; // has to point inward
 | 
|---|
| [c15ca2] | 3218 |     RemoveTesselationTriangle(Runner->second);
 | 
|---|
| [065e82] | 3219 |     count++;
 | 
|---|
 | 3220 |   }
 | 
|---|
| [47d041] | 3221 |   LOG(1, count << " triangles were removed.");
 | 
|---|
| [065e82] | 3222 | 
 | 
|---|
| [c15ca2] | 3223 |   list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
 | 
|---|
 | 3224 |   list<TesselPointList *>::iterator ListRunner = ListAdvance;
 | 
|---|
 | 3225 |   TriangleMap::iterator NumberRunner = Candidates.begin();
 | 
|---|
 | 3226 |   TesselPointList::iterator StartNode, MiddleNode, EndNode;
 | 
|---|
| [57066a] | 3227 |   double angle;
 | 
|---|
 | 3228 |   double smallestangle;
 | 
|---|
 | 3229 |   Vector Point, Reference, OrthogonalVector;
 | 
|---|
| [6613ec] | 3230 |   if (count > 2) { // less than three triangles, then nothing will be created
 | 
|---|
| [065e82] | 3231 |     class TesselPoint *TriangleCandidates[3];
 | 
|---|
 | 3232 |     count = 0;
 | 
|---|
| [6613ec] | 3233 |     for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
 | 
|---|
| [065e82] | 3234 |       if (ListAdvance != ListOfClosedPaths->end())
 | 
|---|
 | 3235 |         ListAdvance++;
 | 
|---|
 | 3236 | 
 | 
|---|
 | 3237 |       connectedPath = *ListRunner;
 | 
|---|
 | 3238 |       // re-create all triangles by going through connected points list
 | 
|---|
| [c15ca2] | 3239 |       LineList NewLines;
 | 
|---|
| [6613ec] | 3240 |       for (; !connectedPath->empty();) {
 | 
|---|
| [57066a] | 3241 |         // search middle node with widest angle to next neighbours
 | 
|---|
 | 3242 |         EndNode = connectedPath->end();
 | 
|---|
 | 3243 |         smallestangle = 0.;
 | 
|---|
 | 3244 |         for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
 | 
|---|
| [47d041] | 3245 |           LOG(1, "INFO: MiddleNode is " << **MiddleNode << ".");
 | 
|---|
| [57066a] | 3246 |           // construct vectors to next and previous neighbour
 | 
|---|
 | 3247 |           StartNode = MiddleNode;
 | 
|---|
 | 3248 |           if (StartNode == connectedPath->begin())
 | 
|---|
 | 3249 |             StartNode = connectedPath->end();
 | 
|---|
 | 3250 |           StartNode--;
 | 
|---|
| [47d041] | 3251 |           //LOG(3, "INFO: StartNode is " << **StartNode << ".");
 | 
|---|
| [d74077] | 3252 |           Point = ((*StartNode)->getPosition()) - ((*MiddleNode)->getPosition());
 | 
|---|
| [57066a] | 3253 |           StartNode = MiddleNode;
 | 
|---|
 | 3254 |           StartNode++;
 | 
|---|
 | 3255 |           if (StartNode == connectedPath->end())
 | 
|---|
 | 3256 |             StartNode = connectedPath->begin();
 | 
|---|
| [47d041] | 3257 |           //LOG(3, "INFO: EndNode is " << **StartNode << ".");
 | 
|---|
| [d74077] | 3258 |           Reference = ((*StartNode)->getPosition()) - ((*MiddleNode)->getPosition());
 | 
|---|
 | 3259 |           OrthogonalVector = ((*MiddleNode)->getPosition()) - OldPoint;
 | 
|---|
| [0a4f7f] | 3260 |           OrthogonalVector.MakeNormalTo(Reference);
 | 
|---|
| [57066a] | 3261 |           angle = GetAngle(Point, Reference, OrthogonalVector);
 | 
|---|
 | 3262 |           //if (angle < M_PI)  // no wrong-sided triangles, please?
 | 
|---|
| [6613ec] | 3263 |           if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
 | 
|---|
 | 3264 |             smallestangle = angle;
 | 
|---|
 | 3265 |             EndNode = MiddleNode;
 | 
|---|
 | 3266 |           }
 | 
|---|
| [57066a] | 3267 |         }
 | 
|---|
 | 3268 |         MiddleNode = EndNode;
 | 
|---|
 | 3269 |         if (MiddleNode == connectedPath->end()) {
 | 
|---|
| [47d041] | 3270 |           ELOG(0, "CRITICAL: Could not find a smallest angle!");
 | 
|---|
| [f67b6e] | 3271 |           performCriticalExit();
 | 
|---|
| [57066a] | 3272 |         }
 | 
|---|
 | 3273 |         StartNode = MiddleNode;
 | 
|---|
 | 3274 |         if (StartNode == connectedPath->begin())
 | 
|---|
 | 3275 |           StartNode = connectedPath->end();
 | 
|---|
 | 3276 |         StartNode--;
 | 
|---|
 | 3277 |         EndNode++;
 | 
|---|
 | 3278 |         if (EndNode == connectedPath->end())
 | 
|---|
 | 3279 |           EndNode = connectedPath->begin();
 | 
|---|
| [47d041] | 3280 |         LOG(2, "INFO: StartNode is " << **StartNode << ".");
 | 
|---|
 | 3281 |         LOG(2, "INFO: MiddleNode is " << **MiddleNode << ".");
 | 
|---|
 | 3282 |         LOG(2, "INFO: EndNode is " << **EndNode << ".");
 | 
|---|
 | 3283 |         LOG(1, "INFO: Attempting to create triangle " << (*StartNode)->getName() << ", " << (*MiddleNode)->getName() << " and " << (*EndNode)->getName() << ".");
 | 
|---|
| [57066a] | 3284 |         TriangleCandidates[0] = *StartNode;
 | 
|---|
 | 3285 |         TriangleCandidates[1] = *MiddleNode;
 | 
|---|
 | 3286 |         TriangleCandidates[2] = *EndNode;
 | 
|---|
| [e138de] | 3287 |         triangle = GetPresentTriangle(TriangleCandidates);
 | 
|---|
| [57066a] | 3288 |         if (triangle != NULL) {
 | 
|---|
| [47d041] | 3289 |           ELOG(0, "New triangle already present, skipping!");
 | 
|---|
| [57066a] | 3290 |           StartNode++;
 | 
|---|
 | 3291 |           MiddleNode++;
 | 
|---|
 | 3292 |           EndNode++;
 | 
|---|
 | 3293 |           if (StartNode == connectedPath->end())
 | 
|---|
 | 3294 |             StartNode = connectedPath->begin();
 | 
|---|
 | 3295 |           if (MiddleNode == connectedPath->end())
 | 
|---|
 | 3296 |             MiddleNode = connectedPath->begin();
 | 
|---|
 | 3297 |           if (EndNode == connectedPath->end())
 | 
|---|
 | 3298 |             EndNode = connectedPath->begin();
 | 
|---|
 | 3299 |           continue;
 | 
|---|
 | 3300 |         }
 | 
|---|
| [47d041] | 3301 |         LOG(3, "Adding new triangle points.");
 | 
|---|
| [57066a] | 3302 |         AddTesselationPoint(*StartNode, 0);
 | 
|---|
 | 3303 |         AddTesselationPoint(*MiddleNode, 1);
 | 
|---|
 | 3304 |         AddTesselationPoint(*EndNode, 2);
 | 
|---|
| [47d041] | 3305 |         LOG(3, "Adding new triangle lines.");
 | 
|---|
| [f07f86d] | 3306 |         AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
 | 
|---|
 | 3307 |         AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
 | 
|---|
| [57066a] | 3308 |         NewLines.push_back(BLS[1]);
 | 
|---|
| [f07f86d] | 3309 |         AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
 | 
|---|
| [065e82] | 3310 |         BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
| [57066a] | 3311 |         BTS->GetNormalVector(NormalVector);
 | 
|---|
| [065e82] | 3312 |         AddTesselationTriangle();
 | 
|---|
 | 3313 |         // calculate volume summand as a general tetraeder
 | 
|---|
| [d74077] | 3314 |         volume += CalculateVolumeofGeneralTetraeder(TPS[0]->node->getPosition(), TPS[1]->node->getPosition(), TPS[2]->node->getPosition(), OldPoint);
 | 
|---|
| [065e82] | 3315 |         // advance number
 | 
|---|
 | 3316 |         count++;
 | 
|---|
| [57066a] | 3317 | 
 | 
|---|
 | 3318 |         // prepare nodes for next triangle
 | 
|---|
 | 3319 |         StartNode = EndNode;
 | 
|---|
| [47d041] | 3320 |         LOG(2, "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << ".");
 | 
|---|
| [57066a] | 3321 |         connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
 | 
|---|
 | 3322 |         if (connectedPath->size() == 2) { // we are done
 | 
|---|
 | 3323 |           connectedPath->remove(*StartNode); // remove the start node
 | 
|---|
 | 3324 |           connectedPath->remove(*EndNode); // remove the end node
 | 
|---|
 | 3325 |           break;
 | 
|---|
 | 3326 |         } else if (connectedPath->size() < 2) { // something's gone wrong!
 | 
|---|
| [47d041] | 3327 |           ELOG(0, "CRITICAL: There are only two endpoints left!");
 | 
|---|
| [f67b6e] | 3328 |           performCriticalExit();
 | 
|---|
| [57066a] | 3329 |         } else {
 | 
|---|
 | 3330 |           MiddleNode = StartNode;
 | 
|---|
 | 3331 |           MiddleNode++;
 | 
|---|
 | 3332 |           if (MiddleNode == connectedPath->end())
 | 
|---|
 | 3333 |             MiddleNode = connectedPath->begin();
 | 
|---|
 | 3334 |           EndNode = MiddleNode;
 | 
|---|
 | 3335 |           EndNode++;
 | 
|---|
 | 3336 |           if (EndNode == connectedPath->end())
 | 
|---|
 | 3337 |             EndNode = connectedPath->begin();
 | 
|---|
 | 3338 |         }
 | 
|---|
| [065e82] | 3339 |       }
 | 
|---|
| [57066a] | 3340 |       // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
 | 
|---|
 | 3341 |       if (NewLines.size() > 1) {
 | 
|---|
| [c15ca2] | 3342 |         LineList::iterator Candidate;
 | 
|---|
| [57066a] | 3343 |         class BoundaryLineSet *OtherBase = NULL;
 | 
|---|
 | 3344 |         double tmp, maxgain;
 | 
|---|
 | 3345 |         do {
 | 
|---|
 | 3346 |           maxgain = 0;
 | 
|---|
| [6613ec] | 3347 |           for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
 | 
|---|
| [e138de] | 3348 |             tmp = PickFarthestofTwoBaselines(*Runner);
 | 
|---|
| [57066a] | 3349 |             if (maxgain < tmp) {
 | 
|---|
 | 3350 |               maxgain = tmp;
 | 
|---|
 | 3351 |               Candidate = Runner;
 | 
|---|
 | 3352 |             }
 | 
|---|
 | 3353 |           }
 | 
|---|
 | 3354 |           if (maxgain != 0) {
 | 
|---|
 | 3355 |             volume += maxgain;
 | 
|---|
| [47d041] | 3356 |             LOG(1, "Flipping baseline with highest volume" << **Candidate << ".");
 | 
|---|
| [e138de] | 3357 |             OtherBase = FlipBaseline(*Candidate);
 | 
|---|
| [57066a] | 3358 |             NewLines.erase(Candidate);
 | 
|---|
 | 3359 |             NewLines.push_back(OtherBase);
 | 
|---|
 | 3360 |           }
 | 
|---|
 | 3361 |         } while (maxgain != 0.);
 | 
|---|
 | 3362 |       }
 | 
|---|
 | 3363 | 
 | 
|---|
| [065e82] | 3364 |       ListOfClosedPaths->remove(connectedPath);
 | 
|---|
| [6613ec] | 3365 |       delete (connectedPath);
 | 
|---|
| [16d866] | 3366 |     }
 | 
|---|
| [ce7bfd] | 3367 |     LOG(1, "INFO: " << count << " triangles were created.");
 | 
|---|
| [065e82] | 3368 |   } else {
 | 
|---|
 | 3369 |     while (!ListOfClosedPaths->empty()) {
 | 
|---|
 | 3370 |       ListRunner = ListOfClosedPaths->begin();
 | 
|---|
 | 3371 |       connectedPath = *ListRunner;
 | 
|---|
 | 3372 |       ListOfClosedPaths->remove(connectedPath);
 | 
|---|
| [6613ec] | 3373 |       delete (connectedPath);
 | 
|---|
| [065e82] | 3374 |     }
 | 
|---|
| [ce7bfd] | 3375 |     LOG(3, "DEBUG: No need to create any triangles.");
 | 
|---|
| [16d866] | 3376 |   }
 | 
|---|
| [6613ec] | 3377 |   delete (ListOfClosedPaths);
 | 
|---|
| [16d866] | 3378 | 
 | 
|---|
| [ce7bfd] | 3379 |   LOG(1, "INFO: Removed volume is " << volume << ".");
 | 
|---|
| [357fba] | 3380 | 
 | 
|---|
| [57066a] | 3381 |   return volume;
 | 
|---|
| [6613ec] | 3382 | }
 | 
|---|
 | 3383 | ;
 | 
|---|
| [ab1932] | 3384 | 
 | 
|---|
 | 3385 | /**
 | 
|---|
| [62bb91] | 3386 |  * Finds triangles belonging to the three provided points.
 | 
|---|
| [ab1932] | 3387 |  *
 | 
|---|
| [71b20e] | 3388 |  * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
 | 
|---|
| [ab1932] | 3389 |  *
 | 
|---|
| [62bb91] | 3390 |  * @return triangles which belong to the provided points, will be empty if there are none,
 | 
|---|
| [ab1932] | 3391 |  *         will usually be one, in case of degeneration, there will be two
 | 
|---|
 | 3392 |  */
 | 
|---|
| [c15ca2] | 3393 | TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
 | 
|---|
| [ab1932] | 3394 | {
 | 
|---|
| [ce7bfd] | 3395 |   //Info FunctionInfo(__func__);
 | 
|---|
| [6613ec] | 3396 |   TriangleList *result = new TriangleList;
 | 
|---|
| [776b64] | 3397 |   LineMap::const_iterator FindLine;
 | 
|---|
 | 3398 |   TriangleMap::const_iterator FindTriangle;
 | 
|---|
| [ab1932] | 3399 |   class BoundaryPointSet *TrianglePoints[3];
 | 
|---|
| [71b20e] | 3400 |   size_t NoOfWildcards = 0;
 | 
|---|
| [ab1932] | 3401 | 
 | 
|---|
 | 3402 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [71b20e] | 3403 |     if (Points[i] == NULL) {
 | 
|---|
 | 3404 |       NoOfWildcards++;
 | 
|---|
| [ab1932] | 3405 |       TrianglePoints[i] = NULL;
 | 
|---|
| [71b20e] | 3406 |     } else {
 | 
|---|
| [735b1c] | 3407 |       PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->getNr());
 | 
|---|
| [71b20e] | 3408 |       if (FindPoint != PointsOnBoundary.end()) {
 | 
|---|
 | 3409 |         TrianglePoints[i] = FindPoint->second;
 | 
|---|
 | 3410 |       } else {
 | 
|---|
 | 3411 |         TrianglePoints[i] = NULL;
 | 
|---|
 | 3412 |       }
 | 
|---|
| [ab1932] | 3413 |     }
 | 
|---|
 | 3414 |   }
 | 
|---|
 | 3415 | 
 | 
|---|
| [71b20e] | 3416 |   switch (NoOfWildcards) {
 | 
|---|
 | 3417 |     case 0: // checks lines between the points in the Points for their adjacent triangles
 | 
|---|
 | 3418 |       for (int i = 0; i < 3; i++) {
 | 
|---|
 | 3419 |         if (TrianglePoints[i] != NULL) {
 | 
|---|
| [6613ec] | 3420 |           for (int j = i + 1; j < 3; j++) {
 | 
|---|
| [71b20e] | 3421 |             if (TrianglePoints[j] != NULL) {
 | 
|---|
| [735b1c] | 3422 |               for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->getNr()); // is a multimap!
 | 
|---|
 | 3423 |               (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->getNr()); FindLine++) {
 | 
|---|
| [6613ec] | 3424 |                 for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
 | 
|---|
| [71b20e] | 3425 |                   if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
 | 
|---|
 | 3426 |                     result->push_back(FindTriangle->second);
 | 
|---|
 | 3427 |                   }
 | 
|---|
 | 3428 |                 }
 | 
|---|
| [ab1932] | 3429 |               }
 | 
|---|
| [71b20e] | 3430 |               // Is it sufficient to consider one of the triangle lines for this.
 | 
|---|
 | 3431 |               return result;
 | 
|---|
| [ab1932] | 3432 |             }
 | 
|---|
 | 3433 |           }
 | 
|---|
 | 3434 |         }
 | 
|---|
 | 3435 |       }
 | 
|---|
| [71b20e] | 3436 |       break;
 | 
|---|
 | 3437 |     case 1: // copy all triangles of the respective line
 | 
|---|
 | 3438 |     {
 | 
|---|
| [6613ec] | 3439 |       int i = 0;
 | 
|---|
| [71b20e] | 3440 |       for (; i < 3; i++)
 | 
|---|
 | 3441 |         if (TrianglePoints[i] == NULL)
 | 
|---|
 | 3442 |           break;
 | 
|---|
| [735b1c] | 3443 |       for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->getNr()); // is a multimap!
 | 
|---|
 | 3444 |       (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->getNr()); FindLine++) {
 | 
|---|
| [6613ec] | 3445 |         for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
 | 
|---|
| [71b20e] | 3446 |           if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
 | 
|---|
 | 3447 |             result->push_back(FindTriangle->second);
 | 
|---|
 | 3448 |           }
 | 
|---|
 | 3449 |         }
 | 
|---|
 | 3450 |       }
 | 
|---|
 | 3451 |       break;
 | 
|---|
 | 3452 |     }
 | 
|---|
 | 3453 |     case 2: // copy all triangles of the respective point
 | 
|---|
 | 3454 |     {
 | 
|---|
| [6613ec] | 3455 |       int i = 0;
 | 
|---|
| [71b20e] | 3456 |       for (; i < 3; i++)
 | 
|---|
 | 3457 |         if (TrianglePoints[i] != NULL)
 | 
|---|
 | 3458 |           break;
 | 
|---|
 | 3459 |       for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
 | 
|---|
 | 3460 |         for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
 | 
|---|
 | 3461 |           result->push_back(triangle->second);
 | 
|---|
 | 3462 |       result->sort();
 | 
|---|
 | 3463 |       result->unique();
 | 
|---|
 | 3464 |       break;
 | 
|---|
 | 3465 |     }
 | 
|---|
 | 3466 |     case 3: // copy all triangles
 | 
|---|
 | 3467 |     {
 | 
|---|
 | 3468 |       for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
 | 
|---|
 | 3469 |         result->push_back(triangle->second);
 | 
|---|
 | 3470 |       break;
 | 
|---|
| [ab1932] | 3471 |     }
 | 
|---|
| [71b20e] | 3472 |     default:
 | 
|---|
| [47d041] | 3473 |       ELOG(0, "Number of wildcards is greater than 3, cannot happen!");
 | 
|---|
| [71b20e] | 3474 |       performCriticalExit();
 | 
|---|
 | 3475 |       break;
 | 
|---|
| [ab1932] | 3476 |   }
 | 
|---|
 | 3477 | 
 | 
|---|
 | 3478 |   return result;
 | 
|---|
 | 3479 | }
 | 
|---|
 | 3480 | 
 | 
|---|
| [6613ec] | 3481 | struct BoundaryLineSetCompare
 | 
|---|
 | 3482 | {
 | 
|---|
 | 3483 |   bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
 | 
|---|
 | 3484 |   {
 | 
|---|
| [856098] | 3485 |     int lowerNra = -1;
 | 
|---|
 | 3486 |     int lowerNrb = -1;
 | 
|---|
 | 3487 | 
 | 
|---|
 | 3488 |     if (a->endpoints[0] < a->endpoints[1])
 | 
|---|
 | 3489 |       lowerNra = 0;
 | 
|---|
 | 3490 |     else
 | 
|---|
 | 3491 |       lowerNra = 1;
 | 
|---|
 | 3492 | 
 | 
|---|
 | 3493 |     if (b->endpoints[0] < b->endpoints[1])
 | 
|---|
 | 3494 |       lowerNrb = 0;
 | 
|---|
 | 3495 |     else
 | 
|---|
 | 3496 |       lowerNrb = 1;
 | 
|---|
 | 3497 | 
 | 
|---|
 | 3498 |     if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
 | 
|---|
 | 3499 |       return true;
 | 
|---|
 | 3500 |     else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
 | 
|---|
 | 3501 |       return false;
 | 
|---|
| [6613ec] | 3502 |     else { // both lower-numbered endpoints are the same ...
 | 
|---|
 | 3503 |       if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
 | 
|---|
 | 3504 |         return true;
 | 
|---|
 | 3505 |       else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
 | 
|---|
 | 3506 |         return false;
 | 
|---|
| [856098] | 3507 |     }
 | 
|---|
 | 3508 |     return false;
 | 
|---|
| [6613ec] | 3509 |   }
 | 
|---|
 | 3510 |   ;
 | 
|---|
| [856098] | 3511 | };
 | 
|---|
 | 3512 | 
 | 
|---|
 | 3513 | #define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
 | 
|---|
 | 3514 | 
 | 
|---|
| [7c14ec] | 3515 | /**
 | 
|---|
| [57066a] | 3516 |  * Finds all degenerated lines within the tesselation structure.
 | 
|---|
| [7c14ec] | 3517 |  *
 | 
|---|
| [57066a] | 3518 |  * @return map of keys of degenerated line pairs, each line occurs twice
 | 
|---|
| [7c14ec] | 3519 |  *         in the list, once as key and once as value
 | 
|---|
 | 3520 |  */
 | 
|---|
| [c15ca2] | 3521 | IndexToIndex * Tesselation::FindAllDegeneratedLines()
 | 
|---|
| [7c14ec] | 3522 | {
 | 
|---|
| [ce7bfd] | 3523 |   //Info FunctionInfo(__func__);
 | 
|---|
| [6613ec] | 3524 |   UniqueLines AllLines;
 | 
|---|
| [c15ca2] | 3525 |   IndexToIndex * DegeneratedLines = new IndexToIndex;
 | 
|---|
| [7c14ec] | 3526 | 
 | 
|---|
 | 3527 |   // sanity check
 | 
|---|
 | 3528 |   if (LinesOnBoundary.empty()) {
 | 
|---|
| [47d041] | 3529 |     ELOG(2, "FindAllDegeneratedTriangles() was called without any tesselation structure.");
 | 
|---|
| [57066a] | 3530 |     return DegeneratedLines;
 | 
|---|
| [7c14ec] | 3531 |   }
 | 
|---|
| [57066a] | 3532 |   LineMap::iterator LineRunner1;
 | 
|---|
| [6613ec] | 3533 |   pair<UniqueLines::iterator, bool> tester;
 | 
|---|
| [7c14ec] | 3534 |   for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
 | 
|---|
| [6613ec] | 3535 |     tester = AllLines.insert(LineRunner1->second);
 | 
|---|
| [856098] | 3536 |     if (!tester.second) { // found degenerated line
 | 
|---|
| [6613ec] | 3537 |       DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
 | 
|---|
 | 3538 |       DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
 | 
|---|
| [57066a] | 3539 |     }
 | 
|---|
 | 3540 |   }
 | 
|---|
 | 3541 | 
 | 
|---|
 | 3542 |   AllLines.clear();
 | 
|---|
 | 3543 | 
 | 
|---|
| [ce7bfd] | 3544 |   LOG(2, "DEBUG: FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines.");
 | 
|---|
| [c15ca2] | 3545 |   IndexToIndex::iterator it;
 | 
|---|
| [856098] | 3546 |   for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
 | 
|---|
 | 3547 |     const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
 | 
|---|
 | 3548 |     const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
 | 
|---|
 | 3549 |     if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
 | 
|---|
| [ce7bfd] | 3550 |       LOG(3, "DEBUG: " << *Line1->second << " => " << *Line2->second);
 | 
|---|
| [856098] | 3551 |     else
 | 
|---|
| [47d041] | 3552 |       ELOG(1, "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!");
 | 
|---|
| [856098] | 3553 |   }
 | 
|---|
| [57066a] | 3554 | 
 | 
|---|
 | 3555 |   return DegeneratedLines;
 | 
|---|
 | 3556 | }
 | 
|---|
 | 3557 | 
 | 
|---|
 | 3558 | /**
 | 
|---|
 | 3559 |  * Finds all degenerated triangles within the tesselation structure.
 | 
|---|
 | 3560 |  *
 | 
|---|
 | 3561 |  * @return map of keys of degenerated triangle pairs, each triangle occurs twice
 | 
|---|
 | 3562 |  *         in the list, once as key and once as value
 | 
|---|
 | 3563 |  */
 | 
|---|
| [c15ca2] | 3564 | IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
 | 
|---|
| [57066a] | 3565 | {
 | 
|---|
| [ce7bfd] | 3566 |   //Info FunctionInfo(__func__);
 | 
|---|
| [c15ca2] | 3567 |   IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
 | 
|---|
 | 3568 |   IndexToIndex * DegeneratedTriangles = new IndexToIndex;
 | 
|---|
| [57066a] | 3569 |   TriangleMap::iterator TriangleRunner1, TriangleRunner2;
 | 
|---|
 | 3570 |   LineMap::iterator Liner;
 | 
|---|
 | 3571 |   class BoundaryLineSet *line1 = NULL, *line2 = NULL;
 | 
|---|
 | 3572 | 
 | 
|---|
| [c15ca2] | 3573 |   for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
 | 
|---|
| [57066a] | 3574 |     // run over both lines' triangles
 | 
|---|
 | 3575 |     Liner = LinesOnBoundary.find(LineRunner->first);
 | 
|---|
 | 3576 |     if (Liner != LinesOnBoundary.end())
 | 
|---|
 | 3577 |       line1 = Liner->second;
 | 
|---|
 | 3578 |     Liner = LinesOnBoundary.find(LineRunner->second);
 | 
|---|
 | 3579 |     if (Liner != LinesOnBoundary.end())
 | 
|---|
 | 3580 |       line2 = Liner->second;
 | 
|---|
 | 3581 |     for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
 | 
|---|
 | 3582 |       for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
 | 
|---|
| [6613ec] | 3583 |         if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
 | 
|---|
 | 3584 |           DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
 | 
|---|
 | 3585 |           DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
 | 
|---|
| [7c14ec] | 3586 |         }
 | 
|---|
 | 3587 |       }
 | 
|---|
 | 3588 |     }
 | 
|---|
 | 3589 |   }
 | 
|---|
| [6613ec] | 3590 |   delete (DegeneratedLines);
 | 
|---|
| [7c14ec] | 3591 | 
 | 
|---|
| [ce7bfd] | 3592 |   LOG(3, "DEBUG: FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:");
 | 
|---|
| [b32dbb] | 3593 |   for (IndexToIndex::iterator it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
 | 
|---|
| [ce7bfd] | 3594 |     LOG(3, "DEBUG:    " << (*it).first << " => " << (*it).second);
 | 
|---|
| [7c14ec] | 3595 | 
 | 
|---|
 | 3596 |   return DegeneratedTriangles;
 | 
|---|
 | 3597 | }
 | 
|---|
 | 3598 | 
 | 
|---|
 | 3599 | /**
 | 
|---|
 | 3600 |  * Purges degenerated triangles from the tesselation structure if they are not
 | 
|---|
 | 3601 |  * necessary to keep a single point within the structure.
 | 
|---|
 | 3602 |  */
 | 
|---|
 | 3603 | void Tesselation::RemoveDegeneratedTriangles()
 | 
|---|
 | 3604 | {
 | 
|---|
| [ce7bfd] | 3605 |   //Info FunctionInfo(__func__);
 | 
|---|
| [c15ca2] | 3606 |   IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
 | 
|---|
| [57066a] | 3607 |   TriangleMap::iterator finder;
 | 
|---|
 | 3608 |   BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
 | 
|---|
| [6613ec] | 3609 |   int count = 0;
 | 
|---|
| [7c14ec] | 3610 | 
 | 
|---|
| [b32dbb] | 3611 |   // iterate over all degenerated triangles
 | 
|---|
 | 3612 |   for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); !DegeneratedTriangles->empty(); TriangleKeyRunner = DegeneratedTriangles->begin()) {
 | 
|---|
| [ce7bfd] | 3613 |     LOG(3, "DEBUG: Checking presence of triangles " << TriangleKeyRunner->first << " and " << TriangleKeyRunner->second << ".");
 | 
|---|
| [b32dbb] | 3614 |     // both ways are stored in the map, only use one
 | 
|---|
 | 3615 |     if (TriangleKeyRunner->first > TriangleKeyRunner->second)
 | 
|---|
 | 3616 |       continue;
 | 
|---|
 | 3617 | 
 | 
|---|
 | 3618 |     // determine from the keys in the map the two _present_ triangles
 | 
|---|
| [57066a] | 3619 |     finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
 | 
|---|
 | 3620 |     if (finder != TrianglesOnBoundary.end())
 | 
|---|
 | 3621 |       triangle = finder->second;
 | 
|---|
 | 3622 |     else
 | 
|---|
| [b32dbb] | 3623 |       continue;
 | 
|---|
| [57066a] | 3624 |     finder = TrianglesOnBoundary.find(TriangleKeyRunner->second);
 | 
|---|
 | 3625 |     if (finder != TrianglesOnBoundary.end())
 | 
|---|
 | 3626 |       partnerTriangle = finder->second;
 | 
|---|
 | 3627 |     else
 | 
|---|
| [b32dbb] | 3628 |       continue;
 | 
|---|
| [7c14ec] | 3629 | 
 | 
|---|
| [b32dbb] | 3630 |     // determine which lines are shared by the two triangles
 | 
|---|
| [7c14ec] | 3631 |     bool trianglesShareLine = false;
 | 
|---|
 | 3632 |     for (int i = 0; i < 3; ++i)
 | 
|---|
 | 3633 |       for (int j = 0; j < 3; ++j)
 | 
|---|
 | 3634 |         trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
 | 
|---|
 | 3635 | 
 | 
|---|
| [6613ec] | 3636 |     if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
 | 
|---|
| [57066a] | 3637 |       // check whether we have to fix lines
 | 
|---|
 | 3638 |       BoundaryTriangleSet *Othertriangle = NULL;
 | 
|---|
 | 3639 |       BoundaryTriangleSet *OtherpartnerTriangle = NULL;
 | 
|---|
 | 3640 |       TriangleMap::iterator TriangleRunner;
 | 
|---|
 | 3641 |       for (int i = 0; i < 3; ++i)
 | 
|---|
 | 3642 |         for (int j = 0; j < 3; ++j)
 | 
|---|
 | 3643 |           if (triangle->lines[i] != partnerTriangle->lines[j]) {
 | 
|---|
 | 3644 |             // get the other two triangles
 | 
|---|
 | 3645 |             for (TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); ++TriangleRunner)
 | 
|---|
 | 3646 |               if (TriangleRunner->second != triangle) {
 | 
|---|
 | 3647 |                 Othertriangle = TriangleRunner->second;
 | 
|---|
 | 3648 |               }
 | 
|---|
 | 3649 |             for (TriangleRunner = partnerTriangle->lines[i]->triangles.begin(); TriangleRunner != partnerTriangle->lines[i]->triangles.end(); ++TriangleRunner)
 | 
|---|
 | 3650 |               if (TriangleRunner->second != partnerTriangle) {
 | 
|---|
 | 3651 |                 OtherpartnerTriangle = TriangleRunner->second;
 | 
|---|
 | 3652 |               }
 | 
|---|
 | 3653 |             /// interchanges their lines so that triangle->lines[i] == partnerTriangle->lines[j]
 | 
|---|
 | 3654 |             // the line of triangle receives the degenerated ones
 | 
|---|
 | 3655 |             triangle->lines[i]->triangles.erase(Othertriangle->Nr);
 | 
|---|
| [6613ec] | 3656 |             triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
 | 
|---|
 | 3657 |             for (int k = 0; k < 3; k++)
 | 
|---|
| [57066a] | 3658 |               if (triangle->lines[i] == Othertriangle->lines[k]) {
 | 
|---|
 | 3659 |                 Othertriangle->lines[k] = partnerTriangle->lines[j];
 | 
|---|
 | 3660 |                 break;
 | 
|---|
 | 3661 |               }
 | 
|---|
 | 3662 |             // the line of partnerTriangle receives the non-degenerated ones
 | 
|---|
| [6613ec] | 3663 |             partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
 | 
|---|
 | 3664 |             partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
 | 
|---|
| [57066a] | 3665 |             partnerTriangle->lines[j] = triangle->lines[i];
 | 
|---|
 | 3666 |           }
 | 
|---|
 | 3667 | 
 | 
|---|
 | 3668 |       // erase the pair
 | 
|---|
 | 3669 |       count += (int) DegeneratedTriangles->erase(triangle->Nr);
 | 
|---|
| [ce7bfd] | 3670 |       LOG(4, "DEBUG: RemoveDegeneratedTriangles() removes triangle " << *triangle << ".");
 | 
|---|
| [7c14ec] | 3671 |       RemoveTesselationTriangle(triangle);
 | 
|---|
| [57066a] | 3672 |       count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
 | 
|---|
| [ce7bfd] | 3673 |       LOG(4, "DEBUG: RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << ".");
 | 
|---|
| [7c14ec] | 3674 |       RemoveTesselationTriangle(partnerTriangle);
 | 
|---|
 | 3675 |     } else {
 | 
|---|
| [ce7bfd] | 3676 |       LOG(4, "DEBUG: RemoveDegeneratedTriangles() does not remove triangle " << *triangle << " and its partner " << *partnerTriangle << " because it is essential for at" << " least one of the endpoints to be kept in the tesselation structure.");
 | 
|---|
| [7c14ec] | 3677 |     }
 | 
|---|
 | 3678 |   }
 | 
|---|
| [6613ec] | 3679 |   delete (DegeneratedTriangles);
 | 
|---|
| [6a7f78c] | 3680 |   if (count > 0)
 | 
|---|
 | 3681 |     LastTriangle = NULL;
 | 
|---|
| [57066a] | 3682 | 
 | 
|---|
| [ce7bfd] | 3683 |   LOG(2, "INFO: RemoveDegeneratedTriangles() removed " << count << " triangles:");
 | 
|---|
| [7c14ec] | 3684 | }
 | 
|---|
 | 3685 | 
 | 
|---|
| [57066a] | 3686 | /** Adds an outside Tesselpoint to the envelope via (two) degenerated triangles.
 | 
|---|
 | 3687 |  * We look for the closest point on the boundary, we look through its connected boundary lines and
 | 
|---|
 | 3688 |  * seek the one with the minimum angle between its center point and the new point and this base line.
 | 
|---|
 | 3689 |  * We open up the line by adding a degenerated triangle, whose other side closes the base line again.
 | 
|---|
 | 3690 |  * \param *out output stream for debugging
 | 
|---|
 | 3691 |  * \param *point point to add
 | 
|---|
 | 3692 |  * \param *LC Linked Cell structure to find nearest point
 | 
|---|
| [ab1932] | 3693 |  */
 | 
|---|
| [6bd7e0] | 3694 | void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell_deprecated *LC)
 | 
|---|
| [ab1932] | 3695 | {
 | 
|---|
| [ce7bfd] | 3696 |   //Info FunctionInfo(__func__);
 | 
|---|
| [57066a] | 3697 |   // find nearest boundary point
 | 
|---|
 | 3698 |   class TesselPoint *BackupPoint = NULL;
 | 
|---|
| [d74077] | 3699 |   class TesselPoint *NearestPoint = FindClosestTesselPoint(point->getPosition(), BackupPoint, LC);
 | 
|---|
| [57066a] | 3700 |   class BoundaryPointSet *NearestBoundaryPoint = NULL;
 | 
|---|
 | 3701 |   PointMap::iterator PointRunner;
 | 
|---|
 | 3702 | 
 | 
|---|
 | 3703 |   if (NearestPoint == point)
 | 
|---|
 | 3704 |     NearestPoint = BackupPoint;
 | 
|---|
| [735b1c] | 3705 |   PointRunner = PointsOnBoundary.find(NearestPoint->getNr());
 | 
|---|
| [57066a] | 3706 |   if (PointRunner != PointsOnBoundary.end()) {
 | 
|---|
 | 3707 |     NearestBoundaryPoint = PointRunner->second;
 | 
|---|
 | 3708 |   } else {
 | 
|---|
| [47d041] | 3709 |     ELOG(1, "I cannot find the boundary point.");
 | 
|---|
| [57066a] | 3710 |     return;
 | 
|---|
 | 3711 |   }
 | 
|---|
| [ce7bfd] | 3712 |   LOG(3, "DEBUG: Nearest point on boundary is " << NearestPoint->getName() << ".");
 | 
|---|
| [57066a] | 3713 | 
 | 
|---|
 | 3714 |   // go through its lines and find the best one to split
 | 
|---|
 | 3715 |   Vector CenterToPoint;
 | 
|---|
 | 3716 |   Vector BaseLine;
 | 
|---|
 | 3717 |   double angle, BestAngle = 0.;
 | 
|---|
 | 3718 |   class BoundaryLineSet *BestLine = NULL;
 | 
|---|
 | 3719 |   for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) {
 | 
|---|
| [d74077] | 3720 |     BaseLine = (Runner->second->endpoints[0]->node->getPosition()) -
 | 
|---|
 | 3721 |                (Runner->second->endpoints[1]->node->getPosition());
 | 
|---|
 | 3722 |     CenterToPoint = 0.5 * ((Runner->second->endpoints[0]->node->getPosition()) +
 | 
|---|
 | 3723 |                            (Runner->second->endpoints[1]->node->getPosition()));
 | 
|---|
 | 3724 |     CenterToPoint -= (point->getPosition());
 | 
|---|
| [273382] | 3725 |     angle = CenterToPoint.Angle(BaseLine);
 | 
|---|
| [57066a] | 3726 |     if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
 | 
|---|
 | 3727 |       BestAngle = angle;
 | 
|---|
 | 3728 |       BestLine = Runner->second;
 | 
|---|
 | 3729 |     }
 | 
|---|
| [ab1932] | 3730 |   }
 | 
|---|
 | 3731 | 
 | 
|---|
| [57066a] | 3732 |   // remove one triangle from the chosen line
 | 
|---|
 | 3733 |   class BoundaryTriangleSet *TempTriangle = (BestLine->triangles.begin())->second;
 | 
|---|
 | 3734 |   BestLine->triangles.erase(TempTriangle->Nr);
 | 
|---|
 | 3735 |   int nr = -1;
 | 
|---|
| [6613ec] | 3736 |   for (int i = 0; i < 3; i++) {
 | 
|---|
| [57066a] | 3737 |     if (TempTriangle->lines[i] == BestLine) {
 | 
|---|
 | 3738 |       nr = i;
 | 
|---|
 | 3739 |       break;
 | 
|---|
 | 3740 |     }
 | 
|---|
 | 3741 |   }
 | 
|---|
| [ab1932] | 3742 | 
 | 
|---|
| [57066a] | 3743 |   // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
 | 
|---|
| [47d041] | 3744 |   LOG(2, "Adding new triangle points.");
 | 
|---|
| [57066a] | 3745 |   AddTesselationPoint((BestLine->endpoints[0]->node), 0);
 | 
|---|
 | 3746 |   AddTesselationPoint((BestLine->endpoints[1]->node), 1);
 | 
|---|
 | 3747 |   AddTesselationPoint(point, 2);
 | 
|---|
| [47d041] | 3748 |   LOG(2, "Adding new triangle lines.");
 | 
|---|
| [f07f86d] | 3749 |   AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
 | 
|---|
 | 3750 |   AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
 | 
|---|
 | 3751 |   AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
 | 
|---|
| [57066a] | 3752 |   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
 | 3753 |   BTS->GetNormalVector(TempTriangle->NormalVector);
 | 
|---|
 | 3754 |   BTS->NormalVector.Scale(-1.);
 | 
|---|
| [47d041] | 3755 |   LOG(1, "INFO: NormalVector of new triangle is " << BTS->NormalVector << ".");
 | 
|---|
| [57066a] | 3756 |   AddTesselationTriangle();
 | 
|---|
 | 3757 | 
 | 
|---|
 | 3758 |   // create other side of this triangle and close both new sides of the first created triangle
 | 
|---|
| [47d041] | 3759 |   LOG(2, "Adding new triangle points.");
 | 
|---|
| [57066a] | 3760 |   AddTesselationPoint((BestLine->endpoints[0]->node), 0);
 | 
|---|
 | 3761 |   AddTesselationPoint((BestLine->endpoints[1]->node), 1);
 | 
|---|
 | 3762 |   AddTesselationPoint(point, 2);
 | 
|---|
| [47d041] | 3763 |   LOG(2, "Adding new triangle lines.");
 | 
|---|
| [f07f86d] | 3764 |   AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
 | 
|---|
 | 3765 |   AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
 | 
|---|
 | 3766 |   AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
 | 
|---|
| [57066a] | 3767 |   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
 | 
|---|
 | 3768 |   BTS->GetNormalVector(TempTriangle->NormalVector);
 | 
|---|
| [47d041] | 3769 |   LOG(1, "INFO: NormalVector of other new triangle is " << BTS->NormalVector << ".");
 | 
|---|
| [57066a] | 3770 |   AddTesselationTriangle();
 | 
|---|
 | 3771 | 
 | 
|---|
 | 3772 |   // add removed triangle to the last open line of the second triangle
 | 
|---|
| [6613ec] | 3773 |   for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion)
 | 
|---|
| [57066a] | 3774 |     if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
 | 
|---|
| [6613ec] | 3775 |       if (BestLine == BTS->lines[i]) {
 | 
|---|
| [47d041] | 3776 |         ELOG(0, "BestLine is same as found line, something's wrong here!");
 | 
|---|
| [f67b6e] | 3777 |         performCriticalExit();
 | 
|---|
| [57066a] | 3778 |       }
 | 
|---|
| [6613ec] | 3779 |       BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));
 | 
|---|
| [57066a] | 3780 |       TempTriangle->lines[nr] = BTS->lines[i];
 | 
|---|
 | 3781 |       break;
 | 
|---|
 | 3782 |     }
 | 
|---|
 | 3783 |   }
 | 
|---|
| [6613ec] | 3784 | }
 | 
|---|
 | 3785 | ;
 | 
|---|
| [57066a] | 3786 | 
 | 
|---|
 | 3787 | /** Writes the envelope to file.
 | 
|---|
 | 3788 |  * \param *out otuput stream for debugging
 | 
|---|
 | 3789 |  * \param *filename basename of output file
 | 
|---|
| [34c43a] | 3790 |  * \param *cloud IPointCloud structure with all nodes
 | 
|---|
| [57066a] | 3791 |  */
 | 
|---|
| [34c43a] | 3792 | void Tesselation::Output(const char *filename, IPointCloud & cloud)
 | 
|---|
| [57066a] | 3793 | {
 | 
|---|
| [ce7bfd] | 3794 |   //Info FunctionInfo(__func__);
 | 
|---|
| [57066a] | 3795 |   ofstream *tempstream = NULL;
 | 
|---|
 | 3796 |   string NameofTempFile;
 | 
|---|
| [68f03d] | 3797 |   string NumberName;
 | 
|---|
| [57066a] | 3798 | 
 | 
|---|
 | 3799 |   if (LastTriangle != NULL) {
 | 
|---|
| [68f03d] | 3800 |     stringstream sstr;
 | 
|---|
| [8f215d] | 3801 |     sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->getEndpointName(0) << "_" << LastTriangle->getEndpointName(1) << "_" << LastTriangle->getEndpointName(2);
 | 
|---|
| [68f03d] | 3802 |     NumberName = sstr.str();
 | 
|---|
| [57066a] | 3803 |     if (DoTecplotOutput) {
 | 
|---|
 | 3804 |       string NameofTempFile(filename);
 | 
|---|
 | 3805 |       NameofTempFile.append(NumberName);
 | 
|---|
| [6613ec] | 3806 |       for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
 | 
|---|
 | 3807 |         NameofTempFile.erase(npos, 1);
 | 
|---|
| [57066a] | 3808 |       NameofTempFile.append(TecplotSuffix);
 | 
|---|
| [47d041] | 3809 |       LOG(1, "INFO: Writing temporary non convex hull to file " << NameofTempFile << ".");
 | 
|---|
| [57066a] | 3810 |       tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
 | 
|---|
| [e138de] | 3811 |       WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
 | 
|---|
| [57066a] | 3812 |       tempstream->close();
 | 
|---|
 | 3813 |       tempstream->flush();
 | 
|---|
| [6613ec] | 3814 |       delete (tempstream);
 | 
|---|
| [57066a] | 3815 |     }
 | 
|---|
 | 3816 | 
 | 
|---|
 | 3817 |     if (DoRaster3DOutput) {
 | 
|---|
 | 3818 |       string NameofTempFile(filename);
 | 
|---|
 | 3819 |       NameofTempFile.append(NumberName);
 | 
|---|
| [6613ec] | 3820 |       for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
 | 
|---|
 | 3821 |         NameofTempFile.erase(npos, 1);
 | 
|---|
| [57066a] | 3822 |       NameofTempFile.append(Raster3DSuffix);
 | 
|---|
| [47d041] | 3823 |       LOG(1, "INFO: Writing temporary non convex hull to file " << NameofTempFile << ".");
 | 
|---|
| [57066a] | 3824 |       tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
 | 
|---|
| [e138de] | 3825 |       WriteRaster3dFile(tempstream, this, cloud);
 | 
|---|
 | 3826 |       IncludeSphereinRaster3D(tempstream, this, cloud);
 | 
|---|
| [57066a] | 3827 |       tempstream->close();
 | 
|---|
 | 3828 |       tempstream->flush();
 | 
|---|
| [6613ec] | 3829 |       delete (tempstream);
 | 
|---|
| [57066a] | 3830 |     }
 | 
|---|
 | 3831 |   }
 | 
|---|
 | 3832 |   if (DoTecplotOutput || DoRaster3DOutput)
 | 
|---|
 | 3833 |     TriangleFilesWritten++;
 | 
|---|
| [6613ec] | 3834 | }
 | 
|---|
 | 3835 | ;
 | 
|---|
| [262bae] | 3836 | 
 | 
|---|
| [6613ec] | 3837 | struct BoundaryPolygonSetCompare
 | 
|---|
 | 3838 | {
 | 
|---|
 | 3839 |   bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
 | 
|---|
 | 3840 |   {
 | 
|---|
| [856098] | 3841 |     if (s1->endpoints.size() < s2->endpoints.size())
 | 
|---|
 | 3842 |       return true;
 | 
|---|
 | 3843 |     else if (s1->endpoints.size() > s2->endpoints.size())
 | 
|---|
 | 3844 |       return false;
 | 
|---|
 | 3845 |     else { // equality of number of endpoints
 | 
|---|
 | 3846 |       PointSet::const_iterator Walker1 = s1->endpoints.begin();
 | 
|---|
 | 3847 |       PointSet::const_iterator Walker2 = s2->endpoints.begin();
 | 
|---|
 | 3848 |       while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
 | 
|---|
 | 3849 |         if ((*Walker1)->Nr < (*Walker2)->Nr)
 | 
|---|
 | 3850 |           return true;
 | 
|---|
 | 3851 |         else if ((*Walker1)->Nr > (*Walker2)->Nr)
 | 
|---|
 | 3852 |           return false;
 | 
|---|
 | 3853 |         Walker1++;
 | 
|---|
 | 3854 |         Walker2++;
 | 
|---|
 | 3855 |       }
 | 
|---|
 | 3856 |       return false;
 | 
|---|
 | 3857 |     }
 | 
|---|
 | 3858 |   }
 | 
|---|
 | 3859 | };
 | 
|---|
 | 3860 | 
 | 
|---|
 | 3861 | #define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
 | 
|---|
 | 3862 | 
 | 
|---|
| [262bae] | 3863 | /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
 | 
|---|
 | 3864 |  * \return number of polygons found
 | 
|---|
 | 3865 |  */
 | 
|---|
 | 3866 | int Tesselation::CorrectAllDegeneratedPolygons()
 | 
|---|
 | 3867 | {
 | 
|---|
| [ce7bfd] | 3868 |   //Info FunctionInfo(__func__);
 | 
|---|
| [fad93c] | 3869 |   /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
 | 
|---|
| [c15ca2] | 3870 |   IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
 | 
|---|
| [6613ec] | 3871 |   set<BoundaryPointSet *> EndpointCandidateList;
 | 
|---|
 | 3872 |   pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
 | 
|---|
 | 3873 |   pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
 | 
|---|
| [fad93c] | 3874 |   for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
 | 
|---|
| [ce7bfd] | 3875 |     LOG(3, "DEBUG: Current point is " << *Runner->second << ".");
 | 
|---|
| [6613ec] | 3876 |     map<int, Vector *> TriangleVectors;
 | 
|---|
| [fad93c] | 3877 |     // gather all NormalVectors
 | 
|---|
| [ce7bfd] | 3878 |     LOG(4, "DEBUG: Gathering triangles ...");
 | 
|---|
| [fad93c] | 3879 |     for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
 | 
|---|
 | 3880 |       for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
 | 
|---|
| [b998c3] | 3881 |         if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
 | 
|---|
| [6613ec] | 3882 |           TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
 | 
|---|
| [b998c3] | 3883 |           if (TriangleInsertionTester.second)
 | 
|---|
| [ce7bfd] | 3884 |             LOG(5, "DEBUG:  Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list.");
 | 
|---|
| [b998c3] | 3885 |         } else {
 | 
|---|
| [ce7bfd] | 3886 |           LOG(5, "DEBUG:  NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one.");
 | 
|---|
| [b998c3] | 3887 |         }
 | 
|---|
| [fad93c] | 3888 |       }
 | 
|---|
 | 3889 |     // check whether there are two that are parallel
 | 
|---|
| [ce7bfd] | 3890 |     LOG(3, "DEBUG: Finding two parallel triangles ...");
 | 
|---|
| [6613ec] | 3891 |     for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
 | 
|---|
 | 3892 |       for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
 | 
|---|
| [fad93c] | 3893 |         if (VectorWalker != VectorRunner) { // skip equals
 | 
|---|
| [8cbb97] | 3894 |           const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
 | 
|---|
| [ce7bfd] | 3895 |           LOG(4, "DEBUG: Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP);
 | 
|---|
| [fad93c] | 3896 |           if (fabs(SCP + 1.) < ParallelEpsilon) {
 | 
|---|
 | 3897 |             InsertionTester = EndpointCandidateList.insert((Runner->second));
 | 
|---|
 | 3898 |             if (InsertionTester.second)
 | 
|---|
| [ce7bfd] | 3899 |               LOG(4, "DEBUG:  Adding " << *Runner->second << " to endpoint candidate list.");
 | 
|---|
| [fad93c] | 3900 |             // and break out of both loops
 | 
|---|
 | 3901 |             VectorWalker = TriangleVectors.end();
 | 
|---|
 | 3902 |             VectorRunner = TriangleVectors.end();
 | 
|---|
 | 3903 |             break;
 | 
|---|
 | 3904 |           }
 | 
|---|
 | 3905 |         }
 | 
|---|
 | 3906 |   }
 | 
|---|
| [9d4c20] | 3907 |   delete DegeneratedTriangles;
 | 
|---|
| [856098] | 3908 | 
 | 
|---|
| [fad93c] | 3909 |   /// 3. Find connected endpoint candidates and put them into a polygon
 | 
|---|
 | 3910 |   UniquePolygonSet ListofDegeneratedPolygons;
 | 
|---|
 | 3911 |   BoundaryPointSet *Walker = NULL;
 | 
|---|
 | 3912 |   BoundaryPointSet *OtherWalker = NULL;
 | 
|---|
 | 3913 |   BoundaryPolygonSet *Current = NULL;
 | 
|---|
| [6613ec] | 3914 |   stack<BoundaryPointSet*> ToCheckConnecteds;
 | 
|---|
| [fad93c] | 3915 |   while (!EndpointCandidateList.empty()) {
 | 
|---|
 | 3916 |     Walker = *(EndpointCandidateList.begin());
 | 
|---|
| [6613ec] | 3917 |     if (Current == NULL) { // create a new polygon with current candidate
 | 
|---|
| [ce7bfd] | 3918 |       LOG(3, "DEBUG: Starting new polygon set at point " << *Walker);
 | 
|---|
| [fad93c] | 3919 |       Current = new BoundaryPolygonSet;
 | 
|---|
 | 3920 |       Current->endpoints.insert(Walker);
 | 
|---|
 | 3921 |       EndpointCandidateList.erase(Walker);
 | 
|---|
 | 3922 |       ToCheckConnecteds.push(Walker);
 | 
|---|
| [856098] | 3923 |     }
 | 
|---|
| [262bae] | 3924 | 
 | 
|---|
| [fad93c] | 3925 |     // go through to-check stack
 | 
|---|
 | 3926 |     while (!ToCheckConnecteds.empty()) {
 | 
|---|
 | 3927 |       Walker = ToCheckConnecteds.top(); // fetch ...
 | 
|---|
 | 3928 |       ToCheckConnecteds.pop(); // ... and remove
 | 
|---|
 | 3929 |       for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
 | 
|---|
 | 3930 |         OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
 | 
|---|
| [ce7bfd] | 3931 |         LOG(4, "DEBUG: Checking " << *OtherWalker);
 | 
|---|
| [6613ec] | 3932 |         set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
 | 
|---|
 | 3933 |         if (Finder != EndpointCandidateList.end()) { // found a connected partner
 | 
|---|
| [ce7bfd] | 3934 |           LOG(5, "DEBUG:  Adding to polygon.");
 | 
|---|
| [fad93c] | 3935 |           Current->endpoints.insert(OtherWalker);
 | 
|---|
| [6613ec] | 3936 |           EndpointCandidateList.erase(Finder); // remove from candidates
 | 
|---|
 | 3937 |           ToCheckConnecteds.push(OtherWalker); // but check its partners too
 | 
|---|
| [856098] | 3938 |         } else {
 | 
|---|
| [ce7bfd] | 3939 |           LOG(5, "DEBUG:  is not connected to " << *Walker);
 | 
|---|
| [856098] | 3940 |         }
 | 
|---|
 | 3941 |       }
 | 
|---|
 | 3942 |     }
 | 
|---|
| [262bae] | 3943 | 
 | 
|---|
| [ce7bfd] | 3944 |     LOG(3, "DEBUG: Final polygon is " << *Current);
 | 
|---|
| [fad93c] | 3945 |     ListofDegeneratedPolygons.insert(Current);
 | 
|---|
 | 3946 |     Current = NULL;
 | 
|---|
| [262bae] | 3947 |   }
 | 
|---|
 | 3948 | 
 | 
|---|
| [fad93c] | 3949 |   const int counter = ListofDegeneratedPolygons.size();
 | 
|---|
| [262bae] | 3950 | 
 | 
|---|
| [47d041] | 3951 |   if (DoLog(0)) {
 | 
|---|
 | 3952 |     std::stringstream output;
 | 
|---|
 | 3953 |     output << "The following " << counter << " degenerated polygons have been found: ";
 | 
|---|
 | 3954 |     for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
 | 
|---|
 | 3955 |       output << " " << **PolygonRunner;
 | 
|---|
| [ce7bfd] | 3956 |     LOG(3, "DEBUG: " << output.str());
 | 
|---|
| [47d041] | 3957 |   }
 | 
|---|
| [856098] | 3958 | 
 | 
|---|
| [262bae] | 3959 |   /// 4. Go through all these degenerated polygons
 | 
|---|
| [fad93c] | 3960 |   for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
 | 
|---|
| [6613ec] | 3961 |     stack<int> TriangleNrs;
 | 
|---|
| [856098] | 3962 |     Vector NormalVector;
 | 
|---|
| [262bae] | 3963 |     /// 4a. Gather all triangles of this polygon
 | 
|---|
| [856098] | 3964 |     TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
 | 
|---|
| [262bae] | 3965 | 
 | 
|---|
| [125b3c] | 3966 |     // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
 | 
|---|
| [b998c3] | 3967 |     if (T->size() == 2) {
 | 
|---|
| [ce7bfd] | 3968 |       LOG(4, "DEBUG:  Skipping degenerated polygon, is just a (already simply degenerated) triangle.");
 | 
|---|
| [6613ec] | 3969 |       delete (T);
 | 
|---|
| [b998c3] | 3970 |       continue;
 | 
|---|
 | 3971 |     }
 | 
|---|
 | 3972 | 
 | 
|---|
| [125b3c] | 3973 |     // check whether number is even
 | 
|---|
 | 3974 |     // If this case occurs, we have to think about it!
 | 
|---|
 | 3975 |     // The Problem is probably due to two degenerated polygons being connected by a bridging, non-degenerated polygon, as somehow one node has
 | 
|---|
 | 3976 |     // connections to either polygon ...
 | 
|---|
 | 3977 |     if (T->size() % 2 != 0) {
 | 
|---|
| [47d041] | 3978 |       ELOG(0, " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!");
 | 
|---|
| [125b3c] | 3979 |       performCriticalExit();
 | 
|---|
 | 3980 |     }
 | 
|---|
| [6613ec] | 3981 |     TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
 | 
|---|
| [262bae] | 3982 |     /// 4a. Get NormalVector for one side (this is "front")
 | 
|---|
| [273382] | 3983 |     NormalVector = (*TriangleWalker)->NormalVector;
 | 
|---|
| [ce7bfd] | 3984 |     LOG(4, "DEBUG: \"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector);
 | 
|---|
| [856098] | 3985 |     TriangleWalker++;
 | 
|---|
 | 3986 |     TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
 | 
|---|
| [262bae] | 3987 |     /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
 | 
|---|
| [856098] | 3988 |     BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 3989 |     while (TriangleSprinter != T->end()) {
 | 
|---|
 | 3990 |       TriangleWalker = TriangleSprinter;
 | 
|---|
 | 3991 |       triangle = *TriangleWalker;
 | 
|---|
 | 3992 |       TriangleSprinter++;
 | 
|---|
| [ce7bfd] | 3993 |       LOG(4, "DEBUG: Current triangle to test for removal: " << *triangle);
 | 
|---|
| [273382] | 3994 |       if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list
 | 
|---|
| [ce7bfd] | 3995 |         LOG(5, "DEBUG:  Removing ... ");
 | 
|---|
| [856098] | 3996 |         TriangleNrs.push(triangle->Nr);
 | 
|---|
| [262bae] | 3997 |         T->erase(TriangleWalker);
 | 
|---|
| [856098] | 3998 |         RemoveTesselationTriangle(triangle);
 | 
|---|
 | 3999 |       } else
 | 
|---|
| [ce7bfd] | 4000 |         LOG(5, "DEBUG:  Keeping ... ");
 | 
|---|
| [262bae] | 4001 |     }
 | 
|---|
 | 4002 |     /// 4c. Copy all "front" triangles but with inverse NormalVector
 | 
|---|
 | 4003 |     TriangleWalker = T->begin();
 | 
|---|
| [6613ec] | 4004 |     while (TriangleWalker != T->end()) { // go through all front triangles
 | 
|---|
| [ce7bfd] | 4005 |       LOG(4, "DEBUG:  Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector);
 | 
|---|
| [856098] | 4006 |       for (int i = 0; i < 3; i++)
 | 
|---|
 | 4007 |         AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
 | 
|---|
| [f07f86d] | 4008 |       AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
 | 
|---|
 | 4009 |       AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
 | 
|---|
 | 4010 |       AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
 | 
|---|
| [fad93c] | 4011 |       if (TriangleNrs.empty())
 | 
|---|
| [47d041] | 4012 |         ELOG(0, "No more free triangle numbers!");
 | 
|---|
| [856098] | 4013 |       BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
 | 
|---|
 | 4014 |       AddTesselationTriangle(); // ... and add
 | 
|---|
 | 4015 |       TriangleNrs.pop();
 | 
|---|
| [273382] | 4016 |       BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector;
 | 
|---|
| [262bae] | 4017 |       TriangleWalker++;
 | 
|---|
 | 4018 |     }
 | 
|---|
| [856098] | 4019 |     if (!TriangleNrs.empty()) {
 | 
|---|
| [47d041] | 4020 |       ELOG(0, "There have been less triangles created than removed!");
 | 
|---|
| [856098] | 4021 |     }
 | 
|---|
| [6613ec] | 4022 |     delete (T); // remove the triangleset
 | 
|---|
| [262bae] | 4023 |   }
 | 
|---|
| [c15ca2] | 4024 |   IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
 | 
|---|
| [ce7bfd] | 4025 |   LOG(2, "DEBUG: Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:");
 | 
|---|
| [c15ca2] | 4026 |   IndexToIndex::iterator it;
 | 
|---|
| [856098] | 4027 |   for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
 | 
|---|
| [ce7bfd] | 4028 |     LOG(2, "DEBUG:   " << (*it).first << " => " << (*it).second);
 | 
|---|
| [6613ec] | 4029 |   delete (SimplyDegeneratedTriangles);
 | 
|---|
| [262bae] | 4030 |   /// 5. exit
 | 
|---|
| [856098] | 4031 |   UniquePolygonSet::iterator PolygonRunner;
 | 
|---|
| [fad93c] | 4032 |   while (!ListofDegeneratedPolygons.empty()) {
 | 
|---|
 | 4033 |     PolygonRunner = ListofDegeneratedPolygons.begin();
 | 
|---|
| [6613ec] | 4034 |     delete (*PolygonRunner);
 | 
|---|
| [fad93c] | 4035 |     ListofDegeneratedPolygons.erase(PolygonRunner);
 | 
|---|
| [262bae] | 4036 |   }
 | 
|---|
 | 4037 | 
 | 
|---|
 | 4038 |   return counter;
 | 
|---|
| [6613ec] | 4039 | }
 | 
|---|
 | 4040 | ;
 | 
|---|