Mantid
Loading...
Searching...
No Matches
ShapeInfo.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2026 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 +
8#include <boost/python/class.hpp>
9#include <boost/python/dict.hpp>
10#include <boost/python/enum.hpp>
11
13using namespace boost::python;
14
15namespace {
16dict cylinderGeometry(const ShapeInfo &self) {
18 PyErr_SetString(PyExc_RuntimeError,
19 "cylinderGeometry() is only valid for ShapeInfo objects with shape() == GeometryShape.CYLINDER");
20 throw boost::python::error_already_set();
21 }
22 const auto cylGeom = self.cylinderGeometry();
23 dict cylGeomDict;
24 cylGeomDict["centreOfBottomBase"] = cylGeom.centreOfBottomBase;
25 cylGeomDict["axis"] = cylGeom.axis;
26 cylGeomDict["radius"] = cylGeom.radius;
27 cylGeomDict["height"] = cylGeom.height;
28 return cylGeomDict;
29}
30
31dict cuboidGeometry(const ShapeInfo &self) {
33 PyErr_SetString(PyExc_RuntimeError,
34 "cuboidGeometry() is only valid for ShapeInfo objects with shape() == GeometryShape.CUBOID");
35 throw boost::python::error_already_set();
36 }
37 const auto cubGeom = self.cuboidGeometry();
38 dict cubGeomDict;
39 cubGeomDict["leftFrontBottom"] = cubGeom.leftFrontBottom;
40 cubGeomDict["leftFrontTop"] = cubGeom.leftFrontTop;
41 cubGeomDict["leftBackBottom"] = cubGeom.leftBackBottom;
42 cubGeomDict["rightFrontBottom"] = cubGeom.rightFrontBottom;
43 return cubGeomDict;
44}
45
46} // namespace
47
49 enum_<ShapeInfo::GeometryShape>("GeometryShape")
50 .value("NOSHAPE", ShapeInfo::GeometryShape::NOSHAPE)
51 .value("CUBOID", ShapeInfo::GeometryShape::CUBOID)
52 .value("HEXAHEDRON", ShapeInfo::GeometryShape::HEXAHEDRON)
53 .value("SPHERE", ShapeInfo::GeometryShape::SPHERE)
54 .value("CYLINDER", ShapeInfo::GeometryShape::CYLINDER)
55 .value("CONE", ShapeInfo::GeometryShape::CONE)
56 .value("HOLLOWCYLINDER", ShapeInfo::GeometryShape::HOLLOWCYLINDER)
57 .export_values();
58
59 class_<ShapeInfo>("ShapeInfo", no_init)
60 .def("shape", &ShapeInfo::shape, arg("self"), "Returns the geometry shape type (GeometryShape enum).")
61 .def("radius", &ShapeInfo::radius, arg("self"),
62 "Returns the radius for sphere, cylinder, cone or hollow cylinder.")
63 .def("innerRadius", &ShapeInfo::innerRadius, arg("self"), "Returns the inner radius for a hollow cylinder.")
64 .def("height", &ShapeInfo::height, arg("self"), "Returns the height for cylinder, cone or hollow cylinder.")
65 .def("cylinderGeometry", &cylinderGeometry, arg("self"),
66 "Returns a CylinderGeometry struct with the geometry information for a cylinder shape. Only valid if "
67 "shape() returns GeometryShape.CYLINDER.")
68 .def("cuboidGeometry", &cuboidGeometry, arg("self"),
69 "Returns a CuboidGeometry struct with the geometry information for a cuboid shape. Only valid if shape() "
70 "returns GeometryShape.CUBOID.");
71}
void export_ShapeInfo()
Definition ShapeInfo.cpp:48
CylinderGeometry cylinderGeometry() const
Definition ShapeInfo.cpp:53
CuboidGeometry cuboidGeometry() const
Definition ShapeInfo.cpp:38