# Add points to polyline

**URL:** https://discourse.vtk.org/t/add-points-to-polyline/7914
**Category:** Support
**Created:** [February 24, 2022, 4:39pm UTC](https://discourse.vtk.org/t/add-points-to-polyline/7914 "2022-02-24T16:39:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [February 24, 2022, 4:39pm UTC](https://discourse.vtk.org/t/add-points-to-polyline/7914/1 "2022-02-24T16:39:56Z")

</div>

Hello,  
I have a vtkPoints and a vtkPolyline. And I would like to add a point to my vtkPoints with the points connected by lines. I manage to do it at initialization but when I am trying to do it later, it doesn’t work. Do you know how to do it ?  
Thanks for your help

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [February 24, 2022, 4:53pm UTC](https://discourse.vtk.org/t/add-points-to-polyline/7914/2 "2022-02-24T16:53:44Z")

</div>

I don’t really understand what you intend to do. Are you working within a `vtkDataSet` such as `vtkPolyData` or `vtkUnstructuredGrid`? Are you editing the points within your `vtkPolyLine` and are wondering why they wouldn’t update in a `vtkPoints` outside of it?

---

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [February 24, 2022, 5:05pm UTC](https://discourse.vtk.org/t/add-points-to-polyline/7914/3 "2022-02-24T17:05:48Z")

</div>

For now I am using `vtkPolyData` but I could use ‘vtkUnstructuredGrid’ instead. I want to do a InsertNexPoint to my vtkPoints and at the same time update my vtkPolyline to add a line between the lastPoint and the newPoint.

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [February 24, 2022, 5:21pm UTC](https://discourse.vtk.org/t/add-points-to-polyline/7914/4 "2022-02-24T17:21:02Z")

</div>

All right, you won’t be able to do that in a clean way. You cannot add points to a cell that is already in storage in a `vtkPolyData` (nor `vtkUnstructuredGrid`). What you could do is deal with `vtkLine` instead of `vtkPolyLine`, and add a line using `vtkPolyData::InsertNextCell`.

Another solution would be to not insert the full poly line until it is finalized.

---

<div class="post-metadata">

### Author: ![Julienchz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/julienchz/32/4106_2.png) [@Julienchz](https://discourse.vtk.org/u/Julienchz)
#### Post date: [February 25, 2022, 7:25am UTC](https://discourse.vtk.org/t/add-points-to-polyline/7914/5 "2022-02-25T07:25:52Z")

</div>

Do you have a short example ? vtkPolyData::InsertNexCell is not very clear for me

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [February 25, 2022, 2:37pm UTC](https://discourse.vtk.org/t/add-points-to-polyline/7914/6 "2022-02-25T14:37:56Z")

</div>

You can find the documentation of `vtkPolyData` [here](https://vtk.org/doc/nightly/html/classvtkPolyData.html) .

```auto
vtkNew<vtkPoints> points;
vtkNew<vtkPolyData> polyData;
vtkNew<vtkIdList> polyLinePointIds;

FillPoints(points); // a function setting points
FillPolyLinePointIds(polyLinePointIds); // extracting the points that are in my polyline
polyData->SetPoints(points);
polyData->InsertNextCell(VTK_POLY_LINE, polyLinePointIds);

```
