Changeset 0d111b for molecuilder/src/tesselation.cpp
- Timestamp:
- Apr 29, 2010, 1:55:21 PM (16 years ago)
- Children:
- 070651, 5d1a94
- Parents:
- 90c4460 (diff), 32842d8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
molecuilder/src/tesselation.cpp (modified) (81 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/tesselation.cpp
r90c4460 r0d111b 17 17 #include "triangleintersectionlist.hpp" 18 18 #include "vector.hpp" 19 #include "vector_ops.hpp" 19 20 #include "verbose.hpp" 21 #include "Plane.hpp" 22 #include "Exceptions/LinearDependenceException.hpp" 20 23 21 24 class molecule; … … 234 237 // have a normal vector on the base line pointing outwards 235 238 //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl; 236 BaseLineCenter.CopyVector(endpoints[0]->node->node); 237 BaseLineCenter.AddVector(endpoints[1]->node->node); 238 BaseLineCenter.Scale(1. / 2.); 239 BaseLine.CopyVector(endpoints[0]->node->node); 240 BaseLine.SubtractVector(endpoints[1]->node->node); 239 BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node)); 240 BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node); 241 241 242 //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl; 242 243 … … 248 249 for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 249 250 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 250 NormalCheck .AddVector(&runner->second->NormalVector);251 NormalCheck .Scale(sign);251 NormalCheck += runner->second->NormalVector; 252 NormalCheck *= sign; 252 253 sign = -sign; 253 254 if (runner->second->NormalVector.NormSquared() > MYEPSILON) 254 BaseLineNormal .CopyVector(&runner->second->NormalVector);// yes, copy second on top of first255 BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first 255 256 else { 256 257 DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl); … … 259 260 if (node != NULL) { 260 261 //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl; 261 helper[i].CopyVector(node->node->node); 262 helper[i].SubtractVector(&BaseLineCenter); 263 helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles! 262 helper[i] = (*node->node->node) - BaseLineCenter; 263 helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles! 264 264 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 265 265 i++; … … 409 409 Info FunctionInfo(__func__); 410 410 // get normal vector 411 NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node); 411 NormalVector = Plane(*(endpoints[0]->node->node), 412 *(endpoints[1]->node->node), 413 *(endpoints[2]->node->node)).getNormal(); 412 414 413 415 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 414 if (NormalVector.ScalarProduct( &OtherVector) > 0.)416 if (NormalVector.ScalarProduct(OtherVector) > 0.) 415 417 NormalVector.Scale(-1.); 416 418 DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl); … … 430 432 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle. 431 433 */ 434 432 435 bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const 433 436 { … … 436 439 Vector helper; 437 440 438 if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) { 441 try { 442 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x); 443 } 444 catch (LinearDependenceException &excp) { 445 Log() << Verbose(1) << excp; 439 446 DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl); 440 447 return false; … … 445 452 DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl); 446 453 447 if (Intersection->DistanceSquared( endpoints[0]->node->node) < MYEPSILON) {454 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 448 455 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl); 449 456 return true; 450 } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {457 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 451 458 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl); 452 459 return true; 453 } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {460 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 454 461 DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl); 455 462 return true; … … 458 465 int i = 0; 459 466 do { 460 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) { 461 helper.CopyVector(endpoints[(i + 1) % 3]->node->node); 462 helper.SubtractVector(endpoints[i % 3]->node->node); 463 CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 464 const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared(); 467 try { 468 CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node), 469 *(endpoints[(i+1)%3]->node->node), 470 *(endpoints[(i+2)%3]->node->node), 471 *Intersection); 472 helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 473 CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 474 const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared(); 465 475 DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl); 466 if ((s < -MYEPSILON) || ((s -1.) > MYEPSILON)) {476 if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) { 467 477 DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl); 468 i =4;478 i=4; 469 479 break; 470 480 } 471 481 i++; 472 } else482 } catch (LinearDependenceException &excp){ 473 483 break; 484 } 474 485 } while (i < 3); 475 486 if (i == 3) { … … 503 514 DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl); 504 515 GetCenter(&Direction); 505 if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) { 506 ClosestPoint->CopyVector(x); 516 try { 517 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction); 518 } 519 catch (LinearDependenceException &excp) { 520 (*ClosestPoint) = (*x); 507 521 } 508 522 509 523 // 2. Calculate in plane part of line (x, intersection) 510 Vector InPlane; 511 InPlane.CopyVector(x); 512 InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point 513 InPlane.ProjectOntoPlane(&NormalVector); 514 InPlane.AddVector(ClosestPoint); 524 Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point 525 InPlane.ProjectOntoPlane(NormalVector); 526 InPlane += *ClosestPoint; 515 527 516 528 DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl); … … 526 538 for (int i = 0; i < 3; i++) { 527 539 // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point 528 Direction.CopyVector(endpoints[(i + 1) % 3]->node->node); 529 Direction.SubtractVector(endpoints[i % 3]->node->node); 540 Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 530 541 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 531 CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node); 532 CrossDirection[i].CopyVector(&CrossPoint[i]); 533 CrossDirection[i].SubtractVector(&InPlane); 534 CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector 535 const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared(); 542 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 543 CrossDirection[i] = CrossPoint[i] - InPlane; 544 CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 545 const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared(); 536 546 DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl); 537 if ((s >= -MYEPSILON) && ((s -1.) <= MYEPSILON)) {538 CrossPoint[i].AddVector(endpoints[i % 3]->node->node);// make cross point absolute again547 if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) { 548 CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again 539 549 DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl); 540 const double distance = CrossPoint[i].DistanceSquared( x);550 const double distance = CrossPoint[i].DistanceSquared(*x); 541 551 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 542 552 ShortestDistance = distance; 543 ClosestPoint->CopyVector(&CrossPoint[i]);553 (*ClosestPoint) = CrossPoint[i]; 544 554 } 545 555 } else … … 548 558 InsideFlag = true; 549 559 for (int i = 0; i < 3; i++) { 550 const double sign = CrossDirection[i].ScalarProduct( &CrossDirection[(i + 1) % 3]);551 const double othersign = CrossDirection[i].ScalarProduct( &CrossDirection[(i + 2) % 3]);552 ; 560 const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 1) % 3]); 561 const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i + 2) % 3]); 562 553 563 if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign 554 564 InsideFlag = false; 555 565 } 556 566 if (InsideFlag) { 557 ClosestPoint->CopyVector(&InPlane);558 ShortestDistance = InPlane.DistanceSquared( x);567 (*ClosestPoint) = InPlane; 568 ShortestDistance = InPlane.DistanceSquared(*x); 559 569 } else { // also check endnodes 560 570 for (int i = 0; i < 3; i++) { 561 const double distance = x->DistanceSquared( endpoints[i]->node->node);571 const double distance = x->DistanceSquared(*endpoints[i]->node->node); 562 572 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 563 573 ShortestDistance = distance; 564 ClosestPoint->CopyVector(endpoints[i]->node->node);574 (*ClosestPoint) = (*endpoints[i]->node->node); 565 575 } 566 576 } … … 667 677 center->Zero(); 668 678 for (int i = 0; i < 3; i++) 669 center->AddVector(endpoints[i]->node->node);679 (*center) += (*endpoints[i]->node->node); 670 680 center->Scale(1. / 3.); 671 681 DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl); … … 733 743 int counter = 0; 734 744 for (; Runner[2] != endpoints.end();) { 735 TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node); 745 TemporaryNormal = Plane(*((*Runner[0])->node->node), 746 *((*Runner[1])->node->node), 747 *((*Runner[2])->node->node)).getNormal(); 736 748 for (int i = 0; i < 3; i++) // increase each of them 737 749 Runner[i]++; 738 TotalNormal->AddVector(&TemporaryNormal);750 (*TotalNormal) += TemporaryNormal; 739 751 } 740 752 TotalNormal->Scale(1. / (double) counter); 741 753 742 754 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 743 if (TotalNormal->ScalarProduct( &OtherVector) > 0.)755 if (TotalNormal->ScalarProduct(OtherVector) > 0.) 744 756 TotalNormal->Scale(-1.); 745 757 DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl); … … 758 770 center->Zero(); 759 771 int counter = 0; 760 for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {761 center->AddVector((*Runner)->node->node);772 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 773 (*center) += (*(*Runner)->node->node); 762 774 counter++; 763 775 } … … 1020 1032 BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI) 1021 1033 { 1022 Info FunctionInfo(__func__);1023 OptCenter .CopyVector(&OptCandidateCenter);1024 OtherOptCenter .CopyVector(&OtherOptCandidateCenter);1025 } 1026 ; 1034 Info FunctionInfo(__func__); 1035 OptCenter = OptCandidateCenter; 1036 OtherOptCenter = OtherOptCandidateCenter; 1037 }; 1038 1027 1039 1028 1040 /** Destructor for class CandidateForTesselation. … … 1055 1067 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1056 1068 for (int i = 0; i < 2; i++) { 1057 const double distance = fabs((*VRunner)->DistanceSquared( BaseLine->endpoints[i]->node->node) - radiusSquared);1069 const double distance = fabs((*VRunner)->DistanceSquared(*BaseLine->endpoints[i]->node->node) - radiusSquared); 1058 1070 if (distance > HULLEPSILON) { 1059 1071 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); … … 1067 1079 const TesselPoint *Walker = *Runner; 1068 1080 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) { 1069 const double distance = fabs((*VRunner)->DistanceSquared( Walker->node) - radiusSquared);1081 const double distance = fabs((*VRunner)->DistanceSquared(*Walker->node) - radiusSquared); 1070 1082 if (distance > HULLEPSILON) { 1071 1083 DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl); … … 1085 1097 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl); 1086 1098 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 1087 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( &OtherOptCenter) << "." << endl);1099 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(OtherOptCenter) << "." << endl); 1088 1100 1089 1101 // remove baseline's endpoints and candidates … … 1107 1119 // check with animate_sphere.tcl VMD script 1108 1120 if (ThirdPoint != NULL) { 1109 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 .x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2]<< endl);1121 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); 1110 1122 } else { 1111 1123 DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl); 1112 DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter .x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2]<< endl);1124 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); 1113 1125 } 1114 1126 } … … 1179 1191 int num = 0; 1180 1192 for (GoToFirst(); (!IsEnd()); GoToNext()) { 1181 Center->AddVector(GetPoint()->node);1193 (*Center) += (*GetPoint()->node); 1182 1194 num++; 1183 1195 } … … 1296 1308 C++; 1297 1309 for (; C != PointsOnBoundary.end(); C++) { 1298 tmp = A->second->node->node->DistanceSquared( B->second->node->node);1310 tmp = A->second->node->node->DistanceSquared(*B->second->node->node); 1299 1311 distance = tmp * tmp; 1300 tmp = A->second->node->node->DistanceSquared( C->second->node->node);1312 tmp = A->second->node->node->DistanceSquared(*C->second->node->node); 1301 1313 distance += tmp * tmp; 1302 tmp = B->second->node->node->DistanceSquared( C->second->node->node);1314 tmp = B->second->node->node->DistanceSquared(*C->second->node->node); 1303 1315 distance += tmp * tmp; 1304 1316 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); … … 1319 1331 // 2. next, we have to check whether all points reside on only one side of the triangle 1320 1332 // 3. construct plane vector 1321 PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node); 1333 PlaneVector = Plane(*A->second->node->node, 1334 *baseline->second.first->second->node->node, 1335 *baseline->second.second->second->node->node).getNormal(); 1322 1336 DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl); 1323 1337 // 4. loop over all points … … 1329 1343 continue; 1330 1344 // 4a. project onto plane vector 1331 TrialVector .CopyVector(checker->second->node->node);1332 TrialVector.SubtractVector( A->second->node->node);1333 distance = TrialVector.ScalarProduct( &PlaneVector);1345 TrialVector = (*checker->second->node->node); 1346 TrialVector.SubtractVector(*A->second->node->node); 1347 distance = TrialVector.ScalarProduct(PlaneVector); 1334 1348 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1335 1349 continue; … … 1346 1360 } 1347 1361 // 4d. Check whether the point is inside the triangle (check distance to each node 1348 tmp = checker->second->node->node->DistanceSquared( A->second->node->node);1362 tmp = checker->second->node->node->DistanceSquared(*A->second->node->node); 1349 1363 int innerpoint = 0; 1350 if ((tmp < A->second->node->node->DistanceSquared( baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))1364 if ((tmp < A->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(*baseline->second.second->second->node->node))) 1351 1365 innerpoint++; 1352 tmp = checker->second->node->node->DistanceSquared( baseline->second.first->second->node->node);1353 if ((tmp < baseline->second.first->second->node->node->DistanceSquared( A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))1366 tmp = checker->second->node->node->DistanceSquared(*baseline->second.first->second->node->node); 1367 if ((tmp < baseline->second.first->second->node->node->DistanceSquared(*A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(*baseline->second.second->second->node->node))) 1354 1368 innerpoint++; 1355 tmp = checker->second->node->node->DistanceSquared( baseline->second.second->second->node->node);1356 if ((tmp < baseline->second.second->second->node->node->DistanceSquared( baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(A->second->node->node)))1369 tmp = checker->second->node->node->DistanceSquared(*baseline->second.second->second->node->node); 1370 if ((tmp < baseline->second.second->second->node->node->DistanceSquared(*baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(*A->second->node->node))) 1357 1371 innerpoint++; 1358 1372 // 4e. If so, break 4. loop and continue with next candidate in 1. loop … … 1435 1449 // prepare some auxiliary vectors 1436 1450 Vector BaseLineCenter, BaseLine; 1437 BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node); 1438 BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node); 1439 BaseLineCenter.Scale(1. / 2.); // points now to center of base line 1440 BaseLine.CopyVector(baseline->second->endpoints[0]->node->node); 1441 BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node); 1451 BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) + 1452 (*baseline->second->endpoints[1]->node->node)); 1453 BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node); 1442 1454 1443 1455 // offset to center of triangle 1444 1456 CenterVector.Zero(); 1445 1457 for (int i = 0; i < 3; i++) 1446 CenterVector .AddVector(BTS->endpoints[i]->node->node);1458 CenterVector += (*BTS->endpoints[i]->node->node); 1447 1459 CenterVector.Scale(1. / 3.); 1448 1460 DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl); 1449 1461 1450 1462 // normal vector of triangle 1451 NormalVector.CopyVector(Center); 1452 NormalVector.SubtractVector(&CenterVector); 1463 NormalVector = (*Center) - CenterVector; 1453 1464 BTS->GetNormalVector(NormalVector); 1454 NormalVector .CopyVector(&BTS->NormalVector);1465 NormalVector = BTS->NormalVector; 1455 1466 DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl); 1456 1467 1457 1468 // vector in propagation direction (out of triangle) 1458 1469 // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection) 1459 PropagationVector.MakeNormalVector(&BaseLine, &NormalVector); 1460 TempVector.CopyVector(&CenterVector); 1461 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1470 PropagationVector = Plane(BaseLine, NormalVector,0).getNormal(); 1471 TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1462 1472 //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl; 1463 if (PropagationVector.ScalarProduct( &TempVector) > 0) // make sure normal propagation vector points outward from baseline1473 if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline 1464 1474 PropagationVector.Scale(-1.); 1465 1475 DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl); … … 1472 1482 1473 1483 // first check direction, so that triangles don't intersect 1474 VirtualNormalVector.CopyVector(target->second->node->node); 1475 VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target 1476 VirtualNormalVector.ProjectOntoPlane(&NormalVector); 1477 TempAngle = VirtualNormalVector.Angle(&PropagationVector); 1484 VirtualNormalVector = (*target->second->node->node) - BaseLineCenter; 1485 VirtualNormalVector.ProjectOntoPlane(NormalVector); 1486 TempAngle = VirtualNormalVector.Angle(PropagationVector); 1478 1487 DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl); 1479 1488 if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees) … … 1502 1511 1503 1512 // check for linear dependence 1504 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1505 TempVector.SubtractVector(target->second->node->node); 1506 helper.CopyVector(baseline->second->endpoints[1]->node->node); 1507 helper.SubtractVector(target->second->node->node); 1508 helper.ProjectOntoPlane(&TempVector); 1513 TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node); 1514 helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node); 1515 helper.ProjectOntoPlane(TempVector); 1509 1516 if (fabs(helper.NormSquared()) < MYEPSILON) { 1510 1517 DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl); … … 1514 1521 // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle 1515 1522 flag = true; 1516 VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node); 1517 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1518 TempVector.AddVector(baseline->second->endpoints[1]->node->node); 1519 TempVector.AddVector(target->second->node->node); 1520 TempVector.Scale(1. / 3.); 1521 TempVector.SubtractVector(Center); 1523 VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node), 1524 *(baseline->second->endpoints[1]->node->node), 1525 *(target->second->node->node)).getNormal(); 1526 TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) + 1527 (*baseline->second->endpoints[1]->node->node) + 1528 (*target->second->node->node)); 1529 TempVector -= (*Center); 1522 1530 // make it always point outward 1523 if (VirtualNormalVector.ScalarProduct( &TempVector) < 0)1531 if (VirtualNormalVector.ScalarProduct(TempVector) < 0) 1524 1532 VirtualNormalVector.Scale(-1.); 1525 1533 // calculate angle 1526 TempAngle = NormalVector.Angle( &VirtualNormalVector);1534 TempAngle = NormalVector.Angle(VirtualNormalVector); 1527 1535 DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl); 1528 1536 if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner … … 1532 1540 } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle) 1533 1541 // hence, check the angles to some normal direction from our base line but in this common plane of both targets... 1534 helper.CopyVector(target->second->node->node); 1535 helper.SubtractVector(&BaseLineCenter); 1536 helper.ProjectOntoPlane(&BaseLine); 1542 helper = (*target->second->node->node) - BaseLineCenter; 1543 helper.ProjectOntoPlane(BaseLine); 1537 1544 // ...the one with the smaller angle is the better candidate 1538 TempVector.CopyVector(target->second->node->node); 1539 TempVector.SubtractVector(&BaseLineCenter); 1540 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1541 TempAngle = TempVector.Angle(&helper); 1542 TempVector.CopyVector(winner->second->node->node); 1543 TempVector.SubtractVector(&BaseLineCenter); 1544 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1545 if (TempAngle < TempVector.Angle(&helper)) { 1546 TempAngle = NormalVector.Angle(&VirtualNormalVector); 1545 TempVector = (*target->second->node->node) - BaseLineCenter; 1546 TempVector.ProjectOntoPlane(VirtualNormalVector); 1547 TempAngle = TempVector.Angle(helper); 1548 TempVector = (*winner->second->node->node) - BaseLineCenter; 1549 TempVector.ProjectOntoPlane(VirtualNormalVector); 1550 if (TempAngle < TempVector.Angle(helper)) { 1551 TempAngle = NormalVector.Angle(VirtualNormalVector); 1547 1552 SmallestAngle = TempAngle; 1548 1553 winner = target; … … 1581 1586 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1582 1587 BTS->GetCenter(&helper); 1583 helper .SubtractVector(Center);1584 helper .Scale(-1);1588 helper -= (*Center); 1589 helper *= -1; 1585 1590 BTS->GetNormalVector(helper); 1586 1591 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); … … 1640 1645 DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl); 1641 1646 // we have the intersection, check whether in- or outside of boundary 1642 if ((Center->DistanceSquared( Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {1647 if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) { 1643 1648 // inside, next! 1644 1649 DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl); … … 1653 1658 OldPoints[i] = BTS->endpoints[i]; 1654 1659 } 1655 Normal .CopyVector(&BTS->NormalVector);1660 Normal = BTS->NormalVector; 1656 1661 // add Walker to boundary points 1657 1662 DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl); … … 1800 1805 // get open line 1801 1806 for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) { 1802 if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared( &Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches1807 if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches 1803 1808 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl); 1804 1809 insertNewLine = false; … … 2039 2044 bool flag = true; 2040 2045 2041 DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter .x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl);2046 DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter[0] << " " << CandidateLine.OtherOptCenter[1] << " " << CandidateLine.OtherOptCenter[2] << "} radius " << RADIUS << " resolution 30" << endl); 2042 2047 // get all points inside the sphere 2043 2048 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter); … … 2045 2050 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl); 2046 2051 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2047 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( &CandidateLine.OtherOptCenter) << "." << endl);2052 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl); 2048 2053 2049 2054 // remove triangles's endpoints … … 2061 2066 DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl); 2062 2067 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner) 2063 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance( &CandidateLine.OtherOptCenter) << "." << endl);2068 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->node->Distance(CandidateLine.OtherOptCenter) << "." << endl); 2064 2069 } 2065 2070 delete (ListofPoints); … … 2215 2220 if (List != NULL) { 2216 2221 for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 2217 if ((*Runner)->node-> x[i]> maxCoordinate[i]) {2222 if ((*Runner)->node->at(i) > maxCoordinate[i]) { 2218 2223 DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl); 2219 maxCoordinate[i] = (*Runner)->node-> x[i];2224 maxCoordinate[i] = (*Runner)->node->at(i); 2220 2225 MaxPoint[i] = (*Runner); 2221 2226 } … … 2235 2240 for (int k = 0; k < NDIM; k++) { 2236 2241 NormalVector.Zero(); 2237 NormalVector .x[k] = 1.;2242 NormalVector[k] = 1.; 2238 2243 BaseLine = new BoundaryLineSet(); 2239 2244 BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]); … … 2253 2258 2254 2259 // construct center of circle 2255 CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node); 2256 CircleCenter.AddVector(BaseLine->endpoints[1]->node->node); 2257 CircleCenter.Scale(0.5); 2260 CircleCenter = 0.5 * ((*BaseLine->endpoints[0]->node->node) + (*BaseLine->endpoints[1]->node->node)); 2258 2261 2259 2262 // construct normal vector of circle 2260 CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node); 2261 CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node); 2263 CirclePlaneNormal = (*BaseLine->endpoints[0]->node->node) - (*BaseLine->endpoints[1]->node->node); 2262 2264 2263 2265 double radius = CirclePlaneNormal.NormSquared(); 2264 2266 double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.); 2265 2267 2266 NormalVector.ProjectOntoPlane( &CirclePlaneNormal);2268 NormalVector.ProjectOntoPlane(CirclePlaneNormal); 2267 2269 NormalVector.Normalize(); 2268 2270 ShortestAngle = 2. * M_PI; // This will indicate the quadrant. 2269 2271 2270 SphereCenter.CopyVector(&NormalVector); 2271 SphereCenter.Scale(CircleRadius); 2272 SphereCenter.AddVector(&CircleCenter); 2272 SphereCenter = (CircleRadius * NormalVector) + CircleCenter; 2273 2273 // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized) 2274 2274 2275 2275 // look in one direction of baseline for initial candidate 2276 SearchDirection .MakeNormalVector(&CirclePlaneNormal, &NormalVector);// whether we look "left" first or "right" first is not important ...2276 SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ... 2277 2277 2278 2278 // adding point 1 and point 2 and add the line between them … … 2478 2478 2479 2479 // construct center of circle 2480 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2481 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2482 CircleCenter.Scale(0.5); 2480 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 2481 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 2483 2482 2484 2483 // construct normal vector of circle 2485 CirclePlaneNormal .CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);2486 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);2484 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 2485 (*CandidateLine.BaseLine->endpoints[1]->node->node); 2487 2486 2488 2487 // calculate squared radius of circle 2489 radius = CirclePlaneNormal.ScalarProduct( &CirclePlaneNormal);2488 radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal); 2490 2489 if (radius / 4. < RADIUS * RADIUS) { 2491 2490 // construct relative sphere center with now known CircleCenter 2492 RelativeSphereCenter.CopyVector(&T.SphereCenter); 2493 RelativeSphereCenter.SubtractVector(&CircleCenter); 2491 RelativeSphereCenter = T.SphereCenter - CircleCenter; 2494 2492 2495 2493 CircleRadius = RADIUS * RADIUS - radius / 4.; … … 2500 2498 2501 2499 // construct SearchDirection and an "outward pointer" 2502 SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal); 2503 helper.CopyVector(&CircleCenter); 2504 helper.SubtractVector(ThirdPoint->node->node); 2505 if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2500 SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal(); 2501 helper = CircleCenter - (*ThirdPoint->node->node); 2502 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2506 2503 SearchDirection.Scale(-1.); 2507 2504 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 2508 if (fabs(RelativeSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) {2505 if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { 2509 2506 // rotated the wrong way! 2510 2507 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl); … … 2643 2640 Finder->second->pointlist.push_back(Sprinter); 2644 2641 Finder->second->ShortestAngle = 0.; 2645 Finder->second->OptCenter .CopyVector(OptCenter);2642 Finder->second->OptCenter = *OptCenter; 2646 2643 } 2647 2644 } … … 2678 2675 // create normal vector 2679 2676 BTS->GetCenter(&Center); 2680 Center .SubtractVector(&CandidateLine.OptCenter);2681 BTS->SphereCenter .CopyVector(&CandidateLine.OptCenter);2677 Center -= CandidateLine.OptCenter; 2678 BTS->SphereCenter = CandidateLine.OptCenter; 2682 2679 BTS->GetNormalVector(Center); 2683 2680 // give some verbose output about the whole procedure … … 2712 2709 AddTesselationTriangle(); 2713 2710 2714 BTS->SphereCenter .CopyVector(&CandidateLine.OtherOptCenter);2711 BTS->SphereCenter = CandidateLine.OtherOptCenter; 2715 2712 // create normal vector in other direction 2716 BTS->GetNormalVector( &triangle->NormalVector);2713 BTS->GetNormalVector(triangle->NormalVector); 2717 2714 BTS->NormalVector.Scale(-1.); 2718 2715 // give some verbose output about the whole procedure … … 2757 2754 // create normal vector 2758 2755 BTS->GetCenter(&Center); 2759 Center.SubtractVector( OptCenter);2760 BTS->SphereCenter .CopyVector(OptCenter);2756 Center.SubtractVector(*OptCenter); 2757 BTS->SphereCenter = *OptCenter; 2761 2758 BTS->GetNormalVector(Center); 2762 2759 … … 2802 2799 Vector DistanceToIntersection[2], BaseLine; 2803 2800 double distance[2]; 2804 BaseLine.CopyVector(Base->endpoints[1]->node->node); 2805 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 2801 BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node); 2806 2802 for (int i = 0; i < 2; i++) { 2807 DistanceToIntersection[i].CopyVector(ClosestPoint); 2808 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 2809 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 2803 DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node); 2804 distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]); 2810 2805 } 2811 2806 delete (ClosestPoint); … … 2883 2878 2884 2879 // get the distance vector from Base line to OtherBase line 2885 Vector Distance; 2886 Distance.CopyVector(ClosestPoint[1]); 2887 Distance.SubtractVector(ClosestPoint[0]); 2880 Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]); 2888 2881 2889 2882 // calculate volume … … 2906 2899 } 2907 2900 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2908 DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);2909 BaseLineNormal .AddVector(&(runner->second->NormalVector));2901 DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl); 2902 BaseLineNormal += (runner->second->NormalVector); 2910 2903 } 2911 2904 BaseLineNormal.Scale(1. / 2.); 2912 2905 2913 if (Distance.ScalarProduct( &BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip2906 if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip 2914 2907 DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl); 2915 2908 // calculate volume summand as a general tetraeder … … 2947 2940 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2948 2941 DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl); 2949 BaseLineNormal .AddVector(&(runner->second->NormalVector));2942 BaseLineNormal += (runner->second->NormalVector); 2950 2943 } 2951 2944 BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector() … … 3087 3080 double distance, scaleFactor; 3088 3081 3089 OrthogonalizedOben.CopyVector(&Oben); 3090 aCandidate.CopyVector(a->node); 3091 aCandidate.SubtractVector(Candidate->node); 3092 OrthogonalizedOben.ProjectOntoPlane(&aCandidate); 3082 OrthogonalizedOben = Oben; 3083 aCandidate = (*a->node) - (*Candidate->node); 3084 OrthogonalizedOben.ProjectOntoPlane(aCandidate); 3093 3085 OrthogonalizedOben.Normalize(); 3094 3086 distance = 0.5 * aCandidate.Norm(); … … 3096 3088 OrthogonalizedOben.Scale(scaleFactor); 3097 3089 3098 Center.CopyVector(Candidate->node); 3099 Center.AddVector(a->node); 3100 Center.Scale(0.5); 3101 Center.AddVector(&OrthogonalizedOben); 3102 3103 AngleCheck.CopyVector(&Center); 3104 AngleCheck.SubtractVector(a->node); 3090 Center = 0.5 * ((*Candidate->node) + (*a->node)); 3091 Center += OrthogonalizedOben; 3092 3093 AngleCheck = Center - (*a->node); 3105 3094 norm = aCandidate.Norm(); 3106 3095 // second point shall have smallest angle with respect to Oben vector 3107 3096 if (norm < RADIUS * 2.) { 3108 angle = AngleCheck.Angle( &Oben);3097 angle = AngleCheck.Angle(Oben); 3109 3098 if (angle < Storage[0]) { 3110 3099 //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]); … … 3182 3171 3183 3172 // copy old center 3184 CandidateLine.OldCenter .CopyVector(&OldSphereCenter);3173 CandidateLine.OldCenter = OldSphereCenter; 3185 3174 CandidateLine.ThirdPoint = ThirdPoint; 3186 3175 CandidateLine.pointlist.clear(); 3187 3176 3188 3177 // construct center of circle 3189 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 3190 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 3191 CircleCenter.Scale(0.5); 3178 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 3179 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 3192 3180 3193 3181 // construct normal vector of circle 3194 CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 3195 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node); 3196 3197 RelativeOldSphereCenter.CopyVector(&OldSphereCenter); 3198 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 3182 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 3183 (*CandidateLine.BaseLine->endpoints[1]->node->node); 3184 3185 RelativeOldSphereCenter = OldSphereCenter - CircleCenter; 3199 3186 3200 3187 // calculate squared radius TesselPoint *ThirdPoint,f circle … … 3206 3193 3207 3194 // test whether old center is on the band's plane 3208 if (fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) > HULLEPSILON) {3209 DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) << "!" << endl);3210 RelativeOldSphereCenter.ProjectOntoPlane( &CirclePlaneNormal);3195 if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) { 3196 DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl); 3197 RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal); 3211 3198 } 3212 3199 radius = RelativeOldSphereCenter.NormSquared(); … … 3216 3203 // check SearchDirection 3217 3204 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 3218 if (fabs(RelativeOldSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) { // rotated the wrong way!3205 if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way! 3219 3206 DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl); 3220 3207 } … … 3254 3241 DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl); 3255 3242 3256 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) { 3243 try { 3244 NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node), 3245 *(CandidateLine.BaseLine->endpoints[1]->node->node), 3246 *(Candidate->node)).getNormal(); 3257 3247 DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl); 3258 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared( &NewPlaneCenter);3248 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter); 3259 3249 DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl); 3260 3250 DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl); 3261 3251 DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl); 3262 3252 if (radius < RADIUS * RADIUS) { 3263 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared( &NewPlaneCenter);3253 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter); 3264 3254 if (fabs(radius - otherradius) < HULLEPSILON) { 3265 3255 // construct both new centers 3266 NewSphereCenter .CopyVector(&NewPlaneCenter);3267 OtherNewSphereCenter .CopyVector(&NewPlaneCenter);3268 helper .CopyVector(&NewNormalVector);3256 NewSphereCenter = NewPlaneCenter; 3257 OtherNewSphereCenter= NewPlaneCenter; 3258 helper = NewNormalVector; 3269 3259 helper.Scale(sqrt(RADIUS * RADIUS - radius)); 3270 3260 DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl); 3271 NewSphereCenter .AddVector(&helper);3261 NewSphereCenter += helper; 3272 3262 DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl); 3273 3263 // OtherNewSphereCenter is created by the same vector just in the other direction 3274 3264 helper.Scale(-1.); 3275 OtherNewSphereCenter .AddVector(&helper);3265 OtherNewSphereCenter += helper; 3276 3266 DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl); 3277 3278 3267 alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3279 3268 Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection); 3280 3269 if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid 3281 if (OldSphereCenter.DistanceSquared( &NewSphereCenter) < OldSphereCenter.DistanceSquared(&OtherNewSphereCenter))3270 if (OldSphereCenter.DistanceSquared(NewSphereCenter) < OldSphereCenter.DistanceSquared(OtherNewSphereCenter)) 3282 3271 alpha = Otheralpha; 3283 3272 } else 3284 3273 alpha = min(alpha, Otheralpha); 3285 3286 3274 // if there is a better candidate, drop the current list and add the new candidate 3287 3275 // otherwise ignore the new candidate and keep the list 3288 3276 if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) { 3289 3277 if (fabs(alpha - Otheralpha) > MYEPSILON) { 3290 CandidateLine.OptCenter .CopyVector(&NewSphereCenter);3291 CandidateLine.OtherOptCenter .CopyVector(&OtherNewSphereCenter);3278 CandidateLine.OptCenter = NewSphereCenter; 3279 CandidateLine.OtherOptCenter = OtherNewSphereCenter; 3292 3280 } else { 3293 CandidateLine.OptCenter .CopyVector(&OtherNewSphereCenter);3294 CandidateLine.OtherOptCenter .CopyVector(&NewSphereCenter);3281 CandidateLine.OptCenter = OtherNewSphereCenter; 3282 CandidateLine.OtherOptCenter = NewSphereCenter; 3295 3283 } 3296 3284 // if there is an equal candidate, add it to the list without clearing the list … … 3319 3307 DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl); 3320 3308 } 3321 } else { 3322 DoLog(1) && (Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl); 3309 } 3310 catch (LinearDependenceException &excp){ 3311 Log() << Verbose(1) << excp; 3312 Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl; 3323 3313 } 3324 3314 } else { … … 3416 3406 FindPoint = PointsOnBoundary.find((*Runner)->nr); 3417 3407 if (FindPoint != PointsOnBoundary.end()) { 3418 points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared( x), FindPoint->second));3408 points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second)); 3419 3409 DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl); 3420 3410 } … … 3460 3450 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3461 3451 // calculate closest point on line to desired point 3462 helper.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3463 helper.AddVector((LineRunner->second)->endpoints[1]->node->node); 3464 helper.Scale(0.5); 3465 Center.CopyVector(x); 3466 Center.SubtractVector(&helper); 3467 BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3468 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3469 Center.ProjectOntoPlane(&BaseLine); 3452 helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) + 3453 (*(LineRunner->second)->endpoints[1]->node->node)); 3454 Center = (*x) - helper; 3455 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3456 (*(LineRunner->second)->endpoints[1]->node->node); 3457 Center.ProjectOntoPlane(BaseLine); 3470 3458 const double distance = Center.NormSquared(); 3471 3459 if ((ClosestLine == NULL) || (distance < MinDistance)) { 3472 3460 // additionally calculate intersection on line (whether it's on the line section or not) 3473 helper.CopyVector(x); 3474 helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3475 helper.SubtractVector(&Center); 3476 const double lengthA = helper.ScalarProduct(&BaseLine); 3477 helper.CopyVector(x); 3478 helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3479 helper.SubtractVector(&Center); 3480 const double lengthB = helper.ScalarProduct(&BaseLine); 3461 helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center; 3462 const double lengthA = helper.ScalarProduct(BaseLine); 3463 helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center; 3464 const double lengthB = helper.ScalarProduct(BaseLine); 3481 3465 if (lengthB * lengthA < 0) { // if have different sign 3482 3466 ClosestLine = LineRunner->second; … … 3527 3511 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3528 3512 3529 BaseLine .CopyVector((LineRunner->second)->endpoints[0]->node->node);3530 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);3513 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3514 (*(LineRunner->second)->endpoints[1]->node->node); 3531 3515 const double lengthBase = BaseLine.NormSquared(); 3532 3516 3533 BaseLineIntersection.CopyVector(x); 3534 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3517 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node); 3535 3518 const double lengthEndA = BaseLineIntersection.NormSquared(); 3536 3519 3537 BaseLineIntersection.CopyVector(x); 3538 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3520 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3539 3521 const double lengthEndB = BaseLineIntersection.NormSquared(); 3540 3522 … … 3554 3536 } else { // intersection is closer, calculate 3555 3537 // calculate closest point on line to desired point 3556 BaseLineIntersection.CopyVector(x); 3557 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3558 Center.CopyVector(&BaseLineIntersection); 3559 Center.ProjectOntoPlane(&BaseLine); 3560 BaseLineIntersection.SubtractVector(&Center); 3538 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3539 Center = BaseLineIntersection; 3540 Center.ProjectOntoPlane(BaseLine); 3541 BaseLineIntersection -= Center; 3561 3542 const double distance = BaseLineIntersection.NormSquared(); 3562 3543 if (Center.NormSquared() > BaseLine.NormSquared()) { … … 3612 3593 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) { 3613 3594 (*Runner)->GetCenter(&Center); 3614 helper.CopyVector(x); 3615 helper.SubtractVector(&Center); 3616 const double Alignment = helper.Angle(&(*Runner)->NormalVector); 3595 helper = (*x) - Center; 3596 const double Alignment = helper.Angle((*Runner)->NormalVector); 3617 3597 if (Alignment < MinAlignment) { 3618 3598 result = *Runner; … … 3681 3661 triangle->GetCenter(&Center); 3682 3662 DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl); 3683 DistanceToCenter.CopyVector(&Center); 3684 DistanceToCenter.SubtractVector(&Point); 3663 DistanceToCenter = Center - Point; 3685 3664 DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl); 3686 3665 3687 3666 // check whether we are on boundary 3688 if (fabs(DistanceToCenter.ScalarProduct( &triangle->NormalVector)) < MYEPSILON) {3667 if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) { 3689 3668 // calculate whether inside of triangle 3690 DistanceToCenter.CopyVector(&Point); 3691 Center.CopyVector(&Point); 3692 Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter 3693 DistanceToCenter.AddVector(&triangle->NormalVector); // points outside 3669 DistanceToCenter = Point + triangle->NormalVector; // points outside 3670 Center = Point - triangle->NormalVector; // points towards MolCenter 3694 3671 DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl); 3695 3672 if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) { … … 3706 3683 3707 3684 // then check direction to boundary 3708 if (DistanceToCenter.ScalarProduct( &triangle->NormalVector) > MYEPSILON) {3685 if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) { 3709 3686 DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl); 3710 3687 return -distance; … … 3840 3817 if ((triangles != NULL) && (!triangles->empty())) { 3841 3818 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) 3842 PlaneNormal .AddVector(&(*Runner)->NormalVector);3819 PlaneNormal += (*Runner)->NormalVector; 3843 3820 } else { 3844 3821 DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl); … … 3851 3828 // construct one orthogonal vector 3852 3829 if (Reference != NULL) { 3853 AngleZero.CopyVector(Reference); 3854 AngleZero.SubtractVector(Point->node); 3855 AngleZero.ProjectOntoPlane(&PlaneNormal); 3830 AngleZero = (*Reference) - (*Point->node); 3831 AngleZero.ProjectOntoPlane(PlaneNormal); 3856 3832 } 3857 3833 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3858 3834 DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl); 3859 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3860 AngleZero.SubtractVector(Point->node); 3861 AngleZero.ProjectOntoPlane(&PlaneNormal); 3835 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3836 AngleZero.ProjectOntoPlane(PlaneNormal); 3862 3837 if (AngleZero.NormSquared() < MYEPSILON) { 3863 3838 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); … … 3867 3842 DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl); 3868 3843 if (AngleZero.NormSquared() > MYEPSILON) 3869 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3844 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3870 3845 else 3871 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3846 OrthogonalVector.MakeNormalTo(PlaneNormal); 3872 3847 DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl); 3873 3848 3874 3849 // go through all connected points and calculate angle 3875 3850 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3876 helper.CopyVector((*listRunner)->node); 3877 helper.SubtractVector(Point->node); 3878 helper.ProjectOntoPlane(&PlaneNormal); 3851 helper = (*(*listRunner)->node) - (*Point->node); 3852 helper.ProjectOntoPlane(PlaneNormal); 3879 3853 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3880 3854 DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl); … … 3934 3908 int counter = 0; 3935 3909 while (TesselC != SetOfNeighbours->end()) { 3936 helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node); 3910 helper = Plane(*((*TesselA)->node), 3911 *((*TesselB)->node), 3912 *((*TesselC)->node)).getNormal(); 3937 3913 DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl); 3938 3914 counter++; … … 3940 3916 TesselB++; 3941 3917 TesselC++; 3942 PlaneNormal .AddVector(&helper);3918 PlaneNormal += helper; 3943 3919 } 3944 3920 //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size() … … 3955 3931 // construct one orthogonal vector 3956 3932 if (Reference != NULL) { 3957 AngleZero.CopyVector(Reference); 3958 AngleZero.SubtractVector(Point->node); 3959 AngleZero.ProjectOntoPlane(&PlaneNormal); 3960 } 3961 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) { 3933 AngleZero = (*Reference) - (*Point->node); 3934 AngleZero.ProjectOntoPlane(PlaneNormal); 3935 } 3936 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) { 3962 3937 DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl); 3963 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3964 AngleZero.SubtractVector(Point->node); 3965 AngleZero.ProjectOntoPlane(&PlaneNormal); 3938 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3939 AngleZero.ProjectOntoPlane(PlaneNormal); 3966 3940 if (AngleZero.NormSquared() < MYEPSILON) { 3967 3941 DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl); … … 3971 3945 DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl); 3972 3946 if (AngleZero.NormSquared() > MYEPSILON) 3973 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3947 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3974 3948 else 3975 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3949 OrthogonalVector.MakeNormalTo(PlaneNormal); 3976 3950 DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl); 3977 3951 … … 3979 3953 pair<map<double, TesselPoint*>::iterator, bool> InserterTest; 3980 3954 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3981 helper.CopyVector((*listRunner)->node); 3982 helper.SubtractVector(Point->node); 3983 helper.ProjectOntoPlane(&PlaneNormal); 3955 helper = (*(*listRunner)->node) - (*Point->node); 3956 helper.ProjectOntoPlane(PlaneNormal); 3984 3957 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3985 3958 if (angle > M_PI) // the correction is of no use here (and not desired) … … 4225 4198 4226 4199 // copy old location for the volume 4227 OldPoint .CopyVector(point->node->node);4200 OldPoint = (*point->node->node); 4228 4201 4229 4202 // get list of connected points … … 4253 4226 for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { 4254 4227 DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl); 4255 NormalVector .SubtractVector(&Runner->second->NormalVector); // has to point inward4228 NormalVector -= Runner->second->NormalVector; // has to point inward 4256 4229 RemoveTesselationTriangle(Runner->second); 4257 4230 count++; … … 4288 4261 StartNode--; 4289 4262 //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl; 4290 Point.CopyVector((*StartNode)->node); 4291 Point.SubtractVector((*MiddleNode)->node); 4263 Point = (*(*StartNode)->node) - (*(*MiddleNode)->node); 4292 4264 StartNode = MiddleNode; 4293 4265 StartNode++; … … 4295 4267 StartNode = connectedPath->begin(); 4296 4268 //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl; 4297 Reference.CopyVector((*StartNode)->node); 4298 Reference.SubtractVector((*MiddleNode)->node); 4299 OrthogonalVector.CopyVector((*MiddleNode)->node); 4300 OrthogonalVector.SubtractVector(&OldPoint); 4301 OrthogonalVector.MakeNormalVector(&Reference); 4269 Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node); 4270 OrthogonalVector = (*(*MiddleNode)->node) - OldPoint; 4271 OrthogonalVector.MakeNormalTo(Reference); 4302 4272 angle = GetAngle(Point, Reference, OrthogonalVector); 4303 4273 //if (angle < M_PI) // no wrong-sided triangles, please? … … 4752 4722 class BoundaryLineSet *BestLine = NULL; 4753 4723 for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) { 4754 BaseLine.CopyVector(Runner->second->endpoints[0]->node->node); 4755 BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node); 4756 CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node); 4757 CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node); 4758 CenterToPoint.Scale(0.5); 4759 CenterToPoint.SubtractVector(point->node); 4760 angle = CenterToPoint.Angle(&BaseLine); 4761 if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) { 4724 BaseLine = (*Runner->second->endpoints[0]->node->node) - 4725 (*Runner->second->endpoints[1]->node->node); 4726 CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) + 4727 (*Runner->second->endpoints[1]->node->node)); 4728 CenterToPoint -= (*point->node); 4729 angle = CenterToPoint.Angle(BaseLine); 4730 if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) { 4762 4731 BestAngle = angle; 4763 4732 BestLine = Runner->second; … … 4925 4894 for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) 4926 4895 if (VectorWalker != VectorRunner) { // skip equals 4927 const double SCP = VectorWalker->second->ScalarProduct( VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles4896 const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles 4928 4897 DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl); 4929 4898 if (fabs(SCP + 1.) < ParallelEpsilon) { … … 5010 4979 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 5011 4980 /// 4a. Get NormalVector for one side (this is "front") 5012 NormalVector .CopyVector(&(*TriangleWalker)->NormalVector);4981 NormalVector = (*TriangleWalker)->NormalVector; 5013 4982 DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl); 5014 4983 TriangleWalker++; … … 5021 4990 TriangleSprinter++; 5022 4991 DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl); 5023 if (triangle->NormalVector.ScalarProduct( &NormalVector) < 0) { // if from other side, then delete and remove from list4992 if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list 5024 4993 DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl); 5025 4994 TriangleNrs.push(triangle->Nr); … … 5043 5012 AddTesselationTriangle(); // ... and add 5044 5013 TriangleNrs.pop(); 5045 BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector); 5046 BTS->NormalVector.Scale(-1.); 5014 BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector; 5047 5015 TriangleWalker++; 5048 5016 }
Note:
See TracChangeset
for help on using the changeset viewer.
