Updating a vtkSpline

Hi!
Thank you in advance for your support.

I have implemented a small tool capable of doing simple animations from external data.

The external data are a list of lines containing every line:
time, 3D position and a Quaternion

I am trying to draw a “dynamic” vtkSpline: For every time/line appearing in the external data, I add that point (the position) and I would like to “re-draw” the spline every time. Nevertheless, although I am setting the new points every time, it seems the spline it is no “updated” taking into account the new added points. Is it possible to do this? If so, how?

What I have now is something like this:

An initial “points” with one point is defined up here:
///…
///…Some other things
///…
//Spline is created
//Spline
//Allocate memory for all the splines and related functions

vtkSmartPointer<vtkKochanekSpline> xSpline = vtkSmartPointer<vtkKochanekSpline>::New();
vtkSmartPointer<vtkKochanekSpline> ySpline = vtkSmartPointer<vtkKochanekSpline>::New();
vtkSmartPointer<vtkKochanekSpline> zSpline = vtkSmartPointer<vtkKochanekSpline>::New();
vtkSmartPointer<vtkParametricSpline> spline = vtkSmartPointer<vtkParametricSpline>::New();
vtkSmartPointer<vtkParametricFunctionSource> functionSource = 
vtkSmartPointer<vtkParametricFunctionSource>::New();

//Allocates memory for the Spline’s actor and mapper
vtkSmartPointer mapperSpline =
vtkSmartPointer::New();
vtkSmartPointer actorSpline = vtkSmartPointer::New();

spline->SetXSpline(xSpline);
spline->SetYSpline(ySpline);
spline->SetZSpline(zSpline);
spline->SetPoints(points);

functionSource->SetParametricFunction(spline);
functionSource->SetUResolution(50 * points->GetNumberOfPoints());
functionSource->SetVResolution(50 * points->GetNumberOfPoints());
functionSource->SetWResolution(50 * points->GetNumberOfPoints());
functionSource->Update();

mapperSpline->SetInputConnection(functionSource->GetOutputPort());
actorSpline->SetMapper(mapperSpline);

renderer->AddActor(actorSpline);

Then I have a callback for time events:

renderWindowInteractor->Initialize();

vtkSmartPointer timerCallback =
vtkSmartPointer::New();
timerCallback->SetCallback(TimerCallbackFunction);
renderWindowInteractor->AddObserver ( vtkCommand::TimerEvent, timerCallback );

The TimerCallbackFunction executes some functions, where “points” are updated by adding one one new point, and then a function “updateSpline” is called. This function is:

void updateSpline(const vtkSmartPointer& spline, const vtkSmartPointer& functionSource,
const vtkSmartPointer& points){
spline->SetPoints(points);

functionSource->SetParametricFunction(spline);
functionSource->SetUResolution(50 * points->GetNumberOfPoints());
functionSource->SetVResolution(50 * points->GetNumberOfPoints());
functionSource->SetWResolution(50 * points->GetNumberOfPoints());
functionSource->Update();

}

Nevertheless, I think the spline is not actually “updating” and taking into account the new points. Is there any way to do this? Or should I create a new spline, with a new mapper and actor and attach it to the renderer?

Thank you in advance! If you needed further information do not hesitate to ask.

Best regards,

PD: I found a solution. In order to be able to update the vtkSpline, first one hast to set the number of points and then set the points, hence, in the update vtkSpline function:

void updateSpline(const vtkSmartPointer& spline, const vtkSmartPointer& functionSource,
const vtkSmartPointer& points){

    spline->SetNumberOfPoints(points->GetNumberOfPoints());
    spline->SetPoints(points);


functionSource->SetParametricFunction(spline);
functionSource->SetUResolution(50 * points->GetNumberOfPoints());
functionSource->SetVResolution(50 * points->GetNumberOfPoints());
functionSource->SetWResolution(50 * points->GetNumberOfPoints());
functionSource->Update();

}