V-ART
jointmover.cpp
Go to the documentation of this file.
1 
5 #include "vart/jointmover.h"
6 #include "vart/dof.h"
7 #include "vart/dofmover.h"
8 #include "vart/noisydofmover.h"
9 #include "vart/time.h"
11 #include "vart/dmmodifier.h"
12 #include <algorithm>
13 #include <cassert>
14 
15 //#include <iostream>
16 using namespace std;
17 
19 
21 {
22  jointPtr = NULL;
23  interpolatorPtr = NULL;
24 }
25 
27  float newDuration, const VART::Interpolator& interpolator)
28 {
29  jointPtr = newJointPtr;
30  duration = newDuration;
31  interpolatorPtr = &interpolator;
32  minimumDuration = newDuration * 0.5;
33 }
34 
36 {
37  list<VART::DofMover*>::iterator iter;
38  // remove all DOF movers from memory
39  for (iter = dofMoverList.begin(); iter != dofMoverList.end(); ++iter)
40  delete *iter;
41 }
42 
44 // Note: A joint mover passes parameters to dof movers by setting some VART::DofMover class attributes.
45 // This implementation should make animations a bit faster.
46 {
47  list<VART::DofMover*>::iterator iter;
48 
49  // pass normalized elapsed time to dof movers
50  VART::DofMover::goalTime = goalTime/duration;
51  // pass interpolator to dof movers
52  VART::DofMover::interpolatorPtr = interpolatorPtr;
53  VART::DofMover::minimumDuration = minimumDuration;
54  // activate dof movers
55  for (iter = dofMoverList.begin(); iter != dofMoverList.end(); ++iter)
56  (*iter)->Move();
57 }
58 
59 void VART::JointMover::AddDofMover(VART::Joint::DofID dof, float iniTime, float finTime, float finPos)
60 {
61  float minimumDurationCandidate = (finTime - iniTime) * 0.5;
62  VART::DofMover* moverPtr = new VART::DofMover;
63  moverPtr->Initialize(iniTime, finTime, finPos);
64  moverPtr->SetDof(const_cast<VART::Dof*>(&(jointPtr->GetDof(dof))));
65  assert(moverPtr->targetDofPtr != NULL);
66  dofMoverList.push_back(moverPtr);
67  if (minimumDurationCandidate < minimumDuration)
68  minimumDuration = minimumDurationCandidate;
69  //~ cout << "joint mover "<<this<<" added dof mover "<<moverPtr<<endl;
70 }
71 
73  float iniTime, float finTime, float finPos)
74 {
75  float minimumDurationCandidate = (finTime - iniTime) * 0.5;
77 
78  moverPtr->Initialize(iniTime, finTime, finPos);
79  moverPtr->SetDof(const_cast<VART::Dof*>(&(jointPtr->GetDof(dof))));
80  assert(moverPtr->targetDofPtr != NULL);
81  dofMoverList.push_back(moverPtr);
82  if (minimumDurationCandidate < minimumDuration)
83  minimumDuration = minimumDurationCandidate;
84  return moverPtr;
85 }
86 
88 {
89  list<VART::DofMover*>::iterator iter;
90  for (iter = dofMoverList.begin(); iter != dofMoverList.end(); ++iter)
91  (*iter)->active = false;
92 }
93 
95 {
96  list<VART::DofMover*>::iterator iter;
97  //~ cout << "\nJointMover " << this << " at MultiplyTimes(" << value << ")\n";
98  for (iter = dofMoverList.begin(); iter != dofMoverList.end(); ++iter)
99  {
100  //~ cout << "Dof mover " << this << " intialTime: " << (*iter)->initialTime << " to " << (*iter)->initialTime * value << "\n";
101  (*iter)->initialTime *= value;
102  //~ cout << "Dof mover " << this << " finalTime: " << (*iter)->finalTime << " to " << (*iter)->finalTime * value << "\n";
103  (*iter)->finalTime *= value;
104  }
105 }
106 
108 {
109  if (jointPtr->HasDof(dofID))
110  {
111  const Dof* dofPtr = &(jointPtr->GetDof(dofID));
112  list<DofMover*>::iterator iter = dofMoverList.begin();
113  for (; iter != dofMoverList.end(); ++iter)
114  {
115  if ((*iter)->GetTarget() == dofPtr)
116  return *iter;
117  }
118  }
119  return NULL;
120 }
121 
122 void VART::JointMover::GetFinalTimes(list<float>* resultPtr)
123 {
124  list<VART::DofMover*>::iterator iter;
125 
126  for (iter = dofMoverList.begin(); iter != dofMoverList.end(); ++iter)
127  (*iter)->GetFinalTime(resultPtr);
128 }
129 
130 void VART::JointMover::CopyFrom( VART::JointMover& jointMover, VART::Joint* targetJoint )
131 {
132  VART::NoisyDofMover* noisyDofMover;
133  VART::DofMover * dofMover;
134  VART::Joint::DofID dofId;
135  std::list<VART::DofMover*>::iterator iter;
136 
137  jointPtr = targetJoint;
138  duration = jointMover.duration;
139  minimumDuration = jointMover.minimumDuration;
140  interpolatorPtr = jointMover.interpolatorPtr;
141  for( iter = jointMover.dofMoverList.begin(); iter != jointMover.dofMoverList.end(); iter++ )
142  {
143  dofId = jointMover.jointPtr->GetDofID( (*iter)->GetTarget() );
144  noisyDofMover = dynamic_cast<VART::NoisyDofMover*>(*iter);
145  if( noisyDofMover )
146  AddNoisyDofMover( dofId, noisyDofMover->initialTime, noisyDofMover->finalTime, noisyDofMover->targetPosition );
147  else
148  {
149  dofMover = *iter;
150  AddDofMover( dofId, dofMover->initialTime, dofMover->finalTime, dofMover->targetPosition );
151  }
152  }
153 }
154 
156 {
157  list<DofMover*>::iterator dofIter = dofMoverList.begin();
158  for (; dofIter != dofMoverList.end(); ++dofIter)
159  {
160  NoisyDofMover* dofMoverPtr = dynamic_cast<NoisyDofMover*>(*dofIter);
161  if (dofMoverPtr)
162  modifier.Modify(dofMoverPtr);
163  }
164 }
165 
166 ostream& VART::operator<<(ostream& output, const VART::JointMover& mover)
167 {
168  list<VART::DofMover*>::const_iterator iter = mover.dofMoverList.begin();
169 
170  output << " <joint_movement joint_name=\""<< mover.jointPtr->GetDescription() << "\" duration=\""
171  << mover.duration << "\">\n <interpolation type=\"";
172  switch (mover.interpolatorPtr->GetID())
173  {
174  case Interpolator::LINEAR:
175  output << "linear\"/>\n";
176  break;
177  case Interpolator::EASE_IN_EASE_OUT:
178  output << "ease-in_ease-out\"/>\n";
179  break;
180  default:
181  output << "unknown\"/>\n";
182  break;
183  }
184  // for each dof mover
185  while (iter != mover.dofMoverList.end()) {
186  output << " <dof_movement dofID=\""
187  << mover.jointPtr->GetDofID((*iter)->GetTarget()) << "\" "
188  << **iter << "/>\n";
189  ++iter;
190  }
191  output << " </joint_movement>\n";
192  return output;
193 }
void GetFinalTimes(std::list< float > *resultPtr)
Returns a list with all different final times for every dof mover.
Definition: jointmover.cpp:122
void ModifyDofMovers(DMModifier &modifier)
Modifies noisy dof movers.
Definition: jointmover.cpp:155
Header file for V-ART class "Dof".
Representation of joints.
Definition: joint.h:34
float minimumDuration
Definition: jointmover.h:99
Header file for V-ART class "Time".
const Interpolator * interpolatorPtr
Definition: jointmover.h:100
static float goalTime
Time of next snapshot, normalized to joint movement's duration.
Definition: dofmover.h:74
static float goalTime
Definition: jointmover.h:92
Dof * targetDofPtr
Target DOF.
Definition: dofmover.h:65
const std::string & GetDescription() const
Returns a copy of the object's description.
Definition: scenenode.h:50
std::ostream & operator<<(std::ostream &output, const Joint::DofID &dofId)
static float minimumDuration
Minimum duration when computing motion paths.
Definition: dofmover.h:82
Joint * jointPtr
Associated joint.
Definition: jointmover.h:97
float finalTime
Normalized deactivation time.
Definition: dofmover.h:59
virtual void Modify(NoisyDofMover *moverPtr)=0
Header file for V-ART class "JointMover".
void CopyFrom(VART::JointMover &jointMover, VART::Joint *targetJoint)
Copy jointMover data to this jointMover, setting its jointPtr atribute to the targetJoint.
Definition: jointmover.cpp:130
void DeactivateDofMovers()
Deactivates all DOF movers.
Definition: jointmover.cpp:87
An object that modifies noisy dof movers.
Definition: dmmodifier.h:15
static const Interpolator * interpolatorPtr
Position interpolator.
Definition: dofmover.h:78
Controller for DOF movement.
Definition: dofmover.h:24
Interpolator representation.
Definition: interpolator.h:17
Controllers for joint movement.
Definition: jointmover.h:22
virtual void Initialize(float iniTime, float finTime, float finPos)
Initializes a noisy DOF mover.
Header file for V-ART class "DofMover".
void MultiplyTimes(float value)
Changes starting/ending times of all dof movers.
Definition: jointmover.cpp:94
Noisy Controller for DOF movement.
Definition: noisydofmover.h:17
float initialTime
Time of predicted activation (normalized).
Definition: dofmover.h:55
virtual TypeID GetID() const =0
void Move()
Moves the associated joint.
Definition: jointmover.cpp:43
Header file for V-ART class "NoisyDofMover".
DofID GetDofID(const Dof *dofPtr) const
Returns the DofID of some member Dof.
Definition: joint.cpp:127
DofMover * GetDofMover(Joint::DofID dof)
Return the DofMover working on given Dof.
Definition: jointmover.cpp:107
Header file for V-ART class "LinearInterpolator".
void SetDof(Dof *dofPtr)
Sets the target DOF.
Definition: dofmover.h:42
std::list< DofMover * > dofMoverList
Definition: jointmover.h:101
Degree Of Freedom - basic component of a Joint.
Definition: dof.h:28
void AddDofMover(Joint::DofID dof, float iniTime, float finTime, float finPos)
Creates a DofMover.
Definition: jointmover.cpp:59
NoisyDofMover * AddNoisyDofMover(Joint::DofID dof, float iniTime, float finTime, float finPos)
Creates a noisy DofMover.
Definition: jointmover.cpp:72
virtual void Initialize(float iniTime, float finTime, float finPos)
Definition: dofmover.cpp:36
float targetPosition
Target position.
Definition: dofmover.h:51