Skip to content
Snippets Groups Projects
Commit a8808633 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #21208 Add new methods to PeaksWorkspace

parent 3d0b7a65
No related merge requests found
......@@ -80,6 +80,13 @@ public:
*/
virtual void addPeak(const Mantid::Geometry::IPeak &ipeak) = 0;
//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param position :: V3D positon of the peak.
* @param position :: Coordinate system frame of the peak position.
*/
virtual void addPeak(const Kernel::V3D &position, const Kernel::SpecialCoordinateSystem &frame) = 0;
//---------------------------------------------------------------------------------------------
/** Return a reference to the Peak
* @param peakNum :: index of the peak to get.
......@@ -113,7 +120,17 @@ public:
*/
virtual Mantid::Geometry::IPeak *
createPeak(const Mantid::Kernel::V3D &QLabFrame,
boost::optional<double> detectorDistance) const = 0;
boost::optional<double> detectorDistance= boost::none) const = 0;
//---------------------------------------------------------------------------------------------
/** Create an instance of a Peak
* @param position :: enter of the peak in the specified frame
* @param frame :: the coordinate frame that the position is specified in.
* @return a pointer to a new Peak object.
*/
virtual std::unique_ptr<Mantid::Geometry::IPeak>
createPeak(const Mantid::Kernel::V3D &position,
const Mantid::Kernel::SpecialCoordinateSystem &frame) const = 0;
/**
* Create an instance of a peak using a V3D
......
......@@ -102,12 +102,18 @@ public:
void addPeak(const Geometry::IPeak &peak) override;
/// Move a peak object into this peaks workspace
void addPeak(Peak &&peak);
void addPeak(const Kernel::V3D &position, const Kernel::SpecialCoordinateSystem &frame) override;
Peak &getPeak(int peakNum) override;
const Peak &getPeak(int peakNum) const override;
Geometry::IPeak *createPeak(
const Kernel::V3D &QLabFrame,
boost::optional<double> detectorDistance = boost::none) const override;
std::unique_ptr<Geometry::IPeak> createPeak(
const Kernel::V3D &Position,
const Kernel::SpecialCoordinateSystem& frame) const override;
std::vector<std::pair<std::string, std::string>>
peakInfo(const Kernel::V3D &qFrame, bool labCoords) const override;
......@@ -192,6 +198,8 @@ private:
void initColumns();
/// Adds a new PeakColumn of the given type
void addPeakColumn(const std::string &name);
/// Create a peak from a QSample position
Peak *createPeakQSample(const Kernel::V3D &position) const;
// ====================================== ITableWorkspace Methods
// ==================================
......
......@@ -183,6 +183,17 @@ void PeaksWorkspace::addPeak(const Geometry::IPeak &ipeak) {
}
}
//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param position :: position on the peak in the specified coordinate frame
* @param frame :: the coordinate frame that the position is specified in
*/
void PeaksWorkspace::addPeak(const V3D &position, const SpecialCoordinateSystem &frame)
{
auto peak = createPeak(position, frame);
addPeak(*peak);
}
//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param peak :: Peak object to add (move) into this.
......@@ -239,6 +250,42 @@ PeaksWorkspace::createPeak(const Kernel::V3D &QLabFrame,
return peak;
}
//---------------------------------------------------------------------------------------------
/** Creates an instance of a Peak BUT DOES NOT ADD IT TO THE WORKSPACE
* @param position :: position of the center of the peak, in reciprocal space
* @param frame :: the coordinate system that the position is specified in
* detector. You do NOT need to explicitly provide this distance.
* @return a pointer to a new Peak object.
*/
std::unique_ptr<Geometry::IPeak>
PeaksWorkspace::createPeak(const Kernel::V3D &position,
const Kernel::SpecialCoordinateSystem &frame) const {
if (frame == Mantid::Kernel::HKL) {
return std::unique_ptr<Geometry::IPeak>(createPeakHKL(position));
} else if (frame == Mantid::Kernel::QLab) {
return std::unique_ptr<Geometry::IPeak>(createPeak(position));
} else {
return std::unique_ptr<Geometry::IPeak>(createPeakQSample(position));
}
}
//---------------------------------------------------------------------------------------------
/** Creates an instance of a Peak BUT DOES NOT ADD IT TO THE WORKSPACE
* @param position :: QSample position of the center of the peak, in reciprocal space
* detector. You do NOT need to explicitly provide this distance.
* @return a pointer to a new Peak object.
*/
Peak *PeaksWorkspace::createPeakQSample(const V3D &position) const
{
// Create a peak from QSampleFrame
const auto goniometer = run().getGoniometer();
// create a peak using the qLab frame
auto peak = new Peak(getInstrument(), position, goniometer.getR());
// Take the run number from this
peak->setRunNumber(getRunNumber());
return peak;
}
/**
* Returns selected information for a "peak" at QLabFrame.
*
......
......@@ -37,6 +37,10 @@ IPeak *createPeakQLabWithDistance(IPeaksWorkspace &self, const object &data,
Mantid::PythonInterface::Converters::PyObjectToV3D(data)(),
detectorDistance);
}
/// Create a peak via it's QLab value from a list or numpy array
void addPeak(IPeaksWorkspace &self, const IPeak& peak) {
self.addPeak(peak);
}
}
void export_IPeaksWorkspace() {
......@@ -45,7 +49,7 @@ void export_IPeaksWorkspace() {
boost::noncopyable>("IPeaksWorkspace", no_init)
.def("getNumberPeaks", &IPeaksWorkspace::getNumberPeaks, arg("self"),
"Returns the number of peaks within the workspace")
.def("addPeak", &IPeaksWorkspace::addPeak, (arg("self"), arg("peak")),
.def("addPeak", addPeak, (arg("self"), arg("peak")),
"Add a peak to the workspace")
.def("removePeak", &IPeaksWorkspace::removePeak,
(arg("self"), arg("peak_num")), "Remove a peak from the workspace")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment