From 0f05d361bf2c507f7a77beb9070d61f0e3c0224c Mon Sep 17 00:00:00 2001 From: Yoel <s73017@beuth-hochschule.de> Date: Wed, 2 Sep 2020 13:25:49 +0200 Subject: [PATCH] Added a setPixel function and replaced expression in setPixels with the new function --- RayTracer/sampling/Image.cpp | 6 +++++- RayTracer/sampling/Image.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/RayTracer/sampling/Image.cpp b/RayTracer/sampling/Image.cpp index 696c102..09d0930 100644 --- a/RayTracer/sampling/Image.cpp +++ b/RayTracer/sampling/Image.cpp @@ -1,5 +1,6 @@ #include "Image.h" +#include "../tools/Threadpool.h" #include "StratifiedSampler.h" namespace util { @@ -9,10 +10,13 @@ Image::Image(int width, int height) : width(width), height(height) { vec.insert(vec.end(), color); } } +void Image::setPixel(int x, int y, Vec3 color) { + vec[width * y + x] = color; +} void Image::setPixels(std::shared_ptr<Sampler> sampler) { for (int x = 0; x != width; x++) { for (int y = 0; y != height; y++) { - vec[width * y + x] = sampler->color(x, y); + setPixel(x, y, sampler->color(x, y)); } } } diff --git a/RayTracer/sampling/Image.h b/RayTracer/sampling/Image.h index 1c783dd..673026d 100644 --- a/RayTracer/sampling/Image.h +++ b/RayTracer/sampling/Image.h @@ -11,6 +11,7 @@ class Image { public: Image(int width, int height); + void setPixel(int x, int y, Vec3 color); void setPixels(std::shared_ptr<Sampler> sampler); Vec3 operator[](const std::array<int, 2>& i) const; // int x, int y @@ -20,7 +21,7 @@ class Image { const int height; private: - std::vector<util::Vec3> vec; + std::vector<Vec3> vec; }; Image raytrace(const cam::CamObs& cam, const std::shared_ptr<Sampler>& sampler, -- GitLab