/
Scene.h
108 lines (92 loc) · 2.81 KB
/
Scene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include "SimpleShape.h"
#include "Ray.h"
#include "SceneObject.h"
#include "KDTree.h"
#include <algorithm>
class SceneObject;
class Scene
{
public:
struct ObjSourceInformation
{
unsigned objID;
unsigned triangleID;
};
float totalArea;
float totalVolume;
KDTree tree;
vector<KDTree> objKDTrees;
public:
vector<unsigned> objTriangleOffsetMap;
bool useGPU;
struct SurfaceSampler
{
Scene* scene;
SurfaceSampler(Scene* scene){ this->scene = scene; }
float totalWeight;
vector<float> weightValues;
vector<SceneObject*> targetObjects;
float totalArea;
void preprocess();
void preprocessForInterpath();
void normalize();
Ray genSample(bool isUniformOrigin , bool isUniformDir) const;
float getDirectionProbDensity(const Ray& ray) const;
float getOriginProbDensity(const Ray& ray) const;
void print();
};
struct VolumeSampler
{
Scene* scene;
VolumeSampler(Scene* scene) { this->scene = scene; }
float totalWeight;
vector<float> weightValues;
vector<SceneObject*> targetObjects;
float totalVolume;
void preprocess(bool isUniformOrigin , float mergeRadius);
Ray genSample(bool isUniformDir) const;
void normalize();
void print();
};
public:
SurfaceSampler *emissiveSurfaceSampler;
SurfaceSampler *otherSurfaceSampler;
VolumeSampler *volumeSampler;
Scene()
{
emissiveSurfaceSampler = otherSurfaceSampler = NULL;
volumeSampler = NULL;
//useGPU = true;
useGPU = false;
}
int Scene::getContactTreeTid(const Ray& ray);
void setGPU(bool on){ useGPU = on; }
bool usingGPU(){ return useGPU; }
vector<SceneObject*> objects;
void buildKDTree();
void buildObjKDTrees();
void preprocessEmissionSampler();
void preprocessOtherSampler(bool isUniformOrigin);
void preprocessVolumeSampler(bool isUniformOrigin , float mergeRadius);
void beginUpdateOtherSampler(const int iter);
void beginUpdateVolumeSampler(const int iter);
void updateOtherSampler(const int objId , const int triId , const int iter , const vec3f& thr);
void updateVolumeSampler(const int objId , const vec3f& pos , const int iter , const vec3f& thr);
void endUpdateOtherSampler();
void endUpdateVolumeSampler();
Ray genEmissionSample(bool isUniformDir = false) const;
Ray genOtherSample(bool isUniformOrigin = true , bool isUniformDir = false) const;
Ray genVolumeSample(bool isUniformDir = false) const;
float intersect(const Ray& ray, ObjSourceInformation& objSource, const KDTree::Condition* condition = NULL);
void fillIntersectObject(vector<Ray>& rays);
SceneObject* findInsideObject(const Ray& ray, const SceneObject* currentObject = NULL);
bool checkInsideObject(const Ray& ray, const int insideObjectIndex);
vector<bool> testVisibility(const vector<Ray>& rays);
void clear();
float getTotalArea();
float getTotalVolume();
float getBoundSphereRadius();
vec3f getDiagonal();
~Scene();
};