[vtkusers] Copy image data into vtkImageData from a textfile

kenichiro yoshimi rccm.kyoshimi at gmail.com
Thu Aug 2 16:59:56 EDT 2018


Hello,

Did you set the dimensions based on your own data?  It looks all dimensions
indicate 3.

Thanks

2018年8月3日(金) 4:50 Lizeth Castellanos <castellanoslizan at gmail.com>:

> Hi,
>
> Thanks for help me.
> I have confirmed the out.vti using Paraview's volume rendering. I don't
> know what is wrong, I get a solid cube again :-(
> I am attaching a screenshot. Could you see, please?
>
> Thanks
> Lizeth
>
> On Wed, Aug 1, 2018 at 10:20 PM, kenichiro yoshimi <
> rccm.kyoshimi at gmail.com> wrote:
>
>> Hi,
>>
>> Thanks for trying.
>> Could you confirm if out.vti is visualized properly using ParaView's
>> volume rendering?
>>
>> Regards
>> 2018年8月2日(木) 6:12 Lizeth Castellanos <castellanoslizan at gmail.com>:
>> >
>> > Hi,
>> >
>> > I got VTK 7.1.1 in my computer, finally! So, I have tested the two
>> solutions that you have suggested:
>> > 1) using vtkProbeFilter
>> > 2) using vtkResampleToImage
>> >
>> > 1) I  have adjusted the image dimensions according to my own data and I
>> am using  vtkSmartVolumeMapper, instead of vtkVolumeRaycastMapper.
>> > No errors are generated in the terminal. However, I have been waiting
>> for several minutes and nothing happens.
>> > Do you have any idea what is wrong?
>> >
>> >
>> > csvfile="directory path to my csv file/sample.csv"
>> >
>> > reader = vtk.vtkDelimitedTextReader()
>> > reader.SetFieldDelimiterCharacters(" ")
>> > reader.DetectNumericColumnsOn()
>> > reader.SetFileName(csvfile)
>> > reader.MergeConsecutiveDelimitersOn()
>> > reader.Update()
>> >
>> > tableToPoints = vtk.vtkTableToPolyData()
>> > tableToPoints.SetInputConnection(reader.GetOutputPort())
>> > tableToPoints.SetXColumn('Field 0')
>> > tableToPoints.SetYColumn('Field 1')
>> > tableToPoints.SetZColumn('Field 2')
>> >
>> > imageData = vtk.vtkImageData()
>> > imageData.SetDimensions(512, 512, 192)
>> > imageData.SetOrigin(0.0, 0.0, 0.0)
>> > imageData.SetSpacing(1.0, 1.0, 1.0)
>> >
>> > probeFilter = vtk.vtkProbeFilter()
>> > probeFilter.SetSourceConnection(tableToPoints.GetOutputPort())
>> > probeFilter.SetInputData(imageData)
>> > probeFilter.Update()
>> >
>> > writer = vtk.vtkXMLImageDataWriter()
>> > writer.SetInputData(probeFilter.GetOutput())
>> > writer.SetFileName('out.vti')
>> > writer.Write()
>> >
>> > probeFilter.GetOutput().GetPointData().SetActiveScalars('Field 3')
>> > range = probeFilter.GetOutput().GetPointData().GetScalars().GetRange()
>> >
>> > colors = vtk.vtkNamedColors()
>> >
>> > # Create the standard renderer, render window
>> > # and interactor.
>> > ren = vtk.vtkRenderer()
>> >
>> > renWin = vtk.vtkRenderWindow()
>> > renWin.AddRenderer(ren)
>> >
>> > iren = vtk.vtkRenderWindowInteractor()
>> > iren.SetRenderWindow(renWin)
>> >
>> > # Create transfer mapping scalar value to opacity.
>> > opacityTransferFunction = vtk.vtkPiecewiseFunction()
>> > opacityTransferFunction.AddPoint(range[0], 0.0)
>> > opacityTransferFunction.AddPoint(range[1], 1.0)
>> >
>> > # Create transfer mapping scalar value to color.
>> > colorTransferFunction = vtk.vtkColorTransferFunction()
>> > colorTransferFunction.AddRGBPoint(range[0], 0.0, 0.0, 1.0)
>> > colorTransferFunction.AddRGBPoint((range[0]+range[1])*0.5, 0.0, 1.0,
>> 0.0)
>> > colorTransferFunction.AddRGBPoint(range[1], 1.0, 0.0, 0.0)
>> >
>> > # The property describes how the data will look.
>> > volumeProperty = vtk.vtkVolumeProperty()
>> > volumeProperty.SetColor(colorTransferFunction)
>> > volumeProperty.SetScalarOpacity(opacityTransferFunction)
>> > volumeProperty.SetScalarOpacityUnitDistance(1.73205080757)
>> > volumeProperty.SetInterpolationTypeToLinear()
>> >
>> > # The mapper / ray cast function know how to render the data.
>> > volumeMapper = vtk.vtkSmartVolumeMapper()
>> > volumeMapper.SetInputConnection(probeFilter.GetOutputPort())
>> > volumeMapper.SetBlendModeToComposite()
>> >
>> > # The volume holds the mapper and the property and
>> > # can be used to position/orient the volume.
>> > volume = vtk.vtkVolume()
>> > volume.SetMapper(volumeMapper)
>> > volume.SetProperty(volumeProperty)
>> >
>> > ren.AddVolume(volume)
>> >
>> > ren.SetBackground(colors.GetColor3d("White"))
>> > ren.GetActiveCamera().ParallelProjectionOn()
>> > ren.ResetCameraClippingRange()
>> > ren.ResetCamera()
>> >
>> > renWin.SetSize(600, 600)
>> > renWin.Render()
>> > iren.Start()
>> >
>> >
>> > 2) I have tested the vtkResampleToImage class, (the solution that you
>> suggest at the beginning of this thread). However, I get a solid a cube as
>> output.
>> > Do you have any idea why that happens?
>> >
>> > csvfile="directory path to my csv file/sample.csv"
>> >
>> > reader = vtk.vtkDelimitedTextReader()
>> > reader.SetFieldDelimiterCharacters(" ")
>> > reader.DetectNumericColumnsOn()
>> > reader.SetFileName(csvfile)
>> > reader.MergeConsecutiveDelimitersOn()
>> > reader.Update()
>> >
>> > tableToPoints = vtk.vtkTableToPolyData()
>> > tableToPoints.SetInputConnection(reader.GetOutputPort())
>> > tableToPoints.SetXColumn("Field 0")
>> > tableToPoints.SetYColumn("Field 1")
>> > tableToPoints.SetZColumn("Field 2")
>> > tableToPoints.Update()
>> >
>> > resample = vtk.vtkResampleToImage()
>> > resample.SetInputConnection(tableToPoints.GetOutputPort())
>> > resample.SetSamplingDimensions(3, 3, 3)
>> > resample.
>>
>
>
>
> --
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180803/62c7d5d1/attachment.html>


More information about the vtkusers mailing list