Access to Cells in VTK.js

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Access to Cells in VTK.js

Andrzej Marciniak
Hi All,

My question is: for a given IJK data cell position in vtkImageData, how can
I get access to:
- voxel value,
- voxel bounds (position of all 8 vertices of a voxel)
- all voxels belonging to a given vtkImageSlice.

More detailed description of why I need this:
I am working on a tool for annotations and segmentations of MRI images using
vtk.js with vtkImageData to represent MRI volume. I tried to use
vtkImageSlice for both original image (grayscale) and overlay (color), but
since there is no transparency for background voxels in vtkImageSlice (i.e.
there is opacity property but no alpha), I had to use a different approach.

Now, I am using "my own" transparent canvas as segmentation/annotation layer
and vtkImageSlice to represent original image.
To establish position of annotation I use picker. Using
- picker.getPickedPositions()[0]
- picker.getCellIJK()
I can get both world position and cell position for a picked point. This
works great, including interactions like zooming, pan, windowlevel, slicing
etc. (see picture).
<http://vtk.1045678.n5.nabble.com/file/t342677/annotationTool.png>

However, I would like to draw on my canvas not only points (as in the
picture), but also full rectangles covering voxels. To do that I need to
know position of 4 vertices of voxel in a given plane and its value (I want
to mark it with different color regarding the value).

Thanks
Andrzej



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Access to Cells in VTK.js

VTK - Users mailing list
You can do that by calling getPoint(idx) on the image data based on it's index. 

idx = i + j * dims[0] + k * dims[0] * dims[1]

for the ijk of the points. You can easily convert from the ijk of a cell to the ijk of the point. based on which corner you want.

HTH,

Seb

On Thu, Jan 17, 2019 at 11:56 AM Andrzej Marciniak <[hidden email]> wrote:
Hi All,

My question is: for a given IJK data cell position in vtkImageData, how can
I get access to:
- voxel value,
- voxel bounds (position of all 8 vertices of a voxel)
- all voxels belonging to a given vtkImageSlice.

More detailed description of why I need this:
I am working on a tool for annotations and segmentations of MRI images using
vtk.js with vtkImageData to represent MRI volume. I tried to use
vtkImageSlice for both original image (grayscale) and overlay (color), but
since there is no transparency for background voxels in vtkImageSlice (i.e.
there is opacity property but no alpha), I had to use a different approach.

Now, I am using "my own" transparent canvas as segmentation/annotation layer
and vtkImageSlice to represent original image.
To establish position of annotation I use picker. Using
- picker.getPickedPositions()[0]
- picker.getCellIJK()
I can get both world position and cell position for a picked point. This
works great, including interactions like zooming, pan, windowlevel, slicing
etc. (see picture).
<http://vtk.1045678.n5.nabble.com/file/t342677/annotationTool.png>

However, I would like to draw on my canvas not only points (as in the
picture), but also full rectangles covering voxels. To do that I need to
know position of 4 vertices of voxel in a given plane and its value (I want
to mark it with different color regarding the value).

Thanks
Andrzej



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Access to Cells in VTK.js

Andrzej Marciniak
Hi Sebastien,

Thank you for the tip - it works for me. Now, I have only a problem with
precision in finding IJK.
Should I better use vtkPicker or vtkMappers to get IJK position of selected
voxel? I have made a simple experiment with both ways to calculate IJK and I
got different results.

 renderWindow.getInteractor().onRightButtonPress((callData) => {
            if (renderer !== callData.pokedRenderer) {
                return;
            }
            const pos = callData.position;
            const point = [pos.x, pos.y, 0.0];
            picker.pick(point, renderer);
            const worldPos = picker.getPickedPositions()[0];
//I have only one Actor in renderer but 3 mappers set on different planes
            let slices = null;
            try {
                slices = mappers.map((el) => {            
                    return el.getSliceAtPosition(worldPos) // this is how I
get I,J,K with ImageMapper API
                });
            }
            catch (err) {  alert("You cannot pick a point outside MRI
volume");
                return;
            }
            const pointIndex = slices[0] + slices[1] * dims[0] + slices[2] *
dims[0] * dims[1];
            const pointIndex2 = picker.getCellIJK()[0]
                               + picker.getCellIJK()[1] * dims[0]
                               + picker.getCellIJK()[2] * dims[0] * dims[1];
            if (pointIndex===pointIndex2)
inputData.getPointData().getScalars().getData()[pointIndex]=1983;            
            else {
               
inputData.getPointData().getScalars().getData()[pointIndex]=1700;
                inputData.getPointData().getScalars().getData()[pointIndex2]
= 1500;
            }
        });
<http://vtk.1045678.n5.nabble.com/file/t342677/pickerProblem.png>
As a result I have different voxels marked (please see image).  White voxel
is when they agree, light- and dark-grey when they don't. The results are
different when the selected point on canvas is close to the border of voxel
(points 1 and 3).
Which way is better?  Can be direction of the vtkDataImage problem here (its
not aligned with xyz coordinates)?
Thank you again
Andrzej



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Access to Cells in VTK.js

VTK - Users mailing list
point picker or cell picker won't give you the same ijk since one will be the point ijk vs the cell one.

On Fri, Jan 18, 2019 at 11:42 AM Andrzej Marciniak <[hidden email]> wrote:
Hi Sebastien,

Thank you for the tip - it works for me. Now, I have only a problem with
precision in finding IJK.
Should I better use vtkPicker or vtkMappers to get IJK position of selected
voxel? I have made a simple experiment with both ways to calculate IJK and I
got different results.

 renderWindow.getInteractor().onRightButtonPress((callData) => {
            if (renderer !== callData.pokedRenderer) {
                return;
            }
            const pos = callData.position;
            const point = [pos.x, pos.y, 0.0];
            picker.pick(point, renderer);
            const worldPos = picker.getPickedPositions()[0];
//I have only one Actor in renderer but 3 mappers set on different planes
            let slices = null;
            try {
                slices = mappers.map((el) => {             
                    return el.getSliceAtPosition(worldPos) // this is how I
get I,J,K with ImageMapper API
                });
            }
            catch (err) {  alert("You cannot pick a point outside MRI
volume");
                return;
            }
            const pointIndex = slices[0] + slices[1] * dims[0] + slices[2] *
dims[0] * dims[1];
            const pointIndex2 = picker.getCellIJK()[0]
                               + picker.getCellIJK()[1] * dims[0]
                               + picker.getCellIJK()[2] * dims[0] * dims[1];
            if (pointIndex===pointIndex2)
inputData.getPointData().getScalars().getData()[pointIndex]=1983;           
            else {

inputData.getPointData().getScalars().getData()[pointIndex]=1700;
                inputData.getPointData().getScalars().getData()[pointIndex2]
= 1500;
            }
        });
<http://vtk.1045678.n5.nabble.com/file/t342677/pickerProblem.png>
As a result I have different voxels marked (please see image).  White voxel
is when they agree, light- and dark-grey when they don't. The results are
different when the selected point on canvas is close to the border of voxel
(points 1 and 3).
Which way is better?  Can be direction of the vtkDataImage problem here (its
not aligned with xyz coordinates)?
Thank you again
Andrzej



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers