-
Notifications
You must be signed in to change notification settings - Fork 3
/
Options.cpp
174 lines (159 loc) · 5.05 KB
/
Options.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// Created by dongmin on 18. 7. 17.
//
#include "Options.h"
#include <getopt.h>
#include <iostream>
#include <cassert>
Options* Options::instance = NULL;
void Options::make_file_name(){
if (!has_input_type){
string file_extension = input_file.substr(input_file.find_last_of(".") + 1);
if (file_extension == "tvr" || file_extension == "TVR"){
input_type = 1;
}
else if (file_extension == "3ds" || file_extension == "3DS"){
input_type = 2;
}
else if (file_extension == "dae" || file_extension == "DAE"){
input_type = 3;
}
}
std::size_t pos = input_file.find_last_of(".");
file_name = input_file.substr(0, pos);
fprintf(stdout, "File name : %s\n",file_name.c_str());
output_dir += file_name;
output_dir += "/";
output_dir += version;
output_dir += "/";
}
void Options::check_options() {
if (!has_input_dir){
throw std::runtime_error("--input-dir is missing..;\n");
}
if (!has_output_dir){
throw std::runtime_error("--output-dir missing : where can I store..\n");
}
if (!has_input_type){
fprintf(stderr, "WARNING : we will detect your file type and covert. Maybe it will be right..\n");
fprintf(stderr, "IF you can make it sure, define value of --input-type option.\n\n");
}
}
void Options::make(int argc, char **argv) {
const char *short_opts = "i:O:v:r:tp:a:b:TDLI:GA:VC";
const option long_opts[] = {
{"input-dir", 1, 0, 'i'},
{"output-dir", 1, 0, 'O'},
{"version", 1, 0, 'v'},
{"input-type", 1, 0, 'r'},
{"no-merge", 0, 0, 't'},
{"polygonizer", 1, 0, 'p'},
{"thres1" , 1, 0, 'a'},
{"thres2", 1, 0, 'b'},
{"output-tvr", 0, 0, 'T'},
{"output-3ds", 0, 0, 'D'},
{"output-tri", 0, 0, 'L'},
{"indoorGML" , 1, 0, 'I'},
{"write-process",0,0, 'G'},
{"select-arch", 1, 0, 'A'},
{"do-validation", 0, 0, 'V'},
{"do-classification", 0, 0, 'C'},
{0, 0, 0, 0}
};
int index = 0;
int c;
while (-1 != (c = getopt_long(argc, argv, short_opts, long_opts, &index))){
string type_name;
switch (c){
case 'i':
assert(optarg != NULL);
input_dir = optarg;
if (input_dir.back() != '/'){
input_dir.append("/");
}
has_input_dir = true;
break;
case 'O':
assert(optarg != NULL);
output_dir = optarg;
if (output_dir.back() != '/'){
output_dir.append("/");
}
has_output_dir = true;
break;
case 'r':
assert(optarg != NULL);
type_name = optarg;
has_input_type = true;
if (type_name == "tvr" || type_name == "TVR"){
input_type = 1;
}
else if (type_name == "3ds" || type_name == "3DS"){
input_type = 2;
}
else if (type_name == "dae" || type_name == "DAE" || type_name == "collada" || type_name == "COLLADA"){
input_type = 3;
}
else{
printf("\n");
printf("Import mode should be one type of {tvr, 3ds, collada}");
printf("\n");
}
break;
case 'v':
version = optarg;
break;
case 't':
has_no_merge = true;
break;
case 'p':
has_polygonizer = true;
polygonizer_mode = stoi(optarg);
break;
case 'a':
assert(optarg != NULL);
threshold_1 = strtod(optarg, NULL);
break;
case 'b':
assert(optarg != NULL);
threshold_2 = strtod(optarg, NULL);
break;
case 'T':
break;
case 'D':
break;
case 'G':
generator = true;
break;
case 'A':
assert(optarg != NULL);
selected = stoi(optarg);
break;
case 'L':
break;
case 'V':
do_validation = 1;
break;
case 'I':
output_indoor_gml = true;
infactory_url = optarg;
break;
case 'C':
do_classification = true;
break;
}
}
if (optind < argc)
{
input_file = argv[optind++];
}
else{
fprintf(stderr, "There is no input file name..\n");
exit(EXIT_FAILURE);
}
if (optind < argc){
fprintf(stderr, "Only one file is needed\n");
}
check_options();
make_file_name();
}