forked from jacobwjs/MC-Boost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.cpp
189 lines (147 loc) · 5.81 KB
/
layer.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "layer.h"
#include <iostream>
using std::cout;
Layer::Layer(double mu_a, double mu_s, double refractive_index, double anisotropy,
double depth_start, double depth_end)
{
this->mu_a = mu_a;
this->mu_s = mu_s;
this->mu_t = mu_a + mu_s;
albedo = mu_s/(mu_s + mu_a);
g = anisotropy;
this->refractive_index = refractive_index;
this->depth_start = depth_start;
this->depth_end = depth_end;
}
Layer::~Layer(void)
{
// Free any memory allocated on the heap by this object.
for (std::vector<Absorber *>::iterator i = p_absorbers.begin(); i < p_absorbers.end(); i++)
delete *i;
}
void Layer::setAbsorpCoeff(double mu_a)
{
this->mu_a = mu_a;
// If we ever update the absorption coefficient we need to update the
// transmission coefficient and albedo similarly.
this->mu_t = mu_a + mu_s;
updateAlbedo();
}
void Layer::setScatterCoeff(double mu_s)
{
this->mu_s = mu_s;
// If we ever update the scattering coefficient we need to update the
// transmission coefficient albedo similarly.
this->mu_t = mu_a + mu_s;
updateAlbedo();
}
void Layer::updateAlbedo()
{
albedo = mu_s/(mu_s + mu_a);
}
void Layer::addAbsorber(Absorber * absorber)
{
// FIXME: Ensure the absorber fits within the bounds of the layer.
//
p_absorbers.push_back(absorber);
}
// Returns the refractive index based on coordinates of photon. That is,
// there could be an occlusion in the medium and we ensure the correct value
// is returned.
double Layer::getRefractiveIndex(const boost::shared_ptr<Vector3d> photonVector)
{
cout << "Layer::getRefractiveIndex(Vector3d) stub\n";
}
// Returns the absorption coefficient after checking to see if the
// photon might be within an absorber.
double Layer::getAbsorpCoeff(const boost::shared_ptr<Vector3d> photonVector)
{
// Iterate over all the absorbers in this layer and see if the coordinates
// of the photon reside within the bounds of the absorber. If so, we return
// the absorption coefficient of the absorber, otherwise we return the
// absorption coefficient of the ambient layer.
for (std::vector<Absorber *>::iterator it = p_absorbers.begin(); it != p_absorbers.end(); it++)
{
if ((*it)->inAbsorber(photonVector))
{
return (*it)->getAbsorberAbsorptionCoeff();
}
}
// If we make it out of the loop (i.e. the photon is not in an absorber) we
// return the layer's absorption coefficient.
return mu_a;
}
// Returns the absorption coefficient after checking to see if the
// photon might be within an absorber.
double Layer::getScatterCoeff(const boost::shared_ptr<Vector3d> photonVector)
{
// Iterate over all the absorbers in this layer and see if the coordinates
// of the photon reside within the bounds of the absorber. If so, we return
// the scattering coefficient of the absorber, otherwise we return the
// absorption coefficient of the ambient layer.
for (std::vector<Absorber *>::iterator it = p_absorbers.begin(); it != p_absorbers.end(); it++)
{
if ((*it)->inAbsorber(photonVector))
{
return (*it)->getAbsorberScatteringCoeff();
}
}
// If we make it out of the loop (i.e. the photon is not in an absorber) we
// return the layer's absorption coefficient.
return mu_s;
}
double Layer::getTotalAttenuationCoeff(const boost::shared_ptr<Vector3d> photonVector)
{
// Iterate over all the absorbers in this layer and see if the coordinates
// of the photon reside within the bounds of the absorber. If so, we return
// the total attenuation coefficient of the absorber, otherwise we return the
// total attenuation coefficient of the ambient layer.
for (std::vector<Absorber *>::iterator it = p_absorbers.begin(); it != p_absorbers.end(); it++)
{
if ((*it)->inAbsorber(photonVector))
{
return ((*it)->getAbsorberScatteringCoeff() + (*it)->getAbsorberScatteringCoeff());
}
}
// If we make it out of the loop (i.e. the photon is not in an absorber) we
// return the layer's total attenuation coefficient.
return (mu_a + mu_s);
}
void Layer::updateAbsorbedWeightByAbsorber(const boost::shared_ptr<Vector3d> photonVector, const double absorbed)
{
// Iterate over all the absorbers in this layer and see if the coordinates
// of the photon reside within the bounds of the absorber. If so, we return
// the absorption coefficient of the absorber, otherwise we return the
// absorption coefficient of the ambient layer.
for (std::vector<Absorber *>::iterator it = p_absorbers.begin(); it != p_absorbers.end(); it++)
{
if ((*it)->inAbsorber(photonVector))
{
(*it)->updateAbsorbedWeight(absorbed);
}
}
}
Absorber * Layer::getAbsorber(const boost::shared_ptr<Vector3d> photonVector)
{
// Iterate over all the absorbers in this layer and see if the coordinates
// of the photon reside within the bounds of the absorber. If so, we return
// the absorption coefficient of the absorber, otherwise we return the
// absorption coefficient of the ambient layer.
for (std::vector<Absorber *>::iterator it = p_absorbers.begin(); it != p_absorbers.end(); it++)
{
if ((*it)->inAbsorber(photonVector))
{
return *it;
}
}
return NULL;
}
// Iterate over all absorbers and write their data out to file.
void Layer::writeAbsorberData(void)
{
// Write out the data for every absorber in the medium.
for (std::vector<Absorber *>::iterator it = p_absorbers.begin(); it != p_absorbers.end(); it++)
{
(*it)->writeData();
}
}