Parse the program parameters and set them as global variables
| 107 | |
| 108 | // Parse the program parameters and set them as global variables |
| 109 | void parseProgramParameters(int argc, char* argv[]){ |
| 110 | if(argc<2){ // not enough arguments |
| 111 | fprintf(stdout, "Not enough program parameters. \n \n"); |
| 112 | printHelp(); |
| 113 | exit(0); |
| 114 | } |
| 115 | bool filegiven = false; |
| 116 | for (int i = 1; i < argc; i++) { |
| 117 | if (string(argv[i]) == "-f") { |
| 118 | filename = argv[i + 1]; |
| 119 | filename_base = filename.substr(0, filename.find_last_of(".")); |
| 120 | filegiven = true; |
| 121 | if (!file_exists(filename)) {fprintf(stdout, "[Err] File does not exist / cannot access: %s \n", filename.c_str());exit(1);} |
| 122 | i++; |
| 123 | } |
| 124 | else if (string(argv[i]) == "-s") { |
| 125 | gridsize = atoi(argv[i + 1]); |
| 126 | i++; |
| 127 | } else if (string(argv[i]) == "-h") { |
| 128 | printHelp(); exit(0); |
| 129 | } else if (string(argv[i]) == "-o") { |
| 130 | string output = (argv[i + 1]); |
| 131 | transform(output.begin(), output.end(), output.begin(), ::tolower); // to lowercase |
| 132 | if (output == "binvox"){outputformat = OutputFormat::output_binvox;} |
| 133 | else if (output == "morton"){outputformat = OutputFormat::output_morton;} |
| 134 | else if (output == "obj"){outputformat = OutputFormat::output_obj_cubes;} |
| 135 | else if (output == "obj_points") { outputformat = OutputFormat::output_obj_points; } |
| 136 | else if (output == "vox") { outputformat = OutputFormat::output_vox; } |
| 137 | else {fprintf(stdout, "[Err] Unrecognized output format: %s, valid options are binvox (default), morton, obj or obj_points \n", output.c_str());exit(1);} |
| 138 | } |
| 139 | else if (string(argv[i]) == "-cpu") { |
| 140 | forceCPU = true; |
| 141 | } |
| 142 | else if (string(argv[i])=="-solid"){ |
| 143 | solidVoxelization = true; |
| 144 | } |
| 145 | } |
| 146 | if (!filegiven) { |
| 147 | fprintf(stdout, "[Err] You didn't specify a file using -f (path). This is required. Exiting. \n"); |
| 148 | printExample(); exit(1); |
| 149 | } |
| 150 | fprintf(stdout, "[Info] Filename: %s \n", filename.c_str()); |
| 151 | fprintf(stdout, "[Info] Grid size: %i \n", gridsize); |
| 152 | fprintf(stdout, "[Info] Output format: %s \n", OutputFormats[int(outputformat)]); |
| 153 | fprintf(stdout, "[Info] Using CPU-based voxelization: %s (default: No)\n", forceCPU ? "Yes" : "No"); |
| 154 | fprintf(stdout, "[Info] Using Solid Voxelization: %s (default: No)\n", solidVoxelization ? "Yes" : "No"); |
| 155 | } |
| 156 | |
| 157 | int main(int argc, char* argv[]) { |
| 158 | // PRINT PROGRAM INFO |
no test coverage detected