From 25d21c239f85ef12bbe0379dfae9e6acee6fa1e8 Mon Sep 17 00:00:00 2001 From: Samuel Jackson Date: Wed, 15 Feb 2017 14:01:41 +0000 Subject: [PATCH 1/5] Refs #18869 Fix U correction view rect --- .../InstrumentView/RotationSurface.h | 5 ++ .../src/InstrumentView/RotationSurface.cpp | 54 ++++++++++++------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/InstrumentView/RotationSurface.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/InstrumentView/RotationSurface.h index 5e21f753185e..0896d16f8005 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/InstrumentView/RotationSurface.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/InstrumentView/RotationSurface.h @@ -46,6 +46,11 @@ class RotationSurface : public UnwrappedSurface { /// UnwrappedSurface::project(). double applyUCorrection(double u) const; + /// Update the view rect to offset for the U correction + void updateViewRectForUCorrection(); + /// Calculate UV offsets from the view rect + std::pair calculateViewRectOffsets(); + const Mantid::Kernel::V3D m_pos; ///< Origin (sample position) const Mantid::Kernel::V3D m_zaxis; ///< The z axis of the surface specific coord system diff --git a/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp b/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp index 65b053cb448e..a1cd14e0cc1c 100644 --- a/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp +++ b/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp @@ -162,26 +162,42 @@ void RotationSurface::init() { udet.u = applyUCorrection(udet.u); } } +} - double dU = fabs(m_u_max - m_u_min); - double dV = fabs(m_v_max - m_v_min); - double du = dU * 0.05; - double dv = dV * 0.05; - if (m_width_max > du && std::isfinite(m_width_max)) { - if (du > 0 && !(dU >= m_width_max)) { - m_width_max = dU; - } - du = m_width_max; - } - if (m_height_max > dv && std::isfinite(m_height_max)) { - if (dv > 0 && !(dV >= m_height_max)) { - m_height_max = dV; - } - dv = m_height_max; - } +/** Update the view rect to account for the U correction + */ +void RotationSurface::updateViewRectForUCorrection() { + const auto offsets = calculateViewRectOffsets(); + const auto min = QPointF(m_u_min - offsets.first, m_v_min - offsets.second); + const auto max = QPointF(m_u_max + offsets.first, m_v_max + offsets.second); + m_viewRect = RectF(min, max); +} + +/** Calculate UV offsets to the view rect + * + * @return a std::pair containing the u & v offsets for the view rect + */ +std::pair RotationSurface::calculateViewRectOffsets() { + const auto dU = fabs(m_u_max - m_u_min); + const auto dV = fabs(m_v_max - m_v_min); + auto du = dU * 0.05; + auto dv = dV * 0.05; + + if (m_width_max > du && std::isfinite(m_width_max)) { + if (du > 0 && !(dU >= m_width_max)) { + m_width_max = dU; + } + du = m_width_max; + } + + if (m_height_max > dv && std::isfinite(m_height_max)) { + if (dv > 0 && !(dV >= m_height_max)) { + m_height_max = dV; + } + dv = m_height_max; + } - m_viewRect = RectF(QPointF(m_u_min - du, m_v_min - dv), - QPointF(m_u_max + du, m_v_max + dv)); + return std::make_pair(du, dv); } void RotationSurface::findUVBounds() { @@ -308,6 +324,7 @@ void RotationSurface::setUCorrection(double umin, double umax) { } m_manual_u_correction = true; updateDetectors(); + updateViewRectForUCorrection(); } /** @@ -316,6 +333,7 @@ void RotationSurface::setUCorrection(double umin, double umax) { void RotationSurface::setAutomaticUCorrection() { m_manual_u_correction = false; updateDetectors(); + updateViewRectForUCorrection(); } } // MantidWidgets From 9fff85cafa1cc78d1faa5b7603839aa09912b0e6 Mon Sep 17 00:00:00 2001 From: Samuel Jackson Date: Wed, 15 Feb 2017 14:03:13 +0000 Subject: [PATCH 2/5] Refs #18869 Fix code formatting This code is badly indented. While we're herewe should fix it --- .../src/InstrumentView/RotationSurface.cpp | 145 +++++++++--------- 1 file changed, 69 insertions(+), 76 deletions(-) diff --git a/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp b/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp index a1cd14e0cc1c..89cf4a9e1679 100644 --- a/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp +++ b/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp @@ -86,82 +86,75 @@ void RotationSurface::init() { // For each detector in the order of actors // cppcheck-suppress syntaxError - PRAGMA_OMP(parallel for) - for (int ii = 0; ii < int(ndet); ++ii) { - if (!exceptionThrown) - try { - size_t i = size_t(ii); - - unsigned char color[3]; - Mantid::detid_t id = m_instrActor->getDetID(i); - - boost::shared_ptr< - const Mantid::Geometry::IDetector> det; - try { - det = inst->getDetector(id); - } catch ( - Mantid::Kernel::Exception::NotFoundError &) { - } - - if (!det || - detectorInfo.isMonitor( - detectorInfo.indexOf(id)) || - (id < 0)) { - // Not a detector or a monitor - // Make some blank, empty thing that won't draw - m_unwrappedDetectors[i] = UnwrappedDetector(); - } else { - // A real detector. - m_instrActor->getColor(id).getUB3(&color[0]); - - // Position, relative to origin - // Mantid::Kernel::V3D pos = det->getPos() - - // m_pos; - Mantid::Kernel::V3D pos = - m_instrActor->getDetPos(i) - m_pos; - - // Create the unwrapped shape - UnwrappedDetector udet(&color[0], det); - // Calculate its position/size in UV coordinates - this->calcUV(udet, pos); - - m_unwrappedDetectors[i] = udet; - } // is a real detectord - } catch (std::exception &e) { - // stop executing the body of the loop - exceptionThrown = true; - g_log.error() << e.what() << '\n'; - } catch (...) { - // stop executing the body of the loop - exceptionThrown = true; - g_log.error("Unknown exception thrown."); - } - } // for each detector in pick order - - // if the loop above has thrown stop execution - if (exceptionThrown) { - throw std::runtime_error( - "An exception was thrown. See log for detail."); - } - - // find the overall edges in u and v coords - findUVBounds(); - - // apply a shift in u-coord either found automatically - // or set manually - if (!m_manual_u_correction) { - // automatic gap correction - findAndCorrectUGap(); - } else { - // apply manually set shift - m_u_min = manual_u_min; - m_u_max = manual_u_max; - for (size_t i = 0; i < m_unwrappedDetectors.size(); - ++i) { - auto &udet = m_unwrappedDetectors[i]; - udet.u = applyUCorrection(udet.u); - } - } + PRAGMA_OMP(parallel for) + for (int ii = 0; ii < int(ndet); ++ii) { + if (!exceptionThrown) + try { + size_t i = size_t(ii); + + unsigned char color[3]; + Mantid::detid_t id = m_instrActor->getDetID(i); + + boost::shared_ptr det; + try { + det = inst->getDetector(id); + } catch (Mantid::Kernel::Exception::NotFoundError &) { + } + + if (!det || detectorInfo.isMonitor(detectorInfo.indexOf(id)) || + (id < 0)) { + // Not a detector or a monitor + // Make some blank, empty thing that won't draw + m_unwrappedDetectors[i] = UnwrappedDetector(); + } else { + // A real detector. + m_instrActor->getColor(id).getUB3(&color[0]); + + // Position, relative to origin + // Mantid::Kernel::V3D pos = det->getPos() - + // m_pos; + Mantid::Kernel::V3D pos = m_instrActor->getDetPos(i) - m_pos; + + // Create the unwrapped shape + UnwrappedDetector udet(&color[0], det); + // Calculate its position/size in UV coordinates + this->calcUV(udet, pos); + + m_unwrappedDetectors[i] = udet; + } // is a real detectord + } catch (std::exception &e) { + // stop executing the body of the loop + exceptionThrown = true; + g_log.error() << e.what() << '\n'; + } catch (...) { + // stop executing the body of the loop + exceptionThrown = true; + g_log.error("Unknown exception thrown."); + } + } // for each detector in pick order + + // if the loop above has thrown stop execution + if (exceptionThrown) { + throw std::runtime_error("An exception was thrown. See log for detail."); + } + + // find the overall edges in u and v coords + findUVBounds(); + + // apply a shift in u-coord either found automatically + // or set manually + if (!m_manual_u_correction) { + // automatic gap correction + findAndCorrectUGap(); + } else { + // apply manually set shift + m_u_min = manual_u_min; + m_u_max = manual_u_max; + for (size_t i = 0; i < m_unwrappedDetectors.size(); ++i) { + auto &udet = m_unwrappedDetectors[i]; + udet.u = applyUCorrection(udet.u); + } + } } /** Update the view rect to account for the U correction From 005202c520fa73e0433ee77eb5eed562ff575f96 Mon Sep 17 00:00:00 2001 From: Samuel Jackson Date: Thu, 16 Feb 2017 07:48:51 +0000 Subject: [PATCH 3/5] Refs #18869 Add release notes. --- docs/source/release/v3.10.0/ui.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/release/v3.10.0/ui.rst b/docs/source/release/v3.10.0/ui.rst index 16708099c14d..d0887acfcf4c 100644 --- a/docs/source/release/v3.10.0/ui.rst +++ b/docs/source/release/v3.10.0/ui.rst @@ -19,6 +19,7 @@ User Interface Instrument View ############### + - Fixed a bug preventing the viewport from being correctly set when using a U correction. Plotting Improvements ##################### From 0deffd9c23a8d238277970ac94616f1504749079 Mon Sep 17 00:00:00 2001 From: Samuel Jackson Date: Thu, 16 Feb 2017 08:03:24 +0000 Subject: [PATCH 4/5] Revert "Refs #18869 Fix code formatting" This reverts commit 9fff85cafa1cc78d1faa5b7603839aa09912b0e6. --- .../src/InstrumentView/RotationSurface.cpp | 145 +++++++++--------- 1 file changed, 76 insertions(+), 69 deletions(-) diff --git a/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp b/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp index 89cf4a9e1679..a1cd14e0cc1c 100644 --- a/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp +++ b/MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp @@ -86,75 +86,82 @@ void RotationSurface::init() { // For each detector in the order of actors // cppcheck-suppress syntaxError - PRAGMA_OMP(parallel for) - for (int ii = 0; ii < int(ndet); ++ii) { - if (!exceptionThrown) - try { - size_t i = size_t(ii); - - unsigned char color[3]; - Mantid::detid_t id = m_instrActor->getDetID(i); - - boost::shared_ptr det; - try { - det = inst->getDetector(id); - } catch (Mantid::Kernel::Exception::NotFoundError &) { - } - - if (!det || detectorInfo.isMonitor(detectorInfo.indexOf(id)) || - (id < 0)) { - // Not a detector or a monitor - // Make some blank, empty thing that won't draw - m_unwrappedDetectors[i] = UnwrappedDetector(); - } else { - // A real detector. - m_instrActor->getColor(id).getUB3(&color[0]); - - // Position, relative to origin - // Mantid::Kernel::V3D pos = det->getPos() - - // m_pos; - Mantid::Kernel::V3D pos = m_instrActor->getDetPos(i) - m_pos; - - // Create the unwrapped shape - UnwrappedDetector udet(&color[0], det); - // Calculate its position/size in UV coordinates - this->calcUV(udet, pos); - - m_unwrappedDetectors[i] = udet; - } // is a real detectord - } catch (std::exception &e) { - // stop executing the body of the loop - exceptionThrown = true; - g_log.error() << e.what() << '\n'; - } catch (...) { - // stop executing the body of the loop - exceptionThrown = true; - g_log.error("Unknown exception thrown."); - } - } // for each detector in pick order - - // if the loop above has thrown stop execution - if (exceptionThrown) { - throw std::runtime_error("An exception was thrown. See log for detail."); - } - - // find the overall edges in u and v coords - findUVBounds(); - - // apply a shift in u-coord either found automatically - // or set manually - if (!m_manual_u_correction) { - // automatic gap correction - findAndCorrectUGap(); - } else { - // apply manually set shift - m_u_min = manual_u_min; - m_u_max = manual_u_max; - for (size_t i = 0; i < m_unwrappedDetectors.size(); ++i) { - auto &udet = m_unwrappedDetectors[i]; - udet.u = applyUCorrection(udet.u); - } - } + PRAGMA_OMP(parallel for) + for (int ii = 0; ii < int(ndet); ++ii) { + if (!exceptionThrown) + try { + size_t i = size_t(ii); + + unsigned char color[3]; + Mantid::detid_t id = m_instrActor->getDetID(i); + + boost::shared_ptr< + const Mantid::Geometry::IDetector> det; + try { + det = inst->getDetector(id); + } catch ( + Mantid::Kernel::Exception::NotFoundError &) { + } + + if (!det || + detectorInfo.isMonitor( + detectorInfo.indexOf(id)) || + (id < 0)) { + // Not a detector or a monitor + // Make some blank, empty thing that won't draw + m_unwrappedDetectors[i] = UnwrappedDetector(); + } else { + // A real detector. + m_instrActor->getColor(id).getUB3(&color[0]); + + // Position, relative to origin + // Mantid::Kernel::V3D pos = det->getPos() - + // m_pos; + Mantid::Kernel::V3D pos = + m_instrActor->getDetPos(i) - m_pos; + + // Create the unwrapped shape + UnwrappedDetector udet(&color[0], det); + // Calculate its position/size in UV coordinates + this->calcUV(udet, pos); + + m_unwrappedDetectors[i] = udet; + } // is a real detectord + } catch (std::exception &e) { + // stop executing the body of the loop + exceptionThrown = true; + g_log.error() << e.what() << '\n'; + } catch (...) { + // stop executing the body of the loop + exceptionThrown = true; + g_log.error("Unknown exception thrown."); + } + } // for each detector in pick order + + // if the loop above has thrown stop execution + if (exceptionThrown) { + throw std::runtime_error( + "An exception was thrown. See log for detail."); + } + + // find the overall edges in u and v coords + findUVBounds(); + + // apply a shift in u-coord either found automatically + // or set manually + if (!m_manual_u_correction) { + // automatic gap correction + findAndCorrectUGap(); + } else { + // apply manually set shift + m_u_min = manual_u_min; + m_u_max = manual_u_max; + for (size_t i = 0; i < m_unwrappedDetectors.size(); + ++i) { + auto &udet = m_unwrappedDetectors[i]; + udet.u = applyUCorrection(udet.u); + } + } } /** Update the view rect to account for the U correction From 146414e4a0c46a3f6b0be6215495a40f97b596ee Mon Sep 17 00:00:00 2001 From: Nick Draper Date: Thu, 16 Feb 2017 13:45:14 +0000 Subject: [PATCH 5/5] made release note more user friendly --- docs/source/release/v3.10.0/ui.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/release/v3.10.0/ui.rst b/docs/source/release/v3.10.0/ui.rst index d0887acfcf4c..3760a83001a1 100644 --- a/docs/source/release/v3.10.0/ui.rst +++ b/docs/source/release/v3.10.0/ui.rst @@ -19,7 +19,7 @@ User Interface Instrument View ############### - - Fixed a bug preventing the viewport from being correctly set when using a U correction. + - Fixed a bug preventing the some of the banks from being visible when using a U correction. Plotting Improvements #####################