LCOV - code coverage report
Current view: top level - src/utils/shapes - PolygonDynamics.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 5 5 100.0 %
Date: 2024-05-05 15:31:14 Functions: 0 0 -

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2004-2024 German Aerospace Center (DLR) and others.
       4             : // This program and the accompanying materials are made available under the
       5             : // terms of the Eclipse Public License 2.0 which is available at
       6             : // https://www.eclipse.org/legal/epl-2.0/
       7             : // This Source Code may also be made available under the following Secondary
       8             : // Licenses when the conditions for such availability set forth in the Eclipse
       9             : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10             : // or later which is available at
      11             : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12             : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13             : /****************************************************************************/
      14             : /// @file    PolygonDynamics.h
      15             : /// @author  Leonhard Luecken
      16             : /// @date    Apr 2019
      17             : ///
      18             : // A polygon, which holds a timeSpan for displaying dynamic properties
      19             : /****************************************************************************/
      20             : 
      21             : 
      22             : #pragma once
      23             : #include <config.h>
      24             : 
      25             : #include <memory>
      26             : #include "SUMOPolygon.h"
      27             : #include "utils/common/SUMOTime.h"
      28             : 
      29             : class SUMOTrafficObject;
      30             : class ShapeContainer;
      31             : class SUMORTree;
      32             : 
      33             : class PolygonDynamics {
      34             : public:
      35             :     /**
      36             :      * @brief Constructor that takes a SUMOPolygon and adds timelines for the properties to be modified dynamically.
      37             :      * @param p Polygon to be modified
      38             :      * @param trackedObject A tracked object (nullptr indicates that no tracking is desired)
      39             :      * @param timeSpan Anchor time points
      40             :      *        For animated polygons: assumed to have a size >= 2, and start at timeSpan[0]=0,
      41             :      *        such that timeSpan[i+1] >= timeSpan[i])
      42             :      *        If no animation is desired, give timeSpan == nullptr
      43             :      * @param ...Span property timelines (assumed to be either nullptr, or of size equal to timeSpan (in case of animated poly))
      44             :      * @param looped Whether the animation should restart when the last keyframe is reached. In that case
      45             :      *               the animation jumps to the first keyframe as soon as the last is reached.
      46             :      *               If looped==false, the controlled polygon is removed as soon as the timeSpan elapses.
      47             :      * @param rotate Whether the polygon shall be rotated with the tracked object.
      48             :      */
      49             :     PolygonDynamics(double creationTime,
      50             :                     SUMOPolygon* p,
      51             :                     SUMOTrafficObject* trackedObject,
      52             :                     const std::vector<double>& timeSpan,
      53             :                     const std::vector<double>& alphaSpan,
      54             :                     bool looped,
      55             :                     bool rotate);
      56             :     virtual ~PolygonDynamics();
      57             : 
      58             :     const std::string& getPolygonID() const {
      59         302 :         return myPolygon->getID();
      60             :     }
      61             : 
      62             :     SUMOPolygon* getPolygon() const {
      63        2929 :         return myPolygon;
      64             :     }
      65             : 
      66             :     inline const std::string& getTrackedObjectID() const {
      67         330 :         return myTrackedObjectID;
      68             :     }
      69             : 
      70             :     /// @brief Updates the polygon according to its timeSpan and follows the tracked object
      71             :     /// @param t Current sumo time step (in ms.) when this is called
      72             :     /// @returns Next desired update time.
      73             :     SUMOTime update(SUMOTime t);
      74             : 
      75             :     /// @brief Set the RTree
      76             :     void setRTree(SUMORTree* rtree) {
      77         100 :         myVis = rtree;
      78         100 :     }
      79             : 
      80             : private:
      81             : 
      82             :     /// @brief Sets the alpha value for the shape's color
      83             :     void setAlpha(double alpha);
      84             : 
      85             :     /// @brief Initialize the object's position
      86             :     void initTrackedPosition();
      87             : 
      88             :     /// @brief The polygon this dynamics acts upon.
      89             :     SUMOPolygon* myPolygon;
      90             : 
      91             :     /// @brief Current time
      92             :     double myCurrentTime;
      93             : 
      94             :     /// @brief The last time the animation has been updated
      95             :     double myLastUpdateTime;
      96             : 
      97             :     /// @brief Whether this polygon is animated, i.e., whether
      98             :     ///        timelines should be used to control properties.
      99             :     bool animated;
     100             : 
     101             :     /// @brief Whether animation should be looped.
     102             :     bool looped;
     103             : 
     104             :     /// @brief Whether this polygon tracks an object
     105             :     bool tracking;
     106             : 
     107             :     /// @brief Whether this polygon should be rotated with the tracked object
     108             :     bool rotate;
     109             : 
     110             :     /// @brief An object tracked by the shape, deletion by caller
     111             :     SUMOTrafficObject* myTrackedObject;
     112             :     std::string myTrackedObjectID;
     113             : 
     114             :     /// @brief Initial position of the tracked object
     115             :     std::unique_ptr<Position> myTrackedObjectsInitialPositon;
     116             : 
     117             :     /// @brief Initial angle of the tracked object
     118             :     double myTrackedObjectsInitialAngle;
     119             : 
     120             :     /// @brief the original shape of the polygon
     121             :     /// (in case of tracking another object, this is converted to relative
     122             :     ///  coords wrt to the other objects initial position as origin)
     123             :     std::unique_ptr<PositionVector> myOriginalShape;
     124             : 
     125             :     /// @brief Time points corresponding to the anchor values of the dynamic properties
     126             :     /// @note  Assumed to have a size >= 2, and start at timeSpan[0]=0, such that timeSpan[i+1] >= timeSpan[i]
     127             :     std::unique_ptr<std::vector<double> > myTimeSpan;
     128             : 
     129             :     /// @brief Pointer to the next time points in timeSpan
     130             :     /// @note  These iterators are only valid if timeSpan != nullptr
     131             :     std::vector<double>::const_iterator myPrevTime;
     132             :     std::vector<double>::const_iterator myNextTime;
     133             : 
     134             :     /// @brief Alpha values corresponding to
     135             :     std::unique_ptr<std::vector<double> > myAlphaSpan;
     136             :     /// @brief Pointer to the next alpha points in alphaSpan
     137             :     /// @note  These iterators are only valid if alphaSpan != nullptr
     138             :     std::vector<double>::const_iterator myPrevAlpha;
     139             :     std::vector<double>::const_iterator myNextAlpha;
     140             : 
     141             :     /// @brief RTree will be supplied in case of GUI simulation to be updated on move
     142             :     SUMORTree* myVis;
     143             : 
     144             : };

Generated by: LCOV version 1.14