Skip to content

Commit

Permalink
Refs #5187: fix non-spectra axis in SliceViewer
Browse files Browse the repository at this point in the history
for Workspace2D
  • Loading branch information
Janik Zikovsky committed May 1, 2012
1 parent ab3b5db commit d41ccd5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/NumericAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MANTID_API_DLL NumericAxis: public Axis
std::string label(const std::size_t& index)const;
/// Create bin boundaries from the point values
std::vector<double> createBinBoundaries() const;
const std::vector<double> & getValues() const;
private:
/// Private, undefined copy assignment operator
const NumericAxis& operator=(const NumericAxis&);
Expand Down
18 changes: 18 additions & 0 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,25 @@ namespace Mantid
{
coord_t x = coords[0];
coord_t y = coords[1];

// First, find the workspace index
NumericAxis * ax1 = dynamic_cast<NumericAxis*>(this->getAxis(1));

// If a spectra/text axis, just use the Y coord as the workspace index
size_t wi = size_t(y);
if (ax1)
{
const MantidVec & yVals = ax1->getValues();
MantidVec::const_iterator it = std::lower_bound(yVals.begin(), yVals.end(), y);
if (it == yVals.end())
{
// Out of range
return std::numeric_limits<double>::quiet_NaN();
}
// The workspace index is the point in the vector that we found
wi = it - yVals.begin();
}

if (wi < this->getNumberHistograms())
{
const MantidVec & X = this->readX(wi);
Expand Down
9 changes: 9 additions & 0 deletions Code/Mantid/Framework/API/src/NumericAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,14 @@ std::vector<double> NumericAxis::createBinBoundaries() const
return boundaries;
}

/** Get a const reference to the vector of values in this axis
*
* @return the values vector
*/
const std::vector<double> & NumericAxis::getValues() const
{
return m_values;
}

} // namespace API
} // namespace Mantid

0 comments on commit d41ccd5

Please sign in to comment.