VTK
|
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 "vtkObject.h" 00036 00037 class VTK_COMMON_EXPORT vtkMatrix4x4 : public vtkObject 00038 { 00039 // Some of the methods in here have a corresponding static (class) 00040 // method taking a pointer to 16 doubles that constitutes a user 00041 // supplied matrix. This allows C++ clients to allocate double arrays 00042 // on the stack and manipulate them using vtkMatrix4x4 methods. 00043 // This is an alternative to allowing vtkMatrix4x4 instances to be 00044 // created on the stack (which is frowned upon) or doing lots of 00045 // temporary heap allocation within vtkTransform and vtkActor methods, 00046 // which is inefficient. 00047 00048 public: 00049 double Element[4][4]; 00050 00052 static vtkMatrix4x4 *New(); 00053 00054 vtkTypeMacro(vtkMatrix4x4,vtkObject); 00055 void PrintSelf(ostream& os, vtkIndent indent); 00056 00058 00060 void DeepCopy(const vtkMatrix4x4 *source) 00061 {vtkMatrix4x4::DeepCopy(*this->Element,source); this->Modified(); } 00062 //BTX 00063 static void DeepCopy(double Elements[16], const vtkMatrix4x4 *source) 00064 {vtkMatrix4x4::DeepCopy(Elements,*source->Element); } 00065 static void DeepCopy(double Elements[16], const double newElements[16]); 00066 //ETX 00068 00070 00071 void DeepCopy(const double Elements[16]) 00072 { this->DeepCopy(*this->Element,Elements); this->Modified(); } 00074 00076 00077 void Zero() 00078 { vtkMatrix4x4::Zero(*this->Element); this->Modified(); } 00079 //BTX 00080 static void Zero(double Elements[16]); 00081 //ETX 00083 00085 00086 void Identity() 00087 { vtkMatrix4x4::Identity(*this->Element); this->Modified();} 00088 //BTX 00089 static void Identity(double Elements[16]); 00090 //ETX 00092 00094 00096 static void Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out) 00097 {vtkMatrix4x4::Invert(*in->Element,*out->Element); out->Modified(); } 00098 void Invert() 00099 { vtkMatrix4x4::Invert(this,this); } 00100 //BTX 00101 static void Invert(const double inElements[16], double outElements[16]); 00102 //ETX 00104 00105 00107 00108 static void Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out) 00109 {vtkMatrix4x4::Transpose(*in->Element,*out->Element); out->Modified(); } 00110 void Transpose() 00111 { vtkMatrix4x4::Transpose(this,this); } 00112 //BTX 00113 static void Transpose(const double inElements[16], double outElements[16]); 00114 //ETX 00116 00118 00120 void MultiplyPoint(const float in[4], float out[4]) 00121 {vtkMatrix4x4::MultiplyPoint(*this->Element,in,out); } 00122 void MultiplyPoint(const double in[4], double out[4]) 00123 {vtkMatrix4x4::MultiplyPoint(*this->Element,in,out); } 00125 00126 //BTX 00127 static void MultiplyPoint(const double Elements[16], 00128 const float in[4], float out[4]); 00129 static void MultiplyPoint(const double Elements[16], 00130 const double in[4], double out[4]); 00131 //ETX 00132 00134 00136 float *MultiplyPoint(const float in[4]) 00137 {return this->MultiplyFloatPoint(in); } 00138 float *MultiplyFloatPoint(const float in[4]) 00139 {this->MultiplyPoint(in,this->FloatPoint); return this->FloatPoint; } 00140 double *MultiplyDoublePoint(const double in[4]) 00141 {this->MultiplyPoint(in,this->DoublePoint); return this->DoublePoint; } 00143 00145 00146 static void Multiply4x4(const vtkMatrix4x4 *a, const vtkMatrix4x4 *b, vtkMatrix4x4 *c) { 00147 vtkMatrix4x4::Multiply4x4(*a->Element,*b->Element,*c->Element); }; 00148 //BTX 00149 static void Multiply4x4(const double a[16], const double b[16], 00150 double c[16]); 00151 //ETX 00153 00155 00156 void Adjoint(const vtkMatrix4x4 *in, vtkMatrix4x4 *out) 00157 {vtkMatrix4x4::Adjoint(*in->Element,*out->Element);} 00158 //BTX 00159 static void Adjoint(const double inElements[16], double outElements[16]); 00160 //ETX 00162 00164 00165 double Determinant() {return vtkMatrix4x4::Determinant(*this->Element);} 00166 //BTX 00167 static double Determinant(const double Elements[16]); 00168 //ETX 00170 00172 void SetElement(int i, int j, double value); 00173 00175 00176 double GetElement(int i, int j) const 00177 {return this->Element[i][j];} 00179 00180 //BTX 00181 double *operator[](const unsigned int i) 00182 {return &(this->Element[i][0]);} 00183 const double *operator[](unsigned int i) const 00184 { return &(this->Element[i][0]); } 00185 void Adjoint(vtkMatrix4x4 &in,vtkMatrix4x4 &out) 00186 {this->Adjoint(&in,&out);} 00187 double Determinant(vtkMatrix4x4 &in) 00188 {return this->Determinant(&in);} 00189 double Determinant(vtkMatrix4x4 *in) 00190 {return vtkMatrix4x4::Determinant(*in->Element);} 00191 void Invert(vtkMatrix4x4 &in,vtkMatrix4x4 &out) 00192 {this->Invert(&in,&out);} 00193 void Transpose(vtkMatrix4x4 &in,vtkMatrix4x4 &out) 00194 {this->Transpose(&in,&out);} 00195 static void PointMultiply(const double Elements[16], 00196 const float in[4], float out[4]); 00197 static void PointMultiply(const double Elements[16], 00198 const double in[4], double out[4]); 00199 //ETX 00200 00201 protected: 00202 vtkMatrix4x4() { vtkMatrix4x4::Identity(*this->Element); }; 00203 ~vtkMatrix4x4() {}; 00204 00205 float FloatPoint[4]; 00206 double DoublePoint[4]; 00207 private: 00208 vtkMatrix4x4(const vtkMatrix4x4&); // Not implemented 00209 void operator= (const vtkMatrix4x4&); // Not implemented 00210 }; 00211 00212 inline void vtkMatrix4x4::SetElement(int i, int j, double value) 00213 { 00214 if (this->Element[i][j] != value) 00215 { 00216 this->Element[i][j] = value; 00217 this->Modified(); 00218 } 00219 } 00220 00221 #endif 00222