Update a line by adding some points


I want to enlarge a line by adding the points in each iteration, i did it like this :

    vtkSmartPointer<vtkPoints> points = realTimeInsertion->getPoints();
    vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New();

    vtkIdType nbPoints = points->GetNumberOfPoints();

    if(nbPoints > 1)
        vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
        for(int i=0; i<nbPoints; i++)
        vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();


But i got this error :

error: [/RealTimeAblation/Slicer/Slicer-SuperBuild/Slicer-build/bin/Slicer.app/Contents/MacOS/./Slicer] exit abnormally - Report the problem.

16:48:17: /RealTimeAblation/Slicer/Slicer-SuperBuild/Slicer-build/Slicer exited with code 1

How can i replace the vtkPolyData of this node ?

I have also another question, how can i delete a vtkMRMLModelNode ?

Thank you.

If you are not comfortable performing such low-level polydata manipulation then you can use higher-level VTK classes (such as vtkLineSource) to generate polydata instead.

To display polylines in Slicer, I would recommend to use markup curve nodes (available in recent Slicer Preview releases).

Can you give me a simple example of markup curve nodes in c++, please ?
And i want to know how can i remove a MRML Model Node in my codes, can you give a simple example for removing nodes ?

Thank you so much.

See these tests: https://github.com/Slicer/Slicer/tree/master/Modules/Loadable/Markups/Testing/Cxx

You can remove nodes by calling vtkMRMLScene::RemoveNode.

1 Like