Sampler类定义
此是所有采样的基类,这样定义的好处是,我们可以分别测试每一个采样算法。
类定义:
#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类定义的更多相关文章
- ViewPlane类定义
这个类主要是记录了所有跟视图窗口有关的数据,用于显示. 类声明: #pragma once #ifndef __VIEWPLANE_HEADER__ #define __VIEWPLANE_HEADE ...
- Python笔记——类定义
Python笔记——类定义 一.类定义: class <类名>: <语句> 类实例化后,可以使用其属性,实际上,创建一个类之后,可以通过类名访问其属性 如果直接使用类名修改其属 ...
- 几种常用的JS类定义方法
几种常用的JS类定义方法 // 方法1 对象直接量var obj1 = { v1 : "", get_v1 : function() { return ...
- Js 类定义的几种方式
提起面向对象我们就能想到类,对象,封装,继承,多态.在<javaScript高级程序设计>(人民邮电出版社,曹力.张欣译.英文名字是:Professional JavaScript for ...
- 为什么C++类定义中,数据成员不能被指定为自身类型,但可以是指向自身类型的指针或引用?为什么在类体内可以定义将静态成员声明为其所属类的类型呢 ?
static的成员变量,不是存储在Bar实例之中的,因而不会有递归定义的问题. 类声明: class Screen: //Screen类的声明 1 类定义: class Screen{ //Scree ...
- C++学了这么多年,你也许不知道为什么类定义要放在.h文件,类实现放在cpp文件。它们如何关联?
原文 http://blog.csdn.net/ithzhang/article/details/8119286 主题 C++ C++学了这么多年你知道为什么定义类时,类的定义放在.h文件中,而类 ...
- YTU 2602: 熟悉题型——类设计( 矩形类定义【C++】)
2602: 熟悉题型--类设计( 矩形类定义[C++]) 时间限制: 1 Sec 内存限制: 128 MB 提交: 183 解决: 119 题目描述 定义一个矩形类,数据成员包括左下角和右上角坐标 ...
- Objective-c 类接口 (@interface) (类定义)
在Objective-c中如何定义一个类呢?我们可以使用下面的格式进行表示: @interface 类名:父类名{ 变量定义; } 方法定义: @end; 下面给出一个实例: @interface P ...
- 只能从脚本中调用在类定义上有[ScriptService]属性的Web服务问题的解决方案
ajax调用webservice中的接口时, 会出现[只能从脚本中调用在类定义上有[ScriptService]属性的...]的异常. 这是因为, 在.net3.5中, 访问web服务, 要对web服 ...
随机推荐
- 原理:C++为什么一般把模板实现放入头文件
写在前面 本文通过实例分析与讲解,解释了为什么C++一般将模板实现放在头文件中.这主要与C/C++的编译机制以及C++模板的实现原理相关,详情见正文.同时,本文给出了不将模板实现放在头文件中的解决方案 ...
- 在sqlbolt上学习SQL
在sqlbolt上学习SQL 该网站能够学习sql基础,并且能在网页中直接输入sql语句进行查询. 学习网站原网址https://sqlbolt.com/(!部分指令该网站不支持,且存在一些bug!) ...
- 如何删除wps在我的电脑入口中的云文档图标
本人有强迫症,看着图标很难受,所以就找到了一种注册表删除的方法,操作如下: 呼出注册表面板, WIN+R 输入 regedit 打开注册表 找到如下路径 计算机\HKEY_CURRENT_USER\S ...
- cookie 案例 记住上一次的访问时间
需求:记住上一次的访问时间 第一次访问Servlet 提示 欢迎首次访问 之后的访问 都提示 您上次的访问时间为:"""""""& ...
- linux web漏洞扫描arachni
1. 下载arachni https://www.arachni-scanner.com/download/下载Linux x86 64bit 2. 上次解压直接使用 tar xzf arachni- ...
- ssh-免密钥登陆
实现openssh免密钥登陆(公私钥验证) 在主机A上,通过root用户,使用ssh-keygen生成的两个密钥:id_rsa和id_rsa.pub 私钥(id_rsa)保存在本地主机,公钥(id_r ...
- 比我的脸还干的gan货——Python Flask Web 框架入门
Flask是一个轻量级的基于Python的web框架. 本文适合有一定HTML.Python.网络基础的同学阅读. 1. 简介 这份文档中的代码使用 Python 3 运行.是的,所以读者需要自己在电 ...
- Integer.MAX_VALUE 和 Integer.MIN_VALUE
在源码中可以看出其对应的值 Integer.MAX_VALUE是2^31 -1 = 2147483647 Integer.MIN_VALUE是-2^31 = -2147483648
- ShardingSphere-proxy-5.0.0企业级分库分表、读写分离、负载均衡、雪花算法、取模算法整合(八)
一.简要说明 以下配置实现了: 1.分库分表 2.每一个分库的读写分离 3.读库负载均衡算法 4.雪花算法,生成唯一id 5.字段取模 二.配置项 # # Licensed to the Apache ...
- 高仿Android网易云音乐OkHttp+Retrofit+RxJava+Glide+MVC+MVVM
简介 这是一个使用Java(以后还会推出Kotlin版本)语言,从0开发一个Android平台,接近企业级的项目(我的云音乐),包含了基础内容,高级内容,项目封装,项目重构等知识:主要是使用系统功能, ...