Commit dcc092df authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #10878. No peak possibility

Add an type for representing no peak shape (position only). Also refactor to move common working code into a PeakShapeBase class. This is useful for serialization to ensure that there are no two diverging methods for serializing types of PeakShape.
parent c9264e51
......@@ -11,6 +11,8 @@ set ( SRC_FILES
src/OffsetsWorkspace.cpp
src/Peak.cpp
src/PeakColumn.cpp
src/PeakShapeBase.cpp
src/PeakShapeNone.cpp
src/PeakShapeSpherical.cpp
src/PeakShapeSphericalFactory.cpp
src/PeaksWorkspace.cpp
......@@ -45,7 +47,9 @@ set ( INC_FILES
inc/MantidDataObjects/Peak.h
inc/MantidDataObjects/PeakColumn.h
inc/MantidDataObjects/PeakShape.h
inc/MantidDataObjects/PeakShapeBase.h
inc/MantidDataObjects/PeakShapeFactory.h
inc/MantidDataObjects/PeakShapeNone.h
inc/MantidDataObjects/PeakShapeSpherical.h
inc/MantidDataObjects/PeakShapeSphericalFactory.h
inc/MantidDataObjects/PeaksWorkspace.h
......@@ -71,6 +75,7 @@ set ( TEST_FILES
MementoTableWorkspaceTest.h
OffsetsWorkspaceTest.h
PeakColumnTest.h
PeakShapeNoneTest.h
PeakShapeSphericalFactoryTest.h
PeakShapeSphericalTest.h
PeakTest.h
......
......@@ -7,6 +7,8 @@
#include "MantidKernel/V3D.h"
#include "MantidKernel/PhysicalConstants.h"
#include "MantidKernel/System.h"
#include "MantidDataObjects/PeakShape.h"
#include <boost/scoped_ptr.hpp>
namespace Mantid {
namespace DataObjects {
......@@ -184,6 +186,9 @@ private:
/// List of contributing detectors IDs
std::set<int> m_detIDs;
/// Peak shape
//boost::scoped_ptr<PeakShape> m_peakShape;
};
} // namespace Mantid
......
......@@ -2,6 +2,7 @@
#define MANTID_DATAOBJECTS_PEAKSHAPE_H_
#include "MantidKernel/System.h"
#include "MantidKernel/VMD.h"
#include "MantidAPI/SpecialCoordinateSystem.h"
namespace Mantid {
......@@ -36,14 +37,18 @@ public:
virtual Mantid::API::SpecialCoordinateSystem frame() const = 0;
/// Serialize
virtual std::string toJSON() const = 0;
/// Deep copy a Peak
virtual PeakShape* clone() const = 0;
/// Deep copy this
virtual PeakShape *clone() const = 0;
/// Algorithm
virtual std::string algorithmName() const = 0;
/// Algorithm Version
virtual int algorithmVersion() const = 0;
/// Peak centre
virtual Mantid::Kernel::VMD centre() const = 0;
/// Shape name
virtual std::string shapeName() const = 0;
/// Destructor
virtual ~PeakShape(){}
virtual ~PeakShape() {}
};
} // namespace DataObjects
......
#ifndef MANTID_DATAOBJECTS_PEAKSHAPEBASE_H_
#define MANTID_DATAOBJECTS_PEAKSHAPEBASE_H_
#include "MantidKernel/System.h"
#include "MantidDataObjects/PeakShape.h"
#include "MantidAPI/SpecialCoordinateSystem.h"
#include "MantidKernel/V3D.h"
namespace Json {
// Forward declaration
class Value;
}
namespace Mantid {
namespace DataObjects {
/** PeakShapeBase : Base class for concrete PeakShapes containing common code.
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeBase : public PeakShape {
public:
/// Constructor
PeakShapeBase(const Mantid::Kernel::VMD &peakCentre,
API::SpecialCoordinateSystem frame,
std::string algorithmName = std::string(),
int algorithmVersion = -1);
/// Destructor
virtual ~PeakShapeBase();
/// Get the coordinate frame
API::SpecialCoordinateSystem frame() const;
/// Get the name of the algorithm used to make this shape
std::string algorithmName() const;
/// Get the version of the algorithm used to make this shape
int algorithmVersion() const;
/// Get the centre of the peak
Mantid::Kernel::VMD centre() const;
protected:
/// Copy constructor
PeakShapeBase(const PeakShapeBase &other);
/// Assignment operator
PeakShapeBase &operator=(const PeakShapeBase &other);
/// Peak centre
Mantid::Kernel::VMD m_centre;
/// Special coordinate system
Mantid::API::SpecialCoordinateSystem m_frame;
/// Generating algorithm name
std::string m_algorithmName;
/// Generating algorithm version
int m_algorithmVersion;
/// Build common parts of outgoing JSON serialization
void buildCommon(Json::Value &root) const;
/// Equals operator
bool operator==(const PeakShapeBase &other) const;
};
} // namespace DataObjects
} // namespace Mantid
#endif /* MANTID_DATAOBJECTS_PEAKSHAPEBASE_H_ */
......@@ -4,54 +4,53 @@
#include "MantidKernel/System.h"
#include <boost/shared_ptr.hpp>
namespace Mantid
{
namespace DataObjects
{
namespace Mantid {
namespace DataObjects {
// Forward declaration
class PeakShape;
/** PeakShapeFactory : Factory for creating peak shapes
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeFactory
{
public:
/// Destructor
virtual ~PeakShapeFactory(){};
/// Make the product
virtual PeakShape* create(const std::string& source) const = 0;
/// Set the successor factory. create will be called on that if this instance is not suitable.
virtual void setSuccessor(boost::shared_ptr<const PeakShapeFactory> successorFactory) = 0;
};
/// Helper typedef
typedef boost::shared_ptr<PeakShapeFactory> PeakShapeFactory_sptr;
/// Helper typedef
typedef boost::shared_ptr<const PeakShapeFactory> PeakShapeFactory_const_sptr;
/** PeakShapeFactory : Factory for creating peak shapes
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeFactory {
public:
/// Destructor
virtual ~PeakShapeFactory(){};
/// Make the product
virtual PeakShape *create(const std::string &source) const = 0;
/// Set the successor factory. create will be called on that if this instance
/// is not suitable.
virtual void
setSuccessor(boost::shared_ptr<const PeakShapeFactory> successorFactory) = 0;
};
/// Helper typedef
typedef boost::shared_ptr<PeakShapeFactory> PeakShapeFactory_sptr;
/// Helper typedef
typedef boost::shared_ptr<const PeakShapeFactory> PeakShapeFactory_const_sptr;
} // namespace DataObjects
} // namespace Mantid
#endif /* MANTID_DATAOBJECTS_PEAKSHAPEFACTORY_H_ */
#endif /* MANTID_DATAOBJECTS_PEAKSHAPEFACTORY_H_ */
#ifndef MANTID_DATAOBJECTS_PEAKSHAPENONE_H_
#define MANTID_DATAOBJECTS_PEAKSHAPENONE_H_
#include "MantidKernel/System.h"
#include "MantidDataObjects/PeakShapeBase.h"
namespace Mantid {
namespace DataObjects {
/** PeakShapeNone : No peak shape positional representation only.
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeNone : public PeakShapeBase {
public:
/// Constructor
PeakShapeNone(const Mantid::Kernel::VMD &peakCentre,
API::SpecialCoordinateSystem frame,
std::string algorithmName = std::string(),
int algorithmVersion = -1);
/// Destructor
virtual ~PeakShapeNone();
/// Copy constructor
PeakShapeNone(const PeakShapeNone &other);
/// Assignment operator
PeakShapeNone &operator=(const PeakShapeNone &other);
/// Serialization method
virtual std::string toJSON() const;
/// Clone the peak shape
virtual PeakShapeNone *clone() const;
/// Shape name
std::string shapeName() const;
/// Equals operator
bool operator==(const PeakShapeNone &other) const;
};
} // namespace DataObjects
} // namespace Mantid
#endif /* MANTID_DATAOBJECTS_PEAKSHAPENONE_H_ */
......@@ -3,83 +3,66 @@
#include "MantidKernel/System.h"
#include "MantidKernel/VMD.h"
#include "MantidDataObjects/PeakShape.h"
#include "MantidDataObjects/PeakShapeBase.h"
#include "MantidAPI/SpecialCoordinateSystem.h"
namespace Mantid
{
namespace DataObjects
{
/** PeakShapeSpherical : PeakShape for a spherical peak
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeSpherical : public PeakShape
{
public:
/// Constructor
PeakShapeSpherical(const Mantid::Kernel::VMD& peakCentre, const double& peakRadius, API::SpecialCoordinateSystem frame, std::string algorithmName = std::string(), int algorithmVersion = -1);
/// Destructor
virtual ~PeakShapeSpherical();
/// Copy constructor
PeakShapeSpherical(const PeakShapeSpherical& other);
/// Assignment operator
PeakShapeSpherical& operator=(const PeakShapeSpherical& other);
/// Creation coordinate frame (coordinate frame used to create shape)
virtual API::SpecialCoordinateSystem frame() const;
/// Serialization method
virtual std::string toJSON() const;
/// Peak algorithm name
virtual std::string algorithmName() const;
/// Peak algorithm version
virtual int algorithmVersion() const;
/// Clone the peak shape
virtual PeakShapeSpherical* clone() const;
/// Equals operator
bool operator==(const PeakShapeSpherical& other) const;
/// Peak centre
Mantid::Kernel::VMD centre() const;
/// Peak radius
double radius() const;
private:
/// Peak radius
double m_radius;
/// Peak centre
Mantid::Kernel::VMD m_centre;
/// Special coordinate system
Mantid::API::SpecialCoordinateSystem m_frame;
/// Generating algorithm name
std::string m_algorithmName;
/// Generating algorithm version
int m_algorithmVersion;
};
namespace Mantid {
namespace DataObjects {
/** PeakShapeSpherical : PeakShape for a spherical peak
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeSpherical : public PeakShapeBase {
public:
/// Constructor
PeakShapeSpherical(const Mantid::Kernel::VMD &peakCentre,
const double &peakRadius,
API::SpecialCoordinateSystem frame,
std::string algorithmName = std::string(),
int algorithmVersion = -1);
/// Destructor
virtual ~PeakShapeSpherical();
/// Copy constructor
PeakShapeSpherical(const PeakShapeSpherical &other);
/// Assignment operator
PeakShapeSpherical &operator=(const PeakShapeSpherical &other);
/// Serialization method
virtual std::string toJSON() const;
/// Clone the peak shape
virtual PeakShapeSpherical *clone() const;
/// Shape name
std::string shapeName() const;
/// Equals operator
bool operator==(const PeakShapeSpherical &other) const;
/// Peak radius
double radius() const;
private:
/// Peak radius
double m_radius;
};
} // namespace DataObjects
} // namespace Mantid
#endif /* MANTID_DATAOBJECTS_PEAKSHAPESPHERICAL_H_ */
#endif /* MANTID_DATAOBJECTS_PEAKSHAPESPHERICAL_H_ */
......@@ -4,56 +4,53 @@
#include "MantidKernel/System.h"
#include "MantidDataObjects/PeakShapeFactory.h"
namespace Mantid
{
namespace DataObjects
{
namespace Mantid {
namespace DataObjects {
// Forward declare
class PeakShape;
/** PeakShapeSphericalFactory : Factory for spherical peak shapes for de-serializing from JSON.
*
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeSphericalFactory : public PeakShapeFactory
{
public:
/// Constructor
PeakShapeSphericalFactory();
/// Destructor
virtual ~PeakShapeSphericalFactory();
/// Make product
PeakShape* create(const std::string &source) const;
/// Set a successor should this factory be unsuitable
void setSuccessor(PeakShapeFactory_const_sptr successorFactory);
private:
/// Successor factory
PeakShapeFactory_const_sptr m_successor;
};
/** PeakShapeSphericalFactory : Factory for spherical peak shapes for
de-serializing from JSON.
*
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport PeakShapeSphericalFactory : public PeakShapeFactory {
public:
/// Constructor
PeakShapeSphericalFactory();
/// Destructor
virtual ~PeakShapeSphericalFactory();
/// Make product
PeakShape *create(const std::string &source) const;
/// Set a successor should this factory be unsuitable
void setSuccessor(PeakShapeFactory_const_sptr successorFactory);
private:
/// Successor factory
PeakShapeFactory_const_sptr m_successor;
};
} // namespace DataObjects
} // namespace Mantid
#endif /* MANTID_DATAOBJECTS_PEAKSHAPESPHERICALFACTORY_H_ */
#endif /* MANTID_DATAOBJECTS_PEAKSHAPESPHERICALFACTORY_H_ */
<
#include "MantidDataObjects/PeakShapeBase.h"
#include "MantidAPI/SpecialCoordinateSystem.h"
#include "MantidKernel/V3D.h"
#include <jsoncpp/json/json.h>
namespace Mantid {
namespace DataObjects {
PeakShapeBase::PeakShapeBase(const Kernel::VMD &peakCentre,
API::SpecialCoordinateSystem frame,
std::string algorithmName, int algorithmVersion)
: m_centre(peakCentre), m_frame(frame), m_algorithmName(algorithmName),
m_algorithmVersion(algorithmVersion) {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
PeakShapeBase::~PeakShapeBase() {}
/**
* @brief Copy constructor
* @param other : source of the copy
*/
PeakShapeBase::PeakShapeBase(const PeakShapeBase &other)
: m_centre(other.centre()), m_frame(other.frame()),
m_algorithmName(other.algorithmName()),
m_algorithmVersion(other.algorithmVersion()) {}
/**
* @brief Assignment operator
* @param other : source of the assignment
* @return Ref to assigned object.
*/