Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
manifold.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba 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  Mitsuba 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 #pragma once
20 #if !defined(__MITSUBA_BIDIR_MANIFOLD_H_)
21 #define __MITSUBA_BIDIR_MANIFOLD_H_
22 
23 #include <mitsuba/bidir/vertex.h>
24 
25 #define MTS_MANIFOLD_DEBUG 0
26 #define MTS_MANIFOLD_EPSILON Epsilon
27 #define MTS_MANIFOLD_MAX_ITERATIONS 20
28 
30 
31 /**
32  * \brief Utility class for perturbing paths located on a specular manifold.
33  * \author Wenzel Jakob
34  */
36 public:
37  /// Construct an unitialized specular manifold data structure
38  SpecularManifold(const Scene *scene, int maxIterations = -1);
39 
40  /**
41  * \brief Initialize the specular manifold with the specified
42  * path segment
43  */
44  bool init(const Path &path, int start, int end);
45 
46  /**
47  * \brief Update the provided path segment based on the stored
48  * specular manifold configuration
49  */
50  bool update(Path &path, int start, int end);
51 
52  /// Attempt to move the movable endpoint vertex to position \c target
53  bool move(const Point &target, const Normal &normal);
54 
55  /**
56  * \brief Compute the generalized geometric term between 'a' and 'b'
57  */
58  Float G(const Path &path, int a, int b);
59 
60  /**
61  * \brief Compute a product of standard and generalized geometric
62  * terms between 'a' and 'b' depending on whether vertices are
63  * specular or non-specular.
64  */
65  Float multiG(const Path &path, int a, int b);
66 
67  Float det(const Path &path, int a, int b, int c);
68 
69  /// Return the number of iterations used by \ref move()
70  inline int getIterationCount() const { return m_iterations; }
71 
72  /// Return the position of a vertex
73  inline const Point &getPosition(int i) { return m_vertices[i].p; }
74 
75  /// Return a string representation
76  std::string toString() const;
77 
79 protected:
80  /// Virtual destructor
81  virtual ~SpecularManifold() { }
82 
83 private:
84  enum EType {
85  EPinnedPosition = 0,
86  EPinnedDirection,
87  EReflection,
88  ERefraction,
89  EMedium,
90  EMovable
91  };
92 
93  /// Describes a single interaction on the path
94  struct SimpleVertex {
95  bool degenerate : 1;
96  EType type : 31;
97 
98  /* Position and partials */
99  Point p;
100  Vector dpdu, dpdv;
101 
102  /* Normal and partials */
103  Normal n, gn;
104  Vector dndu, dndv;
105 
106  /* "Microfacet" normal */
107  Normal m;
108 
109  /* Further information about the vertex */
110  Float eta;
111  const Object *object;
112 
113  /* Scratch space for matrix assembly */
114  Matrix2x2 a, b, c, u;
115 
116  /* Manifold tangent space projected onto this vertex */
117  Matrix2x2 Tp;
118 
119  /// Initialize certain fields to zero by default
120  inline SimpleVertex(EType type, const Point &p) :
121  degenerate(false), type(type), p(p), dpdu(0.0f),
122  dpdv(0.0f), n(0.0f), dndu(0.0f), dndv(0.0f),
123  m(0.0f), eta(1.0f), object(NULL) { }
124 
125  /// Map a tangent space displacement into world space
126  inline Vector map(Float u, Float v) const {
127  Vector2 T = Tp * Vector2(u, v);
128  return T.x * dpdu + T.y * dpdv;
129  }
130 
131  std::string toString() const;
132  };
133 
134  /// Take the specified step and project back onto the manifold
135  bool project(const Vector &d);
136 
137  /**
138  * \brief Compute the tangent vectors with the specified
139  * components when projected onto the movable endpoint vertex
140  */
141  bool computeTangents();
142 
143  void check(SimpleVertex *v);
144 protected:
145  const Scene *m_scene;
147  int m_iterations, m_maxIterations;
148 
149  std::vector<SimpleVertex> m_vertices, m_proposal;
150 };
151 
153 
154 #endif /* __MITSUBA_BIDIR_MANIFOLD_H_ */
#define MTS_EXPORT_BIDIR
Definition: platform.h:119
Three-dimensional normal data structure.
Definition: normal.h:39
int getIterationCount() const
Return the number of iterations used by move()
Definition: manifold.h:70
Float m_time
Definition: manifold.h:146
Principal scene data structure.
Definition: scene.h:49
Bidirectional path data structure.
Definition: path.h:46
T det(const TVector2< T > &v1, const TVector2< T > &v2)
Definition: vector.h:411
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Utility class for perturbing paths located on a specular manifold.
Definition: manifold.h:35
const Scene * m_scene
Definition: manifold.h:145
int m_maxIterations
Definition: manifold.h:147
TVector2< Float > Vector2
Definition: fwd.h:106
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
std::vector< SimpleVertex > m_vertices
Definition: manifold.h:149
Definition: fwd.h:96
const Point & getPosition(int i)
Return the position of a vertex.
Definition: manifold.h:73
Definition: fwd.h:100
Parent of all Mitsuba classes.
Definition: object.h:38
virtual std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
Definition: fwd.h:95
#define MTS_NAMESPACE_END
Definition: platform.h:138