matrix.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00022 
00023 #if !defined MATRIX_HEADER
00024 #define MATRIX_HEADER
00025 
00026 #include "whiptk/whipcore.h"
00027 #include "whiptk/opcode.h"
00028 
00030 class WHIPTK_API WT_Matrix
00031 {
00032 protected:
00033     double      m_elements[4][4];
00034 
00035 public:
00036 
00038 
00039     WT_Matrix()
00040     {   set_identity(); }
00041 
00043     WT_Matrix(WT_Matrix const & xform)
00044     {   set(xform);     }
00045 
00047     WT_Matrix(double const * xform)
00048     {   set(xform);     }
00049 
00050         virtual ~WT_Matrix()
00051         {}
00053 public:
00054 
00056 
00057     double const *        elements() const                          {   return &m_elements[0][0];  }
00059 
00061     inline double  operator() ( unsigned int row, unsigned int col ) const
00062     {   if( row>3 || col>3 )
00063             throw WT_Result::Toolkit_Usage_Error;
00064         return m_elements[row][col];
00065     }
00067 
00069     inline double& operator() ( unsigned int row, unsigned int col )
00070     {   if( row>3 || col>3 )
00071             throw WT_Result::Toolkit_Usage_Error;
00072         return m_elements[row][col];
00073     }
00075 
00077 
00078 
00081     void                  adjoin (WT_Matrix & result) const;
00083 
00087     void                  rotate (WT_Matrix & result, long rotation) const;
00089     void                  set_identity();
00091     void                  set(double const * xform);
00093     void                  set(WT_Matrix const & xform);
00095 
00097     void                  transform(
00098         WT_Point3D const & pt, 
00099         WT_Point3D & result, 
00100         double * out_w = WD_Null, 
00101         double cutoff = 0.0 
00102         ) const;
00104     WT_Matrix &           operator *= (WT_Transform const & xform);
00106 
00108 
00109     WT_Boolean            is_identity() const;
00111     WT_Boolean            operator== (WT_Matrix const & matrix) const;
00113     WT_Boolean            operator!= (WT_Matrix const & matrix) const    {   return !(*this==matrix); }
00115 };
00116 
00118 class WHIPTK_API WT_Matrix_IO : public WT_Matrix
00119 {
00120         friend class WT_Units;
00121         friend class WT_BlockRef;
00122         friend class WT_W2D_Class_Factory;
00123         friend class WT_Class_Factory;
00124 
00125 
00126 private:
00127 
00128     enum
00129     {
00130         Eating_Initial_Whitespace,
00131         Eating_Outermost_Open_Paren,
00132         Getting_First_Row,
00133         Getting_Second_Row,
00134         Getting_Third_Row,
00135         Getting_Fourth_Row,
00136         Skipping_Past_Close_Paren
00137     }           m_stage;
00138 
00139     enum
00140     {
00141         Eating_Initial_Row_Whitespace,
00142         Eating_Open_Paren,
00143         Getting_First_Column,
00144         Getting_Second_Column,
00145         Getting_Third_Column,
00146         Getting_Fourth_Column,
00147         Skipping_Past_Row_Close_Paren
00148     }           m_row_stage;
00149 
00150     int         m_paren_count;
00151     int         m_row_paren_count;
00152 
00153 protected:
00154 
00156 
00157     WT_Matrix_IO()
00158         : WT_Matrix()
00159         , m_stage (Eating_Initial_Whitespace)
00160         , m_row_stage (Eating_Initial_Row_Whitespace)
00161     { }
00162 
00164     WT_Matrix_IO(WT_Matrix const & xform)
00165         : WT_Matrix( xform )
00166         , m_stage (Eating_Initial_Whitespace)
00167         , m_row_stage (Eating_Initial_Row_Whitespace)
00168     { }
00169 
00171     WT_Matrix_IO(double const * xform)
00172         : WT_Matrix( xform )
00173         , m_stage (Eating_Initial_Whitespace)
00174         , m_row_stage (Eating_Initial_Row_Whitespace)
00175     { }
00176 
00177         virtual ~WT_Matrix_IO()
00178         {}
00180 public:
00181 
00187     WT_Result             serialize(WT_File & file) const;
00188     WT_Result             serialize_padded(WT_File & file) const;
00189     WT_Result             materialize(WT_File & file);
00190     WT_Result             materialize_row(WT_File & file, int row);
00192 };
00193 
00195 class WHIPTK_API WT_Matrix2D
00196 {
00197 protected:
00198         double m_elements[3][3];
00199 
00200 public:
00201 
00203 
00204     WT_Matrix2D()
00205     { set_to_identity(); }
00207     WT_Matrix2D( const WT_Matrix2D& r )
00208     { set(r); }
00209 
00210         virtual ~WT_Matrix2D()
00211         {}
00213 public:
00215 
00216     double determinant() const;
00218     void get_adjoint( WT_Matrix2D& matrix) const;
00220     void get_inverse ( WT_Matrix2D& result) const;
00222 
00224     double minor(unsigned int r0, unsigned int r1, unsigned int c0, unsigned int c1) const;
00226 
00228     inline double  operator() ( unsigned int row, unsigned int col ) const
00229     {   if( row>2 || col>2 )
00230             throw WT_Result::Toolkit_Usage_Error;
00231         return m_elements[row][col];
00232     }
00234 
00236     inline double& operator() ( unsigned int row, unsigned int col )
00237     {   if( row>2 || col>2 )
00238             throw WT_Result::Toolkit_Usage_Error;
00239         return m_elements[row][col];
00240     }
00242 
00244 
00245     WT_Matrix2D& adjoin();
00247     void set( const WT_Matrix2D& matrix);
00249     void rotate (WT_Matrix2D & result, long rotation) const;
00251     void rotate (WT_Matrix2D & result, double rotation) const;
00253     WT_Matrix2D& set_to_identity();
00254 
00256 
00259     double transform(
00260         const WT_Point2D& pt, 
00261         WT_Point2D& result, 
00262         double cutoff=0.0 
00263         ) const;
00264 
00266     WT_Matrix2D & operator *= (const WT_Matrix2D & rMatrix);
00267 
00269     WT_Matrix2D & operator *= (double d);
00271 
00273 
00274     WT_Boolean operator== ( const WT_Matrix2D& matrix ) const;
00276     inline WT_Boolean operator!= ( const WT_Matrix2D& matrix ) const { return !(*this==matrix); }
00278 
00280     static const WT_Matrix2D kIdentity;
00281 };
00282 
00283 
00285 class WHIPTK_API WT_Matrix2D_IO : public WT_Matrix2D
00286 {
00287         friend class WT_Plot_Info;
00288         friend class WT_W2D_Class_Factory;
00289         friend class WT_Class_Factory;
00290 
00291 protected:
00292 
00294 
00295     WT_Matrix2D_IO()
00296         : WT_Matrix2D()
00297         , m_stage(Eating_Initial_Whitespace)
00298     { }
00300     WT_Matrix2D_IO( const WT_Matrix2D_IO& r )
00301         : WT_Matrix2D( r )
00302         , m_stage(Eating_Initial_Whitespace)
00303     { }
00304 
00306     WT_Matrix2D_IO( const WT_Matrix2D& r )
00307         : WT_Matrix2D( r )
00308         , m_stage(Eating_Initial_Whitespace)
00309     { }
00310 
00311         virtual ~WT_Matrix2D_IO()
00312         {}
00314 public:
00320     WT_Result serialize( WT_File& file) const;
00321     WT_Result materialize( WT_File& file);
00323 
00324 private:
00325     enum WT_Materialize_Stage
00326     {   Eating_Initial_Whitespace,
00327         Getting_Open_Paren_0,
00328         Getting_Open_Paren_1,
00329         Getting_Element_00,
00330         Getting_Element_01,
00331         Getting_Element_02,
00332         Getting_Close_Paren_1,
00333         Getting_Open_Paren_2,
00334         Getting_Element_10,
00335         Getting_Element_11,
00336         Getting_Element_12,
00337         Getting_Close_Paren_2,
00338         Getting_Open_Paren_3,
00339         Getting_Element_20,
00340         Getting_Element_21,
00341         Getting_Element_22,
00342         Getting_Close_Paren_3,
00343         Eating_End_Whitespace
00344     } m_stage;
00345 };
00346 
00347 
00348 #endif // MATRIX_HEADER

Generated on Tue Jan 6 22:41:13 2009 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.5