[vtkusers] [vtkUsers] Mapping the real x, y, z points to the volume indices i, j, k using vtkImageData

bcombes benoit.combes at inria.fr
Fri Jan 20 04:57:02 EST 2017

Hi vtkUsers,

I have a hard time with ComputeStructuredCoordinates.

* Goal:
  I have a vtk file and a nii file. I want to recover some scalar values 
from the volume to assign it to the surface scalar. So, essentially, I 
want to find the mapping from the real x,y,z points to the volume 
indices i,j,k.

* Observations:
1) When displaying the surface and the volume in the real frame they fit 
perferctly, so data looks not to be the problem.
2) When making the (x,y,z)_Real to (i,j,k)_Volume correspondances using  
ComputeStructuredCoordinates or FindPoint, I do not have the expected 
In particular, the coordinates given by ComputeStructuredCoordinates 
indicates that the points are outside the volume or have wrong scalar 
values. In other words, it does not seem to do the job I expect.

* Code:


// img is a vtkSmartPointer<vtkImageData> loaded from 
// surf is a vtkSmartPointer<vtkPolyData> loaded from 

for(int i=0;i<surf->GetNumberOfPoints();++i)
     double *v=surf->GetPoint(i);

     int ijk[] = { -1,-1,-1};
     double *foopcoords;
     int isOk=img->ComputeStructuredCoordinates(v,ijk,foopcoords) ;

      if(isOk && (ijk[0]>0 && ijk[1]>0 && ijk[2]>0))
         {float v=img->GetScalarComponentAsFloat(ijk[0],ijk[1],ijk[2],0);

I also try to use FindPoint instead:
   int id = img->FindPoint(v);

  but have the same issue.

* Question

I don't understand how to fix this. Am I wrongly understand the purpose 
of ComputeStructuredCoordinates ? Are there any voxels to real frames 
that are not accounted for when using this function (or extra used ones) ?

More information about the vtkusers mailing list