mi32/trans3d.h

Go to the documentation of this file.
00001 /**
00002  * \file trans3d.h <mi32/trans3d.h>
00003  * \brief Definitions for 3-D transformation functions
00004  *
00005  *    This header file requires C++
00006  *
00007  * \if NODOC
00008  * $Id: trans3d.h_v 1.16 2003/09/15 13:49:56 fileserver!dwilliss Exp $
00009  *
00010  * $Log: trans3d.h_v $
00011  * Revision 1.16  2003/09/15 13:49:56  fileserver!dwilliss
00012  * Doxygen
00013  *
00014  * Revision 1.15  2003/03/12 20:45:01  vdronov
00015  * added GetForward and GetInverse
00016  *
00017  * Revision 1.14  2002/11/27 21:40:02  vdronov
00018  * converrsion for FPOINT3D and FPOINT3DH added
00019  *
00020  * Revision 1.13  2002/11/20 22:02:44  vdronov
00021  * methods for  DPOINT3DH added
00022  *
00023  * Revision 1.12  2000/10/04 20:36:38  msmith
00024  * Genitor documentation.
00025  *
00026  * Revision 1.11  2000/10/03 21:39:42  mju
00027  * Include string.h for memcpy() prototype.
00028  *
00029  * Revision 1.10  1999/08/23 15:33:02  dwilliss
00030  * Don't leave dangling commas in enums.  Macintosh will hate you if you do.
00031  *
00032  * Revision 1.9  1999/08/18 15:07:43  mju
00033  * Comment out unused ApplyScale methods so will hopefully work on HP.
00034  *
00035  * Revision 1.8  1999/04/29  21:42:19  mju
00036  * Change TRANS3D to class.
00037  *
00038  * \endif
00039 **/
00040 
00041 #ifndef  INC_MI32_TRANS3D_H
00042 #define  INC_MI32_TRANS3D_H
00043 
00044 #ifndef INC_MI32_CTRLPT_H
00045 #include <mi32/ctrlpt.h>
00046 #endif
00047 
00048 #ifndef  INC_STRING_H
00049 #include <string.h>     //! Includes defn for memcpy()
00050 #define  INC_STRING_H
00051 #endif
00052 
00053 #ifdef GEOMDLL
00054    #define GEOMLIBEXPORT MI_DLLEXPORT
00055 #else
00056    #define GEOMLIBEXPORT MI_DLLIMPORT
00057 #endif
00058 
00059 //-----------------------------------------------------------------------------
00060 //!      TRANS3D class
00061 //-----------------------------------------------------------------------------
00062 
00063 class TRANS3D {
00064 
00065 public:
00066 
00067    enum AXIS {
00068       AXIS_X = 0,
00069       AXIS_Y = 1,
00070       AXIS_Z = 2
00071       };
00072 
00073    enum PLANE {
00074       PLANE_XY = 0,
00075       PLANE_XZ = 1,
00076       PLANE_YZ = 2
00077       };
00078 
00079    //! CONSTRUCTION / DESTRUCTION
00080 
00081    //! Default constructor
00082    TRANS3D (
00083       );
00084 
00085    //! Copy constructor
00086    TRANS3D (
00087       const TRANS3D& rhs
00088       ) :
00089       m_DoHomogeneous(rhs.m_DoHomogeneous)
00090       {
00091       memcpy(m_fwd,rhs.m_fwd,sizeof(m_fwd));
00092       memcpy(m_inv,rhs.m_inv,sizeof(m_inv));
00093       }
00094 
00095    //! Construct as combination of two transformations
00096    TRANS3D (
00097       const TRANS3D& in1,
00098       const TRANS3D& in2
00099       );
00100 
00101    //! Destructor
00102    ~TRANS3D (
00103       ) {
00104       }
00105 
00106    //! OPERATORS
00107 
00108    //! Assignment
00109    TRANS3D& operator= (
00110       const TRANS3D& rhs
00111       ) {
00112       memcpy(m_fwd,rhs.m_fwd,sizeof(m_fwd));
00113       memcpy(m_inv,rhs.m_inv,sizeof(m_inv));
00114       m_DoHomogeneous = rhs.m_DoHomogeneous;
00115       return (*this);
00116       }
00117 
00118    //! METHODS
00119 
00120    //! Apply forward/inverse 3D matrices to transformation
00121    void ApplyMatrices (
00122       const MAT4X4 fwd,                      //!< Forward transformation matrix
00123       const MAT4X4 inv                       //!< Inverse transformation matrix
00124       ) {
00125       ApplyMatrix(fwd,false);
00126       ApplyMatrix(inv,true);
00127       return;
00128       }
00129 
00130    //! Apply coordinate offset
00131    void ApplyOffset (
00132       double xoffset,                        //!< X offset
00133       double yoffset,                        //!< Y offset
00134       double zoffset,                        //!< Z offset
00135       bool inverse = false                   //!< Apply in inverse direction
00136       );
00137 
00138    //! Apply coordinate offset
00139    void ApplyOffset (
00140       const DPOINT3D& point,                 //!< Offset as X/Y/Z
00141       bool inverse = false                   //!< Apply in inverse direction
00142       ) {
00143       ApplyOffset(point.x,point.y,point.z,inverse);
00144       return;
00145       }
00146 
00147    //! Apply rotation
00148    void ApplyRotation (
00149       double angle,                          //!< Angle in radians
00150       AXIS axis,                             //!< Axis of rotation
00151       bool inverse = false                   //!< Apply in inverse direction
00152       );
00153 
00154    //! Apply scale
00155    void ApplyScale (
00156       double xscale,                         //!< X scale
00157       double yscale,                         //!< Y scale
00158       double zscale,                         //!< Z scale
00159       bool inverse = false                   //!< Apply in inverse direction
00160       );
00161 
00162    //! Apply equal scale to all axes
00163 //!   void ApplyScale (
00164 //!      double scale,                          // Scale
00165 //!      bool inverse = false                   // Apply in inverse direction
00166 //!      ) {
00167 //!      ApplyScale(scale,scale,scale,inverse);
00168 //!      return;
00169 //!      }
00170 
00171    //! Apply scale
00172 //!   void ApplyScale (
00173 //!      const DPOINT3D& point,                 // X/Y/Z scale
00174 //!      bool inverse = false                   // Apply in inverse direction
00175 //!      ) {
00176 //!      ApplyScale(point.x,point.y,point.z,inverse);
00177 //!      return;
00178 //!      }
00179 
00180    //! Apply shear in given plane
00181    void ApplyShear (
00182       double shear1,                         //!< First axis shear in radians
00183       double shear2,                         //!< Second axis shear in radians
00184       PLANE plane,                           //!< Shear plane
00185       bool inverse = false                   //!< Apply in inverse direction
00186       );
00187 
00188    //! Perform forward conversion on DPOINT3D array
00189    void ConvertForward (
00190       const DPOINT3D *ipoints,               //!< Source point array
00191       DPOINT3D *opoints,                     //!< Destination point array
00192       INT32 numpoints                        //!< Number of points to convert
00193       ) const;
00194 
00195    //! Perform forward conversion on single 3D point
00196    DPOINT3D ConvertForward (
00197       const DPOINT3D ipoint                  //!< Point to convert
00198       ) const {                              //! Returns converted point
00199       DPOINT3D opoint;
00200       ConvertForward(&ipoint,&opoint,1);
00201       return (opoint);
00202       }
00203 
00204    //! Perform inverse conversion on DPOINT3D array
00205    void ConvertInverse (
00206       const DPOINT3D *ipoints,               //!< Source point array
00207       DPOINT3D *opoints,                     //!< Destination point array
00208       INT32 numpoints                        //!< Number of points to convert
00209       ) const;
00210 
00211    //! Perform inverse conversion on single 3D point
00212    DPOINT3D ConvertInverse (
00213       const DPOINT3D ipoint                  //!< Point to convert
00214       ) const {                              //! Returns converted point
00215       DPOINT3D opoint;
00216       ConvertInverse(&ipoint,&opoint,1);
00217       return (opoint);
00218       }
00219 
00220    //! Perform forward conversion on DPOINT3DH array
00221    void ConvertForward (
00222       const DPOINT3DH *ipoints,              //!< Source point array
00223       DPOINT3DH *opoints,                    //!< Destination point array
00224       INT32 numpoints                        //!< Number of points to convert
00225       ) const;
00226 
00227    //! Perform forward conversion on single 3DH point
00228    DPOINT3DH ConvertForward (
00229       const DPOINT3DH ipoint                 //!< Point to convert
00230       ) const {                              //! Returns converted point
00231       DPOINT3DH opoint;
00232       ConvertForward(&ipoint,&opoint,1);
00233       return (opoint);
00234       }
00235 
00236    //! Perform inverse conversion on DPOINT3DH array
00237    void ConvertInverse (
00238       const DPOINT3DH *ipoints,              //!< Source point array
00239       DPOINT3DH *opoints,                    //!< Destination point array
00240       INT32 numpoints                        //!< Number of points to convert
00241       ) const;
00242 
00243    //! Perform inverse conversion on single 3DH point
00244    DPOINT3DH ConvertInverse (
00245       const DPOINT3DH ipoint                 //!< Point to convert
00246       ) const {                              //! Returns converted point
00247       DPOINT3DH opoint;
00248       ConvertInverse(&ipoint,&opoint,1);
00249       return (opoint);
00250       }
00251 
00252    //! Perform forward conversion on FPOINT3D array
00253    void ConvertForward (
00254       const FPOINT3D *ipoints,               //!< Source point array
00255       FPOINT3D *opoints,                     //!< Destination point array
00256       INT32 numpoints                        //!< Number of points to convert
00257       ) const;
00258 
00259    //! Perform forward conversion on single 3D point
00260    FPOINT3D ConvertForward (
00261       const FPOINT3D ipoint                  //!< Point to convert
00262       ) const {                              //! Returns converted point
00263       FPOINT3D opoint;
00264       ConvertForward(&ipoint,&opoint,1);
00265       return (opoint);
00266       }
00267 
00268    //! Perform inverse conversion on FPOINT3D array
00269    void ConvertInverse (
00270       const FPOINT3D *ipoints,               //!< Source point array
00271       FPOINT3D *opoints,                     //!< Destination point array
00272       INT32 numpoints                        //!< Number of points to convert
00273       ) const;
00274 
00275    //! Perform inverse conversion on single 3D point
00276    FPOINT3D ConvertInverse (
00277       const FPOINT3D ipoint                  //!< Point to convert
00278       ) const {                              //! Returns converted point
00279       FPOINT3D opoint;
00280       ConvertInverse(&ipoint,&opoint,1);
00281       return (opoint);
00282       }
00283 
00284    //! Perform forward conversion on FPOINT3DH array
00285    void ConvertForward (
00286       const FPOINT3DH *ipoints,              //!< Source point array
00287       FPOINT3DH *opoints,                    //!< Destination point array
00288       INT32 numpoints                        //!< Number of points to convert
00289       ) const;
00290 
00291    //! Perform forward conversion on single 3DH point
00292    FPOINT3DH ConvertForward (
00293       const FPOINT3DH ipoint                 //!< Point to convert
00294       ) const {                              //! Returns converted point
00295       FPOINT3DH opoint;
00296       ConvertForward(&ipoint,&opoint,1);
00297       return (opoint);
00298       }
00299 
00300    //! Perform inverse conversion on FPOINT3DH array
00301    void ConvertInverse (
00302       const FPOINT3DH *ipoints,              //!< Source point array
00303       FPOINT3DH *opoints,                    //!< Destination point array
00304       INT32 numpoints                        //!< Number of points to convert
00305       ) const;
00306 
00307    //! Perform inverse conversion on single 3DH point
00308    FPOINT3DH ConvertInverse (
00309       const FPOINT3DH ipoint                 //!< Point to convert
00310       ) const {                              //! Returns converted point
00311       FPOINT3DH opoint;
00312       ConvertInverse(&ipoint,&opoint,1);
00313       return (opoint);
00314       }
00315 
00316    //! Set transformation to identity
00317    void SetIdentity (
00318       );
00319 
00320    const MAT4X4& GetForward (
00321       ) const {                         
00322       return m_fwd;
00323       }
00324 
00325    const MAT4X4& GetInverse (
00326       ) const {                         
00327       return m_inv;
00328       }
00329 
00330 private:
00331    #ifndef GENERATING_DOXYGEN_OUTPUT
00332    //! MEMBERS
00333 
00334    MAT4X4 m_fwd;
00335    MAT4X4 m_inv;
00336    bool m_DoHomogeneous;      //!< Need to perform homogenous transformation
00337 
00338    //! METHODS
00339 
00340    //! Apply general matrix
00341    void ApplyMatrix (
00342       const MAT4X4 mat,                //!< Matrix to apply
00343       bool inverse                     //!< Inverse flag
00344       );
00345 
00346    //! Check if need to do homogenous transformation
00347    void ChkNeedHomo (
00348       );
00349    #endif // GENERATING_DOXYGEN_OUTPUT
00350    };
00351 
00352 
00353 //-----------------------------------------------------------------------------
00354 //!      Function prototypes
00355 //-----------------------------------------------------------------------------
00356 
00357 extern "C" {
00358    //! FindBestTrans3D - Find "best" 3-D affine transformation given set of control points
00359    GEOMLIBEXPORT int FindBestTrans3D (
00360       int NumPoints,                   //!< Number of control points
00361       CTRLPOINT3D *cp,                 //!< Set of control points
00362       MAT4X4 forward,                  //!< Transformation matrices
00363       MAT4X4 inverse
00364       );
00365    
00366    //! FindBestTrans3D3 - Find "best" 3-D affine transformation given a CTRLPOINT array
00367    GEOMLIBEXPORT int FindBestTrans3D3 (
00368       int NumPoints,                   //!< Number of control points
00369       CTRLPOINT3 *cp3,                 //!< Array of control points
00370       MAT4X4 forward,                  //!< Transformation matrices
00371       MAT4X4 inverse
00372       );
00373 
00374    //! Initialize 3-D affine transformation
00375    GEOMLIBEXPORT void trans3dinit (
00376       MAT4X4,                          //!< Transformation matrices
00377       MAT4X4
00378       );
00379    
00380    //! Perform 3-D affine transformation on a point
00381    GEOMLIBEXPORT void trans3d (
00382       double ix,                       //!< Input x
00383       double iy,                       //!< Input y
00384       double iz,                       //!< Input z
00385       MAT4X4 TransMat,                 //!< Transformation matrix
00386       double *ox,                      //!< Output x
00387       double *oy,                      //!< Output y
00388       double *oz                       //!< Output z
00389       );
00390    
00391    //! Apply offsets to a 3-D affine transformation
00392    GEOMLIBEXPORT void trans3dshift (
00393       MAT4X4 m,                        //!< Matrices of transformation
00394       MAT4X4 n,
00395       double dx,                       //!< X offset
00396       double dy,                       //!< Y offset
00397       double dz                        //!< Z offset
00398       );
00399    
00400    //! Apply a scale change to a 3-D affine transformation
00401    GEOMLIBEXPORT void trans3dscale (
00402       MAT4X4 m,                        //!< Matrices of transformation
00403       MAT4X4 n,
00404       double sx,                       //!< X scale
00405       double sy,                       //!< Y scale
00406       double sz                        //!< Z scale
00407       );
00408 
00409    //! Apply rotation to a 3-D affine transformation
00410    GEOMLIBEXPORT void trans3drot (
00411       MAT4X4 m,                        //!< Matrices of transformation
00412       MAT4X4 n,
00413       double z_axis,                   //!< X axis
00414       double x_axis,                   //!< Y axis
00415       double y_axis                    //!< Z axis
00416       );
00417    }
00418 
00419 #endif
00420 

Generated on Thu Aug 12 06:19:11 2004 for TNTsdk by doxygen 1.3.4-20031026