Nori  23
emitter.h
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob
5 
6  Nori is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Nori is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #if !defined(__NORI_EMITTER_H)
20 #define __NORI_EMITTER_H
21 
22 #include <nori/object.h>
23 
24 NORI_NAMESPACE_BEGIN
25 
26 struct Intersection;
41  float pdf;
44 
47 
50 
55  EmitterQueryRecord(const Point3f &ref, const Point3f &p, const Normal3f &n) :
56  ref(ref), p(p), n(n) {
57  wi = (p - ref).normalized();
58  }
59 };
60 
64 class Emitter : public NoriObject {
65 public:
66 
78  virtual Color3f sample(EmitterQueryRecord &lRec, const Point2f &sample) const = 0;
79 
88  virtual Color3f eval(const EmitterQueryRecord &lRec) const = 0;
89 
102  virtual float pdf(const EmitterQueryRecord &lRec) const = 0;
103 
104 
106  virtual Color3f samplePhoton(Ray3f &ray, const Point2f &sample1, const Point2f &sample2) const {
107  throw NoriException("Emitter::samplePhoton(): not implemented!");
108  }
109 
110 
114  virtual ~Emitter() {}
115 
120  virtual EClassType getClassType() const override { return EEmitter; }
121 
125  void setShape(Shape * shape) { m_shape = shape; }
126 
127 protected:
129  Shape * m_shape = nullptr;
130 
131 };
132 
133 NORI_NAMESPACE_END
134 
135 #endif /* __NORI_EMITTER_H */
Superclass of all emitters.
Definition: emitter.h:64
Shape * m_shape
Pointer to the shape if the emitter is attached to a shape.
Definition: emitter.h:129
virtual EClassType getClassType() const override
Return the type of object (i.e. Mesh/Emitter/etc.) provided by this instance.
Definition: emitter.h:120
virtual Color3f eval(const EmitterQueryRecord &lRec) const =0
Evaluate the emitter.
virtual Color3f sample(EmitterQueryRecord &lRec, const Point2f &sample) const =0
Sample the emitter and return the importance weight (i.e. the value of the Emitter divided by the pro...
void setShape(Shape *shape)
Set the shape if the emitter is attached to a shape.
Definition: emitter.h:125
virtual ~Emitter()
Virtual destructor.
Definition: emitter.h:114
virtual Color3f samplePhoton(Ray3f &ray, const Point2f &sample1, const Point2f &sample2) const
Sample a photon.
Definition: emitter.h:106
virtual float pdf(const EmitterQueryRecord &lRec) const =0
Compute the probability of sampling lRec.p.
Simple exception class, which stores a human-readable error description.
Definition: common.h:148
Base class of all objects.
Definition: object.h:32
Superclass of all shapes.
Definition: shape.h:97
Represents a linear RGB color value.
Definition: color.h:29
Data record for conveniently querying and sampling the direct illumination technique implemented by a...
Definition: emitter.h:31
float pdf
Probability.
Definition: emitter.h:41
EmitterQueryRecord(const Point3f &ref, const Point3f &p, const Normal3f &n)
Create a query record that can be used to query the sampling density after having intersected an area...
Definition: emitter.h:55
Normal3f n
Normal at the emitter point.
Definition: emitter.h:37
EmitterQueryRecord()
Create an unitialized query record.
Definition: emitter.h:46
Vector3f wi
Direction between the hit point and the emitter point.
Definition: emitter.h:39
Point3f ref
Origin point from which we sample the emitter.
Definition: emitter.h:33
Ray3f shadowRay
Shadow ray.
Definition: emitter.h:43
Point3f p
Sampled point on the emitter.
Definition: emitter.h:35
EmitterQueryRecord(const Point3f &ref)
Create a new query record that can be used to sample a emitter.
Definition: emitter.h:49
Intersection data structure.
Definition: shape.h:37
3-dimensional surface normal representation
Definition: vector.h:133