[vtkusers] Difficulty keeping volume within vtkBoxWidget

Zamir Khan zkhan at modusmed.com
Thu Dec 10 17:12:49 EST 2009


I think I have found a solution to my problem and, although it does not 
feel elegant (it's actually rather ugly), I am posting back to the 
mailing list for archival purposes, in case someone else is trying to 
accomplish a similar goal.

To recap: I have a volume, which I want to allow the user to 
interactively crop. So I used a vtkBoxWidget to bound the volume and was 
intending to use the bounds of the box as the cropping planes. The 
simplistic approach in my first post did not work, in retrospect because 
I was operating on a false assumption: that when I associated the volume 
actor and box widget with each other, they would be anchored about the 
center of the box widget. The reason I assumed this was that when I 
rotated the box, I saw that the volume rotated with it, seemingly about 
the center of the box. However, further investigation showed me that my 
objects were actually anchored to another position and that, when 
certain actions happened to the box (scaling, translation induced by 
scaling of the individual box faces), if I wanted to see my desired 
behaviour, I needed to re-position the volume to maintain a constant 
positioning between the center of the box and the volume.

I have attached the callback code I used to accomplish this with some 
comments. This is the callback that gets invoked on the boxWidget's 
InteractionEvt. The objects and helper methods are hopefully named 
reasonably enough to figure out what they are/do (e.g. I call my 
vtkBoxWidget a croppingBox). It's not a pretty solution and I'm 
half-expecting a response with a much easier and more elegant way to do 
this. If so, I would love to be enlightened and, regardless, it's been a 
good learning experience =)

Zamir Khan wrote:
> I should add: even purely scaling the box to a smaller size, with the
> right mouse button, will cause the volume to leave the box. It seems
> that they are not centered on the same point. I have verified that the
> volume remains in place - both position and origin remain at (0,0,0) -
> is it possible that the box's scaling is not centered on (0,0,0), even
> though it was bounded to the volume through SetProp3D()?
>
> Zamir Khan wrote:
> > 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>
> > <mailto:zkhan at modusmed.com%3E> <mailto:zkhan at modusmed.com%3E%3E>
> > > <mailto:zkhan at modusmed.com%3E> <mailto:zkhan at modusmed.com%3E%3E> 
> <mailto:zkhan at modusmed.com%3E%3E> <mailto:zkhan at modusmed.com%3E%3E%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..
> > > 
> ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> > ------------------------------------------------------------------------
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: 
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> ------------------------------------------------------------------------
>

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CroppingBoxWidgetTransformCallback.cs
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091210/5664efa2/attachment.txt>


More information about the vtkusers mailing list