Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spline.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_CORE_SPLINE_H_)
21 #define __MITSUBA_CORE_SPLINE_H_
22 
23 #include <mitsuba/mitsuba.h>
24 
26 
27 /*! \addtogroup libcore */
28 /*! @{ */
29 
30 // -----------------------------------------------------------------------
31 //! @{ \name Functions for evaluating and sampling Catmull-Rom splines
32 // -----------------------------------------------------------------------
33 
34 /**
35  * \brief Evaluate a cubic spline interpolant of a uniformly sampled 1D function
36  *
37  * This implementation relies on Catmull-Rom splines, i.e. it uses finite
38  * differences to approximate the derivatives at the endpoints of each spline
39  * segment.
40  *
41  * \param x
42  * Evaluation point
43  * \param values
44  * Floating point array containing \c size regularly spaced evaluations
45  * in the range [\c min,\c max] of the function to be approximated.
46  * \param size
47  * Denotes the size of the \c values array
48  * \param min
49  * Position of the first knot
50  * \param max
51  * Position of the last knot
52  * \param extrapolate
53  * Extrapolate values when \c x is out of range? (default: \c false)
54  * \return
55  * The interpolated value or zero when <tt>extrapolate=false</tt>tt>
56  * and \c x lies outside of [\c min, \c max]
57  */
58 extern MTS_EXPORT_CORE Float evalCubicInterp1D(Float x, const Float *values,
59  size_t size, Float min, Float max, bool extrapolate = false);
60 
61 /**
62  * \brief Evaluate a cubic spline interpolant of a \a nonuniformly sampled 1D function
63  *
64  * This implementation relies on Catmull-Rom splines, i.e. it uses finite
65  * differences to approximate the derivatives at the endpoints of each spline
66  * segment.
67  *
68  * \param x
69  * Evaluation point
70  * \param nodes
71  * Floating point array containing \c size nonuniformly spaced values
72  * denoting positions the where the function to be interpolated was evaluated.
73  * They must be provided in \a increasing order.
74  * \param values
75  * Floating point array containing function evaluations matched to
76  * the entries of \c nodes.
77  * \param size
78  * Denotes the size of the \c values array
79  * \param extrapolate
80  * Extrapolate values when \c x is out of range? (default: \c false)
81  * \return
82  * The interpolated value or zero when <tt>extrapolate=false</tt>tt>
83  * and \c x lies outside of \a [\c min, \c max]
84  */
85 extern MTS_EXPORT_CORE Float evalCubicInterp1DN(Float x, const Float *nodes,
86  const Float *values, size_t size, bool extrapolate = false);
87 
88 /**
89  * \brief Computes the definite integral over a segment of a uniformly
90  * sampled 1D Catmull-Rom spline interpolant
91  *
92  * This is useful for sampling spline segments as part of an importance
93  * sampling scheme (in conjunction with \ref sampleCubicInterp1D)
94  *
95  * \param idx
96  * Denotes the desires spline segment (must be between 0 and size-2)
97  * \param values
98  * Floating point array containing \c size regularly spaced evaluations
99  * in the range [\c min,\c max] of the function to be approximated.
100  * \param size
101  * Denotes the size of the \c values array
102  * \param min
103  * Position of the first knot
104  * \param max
105  * Position of the last knot
106  * \return
107  * The definite integral over the specified segment
108  */
110  const Float *values, size_t size, Float min, Float max);
111 
112 /**
113  * \brief Computes the definite integral over a segment of a \a nonuniformly
114  * sampled 1D Catmull-Rom spline interpolant
115  *
116  * This is useful for sampling spline segments as part of an importance
117  * sampling scheme (in conjunction with \ref sampleCubicInterp1D)
118  *
119  * \param idx
120  * Denotes the desires spline segment (must be between 0 and size-2)
121  * \param nodes
122  * Floating point array containing \c size nonuniformly spaced values
123  * denoting positions the where the function to be interpolated was evaluated.
124  * They must be provided in \a increasing order.
125  * \param values
126  * Floating point array containing function evaluations matched to
127  * the entries of \c nodes.
128  * \param size
129  * Denotes the size of the \c values array
130  * \return
131  * The definite integral over the specified segment
132  */
134  const Float *nodes, const Float *values, size_t size);
135 
136 /**
137  * \brief Importance sample a segment of a uniformly sampled 1D Catmull-Rom
138  * spline interpolant
139  *
140  * \param idx
141  * Denotes the desires spline segment (must be between 0 and size-2)
142  * \param values
143  * Floating point array containing \c size regularly spaced evaluations
144  * in the range [\c min,\c max] of the function to be approximated.
145  * \param size
146  * Denotes the size of the \c values array
147  * \param min
148  * Position of the first knot
149  * \param max
150  * Position of the last knot
151  * \param sample
152  * A uniformly distributed random sample in the interval <tt>[0,1]</tt>
153  * \param fval
154  * If set to a non-NULL pointer, this argument will be used to return
155  * the value of the spline at the sampled position
156  * \return
157  * The sampled position
158  */
159 extern MTS_EXPORT_CORE Float sampleCubicInterp1D(size_t idx, const Float *values,
160  size_t size, Float min, Float max, Float sample, Float *fval = NULL);
161 
162 /**
163  * \brief Importance sample a segment of a \a nonuniformly sampled 1D Catmull-Rom
164  * spline interpolant
165  *
166  * \param idx
167  * Denotes the desires spline segment (must be between 0 and size-2)
168  * \param nodes
169  * Floating point array containing \c size nonuniformly spaced values
170  * denoting positions the where the function to be interpolated was evaluated.
171  * They must be provided in \a increasing order.
172  * \param values
173  * Floating point array containing function evaluations matched to
174  * the entries of \c nodes.
175  * \param size
176  * Denotes the size of the \c values array
177  * \param sample
178  * A uniformly distributed random sample in the interval <tt>[0,1]</tt>
179  * \param fval
180  * If set to a non-NULL pointer, this argument will be used to return
181  * the value of the spline at the sampled position
182  * \return
183  * The sampled position
184  */
185 extern MTS_EXPORT_CORE Float sampleCubicInterp1DN(size_t idx, const Float *nodes,
186  const Float *values, size_t size, Float sample, Float *fval = NULL);
187 
188 /**
189  * \brief Evaluate a cubic spline interpolant of a uniformly sampled 2D function
190  *
191  * This implementation relies on a tensor product of Catmull-Rom splines, i.e. it uses
192  * finite differences to approximate the derivatives at the endpoints of each spline
193  * patch.
194  *
195  * \param p
196  * Evaluation point
197  * \param values
198  * A 2D floating point array of <tt>size.x*size.y</tt> cells containing regularly
199  * spaced evaluations of the function to be interpolated on the domain <tt>[min, max]</tt>.
200  * Consecutive entries of this array correspond to increments in the 'x' coordinate.
201  * \param size
202  * Denotes the size of the \c values array (along each dimension)
203  * \param min
204  * Position of the first knot on each dimension
205  * \param max
206  * Position of the last knot on each dimension
207  * \param extrapolate
208  * Extrapolate values when \c p is out of range? (default: \c false)
209  * \return
210  * The interpolated value or zero when <tt>extrapolate=false</tt>tt> and
211  * \c p lies outside of the knot range
212  */
213 extern MTS_EXPORT_CORE Float evalCubicInterp2D(const Point2 &p, const Float *values,
214  const Size2 &size, const Point2 &min, const Point2 &max, bool extrapolate = false);
215 
216 /**
217  * \brief Evaluate a cubic spline interpolant of a \a nonuniformly sampled 2D function
218  *
219  * This implementation relies on a tensor product of Catmull-Rom splines, i.e. it uses
220  * finite differences to approximate the derivatives at the endpoints of each spline
221  * region.
222  *
223  * When the underlying function is sampled on a regular grid, \ref evalCubicInterp2D()
224  * should be preferred, since value lookups will be considerably faster.
225  *
226  * \param p
227  * Evaluation point
228  * \param nodes
229  * Pointer to a list for each dimension denoting the positions where the function
230  * to be interpolated was evaluated. The <tt>i</tt>-th array must have
231  * size <tt>size[i]</tt> and contain position values in \a increasing order.
232  * \param values
233  * A 2D floating point array of <tt>size.x*size.y</tt> cells containing nonuniformly
234  * spaced evaluations of the function to be interpolated on the domain <tt>[min, max]</tt>.
235  * Consecutive entries of this array correspond to increments in the 'x' coordinate.
236  * \param size
237  * Denotes the size of the \c values array (along each dimension)
238  * \param extrapolate
239  * Extrapolate values when \c p is out of range? (default: \c false)
240  * \return
241  * The interpolated value or zero when <tt>extrapolate=false</tt>tt> and
242  * \c p lies outside of the knot range
243  */
244 extern MTS_EXPORT_CORE Float evalCubicInterp2DN(const Point2 &p, const Float **nodes,
245  const Float *values, const Size2 &size, bool extrapolate = false);
246 
247 /**
248  * \brief Evaluate a cubic spline interpolant of a uniformly sampled 3D function
249  *
250  * This implementation relies on a tensor product of Catmull-Rom splines, i.e. it uses
251  * finite differences to approximate the derivatives at the endpoints of each spline
252  * region.
253  *
254  * \param p
255  * Evaluation point of the interpolant
256  * \param values
257  * A 3D floating point array of <tt>size.x*size.y*size.z</tt> cells containing regularly
258  * spaced evaluations of the function to be interpolated on the domain <tt>[min, max]</tt>.
259  * Consecutive entries of this array correspond to increments in the 'x' coordinate,
260  * then 'y', and finally 'z' increments.
261  * \param size
262  * Denotes the size of the \c values array (along each dimension)
263  * \param min
264  * Position of the first knot on each dimension
265  * \param max
266  * Position of the last knot on each dimension
267  * \param extrapolate
268  * Extrapolate values when \c p is out of range? (default: \c false)
269  * \return
270  * The interpolated value or zero when <tt>extrapolate=false</tt>tt> and
271  * \c p lies outside of the knot range
272  */
273 extern MTS_EXPORT_CORE Float evalCubicInterp3D(const Point3 &p, const Float *values,
274  const Size3 &size, const Point3 &min, const Point3 &max, bool extrapolate = false);
275 
276 /**
277  * \brief Evaluate a cubic spline interpolant of a \a nonuniformly sampled 3D function
278  *
279  * This implementation relies on a tensor product of Catmull-Rom splines, i.e. it uses
280  * finite differences to approximate the derivatives at the endpoints of each spline
281  * region.
282  *
283  * When the underlying function is sampled on a regular grid, \ref evalCubicInterp3D()
284  * should be preferred, since value lookups will be considerably faster.
285  *
286  * \param p
287  * Evaluation point
288  * \param nodes
289  * Pointer to a list for each dimension denoting the positions where the function
290  * to be interpolated was evaluated. The <tt>i</tt>-th array must have
291  * size <tt>size[i]</tt> and contain position values in \a increasing order.
292  * \param values
293  * A 2D floating point array of <tt>size.x*size.y</tt> cells containing nonuniformly
294  * spaced evaluations of the function to be interpolated on the domain <tt>[min, max]</tt>.
295  * Consecutive entries of this array correspond to increments in the 'x' coordinate,
296  * then 'y', and finally 'z' increments.
297  * \param size
298  * Denotes the size of the \c values array (along each dimension)
299  * \param extrapolate
300  * Extrapolate values when \c p is out of range? (default: \c false)
301  * \return
302  * The interpolated value or zero when <tt>extrapolate=false</tt>tt> and
303  * \c p lies outside of the knot range
304  */
305 extern MTS_EXPORT_CORE Float evalCubicInterp3DN(const Point3 &p, const Float **nodes,
306  const Float *values, const Size3 &size, bool extrapolate = false);
307 
308 //! @}
309 // -----------------------------------------------------------------------
310 
311 /*! @} */
312 
314 
315 #endif /* __MITSUBA_CORE_SPLINE_H_ */
Float evalCubicInterp1DN(Float x, const Float *nodes, const Float *values, size_t size, bool extrapolate=false)
Evaluate a cubic spline interpolant of a nonuniformly sampled 1D function.
Float evalCubicInterp2DN(const Point2 &p, const Float **nodes, const Float *values, const Size2 &size, bool extrapolate=false)
Evaluate a cubic spline interpolant of a nonuniformly sampled 2D function.
Float evalCubicInterp3DN(const Point3 &p, const Float **nodes, const Float *values, const Size3 &size, bool extrapolate=false)
Evaluate a cubic spline interpolant of a nonuniformly sampled 3D function.
#define MTS_EXPORT_CORE
Definition: getopt.h:29
Float evalCubicInterp1D(Float x, const Float *values, size_t size, Float min, Float max, bool extrapolate=false)
Evaluate a cubic spline interpolant of a uniformly sampled 1D function.
Float integrateCubicInterp1D(size_t idx, const Float *values, size_t size, Float min, Float max)
Computes the definite integral over a segment of a uniformly sampled 1D Catmull-Rom spline interpolan...
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
Float evalCubicInterp2D(const Point2 &p, const Float *values, const Size2 &size, const Point2 &min, const Point2 &max, bool extrapolate=false)
Evaluate a cubic spline interpolant of a uniformly sampled 2D function.
Definition: fwd.h:99
Float integrateCubicInterp1DN(size_t idx, const Float *nodes, const Float *values, size_t size)
Computes the definite integral over a segment of a nonuniformly sampled 1D Catmull-Rom spline interpo...
Definition: fwd.h:96
Float sampleCubicInterp1DN(size_t idx, const Float *nodes, const Float *values, size_t size, Float sample, Float *fval=NULL)
Importance sample a segment of a nonuniformly sampled 1D Catmull-Rom spline interpolant.
Definition: fwd.h:100
Float sampleCubicInterp1D(size_t idx, const Float *values, size_t size, Float min, Float max, Float sample, Float *fval=NULL)
Importance sample a segment of a uniformly sampled 1D Catmull-Rom spline interpolant.
Float evalCubicInterp3D(const Point3 &p, const Float *values, const Size3 &size, const Point3 &min, const Point3 &max, bool extrapolate=false)
Evaluate a cubic spline interpolant of a uniformly sampled 3D function.
Definition: fwd.h:95
#define MTS_NAMESPACE_END
Definition: platform.h:138