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 const std::string &id() const override { return m_id; }
79
80 void setName(const int objNum) { m_objNum = objNum; }
81 int getName() const override { return m_objNum; }
82
83 void setMaterial(const Kernel::Material &material) override;
84 const Kernel::Material &material() const override;
85
87 bool hasValidShape() const override;
88 int setObject(const int objName, const std::string &lineStr);
89 void procString(const std::string &lineStr);
90 int hasComplement() const;
91
92 int populate(const std::map<int, std::shared_ptr<Surface>> &);
93 int createSurfaceList(const int outFlag = 0);
94 int addSurfString(const std::string &);
95 int removeSurface(const int surfNum);
96 int substituteSurf(const int surfNum, const int newSurfNum, const std::shared_ptr<Surface> &surfPtr);
97 void makeComplement();
98 void convertComplement(const std::map<int, CSGObject> &);
99
100 virtual void print() const;
101 void printTree() const;
102
103 bool isValid(const Kernel::V3D &) const override;
104 bool isValid(const std::map<int, int> &) const;
105 bool isOnSide(const Kernel::V3D &) const override;
106 Mantid::Geometry::TrackDirection calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const;
107 Mantid::Geometry::TrackDirection calcValidTypeBy3Points(const Kernel::V3D &prePt, const Kernel::V3D &curPt,
108 const Kernel::V3D &nxtPt) const;
109
110 std::vector<int> getSurfaceIndex() const;
112 const std::vector<const Surface *> &getSurfacePtr() const { return m_surList; }
114 std::vector<const Surface *> &getSurfacePtr() { return m_surList; }
115
116 std::string cellCompStr() const;
117 std::string cellStr(const std::map<int, CSGObject> &) const;
118
119 std::string str() const;
120 void write(std::ostream &) const;
121
122 // INTERSECTION
123 int interceptSurface(Geometry::Track &track) const override;
124 double distance(const Track &track) const override;
125
126 // Solid angle - uses triangleSolidAngle unless many (>30000) triangles
127 double solidAngle(const SolidAngleParams &params) const override;
128 // Solid angle with a scaling of the object
129 double solidAngle(const SolidAngleParams &params, const Kernel::V3D &scaleFactor) const override;
130 // solid angle via triangulation
131 double triangulatedSolidAngle(const SolidAngleParams &params) const;
132 // Solid angle via triangulation with scaling factor for object size
133 double triangulatedSolidAngle(const SolidAngleParams &params, const Kernel::V3D &scaleFactor) const;
134 // solid angle via ray tracing
135 double rayTraceSolidAngle(const Kernel::V3D &observer) const;
136
138 double volume() const override;
139
142 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
143 double &zmin) const override;
144
146 const BoundingBox &getBoundingBox() const override;
148 void defineBoundingBox(const double &xMax, const double &yMax, const double &zMax, const double &xMin,
149 const double &yMin, const double &zMin);
151 void setNullBoundingBox();
152 // find internal point to object
153 int getPointInObject(Kernel::V3D &point) const override;
154
156 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
157 const size_t) const override;
158 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
159 const BoundingBox &activeRegion, const size_t) const override;
160
161 // Rendering member functions
162 void draw() const override;
163 // Initialize Drawing
164 void initDraw() const override;
165 // Get Geometry Handler
166 std::shared_ptr<GeometryHandler> getGeometryHandler() const override;
168 void setGeometryHandler(const std::shared_ptr<GeometryHandler> &h);
170 void setVtkGeometryCacheWriter(std::shared_ptr<vtkGeometryCacheWriter>);
172 void setVtkGeometryCacheReader(std::shared_ptr<vtkGeometryCacheReader>);
173 detail::ShapeInfo::GeometryShape shape() const override;
174 const detail::ShapeInfo &shapeInfo() const override;
175 void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors, double &innerRadius,
176 double &radius, double &height) const override;
178 std::string getShapeXML() const;
179
180private:
181 int procPair(std::string &lineStr, std::map<int, std::unique_ptr<Rule>> &ruleMap, int &compUnit) const;
182 std::unique_ptr<CompGrp> procComp(std::unique_ptr<Rule>) const;
183 int checkSurfaceValid(const Kernel::V3D &, const Kernel::V3D &) const;
184
186 void calcBoundingBoxByRule();
187
189 void calcBoundingBoxByVertices();
190
192 void calcBoundingBoxByGeometry();
193
194 int searchForObject(Kernel::V3D &) const;
195
197 double monteCarloVolume() const;
199 double singleShotMonteCarloVolume(const int shotSize, const size_t seed) const;
201 std::unique_ptr<Rule> m_topRule;
204 // -- DEPRECATED --
205 mutable double AABBxMax,
211 mutable bool boolBounded;
212
216 std::shared_ptr<GeometryHandler> m_handler;
217 friend class GeometryHandler;
218 friend class GeometryRenderer;
222 std::shared_ptr<vtkGeometryCacheReader> vtkCacheReader;
224 std::shared_ptr<vtkGeometryCacheWriter> vtkCacheWriter;
225 void updateGeometryHandler();
226 size_t numberOfTriangles() const;
227 size_t numberOfVertices() const;
229 const std::vector<uint32_t> &getTriangleFaces() const;
230 const std::vector<double> &getTriangleVertices() const;
232 std::string m_shapeXML;
234 std::string m_id;
236 mutable std::unique_ptr<Kernel::Material> m_material;
238 bool m_isFiniteGeometry = true;
239
240protected:
241 std::vector<const Surface *> m_surList;
243};
244
245} // NAMESPACE Geometry
246} // NAMESPACE Mantid
double height
Definition GetAllEi.cpp:155
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:80
void setID(const std::string &id) override
Definition CSGObject.h:77
int m_objNum
Creation number.
Definition CSGObject.h:214
std::shared_ptr< vtkGeometryCacheReader > vtkCacheReader
a pointer to a class for reading from the geometry cache
Definition CSGObject.h:222
std::string m_shapeXML
original shape xml used to generate this object.
Definition CSGObject.h:232
const std::vector< const Surface * > & getSurfacePtr() const
Get the list of surfaces (const version)
Definition CSGObject.h:112
double AABByMin
xmin of Axis aligned bounding box cache
Definition CSGObject.h:209
std::vector< const Surface * > m_surList
Full surfaces (make a map.
Definition CSGObject.h:241
double AABBzMin
zmin of Axis Aligned Bounding Box Cache
Definition CSGObject.h:210
bool isFiniteGeometry() const override
Definition CSGObject.h:72
~CSGObject() override
Destructor.
std::string m_id
Optional string identifier.
Definition CSGObject.h:234
std::unique_ptr< Kernel::Material > m_material
material composition
Definition CSGObject.h:236
int addSurfString(const std::string &)
Not implemented.
const std::string & id() const override
Definition CSGObject.h:78
double AABBzMax
zmax of Axis aligned bounding box cache
Definition CSGObject.h:207
double AABBxMin
xmin of Axis aligned bounding box cache
Definition CSGObject.h:208
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
Definition CSGObject.h:216
const Rule * topRule() const
Return the top rule.
Definition CSGObject.h:76
double AABByMax
ymax of Axis aligned bounding box cache
Definition CSGObject.h:206
bool bGeometryCaching
Is geometry caching enabled?
Definition CSGObject.h:220
int getName() const override
Get Name.
Definition CSGObject.h:81
std::shared_ptr< vtkGeometryCacheWriter > vtkCacheWriter
a pointer to a class for writing to the geometry cache
Definition CSGObject.h:224
double AABBxMax
xmax of Axis aligned bounding box cache
Definition CSGObject.h:205
BoundingBox m_boundingBox
Object's bounding box.
Definition CSGObject.h:203
IObject * clone() const override
Clone.
Definition CSGObject.h:64
bool boolBounded
flag true if a bounding box exists, either by
Definition CSGObject.h:211
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:114
std::unique_ptr< Rule > m_topRule
Top rule [ Geometric scope of object].
Definition CSGObject.h:201
void setFiniteGeometryFlag(bool isFinite) override
Definition CSGObject.h:73
Handles rendering of all object Geometry.
IObject : Interface for geometry objects.
Definition IObject.h:42
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
Defines a 1D pseudo-random number generator, i.e.
Class for 3D vectors.
Definition V3D.h:34
Helper class which provides the Collimation Length for SANS instruments.