Commit 3e7341a8 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #10878. Peak type has a shape

parent 80546ace
......@@ -39,7 +39,11 @@ public:
Peak(Geometry::Instrument_const_sptr m_inst, double scattering,
double m_Wavelength);
/// Copy constructor
Peak(const Peak& other);
// Construct a peak from a reference to the interface
explicit Peak(const API::IPeak &ipeak);
virtual ~Peak();
......@@ -116,7 +120,19 @@ public:
double getValueByColName(const std::string &name) const;
/// Get the peak shape.
const PeakShape& getPeakShape();
/// Set the PeakShape
void setPeakShape(PeakShape* shape);
/// Assignment
Peak& operator=(const Peak& other);
private:
/// Shared pointer to the instrument (for calculating some values )
Geometry::Instrument_const_sptr m_inst;
......@@ -188,7 +204,7 @@ private:
std::set<int> m_detIDs;
/// Peak shape
//boost::scoped_ptr<PeakShape> m_peakShape;
boost::scoped_ptr<const PeakShape> m_peakShape;
};
} // namespace Mantid
......
#include "MantidDataObjects/Peak.h"
#include "MantidDataObjects/NoShape.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"
#include "MantidGeometry/Objects/InstrumentRayTracer.h"
#include "MantidKernel/Strings.h"
......@@ -20,7 +21,7 @@ Peak::Peak()
: m_H(0), m_K(0), m_L(0), m_Intensity(0), m_SigmaIntensity(0),
m_BinCount(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_RunNumber(0), m_MonitorCount(0),
orig_H(0), orig_K(0), orig_L(0) {}
orig_H(0), orig_K(0), orig_L(0), m_peakShape(new NoShape) {}
//----------------------------------------------------------------------------------------------
/** Constructor that uses the Q position of the peak (in the lab frame).
......@@ -36,7 +37,7 @@ Peak::Peak(Geometry::Instrument_const_sptr m_inst,
: m_H(0), m_K(0), m_L(0), m_Intensity(0), m_SigmaIntensity(0),
m_BinCount(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_RunNumber(0), m_MonitorCount(0),
orig_H(0), orig_K(0), orig_L(0) {
orig_H(0), orig_K(0), orig_L(0), m_peakShape(new NoShape) {
this->setInstrument(m_inst);
this->setQLabFrame(QLabFrame, detectorDistance);
}
......@@ -59,7 +60,7 @@ Peak::Peak(Geometry::Instrument_const_sptr m_inst,
: m_H(0), m_K(0), m_L(0), m_Intensity(0), m_SigmaIntensity(0),
m_BinCount(0), m_GoniometerMatrix(goniometer),
m_InverseGoniometerMatrix(goniometer), m_RunNumber(0), m_MonitorCount(0),
orig_H(0), orig_K(0), orig_L(0) {
orig_H(0), orig_K(0), orig_L(0), m_peakShape(new NoShape) {
if (fabs(m_InverseGoniometerMatrix.Invert()) < 1e-8)
throw std::invalid_argument(
"Peak::ctor(): Goniometer matrix must non-singular.");
......@@ -80,7 +81,7 @@ Peak::Peak(Geometry::Instrument_const_sptr m_inst, int m_DetectorID,
: m_H(0), m_K(0), m_L(0), m_Intensity(0), m_SigmaIntensity(0),
m_BinCount(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_RunNumber(0), m_MonitorCount(0),
orig_H(0), orig_K(0), orig_L(0) {
orig_H(0), orig_K(0), orig_L(0), m_peakShape(new NoShape) {
this->setInstrument(m_inst);
this->setDetectorID(m_DetectorID);
this->setWavelength(m_Wavelength);
......@@ -100,7 +101,7 @@ Peak::Peak(Geometry::Instrument_const_sptr m_inst, int m_DetectorID,
: m_H(HKL[0]), m_K(HKL[1]), m_L(HKL[2]), m_Intensity(0),
m_SigmaIntensity(0), m_BinCount(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_RunNumber(0), m_MonitorCount(0),
orig_H(0), orig_K(0), orig_L(0) {
orig_H(0), orig_K(0), orig_L(0), m_peakShape(new NoShape) {
this->setInstrument(m_inst);
this->setDetectorID(m_DetectorID);
this->setWavelength(m_Wavelength);
......@@ -122,7 +123,7 @@ Peak::Peak(Geometry::Instrument_const_sptr m_inst, int m_DetectorID,
: m_H(HKL[0]), m_K(HKL[1]), m_L(HKL[2]), m_Intensity(0),
m_SigmaIntensity(0), m_BinCount(0), m_GoniometerMatrix(goniometer),
m_InverseGoniometerMatrix(goniometer), m_RunNumber(0), m_MonitorCount(0),
orig_H(0), orig_K(0), orig_L(0) {
orig_H(0), orig_K(0), orig_L(0), m_peakShape(new NoShape) {
if (fabs(m_InverseGoniometerMatrix.Invert()) < 1e-8)
throw std::invalid_argument(
"Peak::ctor(): Goniometer matrix must non-singular.");
......@@ -143,13 +144,36 @@ Peak::Peak(Geometry::Instrument_const_sptr m_inst, double scattering,
: m_H(0), m_K(0), m_L(0), m_Intensity(0), m_SigmaIntensity(0),
m_BinCount(0), m_GoniometerMatrix(3, 3, true),
m_InverseGoniometerMatrix(3, 3, true), m_RunNumber(0), m_MonitorCount(0),
orig_H(0), orig_K(0), orig_L(0) {
orig_H(0), orig_K(0), orig_L(0), m_peakShape(new NoShape) {
this->setInstrument(m_inst);
this->setWavelength(m_Wavelength);
m_DetectorID = -1;
detPos = V3D(sin(scattering), 0.0, cos(scattering));
}
/**
* @brief Copy constructor
* @param other : Source
* @return
*/
Peak::Peak(const Peak &other)
: m_inst(other.m_inst), m_det(other.m_det), m_BankName(other.m_BankName),
m_DetectorID(other.m_DetectorID), m_H(other.m_H), m_K(other.m_K),
m_L(other.m_L), m_Intensity(other.m_Intensity),
m_SigmaIntensity(other.m_SigmaIntensity), m_BinCount(other.m_BinCount),
m_InitialEnergy(other.m_InitialEnergy),
m_FinalEnergy(other.m_FinalEnergy),
m_GoniometerMatrix(other.m_GoniometerMatrix),
m_InverseGoniometerMatrix(other.m_InverseGoniometerMatrix),
m_RunNumber(other.m_RunNumber), m_MonitorCount(other.m_MonitorCount),
m_Row(other.m_Row), m_Col(other.m_Col), sourcePos(other.sourcePos),
samplePos(other.samplePos), detPos(other.detPos), orig_H(other.orig_H),
orig_K(other.orig_K), orig_L(other.orig_L), m_detIDs(other.m_detIDs),
m_peakShape(other.m_peakShape->clone())
{
}
//----------------------------------------------------------------------------------------------
/** Constructor making a Peak from IPeak interface
*
......@@ -166,7 +190,9 @@ Peak::Peak(const API::IPeak &ipeak)
m_GoniometerMatrix(ipeak.getGoniometerMatrix()),
m_InverseGoniometerMatrix(ipeak.getGoniometerMatrix()),
m_RunNumber(ipeak.getRunNumber()),
m_MonitorCount(ipeak.getMonitorCount()) {
m_MonitorCount(ipeak.getMonitorCount()),
m_peakShape(new NoShape)
{
if (fabs(m_InverseGoniometerMatrix.Invert()) < 1e-8)
throw std::invalid_argument(
"Peak::ctor(): Goniometer matrix must non-singular.");
......@@ -795,6 +821,55 @@ double Peak::getValueByColName(const std::string &name_in) const {
name);
}
/**
* @brief Get the peak shape
* @return : const ref to current peak shape.
*/
const PeakShape &Peak::getPeakShape() { return *this->m_peakShape; }
/**
* @brief Set the peak shape
* @param shape : Desired shape
*/
void Peak::setPeakShape(PeakShape *shape) { this->m_peakShape.reset(shape); }
/**
* @brief Assignement operator overload
* @param other : Other peak object to assign from
* @return this
*/
Peak &Peak::operator=(const Peak &other) {
if(&other != this){
m_inst = other.m_inst;
m_det = other.m_det;
m_BankName = other.m_BankName;
m_DetectorID = other.m_DetectorID;
m_H = other.m_H;
m_K = other.m_K;
m_L = other.m_L;
m_Intensity = other.m_Intensity;
m_SigmaIntensity = other.m_SigmaIntensity;
m_BinCount = other.m_BinCount;
m_InitialEnergy = other.m_InitialEnergy;
m_FinalEnergy = other.m_FinalEnergy;
m_GoniometerMatrix = other.m_GoniometerMatrix;
m_InverseGoniometerMatrix = other.m_InverseGoniometerMatrix;
m_RunNumber = other.m_RunNumber;
m_MonitorCount = other.m_MonitorCount;
m_Row = other.m_Row;
m_Col = other.m_Col;
sourcePos = other.sourcePos;
samplePos = other.samplePos;
detPos = other.detPos;
orig_H = other.orig_H;
orig_K = other.orig_K;
orig_L = other.orig_L;
m_detIDs = other.m_detIDs;
m_peakShape.reset(other.m_peakShape->clone());
}
return *this;
}
/**
Forwarding function. Exposes the detector position directly.
*/
......
......@@ -17,6 +17,21 @@ class MockPeakShapeFactory : public PeakShapeFactory {
virtual ~MockPeakShapeFactory() {}
};
class MockPeakShape : public PeakShape
{
public:
MOCK_CONST_METHOD0(frame, Mantid::API::SpecialCoordinateSystem() );
MOCK_CONST_METHOD0(toJSON, std::string() );
MOCK_CONST_METHOD0(clone, PeakShape*() );
MOCK_CONST_METHOD0(algorithmName, std::string() );
MOCK_CONST_METHOD0(algorithmVersion, int() ) ;
MOCK_CONST_METHOD0(shapeName, std::string() );
virtual ~MockPeakShape() {}
};
}
}
......
......@@ -2,10 +2,12 @@
#define MANTID_DATAOBJECTS_PEAKTEST_H_
#include <cxxtest/TestSuite.h>
#include "MockObjects.h"
#include "MantidKernel/Timer.h"
#include "MantidKernel/System.h"
#include <iostream>
#include <iomanip>
#include <gmock/gmock.h>
#include "MantidDataObjects/Peak.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
......@@ -110,9 +112,9 @@ public:
TS_ASSERT_EQUALS(p.getL(), p2.getL());
TS_ASSERT_EQUALS(p.getGoniometerMatrix(), p2.getGoniometerMatrix());
TS_ASSERT_EQUALS(p.getRunNumber(), p2.getRunNumber());
TS_ASSERT_EQUALS(p.getDetector(), p2.getDetector())
TS_ASSERT_EQUALS(p.getInstrument(), p2.getInstrument())
TS_ASSERT_EQUALS(p.getDetector(), p2.getDetector());
TS_ASSERT_EQUALS(p.getInstrument(), p2.getInstrument());
TS_ASSERT_EQUALS(p.getPeakShape().shapeName(), p2.getPeakShape().shapeName());
check_Contributing_Detectors(p2, std::vector<int>(1, 10102));
}
......@@ -352,6 +354,29 @@ public:
TSM_ASSERT_THROWS("Detector is not valid", p.getDetectorPosition(), Mantid::Kernel::Exception::NullPointerException&);
}
void test_get_peak_shape_default()
{
Peak peak;
const PeakShape& integratedShape = peak.getPeakShape();
TS_ASSERT_EQUALS("none", integratedShape.shapeName());
}
void test_set_peak_shape()
{
using namespace testing;
Peak peak;
MockPeakShape* replacementShape = new MockPeakShape;
EXPECT_CALL(*replacementShape, shapeName()).Times(1);
peak.setPeakShape(replacementShape);
const PeakShape& currentShape = peak.getPeakShape();
currentShape.shapeName();
TS_ASSERT(Mock::VerifyAndClearExpectations(replacementShape));
}
private:
void check_Contributing_Detectors(const Peak & peak, const std::vector<int> & expected)
{
......
Markdown is supported
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