2 #ifndef BRUTE4PCS_FUNCTOR4PCS_H 3 #define BRUTE4PCS_FUNCTOR4PCS_H 6 #include "gr/utils/shared.h" 7 #include "gr/algorithms/match4pcsBase.h" 15 template <
typename PointType,
typename PairFilterFunctor,
typename Options>
18 using BaseCoordinates =
typename Traits4pcs<PointType>::Coordinates;
19 using Scalar =
typename PointType::Scalar;
21 using VectorType =
typename PointType::VectorType;
22 using OptionType = Options;
26 OptionType myOptions_;
27 std::vector<PointType>& mySampled_Q_3D_;
28 BaseCoordinates &myBase_3D_;
33 BaseCoordinates& base_3D_,
34 const OptionType &options)
37 ,myOptions_ (options) {}
60 Scalar distance_threshold2,
61 const std::vector <std::pair<
int,
int>> &First_pairs,
62 const std::vector <std::pair<
int,
int>> &Second_pairs,
63 typename Traits4pcs<PointType>::Set* quadrilaterals)
const {
64 using VectorType =
typename PointType::VectorType;
66 if (quadrilaterals == nullptr)
return false;
68 size_t number_of_points = 2 * First_pairs.size();
73 quadrilaterals->clear();
75 std::vector<VectorType> invariant1Set;
76 invariant1Set.reserve(number_of_points);
79 for (size_t i = 0; i < First_pairs.size(); ++i) {
80 const VectorType &p1 = mySampled_Q_3D_[First_pairs[i].first].pos();
81 const VectorType &p2 = mySampled_Q_3D_[First_pairs[i].second].pos();
82 invariant1Set.push_back(p1 + invariant1 * (p2 - p1));
86 for (size_t i = 0; i < Second_pairs.size(); ++i) {
87 const VectorType &p1 = mySampled_Q_3D_[Second_pairs[i].first].pos();
88 const VectorType &p2 = mySampled_Q_3D_[Second_pairs[i].second].pos();
90 query = p1 + invariant2 * (p2 - p1);
91 for (size_t j = 0; j < invariant1Set.size(); ++j) {
92 const auto&other = invariant1Set[j];
93 if ( (query - other).squaredNorm() < distance_threshold2 )
94 quadrilaterals->push_back(
95 { First_pairs[j].first,
96 First_pairs[j].second,
97 Second_pairs[i].first,
98 Second_pairs[i].second });
102 return quadrilaterals->size() != 0;
119 Scalar pair_normals_angle,
120 Scalar pair_distance_epsilon,
123 PairsVector* pairs)
const {
124 if (pairs == nullptr)
return;
127 pairs->reserve(2 * mySampled_Q_3D_.size());
129 PairFilterFunctor fun;
132 for (size_t j = 0; j < mySampled_Q_3D_.size(); ++j) {
133 const PointType& p = mySampled_Q_3D_[j];
134 for (size_t i = j + 1; i < mySampled_Q_3D_.size(); ++i) {
135 const PointType& q = mySampled_Q_3D_[i];
142 const Scalar distance = (q.pos() - p.pos()).norm();
143 if (std::abs(distance - pair_distance) > pair_distance_epsilon)
continue;
146 std::pair<
bool,
bool> res = fun(p,q, pair_normals_angle, *myBase_3D_[base_point1],*myBase_3D_[base_point2], myOptions_);
148 pairs->emplace_back(i, j);
150 pairs->emplace_back(j, i);
Processing functor for the computation of the 4PCS algorithm.
Definition: FunctorBrute4pcs.h:16
bool FindCongruentQuadrilaterals(Scalar invariant1, Scalar invariant2, Scalar, Scalar distance_threshold2, const std::vector< std::pair< int, int >> &First_pairs, const std::vector< std::pair< int, int >> &Second_pairs, typename Traits4pcs< PointType >::Set *quadrilaterals) const
Finds congruent candidates in the set Q, given the invariants and threshold distances. Returns true if a non empty set can be found, false otherwise.
Definition: FunctorBrute4pcs.h:56
static constexpr int size()
Definition: match4pcsBase.h:27
void Initialize()
Initializes the data structures and needed values before the match computation.
Definition: FunctorBrute4pcs.h:41
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
FunctorBrute4PCS(std::vector< PointType > &sampled_Q_3D_, BaseCoordinates &base_3D_, const OptionType &options)
Definition: FunctorBrute4pcs.h:32
void ExtractPairs(Scalar pair_distance, Scalar pair_normals_angle, Scalar pair_distance_epsilon, int base_point1, int base_point2, PairsVector *pairs) const
Constructs pairs of points in Q, corresponding to a single pair in the in basein P.
Definition: FunctorBrute4pcs.h:118