Changeset 6613ec
- Timestamp:
- Apr 21, 2010, 12:07:01 PM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- a67d19
- Parents:
- bc84ffc
- git-author:
- Frederik Heber <heber@…> (04/21/10 11:51:53)
- git-committer:
- Frederik Heber <heber@…> (04/21/10 12:07:01)
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/boundary.cpp
rbc84ffc r6613ec 960 960 bool freeLC = false; 961 961 bool status = false; 962 CandidateForTesselation *baseline; 963 LineMap::iterator testline; 962 CandidateForTesselation *baseline = NULL; 964 963 bool OneLoopWithoutSuccessFlag = true; // marks whether we went once through all baselines without finding any without two triangles 965 964 bool TesselationFailFlag = false; 966 BoundaryTriangleSet *T = NULL;967 965 968 966 if (TesselStruct == NULL) { … … 997 995 998 996 // 2b. find best candidate for each OpenLine 999 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) { 1000 baseline = Runner->second; 1001 if (baseline->pointlist.empty()) { 1002 T = (((baseline->BaseLine->triangles.begin()))->second); 1003 Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl; 1004 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one. 1005 } 1006 } 997 TesselationFailFlag = TesselStruct->FindCandidatesforOpenLines(RADIUS, LCList); 1007 998 1008 999 // 2c. print OpenLines with candidates again … … 1062 1053 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, ""); 1063 1054 1064 // correct degenerated polygons1065 TesselStruct->CorrectAllDegeneratedPolygons();1066 1067 // check envelope for consistency1068 status = CheckListOfBaselines(TesselStruct);1055 // // correct degenerated polygons 1056 // TesselStruct->CorrectAllDegeneratedPolygons(); 1057 // 1058 // // check envelope for consistency 1059 // status = CheckListOfBaselines(TesselStruct); 1069 1060 1070 1061 // write final envelope -
src/tesselation.cpp
rbc84ffc r6613ec 25 25 */ 26 26 BoundaryPointSet::BoundaryPointSet() : 27 LinesCount(0), 28 value(0.), 29 Nr(-1) 30 { 31 Info FunctionInfo(__func__); 32 Log() << Verbose(1) << "Adding noname." << endl; 33 }; 27 LinesCount(0), value(0.), Nr(-1) 28 { 29 Info FunctionInfo(__func__); 30 Log() << Verbose(1) << "Adding noname." << endl; 31 } 32 ; 34 33 35 34 /** Constructor of BoundaryPointSet with Tesselpoint. … … 37 36 */ 38 37 BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) : 39 LinesCount(0), 40 node(Walker), 41 value(0.), 42 Nr(Walker->nr) 43 { 44 Info FunctionInfo(__func__); 38 LinesCount(0), node(Walker), value(0.), Nr(Walker->nr) 39 { 40 Info FunctionInfo(__func__); 45 41 Log() << Verbose(1) << "Adding Node " << *Walker << endl; 46 }; 42 } 43 ; 47 44 48 45 /** Destructor of BoundaryPointSet. … … 52 49 BoundaryPointSet::~BoundaryPointSet() 53 50 { 54 51 Info FunctionInfo(__func__); 55 52 //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl; 56 53 if (!lines.empty()) 57 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);54 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl); 58 55 node = NULL; 59 }; 56 } 57 ; 60 58 61 59 /** Add a line to the LineMap of this point. … … 64 62 void BoundaryPointSet::AddLine(BoundaryLineSet * const line) 65 63 { 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 } 64 Info FunctionInfo(__func__); 65 Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl; 66 if (line->endpoints[0] == this) { 67 lines.insert(LinePair(line->endpoints[1]->Nr, line)); 68 } else { 69 lines.insert(LinePair(line->endpoints[0]->Nr, line)); 70 } 77 71 LinesCount++; 78 }; 72 } 73 ; 79 74 80 75 /** output operator for BoundaryPointSet. … … 94 89 */ 95 90 BoundaryLineSet::BoundaryLineSet() : 96 97 { 98 91 Nr(-1) 92 { 93 Info FunctionInfo(__func__); 99 94 for (int i = 0; i < 2; i++) 100 95 endpoints[i] = NULL; 101 }; 96 } 97 ; 102 98 103 99 /** Constructor of BoundaryLineSet with two endpoints. … … 108 104 BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number) 109 105 { 110 106 Info FunctionInfo(__func__); 111 107 // set number 112 108 Nr = number; … … 120 116 // clear triangles list 121 117 Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl; 122 }; 118 } 119 ; 123 120 124 121 /** Constructor of BoundaryLineSet with two endpoints. … … 142 139 // clear triangles list 143 140 Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl; 144 }; 141 } 142 ; 145 143 146 144 /** Destructor for BoundaryLineSet. … … 150 148 BoundaryLineSet::~BoundaryLineSet() 151 149 { 152 150 Info FunctionInfo(__func__); 153 151 int Numbers[2]; 154 152 … … 181 179 //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl; 182 180 if (endpoints[i] != NULL) { 183 delete (endpoints[i]);181 delete (endpoints[i]); 184 182 endpoints[i] = NULL; 185 183 } … … 188 186 } 189 187 if (!triangles.empty()) 190 DoeLog(2) && (eLog()<< Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl); 191 }; 188 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl); 189 } 190 ; 192 191 193 192 /** Add triangle to TriangleMap of this boundary line. … … 196 195 void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle) 197 196 { 198 197 Info FunctionInfo(__func__); 199 198 Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl; 200 199 triangles.insert(TrianglePair(triangle->Nr, triangle)); 201 }; 200 } 201 ; 202 202 203 203 /** Checks whether we have a common endpoint with given \a *line. … … 207 207 bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const 208 208 { 209 209 Info FunctionInfo(__func__); 210 210 if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1])) 211 211 return true; 212 212 else 213 213 return false; 214 }; 214 } 215 ; 215 216 216 217 /** Checks whether the adjacent triangles of a baseline are convex or not. … … 222 223 bool BoundaryLineSet::CheckConvexityCriterion() const 223 224 { 224 225 Info FunctionInfo(__func__); 225 226 Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck; 226 227 // get the two triangles 227 228 if (triangles.size() != 2) { 228 DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);229 DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl); 229 230 return true; 230 231 } … … 234 235 BaseLineCenter.CopyVector(endpoints[0]->node->node); 235 236 BaseLineCenter.AddVector(endpoints[1]->node->node); 236 BaseLineCenter.Scale(1. /2.);237 BaseLineCenter.Scale(1. / 2.); 237 238 BaseLine.CopyVector(endpoints[0]->node->node); 238 239 BaseLine.SubtractVector(endpoints[1]->node->node); … … 242 243 NormalCheck.Zero(); 243 244 double sign = -1.; 244 int i =0;245 int i = 0; 245 246 class BoundaryPointSet *node = NULL; 246 for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {247 for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 247 248 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 248 249 NormalCheck.AddVector(&runner->second->NormalVector); … … 250 251 sign = -sign; 251 252 if (runner->second->NormalVector.NormSquared() > MYEPSILON) 252 BaseLineNormal.CopyVector(&runner->second->NormalVector); 253 BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first 253 254 else { 254 DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);255 DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl); 255 256 } 256 257 node = runner->second->GetThirdEndpoint(this); … … 259 260 helper[i].CopyVector(node->node->node); 260 261 helper[i].SubtractVector(&BaseLineCenter); 261 helper[i].MakeNormalVector(&BaseLine); 262 helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles! 262 263 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 263 264 i++; 264 265 } else { 265 DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);266 DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl); 266 267 return true; 267 268 } … … 289 290 bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const 290 291 { 291 292 for (int i=0;i<2;i++)292 Info FunctionInfo(__func__); 293 for (int i = 0; i < 2; i++) 293 294 if (point == endpoints[i]) 294 295 return true; 295 296 return false; 296 }; 297 } 298 ; 297 299 298 300 /** Returns other endpoint of the line. … … 302 304 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const 303 305 { 304 306 Info FunctionInfo(__func__); 305 307 if (endpoints[0] == point) 306 308 return endpoints[1]; … … 309 311 else 310 312 return NULL; 311 }; 313 } 314 ; 312 315 313 316 /** output operator for BoundaryLineSet. … … 315 318 * \param &a boundary line 316 319 */ 317 ostream & operator <<(ostream &ost, const 320 ostream & operator <<(ostream &ost, const BoundaryLineSet &a) 318 321 { 319 322 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 323 return ost; 321 }; 324 } 325 ; 322 326 323 327 // ======================================== Triangles on Boundary ================================= … … 328 332 Nr(-1) 329 333 { 330 331 for (int i = 0; i < 3; i++) 332 {333 endpoints[i] = NULL;334 lines[i] = NULL;335 336 };334 Info FunctionInfo(__func__); 335 for (int i = 0; i < 3; i++) { 336 endpoints[i] = NULL; 337 lines[i] = NULL; 338 } 339 } 340 ; 337 341 338 342 /** Constructor for BoundaryTriangleSet with three lines. … … 343 347 Nr(number) 344 348 { 345 349 Info FunctionInfo(__func__); 346 350 // set number 347 351 // set lines … … 355 359 // for all three lines 356 360 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])); 361 OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j])); 359 362 // and we don't care whether insertion fails 360 363 } … … 368 371 } 369 372 if (Counter < 3) { 370 DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);373 DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl); 371 374 performCriticalExit(); 372 375 } 373 }; 376 } 377 ; 374 378 375 379 /** Destructor of BoundaryTriangleSet. … … 379 383 BoundaryTriangleSet::~BoundaryTriangleSet() 380 384 { 381 385 Info FunctionInfo(__func__); 382 386 for (int i = 0; i < 3; i++) { 383 387 if (lines[i] != NULL) { … … 386 390 } 387 391 if (lines[i]->triangles.empty()) { 388 389 390 392 //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl; 393 delete (lines[i]); 394 lines[i] = NULL; 391 395 } 392 396 } 393 397 } 394 398 //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl; 395 }; 399 } 400 ; 396 401 397 402 /** Calculates the normal vector for this triangle. … … 401 406 void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector) 402 407 { 403 408 Info FunctionInfo(__func__); 404 409 // get normal vector 405 410 NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node); … … 409 414 NormalVector.Scale(-1.); 410 415 Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl; 411 }; 416 } 417 ; 412 418 413 419 /** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses. … … 430 436 431 437 if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) { 432 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);438 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 433 439 return false; 434 440 } … … 441 447 Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl; 442 448 return true; 443 } 449 } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) { 444 450 Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl; 445 451 return true; 446 } 452 } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) { 447 453 Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl; 448 454 return true; 449 455 } 450 456 // Calculate cross point between one baseline and the line from the third endpoint to intersection 451 int i =0;457 int i = 0; 452 458 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();459 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) { 460 helper.CopyVector(endpoints[(i + 1) % 3]->node->node); 461 helper.SubtractVector(endpoints[i % 3]->node->node); 462 CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 463 const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared(); 458 464 Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl; 459 if ((s < -MYEPSILON) || ((s -1.) > MYEPSILON)) {465 if ((s < -MYEPSILON) || ((s - 1.) > MYEPSILON)) { 460 466 Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl; 461 i =4;467 i = 4; 462 468 break; 463 469 } 464 470 i++; 465 } else 471 } else 466 472 break; 467 } while (i <3);468 if (i ==3) {473 } while (i < 3); 474 if (i == 3) { 469 475 Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl; 470 476 return true; … … 473 479 return false; 474 480 } 475 }; 481 } 482 ; 476 483 477 484 /** Finds the point on the triangle to the point \a *x. … … 502 509 Vector InPlane; 503 510 InPlane.CopyVector(x); 504 InPlane.SubtractVector(ClosestPoint); 511 InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point 505 512 InPlane.ProjectOntoPlane(&NormalVector); 506 513 InPlane.AddVector(ClosestPoint); … … 516 523 Vector CrossPoint[3]; 517 524 Vector helper; 518 for (int i =0;i<3;i++) {525 for (int i = 0; i < 3; i++) { 519 526 // 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);527 Direction.CopyVector(endpoints[(i + 1) % 3]->node->node); 528 Direction.SubtractVector(endpoints[i % 3]->node->node); 522 529 // 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);530 CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node); 524 531 CrossDirection[i].CopyVector(&CrossPoint[i]); 525 532 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();533 CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 534 const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared(); 528 535 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;536 if ((s >= -MYEPSILON) && ((s - 1.) <= MYEPSILON)) { 537 CrossPoint[i].AddVector(endpoints[i % 3]->node->node); // make cross point absolute again 538 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 539 const double distance = CrossPoint[i].DistanceSquared(x); 533 540 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { … … 539 546 } 540 547 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 548 for (int i = 0; i < 3; i++) { 549 const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 1) % 3]); 550 const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 2) % 3]); 551 ; 552 if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign 545 553 InsideFlag = false; 546 554 } … … 548 556 ClosestPoint->CopyVector(&InPlane); 549 557 ShortestDistance = InPlane.DistanceSquared(x); 550 } else { 551 for (int i =0;i<3;i++) {558 } else { // also check endnodes 559 for (int i = 0; i < 3; i++) { 552 560 const double distance = x->DistanceSquared(endpoints[i]->node->node); 553 561 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { … … 559 567 Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl; 560 568 return ShortestDistance; 561 }; 569 } 570 ; 562 571 563 572 /** Checks whether lines is any of the three boundary lines this triangle contains. … … 567 576 bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const 568 577 { 569 570 for (int i=0;i<3;i++)578 Info FunctionInfo(__func__); 579 for (int i = 0; i < 3; i++) 571 580 if (line == lines[i]) 572 581 return true; 573 582 return false; 574 }; 583 } 584 ; 575 585 576 586 /** Checks whether point is any of the three endpoints this triangle contains. … … 580 590 bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const 581 591 { 582 583 for (int i=0;i<3;i++)592 Info FunctionInfo(__func__); 593 for (int i = 0; i < 3; i++) 584 594 if (point == endpoints[i]) 585 595 return true; 586 596 return false; 587 }; 597 } 598 ; 588 599 589 600 /** Checks whether point is any of the three endpoints this triangle contains. … … 593 604 bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const 594 605 { 595 596 for (int i=0;i<3;i++)606 Info FunctionInfo(__func__); 607 for (int i = 0; i < 3; i++) 597 608 if (point == endpoints[i]->node) 598 609 return true; 599 610 return false; 600 }; 611 } 612 ; 601 613 602 614 /** Checks whether three given \a *Points coincide with triangle's endpoints. … … 606 618 bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const 607 619 { 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 }; 620 Info FunctionInfo(__func__); 621 Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl; 622 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]) 623 624 )); 625 } 626 ; 624 627 625 628 /** Checks whether three given \a *Points coincide with triangle's endpoints. … … 629 632 bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const 630 633 { 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 }; 634 Info FunctionInfo(__func__); 635 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]) 636 637 )); 638 } 639 ; 646 640 647 641 /** Returns the endpoint which is not contained in the given \a *line. … … 651 645 class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const 652 646 { 653 647 Info FunctionInfo(__func__); 654 648 // sanity check 655 649 if (!ContainsBoundaryLine(line)) 656 650 return NULL; 657 for (int i=0;i<3;i++)651 for (int i = 0; i < 3; i++) 658 652 if (!line->ContainsBoundaryPoint(endpoints[i])) 659 653 return endpoints[i]; 660 654 // actually, that' impossible :) 661 655 return NULL; 662 }; 656 } 657 ; 663 658 664 659 /** Calculates the center point of the triangle. … … 668 663 void BoundaryTriangleSet::GetCenter(Vector * const center) const 669 664 { 670 665 Info FunctionInfo(__func__); 671 666 center->Zero(); 672 for (int i=0;i<3;i++)667 for (int i = 0; i < 3; i++) 673 668 center->AddVector(endpoints[i]->node->node); 674 center->Scale(1. /3.);669 center->Scale(1. / 3.); 675 670 Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl; 676 671 } … … 683 678 { 684 679 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 << "]";680 // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," 681 // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]"; 687 682 return ost; 688 }; 683 } 684 ; 689 685 690 686 // ======================================== Polygons on Boundary ================================= … … 696 692 { 697 693 Info FunctionInfo(__func__); 698 }; 694 } 695 ; 699 696 700 697 /** Destructor of BoundaryPolygonSet. … … 707 704 endpoints.clear(); 708 705 Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl; 709 }; 706 } 707 ; 710 708 711 709 /** Calculates the normal vector for this triangle. … … 721 719 Vector *TotalNormal = new Vector; 722 720 PointSet::const_iterator Runner[3]; 723 for (int i =0;i<3; i++) {721 for (int i = 0; i < 3; i++) { 724 722 Runner[i] = endpoints.begin(); 725 for (int j = 0; j <i; j++) { // go as much further723 for (int j = 0; j < i; j++) { // go as much further 726 724 Runner[i]++; 727 725 if (Runner[i] == endpoints.end()) { 728 DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);726 DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl); 729 727 performCriticalExit(); 730 728 } … … 732 730 } 733 731 TotalNormal->Zero(); 734 int counter =0;735 for (; Runner[2] != endpoints.end(); 732 int counter = 0; 733 for (; Runner[2] != endpoints.end();) { 736 734 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 them735 for (int i = 0; i < 3; i++) // increase each of them 738 736 Runner[i]++; 739 737 TotalNormal->AddVector(&TemporaryNormal); 740 738 } 741 TotalNormal->Scale(1. /(double)counter);739 TotalNormal->Scale(1. / (double) counter); 742 740 743 741 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) … … 747 745 748 746 return TotalNormal; 749 }; 747 } 748 ; 750 749 751 750 /** Calculates the center point of the triangle. … … 758 757 center->Zero(); 759 758 int counter = 0; 760 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {759 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 761 760 center->AddVector((*Runner)->node->node); 762 761 counter++; 763 762 } 764 center->Scale(1. /(double)counter);763 center->Scale(1. / (double) counter); 765 764 Log() << Verbose(1) << "Center is at " << *center << "." << endl; 766 765 } … … 774 773 Info FunctionInfo(__func__); 775 774 return ContainsPresentTupel(triangle->endpoints, 3); 776 }; 775 } 776 ; 777 777 778 778 /** Checks whether the polygons contains both endpoints of the line. … … 784 784 Info FunctionInfo(__func__); 785 785 return ContainsPresentTupel(line->endpoints, 2); 786 }; 786 } 787 ; 787 788 788 789 /** Checks whether point is any of the three endpoints this triangle contains. … … 793 794 { 794 795 Info FunctionInfo(__func__); 795 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {796 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 796 797 Log() << Verbose(0) << "Checking against " << **Runner << endl; 797 798 if (point == (*Runner)) { … … 802 803 Log() << Verbose(0) << " Not contained." << endl; 803 804 return false; 804 }; 805 } 806 ; 805 807 806 808 /** Checks whether point is any of the three endpoints this triangle contains. … … 811 813 { 812 814 Info FunctionInfo(__func__); 813 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)815 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) 814 816 if (point == (*Runner)->node) { 815 817 Log() << Verbose(0) << " Contained." << endl; … … 818 820 Log() << Verbose(0) << " Not contained." << endl; 819 821 return false; 820 }; 822 } 823 ; 821 824 822 825 /** Checks whether given array of \a *Points coincide with polygons's endpoints. … … 830 833 int counter = 0; 831 834 Log() << Verbose(1) << "Polygon is " << *this << endl; 832 for (int i=0;i<dim;i++) {835 for (int i = 0; i < dim; i++) { 833 836 Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl; 834 837 if (ContainsBoundaryPoint(Points[i])) { … … 841 844 else 842 845 return false; 843 }; 846 } 847 ; 844 848 845 849 /** Checks whether given PointList coincide with polygons's endpoints. … … 852 856 size_t counter = 0; 853 857 Log() << Verbose(1) << "Polygon is " << *this << endl; 854 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {858 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 855 859 Log() << Verbose(1) << " Testing endpoint " << **Runner << endl; 856 860 if (ContainsBoundaryPoint(*Runner)) … … 862 866 else 863 867 return false; 864 }; 868 } 869 ; 865 870 866 871 /** Checks whether given set of \a *Points coincide with polygons's endpoints. … … 870 875 bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const 871 876 { 872 return ContainsPresentTupel((const PointSet)P->endpoints); 873 }; 877 return ContainsPresentTupel((const PointSet) P->endpoints); 878 } 879 ; 874 880 875 881 /** Gathers all the endpoints' triangles in a unique set. … … 879 885 { 880 886 Info FunctionInfo(__func__); 881 pair 887 pair<TriangleSet::iterator, bool> Tester; 882 888 TriangleSet *triangles = new TriangleSet; 883 889 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++) {890 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) 891 for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++) 892 for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) { 887 893 //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl; 888 894 if (ContainsBoundaryTriangle(Sprinter->second)) { … … 895 901 Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl; 896 902 return triangles; 897 }; 903 } 904 ; 898 905 899 906 /** Fills the endpoints of this polygon from the triangles attached to \a *line. … … 904 911 { 905 912 Info FunctionInfo(__func__); 906 pair 913 pair<PointSet::iterator, bool> Tester; 907 914 if (line == NULL) 908 915 return false; 909 916 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 for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) { 918 for (int i = 0; i < 3; i++) { 912 919 Tester = endpoints.insert((Runner->second)->endpoints[i]); 913 920 if (Tester.second) … … 917 924 918 925 return true; 919 }; 926 } 927 ; 920 928 921 929 /** output operator for BoundaryPolygonSet. … … 926 934 { 927 935 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 << "]";936 for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) { 937 ost << (*Runner)->node->Name; 938 Runner++; 939 if (Runner != a.endpoints.end()) 940 ost << ","; 941 } 942 ost << "]"; 935 943 return ost; 936 }; 944 } 945 ; 937 946 938 947 // =========================================================== class TESSELPOINT =========================================== … … 945 954 node = NULL; 946 955 nr = -1; 947 Name = NULL; 948 }; 956 Name = NULL; 957 } 958 ; 949 959 950 960 /** Destructor for class TesselPoint. … … 953 963 { 954 964 //Info FunctionInfo(__func__); 955 }; 965 } 966 ; 956 967 957 968 /** Prints LCNode to screen. 958 969 */ 959 ostream & operator << 970 ostream & operator <<(ostream &ost, const TesselPoint &a) 960 971 { 961 972 ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]"; 962 973 return ost; 963 }; 974 } 975 ; 964 976 965 977 /** Prints LCNode to screen. 966 978 */ 967 ostream & TesselPoint::operator << 968 { 969 979 ostream & TesselPoint::operator <<(ostream &ost) 980 { 981 Info FunctionInfo(__func__); 970 982 ost << "[" << (nr) << "|" << this << "]"; 971 983 return ost; 972 } ;973 984 } 985 ; 974 986 975 987 // =========================================================== class POINTCLOUD ============================================ … … 979 991 PointCloud::PointCloud() 980 992 { 981 //Info FunctionInfo(__func__); 982 }; 993 //Info FunctionInfo(__func__); 994 } 995 ; 983 996 984 997 /** Destructor for class PointCloud. … … 986 999 PointCloud::~PointCloud() 987 1000 { 988 //Info FunctionInfo(__func__); 989 }; 1001 //Info FunctionInfo(__func__); 1002 } 1003 ; 990 1004 991 1005 // ============================ CandidateForTesselation ============================= … … 993 1007 /** Constructor of class CandidateForTesselation. 994 1008 */ 995 CandidateForTesselation::CandidateForTesselation (BoundaryLineSet* line) : 996 BaseLine(line), 997 ThirdPoint(NULL), 998 T(NULL), 999 ShortestAngle(2.*M_PI), 1000 OtherShortestAngle(2.*M_PI) 1001 { 1002 Info FunctionInfo(__func__); 1003 }; 1004 1009 CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) : 1010 BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI) 1011 { 1012 Info FunctionInfo(__func__); 1013 } 1014 ; 1005 1015 1006 1016 /** Constructor of class CandidateForTesselation. 1007 1017 */ 1008 CandidateForTesselation::CandidateForTesselation (TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) : 1009 BaseLine(line), 1010 ThirdPoint(point), 1011 T(NULL), 1012 ShortestAngle(2.*M_PI), 1013 OtherShortestAngle(2.*M_PI) 1014 { 1015 Info FunctionInfo(__func__); 1018 CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) : 1019 BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI) 1020 { 1021 Info FunctionInfo(__func__); 1016 1022 OptCenter.CopyVector(&OptCandidateCenter); 1017 1023 OtherOptCenter.CopyVector(&OtherOptCandidateCenter); 1018 }; 1024 } 1025 ; 1019 1026 1020 1027 /** Destructor for class CandidateForTesselation. 1021 1028 */ 1022 CandidateForTesselation::~CandidateForTesselation() { 1023 }; 1029 CandidateForTesselation::~CandidateForTesselation() 1030 { 1031 } 1032 ; 1024 1033 1025 1034 /** Checks validity of a given sphere of a candidate line. … … 1033 1042 Info FunctionInfo(__func__); 1034 1043 1035 const double radiusSquared = RADIUS *RADIUS;1044 const double radiusSquared = RADIUS * RADIUS; 1036 1045 list<const Vector *> VectorList; 1037 1046 VectorList.push_back(&OptCenter); … … 1039 1048 1040 1049 if (!pointlist.empty()) 1041 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list " << *(*pointlist.begin()) << "and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);1050 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl); 1042 1051 else 1043 1052 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl); 1044 1053 // check baseline for OptCenter and OtherOptCenter being on sphere's surface 1045 1054 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1046 for (int i =0;i<2;i++) {1055 for (int i = 0; i < 2; i++) { 1047 1056 const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared); 1048 1057 if (distance > HULLEPSILON) { 1049 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << setprecision(13) <<distance << "." << endl);1058 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); 1050 1059 return false; 1051 1060 } … … 1054 1063 1055 1064 // check Candidates for OptCenter and OtherOptCenter being on sphere's surface 1056 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist. begin(); ++Runner) {1065 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) { 1057 1066 const TesselPoint *Walker = *Runner; 1058 1067 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1059 1068 const double distance = fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared); 1060 1069 if (distance > HULLEPSILON) { 1061 DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << Walker << " is out of sphere at " << *(*VRunner) << " by " << setprecision(13)<< distance << "." << endl);1070 DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); 1062 1071 return false; 1072 } else { 1073 Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl; 1063 1074 } 1064 1075 } … … 1070 1081 // get all points inside the sphere 1071 1082 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner)); 1083 1084 Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl; 1085 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 1086 Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&OtherOptCenter) << "." << endl; 1087 1072 1088 // remove baseline's endpoints and candidates 1073 for (int i=0;i<2;i++) 1089 for (int i = 0; i < 2; i++) { 1090 Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl; 1074 1091 ListofPoints->remove(BaseLine->endpoints[i]->node); 1075 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) 1092 } 1093 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) { 1094 Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl; 1076 1095 ListofPoints->remove(*Runner); 1096 } 1077 1097 if (!ListofPoints->empty()) { 1078 cout << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl;1098 DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl); 1079 1099 flag = false; 1080 1100 DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl); … … 1082 1102 DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << endl); 1083 1103 } 1084 delete (ListofPoints);1104 delete (ListofPoints); 1085 1105 1086 1106 // check with animate_sphere.tcl VMD script 1087 1107 if (ThirdPoint != NULL) { 1088 cout << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr+1 << " " << BaseLine->endpoints[1]->Nr+1 << " " << ThirdPoint->Nr+1 << " " << RADIUS << " "; 1089 cout << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " "; 1090 cout << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl; 1108 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; 1091 1109 } else { 1092 cout << Verbose(1) << "Check by: ... missing third point ..." << endl; 1093 cout << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr+1 << " " << BaseLine->endpoints[1]->Nr+1 << " ??? " << RADIUS << " "; 1094 cout << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " "; 1095 cout << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl; 1110 Log() << Verbose(1) << "Check by: ... missing third point ..." << endl; 1111 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; 1096 1112 } 1097 1113 } 1098 1114 return flag; 1099 }; 1115 } 1116 ; 1100 1117 1101 1118 /** output operator for CandidateForTesselation. … … 1103 1120 * \param &a boundary line 1104 1121 */ 1105 ostream & operator <<(ostream &ost, const 1122 ostream & operator <<(ostream &ost, const CandidateForTesselation &a) 1106 1123 { 1107 1124 ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with "; … … 1116 1133 for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++) 1117 1134 ost << *(*Runner) << " "; 1118 ost << " at angle " << (a.ShortestAngle) << ".";1135 ost << " at angle " << (a.ShortestAngle) << "."; 1119 1136 } 1120 1137 1121 1138 return ost; 1122 } ;1123 1139 } 1140 ; 1124 1141 1125 1142 // =========================================================== class TESSELATION =========================================== … … 1128 1145 */ 1129 1146 Tesselation::Tesselation() : 1130 PointsOnBoundaryCount(0), 1131 LinesOnBoundaryCount(0), 1132 TrianglesOnBoundaryCount(0), 1133 LastTriangle(NULL), 1134 TriangleFilesWritten(0), 1135 InternalPointer(PointsOnBoundary.begin()) 1136 { 1137 Info FunctionInfo(__func__); 1147 PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin()) 1148 { 1149 Info FunctionInfo(__func__); 1138 1150 } 1139 1151 ; … … 1144 1156 Tesselation::~Tesselation() 1145 1157 { 1146 1158 Info FunctionInfo(__func__); 1147 1159 Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl; 1148 1160 for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) { … … 1151 1163 runner->second = NULL; 1152 1164 } else 1153 DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);1165 DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl); 1154 1166 } 1155 1167 Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl; … … 1159 1171 /** PointCloud implementation of GetCenter 1160 1172 * Uses PointsOnBoundary and STL stuff. 1161 */ 1173 */ 1162 1174 Vector * Tesselation::GetCenter(ofstream *out) const 1163 1175 { 1164 1165 Vector *Center = new Vector(0., 0.,0.);1166 int num =0;1176 Info FunctionInfo(__func__); 1177 Vector *Center = new Vector(0., 0., 0.); 1178 int num = 0; 1167 1179 for (GoToFirst(); (!IsEnd()); GoToNext()) { 1168 1180 Center->AddVector(GetPoint()->node); 1169 1181 num++; 1170 1182 } 1171 Center->Scale(1. /num);1183 Center->Scale(1. / num); 1172 1184 return Center; 1173 }; 1185 } 1186 ; 1174 1187 1175 1188 /** PointCloud implementation of GoPoint 1176 1189 * Uses PointsOnBoundary and STL stuff. 1177 */ 1190 */ 1178 1191 TesselPoint * Tesselation::GetPoint() const 1179 1192 { 1180 1193 Info FunctionInfo(__func__); 1181 1194 return (InternalPointer->second->node); 1182 }; 1195 } 1196 ; 1183 1197 1184 1198 /** PointCloud implementation of GetTerminalPoint. 1185 1199 * Uses PointsOnBoundary and STL stuff. 1186 */ 1200 */ 1187 1201 TesselPoint * Tesselation::GetTerminalPoint() const 1188 1202 { 1189 1203 Info FunctionInfo(__func__); 1190 1204 PointMap::const_iterator Runner = PointsOnBoundary.end(); 1191 1205 Runner--; 1192 1206 return (Runner->second->node); 1193 }; 1207 } 1208 ; 1194 1209 1195 1210 /** PointCloud implementation of GoToNext. 1196 1211 * Uses PointsOnBoundary and STL stuff. 1197 */ 1212 */ 1198 1213 void Tesselation::GoToNext() const 1199 1214 { 1200 1215 Info FunctionInfo(__func__); 1201 1216 if (InternalPointer != PointsOnBoundary.end()) 1202 1217 InternalPointer++; 1203 }; 1218 } 1219 ; 1204 1220 1205 1221 /** PointCloud implementation of GoToPrevious. 1206 1222 * Uses PointsOnBoundary and STL stuff. 1207 */ 1223 */ 1208 1224 void Tesselation::GoToPrevious() const 1209 1225 { 1210 1226 Info FunctionInfo(__func__); 1211 1227 if (InternalPointer != PointsOnBoundary.begin()) 1212 1228 InternalPointer--; 1213 }; 1229 } 1230 ; 1214 1231 1215 1232 /** PointCloud implementation of GoToFirst. 1216 1233 * Uses PointsOnBoundary and STL stuff. 1217 */ 1234 */ 1218 1235 void Tesselation::GoToFirst() const 1219 1236 { 1220 1237 Info FunctionInfo(__func__); 1221 1238 InternalPointer = PointsOnBoundary.begin(); 1222 }; 1239 } 1240 ; 1223 1241 1224 1242 /** PointCloud implementation of GoToLast. … … 1227 1245 void Tesselation::GoToLast() const 1228 1246 { 1229 1247 Info FunctionInfo(__func__); 1230 1248 InternalPointer = PointsOnBoundary.end(); 1231 1249 InternalPointer--; 1232 }; 1250 } 1251 ; 1233 1252 1234 1253 /** PointCloud implementation of IsEmpty. 1235 1254 * Uses PointsOnBoundary and STL stuff. 1236 */ 1255 */ 1237 1256 bool Tesselation::IsEmpty() const 1238 1257 { 1239 1258 Info FunctionInfo(__func__); 1240 1259 return (PointsOnBoundary.empty()); 1241 }; 1260 } 1261 ; 1242 1262 1243 1263 /** PointCloud implementation of IsLast. 1244 1264 * Uses PointsOnBoundary and STL stuff. 1245 */ 1265 */ 1246 1266 bool Tesselation::IsEnd() const 1247 1267 { 1248 1268 Info FunctionInfo(__func__); 1249 1269 return (InternalPointer == PointsOnBoundary.end()); 1250 } ;1251 1270 } 1271 ; 1252 1272 1253 1273 /** Gueses first starting triangle of the convex envelope. … … 1258 1278 void Tesselation::GuessStartingTriangle() 1259 1279 { 1260 1280 Info FunctionInfo(__func__); 1261 1281 // 4b. create a starting triangle 1262 1282 // 4b1. create all distances … … 1268 1288 1269 1289 // with A chosen, take each pair B,C and sort 1270 if (A != PointsOnBoundary.end()) 1271 { 1272 B = A; 1273 B++; 1274 for (; B != PointsOnBoundary.end(); B++) 1275 { 1276 C = B; 1277 C++; 1278 for (; C != PointsOnBoundary.end(); C++) 1279 { 1280 tmp = A->second->node->node->DistanceSquared(B->second->node->node); 1281 distance = tmp * tmp; 1282 tmp = A->second->node->node->DistanceSquared(C->second->node->node); 1283 distance += tmp * tmp; 1284 tmp = B->second->node->node->DistanceSquared(C->second->node->node); 1285 distance += tmp * tmp; 1286 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); 1287 } 1288 } 1289 } 1290 if (A != PointsOnBoundary.end()) { 1291 B = A; 1292 B++; 1293 for (; B != PointsOnBoundary.end(); B++) { 1294 C = B; 1295 C++; 1296 for (; C != PointsOnBoundary.end(); C++) { 1297 tmp = A->second->node->node->DistanceSquared(B->second->node->node); 1298 distance = tmp * tmp; 1299 tmp = A->second->node->node->DistanceSquared(C->second->node->node); 1300 distance += tmp * tmp; 1301 tmp = B->second->node->node->DistanceSquared(C->second->node->node); 1302 distance += tmp * tmp; 1303 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); 1304 } 1305 } 1306 } 1290 1307 // // listing distances 1291 1308 // Log() << Verbose(1) << "Listing DistanceMMap:"; … … 1297 1314 // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate 1298 1315 DistanceMultiMap::iterator baseline = DistanceMMap.begin(); 1299 for (; baseline != DistanceMMap.end(); baseline++) 1300 { 1301 // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate 1302 // 2. next, we have to check whether all points reside on only one side of the triangle 1303 // 3. construct plane vector 1304 PlaneVector.MakeNormalVector(A->second->node->node, 1305 baseline->second.first->second->node->node, 1306 baseline->second.second->second->node->node); 1307 Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl; 1308 // 4. loop over all points 1309 double sign = 0.; 1310 PointMap::iterator checker = PointsOnBoundary.begin(); 1311 for (; checker != PointsOnBoundary.end(); checker++) 1312 { 1313 // (neglecting A,B,C) 1314 if ((checker == A) || (checker == baseline->second.first) || (checker 1315 == baseline->second.second)) 1316 continue; 1317 // 4a. project onto plane vector 1318 TrialVector.CopyVector(checker->second->node->node); 1319 TrialVector.SubtractVector(A->second->node->node); 1320 distance = TrialVector.ScalarProduct(&PlaneVector); 1321 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1322 continue; 1323 Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl; 1324 tmp = distance / fabs(distance); 1325 // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle) 1326 if ((sign != 0) && (tmp != sign)) 1327 { 1328 // 4c. If so, break 4. loop and continue with next candidate in 1. loop 1329 Log() << Verbose(2) << "Current candidates: " 1330 << A->second->node->Name << "," 1331 << baseline->second.first->second->node->Name << "," 1332 << baseline->second.second->second->node->Name << " leaves " 1333 << checker->second->node->Name << " outside the convex hull." 1334 << endl; 1335 break; 1336 } 1337 else 1338 { // note the sign for later 1339 Log() << Verbose(2) << "Current candidates: " 1340 << A->second->node->Name << "," 1341 << baseline->second.first->second->node->Name << "," 1342 << baseline->second.second->second->node->Name << " leave " 1343 << checker->second->node->Name << " inside the convex hull." 1344 << 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( 1351 baseline->second.first->second->node->node)) && (tmp 1352 < A->second->node->node->DistanceSquared( 1353 baseline->second.second->second->node->node))) 1354 innerpoint++; 1355 tmp = checker->second->node->node->DistanceSquared( 1356 baseline->second.first->second->node->node); 1357 if ((tmp < baseline->second.first->second->node->node->DistanceSquared( 1358 A->second->node->node)) && (tmp 1359 < baseline->second.first->second->node->node->DistanceSquared( 1360 baseline->second.second->second->node->node))) 1361 innerpoint++; 1362 tmp = checker->second->node->node->DistanceSquared( 1363 baseline->second.second->second->node->node); 1364 if ((tmp < baseline->second.second->second->node->node->DistanceSquared( 1365 baseline->second.first->second->node->node)) && (tmp 1366 < baseline->second.second->second->node->node->DistanceSquared( 1367 A->second->node->node))) 1368 innerpoint++; 1369 // 4e. If so, break 4. loop and continue with next candidate in 1. loop 1370 if (innerpoint == 3) 1371 break; 1372 } 1373 // 5. come this far, all on same side? Then break 1. loop and construct triangle 1374 if (checker == PointsOnBoundary.end()) 1375 { 1376 Log() << Verbose(2) << "Looks like we have a candidate!" << endl; 1377 break; 1378 } 1379 } 1380 if (baseline != DistanceMMap.end()) 1381 { 1382 BPS[0] = baseline->second.first->second; 1383 BPS[1] = baseline->second.second->second; 1384 BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1385 BPS[0] = A->second; 1386 BPS[1] = baseline->second.second->second; 1387 BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1388 BPS[0] = baseline->second.first->second; 1389 BPS[1] = A->second; 1390 BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1391 1392 // 4b3. insert created triangle 1393 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1394 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); 1395 TrianglesOnBoundaryCount++; 1396 for (int i = 0; i < NDIM; i++) 1397 { 1398 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i])); 1399 LinesOnBoundaryCount++; 1400 } 1401 1402 Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl; 1403 } 1404 else 1405 { 1406 DoeLog(0) && (eLog()<< Verbose(0) << "No starting triangle found." << endl); 1407 } 1316 for (; baseline != DistanceMMap.end(); baseline++) { 1317 // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate 1318 // 2. next, we have to check whether all points reside on only one side of the triangle 1319 // 3. construct plane vector 1320 PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node); 1321 Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl; 1322 // 4. loop over all points 1323 double sign = 0.; 1324 PointMap::iterator checker = PointsOnBoundary.begin(); 1325 for (; checker != PointsOnBoundary.end(); checker++) { 1326 // (neglecting A,B,C) 1327 if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second)) 1328 continue; 1329 // 4a. project onto plane vector 1330 TrialVector.CopyVector(checker->second->node->node); 1331 TrialVector.SubtractVector(A->second->node->node); 1332 distance = TrialVector.ScalarProduct(&PlaneVector); 1333 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1334 continue; 1335 Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl; 1336 tmp = distance / fabs(distance); 1337 // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle) 1338 if ((sign != 0) && (tmp != sign)) { 1339 // 4c. If so, break 4. loop and continue with next candidate in 1. loop 1340 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; 1341 break; 1342 } else { // note the sign for later 1343 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; 1344 sign = tmp; 1345 } 1346 // 4d. Check whether the point is inside the triangle (check distance to each node 1347 tmp = checker->second->node->node->DistanceSquared(A->second->node->node); 1348 int innerpoint = 0; 1349 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))) 1350 innerpoint++; 1351 tmp = checker->second->node->node->DistanceSquared(baseline->second.first->second->node->node); 1352 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))) 1353 innerpoint++; 1354 tmp = checker->second->node->node->DistanceSquared(baseline->second.second->second->node->node); 1355 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))) 1356 innerpoint++; 1357 // 4e. If so, break 4. loop and continue with next candidate in 1. loop 1358 if (innerpoint == 3) 1359 break; 1360 } 1361 // 5. come this far, all on same side? Then break 1. loop and construct triangle 1362 if (checker == PointsOnBoundary.end()) { 1363 Log() << Verbose(2) << "Looks like we have a candidate!" << endl; 1364 break; 1365 } 1366 } 1367 if (baseline != DistanceMMap.end()) { 1368 BPS[0] = baseline->second.first->second; 1369 BPS[1] = baseline->second.second->second; 1370 BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1371 BPS[0] = A->second; 1372 BPS[1] = baseline->second.second->second; 1373 BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1374 BPS[0] = baseline->second.first->second; 1375 BPS[1] = A->second; 1376 BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1377 1378 // 4b3. insert created triangle 1379 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1380 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); 1381 TrianglesOnBoundaryCount++; 1382 for (int i = 0; i < NDIM; i++) { 1383 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i])); 1384 LinesOnBoundaryCount++; 1385 } 1386 1387 Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl; 1388 } else { 1389 DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl); 1390 } 1408 1391 } 1409 1392 ; … … 1424 1407 void Tesselation::TesselateOnBoundary(const PointCloud * const cloud) 1425 1408 { 1426 1409 Info FunctionInfo(__func__); 1427 1410 bool flag; 1428 1411 PointMap::iterator winner; … … 1493 1476 TempAngle = VirtualNormalVector.Angle(&PropagationVector); 1494 1477 Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl; 1495 if (TempAngle > (M_PI /2.)) { // no bends bigger than Pi/2 (90 degrees)1478 if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees) 1496 1479 Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl; 1497 1480 continue; … … 1534 1517 TempVector.AddVector(baseline->second->endpoints[1]->node->node); 1535 1518 TempVector.AddVector(target->second->node->node); 1536 TempVector.Scale(1. /3.);1519 TempVector.Scale(1. / 3.); 1537 1520 TempVector.SubtractVector(Center); 1538 1521 // make it always point outward … … 1603 1586 TrianglesOnBoundaryCount++; 1604 1587 } else { 1605 DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);1588 DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl); 1606 1589 } 1607 1590 … … 1612 1595 1613 1596 // exit 1614 delete(Center); 1615 }; 1597 delete (Center); 1598 } 1599 ; 1616 1600 1617 1601 /** Inserts all points outside of the tesselated surface into it by adding new triangles. … … 1623 1607 bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC) 1624 1608 { 1625 1609 Info FunctionInfo(__func__); 1626 1610 Vector Intersection, Normal; 1627 1611 TesselPoint *Walker = NULL; … … 1633 1617 cloud->GoToFirst(); 1634 1618 BoundaryPoints = new LinkedCell(this, 5.); 1635 while (!cloud->IsEnd()) { 1619 while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger 1636 1620 if (AddFlag) { 1637 delete (BoundaryPoints);1621 delete (BoundaryPoints); 1638 1622 BoundaryPoints = new LinkedCell(this, 5.); 1639 1623 AddFlag = false; … … 1664 1648 class BoundaryPointSet *OldPoints[3], *NewPoint; 1665 1649 // store the three old lines and old points 1666 for (int i =0;i<3;i++) {1650 for (int i = 0; i < 3; i++) { 1667 1651 OldLines[i] = BTS->lines[i]; 1668 1652 OldPoints[i] = BTS->endpoints[i]; … … 1672 1656 Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl; 1673 1657 AddFlag = true; 1674 if (AddBoundaryPoint(Walker, 0))1658 if (AddBoundaryPoint(Walker, 0)) 1675 1659 NewPoint = BPS[0]; 1676 1660 else … … 1679 1663 Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl; 1680 1664 TrianglesOnBoundary.erase(BTS->Nr); 1681 delete (BTS);1665 delete (BTS); 1682 1666 // create three new boundary lines 1683 for (int i =0;i<3;i++) {1667 for (int i = 0; i < 3; i++) { 1684 1668 BPS[0] = NewPoint; 1685 1669 BPS[1] = OldPoints[i]; … … 1690 1674 } 1691 1675 // create three new triangle with new point 1692 for (int i =0;i<3;i++) { // find all baselines1676 for (int i = 0; i < 3; i++) { // find all baselines 1693 1677 BLS[0] = OldLines[i]; 1694 1678 int n = 1; 1695 for (int j =0;j<3;j++) {1679 for (int j = 0; j < 3; j++) { 1696 1680 if (NewLines[j]->IsConnectedTo(BLS[0])) { 1697 if (n >2) {1698 DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);1681 if (n > 2) { 1682 DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl); 1699 1683 return false; 1700 1684 } else … … 1713 1697 } 1714 1698 } else { // something is wrong with FindClosestTriangleToPoint! 1715 DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);1699 DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl); 1716 1700 return false; 1717 1701 } … … 1720 1704 1721 1705 // exit 1722 delete (Center);1706 delete (Center); 1723 1707 return true; 1724 }; 1708 } 1709 ; 1725 1710 1726 1711 /** Adds a point to the tesselation::PointsOnBoundary list. … … 1731 1716 bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n) 1732 1717 { 1733 1718 Info FunctionInfo(__func__); 1734 1719 PointTestPair InsertUnique; 1735 1720 BPS[n] = new class BoundaryPointSet(Walker); … … 1739 1724 return true; 1740 1725 } else { 1741 delete (BPS[n]);1726 delete (BPS[n]); 1742 1727 BPS[n] = InsertUnique.first->second; 1743 1728 return false; … … 1753 1738 void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n) 1754 1739 { 1755 1740 Info FunctionInfo(__func__); 1756 1741 PointTestPair InsertUnique; 1757 1742 TPS[n] = new class BoundaryPointSet(Candidate); … … 1774 1759 void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const 1775 1760 { 1776 1761 Info FunctionInfo(__func__); 1777 1762 PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr); 1778 1763 if (FindPoint != PointsOnBoundary.end()) … … 1780 1765 else 1781 1766 TPS[n] = NULL; 1782 }; 1767 } 1768 ; 1783 1769 1784 1770 /** Function tries to add line from current Points in BPS to BoundaryLineSet. … … 1791 1777 * @param n index of Tesselation::BLS giving the line with both endpoints 1792 1778 */ 1793 void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) { 1779 void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) 1780 { 1794 1781 bool insertNewLine = true; 1795 1796 1782 LineMap::iterator FindLine = a->lines.find(b->node->nr); 1797 1783 BoundaryLineSet *WinningLine = NULL; … … 1799 1785 Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl; 1800 1786 1801 pair<LineMap::iterator, LineMap::iterator> FindPair;1787 pair<LineMap::iterator, LineMap::iterator> FindPair; 1802 1788 FindPair = a->lines.equal_range(b->node->nr); 1803 1789 1804 for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {1790 for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) { 1805 1791 Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl; 1806 1792 // If there is a line with less than two attached triangles, we don't need a new line. … … 1812 1798 Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl; 1813 1799 // get open line 1814 if ((!Finder->second->pointlist.empty()) && (*(Finder->second->pointlist.begin()) == candidate->node) 1815 && (OptCenter == NULL || *OptCenter == Finder->second->OptCenter)) { // stop searching if candidate matches 1816 insertNewLine = false; 1817 WinningLine = FindLine->second; 1818 break; 1800 for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) { 1801 if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || *OptCenter == Finder->second->OptCenter)) { // stop searching if candidate matches 1802 insertNewLine = false; 1803 WinningLine = FindLine->second; 1804 break; 1805 } 1819 1806 } 1820 1807 } … … 1840 1827 void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) 1841 1828 { 1842 1829 Info FunctionInfo(__func__); 1843 1830 Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl; 1844 1831 BPS[0] = a; 1845 1832 BPS[1] = b; 1846 BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1833 BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps 1847 1834 // add line to global map 1848 1835 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n])); … … 1851 1838 // also add to open lines 1852 1839 CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]); 1853 OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT)); 1854 }; 1840 OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT)); 1841 } 1842 ; 1855 1843 1856 1844 /** Uses an existing line for a new triangle. … … 1868 1856 BPS[1] = Line->endpoints[1]; 1869 1857 BLS[n] = Line; 1870 1871 1858 // remove existing line from OpenLines 1872 1859 CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]); 1873 1860 if (CandidateLine != OpenLines.end()) { 1874 1861 Log() << Verbose(1) << " Removing line from OpenLines." << endl; 1875 delete (CandidateLine->second);1862 delete (CandidateLine->second); 1876 1863 OpenLines.erase(CandidateLine); 1877 1864 } else { 1878 DoeLog(1) && (eLog()<< Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl); 1879 } 1880 }; 1865 DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl); 1866 } 1867 } 1868 ; 1881 1869 1882 1870 /** Function adds triangle to global list. … … 1885 1873 void Tesselation::AddTesselationTriangle() 1886 1874 { 1887 1875 Info FunctionInfo(__func__); 1888 1876 Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl; 1889 1877 … … 1896 1884 1897 1885 // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet 1898 }; 1886 } 1887 ; 1899 1888 1900 1889 /** Function adds triangle to global list. … … 1904 1893 void Tesselation::AddTesselationTriangle(const int nr) 1905 1894 { 1906 1895 Info FunctionInfo(__func__); 1907 1896 Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl; 1908 1897 … … 1914 1903 1915 1904 // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet 1916 }; 1905 } 1906 ; 1917 1907 1918 1908 /** Removes a triangle from the tesselation. … … 1923 1913 void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle) 1924 1914 { 1925 1915 Info FunctionInfo(__func__); 1926 1916 if (triangle == NULL) 1927 1917 return; … … 1931 1921 triangle->lines[i]->triangles.erase(triangle->Nr); 1932 1922 if (triangle->lines[i]->triangles.empty()) { 1933 1934 1923 Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl; 1924 RemoveTesselationLine(triangle->lines[i]); 1935 1925 } else { 1936 1926 Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: "; 1937 OpenLines.insert(pair< 1938 for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)1927 OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL)); 1928 for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++) 1939 1929 Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t"; 1940 1930 Log() << Verbose(0) << endl; 1941 // for (int j=0;j<2;j++) {1942 // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";1943 // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)1944 // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";1945 // Log() << Verbose(0) << endl;1946 // }1931 // for (int j=0;j<2;j++) { 1932 // Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": "; 1933 // for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++) 1934 // Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t"; 1935 // Log() << Verbose(0) << endl; 1936 // } 1947 1937 } 1948 triangle->lines[i] = NULL; 1938 triangle->lines[i] = NULL; // free'd or not: disconnect 1949 1939 } else 1950 DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);1940 DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl); 1951 1941 } 1952 1942 1953 1943 if (TrianglesOnBoundary.erase(triangle->Nr)) 1954 1944 Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl; 1955 delete(triangle); 1956 }; 1945 delete (triangle); 1946 } 1947 ; 1957 1948 1958 1949 /** Removes a line from the tesselation. … … 1962 1953 void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line) 1963 1954 { 1964 1955 Info FunctionInfo(__func__); 1965 1956 int Numbers[2]; 1966 1957 … … 1996 1987 } else { 1997 1988 Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: "; 1998 for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)1989 for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++) 1999 1990 Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t"; 2000 1991 Log() << Verbose(0) << endl; 2001 1992 } 2002 line->endpoints[i] = NULL; 1993 line->endpoints[i] = NULL; // free'd or not: disconnect 2003 1994 } else 2004 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);1995 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl); 2005 1996 } 2006 1997 if (!line->triangles.empty()) 2007 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);1998 DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl); 2008 1999 2009 2000 if (LinesOnBoundary.erase(line->Nr)) 2010 2001 Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl; 2011 delete(line); 2012 }; 2002 delete (line); 2003 } 2004 ; 2013 2005 2014 2006 /** Removes a point from the tesselation. … … 2019 2011 void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point) 2020 2012 { 2021 2013 Info FunctionInfo(__func__); 2022 2014 if (point == NULL) 2023 2015 return; 2024 2016 if (PointsOnBoundary.erase(point->Nr)) 2025 2017 Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl; 2026 delete (point);2027 } ;2028 2018 delete (point); 2019 } 2020 ; 2029 2021 2030 2022 /** Checks validity of a given sphere of a candidate line. 2031 2023 * \sa CandidateForTesselation::CheckValidity(), which is more evolved. 2032 * Note that endpoints are stored in Tesselation::TPS.2033 * \param *OtherOptCenter center of the other triangle2024 * We check CandidateForTesselation::OtherOptCenter 2025 * \param &CandidateLine contains other degenerated candidates which we have to subtract as well 2034 2026 * \param RADIUS radius of sphere 2035 2027 * \param *LC LinkedCell structure with other atoms 2036 2028 * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated 2037 2029 */ 2038 bool Tesselation::CheckDegeneracy( Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC) const2030 bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const 2039 2031 { 2040 2032 Info FunctionInfo(__func__); … … 2043 2035 bool flag = true; 2044 2036 2045 cout << Verbose(1) << "Check by: draw sphere {" << OtherOptCenter->x[0] << " " << OtherOptCenter->x[1] << " " << OtherOptCenter->x[2] << "} radius " << RADIUS << " resolution 30" << endl; 2046 2037 Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter.x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl; 2047 2038 // get all points inside the sphere 2048 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, OtherOptCenter);2049 2050 Log() << Verbose(1) << "The following atoms are inside sphere at " << *OtherOptCenter << ":" << endl;2039 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter); 2040 2041 Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl; 2051 2042 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2052 Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( OtherOptCenter) << "." << endl;2043 Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl; 2053 2044 2054 2045 // remove triangles's endpoints 2055 for (int i=0;i<3;i++) 2056 ListofPoints->remove(TPS[i]->node); 2046 for (int i = 0; i < 2; i++) 2047 ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node); 2048 2049 // remove other candidates 2050 for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner) 2051 ListofPoints->remove(*Runner); 2057 2052 2058 2053 // check for other points … … 2060 2055 Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl; 2061 2056 flag = false; 2062 Log() << Verbose(1) << "External atoms inside of sphere at " << *OtherOptCenter << ":" << endl;2057 Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl; 2063 2058 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2064 Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( OtherOptCenter) << "." << endl;2065 } 2066 delete (ListofPoints);2059 Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl; 2060 } 2061 delete (ListofPoints); 2067 2062 2068 2063 return flag; 2069 } ;2070 2064 } 2065 ; 2071 2066 2072 2067 /** Checks whether the triangle consisting of the three points is already present. … … 2081 2076 int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const 2082 2077 { 2083 2078 Info FunctionInfo(__func__); 2084 2079 int adjacentTriangleCount = 0; 2085 2080 class BoundaryPointSet *Points[3]; … … 2121 2116 Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl; 2122 2117 return adjacentTriangleCount; 2123 }; 2118 } 2119 ; 2124 2120 2125 2121 /** Checks whether the triangle consisting of the three points is already present. … … 2133 2129 class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3]) 2134 2130 { 2135 2131 Info FunctionInfo(__func__); 2136 2132 class BoundaryTriangleSet *triangle = NULL; 2137 2133 class BoundaryPointSet *Points[3]; … … 2171 2167 2172 2168 return triangle; 2173 } ;2174 2169 } 2170 ; 2175 2171 2176 2172 /** Finds the starting triangle for FindNonConvexBorder(). … … 2184 2180 void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC) 2185 2181 { 2186 2182 Info FunctionInfo(__func__); 2187 2183 int i = 0; 2188 2184 TesselPoint* MaxPoint[NDIM]; … … 2193 2189 Vector Chord; 2194 2190 Vector SearchDirection; 2195 Vector CircleCenter; 2191 Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers 2196 2192 Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in 2197 2193 Vector SphereCenter; … … 2206 2202 2207 2203 // 1. searching topmost point with respect to each axis 2208 for (int i =0;i<NDIM;i++) { // each axis2209 LC->n[i] = LC->N[i] -1; // current axis is topmost cell2210 for (LC->n[(i +1)%NDIM]=0;LC->n[(i+1)%NDIM]<LC->N[(i+1)%NDIM];LC->n[(i+1)%NDIM]++)2211 for (LC->n[(i +2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {2204 for (int i = 0; i < NDIM; i++) { // each axis 2205 LC->n[i] = LC->N[i] - 1; // current axis is topmost cell 2206 for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++) 2207 for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) { 2212 2208 const LinkedCell::LinkedNodes *List = LC->GetCurrentCell(); 2213 2209 //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl; 2214 2210 if (List != NULL) { 2215 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end();Runner++) {2211 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 2216 2212 if ((*Runner)->node->x[i] > maxCoordinate[i]) { 2217 2213 Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl; … … 2221 2217 } 2222 2218 } else { 2223 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);2219 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl); 2224 2220 } 2225 2221 } … … 2227 2223 2228 2224 Log() << Verbose(1) << "Found maximum coordinates: "; 2229 for (int i =0;i<NDIM;i++)2225 for (int i = 0; i < NDIM; i++) 2230 2226 Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t"; 2231 2227 Log() << Verbose(0) << endl; 2232 2228 2233 2229 BTS = NULL; 2234 for (int k =0;k<NDIM;k++) {2230 for (int k = 0; k < NDIM; k++) { 2235 2231 NormalVector.Zero(); 2236 2232 NormalVector.x[k] = 1.; … … 2260 2256 2261 2257 double radius = CirclePlaneNormal.NormSquared(); 2262 double CircleRadius = sqrt(RADIUS *RADIUS - radius/4.);2258 double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.); 2263 2259 2264 2260 NormalVector.ProjectOntoPlane(&CirclePlaneNormal); 2265 2261 NormalVector.Normalize(); 2266 ShortestAngle = 2. *M_PI; // This will indicate the quadrant.2262 ShortestAngle = 2. * M_PI; // This will indicate the quadrant. 2267 2263 2268 2264 SphereCenter.CopyVector(&NormalVector); … … 2272 2268 2273 2269 // look in one direction of baseline for initial candidate 2274 SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); 2270 SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ... 2275 2271 2276 2272 // adding point 1 and point 2 and add the line between them … … 2283 2279 Log() << Verbose(0) << "List of third Points is:" << endl; 2284 2280 for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) { 2285 2281 Log() << Verbose(0) << " " << *(*it) << endl; 2286 2282 } 2287 2283 if (!OptCandidates.pointlist.empty()) { … … 2302 2298 delete BaseLine; 2303 2299 } 2304 }; 2300 } 2301 ; 2305 2302 2306 2303 /** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates. … … 2453 2450 bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC) 2454 2451 { 2455 Info FunctionInfo(__func__); 2456 bool result = true; 2457 2452 Info FunctionInfo(__func__); 2458 2453 Vector CircleCenter; 2459 2454 Vector CirclePlaneNormal; … … 2465 2460 double radius, CircleRadius; 2466 2461 2467 for (int i =0;i<3;i++)2462 for (int i = 0; i < 3; i++) 2468 2463 if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) { 2469 2464 ThirdPoint = T.endpoints[i]; … … 2485 2480 // calculate squared radius of circle 2486 2481 radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal); 2487 if (radius /4. < RADIUS*RADIUS) {2482 if (radius / 4. < RADIUS * RADIUS) { 2488 2483 // construct relative sphere center with now known CircleCenter 2489 2484 RelativeSphereCenter.CopyVector(&T.SphereCenter); 2490 2485 RelativeSphereCenter.SubtractVector(&CircleCenter); 2491 2486 2492 CircleRadius = RADIUS *RADIUS - radius/4.;2487 CircleRadius = RADIUS * RADIUS - radius / 4.; 2493 2488 CirclePlaneNormal.Normalize(); 2494 2489 Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl; … … 2505 2500 if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { 2506 2501 // rotated the wrong way! 2507 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);2502 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl); 2508 2503 } 2509 2504 … … 2516 2511 2517 2512 if (CandidateLine.pointlist.empty()) { 2518 DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);2513 DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl); 2519 2514 return false; 2520 2515 } … … 2525 2520 2526 2521 return true; 2527 2528 // BoundaryLineSet *BaseRay = CandidateLine.BaseLine; 2529 // for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) { 2530 // Log() << Verbose(0) << "Third point candidate is " << *(*it)->point 2531 // << " with circumsphere's center at " << (*it)->OptCenter << "." << endl; 2532 // Log() << Verbose(0) << "Baseline is " << *BaseRay << endl; 2533 // 2534 // // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2) 2535 // TesselPoint *PointCandidates[3]; 2536 // PointCandidates[0] = (*it)->point; 2537 // PointCandidates[1] = BaseRay->endpoints[0]->node; 2538 // PointCandidates[2] = BaseRay->endpoints[1]->node; 2539 // int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates); 2540 // 2541 // BTS = NULL; 2542 // // check for present edges and whether we reach better candidates from them 2543 // //if (HasOtherBaselineBetterCandidate(BaseRay, (*it)->point, ShortestAngle, RADIUS, LC) ) { 2544 // if (0) { 2545 // result = false; 2546 // break; 2547 // } else { 2548 // // If there is no triangle, add it regularly. 2549 // if (existentTrianglesCount == 0) { 2550 // AddTesselationPoint((*it)->point, 0); 2551 // AddTesselationPoint(BaseRay->endpoints[0]->node, 1); 2552 // AddTesselationPoint(BaseRay->endpoints[1]->node, 2); 2553 // 2554 // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) { 2555 // CandidateLine.point = (*it)->point; 2556 // CandidateLine.OptCenter.CopyVector(&((*it)->OptCenter)); 2557 // CandidateLine.OtherOptCenter.CopyVector(&((*it)->OtherOptCenter)); 2558 // CandidateLine.ShortestAngle = ShortestAngle; 2559 // } else { 2560 //// DoeLog(1) && (eLog()<< Verbose(1) << "This triangle consisting of "); 2561 //// Log() << Verbose(0) << *(*it)->point << ", "; 2562 //// Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and "; 2563 //// Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " "; 2564 //// Log() << Verbose(0) << "exists and is not added, as it 0x80000000006fc150(does not seem helpful!" << endl; 2565 // result = false; 2566 // } 2567 // } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time. 2568 // AddTesselationPoint((*it)->point, 0); 2569 // AddTesselationPoint(BaseRay->endpoints[0]->node, 1); 2570 // AddTesselationPoint(BaseRay->endpoints[1]->node, 2); 2571 // 2572 // // 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) 2573 // // i.e. at least one of the three lines must be present with TriangleCount <= 1 2574 // if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS) || CandidateLine.BaseLine->skipped) { 2575 // CandidateLine.point = (*it)->point; 2576 // CandidateLine.OptCenter.CopyVector(&(*it)->OptCenter); 2577 // CandidateLine.OtherOptCenter.CopyVector(&(*it)->OtherOptCenter); 2578 // CandidateLine.ShortestAngle = ShortestAngle+2.*M_PI; 2579 // 2580 // } else { 2581 //// DoeLog(1) && (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); 2582 // result = false; 2583 // } 2584 // } else { 2585 //// Log() << Verbose(1) << "This triangle consisting of "; 2586 //// Log() << Verbose(0) << *(*it)->point << ", "; 2587 //// Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and "; 2588 //// Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " "; 2589 //// Log() << Verbose(0) << "is invalid!" << endl; 2590 // result = false; 2591 // } 2592 // } 2593 // 2594 // // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point)) 2595 // BaseRay = BLS[0]; 2596 // if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) { 2597 // DoeLog(1) && (eLog()<< Verbose(1) << "Triangle " << *BTS << " has zero normal vector!" << endl); 2598 // exit(255); 2599 // } 2600 // 2601 // } 2602 // 2603 // // remove all candidates from the list and then the list itself 2604 // class CandidateForTesselation *remover = NULL; 2605 // for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) { 2606 // remover = *it; 2607 // delete(remover); 2608 // } 2609 // delete(OptCandidates); 2610 return result; 2611 }; 2522 } 2523 ; 2524 2525 /** Walks through Tesselation::OpenLines() and finds candidates for newly created ones. 2526 * \param *&LCList atoms in LinkedCell list 2527 * \param RADIUS radius of the virtual sphere 2528 * \return true - for all open lines without candidates so far, a candidate has been found, 2529 * false - at least one open line without candidate still 2530 */ 2531 bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList) 2532 { 2533 bool TesselationFailFlag = true; 2534 CandidateForTesselation *baseline = NULL; 2535 BoundaryTriangleSet *T = NULL; 2536 2537 for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) { 2538 baseline = Runner->second; 2539 if (baseline->pointlist.empty()) { 2540 T = (((baseline->BaseLine->triangles.begin()))->second); 2541 Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl; 2542 TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one. 2543 } 2544 } 2545 return TesselationFailFlag; 2546 } 2547 ; 2612 2548 2613 2549 /** Adds the present line and candidate point from \a &CandidateLine to the Tesselation. … … 2641 2577 Sprinter = Runner; 2642 2578 Sprinter++; 2643 while(Sprinter != connectedClosestPoints->end()) { 2579 while (Sprinter != connectedClosestPoints->end()) { 2580 Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl; 2581 2644 2582 AddTesselationPoint(TurningPoint, 0); 2645 2583 AddTesselationPoint(*Runner, 1); 2646 2584 AddTesselationPoint(*Sprinter, 2); 2647 2585 2586 AddCandidateTriangle(CandidateLine, Opt); 2587 2588 Runner = Sprinter; 2589 Sprinter++; 2590 if (Sprinter != connectedClosestPoints->end()) { 2591 // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked) 2592 FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); 2593 Log() << Verbose(0) << " There are still more triangles to add." << endl; 2594 } 2595 // pick candidates for other open lines as well 2596 FindCandidatesforOpenLines(RADIUS, LC); 2597 2648 2598 // check whether we add a degenerate or a normal triangle 2649 if (CheckDegeneracy( &CandidateLine.OtherOptCenter, RADIUS, LC)) {2599 if (CheckDegeneracy(CandidateLine, RADIUS, LC)) { 2650 2600 // add normal and degenerate triangles 2651 2601 Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl; 2652 AddDegeneratedTriangle(CandidateLine, RADIUS, LC); 2653 } else { 2654 // add this triangle 2655 AddCandidateTriangle(CandidateLine); 2656 } 2657 2658 Runner = Sprinter; 2659 Sprinter++; 2660 Log() << Verbose(0) << "Current Runner is " << **Runner << "." << endl; 2661 if (Sprinter != connectedClosestPoints->end()) 2662 Log() << Verbose(0) << " There are still more triangles to add." << endl; 2663 } 2664 delete(connectedClosestPoints); 2602 AddCandidateTriangle(CandidateLine, OtherOpt); 2603 2604 if (Sprinter != connectedClosestPoints->end()) { 2605 // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked) 2606 FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter); 2607 } 2608 // pick candidates for other open lines as well 2609 FindCandidatesforOpenLines(RADIUS, LC); 2610 } 2611 } 2612 delete (connectedClosestPoints); 2613 }; 2614 2615 /** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate. 2616 * \param *Sprinter next candidate to which internal open lines are set 2617 * \param *OptCenter OptCenter for this candidate 2618 */ 2619 void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter) 2620 { 2621 Info FunctionInfo(__func__); 2622 2623 pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr); 2624 for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) { 2625 Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl; 2626 // If there is a line with less than two attached triangles, we don't need a new line. 2627 if (FindLine->second->triangles.size() == 1) { 2628 CandidateMap::iterator Finder = OpenLines.find(FindLine->second); 2629 if (!Finder->second->pointlist.empty()) 2630 Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl; 2631 else { 2632 Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl; 2633 Finder->second->pointlist.push_back(Sprinter); 2634 Finder->second->ShortestAngle = 0.; 2635 Finder->second->OptCenter.CopyVector(OptCenter); 2636 } 2637 } 2638 } 2665 2639 }; 2666 2640 … … 2680 2654 2681 2655 /// 1. Create or pick the lines for the first triangle 2682 // for each amount of open lines we have a different case:2683 // case 0: no triangles at this line and not closed2684 // case 1: no triangles at new line is closed2685 // case 2: one line with one triangle attached, one will used this line2686 // case 3: one line with two triangles attached, new line will be used by both degenerate triangles2687 // case 4: two lines with one triangle each, each new triangle will pick one2688 2656 Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl; 2689 for (int i =0;i<3;i++) {2657 for (int i = 0; i < 3; i++) { 2690 2658 BLS[i] = NULL; 2691 Log() << Verbose(0) << "Current line is between " << *TPS[(i +0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;2692 AddTesselationLine(&CandidateLine.OptCenter, TPS[(i +2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);2659 Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl; 2660 AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i); 2693 2661 } 2694 2662 … … 2712 2680 /// 3. Gather candidates for each new line 2713 2681 Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl; 2714 for (int i =0;i<3;i++) {2715 Log() << Verbose(0) << "Current line is between " << *TPS[(i +0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;2682 for (int i = 0; i < 3; i++) { 2683 Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl; 2716 2684 CandidateCheck = OpenLines.find(BLS[i]); 2717 2685 if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) { … … 2724 2692 /// 4. Create or pick the lines for the second triangle 2725 2693 Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl; 2726 for (int i =0;i<3;i++) {2727 Log() << Verbose(0) << "Current line is between " << *TPS[(i +0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;2728 AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i +2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);2694 for (int i = 0; i < 3; i++) { 2695 Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl; 2696 AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i); 2729 2697 } 2730 2698 … … 2746 2714 /// 6. Adding triangle to new lines 2747 2715 Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl; 2748 for (int i =0;i<3;i++) {2749 Log() << Verbose(0) << "Current line is between " << *TPS[(i +0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;2716 for (int i = 0; i < 3; i++) { 2717 Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl; 2750 2718 CandidateCheck = OpenLines.find(BLS[i]); 2751 2719 if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) { … … 2754 2722 } 2755 2723 } 2756 }; 2724 } 2725 ; 2757 2726 2758 2727 /** Adds a triangle to the Tesselation structure from three given TesselPoint's. 2759 2728 * Note that endpoints are in Tesselation::TPS. 2760 2729 * \param CandidateLine CandidateForTesselation structure contains other information 2761 */ 2762 void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine) 2730 * \param type which opt center to add (i.e. which side) and thus which NormalVector to take 2731 */ 2732 void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type) 2763 2733 { 2764 2734 Info FunctionInfo(__func__); 2765 2735 Vector Center; 2736 Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter; 2766 2737 2767 2738 // add the lines 2768 AddTesselationLine( &CandidateLine.OptCenter, TPS[2], TPS[0], TPS[1], 0);2769 AddTesselationLine( &CandidateLine.OptCenter, TPS[1], TPS[0], TPS[2], 1);2770 AddTesselationLine( &CandidateLine.OptCenter, TPS[0], TPS[1], TPS[2], 2);2739 AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0); 2740 AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1); 2741 AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2); 2771 2742 2772 2743 // add the triangles … … 2776 2747 // create normal vector 2777 2748 BTS->GetCenter(&Center); 2778 Center.SubtractVector( &CandidateLine.OptCenter);2779 BTS->SphereCenter.CopyVector( &CandidateLine.OptCenter);2749 Center.SubtractVector(OptCenter); 2750 BTS->SphereCenter.CopyVector(OptCenter); 2780 2751 BTS->GetNormalVector(Center); 2781 2752 2782 2753 // give some verbose output about the whole procedure 2783 2754 if (CandidateLine.T != NULL) 2784 Log() << Verbose(0) << "--> New 2755 Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl; 2785 2756 else 2786 Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl; 2787 }; 2757 Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl; 2758 } 2759 ; 2788 2760 2789 2761 /** Checks whether the quadragon of the two triangles connect to \a *Base is convex. … … 2796 2768 class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base) 2797 2769 { 2798 2770 Info FunctionInfo(__func__); 2799 2771 class BoundaryPointSet *Spot = NULL; 2800 2772 class BoundaryLineSet *OtherBase; 2801 2773 Vector *ClosestPoint; 2802 2774 2803 int m =0;2804 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2805 for (int j =0;j<3;j++) // all of their endpoints and baselines2775 int m = 0; 2776 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2777 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2806 2778 if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints 2807 2779 BPS[m++] = runner->second->endpoints[j]; 2808 OtherBase = new class BoundaryLineSet(BPS, -1);2780 OtherBase = new class BoundaryLineSet(BPS, -1); 2809 2781 2810 2782 Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl; … … 2815 2787 2816 2788 // delete the temporary other base line 2817 delete (OtherBase);2789 delete (OtherBase); 2818 2790 2819 2791 // get the distance vector from Base line to OtherBase line … … 2822 2794 BaseLine.CopyVector(Base->endpoints[1]->node->node); 2823 2795 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 2824 for (int i =0;i<2;i++) {2796 for (int i = 0; i < 2; i++) { 2825 2797 DistanceToIntersection[i].CopyVector(ClosestPoint); 2826 2798 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 2827 2799 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 2828 2800 } 2829 delete (ClosestPoint);2830 if ((distance[0] * distance[1]) > 0) 2831 Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] 2801 delete (ClosestPoint); 2802 if ((distance[0] * distance[1]) > 0) { // have same sign? 2803 Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl; 2832 2804 if (distance[0] < distance[1]) { 2833 2805 Spot = Base->endpoints[0]; … … 2836 2808 } 2837 2809 return Spot; 2838 } else { 2810 } else { // different sign, i.e. we are in between 2839 2811 Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl; 2840 2812 return NULL; 2841 2813 } 2842 2814 2843 }; 2815 } 2816 ; 2844 2817 2845 2818 void Tesselation::PrintAllBoundaryPoints(ofstream *out) const 2846 2819 { 2847 2820 Info FunctionInfo(__func__); 2848 2821 // print all lines 2849 2822 Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl; 2850 for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)2823 for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++) 2851 2824 Log() << Verbose(0) << *(PointRunner->second) << endl; 2852 }; 2825 } 2826 ; 2853 2827 2854 2828 void Tesselation::PrintAllBoundaryLines(ofstream *out) const 2855 2829 { 2856 2830 Info FunctionInfo(__func__); 2857 2831 // print all lines 2858 2832 Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl; 2859 2833 for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) 2860 2834 Log() << Verbose(0) << *(LineRunner->second) << endl; 2861 }; 2835 } 2836 ; 2862 2837 2863 2838 void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const 2864 2839 { 2865 2840 Info FunctionInfo(__func__); 2866 2841 // print all triangles 2867 2842 Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl; 2868 2843 for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++) 2869 2844 Log() << Verbose(0) << *(TriangleRunner->second) << endl; 2870 }; 2845 } 2846 ; 2871 2847 2872 2848 /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher". … … 2877 2853 double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base) 2878 2854 { 2879 2855 Info FunctionInfo(__func__); 2880 2856 class BoundaryLineSet *OtherBase; 2881 2857 Vector *ClosestPoint[2]; 2882 2858 double volume; 2883 2859 2884 int m =0;2885 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2886 for (int j =0;j<3;j++) // all of their endpoints and baselines2860 int m = 0; 2861 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2862 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2887 2863 if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints 2888 2864 BPS[m++] = runner->second->endpoints[j]; 2889 OtherBase = new class BoundaryLineSet(BPS, -1);2865 OtherBase = new class BoundaryLineSet(BPS, -1); 2890 2866 2891 2867 Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl; … … 2905 2881 2906 2882 // delete the temporary other base line and the closest points 2907 delete (ClosestPoint[0]);2908 delete (ClosestPoint[1]);2909 delete (OtherBase);2883 delete (ClosestPoint[0]); 2884 delete (ClosestPoint[1]); 2885 delete (OtherBase); 2910 2886 2911 2887 if (Distance.NormSquared() < MYEPSILON) { // check for intersection … … 2916 2892 BaseLineNormal.Zero(); 2917 2893 if (Base->triangles.size() < 2) { 2918 DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);2894 DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl); 2919 2895 return 0.; 2920 2896 } … … 2923 2899 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 2924 2900 } 2925 BaseLineNormal.Scale(1. /2.);2901 BaseLineNormal.Scale(1. / 2.); 2926 2902 2927 2903 if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip … … 2929 2905 // calculate volume summand as a general tetraeder 2930 2906 return volume; 2931 } else { 2907 } else { // Base higher than OtherBase -> do nothing 2932 2908 Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl; 2933 2909 return 0.; 2934 2910 } 2935 2911 } 2936 }; 2912 } 2913 ; 2937 2914 2938 2915 /** For a given baseline and its two connected triangles, flips the baseline. … … 2945 2922 class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base) 2946 2923 { 2947 2924 Info FunctionInfo(__func__); 2948 2925 class BoundaryLineSet *OldLines[4], *NewLine; 2949 2926 class BoundaryPointSet *OldPoints[2]; 2950 2927 Vector BaseLineNormal; 2951 2928 int OldTriangleNrs[2], OldBaseLineNr; 2952 int i, m;2929 int i, m; 2953 2930 2954 2931 // calculate NormalVector for later use 2955 2932 BaseLineNormal.Zero(); 2956 2933 if (Base->triangles.size() < 2) { 2957 DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);2934 DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl); 2958 2935 return NULL; 2959 2936 } … … 2962 2939 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 2963 2940 } 2964 BaseLineNormal.Scale(-1. /2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()2941 BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector() 2965 2942 2966 2943 // get the two triangles 2967 2944 // gather four endpoints and four lines 2968 for (int j =0;j<4;j++)2945 for (int j = 0; j < 4; j++) 2969 2946 OldLines[j] = NULL; 2970 for (int j =0;j<2;j++)2947 for (int j = 0; j < 2; j++) 2971 2948 OldPoints[j] = NULL; 2972 i =0;2973 m =0;2949 i = 0; 2950 m = 0; 2974 2951 Log() << Verbose(0) << "The four old lines are: "; 2975 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2976 for (int j =0;j<3;j++) // all of their endpoints and baselines2952 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2953 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2977 2954 if (runner->second->lines[j] != Base) { // pick not the central baseline 2978 2955 OldLines[i++] = runner->second->lines[j]; … … 2981 2958 Log() << Verbose(0) << endl; 2982 2959 Log() << Verbose(0) << "The two old points are: "; 2983 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)2984 for (int j =0;j<3;j++) // all of their endpoints and baselines2960 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) 2961 for (int j = 0; j < 3; j++) // all of their endpoints and baselines 2985 2962 if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints 2986 2963 OldPoints[m++] = runner->second->endpoints[j]; … … 2990 2967 2991 2968 // check whether everything is in place to create new lines and triangles 2992 if (i <4) {2993 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);2969 if (i < 4) { 2970 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl); 2994 2971 return NULL; 2995 2972 } 2996 for (int j =0;j<4;j++)2973 for (int j = 0; j < 4; j++) 2997 2974 if (OldLines[j] == NULL) { 2998 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);2975 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl); 2999 2976 return NULL; 3000 2977 } 3001 for (int j =0;j<2;j++)2978 for (int j = 0; j < 2; j++) 3002 2979 if (OldPoints[j] == NULL) { 3003 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);2980 DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl); 3004 2981 return NULL; 3005 2982 } … … 3008 2985 Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl; 3009 2986 OldBaseLineNr = Base->Nr; 3010 m =0;3011 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {2987 m = 0; 2988 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 3012 2989 Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl; 3013 2990 OldTriangleNrs[m++] = runner->second->Nr; … … 3023 3000 3024 3001 // construct new triangles with flipped baseline 3025 i =-1;3002 i = -1; 3026 3003 if (OldLines[0]->IsConnectedTo(OldLines[2])) 3027 i =2;3004 i = 2; 3028 3005 if (OldLines[0]->IsConnectedTo(OldLines[3])) 3029 i =3;3030 if (i !=-1) {3006 i = 3; 3007 if (i != -1) { 3031 3008 BLS[0] = OldLines[0]; 3032 3009 BLS[1] = OldLines[i]; … … 3037 3014 Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl; 3038 3015 3039 BLS[0] = (i ==2 ? OldLines[3] : OldLines[2]);3016 BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]); 3040 3017 BLS[1] = OldLines[1]; 3041 3018 BLS[2] = NewLine; … … 3045 3022 Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl; 3046 3023 } else { 3047 DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);3024 DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl); 3048 3025 return NULL; 3049 3026 } 3050 3027 3051 3028 return NewLine; 3052 } ;3053 3029 } 3030 ; 3054 3031 3055 3032 /** Finds the second point of starting triangle. … … 3063 3040 void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC) 3064 3041 { 3065 3042 Info FunctionInfo(__func__); 3066 3043 Vector AngleCheck; 3067 3044 class TesselPoint* Candidate = NULL; … … 3072 3049 int Nupper[NDIM]; 3073 3050 3074 if (LC->SetIndexToNode(a)) { 3075 for (int i=0;i<NDIM;i++) // store indices of this cell3051 if (LC->SetIndexToNode(a)) { // get cell for the starting point 3052 for (int i = 0; i < NDIM; i++) // store indices of this cell 3076 3053 N[i] = LC->n[i]; 3077 3054 } else { 3078 DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);3055 DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl); 3079 3056 return; 3080 3057 } 3081 3058 // then go through the current and all neighbouring cells and check the contained points for possible candidates 3082 for (int i=0;i<NDIM;i++) { 3083 Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0; 3084 Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1; 3085 } 3086 Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :" 3087 << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl; 3059 for (int i = 0; i < NDIM; i++) { 3060 Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0; 3061 Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1; 3062 } 3063 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; 3088 3064 3089 3065 for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++) … … 3119 3095 norm = aCandidate.Norm(); 3120 3096 // second point shall have smallest angle with respect to Oben vector 3121 if (norm < RADIUS *2.) {3097 if (norm < RADIUS * 2.) { 3122 3098 angle = AngleCheck.Angle(&Oben); 3123 3099 if (angle < Storage[0]) { … … 3141 3117 } 3142 3118 } 3143 } ;3144 3119 } 3120 ; 3145 3121 3146 3122 /** This recursive function finds a third point, to form a triangle with two given ones. … … 3174 3150 * @param *LC LinkedCell structure with neighbouring points 3175 3151 */ 3176 void Tesselation::FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet 3177 { 3178 3179 Vector CircleCenter; 3152 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 3153 { 3154 Info FunctionInfo(__func__); 3155 Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers 3180 3156 Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in 3181 3157 Vector SphereCenter; 3182 Vector NewSphereCenter; 3183 Vector OtherNewSphereCenter; 3184 Vector NewNormalVector; 3158 Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility 3159 Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility 3160 Vector NewNormalVector; // normal vector of the Candidate's triangle 3185 3161 Vector helper, OptCandidateCenter, OtherOptCandidateCenter; 3186 3162 Vector RelativeOldSphereCenter; … … 3213 3189 3214 3190 // calculate squared radius TesselPoint *ThirdPoint,f circle 3215 radius = CirclePlaneNormal.NormSquared() /4.;3216 if (radius < RADIUS *RADIUS) {3217 CircleRadius = RADIUS *RADIUS - radius;3191 radius = CirclePlaneNormal.NormSquared() / 4.; 3192 if (radius < RADIUS * RADIUS) { 3193 CircleRadius = RADIUS * RADIUS - radius; 3218 3194 CirclePlaneNormal.Normalize(); 3219 3195 Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl; … … 3221 3197 // test whether old center is on the band's plane 3222 3198 if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) { 3223 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);3199 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); 3224 3200 RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal); 3225 3201 } … … 3230 3206 // check SearchDirection 3231 3207 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 3232 if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { 3233 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);3208 if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way! 3209 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl); 3234 3210 } 3235 3211 3236 3212 // get cell for the starting point 3237 3213 if (LC->SetIndexToVector(&CircleCenter)) { 3238 for (int i=0;i<NDIM;i++) // store indices of this cell3239 N[i] = LC->n[i];3214 for (int i = 0; i < NDIM; i++) // store indices of this cell 3215 N[i] = LC->n[i]; 3240 3216 //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl; 3241 3217 } else { 3242 DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);3218 DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl); 3243 3219 return; 3244 3220 } 3245 3221 // then go through the current and all neighbouring cells and check the contained points for possible candidates 3246 3222 //Log() << Verbose(1) << "LC Intervals:"; 3247 for (int i =0;i<NDIM;i++) {3248 Nlower[i] = ((N[i] -1) >= 0) ? N[i]-1 : 0;3249 Nupper[i] = ((N[i] +1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;3223 for (int i = 0; i < NDIM; i++) { 3224 Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0; 3225 Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1; 3250 3226 //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] "; 3251 3227 } … … 3262 3238 // check for three unique points 3263 3239 Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl; 3264 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node) ){3240 if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) { 3265 3241 3266 3242 // find center on the plane … … 3268 3244 Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl; 3269 3245 3270 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) 3271 && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON) 3272 ) { 3246 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) { 3273 3247 Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl; 3274 3248 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter); … … 3276 3250 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 3277 3251 Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl; 3278 if (radius < RADIUS *RADIUS) {3252 if (radius < RADIUS * RADIUS) { 3279 3253 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter); 3280 3254 if (fabs(radius - otherradius) > HULLEPSILON) { 3281 DoeLog(1) && (eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl);3255 DoeLog(1) && (eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl); 3282 3256 } 3283 3257 // construct both new centers … … 3285 3259 OtherNewSphereCenter.CopyVector(&NewPlaneCenter); 3286 3260 helper.CopyVector(&NewNormalVector); 3287 helper.Scale(sqrt(RADIUS *RADIUS - radius));3261 helper.Scale(sqrt(RADIUS * RADIUS - radius)); 3288 3262 Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl; 3289 3263 NewSphereCenter.AddVector(&helper); … … 3311 3285 if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) { 3312 3286 CandidateLine.pointlist.push_back(Candidate); 3313 Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " 3314 << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl; 3287 Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl; 3315 3288 } else { 3316 3289 // remove all candidates from the list and then the list itself 3317 3290 CandidateLine.pointlist.clear(); 3318 3291 CandidateLine.pointlist.push_back(Candidate); 3319 Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " 3320 << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl; 3292 Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl; 3321 3293 } 3322 3294 CandidateLine.ShortestAngle = alpha; … … 3346 3318 } 3347 3319 } else { 3348 DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);3320 DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl); 3349 3321 } 3350 3322 } else { … … 3355 3327 } 3356 3328 3357 if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {3358 DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);3359 performCriticalExit();3360 }3361 3362 3329 DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl); 3363 3330 if (CandidateLine.pointlist.size() > 1) { … … 3365 3332 CandidateLine.pointlist.sort(); //SortCandidates); 3366 3333 } 3367 }; 3334 3335 if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) { 3336 DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl); 3337 performCriticalExit(); 3338 } 3339 } 3340 ; 3368 3341 3369 3342 /** Finds the endpoint two lines are sharing. … … 3374 3347 class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const 3375 3348 { 3376 3349 Info FunctionInfo(__func__); 3377 3350 const BoundaryLineSet * lines[2] = { line1, line2 }; 3378 3351 class BoundaryPointSet *node = NULL; … … 3381 3354 for (int i = 0; i < 2; i++) 3382 3355 // for both lines 3383 for (int j = 0; j < 2; j++) 3384 { // for both endpoints 3385 OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> ( 3386 lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j])); 3387 if (!OrderTest.second) 3388 { // if insertion fails, we have common endpoint 3389 node = OrderTest.first->second; 3390 Log() << Verbose(1) << "Common endpoint of lines " << *line1 3391 << " and " << *line2 << " is: " << *node << "." << endl; 3392 j = 2; 3393 i = 2; 3394 break; 3395 } 3356 for (int j = 0; j < 2; j++) { // for both endpoints 3357 OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j])); 3358 if (!OrderTest.second) { // if insertion fails, we have common endpoint 3359 node = OrderTest.first->second; 3360 Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl; 3361 j = 2; 3362 i = 2; 3363 break; 3396 3364 } 3365 } 3397 3366 return node; 3398 }; 3367 } 3368 ; 3399 3369 3400 3370 /** Finds the boundary points that are closest to a given Vector \a *x. … … 3410 3380 3411 3381 if (LinesOnBoundary.empty()) { 3412 DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);3382 DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl); 3413 3383 return NULL; 3414 3384 } … … 3416 3386 // gather all points close to the desired one 3417 3387 LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly 3418 for (int i=0;i<NDIM;i++) // store indices of this cell3388 for (int i = 0; i < NDIM; i++) // store indices of this cell 3419 3389 N[i] = LC->n[i]; 3420 3390 Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl; 3421 3422 3391 DistanceToPointMap * points = new DistanceToPointMap; 3423 3392 LC->GetNeighbourBounds(Nlower, Nupper); … … 3432 3401 FindPoint = PointsOnBoundary.find((*Runner)->nr); 3433 3402 if (FindPoint != PointsOnBoundary.end()) { 3434 points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(x), FindPoint->second));3403 points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(x), FindPoint->second)); 3435 3404 Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl; 3436 3405 } 3437 3406 } 3438 3407 } else { 3439 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);3408 DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl); 3440 3409 } 3441 3410 } … … 3443 3412 // check whether we found some points 3444 3413 if (points->empty()) { 3445 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);3446 delete (points);3414 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl); 3415 delete (points); 3447 3416 return NULL; 3448 3417 } 3449 3418 return points; 3450 }; 3419 } 3420 ; 3451 3421 3452 3422 /** Finds the boundary line that is closest to a given Vector \a *x. … … 3458 3428 { 3459 3429 Info FunctionInfo(__func__); 3460 3461 3430 // get closest points 3462 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);3431 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC); 3463 3432 if (points == NULL) { 3464 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);3433 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl); 3465 3434 return NULL; 3466 3435 } … … 3495 3464 helper.SubtractVector(&Center); 3496 3465 const double lengthB = helper.ScalarProduct(&BaseLine); 3497 if (lengthB *lengthA < 0) {// if have different sign3466 if (lengthB * lengthA < 0) { // if have different sign 3498 3467 ClosestLine = LineRunner->second; 3499 3468 MinDistance = distance; … … 3507 3476 } 3508 3477 } 3509 delete (points);3478 delete (points); 3510 3479 // check whether closest line is "too close" :), then it's inside 3511 3480 if (ClosestLine == NULL) { … … 3514 3483 } 3515 3484 return ClosestLine; 3516 }; 3485 } 3486 ; 3517 3487 3518 3488 /** Finds the triangle that is closest to a given Vector \a *x. … … 3523 3493 TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const 3524 3494 { 3525 Info FunctionInfo(__func__); 3526 3527 // get closest points 3528 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x,LC); 3495 Info FunctionInfo(__func__); 3496 // get closest points 3497 DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC); 3529 3498 if (points == NULL) { 3530 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);3499 DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl); 3531 3500 return NULL; 3532 3501 } … … 3555 3524 const double lengthEndB = BaseLineIntersection.NormSquared(); 3556 3525 3557 if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { 3526 if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint 3558 3527 const double lengthEnd = Min(lengthEndA, lengthEndB); 3559 3528 if (lengthEnd - MinDistance < -MYEPSILON) { // new best line … … 3562 3531 MinDistance = lengthEnd; 3563 3532 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl; 3564 } else if 3533 } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate 3565 3534 ClosestLines.insert(LineRunner->second); 3566 3535 Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl; … … 3577 3546 const double distance = BaseLineIntersection.NormSquared(); 3578 3547 if (Center.NormSquared() > BaseLine.NormSquared()) { 3579 DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);3548 DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl); 3580 3549 } 3581 3550 if ((ClosestLines.empty()) || (distance < MinDistance)) { … … 3589 3558 } 3590 3559 } 3591 delete (points);3560 delete (points); 3592 3561 3593 3562 // check whether closest line is "too close" :), then it's inside … … 3599 3568 for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++) 3600 3569 for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) { 3601 candidates->push_back(Runner->second);3602 }3570 candidates->push_back(Runner->second); 3571 } 3603 3572 return candidates; 3604 }; 3573 } 3574 ; 3605 3575 3606 3576 /** Finds closest triangle to a point. … … 3613 3583 class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const 3614 3584 { 3615 3585 Info FunctionInfo(__func__); 3616 3586 class BoundaryTriangleSet *result = NULL; 3617 3587 TriangleList *triangles = FindClosestTrianglesToVector(x, LC); … … 3624 3594 3625 3595 // go through all and pick the one with the best alignment to x 3626 double MinAlignment = 2. *M_PI;3596 double MinAlignment = 2. * M_PI; 3627 3597 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) { 3628 3598 (*Runner)->GetCenter(&Center); … … 3638 3608 } 3639 3609 } 3640 delete (triangles);3610 delete (triangles); 3641 3611 3642 3612 return result; 3643 }; 3613 } 3614 ; 3644 3615 3645 3616 /** Checks whether the provided Vector is within the Tesselation structure. … … 3653 3624 { 3654 3625 Info FunctionInfo(__func__); 3655 TriangleIntersectionList Intersections(&Point, this,LC);3626 TriangleIntersectionList Intersections(&Point, this, LC); 3656 3627 3657 3628 return Intersections.IsInside(); 3658 }; 3629 } 3630 ; 3659 3631 3660 3632 /** Returns the distance to the surface given by the tesselation. … … 3727 3699 } 3728 3700 } 3729 }; 3701 } 3702 ; 3730 3703 3731 3704 /** Calculates minimum distance from \a&Point to a tesselated surface. … … 3738 3711 { 3739 3712 Info FunctionInfo(__func__); 3740 TriangleIntersectionList Intersections(&Point, this,LC);3713 TriangleIntersectionList Intersections(&Point, this, LC); 3741 3714 3742 3715 return Intersections.GetSmallestDistance(); 3743 }; 3716 } 3717 ; 3744 3718 3745 3719 /** Calculates minimum distance from \a&Point to a tesselated surface. … … 3752 3726 { 3753 3727 Info FunctionInfo(__func__); 3754 TriangleIntersectionList Intersections(&Point, this,LC);3728 TriangleIntersectionList Intersections(&Point, this, LC); 3755 3729 3756 3730 return Intersections.GetClosestTriangle(); 3757 }; 3731 } 3732 ; 3758 3733 3759 3734 /** Gets all points connected to the provided point by triangulation lines. … … 3765 3740 TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const 3766 3741 { 3767 3768 3742 Info FunctionInfo(__func__); 3743 TesselPointSet *connectedPoints = new TesselPointSet; 3769 3744 class BoundaryPointSet *ReferencePoint = NULL; 3770 3745 TesselPoint* current; 3771 3746 bool takePoint = false; 3772 3773 3747 // find the respective boundary point 3774 3748 PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr); … … 3776 3750 ReferencePoint = PointRunner->second; 3777 3751 } else { 3778 DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);3752 DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl); 3779 3753 ReferencePoint = NULL; 3780 3754 } … … 3782 3756 // little trick so that we look just through lines connect to the BoundaryPoint 3783 3757 // OR fall-back to look through all lines if there is no such BoundaryPoint 3784 const LineMap *Lines;; 3758 const LineMap *Lines; 3759 ; 3785 3760 if (ReferencePoint != NULL) 3786 3761 Lines = &(ReferencePoint->lines); … … 3789 3764 LineMap::const_iterator findLines = Lines->begin(); 3790 3765 while (findLines != Lines->end()) { 3791 takePoint = false;3792 3793 if (findLines->second->endpoints[0]->Nr == Point->nr) {3794 takePoint = true;3795 current = findLines->second->endpoints[1]->node;3796 } else if (findLines->second->endpoints[1]->Nr == Point->nr) {3797 takePoint = true;3798 current = findLines->second->endpoints[0]->node;3799 }3800 3801 if (takePoint) {3802 Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;3803 connectedPoints->insert(current);3804 }3805 3806 findLines++;3766 takePoint = false; 3767 3768 if (findLines->second->endpoints[0]->Nr == Point->nr) { 3769 takePoint = true; 3770 current = findLines->second->endpoints[1]->node; 3771 } else if (findLines->second->endpoints[1]->Nr == Point->nr) { 3772 takePoint = true; 3773 current = findLines->second->endpoints[0]->node; 3774 } 3775 3776 if (takePoint) { 3777 Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl; 3778 connectedPoints->insert(current); 3779 } 3780 3781 findLines++; 3807 3782 } 3808 3783 3809 3784 if (connectedPoints->empty()) { // if have not found any points 3810 DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point<< "." << endl);3785 DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl); 3811 3786 return NULL; 3812 3787 } 3813 3788 3814 3789 return connectedPoints; 3815 } ;3816 3790 } 3791 ; 3817 3792 3818 3793 /** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point. … … 3830 3805 TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const 3831 3806 { 3832 3807 Info FunctionInfo(__func__); 3833 3808 map<double, TesselPoint*> anglesOfPoints; 3834 3809 TesselPointList *connectedCircle = new TesselPointList; … … 3837 3812 Vector OrthogonalVector; 3838 3813 Vector helper; 3839 const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL};3814 const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL }; 3840 3815 TriangleList *triangles = NULL; 3841 3816 3842 3817 if (SetOfNeighbours == NULL) { 3843 DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);3844 delete (connectedCircle);3818 DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl); 3819 delete (connectedCircle); 3845 3820 return NULL; 3846 3821 } … … 3852 3827 PlaneNormal.AddVector(&(*Runner)->NormalVector); 3853 3828 } else { 3854 DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);3829 DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl); 3855 3830 performCriticalExit(); 3856 3831 } 3857 PlaneNormal.Scale(1.0 /triangles->size());3832 PlaneNormal.Scale(1.0 / triangles->size()); 3858 3833 Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl; 3859 3834 PlaneNormal.Normalize(); … … 3865 3840 AngleZero.ProjectOntoPlane(&PlaneNormal); 3866 3841 } 3867 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON 3842 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3868 3843 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl; 3869 3844 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); … … 3871 3846 AngleZero.ProjectOntoPlane(&PlaneNormal); 3872 3847 if (AngleZero.NormSquared() < MYEPSILON) { 3873 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);3848 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); 3874 3849 performCriticalExit(); 3875 3850 } … … 3889 3864 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3890 3865 Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl; 3891 anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));3892 } 3893 3894 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {3866 anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner))); 3867 } 3868 3869 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) { 3895 3870 connectedCircle->push_back(AngleRunner->second); 3896 3871 } … … 3922 3897 3923 3898 if (SetOfNeighbours == NULL) { 3924 DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);3925 delete (connectedCircle);3899 DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl); 3900 delete (connectedCircle); 3926 3901 return NULL; 3927 3902 } … … 3936 3911 Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl; 3937 3912 // calculate central point 3938 3939 3913 TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin(); 3940 3914 TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin(); … … 3955 3929 //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size() 3956 3930 // << "; scale factor " << counter; 3957 PlaneNormal.Scale(1.0 /(double)counter);3958 // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;3959 //3960 // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points3961 // PlaneNormal.CopyVector(Point->node);3962 // PlaneNormal.SubtractVector(¢er);3963 // PlaneNormal.Normalize();3931 PlaneNormal.Scale(1.0 / (double) counter); 3932 // Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl; 3933 // 3934 // // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points 3935 // PlaneNormal.CopyVector(Point->node); 3936 // PlaneNormal.SubtractVector(¢er); 3937 // PlaneNormal.Normalize(); 3964 3938 Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl; 3965 3939 … … 3970 3944 AngleZero.ProjectOntoPlane(&PlaneNormal); 3971 3945 } 3972 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON 3946 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3973 3947 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl; 3974 3948 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); … … 3976 3950 AngleZero.ProjectOntoPlane(&PlaneNormal); 3977 3951 if (AngleZero.NormSquared() < MYEPSILON) { 3978 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);3952 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); 3979 3953 performCriticalExit(); 3980 3954 } … … 3988 3962 3989 3963 // go through all connected points and calculate angle 3990 pair <map<double, TesselPoint*>::iterator, bool> InserterTest;3964 pair<map<double, TesselPoint*>::iterator, bool> InserterTest; 3991 3965 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3992 3966 helper.CopyVector((*listRunner)->node); … … 3995 3969 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3996 3970 if (angle > M_PI) // the correction is of no use here (and not desired) 3997 angle = 2. *M_PI - angle;3971 angle = 2. * M_PI - angle; 3998 3972 Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl; 3999 InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));3973 InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner))); 4000 3974 if (!InserterTest.second) { 4001 DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);3975 DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl); 4002 3976 performCriticalExit(); 4003 3977 } 4004 3978 } 4005 3979 4006 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {3980 for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) { 4007 3981 connectedCircle->push_back(AngleRunner->second); 4008 3982 } … … 4019 3993 ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const 4020 3994 { 4021 3995 Info FunctionInfo(__func__); 4022 3996 map<double, TesselPoint*> anglesOfPoints; 4023 list< TesselPointList *> *ListOfPaths = new list< TesselPointList *>;3997 list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ; 4024 3998 TesselPointList *connectedPath = NULL; 4025 3999 Vector center; … … 4033 4007 class BoundaryLineSet *CurrentLine = NULL; 4034 4008 class BoundaryLineSet *StartLine = NULL; 4035 4036 4009 // find the respective boundary point 4037 4010 PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr); … … 4039 4012 ReferencePoint = PointRunner->second; 4040 4013 } else { 4041 DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);4014 DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl); 4042 4015 return NULL; 4043 4016 } 4044 4017 4045 map 4046 map 4047 map 4048 map 4018 map<class BoundaryLineSet *, bool> TouchedLine; 4019 map<class BoundaryTriangleSet *, bool> TouchedTriangle; 4020 map<class BoundaryLineSet *, bool>::iterator LineRunner; 4021 map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner; 4049 4022 for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) { 4050 TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false));4023 TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false)); 4051 4024 for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++) 4052 TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false));4025 TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false)); 4053 4026 } 4054 4027 if (!ReferencePoint->lines.empty()) { … … 4056 4029 LineRunner = TouchedLine.find(runner->second); 4057 4030 if (LineRunner == TouchedLine.end()) { 4058 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);4031 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl); 4059 4032 } else if (!LineRunner->second) { 4060 4033 LineRunner->second = true; … … 4064 4037 StartLine = CurrentLine; 4065 4038 CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint); 4066 Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;4039 Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl; 4067 4040 do { 4068 4041 // push current one … … 4086 4059 } 4087 4060 } else { 4088 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);4061 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl); 4089 4062 triangle = NULL; 4090 4063 } … … 4094 4067 break; 4095 4068 // find next line 4096 for (int i =0;i<3;i++) {4069 for (int i = 0; i < 3; i++) { 4097 4070 if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point 4098 4071 CurrentLine = triangle->lines[i]; … … 4103 4076 LineRunner = TouchedLine.find(CurrentLine); 4104 4077 if (LineRunner == TouchedLine.end()) 4105 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);4078 DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl); 4106 4079 else 4107 4080 LineRunner->second = true; … … 4121 4094 } 4122 4095 } else { 4123 DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);4096 DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl); 4124 4097 } 4125 4098 … … 4135 4108 ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const 4136 4109 { 4137 4110 Info FunctionInfo(__func__); 4138 4111 list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point); 4139 list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;4112 list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ; 4140 4113 TesselPointList *connectedPath = NULL; 4141 4114 TesselPointList *newPath = NULL; 4142 4115 int count = 0; 4143 4144 4145 4116 TesselPointList::iterator CircleRunner; 4146 4117 TesselPointList::iterator CircleStart; 4147 4118 4148 for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {4119 for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) { 4149 4120 connectedPath = *ListRunner; 4150 4121 … … 4153 4124 // go through list, look for reappearance of starting Point and count 4154 4125 CircleStart = connectedPath->begin(); 4155 4156 4126 // go through list, look for reappearance of starting Point and create list 4157 4127 TesselPointList::iterator Marker = CircleStart; … … 4159 4129 if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point 4160 4130 // we have a closed circle from Marker to new Marker 4161 Log() << Verbose(1) << count +1 << ". closed path consists of: ";4131 Log() << Verbose(1) << count + 1 << ". closed path consists of: "; 4162 4132 newPath = new TesselPointList; 4163 4133 TesselPointList::iterator CircleSprinter = Marker; … … 4181 4151 connectedPath = *(ListofPaths->begin()); 4182 4152 ListofPaths->remove(connectedPath); 4183 delete (connectedPath);4184 } 4185 delete (ListofPaths);4153 delete (connectedPath); 4154 } 4155 delete (ListofPaths); 4186 4156 4187 4157 // exit 4188 4158 return ListofClosedPaths; 4189 } ;4190 4159 } 4160 ; 4191 4161 4192 4162 /** Gets all belonging triangles for a given BoundaryPointSet. … … 4197 4167 TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const 4198 4168 { 4199 4200 4169 Info FunctionInfo(__func__); 4170 TriangleSet *connectedTriangles = new TriangleSet; 4201 4171 4202 4172 if (Point == NULL) { 4203 DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);4173 DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl); 4204 4174 } else { 4205 4175 // go through its lines and insert all triangles 4206 4176 for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++) 4207 4177 for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { 4208 connectedTriangles->insert(TriangleRunner->second);4209 }4178 connectedTriangles->insert(TriangleRunner->second); 4179 } 4210 4180 } 4211 4181 4212 4182 return connectedTriangles; 4213 } ;4214 4183 } 4184 ; 4215 4185 4216 4186 /** Removes a boundary point from the envelope while keeping it closed. … … 4225 4195 * \return volume added to the volume inside the tesselated surface by the removal 4226 4196 */ 4227 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) { 4197 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) 4198 { 4228 4199 class BoundaryLineSet *line = NULL; 4229 4200 class BoundaryTriangleSet *triangle = NULL; … … 4233 4204 4234 4205 if (point == NULL) { 4235 DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);4206 DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl); 4236 4207 return 0.; 4237 4208 } else … … 4243 4214 // get list of connected points 4244 4215 if (point->lines.empty()) { 4245 DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);4216 DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl); 4246 4217 return 0.; 4247 4218 } … … 4252 4223 // gather all triangles 4253 4224 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) 4254 count +=LineRunner->second->triangles.size();4225 count += LineRunner->second->triangles.size(); 4255 4226 TriangleMap Candidates; 4256 4227 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { … … 4258 4229 for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) { 4259 4230 triangle = TriangleRunner->second; 4260 Candidates.insert( TrianglePair (triangle->Nr, triangle));4231 Candidates.insert(TrianglePair(triangle->Nr, triangle)); 4261 4232 } 4262 4233 } 4263 4234 4264 4235 // remove all triangles 4265 count =0;4236 count = 0; 4266 4237 NormalVector.Zero(); 4267 4238 for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { … … 4280 4251 double smallestangle; 4281 4252 Vector Point, Reference, OrthogonalVector; 4282 if (count > 2) { 4253 if (count > 2) { // less than three triangles, then nothing will be created 4283 4254 class TesselPoint *TriangleCandidates[3]; 4284 4255 count = 0; 4285 for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) {// go through all closed paths4256 for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths 4286 4257 if (ListAdvance != ListOfClosedPaths->end()) 4287 4258 ListAdvance++; 4288 4259 4289 4260 connectedPath = *ListRunner; 4290 4291 4261 // re-create all triangles by going through connected points list 4292 4262 LineList NewLines; 4293 for (; !connectedPath->empty();) {4263 for (; !connectedPath->empty();) { 4294 4264 // search middle node with widest angle to next neighbours 4295 4265 EndNode = connectedPath->end(); … … 4317 4287 angle = GetAngle(Point, Reference, OrthogonalVector); 4318 4288 //if (angle < M_PI) // no wrong-sided triangles, please? 4319 if(fabs(angle - M_PI) < fabs(smallestangle - M_PI)) {// get straightest angle (i.e. construct those triangles with smallest area first)4320 4321 4322 4289 if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first) 4290 smallestangle = angle; 4291 EndNode = MiddleNode; 4292 } 4323 4293 } 4324 4294 MiddleNode = EndNode; 4325 4295 if (MiddleNode == connectedPath->end()) { 4326 DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);4296 DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl); 4327 4297 performCriticalExit(); 4328 4298 } … … 4343 4313 triangle = GetPresentTriangle(TriangleCandidates); 4344 4314 if (triangle != NULL) { 4345 DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);4315 DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl); 4346 4316 StartNode++; 4347 4317 MiddleNode++; … … 4355 4325 continue; 4356 4326 } 4357 Log() << Verbose(3) << "Adding new triangle points." << endl;4327 Log() << Verbose(3) << "Adding new triangle points." << endl; 4358 4328 AddTesselationPoint(*StartNode, 0); 4359 4329 AddTesselationPoint(*MiddleNode, 1); 4360 4330 AddTesselationPoint(*EndNode, 2); 4361 Log() << Verbose(3) << "Adding new triangle lines." << endl;4331 Log() << Verbose(3) << "Adding new triangle lines." << endl; 4362 4332 AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); 4363 4333 AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); … … 4381 4351 break; 4382 4352 } else if (connectedPath->size() < 2) { // something's gone wrong! 4383 DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);4353 DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl); 4384 4354 performCriticalExit(); 4385 4355 } else { … … 4401 4371 do { 4402 4372 maxgain = 0; 4403 for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {4373 for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) { 4404 4374 tmp = PickFarthestofTwoBaselines(*Runner); 4405 4375 if (maxgain < tmp) { … … 4419 4389 4420 4390 ListOfClosedPaths->remove(connectedPath); 4421 delete (connectedPath);4391 delete (connectedPath); 4422 4392 } 4423 4393 Log() << Verbose(0) << count << " triangles were created." << endl; … … 4427 4397 connectedPath = *ListRunner; 4428 4398 ListOfClosedPaths->remove(connectedPath); 4429 delete (connectedPath);4399 delete (connectedPath); 4430 4400 } 4431 4401 Log() << Verbose(0) << "No need to create any triangles." << endl; 4432 4402 } 4433 delete (ListOfClosedPaths);4403 delete (ListOfClosedPaths); 4434 4404 4435 4405 Log() << Verbose(0) << "Removed volume is " << volume << "." << endl; 4436 4406 4437 4407 return volume; 4438 }; 4439 4440 4408 } 4409 ; 4441 4410 4442 4411 /** … … 4450 4419 TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const 4451 4420 { 4452 4453 4421 Info FunctionInfo(__func__); 4422 TriangleList *result = new TriangleList; 4454 4423 LineMap::const_iterator FindLine; 4455 4424 TriangleMap::const_iterator FindTriangle; … … 4475 4444 for (int i = 0; i < 3; i++) { 4476 4445 if (TrianglePoints[i] != NULL) { 4477 for (int j = i +1; j < 3; j++) {4446 for (int j = i + 1; j < 3; j++) { 4478 4447 if (TrianglePoints[j] != NULL) { 4479 4448 for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap! 4480 (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); 4481 FindLine++) { 4482 for (FindTriangle = FindLine->second->triangles.begin(); 4483 FindTriangle != FindLine->second->triangles.end(); 4484 FindTriangle++) { 4449 (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) { 4450 for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) { 4485 4451 if (FindTriangle->second->IsPresentTupel(TrianglePoints)) { 4486 4452 result->push_back(FindTriangle->second); … … 4497 4463 case 1: // copy all triangles of the respective line 4498 4464 { 4499 int i =0;4465 int i = 0; 4500 4466 for (; i < 3; i++) 4501 4467 if (TrianglePoints[i] == NULL) 4502 4468 break; 4503 for (FindLine = TrianglePoints[(i+1)%3]->lines.find(TrianglePoints[(i+2)%3]->node->nr); // is a multimap! 4504 (FindLine != TrianglePoints[(i+1)%3]->lines.end()) && (FindLine->first == TrianglePoints[(i+2)%3]->node->nr); 4505 FindLine++) { 4506 for (FindTriangle = FindLine->second->triangles.begin(); 4507 FindTriangle != FindLine->second->triangles.end(); 4508 FindTriangle++) { 4469 for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap! 4470 (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) { 4471 for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) { 4509 4472 if (FindTriangle->second->IsPresentTupel(TrianglePoints)) { 4510 4473 result->push_back(FindTriangle->second); … … 4516 4479 case 2: // copy all triangles of the respective point 4517 4480 { 4518 int i =0;4481 int i = 0; 4519 4482 for (; i < 3; i++) 4520 4483 if (TrianglePoints[i] != NULL) … … 4534 4497 } 4535 4498 default: 4536 DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);4499 DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl); 4537 4500 performCriticalExit(); 4538 4501 break; … … 4542 4505 } 4543 4506 4544 struct BoundaryLineSetCompare { 4545 bool operator() (const BoundaryLineSet * const a, const BoundaryLineSet * const b) { 4507 struct BoundaryLineSetCompare 4508 { 4509 bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b) 4510 { 4546 4511 int lowerNra = -1; 4547 4512 int lowerNrb = -1; … … 4561 4526 else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb]) 4562 4527 return false; 4563 else { 4564 if (a->endpoints[(lowerNra+1)%2] < b->endpoints[(lowerNrb+1)%2])4565 return true;4566 else if (a->endpoints[(lowerNra+1)%2] > b->endpoints[(lowerNrb+1)%2])4567 return false;4528 else { // both lower-numbered endpoints are the same ... 4529 if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2]) 4530 return true; 4531 else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2]) 4532 return false; 4568 4533 } 4569 4534 return false; 4570 }; 4535 } 4536 ; 4571 4537 }; 4572 4538 … … 4581 4547 IndexToIndex * Tesselation::FindAllDegeneratedLines() 4582 4548 { 4583 4584 4549 Info FunctionInfo(__func__); 4550 UniqueLines AllLines; 4585 4551 IndexToIndex * DegeneratedLines = new IndexToIndex; 4586 4552 4587 4553 // sanity check 4588 4554 if (LinesOnBoundary.empty()) { 4589 DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");4555 DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure."); 4590 4556 return DegeneratedLines; 4591 4557 } 4592 4593 4558 LineMap::iterator LineRunner1; 4594 pair< 4559 pair<UniqueLines::iterator, bool> tester; 4595 4560 for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) { 4596 tester = AllLines.insert( LineRunner1->second);4561 tester = AllLines.insert(LineRunner1->second); 4597 4562 if (!tester.second) { // found degenerated line 4598 DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));4599 DegeneratedLines->insert ( pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));4563 DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr)); 4564 DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr)); 4600 4565 } 4601 4566 } … … 4611 4576 Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl; 4612 4577 else 4613 DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);4578 DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl); 4614 4579 } 4615 4580 … … 4625 4590 IndexToIndex * Tesselation::FindAllDegeneratedTriangles() 4626 4591 { 4627 4592 Info FunctionInfo(__func__); 4628 4593 IndexToIndex * DegeneratedLines = FindAllDegeneratedLines(); 4629 4594 IndexToIndex * DegeneratedTriangles = new IndexToIndex; 4630 4631 4595 TriangleMap::iterator TriangleRunner1, TriangleRunner2; 4632 4596 LineMap::iterator Liner; … … 4643 4607 for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) { 4644 4608 for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) { 4645 if ((TriangleRunner1->second != TriangleRunner2->second) 4646 && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) { 4647 DegeneratedTriangles->insert( pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr) ); 4648 DegeneratedTriangles->insert( pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr) ); 4609 if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) { 4610 DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr)); 4611 DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr)); 4649 4612 } 4650 4613 } 4651 4614 } 4652 4615 } 4653 delete (DegeneratedLines);4616 delete (DegeneratedLines); 4654 4617 4655 4618 Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl; 4656 4619 IndexToIndex::iterator it; 4657 4620 for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++) 4658 4621 Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl; 4659 4622 4660 4623 return DegeneratedTriangles; … … 4667 4630 void Tesselation::RemoveDegeneratedTriangles() 4668 4631 { 4669 4632 Info FunctionInfo(__func__); 4670 4633 IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles(); 4671 4634 TriangleMap::iterator finder; 4672 4635 BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL; 4673 int count = 0; 4674 4675 for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); 4676 TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner 4677 ) { 4636 int count = 0; 4637 4638 for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) { 4678 4639 finder = TrianglesOnBoundary.find(TriangleKeyRunner->first); 4679 4640 if (finder != TrianglesOnBoundary.end()) … … 4692 4653 trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j]; 4693 4654 4694 if (trianglesShareLine 4695 && (triangle->endpoints[1]->LinesCount > 2) 4696 && (triangle->endpoints[2]->LinesCount > 2) 4697 && (triangle->endpoints[0]->LinesCount > 2) 4698 ) { 4655 if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) { 4699 4656 // check whether we have to fix lines 4700 4657 BoundaryTriangleSet *Othertriangle = NULL; … … 4716 4673 // the line of triangle receives the degenerated ones 4717 4674 triangle->lines[i]->triangles.erase(Othertriangle->Nr); 4718 triangle->lines[i]->triangles.insert( TrianglePair( partnerTriangle->Nr, partnerTriangle));4719 for (int k =0;k<3;k++)4675 triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle)); 4676 for (int k = 0; k < 3; k++) 4720 4677 if (triangle->lines[i] == Othertriangle->lines[k]) { 4721 4678 Othertriangle->lines[k] = partnerTriangle->lines[j]; … … 4723 4680 } 4724 4681 // the line of partnerTriangle receives the non-degenerated ones 4725 partnerTriangle->lines[j]->triangles.erase( 4726 partnerTriangle->lines[j]->triangles.insert( TrianglePair( Othertriangle->Nr, Othertriangle));4682 partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr); 4683 partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle)); 4727 4684 partnerTriangle->lines[j] = triangle->lines[i]; 4728 4685 } … … 4736 4693 RemoveTesselationTriangle(partnerTriangle); 4737 4694 } else { 4738 Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle 4739 << " and its partner " << *partnerTriangle << " because it is essential for at" 4740 << " least one of the endpoints to be kept in the tesselation structure." << endl; 4741 } 4742 } 4743 delete(DegeneratedTriangles); 4695 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; 4696 } 4697 } 4698 delete (DegeneratedTriangles); 4744 4699 if (count > 0) 4745 4700 LastTriangle = NULL; … … 4758 4713 void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC) 4759 4714 { 4760 4715 Info FunctionInfo(__func__); 4761 4716 // find nearest boundary point 4762 4717 class TesselPoint *BackupPoint = NULL; … … 4771 4726 NearestBoundaryPoint = PointRunner->second; 4772 4727 } else { 4773 DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);4728 DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl); 4774 4729 return; 4775 4730 } … … 4789 4744 CenterToPoint.SubtractVector(point->node); 4790 4745 angle = CenterToPoint.Angle(&BaseLine); 4791 if (fabs(angle - M_PI /2.) < fabs(BestAngle - M_PI/2.)) {4746 if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) { 4792 4747 BestAngle = angle; 4793 4748 BestLine = Runner->second; … … 4799 4754 BestLine->triangles.erase(TempTriangle->Nr); 4800 4755 int nr = -1; 4801 for (int i =0;i<3; i++) {4756 for (int i = 0; i < 3; i++) { 4802 4757 if (TempTriangle->lines[i] == BestLine) { 4803 4758 nr = i; … … 4807 4762 4808 4763 // create new triangle to connect point (connects automatically with the missing spot of the chosen line) 4809 Log() << Verbose(2) << "Adding new triangle points." << endl;4764 Log() << Verbose(2) << "Adding new triangle points." << endl; 4810 4765 AddTesselationPoint((BestLine->endpoints[0]->node), 0); 4811 4766 AddTesselationPoint((BestLine->endpoints[1]->node), 1); 4812 4767 AddTesselationPoint(point, 2); 4813 Log() << Verbose(2) << "Adding new triangle lines." << endl;4768 Log() << Verbose(2) << "Adding new triangle lines." << endl; 4814 4769 AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); 4815 4770 AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); … … 4822 4777 4823 4778 // create other side of this triangle and close both new sides of the first created triangle 4824 Log() << Verbose(2) << "Adding new triangle points." << endl;4779 Log() << Verbose(2) << "Adding new triangle points." << endl; 4825 4780 AddTesselationPoint((BestLine->endpoints[0]->node), 0); 4826 4781 AddTesselationPoint((BestLine->endpoints[1]->node), 1); 4827 4782 AddTesselationPoint(point, 2); 4828 Log() << Verbose(2) << "Adding new triangle lines." << endl;4783 Log() << Verbose(2) << "Adding new triangle lines." << endl; 4829 4784 AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0); 4830 4785 AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1); … … 4836 4791 4837 4792 // add removed triangle to the last open line of the second triangle 4838 for (int i =0;i<3;i++) { // look for the same line as BestLine (only it's its degenerated companion)4793 for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion) 4839 4794 if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) { 4840 if (BestLine == BTS->lines[i]) {4841 DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl);4795 if (BestLine == BTS->lines[i]) { 4796 DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl); 4842 4797 performCriticalExit(); 4843 4798 } 4844 BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));4799 BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle)); 4845 4800 TempTriangle->lines[nr] = BTS->lines[i]; 4846 4801 break; 4847 4802 } 4848 4803 } 4849 }; 4804 } 4805 ; 4850 4806 4851 4807 /** Writes the envelope to file. … … 4856 4812 void Tesselation::Output(const char *filename, const PointCloud * const cloud) 4857 4813 { 4858 4814 Info FunctionInfo(__func__); 4859 4815 ofstream *tempstream = NULL; 4860 4816 string NameofTempFile; … … 4862 4818 4863 4819 if (LastTriangle != NULL) { 4864 sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);4820 sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name); 4865 4821 if (DoTecplotOutput) { 4866 4822 string NameofTempFile(filename); 4867 4823 NameofTempFile.append(NumberName); 4868 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))4869 NameofTempFile.erase(npos, 1);4824 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos)) 4825 NameofTempFile.erase(npos, 1); 4870 4826 NameofTempFile.append(TecplotSuffix); 4871 4827 Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n"; … … 4874 4830 tempstream->close(); 4875 4831 tempstream->flush(); 4876 delete (tempstream);4832 delete (tempstream); 4877 4833 } 4878 4834 … … 4880 4836 string NameofTempFile(filename); 4881 4837 NameofTempFile.append(NumberName); 4882 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))4883 NameofTempFile.erase(npos, 1);4838 for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos)) 4839 NameofTempFile.erase(npos, 1); 4884 4840 NameofTempFile.append(Raster3DSuffix); 4885 4841 Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n"; … … 4889 4845 tempstream->close(); 4890 4846 tempstream->flush(); 4891 delete (tempstream);4847 delete (tempstream); 4892 4848 } 4893 4849 } 4894 4850 if (DoTecplotOutput || DoRaster3DOutput) 4895 4851 TriangleFilesWritten++; 4896 }; 4897 4898 struct BoundaryPolygonSetCompare { 4899 bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const { 4852 } 4853 ; 4854 4855 struct BoundaryPolygonSetCompare 4856 { 4857 bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const 4858 { 4900 4859 if (s1->endpoints.size() < s2->endpoints.size()) 4901 4860 return true; … … 4926 4885 { 4927 4886 Info FunctionInfo(__func__); 4928 4929 4887 /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector 4930 4888 IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles(); 4931 set <BoundaryPointSet *> EndpointCandidateList;4932 pair < set < BoundaryPointSet *>::iterator, bool> InsertionTester;4933 pair < map < int, Vector *>::iterator, bool> TriangleInsertionTester;4889 set<BoundaryPointSet *> EndpointCandidateList; 4890 pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester; 4891 pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester; 4934 4892 for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) { 4935 4893 Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl; 4936 map <int, Vector *> TriangleVectors;4894 map<int, Vector *> TriangleVectors; 4937 4895 // gather all NormalVectors 4938 4896 Log() << Verbose(1) << "Gathering triangles ..." << endl; … … 4940 4898 for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) { 4941 4899 if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) { 4942 TriangleInsertionTester = TriangleVectors.insert( pair< int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));4900 TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector))); 4943 4901 if (TriangleInsertionTester.second) 4944 4902 Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl; … … 4949 4907 // check whether there are two that are parallel 4950 4908 Log() << Verbose(1) << "Finding two parallel triangles ..." << endl; 4951 for (map <int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)4952 for (map <int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)4909 for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++) 4910 for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) 4953 4911 if (VectorWalker != VectorRunner) { // skip equals 4954 const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); 4955 Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl;4912 const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles 4913 Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl; 4956 4914 if (fabs(SCP + 1.) < ParallelEpsilon) { 4957 4915 InsertionTester = EndpointCandidateList.insert((Runner->second)); … … 4965 4923 } 4966 4924 } 4967 delete(DegeneratedTriangles); 4968 4925 delete (DegeneratedTriangles); 4969 4926 /// 3. Find connected endpoint candidates and put them into a polygon 4970 4927 UniquePolygonSet ListofDegeneratedPolygons; … … 4972 4929 BoundaryPointSet *OtherWalker = NULL; 4973 4930 BoundaryPolygonSet *Current = NULL; 4974 stack 4931 stack<BoundaryPointSet*> ToCheckConnecteds; 4975 4932 while (!EndpointCandidateList.empty()) { 4976 4933 Walker = *(EndpointCandidateList.begin()); 4977 if (Current == NULL) { 4934 if (Current == NULL) { // create a new polygon with current candidate 4978 4935 Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl; 4979 4936 Current = new BoundaryPolygonSet; … … 4990 4947 OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker); 4991 4948 Log() << Verbose(1) << "Checking " << *OtherWalker << endl; 4992 set <BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);4993 if (Finder != EndpointCandidateList.end()) { 4949 set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker); 4950 if (Finder != EndpointCandidateList.end()) { // found a connected partner 4994 4951 Log() << Verbose(1) << " Adding to polygon." << endl; 4995 4952 Current->endpoints.insert(OtherWalker); 4996 EndpointCandidateList.erase(Finder); 4997 ToCheckConnecteds.push(OtherWalker); 4953 EndpointCandidateList.erase(Finder); // remove from candidates 4954 ToCheckConnecteds.push(OtherWalker); // but check its partners too 4998 4955 } else { 4999 4956 Log() << Verbose(1) << " is not connected to " << *Walker << endl; … … 5015 4972 /// 4. Go through all these degenerated polygons 5016 4973 for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) { 5017 stack 4974 stack<int> TriangleNrs; 5018 4975 Vector NormalVector; 5019 4976 /// 4a. Gather all triangles of this polygon … … 5023 4980 if (T->size() == 2) { 5024 4981 Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl; 5025 delete (T);4982 delete (T); 5026 4983 continue; 5027 4984 } … … 5032 4989 // connections to either polygon ... 5033 4990 if (T->size() % 2 != 0) { 5034 DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);4991 DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl); 5035 4992 performCriticalExit(); 5036 4993 } 5037 5038 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 4994 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 5039 4995 /// 4a. Get NormalVector for one side (this is "front") 5040 4996 NormalVector.CopyVector(&(*TriangleWalker)->NormalVector); … … 5059 5015 /// 4c. Copy all "front" triangles but with inverse NormalVector 5060 5016 TriangleWalker = T->begin(); 5061 while (TriangleWalker != T->end()) { 5017 while (TriangleWalker != T->end()) { // go through all front triangles 5062 5018 Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl; 5063 5019 for (int i = 0; i < 3; i++) … … 5067 5023 AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2); 5068 5024 if (TriangleNrs.empty()) 5069 DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);5025 DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl); 5070 5026 BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ... 5071 5027 AddTesselationTriangle(); // ... and add … … 5076 5032 } 5077 5033 if (!TriangleNrs.empty()) { 5078 DoeLog(0) && (eLog()<< Verbose(0) << "There have been less triangles created than removed!" << endl); 5079 } 5080 delete(T); // remove the triangleset 5081 } 5082 5034 DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl); 5035 } 5036 delete (T); // remove the triangleset 5037 } 5083 5038 IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles(); 5084 5039 Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl; 5085 5040 IndexToIndex::iterator it; 5086 5041 for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++) 5087 Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl; 5088 delete(SimplyDegeneratedTriangles); 5089 5042 Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl; 5043 delete (SimplyDegeneratedTriangles); 5090 5044 /// 5. exit 5091 5045 UniquePolygonSet::iterator PolygonRunner; 5092 5046 while (!ListofDegeneratedPolygons.empty()) { 5093 5047 PolygonRunner = ListofDegeneratedPolygons.begin(); 5094 delete (*PolygonRunner);5048 delete (*PolygonRunner); 5095 5049 ListofDegeneratedPolygons.erase(PolygonRunner); 5096 5050 } 5097 5051 5098 5052 return counter; 5099 }; 5053 } 5054 ; -
src/tesselation.hpp
rbc84ffc r6613ec 89 89 90 90 #define ListOfTesselPointList list<list <TesselPoint *> *> 91 92 enum centers {Opt, OtherOpt}; 91 93 92 94 /********************************************** declarations *******************************/ … … 284 286 void AddTesselationTriangle(); 285 287 void AddTesselationTriangle(const int nr); 286 void AddCandidateTriangle(CandidateForTesselation &CandidateLine );288 void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type); 287 289 void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC); 288 290 void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC); … … 290 292 void RemoveTesselationLine(class BoundaryLineSet *line); 291 293 void RemoveTesselationPoint(class BoundaryPointSet *point); 292 bool CheckDegeneracy( Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC) const;294 bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const; 293 295 294 296 … … 298 300 void FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdNode, const double RADIUS, const LinkedCell *LC) const; 299 301 bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC); 302 bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList); 300 303 int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const; 301 304 class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]); … … 372 375 373 376 //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const; 377 void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter); 374 378 }; 375 379
Note:
See TracChangeset
for help on using the changeset viewer.