# Mapping between coordinate position (x,y,z) and voxel index

**URL:** https://discourse.vtk.org/t/mapping-between-coordinate-position-x-y-z-and-voxel-index/5357
**Category:** Support
**Created:** [March 10, 2021, 11:36am UTC](https://discourse.vtk.org/t/mapping-between-coordinate-position-x-y-z-and-voxel-index/5357 "2021-03-10T11:36:29Z")
**Posts on this page:** 1
**Showing post:** 4

<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: [March 11, 2021, 5:45pm UTC](https://discourse.vtk.org/t/mapping-between-coordinate-position-x-y-z-and-voxel-index/5357/4 "2021-03-11T17:45:42Z")

</div>

I think the method that the OP is looking for is the following, which can also be used from Python:

```auto
vtkImageData::TransformPhysicalPointToContinuousIndex(const double xyz[3], double ijk[3])

```

There are three coordinate systems in play:

1. the VTK world coordinates, which are returned by `picker.GetPickPosition()`
2. the VTK data coordinates, which are returned by `picker.GetMapperPosition()`
3. the image data structured point coordinates, i.e. the voxel indices

Not all pickers have a `GetMapperPosition()` method. Which picker are you using?

If you can use `GetMapperPosition()`, then you can compute the voxel index like this:

```python
xyz = picker.GetMapperPosition()
XYZ = [0.0, 0.0, 0.0] # to store voxel index
image.TransformPhysicalPointToContinuousIndex(xyz, XYZ)
print(XYZ)

```

If you cannot use `GetMapperPosition()`, you must use the inverse of the actor’s matrix to convert the result of `GetPickPosition()` from the world coordinate system to the actor’s local data coordinate system.

The picker will automatically take all camera parameters into account, so you never have to worry about the camera when you use `picker.GetPickPosition()` or `picker.GetMapperPosition()`.

---

_[View the full topic](https://discourse.vtk.org/t/mapping-between-coordinate-position-x-y-z-and-voxel-index/5357)._
