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 +
9#include "MantidKernel/Quat.h"
10#include "MantidKernel/V3D.h"
13#include "MantidPythonInterface/geometry/ComponentInfoPythonIterator.h"
14
15#include <boost/python/class.hpp>
16#include <boost/python/copy_const_reference.hpp>
17#include <boost/python/reference_existing_object.hpp>
18#include <boost/python/return_value_policy.hpp>
19
23using Mantid::PythonInterface::ComponentInfoPythonIterator;
26using namespace boost::python;
27
28namespace {
29ComponentInfoPythonIterator make_pyiterator(ComponentInfo &componentInfo) {
30 return ComponentInfoPythonIterator(componentInfo);
31}
32} // namespace
33
34// Function pointers to help resolve ambiguity
36
38
40
42
43// Export ComponentInfo
45 class_<ComponentInfo, boost::noncopyable>("ComponentInfo", no_init)
46
47 .def("__iter__", make_pyiterator)
48
49 .def("__len__", &ComponentInfo::size, arg("self"), "Returns the number of components.")
50
51 .def("size", &ComponentInfo::size, arg("self"), "Returns the number of components.")
52
53 .def("isDetector", &ComponentInfo::isDetector, (arg("self"), arg("index")),
54 "Checks if the component is a detector.")
55
56 .def("detectorsInSubtree", &ComponentInfo::detectorsInSubtree, return_value_policy<VectorToNumpy>(),
57 (arg("self"), arg("index")),
58 "Returns a list of detectors in the subtree for the component "
59 "identified by 'index'.")
60
61 .def("componentsInSubtree", &ComponentInfo::componentsInSubtree, return_value_policy<VectorToNumpy>(),
62 (arg("self"), arg("index")),
63 "Returns a list of components in the subtree for the component "
64 "identified by 'index'.")
65
66 .def("position", position, (arg("self"), arg("index")),
67 "Returns the absolute position of the component identified by "
68 "'index'.")
69
70 .def("rotation", rotation, (arg("self"), arg("index")),
71 "Returns the absolute rotation of the component identified by "
72 "'index'.")
73
74 .def("relativePosition", &ComponentInfo::relativePosition, (arg("self"), arg("index")),
75 "Returns the absolute relative position of the component identified "
76 "by 'index'.")
77
78 .def("relativeRotation", &ComponentInfo::relativeRotation, (arg("self"), arg("index")),
79 "Returns the absolute relative rotation of the component identified "
80 "by 'index'.")
81
82 .def("setPosition", setPosition, (arg("self"), arg("index"), arg("newPosition")),
83 "Set the absolute position of the component identified by 'index'.")
84
85 .def("setRotation", setRotation, (arg("self"), arg("index"), arg("newRotation")),
86 "Set the absolute rotation of the component identified by 'index'.")
87
88 .def("hasSource", &ComponentInfo::hasSource, arg("self"), "Returns True if a source is present.")
89
90 .def("hasEquivalentSource", &ComponentInfo::hasEquivalentSource, arg("self"), arg("other"),
91 "Returns True is both beamlines either lack a Source or "
92 "have a Source at the same position.")
93
94 .def("hasSample", &ComponentInfo::hasSample, arg("self"), "Returns True if a sample is present.")
95
96 .def("hasEquivalentSample", &ComponentInfo::hasEquivalentSample, arg("self"), arg("other"),
97 "Returns True is both beamlines either lack a Sample or "
98 "have a Sample at the same position.")
99
100 .def("source", &ComponentInfo::source, arg("self"), "Returns the source component index.")
101
102 .def("sample", &ComponentInfo::sample, arg("self"), "Returns the sample component index.")
103
104 .def("sourcePosition", &ComponentInfo::sourcePosition, arg("self"), "Returns the source position.")
105
106 .def("samplePosition", &ComponentInfo::samplePosition, arg("self"), "Returns the sample position.")
107
108 .def("hasParent", &ComponentInfo::hasParent, (arg("self"), arg("index")),
109 "Returns True only if the component identified by 'index' has a "
110 "parent component.")
111
112 .def("parent", &ComponentInfo::parent, (arg("self"), arg("index")),
113 "Returns the parent component of the component identified by "
114 "'index'.")
115
116 .def("children", &ComponentInfo::children, (arg("self"), arg("index")),
117 return_value_policy<VectorRefToNumpy<WrapReadOnly>>(),
118 "Returns a list of child components for the component identified by "
119 "'index'.")
120
121 .def("name", &ComponentInfo::name, (arg("self"), arg("index")), return_value_policy<copy_const_reference>(),
122 "Returns the name of the component identified by 'index'.")
123
124 .def("l1", &ComponentInfo::l1, arg("self"), "Returns the l1 value.")
125
126 .def("scaleFactor", &ComponentInfo::scaleFactor, (arg("self"), arg("index")),
127 "Returns the scale factor for the component identified by 'index'.")
128
129 .def("setScaleFactor", &ComponentInfo::setScaleFactor, (arg("self"), arg("index"), arg("scaleFactor")),
130 "Set the scale factor of the component identifed by 'index'.")
131
132 .def("hasValidShape", &ComponentInfo::hasValidShape, (arg("self"), arg("index")),
133 "Returns True if the component identified by 'index' has a valid "
134 "shape.")
135
136 .def("shape", &ComponentInfo::shape, (arg("self"), arg("index")),
137 return_value_policy<reference_existing_object>(),
138 "Returns the shape of the component identified by 'index'.")
139
140 .def("indexOfAny", &ComponentInfo::indexOfAny, (arg("self"), arg("name")),
141 "Returns the index of any component matching name. Raises "
142 "ValueError if name not found")
143
144 .def("uniqueName", &ComponentInfo::uniqueName, (arg("self"), arg("name")),
145 "Returns True if the name is a unique single occurance. Zero occurances yields False.")
146
147 .def("root", &ComponentInfo::root, arg("self"), "Returns the index of the root component");
148}
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.
Definition: ComponentInfo.h:40
bool hasParent(const size_t componentIndex) const
size_t indexOfAny(const std::string &name) const
void setRotation(size_t componentIndex, const Kernel::Quat &newRotation)
bool hasEquivalentSource(const ComponentInfo &other) const
size_t parent(const size_t componentIndex) const
Kernel::Quat rotation(const size_t componentIndex) const
Kernel::V3D position(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
Kernel::V3D sourcePosition() 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
Kernel::Quat relativeRotation(const size_t componentIndex) const
void setPosition(size_t componentIndex, const Kernel::V3D &newPosition)
Kernel::V3D samplePosition() 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
Implements a return value policy that returns a numpy array from a rerence to a std::vector.
Definition: VectorToNumpy.h:63