[vtkusers] updating vtkImageAccumulate

mbcx9rb9 richard.j.brown at live.co.uk
Fri Jul 3 04:50:25 EDT 2015


i have a vtkImageData, which I would like to be able to calculate the max,
min, average, etc. via vtkImageAccumulate. Then I want to be able to edit
the image data, update the image accumulate and see the new statistics.

However, it seems that vtkImageAccumulate doesn't work how I hoped it would.
When I change my image data, my image accumulate still returns the original
statistics of the image data before I made the changes.

If I edit my image data, am I obliged to reinitialise my image accumulate to
be able to see the statistics on the edited image data?

I have attached a simple example of a matrix with one voxel=100 and whose
max is found with imageaccumulate. Then, a voxel of 200 is added,
imageaccumulate is updated, but returns a max of 100 instead of the new 200.
Finally, a new imageaccumulate is used to verify that the actually max is
200 as expected. 

Any ideas of where I'm going wrong would be greatly appreciated.



    // create image data
    vtkSmartPointer<vtkImageData> id = vtkSmartPointer<vtkImageData>::New();
    id->SetSpacing(1,1,1);
    id->SetExtent(0,99,0,99,0,99);
    id->AllocateScalars(VTK_DOUBLE,1);

    // set all values to zero
    for (int i=id->GetExtent()[0]; i<=id->GetExtent()[1]; i++) {
        for (int j=id->GetExtent()[2]; j<=id->GetExtent()[3]; j++) {
            for (int k=id->GetExtent()[4]; k<=id->GetExtent()[5]; k++) {
                double* voxel =
static_cast<double*>(id->GetScalarPointer(i,j,k));
                voxel[0] = 0;
            }
        }
    }

    // set one voxel value to 100
    double* voxel = static_cast<double*>(id->GetScalarPointer(50,50,50));
    voxel[0] = 100;

    // set image accumulate
    vtkSmartPointer<vtkImageAccumulate> ia =
vtkSmartPointer<vtkImageAccumulate>::New();
    ia->SetInputData(id);
    ia->SetComponentExtent(id->GetExtent());
    ia->SetComponentOrigin(id->GetOrigin());
    ia->SetComponentSpacing(id->GetSpacing());
    ia->Update();

    // output the max in the matrix (should be 100)
    std::cout << "max before change: " << ia->GetMax()[0] << std::endl;

    // change a different voxel to 200
    voxel = static_cast<double*>(id->GetScalarPointer(50,50,60));
    voxel[0] = 200;

    // update image accumulate
    ia->Update();
    std::cout << "max after change (want this value to be 200): " <<
ia->GetMax()[0] << std::endl;

    // create second image accumulate to verify that the max is, as it
should be, 200
    vtkSmartPointer<vtkImageAccumulate> ia2 =
vtkSmartPointer<vtkImageAccumulate>::New();
    ia2->SetInputData(id);
    ia2->SetComponentExtent(id->GetExtent());
    ia2->SetComponentOrigin(id->GetOrigin());
    ia2->SetComponentSpacing(id->GetSpacing());
    ia2->Update();
    std::cout << "max with ia2 (should be 200): " << ia2->GetMax()[0] <<
std::endl;



--
View this message in context: http://vtk.1045678.n5.nabble.com/updating-vtkImageAccumulate-tp5732697.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list