[vtkusers] Difficulty keeping volume within vtkBoxWidget

Karthik Krishnan karthik.krishnan at kitware.com
Tue Dec 8 07:32:31 EST 2009


On Mon, Dec 7, 2009 at 5:26 PM, Zamir Khan <zkhan at modusmed.com> wrote:
> Hi all,
>
> I have been attempting to use a vtkBoxWidget for what appears to be a fairly
> common task: bounding and cropping a volume. My end goal is to have the all
> user actions (translation, rotation) on the box be passed onto the volume
> within, except for scaling. When the box is scaled, I need the volume within
> to remain the same size, but be cropped by the planes of the box.
>
> I have been attempting to accomplish this with the following code (C#
> snippets, using Activiz.NET personal edition):
>
>      // this callback gets called on the vtkBoxWidget's (outlineBox)
> InteractionEvt
>       private void transformCallback( vtkObject sender, vtkObjectEventArgs e
> )
>       {
>           vtkTransform boxTransform = vtkTransform.New();
>           outlineBox.GetTransform( boxTransform );
>
>           // remove the scaling from the transform before passing it on
>           double[] scale = boxTransform.GetScale();
>           boxTransform.Scale( 1.0 / scale[ 0 ], 1.0 / scale[ 1 ], 1.0 /
> scale[ 2 ] );
>           volume.SetUserTransform( ( vtkLinearTransform ) boxTransform );
>
>           // crop the volume
>           vtkPlanes planes = vtkPlanes.New();
>           outlineBox.GetPlanes(planes);
>           double[] bounds = planes.GetPoints().GetBounds();
> volumeMapper.SetCroppingRegionPlanes( bounds[ 0 ], bounds[ 1 ], bounds[ 2 ],
> bounds[ 3 ], bounds[ 4 ], bounds[ 5 ] );             }
>
> Now, a few things go wrong with this (probably over-simplified)
> implementation.
>
> 1) The volume does not stay within the box for all manipulations. I have
> tried various approaches to remedy this, including not allowing translation
> on the box (which is not critical to my application), but even so, I have
> not been able to come up with a solution that guarantees that the volume
> stays inside the box.

See answer to (2) below..


>
> 2) The cropping does not always occur on the expected plane. When I take a
> particular plane on the box and shrink the box w.r.t. that plane, especially
> after having rotated the box, the volume will be cropped, but on it's
> corresponding plane. It appears that the "bounds" coordinates of the box
> that I am passing to the mapper are not in agreement with the volume - am I
> missing a transformation?

The bounds specified via
  volumeMapper.SetCroppingRegionPlanes()

specify an axis-aligned aligned bounding box. You mention below that
they are out of sync after rotating the box, which is natural, since
the box widget no longer remains axis-aligned. Disable rotation on it.

Translation should have worked just fine.. Perhaps a bug in your code..



More information about the vtkusers mailing list