Mantid
Loading...
Searching...
No Matches
CSGObject.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidGeometry/DllConfig.h"
17
18#include <map>
19#include <memory>
20#include <optional>
21
22namespace Mantid {
23//----------------------------------------------------------------------
24// Forward declarations
25//----------------------------------------------------------------------
26namespace Kernel {
27class PseudoRandomNumberGenerator;
28class Material;
29class V3D;
30} // namespace Kernel
31
32namespace Geometry {
33class CompGrp;
34class GeometryHandler;
35class Rule;
36class Surface;
37class Track;
38class vtkGeometryCacheReader;
39class vtkGeometryCacheWriter;
40
51class MANTID_GEOMETRY_DLL CSGObject final : public IObject {
52public:
54 CSGObject();
56 CSGObject(std::string shapeXML);
58 CSGObject(const CSGObject &);
60 CSGObject &operator=(const CSGObject &);
62 ~CSGObject() override;
64 IObject *clone() const override { return new CSGObject(*this); }
65
66 IObject *cloneWithMaterial(const Kernel::Material &material) const override {
67 auto obj = this->clone();
68 obj->setMaterial(material);
69 return obj;
70 }
71
72 bool isFiniteGeometry() const override { return m_isFiniteGeometry; }
73 void setFiniteGeometryFlag(bool isFinite) override { m_isFiniteGeometry = isFinite; }
74
76 const Rule *topRule() const { return m_topRule.get(); }
77 void setID(const std::string &id) override { m_id = id; }
78
79 const Kernel::Matrix<double> &getAppliedRotation() const override { return m_appliedRotation; }
82 const std::string &id() const override { return m_id; }
83
84 void setName(const int objNum) { m_objNum = objNum; }
85 int getName() const override { return m_objNum; }
86
87 void setMaterial(const Kernel::Material &material) override;
88 const Kernel::Material &material() const override;
89
91 bool hasValidShape() const override;
92 int setObject(const int objName, const std::string &lineStr);
93 void procString(const std::string &lineStr);
94 int hasComplement() const;
95
96 int populate(const std::map<int, std::shared_ptr<Surface>> &);
97 int createSurfaceList(const int outFlag = 0);
98 int addSurfString(const std::string &);
99 int removeSurface(const int surfNum);
100 int substituteSurf(const int surfNum, const int newSurfNum, const std::shared_ptr<Surface> &surfPtr);
101 void makeComplement();
102 void convertComplement(const std::map<int, CSGObject> &);
103
104 virtual void print() const;
105 void printTree() const;
106
107 bool isValid(const Kernel::V3D &) const override;
108 bool isValid(const std::map<int, int> &) const;
109 bool isOnSide(const Kernel::V3D &) const override;
110 Mantid::Geometry::TrackDirection calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const;
111 Mantid::Geometry::TrackDirection calcValidTypeBy3Points(const Kernel::V3D &prePt, const Kernel::V3D &curPt,
112 const Kernel::V3D &nxtPt) const;
113
114 std::vector<int> getSurfaceIndex() const;
116 const std::vector<const Surface *> &getSurfacePtr() const { return m_surList; }
118 std::vector<const Surface *> &getSurfacePtr() { return m_surList; }
119
120 std::string cellCompStr() const;
121 std::string cellStr(const std::map<int, CSGObject> &) const;
122
123 std::string str() const;
124 void write(std::ostream &) const;
125
126 // INTERSECTION
127 int interceptSurface(Geometry::Track &track) const override;
128 double distance(const Track &track) const override;
129
130 // Solid angle - uses triangleSolidAngle unless many (>30000) triangles
131 double solidAngle(const SolidAngleParams &params) const override;
132 // Solid angle with a scaling of the object
133 double solidAngle(const SolidAngleParams &params, const Kernel::V3D &scaleFactor) const override;
134 // solid angle via triangulation
135 double triangulatedSolidAngle(const SolidAngleParams &params) const;
136 // Solid angle via triangulation with scaling factor for object size
137 double triangulatedSolidAngle(const SolidAngleParams &params, const Kernel::V3D &scaleFactor) const;
138 // solid angle via ray tracing
139 double rayTraceSolidAngle(const Kernel::V3D &observer) const;
140
142 double volume() const override;
143
146 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
147 double &zmin) const override;
148
150 const BoundingBox &getBoundingBox() const override;
152 void defineBoundingBox(const double &xMax, const double &yMax, const double &zMax, const double &xMin,
153 const double &yMin, const double &zMin);
155 void setNullBoundingBox();
156 // find internal point to object
157 int getPointInObject(Kernel::V3D &point) const override;
158
160 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
161 const size_t) const override;
162 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
163 const BoundingBox &activeRegion, const size_t) const override;
164
165 // Rendering member functions
166 void draw() const override;
167 // Initialize Drawing
168 void initDraw() const override;
169 // Get Geometry Handler
170 std::shared_ptr<GeometryHandler> getGeometryHandler() const override;
172 void setGeometryHandler(const std::shared_ptr<GeometryHandler> &h);
174 void setVtkGeometryCacheWriter(std::shared_ptr<vtkGeometryCacheWriter>);
176 void setVtkGeometryCacheReader(std::shared_ptr<vtkGeometryCacheReader>);
177 detail::ShapeInfo::GeometryShape shape() const override;
178 const detail::ShapeInfo &shapeInfo() const override;
179 void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors, double &innerRadius,
180 double &radius, double &height) const override;
182 std::string getShapeXML() const;
183
184 const std::vector<uint32_t> &getTriangleFaces() const;
185 const std::vector<double> &getTriangleVertices() const;
186
187private:
188 int procPair(std::string &lineStr, std::map<int, std::unique_ptr<Rule>> &ruleMap, int &compUnit) const;
189 std::unique_ptr<CompGrp> procComp(std::unique_ptr<Rule>) const;
190 int checkSurfaceValid(const Kernel::V3D &, const Kernel::V3D &) const;
191
193 void calcBoundingBoxByRule();
194
196 void calcBoundingBoxByVertices();
197
199 void calcBoundingBoxByGeometry();
200
201 int searchForObject(Kernel::V3D &) const;
202
204 double monteCarloVolume() const;
206 double singleShotMonteCarloVolume(const int shotSize, const size_t seed) const;
208 std::unique_ptr<Rule> m_topRule;
211 // -- DEPRECATED --
212 mutable double AABBxMax,
218 mutable bool boolBounded;
219
223 std::shared_ptr<GeometryHandler> m_handler;
224 friend class GeometryHandler;
225 friend class GeometryRenderer;
229 std::shared_ptr<vtkGeometryCacheReader> vtkCacheReader;
231 std::shared_ptr<vtkGeometryCacheWriter> vtkCacheWriter;
232 void updateGeometryHandler();
233 size_t numberOfTriangles() const;
234 size_t numberOfVertices() const;
236 std::string m_shapeXML;
238 std::string m_id;
240 mutable std::unique_ptr<Kernel::Material> m_material;
242 bool m_isFiniteGeometry = true;
244 Kernel::Matrix<double> m_appliedRotation{3, 3, true};
245
246protected:
247 std::vector<const Surface *> m_surList;
249};
250
251} // NAMESPACE Geometry
252} // NAMESPACE Mantid
double height
Definition GetAllEi.cpp:155
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
double obj
the value of the quadratic function
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
Constructive Solid Geometry object.
Definition CSGObject.h:51
void setName(const int objNum)
Set Name.
Definition CSGObject.h:84
void setID(const std::string &id) override
Definition CSGObject.h:77
int m_objNum
Creation number.
Definition CSGObject.h:221
std::shared_ptr< vtkGeometryCacheReader > vtkCacheReader
a pointer to a class for reading from the geometry cache
Definition CSGObject.h:229
std::string m_shapeXML
original shape xml used to generate this object.
Definition CSGObject.h:236
const std::vector< const Surface * > & getSurfacePtr() const
Get the list of surfaces (const version)
Definition CSGObject.h:116
double AABByMin
xmin of Axis aligned bounding box cache
Definition CSGObject.h:216
std::vector< const Surface * > m_surList
Full surfaces (make a map.
Definition CSGObject.h:247
const Kernel::Matrix< double > & getAppliedRotation() const override
The goniometer rotation baked into this shape, i.e.
Definition CSGObject.h:79
double AABBzMin
zmin of Axis Aligned Bounding Box Cache
Definition CSGObject.h:217
bool isFiniteGeometry() const override
Definition CSGObject.h:72
~CSGObject() override
Destructor.
std::string m_id
Optional string identifier.
Definition CSGObject.h:238
std::unique_ptr< Kernel::Material > m_material
material composition
Definition CSGObject.h:240
int addSurfString(const std::string &)
Not implemented.
const std::string & id() const override
Definition CSGObject.h:82
double AABBzMax
zmax of Axis aligned bounding box cache
Definition CSGObject.h:214
double AABBxMin
xmin of Axis aligned bounding box cache
Definition CSGObject.h:215
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
Definition CSGObject.h:223
const Rule * topRule() const
Return the top rule.
Definition CSGObject.h:76
double AABByMax
ymax of Axis aligned bounding box cache
Definition CSGObject.h:213
bool bGeometryCaching
Is geometry caching enabled?
Definition CSGObject.h:227
int getName() const override
Get Name.
Definition CSGObject.h:85
std::shared_ptr< vtkGeometryCacheWriter > vtkCacheWriter
a pointer to a class for writing to the geometry cache
Definition CSGObject.h:231
double AABBxMax
xmax of Axis aligned bounding box cache
Definition CSGObject.h:212
BoundingBox m_boundingBox
Object's bounding box.
Definition CSGObject.h:210
IObject * clone() const override
Clone.
Definition CSGObject.h:64
bool boolBounded
flag true if a bounding box exists, either by
Definition CSGObject.h:218
IObject * cloneWithMaterial(const Kernel::Material &material) const override
Definition CSGObject.h:66
std::vector< const Surface * > & getSurfacePtr()
Get the list of surfaces.
Definition CSGObject.h:118
void setAppliedGoniometerRotation(const Kernel::Matrix< double > &rotation)
Record-only: the surfaces are already rotated by the time ShapeFactory calls this.
Definition CSGObject.h:81
std::unique_ptr< Rule > m_topRule
Top rule [ Geometric scope of object].
Definition CSGObject.h:208
void setFiniteGeometryFlag(bool isFinite) override
Definition CSGObject.h:73
Handles rendering of all object Geometry.
IObject : Interface for geometry objects.
Definition IObject.h:43
Object generation rule tree.
Definition Rules.h:33
Defines a track as a start point and a direction.
Definition Track.h:165
A material is defined as being composed of a given element, defined as a PhysicalConstants::NeutronAt...
Definition Material.h:50
Numerical Matrix class.
Definition Matrix.h:41
Defines a 1D pseudo-random number generator, i.e.
Class for 3D vectors.
Definition V3D.h:35
Helper class which provides the Collimation Length for SANS instruments.