[vtkusers] vtkImplicitPlaneWidget2

Eric E. Monson emonson at cs.duke.edu
Fri Mar 12 11:01:23 EST 2010


Hey Christian,

I played around with some of this in Python, so hopefully it will translate okay... I think you need to do two things. First, make a call to 

iPlaneRepresentation->GetPlane(plane);

right after you set up and place the representation. This will make sure that the cut plane is the right one even before the callback is executed. 

Secondly, I think you might be able to get your cut to show up right away if you start with cutActor->VisibilityOff(); and then add an observer on the main interactor for a KeyPress event and then look for the "i" key press. When you see it, it should make the widget appear as usual, but in the callback for your KeyPress event, if you see an "i" then set the cutActor->VisibilityOn();

If this doesn't work then someone who's better with the event system had better try to help you out.

Talk to you later,
-Eric


On Mar 12, 2010, at 5:22 AM, Sebastian Gatzka wrote:

> 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
>>>     
>> 
>>   
> _______________________________________________
> 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/c52672b3/attachment.htm>


More information about the vtkusers mailing list