VotingResultCalculator.hpp
Go to the documentation of this file.
1 
18 #include <map>
19 #include <stack>
20 #include <set>
21 #include <vector>
22 #include <iostream>
23 
24 //Local includes
25 #include "common_type/Pattern.hpp"
27 #include "VotingSpace.hpp"
28 #include "VotingResult.hpp"
29 #include "rating/SimpleRater.hpp"
30 #include "rating/APORater.hpp"
31 #include "rating/RatingData.hpp"
32 #include "typedef.hpp"
33 
34 namespace ISM {
35  //Searches scene instances in given sets of votes and lets VotingSpace perform radius search if that features is requested.
37  {
38  public:
39 
40  VotingResultCalculator(VotingSpacePtr votingSpaceInEval, bool enabledSelfVoteCheck, int raterType = 0);
41 
42  //Compute VotingResults (result) from a set of VotedPoses (votedReferencePoses). Calls searchFittingVotes.
43  bool computeVotingResult(VotingResultPtr& result, TypeToInnerMap votedReferencePoses);
44 
45  private:
46 
47  //Matches given votes to a originForFitting, chosen beforehand.
49 
50  //Voting space used for radius search.
52  //Simple or APO-Rater
54 
55  //VotedPose for reference, used as starting point (reference) for fitting process (either in bin or in sphere).
57  //The pose inside originForFitting.
59  //Used to recognize votes from originForFitting
60  std::string originType;
61  std::string originId;
62 
63  //All votedPoses that fit current originForFitting are counted and added to RecognitionResult.
65 
66  //Cache data for rating to prevent calculating already calculated data again.
68 
69  //To prevent that the same object votes multiple times when evaluating an originForFitting (could happen in ism tree during iterative scene recognition).
70  std::set<ObjectPtr> sourcesWithFittingVotes;
71 
72  //If SelfVoteCheck is active, the use of votedPose from a selfvoting object as originForFitting, in case such an object exists, is ensured.
74 
75  //Both following methods inlined for performance reasons.
76 
77  //For the type and id combination providing originForFitting: Calculate all its votes that fit.
78  unsigned int countSupportingOriginForFittingVotes(VotedPosePtrs originForFittingVotes)
79  {
80 
81  VotedPosePtr currentVotedPose;
82  unsigned int fittingVoteCounter = 0;
83 
84  //Go through all votes for current type and id combination.
85  for (VotedPosePtrs::iterator voteIt = originForFittingVotes.begin(); voteIt != originForFittingVotes.end(); voteIt++)
86  {
87  currentVotedPose = *voteIt;
88  //Prevent that fitting takes place multiple times for the same object when using the same originForFitting.
89  if ((sourcesWithFittingVotes.find(currentVotedPose->source) != sourcesWithFittingVotes.end()))
90  continue;
91 
92  //Reject all votes whose deviation form originForFitting exceed given thresholds. They cannot be regarded as supporting originForFitting.
93  if (mRater->isVoteSupportingReference(currentVotedPose, originPose, ratingCache))
94  //Count it as a supporting vote for origin for fitting
95  fittingVoteCounter++;
96  }
97 
98  return fittingVoteCounter;
99 
100  }
101 
102  //For a given type and id combination: Calculate all parameters required for summarizedFittingVotes
103  void countSupportingOriginForFittingVotes(VotedPosePtrs votes, unsigned int& fittingVoteCounter, double& bestWeight, VotedPosePtr& bestVotedPose)
104  {
105 
106  VotedPosePtr currentVotedPose;
107  double newWeight;
108  fittingVoteCounter = 0;
109  bestWeight = -mVotingSpaceInEval->epsilon;
110 
111  //Go through all votes for current type and id combination.
112  for (VotedPosePtrs::iterator voteIt = votes.begin(); voteIt != votes.end(); voteIt++)
113  {
114  currentVotedPose = *voteIt;
115  //Prevent that fitting takes place multiple times for the same object when using the same originForFitting.
116  if ((sourcesWithFittingVotes.find(currentVotedPose->source) != sourcesWithFittingVotes.end()))
117  continue;
118 
119  //Reject all votes whose deviation from originForFitting exceed given thresholds. They cannot be regarded as supporting originForFitting.
120  if (mRater->isVoteSupportingReference(currentVotedPose, originPose, ratingCache))
121  {
122  //Count it as a supporting vote for origin for fitting
123  fittingVoteCounter++;
124  //If we already found a perfectly rated VotedPose for the current type and id, we do not need to rate the rest.
125  if(bestWeight >= currentVotedPose->weight - VotingSpace::epsilon)
126  continue;
127 
128  newWeight = mRater->rateAtBackProjectionLevel(currentVotedPose, ratingCache);
129  if(newWeight > bestWeight)
130  {
131  bestVotedPose = currentVotedPose;
132  bestWeight = newWeight;
133  }
134  }
135  }
136  }
137 
138  };
139 
140  typedef boost::shared_ptr<VotingResultCalculator> VotingResultCalculatorPtr;
141 
142 }
143 
144 
bool computeVotingResult(VotingResultPtr &result, TypeToInnerMap votedReferencePoses)
void searchFittingVotes(TypeToInnerMap votes)
void countSupportingOriginForFittingVotes(VotedPosePtrs votes, unsigned int &fittingVoteCounter, double &bestWeight, VotedPosePtr &bestVotedPose)
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
std::vector< VotedPosePtr > VotedPosePtrs
Definition: typedef.hpp:59
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)
boost::shared_ptr< Pose > PosePtr
Definition: Pose.hpp:79
boost::shared_ptr< VotingResultCalculator > VotingResultCalculatorPtr
std::set< ObjectPtr > sourcesWithFittingVotes
std::vector< SummarizedVotedPosePtr > SummarizedVotedPosePtrs
Definition: typedef.hpp:75
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.


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