<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">Hi,</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">I have a very basic question: what is the right way to create a volumetric cube or voxel with a certain scalar value associated with it. The way I've done it so far is show below with Python code. It just seems a little bit awkward to me, that I have to define quite a bit of points instead of just 8 to draw a cube with vtkVolumeRayCastCompositeFunction. If I use N = 2 (that is 8 points) it does not looks like a cube any more. It looks like a cube again if I switch to vtkVolumeRayCastIsosurfaceFunction or vtkVolumeRayCastMIPFunction, but transparency and color function do not work in the first case and shade in the second. I'm not sure if I'm drawing a cube in a right way.
</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">So my question is: how one should draw a volumetric cube or voxel by defining just 8 points, so the transparency and color can be set according to a scalar value, and with shades?
</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">I'm planning to use those cubes/voxels for a 3D object reconstruction (with non-hexahedral shape), which was cut into bunch of cubes. Scalar values associated with those cubes represent the intensities of a certain measured parameter.
</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">Thank you for any advice,</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">Vlad</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">import vtk</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">ren = vtk.vtkRenderer()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">renWin = vtk.vtkRenderWindow()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">renWin.AddRenderer(ren)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">iren = vtk.vtkRenderWindowInteractor()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">iren.SetRenderWindow(renWin)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">N = 10 #number of points along a dimension.</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">#cube looks awkward if N < 4</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">imData = vtk.vtkImageData()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">imData.SetDimensions(N,N,N)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">scalars = vtk.vtkUnsignedShortArray()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">scalars.SetNumberOfValues(N**3)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">value = 100 #some fixed value to assign</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">for x in range(N**3):</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"><span style="mso-tab-count: 1"> </span>scalars.SetValue(x,value)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><span style="mso-tab-count: 1"><font face="Times New Roman"> </font></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">imData.GetPointData().SetScalars(scalars)<span style="mso-tab-count: 3"> </span></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">opacityTransferFunction = vtk.vtkPiecewiseFunction()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">opacityTransferFunction.AddPoint(0.0, 0.3)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">opacityTransferFunction.AddPoint(255.0, 0.3)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">colorTransferFunction = vtk.vtkColorTransferFunction()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">colorTransferFunction.AddRGBPoint(0.0, 1,0,0)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">colorTransferFunction.AddRGBPoint(127.0, 0,1,0)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">colorTransferFunction.AddRGBPoint(255.0, 0,0,1)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeProperty = vtk.vtkVolumeProperty()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeProperty.SetScalarOpacity(opacityTransferFunction)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeProperty.SetColor(colorTransferFunction)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeProperty.ShadeOn()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeProperty.SetInterpolationTypeToNearest()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">##rayCastFunction = vtk.vtkVolumeRayCastMIPFunction()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">##rayCastFunction = vtk.vtkVolumeRayCastIsosurfaceFunction()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeMapper = vtk.vtkVolumeRayCastMapper()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeMapper.SetVolumeRayCastFunction(rayCastFunction)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volumeMapper.SetInput(imData)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volume = vtk.vtkVolume()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volume.SetMapper(volumeMapper)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">volume.SetProperty(volumeProperty)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">ren.AddVolume(volume)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">ren.SetBackground(0.5,0.5,0.5)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">renWin.SetSize(600,600)</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">iren.Initialize()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">renWin.Render()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman">iren.Start()</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman"> </font></p>