19 #include <nori/block.h>
21 #include <filesystem/path.h>
22 #include <indicators/progress_bar.hpp>
27 bool run_gui(std::string filename,
bool is_xml) {
35 nanogui::ref<NoriScreen> screen =
new NoriScreen(block);
37 if (filename.length() > 0) {
40 screen->openXML(filename);
43 screen->openEXR(filename);
47 nanogui::mainloop(50.f);
52 }
catch (
const std::exception &e) {
53 cerr <<
"Fatal error: " << e.what() << endl;
61 bool render_headless(std::string filename,
bool is_xml) {
66 if (!filename.length()) {
67 cerr <<
"Need to provide an input XML file to render in headless mode" << endl;
72 cerr <<
"Only XML files supported in the headless mode" << endl;
78 renderer.renderScene(filename);
81 indicators::ProgressBar bar{
82 indicators::option::PrefixText{
"Rendering... "},
83 indicators::option::BarWidth{50},
84 indicators::option::ShowPercentage{
true},
85 indicators::option::ShowElapsedTime{
true},
86 indicators::option::ShowRemainingTime{
true}
88 while (renderer.isBusy()) {
89 bar.set_progress(renderer.getProgress() * 100);
90 std::this_thread::sleep_for(std::chrono::seconds(1));
93 while (renderer.isBusy()) {
94 std::this_thread::sleep_for(std::chrono::seconds(1));
99 catch (
const std::exception &e) {
100 cerr <<
"Failed to render in the headless mode " << e.what() << endl;
108 int main(
int argc,
char **argv) {
109 std::string filename =
"";
110 bool headless =
false;
112 for (
int i = 1; i < argc; ++i) {
113 std::string token(argv[i]);
114 if (token ==
"--help") {
115 cout <<
"Syntax: " << argv[0] <<
"[-b] <scene.[xml|exr]>" << endl;
119 if (token ==
"-b" || token ==
"--background") {
124 if (!filename.length()) {
128 cerr <<
"Syntax: " << argv[0] <<
"[-b] <scene.[xml|exr]>" << endl;
134 if (filename.length()) {
135 filesystem::path path(filename);
137 if (path.extension() ==
"xml") {
139 }
else if (path.extension() ==
"exr") {
143 cerr <<
"Error: unknown file \"" << filename
144 <<
"\", expected an extension of type .xml or .exr" << endl;
150 cout <<
"Forcing background mode" << endl;
156 return render_headless(filename, is_xml);
158 return run_gui(filename, is_xml);
Weighted pixel storage for a rectangular subregion of an image.