Mantid
Loading...
Searching...
No Matches
WorkspaceNearestNeighbourInfo.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2025 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 +
11#include "MantidKernel/V3D.h"
14#include <boost/python/class.hpp>
15#include <boost/python/dict.hpp>
16#include <boost/python/make_constructor.hpp>
17
18using namespace boost::python;
19using namespace Mantid::API;
21
23
24namespace {
25WorkspaceNearestNeighbourInfo *createWorkspaceNearestNeighbourInfo(const boost::python::object &workspace,
26 const bool ignoreMaskedDetectors,
27 const int nNeighbours = 8) {
28 Mantid::API::MatrixWorkspace_sptr matrixWorkspace = std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
30
31 return new WorkspaceNearestNeighbourInfo(*matrixWorkspace, ignoreMaskedDetectors, nNeighbours);
32}
33
34boost::python::dict mapToDict(const std::map<Mantid::specnum_t, Mantid::Kernel::V3D> &inputMap) {
35 boost::python::dict result;
36 for (const auto &pair : inputMap) {
37 result[pair.first] = pair.second;
38 }
39 return result;
40}
41
42boost::python::dict getNeighboursByDetector(const WorkspaceNearestNeighbourInfo &self,
43 const Mantid::Geometry::IDetector *comp, double radius = 0.0) {
44 auto result = self.getNeighbours(comp, radius);
45 return mapToDict(result);
46}
47
48boost::python::dict getNeighboursBySpec(const WorkspaceNearestNeighbourInfo &self, Mantid::specnum_t spec,
49 double radius) {
50 auto result = self.getNeighbours(spec, radius);
51 return mapToDict(result);
52}
53
54boost::python::dict getNeighboursExact(const WorkspaceNearestNeighbourInfo &self, Mantid::specnum_t spec) {
55 auto result = self.getNeighboursExact(spec);
56 return mapToDict(result);
57}
58
59} // namespace
60
62 class_<WorkspaceNearestNeighbourInfo, boost::noncopyable>("WorkspaceNearestNeighbourInfo", no_init)
63 .def("__init__", make_constructor(&createWorkspaceNearestNeighbourInfo, default_call_policies(),
64 (arg("workspace"), arg("ignoreMaskedDetectors"), arg("nNeighbours") = 8)))
65 .def("getNeighbours", &getNeighboursByDetector, (arg("self"), arg("comp"), arg("radius") = 0.0))
66 .def("getNeighbours", &getNeighboursBySpec, (arg("self"), arg("spec_num"), arg("radius")))
67 .def("getNeighboursExact", &getNeighboursExact, (arg("self"), arg("spec_num")));
68}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
IPeaksWorkspace_sptr workspace
void export_WorkspaceNearestNeighbourInfo()
WorkspaceNearestNeighbourInfo provides easy access to nearest-neighbour information for a workspace.
std::map< specnum_t, Kernel::V3D > getNeighbours(const Geometry::IDetector *comp, const double radius=0.0) const
Queries the WorkspaceNearestNeighbours object for the selected detector.
std::map< specnum_t, Kernel::V3D > getNeighboursExact(specnum_t spec) const
Queries the WorkspaceNearestNeighbours object for the selected spectrum number.
Interface class for detector objects.
Definition IDetector.h:43
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14