SEARCH
TOOLBOX
LANGUAGES
XMLSyntax

XMLSyntax

From SOFAWiki

Jump to: navigation, search
Creating scenes with the XML syntax

Contents

XML format

To create a data structure and link the different components (C++ module of SOFA) together, scene graphs (simulation tree in XML format) are used to describe a simulation. In term of simulation tree, nodes are used to create hierarchical levels of modeling (e.g. behavior model, collision model, visual model, etc.), whereas the large collection of components corresponds to leaves under the nodes and covers a large set of fields (e.g. mechanical behavior, force fields, topology, mass, etc. ).

This description using a XML file allows a high flexibility in designing a simulation scene. Indeed, it is easy to replace one simple component by another. For example for the computation of forces acting on a mechanical system, one can replace a spring-mass force with a finite element force. Changing a component does not affect other components in the scene due to the library architecture.


Simple example of XML scene graph:

Image:pendulum.png

In this simple example, a whole pipeline allowing to simulate a pendulum is described. Each component (white name) is a C++ class of SOFA with parameters (explain in next paragraph). Thus, in this example, each component has a different goal. - The solver system with a ODE scheme for each time step and a linear solver to solve integrated time step. - The mechanical object to define the geometry of simulated object and play the role of mechanical position container. - Then, FixedConstraint and the mass define the rest of the mechanical model. - Finaly the spring forcefield, define the spring.


Data input-output

All parameters describing a scene are stored in specific C++ containers called "Data". Those containers are C++ components members reachable in the XML file. If we take the previous example of the pendulum. In each component, we can see parameter (in blue). Those parameters are specific containers member of the different c++ classes. For example the "Data name", which define simply the name of the component, is a container Data <string>. In SOFA there are common Data, i.e which can be access in every component. Those Data are: TODO chercher la liste. Then specific Data, like for example "indices" of FixedConstraint, which define the index of the point to be fixed, should be declare in this specific C++ class.


Moreover, dependency between Data containers of same nature can be specified in the XML scene files, indicating that the content of one container should be copied from the other, making the scene description fairly simple and above all efficient. To create this dependency, the flag "@" follow by the name of the source component should be use. Like in next example. Note that it is possible to link to a component located in an other node. Thus, the syntax: myData = "@LinkToOtherNode/SourceComponent.myData". Where LinkToOtherNode = ../ if you should go up to one node, or directly the name of a node. TODO: ajouter un example, ça sera plus clair.

Image:dataLink.png


Including Files

How to use the <include href="..."/> command, and overriding some parameters

Loading Mesh Files

Mesh files located in $SOFA_DIR/share or $SOFA_DIR/examples can be automatically found by Sofa DataRepository system, so you can write <MeshLoader filename="mesh/liver.msh" />.

Using Php+XML

Explain how to generate a scene using php+xml