Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

matrix.h

00001 //  Copyright (c) 1996-2001 by Autodesk, Inc.
00002 //
00003 //  By using this code, you are agreeing to the terms and conditions of
00004 //  the License Agreement included in the documentation for this code.
00005 //
00006 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00007 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00008 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00009 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00010 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00011 //
00012 //  Use, duplication, or disclosure by the U.S. Government is subject to
00013 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00014 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00015 //  Data and Computer Software), as applicable.
00016 //
00017 
00018 #if !defined MATRIX_HEADER
00019 #define MATRIX_HEADER
00020 
00021 #include "whiptk/whipcore.h"
00022 #include "whiptk/opcode.h"
00023 
00025 class WHIPTK_API WT_Matrix
00026 {
00027 private:
00028 
00029     double      m_elements[4][4];
00030 
00031     enum
00032     {
00033         Eating_Initial_Whitespace,
00034         Eating_Outermost_Open_Paren,
00035         Getting_First_Row,
00036         Getting_Second_Row,
00037         Getting_Third_Row,
00038         Getting_Fourth_Row,
00039         Skipping_Past_Close_Paren
00040     }           m_stage;
00041 
00042     enum
00043     {
00044         Eating_Initial_Row_Whitespace,
00045         Eating_Open_Paren,
00046         Getting_First_Column,
00047         Getting_Second_Column,
00048         Getting_Third_Column,
00049         Getting_Fourth_Column,
00050         Skipping_Past_Row_Close_Paren
00051     }           m_row_stage;
00052 
00053     int         m_paren_count;
00054     int         m_row_paren_count;
00055 
00056 public:
00057 
00059 
00060     WT_Matrix()
00061         : m_stage (Eating_Initial_Whitespace)
00062         , m_row_stage (Eating_Initial_Row_Whitespace)
00063     {   set_identity(); }
00064 
00066     WT_Matrix(WT_Matrix const & xform)
00067         : m_stage (Eating_Initial_Whitespace)
00068         , m_row_stage (Eating_Initial_Row_Whitespace)
00069     {   set(xform);     }
00070 
00072     WT_Matrix(double const * xform)
00073         : m_stage (Eating_Initial_Whitespace)
00074         , m_row_stage (Eating_Initial_Row_Whitespace)
00075     {   set(xform);     }
00077 
00078 
00080 
00081     double const *        elements() const                          {   return &m_elements[0][0];  }
00083 
00085     inline double  operator() ( unsigned int row, unsigned int col ) const
00086     {   if( row>3 || col>3 )
00087             throw WT_Result::Toolkit_Usage_Error;
00088         return m_elements[row][col];
00089     }
00091 
00093     inline double& operator() ( unsigned int row, unsigned int col )
00094     {   if( row>3 || col>3 )
00095             throw WT_Result::Toolkit_Usage_Error;
00096         return m_elements[row][col];
00097     }
00099 
00101 
00102 
00105     void                  adjoin (WT_Matrix & result) const;
00107 
00111     void                  rotate (WT_Matrix & result, long rotation) const;
00113     void                  set_identity();
00115     void                  set(double const * xform);
00117     void                  set(WT_Matrix const & xform);
00119 
00121     void                  transform(
00122         WT_Point3D const & pt, 
00123         WT_Point3D & result, 
00124         double * out_w = WD_Null, 
00125         double cutoff = 0.0 
00126         ) const;
00128     WT_Matrix &           operator *= (WT_Transform const & xform);
00130 
00132 
00133     WT_Boolean            is_identity() const;
00135     WT_Boolean            operator== (WT_Matrix const & matrix) const;
00137     WT_Boolean            operator!= (WT_Matrix const & matrix) const    {   return !(*this==matrix); }
00139 
00145     WT_Result             serialize(WT_File & file) const;
00146     WT_Result             serialize_padded(WT_File & file) const;
00147     WT_Result             materialize(WT_File & file);
00148     WT_Result             materialize_row(WT_File & file, int row);
00150 };
00151 
00153 class WHIPTK_API WT_Matrix2D
00154 {   double m_elements[3][3];
00155 public:
00156 
00158 
00159     WT_Matrix2D()
00160     : m_stage(Eating_Initial_Whitespace)
00161     { set_to_identity(); }
00163     WT_Matrix2D( const WT_Matrix2D& r )
00164     : m_stage(Eating_Initial_Whitespace)
00165     { set(r); }
00167 
00169 
00170     double determinant() const;
00172     void get_adjoint( WT_Matrix2D& matrix) const;
00174     void get_inverse (WT_Matrix2D & result) const;
00176 
00178     double minor(unsigned int r0, unsigned int r1, unsigned int c0, unsigned int c1) const;
00180 
00182     inline double  operator() ( unsigned int row, unsigned int col ) const
00183     {   if( row>2 || col>2 )
00184             throw WT_Result::Toolkit_Usage_Error;
00185         return m_elements[row][col];
00186     }
00188 
00190     inline double& operator() ( unsigned int row, unsigned int col )
00191     {   if( row>2 || col>2 )
00192             throw WT_Result::Toolkit_Usage_Error;
00193         return m_elements[row][col];
00194     }
00196 
00198 
00199     WT_Matrix2D& adjoin();
00201     void set( const WT_Matrix2D& matrix);
00203     WT_Matrix2D& set_to_identity();
00204 
00206 
00209     double transform(
00210         const WT_Point2D& pt, 
00211         WT_Point2D& result, 
00212         double cutoff=0.0 
00213         ) const;
00214 
00216     WT_Matrix2D & operator *= (double d);
00218 
00220 
00221     WT_Boolean operator== ( const WT_Matrix2D& matrix ) const;
00223     inline WT_Boolean operator!= ( const WT_Matrix2D& matrix ) const { return !(*this==matrix); }
00225 
00231     WT_Result serialize( WT_File& file) const;
00232     WT_Result materialize( WT_File& file);
00234 
00236     static const WT_Matrix2D kIdentity;
00237 
00238 private:
00239     enum WT_Materialize_Stage
00240     {   Eating_Initial_Whitespace,
00241         Getting_Open_Paren_0,
00242         Getting_Open_Paren_1,
00243         Getting_Element_00,
00244         Getting_Element_01,
00245         Getting_Element_02,
00246         Getting_Close_Paren_1,
00247         Getting_Open_Paren_2,
00248         Getting_Element_10,
00249         Getting_Element_11,
00250         Getting_Element_12,
00251         Getting_Close_Paren_2,
00252         Getting_Open_Paren_3,
00253         Getting_Element_20,
00254         Getting_Element_21,
00255         Getting_Element_22,
00256         Getting_Close_Paren_3,
00257         Eating_End_Whitespace
00258     } m_stage;
00259 };
00260 
00261 
00262 #endif // MATRIX_HEADER

Generated on Tue May 17 12:07:44 2005 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.1