# Need a noninvasive vtkActor::GetProperty()

**URL:** https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700
**Category:** Support
**Created:** [April 11, 2024, 10:30pm UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700 "2024-04-11T22:30:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![whereismymoney](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whereismymoney/32/6859_2.png) [@whereismymoney](https://discourse.vtk.org/u/whereismymoney)
#### Post date: [April 11, 2024, 10:30pm UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700/1 "2024-04-11T22:30:36Z")

</div>

Unfortunately  
vtkProperty\* vtkActor::GetProperty( )  
will automatically create a vtkProperty object if one has not yet been created.  
I would like something like GetProperty() but it should return a Null pointer if the vtkProperty object has not yet been created.  
My motivation: If someone else has already created a vtkProperty object for a particular vtkActor, then I will not change it. However, if the vtkProperty object has not yet been created, then I will create one and set the Interpolation to Flat. Currently we are having problems with uninitialized memory reads causing some vtkActors to have Gouraud shading.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 14, 2024, 1:06pm UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700/2 "2024-04-14T13:06:56Z")

</div>

Hello,

If I understood it right, just test whether the returned `vtkProperty`’s setting is Gouraud shading and set it to flat.

regards,

Paulo

---

<div class="post-metadata">

### Author: ![whereismymoney](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whereismymoney/32/6859_2.png) [@whereismymoney](https://discourse.vtk.org/u/whereismymoney)
#### Post date: [April 14, 2024, 11:05pm UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700/3 "2024-04-14T23:05:05Z")

</div>

Hello Paulo,  
Thank you for your response.  
Unfortunately if the vtkProperty objects are automatically created by vtkActor::GetProperty(), they contain uninitialized values (garbage values that are different each time I run the program), so they could have shading set to Flat or Gouraud randomly. So I need to know if a vtkProperty object for this vtkActor does not exist before I call vtkActor::GetProperty() or if someone else has already created a vtkProperty object for this vtkActor.  
Thanks,  
Matthias

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 15, 2024, 1:11pm UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700/4 "2024-04-15T13:11:15Z")

</div>

Like I said, just test the shading setting with an `if()` and set it correctly when it is initialized incorrectly. Now, if the question extends to other properties, not only shading option, just call `vtkProperty::DeepCopy( my_standard_property )` on the returned `vtkProperty` objects.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 15, 2024, 10:38pm UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700/5 "2024-04-15T22:38:11Z")

</div>

> [@whereismymoney](#):
>
> Unfortunately if the vtkProperty objects are automatically created by vtkActor::GetProperty(), they contain uninitialized values (garbage values that are different each time I run the program), so they could have shading set to Flat or Gouraud randomly.

I don’t understand how this might be happening. If I look at [`vtkActor::GetProperty()`](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/Core/vtkActor.cxx?ref_type=heads#L340), I see it invokes [`vtkActor::MakeActor()`](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/Core/vtkActor.cxx?ref_type=heads#L336) which simply invokes the `vtkProperty` constructor. In that constructor, the [`Shading`](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/Core/vtkProperty.cxx#L101) member variable is indeed initialized.

---

<div class="post-metadata">

### Author: ![whereismymoney](https://discourse.vtk.org/user_avatar/discourse.vtk.org/whereismymoney/32/6859_2.png) [@whereismymoney](https://discourse.vtk.org/u/whereismymoney)
#### Post date: [April 16, 2024, 5:29am UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700/6 "2024-04-16T05:29:20Z")

</div>

Cory,  
Thank you for the information. I studied the problem in more detail and determined that the uninitialized memory error was not in the VTK code. It was in some other convoluted code that deceptively made it look like the vtkProperty objects contained uninitialized values. My apologies.  
Matthias

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 16, 2024, 11:24am UTC](https://discourse.vtk.org/t/need-a-noninvasive-vtkactor-getproperty/13700/7 "2024-04-16T11:24:12Z")

</div>

No worries! Glad you got it resolved.
