[vtkusers] GetWidth() on vtkActor2D always returns 0.5

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Sep 29 04:48:04 EDT 2016


I'm trying to position a vtkActor2D 5 pixels from the window edges in
the bottom right corner of the window when the window is modified:

void SegmentWidget::onRenderWindowModified()
{
    auto windowSize = GetRenderWindow()->GetSize();

    // FIXME: Don't hardcode the width of the image (80) here.
    //        ..but m_logoActor->GetWidth() always returns 0.5 (!)
    m_logoActor->SetPosition(windowSize[0] - 80 - 5, 5);

    GetRenderWindow()->Render();
}

Here I'm hardcoding the width of the actor (80 pixels) in the position
calculation. I was planning on using GetWidth on the actor, but for
some reason it always returns 0.5.

The docs says it should return the width of the actor as a fraction of
the viewport, but the actor is always a much larger fraction of the
viewport width, so I don't know where the 0.5 is coming from. And it's
not changing when I resize the window, it's always 0.5.

How can I get the width of the vtkActor2D in display coordinates?
(That's what I want in the end).

Thanks in advance,
Elvis

PS. The vtkActor2D is backed by a vtkPNGReader -> vtkImageMapper.


More information about the vtkusers mailing list