1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file GUIInductLoop.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Sascha Krieg 14 /// @author Michael Behrisch 15 /// @date Aug 2003 16 /// @version $Id$ 17 /// 18 // The gui-version of the MSInductLoop, together with the according 19 /****************************************************************************/ 20 #ifndef GUIInductLoop_h 21 #define GUIInductLoop_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <fx.h> 30 #include <microsim/output/MSInductLoop.h> 31 #include <utils/geom/Position.h> 32 #include "GUIDetectorWrapper.h" 33 34 35 // =========================================================================== 36 // class definitions 37 // =========================================================================== 38 /** 39 * @class GUIInductLoop 40 * @brief The gui-version of the MSInductLoop. 41 * 42 * Allows the building of a wrapper (also declared herein) which draws the 43 * detector on the gl-canvas. Uses a mutex to avoid parallel read/write operations. 44 * The mutex is only set within methods that change MSInductLoop-internal state 45 * and within "collectVehiclesOnDet". All other reading operations should be performed 46 * via the simulation loop only. 47 */ 48 class GUIInductLoop : public MSInductLoop { 49 public: 50 /** 51 * @brief Constructor. 52 * @param[in] id Unique id 53 * @param[in] lane Lane where detector woks on 54 * @param[in] position Position of the detector within the lane 55 * @param[in] vTypes which vehicle types are considered 56 */ 57 GUIInductLoop(const std::string& id, MSLane* const lane, double position, const std::string& vTypes); 58 59 60 /// @brief Destructor 61 ~GUIInductLoop(); 62 63 64 /** @brief Resets all generated values to allow computation of next interval 65 * 66 * Locks the internal mutex before calling MSInductLoop::reset() 67 * @see MSInductLoop::reset() 68 */ 69 void reset(); 70 71 72 /** @brief Returns this detector's visualisation-wrapper 73 * @return The wrapper representing the detector 74 */ 75 virtual GUIDetectorWrapper* buildDetectorGUIRepresentation(); 76 77 78 /** @brief Returns vehicle data for vehicles that have been on the detector starting at the given time 79 * 80 * This method uses a mutex to prevent parallel read/write access to the vehicle buffer 81 * 82 * @param[in] t The time from which vehicles shall be counted 83 * @param[in] leaveTime Whether entryTime or leaveTime shall be compared against t 84 * (the latter gives a more complete picture but may include vehicles in multiple steps even if they did not stay on the detector) 85 * @return The list of vehicles 86 * @see MSInductLoop::collectVehiclesOnDet() 87 */ 88 std::vector<VehicleData> collectVehiclesOnDet(SUMOTime t, bool leaveTime = false) const; 89 90 91 /// @brief sets special caller for myWrapper 92 void setSpecialColor(const RGBColor* color); 93 94 protected: 95 /// @name Methods that add and remove vehicles from internal container 96 /// @{ 97 98 /** @brief Introduces a vehicle to the detector's map myVehiclesOnDet. 99 * 100 * Locks the internal mutex before calling MSInductLoop::enterDetectorByMove() 101 * @see MSInductLoop::enterDetectorByMove() 102 * @param veh The entering vehicle. 103 * @param entryTimestep Timestep (not necessary integer) of entrance. 104 * @see MSInductLoop::enterDetectorByMove() 105 */ 106 void enterDetectorByMove(SUMOTrafficObject& veh, double entryTimestep); 107 108 109 /** @brief Processes a vehicle that leaves the detector 110 * 111 * Locks the internal mutex before calling MSInductLoop::leaveDetectorByMove() 112 * @see MSInductLoop::leaveDetectorByMove() 113 * @param veh The leaving vehicle. 114 * @param leaveTimestep Timestep (not necessary integer) of leaving. 115 * @see MSInductLoop::leaveDetectorByMove() 116 */ 117 void leaveDetectorByMove(SUMOTrafficObject& veh, double leaveTimestep); 118 119 120 /** @brief Removes a vehicle from the detector's map myVehiclesOnDet. 121 * 122 * Locks the internal mutex before calling MSInductLoop::leaveDetectorByLaneChange() 123 * @see MSInductLoop::leaveDetectorByLaneChange() 124 * @param veh The leaving vehicle. 125 * @param lastPos The last position of the leaving vehicle. 126 */ 127 void leaveDetectorByLaneChange(SUMOTrafficObject& veh, double lastPos); 128 /// @} 129 130 131 132 133 public: 134 /** 135 * @class GUIInductLoop::MyWrapper 136 * @brief A MSInductLoop-visualiser 137 */ 138 class MyWrapper : public GUIDetectorWrapper { 139 public: 140 /// @brief Constructor 141 MyWrapper(GUIInductLoop& detector, double pos); 142 143 /// @brief Destructor 144 ~MyWrapper(); 145 146 147 /// @name inherited from GUIGlObject 148 //@{ 149 150 /** @brief Returns an own parameter window 151 * 152 * @param[in] app The application needed to build the parameter window 153 * @param[in] parent The parent window needed to build the parameter window 154 * @return The built parameter window 155 * @see GUIGlObject::getParameterWindow 156 */ 157 GUIParameterTableWindow* getParameterWindow( 158 GUIMainWindow& app, GUISUMOAbstractView& parent); 159 160 161 /** @brief Returns the boundary to which the view shall be centered in order to show the object 162 * 163 * @return The boundary the object is within 164 * @see GUIGlObject::getCenteringBoundary 165 */ 166 Boundary getCenteringBoundary() const; 167 168 169 /** @brief Draws the object 170 * @param[in] s The settings for the current view (may influence drawing) 171 * @see GUIGlObject::drawGL 172 */ 173 void drawGL(const GUIVisualizationSettings& s) const; 174 //@} 175 176 177 /// @brief Returns the detector itself 178 GUIInductLoop& getLoop(); 179 180 /// @brief set (outline) color for extra visualiaztion setSpecialColor(const RGBColor * color)181 void setSpecialColor(const RGBColor* color) { 182 mySpecialColor = color; 183 } 184 185 private: 186 /// @brief The wrapped detector 187 GUIInductLoop& myDetector; 188 189 /// @brief The detector's boundary 190 Boundary myBoundary; 191 192 /// @brief The position in full-geometry mode 193 Position myFGPosition; 194 195 /// @brief The rotation in full-geometry mode 196 double myFGRotation; 197 198 /// @brief The position on the lane 199 double myPosition; 200 201 /// @brief color for extra visualization 202 const RGBColor* mySpecialColor; 203 204 private: 205 /// @brief Invalidated copy constructor. 206 MyWrapper(const MyWrapper&); 207 208 /// @brief Invalidated assignment operator. 209 MyWrapper& operator=(const MyWrapper&); 210 211 }; 212 213 private: 214 215 /// @brief the glObject wrapper for this induction loop 216 MyWrapper* myWrapper; 217 218 /// @brief Mutex preventing parallel read/write access to internal MSInductLoop state 219 mutable FXMutex myLock; 220 221 }; 222 223 224 #endif 225 226 /****************************************************************************/ 227 228