Changeset 71910a for molecuilder/src/tesselation.cpp
- Timestamp:
- Apr 7, 2010, 3:45:38 PM (15 years ago)
- Children:
- 0f55b2
- Parents:
- 770138
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/tesselation.cpp
r770138 r71910a 15 15 #include "tesselationhelpers.hpp" 16 16 #include "vector.hpp" 17 #include "vector_ops.hpp" 17 18 #include "verbose.hpp" 19 #include "Plane.hpp" 20 #include "Exceptions/LinearDependenceException.hpp" 18 21 19 22 class molecule; … … 258 261 helper[i].CopyVector(node->node->node); 259 262 helper[i].SubtractVector(&BaseLineCenter); 260 helper[i].MakeNormal Vector(&BaseLine); // we want to compare the triangle's heights' angles!263 helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles! 261 264 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 262 265 i++; … … 402 405 Info FunctionInfo(__func__); 403 406 // get normal vector 404 NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node); 407 NormalVector = Plane(*(endpoints[0]->node->node), 408 *(endpoints[1]->node->node), 409 *(endpoints[2]->node->node)).getNormal(); 405 410 406 411 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) … … 428 433 Vector helper; 429 434 430 if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) { 435 try { 436 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x); 437 } 438 catch (LinearDependenceException &excp) { 439 Log() << Verbose(1) << excp; 431 440 eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl; 432 441 return false; … … 450 459 int i=0; 451 460 do { 452 if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) { 461 try { 462 CrossPoint = GetIntersectionOfTwoLinesOnPlane(*(endpoints[i%3]->node->node), 463 *(endpoints[(i+1)%3]->node->node), 464 *(endpoints[(i+2)%3]->node->node), 465 *Intersection); 453 466 helper.CopyVector(endpoints[(i+1)%3]->node->node); 454 467 helper.SubtractVector(endpoints[i%3]->node->node); … … 462 475 } 463 476 i++; 464 } else477 } catch (LinearDependenceException &excp){ 465 478 break; 479 } 466 480 } while (i<3); 467 481 if (i==3) { … … 492 506 Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl; 493 507 GetCenter(&Direction); 494 if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) { 508 try { 509 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction); 510 } 511 catch (LinearDependenceException &excp) { 495 512 ClosestPoint->CopyVector(x); 496 513 } … … 518 535 Direction.SubtractVector(endpoints[i%3]->node->node); 519 536 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 520 CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node); 537 538 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 539 521 540 CrossDirection[i].CopyVector(&CrossPoint[i]); 522 541 CrossDirection[i].SubtractVector(&InPlane); … … 731 750 int counter=0; 732 751 for (; Runner[2] != endpoints.end(); ) { 733 TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node); 752 TemporaryNormal = Plane(*((*Runner[0])->node->node), 753 *((*Runner[1])->node->node), 754 *((*Runner[2])->node->node)).getNormal(); 734 755 for (int i=0;i<3;i++) // increase each of them 735 756 Runner[i]++; … … 1220 1241 // 2. next, we have to check whether all points reside on only one side of the triangle 1221 1242 // 3. construct plane vector 1222 PlaneVector .MakeNormalVector(A->second->node->node,1223 baseline->second.first->second->node->node,1224 baseline->second.second->second->node->node);1243 PlaneVector = Plane(*(A->second->node->node), 1244 *(baseline->second.first->second->node->node), 1245 *(baseline->second.second->second->node->node)).getNormal(); 1225 1246 Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl; 1226 1247 // 4. loop over all points … … 1391 1412 // vector in propagation direction (out of triangle) 1392 1413 // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection) 1393 PropagationVector .MakeNormalVector(&BaseLine, &NormalVector);1414 PropagationVector = Plane(BaseLine, NormalVector,0).getNormal(); 1394 1415 TempVector.CopyVector(&CenterVector); 1395 1416 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! … … 1448 1469 // in case NOT both were found, create virtually this triangle, get its normal vector, calculate angle 1449 1470 flag = true; 1450 VirtualNormalVector.MakeNormalVector(baseline->second->endpoints[0]->node->node, baseline->second->endpoints[1]->node->node, target->second->node->node); 1471 VirtualNormalVector = Plane(*(baseline->second->endpoints[0]->node->node), 1472 *(baseline->second->endpoints[1]->node->node), 1473 *(target->second->node->node)).getNormal(); 1451 1474 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1452 1475 TempVector.AddVector(baseline->second->endpoints[1]->node->node); … … 2063 2086 if (List != NULL) { 2064 2087 for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) { 2065 if ((*Runner)->node-> x[i]> maxCoordinate[i]) {2088 if ((*Runner)->node->at(i) > maxCoordinate[i]) { 2066 2089 Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl; 2067 maxCoordinate[i] = (*Runner)->node-> x[i];2090 maxCoordinate[i] = (*Runner)->node->at(i); 2068 2091 MaxPoint[i] = (*Runner); 2069 2092 } … … 2083 2106 for (int k=0;k<NDIM;k++) { 2084 2107 NormalVector.Zero(); 2085 NormalVector .x[k] = 1.;2108 NormalVector[k] = 1.; 2086 2109 BaseLine.endpoints[0] = new BoundaryPointSet(MaxPoint[k]); 2087 2110 Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine.endpoints[0]->node << "." << endl; … … 2117 2140 2118 2141 // look in one direction of baseline for initial candidate 2119 SearchDirection .MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...2142 SearchDirection = Plane(CirclePlaneNormal, NormalVector,0).getNormal(); // whether we look "left" first or "right" first is not important ... 2120 2143 2121 2144 // adding point 1 and point 2 and add the line between them … … 2336 2359 2337 2360 // construct SearchDirection and an "outward pointer" 2338 SearchDirection .MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);2361 SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal(); 2339 2362 helper.CopyVector(&CircleCenter); 2340 2363 helper.SubtractVector(ThirdNode->node); … … 2979 3002 Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl; 2980 3003 2981 if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) 2982 && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON) 2983 ) { 3004 try { 3005 NewNormalVector = Plane(*(CandidateLine.BaseLine->endpoints[0]->node->node), 3006 *(CandidateLine.BaseLine->endpoints[1]->node->node), 3007 *(Candidate->node)).getNormal(); 3008 3009 if(!fabs(NewNormalVector.NormSquared()) > HULLEPSILON) 3010 throw LinearDependenceException(__FILE__,__LINE__); 3011 2984 3012 Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl; 2985 3013 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter); … … 3043 3071 Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl; 3044 3072 } 3045 } else { 3073 } 3074 catch (LinearDependenceException &excp){ 3075 Log() << Verbose(1) << excp; 3046 3076 Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl; 3047 3077 } … … 3565 3595 Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl; 3566 3596 if (AngleZero.NormSquared() > MYEPSILON) 3567 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3597 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3568 3598 else 3569 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3599 OrthogonalVector.MakeNormalTo(PlaneNormal); 3570 3600 Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl; 3571 3601 … … 3633 3663 int counter = 0; 3634 3664 while (TesselC != SetOfNeighbours->end()) { 3635 helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node); 3665 helper = Plane(*((*TesselA)->node), 3666 *((*TesselB)->node), 3667 *((*TesselC)->node)).getNormal(); 3636 3668 Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl; 3637 3669 counter++; … … 3670 3702 Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl; 3671 3703 if (AngleZero.NormSquared() > MYEPSILON) 3672 OrthogonalVector .MakeNormalVector(&PlaneNormal, &AngleZero);3704 OrthogonalVector = Plane(PlaneNormal, AngleZero,0).getNormal(); 3673 3705 else 3674 OrthogonalVector.MakeNormal Vector(&PlaneNormal);3706 OrthogonalVector.MakeNormalTo(PlaneNormal); 3675 3707 Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl; 3676 3708 … … 4002 4034 OrthogonalVector.CopyVector((*MiddleNode)->node); 4003 4035 OrthogonalVector.SubtractVector(&OldPoint); 4004 OrthogonalVector.MakeNormal Vector(&Reference);4036 OrthogonalVector.MakeNormalTo(Reference); 4005 4037 angle = GetAngle(Point, Reference, OrthogonalVector); 4006 4038 //if (angle < M_PI) // no wrong-sided triangles, please?
Note:
See TracChangeset
for help on using the changeset viewer.