• Jittered采样类定义和测试


    抖动采样算法测试,小图形看不出什么明显区别,还是上代码和测试图吧。

    类声明:

    #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);
    			}
    	}
    } 

    测试结果图:

  • 相关阅读:
    js联系题目
    js运算符
    太极图
    第一周 Welcome
    对 vscode 自动格式化的结果不太满意,我们该如何自己调整直至自己满意为止
    ASP.NET MVC5.0 OutputCache不起效果
    对照实验(1)-批量清理系统临时文件
    ES6
    19.局部变量和全局变量
    18.函数定义和参数
  • 原文地址:https://www.cnblogs.com/dalgleish/p/12602759.html
Copyright © 2020-2023  润新知