[vtk-developers] vtkBorderWidget events

Leonardo M. Ramé l.rame at griensu.com
Tue Oct 26 13:47:32 EDT 2010


On 2010-10-26 21:23:31 +0530, Karthik Krishnan wrote:
> On Tue, Oct 26, 2010 at 8:43 PM, Leonardo M. Ramé <l.rame at griensu.com> wrote:
> > On 2010-10-26 20:30:12 +0530, Karthik Krishnan wrote:
> >
> > I need that data to draw my vtkBorderWidget, but again, to draw it I
> > have to set its coordinate system to world. If I use
> > SetCoordinateSystemToNormalizedViewport I can't see the BorderWidget.
> >
> > Hope somebody helps me on finding a way to translate the coordinates of
> > vtkInteractorStyleRubberBand2D to the normalized viewport of
> > vtkBorderRepresentation.
> 
> Take a look at vtkCoordinate. It has all the methods you need to
> convert a vector from one coordinate system to another. See
> (./Rendering/Testing/Cxx/otherCoordinate.cxx) as an example. You
> should be able to convert the world coords to NormalizedViewport
> coords and then pass them along to the BorderWidget. Isn't that so ?
> 
> --
> karthik

Karthik, after your suggestions here and in vtkusers, I changed my
mouseReleaseEvent to this:

void DCMWidget::mouseReleaseEvent (QMouseEvent* e)
{
    if(m_rubberBand)
    {
        double x0;
        double y0;
        double x1;
        double y1;

        MyRubberBand::SafeDownCast(m_rubberBand)->GetPosition(x0, y0, x1, y1);

        m_ImageViewer->GetRenderer()->DisplayToNormalizedDisplay(x0, y0);
        m_ImageViewer->GetRenderer()->NormalizedDisplayToViewport(x0,y0);
        m_ImageViewer->GetRenderer()->ViewportToNormalizedViewport(x0, y0);

        m_ImageViewer->GetRenderer()->DisplayToNormalizedDisplay(x1, y1);
        m_ImageViewer->GetRenderer()->NormalizedDisplayToViewport(x1, y1);
        m_ImageViewer->GetRenderer()->ViewportToNormalizedViewport(x1, y1);

        m_rubberBand->Delete();
        m_rubberBand = NULL;

        this->GetInteractor()->SetInteractorStyle(this->m_ImageViewer->GetInteractorStyle());

        vtkAbstractWidget * lWidget = vtkBorderWidget::New();
        lWidget->SetInteractor(this->GetInteractor());
        lWidget->CreateDefaultRepresentation();

        vtkBorderRepresentation * borderRep = vtkBorderRepresentation::SafeDownCast(lWidget->GetRepresentation());
        borderRep->GetPositionCoordinate()->SetValue(x0, y0);
        borderRep->GetPosition2Coordinate()->SetValue(x1 - x0, y1 - y0);
        lWidget->AddObserver(vtkCommand::AnyEvent, widgetCallback);
        lWidget->On();
    }
    m_buttonpressed = false;
    e->accept();
    QVTKWidget::mouseReleaseEvent(e);
    update();
}

In fact, after applying the methods of Renderer
(DisplayToNormalizedDisplay, NormalizedDisplayToViewport and
ViewportToNormalizedViewport), the values of x0,y0,x1,y1 are changed,
and the vtkBorderWidget is drawn correctly on the screen, but still, mouse
events are not fired when I click on the widget. Does anyone knows why?

-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com



More information about the vtk-developers mailing list