Changes in src/tesselationhelpers.cpp [643e76:b32dbb]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tesselationhelpers.cpp
r643e76 rb32dbb 10 10 #include "info.hpp" 11 11 #include "linkedcell.hpp" 12 #include "linearsystemofequations.hpp" 12 13 #include "log.hpp" 13 14 #include "tesselation.hpp" 14 15 #include "tesselationhelpers.hpp" 15 16 #include "vector.hpp" 16 #include "Line.hpp"17 17 #include "vector_ops.hpp" 18 18 #include "verbose.hpp" … … 183 183 beta = M_PI - SideC.Angle(SideA); 184 184 gamma = M_PI - SideA.Angle(SideB); 185 //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;185 Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl; 186 186 if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) { 187 187 DoeLog(2) && (eLog()<< Verbose(2) << "GetCenterofCircumcircle: Sum of angles " << (alpha+beta+gamma)/M_PI*180. << " > 180 degrees by " << fabs(M_PI - alpha - beta - gamma)/M_PI*180. << "!" << endl); … … 196 196 (*Center) += helper; 197 197 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma))); 198 Log() << Verbose(1) << "INFO: Center (1st algo) is at " << *Center << "." << endl; 199 200 // LinearSystemOfEquations LSofEq(NDIM,NDIM); 201 // double *matrix = new double[NDIM*NDIM]; 202 // matrix[0] = 0.; 203 // matrix[1] = a.DistanceSquared(b); 204 // matrix[2] = a.DistanceSquared(c); 205 // matrix[3] = a.DistanceSquared(b); 206 // matrix[4] = 0.; 207 // matrix[5] = b.DistanceSquared(c); 208 // matrix[6] = a.DistanceSquared(c); 209 // matrix[7] = b.DistanceSquared(c); 210 // matrix[8] = 0.; 211 // cout << "Matrix is: "; 212 // for (int i=0;i<NDIM*NDIM;i++) 213 // cout << matrix[i] << "\t"; 214 // cout << endl; 215 // LSofEq.SetA(matrix); 216 // delete[](matrix); 217 // LSofEq.Setb(new Vector(1.,1.,1.)); 218 // LSofEq.SetSymmetric(true); 219 // helper.Zero(); 220 // if (!LSofEq.GetSolutionAsVector(helper)) { 221 // DoLog(0) && (eLog()<< Verbose(0) << "Could not solve the linear system in GetCenterofCircumCircle()!" << endl); 222 // } 223 // cout << "Solution is " << helper << endl; 224 // is equivalent to the three lines below 225 helper[0] = SideA.NormSquared()*(SideB.NormSquared()+SideC.NormSquared() - SideA.NormSquared()); 226 helper[1] = SideB.NormSquared()*(SideC.NormSquared()+SideA.NormSquared() - SideB.NormSquared()); 227 helper[2] = SideC.NormSquared()*(SideA.NormSquared()+SideB.NormSquared() - SideC.NormSquared()); 228 229 Center->Zero(); 230 *Center += helper[0] * a; 231 *Center += helper[1] * b; 232 *Center += helper[2] * c; 233 Center->Scale(1./(helper[0]+helper[1]+helper[2])); 234 Log() << Verbose(1) << "INFO: Center (2nd algo) is at " << *Center << "." << endl; 198 235 }; 199 236 … … 417 454 /** Calculates the volume of a general tetraeder. 418 455 * \param *a first vector 419 * \param * a firstvector420 * \param * a firstvector421 * \param * a firstvector456 * \param *b second vector 457 * \param *c third vector 458 * \param *d fourth vector 422 459 * \return \f$ \frac{1}{6} \cdot ((a-d) \times (a-c) \cdot (a-b)) \f$ 423 460 */ … … 437 474 volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2])); 438 475 return volume; 476 }; 477 478 /** Calculates the area of a general triangle. 479 * We use the Heron's formula of area, [Bronstein, S. 138] 480 * \param &A first vector 481 * \param &B second vector 482 * \param &C third vector 483 * \return \f$ \frac{1}{6} \cdot ((a-d) \times (a-c) \cdot (a-b)) \f$ 484 */ 485 double CalculateAreaofGeneralTriangle(const Vector &A, const Vector &B, const Vector &C) 486 { 487 Info FunctionInfo(__func__); 488 489 const double sidea = B.distance(C); 490 const double sideb = A.distance(C); 491 const double sidec = A.distance(B); 492 const double s = (sidea+sideb+sidec)/2.; 493 494 const double area = sqrt(s*(s-sidea)*(s-sideb)*(s-sidec)); 495 return area; 439 496 }; 440 497 … … 667 724 // calculate the intersection between this projected baseline and Base 668 725 Vector *Intersection = new Vector; 669 Line line1 = makeLineThrough(*(Base->endpoints[0]->node->node),*(Base->endpoints[1]->node->node));670 Line line2 = makeLineThrough(NewOffset, NewDirection);671 *Intersection = line1.getIntersection(line2);726 *Intersection = GetIntersectionOfTwoLinesOnPlane(*(Base->endpoints[0]->node->node), 727 *(Base->endpoints[1]->node->node), 728 NewOffset, NewDirection); 672 729 Normal = (*Intersection) - (*Base->endpoints[0]->node->node); 673 730 DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(Baseline)/Baseline.NormSquared()) << "." << endl); … … 871 928 class BoundaryPointSet *point = NULL; 872 929 class BoundaryLineSet *line = NULL; 873 874 // calculate remaining concavity 930 class BoundaryTriangleSet *triangle = NULL; 931 double ConcavityPerLine = 0.; 932 double ConcavityPerTriangle = 0.; 933 double area = 0.; 934 double totalarea = 0.; 935 875 936 for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { 876 937 point = PointRunner->second; 877 938 DoLog(1) && (Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl); 878 point->value = 0; 939 940 // calculate mean concavity over all connected line 941 ConcavityPerLine = 0.; 879 942 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 880 943 line = LineRunner->second; 881 944 //Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 882 if (!line->CheckConvexityCriterion()) 883 point->value += 1; 884 } 885 } 886 }; 887 945 ConcavityPerLine -= line->CalculateConvexity(); 946 } 947 ConcavityPerLine /= point->lines.size(); 948 949 // weigh with total area of the surrounding triangles 950 totalarea = 0.; 951 TriangleSet *triangles = TesselStruct->GetAllTriangles(PointRunner->second); 952 for (TriangleSet::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); ++TriangleRunner) { 953 totalarea += CalculateAreaofGeneralTriangle(*(*TriangleRunner)->endpoints[0]->node->node, *(*TriangleRunner)->endpoints[1]->node->node, *(*TriangleRunner)->endpoints[2]->node->node); 954 } 955 ConcavityPerLine *= totalarea; 956 957 // calculate mean concavity over all attached triangles 958 ConcavityPerTriangle = 0.; 959 for (TriangleSet::const_iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); ++TriangleRunner) { 960 line = (*TriangleRunner)->GetThirdLine(PointRunner->second); 961 triangle = line->GetOtherTriangle(*TriangleRunner); 962 area = CalculateAreaofGeneralTriangle(*triangle->endpoints[0]->node->node, *triangle->endpoints[1]->node->node, *triangle->endpoints[2]->node->node); 963 area += CalculateAreaofGeneralTriangle(*(*TriangleRunner)->endpoints[0]->node->node, *(*TriangleRunner)->endpoints[1]->node->node, *(*TriangleRunner)->endpoints[2]->node->node); 964 area *= -line->CalculateConvexity(); 965 if (area > 0) 966 ConcavityPerTriangle += area; 967 // else 968 // ConcavityPerTriangle -= area; 969 } 970 ConcavityPerTriangle /= triangles->size()/totalarea; 971 delete(triangles); 972 973 // add up 974 point->value = ConcavityPerLine + ConcavityPerTriangle; 975 } 976 }; 977 978 979 980 /** Calculates the concavity for each of the BoundaryPointSet's in a Tesselation. 981 * Sets BoundaryPointSet::value equal to the nearest distance to convex envelope. 982 * \param *out output stream for debugging 983 * \param *TesselStruct pointer to Tesselation structure 984 * \param *Convex pointer to convex Tesselation structure as reference 985 */ 986 void CalculateConstrictionPerBoundaryPoint(const Tesselation * const TesselStruct, const Tesselation * const Convex) 987 { 988 Info FunctionInfo(__func__); 989 double distance = 0.; 990 991 for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { 992 DoeLog(1) && (eLog() << Verbose(1) << "INFO: Current point is " << * PointRunner->second << "." << endl); 993 994 distance = 0.; 995 for (TriangleMap::const_iterator TriangleRunner = Convex->TrianglesOnBoundary.begin(); TriangleRunner != Convex->TrianglesOnBoundary.end(); TriangleRunner++) { 996 const double CurrentDistance = Convex->GetDistanceSquaredToTriangle(*PointRunner->second->node->node, TriangleRunner->second); 997 if (CurrentDistance < distance) 998 distance = CurrentDistance; 999 } 1000 1001 PointRunner->second->value = distance; 1002 } 1003 }; 888 1004 889 1005 /** Checks whether each BoundaryLineSet in the Tesselation has two triangles.
Note:
See TracChangeset
for help on using the changeset viewer.