<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2018-06-14 3:21 GMT+02:00 Berti Krüger <span dir="ltr"><<a href="mailto:berti_krueger@hotmail.com" target="_blank">berti_krueger@hotmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>Hi Elvis,<br>
<br>
thanks for jumping in. As you can see in David's response you were right or at<br>
least close with your assumptions.<br></p></div></blockquote><div>Yep, you can always trust David to have all the nitty gritty details. He's the friendly VTK ninja around here :)</div><div><br> </div><div>Elvis<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div text="#000000" bgcolor="#FFFFFF"><p>
<br>
Regards<span class="HOEnZb"><font color="#888888"><br>
<br>
Berti<br>
</font></span></p><div><div class="h5">
<br>
<div class="m_9095057951200913777moz-cite-prefix">Am 11.06.2018 um 08:50 schrieb Elvis Stansvik:<br>
</div>
<blockquote type="cite">
<div dir="auto">
<div>
<div class="gmail_quote">
<div dir="ltr">Den mån 11 juni 2018 08:33Berti Krüger <<a href="mailto:berti_krueger@hotmail.com" target="_blank">berti_krueger@hotmail.com</a>> skrev:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div 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 href="http://www.patrickmin.com/binvox/" rel="noreferrer" target="_blank">http://www.patrickmin.com/<wbr>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 alt="Teapot missing voxels" width="321" height="197"></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 alt="bunny surface voxelization visualization" width="321" height="276"></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(<wbr>voxelImage);</tt><tt><br>
</tt><tt> selector->ThresholdByUpper(1.<wbr>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(<wbr>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></p>
</div>
</blockquote>
</div>
</div>
<div dir="auto">I'm just jumping in from the side here, and I'm by no means a VTK expert. But I think what you're seeing is simply due to how VTK does volume rendering. It interpolates the given data points, which means you need at least two data points to
get a voxel.</div>
<div dir="auto"><br>
</div>
<div dir="auto">I'm guessing that at the resolution you're doing the voxelization here, your teapot handle is simply too thin to result in even a single voxel.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Think of your data points as a grid of fenceposts. You'll get a voxel in the middle of each 2x2x2 cluster of posts.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Someone correct me if I'm wrong here.</div>
<div dir="auto"><br>
</div>
<div dir="auto">HTH,</div>
<div dir="auto">Elvis</div>
<div dir="auto">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<p><br>
</p>
<p>I therefore tried another approach by using the vtkGlyph3DMapper based on the example code from<a href="https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Glyph3DMapper" rel="noreferrer" target="_blank"><br>
</a></p>
<p><a href="https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Glyph3DMapper" rel="noreferrer" target="_blank">https://www.vtk.org/Wiki/VTK/<wbr>Examples/Cxx/Visualization/<wbr>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-<wbr>>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-><wbr>SetSourceConnection(<wbr>cubeSource->GetOutputPort());</tt><tt><br>
</tt><tt> glyph3Dmapper->SetInputData(<wbr>polydata);</tt><tt><br>
</tt><tt> glyph3Dmapper->Update();</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> actor->SetMapper(<wbr>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 alt="bunny ok" width="281" height="285"><img alt="teapot" width="478" height="263"><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>PolyDataToImageDataVisualizat<wbr>ionVoxel</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 href="https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/PolyDataToImageData/" rel="noreferrer" target="_blank">
https://lorensen.github.io/<wbr>VTKExamples/site/Cxx/PolyData/<wbr>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 alt="teapot errors" width="452" height="365"><img alt="teapot errors 2" width="309" height="410"><img alt="teapot errors3" width="390" height="367"><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>PolyDataToImageDataVisualizat<wbr>ionSTL</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="m_9095057951200913777m_-1354160078478922244moz-cite-prefix">Am 06.06.2018 um 01:49 schrieb David Gobbi:<br>
</div>
<blockquote type="cite">
<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-><wbr>SetInputArrayToProcess(0, 0, 0,</div>
<div> // vtkDataObject::FIELD_<wbr>ASSOCIATION_POINTS,</div>
<div> // vtkDataSetAttributes::<wbr>SCALARS);</div>
<div> selector->SetInputData(<wbr>voxelImage);</div>
<div> selector->ThresholdByUpper(0.<wbr>5*(startLabel + endLabel));</div>
<div> selector->Update();</div>
<div> </div>
<div> vtkNew<vtkDataSetMapper> mapper;</div>
<div> mapper->SetInputConnection(<wbr>selector->GetOutputPort());</div>
<div> mapper->ScalarVisibilityOff();</div>
<div><br>
</div>
<div> vtkNew<vtkActor> actor;</div>
<div> actor->SetMapper(mapper);</div>
<div> actor->GetProperty()-><wbr>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" rel="noreferrer" target="_blank">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_9095057951200913777m_-1354160078478922244m_-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>vtkVoxelModeller:</span></p>
<p style="margin-top:0;margin-bottom:0"><span><br>
</span></p>
<p style="margin-top:0;margin-bottom:0"><span><img size="62429" id="m_9095057951200913777m_-1354160078478922244m_-198746697627671209174177_rs|1" style="height:180px;width:177.559px" alt="Screenshot result voxelization"><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>For the visualization i use Bill Lorensen's example code from here:</span></p>
<p style="margin-top:0;margin-bottom:0"><span><a href="https://lorensen.github.io/VTKExamples/site/Cxx/Medical/GenerateCubesFromLabels/" class="m_9095057951200913777m_-1354160078478922244m_-1987466976276712091OWAAutoLink" id="m_9095057951200913777m_-1354160078478922244m_-1987466976276712091LPlnk363920" rel="noreferrer" target="_blank">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_9095057951200913777m_-1354160078478922244m_-1987466976276712091OWAAutoLink" id="m_9095057951200913777m_-1354160078478922244m_-1987466976276712091LPlnk404825" rel="noreferrer" target="_blank">https://lorensen.github.io/<wbr>VTKExamples/site/Cxx/PolyData/<wbr>PolyDataToImageData/</a>)
and the visualization code from the <span> 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>Any idea what is going wrong or what can i do get also voxelization of the interior (solid voxelization)?</p>
<p><br>
</p>
<p>Thank you very much in advance.<br>
</p>
<p><br>
</p>
<p><br>
</p>
<p>Regards</p>
<p><br>
</p>
<p>Berti</p>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block;width:98%">
<div id="m_9095057951200913777m_-1354160078478922244m_-1987466976276712091divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri,
sans-serif" color="#000000"><b>Von:</b> David Gobbi <<a href="mailto:david.gobbi@gmail.com" rel="noreferrer" target="_blank">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" rel="noreferrer" target="_blank">
vtkusers@vtk.org</a><br>
<b>Betreff:</b> Re: [vtkusers] Solid Voxelization with VTK</font>
<div> </div>
</div>
<div>
<div dir="ltr"><span>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_9095057951200913777m_-1354160078478922244m_-1987466976276712091LPlnk739546" class="m_9095057951200913777m_-1354160078478922244m_-1987466976276712091OWAAutoLink" rel="noreferrer" target="_blank">https://lorensen.github.io/<wbr>VTKExamples/site/Cxx/PolyData/<wbr>PolyDataToImageData/</a>
<div id="m_9095057951200913777m_-1354160078478922244m_-1987466976276712091LPBorder_GT_15281827222900.5768444366185992" style="margin-bottom:20px;overflow:auto;width:100%;text-indent:0px">
<br>
</div>
<span></span></div>
<span>
<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_9095057951200913777m_-1354160078478922244m_-1987466976276712091x_gmail_extra"><br>
<div class="m_9095057951200913777m_-1354160078478922244m_-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_9095057951200913777m_-1354160078478922244m_-1987466976276712091LPlnk570911" class="m_9095057951200913777m_-1354160078478922244m_-1987466976276712091OWAAutoLink" rel="noreferrer" target="_blank">berti_krueger@hotmail.com</a>></span>
wrote:<br>
<blockquote class="m_9095057951200913777m_-1354160078478922244m_-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>
</div>
______________________________<wbr>_________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer noreferrer" target="_blank">
www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer noreferrer" target="_blank">
http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer
noreferrer" target="_blank">
http://www.vtk.org/Wiki/VTK_<wbr>FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer noreferrer" target="_blank">
http://markmail.org/search/?q=<wbr>vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer noreferrer" target="_blank">https://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
</blockquote>
</div>
</div>
</div>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div></div>