From d1a748cea4c1c33d6979c32181ff4a17da9ecd71 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 13 Apr 2022 13:23:25 +0800 Subject: Rename viewport to basic_viewport. Extract interface viewport. --- main_simple_scanner.cpp | 2 +- viewport.h | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp index 6dadf30..06476d8 100644 --- a/main_simple_scanner.cpp +++ b/main_simple_scanner.cpp @@ -19,7 +19,7 @@ void generate_image(uint16_t image_width, uint16_t image_height, double viewport_width, double focal_length, double sphere_z, double sphere_r, const std::string &caption = "", unsigned caption_scale = 1) { double r = 1.0 * image_width / image_height; - viewport vp{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}}; + basic_viewport vp{viewport_width, viewport_width / r, vec3d{0, 0, -focal_length}}; hitlist world; bias_ctx bias{false, 0}; world.add_object(std::make_shared( diff --git a/viewport.h b/viewport.h index 41c86a2..2610ff5 100644 --- a/viewport.h +++ b/viewport.h @@ -25,6 +25,8 @@ class bias_ctx { std::uniform_real_distribution uni{0.0, 1.0}; public: + bias_ctx() : enabled(false) {} + bias_ctx(bool enabled, uint64_t seed = 0UL) : enabled(enabled), mt(std::mt19937_64{seed}) {} void operator()(double &bx, double &by) { @@ -38,17 +40,32 @@ public: } }; +template class viewport { +public: + virtual bitmap render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) = 0; +}; + +using viewport8b = viewport; + +// Single sampled viewport which supports bias sampling +class basic_viewport : public viewport8b { const double half_width, half_height; // viewport size const vec3d center; // coordinate of the viewport center point public: - viewport() = delete; + basic_viewport() = delete; - viewport(double width, double height, vec3d viewport_center) : + basic_viewport(double width, double height, vec3d viewport_center) : half_width(width / 2.0), half_height(height / 2.0), center(viewport_center) {} - /** + virtual bitmap8b + render(const hitlist &world, vec3d viewpoint, uint16_t image_width, uint16_t image_height) override { + bias_ctx bc{}; + return render(world, viewpoint, image_width, image_height, bc); + } + + virtual /** * Generate the image seen on given viewpoint. * @param bx bias on x axis (0.0 <= bx < 1.0) * @param by bias on y axis (0.0 <= by < 1.0) -- cgit v1.2.3