33 void DuCTTTestModel::addNodes(
tgStructure& tetra,
double edge,
double height)
36 tetra.
addNode(-edge / 2.0, 0, tgUtil::round(std::sqrt(3.0) / 2.0 * height));
38 tetra.
addNode( edge / 2.0, 0, tgUtil::round(std::sqrt(3.0) / 2.0 * height));
46 tetra.
addNode(-0.01, 0, tgUtil::round(std::sqrt(3.0) / 2.0 * height));
48 tetra.
addNode(0.01, 0, tgUtil::round(std::sqrt(3.0) / 2.0 * height));
58 tetra.
addPair(3, 0,
"back right rod");
59 tetra.
addPair(3, 1,
"back left rod");
60 tetra.
addPair(2, 0,
"front right rod");
61 tetra.
addPair(2, 1,
"front left rod");
67 addBottomPairs(tetra);
71 void DuCTTTestModel::addTopPairs(
tgStructure& tetra)
73 tetra.
addPair(0, 4,
"top1 rod");
74 tetra.
addPair(5, 1,
"top2 rod");
76 tetra.
addPair(4, 5,
"top prismatic");
79 void DuCTTTestModel::addBottomPairs(
tgStructure& tetra)
81 tetra.
addPair(2, 6,
"bottom1 rod");
82 tetra.
addPair(7, 3,
"bottom2 rod");
84 tetra.
addPair(6, 7,
"bottom prismatic");
91 const btVector3 offset(0, 0, -edge * 1.15);
92 for (
size_t i = 0; i < segmentCount; ++i)
95 t->addTags(
tgString(
"segment", i + 1));
96 t->move((i + 1) * offset);
103 void DuCTTTestModel::addMuscles(
tgStructure& snake)
105 std::vector<tgStructure*> children = snake.
getChildren();
106 for (
size_t i = 1; i < children.size(); ++i)
108 addBottomPairs(*children[i]);
109 addTopPairs(*children[i-1]);
114 tgNodes n0 = children[i-1]->getNodes();
115 tgNodes n1 = children[i ]->getNodes();
117 snake.
addPair(n0[0], n1[0],
"top right muscle");
118 snake.
addPair(n0[1], n1[1],
"top left muscle");
120 snake.
addPair(n0[2], n1[0],
"front right muscle");
121 snake.
addPair(n0[2], n1[1],
"front left muscle");
123 snake.
addPair(n0[3], n1[0],
"back right muscle");
124 snake.
addPair(n0[3], n1[1],
"back left muscle");
126 snake.
addPair(n0[2], n1[2],
"bottom front muscle");
127 snake.
addPair(n0[3], n1[3],
"bottom back muscle");
151 std::cout <<
"StructureInfo:" << std::endl
152 << structureInfo << std::endl
153 <<
"Model: " << std::endl
154 << model << std::endl;
159 const double edge = 30.0;
160 const double height = tgUtil::round(std::sqrt(3.0)/2 * edge);
161 std::cout <<
"edge: " << edge <<
"; height: " << height << std::endl;
165 addNodes(tetra, edge, height);
169 tetra.move(btVector3(0.0, edge, 10.0));
173 addSegments(snake, tetra, edge, 1);
179 const double density = 4.2 / 300.0;
180 const double radius = 0.5;
185 spec.addBuilder(
"rod",
new tgRodInfo(rodConfig));
194 structureInfo.buildInto(*
this, world);
198 allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (
getDescendants());
199 mapMuscles(muscleMap, *
this);
201 trace(structureInfo, *
this);
204 std::cout <<
"StructureInfo:" << std::endl;
205 std::cout << structureInfo << std::endl;
207 std::cout <<
"Model: " << std::endl;
208 std::cout << *
this << std::endl;
213 std::cout <<
"Finished Setup!" << std::endl;
220 throw std::invalid_argument(
"dt is not positive");
231 const std::vector<tgSpringCableActuator*>&
234 const MuscleMap::const_iterator it = muscleMap.find(key);
235 if (it == muscleMap.end())
237 throw std::invalid_argument(
"Key '" + key +
"' not found in muscle map");
const std::vector< tgStructure * > & getChildren() const
virtual void setup(tgWorld &world)
void addChild(tgStructure *child)
DuCTTTestModel(size_t segments)
virtual void step(const double dt)
virtual void step(double dt)
const std::vector< tgSpringCableActuator * > & getMuscles(const std::string &key) const
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Contains the definition of class DuCTTTestModel.
std::map< std::string, std::vector< tgSpringCableActuator * > > MuscleMap
std::string tgString(std::string s, int i)
std::vector< T * > find(const tgTagSearch &tagSearch)
virtual void setup(tgWorld &world)
void notifyStep(double dt)
std::vector< tgModel * > getDescendants() const
void addNode(double x, double y, double z, std::string tags="")