| [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 |  | 
|---|
|  | 2604 | /** Returns the distance to the surface given by the tesselation. | 
|---|
| [97498a] | 2605 | * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points | 
|---|
| [9473f6] | 2606 | * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the | 
|---|
|  | 2607 | * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's | 
|---|
|  | 2608 | * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle(). | 
|---|
|  | 2609 | * In the end we additionally find the point on the triangle who was smallest distance to \a Point: | 
|---|
|  | 2610 | *  -# Separate distance from point to center in vector in NormalDirection and on the triangle plane. | 
|---|
|  | 2611 | *  -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds. | 
|---|
|  | 2612 | *  -# If inside, take it to calculate closest distance | 
|---|
|  | 2613 | *  -# If not, take intersection with BoundaryLine as distance | 
|---|
|  | 2614 | * | 
|---|
|  | 2615 | * @note distance is squared despite it still contains a sign to determine in-/outside! | 
|---|
| [62bb91] | 2616 | * | 
|---|
|  | 2617 | * @param point of which to check the position | 
|---|
| [6bd7e0] | 2618 | * @param *LC LinkedCell_deprecated structure | 
|---|
| [62bb91] | 2619 | * | 
|---|
| [244a84] | 2620 | * @return >0 if outside, ==0 if on surface, <0 if inside | 
|---|
| [62bb91] | 2621 | */ | 
|---|
| [244a84] | 2622 | double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const | 
|---|
| [62bb91] | 2623 | { | 
|---|
| [ce7bfd] | 2624 | //Info FunctionInfo(__func__); | 
|---|
| [57066a] | 2625 | Vector Center; | 
|---|
| [71b20e] | 2626 | Vector helper; | 
|---|
| [97498a] | 2627 | Vector DistanceToCenter; | 
|---|
|  | 2628 | Vector Intersection; | 
|---|
| [9473f6] | 2629 | double distance = 0.; | 
|---|
| [57066a] | 2630 |  | 
|---|
| [244a84] | 2631 | if (triangle == NULL) {// is boundary point or only point in point cloud? | 
|---|
| [47d041] | 2632 | LOG(1, "No triangle given!"); | 
|---|
| [244a84] | 2633 | return -1.; | 
|---|
| [71b20e] | 2634 | } else { | 
|---|
| [47d041] | 2635 | LOG(1, "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "."); | 
|---|
| [57066a] | 2636 | } | 
|---|
|  | 2637 |  | 
|---|
| [d74077] | 2638 | triangle->GetCenter(Center); | 
|---|
| [47d041] | 2639 | LOG(2, "INFO: Central point of the triangle is " << Center << "."); | 
|---|
| [273382] | 2640 | DistanceToCenter = Center - Point; | 
|---|
| [47d041] | 2641 | LOG(2, "INFO: Vector from point to test to center is " << DistanceToCenter << "."); | 
|---|
| [97498a] | 2642 |  | 
|---|
|  | 2643 | // check whether we are on boundary | 
|---|
| [273382] | 2644 | if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) { | 
|---|
| [97498a] | 2645 | // calculate whether inside of triangle | 
|---|
| [273382] | 2646 | DistanceToCenter = Point + triangle->NormalVector; // points outside | 
|---|
|  | 2647 | Center = Point - triangle->NormalVector; // points towards MolCenter | 
|---|
| [47d041] | 2648 | LOG(1, "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "."); | 
|---|
| [d74077] | 2649 | if (triangle->GetIntersectionInsideTriangle(Center, DistanceToCenter, Intersection)) { | 
|---|
| [47d041] | 2650 | LOG(1, Point << " is inner point: sufficiently close to boundary, " << Intersection << "."); | 
|---|
| [9473f6] | 2651 | return 0.; | 
|---|
| [97498a] | 2652 | } else { | 
|---|
| [47d041] | 2653 | LOG(1, Point << " is NOT an inner point: on triangle plane but outside of triangle bounds."); | 
|---|
| [97498a] | 2654 | return false; | 
|---|
|  | 2655 | } | 
|---|
| [57066a] | 2656 | } else { | 
|---|
| [9473f6] | 2657 | // calculate smallest distance | 
|---|
| [d74077] | 2658 | distance = triangle->GetClosestPointInsideTriangle(Point, Intersection); | 
|---|
| [47d041] | 2659 | LOG(1, "Closest point on triangle is " << Intersection << "."); | 
|---|
| [9473f6] | 2660 |  | 
|---|
|  | 2661 | // then check direction to boundary | 
|---|
| [273382] | 2662 | if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) { | 
|---|
| [47d041] | 2663 | LOG(1, Point << " is an inner point, " << distance << " below surface."); | 
|---|
| [9473f6] | 2664 | return -distance; | 
|---|
|  | 2665 | } else { | 
|---|
| [47d041] | 2666 | LOG(1, Point << " is NOT an inner point, " << distance << " above surface."); | 
|---|
| [9473f6] | 2667 | return +distance; | 
|---|
|  | 2668 | } | 
|---|
| [57066a] | 2669 | } | 
|---|
| [6613ec] | 2670 | } | 
|---|
|  | 2671 | ; | 
|---|
| [62bb91] | 2672 |  | 
|---|
| [8db598] | 2673 | /** Calculates minimum distance from \a&Point to a tesselated surface. | 
|---|
| [244a84] | 2674 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle(). | 
|---|
|  | 2675 | * \param &Point point to calculate distance from | 
|---|
|  | 2676 | * \param *LC needed for finding closest points fast | 
|---|
|  | 2677 | * \return distance squared to closest point on surface | 
|---|
|  | 2678 | */ | 
|---|
| [6bd7e0] | 2679 | double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const | 
|---|
| [244a84] | 2680 | { | 
|---|
| [ce7bfd] | 2681 | //Info FunctionInfo(__func__); | 
|---|
| [d74077] | 2682 | TriangleIntersectionList Intersections(Point, this, LC); | 
|---|
| [8db598] | 2683 |  | 
|---|
|  | 2684 | return Intersections.GetSmallestDistance(); | 
|---|
| [6613ec] | 2685 | } | 
|---|
|  | 2686 | ; | 
|---|
| [8db598] | 2687 |  | 
|---|
|  | 2688 | /** Calculates minimum distance from \a&Point to a tesselated surface. | 
|---|
|  | 2689 | * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle(). | 
|---|
|  | 2690 | * \param &Point point to calculate distance from | 
|---|
|  | 2691 | * \param *LC needed for finding closest points fast | 
|---|
|  | 2692 | * \return distance squared to closest point on surface | 
|---|
|  | 2693 | */ | 
|---|
| [6bd7e0] | 2694 | BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell_deprecated* const LC) const | 
|---|
| [8db598] | 2695 | { | 
|---|
| [ce7bfd] | 2696 | //Info FunctionInfo(__func__); | 
|---|
| [d74077] | 2697 | TriangleIntersectionList Intersections(Point, this, LC); | 
|---|
| [8db598] | 2698 |  | 
|---|
|  | 2699 | return Intersections.GetClosestTriangle(); | 
|---|
| [6613ec] | 2700 | } | 
|---|
|  | 2701 | ; | 
|---|
| [244a84] | 2702 |  | 
|---|
| [62bb91] | 2703 | /** Gets all points connected to the provided point by triangulation lines. | 
|---|
|  | 2704 | * | 
|---|
|  | 2705 | * @param *Point of which get all connected points | 
|---|
|  | 2706 | * | 
|---|
| [065e82] | 2707 | * @return set of the all points linked to the provided one | 
|---|
| [62bb91] | 2708 | */ | 
|---|
| [c15ca2] | 2709 | TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const | 
|---|
| [62bb91] | 2710 | { | 
|---|
| [ce7bfd] | 2711 | //Info FunctionInfo(__func__); | 
|---|
| [6613ec] | 2712 | TesselPointSet *connectedPoints = new TesselPointSet; | 
|---|
| [5c7bf8] | 2713 | class BoundaryPointSet *ReferencePoint = NULL; | 
|---|
| [62bb91] | 2714 | TesselPoint* current; | 
|---|
|  | 2715 | bool takePoint = false; | 
|---|
| [5c7bf8] | 2716 | // find the respective boundary point | 
|---|
| [735b1c] | 2717 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->getNr()); | 
|---|
| [5c7bf8] | 2718 | if (PointRunner != PointsOnBoundary.end()) { | 
|---|
|  | 2719 | ReferencePoint = PointRunner->second; | 
|---|
|  | 2720 | } else { | 
|---|
| [47d041] | 2721 | ELOG(2, "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "."); | 
|---|
| [5c7bf8] | 2722 | ReferencePoint = NULL; | 
|---|
|  | 2723 | } | 
|---|
| [62bb91] | 2724 |  | 
|---|
| [065e82] | 2725 | // little trick so that we look just through lines connect to the BoundaryPoint | 
|---|
| [5c7bf8] | 2726 | // OR fall-back to look through all lines if there is no such BoundaryPoint | 
|---|
| [6613ec] | 2727 | const LineMap *Lines; | 
|---|
|  | 2728 | ; | 
|---|
| [5c7bf8] | 2729 | if (ReferencePoint != NULL) | 
|---|
|  | 2730 | Lines = &(ReferencePoint->lines); | 
|---|
| [776b64] | 2731 | else | 
|---|
|  | 2732 | Lines = &LinesOnBoundary; | 
|---|
|  | 2733 | LineMap::const_iterator findLines = Lines->begin(); | 
|---|
| [5c7bf8] | 2734 | while (findLines != Lines->end()) { | 
|---|
| [6613ec] | 2735 | takePoint = false; | 
|---|
|  | 2736 |  | 
|---|
| [735b1c] | 2737 | if (findLines->second->endpoints[0]->Nr == Point->getNr()) { | 
|---|
| [6613ec] | 2738 | takePoint = true; | 
|---|
|  | 2739 | current = findLines->second->endpoints[1]->node; | 
|---|
| [735b1c] | 2740 | } else if (findLines->second->endpoints[1]->Nr == Point->getNr()) { | 
|---|
| [6613ec] | 2741 | takePoint = true; | 
|---|
|  | 2742 | current = findLines->second->endpoints[0]->node; | 
|---|
|  | 2743 | } | 
|---|
| [065e82] | 2744 |  | 
|---|
| [6613ec] | 2745 | if (takePoint) { | 
|---|
| [47d041] | 2746 | LOG(1, "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted."); | 
|---|
| [6613ec] | 2747 | connectedPoints->insert(current); | 
|---|
|  | 2748 | } | 
|---|
| [62bb91] | 2749 |  | 
|---|
| [6613ec] | 2750 | findLines++; | 
|---|
| [62bb91] | 2751 | } | 
|---|
|  | 2752 |  | 
|---|
| [71b20e] | 2753 | if (connectedPoints->empty()) { // if have not found any points | 
|---|
| [47d041] | 2754 | ELOG(1, "We have not found any connected points to " << *Point << "."); | 
|---|
| [16d866] | 2755 | return NULL; | 
|---|
|  | 2756 | } | 
|---|
| [065e82] | 2757 |  | 
|---|
| [16d866] | 2758 | return connectedPoints; | 
|---|
| [6613ec] | 2759 | } | 
|---|
|  | 2760 | ; | 
|---|
| [065e82] | 2761 |  | 
|---|
|  | 2762 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point. | 
|---|
| [16d866] | 2763 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points | 
|---|
|  | 2764 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given | 
|---|
|  | 2765 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the | 
|---|
|  | 2766 | * triangle we are looking for. | 
|---|
|  | 2767 | * | 
|---|
|  | 2768 | * @param *out output stream for debugging | 
|---|
| [27bd2f] | 2769 | * @param *SetOfNeighbours all points for which the angle should be calculated | 
|---|
| [16d866] | 2770 | * @param *Point of which get all connected points | 
|---|
| [065e82] | 2771 | * @param *Reference Reference vector for zero angle or NULL for no preference | 
|---|
|  | 2772 | * @return list of the all points linked to the provided one | 
|---|
| [16d866] | 2773 | */ | 
|---|
| [d74077] | 2774 | TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const | 
|---|
| [16d866] | 2775 | { | 
|---|
| [ce7bfd] | 2776 | //Info FunctionInfo(__func__); | 
|---|
| [16d866] | 2777 | map<double, TesselPoint*> anglesOfPoints; | 
|---|
| [c15ca2] | 2778 | TesselPointList *connectedCircle = new TesselPointList; | 
|---|
| [71b20e] | 2779 | Vector PlaneNormal; | 
|---|
|  | 2780 | Vector AngleZero; | 
|---|
|  | 2781 | Vector OrthogonalVector; | 
|---|
|  | 2782 | Vector helper; | 
|---|
| [6613ec] | 2783 | const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL }; | 
|---|
| [c15ca2] | 2784 | TriangleList *triangles = NULL; | 
|---|
| [71b20e] | 2785 |  | 
|---|
|  | 2786 | if (SetOfNeighbours == NULL) { | 
|---|
| [47d041] | 2787 | ELOG(2, "Could not find any connected points!"); | 
|---|
| [6613ec] | 2788 | delete (connectedCircle); | 
|---|
| [71b20e] | 2789 | return NULL; | 
|---|
|  | 2790 | } | 
|---|
|  | 2791 |  | 
|---|
|  | 2792 | // calculate central point | 
|---|
|  | 2793 | triangles = FindTriangles(TrianglePoints); | 
|---|
|  | 2794 | if ((triangles != NULL) && (!triangles->empty())) { | 
|---|
| [c15ca2] | 2795 | for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) | 
|---|
| [273382] | 2796 | PlaneNormal += (*Runner)->NormalVector; | 
|---|
| [71b20e] | 2797 | } else { | 
|---|
| [47d041] | 2798 | ELOG(0, "Could not find any triangles for point " << *Point << "."); | 
|---|
| [71b20e] | 2799 | performCriticalExit(); | 
|---|
|  | 2800 | } | 
|---|
| [6613ec] | 2801 | PlaneNormal.Scale(1.0 / triangles->size()); | 
|---|
| [ce7bfd] | 2802 | LOG(4, "DEBUG: Calculated PlaneNormal of all circle points is " << PlaneNormal << "."); | 
|---|
| [71b20e] | 2803 | PlaneNormal.Normalize(); | 
|---|
|  | 2804 |  | 
|---|
|  | 2805 | // construct one orthogonal vector | 
|---|
| [d74077] | 2806 | AngleZero = (Reference) - (Point->getPosition()); | 
|---|
|  | 2807 | AngleZero.ProjectOntoPlane(PlaneNormal); | 
|---|
|  | 2808 | if ((AngleZero.NormSquared() < MYEPSILON)) { | 
|---|
| [ce7bfd] | 2809 | LOG(4, "DEBUG: Using alternatively " << (*SetOfNeighbours->begin())->getPosition() << " as angle 0 referencer."); | 
|---|
| [d74077] | 2810 | AngleZero = ((*SetOfNeighbours->begin())->getPosition()) - (Point->getPosition()); | 
|---|
| [273382] | 2811 | AngleZero.ProjectOntoPlane(PlaneNormal); | 
|---|
| [71b20e] | 2812 | if (AngleZero.NormSquared() < MYEPSILON) { | 
|---|
| [47d041] | 2813 | ELOG(0, "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!"); | 
|---|
| [71b20e] | 2814 | performCriticalExit(); | 
|---|
|  | 2815 | } | 
|---|
|  | 2816 | } | 
|---|
| [ce7bfd] | 2817 | LOG(4, "DEBUG: Reference vector on this plane representing angle 0 is " << AngleZero << "."); | 
|---|
| [71b20e] | 2818 | if (AngleZero.NormSquared() > MYEPSILON) | 
|---|
| [0a4f7f] | 2819 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); | 
|---|
| [71b20e] | 2820 | else | 
|---|
| [0a4f7f] | 2821 | OrthogonalVector.MakeNormalTo(PlaneNormal); | 
|---|
| [ce7bfd] | 2822 | LOG(4, "DEBUG: OrthogonalVector on plane is " << OrthogonalVector << "."); | 
|---|
| [71b20e] | 2823 |  | 
|---|
|  | 2824 | // go through all connected points and calculate angle | 
|---|
| [c15ca2] | 2825 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { | 
|---|
| [d74077] | 2826 | helper = ((*listRunner)->getPosition()) - (Point->getPosition()); | 
|---|
| [273382] | 2827 | helper.ProjectOntoPlane(PlaneNormal); | 
|---|
| [71b20e] | 2828 | double angle = GetAngle(helper, AngleZero, OrthogonalVector); | 
|---|
| [ce7bfd] | 2829 | LOG(4, "DEBUG" << angle << " for point " << **listRunner << "."); | 
|---|
| [6613ec] | 2830 | anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner))); | 
|---|
| [71b20e] | 2831 | } | 
|---|
|  | 2832 |  | 
|---|
| [6613ec] | 2833 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) { | 
|---|
| [71b20e] | 2834 | connectedCircle->push_back(AngleRunner->second); | 
|---|
|  | 2835 | } | 
|---|
|  | 2836 |  | 
|---|
|  | 2837 | return connectedCircle; | 
|---|
|  | 2838 | } | 
|---|
|  | 2839 |  | 
|---|
|  | 2840 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point. | 
|---|
|  | 2841 | * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points | 
|---|
|  | 2842 | * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given | 
|---|
|  | 2843 | * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the | 
|---|
|  | 2844 | * triangle we are looking for. | 
|---|
|  | 2845 | * | 
|---|
|  | 2846 | * @param *SetOfNeighbours all points for which the angle should be calculated | 
|---|
|  | 2847 | * @param *Point of which get all connected points | 
|---|
| [d74077] | 2848 | * @param *Reference Reference vector for zero angle or (0,0,0) for no preference | 
|---|
| [71b20e] | 2849 | * @return list of the all points linked to the provided one | 
|---|
|  | 2850 | */ | 
|---|
| [d74077] | 2851 | TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector &Reference) const | 
|---|
| [71b20e] | 2852 | { | 
|---|
| [ce7bfd] | 2853 | //Info FunctionInfo(__func__); | 
|---|
| [71b20e] | 2854 | map<double, TesselPoint*> anglesOfPoints; | 
|---|
| [c15ca2] | 2855 | TesselPointList *connectedCircle = new TesselPointList; | 
|---|
| [065e82] | 2856 | Vector center; | 
|---|
|  | 2857 | Vector PlaneNormal; | 
|---|
|  | 2858 | Vector AngleZero; | 
|---|
|  | 2859 | Vector OrthogonalVector; | 
|---|
|  | 2860 | Vector helper; | 
|---|
| [62bb91] | 2861 |  | 
|---|
| [27bd2f] | 2862 | if (SetOfNeighbours == NULL) { | 
|---|
| [47d041] | 2863 | ELOG(2, "Could not find any connected points!"); | 
|---|
| [6613ec] | 2864 | delete (connectedCircle); | 
|---|
| [99593f] | 2865 | return NULL; | 
|---|
|  | 2866 | } | 
|---|
| [a2028e] | 2867 |  | 
|---|
| [97498a] | 2868 | // check whether there's something to do | 
|---|
|  | 2869 | if (SetOfNeighbours->size() < 3) { | 
|---|
|  | 2870 | for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++) | 
|---|
|  | 2871 | connectedCircle->push_back(*TesselRunner); | 
|---|
|  | 2872 | return connectedCircle; | 
|---|
|  | 2873 | } | 
|---|
|  | 2874 |  | 
|---|
| [47d041] | 2875 | LOG(1, "INFO: Point is " << *Point << " and Reference is " << Reference << "."); | 
|---|
| [16d866] | 2876 | // calculate central point | 
|---|
| [97498a] | 2877 | TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin(); | 
|---|
|  | 2878 | TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin(); | 
|---|
|  | 2879 | TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin(); | 
|---|
|  | 2880 | TesselB++; | 
|---|
|  | 2881 | TesselC++; | 
|---|
|  | 2882 | TesselC++; | 
|---|
|  | 2883 | int counter = 0; | 
|---|
|  | 2884 | while (TesselC != SetOfNeighbours->end()) { | 
|---|
| [d74077] | 2885 | helper = Plane(((*TesselA)->getPosition()), | 
|---|
|  | 2886 | ((*TesselB)->getPosition()), | 
|---|
|  | 2887 | ((*TesselC)->getPosition())).getNormal(); | 
|---|
| [ce7bfd] | 2888 | LOG(5, "DEBUG: Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper); | 
|---|
| [97498a] | 2889 | counter++; | 
|---|
|  | 2890 | TesselA++; | 
|---|
|  | 2891 | TesselB++; | 
|---|
|  | 2892 | TesselC++; | 
|---|
| [273382] | 2893 | PlaneNormal += helper; | 
|---|
| [97498a] | 2894 | } | 
|---|
| [47d041] | 2895 | //LOG(0, "Summed vectors " << center << "; number of points " << connectedPoints.size() << "; scale factor " << counter); | 
|---|
| [6613ec] | 2896 | PlaneNormal.Scale(1.0 / (double) counter); | 
|---|
| [47d041] | 2897 | //  LOG(1, "INFO: Calculated center of all circle points is " << center << "."); | 
|---|
| [6613ec] | 2898 | // | 
|---|
|  | 2899 | //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points | 
|---|
|  | 2900 | //  PlaneNormal.CopyVector(Point->node); | 
|---|
|  | 2901 | //  PlaneNormal.SubtractVector(¢er); | 
|---|
|  | 2902 | //  PlaneNormal.Normalize(); | 
|---|
| [ce7bfd] | 2903 | LOG(4, "DEBUG: Calculated plane normal of circle is " << PlaneNormal << "."); | 
|---|
| [62bb91] | 2904 |  | 
|---|
|  | 2905 | // construct one orthogonal vector | 
|---|
| [d74077] | 2906 | if (!Reference.IsZero()) { | 
|---|
|  | 2907 | AngleZero = (Reference) - (Point->getPosition()); | 
|---|
| [273382] | 2908 | AngleZero.ProjectOntoPlane(PlaneNormal); | 
|---|
| [a2028e] | 2909 | } | 
|---|
| [d74077] | 2910 | if ((Reference.IsZero()) || (AngleZero.NormSquared() < MYEPSILON )) { | 
|---|
| [ce7bfd] | 2911 | LOG(4, "DEBUG: Using alternatively " << (*SetOfNeighbours->begin())->getPosition() << " as angle 0 referencer."); | 
|---|
| [d74077] | 2912 | AngleZero = ((*SetOfNeighbours->begin())->getPosition()) - (Point->getPosition()); | 
|---|
| [273382] | 2913 | AngleZero.ProjectOntoPlane(PlaneNormal); | 
|---|
| [a2028e] | 2914 | if (AngleZero.NormSquared() < MYEPSILON) { | 
|---|
| [47d041] | 2915 | ELOG(0, "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!"); | 
|---|
| [a2028e] | 2916 | performCriticalExit(); | 
|---|
|  | 2917 | } | 
|---|
|  | 2918 | } | 
|---|
| [ce7bfd] | 2919 | LOG(4, "DEBUG: Reference vector on this plane representing angle 0 is " << AngleZero << "."); | 
|---|
| [a2028e] | 2920 | if (AngleZero.NormSquared() > MYEPSILON) | 
|---|
| [0a4f7f] | 2921 | OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); | 
|---|
| [a2028e] | 2922 | else | 
|---|
| [0a4f7f] | 2923 | OrthogonalVector.MakeNormalTo(PlaneNormal); | 
|---|
| [ce7bfd] | 2924 | LOG(4, "DEBUG: OrthogonalVector on plane is " << OrthogonalVector << "."); | 
|---|
| [16d866] | 2925 |  | 
|---|
| [5c7bf8] | 2926 | // go through all connected points and calculate angle | 
|---|
| [6613ec] | 2927 | pair<map<double, TesselPoint*>::iterator, bool> InserterTest; | 
|---|
| [c15ca2] | 2928 | for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { | 
|---|
| [d74077] | 2929 | helper = ((*listRunner)->getPosition()) - (Point->getPosition()); | 
|---|
| [273382] | 2930 | helper.ProjectOntoPlane(PlaneNormal); | 
|---|
| [f1cccd] | 2931 | double angle = GetAngle(helper, AngleZero, OrthogonalVector); | 
|---|
| [97498a] | 2932 | if (angle > M_PI) // the correction is of no use here (and not desired) | 
|---|
| [6613ec] | 2933 | angle = 2. * M_PI - angle; | 
|---|
| [ce7bfd] | 2934 | LOG(4, "DEBUG: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "."); | 
|---|
| [6613ec] | 2935 | InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner))); | 
|---|
| [c15ca2] | 2936 | if (!InserterTest.second) { | 
|---|
| [47d041] | 2937 | ELOG(0, "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner)); | 
|---|
| [c15ca2] | 2938 | performCriticalExit(); | 
|---|
|  | 2939 | } | 
|---|
| [62bb91] | 2940 | } | 
|---|
|  | 2941 |  | 
|---|
| [6613ec] | 2942 | for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) { | 
|---|
| [065e82] | 2943 | connectedCircle->push_back(AngleRunner->second); | 
|---|
|  | 2944 | } | 
|---|
| [62bb91] | 2945 |  | 
|---|
| [065e82] | 2946 | return connectedCircle; | 
|---|
|  | 2947 | } | 
|---|
| [62bb91] | 2948 |  | 
|---|
| [065e82] | 2949 | /** Gets all points connected to the provided point by triangulation lines, ordered such that we walk along a closed path. | 
|---|
|  | 2950 | * | 
|---|
|  | 2951 | * @param *out output stream for debugging | 
|---|
|  | 2952 | * @param *Point of which get all connected points | 
|---|
|  | 2953 | * @return list of the all points linked to the provided one | 
|---|
|  | 2954 | */ | 
|---|
| [244a84] | 2955 | ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const | 
|---|
| [065e82] | 2956 | { | 
|---|
| [ce7bfd] | 2957 | //Info FunctionInfo(__func__); | 
|---|
| [065e82] | 2958 | map<double, TesselPoint*> anglesOfPoints; | 
|---|
| [6613ec] | 2959 | list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ; | 
|---|
| [c15ca2] | 2960 | TesselPointList *connectedPath = NULL; | 
|---|
| [065e82] | 2961 | Vector center; | 
|---|
|  | 2962 | Vector PlaneNormal; | 
|---|
|  | 2963 | Vector AngleZero; | 
|---|
|  | 2964 | Vector OrthogonalVector; | 
|---|
|  | 2965 | Vector helper; | 
|---|
|  | 2966 | class BoundaryPointSet *ReferencePoint = NULL; | 
|---|
|  | 2967 | class BoundaryPointSet *CurrentPoint = NULL; | 
|---|
|  | 2968 | class BoundaryTriangleSet *triangle = NULL; | 
|---|
|  | 2969 | class BoundaryLineSet *CurrentLine = NULL; | 
|---|
|  | 2970 | class BoundaryLineSet *StartLine = NULL; | 
|---|
|  | 2971 | // find the respective boundary point | 
|---|
| [735b1c] | 2972 | PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->getNr()); | 
|---|
| [065e82] | 2973 | if (PointRunner != PointsOnBoundary.end()) { | 
|---|
|  | 2974 | ReferencePoint = PointRunner->second; | 
|---|
|  | 2975 | } else { | 
|---|
| [47d041] | 2976 | ELOG(1, "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "."); | 
|---|
| [065e82] | 2977 | return NULL; | 
|---|
|  | 2978 | } | 
|---|
|  | 2979 |  | 
|---|
| [6613ec] | 2980 | map<class BoundaryLineSet *, bool> TouchedLine; | 
|---|
|  | 2981 | map<class BoundaryTriangleSet *, bool> TouchedTriangle; | 
|---|
|  | 2982 | map<class BoundaryLineSet *, bool>::iterator LineRunner; | 
|---|
|  | 2983 | map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner; | 
|---|
| [57066a] | 2984 | for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) { | 
|---|
| [6613ec] | 2985 | TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false)); | 
|---|
| [57066a] | 2986 | for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++) | 
|---|
| [6613ec] | 2987 | TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false)); | 
|---|
| [57066a] | 2988 | } | 
|---|
| [065e82] | 2989 | if (!ReferencePoint->lines.empty()) { | 
|---|
|  | 2990 | for (LineMap::iterator runner = ReferencePoint->lines.begin(); runner != ReferencePoint->lines.end(); runner++) { | 
|---|
| [57066a] | 2991 | LineRunner = TouchedLine.find(runner->second); | 
|---|
|  | 2992 | if (LineRunner == TouchedLine.end()) { | 
|---|
| [47d041] | 2993 | ELOG(1, "I could not find " << *runner->second << " in the touched list."); | 
|---|
| [57066a] | 2994 | } else if (!LineRunner->second) { | 
|---|
|  | 2995 | LineRunner->second = true; | 
|---|
| [c15ca2] | 2996 | connectedPath = new TesselPointList; | 
|---|
| [065e82] | 2997 | triangle = NULL; | 
|---|
|  | 2998 | CurrentLine = runner->second; | 
|---|
|  | 2999 | StartLine = CurrentLine; | 
|---|
|  | 3000 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint); | 
|---|
| [47d041] | 3001 | LOG(1, "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "."); | 
|---|
| [065e82] | 3002 | do { | 
|---|
|  | 3003 | // push current one | 
|---|
| [47d041] | 3004 | LOG(1, "INFO: Putting " << *CurrentPoint << " at end of path."); | 
|---|
| [065e82] | 3005 | connectedPath->push_back(CurrentPoint->node); | 
|---|
|  | 3006 |  | 
|---|
|  | 3007 | // find next triangle | 
|---|
| [57066a] | 3008 | for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) { | 
|---|
| [47d041] | 3009 | LOG(1, "INFO: Inspecting triangle " << *Runner->second << "."); | 
|---|
| [57066a] | 3010 | if ((Runner->second != triangle)) { // look for first triangle not equal to old one | 
|---|
|  | 3011 | triangle = Runner->second; | 
|---|
|  | 3012 | TriangleRunner = TouchedTriangle.find(triangle); | 
|---|
|  | 3013 | if (TriangleRunner != TouchedTriangle.end()) { | 
|---|
|  | 3014 | if (!TriangleRunner->second) { | 
|---|
|  | 3015 | TriangleRunner->second = true; | 
|---|
| [47d041] | 3016 | LOG(1, "INFO: Connecting triangle is " << *triangle << "."); | 
|---|
| [57066a] | 3017 | break; | 
|---|
|  | 3018 | } else { | 
|---|
| [47d041] | 3019 | LOG(1, "INFO: Skipping " << *triangle << ", as we have already visited it."); | 
|---|
| [57066a] | 3020 | triangle = NULL; | 
|---|
|  | 3021 | } | 
|---|
|  | 3022 | } else { | 
|---|
| [47d041] | 3023 | ELOG(1, "I could not find " << *triangle << " in the touched list."); | 
|---|
| [57066a] | 3024 | triangle = NULL; | 
|---|
|  | 3025 | } | 
|---|
| [065e82] | 3026 | } | 
|---|
|  | 3027 | } | 
|---|
| [57066a] | 3028 | if (triangle == NULL) | 
|---|
|  | 3029 | break; | 
|---|
| [065e82] | 3030 | // find next line | 
|---|
| [6613ec] | 3031 | for (int i = 0; i < 3; i++) { | 
|---|
| [065e82] | 3032 | if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point | 
|---|
|  | 3033 | CurrentLine = triangle->lines[i]; | 
|---|
| [47d041] | 3034 | LOG(1, "INFO: Connecting line is " << *CurrentLine << "."); | 
|---|
| [065e82] | 3035 | break; | 
|---|
|  | 3036 | } | 
|---|
|  | 3037 | } | 
|---|
| [57066a] | 3038 | LineRunner = TouchedLine.find(CurrentLine); | 
|---|
|  | 3039 | if (LineRunner == TouchedLine.end()) | 
|---|
| [47d041] | 3040 | ELOG(1, "I could not find " << *CurrentLine << " in the touched list."); | 
|---|
| [065e82] | 3041 | else | 
|---|
| [57066a] | 3042 | LineRunner->second = true; | 
|---|
| [065e82] | 3043 | // find next point | 
|---|
|  | 3044 | CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint); | 
|---|
|  | 3045 |  | 
|---|
|  | 3046 | } while (CurrentLine != StartLine); | 
|---|
|  | 3047 | // last point is missing, as it's on start line | 
|---|
| [47d041] | 3048 | LOG(1, "INFO: Putting " << *CurrentPoint << " at end of path."); | 
|---|
| [57066a] | 3049 | if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back()) | 
|---|
|  | 3050 | connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node); | 
|---|
| [065e82] | 3051 |  | 
|---|
|  | 3052 | ListOfPaths->push_back(connectedPath); | 
|---|
|  | 3053 | } else { | 
|---|
| [47d041] | 3054 | LOG(1, "INFO: Skipping " << *runner->second << ", as we have already visited it."); | 
|---|
| [065e82] | 3055 | } | 
|---|
|  | 3056 | } | 
|---|
|  | 3057 | } else { | 
|---|
| [47d041] | 3058 | ELOG(1, "There are no lines attached to " << *ReferencePoint << "."); | 
|---|
| [065e82] | 3059 | } | 
|---|
|  | 3060 |  | 
|---|
|  | 3061 | return ListOfPaths; | 
|---|
| [62bb91] | 3062 | } | 
|---|
|  | 3063 |  | 
|---|
| [065e82] | 3064 | /** Gets all closed paths on the circle of points connected to the provided point by triangulation lines, if this very point is removed. | 
|---|
|  | 3065 | * From GetPathsOfConnectedPoints() extracts all single loops of intracrossing paths in the list of closed paths. | 
|---|
|  | 3066 | * @param *out output stream for debugging | 
|---|
|  | 3067 | * @param *Point of which get all connected points | 
|---|
|  | 3068 | * @return list of the closed paths | 
|---|
|  | 3069 | */ | 
|---|
| [244a84] | 3070 | ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const | 
|---|
| [065e82] | 3071 | { | 
|---|
| [ce7bfd] | 3072 | //Info FunctionInfo(__func__); | 
|---|
| [c15ca2] | 3073 | list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point); | 
|---|
| [6613ec] | 3074 | list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ; | 
|---|
| [c15ca2] | 3075 | TesselPointList *connectedPath = NULL; | 
|---|
|  | 3076 | TesselPointList *newPath = NULL; | 
|---|
| [065e82] | 3077 | int count = 0; | 
|---|
| [c15ca2] | 3078 | TesselPointList::iterator CircleRunner; | 
|---|
|  | 3079 | TesselPointList::iterator CircleStart; | 
|---|
| [065e82] | 3080 |  | 
|---|
| [6613ec] | 3081 | for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) { | 
|---|
| [065e82] | 3082 | connectedPath = *ListRunner; | 
|---|
|  | 3083 |  | 
|---|
| [47d041] | 3084 | LOG(1, "INFO: Current path is " << connectedPath << "."); | 
|---|
| [065e82] | 3085 |  | 
|---|
|  | 3086 | // go through list, look for reappearance of starting Point and count | 
|---|
|  | 3087 | CircleStart = connectedPath->begin(); | 
|---|
|  | 3088 | // go through list, look for reappearance of starting Point and create list | 
|---|
| [c15ca2] | 3089 | TesselPointList::iterator Marker = CircleStart; | 
|---|
| [065e82] | 3090 | for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) { | 
|---|
|  | 3091 | if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point | 
|---|
|  | 3092 | // we have a closed circle from Marker to new Marker | 
|---|
| [47d041] | 3093 | if (DoLog(1)) { | 
|---|
|  | 3094 | std::stringstream output; | 
|---|
|  | 3095 | output << count + 1 << ". closed path consists of: "; | 
|---|
|  | 3096 | for (TesselPointList::iterator CircleSprinter = Marker; | 
|---|
|  | 3097 | CircleSprinter != CircleRunner; | 
|---|
|  | 3098 | CircleSprinter++) | 
|---|
|  | 3099 | output << (**CircleSprinter) << " <-> "; | 
|---|
|  | 3100 | LOG(1, output.str()); | 
|---|
|  | 3101 | } | 
|---|
| [c15ca2] | 3102 | newPath = new TesselPointList; | 
|---|
|  | 3103 | TesselPointList::iterator CircleSprinter = Marker; | 
|---|
| [47d041] | 3104 | for (; CircleSprinter != CircleRunner; CircleSprinter++) | 
|---|
| [065e82] | 3105 | newPath->push_back(*CircleSprinter); | 
|---|
|  | 3106 | count++; | 
|---|
|  | 3107 | Marker = CircleRunner; | 
|---|
|  | 3108 |  | 
|---|
|  | 3109 | // add to list | 
|---|
|  | 3110 | ListofClosedPaths->push_back(newPath); | 
|---|
|  | 3111 | } | 
|---|
|  | 3112 | } | 
|---|
|  | 3113 | } | 
|---|
| [47d041] | 3114 | LOG(1, "INFO: " << count << " closed additional path(s) have been created."); | 
|---|
| [065e82] | 3115 |  | 
|---|
|  | 3116 | // delete list of paths | 
|---|
|  | 3117 | while (!ListofPaths->empty()) { | 
|---|
|  | 3118 | connectedPath = *(ListofPaths->begin()); | 
|---|
|  | 3119 | ListofPaths->remove(connectedPath); | 
|---|
| [6613ec] | 3120 | delete (connectedPath); | 
|---|
| [065e82] | 3121 | } | 
|---|
| [6613ec] | 3122 | delete (ListofPaths); | 
|---|
| [065e82] | 3123 |  | 
|---|
|  | 3124 | // exit | 
|---|
|  | 3125 | return ListofClosedPaths; | 
|---|
| [6613ec] | 3126 | } | 
|---|
|  | 3127 | ; | 
|---|
| [065e82] | 3128 |  | 
|---|
|  | 3129 | /** Gets all belonging triangles for a given BoundaryPointSet. | 
|---|
|  | 3130 | * \param *out output stream for debugging | 
|---|
|  | 3131 | * \param *Point BoundaryPoint | 
|---|
|  | 3132 | * \return pointer to allocated list of triangles | 
|---|
|  | 3133 | */ | 
|---|
| [c15ca2] | 3134 | TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const | 
|---|
| [065e82] | 3135 | { | 
|---|
| [ce7bfd] | 3136 | //Info FunctionInfo(__func__); | 
|---|
| [6613ec] | 3137 | TriangleSet *connectedTriangles = new TriangleSet; | 
|---|
| [065e82] | 3138 |  | 
|---|
|  | 3139 | if (Point == NULL) { | 
|---|
| [47d041] | 3140 | ELOG(1, "Point given is NULL."); | 
|---|
| [065e82] | 3141 | } else { | 
|---|
|  | 3142 | // go through its lines and insert all triangles | 
|---|
| [776b64] | 3143 | for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++) | 
|---|
| [065e82] | 3144 | for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { | 
|---|
| [6613ec] | 3145 | connectedTriangles->insert(TriangleRunner->second); | 
|---|
|  | 3146 | } | 
|---|
| [065e82] | 3147 | } | 
|---|
|  | 3148 |  | 
|---|
|  | 3149 | return connectedTriangles; | 
|---|
| [6613ec] | 3150 | } | 
|---|
|  | 3151 | ; | 
|---|
| [065e82] | 3152 |  | 
|---|
| [16d866] | 3153 | /** Removes a boundary point from the envelope while keeping it closed. | 
|---|
| [57066a] | 3154 | * We remove the old triangles connected to the point and re-create new triangles to close the surface following this ansatz: | 
|---|
|  | 3155 | *  -# a closed path(s) of boundary points surrounding the point to be removed is constructed | 
|---|
|  | 3156 | *  -# on each closed path, we pick three adjacent points, create a triangle with them and subtract the middle point from the path | 
|---|
|  | 3157 | *  -# we advance two points (i.e. the next triangle will start at the ending point of the last triangle) and continue as before | 
|---|
|  | 3158 | *  -# the surface is closed, when the path is empty | 
|---|
|  | 3159 | * Thereby, we (hopefully) make sure that the removed points remains beneath the surface (this is checked via IsInnerPoint eventually). | 
|---|
| [16d866] | 3160 | * \param *out output stream for debugging | 
|---|
|  | 3161 | * \param *point point to be removed | 
|---|
|  | 3162 | * \return volume added to the volume inside the tesselated surface by the removal | 
|---|
|  | 3163 | */ | 
|---|
| [6613ec] | 3164 | double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) | 
|---|
|  | 3165 | { | 
|---|
| [16d866] | 3166 | class BoundaryLineSet *line = NULL; | 
|---|
|  | 3167 | class BoundaryTriangleSet *triangle = NULL; | 
|---|
| [57066a] | 3168 | Vector OldPoint, NormalVector; | 
|---|
| [16d866] | 3169 | double volume = 0; | 
|---|
|  | 3170 | int count = 0; | 
|---|
|  | 3171 |  | 
|---|
| [1d9b7aa] | 3172 | if (point == NULL) { | 
|---|
| [47d041] | 3173 | ELOG(1, "Cannot remove the point " << point << ", it's NULL!"); | 
|---|
| [1d9b7aa] | 3174 | return 0.; | 
|---|
|  | 3175 | } else | 
|---|
| [ce7bfd] | 3176 | LOG(4, "DEBUG: Removing point " << *point << " from tesselated boundary ..."); | 
|---|
| [1d9b7aa] | 3177 |  | 
|---|
| [16d866] | 3178 | // copy old location for the volume | 
|---|
| [d74077] | 3179 | OldPoint = (point->node->getPosition()); | 
|---|
| [16d866] | 3180 |  | 
|---|
|  | 3181 | // get list of connected points | 
|---|
|  | 3182 | if (point->lines.empty()) { | 
|---|
| [47d041] | 3183 | ELOG(1, "Cannot remove the point " << *point << ", it's connected to no lines!"); | 
|---|
| [16d866] | 3184 | return 0.; | 
|---|
|  | 3185 | } | 
|---|
|  | 3186 |  | 
|---|
| [c15ca2] | 3187 | list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node); | 
|---|
|  | 3188 | TesselPointList *connectedPath = NULL; | 
|---|
| [065e82] | 3189 |  | 
|---|
|  | 3190 | // gather all triangles | 
|---|
| [16d866] | 3191 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) | 
|---|
| [6613ec] | 3192 | count += LineRunner->second->triangles.size(); | 
|---|
| [c15ca2] | 3193 | TriangleMap Candidates; | 
|---|
| [57066a] | 3194 | for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { | 
|---|
| [16d866] | 3195 | line = LineRunner->second; | 
|---|
|  | 3196 | for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) { | 
|---|
|  | 3197 | triangle = TriangleRunner->second; | 
|---|
| [6613ec] | 3198 | Candidates.insert(TrianglePair(triangle->Nr, triangle)); | 
|---|
| [16d866] | 3199 | } | 
|---|
|  | 3200 | } | 
|---|
|  | 3201 |  | 
|---|
| [065e82] | 3202 | // remove all triangles | 
|---|
| [6613ec] | 3203 | count = 0; | 
|---|
| [57066a] | 3204 | NormalVector.Zero(); | 
|---|
| [c15ca2] | 3205 | for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { | 
|---|
| [47d041] | 3206 | LOG(1, "INFO: Removing triangle " << *(Runner->second) << "."); | 
|---|
| [273382] | 3207 | NormalVector -= Runner->second->NormalVector; // has to point inward | 
|---|
| [c15ca2] | 3208 | RemoveTesselationTriangle(Runner->second); | 
|---|
| [065e82] | 3209 | count++; | 
|---|
|  | 3210 | } | 
|---|
| [47d041] | 3211 | LOG(1, count << " triangles were removed."); | 
|---|
| [065e82] | 3212 |  | 
|---|
| [c15ca2] | 3213 | list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin(); | 
|---|
|  | 3214 | list<TesselPointList *>::iterator ListRunner = ListAdvance; | 
|---|
|  | 3215 | TriangleMap::iterator NumberRunner = Candidates.begin(); | 
|---|
|  | 3216 | TesselPointList::iterator StartNode, MiddleNode, EndNode; | 
|---|
| [57066a] | 3217 | double angle; | 
|---|
|  | 3218 | double smallestangle; | 
|---|
|  | 3219 | Vector Point, Reference, OrthogonalVector; | 
|---|
| [6613ec] | 3220 | if (count > 2) { // less than three triangles, then nothing will be created | 
|---|
| [065e82] | 3221 | class TesselPoint *TriangleCandidates[3]; | 
|---|
|  | 3222 | count = 0; | 
|---|
| [6613ec] | 3223 | for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths | 
|---|
| [065e82] | 3224 | if (ListAdvance != ListOfClosedPaths->end()) | 
|---|
|  | 3225 | ListAdvance++; | 
|---|
|  | 3226 |  | 
|---|
|  | 3227 | connectedPath = *ListRunner; | 
|---|
|  | 3228 | // re-create all triangles by going through connected points list | 
|---|
| [c15ca2] | 3229 | LineList NewLines; | 
|---|
| [6613ec] | 3230 | for (; !connectedPath->empty();) { | 
|---|
| [57066a] | 3231 | // search middle node with widest angle to next neighbours | 
|---|
|  | 3232 | EndNode = connectedPath->end(); | 
|---|
|  | 3233 | smallestangle = 0.; | 
|---|
|  | 3234 | for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) { | 
|---|
| [47d041] | 3235 | LOG(1, "INFO: MiddleNode is " << **MiddleNode << "."); | 
|---|
| [57066a] | 3236 | // construct vectors to next and previous neighbour | 
|---|
|  | 3237 | StartNode = MiddleNode; | 
|---|
|  | 3238 | if (StartNode == connectedPath->begin()) | 
|---|
|  | 3239 | StartNode = connectedPath->end(); | 
|---|
|  | 3240 | StartNode--; | 
|---|
| [47d041] | 3241 | //LOG(3, "INFO: StartNode is " << **StartNode << "."); | 
|---|
| [d74077] | 3242 | Point = ((*StartNode)->getPosition()) - ((*MiddleNode)->getPosition()); | 
|---|
| [57066a] | 3243 | StartNode = MiddleNode; | 
|---|
|  | 3244 | StartNode++; | 
|---|
|  | 3245 | if (StartNode == connectedPath->end()) | 
|---|
|  | 3246 | StartNode = connectedPath->begin(); | 
|---|
| [47d041] | 3247 | //LOG(3, "INFO: EndNode is " << **StartNode << "."); | 
|---|
| [d74077] | 3248 | Reference = ((*StartNode)->getPosition()) - ((*MiddleNode)->getPosition()); | 
|---|
|  | 3249 | OrthogonalVector = ((*MiddleNode)->getPosition()) - OldPoint; | 
|---|
| [0a4f7f] | 3250 | OrthogonalVector.MakeNormalTo(Reference); | 
|---|
| [57066a] | 3251 | angle = GetAngle(Point, Reference, OrthogonalVector); | 
|---|
|  | 3252 | //if (angle < M_PI)  // no wrong-sided triangles, please? | 
|---|
| [6613ec] | 3253 | if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first) | 
|---|
|  | 3254 | smallestangle = angle; | 
|---|
|  | 3255 | EndNode = MiddleNode; | 
|---|
|  | 3256 | } | 
|---|
| [57066a] | 3257 | } | 
|---|
|  | 3258 | MiddleNode = EndNode; | 
|---|
|  | 3259 | if (MiddleNode == connectedPath->end()) { | 
|---|
| [47d041] | 3260 | ELOG(0, "CRITICAL: Could not find a smallest angle!"); | 
|---|
| [f67b6e] | 3261 | performCriticalExit(); | 
|---|
| [57066a] | 3262 | } | 
|---|
|  | 3263 | StartNode = MiddleNode; | 
|---|
|  | 3264 | if (StartNode == connectedPath->begin()) | 
|---|
|  | 3265 | StartNode = connectedPath->end(); | 
|---|
|  | 3266 | StartNode--; | 
|---|
|  | 3267 | EndNode++; | 
|---|
|  | 3268 | if (EndNode == connectedPath->end()) | 
|---|
|  | 3269 | EndNode = connectedPath->begin(); | 
|---|
| [47d041] | 3270 | LOG(2, "INFO: StartNode is " << **StartNode << "."); | 
|---|
|  | 3271 | LOG(2, "INFO: MiddleNode is " << **MiddleNode << "."); | 
|---|
|  | 3272 | LOG(2, "INFO: EndNode is " << **EndNode << "."); | 
|---|
|  | 3273 | LOG(1, "INFO: Attempting to create triangle " << (*StartNode)->getName() << ", " << (*MiddleNode)->getName() << " and " << (*EndNode)->getName() << "."); | 
|---|
| [57066a] | 3274 | TriangleCandidates[0] = *StartNode; | 
|---|
|  | 3275 | TriangleCandidates[1] = *MiddleNode; | 
|---|
|  | 3276 | TriangleCandidates[2] = *EndNode; | 
|---|
| [e138de] | 3277 | triangle = GetPresentTriangle(TriangleCandidates); | 
|---|
| [57066a] | 3278 | if (triangle != NULL) { | 
|---|
| [47d041] | 3279 | ELOG(0, "New triangle already present, skipping!"); | 
|---|
| [57066a] | 3280 | StartNode++; | 
|---|
|  | 3281 | MiddleNode++; | 
|---|
|  | 3282 | EndNode++; | 
|---|
|  | 3283 | if (StartNode == connectedPath->end()) | 
|---|
|  | 3284 | StartNode = connectedPath->begin(); | 
|---|
|  | 3285 | if (MiddleNode == connectedPath->end()) | 
|---|
|  | 3286 | MiddleNode = connectedPath->begin(); | 
|---|
|  | 3287 | if (EndNode == connectedPath->end()) | 
|---|
|  | 3288 | EndNode = connectedPath->begin(); | 
|---|
|  | 3289 | continue; | 
|---|
|  | 3290 | } | 
|---|
| [47d041] | 3291 | LOG(3, "Adding new triangle points."); | 
|---|
| [57066a] | 3292 | AddTesselationPoint(*StartNode, 0); | 
|---|
|  | 3293 | AddTesselationPoint(*MiddleNode, 1); | 
|---|
|  | 3294 | AddTesselationPoint(*EndNode, 2); | 
|---|
| [47d041] | 3295 | LOG(3, "Adding new triangle lines."); | 
|---|
| [f07f86d] | 3296 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); | 
|---|
|  | 3297 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); | 
|---|
| [57066a] | 3298 | NewLines.push_back(BLS[1]); | 
|---|
| [f07f86d] | 3299 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); | 
|---|
| [065e82] | 3300 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); | 
|---|
| [57066a] | 3301 | BTS->GetNormalVector(NormalVector); | 
|---|
| [065e82] | 3302 | AddTesselationTriangle(); | 
|---|
|  | 3303 | // calculate volume summand as a general tetraeder | 
|---|
| [d74077] | 3304 | volume += CalculateVolumeofGeneralTetraeder(TPS[0]->node->getPosition(), TPS[1]->node->getPosition(), TPS[2]->node->getPosition(), OldPoint); | 
|---|
| [065e82] | 3305 | // advance number | 
|---|
|  | 3306 | count++; | 
|---|
| [57066a] | 3307 |  | 
|---|
|  | 3308 | // prepare nodes for next triangle | 
|---|
|  | 3309 | StartNode = EndNode; | 
|---|
| [47d041] | 3310 | LOG(2, "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "."); | 
|---|
| [57066a] | 3311 | connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles) | 
|---|
|  | 3312 | if (connectedPath->size() == 2) { // we are done | 
|---|
|  | 3313 | connectedPath->remove(*StartNode); // remove the start node | 
|---|
|  | 3314 | connectedPath->remove(*EndNode); // remove the end node | 
|---|
|  | 3315 | break; | 
|---|
|  | 3316 | } else if (connectedPath->size() < 2) { // something's gone wrong! | 
|---|
| [47d041] | 3317 | ELOG(0, "CRITICAL: There are only two endpoints left!"); | 
|---|
| [f67b6e] | 3318 | performCriticalExit(); | 
|---|
| [57066a] | 3319 | } else { | 
|---|
|  | 3320 | MiddleNode = StartNode; | 
|---|
|  | 3321 | MiddleNode++; | 
|---|
|  | 3322 | if (MiddleNode == connectedPath->end()) | 
|---|
|  | 3323 | MiddleNode = connectedPath->begin(); | 
|---|
|  | 3324 | EndNode = MiddleNode; | 
|---|
|  | 3325 | EndNode++; | 
|---|
|  | 3326 | if (EndNode == connectedPath->end()) | 
|---|
|  | 3327 | EndNode = connectedPath->begin(); | 
|---|
|  | 3328 | } | 
|---|
| [065e82] | 3329 | } | 
|---|
| [57066a] | 3330 | // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing) | 
|---|
|  | 3331 | if (NewLines.size() > 1) { | 
|---|
| [c15ca2] | 3332 | LineList::iterator Candidate; | 
|---|
| [57066a] | 3333 | class BoundaryLineSet *OtherBase = NULL; | 
|---|
|  | 3334 | double tmp, maxgain; | 
|---|
|  | 3335 | do { | 
|---|
|  | 3336 | maxgain = 0; | 
|---|
| [6613ec] | 3337 | for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) { | 
|---|
| [e138de] | 3338 | tmp = PickFarthestofTwoBaselines(*Runner); | 
|---|
| [57066a] | 3339 | if (maxgain < tmp) { | 
|---|
|  | 3340 | maxgain = tmp; | 
|---|
|  | 3341 | Candidate = Runner; | 
|---|
|  | 3342 | } | 
|---|
|  | 3343 | } | 
|---|
|  | 3344 | if (maxgain != 0) { | 
|---|
|  | 3345 | volume += maxgain; | 
|---|
| [47d041] | 3346 | LOG(1, "Flipping baseline with highest volume" << **Candidate << "."); | 
|---|
| [e138de] | 3347 | OtherBase = FlipBaseline(*Candidate); | 
|---|
| [57066a] | 3348 | NewLines.erase(Candidate); | 
|---|
|  | 3349 | NewLines.push_back(OtherBase); | 
|---|
|  | 3350 | } | 
|---|
|  | 3351 | } while (maxgain != 0.); | 
|---|
|  | 3352 | } | 
|---|
|  | 3353 |  | 
|---|
| [065e82] | 3354 | ListOfClosedPaths->remove(connectedPath); | 
|---|
| [6613ec] | 3355 | delete (connectedPath); | 
|---|
| [16d866] | 3356 | } | 
|---|
| [ce7bfd] | 3357 | LOG(1, "INFO: " << count << " triangles were created."); | 
|---|
| [065e82] | 3358 | } else { | 
|---|
|  | 3359 | while (!ListOfClosedPaths->empty()) { | 
|---|
|  | 3360 | ListRunner = ListOfClosedPaths->begin(); | 
|---|
|  | 3361 | connectedPath = *ListRunner; | 
|---|
|  | 3362 | ListOfClosedPaths->remove(connectedPath); | 
|---|
| [6613ec] | 3363 | delete (connectedPath); | 
|---|
| [065e82] | 3364 | } | 
|---|
| [ce7bfd] | 3365 | LOG(3, "DEBUG: No need to create any triangles."); | 
|---|
| [16d866] | 3366 | } | 
|---|
| [6613ec] | 3367 | delete (ListOfClosedPaths); | 
|---|
| [16d866] | 3368 |  | 
|---|
| [ce7bfd] | 3369 | LOG(1, "INFO: Removed volume is " << volume << "."); | 
|---|
| [357fba] | 3370 |  | 
|---|
| [57066a] | 3371 | return volume; | 
|---|
| [6613ec] | 3372 | } | 
|---|
|  | 3373 | ; | 
|---|
| [ab1932] | 3374 |  | 
|---|
|  | 3375 | /** | 
|---|
| [62bb91] | 3376 | * Finds triangles belonging to the three provided points. | 
|---|
| [ab1932] | 3377 | * | 
|---|
| [71b20e] | 3378 | * @param *Points[3] list, is expected to contain three points (NULL means wildcard) | 
|---|
| [ab1932] | 3379 | * | 
|---|
| [62bb91] | 3380 | * @return triangles which belong to the provided points, will be empty if there are none, | 
|---|
| [ab1932] | 3381 | *         will usually be one, in case of degeneration, there will be two | 
|---|
|  | 3382 | */ | 
|---|
| [c15ca2] | 3383 | TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const | 
|---|
| [ab1932] | 3384 | { | 
|---|
| [ce7bfd] | 3385 | //Info FunctionInfo(__func__); | 
|---|
| [6613ec] | 3386 | TriangleList *result = new TriangleList; | 
|---|
| [776b64] | 3387 | LineMap::const_iterator FindLine; | 
|---|
|  | 3388 | TriangleMap::const_iterator FindTriangle; | 
|---|
| [ab1932] | 3389 | class BoundaryPointSet *TrianglePoints[3]; | 
|---|
| [71b20e] | 3390 | size_t NoOfWildcards = 0; | 
|---|
| [ab1932] | 3391 |  | 
|---|
|  | 3392 | for (int i = 0; i < 3; i++) { | 
|---|
| [71b20e] | 3393 | if (Points[i] == NULL) { | 
|---|
|  | 3394 | NoOfWildcards++; | 
|---|
| [ab1932] | 3395 | TrianglePoints[i] = NULL; | 
|---|
| [71b20e] | 3396 | } else { | 
|---|
| [735b1c] | 3397 | PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->getNr()); | 
|---|
| [71b20e] | 3398 | if (FindPoint != PointsOnBoundary.end()) { | 
|---|
|  | 3399 | TrianglePoints[i] = FindPoint->second; | 
|---|
|  | 3400 | } else { | 
|---|
|  | 3401 | TrianglePoints[i] = NULL; | 
|---|
|  | 3402 | } | 
|---|
| [ab1932] | 3403 | } | 
|---|
|  | 3404 | } | 
|---|
|  | 3405 |  | 
|---|
| [71b20e] | 3406 | switch (NoOfWildcards) { | 
|---|
|  | 3407 | case 0: // checks lines between the points in the Points for their adjacent triangles | 
|---|
|  | 3408 | for (int i = 0; i < 3; i++) { | 
|---|
|  | 3409 | if (TrianglePoints[i] != NULL) { | 
|---|
| [6613ec] | 3410 | for (int j = i + 1; j < 3; j++) { | 
|---|
| [71b20e] | 3411 | if (TrianglePoints[j] != NULL) { | 
|---|
| [735b1c] | 3412 | for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->getNr()); // is a multimap! | 
|---|
|  | 3413 | (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->getNr()); FindLine++) { | 
|---|
| [6613ec] | 3414 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) { | 
|---|
| [71b20e] | 3415 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) { | 
|---|
|  | 3416 | result->push_back(FindTriangle->second); | 
|---|
|  | 3417 | } | 
|---|
|  | 3418 | } | 
|---|
| [ab1932] | 3419 | } | 
|---|
| [71b20e] | 3420 | // Is it sufficient to consider one of the triangle lines for this. | 
|---|
|  | 3421 | return result; | 
|---|
| [ab1932] | 3422 | } | 
|---|
|  | 3423 | } | 
|---|
|  | 3424 | } | 
|---|
|  | 3425 | } | 
|---|
| [71b20e] | 3426 | break; | 
|---|
|  | 3427 | case 1: // copy all triangles of the respective line | 
|---|
|  | 3428 | { | 
|---|
| [6613ec] | 3429 | int i = 0; | 
|---|
| [71b20e] | 3430 | for (; i < 3; i++) | 
|---|
|  | 3431 | if (TrianglePoints[i] == NULL) | 
|---|
|  | 3432 | break; | 
|---|
| [735b1c] | 3433 | for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->getNr()); // is a multimap! | 
|---|
|  | 3434 | (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->getNr()); FindLine++) { | 
|---|
| [6613ec] | 3435 | for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) { | 
|---|
| [71b20e] | 3436 | if (FindTriangle->second->IsPresentTupel(TrianglePoints)) { | 
|---|
|  | 3437 | result->push_back(FindTriangle->second); | 
|---|
|  | 3438 | } | 
|---|
|  | 3439 | } | 
|---|
|  | 3440 | } | 
|---|
|  | 3441 | break; | 
|---|
|  | 3442 | } | 
|---|
|  | 3443 | case 2: // copy all triangles of the respective point | 
|---|
|  | 3444 | { | 
|---|
| [6613ec] | 3445 | int i = 0; | 
|---|
| [71b20e] | 3446 | for (; i < 3; i++) | 
|---|
|  | 3447 | if (TrianglePoints[i] != NULL) | 
|---|
|  | 3448 | break; | 
|---|
|  | 3449 | for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++) | 
|---|
|  | 3450 | for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++) | 
|---|
|  | 3451 | result->push_back(triangle->second); | 
|---|
|  | 3452 | result->sort(); | 
|---|
|  | 3453 | result->unique(); | 
|---|
|  | 3454 | break; | 
|---|
|  | 3455 | } | 
|---|
|  | 3456 | case 3: // copy all triangles | 
|---|
|  | 3457 | { | 
|---|
|  | 3458 | for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++) | 
|---|
|  | 3459 | result->push_back(triangle->second); | 
|---|
|  | 3460 | break; | 
|---|
| [ab1932] | 3461 | } | 
|---|
| [71b20e] | 3462 | default: | 
|---|
| [47d041] | 3463 | ELOG(0, "Number of wildcards is greater than 3, cannot happen!"); | 
|---|
| [71b20e] | 3464 | performCriticalExit(); | 
|---|
|  | 3465 | break; | 
|---|
| [ab1932] | 3466 | } | 
|---|
|  | 3467 |  | 
|---|
|  | 3468 | return result; | 
|---|
|  | 3469 | } | 
|---|
|  | 3470 |  | 
|---|
| [6613ec] | 3471 | struct BoundaryLineSetCompare | 
|---|
|  | 3472 | { | 
|---|
|  | 3473 | bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b) | 
|---|
|  | 3474 | { | 
|---|
| [856098] | 3475 | int lowerNra = -1; | 
|---|
|  | 3476 | int lowerNrb = -1; | 
|---|
|  | 3477 |  | 
|---|
|  | 3478 | if (a->endpoints[0] < a->endpoints[1]) | 
|---|
|  | 3479 | lowerNra = 0; | 
|---|
|  | 3480 | else | 
|---|
|  | 3481 | lowerNra = 1; | 
|---|
|  | 3482 |  | 
|---|
|  | 3483 | if (b->endpoints[0] < b->endpoints[1]) | 
|---|
|  | 3484 | lowerNrb = 0; | 
|---|
|  | 3485 | else | 
|---|
|  | 3486 | lowerNrb = 1; | 
|---|
|  | 3487 |  | 
|---|
|  | 3488 | if (a->endpoints[lowerNra] < b->endpoints[lowerNrb]) | 
|---|
|  | 3489 | return true; | 
|---|
|  | 3490 | else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb]) | 
|---|
|  | 3491 | return false; | 
|---|
| [6613ec] | 3492 | else { // both lower-numbered endpoints are the same ... | 
|---|
|  | 3493 | if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2]) | 
|---|
|  | 3494 | return true; | 
|---|
|  | 3495 | else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2]) | 
|---|
|  | 3496 | return false; | 
|---|
| [856098] | 3497 | } | 
|---|
|  | 3498 | return false; | 
|---|
| [6613ec] | 3499 | } | 
|---|
|  | 3500 | ; | 
|---|
| [856098] | 3501 | }; | 
|---|
|  | 3502 |  | 
|---|
|  | 3503 | #define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare> | 
|---|
|  | 3504 |  | 
|---|
| [7c14ec] | 3505 | /** | 
|---|
| [57066a] | 3506 | * Finds all degenerated lines within the tesselation structure. | 
|---|
| [7c14ec] | 3507 | * | 
|---|
| [57066a] | 3508 | * @return map of keys of degenerated line pairs, each line occurs twice | 
|---|
| [7c14ec] | 3509 | *         in the list, once as key and once as value | 
|---|
|  | 3510 | */ | 
|---|
| [c15ca2] | 3511 | IndexToIndex * Tesselation::FindAllDegeneratedLines() | 
|---|
| [7c14ec] | 3512 | { | 
|---|
| [ce7bfd] | 3513 | //Info FunctionInfo(__func__); | 
|---|
| [6613ec] | 3514 | UniqueLines AllLines; | 
|---|
| [c15ca2] | 3515 | IndexToIndex * DegeneratedLines = new IndexToIndex; | 
|---|
| [7c14ec] | 3516 |  | 
|---|
|  | 3517 | // sanity check | 
|---|
|  | 3518 | if (LinesOnBoundary.empty()) { | 
|---|
| [47d041] | 3519 | ELOG(2, "FindAllDegeneratedTriangles() was called without any tesselation structure."); | 
|---|
| [57066a] | 3520 | return DegeneratedLines; | 
|---|
| [7c14ec] | 3521 | } | 
|---|
| [57066a] | 3522 | LineMap::iterator LineRunner1; | 
|---|
| [6613ec] | 3523 | pair<UniqueLines::iterator, bool> tester; | 
|---|
| [7c14ec] | 3524 | for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) { | 
|---|
| [6613ec] | 3525 | tester = AllLines.insert(LineRunner1->second); | 
|---|
| [856098] | 3526 | if (!tester.second) { // found degenerated line | 
|---|
| [6613ec] | 3527 | DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr)); | 
|---|
|  | 3528 | DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr)); | 
|---|
| [57066a] | 3529 | } | 
|---|
|  | 3530 | } | 
|---|
|  | 3531 |  | 
|---|
|  | 3532 | AllLines.clear(); | 
|---|
|  | 3533 |  | 
|---|
| [ce7bfd] | 3534 | LOG(2, "DEBUG: FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines."); | 
|---|
| [c15ca2] | 3535 | IndexToIndex::iterator it; | 
|---|
| [856098] | 3536 | for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) { | 
|---|
|  | 3537 | const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first); | 
|---|
|  | 3538 | const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second); | 
|---|
|  | 3539 | if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end()) | 
|---|
| [ce7bfd] | 3540 | LOG(3, "DEBUG: " << *Line1->second << " => " << *Line2->second); | 
|---|
| [856098] | 3541 | else | 
|---|
| [47d041] | 3542 | ELOG(1, "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!"); | 
|---|
| [856098] | 3543 | } | 
|---|
| [57066a] | 3544 |  | 
|---|
|  | 3545 | return DegeneratedLines; | 
|---|
|  | 3546 | } | 
|---|
|  | 3547 |  | 
|---|
|  | 3548 | /** | 
|---|
|  | 3549 | * Finds all degenerated triangles within the tesselation structure. | 
|---|
|  | 3550 | * | 
|---|
|  | 3551 | * @return map of keys of degenerated triangle pairs, each triangle occurs twice | 
|---|
|  | 3552 | *         in the list, once as key and once as value | 
|---|
|  | 3553 | */ | 
|---|
| [c15ca2] | 3554 | IndexToIndex * Tesselation::FindAllDegeneratedTriangles() | 
|---|
| [57066a] | 3555 | { | 
|---|
| [ce7bfd] | 3556 | //Info FunctionInfo(__func__); | 
|---|
| [c15ca2] | 3557 | IndexToIndex * DegeneratedLines = FindAllDegeneratedLines(); | 
|---|
|  | 3558 | IndexToIndex * DegeneratedTriangles = new IndexToIndex; | 
|---|
| [57066a] | 3559 | TriangleMap::iterator TriangleRunner1, TriangleRunner2; | 
|---|
|  | 3560 | LineMap::iterator Liner; | 
|---|
|  | 3561 | class BoundaryLineSet *line1 = NULL, *line2 = NULL; | 
|---|
|  | 3562 |  | 
|---|
| [c15ca2] | 3563 | for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) { | 
|---|
| [57066a] | 3564 | // run over both lines' triangles | 
|---|
|  | 3565 | Liner = LinesOnBoundary.find(LineRunner->first); | 
|---|
|  | 3566 | if (Liner != LinesOnBoundary.end()) | 
|---|
|  | 3567 | line1 = Liner->second; | 
|---|
|  | 3568 | Liner = LinesOnBoundary.find(LineRunner->second); | 
|---|
|  | 3569 | if (Liner != LinesOnBoundary.end()) | 
|---|
|  | 3570 | line2 = Liner->second; | 
|---|
|  | 3571 | for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) { | 
|---|
|  | 3572 | for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) { | 
|---|
| [6613ec] | 3573 | if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) { | 
|---|
|  | 3574 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr)); | 
|---|
|  | 3575 | DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr)); | 
|---|
| [7c14ec] | 3576 | } | 
|---|
|  | 3577 | } | 
|---|
|  | 3578 | } | 
|---|
|  | 3579 | } | 
|---|
| [6613ec] | 3580 | delete (DegeneratedLines); | 
|---|
| [7c14ec] | 3581 |  | 
|---|
| [ce7bfd] | 3582 | LOG(3, "DEBUG: FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:"); | 
|---|
| [b32dbb] | 3583 | for (IndexToIndex::iterator it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++) | 
|---|
| [ce7bfd] | 3584 | LOG(3, "DEBUG:    " << (*it).first << " => " << (*it).second); | 
|---|
| [7c14ec] | 3585 |  | 
|---|
|  | 3586 | return DegeneratedTriangles; | 
|---|
|  | 3587 | } | 
|---|
|  | 3588 |  | 
|---|
|  | 3589 | /** | 
|---|
|  | 3590 | * Purges degenerated triangles from the tesselation structure if they are not | 
|---|
|  | 3591 | * necessary to keep a single point within the structure. | 
|---|
|  | 3592 | */ | 
|---|
|  | 3593 | void Tesselation::RemoveDegeneratedTriangles() | 
|---|
|  | 3594 | { | 
|---|
| [ce7bfd] | 3595 | //Info FunctionInfo(__func__); | 
|---|
| [c15ca2] | 3596 | IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles(); | 
|---|
| [57066a] | 3597 | TriangleMap::iterator finder; | 
|---|
|  | 3598 | BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL; | 
|---|
| [6613ec] | 3599 | int count = 0; | 
|---|
| [7c14ec] | 3600 |  | 
|---|
| [b32dbb] | 3601 | // iterate over all degenerated triangles | 
|---|
|  | 3602 | for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); !DegeneratedTriangles->empty(); TriangleKeyRunner = DegeneratedTriangles->begin()) { | 
|---|
| [ce7bfd] | 3603 | LOG(3, "DEBUG: Checking presence of triangles " << TriangleKeyRunner->first << " and " << TriangleKeyRunner->second << "."); | 
|---|
| [b32dbb] | 3604 | // both ways are stored in the map, only use one | 
|---|
|  | 3605 | if (TriangleKeyRunner->first > TriangleKeyRunner->second) | 
|---|
|  | 3606 | continue; | 
|---|
|  | 3607 |  | 
|---|
|  | 3608 | // determine from the keys in the map the two _present_ triangles | 
|---|
| [57066a] | 3609 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->first); | 
|---|
|  | 3610 | if (finder != TrianglesOnBoundary.end()) | 
|---|
|  | 3611 | triangle = finder->second; | 
|---|
|  | 3612 | else | 
|---|
| [b32dbb] | 3613 | continue; | 
|---|
| [57066a] | 3614 | finder = TrianglesOnBoundary.find(TriangleKeyRunner->second); | 
|---|
|  | 3615 | if (finder != TrianglesOnBoundary.end()) | 
|---|
|  | 3616 | partnerTriangle = finder->second; | 
|---|
|  | 3617 | else | 
|---|
| [b32dbb] | 3618 | continue; | 
|---|
| [7c14ec] | 3619 |  | 
|---|
| [b32dbb] | 3620 | // determine which lines are shared by the two triangles | 
|---|
| [7c14ec] | 3621 | bool trianglesShareLine = false; | 
|---|
|  | 3622 | for (int i = 0; i < 3; ++i) | 
|---|
|  | 3623 | for (int j = 0; j < 3; ++j) | 
|---|
|  | 3624 | trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j]; | 
|---|
|  | 3625 |  | 
|---|
| [6613ec] | 3626 | if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) { | 
|---|
| [57066a] | 3627 | // check whether we have to fix lines | 
|---|
|  | 3628 | BoundaryTriangleSet *Othertriangle = NULL; | 
|---|
|  | 3629 | BoundaryTriangleSet *OtherpartnerTriangle = NULL; | 
|---|
|  | 3630 | TriangleMap::iterator TriangleRunner; | 
|---|
|  | 3631 | for (int i = 0; i < 3; ++i) | 
|---|
|  | 3632 | for (int j = 0; j < 3; ++j) | 
|---|
|  | 3633 | if (triangle->lines[i] != partnerTriangle->lines[j]) { | 
|---|
|  | 3634 | // get the other two triangles | 
|---|
|  | 3635 | for (TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); ++TriangleRunner) | 
|---|
|  | 3636 | if (TriangleRunner->second != triangle) { | 
|---|
|  | 3637 | Othertriangle = TriangleRunner->second; | 
|---|
|  | 3638 | } | 
|---|
|  | 3639 | for (TriangleRunner = partnerTriangle->lines[i]->triangles.begin(); TriangleRunner != partnerTriangle->lines[i]->triangles.end(); ++TriangleRunner) | 
|---|
|  | 3640 | if (TriangleRunner->second != partnerTriangle) { | 
|---|
|  | 3641 | OtherpartnerTriangle = TriangleRunner->second; | 
|---|
|  | 3642 | } | 
|---|
|  | 3643 | /// interchanges their lines so that triangle->lines[i] == partnerTriangle->lines[j] | 
|---|
|  | 3644 | // the line of triangle receives the degenerated ones | 
|---|
|  | 3645 | triangle->lines[i]->triangles.erase(Othertriangle->Nr); | 
|---|
| [6613ec] | 3646 | triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle)); | 
|---|
|  | 3647 | for (int k = 0; k < 3; k++) | 
|---|
| [57066a] | 3648 | if (triangle->lines[i] == Othertriangle->lines[k]) { | 
|---|
|  | 3649 | Othertriangle->lines[k] = partnerTriangle->lines[j]; | 
|---|
|  | 3650 | break; | 
|---|
|  | 3651 | } | 
|---|
|  | 3652 | // the line of partnerTriangle receives the non-degenerated ones | 
|---|
| [6613ec] | 3653 | partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr); | 
|---|
|  | 3654 | partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle)); | 
|---|
| [57066a] | 3655 | partnerTriangle->lines[j] = triangle->lines[i]; | 
|---|
|  | 3656 | } | 
|---|
|  | 3657 |  | 
|---|
|  | 3658 | // erase the pair | 
|---|
|  | 3659 | count += (int) DegeneratedTriangles->erase(triangle->Nr); | 
|---|
| [ce7bfd] | 3660 | LOG(4, "DEBUG: RemoveDegeneratedTriangles() removes triangle " << *triangle << "."); | 
|---|
| [7c14ec] | 3661 | RemoveTesselationTriangle(triangle); | 
|---|
| [57066a] | 3662 | count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr); | 
|---|
| [ce7bfd] | 3663 | LOG(4, "DEBUG: RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "."); | 
|---|
| [7c14ec] | 3664 | RemoveTesselationTriangle(partnerTriangle); | 
|---|
|  | 3665 | } else { | 
|---|
| [ce7bfd] | 3666 | 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] | 3667 | } | 
|---|
|  | 3668 | } | 
|---|
| [6613ec] | 3669 | delete (DegeneratedTriangles); | 
|---|
| [6a7f78c] | 3670 | if (count > 0) | 
|---|
|  | 3671 | LastTriangle = NULL; | 
|---|
| [57066a] | 3672 |  | 
|---|
| [ce7bfd] | 3673 | LOG(2, "INFO: RemoveDegeneratedTriangles() removed " << count << " triangles:"); | 
|---|
| [7c14ec] | 3674 | } | 
|---|
|  | 3675 |  | 
|---|
| [57066a] | 3676 | /** Adds an outside Tesselpoint to the envelope via (two) degenerated triangles. | 
|---|
|  | 3677 | * We look for the closest point on the boundary, we look through its connected boundary lines and | 
|---|
|  | 3678 | * seek the one with the minimum angle between its center point and the new point and this base line. | 
|---|
|  | 3679 | * We open up the line by adding a degenerated triangle, whose other side closes the base line again. | 
|---|
|  | 3680 | * \param *out output stream for debugging | 
|---|
|  | 3681 | * \param *point point to add | 
|---|
|  | 3682 | * \param *LC Linked Cell structure to find nearest point | 
|---|
| [ab1932] | 3683 | */ | 
|---|
| [6bd7e0] | 3684 | void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell_deprecated *LC) | 
|---|
| [ab1932] | 3685 | { | 
|---|
| [ce7bfd] | 3686 | //Info FunctionInfo(__func__); | 
|---|
| [57066a] | 3687 | // find nearest boundary point | 
|---|
|  | 3688 | class TesselPoint *BackupPoint = NULL; | 
|---|
| [d74077] | 3689 | class TesselPoint *NearestPoint = FindClosestTesselPoint(point->getPosition(), BackupPoint, LC); | 
|---|
| [57066a] | 3690 | class BoundaryPointSet *NearestBoundaryPoint = NULL; | 
|---|
|  | 3691 | PointMap::iterator PointRunner; | 
|---|
|  | 3692 |  | 
|---|
|  | 3693 | if (NearestPoint == point) | 
|---|
|  | 3694 | NearestPoint = BackupPoint; | 
|---|
| [735b1c] | 3695 | PointRunner = PointsOnBoundary.find(NearestPoint->getNr()); | 
|---|
| [57066a] | 3696 | if (PointRunner != PointsOnBoundary.end()) { | 
|---|
|  | 3697 | NearestBoundaryPoint = PointRunner->second; | 
|---|
|  | 3698 | } else { | 
|---|
| [47d041] | 3699 | ELOG(1, "I cannot find the boundary point."); | 
|---|
| [57066a] | 3700 | return; | 
|---|
|  | 3701 | } | 
|---|
| [ce7bfd] | 3702 | LOG(3, "DEBUG: Nearest point on boundary is " << NearestPoint->getName() << "."); | 
|---|
| [57066a] | 3703 |  | 
|---|
|  | 3704 | // go through its lines and find the best one to split | 
|---|
|  | 3705 | Vector CenterToPoint; | 
|---|
|  | 3706 | Vector BaseLine; | 
|---|
|  | 3707 | double angle, BestAngle = 0.; | 
|---|
|  | 3708 | class BoundaryLineSet *BestLine = NULL; | 
|---|
|  | 3709 | for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) { | 
|---|
| [d74077] | 3710 | BaseLine = (Runner->second->endpoints[0]->node->getPosition()) - | 
|---|
|  | 3711 | (Runner->second->endpoints[1]->node->getPosition()); | 
|---|
|  | 3712 | CenterToPoint = 0.5 * ((Runner->second->endpoints[0]->node->getPosition()) + | 
|---|
|  | 3713 | (Runner->second->endpoints[1]->node->getPosition())); | 
|---|
|  | 3714 | CenterToPoint -= (point->getPosition()); | 
|---|
| [273382] | 3715 | angle = CenterToPoint.Angle(BaseLine); | 
|---|
| [57066a] | 3716 | if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) { | 
|---|
|  | 3717 | BestAngle = angle; | 
|---|
|  | 3718 | BestLine = Runner->second; | 
|---|
|  | 3719 | } | 
|---|
| [ab1932] | 3720 | } | 
|---|
|  | 3721 |  | 
|---|
| [57066a] | 3722 | // remove one triangle from the chosen line | 
|---|
|  | 3723 | class BoundaryTriangleSet *TempTriangle = (BestLine->triangles.begin())->second; | 
|---|
|  | 3724 | BestLine->triangles.erase(TempTriangle->Nr); | 
|---|
|  | 3725 | int nr = -1; | 
|---|
| [6613ec] | 3726 | for (int i = 0; i < 3; i++) { | 
|---|
| [57066a] | 3727 | if (TempTriangle->lines[i] == BestLine) { | 
|---|
|  | 3728 | nr = i; | 
|---|
|  | 3729 | break; | 
|---|
|  | 3730 | } | 
|---|
|  | 3731 | } | 
|---|
| [ab1932] | 3732 |  | 
|---|
| [57066a] | 3733 | // create new triangle to connect point (connects automatically with the missing spot of the chosen line) | 
|---|
| [47d041] | 3734 | LOG(2, "Adding new triangle points."); | 
|---|
| [57066a] | 3735 | AddTesselationPoint((BestLine->endpoints[0]->node), 0); | 
|---|
|  | 3736 | AddTesselationPoint((BestLine->endpoints[1]->node), 1); | 
|---|
|  | 3737 | AddTesselationPoint(point, 2); | 
|---|
| [47d041] | 3738 | LOG(2, "Adding new triangle lines."); | 
|---|
| [f07f86d] | 3739 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); | 
|---|
|  | 3740 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); | 
|---|
|  | 3741 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); | 
|---|
| [57066a] | 3742 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); | 
|---|
|  | 3743 | BTS->GetNormalVector(TempTriangle->NormalVector); | 
|---|
|  | 3744 | BTS->NormalVector.Scale(-1.); | 
|---|
| [47d041] | 3745 | LOG(1, "INFO: NormalVector of new triangle is " << BTS->NormalVector << "."); | 
|---|
| [57066a] | 3746 | AddTesselationTriangle(); | 
|---|
|  | 3747 |  | 
|---|
|  | 3748 | // create other side of this triangle and close both new sides of the first created triangle | 
|---|
| [47d041] | 3749 | LOG(2, "Adding new triangle points."); | 
|---|
| [57066a] | 3750 | AddTesselationPoint((BestLine->endpoints[0]->node), 0); | 
|---|
|  | 3751 | AddTesselationPoint((BestLine->endpoints[1]->node), 1); | 
|---|
|  | 3752 | AddTesselationPoint(point, 2); | 
|---|
| [47d041] | 3753 | LOG(2, "Adding new triangle lines."); | 
|---|
| [f07f86d] | 3754 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); | 
|---|
|  | 3755 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); | 
|---|
|  | 3756 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); | 
|---|
| [57066a] | 3757 | BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); | 
|---|
|  | 3758 | BTS->GetNormalVector(TempTriangle->NormalVector); | 
|---|
| [47d041] | 3759 | LOG(1, "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "."); | 
|---|
| [57066a] | 3760 | AddTesselationTriangle(); | 
|---|
|  | 3761 |  | 
|---|
|  | 3762 | // add removed triangle to the last open line of the second triangle | 
|---|
| [6613ec] | 3763 | for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion) | 
|---|
| [57066a] | 3764 | if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) { | 
|---|
| [6613ec] | 3765 | if (BestLine == BTS->lines[i]) { | 
|---|
| [47d041] | 3766 | ELOG(0, "BestLine is same as found line, something's wrong here!"); | 
|---|
| [f67b6e] | 3767 | performCriticalExit(); | 
|---|
| [57066a] | 3768 | } | 
|---|
| [6613ec] | 3769 | BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle)); | 
|---|
| [57066a] | 3770 | TempTriangle->lines[nr] = BTS->lines[i]; | 
|---|
|  | 3771 | break; | 
|---|
|  | 3772 | } | 
|---|
|  | 3773 | } | 
|---|
| [6613ec] | 3774 | } | 
|---|
|  | 3775 | ; | 
|---|
| [57066a] | 3776 |  | 
|---|
|  | 3777 | /** Writes the envelope to file. | 
|---|
|  | 3778 | * \param *out otuput stream for debugging | 
|---|
|  | 3779 | * \param *filename basename of output file | 
|---|
| [34c43a] | 3780 | * \param *cloud IPointCloud structure with all nodes | 
|---|
| [57066a] | 3781 | */ | 
|---|
| [34c43a] | 3782 | void Tesselation::Output(const char *filename, IPointCloud & cloud) | 
|---|
| [57066a] | 3783 | { | 
|---|
| [ce7bfd] | 3784 | //Info FunctionInfo(__func__); | 
|---|
| [57066a] | 3785 | ofstream *tempstream = NULL; | 
|---|
|  | 3786 | string NameofTempFile; | 
|---|
| [68f03d] | 3787 | string NumberName; | 
|---|
| [57066a] | 3788 |  | 
|---|
|  | 3789 | if (LastTriangle != NULL) { | 
|---|
| [68f03d] | 3790 | stringstream sstr; | 
|---|
| [8f215d] | 3791 | sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->getEndpointName(0) << "_" << LastTriangle->getEndpointName(1) << "_" << LastTriangle->getEndpointName(2); | 
|---|
| [68f03d] | 3792 | NumberName = sstr.str(); | 
|---|
| [57066a] | 3793 | if (DoTecplotOutput) { | 
|---|
|  | 3794 | string NameofTempFile(filename); | 
|---|
|  | 3795 | NameofTempFile.append(NumberName); | 
|---|
| [6613ec] | 3796 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos)) | 
|---|
|  | 3797 | NameofTempFile.erase(npos, 1); | 
|---|
| [57066a] | 3798 | NameofTempFile.append(TecplotSuffix); | 
|---|
| [47d041] | 3799 | LOG(1, "INFO: Writing temporary non convex hull to file " << NameofTempFile << "."); | 
|---|
| [57066a] | 3800 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc); | 
|---|
| [e138de] | 3801 | WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten); | 
|---|
| [57066a] | 3802 | tempstream->close(); | 
|---|
|  | 3803 | tempstream->flush(); | 
|---|
| [6613ec] | 3804 | delete (tempstream); | 
|---|
| [57066a] | 3805 | } | 
|---|
|  | 3806 |  | 
|---|
|  | 3807 | if (DoRaster3DOutput) { | 
|---|
|  | 3808 | string NameofTempFile(filename); | 
|---|
|  | 3809 | NameofTempFile.append(NumberName); | 
|---|
| [6613ec] | 3810 | for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos)) | 
|---|
|  | 3811 | NameofTempFile.erase(npos, 1); | 
|---|
| [57066a] | 3812 | NameofTempFile.append(Raster3DSuffix); | 
|---|
| [47d041] | 3813 | LOG(1, "INFO: Writing temporary non convex hull to file " << NameofTempFile << "."); | 
|---|
| [57066a] | 3814 | tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc); | 
|---|
| [e138de] | 3815 | WriteRaster3dFile(tempstream, this, cloud); | 
|---|
|  | 3816 | IncludeSphereinRaster3D(tempstream, this, cloud); | 
|---|
| [57066a] | 3817 | tempstream->close(); | 
|---|
|  | 3818 | tempstream->flush(); | 
|---|
| [6613ec] | 3819 | delete (tempstream); | 
|---|
| [57066a] | 3820 | } | 
|---|
|  | 3821 | } | 
|---|
|  | 3822 | if (DoTecplotOutput || DoRaster3DOutput) | 
|---|
|  | 3823 | TriangleFilesWritten++; | 
|---|
| [6613ec] | 3824 | } | 
|---|
|  | 3825 | ; | 
|---|
| [262bae] | 3826 |  | 
|---|
| [6613ec] | 3827 | struct BoundaryPolygonSetCompare | 
|---|
|  | 3828 | { | 
|---|
|  | 3829 | bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const | 
|---|
|  | 3830 | { | 
|---|
| [856098] | 3831 | if (s1->endpoints.size() < s2->endpoints.size()) | 
|---|
|  | 3832 | return true; | 
|---|
|  | 3833 | else if (s1->endpoints.size() > s2->endpoints.size()) | 
|---|
|  | 3834 | return false; | 
|---|
|  | 3835 | else { // equality of number of endpoints | 
|---|
|  | 3836 | PointSet::const_iterator Walker1 = s1->endpoints.begin(); | 
|---|
|  | 3837 | PointSet::const_iterator Walker2 = s2->endpoints.begin(); | 
|---|
|  | 3838 | while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) { | 
|---|
|  | 3839 | if ((*Walker1)->Nr < (*Walker2)->Nr) | 
|---|
|  | 3840 | return true; | 
|---|
|  | 3841 | else if ((*Walker1)->Nr > (*Walker2)->Nr) | 
|---|
|  | 3842 | return false; | 
|---|
|  | 3843 | Walker1++; | 
|---|
|  | 3844 | Walker2++; | 
|---|
|  | 3845 | } | 
|---|
|  | 3846 | return false; | 
|---|
|  | 3847 | } | 
|---|
|  | 3848 | } | 
|---|
|  | 3849 | }; | 
|---|
|  | 3850 |  | 
|---|
|  | 3851 | #define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare> | 
|---|
|  | 3852 |  | 
|---|
| [262bae] | 3853 | /** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/ | 
|---|
|  | 3854 | * \return number of polygons found | 
|---|
|  | 3855 | */ | 
|---|
|  | 3856 | int Tesselation::CorrectAllDegeneratedPolygons() | 
|---|
|  | 3857 | { | 
|---|
| [ce7bfd] | 3858 | //Info FunctionInfo(__func__); | 
|---|
| [fad93c] | 3859 | /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector | 
|---|
| [c15ca2] | 3860 | IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles(); | 
|---|
| [6613ec] | 3861 | set<BoundaryPointSet *> EndpointCandidateList; | 
|---|
|  | 3862 | pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester; | 
|---|
|  | 3863 | pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester; | 
|---|
| [fad93c] | 3864 | for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) { | 
|---|
| [ce7bfd] | 3865 | LOG(3, "DEBUG: Current point is " << *Runner->second << "."); | 
|---|
| [6613ec] | 3866 | map<int, Vector *> TriangleVectors; | 
|---|
| [fad93c] | 3867 | // gather all NormalVectors | 
|---|
| [ce7bfd] | 3868 | LOG(4, "DEBUG: Gathering triangles ..."); | 
|---|
| [fad93c] | 3869 | for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++) | 
|---|
|  | 3870 | for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { | 
|---|
| [b998c3] | 3871 | if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) { | 
|---|
| [6613ec] | 3872 | TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector))); | 
|---|
| [b998c3] | 3873 | if (TriangleInsertionTester.second) | 
|---|
| [ce7bfd] | 3874 | LOG(5, "DEBUG:  Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list."); | 
|---|
| [b998c3] | 3875 | } else { | 
|---|
| [ce7bfd] | 3876 | LOG(5, "DEBUG:  NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one."); | 
|---|
| [b998c3] | 3877 | } | 
|---|
| [fad93c] | 3878 | } | 
|---|
|  | 3879 | // check whether there are two that are parallel | 
|---|
| [ce7bfd] | 3880 | LOG(3, "DEBUG: Finding two parallel triangles ..."); | 
|---|
| [6613ec] | 3881 | for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++) | 
|---|
|  | 3882 | for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) | 
|---|
| [fad93c] | 3883 | if (VectorWalker != VectorRunner) { // skip equals | 
|---|
| [8cbb97] | 3884 | const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles | 
|---|
| [ce7bfd] | 3885 | LOG(4, "DEBUG: Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP); | 
|---|
| [fad93c] | 3886 | if (fabs(SCP + 1.) < ParallelEpsilon) { | 
|---|
|  | 3887 | InsertionTester = EndpointCandidateList.insert((Runner->second)); | 
|---|
|  | 3888 | if (InsertionTester.second) | 
|---|
| [ce7bfd] | 3889 | LOG(4, "DEBUG:  Adding " << *Runner->second << " to endpoint candidate list."); | 
|---|
| [fad93c] | 3890 | // and break out of both loops | 
|---|
|  | 3891 | VectorWalker = TriangleVectors.end(); | 
|---|
|  | 3892 | VectorRunner = TriangleVectors.end(); | 
|---|
|  | 3893 | break; | 
|---|
|  | 3894 | } | 
|---|
|  | 3895 | } | 
|---|
|  | 3896 | } | 
|---|
| [9d4c20] | 3897 | delete DegeneratedTriangles; | 
|---|
| [856098] | 3898 |  | 
|---|
| [fad93c] | 3899 | /// 3. Find connected endpoint candidates and put them into a polygon | 
|---|
|  | 3900 | UniquePolygonSet ListofDegeneratedPolygons; | 
|---|
|  | 3901 | BoundaryPointSet *Walker = NULL; | 
|---|
|  | 3902 | BoundaryPointSet *OtherWalker = NULL; | 
|---|
|  | 3903 | BoundaryPolygonSet *Current = NULL; | 
|---|
| [6613ec] | 3904 | stack<BoundaryPointSet*> ToCheckConnecteds; | 
|---|
| [fad93c] | 3905 | while (!EndpointCandidateList.empty()) { | 
|---|
|  | 3906 | Walker = *(EndpointCandidateList.begin()); | 
|---|
| [6613ec] | 3907 | if (Current == NULL) { // create a new polygon with current candidate | 
|---|
| [ce7bfd] | 3908 | LOG(3, "DEBUG: Starting new polygon set at point " << *Walker); | 
|---|
| [fad93c] | 3909 | Current = new BoundaryPolygonSet; | 
|---|
|  | 3910 | Current->endpoints.insert(Walker); | 
|---|
|  | 3911 | EndpointCandidateList.erase(Walker); | 
|---|
|  | 3912 | ToCheckConnecteds.push(Walker); | 
|---|
| [856098] | 3913 | } | 
|---|
| [262bae] | 3914 |  | 
|---|
| [fad93c] | 3915 | // go through to-check stack | 
|---|
|  | 3916 | while (!ToCheckConnecteds.empty()) { | 
|---|
|  | 3917 | Walker = ToCheckConnecteds.top(); // fetch ... | 
|---|
|  | 3918 | ToCheckConnecteds.pop(); // ... and remove | 
|---|
|  | 3919 | for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) { | 
|---|
|  | 3920 | OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker); | 
|---|
| [ce7bfd] | 3921 | LOG(4, "DEBUG: Checking " << *OtherWalker); | 
|---|
| [6613ec] | 3922 | set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker); | 
|---|
|  | 3923 | if (Finder != EndpointCandidateList.end()) { // found a connected partner | 
|---|
| [ce7bfd] | 3924 | LOG(5, "DEBUG:  Adding to polygon."); | 
|---|
| [fad93c] | 3925 | Current->endpoints.insert(OtherWalker); | 
|---|
| [6613ec] | 3926 | EndpointCandidateList.erase(Finder); // remove from candidates | 
|---|
|  | 3927 | ToCheckConnecteds.push(OtherWalker); // but check its partners too | 
|---|
| [856098] | 3928 | } else { | 
|---|
| [ce7bfd] | 3929 | LOG(5, "DEBUG:  is not connected to " << *Walker); | 
|---|
| [856098] | 3930 | } | 
|---|
|  | 3931 | } | 
|---|
|  | 3932 | } | 
|---|
| [262bae] | 3933 |  | 
|---|
| [ce7bfd] | 3934 | LOG(3, "DEBUG: Final polygon is " << *Current); | 
|---|
| [fad93c] | 3935 | ListofDegeneratedPolygons.insert(Current); | 
|---|
|  | 3936 | Current = NULL; | 
|---|
| [262bae] | 3937 | } | 
|---|
|  | 3938 |  | 
|---|
| [fad93c] | 3939 | const int counter = ListofDegeneratedPolygons.size(); | 
|---|
| [262bae] | 3940 |  | 
|---|
| [47d041] | 3941 | if (DoLog(0)) { | 
|---|
|  | 3942 | std::stringstream output; | 
|---|
|  | 3943 | output << "The following " << counter << " degenerated polygons have been found: "; | 
|---|
|  | 3944 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) | 
|---|
|  | 3945 | output << " " << **PolygonRunner; | 
|---|
| [ce7bfd] | 3946 | LOG(3, "DEBUG: " << output.str()); | 
|---|
| [47d041] | 3947 | } | 
|---|
| [856098] | 3948 |  | 
|---|
| [262bae] | 3949 | /// 4. Go through all these degenerated polygons | 
|---|
| [fad93c] | 3950 | for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) { | 
|---|
| [6613ec] | 3951 | stack<int> TriangleNrs; | 
|---|
| [856098] | 3952 | Vector NormalVector; | 
|---|
| [262bae] | 3953 | /// 4a. Gather all triangles of this polygon | 
|---|
| [856098] | 3954 | TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints(); | 
|---|
| [262bae] | 3955 |  | 
|---|
| [125b3c] | 3956 | // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do. | 
|---|
| [b998c3] | 3957 | if (T->size() == 2) { | 
|---|
| [ce7bfd] | 3958 | LOG(4, "DEBUG:  Skipping degenerated polygon, is just a (already simply degenerated) triangle."); | 
|---|
| [6613ec] | 3959 | delete (T); | 
|---|
| [b998c3] | 3960 | continue; | 
|---|
|  | 3961 | } | 
|---|
|  | 3962 |  | 
|---|
| [125b3c] | 3963 | // check whether number is even | 
|---|
|  | 3964 | // If this case occurs, we have to think about it! | 
|---|
|  | 3965 | // The Problem is probably due to two degenerated polygons being connected by a bridging, non-degenerated polygon, as somehow one node has | 
|---|
|  | 3966 | // connections to either polygon ... | 
|---|
|  | 3967 | if (T->size() % 2 != 0) { | 
|---|
| [47d041] | 3968 | ELOG(0, " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!"); | 
|---|
| [125b3c] | 3969 | performCriticalExit(); | 
|---|
|  | 3970 | } | 
|---|
| [6613ec] | 3971 | TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator | 
|---|
| [262bae] | 3972 | /// 4a. Get NormalVector for one side (this is "front") | 
|---|
| [273382] | 3973 | NormalVector = (*TriangleWalker)->NormalVector; | 
|---|
| [ce7bfd] | 3974 | LOG(4, "DEBUG: \"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector); | 
|---|
| [856098] | 3975 | TriangleWalker++; | 
|---|
|  | 3976 | TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator | 
|---|
| [262bae] | 3977 | /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back") | 
|---|
| [856098] | 3978 | BoundaryTriangleSet *triangle = NULL; | 
|---|
|  | 3979 | while (TriangleSprinter != T->end()) { | 
|---|
|  | 3980 | TriangleWalker = TriangleSprinter; | 
|---|
|  | 3981 | triangle = *TriangleWalker; | 
|---|
|  | 3982 | TriangleSprinter++; | 
|---|
| [ce7bfd] | 3983 | LOG(4, "DEBUG: Current triangle to test for removal: " << *triangle); | 
|---|
| [273382] | 3984 | if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list | 
|---|
| [ce7bfd] | 3985 | LOG(5, "DEBUG:  Removing ... "); | 
|---|
| [856098] | 3986 | TriangleNrs.push(triangle->Nr); | 
|---|
| [262bae] | 3987 | T->erase(TriangleWalker); | 
|---|
| [856098] | 3988 | RemoveTesselationTriangle(triangle); | 
|---|
|  | 3989 | } else | 
|---|
| [ce7bfd] | 3990 | LOG(5, "DEBUG:  Keeping ... "); | 
|---|
| [262bae] | 3991 | } | 
|---|
|  | 3992 | /// 4c. Copy all "front" triangles but with inverse NormalVector | 
|---|
|  | 3993 | TriangleWalker = T->begin(); | 
|---|
| [6613ec] | 3994 | while (TriangleWalker != T->end()) { // go through all front triangles | 
|---|
| [ce7bfd] | 3995 | LOG(4, "DEBUG:  Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector); | 
|---|
| [856098] | 3996 | for (int i = 0; i < 3; i++) | 
|---|
|  | 3997 | AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i); | 
|---|
| [f07f86d] | 3998 | AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); | 
|---|
|  | 3999 | AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); | 
|---|
|  | 4000 | AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); | 
|---|
| [fad93c] | 4001 | if (TriangleNrs.empty()) | 
|---|
| [47d041] | 4002 | ELOG(0, "No more free triangle numbers!"); | 
|---|
| [856098] | 4003 | BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ... | 
|---|
|  | 4004 | AddTesselationTriangle(); // ... and add | 
|---|
|  | 4005 | TriangleNrs.pop(); | 
|---|
| [273382] | 4006 | BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector; | 
|---|
| [262bae] | 4007 | TriangleWalker++; | 
|---|
|  | 4008 | } | 
|---|
| [856098] | 4009 | if (!TriangleNrs.empty()) { | 
|---|
| [47d041] | 4010 | ELOG(0, "There have been less triangles created than removed!"); | 
|---|
| [856098] | 4011 | } | 
|---|
| [6613ec] | 4012 | delete (T); // remove the triangleset | 
|---|
| [262bae] | 4013 | } | 
|---|
| [c15ca2] | 4014 | IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles(); | 
|---|
| [ce7bfd] | 4015 | LOG(2, "DEBUG: Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:"); | 
|---|
| [c15ca2] | 4016 | IndexToIndex::iterator it; | 
|---|
| [856098] | 4017 | for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++) | 
|---|
| [ce7bfd] | 4018 | LOG(2, "DEBUG:   " << (*it).first << " => " << (*it).second); | 
|---|
| [6613ec] | 4019 | delete (SimplyDegeneratedTriangles); | 
|---|
| [262bae] | 4020 | /// 5. exit | 
|---|
| [856098] | 4021 | UniquePolygonSet::iterator PolygonRunner; | 
|---|
| [fad93c] | 4022 | while (!ListofDegeneratedPolygons.empty()) { | 
|---|
|  | 4023 | PolygonRunner = ListofDegeneratedPolygons.begin(); | 
|---|
| [6613ec] | 4024 | delete (*PolygonRunner); | 
|---|
| [fad93c] | 4025 | ListofDegeneratedPolygons.erase(PolygonRunner); | 
|---|
| [262bae] | 4026 | } | 
|---|
|  | 4027 |  | 
|---|
|  | 4028 | return counter; | 
|---|
| [6613ec] | 4029 | } | 
|---|
|  | 4030 | ; | 
|---|