npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
StorableInterpolationFunctor.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
2 #define NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
3 
4 /*!
5 // \file StorableInterpolationFunctor.hh
6 //
7 // \brief Storable multivariate functor represented by a multilinear
8 // interpolation/extrapolation table
9 //
10 // Author: I. Volobouev
11 //
12 // July 2012
13 */
14 
18 
19 namespace npstat {
20  /**
21  // This class adapts LinInterpolatedTableND template to the
22  // StorableMultivariateFunctor interface
23  */
24  template
25  <
26  class Numeric,
27  class Axis = UniformAxis,
28  class Converter = Same<Numeric>
29  >
31  {
32  template <typename Num2, typename Axis2, typename Conv2>
33  friend class StorableInterpolationFunctor;
34 
35  public:
37 
38  //@{
39  /** Constructor from a pre-existing table */
40  template <class Num2>
43  : StorableMultivariateFunctor(), table_(table) {}
44 
45  template <class Num2>
48  const std::string& descr)
49  : StorableMultivariateFunctor(descr), table_(table) {}
50  //@}
51 
52  /** Converting copy constructor */
53  template <class Num2, class Conv2>
57  table_(tab.table_) {}
58 
59  //@{
60  /**
61  // Constructor which builds the table in place.
62  // It basically passses its arguments to the
63  // corresponding constructor of LinInterpolatedTableND.
64  */
66  const std::vector<Axis>& axes,
67  const std::vector<std::pair<bool,bool> >& interpolationType,
68  const char* functionLabel=0)
70  table_(axes, interpolationType, functionLabel) {}
71 
73  const Axis& xAxis, bool leftX, bool rightX,
74  const char* functionLabel=0)
76  table_(xAxis, leftX, rightX, functionLabel) {}
77 
78  inline StorableInterpolationFunctor(
79  const Axis& xAxis, bool leftX, bool rightX,
80  const Axis& yAxis, bool leftY, bool rightY,
81  const char* functionLabel=0)
82  : StorableMultivariateFunctor(),
83  table_(xAxis, leftX, rightX,
84  yAxis, leftY, rightY, functionLabel) {}
85 
86  inline StorableInterpolationFunctor(
87  const Axis& xAxis, bool leftX, bool rightX,
88  const Axis& yAxis, bool leftY, bool rightY,
89  const Axis& zAxis, bool leftZ, bool rightZ,
90  const char* functionLabel=0)
91  : StorableMultivariateFunctor(),
92  table_(xAxis, leftX, rightX,
93  yAxis, leftY, rightY,
94  zAxis, leftZ, rightZ, functionLabel) {}
95 
96  inline StorableInterpolationFunctor(
97  const Axis& xAxis, bool leftX, bool rightX,
98  const Axis& yAxis, bool leftY, bool rightY,
99  const Axis& zAxis, bool leftZ, bool rightZ,
100  const Axis& tAxis, bool leftT, bool rightT,
101  const char* functionLabel=0)
102  : StorableMultivariateFunctor(),
103  table_(xAxis, leftX, rightX,
104  yAxis, leftY, rightY,
105  zAxis, leftZ, rightZ,
106  tAxis, leftT, rightT, functionLabel) {}
107 
108  inline StorableInterpolationFunctor(
109  const Axis& xAxis, bool leftX, bool rightX,
110  const Axis& yAxis, bool leftY, bool rightY,
111  const Axis& zAxis, bool leftZ, bool rightZ,
112  const Axis& tAxis, bool leftT, bool rightT,
113  const Axis& vAxis, bool leftV, bool rightV,
114  const char* functionLabel=0)
115  : StorableMultivariateFunctor(),
116  table_(xAxis, leftX, rightX,
117  yAxis, leftY, rightY,
118  zAxis, leftZ, rightZ,
119  tAxis, leftT, rightT,
120  vAxis, leftV, rightV, functionLabel) {}
121  //@}
122 
123  virtual ~StorableInterpolationFunctor() {}
124 
125  virtual unsigned minDim() const {return table_.dim();};
126 
127  virtual double operator()(const double* point, unsigned dim) const
128  {return conv_(table_(point, dim));}
129 
130  //@{
131  /** Retrieve the underlying LinInterpolatedTableND object */
132  inline Table& interpolator() {return table_;}
133  inline const Table& interpolator() const {return table_;}
134  //@}
135 
136  //@{
137  /** Retrieve the tabulated data */
138  inline ArrayND<Numeric>& table() {return table_.table();}
139  inline const ArrayND<Numeric>& table() const {return table_.table();}
140  //@}
141 
142  /** Change the coordinate converter */
143  inline void setConverter(const Converter& conv) {conv_ = conv;}
144 
145  //@{
146  // Method related to "geners" I/O
147  virtual gs::ClassId classId() const {return gs::ClassId(*this);}
148  virtual bool write(std::ostream& of) const;
149  //@}
150 
151  // I/O methods needed for reading
152  static inline const char* classname();
153  static inline unsigned version() {return 1;}
154  static StorableInterpolationFunctor* read(
155  const gs::ClassId& id, std::istream& in);
156 
157  protected:
158  virtual bool isEqual(const StorableMultivariateFunctor& other) const
159  {
160  // Note the use of static_cast rather than dynamic_cast below.
161  // static_cast works faster and it is guaranteed to succeed here.
162  const StorableInterpolationFunctor& r =
163  static_cast<const StorableInterpolationFunctor&>(other);
164  return table_ == r.table_ &&
165  this->description() == other.description();
166  }
167 
168  private:
170 
171  Table table_;
172  Converter conv_;
173  };
174 }
175 
176 #include "npstat/stat/StorableInterpolationFunctor.icc"
177 
178 #endif // NPSTAT_STORABLEINTERPOLATIONFUNCTOR_HH_
Multilinear interpolation/extrapolation on rectangular grids.
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Interface definition for storable multivariate functors.
Definition: LinInterpolatedTableND.hh:32
unsigned dim() const
Definition: LinInterpolatedTableND.hh:117
const ArrayND< Numeric > & table() const
Definition: LinInterpolatedTableND.hh:131
Definition: StorableInterpolationFunctor.hh:31
Table & interpolator()
Definition: StorableInterpolationFunctor.hh:132
virtual gs::ClassId classId() const
Definition: StorableInterpolationFunctor.hh:147
void setConverter(const Converter &conv)
Definition: StorableInterpolationFunctor.hh:143
StorableInterpolationFunctor(const StorableInterpolationFunctor< Num2, Axis, Conv2 > &tab)
Definition: StorableInterpolationFunctor.hh:54
StorableInterpolationFunctor(const LinInterpolatedTableND< Num2, Axis > &table)
Definition: StorableInterpolationFunctor.hh:41
virtual bool isEqual(const StorableMultivariateFunctor &other) const
Definition: StorableInterpolationFunctor.hh:158
virtual unsigned minDim() const
Definition: StorableInterpolationFunctor.hh:125
virtual double operator()(const double *point, unsigned dim) const
Definition: StorableInterpolationFunctor.hh:127
StorableInterpolationFunctor(const std::vector< Axis > &axes, const std::vector< std::pair< bool, bool > > &interpolationType, const char *functionLabel=0)
Definition: StorableInterpolationFunctor.hh:65
ArrayND< Numeric > & table()
Definition: StorableInterpolationFunctor.hh:138
Definition: StorableMultivariateFunctor.hh:24
const std::string & description() const
Definition: StorableMultivariateFunctor.hh:35
Definition: AbsArrayProjector.hh:14