LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lsst::afw::math::InterpolateConstant Class Reference
Inheritance diagram for lsst::afw::math::InterpolateConstant:
lsst::afw::math::Interpolate

Public Member Functions

virtual ~InterpolateConstant ()
 
virtual double interpolate (double const x) const
 Interpolate a constant to the point xInterp. More...
 
- Public Member Functions inherited from lsst::afw::math::Interpolate
virtual ~Interpolate ()
 

Private Member Functions

 InterpolateConstant (std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style)
 

Private Attributes

std::vector< double >
::const_iterator 
_old
 

Friends

boost::shared_ptr< InterpolatemakeInterpolate (std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style)
 

Additional Inherited Members

- Public Types inherited from lsst::afw::math::Interpolate
enum  Style {
  UNKNOWN = -1, CONSTANT = 0, LINEAR = 1, NATURAL_SPLINE = 2,
  CUBIC_SPLINE = 3, CUBIC_SPLINE_PERIODIC = 4, AKIMA_SPLINE = 5, AKIMA_SPLINE_PERIODIC = 6,
  NUM_STYLES
}
 
- Protected Member Functions inherited from lsst::afw::math::Interpolate
 Interpolate (std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=UNKNOWN)
 
 Interpolate (std::pair< std::vector< double >, std::vector< double > > const xy, Interpolate::Style const style=UNKNOWN)
 
- Protected Attributes inherited from lsst::afw::math::Interpolate
std::vector< double > const _x
 
std::vector< double > const _y
 
Interpolate::Style const _style
 

Detailed Description

Definition at line 82 of file Interpolate.cc.

Constructor & Destructor Documentation

virtual lsst::afw::math::InterpolateConstant::~InterpolateConstant ( )
inlinevirtual

Definition at line 86 of file Interpolate.cc.

86 {}
lsst::afw::math::InterpolateConstant::InterpolateConstant ( std::vector< double > const &  x,
std::vector< double > const &  y,
Interpolate::Style const  style 
)
inlineprivate
Parameters
xthe x-values of points
ythe values at x[]
styledesired interpolator

Definition at line 89 of file Interpolate.cc.

92  :
93  Interpolate(recenter(x, y)), _old(_x.begin()) {}
std::vector< double >::const_iterator _old
Definition: Interpolate.cc:94
std::vector< double > const _x
Definition: Interpolate.h:67
Interpolate(std::vector< double > const &x, std::vector< double > const &y, Interpolate::Style const style=UNKNOWN)
Definition: Interpolate.h:60

Member Function Documentation

double lsst::afw::math::InterpolateConstant::interpolate ( double const  x) const
virtual

Interpolate a constant to the point xInterp.

Implements lsst::afw::math::Interpolate.

Definition at line 99 of file Interpolate.cc.

101 {
102  //
103  // Look for the interval wherein lies xInterp. We could naively use std::upper_bound, but that requires a
104  // logarithmic time lookup so we'll cache the previous answer in _old -- this is a good idea if people
105  // usually call this routine repeatedly for a range of x
106  //
107  // We start by searching up from _old
108  //
109  if (xInterp < *_old) { // We're to the left of the cache
110  if (_old == _x.begin()) { // ... actually off the array
111  return _y[0];
112  }
113  _old = _x.begin(); // reset the cached point to the start of the array
114  } else { // see if we're still in the same interval
115  if (_old < _x.end() - 1 and xInterp < *(_old + 1)) { // we are, so we're done
116  return _y[_old - _x.begin()];
117  }
118  }
119  // We're to the right of the cached point and not in the same inverval, so search up from _old
120  std::vector<double>::const_iterator low = std::upper_bound(_old, _x.end(), xInterp);
121  //
122  // Did that work?
123  if (low == _old && _old != _x.begin()) {
124  // No. Sigh. Search the entire range.
125  low = std::upper_bound(_x.begin(), low + 1, xInterp);
126  }
127  //
128  // OK, we've found the right interval. Return the desired value, being careful at the ends
129  //
130  if (low == _x.end()) {
131  return _y[_y.size() - 1];
132  } else if (low == _x.begin()) {
133  return _y[0];
134  } else {
135  --low;
136  _old = low;
137  return _y[low - _x.begin()];
138  }
139 }
std::vector< double >::const_iterator _old
Definition: Interpolate.cc:94
std::vector< double > const _x
Definition: Interpolate.h:67
std::vector< double > const _y
Definition: Interpolate.h:68

Friends And Related Function Documentation

boost::shared_ptr< Interpolate > makeInterpolate ( std::vector< double > const &  x,
std::vector< double > const &  y,
Interpolate::Style const  style 
)
friend

A factory function to make Interpolate objects

Member Data Documentation

std::vector<double>::const_iterator lsst::afw::math::InterpolateConstant::_old
mutableprivate

Definition at line 94 of file Interpolate.cc.


The documentation for this class was generated from the following file: