diff --git a/Framework/API/inc/MantidAPI/IPeaksWorkspace.h b/Framework/API/inc/MantidAPI/IPeaksWorkspace.h index 0af11c860daee982355528a76e3907a721036666..22923b7dbc557cc6dab6aa24d433473fc434e3ed 100644 --- a/Framework/API/inc/MantidAPI/IPeaksWorkspace.h +++ b/Framework/API/inc/MantidAPI/IPeaksWorkspace.h @@ -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 diff --git a/Framework/DataObjects/inc/MantidDataObjects/PeaksWorkspace.h b/Framework/DataObjects/inc/MantidDataObjects/PeaksWorkspace.h index 2bdbd533ff90e4c116fa85a5fb295ed050095792..ce4717bd0cf551994ff4343c7cf24501ee011e71 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/PeaksWorkspace.h +++ b/Framework/DataObjects/inc/MantidDataObjects/PeaksWorkspace.h @@ -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 // ================================== diff --git a/Framework/DataObjects/src/PeaksWorkspace.cpp b/Framework/DataObjects/src/PeaksWorkspace.cpp index 301c714e2c6f5a474e161fe5bc73a93c2e900315..4d07437962052b819b1f12aa1d9baced538e7913 100644 --- a/Framework/DataObjects/src/PeaksWorkspace.cpp +++ b/Framework/DataObjects/src/PeaksWorkspace.cpp @@ -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. * diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IPeaksWorkspace.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IPeaksWorkspace.cpp index 8eeb370e494d6f1569208e0125381ef57ea611c0..115732cfb949fd559a147e1aad091f497d12f376 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/IPeaksWorkspace.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/IPeaksWorkspace.cpp @@ -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")