00001
00033 #ifndef INC_MI32_TRANS2DAFFINE_H
00034 #define INC_MI32_TRANS2DAFFINE_H
00035
00036 #ifndef INC_MI32_TRANS2D_H
00037 #include <mi32/trans2d.h>
00038 #endif
00039
00040 #ifndef INC__MI32_RECT_H
00041 #include <mi32/rect.h>
00042 #endif
00043
00044 #ifndef INC_MEMORY_H
00045 #include <memory.h>
00046 #define INC_MEMORY_H
00047 #endif
00048
00049
00050 #ifndef GENERATING_DOXYGEN_OUTPUT
00051 #ifdef GEOMDLL
00052 #define LIBEXPORT MI_DLLEXPORT
00053 #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00054 #else
00055 #define LIBEXPORT MI_DLLIMPORT
00056 #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00057 #endif
00058
00059
00060 class TRANS2D_MAPGEN;
00061 class FILEPATH;
00062
00063 #endif // GENERATING_DOXYGEN_OUTPUT
00064
00065
00066
00072 class CLASSLIBEXPORT TRANS2D_AFFINE {
00073
00074 public:
00075
00076 enum AXIS {
00077 AXIS_X = 0,
00078 AXIS_Y = 1
00079 };
00080
00082 TRANS2D_AFFINE (
00083 ) { trans2dinit(m_fwd,m_inv); }
00084
00086 TRANS2D_AFFINE (
00087 const TRANS2D_AFFINE& rhs
00088 ) {
00089 memcpy(m_fwd,rhs.m_fwd,sizeof(MAT3X3));
00090 memcpy(m_inv,rhs.m_inv,sizeof(MAT3X3));
00091 }
00092
00094 TRANS2D_AFFINE (
00095 const MAT3X3 matrix,
00096 bool IsForward = true
00097 ) {
00098 if (IsForward) {
00099 memcpy(m_fwd,matrix,sizeof(MAT3X3));
00100 trans2dfindinverse(m_fwd,m_inv);
00101 }
00102 else {
00103 memcpy(m_inv,matrix,sizeof(MAT3X3));
00104 trans2dfindinverse(m_inv,m_fwd);
00105 }
00106 }
00107
00109 TRANS2D_AFFINE (
00110 const MAT3X3 fwd,
00111 const MAT3X3 inv
00112 ) {
00113 memcpy(m_fwd,fwd,sizeof(MAT3X3));
00114 memcpy(m_inv,inv,sizeof(MAT3X3));
00115 }
00116
00118 TRANS2D_AFFINE (
00119 const TRANS2D_AFFINE& trans1,
00120 const TRANS2D_AFFINE& trans2
00121 ) { trans2dmatrix2(m_fwd,m_inv,trans1.m_fwd,trans1.m_inv,trans2.m_fwd,trans2.m_inv); }
00122
00124 TRANS2D_AFFINE (
00125 const CTRLPOINT *cp,
00126 int numpoints,
00127 bool invert = false
00128 ) { FindBestTrans2DA(numpoints,cp,m_fwd,m_inv,(invert)?TRANS2DMODEL_OrientInvert:0); }
00129
00131 TRANS2D_AFFINE (
00132 const CTRLPOINT3 *cp,
00133 int numpoints,
00134 bool invert = false
00135 ) { FindBestTrans2D3A(numpoints,cp,m_fwd,m_inv,(invert)?TRANS2DMODEL_OrientInvert:0); }
00136
00138 ~TRANS2D_AFFINE (
00139 ) {}
00140
00142 TRANS2D_AFFINE& operator= (
00143 const TRANS2D_AFFINE& rhs
00144 ) {
00145 if (this != &rhs) {
00146 memcpy(m_fwd,rhs.m_fwd,sizeof(MAT3X3));
00147 memcpy(m_inv,rhs.m_inv,sizeof(MAT3X3));
00148 }
00149 return (*this);
00150 }
00151
00153 void ApplyOffset (
00154 double xoffset,
00155 double yoffset
00156 ) { trans2dshift(m_fwd,m_inv,xoffset,yoffset); }
00157
00159 void ApplyOffset (
00160 const DPOINT2D& offset
00161 ) { trans2dshift(m_fwd,m_inv,offset.x,offset.y); }
00162
00164 void ApplyOffsetReverse (
00165 double xoffset,
00166 double yoffset
00167 ) { trans2dshift(m_inv,m_fwd,xoffset,yoffset); }
00168
00170 void ApplyOffsetReverse (
00171 const DPOINT2D& offset
00172 ) { trans2dshift(m_inv,m_fwd,offset.x,offset.y); }
00173
00175 void ApplyRotation (
00176 double angle
00177 ) { trans2drot(m_fwd,m_inv,angle); }
00178
00180 void ApplyScale (
00181 double scale
00182 ) { trans2dscale(m_fwd,m_inv,scale,scale); }
00183
00185 void ApplyScale (
00186 double xscale,
00187 double yscale
00188 ) { trans2dscale(m_fwd,m_inv,xscale,yscale); }
00189
00191 void ApplyScale (
00192 const DPOINT2D &scale
00193 ) { trans2dscale(m_fwd,m_inv,scale.x,scale.y); }
00194
00196 void ApplyScaleReverse (
00197 double xscale,
00198 double yscale
00199 ) { trans2dscale(m_inv,m_fwd,xscale,yscale); }
00200
00202 void ApplyScaleReverse (
00203 const DPOINT2D &scale
00204 ) { trans2dscale(m_inv,m_fwd,scale.x,scale.y); }
00205
00207 void ApplyShear (
00208 double angle,
00209 AXIS axis
00210 ) { trans2dshear(m_fwd,m_inv,angle,static_cast<int>(axis)); }
00211
00213 void Combine (
00214 const TRANS2D_AFFINE& trans1
00215 ) {
00216 trans2dmatrix(m_fwd,trans1.m_fwd);
00217 trans2dmatrix(m_inv,trans1.m_inv);
00218 }
00219
00221 void Combine (
00222 const TRANS2D_AFFINE& trans1,
00223 const TRANS2D_AFFINE& trans2
00224 ) { trans2dmatrix2(m_fwd,m_inv,trans1.m_fwd,trans1.m_inv,trans2.m_fwd,trans2.m_inv); }
00225
00227 void CombineForwardReverse (
00228 const TRANS2D_AFFINE& trans1,
00229 const TRANS2D_AFFINE& trans2
00230 ) { trans2dmatrix2(m_fwd,m_inv,trans1.m_fwd,trans1.m_inv,trans2.m_inv,trans2.m_fwd); }
00231
00234 DPOINT2D ConvertForward (
00235 double x,
00236 double y
00237 ) const { return (DPOINT2D(trans2dx(x,y,m_fwd),trans2dy(x,y,m_fwd))); }
00238
00240 void ConvertForward (
00241 double x,
00242 double y,
00243 double& ox,
00244 double& oy
00245 ) const { ox = trans2dx(x,y,m_fwd); oy = trans2dy(x,y,m_fwd); }
00246
00249 DPOINT2D ConvertForward (
00250 const DPOINT2D& ipoint
00251 ) const { return (DPOINT2D(trans2dx(ipoint.x,ipoint.y,m_fwd),trans2dy(ipoint.x,ipoint.y,m_fwd))); }
00252
00255 DPOINT3D ConvertForward (
00256 const DPOINT3D& ipoint
00257 ) const { return (DPOINT3D(trans2dx(ipoint.x,ipoint.y,m_fwd),trans2dy(ipoint.x,ipoint.y,m_fwd),ipoint.z)); }
00258
00260 void ConvertForward (
00261 const DPOINT2D *ipoints,
00262 DPOINT2D *opoints,
00263 INT32 NumPoints
00264 ) const;
00265
00267 void ConvertForward (
00268 const DPOINT3D *ipoints,
00269 DPOINT3D *opoints,
00270 INT32 NumPoints
00271 ) const;
00272
00274 void ConvertForward (
00275 const double *ipoints,
00276 double *opoints,
00277 INT32 NumPoints,
00278 int NumDim
00279 ) const;
00280
00283 DRECT2D ConvertForward (
00284 const DRECT2D& irect
00285 ) const {
00286 DRECT2D orect;
00287 ConvertForward(irect,orect);
00288 return (orect);
00289 }
00290
00292 void ConvertForward (
00293 const DRECT2D& irect,
00294 DRECT2D& orect
00295 ) const;
00296
00299 DPOINT2D ConvertInverse (
00300 double x,
00301 double y
00302 ) const { return (DPOINT2D(trans2dx(x,y,m_inv),trans2dy(x,y,m_inv))); }
00303
00305 void ConvertInverse (
00306 double x,
00307 double y,
00308 double& ox,
00309 double& oy
00310 ) const { ox = trans2dx(x,y,m_inv); oy = trans2dy(x,y,m_inv); }
00311
00314 DPOINT2D ConvertInverse (
00315 const DPOINT2D& ipoint
00316 ) const { return (DPOINT2D(trans2dx(ipoint.x,ipoint.y,m_inv),trans2dy(ipoint.x,ipoint.y,m_inv))); }
00317
00320 DPOINT3D ConvertInverse (
00321 const DPOINT3D& ipoint
00322 ) const { return (DPOINT3D(trans2dx(ipoint.x,ipoint.y,m_inv),trans2dy(ipoint.x,ipoint.y,m_inv),ipoint.z)); }
00323
00325 void ConvertInverse (
00326 const DPOINT2D *ipoints,
00327 DPOINT2D *opoints,
00328 INT32 NumPoints
00329 ) const;
00330
00332 void ConvertInverse (
00333 const DPOINT3D *ipoints,
00334 DPOINT3D *opoints,
00335 INT32 NumPoints
00336 ) const;
00337
00339 void ConvertInverse (
00340 const double *ipoints,
00341 double *opoints,
00342 INT32 NumPoints,
00343 int NumDim
00344 ) const;
00345
00348 DRECT2D ConvertInverse (
00349 const DRECT2D& irect
00350 ) const {
00351 DRECT2D orect;
00352 ConvertInverse(irect,orect);
00353 return (orect);
00354 }
00355
00357 void ConvertInverse (
00358 const DRECT2D& irect,
00359 DRECT2D& orect
00360 ) const;
00361
00363 void DisectForward (
00364 double *xscale,
00365 double *yscale,
00366 double *rotangle = 0,
00367 double *shearangle = 0
00368 ) const { DisectTrans2D(m_fwd,xscale,yscale,rotangle,shearangle); }
00369
00371 void DisectInverse (
00372 double *xscale,
00373 double *yscale,
00374 double *rotangle = 0,
00375 double *shearangle = 0
00376 ) const { DisectTrans2D(m_inv,xscale,yscale,rotangle,shearangle); }
00377
00379 void GetMatrices (
00380 MAT3X3 fwd,
00381 MAT3X3 inv
00382 ) const { memcpy(fwd,m_fwd,sizeof(MAT3X3)); memcpy(inv,m_inv,sizeof(MAT3X3)); }
00383
00385 void GetValuesForward (
00386 double& xscale,
00387 double& xrot,
00388 double& xpos,
00389 double& yscale,
00390 double& yrot,
00391 double& ypos
00392 ) const {
00393 xscale = m_fwd[0][0]; xrot = m_fwd[0][1]; xpos = m_fwd[0][2];
00394 yscale = m_fwd[1][1]; yrot = m_fwd[1][0]; ypos = m_fwd[1][2];
00395 }
00396
00398 bool HasReverseOrientation (
00399 ) const { return ((m_fwd[0][0]*m_fwd[1][1]-m_fwd[0][1]*m_fwd[1][0]) < 0); }
00400
00401 bool IsEqual (
00402 const TRANS2D_AFFINE& rhs
00403 ) const {
00404 return (!memcmp(m_fwd,rhs.m_fwd,sizeof(MAT3X3)) && !memcmp(m_inv,rhs.m_inv,sizeof(MAT3X3)));
00405 }
00406
00409 bool IsEquivalentTo (
00410 const TRANS2D_AFFINE& rhs
00411 ) const {
00412 for (int i = 0;(i < 3);++i) {
00413 for (int j = 0;(j < 3);++j) {
00414 if (fabs(m_fwd[i][j] - rhs.m_fwd[i][j]) > 0.0000001) return (false);
00415 }
00416 }
00417 return (true);
00418 }
00419
00422 bool IsIdentity (
00423 ) const {
00424 return (m_fwd[0][0] == 1.0 && m_fwd[1][1] == 1.0 && m_fwd[0][1] == 0.0 && m_fwd[0][2] == 0.0 && m_fwd[1][0] == 0.0 && m_fwd[1][2] == 0.0);
00425 }
00426
00428 void ReverseDirection (
00429 ) {
00430 MAT3X3 temp;
00431 memcpy(temp,m_fwd,sizeof(MAT3X3));
00432 memcpy(m_fwd,m_inv,sizeof(MAT3X3));
00433 memcpy(m_inv,temp,sizeof(MAT3X3));
00434 }
00435
00437 ERRVALUE SetCtrlPoint (
00438 const CTRLPOINT *cp,
00439 int numpoints,
00440 bool invert = false
00441 ) { return (FindBestTrans2DA(numpoints,cp,m_fwd,m_inv,(invert)?TRANS2DMODEL_OrientInvert:0)); }
00442
00444 ERRVALUE SetCtrlPoint (
00445 const CTRLPOINT3 *cp,
00446 int numpoints,
00447 bool invert = false
00448 ) { return (FindBestTrans2D3A(numpoints,cp,m_fwd,m_inv,(invert)?TRANS2DMODEL_OrientInvert:0)); }
00449
00451 void SetIdentity (
00452 ) { trans2dinit(m_fwd,m_inv); }
00453
00455 void SetMatrices (
00456 const MAT3X3 fwd,
00457 const MAT3X3 inv
00458 ) { memcpy(m_fwd,fwd,sizeof(MAT3X3)); memcpy(m_inv,inv,sizeof(MAT3X3)); }
00459
00460 private:
00461 #ifndef GENERATING_DOXYGEN_OUTPUT
00462 MAT3X3 m_fwd;
00463 MAT3X3 m_inv;
00464
00465 friend class TRANS2D_MAPGEN;
00466 #endif // GENERATING_DOXYGEN_OUTPUT
00467 };
00468
00469 inline bool operator== (
00470 const TRANS2D_AFFINE& lhs,
00471 const TRANS2D_AFFINE& rhs
00472 ) { return (lhs.IsEqual(rhs)); }
00473
00474 inline bool operator!= (
00475 const TRANS2D_AFFINE& lhs,
00476 const TRANS2D_AFFINE& rhs
00477 ) { return (!lhs.IsEqual(rhs)); }
00478
00479
00482 LIBEXPORT int Trans2DReadArcWorld (
00483 const FILEPATH& filepath,
00484 TRANS2D_AFFINE& Affine
00485 );
00486
00487
00488 #undef LIBEXPORT
00489 #undef CLASSLIBEXPORT
00490
00491 #endif // INC_MI32_TRANS2DAFFINE_H