smooth_linear_spline.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_SMOOTH_LINEAR_SPLINE_HPP_
13 #define ECL_SMOOTH_LINEAR_SPLINE_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <ecl/config/macros.hpp>
20 #include <ecl/concepts/streams.hpp>
21 #include <ecl/containers/array.hpp>
22 #include <ecl/exceptions/data_exception.hpp>
23 #include <ecl/exceptions/standard_exception.hpp>
24 #include "polynomial.hpp"
25 #include "macros.hpp"
26 
27 /*****************************************************************************
28 ** Namespaces
29 *****************************************************************************/
30 
31 namespace ecl {
32 
33 /*****************************************************************************
34 ** Interface [SmoothLinearSpline]
35 *****************************************************************************/
45 class ecl_geometry_PUBLIC SmoothLinearSpline {
46 public:
53  SmoothLinearSpline() {}
77  SmoothLinearSpline(const Array<double>& x_data, const Array<double>& y_data, double a_max) throw (DataException<int>);
78 
79  virtual ~SmoothLinearSpline() {}
80 
90  double operator()(const double &x) const ecl_assert_throw_decl(StandardException);
101  double derivative(const double &x) const ecl_assert_throw_decl(StandardException);
110  double dderivative(const double &x) const ecl_assert_throw_decl(StandardException);
111 
120  const Array<double>& domain() const { return discretised_domain; }
121 
122  /*********************
123  * Static Constructor
124  **********************/
136  static SmoothLinearSpline Interpolation(const Array<double>& x_data, const Array<double>& y_data, double a_max) throw (DataException<int>)
137  {
138  try {
139  return SmoothLinearSpline(x_data, y_data, a_max);
140  } catch ( DataException<int> &e ) {
141  throw DataException<int>(LOC,e);
142  }
143  return SmoothLinearSpline(); // avoid a warning because of the rethrown exception.
144  }
145 
146  /******************************************
147  * Streaming
148  *******************************************/
162  template <typename OutputStream>
163  friend OutputStream& operator << (OutputStream &ostream, const SmoothLinearSpline &smooth_linear_spline);
164 
165 private:
166  Array<double> discretised_domain; // 2*N points (2 end points + 2*(N-1) corner points)
167  Array<LinearFunction> segments; // N linear segments
168  Array<QuinticPolynomial> corners; // N-1 corners
169 };
170 
171 /*****************************************************************************
172 ** Implementation [SmoothLinearSpline][Streaming]
173 *****************************************************************************/
174 
175 template <typename OutputStream>
176 OutputStream& operator << (OutputStream &ostream, const SmoothLinearSpline &smooth_linear_spline) {
177 
179 
180  ostream << smooth_linear_spline.segments[0] << "\n";
181  for ( unsigned int i = 1; i < smooth_linear_spline.segments.size(); ++i ) {
182  ostream << smooth_linear_spline.corners[i-1] << "\n";
183  ostream << smooth_linear_spline.segments[i] << "\n";
184  }
185  ostream.flush();
186  return ostream;
187 }
188 
189 } // namespace ecl
190 
191 #endif /* ECL_SMOOTH_LINEAR_SPLINE_HPP_ */
Storage container for a smoothed linear spline interpolation.
Defines validating functionality for the streams concept.
#define LOC
Stringify the line of code you are at.
#define ecl_geometry_PUBLIC
OutputStream & operator<<(OutputStream &ostream, const Void void_object)
Output stream operator for Void objects.
Definition: void.hpp:76
Array< QuinticPolynomial > corners
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
#define ecl_compile_time_concept_check(Model)
Compile time concept checking assertion.
Array< LinearFunction > segments


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:38