Skip to content

Commit

Permalink
refs #10904. Ellipsoid shape.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Feb 5, 2015
1 parent 4427109 commit 2387ce5
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/DataObjects/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ set ( SRC_FILES
src/PeakColumn.cpp
src/PeakNoShapeFactory.cpp
src/PeakShapeBase.cpp
src/PeakShapeEllipsoid.cpp
src/PeakShapeSpherical.cpp
src/PeakShapeSphericalFactory.cpp
src/PeaksWorkspace.cpp
Expand Down Expand Up @@ -51,6 +52,7 @@ set ( INC_FILES
inc/MantidDataObjects/PeakNoShapeFactory.h
inc/MantidDataObjects/PeakShape.h
inc/MantidDataObjects/PeakShapeBase.h
inc/MantidDataObjects/PeakShapeEllipsoid.h
inc/MantidDataObjects/PeakShapeFactory.h
inc/MantidDataObjects/PeakShapeSpherical.h
inc/MantidDataObjects/PeakShapeSphericalFactory.h
Expand Down Expand Up @@ -79,6 +81,7 @@ set ( TEST_FILES
OffsetsWorkspaceTest.h
PeakColumnTest.h
PeakNoShapeFactoryTest.h
PeakShapeEllipsoidTest.h
PeakShapeSphericalFactoryTest.h
PeakShapeSphericalTest.h
PeakTest.h
Expand Down
@@ -0,0 +1,84 @@
#ifndef MANTID_DATAOBJECTS_PEAKSHAPEELLIPSOID_H_
#define MANTID_DATAOBJECTS_PEAKSHAPEELLIPSOID_H_

#include "MantidKernel/System.h"
#include "MantidKernel/V3D.h"
#include "MantidDataObjects/PeakShapeBase.h"


namespace Mantid
{
namespace DataObjects
{

/** PeakShapeEllipsoid : PeakShape representing a 3D ellipsoid
Copyright © 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 PeakShapeEllipsoid : public PeakShapeBase
{
public:
/// Constructor
PeakShapeEllipsoid(std::vector<Mantid::Kernel::V3D> directions, std::vector<double> abcRadius, std::vector<double> abcBackgroundInnerRadius, std::vector<double> abcBackgroundOuterRadius, API::SpecialCoordinateSystem frame,
std::string algorithmName = std::string(),
int algorithmVersion = -1);
/// Copy constructor
PeakShapeEllipsoid(const PeakShapeEllipsoid& other);
/// Assignment operator
PeakShapeEllipsoid& operator=(const PeakShapeEllipsoid& other);
/// Equals operator
bool operator==(const PeakShapeEllipsoid& other) const;
/// Destructor
virtual ~PeakShapeEllipsoid();
/// Get radii
std::vector<double> abcRadii() const;
/// Get background inner radii
std::vector<double> abcRadiiBackgroundInner() const;
/// Get background outer radii
std::vector<double> abcRadiiBackgroundOuter() const;
/// Get ellipsoid directions
std::vector<Mantid::Kernel::V3D> directions() const;

/// PeakShape interface
std::string toJSON() const;
/// Clone ellipsoid
PeakShape *clone() const;
/// Get the peak shape
std::string shapeName() const;

private:
/// principle axis
std::vector<Mantid::Kernel::V3D> m_directions;
/// radii
std::vector<double> m_abc_radii;
/// inner radii
std::vector<double> m_abc_radiiBackgroundInner;
/// outer radii
std::vector<double> m_abc_radiiBackgroundOuter;


};


} // namespace DataObjects
} // namespace Mantid

#endif /* MANTID_DATAOBJECTS_PEAKSHAPEELLIPSOID_H_ */
105 changes: 105 additions & 0 deletions Code/Mantid/Framework/DataObjects/src/PeakShapeEllipsoid.cpp
@@ -0,0 +1,105 @@
#include "MantidDataObjects/PeakShapeEllipsoid.h"
#include "MantidKernel/cow_ptr.h"
#include <jsoncpp/json/json.h>

namespace Mantid {
namespace DataObjects {

PeakShapeEllipsoid::PeakShapeEllipsoid(
std::vector<Kernel::V3D> directions, std::vector<double> abcRadii,
std::vector<double> abcRadiiBackgroundInner,
std::vector<double> abcRadiiBackgroundOuter,
API::SpecialCoordinateSystem frame, std::string algorithmName,
int algorithmVersion)
: PeakShapeBase(frame, algorithmName, algorithmVersion),
m_directions(directions), m_abc_radii(abcRadii),
m_abc_radiiBackgroundInner(abcRadiiBackgroundInner),
m_abc_radiiBackgroundOuter(abcRadiiBackgroundOuter) {

if (directions.size() != 3) {
throw std::invalid_argument("directions must be of size 3");
}
if (abcRadii.size() != 3) {
throw std::invalid_argument("radii must be of size 3");
}
if (abcRadiiBackgroundInner.size() != 3) {
throw std::invalid_argument("radii inner must be of size 3");
}
if (abcRadiiBackgroundOuter.size() != 3) {
throw std::invalid_argument("radii outer must be of size 3");
}
}

PeakShapeEllipsoid::PeakShapeEllipsoid(const PeakShapeEllipsoid &other)
: PeakShapeBase(other), m_directions(other.directions()),
m_abc_radii(other.abcRadii()),
m_abc_radiiBackgroundInner(other.abcRadiiBackgroundInner()),
m_abc_radiiBackgroundOuter(other.abcRadiiBackgroundOuter()) {}

PeakShapeEllipsoid &PeakShapeEllipsoid::
operator=(const PeakShapeEllipsoid &other) {
if (&other != this) {
PeakShapeBase::operator=(other);
m_directions = other.directions();
m_abc_radii = other.abcRadii();
m_abc_radiiBackgroundInner = other.abcRadiiBackgroundInner();
m_abc_radiiBackgroundOuter = other.abcRadiiBackgroundOuter();
}
return *this;
}

bool PeakShapeEllipsoid::operator==(const PeakShapeEllipsoid &other) const {
return PeakShapeBase::operator==(other) &&
other.directions() == this->directions() &&
other.abcRadii() == this->abcRadii() &&
other.abcRadiiBackgroundInner() == this->abcRadiiBackgroundInner() &&
other.abcRadiiBackgroundOuter() == this->abcRadiiBackgroundOuter();
}

PeakShapeEllipsoid::~PeakShapeEllipsoid() {}

std::vector<double> PeakShapeEllipsoid::abcRadii() const { return m_abc_radii; }

std::vector<double> PeakShapeEllipsoid::abcRadiiBackgroundInner() const {
return m_abc_radiiBackgroundInner;
}

std::vector<double> PeakShapeEllipsoid::abcRadiiBackgroundOuter() const {
return m_abc_radiiBackgroundOuter;
}

std::vector<Kernel::V3D> PeakShapeEllipsoid::directions() const {
return m_directions;
}

std::string PeakShapeEllipsoid::toJSON() const {
Json::Value root;
PeakShapeBase::buildCommon(root);
root["radius0"] = Json::Value(m_abc_radii[0]);
root["radius1"] = Json::Value(m_abc_radii[1]);
root["radius2"] = Json::Value(m_abc_radii[2]);

root["background_inner_radius0"] = Json::Value(m_abc_radiiBackgroundInner[0]);
root["background_inner_radius1"] = Json::Value(m_abc_radiiBackgroundInner[1]);
root["background_inner_radius2"] = Json::Value(m_abc_radiiBackgroundInner[2]);

root["background_outer_radius0"] = Json::Value(m_abc_radiiBackgroundOuter[0]);
root["background_outer_radius1"] = Json::Value(m_abc_radiiBackgroundOuter[1]);
root["background_outer_radius2"] = Json::Value(m_abc_radiiBackgroundOuter[2]);

root["direction0"] = m_directions[0].toString();
root["direction1"] = m_directions[1].toString();
root["direction2"] = m_directions[2].toString();

Json::StyledWriter writer;
return writer.write(root);
}

PeakShape *PeakShapeEllipsoid::clone() const {
return new PeakShapeEllipsoid(*this);
}

std::string PeakShapeEllipsoid::shapeName() const { return "ellipsoid"; }

} // namespace DataObjects
} // namespace Mantid

0 comments on commit 2387ce5

Please sign in to comment.