此是所有采样的基类,这样定义的好处是,我们可以分别测试每一个采样算法。

类定义:

#pragma once
#ifndef __SAMPLER_HEADER__
#define __SAMPLER_HEADER__ #include "../utilities/geometry.h" class Sampler {
public:
Sampler();
virtual ~Sampler();
Sampler(const integer samps);
Sampler(const integer samps, const integer sets);
Sampler(const Sampler& s);
virtual Sampler* clone() const = 0;
virtual void generate_samples() = 0;//这个设置为纯虚函数,书中没有这样做,我们这样做是方便之后动态调整采样数量
virtual Point3 sample_unit_square();
void setup_shuffled_indices();
void set_num_sets(const integer sets);
integer get_num_sets() const;
void set_num_samples(const integer samps);
integer get_num_samples() const;
void clear();
Sampler& operator=(const Sampler& s);
protected:
integer nsamples;
integer nsets;
std::vector<Point3> samples;//这里采用Point3,兼容所有的采样算法
std::vector<integer> shuffled_indices;
integer count;
integer jump;
};
#endif

  

类实现:

#include "pch.h"
#include "sampler.h" Sampler::Sampler() :nsamples(16), nsets(36), count(0), jump(0) {
setup_shuffled_indices();
} Sampler::~Sampler() {} Sampler::Sampler(const integer samps) : nsamples(samps), nsets(36), count(0), jump(0) {
setup_shuffled_indices();
} Sampler::Sampler(const integer samps, const integer sets)
: nsamples(samps), nsets(sets), count(0), jump(0) {
setup_shuffled_indices();
} Sampler::Sampler(const Sampler& s)
: nsamples(s.nsamples), nsets(s.nsets), count(s.count), jump(s.jump),
samples(s.samples), shuffled_indices(s.shuffled_indices) {} Point3 Sampler::sample_unit_square() {
if (count % nsamples == 0)
jump = (random_integer() % nsets) * nsamples;
return (samples[jump + shuffled_indices[jump + count++ % nsamples]]);
} void Sampler::setup_shuffled_indices() {
shuffled_indices.reserve(nsamples * nsets);
std::vector<integer> indices;
for (integer i = 0; i < nsamples; i++)
indices.push_back(i);
for (integer i = 0; i < nsets; i++) {
random_shuffle(indices.begin(), indices.end());
shuffled_indices.insert(shuffled_indices.end(), indices.begin(), indices.end());
}
} void Sampler::set_num_sets(const integer sets) {
nsets = sets;
} integer Sampler::get_num_sets() const {
return nsets;
} void Sampler::set_num_samples(const integer samps) {
nsamples = samps;
} integer Sampler::get_num_samples() const {
return nsamples;
} void Sampler::clear() {
shuffled_indices.resize(0);
samples.resize(0);
count = jump = 0;
} Sampler& Sampler::operator=(const Sampler& s) {
if (this == &s)
return *this;
nsamples = s.nsamples;
nsets = s.nsets;
count = s.count;
jump = s.jump;
samples = s.samples;
shuffled_indices = s.shuffled_indices;
return *this;
}

  

  

Sampler类定义的更多相关文章

  1. ViewPlane类定义

    这个类主要是记录了所有跟视图窗口有关的数据,用于显示. 类声明: #pragma once #ifndef __VIEWPLANE_HEADER__ #define __VIEWPLANE_HEADE ...

  2. Python笔记——类定义

    Python笔记——类定义 一.类定义: class <类名>: <语句> 类实例化后,可以使用其属性,实际上,创建一个类之后,可以通过类名访问其属性 如果直接使用类名修改其属 ...

  3. 几种常用的JS类定义方法

    几种常用的JS类定义方法   // 方法1 对象直接量var obj1 = {    v1 : "",    get_v1 : function() {        return ...

  4. Js 类定义的几种方式

    提起面向对象我们就能想到类,对象,封装,继承,多态.在<javaScript高级程序设计>(人民邮电出版社,曹力.张欣译.英文名字是:Professional JavaScript for ...

  5. 为什么C++类定义中,数据成员不能被指定为自身类型,但可以是指向自身类型的指针或引用?为什么在类体内可以定义将静态成员声明为其所属类的类型呢 ?

    static的成员变量,不是存储在Bar实例之中的,因而不会有递归定义的问题. 类声明: class Screen: //Screen类的声明 1 类定义: class Screen{ //Scree ...

  6. C++学了这么多年,你也许不知道为什么类定义要放在.h文件,类实现放在cpp文件。它们如何关联?

    原文  http://blog.csdn.net/ithzhang/article/details/8119286 主题 C++  C++学了这么多年你知道为什么定义类时,类的定义放在.h文件中,而类 ...

  7. YTU 2602: 熟悉题型——类设计( 矩形类定义【C++】)

    2602: 熟悉题型--类设计( 矩形类定义[C++]) 时间限制: 1 Sec  内存限制: 128 MB 提交: 183  解决: 119 题目描述 定义一个矩形类,数据成员包括左下角和右上角坐标 ...

  8. Objective-c 类接口 (@interface) (类定义)

    在Objective-c中如何定义一个类呢?我们可以使用下面的格式进行表示: @interface 类名:父类名{ 变量定义; } 方法定义: @end; 下面给出一个实例: @interface P ...

  9. 只能从脚本中调用在类定义上有[ScriptService]属性的Web服务问题的解决方案

    ajax调用webservice中的接口时, 会出现[只能从脚本中调用在类定义上有[ScriptService]属性的...]的异常. 这是因为, 在.net3.5中, 访问web服务, 要对web服 ...

随机推荐

  1. 817. Linked List Components - LeetCode

    Question 817. Linked List Components Solution 题目大意:给一个链表和该链表元素组成的一个子数组,求子数组在链表中组成多少个片段,每个片段中可有多个连续的元 ...

  2. linux篇-centos7安装DHCP服务器

    1检查防火墙和selinux(关闭) 关闭防火墙和selinux,这边不多说 2检查DHCP状态 3安装DHCP软件包 4把系统默认的样例复制 5修改配置文件 option domain-name & ...

  3. 好客租房20-react组件介绍

    1react组件介绍 组件是react中的一等公民 组件表示页面中的部分功能 组合多个组件实现完整的页面功能 特点 可复用性 独立 可组合

  4. 120_PowerBI堆积瀑布图_R脚本Visual

    博客:www.jiaopengzi.com 焦棚子的文章目录 请点击下载附件 一.效果 二.data 三.添加字段 注意红色框标注地方 四.code # 下面用于创建数据帧并删除重复行的代码始终执行, ...

  5. leetcode 4. Median of Two Sorted Arrays 寻找两个正序数组的中位数(困难)

    一.题目大意 标签: 查找 https://leetcode.cn/problems/median-of-two-sorted-arrays 给定两个大小分别为 m 和 n 的正序(从小到大)数组 n ...

  6. .NET C#基础(4):属性 - 本质是方法

    0. 文章目的   本文面向有一定.NET C#基础知识的学习者,介绍C#中属性的属性.定义.使用方法以及特殊性. 1. 阅读基础   理解C#基本语法(定义类及类成员,调用方法)   认可OOP的封 ...

  7. Prometheus 四种metric类型

    Prometheus的4种metrics(指标)类型: Counter Gauge Histogram Summary 四种指标类型的数据对象都是数字,如果要监控文本类的信息只能通过指标名称或者 la ...

  8. 一张图进阶 RocketMQ - 整体架构

    前 言 三此君看了好几本书,看了很多遍源码整理的 一张图进阶 RocketMQ 图片链接,关于 RocketMQ 你只需要记住这张图!如果你第一次看到这个系列,墙裂建议你打开链接.觉得不错的话,记得点 ...

  9. el-select数据量过大引发卡顿,怎么办?

    本文分享自华为云社区<解决el-select数据量过大的卡顿的两种思路与一种实施方案>,作者: KevinQ. 经典问题:在测试环境好好的,怎么到正式环境就不行了? --本文:数据量变了. ...

  10. 【2022-06-16】Python解释器的下载安装与使用

    一.Python解释器介绍 什么是Python解释器? Python是一门解释型语言,解释器是Python运行必不可少的一种工具.所以,我们搭建Python环境,本质上就是对Python进行配置和定制 ...