-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
42 lines (37 loc) · 1.31 KB
/
example.cpp
File metadata and controls
42 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
void createDirectoryIfNotExists(const string& dirPath)
{
string cmd = "mkdir -p " + dirPath;
int ret = system(cmd.c_str());
if (ret == -1)
{
//handle error
}
}
static int counter = 0;
void House::montage(const string& algoName, const string& houseName) const
{
vector<string> tiles;
for (size_t row = 0; row < _rows; ++row)
{
for (size_t col = 0; col < _cols; ++col)
{
if (_house[row][col] == ' ')
tiles.push_back("0");
else
tiles.push_back(string() + _house[row][col]);
}
}
string imagesDirPath = "simulations/" + algoName + "_" + houseName;
createDirectoryIfNotExists(imagesDirPath);
string counterStr = to_string(counter++);
string composedImage = imagesDirPath + "/image" + string(5-counterStr.length(), '0') + counterStr + ".jpg";
Montage::compose(tiles, _cols, _rows, composedImage);
}
//.... To Encode images into video:
string simulationDir = "simulations/" + algoName + "_" + houseName + "/";
string imagesExpression = simulationDir + "image%5d.jpg";
Encoder::encode(imagesExpression, algoName + "_" + houseName + ".mpg");
//don't forget to remove the images after the video is created...