Mantid
Loading...
Searching...
No Matches
MDHistoDimension.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include <utility>
10
11#include "MantidGeometry/DllConfig.h"
15#include "MantidKernel/MDUnit.h"
16
17namespace Mantid {
18namespace Geometry {
19
28class MANTID_GEOMETRY_DLL MDHistoDimension : public IMDDimension {
29public:
38 MDHistoDimension(std::string name, std::string ID, const MDFrame &frame, coord_t min, coord_t max, size_t numBins)
39 : m_name(std::move(name)), m_dimensionId(std::move(ID)), m_frame(frame.clone()), m_min(min), m_max(max),
40 m_numBins(numBins), m_binWidth((max - min) / static_cast<coord_t>(numBins)) {
41 if (max < min) {
42 throw std::invalid_argument("Error making MDHistoDimension. Cannot have "
43 "dimension with min > max");
44 }
45 }
46
51 : m_name(other->getName()), m_dimensionId(other->getDimensionId()), m_frame(other->getMDFrame().clone()),
52 m_min(other->getMinimum()), m_max(other->getMaximum()), m_numBins(other->getNBins()),
53 m_binWidth(other->getBinWidth()) {}
54
56 std::string getName() const override { return m_name; }
57
59 const MDFrame &getMDFrame() const override { return *m_frame; }
60
62 const Kernel::UnitLabel getUnits() const override { return m_frame->getUnitLabel(); }
63
65 const Kernel::MDUnit &getMDUnits() const override { return m_frame->getMDUnit(); }
66
71 const std::string &getDimensionId() const override { return m_dimensionId; }
72
74 coord_t getMaximum() const override { return m_max; }
75
77 coord_t getMinimum() const override { return m_min; }
78
81 size_t getNBins() const override { return m_numBins; }
82
84 size_t getNBoundaries() const override { return m_numBins + 1; }
85
87 std::string toXMLString() const override;
88
90 coord_t getX(size_t index) const override { return static_cast<coord_t>(index) * m_binWidth + m_min; }
91
93 coord_t getBinWidth() const override { return m_binWidth; }
94
100 void setRange(size_t nBins, coord_t min, coord_t max) override {
101 if (max < min) {
102 throw std::invalid_argument("Error making MDHistoDimension. Cannot have "
103 "dimension with min > max");
104 }
105 m_min = min;
106 m_max = max;
107 m_numBins = nBins;
108 m_binWidth = (m_max - m_min) / static_cast<coord_t>(m_numBins);
109 }
110
119 void setMDFrame(const MDFrame &frame) { m_frame.reset(frame.clone()); }
120
121private:
123 std::string m_name;
124
126 std::string m_dimensionId;
127
130
133
136
138 size_t m_numBins;
139
142};
143
145using MDHistoDimension_sptr = std::shared_ptr<MDHistoDimension>;
146
148using MDHistoDimension_const_sptr = std::shared_ptr<const MDHistoDimension>;
149
150} // namespace Geometry
151} // namespace Mantid
std::string name
Definition Run.cpp:60
std::map< DeltaEMode::Type, std::string > index
specnum_t m_min
specnum_t m_max
std::string getName(const IMDDimension &self)
The class describes one dimension of multidimensional dataset representing an orthogonal dimension an...
MDFrame : The coordinate frame for a dimension, or set of dimensions in a multidimensional workspace.
Definition MDFrame.h:22
virtual MDFrame * clone() const =0
void setRange(size_t nBins, coord_t min, coord_t max) override
Change the extents and number of bins.
MDHistoDimension(std::string name, std::string ID, const MDFrame &frame, coord_t min, coord_t max, size_t numBins)
Constructor for simple MDHistoDimension.
coord_t getMaximum() const override
Returns the maximum extent of this dimension.
coord_t getMinimum() const override
Returns the minimum extent of this dimension.
Geometry::MDFrame_uptr m_frame
Multidimensional frame.
size_t getNBoundaries() const override
number of bin boundaries (axis points)
coord_t getBinWidth() const override
Return the width of one bin.
coord_t getX(size_t index) const override
Get coordinate for index;.
const MDFrame & getMDFrame() const override
Return the md frame.
const Kernel::UnitLabel getUnits() const override
Return the units of the dimension as a string.
const Kernel::MDUnit & getMDUnits() const override
Returns the unit.
void setMDFrame(const MDFrame &frame)
Set the MDFrame.
std::string getName() const override
Return the name of the dimension as can be displayed along the axis.
coord_t m_min
Extent of dimension.
coord_t m_max
Extent of dimension.
coord_t m_binWidth
Calculated bin size.
const std::string & getDimensionId() const override
Short name which identify the dimension among other dimension.
size_t getNBins() const override
number of bins dimension have (an integrated has one).
MDHistoDimension(const IMDDimension *other)
copy constructor
MDUnit : Unit type for multidimensional data types.
Definition MDUnit.h:20
A base-class for the a class that is able to return unit labels in different representations.
Definition UnitLabel.h:20
std::unique_ptr< MDFrame > MDFrame_uptr
Definition MDFrame.h:36
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
std::shared_ptr< const MDHistoDimension > MDHistoDimension_const_sptr
Shared pointer to a const MDHistoDimension.
Helper class which provides the Collimation Length for SANS instruments.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition MDTypes.h:27
STL namespace.