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 new MeshObject(m_triangles, m_vertices, m_material); }
68 IObject *cloneWithMaterial(const Kernel::Material &material) const override {
69 return new MeshObject(m_triangles, m_vertices, material);
70 }
71
72 void setID(const std::string &id) override { m_id = id; }
73 const std::string &id() const override { return m_id; }
74
75 int getName() const override { return 0; }
76
77 const Kernel::Material &material() const override;
78 void setMaterial(const Kernel::Material &material) override;
79
81 bool hasValidShape() const override;
82
83 bool isValid(const Kernel::V3D &) const override;
84 bool isOnSide(const Kernel::V3D &) const override;
85 int calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const;
86
87 // INTERSECTION
88 int interceptSurface(Geometry::Track &) const override;
89 double distance(const Track &track) const override;
90
91 // Solid angle - uses triangleSolidAngle unless many (>30000) triangles
92 double solidAngle(const SolidAngleParams &params) const override;
93 // Solid angle with a scaling of the object
94 double solidAngle(const SolidAngleParams &params, const Kernel::V3D &scaleFactor) const override;
95
97 double volume() const override;
98
101 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
102 double &zmin) const override;
103
105 const BoundingBox &getBoundingBox() const override;
106
107 // find internal point to object
108 int getPointInObject(Kernel::V3D &point) const override;
109
111 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
112 const size_t) const override;
113 std::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
114 const BoundingBox &activeRegion, const size_t) const override;
115
116 // Rendering member functions
117 void draw() const override;
118 // Initialize Drawing
119 void initDraw() const override;
120 // Get Geometry Handler
121 std::shared_ptr<GeometryHandler> getGeometryHandler() const override;
123 void setGeometryHandler(const std::shared_ptr<GeometryHandler> &h);
124
125 detail::ShapeInfo::GeometryShape shape() const override;
126 const detail::ShapeInfo &shapeInfo() const override;
127
128 void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors, double &innerRadius,
129 double &radius, double &height) const override;
130
132 size_t numberOfVertices() const;
133 std::vector<double> getVertices() const;
134 const std::vector<Kernel::V3D> &getV3Ds() const;
135 size_t numberOfTriangles() const;
136 const std::vector<uint32_t> &getTriangles() const;
137
138 void rotate(const Kernel::Matrix<double> &);
139 void translate(const Kernel::V3D &);
140 void multiply(const Kernel::Matrix<double> &);
141 void scale(const double scaleFactor);
142 void updateGeometryHandler();
143
145 void saveNexus(Nexus::File *file, const std::string &group) const;
147 static std::shared_ptr<MeshObject> loadNexus(Nexus::File *file, const std::string &group,
148 const Kernel::Material &material);
149
150private:
151 void initialize();
153 void getIntersections(const Kernel::V3D &start, const Kernel::V3D &direction,
154 std::vector<Kernel::V3D> &intersectionPoints,
155 std::vector<Mantid::Geometry::TrackDirection> &entryExitFlags) const;
156
158 bool getTriangle(const size_t index, Kernel::V3D &v1, Kernel::V3D &v2, Kernel::V3D &v3) const;
160 bool searchForObject(Kernel::V3D &point) const;
161
164
166 const double M_TOLERANCE = 0.000001;
167
169 std::shared_ptr<GeometryHandler> m_handler;
170
171 // String from which object may be defined
172 std::string m_string;
173
175 std::string m_id;
176
178 std::shared_ptr<vtkGeometryCacheReader> m_vtk_cache_reader;
180 std::shared_ptr<vtkGeometryCacheWriter> m_vtk_cache_writer;
181
184 std::vector<uint32_t> m_triangles;
185 std::vector<Kernel::V3D> m_vertices;
188};
189
190} // NAMESPACE Geometry
191} // 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:42
Triangular Mesh Object.
Definition MeshObject.h:53
Kernel::Material m_material
material composition
Definition MeshObject.h:187
std::shared_ptr< vtkGeometryCacheWriter > m_vtk_cache_writer
a pointer to a class for writing to the geometry cache
Definition MeshObject.h:180
MeshObject(const MeshObject &)=delete
Copy constructor.
std::vector< Kernel::V3D > m_vertices
Definition MeshObject.h:185
void setID(const std::string &id) override
Definition MeshObject.h:72
std::vector< uint32_t > m_triangles
Contents Triangles are specified by indices into a list of vertices.
Definition MeshObject.h:184
IObject * clone() const override
Clone.
Definition MeshObject.h:67
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
Definition MeshObject.h:169
IObject * cloneWithMaterial(const Kernel::Material &material) const override
Definition MeshObject.h:68
std::string m_id
string to return as ID
Definition MeshObject.h:175
const std::string & id() const override
Definition MeshObject.h:73
BoundingBox m_boundingBox
Cache for object's bounding box.
Definition MeshObject.h:163
MeshObject & operator=(const MeshObject &)=delete
Assignment operator.
int getName() const override
Definition MeshObject.h:75
~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:178
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:42
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.