hivemind 1.0.0
Loading...
Searching...
No Matches
scenario.cpp
Go to the documentation of this file.
4
5namespace CompileScenario
6{
7
8 // The constructor to the scenario class update the size and origin to
9 // coordinate converter, map manager and routemaker so the whole system uses
10 // the same values.
12 int size)
13 : m_Name(name), m_Size(size), m_Origin(origin),
14 m_KeyframeManager(KeyframeManagement::KeyframeManager::Instance())
15 {
19 m_Routemaker = std::make_unique<Routemaker::Routemaker>(
21 }
22
23 // SetOrigin to the scenario class update the size and origin to
24 // coordinate converter, map manager and routemaker so the whole system uses
25 // the same values.
26 void
28 {
29 m_Origin = GeoCoord;
30 m_Size = size;
32 m_Routemaker->UpdateOrigin(
36 }
37
40 {
41 if (m_KeyframeManager.GetKeyframes().empty()) {
42 return m_Routes;
43 }
44
45 m_Routes.clear();
46 auto keyframes = m_KeyframeManager.GetKeyframes();
47 // Keyframes need to be sorted by agentID and timestamp before planning
48 // routes between them.
49 std::sort(keyframes.begin(), keyframes.end(),
51 if (a.AgentId != b.AgentId) {
52 return a.AgentId < b.AgentId;
53 }
54 return a.TimeStamp < b.TimeStamp;
55 });
56 // The routes generated by the routemaker is stored in a map where the
57 // key is the agent ID and the value is a vector with the coordinates
58 // the routemaker returns.
59 for (int i = 0; i < keyframes.size() - 1; i++) {
60 // Check if the current and next keyframe belongs to the same agent
61 // and search for the agent Id in the map. If this is the first
62 // agent with this ID the routes will be inserted as a new element
63 // in the map. If the agent ID is already in the map, the returned
64 // values from the routemaker will be pushed back into the place for
65 // the agent ID to the agent.
66 if (keyframes[i].AgentId == keyframes[i + 1].AgentId) {
67 auto iter = m_Routes.find(keyframes[i].AgentId);
68 if (iter == m_Routes.end()) {
69 std::vector<std::vector<Core::CartesianCoordinate>> vec;
70 vec.push_back(m_Routemaker->MakeRoute(keyframes[i],
71 keyframes[i + 1]));
72 m_Routes.insert(std::make_pair(keyframes[i].AgentId, vec));
73 } else {
74 iter->second.push_back(m_Routemaker->MakeRoute(
75 keyframes[i], keyframes[i + 1]));
76 }
77 }
78 }
79
80 return m_Routes;
81 }
82
83 void
84 Scenario::AddAgent(Core::Agent newAgent)
85 {
86 m_Agents.push_back(newAgent);
87 }
88
89 void
90 Scenario::save(std::string filename)
91 {
92 Json::serialize(filename, this);
93 }
94
95 void
96 Scenario::load(std::string filename)
97 {
98 Json::deserialize(filename, this);
99 SetOrigin(m_Origin, m_Size);
100 }
101
102} // namespace CompileScenario
KeyframeManagement::KeyframeManager & m_KeyframeManager
Definition: scenario.h:73
std::unique_ptr< Routemaker::Routemaker > m_Routemaker
Definition: scenario.h:76
RouteMap & Compile()
Compiles the scenario into a map of routes.
Definition: scenario.cpp:39
Core::GeographicalCoordinate m_Origin
Definition: scenario.h:78
std::map< int, std::vector< std::vector< Core::CartesianCoordinate > > > RouteMap
Definition: scenario.h:25
Scenario(std::string name, Core::GeographicalCoordinate origin, int size)
Constructs a new Scenario object with the given name, origin, and size.
Definition: scenario.cpp:11
void SetOrigin(Core::GeographicalCoordinate GeoCoord, int size)
Sets the origin of the scenario to the given geographical coordinates and size.
Definition: scenario.cpp:27
static void ResetOrigin(Core::GeographicalCoordinate geoCoord, int size)
Sets the origin coordinate to use with relative coordinates.
static Core::UTMCoordinate GeographicToUTM(Core::GeographicalCoordinate GeoCoord)
Function used to convert a geographical coordinate to a UTM coordinate.
std::vector< Core::Keyframe > & GetKeyframes()
Returns a reference to the list of keyframes.
static void GetMap(Core::UTMCoordinate coord, int size)
Retrieves the map from Kartverket for the specified UTM coordinate and size.
Definition: map_manager.cpp:17
void deserialize(std::string filename, ISValue *p)
Function to start deserializing a file.
Definition: serializer.cpp:235
void serialize(std::string filename, ISValue *p)
Function to start serializing an onbject.
Definition: serializer.cpp:206
A structure that represents a geographic coordinate.
Definition: types.h:29
A structure representing an agent's position in cartesian space at a given point in time.
Definition: types.h:69
float TimeStamp
Definition: types.h:77