Mantid
Loading...
Searching...
No Matches
RandomPoint.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 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#pragma once
8
9#include "MantidGeometry/DllConfig.h"
11#include "MantidKernel/V3D.h"
12
13#include <boost/optional.hpp>
14
15namespace Mantid {
16namespace Kernel {
17class PseudoRandomNumberGenerator;
18}
19namespace Geometry {
20namespace detail {
21class ShapeInfo;
22}
23class BoundingBox;
24class IObject;
25namespace RandomPoint {
26
27MANTID_GEOMETRY_DLL Kernel::V3D inCuboid(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng);
28
29MANTID_GEOMETRY_DLL Kernel::V3D inCylinder(const detail::ShapeInfo &shapeInfo,
31
32MANTID_GEOMETRY_DLL Kernel::V3D inHollowCylinder(const detail::ShapeInfo &shapeInfo,
34
35MANTID_GEOMETRY_DLL Kernel::V3D inSphere(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng);
36
37MANTID_GEOMETRY_DLL boost::optional<Kernel::V3D>
38inGenericShape(const IObject &object, Kernel::PseudoRandomNumberGenerator &rng, size_t maxAttempts);
39
40MANTID_GEOMETRY_DLL Kernel::V3D localPointInCylinder(const Kernel::V3D &basis, const Kernel::V3D &alongAxis,
41 double polarAngle, double radialLength);
42
43template <Kernel::V3D (*T)(const detail::ShapeInfo &, Kernel::PseudoRandomNumberGenerator &)>
44boost::optional<Kernel::V3D> bounded(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng,
45 const BoundingBox &box, size_t maxAttempts);
46
47MANTID_GEOMETRY_DLL boost::optional<Kernel::V3D>
48bounded(const IObject &object, Kernel::PseudoRandomNumberGenerator &rng, const BoundingBox &box, size_t maxAttempts);
49
61template <Kernel::V3D (*randomInShape)(const detail::ShapeInfo &, Kernel::PseudoRandomNumberGenerator &)>
62boost::optional<Kernel::V3D> bounded(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng,
63 const BoundingBox &box, size_t maxAttempts) {
64 boost::optional<Kernel::V3D> point;
65 for (size_t attempt{0}; attempt < maxAttempts; ++attempt) {
66 const Kernel::V3D pt{randomInShape(shapeInfo, rng)};
67 if (box.isPointInside(pt)) {
68 point = pt;
69 break;
70 }
71 }
72 return point;
73}
74
75} // namespace RandomPoint
76} // namespace Geometry
77} // namespace Mantid
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
bool isPointInside(const Kernel::V3D &point) const
Is the given point within the bounding box?
Definition: BoundingBox.cpp:28
IObject : Interface for geometry objects.
Definition: IObject.h:41
Defines a 1D pseudo-random number generator, i.e.
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL Kernel::V3D inCylinder(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in cylinder.
Definition: RandomPoint.cpp:67
MANTID_GEOMETRY_DLL Kernel::V3D inCuboid(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in a cuboid shape.
Definition: RandomPoint.cpp:50
MANTID_GEOMETRY_DLL Kernel::V3D inSphere(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in sphere.
MANTID_GEOMETRY_DLL Kernel::V3D inHollowCylinder(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng)
Return a random point in a hollow cylinder.
Definition: RandomPoint.cpp:87
MANTID_GEOMETRY_DLL Kernel::V3D localPointInCylinder(const Kernel::V3D &basis, const Kernel::V3D &alongAxis, double polarAngle, double radialLength)
Return a local point in a cylinder shape.
Definition: RandomPoint.cpp:23
MANTID_GEOMETRY_DLL boost::optional< Kernel::V3D > inGenericShape(const IObject &object, Kernel::PseudoRandomNumberGenerator &rng, size_t maxAttempts)
Return a random point in a generic shape.
boost::optional< Kernel::V3D > bounded(const detail::ShapeInfo &shapeInfo, Kernel::PseudoRandomNumberGenerator &rng, const BoundingBox &box, size_t maxAttempts)
Return a random point in a known shape restricted by a bounding box.
Definition: RandomPoint.h:62
Helper class which provides the Collimation Length for SANS instruments.