Skip to content

Commit

Permalink
Get file paths from command line arguments #18
Browse files Browse the repository at this point in the history
A file path must be provided for the scene config file, whereas only an
image name needs to be provided for the output image file.
  • Loading branch information
smercer10 committed Feb 28, 2024
1 parent 6fcc0ae commit 199537f
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions apps/raydiance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,49 @@
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
#include <unistd.h>

int main() {
std::ofstream imgOut{file::openOutStream("img")};
int main(int argc, char *argv[]) {
std::string sceneConfigPath;
std::string imgOutName;

// Get file paths from command line arguments
int opt;
while ((opt = getopt(argc, argv, "s:o:")) != -1) {
switch (opt) {
case 's':
sceneConfigPath = optarg;
break;
case 'o':
imgOutName = optarg;
break;
default:
std::cerr << "Invalid option.\n\n"
<< "Usage: raydiance -s <scene config file path> [-o <output image name>]\n";
return 1;
}
}

if (sceneConfigPath.empty()) {
std::cerr << "Scene config file is required.\n\n"
<< "Usage: vb2c -s <scene config file path> [-o <output image name>]\n";
return 1;
}

// The default output image name is "img"
if (imgOutName.empty()) {
imgOutName = "img";
}

std::ofstream imgOut{file::openOutStream(imgOutName)};

std::ifstream sceneConfigFile{sceneConfigPath};

if (!imgOut.is_open()) {
std::cerr << "Failed to open file for writing.\n";
return 1;
}

std::ifstream sceneConfigFile{"scene.json"};

if (!sceneConfigFile.is_open()) {
std::cerr << "Failed to open scene config file.\n";
return 1;
Expand Down

0 comments on commit 199537f

Please sign in to comment.