ConditionCheckMagnitudeChecks.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, 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
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
25 
27 
28 namespace armarx
29 {
30 
32  {
39  }
40 
43  {
44  return new ConditionCheckMagnitudeLarger(*this);
45  }
46 
47  bool
49  {
50 
51  if (dataFields.size() != 1)
52  {
53  throw InvalidConditionException(
54  "Wrong number of datafields for condition magnitude larger: expected 1 actual: " +
55  ValueToString(dataFields.size()));
56  }
57 
58  const Variant& value = dataFields.begin()->second;
59  VariantTypeId type = value.getType();
60 
61  if (type == VariantType::Vector3)
62  {
63  Eigen::Vector3f vec = value.getClass<Vector3>()->toEigen();
64  return (vec).norm() > getParameter(0).getFloat();
65  }
66 
67  if (type == VariantType::FramedDirection)
68  {
69  FramedDirectionPtr fV1 = value.getClass<FramedDirection>();
70  Eigen::Vector3f vec = value.getClass<FramedDirection>()->toEigen();
71  return (vec).norm() > getParameter(0).getFloat();
72  }
73 
74  if (type == VariantType::LinkedDirection)
75  {
76  LinkedDirectionPtr lV1 = value.getClass<LinkedDirection>();
77 
78  Eigen::Vector3f vec = value.getClass<LinkedDirection>()->toEigen();
79  return (vec).norm() > getParameter(0).getFloat();
80  }
81 
82  return false;
83  }
84 
86  {
93  }
94 
97  {
98  return new ConditionCheckMagnitudeSmaller(*this);
99  }
100 
101  bool
103  {
104 
105  if (dataFields.size() != 1)
106  {
107  ARMARX_WARNING_S << "Size of dataFields: %d\n" << dataFields.size();
108  throw InvalidConditionException("Wrong number of datafields for condition equals ");
109  }
110 
111  const Variant& value = dataFields.begin()->second;
112  VariantTypeId type = value.getType();
113 
114  if (type == VariantType::Vector3)
115  {
116  Eigen::Vector3f vec = value.getClass<Vector3>()->toEigen();
117  return (vec).norm() < getParameter(0).getFloat();
118  }
119 
120  if (type == VariantType::FramedDirection)
121  {
122  // FramedDirectionPtr fV1 = value.getClass<FramedDirection>();
123  Eigen::Vector3f vec = value.getClass<FramedDirection>()->toEigen();
124  return (vec).norm() < getParameter(0).getFloat();
125  }
126 
127  if (type == VariantType::LinkedDirection)
128  {
129  // LinkedDirectionPtr lV1 = value.getClass<LinkedDirection>();
130  Eigen::Vector3f vec = value.getClass<LinkedDirection>()->toEigen();
131  return (vec).norm() < getParameter(0).getFloat();
132  }
133 
134  return false;
135  }
136 
138  {
146  }
147 
150  {
151  return new ConditionCheckMagnitudeInRange(*this);
152  }
153 
154  bool
156  {
157  if (dataFields.size() != 1)
158  {
159  ARMARX_WARNING_S << "Size of dataFields: " << dataFields.size();
160  throw InvalidConditionException("Wrong number of datafields for condition InRange ");
161  }
162 
163  const Variant& value = dataFields.begin()->second;
164  VariantTypeId type = value.getType();
165 
166  if (type == VariantType::Vector3)
167  {
168  Eigen::Vector3f vec = value.getClass<Vector3>()->toEigen();
169  return ((vec).norm() > getParameter(0).getFloat()) &&
170  ((vec).norm() < getParameter(1).getFloat());
171  }
172 
173  if (type == VariantType::FramedDirection)
174  {
175  // FramedDirectionPtr fV1 = value.getClass<FramedDirection>();
176  Eigen::Vector3f vec = value.getClass<FramedDirection>()->toEigen();
177  return ((vec).norm() > getParameter(0).getFloat()) &&
178  ((vec).norm() < getParameter(1).getFloat());
179  }
180 
181  if (type == VariantType::LinkedDirection)
182  {
183  // LinkedDirectionPtr lV1 = value.getClass<LinkedDirection>();
184  Eigen::Vector3f vec = value.getClass<LinkedDirection>()->toEigen();
185  return ((vec).norm() > getParameter(0).getFloat()) &&
186  ((vec).norm() < getParameter(1).getFloat());
187  }
188 
189  return false;
190  }
191 
192 } // namespace armarx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::ConditionCheck::addSupportedType
void addSupportedType(VariantTypeId dataFieldType=0, ParameterTypeList parameterTypes=ParameterTypeList())
Add a supported type for elementary condition check marks pairs of (dataFieldType,...
Definition: ConditionCheck.cpp:279
armarx::StringVariantMap
std::map< std::string, Variant > StringVariantMap
Definition: Variant.h:748
armarx::LinkedDirection
The LinkedDirection class.
Definition: LinkedPose.h:118
armarx::VariantType::Vector3
const VariantTypeId Vector3
Definition: Pose.h:38
armarx::ConditionCheckMagnitudeInRange::ConditionCheckMagnitudeInRange
ConditionCheckMagnitudeInRange()
Definition: ConditionCheckMagnitudeChecks.cpp:137
StringHelpers.h
IceInternal::Handle< FramedDirection >
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::ConditionCheckMagnitudeInRange::evaluate
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
Definition: ConditionCheckMagnitudeChecks.cpp:155
armarx::ConditionCheckMagnitudeInRange::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckMagnitudeChecks.cpp:149
armarx::toEigen
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)
Definition: PointToModelICP.h:67
armarx::ValueToString
std::string ValueToString(const T &value)
Definition: StringHelpers.h:61
armarx::ConditionCheck::getParameter
const Variant & getParameter(int index)
Retrieve parameters of check.
Definition: ConditionCheck.cpp:170
armarx::ConditionCheckMagnitudeLarger::ConditionCheckMagnitudeLarger
ConditionCheckMagnitudeLarger()
Definition: ConditionCheckMagnitudeChecks.cpp:31
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::ConditionCheck::createParameterTypeList
static ParameterTypeList createParameterTypeList(int numberTypes,...)
Definition: ConditionCheck.cpp:289
armarx::ConditionCheckMagnitudeLarger::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckMagnitudeChecks.cpp:42
armarx::Variant::getFloat
float getFloat(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as float.
Definition: Variant.cpp:532
armarx::ConditionCheckMagnitudeSmaller::evaluate
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
Definition: ConditionCheckMagnitudeChecks.cpp:102
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:43
armarx::ConditionCheckMagnitudeLarger::evaluate
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
Definition: ConditionCheckMagnitudeChecks.cpp:48
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:213
armarx::ConditionCheck
Definition: ConditionCheck.h:54
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:86
armarx::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:37
armarx::ConditionCheck::setNumberParameters
void setNumberParameters(int numberParameters)
Sets the number of paramaters required for this check.
Definition: ConditionCheck.cpp:273
armarx::ConditionCheckMagnitudeSmaller::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckMagnitudeChecks.cpp:96
ConditionCheckMagnitudeChecks.h
armarx::ConditionCheckMagnitudeSmaller::ConditionCheckMagnitudeSmaller
ConditionCheckMagnitudeSmaller()
Definition: ConditionCheckMagnitudeChecks.cpp:85
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
norm
double norm(const Point &a)
Definition: point.hpp:102
armarx::VariantType::LinkedDirection
const VariantTypeId LinkedDirection
Definition: LinkedPose.h:44