39#ifndef vpPoseFeatures_HH
40#define vpPoseFeatures_HH
42#include <visp3/core/vpConfig.h>
44#if defined(VISP_HAVE_MODULE_VISUAL_FEATURES) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
46#include <visp3/core/vpCircle.h>
47#include <visp3/core/vpCylinder.h>
48#include <visp3/core/vpDebug.h>
49#include <visp3/core/vpException.h>
50#include <visp3/core/vpExponentialMap.h>
51#include <visp3/core/vpForwardProjection.h>
52#include <visp3/core/vpLine.h>
53#include <visp3/core/vpPoint.h>
54#include <visp3/core/vpRobust.h>
55#include <visp3/core/vpSphere.h>
56#include <visp3/visual_features/vpBasicFeature.h>
57#include <visp3/visual_features/vpFeatureBuilder.h>
58#include <visp3/visual_features/vpFeatureEllipse.h>
59#include <visp3/visual_features/vpFeaturePoint.h>
67#ifndef DOXYGEN_SHOULD_SKIP_THIS
71template <
unsigned int N>
struct vpDesiredFeatureBuilderWithTuple
73 template <
typename featureType,
typename RetType,
typename... ArgsF,
typename... ArgsT,
typename... Args>
74 static void buildDesiredFeatureWithTuple(featureType &feature, RetType(*f)(ArgsF...),
const std::tuple<ArgsT...> &t,
77 vpDesiredFeatureBuilderWithTuple<N - 1>::buildDesiredFeatureWithTuple(feature, f, t, std::get<N - 1>(t),
args...);
81template <>
struct vpDesiredFeatureBuilderWithTuple<0>
83 template <
typename featureType,
typename RetType,
typename... ArgsF,
typename... ArgsT,
typename... Args>
84 static void buildDesiredFeatureWithTuple(featureType & , RetType(*f)(ArgsF...),
85 const std::tuple<ArgsT...> & , Args &&...args)
91template <>
struct vpDesiredFeatureBuilderWithTuple<1>
93 template <
typename featureType,
typename RetType,
typename... ArgsF,
typename... ArgsT,
typename... Args>
94 static void buildDesiredFeatureWithTuple(featureType &feature, RetType(*f)(ArgsF...),
const std::tuple<ArgsT...> &t,
97 vpDesiredFeatureBuilderWithTuple<0>::buildDesiredFeatureWithTuple(feature, f, t, feature,
args...);
101template <
typename featureType,
typename RetType,
typename... Args,
typename... ArgsFunc>
102void buildDesiredFeatureWithTuple(featureType &feature, RetType(*f)(ArgsFunc...), std::tuple<Args...>
const &t)
104 vpDesiredFeatureBuilderWithTuple<
sizeof...(Args)>::buildDesiredFeatureWithTuple(feature, f, t);
112template <
unsigned int N>
struct vpDesiredFeatureBuilderObjectWithTuple
114 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsF,
typename... ArgsT,
116 static void buildDesiredFeatureObjectWithTuple(objType *obj, featureType &feature, RetType(objType:: *f)(ArgsF...),
117 const std::tuple<ArgsT...> &t, Args &&...args)
119 vpDesiredFeatureBuilderObjectWithTuple<N - 1>::buildDesiredFeatureObjectWithTuple(obj, feature, f, t,
120 std::get<N - 1>(t),
args...);
124template <>
struct vpDesiredFeatureBuilderObjectWithTuple<0>
126 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsF,
typename... ArgsT,
128 static void buildDesiredFeatureObjectWithTuple(objType *obj, featureType & ,
129 RetType(objType:: *f)(ArgsF...),
const std::tuple<ArgsT...> & ,
136template <>
struct vpDesiredFeatureBuilderObjectWithTuple<1>
138 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsF,
typename... ArgsT,
140 static void buildDesiredFeatureObjectWithTuple(objType *obj, featureType &feature, RetType(objType:: *f)(ArgsF...),
141 const std::tuple<ArgsT...> &t, Args &&...args)
143 vpDesiredFeatureBuilderObjectWithTuple<0>::buildDesiredFeatureObjectWithTuple(obj, feature, f, t, feature,
args...);
147template <
typename objType,
typename featureType,
typename RetType,
typename... Args,
typename... ArgsFunc>
148void buildDesiredFeatureObjectWithTuple(objType *obj, featureType &feature, RetType(objType:: *f)(ArgsFunc...),
149 std::tuple<Args...>
const &t)
151 vpDesiredFeatureBuilderObjectWithTuple<
sizeof...(Args)>::buildDesiredFeatureObjectWithTuple(obj, feature, f, t);
160template <
unsigned int N>
struct vpCurrentFeatureBuilderWithTuple
162 template <
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
164 static void buildCurrentFeatureWithTuple(featureType &feature,
const vpHomogeneousMatrix &cMo, RetType(*f)(ArgsF...),
165 std::tuple<ArgsTuple...> &t, ArgsDecomposed &&...args)
167 auto proj = std::get<N - 1>(
t);
169 vpCurrentFeatureBuilderWithTuple<N - 1>::buildCurrentFeatureWithTuple(feature, cMo, f, t, proj,
args...);
173template <>
struct vpCurrentFeatureBuilderWithTuple<0>
175 template <
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
177 static void buildCurrentFeatureWithTuple(featureType & ,
const vpHomogeneousMatrix & ,
178 RetType(*f)(ArgsF...), std::tuple<ArgsTuple...> &, ArgsDecomposed &&...args)
184template <>
struct vpCurrentFeatureBuilderWithTuple<1>
186 template <
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
188 static void buildCurrentFeatureWithTuple(featureType &feature,
const vpHomogeneousMatrix &cMo, RetType(*f)(ArgsF...),
189 std::tuple<ArgsTuple...> &t, ArgsDecomposed &&...args)
191 vpCurrentFeatureBuilderWithTuple<0>::buildCurrentFeatureWithTuple(feature, cMo, f, t, feature,
args...);
195template <
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsFunc>
196void buildCurrentFeatureWithTuple(featureType &feature,
const vpHomogeneousMatrix &cMo, RetType(*f)(ArgsFunc...),
197 std::tuple<ArgsTuple...> &t)
199 vpCurrentFeatureBuilderWithTuple<
sizeof...(ArgsTuple)>::buildCurrentFeatureWithTuple(feature, cMo, f, t);
209template <
unsigned int N>
struct vpCurrentFeatureBuilderObjectWithTuple
211 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
213 static void buildCurrentFeatureObjectWithTuple(objType *obj, featureType &feature,
const vpHomogeneousMatrix &cMo,
214 RetType(objType:: *f)(ArgsF...), std::tuple<ArgsTuple...> &t,
215 ArgsDecomposed &&...args)
217 auto proj = std::get<N - 1>(
t);
219 vpCurrentFeatureBuilderObjectWithTuple<N - 1>::buildCurrentFeatureObjectWithTuple(obj, feature, cMo, f, t, proj,
224template <>
struct vpCurrentFeatureBuilderObjectWithTuple<0>
226 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
228 static void buildCurrentFeatureObjectWithTuple(objType *obj, featureType & ,
229 const vpHomogeneousMatrix & , RetType(objType:: *f)(ArgsF...),
230 std::tuple<ArgsTuple...> &, ArgsDecomposed &&...args)
236template <>
struct vpCurrentFeatureBuilderObjectWithTuple<1>
238 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
240 static void buildCurrentFeatureObjectWithTuple(objType *obj, featureType &feature,
const vpHomogeneousMatrix &cMo,
241 RetType(objType:: *f)(ArgsF...), std::tuple<ArgsTuple...> &t,
242 ArgsDecomposed &&...args)
244 vpCurrentFeatureBuilderObjectWithTuple<0>::buildCurrentFeatureObjectWithTuple(obj, feature, cMo, f, t, feature,
249template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsFunc>
250void buildCurrentFeatureObjectWithTuple(objType *obj, featureType &feature,
const vpHomogeneousMatrix &cMo,
251 RetType(objType:: *f)(ArgsFunc...), std::tuple<ArgsTuple...> &t)
253 vpCurrentFeatureBuilderObjectWithTuple<
sizeof...(ArgsTuple)>::buildCurrentFeatureObjectWithTuple(obj, feature, cMo, f,
267class VISP_EXPORT vpPoseSpecificFeature
270 vpPoseSpecificFeature() { }
271 virtual ~vpPoseSpecificFeature() { }
273 virtual vpColVector
error() = 0;
274 virtual vpMatrix currentInteraction() = 0;
275 virtual void createDesired() = 0;
276 virtual void createCurrent(
const vpHomogeneousMatrix &cMo) = 0;
289template <
typename featureType,
typename RetType,
typename... Args>
290class vpPoseSpecificFeatureTemplate :
public vpPoseSpecificFeature
293 featureType m_desiredFeature;
294 featureType m_currentFeature;
295 std::tuple<Args...> *m_tuple;
296 RetType(*func_ptr)(Args...);
299 vpPoseSpecificFeatureTemplate(RetType(*f_ptr)(Args...), Args &&...args)
302 m_tuple =
new std::tuple<Args...>(
args...);
304 virtual ~vpPoseSpecificFeatureTemplate() VP_OVERRIDE
309 virtual void createDesired() VP_OVERRIDE
311 buildDesiredFeatureWithTuple(m_desiredFeature, func_ptr, *m_tuple);
314 virtual vpColVector
error() VP_OVERRIDE
318 return m_currentFeature.error(m_desiredFeature);
321 virtual vpMatrix currentInteraction() VP_OVERRIDE
323 return m_currentFeature.interaction();
326 virtual void createCurrent(
const vpHomogeneousMatrix &cMo) VP_OVERRIDE
328 buildCurrentFeatureWithTuple(m_currentFeature, cMo, func_ptr, *m_tuple);
343template <
typename ObjectType,
typename featureType,
typename RetType,
typename... Args>
344class vpPoseSpecificFeatureTemplateObject :
public vpPoseSpecificFeature
347 featureType m_desiredFeature;
348 featureType m_currentFeature;
349 std::tuple<Args...> *m_tuple;
350 RetType(ObjectType:: *func_ptr)(Args...);
354 vpPoseSpecificFeatureTemplateObject(ObjectType *o, RetType(ObjectType:: *f_ptr)(Args...), Args &&...args)
357 m_tuple =
new std::tuple<Args...>(
args...);
361 virtual ~vpPoseSpecificFeatureTemplateObject() VP_OVERRIDE
366 virtual void createDesired() VP_OVERRIDE
368 buildDesiredFeatureObjectWithTuple(m_obj, m_desiredFeature, func_ptr, *m_tuple);
371 virtual vpColVector
error() VP_OVERRIDE
373 return m_currentFeature.error(m_desiredFeature);
376 virtual vpMatrix currentInteraction() VP_OVERRIDE
378 return m_currentFeature.interaction();
381 virtual void createCurrent(
const vpHomogeneousMatrix &cMo) VP_OVERRIDE
383 buildCurrentFeatureObjectWithTuple(m_obj, m_currentFeature, cMo, func_ptr, *m_tuple);
408 } vpPoseFeaturesMethodType;
420#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
504 template <
typename RetType,
typename... ArgsFunc,
typename... Args>
510 template <
typename ObjType,
typename RetType,
typename... ArgsFunc,
typename... Args>
511 void addSpecificFeature(ObjType *obj, RetType(ObjType:: *fct_ptr)(ArgsFunc...), Args &&...args);
542 if (!m_computeCovariance)
543 vpTRACE(
"Warning : The covariance matrix has not been computed. See "
544 "setCovarianceComputation() to do it.");
546 return m_covarianceMatrix;
595#ifndef DOXYGEN_SHOULD_SKIP_THIS
596 template <
typename FeatureType,
typename FirstParamType>
struct vpDuo
598 FeatureType *desiredFeature;
599 FirstParamType firstParam;
600 vpDuo() : desiredFeature(nullptr), firstParam() { }
603 template <
typename FeatureType,
typename FirstParamType,
typename SecondParamType>
struct vpTrio
605 FeatureType *desiredFeature;
606 FirstParamType firstParam;
607 SecondParamType secondParam;
609 vpTrio() : desiredFeature(nullptr), firstParam(), secondParam() { }
613 unsigned int m_maxSize;
614 unsigned int m_totalSize;
615 unsigned int m_vvsIterMax;
620 bool m_computeCovariance;
621 vpMatrix m_covarianceMatrix;
624 std::vector<vpDuo<vpFeaturePoint, vpPoint> > m_featurePoint_Point_list;
626 std::vector<vpDuo<vpFeaturePoint3D, vpPoint> > m_featurePoint3D_Point_list;
628 std::vector<vpDuo<vpFeatureVanishingPoint, vpPoint> > m_featureVanishingPoint_Point_list;
629 std::vector<vpTrio<vpFeatureVanishingPoint, vpLine, vpLine> > m_featureVanishingPoint_DuoLine_list;
631 std::vector<vpDuo<vpFeatureEllipse, vpSphere> > m_featureEllipse_Sphere_list;
632 std::vector<vpDuo<vpFeatureEllipse, vpCircle> > m_featureEllipse_Circle_list;
634 std::vector<vpDuo<vpFeatureLine, vpLine> > m_featureLine_Line_list;
635 std::vector<vpTrio<vpFeatureLine, vpCylinder, int> > m_featureLine_DuoLineInt_List;
637 std::vector<vpTrio<vpFeatureSegment, vpPoint, vpPoint> > m_featureSegment_DuoPoints_list;
639#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
641 std::vector<vpPoseSpecificFeature *> m_featureSpecific_list;
651 void error_and_interaction(vpHomogeneousMatrix &cMo, vpColVector &err, vpMatrix &L);
660 void computePoseVVS(vpHomogeneousMatrix &cMo);
668 void computePoseRobustVVS(vpHomogeneousMatrix &cMo);
727template <
typename RetType,
typename... ArgsFunc,
typename... Args>
730 typedef typename std::tuple_element<0, std::tuple<Args...> >::type featureTypeReference;
731 typedef typename std::remove_reference<featureTypeReference>::type featureType;
732 m_featureSpecific_list.push_back(
733 new vpPoseSpecificFeatureTemplate<featureType, RetType, ArgsFunc...>(fct_ptr, std::forward<ArgsFunc>(args)...));
735 m_featureSpecific_list.back()->createDesired();
738 if (m_featureSpecific_list.size() > m_maxSize)
739 m_maxSize =
static_cast<unsigned int>(m_featureSpecific_list.size());
810template <
typename ObjType,
typename RetType,
typename... ArgsFunc,
typename... Args>
813 typedef typename std::tuple_element<0, std::tuple<Args...> >::type featureTypeReference;
814 typedef typename std::remove_reference<featureTypeReference>::type featureType;
815 m_featureSpecific_list.push_back(
new vpPoseSpecificFeatureTemplateObject<ObjType, featureType, RetType, ArgsFunc...>(
816 obj, fct_ptr, std::forward<ArgsFunc>(args)...));
818 m_featureSpecific_list.back()->createDesired();
821 if (m_featureSpecific_list.size() > m_maxSize)
822 m_maxSize =
static_cast<unsigned int>(m_featureSpecific_list.size());
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Class that defines a 3D cylinder in the object frame and allows forward projection of a 3D cylinder i...
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Implementation of a matrix and operations on matrices.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Tools for pose computation from any feature.
void setVerbose(const bool &mode)
void addFeatureLine(const vpLine &l)
void addFeatureEllipse(const vpCircle &c)
void addFeaturePoint3D(const vpPoint &p)
void setVVSIterMax(const unsigned int &val)
void addFeaturePoint(const vpPoint &p)
vpPoseFeatures & operator=(const vpPoseFeatures &)=default
vpPoseFeatures(const vpPoseFeatures &)=default
void setCovarianceComputation(const bool &flag)
unsigned int getVVSIterMax()
void addSpecificFeature(RetType(*fct_ptr)(ArgsFunc...), Args &&...args)
void addFeatureVanishingPoint(const vpPoint &p)
void setLambda(const double &val)
void computePose(vpHomogeneousMatrix &cMo, const vpPoseFeaturesMethodType &type=VIRTUAL_VS)
void addFeatureSegment(vpPoint &P1, vpPoint &P2)
vpMatrix getCovarianceMatrix() const
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...