ObjectRelation.cpp
Go to the documentation of this file.
1 
18 #include <stdlib.h>
19 
20 #include "ObjectRelation.hpp"
24 
25 namespace ISM
26 {
28  {
29  this->votesFromBForReferencePoseA = std::vector<VoteSpecifierPtr>();
30  this->votesFromAForReferencePoseB = std::vector<VoteSpecifierPtr>();
31  if (objectA == 0 || objectB == 0)
32  {
33  std::cerr<<"invalid tracks\n";
34  exit(EXIT_FAILURE);
35  }
36  for (size_t i = 0; i < objectA->objects.size() && i < objectB->objects.size(); ++i)
37  {
38  //Keep in mind that the reference object gets voted for, so voteBToA actually refers
39  //to the relative Positions of B in relation to A which is why voteBToA is
40  //inserted to aToB. aToB means: where might B be from A point of view
41  if (objectA->objects[i] == 0 || objectB->objects[i] == 0)
42  {
43  //Skips those snapshots where at least one of the two objects isn't present at all
44  continue;
45  }
46  VoteSpecifierPtr voteFromBForReferencePoseA =
47  GeometryHelper::createVoteSpecifier(objectB->objects[i]->pose,
48  objectA->objects[i]->pose);
49 
50  assert(GeometryHelper::poseEqual(GeometryHelper::getPoseFromVote(objectB->objects[i]->pose,
51  voteFromBForReferencePoseA),
52  objectA->objects[i]->pose));
53 
54  voteFromBForReferencePoseA->patternName = patternName;
55  voteFromBForReferencePoseA->observedId = objectB->observedId;
56  voteFromBForReferencePoseA->objectType = objectB->type;
57  voteFromBForReferencePoseA->trackIndex = i;
58  voteFromBForReferencePoseA->weight = 0;
59  this->votesFromBForReferencePoseA.push_back(voteFromBForReferencePoseA);
60 
61  VoteSpecifierPtr voteFromAForReferencePoseB =
62  GeometryHelper::createVoteSpecifier(objectA->objects[i]->pose,
63  objectB->objects[i]->pose);
64 
65  assert(GeometryHelper::poseEqual(GeometryHelper::getPoseFromVote(objectA->objects[i]->pose,
66  voteFromAForReferencePoseB),
67  objectB->objects[i]->pose));
68 
69  voteFromAForReferencePoseB->patternName = patternName;
70  voteFromAForReferencePoseB->observedId = objectA->observedId;
71  voteFromAForReferencePoseB->objectType = objectA->type;
72  voteFromAForReferencePoseB->trackIndex = i;
73  voteFromAForReferencePoseB->weight = 0;
74  this->votesFromAForReferencePoseB.push_back(voteFromAForReferencePoseB);
75  }
76  this->objectIdA = objectA->observedId;
77  this->objectIdB = objectB->observedId;
78  this->objectTypeA = objectA->type;
79  this->objectTypeB = objectB->type;
80  this->trackA = objectA;
81  this->trackB = objectB;
82  }
83 
85  {
86  this->votesFromBForReferencePoseA = std::vector<VoteSpecifierPtr>();
87  this->votesFromAForReferencePoseB = std::vector<VoteSpecifierPtr>();
88  if (objectA == 0)
89  {
90  std::cerr<<"invalid tracks\n";
91  exit(EXIT_FAILURE);
92  }
93 
94  for (size_t i = 0; i < objectA->objects.size(); ++i)
95  {
96  //Keep in mind that the reference object gets voted for, so voteBToA actually refers
97  //to the relative Positions of B in relation to A which is why voteBToA is
98  //inserted to aToB. aToB means: where might B be from A point of view
99  if (objectA->objects[i] == 0)
100  {
101  //Skips those snapshots where at least one of the two objects isn't present at all
102  continue;
103  }
104  //Identity quaternion. No transformation to self is needed
106  double r = 0;
107  VoteSpecifierPtr voteFromBForReferencePoseA = VoteSpecifierPtr(new VoteSpecifier(q,q,q,q,r));
108  voteFromBForReferencePoseA->patternName = patternName;
109  voteFromBForReferencePoseA->observedId = objectA->observedId;
110  voteFromBForReferencePoseA->objectType = objectA->type;
111  voteFromBForReferencePoseA->trackIndex = i;
112  voteFromBForReferencePoseA->weight = 0;
113  this->votesFromBForReferencePoseA.push_back(voteFromBForReferencePoseA);
114 
115  VoteSpecifierPtr voteFromAForReferencePoseB = VoteSpecifierPtr(new VoteSpecifier(q,q,q,q,r));
116  voteFromAForReferencePoseB->patternName = patternName;
117  voteFromAForReferencePoseB->observedId = objectA->observedId;
118  voteFromAForReferencePoseB->objectType = objectA->type;
119  voteFromAForReferencePoseB->trackIndex = i;
120  voteFromAForReferencePoseB->weight = 0;
121  this->votesFromAForReferencePoseB.push_back(voteFromAForReferencePoseB);
122  }
123  this->objectIdA = objectA->observedId;
124  this->objectIdB = objectA->observedId;
125  this->objectTypeA = objectA->type;
126  this->objectTypeB = objectA->type;
127  this->trackA = objectA;
128  this->trackB = objectA;
129  }
130 
131  std::string ObjectRelation::getObjectIdA() const
132  {
133  return objectIdA;
134  }
135 
136  std::string ObjectRelation::getObjectIdB() const
137  {
138  return objectIdB;
139  }
140 
141  std::string ObjectRelation::getObjectTypeA() const
142  {
143  return objectTypeA;
144  }
145 
146  std::string ObjectRelation::getObjectTypeB() const
147  {
148  return objectTypeB;
149  }
150 
151  std::vector<ISM::VoteSpecifierPtr> ObjectRelation::getVotesFromAForReferencePoseB() const
152  {
153  return this->votesFromAForReferencePoseB;
154  }
155 
156  std::vector<ISM::VoteSpecifierPtr> ObjectRelation::getVotesFromBForReferencePoseA() const
157  {
158  return this->votesFromBForReferencePoseA;
159  }
160 
161  bool ObjectRelation::containsObject(const std::string& type, const std::string& id)
162  {
163  return ((type == getObjectTypeA() && id == getObjectIdA()) ||
164  (type == getObjectTypeB() && id == getObjectIdB()));
165  }
166 
167  std::ostream& operator<<(std::ostream &strm, const ISM::ObjectRelation &r) {
168  return strm << r.getObjectTypeA() << " (ID: " << r.getObjectIdA()<<") <-> "
169  << r.getObjectTypeB() << " (ID: " << r.getObjectIdB()<<")";
170  }
171 
172  std::ostream& operator<<(std::ostream &strm, const ISM::ObjectRelationPtr &r) {
173  return strm<<(*r);
174  }
175 
176  std::ostream& operator<<(std::ostream &strm, const ISM::ObjectRelations &r) {
177  ISM::ObjectRelations relations = r;
178  std::ostringstream os;
179  strm << "Topology [";
180  for (ObjectRelations::iterator it = relations.begin(); it != relations.end();)
181  {
182  strm << it->first;
183  os << "\t- Relation " << it->first << " : " << it->second << std::endl;
184 
185  ++it;
186  if (it != relations.end())
187  {
188  strm << ", ";
189  } else {
190  os << std::endl;
191  }
192  }
193  strm << "] with relations : " << std::endl << os.str();
194  return strm;
195  }
196 
197  void ObjectRelation::serialize(std::ostream& strm) const {
198  strm << "{\"typeA\": " << this->getObjectTypeA()
199  << ", \"idA\": " <<this->getObjectIdA()
200  << ", \"typeB\": " << this->getObjectIdB()
201  << ", \"idB\": " << this->getObjectIdB() << "}";
202  }
203 
204 }
boost::shared_ptr< Quaternion > QuaternionPtr
Definition: Quaternion.hpp:39
static VoteSpecifierPtr createVoteSpecifier(const PosePtr &sourcePose, const PosePtr &refPose)
std::vector< ISM::VoteSpecifierPtr > getVotesFromBForReferencePoseA() const
boost::shared_ptr< ISM::ObjectRelation > ObjectRelationPtr
static PosePtr getPoseFromVote(const PosePtr &source, const VoteSpecifierPtr &vote)
std::vector< VoteSpecifierPtr > votesFromAForReferencePoseB
std::string patternName
std::string getObjectTypeA() const
virtual void serialize(std::ostream &strm) const
std::map< unsigned int, ISM::ObjectRelationPtr, std::less< unsigned > > ObjectRelations
std::ostream & operator<<(std::ostream &strm, const ISM::ObjectRelation &r)
static bool poseEqual(const PosePtr &p1, const PosePtr &p2)
std::string getObjectTypeB() const
boost::shared_ptr< VoteSpecifier > VoteSpecifierPtr
std::vector< VoteSpecifierPtr > votesFromBForReferencePoseA
std::vector< ISM::VoteSpecifierPtr > getVotesFromAForReferencePoseB() const
bool containsObject(const std::string &type, const std::string &id)
std::string getObjectIdB() const
boost::shared_ptr< Track > TrackPtr
Definition: Track.hpp:55
ObjectRelation(ISM::TrackPtr objectA, ISM::TrackPtr objectB, std::string patternName)
this namespace contains all generally usable classes.
std::string getObjectIdA() const


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:40