00001
00002 #ifndef vimt_transform_2d_h_
00003 #define vimt_transform_2d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012 #include <vnl/vnl_fwd.h>
00013 #include <vgl/vgl_vector_2d.h>
00014 #include <vgl/vgl_point_2d.h>
00015 #include <vsl/vsl_binary_io.h>
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 class vimt_transform_2d
00055 {
00056 public:
00057
00058 enum Form { Identity,
00059 Translation,
00060 ZoomOnly,
00061 RigidBody,
00062 Similarity,
00063 Affine,
00064 Projective,
00065 Reflection};
00066
00067 vimt_transform_2d() :
00068 xx_(1),xy_(0),xt_(0),
00069 yx_(0),yy_(1),yt_(0),
00070 tx_(0),ty_(0),tt_(1),
00071 form_(Identity),inv_uptodate_(0) {};
00072
00073
00074 bool is_identity() const { return form_==Identity; };
00075 Form form() const { return form_; };
00076 vnl_matrix<double> matrix() const;
00077 void matrix(vnl_matrix<double>&) const;
00078
00079
00080 void params(vnl_vector<double>& v) const;
00081
00082 void set(const vnl_vector<double>& v, Form);
00083
00084 void set_identity();
00085
00086
00087
00088
00089
00090
00091 void set_zoom_only(double s_x, double s_y, double t_x, double t_y);
00092
00093
00094
00095
00096
00097 void set_zoom_only(double s, double t_x, double t_y) { set_zoom_only(s,s,t_x,t_y);};
00098
00099
00100
00101 void set_translation(double t_x, double t_y);
00102
00103
00104
00105
00106 void set_rigid_body(double theta, double t_x, double t_y);
00107
00108
00109
00110
00111
00112 void set_similarity(double s, double theta, double t_x, double t_y);
00113
00114
00115
00116
00117 void set_similarity(const vgl_point_2d<double> & dx, const vgl_point_2d<double> & t);
00118
00119
00120 void set_reflection( const vgl_point_2d<double> & m1, const vgl_point_2d<double> & m2);
00121
00122
00123 void set_affine(const vnl_matrix<double>&);
00124
00125
00126 void set_affine(const vgl_point_2d<double> & p,
00127 const vgl_vector_2d<double> & u,
00128 const vgl_vector_2d<double> & v);
00129
00130
00131 void set_projective(const vnl_matrix<double>&);
00132
00133
00134
00135 vgl_point_2d<double> origin() const
00136 { return vgl_point_2d<double> (tt_==1?xt_:xt_/tt_,tt_==1?yt_:yt_/tt_); }
00137
00138
00139
00140
00141 void set_origin( const vgl_point_2d<double> & );
00142
00143
00144 vgl_point_2d<double> operator()(double x, double y) const;
00145
00146 vgl_point_2d<double> operator()(const vgl_point_2d<double> & p) const { return operator()(p.x(),p.y()); }
00147
00148
00149 vimt_transform_2d inverse() const;
00150
00151
00152
00153 vgl_vector_2d<double> delta(const vgl_point_2d<double> & p, const vgl_vector_2d<double> & dp) const;
00154
00155 friend vimt_transform_2d operator*(const vimt_transform_2d&,
00156 const vimt_transform_2d&);
00157
00158 short version_no() const;
00159 void print_summary(vcl_ostream&) const;
00160 void b_write(vsl_b_ostream& bfs) const;
00161 void b_read(vsl_b_istream& bfs);
00162
00163
00164 bool operator==(const vimt_transform_2d& t) const;
00165
00166 private:
00167
00168 double xx_,xy_,xt_,yx_,yy_,yt_,tx_,ty_,tt_;
00169 Form form_;
00170
00171
00172 mutable double xx2_,xy2_,xt2_,yx2_,yy2_,yt2_,tx2_,ty2_,tt2_;
00173 mutable bool inv_uptodate_;
00174
00175 void calcInverse() const;
00176 void setCheck(int n1,int n2,const char* str) const;
00177 };
00178
00179
00180 vcl_ostream& operator<<(vcl_ostream&,const vimt_transform_2d& t);
00181
00182
00183 void vsl_b_write(vsl_b_ostream& bfs, const vimt_transform_2d& b);
00184
00185
00186 void vsl_b_read(vsl_b_istream& bfs, vimt_transform_2d& b);
00187
00188
00189 void vsl_print_summary(vcl_ostream& os,const vimt_transform_2d& t);
00190
00191
00192 #endif // vimt_transform_2d_h_