Mantid
Loading...
Searching...
No Matches
SampleEnvironment.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 +
7//------------------------------------------------------------------------------
8// Includes
9//------------------------------------------------------------------------------
14
15namespace Mantid::Geometry {
16using Geometry::BoundingBox;
17using Geometry::Track;
18using Kernel::V3D;
19
20//------------------------------------------------------------------------------
21// Public methods
22//------------------------------------------------------------------------------
23
31 : m_name(std::move(name)), m_components(1, container) {}
32
33const IObject &SampleEnvironment::getComponent(const size_t index) const {
34 if (index > this->nelements()) {
35 std::stringstream msg;
36 msg << "Requested SampleEnvironment element that is out of range: " << index << " < " << this->nelements();
37 throw std::out_of_range(msg.str());
38 }
39 return *(m_components[index]);
40}
41
43 if (index > this->nelements()) {
44 std::stringstream msg;
45 msg << "Requested SampleEnvironment element that is out of range: " << index << " < " << this->nelements();
46 throw std::out_of_range(msg.str());
47 }
48 return m_components[index];
49}
50
55 BoundingBox box;
56 for (const auto &component : m_components) {
57 box.grow(component->getBoundingBox());
58 }
59 return box;
60}
61
67bool SampleEnvironment::isValid(const V3D &point) const {
68 return std::any_of(m_components.cbegin(), m_components.cend(),
69 [&point](const auto &component) { return component->isValid(point); });
70}
71
79 return std::accumulate(m_components.cbegin(), m_components.cend(), 0,
80 [&track](int sum, const auto &component) { return sum + component->interceptSurface(track); });
81}
82
86void SampleEnvironment::add(const IObject_const_sptr &component) { m_components.emplace_back(component); }
87} // namespace Mantid::Geometry
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
void grow(const BoundingBox &other)
Grow the bounding box so that it also encompasses the given box.
IObject : Interface for geometry objects.
Definition: IObject.h:41
std::vector< IObject_const_sptr > m_components
const IObject & getComponent(const size_t index) const
Returns the requested IObject.
bool isValid(const Kernel::V3D &point) const
Is the point given a valid point within the environment.
SampleEnvironment(std::string name, const Container_const_sptr &getContainer)
Constructor specifying a name for the environment.
void add(const IObject_const_sptr &component)
Geometry::BoundingBox boundingBox() const
int interceptSurfaces(Track &track) const
Update the given track with intersections within the environment.
const IObject_const_sptr getComponentPtr(const size_t index) const
Defines a track as a start point and a direction.
Definition: Track.h:165
Class for 3D vectors.
Definition: V3D.h:34
std::shared_ptr< const Container > Container_const_sptr
Typdef for a shared pointer to a const object.
Definition: Container.h:107
std::shared_ptr< const IObject > IObject_const_sptr
Typdef for a shared pointer to a const object.
Definition: IObject.h:94
STL namespace.