# Issue with GetScalarPointer and GetScalarRange in c++

**URL:** https://discourse.vtk.org/t/issue-with-getscalarpointer-and-getscalarrange-in-c/8925
**Category:** Support
**Created:** [July 11, 2022, 9:28am UTC](https://discourse.vtk.org/t/issue-with-getscalarpointer-and-getscalarrange-in-c/8925 "2022-07-11T09:28:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lonewolf](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3da27b/32.png) [@lonewolf](https://discourse.vtk.org/u/lonewolf)
#### Post date: [July 11, 2022, 9:28am UTC](https://discourse.vtk.org/t/issue-with-getscalarpointer-and-getscalarrange-in-c/8925/1 "2022-07-11T09:28:08Z")

</div>

Hi all,  
I am facing a strange behavior and I am pretty sure I am missing something. Using VTK 8.0.1.

I have a 3D VtkImageData to which I need to modify the scalar values. When I get the ScalarRange is ok before changing them all.  
I proceed to change the values, but then after the cycle, the scalar range is exactly the same. I print a value inside the cycle to make sure there is a change.

The code goes as follows:

```
int dims[3];
img->GetDimensions(dims);
float* beamBuf = (float*)img->GetScalarPointer();
cout << "my nf = " << nf << endl;
cout<< img->GetScalarRange()[0] << "," << img->GetScalarRange()[1] <<endl;
for (int j = 0; j < dims[0] * dims[1] * dims[2]; j++)
{
    if(dims[0] * dims[1] * dims[2]/3 == j) cout << beamBuf[j] << endl;
    beamBuf[j] = (float)beamBuf[j] / (float)nf;
    if(dims[0] * dims[1] * dims[2]/3 == j) cout << beamBuf[j] << endl;
}

```

// force modified…  
img-\>Modified();  
img-\>GetPointData()-\>Modified();  
img-\>GetPointData()-\>Update();  
cout\<\< img-\>GetScalarRange()[0] \<\< “,” \<\< img-\>GetScalarRange()[1] \<\<endl;

and this is the output:

my nf = 16  
0, 25.1817  
0.176752  
0.011047  
0, 25.1817

Later on, I use this same image to perform a calculation and then the values are the ones I updated on the buffer.  
I am utterly confused.

LoneWolf.

---

<div class="post-metadata">

### Author: ![lonewolf](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3da27b/32.png) [@lonewolf](https://discourse.vtk.org/u/lonewolf)
#### Post date: [July 12, 2022, 2:28pm UTC](https://discourse.vtk.org/t/issue-with-getscalarpointer-and-getscalarrange-in-c/8925/2 "2022-07-12T14:28:57Z")

</div>

No one?

---

<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: [July 12, 2022, 9:49pm UTC](https://discourse.vtk.org/t/issue-with-getscalarpointer-and-getscalarrange-in-c/8925/3 "2022-07-12T21:49:46Z")

</div>

Since the scalars were changed, the vtkDataArray that holds the scalars must be `Modified()`.

```nohighlight
img->GetPointData()->GetScalars()->Modified();

```

Tracking of changes to objects in the VTK pipeline is very fine-grained. It’s necessary to call `Modified()` on the specific object that was modified, and in this case that means the data array, not the data set or the attributes. (Though in this case, `Modified()` must be called on the data set as well.)

---

<div class="post-metadata">

### Author: ![lonewolf](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/3da27b/32.png) [@lonewolf](https://discourse.vtk.org/u/lonewolf)
#### Post date: [July 13, 2022, 6:51am UTC](https://discourse.vtk.org/t/issue-with-getscalarpointer-and-getscalarrange-in-c/8925/4 "2022-07-13T06:51:01Z")

</div>

David Gobbi  
thank you so much for your reply. Indeed, I was calling modify on the wrong structure. silly me!  
Best regards!
