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 
28 namespace 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 
53  if (type == VariantType::FramedDirection)
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 
112  return AverageFilter::calculate(c);
113  }
114 
115 
116 } // namespace armarx::filters
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::VariantBasePtr
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr
Definition: ManagedIceObject.h:108
armarx::VariantType::Vector3
const VariantTypeId Vector3
Definition: Pose.h:38
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
IceInternal::Handle< Variant >
armarx::filters
Definition: AverageFilter.h:32
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:920
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::toEigen
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)
Definition: PointToModelICP.h:67
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:157
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
PoseAverageFilter.h
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:43
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:213
armarx::filters::AverageFilter::calculate
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: AverageFilter.cpp:34
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::filters::PoseAverageFilter::calculate
VariantBasePtr calculate(const Ice::Current &c) const override
Definition: PoseAverageFilter.cpp:32
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:86
armarx::DatafieldFilter::dataHistory
TimeVariantBaseMap dataHistory
Definition: DatafieldFilter.h:83
armarx::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:37
armarx::DatafieldFilter::historyMutex
std::mutex historyMutex
Definition: DatafieldFilter.h:84
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
Logging.h
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:38