Home › Forum › Community Help › Programming with SOFA › C++ code in TetrahedralCorotationalFEMForceField.cpp/.h/.inl
Tagged: 64_bits, SOFA_16.12, win7
This topic contains 6 replies, has 2 voices, and was last updated by Lujain 6 months ago.

AuthorPosts

16 May 2017 at 10 h 04 min #9121
Hi everyone！
Now I can make my model deform using TetrahedralCorotationalFEMForceField component. But for bad luck, the deformation is not the one that I need. I was trying to do nonrigid registration to get deformation vertor field. But I dont know how to use it in this component.
So I am wondering what I can do if I am going to program with C++ code in TetrahedralCorotationalFEMForceField.inl. Actually I leart the c++ code in the component but I dont know what’s in meaning in dispalacement computation.Here are the code:// Rotation matrix (deformed and displaced Tetrahedron/world) Transformation R_0_2; computeRotationLarge( R_0_2, p, t[0],t[1],t[2]); tetrahedronInf[elementIndex].rotation.transpose(R_0_2); //serr<<"R_0_2 large : "<<R_0_2<<sendl; // positions of the deformed and displaced Tetrahedron in its frame helper::fixed_array<Coord,4> deforme; for(int i=0; i<4; ++i) deforme[i] = R_0_2*p[t[i]]; deforme[1][0] = deforme[0][0]; deforme[2][0] = deforme[0][0]; deforme[2][1] = deforme[0][1]; deforme[3] = deforme[0]; // displacement Displacement D; D[0] = 0; D[1] = 0; D[2] = 0; D[3] = tetrahedronInf[elementIndex].rotatedInitialElements[1][0]  deforme[1][0]; D[4] = 0; D[5] = 0; D[6] = tetrahedronInf[elementIndex].rotatedInitialElements[2][0]  deforme[2][0]; D[7] = tetrahedronInf[elementIndex].rotatedInitialElements[2][1]  deforme[2][1]; D[8] = 0; D[9] = tetrahedronInf[elementIndex].rotatedInitialElements[3][0]  deforme[3][0]; D[10] = tetrahedronInf[elementIndex].rotatedInitialElements[3][1]  deforme[3][1]; D[11] =tetrahedronInf[elementIndex].rotatedInitialElements[3][2]  deforme[3][2];
I am looking forward some kind adviece. Thanks in advance!
16 May 2017 at 10 h 34 min #9123Hi Lujain
Be careful to use the [code] tag to start and close your code citation.
I did not write it myself but here are some advices.
 First, know that there is a specific plugin in SOFA focused on registration. It would maybe be worth it to try. Feel free to compile and test it!
 The Corotational approach in SOFA is inspired from the work of Felippa. You can find it also explain in these papers:
 Efficient, physically plausible finite elements
 Imageguided Simulation of Heterogeneous Tissue Deformation For Augmented Reality (see equation (2))
The displacement you notice corresponds to Δu in the force calculation: Δf=R^T K Δu.
 About how to write a scene in C++ several posts solved it. Browse the forum of look at the documentation page.
Hope this helps
Hugo
18 May 2017 at 3 h 23 min #9128Hi Hugo,
Thanks very much. I am trying to understand the code and the paper helps a lot.
But I still dont understand why there are computation of D[0]…D[11] and the deforme.18 May 2017 at 18 h 29 min #9133Hi Lujain,
This corresponds corresponds to the deformation (Vec3) of the 4 vertices of the tetrahedron. Therefore, the D matrix is 3×4 = 12.
The operation done here aims at removing the displacement due to the rotation (called here “deforme”) from the global displacement.
Hugo
19 May 2017 at 5 h 32 min #9135Hi Hugo,
Thanks a lot for your kind explanation.
That means the “deforme” is done as follows: when one tetrahedron is rotated, we computed the displacement of the four vertices first right?
But I was also confused about why there are operation of the three vertices based on the one vertices?
deforme[1][0] = deforme[0][0];
deforme[2][0] = deforme[0][0];
deforme[2][1] = deforme[0][1];
deforme[3] = deforme[0];
And the dispalcement for the first vertice is directly set to 0: D[0] = 0;D[1] = 0;D[2] = 0; So why?
Sorry to trouble you and thanks again!BR,
Lujain7 June 2017 at 4 h 41 min #9288Hi Lujain,
In the corotational approach, the part of the deformation due to the rotation must be removed to compute the stress in each tetra. To do so, this rotation component is computed at each tetra, in the tetrahedron frame. In the tetrahedron frame, the first vertices is the origin frame. Therefore, there is no displacement related to the rotation in its frame.
See Fig. 1 in the paper of Nesme.
Hope this helps,
Hugo
11 June 2017 at 10 h 42 min #9316Hi Hugo,
Sorry for late reply.
I got it finally.
Thanks very much!Best Regards,
Lujain 
AuthorPosts
You must be logged in to reply to this topic.