/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2004-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file PolygonDynamics.h14/// @author Leonhard Luecken15/// @date Apr 201916///17// A polygon, which holds a timeSpan for displaying dynamic properties18/****************************************************************************/192021#pragma once22#include <config.h>2324#include <memory>25#include "SUMOPolygon.h"26#include "utils/common/SUMOTime.h"2728class SUMOTrafficObject;29class ShapeContainer;30class SUMORTree;3132class PolygonDynamics {33public:34/**35* @brief Constructor that takes a SUMOPolygon and adds timelines for the properties to be modified dynamically.36* @param p Polygon to be modified37* @param trackedObject A tracked object (nullptr indicates that no tracking is desired)38* @param timeSpan Anchor time points39* For animated polygons: assumed to have a size >= 2, and start at timeSpan[0]=0,40* such that timeSpan[i+1] >= timeSpan[i])41* If no animation is desired, give timeSpan == nullptr42* @param ...Span property timelines (assumed to be either nullptr, or of size equal to timeSpan (in case of animated poly))43* @param looped Whether the animation should restart when the last keyframe is reached. In that case44* the animation jumps to the first keyframe as soon as the last is reached.45* If looped==false, the controlled polygon is removed as soon as the timeSpan elapses.46* @param rotate Whether the polygon shall be rotated with the tracked object.47*/48PolygonDynamics(double creationTime,49SUMOPolygon* p,50SUMOTrafficObject* trackedObject,51const std::vector<double>& timeSpan,52const std::vector<double>& alphaSpan,53bool looped,54bool rotate);55virtual ~PolygonDynamics();5657const std::string& getPolygonID() const {58return myPolygon->getID();59}6061SUMOPolygon* getPolygon() const {62return myPolygon;63}6465inline const std::string& getTrackedObjectID() const {66return myTrackedObjectID;67}6869/// @brief Updates the polygon according to its timeSpan and follows the tracked object70/// @param t Current sumo time step (in ms.) when this is called71/// @returns Next desired update time.72SUMOTime update(SUMOTime t);7374/// @brief Set the RTree75void setRTree(SUMORTree* rtree) {76myVis = rtree;77}7879private:8081/// @brief Sets the alpha value for the shape's color82void setAlpha(double alpha);8384/// @brief Initialize the object's position85void initTrackedPosition();8687/// @brief The polygon this dynamics acts upon.88SUMOPolygon* myPolygon;8990/// @brief Current time91double myCurrentTime;9293/// @brief The last time the animation has been updated94double myLastUpdateTime;9596/// @brief Whether this polygon is animated, i.e., whether97/// timelines should be used to control properties.98bool animated;99100/// @brief Whether animation should be looped.101bool looped;102103/// @brief Whether this polygon tracks an object104bool tracking;105106/// @brief Whether this polygon should be rotated with the tracked object107bool rotate;108109/// @brief An object tracked by the shape, deletion by caller110SUMOTrafficObject* myTrackedObject;111std::string myTrackedObjectID;112113/// @brief Initial position of the tracked object114std::unique_ptr<Position> myTrackedObjectsInitialPositon;115116/// @brief Initial angle of the tracked object117double myTrackedObjectsInitialAngle;118119/// @brief the original shape of the polygon120/// (in case of tracking another object, this is converted to relative121/// coords wrt to the other objects initial position as origin)122std::unique_ptr<PositionVector> myOriginalShape;123124/// @brief Time points corresponding to the anchor values of the dynamic properties125/// @note Assumed to have a size >= 2, and start at timeSpan[0]=0, such that timeSpan[i+1] >= timeSpan[i]126std::unique_ptr<std::vector<double> > myTimeSpan;127128/// @brief Pointer to the next time points in timeSpan129/// @note These iterators are only valid if timeSpan != nullptr130std::vector<double>::const_iterator myPrevTime;131std::vector<double>::const_iterator myNextTime;132133/// @brief Alpha values corresponding to134std::unique_ptr<std::vector<double> > myAlphaSpan;135/// @brief Pointer to the next alpha points in alphaSpan136/// @note These iterators are only valid if alphaSpan != nullptr137std::vector<double>::const_iterator myPrevAlpha;138std::vector<double>::const_iterator myNextAlpha;139140/// @brief RTree will be supplied in case of GUI simulation to be updated on move141SUMORTree* myVis;142143};144145146