Changeset 27459a for molecuilder/src/tesselation.cpp
- Timestamp:
- Aug 18, 2009, 8:42:39 AM (16 years ago)
- Children:
- daf5d6
- Parents:
- 3de1d2
- File:
-
- 1 edited
-
molecuilder/src/tesselation.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/tesselation.cpp
r3de1d2 r27459a 1751 1751 class BoundaryPointSet *Spot = NULL; 1752 1752 class BoundaryLineSet *OtherBase; 1753 Vector *ClosestPoint [2];1753 Vector *ClosestPoint; 1754 1754 1755 1755 int m=0; … … 1764 1764 1765 1765 // 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); 1766 ClosestPoint = GetClosestPointBetweenLine(out, Base, OtherBase); 1768 1767 1769 1768 // delete the temporary other base line 1769 delete(ClosestPoint); 1770 1770 delete(OtherBase); 1771 1771 1772 1772 // get the distance vector from Base line to OtherBase line 1773 Vector DistanceToIntersection, BaseLine; 1773 Vector DistanceToIntersection[2], BaseLine; 1774 double distance[2]; 1774 1775 BaseLine.CopyVector(Base->endpoints[1]->node->node); 1775 1776 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; 1777 for (int i=0;i<2;i++) { 1778 DistanceToIntersection[i].CopyVector(ClosestPoint); 1779 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 1780 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 1781 } 1782 if ((distance[0] * distance[1]) > MYEPSILON) { // have same sign? 1783 *out << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << " is concave." << endl; 1784 if (distance[0] < distance[1]) { 1785 Spot = Base->endpoints[0]; 1786 } else { 1787 Spot = Base->endpoints[1]; 1788 } 1790 1789 return Spot; 1791 } else { // base line is longer: convex1792 *out << Verbose(3) << " INFO: Rectangle of triangles of base line " << *Base << " is concave." << endl;1790 } else { // different sign, i.e. we are in between 1791 *out << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl; 1793 1792 return NULL; 1794 1793 } … … 1796 1795 }; 1797 1796 1797 void Tesselation::PrintAllBoundaryPoints(ofstream *out) 1798 { 1799 // print all lines 1800 *out << Verbose(1) << "Printing all boundary points for debugging:" << endl; 1801 for (PointMap::iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++) 1802 *out << Verbose(2) << *(PointRunner->second) << endl; 1803 }; 1804 1805 void Tesselation::PrintAllBoundaryLines(ofstream *out) 1806 { 1807 // print all lines 1808 *out << Verbose(1) << "Printing all boundary lines for debugging:" << endl; 1809 for (LineMap::iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) 1810 *out << Verbose(2) << *(LineRunner->second) << endl; 1811 }; 1812 1813 void Tesselation::PrintAllBoundaryTriangles(ofstream *out) 1814 { 1815 // print all triangles 1816 *out << Verbose(1) << "Printing all boundary triangles for debugging:" << endl; 1817 for (TriangleMap::iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++) 1818 *out << Verbose(2) << *(TriangleRunner->second) << endl; 1819 }; 1798 1820 1799 1821 /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher". … … 1826 1848 Distance.SubtractVector(ClosestPoint[0]); 1827 1849 1828 // delete the temporary other base line 1850 // delete the temporary other base line and the closest points 1851 delete(ClosestPoint[0]); 1852 delete(ClosestPoint[1]); 1829 1853 delete(OtherBase); 1830 1854 … … 1843 1867 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 1844 1868 } 1845 BaseLineNormal.Scale( -1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()1869 BaseLineNormal.Scale(1./2.); 1846 1870 1847 1871 if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip … … 1866 1890 // construct the plane of the two baselines (i.e. take both their directional vectors) 1867 1891 Vector Normal; 1868 Vector OtherBaseline;1869 Normal.CopyVector(Base->endpoints[1]->node->node);1870 Normal.SubtractVector(Base->endpoints[0]->node->node);1892 Vector Baseline, OtherBaseline; 1893 Baseline.CopyVector(Base->endpoints[1]->node->node); 1894 Baseline.SubtractVector(Base->endpoints[0]->node->node); 1871 1895 OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node); 1872 1896 OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node); 1897 Normal.CopyVector(&Baseline); 1873 1898 Normal.VectorProduct(&OtherBaseline); 1874 1899 Normal.Normalize(); 1875 1876 // project one offset point of OtherBase onto this plane 1900 *out << Verbose(4) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl; 1901 1902 // project one offset point of OtherBase onto this plane (and add plane offset vector) 1877 1903 Vector NewOffset; 1878 1904 NewOffset.CopyVector(OtherBase->endpoints[0]->node->node); 1879 1905 NewOffset.ProjectOntoPlane(&Normal); 1880 Vector NewDirection; 1881 NewDirection.CopyVector(OtherBase->endpoints[1]->node->node); 1882 NewDirection.ProjectOntoPlane(&Normal); 1906 NewOffset.AddVector(Base->endpoints[0]->node->node); 1883 1907 1884 1908 // calculate the intersection between this projected baseline and Base 1885 1909 Vector *Intersection = new Vector; 1886 Intersection->GetIntersectionOfTwoLinesOnPlane(out, Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal); 1910 Intersection->GetIntersectionOfTwoLinesOnPlane(out, Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &OtherBaseline, &Normal); 1911 Normal.CopyVector(Intersection); 1912 Normal.SubtractVector(Base->endpoints[0]->node->node); 1913 *out << Verbose(3) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl; 1887 1914 1888 1915 return Intersection; … … 2938 2965 double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector) 2939 2966 { 2940 if (reference.Is Null())2967 if (reference.IsZero()) 2941 2968 return M_PI; 2942 2969 2943 2970 // calculate both angles and correct with in-plane vector 2944 if (point.Is Null())2971 if (point.IsZero()) 2945 2972 return M_PI; 2946 2973 double phi = point.Angle(&reference);
Note:
See TracChangeset
for help on using the changeset viewer.
