[vtkusers] vtkImplicitPlaneWidget2

Sebastian Gatzka sebastian.gatzka at stud.tu-darmstadt.de
Fri Mar 12 05:22:12 EST 2010


Ok. Here we go with some code.

This is the callback class

// Callback for the interaction
// This does the actual work: updates the vtkPlane implicit function.
// This in turn causes the pipeline to update and clip the object.
class vtkIPWCallback : public vtkCommand
{
public:
   static vtkIPWCallback *New()
     { return new vtkIPWCallback; }
   virtual void Execute(vtkObject *caller, unsigned long, void*)
     {
     vtkImplicitPlaneWidget2 *planeWidget =
       reinterpret_cast<vtkImplicitPlaneWidget2*>(caller);
     vtkImplicitPlaneRepresentation *rep =
       
reinterpret_cast<vtkImplicitPlaneRepresentation*>(planeWidget->GetRepresentation());
     rep->GetPlane(this->Plane);
     }

   vtkIPWCallback():Plane(0),Actor(0) {}

   vtkPlane *Plane;
   vtkActor *Actor;

  };

This is the cutting plane and its actor the callback will access:

// Cutting-Plane
vtkPlane *plane = vtkPlane::New();

vtkCutter *planeCut = vtkCutter::New();
planeCut->SetInput(sGrid);
planeCut->SetCutFunction(plane);

vtkPolyDataMapper *cutMapper = vtkPolyDataMapper::New();
cutMapper->SetInputConnection(planeCut->GetOutputPort());
cutMapper->SetScalarRange( sGrid->GetCellData()->GetScalars()->GetRange() );

vtkActor *cutActor = vtkActor::New();
cutActor->SetMapper(cutMapper);


The rest is just like in the example

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);


// 1. implicit plane representation
vtkImplicitPlaneRepresentation *iPlaneRepresentation = 
vtkImplicitPlaneRepresentation::New();
iPlaneRepresentation->SetPlaceFactor(1.0); // This must be set prior to 
placing the widget
iPlaneRepresentation->PlaceWidget(sGrid->GetBounds());
iPlaneRepresentation->SetNormal(0,0,1);
iPlaneRepresentation->SetOrigin(sGrid->GetCenter());
iPlaneRepresentation->SetOutlineTranslation(0);
iPlaneRepresentation->SetDrawPlane(0);

// 2. Callback:
vtkIPWCallback *myCallback = vtkIPWCallback::New();
myCallback->Plane = plane;
myCallback->Actor = cutActor;

// 3. ImplicitPlaneWidget
vtkImplicitPlaneWidget2 *iPlane = vtkImplicitPlaneWidget2::New();
iPlane->SetInteractor(iren);
iPlane->SetRepresentation(iPlaneRepresentation);
iPlane->AddObserver(vtkCommand::InteractionEvent,myCallback);

iren->Start();

So when pressing "i" the plane is displayed but I need to to some 
interaction with it before it displays anything.

Am 10.03.2010 23:05, schrieb Eric E. Monson:
> Hey again,
>
> Somehow it seems like this would have more to do with how your code is dealing with the plane and the cutting rather than an inherent property of the widget itself. This is sort of the natural VTK behavior, though, since some part of the pipeline needs to explicitly force the pipeline to Update, and it sounds like there's nothing that's forcing that to happen when the widget is made visible. Maybe if you post a piece of your code someone will have some ideas.
>
> -Eric
>
>
> On Mar 10, 2010, at 7:36 AM, Sebastian Gatzka wrote:
>
>    
>> Hi again (sorry, this is a busy day for the list)
>>
>> Is there a way of telling the vtkImplicitPlaneWidget2 to display the cutting data right from the beginning?
>> In my code the plane is displaying nothing after I press the key "i".
>> Just as I do a first manipulation, like moving, rotating or translating there is an update to the plane.
>>
>> Sebastian
>>
>>
>> _______________________________________________
>> 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 HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100312/67c84d97/attachment.htm>


More information about the vtkusers mailing list