Mantid
Loading...
Searching...
No Matches
ShapeInfo.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 +
9#include "MantidKernel/V3D.h"
10#include <cassert>
11#include <cmath>
12
13namespace Mantid {
14using Kernel::V3D;
15namespace Geometry::detail {
17 : m_points(), m_radius(0), m_height(0), m_innerRadius(0), m_shape(ShapeInfo::GeometryShape::NOSHAPE) {}
18
19const std::vector<Kernel::V3D> &ShapeInfo::points() const { return m_points; }
20
21double ShapeInfo::radius() const { return m_radius; }
22
23double ShapeInfo::height() const { return m_height; }
24
25double ShapeInfo::innerRadius() const { return m_innerRadius; }
26
28
29void ShapeInfo::getObjectGeometry(ShapeInfo::GeometryShape &shape, std::vector<Kernel::V3D> &points,
30 double &innerRadius, double &radius, double &height) const {
31 shape = m_shape;
36}
37
40 return {m_points[0], m_points[1], m_points[2], m_points[3]};
41}
42
45 return {m_points[0], m_points[1], m_points[2], m_points[3], m_points[4], m_points[5], m_points[6], m_points[7]};
46}
47
50 return {m_points.front(), m_radius};
51}
52
55 return {m_points.front(), m_points.back(), m_radius, m_height};
56}
57
60 return {m_points.front(), m_points.back(), m_innerRadius, m_radius, m_height};
61}
62
65 return {m_points.front(), m_points.back(), m_radius, m_height};
66}
67
68void ShapeInfo::setCuboid(const V3D &p1, const V3D &p2, const V3D &p3, const V3D &p4) {
70 m_points.assign({p1, p2, p3, p4});
71 m_radius = 0;
72 m_height = 0;
73 m_innerRadius = 0;
74}
75
76void ShapeInfo::setHexahedron(const V3D &p1, const V3D &p2, const V3D &p3, const V3D &p4, const V3D &p5, const V3D &p6,
77 const V3D &p7, const V3D &p8) {
79 m_points.assign({p1, p2, p3, p4, p5, p6, p7, p8});
80 m_radius = 0;
81 m_height = 0;
82 m_innerRadius = 0;
83}
84
85void ShapeInfo::setSphere(const V3D &center, double radius) {
87 m_points.assign({center});
89 m_height = 0;
90 m_innerRadius = 0;
91}
92
93void ShapeInfo::setCylinder(const V3D &centerBottomBase, const V3D &symmetryAxis, double radius, double height) {
95 m_points.assign({centerBottomBase, symmetryAxis});
98 m_innerRadius = 0;
99}
100
101void ShapeInfo::setCone(const V3D &center, const V3D &symmetryAxis, double radius, double height) {
103 m_points.assign({center, symmetryAxis});
106 m_innerRadius = 0;
107}
108
109void ShapeInfo::setHollowCylinder(const Kernel::V3D &centreBottomBase, const Kernel::V3D &symmetryAxis,
110 double innerRadius, double outerRadius, double height) {
112 m_points.assign({centreBottomBase, symmetryAxis});
113 m_radius = outerRadius;
116}
117
119 return m_shape == other.m_shape && std::abs(m_height - other.m_height) < Kernel::Tolerance &&
120 std::abs(m_radius - other.m_radius) < Kernel::Tolerance && m_points == other.m_points;
121}
122
123std::ostream &operator<<(std::ostream &os, const ShapeInfo::GeometryShape shape) {
124 switch (shape) {
126 os << "NOSHAPE";
127 break;
129 os << "CUBOID";
130 break;
132 os << "HEXAHEDRON";
133 break;
135 os << "SPHERE";
136 break;
138 os << "CYLINDER";
139 break;
141 os << "CONE";
142 break;
144 os << "HOLLOWCYLINDER";
145 break;
146 default:
147 os.setstate(std::ios_base::failbit);
148 }
149 return os;
150}
151
152} // namespace Geometry::detail
153} // namespace Mantid
double height
Definition: GetAllEi.cpp:155
double radius
Definition: Rasterize.cpp:31
double innerRadius
Definition: Rasterize.cpp:39
V3D centerBottomBase
Definition: Rasterize.cpp:33
SphereGeometry sphereGeometry() const
Definition: ShapeInfo.cpp:48
void getObjectGeometry(GeometryShape &shape, std::vector< Kernel::V3D > &points, double &innerRadius, double &radius, double &height) const
Definition: ShapeInfo.cpp:29
void setSphere(const Kernel::V3D &center, double radius)
sets the geometry handler for a sphere
Definition: ShapeInfo.cpp:85
ConeGeometry coneGeometry() const
Definition: ShapeInfo.cpp:63
void setCylinder(const Kernel::V3D &centerBottomBase, const Kernel::V3D &symmetryAxis, double radius, double height)
sets the geometry handler for a cylinder
Definition: ShapeInfo.cpp:93
GeometryShape shape() const
Definition: ShapeInfo.cpp:27
double m_radius
Radius for the sphere, cone and cylinder; Also outer radius for hollow cylinder;.
Definition: ShapeInfo.h:80
void setCone(const Kernel::V3D &center, const Kernel::V3D &symmetryAxis, double radius, double height)
sets the geometry handler for a cone
Definition: ShapeInfo.cpp:101
void setHollowCylinder(const Kernel::V3D &centreBottomBase, const Kernel::V3D &symmetryAxis, double innerRadius, double outerRadius, double height)
sets the geometry handler for a hollow cylinder
Definition: ShapeInfo.cpp:109
double m_height
height for cone, cylinder and hollow cylinder;
Definition: ShapeInfo.h:82
void setCuboid(const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &)
sets the geometry handler for a cuboid
Definition: ShapeInfo.cpp:68
bool operator==(const ShapeInfo &other)
Definition: ShapeInfo.cpp:118
CylinderGeometry cylinderGeometry() const
Definition: ShapeInfo.cpp:53
CuboidGeometry cuboidGeometry() const
Definition: ShapeInfo.cpp:38
std::vector< Kernel::V3D > m_points
Definition: ShapeInfo.h:79
const std::vector< Kernel::V3D > & points() const
Definition: ShapeInfo.cpp:19
double m_innerRadius
Inner radius for hollow cylinder.
Definition: ShapeInfo.h:83
void setHexahedron(const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &, const Kernel::V3D &)
sets the geometry handler for a hexahedron
Definition: ShapeInfo.cpp:76
HexahedronGeometry hexahedronGeometry() const
Definition: ShapeInfo.cpp:43
HollowCylinderGeometry hollowCylinderGeometry() const
Definition: ShapeInfo.cpp:58
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &os, const ShapeInfo::GeometryShape shape)
Definition: ShapeInfo.cpp:123
constexpr double Tolerance
Standard tolerance value.
Definition: Tolerance.h:12
Helper class which provides the Collimation Length for SANS instruments.