[vtkusers] BoxWidget + VolumeMapper errors

David Gobbi dgobbi at imaging.robarts.ca
Thu May 27 15:32:11 EDT 2004


Hi Dean,

The old "GetPlane() always returns the same object" kind of problem
is pervasive in VTK.

A vtkPlanes object has exactly one Plane, and when you call GetPlane(i),
it simply sets the Normal and Origin of that plane as appropriate, and
then returns it.  This is what caused the problem you were seeing.

Digging a bit deeper, this problem did not occur in VTK 4.2, since back
then GetPlane() would create a new plane via vtkPlane::New(), and then
return that new plane after setting the Origin and Normal.  Of course,
returning a New'ly created object results in a memory leak.

The solution would be for vtkPlanes to have a different internal plane
for each index i (any volunteers?).

Note that vtkPolyData::GetCell() has the same problem, as do a multitude
of vtk Get methods.

It's generally safe to assume, for any Get(int i) method that returns a
vtkObject, that the same object instance will be returned for all values
of i, unless you are Get'ing the object from some sort of collection.
Read the source whenever you're not certain.

Also, Dean, note that as Mathieu said, you can simplify your code
by just doing

box->GetPlanes(planes);
mapper->SetClippingPlanes(planes);

Cheers,
 - David


On Thu, 27 May 2004, Dean Inglis wrote:

> Okay, here is what works (not elegant but hey!)
>
> <snip>
> virtual void Execute(vtkObject *caller, unsigned long, void*)
>   {
>   vtkBoxWidget *box = reinterpret_cast<vtkBoxWidget*>(caller);
>   box->GetPlanes( planes );
>   mapper->RemoveAllClippingPlanes();
>   for (int i = 0; i<planes->GetNumberOfPlanes(); i++ )
>     {
>     vtkPlane* newplane = vtkPlane::New();
>     newplane->SetOrigin( planes->GetPlane(i)->GetOrigin() );
>     newplane->SetNormal( planes->GetPlane(i)->GetNormal() );
>     mapper->AddClippingPlane( newplane );
>     newplane->Delete();
>     }
>   }
> <snip>
>
> So, I think vtkPlanes needs udpated documentation/cautionary warning
> and perhaps vtkAbstractMapper should be modified?
>
> Dean
>
> >	why don't you simply use:
>
> >void vtkAbstractMapper::SetClippingPlanes( vtkPlanes * planes )
>
> >	This seems to be much easier to use, right ?
>
> >HTH
> >Mathieu
>
>
> dean.inglis at camris.ca wrote:
> > I am trying to use vtkBoxWidget with a callback to send its vtkPlanes
> > to a vtkVolumeMapper as in
> > VTK/Examples/GUI/Tcl/VolumeRenderWithBoxWidget.tcl
> > Apparently, I should be passing in a vtkPlaneCollection, so I tried
> > modifying my callback:
> >
> > class vtkBWCallback : public vtkCommand
> > {
> > public:
> >   static vtkBWCallback *New()
> >     { return new vtkBWCallback; }
> >
> >   virtual void Execute(vtkObject *caller, unsigned long, void*)
> >     {
> >       vtkBoxWidget *box = reinterpret_cast<vtkBoxWidget*>(caller);
> >       box->GetPlanes( planes);
> >       collection->RemoveAllItems();
> >       for (int i = 0; i < planes->GetNumberOfPlanes(); i++)
> >         {
> >         collection->AddItem( planes->GetPlane(i) );
> >         }
> >       mapper->SetClippingPlanes( collection );
> >     }
> >   vtkBWCallback():planes(0),mapper(0),pc(0){};
> >
> >   vtkPlanes* planes;
> >   vtkPlaneCollection* collection;
> >   vtkVolumeTextureMapper2D* mapper;
> > };
> >
> > no luck!
> >
> > I only get one plane acting as a clipping plane in both my .cxx app
> >  and in the above VTK tcl example.  The plane with unit normal
> > originally in the +z direction is the only valid plane.
> > Can anyone else verify this error?  This is seen on two builds:
> >
> > 1) Borland C++ Builder vers. 5 , Win 2k Pro, Pentium 4,
> > NVIDIA GeForce4 Ti 4400, driver 5.3.0.3, CMake 2.0.0, latest VTK cvs
> >
> > 2) Borland C++ Builder vers. 6 , Win 2k Pro, Pentium 4 mobile,
> > NVIDIA Quadro4 500 GoGL,  driver 2.9.4.0, CMake 2.0.0, latest VTK cvs
> >
> > Dean
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq>
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
>
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>





More information about the vtkusers mailing list