#include <Direction.h>
Public Member Functions | |
void | clear () |
Clears the direction so it can be used in another simulation. | |
Direction () | |
Default constructor. | |
virtual | ~Direction () |
Default destructor. | |
void | setRoadSegments (std::vector< RoadSegment * > segments) |
void | setOutputDetector (OutputDetector *OutputDet) |
Sets the direction's output detector. | |
OutputDetector * | getOutputDetector () |
Gets the direction's output detector. | |
Lane & | getLane (int i) |
Gets a specific lane. | |
int | getNoLanes () |
Gets the number of lanes. | |
M2D | getVehiclesM2D () |
Gets all the vehicles on the road. | |
M2D | getGlobalPos () |
Updates all the vehicle positions to take account of direction. | |
bool | update (const double step, const double curTime) |
Handles the updating of all the lanes in the direction. | |
void | init (bool DirPos, OutputDetector *OutDet, bool AllowLaneChange, int RoadLength, bool DriveOnRight) |
Initialises the direction. | |
void | createLanes (int iFirstLane, std::vector< int > vLaneLengths, std::vector< Detector * > detectors, std::vector< RoadSegment * > segments) |
Creates all the lanes running in a particular direction. | |
Private Member Functions | |
void | CheckDetectorTimes (double step) |
Checks all the detectors for their output times. | |
Private Attributes | |
bool | m_DriveOnRight |
bool | m_AllowLaneChanging |
double | m_RoadLength |
bool | m_DirPos |
int | m_NoLanes |
OutputDetector * | m_pOutputDetector |
std::vector< Lane > | m_vLanes |
std::vector< Detector * > | m_vDetectors |
std::vector< RoadSegment * > | m_vRoadSegments |
Definition at line 13 of file Direction.h.
Direction::Direction | ( | ) |
Default constructor.
Definition at line 6 of file Direction.cpp.
References m_pOutputDetector.
00007 { 00008 m_pOutputDetector = NULL; 00009 }
Direction::~Direction | ( | ) | [virtual] |
Default destructor.
Definition at line 12 of file Direction.cpp.
References m_vDetectors, and m_vRoadSegments.
00013 { 00014 int i; 00015 00016 // Delete all of this direction's metrics detectors 00017 for(i = 0; i < m_vDetectors.size(); i++) 00018 delete m_vDetectors.at(i); 00019 00020 00021 // Delete all of this direction's special segments 00022 for(i = 0; i < m_vRoadSegments.size(); i++) 00023 delete m_vRoadSegments.at(i); 00024 00025 }
void Direction::clear | ( | ) |
Clears the direction so it can be used in another simulation.
This function clears all of the direction's information so that it may be used in another simulation without re-instanciating.
Definition at line 220 of file Direction.cpp.
References m_pOutputDetector, m_vDetectors, m_vLanes, and m_vRoadSegments.
Referenced by Road::clear().
00221 { 00222 int i; 00223 00224 for(i = 0; i < m_vLanes.size(); i++) 00225 m_vLanes.at(i).clear(); 00226 00227 m_vLanes.clear(); 00228 00229 delete m_pOutputDetector; // Delete this direction's output detector 00230 00231 // Delete all of this direction's metrics detectors 00232 for(i = 0; i < m_vDetectors.size(); i++) 00233 delete m_vDetectors.at(i); 00234 00235 m_vDetectors.clear(); 00236 00237 // Delete all of this direction's special segments 00238 for(i = 0; i < m_vRoadSegments.size(); i++) 00239 delete m_vRoadSegments.at(i); 00240 00241 m_vRoadSegments.clear(); 00242 }
void Direction::setRoadSegments | ( | std::vector< RoadSegment * > | segments | ) |
void Direction::setOutputDetector | ( | OutputDetector * | OutputDet | ) |
Sets the direction's output detector.
OutputDet | The direction's output detector |
Definition at line 196 of file Direction.cpp.
References m_pOutputDetector.
00197 { 00198 m_pOutputDetector = OutputDet; 00199 }
OutputDetector * Direction::getOutputDetector | ( | ) |
Gets the direction's output detector.
Definition at line 187 of file Direction.cpp.
References m_pOutputDetector.
00188 { 00189 return m_pOutputDetector; 00190 }
Lane & Direction::getLane | ( | int | i | ) |
Gets a specific lane.
i | The lane to choose |
Definition at line 178 of file Direction.cpp.
References m_vLanes.
Referenced by Road::init().
00179 { 00180 return m_vLanes.at(i); 00181 }
int Direction::getNoLanes | ( | ) |
Gets the number of lanes.
Definition at line 168 of file Direction.cpp.
References m_NoLanes.
Referenced by Road::init().
00169 { 00170 return m_NoLanes; 00171 }
M2D Direction::getVehiclesM2D | ( | ) |
Gets all the vehicles on the road.
Definition at line 151 of file Direction.cpp.
References m_NoLanes, and m_vLanes.
Referenced by getGlobalPos().
00152 { 00153 // returns vehicles for position from the start of the lane extraction 00154 M2D vVeh2D; 00155 00156 for(int i = 0; i < m_NoLanes; i++) 00157 { 00158 std::vector<Vehicle*> temp = m_vLanes[i].getPos(); 00159 vVeh2D.push_back(temp); 00160 } 00161 return vVeh2D; 00162 }
M2D Direction::getGlobalPos | ( | ) |
Updates all the vehicle positions to take account of direction.
Definition at line 130 of file Direction.cpp.
References getVehiclesM2D(), m_DirPos, m_NoLanes, and m_vLanes.
Referenced by Road::getVehicles().
00131 { 00132 // this modifies the lane position to take accound of direction 00133 M2D vVeh2D = getVehiclesM2D(); 00134 00135 if(!m_DirPos) // if in negative x-direction 00136 { 00137 for(int i = 0; i < m_NoLanes; i++) 00138 { 00139 int d2 = vVeh2D[i].size(); 00140 for(int j = 0; j < d2; j++) 00141 vVeh2D[i][j]->setRoadPos( m_vLanes[i].getLength() - vVeh2D[i][j]->getPos() ); 00142 } 00143 } 00144 return vVeh2D; 00145 }
bool Direction::update | ( | const double | step, | |
const double | curTime | |||
) |
Handles the updating of all the lanes in the direction.
step | The timestep | |
curTime | The current simulation time |
Definition at line 37 of file Direction.cpp.
References CheckDetectorTimes(), m_NoLanes, m_pOutputDetector, m_vLanes, and OutputDetector::WriteVehiclesToFile().
Referenced by Road::update().
00038 { 00039 CheckDetectorTimes(step); // check if it's time to output what we have 00040 bool DirectionEmpty = false; 00041 int NoEmptyLanes = 0; 00042 for(int i = 0; i < m_NoLanes; i++) 00043 { 00044 bool laneEmpty = m_vLanes[i].update(step, curTime); 00045 if(laneEmpty) 00046 NoEmptyLanes++; 00047 } 00048 00049 // output any vehicles past the detector 00050 m_pOutputDetector->WriteVehiclesToFile(); 00051 00052 if(NoEmptyLanes == m_NoLanes) 00053 DirectionEmpty = true; 00054 00055 return DirectionEmpty; 00056 }
void Direction::init | ( | bool | DirPos, | |
OutputDetector * | pOutDet, | |||
bool | AllowLaneChange, | |||
int | RoadLength, | |||
bool | DriveOnRight | |||
) |
Initialises the direction.
DirPos | Whether or not the direction is in a positive direction | |
pOutDet | The direction's output detector | |
AllowLaneChange | Whether or not lane changing is allowed | |
RoadLength | The length of the road | |
DriveOnRight | Whether or not vehicles drive on the right |
Definition at line 66 of file Direction.cpp.
References m_AllowLaneChanging, m_DirPos, m_DriveOnRight, m_pOutputDetector, and m_RoadLength.
Referenced by Road::init().
00067 { 00068 m_DirPos = DirPos; 00069 m_pOutputDetector = pOutDet; 00070 m_AllowLaneChanging = AllowLaneChange; 00071 m_RoadLength = RoadLength; 00072 m_DriveOnRight = DriveOnRight; 00073 }
void Direction::createLanes | ( | int | iFirstLane, | |
std::vector< int > | vLaneLengths, | |||
std::vector< Detector * > | detectors, | |||
std::vector< RoadSegment * > | segments | |||
) |
Creates all the lanes running in a particular direction.
iFirstLane | The index of the first lane in this direction | |
vLaneLengths | The number of lanes to create | |
detectors | The detectors in the direction | |
segments | The segments in this direction |
Definition at line 86 of file Direction.cpp.
References m_AllowLaneChanging, m_DirPos, m_DriveOnRight, m_NoLanes, m_pOutputDetector, m_vDetectors, m_vLanes, m_vRoadSegments, Lane::setOutputDetector(), and Lane::setRoadSegments().
Referenced by Road::init().
00088 { 00089 m_NoLanes = vLaneLengths.size(); 00090 m_vDetectors = detectors; 00091 m_vRoadSegments = segments; 00092 00093 for(int i = 0; i < m_NoLanes; i++) 00094 { 00095 Lane lane(iFirstLane + i, vLaneLengths[i], m_vDetectors, m_DirPos, m_AllowLaneChanging); 00096 lane.setOutputDetector(m_pOutputDetector); 00097 lane.setRoadSegments(m_vRoadSegments); 00098 m_vLanes.push_back(lane); 00099 } 00100 00101 // set adjacent lanes if more than 1 lane 00102 if(m_NoLanes > 1) 00103 { 00104 // If(DRIVE_ON_RIGHT), lanes are numbered from the BTM of the screen as: 00105 // Dir Pos - 0, 1, 2, 3 - Dir Neg - 4, 5, 6, 7 00106 // else lanes are numbered from the TOP of the screen 00107 if(m_DriveOnRight) 00108 { 00109 for(i = 0; i < m_NoLanes - 1; i++) 00110 m_vLanes.at(i).setLeftLane(&m_vLanes.at(i+1)); // next lane up the screen 00111 for(i = 1; i < m_NoLanes; i++) 00112 m_vLanes.at(i).setRightLane(&m_vLanes.at(i-1)); // one down the screen 00113 } 00114 else 00115 { 00116 for(i = 0; i < m_NoLanes - 1; i++) 00117 m_vLanes.at(i).setRightLane(&m_vLanes.at(i+1)); // next lane down the screen 00118 for(i = 1; i < m_NoLanes; i++) 00119 m_vLanes.at(i).setLeftLane(&m_vLanes.at(i-1)); // next one up the screen 00120 } 00121 } 00122 }
void Direction::CheckDetectorTimes | ( | double | step | ) | [private] |
Checks all the detectors for their output times.
step | The timestep |
Definition at line 208 of file Direction.cpp.
References m_vDetectors.
Referenced by update().
00209 { 00210 for(int i = 0; i < m_vDetectors.size(); i++) 00211 { 00212 m_vDetectors.at(i)->CheckForOutputTime(step); 00213 } 00214 }
bool Direction::m_DriveOnRight [private] |
bool Direction::m_AllowLaneChanging [private] |
double Direction::m_RoadLength [private] |
bool Direction::m_DirPos [private] |
int Direction::m_NoLanes [private] |
Definition at line 43 of file Direction.h.
Referenced by createLanes(), getGlobalPos(), getNoLanes(), getVehiclesM2D(), and update().
OutputDetector* Direction::m_pOutputDetector [private] |
Definition at line 45 of file Direction.h.
Referenced by clear(), createLanes(), Direction(), getOutputDetector(), init(), setOutputDetector(), and update().
std::vector<Lane> Direction::m_vLanes [private] |
Definition at line 46 of file Direction.h.
Referenced by clear(), createLanes(), getGlobalPos(), getLane(), getVehiclesM2D(), and update().
std::vector<Detector*> Direction::m_vDetectors [private] |
Definition at line 47 of file Direction.h.
Referenced by CheckDetectorTimes(), clear(), createLanes(), and ~Direction().
std::vector<RoadSegment*> Direction::m_vRoadSegments [private] |