VotingResultCalculator.cpp
Go to the documentation of this file.
1 
20 
21 namespace ISM {
22 
23  typedef GeometryHelper GH;
24 
25  VotingResultCalculator::VotingResultCalculator(VotingSpacePtr votingSpaceInEval, bool enableSelfVoteCheck, int raterType) : mVotingSpaceInEval(votingSpaceInEval), enabledSelfVoteCheck(enableSelfVoteCheck)
26 
27  {
28 
30 
31  switch (raterType) {
32  case 1:
33  this->mRater = ISM::RaterPtr(new ISM::APORater(votingSpaceInEval->binSize, votingSpaceInEval->maxProjectionAngleDeviation));
34  break;
35  default:
36  this->mRater = ISM::RaterPtr(new ISM::SimpleRater(votingSpaceInEval->binSize, votingSpaceInEval->maxProjectionAngleDeviation));
37  break;
38  }
39 
40  }
41 
43 
44  {
45  //We check if there are any reference object votes in the vote set from radius search.
46  bool voteFromReferenceObjectExists;
47 
48  //Now we go through all votes, used as origins for fitting.
49  for (TypeToInnerMap::iterator typeIt = votedReferencePoses.begin();
50  typeIt != votedReferencePoses.end(); typeIt++)
51  {
52  for (IdToVoteMap::iterator idIt = typeIt->second.begin();
53  idIt != typeIt->second.end(); idIt++)
54  {
55  //But we analyze this voxel grid element just once (one call by VotingSpace).
56  for (VotedPosePtrs::iterator voteIt = idIt->second.begin();
57  voteIt != idIt->second.end(); voteIt++)
58  {
59  //All objects are allowed to vote for this new originForFitting
61 
62  originForFitting = *voteIt;
63 
64  //If there is any votedPose for the current type and id combination that we previously set as originForFitting it should not be at the same pose as that we now want to set as originForFitting.
65  if(voteIt != idIt->second.begin())
66  {
67  VotedPosePtrs::iterator previousVoteIt = std::prev(voteIt);
68  if (GH::poseEqual((*voteIt)->pose, (*previousVoteIt)->pose))
69  continue;
70  }
71 
72  //Get votes to fit from radius search
73  TypeToInnerMap votes = mVotingSpaceInEval->collectVotesInSphere(originForFitting->pose->point, voteFromReferenceObjectExists);
74 
75  //In case a reference vote exists in our votedPose, we just accept selfvotes from it as originForFitting.
76  if (enabledSelfVoteCheck && voteFromReferenceObjectExists && !GH::isSelfVote(originForFitting->vote))
77  {
78  continue;
79  }
80 
81  //Set votedPose, to which others are going to be fitted, before we start matching the rest.
83  originType = typeIt->first;
84  originId = idIt->first;
85 
87 
88  //originForFitting is trivially fitting itself and until now we have one exemplary of it.
89  summarizedFittingVotes.push_back(std::make_pair(originForFitting, std::make_pair(1u, originForFitting->weight)));
90 
91  //Here we look for all fitting votes (from origin source and other objects) for the currently chosen origin.
92  searchFittingVotes(votes);
93 
94  double confidence = 0;
95  ObjectSetPtr objSet(new ObjectSet());
96 
97  //Create objects in RecognitionResult and calculate confidence of RecognitionResult.
98  for (SummarizedVotedPosePtr summarizedVote : summarizedFittingVotes)
99  {
100  VotedPosePtr votedPose = summarizedVote.first;
101  double tmpWeight = summarizedVote.second.second;
102  confidence += (tmpWeight / votedPose->weightDenominator);
103  ObjectPtr obj(new Object((*votedPose->source)));
104  obj->type = votedPose->vote->objectType;
105  obj->observedId = votedPose->vote->observedId;
106  obj->weight = tmpWeight;
107  if(obj->type.find("_sub") == std::string::npos)
108  {
109  obj->confidence = votedPose->weight;
110  }
111  objSet->insert(obj);
112  }
113  //We overwrite previous VotingResult for this votes if it is the best rated result.
114  if ((confidence > 0) && (!result || (result->confidence < confidence)))
115  {
116  result = VotingResultPtr(new VotingResult(objSet, originPose, confidence, summarizedFittingVotes));
117  //Abort searching for this vote set once a perfect VotingResult for this bin, since we return one at all.
118  if (confidence >= 1.0 - VotingSpace::epsilon)
119  return true;
120  }
121  }
122  }
123  }
124 
125  return (result != nullptr);
126 
127  }
128 
130  {
131 
132  //Count fitting votes for current type and id combination.
133  unsigned int fittingVoteCounter;
134  //For the current type and id combination, we explicitly just add the votedPose that fits best to originForFitting.
135  VotedPosePtr bestVotedPose;
136  double bestWeight;
137 
138  //Fit votes for each combination of type and id.
139  for (TypeToInnerMap::iterator typeIt = votes.begin();
140  typeIt != votes.end(); typeIt++)
141  {
142 
143  for (IdToVoteMap::iterator idIt = typeIt->second.begin();
144  idIt != typeIt->second.end(); idIt++)
145  {
146 
147  //If we encounter votes from originForFitting, just count them if they are supporting.
148  if (typeIt->first == originType && idIt->first == originId)
149  {
150  fittingVoteCounter = countSupportingOriginForFittingVotes(idIt->second);
151  }
152  else
153  {
154  countSupportingOriginForFittingVotes(idIt->second, fittingVoteCounter, bestWeight, bestVotedPose);
155  }
156 
157  //If we found any vote from the current type and id combination
158  if (fittingVoteCounter > 0)
159  {
160  //We also count all fitting votes from the object that delivers originForFitting.
161  if(typeIt->first == originType && idIt->first == originId)
162  {
163  summarizedFittingVotes.front().second.first = fittingVoteCounter;
164  sourcesWithFittingVotes.insert(summarizedFittingVotes.front().first->source);
165  }
166  //Just add new optimally fitting votedPose to RecognitionResult if votedPos is not coming from object that delivers originForFitting.
167  else
168  {
169  summarizedFittingVotes.push_back(std::make_pair(bestVotedPose, std::make_pair(fittingVoteCounter, bestWeight)));
170  //Do not process votes from currently processed "object" for this originForFitting.
171  sourcesWithFittingVotes.insert(bestVotedPose->source);
172  }
173  }
174  }
175  }
176  }
177 
178 }
179 
bool computeVotingResult(VotingResultPtr &result, TypeToInnerMap votedReferencePoses)
static bool isSelfVote(const VoteSpecifierPtr &vote)
void searchFittingVotes(TypeToInnerMap votes)
boost::shared_ptr< VotingResult > VotingResultPtr
Definition: typedef.hpp:37
boost::shared_ptr< RatingData > RatingDataPtr
Definition: RatingData.hpp:38
SummarizedVotedPosePtrs summarizedFittingVotes
boost::shared_ptr< BaseRater > RaterPtr
Definition: BaseRater.hpp:91
boost::shared_ptr< VotedPose > VotedPosePtr
Definition: typedef.hpp:31
std::map< std::string, IdToVoteMap > TypeToInnerMap
Definition: typedef.hpp:71
VotingResultCalculator(VotingSpacePtr votingSpaceInEval, bool enabledSelfVoteCheck, int raterType=0)
static bool poseEqual(const PosePtr &p1, const PosePtr &p2)
GeometryHelper GH
boost::shared_ptr< ObjectSet > ObjectSetPtr
Definition: ObjectSet.hpp:53
std::set< ObjectPtr > sourcesWithFittingVotes
std::vector< SummarizedVotedPosePtr > SummarizedVotedPosePtrs
Definition: typedef.hpp:75
std::pair< VotedPosePtr, CountWeightPair > SummarizedVotedPosePtr
Definition: typedef.hpp:74
unsigned int countSupportingOriginForFittingVotes(VotedPosePtrs originForFittingVotes)
static constexpr double epsilon
Definition: VotingSpace.hpp:76
boost::shared_ptr< VotingSpace > VotingSpacePtr
Definition: typedef.hpp:34
this namespace contains all generally usable classes.
boost::shared_ptr< Object > ObjectPtr
Definition: Object.hpp:82


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:41