diff --git a/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h b/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h index f6a9a805d2a6baa4ba14b4557df4bc8500b9ac83..fc32c89e24a03b8131dafae0b648bcf6127b8a4d 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h +++ b/Framework/DataObjects/inc/MantidDataObjects/MDHistoWorkspace.h @@ -452,6 +452,15 @@ private: /// Display normalization to use Mantid::API::MDNormalization m_displayNormalization; + // Get ordered list of boundaries in position-along-the-line coordinates + std::set<coord_t> getBinBoundariesOnLine(const Kernel::VMD &start, + const Kernel::VMD &end, size_t nd, + const Kernel::VMD &dir, + coord_t length) const; + + signal_t getNormalizationFactor(const API::MDNormalization &normalize, + size_t linearIndex) const; + protected: /// Protected copy constructor. May be used by childs for cloning. MDHistoWorkspace(const MDHistoWorkspace &other); @@ -460,6 +469,7 @@ protected: /// Linear array of masks for each bin bool *m_masks; + }; /// A shared pointer to a MDHistoWorkspace diff --git a/Framework/DataObjects/src/MDHistoWorkspace.cpp b/Framework/DataObjects/src/MDHistoWorkspace.cpp index 13ac72976477d9cbfb881576065dd5ba59b4ccb3..db82718f9a9fb5344bb781cb1687aac95f60f0be 100644 --- a/Framework/DataObjects/src/MDHistoWorkspace.cpp +++ b/Framework/DataObjects/src/MDHistoWorkspace.cpp @@ -369,17 +369,8 @@ signal_t MDHistoWorkspace::getSignalAtCoord( const Mantid::API::MDNormalization &normalization) const { size_t linearIndex = this->getLinearIndexAtCoord(coords); if (linearIndex < m_length) { - // What is our normalization factor? - switch (normalization) { - case NoNormalization: - return m_signals[linearIndex]; - case VolumeNormalization: - return m_signals[linearIndex] * m_inverseVolume; - case NumEventsNormalization: - return m_signals[linearIndex] / m_numEvents[linearIndex]; - } - // Should not reach here - return m_signals[linearIndex]; + signal_t normalizer = getNormalizationFactor(normalization, linearIndex); + return m_signals[linearIndex] * normalizer; } else return std::numeric_limits<signal_t>::quiet_NaN(); } @@ -556,37 +547,8 @@ void MDHistoWorkspace::getLinePlot(const Mantid::Kernel::VMD &start, numBins[d] = dim->getNBins(); } - // Ordered list of boundaries in position-along-the-line coordinates - std::set<coord_t> boundaries; - - // Start with the start/end points, if they are within range. - if (pointInWorkspace(this, start)) - boundaries.insert(0.0f); - if (pointInWorkspace(this, end)) - boundaries.insert(length); - - // Next, we go through each dimension and see where the bin boundaries - // intersect the line. - for (size_t d = 0; d < nd; d++) { - IMDDimension_const_sptr dim = this->getDimension(d); - coord_t lineStartX = start[d]; - - if (dir[d] != 0.0) { - for (size_t i = 0; i <= dim->getNBins(); i++) { - // Position in this coordinate - coord_t thisX = dim->getX(i); - // Position along the line. Is this between the start and end of it? - coord_t linePos = (thisX - lineStartX) / dir[d]; - if (linePos >= 0 && linePos <= length) { - // Full position - VMD pos = start + (dir * linePos); - // This is a boundary if the line point is inside the workspace - if (pointInWorkspace(this, pos)) - boundaries.insert(linePos); - } - } - } - } + std::set<coord_t> boundaries = + getBinBoundariesOnLine(start, end, nd, dir, length); if (boundaries.empty()) { // Nothing at all! @@ -627,18 +589,7 @@ void MDHistoWorkspace::getLinePlot(const Mantid::Kernel::VMD &start, y.push_back(0.0); e.push_back(0.0); } else { - // What is our normalization factor? - signal_t normalizer = 1.0; - switch (normalize) { - case NoNormalization: - break; - case VolumeNormalization: - normalizer = m_inverseVolume; - break; - case NumEventsNormalization: - normalizer = 1.0 / m_numEvents[linearIndex]; - break; - } + signal_t normalizer = getNormalizationFactor(normalize, linearIndex); // And add the normalized signal/error to the list too auto signal = this->getSignalAt(linearIndex) * normalizer; if (boost::math::isinf(signal)) { @@ -657,7 +608,69 @@ void MDHistoWorkspace::getLinePlot(const Mantid::Kernel::VMD &start, } } // for each unique boundary } // if there is at least one point -} // (end function) +} + +signal_t +MDHistoWorkspace::getNormalizationFactor(const MDNormalization &normalize, + size_t linearIndex) const { + signal_t normalizer = 1.0; + switch (normalize) { + case NoNormalization: + return normalizer; + case VolumeNormalization: + return m_inverseVolume; + case NumEventsNormalization: + return 1.0 / m_numEvents[linearIndex]; + } + return normalizer; +} + +//---------------------------------------------------------------------------------------------- +/** Get ordered list of boundaries in position-along-the-line coordinates + * + * @param start :: start of the line + * @param end :: end of the line + * @param nd :: number of dimensions + * @param dir :: vector of the direction + * @param length :: unit-vector of the direction + * @returns :: ordered list of boundaries + */ +std::set<coord_t> +MDHistoWorkspace::getBinBoundariesOnLine(const VMD &start, const VMD &end, + size_t nd, const VMD &dir, + coord_t length) const { + std::set<coord_t> boundaries; + + // Start with the start/end points, if they are within range. + if (pointInWorkspace(this, start)) + boundaries.insert(0.0f); + if (pointInWorkspace(this, end)) + boundaries.insert(length); + + // Next, we go through each dimension and see where the bin boundaries + // intersect the line. + for (size_t d = 0; d < nd; d++) { + IMDDimension_const_sptr dim = getDimension(d); + coord_t lineStartX = start[d]; + + if (dir[d] != 0.0) { + for (size_t i = 0; i <= dim->getNBins(); i++) { + // Position in this coordinate + coord_t thisX = dim->getX(i); + // Position along the line. Is this between the start and end of it? + coord_t linePos = (thisX - lineStartX) / dir[d]; + if (linePos >= 0 && linePos <= length) { + // Full position + VMD pos = start + (dir * linePos); + // This is a boundary if the line point is inside the workspace + if (pointInWorkspace(this, pos)) + boundaries.insert(linePos); + } + } + } + } + return boundaries; +} //============================================================================================== //============================== ARITHMETIC OPERATIONS