Commit 7e787421 authored by Walsh, Michael's avatar Walsh, Michael Committed by Peterson, Peter
Browse files

merged and fixed runtime issue mostly

parent 1821674f
......@@ -7,7 +7,10 @@
#pragma once
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidHistogramData/Histogram.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/V3D.h"
namespace Mantid {
namespace Algorithms {
......@@ -52,7 +55,10 @@ public:
void updateMinMax(int index);
private:
Kernel::V3D &position(int index);
const HistogramData::HistogramY &histogramY(int index);
API::MatrixWorkspace_sptr workspace;
const API::SpectrumInfo *spectrumInfo;
double x = 0;
double y = 0;
double centerX;
......@@ -62,6 +68,10 @@ private:
double yMin = 0;
double yMax = 0;
const int m_specID = 0;
int m_cachedPositionIndex = -1;
int m_cachedHistogramYIndex = -1;
Kernel::V3D m_cachedPosition;
const HistogramData::HistogramY *m_cachedHistogramY;
};
} // namespace Algorithms
......
......@@ -114,14 +114,15 @@ double initBoundingBox(WorkspaceBoundingBox &boundingBox, const int numSpec, con
// In subsequent iterations check if spectra fits in the normalized bounding box(generated by previous iterations)
// If so, update position
double updateBoundingBox(WorkspaceBoundingBox &boundingBox, WorkspaceBoundingBox previousBoundingBox, const int numSpec,
const double beamRadius, const bool directBeam) {
double updateBoundingBox(WorkspaceBoundingBox &boundingBox, WorkspaceBoundingBox &previousBoundingBox,
const int numSpec, const double beamRadius, const bool directBeam) {
double totalCount = 0;
const auto spectrumInfo = boundingBox.getWorkspace()->spectrumInfo();
for (int i = 0; i < numSpec; i++) {
if (!boundingBox.isValidWs(i))
continue;
const V3D position = boundingBox.getWorkspace()->spectrumInfo().position(i);
const V3D position = spectrumInfo.position(i);
if (previousBoundingBox.containsPoint(position.X(), position.Y())) {
if (!boundingBox.isOutOfBoundsOfNonDirectBeam(beamRadius, i, directBeam))
......
#include "MantidAlgorithms/WorkspaceBoundingBox.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/SpectrumInfo.h"
namespace Mantid {
namespace Algorithms {
WorkspaceBoundingBox::WorkspaceBoundingBox(API::MatrixWorkspace_sptr workspace) : workspace(workspace) {}
WorkspaceBoundingBox::WorkspaceBoundingBox(API::MatrixWorkspace_sptr workspace) {
this->workspace = workspace;
this->spectrumInfo = &workspace->spectrumInfo();
}
WorkspaceBoundingBox::WorkspaceBoundingBox() {}
WorkspaceBoundingBox::~WorkspaceBoundingBox() {}
Kernel::V3D &WorkspaceBoundingBox::position(int index) {
if (m_cachedPositionIndex == -1 || m_cachedPositionIndex != index) {
m_cachedPosition = this->spectrumInfo->position(index);
m_cachedPositionIndex = index;
}
return m_cachedPosition;
}
const HistogramData::HistogramY &WorkspaceBoundingBox::histogramY(int index) {
if (m_cachedHistogramYIndex == -1 || m_cachedHistogramYIndex != index) {
auto &YIn = this->workspace->y(index);
m_cachedHistogramY = &YIn;
m_cachedHistogramYIndex = index;
}
return *m_cachedHistogramY;
}
void WorkspaceBoundingBox::setPosition(double x, double y) {
this->x = x;
this->y = y;
......@@ -35,17 +54,16 @@ void WorkspaceBoundingBox::setBounds(double xMin, double xMax, double yMin, doub
* @return true/false if its valid
*/
bool WorkspaceBoundingBox::isValidWs(int index) {
const auto spectrumInfo = this->workspace->spectrumInfo();
if (!spectrumInfo.hasDetectors(index)) {
if (!this->spectrumInfo->hasDetectors(index)) {
g_log.warning() << "Workspace index " << index << " has no detector assigned to it - discarding\n";
return false;
}
// Skip if we have a monitor or if the detector is masked.
if (spectrumInfo.isMonitor(index) || spectrumInfo.isMasked(index))
if (this->spectrumInfo->isMonitor(index) || this->spectrumInfo->isMasked(index))
return false;
// Get the current spectrum
const auto &YIn = this->workspace->y(index);
auto &YIn = this->histogramY(index);
// Skip if NaN of inf
if (std::isnan(YIn[m_specID]) || std::isinf(YIn[m_specID]))
return false;
......@@ -73,10 +91,9 @@ int WorkspaceBoundingBox::findFirstValidWs(const int numSpec) {
* @return number of points of histogram data at index
*/
double WorkspaceBoundingBox::updatePositionAndReturnCount(int index) {
const auto spectrumInfo = this->workspace->spectrumInfo();
const auto &YIn = this->workspace->y(index);
double x = spectrumInfo.position(index).X();
double y = spectrumInfo.position(index).Y();
auto &YIn = this->histogramY(index);
double x = this->position(index).X();
double y = this->position(index).Y();
this->x += YIn[m_specID] * x;
this->y += YIn[m_specID] * y;
return YIn[m_specID];
......@@ -88,9 +105,8 @@ double WorkspaceBoundingBox::updatePositionAndReturnCount(int index) {
* @param index :: index of spectrum data
*/
void WorkspaceBoundingBox::updateMinMax(int index) {
const auto spectrumInfo = this->workspace->spectrumInfo();
double x = spectrumInfo.position(index).X();
double y = spectrumInfo.position(index).Y();
double x = this->position(index).X();
double y = this->position(index).Y();
this->xMin = std::min(x, this->xMin);
this->xMax = std::max(x, this->xMax);
this->yMin = std::min(y, this->yMin);
......@@ -105,9 +121,8 @@ void WorkspaceBoundingBox::updateMinMax(int index) {
* @return number of points of histogram data at index
*/
bool WorkspaceBoundingBox::isOutOfBoundsOfNonDirectBeam(const double beamRadius, int index, const bool directBeam) {
const auto spectrumInfo = this->workspace->spectrumInfo();
double x = spectrumInfo.position(index).X();
double y = spectrumInfo.position(index).Y();
double x = this->position(index).X();
double y = this->position(index).Y();
if (!directBeam) {
double dx = x - this->centerX;
double dy = y - this->centerY;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment