# [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?

double vt;
vt = pts2 - pts1;
vt = pts2 - pts1;
vt = pts2 - pts1; // it will be 0 as z is the same in all
points
double perpendicular = { -vt,vt,0 };

double startPoint, endPoint;
startPoint = tar_cen;
startPoint = tar_cen;
startPoint = tar_cen;
endPoint = startPoint + perpendicular;
endPoint = startPoint + perpendicular;
endPoint = startPoint + perpendicular;

// Compute a basis
double normalizedX;
double normalizedY;
double normalizedZ;

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

// The Z axis is an arbitrary vector cross X
double arbitrary;
arbitrary = vtkMath::Random(-10, 10);
arbitrary = vtkMath::Random(-10, 10);
arbitrary = vtkMath::Random(-10, 10);
vtkMath::Cross(normalizedX, arbitrary, normalizedZ);
vtkMath::Normalize(normalizedZ);

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

// Create the direction cosine matrix
matrix->Identity();
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 =
vtkSmartPointer<vtkTransform>::New();
transform->Translate(startPoint);
transform->Concatenate(matrix);

reslice->SetResliceTransform(transform);

//Step 3: done
reslice->Update();

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