SplineInterpolation.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXGuiPlugins::RobotTrajectoryDesigner::Interpolation
17 * @author Timo Birr
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22#include "SplineInterpolation.h"
23
25
26///ARMARX-INCLUDES
28///EXCEPTIONS
31
32using namespace armarx;
33using namespace alglib;
34
36{
37 if (controlPoints.size() < static_cast<unsigned>(3))
38 {
40 }
42
43 //Creating the Interpolation Functions for all parametric Splines (x,y,z -Coordinate)
44 alglib::pspline2build(getCoordinateArray(0), controlPoints.size(), 2, 0, xInterpolation);
45 alglib::pspline2build(getCoordinateArray(1), controlPoints.size(), 2, 0, yInterpolation);
46 alglib::pspline2build(getCoordinateArray(2), controlPoints.size(), 2, 0, zInterpolation);
47}
48
49PoseBasePtr
51{
52 if (time < 0 || time > 1)
53 {
55 }
56 if (time == 1)
57 {
59 }
60 double x = 0;
61 double y = 0;
62 double z = 0;
63 double temp = 0;
64 alglib::pspline2calc(xInterpolation, time, x, temp);
65 alglib::pspline2calc(yInterpolation, time, y, temp);
66 alglib::pspline2calc(zInterpolation, time, z, temp);
67
68 Vector3BasePtr position = new Vector3(x, y, z);
69 QuaternionBasePtr base = this->calculateOrientationAt(time);
70 return *new PoseBasePtr(new Pose(position, base));
71}
72
75{
76 int number = 0;
77 for (unsigned int i = 0; i < controlPoints.size(); i++)
78 {
79 if (controlPoints.at(i) == start)
80 {
81 number = i;
82 break;
83 }
84 }
85 return *new AbstractInterpolationPtr(
87}
88
95
96alglib::real_2d_array
97SplineInterpolation::getCoordinateArray(int coordinate)
98{
99 std::string transformation = "[";
100 unsigned int i = 0;
101 for (PoseBasePtr current : controlPoints)
102 {
103 int temp;
104 switch (coordinate)
105 {
106 case (0):
107 temp = current->position->x;
108 break;
109 case (1):
110 temp = current->position->y;
111 break;
112 case (2):
113 temp = current->position->z;
114 break;
115 }
116 transformation = transformation + "[" + std::to_string(temp) + "," +
117 std::to_string(i / this->controlPoints.size()) + "]";
118 if (i != controlPoints.size() - 1)
119 {
120 transformation += ",";
121 }
122 i++;
123 }
124 transformation += "]";
125 const char* c = transformation.c_str();
126 real_2d_array input = *new real_2d_array(c); //TODO implement
127 return input;
128}
constexpr T c
virtual const QuaternionBasePtr calculateOrientationAt(double time)
calculateOrientationAt calculates the rotation/orientation of the pose at a certain time
static PoseBasePtr deepCopy(PoseBasePtr org)
deepCopy creates a real, independent copy of a PoseBasePtr
void init(const std::vector< PoseBasePtr > cp)
init convinience method to construct the basic parts of the interpolation (copying all controlPoints)
std::vector< PoseBasePtr > controlPoints
controlPoints the controlPoints that are interpolated between
The Pose class.
Definition Pose.h:243
The SplineInterpolationSegment class represents the segment of a parent SplineInterpolation between t...
AbstractInterpolationPtr getInterPolationSegment(PoseBasePtr start)
getInterPolationSegment returns a segment of the current interpolation
PoseBasePtr getPoseAt(double time) override
getPoseAt returns the Pose defined by f(time)
SplineInterpolation(std::vector< PoseBasePtr > controlPoints)
SplineInterpolation creates a new SplineInterpolation through a series of conntrol points.
The Vector3 class.
Definition Pose.h:113
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< AbstractInterpolation > AbstractInterpolationPtr