[vtkusers] Difficulty keeping volume within vtkBoxWidget

Zamir Khan zkhan at modusmed.com
Tue Dec 8 09:15:07 EST 2009


Thanks for the response. I would like to continue to allow rotation, 
could I perhaps apply an inverse of the box transform to its bounds and 
then use that for cropping? Also, the reason that translation fails, I 
believe, is that when you grow or shrink one of the faces of the box, 
this appears to be a scaling & translation operation and, perhaps 
because I am always negating the scaling operation in my transform on 
the volume, by moving the faces of the box back and forth, I can get the 
volume to leave the bounds of the box.

I will keep trying some different solutions (unfortunately disabling 
rotation is not an acceptable one for my application), but if anyone has 
accomplished this task before (with or without a vtkBoxWidget!) - 
example code would be much appreciated.

Thanks,
Zamir

Karthik Krishnan wrote:
> On Mon, Dec 7, 2009 at 5:26 PM, Zamir Khan <zkhan at modusmed.com> 
> <mailto:zkhan at modusmed.com%3E> 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