Program Listing for File matching-problem.h

Return to documentation for file (aslam_cv2/aslam_cv_matcher/include/aslam/matcher/matching-problem.h)

#ifndef ASLAM_CV_MATCHING_PROBLEM_H_
#define ASLAM_CV_MATCHING_PROBLEM_H_


#include <vector>

#include <aslam/common/macros.h>
#include <aslam/common/memory.h>
#include <glog/logging.h>

namespace aslam {

class MatchingProblem {
public:
  struct Candidate {
    int index_apple;
    int index_banana;
    double score;
    int priority;

    Candidate() : index_apple(-1), index_banana(-1), score(0.0), priority(-1) {}
    Candidate(int _index_apple, int _index_banana, double _score, int _priority) :
      index_apple(_index_apple), index_banana(_index_banana), score(_score), priority(_priority) {}

    bool operator<(const Candidate& other) const {
      return (this->priority < other.priority) ||
          ((this->priority == other.priority) && (this->score < other.score));
    }
    bool operator>(const Candidate& other) const {
      return (this->priority > other.priority) ||
          ((this->priority == other.priority) && (this->score > other.score));
    }

    bool operator==(const Candidate& other) const {
      return (this->index_apple == other.index_apple) &&
             (this->score == other.score) &&
             (this->priority == other.priority);
    }
  };

  typedef Aligned<std::vector, Candidate> Candidates;
  typedef Aligned<std::vector, Candidates> CandidatesList;

  ASLAM_POINTER_TYPEDEFS(MatchingProblem);
  ASLAM_DISALLOW_EVIL_CONSTRUCTORS(MatchingProblem);

  MatchingProblem() = default;
  virtual ~MatchingProblem() = default;

  virtual size_t numApples() const = 0;
  virtual size_t numBananas() const = 0;

  virtual inline void getCandidates(CandidatesList* candidates_for_bananas) {
    CHECK_NOTNULL(candidates_for_bananas)->clear();
    const size_t num_bananas = numBananas();
    candidates_for_bananas->resize(num_bananas);
    for (size_t banana_idx = 0u; banana_idx < num_bananas; ++banana_idx) {
      getAppleCandidatesForBanana(
          banana_idx, &(*candidates_for_bananas)[banana_idx]);
    }
  }

  virtual void getAppleCandidatesForBanana(int /*banana_index*/, Candidates* /*candidates*/) {
    LOG(FATAL) << "Not implemented.";
  }

  virtual bool doSetup() = 0;

  CandidatesList all_tested_pairs_;
};
}  // namespace aslam
#endif //ASLAM_CV_MATCHING_PROBLEM_H_