From d802e8367e7709966747efbe57c90f1b8a08f83b Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 13 Apr 2022 14:52:46 +0800 Subject: Use basic_viewport8b if antialiasing is not enabled. --- main_simple_scanner.cpp | 12 +++++++++--- viewport.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp index eaaa8b7..bd870d7 100644 --- a/main_simple_scanner.cpp +++ b/main_simple_scanner.cpp @@ -26,7 +26,12 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport std::cerr << "Antialiasing Samples: " << samples << std::endl; } double r = 1.0 * image_width / image_height; - aa_viewport8b vp{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}, samples}; + viewport8b *vp; + if (samples == 1) { + vp = new basic_viewport8b{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}}; + } else { + vp = new aa_viewport8b{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}, samples}; + } hitlist8b world; world.add_object(std::make_shared( vec3d{0, -100.5, -1}, @@ -34,8 +39,8 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport world.add_object(std::make_shared(vec3d{0, 0, sphere_z}, sphere_r)); timer tm; tm.start_measure(); - auto image = vp.render(world, vec3d::zero(), - image_width, image_height); // camera position as the coordinate origin + auto image = vp->render(world, vec3d::zero(), + image_width, image_height); // camera position as the coordinate origin tm.stop_measure(); if (!caption.empty()) { image.print(caption, @@ -47,6 +52,7 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport } else { std::cerr << "NOPRINT is defined. PPM Image won't be printed." << std::endl; } + delete vp; } int main(int argc, char **argv) { diff --git a/viewport.h b/viewport.h index b4e4e56..74bdfcd 100644 --- a/viewport.h +++ b/viewport.h @@ -44,6 +44,7 @@ template class viewport { public: virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0; + virtual ~viewport() = default; }; using viewport8b = viewport; -- cgit v1.2.3