# inflating a part of an object in VTK

**URL:** <https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375>\
**Category:** Development\
**Created:** [September 27, 2023, 8:34am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375 "2023-09-27T08:34:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)\
**Post date:** [September 27, 2023, 8:34am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/1 "2023-09-27T08:34:12Z")

</div>

Hi everyone!  
How can I inflate a part of an object by getting an input from user in VTK using C++?(something like what I attached here)

 ![Screenshot 2023-09-27 114125](https://discourse.vtk.org/uploads/default/original/2X/8/8c5d1ee5c6aab5085b1833504ee5e430647bb1e4.png)

---

<div class="post-metadata">

**Author:** ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)\
**Post date:** [September 27, 2023, 8:35am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/2 "2023-09-27T08:35:49Z")

</div>

@Tiffany_Chhim @Charles_Gueunet

---

<div class="post-metadata">

**Author:** ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)\
**Post date:** [September 27, 2023, 9:18am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/3 "2023-09-27T09:18:39Z")

</div>

For the user input part, you may rely on the already existing VTK pickers, like on [this example](https://examples.vtk.org/site/Cxx/Picking/HighlightSelectedPoints/). There are a lots of pickers for you to explore, I have chosen one quickly here, maybe not the best.

For the deformation part, the [vespa](https://gitlab.kitware.com/vtk-cgal/vespa) library has a [deformation algorithm](https://gitlab.kitware.com/vtk-cgal/vespa/-/blob/master/vespa/PolygonMeshProcessing/vtkCGALMeshDeformation.h?ref_type=heads), I encourage you to use the [corresponding test](https://gitlab.kitware.com/vtk-cgal/vespa/-/blob/master/vespa/PolygonMeshProcessing/Testing/TestPMPDeformExecution.cxx?ref_type=heads) to see how it works.

With these tools, the pipeline would be:

1. Load your data set and generate global ids (and maybe normals ?)
2. The user create a selection on cells or points
3. You apply a transform on the selection like a warp by vector
4. You use the vepa deformation filter with both the dataset and the transformed points as input (global ides are used to identify with points to move where)
5. You obtain the result you want.

Bonus, the deformation filter can also take a Regoin Of Interest to be able to move some points and provide a smoother result

---

<div class="post-metadata">

**Author:** ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)\
**Post date:** [September 27, 2023, 12:06pm UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/4 "2023-09-27T12:06:29Z")

</div>

Thank you so much!  
I will test it

---

<div class="post-metadata">

**Author:** ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)\
**Post date:** [October 2, 2023, 11:01am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/5 "2023-10-02T11:01:10Z")

</div>

well, I tried to build Vespa with CMake but the error which I attched here occured.(I should say that I have built VTK without Python wrapper before

 ![vespa error](https://discourse.vtk.org/uploads/default/original/2X/a/ace41a115d73fb1cae3f3fbf4c46713f8cd698b9.png)  
)

---

<div class="post-metadata">

**Author:** ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)\
**Post date:** [October 2, 2023, 11:21am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/6 "2023-10-02T11:21:20Z")

</div>

I think you have the `BUILD_PYTHON_WRAPPERS` option set to **ON**. In this case, the VTK you use should support Python also.  
The simplest solution is to set `BUILD_PYTHON_WRAPPERS` to **OFF** during vespa configuration.  
Otherwise, you may try to set `VTK_WRAP_PYTHON` to **ON** in your VTK build, to be able to access VTK (and Vespa) in python.

---

<div class="post-metadata">

**Author:** ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)\
**Post date:** [October 18, 2023, 6:54am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/8 "2023-10-18T06:54:00Z")

</div>

Hi  
could you please tell me how can I move points(target points in deformation algorithm) by dragging the mouse?  
in this test “TestPMPDeformExecution.cxx” the target points coordinates have been valued in the code, but I want to deform the points by the mouse to wherever I want.

@Charles_Gueunet

---

<div class="post-metadata">

**Author:** ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)\
**Post date:** [October 18, 2023, 12:26pm UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/9 "2023-10-18T12:26:18Z")

</div>

@kimia_ghodoosi are you familiar with VTK widgets ? I this situation you may want to use a `vtkHandleWidget`. This will provide you with one handle that you may move (and constrain) in your scene.  
Of course, when applying the deformation filter, you need to transform your widget into a valid point set, with an array of Ids consistent with the one of your initial dataset, so the algorithm can match the points to move.

There are [various tests](https://vtk.org/doc/nightly/html/c2_vtk_t_8.html#c2_vtk_t_vtkHandleWidget) that uses the `vtkHandleWidget` that can serve as examples.

---

<div class="post-metadata">

**Author:** ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)\
**Post date:** [October 21, 2023, 12:25pm UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/10 "2023-10-21T12:25:18Z")

</div>

well, I tried to inflate a part of my object with vtkCGALAlphaWrapping but it warp the area larger than our selected area. the results have shown below:

 ![foot1](https://discourse.vtk.org/uploads/default/original/2X/5/549f862cb8682733fadcf3495ef048e2fb380649.png)

 ![foot2](https://discourse.vtk.org/uploads/default/original/2X/d/ddb7c881380ee57cd47caed977e6b3c6395febfe.png)

In this method two parameters can be changed: alpha and offset. the more increase the offset parameter, the area is expanded from all sides. how can I specify the direction of it’s inflating process. I mean I want it to be apply more perpendicular to the surface and a bit from the sides. Is this possible with this method or should I use another solution?

@Charles_Gueunet

---

<div class="post-metadata">

**Author:** ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)\
**Post date:** [October 23, 2023, 7:34am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/11 "2023-10-23T07:34:11Z")

</div>

Nice, things are coming together.

I would see sevral things here to improve the restult:

1. `vtkCGAHMeshDeformation` has two modes, the smooth (by default) and the [sre\_arap](https://doc.cgal.org/latest/Surface_mesh_deformation/index.html#SMD_Overview_SRE_ARAP). Please ensure you are using the second one (you can use the `SetMode` [method](https://gitlab.kitware.com/vtk-cgal/vespa/-/blame/master/vespa/PolygonMeshProcessing/vtkCGALMeshDeformation.h#L60)) and play with the `SreAlpha` variable.
2. check you selection only consist of points inside the selected area
3. recompute normals as deforming the mesh may lead to visual artifacts if old normals stay in use.

---

<div class="post-metadata">

**Author:** ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)\
**Post date:** [October 31, 2023, 8:01am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/12 "2023-10-31T08:01:47Z")

</div>

Hi  
could you please tell me how can I generate global ids?  
because my STL files doesn’t have any ids.

---

<div class="post-metadata">

**Author:** ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)\
**Post date:** [October 31, 2023, 8:47am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/13 "2023-10-31T08:47:18Z")

</div>

The best way would be to use the `vtkGenerateGlobalIds` filter in the FiltersParallelDIY2 module. Unfortunately it requires VTK to be compiled with MPI, even for sequential executions, I hope we will be able to fix that one day.

The other way is to write a really simple VTK filter that create an array filled with number from 0 to # of points and attach it to the input dataset.

---

<div class="post-metadata">

**Author:** ![kimia\_ghodoosi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kimia_ghodoosi/32/7758_2.png) [@kimia\_ghodoosi](https://discourse.vtk.org/u/kimia_ghodoosi)\
**Post date:** [October 31, 2023, 9:25am UTC](https://discourse.vtk.org/t/inflating-a-part-of-an-object-in-vtk/12375/15 "2023-10-31T09:25:37Z")

</div>

Thannk you so much. I will check it
