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