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 <boost/optional.hpp>
19#include <map>
20#include <memory>
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 = new CSGObject(*this);
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 int procString(const std::string &lineStr);
90 int complementaryObject(const int cellNum,
91 std::string &lineStr);
92 int hasComplement() const;
93
94 int populate(const std::map<int, std::shared_ptr<Surface>> &);
95 int createSurfaceList(const int outFlag = 0);
96 int addSurfString(const std::string &);
97 int removeSurface(const int surfNum);
98 int substituteSurf(const int surfNum, const int newSurfNum, const std::shared_ptr<Surface> &surfPtr);
99 void makeComplement();
100 void convertComplement(const std::map<int, CSGObject> &);
101
102 virtual void print() const;
103 void printTree() const;
104
105 bool isValid(const Kernel::V3D &) const override;
106 bool isValid(const std::map<int, int> &) const;
107 bool isOnSide(const Kernel::V3D &) const override;
108 Mantid::Geometry::TrackDirection calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const;
109 Mantid::Geometry::TrackDirection calcValidTypeBy3Points(const Kernel::V3D &prePt, const Kernel::V3D &curPt,
110 const Kernel::V3D &nxtPt) const;
111
112 std::vector<int> getSurfaceIndex() const;
114 const std::vector<const Surface *> &getSurfacePtr() const { return m_surList; }
116 std::vector<const Surface *> &getSurfacePtr() { return m_surList; }
117
118 std::string cellCompStr() const;
119 std::string cellStr(const std::map<int, CSGObject> &) const;
120
121 std::string str() const;
122 void write(std::ostream &) const;
123
124 // INTERSECTION
125 int interceptSurface(Geometry::Track &track) const override;
126 double distance(const Track &track) const override;
127
128 // Solid angle - uses triangleSolidAngle unless many (>30000) triangles
129 double solidAngle(const Kernel::V3D &observer) const override;
130 // Solid angle with a scaling of the object
131 double solidAngle(const Kernel::V3D &observer, const Kernel::V3D &scaleFactor) const override;
132 // solid angle via triangulation
133 double triangulatedSolidAngle(const Kernel::V3D &observer) const;
134 // Solid angle via triangulation with scaling factor for object size
135 double triangulatedSolidAngle(const Kernel::V3D &observer, const Kernel::V3D &scaleFactor) const;
136 // solid angle via ray tracing
137 double rayTraceSolidAngle(const Kernel::V3D &observer) const;
138
140 double volume() const override;
141
144 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
145 double &zmin) const override;
146
148 const BoundingBox &getBoundingBox() const override;
150 void defineBoundingBox(const double &xMax, const double &yMax, const double &zMax, const double &xMin,
151 const double &yMin, const double &zMin);
153 void setNullBoundingBox();
154 // find internal point to object
155 int getPointInObject(Kernel::V3D &point) const override;
156
158 boost::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
159 const size_t) const override;
160 boost::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
161 const BoundingBox &activeRegion, const size_t) const override;
162
163 // Rendering member functions
164 void draw() const override;
165 // Initialize Drawing
166 void initDraw() const override;
167 // Get Geometry Handler
168 std::shared_ptr<GeometryHandler> getGeometryHandler() const override;
170 void setGeometryHandler(const std::shared_ptr<GeometryHandler> &h);
171
173 void setVtkGeometryCacheWriter(std::shared_ptr<vtkGeometryCacheWriter>);
175 void setVtkGeometryCacheReader(std::shared_ptr<vtkGeometryCacheReader>);
176 detail::ShapeInfo::GeometryShape shape() const override;
177 const detail::ShapeInfo &shapeInfo() const override;
178 void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors, double &innerRadius,
179 double &radius, double &height) const override;
181 std::string getShapeXML() const;
182
183private:
184 int procPair(std::string &lineStr, std::map<int, std::unique_ptr<Rule>> &ruleMap, int &compUnit) const;
185 std::unique_ptr<CompGrp> procComp(std::unique_ptr<Rule>) const;
186 int checkSurfaceValid(const Kernel::V3D &, const Kernel::V3D &) const;
187
189 void calcBoundingBoxByRule();
190
192 void calcBoundingBoxByVertices();
193
195 void calcBoundingBoxByGeometry();
196
197 int searchForObject(Kernel::V3D &) const;
198
200 double monteCarloVolume() const;
202 double singleShotMonteCarloVolume(const int shotSize, const size_t seed) const;
204 std::unique_ptr<Rule> m_topRule;
207 // -- DEPRECATED --
208 mutable double AABBxMax,
214 mutable bool boolBounded;
215
219 std::shared_ptr<GeometryHandler> m_handler;
220 friend class GeometryHandler;
221 friend class GeometryRenderer;
225 std::shared_ptr<vtkGeometryCacheReader> vtkCacheReader;
227 std::shared_ptr<vtkGeometryCacheWriter> vtkCacheWriter;
228 void updateGeometryHandler();
229 size_t numberOfTriangles() const;
230 size_t numberOfVertices() const;
232 const std::vector<uint32_t> &getTriangleFaces() const;
233 const std::vector<double> &getTriangleVertices() const;
235 std::string m_shapeXML;
237 std::string m_id;
239 mutable std::unique_ptr<Kernel::Material> m_material;
241 bool m_isFiniteGeometry = true;
242
243protected:
244 std::vector<const Surface *> m_surList;
246};
247
248} // NAMESPACE Geometry
249} // NAMESPACE Mantid
double height
Definition: GetAllEi.cpp:155
double radius
Definition: Rasterize.cpp:31
double innerRadius
Definition: Rasterize.cpp:39
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:34
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:217
std::shared_ptr< vtkGeometryCacheReader > vtkCacheReader
a pointer to a class for reading from the geometry cache
Definition: CSGObject.h:225
std::string m_shapeXML
original shape xml used to generate this object.
Definition: CSGObject.h:235
const std::vector< const Surface * > & getSurfacePtr() const
Get the list of surfaces (const version)
Definition: CSGObject.h:114
double AABByMin
xmin of Axis aligned bounding box cache
Definition: CSGObject.h:212
std::vector< const Surface * > m_surList
Full surfaces (make a map.
Definition: CSGObject.h:244
double AABBzMin
zmin of Axis Aligned Bounding Box Cache
Definition: CSGObject.h:213
bool isFiniteGeometry() const override
Definition: CSGObject.h:72
~CSGObject() override
Destructor.
std::string m_id
Optional string identifier.
Definition: CSGObject.h:237
std::unique_ptr< Kernel::Material > m_material
material composition
Definition: CSGObject.h:239
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:210
double AABBxMin
xmin of Axis aligned bounding box cache
Definition: CSGObject.h:211
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
Definition: CSGObject.h:219
const Rule * topRule() const
Return the top rule.
Definition: CSGObject.h:76
double AABByMax
ymax of Axis aligned bounding box cache
Definition: CSGObject.h:209
bool bGeometryCaching
Is geometry caching enabled?
Definition: CSGObject.h:223
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:227
double AABBxMax
xmax of Axis aligned bounding box cache
Definition: CSGObject.h:208
BoundingBox m_boundingBox
Object's bounding box.
Definition: CSGObject.h:206
IObject * clone() const override
Clone.
Definition: CSGObject.h:64
bool boolBounded
flag true if a bounding box exists, either by
Definition: CSGObject.h:214
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:116
std::unique_ptr< Rule > m_topRule
Top rule [ Geometric scope of object].
Definition: CSGObject.h:204
void setFiniteGeometryFlag(bool isFinite) override
Definition: CSGObject.h:73
Handles rendering of all object Geometry.
IObject : Interface for geometry objects.
Definition: IObject.h:41
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.