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"
10#include "MantidKernel/V3D.h"
11#ifndef Q_MOC_RUN
12#include <memory>
13#endif
14#include <sstream>
15
16namespace Mantid {
17namespace Geometry {
18
19//-------------------------------------------------------------------------
20// Forward declarations
21//-------------------------------------------------------------------------
22class Track;
23
33class MANTID_GEOMETRY_DLL BoundingBox {
34public:
36 BoundingBox() : m_minPoint(), m_maxPoint(), m_null(true), is_axis_aligned(true) {}
37
47 BoundingBox(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin)
48 : m_minPoint(xmin, ymin, zmin), m_maxPoint(xmax, ymax, zmax), m_null(false), is_axis_aligned(true) {
49 // Sanity check
50 checkValid(xmax, ymax, zmax, xmin, ymin, zmin);
51 }
52
63 static void checkValid(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin) {
64 if (xmax < xmin || ymax < ymin || zmax < zmin) {
65 std::ostringstream error;
66 error << "Error creating bounding box, inconsistent values given:\n"
67 << "\txmin=" << xmin << ", xmax=" << xmax << "\n"
68 << "\tymin=" << ymin << ", ymax=" << ymax << "\n"
69 << "\tzmin=" << zmin << ", zmax=" << zmax << "\n";
70 throw std::invalid_argument(error.str());
71 }
72 }
73
77 inline double xMin() const { return m_minPoint.X(); }
79 inline double xMax() const { return m_maxPoint.X(); }
81 inline double yMin() const { return m_minPoint.Y(); }
83 inline double yMax() const { return m_maxPoint.Y(); }
85 inline double zMin() const { return m_minPoint.Z(); }
87 inline double zMax() const { return m_maxPoint.Z(); }
89 inline const Kernel::V3D &minPoint() const { return m_minPoint; }
91 inline const Kernel::V3D &maxPoint() const { return m_maxPoint; }
93 inline Kernel::V3D centrePoint() const {
94 return Kernel::V3D(0.5 * (xMax() + xMin()), 0.5 * (yMax() + yMin()), 0.5 * (zMax() + zMin()));
95 }
97 inline Kernel::V3D width() const { return Kernel::V3D(m_maxPoint - m_minPoint); }
99
103 inline bool isNull() const { return m_null; }
105 inline bool isNonNull() const { return !m_null; }
107 bool isPointInside(const Kernel::V3D &point) const;
109 bool doesLineIntersect(const Track &track) const;
111 bool doesLineIntersect(const Kernel::V3D &startPoint, const Kernel::V3D &lineDir) const;
113 double angularWidth(const Kernel::V3D &observer) const;
115 inline bool isAxisAligned() const { return is_axis_aligned; }
117 std::vector<Kernel::V3D> const &getCoordSystem() const { return coord_system; }
119
121 Kernel::V3D generatePointInside(double r1, double r2, double r3) const;
124 void getFullBox(std::vector<Kernel::V3D> &box, const Kernel::V3D &observer) const;
128 inline double &xMin() {
129 m_null = false;
130 return m_minPoint[0];
131 }
133 inline double &xMax() {
134 m_null = false;
135 return m_maxPoint[0];
136 }
138 inline double &yMin() {
139 m_null = false;
140 return m_minPoint[1];
141 }
143 inline double &yMax() {
144 m_null = false;
145 return m_maxPoint[1];
146 }
148 inline double &zMin() {
149 m_null = false;
150 return m_minPoint[2];
151 }
153 inline double &zMax() {
154 m_null = false;
155 return m_maxPoint[2];
156 }
158 void grow(const BoundingBox &other);
160 void setBoxAlignment(const Kernel::V3D &R0, const std::vector<Kernel::V3D> &orts);
162 void nullify();
165 void realign(std::vector<Kernel::V3D> const *const pCS = nullptr);
167 void moveBy(const Kernel::V3D &v) {
168 m_minPoint += v;
169 m_maxPoint += v;
170 }
172
173private:
180 bool m_null;
188 std::vector<Kernel::V3D> coord_system;
189};
190
192using BoundingBox_sptr = std::shared_ptr<BoundingBox>;
194using BoundingBox_const_sptr = std::shared_ptr<const BoundingBox>;
195
197MANTID_GEOMETRY_DLL std::ostream &operator<<(std::ostream &os, const BoundingBox &box);
198} // namespace Geometry
199} // namespace Mantid
double error
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
BoundingBox(double xmax, double ymax, double zmax, double xmin, double ymin, double zmin)
Constructor taking six points.
Definition BoundingBox.h:47
bool m_null
Flag marking if we've been initialized using the default constructor, with values or default values a...
BoundingBox()
Default constructor constructs a zero-sized box.
Definition BoundingBox.h:36
double & yMin()
Return the minimum value of Y (non-const)
double xMax() const
Return the maximum value of X.
Definition BoundingBox.h:79
bool isNonNull() const
Is the box considered valid. Convenience for !isNull()
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 & yMax()
Return the maximum value of Y (non-const)
std::vector< Kernel::V3D > const & getCoordSystem() const
returns the coordinate system to which BB is alighned to;
double & zMin()
Return the minimum value of Z (non-const)
Kernel::V3D m_maxPoint
The maximum point of the axis-aligned box.
bool isNull() const
Is this a default constructed box?
double zMax() const
Return the maximum value of Z.
Definition BoundingBox.h:87
Kernel::V3D width() const
Returns the width of the box.
Definition BoundingBox.h:97
double yMax() const
Return the maximum value of Y.
Definition BoundingBox.h:83
bool isAxisAligned() const
Check if it is normal axis aligned bounding box or not.
double & xMax()
Return the maximum value of X (non-const)
double xMin() const
Return the minimum value of X.
Definition BoundingBox.h:77
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:63
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
double & zMax()
Return the maximum value of Z (non-const)
std::vector< Kernel::V3D > coord_system
if the bounding box is not axis aligned, the vector below describes the coordinate system,...
Kernel::V3D m_minPoint
The minimum point of the axis-aligned box.
double & xMin()
Return the minimum value of X (non-const)
const Kernel::V3D & maxPoint() const
Returns the min point of the box.
Definition BoundingBox.h:91
bool is_axis_aligned
the parameter which describe if the bounding box is axis aligned or not
void moveBy(const Kernel::V3D &v)
move the BB by a vector
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.
std::shared_ptr< BoundingBox > BoundingBox_sptr
A shared pointer to a BoundingBox.
std::shared_ptr< const BoundingBox > BoundingBox_const_sptr
A shared pointer to a const BoundingBox.
Helper class which provides the Collimation Length for SANS instruments.