1 // This is oxl/mvl/SimilarityMetric.h
2 #ifndef SimilarityMetric_h_
3 #define SimilarityMetric_h_
4 //:
5 // \file
6 // \brief Scale + translate ImageMetric
7 //
8 //    An ImageMetric that simply scales and translates.  Most often used
9 //    to condition points by transforming the image centre to the origin,
10 //    and scaling so that the diagonal has length 2.
11 //
12 // \author
13 //     Andrew W. Fitzgibbon, Oxford RRG, 04 Feb 97
14 //
15 // \verbatim
16 //  Modifications
17 //   22 Jun 2003 - Peter Vanroose - added vgl_homg_point_2d interface
18 // \endverbatim
19 //
20 //-----------------------------------------------------------------------------
21 
22 #include <iostream>
23 #include <iosfwd>
24 #include <vnl/vnl_double_3x3.h>
25 #include <vgl/vgl_fwd.h>
26 #include <mvl/ImageMetric.h>
27 #ifdef _MSC_VER
28 #  include <vcl_msvc_warnings.h>
29 #endif
30 class Image;
31 
32 class SimilarityMetric : public ImageMetric
33 {
34   // Data Members--------------------------------------------------------------
35   double centre_x_;
36   double centre_y_;
37   double inv_scale_;
38   double scale_;
39 
40   vnl_double_3x3 cond_matrix;
41   vnl_double_3x3 inv_cond_matrix;
42 
43  public:
44   // Constructors/Destructors--------------------------------------------------
45 
46   SimilarityMetric();
47   SimilarityMetric(int xsize, int ysize);
48   SimilarityMetric(double cx, double cy, double scale);
49 
50   //  SimilarityMetric(const Image* ); -- don't want a dependency on ImageClasses
51   // SimilarityMetric(const SimilarityMetric& that); - use default
52   ~SimilarityMetric() override;
53   // SimilarityMetric& operator=(const SimilarityMetric& that); - use default
54 
55   void set_from_rectangle(int xsize, int ysize);
56   void set_center_and_scale(double cx, double cy, double scale);
57   void scale_matrices(double s);
58 
59   // Operations----------------------------------------------------------------
60   vgl_homg_point_2d<double> image_to_homg(vgl_point_2d<double> const&) const override;
61   HomgPoint2D image_to_homg(const vnl_double_2&) const override;
62   HomgPoint2D image_to_homg(double x, double y) const override;
63 
64   vgl_point_2d<double> homg_to_image(vgl_homg_point_2d<double> const&) const override;
65   vnl_double_2 homg_to_image(const HomgPoint2D&) const override;
66 
67   HomgPoint2D imagehomg_to_homg(const HomgPoint2D&) const override;
68   HomgPoint2D homg_to_imagehomg(const HomgPoint2D&) const override;
69   vgl_homg_point_2d<double> imagehomg_to_homg(vgl_homg_point_2d<double> const&) const override;
70   vgl_homg_point_2d<double> homg_to_imagehomg(vgl_homg_point_2d<double> const&) const override;
71 
72   double perp_dist_squared(HomgPoint2D const& p, HomgLine2D const& l) const override;
73   double perp_dist_squared(vgl_homg_point_2d<double> const&,
74                                    vgl_homg_line_2d<double> const&) const override;
75   double distance_squared(const vgl_homg_point_2d<double>&, const vgl_homg_point_2d<double>&) const override;
76   double distance_squared(vgl_line_segment_2d<double> const& segment,
77                                   vgl_homg_line_2d<double> const& line) const override;
78   double distance_squared(HomgPoint2D const&, HomgPoint2D const&) const override;
79   double distance_squared(HomgLineSeg2D const& segment, HomgLine2D const& line) const override;
80 
is_linear()81   bool is_linear() const override { return true; }
get_C()82   vnl_double_3x3 get_C() const override { return cond_matrix; }
get_C_inverse()83   vnl_double_3x3 get_C_inverse() const override { return inv_cond_matrix; }
84 
85   bool can_invert_distance() const override;
86   double image_to_homg_distance(double image_distance) const override;
87   double homg_to_image_distance(double image_distance) const override;
88 
89   // virtual bool can_invert_distance() const { return true; }
90 
91   // Data Control--------------------------------------------------------------
92   std::ostream& print(std::ostream&) const override;
93   void print() const;
94   void print(char* msg) const;
95 
96  private:
97   // Helpers-------------------------------------------------------------------
98   void make_matrices();
99 };
100 
101 #endif // SimilarityMetric_h_
102