Changes in src/tesselation.cpp [b32dbb:27ac00]
- File:
-
- 1 edited
-
src/tesselation.cpp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tesselation.cpp
rb32dbb r27ac00 17 17 #include "triangleintersectionlist.hpp" 18 18 #include "vector.hpp" 19 #include "Line.hpp" 19 20 #include "vector_ops.hpp" 20 21 #include "verbose.hpp" … … 229 230 { 230 231 Info FunctionInfo(__func__); 231 double angle = CalculateConvexity();232 if (angle > -MYEPSILON) {233 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);234 return true;235 } else {236 DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);237 return false;238 }239 }240 241 242 /** Calculates the angle between two triangles with respect to their normal vector.243 * We sum the two angles of each height vector with respect to the center of the baseline.244 * \return angle > 0 then convex, if < 0 then concave245 */246 double BoundaryLineSet::CalculateConvexity() const247 {248 Info FunctionInfo(__func__);249 232 Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck; 250 233 // get the two triangles … … 295 278 BaseLineNormal.Scale(-1.); 296 279 double angle = GetAngle(helper[0], helper[1], BaseLineNormal); 297 return (angle - M_PI); 280 if ((angle - M_PI) > -MYEPSILON) { 281 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl); 282 return true; 283 } else { 284 DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl); 285 return false; 286 } 298 287 } 299 288 … … 314 303 /** Returns other endpoint of the line. 315 304 * \param *point other endpoint 316 * \return NULL - if endpoint not contained in BoundaryLineSet ::lines, or pointer to BoundaryPointSet otherwise305 * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise 317 306 */ 318 307 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const … … 325 314 else 326 315 return NULL; 327 }328 ;329 330 /** Returns other triangle of the line.331 * \param *point other endpoint332 * \return NULL - if triangle not contained in BoundaryLineSet::triangles, or pointer to BoundaryTriangleSet otherwise333 */334 class BoundaryTriangleSet *BoundaryLineSet::GetOtherTriangle(const BoundaryTriangleSet * const triangle) const335 {336 Info FunctionInfo(__func__);337 if (triangles.size() == 2) {338 for (TriangleMap::const_iterator TriangleRunner = triangles.begin(); TriangleRunner != triangles.end(); ++TriangleRunner)339 if (TriangleRunner->second != triangle)340 return TriangleRunner->second;341 }342 return NULL;343 316 } 344 317 ; … … 469 442 470 443 try { 471 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x); 472 } 473 catch (LinearDependenceException &excp) { 474 Log() << Verbose(1) << excp; 475 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 476 return false; 477 } 478 479 DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl); 480 DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl); 481 DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl); 482 483 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 484 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl); 485 return true; 486 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 487 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl); 488 return true; 489 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 490 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl); 491 return true; 492 } 493 // Calculate cross point between one baseline and the line from the third endpoint to intersection 494 int i = 0; 495 do { 496 try { 497 CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node), 498 *(endpoints[(i+1)%3]->node->node), 499 *(endpoints[(i+2)%3]->node->node), 500 *Intersection); 444 Line centerLine = makeLineThrough(*MolCenter, *x); 445 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(centerLine); 446 447 DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl); 448 DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl); 449 DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl); 450 451 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 452 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl); 453 return true; 454 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 455 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl); 456 return true; 457 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 458 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl); 459 return true; 460 } 461 // Calculate cross point between one baseline and the line from the third endpoint to intersection 462 int i = 0; 463 do { 464 Line line1 = makeLineThrough(*(endpoints[i%3]->node->node),*(endpoints[(i+1)%3]->node->node)); 465 Line line2 = makeLineThrough(*(endpoints[(i+2)%3]->node->node),*Intersection); 466 CrossPoint = line1.getIntersection(line2); 501 467 helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 502 468 CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector … … 505 471 if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) { 506 472 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl); 507 i=4; 508 break; 473 return false; 509 474 } 510 475 i++; 511 } catch (LinearDependenceException &excp){ 512 break; 513 } 514 } while (i < 3); 515 if (i == 3) { 476 } while (i < 3); 516 477 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl); 517 478 return true; 518 } else { 519 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl); 479 } 480 catch (MathException &excp) { 481 Log() << Verbose(1) << excp; 482 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 520 483 return false; 521 484 } … … 544 507 GetCenter(&Direction); 545 508 try { 546 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction); 547 } 548 catch (LinearDependenceException &excp) { 509 Line l = makeLineThrough(*x, Direction); 510 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(l); 511 } 512 catch (MathException &excp) { 549 513 (*ClosestPoint) = (*x); 550 514 } … … 569 533 Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 570 534 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 571 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 535 Line l = makeLineThrough(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 536 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(l); 572 537 CrossDirection[i] = CrossPoint[i] - InPlane; 573 538 CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector … … 697 662 ; 698 663 699 /** Returns the baseline which does not contain the given boundary point \a *point.700 * \param *point endpoint which is neither endpoint of the desired line701 * \return pointer to desired third baseline702 */703 class BoundaryLineSet *BoundaryTriangleSet::GetThirdLine(const BoundaryPointSet * const point) const704 {705 Info FunctionInfo(__func__);706 // sanity check707 if (!ContainsBoundaryPoint(point))708 return NULL;709 for (int i = 0; i < 3; i++)710 if (!lines[i]->ContainsBoundaryPoint(point))711 return lines[i];712 // actually, that' impossible :)713 return NULL;714 }715 ;716 717 664 /** Calculates the center point of the triangle. 718 665 * Is third of the sum of all endpoints. … … 740 687 } 741 688 689 Vector BoundaryTriangleSet::getEndpoint(int i) const{ 690 ASSERT(i>=0 && i<3,"Index of Endpoint out of Range"); 691 692 return *endpoints[i]->node->node; 693 } 694 695 string BoundaryTriangleSet::getEndpointName(int i) const{ 696 ASSERT(i>=0 && i<3,"Index of Endpoint out of Range"); 697 698 return endpoints[i]->node->getName(); 699 } 700 742 701 /** output operator for BoundaryTriangleSet. 743 702 * \param &ost output stream … … 746 705 ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a) 747 706 { 748 ost << "[" << a.Nr << "|" << a. endpoints[0]->node->getName() << "," << a.endpoints[1]->node->getName() << "," << a.endpoints[2]->node->getName() << "]";707 ost << "[" << a.Nr << "|" << a.getEndpointName(0) << "," << a.getEndpointName(1) << "," << a.getEndpointName(2) << "]"; 749 708 // ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," 750 709 // << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]"; … … 1152 1111 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner)); 1153 1112 1154 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << (*VRunner)<< ":" << endl);1113 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl); 1155 1114 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 1156 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance( *(*VRunner)) << "." << endl);1115 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->distance(OtherOptCenter) << "." << endl); 1157 1116 1158 1117 // remove baseline's endpoints and candidates … … 1170 1129 DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl); 1171 1130 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 1172 DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << " at distance " << setprecision(13) << (*Runner)->node->distance(*(*VRunner)) << setprecision(6) << "." << endl); 1173 1174 // check with animate_sphere.tcl VMD script 1175 if (ThirdPoint != NULL) { 1176 DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl); 1177 } else { 1178 DoeLog(1) && (eLog() << Verbose(1) << "Check by: ... missing third point ..." << endl); 1179 DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl); 1180 } 1131 DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << endl); 1181 1132 } 1182 1133 delete (ListofPoints); 1183 1134 1135 // check with animate_sphere.tcl VMD script 1136 if (ThirdPoint != NULL) { 1137 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl); 1138 } else { 1139 DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl); 1140 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl); 1141 } 1184 1142 } 1185 1143 return flag; … … 1514 1472 CenterVector.Zero(); 1515 1473 for (int i = 0; i < 3; i++) 1516 CenterVector += (*BTS->endpoints[i]->node->node);1474 CenterVector += BTS->getEndpoint(i); 1517 1475 CenterVector.Scale(1. / 3.); 1518 1476 DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl); … … 3360 3318 } 3361 3319 } else { 3362 Do eLog(0) && (eLog() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);3320 DoLog(1) && (Log() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl); 3363 3321 } 3364 3322 } else { … … 4660 4618 4661 4619 DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl); 4662 for (IndexToIndex::iterator it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++) 4620 IndexToIndex::iterator it; 4621 for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++) 4663 4622 DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl); 4664 4623 … … 4678 4637 int count = 0; 4679 4638 4680 // iterate over all degenerated triangles 4681 for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); !DegeneratedTriangles->empty(); TriangleKeyRunner = DegeneratedTriangles->begin()) { 4682 DoLog(0) && (Log() << Verbose(0) << "Checking presence of triangles " << TriangleKeyRunner->first << " and " << TriangleKeyRunner->second << "." << endl); 4683 // both ways are stored in the map, only use one 4684 if (TriangleKeyRunner->first > TriangleKeyRunner->second) 4685 continue; 4686 4687 // determine from the keys in the map the two _present_ triangles 4639 for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) { 4688 4640 finder = TrianglesOnBoundary.find(TriangleKeyRunner->first); 4689 4641 if (finder != TrianglesOnBoundary.end()) 4690 4642 triangle = finder->second; 4691 4643 else 4692 continue;4644 break; 4693 4645 finder = TrianglesOnBoundary.find(TriangleKeyRunner->second); 4694 4646 if (finder != TrianglesOnBoundary.end()) 4695 4647 partnerTriangle = finder->second; 4696 4648 else 4697 continue; 4698 4699 // determine which lines are shared by the two triangles 4649 break; 4650 4700 4651 bool trianglesShareLine = false; 4701 4652 for (int i = 0; i < 3; ++i) … … 4868 4819 if (LastTriangle != NULL) { 4869 4820 stringstream sstr; 4870 sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle-> endpoints[0]->node->getName() << "_" << LastTriangle->endpoints[1]->node->getName() << "_" << LastTriangle->endpoints[2]->node->getName();4821 sstr << "-"<< TrianglesOnBoundary.size() << "-" << LastTriangle->getEndpointName(0) << "_" << LastTriangle->getEndpointName(1) << "_" << LastTriangle->getEndpointName(2); 4871 4822 NumberName = sstr.str(); 4872 4823 if (DoTecplotOutput) {
Note:
See TracChangeset
for help on using the changeset viewer.
