VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/Math/vtkMatrix4x4.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkMatrix4x4.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00032 #ifndef vtkMatrix4x4_h
00033 #define vtkMatrix4x4_h
00034 
00035 #include "vtkCommonMathModule.h" // For export macro
00036 #include "vtkObject.h"
00037 
00038 class VTKCOMMONMATH_EXPORT vtkMatrix4x4 : public vtkObject
00039 {
00040   // Some of the methods in here have a corresponding static (class)
00041   // method taking a pointer to 16 doubles that constitutes a user
00042   // supplied matrix. This allows C++ clients to allocate double arrays
00043   // on the stack and manipulate them using vtkMatrix4x4 methods.
00044   // This is an alternative to allowing vtkMatrix4x4 instances to be
00045   // created on the stack (which is frowned upon) or doing lots of
00046   // temporary heap allocation within vtkTransform and vtkActor methods,
00047   // which is inefficient.
00048 
00049 public:
00050   double Element[4][4];
00051 
00053   static vtkMatrix4x4 *New();
00054 
00055   vtkTypeMacro(vtkMatrix4x4,vtkObject);
00056   void PrintSelf(ostream& os, vtkIndent indent);
00057 
00059 
00061   void DeepCopy(const vtkMatrix4x4 *source)
00062     {vtkMatrix4x4::DeepCopy(*this->Element,source); this->Modified(); }
00063 //BTX
00064   static void DeepCopy(double Elements[16], const vtkMatrix4x4 *source)
00065     {vtkMatrix4x4::DeepCopy(Elements,*source->Element); }
00066   static void DeepCopy(double Elements[16], const double newElements[16]);
00067 //ETX
00069 
00071 
00072   void DeepCopy(const double Elements[16])
00073     { this->DeepCopy(*this->Element,Elements); this->Modified(); }
00075 
00077 
00078   void Zero()
00079     { vtkMatrix4x4::Zero(*this->Element); this->Modified(); }
00080 //BTX
00081   static void Zero(double Elements[16]);
00082 //ETX
00084 
00086 
00087   void Identity()
00088     { vtkMatrix4x4::Identity(*this->Element); this->Modified();}
00089 //BTX
00090   static void Identity(double Elements[16]);
00091 //ETX
00093 
00095 
00097   static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
00098     {vtkMatrix4x4::Invert(*in->Element,*out->Element); out->Modified(); }
00099   void Invert()
00100     { vtkMatrix4x4::Invert(this,this); }
00101 //BTX
00102   static void Invert(const double inElements[16], double outElements[16]);
00103 //ETX
00105 
00106 
00108 
00109   static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
00110     {vtkMatrix4x4::Transpose(*in->Element,*out->Element); out->Modified(); }
00111   void Transpose()
00112     { vtkMatrix4x4::Transpose(this,this); }
00113 //BTX
00114   static void Transpose(const double inElements[16], double outElements[16]);
00115 //ETX
00117 
00119 
00121   void MultiplyPoint(const float in[4], float out[4])
00122     {vtkMatrix4x4::MultiplyPoint(*this->Element,in,out); }
00123   void MultiplyPoint(const double in[4], double out[4])
00124     {vtkMatrix4x4::MultiplyPoint(*this->Element,in,out); }
00126 
00127 //BTX
00128   static void MultiplyPoint(const double Elements[16],
00129                             const float in[4], float out[4]);
00130   static void MultiplyPoint(const double Elements[16],
00131                             const double in[4], double out[4]);
00132 //ETX
00133 
00135 
00137   float *MultiplyPoint(const float in[4])
00138     {return this->MultiplyFloatPoint(in); }
00139   float *MultiplyFloatPoint(const float in[4])
00140     {this->MultiplyPoint(in,this->FloatPoint); return this->FloatPoint; }
00141   double *MultiplyDoublePoint(const double in[4])
00142     {this->MultiplyPoint(in,this->DoublePoint); return this->DoublePoint; }
00144 
00146 
00147   static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b,
00148                           vtkMatrix4x4 *c);
00149 //BTX
00150   static void Multiply4x4(const double a[16], const double b[16],
00151                           double c[16]);
00152 //ETX
00154 
00156 
00157   void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out)
00158     {vtkMatrix4x4::Adjoint(*in->Element,*out->Element);}
00159 //BTX
00160   static void Adjoint(const double inElements[16], double outElements[16]);
00161 //ETX
00163 
00165 
00166   double Determinant() {return vtkMatrix4x4::Determinant(*this->Element);}
00167 //BTX
00168   static double Determinant(const double Elements[16]);
00169 //ETX
00171 
00173   void SetElement(int i, int j, double value);
00174 
00176 
00177   double GetElement(int i, int j) const
00178     {return this->Element[i][j];}
00180 
00181 //BTX
00182   double *operator[](const unsigned int i)
00183     {return &(this->Element[i][0]);}
00184   const double *operator[](unsigned int i) const
00185     { return &(this->Element[i][0]); }
00186   void Adjoint(vtkMatrix4x4 &in,vtkMatrix4x4 &out)
00187     {this->Adjoint(&in,&out);}
00188   double Determinant(vtkMatrix4x4 &in)
00189     {return this->Determinant(&in);}
00190   double Determinant(vtkMatrix4x4 *in)
00191     {return vtkMatrix4x4::Determinant(*in->Element);}
00192   void Invert(vtkMatrix4x4 &in,vtkMatrix4x4 &out)
00193     {this->Invert(&in,&out);}
00194   void Transpose(vtkMatrix4x4 &in,vtkMatrix4x4 &out)
00195     {this->Transpose(&in,&out);}
00196   static void PointMultiply(const double Elements[16],
00197                             const float in[4], float out[4]);
00198   static void PointMultiply(const double Elements[16],
00199                             const double in[4], double out[4]);
00200 //ETX
00201 
00202 protected:
00203   vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); };
00204   ~vtkMatrix4x4() {}
00205 
00206   float FloatPoint[4];
00207   double DoublePoint[4];
00208 private:
00209   // Useful for viewing a double[16] as a double[4][4]
00210   typedef double (*SqMatPtr)[4];
00211   typedef const double (*ConstSqMatPtr)[4];
00212 
00213   vtkMatrix4x4(const vtkMatrix4x4&);  // Not implemented
00214   void operator= (const vtkMatrix4x4&);  // Not implemented
00215 };
00216 
00217 //----------------------------------------------------------------------------
00218 // Multiplies matrices a and b and stores the result in c.
00219 inline void vtkMatrix4x4::Multiply4x4(const double a[16], const double b[16],
00220                                       double c[16])
00221 {
00222   ConstSqMatPtr aMat = reinterpret_cast<ConstSqMatPtr>(a);
00223   ConstSqMatPtr bMat = reinterpret_cast<ConstSqMatPtr>(b);
00224 
00225   double tmp[16];
00226   SqMatPtr cMat = reinterpret_cast<SqMatPtr>(tmp);
00227 
00228   for (int i = 0; i < 4; i++)
00229     {
00230     for (int k = 0; k < 4; k++)
00231       {
00232       cMat[i][k] = aMat[i][0] * bMat[0][k] +
00233                    aMat[i][1] * bMat[1][k] +
00234                    aMat[i][2] * bMat[2][k] +
00235                    aMat[i][3] * bMat[3][k];
00236       }
00237     }
00238 
00239   // Copy to final dest
00240   memcpy(c, tmp, 16 * sizeof(double));
00241 }
00242 
00243 //----------------------------------------------------------------------------
00244 inline void vtkMatrix4x4::Multiply4x4(
00245   const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c)
00246 {
00247   vtkMatrix4x4::Multiply4x4(*a->Element, *b->Element, *c->Element);
00248 }
00249 
00250 //----------------------------------------------------------------------------
00251 inline void vtkMatrix4x4::SetElement(int i, int j, double value)
00252 {
00253   if (this->Element[i][j] != value)
00254     {
00255     this->Element[i][j] = value;
00256     this->Modified();
00257     }
00258 }
00259 
00260 #endif
00261