00001 // This is oxl/mvl/HomgNorm2D.h 00002 #ifndef HomgNorm2D_h_ 00003 #define HomgNorm2D_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Normalize homogeneous points 00010 // 00011 // HomgNorm2D is a class that normalizes a set of homogeneous points 00012 // by subtracting their centroid and uniformly scaling them so that 00013 // the average length (nonhomogeneous) is $\sqrt2$. 00014 // 00015 // In addition the class stores the matrices that describe the 00016 // transformations between normalized and unnormalized representations. 00017 // 00018 // \author 00019 // Andrew W. Fitzgibbon, Oxford RRG, 18 Aug 96 00020 // 00021 // \verbatim 00022 // Modifications: 00023 // 200598 FSM added diagnostic method allowing caller to detect coincident points. 00024 // 221002 Peter Vanroose - added vgl_homg_point_2d interface 00025 // \endverbatim 00026 //----------------------------------------------------------------------------- 00027 00028 #include <vcl_vector.h> 00029 #include <vgl/vgl_homg_point_2d.h> 00030 #include <mvl/HomgPoint2D.h> 00031 #include <mvl/SimilarityMetric.h> 00032 00033 class HomgNorm2D : public SimilarityMetric 00034 { 00035 public: 00036 // Constructors/Destructors-------------------------------------------------- 00037 00038 //: Construct a HomgNorm2D that will hold n normalized points. 00039 HomgNorm2D(int n, bool unit_omega = true): normalized_(n),unit_omega_(unit_omega) {} 00040 00041 //: Construct a HomgNorm2D from an array of homogeneous points. 00042 // The points will be normalized as described above and the results 00043 // stored in this class. If the optional parameter unit_omega is 00044 // set to false, then the points will not be scaled to ensure that 00045 // the homogeneous parameter is one. 00046 HomgNorm2D(const vcl_vector<HomgPoint2D>& points, bool unit_omega = true); 00047 HomgNorm2D(vcl_vector<vgl_homg_point_2d<double> > const& points, bool unit_omega = true); 00048 00049 //: Destructor 00050 ~HomgNorm2D(); 00051 00052 // Computations-------------------------------------------------------------- 00053 00054 //: Perform the normalization 00055 void normalize(const vcl_vector<HomgPoint2D>& points); 00056 void normalize(vcl_vector<vgl_homg_point_2d<double> > const& points); 00057 00058 bool was_coincident(void) const { return was_coincident_; } // FSM 00059 00060 void set(const vcl_vector<HomgPoint2D>& points) { normalize(points); } 00061 void set(vcl_vector<vgl_homg_point_2d<double> > const& points) { normalize(points); } 00062 00063 // Operations---------------------------------------------------------------- 00064 00065 //: Apply the normalization to the given point 00066 HomgPoint2D apply_normalization(const HomgPoint2D& p) { return imagehomg_to_homg(p); } 00067 vgl_homg_point_2d<double> apply_normalization(vgl_homg_point_2d<double> const& p) { return imagehomg_to_homg(p); } 00068 00069 //: Apply the inverse normalization to the given point 00070 HomgPoint2D apply_denormalization(const HomgPoint2D& p) { return homg_to_imagehomg(p); } 00071 vgl_homg_point_2d<double> apply_denormalization(vgl_homg_point_2d<double> const& p) { return homg_to_imagehomg(p); } 00072 00073 // Data Access--------------------------------------------------------------- 00074 00075 //: Return the array of normalized points 00076 vcl_vector<HomgPoint2D>& get_normalized_points() { return normalized_; } 00077 vcl_vector<vgl_homg_point_2d<double> > normalized_points(); 00078 00079 //: Have the points been scaled so their third components are one? 00080 bool points_have_unit_omega() const { return unit_omega_; } 00081 00082 //: Return the i'th normalized point. 00083 HomgPoint2D& operator [] (int i) { return normalized_[i]; } 00084 00085 //: Return the i'th normalized point. 00086 HomgPoint2D& get (int i) { return normalized_[i]; } 00087 00088 protected: 00089 // Data Members-------------------------------------------------------------- 00090 vcl_vector<HomgPoint2D> normalized_; 00091 bool unit_omega_; 00092 bool was_coincident_; // FSM 00093 }; 00094 00095 #endif // HomgNorm2D_h_