抖动采样算法测试,小图形看不出什么明显区别,还是上代码和测试图吧。
类声明:
#pragma once #ifndef __JITTERED_HEADER__ #define __JITTERED_HEADER__ #include "sampler.h" class Jittered:public Sampler { public: Jittered(); ~Jittered(); Jittered(const integer samps); Jittered(const integer samps, const integer sets); Jittered(const Jittered& ji); Jittered& operator=(const Jittered& ji); virtual Sampler* clone() const; virtual void generate_samples(); }; #endif
类实现:
#include "pch.h" #include "jittered.h" Jittered::Jittered() :Sampler() { generate_samples(); } Jittered::~Jittered() {} Jittered::Jittered(const integer samps) : Sampler(samps) { generate_samples(); } Jittered::Jittered(const integer samps, const integer sets) : Sampler(samps, sets) { generate_samples(); } Jittered::Jittered(const Jittered& ji) : Sampler(ji) { generate_samples(); } Jittered& Jittered::operator=(const Jittered& ji) { if (this == &ji) return *this; Sampler::operator=(ji); return *this; } Sampler* Jittered::clone() const { return new Jittered(*this); } void Jittered::generate_samples() { integer n = (integer)std::sqrt((ldouble)nsamples); for (integer p = 0; p < nsets; p++) { for (integer i = 0; i < n; i++) for (integer j = 0; j < n; j++) { Point2 sp((j + random_ldouble()) / n, (i + random_ldouble()) / n); //抖动算法核心 samples.push_back(sp); } } }
测试结果图: