Cluster.cpp
Go to the documentation of this file.
1 
18 #include "Cluster.hpp"
19 #include "utility/Util.hpp"
20 #include "utility/LogHelper.hpp"
21 
22 namespace ISM
23 {
24  Cluster::Cluster(const std::pair<TrackPtr, ClusterPtr>& referenceWithParent,
25  ObjectRelations& topology, const std::vector<std::pair<int, TrackPtr> >& mostCommonObjects,
26  std::map<TrackPtr, int>& objectOccurences)
27  {
28  if (referenceWithParent.second == 0)
29  {
30  this->recommendedLevel = 0;
31  }
32  else
33  {
34  this->recommendedLevel = referenceWithParent.second->getRecommendedLevel() + 1;
35  }
36 
37  this->reference = referenceWithParent.first;
38  std::vector<TrackPtr> clustersTracks;
39  this->children = TracksPtr(new Tracks(clustersTracks));
40  //Iterate over relations to check whether the current Object is part of the current relation.
41  //If so, insert the track into the cluster and erase the current relation
42  bool referenceInserted = false;
43  for (ObjectRelations::iterator relationIt = topology.begin(); relationIt != topology.end();)
44  {
45  bool erased = false;
46  if (relationIt->second->containsObject(referenceWithParent.first->type,
47  referenceWithParent.first->observedId))
48  {
49  bool childInserted = false;
50  for (std::vector<std::pair<int, TrackPtr> >::const_iterator tracksIt = mostCommonObjects.begin();
51  tracksIt != mostCommonObjects.end();
52  ++tracksIt)
53  {
54  if (tracksIt->second->type == referenceWithParent.first->type &&
55  tracksIt->second->observedId == referenceWithParent.first->observedId)
56  {
57  if (referenceInserted == false)
58  {
59  this->children->tracks.push_back(TrackPtr(new Track(*(*tracksIt).second)));
60  referenceInserted = true;
61  std::vector<VoteSpecifierPtr> votes;
62 
63  for (size_t i = 0; i < referenceWithParent.first->objects.size(); ++i)
64  {
65  if (referenceWithParent.first->objects[i] == 0)
66  {
67  //Skips those snapshots where at least one of the two objects isn't present at all
68  continue;
69  }
71  double r = 0;
72  VoteSpecifierPtr vote = VoteSpecifierPtr(new VoteSpecifier(q,q,q,q,r));
73  vote->trackIndex = i;
74  votes.push_back(vote);
75  }
76  if (votesByVotersTypeAndObservedId.find(referenceWithParent.first->type) ==
78  {
79  votesByVotersTypeAndObservedId[referenceWithParent.first->type] =
80  std::map<std::string, std::vector<VoteSpecifierPtr>>();
81  }
82  votesByVotersTypeAndObservedId[referenceWithParent.first->type][referenceWithParent.first->observedId] = votes;
83  }
84  }
85  else if (relationIt->second->containsObject(tracksIt->second->type, tracksIt->second->observedId))
86  {
87  this->children->tracks.push_back(TrackPtr(new Track(*(*tracksIt).second)));
88  childInserted = true;
89  std::vector<VoteSpecifierPtr> votes;
90  if (relationIt->second->getObjectTypeA() == tracksIt->second->type &&
91  relationIt->second->getObjectIdA() == tracksIt->second->observedId)
92  {
93  votes = relationIt->second->getVotesFromAForReferencePoseB();
94  }
95  else
96  {
97  votes = relationIt->second->getVotesFromBForReferencePoseA();
98  }
99  if (votesByVotersTypeAndObservedId.find(tracksIt->second->type) ==
101  {
102  votesByVotersTypeAndObservedId[tracksIt->second->type] =
103  std::map<std::string, std::vector<VoteSpecifierPtr>>();
104  }
105  votesByVotersTypeAndObservedId[tracksIt->second->type][tracksIt->second->observedId] = votes;
106  }
107 
108  if (childInserted && referenceInserted)
109  {
110  break;
111  }
112  }
113 
114  objectOccurences[relationIt->second->getTrackA()] -= 1;
115  objectOccurences[relationIt->second->getTrackB()] -= 1;
116 
117  topology.erase(relationIt++);
118  erased = true;
119  }
120  if (!erased)
121  {
122  ++relationIt;
123  }
124  }
125  }
126 
127  std::vector<VoteSpecifierPtr> Cluster::getVotersByVotersTypeAndObservedId(const std::string& type,
128  const std::string &observedId) const
129  {
130  return this->votesByVotersTypeAndObservedId.at(type).at(observedId);
131  }
132 
134  {
135  return this->recommendedLevel;
136  }
137 }
boost::shared_ptr< Quaternion > QuaternionPtr
Definition: Quaternion.hpp:39
unsigned recommendedLevel
Definition: Cluster.hpp:51
Cluster(const std::pair< TrackPtr, boost::shared_ptr< Cluster > > &referenceWithParent, ObjectRelations &topology, const std::vector< std::pair< int, TrackPtr > > &mostCommonObjects, std::map< TrackPtr, int > &objectOccurences)
Definition: Cluster.cpp:24
std::vector< VoteSpecifierPtr > getVotersByVotersTypeAndObservedId(const std::string &type, const std::string &observedId) const
Definition: Cluster.cpp:127
TracksPtr children
Definition: Cluster.hpp:49
std::map< unsigned int, ISM::ObjectRelationPtr, std::less< unsigned > > ObjectRelations
unsigned getRecommendedLevel()
Definition: Cluster.cpp:133
boost::shared_ptr< VoteSpecifier > VoteSpecifierPtr
TrackPtr reference
Definition: Cluster.hpp:48
boost::shared_ptr< Tracks > TracksPtr
Definition: Tracks.hpp:42
std::map< std::string, std::map< std::string, std::vector< VoteSpecifierPtr > > > votesByVotersTypeAndObservedId
Definition: Cluster.hpp:50
boost::shared_ptr< Track > TrackPtr
Definition: Track.hpp:55
this namespace contains all generally usable classes.


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