1 // This is oxl/mvl/ClosestImagePointFinder.h
2 #ifndef ClosestImagePointFinder_h_
3 #define ClosestImagePointFinder_h_
4 //:
5 // \file
6 // \brief HomgInterestPointSet closest points
7 //
8 //    ClosestImagePointFinder allows fast access to closest-point
9 //    operations on a HomgInterestPointSet.
10 //
11 // \author  Andrew W. Fitzgibbon, Oxford RRG, 21 Jan 97
12 //
13 // \verbatim
14 //  Modifications
15 //   22 Jun 2003 - Peter Vanroose - added vgl_homg_point_2d interface
16 // \endverbatim
17 //-----------------------------------------------------------------------------
18 
19 #include <iostream>
20 #include <vector>
21 #ifdef _MSC_VER
22 #  include <vcl_msvc_warnings.h>
23 #endif
24 #include <vnl/vnl_vector.h>
25 #include <vgl/vgl_fwd.h>
26 
27 class HomgInterestPointSet;
28 class vcl_multimap_double_int;
29 class HomgPoint2D;
30 
31 class ClosestImagePointFinder
32 {
33  public:
34   // Constructors/Destructors--------------------------------------------------
35 
36   ClosestImagePointFinder(const HomgInterestPointSet& corners);
37   ClosestImagePointFinder(std::vector<vgl_homg_point_2d<double> > const& corners);
38   ClosestImagePointFinder(const std::vector<HomgPoint2D>& corners);
39   ~ClosestImagePointFinder();
40 
41   // ClosestImagePointFinder(const ClosestImagePointFinder& that); - use default
42   // ClosestImagePointFinder& operator=(const ClosestImagePointFinder& that); - use default
43 
44   // Operations----------------------------------------------------------------
45   void get_all_within_search_region(double cx, double cy, double w, double h, std::vector<int>* out_indices);
46   void get_all_within_search_region(vgl_box_2d<double> const& region, std::vector<int>* out_indices);
47 
48   int get_closest_within_region(double cx, double cy, double w, double h, int* out_index = nullptr);
49   int get_closest_within_distance(double cx, double cy, double r, int* out_index = nullptr);
50 
51   // Data Access---------------------------------------------------------------
get_last_squared_distance()52   double get_last_squared_distance() const { return last_d2_; }
get_last_num_candidates()53   int get_last_num_candidates() const { return last_inrange_; }
get_last_match_index()54   int get_last_match_index() const { return last_index_; }
get_last_x()55   double get_last_x() const { return px_[last_index_]; }
get_last_y()56   double get_last_y() const { return py_[last_index_]; }
57 
58  protected:
59   // Data Members--------------------------------------------------------------
60 
61   int get_closest_within_region(double cx, double cy, double w, double h, int* out_index, double mindist_sq);
62 
63   vnl_vector<double> px_;
64   vnl_vector<double> py_;
65   vcl_multimap_double_int* y2i_;
66   double last_d2_;
67   int last_inrange_;
68   int last_index_;
69 };
70 
71 #endif // ClosestImagePointFinder_h_
72