VTK
|
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(); } 00058 //BTX 00059 static void DeepCopy(double Elements[9], vtkMatrix3x3 *source) 00060 {vtkMatrix3x3::DeepCopy(Elements,*source->Element); } 00061 static void DeepCopy(double Elements[9], const double newElements[9]); 00062 //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(); } 00075 //BTX 00076 static void Zero(double Elements[9]); 00077 //ETX 00078 00080 00081 void Identity() 00082 { vtkMatrix3x3::Identity(*this->Element); this->Modified();} 00084 //BTX 00085 static void Identity(double Elements[9]); 00086 //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); } 00096 //BTX 00097 static void Invert(const double inElements[9], double outElements[9]); 00098 //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); } 00108 //BTX 00109 static void Transpose(const double inElements[9], double outElements[9]); 00110 //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); } 00133 //BTX 00134 static void Multiply3x3(const double a[9], const double b[9], 00135 double c[9]); 00136 //ETX 00137 00139 00140 void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out) 00141 {vtkMatrix3x3::Adjoint(*in->Element,*out->Element);} 00143 //BTX 00144 static void Adjoint(const double inElements[9], double outElements[9]); 00145 //ETX 00146 00148 double Determinant() {return vtkMatrix3x3::Determinant(*this->Element);} 00149 //BTX 00150 static double Determinant(const double Elements[9]); 00151 //ETX 00152 00154 void SetElement(int i, int j, double value); 00155 00157 00158 double GetElement(int i, int j) const 00159 {return this->Element[i][j];} 00161 00162 //BTX 00163 double *operator[](const unsigned int i) 00164 {return &(this->Element[i][0]);} 00165 const double *operator[](unsigned int i) const 00166 { return &(this->Element[i][0]); } 00167 bool operator==(const vtkMatrix3x3&); 00168 bool operator!=(const vtkMatrix3x3&); 00169 void Adjoint(vtkMatrix3x3 &in,vtkMatrix3x3 &out) 00170 {this->Adjoint(&in,&out);} 00171 double Determinant(vtkMatrix3x3 &in) 00172 {return this->Determinant(&in);} 00173 double Determinant(vtkMatrix3x3 *in) 00174 {return vtkMatrix3x3::Determinant(*in->Element);} 00175 void Invert(vtkMatrix3x3 &in,vtkMatrix3x3 &out) 00176 {this->Invert(&in,&out);} 00177 void Transpose(vtkMatrix3x3 &in,vtkMatrix3x3 &out) 00178 {this->Transpose(&in,&out);} 00179 static void PointMultiply(const double Elements[9], 00180 const float in[3], float out[3]); 00181 static void PointMultiply(const double Elements[9], 00182 const double in[3], double out[3]); 00183 //ETX 00184 00185 // Descption: 00186 // Returns true if this matrix is equal to the identity matrix. 00187 bool IsIdentity(); 00188 00190 double * GetData() { return *this->Element; } 00191 00192 //BTX 00193 protected: 00194 vtkMatrix3x3(); 00195 ~vtkMatrix3x3(); 00196 00197 double Element[3][3]; // The elements of the 3x3 matrix 00198 00199 private: 00200 vtkMatrix3x3(const vtkMatrix3x3&); // Not implemented 00201 void operator=(const vtkMatrix3x3&); // Not implemented 00202 //ETX 00203 }; 00204 00205 inline void vtkMatrix3x3::SetElement(int i, int j, double value) 00206 { 00207 if (this->Element[i][j] != value) 00208 { 00209 this->Element[i][j] = value; 00210 this->Modified(); 00211 } 00212 } 00213 00214 inline bool vtkMatrix3x3::IsIdentity() 00215 { 00216 double *M = *this->Element; 00217 if (M[0] == 1.0 && M[4] == 1.0 && M[8] == 1.0 && 00218 M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[5] == 0.0 && 00219 M[6] == 0.0 && M[7] == 0.0) 00220 { 00221 return true; 00222 } 00223 else 00224 { 00225 return false; 00226 } 00227 } 00228 00229 inline bool vtkMatrix3x3::operator==(const vtkMatrix3x3 &other) 00230 { 00231 for (int i = 0; i < 3; ++i) 00232 { 00233 for (int j = 0; j < 3; ++j) 00234 { 00235 if (Element[i][j] != other.Element[i][j]) 00236 { 00237 return false; 00238 } 00239 } 00240 } 00241 return true; 00242 } 00243 00244 inline bool vtkMatrix3x3::operator!=(const vtkMatrix3x3 &other) 00245 { 00246 for (int i = 0; i < 3; ++i) 00247 { 00248 for (int j = 0; j < 3; ++j) 00249 { 00250 if (Element[i][j] != other.Element[i][j]) 00251 { 00252 return true; 00253 } 00254 } 00255 } 00256 return false; 00257 } 00258 00259 #endif