forked from krishnatoshniwal/style-transfer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmplocations.cpp
executable file
·107 lines (94 loc) · 3.32 KB
/
bmplocations.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Created by krishna on 4/28/18.
//
#include "bmplocations.h"
namespace BmpLocations {
std::string styleBmpLoc, contentBmpLoc, outputBmpLoc;
int contentNum = 0, numContent = 1;
void SetLocs() {
std::string dataPath = "./images/";
styleBmpLoc = dataPath + "style";
contentBmpLoc = dataPath + "content";
outputBmpLoc = dataPath + "output";
}
void GetStyleBmpLocs(vector<std::string> &fileLocs, vector<std::string> &fileNames) {
SetLocs();
ReadFilesFromLoc(styleBmpLoc, fileLocs, fileNames);
}
void GetContentBmpLoc(std::string &fileLoc, std::string &fileName) {
SetLocs();
vector<std::string> fileLocs, fileNames;
ReadFilesFromLoc(contentBmpLoc, fileLocs, fileNames);
numContent = fileLocs.size();
fileLoc = fileLocs[contentNum];
fileName = fileNames[contentNum];
}
void GetOutputBmpLoc(std::string &fileLoc, std::string &fileName) {
SetLocs();
ReadFileFromLoc(outputBmpLoc, fileLoc, fileName);
}
void ReadFilesFromLoc(const std::string &path, vector<std::string> &fileLocs, vector<std::string> &fileNames) {
/**
* Uses functions from dirent.h
* Reads all the files stored in a given location and returns a vector object
* of all the paths as strings
*/
fileLocs.clear();
fileNames.clear();
DIR *dir;
dirent *pdir;
// Read the file dirs
dir = opendir(path.c_str());
// std::string currentDir = get_current_dir_name();
// std::cout << currentDir;
while (pdir = readdir(dir)) {
fileLocs.push_back(pdir->d_name);
}
RemoveDotDotDot(fileLocs);
fileNames = fileLocs;
for (auto &file:fileLocs) {
// append the path to the file loc
file = path + '/' + file;
}
}
void ReadFileFromLoc(const std::string &path, std::string &fileLoc, std::string &fileName) {
/**
* Reads all the files in the path and returns the first file in the path
* Useful when you only want to read one file
*/
vector<std::string> fileLocs, fileNames;
ReadFilesFromLoc(path, fileLocs, fileNames);
fileLoc = fileLocs[0];
fileName = fileNames[0];
}
// void ReadContentBmp(const std::string &path, std::string &fileLoc, std::string &fileName, int num){
// vector<std::string> fileLocs, fileNames;
// ReadFilesFromLoc(path, fileLocs, fileNames);
// fileLoc = fileLocs[num];
// fileName = fileNames[num];
// }
void RemoveDotDotDot(vector<std::string> &files) {
/**
* Removes ./ and ../ items from a given directory
*/
std::string dotFile = ".", dotdotFile = "..";
for (auto fi = files.begin(); fi != files.end(); fi++) {
if (dotFile == *fi) {
files.erase(fi);
break;
}
}
for (auto fi = files.begin(); fi != files.end(); fi++) {
if (dotdotFile == *fi) {
files.erase(fi);
break;
}
}
}
void IncrementContentNum() {
contentNum = (contentNum + 1) % numContent;
}
void DecrementContentNum() {
contentNum = (contentNum - 1 + numContent) % numContent;
}
}