The spica renderer
interpolation.h
1 #ifdef _MSC_VER
2 #pragma once
3 #endif
4 
5 #ifndef _SPICA_INTERPOLATION_H_
6 #define _SPICA_INTERPOLATION_H_
7 
8 #include <vector>
9 
10 #include "../core/common.h"
11 
12 namespace spica {
13 
14 class SPICA_EXPORTS CatmullRom {
15 public:
16  // Public methods
17  CatmullRom();
18  CatmullRom(const std::vector<double>& fs,
19  const std::vector<double>& xs);
20  CatmullRom(const CatmullRom&) = default;
21  CatmullRom(CatmullRom&& cr);
22 
23  CatmullRom& operator=(const CatmullRom&) = default;
24  CatmullRom& operator=(CatmullRom&& cr);
25 
26  inline double x(int i) const {
27  Assertion(i >= 0 && i < size(), "Index out of bounds!!");
28  return xs_[i];
29  }
30 
31  inline double f(int i) const {
32  Assertion(i >= 0 && i < size(), "Index out of bounds!!: %d for %zu", i, fs_.size());
33  return fs_[i];
34  }
35 
36  double evaluate(double x) const;
37  double sample(double rand, double* fval = nullptr,
38  double* pdf = nullptr) const;
39 
40  inline int size() const { return static_cast<int>(fs_.size()); }
41 
42 private:
43  // Private methods
44  bool weights(double x, double* w0, double* w1, double* w2,
45  double* w3, int* offset = nullptr) const;
46 
47  // Private fields
48  std::vector<double> xs_;
49  std::vector<double> fs_;
50  std::vector<double> Fs_;
51 };
52 
53 class SPICA_EXPORTS CatmullRom2D {
54 public:
55  // Public methods
56  CatmullRom2D();
57  CatmullRom2D(const std::vector<std::vector<double>>& fs,
58  const std::vector<double>& xs,
59  const std::vector<double>& ys);
60  CatmullRom2D(const CatmullRom2D&) = default;
62 
63  CatmullRom2D& operator=(const CatmullRom2D&) = default;
64  CatmullRom2D& operator=(CatmullRom2D&&);
65  inline double operator()(int i, int j) const {
66  return fs_[i][j];
67  }
68 
69  double evaluate(double x, double y) const;
70  double sample(double rand1, double rand2, double* fval = nullptr,
71  double* pdf = nullptr) const;
72 
73  inline const std::vector<double>& xs() const { return xs_; }
74  inline const std::vector<double>& ys() const { return ys_; }
75  inline const std::vector<double>& marginalY() const { return marginalY_; }
76 
77 private:
78  std::vector<std::vector<double>> fs_;
79  std::vector<std::vector<double>> cdf_;
80  std::vector<double> marginalY_;
81  std::vector<double> xs_;
82  std::vector<double> ys_;
83 };
84 
85 // -----------------------------------------------------------------------------
86 // Interpolation utility functions
87 // -----------------------------------------------------------------------------
88 
89 SPICA_EXPORTS
90 bool catmullRomWeight(const std::vector<double>& nodes, double x,
91  double* w0, double* w1, double* w2, double* w3,
92  int* offset);
93 
94 SPICA_EXPORTS
95 double integrateCatmullRom(const std::vector<double>& xs,
96  const std::vector<double>& fs,
97  std::vector<double>* cdf = nullptr);
98 
99 } // namespace spica
100 
101 #endif // _SPICA_INTERPOLATION_H_
Definition: interpolation.h:53
Definition: interpolation.h:14