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 { params_of(v,form_); }
00081
00082 void params_of(vnl_vector<double>& v, Form) const;
00083
00084 void set(const vnl_vector<double>& v, Form);
00085
00086 void set_identity();
00087
00088
00089
00090
00091
00092
00093 void set_zoom_only(double s_x, double s_y, double t_x, double t_y);
00094
00095
00096
00097
00098
00099 void set_zoom_only(double s, double t_x, double t_y) { set_zoom_only(s,s,t_x,t_y); }
00100
00101
00102
00103 void set_translation(double t_x, double t_y);
00104
00105
00106
00107
00108 void set_rigid_body(double theta, double t_x, double t_y);
00109
00110
00111
00112
00113
00114 void set_similarity(double s, double theta, double t_x, double t_y);
00115
00116
00117
00118
00119 void set_similarity(const vgl_point_2d<double> & dx,
00120 const vgl_point_2d<double> & t);
00121
00122
00123
00124
00125 void set_similarity(const vgl_vector_2d<double> & dx,
00126 const vgl_point_2d<double> & t);
00127
00128
00129 void set_reflection( const vgl_point_2d<double> & m1, const vgl_point_2d<double> & m2);
00130
00131
00132 void set_affine(const vnl_matrix<double>&);
00133
00134
00135 void set_affine(const vgl_point_2d<double> & p,
00136 const vgl_vector_2d<double> & u,
00137 const vgl_vector_2d<double> & v);
00138
00139
00140 void set_projective(const vnl_matrix<double>&);
00141
00142
00143
00144 vgl_point_2d<double> origin() const
00145 { return vgl_point_2d<double> (tt_==1?xt_:xt_/tt_,tt_==1?yt_:yt_/tt_); }
00146
00147
00148
00149
00150 void set_origin( const vgl_point_2d<double> & );
00151
00152
00153 vgl_point_2d<double> operator()(double x, double y) const;
00154
00155 vgl_point_2d<double> operator()(const vgl_point_2d<double> & p) const { return operator()(p.x(),p.y()); }
00156
00157
00158 vimt_transform_2d inverse() const;
00159
00160
00161
00162 vgl_vector_2d<double> delta(const vgl_point_2d<double> & p, const vgl_vector_2d<double> & dp) const;
00163
00164 friend vimt_transform_2d operator*(const vimt_transform_2d&,
00165 const vimt_transform_2d&);
00166
00167 short version_no() const;
00168 void print_summary(vcl_ostream&) const;
00169 void b_write(vsl_b_ostream& bfs) const;
00170 void b_read(vsl_b_istream& bfs);
00171
00172
00173 bool operator==(const vimt_transform_2d& t) const;
00174
00175 private:
00176
00177 double xx_,xy_,xt_,yx_,yy_,yt_,tx_,ty_,tt_;
00178 Form form_;
00179
00180
00181 mutable double xx2_,xy2_,xt2_,yx2_,yy2_,yt2_,tx2_,ty2_,tt2_;
00182 mutable bool inv_uptodate_;
00183
00184 void calcInverse() const;
00185 void setCheck(int n1,int n2,const char* str) const;
00186 };
00187
00188
00189 vcl_ostream& operator<<(vcl_ostream&,const vimt_transform_2d& t);
00190
00191
00192 void vsl_b_write(vsl_b_ostream& bfs, const vimt_transform_2d& b);
00193
00194
00195 void vsl_b_read(vsl_b_istream& bfs, vimt_transform_2d& b);
00196
00197
00198 void vsl_print_summary(vcl_ostream& os,const vimt_transform_2d& t);
00199
00200
00201 #endif // vimt_transform_2d_h_