[vtkusers] how to compute the length of spline?
Jorge Perez
josp.jorge at gmail.com
Tue Nov 4 04:13:13 EST 2014
Hello, you can use a vtkParametricFunctionSource to sample the parametric
spline and then add the length of the linear segments. You can see how it
can be done by inspecting the method vtkSplineWidget::GetSummedLength at
source code vtkSplineWidget.cxx
double vtkSplineWidget::GetSummedLength()
{
vtkPoints* points =
this->ParametricFunctionSource->GetOutput()->GetPoints();
int npts = points->GetNumberOfPoints();
if ( npts < 2 ) { return 0.0; }
double a[3];
double b[3];
double sum = 0.0;
int i = 0;
points->GetPoint(i, a);
int imax = (npts%2 == 0) ? npts-2 : npts-1;
while ( i < imax )
{
points->GetPoint(i+1, b);
sum += sqrt(vtkMath::Distance2BetweenPoints(a, b));
i = i + 2;
points->GetPoint(i, a);
sum = sum + sqrt(vtkMath::Distance2BetweenPoints(a, b));
}
if ( npts%2 == 0 )
{
points->GetPoint(i+1, b);
sum += sqrt(vtkMath::Distance2BetweenPoints(a, b));
}
return sum;
}
2014-11-01 5:05 GMT+01:00 just_rookie <925345468 at qq.com>:
> Hi all,
>
> I have used the vtkParametricSpline class to get a spline, and my next step
> is to compute the length of the spline, any help? Thank you in advance!
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/how-to-compute-the-length-of-spline-tp5729305.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141104/8d67ad11/attachment.html>
More information about the vtkusers
mailing list