Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jason Chemin
curves
Commits
8880d229
Commit
8880d229
authored
Nov 25, 2016
by
Steve Tonneau
Browse files
generic spline
parent
a0527d5d
Changes
5
Hide whitespace changes
Inline
Side-by-side
include/spline/cubic_
function
.h
→
include/spline/cubic_
spline
.h
View file @
8880d229
/**
* \file cubic_
function
.h
* \file cubic_
spline
.h
* \brief Definition of a cubic spline.
* \author Steve T.
* \version 0.1
...
...
@@ -11,8 +11,8 @@
*/
#ifndef _STRUCT_CUBIC
FUNCTION
#define _STRUCT_CUBIC
FUNCTION
#ifndef _STRUCT_CUBIC
SPLINE
#define _STRUCT_CUBIC
SPLINE
#include
"MathDefs.h"
...
...
@@ -29,39 +29,39 @@ namespace spline
///
template
<
typename
Time
=
double
,
typename
Numeric
=
Time
,
std
::
size_t
Dim
=
3
,
bool
Safe
=
false
,
typename
Point
=
Eigen
::
Matrix
<
Numeric
,
Dim
,
1
>,
typename
T_Point
=
std
::
vector
<
Point
,
Eigen
::
aligned_allocator
<
Point
>
>
>
struct
cubic_
function
:
public
spline_curve
<
Time
,
Numeric
,
Dim
,
3
,
Safe
,
Point
,
T_Point
>
struct
cubic_
spline
:
public
spline_curve
<
Time
,
Numeric
,
Dim
,
3
,
Safe
,
Point
,
T_Point
>
{
typedef
Point
point_t
;
typedef
T_Point
t_point_t
;
typedef
Time
time_t
;
typedef
Time
time_t
;
typedef
Numeric
num_t
;
typedef
spline_curve
<
Time
,
Numeric
,
Dim
,
3
,
Safe
,
Point
,
T_Point
>
spline_curve_t
;
/* Constructors - destructors */
public:
///\brief Constructor
cubic_
function
(
point_t
const
&
a
,
point_t
const
&
b
,
point_t
const
&
c
,
point_t
const
&
d
,
time_t
min
,
time_t
max
)
public:
///\brief Constructor
cubic_
spline
(
point_t
const
&
a
,
point_t
const
&
b
,
point_t
const
&
c
,
point_t
const
&
d
,
time_t
min
,
time_t
max
)
:
spline_curve_t
(
makeVector
(
a
,
b
,
c
,
d
),
min
,
max
)
{}
///\brief Constructor
cubic_
function
(
const
T_Point
&
coefficients
,
time_t
min
,
time_t
max
)
cubic_
spline
(
const
T_Point
&
coefficients
,
time_t
min
,
time_t
max
)
:
spline_curve_t
(
coefficients
,
min
,
max
)
{}
///\brief Constructor
template
<
typename
In
>
cubic_
function
(
In
zeroOrderCoefficient
,
In
out
,
time_t
min
,
time_t
max
)
cubic_
spline
(
In
zeroOrderCoefficient
,
In
out
,
time_t
min
,
time_t
max
)
:
spline_curve_t
(
zeroOrderCoefficient
,
out
,
min
,
max
)
{}
///\brief Destructor
~
cubic_
function
()
~
cubic_
spline
()
{
// NOTHING
}
private:
cubic_
function
(
const
cubic_
function
&
);
cubic_
function
&
operator
=
(
const
cubic_
function
&
);
//
cubic_
spline
(const cubic_
spline
&);
//
cubic_
spline
& operator=(const cubic_
spline
&);
/* Constructors - destructors */
/*Operations*/
...
...
@@ -73,7 +73,7 @@ struct cubic_function : public spline_curve<Time, Numeric, Dim,3, Safe, Point, T
}
/*Operations*/
};
//class
C
ubic
Function
};
//class
c
ubic
_spline
}
#endif //_STRUCT_CUBIC
FUNCTION
#endif //_STRUCT_CUBIC
SPLINE
include/spline/exact_cubic.h
View file @
8880d229
...
...
@@ -21,7 +21,7 @@
#define _CLASS_EXACTCUBIC
#include
"curve_abc.h"
#include
"cubic_
function
.h"
#include
"cubic_
spline
.h"
#include
"MathDefs.h"
...
...
@@ -42,8 +42,8 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point>
typedef
Eigen
::
Matrix
<
Numeric
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
MatrixX
;
typedef
Time
time_t
;
typedef
Numeric
num_t
;
typedef
cubic_
function
<
time_t
,
Numeric
,
Dim
,
Safe
,
Point
>
cubic_
function
_t
;
typedef
typename
std
::
vector
<
cubic_
function
_t
*>
T_cubic
;
typedef
cubic_
spline
<
time_t
,
Numeric
,
Dim
,
Safe
,
Point
>
cubic_
spline
_t
;
typedef
typename
std
::
vector
<
cubic_
spline
_t
*>
T_cubic
;
typedef
typename
T_cubic
::
iterator
IT_cubic
;
typedef
typename
T_cubic
::
const_iterator
CIT_cubic
;
...
...
@@ -119,18 +119,18 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point>
it
=
wayPointsBegin
,
next
=
wayPointsBegin
;
++
next
;
for
(
int
i
=
0
;
next
!=
wayPointsEnd
;
++
i
,
++
it
,
++
next
)
{
subSplines_
.
push_back
(
new
cubic_
function
_t
(
a
.
row
(
i
),
b
.
row
(
i
),
c
.
row
(
i
),
d
.
row
(
i
),
(
*
it
).
first
,
(
*
next
).
first
));
subSplines_
.
push_back
(
new
cubic_
spline
_t
(
a
.
row
(
i
),
b
.
row
(
i
),
c
.
row
(
i
),
d
.
row
(
i
),
(
*
it
).
first
,
(
*
next
).
first
));
}
subSplines_
.
push_back
(
new
cubic_
function
_t
(
a
.
row
(
size
-
1
),
b
.
row
(
size
-
1
),
c
.
row
(
size
-
1
),
d
.
row
(
size
-
1
),
(
*
it
).
first
,
(
*
it
).
first
));
subSplines_
.
push_back
(
new
cubic_
spline
_t
(
a
.
row
(
size
-
1
),
b
.
row
(
size
-
1
),
c
.
row
(
size
-
1
),
d
.
row
(
size
-
1
),
(
*
it
).
first
,
(
*
it
).
first
));
}
///\brief Destructor
~
exact_cubic
()
{
for
(
IT_cubic
it
=
subSplines_
.
begin
();
it
!=
subSplines_
.
end
();
++
it
)
{
delete
(
*
it
);
}
{
for
(
IT_cubic
it
=
subSplines_
.
begin
();
it
!=
subSplines_
.
end
();
++
it
)
{
delete
(
*
it
);
}
}
private:
...
...
@@ -146,12 +146,12 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point>
virtual
point_t
operator
()(
time_t
t
)
const
{
if
(
Safe
&&
(
t
<
subSplines_
.
front
()
->
t_min_
||
t
>
subSplines_
.
back
()
->
t_max_
)){
throw
std
::
out_of_range
(
"TODO"
);}
if
(
Safe
&&
(
t
<
subSplines_
.
front
()
->
t_min_
||
t
>
subSplines_
.
back
()
->
t_max_
)){
throw
std
::
out_of_range
(
"TODO"
);}
for
(
CIT_cubic
it
=
subSplines_
.
begin
();
it
!=
subSplines_
.
end
();
++
it
)
{
if
(
t
>=
((
*
it
)
->
t_min_
)
&&
t
<=
((
*
it
)
->
t_max_
))
if
(
t
>=
((
*
it
)
->
t_min_
)
&&
t
<=
((
*
it
)
->
t_max_
))
{
return
(
*
it
)
->
operator
()(
t
);
return
(
*
it
)
->
operator
()(
t
);
}
}
}
...
...
@@ -159,8 +159,8 @@ struct exact_cubic : public curve_abc<Time, Numeric, Dim, Safe, Point>
/*Helpers*/
public:
num_t
virtual
min
()
const
{
return
subSplines_
.
front
()
->
t_min_
;}
num_t
virtual
max
()
const
{
return
subSplines_
.
back
()
->
t_max_
;}
num_t
virtual
min
()
const
{
return
subSplines_
.
front
()
->
t_min_
;}
num_t
virtual
max
()
const
{
return
subSplines_
.
back
()
->
t_max_
;}
/*Helpers*/
/*Attributes*/
...
...
include/spline/quintic_spline.h
0 → 100644
View file @
8880d229
/**
* \file cubic_spline.h
* \brief Definition of a cubic spline.
* \author Steve T.
* \version 0.1
* \date 06/17/2013
*
* This file contains definitions for the CubicFunction struct.
* It allows the creation and evaluation of natural
* smooth cubic splines of arbitrary dimension
*/
#ifndef _STRUCT_QUINTIC_SPLINE
#define _STRUCT_QUINTIC_SPLINE
#include
"MathDefs.h"
#include
"spline_curve.h"
#include
<stdexcept>
namespace
spline
{
/// \class quintic_spline
/// \brief Represents a quintic spline defined on the interval
/// [tBegin, tEnd]. It follows the equation
/// x(t) = a + b(t - t_min_) + c(t - t_min_)^2 + d(t - t_min_)^3 + e(t - t_min_)^4 + f(t - t_min_)^5
///
template
<
typename
Time
=
double
,
typename
Numeric
=
Time
,
std
::
size_t
Dim
=
3
,
bool
Safe
=
false
,
typename
Point
=
Eigen
::
Matrix
<
Numeric
,
Dim
,
1
>,
typename
T_Point
=
std
::
vector
<
Point
,
Eigen
::
aligned_allocator
<
Point
>
>
>
struct
quintic_spline
:
public
spline_curve
<
Time
,
Numeric
,
Dim
,
5
,
Safe
,
Point
,
T_Point
>
{
typedef
Point
point_t
;
typedef
T_Point
t_point_t
;
typedef
Time
time_t
;
typedef
Numeric
num_t
;
typedef
spline_curve
<
Time
,
Numeric
,
Dim
,
5
,
Safe
,
Point
,
T_Point
>
spline_curve_t
;
/* Constructors - destructors */
public:
///\brief Constructor
quintic_spline
(
point_t
const
&
a
,
point_t
const
&
b
,
point_t
const
&
c
,
point_t
const
&
d
,
point_t
const
&
e
,
point_t
const
&
f
,
time_t
min
,
time_t
max
)
:
spline_curve_t
(
makeVector
(
a
,
b
,
c
,
d
,
e
,
f
),
min
,
max
)
{}
///\brief Constructor
quintic_spline
(
const
T_Point
&
coefficients
,
time_t
min
,
time_t
max
)
:
spline_curve_t
(
coefficients
,
min
,
max
)
{}
///\brief Constructor
template
<
typename
In
>
quintic_spline
(
In
zeroOrderCoefficient
,
In
out
,
time_t
min
,
time_t
max
)
:
spline_curve_t
(
zeroOrderCoefficient
,
out
,
min
,
max
)
{}
///\brief Destructor
~
quintic_spline
()
{
// NOTHING
}
private:
//quintic_spline(const quintic_spline&);
quintic_spline
&
operator
=
(
const
quintic_spline
&
);
/* Constructors - destructors */
/*Operations*/
T_Point
makeVector
(
point_t
const
&
a
,
point_t
const
&
b
,
point_t
const
&
c
,
point_t
const
&
d
,
point_t
const
&
e
,
point_t
const
&
f
)
{
T_Point
res
;
res
.
push_back
(
a
);
res
.
push_back
(
b
);
res
.
push_back
(
c
);
res
.
push_back
(
d
);
res
.
push_back
(
e
);
res
.
push_back
(
f
);
return
res
;
}
/*Operations*/
};
//class quintic_spline
}
#endif //_STRUCT_QUINTIC_SPLINE
include/spline/spline_curve.h
View file @
8880d229
/**
* \file
cubic_function
.h
* \file
spline_curve
.h
* \brief Definition of a cubic spline.
* \author Steve T.
* \version 0.1
* \date 06/17/2013
*
* This file contains definitions for the
CubicFunction
struct.
* This file contains definitions for the
spline_curve
struct.
* It allows the creation and evaluation of natural
* smooth
cubic
splines of arbitrary dimension
* smooth splines of arbitrary dimension
and order
*/
...
...
@@ -46,12 +46,19 @@ struct spline_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
/// with the zero order coefficient, up to the highest order
///\param min: LOWER bound on interval definition of the spline
///\param max: UPPER bound on interval definition of the spline
spline_curve
(
const
T_Point
&
coefficients
,
time_t
min
,
time_t
max
)
spline_curve
(
const
T_Point
&
coefficients
,
const
time_t
min
,
const
time_t
max
)
:
coefficients_
(
coefficients
),
t_min_
(
min
),
t_max_
(
max
),
dim_
(
Dim
),
order_
(
Order
)
{
if
(
t_min_
>
t_max_
&&
Safe
)
if
(
Safe
)
{
std
::
out_of_range
(
"TODO"
);
if
(
t_min_
>
t_max_
)
{
std
::
out_of_range
(
"TODO"
);
}
if
(
coefficients_
.
size
()
!=
order_
+
1
)
{
std
::
runtime_error
(
"Spline order and coefficients do not match"
);
}
}
}
...
...
@@ -62,12 +69,19 @@ struct spline_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
///\param min: LOWER bound on interval definition of the spline
///\param max: UPPER bound on interval definition of the spline
template
<
typename
In
>
spline_curve
(
In
zeroOrderCoefficient
,
In
out
,
time_t
min
,
time_t
max
)
spline_curve
(
In
zeroOrderCoefficient
,
In
out
,
const
time_t
min
,
const
time_t
max
)
:
coefficients_
(
init_coeffs
(
zeroOrderCoefficient
,
out
)),
t_min_
(
min
),
t_max_
(
max
),
dim_
(
Dim
),
order_
(
Order
)
{
if
(
t_min_
>
t_max_
&&
Safe
)
if
(
Safe
)
{
std
::
out_of_range
(
"TODO"
);
if
(
t_min_
>
t_max_
)
{
std
::
out_of_range
(
"TODO"
);
}
if
(
coefficients_
.
size
()
!=
order_
+
1
)
{
std
::
runtime_error
(
"Spline order and coefficients do not match"
);
}
}
}
...
...
@@ -77,9 +91,20 @@ struct spline_curve : public curve_abc<Time, Numeric, Dim, Safe, Point>
// NOTHING
}
private:
spline_curve
(
const
spline_curve
&
);
spline_curve
&
operator
=
(
const
spline_curve
&
);
spline_curve
(
const
spline_curve
&
other
)
:
t_min_
(
other
.
t_min_
),
t_max_
(
other
.
t_max_
)
,
coefficients_
(
other
.
coefficients_
)
{}
//private:
spline_curve
&
operator
=
(
const
spline_curve
&
other
)
{
t_min_
=
other
.
t_min_
;
t_max_
=
other
.
t_max_
;
coefficients_
=
other
.
coefficients_
;
return
*
this
;
}
/* Constructors - destructors */
/*Operations*/
...
...
src/tests/spline_test/Main.cpp
View file @
8880d229
...
...
@@ -2,6 +2,8 @@
#include
"spline/exact_cubic.h"
#include
"spline/bezier_curve.h"
#include
"spline/spline_curve.h"
#include
"spline/cubic_spline.h"
#include
"spline/quintic_spline.h"
#include
<string>
#include
<iostream>
...
...
@@ -13,7 +15,7 @@ namespace spline
{
typedef
Eigen
::
Vector3d
point_t
;
typedef
std
::
vector
<
point_t
,
Eigen
::
aligned_allocator
<
point_t
>
>
t_point_t
;
typedef
spline_curv
e
<
double
,
double
,
3
,
3
,
true
,
point_t
,
t_point_t
>
cubic_function_t
;
typedef
cubic_splin
e
<
double
,
double
,
3
,
true
,
point_t
,
t_point_t
>
cubic_function_t
;
typedef
exact_cubic
<
double
,
double
,
3
,
true
,
point_t
>
exact_cubic_t
;
typedef
bezier_curve
<
double
,
double
,
3
,
true
,
point_t
>
bezier_curve_t
;
typedef
std
::
pair
<
double
,
point_t
>
Waypoint
;
...
...
@@ -66,7 +68,7 @@ void ComparePoints(const point_t& pt1, const point_t& pt2, const std::string& er
void
ComparePoints
(
const
point_one
&
pt1
,
const
point_one
&
pt2
,
const
std
::
string
&
errmsg
,
bool
&
error
)
{
if
(
!
(
pt1
==
pt2
))
if
(
!
(
pt1
==
pt2
))
{
error
=
true
;
std
::
cout
<<
errmsg
<<
pt1
<<
" ; "
<<
pt2
<<
std
::
endl
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment