Mantid
Loading...
Searching...
No Matches
ComponentInfo.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2017 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 "MantidBeamline/ComponentType.h"
10#include "MantidBeamline/PixelGridComponent.h"
11#include "MantidGeometry/DllConfig.h"
17#include "MantidTypes/Core/DateAndTime.h"
18#include <limits>
19#include <memory>
20#include <set>
21#include <tuple>
22#include <unordered_map>
23#include <vector>
24
25namespace Mantid {
26
27namespace Kernel {
28class Quat;
29class V2D;
30class V3D;
31} // namespace Kernel
32
33namespace Geometry {
34class IComponent;
35class IObject;
36} // namespace Geometry
37
38namespace Beamline {
39class ComponentInfo;
40}
41
42namespace Geometry {
43class Instrument;
44
48class MANTID_GEOMETRY_DLL ComponentInfo {
49public:
51 static constexpr size_t invalidIndex = std::numeric_limits<size_t>::max();
52
53private:
55 std::unique_ptr<Beamline::ComponentInfo> m_componentInfo;
57 std::shared_ptr<const std::vector<Geometry::IComponent *>> m_componentIds;
59 std::shared_ptr<const std::unordered_map<Geometry::IComponent const *, size_t>> m_compIDToIndex;
60
62 std::shared_ptr<std::vector<std::shared_ptr<const Geometry::IObject>>> m_shapes;
63
65 std::shared_ptr<ParameterInfo> m_parameterInfo;
66
67 template <class T> std::vector<T> getParameter(size_t componentIndex, const std::string &name, bool recursive) const;
68
70 template <class T>
71 void addTypedParameter(const size_t componentIndex, const std::string &type, const std::string &name, const T &value,
72 const std::string *const pDescription, const std::string &pVisible);
73
76 ParameterInfo &mutableParameterInfo();
77
78 BoundingBox componentBoundingBox(const size_t index, const BoundingBox *reference,
79 const bool excludeMonitors = false) const;
80
82 ComponentInfo(const ComponentInfo &other);
83 void growBoundingBoxAsRectuangularBank(size_t index, const Geometry::BoundingBox *reference,
84 Geometry::BoundingBox &mutableBB, const bool excludeMonitors = false) const;
85 void growBoundingBoxAsOutline(size_t index, const Geometry::BoundingBox *reference, Geometry::BoundingBox &mutableBB,
86 const bool excludeMonitors = false) const;
87
88public:
90 size_t topLeft;
91 size_t bottomLeft;
93 size_t topRight;
94 size_t nX;
95 size_t nY;
96 };
97
98 ComponentInfo(std::unique_ptr<Beamline::ComponentInfo> componentInfo,
99 std::shared_ptr<const std::vector<Mantid::Geometry::IComponent *>> componentIds,
100 std::shared_ptr<const std::unordered_map<Geometry::IComponent const *, size_t>> componentIdToIndexMap,
101 std::shared_ptr<std::vector<std::shared_ptr<const Geometry::IObject>>> shapes,
102 std::shared_ptr<ParameterInfo> parameterInfo = nullptr);
106 std::unique_ptr<ComponentInfo> cloneWithoutDetectorInfo() const;
107 std::vector<size_t> detectorsInSubtree(size_t componentIndex) const;
108 std::vector<size_t> componentsInSubtree(size_t componentIndex) const;
109 const std::vector<size_t> &children(size_t componentIndex) const;
110 size_t size() const;
111 size_t getMemorySize() const;
112 QuadrilateralComponent quadrilateralComponent(const size_t componentIndex) const;
113 size_t indexOf(Geometry::IComponent const *id) const;
115 size_t indexOfOrInvalid(Geometry::IComponent const *id) const;
116 size_t indexOfAny(const std::string &name) const;
117 bool uniqueName(const std::string &name) const;
118 bool isDetector(const size_t componentIndex) const;
119 Kernel::V3D position(const size_t componentIndex) const;
120 Kernel::V3D position(const std::pair<size_t, size_t> &index) const;
121 Kernel::Quat rotation(const size_t componentIndex) const;
122 Kernel::Quat rotation(const std::pair<size_t, size_t> &index) const;
123 Kernel::V3D relativePosition(const size_t componentIndex) const;
124 Kernel::Quat relativeRotation(const size_t componentIndex) const;
125 void setPosition(size_t componentIndex, const Kernel::V3D &newPosition);
126 void setRotation(size_t componentIndex, const Kernel::Quat &newRotation);
127 void setPosition(const std::pair<size_t, size_t> &index, const Kernel::V3D &newPosition);
128 void setRotation(const std::pair<size_t, size_t> &index, const Kernel::Quat &newRotation);
129 void scaleComponent(const size_t componentIndex, const Kernel::V3D &newScaling);
130 void scaleComponent(const std::pair<size_t, size_t> &index, const Kernel::V3D &newScaling);
131 size_t parent(const size_t componentIndex) const;
132 bool hasParent(const size_t componentIndex) const;
133 bool hasDetectorInfo() const;
134 Kernel::V3D sourcePosition() const;
135 Kernel::V3D samplePosition() const;
136 bool hasSource() const;
137 bool hasEquivalentSource(const ComponentInfo &other) const;
138 bool hasSample() const;
139 bool hasEquivalentSample(const ComponentInfo &other) const;
140 bool hasDetectors(const size_t componentIndex) const;
141 size_t source() const;
142 size_t sample() const;
143 double l1() const;
144 Kernel::V3D scaleFactor(const size_t componentIndex) const;
145 const std::string &name(const size_t componentIndex) const;
146 void setScaleFactor(const size_t componentIndex, const Kernel::V3D &scaleFactor);
147 Kernel::V2D sideBySideViewPosition(const size_t componentIndex) const;
148 Beamline::PixelGridComponent pixelGridComponent(const size_t componentIndex) const;
149 size_t detectorIndexAtXYZ(const size_t componentIndex, const int x, const int y, const int z) const;
150 std::tuple<int, int, int> xyzForDetectorID(const size_t componentIndex, const detid_t detectorID) const;
151 bool isGridDetector(size_t const componentIndex) const;
152 size_t root() const;
153
154 const IComponent *componentID(const size_t componentIndex) const { return (*m_componentIds)[componentIndex]; }
155 bool hasValidShape(const size_t componentIndex) const;
156
157 const Geometry::IObject &shape(const size_t componentIndex) const;
158 std::unordered_map<std::shared_ptr<const Geometry::IObject>, std::vector<size_t>> shapeToComponentIndices() const;
159
160 double solidAngle(const size_t componentIndex, const Geometry::SolidAngleParams &params) const;
161 BoundingBox boundingBox(const size_t componentIndex, const BoundingBox *reference = nullptr,
162 const bool excludeMonitors = false) const;
163 Beamline::ComponentType componentType(const size_t componentIndex) const;
164 void setScanInterval(const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> &interval);
165 size_t scanCount() const;
166 void merge(const ComponentInfo &other);
167
172
173 size_t findBankParent(size_t index, const std::string &bankPart) const;
174
176 std::string fullName(const size_t componentIndex) const;
177
179 size_t indexOfFullName(const std::string &fullName) const;
180
182 bool hasParameter(const size_t componentIndex, const std::string &name, bool recursive = true) const;
183 std::set<std::string> getParameterNames(const size_t componentIndex, bool recursive = true) const;
185 const ParameterInfo::ComponentParameters &parameters(const size_t componentIndex) const;
186 std::vector<double> getNumberParameter(const size_t componentIndex, const std::string &name,
187 bool recursive = true) const;
188 std::vector<int> getIntParameter(const size_t componentIndex, const std::string &name, bool recursive = true) const;
189 std::vector<bool> getBoolParameter(const size_t componentIndex, const std::string &name, bool recursive = true) const;
190 std::vector<std::string> getStringParameter(const size_t componentIndex, const std::string &name,
191 bool recursive = true) const;
192 double getFittingParameter(const size_t componentIndex, const std::string &name, double xvalue) const;
193
195 void addParameter(const size_t componentIndex, const std::string &type, const std::string &name,
196 const std::string &value, const std::string *const pDescription = nullptr,
197 const std::string &pVisible = "true");
199 void addDouble(const size_t componentIndex, const std::string &name, double value,
200 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
202 void addInt(const size_t componentIndex, const std::string &name, int value,
203 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
205 void addBool(const size_t componentIndex, const std::string &name, bool value,
206 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
208 void addString(const size_t componentIndex, const std::string &name, const std::string &value,
209 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
211 void addV3D(const size_t componentIndex, const std::string &name, const Kernel::V3D &value,
212 const std::string *const pDescription = nullptr);
214 void addQuat(const size_t componentIndex, const std::string &name, const Kernel::Quat &value,
215 const std::string *const pDescription = nullptr);
217 void addFittingParameter(const size_t componentIndex, const std::string &name, const std::string &fittingFunction,
218 const std::string &value, const std::string *const pDescription = nullptr,
219 const std::string &pVisible = "true");
222 void clearParameter(const size_t componentIndex, const std::string &name);
223
226 const std::shared_ptr<ParameterInfo> &sharedParameterInfo() const { return m_parameterInfo; }
227
228 friend class Instrument;
229};
230
233
234} // namespace Geometry
235} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double position
Definition GetAllEi.cpp:154
std::map< DeltaEMode::Type, std::string > index
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
void(ComponentInfo::* setPosition)(const size_t, const Mantid::Kernel::V3D &)
void(ComponentInfo::* setRotation)(const size_t, const Mantid::Kernel::Quat &)
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
ComponentInfoIterator for random access iteration over ComponentInfo.
ComponentInfo : Provides a component centric view on to the instrument.
const std::shared_ptr< ParameterInfo > & sharedParameterInfo() const
This allows ParameterMap to delegate to ParameterInfo, rather than keeping a parallel copy that would...
ComponentInfo & operator=(const ComponentInfo &)=delete
Copy assignment is not possible for ComponentInfo.
std::shared_ptr< std::vector< std::shared_ptr< const Geometry::IObject > > > m_shapes
Shapes for each component.
std::shared_ptr< const std::unordered_map< Geometry::IComponent const *, size_t > > m_compIDToIndex
Map of component ids to indexes.
const IComponent * componentID(const size_t componentIndex) const
std::shared_ptr< ParameterInfo > m_parameterInfo
The instrument's named parameters, keyed by component index.
std::unique_ptr< Beamline::ComponentInfo > m_componentInfo
Pointer to the actual ComponentInfo object (non-wrapping part).
std::shared_ptr< const std::vector< Geometry::IComponent * > > m_componentIds
Collection of component ids.
base class for Geometric IComponent
Definition IComponent.h:53
IObject : Interface for geometry objects.
Definition IObject.h:42
Base Instrument Class.
Definition Instrument.h:49
ParameterInfo : the named parameters of an instrument, addressed by component index.
std::multimap< std::string, std::shared_ptr< Parameter >, Kernel::CaseInsensitiveStringComparator > ComponentParameters
Parameters of a single component, ordered by name.
Class for quaternions.
Definition Quat.h:39
Implements a 2-dimensional vector embedded in a 3D space, i.e.
Definition V2D.h:29
Class for 3D vectors.
Definition V3D.h:34
ComponentInfoIterator< const ComponentInfo > ComponentInfoConstIt
ComponentInfoIterator< ComponentInfo > ComponentInfoIt
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.