[vtkusers] vtkParametricSpline and vtkParametricFunctionSource
Anja Ende
anja.ende at googlemail.com
Fri Nov 10 11:53:35 EST 2006
Hi Dean,
Thanks for the reply!
I had looked at it but had got a bit confused with the following lines:
x = (1.0 - u[0])*x0 + u[0]*x1;
y = (1.0 - u[0])*y0 + u[0]*y1;
z = (1.0 - u[0])*z0 + u[0]*z1;
But it is great to know that they can be used with any values. Perfect!
Thanks again.
Anja
On 10/11/06, Dean Inglis <dean.inglis at sympatico.ca> wrote:
>
> Anja,
>
> have a look at the code snippet taken from vtkSplineWidget below.
> Pass your screen coordinates as is (or any other type of points) to the
> vtkParametricSpline: these are your "handles" or control points: no need
> to normalize. You control how many points to generate along the spline
> with
> the
> Resolution term. For a single line between control point pairs,
> set resolution to be numberOfControlPoints - 1.
>
> Dean
>
> Hi everyone,
>
> I have a question about the usage of vtkParametricSpline and
> vtkParametricSource. What I want to do is use Qt to draw a spline through
> some selected points on my image. I think the combination of
> vtkParametricSpline and vtkParametricFunctionSource can do what I want to
> achieve.
>
> Now, I acquire the control points coordinates through the mouse events and
> these are integers. What I would like to do is calculate the spline using
> these values. I noticed that the documentation for the vtkParametricSpline
> mentions:
> "This family of 1D splines is quaranteed to be parameterized in the
> interval
> [0,1]. Attempting to evaluate outside this interval will cause the
> parameter
> u to be clamped in the range [0,1]."
>
> I was wondering if I could pass the screen coordinates as input points to
> the spline or does everything has to be normalized between 0 and 1. I
> think
> working with integers would be faster and I would like to avoid the
> unnecessary conversions back and forth...
>
> Thanks and cheers,
>
> Anja
>
> vtkPoints* points = vtkPoints::New(VTK_DOUBLE);
> points->SetNumberOfPoints(this->NumberOfHandles);
>
> for ( i = 0; i < this->NumberOfHandles; ++i )
> {
> this->HandleGeometry[i] = vtkSphereSource::New();
> this->HandleGeometry[i]->SetThetaResolution(16);
> this->HandleGeometry[i]->SetPhiResolution(8);
> vtkPolyDataMapper* handleMapper = vtkPolyDataMapper::New();
> handleMapper->SetInput(this->HandleGeometry[i]->GetOutput());
> this->Handle[i] = vtkActor::New();
> this->Handle[i]->SetMapper(handleMapper);
> handleMapper->Delete();
> u[0] = (double)i / (double)(this->NumberOfHandles - 1.0);
> x = (1.0 - u[0])*x0 + u[0]*x1;
> y = (1.0 - u[0])*y0 + u[0]*y1;
> z = (1.0 - u[0])*z0 + u[0]*z1;
> points->SetPoint(i, x, y, z);
> this->HandleGeometry[i]->SetCenter(x,y,z);
> }
>
> // vtkParametric spline acts as the interpolating engine
> this->ParametricSpline = vtkParametricSpline::New();
> this->ParametricSpline->Register(this);
> this->ParametricSpline->SetPoints(points);
> this->ParametricSpline->ParameterizeByLengthOff();
> points->Delete();
> this->ParametricSpline->Delete();
>
> // Define the points and line segments representing the spline
> this->Resolution = 499;
>
> this->ParametricFunctionSource = vtkParametricFunctionSource::New();
>
> this->ParametricFunctionSource->SetParametricFunction(this->ParametricSpli
> ne);
> this->ParametricFunctionSource->SetScalarModeToNone();
> this->ParametricFunctionSource->GenerateTextureCoordinatesOff();
> this->ParametricFunctionSource->SetUResolution( this->Resolution );
> this->ParametricFunctionSource->Update();
>
> vtkPolyDataMapper* lineMapper = vtkPolyDataMapper::New();
> lineMapper->SetInput( this->ParametricFunctionSource->GetOutput() ) ;
> lineMapper->ImmediateModeRenderingOn();
> lineMapper->SetResolveCoincidentTopologyToPolygonOffset();
>
> this->LineActor = vtkActor::New();
> this->LineActor->SetMapper( lineMapper );
> lineMapper->Delete();
>
>
--
Cheers,
Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061110/5aeaf061/attachment.htm>
More information about the vtkusers
mailing list