Displacement Vector Visualisation

I have a Model read in from a .vtu file in an unstructured grid format. Each point in this unstructured grid has its position data which visualises nicely but it also has a unique PointData Vector associated with it describing that point’s displacement from a previous time step. I’m wondering if there is a way to turn those vectors into a glyph. I’m aware that the Transformation module is designed to do this with Volumes but I can’t see how to make it work with a Model, especially given that the deformations cannot be summarised in a Transformation Matrix.
Thank you!

Slicer’s transforms module requires transforms that define displacements (and their inverse) everywhere, not just at specific sample points.

You can construct a transform from displacements known at random points by creating a thin-plate-spline transform. It is probably 10-15 lines of Python code: use original point coordinates as source landmarks, use warp filter to compute displaced point coordinates, use those as target landmarks, then set the VTK transform to a new transform node.

If you had many thousands of points then evaluating the thin-plate-spline transform could take a long time. You can then use ScatteredTransform extension to create a regularly sampled b-spline displacement field from sparse samples, which may make the transform magnitudes faster to evaluate.

Hi Andras,
Would you please give me some information on how can i use warpbyvector filter in slicer for warping models.

Thank you

Regards,
Saima Safdar

You can get the mesh from the model node, set it as input to a vtkWarpVector, and create a new model from the output of the filter.

Hi Andras,
I tried it
mesh = model.GetMesh()
warpvector = vtk.vtkWarpVector()
warpvector.SetInputData(mesh)
warpvector.Update()
output = warpvector.GetUnstructuredGridOutput()

mesh2 = vtk.vtkUnstructuredGrid()
mesh2.SetPoints(output.GetPoints())
mesh2.SetCells(output.GetCellTypesArray(),output.GetCellLocationsArray(), output.GetCells())
mesh2.UpdateCellGhostArrayCache()
mesh2.UpdatePointGhostArrayCache()

modelNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLModelNode’)
modelNode.SetAndObserveMesh(mesh2)

but didnt get the warped model. Could you please see what am I missing in the code above.

It gives me the exact model as before.

Thanks alot

Regards,
Saima Safdar

Probably you just miss active vector selection, warping mode setting, etc. Check out warp filter VTK examples to see what exactly you need to set and how.

Thanks Andras. Yes I was missing the setactivevectors for the mesh grid.

Thanks a lot

1 Like

Hi andras,
Is it possible to show the coloring for the deformed mesh according to the displacements

Hi Andras,
I am trying to offset a mesh using warpvector by setting the setscalarfactor. But dont know what is missing . could you please see the attached code.

Thank you or is there any other way to get one or two layers of extranodes around the existing mesh.

Thank you
modelNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLModelNode’)

  model = slicer.util.getNode(inputModel.GetID())
  mesh =  model.GetMesh()
  mesh.GetPointData().SetActiveVectors("Displacements")
  warpvector = vtk.vtkWarpVector()
  warpvector.SetInputData(mesh)
  warpvector.SetInputArrayToProcess(0,0,0,"vtkDataObject::FIELD_ASSOCIATION_POINTS", "Displacements")

  warpvector.SetScaleFactor(1.0)
  warpvector.Update()
  output = warpvector.GetUnstructuredGridOutput()
  
  mesh2 = vtk.vtkUnstructuredGrid()
  mesh2.SetPoints(output.GetPoints())
  mesh2.SetCells(output.GetCellTypesArray(),output.GetCellLocationsArray(), output.GetCells())
  mesh2.UpdateCellGhostArrayCache()
  mesh2.UpdatePointGhostArrayCache()
  modelNode.SetAndObserveMesh(mesh2)   

Regards,
Saima sAfdar

This syntax does not look familiar. Normally we use something like this:

threshold.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "Distance")

We usually simply use output = warpvector.GetOutput().

Hi Andras.
I am getting the output mesh but with no scalar factor. THe code I pasted is without errors but I dont get desired output.

I do not understand threshold line …

Regards,
Saima Safdar

I don’t understand what you mean by this.

You can check our VTK examples website for complete examples of using the warp filter. One you get an example working, modify it step by step so that it does exactly what you need.

Dear Andras,
I am trying to visualise the electric potential within 3D slicer. In paraview, I can use select potentail from a drop down window and then apply rescale to visible data range and it shoes me a coloured vtk mesh. Mesh is a hexahedral mesh.

How can I do something like below in paraview in 3D slicer:

In Slicer you can configure how a scalar array colors a model in Models module / Display / Scalars section.

Hi Andras,
I can see all variable in active scalar under scalar section, but when i select variable it does not show it on the model.

pic
pic2

regards,
Saima Safdar

You have set a very large display range for potential, therefore all your valid values have very similar color. Reduce the displayed range manually or switch to Scalar range modeData scalar range (auto).

1 Like