1 #ifndef LINEAR_INTERPOLATE_H 2 #define LINEAR_INTERPOLATE_H 7 #include <boost/shared_ptr.hpp> 21 virtual const TX&
x_min()
const = 0;
22 virtual const TX&
x_max()
const = 0;
40 const TX&
x_min()
const {
return x0_; }
41 const TX&
x_max()
const {
return x0_; }
43 void print(std::ostream& Os)
const { Os <<
"Return1Point"; }
60 public Printable<LinearInterpolate2Point<TX, TY> > {
64 : x0_(x0), x1_(x1), y0_(y0), delta_y0_((y1 - y0) / (x1 - x0))
68 const TX&
x_min()
const {
return x0_; }
69 const TX&
x_max()
const {
return x1_; }
70 TY
operator()(
const TX& x)
const {
return TY(y0_ + delta_y0_ * (x - x0_)); }
71 void print(std::ostream& Os)
const { Os <<
"LinearInterpolate2Point"; }
97 public Printable<LinearInterpolate<TX, TY> > {
99 enum BehaviorOutOfRange
100 {OUT_OF_RANGE_EXTRAPOLATE = 0, OUT_OF_RANGE_CLIP, OUT_OF_RANGE_ERROR};
109 I2 ystart, BehaviorOutOfRange Out_of_range = OUT_OF_RANGE_EXTRAPOLATE)
110 : out_of_range(Out_of_range)
112 if(std::distance(xstart, xend) == 0) {
116 }
else if(std::distance(xstart, xend) == 1) {
119 const TX& x0 = *xstart;
120 const TY& y0 = *ystart;
125 }
else while(xstart != xend) {
127 const TX& x0 = *xstart++;
128 const TY& y0 = *ystart++;
131 const TX& x1 = *xstart;
132 const TY& y1 = *ystart;
143 throw Exception(
"Can not interpolate since interpolation map is empty.");
147 std::map<TX, boost::shared_ptr<InterpolatePoint<TX, TY> > >::
148 const_iterator Itype;
149 Itype i = inter.lower_bound(x);
150 if(i == inter.end()) {
151 switch(out_of_range) {
152 case OUT_OF_RANGE_ERROR:
154 std::stringstream err_msg;
155 err_msg <<
"Linear interpolation point " 156 << x <<
" is past the end of interpolation range: " 157 <<
"[" << inter.begin()->first
158 <<
", " << inter.rbegin()->first <<
"]";
161 case OUT_OF_RANGE_EXTRAPOLATE:
162 return (*inter.rbegin()->second)(x);
163 case OUT_OF_RANGE_CLIP:
164 return (*inter.rbegin()->second)(inter.rbegin()->second->x_max());
166 throw Exception(
"Unknown out_of_range value");
169 if(x >= i->second->x_min())
170 return (*i->second)(x);
171 switch(out_of_range) {
172 case OUT_OF_RANGE_ERROR:
174 std::stringstream err_msg;
175 err_msg <<
"Linear interpolation point " 176 << x <<
" is outside of interpolation range: " 177 <<
"[" << inter.begin()->first
178 <<
", " << inter.rbegin()->first <<
"]";
181 case OUT_OF_RANGE_EXTRAPOLATE:
182 return (*i->second)(x);
183 case OUT_OF_RANGE_CLIP:
184 return (*i->second)(i->second->x_min());
186 throw Exception(
"Unknown out_of_range value");
190 void print(std::ostream& Os)
const { Os <<
"LinearInterpolate"; }
192 std::map<TX, boost::shared_ptr<InterpolatePoint<TX, TY> > > inter;
193 BehaviorOutOfRange out_of_range;
#define range_max_check(V, Max)
Range check.
This just returns the same y value, always.
virtual TY operator()(const TX &x) const =0
This class takes a set of points and values, and linearly interpolates between those values...
This is the base of the exception hierarchy for Full Physics code.
void print(std::ostream &Os) const
This is a Mixin for classes that can be printed.
Interface for interpolating values.
LinearInterpolate(I1 xstart, I1 xend, I2 ystart, BehaviorOutOfRange Out_of_range=OUT_OF_RANGE_EXTRAPOLATE)
Constructor.
void print(std::ostream &Os) const
This does linear interpolate between two points.
There are a number of tools that can be used to do "Automatic Differentiation" (see for example http:...
LinearInterpolate2Point(const TX &x0, const TY &y0, const TX &x1, const TY &y1)
TY operator()(const TX &x) const
virtual const TX & x_min() const =0
Contains classes to abstract away details in various Spurr Radiative Transfer software.
TY operator()(const TX &x) const
void print(std::ostream &Os) const
TY operator()(const TX &x) const
virtual const TX & x_max() const =0
Return1Point(const TX &x0, const TY &y0)