8#include "MantidBeamline/ComponentInfo.h"
9#include "MantidBeamline/ComponentType.h"
16#include <Eigen/Geometry>
27const Eigen::Vector3d undoRotation(
const Eigen::Vector3d &point,
const Beamline::ComponentInfo &compInfo,
28 const size_t componentIndex) {
29 auto unRotateTransform = Eigen::Affine3d(compInfo.rotation(componentIndex).inverse());
30 return unRotateTransform * point;
39const Kernel::V3D toShapeFrame(
const Kernel::V3D &point,
const Beamline::ComponentInfo &compInfo,
40 const size_t componentIndex) {
42 undoRotation(
Kernel::toVector3d(point) - compInfo.position(componentIndex), compInfo, componentIndex));
55 std::unique_ptr<Beamline::ComponentInfo> componentInfo,
56 std::shared_ptr<
const std::vector<Mantid::Geometry::IComponent *>> componentIds,
57 std::shared_ptr<
const std::unordered_map<Geometry::IComponent *, size_t>> componentIdToIndexMap,
58 std::shared_ptr<std::vector<std::shared_ptr<const Geometry::IObject>>> shapes)
59 : m_componentInfo(
std::move(componentInfo)), m_componentIds(
std::move(componentIds)),
60 m_compIDToIndex(
std::move(componentIdToIndexMap)), m_shapes(
std::move(shapes)) {
63 throw std::invalid_argument(
"Inconsistent ID and Mapping input containers "
64 "for Geometry::ComponentInfo");
67 throw std::invalid_argument(
"Inconsistent ID and base "
68 "Beamline::ComponentInfo sizes for "
69 "Geometry::ComponentInfo");
87 : m_componentInfo(other.m_componentInfo->cloneWithoutDetectorInfo()), m_componentIds(other.m_componentIds),
88 m_compIDToIndex(other.m_compIDToIndex), m_shapes(other.m_shapes) {}
110 if (!(type == Beamline::ComponentType::Structured || type == Beamline::ComponentType::Rectangular ||
111 parentType == Beamline::ComponentType::Grid))
112 throw std::runtime_error(
"ComponentType is not Structured or Rectangular "
113 "in ComponentInfo::quadrilateralComponent.");
116 const auto &innerRangeComp =
m_componentInfo->children(componentIndex);
117 corners.
nX = innerRangeComp.size();
120 corners.
nY = firstCol.size();
123 corners.
topLeft = firstCol.back();
140 const auto *
shape = (*m_shapes)[componentIndex].get();
217 const auto range =
m_componentInfo->detectorRangeInSubtree(componentIndex);
218 return range.begin() < range.end();
285 const bool excludeMonitors)
const {
305 const bool excludeMonitors)
const {
319 const bool excludeMonitors)
const {
324 if (excludeMonitors) {
338 const auto &s = this->
shape(index);
352 .rotateBB(absoluteBB.
xMin(), absoluteBB.
yMin(), absoluteBB.
zMin(), absoluteBB.
xMax(), absoluteBB.
yMax(),
357 absoluteBB.
xMin() += localPos[0];
358 absoluteBB.
xMax() += localPos[0];
359 absoluteBB.
yMin() += localPos[1];
360 absoluteBB.
yMax() += localPos[1];
361 absoluteBB.
zMin() += localPos[2];
362 absoluteBB.
zMax() += localPos[2];
366 std::vector<Kernel::V3D> coordSystem;
370 absoluteBB.
realign(&coordSystem);
388 const bool excludeMonitors)
const {
396 auto parentFlag = Beamline::ComponentType::Generic;
403 }
else if (compFlag == Beamline::ComponentType::Unstructured) {
404 for (
const auto &childIndex : this->
children(componentIndex)) {
407 }
else if (compFlag == Beamline::ComponentType::Grid) {
408 for (
const auto &childIndex : this->
children(componentIndex)) {
411 }
else if (compFlag == Beamline::ComponentType::Rectangular || compFlag == Beamline::ComponentType::Structured ||
412 parentFlag == Beamline::ComponentType::Grid) {
414 }
else if (compFlag == Beamline::ComponentType::OutlineComposite) {
428 m_componentInfo->setScanInterval({interval.first.totalNanoseconds(), interval.second.totalNanoseconds()});
std::map< DeltaEMode::Type, std::string > index
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
double xMax() const
Return the maximum value of X.
double zMin() const
Return the minimum value of Z.
std::vector< Kernel::V3D > const & getCoordSystem() const
returns the coordinate system to which BB is alighned to;
double zMax() const
Return the maximum value of Z.
double yMax() const
Return the maximum value of Y.
bool isAxisAligned() const
Check if it is normal axis aligned bounding box or not.
double xMin() const
Return the minimum value of X.
double yMin() const
Return the minimum value of Y.
void grow(const BoundingBox &other)
Grow the bounding box so that it also encompasses the given box.
void realign(std::vector< Kernel::V3D > const *const pCS=nullptr)
reallign the BB according to new coordinate system, provided earlier or specified as parameter;
ComponentInfoIterator for random access iteration over ComponentInfo.
ComponentInfo : Provides a component centric view on to the instrument.
bool hasParent(const size_t componentIndex) const
const ComponentInfoIterator< const ComponentInfo > cend()
bool hasDetectorInfo() const
BoundingBox componentBoundingBox(const size_t index, const BoundingBox *reference, const bool excludeMonitors=false) const
Calculates the absolute bounding box for the leaf item at index.
size_t indexOfAny(const std::string &name) const
void setRotation(size_t componentIndex, const Kernel::Quat &newRotation)
bool hasDetectors(const size_t componentIndex) const
bool hasEquivalentSource(const ComponentInfo &other) const
size_t parent(const size_t componentIndex) const
Kernel::Quat rotation(const size_t componentIndex) const
std::shared_ptr< const std::unordered_map< Geometry::IComponent *, size_t > > m_compIDToIndex
Map of component ids to indexes.
void growBoundingBoxAsOutline(size_t index, const Geometry::BoundingBox *reference, Geometry::BoundingBox &mutableBB, const bool excludeMonitors=false) const
Grow the bounding box on the basis that the component described by index has an outline,...
BoundingBox boundingBox(const size_t componentIndex, const BoundingBox *reference=nullptr, const bool excludeMonitors=false) const
Compute the bounding box for the component with componentIndex taking into account all sub components...
double solidAngle(const size_t componentIndex, const Kernel::V3D &observer) const
Kernel::V3D position(const size_t componentIndex) const
const std::vector< size_t > & children(size_t componentIndex) const
std::vector< size_t > componentsInSubtree(size_t componentIndex) const
void merge(const ComponentInfo &other)
bool hasValidShape(const size_t componentIndex) const
size_t indexOf(Geometry::IComponent *id) const
Kernel::V3D sourcePosition() const
ComponentInfoIterator< ComponentInfo > begin()
bool hasEquivalentSample(const ComponentInfo &other) const
void setScaleFactor(const size_t componentIndex, const Kernel::V3D &scaleFactor)
ComponentInfoIterator< ComponentInfo > end()
std::unique_ptr< Beamline::ComponentInfo > m_componentInfo
Pointer to the actual ComponentInfo object (non-wrapping part).
std::vector< size_t > detectorsInSubtree(size_t componentIndex) const
bool isDetector(const size_t componentIndex) const
bool uniqueName(const std::string &name) const
void growBoundingBoxAsRectuangularBank(size_t index, const Geometry::BoundingBox *reference, Geometry::BoundingBox &mutableBB, const bool excludeMonitors=false) const
Grow the bounding box on the basis that the component described by index is a regular grid in a trape...
std::unique_ptr< ComponentInfo > cloneWithoutDetectorInfo() const
Clone current instance but not the DetectorInfo non-owned parts.
const ComponentInfoIterator< const ComponentInfo > cbegin()
std::shared_ptr< const std::vector< Geometry::IComponent * > > m_componentIds
Collection of component ids.
Kernel::V3D relativePosition(const size_t componentIndex) const
const std::string & name(const size_t componentIndex) const
Kernel::Quat relativeRotation(const size_t componentIndex) const
void setPosition(size_t componentIndex, const Kernel::V3D &newPosition)
Kernel::V3D samplePosition() const
const Geometry::IObject & shape(const size_t componentIndex) const
void setScanInterval(const std::pair< Types::Core::DateAndTime, Types::Core::DateAndTime > &interval)
QuadrilateralComponent quadrilateralComponent(const size_t componentIndex) const
Beamline::ComponentType componentType(const size_t componentIndex) const
Kernel::V3D scaleFactor(const size_t componentIndex) const
ComponentInfo(const ComponentInfo &other)
Private copy constructor. Do not make public.
base class for Geometric IComponent
IObject : Interface for geometry objects.
virtual double solidAngle(const Kernel::V3D &observer) const =0
virtual bool hasValidShape() const =0
Exception thrown when an attempt is made to dereference a null pointer.
ComponentInfoIterator< const ComponentInfo > ComponentInfoConstIt
ComponentInfoIterator< ComponentInfo > ComponentInfoIt
Kernel::Quat toQuat(const Eigen::Quaterniond &quat)
Converts Eigen::Quaterniond to Kernel::Quat.
Eigen::Vector3d toVector3d(const Kernel::V3D &vec)
Converts Kernel::V3D to Eigen::Vector3d.
Kernel::V3D toV3D(const Eigen::Vector3d &vec)
This header provides conversion helpers between vector and rotation types in MantidKernel and equival...
Eigen::Quaterniond toQuaterniond(const Kernel::Quat &quat)
Converts Kernel::Quat to Eigen::Quaterniond.