Views

OneTetrahedron

Contents

How to implement an animation model different from the visual model ?

Screenshot : the liver - visual model - immersing in one tetrahedron - the animation model.
Screenshot : the liver - visual model - immersing in one tetrahedron - the animation model.

The code

The code relative to this example is located in : .../sofa/src/Tutorials/oneTetrahedron

There is just a Main.ccp with less than 100 lines. Open and observe it.



The scene graph

The scene graph used for this example
Enlarge
The scene graph used for this example
  • See OneParticule tutorial to know how to get this graph in :: SOFA ::



More comments

  • The graph root node:

   Sofa::Components::Graph::GNode* groot = new sofa::Components::Graph::GNode;
   ...

  • One solver for all the graph

   Sofa::Components::CGImplicitSolver* solver = new Sofa::Components::CGImplicitSolver;
   ...

  • Set gravity for all the graph

   Sofa::Components::Gravity* gravity =  new Sofa::Components::Gravity;
   ...

  • Tetrahedron degrees of freedom: set the geometric values of the 4 vertices

   Sofa::Core::MechanicalObject<MyTypes>* DOF = new Sofa::Core::MechanicalObject<MyTypes>;
   ... 

  • Tetrahedron uniform mass: set an uniform mass onto the tetrahedron

   Sofa::Components::UniformMass<MyTypes,double>* mass = new Sofa::Components::UniformMass<MyTypes,double>(DOF);
   ...

  • Tetrahedron topology: the tetrahedron itself

   Sofa::Components::MeshTopology* topology = new Sofa::Components::MeshTopology;
   ...

  • Tetrahedron constraints: fixe the tetrahedron on the top

   Sofa::Components::FixedConstraint<MyTypes>* constraints = new Sofa::Components::FixedConstraint<MyTypes>(DOF);
   ...

  • Tetrahedron force field, the animation model : put some springs on edges

   Sofa::Components::TetrahedronFEMForceField<MyTypes>* spring = new Sofa::Components::TetrahedronFEMForceField<MyTypes>(DOF);
   ...

  • Tetrahedron skin: a children node containing the liver

   Sofa::Components::Graph::GNode* skin = new Sofa::Components::Graph::GNode;
   ...

  • The visual model: the liver

   Sofa::Components::GL::OglModel* visual = new Sofa::Components::GL::OglModel();
   visual->load("../../../Data/VisualModels/liver-smooth.obj", "", "");

  • The mapping between the tetrahedron (DOF) and the liver (visual) in order that the liver follow the tetrahedron animation

   MyMapping* mapping = new MyMapping(DOF, visual);
   ...



The mapping type between the visual and animation models

Here a BarycentricMapping is used to map the visual model to the animation model. This type is templated and you can find some examples of uses at the end of the file ...\sofa\src\Sofa\Components\BarycentricMapping.cpp

By analogy, we have built MyMapping type :

   typedef Sofa::Components::BarycentricMapping<
       Sofa::Core::Mapping<
           Sofa::Core::MechanicalModel<MyTypes>,
           Sofa::Core::MappedModel< 
               Sofa::Components::Common::ExtVectorTypes< 
                   Sofa::Components::Common::Vec<3,GLfloat>,
                   Sofa::Components::Common::Vec<3,GLfloat>
               >
           >
       >
   > MyMapping;