cubic_spline.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_GEOMETRY_CUBIC_SPLINE_HPP_
13 #define ECL_GEOMETRY_CUBIC_SPLINE_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include "polynomial.hpp"
20 #include <ecl/config/macros.hpp>
21 #include <ecl/concepts/macros.hpp>
22 #include <ecl/concepts/streams.hpp>
23 #include <ecl/concepts/containers.hpp>
24 #include <ecl/containers/array.hpp>
25 #include <ecl/exceptions/standard_exception.hpp>
26 #include <ecl/utilities/blueprints.hpp>
27 
28 /*****************************************************************************
29 ** Namespaces
30 *****************************************************************************/
31 
32 namespace ecl {
33 
34 /*****************************************************************************
35 ** Forward Declarations
36 *****************************************************************************/
37 
38 class CubicSpline;
39 
40 namespace blueprints {
41 
42 class C2CubicSpline;
43 class DerivativeHeuristicCubicSpline;
44 
45 } // namespace blueprints
46 
47 /*****************************************************************************
48 ** BluePrintFactory
49 *****************************************************************************/
58 template<>
59 class ECL_PUBLIC BluePrintFactory< CubicSpline > {
60  public:
72  static blueprints::C2CubicSpline Natural(const Array<double>& x_set, const Array<double>& y_set);
85  static blueprints::C2CubicSpline ContinuousDerivatives(
86  const Array<double>& x_set, const Array<double>& y_set, const double ydot_0, const double ydot_f);
100  static blueprints::DerivativeHeuristicCubicSpline DerivativeHeuristic(
101  const Array<double>& x_set, const Array<double>& y_set, const double ydot_0, const double ydot_f);
102 
103  virtual ~BluePrintFactory() {}
104 };
105 
106 /*****************************************************************************
107 ** Interface [CubicSpline]
108 *****************************************************************************/
123 class ECL_PUBLIC CubicSpline : public BluePrintFactory< CubicSpline > {
124  public:
125  /******************************************
126  ** Constructors
127  *******************************************/
133  CubicSpline () {};
160  template<typename Derived>
161  CubicSpline(const BluePrint< Derived > &blueprint) {
162  blueprint.implementApply(*this);
163  }
164  virtual ~CubicSpline () {};
165 
166  /******************************************
167  ** Access
168  *******************************************/
169  friend class blueprints::DerivativeHeuristicCubicSpline;
170  friend class blueprints::C2CubicSpline;
179  double operator()(const double &x) const ecl_assert_throw_decl(StandardException);
188  double derivative(double x) const ecl_assert_throw_decl(StandardException);
197  double dderivative(double x) const ecl_assert_throw_decl(StandardException);
198 
206  const Array<double>& domain() { return discretised_domain; }
215  const Array<CubicPolynomial>& polynomials() { return cubic_polynomials; }
216 
217  /******************************************
218  ** Streaming
219  *******************************************/
231  template <typename OutputStream>
232  friend OutputStream& operator << (OutputStream &ostream, const CubicSpline &cubic_spline);
233 
234  private:
235  Array<double> discretised_domain; // N+1 x_i's
236  // Would normally use pointers here, but the polynomials have fixed storage
237  // size, the copy cost is small and the access times will be faster this way.
238  Array<CubicPolynomial> cubic_polynomials; // N polynomials
239 };
240 
241 /*****************************************************************************
242 ** Implementation [CubicSpline][Streaming]
243 *****************************************************************************/
244 
245 template <typename OutputStream>
246 OutputStream& operator << (OutputStream &ostream, const CubicSpline &cubic_spline) {
247 
249 
250  for ( unsigned int i = 0; i < cubic_spline.cubic_polynomials.size(); ++i ) {
251  ostream << cubic_spline.cubic_polynomials[i] << "\n";
252  }
253  ostream.flush();
254  return ostream;
255 }
256 
257 /*****************************************************************************
258 ** BluePrints
259 *****************************************************************************/
260 
261 namespace blueprints {
262 
263 /*****************************************************************************
264 ** Interface [C2CubicSpline]
265 *****************************************************************************/
266 
276 class ECL_PUBLIC C2CubicSpline : public ecl::BluePrint<C2CubicSpline> {
277  public:
281  typedef ecl::CubicSpline base_type;
287  C2CubicSpline() {};
288 
301  C2CubicSpline(const ecl::Array<double>& x_set, const ecl::Array<double>& y_set,
302  const double ydot_0, const double ydot_f) ecl_assert_throw_decl(ecl::StandardException);
303 
304  virtual ~C2CubicSpline() {};
318  C2CubicSpline(const ecl::Array<double>& x_set, const ecl::Array<double>& y_set) ecl_assert_throw_decl(ecl::StandardException);
319 
327  ecl::CubicSpline instantiate();
328 
336  void apply(ecl::CubicSpline& spline) const;
337 
338  private:
339  ecl::Array<double> x_data;
340  ecl::Array<double> y_data;
341  ecl::Array<double> yddot_data;
342 };
343 
344 /*****************************************************************************
345 ** Interface [DerivativeHeuristicCubicSpline]
346 *****************************************************************************/
347 
362 class ECL_PUBLIC DerivativeHeuristicCubicSpline : public ecl::BluePrint<DerivativeHeuristicCubicSpline> {
363  public:
367  typedef ecl::CubicSpline base_type;
373  DerivativeHeuristicCubicSpline() {};
374 
388  DerivativeHeuristicCubicSpline(const ecl::Array<double>& x_set, const ecl::Array<double>& y_set,
389  const double ydot_0, const double ydot_f) ecl_assert_throw_decl(ecl::StandardException);
390 
391  virtual ~DerivativeHeuristicCubicSpline() {};
399  ecl::CubicSpline instantiate();
400 
408  void apply(ecl::CubicSpline& spline) const;
409 
410  private:
411  ecl::Array<double> x_data;
412  ecl::Array<double> y_data;
413  ecl::Array<double> ydot_data;
414 };
415 
416 } // namespace blueprints
417 } // namespace ecl
418 
419 #endif /* ECL_GEOMETRY_CUBIC_SPLINE_HPP_ */
Array< CubicPolynomial > cubic_polynomials
Defines validating functionality for the streams concept.
OutputStream & operator<<(OutputStream &ostream, const Void void_object)
Output stream operator for Void objects.
Definition: void.hpp:76
Standard exception type, provides code location and error string.
Storage container for a cubic spline interpolation.
#define ECL_PUBLIC
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
#define ecl_compile_time_concept_check(Model)
Compile time concept checking assertion.
This is a parent template for blueprints using crtp.


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13