Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2014-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 MSTrainHelper.h
15 : /// @author Benjamin Coueraud
16 : /// @date Wed, 07 Fev 2024
17 : ///
18 : // A class that helps computing positions of a train's carriages.
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <utils/geom/Position.h>
24 : #include <utils/geom/PositionVector.h>
25 : #include "MSVehicleControl.h"
26 :
27 : // ===========================================================================
28 : // class declarations
29 : // ===========================================================================
30 : class MSVehicle;
31 :
32 :
33 : // ===========================================================================
34 : // class definitions
35 : // ===========================================================================
36 : /**
37 : * @class MSTrainHelper
38 : * @brief A class that helps computing positions of a train's carriages
39 : * and additional structures.
40 : *
41 : */
42 : class MSTrainHelper {
43 : public:
44 14953 : struct Carriage {
45 : Position front;
46 : Position back;
47 : std::vector<Position> doorPositions;
48 : std::vector<Position> unboardingPositions;
49 : };
50 :
51 4694 : MSTrainHelper(const MSVehicle* vehicle, bool reversed = false, bool secondaryShape = false, double exaggeration = 1.0, int vehicleQuality = 3)
52 4694 : : myTrain(vehicle) {
53 4694 : computeTrainDimensions(exaggeration, vehicleQuality);
54 4694 : computeCarriages(reversed, secondaryShape);
55 4694 : }
56 :
57 4694 : ~MSTrainHelper() {
58 19647 : for (const Carriage* carriage : myCarriages) {
59 29906 : delete carriage;
60 : }
61 4694 : }
62 :
63 : inline double getUpscaleLength() const {
64 8716 : return myUpscaleLength;
65 : }
66 :
67 : inline double getHalfWidth() const {
68 13612 : return myHalfWidth;
69 : }
70 :
71 : inline int getNumCarriages() const {
72 4694 : return myNumCarriages;
73 : }
74 :
75 : inline double getCarriageLength() const {
76 9254 : return myCarriageLength;
77 : }
78 :
79 : inline double getFirstCarriageLength() const {
80 8716 : return myFirstCarriageLength;
81 : }
82 :
83 : inline int getCarriageDoors() const {
84 336 : return myCarriageDoors;
85 : }
86 :
87 : inline int getFirstCarriageNo() const {
88 39036 : return myFirstCarriageNo;
89 : }
90 :
91 : inline int getFirstPassengerCarriage() const {
92 4694 : return myFirstPassengerCarriage;
93 : }
94 :
95 : inline bool isReversed() const {
96 13612 : return myIsReversed;
97 : }
98 :
99 : inline const std::vector<Carriage*>& getCarriages() const {
100 : return myCarriages;
101 : }
102 :
103 : /// @brief compute door positions on demand and fills the carriage structures
104 : /// @remark need to be called before retrieving carriages if door positions needed
105 : void computeDoorPositions();
106 :
107 : /// @brief compute unboarding positions on demand and fills the carriage structures
108 : /// @remark need to be called before retrieving carriages if unboarding positions needed
109 : void computeUnboardingPositions(double passengerRadius, std::vector<Position>& unboardingPositions);
110 :
111 : /// @brief return length exaggeration factor (special for long vehicles)
112 : static double getUpscaleLength(double upscale, double length, double width, int vehicleQuality);
113 :
114 : /// @brief average door width used to compute doors positions
115 : static const double CARRIAGE_DOOR_WIDTH;
116 :
117 : /// @brief small extra tolerance used to avoid constraint violations
118 : static const double PEDESTRIAN_RADIUS_EXTRA_TOLERANCE;
119 :
120 : private:
121 : void computeTrainDimensions(double exaggeration, int vehicleQuality);
122 : void computeCarriages(bool reversed, bool secondaryShape);
123 :
124 : const MSVehicle* myTrain;
125 : double myUpscaleLength;
126 : double myLocomotiveLength;
127 : double myDefaultLength;
128 : double myCarriageGap;
129 : double myLength;
130 : double myHalfWidth;
131 : int myNumCarriages;
132 : double myCarriageLengthWithGap;
133 : double myCarriageLength;
134 : double myFirstCarriageLength;
135 : int myCarriageDoors;
136 : int myFirstCarriageNo;
137 : int myFirstPassengerCarriage;
138 : bool myIsReversed;
139 : std::vector<Carriage*> myCarriages;
140 : };
|