[vtkusers] vtkBorderWidget position & size

Leonardo M. Ramé l.rame at griensu.com
Mon Oct 25 16:22:28 EDT 2010


On 2010-10-25 16:30:09 -0300, Leonardo M. Ramé wrote:
> I'm trying to create a vtkBorderWidget with the dimension data obtained
> from a vtkInteractorStyleRubberBand2D.
> 
> To get the bounds of vtkInteractorStyleRubberBand2D I use this subclass:
> 
> class MyRubberBand : public vtkInteractorStyleRubberBand2D
> {
>   public:
>     static MyRubberBand* New();
>     vtkTypeRevisionMacro(MyRubberBand, vtkInteractorStyleRubberBand2D);
> 
>     void GetPosition(int &x0, int &y0, int &x1, int &y1)
>     {
>         x0 = this->StartPosition[0];
>         y0 = this->StartPosition[1];
>         x1 = this->EndPosition[0];
>         y1 = this->EndPosition[1];
>     };
> };
> 
> 
> Aparently, SetPosition and SetPosition2 methods of
> vtkBorderRepresentation allows to define the position and bounds of the
> vtkBorderWidget, but, instead of that, I can't see the widget:
> 
> This is my code:
> 
> int x0;
> int y0;
> int x1;
> int y1;
> 
> MyRubberBand::SafeDownCast(m_rubberBand)->GetPosition(x0, y0,x1, y1);
> m_rubberBand->Delete();
> m_rubberBand = NULL;
> 
> m_border = vtkBorderWidget::New();
> m_border->SetInteractor(this->GetInteractor());
> m_border->CreateDefaultRepresentation();
> vtkBorderRepresentation::SafeDownCast(m_border->GetRepresentation())->SetPosition(x0, y0);
> vtkBorderRepresentation::SafeDownCast(m_border->GetRepresentation())->SetPosition2(x1, y1);
> m_border->On();
> 
> Are the positions obtanied from the vtkInteractorStyleRubberBand2D
> Screen positions instead of world positions? Should I translate them?
> how?
> 

Found the (partial) solution:

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

vtkBorderRepresentation * borderRep = vtkBorderRepresentation::SafeDownCast(m_border->GetRepresentation());
borderRep->GetPositionCoordinate()->SetCoordinateSystemToDisplay();
borderRep->GetPositionCoordinate()->SetValue(x0, y0);
borderRep->GetPosition2Coordinate()->SetCoordinateSystemToDisplay();
borderRep->GetPosition2Coordinate()->SetValue(x1 - x0, y1 - y0);

This allows me to show the vtkBorderWidget in the correct position,
however, I cannot select nor move it anymore. I think this is because of
my "SetCoordinateSystemToDisplay()" calls.

How can I let the user select and move the borderwidget again?

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



More information about the vtkusers mailing list