PoseAverageFilter.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2018
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "PoseAverageFilter.h"
25
27
28namespace armarx::filters
29{
30
32 PoseAverageFilter::calculate(const Ice::Current& c) const
33 {
34 std::unique_lock lock(historyMutex);
35
36 if (dataHistory.size() == 0)
37 {
38 return NULL;
39 }
40
41 VariantTypeId type = dataHistory.begin()->second->getType();
42
43 if ((type == VariantType::Vector3) || (type == VariantType::FramedDirection) ||
45 {
46
47 Eigen::Vector3f vec;
48 vec.setZero();
49 std::string frame = "";
50 std::string agent = "";
51 VariantPtr var = VariantPtr::dynamicCast(dataHistory.begin()->second);
52
54 {
55 FramedDirectionPtr p = var->get<FramedDirection>();
56 frame = p->frame;
57 agent = p->agent;
58 }
59 else if (type == VariantType::FramedPosition)
60 {
61 FramedPositionPtr p = var->get<FramedPosition>();
62 frame = p->frame;
63 agent = p->agent;
64 }
65 Eigen::MatrixXf keypointPositions(dataHistory.size(), 3);
66 int i = 0;
67 for (auto& v : dataHistory)
68 {
69 VariantPtr v2 = VariantPtr::dynamicCast(v.second);
70 Eigen::Vector3f value = v2->get<Vector3>()->toEigen();
71 keypointPositions(i, 0) = value(0);
72 keypointPositions(i, 1) = value(1);
73 keypointPositions(i, 2) = value(2);
74 i++;
75 }
76 vec = keypointPositions.colwise().mean();
77
78
79 if (type == VariantType::Vector3)
80 {
81 Vector3Ptr vecVar = new Vector3(vec);
82 return new Variant(vecVar);
83 }
84 else if (type == VariantType::FramedDirection)
85 {
86
87 FramedDirectionPtr vecVar = new FramedDirection(vec, frame, agent);
88 return new Variant(vecVar);
89 }
90 else if (type == VariantType::FramedPosition)
91 {
92 FramedPositionPtr vecVar = new FramedPosition(vec, frame, agent);
93 return new Variant(vecVar);
94 }
95 else
96 {
97 ARMARX_WARNING_S << "Implementation missing here";
98 return NULL;
99 }
100 }
101 else if (type == VariantType::Double)
102 {
103 // auto values = SortVariants<double>(dataHistory);
104 // return new Variant(values.at(values.size()/2));
105 }
106 else if (type == VariantType::Int)
107 {
108 // auto values = SortVariants<int>(dataHistory);
109 // return new Variant(values.at(values.size()/2));
110 }
111
113 }
114
115
116} // namespace armarx::filters
constexpr T c
TimeVariantBaseMap dataHistory
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
The FramedPosition class.
Definition FramedPose.h:158
The Variant class is described here: Variants.
Definition Variant.h:224
The Vector3 class.
Definition Pose.h:113
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
VariantBasePtr calculate(const Ice::Current &c) const override
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
const VariantTypeId FramedPosition
Definition FramedPose.h:38
const VariantTypeId FramedDirection
Definition FramedPose.h:37
const VariantTypeId Int
Definition Variant.h:917
const VariantTypeId Vector3
Definition Pose.h:38
const VariantTypeId Double
Definition Variant.h:920
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
Ice::Int VariantTypeId
Definition Variant.h:43
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)