[vtkusers] vtkWarpVector/vtkGlyph3D array problem

Charles Kind charles.kind at bristol.ac.uk
Fri Dec 29 17:11:26 EST 2017


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


More information about the vtkusers mailing list