Issue with GetScalarPointer and GetScalarRange in c++

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.

No one?

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

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

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