Transform a vtkMRMLModelNode

Operating system: macOS 10.14.6
Slicer version: 4.10.2


I want to set and apply a transformation on a vtkMRMLModelNode by its polyData. I did it like this :

> vtkSmartPointer<vtkPolyData> cylinder = vtkMRMLModelNode::SafeDownCast(node)->GetPolyData();
> / create transform filter
> vtkSmartPointer<vtkTransform> translation = vtkSmartPointer<vtkTransform>::New();
> translation->Translate(vectranslation[0], vectranslation[1], vectranslation[2]);
> // apply filter on cylinder
> vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
> transformFilter->SetInputData(m_cylinder);
> transformFilter->SetTransform(translation);
> transformFilter->Update();
> cylinder->ShallowCopy(transformFilter->GetOutput());

But it would not display the modifications in Slicer. Can you help me to do it, please ?


Try calling node->Modified().

Also as a general suggestion, I always prototype this kind of thing in the python console before doing it in C++. It’s much quicker and easier to learn how the nodes and viewers behave without needing to exit, recompile, and restart for each experiment.

1 Like

You are right. It’s much quicker and easier.

Thank you.