[Paraview] How to generate/access Points array from vtkImageData Inbox

David E DeMarle dave.demarle at kitware.com
Thu Oct 25 15:40:34 EDT 2012


Try this modern version of that:

from paraview.numeric import fromvtkarray
array = fromvtkarray(
  self.GetInput().GetPoints().GetData()
)
print array

David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909


On Thu, Oct 25, 2012 at 2:56 PM, Gang Song <songgang97 at gmail.com> wrote:
> Thanks for explanation. I will write the numpy expression for this.
> One related question is how to convert the vtkPoints to a numpy array.
> From wiki, I saw it asks to use vtkDataArrayToVTKArray, but I coulnd't
> find an example for this. The following code doesn't work:
>
> points = vtk.vtkPoints();
> # ....
> points_array = vtkDataArrayToVTKArray(points.GetData())
>
> Seems I am missing some arguments here.
>
>
> Thanks
>
> Gang
>
>
> On Thu, Oct 25, 2012 at 2:50 PM, David E DeMarle
> <dave.demarle at kitware.com> wrote:
>> You should come up with numpy expression that derives each point's location.
>>
>> vtkImageData's point locations are implicitly determined by the image data's
>> origin, extent, and spacing.
>>
>> David E DeMarle
>> Kitware, Inc.
>> R&D Engineer
>> 21 Corporate Drive
>> Clifton Park, NY 12065-8662
>> Phone: 518-881-4909
>>
>>
>> On Thu, Oct 25, 2012 at 2:37 PM, Gang Song <songgang97 at gmail.com> wrote:
>>> Hi,
>>>
>>> I am writing a Python programmable filter in Paraview. The input
>>> source is a type of vtkImageData. I want to get the coordinates of all
>>> the points and use them to generate an output of type
>>> vtkStructuredGrid. Currently I am using a for loop:
>>>
>>> pdi = self.GetInput()
>>> pdo = self.GetOutput()
>>>
>>> numPts = pdi.GetNumberOfPoints()
>>> points = vtk.vtkPoints()
>>> points.Allocate(numPts, numPts)
>>>
>>> for i in xrange(numPts):
>>>         point = pdi.GetPoint(i)
>>>         # ...
>>>         # other manipulations on point
>>>         # ...
>>>         points.InsertNextPoint(point)
>>>
>>> # ...
>>> pdo.SetDimensions(pdi.GetDimensions())
>>> pdo.SetPoints(points)
>>>
>>>
>>> My problem is that for loop became very slow for large image volumes.
>>> So I am replacing it with numpy. But I couldn't find a way to get
>>> points array directly from vtkImageData, something like:
>>>
>>> points = pdi.Points
>>> points = points * 0.5
>>> newPoints.SetData(numpyTovtkDataArray(points))
>>>
>>>
>>> It seems that there is no internal points array stored in
>>> vtkImageData. Is there a easy way to do this?
>>>
>>>
>>> Thanks
>>>
>>> Gang
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.paraview.org/mailman/listinfo/paraview


More information about the ParaView mailing list