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 
29 namespace armarx
30 {
31 
33  {
38 
39  }
40 
42  {
43  return new ConditionCheckMagnitudeLarger(*this);
44  }
45 
47  {
48 
49  if (dataFields.size() != 1)
50  {
51  throw InvalidConditionException("Wrong number of datafields for condition magnitude larger: expected 1 actual: " + ValueToString(dataFields.size()));
52  }
53 
54  const Variant& value = dataFields.begin()->second;
55  VariantTypeId type = value.getType();
56 
57  if (type == VariantType::Vector3)
58  {
59  Eigen::Vector3f vec = value.getClass<Vector3>()->toEigen();
60  return (vec).norm() > getParameter(0).getFloat();
61  }
62 
63  if (type == VariantType::FramedDirection)
64  {
65  FramedDirectionPtr fV1 = value.getClass<FramedDirection>();
66  Eigen::Vector3f vec = value.getClass<FramedDirection>()->toEigen();
67  return (vec).norm() > getParameter(0).getFloat();
68  }
69 
70  if (type == VariantType::LinkedDirection)
71  {
72  LinkedDirectionPtr lV1 = value.getClass<LinkedDirection>();
73 
74  Eigen::Vector3f vec = value.getClass<LinkedDirection>()->toEigen();
75  return (vec).norm() > getParameter(0).getFloat();
76  }
77 
78  return false;
79  }
80 
81 
83  {
88 
89  }
90 
92  {
93  return new ConditionCheckMagnitudeSmaller(*this);
94  }
95 
97  {
98 
99  if (dataFields.size() != 1)
100  {
101  ARMARX_WARNING_S << "Size of dataFields: %d\n" << dataFields.size();
102  throw InvalidConditionException("Wrong number of datafields for condition equals ");
103  }
104 
105  const Variant& value = dataFields.begin()->second;
106  VariantTypeId type = value.getType();
107 
108  if (type == VariantType::Vector3)
109  {
110  Eigen::Vector3f vec = value.getClass<Vector3>()->toEigen();
111  return (vec).norm() < getParameter(0).getFloat();
112  }
113 
114  if (type == VariantType::FramedDirection)
115  {
116  // FramedDirectionPtr fV1 = value.getClass<FramedDirection>();
117  Eigen::Vector3f vec = value.getClass<FramedDirection>()->toEigen();
118  return (vec).norm() < getParameter(0).getFloat();
119  }
120 
121  if (type == VariantType::LinkedDirection)
122  {
123  // LinkedDirectionPtr lV1 = value.getClass<LinkedDirection>();
124  Eigen::Vector3f vec = value.getClass<LinkedDirection>()->toEigen();
125  return (vec).norm() < getParameter(0).getFloat();
126  }
127 
128  return false;
129  }
130 
132  {
137 
138  }
139 
141  {
142  return new ConditionCheckMagnitudeInRange(*this);
143  }
144 
146  {
147  if (dataFields.size() != 1)
148  {
149  ARMARX_WARNING_S << "Size of dataFields: " << dataFields.size();
150  throw InvalidConditionException("Wrong number of datafields for condition InRange ");
151  }
152 
153  const Variant& value = dataFields.begin()->second;
154  VariantTypeId type = value.getType();
155 
156  if (type == VariantType::Vector3)
157  {
158  Eigen::Vector3f vec = value.getClass<Vector3>()->toEigen();
159  return ((vec).norm() > getParameter(0).getFloat()) && ((vec).norm() < getParameter(1).getFloat());
160  }
161 
162  if (type == VariantType::FramedDirection)
163  {
164  // FramedDirectionPtr fV1 = value.getClass<FramedDirection>();
165  Eigen::Vector3f vec = value.getClass<FramedDirection>()->toEigen();
166  return ((vec).norm() > getParameter(0).getFloat()) && ((vec).norm() < getParameter(1).getFloat());
167  }
168 
169  if (type == VariantType::LinkedDirection)
170  {
171  // LinkedDirectionPtr lV1 = value.getClass<LinkedDirection>();
172  Eigen::Vector3f vec = value.getClass<LinkedDirection>()->toEigen();
173  return ((vec).norm() > getParameter(0).getFloat()) && ((vec).norm() < getParameter(1).getFloat());
174  }
175 
176  return false;
177  }
178 
179 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
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:250
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
armarx::StringVariantMap
std::map< std::string, Variant > StringVariantMap
Definition: Variant.h:748
armarx::LinkedDirection
The LinkedDirection class.
Definition: LinkedPose.h:113
armarx::VariantType::Vector3
const VariantTypeId Vector3
Definition: Pose.h:38
armarx::ConditionCheckMagnitudeInRange::ConditionCheckMagnitudeInRange
ConditionCheckMagnitudeInRange()
Definition: ConditionCheckMagnitudeChecks.cpp:131
StringHelpers.h
IceInternal::Handle< FramedDirection >
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::ConditionCheckMagnitudeInRange::evaluate
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
Definition: ConditionCheckMagnitudeChecks.cpp:145
armarx::ConditionCheckMagnitudeInRange::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckMagnitudeChecks.cpp:140
armarx::ValueToString
std::string ValueToString(const T &value)
Definition: StringHelpers.h:58
armarx::ConditionCheck::getParameter
const Variant & getParameter(int index)
Retrieve parameters of check.
Definition: ConditionCheck.cpp:151
armarx::ConditionCheckMagnitudeLarger::ConditionCheckMagnitudeLarger
ConditionCheckMagnitudeLarger()
Definition: ConditionCheckMagnitudeChecks.cpp:32
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::ConditionCheck::createParameterTypeList
static ParameterTypeList createParameterTypeList(int numberTypes,...)
Definition: ConditionCheck.cpp:259
armarx::ConditionCheckMagnitudeLarger::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckMagnitudeChecks.cpp:41
armarx::Variant::getFloat
float getFloat(const Ice::Current &c=Ice::emptyCurrent) const override
Return the Variant's value as float.
Definition: Variant.cpp:434
armarx::ConditionCheckMagnitudeSmaller::evaluate
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
Definition: ConditionCheckMagnitudeChecks.cpp:96
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::ConditionCheckMagnitudeLarger::evaluate
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
Definition: ConditionCheckMagnitudeChecks.cpp:46
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::ConditionCheck
Definition: ConditionCheck.h:56
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:83
armarx::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:38
armarx::ConditionCheck::setNumberParameters
void setNumberParameters(int numberParameters)
Sets the number of paramaters required for this check.
Definition: ConditionCheck.cpp:245
armarx::ConditionCheckMagnitudeSmaller::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckMagnitudeChecks.cpp:91
ConditionCheckMagnitudeChecks.h
armarx::ConditionCheckMagnitudeSmaller::ConditionCheckMagnitudeSmaller
ConditionCheckMagnitudeSmaller()
Definition: ConditionCheckMagnitudeChecks.cpp:82
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
norm
double norm(const Point &a)
Definition: point.hpp:94
armarx::VariantType::LinkedDirection
const VariantTypeId LinkedDirection
Definition: LinkedPose.h:44