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"
16#include "MantidKernel/MDUnit.h"
18#include "MantidKernel/VMD.h"
19
20namespace Mantid {
21namespace Geometry {
22
31class MANTID_GEOMETRY_DLL MDHistoDimension : public IMDDimension {
32public:
41 MDHistoDimension(std::string name, std::string ID, const MDFrame &frame, coord_t min, coord_t max, size_t numBins)
42 : m_name(std::move(name)), m_dimensionId(std::move(ID)), m_frame(frame.clone()), m_min(min), m_max(max),
43 m_numBins(numBins), m_binWidth((max - min) / static_cast<coord_t>(numBins)) {
44 if (max < min) {
45 throw std::invalid_argument("Error making MDHistoDimension. Cannot have "
46 "dimension with min > max");
47 }
48 }
49
54 : m_name(other->getName()), m_dimensionId(other->getDimensionId()), m_frame(other->getMDFrame().clone()),
55 m_min(other->getMinimum()), m_max(other->getMaximum()), m_numBins(other->getNBins()),
56 m_binWidth(other->getBinWidth()) {}
57
59 std::string getName() const override { return m_name; }
60
62 const MDFrame &getMDFrame() const override { return *m_frame; }
63
65 const Kernel::UnitLabel getUnits() const override { return m_frame->getUnitLabel(); }
66
68 const Kernel::MDUnit &getMDUnits() const override { return m_frame->getMDUnit(); }
69
74 const std::string &getDimensionId() const override { return m_dimensionId; }
75
77 coord_t getMaximum() const override { return m_max; }
78
80 coord_t getMinimum() const override { return m_min; }
81
84 size_t getNBins() const override { return m_numBins; }
85
87 size_t getNBoundaries() const override { return m_numBins + 1; }
88
90 std::string toXMLString() const override;
91
93 coord_t getX(size_t index) const override { return static_cast<coord_t>(index) * m_binWidth + m_min; }
94
96 coord_t getBinWidth() const override { return m_binWidth; }
97
103 void setRange(size_t nBins, coord_t min, coord_t max) override {
104 if (max < min) {
105 throw std::invalid_argument("Error making MDHistoDimension. Cannot have "
106 "dimension with min > max");
107 }
108 m_min = min;
109 m_max = max;
110 m_numBins = nBins;
111 m_binWidth = (m_max - m_min) / static_cast<coord_t>(m_numBins);
112 }
113
122 void setMDFrame(const MDFrame &frame) { m_frame.reset(frame.clone()); }
123
124private:
126 std::string m_name;
127
129 std::string m_dimensionId;
130
133
136
139
141 size_t m_numBins;
142
145};
146
148using MDHistoDimension_sptr = std::shared_ptr<MDHistoDimension>;
149
151using MDHistoDimension_const_sptr = std::shared_ptr<const MDHistoDimension>;
152
153} // namespace Geometry
154} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
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...
Definition: IMDDimension.h:39
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.