39 BaseSpineModelLearning::BaseSpineModelLearning(
int segments) :
45 BaseSpineModelLearning::~BaseSpineModelLearning()
66 m_allSegments.clear();
80 const std::vector<tgLinearString*>&
81 BaseSpineModelLearning::getMuscles (
const std::string& key)
const
83 const MuscleMap::const_iterator it = m_muscleMap.find(key);
84 if (it == m_muscleMap.end())
86 throw std::invalid_argument(
"Key '" + key +
"' not found in muscle map");
94 const std::vector<tgLinearString*>& BaseSpineModelLearning::getAllMuscles()
99 const int BaseSpineModelLearning::getSegments()
104 std::vector<double> BaseSpineModelLearning::getSegmentCOM(
const int n)
const
106 if (m_allSegments.size() != m_segments)
108 throw std::runtime_error(
"Not initialized");
112 throw std::range_error(
"Negative segment number");
114 else if (n >= m_segments)
116 throw std::range_error(
tgString(
"Segment number > ", m_segments));
119 std::vector<tgRod*> p_rods =
120 tgCast::filter<tgModel, tgRod> (m_allSegments[n]->getDescendants());
123 assert(!p_rods.empty());
125 btVector3 segmentCenterOfMass(0, 0, 0);
126 double segmentMass = 0.0;
127 for (std::size_t i = 0; i < p_rods.size(); i++)
129 const tgRod*
const pRod = p_rods[i];
130 assert(pRod != NULL);
131 const double rodMass = pRod->
mass();
132 std::cout <<
"mass " << rodMass;
134 segmentCenterOfMass += rodCenterOfMass * rodMass;
135 segmentMass += rodMass;
139 assert(segmentMass > 0.0);
141 segmentCenterOfMass /= segmentMass;
144 std::vector<double> result(3);
145 for (
size_t i = 0; i < 3; ++i) { result[i] = segmentCenterOfMass[i]; }
virtual void setup(tgWorld &world)
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
Utility class for class casting and filtering collections by type.
virtual void setup(tgWorld &world)
A template base class for a tensegrity spine.
btVector3 centerOfMass() const
Contains the definition of class tgLinearString.
std::string tgString(std::string s, int i)
Contains the definition of class tgRod $Id$.
virtual void step(double dt)