[vtkusers] vtkImplicitPlaneWidget2

Eric E. Monson emonson at cs.duke.edu
Fri Mar 19 09:22:49 EDT 2010


It really seems like your cut plane should show up right away if you set up your cutter, then set up the plane representation (VisibilityOn() for actor and rep), and then get the plane from the representation that's used in the cut, and then update the pipeline (Render() the window). That doesn't work?

I'll include a python script that shows the cutting plane and plane widget right from the beginning (the callback for InteractionEvent is just for moving the plane). I would assume the same sort of thing should work in C++. (Sorry for the bad variable names -- I was cutting and pasting from a couple pieces of code.)

-Eric

# ================
#!/usr/bin/env python

import vtk

# Create a mace out of filters.
rt = vtk.vtkRTAnalyticSource()
rt.SetWholeExtent(-3,3,-3,3,-3,3)
rt.Update()

maceMapper = vtk.vtkDataSetMapper()
maceMapper.SetInputConnection(rt.GetOutputPort())

maceActor = vtk.vtkActor()
maceActor.SetMapper(maceMapper)
maceActor.VisibilityOn()

# This portion of the code clips the mace with the vtkPlanes
# implicit function. The clipped region is colored green.
plane = vtk.vtkPlane()
clipper = vtk.vtkCutter()
clipper.SetInputConnection(rt.GetOutputPort())
clipper.SetCutFunction(plane)

selectMapper = vtk.vtkPolyDataMapper()
selectMapper.SetInputConnection(clipper.GetOutputPort())
selectMapper.SetScalarModeToUsePointFieldData()
selectMapper.SetColorModeToMapScalars()
selectMapper.ScalarVisibilityOn()
selectMapper.SetScalarRange(rt.GetOutputDataObject(0).GetPointData().GetScalars().GetRange())
selectMapper.SelectColorArray('RTData')

selectActor = vtk.vtkLODActor()
selectActor.SetMapper(selectMapper)
selectActor.VisibilityOn()
selectActor.SetScale(1.01, 1.01, 1.01)

# Create the RenderWindow, Renderer and both Actors
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# The callback function
def myCallback(obj, event):
    global plane
    obj.GetRepresentation().GetPlane(plane)
    selectActor.VisibilityOn()

# Create the representation and widget
planeRep = vtk.vtkImplicitPlaneRepresentation()
planeRep.SetPlaceFactor(1.25)
planeRep.PlaceWidget(rt.GetOutput().GetBounds())
planeRep.VisibilityOn()
planeRep.SetNormal(1,1,1)
planeRep.GetPlane(plane)

planeWidget = vtk.vtkImplicitPlaneWidget2()
planeWidget.SetInteractor(iren)
planeWidget.SetRepresentation(planeRep)
planeWidget.SetEnabled(1)
planeWidget.AddObserver("InteractionEvent", myCallback)

# ren.AddActor(maceActor)
ren.AddActor(selectActor)

# Add the actors to the renderer, set the background and size
renWin.SetSize(300, 300)
ren.SetBackground(0.1, 0.2, 0.4)
ren.ResetCamera()

# Start interaction.
renWin.Render()
iren.Start()

# ================



On Mar 19, 2010, at 6:27 AM, Sebastian Gatzka wrote:

> So by now I have gained some more knowledge about the callback stuff - or so I think.
> 
> I wan't to get back to this problem.
> I have made my code to display the widget right from the start with 
> 
> ->SetEnabled(1);
> 
> to the implicit plane widget. I'm adding the observer 
> 
> ->AddObserver(vtkCommand::AnyEvent,myCallback);
> 
> with AnyEvent and I think this is the problem.
> 
> The cutting plane the implicit plane widget is representing is displayed only if I do anything to the widget - and may it be a simple move with the mouse.
> But what I want is for the implicit plane widget to display the cut right from the beginning.
> 
> Anyone know how this is done?
> 
> Am 12.03.2010 17:01, schrieb Eric E. Monson:
>> 
>> 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
>> 
> _______________________________________________
> 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/20100319/b74fda4d/attachment.htm>


More information about the vtkusers mailing list