Commit 1548b737 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri 💬
Browse files

Fix orientation marker viewport coordinates

When the current renderer for the orientation marker widget does
not extend the whole size of the render window, the widget
viewport was not being confined to the current renderer. Changed
the behavior to scale the viewport supplied by the user to the
viewport of the current renderer.
parent 26be68fd
......@@ -66,8 +66,13 @@ vtkOrientationMarkerWidget::vtkOrientationMarkerWidget()
this->Tolerance = 7;
this->Moving = 0;
this->Viewport[0] = 0.0;
this->Viewport[1] = 0.0;
this->Viewport[2] = 0.2;
this->Viewport[3] = 0.2;
this->Renderer = vtkRenderer::New();
this->Renderer->SetViewport( 0.0, 0.0, 0.2, 0.2 );
//this->Renderer->SetViewport( 0.0, 0.0, 0.2, 0.2 );
this->Renderer->SetLayer( 1 );
this->Renderer->InteractiveOff();
......@@ -150,6 +155,20 @@ void vtkOrientationMarkerWidget::SetEnabled(int enabling)
this->Enabled = 1;
// Compute the viewport for the widget w.r.t. to the current renderer
double currentViewport[4];
this->CurrentRenderer->GetViewport(currentViewport);
double vp[4], currentViewportRange[2];
for (int i = 0; i < 2; ++i)
{
currentViewportRange[i] = currentViewport[i+2] - currentViewport[i];
vp[i] = this->Viewport[i] * currentViewportRange[i] +
currentViewport[i];
vp[i+2] = this->Viewport[i+2] * currentViewportRange[i] +
currentViewport[i];
}
this->Renderer->SetViewport(vp);
vtkRenderWindow* renwin = this->CurrentRenderer->GetRenderWindow();
renwin->AddRenderer( this->Renderer );
if (renwin->GetNumberOfLayers() < 2)
......@@ -477,6 +496,7 @@ void vtkOrientationMarkerWidget::SquareRenderer()
this->Renderer->DisplayToNormalizedDisplay( vp[0], vp[1] );
this->Renderer->DisplayToNormalizedDisplay( vp[2], vp[3] );
this->Renderer->SetViewport( vp );
this->UpdateViewport();
}
}
......@@ -644,6 +664,7 @@ void vtkOrientationMarkerWidget::MoveWidget(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -706,6 +727,7 @@ void vtkOrientationMarkerWidget::ResizeTopLeft(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -768,6 +790,7 @@ void vtkOrientationMarkerWidget::ResizeTopRight(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -830,6 +853,7 @@ void vtkOrientationMarkerWidget::ResizeBottomRight(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -892,6 +916,7 @@ void vtkOrientationMarkerWidget::ResizeBottomLeft(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -910,23 +935,48 @@ double* vtkOrientationMarkerWidget::GetOutlineColor()
return this->OutlineActor->GetProperty()->GetColor();
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetViewport(double minX, double minY,
double maxX, double maxY)
{
this->Renderer->SetViewport( minX, minY, maxX, maxY );
}
////-------------------------------------------------------------------------
//void vtkOrientationMarkerWidget::SetViewport(double minX, double minY,
// double maxX, double maxY)
//{
// double vp[4];
// vp[0] = minX; vp[2] = maxX;
// vp[1] = minY; vp[3] = maxY;
// this->SetViewport( vp );
//}
//
////-------------------------------------------------------------------------
//void vtkOrientationMarkerWidget::SetViewport(double viewport[4])
//{
// this->Renderer->SetViewport(viewport);
//}
//
////-------------------------------------------------------------------------
//double* vtkOrientationMarkerWidget::GetViewport()
//{
// return this->Renderer->GetViewport();
//}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetViewport(double viewport[4])
void vtkOrientationMarkerWidget::UpdateViewport()
{
this->Renderer->SetViewport(viewport);
}
if (!this->CurrentRenderer)
{
return;
}
double currentViewport[4];
this->CurrentRenderer->GetViewport(currentViewport);
//-------------------------------------------------------------------------
double* vtkOrientationMarkerWidget::GetViewport()
{
return this->Renderer->GetViewport();
double vp[4];
this->Renderer->GetViewport(vp);
double cvpRange[2];
for (int i = 0; i < 2; ++i)
{
cvpRange[i] = currentViewport[i+2] - currentViewport[i];
this->Viewport[i] = (vp[i] - currentViewport[i]) / cvpRange[i];
this->Viewport[i+2] = (vp[i+2] - currentViewport[i]) / cvpRange[i];
}
}
//-------------------------------------------------------------------------
......@@ -937,4 +987,7 @@ void vtkOrientationMarkerWidget::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "OrientationMarker: " << this->OrientationMarker << endl;
os << indent << "Interactive: " << this->Interactive << endl;
os << indent << "Tolerance: " << this->Tolerance << endl;
os << indent << "Viewport: (" << this->Viewport[0] << ", "
<< this->Viewport[1] << ", " << this->Viewport[2] << ", "
<< this->Viewport[3] << ")\n";
}
......@@ -113,9 +113,13 @@ public:
// Description:
// Set/get the viewport to position/size this widget.
// Default is bottom left corner (0,0,0.2,0.2).
void SetViewport(double minX, double minY, double maxX, double maxY);
void SetViewport(double viewport[4]);
double* GetViewport();
// Note that this viewport is scaled with respect to the viewport of the
// current renderer i.e. if the viewport of the current renderer is
// (0.5, 0.5, 0.75, 0.75) and Viewport is set to (0, 0, 1, 1), the orientation
// marker will be confined to a viewport of (0.5, 0.5, 0.75, 0.75).
// \sa SetCurrentRenderer()
vtkSetVector4Macro(Viewport, double);
vtkGetVector4Macro(Viewport, double);
// Description:
// The tolerance representing the distance to the widget (in pixels)
......@@ -150,6 +154,9 @@ protected:
int Tolerance;
int Moving;
// viewport to position/size this widget
double Viewport[4];
// used to compute relative movements
int StartPosition[2];
......@@ -183,6 +190,7 @@ protected:
void SquareRenderer();
void UpdateOutline();
void UpdateViewport();
private:
vtkOrientationMarkerWidget(const vtkOrientationMarkerWidget&); // Not implemented
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment