LinearInterpolation.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 "LinearInterpolation.h"
23
25
26///EXCEPTIONS
29///ARMARX-INCLUDES
31
32using namespace armarx;
33
35{
36 if (controlPoints.size() < 2)
37 {
39 }
41 for (unsigned int i = 0; i < this->controlPoints.size() - 1; i++)
42 {
43 PoseBasePtr current = this->controlPoints.at(i);
44 PoseBasePtr next = this->controlPoints.at(i + 1);
45 int deltaX = next->position->x - current->position->x;
46 int deltaY = next->position->y - current->position->y;
47 int deltaZ = next->position->z - current->position->z;
48 connectingVector.push_back(*new Eigen::Vector3f(deltaX, deltaY, deltaZ));
49 }
50}
51
52PoseBasePtr
54{
55 if (time < 0 || time > 1)
56 {
58 }
59
60 int segment = time * (controlPoints.size() - 1);
61 if (time == 1)
62 {
64 }
65 double segmentRelativeTime =
66 (time - (1.0 / (controlPoints.size() - 1.0)) * segment) * (controlPoints.size() - 1);
67 PoseBasePtr current = controlPoints[segment];
68
69 Eigen::Vector3f start =
70 Eigen::Vector3f(current->position->x, current->position->y, current->position->z);
71 Eigen::Vector3f transition = connectingVector[segment];
72 transition *= segmentRelativeTime;
73 Eigen::Vector3f position = start + transition;
74 return *new PoseBasePtr(
75 new Pose(*new Vector3BasePtr(new Vector3(position)), calculateOrientationAt(time)));
76}
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
PoseBasePtr getPoseAt(double time) override
getPoseAt returns the Pose defined by f(time)
LinearInterpolation(std::vector< PoseBasePtr > controlPoints)
LinearInterpolation creates a new LinearInterPolation defined by controlPoints.
The Pose class.
Definition Pose.h:243
The Vector3 class.
Definition Pose.h:113
This file offers overloads of toIce() and fromIce() functions for STL container types.