From e128ef7949f92db2e85fb87f25feafe433b4ae1d Mon Sep 17 00:00:00 2001 From: Paul Lafoix <paul.lafoix@kitware.com> Date: Mon, 26 Apr 2021 13:15:59 +0200 Subject: [PATCH] Zoom closer to the data and fix too much zoom bug --- .../TestResetCameraScreenSpace.png.sha512 | 2 +- Rendering/Core/vtkRenderer.cxx | 26 +++++-------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/Rendering/Core/Testing/Data/Baseline/TestResetCameraScreenSpace.png.sha512 b/Rendering/Core/Testing/Data/Baseline/TestResetCameraScreenSpace.png.sha512 index 99ba1f38a77..892ecab430d 100644 --- a/Rendering/Core/Testing/Data/Baseline/TestResetCameraScreenSpace.png.sha512 +++ b/Rendering/Core/Testing/Data/Baseline/TestResetCameraScreenSpace.png.sha512 @@ -1 +1 @@ -5791a385e48a7213fb85a3da060ce788f7050ef0ce53bda1df8b2f126947b860b0ddd6e405ee9c44f54b91eaaed3d3565a7479350b03e4d99c4774f4e648075f +1dfa972a6f686870f82cc5dc99035516f5d4e79bb41a014be9eec96a6b07f42044b012bb32690a84abfe78f1dfaf7f1671a250752f3f4f15b115792267933a0b diff --git a/Rendering/Core/vtkRenderer.cxx b/Rendering/Core/vtkRenderer.cxx index c73350c3df6..b96674ab5c7 100644 --- a/Rendering/Core/vtkRenderer.cxx +++ b/Rendering/Core/vtkRenderer.cxx @@ -1404,15 +1404,6 @@ void vtkRenderer::ResetCameraScreenSpace(const double bounds[6]) } } - // Offset a little to make sure bounds are not clipped - int offsetX = std::max(static_cast<int>((xmax - xmin) * 0.01), 10); - int offsetY = std::max(static_cast<int>((ymax - ymin) * 0.01), 10); - - xmin -= offsetX; - xmax += offsetX; - ymin -= offsetY; - ymax += offsetY; - // Project the focal point in screen space double fp[4]; this->ActiveCamera->GetFocalPoint(fp); @@ -1465,18 +1456,13 @@ vtkVector3d vtkRenderer::DisplayToWorld(const vtkVector3d& display) void vtkRenderer::ZoomToBoxUsingViewAngle(const vtkRecti& box) { const int* size = this->GetSize(); - double zoomFactor; - if (box.GetWidth() > box.GetHeight()) - { - zoomFactor = size[0] / static_cast<double>(box.GetWidth()); - } - else - { - zoomFactor = size[1] / static_cast<double>(box.GetHeight()); - } + double zf1 = size[0] / static_cast<double>(box.GetWidth()); + double zf2 = size[1] / static_cast<double>(box.GetHeight()); + double zoomFactor = std::min(zf1, zf2); - vtkCamera* cam = this->GetActiveCamera(); - cam->Zoom(zoomFactor); + // Offset a little to let a free space between the zoomed data + // And the edges of the window + this->GetActiveCamera()->Zoom(zoomFactor * 0.90); } // Specify the rendering window in which to draw. This is automatically set -- GitLab