[vtkusers] Drawing an image mask per slice on top of VtkImageViewer2 for a 3D data set

Dan Liew delcypher at gmail.com
Sat Mar 3 06:06:17 EST 2012


On 02/03/12 19:33, Delcypher wrote:
> Well I tried using two "VtkImageViewer2"s the program crashed. So
> I tried the approach in the example and added another actor to the 
> renderer. It is sort of working but for some reason the slices are
> not correctly lining up in the XY plane despite the actors both
> sharing the same origin.
> 
> Here's a screenshot illustrating what I see 
> http://www.doc.ic.ac.uk/~dsl11/simi-qt.png
> 
> The green square should be lined on top of the "blackish" image 
> underneath it. Instead the bottom corner of the "mask" is aligned
> with the centre of the "original" image in the XY plane.
> 
> Here is the code if anyone wishes to see it 
> https://github.com/delcypher/simi-qt/blob/restructure/src/viewmanager.cpp
>
>  Does anyone know what's wrong?
> 
> 
> On 2 March 2012 15:42, Delcypher <delcypher at gmail.com> wrote:
>> Hi, I have two 3D data sets
>> 
>> VtkStructuredPoints  named "original" of dimensions
>> [512x512x120] VtkStructuredPoints named "mask" of dimensions
>> [512x512x120]
>> 
>> I'm currently using the VtkImageViewer2 class to view a slice at
>> a time of the image "original" and this seems to be working
>> quite nicely.
>> 
>> What I want is to have an image mask that is drawn on top of the 
>> "original" image for each slice. I want the mask to come from
>> "mask" i.e. for every slice in "original" there is one
>> corresponding mask for that slice in "mask". When I switch slice
>> using imageViewer I need a way to make sure that the
>> corresponding mask from "mask" is drawn on the newly displayed
>> slice.
>> 
>> I started looking at 
>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/Transparency
>> which is a good example but it is only for 2D images.
>> 
>> I took a look at the source code for VtkImageViewer2 and I think
>> it does the following...
>> 
>> 1. Place the entire 3D image in the world co-ordinate system and
>> place the camera outside of this. 2. To select a particular slice
>> VtkImageViewer2 seems to call SetDisplayExtent(x_min , x_max,
>> y_min, y_max,  NEWSLICE_NUMBER, NEWSLICE_NUMBER) on its Actor so
>> that only the relevant slice is visible (assuming slices are
>> arranged along the Z-axis). I presume that these co-ordinates are
>> local to the actor and are not world co-ordinates, is that
>> correct?
>> 
>> I'm quite happy to call SetDisplayExtent() myself on the
>> VtkImageActor for my "mask" image so that the right slice is used
>> but what I'm really unsure of is.... Where do I put the
>> VtkImageActor for my "mask" image in the world co-ordinate system
>> so everything works (i.e. the mask's slices line up perfectly for
>> all slices)??
>> 
>> I consider placing the "mask" image Actor completely outside the
>> block of data for "original" but I have a strong suspicion this
>> won't work because VtkImageViewer2 adjusts the cliping planes of
>> the Active Camera of the renderer everytime the slice is changed
>> so my "mask" may be outside the clipping planes.
>> 
>> Or could I just place "mask" directly on top of "original" in
>> the world co-ordinate system?
>> 
>> Or better yet could I use a second VtkImageViewer2 for my "mask"
>> image and have both "VtkImageViewer2"s use the same renderer?
>> 
>> What's the best approach?
>> 
>> Regards,
>> 
>> Dan Liew.
Well managed to fix it on my own. It turns out that the
VTKStructuredPoints Image I'm loading has a weird origin which is
different from the default. So I just copied the origin from my
original image to the mask image and it worked correctly.

So in C++ code I now do...

mask = vtkStructuredPoints::New();
	mask->SetExtent(original->GetExtent());
	mask->SetSpacing(original->GetSpacing());
	mask->SetNumberOfScalarComponents(1);
	mask->SetOrigin(original->GetOrigin()); //IMPORTANT!



More information about the vtkusers mailing list