gen3c / gui /src /main.cu
elungky's picture
Initial commit for new Space - pre-built Docker image
28451f7
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @file main.cu
* @author Thomas Müller, NVIDIA
*/
#include <neural-graphics-primitives/testbed.h>
#include <tiny-cuda-nn/common.h>
#include <args/args.hxx>
#include <filesystem/path.h>
using namespace args;
using namespace ngp;
using namespace std;
namespace ngp {
int main_func(const std::vector<std::string>& arguments) {
ArgumentParser parser{
"Gen3C GUI"
"Version " NGP_VERSION,
"",
};
HelpFlag help_flag{
parser,
"HELP",
"Display this help menu.",
{'h', "help"},
};
Flag vr_flag{parser, "VR", "Enables VR", {"vr"}};
ValueFlag<string> snapshot_flag{
parser,
"SNAPSHOT",
"Optional snapshot to load upon startup.",
{"snapshot", "load_snapshot"},
};
ValueFlag<uint32_t> width_flag{
parser,
"WIDTH",
"Resolution width of the GUI.",
{"width"},
};
ValueFlag<uint32_t> height_flag{
parser,
"HEIGHT",
"Resolution height of the GUI.",
{"height"},
};
Flag version_flag{
parser,
"VERSION",
"Display the version of Gen3C GUI.",
{'v', "version"},
};
PositionalList<string> files{
parser,
"files",
"Files to be loaded. Can be a scene, network config, snapshot, camera path, or a combination of those.",
};
// Parse command line arguments and react to parsing
// errors using exceptions.
try {
if (arguments.empty()) {
tlog::error() << "Number of arguments must be bigger than 0.";
return -3;
}
parser.Prog(arguments.front());
parser.ParseArgs(begin(arguments) + 1, end(arguments));
} catch (const Help&) {
cout << parser;
return 0;
} catch (const ParseError& e) {
cerr << e.what() << endl;
cerr << parser;
return -1;
} catch (const ValidationError& e) {
cerr << e.what() << endl;
cerr << parser;
return -2;
}
if (version_flag) {
tlog::none() << "Gen3C GUI v" NGP_VERSION;
return 0;
}
Testbed testbed{ETestbedMode::Gen3c};
for (auto file : get(files)) {
testbed.load_file(file);
}
#ifdef NGP_GUI
bool gui = true;
#else
bool gui = false;
#endif
if (gui) {
testbed.init_window(width_flag ? get(width_flag) : 1920, height_flag ? get(height_flag) : 1080);
}
if (vr_flag) {
testbed.init_vr();
}
// Render loop
while (testbed.frame()) {}
return 0;
}
} // namespace ngp
#ifdef _WIN32
int wmain(int argc, wchar_t* argv[]) {
SetConsoleOutputCP(CP_UTF8);
#else
int main(int argc, char* argv[]) {
#endif
try {
std::vector<std::string> arguments;
for (int i = 0; i < argc; ++i) {
#ifdef _WIN32
arguments.emplace_back(ngp::utf16_to_utf8(argv[i]));
#else
arguments.emplace_back(argv[i]);
#endif
}
return ngp::main_func(arguments);
} catch (const exception& e) {
tlog::error() << fmt::format("Uncaught exception: {}", e.what());
return 1;
}
}