26#ifndef TRANSLATION_CONSTRAINT_INL
27#define TRANSLATION_CONSTRAINT_INL
30#include <sofa/helper/system/config.h>
31#include <sofa/helper/gl/template.h>
34using namespace sofa::core::behavior;
36template<
class DataTypes>
38 atomToDOFIndexes = atomIndexToDOFIndex;
41 SReal dirX, dirY, dirZ;
42 this->setName(
"TranslationConstraint");
45 for (
unsigned int i = 0 ; i < loadsList->
numberOfLoads() ; i++) {
47 if (load->
getType() ==
"Translation") {
49 std::map<unsigned int, unsigned int>::const_iterator titi = atomIndexToDOFIndex.find(load->
getDirection().getToward());
50 if (titi != atomIndexToDOFIndex.end()){
51 unsigned int dofInd = titi->second;
52 dirX = (*mm->getX())[dofInd].x();
53 dirY = (*mm->getX())[dofInd].y();
54 dirZ = (*mm->getX())[dofInd].z();
61 std::map<unsigned int, unsigned int>::const_iterator result = atomIndexToDOFIndex.find(load->
getTarget(j));
62 if (result != atomIndexToDOFIndex.end()) {
65 addConstraint(result->second,
Deriv(dirX - (*mm->getX())[result->second].x(), dirY - (*mm->getX())[result->second].y(), dirZ - (*mm->getX())[result->second].z()));
70 fixDOF(result->second, 0);
72 fixDOF(result->second, 1);
74 fixDOF(result->second, 2);
78 loads.push_back(load);
84template<
class DataTypes>
87 this->targets.push_back(index);
89 this->translations.push_back(trans);
90 this->directionsNULLs.push_back(
Deriv(1, 1, 1));
91 this->initPos.push_back(
Deriv(0, 0, 0));
95template<
class DataTypes>
98 std::vector<unsigned int>::iterator it1 = targets.begin();
102 while (it1 != targets.end() && *it1 != (
unsigned)index) {
110 translations.erase(it2);
111 directionsNULLs.erase(it3);
118template<
class DataTypes>
122 std::vector<unsigned int>::iterator it1 = targets.begin();
123 VecDerivIterator it2 = directionsNULLs.begin();
124 while (it1 != targets.end() && *it1 != (
unsigned)index) {
133template<
class DataTypes>
136 SReal time = this->getContext()->getTime()-initTime;
139 std::vector<unsigned int>::iterator it1 = targets.begin();
145 for (
unsigned int i = 0 ; i < loads.size() ; i++) {
152 if (atomToDOFIndexes.find(load->
getTarget(j)) != atomToDOFIndexes.end())
170template <
class DataTypes>
172 for (std::vector<unsigned int>::iterator it1 = targets.begin();it1 != targets.end();++it1) {
179template<
class DataTypes>
182 SReal time = this->getContext()->getTime()-initTime;
183 SReal prevTime = time - this->getContext()->getDt();
185 std::vector<unsigned int>::iterator it1 = targets.begin();
190 for (
unsigned int i = 0 ; i < loads.size() ; i++)
195 if (atomToDOFIndexes.find(load->
getTarget(j)) != atomToDOFIndexes.end()) {
202 std::map<unsigned int, unsigned int>::const_iterator titi = atomToDOFIndexes.find(load->
getDirection().getToward());
203 if (titi != atomToDOFIndexes.end()){
204 (*it2) = (*mmodel->getX())[titi->second] - (*mmodel->getX())[*it1];
209 double lastValue = (prevTime < 0.0) ? 0.0 : load->
getValue(prevTime);
213 x[*it1] = (*it3) + (*it2) * (load->
getValue(time) - lastValue);
227template<
class DataTypes>
273template<
class DataTypes>
Class that describes a load to be used in the simulation.
Definition Load.h:53
double getValue(const double d=0.0)
The current value at date d (default: d = 0.0).
Definition Load.cpp:112
void getDirection(double &x, double &y, double &z) const
Get the direction.
Definition Load.cpp:235
unsigned int numberOfTargets() const
get the number of target
Definition Load.cpp:224
int getTarget(const unsigned int target) const
Get a target by index.
Definition Load.cpp:229
std::string getType() const
get the type string, has to be impleted in subclasses
Definition Load.cpp:283
This class makes it possible to manage a list of "Load".
Definition Loads.h:71
Load * getLoad(const unsigned int i) const
get a load by its index in the list
Definition Loads.cpp:249
unsigned int numberOfLoads() const
get the number of "Load" stored in the list
Definition Loads.cpp:259
TODO Comment class here.
Definition TranslationConstraint.h:48
DataTypes::VecDeriv::iterator VecDerivIterator
Definition TranslationConstraint.h:54
TranslationConstraint< DataTypes > * addConstraint(unsigned int index, Deriv trans)
fix or translate a point
Definition TranslationConstraint.inl:85
TranslationConstraint(Loads *loadsList, const std::map< unsigned int, unsigned int > &atomIndexToDOFIndex, sofa::core::behavior::MechanicalState< DataTypes > *mm)
constructor
Definition TranslationConstraint.inl:37
DataTypes::VecDeriv VecDeriv
Definition TranslationConstraint.h:52
TranslationConstraint< DataTypes > * removeConstraint(int index)
Definition TranslationConstraint.inl:96
virtual void projectPosition(VecCoord &x)
project x to constrained space (x models a position)
Definition TranslationConstraint.inl:180
void setInitTime(double time)
set initial time (context->getTime() remind the same when simulation is rewind)
Definition TranslationConstraint.inl:274
DataTypes::VecCoord VecCoord
template types
Definition TranslationConstraint.h:51
void projectResponse(VecDeriv &dx)
Constraint inherits.
Definition TranslationConstraint.inl:134
void draw()
– VisualModel interface
Definition TranslationConstraint.inl:228
virtual void projectVelocity(VecDeriv &v)
project dx to constrained space (dx models a velocity)
Definition TranslationConstraint.inl:171
DataTypes::Deriv Deriv
Definition TranslationConstraint.h:56