From: Markus R. <rol...@us...> - 2006-02-19 15:04:13
|
Update of /cvsroot/simspark/simspark/spark/plugin/rosimporter In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8248 Modified Files: rosimporter.cpp rosimporter.h Log Message: - an object within a 'movable' tag has not necessarily a physical Body - added a valid flag to the physical description - moved decision whether to create a Body to function HasBody() - when macros are instantiated with a translation or rotation, an additional Transform node is required. Therefore GetJointParentBody has to walk up the hierarchy Index: rosimporter.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** rosimporter.cpp 19 Feb 2006 14:16:58 -0000 1.6 --- rosimporter.cpp 19 Feb 2006 15:04:01 -0000 1.7 *************** *** 139,142 **** --- 139,150 ---- } + bool RosImporter::HasBody(const Physical& physical, ENodeContext context) + { + return ( + (physical.valid) && + (context == NC_MOVABLE) + ); + } + bool RosImporter::ParseScene(const char* scene, int size, shared_ptr<BaseNode> parent, *************** *** 468,477 **** ) { ! TiXmlElement* element = static_cast<TiXmlElement*>(node); ! if (element == 0) { continue; } bool ok = true; --- 476,485 ---- ) { ! if (IgnoreNode(node)) { continue; } + TiXmlElement* element = static_cast<TiXmlElement*>(node); bool ok = true; *************** *** 676,679 **** --- 684,689 ---- bool RosImporter::ReadPhysical(TiXmlElement* element, Physical& physical, ENodeContext context) { + physical.valid = false; + if (context != NC_MOVABLE) { *************** *** 684,717 **** if (physElem == 0) { ! string name = S_UNNAMED; ! ReadAttribute(element, RA_NAME, name, true); ! ! GetLog()->Error() << "(RosImporter) ERROR: missing physical attributes in " ! << GetXMLPath(element) << " name " << name << "\n"; ! return false; } ! // we must have a mass TiXmlElement* massElem = GetFirstChild(physElem, RosElements::RE_MASS); ! if (massElem == 0) { - string name = S_UNNAMED; - ReadAttribute(element, RA_NAME, name, true); - - GetLog()->Error() << "(RosImporter) ERROR: missing mass element in physical attributes in " - << GetXMLPath(element) << "name " << name << " \n"; return false; } ! if (! ReadAttribute(massElem, RA_VALUE, physical.mass)) ! { ! return false; ! } // check for mass center TiXmlElement* centerElem = GetFirstChild(physElem,RosElements::RE_CENTEROFMASS); ! if (centerElem != 0) { ! ReadVector(centerElem, physical.massCenter); } --- 694,721 ---- if (physElem == 0) { ! return true; } ! // check for mass TiXmlElement* massElem = GetFirstChild(physElem, RosElements::RE_MASS); ! if ( ! (massElem != 0) && ! (! ReadAttribute(massElem, RA_VALUE, physical.mass)) ! ) { return false; } ! // a mass value is enough for a valid physical body description ! physical.valid = true; // check for mass center TiXmlElement* centerElem = GetFirstChild(physElem,RosElements::RE_CENTEROFMASS); ! if ( ! (centerElem != 0) && ! (! ReadVector(centerElem, physical.massCenter)) ! ) { ! return false; } *************** *** 761,782 **** ccylinder->SetMaterial(appear.ref); ! // add body? ! switch (context) { ! case NC_ELEMENTS: ! break; ! ! case NC_MOVABLE: ! { ! shared_ptr<Body> body = shared_dynamic_cast<Body> ! (GetCore()->New("/oxygen/Body")); ! transform->AddChildReference(body); ! body->SetName(S_BODY+name); ! body->SetCappedCylinderTotal(physical.mass, radius, height); ! //! TODO: set mass center ! break; ! } } --- 765,778 ---- ccylinder->SetMaterial(appear.ref); ! if (HasBody(physical, context)) { ! shared_ptr<Body> body = shared_dynamic_cast<Body> ! (GetCore()->New("/oxygen/Body")); ! transform->AddChildReference(body); ! body->SetName(S_BODY+name); ! body->SetCappedCylinderTotal(physical.mass, radius, height); ! //! TODO: set mass center } *************** *** 831,852 **** sphere->SetMaterial(appear.ref); ! // add body? ! switch (context) { ! case NC_ELEMENTS: ! break; ! ! case NC_MOVABLE: ! { ! shared_ptr<Body> body = shared_dynamic_cast<Body> ! (GetCore()->New("/oxygen/Body")); ! transform->AddChildReference(body); ! body->SetName(S_BODY+name); ! body->SetSphereTotal(physical.mass, radius); ! //! TODO: set mass center ! break; ! } } --- 827,840 ---- sphere->SetMaterial(appear.ref); ! if (HasBody(physical, context)) { ! shared_ptr<Body> body = shared_dynamic_cast<Body> ! (GetCore()->New("/oxygen/Body")); ! transform->AddChildReference(body); ! body->SetName(S_BODY+name); ! body->SetSphereTotal(physical.mass, radius); ! //! TODO: set mass center } *************** *** 904,925 **** box->SetMaterial(appear.ref); ! // add body? ! switch (context) { ! case NC_ELEMENTS: ! break; ! ! case NC_MOVABLE: ! { ! shared_ptr<Body> body = shared_dynamic_cast<Body> ! (GetCore()->New("/oxygen/Body")); ! transform->AddChildReference(body); ! body->SetName(S_BODY+name); ! body->SetBoxTotal(physical.mass, boxDim); ! //! TODO: set mass center ! break; ! } } --- 892,905 ---- box->SetMaterial(appear.ref); ! if (HasBody(physical, context)) { ! shared_ptr<Body> body = shared_dynamic_cast<Body> ! (GetCore()->New("/oxygen/Body")); ! transform->AddChildReference(body); ! body->SetName(S_BODY+name); ! body->SetBoxTotal(physical.mass, boxDim); ! //! TODO: set mass center } *************** *** 968,972 **** shared_ptr<Body> RosImporter::GetJointParentBody(shared_ptr<BaseNode> parent) { ! return parent->FindChildSupportingClass<Body>(); } --- 948,965 ---- shared_ptr<Body> RosImporter::GetJointParentBody(shared_ptr<BaseNode> parent) { ! for ( ! shared_ptr<BaseNode> node = parent; ! node.get() != 0; ! node = shared_dynamic_cast<BaseNode>(node->GetParent().lock()) ! ) ! { ! shared_ptr<Body> body = node->FindChildSupportingClass<Body>(); ! if (body.get() != 0) ! { ! return body; ! } ! } ! ! return shared_ptr<Body>(); } Index: rosimporter.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/plugin/rosimporter/rosimporter.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** rosimporter.h 19 Feb 2006 14:16:58 -0000 1.5 --- rosimporter.h 19 Feb 2006 15:04:01 -0000 1.6 *************** *** 78,81 **** --- 78,82 ---- { public: + bool valid; double mass; salt::Vector3f massCenter; *************** *** 83,87 **** public: Physical() ! : mass(0.0), massCenter(0.0, 0.0, 0.0) {} }; --- 84,88 ---- public: Physical() ! : valid(false), mass(0.0), massCenter(0.0, 0.0, 0.0) {} }; *************** *** 119,123 **** --- 120,126 ---- TiXmlElement* GetFirstChild(TiXmlNode* node, RosElements::ERosElement type); TiXmlElement* IterateChildren(TiXmlNode* node, RosElements::ERosElement type); + bool IgnoreNode(const TiXmlNode* node) const; + bool HasBody(const Physical& physical, ENodeContext context); RosElements::ERosElement GetType(const TiXmlElement* element) const; |