[vtkusers] Solid Voxelization with VTK

David Gobbi david.gobbi at gmail.com
Tue Jun 5 19:49:58 EDT 2018


Hi Berti,

The correct pad filter to use for this is "vtkImageConstantPad", not
"WrapPad", but padding really isn't necessary.  Neither is the use of cell
scalars, it's more appropriate to use point scalars when working with image
data since each voxel is represented as a point scalar.

The threshold should be set like this, for a threshold halfway between your
"inval" and "outval":

  selector->ThresholdByUpper(0.5*(startLabel + endLabel));

The lookup table wasn't correctly set. Calling SetRange() does not set the
number of entries in the lookup table (by default, the lookup table has 256
entries).

  lut->SetTableRange(0, 1);
  lut->SetNumberOfColors(2);

Also, your color for "1" was transparent, whereas it has to be opaque in
order to properly see a scalar-colored cone.



I stripped the visualization part of your pipeline down to the following.
No padding is done, the thresholding uses point scalars, no shifting, and
no lookup table (instead, I call ScalarVisibilityOff() and set the color
via the actor's property object).  I replaced vtkPolyDataMapper with
vtkDataSetMapper, which automatically skins the data.


  unsigned char startLabel = outval;
  unsigned char endLabel = inval;

  vtkNew<vtkThreshold> selector;
  // the call to SetInputArrayToProcess() isn't necessary, the default is
fine
  //selector->SetInputArrayToProcess(0, 0, 0,
  //
 vtkDataObject::FIELD_ASSOCIATION_POINTS,
  //                                 vtkDataSetAttributes::SCALARS);
  selector->SetInputData(voxelImage);
  selector->ThresholdByUpper(0.5*(startLabel + endLabel));
  selector->Update();

  vtkNew<vtkDataSetMapper> mapper;
  mapper->SetInputConnection(selector->GetOutputPort());
  mapper->ScalarVisibilityOff();

  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper);
  actor->GetProperty()->SetColor(0.0, 1.0, 0.0);


An image of the resulting cone is attached.

 - David


On Tue, Jun 5, 2018 at 1:26 AM, Berti Krüger <berti_krueger at hotmail.com>
wrote:

> Hi David,
>
>
> thank you very much for your help.
>
>
> I tried the example from your link. Unfortunately the result is same as
> using the vtkVoxelModeller:
>
>
> [image: Screenshot result voxelization]
> I get only a voxelization of the surface. The interior of the voxelized
> cone is still hollow and not filled with voxels (at least this is implied
> by the visualization).
>
>
> For the visualization i use Bill Lorensen's example code from here:
>
> https://lorensen.github.io/VTKExamples/site/Cxx/Medical/
> GenerateCubesFromLabels/
>
>
>
> I have attached this small example which compiles with VTK 8.1 to show the
> issue. It basicly only consist of the example code from your link (
> https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/
> PolyDataToImageData/) and the visualization code from the  Bill
> Lorensen's example from the link above. I have not changed much.
>
>
> Any idea what is going wrong or what can i do get also voxelization of the
> interior (solid voxelization)?
>
>
> Thank you very much in advance.
>
>
>
> Regards
>
>
> Berti
>
> PolyDataToImageData - lorensen.github.io
> <https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/PolyDataToImageData/>
> lorensen.github.io
> If VTK is not installed but compiled on your system, you will need to
> specify the path to your VTK build:
>
>
>
> GenerateCubesFromLabels - GitHub Pages
> <https://lorensen.github.io/VTKExamples/site/Cxx/Medical/GenerateCubesFromLabels/>
> lorensen.github.io
> Usage: GenerateCubesFromLabels FullHead.mhd StartLabel EndLabel where
> InputVolume is a meta file containing a 3 volume of discrete labels.
>
>
>
>
> ------------------------------
> *Von:* David Gobbi <david.gobbi at gmail.com>
> *Gesendet:* Montag, 28. Mai 2018 23:13
> *An:* Berti Krüger
> *Cc:* vtkusers at vtk.org
> *Betreff:* Re: [vtkusers] Solid Voxelization with VTK
>
> Hi Berti,
>
> If its a triangulated surface that you want to fill with voxels, use
> vtkPolyDataToImageStencil:
> https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/Pol
> yDataToImageData/
> PolyDataToImageData - lorensen.github.io
> <https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/PolyDataToImageData/>
> lorensen.github.io
> If VTK is not installed but compiled on your system, you will need to
> specify the path to your VTK build:
>
>
>
> If its a mesh of 3D elements and you want to sample the elements to create
> voxels, try vtkResampleToImage.
>
>  - David
>
>
>
> On Mon, May 28, 2018 at 4:41 PM, Berti Krüger <berti_krueger at hotmail.com>
> wrote:
>
> Hello Everyone.
>
> For my Project i have to voxelize a 3D-Triangle-Mesh. I already found the
> vtkVoxelModeller which, while somewhat slow (only around 200 Triangles per
> second), works, but only voxelizes the outer shell where the mesh boundary
> triangles are. The inner part of the mesh stays hollow.
>
> Is there some way to get solid voxelization of 3D-Triangle-Meshes out of
> the
> box with VTK ?
>
>
> Thank you very much in advance,
>
> Berti
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180605/f6b0a609/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: screenshot.jpg
Type: image/jpeg
Size: 62429 bytes
Desc: not available
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180605/f6b0a609/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SolidCone.png
Type: image/png
Size: 16859 bytes
Desc: not available
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180605/f6b0a609/attachment-0001.png>


More information about the vtkusers mailing list