[vtkusers] Difficulty keeping volume within vtkBoxWidget

Zamir Khan zkhan at modusmed.com
Mon Dec 7 17:26:54 EST 2009


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.

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?

My hunch is that both of these problems are tied to the same issue, 
which is my lack of understanding of the relative positioning of the 
volume and the vtkBoxWidget. I tried several solutions, which at a high 
level involved trying to reposition the volume or the box to agree with 
the position of the other, but none of these attempts brought the 
desired results, so I'm reaching out to the experts!

Thanks in advance,
Zamir

-- 
Zamir Khan
Modus Medical Devices
e-mail: zkhan at modusmed.com




More information about the vtkusers mailing list