-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain_automate_add_texture.cpp
122 lines (87 loc) · 3.16 KB
/
main_automate_add_texture.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <iosfwd>
#include <fstream>
#include <stdlib.h>
#include <sstream>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include "utils/map_object_label2training_label.h"
using namespace std;
void getFilesInDirectory(std::string& dirName, std::vector<std::string>& fileNames)
{
if ( !boost::filesystem::exists(dirName))
return;
boost::filesystem::path targetDir(dirName);
boost::filesystem::directory_iterator iter(targetDir), eod;
BOOST_FOREACH(boost::filesystem::path const& i, make_pair(iter, eod))
{
if (is_regular_file(i))
{
fileNames.push_back(i.string());
}
}
}
int main(void)
{
srand(time(NULL));
//for(int i = 1 ; i < 12; i++ )
int i =1;
{
char fileName[100];
// sprintf(fileName,"/home/ankur/livingroom/previous_mtls/livingroom%d.mtl",i);
sprintf(fileName,"/home/dysondemo/workspace/SceneNetBasisModels/bedroom/room_layout/bedroom%d_layout.mtl",i);
ifstream ifile(fileName);
sprintf(fileName,"bedroom%d_layout.mtl",i);
ofstream ofile(fileName);
std::string cmd, matname;
if (ifile.is_open())
{
char readlinedata[300];
std::string previous_line;
while(1)
{
ifile.getline(readlinedata,300);
if ( ifile.eof() )
{
break;
}
istringstream iss(readlinedata);
std::string current_line(readlinedata);
std::vector<std::string> filesinDir;
std::string base_dir;
if ( current_line.find("newmtl") != std::string::npos)
{
iss >> cmd;
iss >> matname;
std::cout<<matname<<" -> ";
matname = get_class_name(matname);
std::transform(matname.begin(),
matname.end(),
matname.begin(),
::tolower);
std::cout<<matname<<std::endl;
base_dir = "/home/dysondemo/workspace/code/texture_library/" + matname;
getFilesInDirectory(base_dir,filesinDir);
}
ofile << current_line << std::endl;
if ( current_line.find("newmtl") != std::string::npos )
{
if ( filesinDir.size())
{
int random_texture = ((float)rand()/RAND_MAX)*(filesinDir.size()-1);
std::cout<<filesinDir.at(random_texture) << std::endl;
ofile << "map_Kd "<< filesinDir.at(random_texture) << std::endl;
}
else
{
ofile << "map_Kd /home/dysondemo/workspace/code/texture_library/duvet/5634339c2263c3d69c2b4838bd5d80cc.jpg" << std::endl;
}
}
previous_line = current_line;
}
}
ifile.close();
ofile.close();
}
}