# Using Displacement Map to Deform or Morph a Segment/Model

**URL:** <https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552>\
**Category:** Support\
**Created:** [July 7, 2021, 3:12am UTC](https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552 "2021-07-07T03:12:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)\
**Post date:** [July 7, 2021, 3:12am UTC](https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552/1 "2021-07-07T03:12:49Z")

</div>

Hello,

Is it possible to use a displacement map/volume, like the output from the **Model to Model Distance** module, to **deform** or **morph** another segment/volume/model? Even if it just a simple approximation.

I am trying to simulate the stretching of the skin over the advancement of multiple skull segments.

 ![model2modeldist](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/7/3759d786dc157544585f40ee83834b25f9fd2eab.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 12, 2021, 2:47pm UTC](https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552/2 "2021-07-12T14:47:47Z")

</div>

You can very easily warp a model using displacement field stored for each point of the mesh (see [VTK: vtkWarpVector Class Reference](https://vtk.org/doc/nightly/html/classvtkWarpVector.html)). However, I’m not sure if Model to Model Distance extension provides displacement vectors. Anyway, if you want to align surface models then you can probably get better results with [model registration modules](https://slicer.readthedocs.io/en/latest/user_guide/registration.html#model-registration).

---

<div class="post-metadata">

**Author:** ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)\
**Post date:** [July 13, 2021, 2:31am UTC](https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552/3 "2021-07-13T02:31:20Z")

</div>

@lassoan,

I found [this post](https://discourse.slicer.org/t/merge-scalars-of-two-models/15682/3) and I am trying to repeat the process;

First, I ran **Model To Model Distance** and created `D_rev2orig` as the “displacement model”  
Additionally, I have a “target” model `D_ST` which I would like to warp/deform.

 ![figure_disp_map](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/9/69b428da699103a73f84737b3763eb520d7052b4.jpeg)  
 ![figure_skin_model](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/e/fe251c1a674b401d1e320c78e8b1b31288ccd34a.png)

Here is what I am doing to warp the “target” model;

```auto
dispModel = getNode("D_rev2orig")
targetModel = getNode("D_ST")

dispMesh = dispModel.GetMesh()
dispMesh.GetPointData().SetActiveVectors("PointToPointVector")

warp = vtk.vtkWarpVector()
warp.SetInputData(dispMesh)

warp.SetScaleFactor(1.0)
warp.Update()
targetModel.SetPolyDataConnection(warp.GetOutputPort())

```

This overrides the `D_ST` “target” model and generates a weird hybrid model;

 ![figure_output_warp](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/d/5d8ddb90d0e2a4b6dc39268782e2c08dbff350bb.jpeg)

This model has the `PointToPointVector` attribute from the displacement model `D_rev2orig`, but does not have the geometry of the “target” model. The geometry is not the same as the “displacement model” however, so maybe I am just missing something in the script above?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 13, 2021, 3:13am UTC](https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552/4 "2021-07-13T03:13:55Z")

</div>

I’m not sure what “PointToPointVector” vector contains, but I guess it is something like vector to the closest point. This vector field can be very noisy and discontinuous, so I would not use it to warp a surface. Instead, I would try to use one of the surface registration methods.

Can you write a bit more about your end goal? You wrote above that “I am trying to simulate the stretching of the skin over the advancement of multiple skull segments.”, but this is not very clear for me. Displacement of rigid bone pieces and geometric interpolation between them will not tell much about how the skin will move or stretch. For that you would probably need to run FEM analysis, for example using [FEBio](https://febio.org/downloads/).

---

<div class="post-metadata">

**Author:** ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)\
**Post date:** [July 13, 2021, 1:22pm UTC](https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552/5 "2021-07-13T13:22:20Z")

</div>

> Can you write a bit more about your end goal? You wrote above that “I am trying to simulate the stretching of the skin over the advancement of multiple skull segments.”, but this is not very clear for me.

Of course!  
The model representative of the bone segments here, also carrying the **Model To Model Distance** data, is the result of a **Fronto-Orbital Advancement** [planning done using Slicer](https://discourse.slicer.org/t/osteotomy-planner-v2-0/18384/2). I ended-up creating two posts about this problem because I wanted to separate this final step from the entire planning discussion.

My goal was to use either the **Bandeau Model** itself or the **Model To Model Distance** data to then **warp** or **deform** the skin to match the overall advancement of the bones.

> This vector field can be very noisy and discontinuous, so I would not use it to warp a surface. Instead, I would try to use one of the surface registration methods.

I have been using registration methods to warp the model [also](https://discourse.slicer.org/t/osteotomy-planner-v2-0/18384/9). So far creating a warp transform from fiducial registration has given me the best results, but the result can only be improved with the addition of more landmark and with manual registration. The limit is 30 landmarks and warp transforms do not support the automatic registration.

 ![skin_overlay](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/9/a90c2e25f38c89eceafd3a95467c9ec8134a298e.jpeg)

I was working on Python script that would use the vertices of the source and target models as landmarks, but the registration was falling apart. If you think this is a viable approach, I can continue to explore this… I was thinking of sorting the vertices along the AP so that vertices would match somewhat better between models. In this case I am still limited by the 30 point limit. Is this a hard limit or just a warning about # computations?

> Displacement of rigid bone pieces and geometric interpolation between them will not tell much about how the skin will move or stretch. For that you would probably need to run FEM analysis, for example using [FEBio](https://febio.org/downloads/).

I agree. In fact, I was planning to use FEBio too. My hope was to, at the very least, get some sort of nodal displacement field that I can use in FEBio to run the simulation a little more programmatically.

Perhaps I can improve the warp transform and convert it to a grid transform, vector volume, or displacement volume? 🤔

Let me know if this is a little clearer now,

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 13, 2021, 1:50pm UTC](https://discourse.slicer.org/t/using-displacement-map-to-deform-or-morph-a-segment-model/18552/6 "2021-07-13T13:50:47Z")

</div>

There should be no limit on number of points for registration, just the computation will get slower. To make computation fast, you can create bspline transform from the scattered landmark points using ScatteredTransform extension.

The main issue with transforms is that the deformation is constrained to be smooth, but it does not mean that the deformation will be realistic (e.g., bones may be stretched).
