MCPcopy Create free account
hub / github.com/Kitware/VTK / InterpolateFunctionsUsingMVC

Method InterpolateFunctionsUsingMVC

Common/DataModel/vtkPolygon.cxx:524–622  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Compute interpolation weights using mean value coordinate.

Source from the content-addressed store, hash-verified

522//------------------------------------------------------------------------------
523// Compute interpolation weights using mean value coordinate.
524void vtkPolygon::InterpolateFunctionsUsingMVC(const double x[3], double* weights)
525{
526 int numPts = this->Points->GetNumberOfPoints();
527
528 // Begin by initializing weights.
529 for (int i = 0; i < numPts; i++)
530 {
531 weights[i] = 0.0;
532 }
533
534 // create local array for storing point-to-vertex vectors and distances
535 std::vector<double> dist(numPts);
536 std::vector<double> uVec(3 * numPts);
537 static const double eps = 0.00000001;
538 for (int i = 0; i < numPts; i++)
539 {
540 double pt[3];
541 this->Points->GetPoint(i, pt);
542
543 // point-to-vertex vector
544 uVec[3 * i] = pt[0] - x[0];
545 uVec[3 * i + 1] = pt[1] - x[1];
546 uVec[3 * i + 2] = pt[2] - x[2];
547
548 // distance
549 dist[i] = vtkMath::Norm(uVec.data() + 3 * i);
550
551 // handle special case when the point is really close to a vertex
552 if (dist[i] < eps)
553 {
554 weights[i] = 1.0;
555 return;
556 }
557
558 uVec[3 * i] /= dist[i];
559 uVec[3 * i + 1] /= dist[i];
560 uVec[3 * i + 2] /= dist[i];
561 }
562
563 // Now loop over all vertices to compute weight
564 // w_i = ( tan(theta_i/2) + tan(theta_(i+1)/2) ) / dist_i
565 // To do consider the simplification of
566 // tan(alpha/2) = (1-cos(alpha))/sin(alpha)
567 // = (d0*d1 - cross(u0, u1))/(2*dot(u0,u1))
568 std::vector<double> tanHalfTheta(numPts);
569 for (int i = 0; i < numPts; i++)
570 {
571 int i1 = i + 1;
572 if (i1 == numPts)
573 {
574 i1 = 0;
575 }
576
577 double* u0 = uVec.data() + 3 * i;
578 double* u1 = uVec.data() + 3 * i1;
579
580 double l = sqrt(vtkMath::Distance2BetweenPoints(u0, u1));
581 double theta = 2.0 * asin(l / 2.0);

Callers 1

InterpolateFunctionsMethod · 0.95

Calls 8

PiFunction · 0.85
NormFunction · 0.70
sqrtFunction · 0.50
asinFunction · 0.50
tanFunction · 0.50
GetNumberOfPointsMethod · 0.45
GetPointMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected