VTK
dox/Common/vtkMatrix3x3.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkMatrix3x3.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 =========================================================================*/
00029 #ifndef __vtkMatrix3x3_h
00030 #define __vtkMatrix3x3_h
00031 
00032 #include "vtkObject.h"
00033 
00034 class VTK_COMMON_EXPORT vtkMatrix3x3 : public vtkObject
00035 {
00036   // Some of the methods in here have a corresponding static (class)
00037   // method taking a pointer to 9 doubles that constitutes a user
00038   // supplied matrix. This allows C++ clients to allocate double arrays
00039   // on the stack and manipulate them using vtkMatrix3x3 methods.
00040   // This is an alternative to allowing vtkMatrix3x3 instances to be
00041   // created on the stack (which is frowned upon) or doing lots of
00042   // temporary heap allocation within vtkTransform2D methods,
00043   // which is inefficient.
00044 
00045 public:
00047   static vtkMatrix3x3 *New();
00048 
00049   vtkTypeMacro(vtkMatrix3x3,vtkObject);
00050   void PrintSelf(ostream& os, vtkIndent indent);
00051 
00053 
00055   void DeepCopy(vtkMatrix3x3 *source)
00056     {vtkMatrix3x3::DeepCopy(*this->Element,source); this->Modified(); }
00057 //BTX
00058   static void DeepCopy(double Elements[9], vtkMatrix3x3 *source)
00059     {vtkMatrix3x3::DeepCopy(Elements,*source->Element); }
00060   static void DeepCopy(double Elements[9], const double newElements[9]);
00061 //ETX
00063 
00065 
00066   void DeepCopy(const double Elements[9])
00067     { this->DeepCopy(*this->Element,Elements); this->Modified(); }
00069 
00071 
00072   void Zero()
00073     { vtkMatrix3x3::Zero(*this->Element); this->Modified(); }
00074 //BTX
00075   static void Zero(double Elements[9]);
00076 //ETX
00078 
00080 
00081   void Identity()
00082     { vtkMatrix3x3::Identity(*this->Element); this->Modified();}
00083 //BTX
00084   static void Identity(double Elements[9]);
00085 //ETX
00087 
00089 
00091   static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
00092     {vtkMatrix3x3::Invert(*in->Element,*out->Element); out->Modified(); }
00093   void Invert()
00094     { vtkMatrix3x3::Invert(this,this); }
00095 //BTX
00096   static void Invert(const double inElements[9], double outElements[9]);
00097 //ETX
00099 
00100 
00102 
00103   static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
00104     {vtkMatrix3x3::Transpose(*in->Element,*out->Element); out->Modified(); }
00105   void Transpose()
00106     { vtkMatrix3x3::Transpose(this,this); }
00107 //BTX
00108   static void Transpose(const double inElements[9], double outElements[9]);
00109 //ETX
00111 
00113 
00115   void MultiplyPoint(const float in[3], float out[3])
00116     {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
00117   void MultiplyPoint(const double in[3], double out[3])
00118     {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); }
00120 
00121 //BTX
00122   static void MultiplyPoint(const double Elements[9],
00123                             const float in[3], float out[3]);
00124   static void MultiplyPoint(const double Elements[9],
00125                             const double in[3], double out[3]);
00126 //ETX
00127 
00129 
00130   static void Multiply3x3(vtkMatrix3x3 *a, vtkMatrix3x3 *b, vtkMatrix3x3 *c) {
00131     vtkMatrix3x3::Multiply3x3(*a->Element,*b->Element,*c->Element); }
00132 //BTX
00133   static void Multiply3x3(const double a[9], const double b[9],
00134                           double c[9]);
00135 //ETX
00137 
00139 
00140   void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out)
00141     {vtkMatrix3x3::Adjoint(*in->Element,*out->Element);}
00142 //BTX
00143   static void Adjoint(const double inElements[9], double outElements[9]);
00144 //ETX
00146 
00148 
00149   double Determinant() {return vtkMatrix3x3::Determinant(*this->Element);}
00150 //BTX
00151   static double Determinant(const double Elements[9]);
00152 //ETX
00154 
00156   void SetElement(int i, int j, double value);
00157 
00159 
00160   double GetElement(int i, int j) const
00161     {return this->Element[i][j];}
00163 
00164 //BTX
00165   double *operator[](const unsigned int i)
00166     {return &(this->Element[i][0]);}
00167   const double *operator[](unsigned int i) const
00168     { return &(this->Element[i][0]); }
00169   bool operator==(const vtkMatrix3x3&);
00170   bool operator!=(const vtkMatrix3x3&);
00171   void Adjoint(vtkMatrix3x3 &in,vtkMatrix3x3 &out)
00172     {this->Adjoint(&in,&out);}
00173   double Determinant(vtkMatrix3x3 &in)
00174     {return this->Determinant(&in);}
00175   double Determinant(vtkMatrix3x3 *in)
00176     {return vtkMatrix3x3::Determinant(*in->Element);}
00177   void Invert(vtkMatrix3x3 &in,vtkMatrix3x3 &out)
00178     {this->Invert(&in,&out);}
00179   void Transpose(vtkMatrix3x3 &in,vtkMatrix3x3 &out)
00180     {this->Transpose(&in,&out);}
00181   static void PointMultiply(const double Elements[9],
00182                             const float in[3], float out[3]);
00183   static void PointMultiply(const double Elements[9],
00184                             const double in[3], double out[3]);
00185 //ETX
00186 
00187   // Descption:
00188   // Returns true if this matrix is equal to the identity matrix.
00189   bool IsIdentity();
00190 
00192   double * GetData() { return *this->Element; }
00193 
00194 //BTX
00195 protected:
00196   vtkMatrix3x3();
00197   ~vtkMatrix3x3();
00198 
00199   double Element[3][3]; // The elements of the 3x3 matrix
00200 
00201 private:
00202   vtkMatrix3x3(const vtkMatrix3x3&);  // Not implemented
00203   void operator=(const vtkMatrix3x3&);  // Not implemented
00204 //ETX
00205 };
00206 
00207 inline void vtkMatrix3x3::SetElement(int i, int j, double value)
00208 {
00209   if (this->Element[i][j] != value)
00210     {
00211     this->Element[i][j] = value;
00212     this->Modified();
00213     }
00214 }
00215 
00216 inline bool vtkMatrix3x3::IsIdentity()
00217 {
00218   double *M = *this->Element;
00219   if (M[0] == 1.0 && M[4] == 1.0 && M[8] == 1.0 &&
00220       M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[5] == 0.0 &&
00221       M[6] == 0.0 && M[7] == 0.0)
00222     {
00223     return true;
00224     }
00225   else
00226     {
00227     return false;
00228     }
00229 }
00230 
00231 inline bool vtkMatrix3x3::operator==(const vtkMatrix3x3 &other)
00232 {
00233   for (int i = 0; i < 3; ++i)
00234     {
00235     for (int j = 0; j < 3; ++j)
00236       {
00237       if (Element[i][j] != other.Element[i][j])
00238         {
00239         return false;
00240         }
00241       }
00242     }
00243   return true;
00244 }
00245 
00246 inline bool vtkMatrix3x3::operator!=(const vtkMatrix3x3 &other)
00247 {
00248   for (int i = 0; i < 3; ++i)
00249     {
00250     for (int j = 0; j < 3; ++j)
00251       {
00252       if (Element[i][j] != other.Element[i][j])
00253         {
00254         return true;
00255         }
00256       }
00257     }
00258   return false;
00259 }
00260 
00261 #endif