Commit aa4dc045 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri 💬 Committed by Kitware Robot
Browse files

Merge topic 'orientation_marker_viewport'

2dec4506 Cleaned up commented code
9a12a244 Fixed the orientation marker widget test for viewport changes
1548b737

 Fix orientation marker viewport coordinates
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarRobert Maynard <robert.maynard@kitware.com>
Merge-request: !1607
parents 0ac074c8 2dec4506
......@@ -108,7 +108,7 @@ int TestOrientationMarkerWidget2(int argc, char *argv[])
vtkNew<vtkOrientationMarkerWidget> orientationWidget;
orientationWidget->SetInteractor(iren.GetPointer());
orientationWidget->SetDefaultRenderer(smallViewRenderer.GetPointer());
orientationWidget->SetViewport(smallViewRenderer->GetViewport());
orientationWidget->SetViewport(0, 0, 1, 1);
orientationWidget->SetOrientationMarker(textActor.GetPointer());
orientationWidget->On();
......
......@@ -66,8 +66,12 @@ 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->SetLayer( 1 );
this->Renderer->InteractiveOff();
......@@ -150,6 +154,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 +495,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 +663,7 @@ void vtkOrientationMarkerWidget::MoveWidget(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -706,6 +726,7 @@ void vtkOrientationMarkerWidget::ResizeTopLeft(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -768,6 +789,7 @@ void vtkOrientationMarkerWidget::ResizeTopRight(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -830,6 +852,7 @@ void vtkOrientationMarkerWidget::ResizeBottomRight(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -892,6 +915,7 @@ void vtkOrientationMarkerWidget::ResizeBottomLeft(int X, int Y)
this->Renderer->DisplayToNormalizedDisplay( newPos[2], newPos[3] );
this->Renderer->SetViewport( newPos );
this->UpdateViewport();
}
//-------------------------------------------------------------------------
......@@ -911,22 +935,25 @@ double* vtkOrientationMarkerWidget::GetOutlineColor()
}
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetViewport(double minX, double minY,
double maxX, double maxY)
void vtkOrientationMarkerWidget::UpdateViewport()
{
this->Renderer->SetViewport( minX, minY, maxX, maxY );
}
if (!this->CurrentRenderer)
{
return;
}
double currentViewport[4];
this->CurrentRenderer->GetViewport(currentViewport);
//-------------------------------------------------------------------------
void vtkOrientationMarkerWidget::SetViewport(double viewport[4])
{
this->Renderer->SetViewport(viewport);
}
double vp[4];
this->Renderer->GetViewport(vp);
//-------------------------------------------------------------------------
double* vtkOrientationMarkerWidget::GetViewport()
{
return this->Renderer->GetViewport();
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 +964,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";
}
......@@ -112,10 +112,17 @@ public:
// Description:
// Set/get the viewport to position/size this widget.
// Coordinates are expressed as (xmin,ymin,xmax,ymax), where each
// coordinate is 0 <= coordinate <= 1.0.
// 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) in the
// render window.
// \sa SetCurrentRenderer()
vtkSetVector4Macro(Viewport, double);
vtkGetVector4Macro(Viewport, double);
// Description:
// The tolerance representing the distance to the widget (in pixels)
......@@ -150,6 +157,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 +193,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