<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi David,<br>
<br>
thank you very much for all your help and for all the effort.<br>
<br>
I am sorry, but i am an absolute beginner with VTK and for me it is really hard to find informations / documentation / explanations beyond the doxygen class documentation about the advanced visualization/manipulation operations in VTK (the VTK User Manual sadly
 only covers the very basics). <br>
</p>
<p>So thanks again for all your clarifications and all your help so far.<br>
<br>
I replaced the visualization part of my pipeline with your code which makes it so much clearer, shorter and better in terms of the visualization. And it is also easy enough so that even i get it :-)<br>
<br>
Unfortunately when i extend the simple cone source voxelization example i attached the last time by using general STL meshes via the vtkSTLReader, i get missing voxels in the visualization. To be sure that the problem is indeed in the visualization part and
 not in the voxelization part i used <i>binvox</i>, a mature voxelization program (<a moz-do-not-send="true" href="http://www.patrickmin.com/binvox/">http://www.patrickmin.com/binvox/</a> ) to do the voxelization and the code you suggested for the visualization
 of the vtkImageData via VTK.</p>
<p><br>
</p>
<p>Using this setup the Utah Teapot looks like this (the handle and other thin parts of the mesh are missing in the visualization):<br>
</p>
<p><img moz-do-not-send="false" src="cid:part2.BD32B281.2515C60E@hotmail.com" alt="Teapot
        missing voxels" height="197" width="321"></p>
<p><br>
</p>
<p>For surface-only-voxelized meshes there even more voxels missing (the example here is the Stanford Bunny which has only been surface voxelized):</p>
<p><img moz-do-not-send="false" src="cid:part3.34EA7E5F.97F39B72@hotmail.com" alt="bunny surface
        voxelization visualization" height="276" width="321"></p>
<p>What i don't get is that the visualization code is as simple as it gets:</p>
<p><tt>    vtkNew<vtkThreshold> selector;</tt><tt><br>
</tt><tt>    selector->SetInputData(voxelImage);</tt><tt><br>
</tt><tt>    selector->ThresholdByUpper(1.0);</tt><tt><br>
</tt><tt>    selector->Update();</tt><tt><br>
</tt><tt>      </tt><tt><br>
</tt><tt>    vtkNew<vtkDataSetMapper> mapper;</tt><tt><br>
</tt><tt>    mapper->SetInputConnection(selector->GetOutputPort());</tt><tt><br>
</tt><tt>    mapper->ScalarVisibilityOff();</tt><tt><br>
</tt><tt>    mapper->StaticOn();   </tt> <br>
</p>
<p>When i understand it correctly, then we simply visualize every cell (voxel) whose threshold is equal or greater than 1.0 which means we visualize (filter) all voxels which are set (in my vtkImageData voxels which are set are 1, voxels which are not set 0)
 and the vtkDataSetMapper maps these to graphic primitives and this does the rest of the visualization. Not much to do wrong here and that basically should do the trick but it doesn't.</p>
<p><b>Any idea why this does not work correctly all the time and has problems with thin parts?</b><br>
</p>
<p><br>
</p>
<p>I therefore tried another approach by using the vtkGlyph3DMapper based on the example code from<a moz-do-not-send="true" href="https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Glyph3DMapper"><br>
</a></p>
<p><a moz-do-not-send="true" href="https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Glyph3DMapper">https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Glyph3DMapper</a> :</p>
<p><tt><br>
</tt></p>
<p><tt>    vtkNew<vtkPoints> points;</tt><tt><br>
</tt><tt>  </tt><tt><br>
</tt><tt>    for (int x = 0; x < dims[0]; x++)</tt><tt><br>
</tt><tt>    {</tt><tt><br>
</tt><tt>      for (int y = 0; y < dims[1]; y++)</tt><tt><br>
</tt><tt>      {</tt><tt><br>
</tt><tt>        for (int z = 0; z < dims[2]; z++)</tt><tt><br>
</tt><tt>        {</tt><tt><br>
</tt><tt>          char* pixel = static_cast<char*>(voxelImage->GetScalarPointer(x, y, z));</tt><tt><br>
</tt><tt>          </tt><tt><br>
</tt><tt>          if(pixel[0] == 1) // if the voxel is set (1) in the voxel image</tt><tt><br>
</tt><tt>            points->InsertNextPoint(x, y, z);</tt><tt><br>
</tt><tt>        }</tt><tt><br>
</tt><tt>      }</tt><tt><br>
</tt><tt>    }</tt><tt><br>
</tt><tt>    </tt><tt><br>
</tt><tt>    vtkNew<vtkPolyData> polydata;</tt><tt><br>
</tt><tt>    polydata->SetPoints(points);</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt>    vtkNew<vtkPolyData> glyph;</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt>    vtkNew<vtkCubeSource> cubeSource;</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt>    vtkNew<vtkGlyph3DMapper> glyph3Dmapper;</tt><tt><br>
</tt><tt>    glyph3Dmapper->SetSourceConnection(cubeSource->GetOutputPort());</tt><tt><br>
</tt><tt>    glyph3Dmapper->SetInputData(polydata);</tt><tt><br>
</tt><tt>    glyph3Dmapper->Update();</tt><tt><br>
</tt><tt>    </tt><tt><br>
</tt><tt>    actor->SetMapper(glyph3Dmapper);</tt><br>
</p>
<p><br>
The visualization with this approach is a bit slower (probably because it does no backface culling of the backfaces of the cube polygons) but it seems to work correctly even with surface only voxelized meshes:</p>
<img moz-do-not-send="false" src="cid:part6.26C2B470.CB8CC6BB@hotmail.com" alt="bunny ok" height="285" width="281"><img moz-do-not-send="false" src="cid:part7.82E2C5EF.8905BAA6@hotmail.com" alt="teapot" height="263" width="478"><br>
<br>
<br>
I attached a simple working vtk demo with both visualizations and integrated voxelized meshes (no external data files or other dependencies) as a simple cmake/vtk compileable project (<i>PolyDataToImageDataVisualizationVoxel</i>). Maybe it might help other
 vtk users in the future.<br>
<b><br>
</b><b>Are there any other possibilities (maybe faster) to do the visualization with vtk ?</b><br>
<br>
<br>
<br>
Now having a visualization that seems to work, i tried this visualization with the suggested voxelization code from the vtk examples here
<a moz-do-not-send="true" href="https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/PolyDataToImageData/">
https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/PolyDataToImageData/</a><br>
<br>
and while the voxelization is lighting-fast and some example meshes did get correctly voxelized, i also had a lot of meshes whose voxelizations had misclassified voxels (e.g. voxels are set where voxels should not have been set and the opposite (holes)) like
 with the Utah Teapot here:<br>
<br>
<img moz-do-not-send="false" src="cid:part9.08075F2E.5A6E5878@hotmail.com" alt="teapot errors" height="365" width="452"><img moz-do-not-send="false" src="cid:part10.E3E1D7C6.C7610139@hotmail.com" alt="teapot errors
      2" height="410" width="309"><img moz-do-not-send="false" src="cid:part11.49B80C59.BB43C8E6@hotmail.com" alt="teapot
      errors3" height="367" width="390"><br>
<br>
The problem is that for my project i have to find paths through the voxel image. So miscIassified voxels would lead to either wrong paths found (paths which do not really exist like in the first image) or maybe to a situation where no path can be found because
 of holes.<br>
<br>
I attached a compileable cmake/vtk example (<i>PolyDataToImageDataVisualizationSTL</i>) together with some small example stl-mesh-files (teapot etc.) using the example code from the vtk example repository for showing the problem with the given approach there.
<br>
<br>
<br>
<b>Is it possible by tweaking the vtk PolyDataToImageData example code to always get a correct voxelization or is another approach needed?</b><br>
<br>
<br>
If you or anybody else has ideas / suggestions i would really be glad. <br>
Thank for reading if you managed to get this far and have not fallen asleep and thank you very much in advance.<br>
<br>
<br>
Regards<br>
<br>
Berti<br>
<br>
<br>
<div class="moz-cite-prefix">Am 06.06.2018 um 01:49 schrieb David Gobbi:<br>
</div>
<blockquote type="cite" cite="mid:CANwS1=EMYfZbzayTzcqrw_nC4p3QivjZ1_nzsUQ0p7_fm3zhwg@mail.gmail.com">
<div dir="ltr">Hi Berti,
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>The threshold should be set like this, for a threshold halfway between your "inval" and "outval":</div>
<div><br>
</div>
<div>  selector->ThresholdByUpper(0.<wbr>5*(startLabel + endLabel));</div>
<div><br>
</div>
<div>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). </div>
<div><br>
</div>
<div>
<div>  lut->SetTableRange(0, 1);</div>
<div>  lut->SetNumberOfColors(2);</div>
<div><br>
</div>
</div>
<div>Also, your color for "1" was transparent, whereas it has to be opaque in order to properly see a scalar-colored cone.</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>  unsigned char startLabel = outval;</div>
<div>  unsigned char endLabel = inval;</div>
<div><br>
</div>
<div>  vtkNew<vtkThreshold> selector;</div>
<div>  // the call to SetInputArrayToProcess() isn't necessary, the default is fine</div>
<div>  //selector->SetInputArrayToProcess(0, 0, 0,</div>
<div>  //                                 vtkDataObject::FIELD_ASSOCIATION_POINTS,</div>
<div>  //                                 vtkDataSetAttributes::SCALARS);</div>
<div>  selector->SetInputData(voxelImage);</div>
<div>  selector->ThresholdByUpper(0.5*(startLabel + endLabel));</div>
<div>  selector->Update();</div>
<div>    </div>
<div>  vtkNew<vtkDataSetMapper> mapper;</div>
<div>  mapper->SetInputConnection(selector->GetOutputPort());</div>
<div>  mapper->ScalarVisibilityOff();</div>
<div><br>
</div>
<div>  vtkNew<vtkActor> actor;</div>
<div>  actor->SetMapper(mapper);</div>
<div>  actor->GetProperty()->SetColor(0.0, 1.0, 0.0);</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>An image of the resulting cone is attached.</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Tue, Jun 5, 2018 at 1:26 AM, Berti Krüger <span dir="ltr">
<<a href="mailto:berti_krueger@hotmail.com" target="_blank" moz-do-not-send="true">berti_krueger@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div id="m_-1987466976276712091divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hi David,</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">thank you very much for your help.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I tried the example from your link. Unfortunately the result is same as using the <span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                    Color Emoji","Segoe UI
                    Emoji",NotoColorEmoji,"Segoe UI
                    Symbol","Android
                    Emoji",EmojiSymbols;font-size:16px">vtkVoxelModeller:</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                    Color Emoji","Segoe UI
                    Emoji",NotoColorEmoji,"Segoe UI
                    Symbol","Android
                    Emoji",EmojiSymbols;font-size:16px"><br>
</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                    Color Emoji","Segoe UI
                    Emoji",NotoColorEmoji,"Segoe UI
                    Symbol","Android
                    Emoji",EmojiSymbols;font-size:16px"><img size="62429" id="m_-198746697627671209174177_rs|1" style="height:180px;width:177.559px" alt="Screenshot result voxelization" src="cid:part13.D92A4BC6.F7707C31@hotmail.com" class=""><br>
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).</span></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                    Color Emoji","Segoe UI
                    Emoji",NotoColorEmoji,"Segoe UI
                    Symbol","Android
                    Emoji",EmojiSymbols;font-size:16px">For
 the visualization i use Bill Lorensen's example code from here:</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                    Color Emoji","Segoe UI
                    Emoji",NotoColorEmoji,"Segoe UI
                    Symbol","Android
                    Emoji",EmojiSymbols;font-size:16px"><a href="https://lorensen.github.io/VTKExamples/site/Cxx/Medical/GenerateCubesFromLabels/" class="m_-1987466976276712091OWAAutoLink" id="m_-1987466976276712091LPlnk363920" target="_blank" moz-do-not-send="true">https://lorensen.github.io/<wbr>VTKExamples/site/Cxx/Medical/<wbr>GenerateCubesFromLabels/</a></span></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">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 (<a href="https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/PolyDataToImageData/" class="m_-1987466976276712091OWAAutoLink" id="m_-1987466976276712091LPlnk404825" target="_blank" moz-do-not-send="true">https://lorensen.github.io/<wbr>VTKExamples/site/Cxx/PolyData/<wbr>PolyDataToImageData/</a>)
 and the visualization code from the <span style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                    Color Emoji","Segoe UI
                    Emoji",NotoColorEmoji,"Segoe UI
                    Symbol","Android
                    Emoji",EmojiSymbols;font-size:16px">
 Bill Lorensen's </span>example from the link above. I have not changed much.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
Any idea what is going wrong or what can i do get also voxelization of the interior (solid voxelization)?</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
<br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
Thank you very much in advance.<br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
<br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
<br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
Regards</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
<br>
</p>
<p style="font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple
                  Color Emoji","Segoe UI
                  Emoji",NotoColorEmoji,"Segoe UI
                  Symbol","Android
                  Emoji",EmojiSymbols;font-size:16px">
Berti</p>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block;width:98%">
<div id="m_-1987466976276712091divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>Von:</b> David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank" moz-do-not-send="true">david.gobbi@gmail.com</a>><br>
<b>Gesendet:</b> Montag, 28. Mai 2018 23:13<br>
<b>An:</b> Berti Krüger<br>
<b>Cc:</b> <a href="mailto:vtkusers@vtk.org" target="_blank" moz-do-not-send="true">
vtkusers@vtk.org</a><br>
<b>Betreff:</b> Re: [vtkusers] Solid Voxelization with VTK</font>
<div> </div>
</div>
<div>
<div dir="ltr"><span class="">Hi Berti,
<div><br>
</div>
<div>If its a triangulated surface that you want to fill with voxels, use vtkPolyDataToImageStencil:</div>
</span>
<div><a href="https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/PolyDataToImageData/" id="m_-1987466976276712091LPlnk739546" class="m_-1987466976276712091OWAAutoLink" target="_blank" moz-do-not-send="true">https://lorensen.github.io/VTK<wbr>Examples/site/Cxx/PolyData/Pol<wbr>yDataToImageData/</a>
<div id="m_-1987466976276712091LPBorder_GT_15281827222900.5768444366185992" style="margin-bottom:20px;overflow:auto;width:100%;text-indent:0px">
<br>
</div>
<span class=""></span></div>
<span class="">
<div>If its a mesh of 3D elements and you want to sample the elements to create voxels, try vtkResampleToImage.</div>
<div><br>
</div>
<div> - David</div>
<div><br>
</div>
<div><br>
<div class="m_-1987466976276712091x_gmail_extra"><br>
<div class="m_-1987466976276712091x_gmail_quote">On Mon, May 28, 2018 at 4:41 PM, Berti Krüger
<span dir="ltr"><<a href="mailto:berti_krueger@hotmail.com" id="m_-1987466976276712091LPlnk570911" class="m_-1987466976276712091OWAAutoLink" target="_blank" moz-do-not-send="true">berti_krueger@hotmail.com</a>></span> wrote:<br>
<blockquote class="m_-1987466976276712091x_gmail_quote" style="margin:0px 0px 0px
                                0.8ex;border-left:1px solid
                                rgb(204,204,204);padding-left:1ex">
Hello Everyone.<br>
<br>
For my Project i have to voxelize a 3D-Triangle-Mesh. I already found the<br>
vtkVoxelModeller which, while somewhat slow (only around 200 Triangles per<br>
second), works, but only voxelizes the outer shell where the mesh boundary<br>
triangles are. The inner part of the mesh stays hollow. <br>
<br>
Is there some way to get solid voxelization of 3D-Triangle-Meshes out of the<br>
box with VTK ?<br>
<br>
<br>
Thank you very much in advance,<br>
<br>
Berti<br>
</blockquote>
</div>
</div>
</div>
</span></div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>