[vtkusers] Events/Callbacks: How to invoke an event to force vtkLineWidget2 to update?

da remywendy at gmail.com
Tue Feb 2 20:13:05 EST 2010


Hi everyone.

I am working with vtkLineWidget2 and vtkLineRepresentation. I have a
function that is to align the vtkLineWidget to some axis. The problem is
that when I interact with the widget with the mouse, the streamlines that
use the vtkLineWidget's polydata updates correctly. However when I call the
function to set the Line Widget's positions, the streamlines do not update
(the polydata is not getting updated - how do I invoke it to update?)

switch (axis) // Align to axis, keep original length
{
case flowModuleStreamlines::XAxis:
start[0] += length;
m_LineRep->SetPoint2WorldPosition(start);
break;
case flowModuleStreamlines::YAxis:
start[1] += length;
m_LineRep->SetPoint2WorldPosition(start);
break;
case flowModuleStreamlines::ZAxis:
start[2] += length;
m_LineRep->SetPoint2WorldPosition(start);
break;
default:
break;
}
m_Callback->Execute(m_LineWidget,0,0); // Manually update widget's position
- but streamlines don't update?!

I then manually call the callback for it to update - but it only updates the
widget - my pipeline further down is not updated! If I click on the render
window though, it updates again - this is probably because the widget itself
needs an event to update internally? My question is how do I invoke this
event, and is there a better way to do this?

Heres the callback:

class vtk2DLineCallback : public vtkCommand
{
public:
static vtk2DLineCallback *New()
{
return new vtk2DLineCallback;
}

  virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
      vtkLineWidget2 *lineWidget =
reinterpret_cast<vtkLineWidget2*>(caller);
      vtkLineRepresentation *rep =

 reinterpret_cast<vtkLineRepresentation*>(lineWidget->GetRepresentation());
      rep->GetPolyData(this->PolyData);
      this->Actor->VisibilityOn();
    }

  vtk2DLineCallback():PolyData(0),Actor(0){}
  vtkPolyData *PolyData;
  vtkActor *Actor;
};

The callback is called on EndInteractionEvent...

m_LineWidget->AddObserver(vtkCommand::EndInteractionEvent,m_Callback);

I've tried using the invokeEvent method, but have limited success and am not
sure how to do it correctly.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100202/9e114815/attachment.htm>


More information about the vtkusers mailing list