<div dir="ltr">Hi!<div><br></div><div>Thanks for your reply.</div><div><div>My doubt was about how to pass the 'Field 3' to the probe filter. I made some adjust based in your help. However, the output shows two solid cube instead of the points from my segmented dataset. </div><div><br></div><div>I am sending the code and the screenshot of the output. Thanks again :-)</div></div><div><br></div><div><div>reader = vtk.vtkDelimitedTextReader() </div><div>reader.SetFieldDelimiterCharacters(' ') </div><div>reader.DetectNumericColumnsOn() </div><div>reader.SetFileName('sample.csv')</div><div>reader.MergeConsecutiveDelimitersOn() </div><div>reader.Update()</div></div><div><div><br></div><div>tableToPoints = vtk.vtkTableToPolyData() </div><div>tableToPoints.SetInputConnection(reader.GetOutputPort()) </div><div>tableToPoints.SetXColumn('Field 0') </div><div>tableToPoints.SetYColumn('Field 1') </div><div>tableToPoints.SetZColumn('Field 2') </div><div>tableToPoints.Update()</div><div><br></div><div>imageData = vtk.vtkImageData() </div><div>imageData.SetDimensions(3, 3, 3) </div><div>imageData.SetOrigin(0.0, 0.0, 0.0) </div><div>imageData.SetSpacing(1.0, 1.0, 1.0) </div><div>imageData.Update()</div><div><br></div><div>probeFilter = vtk.vtkProbeFilter() </div><div>probeFilter.SetSourceConnection(tableToPoints.GetOutputPort()) </div><div>probeFilter.SetInput(imageData) </div><div>probeFilter.Update() </div><div><br></div><div>probeFilter.GetOutput().GetPointData().SetActiveScalars('Field 3') </div><div>scalarRange = probeFilter.GetOutput().GetPointData().GetScalars().GetRange() </div><div><br></div><div>writer = vtk.vtkXMLImageDataWriter() </div><div>writer.SetInput(probeFilter.GetOutput()) </div><div>writer.SetFileName('out.vti') </div><div>writer.Write() </div><div><br></div><div># Create transfer mapping scalar value to opacity. </div><div>opacityTransferFunction = vtk.vtkPiecewiseFunction() </div><div>opacityTransferFunction.AddPoint(scalarRange[0], 0.0) </div><div>opacityTransferFunction.AddPoint(scalarRange[1], 0.5) </div><div><br></div><div># Create transfer mapping scalar value to color.</div><div>colorTransferFunction = vtk.vtkColorTransferFunction() </div><div>colorTransferFunction.AddRGBPoint(scalarRange[0], 0.0, 0.0, 1.0) </div><div>colorTransferFunction.AddRGBPoint((scalarRange[0]+scalarRange[1])*0.5, 0.0, 1.0, 0.0) </div><div>colorTransferFunction.AddRGBPoint(scalarRange[1], 1.0, 0.0, 0.0) </div><div><br></div><div># The property describes how the data will look.</div><div>volumeProperty = vtk.vtkVolumeProperty()</div><div>volumeProperty.SetColor(colorTransferFunction)</div><div>volumeProperty.SetScalarOpacity(opacityTransferFunction)</div><div>volumeProperty.SetScalarOpacityUnitDistance(1.73205080757) </div><div>volumeProperty.SetInterpolationTypeToLinear()</div><div>volumeProperty.ShadeOn()</div><div><br></div><div># vtkVolumeRayCastMapper need data of type unsigned char or unsigned short</div><div>cast = vtk.vtkImageCast()</div><div>cast.SetInputConnection(probeFilter.GetOutputPort())</div><div>cast.SetOutputScalarTypeToUnsignedChar()</div><div>cast.Update()</div><div><br></div><div>## The mapper / ray cast function know how to render the data</div><div>compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()</div><div>volumeMapper = vtk.vtkVolumeRayCastMapper()</div><div>volumeMapper.SetVolumeRayCastFunction(compositeFunction)</div><div>volumeMapper.SetInputConnection(cast.GetOutputPort())</div><div><br></div><div><br></div><div>#The volume holds the mapper and the property.</div><div>volume = vtk.vtkVolume()</div><div>volume.SetMapper(volumeMapper)</div><div>volume.SetProperty(volumeProperty)</div><div><br></div><div>#Create the standard renderer, render window and interactor</div><div>ren = vtk.vtkRenderer()</div><div><br></div><div>renWin = vtk.vtkRenderWindow()</div><div>renWin.AddRenderer(ren)</div><div><br></div><div>iren = vtk.vtkRenderWindowInteractor()</div><div>iren.SetRenderWindow(renWin)</div><div><br></div><div>ren.AddVolume(volume)</div><div>ren.SetBackground(1, 1, 1)</div><div>renWin.SetSize(600, 600)</div><div>renWin.Render()</div><div><br></div><div>iren.Initialize()</div><div>renWin.Render()</div><div>iren.Start()</div></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 26, 2018 at 9:35 PM, kenichiro yoshimi <span dir="ltr"><<a href="mailto:rccm.kyoshimi@gmail.com" target="_blank">rccm.kyoshimi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Your question is not clear enough. If you possible, can you post your<br>
code? I don't have a problem with volume rendering in my code.<br>
<br>
----<br>
<span class="">import vtk<br>
<br>
<br>
def main():<br>
<br>
reader = vtk.vtkDelimitedTextReader()<br>
reader.SetFileName('sample.<wbr>csv')<br>
reader.DetectNumericColumnsOn(<wbr>)<br>
reader.<wbr>SetFieldDelimiterCharacters(' ')<br>
reader.<wbr>MergeConsecutiveDelimitersOn()<br>
<br>
tableToPoints = vtk.vtkTableToPolyData()<br>
tableToPoints.<wbr>SetInputConnection(reader.<wbr>GetOutputPort())<br>
tableToPoints.SetXColumn('<wbr>Field 0')<br>
tableToPoints.SetYColumn('<wbr>Field 1')<br>
tableToPoints.SetZColumn('<wbr>Field 2')<br>
<br>
imageData = vtk.vtkImageData()<br>
imageData.SetDimensions(3, 3, 3)<br>
imageData.SetOrigin(0.0, 0.0, 0.0)<br>
imageData.SetSpacing(1.0, 1.0, 1.0)<br>
<br>
probeFilter = vtk.vtkProbeFilter()<br>
probeFilter.<wbr>SetSourceConnection(<wbr>tableToPoints.GetOutputPort())<br>
probeFilter.SetInputData(<wbr>imageData)<br>
probeFilter.Update()<br>
<br>
writer = vtk.vtkXMLImageDataWriter()<br>
writer.SetInputData(<wbr>probeFilter.GetOutput())<br>
writer.SetFileName('out.vti')<br>
writer.Write()<br>
<br>
</span> probeFilter.GetOutput().<wbr>GetPointData().<wbr>SetActiveScalars('Field 3')<br>
range = probeFilter.GetOutput().<wbr>GetPointData().GetScalars().<wbr>GetRange()<br>
<br>
colors = vtk.vtkNamedColors()<br>
<br>
# Create the standard renderer, render window<br>
# and interactor.<br>
ren = vtk.vtkRenderer()<br>
<br>
renWin = vtk.vtkRenderWindow()<br>
renWin.AddRenderer(ren)<br>
<br>
iren = vtk.vtkRenderWindowInteractor(<wbr>)<br>
iren.SetRenderWindow(renWin)<br>
<br>
# Create transfer mapping scalar value to opacity.<br>
opacityTransferFunction = vtk.vtkPiecewiseFunction()<br>
opacityTransferFunction.<wbr>AddPoint(range[0], 0.0)<br>
opacityTransferFunction.<wbr>AddPoint(range[1], 1.0)<br>
<br>
# Create transfer mapping scalar value to color.<br>
colorTransferFunction = vtk.vtkColorTransferFunction()<br>
colorTransferFunction.<wbr>AddRGBPoint(range[0], 0.0, 0.0, 1.0)<br>
colorTransferFunction.<wbr>AddRGBPoint((range[0]+range[1]<wbr>)*0.5, 0.0, 1.0, 0.0)<br>
colorTransferFunction.<wbr>AddRGBPoint(range[1], 1.0, 0.0, 0.0)<br>
<br>
# The property describes how the data will look.<br>
volumeProperty = vtk.vtkVolumeProperty()<br>
volumeProperty.SetColor(<wbr>colorTransferFunction)<br>
volumeProperty.<wbr>SetScalarOpacity(<wbr>opacityTransferFunction)<br>
volumeProperty.<wbr>SetScalarOpacityUnitDistance(<wbr>1.73205080757)<br>
volumeProperty.<wbr>SetInterpolationTypeToLinear()<br>
<br>
# The mapper / ray cast function know how to render the data.<br>
volumeMapper = vtk.vtkSmartVolumeMapper()<br>
volumeMapper.<wbr>SetInputConnection(<wbr>probeFilter.GetOutputPort())<br>
volumeMapper.<wbr>SetBlendModeToComposite()<br>
<br>
# The volume holds the mapper and the property and<br>
# can be used to position/orient the volume.<br>
volume = vtk.vtkVolume()<br>
volume.SetMapper(volumeMapper)<br>
volume.SetProperty(<wbr>volumeProperty)<br>
<br>
ren.AddVolume(volume)<br>
<br>
ren.SetBackground(colors.<wbr>GetColor3d("White"))<br>
ren.GetActiveCamera().<wbr>ParallelProjectionOn()<br>
ren.ResetCameraClippingRange()<br>
ren.ResetCamera()<br>
<br>
renWin.SetSize(600, 600)<br>
renWin.Render()<br>
<br>
iren.Start()<br>
<span class=""><br>
<br>
if __name__ == '__main__':<br>
main()<br>
</span>----<br>
<br>
Regards<br>
2018年7月26日(木) 0:15 Lizeth Castellanos <<a href="mailto:castellanoslizan@gmail.com">castellanoslizan@gmail.com</a>>:<br>
<div class="HOEnZb"><div class="h5">><br>
> Thanks for your answers!<br>
><br>
> For the case 2) I have one more question: How can I add the scalar values from the intensity ('Field 3') to the data?<br>
><br>
> I have added those two lines to your code:<br>
><br>
> scalar = probeFilter.GetOutput().<wbr>GetPointData().GetArray('Field 3')<br>
> probeFilter.GetOutput().<wbr>GetPointData().SetScalars(<wbr>scalar)<br>
><br>
> But when I render the volume, nothing is displayed in the render window.<br>
><br>
> Thanks<br>
><br>
> Lizeth<br>
><br>
><br>
><br>
><br>
><br>
> On Tue, Jul 24, 2018 at 11:29 PM, kenichiro yoshimi <<a href="mailto:rccm.kyoshimi@gmail.com">rccm.kyoshimi@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> 1) You need to specify PYTHON_INCLUDE_DIR and PYTHON_LIBRARY to suit<br>
>> your own system in the 'advanced options' in cmake.<br>
>><br>
>> PYTHON_INCLUDE_DIR will be the name of the directory containing the Python.h:<br>
>> e.g. /usr/include/python2.7<br>
>> PYTHON_LIBRARY will be the full path to <a href="http://libpython2.7.so" rel="noreferrer" target="_blank">libpython2.7.so</a> (or.a):<br>
>> e.g. /usr/lib64/<a href="http://libpython2.7.so" rel="noreferrer" target="_blank">libpython2.7.so</a><br>
>><br>
>> 2) For example, if you apply vtkProbeFilter to sample.csv in the<br>
>> previous my post, script is something like below.<br>
>><br>
>> ---<br>
>> import vtk<br>
>><br>
>><br>
>> def main():<br>
>><br>
>> reader = vtk.vtkDelimitedTextReader()<br>
>> reader.SetFileName('sample.<wbr>csv')<br>
>> reader.DetectNumericColumnsOn(<wbr>)<br>
>> reader.<wbr>SetFieldDelimiterCharacters(' ')<br>
>> reader.<wbr>MergeConsecutiveDelimitersOn()<br>
>><br>
>> tableToPoints = vtk.vtkTableToPolyData()<br>
>> tableToPoints.<wbr>SetInputConnection(reader.<wbr>GetOutputPort())<br>
>> tableToPoints.SetXColumn('<wbr>Field 0')<br>
>> tableToPoints.SetYColumn('<wbr>Field 1')<br>
>> tableToPoints.SetZColumn('<wbr>Field 2')<br>
>><br>
>> imageData = vtk.vtkImageData()<br>
>> imageData.SetDimensions(3, 3, 3)<br>
>> imageData.SetOrigin(0.0, 0.0, 0.0)<br>
>> imageData.SetSpacing(1.0, 1.0, 1.0)<br>
>><br>
>> probeFilter = vtk.vtkProbeFilter()<br>
>> probeFilter.<wbr>SetSourceConnection(<wbr>tableToPoints.GetOutputPort())<br>
>> probeFilter.SetInputData(<wbr>imageData)<br>
>> probeFilter.Update()<br>
>><br>
>> writer = vtk.vtkXMLImageDataWriter()<br>
>> writer.SetInputData(<wbr>probeFilter.GetOutput())<br>
>> writer.SetFileName('out.vti')<br>
>> writer.Write()<br>
>><br>
>><br>
>> if __name__ == '__main__':<br>
>> main()<br>
>> ---<br>
>><br>
>> For your reference.<br>
>> 2018年7月25日(水) 4:10 Lizeth Castellanos <<a href="mailto:castellanoslizan@gmail.com">castellanoslizan@gmail.com</a>>:<br>
>> ><br>
>> > Thanks for your help Kenichiro Yoshimi<br>
>> ><br>
>> > I was able to reproduce some part of your code. However, I encountered new issues.<br>
>> ><br>
>> > 1)I have all my project under VTK 5.10.1 with python 2.7.12 in linux. I got this error: 'module' object has no attribute 'vtkResampleToImage'.<br>
>> > So I guess that the vtkResampleToImage class is not avaliable for my VTK version.<br>
>> > I tried to build a newer VTK version but I didn't get success. I tried with VTK 7.1.1 and I got errors related to the python libs Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS).<br>
>> ><br>
>> > 2) I read that vtkResampleToImage samples a dataset on a uniform grid and it internally uses vtkProbeFilter to do the probing. So, Is there any way to use vtkProbeFilter instead of vtkResampleToImage?<br>
>> > I have tested some examples from vtkProbeFilter but I am confused about how use it in my specific problem.<br>
>> ><br>
>> > Thanks,<br>
>> ><br>
>> > Lizeth<br>
>> ><br>
>> > On Thu, Jul 19, 2018 at 12:38 AM, kenichiro yoshimi <<a href="mailto:rccm.kyoshimi@gmail.com">rccm.kyoshimi@gmail.com</a>> wrote:<br>
>> >><br>
>> >> Hi Lizeth,<br>
>> >><br>
>> >> Because vtkDelimitedTextReader outputs a vtkTable, you firstly need to<br>
>> >> convert it to a vtkPolyData using vtkTableToPolyData. And then you can<br>
>> >> use vtkResampleToImage to map the polyData to vtkImageData.<br>
>> >><br>
>> >> ---sample.csv---<br>
>> >> 0 0 0 60.7635<br>
>> >> 1 0 0 107.555<br>
>> >> 2 0 0 80.5241<br>
>> >> 0 1 0 85.9694<br>
>> >> 1 1 0 156.706<br>
>> >> 2 1 0 105.73<br>
>> >> 0 2 0 37.3531<br>
>> >> 1 2 0 84.1445<br>
>> >> 2 2 0 57.1137<br>
>> >> 0 0 1 100.634<br>
>> >> 1 0 1 171.37<br>
>> >> 2 0 1 120.395<br>
>> >> 0 1 1 149.785<br>
>> >> 1 1 1 260<br>
>> >> 2 1 1 169.546<br>
>> >> 0 2 1 77.2238<br>
>> >> 1 2 1 147.96<br>
>> >> 2 2 1 96.9844<br>
>> >> 0 0 2 60.7635<br>
>> >> 1 0 2 107.555<br>
>> >> 2 0 2 80.5241<br>
>> >> 0 1 2 85.9694<br>
>> >> 1 1 2 156.706<br>
>> >> 2 1 2 105.73<br>
>> >> 0 2 2 37.3531<br>
>> >> 1 2 2 84.1445<br>
>> >> 2 2 2 57.1137<br>
>> >><br>
>> >> ---<br>
>> >> import vtk<br>
>> >><br>
>> >><br>
>> >> def main():<br>
>> >> colors = vtk.vtkNamedColors()<br>
>> >><br>
>> >> reader = vtk.vtkDelimitedTextReader()<br>
>> >> reader.SetFileName('sample.<wbr>csv')<br>
>> >> reader.DetectNumericColumnsOn(<wbr>)<br>
>> >> reader.<wbr>SetFieldDelimiterCharacters(' ')<br>
>> >> reader.<wbr>MergeConsecutiveDelimitersOn()<br>
>> >><br>
>> >> tableToPoints = vtk.vtkTableToPolyData()<br>
>> >> tableToPoints.<wbr>SetInputConnection(reader.<wbr>GetOutputPort())<br>
>> >> tableToPoints.SetXColumn('<wbr>Field 0')<br>
>> >> tableToPoints.SetYColumn('<wbr>Field 1')<br>
>> >> tableToPoints.SetZColumn('<wbr>Field 2')<br>
>> >><br>
>> >> resample = vtk.vtkResampleToImage()<br>
>> >> resample.SetInputConnection(<wbr>tableToPoints.GetOutputPort())<br>
>> >> resample.<wbr>SetSamplingDimensions(3, 3, 3)<br>
>> >> resample.Update()<br>
>> >><br>
>> >> scalar = resample.GetOutput().<wbr>GetPointData().GetArray('Field 3')<br>
>> >> resample.GetOutput().<wbr>GetPointData().SetScalars(<wbr>scalar)<br>
>> >><br>
>> >> writer = vtk.vtkMetaImageWriter()<br>
>> >> writer.SetInputData(resample.<wbr>GetOutput())<br>
>> >> writer.SetFileName('out.mha')<br>
>> >> writer.SetCompression(True)<br>
>> >> writer.Write()<br>
>> >><br>
>> >><br>
>> >> if __name__ == '__main__':<br>
>> >> main()<br>
>> >> ---<br>
>> >><br>
>> >> Best<br>
>> >> 2018年7月19日(木) 3:43 Lizeth Castellanos <<a href="mailto:castellanoslizan@gmail.com">castellanoslizan@gmail.com</a>>:<br>
>> >> ><br>
>> >> > Hi!<br>
>> >> ><br>
>> >> > I'd like to copy image data from a textfile (csv) into vtkImageData.<br>
>> >> > The textfile have voxel values for x,y,z and image intensity. I already have read the textfile into VTK with the vtkDelimitedTextReader class:<br>
>> >> ><br>
>> >> > Table loaded from CSV file:<br>
>> >> > +-----------+-----------+-----<wbr>------+------------+<br>
>> >> > | Field 0 | Field 1 | Field 2 | Field 3 |<br>
>> >> > +-----------+-----------+-----<wbr>------+------------+<br>
>> >> > | 510 | 291 | 0 | 32 |<br>
>> >> > | 511 | 291 | 0 | 128 |<br>
>> >> > | 510 | 292 | 0 | 104 |<br>
>> >> > | 511 | 292 | 0 | 104 |<br>
>> >> > | 510 | 293 | 0 | 40 |<br>
>> >> > | 511 | 293 | 0 | 240 |<br>
>> >> > | 510 | 294 | 0 | 104 |<br>
>> >> > | 511 | 294 | 0 | 96 |<br>
>> >> > | 506 | 295 | 0 | 64 |<br>
>> >> > | 507 | 295 | 0 | 16 |<br>
>> >> > .....<br>
>> >> > .....<br>
>> >> > The file is an exported segmented dataset.<br>
>> >> ><br>
>> >> > I am following the tips from this similar question <a href="http://vtk.1045678.n5.nabble.com/importing-image-data-into-VTK-from-textfile-mimics-td1243332.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.<wbr>com/importing-image-data-into-<wbr>VTK-from-textfile-mimics-<wbr>td1243332.html</a><br>
>> >> > I have created an appropriate vtkimagedata (volume):<br>
>> >> ><br>
>> >> > imageData = vtk.vtkImageData()<br>
>> >> > imageData.SetDimensions(512, 512, 192)<br>
>> >> > imageData.SetOrigin(0.0, 0.0, 0.0)<br>
>> >> > imageData.SetSpacing(1, 1, 1)<br>
>> >> > imageData.<wbr>SetNumberOfScalarComponents(1)<br>
>> >> > imageData.Update()<br>
>> >> ><br>
>> >> > However I don't know how to copy the data loaded from vtkDelimitedTextReader into vtkImageData. How do I copy the x,y,z voxel values into vtkImageData? How do I copy the intensity valuesVtkImageData?<br>
>> >> ><br>
>> >> > Any help provided for this would be greatly appreciated!<br>
>> >> ><br>
>> >> > Lizeth<br>
>> >> ><br>
>> >> ><br>
>> >> > ______________________________<wbr>_________________<br>
>> >> > Powered by <a href="http://www.kitware.com" rel="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" 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" 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" 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" target="_blank">https://public.kitware.com/<wbr>mailman/listinfo/vtkusers</a><br>
>> ><br>
>> ><br>
>> ><br>
>> ><br>
>> > --<br>
>> ><br>
>> ><br>
>> ><br>
><br>
><br>
><br>
><br>
> --<br>
><br>
><br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Lizeth Castellanos.</div><div>PhD Student </div><div>Federal University of Rio Grande do Sul (UFRGS)</div><div><br></div><div><br></div></div></div></div></div></div></div></div></div>
</div>