Changes in src/tesselation.cpp [8db598:b1a6d8]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tesselation.cpp
r8db598 rb1a6d8 7 7 8 8 #include <fstream> 9 #include <assert.h> 9 10 10 11 #include "helpers.hpp" … … 25 26 */ 26 27 BoundaryPointSet::BoundaryPointSet() : 27 LinesCount(0), 28 value(0.), 29 Nr(-1) 30 { 31 Info FunctionInfo(__func__); 32 Log() << Verbose(1) << "Adding noname." << endl; 33 }; 28 LinesCount(0), value(0.), Nr(-1) 29 { 30 Info FunctionInfo(__func__); 31 DoLog(1) && (Log() << Verbose(1) << "Adding noname." << endl); 32 } 33 ; 34 34 35 35 /** Constructor of BoundaryPointSet with Tesselpoint. … … 37 37 */ 38 38 BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) : 39 LinesCount(0), 40 node(Walker), 41 value(0.), 42 Nr(Walker->nr) 43 { 44 Info FunctionInfo(__func__); 45 Log() << Verbose(1) << "Adding Node " << *Walker << endl; 46 }; 39 LinesCount(0), node(Walker), value(0.), Nr(Walker->nr) 40 { 41 Info FunctionInfo(__func__); 42 DoLog(1) && (Log() << Verbose(1) << "Adding Node " << *Walker << endl); 43 } 44 ; 47 45 48 46 /** Destructor of BoundaryPointSet. … … 52 50 BoundaryPointSet::~BoundaryPointSet() 53 51 { 54 52 Info FunctionInfo(__func__); 55 53 //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl; 56 54 if (!lines.empty()) 57 eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl;55 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl); 58 56 node = NULL; 59 }; 57 } 58 ; 60 59 61 60 /** Add a line to the LineMap of this point. … … 64 63 void BoundaryPointSet::AddLine(BoundaryLineSet * const line) 65 64 { 66 Info FunctionInfo(__func__); 67 Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." 68 << endl; 69 if (line->endpoints[0] == this) 70 { 71 lines.insert(LinePair(line->endpoints[1]->Nr, line)); 72 } 73 else 74 { 75 lines.insert(LinePair(line->endpoints[0]->Nr, line)); 76 } 65 Info FunctionInfo(__func__); 66 DoLog(1) && (Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl); 67 if (line->endpoints[0] == this) { 68 lines.insert(LinePair(line->endpoints[1]->Nr, line)); 69 } else { 70 lines.insert(LinePair(line->endpoints[0]->Nr, line)); 71 } 77 72 LinesCount++; 78 }; 73 } 74 ; 79 75 80 76 /** output operator for BoundaryPointSet. … … 94 90 */ 95 91 BoundaryLineSet::BoundaryLineSet() : 96 97 { 98 92 Nr(-1) 93 { 94 Info FunctionInfo(__func__); 99 95 for (int i = 0; i < 2; i++) 100 96 endpoints[i] = NULL; 101 }; 97 } 98 ; 102 99 103 100 /** Constructor of BoundaryLineSet with two endpoints. … … 108 105 BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number) 109 106 { 110 107 Info FunctionInfo(__func__); 111 108 // set number 112 109 Nr = number; … … 119 116 skipped = false; 120 117 // clear triangles list 121 Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl; 122 }; 118 DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl); 119 } 120 ; 123 121 124 122 /** Constructor of BoundaryLineSet with two endpoints. … … 141 139 skipped = false; 142 140 // clear triangles list 143 Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl; 144 }; 141 DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl); 142 } 143 ; 145 144 146 145 /** Destructor for BoundaryLineSet. … … 150 149 BoundaryLineSet::~BoundaryLineSet() 151 150 { 152 151 Info FunctionInfo(__func__); 153 152 int Numbers[2]; 154 153 … … 181 180 //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl; 182 181 if (endpoints[i] != NULL) { 183 delete (endpoints[i]);182 delete (endpoints[i]); 184 183 endpoints[i] = NULL; 185 184 } … … 188 187 } 189 188 if (!triangles.empty()) 190 eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl; 191 }; 189 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl); 190 } 191 ; 192 192 193 193 /** Add triangle to TriangleMap of this boundary line. … … 196 196 void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle) 197 197 { 198 199 Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl;198 Info FunctionInfo(__func__); 199 DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl); 200 200 triangles.insert(TrianglePair(triangle->Nr, triangle)); 201 }; 201 } 202 ; 202 203 203 204 /** Checks whether we have a common endpoint with given \a *line. … … 207 208 bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const 208 209 { 209 210 Info FunctionInfo(__func__); 210 211 if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1])) 211 212 return true; 212 213 else 213 214 return false; 214 }; 215 } 216 ; 215 217 216 218 /** Checks whether the adjacent triangles of a baseline are convex or not. … … 222 224 bool BoundaryLineSet::CheckConvexityCriterion() const 223 225 { 224 226 Info FunctionInfo(__func__); 225 227 Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck; 226 228 // get the two triangles 227 229 if (triangles.size() != 2) { 228 eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;230 DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl); 229 231 return true; 230 232 } … … 234 236 BaseLineCenter.CopyVector(endpoints[0]->node->node); 235 237 BaseLineCenter.AddVector(endpoints[1]->node->node); 236 BaseLineCenter.Scale(1. /2.);238 BaseLineCenter.Scale(1. / 2.); 237 239 BaseLine.CopyVector(endpoints[0]->node->node); 238 240 BaseLine.SubtractVector(endpoints[1]->node->node); … … 242 244 NormalCheck.Zero(); 243 245 double sign = -1.; 244 int i =0;246 int i = 0; 245 247 class BoundaryPointSet *node = NULL; 246 for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {248 for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 247 249 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 248 250 NormalCheck.AddVector(&runner->second->NormalVector); … … 250 252 sign = -sign; 251 253 if (runner->second->NormalVector.NormSquared() > MYEPSILON) 252 BaseLineNormal.CopyVector(&runner->second->NormalVector); 254 BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first 253 255 else { 254 eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl;256 DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl); 255 257 } 256 258 node = runner->second->GetThirdEndpoint(this); … … 259 261 helper[i].CopyVector(node->node->node); 260 262 helper[i].SubtractVector(&BaseLineCenter); 261 helper[i].MakeNormalVector(&BaseLine); 263 helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles! 262 264 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 263 265 i++; 264 266 } else { 265 eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl;267 DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl); 266 268 return true; 267 269 } … … 269 271 //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl; 270 272 if (NormalCheck.NormSquared() < MYEPSILON) { 271 Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;273 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl); 272 274 return true; 273 275 } … … 275 277 double angle = GetAngle(helper[0], helper[1], BaseLineNormal); 276 278 if ((angle - M_PI) > -MYEPSILON) { 277 Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl;279 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl); 278 280 return true; 279 281 } else { 280 Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl;282 DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl); 281 283 return false; 282 284 } … … 289 291 bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const 290 292 { 291 292 for (int i=0;i<2;i++)293 Info FunctionInfo(__func__); 294 for (int i = 0; i < 2; i++) 293 295 if (point == endpoints[i]) 294 296 return true; 295 297 return false; 296 }; 298 } 299 ; 297 300 298 301 /** Returns other endpoint of the line. … … 302 305 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const 303 306 { 304 307 Info FunctionInfo(__func__); 305 308 if (endpoints[0] == point) 306 309 return endpoints[1]; … … 309 312 else 310 313 return NULL; 311 }; 314 } 315 ; 312 316 313 317 /** output operator for BoundaryLineSet. … … 315 319 * \param &a boundary line 316 320 */ 317 ostream & operator <<(ostream &ost, const 321 ostream & operator <<(ostream &ost, const BoundaryLineSet &a) 318 322 { 319 323 ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "]"; 320 324 return ost; 321 }; 325 } 326 ; 322 327 323 328 // ======================================== Triangles on Boundary ================================= … … 328 333 Nr(-1) 329 334 { 330 331 for (int i = 0; i < 3; i++) 332 {333 endpoints[i] = NULL;334 lines[i] = NULL;335 336 };335 Info FunctionInfo(__func__); 336 for (int i = 0; i < 3; i++) { 337 endpoints[i] = NULL; 338 lines[i] = NULL; 339 } 340 } 341 ; 337 342 338 343 /** Constructor for BoundaryTriangleSet with three lines. … … 343 348 Nr(number) 344 349 { 345 350 Info FunctionInfo(__func__); 346 351 // set number 347 352 // set lines … … 355 360 // for all three lines 356 361 for (int j = 0; j < 2; j++) { // for both endpoints 357 OrderMap.insert(pair<int, class BoundaryPointSet *> ( 358 line[i]->endpoints[j]->Nr, line[i]->endpoints[j])); 362 OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j])); 359 363 // and we don't care whether insertion fails 360 364 } 361 365 // set endpoints 362 366 int Counter = 0; 363 Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl;367 DoLog(0) && (Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl); 364 368 for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) { 365 369 endpoints[Counter] = runner->second; 366 Log() << Verbose(0) << " " << *endpoints[Counter] << endl;370 DoLog(0) && (Log() << Verbose(0) << " " << *endpoints[Counter] << endl); 367 371 Counter++; 368 372 } 369 373 if (Counter < 3) { 370 eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl;374 DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl); 371 375 performCriticalExit(); 372 376 } 373 }; 377 } 378 ; 374 379 375 380 /** Destructor of BoundaryTriangleSet. … … 379 384 BoundaryTriangleSet::~BoundaryTriangleSet() 380 385 { 381 386 Info FunctionInfo(__func__); 382 387 for (int i = 0; i < 3; i++) { 383 388 if (lines[i] != NULL) { … … 386 391 } 387 392 if (lines[i]->triangles.empty()) { 388 389 390 393 //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl; 394 delete (lines[i]); 395 lines[i] = NULL; 391 396 } 392 397 } 393 398 } 394 399 //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl; 395 }; 400 } 401 ; 396 402 397 403 /** Calculates the normal vector for this triangle. … … 401 407 void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector) 402 408 { 403 409 Info FunctionInfo(__func__); 404 410 // get normal vector 405 411 NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node); … … 408 414 if (NormalVector.ScalarProduct(&OtherVector) > 0.) 409 415 NormalVector.Scale(-1.); 410 Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl; 411 }; 416 DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl); 417 } 418 ; 412 419 413 420 /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses. … … 430 437 431 438 if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) { 432 eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;439 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 433 440 return false; 434 441 } 435 442 436 Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl;437 Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl;438 Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl;443 DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl); 444 DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl); 445 DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl); 439 446 440 447 if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) { 441 Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl;448 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl); 442 449 return true; 443 } 444 Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl;450 } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) { 451 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl); 445 452 return true; 446 } 447 Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl;453 } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) { 454 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl); 448 455 return true; 449 456 } 450 457 // Calculate cross point between one baseline and the line from the third endpoint to intersection 451 int i =0;458 int i = 0; 452 459 do { 453 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i %3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) {454 helper.CopyVector(endpoints[(i +1)%3]->node->node);455 helper.SubtractVector(endpoints[i %3]->node->node);456 CrossPoint.SubtractVector(endpoints[i %3]->node->node);// cross point was returned as absolute vector457 const double s = CrossPoint.ScalarProduct(&helper) /helper.NormSquared();458 Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl;459 if ((s < -MYEPSILON) || ((s -1.) > MYEPSILON)) {460 Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl;461 i =4;460 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) { 461 helper.CopyVector(endpoints[(i + 1) % 3]->node->node); 462 helper.SubtractVector(endpoints[i % 3]->node->node); 463 CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 464 const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared(); 465 DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl); 466 if ((s < -MYEPSILON) || ((s - 1.) > MYEPSILON)) { 467 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl); 468 i = 4; 462 469 break; 463 470 } 464 471 i++; 465 } else 472 } else 466 473 break; 467 } while (i <3);468 if (i ==3) {469 Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl;474 } while (i < 3); 475 if (i == 3) { 476 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl); 470 477 return true; 471 478 } else { 472 Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl;479 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl); 473 480 return false; 474 481 } 475 }; 482 } 483 ; 476 484 477 485 /** Finds the point on the triangle to the point \a *x. … … 493 501 494 502 // 1. get intersection with plane 495 Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl;503 DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl); 496 504 GetCenter(&Direction); 497 505 if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) { … … 502 510 Vector InPlane; 503 511 InPlane.CopyVector(x); 504 InPlane.SubtractVector(ClosestPoint); 512 InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point 505 513 InPlane.ProjectOntoPlane(&NormalVector); 506 514 InPlane.AddVector(ClosestPoint); 507 515 508 Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl;509 Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl;510 Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl;516 DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl); 517 DoLog(2) && (Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl); 518 DoLog(2) && (Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl); 511 519 512 520 // Calculate cross point between one baseline and the desired point such that distance is shortest … … 516 524 Vector CrossPoint[3]; 517 525 Vector helper; 518 for (int i =0;i<3;i++) {526 for (int i = 0; i < 3; i++) { 519 527 // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point 520 Direction.CopyVector(endpoints[(i +1)%3]->node->node);521 Direction.SubtractVector(endpoints[i %3]->node->node);528 Direction.CopyVector(endpoints[(i + 1) % 3]->node->node); 529 Direction.SubtractVector(endpoints[i % 3]->node->node); 522 530 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 523 CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i %3]->node->node, endpoints[(i+1)%3]->node->node);531 CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node); 524 532 CrossDirection[i].CopyVector(&CrossPoint[i]); 525 533 CrossDirection[i].SubtractVector(&InPlane); 526 CrossPoint[i].SubtractVector(endpoints[i %3]->node->node);// cross point was returned as absolute vector527 const double s = CrossPoint[i].ScalarProduct(&Direction) /Direction.NormSquared();528 Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl;529 if ((s >= -MYEPSILON) && ((s -1.) <= MYEPSILON)) {530 CrossPoint[i].AddVector(endpoints[i %3]->node->node);// make cross point absolute again531 Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl;534 CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 535 const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared(); 536 DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl); 537 if ((s >= -MYEPSILON) && ((s - 1.) <= MYEPSILON)) { 538 CrossPoint[i].AddVector(endpoints[i % 3]->node->node); // make cross point absolute again 539 DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl); 532 540 const double distance = CrossPoint[i].DistanceSquared(x); 533 541 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { … … 539 547 } 540 548 InsideFlag = true; 541 for (int i=0;i<3;i++) { 542 const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+1)%3]); 543 const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i+2)%3]);; 544 if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign 549 for (int i = 0; i < 3; i++) { 550 const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 1) % 3]); 551 const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 2) % 3]); 552 ; 553 if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign 545 554 InsideFlag = false; 546 555 } … … 548 557 ClosestPoint->CopyVector(&InPlane); 549 558 ShortestDistance = InPlane.DistanceSquared(x); 550 } else { 551 for (int i =0;i<3;i++) {559 } else { // also check endnodes 560 for (int i = 0; i < 3; i++) { 552 561 const double distance = x->DistanceSquared(endpoints[i]->node->node); 553 562 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { … … 557 566 } 558 567 } 559 Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl;568 DoLog(1) && (Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl); 560 569 return ShortestDistance; 561 }; 570 } 571 ; 562 572 563 573 /** Checks whether lines is any of the three boundary lines this triangle contains. … … 567 577 bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const 568 578 { 569 570 for (int i=0;i<3;i++)579 Info FunctionInfo(__func__); 580 for (int i = 0; i < 3; i++) 571 581 if (line == lines[i]) 572 582 return true; 573 583 return false; 574 }; 584 } 585 ; 575 586 576 587 /** Checks whether point is any of the three endpoints this triangle contains. … … 580 591 bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const 581 592 { 582 583 for (int i=0;i<3;i++)593 Info FunctionInfo(__func__); 594 for (int i = 0; i < 3; i++) 584 595 if (point == endpoints[i]) 585 596 return true; 586 597 return false; 587 }; 598 } 599 ; 588 600 589 601 /** Checks whether point is any of the three endpoints this triangle contains. … … 593 605 bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const 594 606 { 595 596 for (int i=0;i<3;i++)607 Info FunctionInfo(__func__); 608 for (int i = 0; i < 3; i++) 597 609 if (point == endpoints[i]->node) 598 610 return true; 599 611 return false; 600 }; 612 } 613 ; 601 614 602 615 /** Checks whether three given \a *Points coincide with triangle's endpoints. … … 606 619 bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const 607 620 { 608 Info FunctionInfo(__func__); 609 Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl; 610 return (((endpoints[0] == Points[0]) 611 || (endpoints[0] == Points[1]) 612 || (endpoints[0] == Points[2]) 613 ) && ( 614 (endpoints[1] == Points[0]) 615 || (endpoints[1] == Points[1]) 616 || (endpoints[1] == Points[2]) 617 ) && ( 618 (endpoints[2] == Points[0]) 619 || (endpoints[2] == Points[1]) 620 || (endpoints[2] == Points[2]) 621 622 )); 623 }; 621 Info FunctionInfo(__func__); 622 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl); 623 return (((endpoints[0] == Points[0]) || (endpoints[0] == Points[1]) || (endpoints[0] == Points[2])) && ((endpoints[1] == Points[0]) || (endpoints[1] == Points[1]) || (endpoints[1] == Points[2])) && ((endpoints[2] == Points[0]) || (endpoints[2] == Points[1]) || (endpoints[2] == Points[2]) 624 625 )); 626 } 627 ; 624 628 625 629 /** Checks whether three given \a *Points coincide with triangle's endpoints. … … 629 633 bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const 630 634 { 631 Info FunctionInfo(__func__); 632 return (((endpoints[0] == T->endpoints[0]) 633 || (endpoints[0] == T->endpoints[1]) 634 || (endpoints[0] == T->endpoints[2]) 635 ) && ( 636 (endpoints[1] == T->endpoints[0]) 637 || (endpoints[1] == T->endpoints[1]) 638 || (endpoints[1] == T->endpoints[2]) 639 ) && ( 640 (endpoints[2] == T->endpoints[0]) 641 || (endpoints[2] == T->endpoints[1]) 642 || (endpoints[2] == T->endpoints[2]) 643 644 )); 645 }; 635 Info FunctionInfo(__func__); 636 return (((endpoints[0] == T->endpoints[0]) || (endpoints[0] == T->endpoints[1]) || (endpoints[0] == T->endpoints[2])) && ((endpoints[1] == T->endpoints[0]) || (endpoints[1] == T->endpoints[1]) || (endpoints[1] == T->endpoints[2])) && ((endpoints[2] == T->endpoints[0]) || (endpoints[2] == T->endpoints[1]) || (endpoints[2] == T->endpoints[2]) 637 638 )); 639 } 640 ; 646 641 647 642 /** Returns the endpoint which is not contained in the given \a *line. … … 651 646 class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const 652 647 { 653 648 Info FunctionInfo(__func__); 654 649 // sanity check 655 650 if (!ContainsBoundaryLine(line)) 656 651 return NULL; 657 for (int i=0;i<3;i++)652 for (int i = 0; i < 3; i++) 658 653 if (!line->ContainsBoundaryPoint(endpoints[i])) 659 654 return endpoints[i]; 660 655 // actually, that' impossible :) 661 656 return NULL; 662 }; 657 } 658 ; 663 659 664 660 /** Calculates the center point of the triangle. … … 668 664 void BoundaryTriangleSet::GetCenter(Vector * const center) const 669 665 { 670 666 Info FunctionInfo(__func__); 671 667 center->Zero(); 672 for (int i=0;i<3;i++)668 for (int i = 0; i < 3; i++) 673 669 center->AddVector(endpoints[i]->node->node); 674 center->Scale(1. /3.);675 Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl;670 center->Scale(1. / 3.); 671 DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl); 676 672 } 677 673 … … 683 679 { 684 680 ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]"; 685 // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","686 // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";681 // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," 682 // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]"; 687 683 return ost; 688 }; 684 } 685 ; 689 686 690 687 // ======================================== Polygons on Boundary ================================= … … 696 693 { 697 694 Info FunctionInfo(__func__); 698 }; 695 } 696 ; 699 697 700 698 /** Destructor of BoundaryPolygonSet. … … 706 704 Info FunctionInfo(__func__); 707 705 endpoints.clear(); 708 Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl; 709 }; 706 DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl); 707 } 708 ; 710 709 711 710 /** Calculates the normal vector for this triangle. … … 721 720 Vector *TotalNormal = new Vector; 722 721 PointSet::const_iterator Runner[3]; 723 for (int i =0;i<3; i++) {722 for (int i = 0; i < 3; i++) { 724 723 Runner[i] = endpoints.begin(); 725 for (int j = 0; j <i; j++) { // go as much further724 for (int j = 0; j < i; j++) { // go as much further 726 725 Runner[i]++; 727 726 if (Runner[i] == endpoints.end()) { 728 eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl;727 DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl); 729 728 performCriticalExit(); 730 729 } … … 732 731 } 733 732 TotalNormal->Zero(); 734 int counter =0;735 for (; Runner[2] != endpoints.end(); 733 int counter = 0; 734 for (; Runner[2] != endpoints.end();) { 736 735 TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node); 737 for (int i =0;i<3;i++) // increase each of them736 for (int i = 0; i < 3; i++) // increase each of them 738 737 Runner[i]++; 739 738 TotalNormal->AddVector(&TemporaryNormal); 740 739 } 741 TotalNormal->Scale(1. /(double)counter);740 TotalNormal->Scale(1. / (double) counter); 742 741 743 742 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 744 743 if (TotalNormal->ScalarProduct(&OtherVector) > 0.) 745 744 TotalNormal->Scale(-1.); 746 Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl;745 DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl); 747 746 748 747 return TotalNormal; 749 }; 748 } 749 ; 750 750 751 751 /** Calculates the center point of the triangle. … … 758 758 center->Zero(); 759 759 int counter = 0; 760 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {760 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 761 761 center->AddVector((*Runner)->node->node); 762 762 counter++; 763 763 } 764 center->Scale(1. /(double)counter);765 Log() << Verbose(1) << "Center is at " << *center << "." << endl;764 center->Scale(1. / (double) counter); 765 DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl); 766 766 } 767 767 … … 774 774 Info FunctionInfo(__func__); 775 775 return ContainsPresentTupel(triangle->endpoints, 3); 776 }; 776 } 777 ; 777 778 778 779 /** Checks whether the polygons contains both endpoints of the line. … … 784 785 Info FunctionInfo(__func__); 785 786 return ContainsPresentTupel(line->endpoints, 2); 786 }; 787 } 788 ; 787 789 788 790 /** Checks whether point is any of the three endpoints this triangle contains. … … 793 795 { 794 796 Info FunctionInfo(__func__); 795 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {796 Log() << Verbose(0) << "Checking against " << **Runner << endl;797 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 798 DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl); 797 799 if (point == (*Runner)) { 798 Log() << Verbose(0) << " Contained." << endl;800 DoLog(0) && (Log() << Verbose(0) << " Contained." << endl); 799 801 return true; 800 802 } 801 803 } 802 Log() << Verbose(0) << " Not contained." << endl;804 DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl); 803 805 return false; 804 }; 806 } 807 ; 805 808 806 809 /** Checks whether point is any of the three endpoints this triangle contains. … … 811 814 { 812 815 Info FunctionInfo(__func__); 813 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)816 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) 814 817 if (point == (*Runner)->node) { 815 Log() << Verbose(0) << " Contained." << endl;818 DoLog(0) && (Log() << Verbose(0) << " Contained." << endl); 816 819 return true; 817 820 } 818 Log() << Verbose(0) << " Not contained." << endl;821 DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl); 819 822 return false; 820 }; 823 } 824 ; 821 825 822 826 /** Checks whether given array of \a *Points coincide with polygons's endpoints. … … 829 833 Info FunctionInfo(__func__); 830 834 int counter = 0; 831 Log() << Verbose(1) << "Polygon is " << *this << endl;832 for (int i=0;i<dim;i++) {833 Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl;835 DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl); 836 for (int i = 0; i < dim; i++) { 837 DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl); 834 838 if (ContainsBoundaryPoint(Points[i])) { 835 839 counter++; … … 841 845 else 842 846 return false; 843 }; 847 } 848 ; 844 849 845 850 /** Checks whether given PointList coincide with polygons's endpoints. … … 851 856 Info FunctionInfo(__func__); 852 857 size_t counter = 0; 853 Log() << Verbose(1) << "Polygon is " << *this << endl;854 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {855 Log() << Verbose(1) << " Testing endpoint " << **Runner << endl;858 DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl); 859 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 860 DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl); 856 861 if (ContainsBoundaryPoint(*Runner)) 857 862 counter++; … … 862 867 else 863 868 return false; 864 }; 869 } 870 ; 865 871 866 872 /** Checks whether given set of \a *Points coincide with polygons's endpoints. … … 870 876 bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const 871 877 { 872 return ContainsPresentTupel((const PointSet)P->endpoints); 873 }; 878 return ContainsPresentTupel((const PointSet) P->endpoints); 879 } 880 ; 874 881 875 882 /** Gathers all the endpoints' triangles in a unique set. … … 879 886 { 880 887 Info FunctionInfo(__func__); 881 pair 888 pair<TriangleSet::iterator, bool> Tester; 882 889 TriangleSet *triangles = new TriangleSet; 883 890 884 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)885 for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)886 for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {891 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) 892 for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++) 893 for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) { 887 894 //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl; 888 895 if (ContainsBoundaryTriangle(Sprinter->second)) { 889 896 Tester = triangles->insert(Sprinter->second); 890 897 if (Tester.second) 891 Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl;898 DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl); 892 899 } 893 900 } 894 901 895 Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl;902 DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl); 896 903 return triangles; 897 }; 904 } 905 ; 898 906 899 907 /** Fills the endpoints of this polygon from the triangles attached to \a *line. … … 904 912 { 905 913 Info FunctionInfo(__func__); 906 pair 914 pair<PointSet::iterator, bool> Tester; 907 915 if (line == NULL) 908 916 return false; 909 Log() << Verbose(1) << "Filling polygon from line " << *line << endl;910 for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {911 for (int i =0;i<3;i++) {917 DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl); 918 for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) { 919 for (int i = 0; i < 3; i++) { 912 920 Tester = endpoints.insert((Runner->second)->endpoints[i]); 913 921 if (Tester.second) 914 Log() << Verbose(1) << " Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl;922 DoLog(1) && (Log() << Verbose(1) << " Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl); 915 923 } 916 924 } 917 925 918 926 return true; 919 }; 927 } 928 ; 920 929 921 930 /** output operator for BoundaryPolygonSet. … … 926 935 { 927 936 ost << "[" << a.Nr << "|"; 928 for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {929 ost << (*Runner)->node->Name;930 Runner++;931 if (Runner != a.endpoints.end())932 ost << ",";933 } 934 ost << "]";937 for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) { 938 ost << (*Runner)->node->Name; 939 Runner++; 940 if (Runner != a.endpoints.end()) 941 ost << ","; 942 } 943 ost << "]"; 935 944 return ost; 936 }; 945 } 946 ; 937 947 938 948 // =========================================================== class TESSELPOINT =========================================== … … 945 955 node = NULL; 946 956 nr = -1; 947 Name = NULL; 948 }; 957 Name = NULL; 958 } 959 ; 949 960 950 961 /** Destructor for class TesselPoint. … … 953 964 { 954 965 //Info FunctionInfo(__func__); 955 }; 966 } 967 ; 956 968 957 969 /** Prints LCNode to screen. 958 970 */ 959 ostream & operator << 971 ostream & operator <<(ostream &ost, const TesselPoint &a) 960 972 { 961 973 ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]"; 962 974 return ost; 963 }; 975 } 976 ; 964 977 965 978 /** Prints LCNode to screen. 966 979 */ 967 ostream & TesselPoint::operator << 968 { 969 980 ostream & TesselPoint::operator <<(ostream &ost) 981 { 982 Info FunctionInfo(__func__); 970 983 ost << "[" << (nr) << "|" << this << "]"; 971 984 return ost; 972 } ;973 985 } 986 ; 974 987 975 988 // =========================================================== class POINTCLOUD ============================================ … … 979 992 PointCloud::PointCloud() 980 993 { 981 //Info FunctionInfo(__func__); 982 }; 994 //Info FunctionInfo(__func__); 995 } 996 ; 983 997 984 998 /** Destructor for class PointCloud. … … 986 1000 PointCloud::~PointCloud() 987 1001 { 988 //Info FunctionInfo(__func__); 989 }; 1002 //Info FunctionInfo(__func__); 1003 } 1004 ; 990 1005 991 1006 // ============================ CandidateForTesselation ============================= … … 993 1008 /** Constructor of class CandidateForTesselation. 994 1009 */ 995 CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) : 996 BaseLine(line), 997 ShortestAngle(2.*M_PI), 998 OtherShortestAngle(2.*M_PI) 999 { 1000 Info FunctionInfo(__func__); 1001 }; 1002 1010 CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) : 1011 BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI) 1012 { 1013 Info FunctionInfo(__func__); 1014 } 1015 ; 1003 1016 1004 1017 /** Constructor of class CandidateForTesselation. 1005 1018 */ 1006 CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) : 1007 BaseLine(line), 1008 ShortestAngle(2.*M_PI), 1009 OtherShortestAngle(2.*M_PI) 1010 { 1011 Info FunctionInfo(__func__); 1019 CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) : 1020 BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI) 1021 { 1022 Info FunctionInfo(__func__); 1012 1023 OptCenter.CopyVector(&OptCandidateCenter); 1013 1024 OtherOptCenter.CopyVector(&OtherOptCandidateCenter); 1014 }; 1025 } 1026 ; 1015 1027 1016 1028 /** Destructor for class CandidateForTesselation. 1017 1029 */ 1018 CandidateForTesselation::~CandidateForTesselation() { 1019 BaseLine = NULL; 1020 }; 1030 CandidateForTesselation::~CandidateForTesselation() 1031 { 1032 } 1033 ; 1034 1035 /** Checks validity of a given sphere of a candidate line. 1036 * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside. 1037 * \param RADIUS radius of sphere 1038 * \param *LC LinkedCell structure with other atoms 1039 * \return true - sphere is valid, false - sphere contains other points 1040 */ 1041 bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const 1042 { 1043 Info FunctionInfo(__func__); 1044 1045 const double radiusSquared = RADIUS * RADIUS; 1046 list<const Vector *> VectorList; 1047 VectorList.push_back(&OptCenter); 1048 //VectorList.push_back(&OtherOptCenter); // don't check the other (wrong) center 1049 1050 if (!pointlist.empty()) 1051 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl); 1052 else 1053 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl); 1054 // check baseline for OptCenter and OtherOptCenter being on sphere's surface 1055 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1056 for (int i = 0; i < 2; i++) { 1057 const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared); 1058 if (distance > HULLEPSILON) { 1059 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); 1060 return false; 1061 } 1062 } 1063 } 1064 1065 // check Candidates for OptCenter and OtherOptCenter being on sphere's surface 1066 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) { 1067 const TesselPoint *Walker = *Runner; 1068 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1069 const double distance = fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared); 1070 if (distance > HULLEPSILON) { 1071 DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); 1072 return false; 1073 } else { 1074 DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl); 1075 } 1076 } 1077 } 1078 1079 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl); 1080 bool flag = true; 1081 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1082 // get all points inside the sphere 1083 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner)); 1084 1085 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl); 1086 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 1087 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&OtherOptCenter) << "." << endl); 1088 1089 // remove baseline's endpoints and candidates 1090 for (int i = 0; i < 2; i++) { 1091 DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl); 1092 ListofPoints->remove(BaseLine->endpoints[i]->node); 1093 } 1094 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) { 1095 DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl); 1096 ListofPoints->remove(*Runner); 1097 } 1098 if (!ListofPoints->empty()) { 1099 DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl); 1100 flag = false; 1101 DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl); 1102 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 1103 DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << endl); 1104 } 1105 delete (ListofPoints); 1106 1107 // check with animate_sphere.tcl VMD script 1108 if (ThirdPoint != NULL) { 1109 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl); 1110 } else { 1111 DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl); 1112 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl); 1113 } 1114 } 1115 return flag; 1116 } 1117 ; 1021 1118 1022 1119 /** output operator for CandidateForTesselation. … … 1024 1121 * \param &a boundary line 1025 1122 */ 1026 ostream & operator <<(ostream &ost, const 1123 ostream & operator <<(ostream &ost, const CandidateForTesselation &a) 1027 1124 { 1028 1125 ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with "; … … 1037 1134 for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++) 1038 1135 ost << *(*Runner) << " "; 1039 ost << " at angle " << (a.ShortestAngle) << ".";1136 ost << " at angle " << (a.ShortestAngle) << "."; 1040 1137 } 1041 1138 1042 1139 return ost; 1043 } ;1044 1140 } 1141 ; 1045 1142 1046 1143 // =========================================================== class TESSELATION =========================================== … … 1049 1146 */ 1050 1147 Tesselation::Tesselation() : 1051 PointsOnBoundaryCount(0), 1052 LinesOnBoundaryCount(0), 1053 TrianglesOnBoundaryCount(0), 1054 LastTriangle(NULL), 1055 TriangleFilesWritten(0), 1056 InternalPointer(PointsOnBoundary.begin()) 1057 { 1058 Info FunctionInfo(__func__); 1148 PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin()) 1149 { 1150 Info FunctionInfo(__func__); 1059 1151 } 1060 1152 ; … … 1065 1157 Tesselation::~Tesselation() 1066 1158 { 1067 1068 Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl;1159 Info FunctionInfo(__func__); 1160 DoLog(0) && (Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl); 1069 1161 for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) { 1070 1162 if (runner->second != NULL) { … … 1072 1164 runner->second = NULL; 1073 1165 } else 1074 eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl;1075 } 1076 Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;1166 DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl); 1167 } 1168 DoLog(0) && (Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl); 1077 1169 } 1078 1170 ; … … 1080 1172 /** PointCloud implementation of GetCenter 1081 1173 * Uses PointsOnBoundary and STL stuff. 1082 */ 1174 */ 1083 1175 Vector * Tesselation::GetCenter(ofstream *out) const 1084 1176 { 1085 1086 Vector *Center = new Vector(0., 0.,0.);1087 int num =0;1177 Info FunctionInfo(__func__); 1178 Vector *Center = new Vector(0., 0., 0.); 1179 int num = 0; 1088 1180 for (GoToFirst(); (!IsEnd()); GoToNext()) { 1089 1181 Center->AddVector(GetPoint()->node); 1090 1182 num++; 1091 1183 } 1092 Center->Scale(1. /num);1184 Center->Scale(1. / num); 1093 1185 return Center; 1094 }; 1186 } 1187 ; 1095 1188 1096 1189 /** PointCloud implementation of GoPoint 1097 1190 * Uses PointsOnBoundary and STL stuff. 1098 */ 1191 */ 1099 1192 TesselPoint * Tesselation::GetPoint() const 1100 1193 { 1101 1194 Info FunctionInfo(__func__); 1102 1195 return (InternalPointer->second->node); 1103 }; 1196 } 1197 ; 1104 1198 1105 1199 /** PointCloud implementation of GetTerminalPoint. 1106 1200 * Uses PointsOnBoundary and STL stuff. 1107 */ 1201 */ 1108 1202 TesselPoint * Tesselation::GetTerminalPoint() const 1109 1203 { 1110 1204 Info FunctionInfo(__func__); 1111 1205 PointMap::const_iterator Runner = PointsOnBoundary.end(); 1112 1206 Runner--; 1113 1207 return (Runner->second->node); 1114 }; 1208 } 1209 ; 1115 1210 1116 1211 /** PointCloud implementation of GoToNext. 1117 1212 * Uses PointsOnBoundary and STL stuff. 1118 */ 1213 */ 1119 1214 void Tesselation::GoToNext() const 1120 1215 { 1121 1216 Info FunctionInfo(__func__); 1122 1217 if (InternalPointer != PointsOnBoundary.end()) 1123 1218 InternalPointer++; 1124 }; 1219 } 1220 ; 1125 1221 1126 1222 /** PointCloud implementation of GoToPrevious. 1127 1223 * Uses PointsOnBoundary and STL stuff. 1128 */ 1224 */ 1129 1225 void Tesselation::GoToPrevious() const 1130 1226 { 1131 1227 Info FunctionInfo(__func__); 1132 1228 if (InternalPointer != PointsOnBoundary.begin()) 1133 1229 InternalPointer--; 1134 }; 1230 } 1231 ; 1135 1232 1136 1233 /** PointCloud implementation of GoToFirst. 1137 1234 * Uses PointsOnBoundary and STL stuff. 1138 */ 1235 */ 1139 1236 void Tesselation::GoToFirst() const 1140 1237 { 1141 1238 Info FunctionInfo(__func__); 1142 1239 InternalPointer = PointsOnBoundary.begin(); 1143 }; 1240 } 1241 ; 1144 1242 1145 1243 /** PointCloud implementation of GoToLast. … … 1148 1246 void Tesselation::GoToLast() const 1149 1247 { 1150 1248 Info FunctionInfo(__func__); 1151 1249 InternalPointer = PointsOnBoundary.end(); 1152 1250 InternalPointer--; 1153 }; 1251 } 1252 ; 1154 1253 1155 1254 /** PointCloud implementation of IsEmpty. 1156 1255 * Uses PointsOnBoundary and STL stuff. 1157 */ 1256 */ 1158 1257 bool Tesselation::IsEmpty() const 1159 1258 { 1160 1259 Info FunctionInfo(__func__); 1161 1260 return (PointsOnBoundary.empty()); 1162 }; 1261 } 1262 ; 1163 1263 1164 1264 /** PointCloud implementation of IsLast. 1165 1265 * Uses PointsOnBoundary and STL stuff. 1166 */ 1266 */ 1167 1267 bool Tesselation::IsEnd() const 1168 1268 { 1169 1269 Info FunctionInfo(__func__); 1170 1270 return (InternalPointer == PointsOnBoundary.end()); 1171 } ;1172 1271 } 1272 ; 1173 1273 1174 1274 /** Gueses first starting triangle of the convex envelope. … … 1179 1279 void Tesselation::GuessStartingTriangle() 1180 1280 { 1181 1281 Info FunctionInfo(__func__); 1182 1282 // 4b. create a starting triangle 1183 1283 // 4b1. create all distances … … 1189 1289 1190 1290 // with A chosen, take each pair B,C and sort 1191 if (A != PointsOnBoundary.end()) 1192 { 1193 B = A; 1194 B++; 1195 for (; B != PointsOnBoundary.end(); B++) 1196 { 1197 C = B; 1198 C++; 1199 for (; C != PointsOnBoundary.end(); C++) 1200 { 1201 tmp = A->second->node->node->DistanceSquared(B->second->node->node); 1202 distance = tmp * tmp; 1203 tmp = A->second->node->node->DistanceSquared(C->second->node->node); 1204 distance += tmp * tmp; 1205 tmp = B->second->node->node->DistanceSquared(C->second->node->node); 1206 distance += tmp * tmp; 1207 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); 1208 } 1209 } 1210 } 1291 if (A != PointsOnBoundary.end()) { 1292 B = A; 1293 B++; 1294 for (; B != PointsOnBoundary.end(); B++) { 1295 C = B; 1296 C++; 1297 for (; C != PointsOnBoundary.end(); C++) { 1298 tmp = A->second->node->node->DistanceSquared(B->second->node->node); 1299 distance = tmp * tmp; 1300 tmp = A->second->node->node->DistanceSquared(C->second->node->node); 1301 distance += tmp * tmp; 1302 tmp = B->second->node->node->DistanceSquared(C->second->node->node); 1303 distance += tmp * tmp; 1304 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); 1305 } 1306 } 1307 } 1211 1308 // // listing distances 1212 1309 // Log() << Verbose(1) << "Listing DistanceMMap:"; … … 1218 1315 // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate 1219 1316 DistanceMultiMap::iterator baseline = DistanceMMap.begin(); 1220 for (; baseline != DistanceMMap.end(); baseline++) 1221 { 1222 // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate 1223 // 2. next, we have to check whether all points reside on only one side of the triangle 1224 // 3. construct plane vector 1225 PlaneVector.MakeNormalVector(A->second->node->node, 1226 baseline->second.first->second->node->node, 1227 baseline->second.second->second->node->node); 1228 Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl; 1229 // 4. loop over all points 1230 double sign = 0.; 1231 PointMap::iterator checker = PointsOnBoundary.begin(); 1232 for (; checker != PointsOnBoundary.end(); checker++) 1233 { 1234 // (neglecting A,B,C) 1235 if ((checker == A) || (checker == baseline->second.first) || (checker 1236 == baseline->second.second)) 1237 continue; 1238 // 4a. project onto plane vector 1239 TrialVector.CopyVector(checker->second->node->node); 1240 TrialVector.SubtractVector(A->second->node->node); 1241 distance = TrialVector.ScalarProduct(&PlaneVector); 1242 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1243 continue; 1244 Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl; 1245 tmp = distance / fabs(distance); 1246 // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle) 1247 if ((sign != 0) && (tmp != sign)) 1248 { 1249 // 4c. If so, break 4. loop and continue with next candidate in 1. loop 1250 Log() << Verbose(2) << "Current candidates: " 1251 << A->second->node->Name << "," 1252 << baseline->second.first->second->node->Name << "," 1253 << baseline->second.second->second->node->Name << " leaves " 1254 << checker->second->node->Name << " outside the convex hull." 1255 << endl; 1256 break; 1257 } 1258 else 1259 { // note the sign for later 1260 Log() << Verbose(2) << "Current candidates: " 1261 << A->second->node->Name << "," 1262 << baseline->second.first->second->node->Name << "," 1263 << baseline->second.second->second->node->Name << " leave " 1264 << checker->second->node->Name << " inside the convex hull." 1265 << endl; 1266 sign = tmp; 1267 } 1268 // 4d. Check whether the point is inside the triangle (check distance to each node 1269 tmp = checker->second->node->node->DistanceSquared(A->second->node->node); 1270 int innerpoint = 0; 1271 if ((tmp < A->second->node->node->DistanceSquared( 1272 baseline->second.first->second->node->node)) && (tmp 1273 < A->second->node->node->DistanceSquared( 1274 baseline->second.second->second->node->node))) 1275 innerpoint++; 1276 tmp = checker->second->node->node->DistanceSquared( 1277 baseline->second.first->second->node->node); 1278 if ((tmp < baseline->second.first->second->node->node->DistanceSquared( 1279 A->second->node->node)) && (tmp 1280 < baseline->second.first->second->node->node->DistanceSquared( 1281 baseline->second.second->second->node->node))) 1282 innerpoint++; 1283 tmp = checker->second->node->node->DistanceSquared( 1284 baseline->second.second->second->node->node); 1285 if ((tmp < baseline->second.second->second->node->node->DistanceSquared( 1286 baseline->second.first->second->node->node)) && (tmp 1287 < baseline->second.second->second->node->node->DistanceSquared( 1288 A->second->node->node))) 1289 innerpoint++; 1290 // 4e. If so, break 4. loop and continue with next candidate in 1. loop 1291 if (innerpoint == 3) 1292 break; 1293 } 1294 // 5. come this far, all on same side? Then break 1. loop and construct triangle 1295 if (checker == PointsOnBoundary.end()) 1296 { 1297 Log() << Verbose(2) << "Looks like we have a candidate!" << endl; 1298 break; 1299 } 1300 } 1301 if (baseline != DistanceMMap.end()) 1302 { 1303 BPS[0] = baseline->second.first->second; 1304 BPS[1] = baseline->second.second->second; 1305 BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1306 BPS[0] = A->second; 1307 BPS[1] = baseline->second.second->second; 1308 BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1309 BPS[0] = baseline->second.first->second; 1310 BPS[1] = A->second; 1311 BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1312 1313 // 4b3. insert created triangle 1314 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1315 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); 1316 TrianglesOnBoundaryCount++; 1317 for (int i = 0; i < NDIM; i++) 1318 { 1319 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i])); 1320 LinesOnBoundaryCount++; 1321 } 1322 1323 Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl; 1324 } 1325 else 1326 { 1327 eLog() << Verbose(0) << "No starting triangle found." << endl; 1328 } 1317 for (; baseline != DistanceMMap.end(); baseline++) { 1318 // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate 1319 // 2. next, we have to check whether all points reside on only one side of the triangle 1320 // 3. construct plane vector 1321 PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node); 1322 DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl); 1323 // 4. loop over all points 1324 double sign = 0.; 1325 PointMap::iterator checker = PointsOnBoundary.begin(); 1326 for (; checker != PointsOnBoundary.end(); checker++) { 1327 // (neglecting A,B,C) 1328 if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second)) 1329 continue; 1330 // 4a. project onto plane vector 1331 TrialVector.CopyVector(checker->second->node->node); 1332 TrialVector.SubtractVector(A->second->node->node); 1333 distance = TrialVector.ScalarProduct(&PlaneVector); 1334 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1335 continue; 1336 DoLog(2) && (Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl); 1337 tmp = distance / fabs(distance); 1338 // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle) 1339 if ((sign != 0) && (tmp != sign)) { 1340 // 4c. If so, break 4. loop and continue with next candidate in 1. loop 1341 DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leaves " << checker->second->node->Name << " outside the convex hull." << endl); 1342 break; 1343 } else { // note the sign for later 1344 DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leave " << checker->second->node->Name << " inside the convex hull." << endl); 1345 sign = tmp; 1346 } 1347 // 4d. Check whether the point is inside the triangle (check distance to each node 1348 tmp = checker->second->node->node->DistanceSquared(A->second->node->node); 1349 int innerpoint = 0; 1350 if ((tmp < A->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(baseline->second.second->second->node->node))) 1351 innerpoint++; 1352 tmp = checker->second->node->node->DistanceSquared(baseline->second.first->second->node->node); 1353 if ((tmp < baseline->second.first->second->node->node->DistanceSquared(A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(baseline->second.second->second->node->node))) 1354 innerpoint++; 1355 tmp = checker->second->node->node->DistanceSquared(baseline->second.second->second->node->node); 1356 if ((tmp < baseline->second.second->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(A->second->node->node))) 1357 innerpoint++; 1358 // 4e. If so, break 4. loop and continue with next candidate in 1. loop 1359 if (innerpoint == 3) 1360 break; 1361 } 1362 // 5. come this far, all on same side? Then break 1. loop and construct triangle 1363 if (checker == PointsOnBoundary.end()) { 1364 DoLog(2) && (Log() << Verbose(2) << "Looks like we have a candidate!" << endl); 1365 break; 1366 } 1367 } 1368 if (baseline != DistanceMMap.end()) { 1369 BPS[0] = baseline->second.first->second; 1370 BPS[1] = baseline->second.second->second; 1371 BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1372 BPS[0] = A->second; 1373 BPS[1] = baseline->second.second->second; 1374 BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1375 BPS[0] = baseline->second.first->second; 1376 BPS[1] = A->second; 1377 BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1378 1379 // 4b3. insert created triangle 1380 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1381 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); 1382 TrianglesOnBoundaryCount++; 1383 for (int i = 0; i < NDIM; i++) { 1384 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i])); 1385 LinesOnBoundaryCount++; 1386 } 1387 1388 DoLog(1) && (Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl); 1389 } else { 1390 DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl); 1391 } 1329 1392 } 1330 1393 ; … … 1345 1408 void Tesselation::TesselateOnBoundary(const PointCloud * const cloud) 1346 1409 { 1347 1410 Info FunctionInfo(__func__); 1348 1411 bool flag; 1349 1412 PointMap::iterator winner; … … 1364 1427 // get peak point with respect to this base line's only triangle 1365 1428 BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far 1366 Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl;1429 DoLog(0) && (Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl); 1367 1430 for (int i = 0; i < 3; i++) 1368 1431 if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1])) 1369 1432 peak = BTS->endpoints[i]; 1370 Log() << Verbose(1) << " and has peak " << *peak << "." << endl;1433 DoLog(1) && (Log() << Verbose(1) << " and has peak " << *peak << "." << endl); 1371 1434 1372 1435 // prepare some auxiliary vectors … … 1383 1446 CenterVector.AddVector(BTS->endpoints[i]->node->node); 1384 1447 CenterVector.Scale(1. / 3.); 1385 Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl;1448 DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl); 1386 1449 1387 1450 // normal vector of triangle … … 1390 1453 BTS->GetNormalVector(NormalVector); 1391 1454 NormalVector.CopyVector(&BTS->NormalVector); 1392 Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl;1455 DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl); 1393 1456 1394 1457 // vector in propagation direction (out of triangle) … … 1400 1463 if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline 1401 1464 PropagationVector.Scale(-1.); 1402 Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl;1465 DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl); 1403 1466 winner = PointsOnBoundary.end(); 1404 1467 … … 1406 1469 for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) { 1407 1470 if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints 1408 Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl;1471 DoLog(1) && (Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl); 1409 1472 1410 1473 // first check direction, so that triangles don't intersect … … 1413 1476 VirtualNormalVector.ProjectOntoPlane(&NormalVector); 1414 1477 TempAngle = VirtualNormalVector.Angle(&PropagationVector); 1415 Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;1416 if (TempAngle > (M_PI /2.)) { // no bends bigger than Pi/2 (90 degrees)1417 Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;1478 DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl); 1479 if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees) 1480 DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl); 1418 1481 continue; 1419 1482 } else 1420 Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;1483 DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl); 1421 1484 1422 1485 // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle) … … 1424 1487 LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first); 1425 1488 if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) { 1426 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;1489 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); 1427 1490 continue; 1428 1491 } 1429 1492 if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) { 1430 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;1493 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); 1431 1494 continue; 1432 1495 } … … 1434 1497 // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint) 1435 1498 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)))) { 1436 Log() << Verbose(4) << "Current target is peak!" << endl;1499 DoLog(4) && (Log() << Verbose(4) << "Current target is peak!" << endl); 1437 1500 continue; 1438 1501 } … … 1445 1508 helper.ProjectOntoPlane(&TempVector); 1446 1509 if (fabs(helper.NormSquared()) < MYEPSILON) { 1447 Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl;1510 DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl); 1448 1511 continue; 1449 1512 } … … 1455 1518 TempVector.AddVector(baseline->second->endpoints[1]->node->node); 1456 1519 TempVector.AddVector(target->second->node->node); 1457 TempVector.Scale(1. /3.);1520 TempVector.Scale(1. / 3.); 1458 1521 TempVector.SubtractVector(Center); 1459 1522 // make it always point outward … … 1462 1525 // calculate angle 1463 1526 TempAngle = NormalVector.Angle(&VirtualNormalVector); 1464 Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;1527 DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl); 1465 1528 if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner 1466 1529 SmallestAngle = TempAngle; 1467 1530 winner = target; 1468 Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;1531 DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl); 1469 1532 } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle) 1470 1533 // hence, check the angles to some normal direction from our base line but in this common plane of both targets... … … 1484 1547 SmallestAngle = TempAngle; 1485 1548 winner = target; 1486 Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;1549 DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl); 1487 1550 } else 1488 Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;1551 DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl); 1489 1552 } else 1490 Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;1553 DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl); 1491 1554 } 1492 1555 } // end of loop over all boundary points … … 1494 1557 // 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 1495 1558 if (winner != PointsOnBoundary.end()) { 1496 Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;1559 DoLog(0) && (Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl); 1497 1560 // create the lins of not yet present 1498 1561 BLS[0] = baseline->second; … … 1524 1587 TrianglesOnBoundaryCount++; 1525 1588 } else { 1526 eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;1589 DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl); 1527 1590 } 1528 1591 1529 1592 // 5d. If the set of lines is not yet empty, go to 5. and continue 1530 1593 } else 1531 Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;1594 DoLog(0) && (Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl); 1532 1595 } while (flag); 1533 1596 1534 1597 // exit 1535 delete(Center); 1536 }; 1598 delete (Center); 1599 } 1600 ; 1537 1601 1538 1602 /** Inserts all points outside of the tesselated surface into it by adding new triangles. … … 1544 1608 bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC) 1545 1609 { 1546 1610 Info FunctionInfo(__func__); 1547 1611 Vector Intersection, Normal; 1548 1612 TesselPoint *Walker = NULL; … … 1554 1618 cloud->GoToFirst(); 1555 1619 BoundaryPoints = new LinkedCell(this, 5.); 1556 while (!cloud->IsEnd()) { 1620 while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger 1557 1621 if (AddFlag) { 1558 delete (BoundaryPoints);1622 delete (BoundaryPoints); 1559 1623 BoundaryPoints = new LinkedCell(this, 5.); 1560 1624 AddFlag = false; 1561 1625 } 1562 1626 Walker = cloud->GetPoint(); 1563 Log() << Verbose(0) << "Current point is " << *Walker << "." << endl;1627 DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Walker << "." << endl); 1564 1628 // get the next triangle 1565 1629 triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints); 1566 1630 BTS = triangles->front(); 1567 1631 if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) { 1568 Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl;1632 DoLog(0) && (Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl); 1569 1633 cloud->GoToNext(); 1570 1634 continue; 1571 1635 } else { 1572 1636 } 1573 Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl;1637 DoLog(0) && (Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl); 1574 1638 // get the intersection point 1575 1639 if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) { 1576 Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl;1640 DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl); 1577 1641 // we have the intersection, check whether in- or outside of boundary 1578 1642 if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) { 1579 1643 // inside, next! 1580 Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;1644 DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl); 1581 1645 } else { 1582 1646 // outside! 1583 Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;1647 DoLog(0) && (Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl); 1584 1648 class BoundaryLineSet *OldLines[3], *NewLines[3]; 1585 1649 class BoundaryPointSet *OldPoints[3], *NewPoint; 1586 1650 // store the three old lines and old points 1587 for (int i =0;i<3;i++) {1651 for (int i = 0; i < 3; i++) { 1588 1652 OldLines[i] = BTS->lines[i]; 1589 1653 OldPoints[i] = BTS->endpoints[i]; … … 1591 1655 Normal.CopyVector(&BTS->NormalVector); 1592 1656 // add Walker to boundary points 1593 Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl;1657 DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl); 1594 1658 AddFlag = true; 1595 if (AddBoundaryPoint(Walker, 0))1659 if (AddBoundaryPoint(Walker, 0)) 1596 1660 NewPoint = BPS[0]; 1597 1661 else 1598 1662 continue; 1599 1663 // remove triangle 1600 Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl;1664 DoLog(0) && (Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl); 1601 1665 TrianglesOnBoundary.erase(BTS->Nr); 1602 delete (BTS);1666 delete (BTS); 1603 1667 // create three new boundary lines 1604 for (int i =0;i<3;i++) {1668 for (int i = 0; i < 3; i++) { 1605 1669 BPS[0] = NewPoint; 1606 1670 BPS[1] = OldPoints[i]; 1607 1671 NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1608 Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl;1672 DoLog(1) && (Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl); 1609 1673 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one 1610 1674 LinesOnBoundaryCount++; 1611 1675 } 1612 1676 // create three new triangle with new point 1613 for (int i =0;i<3;i++) { // find all baselines1677 for (int i = 0; i < 3; i++) { // find all baselines 1614 1678 BLS[0] = OldLines[i]; 1615 1679 int n = 1; 1616 for (int j =0;j<3;j++) {1680 for (int j = 0; j < 3; j++) { 1617 1681 if (NewLines[j]->IsConnectedTo(BLS[0])) { 1618 if (n >2) {1619 eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl;1682 if (n > 2) { 1683 DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl); 1620 1684 return false; 1621 1685 } else … … 1628 1692 BTS->GetNormalVector(Normal); 1629 1693 Normal.Scale(-1.); 1630 Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl;1694 DoLog(0) && (Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl); 1631 1695 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); 1632 1696 TrianglesOnBoundaryCount++; … … 1634 1698 } 1635 1699 } else { // something is wrong with FindClosestTriangleToPoint! 1636 eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl;1700 DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl); 1637 1701 return false; 1638 1702 } … … 1641 1705 1642 1706 // exit 1643 delete (Center);1707 delete (Center); 1644 1708 return true; 1645 }; 1709 } 1710 ; 1646 1711 1647 1712 /** Adds a point to the tesselation::PointsOnBoundary list. … … 1652 1717 bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n) 1653 1718 { 1654 1719 Info FunctionInfo(__func__); 1655 1720 PointTestPair InsertUnique; 1656 1721 BPS[n] = new class BoundaryPointSet(Walker); … … 1660 1725 return true; 1661 1726 } else { 1662 delete (BPS[n]);1727 delete (BPS[n]); 1663 1728 BPS[n] = InsertUnique.first->second; 1664 1729 return false; … … 1674 1739 void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n) 1675 1740 { 1676 1741 Info FunctionInfo(__func__); 1677 1742 PointTestPair InsertUnique; 1678 1743 TPS[n] = new class BoundaryPointSet(Candidate); … … 1682 1747 } else { 1683 1748 delete TPS[n]; 1684 Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;1749 DoLog(0) && (Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl); 1685 1750 TPS[n] = (InsertUnique.first)->second; 1686 1751 } … … 1695 1760 void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const 1696 1761 { 1697 1762 Info FunctionInfo(__func__); 1698 1763 PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr); 1699 1764 if (FindPoint != PointsOnBoundary.end()) … … 1701 1766 else 1702 1767 TPS[n] = NULL; 1703 }; 1768 } 1769 ; 1704 1770 1705 1771 /** Function tries to add line from current Points in BPS to BoundaryLineSet. 1706 1772 * If successful it raises the line count and inserts the new line into the BLS, 1707 1773 * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one. 1774 * @param *OptCenter desired OptCenter if there are more than one candidate line 1775 * @param *candidate third point of the triangle to be, for checking between multiple open line candidates 1708 1776 * @param *a first endpoint 1709 1777 * @param *b second endpoint 1710 1778 * @param n index of Tesselation::BLS giving the line with both endpoints 1711 1779 */ 1712 void Tesselation::AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) { 1780 void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) 1781 { 1713 1782 bool insertNewLine = true; 1714 1715 1783 LineMap::iterator FindLine = a->lines.find(b->node->nr); 1784 BoundaryLineSet *WinningLine = NULL; 1716 1785 if (FindLine != a->lines.end()) { 1717 Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;1718 1719 pair<LineMap::iterator, LineMap::iterator> FindPair;1786 DoLog(1) && (Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl); 1787 1788 pair<LineMap::iterator, LineMap::iterator> FindPair; 1720 1789 FindPair = a->lines.equal_range(b->node->nr); 1721 1790 1722 for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) { 1791 for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) { 1792 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl); 1723 1793 // If there is a line with less than two attached triangles, we don't need a new line. 1724 if (FindLine->second->triangles.size() < 2) {1725 insertNewLine = false;1726 Log() << Verbose(0) << "Using existing line " << *FindLine->second << endl;1727 1728 BPS[0] = FindLine->second->endpoints[0];1729 BPS[1] = FindLine->second->endpoints[1];1730 BLS[n] = FindLine->second;1731 1732 // remove existing line from OpenLines1733 CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);1734 if (CandidateLine != OpenLines.end()) {1735 Log() << Verbose(1) << " Removing line from OpenLines." << endl;1736 delete(CandidateLine->second);1737 OpenLines.erase(CandidateLine);1738 } else {1739 eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl;1794 if (FindLine->second->triangles.size() == 1) { 1795 CandidateMap::iterator Finder = OpenLines.find(FindLine->second); 1796 if (!Finder->second->pointlist.empty()) 1797 DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl); 1798 else 1799 DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl); 1800 // get open line 1801 for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) { 1802 if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(&Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches 1803 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl); 1804 insertNewLine = false; 1805 WinningLine = FindLine->second; 1806 break; 1807 } else { 1808 DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << "." << endl); 1809 } 1740 1810 } 1741 1742 break;1743 1811 } 1744 1812 } … … 1746 1814 1747 1815 if (insertNewLine) { 1748 AlwaysAddTesselationTriangleLine(a, b, n); 1816 AddNewTesselationTriangleLine(a, b, n); 1817 } else { 1818 AddExistingTesselationTriangleLine(WinningLine, n); 1749 1819 } 1750 1820 } … … 1759 1829 * @param n index of Tesselation::BLS giving the line with both endpoints 1760 1830 */ 1761 void Tesselation::A lwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)1762 { 1763 1764 Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;1831 void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) 1832 { 1833 Info FunctionInfo(__func__); 1834 DoLog(0) && (Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl); 1765 1835 BPS[0] = a; 1766 1836 BPS[1] = b; 1767 BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1837 BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps 1768 1838 // add line to global map 1769 1839 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n])); … … 1772 1842 // also add to open lines 1773 1843 CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]); 1774 OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT)); 1775 }; 1844 OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT)); 1845 } 1846 ; 1847 1848 /** Uses an existing line for a new triangle. 1849 * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines. 1850 * \param *FindLine the line to add 1851 * \param n index of the line to set in Tesselation::BLS 1852 */ 1853 void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n) 1854 { 1855 Info FunctionInfo(__func__); 1856 DoLog(0) && (Log() << Verbose(0) << "Using existing line " << *Line << endl); 1857 1858 // set endpoints and line 1859 BPS[0] = Line->endpoints[0]; 1860 BPS[1] = Line->endpoints[1]; 1861 BLS[n] = Line; 1862 // remove existing line from OpenLines 1863 CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]); 1864 if (CandidateLine != OpenLines.end()) { 1865 DoLog(1) && (Log() << Verbose(1) << " Removing line from OpenLines." << endl); 1866 delete (CandidateLine->second); 1867 OpenLines.erase(CandidateLine); 1868 } else { 1869 DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl); 1870 } 1871 } 1872 ; 1776 1873 1777 1874 /** Function adds triangle to global list. … … 1780 1877 void Tesselation::AddTesselationTriangle() 1781 1878 { 1782 1783 Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;1879 Info FunctionInfo(__func__); 1880 DoLog(1) && (Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl); 1784 1881 1785 1882 // add triangle to global map … … 1791 1888 1792 1889 // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet 1793 }; 1890 } 1891 ; 1794 1892 1795 1893 /** Function adds triangle to global list. … … 1799 1897 void Tesselation::AddTesselationTriangle(const int nr) 1800 1898 { 1801 1802 Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl;1899 Info FunctionInfo(__func__); 1900 DoLog(0) && (Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl); 1803 1901 1804 1902 // add triangle to global map … … 1809 1907 1810 1908 // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet 1811 }; 1909 } 1910 ; 1812 1911 1813 1912 /** Removes a triangle from the tesselation. … … 1818 1917 void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle) 1819 1918 { 1820 1919 Info FunctionInfo(__func__); 1821 1920 if (triangle == NULL) 1822 1921 return; 1823 1922 for (int i = 0; i < 3; i++) { 1824 1923 if (triangle->lines[i] != NULL) { 1825 Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;1924 DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl); 1826 1925 triangle->lines[i]->triangles.erase(triangle->Nr); 1827 1926 if (triangle->lines[i]->triangles.empty()) { 1828 Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;1829 1927 DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl); 1928 RemoveTesselationLine(triangle->lines[i]); 1830 1929 } else { 1831 Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ";1832 OpenLines.insert(pair< 1833 for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)1834 Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";1835 Log() << Verbose(0) << endl;1836 // for (int j=0;j<2;j++) {1837 // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";1838 // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)1839 // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";1840 // Log() << Verbose(0) << endl;1841 // }1930 DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: "); 1931 OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL)); 1932 for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++) 1933 DoLog(0) && (Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t"); 1934 DoLog(0) && (Log() << Verbose(0) << endl); 1935 // for (int j=0;j<2;j++) { 1936 // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": "; 1937 // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++) 1938 // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t"; 1939 // Log() << Verbose(0) << endl; 1940 // } 1842 1941 } 1843 triangle->lines[i] = NULL; 1942 triangle->lines[i] = NULL; // free'd or not: disconnect 1844 1943 } else 1845 eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl;1944 DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl); 1846 1945 } 1847 1946 1848 1947 if (TrianglesOnBoundary.erase(triangle->Nr)) 1849 Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl; 1850 delete(triangle); 1851 }; 1948 DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl); 1949 delete (triangle); 1950 } 1951 ; 1852 1952 1853 1953 /** Removes a line from the tesselation. … … 1857 1957 void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line) 1858 1958 { 1859 1959 Info FunctionInfo(__func__); 1860 1960 int Numbers[2]; 1861 1961 … … 1878 1978 for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++) 1879 1979 if ((*Runner).second == line) { 1880 Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;1980 DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl); 1881 1981 line->endpoints[i]->lines.erase(Runner); 1882 1982 break; … … 1884 1984 } else { // there's just a single line left 1885 1985 if (line->endpoints[i]->lines.erase(line->Nr)) 1886 Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;1986 DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl); 1887 1987 } 1888 1988 if (line->endpoints[i]->lines.empty()) { 1889 Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;1989 DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl); 1890 1990 RemoveTesselationPoint(line->endpoints[i]); 1891 1991 } else { 1892 Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ";1893 for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)1894 Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";1895 Log() << Verbose(0) << endl;1992 DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: "); 1993 for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++) 1994 DoLog(0) && (Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t"); 1995 DoLog(0) && (Log() << Verbose(0) << endl); 1896 1996 } 1897 line->endpoints[i] = NULL; 1997 line->endpoints[i] = NULL; // free'd or not: disconnect 1898 1998 } else 1899 eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl;1999 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl); 1900 2000 } 1901 2001 if (!line->triangles.empty()) 1902 eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl;2002 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl); 1903 2003 1904 2004 if (LinesOnBoundary.erase(line->Nr)) 1905 Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl; 1906 delete(line); 1907 }; 2005 DoLog(0) && (Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl); 2006 delete (line); 2007 } 2008 ; 1908 2009 1909 2010 /** Removes a point from the tesselation. … … 1914 2015 void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point) 1915 2016 { 1916 2017 Info FunctionInfo(__func__); 1917 2018 if (point == NULL) 1918 2019 return; 1919 2020 if (PointsOnBoundary.erase(point->Nr)) 1920 Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl; 1921 delete(point); 1922 }; 2021 DoLog(0) && (Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl); 2022 delete (point); 2023 } 2024 ; 2025 2026 /** Checks validity of a given sphere of a candidate line. 2027 * \sa CandidateForTesselation::CheckValidity(), which is more evolved. 2028 * We check CandidateForTesselation::OtherOptCenter 2029 * \param &CandidateLine contains other degenerated candidates which we have to subtract as well 2030 * \param RADIUS radius of sphere 2031 * \param *LC LinkedCell structure with other atoms 2032 * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated 2033 */ 2034 bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const 2035 { 2036 Info FunctionInfo(__func__); 2037 2038 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl); 2039 bool flag = true; 2040 2041 DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter.x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl); 2042 // get all points inside the sphere 2043 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter); 2044 2045 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl); 2046 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2047 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl); 2048 2049 // remove triangles's endpoints 2050 for (int i = 0; i < 2; i++) 2051 ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node); 2052 2053 // remove other candidates 2054 for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner) 2055 ListofPoints->remove(*Runner); 2056 2057 // check for other points 2058 if (!ListofPoints->empty()) { 2059 DoLog(1) && (Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl); 2060 flag = false; 2061 DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl); 2062 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2063 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl); 2064 } 2065 delete (ListofPoints); 2066 2067 return flag; 2068 } 2069 ; 1923 2070 1924 2071 /** Checks whether the triangle consisting of the three points is already present. … … 1933 2080 int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const 1934 2081 { 1935 2082 Info FunctionInfo(__func__); 1936 2083 int adjacentTriangleCount = 0; 1937 2084 class BoundaryPointSet *Points[3]; … … 1955 2102 for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) { 1956 2103 TriangleMap *triangles = &FindLine->second->triangles; 1957 Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;2104 DoLog(1) && (Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl); 1958 2105 for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) { 1959 2106 if (FindTriangle->second->IsPresentTupel(Points)) { … … 1961 2108 } 1962 2109 } 1963 Log() << Verbose(1) << "end." << endl;2110 DoLog(1) && (Log() << Verbose(1) << "end." << endl); 1964 2111 } 1965 2112 // Only one of the triangle lines must be considered for the triangle count. … … 1971 2118 } 1972 2119 1973 Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;2120 DoLog(0) && (Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl); 1974 2121 return adjacentTriangleCount; 1975 }; 2122 } 2123 ; 1976 2124 1977 2125 /** Checks whether the triangle consisting of the three points is already present. … … 1985 2133 class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3]) 1986 2134 { 1987 2135 Info FunctionInfo(__func__); 1988 2136 class BoundaryTriangleSet *triangle = NULL; 1989 2137 class BoundaryPointSet *Points[3]; … … 2023 2171 2024 2172 return triangle; 2025 } ;2026 2173 } 2174 ; 2027 2175 2028 2176 /** Finds the starting triangle for FindNonConvexBorder(). … … 2033 2181 * \param RADIUS radius of virtual rolling sphere 2034 2182 * \param *LC LinkedCell structure with neighbouring TesselPoint's 2035 */ 2036 void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC) 2037 { 2038 Info FunctionInfo(__func__); 2183 * \return true - a starting triangle has been created, false - no valid triple of points found 2184 */ 2185 bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC) 2186 { 2187 Info FunctionInfo(__func__); 2039 2188 int i = 0; 2040 2189 TesselPoint* MaxPoint[NDIM]; 2041 2190 TesselPoint* Temporary; 2042 2191 double maxCoordinate[NDIM]; 2043 BoundaryLineSet BaseLine;2192 BoundaryLineSet *BaseLine = NULL; 2044 2193 Vector helper; 2045 2194 Vector Chord; 2046 2195 Vector SearchDirection; 2047 Vector CircleCenter; 2196 Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers 2048 2197 Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in 2049 2198 Vector SphereCenter; … … 2058 2207 2059 2208 // 1. searching topmost point with respect to each axis 2060 for (int i =0;i<NDIM;i++) { // each axis2061 LC->n[i] = LC->N[i] -1; // current axis is topmost cell2062 for (LC->n[(i +1)%NDIM]=0;LC->n[(i+1)%NDIM]<LC->N[(i+1)%NDIM];LC->n[(i+1)%NDIM]++)2063 for (LC->n[(i +2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {2064 const Linked Nodes *List = LC->GetCurrentCell();2209 for (int i = 0; i < NDIM; i++) { // each axis 2210 LC->n[i] = LC->N[i] - 1; // current axis is topmost cell 2211 for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++) 2212 for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) { 2213 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell(); 2065 2214 //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl; 2066 2215 if (List != NULL) { 2067 for (Linked Nodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {2216 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 2068 2217 if ((*Runner)->node->x[i] > maxCoordinate[i]) { 2069 Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;2218 DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl); 2070 2219 maxCoordinate[i] = (*Runner)->node->x[i]; 2071 2220 MaxPoint[i] = (*Runner); … … 2073 2222 } 2074 2223 } else { 2075 eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;2224 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl); 2076 2225 } 2077 2226 } 2078 2227 } 2079 2228 2080 Log() << Verbose(1) << "Found maximum coordinates: ";2081 for (int i =0;i<NDIM;i++)2082 Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";2083 Log() << Verbose(0) << endl;2229 DoLog(1) && (Log() << Verbose(1) << "Found maximum coordinates: "); 2230 for (int i = 0; i < NDIM; i++) 2231 DoLog(0) && (Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t"); 2232 DoLog(0) && (Log() << Verbose(0) << endl); 2084 2233 2085 2234 BTS = NULL; 2086 for (int k =0;k<NDIM;k++) {2235 for (int k = 0; k < NDIM; k++) { 2087 2236 NormalVector.Zero(); 2088 2237 NormalVector.x[k] = 1.; 2089 BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]); 2090 Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl; 2238 BaseLine = new BoundaryLineSet(); 2239 BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]); 2240 DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl); 2091 2241 2092 2242 double ShortestAngle; 2093 2243 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. 2094 2244 2095 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_... 2096 if (Temporary == NULL) // have we found a second point? 2245 Temporary = NULL; 2246 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_... 2247 if (Temporary == NULL) { 2248 // have we found a second point? 2249 delete BaseLine; 2097 2250 continue; 2098 BaseLine.endpoints[1] = new BoundaryPointSet(Temporary); 2251 } 2252 BaseLine->endpoints[1] = new BoundaryPointSet(Temporary); 2099 2253 2100 2254 // construct center of circle 2101 CircleCenter.CopyVector(BaseLine .endpoints[0]->node->node);2102 CircleCenter.AddVector(BaseLine .endpoints[1]->node->node);2255 CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node); 2256 CircleCenter.AddVector(BaseLine->endpoints[1]->node->node); 2103 2257 CircleCenter.Scale(0.5); 2104 2258 2105 2259 // construct normal vector of circle 2106 CirclePlaneNormal.CopyVector(BaseLine .endpoints[0]->node->node);2107 CirclePlaneNormal.SubtractVector(BaseLine .endpoints[1]->node->node);2260 CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node); 2261 CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node); 2108 2262 2109 2263 double radius = CirclePlaneNormal.NormSquared(); 2110 double CircleRadius = sqrt(RADIUS *RADIUS - radius/4.);2264 double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.); 2111 2265 2112 2266 NormalVector.ProjectOntoPlane(&CirclePlaneNormal); 2113 2267 NormalVector.Normalize(); 2114 ShortestAngle = 2. *M_PI; // This will indicate the quadrant.2268 ShortestAngle = 2. * M_PI; // This will indicate the quadrant. 2115 2269 2116 2270 SphereCenter.CopyVector(&NormalVector); … … 2120 2274 2121 2275 // look in one direction of baseline for initial candidate 2122 SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); 2276 SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ... 2123 2277 2124 2278 // adding point 1 and point 2 and add the line between them 2125 Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl;2126 Log() << Verbose(0) << "Found second point is at " << *BaseLine.endpoints[1]->node << ".\n";2279 DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl); 2280 DoLog(0) && (Log() << Verbose(0) << "Found second point is at " << *BaseLine->endpoints[1]->node << ".\n"); 2127 2281 2128 2282 //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n"; 2129 CandidateForTesselation OptCandidates( &BaseLine);2283 CandidateForTesselation OptCandidates(BaseLine); 2130 2284 FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC); 2131 Log() << Verbose(0) << "List of third Points is:" << endl;2285 DoLog(0) && (Log() << Verbose(0) << "List of third Points is:" << endl); 2132 2286 for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) { 2133 Log() << Verbose(0) << " " << *(*it) << endl; 2134 } 2135 2136 BTS = NULL; 2137 AddCandidateTriangle(OptCandidates); 2138 // delete(BaseLine.endpoints[0]); 2139 // delete(BaseLine.endpoints[1]); 2140 2141 if (BTS != NULL) // we have created one starting triangle 2287 DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl); 2288 } 2289 if (!OptCandidates.pointlist.empty()) { 2290 BTS = NULL; 2291 AddCandidatePolygon(OptCandidates, RADIUS, LC); 2292 } else { 2293 delete BaseLine; 2294 continue; 2295 } 2296 2297 if (BTS != NULL) { // we have created one starting triangle 2298 delete BaseLine; 2142 2299 break; 2143 else {2300 } else { 2144 2301 // remove all candidates from the list and then the list itself 2145 2302 OptCandidates.pointlist.clear(); 2146 2303 } 2147 } 2148 }; 2304 delete BaseLine; 2305 } 2306 2307 return (BTS != NULL); 2308 } 2309 ; 2149 2310 2150 2311 /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates. … … 2217 2378 // if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { 2218 2379 // // rotated the wrong way! 2219 // eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;2380 // DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl); 2220 2381 // } 2221 2382 // … … 2274 2435 // } 2275 2436 // } else { 2276 // eLog() << Verbose(2) << "Baseline is connected to two triangles already?" << endl;2437 // DoeLog(2) && (eLog()<< Verbose(2) << "Baseline is connected to two triangles already?" << endl); 2277 2438 // } 2278 2439 // } else { … … 2281 2442 // } 2282 2443 // } else { 2283 // eLog() << Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl;2444 // DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl); 2284 2445 // } 2285 2446 // … … 2295 2456 * @param *LC LinkedCell structure with neighbouring points 2296 2457 */ 2297 bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC) 2298 { 2299 Info FunctionInfo(__func__); 2300 bool result = true; 2301 2458 bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC) 2459 { 2460 Info FunctionInfo(__func__); 2302 2461 Vector CircleCenter; 2303 2462 Vector CirclePlaneNormal; … … 2305 2464 Vector SearchDirection; 2306 2465 Vector helper; 2307 TesselPoint *ThirdNode= NULL;2466 BoundaryPointSet *ThirdPoint = NULL; 2308 2467 LineMap::iterator testline; 2309 2468 double radius, CircleRadius; 2310 2469 2311 for (int i =0;i<3;i++)2312 if ((T.endpoints[i] ->node != CandidateLine.BaseLine->endpoints[0]->node) && (T.endpoints[i]->node != CandidateLine.BaseLine->endpoints[1]->node)) {2313 Third Node = T.endpoints[i]->node;2470 for (int i = 0; i < 3; i++) 2471 if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) { 2472 ThirdPoint = T.endpoints[i]; 2314 2473 break; 2315 2474 } 2316 Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdNode " << *ThirdNode << " of triangle " << T << "." << endl; 2475 DoLog(0) && (Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl); 2476 2477 CandidateLine.T = &T; 2317 2478 2318 2479 // construct center of circle … … 2327 2488 // calculate squared radius of circle 2328 2489 radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal); 2329 if (radius /4. < RADIUS*RADIUS) {2490 if (radius / 4. < RADIUS * RADIUS) { 2330 2491 // construct relative sphere center with now known CircleCenter 2331 2492 RelativeSphereCenter.CopyVector(&T.SphereCenter); 2332 2493 RelativeSphereCenter.SubtractVector(&CircleCenter); 2333 2494 2334 CircleRadius = RADIUS *RADIUS - radius/4.;2495 CircleRadius = RADIUS * RADIUS - radius / 4.; 2335 2496 CirclePlaneNormal.Normalize(); 2336 Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;2337 2338 Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl;2497 DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl); 2498 2499 DoLog(1) && (Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl); 2339 2500 2340 2501 // construct SearchDirection and an "outward pointer" 2341 2502 SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal); 2342 2503 helper.CopyVector(&CircleCenter); 2343 helper.SubtractVector(Third Node->node);2504 helper.SubtractVector(ThirdPoint->node->node); 2344 2505 if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2345 2506 SearchDirection.Scale(-1.); 2346 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;2507 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 2347 2508 if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { 2348 2509 // rotated the wrong way! 2349 eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;2510 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl); 2350 2511 } 2351 2512 2352 2513 // add third point 2353 FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, Third Node, RADIUS, LC);2514 FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC); 2354 2515 2355 2516 } else { 2356 Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl;2517 DoLog(0) && (Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl); 2357 2518 } 2358 2519 2359 2520 if (CandidateLine.pointlist.empty()) { 2360 eLog() << Verbose(2) << "Could not find a suitable candidate." << endl;2521 DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl); 2361 2522 return false; 2362 2523 } 2363 Log() << Verbose(0) << "Third Points are: " << endl;2524 DoLog(0) && (Log() << Verbose(0) << "Third Points are: " << endl); 2364 2525 for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) { 2365 Log() << Verbose(0) << " " << *(*it) << endl;2526 DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl); 2366 2527 } 2367 2528 2368 2529 return true; 2369 2370 // BoundaryLineSet *BaseRay = CandidateLine.BaseLine; 2371 // for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) { 2372 // Log() << Verbose(0) << "Third point candidate is " << *(*it)->point 2373 // << " with circumsphere's center at " << (*it)->OptCenter << "." << endl; 2374 // Log() << Verbose(0) << "Baseline is " << *BaseRay << endl; 2375 // 2376 // // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2) 2377 // TesselPoint *PointCandidates[3]; 2378 // PointCandidates[0] = (*it)->point; 2379 // PointCandidates[1] = BaseRay->endpoints[0]->node; 2380 // PointCandidates[2] = BaseRay->endpoints[1]->node; 2381 // int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates); 2382 // 2383 // BTS = NULL; 2384 // // check for present edges and whether we reach better candidates from them 2385 // //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) { 2386 // if (0) { 2387 // result = false; 2388 // break; 2389 // } else { 2390 // // If there is no triangle, add it regularly. 2391 // if (existentTrianglesCount == 0) { 2392 // AddTesselationPoint((*it)->point, 0); 2393 // AddTesselationPoint(BaseRay->endpoints[0]->node, 1); 2394 // AddTesselationPoint(BaseRay->endpoints[1]->node, 2); 2395 // 2396 // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) { 2397 // CandidateLine.point = (*it)->point; 2398 // CandidateLine.OptCenter.CopyVector(&((*it)->OptCenter)); 2399 // CandidateLine.OtherOptCenter.CopyVector(&((*it)->OtherOptCenter)); 2400 // CandidateLine.ShortestAngle = ShortestAngle; 2401 // } else { 2402 //// eLog() << Verbose(1) << "This triangle consisting of "; 2403 //// Log() << Verbose(0) << *(*it)->point << ", "; 2404 //// Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and "; 2405 //// Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " "; 2406 //// Log() << Verbose(0) << "exists and is not added, as it 0x80000000006fc150(does not seem helpful!" << endl; 2407 // result = false; 2408 // } 2409 // } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time. 2410 // AddTesselationPoint((*it)->point, 0); 2411 // AddTesselationPoint(BaseRay->endpoints[0]->node, 1); 2412 // AddTesselationPoint(BaseRay->endpoints[1]->node, 2); 2413 // 2414 // // 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) 2415 // // i.e. at least one of the three lines must be present with TriangleCount <= 1 2416 // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS) || CandidateLine.BaseLine->skipped) { 2417 // CandidateLine.point = (*it)->point; 2418 // CandidateLine.OptCenter.CopyVector(&(*it)->OptCenter); 2419 // CandidateLine.OtherOptCenter.CopyVector(&(*it)->OtherOptCenter); 2420 // CandidateLine.ShortestAngle = ShortestAngle+2.*M_PI; 2421 // 2422 // } else { 2423 //// eLog() << Verbose(1) << "This triangle consisting of " << *(*it)->point << ", " << *BaseRay->endpoints[0]->node << " and " << *BaseRay->endpoints[1]->node << " " << "exists and is not added, as it does not seem helpful!" << endl; 2424 // result = false; 2425 // } 2426 // } else { 2427 //// Log() << Verbose(1) << "This triangle consisting of "; 2428 //// Log() << Verbose(0) << *(*it)->point << ", "; 2429 //// Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and "; 2430 //// Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " "; 2431 //// Log() << Verbose(0) << "is invalid!" << endl; 2432 // result = false; 2433 // } 2434 // } 2435 // 2436 // // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point)) 2437 // BaseRay = BLS[0]; 2438 // if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) { 2439 // eLog() << Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl; 2440 // exit(255); 2441 // } 2442 // 2443 // } 2444 // 2445 // // remove all candidates from the list and then the list itself 2446 // class CandidateForTesselation *remover = NULL; 2447 // for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) { 2448 // remover = *it; 2449 // delete(remover); 2450 // } 2451 // delete(OptCandidates); 2452 return result; 2453 }; 2530 } 2531 ; 2532 2533 /** Walks through Tesselation::OpenLines() and finds candidates for newly created ones. 2534 * \param *&LCList atoms in LinkedCell list 2535 * \param RADIUS radius of the virtual sphere 2536 * \return true - for all open lines without candidates so far, a candidate has been found, 2537 * false - at least one open line without candidate still 2538 */ 2539 bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList) 2540 { 2541 bool TesselationFailFlag = true; 2542 CandidateForTesselation *baseline = NULL; 2543 BoundaryTriangleSet *T = NULL; 2544 2545 for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) { 2546 baseline = Runner->second; 2547 if (baseline->pointlist.empty()) { 2548 assert((baseline->BaseLine->triangles.size() == 1) && ("Open line without exactly one attached triangle")); 2549 T = (((baseline->BaseLine->triangles.begin()))->second); 2550 DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl); 2551 TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one. 2552 } 2553 } 2554 return TesselationFailFlag; 2555 } 2556 ; 2454 2557 2455 2558 /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation. 2456 2559 * \param CandidateLine triangle to add 2457 * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in AddTesselationLine() 2458 */ 2459 void Tesselation::AddCandidateTriangle(CandidateForTesselation CandidateLine) 2460 { 2461 Info FunctionInfo(__func__); 2560 * \param RADIUS Radius of sphere 2561 * \param *LC LinkedCell structure 2562 * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in 2563 * AddTesselationLine() in AddCandidateTriangle() 2564 */ 2565 void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC) 2566 { 2567 Info FunctionInfo(__func__); 2462 2568 Vector Center; 2463 2569 TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node; 2570 TesselPointList::iterator Runner; 2571 TesselPointList::iterator Sprinter; 2464 2572 2465 2573 // fill the set of neighbours … … 2470 2578 TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node); 2471 2579 2580 DoLog(0) && (Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl); 2581 for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner) 2582 DoLog(0) && (Log() << Verbose(0) << " " << **TesselRunner << endl); 2583 2472 2584 // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles) 2473 Log() << Verbose(0) << "List of Candidates for Turning Point: " << *TurningPoint << "." << endl; 2474 for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner) 2475 Log() << Verbose(0) << **TesselRunner << endl; 2476 TesselPointList::iterator Runner = connectedClosestPoints->begin(); 2477 TesselPointList::iterator Sprinter = Runner; 2585 Runner = connectedClosestPoints->begin(); 2586 Sprinter = Runner; 2478 2587 Sprinter++; 2479 while(Sprinter != connectedClosestPoints->end()) { 2480 // add the points 2588 while (Sprinter != connectedClosestPoints->end()) { 2589 DoLog(0) && (Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl); 2590 2481 2591 AddTesselationPoint(TurningPoint, 0); 2482 AddTesselationPoint((*Runner), 1); 2483 AddTesselationPoint((*Sprinter), 2); 2484 2485 // add the lines 2486 AddTesselationLine(TPS[0], TPS[1], 0); 2487 AddTesselationLine(TPS[0], TPS[2], 1); 2488 AddTesselationLine(TPS[1], TPS[2], 2); 2489 2490 // add the triangles 2491 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 2492 AddTesselationTriangle(); 2493 BTS->GetCenter(&Center); 2494 Center.SubtractVector(&CandidateLine.OptCenter); 2495 BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter); 2496 BTS->GetNormalVector(Center); 2497 2498 Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << "." << endl; 2592 AddTesselationPoint(*Runner, 1); 2593 AddTesselationPoint(*Sprinter, 2); 2594 2595 AddCandidateTriangle(CandidateLine, Opt); 2596 2499 2597 Runner = Sprinter; 2500 2598 Sprinter++; 2501 Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl; 2502 if (Sprinter != connectedClosestPoints->end()) 2503 Log() << Verbose(0) << " There are still more triangles to add." << endl; 2504 } 2505 delete(connectedClosestPoints); 2599 if (Sprinter != connectedClosestPoints->end()) { 2600 // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked) 2601 FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle 2602 DoLog(0) && (Log() << Verbose(0) << " There are still more triangles to add." << endl); 2603 } 2604 // pick candidates for other open lines as well 2605 FindCandidatesforOpenLines(RADIUS, LC); 2606 2607 // check whether we add a degenerate or a normal triangle 2608 if (CheckDegeneracy(CandidateLine, RADIUS, LC)) { 2609 // add normal and degenerate triangles 2610 DoLog(1) && (Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl); 2611 AddCandidateTriangle(CandidateLine, OtherOpt); 2612 2613 if (Sprinter != connectedClosestPoints->end()) { 2614 // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked) 2615 FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter); 2616 } 2617 // pick candidates for other open lines as well 2618 FindCandidatesforOpenLines(RADIUS, LC); 2619 } 2620 } 2621 delete (connectedClosestPoints); 2506 2622 }; 2623 2624 /** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate. 2625 * \param *Sprinter next candidate to which internal open lines are set 2626 * \param *OptCenter OptCenter for this candidate 2627 */ 2628 void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter) 2629 { 2630 Info FunctionInfo(__func__); 2631 2632 pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr); 2633 for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) { 2634 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl); 2635 // If there is a line with less than two attached triangles, we don't need a new line. 2636 if (FindLine->second->triangles.size() == 1) { 2637 CandidateMap::iterator Finder = OpenLines.find(FindLine->second); 2638 if (!Finder->second->pointlist.empty()) 2639 DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl); 2640 else { 2641 DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl); 2642 Finder->second->T = BTS; // is last triangle 2643 Finder->second->pointlist.push_back(Sprinter); 2644 Finder->second->ShortestAngle = 0.; 2645 Finder->second->OptCenter.CopyVector(OptCenter); 2646 } 2647 } 2648 } 2649 }; 2650 2651 /** If a given \a *triangle is degenerated, this adds both sides. 2652 * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction. 2653 * Note that endpoints are stored in Tesselation::TPS 2654 * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine 2655 * \param RADIUS radius of sphere 2656 * \param *LC pointer to LinkedCell structure 2657 */ 2658 void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) 2659 { 2660 Info FunctionInfo(__func__); 2661 Vector Center; 2662 CandidateMap::const_iterator CandidateCheck = OpenLines.end(); 2663 BoundaryTriangleSet *triangle = NULL; 2664 2665 /// 1. Create or pick the lines for the first triangle 2666 DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl); 2667 for (int i = 0; i < 3; i++) { 2668 BLS[i] = NULL; 2669 DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl); 2670 AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i); 2671 } 2672 2673 /// 2. create the first triangle and NormalVector and so on 2674 DoLog(0) && (Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl); 2675 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 2676 AddTesselationTriangle(); 2677 2678 // create normal vector 2679 BTS->GetCenter(&Center); 2680 Center.SubtractVector(&CandidateLine.OptCenter); 2681 BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter); 2682 BTS->GetNormalVector(Center); 2683 // give some verbose output about the whole procedure 2684 if (CandidateLine.T != NULL) 2685 DoLog(0) && (Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl); 2686 else 2687 DoLog(0) && (Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl); 2688 triangle = BTS; 2689 2690 /// 3. Gather candidates for each new line 2691 DoLog(0) && (Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl); 2692 for (int i = 0; i < 3; i++) { 2693 DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl); 2694 CandidateCheck = OpenLines.find(BLS[i]); 2695 if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) { 2696 if (CandidateCheck->second->T == NULL) 2697 CandidateCheck->second->T = triangle; 2698 FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC); 2699 } 2700 } 2701 2702 /// 4. Create or pick the lines for the second triangle 2703 DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl); 2704 for (int i = 0; i < 3; i++) { 2705 DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl); 2706 AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i); 2707 } 2708 2709 /// 5. create the second triangle and NormalVector and so on 2710 DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl); 2711 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 2712 AddTesselationTriangle(); 2713 2714 BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter); 2715 // create normal vector in other direction 2716 BTS->GetNormalVector(&triangle->NormalVector); 2717 BTS->NormalVector.Scale(-1.); 2718 // give some verbose output about the whole procedure 2719 if (CandidateLine.T != NULL) 2720 DoLog(0) && (Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl); 2721 else 2722 DoLog(0) && (Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl); 2723 2724 /// 6. Adding triangle to new lines 2725 DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl); 2726 for (int i = 0; i < 3; i++) { 2727 DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl); 2728 CandidateCheck = OpenLines.find(BLS[i]); 2729 if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) { 2730 if (CandidateCheck->second->T == NULL) 2731 CandidateCheck->second->T = BTS; 2732 } 2733 } 2734 } 2735 ; 2736 2737 /** Adds a triangle to the Tesselation structure from three given TesselPoint's. 2738 * Note that endpoints are in Tesselation::TPS. 2739 * \param CandidateLine CandidateForTesselation structure contains other information 2740 * \param type which opt center to add (i.e. which side) and thus which NormalVector to take 2741 */ 2742 void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type) 2743 { 2744 Info FunctionInfo(__func__); 2745 Vector Center; 2746 Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter; 2747 2748 // add the lines 2749 AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0); 2750 AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1); 2751 AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2); 2752 2753 // add the triangles 2754 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 2755 AddTesselationTriangle(); 2756 2757 // create normal vector 2758 BTS->GetCenter(&Center); 2759 Center.SubtractVector(OptCenter); 2760 BTS->SphereCenter.CopyVector(OptCenter); 2761 BTS->GetNormalVector(Center); 2762 2763 // give some verbose output about the whole procedure 2764 if (CandidateLine.T != NULL) 2765 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); 2766 else 2767 DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl); 2768 } 2769 ; 2507 2770 2508 2771 /** Checks whether the quadragon of the two triangles connect to \a *Base is convex. … … 2515 2778 class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base) 2516 2779 { 2517 2780 Info FunctionInfo(__func__); 2518 2781 class BoundaryPointSet *Spot = NULL; 2519 2782 class BoundaryLineSet *OtherBase; 2520 2783 Vector *ClosestPoint; 2521 2784 2522 int m =0;2523 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2524 for (int j =0;j<3;j++) // all of their endpoints and baselines2785 int m = 0; 2786 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2787 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2525 2788 if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints 2526 2789 BPS[m++] = runner->second->endpoints[j]; 2527 OtherBase = new class BoundaryLineSet(BPS, -1);2528 2529 Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl;2530 Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl;2790 OtherBase = new class BoundaryLineSet(BPS, -1); 2791 2792 DoLog(1) && (Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl); 2793 DoLog(1) && (Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl); 2531 2794 2532 2795 // get the closest point on each line to the other line … … 2534 2797 2535 2798 // delete the temporary other base line 2536 delete (OtherBase);2799 delete (OtherBase); 2537 2800 2538 2801 // get the distance vector from Base line to OtherBase line … … 2541 2804 BaseLine.CopyVector(Base->endpoints[1]->node->node); 2542 2805 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 2543 for (int i =0;i<2;i++) {2806 for (int i = 0; i < 2; i++) { 2544 2807 DistanceToIntersection[i].CopyVector(ClosestPoint); 2545 2808 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 2546 2809 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 2547 2810 } 2548 delete (ClosestPoint);2549 if ((distance[0] * distance[1]) > 0) 2550 Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl;2811 delete (ClosestPoint); 2812 if ((distance[0] * distance[1]) > 0) { // have same sign? 2813 DoLog(1) && (Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl); 2551 2814 if (distance[0] < distance[1]) { 2552 2815 Spot = Base->endpoints[0]; … … 2555 2818 } 2556 2819 return Spot; 2557 } else { 2558 Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;2820 } else { // different sign, i.e. we are in between 2821 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl); 2559 2822 return NULL; 2560 2823 } 2561 2824 2562 }; 2825 } 2826 ; 2563 2827 2564 2828 void Tesselation::PrintAllBoundaryPoints(ofstream *out) const 2565 2829 { 2566 2830 Info FunctionInfo(__func__); 2567 2831 // print all lines 2568 Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl; 2569 for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++) 2570 Log() << Verbose(0) << *(PointRunner->second) << endl; 2571 }; 2832 DoLog(0) && (Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl); 2833 for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++) 2834 DoLog(0) && (Log() << Verbose(0) << *(PointRunner->second) << endl); 2835 } 2836 ; 2572 2837 2573 2838 void Tesselation::PrintAllBoundaryLines(ofstream *out) const 2574 2839 { 2575 2840 Info FunctionInfo(__func__); 2576 2841 // print all lines 2577 Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl;2842 DoLog(0) && (Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl); 2578 2843 for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) 2579 Log() << Verbose(0) << *(LineRunner->second) << endl; 2580 }; 2844 DoLog(0) && (Log() << Verbose(0) << *(LineRunner->second) << endl); 2845 } 2846 ; 2581 2847 2582 2848 void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const 2583 2849 { 2584 2850 Info FunctionInfo(__func__); 2585 2851 // print all triangles 2586 Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl;2852 DoLog(0) && (Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl); 2587 2853 for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++) 2588 Log() << Verbose(0) << *(TriangleRunner->second) << endl; 2589 }; 2854 DoLog(0) && (Log() << Verbose(0) << *(TriangleRunner->second) << endl); 2855 } 2856 ; 2590 2857 2591 2858 /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher". … … 2596 2863 double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base) 2597 2864 { 2598 2865 Info FunctionInfo(__func__); 2599 2866 class BoundaryLineSet *OtherBase; 2600 2867 Vector *ClosestPoint[2]; 2601 2868 double volume; 2602 2869 2603 int m =0;2604 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2605 for (int j =0;j<3;j++) // all of their endpoints and baselines2870 int m = 0; 2871 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2872 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2606 2873 if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints 2607 2874 BPS[m++] = runner->second->endpoints[j]; 2608 OtherBase = new class BoundaryLineSet(BPS, -1);2609 2610 Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl;2611 Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl;2875 OtherBase = new class BoundaryLineSet(BPS, -1); 2876 2877 DoLog(0) && (Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl); 2878 DoLog(0) && (Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl); 2612 2879 2613 2880 // get the closest point on each line to the other line … … 2624 2891 2625 2892 // delete the temporary other base line and the closest points 2626 delete (ClosestPoint[0]);2627 delete (ClosestPoint[1]);2628 delete (OtherBase);2893 delete (ClosestPoint[0]); 2894 delete (ClosestPoint[1]); 2895 delete (OtherBase); 2629 2896 2630 2897 if (Distance.NormSquared() < MYEPSILON) { // check for intersection 2631 Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl;2898 DoLog(0) && (Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl); 2632 2899 return false; 2633 2900 } else { // check for sign against BaseLineNormal … … 2635 2902 BaseLineNormal.Zero(); 2636 2903 if (Base->triangles.size() < 2) { 2637 eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;2904 DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl); 2638 2905 return 0.; 2639 2906 } 2640 2907 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2641 Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;2908 DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl); 2642 2909 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 2643 2910 } 2644 BaseLineNormal.Scale(1. /2.);2911 BaseLineNormal.Scale(1. / 2.); 2645 2912 2646 2913 if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip 2647 Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;2914 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl); 2648 2915 // calculate volume summand as a general tetraeder 2649 2916 return volume; 2650 } else { 2651 Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl;2917 } else { // Base higher than OtherBase -> do nothing 2918 DoLog(0) && (Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl); 2652 2919 return 0.; 2653 2920 } 2654 2921 } 2655 }; 2922 } 2923 ; 2656 2924 2657 2925 /** For a given baseline and its two connected triangles, flips the baseline. … … 2664 2932 class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base) 2665 2933 { 2666 2934 Info FunctionInfo(__func__); 2667 2935 class BoundaryLineSet *OldLines[4], *NewLine; 2668 2936 class BoundaryPointSet *OldPoints[2]; 2669 2937 Vector BaseLineNormal; 2670 2938 int OldTriangleNrs[2], OldBaseLineNr; 2671 int i, m;2939 int i, m; 2672 2940 2673 2941 // calculate NormalVector for later use 2674 2942 BaseLineNormal.Zero(); 2675 2943 if (Base->triangles.size() < 2) { 2676 eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl;2944 DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl); 2677 2945 return NULL; 2678 2946 } 2679 2947 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2680 Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;2948 DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl); 2681 2949 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 2682 2950 } 2683 BaseLineNormal.Scale(-1. /2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()2951 BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector() 2684 2952 2685 2953 // get the two triangles 2686 2954 // gather four endpoints and four lines 2687 for (int j =0;j<4;j++)2955 for (int j = 0; j < 4; j++) 2688 2956 OldLines[j] = NULL; 2689 for (int j =0;j<2;j++)2957 for (int j = 0; j < 2; j++) 2690 2958 OldPoints[j] = NULL; 2691 i =0;2692 m =0;2693 Log() << Verbose(0) << "The four old lines are: ";2694 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2695 for (int j =0;j<3;j++) // all of their endpoints and baselines2959 i = 0; 2960 m = 0; 2961 DoLog(0) && (Log() << Verbose(0) << "The four old lines are: "); 2962 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2963 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2696 2964 if (runner->second->lines[j] != Base) { // pick not the central baseline 2697 2965 OldLines[i++] = runner->second->lines[j]; 2698 Log() << Verbose(0) << *runner->second->lines[j] << "\t";2966 DoLog(0) && (Log() << Verbose(0) << *runner->second->lines[j] << "\t"); 2699 2967 } 2700 Log() << Verbose(0) << endl;2701 Log() << Verbose(0) << "The two old points are: ";2702 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2703 for (int j =0;j<3;j++) // all of their endpoints and baselines2968 DoLog(0) && (Log() << Verbose(0) << endl); 2969 DoLog(0) && (Log() << Verbose(0) << "The two old points are: "); 2970 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2971 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2704 2972 if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints 2705 2973 OldPoints[m++] = runner->second->endpoints[j]; 2706 Log() << Verbose(0) << *runner->second->endpoints[j] << "\t";2974 DoLog(0) && (Log() << Verbose(0) << *runner->second->endpoints[j] << "\t"); 2707 2975 } 2708 Log() << Verbose(0) << endl;2976 DoLog(0) && (Log() << Verbose(0) << endl); 2709 2977 2710 2978 // check whether everything is in place to create new lines and triangles 2711 if (i <4) {2712 eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;2979 if (i < 4) { 2980 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl); 2713 2981 return NULL; 2714 2982 } 2715 for (int j =0;j<4;j++)2983 for (int j = 0; j < 4; j++) 2716 2984 if (OldLines[j] == NULL) { 2717 eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl;2985 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl); 2718 2986 return NULL; 2719 2987 } 2720 for (int j =0;j<2;j++)2988 for (int j = 0; j < 2; j++) 2721 2989 if (OldPoints[j] == NULL) { 2722 eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl;2990 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl); 2723 2991 return NULL; 2724 2992 } 2725 2993 2726 2994 // remove triangles and baseline removes itself 2727 Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl;2995 DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl); 2728 2996 OldBaseLineNr = Base->Nr; 2729 m =0;2730 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {2731 Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;2997 m = 0; 2998 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2999 DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl); 2732 3000 OldTriangleNrs[m++] = runner->second->Nr; 2733 3001 RemoveTesselationTriangle(runner->second); … … 2739 3007 NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr); 2740 3008 LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one 2741 Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl;3009 DoLog(0) && (Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl); 2742 3010 2743 3011 // construct new triangles with flipped baseline 2744 i =-1;3012 i = -1; 2745 3013 if (OldLines[0]->IsConnectedTo(OldLines[2])) 2746 i =2;3014 i = 2; 2747 3015 if (OldLines[0]->IsConnectedTo(OldLines[3])) 2748 i =3;2749 if (i !=-1) {3016 i = 3; 3017 if (i != -1) { 2750 3018 BLS[0] = OldLines[0]; 2751 3019 BLS[1] = OldLines[i]; … … 2754 3022 BTS->GetNormalVector(BaseLineNormal); 2755 3023 AddTesselationTriangle(OldTriangleNrs[0]); 2756 Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;2757 2758 BLS[0] = (i ==2 ? OldLines[3] : OldLines[2]);3024 DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl); 3025 3026 BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]); 2759 3027 BLS[1] = OldLines[1]; 2760 3028 BLS[2] = NewLine; … … 2762 3030 BTS->GetNormalVector(BaseLineNormal); 2763 3031 AddTesselationTriangle(OldTriangleNrs[1]); 2764 Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl;3032 DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl); 2765 3033 } else { 2766 eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl;3034 DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl); 2767 3035 return NULL; 2768 3036 } 2769 3037 2770 3038 return NewLine; 2771 } ;2772 3039 } 3040 ; 2773 3041 2774 3042 /** Finds the second point of starting triangle. … … 2782 3050 void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC) 2783 3051 { 2784 3052 Info FunctionInfo(__func__); 2785 3053 Vector AngleCheck; 2786 3054 class TesselPoint* Candidate = NULL; … … 2791 3059 int Nupper[NDIM]; 2792 3060 2793 if (LC->SetIndexToNode(a)) { 2794 for (int i=0;i<NDIM;i++) // store indices of this cell3061 if (LC->SetIndexToNode(a)) { // get cell for the starting point 3062 for (int i = 0; i < NDIM; i++) // store indices of this cell 2795 3063 N[i] = LC->n[i]; 2796 3064 } else { 2797 eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl;3065 DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl); 2798 3066 return; 2799 3067 } 2800 3068 // then go through the current and all neighbouring cells and check the contained points for possible candidates 2801 for (int i=0;i<NDIM;i++) { 2802 Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0; 2803 Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1; 2804 } 2805 Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :" 2806 << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl; 3069 for (int i = 0; i < NDIM; i++) { 3070 Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0; 3071 Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1; 3072 } 3073 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); 2807 3074 2808 3075 for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++) 2809 3076 for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++) 2810 3077 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) { 2811 const Linked Nodes *List = LC->GetCurrentCell();3078 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell(); 2812 3079 //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl; 2813 3080 if (List != NULL) { 2814 for (Linked Nodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {3081 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 2815 3082 Candidate = (*Runner); 2816 3083 // check if we only have one unique point yet ... … … 2838 3105 norm = aCandidate.Norm(); 2839 3106 // second point shall have smallest angle with respect to Oben vector 2840 if (norm < RADIUS *2.) {3107 if (norm < RADIUS * 2.) { 2841 3108 angle = AngleCheck.Angle(&Oben); 2842 3109 if (angle < Storage[0]) { 2843 3110 //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]); 2844 Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";3111 DoLog(1) && (Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n"); 2845 3112 OptCandidate = Candidate; 2846 3113 Storage[0] = angle; … … 2857 3124 } 2858 3125 } else { 2859 Log() << Verbose(0) << "Linked cell list is empty." << endl;3126 DoLog(0) && (Log() << Verbose(0) << "Linked cell list is empty." << endl); 2860 3127 } 2861 3128 } 2862 } ;2863 3129 } 3130 ; 2864 3131 2865 3132 /** This recursive function finds a third point, to form a triangle with two given ones. … … 2889 3156 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle 2890 3157 * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle 2891 * @param Third Nodethird point to avoid in search3158 * @param ThirdPoint third point to avoid in search 2892 3159 * @param RADIUS radius of sphere 2893 3160 * @param *LC LinkedCell structure with neighbouring points 2894 3161 */ 2895 void Tesselation::FindThirdPointForTesselation( Vector &NormalVector, Vector &SearchDirection, Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class TesselPoint * const ThirdNode, const double RADIUS, const LinkedCell *LC) const2896 { 2897 2898 Vector CircleCenter; 3162 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 3163 { 3164 Info FunctionInfo(__func__); 3165 Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers 2899 3166 Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in 2900 3167 Vector SphereCenter; 2901 Vector NewSphereCenter; 2902 Vector OtherNewSphereCenter; 2903 Vector NewNormalVector; 3168 Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility 3169 Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility 3170 Vector NewNormalVector; // normal vector of the Candidate's triangle 2904 3171 Vector helper, OptCandidateCenter, OtherOptCandidateCenter; 2905 3172 Vector RelativeOldSphereCenter; … … 2912 3179 TesselPoint *Candidate = NULL; 2913 3180 2914 Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl; 3181 DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl); 3182 3183 // copy old center 3184 CandidateLine.OldCenter.CopyVector(&OldSphereCenter); 3185 CandidateLine.ThirdPoint = ThirdPoint; 3186 CandidateLine.pointlist.clear(); 2915 3187 2916 3188 // construct center of circle … … 2926 3198 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 2927 3199 2928 // calculate squared radius TesselPoint *Third Node,f circle2929 radius = CirclePlaneNormal.NormSquared() /4.;2930 if (radius < RADIUS *RADIUS) {2931 CircleRadius = RADIUS *RADIUS - radius;3200 // calculate squared radius TesselPoint *ThirdPoint,f circle 3201 radius = CirclePlaneNormal.NormSquared() / 4.; 3202 if (radius < RADIUS * RADIUS) { 3203 CircleRadius = RADIUS * RADIUS - radius; 2932 3204 CirclePlaneNormal.Normalize(); 2933 Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;3205 DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl); 2934 3206 2935 3207 // test whether old center is on the band's plane 2936 3208 if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) { 2937 eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;3209 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); 2938 3210 RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal); 2939 3211 } 2940 3212 radius = RelativeOldSphereCenter.NormSquared(); 2941 3213 if (fabs(radius - CircleRadius) < HULLEPSILON) { 2942 Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl;3214 DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl); 2943 3215 2944 3216 // check SearchDirection 2945 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;2946 if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { 2947 eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;3217 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 3218 if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way! 3219 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl); 2948 3220 } 2949 3221 2950 3222 // get cell for the starting point 2951 3223 if (LC->SetIndexToVector(&CircleCenter)) { 2952 for (int i=0;i<NDIM;i++) // store indices of this cell2953 N[i] = LC->n[i];3224 for (int i = 0; i < NDIM; i++) // store indices of this cell 3225 N[i] = LC->n[i]; 2954 3226 //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl; 2955 3227 } else { 2956 eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;3228 DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl); 2957 3229 return; 2958 3230 } 2959 3231 // then go through the current and all neighbouring cells and check the contained points for possible candidates 2960 3232 //Log() << Verbose(1) << "LC Intervals:"; 2961 for (int i =0;i<NDIM;i++) {2962 Nlower[i] = ((N[i] -1) >= 0) ? N[i]-1 : 0;2963 Nupper[i] = ((N[i] +1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;3233 for (int i = 0; i < NDIM; i++) { 3234 Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0; 3235 Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1; 2964 3236 //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] "; 2965 3237 } … … 2968 3240 for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++) 2969 3241 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) { 2970 const Linked Nodes *List = LC->GetCurrentCell();3242 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell(); 2971 3243 //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl; 2972 3244 if (List != NULL) { 2973 for (Linked Nodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {3245 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 2974 3246 Candidate = (*Runner); 2975 3247 2976 3248 // check for three unique points 2977 Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl;2978 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){3249 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl); 3250 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) { 2979 3251 2980 3252 // find center on the plane 2981 3253 GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node); 2982 Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl; 2983 2984 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) 2985 && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON) 2986 ) { 2987 Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl; 3254 DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl); 3255 3256 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) { 3257 DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl); 2988 3258 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter); 2989 Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;2990 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;2991 Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl;2992 if (radius < RADIUS *RADIUS) {3259 DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl); 3260 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 3261 DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl); 3262 if (radius < RADIUS * RADIUS) { 2993 3263 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter); 2994 if (fabs(radius - otherradius) > HULLEPSILON) { 2995 eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl; 2996 } 2997 // construct both new centers 2998 NewSphereCenter.CopyVector(&NewPlaneCenter); 2999 OtherNewSphereCenter.CopyVector(&NewPlaneCenter); 3000 helper.CopyVector(&NewNormalVector); 3001 helper.Scale(sqrt(RADIUS*RADIUS - radius)); 3002 Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl; 3003 NewSphereCenter.AddVector(&helper); 3004 Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl; 3005 // OtherNewSphereCenter is created by the same vector just in the other direction 3006 helper.Scale(-1.); 3007 OtherNewSphereCenter.AddVector(&helper); 3008 Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl; 3009 3010 alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3011 Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3012 alpha = min(alpha, Otheralpha); 3013 3014 // if there is a better candidate, drop the current list and add the new candidate 3015 // otherwise ignore the new candidate and keep the list 3016 if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) { 3017 if (fabs(alpha - Otheralpha) > MYEPSILON) { 3018 CandidateLine.OptCenter.CopyVector(&NewSphereCenter); 3019 CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter); 3264 if (fabs(radius - otherradius) < HULLEPSILON) { 3265 // construct both new centers 3266 NewSphereCenter.CopyVector(&NewPlaneCenter); 3267 OtherNewSphereCenter.CopyVector(&NewPlaneCenter); 3268 helper.CopyVector(&NewNormalVector); 3269 helper.Scale(sqrt(RADIUS * RADIUS - radius)); 3270 DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl); 3271 NewSphereCenter.AddVector(&helper); 3272 DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl); 3273 // OtherNewSphereCenter is created by the same vector just in the other direction 3274 helper.Scale(-1.); 3275 OtherNewSphereCenter.AddVector(&helper); 3276 DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl); 3277 3278 alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3279 Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3280 if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid 3281 if (OldSphereCenter.DistanceSquared(&NewSphereCenter) < OldSphereCenter.DistanceSquared(&OtherNewSphereCenter)) 3282 alpha = Otheralpha; 3283 } else 3284 alpha = min(alpha, Otheralpha); 3285 3286 // if there is a better candidate, drop the current list and add the new candidate 3287 // otherwise ignore the new candidate and keep the list 3288 if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) { 3289 if (fabs(alpha - Otheralpha) > MYEPSILON) { 3290 CandidateLine.OptCenter.CopyVector(&NewSphereCenter); 3291 CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter); 3292 } else { 3293 CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter); 3294 CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter); 3295 } 3296 // if there is an equal candidate, add it to the list without clearing the list 3297 if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) { 3298 CandidateLine.pointlist.push_back(Candidate); 3299 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl); 3300 } else { 3301 // remove all candidates from the list and then the list itself 3302 CandidateLine.pointlist.clear(); 3303 CandidateLine.pointlist.push_back(Candidate); 3304 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl); 3305 } 3306 CandidateLine.ShortestAngle = alpha; 3307 DoLog(0) && (Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl); 3020 3308 } else { 3021 CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter); 3022 CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter); 3309 if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) { 3310 DoLog(1) && (Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl); 3311 } else { 3312 DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl); 3313 } 3023 3314 } 3024 // if there is an equal candidate, add it to the list without clearing the list3025 if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {3026 CandidateLine.pointlist.push_back(Candidate);3027 Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with "3028 << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;3029 } else {3030 // remove all candidates from the list and then the list itself3031 CandidateLine.pointlist.clear();3032 CandidateLine.pointlist.push_back(Candidate);3033 Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with "3034 << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl;3035 }3036 CandidateLine.ShortestAngle = alpha;3037 Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl;3038 3315 } else { 3039 if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) { 3040 Log() << Verbose(1) << "REJECT: Old candidate " << *(Candidate) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl; 3041 } else { 3042 Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl; 3043 } 3316 DoLog(1) && (Log() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl); 3044 3317 } 3045 3318 } else { 3046 Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;3319 DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl); 3047 3320 } 3048 3321 } else { 3049 Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;3322 DoLog(1) && (Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl); 3050 3323 } 3051 3324 } else { 3052 if (Third Node!= NULL) {3053 Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;3325 if (ThirdPoint != NULL) { 3326 DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl); 3054 3327 } else { 3055 Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl;3328 DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl); 3056 3329 } 3057 3330 } … … 3060 3333 } 3061 3334 } else { 3062 eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;3335 DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl); 3063 3336 } 3064 3337 } else { 3065 if (Third Node!= NULL)3066 Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;3338 if (ThirdPoint != NULL) 3339 DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl); 3067 3340 else 3068 Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl;3069 } 3070 3071 Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl;3341 DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl); 3342 } 3343 3344 DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl); 3072 3345 if (CandidateLine.pointlist.size() > 1) { 3073 3346 CandidateLine.pointlist.unique(); 3074 3347 CandidateLine.pointlist.sort(); //SortCandidates); 3075 3348 } 3076 }; 3349 3350 if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) { 3351 DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl); 3352 performCriticalExit(); 3353 } 3354 } 3355 ; 3077 3356 3078 3357 /** Finds the endpoint two lines are sharing. … … 3083 3362 class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const 3084 3363 { 3085 3364 Info FunctionInfo(__func__); 3086 3365 const BoundaryLineSet * lines[2] = { line1, line2 }; 3087 3366 class BoundaryPointSet *node = NULL; … … 3090 3369 for (int i = 0; i < 2; i++) 3091 3370 // for both lines 3092 for (int j = 0; j < 2; j++) 3093 { // for both endpoints 3094 OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> ( 3095 lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j])); 3096 if (!OrderTest.second) 3097 { // if insertion fails, we have common endpoint 3098 node = OrderTest.first->second; 3099 Log() << Verbose(1) << "Common endpoint of lines " << *line1 3100 << " and " << *line2 << " is: " << *node << "." << endl; 3101 j = 2; 3102 i = 2; 3103 break; 3104 } 3371 for (int j = 0; j < 2; j++) { // for both endpoints 3372 OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j])); 3373 if (!OrderTest.second) { // if insertion fails, we have common endpoint 3374 node = OrderTest.first->second; 3375 DoLog(1) && (Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl); 3376 j = 2; 3377 i = 2; 3378 break; 3105 3379 } 3380 } 3106 3381 return node; 3107 }; 3382 } 3383 ; 3108 3384 3109 3385 /** Finds the boundary points that are closest to a given Vector \a *x. … … 3119 3395 3120 3396 if (LinesOnBoundary.empty()) { 3121 eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl;3397 DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl); 3122 3398 return NULL; 3123 3399 } … … 3125 3401 // gather all points close to the desired one 3126 3402 LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly 3127 for (int i=0;i<NDIM;i++) // store indices of this cell3403 for (int i = 0; i < NDIM; i++) // store indices of this cell 3128 3404 N[i] = LC->n[i]; 3129 Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl; 3130 3405 DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl); 3131 3406 DistanceToPointMap * points = new DistanceToPointMap; 3132 3407 LC->GetNeighbourBounds(Nlower, Nupper); … … 3135 3410 for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++) 3136 3411 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) { 3137 const Linked Nodes *List = LC->GetCurrentCell();3412 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell(); 3138 3413 //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl; 3139 3414 if (List != NULL) { 3140 for (Linked Nodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {3415 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 3141 3416 FindPoint = PointsOnBoundary.find((*Runner)->nr); 3142 3417 if (FindPoint != PointsOnBoundary.end()) { 3143 points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second));3144 Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl;3418 points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(x), FindPoint->second)); 3419 DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl); 3145 3420 } 3146 3421 } 3147 3422 } else { 3148 eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;3423 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl); 3149 3424 } 3150 3425 } … … 3152 3427 // check whether we found some points 3153 3428 if (points->empty()) { 3154 eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;3155 delete (points);3429 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl); 3430 delete (points); 3156 3431 return NULL; 3157 3432 } 3158 3433 return points; 3159 }; 3434 } 3435 ; 3160 3436 3161 3437 /** Finds the boundary line that is closest to a given Vector \a *x. … … 3167 3443 { 3168 3444 Info FunctionInfo(__func__); 3169 3170 3445 // get closest points 3171 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);3446 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC); 3172 3447 if (points == NULL) { 3173 eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;3448 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl); 3174 3449 return NULL; 3175 3450 } 3176 3451 3177 3452 // for each point, check its lines, remember closest 3178 Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl;3453 DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl); 3179 3454 BoundaryLineSet *ClosestLine = NULL; 3180 3455 double MinDistance = -1.; … … 3204 3479 helper.SubtractVector(&Center); 3205 3480 const double lengthB = helper.ScalarProduct(&BaseLine); 3206 if (lengthB *lengthA < 0) {// if have different sign3481 if (lengthB * lengthA < 0) { // if have different sign 3207 3482 ClosestLine = LineRunner->second; 3208 3483 MinDistance = distance; 3209 Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl;3484 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl); 3210 3485 } else { 3211 Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl;3486 DoLog(1) && (Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl); 3212 3487 } 3213 3488 } else { 3214 Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl;3489 DoLog(1) && (Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl); 3215 3490 } 3216 3491 } 3217 3492 } 3218 delete (points);3493 delete (points); 3219 3494 // check whether closest line is "too close" :), then it's inside 3220 3495 if (ClosestLine == NULL) { 3221 Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;3496 DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl); 3222 3497 return NULL; 3223 3498 } 3224 3499 return ClosestLine; 3225 }; 3500 } 3501 ; 3226 3502 3227 3503 /** Finds the triangle that is closest to a given Vector \a *x. … … 3232 3508 TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const 3233 3509 { 3234 Info FunctionInfo(__func__); 3235 3236 // get closest points 3237 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC); 3510 Info FunctionInfo(__func__); 3511 // get closest points 3512 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC); 3238 3513 if (points == NULL) { 3239 eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl;3514 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl); 3240 3515 return NULL; 3241 3516 } 3242 3517 3243 3518 // for each point, check its lines, remember closest 3244 Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl;3519 DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl); 3245 3520 LineSet ClosestLines; 3246 3521 double MinDistance = 1e+16; … … 3264 3539 const double lengthEndB = BaseLineIntersection.NormSquared(); 3265 3540 3266 if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { 3541 if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint 3267 3542 const double lengthEnd = Min(lengthEndA, lengthEndB); 3268 3543 if (lengthEnd - MinDistance < -MYEPSILON) { // new best line … … 3270 3545 ClosestLines.insert(LineRunner->second); 3271 3546 MinDistance = lengthEnd; 3272 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl;3273 } else if 3547 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl); 3548 } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate 3274 3549 ClosestLines.insert(LineRunner->second); 3275 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl;3550 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl); 3276 3551 } else { // line is worse 3277 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;3552 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); 3278 3553 } 3279 3554 } else { // intersection is closer, calculate … … 3286 3561 const double distance = BaseLineIntersection.NormSquared(); 3287 3562 if (Center.NormSquared() > BaseLine.NormSquared()) { 3288 eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl;3563 DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl); 3289 3564 } 3290 3565 if ((ClosestLines.empty()) || (distance < MinDistance)) { 3291 3566 ClosestLines.insert(LineRunner->second); 3292 3567 MinDistance = distance; 3293 Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl;3568 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl); 3294 3569 } else { 3295 Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl;3570 DoLog(2) && (Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl); 3296 3571 } 3297 3572 } 3298 3573 } 3299 3574 } 3300 delete (points);3575 delete (points); 3301 3576 3302 3577 // check whether closest line is "too close" :), then it's inside 3303 3578 if (ClosestLines.empty()) { 3304 Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl;3579 DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl); 3305 3580 return NULL; 3306 3581 } … … 3308 3583 for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++) 3309 3584 for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) { 3310 candidates->push_back(Runner->second);3311 }3585 candidates->push_back(Runner->second); 3586 } 3312 3587 return candidates; 3313 }; 3588 } 3589 ; 3314 3590 3315 3591 /** Finds closest triangle to a point. … … 3322 3598 class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const 3323 3599 { 3324 3600 Info FunctionInfo(__func__); 3325 3601 class BoundaryTriangleSet *result = NULL; 3326 3602 TriangleList *triangles = FindClosestTrianglesToVector(x, LC); … … 3333 3609 3334 3610 // go through all and pick the one with the best alignment to x 3335 double MinAlignment = 2. *M_PI;3611 double MinAlignment = 2. * M_PI; 3336 3612 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) { 3337 3613 (*Runner)->GetCenter(&Center); … … 3342 3618 result = *Runner; 3343 3619 MinAlignment = Alignment; 3344 Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl;3620 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl); 3345 3621 } else { 3346 Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl;3347 } 3348 } 3349 delete (triangles);3622 DoLog(1) && (Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl); 3623 } 3624 } 3625 delete (triangles); 3350 3626 3351 3627 return result; 3352 }; 3628 } 3629 ; 3353 3630 3354 3631 /** Checks whether the provided Vector is within the Tesselation structure. … … 3362 3639 { 3363 3640 Info FunctionInfo(__func__); 3364 TriangleIntersectionList Intersections(&Point, this,LC);3641 TriangleIntersectionList Intersections(&Point, this, LC); 3365 3642 3366 3643 return Intersections.IsInside(); 3367 }; 3644 } 3645 ; 3368 3646 3369 3647 /** Returns the distance to the surface given by the tesselation. … … 3395 3673 3396 3674 if (triangle == NULL) {// is boundary point or only point in point cloud? 3397 Log() << Verbose(1) << "No triangle given!" << endl;3675 DoLog(1) && (Log() << Verbose(1) << "No triangle given!" << endl); 3398 3676 return -1.; 3399 3677 } else { 3400 Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl;3678 DoLog(1) && (Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl); 3401 3679 } 3402 3680 3403 3681 triangle->GetCenter(&Center); 3404 Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl;3682 DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl); 3405 3683 DistanceToCenter.CopyVector(&Center); 3406 3684 DistanceToCenter.SubtractVector(&Point); 3407 Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl;3685 DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl); 3408 3686 3409 3687 // check whether we are on boundary … … 3414 3692 Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter 3415 3693 DistanceToCenter.AddVector(&triangle->NormalVector); // points outside 3416 Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl;3694 DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl); 3417 3695 if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) { 3418 Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl;3696 DoLog(1) && (Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl); 3419 3697 return 0.; 3420 3698 } else { 3421 Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl;3699 DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl); 3422 3700 return false; 3423 3701 } … … 3425 3703 // calculate smallest distance 3426 3704 distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection); 3427 Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl;3705 DoLog(1) && (Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl); 3428 3706 3429 3707 // then check direction to boundary 3430 3708 if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) { 3431 Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl;3709 DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl); 3432 3710 return -distance; 3433 3711 } else { 3434 Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl;3712 DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl); 3435 3713 return +distance; 3436 3714 } 3437 3715 } 3438 }; 3716 } 3717 ; 3439 3718 3440 3719 /** Calculates minimum distance from \a&Point to a tesselated surface. … … 3447 3726 { 3448 3727 Info FunctionInfo(__func__); 3449 TriangleIntersectionList Intersections(&Point, this,LC);3728 TriangleIntersectionList Intersections(&Point, this, LC); 3450 3729 3451 3730 return Intersections.GetSmallestDistance(); 3452 }; 3731 } 3732 ; 3453 3733 3454 3734 /** Calculates minimum distance from \a&Point to a tesselated surface. … … 3461 3741 { 3462 3742 Info FunctionInfo(__func__); 3463 TriangleIntersectionList Intersections(&Point, this,LC);3743 TriangleIntersectionList Intersections(&Point, this, LC); 3464 3744 3465 3745 return Intersections.GetClosestTriangle(); 3466 }; 3746 } 3747 ; 3467 3748 3468 3749 /** Gets all points connected to the provided point by triangulation lines. … … 3474 3755 TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const 3475 3756 { 3476 3477 3757 Info FunctionInfo(__func__); 3758 TesselPointSet *connectedPoints = new TesselPointSet; 3478 3759 class BoundaryPointSet *ReferencePoint = NULL; 3479 3760 TesselPoint* current; 3480 3761 bool takePoint = false; 3481 3482 3762 // find the respective boundary point 3483 3763 PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr); … … 3485 3765 ReferencePoint = PointRunner->second; 3486 3766 } else { 3487 eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;3767 DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl); 3488 3768 ReferencePoint = NULL; 3489 3769 } … … 3491 3771 // little trick so that we look just through lines connect to the BoundaryPoint 3492 3772 // OR fall-back to look through all lines if there is no such BoundaryPoint 3493 const LineMap *Lines;; 3773 const LineMap *Lines; 3774 ; 3494 3775 if (ReferencePoint != NULL) 3495 3776 Lines = &(ReferencePoint->lines); … … 3498 3779 LineMap::const_iterator findLines = Lines->begin(); 3499 3780 while (findLines != Lines->end()) { 3500 takePoint = false;3501 3502 if (findLines->second->endpoints[0]->Nr == Point->nr) {3503 takePoint = true;3504 current = findLines->second->endpoints[1]->node;3505 } else if (findLines->second->endpoints[1]->Nr == Point->nr) {3506 takePoint = true;3507 current = findLines->second->endpoints[0]->node;3508 }3509 3510 if (takePoint) {3511 Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;3512 connectedPoints->insert(current);3513 }3514 3515 findLines++;3781 takePoint = false; 3782 3783 if (findLines->second->endpoints[0]->Nr == Point->nr) { 3784 takePoint = true; 3785 current = findLines->second->endpoints[1]->node; 3786 } else if (findLines->second->endpoints[1]->Nr == Point->nr) { 3787 takePoint = true; 3788 current = findLines->second->endpoints[0]->node; 3789 } 3790 3791 if (takePoint) { 3792 DoLog(1) && (Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl); 3793 connectedPoints->insert(current); 3794 } 3795 3796 findLines++; 3516 3797 } 3517 3798 3518 3799 if (connectedPoints->empty()) { // if have not found any points 3519 eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl;3800 DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl); 3520 3801 return NULL; 3521 3802 } 3522 3803 3523 3804 return connectedPoints; 3524 } ;3525 3805 } 3806 ; 3526 3807 3527 3808 /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point. … … 3539 3820 TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const 3540 3821 { 3541 3822 Info FunctionInfo(__func__); 3542 3823 map<double, TesselPoint*> anglesOfPoints; 3543 3824 TesselPointList *connectedCircle = new TesselPointList; … … 3546 3827 Vector OrthogonalVector; 3547 3828 Vector helper; 3548 const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL};3829 const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL }; 3549 3830 TriangleList *triangles = NULL; 3550 3831 3551 3832 if (SetOfNeighbours == NULL) { 3552 eLog() << Verbose(2) << "Could not find any connected points!" << endl;3553 delete (connectedCircle);3833 DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl); 3834 delete (connectedCircle); 3554 3835 return NULL; 3555 3836 } … … 3561 3842 PlaneNormal.AddVector(&(*Runner)->NormalVector); 3562 3843 } else { 3563 eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl;3844 DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl); 3564 3845 performCriticalExit(); 3565 3846 } 3566 PlaneNormal.Scale(1.0 /triangles->size());3567 Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl;3847 PlaneNormal.Scale(1.0 / triangles->size()); 3848 DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl); 3568 3849 PlaneNormal.Normalize(); 3569 3850 … … 3574 3855 AngleZero.ProjectOntoPlane(&PlaneNormal); 3575 3856 } 3576 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON 3577 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;3857 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3858 DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl); 3578 3859 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3579 3860 AngleZero.SubtractVector(Point->node); 3580 3861 AngleZero.ProjectOntoPlane(&PlaneNormal); 3581 3862 if (AngleZero.NormSquared() < MYEPSILON) { 3582 eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;3863 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); 3583 3864 performCriticalExit(); 3584 3865 } 3585 3866 } 3586 Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;3867 DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl); 3587 3868 if (AngleZero.NormSquared() > MYEPSILON) 3588 3869 OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero); 3589 3870 else 3590 3871 OrthogonalVector.MakeNormalVector(&PlaneNormal); 3591 Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;3872 DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl); 3592 3873 3593 3874 // go through all connected points and calculate angle … … 3597 3878 helper.ProjectOntoPlane(&PlaneNormal); 3598 3879 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3599 Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;3600 anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));3601 } 3602 3603 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {3880 DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl); 3881 anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner))); 3882 } 3883 3884 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) { 3604 3885 connectedCircle->push_back(AngleRunner->second); 3605 3886 } … … 3631 3912 3632 3913 if (SetOfNeighbours == NULL) { 3633 eLog() << Verbose(2) << "Could not find any connected points!" << endl;3634 delete (connectedCircle);3914 DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl); 3915 delete (connectedCircle); 3635 3916 return NULL; 3636 3917 } … … 3643 3924 } 3644 3925 3645 Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl;3926 DoLog(1) && (Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl); 3646 3927 // calculate central point 3647 3648 3928 TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin(); 3649 3929 TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin(); … … 3655 3935 while (TesselC != SetOfNeighbours->end()) { 3656 3936 helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node); 3657 Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl;3937 DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl); 3658 3938 counter++; 3659 3939 TesselA++; … … 3664 3944 //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size() 3665 3945 // << "; scale factor " << counter; 3666 PlaneNormal.Scale(1.0 /(double)counter);3667 // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;3668 //3669 // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points3670 // PlaneNormal.CopyVector(Point->node);3671 // PlaneNormal.SubtractVector(¢er);3672 // PlaneNormal.Normalize();3673 Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;3946 PlaneNormal.Scale(1.0 / (double) counter); 3947 // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl; 3948 // 3949 // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points 3950 // PlaneNormal.CopyVector(Point->node); 3951 // PlaneNormal.SubtractVector(¢er); 3952 // PlaneNormal.Normalize(); 3953 DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl); 3674 3954 3675 3955 // construct one orthogonal vector … … 3679 3959 AngleZero.ProjectOntoPlane(&PlaneNormal); 3680 3960 } 3681 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON 3682 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl;3961 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3962 DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl); 3683 3963 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3684 3964 AngleZero.SubtractVector(Point->node); 3685 3965 AngleZero.ProjectOntoPlane(&PlaneNormal); 3686 3966 if (AngleZero.NormSquared() < MYEPSILON) { 3687 eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;3967 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); 3688 3968 performCriticalExit(); 3689 3969 } 3690 3970 } 3691 Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;3971 DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl); 3692 3972 if (AngleZero.NormSquared() > MYEPSILON) 3693 3973 OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero); 3694 3974 else 3695 3975 OrthogonalVector.MakeNormalVector(&PlaneNormal); 3696 Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;3976 DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl); 3697 3977 3698 3978 // go through all connected points and calculate angle 3699 pair <map<double, TesselPoint*>::iterator, bool> InserterTest;3979 pair<map<double, TesselPoint*>::iterator, bool> InserterTest; 3700 3980 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3701 3981 helper.CopyVector((*listRunner)->node); … … 3704 3984 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3705 3985 if (angle > M_PI) // the correction is of no use here (and not desired) 3706 angle = 2. *M_PI - angle;3707 Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl;3708 InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));3986 angle = 2. * M_PI - angle; 3987 DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl); 3988 InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner))); 3709 3989 if (!InserterTest.second) { 3710 eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl;3990 DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl); 3711 3991 performCriticalExit(); 3712 3992 } 3713 3993 } 3714 3994 3715 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {3995 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) { 3716 3996 connectedCircle->push_back(AngleRunner->second); 3717 3997 } … … 3728 4008 ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const 3729 4009 { 3730 4010 Info FunctionInfo(__func__); 3731 4011 map<double, TesselPoint*> anglesOfPoints; 3732 list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;4012 list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ; 3733 4013 TesselPointList *connectedPath = NULL; 3734 4014 Vector center; … … 3742 4022 class BoundaryLineSet *CurrentLine = NULL; 3743 4023 class BoundaryLineSet *StartLine = NULL; 3744 3745 4024 // find the respective boundary point 3746 4025 PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr); … … 3748 4027 ReferencePoint = PointRunner->second; 3749 4028 } else { 3750 eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;4029 DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl); 3751 4030 return NULL; 3752 4031 } 3753 4032 3754 map 3755 map 3756 map 3757 map 4033 map<class BoundaryLineSet *, bool> TouchedLine; 4034 map<class BoundaryTriangleSet *, bool> TouchedTriangle; 4035 map<class BoundaryLineSet *, bool>::iterator LineRunner; 4036 map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner; 3758 4037 for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) { 3759 TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false));4038 TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false)); 3760 4039 for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++) 3761 TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false));4040 TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false)); 3762 4041 } 3763 4042 if (!ReferencePoint->lines.empty()) { … … 3765 4044 LineRunner = TouchedLine.find(runner->second); 3766 4045 if (LineRunner == TouchedLine.end()) { 3767 eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl;4046 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl); 3768 4047 } else if (!LineRunner->second) { 3769 4048 LineRunner->second = true; … … 3773 4052 StartLine = CurrentLine; 3774 4053 CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint); 3775 Log() << Verbose(1)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;4054 DoLog(1) && (Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl); 3776 4055 do { 3777 4056 // push current one 3778 Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;4057 DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl); 3779 4058 connectedPath->push_back(CurrentPoint->node); 3780 4059 3781 4060 // find next triangle 3782 4061 for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) { 3783 Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;4062 DoLog(1) && (Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl); 3784 4063 if ((Runner->second != triangle)) { // look for first triangle not equal to old one 3785 4064 triangle = Runner->second; … … 3788 4067 if (!TriangleRunner->second) { 3789 4068 TriangleRunner->second = true; 3790 Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl;4069 DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl); 3791 4070 break; 3792 4071 } else { 3793 Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;4072 DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl); 3794 4073 triangle = NULL; 3795 4074 } 3796 4075 } else { 3797 eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl;4076 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl); 3798 4077 triangle = NULL; 3799 4078 } … … 3803 4082 break; 3804 4083 // find next line 3805 for (int i =0;i<3;i++) {4084 for (int i = 0; i < 3; i++) { 3806 4085 if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point 3807 4086 CurrentLine = triangle->lines[i]; 3808 Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl;4087 DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl); 3809 4088 break; 3810 4089 } … … 3812 4091 LineRunner = TouchedLine.find(CurrentLine); 3813 4092 if (LineRunner == TouchedLine.end()) 3814 eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl;4093 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl); 3815 4094 else 3816 4095 LineRunner->second = true; … … 3820 4099 } while (CurrentLine != StartLine); 3821 4100 // last point is missing, as it's on start line 3822 Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;4101 DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl); 3823 4102 if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back()) 3824 4103 connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node); … … 3826 4105 ListOfPaths->push_back(connectedPath); 3827 4106 } else { 3828 Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;4107 DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl); 3829 4108 } 3830 4109 } 3831 4110 } else { 3832 eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl;4111 DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl); 3833 4112 } 3834 4113 … … 3844 4123 ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const 3845 4124 { 3846 4125 Info FunctionInfo(__func__); 3847 4126 list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point); 3848 list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;4127 list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ; 3849 4128 TesselPointList *connectedPath = NULL; 3850 4129 TesselPointList *newPath = NULL; 3851 4130 int count = 0; 3852 3853 3854 4131 TesselPointList::iterator CircleRunner; 3855 4132 TesselPointList::iterator CircleStart; 3856 4133 3857 for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {4134 for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) { 3858 4135 connectedPath = *ListRunner; 3859 4136 3860 Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl;4137 DoLog(1) && (Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl); 3861 4138 3862 4139 // go through list, look for reappearance of starting Point and count 3863 4140 CircleStart = connectedPath->begin(); 3864 3865 4141 // go through list, look for reappearance of starting Point and create list 3866 4142 TesselPointList::iterator Marker = CircleStart; … … 3868 4144 if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point 3869 4145 // we have a closed circle from Marker to new Marker 3870 Log() << Verbose(1) << count+1 << ". closed path consists of: ";4146 DoLog(1) && (Log() << Verbose(1) << count + 1 << ". closed path consists of: "); 3871 4147 newPath = new TesselPointList; 3872 4148 TesselPointList::iterator CircleSprinter = Marker; 3873 4149 for (; CircleSprinter != CircleRunner; CircleSprinter++) { 3874 4150 newPath->push_back(*CircleSprinter); 3875 Log() << Verbose(0) << (**CircleSprinter) << " <-> ";4151 DoLog(0) && (Log() << Verbose(0) << (**CircleSprinter) << " <-> "); 3876 4152 } 3877 Log() << Verbose(0) << ".." << endl;4153 DoLog(0) && (Log() << Verbose(0) << ".." << endl); 3878 4154 count++; 3879 4155 Marker = CircleRunner; … … 3884 4160 } 3885 4161 } 3886 Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl;4162 DoLog(1) && (Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl); 3887 4163 3888 4164 // delete list of paths … … 3890 4166 connectedPath = *(ListofPaths->begin()); 3891 4167 ListofPaths->remove(connectedPath); 3892 delete (connectedPath);3893 } 3894 delete (ListofPaths);4168 delete (connectedPath); 4169 } 4170 delete (ListofPaths); 3895 4171 3896 4172 // exit 3897 4173 return ListofClosedPaths; 3898 } ;3899 4174 } 4175 ; 3900 4176 3901 4177 /** Gets all belonging triangles for a given BoundaryPointSet. … … 3906 4182 TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const 3907 4183 { 3908 3909 4184 Info FunctionInfo(__func__); 4185 TriangleSet *connectedTriangles = new TriangleSet; 3910 4186 3911 4187 if (Point == NULL) { 3912 eLog() << Verbose(1) << "Point given is NULL." << endl;4188 DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl); 3913 4189 } else { 3914 4190 // go through its lines and insert all triangles 3915 4191 for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++) 3916 4192 for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { 3917 connectedTriangles->insert(TriangleRunner->second);3918 }4193 connectedTriangles->insert(TriangleRunner->second); 4194 } 3919 4195 } 3920 4196 3921 4197 return connectedTriangles; 3922 } ;3923 4198 } 4199 ; 3924 4200 3925 4201 /** Removes a boundary point from the envelope while keeping it closed. … … 3934 4210 * \return volume added to the volume inside the tesselated surface by the removal 3935 4211 */ 3936 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) { 4212 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) 4213 { 3937 4214 class BoundaryLineSet *line = NULL; 3938 4215 class BoundaryTriangleSet *triangle = NULL; … … 3942 4219 3943 4220 if (point == NULL) { 3944 eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl;4221 DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl); 3945 4222 return 0.; 3946 4223 } else 3947 Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl;4224 DoLog(0) && (Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl); 3948 4225 3949 4226 // copy old location for the volume … … 3952 4229 // get list of connected points 3953 4230 if (point->lines.empty()) { 3954 eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl;4231 DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl); 3955 4232 return 0.; 3956 4233 } … … 3961 4238 // gather all triangles 3962 4239 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) 3963 count +=LineRunner->second->triangles.size();4240 count += LineRunner->second->triangles.size(); 3964 4241 TriangleMap Candidates; 3965 4242 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { … … 3967 4244 for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) { 3968 4245 triangle = TriangleRunner->second; 3969 Candidates.insert( TrianglePair (triangle->Nr, triangle));4246 Candidates.insert(TrianglePair(triangle->Nr, triangle)); 3970 4247 } 3971 4248 } 3972 4249 3973 4250 // remove all triangles 3974 count =0;4251 count = 0; 3975 4252 NormalVector.Zero(); 3976 4253 for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { 3977 Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl;4254 DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl); 3978 4255 NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward 3979 4256 RemoveTesselationTriangle(Runner->second); 3980 4257 count++; 3981 4258 } 3982 Log() << Verbose(1) << count << " triangles were removed." << endl;4259 DoLog(1) && (Log() << Verbose(1) << count << " triangles were removed." << endl); 3983 4260 3984 4261 list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin(); … … 3989 4266 double smallestangle; 3990 4267 Vector Point, Reference, OrthogonalVector; 3991 if (count > 2) { 4268 if (count > 2) { // less than three triangles, then nothing will be created 3992 4269 class TesselPoint *TriangleCandidates[3]; 3993 4270 count = 0; 3994 for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) {// go through all closed paths4271 for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths 3995 4272 if (ListAdvance != ListOfClosedPaths->end()) 3996 4273 ListAdvance++; 3997 4274 3998 4275 connectedPath = *ListRunner; 3999 4000 4276 // re-create all triangles by going through connected points list 4001 4277 LineList NewLines; 4002 for (; !connectedPath->empty();) {4278 for (; !connectedPath->empty();) { 4003 4279 // search middle node with widest angle to next neighbours 4004 4280 EndNode = connectedPath->end(); 4005 4281 smallestangle = 0.; 4006 4282 for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) { 4007 Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;4283 DoLog(1) && (Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl); 4008 4284 // construct vectors to next and previous neighbour 4009 4285 StartNode = MiddleNode; … … 4026 4302 angle = GetAngle(Point, Reference, OrthogonalVector); 4027 4303 //if (angle < M_PI) // no wrong-sided triangles, please? 4028 if(fabs(angle - M_PI) < fabs(smallestangle - M_PI)) {// get straightest angle (i.e. construct those triangles with smallest area first)4029 4030 4031 4304 if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first) 4305 smallestangle = angle; 4306 EndNode = MiddleNode; 4307 } 4032 4308 } 4033 4309 MiddleNode = EndNode; 4034 4310 if (MiddleNode == connectedPath->end()) { 4035 eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl;4311 DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl); 4036 4312 performCriticalExit(); 4037 4313 } … … 4043 4319 if (EndNode == connectedPath->end()) 4044 4320 EndNode = connectedPath->begin(); 4045 Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl;4046 Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;4047 Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl;4048 Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;4321 DoLog(2) && (Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl); 4322 DoLog(2) && (Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl); 4323 DoLog(2) && (Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl); 4324 DoLog(1) && (Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl); 4049 4325 TriangleCandidates[0] = *StartNode; 4050 4326 TriangleCandidates[1] = *MiddleNode; … … 4052 4328 triangle = GetPresentTriangle(TriangleCandidates); 4053 4329 if (triangle != NULL) { 4054 eLog() << Verbose(0) << "New triangle already present, skipping!" << endl;4330 DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl); 4055 4331 StartNode++; 4056 4332 MiddleNode++; … … 4064 4340 continue; 4065 4341 } 4066 Log() << Verbose(3) << "Adding new triangle points."<< endl;4342 DoLog(3) && (Log() << Verbose(3) << "Adding new triangle points." << endl); 4067 4343 AddTesselationPoint(*StartNode, 0); 4068 4344 AddTesselationPoint(*MiddleNode, 1); 4069 4345 AddTesselationPoint(*EndNode, 2); 4070 Log() << Verbose(3) << "Adding new triangle lines."<< endl;4071 AddTesselationLine( TPS[0], TPS[1], 0);4072 AddTesselationLine( TPS[0], TPS[2], 1);4346 DoLog(3) && (Log() << Verbose(3) << "Adding new triangle lines." << endl); 4347 AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); 4348 AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); 4073 4349 NewLines.push_back(BLS[1]); 4074 AddTesselationLine( TPS[1], TPS[2], 2);4350 AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); 4075 4351 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 4076 4352 BTS->GetNormalVector(NormalVector); … … 4083 4359 // prepare nodes for next triangle 4084 4360 StartNode = EndNode; 4085 Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;4361 DoLog(2) && (Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl); 4086 4362 connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles) 4087 4363 if (connectedPath->size() == 2) { // we are done … … 4090 4366 break; 4091 4367 } else if (connectedPath->size() < 2) { // something's gone wrong! 4092 eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl;4368 DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl); 4093 4369 performCriticalExit(); 4094 4370 } else { … … 4110 4386 do { 4111 4387 maxgain = 0; 4112 for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {4388 for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) { 4113 4389 tmp = PickFarthestofTwoBaselines(*Runner); 4114 4390 if (maxgain < tmp) { … … 4119 4395 if (maxgain != 0) { 4120 4396 volume += maxgain; 4121 Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl;4397 DoLog(1) && (Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl); 4122 4398 OtherBase = FlipBaseline(*Candidate); 4123 4399 NewLines.erase(Candidate); … … 4128 4404 4129 4405 ListOfClosedPaths->remove(connectedPath); 4130 delete (connectedPath);4131 } 4132 Log() << Verbose(0) << count << " triangles were created." << endl;4406 delete (connectedPath); 4407 } 4408 DoLog(0) && (Log() << Verbose(0) << count << " triangles were created." << endl); 4133 4409 } else { 4134 4410 while (!ListOfClosedPaths->empty()) { … … 4136 4412 connectedPath = *ListRunner; 4137 4413 ListOfClosedPaths->remove(connectedPath); 4138 delete (connectedPath);4139 } 4140 Log() << Verbose(0) << "No need to create any triangles." << endl;4141 } 4142 delete (ListOfClosedPaths);4143 4144 Log() << Verbose(0) << "Removed volume is " << volume << "." << endl;4414 delete (connectedPath); 4415 } 4416 DoLog(0) && (Log() << Verbose(0) << "No need to create any triangles." << endl); 4417 } 4418 delete (ListOfClosedPaths); 4419 4420 DoLog(0) && (Log() << Verbose(0) << "Removed volume is " << volume << "." << endl); 4145 4421 4146 4422 return volume; 4147 }; 4148 4149 4423 } 4424 ; 4150 4425 4151 4426 /** … … 4159 4434 TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const 4160 4435 { 4161 4162 4436 Info FunctionInfo(__func__); 4437 TriangleList *result = new TriangleList; 4163 4438 LineMap::const_iterator FindLine; 4164 4439 TriangleMap::const_iterator FindTriangle; … … 4184 4459 for (int i = 0; i < 3; i++) { 4185 4460 if (TrianglePoints[i] != NULL) { 4186 for (int j = i +1; j < 3; j++) {4461 for (int j = i + 1; j < 3; j++) { 4187 4462 if (TrianglePoints[j] != NULL) { 4188 4463 for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap! 4189 (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); 4190 FindLine++) { 4191 for (FindTriangle = FindLine->second->triangles.begin(); 4192 FindTriangle != FindLine->second->triangles.end(); 4193 FindTriangle++) { 4464 (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) { 4465 for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) { 4194 4466 if (FindTriangle->second->IsPresentTupel(TrianglePoints)) { 4195 4467 result->push_back(FindTriangle->second); … … 4206 4478 case 1: // copy all triangles of the respective line 4207 4479 { 4208 int i =0;4480 int i = 0; 4209 4481 for (; i < 3; i++) 4210 4482 if (TrianglePoints[i] == NULL) 4211 4483 break; 4212 for (FindLine = TrianglePoints[(i+1)%3]->lines.find(TrianglePoints[(i+2)%3]->node->nr); // is a multimap! 4213 (FindLine != TrianglePoints[(i+1)%3]->lines.end()) && (FindLine->first == TrianglePoints[(i+2)%3]->node->nr); 4214 FindLine++) { 4215 for (FindTriangle = FindLine->second->triangles.begin(); 4216 FindTriangle != FindLine->second->triangles.end(); 4217 FindTriangle++) { 4484 for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap! 4485 (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) { 4486 for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) { 4218 4487 if (FindTriangle->second->IsPresentTupel(TrianglePoints)) { 4219 4488 result->push_back(FindTriangle->second); … … 4225 4494 case 2: // copy all triangles of the respective point 4226 4495 { 4227 int i =0;4496 int i = 0; 4228 4497 for (; i < 3; i++) 4229 4498 if (TrianglePoints[i] != NULL) … … 4243 4512 } 4244 4513 default: 4245 eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl;4514 DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl); 4246 4515 performCriticalExit(); 4247 4516 break; … … 4251 4520 } 4252 4521 4253 struct BoundaryLineSetCompare { 4254 bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) { 4522 struct BoundaryLineSetCompare 4523 { 4524 bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b) 4525 { 4255 4526 int lowerNra = -1; 4256 4527 int lowerNrb = -1; … … 4270 4541 else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb]) 4271 4542 return false; 4272 else { 4273 if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])4274 return true;4275 else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])4276 return false;4543 else { // both lower-numbered endpoints are the same ... 4544 if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2]) 4545 return true; 4546 else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2]) 4547 return false; 4277 4548 } 4278 4549 return false; 4279 }; 4550 } 4551 ; 4280 4552 }; 4281 4553 … … 4290 4562 IndexToIndex * Tesselation::FindAllDegeneratedLines() 4291 4563 { 4292 4293 4564 Info FunctionInfo(__func__); 4565 UniqueLines AllLines; 4294 4566 IndexToIndex * DegeneratedLines = new IndexToIndex; 4295 4567 4296 4568 // sanity check 4297 4569 if (LinesOnBoundary.empty()) { 4298 eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.";4570 DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure."); 4299 4571 return DegeneratedLines; 4300 4572 } 4301 4302 4573 LineMap::iterator LineRunner1; 4303 pair< 4574 pair<UniqueLines::iterator, bool> tester; 4304 4575 for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) { 4305 tester = AllLines.insert( LineRunner1->second);4576 tester = AllLines.insert(LineRunner1->second); 4306 4577 if (!tester.second) { // found degenerated line 4307 DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));4308 DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));4578 DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr)); 4579 DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr)); 4309 4580 } 4310 4581 } … … 4312 4583 AllLines.clear(); 4313 4584 4314 Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;4585 DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl); 4315 4586 IndexToIndex::iterator it; 4316 4587 for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) { … … 4318 4589 const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second); 4319 4590 if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end()) 4320 Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl;4591 DoLog(0) && (Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl); 4321 4592 else 4322 eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl;4593 DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl); 4323 4594 } 4324 4595 … … 4334 4605 IndexToIndex * Tesselation::FindAllDegeneratedTriangles() 4335 4606 { 4336 4607 Info FunctionInfo(__func__); 4337 4608 IndexToIndex * DegeneratedLines = FindAllDegeneratedLines(); 4338 4609 IndexToIndex * DegeneratedTriangles = new IndexToIndex; 4339 4340 4610 TriangleMap::iterator TriangleRunner1, TriangleRunner2; 4341 4611 LineMap::iterator Liner; … … 4352 4622 for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) { 4353 4623 for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) { 4354 if ((TriangleRunner1->second != TriangleRunner2->second) 4355 && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) { 4356 DegeneratedTriangles->insert( pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr) ); 4357 DegeneratedTriangles->insert( pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr) ); 4624 if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) { 4625 DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr)); 4626 DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr)); 4358 4627 } 4359 4628 } 4360 4629 } 4361 4630 } 4362 delete (DegeneratedLines);4363 4364 Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;4631 delete (DegeneratedLines); 4632 4633 DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl); 4365 4634 IndexToIndex::iterator it; 4366 4635 for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++) 4367 Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl;4636 DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl); 4368 4637 4369 4638 return DegeneratedTriangles; … … 4376 4645 void Tesselation::RemoveDegeneratedTriangles() 4377 4646 { 4378 4647 Info FunctionInfo(__func__); 4379 4648 IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles(); 4380 4649 TriangleMap::iterator finder; 4381 4650 BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL; 4382 int count = 0; 4383 4384 for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); 4385 TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner 4386 ) { 4651 int count = 0; 4652 4653 for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) { 4387 4654 finder = TrianglesOnBoundary.find(TriangleKeyRunner->first); 4388 4655 if (finder != TrianglesOnBoundary.end()) … … 4401 4668 trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j]; 4402 4669 4403 if (trianglesShareLine 4404 && (triangle->endpoints[1]->LinesCount > 2) 4405 && (triangle->endpoints[2]->LinesCount > 2) 4406 && (triangle->endpoints[0]->LinesCount > 2) 4407 ) { 4670 if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) { 4408 4671 // check whether we have to fix lines 4409 4672 BoundaryTriangleSet *Othertriangle = NULL; … … 4425 4688 // the line of triangle receives the degenerated ones 4426 4689 triangle->lines[i]->triangles.erase(Othertriangle->Nr); 4427 triangle->lines[i]->triangles.insert( TrianglePair( partnerTriangle->Nr, partnerTriangle));4428 for (int k =0;k<3;k++)4690 triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle)); 4691 for (int k = 0; k < 3; k++) 4429 4692 if (triangle->lines[i] == Othertriangle->lines[k]) { 4430 4693 Othertriangle->lines[k] = partnerTriangle->lines[j]; … … 4432 4695 } 4433 4696 // the line of partnerTriangle receives the non-degenerated ones 4434 partnerTriangle->lines[j]->triangles.erase( 4435 partnerTriangle->lines[j]->triangles.insert( TrianglePair( Othertriangle->Nr, Othertriangle));4697 partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr); 4698 partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle)); 4436 4699 partnerTriangle->lines[j] = triangle->lines[i]; 4437 4700 } … … 4439 4702 // erase the pair 4440 4703 count += (int) DegeneratedTriangles->erase(triangle->Nr); 4441 Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;4704 DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl); 4442 4705 RemoveTesselationTriangle(triangle); 4443 4706 count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr); 4444 Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;4707 DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl); 4445 4708 RemoveTesselationTriangle(partnerTriangle); 4446 4709 } else { 4447 Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle 4448 << " and its partner " << *partnerTriangle << " because it is essential for at" 4449 << " least one of the endpoints to be kept in the tesselation structure." << endl; 4450 } 4451 } 4452 delete(DegeneratedTriangles); 4710 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); 4711 } 4712 } 4713 delete (DegeneratedTriangles); 4453 4714 if (count > 0) 4454 4715 LastTriangle = NULL; 4455 4716 4456 Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;4717 DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl); 4457 4718 } 4458 4719 … … 4467 4728 void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC) 4468 4729 { 4469 4730 Info FunctionInfo(__func__); 4470 4731 // find nearest boundary point 4471 4732 class TesselPoint *BackupPoint = NULL; … … 4480 4741 NearestBoundaryPoint = PointRunner->second; 4481 4742 } else { 4482 eLog() << Verbose(1) << "I cannot find the boundary point." << endl;4743 DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl); 4483 4744 return; 4484 4745 } 4485 Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;4746 DoLog(0) && (Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl); 4486 4747 4487 4748 // go through its lines and find the best one to split … … 4498 4759 CenterToPoint.SubtractVector(point->node); 4499 4760 angle = CenterToPoint.Angle(&BaseLine); 4500 if (fabs(angle - M_PI /2.) < fabs(BestAngle - M_PI/2.)) {4761 if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) { 4501 4762 BestAngle = angle; 4502 4763 BestLine = Runner->second; … … 4508 4769 BestLine->triangles.erase(TempTriangle->Nr); 4509 4770 int nr = -1; 4510 for (int i =0;i<3; i++) {4771 for (int i = 0; i < 3; i++) { 4511 4772 if (TempTriangle->lines[i] == BestLine) { 4512 4773 nr = i; … … 4516 4777 4517 4778 // create new triangle to connect point (connects automatically with the missing spot of the chosen line) 4518 Log() << Verbose(2) << "Adding new triangle points."<< endl;4779 DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl); 4519 4780 AddTesselationPoint((BestLine->endpoints[0]->node), 0); 4520 4781 AddTesselationPoint((BestLine->endpoints[1]->node), 1); 4521 4782 AddTesselationPoint(point, 2); 4522 Log() << Verbose(2) << "Adding new triangle lines."<< endl;4523 AddTesselationLine( TPS[0], TPS[1], 0);4524 AddTesselationLine( TPS[0], TPS[2], 1);4525 AddTesselationLine( TPS[1], TPS[2], 2);4783 DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl); 4784 AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); 4785 AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); 4786 AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); 4526 4787 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 4527 4788 BTS->GetNormalVector(TempTriangle->NormalVector); 4528 4789 BTS->NormalVector.Scale(-1.); 4529 Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;4790 DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl); 4530 4791 AddTesselationTriangle(); 4531 4792 4532 4793 // create other side of this triangle and close both new sides of the first created triangle 4533 Log() << Verbose(2) << "Adding new triangle points."<< endl;4794 DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl); 4534 4795 AddTesselationPoint((BestLine->endpoints[0]->node), 0); 4535 4796 AddTesselationPoint((BestLine->endpoints[1]->node), 1); 4536 4797 AddTesselationPoint(point, 2); 4537 Log() << Verbose(2) << "Adding new triangle lines."<< endl;4538 AddTesselationLine( TPS[0], TPS[1], 0);4539 AddTesselationLine( TPS[0], TPS[2], 1);4540 AddTesselationLine( TPS[1], TPS[2], 2);4798 DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl); 4799 AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); 4800 AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); 4801 AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); 4541 4802 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 4542 4803 BTS->GetNormalVector(TempTriangle->NormalVector); 4543 Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;4804 DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl); 4544 4805 AddTesselationTriangle(); 4545 4806 4546 4807 // add removed triangle to the last open line of the second triangle 4547 for (int i =0;i<3;i++) { // look for the same line as BestLine (only it's its degenerated companion)4808 for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion) 4548 4809 if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) { 4549 if (BestLine == BTS->lines[i]) {4550 eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl;4810 if (BestLine == BTS->lines[i]) { 4811 DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl); 4551 4812 performCriticalExit(); 4552 4813 } 4553 BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));4814 BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle)); 4554 4815 TempTriangle->lines[nr] = BTS->lines[i]; 4555 4816 break; 4556 4817 } 4557 4818 } 4558 }; 4819 } 4820 ; 4559 4821 4560 4822 /** Writes the envelope to file. … … 4565 4827 void Tesselation::Output(const char *filename, const PointCloud * const cloud) 4566 4828 { 4567 4829 Info FunctionInfo(__func__); 4568 4830 ofstream *tempstream = NULL; 4569 4831 string NameofTempFile; … … 4571 4833 4572 4834 if (LastTriangle != NULL) { 4573 sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);4835 sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name); 4574 4836 if (DoTecplotOutput) { 4575 4837 string NameofTempFile(filename); 4576 4838 NameofTempFile.append(NumberName); 4577 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))4578 NameofTempFile.erase(npos, 1);4839 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos)) 4840 NameofTempFile.erase(npos, 1); 4579 4841 NameofTempFile.append(TecplotSuffix); 4580 Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";4842 DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n"); 4581 4843 tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc); 4582 4844 WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten); 4583 4845 tempstream->close(); 4584 4846 tempstream->flush(); 4585 delete (tempstream);4847 delete (tempstream); 4586 4848 } 4587 4849 … … 4589 4851 string NameofTempFile(filename); 4590 4852 NameofTempFile.append(NumberName); 4591 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))4592 NameofTempFile.erase(npos, 1);4853 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos)) 4854 NameofTempFile.erase(npos, 1); 4593 4855 NameofTempFile.append(Raster3DSuffix); 4594 Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";4856 DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n"); 4595 4857 tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc); 4596 4858 WriteRaster3dFile(tempstream, this, cloud); … … 4598 4860 tempstream->close(); 4599 4861 tempstream->flush(); 4600 delete (tempstream);4862 delete (tempstream); 4601 4863 } 4602 4864 } 4603 4865 if (DoTecplotOutput || DoRaster3DOutput) 4604 4866 TriangleFilesWritten++; 4605 }; 4606 4607 struct BoundaryPolygonSetCompare { 4608 bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const { 4867 } 4868 ; 4869 4870 struct BoundaryPolygonSetCompare 4871 { 4872 bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const 4873 { 4609 4874 if (s1->endpoints.size() < s2->endpoints.size()) 4610 4875 return true; … … 4635 4900 { 4636 4901 Info FunctionInfo(__func__); 4637 4638 4902 /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector 4639 4903 IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles(); 4640 set <BoundaryPointSet *> EndpointCandidateList;4641 pair < set < BoundaryPointSet *>::iterator, bool> InsertionTester;4642 pair < map < int, Vector *>::iterator, bool> TriangleInsertionTester;4904 set<BoundaryPointSet *> EndpointCandidateList; 4905 pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester; 4906 pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester; 4643 4907 for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) { 4644 Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl;4645 map <int, Vector *> TriangleVectors;4908 DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl); 4909 map<int, Vector *> TriangleVectors; 4646 4910 // gather all NormalVectors 4647 Log() << Verbose(1) << "Gathering triangles ..." << endl;4911 DoLog(1) && (Log() << Verbose(1) << "Gathering triangles ..." << endl); 4648 4912 for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++) 4649 4913 for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { 4650 4914 if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) { 4651 TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));4915 TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector))); 4652 4916 if (TriangleInsertionTester.second) 4653 Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl;4917 DoLog(1) && (Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl); 4654 4918 } else { 4655 Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl;4919 DoLog(1) && (Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl); 4656 4920 } 4657 4921 } 4658 4922 // check whether there are two that are parallel 4659 Log() << Verbose(1) << "Finding two parallel triangles ..." << endl;4660 for (map <int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)4661 for (map <int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)4923 DoLog(1) && (Log() << Verbose(1) << "Finding two parallel triangles ..." << endl); 4924 for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++) 4925 for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) 4662 4926 if (VectorWalker != VectorRunner) { // skip equals 4663 const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); 4664 Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl;4927 const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles 4928 DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl); 4665 4929 if (fabs(SCP + 1.) < ParallelEpsilon) { 4666 4930 InsertionTester = EndpointCandidateList.insert((Runner->second)); 4667 4931 if (InsertionTester.second) 4668 Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl;4932 DoLog(0) && (Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl); 4669 4933 // and break out of both loops 4670 4934 VectorWalker = TriangleVectors.end(); … … 4674 4938 } 4675 4939 } 4676 4940 delete (DegeneratedTriangles); 4677 4941 /// 3. Find connected endpoint candidates and put them into a polygon 4678 4942 UniquePolygonSet ListofDegeneratedPolygons; … … 4680 4944 BoundaryPointSet *OtherWalker = NULL; 4681 4945 BoundaryPolygonSet *Current = NULL; 4682 stack 4946 stack<BoundaryPointSet*> ToCheckConnecteds; 4683 4947 while (!EndpointCandidateList.empty()) { 4684 4948 Walker = *(EndpointCandidateList.begin()); 4685 if (Current == NULL) { 4686 Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl;4949 if (Current == NULL) { // create a new polygon with current candidate 4950 DoLog(0) && (Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl); 4687 4951 Current = new BoundaryPolygonSet; 4688 4952 Current->endpoints.insert(Walker); … … 4697 4961 for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) { 4698 4962 OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker); 4699 Log() << Verbose(1) << "Checking " << *OtherWalker << endl;4700 set <BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);4701 if (Finder != EndpointCandidateList.end()) { 4702 Log() << Verbose(1) << " Adding to polygon." << endl;4963 DoLog(1) && (Log() << Verbose(1) << "Checking " << *OtherWalker << endl); 4964 set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker); 4965 if (Finder != EndpointCandidateList.end()) { // found a connected partner 4966 DoLog(1) && (Log() << Verbose(1) << " Adding to polygon." << endl); 4703 4967 Current->endpoints.insert(OtherWalker); 4704 EndpointCandidateList.erase(Finder); 4705 ToCheckConnecteds.push(OtherWalker); 4968 EndpointCandidateList.erase(Finder); // remove from candidates 4969 ToCheckConnecteds.push(OtherWalker); // but check its partners too 4706 4970 } else { 4707 Log() << Verbose(1) << " is not connected to " << *Walker << endl;4971 DoLog(1) && (Log() << Verbose(1) << " is not connected to " << *Walker << endl); 4708 4972 } 4709 4973 } 4710 4974 } 4711 4975 4712 Log() << Verbose(0) << "Final polygon is " << *Current << endl;4976 DoLog(0) && (Log() << Verbose(0) << "Final polygon is " << *Current << endl); 4713 4977 ListofDegeneratedPolygons.insert(Current); 4714 4978 Current = NULL; … … 4717 4981 const int counter = ListofDegeneratedPolygons.size(); 4718 4982 4719 Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl;4983 DoLog(0) && (Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl); 4720 4984 for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) 4721 Log() << Verbose(0) << " " << **PolygonRunner << endl;4985 DoLog(0) && (Log() << Verbose(0) << " " << **PolygonRunner << endl); 4722 4986 4723 4987 /// 4. Go through all these degenerated polygons 4724 4988 for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) { 4725 stack 4989 stack<int> TriangleNrs; 4726 4990 Vector NormalVector; 4727 4991 /// 4a. Gather all triangles of this polygon … … 4730 4994 // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do. 4731 4995 if (T->size() == 2) { 4732 Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl;4733 delete (T);4996 DoLog(1) && (Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl); 4997 delete (T); 4734 4998 continue; 4735 4999 } … … 4740 5004 // connections to either polygon ... 4741 5005 if (T->size() % 2 != 0) { 4742 eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl;5006 DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl); 4743 5007 performCriticalExit(); 4744 5008 } 4745 4746 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 5009 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 4747 5010 /// 4a. Get NormalVector for one side (this is "front") 4748 5011 NormalVector.CopyVector(&(*TriangleWalker)->NormalVector); 4749 Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl;5012 DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl); 4750 5013 TriangleWalker++; 4751 5014 TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator … … 4756 5019 triangle = *TriangleWalker; 4757 5020 TriangleSprinter++; 4758 Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl;5021 DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl); 4759 5022 if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list 4760 Log() << Verbose(1) << " Removing ... " << endl;5023 DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl); 4761 5024 TriangleNrs.push(triangle->Nr); 4762 5025 T->erase(TriangleWalker); 4763 5026 RemoveTesselationTriangle(triangle); 4764 5027 } else 4765 Log() << Verbose(1) << " Keeping ... " << endl;5028 DoLog(1) && (Log() << Verbose(1) << " Keeping ... " << endl); 4766 5029 } 4767 5030 /// 4c. Copy all "front" triangles but with inverse NormalVector 4768 5031 TriangleWalker = T->begin(); 4769 while (TriangleWalker != T->end()) { 4770 Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl;5032 while (TriangleWalker != T->end()) { // go through all front triangles 5033 DoLog(1) && (Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl); 4771 5034 for (int i = 0; i < 3; i++) 4772 5035 AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i); 4773 AddTesselationLine( TPS[0], TPS[1], 0);4774 AddTesselationLine( TPS[0], TPS[2], 1);4775 AddTesselationLine( TPS[1], TPS[2], 2);5036 AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); 5037 AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); 5038 AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); 4776 5039 if (TriangleNrs.empty()) 4777 eLog() << Verbose(0) << "No more free triangle numbers!" << endl;5040 DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl); 4778 5041 BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ... 4779 5042 AddTesselationTriangle(); // ... and add … … 4784 5047 } 4785 5048 if (!TriangleNrs.empty()) { 4786 eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl; 4787 } 4788 delete(T); // remove the triangleset 4789 } 4790 5049 DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl); 5050 } 5051 delete (T); // remove the triangleset 5052 } 4791 5053 IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles(); 4792 Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl;5054 DoLog(0) && (Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl); 4793 5055 IndexToIndex::iterator it; 4794 5056 for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++) 4795 Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl; 4796 delete(SimplyDegeneratedTriangles); 4797 5057 DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl); 5058 delete (SimplyDegeneratedTriangles); 4798 5059 /// 5. exit 4799 5060 UniquePolygonSet::iterator PolygonRunner; 4800 5061 while (!ListofDegeneratedPolygons.empty()) { 4801 5062 PolygonRunner = ListofDegeneratedPolygons.begin(); 4802 delete (*PolygonRunner);5063 delete (*PolygonRunner); 4803 5064 ListofDegeneratedPolygons.erase(PolygonRunner); 4804 5065 } 4805 5066 4806 5067 return counter; 4807 }; 5068 } 5069 ;
Note:
See TracChangeset
for help on using the changeset viewer.