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 "vtkCommonMathModule.h" // For export macro 00033 #include "vtkObject.h" 00034 00035 class VTKCOMMONMATH_EXPORT vtkMatrix3x3 : public vtkObject 00036 { 00037 // Some of the methods in here have a corresponding static (class) 00038 // method taking a pointer to 9 doubles that constitutes a user 00039 // supplied matrix. This allows C++ clients to allocate double arrays 00040 // on the stack and manipulate them using vtkMatrix3x3 methods. 00041 // This is an alternative to allowing vtkMatrix3x3 instances to be 00042 // created on the stack (which is frowned upon) or doing lots of 00043 // temporary heap allocation within vtkTransform2D methods, 00044 // which is inefficient. 00045 00046 public: 00048 static vtkMatrix3x3 *New(); 00049 00050 vtkTypeMacro(vtkMatrix3x3,vtkObject); 00051 void PrintSelf(ostream& os, vtkIndent indent); 00052 00054 00056 void DeepCopy(vtkMatrix3x3 *source) 00057 {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 00064 00066 00067 void DeepCopy(const double Elements[9]) 00068 { this->DeepCopy(*this->Element,Elements); this->Modified(); } 00070 00072 00073 void Zero() 00074 { vtkMatrix3x3::Zero(*this->Element); this->Modified(); } 00075 //BTX 00076 static void Zero(double Elements[9]); 00077 //ETX 00079 00081 00082 void Identity() 00083 { vtkMatrix3x3::Identity(*this->Element); this->Modified();} 00084 //BTX 00085 static void Identity(double Elements[9]); 00086 //ETX 00088 00090 00092 static void Invert(vtkMatrix3x3 *in, vtkMatrix3x3 *out) 00093 {vtkMatrix3x3::Invert(*in->Element,*out->Element); out->Modified(); } 00094 void Invert() 00095 { vtkMatrix3x3::Invert(this,this); } 00096 //BTX 00097 static void Invert(const double inElements[9], double outElements[9]); 00098 //ETX 00100 00101 00103 00104 static void Transpose(vtkMatrix3x3 *in, vtkMatrix3x3 *out) 00105 {vtkMatrix3x3::Transpose(*in->Element,*out->Element); out->Modified(); } 00106 void Transpose() 00107 { vtkMatrix3x3::Transpose(this,this); } 00108 //BTX 00109 static void Transpose(const double inElements[9], double outElements[9]); 00110 //ETX 00112 00114 00116 void MultiplyPoint(const float in[3], float out[3]) 00117 {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); } 00118 void MultiplyPoint(const double in[3], double out[3]) 00119 {vtkMatrix3x3::MultiplyPoint(*this->Element,in,out); } 00121 00122 //BTX 00123 static void MultiplyPoint(const double Elements[9], 00124 const float in[3], float out[3]); 00125 static void MultiplyPoint(const double Elements[9], 00126 const double in[3], double out[3]); 00127 //ETX 00128 00130 00131 static void Multiply3x3(vtkMatrix3x3 *a, vtkMatrix3x3 *b, vtkMatrix3x3 *c) { 00132 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 00138 00140 00141 void Adjoint(vtkMatrix3x3 *in, vtkMatrix3x3 *out) 00142 {vtkMatrix3x3::Adjoint(*in->Element,*out->Element);} 00143 //BTX 00144 static void Adjoint(const double inElements[9], double outElements[9]); 00145 //ETX 00147 00149 00150 double Determinant() {return vtkMatrix3x3::Determinant(*this->Element);} 00151 //BTX 00152 static double Determinant(const double Elements[9]); 00153 //ETX 00155 00157 void SetElement(int i, int j, double value); 00158 00160 00161 double GetElement(int i, int j) const 00162 {return this->Element[i][j];} 00164 00165 //BTX 00166 double *operator[](const unsigned int i) 00167 {return &(this->Element[i][0]);} 00168 const double *operator[](unsigned int i) const 00169 { return &(this->Element[i][0]); } 00170 bool operator==(const vtkMatrix3x3&); 00171 bool operator!=(const vtkMatrix3x3&); 00172 void Adjoint(vtkMatrix3x3 &in,vtkMatrix3x3 &out) 00173 {this->Adjoint(&in,&out);} 00174 double Determinant(vtkMatrix3x3 &in) 00175 {return this->Determinant(&in);} 00176 double Determinant(vtkMatrix3x3 *in) 00177 {return vtkMatrix3x3::Determinant(*in->Element);} 00178 void Invert(vtkMatrix3x3 &in,vtkMatrix3x3 &out) 00179 {this->Invert(&in,&out);} 00180 void Transpose(vtkMatrix3x3 &in,vtkMatrix3x3 &out) 00181 {this->Transpose(&in,&out);} 00182 static void PointMultiply(const double Elements[9], 00183 const float in[3], float out[3]); 00184 static void PointMultiply(const double Elements[9], 00185 const double in[3], double out[3]); 00186 //ETX 00187 00188 // Descption: 00189 // Returns true if this matrix is equal to the identity matrix. 00190 bool IsIdentity(); 00191 00193 double * GetData() { return *this->Element; } 00194 00195 //BTX 00196 protected: 00197 vtkMatrix3x3(); 00198 ~vtkMatrix3x3(); 00199 00200 double Element[3][3]; // The elements of the 3x3 matrix 00201 00202 private: 00203 vtkMatrix3x3(const vtkMatrix3x3&); // Not implemented 00204 void operator=(const vtkMatrix3x3&); // Not implemented 00205 //ETX 00206 }; 00207 00208 inline void vtkMatrix3x3::SetElement(int i, int j, double value) 00209 { 00210 if (this->Element[i][j] != value) 00211 { 00212 this->Element[i][j] = value; 00213 this->Modified(); 00214 } 00215 } 00216 00217 inline bool vtkMatrix3x3::IsIdentity() 00218 { 00219 double *M = *this->Element; 00220 if (M[0] == 1.0 && M[4] == 1.0 && M[8] == 1.0 && 00221 M[1] == 0.0 && M[2] == 0.0 && M[3] == 0.0 && M[5] == 0.0 && 00222 M[6] == 0.0 && M[7] == 0.0) 00223 { 00224 return true; 00225 } 00226 else 00227 { 00228 return false; 00229 } 00230 } 00231 00232 inline bool vtkMatrix3x3::operator==(const vtkMatrix3x3 &other) 00233 { 00234 for (int i = 0; i < 3; ++i) 00235 { 00236 for (int j = 0; j < 3; ++j) 00237 { 00238 if (Element[i][j] != other.Element[i][j]) 00239 { 00240 return false; 00241 } 00242 } 00243 } 00244 return true; 00245 } 00246 00247 inline bool vtkMatrix3x3::operator!=(const vtkMatrix3x3 &other) 00248 { 00249 for (int i = 0; i < 3; ++i) 00250 { 00251 for (int j = 0; j < 3; ++j) 00252 { 00253 if (Element[i][j] != other.Element[i][j]) 00254 { 00255 return true; 00256 } 00257 } 00258 } 00259 return false; 00260 } 00261 00262 #endif