1 #ifndef SimTK_SIMMATH_MULTIBODY_GRAPH_MAKER_H_
2 #define SimTK_SIMMATH_MULTIBODY_GRAPH_MAKER_H_
159 explicit Body(
const std::string& name,
163 : name(name), mass(mass), mustBeBaseBody(mustBeBaseBody),
164 userRef(userRef), level(-1), mobilizer(-1), master(-1) {}
170 {
return int(jointsAsChild.size() + jointsAsParent.size()); }
197 Joint(
const std::string& name,
int jointTypeNum,
198 int parentBodyNum,
int childBodyNum,
199 bool mustBeLoopJoint,
void* userRef)
201 mustBeLoopJoint(mustBeLoopJoint),
203 parentBodyNum(parentBodyNum),
204 childBodyNum(childBodyNum),
205 jointTypeNum(jointTypeNum),
206 isAddedBaseJoint(false),
208 loopConstraint(-1) {}
239 bool haveGoodLoopJointAvailable,
void* userRef)
240 : name(name), numMobilities(numMobilities),
241 haveGoodLoopJointAvailable(haveGoodLoopJointAvailable),
255 : joint(-1), level(-1), inboardBody(-1), outboardBody(-1),
256 isReversed(false), mgm(0) {}
257 Mobilizer(
int jointNum,
int level,
int inboardBodyNum,
int outboardBodyNum,
259 : joint(jointNum), level(level), inboardBody(inboardBodyNum),
260 outboardBody(outboardBodyNum), isReversed(isReversed),
270 {
return mgm->getJoint(joint).isAddedBaseJoint; }
275 {
return mgm->getJoint(joint).userRef; }
281 {
return mgm->getBody(inboardBody).userRef; }
288 {
return mgm->getBody(outboardBody).userRef; }
294 {
return mgm->getBody(getOutboardMasterBodyNum()).userRef; }
297 {
return mgm->getJointType(mgm->getJoint(joint).jointTypeNum).name; }
301 {
return mgm->getJointType(mgm->getJoint(joint).jointTypeNum).userRef; }
305 {
return mgm->getBody(outboardBody).isSlave(); }
312 {
return mgm->getBody(getOutboardMasterBodyNum()).getNumFragments(); }
324 int getOutboardMasterBodyNum()
const
325 {
const Body& outb = mgm->getBody(outboardBody);
343 int parentBodyNum,
int childBodyNum,
345 : type(type), joint(jointNum),
346 parentBody(parentBodyNum), childBody(childBodyNum),
352 {
return mgm->getJoint(joint).userRef; }
360 {
return mgm->getBody(parentBody).userRef; }
364 {
return mgm->getBody(childBody).userRef; }
388 bool haveGoodLoopJointAvailable =
false,
460 const std::string& type,
461 const std::string& parentBodyName,
462 const std::string& childBodyName,
463 bool mustBeLoopJoint,
495 {
return mobilizers[mobilizerNum]; }
508 {
return constraints[loopConstraintNum]; }
521 std::map<std::string,int>::const_iterator p =
522 bodyName2Num.find(bodyName);
523 return p==bodyName2Num.end() ? -1 : p->second;
538 std::map<std::string,int>::const_iterator p =
539 jointName2Num.find(jointName);
540 return p==jointName2Num.end() ? -1 : p->second;
547 {
return jointTypes[jointTypeNum]; }
550 std::map<std::string,int>::const_iterator p =
551 jointTypeName2Num.find(jointTypeName);
552 return p==jointTypeName2Num.end() ? -1 : p->second;
559 { weldTypeName=name; initialize(); }
568 { freeTypeName=name; initialize(); }
578 Body& updBody(
int bodyNum) {
return bodies[bodyNum];}
579 Joint& updJoint(
int jointNum) {
return joints[jointNum];}
580 Joint& updJoint(
const std::string& name) {
return joints[jointName2Num[name]];}
583 int splitBody(
int bodyNum);
584 int chooseNewBaseBody()
const;
585 void connectBodyToGround(
int bodyNum);
586 int addMobilizerForJoint(
int jointNum);
587 int findHeaviestUnassignedForwardJoint(
int inboardBody)
const;
588 int findHeaviestUnassignedReverseJoint(
int inboardBody)
const;
591 bool bodiesAreConnected(
int b1,
int b2)
const;
595 bodies.clear(); joints.clear(); jointTypes.clear();
596 bodyName2Num.clear(); jointName2Num.clear(); jointTypeName2Num.clear();
597 mobilizers.clear(); constraints.clear();
600 std::string weldTypeName, freeTypeName;
601 std::vector<Body> bodies;
602 std::vector<Joint> joints;
603 std::vector<JointType> jointTypes;
604 std::map<std::string,int> bodyName2Num;
605 std::map<std::string,int> jointName2Num;
606 std::map<std::string,int> jointTypeName2Num;
609 std::vector<Mobilizer> mobilizers;
610 std::vector<LoopConstraint> constraints;
Includes internal headers providing declarations for the basic SimTK Core classes,...
This is the header file that every Simmath compilation unit should include first.
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
Local class that collects information about bodies.
Definition: MultibodyGraphMaker.h:157
Body(const std::string &name, double mass, bool mustBeBaseBody, void *userRef)
Definition: MultibodyGraphMaker.h:159
int master
Definition: MultibodyGraphMaker.h:190
void forgetGraph(MultibodyGraphMaker &graph)
int level
Definition: MultibodyGraphMaker.h:187
std::vector< int > jointsAsChild
Definition: MultibodyGraphMaker.h:182
bool isMaster() const
Definition: MultibodyGraphMaker.h:172
int getNumJoints() const
Definition: MultibodyGraphMaker.h:169
int getNumFragments() const
Definition: MultibodyGraphMaker.h:167
int mobilizer
Definition: MultibodyGraphMaker.h:188
std::vector< int > jointsAsParent
Definition: MultibodyGraphMaker.h:183
double mass
Definition: MultibodyGraphMaker.h:177
int getNumSlaves() const
Definition: MultibodyGraphMaker.h:168
std::string name
Definition: MultibodyGraphMaker.h:176
std::vector< int > slaves
Definition: MultibodyGraphMaker.h:191
void * userRef
Definition: MultibodyGraphMaker.h:179
bool isInTree() const
Definition: MultibodyGraphMaker.h:173
bool mustBeBaseBody
Definition: MultibodyGraphMaker.h:178
bool isSlave() const
Definition: MultibodyGraphMaker.h:171
Local class that defines the properties of a known joint type.
Definition: MultibodyGraphMaker.h:236
JointType(const std::string &name, int numMobilities, bool haveGoodLoopJointAvailable, void *userRef)
Definition: MultibodyGraphMaker.h:238
bool haveGoodLoopJointAvailable
Definition: MultibodyGraphMaker.h:245
std::string name
Definition: MultibodyGraphMaker.h:243
int numMobilities
Definition: MultibodyGraphMaker.h:244
void * userRef
Definition: MultibodyGraphMaker.h:246
Local class that collects information about joints.
Definition: MultibodyGraphMaker.h:195
std::string name
Definition: MultibodyGraphMaker.h:220
bool isAddedBaseJoint
Definition: MultibodyGraphMaker.h:228
int mobilizer
Definition: MultibodyGraphMaker.h:231
bool hasMobilizer() const
Definition: MultibodyGraphMaker.h:216
Joint(const std::string &name, int jointTypeNum, int parentBodyNum, int childBodyNum, bool mustBeLoopJoint, void *userRef)
Definition: MultibodyGraphMaker.h:197
bool mustBeLoopJoint
Definition: MultibodyGraphMaker.h:221
void * userRef
Definition: MultibodyGraphMaker.h:222
int jointTypeNum
Definition: MultibodyGraphMaker.h:226
bool hasLoopConstraint() const
Definition: MultibodyGraphMaker.h:217
bool forgetGraph(MultibodyGraphMaker &graph)
Return true if the joint is deleted as a result of restoring it to the state prior to generateGraph()...
int childBodyNum
Definition: MultibodyGraphMaker.h:225
int loopConstraint
Definition: MultibodyGraphMaker.h:232
Local class that represents one of the constraints that were added to close topological loops that we...
Definition: MultibodyGraphMaker.h:339
LoopConstraint(const std::string &type, int jointNum, int parentBodyNum, int childBodyNum, MultibodyGraphMaker *graphMaker)
Definition: MultibodyGraphMaker.h:342
const std::string & getJointTypeName() const
Get the loop constraint type name of the constraint that should be used here.
Definition: MultibodyGraphMaker.h:355
void * getJointRef() const
Get the user reference pointer for the joint associated with this loop constraint.
Definition: MultibodyGraphMaker.h:351
void * getChildBodyRef() const
Get the user reference pointer for the child body defined by the joint associated with this loop cons...
Definition: MultibodyGraphMaker.h:363
void * getParentBodyRef() const
Get the user reference pointer for the parent body defined by the joint associated with this loop con...
Definition: MultibodyGraphMaker.h:359
LoopConstraint()
Definition: MultibodyGraphMaker.h:341
Local class that represents one of the mobilizers (tree joints) in the generated spanning tree.
Definition: MultibodyGraphMaker.h:252
bool isAddedBaseMobilizer() const
Return true if this mobilizer does not represent one of the input joints, but is instead a joint we a...
Definition: MultibodyGraphMaker.h:269
bool isReversedFromJoint() const
Return true if this mobilizer represents one of the input joints but the sense of inboard->outboard i...
Definition: MultibodyGraphMaker.h:317
void * getJointRef() const
Get the user reference pointer for the joint associated with this mobilizer, if there is such a joint...
Definition: MultibodyGraphMaker.h:274
int getNumFragments() const
Return the number of fragments into which we chopped the outboard body of this mobilizer.
Definition: MultibodyGraphMaker.h:311
bool isSlaveMobilizer() const
Return true if the outboard body of this mobilizer is a slave we created in order to cut a loop,...
Definition: MultibodyGraphMaker.h:304
void * getInboardBodyRef() const
Get the user reference pointer for the inboard body of this mobilizer.
Definition: MultibodyGraphMaker.h:280
void * getOutboardMasterBodyRef() const
Get the user reference pointer for the outboard body of this mobilizer, if it is one of the input bod...
Definition: MultibodyGraphMaker.h:293
Mobilizer(int jointNum, int level, int inboardBodyNum, int outboardBodyNum, bool isReversed, MultibodyGraphMaker *graphMaker)
Definition: MultibodyGraphMaker.h:257
Mobilizer()
Definition: MultibodyGraphMaker.h:254
int getLevel() const
Return the level of the outboard body (Ground is level 0)
Definition: MultibodyGraphMaker.h:319
void * getJointTypeRef() const
Get the reference pointer (if any) that was provided when this mobilizer's joint type was defined in ...
Definition: MultibodyGraphMaker.h:300
const std::string & getJointTypeName() const
Get the joint type name of the joint that this mobilizer represents.
Definition: MultibodyGraphMaker.h:296
void * getOutboardBodyRef() const
Get the user reference pointer for the outboard body of this mobilizer.
Definition: MultibodyGraphMaker.h:287
Construct a reasonably good spanning-tree-plus-constraints structure for modeling a given set of bodi...
Definition: MultibodyGraphMaker.h:152
const JointType & getJointType(int jointTypeNum) const
Get a JointType object by its assigned number.
Definition: MultibodyGraphMaker.h:546
int getNumLoopConstraints() const
Return the number of loop joint constraints that were used to close loops in the graph topology.
Definition: MultibodyGraphMaker.h:504
int addJointType(const std::string &name, int numMobilities, bool haveGoodLoopJointAvailable=false, void *userRef=0)
Specify relevant properties of a joint type.
void dumpGraph(std::ostream &out) const
Output a text representation of the multibody graph for debugging.
void setWeldJointTypeName(const std::string &name)
Change the name to be used to identify the weld joint type (0 dof) and weld loop constraint type (6 c...
Definition: MultibodyGraphMaker.h:558
const std::string & getGroundBodyName() const
Return the name we recognize as the Ground (or World) body.
const std::string & getWeldJointTypeName() const
Return the name currently being used to identify the weld joint type and weld loop constraint type.
Definition: MultibodyGraphMaker.h:562
void setFreeJointTypeName(const std::string &name)
Change the name to be used to identify the free (6 dof) joint type and free (0 constraints) loop cons...
Definition: MultibodyGraphMaker.h:567
int getNumJoints() const
Return the number of joints, including all input joints, and all joints added to connect otherwise di...
Definition: MultibodyGraphMaker.h:530
void clearGraph()
Throw away the multibody graph produced by generateGraph().
int getJointNum(const std::string &jointName) const
Return the joint number assigned to the input joint with the given name.
Definition: MultibodyGraphMaker.h:537
int getNumBodies() const
Return the number of bodies, including all input bodies, a ground body, and any slave bodies.
Definition: MultibodyGraphMaker.h:512
const Mobilizer & getMobilizer(int mobilizerNum) const
Get a Mobilizer object by its mobilizer number, ordered outwards by topological distance from Ground.
Definition: MultibodyGraphMaker.h:494
const Body & getBody(int bodyNum) const
Get a Body object by its assigned number.
Definition: MultibodyGraphMaker.h:516
const LoopConstraint & getLoopConstraint(int loopConstraintNum) const
Get a loop constraint by its assigned number.
Definition: MultibodyGraphMaker.h:507
int getBodyNum(const std::string &bodyName) const
Return the body number assigned to the input body with the given name.
Definition: MultibodyGraphMaker.h:520
int getJointTypeNum(const std::string &jointTypeName) const
Get the assigned number for a joint type from the type name.
Definition: MultibodyGraphMaker.h:549
MultibodyGraphMaker()
Construct an empty MultibodyGraphMaker object and set the default names for weld and free joints to "...
bool deleteBody(const std::string &name)
Delete a body (link) from the set of input bodies.
void addBody(const std::string &name, double mass, bool mustBeBaseBody, void *userRef=0)
Add a new body (link) to the set of input bodies.
int getNumJointTypes() const
Return the number of registered joint types.
Definition: MultibodyGraphMaker.h:544
void addJoint(const std::string &name, const std::string &type, const std::string &parentBodyName, const std::string &childBodyName, bool mustBeLoopJoint, void *userRef=0)
Add a new joint to the set of input joints.
const Joint & getJoint(int jointNum) const
Get a Joint object by its assigned number.
Definition: MultibodyGraphMaker.h:533
bool deleteJoint(const std::string &name)
Delete an existing joint from the set of input joints.
void generateGraph()
Generate a new multibody graph from the input data.
const std::string & getFreeJointTypeName() const
Return the name currently being used to identify the free joint type and free loop constraint type.
Definition: MultibodyGraphMaker.h:571
int getNumMobilizers() const
Returns the number of mobilizers (tree joints) in the spanning tree.
Definition: MultibodyGraphMaker.h:491
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37