[vtkusers] reslice using an arbitrary orientation

zandarina esmeralda.ruiz at alma3d.com
Mon Mar 25 15:08:19 EDT 2019

Dear all

I want to reslice a 3d volume computing the perpendicular
between two points x and y. I compute the
perpendicular berween point 1, point2 in x and y (z is the same for all
points as the 
poins are obtained of one slice)

And then i compute the perpendicular of x and y
And i compute the rotation. And i get a blank image. I would like to
cut the slice cutting through the perpendicular of those two points.

I attach the code. Is there something wrong

Any help?

Thanks in advance

  double vt[3];
        vt[0] = pts2[0] - pts1[0];
        vt[1] = pts2[1] - pts1[1];
        vt[2] = pts2[2] - pts1[2]; // it will be 0 as z is the same in all
        double perpendicular[3] = { -vt[1],vt[0],0 };

        double startPoint[3], endPoint[3];
        startPoint[0] = tar_cen[0];
        startPoint[1] = tar_cen[1];
        startPoint[2] = tar_cen[2];
        endPoint[0] = startPoint[0] + perpendicular[0];
        endPoint[1] = startPoint[1] + perpendicular[1];
        endPoint[2] = startPoint[2] + perpendicular[2];

        // Compute a basis
        double normalizedX[3];
        double normalizedY[3];
        double normalizedZ[3];

        // The X axis is a vector from start to end
        vtkMath::Subtract(endPoint, startPoint, normalizedX);
        //double length = vtkMath::Norm(normalizedX);

        // The Z axis is an arbitrary vector cross X
        double arbitrary[3];
        arbitrary[0] = vtkMath::Random(-10, 10);
        arbitrary[1] = vtkMath::Random(-10, 10);
        arbitrary[2] = vtkMath::Random(-10, 10);
        vtkMath::Cross(normalizedX, arbitrary, normalizedZ);

        // The Y axis is Z cross X
        vtkMath::Cross(normalizedZ, normalizedX, normalizedY);
        vtkSmartPointer<vtkMatrix4x4> matrix =

        // Create the direction cosine matrix
        for (unsigned int i = 0; i < 3; i++)
            matrix->SetElement(i, 0, normalizedX[i]);
            matrix->SetElement(i, 1, normalizedY[i]);
            matrix->SetElement(i, 2, normalizedZ[i]);

        // Apply the transforms
        vtkSmartPointer<vtkTransform> transform =


        //Step 3: done

Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html

More information about the vtkusers mailing list