类声明:

#pragma once
#ifndef __NROOKS_HEADER__
#define __NROOKS_HEADER__ #include "sampler.h" class NRooks :public Sampler {
public:
NRooks();
~NRooks();
NRooks(const integer samps);
NRooks(const integer samps, const integer sets);
NRooks(const NRooks& nr);
NRooks& operator=(const NRooks& nr);
virtual Sampler* clone() const;
virtual void generate_samples();
private:
void shuffled_x_coordinates();
void shuffled_y_coordinates();
};
#endif

类实现:

#include "pch.h"
#include "nrooks.h" NRooks::NRooks() :Sampler() {
generate_samples();
} NRooks::~NRooks() {} NRooks::NRooks(const integer samps) :Sampler(samps) {
generate_samples();
} NRooks::NRooks(const integer samps, const integer sets) : Sampler(samps, sets) {
generate_samples();
} NRooks::NRooks(const NRooks& nr) : Sampler(nr) {
generate_samples();
} NRooks& NRooks::operator=(const NRooks& nr) {
if (this == &nr)
return *this;
Sampler::operator=(nr);
return *this;
} Sampler* NRooks::clone() const {
return new NRooks(*this);
} void NRooks::generate_samples() {
for (integer i = 0; i < nsets; i++)
for (integer j = 0; j < nsamples; j++) {
Point2 sp((j + random_ldouble()) / nsamples, (j + random_ldouble()) / nsamples);
samples.push_back(sp);
}
shuffled_x_coordinates();
shuffled_y_coordinates();
} void NRooks::shuffled_x_coordinates() {
for (integer i = 0; i < nsets; i++)
for (integer j = 0; j < nsamples - 1; j++) {
integer k = random_integer() % nsamples + i * nsamples;
std::swap(samples[i * nsamples + j + 1].x, samples[k].x);
}
} void NRooks::shuffled_y_coordinates() {
for (integer i = 0; i < nsets; i++)
for (integer j = 0; j < nsamples - 1; j++) {
integer k = random_integer() % nsamples + i * nsamples;
std::swap(samples[i * nsamples + j + 1].y, samples[k].y);
}
}

  

测试结果图:

NRooks采样类定义和测试的更多相关文章

  1. Regular采样类定义和测试

    这个算法是均匀采样算法,继承于Sampler类. 类声明: #pragma once #ifndef __REGULAR_HEADER__ #define __REGULAR_HEADER__ #in ...

  2. Jittered采样类定义和测试

    抖动采样算法测试,小图形看不出什么明显区别,还是上代码和测试图吧. 类声明: #pragma once #ifndef __JITTERED_HEADER__ #define __JITTERED_H ...

  3. PureRandom采样类定义和测试

    此是随机采样算法,效果感觉一般般. 类声明: #pragma once #ifndef __PURERANDOM_HEADER__ #define __PURERANDOM_HEADER__ #inc ...

  4. Hammersley采样类定义和测试

    原理参照书籍 类声明: #pragma once #ifndef __HAMMERSLEY_HEADER__ #define __HAMMERSLEY_HEADER__ #include " ...

  5. MultiJittered采样类定义和测试

    多重抖动在书上说的是水平和竖直方面随机交换. 类声明: #pragma once #ifndef __MULTIJITTERED_HEADER__ #define __MULTIJITTERED_HE ...

  6. Sampler类定义

    此是所有采样的基类,这样定义的好处是,我们可以分别测试每一个采样算法. 类定义: #pragma once #ifndef __SAMPLER_HEADER__ #define __SAMPLER_H ...

  7. 开涛spring3(12.4) - 零配置 之 12.4 基于Java类定义Bean配置元数据

    12.4  基于Java类定义Bean配置元数据 12.4.1  概述 基于Java类定义Bean配置元数据,其实就是通过Java类定义Spring配置元数据,且直接消除XML配置文件. 基于Java ...

  8. python类定义

    在我的收藏中有一篇特别详细的类讲解 此处部分内容引自:http://blog.sina.com.cn/s/blog_59b6af690101bfem.html class myclass: 'this ...

  9. 20175312 2018-2019-2 《Java程序设计》第6周课下选做——类定义

    20175312 2018-2019-2 <Java程序设计>第6周课下选做--类定义 设计思路 1.我觉得Book其实就是一个中转的作用,由测试类Bookself通过Book输入数据,然 ...

随机推荐

  1. 好客租房56-props深入(3props校验-约束规则)

    1常见类型:Array,bool,func,number,object,string 2React:element 3必填项:isRequred 4特定结构的想:shape({}) //导入react ...

  2. 104_Power Query 数据库条件查询

    博客:www.jiaopengzi.com 焦棚子的文章目录 请点击下载 1.应用场景 底层数据在数据库(sql server数据库,其他数据库同理,下文不再说明.)中,Excel中有查询的字段,需要 ...

  3. 自学c语言

    C 语言是一种通用的.面向过程式的计算机程序设计语言. 当前最新的 C 语言标准为 C18 前期准备 C 编译器  写在源文件中的源代码是人类可读的源.它需要"编译",转为机器语言 ...

  4. 【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed

    问题描述 使用Azure Storage Account的共享访问签名(Share Access Signature) 生成的终结点,连接时遇见  The Azure Storage endpoint ...

  5. 浏览器上写代码,4核8G微软服务器免费用,Codespaces真香

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 一图胜千言 先上图,下面是欣宸在自己的iPad Pro ...

  6. 2021.03.20【NOIP提高B组】模拟 总结

    区间 DP 专场:愉快爆炸 T1 题目大意 有 \(n\) 个有颜色的块,连续 \(k\) 个相同颜色的就可以消掉 现在可以在任意位置插入任意颜色的方块,问最少插入多少个可以全部抵消 题解 先把连续的 ...

  7. iNeuOS工业互联网操作系统,在线报表(Excel)开发工具

    目       录 1.      概述... 2 2.      视频介绍... 2 3.      应用过程... 2 1.   概述 iNeuOS工业互联网操作系统在线报表(Excel)工具的开 ...

  8. 爱快在PVE下不定时反复重启死机的解决方法

    太长不看版本: 爱快3.6.X在PVE乃至于ESXI下都存在一定的兼容问题! 官网下载3.6.X安装后进入系统设置-升级备份-版本升级,使用爱快3.4.9bin升降级包,下载其中的bin升降级包,将爱 ...

  9. QT软件工程师招聘市场需求报告

    QT软件工程师招聘市场需求报告 目录 最流行的编程语言排行榜 QT软件工程师职位需求 QT软件工程师薪资待遇 QT软件工程师行业需求 QT软件工程师QT技术需求 QT软件工程师基础技术需求 QT软件工 ...

  10. 关于使用koa 跨域问题你可能会遇到

    var cors = require('koa2-cors');// 跨域const allowOrigins = ["http://localhost:8080" // 需要跨域 ...