25 using namespace boost;
35 ProtoInfo(
int id, ProtoCheckFunc func) : id(id), protoCheckFunc(func) { }
37 ProtoCheckFunc protoCheckFunc;
40 typedef map<string,ProtoInfo> ProtoNameToInfoMap;
41 ProtoNameToInfoMap protoNameToInfoMap;
52 bool loadModelFile(
const std::string&
filename);
84 void addFloatField(
const std::string&
name,
double defaultValue);
86 void checkHumanoidProto();
87 void checkJointProto();
88 void checkSegmentProto();
89 void checkSensorProtoCommon();
90 void checkHardwareComponentProto();
91 void extractJointNodes();
92 void checkExtraJointProto();
94 void extractChildNodes
97 void putMessage(
const std::string& message);
113 if(protoNameToInfoMap.empty()){
115 protoNameToInfoMap[
"Humanoid"]
118 protoNameToInfoMap[
"Joint"]
121 protoNameToInfoMap[
"Segment"]
124 protoNameToInfoMap[
"ForceSensor"]
127 protoNameToInfoMap[
"Gyro"]
130 protoNameToInfoMap[
"AccelerationSensor"]
133 protoNameToInfoMap[
"VisionSensor"]
136 protoNameToInfoMap[
"RangeSensor"]
139 protoNameToInfoMap[
"HardwareComponent"]
142 protoNameToInfoMap[
"ExtraJoint"]
216 ProtoNameToInfoMap::iterator p = protoNameToInfoMap.find(
protoToCheck->protoName);
217 if(p != protoNameToInfoMap.end()){
218 ProtoInfo&
info = p->second;
219 (this->*info.protoCheckFunc)();
225 if(instance->proto->protoName ==
"Humanoid") {
227 }
else if(instance->proto->protoName ==
"ExtraJoint") {
244 string message =
"Proto \"";
245 message +=
protoToCheck->protoName +
"\" must have the \"" +
name +
"\" field of " +
254 if(!field || field->
typeId() != typeId){
263 if(field && field->
typeId() != typeId){
274 }
else if(field->
typeId() != typeId){
286 field->
sfFloat() = defaultValue;
311 std::fill(scale.begin(), scale.end(), 1.0);
331 (
"Prototype of Humanoid must have the \"jointAxis\" field");
335 (
"The type of \"jointAxis\" field in \"Humanoid\" prototype must be SFString or SFVec3f");
356 std::fill(scale.begin(), scale.end(), 1.0);
360 putMessage(
"The \"equivalentInertia\" field of the Joint node is obsolete.");
404 if(nodes.size() > 1){
406 (
"The Humanoid node must have a unique Joint node in its \"humanoidBody\" field.");
408 }
else if(nodes.size() == 1){
411 if(jointNode && jointNode->proto->protoName ==
"Joint"){
419 (
"The Humanoid node does not have a Joint node in its \"humanoidBody\" field.");
428 putMessage(
string(
"Joint node ") + jointNode->defName);
432 jointNodeSet->jointNode = jointNode;
434 MFNode& childNodes = jointNode->fields[
"children"].mfNode();
451 for(
size_t i = 0;
i < childNodes.size();
i++){
452 VrmlNode* childNode = childNodes[
i].get();
466 extractChildNodes(jointNodeSet, groupNode->
getChildren(), acceptableProtoIds, *pT);
469 jointNodeSet->lightNodes.push_back(std::make_pair(T,childNode));
473 int id = PROTO_UNDEFINED;
474 bool doTraverseChildren =
false;
475 ProtoIdSet acceptableChildProtoIds(acceptableProtoIds);
477 const string& protoName = protoInstance->
proto->protoName;
478 ProtoNameToInfoMap::iterator p = protoNameToInfoMap.find(protoName);
480 if(p == protoNameToInfoMap.end()){
481 doTraverseChildren =
true;
484 if(!acceptableProtoIds.test(
id)){
494 if(T != Matrix44::Identity())
496 jointNodeSet->childJointNodeSets.push_back(addJointNodeSet(protoInstance));
500 if(T != Matrix44::Identity())
502 jointNodeSet->sensorNodes.push_back(protoInstance);
503 putMessage(protoName + protoInstance->
defName);
506 case PROTO_HARDWARECOMPONENT:
507 if(T != Matrix44::Identity())
509 jointNodeSet->hwcNodes.push_back(protoInstance);
510 putMessage(protoName + protoInstance->
defName);
515 jointNodeSet->segmentNodes.push_back(protoInstance);
516 jointNodeSet->transforms.push_back(T);
517 putMessage(
string(
"Segment node ") + protoInstance->
defName);
519 doTraverseChildren =
true;
520 acceptableChildProtoIds.reset();
521 acceptableChildProtoIds.set(PROTO_SENSOR);
529 if(doTraverseChildren){
530 if (protoInstance->
fields.count(
"children")){
531 MFNode& childNodes = protoInstance->
fields[
"children"].mfNode();
532 extractChildNodes(jointNodeSet, childNodes, acceptableChildProtoIds, T);
546 self->sigMessage(space + message +
"\n");