Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
ndcurves
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
loco-3d
ndcurves
Commits
899dd9db
Commit
899dd9db
authored
5 years ago
by
Pierre Fernbach
Browse files
Options
Downloads
Patches
Plain Diff
[piecewise] refactor/simplify constructor from discret point
parent
4cc0b596
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/curves/piecewise_curve.h
+12
-40
12 additions, 40 deletions
include/curves/piecewise_curve.h
tests/Main.cpp
+22
-31
22 additions, 31 deletions
tests/Main.cpp
with
34 additions
and
71 deletions
include/curves/piecewise_curve.h
+
12
−
40
View file @
899dd9db
...
...
@@ -216,51 +216,23 @@ namespace curves
}
template
<
typename
Polynomial
>
static
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
convert_discrete_points_to_polynomial
(
T_Point
points
,
Time
T_min
,
Time
T_max
)
static
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
convert_discrete_points_to_polynomial
(
T_Point
points
,
t_time_t
time_points
)
{
if
(
Safe
&!
(
points
.
size
()
>
1
))
{
//std::cout<<"[Min,Max]=["<<T_min_<<","<<T_max_<<"]"<<" t="<<t<<std::endl;
throw
std
::
invalid_argument
(
"piecewise_curve
->
convert_discrete_points_to_polynomial
,
Error, less than 2 discrete points"
);
throw
std
::
invalid_argument
(
"piecewise_curve
::
convert_discrete_points_to_polynomial
:
Error, less than 2 discrete points"
);
}
typedef
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
piecewise_curve_out_t
;
Time
discretization_step
=
(
T_max
-
T_min
)
/
Time
(
points
.
size
()
-
1
);
Time
time_actual
=
T_min
;
// Initialization at first points
point_t
actual_point
=
points
[
0
];
point_t
next_point
=
points
[
1
];
point_t
coeff_order_zero
(
actual_point
);
point_t
coeff_order_one
((
next_point
-
actual_point
)
/
discretization_step
);
t_point_t
coeffs
;
coeffs
.
push_back
(
coeff_order_zero
);
coeffs
.
push_back
(
coeff_order_one
);
Polynomial
pol
(
coeffs
,
time_actual
,
time_actual
+
discretization_step
);
piecewise_curve_out_t
ppc
(
pol
);
time_actual
+=
discretization_step
;
// Other points
for
(
std
::
size_t
i
=
1
;
i
<
points
.
size
()
-
2
;
i
++
)
{
coeffs
.
clear
();
actual_point
=
points
[
i
];
next_point
=
points
[
i
+
1
];
coeff_order_zero
=
actual_point
;
coeff_order_one
=
(
next_point
-
actual_point
)
/
discretization_step
;
coeffs
.
push_back
(
coeff_order_zero
);
coeffs
.
push_back
(
coeff_order_one
);
ppc
.
add_curve
(
Polynomial
(
coeffs
,
time_actual
,
time_actual
+
discretization_step
));
time_actual
+=
discretization_step
;
if
(
points
.
size
()
!=
time_points
.
size
()){
throw
std
::
invalid_argument
(
"piecewise_curve::convert_discrete_points_to_polynomial: Error, points and time_points must have the same size."
);
}
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
piecewise_res
;
for
(
size_t
i
=
1
;
i
<
points
.
size
()
;
++
i
){
piecewise_res
.
add_curve
(
Polynomial
(
points
[
i
-
1
],
points
[
i
],
time_points
[
i
-
1
],
time_points
[
i
]));
}
// Last points
coeffs
.
clear
();
actual_point
=
points
[
points
.
size
()
-
2
];
next_point
=
points
[
points
.
size
()
-
1
];
coeff_order_zero
=
actual_point
;
coeff_order_one
=
(
next_point
-
actual_point
)
/
discretization_step
;
coeffs
.
push_back
(
coeff_order_zero
);
coeffs
.
push_back
(
coeff_order_one
);
ppc
.
add_curve
(
Polynomial
(
coeffs
,
time_actual
,
T_max
));
return
ppc
;
return
piecewise_res
;
}
private
:
...
...
@@ -357,4 +329,4 @@ namespace curves
}
// end namespace
#endif // _CLASS_PIECEWISE_CURVE
\ No newline at end of file
#endif // _CLASS_PIECEWISE_CURVE
This diff is collapsed.
Click to expand it.
tests/Main.cpp
+
22
−
31
View file @
899dd9db
...
...
@@ -1335,37 +1335,28 @@ void curveAbcDimDynamicTest(bool& error)
void
piecewiseCurveConversionFromDiscretePointsTest
(
bool
&
error
)
{
try
{
std
::
string
errMsg
(
"piecewiseCurveConversionFromDiscretePointsTest, Error, value on curve is wrong : "
);
point_t
p0
(
0.
,
0.
,
0.
);
point_t
p1
(
1.
,
2.
,
3.
);
point_t
p2
(
4.
,
4.
,
4.
);
point_t
p3
(
10.
,
10.
,
10.
);
point_t
p_test_0_5
=
(
p0
+
p1
)
/
2.0
;
t_point_t
points
;
points
.
push_back
(
p0
);
points
.
push_back
(
p1
);
points
.
push_back
(
p2
);
points
.
push_back
(
p3
);
double
T_min
=
1.0
;
double
T_max
=
3.0
;
double
timestep
=
(
T_max
-
T_min
)
/
double
(
points
.
size
()
-
1
);
piecewise_polynomial_curve_t
ppc
=
piecewise_polynomial_curve_t
::
convert_discrete_points_to_polynomial
<
polynomial_t
>
(
points
,
T_min
,
T_max
);
if
(
!
ppc
.
is_continuous
(
0
))
{
std
::
cout
<<
"piecewiseCurveConversionFromDiscretePointsTest, Error, piecewise curve is not C0"
<<
std
::
endl
;
error
=
true
;
}
ComparePoints
(
p0
,
ppc
(
T_min
),
errMsg
,
error
);
ComparePoints
(
p_test_0_5
,
ppc
(
T_min
+
timestep
/
2.0
),
errMsg
,
error
);
ComparePoints
(
p1
,
ppc
(
T_min
+
timestep
),
errMsg
,
error
);
ComparePoints
(
p2
,
ppc
(
T_min
+
2
*
timestep
),
errMsg
,
error
);
ComparePoints
(
p3
,
ppc
(
T_max
),
errMsg
,
error
);
}
catch
(...)
{
std
::
string
errMsg
(
"piecewiseCurveConversionFromDiscretePointsTest, Error, value on curve is wrong : "
);
point_t
p0
(
0.
,
0.
,
0.
);
point_t
p1
(
1.
,
2.
,
3.
);
point_t
p2
(
4.
,
4.
,
4.
);
point_t
p3
(
10.
,
10.
,
10.
);
point_t
p_test_0_5
=
(
p0
+
p1
)
/
2.0
;
t_point_t
points
;
points
.
push_back
(
p0
);
points
.
push_back
(
p1
);
points
.
push_back
(
p2
);
points
.
push_back
(
p3
);
double
T_min
=
1.0
;
double
T_max
=
3.0
;
double
timestep
=
(
T_max
-
T_min
)
/
double
(
points
.
size
()
-
1
);
std
::
vector
<
double
>
time_points
;
for
(
size_t
i
=
0
;
i
<
points
.
size
();
++
i
)
time_points
.
push_back
(
T_min
+
i
*
timestep
);
piecewise_polynomial_curve_t
ppc
=
piecewise_polynomial_curve_t
::
convert_discrete_points_to_polynomial
<
polynomial_t
>
(
points
,
time_points
);
if
(
!
ppc
.
is_continuous
(
0
))
{
std
::
cout
<<
"piecewiseCurveConversionFromDiscretePointsTest, Error, piecewise curve is not C0"
<<
std
::
endl
;
error
=
true
;
std
::
cout
<<
"Error in piecewiseCurveConversionFromDiscretePointsTest"
<<
std
::
endl
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment