Skip to content

Commit

Permalink
Merge pull request #18875 from mantidproject/18869_u_correction_instr…
Browse files Browse the repository at this point in the history
…ument_view

U correction not correctly applied to viewport
  • Loading branch information
NickDraper committed Feb 16, 2017
2 parents 580996f + 146414e commit a699490
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
Expand Up @@ -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<double, double> 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
Expand Down
54 changes: 36 additions & 18 deletions MantidQt/MantidWidgets/src/InstrumentView/RotationSurface.cpp
Expand Up @@ -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<double, double> 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() {
Expand Down Expand Up @@ -308,6 +324,7 @@ void RotationSurface::setUCorrection(double umin, double umax) {
}
m_manual_u_correction = true;
updateDetectors();
updateViewRectForUCorrection();
}

/**
Expand All @@ -316,6 +333,7 @@ void RotationSurface::setUCorrection(double umin, double umax) {
void RotationSurface::setAutomaticUCorrection() {
m_manual_u_correction = false;
updateDetectors();
updateViewRectForUCorrection();
}

} // MantidWidgets
Expand Down
1 change: 1 addition & 0 deletions docs/source/release/v3.10.0/ui.rst
Expand Up @@ -19,6 +19,7 @@ User Interface

Instrument View
###############
- Fixed a bug preventing the some of the banks from being visible when using a U correction.

Plotting Improvements
#####################
Expand Down

0 comments on commit a699490

Please sign in to comment.