[vtkusers] SetCutPlane not working in vtkImageResliceMapper

David Gobbi david.gobbi at gmail.com
Fri Jan 25 18:51:38 EST 2013


On Fri, Jan 25, 2013 at 4:30 PM, Debjit Ghosh <dghosh at chla.usc.edu> wrote:
> 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?

The use of "dimX/2" etc. looks suspicious to me because that will only
give you the center if your image Spacing is 1.0 and your image Origin
is 0.0.  Usually the center of the volume cannot be computed so
simplistically.

On the programming side, you have declared "normal" as a local
variable even though it is also a member of your class.

That is all that I have time to check... this month has been very busy
for me (and next month will be the same).

 - David



More information about the vtkusers mailing list