Mantid
Loading...
Searching...
No Matches
IBeamProfile.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 +
7
13#include "MantidKernel/V3D.h"
14
15namespace Mantid {
16using Kernel::V3D;
17
18namespace {
28std::string cuboidXML(double xExtent, double yExtent, double zExtent, const V3D &centerPos) {
29
30 // Convert full dimensions to half-lengths
31 const double szX = xExtent / 2.0;
32 const double szY = yExtent / 2.0;
33 const double szZ = zExtent / 2.0;
34
35 // Define corners of the cuboid
36 V3D leftFrontBottom{szX, -szY, -szZ};
37 V3D leftFrontTop{szX, -szY, szZ};
38 V3D leftBackBottom{-szX, -szY, -szZ};
39 V3D rightFrontBottom{szX, szY, -szZ};
40
41 // Shift the points by the center position
42 leftFrontBottom += centerPos;
43 leftFrontTop += centerPos;
44 leftBackBottom += centerPos;
45 rightFrontBottom += centerPos;
46
47 std::ostringstream xmlShapeStream;
48 xmlShapeStream << " <cuboid id=\"gauge-volume\"> "
49 << "<left-front-bottom-point x=\"" << leftFrontBottom.X() << "\" y=\"" << leftFrontBottom.Y()
50 << "\" z=\"" << leftFrontBottom.Z() << "\" /> "
51 << "<left-front-top-point x=\"" << leftFrontTop.X() << "\" y=\"" << leftFrontTop.Y() << "\" z=\""
52 << leftFrontTop.Z() << "\" /> "
53 << "<left-back-bottom-point x=\"" << leftBackBottom.X() << "\" y=\"" << leftBackBottom.Y()
54 << "\" z=\"" << leftBackBottom.Z() << "\" /> "
55 << "<right-front-bottom-point x=\"" << rightFrontBottom.X() << "\" y=\"" << rightFrontBottom.Y()
56 << "\" z=\"" << rightFrontBottom.Z() << "\" /> "
57 << "</cuboid>";
58
59 return xmlShapeStream.str();
60}
61} // namespace
62
63namespace Algorithms {
69IBeamProfile::IBeamProfile(const V3D center) : m_beamCenter(center) {}
70
78 Geometry::BoundingBox sampleBB = sample.getBoundingBox();
79 Geometry::BoundingBox intersectionBox;
80
81 try {
82 intersectionBox = defineActiveRegion(sampleBB);
83 } catch (const std::invalid_argument &) {
84 // Exception means the beam missed the object and cannot create an intersection BoundingBox
85 return nullptr;
86 }
87
88 // If the intersection volume is the same as the sample volume use the sample volume instead of creating a new shape
89 // V3D operator== comparison is done with a 1.0e-6 tolerance
90 if ((sampleBB.minPoint() == intersectionBox.minPoint()) && (sampleBB.maxPoint() == intersectionBox.maxPoint())) {
91 return std::shared_ptr<Geometry::IObject>(sample.clone());
92 }
93
94 double yExtent = intersectionBox.yMax() - intersectionBox.yMin();
95 double xExtent = intersectionBox.xMax() - intersectionBox.xMin();
96 double zExtent = intersectionBox.zMax() - intersectionBox.zMin();
97
98 std::string shapeXML = cuboidXML(xExtent, yExtent, zExtent, intersectionBox.centrePoint());
99 return Geometry::ShapeFactory().createShape(std::move(shapeXML));
100}
101
102} // namespace Algorithms
103} // namespace Mantid
virtual Geometry::BoundingBox defineActiveRegion(const Geometry::BoundingBox &) const =0
Geometry::IObject_sptr getIntersectionWithSample(const Geometry::IObject &sample) const
Get the intersection of the beam with the sample.
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
double xMax() const
Return the maximum value of X.
Definition BoundingBox.h:79
double zMin() const
Return the minimum value of Z.
Definition BoundingBox.h:85
const Kernel::V3D & minPoint() const
Returns the min point of the box.
Definition BoundingBox.h:89
double zMax() const
Return the maximum value of Z.
Definition BoundingBox.h:87
double yMax() const
Return the maximum value of Y.
Definition BoundingBox.h:83
double xMin() const
Return the minimum value of X.
Definition BoundingBox.h:77
Kernel::V3D centrePoint() const
Returns the centre of the bounding box.
Definition BoundingBox.h:93
double yMin() const
Return the minimum value of Y.
Definition BoundingBox.h:81
const Kernel::V3D & maxPoint() const
Returns the min point of the box.
Definition BoundingBox.h:91
IObject : Interface for geometry objects.
Definition IObject.h:42
virtual const BoundingBox & getBoundingBox() const =0
Return cached value of axis-aligned bounding box.
virtual IObject * clone() const =0
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
Class for 3D vectors.
Definition V3D.h:34
std::string cuboidXML(double xHalfLength, double yHalfLength=-1.0, double zHalfLength=-1.0, const Mantid::Kernel::V3D &centre={0.0, 0.0, 0.0}, const std::string &id="detector-shape")
std::shared_ptr< IObject > IObject_sptr
Typdef for a shared pointer.
Definition IObject.h:93
Helper class which provides the Collimation Length for SANS instruments.