# Update a line by adding some points

**URL:** <https://discourse.slicer.org/t/update-a-line-by-adding-some-points/8754>\
**Category:** Development\
**Created:** [October 12, 2019, 1:20pm UTC](https://discourse.slicer.org/t/update-a-line-by-adding-some-points/8754 "2019-10-12T13:20:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danial](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danial/32/4888_2.png) [@danial](https://discourse.slicer.org/u/danial)\
**Post date:** [October 12, 2019, 1:20pm UTC](https://discourse.slicer.org/t/update-a-line-by-adding-some-points/8754/1 "2019-10-12T13:20:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 12, 2019, 2:14pm UTC](https://discourse.slicer.org/t/update-a-line-by-adding-some-points/8754/2 "2019-10-12T14:14:42Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![danial](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/danial/32/4888_2.png) [@danial](https://discourse.slicer.org/u/danial)\
**Post date:** [October 12, 2019, 3:08pm UTC](https://discourse.slicer.org/t/update-a-line-by-adding-some-points/8754/3 "2019-10-12T15:08:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 12, 2019, 4:02pm UTC](https://discourse.slicer.org/t/update-a-line-by-adding-some-points/8754/4 "2019-10-12T16:02:30Z")

</div>

> [@danial](#):
>
> Can you give me a simple example of markup curve nodes in c++, please ?

See these tests: [Slicer/Modules/Loadable/Markups/Testing/Cxx at main · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/tree/master/Modules/Loadable/Markups/Testing/Cxx)

> [@danial](#):
>
> how can i remove a MRML Model Node

You can remove nodes by calling [vtkMRMLScene::RemoveNode](https://apidocs.slicer.org/master/classvtkMRMLScene.html#af22004ab04625f8746872e2d5ed37245).
