[Opal-commits] opal/src Blueprint.cpp,1.17,1.18 BlueprintManager.cpp,1.31,1.32 BlueprintManager.h,1.
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-03-13 23:08:13
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24830/src Modified Files: Blueprint.cpp BlueprintManager.cpp BlueprintManager.h RaycastSensor.cpp RaycastSensorData.h SensorData.h Simulator.cpp Simulator.h VolumeSensor.cpp VolumeSensorData.h Log Message: added xml parsing for raycast and volume sensors Index: Blueprint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Blueprint.cpp 28 Feb 2005 03:27:54 -0000 1.17 --- Blueprint.cpp 13 Mar 2005 23:07:09 -0000 1.18 *************** *** 36,39 **** --- 36,41 ---- #include "ThrusterMotorData.h" #include "SensorData.h" + #include "RaycastSensorData.h" + #include "VolumeSensorData.h" namespace opal *************** *** 210,214 **** } ! // TODO: once we have Sensors, loop over them here. mFinalized = true; --- 212,230 ---- } ! // Setup Sensor reference indices. ! for (i=0; i<mSensorList.size(); ++i) ! { ! SensorData* data = mSensorList.at(i); ! ! // At this time we have no Sensors with special references ! // besides the standard Solid reference present in every ! // Sensor. Thus we can just treat them all the same. ! ! // Find the index of the Solid reference. If the value of ! // the index is -1, the Sensor must not be attached to any ! // Solid. ! int solidIndex = getSolidIndex(data->internal_solidName); ! data->internal_solidIndex = solidIndex; ! } mFinalized = true; *************** *** 327,345 **** 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); } } --- 343,380 ---- else { ! SensorData* newData = NULL; ! // Allocate the right type of Sensor. ! switch(data->getType()) ! { ! //case ACCELERATION_SENSOR: ! //{ ! // newData = ! // new AccelerationSensorData( ! // *((AccelerationSensorData*)data)); ! // break; ! //} ! case RAYCAST_SENSOR: ! { ! newData = ! new RaycastSensorData(*((RaycastSensorData*)data)); ! break; ! } ! //case VELOCITY_SENSOR: ! //{ ! // newData = ! // new VelocitySensorData(*((VelocitySensorData*)data)); ! //} ! case VOLUME_SENSOR: ! { ! newData = ! new VolumeSensorData(*((VolumeSensorData*)data)); ! break; ! } ! default: ! assert(false); ! } ! mSensorList.push_back(newData); } } Index: RaycastSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensor.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RaycastSensor.cpp 12 Mar 2005 01:21:16 -0000 1.4 --- RaycastSensor.cpp 13 Mar 2005 23:07:10 -0000 1.5 *************** *** 60,64 **** { // TODO: if mData.solid is valid, update this Sensor's ray ! // relative to the Solid // TODO: if this is attached to a Solid, keep the ray from --- 60,65 ---- { // TODO: if mData.solid is valid, update this Sensor's ray ! // relative to the Solid; otherwise, update it relative to ! // global origin. // TODO: if this is attached to a Solid, keep the ray from Index: SensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/SensorData.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SensorData.h 12 Mar 2005 01:21:16 -0000 1.6 --- SensorData.h 13 Mar 2005 23:07:10 -0000 1.7 *************** *** 54,57 **** --- 54,59 ---- name = ""; solid = NULL; + internal_solidIndex = 0; + internal_solidName = ""; // "transform" is initialized in its own constructor. } *************** *** 75,81 **** /// Pointer to the Solid to which this Sensor is attached. This /// will be NULL if the Sensor is not attached to a Solid (i.e. ! /// it is positioned somewhere within the environment). Solid* solid; /// If the Sensor is attached to a Solid, this matrix is the global /// offset from that Solid's transform. Otherwise, it is just the --- 77,89 ---- /// Pointer to the Solid to which this Sensor is attached. This /// will be NULL if the Sensor is not attached to a Solid (i.e. ! /// it is just positioned somewhere within the environment). Solid* solid; + /// Internal data used for Blueprint instantiation. + int internal_solidIndex; + + /// Internal data used for Blueprint instantiation. + std::string internal_solidName; + /// If the Sensor is attached to a Solid, this matrix is the global /// offset from that Solid's transform. Otherwise, it is just the Index: VolumeSensor.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/VolumeSensor.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VolumeSensor.cpp 12 Mar 2005 01:21:17 -0000 1.1 --- VolumeSensor.cpp 13 Mar 2005 23:07:11 -0000 1.2 *************** *** 55,59 **** { // TODO: if mData.solid is valid, update this Sensor's transform ! // relative to the Solid // TODO: if this is attached to a Solid, don't add the volume Solid --- 55,60 ---- { // TODO: if mData.solid is valid, update this Sensor's transform ! // relative to the Solid; otherwise, update it relative to ! // global origin. // TODO: if this is attached to a Solid, don't add the volume Solid Index: BlueprintManager.h =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** BlueprintManager.h 26 Feb 2005 10:22:23 -0000 1.17 --- BlueprintManager.h 13 Mar 2005 23:07:10 -0000 1.18 *************** *** 42,45 **** --- 42,47 ---- class SpringMotorData; class ThrusterMotorData; + class RaycastSensorData; + class VolumeSensorData; namespace blueprint_manager *************** *** 56,66 **** /// will be ignored). The Blueprint can contain any number /// of Solids, Joints, Motors, and Sensors. Most of the ! /// object parameters are optional, in which case the usual, /// default values will be used. The only required /// parameters are object types and references to other objects ! /// (i.e. the "References" elements in an XML file. For example, ! /// 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, --- 58,71 ---- /// will be ignored). The Blueprint can contain any number /// of Solids, Joints, Motors, and Sensors. Most of the ! /// object parameters are optional, in which case the usual /// default values will be used. The only required /// parameters are object types and references to other objects ! /// (i.e. the "References" elements in an XML file). For ! /// example, a Joint refers to two Solids; if either of those ! /// Solids are not in the file, the Joint will be ignored. The ! /// exception is Sensors' references to Solids; these aren't ! /// required because Sensors don't have to be attached to a ! /// Solid. For a particular element that does exist in the ! /// XML file, all attributes are always required. /// All object names, if used, must be unique. virtual void OPAL_CALL loadFile(Blueprint& bp, *************** *** 126,129 **** --- 131,146 ---- const Blueprint& bp, const std::string& filename); + /// Helper function for parsing RaycastSensor XML elements. + /// Allocates and returns a pointer to a new RaycastSensorData + /// object. Returns NULL if the element could not be loaded. + RaycastSensorData* loadRaycastSensor(const TiXmlNode* nodePtr, + const Blueprint& bp, const std::string& filename); + + /// Helper function for parsing VolumeSensor XML elements. + /// Allocates and returns a pointer to a new VolumeSensorData + /// object. Returns NULL if the element could not be loaded. + VolumeSensorData* loadVolumeSensor(const TiXmlNode* nodePtr, + const Blueprint& bp, const std::string& filename); + /// Helper function for parsing Shape XML elements. Allocates /// and returns a pointer to a new ShapeData object. Returns Index: RaycastSensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/RaycastSensorData.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RaycastSensorData.h 11 Mar 2005 05:31:56 -0000 1.2 --- RaycastSensorData.h 13 Mar 2005 23:07:10 -0000 1.3 *************** *** 63,66 **** --- 63,68 ---- name = data.name; solid = data.solid; + internal_solidIndex = data.internal_solidIndex; + internal_solidName = data.internal_solidName; transform = data.transform; ray = data.ray; Index: BlueprintManager.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** BlueprintManager.cpp 8 Mar 2005 22:05:02 -0000 1.31 --- BlueprintManager.cpp 13 Mar 2005 23:07:09 -0000 1.32 *************** *** 38,41 **** --- 38,43 ---- #include "SpringMotorData.h" #include "SensorData.h" + #include "RaycastSensorData.h" + #include "VolumeSensorData.h" #ifdef OPAL_USE_XML *************** *** 1199,1216 **** } ! // TODO: implement this once we have some Sensors. ! //// Load data for the specific type of Sensor. ! //if ("velocity" == type) //{ ! // data = loadVelocitySensor(nodePtr, bp, filename); //} ! //else //{ ! // OPAL_LOGGER("warning") << ! // "opal::BlueprintManager::loadSensor: Invalid Sensor \ ! // type " << type << " in " << filename ! // << ". Ignoring the Sensor." << std::endl; ! // return NULL; //} // Load Name element if it exists. --- 1201,1230 ---- } ! // Load data for the specific type of Sensor. ! //if ("acceleration" == type) //{ ! // data = loadAccelerationSensor(nodePtr, bp, filename); //} ! //else if ("raycast" == type) ! if ("raycast" == type) ! { ! data = loadRaycastSensor(nodePtr, bp, filename); ! } ! //else if ("velocity" == type) //{ ! // data = loadVelocitySensor(nodePtr, bp, filename); //} + else if ("volume" == type) + { + data = loadVolumeSensor(nodePtr, bp, filename); + } + else + { + OPAL_LOGGER("warning") << + "opal::BlueprintManager::loadSensor: Invalid Sensor \ + type " << type << " in " << filename + << ". Ignoring the Sensor." << std::endl; + return NULL; + } // Load Name element if it exists. *************** *** 1244,1247 **** --- 1258,1330 ---- } } + + // Load Offset element if it exists. + TiXmlNode* offsetNodePtr = + const_cast<TiXmlNode*>(nodePtr)->FirstChild("Offset"); + if (NULL != offsetNodePtr) + { + loadOffset(data->transform, offsetNodePtr, filename); + } + + // Load References element. If it doesn't exist, just assume + // that this Sensor will not be attached to a Solid. + paramNodePtr = + const_cast<TiXmlNode*>(nodePtr)->FirstChild("References"); + if (NULL != paramNodePtr) + { + // Get the Solids' names. + data->internal_solidName = getAttributeString(paramNodePtr, + "solid"); + } + else + { + data->internal_solidName = ""; + } + #endif + return data; + } + + RaycastSensorData* BlueprintManager::loadRaycastSensor( + const TiXmlNode* nodePtr, const Blueprint& bp, + const std::string& filename) + { + // This data structure automatically gets initialized to + // default values in its constructor. + RaycastSensorData* data = new RaycastSensorData(); + + #ifdef OPAL_USE_XML + + TiXmlNode* paramNodePtr = NULL; + + // Load Ray element if it exists. + paramNodePtr = + const_cast<TiXmlNode*>(nodePtr)->FirstChild("Ray"); + if (NULL != paramNodePtr) + { + Point3r origin; + Vec3r dir; + origin[0] = getAttributeReal(paramNodePtr, "originx"); + origin[1] = getAttributeReal(paramNodePtr, "originy"); + origin[2] = getAttributeReal(paramNodePtr, "originz"); + dir[0] = getAttributeReal(paramNodePtr, "dirx"); + dir[1] = getAttributeReal(paramNodePtr, "diry"); + dir[2] = getAttributeReal(paramNodePtr, "dirz"); + data->ray.setOrigin(origin); + data->ray.setDir(dir); + } + #endif + return data; + } + + VolumeSensorData* BlueprintManager::loadVolumeSensor( + const TiXmlNode* nodePtr, const Blueprint& bp, + const std::string& filename) + { + // This data structure automatically gets initialized to + // default values in its constructor. + VolumeSensorData* data = new VolumeSensorData(); + + #ifdef OPAL_USE_XML + // Nothing special to load for VolumeSensors. #endif return data; Index: VolumeSensorData.h =================================================================== RCS file: /cvsroot/opal/opal/src/VolumeSensorData.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** VolumeSensorData.h 12 Mar 2005 01:21:17 -0000 1.1 --- VolumeSensorData.h 13 Mar 2005 23:07:11 -0000 1.2 *************** *** 62,65 **** --- 62,67 ---- name = data.name; solid = data.solid; + internal_solidIndex = data.internal_solidIndex; + internal_solidName = data.internal_solidName; transform = data.transform; } Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** Simulator.cpp 12 Mar 2005 01:21:16 -0000 1.45 --- Simulator.cpp 13 Mar 2005 23:07:10 -0000 1.46 *************** *** 234,237 **** --- 234,238 ---- void Simulator::setStepSize(real stepSize) { + assert(stepSize > 0); mStepSize = stepSize; } *************** *** 288,291 **** --- 289,295 ---- { Solid* s = createSolid(); + + // Make a local copy of the Solid's data, including all of its + // Shapes. SolidData sd = *bp.getSolidData(i); *************** *** 379,389 **** for (i=0; i<bp.getNumJoints(); ++i) { - // Setup the Solid reference pointers. - JointData* data = bp.getJointData(i); - data->solid0 = solidList.at(data->internal_solid0Index); - data->solid1 = solidList.at(data->internal_solid1Index); - Joint* j = createJoint(); ! JointData jd = *data; if (useOffset) --- 383,394 ---- for (i=0; i<bp.getNumJoints(); ++i) { Joint* j = createJoint(); ! ! // Create a local copy of the Joint's data. ! JointData jd = *bp.getJointData(i); ! ! // Setup the Solid reference pointers. ! jd.solid0 = solidList.at(jd.internal_solid0Index); ! jd.solid1 = solidList.at(jd.internal_solid1Index); if (useOffset) *************** *** 413,480 **** { Motor* m = NULL; ! //MotorData* data = bp.getMotorData(i); switch(bp.getMotorData(i)->getType()) { - case ATTRACTOR_MOTOR: { ! AttractorMotorData* data = ! (AttractorMotorData*)(bp.getMotorData(i)); // Setup the Solid reference pointers. ! data->solid0 = solidList.at(data->internal_solid0Index); ! data->solid1 = solidList.at(data->internal_solid1Index); m = createAttractorMotor(); ! ((AttractorMotor*)m)->init(*data); break; } case GEARED_MOTOR: { ! GearedMotorData* data = ! (GearedMotorData*)(bp.getMotorData(i)); // Setup the Joint reference pointer. ! data->joint = jointList.at(data->internal_jointIndex); m = createGearedMotor(); ! ((GearedMotor*)m)->init(*data); break; } case SERVO_MOTOR: { ! ServoMotorData* data = ! (ServoMotorData*)(bp.getMotorData(i)); // Setup the Joint reference pointer. ! data->joint = jointList.at(data->internal_jointIndex); m = createServoMotor(); ! ((ServoMotor*)m)->init(*data); break; } case SPRING_MOTOR: { ! SpringMotorData* data = ! (SpringMotorData*)(bp.getMotorData(i)); // Setup the Solid reference pointer. ! data->solid = solidList.at(data->internal_solidIndex); m = createSpringMotor(); ! ((SpringMotor*)m)->init(*data); break; } case THRUSTER_MOTOR: { ! ThrusterMotorData* data = ! (ThrusterMotorData*)(bp.getMotorData(i)); // Setup the Solid reference pointer. ! data->solid = solidList.at(data->internal_solidIndex); m = createThrusterMotor(); ! ((ThrusterMotor*)m)->init(*data); break; } --- 418,485 ---- { Motor* m = NULL; ! MotorData* motorData = bp.getMotorData(i); + // Allocate and setup the right type of Motor. switch(bp.getMotorData(i)->getType()) { case ATTRACTOR_MOTOR: { ! // Make a local copy of the Motor's data. ! AttractorMotorData data = *(AttractorMotorData*)motorData; // Setup the Solid reference pointers. ! data.solid0 = solidList.at(data.internal_solid0Index); ! data.solid1 = solidList.at(data.internal_solid1Index); m = createAttractorMotor(); ! ((AttractorMotor*)m)->init(data); break; } case GEARED_MOTOR: { ! // Make a local copy of the Motor's data. ! GearedMotorData data = *(GearedMotorData*)motorData; // Setup the Joint reference pointer. ! data.joint = jointList.at(data.internal_jointIndex); m = createGearedMotor(); ! ((GearedMotor*)m)->init(data); break; } case SERVO_MOTOR: { ! // Make a local copy of the Motor's data. ! ServoMotorData data = *(ServoMotorData*)motorData; // Setup the Joint reference pointer. ! data.joint = jointList.at(data.internal_jointIndex); m = createServoMotor(); ! ((ServoMotor*)m)->init(data); break; } case SPRING_MOTOR: { ! // Make a local copy of the Motor's data. ! SpringMotorData data = *(SpringMotorData*)motorData; // Setup the Solid reference pointer. ! data.solid = solidList.at(data.internal_solidIndex); m = createSpringMotor(); ! ((SpringMotor*)m)->init(data); break; } case THRUSTER_MOTOR: { ! // Make a local copy of the Motor's data. ! ThrusterMotorData data = *(ThrusterMotorData*)motorData; // Setup the Solid reference pointer. ! data.solid = solidList.at(data.internal_solidIndex); m = createThrusterMotor(); ! ((ThrusterMotor*)m)->init(data); break; } *************** *** 487,511 **** } ! // TODO: implement this when we have Sensors. ! //// Create all Sensors in the Blueprint. ! // This is outdated... ! //for (int i=0; i<bp.getNumSensors(); ++i) ! //{ ! // Sensor* s = NULL; ! // SensorData* data = bp.getSensorData(i); ! // switch(bp.getMotorData(i).getType()) ! // { ! // case VELOCITY_SENSOR: ! // m = createVelocitySensor(); ! // ((VelocitySensor*)m)->init(*((VelocitySensorData*)data)); ! // break; ! // default: ! // assert(false); ! // } ! // // Add the Sensor to the BlueprintInstance. ! // instance.internal_addSensor(s); ! //} solidList.clear(); --- 492,587 ---- } ! // Create all Sensors in the Blueprint. ! for (i=0; i<bp.getNumSensors(); ++i) ! { ! Sensor* s = NULL; ! SensorData* sensorData = bp.getSensorData(i); ! // These are necessary because we don't want to change teh ! // Blueprint's Sensor data directly; we need a local copy. ! Solid* solidPtr = NULL; ! Matrix44r transform = sensorData->transform; ! // Setup the Solid reference pointer. ! if (-1 == sensorData->internal_solidIndex) ! { ! // This Sensor must not be attached to any Solid. ! solidPtr = NULL; ! } ! else ! { ! // This Sensor is attached to a Solid. ! solidPtr = solidList.at(sensorData->internal_solidIndex); ! } ! ! if (useOffset) ! { ! // Offset the Sensor's transform. ! transform = offset * transform; ! } ! ! if (useScale) ! { ! // Scale the Solid's transform. ! transform[12] *= scale; ! transform[13] *= scale; ! transform[14] *= scale; ! } ! ! // Allocate the right type of Sensor. ! switch(sensorData->getType()) ! { ! //case ACCELERATION_SENSOR: ! //{ ! // // Make a local copy of the Sensor's data. ! // AccelerationSensorData data = ! // *(AccelerationSensorData*)sensorData; ! // data.solid = solidPtr; ! // data.transform = transform; ! ! // s = createAccelerationSensor(); ! // ((AccelerationSensor*)s)->init(data); ! // break; ! //} ! case RAYCAST_SENSOR: ! { ! // Make a local copy of the Sensor's data. ! RaycastSensorData data = *(RaycastSensorData*)sensorData; ! data.solid = solidPtr; ! data.transform = transform; ! ! s = createRaycastSensor(); ! ((RaycastSensor*)s)->init(data); ! break; ! } ! //case VELOCITY_SENSOR: ! //{ ! // // Make a local copy of the Sensor's data. ! // VelocitySensorData data = *(VelocitySensorData*)sensorData; ! // data.solid = solidPtr; ! // data.transform = transform; ! ! // s = createVelocitySensor(); ! // ((VelocitySensor*)s)->init(data); ! // break; ! //} ! case VOLUME_SENSOR: ! { ! // Make a local copy of the Sensor's data. ! VolumeSensorData data = *(VolumeSensorData*)sensorData; ! data.solid = solidPtr; ! data.transform = transform; ! ! s = createVolumeSensor(); ! ((VolumeSensor*)s)->init(data); ! break; ! } ! default: ! assert(false); ! } ! ! // Add the Sensor to the BlueprintInstance. ! instance.internal_addSensor(s); ! } solidList.clear(); *************** *** 734,737 **** --- 810,820 ---- } + VolumeSensor* Simulator::createVolumeSensor() + { + VolumeSensor* newSensor = new VolumeSensor(this); + addSensor(newSensor); + return newSensor; + } + void Simulator::destroySensor(Sensor* s) { Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** Simulator.h 12 Mar 2005 01:21:17 -0000 1.85 --- Simulator.h 13 Mar 2005 23:07:11 -0000 1.86 *************** *** 45,48 **** --- 45,49 ---- class ThrusterMotor; class RaycastSensor; + class VolumeSensor; class BlueprintInstance; struct RaycastResult; *************** *** 70,74 **** virtual bool OPAL_CALL simulate(real dt); ! /// Sets the constant step size used in the simulation. virtual void OPAL_CALL setStepSize(real stepSize); --- 71,76 ---- virtual bool OPAL_CALL simulate(real dt); ! /// Sets the constant step size used in the simulation. The step ! /// size must be greater than zero. virtual void OPAL_CALL setStepSize(real stepSize); *************** *** 201,204 **** --- 203,209 ---- virtual RaycastSensor* OPAL_CALL createRaycastSensor(); + /// Creates and returns a pointer to a VolumeSensor. + virtual VolumeSensor* OPAL_CALL createVolumeSensor(); + /// Immediately destroys the given Sensor. virtual void OPAL_CALL destroySensor(Sensor* s); |