match4pcsBase.h
Go to the documentation of this file.
1 //
2 // Created by Sandra Alfaro on 24/05/18.
3 //
4 
5 #ifndef OPENGR_MATCH4PCSBASE_H
6 #define OPENGR_MATCH4PCSBASE_H
7 
8 #include <vector>
9 
10 #ifdef OpenGR_USE_OPENMP
11 #include <omp.h>
12 #endif
13 
14 #include "gr/utils/shared.h"
15 #include "gr/utils/sampling.h"
16 #include "gr/accelerators/kdtree.h"
17 #include "gr/utils/logger.h"
18 #include "gr/algorithms/congruentSetExplorationBase.h"
19 
20 #ifdef TEST_GLOBAL_TIMINGS
21 # include "gr/utils/timer.h"
22 #endif
23 
24 namespace gr {
25  template <typename PointType>
26  struct Traits4pcs {
27  static constexpr int size() { return 4; }
28  using Base = std::array<int,4>;
29  using Set = std::vector<Base>;
30  using Coordinates = std::array<const PointType*, 4>;
31  };
32 
33  /// Class for the computation of the 4PCS algorithm.
34  /// \param Functor use to determinate the use of Super4pcs or 4pcs algorithm.
35  template <template <typename, typename, typename> class _Functor,
36  typename _PointType,
37  typename _TransformVisitor,
38  typename _PairFilteringFunctor, /// <\brief Must implements PairFilterConcept
39  template < class, class > class PairFilteringOptions >
41  public:
42  using Scalar = typename _PointType::Scalar;
43  using PairFilteringFunctor = _PairFilteringFunctor;
46  using VectorType = typename MatchBaseType::VectorType;
47  using MatrixType = typename MatchBaseType::MatrixType;
50  using Set = typename MatchBaseType::Set;
54 
55  protected:
57 
58  public:
59 
60  inline Match4pcsBase (const OptionsType& options
61  , const Utils::Logger& logger);
62 
63  virtual ~Match4pcsBase();
64 
65  inline const Functor& getFunctor() const { return fun_; }
66 
67  /// Takes quadrilateral as a base, computes robust intersection point
68  /// (approximate as the lines might not intersect) and returns the invariants
69  /// corresponding to the two selected lines. The method also updates the order
70  /// of the base base_3D_.
71  inline bool TryQuadrilateral(Scalar &invariant1, Scalar &invariant2,
72  int &id1, int &id2, int &id3, int &id4);
73 
74  /// Selects a random triangle in the set P (then we add another point to keep the
75  /// base as planar as possible). We apply a simple heuristic that works in most
76  /// practical cases. The idea is to accept maximum distance, computed by the
77  /// estimated overlap, multiplied by the diameter of P, and try to have
78  /// a triangle with all three edges close to this distance. Wide triangles helps
79  /// to make the transformation robust while too large triangles makes the
80  /// probability of having all points in the inliers small so we try to trade-off.
81  inline bool SelectQuadrilateral(Scalar &invariant1, Scalar &invariant2,
82  int& base1, int& base2, int& base3, int& base4);
83 
84  /// Initializes the data structures and needed values before the match
85  /// computation.
86  /// This method is called once the internal state of the Base class as been
87  /// set.
88  void Initialize() override;
89 
90  /// Find all the congruent set similar to the base in the second 3D model (Q).
91  /// It could be with a 3 point base or a 4 point base.
92  /// \param base use to find the similar points congruent in Q.
93  /// \param congruent_set a set of all point congruent found in Q.
94  bool generateCongruents (CongruentBaseType& base,Set& congruent_quads) override;
95 
96  /// Tries to compute an inital base from P
97  /// @param [out] base The base, if found. Initial value is not used. Modified as
98  /// the computed base if the return value is true.
99  /// @return true if a base is found an initialized, false otherwise
100  bool initBase(CongruentBaseType &base) override;
101 
102  protected:
104 
105  private:
106  static inline Scalar distSegmentToSegment( const VectorType& p1, const VectorType& p2,
107  const VectorType& q1, const VectorType& q2,
108  Scalar& invariant1, Scalar& invariant2);
109  };
110 }
111 
112 #include "match4pcsBase.hpp"
113 
114 #endif //OPENGR_MATCH4PCSBASE_H
bool initBase(CongruentBaseType &base) override
Tries to compute an inital base from P.
Definition: match4pcsBase.hpp:255
Match4pcsBase(const OptionsType &options, const Utils::Logger &logger)
Definition: match4pcsBase.hpp:34
virtual ~Match4pcsBase()
Definition: match4pcsBase.hpp:46
static constexpr int size()
Definition: match4pcsBase.h:27
bool generateCongruents(CongruentBaseType &base, Set &congruent_quads) override
Find all the congruent set similar to the base in the second 3D model (Q). It could be with a 3 point...
Definition: match4pcsBase.hpp:202
void Initialize() override
Initializes the data structures and needed values before the match computation. This method is called...
Definition: match4pcsBase.hpp:192
Functor fun_
Definition: match4pcsBase.h:56
bool SelectQuadrilateral(Scalar &invariant1, Scalar &invariant2, int &base1, int &base2, int &base3, int &base4)
Selects a random triangle in the set P (then we add another point to keep the base as planar as possi...
Definition: match4pcsBase.hpp:111
CongruentSetExplorationBase< Traits, PointType, TransformVisitor, PairFilteringFunctor, OptExts... >::Scalar ComputeTransformation(const InputRange1 &P, const InputRange2 &Q, Eigen::Ref< typename CongruentSetExplorationBase< Traits, PointType, TransformVisitor, PairFilteringFunctor, OptExts... >::MatrixType > transformation, const Sampler< PointType > &sampler, TransformVisitor &v)
Definition: congruentSetExplorationBase.hpp:61
void get(int queryId, int nElPerDim, int, typename NeighborhoodType< 3 >::ptr first, typename NeighborhoodType< 3 >::ptr)
Definition: utils.h:279
const Functor & getFunctor() const
Definition: match4pcsBase.h:65
Definition: logger.h:62
bool TryQuadrilateral(Scalar &invariant1, Scalar &invariant2, int &id1, int &id2, int &id3, int &id4)
Takes quadrilateral as a base, computes robust intersection point (approximate as the lines might not...
Definition: match4pcsBase.hpp:53
virtual bool initBase(CongruentBaseType &base, Scalar &invariant1, Scalar &invariant2)
Definition: match4pcsBase.hpp:267