00001 /** 00002 * \file trans2d.h <mi32/trans2d.h> 00003 * \brief Definitions for 2-D transformations and macros 00004 * 00005 * \if NODOC 00006 * $Id: trans2d.h_v 1.30 2003/09/15 13:49:56 fileserver!dwilliss Exp $ 00007 * 00008 * $Log: trans2d.h_v $ 00009 * Revision 1.30 2003/09/15 13:49:56 fileserver!dwilliss 00010 * Doxygen 00011 * 00012 * Revision 1.29 2003/07/18 20:23:30 vdronov 00013 * Added TRANS2DMODEL_RationalPolinomial 00014 * 00015 * Revision 1.28 2001/05/22 14:17:03 mju 00016 * Add Trans2DReadArcWorld() prototype. 00017 * 00018 * \endif 00019 **/ 00020 00021 #ifndef INC_MI32_TRANS2D_H 00022 #define INC_MI32_TRANS2D_H 00023 00024 #ifndef INC_MI32_CTRLPT_H 00025 #include <mi32/ctrlpt.h> 00026 #endif 00027 00028 #ifdef GEOMDLL 00029 #define GEOMLIBEXPORT MI_DLLEXPORT 00030 #else 00031 #define GEOMLIBEXPORT MI_DLLIMPORT 00032 #endif 00033 00034 00035 class FILEPATH; 00036 00037 00038 /*-------------------------------------------------------------------------------------------------*/ 00039 /* Define macros for fastest possible transformation */ 00040 /*-------------------------------------------------------------------------------------------------*/ 00041 00042 #define trans2dm(ix,iy,mat,ox,oy) { double _trans2dm_tx_, _trans2dm_ty_; _trans2dm_tx_ = (ix) * mat[0][0] + (iy) * mat[0][1] + mat[0][2]; \ 00043 _trans2dm_ty_ = (ix) * mat[1][0] + (iy) * mat[1][1] + mat[1][2]; *(ox) = _trans2dm_tx_; *(oy) = _trans2dm_ty_; } 00044 00045 #define trans2dms(ix,iy,mat) { double _trans2dms_tx_, _trans2dms_ty_; _trans2dms_tx_ = (ix) * mat[0][0] + (iy) * mat[0][1] + mat[0][2]; \ 00046 _trans2dms_ty_ = (ix) * mat[1][0] + (iy) * mat[1][1] + mat[1][2]; (ix) = _trans2dms_tx_; (iy) = _trans2dms_ty_; } 00047 00048 00049 #define trans2dx(ix,iy,mat) ((ix) * mat[0][0] + (iy) * mat[0][1] + mat[0][2]) 00050 #define trans2dy(ix,iy,mat) ((ix) * mat[1][0] + (iy) * mat[1][1] + mat[1][2]) 00051 00052 00053 /*-------------------------------------------------------------------------------------------------*/ 00054 /* Transformation model definitions */ 00055 /*-------------------------------------------------------------------------------------------------*/ 00056 00057 /* These values must fit in a UINT16 because they are stored in the RVCGEOREFINFO.CalibModel field */ 00058 00059 #define TRANS2DMODEL_OrderMask 0x00FF //!< Mask out "order" for polynomial and other models 00060 #define TRANS2DMODEL_TypeMask 0x0F00 //!< Mask out "type" values below 00061 #define TRANS2DMODEL_FlagMask 0xF000 //!< Mask out "flag" values 00062 00063 #define TRANS2DMODEL_Piecewise 0x8000 //!< Model is "piecewise" 00064 #define TRANS2DMODEL_OrientInvert 0x4000 //!< Inverted coordinate systems (eg. raster to map) 00065 00066 #define TRANS2DMODEL_Affine 0x0100 //!< Affine (MAT3X3) 00067 #define TRANS2DMODEL_PlaneProj 0x0200 //!< Plane-projective 00068 #define TRANS2DMODEL_Bilinear 0x0300 00069 #define TRANS2DMODEL_Polynomial 0x0400 00070 #define TRANS2DMODEL_Quintic 0x0500 00071 #define TRANS2DMODEL_SpaceResect 0x0600 //!< Space resection (aerial photography) 00072 #define TRANS2DMODEL_Conformal 0x0700 //!< Conformal transformation 00073 #define TRANS2DMODEL_RubberSheet 0x0800 //!< "Rubber Sheeting" or "Morphing" model 00074 #define TRANS2DMODEL_RationalPolynomial 0x0900 00075 00076 /*-------------------------------------------------------------------------------------------------*/ 00077 /* Function prototypes */ 00078 /*-------------------------------------------------------------------------------------------------*/ 00079 #if defined(__cplusplus) 00080 extern "C" { 00081 #endif 00082 //! Return pointers to forward and inverse polynomial transformation coefficients 00083 GEOMLIBEXPORT void CoordTrans2DCoeff ( 00084 const void *vtdp, //!< Transformation data 00085 const double **fx, //!< Forward x pointer 00086 const double **fy, //!< Forward y pointer 00087 const double **ix, //!< Inverse x pointer 00088 const double **iy //!< Inverse y pointer 00089 ); 00090 00091 //! Initialize polynomial transformation 00092 GEOMLIBEXPORT int CoordTrans2DCreate ( 00093 int NumPoints, //!< Number of control points used 00094 const CTRLPOINT3 *cp, //!< Control point buffer 00095 UINT16 transmodel, //!< Transformation model 00096 void **vtdp //!< Passed and returned 00097 ); 00098 00099 //! Duplicate transformation 00100 GEOMLIBEXPORT int CoordTrans2DDup ( 00101 const void *ivtdp, //!< Input transformation data 00102 void **ovtdp //!< Output transformation data 00103 ); 00104 00105 //! Frees the transformation data 00106 GEOMLIBEXPORT void CoordTrans2DFree ( 00107 void *vtdp 00108 ); 00109 00110 //! Perform forward 2-D polynomial/projective transformation 00111 GEOMLIBEXPORT int CoordTrans2DFwd ( 00112 const void *vip, //!< Input pointer 00113 void *vop, //!< Output pointer 00114 int numpts, //!< Number of points 00115 int pointsize, //!< Point size 00116 const void *vtdp //!< Transformation data 00117 ); 00118 00119 //! Retrieve affine transformation matrices 00120 GEOMLIBEXPORT int CoordTrans2DGetAffine ( 00121 const void *vtdp, //!< Transformation data 00122 MAT3X3 forward, //!< Forward transformation passed / returned 00123 MAT3X3 inverse //!< Inverse transformation passed / returned 00124 ); 00125 00126 //! Perform inverse 2-D polynomial/projective transformation 00127 GEOMLIBEXPORT int CoordTrans2DInv ( 00128 const void *vip, //!< Input pointer 00129 void *vop, //!< Output pointer 00130 int numpts, //!< Number of points 00131 int pointsize, //!< Point size 00132 const void *vtdp //!< Transformation data 00133 ); 00134 00135 //! Return TRUE if transformation is "affine", false if not 00136 //! 00137 //! @return TRUE if transformation is "affine", false if not 00138 GEOMLIBEXPORT int CoordTrans2DIsAffine ( 00139 const void *vtdp //!< Transformation data 00140 ); 00141 00142 //! Return TRUE if transformation is "reversible", false if not 00143 //! 00144 //! @return TRUE if transformation is "reversible", false if not 00145 GEOMLIBEXPORT int CoordTrans2DIsReversible ( 00146 const void *vtdp 00147 ); 00148 00149 //! Set flag for controlling primary transformation direction 00150 GEOMLIBEXPORT void CoordTrans2DSetPrimaryDirection ( 00151 void *vtdp, //!< Transformation data 00152 UINT8 PrimaryDir //!< Primary direction 00153 ); 00154 00155 //! Disect a trans2d into component parts (scale, rotation, shear) 00156 GEOMLIBEXPORT void DisectTrans2D ( 00157 const MAT3X3 mat, //!< Transformation matrix 00158 double *xscale, //!< X scale passed / returned 00159 double *yscale, //!< Y scale passed / returned 00160 double *rot, //!< Rotation passed / returned 00161 double *shear //!< Shear passed / returned 00162 ); 00163 00164 //! Compute "best" 2-D affine transformation for set of CTRLPOINT's 00165 GEOMLIBEXPORT int FindBestTrans2D ( 00166 int NumPoints, //!< Number of points 00167 const CTRLPOINT *cp, //!< Set of CTRLPOINT's 00168 MAT3X3 forward, //!< Forward transformation passed / returned 00169 MAT3X3 inverse //!< Inverse transformation passed / returned 00170 ); 00171 00172 //! Find "best" affine transformation given set of control points using CTRLPOINT array 00173 GEOMLIBEXPORT int FindBestTrans2DA ( 00174 int NumPoints, //!< Number of points 00175 const CTRLPOINT *cp, //!< Set of CTRLPOINT's 00176 MAT3X3 forward, //!< Forward transformation passed / returned 00177 MAT3X3 inverse, //!< Inverse transformation passed / returned 00178 UINT32 flags //!< Flags 00179 ); 00180 00181 //! Compute "best" 2-D affine transformation for set of CTRLPOINT3's 00182 GEOMLIBEXPORT int FindBestTrans2D3 ( 00183 int NumPoints, //!< Number of points 00184 const CTRLPOINT3 *cp3, //!< Set of CTRLPOINT3's 00185 MAT3X3 forward, //!< Forward transformation passed / returned 00186 MAT3X3 inverse //!< Inverse transformation passed / returned 00187 ); 00188 00189 //! Find "best affine transformation given set of control points using CTRLPOINT3 array 00190 GEOMLIBEXPORT int FindBestTrans2D3A ( 00191 int NumPoints, //!< Number of points 00192 const CTRLPOINT3 *cp3, //!< Set of CTRLPOINT3's 00193 MAT3X3 forward, //!< Forward transformation passed / returned 00194 MAT3X3 inverse, //!< Inverse transformation passed / returned 00195 UINT32 flags //!< Flags 00196 ); 00197 00198 //! Perform affine transformation on a point 00199 GEOMLIBEXPORT void trans2d ( 00200 double ix, //!< Input X coordinate 00201 double iy, //!< Input Y coordinate 00202 const MAT3X3 ItoO, //!< Input to Output transformation 00203 double *ox, //!< Output X coordinate 00204 double *oy //!< Output Y coordinate 00205 ); 00206 00207 //! Find the inverse transformation 00208 GEOMLIBEXPORT void trans2dfindinverse ( 00209 const MAT3X3 fwd, //!< Input transformation 00210 MAT3X3 inv //!< Output inverse transformation 00211 ); 00212 00213 //! Initialize an affine transformation 00214 //! 00215 //! This will initialize the transformation to "identity". 00216 GEOMLIBEXPORT void trans2dinit ( 00217 MAT3X3 ItoO, //!< Input to Output transformation 00218 MAT3X3 OtoI //!< Output to Input transformation 00219 ); 00220 00221 //! Shift forward/inverse affine transformation so specified points match 00222 GEOMLIBEXPORT void trans2dmatch ( 00223 MAT3X3 f, //!< Input to Output transformation 00224 MAT3X3 i, //!< Output to Input transformation 00225 double ix, //!< Input x 00226 double iy, //!< Input y 00227 double ox, //!< Output x 00228 double oy //!< Output y 00229 ); 00230 00231 //! Apply a matrix to a transformation ** not reversible 00232 GEOMLIBEXPORT void trans2dmatrix ( 00233 MAT3X3 m, //!< Output matrix 00234 const MAT3X3 mat //!< Input matrix 00235 ); 00236 00237 //! Apply a matrix to a transformation ** not reversible 00238 GEOMLIBEXPORT void trans2dmatrix1 ( 00239 const MAT3X3 m, //!< Input matrices 00240 const MAT3X3 mat, 00241 MAT3X3 out //!< Output matrix 00242 ); 00243 00244 //! Combine two affine transformations (both forward and inverse) 00245 GEOMLIBEXPORT void trans2dmatrix2 ( 00246 MAT3X3 atoc, //!< Output matrices 00247 MAT3X3 ctoa, 00248 const MAT3X3 atob, //!< Input matrices 00249 const MAT3X3 btoa, 00250 const MAT3X3 btoc, 00251 const MAT3X3 ctob 00252 ); 00253 00254 //! Rotate by ang (radians) about point x y 00255 GEOMLIBEXPORT void trans2drotpt ( 00256 MAT3X3 fwd, //!< Forward transformation 00257 MAT3X3 inv, //!< Inverse transformation 00258 double angle, //!< Angle to rotate by 00259 double ptx, //!< Point to rotat about 00260 double pty 00261 ); 00262 00263 //! Apply a rotation to an affine transformation 00264 GEOMLIBEXPORT void trans2drot ( 00265 MAT3X3 m, //!< Input to Output transformation 00266 MAT3X3 n, //!< Output to Input transformation 00267 double angle //!< Angle to rotate by 00268 ); 00269 00270 //! Scale image by sx, sy 00271 GEOMLIBEXPORT void trans2dscale ( 00272 MAT3X3 m, //!< Input to Output transformation 00273 MAT3X3 n, //!< Output to Input transformation 00274 double sx, //!< X scale 00275 double sy //!< Y scale 00276 ); 00277 00278 //! Apply a shear to an affine transformation 00279 GEOMLIBEXPORT void trans2dshear ( 00280 MAT3X3 m, //!< Input to Output transformation 00281 MAT3X3 n, //!< Output to Input transformation 00282 double shear, //!< Shear angle in radians (0 = no shear) 00283 int axis //!< Axis to shear (0 = X, 1 = Y) 00284 ); 00285 00286 //! Apply an offset to an affine transformation 00287 GEOMLIBEXPORT void trans2dshift ( 00288 MAT3X3 m, //!< Input to Output transformation 00289 MAT3X3 n, //!< Output to Input transformation 00290 double dx, //!< X shift 00291 double dy //!< Y shift 00292 ); 00293 00294 #define trans2dorient(m) SIGN(m[0][0]*m[1][1]-m[1][0]*m[0][1]) 00295 00296 //! TRANSFUNC which uses a trans2d matrix 00297 int Trans2DFunc ( 00298 void *idata, //!< Input data 00299 void *odata, //!< Output data 00300 int numpts, //!< Number of points 00301 int numdim, 00302 void *fwd //!< Transformation matrix 00303 ); 00304 00305 //! Apply an affine transformation to a DRECTXY 00306 GEOMLIBEXPORT void Trans2DRect ( 00307 const MAT3X3 trans, //!< Affine transformation 00308 const DRECT2D *irect, //!< Input rectangle 00309 DRECT2D *orect //!< Outpu rectange 00310 ); 00311 00312 //! Read transformation from ArcWorld file. 00313 //! @return TRUE if successful, FALSE if no file, < 0 if error. 00314 GEOMLIBEXPORT int Trans2DReadArcWorld ( 00315 const FILEPATH& filepath, //!< ArcWorld file path 00316 MAT3X3 forward, //!< Forward transformation returned 00317 MAT3X3 inverse //!< Inverse transformation returned 00318 ); 00319 00320 #if defined(__cplusplus) 00321 } 00322 #endif 00323 00324 #endif //!< #ifndef INC_MI32_TRANS2D_H 00325 00326
1.3.4-20031026