Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SofaSimulator.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 
27 #ifndef SIMULATOR_SIMULATORS_SOFA_SOFASIMULATOR_H
28 #define SIMULATOR_SIMULATORS_SOFA_SOFASIMULATOR_H
29 
31 
32 #include <sofa/simulation/tree/TreeSimulation.h>
33 #include <sofa/component/container/MechanicalObject.h>
34 #include <sofa/defaulttype/VecTypes.h>
35 #include <sofa/simulation/tree/GNode.h>
36 
37 // simplification of sofa interface
38 #define SofaVector sofa::helper::vector
39 
40 // Loads for Sofa
42 
44 namespace std {
46 typedef pair<unsigned int, unsigned int> MechanicalObjectDOFIndex;
50 typedef map <unsigned int, MechanicalObjectDOFIndex> AtomDOFMap;
54 typedef map<unsigned int, unsigned int> MechanicalObjectAtomDOFMap;
58 typedef map<unsigned int, unsigned int> MechanicalObjectDOFAtomMap;
59 }
60 
69 
70 public:
72 
73  SofaSimulator(MonitoringManager* monitoringManager,const char* file);
74 
75  virtual ~SofaSimulator();
76 
79  void doMove(double dt);
80  void init();
81  void getPosition(int index, double position[3]);
82  void getForce(int index, double force[3]);
83  void end() {}
84 
85  void createPml(const char* inputFile,const char* pmlFile);
87 
89 
90 private:
92  sofa::simulation::Node *getGNode();
93 
95  std::MechanicalObjectAtomDOFMap & getMechanicalObjectAtomDOFMap(unsigned int mechObjectIndex);
96 
98  std::MechanicalObjectDOFAtomMap & getMechanicalObjectDOFAtomMap(unsigned int mechObjectIndex);
99 
101  sofa::defaulttype::Vec3Types::Coord getDOFPosition(unsigned int atomIndex);
102 
104  sofa::defaulttype::Vec3Types::Coord getDOFPosition(unsigned int mechObjectIndex, unsigned int dofIndex);
105 
107  sofa::defaulttype::Vec3Types::Deriv getDOFForce(unsigned int atomIndex);
108 
110  sofa::defaulttype::Vec3Types::Deriv getDOFForce(unsigned int mechObjectIndex, unsigned int dofIndex);
111 
113  unsigned int getAtomIndex(unsigned int mechObjectIndex, unsigned int dofIndex);
114 
116  sofa::component::container::MechanicalObject<sofa::defaulttype::Vec3Types> * getMechanicalObject(unsigned int mechObjectIndex);
117 
119  unsigned int getNumberOfMechanicalObjects();
120 
122  sofa::defaulttype::Vec3Types::VecCoord getMechanicalObjectDOFPosition(unsigned int mechObjectIndex);
123 
125  sofa::defaulttype::Vec3Types::VecDeriv getMechanicalObjectDOFForce(unsigned int mechObjectIndex);
126 
128  void build();
129 
131  void buildConstraints();
132 
134 #ifdef SOFA_1_0_RC1
135  sofa::simulation::Node::SPtr groot;
136 #else
137  sofa::simulation::Node* groot;
138 #endif
139 
141  SofaVector<BaseMechanicalState*> mechanicalObjects;
142 
144  std::AtomDOFMap atomsToDOF;
145 
147  std::vector<std::MechanicalObjectAtomDOFMap*> mechanicalObjectAtomDOFMap;
148 
150  std::vector<std::MechanicalObjectDOFAtomMap*> mechanicalObjectDOFAtomMap;
151 
153  std::vector<TranslationConstraint<sofa::defaulttype::Vec3Types> *> translations;
154 
157 };
158 
159 // -------------------- getGNode --------------------
160 inline sofa::simulation::Node* SofaSimulator::getGNode() {
161  if (groot == NULL) {
162  //-- TODO build a sofaGRoot using the nodes
163  }
164 
165 #ifdef SOFA_1_0_RC1
166  return groot.get();
167 #else
168  return groot;
169 #endif
170 }
171 
172 // -------------------- getNumberOfMechanicalObjects --------------------
174  return mechanicalObjects.size();
175 }
176 
177 // -------------------- getMechanicalObjectAtomDOFMap --------------------
178 inline std::MechanicalObjectAtomDOFMap & SofaSimulator::getMechanicalObjectAtomDOFMap(unsigned int mechObjectIndex) {
179  return (*mechanicalObjectAtomDOFMap[mechObjectIndex]);
180 }
181 
182 // -------------------- getMechanicalObjectDOFAtomMap --------------------
183 inline std::MechanicalObjectDOFAtomMap & SofaSimulator::getMechanicalObjectDOFAtomMap(unsigned int mechObjectIndex) {
184  return (*mechanicalObjectDOFAtomMap[mechObjectIndex]);
185 }
186 
187 // -------------------- getMechanicalObjectDOFPosition --------------------
188 inline sofa::defaulttype::Vec3Types::VecCoord SofaSimulator::getMechanicalObjectDOFPosition(unsigned int mechObjectIndex) {
189  return (*getMechanicalObject(mechObjectIndex)->getX());
190 }
191 
192 // -------------------- getMechanicalObjectDOFForce --------------------
193 inline sofa::defaulttype::Vec3Types::VecDeriv SofaSimulator::getMechanicalObjectDOFForce(unsigned int mechObjectIndex) {
194  return (*getMechanicalObject(mechObjectIndex)->getF());
195 }
196 
197 // -------------------- getScnFile --------------------
199  return scnFile;
200 }
201 
202 #endif // SIMULATOR_SIMULATORS_SOFA_SOFASIMULATOR_H
MonitoringManager * monitoringManager
monitoring manager
Definition: Simulator.h:82
unsigned int getAtomIndex(unsigned int mechObjectIndex, unsigned int dofIndex)
get the atom id corresponding to DOF of index dofIndex in the MechanicalObject of index mechObjectInd...
std::vector< std::MechanicalObjectDOFAtomMap * > mechanicalObjectDOFAtomMap
list of all MechanicalObjectDOFAtomMap
Definition: SofaSimulator.h:150
std::vector< std::MechanicalObjectAtomDOFMap * > mechanicalObjectAtomDOFMap
list of all MechanicalObjectAtomDOFMap
Definition: SofaSimulator.h:147
std::vector< TranslationConstraint< sofa::defaulttype::Vec3Types > * > translations
the load constraints (i.e. Translation) for each mechanical Objects
Definition: SofaSimulator.h:153
sofa::defaulttype::Vec3Types::VecDeriv getMechanicalObjectDOFForce(unsigned int mechObjectIndex)
get the forces of all DOF for mechanical object mechObjectIndex
Definition: SofaSimulator.h:193
void createPml(const char *inputFile, const char *pmlFile)
Create a pml file from an imput file.
std::string getScnFile()
Definition: SofaSimulator.h:198
sofa::simulation::Node * groot
the sofa graph node root
Definition: SofaSimulator.h:137
SofaSimulator(MonitoringManager *monitoringManager)
void end()
end simultor
Definition: SofaSimulator.h:83
TODO Comment class here.
Definition: SofaSimulator.h:68
void buildConstraints()
translate loads into constraints
sofa::defaulttype::Vec3Types::Deriv getDOFForce(unsigned int atomIndex)
Return the force std::vector corresponding to the Atom number i.
unsigned int getNumberOfMechanicalObjects()
get the number of mechanical objects
Definition: SofaSimulator.h:173
sofa::simulation::Node * getGNode()
get the sofa graph node root
Definition: SofaSimulator.h:160
SofaVector< BaseMechanicalState * > mechanicalObjects
all the mechanical objects
Definition: SofaSimulator.h:141
std::MechanicalObjectDOFAtomMap & getMechanicalObjectDOFAtomMap(unsigned int mechObjectIndex)
get the MechanicalObjectAtomDOFMap for a given mechancial object
Definition: SofaSimulator.h:183
std::MechanicalObjectAtomDOFMap & getMechanicalObjectAtomDOFMap(unsigned int mechObjectIndex)
get the MechanicalObjectAtomDOFMap for a given mechancial object
Definition: SofaSimulator.h:178
virtual ~SofaSimulator()
void getPosition(int index, double position[3])
get current position for one atom
sofa::defaulttype::Vec3Types::VecCoord getMechanicalObjectDOFPosition(unsigned int mechObjectIndex)
get the positions of all DOF for mechanical object mechObjectIndex
Definition: SofaSimulator.h:188
Manager of the benchmark tests.
Definition: MonitoringManager.h:50
CamiTK CamiTKDir txt file(STRINGS"${FIND_CAMITK_USER_BASE_DIR}/CamiTK/CamiTKDir.txt"FIND_CAMITK_USER_DIR_LAST_INSTALL) endif() find_program(CAMITK_CONFIG_EXECUTABLE NAMES camitk-config-debug camitk-config PATH_SUFFIXES"bin"PATHS"$
Definition: FindCamiTK.cmake:80
void init()
initialize the simulator
void doMove(double dt)
ask the simulator do to one step of the simulation
void build()
build structure
string(REGEX REPLACE"^.*-(.*)-.*""\\1"ARCH"${CAMITK_CONTINUOUS_INTEGRATION}") string(REGEX REPLACE"^.*-.*-(.*)""\\1"BUILDTYPE"$
Definition: continuous.cmake:34
An interactive simulator is a simulator that we can control step by step (ex: Sofa) ...
Definition: InteractiveSimulator.h:38
sofa::defaulttype::Vec3Types::Coord getDOFPosition(unsigned int atomIndex)
Return the Coord std::vector corresponding to the Atom number i.
sofa::component::container::MechanicalObject< sofa::defaulttype::Vec3Types > * getMechanicalObject(unsigned int mechObjectIndex)
get a mechanical object by its index
std::string scnFile
path to .scn file
Definition: SofaSimulator.h:156
std::AtomDOFMap atomsToDOF
create a correspondance between the atoms and the DOFs (indexAtom<->indexMechObject[indexDOF]) ...
Definition: SofaSimulator.h:144
void getForce(int index, double force[3])
get current force for one atom