From 75a145e0c56498cb0d5b5499107d95904b13e9c6 Mon Sep 17 00:00:00 2001 From: Krad Date: Wed, 29 Jun 2022 10:17:29 +0800 Subject: [PATCH] Slice orientation fix. --- src/src/base/infinitiViewer.cxx | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/src/base/infinitiViewer.cxx b/src/src/base/infinitiViewer.cxx index af511ee..a6e6172 100644 --- a/src/src/base/infinitiViewer.cxx +++ b/src/src/base/infinitiViewer.cxx @@ -708,8 +708,9 @@ void infinitiViewer::ResetZoomScaleToFitWindowSize() { double whFactor = 0.5; double ws = 1.0* size[0]; double hs = 1.0* size[1]; - double hp = 1.0 * inputData->GetBounds()[upIndex*2+1]; - double wp = 1.0 * inputData->GetBounds()[rightIndex*2+1]; + double* bounds = inputData->GetBounds(); + double hp = fabs(1.0 * (bounds[upIndex*2+1] - bounds[upIndex*2])); + double wp = fabs(1.0 * (bounds[rightIndex*2+1] - bounds[rightIndex*2])); //because Parallel Scale is campare with half height if(wp/hp>ws/hs){ double aspect = hs/ws; @@ -1242,25 +1243,33 @@ void infinitiViewer::UpdateOrientation() vtkCamera* cam = this->Renderer ? this->Renderer->GetActiveCamera() : nullptr; if (cam) { + switch (this->SliceOrientation) { case infinitiViewer::SLICE_ORIENTATION_XY: + { cam->SetFocalPoint(0, 0, 0); cam->SetPosition(0, 0, -1); // -1 if medical ? cam->SetViewUp(0, -1, 0); break; - - case infinitiViewer::SLICE_ORIENTATION_XZ: + } + case infinitiViewer::SLICE_ORIENTATION_XZ:{ + double zVec = GetInput()->GetSpacing()[2]; + double upVal = (zVec > 0.0?1.0:-1.0); cam->SetFocalPoint(0, 0, 0); - cam->SetPosition(0, 1, 0); // 1 if medical ? - cam->SetViewUp(0, 0, -1); + cam->SetPosition(0, 1*upVal, 0); // 1 if medical ? + cam->SetViewUp(0, 0, -1.0 *upVal); break; - - case infinitiViewer::SLICE_ORIENTATION_YZ: + } + case infinitiViewer::SLICE_ORIENTATION_YZ:{ + double zVec = GetInput()->GetSpacing()[2]; + double upVal = (zVec > 0.0?1.0:-1.0); cam->SetFocalPoint(0, 0, 0); - cam->SetPosition( -1, 0, 0); // -1 if medical ? - cam->SetViewUp(0, 0, -1); + cam->SetPosition( -1 * upVal, 0, 0); // -1 if medical ? + cam->SetViewUp(0, 0, -1.0 *upVal); break; + } + } } }