Spline.h
Go to the documentation of this file.00001 #ifndef SimTK_SIMMATH_SPLINE_H_
00002 #define SimTK_SIMMATH_SPLINE_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "simmath/internal/Function.h"
00036 #include "simmath/internal/GCVSPLUtil.h"
00037
00038 #include <limits>
00039
00040 namespace SimTK {
00041
00049 template <int N>
00050 class Spline : public Function<N> {
00051 public:
00059 Spline(int degree, const Vector& x, const Vector_<Vec<N> >& y) : impl(new SplineImpl(degree, x, y)) {
00060 }
00061 Spline(const Spline& copy) : impl(copy.impl) {
00062 impl->referenceCount++;
00063 }
00064 Spline() : impl(NULL) {
00065 }
00066 Spline& operator=(const Spline& copy) {
00067 if (impl) {
00068 impl->referenceCount--;
00069 if (impl->referenceCount == 0)
00070 delete impl;
00071 }
00072 impl = copy.impl;
00073 assert(impl);
00074 impl->referenceCount++;
00075 return *this;
00076 }
00077 ~Spline() {
00078 if (impl) {
00079 impl->referenceCount--;
00080 if (impl->referenceCount == 0)
00081 delete impl;
00082 }
00083 }
00089 Vec<N> calcValue(const Vector& x) const {
00090 assert(impl);
00091 assert(x.size() == 1);
00092 return impl->getValue(x[0]);
00093 }
00099 Vec<N> calcDerivative(const std::vector<int>& derivComponents, const Vector& x) const {
00100 assert(impl);
00101 assert(x.size() == 1);
00102 assert(derivComponents.size() > 0);
00103 return impl->getDerivative(derivComponents.size(), x[0]);
00104 }
00105 int getArgumentSize() const {
00106 return 1;
00107 }
00108 int getMaxDerivativeOrder() const {
00109 return std::numeric_limits<int>::max();
00110 }
00114 const Vector& getControlPointLocations() const {
00115 assert(impl);
00116 return impl->x;
00117 }
00121 const Vector_<Vec<N> >& getControlPointValues() const {
00122 assert(impl);
00123 return impl->y;
00124 }
00128 int getSplineDegree() const {
00129 assert(impl);
00130 return impl->degree;
00131 }
00132 private:
00133 class SplineImpl;
00134 SplineImpl* impl;
00135 };
00136
00137 template <int N>
00138 class Spline<N>::SplineImpl {
00139 public:
00140 SplineImpl(int degree, const Vector& x, const Vector_<Vec<N> >& y) : degree(degree), x(x), y(y), referenceCount(1) {
00141 }
00142 ~SplineImpl() {
00143 assert(referenceCount == 0);
00144 }
00145 Vec<N> getValue(Real t) const {
00146 return GCVSPLUtil::splder(0, degree, t, x, y);
00147 }
00148 Vec<N> getDerivative(int derivOrder, Real t) const {
00149 return GCVSPLUtil::splder(derivOrder, degree, t, x, y);
00150 }
00151 int referenceCount;
00152 int degree;
00153 Vector x;
00154 Vector_<Vec<N> > y;
00155 };
00156
00157 }
00158
00159 #endif // SimTK_SIMMATH_SPLINE_H_
00160
00161