SplinePrivate.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_SPLINEPRIVATE_HH_
18 #define IGNITION_MATH_SPLINEPRIVATE_HH_
19 
20 #include <algorithm>
21 #include <vector>
22 #include <ignition/math/Vector3.hh>
23 #include <ignition/math/Vector4.hh>
24 #include <ignition/math/Matrix4.hh>
25 
26 namespace ignition
27 {
28  namespace math
29  {
34  {
38  public: explicit ControlPoint(const std::vector<Vector3d> &_initList)
39  : derivatives(_initList.begin(), _initList.end())
40  {
41  }
42 
48  public: inline void Match(const ControlPoint &_other)
49  {
50  std::copy(_other.derivatives.begin(),
51  _other.derivatives.end(),
52  this->derivatives.begin());
53  }
54 
58  public: inline bool operator==(const ControlPoint &_other) const
59  {
60  // Workaround to compare the two vector of vectors in MSVC 2013
61  // and MSVC 2015. See
62  // https://bitbucket.org/ignitionrobotics/ign-math/issues/70
63  if (this->derivatives.size() != _other.derivatives.size())
64  return false;
65 
66  for (size_t i = 0; i < this->derivatives.size(); ++i)
67  if (this->derivatives[i] != _other.derivatives[i])
68  return false;
69 
70  return true;
71  }
72 
78  public: inline Vector3d MthDerivative(const unsigned int _mth) const
79  {
80  if (_mth >= this->derivatives.size())
81  return Vector3d(0.0, 0.0, 0.0);
82  return this->derivatives[_mth];
83  }
84 
91  public: inline Vector3d& MthDerivative(const unsigned int _mth)
92  {
93  if (_mth >= this->derivatives.size())
94  {
95  this->derivatives.insert(this->derivatives.end(),
96  _mth - this->derivatives.size() + 1,
97  Vector3d(0.0, 0.0, 0.0));
98  }
99  return this->derivatives[_mth];
100  }
101 
103  private: std::vector<Vector3d> derivatives;
104  };
105 
109  {
111  public: IntervalCubicSpline();
112 
116  public: void SetPoints(const ControlPoint &_startPoint,
117  const ControlPoint &_endPoint);
118 
121  public: inline const ControlPoint &StartPoint() const
122  {
123  return this->startPoint;
124  };
125 
128  public: inline const ControlPoint &EndPoint() const
129  {
130  return this->endPoint;
131  };
132 
139  public: Vector3d InterpolateMthDerivative(
140  const unsigned int _mth, const double _t) const;
141 
144  public: inline double ArcLength() const { return this->arcLength; }
145 
149  public: double ArcLength(const double _t) const;
150 
157  private: Vector3d DoInterpolateMthDerivative(
158  const unsigned int _mth, const double _t) const;
159 
161  private: ControlPoint startPoint;
162 
164  private: ControlPoint endPoint;
165 
168  private: Matrix4d coeffs;
169 
171  private: double arcLength;
172  };
173 
176  {
179  public: bool autoCalc;
180 
182  public: double tension;
183 
185  public: std::vector<bool> fixings;
186 
188  public: std::vector<ControlPoint> points;
189 
190  // \brief interpolated segments.
191  public: std::vector<IntervalCubicSpline> segments;
192 
193  // \brief segments arc length cumulative distribution.
194  public: std::vector<double> cumulativeArcLengths;
195 
196  // \brief spline arc length.
197  public: double arcLength;
198  };
199  }
200 }
201 
202 #endif
std::vector< IntervalCubicSpline > segments
Definition: SplinePrivate.hh:191
std::vector< bool > fixings
fixings for control points.
Definition: SplinePrivate.hh:185
const ControlPoint & StartPoint() const
Gets the start control point.
Definition: SplinePrivate.hh:121
ControlPoint(const std::vector< Vector3d > &_initList)
Constructor that takes the M derivatives that define the control point.
Definition: SplinePrivate.hh:38
void Match(const ControlPoint &_other)
Matches all mth derivatives defined in _other to this.
Definition: SplinePrivate.hh:48
Vector3< double > Vector3d
Definition: Vector3.hh:744
double arcLength
Definition: SplinePrivate.hh:197
Vector3d MthDerivative(const unsigned int _mth) const
Gets the mth derivative of this control point.
Definition: SplinePrivate.hh:78
Private data for Spline class.
Definition: SplinePrivate.hh:175
const ControlPoint & EndPoint() const
Gets the end control point.
Definition: SplinePrivate.hh:128
std::vector< ControlPoint > points
control points.
Definition: SplinePrivate.hh:188
Cubic interpolator for splines defined between each pair of control points.
Definition: SplinePrivate.hh:108
Control point representation for polynomial interpolation, defined in terms of arbitrary m derivative...
Definition: SplinePrivate.hh:33
double tension
tension of 0 = Catmull-Rom spline, otherwise a Cardinal spline.
Definition: SplinePrivate.hh:182
double ArcLength() const
Gets curve arc length.
Definition: SplinePrivate.hh:144
bool operator==(const ControlPoint &_other) const
Checks for control point equality.
Definition: SplinePrivate.hh:58
Definition: Angle.hh:38
bool autoCalc
when true, the tangents are recalculated when the control point change.
Definition: SplinePrivate.hh:179
Vector3d & MthDerivative(const unsigned int _mth)
Returns a mutable reference to the mth derivative of this control point.
Definition: SplinePrivate.hh:91
std::vector< double > cumulativeArcLengths
Definition: SplinePrivate.hh:194