PyGeM

Tutorial 1: Free Form Deformation on a sphere

In this tutorial we will show the typical workflow to perform a deformation on a generic geometry using the free-form deformation method implemented within PyGeM. A brief teoretical overview of the method is introduced in the pygem.ffd module, while in the README you can find several references that focus on FFD.

First of all we import the required PyGeM class and we set matplotlib for 3D plots. The version of PyGeM we are using in this tutorial is the 2.0.0.

Then, the other ingredient is the original geometry we want to deform. In this simple tutorial we just span some points around a sphere and morph their coordinates using the FFD class.

Well, we have our sphere! Now it is time to create the new instance of the FFD class, that will actually perform the points deformation. We can read from the documentation that the only parameter to the FFD constructor is the number of control points we want to create, in the three directions. In this simple tutorial we create just a $2\times 2 \times 2$ lattice of points.

We can print the FFD object itself, in order to summarize all the parameters. It's important to note that the lattice has the default length equal to 1, the origin at $(0, 0, 0)$ and no rotation. We can edit manually these quantities to change the configuration of the lattice, but in this simple case the default values are fine.

To control the displacement of the control points, we can touch the arrays array_mu_x, array_mu_y and array_mu_z: these structures contain the movements in the three directions of all the lattice points. By default, the movements is imposed to zero but we can change those values to apply the deformation. It is important to know also that the points movement is normalized by the length of the lattice.

Let's try together to move a point. We can manipulate the movements of each point along a specific direction by accessing to the relative array: in this case we move the right-top-rear point!

Now we can deform our sphere (in particular the coordinates of the points that define it) just calling the __call__() method and passing to it the numpy array of the points coordinates.

Done! The new array (in this tutorial the array new_mesh) contains the deformed coordinates. To visualize the new shape, we plot the sphere points and, in red, the control points.