Mantid
Loading...
Searching...
No Matches
MeshObject.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2017 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 "BoundingBox.h"
13#include "MantidGeometry/DllConfig.h"
18#include "MantidKernel/Matrix.h"
19#include <map>
20#include <memory>
21
22namespace Mantid {
23//----------------------------------------------------------------------
24// Forward declarations
25//----------------------------------------------------------------------
26namespace Kernel {
27class PseudoRandomNumberGenerator;
28class V3D;
29} // namespace Kernel
30namespace Nexus {
31class File;
32} // namespace Nexus
33
34namespace Geometry {
35class CompGrp;
36class GeometryHandler;
37class Track;
38class vtkGeometryCacheReader;
39class vtkGeometryCacheWriter;
40
53class MANTID_GEOMETRY_DLL MeshObject : public IObject {
54public:
56 MeshObject(std::vector<uint32_t> faces, std::vector<Kernel::V3D> vertices, const Kernel::Material &material);
58 MeshObject(std::vector<uint32_t> &&faces, std::vector<Kernel::V3D> &&vertices, const Kernel::Material &&material);
59
61 MeshObject(const MeshObject &) = delete;
63 MeshObject &operator=(const MeshObject &) = delete;
65 ~MeshObject() override = default;
67 IObject *clone() const override { return cloneWithMaterial(m_material); }
68 IObject *cloneWithMaterial(const Kernel::Material &material) const override {
69 auto *copy = new MeshObject(m_triangles, m_vertices, material);
70 copy->m_id = m_id;
71 // the copied vertices are already turned, so the copy is baked just as far as this mesh is
72 copy->m_appliedRotation = m_appliedRotation;
73 return copy;
74 }
75
76 void setID(const std::string &id) override { m_id = id; }
77 const std::string &id() const override { return m_id; }
78
79 int getName() const override { return 0; }
80
81 const Kernel::Material &material() const override;
82 void setMaterial(const Kernel::Material &material) override;
83
85 bool hasValidShape() const override;
86
87 bool isValid(const Kernel::V3D &) const override;
88 bool isOnSide(const Kernel::V3D &) const override;
89 int calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const;
90
91 // INTERSECTION
92 int interceptSurface(Geometry::Track &) const override;
93 double distance(const Track &track) const override;
94
95 // Solid angle - uses triangleSolidAngle unless many (>30000) triangles
96 double solidAngle(const SolidAngleParams &params) const override;
97 // Solid angle with a scaling of the object
98 double solidAngle(const SolidAngleParams &params, const Kernel::V3D &scaleFactor) const override;
99
101 double volume() const override;
102
105 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
106 double &zmin) const override;
107
109 const BoundingBox &getBoundingBox() const override;
110
111 // find internal point to object
112 int getPointInObject(Kernel::V3D &point) const override;
113
115 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
116 const size_t) const override;
117 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
118 const BoundingBox &activeRegion, const size_t) const override;
119
120 // Rendering member functions
121 void draw() const override;
122 // Initialize Drawing
123 void initDraw() const override;
124 // Get Geometry Handler
125 std::shared_ptr<GeometryHandler> getGeometryHandler() const override;
127 void setGeometryHandler(const std::shared_ptr<GeometryHandler> &h);
128
129 detail::ShapeInfo::GeometryShape shape() const override;
130 const detail::ShapeInfo &shapeInfo() const override;
131
132 void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors, double &innerRadius,
133 double &radius, double &height) const override;
134
136 size_t numberOfVertices() const;
137 std::vector<double> getVertices() const;
138 const std::vector<Kernel::V3D> &getV3Ds() const;
139 size_t numberOfTriangles() const;
140 const std::vector<uint32_t> &getTriangles() const;
141
143 void rotate(const Kernel::Matrix<double> &);
145 void bakeGoniometerRotation(const Kernel::Matrix<double> &);
147 void setAppliedGoniometerRotation(const Kernel::Matrix<double> &);
148 const Kernel::Matrix<double> &getAppliedRotation() const override { return m_appliedRotation; }
149 void translate(const Kernel::V3D &);
150 void multiply(const Kernel::Matrix<double> &);
151 void scale(const double scaleFactor);
152 void updateGeometryHandler();
153
155 void saveNexus(Nexus::File *file, const std::string &group) const;
157 static std::shared_ptr<MeshObject> loadNexus(Nexus::File *file, const std::string &group,
158 const Kernel::Material &material);
159
160private:
161 void initialize();
163 void getIntersections(const Kernel::V3D &start, const Kernel::V3D &direction,
164 std::vector<Kernel::V3D> &intersectionPoints,
165 std::vector<Mantid::Geometry::TrackDirection> &entryExitFlags) const;
166
168 bool getTriangle(const size_t index, Kernel::V3D &v1, Kernel::V3D &v2, Kernel::V3D &v3) const;
170 bool searchForObject(Kernel::V3D &point) const;
171
174
176 const double M_TOLERANCE = 0.000001;
177
179 std::shared_ptr<GeometryHandler> m_handler;
180
181 // String from which object may be defined
182 std::string m_string;
183
185 std::string m_id;
186
188 std::shared_ptr<vtkGeometryCacheReader> m_vtk_cache_reader;
190 std::shared_ptr<vtkGeometryCacheWriter> m_vtk_cache_writer;
191
194 std::vector<uint32_t> m_triangles;
195 std::vector<Kernel::V3D> m_vertices;
199 Kernel::Matrix<double> m_appliedRotation{3, 3, true};
200};
201
202} // NAMESPACE Geometry
203} // NAMESPACE Mantid
double height
Definition GetAllEi.cpp:155
std::map< DeltaEMode::Type, std::string > index
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
IObject : Interface for geometry objects.
Definition IObject.h:43
Triangular Mesh Object.
Definition MeshObject.h:53
Kernel::Material m_material
material composition
Definition MeshObject.h:197
std::shared_ptr< vtkGeometryCacheWriter > m_vtk_cache_writer
a pointer to a class for writing to the geometry cache
Definition MeshObject.h:190
MeshObject(const MeshObject &)=delete
Copy constructor.
std::vector< Kernel::V3D > m_vertices
Definition MeshObject.h:195
void setID(const std::string &id) override
Definition MeshObject.h:76
std::vector< uint32_t > m_triangles
Contents Triangles are specified by indices into a list of vertices.
Definition MeshObject.h:194
IObject * clone() const override
Clone.
Definition MeshObject.h:67
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
Definition MeshObject.h:179
const Kernel::Matrix< double > & getAppliedRotation() const override
The goniometer rotation baked into this shape, i.e.
Definition MeshObject.h:148
IObject * cloneWithMaterial(const Kernel::Material &material) const override
Definition MeshObject.h:68
std::string m_id
string to return as ID
Definition MeshObject.h:185
const std::string & id() const override
Definition MeshObject.h:77
BoundingBox m_boundingBox
Cache for object's bounding box.
Definition MeshObject.h:173
MeshObject & operator=(const MeshObject &)=delete
Assignment operator.
int getName() const override
Definition MeshObject.h:79
~MeshObject() override=default
Destructor.
std::shared_ptr< vtkGeometryCacheReader > m_vtk_cache_reader
a pointer to a class for reading from the geometry cache
Definition MeshObject.h:188
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.