[vtkusers] vtkWarpVector/vtkGlyph3D array problem
Robby Aungst
robert.aungst at gmail.com
Tue Jan 2 22:30:45 EST 2018
Thanks. I tried a similar approach but I have a number of filters lined up
so I can't cast things back
to polydata at the end without breaking everything. I basically need to be
able to do the same thing (manually add the arrays back in), but without
having to create new polydata. I guess I need a filter that adds array data
to the poly data? Does something like that exist? Is there any other way
around this?
On Fri, Dec 29, 2017 at 4:11 PM, Charles Kind <charles.kind at bristol.ac.uk>
wrote:
> Dear Robby,
>
> Below is a function where I warp points back by half a vector in order that
> the vector glyph arrow is drawn later on with the center of the vector in
> plane. You will note that I create the warp vector field, apply it to the
> warp, copy these points to a polydata then extract all relevant arrays and
> copy the whole lot back. This may not be the correct way of doing things, I
> am just hacking at VTK, but it works. If you designated arrays as vector or
> scalar you will need to do that again afterwards.
>
> # Generate warp vectors, these vectors warp the point data
> # Warp centers vectors on plane, but warps base geometry
> def CenterVectors(self):
> numPoints = self.thinPD.GetNumberOfPoints()
> mtrans = vtk.vtkFloatArray()
> mtrans.SetNumberOfTuples(numPoints)
> mtrans.SetNumberOfComponents(3)
> mtrans.SetNumberOfValues(3*numPoints)
> mtrans.SetName("mtrans")
> # Warp of -(1/2)v centers vectors if vector origin is z=0 plane
> for x in range(numPoints):
> mtrans.SetTuple3(x, \
> -self.thinPD.GetPointData().GetAbstractArray('m').\
> GetTuple(x)[0]/2, \
> -self.thinPD.GetPointData().GetAbstractArray('m').\
> GetTuple(x)[1]/2, \
> -self.thinPD.GetPointData().GetAbstractArray('m').\
> GetTuple(x)[2]/2)
> wpd = vtk.vtkPolyData()
> wpd.SetPoints(self.thinPD.GetPoints())
> wpd.GetPointData().SetVectors(mtrans)
> # Warp vector origins
> warpVector = vtk.vtkWarpVector()
> warpVector.SetInputData(wpd)
> warpVector.Update()
> # Cast warped points and original vectors into PolyData
> warped = vtk.vtkPolyData()
> warped.SetPoints(warpVector.GetOutput().GetPoints())
> noarrays = self.thinPD.GetPointData().GetNumberOfArrays()
> for x in range(noarrays):
> warped.GetPointData().AddArray(self.thinPD.GetPointData()\
> .GetAbstractArray(x))
> self.thinPD = warped
>
> Luck,
>
> Charlie
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> 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 VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180102/bc8a5333/attachment.html>
More information about the vtkusers
mailing list