[vtkusers] SetCutPlane not working in vtkImageResliceMapper
Debjit Ghosh
dghosh at chla.usc.edu
Fri Jan 25 18:30:49 EST 2013
Hi David,
In order to implement what you had suggested (as a refresher to what my goal
is, in your own words which best explain it: I am trying to extract oblique
slices from a cone-shaped (or pyramid-shaped) 3D ultrasound volume, and then
show them on the screen. On the screen, they will look a lot like regular
2D B-mode ultrasound images), here is my code to do so:
if(event == vtkCommand::KeyPressEvent)
{
std::string key = interactor->GetKeySym();
if(key == "a" && this->azimuth < 180)
{
this->azimuth += 1;
}
else if(key == "z" && this->azimuth > -180)
{
this->azimuth -= 1;
}
else if(key == "s" && this->elevation < 90)
{
this->elevation += 1;
}
else if(key == "x" && this->elevation > -90)
{
this->elevation -= 1;
}
else if(key == "d" && this->roll < 180)
{
this->roll += 1;
}
else if(key == "c" && this->roll > -180)
{
this->roll -= 1;
}
//Slicing algorithm:
vtkSmartPointer<vtkPlane> sliceplane =
vtkSmartPointer<vtkPlane>::New();
sliceplane = resliceMapper->GetSlicePlane();
//Calculate the position of the camera
double normal[3];
double position[3];
double norm[3];
norm[0] = 0;
norm[1] = 0;
norm[2] = 1;
vtkSmartPointer<vtkCamera> cam = ren->GetActiveCamera();
this->normal[0] = cos(Deg_to_Rad(azimuth)) *
cos(Deg_to_Rad(elevation)) * norm[0] +
(cos(Deg_to_Rad(azimuth)) * sin(Deg_to_Rad(elevation)) *
sin(Deg_to_Rad(roll))) - (sin(Deg_to_Rad(azimuth))*cos(Deg_to_Rad(roll))) *
norm[1] +
(cos(Deg_to_Rad(azimuth)) * sin(Deg_to_Rad(elevation)) *
cos(Deg_to_Rad(roll))) + (sin(Deg_to_Rad(azimuth)) * sin(Deg_to_Rad(roll)))
* norm[2];
this->normal[1] = sin(Deg_to_Rad(azimuth)) *
cos(Deg_to_Rad(elevation)) * norm[0] +
(sin(Deg_to_Rad(azimuth)) * sin(Deg_to_Rad(elevation)) *
sin(Deg_to_Rad(roll))) + (cos(Deg_to_Rad(azimuth))*cos(Deg_to_Rad(roll))) *
norm[1] +
(sin(Deg_to_Rad(azimuth)) * sin(Deg_to_Rad(elevation)) *
cos(Deg_to_Rad(roll))) - (cos(Deg_to_Rad(azimuth)) * sin(Deg_to_Rad(roll)))
* norm[2];
this->normal[2] = -sin(Deg_to_Rad(elevation)) * norm[0] +
cos(Deg_to_Rad(elevation)) * sin(Deg_to_Rad(roll)) * norm[1]
+
cos(Deg_to_Rad(elevation)) * cos(Deg_to_Rad(roll)) *
norm[2];
//Calculate the focal point
double focalPt[3];
double centerofvol[] = {dimX/2, dimY/2, dimZ/2};
vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
plane->SetOrigin(dimX/2, dimY/2, 0);
plane->SetNormal(this->normal);
plane->ProjectPoint( centerofvol, focalPt );
position[0] = focalPt[0] + distfromcam * this->normal[0];
position[1] = focalPt[1] + distfromcam * this->normal[1];
position[2] = focalPt[2] + distfromcam * this->normal[2];
cam->SetPosition(position);
cam->SetViewUp(0, 0, -1);
cam->SetFocalPoint(focalPt);
renderer->ResetCameraClippingRange();
interactor->Render();
}
Is there anything here that is standing out/grossly incorrect?
Thanks,
Debjit
--
View this message in context: http://vtk.1045678.n5.nabble.com/SetCutPlane-not-working-in-vtkImageResliceMapper-tp5716627p5718113.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list