[vtkusers] Slicing through volume about arbitraty vector

Arunachalam Kana Kana.Arunachalam at fh-wels.at
Tue Aug 17 07:49:30 EDT 2010


Hi Vtk User,

 

I want to slice through a volume about an arbitrary vector.

 

I give 2 points p1 and p2, from which i calculate the vector as shown below. I want to have the axial from point p1 In the direction of the vector. 

 

I do the following transformations: Translation to origin, rotation to make vector parallel to z axis, rotate about z axis and finally translate back to the p1 which leads to a 

Transformation matrix. Finally i apply the axial transform matrix to  the transformation matrix and get the transformation for axial view. I set the transform to my imagereslicer and

Update the imagereslicer and imageviewer. But I do not get any image as output and i don't know where is the mistake ? Can someone help me, I have copied the code below.

 

            

            normal[0] = p2[0]-p1[0];

            normal[1] = p2[1]-p1[1];

            normal[2] = p2[2]-p1[2];

            

            point[0] = p1[0]; point[1] = p1[1]; point[2] = p1[2];

            

            //transformation

            double t_matrix[16] = {1, 0, 0, 0, 

                                         0, 1, 0, 0, 

                                         0, 0, 1, 0, 

                                      -point[0], -point[1], -point[2], 1};

            vtkMatrix4x4 * translation_matrix = vtkMatrix4x4::New();

            translation_matrix->DeepCopy(t_matrix);

 

            //rotation to make vector parallel to the z axis

            double diagonal = sqrt (pow(normal[0],2) + pow(normal[1],2) + pow(normal[2],2) );

            double intermediate_dia = sqrt ( pow(normal[0],2) + pow(normal[1],2) );

            double cos_theta = normal[2] / diagonal;

            double sin_theta = intermediate_dia / diagonal;

            double r_matrix[16] = {cos_theta, 0, sin_theta, 0,  

                                               0, 1, 0, 0,  

                                               -sin_theta, 0, cos_theta, 0,  

                                               0, 0, 0, 1};

 

            vtkMatrix4x4 * rotation_matrix = vtkMatrix4x4::New();

            rotation_matrix->DeepCopy(r_matrix);

 

            //rotation in Z axis by 180 degree

            double cos_theta_z = cos(3.14159);

            double sin_theta_z = sin(3.14159);

            double r_matrix_z[16] = {    cos_theta_z, -sin_theta_z, 0, 0,  

                                                     sin_theta_z,  cos_theta_z, 0, 0,  

                                                     0, 0, 1, 0,  

                                                     0, 0, 0, 1};

            vtkMatrix4x4 * rotation_matrix_z = vtkMatrix4x4::New();

            rotation_matrix_z->DeepCopy(r_matrix_z);

 

            //translate back to object position

            double bt_matrix[16] = {1, 0, 0, 0, 

                                               0, 1, 0, 0, 

                                               0, 0, 1, 0, 

                                               point[0], point[1], point[2], 1};

            vtkMatrix4x4 * backtranslation_matrix = vtkMatrix4x4::New();

            backtranslation_matrix->DeepCopy(bt_matrix);

 

            //get the final transformation matrix to apply on the image

            vtkMatrix4x4 * intermediate_transformation_1 = vtkMatrix4x4::New();

            vtkMatrix4x4 * intermediate_transformation_2 = vtkMatrix4x4::New();

            vtkMatrix4x4 * final_transformation_matrix = vtkMatrix4x4::New();

            vtkMatrix4x4::Multiply4x4(translation_matrix, rotation_matrix, intermediate_transformation_1);

            vtkMatrix4x4::Multiply4x4(intermediate_transformation_1, rotation_matrix_z, intermediate_transformation_2); 

            vtkMatrix4x4::Multiply4x4(intermediate_transformation_2, backtranslation_matrix, final_transformation_matrix);

 

            double a_matrix[16] = { 1, 0, 0, 0, 

                                   0, 1, 0, 0, 

                                   0, 0, 1, 0, 

                                   0, 0, 0, 1};

            vtkMatrix4x4 * axial_matrix = vtkMatrix4x4::New();

            axial_matrix->DeepCopy(a_matrix);

            vtkMatrix4x4 * axial_transformation_matrix = vtkMatrix4x4::New();

            vtkMatrix4x4::Multiply4x4(final_transformation_matrix, axial_matrix, axial_transformation_matrix);

 

            vtkMatrixToLinearTransform  * axial_transform = vtkMatrixToLinearTransform ::New();

            axial_transform->SetInput(axial_transformation_matrix);

            axial_transform->Update();

 

            vtkImageReslice* Imagereslicer = vtkImageReslice::New();

            Imagereslicer->SetResliceTransform(axial_transform);

Imagereslicer-> SetResliceAxesOrigin (0, 0, point[2]);     

            Imagereslicer->Update();

vtkImageViewer2 * Imageviewer = vtkImageViewer2::New();

Imageviewer ->SetInput(Imagereslicer->GetOutput() );

            Imageviewer->UpdateDisplayExtent();

            Imageviewer()->Render();

            Imageviewer->Update();

                        

Regards, 

Kana Arunachalam Kannappan

Research Associate

FH OÖ Forschungs & Entwicklungs GmbH

Stelzhamer Strasse 23,

4600 Wels,

Austria.

Phone: +43 (0)7242 72811 -4420

kana.arunachalam at fh-wels.at

www.fh-ooe.at; www.3dct.at

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100817/143d3800/attachment.htm>


More information about the vtkusers mailing list