Changeset 1f591b for molecuilder/src/tesselation.cpp
- Timestamp:
- Apr 13, 2010, 1:22:42 PM (16 years ago)
- Children:
- e7ea64
- Parents:
- 0f55b2
- File:
-
- 1 edited
-
molecuilder/src/tesselation.cpp (modified) (63 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/tesselation.cpp
r0f55b2 r1f591b 234 234 // have a normal vector on the base line pointing outwards 235 235 //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); 236 BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node)); 237 BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node); 241 238 //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl; 242 239 … … 248 245 for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 249 246 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 250 NormalCheck .AddVector(&runner->second->NormalVector);251 NormalCheck .Scale(sign);247 NormalCheck += runner->second->NormalVector; 248 NormalCheck *= sign; 252 249 sign = -sign; 253 250 if (runner->second->NormalVector.NormSquared() > MYEPSILON) 254 BaseLineNormal .CopyVector(&runner->second->NormalVector); // yes, copy second on top of first251 BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first 255 252 else { 256 253 eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl; … … 259 256 if (node != NULL) { 260 257 //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); 258 helper[i] = (*node->node->node) - BaseLineCenter; 263 259 helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles! 264 260 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; … … 410 406 411 407 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 412 if (NormalVector.ScalarProduct( &OtherVector) > 0.)408 if (NormalVector.ScalarProduct(OtherVector) > 0.) 413 409 NormalVector.Scale(-1.); 414 410 Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl; … … 446 442 Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl; 447 443 448 if (Intersection->DistanceSquared( endpoints[0]->node->node) < MYEPSILON) {444 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 449 445 Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl; 450 446 return true; 451 } else if (Intersection->DistanceSquared( endpoints[1]->node->node) < MYEPSILON) {447 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 452 448 Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl; 453 449 return true; 454 } else if (Intersection->DistanceSquared( endpoints[2]->node->node) < MYEPSILON) {450 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 455 451 Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl; 456 452 return true; … … 464 460 *(endpoints[(i+2)%3]->node->node), 465 461 *Intersection); 466 helper.CopyVector(endpoints[(i+1)%3]->node->node); 467 helper.SubtractVector(endpoints[i%3]->node->node); 468 CrossPoint.SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector 469 const double s = CrossPoint.ScalarProduct(&helper)/helper.NormSquared(); 462 helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 463 CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 464 const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared(); 470 465 Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl; 471 466 if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) { … … 510 505 } 511 506 catch (LinearDependenceException &excp) { 512 ClosestPoint->CopyVector(x);507 (*ClosestPoint) = (*x); 513 508 } 514 509 515 510 // 2. Calculate in plane part of line (x, intersection) 516 Vector InPlane; 517 InPlane.CopyVector(x); 518 InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point 519 InPlane.ProjectOntoPlane(&NormalVector); 520 InPlane.AddVector(ClosestPoint); 511 Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point 512 InPlane.ProjectOntoPlane(NormalVector); 513 InPlane += *ClosestPoint; 521 514 522 515 Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl; … … 532 525 for (int i=0;i<3;i++) { 533 526 // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point 534 Direction.CopyVector(endpoints[(i+1)%3]->node->node); 535 Direction.SubtractVector(endpoints[i%3]->node->node); 527 Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 536 528 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 537 529 538 530 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 539 531 540 CrossDirection[i].CopyVector(&CrossPoint[i]); 541 CrossDirection[i].SubtractVector(&InPlane); 542 CrossPoint[i].SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector 543 const double s = CrossPoint[i].ScalarProduct(&Direction)/Direction.NormSquared(); 532 CrossDirection[i] = CrossPoint[i] - InPlane; 533 CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 534 const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared(); 544 535 Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl; 545 536 if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) { 546 CrossPoint[i] .AddVector(endpoints[i%3]->node->node); // make cross point absolute again537 CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again 547 538 Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl; 548 const double distance = CrossPoint[i].DistanceSquared( x);539 const double distance = CrossPoint[i].DistanceSquared(*x); 549 540 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 550 541 ShortestDistance = distance; 551 ClosestPoint->CopyVector(&CrossPoint[i]);542 (*ClosestPoint) = CrossPoint[i]; 552 543 } 553 544 } else … … 556 547 InsideFlag = true; 557 548 for (int i=0;i<3;i++) { 558 const double sign = CrossDirection[i].ScalarProduct( &CrossDirection[(i+1)%3]);559 const double othersign = CrossDirection[i].ScalarProduct( &CrossDirection[(i+2)%3]);;549 const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i+1)%3]); 550 const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i+2)%3]);; 560 551 if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign 561 552 InsideFlag = false; 562 553 } 563 554 if (InsideFlag) { 564 ClosestPoint->CopyVector(&InPlane);565 ShortestDistance = InPlane.DistanceSquared( x);555 (*ClosestPoint) = InPlane; 556 ShortestDistance = InPlane.DistanceSquared(*x); 566 557 } else { // also check endnodes 567 558 for (int i=0;i<3;i++) { 568 const double distance = x->DistanceSquared( endpoints[i]->node->node);559 const double distance = x->DistanceSquared(*endpoints[i]->node->node); 569 560 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 570 561 ShortestDistance = distance; 571 ClosestPoint->CopyVector(endpoints[i]->node->node);562 (*ClosestPoint) = (*endpoints[i]->node->node); 572 563 } 573 564 } … … 687 678 center->Zero(); 688 679 for(int i=0;i<3;i++) 689 center->AddVector(endpoints[i]->node->node);680 (*center) += (*endpoints[i]->node->node); 690 681 center->Scale(1./3.); 691 682 Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl; … … 755 746 for (int i=0;i<3;i++) // increase each of them 756 747 Runner[i]++; 757 TotalNormal->AddVector(&TemporaryNormal);748 (*TotalNormal) += TemporaryNormal; 758 749 } 759 750 TotalNormal->Scale(1./(double)counter); 760 751 761 752 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 762 if (TotalNormal->ScalarProduct( &OtherVector) > 0.)753 if (TotalNormal->ScalarProduct(OtherVector) > 0.) 763 754 TotalNormal->Scale(-1.); 764 755 Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl; … … 777 768 int counter = 0; 778 769 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 779 center->AddVector((*Runner)->node->node);770 (*center) += (*(*Runner)->node->node); 780 771 counter++; 781 772 } … … 1028 1019 { 1029 1020 Info FunctionInfo(__func__); 1030 OptCenter .CopyVector(&OptCandidateCenter);1031 OtherOptCenter .CopyVector(&OtherOptCandidateCenter);1021 OptCenter = OptCandidateCenter; 1022 OtherOptCenter = OtherOptCandidateCenter; 1032 1023 }; 1033 1024 … … 1105 1096 int num=0; 1106 1097 for (GoToFirst(); (!IsEnd()); GoToNext()) { 1107 Center->AddVector(GetPoint()->node);1098 (*Center) += (*GetPoint()->node); 1108 1099 num++; 1109 1100 } … … 1217 1208 for (; C != PointsOnBoundary.end(); C++) 1218 1209 { 1219 tmp = A->second->node->node->DistanceSquared( B->second->node->node);1210 tmp = A->second->node->node->DistanceSquared(*B->second->node->node); 1220 1211 distance = tmp * tmp; 1221 tmp = A->second->node->node->DistanceSquared( C->second->node->node);1212 tmp = A->second->node->node->DistanceSquared(*C->second->node->node); 1222 1213 distance += tmp * tmp; 1223 tmp = B->second->node->node->DistanceSquared( C->second->node->node);1214 tmp = B->second->node->node->DistanceSquared(*C->second->node->node); 1224 1215 distance += tmp * tmp; 1225 1216 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); … … 1255 1246 continue; 1256 1247 // 4a. project onto plane vector 1257 TrialVector.CopyVector(checker->second->node->node); 1258 TrialVector.SubtractVector(A->second->node->node); 1259 distance = TrialVector.ScalarProduct(&PlaneVector); 1248 TrialVector = (*checker->second->node->node) - (*A->second->node->node); 1249 distance = TrialVector.ScalarProduct(PlaneVector); 1260 1250 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1261 1251 continue; … … 1285 1275 } 1286 1276 // 4d. Check whether the point is inside the triangle (check distance to each node 1287 tmp = checker->second->node->node->DistanceSquared( A->second->node->node);1277 tmp = checker->second->node->node->DistanceSquared(*A->second->node->node); 1288 1278 int innerpoint = 0; 1289 1279 if ((tmp < A->second->node->node->DistanceSquared( 1290 baseline->second.first->second->node->node)) && (tmp1280 *baseline->second.first->second->node->node)) && (tmp 1291 1281 < A->second->node->node->DistanceSquared( 1292 baseline->second.second->second->node->node)))1282 *baseline->second.second->second->node->node))) 1293 1283 innerpoint++; 1294 1284 tmp = checker->second->node->node->DistanceSquared( 1295 baseline->second.first->second->node->node);1285 *baseline->second.first->second->node->node); 1296 1286 if ((tmp < baseline->second.first->second->node->node->DistanceSquared( 1297 A->second->node->node)) && (tmp1287 *A->second->node->node)) && (tmp 1298 1288 < baseline->second.first->second->node->node->DistanceSquared( 1299 baseline->second.second->second->node->node)))1289 *baseline->second.second->second->node->node))) 1300 1290 innerpoint++; 1301 1291 tmp = checker->second->node->node->DistanceSquared( 1302 baseline->second.second->second->node->node);1292 *baseline->second.second->second->node->node); 1303 1293 if ((tmp < baseline->second.second->second->node->node->DistanceSquared( 1304 baseline->second.first->second->node->node)) && (tmp1294 *baseline->second.first->second->node->node)) && (tmp 1305 1295 < baseline->second.second->second->node->node->DistanceSquared( 1306 A->second->node->node)))1296 *A->second->node->node))) 1307 1297 innerpoint++; 1308 1298 // 4e. If so, break 4. loop and continue with next candidate in 1. loop … … 1390 1380 // prepare some auxiliary vectors 1391 1381 Vector BaseLineCenter, BaseLine; 1392 BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node); 1393 BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node); 1394 BaseLineCenter.Scale(1. / 2.); // points now to center of base line 1395 BaseLine.CopyVector(baseline->second->endpoints[0]->node->node); 1396 BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node); 1382 BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) + 1383 (*baseline->second->endpoints[1]->node->node)); 1384 BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node); 1397 1385 1398 1386 // offset to center of triangle 1399 1387 CenterVector.Zero(); 1400 1388 for (int i = 0; i < 3; i++) 1401 CenterVector .AddVector(BTS->endpoints[i]->node->node);1389 CenterVector += (*BTS->endpoints[i]->node->node); 1402 1390 CenterVector.Scale(1. / 3.); 1403 1391 Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl; 1404 1392 1405 1393 // normal vector of triangle 1406 NormalVector.CopyVector(Center); 1407 NormalVector.SubtractVector(&CenterVector); 1394 NormalVector = (*Center) - CenterVector; 1408 1395 BTS->GetNormalVector(NormalVector); 1409 NormalVector .CopyVector(&BTS->NormalVector);1396 NormalVector = BTS->NormalVector; 1410 1397 Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl; 1411 1398 … … 1413 1400 // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection) 1414 1401 PropagationVector = Plane(BaseLine, NormalVector,0).getNormal(); 1415 TempVector.CopyVector(&CenterVector); 1416 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1402 TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1417 1403 //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl; 1418 if (PropagationVector.ScalarProduct( &TempVector) > 0) // make sure normal propagation vector points outward from baseline1404 if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline 1419 1405 PropagationVector.Scale(-1.); 1420 1406 Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl; … … 1427 1413 1428 1414 // first check direction, so that triangles don't intersect 1429 VirtualNormalVector.CopyVector(target->second->node->node); 1430 VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target 1431 VirtualNormalVector.ProjectOntoPlane(&NormalVector); 1432 TempAngle = VirtualNormalVector.Angle(&PropagationVector); 1415 VirtualNormalVector = (*target->second->node->node) - BaseLineCenter; 1416 TempAngle = VirtualNormalVector.Angle(PropagationVector); 1433 1417 Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl; 1434 1418 if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees) … … 1457 1441 1458 1442 // check for linear dependence 1459 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1460 TempVector.SubtractVector(target->second->node->node); 1461 helper.CopyVector(baseline->second->endpoints[1]->node->node); 1462 helper.SubtractVector(target->second->node->node); 1463 helper.ProjectOntoPlane(&TempVector); 1443 TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node); 1444 helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node); 1445 helper.ProjectOntoPlane(TempVector); 1464 1446 if (fabs(helper.NormSquared()) < MYEPSILON) { 1465 1447 Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl; … … 1472 1454 *(baseline->second->endpoints[1]->node->node), 1473 1455 *(target->second->node->node)).getNormal(); 1474 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1475 TempVector.AddVector(baseline->second->endpoints[1]->node->node); 1476 TempVector.AddVector(target->second->node->node); 1477 TempVector.Scale(1./3.); 1478 TempVector.SubtractVector(Center); 1456 TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) + 1457 (*baseline->second->endpoints[1]->node->node) + 1458 (*target->second->node->node)); 1459 TempVector -= (*Center); 1479 1460 // make it always point outward 1480 if (VirtualNormalVector.ScalarProduct( &TempVector) < 0)1461 if (VirtualNormalVector.ScalarProduct(TempVector) < 0) 1481 1462 VirtualNormalVector.Scale(-1.); 1482 1463 // calculate angle 1483 TempAngle = NormalVector.Angle( &VirtualNormalVector);1464 TempAngle = NormalVector.Angle(VirtualNormalVector); 1484 1465 Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl; 1485 1466 if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner … … 1489 1470 } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle) 1490 1471 // hence, check the angles to some normal direction from our base line but in this common plane of both targets... 1491 helper.CopyVector(target->second->node->node); 1492 helper.SubtractVector(&BaseLineCenter); 1493 helper.ProjectOntoPlane(&BaseLine); 1472 helper = (*target->second->node->node) - BaseLineCenter; 1473 helper.ProjectOntoPlane(BaseLine); 1494 1474 // ...the one with the smaller angle is the better candidate 1495 TempVector.CopyVector(target->second->node->node); 1496 TempVector.SubtractVector(&BaseLineCenter); 1497 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1498 TempAngle = TempVector.Angle(&helper); 1499 TempVector.CopyVector(winner->second->node->node); 1500 TempVector.SubtractVector(&BaseLineCenter); 1501 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1502 if (TempAngle < TempVector.Angle(&helper)) { 1503 TempAngle = NormalVector.Angle(&VirtualNormalVector); 1475 TempVector = (*target->second->node->node) - BaseLineCenter; 1476 TempVector.ProjectOntoPlane(VirtualNormalVector); 1477 TempAngle = TempVector.Angle(helper); 1478 TempVector = (*winner->second->node->node) - BaseLineCenter; 1479 TempVector.ProjectOntoPlane(VirtualNormalVector); 1480 if (TempAngle < TempVector.Angle(helper)) { 1481 TempAngle = NormalVector.Angle(VirtualNormalVector); 1504 1482 SmallestAngle = TempAngle; 1505 1483 winner = target; … … 1538 1516 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1539 1517 BTS->GetCenter(&helper); 1540 helper .SubtractVector(Center);1541 helper .Scale(-1);1518 helper -= (*Center); 1519 helper *= -1; 1542 1520 BTS->GetNormalVector(helper); 1543 1521 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); … … 1596 1574 Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl; 1597 1575 // we have the intersection, check whether in- or outside of boundary 1598 if ((Center->DistanceSquared( Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {1576 if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) { 1599 1577 // inside, next! 1600 1578 Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl; … … 1609 1587 OldPoints[i] = BTS->endpoints[i]; 1610 1588 } 1611 Normal .CopyVector(&BTS->NormalVector);1589 Normal = BTS->NormalVector; 1612 1590 // add Walker to boundary points 1613 1591 Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl; … … 2119 2097 2120 2098 // construct center of circle 2121 CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node); 2122 CircleCenter.AddVector(BaseLine.endpoints[1]->node->node); 2123 CircleCenter.Scale(0.5); 2099 CircleCenter = 0.5 * ((*BaseLine.endpoints[0]->node->node) + (*BaseLine.endpoints[1]->node->node)); 2124 2100 2125 2101 // construct normal vector of circle 2126 CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node); 2127 CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node); 2102 CirclePlaneNormal = (*BaseLine.endpoints[0]->node->node) - (*BaseLine.endpoints[1]->node->node); 2128 2103 2129 2104 double radius = CirclePlaneNormal.NormSquared(); 2130 2105 double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.); 2131 2106 2132 NormalVector.ProjectOntoPlane( &CirclePlaneNormal);2107 NormalVector.ProjectOntoPlane(CirclePlaneNormal); 2133 2108 NormalVector.Normalize(); 2134 2109 ShortestAngle = 2.*M_PI; // This will indicate the quadrant. 2135 2110 2136 SphereCenter.CopyVector(&NormalVector); 2137 SphereCenter.Scale(CircleRadius); 2138 SphereCenter.AddVector(&CircleCenter); 2111 SphereCenter = (CircleRadius * NormalVector) + CircleCenter; 2139 2112 // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized) 2140 2113 … … 2337 2310 2338 2311 // construct center of circle 2339 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2340 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2341 CircleCenter.Scale(0.5); 2312 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 2313 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 2342 2314 2343 2315 // construct normal vector of circle 2344 CirclePlaneNormal .CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);2345 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);2316 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 2317 (*CandidateLine.BaseLine->endpoints[1]->node->node); 2346 2318 2347 2319 // calculate squared radius of circle 2348 radius = CirclePlaneNormal.ScalarProduct( &CirclePlaneNormal);2320 radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal); 2349 2321 if (radius/4. < RADIUS*RADIUS) { 2350 2322 // construct relative sphere center with now known CircleCenter 2351 RelativeSphereCenter.CopyVector(&T.SphereCenter); 2352 RelativeSphereCenter.SubtractVector(&CircleCenter); 2323 RelativeSphereCenter = T.SphereCenter - CircleCenter; 2353 2324 2354 2325 CircleRadius = RADIUS*RADIUS - radius/4.; … … 2360 2331 // construct SearchDirection and an "outward pointer" 2361 2332 SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal(); 2362 helper.CopyVector(&CircleCenter); 2363 helper.SubtractVector(ThirdNode->node); 2364 if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2333 helper = CircleCenter - (*ThirdNode->node); 2334 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2365 2335 SearchDirection.Scale(-1.); 2366 2336 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 2367 if (fabs(RelativeSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) {2337 if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { 2368 2338 // rotated the wrong way! 2369 2339 eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl; … … 2512 2482 AddTesselationTriangle(); 2513 2483 BTS->GetCenter(&Center); 2514 Center .SubtractVector(&CandidateLine.OptCenter);2515 BTS->SphereCenter .CopyVector(&CandidateLine.OptCenter);2484 Center -= CandidateLine.OptCenter; 2485 BTS->SphereCenter = CandidateLine.OptCenter; 2516 2486 BTS->GetNormalVector(Center); 2517 2487 … … 2559 2529 Vector DistanceToIntersection[2], BaseLine; 2560 2530 double distance[2]; 2561 BaseLine.CopyVector(Base->endpoints[1]->node->node); 2562 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 2531 BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node); 2563 2532 for (int i=0;i<2;i++) { 2564 DistanceToIntersection[i].CopyVector(ClosestPoint); 2565 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 2566 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 2533 DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node); 2534 distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]); 2567 2535 } 2568 2536 delete(ClosestPoint); … … 2636 2604 2637 2605 // get the distance vector from Base line to OtherBase line 2638 Vector Distance; 2639 Distance.CopyVector(ClosestPoint[1]); 2640 Distance.SubtractVector(ClosestPoint[0]); 2606 Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]); 2641 2607 2642 2608 // calculate volume … … 2660 2626 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2661 2627 Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl; 2662 BaseLineNormal .AddVector(&(runner->second->NormalVector));2628 BaseLineNormal += (runner->second->NormalVector); 2663 2629 } 2664 2630 BaseLineNormal.Scale(1./2.); 2665 2631 2666 if (Distance.ScalarProduct( &BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip2632 if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip 2667 2633 Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl; 2668 2634 // calculate volume summand as a general tetraeder … … 2699 2665 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2700 2666 Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl; 2701 BaseLineNormal .AddVector(&(runner->second->NormalVector));2667 BaseLineNormal += (runner->second->NormalVector); 2702 2668 } 2703 2669 BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector() … … 2840 2806 double distance, scaleFactor; 2841 2807 2842 OrthogonalizedOben.CopyVector(&Oben); 2843 aCandidate.CopyVector(a->node); 2844 aCandidate.SubtractVector(Candidate->node); 2845 OrthogonalizedOben.ProjectOntoPlane(&aCandidate); 2808 OrthogonalizedOben = Oben; 2809 aCandidate = (*a->node) - (*Candidate->node); 2810 OrthogonalizedOben.ProjectOntoPlane(aCandidate); 2846 2811 OrthogonalizedOben.Normalize(); 2847 2812 distance = 0.5 * aCandidate.Norm(); … … 2849 2814 OrthogonalizedOben.Scale(scaleFactor); 2850 2815 2851 Center.CopyVector(Candidate->node); 2852 Center.AddVector(a->node); 2853 Center.Scale(0.5); 2854 Center.AddVector(&OrthogonalizedOben); 2855 2856 AngleCheck.CopyVector(&Center); 2857 AngleCheck.SubtractVector(a->node); 2816 Center = 0.5 * ((*Candidate->node) + (*a->node)); 2817 Center += OrthogonalizedOben; 2818 2819 AngleCheck = Center - (*a->node); 2858 2820 norm = aCandidate.Norm(); 2859 2821 // second point shall have smallest angle with respect to Oben vector 2860 2822 if (norm < RADIUS*2.) { 2861 angle = AngleCheck.Angle( &Oben);2823 angle = AngleCheck.Angle(Oben); 2862 2824 if (angle < Storage[0]) { 2863 2825 //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]); … … 2935 2897 2936 2898 // construct center of circle 2937 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2938 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2939 CircleCenter.Scale(0.5); 2899 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 2900 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 2940 2901 2941 2902 // construct normal vector of circle 2942 CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2943 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2944 2945 RelativeOldSphereCenter.CopyVector(&OldSphereCenter); 2946 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 2903 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 2904 (*CandidateLine.BaseLine->endpoints[1]->node->node); 2905 2906 RelativeOldSphereCenter = OldSphereCenter - CircleCenter; 2947 2907 2948 2908 // calculate squared radius TesselPoint *ThirdNode,f circle … … 2954 2914 2955 2915 // test whether old center is on the band's plane 2956 if (fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) > HULLEPSILON) {2957 eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) << "!" << endl;2958 RelativeOldSphereCenter.ProjectOntoPlane( &CirclePlaneNormal);2916 if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) { 2917 eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl; 2918 RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal); 2959 2919 } 2960 2920 radius = RelativeOldSphereCenter.NormSquared(); … … 2964 2924 // check SearchDirection 2965 2925 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 2966 if (fabs(RelativeOldSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) { // rotated the wrong way!2926 if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way! 2967 2927 eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl; 2968 2928 } … … 3011 2971 3012 2972 Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl; 3013 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared( &NewPlaneCenter);2973 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter); 3014 2974 Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl; 3015 2975 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 3016 2976 Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl; 3017 2977 if (radius < RADIUS*RADIUS) { 3018 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared( &NewPlaneCenter);2978 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter); 3019 2979 if (fabs(radius - otherradius) > HULLEPSILON) { 3020 2980 eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl; 3021 2981 } 3022 2982 // construct both new centers 3023 NewSphereCenter.CopyVector(&NewPlaneCenter); 3024 OtherNewSphereCenter.CopyVector(&NewPlaneCenter); 3025 helper.CopyVector(&NewNormalVector); 3026 helper.Scale(sqrt(RADIUS*RADIUS - radius)); 2983 NewSphereCenter = NewPlaneCenter; 2984 OtherNewSphereCenter = NewPlaneCenter; 2985 helper = sqrt(RADIUS*RADIUS - radius) * NewNormalVector; 3027 2986 Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl; 3028 NewSphereCenter .AddVector(&helper);2987 NewSphereCenter += helper; 3029 2988 Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl; 3030 2989 // OtherNewSphereCenter is created by the same vector just in the other direction 3031 2990 helper.Scale(-1.); 3032 OtherNewSphereCenter .AddVector(&helper);2991 OtherNewSphereCenter += helper; 3033 2992 Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl; 3034 2993 … … 3041 3000 if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) { 3042 3001 if (fabs(alpha - Otheralpha) > MYEPSILON) { 3043 CandidateLine.OptCenter .CopyVector(&NewSphereCenter);3044 CandidateLine.OtherOptCenter .CopyVector(&OtherNewSphereCenter);3002 CandidateLine.OptCenter = NewSphereCenter; 3003 CandidateLine.OtherOptCenter = OtherNewSphereCenter; 3045 3004 } else { 3046 CandidateLine.OptCenter .CopyVector(&OtherNewSphereCenter);3047 CandidateLine.OtherOptCenter .CopyVector(&NewSphereCenter);3005 CandidateLine.OptCenter = OtherNewSphereCenter; 3006 CandidateLine.OtherOptCenter = NewSphereCenter; 3048 3007 } 3049 3008 // if there is an equal candidate, add it to the list without clearing the list … … 3168 3127 FindPoint = PointsOnBoundary.find((*Runner)->nr); 3169 3128 if (FindPoint != PointsOnBoundary.end()) { 3170 points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared( x), FindPoint->second) );3129 points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second) ); 3171 3130 Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl; 3172 3131 } … … 3212 3171 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3213 3172 // calculate closest point on line to desired point 3214 helper.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3215 helper.AddVector((LineRunner->second)->endpoints[1]->node->node); 3216 helper.Scale(0.5); 3217 Center.CopyVector(x); 3218 Center.SubtractVector(&helper); 3219 BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3220 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3221 Center.ProjectOntoPlane(&BaseLine); 3173 helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) + 3174 (*(LineRunner->second)->endpoints[1]->node->node)); 3175 Center = (*x) - helper; 3176 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3177 (*(LineRunner->second)->endpoints[1]->node->node); 3178 Center.ProjectOntoPlane(BaseLine); 3222 3179 const double distance = Center.NormSquared(); 3223 3180 if ((ClosestLine == NULL) || (distance < MinDistance)) { 3224 3181 // additionally calculate intersection on line (whether it's on the line section or not) 3225 helper.CopyVector(x); 3226 helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3227 helper.SubtractVector(&Center); 3228 const double lengthA = helper.ScalarProduct(&BaseLine); 3229 helper.CopyVector(x); 3230 helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3231 helper.SubtractVector(&Center); 3232 const double lengthB = helper.ScalarProduct(&BaseLine); 3182 helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center; 3183 const double lengthA = helper.ScalarProduct(BaseLine); 3184 helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center; 3185 const double lengthB = helper.ScalarProduct(BaseLine); 3233 3186 if (lengthB*lengthA < 0) { // if have different sign 3234 3187 ClosestLine = LineRunner->second; … … 3280 3233 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3281 3234 3282 BaseLine .CopyVector((LineRunner->second)->endpoints[0]->node->node);3283 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);3235 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3236 (*(LineRunner->second)->endpoints[1]->node->node); 3284 3237 const double lengthBase = BaseLine.NormSquared(); 3285 3238 3286 BaseLineIntersection.CopyVector(x); 3287 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3239 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node); 3288 3240 const double lengthEndA = BaseLineIntersection.NormSquared(); 3289 3241 3290 BaseLineIntersection.CopyVector(x); 3291 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3242 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3292 3243 const double lengthEndB = BaseLineIntersection.NormSquared(); 3293 3244 … … 3307 3258 } else { // intersection is closer, calculate 3308 3259 // calculate closest point on line to desired point 3309 BaseLineIntersection.CopyVector(x); 3310 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3311 Center.CopyVector(&BaseLineIntersection); 3312 Center.ProjectOntoPlane(&BaseLine); 3313 BaseLineIntersection.SubtractVector(&Center); 3260 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3261 Center = BaseLineIntersection; 3262 Center.ProjectOntoPlane(BaseLine); 3263 BaseLineIntersection -= Center; 3314 3264 const double distance = BaseLineIntersection.NormSquared(); 3315 3265 if (Center.NormSquared() > BaseLine.NormSquared()) { … … 3363 3313 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) { 3364 3314 (*Runner)->GetCenter(&Center); 3365 helper.CopyVector(x); 3366 helper.SubtractVector(&Center); 3367 const double Alignment = helper.Angle(&(*Runner)->NormalVector); 3315 helper = (*x) - Center; 3316 const double Alignment = helper.Angle((*Runner)->NormalVector); 3368 3317 if (Alignment < MinAlignment) { 3369 3318 result = *Runner; … … 3427 3376 triangle->GetCenter(&Center); 3428 3377 Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl; 3429 DistanceToCenter.CopyVector(&Center); 3430 DistanceToCenter.SubtractVector(&Point); 3378 DistanceToCenter = Center - Point; 3431 3379 Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl; 3432 3380 3433 3381 // check whether we are on boundary 3434 if (fabs(DistanceToCenter.ScalarProduct( &triangle->NormalVector)) < MYEPSILON) {3382 if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) { 3435 3383 // calculate whether inside of triangle 3436 DistanceToCenter.CopyVector(&Point); 3437 Center.CopyVector(&Point); 3438 Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter 3439 DistanceToCenter.AddVector(&triangle->NormalVector); // points outside 3384 DistanceToCenter = Point + triangle->NormalVector; // points outside 3385 Center = Point - triangle->NormalVector; // points towards MolCenter 3440 3386 Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl; 3441 3387 if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) { … … 3452 3398 3453 3399 // then check direction to boundary 3454 if (DistanceToCenter.ScalarProduct( &triangle->NormalVector) > MYEPSILON) {3400 if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) { 3455 3401 Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl; 3456 3402 return -distance; … … 3568 3514 if ((triangles != NULL) && (!triangles->empty())) { 3569 3515 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) 3570 PlaneNormal .AddVector(&(*Runner)->NormalVector);3516 PlaneNormal += (*Runner)->NormalVector; 3571 3517 } else { 3572 3518 eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl; … … 3579 3525 // construct one orthogonal vector 3580 3526 if (Reference != NULL) { 3581 AngleZero.CopyVector(Reference); 3582 AngleZero.SubtractVector(Point->node); 3583 AngleZero.ProjectOntoPlane(&PlaneNormal); 3527 AngleZero = (*Reference) - (*Point->node); 3528 AngleZero.ProjectOntoPlane(PlaneNormal); 3584 3529 } 3585 3530 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) { 3586 3531 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl; 3587 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3588 AngleZero.SubtractVector(Point->node); 3589 AngleZero.ProjectOntoPlane(&PlaneNormal); 3532 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3533 AngleZero.ProjectOntoPlane(PlaneNormal); 3590 3534 if (AngleZero.NormSquared() < MYEPSILON) { 3591 3535 eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl; … … 3602 3546 // go through all connected points and calculate angle 3603 3547 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3604 helper.CopyVector((*listRunner)->node); 3605 helper.SubtractVector(Point->node); 3606 helper.ProjectOntoPlane(&PlaneNormal); 3548 helper = (*(*listRunner)->node) - (*Point->node); 3549 helper.ProjectOntoPlane(PlaneNormal); 3607 3550 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3608 3551 Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl; … … 3671 3614 TesselB++; 3672 3615 TesselC++; 3673 PlaneNormal .AddVector(&helper);3616 PlaneNormal += helper; 3674 3617 } 3675 3618 //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size() … … 3686 3629 // construct one orthogonal vector 3687 3630 if (Reference != NULL) { 3688 AngleZero.CopyVector(Reference); 3689 AngleZero.SubtractVector(Point->node); 3690 AngleZero.ProjectOntoPlane(&PlaneNormal); 3631 AngleZero = (*Reference) - (*Point->node); 3632 AngleZero.ProjectOntoPlane(PlaneNormal); 3691 3633 } 3692 3634 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) { 3693 3635 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl; 3694 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3695 AngleZero.SubtractVector(Point->node); 3696 AngleZero.ProjectOntoPlane(&PlaneNormal); 3636 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3637 AngleZero.ProjectOntoPlane(PlaneNormal); 3697 3638 if (AngleZero.NormSquared() < MYEPSILON) { 3698 3639 eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl; … … 3710 3651 pair <map<double, TesselPoint*>::iterator, bool > InserterTest; 3711 3652 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3712 helper.CopyVector((*listRunner)->node); 3713 helper.SubtractVector(Point->node); 3714 helper.ProjectOntoPlane(&PlaneNormal); 3653 helper = (*(*listRunner)->node) - (*Point->node); 3654 helper.ProjectOntoPlane(PlaneNormal); 3715 3655 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3716 3656 if (angle > M_PI) // the correction is of no use here (and not desired) … … 3959 3899 3960 3900 // copy old location for the volume 3961 OldPoint .CopyVector(point->node->node);3901 OldPoint = (*point->node->node); 3962 3902 3963 3903 // get list of connected points … … 3987 3927 for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { 3988 3928 Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl; 3989 NormalVector .SubtractVector(&Runner->second->NormalVector); // has to point inward3929 NormalVector -= Runner->second->NormalVector; // has to point inward 3990 3930 RemoveTesselationTriangle(Runner->second); 3991 3931 count++; … … 4023 3963 StartNode--; 4024 3964 //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl; 4025 Point.CopyVector((*StartNode)->node); 4026 Point.SubtractVector((*MiddleNode)->node); 3965 Point = (*(*StartNode)->node) - (*(*MiddleNode)->node); 4027 3966 StartNode = MiddleNode; 4028 3967 StartNode++; … … 4030 3969 StartNode = connectedPath->begin(); 4031 3970 //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl; 4032 Reference.CopyVector((*StartNode)->node); 4033 Reference.SubtractVector((*MiddleNode)->node); 4034 OrthogonalVector.CopyVector((*MiddleNode)->node); 4035 OrthogonalVector.SubtractVector(&OldPoint); 3971 Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node); 3972 OrthogonalVector = (*(*MiddleNode)->node) - OldPoint; 4036 3973 OrthogonalVector.MakeNormalTo(Reference); 4037 3974 angle = GetAngle(Point, Reference, OrthogonalVector); … … 4502 4439 class BoundaryLineSet *BestLine = NULL; 4503 4440 for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) { 4504 BaseLine.CopyVector(Runner->second->endpoints[0]->node->node); 4505 BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node); 4506 CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node); 4507 CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node); 4508 CenterToPoint.Scale(0.5); 4509 CenterToPoint.SubtractVector(point->node); 4510 angle = CenterToPoint.Angle(&BaseLine); 4441 BaseLine = (*Runner->second->endpoints[0]->node->node) - 4442 (*Runner->second->endpoints[1]->node->node); 4443 CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) + 4444 (*Runner->second->endpoints[1]->node->node)); 4445 CenterToPoint -= (*point->node); 4446 angle = CenterToPoint.Angle(BaseLine); 4511 4447 if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) { 4512 4448 BestAngle = angle; … … 4672 4608 for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) 4673 4609 if (VectorWalker != VectorRunner) { // skip equals 4674 const double SCP = VectorWalker->second->ScalarProduct( VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles4610 const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles 4675 4611 Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl; 4676 4612 if (fabs(SCP + 1.) < ParallelEpsilon) { … … 4758 4694 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 4759 4695 /// 4a. Get NormalVector for one side (this is "front") 4760 NormalVector .CopyVector(&(*TriangleWalker)->NormalVector);4696 NormalVector = (*TriangleWalker)->NormalVector; 4761 4697 Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl; 4762 4698 TriangleWalker++; … … 4769 4705 TriangleSprinter++; 4770 4706 Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl; 4771 if (triangle->NormalVector.ScalarProduct( &NormalVector) < 0) { // if from other side, then delete and remove from list4707 if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list 4772 4708 Log() << Verbose(1) << " Removing ... " << endl; 4773 4709 TriangleNrs.push(triangle->Nr); … … 4791 4727 AddTesselationTriangle(); // ... and add 4792 4728 TriangleNrs.pop(); 4793 BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector); 4794 BTS->NormalVector.Scale(-1.); 4729 BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector; 4795 4730 TriangleWalker++; 4796 4731 }
Note:
See TracChangeset
for help on using the changeset viewer.
