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
71 template <
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...);
81 template <>
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)
91 template <>
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...);
101 template <
typename featureType,
typename RetType,
typename... Args,
typename... ArgsFunc>
102 void buildDesiredFeatureWithTuple(featureType &feature, RetType(*f)(ArgsFunc...), std::tuple<Args...>
const &t)
104 vpDesiredFeatureBuilderWithTuple<
sizeof...(Args)>::buildDesiredFeatureWithTuple(feature, f, t);
112 template <
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...);
124 template <>
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...> & ,
136 template <>
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...);
147 template <
typename objType,
typename featureType,
typename RetType,
typename... Args,
typename... ArgsFunc>
148 void buildDesiredFeatureObjectWithTuple(objType *obj, featureType &feature, RetType(objType:: *f)(ArgsFunc...),
149 std::tuple<Args...>
const &t)
151 vpDesiredFeatureBuilderObjectWithTuple<
sizeof...(Args)>::buildDesiredFeatureObjectWithTuple(obj, feature, f, t);
160 template <
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...);
173 template <>
struct vpCurrentFeatureBuilderWithTuple<0>
175 template <
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
178 RetType(*f)(ArgsF...), std::tuple<ArgsTuple...> &, ArgsDecomposed &&...args)
184 template <>
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...);
195 template <
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsFunc>
196 void buildCurrentFeatureWithTuple(featureType &feature,
const vpHomogeneousMatrix &cMo, RetType(*f)(ArgsFunc...),
197 std::tuple<ArgsTuple...> &t)
199 vpCurrentFeatureBuilderWithTuple<
sizeof...(ArgsTuple)>::buildCurrentFeatureWithTuple(feature, cMo, f, t);
209 template <
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,
224 template <>
struct vpCurrentFeatureBuilderObjectWithTuple<0>
226 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsDecomposed,
228 static void buildCurrentFeatureObjectWithTuple(objType *obj, featureType & ,
230 std::tuple<ArgsTuple...> &, ArgsDecomposed &&...args)
236 template <>
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,
249 template <
typename objType,
typename featureType,
typename RetType,
typename... ArgsTuple,
typename... ArgsFunc>
250 void 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,
267 class VISP_EXPORT vpPoseSpecificFeature
270 vpPoseSpecificFeature() { }
271 virtual ~vpPoseSpecificFeature() { }
274 virtual vpMatrix currentInteraction() = 0;
275 virtual void createDesired() = 0;
289 template <
typename featureType,
typename RetType,
typename... Args>
290 class 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);
318 return m_currentFeature.error(m_desiredFeature);
321 virtual vpMatrix currentInteraction() VP_OVERRIDE
323 return m_currentFeature.interaction();
328 buildCurrentFeatureWithTuple(m_currentFeature, cMo, func_ptr, *m_tuple);
343 template <
typename ObjectType,
typename featureType,
typename RetType,
typename... Args>
344 class 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);
373 return m_currentFeature.error(m_desiredFeature);
376 virtual vpMatrix currentInteraction() VP_OVERRIDE
378 return m_currentFeature.interaction();
383 buildCurrentFeatureObjectWithTuple(m_obj, m_currentFeature, cMo, func_ptr, *m_tuple);
398 class VISP_EXPORT vpPoseFeatures
408 } vpPoseFeaturesMethodType;
418 virtual ~vpPoseFeatures();
426 void addFeaturePoint(
const vpPoint &p);
434 void addFeaturePoint3D(
const vpPoint &p);
442 void addFeatureVanishingPoint(
const vpPoint &p);
451 void addFeatureVanishingPoint(
const vpLine &l1,
const vpLine &l2);
459 void addFeatureEllipse(
const vpCircle &);
467 void addFeatureEllipse(
const vpSphere &);
475 void addFeatureLine(
const vpLine &);
485 void addFeatureLine(
const vpCylinder &,
const int &line);
499 template <
typename RetType,
typename... ArgsFunc,
typename... Args>
500 void addSpecificFeature(RetType(*fct_ptr)(ArgsFunc...), Args &&...args);
505 template <
typename ObjType,
typename RetType,
typename... ArgsFunc,
typename... Args>
506 void addSpecificFeature(ObjType *obj, RetType(ObjType:: *fct_ptr)(ArgsFunc...), Args &&...args);
526 void computePose(
vpHomogeneousMatrix &cMo,
const vpPoseFeaturesMethodType &type = VIRTUAL_VS);
535 vpMatrix getCovarianceMatrix()
const
537 if (!m_computeCovariance)
538 vpTRACE(
"Warning : The covariance matrix has not been computed. See "
539 "setCovarianceComputation() to do it.");
541 return m_covarianceMatrix;
550 double getLambda() {
return m_lambda; }
558 unsigned int getVVSIterMax() {
return m_vvsIterMax; }
565 void setCovarianceComputation(
const bool &flag) { m_computeCovariance = flag; }
573 void setLambda(
const double &val) { m_lambda = val; }
580 void setVVSIterMax(
const unsigned int &val) { m_vvsIterMax = val; }
587 void setVerbose(
const bool &mode) { m_verbose = mode; }
590 #ifndef DOXYGEN_SHOULD_SKIP_THIS
591 template <
typename FeatureType,
typename FirstParamType>
struct vpDuo
593 FeatureType *desiredFeature;
594 FirstParamType firstParam;
595 vpDuo() : desiredFeature(nullptr), firstParam() { }
598 template <
typename FeatureType,
typename FirstParamType,
typename SecondParamType>
struct vpTrio
600 FeatureType *desiredFeature;
601 FirstParamType firstParam;
602 SecondParamType secondParam;
604 vpTrio() : desiredFeature(nullptr), firstParam(), secondParam() { }
608 unsigned int m_maxSize;
609 unsigned int m_totalSize;
610 unsigned int m_vvsIterMax;
615 bool m_computeCovariance;
619 std::vector<vpDuo<vpFeaturePoint, vpPoint> > m_featurePoint_Point_list;
621 std::vector<vpDuo<vpFeaturePoint3D, vpPoint> > m_featurePoint3D_Point_list;
623 std::vector<vpDuo<vpFeatureVanishingPoint, vpPoint> > m_featureVanishingPoint_Point_list;
624 std::vector<vpTrio<vpFeatureVanishingPoint, vpLine, vpLine> > m_featureVanishingPoint_DuoLine_list;
626 std::vector<vpDuo<vpFeatureEllipse, vpSphere> > m_featureEllipse_Sphere_list;
627 std::vector<vpDuo<vpFeatureEllipse, vpCircle> > m_featureEllipse_Circle_list;
629 std::vector<vpDuo<vpFeatureLine, vpLine> > m_featureLine_Line_list;
630 std::vector<vpTrio<vpFeatureLine, vpCylinder, int> > m_featureLine_DuoLineInt_List;
632 std::vector<vpTrio<vpFeatureSegment, vpPoint, vpPoint> > m_featureSegment_DuoPoints_list;
634 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
636 std::vector<vpPoseSpecificFeature *> m_featureSpecific_list;
722 template <
typename RetType,
typename... ArgsFunc,
typename... Args>
723 void vpPoseFeatures::addSpecificFeature(RetType(*fct_ptr)(ArgsFunc...), Args &&...args)
725 typedef typename std::tuple_element<0, std::tuple<Args...> >::type featureTypeReference;
726 typedef typename std::remove_reference<featureTypeReference>::type featureType;
727 m_featureSpecific_list.push_back(
728 new vpPoseSpecificFeatureTemplate<featureType, RetType, ArgsFunc...>(fct_ptr, std::forward<ArgsFunc>(args)...));
730 m_featureSpecific_list.back()->createDesired();
733 if (m_featureSpecific_list.size() > m_maxSize)
734 m_maxSize =
static_cast<unsigned int>(m_featureSpecific_list.size());
805 template <
typename ObjType,
typename RetType,
typename... ArgsFunc,
typename... Args>
806 void vpPoseFeatures::addSpecificFeature(ObjType *obj, RetType(ObjType:: *fct_ptr)(ArgsFunc...), Args &&...args)
808 typedef typename std::tuple_element<0, std::tuple<Args...> >::type featureTypeReference;
809 typedef typename std::remove_reference<featureTypeReference>::type featureType;
810 m_featureSpecific_list.push_back(
new vpPoseSpecificFeatureTemplateObject<ObjType, featureType, RetType, ArgsFunc...>(
811 obj, fct_ptr, std::forward<ArgsFunc>(args)...));
813 m_featureSpecific_list.back()->createDesired();
816 if (m_featureSpecific_list.size() > m_maxSize)
817 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...
Implementation of column vector and the associated operations.
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 ...
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...