Loading...
Searching...
No Matches
MultiSampleConsensusProblem.hpp
Go to the documentation of this file.
/******************************************************************************
* Authors: Laurent Kneip & Paul Furgale *
* Contact: kneip.laurent@gmail.com *
* License: Copyright (c) 2013 Laurent Kneip, ANU. All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* * Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* * Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* * Neither the name of ANU nor the names of its contributors may be *
* used to endorse or promote products derived from this software without *
* specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"*
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
* ARE DISCLAIMED. IN NO EVENT SHALL ANU OR THE CONTRIBUTORS BE LIABLE *
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
* SUCH DAMAGE. *
******************************************************************************/
//Note: has been derived from ROS
#ifndef OPENGV_SAC_MULTISAMPLECONSENSUSPROBLEM_HPP_
#define OPENGV_SAC_MULTISAMPLECONSENSUSPROBLEM_HPP_
#include <stdlib.h>
#include <stdio.h>
#include <memory>
#include <functional>
#include <random>
#include <ctime>
namespace opengv
{
namespace sac
{
template<typename MODEL_T>
class MultiSampleConsensusProblem
{
public:
typedef MODEL_T model_t;
MultiSampleConsensusProblem( bool randomSeed = true );
virtual ~MultiSampleConsensusProblem();
virtual void getSamples(
int &iterations,
std::vector< std::vector<int> > &samples );
virtual bool isSampleGood(
const std::vector< std::vector<int> > & sample ) const;
std::shared_ptr< std::vector< std::vector<int> > > getIndices() const;
void drawIndexSample( std::vector< std::vector<int> > & sample );
virtual std::vector<int> getSampleSizes() const = 0;
virtual bool computeModelCoefficients(
const std::vector< std::vector<int> > & indices,
model_t & outModel) const = 0;
virtual void optimizeModelCoefficients(
const std::vector< std::vector<int> > & inliers,
const model_t & model_coefficients,
model_t & optimized_coefficients ) = 0;
virtual void getSelectedDistancesToModel(
const model_t & model,
const std::vector< std::vector<int> > & indices,
std::vector< std::vector<double> > & scores ) const = 0;
virtual void getDistancesToModel(
const model_t & model_coefficients,
std::vector< std::vector<double> > &distances );
virtual void selectWithinDistance(
const model_t &model_coefficients,
const double threshold,
std::vector< std::vector<int> > &inliers );
virtual int countWithinDistance(
const model_t &model_coefficients,
const double threshold);
void setIndices(const std::vector< std::vector<int> > & indices);
void setUniformIndices(std::vector<int> N);
int rnd();
int max_sample_checks_;
std::shared_ptr< std::vector< std::vector<int> > > indices_;
std::vector< std::vector<int> > shuffled_indices_;
std::mt19937 rng_alg_;
std::shared_ptr< std::uniform_int_distribution<> > rng_dist_;
std::shared_ptr< std::function<int()> > rng_gen_;
};
} // namespace sac
} // namespace opengv
#include "implementation/MultiSampleConsensusProblem.hpp"
#endif /* OPENGV_SAC_MULTISAMPLECONSENSUS_PROBLEM_HPP_ */
opengv::sac::MultiSampleConsensusProblem::optimizeModelCoefficients
virtual void optimizeModelCoefficients(const std::vector< std::vector< int > > &inliers, const model_t &model_coefficients, model_t &optimized_coefficients)=0
Refine the model coefficients over a given set (inliers). Needs implementation in the child-class.
opengv::sac::MultiSampleConsensusProblem::setIndices
void setIndices(const std::vector< std::vector< int > > &indices)
Set the indices_ variable (see member-description).
opengv::sac::MultiSampleConsensusProblem::selectWithinDistance
virtual void selectWithinDistance(const model_t &model_coefficients, const double threshold, std::vector< std::vector< int > > &inliers)
Select all the inlier samples whith respect to given model coefficients.
opengv::sac::MultiSampleConsensusProblem::rng_dist_
std::shared_ptr< std::uniform_int_distribution<> > rng_dist_
std-based random number generator distribution.
Definition MultiSampleConsensusProblem.hpp:233
opengv::sac::MultiSampleConsensusProblem::max_sample_checks_
int max_sample_checks_
Definition MultiSampleConsensusProblem.hpp:218
opengv::sac::MultiSampleConsensusProblem::isSampleGood
virtual bool isSampleGood(const std::vector< std::vector< int > > &sample) const
Check if a set of samples for model generation is degenerate.
opengv::sac::MultiSampleConsensusProblem::MultiSampleConsensusProblem
MultiSampleConsensusProblem(bool randomSeed=true)
Contructor.
opengv::sac::MultiSampleConsensusProblem::setUniformIndices
void setUniformIndices(std::vector< int > N)
Use this method if you want to use all samples.
opengv::sac::MultiSampleConsensusProblem::getSelectedDistancesToModel
virtual void getSelectedDistancesToModel(const model_t &model, const std::vector< std::vector< int > > &indices, std::vector< std::vector< double > > &scores) const =0
Compute the distances of all samples whith respect to given model coefficients. Needs implementation ...
opengv::sac::MultiSampleConsensusProblem::getSamples
virtual void getSamples(int &iterations, std::vector< std::vector< int > > &samples)
Get samples for hypothesis generation.
opengv::sac::MultiSampleConsensusProblem::getIndices
std::shared_ptr< std::vector< std::vector< int > > > getIndices() const
Get a pointer to the vector of multi-indices used.
opengv::sac::MultiSampleConsensusProblem::getSampleSizes
virtual std::vector< int > getSampleSizes() const =0
Get the number of samples needed for a hypothesis generation. Needs implementation in the child class...
opengv::sac::MultiSampleConsensusProblem::rng_alg_
std::mt19937 rng_alg_
std-based random number generator algorithm.
Definition MultiSampleConsensusProblem.hpp:230
opengv::sac::MultiSampleConsensusProblem::~MultiSampleConsensusProblem
virtual ~MultiSampleConsensusProblem()
Destructor.
opengv::sac::MultiSampleConsensusProblem::shuffled_indices_
std::vector< std::vector< int > > shuffled_indices_
Definition MultiSampleConsensusProblem.hpp:227
opengv::sac::MultiSampleConsensusProblem::drawIndexSample
void drawIndexSample(std::vector< std::vector< int > > &sample)
Sub-function for getting samples for hypothesis generation.
opengv::sac::MultiSampleConsensusProblem::indices_
std::shared_ptr< std::vector< std::vector< int > > > indices_
Definition MultiSampleConsensusProblem.hpp:224
opengv::sac::MultiSampleConsensusProblem::getDistancesToModel
virtual void getDistancesToModel(const model_t &model_coefficients, std::vector< std::vector< double > > &distances)
Compute the distances of all samples which respect to given model coefficients.
opengv::sac::MultiSampleConsensusProblem::countWithinDistance
virtual int countWithinDistance(const model_t &model_coefficients, const double threshold)
Count all the inlier samples whith respect to given model coefficients.
opengv::sac::MultiSampleConsensusProblem::model_t
MODEL_T model_t
Definition MultiSampleConsensusProblem.hpp:74
opengv::sac::MultiSampleConsensusProblem::computeModelCoefficients
virtual bool computeModelCoefficients(const std::vector< std::vector< int > > &indices, model_t &outModel) const =0
Compute a model from a set of samples. Needs implementation in the child-class.
opengv::sac::MultiSampleConsensusProblem::rnd
int rnd()
Get a random number.
opengv::sac::MultiSampleConsensusProblem::rng_gen_
std::shared_ptr< std::function< int()> > rng_gen_
std-based random number generator.
Definition MultiSampleConsensusProblem.hpp:236
opengv::sac
The namespace for the sample consensus methods.
Definition Lmeds.hpp:53
opengv
The namespace of this library.
Definition AbsoluteAdapterBase.hpp:48