-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy patharea_8cpp-source.html
132 lines (132 loc) · 17.9 KB
/
area_8cpp-source.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>pbrt: area.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>area.cpp</h1><a href="area_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">/*</span>
<a name="l00003"></a>00003 <span class="comment"> pbrt source code Copyright(c) 1998-2007 Matt Pharr and Greg Humphreys.</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment"> This file is part of pbrt.</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment"> pbrt is free software; you can redistribute it and/or modify</span>
<a name="l00008"></a>00008 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
<a name="l00009"></a>00009 <span class="comment"> the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00010"></a>00010 <span class="comment"> (at your option) any later version. Note that the text contents of</span>
<a name="l00011"></a>00011 <span class="comment"> the book "Physically Based Rendering" are *not* licensed under the</span>
<a name="l00012"></a>00012 <span class="comment"> GNU GPL.</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment"> pbrt is distributed in the hope that it will be useful,</span>
<a name="l00015"></a>00015 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00016"></a>00016 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00017"></a>00017 <span class="comment"> GNU General Public License for more details.</span>
<a name="l00018"></a>00018 <span class="comment"></span>
<a name="l00019"></a>00019 <span class="comment"> You should have received a copy of the GNU General Public License</span>
<a name="l00020"></a>00020 <span class="comment"> along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
<a name="l00021"></a>00021 <span class="comment"></span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="comment">// area.cpp*</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="light_8h.html">light.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="primitive_8h.html">primitive.h</a>"</span>
<a name="l00027"></a>00027 <span class="comment">// AreaLight Method Definitions</span>
<a name="l00028"></a><a class="code" href="classAreaLight.html#7d5346c3785371bdea63acf262ceaaf6">00028</a> <a class="code" href="classAreaLight.html#7d5346c3785371bdea63acf262ceaaf6">AreaLight::AreaLight</a>(<span class="keyword">const</span> <a class="code" href="classTransform.html">Transform</a> &light2world,
<a name="l00029"></a>00029 <span class="keyword">const</span> <a class="code" href="classSpectrum.html">Spectrum</a> &le, <span class="keywordtype">int</span> ns,
<a name="l00030"></a>00030 <span class="keyword">const</span> <a class="code" href="classReference.html">Reference<Shape></a> &s)
<a name="l00031"></a>00031 : <a class="code" href="classLight.html">Light</a>(light2world, ns) {
<a name="l00032"></a>00032 <a class="code" href="classAreaLight.html#778c381c311d5159d81f581e18e57ff8">Lemit</a> = le;
<a name="l00033"></a>00033 <span class="keywordflow">if</span> (s->CanIntersect())
<a name="l00034"></a>00034 <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a> = s;
<a name="l00035"></a>00035 <span class="keywordflow">else</span> {
<a name="l00036"></a>00036 <span class="comment">// Create _ShapeSet_ for _Shape_</span>
<a name="l00037"></a>00037 <a class="code" href="classReference.html">Reference<Shape></a> shapeSet = s;
<a name="l00038"></a>00038 vector<Reference<Shape> > todo, done;
<a name="l00039"></a>00039 todo.push_back(shapeSet);
<a name="l00040"></a>00040 <span class="keywordflow">while</span> (todo.size()) {
<a name="l00041"></a>00041 <a class="code" href="classReference.html">Reference<Shape></a> sh = todo.back();
<a name="l00042"></a>00042 todo.pop_back();
<a name="l00043"></a>00043 <span class="keywordflow">if</span> (sh->CanIntersect())
<a name="l00044"></a>00044 done.push_back(sh);
<a name="l00045"></a>00045 <span class="keywordflow">else</span>
<a name="l00046"></a>00046 sh->Refine(todo);
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 <span class="keywordflow">if</span> (done.size() == 1) <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a> = done[0];
<a name="l00049"></a>00049 <span class="keywordflow">else</span> {
<a name="l00050"></a>00050 <span class="keywordflow">if</span> (done.size() > 16)
<a name="l00051"></a>00051 <a class="code" href="pbrt_8h.html#79abc2e750c4774bd9d433ad4f6e440a">Warning</a>(<span class="stringliteral">"Area light geometry turned into %d shapes; "</span>
<a name="l00052"></a>00052 <span class="stringliteral">"may be very inefficient."</span>, (<span class="keywordtype">int</span>)done.size());
<a name="l00053"></a>00053 <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a> = <span class="keyword">new</span> <a class="code" href="classShapeSet.html">ShapeSet</a>(done, s->ObjectToWorld, s->reverseOrientation);
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056 <a class="code" href="classAreaLight.html#86707ae6cbcb142631be43f317fb9faf">area</a> = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Area();
<a name="l00057"></a>00057 }
<a name="l00058"></a><a class="code" href="classAreaLight.html#040cd473570ee94dc6f1aad4f368d2e4">00058</a> <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classAreaLight.html#fdfef73eee9b2191db1469214eacef94">AreaLight::Sample_L</a>(<span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &p,
<a name="l00059"></a>00059 <span class="keyword">const</span> <a class="code" href="classNormal.html">Normal</a> &n, <span class="keywordtype">float</span> u1, <span class="keywordtype">float</span> u2,
<a name="l00060"></a>00060 <a class="code" href="classVector.html">Vector</a> *wi, <span class="keywordtype">float</span> *pdf,
<a name="l00061"></a>00061 <a class="code" href="structVisibilityTester.html">VisibilityTester</a> *visibility)<span class="keyword"> const </span>{
<a name="l00062"></a>00062 <a class="code" href="classNormal.html">Normal</a> ns;
<a name="l00063"></a>00063 <a class="code" href="classPoint.html">Point</a> ps = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Sample(p, u1, u2, &ns);
<a name="l00064"></a>00064 *wi = <a class="code" href="geometry_8h.html#46448bfa3df1c2de5e3b763f163866a4">Normalize</a>(ps - p);
<a name="l00065"></a>00065 *pdf = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Pdf(p, *wi);
<a name="l00066"></a>00066 visibility-><a class="code" href="structVisibilityTester.html#5576bb7bf15006fb3f834bd817fa26a0">SetSegment</a>(p, ps);
<a name="l00067"></a>00067 <span class="keywordflow">return</span> <a class="code" href="classAreaLight.html#1fb2187cce4c9d32755698b8536e89e3">L</a>(ps, ns, -*wi);
<a name="l00068"></a>00068 }
<a name="l00069"></a><a class="code" href="classAreaLight.html#27b47741b10c00aa2d88c187646eb457">00069</a> <span class="keywordtype">float</span> <a class="code" href="classAreaLight.html#6b2064ed03ce53c5920a94ad0172e512">AreaLight::Pdf</a>(<span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &p, <span class="keyword">const</span> <a class="code" href="classNormal.html">Normal</a> &<a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>,
<a name="l00070"></a>00070 <span class="keyword">const</span> <a class="code" href="classVector.html">Vector</a> &wi)<span class="keyword"> const </span>{
<a name="l00071"></a>00071 <span class="keywordflow">return</span> <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Pdf(p, wi);
<a name="l00072"></a>00072 }
<a name="l00073"></a><a class="code" href="classAreaLight.html#2b2ec43ac0a8cf5ef76f05c5be59191c">00073</a> <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classAreaLight.html#fdfef73eee9b2191db1469214eacef94">AreaLight::Sample_L</a>(<span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &P,
<a name="l00074"></a>00074 <span class="keywordtype">float</span> u1, <span class="keywordtype">float</span> u2, <a class="code" href="classVector.html">Vector</a> *wo, <span class="keywordtype">float</span> *pdf,
<a name="l00075"></a>00075 <a class="code" href="structVisibilityTester.html">VisibilityTester</a> *visibility)<span class="keyword"> const </span>{
<a name="l00076"></a>00076 <a class="code" href="classNormal.html">Normal</a> Ns;
<a name="l00077"></a>00077 <a class="code" href="classPoint.html">Point</a> Ps = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Sample(P, u1, u2, &Ns);
<a name="l00078"></a>00078 *wo = <a class="code" href="geometry_8h.html#46448bfa3df1c2de5e3b763f163866a4">Normalize</a>(Ps - P);
<a name="l00079"></a>00079 *pdf = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Pdf(P, *wo);
<a name="l00080"></a>00080 visibility-><a class="code" href="structVisibilityTester.html#5576bb7bf15006fb3f834bd817fa26a0">SetSegment</a>(P, Ps);
<a name="l00081"></a>00081 <span class="keywordflow">return</span> <a class="code" href="classAreaLight.html#1fb2187cce4c9d32755698b8536e89e3">L</a>(Ps, Ns, -*wo);
<a name="l00082"></a>00082 }
<a name="l00083"></a><a class="code" href="classAreaLight.html#7bb80d972c95e47be110fd95ec71fe70">00083</a> <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classAreaLight.html#fdfef73eee9b2191db1469214eacef94">AreaLight::Sample_L</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <span class="keywordtype">float</span> u1,
<a name="l00084"></a>00084 <span class="keywordtype">float</span> u2, <span class="keywordtype">float</span> u3, <span class="keywordtype">float</span> u4,
<a name="l00085"></a>00085 <a class="code" href="classRay.html">Ray</a> *ray, <span class="keywordtype">float</span> *pdf)<span class="keyword"> const </span>{
<a name="l00086"></a>00086 <a class="code" href="classNormal.html">Normal</a> ns;
<a name="l00087"></a>00087 ray-><a class="code" href="classRay.html#1014d000992e8ac3b92f150ad2a5cffe">o</a> = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Sample(u1, u2, &ns);
<a name="l00088"></a>00088 ray-><a class="code" href="classRay.html#5bbfc94e178e0a050b51200acc579069">d</a> = <a class="code" href="mc_8cpp.html#3be32f43969ef61ca8fc550a61814548">UniformSampleSphere</a>(u3, u4);
<a name="l00089"></a>00089 <span class="keywordflow">if</span> (<a class="code" href="geometry_8h.html#ad0d36688d190693f70a5c9ef9342914">Dot</a>(ray-><a class="code" href="classRay.html#5bbfc94e178e0a050b51200acc579069">d</a>, ns) < 0.) ray-><a class="code" href="classRay.html#5bbfc94e178e0a050b51200acc579069">d</a> *= -1;
<a name="l00090"></a>00090 *pdf = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Pdf(ray-><a class="code" href="classRay.html#1014d000992e8ac3b92f150ad2a5cffe">o</a>) * <a class="code" href="pbrt_8h.html#42177ad937b6de334f376c039189e067">INV_TWOPI</a>;
<a name="l00091"></a>00091 <span class="keywordflow">return</span> <a class="code" href="classAreaLight.html#1fb2187cce4c9d32755698b8536e89e3">L</a>(ray-><a class="code" href="classRay.html#1014d000992e8ac3b92f150ad2a5cffe">o</a>, ns, ray-><a class="code" href="classRay.html#5bbfc94e178e0a050b51200acc579069">d</a>);
<a name="l00092"></a>00092 }
<a name="l00093"></a><a class="code" href="classAreaLight.html#6b2064ed03ce53c5920a94ad0172e512">00093</a> <span class="keywordtype">float</span> <a class="code" href="classAreaLight.html#6b2064ed03ce53c5920a94ad0172e512">AreaLight::Pdf</a>(<span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &P, <span class="keyword">const</span> <a class="code" href="classVector.html">Vector</a> &w)<span class="keyword"> const </span>{
<a name="l00094"></a>00094 <span class="keywordflow">return</span> <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Pdf(P, w);
<a name="l00095"></a>00095 }
<a name="l00096"></a><a class="code" href="classAreaLight.html#fdfef73eee9b2191db1469214eacef94">00096</a> <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classAreaLight.html#fdfef73eee9b2191db1469214eacef94">AreaLight::Sample_L</a>(<span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &P, <a class="code" href="classVector.html">Vector</a> *wo,
<a name="l00097"></a>00097 <a class="code" href="structVisibilityTester.html">VisibilityTester</a> *visibility)<span class="keyword"> const </span>{
<a name="l00098"></a>00098 <a class="code" href="classNormal.html">Normal</a> Ns;
<a name="l00099"></a>00099 <a class="code" href="classPoint.html">Point</a> Ps = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Sample(P, <a class="code" href="pbrt_8h.html#4f11994534b888fcf650c04b5d61d9d4">RandomFloat</a>(), <a class="code" href="pbrt_8h.html#4f11994534b888fcf650c04b5d61d9d4">RandomFloat</a>(), &Ns);
<a name="l00100"></a>00100 *wo = <a class="code" href="geometry_8h.html#46448bfa3df1c2de5e3b763f163866a4">Normalize</a>(Ps - P);
<a name="l00101"></a>00101 visibility-><a class="code" href="structVisibilityTester.html#5576bb7bf15006fb3f834bd817fa26a0">SetSegment</a>(P, Ps);
<a name="l00102"></a>00102 <span class="keywordtype">float</span> pdf = <a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>->Pdf(P, *wo);
<a name="l00103"></a>00103 <span class="keywordflow">if</span> (pdf == 0.f) <span class="keywordflow">return</span> <a class="code" href="classSpectrum.html">Spectrum</a>(0.f);
<a name="l00104"></a>00104 <span class="keywordflow">return</span> <a class="code" href="classAreaLight.html#1fb2187cce4c9d32755698b8536e89e3">L</a>(P, Ns, -*wo) / pdf;
<a name="l00105"></a>00105 }
<a name="l00106"></a><a class="code" href="area_8cpp.html#ba46ff0696cf8d9e4f4ab5f7c6db9b87">00106</a> <span class="keyword">extern</span> <span class="stringliteral">"C"</span> <a class="code" href="pbrt_8h.html#808e08638be3cba36e36759e5b150de0">DLLEXPORT</a> <a class="code" href="classLight.html">Light</a> *<a class="code" href="area_8cpp.html#ba46ff0696cf8d9e4f4ab5f7c6db9b87">CreateAreaLight</a>(<span class="keyword">const</span> <a class="code" href="classTransform.html">Transform</a> &light2world, <span class="keyword">const</span> <a class="code" href="classParamSet.html">ParamSet</a> &paramSet,
<a name="l00107"></a>00107 <span class="keyword">const</span> <a class="code" href="classReference.html">Reference<Shape></a> &<a class="code" href="classAreaLight.html#afd83d4d2f9230561ecdd66b96534312">shape</a>) {
<a name="l00108"></a>00108 <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classAreaLight.html#1fb2187cce4c9d32755698b8536e89e3">L</a> = paramSet.<a class="code" href="classParamSet.html#abe7a9db3a1aff8d7ec06408c34adc14">FindOneSpectrum</a>(<span class="stringliteral">"L"</span>, <a class="code" href="classSpectrum.html">Spectrum</a>(1.0));
<a name="l00109"></a>00109 <span class="keywordtype">int</span> <a class="code" href="classLight.html#fae2e64a4a14046913c82c175078d8bb">nSamples</a> = paramSet.<a class="code" href="classParamSet.html#23f24db9c46375e33764910c4fa999d5">FindOneInt</a>(<span class="stringliteral">"nsamples"</span>, 1);
<a name="l00110"></a>00110 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classAreaLight.html#7d5346c3785371bdea63acf262ceaaf6">AreaLight</a>(light2world, L, nSamples, shape);
<a name="l00111"></a>00111 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 20 17:31:52 2009 for pbrt by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>