Mantid
Loading...
Searching...
No Matches
ComponentInfo.cpp
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 +
10#include "MantidKernel/Quat.h"
11#include "MantidKernel/V3D.h"
14#include "MantidPythonInterface/geometry/ComponentInfoPythonIterator.h"
15
16#include <boost/python/class.hpp>
17#include <boost/python/copy_const_reference.hpp>
18#include <boost/python/dict.hpp>
19#include <boost/python/reference_existing_object.hpp>
20#include <boost/python/return_value_policy.hpp>
21
25using Mantid::PythonInterface::ComponentInfoPythonIterator;
28using namespace boost::python;
29
30namespace {
31ComponentInfoPythonIterator make_pyiterator(ComponentInfo &componentInfo) {
32 return ComponentInfoPythonIterator(componentInfo);
33}
34
35dict shapeToComponentIndices(const ComponentInfo &componentInfo) {
36 dict result;
37 const auto shapeMap = componentInfo.shapeToComponentIndices();
38 for (const auto &shape : shapeMap) {
39 const auto csgObject = std::dynamic_pointer_cast<const Mantid::Geometry::CSGObject>(shape.first);
40 if (csgObject != nullptr) {
41 result[csgObject->getShapeXML()] = shape.second;
42 }
43 }
44 return result;
45}
46
47} // namespace
48
49// Function pointers to help resolve ambiguity
51
53
54void (ComponentInfo::*setPosition)(const size_t, const Mantid::Kernel::V3D &) = &ComponentInfo::setPosition;
55
56void (ComponentInfo::*setRotation)(const size_t, const Mantid::Kernel::Quat &) = &ComponentInfo::setRotation;
57
58// Export ComponentInfo
60 class_<ComponentInfo, boost::noncopyable>("ComponentInfo", no_init)
61
62 .def("__iter__", make_pyiterator)
63
64 .def("__len__", &ComponentInfo::size, arg("self"), "Returns the number of components.")
65
66 .def("size", &ComponentInfo::size, arg("self"), "Returns the number of components.")
67
68 .def("isDetector", &ComponentInfo::isDetector, (arg("self"), arg("index")),
69 "Checks if the component is a detector.")
70
71 .def("detectorsInSubtree", &ComponentInfo::detectorsInSubtree, return_value_policy<VectorToNumpy>(),
72 (arg("self"), arg("index")),
73 "Returns a list of detectors in the subtree for the component "
74 "identified by 'index'.")
75
76 .def("componentsInSubtree", &ComponentInfo::componentsInSubtree, return_value_policy<VectorToNumpy>(),
77 (arg("self"), arg("index")),
78 "Returns a list of components in the subtree for the component "
79 "identified by 'index'.")
80
81 .def("position", position, (arg("self"), arg("index")),
82 "Returns the absolute position of the component identified by "
83 "'index'.")
84
85 .def("rotation", rotation, (arg("self"), arg("index")),
86 "Returns the absolute rotation of the component identified by "
87 "'index'.")
88
89 .def("relativePosition", &ComponentInfo::relativePosition, (arg("self"), arg("index")),
90 "Returns the absolute relative position of the component identified "
91 "by 'index'.")
92
93 .def("relativeRotation", &ComponentInfo::relativeRotation, (arg("self"), arg("index")),
94 "Returns the absolute relative rotation of the component identified "
95 "by 'index'.")
96
97 .def("setPosition", setPosition, (arg("self"), arg("index"), arg("newPosition")),
98 "Set the absolute position of the component identified by 'index'.")
99
100 .def("setRotation", setRotation, (arg("self"), arg("index"), arg("newRotation")),
101 "Set the absolute rotation of the component identified by 'index'.")
102
103 .def("hasSource", &ComponentInfo::hasSource, arg("self"), "Returns True if a source is present.")
104
105 .def("hasEquivalentSource", &ComponentInfo::hasEquivalentSource, arg("self"), arg("other"),
106 "Returns True is both beamlines either lack a Source or "
107 "have a Source at the same position.")
108
109 .def("hasSample", &ComponentInfo::hasSample, arg("self"), "Returns True if a sample is present.")
110
111 .def("hasEquivalentSample", &ComponentInfo::hasEquivalentSample, arg("self"), arg("other"),
112 "Returns True is both beamlines either lack a Sample or "
113 "have a Sample at the same position.")
114
115 .def("source", &ComponentInfo::source, arg("self"), "Returns the source component index.")
116
117 .def("sample", &ComponentInfo::sample, arg("self"), "Returns the sample component index.")
118
119 .def("sourcePosition", &ComponentInfo::sourcePosition, arg("self"), "Returns the source position.")
120
121 .def("samplePosition", &ComponentInfo::samplePosition, arg("self"), "Returns the sample position.")
122
123 .def("hasParent", &ComponentInfo::hasParent, (arg("self"), arg("index")),
124 "Returns True only if the component identified by 'index' has a "
125 "parent component.")
126
127 .def("parent", &ComponentInfo::parent, (arg("self"), arg("index")),
128 "Returns the parent component of the component identified by "
129 "'index'.")
130
131 .def("children", &ComponentInfo::children, (arg("self"), arg("index")),
132 return_value_policy<VectorRefToNumpy<WrapReadOnly>>(),
133 "Returns a list of child components for the component identified by "
134 "'index'.")
135
136 .def("name", &ComponentInfo::name, (arg("self"), arg("index")), return_value_policy<copy_const_reference>(),
137 "Returns the name of the component identified by 'index'.")
138
139 .def("l1", &ComponentInfo::l1, arg("self"), "Returns the l1 value.")
140
141 .def("scaleFactor", &ComponentInfo::scaleFactor, (arg("self"), arg("index")),
142 "Returns the scale factor for the component identified by 'index'.")
143
144 .def("setScaleFactor", &ComponentInfo::setScaleFactor, (arg("self"), arg("index"), arg("scaleFactor")),
145 "Set the scale factor of the component identifed by 'index'.")
146
147 .def("hasValidShape", &ComponentInfo::hasValidShape, (arg("self"), arg("index")),
148 "Returns True if the component identified by 'index' has a valid "
149 "shape.")
150
151 .def("shape", &ComponentInfo::shape, (arg("self"), arg("index")),
152 return_value_policy<reference_existing_object>(),
153 "Returns the shape of the component identified by 'index'.")
154
155 .def("indexOfAny", &ComponentInfo::indexOfAny, (arg("self"), arg("name")),
156 "Returns the index of any component matching name. Raises "
157 "ValueError if name not found")
158
159 .def("uniqueName", &ComponentInfo::uniqueName, (arg("self"), arg("name")),
160 "Returns True if the name is a unique single occurance. Zero occurances yields False.")
161
162 .def("root", &ComponentInfo::root, arg("self"), "Returns the index of the root component")
163 .def("getMemorySize", &ComponentInfo::getMemorySize, arg("self"),
164 "Return the memory footprint of the component info in bytes.")
165 .def("shapeToComponentIndices", &shapeToComponentIndices, arg("self"),
166 "Returns a mapping of shapes to the indices of components with that shape.");
167}
SpectrumInfoPythonIterator make_pyiterator(SpectrumInfo &spectrumInfo)
void export_ComponentInfo()
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 &)
Mantid::Kernel::V3D(ComponentInfo::* position)(const size_t) const
ComponentInfo : Provides a component centric view on to the instrument.
bool hasParent(const size_t componentIndex) const
std::unordered_map< std::shared_ptr< const Geometry::IObject >, std::vector< size_t > > shapeToComponentIndices() const
Build a map from each unique shape to the list of component indices that share it.
size_t indexOfAny(const std::string &name) const
bool hasEquivalentSource(const ComponentInfo &other) const
size_t parent(const size_t componentIndex) const
const std::vector< size_t > & children(size_t componentIndex) const
std::vector< size_t > componentsInSubtree(size_t componentIndex) const
bool hasValidShape(const size_t componentIndex) const
bool hasEquivalentSample(const ComponentInfo &other) const
void setScaleFactor(const size_t componentIndex, const Kernel::V3D &scaleFactor)
std::vector< size_t > detectorsInSubtree(size_t componentIndex) const
bool isDetector(const size_t componentIndex) const
bool uniqueName(const std::string &name) const
Kernel::V3D relativePosition(const size_t componentIndex) const
const std::string & name(const size_t componentIndex) const
size_t getMemorySize() const
Return memory used by the component info, in bytes.
Kernel::Quat relativeRotation(const size_t componentIndex) const
const Geometry::IObject & shape(const size_t componentIndex) const
Kernel::V3D scaleFactor(const size_t componentIndex) const
Class for quaternions.
Definition Quat.h:39
Class for 3D vectors.
Definition V3D.h:34
Helper class which provides the Collimation Length for SANS instruments.
Implements a return value policy that returns a numpy array from a rerence to a std::vector.