mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Fixes for polyline parameterization.
This commit is contained in:
parent
489995782f
commit
83cf50d549
@ -695,27 +695,7 @@ WorldCoordinatesToParametricCoordinates(const WorldCoordVector& pointWCoords,
|
||||
pointWCoords, wcoords, vtkm::CellShapeTagLine(), success, worklet);
|
||||
}
|
||||
|
||||
vtkm::IdComponent idx = 0;
|
||||
vtkm::FloatDefault minDistSq = vtkm::Dot(pointWCoords[0], wcoords);
|
||||
for (vtkm::IdComponent i = 1; i < numPoints; i++)
|
||||
{
|
||||
vtkm::FloatDefault d = vtkm::Dot(pointWCoords[i], wcoords);
|
||||
if (d < minDistSq)
|
||||
{
|
||||
idx = i;
|
||||
minDistSq = d;
|
||||
}
|
||||
}
|
||||
if (idx == 0)
|
||||
idx = 1;
|
||||
|
||||
using Vector3 = typename WorldCoordVector::ComponentType;
|
||||
using T = typename Vector3::ComponentType;
|
||||
|
||||
Vector3 vec = pointWCoords[idx] - pointWCoords[idx - 1];
|
||||
T numerator = vtkm::Dot(vec, wcoords - pointWCoords[idx - 1]);
|
||||
T denominator = vtkm::MagnitudeSquared(vec);
|
||||
|
||||
std::cout << std::endl << std::endl;
|
||||
std::cout << "worldCoordsToParam:" << std::endl;
|
||||
std::cout << " PointWcoords= (";
|
||||
for (int i = 0; i < numPoints; i++)
|
||||
@ -723,39 +703,61 @@ WorldCoordinatesToParametricCoordinates(const WorldCoordVector& pointWCoords,
|
||||
std::cout << ")" << std::endl;
|
||||
std::cout << "wCoords= " << wcoords << std::endl;
|
||||
|
||||
std::cout << "idx= " << idx << std::endl;
|
||||
std::cout << "Param= " << Vector3(numerator / denominator, 0, 0) << std::endl;
|
||||
|
||||
return Vector3(numerator / denominator, 0, 0);
|
||||
|
||||
#if 0
|
||||
std::cout<<"worldCoordsToParam:"<<std::endl;
|
||||
std::cout<<" PointWcoords= (";
|
||||
for (int i = 0; i < numPoints; i++) std::cout<<pointWCoords[i]<<" ";
|
||||
std::cout<<")"<<std::endl;
|
||||
|
||||
std::cout<<"wCoords= "<<wcoords<<std::endl;
|
||||
|
||||
success = true;
|
||||
using Vector3 = typename WorldCoordVector::ComponentType;
|
||||
|
||||
return Vector3(0,0,0);
|
||||
#endif
|
||||
/*
|
||||
vtkm::FloatDefault dt = 1/static_cast<vtkm::FloatDefault>(numPoints-1);
|
||||
vtkm::IdComponent idx = 1; //static_cast<vtkm::IdComponent>(pcoords[0]/dt);
|
||||
if (idx == 0)
|
||||
idx = 1;
|
||||
|
||||
using Vector3 = typename WorldCoordVector::ComponentType;
|
||||
using T = typename Vector3::ComponentType;
|
||||
|
||||
Vector3 vec = pointWCoords[idx] - pointWCoords[idx-1];
|
||||
T numerator = vtkm::Dot(vec, wcoords - pointWCoords[idx-1]);
|
||||
T denominator = vtkm::MagnitudeSquared(vec);
|
||||
//Find the closest vertex to the point.
|
||||
vtkm::IdComponent idx = 0;
|
||||
Vector3 vec = pointWCoords[0] - wcoords;
|
||||
T minDistSq = vtkm::Dot(vec, vec);
|
||||
std::cout << "Find idx: " << std::endl;
|
||||
std::cout << " idx: " << idx << " " << minDistSq << std::endl;
|
||||
for (vtkm::IdComponent i = 1; i < numPoints; i++)
|
||||
{
|
||||
vec = pointWCoords[i] - wcoords;
|
||||
T d = vtkm::Dot(vec, vec);
|
||||
std::cout << " idx: " << i << " " << d << " " << pointWCoords[i] << " " << wcoords
|
||||
<< std::endl;
|
||||
|
||||
return Vector3(numerator / denominator, 0, 0);
|
||||
*/
|
||||
if (d < minDistSq)
|
||||
{
|
||||
idx = i;
|
||||
minDistSq = d;
|
||||
}
|
||||
}
|
||||
|
||||
//Find the right segment, and the parameterization along that segment.
|
||||
//Closest to 0, so segment is (0,1)
|
||||
if (idx == 0)
|
||||
idx = 1;
|
||||
|
||||
//Find the pt projection onto the line segment at points idx and idx-1.
|
||||
vec = pointWCoords[idx] - pointWCoords[idx - 1];
|
||||
T numerator = vtkm::Dot(vec, wcoords - pointWCoords[idx - 1]);
|
||||
T denominator = vtkm::MagnitudeSquared(vec);
|
||||
T segmentParam = numerator / denominator;
|
||||
|
||||
std::cout << "segment: " << idx - 1 << " " << idx << " p= " << segmentParam << std::endl;
|
||||
//The point is on the OTHER side of idx. If there is a next segment reparam onto it.
|
||||
if (segmentParam > 1 && idx < numPoints - 1)
|
||||
{
|
||||
idx = idx + 1;
|
||||
vec = pointWCoords[idx] - pointWCoords[idx - 1];
|
||||
numerator = vtkm::Dot(vec, wcoords - pointWCoords[idx - 1]);
|
||||
denominator = vtkm::MagnitudeSquared(vec);
|
||||
segmentParam = numerator / denominator;
|
||||
std::cout << " +++ segment: " << idx - 1 << " " << idx << " p= " << segmentParam << std::endl;
|
||||
}
|
||||
|
||||
//Segment param is [0,1] on that segment.
|
||||
//Map that onto the param for the entire segment.
|
||||
T dParam = static_cast<T>(1) / static_cast<T>(numPoints - 1);
|
||||
T polyLineParam = static_cast<T>(idx - 1) * dParam + segmentParam * dParam;
|
||||
|
||||
std::cout << "idx= " << idx << " dParam= " << dParam << std::endl;
|
||||
std::cout << "Param= " << Vector3(polyLineParam, 0, 0) << std::endl;
|
||||
|
||||
return Vector3(polyLineParam, 0, 0);
|
||||
}
|
||||
|
||||
template <typename WorldCoordVector>
|
||||
|
Loading…
Reference in New Issue
Block a user