Deformation - Free Form Deformation
Path of the code: [04_ffd]
This code model a deformable grid that should be used to apply an FFD deformation to the mesh inside it.
To deform the grid, keep shift pressed while moving the mouse over one of the grid vertex.
When the grid is modified, the function and ffd_deform() is called. This function, currently empty, is expected to apply the FFD deformation to the shape. Note that a timer system ensure that ffd_deform function is called periodically (and not at every mouse event) in order to limit the computation.
> Implement the FFD deformation on the shape using Bezier functions
\(\forall m\,,\;\; \displaystyle q_m = \sum_i \sum_j \sum_k b_i(x_m)\,b_j(y_m)\,b_k(z_m)\;g_{ijk}\)
With \(b_{i/j/k}\) the Bezier basis function, \(g_{ijk}\) the absolute coordinates of the grid vertices, \(p_m=(x_m,y_m,z_m)\in[0,1]^3\) the original shape vertex coordinates associated to the parametric coordinates of Bezier function, and \(q_m\) are the deformed coordinates.
Hints
- - You will need to complete the functions precompute_weights() and ffd_deform().
- - The grid-vertex coordinates \(g_{ijk}\) can be accessed as grid(kx,ky,kz) for the integer indices kx, ky, kz. Its dimension along the three directions can be accessed as grid.dimension.x/y/z.
- - A function computing \({N \choose i}\) is provided as binomial_coeff(N,k) (in file ffd.cpp).
- - Beware that to approximate \(N\) points (\(p_k\,, \;k\in[\![0,N[\![\)) with a Bezier polynomial, you need to consider a polynomial of degree \(N-1\) (linear for 2 points, cubic for 4 points, etc).
- - You may need to precompute values related to the parameteric coordinates of the vertices in the grid, and pass these values as argument of the function ffd_deform().