#include"math.h" #include"matrixRotation.h" //------------------------------------------------------------------------------------------- matrixRotation::matrixRotation() { spcX = 1; spcY = 1; spcZ = 1; orgX = 0; orgY = 0; orgZ = 0; vec1X = 1; vec1Y = 0; vec1Z = 0; vec2X = 0; vec2Y = 1; vec2Z = 0; } //------------------------------------------------------------------------------------------- matrixRotation::~matrixRotation() { } void matrixRotation::CrossProduct(double *vecZx, double *vecZy, double *vecZz) { *vecZx = vec1Y * vec2Z - vec1Z * vec2Y; *vecZy = vec1Z * vec2X - vec1X * vec2Z; *vecZz = vec1X * vec2Y - vec1Y * vec2X; } //------------------------------------------------------------------------------------------- void matrixRotation::GetTransformation(vtkTransform *transform) { double dst_nrm_dircos_x; double dst_nrm_dircos_y; double dst_nrm_dircos_z; //http://www.dclunie.com/medical-image-faq/html/part2.html CrossProduct( &dst_nrm_dircos_x , &dst_nrm_dircos_y , &dst_nrm_dircos_z ); vtkMatrix4x4 *mat = vtkMatrix4x4::New(); mat->SetElement(0,0,vec1X); mat->SetElement(1,0,vec1Y); mat->SetElement(2,0,vec1Z); mat->SetElement(3,0,0); mat->SetElement(0,1,vec2X); mat->SetElement(1,1,vec2Y); mat->SetElement(2,1,vec2Z); mat->SetElement(3,1,0); mat->SetElement(0,2,dst_nrm_dircos_x); mat->SetElement(1,2,dst_nrm_dircos_y); mat->SetElement(2,2,dst_nrm_dircos_z); mat->SetElement(3,2,0); mat->SetElement(0,3,0); mat->SetElement(1,3,0); mat->SetElement(2,3,0); mat->SetElement(3,3,1); transform->PostMultiply (); transform->Identity(); transform->Scale(spcX,spcY,spcZ); transform->Update(); transform->Concatenate(mat); transform->Update(); transform->Translate(orgX,orgY,orgZ); transform->Update(); } //------------------------------------------------------------------------------------------- void matrixRotation::SetSpacing(double spcX,double spcY, double spcZ) { this->spcX = spcX; this->spcY = spcY; this->spcZ = spcZ; } //------------------------------------------------------------------------------------------- void matrixRotation::SetOrigin(double orgX,double orgY, double orgZ) { this->orgX = orgX; this->orgY = orgY; this->orgZ = orgZ; } //------------------------------------------------------------------------------------------- void matrixRotation::SetVector1(double vX,double vY, double vZ) { double nor=sqrt(vX*vX + vY*vY + vZ*vZ); this->vec1X = vX/nor; this->vec1Y = vY/nor; this->vec1Z = vZ/nor; } //------------------------------------------------------------------------------------------- void matrixRotation::SetVector2(double vX,double vY, double vZ) { double nor=sqrt(vX*vX + vY*vY + vZ*vZ); this->vec2X = vX/nor; this->vec2Y = vY/nor; this->vec2Z = vZ/nor; }