From caad394cfa36de9aeeebf29b21f1ef6264cccd50 Mon Sep 17 00:00:00 2001 From: Miguel Angel Astor Romero Date: Tue, 28 Mar 2017 14:22:39 -0400 Subject: [PATCH] Minor changes. --- main.cpp | 15 +++++++++++---- photon_tracer.cpp | 7 ++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 184ec22..3f97fb6 100644 --- a/main.cpp +++ b/main.cpp @@ -104,15 +104,19 @@ int main(int argc, char ** argv) { cout << "Maximum ray tree depth is " << ANSI_BOLD_YELLOW << g_max_depth << ANSI_RESET_STYLE << "." << endl; // Create the tracer object. - if (g_tracer == WHITTED) { + switch (g_tracer) { + + case WHITTED: cout << "Using " << ANSI_BOLD_YELLOW << "Whitted" << ANSI_RESET_STYLE << " ray tracing." << endl; tracer = static_cast(new WhittedTracer(g_max_depth)); + break; - } else if(g_tracer == MONTE_CARLO) { + case MONTE_CARLO: cout << "Using " << ANSI_BOLD_YELLOW << "Monte Carlo" << ANSI_RESET_STYLE << " path tracing." << endl; tracer = static_cast(new PathTracer(g_max_depth)); + break; - } else if(g_tracer == JENSEN) { + case JENSEN: cout << "Using " << ANSI_BOLD_YELLOW << "Jensen's photon mapping" << ANSI_RESET_STYLE << " with ray tracing." << endl; p_tracer = new PhotonTracer(g_max_depth, g_p_sample_radius, g_cone_filter_k); if (g_photons_file == NULL && g_caustics_file == NULL) { @@ -121,6 +125,7 @@ int main(int argc, char ** argv) { cout << "Building caustics photon map with " << ANSI_BOLD_YELLOW << g_photons / 2 << ANSI_RESET_STYLE << " primary photons per light source." << endl; p_tracer->photon_tracing(scn, g_photons / 2, true); p_tracer->build_photon_map(); + } else { if (g_photons_file != g_caustics_file) { cerr << "Must specify both a photon map file and a caustics file." << endl; @@ -129,9 +134,11 @@ int main(int argc, char ** argv) { p_tracer->build_photon_map(g_photons_file); p_tracer->build_photon_map(g_caustics_file, true); } + tracer = static_cast(p_tracer); + break; - } else { + default: cerr << "Must specify a ray tracer with \"-t\"." << endl; print_usage(argv); return EXIT_FAILURE; diff --git a/photon_tracer.cpp b/photon_tracer.cpp index 53a71be..d368d01 100644 --- a/photon_tracer.cpp +++ b/photon_tracer.cpp @@ -288,8 +288,13 @@ void PhotonTracer::photon_tracing(Scene * s, const size_t n_photons_per_ligth, c void PhotonTracer::build_photon_map(const char * photons_file, const bool caustics) { Photon ph; float x, y, z, dx, dy, dz, r, g, b, rc; - ifstream ifs(photons_file, ios::in); + ifstream ifs; + if (photons_file == NULL) + return; + + ifs.open(photons_file); + if (!ifs.is_open()) { cerr << "Failed to open the file " << photons_file << " for reading." << endl; exit(EXIT_FAILURE);