Changes in molecuilder/src/tesselation.cpp [d6b011:78dac6]
- File:
-
- 1 edited
-
molecuilder/src/tesselation.cpp (modified) (63 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/tesselation.cpp
rd6b011 r78dac6 16 16 LinesCount = 0; 17 17 Nr = -1; 18 value = 0.; 18 19 }; 19 20 … … 26 27 LinesCount = 0; 27 28 Nr = Walker->nr; 29 value = 0.; 28 30 }; 29 31 … … 148 150 void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle) 149 151 { 150 cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." 151 << endl; 152 cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl; 152 153 triangles.insert(TrianglePair(triangle->Nr, triangle)); 153 154 }; … … 177 178 if (triangles.size() != 2) { 178 179 *out << Verbose(1) << "ERROR: Baseline " << *this << " is connect to less than two triangles, Tesselation incomplete!" << endl; 179 return false;180 return true; 180 181 } 181 182 // check normal vectors 182 183 // have a normal vector on the base line pointing outwards 183 *out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;184 //*out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl; 184 185 BaseLineCenter.CopyVector(endpoints[0]->node->node); 185 186 BaseLineCenter.AddVector(endpoints[1]->node->node); … … 187 188 BaseLine.CopyVector(endpoints[0]->node->node); 188 189 BaseLine.SubtractVector(endpoints[1]->node->node); 189 *out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;190 //*out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl; 190 191 191 192 BaseLineNormal.Zero(); … … 195 196 class BoundaryPointSet *node = NULL; 196 197 for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 197 *out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;198 //*out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 198 199 NormalCheck.AddVector(&runner->second->NormalVector); 199 200 NormalCheck.Scale(sign); … … 202 203 node = runner->second->GetThirdEndpoint(this); 203 204 if (node != NULL) { 204 *out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;205 //*out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl; 205 206 helper[i].CopyVector(node->node->node); 206 207 helper[i].SubtractVector(&BaseLineCenter); 207 208 helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles! 208 *out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;209 //*out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 209 210 i++; 210 211 } else { 211 *out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl;212 //*out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl; 212 213 return true; 213 214 } 214 215 } 215 *out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;216 //*out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl; 216 217 if (NormalCheck.NormSquared() < MYEPSILON) { 217 *out << Verbose( 3) << "Normalvectors of both triangles are the same: convex." << endl;218 *out << Verbose(2) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl; 218 219 return true; 219 220 } 220 double angle = GetAngle(helper[0], helper[1], BaseLineNormal); 221 if ((angle - M_PI) > -MYEPSILON) 221 double angle = getAngle(helper[0], helper[1], BaseLineNormal); 222 if ((angle - M_PI) > -MYEPSILON) { 223 *out << Verbose(2) << "ACCEPT: Angle is greater than pi: convex." << endl; 222 224 return true; 223 else 225 } else { 226 *out << Verbose(2) << "REJECT: Angle is less than pi: concave." << endl; 224 227 return false; 228 } 225 229 } 226 230 … … 349 353 350 354 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 351 if (NormalVector. Projection(&OtherVector) > 0)355 if (NormalVector.ScalarProduct(&OtherVector) > 0.) 352 356 NormalVector.Scale(-1.); 353 357 }; … … 737 741 TrialVector.CopyVector(checker->second->node->node); 738 742 TrialVector.SubtractVector(A->second->node->node); 739 distance = TrialVector. Projection(&PlaneVector);743 distance = TrialVector.ScalarProduct(&PlaneVector); 740 744 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 741 745 continue; … … 897 901 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 898 902 //*out << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl; 899 if (PropagationVector. Projection(&TempVector) > 0) // make sure normal propagation vector points outward from baseline903 if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline 900 904 PropagationVector.Scale(-1.); 901 905 *out << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl; … … 957 961 TempVector.SubtractVector(Center); 958 962 // make it always point outward 959 if (VirtualNormalVector. Projection(&TempVector) < 0)963 if (VirtualNormalVector.ScalarProduct(&TempVector) < 0) 960 964 VirtualNormalVector.Scale(-1.); 961 965 // calculate angle … … 1398 1402 1399 1403 1400 /** Finds the starting triangle for FindNonConvexBorder().1401 * Looks at the outermost point per axis, then Find SecondPointForTesselation()1402 * for the second and Find NextSuitablePointViaAngleOfSphere() for the third1404 /** Finds the starting triangle for find_non_convex_border(). 1405 * Looks at the outermost point per axis, then Find_second_point_for_Tesselation() 1406 * for the second and Find_next_suitable_point_via_Angle_of_Sphere() for the third 1403 1407 * point are called. 1404 1408 * \param *out output stream for debugging … … 1406 1410 * \param *LC LinkedCell structure with neighbouring TesselPoint's 1407 1411 */ 1408 void Tesselation::Find StartingTriangle(ofstream *out, const double RADIUS, LinkedCell *LC)1409 { 1410 cout << Verbose(1) << "Begin of Find StartingTriangle\n";1412 void Tesselation::Find_starting_triangle(ofstream *out, const double RADIUS, LinkedCell *LC) 1413 { 1414 cout << Verbose(1) << "Begin of Find_starting_triangle\n"; 1411 1415 int i = 0; 1412 1416 LinkedNodes *List = NULL; … … 1414 1418 TesselPoint* SecondPoint = NULL; 1415 1419 TesselPoint* MaxPoint[NDIM]; 1416 double max Coordinate[NDIM];1420 double max_coordinate[NDIM]; 1417 1421 Vector Oben; 1418 1422 Vector helper; … … 1424 1428 for (i = 0; i < 3; i++) { 1425 1429 MaxPoint[i] = NULL; 1426 max Coordinate[i] = -1;1430 max_coordinate[i] = -1; 1427 1431 } 1428 1432 … … 1436 1440 if (List != NULL) { 1437 1441 for (LinkedNodes::iterator Runner = List->begin();Runner != List->end();Runner++) { 1438 if ((*Runner)->node->x[i] > max Coordinate[i]) {1442 if ((*Runner)->node->x[i] > max_coordinate[i]) { 1439 1443 cout << Verbose(2) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl; 1440 max Coordinate[i] = (*Runner)->node->x[i];1444 max_coordinate[i] = (*Runner)->node->x[i]; 1441 1445 MaxPoint[i] = (*Runner); 1442 1446 } … … 1454 1458 1455 1459 BTS = NULL; 1456 CandidateList *Opt Candidates = new CandidateList();1460 CandidateList *Opt_Candidates = new CandidateList(); 1457 1461 for (int k=0;k<NDIM;k++) { 1458 1462 Oben.x[k] = 1.; … … 1461 1465 1462 1466 double ShortestAngle; 1463 TesselPoint* Opt Candidate = NULL;1467 TesselPoint* Opt_Candidate = NULL; 1464 1468 ShortestAngle = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant. 1465 1469 1466 Find SecondPointForTesselation(FirstPoint, NULL, Oben, OptCandidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...1467 SecondPoint = Opt Candidate;1470 Find_second_point_for_Tesselation(FirstPoint, NULL, Oben, Opt_Candidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_... 1471 SecondPoint = Opt_Candidate; 1468 1472 if (SecondPoint == NULL) // have we found a second point? 1469 1473 continue; … … 1496 1500 1497 1501 //cout << Verbose(2) << "INFO: OldSphereCenter is at " << helper << ".\n"; 1498 Find ThirdPointForTesselation(1499 Oben, SearchDirection, helper, BLS[0], NULL, *&Opt Candidates, &ShortestAngle, RADIUS, LC1502 Find_third_point_for_Tesselation( 1503 Oben, SearchDirection, helper, BLS[0], NULL, *&Opt_Candidates, &ShortestAngle, RADIUS, LC 1500 1504 ); 1501 1505 cout << Verbose(1) << "List of third Points is "; 1502 for (CandidateList::iterator it = Opt Candidates->begin(); it != OptCandidates->end(); ++it) {1506 for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) { 1503 1507 cout << " " << *(*it)->point; 1504 1508 } 1505 1509 cout << endl; 1506 1510 1507 for (CandidateList::iterator it = Opt Candidates->begin(); it != OptCandidates->end(); ++it) {1511 for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) { 1508 1512 // add third triangle point 1509 1513 AddTesselationPoint((*it)->point, 2); … … 1522 1526 1523 1527 // if we do not reach the end with the next step of iteration, we need to setup a new first line 1524 if (it != Opt Candidates->end()--) {1528 if (it != Opt_Candidates->end()--) { 1525 1529 FirstPoint = (*it)->BaseLine->endpoints[0]->node; 1526 1530 SecondPoint = (*it)->point; … … 1530 1534 AddTesselationLine(TPS[0], TPS[1], 0); 1531 1535 } 1532 cout << Verbose(2) << "Projection is " << BTS->NormalVector. Projection(&Oben) << "." << endl;1536 cout << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl; 1533 1537 } 1534 1538 if (BTS != NULL) // we have created one starting triangle … … 1537 1541 // remove all candidates from the list and then the list itself 1538 1542 class CandidateForTesselation *remover = NULL; 1539 for (CandidateList::iterator it = Opt Candidates->begin(); it != OptCandidates->end(); ++it) {1543 for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) { 1540 1544 remover = *it; 1541 1545 delete(remover); 1542 1546 } 1543 Opt Candidates->clear();1547 Opt_Candidates->clear(); 1544 1548 } 1545 1549 } … … 1547 1551 // remove all candidates from the list and then the list itself 1548 1552 class CandidateForTesselation *remover = NULL; 1549 for (CandidateList::iterator it = Opt Candidates->begin(); it != OptCandidates->end(); ++it) {1553 for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) { 1550 1554 remover = *it; 1551 1555 delete(remover); 1552 1556 } 1553 delete(Opt Candidates);1554 cout << Verbose(1) << "End of Find StartingTriangle\n";1557 delete(Opt_Candidates); 1558 cout << Verbose(1) << "End of Find_starting_triangle\n"; 1555 1559 }; 1556 1560 … … 1564 1568 * @param *LC LinkedCell structure with neighbouring points 1565 1569 */ 1566 bool Tesselation::Find NextSuitableTriangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC)1567 { 1568 cout << Verbose(0) << "Begin of Find NextSuitableTriangle\n";1570 bool Tesselation::Find_next_suitable_triangle(ofstream *out, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N, LinkedCell *LC) 1571 { 1572 cout << Verbose(0) << "Begin of Find_next_suitable_triangle\n"; 1569 1573 bool result = true; 1570 CandidateList *Opt Candidates = new CandidateList();1574 CandidateList *Opt_Candidates = new CandidateList(); 1571 1575 1572 1576 Vector CircleCenter; … … 1625 1629 1626 1630 // add third point 1627 Find ThirdPointForTesselation(1628 T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, Opt Candidates,1631 Find_third_point_for_Tesselation( 1632 T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, Opt_Candidates, 1629 1633 &ShortestAngle, RADIUS, LC 1630 1634 ); … … 1634 1638 } 1635 1639 1636 if (Opt Candidates->begin() == OptCandidates->end()) {1640 if (Opt_Candidates->begin() == Opt_Candidates->end()) { 1637 1641 cerr << "WARNING: Could not find a suitable candidate." << endl; 1638 1642 return false; 1639 1643 } 1640 1644 cout << Verbose(1) << "Third Points are "; 1641 for (CandidateList::iterator it = Opt Candidates->begin(); it != OptCandidates->end(); ++it) {1645 for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) { 1642 1646 cout << " " << *(*it)->point; 1643 1647 } … … 1645 1649 1646 1650 BoundaryLineSet *BaseRay = &Line; 1647 for (CandidateList::iterator it = Opt Candidates->begin(); it != OptCandidates->end(); ++it) {1651 for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) { 1648 1652 cout << Verbose(1) << " Third point candidate is " << *(*it)->point 1649 1653 << " with circumsphere's center at " << (*it)->OptCenter << "." << endl; … … 1664 1668 AddTesselationPoint(BaseRay->endpoints[1]->node, 2); 1665 1669 1666 if (CheckLineCriteria ForDegeneratedTriangle(TPS)) {1670 if (CheckLineCriteriaforDegeneratedTriangle(TPS)) { 1667 1671 AddTesselationLine(TPS[0], TPS[1], 0); 1668 1672 AddTesselationLine(TPS[0], TPS[2], 1); … … 1693 1697 // 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) 1694 1698 // i.e. at least one of the three lines must be present with TriangleCount <= 1 1695 if (CheckLineCriteria ForDegeneratedTriangle(TPS)) {1699 if (CheckLineCriteriaforDegeneratedTriangle(TPS)) { 1696 1700 AddTesselationLine(TPS[0], TPS[1], 0); 1697 1701 AddTesselationLine(TPS[0], TPS[2], 1); … … 1731 1735 // remove all candidates from the list and then the list itself 1732 1736 class CandidateForTesselation *remover = NULL; 1733 for (CandidateList::iterator it = Opt Candidates->begin(); it != OptCandidates->end(); ++it) {1737 for (CandidateList::iterator it = Opt_Candidates->begin(); it != Opt_Candidates->end(); ++it) { 1734 1738 remover = *it; 1735 1739 delete(remover); 1736 1740 } 1737 delete(Opt Candidates);1738 cout << Verbose(0) << "End of Find NextSuitableTriangle\n";1741 delete(Opt_Candidates); 1742 cout << Verbose(0) << "End of Find_next_suitable_triangle\n"; 1739 1743 return result; 1740 1744 }; … … 1751 1755 class BoundaryPointSet *Spot = NULL; 1752 1756 class BoundaryLineSet *OtherBase; 1753 Vector *ClosestPoint [2];1757 Vector *ClosestPoint; 1754 1758 1755 1759 int m=0; … … 1764 1768 1765 1769 // get the closest point on each line to the other line 1766 ClosestPoint[0] = GetClosestPointBetweenLine(out, Base, OtherBase); 1767 ClosestPoint[1] = GetClosestPointBetweenLine(out, OtherBase, Base); 1770 ClosestPoint = GetClosestPointBetweenLine(out, Base, OtherBase); 1768 1771 1769 1772 // delete the temporary other base line … … 1771 1774 1772 1775 // get the distance vector from Base line to OtherBase line 1773 Vector DistanceToIntersection, BaseLine; 1776 Vector DistanceToIntersection[2], BaseLine; 1777 double distance[2]; 1774 1778 BaseLine.CopyVector(Base->endpoints[1]->node->node); 1775 1779 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 1776 DistanceToIntersection.CopyVector(ClosestPoint[0]); 1777 DistanceToIntersection.SubtractVector(Base->endpoints[0]->node->node); 1778 Spot = Base->endpoints[1]; 1779 if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) { 1780 DistanceToIntersection.CopyVector(ClosestPoint[0]); 1781 DistanceToIntersection.SubtractVector(Base->endpoints[1]->node->node); 1782 Spot = Base->endpoints[0]; 1783 if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) { 1784 *out << Verbose(3) << "ERROR: Something's very wrong here, both SKPs return negative?!" << endl; 1785 return NULL; 1786 } 1787 } 1788 if ((BaseLine.NormSquared() - DistanceToIntersection.NormSquared()) < -MYEPSILON) { // distance is smaller: concave 1789 *out << Verbose(3) << "INFO: Rectangle of triangles of base line " << *Base << " is concave: Base line squared length " << BaseLine.NormSquared() << " against Distance to intersection squared " << DistanceToIntersection.NormSquared() << "." << endl; 1780 for (int i=0;i<2;i++) { 1781 DistanceToIntersection[i].CopyVector(ClosestPoint); 1782 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 1783 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 1784 } 1785 delete(ClosestPoint); 1786 if ((distance[0] * distance[1]) > 0) { // have same sign? 1787 *out << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl; 1788 if (distance[0] < distance[1]) { 1789 Spot = Base->endpoints[0]; 1790 } else { 1791 Spot = Base->endpoints[1]; 1792 } 1790 1793 return Spot; 1791 } else { // base line is longer: convex1792 *out << Verbose(3) << " INFO: Rectangle of triangles of base line " << *Base << " is concave." << endl;1794 } else { // different sign, i.e. we are in between 1795 *out << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl; 1793 1796 return NULL; 1794 1797 } … … 1796 1799 }; 1797 1800 1801 void Tesselation::PrintAllBoundaryPoints(ofstream *out) 1802 { 1803 // print all lines 1804 *out << Verbose(1) << "Printing all boundary points for debugging:" << endl; 1805 for (PointMap::iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++) 1806 *out << Verbose(2) << *(PointRunner->second) << endl; 1807 }; 1808 1809 void Tesselation::PrintAllBoundaryLines(ofstream *out) 1810 { 1811 // print all lines 1812 *out << Verbose(1) << "Printing all boundary lines for debugging:" << endl; 1813 for (LineMap::iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) 1814 *out << Verbose(2) << *(LineRunner->second) << endl; 1815 }; 1816 1817 void Tesselation::PrintAllBoundaryTriangles(ofstream *out) 1818 { 1819 // print all triangles 1820 *out << Verbose(1) << "Printing all boundary triangles for debugging:" << endl; 1821 for (TriangleMap::iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++) 1822 *out << Verbose(2) << *(TriangleRunner->second) << endl; 1823 }; 1798 1824 1799 1825 /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher". … … 1826 1852 Distance.SubtractVector(ClosestPoint[0]); 1827 1853 1828 // delete the temporary other base line 1854 // delete the temporary other base line and the closest points 1855 delete(ClosestPoint[0]); 1856 delete(ClosestPoint[1]); 1829 1857 delete(OtherBase); 1830 1858 … … 1843 1871 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 1844 1872 } 1845 BaseLineNormal.Scale( -1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()1873 BaseLineNormal.Scale(1./2.); 1846 1874 1847 1875 if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip … … 1866 1894 // construct the plane of the two baselines (i.e. take both their directional vectors) 1867 1895 Vector Normal; 1868 Vector OtherBaseline;1869 Normal.CopyVector(Base->endpoints[1]->node->node);1870 Normal.SubtractVector(Base->endpoints[0]->node->node);1896 Vector Baseline, OtherBaseline; 1897 Baseline.CopyVector(Base->endpoints[1]->node->node); 1898 Baseline.SubtractVector(Base->endpoints[0]->node->node); 1871 1899 OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node); 1872 1900 OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node); 1901 Normal.CopyVector(&Baseline); 1873 1902 Normal.VectorProduct(&OtherBaseline); 1874 1903 Normal.Normalize(); 1875 1876 // project one offset point of OtherBase onto this plane 1904 *out << Verbose(4) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl; 1905 1906 // project one offset point of OtherBase onto this plane (and add plane offset vector) 1877 1907 Vector NewOffset; 1878 1908 NewOffset.CopyVector(OtherBase->endpoints[0]->node->node); 1909 NewOffset.SubtractVector(Base->endpoints[0]->node->node); 1879 1910 NewOffset.ProjectOntoPlane(&Normal); 1911 NewOffset.AddVector(Base->endpoints[0]->node->node); 1880 1912 Vector NewDirection; 1881 NewDirection.CopyVector( OtherBase->endpoints[1]->node->node);1882 NewDirection. ProjectOntoPlane(&Normal);1913 NewDirection.CopyVector(&NewOffset); 1914 NewDirection.AddVector(&OtherBaseline); 1883 1915 1884 1916 // calculate the intersection between this projected baseline and Base 1885 1917 Vector *Intersection = new Vector; 1886 1918 Intersection->GetIntersectionOfTwoLinesOnPlane(out, Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal); 1919 Normal.CopyVector(Intersection); 1920 Normal.SubtractVector(Base->endpoints[0]->node->node); 1921 *out << Verbose(3) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl; 1887 1922 1888 1923 return Intersection; … … 2012 2047 * \param *Candidate pointer to candidate node on return 2013 2048 * \param Oben vector indicating the outside 2014 * \param Opt Candidate reference to recommended candidate on return2049 * \param Opt_Candidate reference to recommended candidate on return 2015 2050 * \param Storage[3] array storing angles and other candidate information 2016 2051 * \param RADIUS radius of virtual sphere 2017 2052 * \param *LC LinkedCell structure with neighbouring points 2018 2053 */ 2019 void Tesselation::Find SecondPointForTesselation(TesselPoint* a, TesselPoint* Candidate, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, LinkedCell *LC)2020 { 2021 cout << Verbose(2) << "Begin of Find SecondPointForTesselation" << endl;2054 void Tesselation::Find_second_point_for_Tesselation(TesselPoint* a, TesselPoint* Candidate, Vector Oben, TesselPoint*& Opt_Candidate, double Storage[3], double RADIUS, LinkedCell *LC) 2055 { 2056 cout << Verbose(2) << "Begin of Find_second_point_for_Tesselation" << endl; 2022 2057 Vector AngleCheck; 2023 2058 double norm = -1., angle; … … 2057 2092 if (a != Candidate) { 2058 2093 // Calculate center of the circle with radius RADIUS through points a and Candidate 2059 Vector OrthogonalizedOben, a Candidate, Center;2094 Vector OrthogonalizedOben, a_Candidate, Center; 2060 2095 double distance, scaleFactor; 2061 2096 2062 2097 OrthogonalizedOben.CopyVector(&Oben); 2063 a Candidate.CopyVector(a->node);2064 a Candidate.SubtractVector(Candidate->node);2065 OrthogonalizedOben.ProjectOntoPlane(&a Candidate);2098 a_Candidate.CopyVector(a->node); 2099 a_Candidate.SubtractVector(Candidate->node); 2100 OrthogonalizedOben.ProjectOntoPlane(&a_Candidate); 2066 2101 OrthogonalizedOben.Normalize(); 2067 distance = 0.5 * a Candidate.Norm();2102 distance = 0.5 * a_Candidate.Norm(); 2068 2103 scaleFactor = sqrt(((RADIUS * RADIUS) - (distance * distance))); 2069 2104 OrthogonalizedOben.Scale(scaleFactor); … … 2076 2111 AngleCheck.CopyVector(&Center); 2077 2112 AngleCheck.SubtractVector(a->node); 2078 norm = a Candidate.Norm();2113 norm = a_Candidate.Norm(); 2079 2114 // second point shall have smallest angle with respect to Oben vector 2080 2115 if (norm < RADIUS*2.) { … … 2083 2118 //cout << Verbose(3) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]); 2084 2119 cout << Verbose(3) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n"; 2085 Opt Candidate = Candidate;2120 Opt_Candidate = Candidate; 2086 2121 Storage[0] = angle; 2087 2122 //cout << Verbose(3) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]); 2088 2123 } else { 2089 //cout << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *Opt Candidate << endl;2124 //cout << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *Opt_Candidate << endl; 2090 2125 } 2091 2126 } else { … … 2100 2135 } 2101 2136 } 2102 cout << Verbose(2) << "End of Find SecondPointForTesselation" << endl;2137 cout << Verbose(2) << "End of Find_second_point_for_Tesselation" << endl; 2103 2138 }; 2104 2139 … … 2126 2161 * holds. Then, the normalized projection onto the SearchDirection is either +1 or -1 and thus states whether 2127 2162 * the angle is uniquely in either (0,M_PI] or [M_PI, 2.*M_PI). 2128 * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa Find StartingTriangle())2163 * @param NormalVector normal direction of the base triangle (here the unit axis vector, \sa Find_starting_triangle()) 2129 2164 * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine 2130 2165 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle … … 2132 2167 * @param ThirdNode third point to avoid in search 2133 2168 * @param candidates list of equally good candidates to return 2134 * @param ShortestAngle the current path length on this circle band for the current Opt Candidate2169 * @param ShortestAngle the current path length on this circle band for the current Opt_Candidate 2135 2170 * @param RADIUS radius of sphere 2136 2171 * @param *LC LinkedCell structure with neighbouring points 2137 2172 */ 2138 void Tesselation::Find ThirdPointForTesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, LinkedCell *LC)2173 void Tesselation::Find_third_point_for_Tesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, LinkedCell *LC) 2139 2174 { 2140 2175 Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers … … 2153 2188 CandidateForTesselation *optCandidate = NULL; 2154 2189 2155 cout << Verbose(1) << "Begin of Find ThirdPointForTesselation" << endl;2190 cout << Verbose(1) << "Begin of Find_third_point_for_Tesselation" << endl; 2156 2191 2157 2192 //cout << Verbose(2) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl; … … 2310 2345 if (candidates->size() > 1) { 2311 2346 candidates->unique(); 2312 candidates->sort( SortCandidates);2313 } 2314 2315 cout << Verbose(1) << "End of Find ThirdPointForTesselation" << endl;2347 candidates->sort(sortCandidates); 2348 } 2349 2350 cout << Verbose(1) << "End of Find_third_point_for_Tesselation" << endl; 2316 2351 }; 2317 2352 … … 2362 2397 } 2363 2398 2364 trianglePoints[0] = FindClosestPoint(x, SecondPoint, LC);2399 trianglePoints[0] = findClosestPoint(x, SecondPoint, LC); 2365 2400 2366 2401 // check whether closest point is "too close" :), then it's inside … … 2373 2408 return NULL; 2374 2409 } 2375 list<TesselPoint*> *connectedPoints = GetCircleOfConnectedPoints(out, trianglePoints[0]);2376 list<TesselPoint*> *connectedClosestPoints = GetNeighboursOnCircleOfConnectedPoints(out, connectedPoints, trianglePoints[0], x);2410 list<TesselPoint*> *connectedPoints = getCircleOfConnectedPoints(out, trianglePoints[0]); 2411 list<TesselPoint*> *connectedClosestPoints = getNeighboursonCircleofConnectedPoints(out, connectedPoints, trianglePoints[0], x); 2377 2412 delete(connectedPoints); 2378 2413 trianglePoints[1] = connectedClosestPoints->front(); … … 2462 2497 * @return list of the all points linked to the provided one 2463 2498 */ 2464 list<TesselPoint*> * Tesselation:: GetCircleOfConnectedPoints(ofstream *out, TesselPoint* Point)2499 list<TesselPoint*> * Tesselation::getCircleOfConnectedPoints(ofstream *out, TesselPoint* Point) 2465 2500 { 2466 2501 list<TesselPoint*> *connectedPoints = new list<TesselPoint*>; … … 2523 2558 * @return list of the two points linked to the provided one and closest to the point to be checked, 2524 2559 */ 2525 list<TesselPoint*> * Tesselation:: GetNeighboursOnCircleOfConnectedPoints(ofstream *out, list<TesselPoint*> *connectedPoints, TesselPoint* Point, Vector* Reference)2560 list<TesselPoint*> * Tesselation::getNeighboursonCircleofConnectedPoints(ofstream *out, list<TesselPoint*> *connectedPoints, TesselPoint* Point, Vector* Reference) 2526 2561 { 2527 2562 map<double, TesselPoint*> anglesOfPoints; … … 2562 2597 helper.SubtractVector(Point->node); 2563 2598 helper.ProjectOntoPlane(&PlaneNormal); 2564 double angle = GetAngle(helper, AngleZero, OrthogonalVector);2599 double angle = getAngle(helper, AngleZero, OrthogonalVector); 2565 2600 *out << Verbose(2) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl; 2566 2601 anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner))); … … 2595 2630 int i; 2596 2631 2632 if (point == NULL) { 2633 *out << Verbose(1) << "ERROR: Cannot remove the point " << point << ", it's NULL!" << endl; 2634 return 0.; 2635 } else 2636 *out << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl; 2637 2597 2638 // copy old location for the volume 2598 2639 OldPoint.CopyVector(point->node->node); … … 2603 2644 return 0.; 2604 2645 } 2605 list<TesselPoint*> *CircleofPoints = GetCircleOfConnectedPoints(out, point->node);2646 list<TesselPoint*> *CircleofPoints = getCircleOfConnectedPoints(out, point->node); 2606 2647 2607 2648 // remove all triangles … … 2609 2650 count+=LineRunner->second->triangles.size(); 2610 2651 numbers = new int[count]; 2652 class BoundaryTriangleSet **Candidates = new BoundaryTriangleSet*[count]; 2611 2653 i=0; 2612 2654 for (LineMap::iterator LineRunner = point->lines.begin(); (point != NULL) && (LineRunner != point->lines.end()); LineRunner++) { … … 2614 2656 for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) { 2615 2657 triangle = TriangleRunner->second; 2616 *out << Verbose(2) << "Erasing triangle " << *triangle << "." << endl;2658 Candidates[i] = triangle; 2617 2659 numbers[i++] = triangle->Nr; 2618 RemoveTesselationTriangle(triangle); 2619 triangle = NULL; 2620 } 2621 } 2660 } 2661 } 2662 for (int j=0;j<i;j++) { 2663 RemoveTesselationTriangle(Candidates[j]); 2664 } 2665 delete[](Candidates); 2622 2666 *out << Verbose(1) << i << " triangles were removed." << endl; 2623 2667 … … 2672 2716 * \return true - there is such a line (i.e. creation of degenerated triangle is valid), false - no such line (don't create) 2673 2717 */ 2674 bool CheckLineCriteria ForDegeneratedTriangle(class BoundaryPointSet *nodes[3])2718 bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3]) 2675 2719 { 2676 2720 bool result = false; … … 2706 2750 /** Sort function for the candidate list. 2707 2751 */ 2708 bool SortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2)2752 bool sortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2) 2709 2753 { 2710 2754 Vector BaseLineVector, OrthogonalVector, helper; … … 2756 2800 * @return point which is second closest to the provided one 2757 2801 */ 2758 TesselPoint* FindSecondClosestPoint(const Vector* Point, LinkedCell* LC)2802 TesselPoint* findSecondClosestPoint(const Vector* Point, LinkedCell* LC) 2759 2803 { 2760 2804 LinkedNodes *List = NULL; … … 2802 2846 }; 2803 2847 2848 2849 2804 2850 /** 2805 2851 * Finds the point which is closest to the provided one. … … 2811 2857 * @return point which is closest to the provided one, NULL if none found 2812 2858 */ 2813 TesselPoint* FindClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC)2859 TesselPoint* findClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, LinkedCell* LC) 2814 2860 { 2815 2861 LinkedNodes *List = NULL; … … 2858 2904 return closestPoint; 2859 2905 }; 2906 2860 2907 2861 2908 /** … … 2924 2971 } 2925 2972 2926 /**2927 * Finds all degenerated triangles within the tesselation structure.2928 *2929 * @return map of keys of degenerated triangle pairs, each triangle occurs twice2930 * in the list, once as key and once as value2931 */2932 map<int, int> Tesselation::FindAllDegeneratedTriangles()2933 {2934 map<int, int> DegeneratedTriangles;2935 2936 // sanity check2937 if (LinesOnBoundary.empty()) {2938 cout << Verbose(1) << "Warning: FindAllDegeneratedTriangles() was called without any tesselation structure.";2939 return DegeneratedTriangles;2940 }2941 2942 LineMap::iterator LineRunner1, LineRunner2;2943 2944 for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {2945 for (LineRunner2 = LinesOnBoundary.begin(); LineRunner2 != LinesOnBoundary.end(); ++LineRunner2) {2946 if ((LineRunner1->second != LineRunner2->second)2947 && (LineRunner1->second->endpoints[0] == LineRunner2->second->endpoints[0])2948 && (LineRunner1->second->endpoints[1] == LineRunner2->second->endpoints[1])2949 ) {2950 TriangleMap::iterator TriangleRunner1 = LineRunner1->second->triangles.begin(),2951 TriangleRunner2 = LineRunner2->second->triangles.begin();2952 2953 for (; TriangleRunner1 != LineRunner1->second->triangles.end(); ++TriangleRunner1) {2954 for (; TriangleRunner2 != LineRunner2->second->triangles.end(); ++TriangleRunner2) {2955 if ((TriangleRunner1->second != TriangleRunner2->second)2956 && (TriangleRunner1->second->endpoints[0] == TriangleRunner2->second->endpoints[0])2957 && (TriangleRunner1->second->endpoints[1] == TriangleRunner2->second->endpoints[1])2958 && (TriangleRunner1->second->endpoints[2] == TriangleRunner2->second->endpoints[2])2959 ) {2960 DegeneratedTriangles[TriangleRunner1->second->Nr] = TriangleRunner2->second->Nr;2961 DegeneratedTriangles[TriangleRunner2->second->Nr] = TriangleRunner1->second->Nr;2962 }2963 }2964 }2965 }2966 }2967 }2968 2969 cout << Verbose(1) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles.size() << " triangles." << endl;2970 map<int,int>::iterator it;2971 for (it = DegeneratedTriangles.begin(); it != DegeneratedTriangles.end(); it++)2972 cout << Verbose(2) << (*it).first << " => " << (*it).second << endl;2973 2974 return DegeneratedTriangles;2975 }2976 2977 /**2978 * Purges degenerated triangles from the tesselation structure if they are not2979 * necessary to keep a single point within the structure.2980 */2981 void Tesselation::RemoveDegeneratedTriangles()2982 {2983 map<int, int> DegeneratedTriangles = FindAllDegeneratedTriangles();2984 2985 for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles.begin();2986 TriangleKeyRunner != DegeneratedTriangles.end(); ++TriangleKeyRunner2987 ) {2988 BoundaryTriangleSet *triangle = TrianglesOnBoundary.find(TriangleKeyRunner->first)->second,2989 *partnerTriangle = TrianglesOnBoundary.find(TriangleKeyRunner->second)->second;2990 2991 bool trianglesShareLine = false;2992 for (int i = 0; i < 3; ++i)2993 for (int j = 0; j < 3; ++j)2994 trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];2995 2996 if (trianglesShareLine2997 && (triangle->endpoints[1]->LinesCount > 2)2998 && (triangle->endpoints[2]->LinesCount > 2)2999 && (triangle->endpoints[0]->LinesCount > 2)3000 ) {3001 cout << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;3002 RemoveTesselationTriangle(triangle);3003 cout << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;3004 RemoveTesselationTriangle(partnerTriangle);3005 DegeneratedTriangles.erase(DegeneratedTriangles.find(partnerTriangle->Nr));3006 } else {3007 cout << Verbose(1) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle3008 << " and its partner " << *partnerTriangle << " because it is essential for at"3009 << " least one of the endpoints to be kept in the tesselation structure." << endl;3010 }3011 }3012 }3013 3014 2973 /** Gets the angle between a point and a reference relative to the provided center. 3015 2974 * We have two shanks point and reference between which the angle is calculated … … 3021 2980 * @return angle between point and reference 3022 2981 */ 3023 double GetAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector)3024 { 3025 if (reference.Is Null())2982 double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector) 2983 { 2984 if (reference.IsZero()) 3026 2985 return M_PI; 3027 2986 3028 2987 // calculate both angles and correct with in-plane vector 3029 if (point.Is Null())2988 if (point.IsZero()) 3030 2989 return M_PI; 3031 2990 double phi = point.Angle(&reference);
Note:
See TracChangeset
for help on using the changeset viewer.
