# After add actor to render, can i change the actor data real time ?

**URL:** https://discourse.vtk.org/t/after-add-actor-to-render-can-i-change-the-actor-data-real-time/9724
**Category:** Support
**Created:** [November 2, 2022, 8:41am UTC](https://discourse.vtk.org/t/after-add-actor-to-render-can-i-change-the-actor-data-real-time/9724 "2022-11-02T08:41:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![herman](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/eada6e/32.png) [@herman](https://discourse.vtk.org/u/herman)
#### Post date: [November 2, 2022, 8:41am UTC](https://discourse.vtk.org/t/after-add-actor-to-render-can-i-change-the-actor-data-real-time/9724/1 "2022-11-02T08:41:49Z")

</div>

Dear vtk users:

As we know, after add actor to render, we can change the properties of the actor.  
Now I tried to change the data of the actor,but it does not work.  
My code is as below:

//////////////////////////////////////////////  
vtkActor\* temp\_actor = render-\>GetActors()-\>GetLastActor();  
vtkMapper\* temp\_mapper = temp\_actor-\>GetMapper();  
vtkPolyData\* temp\_poly\_data = vtkPolyData::SafeDownCast(temp\_mapper-\>GetInput());  
vtkPoints\* temp\_points = temp\_poly\_data-\>GetPoints();  
int points\_num = temp\_points-\>GetNumberOfPoints();

// change z value of 100 points  
for (int i = 0; i \< 100; i++)  
{  
//get a random idx  
int idx = rand() % (points\_num - 0 + 1);

```
//get point by idx
double* p_data = temp_points->GetPoint(idx);

//change z value of the point
p_data[2] *= 2;

```

}

renWindow-\>Render();

///////////////////////////////////////////////////

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 2, 2022, 9:20pm UTC](https://discourse.vtk.org/t/after-add-actor-to-render-can-i-change-the-actor-data-real-time/9724/2 "2022-11-02T21:20:43Z")

</div>

You might find the [markdown rules for code highlighting](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks) useful.

Before I get to your main question, I’ll warn you against doing the following, because `GetPoint(idx)` just returns a copy of the point, and modifying the copy doesn’t modify the original point.

```nohighlight
double* p_data = temp_points->GetPoint(idx);
p_data[2] *= 2;

```

If you want to modify the point, you _must_ use `SetPoint()`:

```nohighlight
double p_data[3];
temp_points->GetPoint(idx, p_data);
p_data[2] *= 2;
temp_points->SetPoint(idx, p_data);

```

Finally, to answer your question, after setting all of the points that you want to change, you _must_ call `Modified()`:

```nohighlight
temp_points->Modified();

```

However, modifying an actor’s data like this is not always a safe thing to do. If the data object was generated as the output of a VTK algorithm object, and if it is still associated with that algorithm object, then the data object should only be modified by that algorithm object.

If you want to modify the data, you must make sure that it is no longer associated with the algorithm object. For example:

```nohighlight
algorithm->Update();
vtkDataSet* data = algorithm->GetOutput();
// separate the data from the algorithm
algorithm->SetOutput(nullptr);
// now we can safely modify the data ourselves

```

Also, when you modify the data, you are responsible for the internal consistency of the data object. So if you add more points, you must ensure that any arrays associated with the points are properly resized. If you remove points, you must ensure that no cells refer to the points that you have removed.

---

<div class="post-metadata">

### Author: ![herman](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/eada6e/32.png) [@herman](https://discourse.vtk.org/u/herman)
#### Post date: [November 3, 2022, 7:53am UTC](https://discourse.vtk.org/t/after-add-actor-to-render-can-i-change-the-actor-data-real-time/9724/3 "2022-11-03T07:53:22Z")

</div>

Thanks so much, the problem bother me for a long time, I tried your method, it works well.
