Mantid
Loading...
Searching...
No Matches
BoundingBox.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 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#ifndef Q_MOC_RUN
13#include <memory>
14#endif
15#include <sstream>
16
17namespace Mantid {
18namespace Geometry {
19
20//-------------------------------------------------------------------------
21// Forward declarations
22//-------------------------------------------------------------------------
23class Track;
24
34class MANTID_GEOMETRY_DLL BoundingBox {
35public:
37 BoundingBox() : m_minPoint(), m_maxPoint(), m_null(true), is_axis_aligned(true) {}
38
48 BoundingBox(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin)
49 : m_minPoint(xmin, ymin, zmin), m_maxPoint(xmax, ymax, zmax), m_null(false), is_axis_aligned(true) {
50 // Sanity check
51 checkValid(xmax, ymax, zmax, xmin, ymin, zmin);
52 }
53
64 static void checkValid(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin) {
65 if (xmax < xmin || ymax < ymin || zmax < zmin) {
66 std::ostringstream error;
67 error << "Error creating bounding box, inconsistent values given:\n"
68 << "\txmin=" << xmin << ", xmax=" << xmax << "\n"
69 << "\tymin=" << ymin << ", ymax=" << ymax << "\n"
70 << "\tzmin=" << zmin << ", zmax=" << zmax << "\n";
71 throw std::invalid_argument(error.str());
72 }
73 }
74
78 inline double xMin() const { return m_minPoint.X(); }
80 inline double xMax() const { return m_maxPoint.X(); }
82 inline double yMin() const { return m_minPoint.Y(); }
84 inline double yMax() const { return m_maxPoint.Y(); }
86 inline double zMin() const { return m_minPoint.Z(); }
88 inline double zMax() const { return m_maxPoint.Z(); }
90 inline const Kernel::V3D &minPoint() const { return m_minPoint; }
92 inline const Kernel::V3D &maxPoint() const { return m_maxPoint; }
94 inline Kernel::V3D centrePoint() const {
95 return Kernel::V3D(0.5 * (xMax() + xMin()), 0.5 * (yMax() + yMin()), 0.5 * (zMax() + zMin()));
96 }
98 inline Kernel::V3D width() const { return Kernel::V3D(m_maxPoint - m_minPoint); }
100
104 inline bool isNull() const { return m_null; }
106 inline bool isNonNull() const { return !m_null; }
108 bool isPointInside(const Kernel::V3D &point) const;
110 bool doesLineIntersect(const Track &track) const;
112 bool doesLineIntersect(const Kernel::V3D &startPoint, const Kernel::V3D &lineDir) const;
114 double angularWidth(const Kernel::V3D &observer) const;
116 inline bool isAxisAligned() const { return is_axis_aligned; }
118 std::vector<Kernel::V3D> const &getCoordSystem() const { return coord_system; }
120
122 Kernel::V3D generatePointInside(double r1, double r2, double r3) const;
125 void getFullBox(std::vector<Kernel::V3D> &box, const Kernel::V3D &observer) const;
129 inline double &xMin() {
130 m_null = false;
131 return m_minPoint[0];
132 }
134 inline double &xMax() {
135 m_null = false;
136 return m_maxPoint[0];
137 }
139 inline double &yMin() {
140 m_null = false;
141 return m_minPoint[1];
142 }
144 inline double &yMax() {
145 m_null = false;
146 return m_maxPoint[1];
147 }
149 inline double &zMin() {
150 m_null = false;
151 return m_minPoint[2];
152 }
154 inline double &zMax() {
155 m_null = false;
156 return m_maxPoint[2];
157 }
159 void grow(const BoundingBox &other);
161 void setBoxAlignment(const Kernel::V3D &R0, const std::vector<Kernel::V3D> &orts);
163 void nullify();
166 void realign(std::vector<Kernel::V3D> const *const pCS = nullptr);
168 void moveBy(const Kernel::V3D &v) {
169 m_minPoint += v;
170 m_maxPoint += v;
171 }
173
174private:
181 bool m_null;
189 std::vector<Kernel::V3D> coord_system;
190};
191
193using BoundingBox_sptr = std::shared_ptr<BoundingBox>;
195using BoundingBox_const_sptr = std::shared_ptr<const BoundingBox>;
196
198MANTID_GEOMETRY_DLL std::ostream &operator<<(std::ostream &os, const BoundingBox &box);
199} // namespace Geometry
200} // namespace Mantid
double error
Definition: IndexPeaks.cpp:133
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
BoundingBox(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin)
Constructor taking six points.
Definition: BoundingBox.h:48
bool m_null
Flag marking if we've been initialized using the default constructor, with values or default values a...
Definition: BoundingBox.h:181
BoundingBox()
Default constructor constructs a zero-sized box.
Definition: BoundingBox.h:37
double & yMin()
Return the minimum value of Y (non-const)
Definition: BoundingBox.h:139
double xMax() const
Return the maximum value of X.
Definition: BoundingBox.h:80
bool isNonNull() const
Is the box considered valid. Convenience for !isNull()
Definition: BoundingBox.h:106
double zMin() const
Return the minimum value of Z.
Definition: BoundingBox.h:86
const Kernel::V3D & minPoint() const
Returns the min point of the box.
Definition: BoundingBox.h:90
double & yMax()
Return the maximum value of Y (non-const)
Definition: BoundingBox.h:144
std::vector< Kernel::V3D > const & getCoordSystem() const
returns the coordinate system to which BB is alighned to;
Definition: BoundingBox.h:118
double & zMin()
Return the minimum value of Z (non-const)
Definition: BoundingBox.h:149
Kernel::V3D m_maxPoint
The maximum point of the axis-aligned box.
Definition: BoundingBox.h:178
bool isNull() const
Is this a default constructed box?
Definition: BoundingBox.h:104
double zMax() const
Return the maximum value of Z.
Definition: BoundingBox.h:88
Kernel::V3D width() const
Returns the width of the box.
Definition: BoundingBox.h:98
double yMax() const
Return the maximum value of Y.
Definition: BoundingBox.h:84
bool isAxisAligned() const
Check if it is normal axis aligned bounding box or not.
Definition: BoundingBox.h:116
double & xMax()
Return the maximum value of X (non-const)
Definition: BoundingBox.h:134
double xMin() const
Return the minimum value of X.
Definition: BoundingBox.h:78
static void checkValid(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin)
Do the given arguments form a valid bounding box, throws std::invalid argument if not.
Definition: BoundingBox.h:64
Kernel::V3D centrePoint() const
Returns the centre of the bounding box.
Definition: BoundingBox.h:94
double yMin() const
Return the minimum value of Y.
Definition: BoundingBox.h:82
double & zMax()
Return the maximum value of Z (non-const)
Definition: BoundingBox.h:154
std::vector< Kernel::V3D > coord_system
if the bounding box is not axis aligned, the vector below describes the coordinate system,...
Definition: BoundingBox.h:189
Kernel::V3D m_minPoint
The minimum point of the axis-aligned box.
Definition: BoundingBox.h:176
double & xMin()
Return the minimum value of X (non-const)
Definition: BoundingBox.h:129
const Kernel::V3D & maxPoint() const
Returns the min point of the box.
Definition: BoundingBox.h:92
bool is_axis_aligned
the parameter which describe if the bounding box is axis aligned or not
Definition: BoundingBox.h:183
void moveBy(const Kernel::V3D &v)
move the BB by a vector
Definition: BoundingBox.h:168
Defines a track as a start point and a direction.
Definition: Track.h:165
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
Definition: PointGroup.cpp:312
std::shared_ptr< BoundingBox > BoundingBox_sptr
A shared pointer to a BoundingBox.
Definition: BoundingBox.h:193
std::shared_ptr< const BoundingBox > BoundingBox_const_sptr
A shared pointer to a const BoundingBox.
Definition: BoundingBox.h:195
Helper class which provides the Collimation Length for SANS instruments.