[vtk-developers] vtkBorderWidget events

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


On 2010-10-26 20:30:12 +0530, Karthik Krishnan wrote:
> Leonardo:
> 
> The BorderWidget is going to work correctly if you change the
> co-ordinate system of the PositionCoordinate and the
> Position2Coordinate of its representation. It is assumed that those
> ivars are always in the NormalizedViewport coordinate system.
> 
> There are a lot of excerpts like this in BorderWidget...
> 
> void vtkBorderWidget::SelectAction(vtkAbstractWidget *w)
> {
> ....
>   // Picked something inside the widget
>   int X = self->Interactor->GetEventPosition()[0];
>   int Y = self->Interactor->GetEventPosition()[1];
> 
>   // convert to normalized viewport coordinates
>   double XF = static_cast<double>(X);
>   double YF = static_cast<double>(Y);
>   self->CurrentRenderer->DisplayToNormalizedDisplay(XF,YF);
>   self->CurrentRenderer->NormalizedDisplayToViewport(XF,YF);
>   self->CurrentRenderer->ViewportToNormalizedViewport(XF,YF);
>   ...
>     vtkBorderRepresentation *rep =
> reinterpret_cast<vtkBorderRepresentation*>(self->WidgetRep);
>     double *fpos1 = rep->GetPositionCoordinate()->GetValue();
>     double *fpos2 = rep->GetPosition2Coordinate()->GetValue();
> 
>     eventPos[0] = (XF-fpos1[0])/fpos2[0];
>     eventPos[1] = (YF-fpos1[1])/fpos2[1];
> 
>     self->SelectRegion(eventPos);
>     }
> 
> 
> The GetValue() on the coordinate is going to return values in that
> coordinate system. If its anything other than NormalizedViewport, will
> not play well with the other variables in there.
> 
> 
> 
> This is (arguably) a bug, but you can work around this by defining
> your border widget's position in the NormalizedViewport frame of
> reference.
> 
> HTH
> --
> karthik
> 

Thanks Karthik, my problem is that I have to synchronize the coordinate
systems of vtkInteractorStyleRubberBand2D and vtkBorderRepresentation.

vtkInteractorStyleRubberBand2D as methods to get x0,y0 and x1,y1 (2d
area), but those are screen corrdinates, then using
ComputeDisplayToWorld I can translate those coordinates to my scene.

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.

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



More information about the vtk-developers mailing list