2 #include"matrixRotation.h"
4 //-------------------------------------------------------------------------------------------
5 matrixRotation::matrixRotation()
23 //-------------------------------------------------------------------------------------------
24 matrixRotation::~matrixRotation()
28 void matrixRotation::CrossProduct(double *vecZx, double *vecZy, double *vecZz)
30 *vecZx = vec1Y * vec2Z - vec1Z * vec2Y;
31 *vecZy = vec1Z * vec2X - vec1X * vec2Z;
32 *vecZz = vec1X * vec2Y - vec1Y * vec2X;
35 //-------------------------------------------------------------------------------------------
36 void matrixRotation::GetTransformation(vtkTransform *transform)
38 double dst_nrm_dircos_x;
39 double dst_nrm_dircos_y;
40 double dst_nrm_dircos_z;
41 //http://www.dclunie.com/medical-image-faq/html/part2.html
42 CrossProduct( &dst_nrm_dircos_x , &dst_nrm_dircos_y , &dst_nrm_dircos_z );
43 vtkMatrix4x4 *mat = vtkMatrix4x4::New();
45 mat->SetElement(0,0,vec1X);
46 mat->SetElement(1,0,vec1Y);
47 mat->SetElement(2,0,vec1Z);
48 mat->SetElement(3,0,0);
50 mat->SetElement(0,1,vec2X);
51 mat->SetElement(1,1,vec2Y);
52 mat->SetElement(2,1,vec2Z);
53 mat->SetElement(3,1,0);
55 mat->SetElement(0,2,dst_nrm_dircos_x);
56 mat->SetElement(1,2,dst_nrm_dircos_y);
57 mat->SetElement(2,2,dst_nrm_dircos_z);
58 mat->SetElement(3,2,0);
60 mat->SetElement(0,3,0);
61 mat->SetElement(1,3,0);
62 mat->SetElement(2,3,0);
63 mat->SetElement(3,3,1);
65 transform->PostMultiply ();
66 transform->Identity();
67 transform->Scale(spcX,spcY,spcZ);
69 transform->Concatenate(mat);
71 transform->Translate(orgX,orgY,orgZ);
76 //-------------------------------------------------------------------------------------------
77 void matrixRotation::SetSpacing(double spcX,double spcY, double spcZ)
84 //-------------------------------------------------------------------------------------------
85 void matrixRotation::SetOrigin(double orgX,double orgY, double orgZ)
92 //-------------------------------------------------------------------------------------------
93 void matrixRotation::SetVector1(double vX,double vY, double vZ)
95 double nor=sqrt(vX*vX + vY*vY + vZ*vZ);
101 //-------------------------------------------------------------------------------------------
102 void matrixRotation::SetVector2(double vX,double vY, double vZ)
104 double nor=sqrt(vX*vX + vY*vY + vZ*vZ);
105 this->vec2X = vX/nor;
106 this->vec2Y = vY/nor;
107 this->vec2Z = vZ/nor;