Skip to content

Commit 9a45917

Browse files
committed
Enable heatmap globally rather than on a per actor basis
1 parent 9a0ecb7 commit 9a45917

File tree

9 files changed

+45
-47
lines changed

9 files changed

+45
-47
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ Below is an annotated example input file which creates a room containing two act
6262
"scale": 100,
6363
"delay": 0,
6464
"bgColor": [0, 0, 0],
65-
"wallColor": [255, 255, 255]
66-
},
67-
65+
"wallColor": [255, 255, 255],
66+
"heatmapEnabled": true <-- Flag denoting whether
67+
}, the heatmap should be
68+
applied to actors
6869
"room": {
6970
"walls": [
7071
[0.5, 0.5, 8.5, 0.5], <-- Walls are defined via their
@@ -84,9 +85,9 @@ Below is an annotated example input file which creates a room containing two act
8485
"radius": 0.05,
8586
"atDestination": false,
8687
"color": [255, 0, 0],
87-
"heatmapEnabled": true <-- Flag denoting whether the
88-
}, actor's colour should change
89-
{ with the heatmap
88+
"heatmapEnabled": true
89+
},
90+
{
9091
"pos": [0.7, 7.3],
9192
"velocity": [0.0789, 0.0444],
9293
"desiredSpeed": 0.6,

external/Actor.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
Actor::Actor(vecType pPos, vecType pVelocity, float pDesiredSpeed, int pPathId,
2929
float pMass, float pRadius, bool pAtDestination,
30-
std::array<int, 3> pColor, bool pHeatmapEnabled)
30+
std::array<int, 3> pColor)
3131
: pos(pPos), velocity(pVelocity), desiredSpeed(pDesiredSpeed),
3232
pathId(pPathId), mass(pMass), radius(pRadius),
33-
atDestination(pAtDestination), color(pColor),
34-
heatmapEnabled(pHeatmapEnabled), destinationIndex(0), bBox({0, 0}) {}
33+
atDestination(pAtDestination), color(pColor),
34+
destinationIndex(0), bBox({0, 0}) {}
3535

3636
SYCL_EXTERNAL vecType Actor::getPos() const { return pos; }
3737

@@ -53,8 +53,6 @@ SYCL_EXTERNAL bool Actor::getAtDestination() const { return atDestination; }
5353

5454
SYCL_EXTERNAL std::array<int, 3> Actor::getColor() const { return color; }
5555

56-
SYCL_EXTERNAL bool Actor::getHeatmapEnabled() const { return heatmapEnabled; }
57-
5856
SYCL_EXTERNAL std::array<int, 2> Actor::getBBox() const { return bBox; }
5957

6058
SYCL_EXTERNAL uint Actor::getSeed() const { return seed; }

external/Actor.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ class Actor {
4646
float radius;
4747
bool atDestination;
4848
std::array<int, 3> color;
49-
bool heatmapEnabled;
5049
std::array<int, 2> bBox;
5150
uint seed;
5251
float force;
5352

5453
public:
5554
Actor(vecType pPos, vecType pVelocity, float pdesiredSpeed, int pPathId,
5655
float pMass, float pRadius, bool pAtDestination,
57-
std::array<int, 3> pColor, bool pHeatmapEnabled);
56+
std::array<int, 3> pColor);
5857

5958
SYCL_EXTERNAL vecType getPos() const;
6059
SYCL_EXTERNAL vecType getVelocity() const;
@@ -65,7 +64,6 @@ class Actor {
6564
SYCL_EXTERNAL float getRadius() const;
6665
SYCL_EXTERNAL bool getAtDestination() const;
6766
SYCL_EXTERNAL std::array<int, 3> getColor() const;
68-
SYCL_EXTERNAL bool getHeatmapEnabled() const;
6967
SYCL_EXTERNAL std::array<int, 2> getBBox() const;
7068
SYCL_EXTERNAL uint getSeed() const;
7169
SYCL_EXTERNAL float getForce() const;

external/DifferentialEq.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ SYCL_EXTERNAL void differentialEq(
2929
int actorIndex,
3030
sycl::accessor<Actor, 1, sycl::access::mode::read_write> actors,
3131
sycl::accessor<std::array<vecType, 2>, 1, sycl::access::mode::read> walls,
32-
sycl::accessor<Path, 1, sycl::access::mode::read> paths) {
32+
sycl::accessor<Path, 1, sycl::access::mode::read> paths,
33+
sycl::accessor<bool, 1, sycl::access::mode::read> heatmapEnabled) {
3334
Actor *currentActor = &actors[actorIndex];
3435

3536
vecType pos = currentActor->getPos();
@@ -138,7 +139,7 @@ SYCL_EXTERNAL void differentialEq(
138139
currentActor->setSeed(randXorShift(seed));
139140

140141
// Color actor according to heatmap
141-
if (currentActor->getHeatmapEnabled()) {
142+
if (heatmapEnabled[0]) {
142143
// theoreticalMax was decided based on observed max forces for a set of
143144
// configurations It may need to be altered based on the max forces of
144145
// your config to create a satisfying heatmap

external/DifferentialEq.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ SYCL_EXTERNAL void differentialEq(
5656
int actorIndex,
5757
sycl::accessor<Actor, 1, sycl::access::mode::read_write> actors,
5858
sycl::accessor<std::array<vecType, 2>, 1, sycl::access::mode::read> walls,
59-
sycl::accessor<Path, 1, sycl::access::mode::read> paths);
59+
sycl::accessor<Path, 1, sycl::access::mode::read> paths,
60+
sycl::accessor<bool, 1, sycl::access::mode::read> heatmapEnabled);
6061

6162
#endif

external/ParseInputFile.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void validateParameters(rapidjson::Document &jsonDoc) {
4343
} else {
4444
auto &config = jsonDoc["config"];
4545
auto configParams = {"width", "height", "scale",
46-
"delay", "wallColor", "bgColor"};
46+
"delay", "wallColor", "bgColor", "heatmapEnabled"};
4747
for (auto p : configParams) {
4848
if (!config.HasMember(p))
4949
missingParameters += std::string(p) + " ";
@@ -54,7 +54,7 @@ void validateParameters(rapidjson::Document &jsonDoc) {
5454

5555
auto actorParams = {"pos", "velocity", "desiredSpeed",
5656
"pathId", "mass", "radius",
57-
"atDestination", "color", "heatmapEnabled"};
57+
"atDestination", "color"};
5858
for (auto &a : jsonDoc["actors"].GetArray()) {
5959
for (auto p : actorParams) {
6060
if (!a.HasMember(p))
@@ -80,7 +80,7 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors,
8080
Room &room, std::vector<Path> &paths, int &WIDTH,
8181
int &HEIGHT, int &SCALE, int &DELAY,
8282
std::array<int, 3> &BGCOLOR,
83-
std::array<int, 3> &WALLCOLOR) {
83+
std::array<int, 3> &WALLCOLOR, bool &HEATMAPENABLED) {
8484
std::ifstream jsonFile(filename);
8585
if (!jsonFile.is_open()) {
8686
throw JSONException("Error opening file " + filename);
@@ -105,6 +105,7 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors,
105105
config["wallColor"][2].GetInt()};
106106
BGCOLOR = {config["bgColor"][0].GetInt(), config["bgColor"][1].GetInt(),
107107
config["bgColor"][2].GetInt()};
108+
HEATMAPENABLED = config["heatmapEnabled"].GetBool();
108109

109110
// Room
110111
auto jsonWalls = jsonDoc["room"]["walls"].GetArray();
@@ -156,9 +157,7 @@ void parseInputFile(std::string filename, std::vector<Actor> &actors,
156157
jsonColor[1].GetInt(),
157158
jsonColor[2].GetInt()};
158159

159-
bool heatmapEnabled = a["heatmapEnabled"].GetBool();
160-
161160
actors.push_back(Actor(pos, velocity, desiredSpeed, pathId, mass,
162-
radius, atDestination, color, heatmapEnabled));
161+
radius, atDestination, color));
163162
}
164163
}

external/ParseInputFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ void validateParameters(rapidjson::Document &jsonDoc);
5050
void parseInputFile(std::string filename, std::vector<Actor> &actors,
5151
Room &room, std::vector<Path> &paths, int &WIDTH,
5252
int &HEIGHT, int &SCALE, int &DELAY,
53-
std::array<int, 3> &BGCOLOR, std::array<int, 3> &WALLCOLOR);
53+
std::array<int, 3> &BGCOLOR, std::array<int, 3> &WALLCOLOR, bool &HEATMAPENABLED);
5454

5555
#endif

scripts/InputFileGenerator.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def main(argv):
8585
"delay": 0,
8686
"bgColor": [0, 0, 0],
8787
"wallColor": [255, 255, 255],
88+
"heatmapEnabled": False
8889
}
8990

9091
fourSquare["room"] = {
@@ -143,8 +144,7 @@ def main(argv):
143144
"mass": 50,
144145
"radius": 0.05,
145146
"atDestination": False,
146-
"color": colors[o],
147-
"heatmapEnabled": False,
147+
"color": colors[o]
148148
}
149149
)
150150
idCounter += 1
@@ -161,6 +161,7 @@ def main(argv):
161161
"delay": 0,
162162
"bgColor": [0, 0, 0],
163163
"wallColor": [255, 255, 255],
164+
"heatmapEnabled": False
164165
}
165166

166167
fourCorridor["room"] = {
@@ -193,7 +194,6 @@ def main(argv):
193194
"radius": 0.05,
194195
"atDestination": False,
195196
"color": [34, 174, 231],
196-
"heatmapEnabled": False,
197197
}
198198
)
199199
for i in range(0, 9):
@@ -208,7 +208,6 @@ def main(argv):
208208
"radius": 0.05,
209209
"atDestination": False,
210210
"color": [251, 255, 0],
211-
"heatmapEnabled": False,
212211
}
213212
)
214213
for i in range(0, 50):
@@ -223,7 +222,6 @@ def main(argv):
223222
"radius": 0.05,
224223
"atDestination": False,
225224
"color": [169, 0, 146],
226-
"heatmapEnabled": False,
227225
}
228226
)
229227
for i in range(0, 50):
@@ -238,7 +236,6 @@ def main(argv):
238236
"radius": 0.05,
239237
"atDestination": False,
240238
"color": [0, 150, 0],
241-
"heatmapEnabled": False,
242239
}
243240
)
244241

@@ -272,6 +269,7 @@ def main(argv):
272269
"delay": 0,
273270
"bgColor": [0, 0, 0],
274271
"wallColor": [255, 255, 255],
272+
"heatmapEnabled": False
275273
}
276274

277275
twoGroups["room"] = {
@@ -298,7 +296,6 @@ def main(argv):
298296
"radius": 0.05,
299297
"atDestination": False,
300298
"color": [251, 255, 0],
301-
"heatmapEnabled": False,
302299
}
303300
)
304301
for i in range(0, 10):
@@ -313,7 +310,6 @@ def main(argv):
313310
"radius": 0.05,
314311
"atDestination": False,
315312
"color": [169, 0, 146],
316-
"heatmapEnabled": False,
317313
}
318314
)
319315

@@ -344,6 +340,7 @@ def main(argv):
344340
"delay": 0,
345341
"bgColor": [0, 0, 0],
346342
"wallColor": [255, 255, 255],
343+
"heatmapEnabled": False
347344
}
348345

349346
twoGroups10000["room"] = {
@@ -367,8 +364,7 @@ def main(argv):
367364
"mass": 50,
368365
"radius": 0.05,
369366
"atDestination": False,
370-
"color": [251, 255, 0],
371-
"heatmapEnabled": False,
367+
"color": [251, 255, 0]
372368
}
373369
)
374370
for i in range(0, 50):
@@ -383,7 +379,6 @@ def main(argv):
383379
"radius": 0.05,
384380
"atDestination": False,
385381
"color": [169, 0, 146],
386-
"heatmapEnabled": False,
387382
}
388383
)
389384

@@ -412,6 +407,7 @@ def main(argv):
412407
"delay": 0,
413408
"bgColor": [0, 0, 0],
414409
"wallColor": [255, 255, 255],
410+
"heatmapEnabled": True
415411
}
416412

417413
tightCorner["room"] = {
@@ -440,8 +436,7 @@ def main(argv):
440436
"mass": 50,
441437
"radius": 0.05,
442438
"atDestination": False,
443-
"color": [34, 174, 231],
444-
"heatmapEnabled": True,
439+
"color": [34, 174, 231]
445440
}
446441
)
447442

@@ -466,6 +461,7 @@ def main(argv):
466461
"delay": 0,
467462
"bgColor": [0, 0, 0],
468463
"wallColor": [255, 255, 255],
464+
"heatmapEnabled": False
469465
}
470466

471467
laneFiltering["room"] = {
@@ -505,7 +501,6 @@ def main(argv):
505501
"radius": 0.05,
506502
"atDestination": False,
507503
"color": [169, 0, 146],
508-
"heatmapEnabled": False,
509504
}
510505
)
511506

@@ -529,6 +524,7 @@ def main(argv):
529524
"delay": 0,
530525
"bgColor": [0, 0, 0],
531526
"wallColor": [255, 255, 255],
527+
"heatmapEnabled": True
532528
}
533529

534530
corridorWidening["room"] = {
@@ -558,7 +554,6 @@ def main(argv):
558554
"radius": 0.1,
559555
"atDestination": False,
560556
"color": [255, 0, 0],
561-
"heatmapEnabled": True,
562557
}
563558
)
564559

@@ -579,6 +574,7 @@ def main(argv):
579574
"delay": 0,
580575
"bgColor": [0, 0, 0],
581576
"wallColor": [255, 255, 255],
577+
"heatmapEnabled": True
582578
}
583579

584580
evacuateRoom["room"] = {
@@ -604,7 +600,6 @@ def main(argv):
604600
"radius": random.uniform(0.04, 0.06),
605601
"atDestination": False,
606602
"color": [34, 174, 231],
607-
"heatmapEnabled": True,
608603
}
609604
)
610605
evacuateRoom["paths"] = [
@@ -627,6 +622,7 @@ def main(argv):
627622
"delay": 0,
628623
"bgColor": [0, 0, 0],
629624
"wallColor": [255, 255, 255],
625+
"heatmapEnabled": True
630626
}
631627

632628
evacuateRoom10000["room"] = {
@@ -652,7 +648,6 @@ def main(argv):
652648
"radius": 0.05,
653649
"atDestination": False,
654650
"color": [34, 174, 231],
655-
"heatmapEnabled": True,
656651
}
657652
)
658653
evacuateRoom10000["paths"] = [
@@ -675,6 +670,7 @@ def main(argv):
675670
"delay": 0,
676671
"bgColor": [0, 0, 0],
677672
"wallColor": [255, 255, 255],
673+
"heatmapEnabled": True
678674
}
679675

680676
evacuateRoom50000["room"] = {
@@ -700,7 +696,6 @@ def main(argv):
700696
"radius": 0.05,
701697
"atDestination": False,
702698
"color": [34, 174, 231],
703-
"heatmapEnabled": True,
704699
}
705700
)
706701
evacuateRoom50000["paths"] = [

0 commit comments

Comments
 (0)