diff --git a/src/microsim/transportables/MSPModel_JuPedSim.cpp b/src/microsim/transportables/MSPModel_JuPedSim.cpp index 02f96530ceb2..81509daa3d10 100644 --- a/src/microsim/transportables/MSPModel_JuPedSim.cpp +++ b/src/microsim/transportables/MSPModel_JuPedSim.cpp @@ -58,13 +58,15 @@ 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::CARRIAGE_RAMP_WIDTH = 2.0; +const RGBColor MSPModel_JuPedSim::PEDESTRIAN_NETWORK_COLOR = RGBColor(179, 217, 255, 255); // =========================================================================== // method definitions // =========================================================================== MSPModel_JuPedSim::MSPModel_JuPedSim(const OptionsCont& oc, MSNet* net) : myNetwork(net), myJPSDeltaT(string2time(oc.getString("pedestrian.jupedsim.step-length"))), - myExitTolerance(oc.getFloat("pedestrian.jupedsim.exit-tolerance")), myHaveAdditionalWalkableAreas(false) { + myExitTolerance(oc.getFloat("pedestrian.jupedsim.exit-tolerance")), myMaxAreaConnectedComponentPolygon(nullptr), + myHaveAdditionalWalkableAreas(false) { initialize(oc); net->getBeginOfTimestepEvents()->addEvent(new Event(this), net->getCurrentTimeStep() + DELTA_T); } @@ -457,6 +459,7 @@ MSPModel_JuPedSim::execute(SUMOTime time) { dumpGeometry(pedestrianNetworkWithTrainsAndRamps, "pedestrianNetworkWithTrainsAndRamps.wkt"); #endif myJPSGeometryWithTrainsAndRamps = buildJPSGeometryFromGEOSGeometry(pedestrianNetworkWithTrainsAndRamps); + preparePolygonForDrawing(myMaxAreaConnectedComponentPolygon, myMaxAreaPolygonId + ".carriages_and_ramps", PEDESTRIAN_NETWORK_COLOR); #if JPS_VERSION > 106 JPS_Simulation_SwitchGeometry(myJPSSimulation, myJPSGeometryWithTrainsAndRamps, nullptr, nullptr); #endif @@ -828,12 +831,11 @@ MSPModel_JuPedSim::preparePolygonForJPS(const GEOSGeometry* polygon, JPS_Geometr void -MSPModel_JuPedSim::preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId) { +MSPModel_JuPedSim::preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId, const RGBColor& color) { const GEOSGeometry* exterior = GEOSGetExteriorRing(polygon); PositionVector shape = getCoordinates(exterior); ShapeContainer& shapeContainer = myNetwork->getShapeContainer(); - shapeContainer.removePolygon(polygonId); - bool added = shapeContainer.addPolygon(polygonId, std::string("jupedsim.pedestrian_network"), RGBColor(179, 217, 255, 255), 10.0, 0.0, std::string(), false, shape, false, true, 1.0); + bool added = shapeContainer.addPolygon(polygonId, std::string("jupedsim.pedestrian_network"), color, 10.0, 0.0, std::string(), false, shape, false, true, 1.0); if (added) { std::vector holes; int nbrInteriorRings = GEOSGetNumInteriorRings(polygon); @@ -856,20 +858,19 @@ JPS_Geometry MSPModel_JuPedSim::buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon) { // For the moment, JuPedSim only supports one connected component, select the one with max area. int nbrConnectedComponents = GEOSGetNumGeometries(polygon); - const GEOSGeometry* maxAreaConnectedComponentPolygon = nullptr; - std::string maxAreaPolygonId; + myMaxAreaConnectedComponentPolygon = nullptr; double maxArea = 0.0; double totalArea = 0.0; for (unsigned int i = 0; i < (unsigned int)nbrConnectedComponents; i++) { const GEOSGeometry* connectedComponentPolygon = GEOSGetGeometryN(polygon, i); - std::string polygonId = std::string("jupedsim.pedestrian_network.") + std::to_string(i); + const std::string polygonId = std::string("jupedsim.pedestrian_network.") + std::to_string(i); double area; GEOSArea(connectedComponentPolygon, &area); totalArea += area; if (area > maxArea) { maxArea = area; - maxAreaConnectedComponentPolygon = connectedComponentPolygon; - maxAreaPolygonId = polygonId; + myMaxAreaConnectedComponentPolygon = connectedComponentPolygon; + myMaxAreaPolygonId = polygonId; } } if (nbrConnectedComponents > 1) { @@ -880,8 +881,7 @@ MSPModel_JuPedSim::buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon) dumpGeometry(maxAreaConnectedComponentPolygon, "pedestrianNetwork.wkt"); #endif JPS_GeometryBuilder geometryBuilder = JPS_GeometryBuilder_Create(); - preparePolygonForJPS(maxAreaConnectedComponentPolygon, geometryBuilder); - preparePolygonForDrawing(maxAreaConnectedComponentPolygon, maxAreaPolygonId); + preparePolygonForJPS(myMaxAreaConnectedComponentPolygon, geometryBuilder); JPS_ErrorMessage message = nullptr; JPS_Geometry geometry = JPS_GeometryBuilder_Build(geometryBuilder, &message); if (geometry == nullptr) { @@ -913,6 +913,7 @@ MSPModel_JuPedSim::initialize(const OptionsCont& oc) { PROGRESS_BEGIN_MESSAGE("Generating initial JuPedSim geometry for pedestrian network"); myGEOSPedestrianNetwork = buildPedestrianNetwork(myNetwork); myJPSGeometry = buildJPSGeometryFromGEOSGeometry(myGEOSPedestrianNetwork); + preparePolygonForDrawing(myMaxAreaConnectedComponentPolygon, myMaxAreaPolygonId, PEDESTRIAN_NETWORK_COLOR); PROGRESS_DONE_MESSAGE(); myJPSGeometryWithTrainsAndRamps = nullptr; JPS_ErrorMessage message = nullptr; diff --git a/src/microsim/transportables/MSPModel_JuPedSim.h b/src/microsim/transportables/MSPModel_JuPedSim.h index 1d03d71425b2..60c2b0c3f9d8 100644 --- a/src/microsim/transportables/MSPModel_JuPedSim.h +++ b/src/microsim/transportables/MSPModel_JuPedSim.h @@ -155,6 +155,8 @@ class MSPModel_JuPedSim : public MSPModel { std::vector myPedestrianStates; GEOSGeometry* myGEOSPedestrianNetwork; + const GEOSGeometry* myMaxAreaConnectedComponentPolygon; + std::string myMaxAreaPolygonId; bool myHaveAdditionalWalkableAreas; JPS_Geometry myJPSGeometry; @@ -176,6 +178,7 @@ class MSPModel_JuPedSim : public MSPModel { static const double GEOS_MIN_AREA; static const double GEOS_BUFFERED_SEGMENT_WIDTH; static const double CARRIAGE_RAMP_WIDTH; + static const RGBColor PEDESTRIAN_NETWORK_COLOR; void initialize(const OptionsCont& oc); void tryPedestrianInsertion(PState* state, const Position& p); @@ -192,7 +195,7 @@ class MSPModel_JuPedSim : public MSPModel { static std::vector convertToJPSPoints(const GEOSGeometry* geometry); static double getHoleArea(const GEOSGeometry* hole); void preparePolygonForJPS(const GEOSGeometry* polygon, JPS_GeometryBuilder geometryBuilder); - void preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId); + void preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId, const RGBColor& color); JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon); static void dumpGeometry(const GEOSGeometry* polygon, const std::string& filename); };