Skip to content

Commit

Permalink
[JuPedSim] Small refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoueraud87 authored and behrisch committed Feb 19, 2024
1 parent 7a8db85 commit 874b36b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 33 deletions.
20 changes: 1 addition & 19 deletions src/microsim/MSTrainHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,11 @@
#include "MSTrainHelper.h"


const double MSTrainHelper::DEFAULT_CARRIAGE_DOOR_WIDTH = 1.5;
const double MSTrainHelper::CARRIAGE_DOOR_WIDTH = 1.5;

// ===========================================================================
// method definitions
// ===========================================================================
std::vector<PositionVector>
MSTrainHelper::getCarriageShapes(void) const {
std::vector<PositionVector> carriageShapes;
for (const Carriage* carriage: myCarriages) {
Position direction = carriage->front - carriage->back;
direction.norm2D();
Position perp = Position(-direction.y(), direction.x());
PositionVector shape;
shape.push_back(carriage->front + perp*myHalfWidth);
shape.push_back(carriage->back + perp*myHalfWidth);
shape.push_back(carriage->back - perp*myHalfWidth);
shape.push_back(carriage->front - perp*myHalfWidth);
carriageShapes.push_back(shape);
}
return carriageShapes;
}


void
MSTrainHelper::computeTrainDimensions(double exaggeration) {
const MSVehicleType& vtype = myTrain->getVehicleType();
Expand Down
5 changes: 1 addition & 4 deletions src/microsim/MSTrainHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ class MSTrainHelper {
return myCarriages;
}

// Compute the rectangles from the front and back positions.
std::vector<PositionVector> getCarriageShapes(void) const;
static const double CARRIAGE_DOOR_WIDTH;

static const double DEFAULT_CARRIAGE_DOOR_WIDTH;

private:
const MSVehicle* myTrain;
double myUpscaleLength;
Expand Down
21 changes: 13 additions & 8 deletions src/microsim/transportables/MSPModel_JuPedSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const int MSPModel_JuPedSim::GEOS_QUADRANT_SEGMENTS = 16;
const double MSPModel_JuPedSim::GEOS_MITRE_LIMIT = 5.0;
const double MSPModel_JuPedSim::GEOS_MIN_AREA = 0.01;
const double MSPModel_JuPedSim::GEOS_BUFFERED_SEGMENT_WIDTH = 0.5 * SUMO_const_laneWidth;
const double MSPModel_JuPedSim::DEFAULT_RAMP_WIDTH = 2.0;
const double MSPModel_JuPedSim::CARRIAGE_RAMP_WIDTH = 2.0;

// ===========================================================================
// method definitions
Expand Down Expand Up @@ -413,17 +413,22 @@ MSPModel_JuPedSim::execute(SUMOTime time) {
std::vector<GEOSGeometry*> rampPolygons;
for (const MSVehicle* train : allStoppedTrains) {
const MSTrainHelper trainHelper(train);
const std::vector<PositionVector> carriageShapes = trainHelper.getCarriageShapes();
for (const PositionVector& carriageShape : carriageShapes) {
carriagePolygons.push_back(createGeometryFromShape(carriageShape, train->getID(), false));
}
const std::vector<MSTrainHelper::Carriage*> carriages = trainHelper.getCarriages();
for (const MSTrainHelper::Carriage* carriage: carriages) {
Position dir = carriage->front - carriage->back;
dir.norm2D();
const Position perp = Position(-dir.y(), dir.x());
const double p = trainHelper.getHalfWidth() + DEFAULT_RAMP_WIDTH;
const double d = 0.5 * MSTrainHelper::DEFAULT_CARRIAGE_DOOR_WIDTH;
Position perp = Position(-dir.y(), dir.x());
// Create carriages geometry.
double p = trainHelper.getHalfWidth();
PositionVector carriageShape;
carriageShape.push_back(carriage->front + perp*p);
carriageShape.push_back(carriage->back + perp*p);
carriageShape.push_back(carriage->back - perp*p);
carriageShape.push_back(carriage->front - perp*p);
carriagePolygons.push_back(createGeometryFromShape(carriageShape, train->getID(), false));
// Create ramps geometry.
p += CARRIAGE_RAMP_WIDTH;
const double d = 0.5 * MSTrainHelper::CARRIAGE_DOOR_WIDTH;
const std::vector<Position>& doors = carriage->doors;
for (const Position door : doors) {
PositionVector rampShape;
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSPModel_JuPedSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class MSPModel_JuPedSim : public MSPModel {
static const double GEOS_MITRE_LIMIT;
static const double GEOS_MIN_AREA;
static const double GEOS_BUFFERED_SEGMENT_WIDTH;
static const double DEFAULT_RAMP_WIDTH;
static const double CARRIAGE_RAMP_WIDTH;

void initialize(const OptionsCont& oc);
void tryPedestrianInsertion(PState* state, const Position& p);
Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSStageDriving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ MSStageDriving::setArrived(MSNet* net, MSTransportable* transportable, SUMOTime
// Jitter the position before projection because of possible train curvature.
Position direction = randomCarriage->front - randomCarriage->back;
direction.norm2D();
randomDoor.add(direction * RandHelper::rand(-0.5 * MSTrainHelper::DEFAULT_CARRIAGE_DOOR_WIDTH, 0.5 * MSTrainHelper::DEFAULT_CARRIAGE_DOOR_WIDTH));
randomDoor.add(direction * RandHelper::rand(-0.5 * MSTrainHelper::CARRIAGE_DOOR_WIDTH, 0.5 * MSTrainHelper::CARRIAGE_DOOR_WIDTH));
// Project onto the lane.
myArrivalPos = myVehicle->getLane()->getShape().nearest_offset_to_point2D(randomDoor);
myArrivalPos = myVehicle->getLane()->interpolateGeometryPosToLanePos(myArrivalPos);
Expand Down

0 comments on commit 874b36b

Please sign in to comment.