How to delete/hide specific points from vtkvolume?

Hi!
I want to make a “scalpel” tool for a vtkVolume where the user can select a specific zone of it, get all of points (from .getPointData) and remove/hide them from the visualization.
Actually, i’m trying to aproaching with two ways:

A: Using clipping planes, but i have the default limit of 6 and i need more than these, exists any way of
create more clipping planes for the vtkVolumeMapper?.

B: Get the scalars of this points and set its values to black or transparent. How can i achieve this?
Actually i’m setting all points i want to be black/not visible for example to a specific value (for example “-3024”) and the other ones with other value (“1000” for example), then i create a new scalarOpacity function with points in this values and add it to the actual volume (remplacing the old one). I need to render other time the volume or do anything more? I don’t if i’m missing something, i let you the code i’m trying here:

    //Here set all values i want to be transparent/black
    const scalars = this.volume3D.getMapper().getInputData().getPointData().getScalars().getData(); 
    for (let i = 0; i < scalars.length; i++) {
       scalars[i] = -3024;
    }
    //Then set all the values i want to remain as it with other value as 1000 (I use a timeout of 1s 
    //between this two loops)
    for(let i = 0; i < points[0].length; i++) {
       scalars[POINT_INDEX] = 1000;
    }
   
   //I also try it with "setScalars" and new array of Float3d but didn't work 
   this.volume3D.getMapper().getInputData().getPointData().getScalars().modified();
  

    //Then add the opacityFunction on the site of the old one: "0". With points as 1.0 in my desired 
    //scalars
     const pieceFun = vtkPiecewiseFunction.newInstance();
     pieceFun.addPoint(999, 0.0);
     pieceFun.addPoint(1000.0, 1.0);
     pieceFun.addPoint(1001.0, 0.0);
     this.volume3D.getProperty().setScalarOpacity(0, pieceFun);

I don’t know if i’m understandly properly the opacity with the scalars or something…
Thanks in advance!

You can create a 3D frustum shape based on the 2D polygon drawn on the screen and the camera parameters, then convert this closed surface to a binary image. This binary image can be either used as a mask in the volume raycast mapper, or you can use it to blank out voxels of the rendered volume.

This is implemented using VTK in 3D Slicer. It is called the Scissors tool (a.k.a. Scalpel in other software):

You can use the feature as is in 3D Slicer using GUI or in your custom C++ modules or Python scripts. Or you can copy-paste the code into your application (Slicer’s permissive license allows using any parts of it for any purpose in any other software). The implementation in C++ is available here, for both slice and 3D views, perspective and parallel projections:

1 Like