[Opal-commits] opal/src Blueprint.cpp,1.14,1.15 Blueprint.h,1.22,1.23 BlueprintManager.cpp,1.26,1.27
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-02-25 16:43:31
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28785/src Modified Files: Blueprint.cpp Blueprint.h BlueprintManager.cpp BlueprintManager.h Simulator.cpp Log Message: fixed Blueprint add functions to take pointers instead of const references; this is necessary because we need to add inherited object types to the Blueprint Index: Blueprint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Blueprint.cpp 25 Feb 2005 06:40:26 -0000 1.14 --- Blueprint.cpp 25 Feb 2005 16:43:19 -0000 1.15 *************** *** 30,33 **** --- 30,38 ---- #include "JointData.h" #include "MotorData.h" + #include "AttractorMotorData.h" + #include "GearedMotorData.h" + #include "ServoMotorData.h" + #include "SpringMotorData.h" + #include "ThrusterMotorData.h" #include "SensorData.h" *************** *** 65,128 **** } ! void Blueprint::addSolid(const SolidData& data) { ! if (solidExists(data.name)) { Logger::stream("warning") << "opal::Blueprint::addSolid: Solid " ! << data.name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! SolidData* newData = new SolidData(data); mSolidList.push_back(newData); } } ! void Blueprint::addJoint(const JointData& data) { ! if (jointExists(data.name)) { Logger::stream("warning") << "opal::Blueprint::addJoint: Joint " ! << data.name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! JointData* newData = new JointData(data); mJointList.push_back(newData); } } ! void Blueprint::addMotor(const MotorData& data) { ! if (motorExists(data.name)) { Logger::stream("warning") << "opal::Blueprint::addMotor: Motor " ! << data.name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! MotorData* newData = new MotorData(data); mMotorList.push_back(newData); } } ! void Blueprint::addSensor(const SensorData& data) { ! if (sensorExists(data.name)) { Logger::stream("warning") << "opal::Blueprint::addSensor: Sensor " ! << data.name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! SensorData* newData = new SensorData(data); ! mSensorList.push_back(newData); } } bool Blueprint::solidExists(const std::string& name) { --- 70,214 ---- } ! void Blueprint::addSolid(SolidData* data) { ! if (solidExists(data->name)) { Logger::stream("warning") << "opal::Blueprint::addSolid: Solid " ! << data->name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! SolidData* newData = new SolidData(*data); mSolidList.push_back(newData); } } ! void Blueprint::addJoint(JointData* data) { ! if (jointExists(data->name)) { Logger::stream("warning") << "opal::Blueprint::addJoint: Joint " ! << data->name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! JointData* newData = new JointData(*data); mJointList.push_back(newData); } } ! void Blueprint::addMotor(MotorData* data) { ! if (motorExists(data->name)) { Logger::stream("warning") << "opal::Blueprint::addMotor: Motor " ! << data->name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! MotorData* newData = NULL; ! ! // Allocate the right type of Motor. ! switch(data->getType()) ! { ! case ATTRACTOR_MOTOR: ! newData = ! new AttractorMotorData(*((AttractorMotorData*)data)); ! break; ! case GEARED_MOTOR: ! newData = ! new GearedMotorData(*((GearedMotorData*)data)); ! break; ! case SERVO_MOTOR: ! newData = ! new ServoMotorData(*((ServoMotorData*)data)); ! break; ! case SPRING_MOTOR: ! newData = ! new SpringMotorData(*((SpringMotorData*)data)); ! break; ! case THRUSTER_MOTOR: ! newData = ! new ThrusterMotorData(*((ThrusterMotorData*)data)); ! break; ! default: ! assert(false); ! } ! mMotorList.push_back(newData); } } ! void Blueprint::addSensor(SensorData* data) { ! if (sensorExists(data->name)) { Logger::stream("warning") << "opal::Blueprint::addSensor: Sensor " ! << data->name << " already exists in this Blueprint. \ Ignoring the new one." << std::endl; } else { ! // TODO: implement this when we have some Sensors available. ! //SensorData* newData = NULL; ! ! //// Allocate the right type of Sensor. ! //switch(data->getType()) ! //{ ! // case VELOCITY_SENSOR: ! // newData = ! // new VelocitySensorData(*((VelocitySensorData*)data)); ! // break; ! // default: ! // assert(false); ! //} ! ! //mSensorList.push_back(newData); } } + int Blueprint::getNumSolids()const + { + return (int)(mSolidList.size()); + } + + int Blueprint::getNumJoints()const + { + return (int)(mJointList.size()); + } + + int Blueprint::getNumMotors()const + { + return (int)(mMotorList.size()); + } + + int Blueprint::getNumSensors()const + { + return (int)(mSensorList.size()); + } + + SolidData* Blueprint::getSolidData(unsigned int i)const + { + return mSolidList.at(i); + } + + JointData* Blueprint::getJointData(unsigned int i)const + { + return mJointList.at(i); + } + + MotorData* Blueprint::getMotorData(unsigned int i)const + { + return mMotorList.at(i); + } + + SensorData* Blueprint::getSensorData(unsigned int i)const + { + return mSensorList.at(i); + } + bool Blueprint::solidExists(const std::string& name) { Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Simulator.cpp 25 Feb 2005 06:40:26 -0000 1.36 --- Simulator.cpp 25 Feb 2005 16:43:20 -0000 1.37 *************** *** 237,414 **** BlueprintInstance& instance, const Blueprint& bp) { ! // NamedObjectCollection coll; - // // create all solids in the blueprint; add name and pointer to - // // collection - // std::map<std::string, SolidDescription> solidMap = bp.getSolidMap(); - // std::map<std::string, SolidDescription>::iterator solidIter; - // for (solidIter = solidMap.begin(); solidIter != solidMap.end(); - // ++solidIter) - // { - // // Just use the default parent space for now; if it should be - // // in a different space, it will get handled later this - // // function. - // SolidData newSolid; ! // newSolid.solidPtr = createSolid(); ! // newSolid.solidPtr->setTransform((*solidIter).second.transform); ! // newSolid.solidPtr->setStatic((*solidIter).second.isStatic); ! // newSolid.solidPtr->setLinearDamping( ! // (*solidIter).second.linearDamping); ! // newSolid.solidPtr->setAngularDamping( ! // (*solidIter).second.angularDamping); ! // // add user properties to this solid ! // for (unsigned int i=0; ! // i<(*solidIter).second.userProperties.size(); ++i) ! // { ! // newSolid.userProperties[ ! // (*solidIter).second.userProperties[i].name] = ! // (*solidIter).second.userProperties[i].value; ! // } ! // // add shapes to this solid ! // std::vector<ShapeDescription>::iterator shapeIter; ! // for (shapeIter = (*solidIter).second.shapeList.begin(); ! // shapeIter != (*solidIter).second.shapeList.end(); ++shapeIter) ! // { ! // real* dim = (*shapeIter).dimensions; ! // switch((*shapeIter).type) ! // { ! // case BOX_SHAPE: ! // newSolid.solidPtr->addBox(Vec3r(dim[0], dim[1], ! // dim[2]), (*shapeIter).offset, (*shapeIter).material); ! // break; ! // case SPHERE_SHAPE: ! // newSolid.solidPtr->addSphere(dim[0], ! // (*shapeIter).offset, (*shapeIter).material); ! // break; ! // case CAPSULE_SHAPE: ! // newSolid.solidPtr->addCapsule(dim[0], dim[1], ! // (*shapeIter).offset, (*shapeIter).material); ! // break; ! // case PLANE_SHAPE: ! // { ! // //Point3r p(dim[0], dim[1], dim[2]); ! // //Vec3r normal(dim[3], dim[4], dim[5]); ! // //newSolid.solidPtr->addPlane(p, normal, (*shapeIter).material); ! // newSolid.solidPtr->addPlane(dim, ! // (*shapeIter).material); ! // break; ! // } ! // case RAY_SHAPE: ! // newSolid.solidPtr->addRay(Point3r(dim[0], dim[1], ! // dim[2]), Vec3r(dim[3], dim[4], dim[5]), ! // dim[6], (*shapeIter).offset, ! // (*shapeIter).material); ! // break; ! // // TODO: add MESH_SHAPE type ! // default: ! // assert(false); ! // } ! // } ! // ! // coll.solidMap[(*solidIter).second.name] = newSolid; ! // } ! // // create all joints in the blueprint; add name and pointer to ! // // collection ! // std::map<std::string, JointData> jointMap = bp.getJointMap(); ! // std::map<std::string, JointData>::iterator jointIter; ! // for (jointIter = jointMap.begin(); jointIter != jointMap.end(); ! // ++jointIter) ! // { ! // Solid* solid0 = coll.getSolid( ! // (*jointIter).second.solid0Name).solidPtr; ! // Solid* solid1 = coll.getSolid( ! // (*jointIter).second.solid1Name).solidPtr; ! // // if joint refers to non-existant solids, don't create the joint ! // if (NULL == solid0 || NULL == solid1) ! // { ! // std::cout << "Error in opal::Simulator::instantiateBlueprint: \ ! // Joint " << (*jointIter).second.name << " refers \ ! // to a nonexistant Solid" << std::endl; ! // } ! // else ! // { ! // Joint* newJoint = NULL; ! // Point3r anchor = (*jointIter).second.anchor; ! // Vec3r axis0 = (*jointIter).second.axis0; ! // Vec3r axis1 = (*jointIter).second.axis1; ! // Vec3r axis2 = (*jointIter).second.axis2; ! // // TODO: finish this... ! // switch((*jointIter).second.type) ! // { ! // case HINGE_JOINT: ! // newJoint = createJoint(); ! // newJoint->init(HINGE_JOINT, solid0, solid1, anchor, ! // axis0); ! // break; ! // case UNIVERSAL_JOINT: ! // break; ! // case BALL_JOINT: ! // break; ! // case SLIDER_JOINT: ! // break; ! // case HINGE_2_JOINT: ! // break; ! // case FIXED_JOINT: ! // break; ! // default: ! // assert(false); ! // } ! // if ((*jointIter).second.axis0LimitsEnabled) ! // { ! // newJoint->setLimits(0, (*jointIter).second.lowLimit0, ! // (*jointIter).second.lowLimit0); ! // if ((*jointIter).second.axis1LimitsEnabled) ! // { ! // newJoint->setLimits(1, (*jointIter).second.lowLimit1, ! // (*jointIter).second.lowLimit1); ! // if ((*jointIter).second.axis2LimitsEnabled) ! // { ! // newJoint->setLimits(2, (*jointIter).second.lowLimit2, ! // (*jointIter).second.lowLimit2); ! // } ! // } ! // } ! // //newJoint->setDampingConstant((*jointIter).second.kd); ! // //newJoint->setSpringConstant((*jointIter).second.ks); ! // newJoint->setBreakParams((*jointIter).second.breakMode, ! // (*jointIter).second.breakThresh, ! // (*jointIter).second.accumThresh); ! // coll.jointMap[(*jointIter).second.name] = newJoint; ! // } ! // } ! // // create spaces and add solids to them ! // std::vector<SpaceDescription> spaceList = bp.getSpaceList(); ! // std::vector<SpaceDescription>::iterator spaceIter; ! // for (spaceIter = spaceList.begin(); spaceIter != spaceList.end(); ! // ++spaceIter) ! // { ! // Space* newSpace = createSpace(); ! // // for each space, loop over its list of solids ! // std::vector<std::string>::iterator nameIter; ! // for (nameIter = (*spaceIter).solidNameList.begin(); ! // nameIter != (*spaceIter).solidNameList.end(); ++nameIter) ! // { ! // Solid* solid = coll.getSolid(*nameIter).solidPtr; ! // solid->setSpace(newSpace); ! // } ! // } ! // return coll; } --- 237,418 ---- BlueprintInstance& instance, const Blueprint& bp) { ! // Create all solids in the Blueprint. If names exist, add the ! // names and poitners to the BlueprintInstance. ! for (int i=0; i<bp.getNumSolids(); ++i) ! { ! ! } ! //std::map<std::string, SolidDescription> solidMap = bp.getSolidMap(); ! //std::map<std::string, SolidDescription>::iterator solidIter; ! //for (solidIter = solidMap.begin(); solidIter != solidMap.end(); ! // ++solidIter) ! //{ ! // // Just use the default parent space for now; if it should be ! // // in a different space, it will get handled later this ! // // function. ! // SolidData newSolid; ! // newSolid.solidPtr = createSolid(); ! // newSolid.solidPtr->setTransform((*solidIter).second.transform); ! // newSolid.solidPtr->setStatic((*solidIter).second.isStatic); ! // newSolid.solidPtr->setLinearDamping( ! // (*solidIter).second.linearDamping); ! // newSolid.solidPtr->setAngularDamping( ! // (*solidIter).second.angularDamping); ! // // add user properties to this solid ! // for (unsigned int i=0; ! // i<(*solidIter).second.userProperties.size(); ++i) ! // { ! // newSolid.userProperties[ ! // (*solidIter).second.userProperties[i].name] = ! // (*solidIter).second.userProperties[i].value; ! // } ! // // add shapes to this solid ! // std::vector<ShapeDescription>::iterator shapeIter; ! // for (shapeIter = (*solidIter).second.shapeList.begin(); ! // shapeIter != (*solidIter).second.shapeList.end(); ++shapeIter) ! // { ! // real* dim = (*shapeIter).dimensions; ! // switch((*shapeIter).type) ! // { ! // case BOX_SHAPE: ! // newSolid.solidPtr->addBox(Vec3r(dim[0], dim[1], ! // dim[2]), (*shapeIter).offset, (*shapeIter).material); ! // break; ! // case SPHERE_SHAPE: ! // newSolid.solidPtr->addSphere(dim[0], ! // (*shapeIter).offset, (*shapeIter).material); ! // break; ! // case CAPSULE_SHAPE: ! // newSolid.solidPtr->addCapsule(dim[0], dim[1], ! // (*shapeIter).offset, (*shapeIter).material); ! // break; ! // case PLANE_SHAPE: ! // { ! // //Point3r p(dim[0], dim[1], dim[2]); ! // //Vec3r normal(dim[3], dim[4], dim[5]); ! // //newSolid.solidPtr->addPlane(p, normal, (*shapeIter).material); ! // newSolid.solidPtr->addPlane(dim, ! // (*shapeIter).material); ! // break; ! // } ! // case RAY_SHAPE: ! // newSolid.solidPtr->addRay(Point3r(dim[0], dim[1], ! // dim[2]), Vec3r(dim[3], dim[4], dim[5]), ! // dim[6], (*shapeIter).offset, ! // (*shapeIter).material); ! // break; ! // // TODO: add MESH_SHAPE type ! // default: ! // assert(false); ! // } ! // } ! // ! // coll.solidMap[(*solidIter).second.name] = newSolid; ! //} ! //// create all joints in the blueprint; add name and pointer to ! //// collection ! //std::map<std::string, JointData> jointMap = bp.getJointMap(); ! //std::map<std::string, JointData>::iterator jointIter; ! //for (jointIter = jointMap.begin(); jointIter != jointMap.end(); ! // ++jointIter) ! //{ ! // Solid* solid0 = coll.getSolid( ! // (*jointIter).second.solid0Name).solidPtr; ! // Solid* solid1 = coll.getSolid( ! // (*jointIter).second.solid1Name).solidPtr; ! // // if joint refers to non-existant solids, don't create the joint ! // if (NULL == solid0 || NULL == solid1) ! // { ! // std::cout << "Error in opal::Simulator::instantiateBlueprint: \ ! // Joint " << (*jointIter).second.name << " refers \ ! // to a nonexistant Solid" << std::endl; ! // } ! // else ! // { ! // Joint* newJoint = NULL; ! // Point3r anchor = (*jointIter).second.anchor; ! // Vec3r axis0 = (*jointIter).second.axis0; ! // Vec3r axis1 = (*jointIter).second.axis1; ! // Vec3r axis2 = (*jointIter).second.axis2; ! // // TODO: finish this... ! // switch((*jointIter).second.type) ! // { ! // case HINGE_JOINT: ! // newJoint = createJoint(); ! // newJoint->init(HINGE_JOINT, solid0, solid1, anchor, ! // axis0); ! // break; ! // case UNIVERSAL_JOINT: ! // break; ! // case BALL_JOINT: ! // break; ! // case SLIDER_JOINT: ! // break; ! // case HINGE_2_JOINT: ! // break; ! // case FIXED_JOINT: ! // break; ! // default: ! // assert(false); ! // } ! // if ((*jointIter).second.axis0LimitsEnabled) ! // { ! // newJoint->setLimits(0, (*jointIter).second.lowLimit0, ! // (*jointIter).second.lowLimit0); ! // if ((*jointIter).second.axis1LimitsEnabled) ! // { ! // newJoint->setLimits(1, (*jointIter).second.lowLimit1, ! // (*jointIter).second.lowLimit1); ! // if ((*jointIter).second.axis2LimitsEnabled) ! // { ! // newJoint->setLimits(2, (*jointIter).second.lowLimit2, ! // (*jointIter).second.lowLimit2); ! // } ! // } ! // } ! // //newJoint->setDampingConstant((*jointIter).second.kd); ! // //newJoint->setSpringConstant((*jointIter).second.ks); ! // newJoint->setBreakParams((*jointIter).second.breakMode, ! // (*jointIter).second.breakThresh, ! // (*jointIter).second.accumThresh); ! // coll.jointMap[(*jointIter).second.name] = newJoint; ! // } ! //} ! //// create spaces and add solids to them ! //std::vector<SpaceDescription> spaceList = bp.getSpaceList(); ! //std::vector<SpaceDescription>::iterator spaceIter; ! //for (spaceIter = spaceList.begin(); spaceIter != spaceList.end(); ! // ++spaceIter) ! //{ ! // Space* newSpace = createSpace(); ! // // for each space, loop over its list of solids ! // std::vector<std::string>::iterator nameIter; ! // for (nameIter = (*spaceIter).solidNameList.begin(); ! // nameIter != (*spaceIter).solidNameList.end(); ++nameIter) ! // { ! // Solid* solid = coll.getSolid(*nameIter).solidPtr; ! // solid->setSpace(newSpace); ! // } ! //} ! ! //return coll; } Index: BlueprintManager.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** BlueprintManager.cpp 25 Feb 2005 06:40:26 -0000 1.26 --- BlueprintManager.cpp 25 Feb 2005 16:43:19 -0000 1.27 *************** *** 91,95 **** if (data) { ! bp.addSolid(*data); } } --- 91,98 ---- if (data) { ! // This function makes a deep copy, so we need to destroy ! // the data. ! bp.addSolid(data); ! delete data; } } *************** *** 103,107 **** if (data) { ! bp.addJoint(*data); } } --- 106,113 ---- if (data) { ! // This function makes a deep copy, so we need to destroy ! // the data. ! bp.addJoint(data); ! delete data; } } *************** *** 115,119 **** if (data) { ! bp.addMotor(*data); } } --- 121,128 ---- if (data) { ! // This function makes a deep copy, so we need to destroy ! // the data. ! bp.addMotor(data); ! delete data; } } *************** *** 127,131 **** if (data) { ! bp.addSensor(*data); } } --- 136,143 ---- if (data) { ! // This function makes a deep copy, so we need to destroy ! // the data. ! bp.addSensor(data); ! delete data; } } Index: Blueprint.h =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.h,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Blueprint.h 25 Feb 2005 06:40:26 -0000 1.22 --- Blueprint.h 25 Feb 2005 16:43:19 -0000 1.23 *************** *** 41,45 **** /// Blueprints are useful for saving and loading systems of Solids, ! /// Joints, Motors, and/or Sensors. They are not guaranteed to yield /// perfect repeatability after a save/restore sequence. class Blueprint --- 41,47 ---- /// Blueprints are useful for saving and loading systems of Solids, ! /// Joints, Motors, and/or Sensors. They are created by OPAL when ! /// an OPAL XML file is loaded. They can also be created by users ! /// and saved to an OPAL XML file. They are not guaranteed to yield /// perfect repeatability after a save/restore sequence. class Blueprint *************** *** 52,68 **** /// Adds a new SolidData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addSolid(const SolidData& data); /// Adds a new JointData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addJoint(const JointData& data); /// Adds a new MotorData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addMotor(const MotorData& data); /// Adds a new SensorData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addSensor(const SensorData& data); /// Returns the index of the given Solid name in the Blueprint's --- 54,94 ---- /// Adds a new SolidData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addSolid(SolidData* data); /// Adds a new JointData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addJoint(JointData* data); /// Adds a new MotorData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addMotor(MotorData* data); /// Adds a new SensorData object to the Blueprint. Makes a /// deep copy of the given data. ! virtual void OPAL_CALL addSensor(SensorData* data); ! ! /// Returns the number of SolidData objects. ! virtual int OPAL_CALL getNumSolids()const; ! ! /// Returns the number of JointData objects. ! virtual int OPAL_CALL getNumJoints()const; ! ! /// Returns the number of MotorData objects. ! virtual int OPAL_CALL getNumMotors()const; ! ! /// Returns the number of SensorData objects. ! virtual int OPAL_CALL getNumSensors()const; ! ! /// Returns a pointer to the SolidData at the given index. ! virtual SolidData* OPAL_CALL getSolidData(unsigned int i)const; ! ! /// Returns a pointer to the JointData at the given index. ! virtual JointData* OPAL_CALL getJointData(unsigned int i)const; ! ! /// Returns a pointer to the MotorData at the given index. ! virtual MotorData* OPAL_CALL getMotorData(unsigned int i)const; ! ! /// Returns a pointer to the SensorData at the given index. ! virtual SensorData* OPAL_CALL getSensorData(unsigned int i)const; /// Returns the index of the given Solid name in the Blueprint's Index: BlueprintManager.h =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** BlueprintManager.h 25 Feb 2005 06:40:26 -0000 1.15 --- BlueprintManager.h 25 Feb 2005 16:43:20 -0000 1.16 *************** *** 56,60 **** /// a Joint refers to two Solids; if either of those Solids /// are not in the file, the Joint will be ignored. For a ! /// particular element, all attributes are always required. virtual void OPAL_CALL loadFile(Blueprint& bp, const std::string& filename); --- 56,61 ---- /// a Joint refers to two Solids; if either of those Solids /// are not in the file, the Joint will be ignored. For a ! /// particular element, all attributes are always required. ! /// All object names, if used, must be unique. virtual void OPAL_CALL loadFile(Blueprint& bp, const std::string& filename); |