Update a line by adding some points

Hello,

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();
    poly->SetPoints(points);

    vtkIdType nbPoints = points->GetNumberOfPoints();

    if(nbPoints > 1)
    {
        vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New();
        polyLine->GetPointIds()->SetNumberOfIds(nbPoints);
        for(int i=0; i<nbPoints; i++)
            polyLine->GetPointIds()->SetId(i,i);
        vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
        cells->InsertNextCell(polyLine);
        poly->SetLines(cells);
    }

    vtkMRMLModelNode::SafeDownCast(realTimeTrajectory)->SetAndObservePolyData(poly);
    realTimeTrajectory->Modified();

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: Slicer/Modules/Loadable/Markups/Testing/Cxx at main · Slicer/Slicer · GitHub

You can remove nodes by calling vtkMRMLScene::RemoveNode.

1 Like