Permalink
Browse files

fnc ptrs to std::functional (WIP)

  • Loading branch information...
jlblancoc committed Aug 23, 2017
1 parent 3443195 commit bc66956dcbd976f11f3f297c95015ddb1ec302e3
@@ -112,7 +112,8 @@ class BASE_IMPEXP CParticleFilter : public mrpt::utils::COutputLogger
const mrpt::utils::CConfigFileBase& source,
const std::string& section) override;
virtual void saveToConfigFile(
mrpt::utils::CConfigFileBase& target, const std::string& section) const override;
mrpt::utils::CConfigFileBase& target,
const std::string& section) const override;
/** A flag that indicates whether the CParticleFilterCapable object
* should perform adative sample size (default=false). */
@@ -14,6 +14,7 @@
#include <mrpt/math/num_jacobian.h>
#include <mrpt/utils/printf_vector.h>
#include <mrpt/math/ops_containers.h>
#include <functional>
namespace mrpt
{
@@ -55,15 +56,15 @@ class CLevenbergMarquardtTempl : public mrpt::utils::COutputLogger
* root error, for the given "x". The functor code must set the size of this
* vector.
*/
typedef void (*TFunctorEval)(
const VECTORTYPE& x, const USERPARAM& y, VECTORTYPE& out);
using TFunctorEval = std::function<void(
const VECTORTYPE& x, const USERPARAM& y, VECTORTYPE& out)>;
/** The type of an optional functor passed to \a execute to replace the
* Euclidean addition "x_new = x_old + x_incr" by any other operation.
*/
typedef void (*TFunctorIncrement)(
using TFunctorIncrement = std::function<void(
VECTORTYPE& x_new, const VECTORTYPE& x_old, const VECTORTYPE& x_incr,
const USERPARAM& user_param);
const USERPARAM& user_param)>;
struct TResultInfo
{
@@ -15,6 +15,7 @@
#include <mrpt/poses/CPosePDF.h>
#include <mrpt/poses/CPose3DQuatPDF.h>
#include <mrpt/poses/CPose3DPDF.h>
#include <functional>
namespace mrpt
{
@@ -142,7 +143,8 @@ template <class VECTORLIKE, class VECTORLIKE2, class VECTORLIKE3,
class MATRIXLIKE, class USERPARAM>
inline void jacob_numeric_estimate(
const VECTORLIKE& x,
void (*functor)(const VECTORLIKE& x, const USERPARAM& y, VECTORLIKE3& out),
std::function<
void(const VECTORLIKE& x, const USERPARAM& y, VECTORLIKE3& out)>,
const VECTORLIKE2& increments, const USERPARAM& userParam,
MATRIXLIKE& out_Jacobian)
{
@@ -151,9 +153,6 @@ inline void jacob_numeric_estimate(
}
} // End of jacobians namespace
} // End of MATH namespace
} // End of namespace
#endif
@@ -9,6 +9,7 @@
#pragma once
#include <mrpt/utils/core_defs.h>
#include <functional>
namespace mrpt
{
@@ -29,7 +30,8 @@ template <class VECTORLIKE, class VECTORLIKE2, class VECTORLIKE3,
class MATRIXLIKE, class USERPARAM>
void estimateJacobian(
const VECTORLIKE& x,
void (*functor)(const VECTORLIKE& x, const USERPARAM& y, VECTORLIKE3& out),
std::function<
void(const VECTORLIKE& x, const USERPARAM& y, VECTORLIKE3& out)>,
const VECTORLIKE2& increments, const USERPARAM& userParam,
MATRIXLIKE& out_Jacobian)
{
@@ -12,6 +12,7 @@
#include <mrpt/utils/COutputLogger.h>
#include <mrpt/math/CMatrixD.h>
#include <set>
#include <functional>
namespace mrpt
{
@@ -33,24 +34,24 @@ class BASE_IMPEXP RANSAC_Template : public mrpt::utils::COutputLogger
RANSAC_Template() : mrpt::utils::COutputLogger("RANSAC_Template") {}
/** The type of the function passed to mrpt::math::ransac - See the
* documentation for that method for more info. */
typedef void (*TRansacFitFunctor)(
using TRansacFitFunctor = std::function<void(
const CMatrixTemplateNumeric<NUMTYPE>& allData,
const mrpt::vector_size_t& useIndices,
std::vector<CMatrixTemplateNumeric<NUMTYPE>>& fitModels);
std::vector<CMatrixTemplateNumeric<NUMTYPE>>& fitModels)>;
/** The type of the function passed to mrpt::math::ransac - See the
* documentation for that method for more info. */
typedef void (*TRansacDistanceFunctor)(
using TRansacDistanceFunctor = std::function<void(
const CMatrixTemplateNumeric<NUMTYPE>& allData,
const std::vector<CMatrixTemplateNumeric<NUMTYPE>>& testModels,
const NUMTYPE distanceThreshold, unsigned int& out_bestModelIndex,
mrpt::vector_size_t& out_inlierIndices);
mrpt::vector_size_t& out_inlierIndices)>;
/** The type of the function passed to mrpt::math::ransac - See the
* documentation for that method for more info. */
typedef bool (*TRansacDegenerateFunctor)(
using TRansacDegenerateFunctor = std::function<bool(
const CMatrixTemplateNumeric<NUMTYPE>& allData,
const mrpt::vector_size_t& useIndices);
const mrpt::vector_size_t& useIndices)>;
/** An implementation of the RANSAC algorithm for robust fitting of models
* to data.
@@ -66,8 +67,10 @@ class BASE_IMPEXP RANSAC_Template : public mrpt::utils::COutputLogger
* COutputLogger settings.
*/
bool execute(
const CMatrixTemplateNumeric<NUMTYPE>& data, TRansacFitFunctor fit_func,
TRansacDistanceFunctor dist_func, TRansacDegenerateFunctor degen_func,
const CMatrixTemplateNumeric<NUMTYPE>& data,
const TRansacFitFunctor& fit_func,
const TRansacDistanceFunctor& dist_func,
const TRansacDegenerateFunctor& degen_func,
const double distanceThreshold,
const unsigned int minimumSizeSamplesToFit,
mrpt::vector_size_t& out_best_inliers,
@@ -17,6 +17,7 @@
#include <mrpt/math/jacobians.h>
#include <mrpt/math/data_utils.h>
#include <mrpt/random.h>
#include <functional>
namespace mrpt
{
@@ -46,8 +47,9 @@ template <class VECTORLIKE1, class MATLIKE1, class USERPARAM, class VECTORLIKE2,
class VECTORLIKE3, class MATLIKE2>
void transform_gaussian_unscented(
const VECTORLIKE1& x_mean, const MATLIKE1& x_cov,
void (*functor)(
const VECTORLIKE1& x, const USERPARAM& fixed_param, VECTORLIKE3& y),
std::function<void(
const VECTORLIKE1& x, const USERPARAM& fixed_param, VECTORLIKE3& y)>
functor,
const USERPARAM& fixed_param, VECTORLIKE2& y_mean, MATLIKE2& y_cov,
const bool* elem_do_wrap2pi = nullptr, const double alpha = 1e-3,
const double K = 0, const double beta = 2.0)
@@ -114,8 +116,9 @@ template <class VECTORLIKE1, class MATLIKE1, class USERPARAM, class VECTORLIKE2,
class VECTORLIKE3, class MATLIKE2>
void transform_gaussian_montecarlo(
const VECTORLIKE1& x_mean, const MATLIKE1& x_cov,
void (*functor)(
const VECTORLIKE1& x, const USERPARAM& fixed_param, VECTORLIKE3& y),
std::function<void(
const VECTORLIKE1& x, const USERPARAM& fixed_param, VECTORLIKE3& y)>
functor,
const USERPARAM& fixed_param, VECTORLIKE2& y_mean, MATLIKE2& y_cov,
const size_t num_samples = 1000,
typename mrpt::aligned_containers<VECTORLIKE3>::vector_t* out_samples_y =
@@ -152,8 +155,9 @@ template <class VECTORLIKE1, class MATLIKE1, class USERPARAM, class VECTORLIKE2,
class VECTORLIKE3, class MATLIKE2>
void transform_gaussian_linear(
const VECTORLIKE1& x_mean, const MATLIKE1& x_cov,
void (*functor)(
const VECTORLIKE1& x, const USERPARAM& fixed_param, VECTORLIKE3& y),
std::function<void(
const VECTORLIKE1& x, const USERPARAM& fixed_param, VECTORLIKE3& y)>
functor,
const USERPARAM& fixed_param, VECTORLIKE2& y_mean, MATLIKE2& y_cov,
const VECTORLIKE1& x_increments)
{
@@ -76,14 +76,16 @@ class BASE_IMPEXP CConfigFileBase
/** Checks if a given section exists (name is case insensitive) */
bool sectionExists(const std::string& section_name) const;
template <typename enum_t, class = typename std::enable_if<std::is_enum<enum_t>::value,enum_t>::value>
template <typename enum_t, class = typename std::enable_if<
std::is_enum<enum_t>::value, enum_t>::value>
void write(
const std::string& section, const std::string& name, enum_t value,
const int name_padding_width = -1, const int value_padding_width = -1,
const std::string& comment = std::string())
{
this->write(section, name, mrpt::utils::TEnumType<enum_t>::value2name(value),
name_padding_width, value_padding_width, comment);
this->write(
section, name, mrpt::utils::TEnumType<enum_t>::value2name(value),
name_padding_width, value_padding_width, comment);
}
/** @name Save a configuration parameter. Optionally pads with spaces up to
* the desired width in number of characters (-1: no fill), and add a final
@@ -116,19 +116,39 @@ CParticleFilter::TParticleFilterOptions::TParticleFilterOptions()
}
void CParticleFilter::TParticleFilterOptions::saveToConfigFile(
mrpt::utils::CConfigFileBase& c, const std::string& s) const
mrpt::utils::CConfigFileBase& c, const std::string& s) const
{
MRPT_SAVE_CONFIG_VAR_COMMENT(PF_algorithm,"The PF algorithm to use. See TParticleFilterAlgorithm");
MRPT_SAVE_CONFIG_VAR_COMMENT(resamplingMethod,"The resampling algorithm to use. See TParticleResamplingAlgorithm");
MRPT_SAVE_CONFIG_VAR_COMMENT(adaptiveSampleSize,"A flag that indicates whether the CParticleFilterCapable object should perform adative sample size (default=false)");
MRPT_SAVE_CONFIG_VAR_COMMENT(BETA,"The resampling of particles will be performed when ESS (in range [0,1]) < BETA (default is 0.5)");
MRPT_SAVE_CONFIG_VAR_COMMENT(sampleSize,"The initial number of particles in the filter (it can change only if adaptiveSampleSize=true) (default=1)");
MRPT_SAVE_CONFIG_VAR_COMMENT(pfAuxFilterOptimal_MaximumSearchSamples,"See Doxygen docs");
MRPT_SAVE_CONFIG_VAR_COMMENT(powFactor,"An optional step to smooth dramatic changes in the observation model to affect the variance of the particle weights (default=1)");
MRPT_SAVE_CONFIG_VAR_COMMENT(max_loglikelihood_dyn_range, "Only for PF_algorithm=pfAuxiliaryPFOptimal");
MRPT_SAVE_CONFIG_VAR_COMMENT(pfAuxFilterStandard_FirstStageWeightsMonteCarlo,"Only for PF_algorithm==pfAuxiliaryPFStandard");
MRPT_SAVE_CONFIG_VAR_COMMENT(pfAuxFilterOptimal_MLE,"See doxygen docs.");
MRPT_SAVE_CONFIG_VAR_COMMENT(
PF_algorithm, "The PF algorithm to use. See TParticleFilterAlgorithm");
MRPT_SAVE_CONFIG_VAR_COMMENT(
resamplingMethod,
"The resampling algorithm to use. See TParticleResamplingAlgorithm");
MRPT_SAVE_CONFIG_VAR_COMMENT(
adaptiveSampleSize,
"A flag that indicates whether the CParticleFilterCapable object "
"should perform adative sample size (default=false)");
MRPT_SAVE_CONFIG_VAR_COMMENT(
BETA,
"The resampling of particles will be performed when ESS (in range "
"[0,1]) < BETA (default is 0.5)");
MRPT_SAVE_CONFIG_VAR_COMMENT(
sampleSize,
"The initial number of particles in the filter (it can change only if "
"adaptiveSampleSize=true) (default=1)");
MRPT_SAVE_CONFIG_VAR_COMMENT(
pfAuxFilterOptimal_MaximumSearchSamples, "See Doxygen docs");
MRPT_SAVE_CONFIG_VAR_COMMENT(
powFactor,
"An optional step to smooth dramatic changes in the observation model "
"to affect the variance of the particle weights (default=1)");
MRPT_SAVE_CONFIG_VAR_COMMENT(
max_loglikelihood_dyn_range,
"Only for PF_algorithm=pfAuxiliaryPFOptimal");
MRPT_SAVE_CONFIG_VAR_COMMENT(
pfAuxFilterStandard_FirstStageWeightsMonteCarlo,
"Only for PF_algorithm==pfAuxiliaryPFStandard");
MRPT_SAVE_CONFIG_VAR_COMMENT(pfAuxFilterOptimal_MLE, "See doxygen docs.");
}
/*---------------------------------------------------------------
@@ -23,9 +23,10 @@ using namespace std;
---------------------------------------------------------------*/
template <typename NUMTYPE>
bool RANSAC_Template<NUMTYPE>::execute(
const CMatrixTemplateNumeric<NUMTYPE>& data, TRansacFitFunctor fit_func,
TRansacDistanceFunctor dist_func, TRansacDegenerateFunctor degen_func,
const double distanceThreshold, const unsigned int minimumSizeSamplesToFit,
const CMatrixTemplateNumeric<NUMTYPE>& data,
const TRansacFitFunctor& fit_func, const TRansacDistanceFunctor& dist_func,
const TRansacDegenerateFunctor& degen_func, const double distanceThreshold,
const unsigned int minimumSizeSamplesToFit,
mrpt::vector_size_t& out_best_inliers,
CMatrixTemplateNumeric<NUMTYPE>& out_best_model, const double p,
const size_t maxIter) const
@@ -138,8 +138,9 @@ void mrpt::math::ransac_detect_3D_planes(
math::RANSAC_Template<NUMTYPE> ransac;
ransac.setVerbosityLevel(mrpt::utils::LVL_INFO);
ransac.execute(
remainingPoints, ransac3Dplane_fit, ransac3Dplane_distance,
ransac3Dplane_degenerate, threshold,
remainingPoints, mrpt::math::ransac3Dplane_fit<NUMTYPE>,
mrpt::math::ransac3Dplane_distance<NUMTYPE>,
mrpt::math::ransac3Dplane_degenerate<NUMTYPE>, threshold,
3, // Minimum set of points
this_best_inliers, this_best_model,
0.999 // Prob. of good result
@@ -19,6 +19,7 @@
#include <vector>
#include <utility>
#include <exception>
#include <functional>
namespace mrpt
{
@@ -159,6 +160,13 @@ class CDijkstra
/** A list of edges used to describe a path on the graph */
typedef std::list<TPairNodeIDs> edge_list_t;
using functor_edge_weight_t = std::function<double(
const graph_t& graph, const TNodeID id_from, const TNodeID id_to,
const edge_t& edge)>;
using functor_on_progress_t =
std::function<void(const graph_t& graph, size_t visitedCount)>;
/** @} */
/** Constructor which takes the input graph and executes the entire
@@ -180,11 +188,8 @@ class CDijkstra
*/
CDijkstra(
const graph_t& graph, const TNodeID source_node_ID,
double (*functor_edge_weight)(
const graph_t& graph, const TNodeID id_from, const TNodeID id_to,
const edge_t& edge) = nullptr,
void (*functor_on_progress)(const graph_t& graph, size_t visitedCount) =
nullptr)
functor_edge_weight_t functor_edge_weight = functor_edge_weight_t,
functor_on_progress_t functor_on_progress = functor_on_progress_t())
: m_cached_graph(graph), m_source_node_ID(source_node_ID)
{
/*
@@ -82,7 +82,7 @@ void optimize_graph_spa_levmarq(
const mrpt::utils::TParametersDouble& extra_params =
mrpt::utils::TParametersDouble(),
typename graphslam_traits<GRAPH_T>::TFunctorFeedback functor_feedback =
nullptr)
typename graphslam_traits<GRAPH_T>::TFunctorFeedback)
{
using namespace mrpt;
using namespace mrpt::poses;
@@ -11,6 +11,7 @@
#include <mrpt/graphs/CNetworkOfPoses.h>
#include <mrpt/poses/SE_traits.h>
#include <functional>
namespace mrpt
{
@@ -58,9 +59,9 @@ struct graphslam_traits
typename gst::graph_t::constraint_t::type_value *P1, *P2;
};
typedef void (*TFunctorFeedback)(
using TFunctorFeedback = std::function<void(
const GRAPH_T& graph, const size_t iter, const size_t max_iter,
const double cur_sq_error);
const double cur_sq_error)>;
};
/** Output information for mrpt::graphslam::optimize_graph_spa_levmarq() */
@@ -31,6 +31,7 @@
#include <mrpt/gui/CDisplayWindow.h>
#include <memory> // unique_ptr
#include <functional>
namespace mrpt
{
@@ -402,8 +403,8 @@ class HWDRIVERS_IMPEXP CCameraSensor : public mrpt::utils::COutputLogger,
};
/** Functor type */
typedef void (*TPreSaveUserHook)(
const mrpt::obs::CObservation::Ptr& obs, void* user_ptr);
using TPreSaveUserHook = std::function<void(
const mrpt::obs::CObservation::Ptr& obs, void* user_ptr)>;
/** Provides a "hook" for user-code to be run BEFORE an image is going to be
* saved to disk if external storage is enabled (e.g. to rectify images,
@@ -14,6 +14,7 @@
#include <mrpt/obs/obs_frwds.h>
#include <map>
#include <string>
#include <functional>
namespace mrpt
{
@@ -22,9 +23,10 @@ namespace maps
struct TMetricMapInitializer;
namespace internal
{
typedef mrpt::maps::TMetricMapInitializer* (*MapDefCtorFunctor)(void);
typedef mrpt::maps::CMetricMap* (*MapCtorFromDefFunctor)(
const mrpt::maps::TMetricMapInitializer&);
using MapDefCtorFunctor =
std::function<mrpt::maps::TMetricMapInitializer*(void)>;
using MapCtorFromDefFunctor = std::function<mrpt::maps::CMetricMap*(
const mrpt::maps::TMetricMapInitializer&)>;
/** Class factory & registry for map classes. Used from
* mrpt::maps::TMetricMapInitializer */
@@ -29,7 +29,7 @@ struct TFEST_IMPEXP TPotentialMatch
size_t idx_this, idx_other;
};
typedef std::function<bool(const TPotentialMatch&)> TFunctorCheckPotentialMatch;
using TFunctorCheckPotentialMatch = std::function<bool(const TPotentialMatch&)>;
/** @} */ // end of grouping
}
Oops, something went wrong.

0 comments on commit bc66956

Please sign in to comment.