SECRelation.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 MemoryX::
17 * @author Mirko Waechter ( mirko.waechter at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "SECRelation.h"
24 
25 #include "../ObjectClass.h"
26 #include "../../segment/ObjectClassMemorySegment.h"
27 
30 
31 namespace memoryx
32 {
33 
35  {
36  }
37 
38  SECRelation::SECRelation(const std::string& relationName, const memoryx::ObjectClassList& possibleObjects1, const memoryx::ObjectClassList& possibleObjects2)
39  {
40  name = relationName;
41  ARMARX_CHECK_EXPRESSION(possibleObjects1.size() > 0);
42  ARMARX_CHECK_EXPRESSION(possibleObjects2.size() > 0);
43  objects1 = possibleObjects1;
44  objects2 = possibleObjects2;
45  }
46 
47  SECRelation::SECRelation(const std::string& relationName, const ObjectClassBasePtr& possibleObject1, const ObjectClassBasePtr& possibleObject2)
48  {
49  name = relationName;
50  ARMARX_CHECK_EXPRESSION(possibleObject1);
51  ARMARX_CHECK_EXPRESSION(possibleObject2);
52  objects1.push_back(possibleObject1);
53  objects2.push_back(possibleObject2);
54  }
55 
57  {
58  return clone();
59  }
60 
61  bool SECRelation::isEqual(const SECRelationBasePtr& other, bool ignoreName) const
62  {
63  return _isEqual(other, ignoreName, false);
64  }
65 
66  bool SECRelation::isEqual(const SECRelationBasePtr& other, const Ice::Current&) const
67  {
68  return isEqual(other, false);
69  }
70 
71  bool SECRelation::hasEqualObjects(const SECRelationBasePtr& other, const Ice::Current&)
72  {
73  return isEqual(other, true);
74  }
75 
76  std::string SECRelation::getName(const Ice::Current& c) const
77  {
78  return name;
79  }
80 
81 
82  void SECRelation::setName(const std::string& name, const Ice::Current&)
83  {
84  this->name = name;
85  }
86 
87 
88 
89  std::string SECRelation::objects1ToString() const
90  {
92  }
93 
94  std::string SECRelation::objects2ToString() const
95  {
97  }
98 
99 
100 
101 
102  bool SECRelation::_isEqual(const SECRelationBasePtr& other, bool ignoreName, bool reversed) const
103  {
104  if (!ignoreName && getName() != other->getName())
105  {
106  return false;
107  }
108 
109  bool foundMatchObj1 = false;
110 
111  for (ObjectClassList::const_iterator it = objects1.begin(); it != objects1.end(); it++)
112  {
113  for (ObjectClassList::const_iterator itOther = other->objects1.begin(); itOther != other->objects1.end(); itOther++)
114  {
115  // ARMARX_VERBOSE_S << "Comparing " << (*it)->getName() << " with " << (*itOther)->getName();
116  if ((*it)->compare(*itOther) == eEqualClass /*|| (*itOther)->compare(*it) == eEqualClass*/)
117  {
118  foundMatchObj1 = true;
119  }
120  }
121  }
122 
123  bool foundMatchObj2 = false;
124 
125  for (ObjectClassList::const_iterator it = objects2.begin(); it != objects2.end(); it++)
126  {
127  for (ObjectClassList::const_iterator itOther = other->objects2.begin(); itOther != other->objects2.end(); itOther++)
128  {
129  // ARMARX_VERBOSE_S << "Comparing " << (*it)->getName() << " with " << (*itOther)->getName();
130  if ((*it)->compare(*itOther) == eEqualClass /*|| (*itOther)->compare(*it) == eEqualClass*/)
131  {
132  foundMatchObj2 = true;
133  }
134  }
135  }
136 
137  bool result = foundMatchObj1 && foundMatchObj2;
138 
139  if (!result && !reversed)
140  {
141  SECRelationBasePtr inverseRelation = new SECRelation(getName(), other->objects2, other->objects1);
142  return _isEqual(inverseRelation, ignoreName, true);
143  }
144  else
145  {
146  return result;
147  }
148  }
149 
151  {
152  name = "NoConnection";
153  }
154 
155  Relations::NoConnectionRelation::NoConnectionRelation(const ObjectClassList& possibleObjects1, const ObjectClassList& possibleObjects2)
156  : SECRelation("NoConnection", possibleObjects1, possibleObjects2)
157  {
158 
159  }
160 
161  Relations::NoConnectionRelation::NoConnectionRelation(const ObjectClassBasePtr& possibleObject1, const ObjectClassBasePtr& possibleObject2) :
162  SECRelation("NoConnection", possibleObject1, possibleObject2)
163  {
164 
165  }
166 
168  {
169  name = "Touching";
170  }
171 
172  Relations::TouchingRelation::TouchingRelation(const ObjectClassList& possibleObjects1, const ObjectClassList& possibleObjects2)
173  : SECRelation("Touching", possibleObjects1, possibleObjects2)
174  {
175 
176  }
177 
178  Relations::TouchingRelation::TouchingRelation(const ObjectClassBasePtr& possibleObject1, const ObjectClassBasePtr& possibleObject2) :
179  SECRelation("Touching", possibleObject1, possibleObject2)
180  {
181  }
182 
184  {
185  name = "BehindOf";
186  }
187 
188  Relations::BehindOfRelation::BehindOfRelation(const ObjectClassList& possibleObjects1, const ObjectClassList& possibleObjects2)
189  : SECRelation("BehindOf", possibleObjects1, possibleObjects2)
190  {
191 
192  }
193 
194  Relations::BehindOfRelation::BehindOfRelation(const ObjectClassBasePtr& possibleObject1, const ObjectClassBasePtr& possibleObject2) :
195  SECRelation("BehindOf", possibleObject1, possibleObject2)
196  {
197  }
198 
200  {
201  name = "LeftTo";
202  }
203 
204  Relations::LeftToRelation::LeftToRelation(const ObjectClassList& possibleObjects1, const ObjectClassList& possibleObjects2)
205  : SECRelation("LeftTo", possibleObjects1, possibleObjects2)
206  {
207 
208  }
209 
210  Relations::LeftToRelation::LeftToRelation(const ObjectClassBasePtr& possibleObject1, const ObjectClassBasePtr& possibleObject2) :
211  SECRelation("LeftTo", possibleObject1, possibleObject2)
212  {
213  }
214 
216  {
217  name = "RightTo";
218  }
219 
220  Relations::RightToRelation::RightToRelation(const ObjectClassList& possibleObjects1, const ObjectClassList& possibleObjects2)
221  : SECRelation("RightTo", possibleObjects1, possibleObjects2)
222  {
223 
224  }
225 
226  Relations::RightToRelation::RightToRelation(const ObjectClassBasePtr& possibleObject1, const ObjectClassBasePtr& possibleObject2) :
227  SECRelation("RightTo", possibleObject1, possibleObject2)
228  {
229  }
230 
231 
232  armarx::VariantDataClassPtr SECRelation::clone(const Ice::Current&) const
233  {
234  SECRelationPtr result = new SECRelation();
235  result->name = getName();
236 
237  for (ObjectClassList::const_iterator it = objects1.begin(); it != objects1.end(); it++)
238  {
239  result->objects1.push_back(ObjectClassBasePtr::dynamicCast((*it)->ice_clone()));
240  }
241 
242  for (ObjectClassList::const_iterator it = objects2.begin(); it != objects2.end(); it++)
243  {
244  result->objects2.push_back(ObjectClassBasePtr::dynamicCast((*it)->ice_clone()));
245  }
246 
247  return result;
248  }
249 
250  std::string SECRelation::output(const Ice::Current&) const
251  {
252  return getName() + " between " + objects1ToString() + " and " + objects2ToString();
253  }
254 
255  Ice::Int SECRelation::getType(const Ice::Current&) const
256  {
258  }
259 
260  bool SECRelation::validate(const Ice::Current&)
261  {
262  return true;
263  }
264 
265  void SECRelation::serialize(const armarx::ObjectSerializerBasePtr& serializer, const Ice::Current&) const
266  {
267  armarx::AbstractObjectSerializerPtr obj = armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
268  obj->setString("relationName", getName());
269  obj->setStringArray("objects1", ObjectClassMemorySegment::ObjectsToStringList(objects1));
270  obj->setStringArray("objects2", ObjectClassMemorySegment::ObjectsToStringList(objects2));
271  }
272 
273  void SECRelation::deserialize(const armarx::ObjectSerializerBasePtr& serializer, const Ice::Current&)
274  {
275  armarx::AbstractObjectSerializerPtr obj = armarx::AbstractObjectSerializerPtr::dynamicCast(serializer);
276  name = obj->getString("relationName");
277  Ice::StringSeq objectStrings1;
278  obj->getStringArray("objects1", objectStrings1);
279 
280  for (Ice::StringSeq::iterator it = objectStrings1.begin(); it != objectStrings1.end(); it++)
281  {
282  ObjectClassPtr newObj = new ObjectClass();
283  newObj->setName(*it);
284  objects1.push_back(newObj);
285  }
286 
287  Ice::StringSeq objectStrings2;
288  obj->getStringArray("objects2", objectStrings2);
289 
290  for (Ice::StringSeq::iterator it = objectStrings2.begin(); it != objectStrings2.end(); it++)
291  {
292  ObjectClassPtr newObj = new ObjectClass();
293  newObj->setName(*it);
294  objects2.push_back(newObj);
295  }
296  }
297 
298 } // namespace memoryx
299 
300 
301 
302 
303 
304 
305 
306 
307 
memoryx::SECRelation::SECRelation
SECRelation()
Definition: SECRelation.cpp:34
memoryx::VariantType::SECRelation
const armarx::VariantTypeId SECRelation
Definition: SECRelation.h:31
memoryx::Relations::LeftToRelation::LeftToRelation
LeftToRelation()
Definition: SECRelation.cpp:199
memoryx::SECRelation::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: SECRelation.cpp:56
memoryx::SECRelation::_isEqual
bool _isEqual(const SECRelationBasePtr &other, bool ignoreName=false, bool reversed=false) const
Definition: SECRelation.cpp:102
memoryx::SECRelation::serialize
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) const override
Definition: SECRelation.cpp:265
AbstractObjectSerializer.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::Relations::TouchingRelation::TouchingRelation
TouchingRelation()
Definition: SECRelation.cpp:167
memoryx::SECRelation::clone
armarx::VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: SECRelation.cpp:232
memoryx::Relations::NoConnectionRelation::NoConnectionRelation
NoConnectionRelation()
Definition: SECRelation.cpp:150
memoryx::Relations::BehindOfRelation::BehindOfRelation
BehindOfRelation()
Definition: SECRelation.cpp:183
memoryx::SECRelation::isEqual
bool isEqual(const SECRelationBasePtr &other, bool ignoreName) const
Definition: SECRelation.cpp:61
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::SECRelation::hasEqualObjects
bool hasEqualObjects(const SECRelationBasePtr &other, const Ice::Current &c=Ice::emptyCurrent) override
Definition: SECRelation.cpp:71
memoryx::SECRelation::objects1ToString
std::string objects1ToString() const
Definition: SECRelation.cpp:89
memoryx::ObjectClassMemorySegment::ObjectsToStringList
static Ice::StringSeq ObjectsToStringList(const ObjectClassList &objects)
Definition: ObjectClassMemorySegment.h:220
memoryx::SECRelation
Definition: SECRelation.h:36
memoryx::SECRelation::validate
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Definition: SECRelation.cpp:260
memoryx::ObjectClass
Definition: ObjectClass.h:37
ExpressionException.h
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
memoryx::SECRelation::output
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: SECRelation.cpp:250
memoryx::SECRelation::deserialize
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const Ice::Current &c=Ice::emptyCurrent) override
Definition: SECRelation.cpp:273
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
memoryx::SECRelation::getName
std::string getName(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: SECRelation.cpp:76
memoryx::SECRelation::getType
Ice::Int getType(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: SECRelation.cpp:255
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::ObjectClassMemorySegment::ObjectsToString
static std::string ObjectsToString(const ObjectClassList &objects)
Definition: ObjectClassMemorySegment.h:197
memoryx::SECRelation::setName
void setName(const std::string &name, const Ice::Current &c=Ice::emptyCurrent) override
Definition: SECRelation.cpp:82
memoryx::SECRelation::objects2ToString
std::string objects2ToString() const
Definition: SECRelation.cpp:94
memoryx::Relations::RightToRelation::RightToRelation
RightToRelation()
Definition: SECRelation.cpp:215
SECRelation.h