Changeset 5c7bf8 for src/tesselation.cpp
- Timestamp:
- Aug 8, 2009, 7:25:28 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:
- 08ef35
- Parents:
- 8bb475f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tesselation.cpp
r8bb475f r5c7bf8 64 64 for (int i = 0; i < 2; i++) 65 65 endpoints[i] = NULL; 66 TrianglesCount = 0;67 66 Nr = -1; 68 67 } … … 79 78 Point[1]->AddLine(this); // 80 79 // clear triangles list 81 TrianglesCount = 0;82 80 cout << Verbose(5) << "New Line with endpoints " << *this << "." << endl; 83 81 } … … 119 117 << endl; 120 118 triangles.insert(TrianglePair(triangle->Nr, triangle)); 121 TrianglesCount++;122 119 } 123 120 ; … … 143 140 bool BoundaryLineSet::CheckConvexityCriterion(ofstream *out) 144 141 { 145 Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2] ;142 Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck; 146 143 // get the two triangles 147 if ( TrianglesCount!= 2) {148 *out << Verbose(1) << "ERROR: Baseline " << this << " is connect to less than two triangles, Tesselation incomplete!" << endl;144 if (triangles.size() != 2) { 145 *out << Verbose(1) << "ERROR: Baseline " << *this << " is connect to less than two triangles, Tesselation incomplete!" << endl; 149 146 return false; 150 147 } 148 // check normal vectors 151 149 // have a normal vector on the base line pointing outwards 152 150 *out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl; … … 159 157 160 158 BaseLineNormal.Zero(); 159 NormalCheck.Zero(); 160 double sign = -1.; 161 161 int i=0; 162 162 class BoundaryPointSet *node = NULL; 163 163 for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 164 164 *out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 165 NormalCheck.AddVector(&runner->second->NormalVector); 166 NormalCheck.Scale(sign); 167 sign = -sign; 165 168 BaseLineNormal.SubtractVector(&runner->second->NormalVector); // we subtract as BaseLineNormal has to point inward in direction of [pi,2pi] 166 169 node = runner->second->GetThirdEndpoint(this); … … 178 181 } 179 182 *out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl; 180 double angle = helper[0].Angle(&helper[1]);181 if (BaseLineNormal.ScalarProduct(&helper[1]) > 0) {182 angle = 2.*M_PI - angle;183 } 184 *out << Verbose(3) << "The angle is " << angle << "." << endl;183 if (NormalCheck.NormSquared() < MYEPSILON) { 184 *out << Verbose(3) << "Normalvectors of both triangles are the same: convex." << endl; 185 return true; 186 } 187 double angle = getAngle(helper[0], helper[1], BaseLineNormal); 185 188 if ((angle - M_PI) > -MYEPSILON) 186 189 return true; … … 327 330 Vector CrossPoint; 328 331 Vector helper; 332 333 if (!Intersection->GetIntersectionWithPlane(out, &NormalVector, endpoints[0]->node->node, MolCenter, x)) { 334 *out << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl; 335 return false; 336 } 337 338 // Calculate cross point between one baseline and the line from the third endpoint to intersection 329 339 int i=0; 330 331 if (Intersection->GetIntersectionWithPlane(out, &NormalVector, endpoints[0]->node->node, MolCenter, x)) {332 *out << Verbose(1) << "Alas! [Bronstein] failed - at least numerically - the intersection is not on the plane!" << endl;333 return false;334 }335 336 // Calculate cross point between one baseline and the line from the third endpoint to intersection337 340 do { 338 CrossPoint.GetIntersectionOfTwoLinesOnPlane(out, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection); 339 helper.CopyVector(endpoints[(i+1)%3]->node->node); 340 helper.SubtractVector(endpoints[i%3]->node->node); 341 i++; 342 if (i>3) 341 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(out, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) { 342 helper.CopyVector(endpoints[(i+1)%3]->node->node); 343 helper.SubtractVector(endpoints[i%3]->node->node); 344 } else 345 i++; 346 if (i>2) 343 347 break; 344 348 } while (CrossPoint.NormSquared() < MYEPSILON); 345 if (i >3) {349 if (i==3) { 346 350 *out << Verbose(1) << "ERROR: Could not find any cross points, something's utterly wrong here!" << endl; 347 351 exit(255); … … 466 470 }; 467 471 472 /** Prints LCNode to screen. 473 */ 474 ostream & TesselPoint::operator << (ostream &ost) 475 { 476 ost << "[" << (Name) << "|" << this << "]"; 477 return ost; 478 }; 479 468 480 469 481 // =========================================================== class POINTCLOUD ============================================ … … 510 522 LinesOnBoundaryCount = 0; 511 523 TrianglesOnBoundaryCount = 0; 524 InternalPointer = PointsOnBoundary.begin(); 512 525 } 513 526 ; … … 528 541 } 529 542 ; 543 544 /** PointCloud implementation of GetCenter 545 * Uses PointsOnBoundary and STL stuff. 546 */ 547 Vector * Tesselation::GetCenter(ofstream *out) 548 { 549 Vector *Center = new Vector(0.,0.,0.); 550 int num=0; 551 for (GoToFirst(); (!IsEnd()); GoToNext()) { 552 Center->AddVector(GetPoint()->node); 553 num++; 554 } 555 Center->Scale(1./num); 556 return Center; 557 }; 558 559 /** PointCloud implementation of GoPoint 560 * Uses PointsOnBoundary and STL stuff. 561 */ 562 TesselPoint * Tesselation::GetPoint() 563 { 564 return (InternalPointer->second->node); 565 }; 566 567 /** PointCloud implementation of GetTerminalPoint. 568 * Uses PointsOnBoundary and STL stuff. 569 */ 570 TesselPoint * Tesselation::GetTerminalPoint() 571 { 572 PointMap::iterator Runner = PointsOnBoundary.end(); 573 Runner--; 574 return (Runner->second->node); 575 }; 576 577 /** PointCloud implementation of GoToNext. 578 * Uses PointsOnBoundary and STL stuff. 579 */ 580 void Tesselation::GoToNext() 581 { 582 if (InternalPointer != PointsOnBoundary.end()) 583 InternalPointer++; 584 }; 585 586 /** PointCloud implementation of GoToPrevious. 587 * Uses PointsOnBoundary and STL stuff. 588 */ 589 void Tesselation::GoToPrevious() 590 { 591 if (InternalPointer != PointsOnBoundary.begin()) 592 InternalPointer--; 593 }; 594 595 /** PointCloud implementation of GoToFirst. 596 * Uses PointsOnBoundary and STL stuff. 597 */ 598 void Tesselation::GoToFirst() 599 { 600 InternalPointer = PointsOnBoundary.begin(); 601 }; 602 603 /** PointCloud implementation of GoToLast. 604 * Uses PointsOnBoundary and STL stuff. 605 */ 606 void Tesselation::GoToLast() 607 { 608 InternalPointer = PointsOnBoundary.end(); 609 InternalPointer--; 610 }; 611 612 /** PointCloud implementation of IsEmpty. 613 * Uses PointsOnBoundary and STL stuff. 614 */ 615 bool Tesselation::IsEmpty() 616 { 617 return (PointsOnBoundary.empty()); 618 }; 619 620 /** PointCloud implementation of IsLast. 621 * Uses PointsOnBoundary and STL stuff. 622 */ 623 bool Tesselation::IsEnd() 624 { 625 return (InternalPointer == PointsOnBoundary.end()); 626 }; 627 530 628 531 629 /** Gueses first starting triangle of the convex envelope. … … 718 816 flag = false; 719 817 for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++) 720 if (baseline->second-> TrianglesCount== 1) {818 if (baseline->second->triangles.size() == 1) { 721 819 // 5a. go through each boundary point if not _both_ edges between either endpoint of the current line and this point exist (and belong to 2 triangles) 722 820 SmallestAngle = M_PI; … … 783 881 LineChecker[0] = baseline->second->endpoints[0]->lines.find(target->first); 784 882 LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first); 785 if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second-> TrianglesCount== 2))) {786 *out << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second-> TrianglesCount<< " triangles." << endl;883 if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) { 884 *out << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl; 787 885 continue; 788 886 } 789 if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second-> TrianglesCount== 2))) {790 *out << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second-> TrianglesCount<< " triangles." << endl;887 if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) { 888 *out << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl; 791 889 continue; 792 890 } … … 889 987 // 5d. If the set of lines is not yet empty, go to 5. and continue 890 988 } else 891 *out << Verbose(2) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second-> TrianglesCount<< "." << endl;989 *out << Verbose(2) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl; 892 990 } while (flag); 893 991 … … 904 1002 bool Tesselation::InsertStraddlingPoints(ofstream *out, PointCloud *cloud, LinkedCell *LC) 905 1003 { 906 Vector Intersection ;1004 Vector Intersection, Normal; 907 1005 TesselPoint *Walker = NULL; 908 1006 Vector *Center = cloud->GetCenter(out); … … 913 1011 cloud->GoToFirst(); 914 1012 while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger 1013 LinkedCell BoundaryPoints(this, 5.); 915 1014 Walker = cloud->GetPoint(); 916 1015 *out << Verbose(2) << "Current point is " << *Walker << "." << endl; 917 1016 // get the next triangle 918 triangles = FindClosestTrianglesToPoint(out, Walker->node, LC);1017 triangles = FindClosestTrianglesToPoint(out, Walker->node, &BoundaryPoints); 919 1018 if (triangles == NULL) { 920 1019 *out << Verbose(1) << "No triangles found, probably a tesselation point itself." << endl; … … 924 1023 BTS = triangles->front(); 925 1024 } 926 *out << Verbose(2) << "Closest triangle is " << BTS << "." << endl;1025 *out << Verbose(2) << "Closest triangle is " << *BTS << "." << endl; 927 1026 // get the intersection point 928 1027 if (BTS->GetIntersectionInsideTriangle(out, Center, Walker->node, &Intersection)) { … … 931 1030 if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) { 932 1031 // inside, next! 933 *out << Verbose( 4) << Walker << " is inside wrt triangle " <<BTS << "." << endl;1032 *out << Verbose(2) << *Walker << " is inside wrt triangle " << *BTS << "." << endl; 934 1033 } else { 935 1034 // outside! 936 *out << Verbose( 3) << Walker << " is outside wrt triangle " <<BTS << "." << endl;1035 *out << Verbose(2) << *Walker << " is outside wrt triangle " << *BTS << "." << endl; 937 1036 class BoundaryLineSet *OldLines[3], *NewLines[3]; 938 1037 class BoundaryPointSet *OldPoints[3], *NewPoint; … … 942 1041 OldPoints[i] = BTS->endpoints[i]; 943 1042 } 1043 Normal.CopyVector(&BTS->NormalVector); 944 1044 // add Walker to boundary points 1045 *out << Verbose(2) << "Adding " << *Walker << " to BoundaryPoints." << endl; 945 1046 AddPoint(Walker); 946 if (BPS[0] == NULL)1047 if (BPS[0] != NULL) 947 1048 NewPoint = BPS[0]; 948 1049 else 949 1050 continue; 950 1051 // remove triangle 1052 *out << Verbose(2) << "Erasing triangle " << *BTS << "." << endl; 951 1053 TrianglesOnBoundary.erase(BTS->Nr); 1054 delete(BTS); 952 1055 // create three new boundary lines 953 1056 for (int i=0;i<3;i++) { … … 955 1058 BPS[1] = OldPoints[i]; 956 1059 NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); 1060 *out << Verbose(3) << "Creating new line " << *NewLines[i] << "." << endl; 957 1061 LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one 958 1062 LinesOnBoundaryCount++; … … 973 1077 // create the triangle 974 1078 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1079 Normal.Scale(-1.); 1080 BTS->GetNormalVector(Normal); 1081 Normal.Scale(-1.); 1082 *out << Verbose(2) << "Created new triangle " << *BTS << "." << endl; 975 1083 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); 976 1084 TrianglesOnBoundaryCount++; … … 1046 1154 for (FindLine = FindPair.first; FindLine != FindPair.second; ++FindLine) { 1047 1155 // If there is a line with less than two attached triangles, we don't need a new line. 1048 if (FindLine->second-> TrianglesCount< 2) {1156 if (FindLine->second->triangles.size() < 2) { 1049 1157 insertNewLine = false; 1050 1158 cout << Verbose(3) << "Using existing line " << *FindLine->second << endl; … … 1247 1355 SearchDirection.MakeNormalVector(&Chord, &Oben); // whether we look "left" first or "right" first is not important ... 1248 1356 1249 // adding point 1 and point 2 and the line between them1357 // adding point 1 and point 2 and add the line between them 1250 1358 AddTrianglePoint(FirstPoint, 0); 1251 1359 AddTrianglePoint(SecondPoint, 1); … … 1464 1572 cout << "--> WARNING: Special new triangle with " << *BTS << " and normal vector " << BTS->NormalVector 1465 1573 << " for this triangle ... " << endl; 1466 cout << Verbose(1) << "We have "<< BaseRay-> TrianglesCount<< " for line " << BaseRay << "." << endl;1574 cout << Verbose(1) << "We have "<< BaseRay->triangles.size() << " for line " << BaseRay << "." << endl; 1467 1575 } else { 1468 1576 cout << Verbose(1) << "WARNING: This triangle consisting of "; … … 1513 1621 *out << Verbose(1) << "Begin of CorrectConcaveBaselines" << endl; 1514 1622 1515 for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline++) { 1623 // go through every baseline 1624 LineMap::iterator Advancer = LinesOnBoundary.begin(); 1625 for (LineMap::iterator baseline = LinesOnBoundary.begin(); baseline != LinesOnBoundary.end(); baseline = Advancer) { 1626 Advancer++; // as the base line might be removed, we rather have the next one already present 1516 1627 Base = baseline->second; 1517 1628 *out << Verbose(2) << "Current baseline is " << *Base << " ... " << endl; 1629 // calculate NormalVector for later use 1630 BaseLineNormal.Zero(); 1631 if (Base->triangles.size() < 2) { 1632 *out << Verbose(2) << "ERROR: Less than two triangles are attached to this baseline!" << endl; 1633 return false; 1634 } 1635 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 1636 *out << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl; 1637 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 1638 } 1639 BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector() 1518 1640 // check convexity 1519 1641 if (Base->CheckConvexityCriterion(out)) { // triangles are convex … … 1561 1683 1562 1684 // remove triangles and baseline removes itself 1563 m=0;1685 *out << Verbose(3) << "INFO: Deleting baseline " << *Base << "." << endl; 1564 1686 OldBaseLine = Base->Nr; 1565 1687 LinesOnBoundary.erase(OldBaseLine); 1688 m=0; 1566 1689 for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 1690 *out << Verbose(3) << "INFO: Deleting triangle " << *(runner->second) << "." << endl; 1567 1691 TrianglesOnBoundary.erase(OldTriangles[m++] = runner->second->Nr); 1568 1692 delete(runner->second); … … 1574 1698 NewLine = new class BoundaryLineSet(BPS, OldBaseLine); 1575 1699 LinesOnBoundary.insert(LinePair(OldBaseLine, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one 1700 *out << Verbose(3) << "INFO: Created new baseline " << *NewLine << "." << endl; 1576 1701 1577 1702 // construct new triangles with flipped baseline … … 1586 1711 BLS[2] = NewLine; 1587 1712 BTS = new class BoundaryTriangleSet(BLS, OldTriangles[0]); 1713 BTS->GetNormalVector(BaseLineNormal); 1588 1714 TrianglesOnBoundary.insert(TrianglePair(OldTriangles[0], BTS)); 1715 *out << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl; 1589 1716 1590 1717 BLS[0] = (i==2 ? OldLines[3] : OldLines[2]); … … 1592 1719 BLS[2] = NewLine; 1593 1720 BTS = new class BoundaryTriangleSet(BLS, OldTriangles[1]); 1721 BTS->GetNormalVector(BaseLineNormal); 1594 1722 TrianglesOnBoundary.insert(TrianglePair(OldTriangles[1], BTS)); 1723 *out << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl; 1595 1724 } else { 1596 1725 *out << Verbose(1) << "The four old lines do not connect, something's utterly wrong here!" << endl; … … 1949 2078 list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(ofstream *out, Vector *x, LinkedCell* LC) 1950 2079 { 1951 class TesselPoint *trianglePoints[3]; 2080 TesselPoint *trianglePoints[3]; 2081 TesselPoint *SecondPoint = NULL; 1952 2082 1953 2083 if (LinesOnBoundary.empty()) { 1954 *out << Verbose(0) << "Error: There is no tesselation structure to compare the point with, " << "please create one first.";2084 *out << Verbose(0) << "Error: There is no tesselation structure to compare the point with, please create one first."; 1955 2085 return NULL; 1956 2086 } 1957 2087 1958 trianglePoints[0] = findClosestPoint(x, LC); 2088 trianglePoints[0] = findClosestPoint(x, SecondPoint, LC); 2089 1959 2090 // check whether closest point is "too close" :), then it's inside 2091 if (trianglePoints[0] == NULL) { 2092 *out << Verbose(1) << "Is the only point, no one else is closeby." << endl; 2093 return NULL; 2094 } 1960 2095 if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) { 1961 2096 *out << Verbose(1) << "Point is right on a tesselation point, no nearest triangle." << endl; … … 1969 2104 *out << Verbose(1) << "IsInnerPoint encounters serious error, point " << i << " not found." << endl; 1970 2105 } 1971 *out << Verbose(1) << "List of possible points:" << endl; 1972 *out << *trianglePoints[i] << endl; 1973 } 2106 //*out << Verbose(1) << "List of possible points:" << endl; 2107 //*out << Verbose(2) << *trianglePoints[i] << endl; 2108 } 2109 2110 list<BoundaryTriangleSet*> *triangles = FindTriangles(trianglePoints); 2111 1974 2112 delete(connectedClosestPoints); 1975 1976 list<BoundaryTriangleSet*> *triangles = FindTriangles(trianglePoints); 1977 2113 1978 2114 if (triangles->empty()) { 1979 2115 *out << Verbose(0) << "Error: There is no nearest triangle. Please check the tesselation structure."; … … 2059 2195 map<double, TesselPoint*>::iterator runner; 2060 2196 list<TesselPoint*>::iterator listRunner; 2061 Vector center, planeNorm, currentPoint, OrthogonalVector, helper; 2197 class BoundaryPointSet *ReferencePoint = NULL; 2198 Vector center, PlaneNormal, currentPoint, OrthogonalVector, helper, AngleZero; 2062 2199 TesselPoint* current; 2063 2200 bool takePoint = false; 2064 2201 2065 planeNorm.CopyVector(Point->node); 2066 planeNorm.SubtractVector(Reference); 2067 planeNorm.Normalize(); 2068 2069 LineMap::iterator findLines = LinesOnBoundary.begin(); 2070 while (findLines != LinesOnBoundary.end()) { 2202 // find the respective boundary point 2203 PointMap::iterator PointRunner = PointsOnBoundary.find(Point->nr); 2204 if (PointRunner != PointsOnBoundary.end()) { 2205 ReferencePoint = PointRunner->second; 2206 } else { 2207 *out << Verbose(2) << "getCircleOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl; 2208 ReferencePoint = NULL; 2209 } 2210 2211 // little trick so that we look just through lines connect to the BoundaryPoint 2212 // OR fall-back to look through all lines if there is no such BoundaryPoint 2213 LineMap *Lines = &LinesOnBoundary; 2214 if (ReferencePoint != NULL) 2215 Lines = &(ReferencePoint->lines); 2216 LineMap::iterator findLines = Lines->begin(); 2217 while (findLines != Lines->end()) { 2071 2218 takePoint = false; 2072 2219 … … 2078 2225 current = findLines->second->endpoints[0]->node; 2079 2226 } 2080 2227 2081 2228 if (takePoint) { 2229 *out << Verbose(3) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is taken into the circle." << endl; 2082 2230 connectedPoints.push_back(current); 2083 2231 currentPoint.CopyVector(current->node); 2084 currentPoint.ProjectOntoPlane(& planeNorm);2232 currentPoint.ProjectOntoPlane(&PlaneNormal); 2085 2233 center.AddVector(¤tPoint); 2086 2234 } … … 2089 2237 } 2090 2238 2091 *out << "Summed vectors " << center << "; number of points " << connectedPoints.size() 2092 << "; scale factor " << 1.0/connectedPoints.size(); 2093 2239 //*out << "Summed vectors " << center << "; number of points " << connectedPoints.size() 2240 // << "; scale factor " << 1.0/connectedPoints.size(); 2241 2242 if (connectedPoints.size() == 0) { // if have not found any points 2243 *out << Verbose(1) << "ERROR: We have not found any connected points to " << *Point<< "." << endl; 2244 return NULL; 2245 } 2094 2246 center.Scale(1.0/connectedPoints.size()); 2247 2248 *out << Verbose(4) << "INFO: Calculated center of all circle points is " << center << "." << endl; 2249 2250 // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points 2251 PlaneNormal.CopyVector(Point->node); 2252 PlaneNormal.SubtractVector(¢er); 2253 PlaneNormal.Normalize(); 2254 *out << Verbose(4) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl; 2255 2256 // construct one orthogonal vector 2257 AngleZero.CopyVector(Reference); 2258 AngleZero.SubtractVector(Point->node); 2259 AngleZero.ProjectOntoPlane(&PlaneNormal); 2260 *out << Verbose(4) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl; 2261 OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero); 2262 *out << Verbose(4) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl; 2263 2264 // go through all connected points and calculate angle 2095 2265 listRunner = connectedPoints.begin(); 2096 2097 *out << " calculated center " << center << endl;2098 2099 // construct one orthogonal vector2100 helper.CopyVector(Reference);2101 helper.ProjectOntoPlane(&planeNorm);2102 OrthogonalVector.MakeNormalVector(¢er, &helper, (*listRunner)->node);2103 2266 while (listRunner != connectedPoints.end()) { 2104 double angle = getAngle(*((*listRunner)->node), *(Reference), center, OrthogonalVector); 2105 *out << "Calculated angle " << angle << " for point " << **listRunner << endl; 2267 helper.CopyVector((*listRunner)->node); 2268 helper.SubtractVector(Point->node); 2269 helper.ProjectOntoPlane(&PlaneNormal); 2270 double angle = getAngle(helper, AngleZero, OrthogonalVector); 2271 *out << Verbose(2) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl; 2106 2272 anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner))); 2107 2273 listRunner++; … … 2110 2276 list<TesselPoint*> *result = new list<TesselPoint*>; 2111 2277 runner = anglesOfPoints.begin(); 2112 *out << "First value is " << *runner->second << endl;2113 2278 result->push_back(runner->second); 2114 2279 runner = anglesOfPoints.end(); 2115 2280 runner--; 2116 *out << "Second value is " << *runner->second << endl;2117 2281 result->push_back(runner->second); 2118 2282 2119 *out << "List of closest points has " << result->size() << " elements, which are "2283 *out << Verbose(2) << "List of closest points has " << result->size() << " elements, which are " 2120 2284 << *(result->front()) << " and " << *(result->back()) << endl; 2121 2285 … … 2143 2307 for (FindLine = FindPair.first; FindLine != FindPair.second; ++FindLine) { 2144 2308 // If there is a line with less than two attached triangles, we don't need a new line. 2145 if (FindLine->second-> TrianglesCount< 2) {2309 if (FindLine->second->triangles.size() < 2) { 2146 2310 counter++; 2147 2311 break; // increase counter only once per edge … … 2149 2313 } 2150 2314 } else { // no line 2151 cout << Verbose(1) << " ERROR: The line between " << nodes[i] << " and " << nodes[j] << " is not yet present, hence no need for a degenerate triangle!" << endl;2315 cout << Verbose(1) << "The line between " << nodes[i] << " and " << nodes[j] << " is not yet present, hence no need for a degenerate triangle." << endl; 2152 2316 result = true; 2153 2317 } … … 2205 2369 }; 2206 2370 2207 2208 2209 2371 /** 2210 * Finds the point which is closest to the provided one.2372 * Finds the point which is second closest to the provided one. 2211 2373 * 2212 * @param Point to which to find the closest other point2374 * @param Point to which to find the second closest other point 2213 2375 * @param linked cell structure 2214 2376 * 2215 * @return point which is closest to the provided one2216 */ 2217 TesselPoint* find ClosestPoint(const Vector* Point, LinkedCell* LC)2377 * @return point which is second closest to the provided one 2378 */ 2379 TesselPoint* findSecondClosestPoint(const Vector* Point, LinkedCell* LC) 2218 2380 { 2219 2381 LinkedNodes *List = NULL; 2220 2382 TesselPoint* closestPoint = NULL; 2383 TesselPoint* secondClosestPoint = NULL; 2221 2384 double distance = 1e16; 2385 double secondDistance = 1e16; 2222 2386 Vector helper; 2223 2387 int N[NDIM], Nlower[NDIM], Nupper[NDIM]; … … 2226 2390 for(int i=0;i<NDIM;i++) // store indices of this cell 2227 2391 N[i] = LC->n[i]; 2228 //cout << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;2392 cout << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl; 2229 2393 2230 2394 LC->GetNeighbourBounds(Nlower, Nupper); … … 2234 2398 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) { 2235 2399 List = LC->GetCurrentCell(); 2236 //cout<< "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;2400 cout << Verbose(3) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl; 2237 2401 if (List != NULL) { 2238 2402 for (LinkedNodes::iterator Runner = List->begin(); Runner != List->end(); Runner++) { … … 2241 2405 double currentNorm = helper. Norm(); 2242 2406 if (currentNorm < distance) { 2407 // remember second point 2408 secondDistance = distance; 2409 secondClosestPoint = closestPoint; 2410 // mark down new closest point 2243 2411 distance = currentNorm; 2244 2412 closestPoint = (*Runner); 2413 cout << Verbose(2) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl; 2245 2414 } 2246 2415 } … … 2251 2420 } 2252 2421 2422 return secondClosestPoint; 2423 }; 2424 2425 2426 2427 /** 2428 * Finds the point which is closest to the provided one. 2429 * 2430 * @param Point to which to find the closest other point 2431 * @param SecondPoint the second closest other point on return, NULL if none found 2432 * @param linked cell structure 2433 * 2434 * @return point which is closest to the provided one, NULL if none found 2435 */ 2436 TesselPoint* findClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC) 2437 { 2438 LinkedNodes *List = NULL; 2439 TesselPoint* closestPoint = NULL; 2440 SecondPoint = NULL; 2441 double distance = 1e16; 2442 double secondDistance = 1e16; 2443 Vector helper; 2444 int N[NDIM], Nlower[NDIM], Nupper[NDIM]; 2445 2446 LC->SetIndexToVector(Point); // ignore status as we calculate bounds below sensibly 2447 for(int i=0;i<NDIM;i++) // store indices of this cell 2448 N[i] = LC->n[i]; 2449 cout << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl; 2450 2451 LC->GetNeighbourBounds(Nlower, Nupper); 2452 //cout << endl; 2453 for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++) 2454 for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++) 2455 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) { 2456 List = LC->GetCurrentCell(); 2457 cout << Verbose(3) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl; 2458 if (List != NULL) { 2459 for (LinkedNodes::iterator Runner = List->begin(); Runner != List->end(); Runner++) { 2460 helper.CopyVector(Point); 2461 helper.SubtractVector((*Runner)->node); 2462 double currentNorm = helper. Norm(); 2463 if (currentNorm < distance) { 2464 secondDistance = distance; 2465 SecondPoint = closestPoint; 2466 distance = currentNorm; 2467 closestPoint = (*Runner); 2468 cout << Verbose(2) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl; 2469 } else if (currentNorm < secondDistance) { 2470 secondDistance = currentNorm; 2471 SecondPoint = (*Runner); 2472 cout << Verbose(2) << "INFO: New Second Nearest Neighbour is " << *SecondPoint << "." << endl; 2473 } 2474 } 2475 } else { 2476 cerr << "ERROR: The current cell " << LC->n[0] << "," << LC->n[1] << "," 2477 << LC->n[2] << " is invalid!" << endl; 2478 } 2479 } 2480 2253 2481 return closestPoint; 2254 } 2482 }; 2255 2483 2256 2484 … … 2321 2549 2322 2550 /** Gets the angle between a point and a reference relative to the provided center. 2323 * We have two shanks (point, center) and (reference, center)between which the angle is calculated2551 * We have two shanks point and reference between which the angle is calculated 2324 2552 * and by scalar product with OrthogonalVector we decide the interval. 2325 2553 * @param point to calculate the angle for 2326 2554 * @param reference to which to calculate the angle 2327 * @param center for which to calculate the angle between the vectors2328 2555 * @param OrthogonalVector points in direction of [pi,2pi] interval 2329 2556 * 2330 2557 * @return angle between point and reference 2331 2558 */ 2332 double getAngle(const Vector &point, const Vector &reference, const Vector ¢er, Vector OrthogonalVector) 2333 { 2334 Vector ReferenceVector, helper; 2335 cout << Verbose(4) << center << " is our center " << endl; 2336 // create baseline vector 2337 ReferenceVector.CopyVector(&reference); 2338 ReferenceVector.SubtractVector(¢er); 2339 OrthogonalVector.MakeNormalVector(&ReferenceVector); 2340 cout << Verbose(4) << ReferenceVector << " is our reference " << endl; 2341 if (ReferenceVector.IsNull()) 2559 double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector) 2560 { 2561 if (reference.IsNull()) 2342 2562 return M_PI; 2343 2563 2344 2564 // calculate both angles and correct with in-plane vector 2345 helper.CopyVector(&point); 2346 helper.SubtractVector(¢er); 2347 if (helper.IsNull()) 2565 if (point.IsNull()) 2348 2566 return M_PI; 2349 double phi = ReferenceVector.Angle(&helper);2350 if (OrthogonalVector.ScalarProduct(& helper) > 0) {2567 double phi = point.Angle(&reference); 2568 if (OrthogonalVector.ScalarProduct(&point) > 0) { 2351 2569 phi = 2.*M_PI - phi; 2352 2570 } 2353 2571 2354 cout << Verbose(3) << helper << " has angle " << phi << " with respect to reference." << endl;2572 cout << Verbose(3) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl; 2355 2573 2356 2574 return phi;
Note:
See TracChangeset
for help on using the changeset viewer.