First my final goal: given a point cloud, downsample it, and visualize the resultings voxels (i.e. 1 if containing any point, 0 otherwise) in an efficient way, using Python-VTK. I already succeeded in doing it with my own downsampling code, and a voxel visualization mechanism crafted from vtkUnstructuredGrid, vtkVoxel and vtkPoints. However I have the strong feeling that there must be a more efficient way of doing it, and from what I read I gather that a vtkImageData, rendered with vtkMarchingCubes might work well.<br>

<br>I tried really hard to build an understanding of those objects by triangulating the many pieces of code and information I gathered everywhere, but I just can&#39;t make it this time. The toy model I&#39;m trying to first build is a simple 3x3x3 grid where the 3 diagonal voxels would be &quot;on&quot;:<br>

<br><font face="&#39;courier new&#39;, monospace">import vtk<br>n = 3<br>grid = vtk.vtkImageData()<br>grid.SetDimensions(n, n, n)<br>grid.SetOrigin(0, 0, 0)<br>grid.SetSpacing(1, 1, 1)<br></font><br>From there, I tried two things: first, to set the desired voxels explicitly:<div>

<br></div><div><div><font face="&#39;courier new&#39;, monospace">grid.SetScalarComponentFromFloat(0,0,0,0,1)</font></div><div><font face="&#39;courier new&#39;, monospace">grid.SetScalarComponentFromFloat(1,1,1,0,1)</font></div>

<div><font face="&#39;courier new&#39;, monospace">grid.SetScalarComponentFromFloat(2,2,2,0,1)</font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">The other way I tried is to set the scalar field:</font></div>

<div><font face="arial, helvetica, sans-serif"><br></font></div><div><div style="font-family:&#39;courier new&#39;,monospace">scalars = vtk.vtkUnsignedShortArray()</div><div style="font-family:&#39;courier new&#39;,monospace">

for i in range(n):</div><div style="font-family:&#39;courier new&#39;,monospace">    for j in range(n):</div><div style="font-family:&#39;courier new&#39;,monospace">        for k in range(n):</div><div style="font-family:&#39;courier new&#39;,monospace">

            scalars.InsertNextTuple1(1 if i == j == k else 0)</div><div style="font-family:&#39;courier new&#39;,monospace">grid.GetPointData().SetScalars(scalars)</div><div style="font-family:&#39;courier new&#39;,monospace">

<br></div><div><font face="arial, helvetica, sans-serif">But then when I try to render the resulting grid with marching cubes, it always yields some strange shape, very far from my goal:</font></div></div><div><font face="arial, helvetica, sans-serif"><br>

</font></div><div><div><font face="&#39;courier new&#39;, monospace">surface = vtk.vtkMarchingCubes()</font></div><div><font face="&#39;courier new&#39;, monospace">surface.SetInput(grid)</font></div><div><font face="&#39;courier new&#39;, monospace">surface.SetValue(0, 0.5)</font></div>

<div><font face="&#39;courier new&#39;, monospace">mapper = vtk.vtkPolyDataMapper()</font></div><div><font face="&#39;courier new&#39;, monospace">mapper.SetInputConnection(surface.GetOutputPort())</font></div><div><font face="&#39;courier new&#39;, monospace">actor = vtk.vtkActor()</font></div>

<div><font face="&#39;courier new&#39;, monospace">actor.SetMapper(mapper)</font></div><div><font face="&#39;courier new&#39;, monospace">ren = vtk.vtkRenderer()</font></div><div><font face="&#39;courier new&#39;, monospace">renWin = vtk.vtkRenderWindow()</font></div>

<div><font face="&#39;courier new&#39;, monospace">renWin.AddRenderer(ren)</font></div><div><font face="&#39;courier new&#39;, monospace">iren = vtk.vtkRenderWindowInteractor()</font></div><div><font face="&#39;courier new&#39;, monospace">iren.SetRenderWindow(renWin)</font></div>

<div><font face="&#39;courier new&#39;, monospace">ren.AddActor(actor)</font></div><div><font face="&#39;courier new&#39;, monospace">iren.Initialize()</font></div><div><font face="&#39;courier new&#39;, monospace">renWin.Render()</font></div>

<div><font face="&#39;courier new&#39;, monospace">iren.Start()</font></div><div style="font-family:arial,helvetica,sans-serif"><br></div></div><div>I&#39;d greatly appreciate any help, thanks in advance.</div></div><div>

<br></div><div>Christian</div><div><br></div>