Nori  24
scene.h
1 /*
2  This file is part of Nori, a simple educational ray tracer
3 
4  Copyright (c) 2015 by Wenzel Jakob, Romain Prévost
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_SCENE_H)
20 #define __NORI_SCENE_H
21 
22 #include <nori/bvh.h>
23 #include <nori/emitter.h>
24 
25 NORI_NAMESPACE_BEGIN
26 
34 class Scene : public NoriObject {
35 public:
37  Scene(const PropertyList &);
38 
40  virtual ~Scene();
41 
43  const BVH *getBVH() const { return m_bvh; }
44 
46  const Integrator *getIntegrator() const { return m_integrator; }
47 
49  Integrator *getIntegrator() { return m_integrator; }
50 
52  const Camera *getCamera() const { return m_camera; }
53 
55  const Sampler *getSampler() const { return m_sampler; }
56 
58  Sampler *getSampler() { return m_sampler; }
59 
61  const std::vector<Shape *> &getShapes() const { return m_shapes; }
62 
64  const std::vector<Emitter *> &getLights() const { return m_emitters; }
65 
67  const Emitter * getRandomEmitter(float rnd) const {
68  auto const & n = m_emitters.size();
69  size_t index = std::min(
70  static_cast<size_t>(std::floor(n*rnd)),
71  n-1);
72  return m_emitters[index];
73  }
74 
89  bool rayIntersect(const Ray3f &ray, Intersection &its) const {
90  return m_bvh->rayIntersect(ray, its, false);
91  }
92 
108  bool rayIntersect(const Ray3f &ray) const {
109  Intersection its; /* Unused */
110  return m_bvh->rayIntersect(ray, its, true);
111  }
112 
116  const BoundingBox3f &getBoundingBox() const {
117  return m_bvh->getBoundingBox();
118  }
119 
126  virtual void activate() override;
127 
129  virtual void addChild(NoriObject *obj) override;
130 
132  virtual std::string toString() const override;
133 
134  virtual EClassType getClassType() const override { return EScene; }
135 private:
136  std::vector<Shape *> m_shapes;
137  Integrator *m_integrator = nullptr;
138  Sampler *m_sampler = nullptr;
139  Camera *m_camera = nullptr;
140  BVH *m_bvh = nullptr;
141 
142  std::vector<Emitter *> m_emitters;
143 };
144 
145 NORI_NAMESPACE_END
146 
147 #endif /* __NORI_SCENE_H */
Bounding Volume Hierarchy for fast ray intersection queries.
Definition: bvh.h:43
bool rayIntersect(const Ray3f &ray, Intersection &its, bool shadowRay=false) const
Intersect a ray against all shapes registered with the BVH.
Definition: bvh.cpp:404
Generic camera interface.
Definition: camera.h:35
Superclass of all emitters.
Definition: emitter.h:64
Abstract integrator (i.e. a rendering technique)
Definition: integrator.h:35
Base class of all objects.
Definition: object.h:32
This is an associative container used to supply the constructors of NoriObject subclasses with parame...
Definition: proplist.h:32
Abstract sample generator.
Definition: sampler.h:63
Main scene data structure.
Definition: scene.h:34
const BVH * getBVH() const
Return a pointer to the scene's kd-tree.
Definition: scene.h:43
virtual void activate() override
Inherited from NoriObject::activate()
Definition: scene.cpp:42
virtual ~Scene()
Release all memory.
Definition: scene.cpp:32
const Emitter * getRandomEmitter(float rnd) const
Return a random emitter.
Definition: scene.h:67
const Camera * getCamera() const
Return a pointer to the scene's camera.
Definition: scene.h:52
virtual EClassType getClassType() const override
Return the type of object (i.e. Mesh/BSDF/etc.) provided by this instance.
Definition: scene.h:134
Integrator * getIntegrator()
Return a pointer to the scene's integrator.
Definition: scene.h:49
const BoundingBox3f & getBoundingBox() const
Return an axis-aligned box that bounds the scene.
Definition: scene.h:116
bool rayIntersect(const Ray3f &ray) const
Intersect a ray against all triangles stored in the scene and only determine whether or not there is ...
Definition: scene.h:108
bool rayIntersect(const Ray3f &ray, Intersection &its) const
Intersect a ray against all triangles stored in the scene and return detailed intersection informatio...
Definition: scene.h:89
virtual std::string toString() const override
Return a string summary of the scene (for debugging purposes)
Definition: scene.cpp:101
Scene(const PropertyList &)
Construct a new scene object.
Definition: scene.cpp:28
Sampler * getSampler()
Return a pointer to the scene's sample generator.
Definition: scene.h:58
virtual void addChild(NoriObject *obj) override
Add a child object to the scene (meshes, integrators etc.)
Definition: scene.cpp:62
const std::vector< Shape * > & getShapes() const
Return a reference to an array containing all shapes.
Definition: scene.h:61
const Integrator * getIntegrator() const
Return a pointer to the scene's integrator.
Definition: scene.h:46
const std::vector< Emitter * > & getLights() const
Return a reference to an array containing all lights.
Definition: scene.h:64
const Sampler * getSampler() const
Return a pointer to the scene's sample generator (const version)
Definition: scene.h:55
Intersection data structure.
Definition: shape.h:37