Library of Assembled Shared Sources
spline_bezier_path.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * Distributed under the terms of the GPL (GNU Public License)
6 *
7 * The LASS License:
8 *
9 * Copyright 2004-2006 Bram de Greve and Tom De Muer
10 *
11 * LASS is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26
27
28/** @class lass::num::SplineBezierPath
29 * @brief connects the data nodes with cubic bezier splines.
30 * @author Bram de Greve [BdG]
31 */
32
33#ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_SPLINE_BEZIER_PATH_H
34#define LASS_GUARDIAN_OF_INCLUSION_NUM_SPLINE_BEZIER_PATH_H
35
36#include "num_common.h"
37#include "spline.h"
38
39namespace lass
40{
41namespace num
42{
43
44template
45<
46 typename ScalarType,
47 typename DataType,
48 typename DataTraits
49>
50class SplineBezierPath: public Spline<ScalarType, DataType>
51{
52public:
53
54 typedef DataTraits TDataTraits;
55 typedef Spline<ScalarType, DataType> TSplineBase;
56 typedef typename TSplineBase::TScalar TScalar;
57 typedef typename TSplineBase::TData TData;
58 typedef typename TSplineBase::ControlRange TControlRange;
59
60 class DataTriplet
61 {
62 public:
63 DataTriplet(const TData& left, const TData& knot, const TData& right):
64 left_(left), knot_(knot), right_(right) {}
65 const TData& left() const { return left_; }
66 const TData& knot() const { return knot_; }
67 const TData& right() const { return right_; }
68 private:
69 friend class SplineBezierPath;
70 TData left_;
71 TData knot_;
72 TData right_;
73 };
74
75 SplineBezierPath();
76 template <typename PairInputIterator>
77 SplineBezierPath(PairInputIterator iFirst, PairInputIterator iLast);
78 template <typename ScalarInputIterator, typename DataInputIterator>
79 SplineBezierPath(ScalarInputIterator iFirstControl, ScalarInputIterator iLastControl,
80 DataInputIterator iFirstData);
81
82 const TData operator()(TScalar iX) const override;
83 const TData derivative(TScalar iX) const override;
84 const TData derivative2(TScalar iX) const override;
85 const TData integral(TScalar iA, TScalar iB) const override;
86
87 bool isEmpty() const override;
88 const TControlRange controlRange() const override;
89
90private:
91
92 struct Node
93 {
94 DataTriplet triplet;
95 TScalar x;
96
97 Node(const DataTriplet& triplet, TScalar x): triplet(triplet), x(x) {}
98 const TData& left() const { return triplet.left(); }
99 const TData& knot() const { return triplet.knot(); }
100 const TData& right() const { return triplet.right(); }
101
102 static bool less(const Node& iA, const Node& iB) { return iA.x < iB.x; }
103 };
104 typedef std::vector<Node> TNodes;
105 typedef typename TNodes::const_iterator TNodeConstIterator;
106
107 typedef std::pair<TScalar, TData> TSimpleNode;
108 typedef std::vector<TSimpleNode> TSimpleNodes;
109
110 template <typename PairInputIterator>
111 void init(PairInputIterator first, PairInputIterator last, const DataTriplet& dummy);
112 template <typename PairInputIterator>
113 void init(PairInputIterator first, PairInputIterator last, const TData& dummy);
114 template <typename ScalarInputIterator, typename DataInputIterator>
115 void init(ScalarInputIterator firstControl, ScalarInputIterator lastControl,
116 DataInputIterator firstData, const DataTriplet& dummy);
117 template <typename ScalarInputIterator, typename DataInputIterator>
118 void init(ScalarInputIterator firstControl, ScalarInputIterator lastControl,
119 DataInputIterator firstData, const TData& dummy);
120 void makeFullNodes(const TSimpleNodes& simpleNodes);
121 void finalInit();
122
123 const TNodeConstIterator findNode(TScalar iX) const;
124
125 TNodes nodes_;
126 size_t dataDimension_;
127};
128
129
130
131}
132
133}
134
135#include "spline_bezier_path.inl"
136
137#endif
138
139// EOF
bool isEmpty() const override
return true if the spline contains any nodes at all.
const TControlRange controlRange() const override
return the range of control values for which the spline can interpolate.
abstract base class of splines.
Definition spline.h:67
numeric types and traits.
Definition basic_ops.h:70
const SplineLinear< S, D, T >::TData SplineLinear< S, D, T >::derivative2(TScalar) const
Get the second derivative of data value that corresponds with constrol value iX.
Library for Assembled Shared Sources.
Definition config.h:53