Skip to content

Commit

Permalink
refs #10878. Peak type has a shape
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 14, 2015
1 parent 80546ac commit 3e7341a
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 12 deletions.
18 changes: 17 additions & 1 deletion Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Peak.h
Expand Up @@ -39,7 +39,11 @@ class DLLExport Peak : public API::IPeak {
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();

Expand Down Expand Up @@ -116,7 +120,19 @@ class DLLExport Peak : public API::IPeak {

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;

Expand Down Expand Up @@ -188,7 +204,7 @@ class DLLExport Peak : public API::IPeak {
std::set<int> m_detIDs;

/// Peak shape
//boost::scoped_ptr<PeakShape> m_peakShape;
boost::scoped_ptr<const PeakShape> m_peakShape;
};

} // namespace Mantid
Expand Down
91 changes: 83 additions & 8 deletions Code/Mantid/Framework/DataObjects/src/Peak.cpp
@@ -1,4 +1,5 @@
#include "MantidDataObjects/Peak.h"
#include "MantidDataObjects/NoShape.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"
#include "MantidGeometry/Objects/InstrumentRayTracer.h"
#include "MantidKernel/Strings.h"
Expand All @@ -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).
Expand All @@ -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);
}
Expand All @@ -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.");
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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.");
Expand All @@ -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
*
Expand All @@ -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.");
Expand Down Expand Up @@ -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.
*/
Expand Down
15 changes: 15 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/MockObjects.h
Expand Up @@ -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() {}
};

}
}

Expand Down
31 changes: 28 additions & 3 deletions Code/Mantid/Framework/DataObjects/test/PeakTest.h
Expand Up @@ -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"
Expand Down Expand Up @@ -110,9 +112,9 @@ class PeakTest : public CxxTest::TestSuite
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));
}

Expand Down Expand Up @@ -352,6 +354,29 @@ class PeakTest : public CxxTest::TestSuite
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)
{
Expand Down

0 comments on commit 3e7341a

Please sign in to comment.