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
30
31namespace Geometry {
32class CompGrp;
33class GeometryHandler;
34class Track;
35class vtkGeometryCacheReader;
36class vtkGeometryCacheWriter;
37
50class MANTID_GEOMETRY_DLL MeshObject : public IObject {
51public:
53 MeshObject(std::vector<uint32_t> faces, std::vector<Kernel::V3D> vertices, const Kernel::Material &material);
55 MeshObject(std::vector<uint32_t> &&faces, std::vector<Kernel::V3D> &&vertices, const Kernel::Material &&material);
56
58 MeshObject(const MeshObject &) = delete;
60 MeshObject &operator=(const MeshObject &) = delete;
62 virtual ~MeshObject() = default;
64 IObject *clone() const override { return new MeshObject(m_triangles, m_vertices, m_material); }
65 IObject *cloneWithMaterial(const Kernel::Material &material) const override {
66 return new MeshObject(m_triangles, m_vertices, material);
67 }
68
69 void setID(const std::string &id) override { m_id = id; }
70 const std::string &id() const override { return m_id; }
71
72 int getName() const override { return 0; }
73
74 const Kernel::Material &material() const override;
75 void setMaterial(const Kernel::Material &material) override;
76
78 bool hasValidShape() const override;
79
80 bool isValid(const Kernel::V3D &) const override;
81 bool isOnSide(const Kernel::V3D &) const override;
82 int calcValidType(const Kernel::V3D &Pt, const Kernel::V3D &uVec) const;
83
84 // INTERSECTION
85 int interceptSurface(Geometry::Track &) const override;
86 double distance(const Track &track) const override;
87
88 // Solid angle - uses triangleSolidAngle unless many (>30000) triangles
89 double solidAngle(const Kernel::V3D &observer) const override;
90 // Solid angle with a scaling of the object
91 double solidAngle(const Kernel::V3D &observer, const Kernel::V3D &scaleFactor) const override;
92
94 double volume() const override;
95
98 void getBoundingBox(double &xmax, double &ymax, double &zmax, double &xmin, double &ymin,
99 double &zmin) const override;
100
102 const BoundingBox &getBoundingBox() const override;
103
104 // find internal point to object
105 int getPointInObject(Kernel::V3D &point) const override;
106
108 boost::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
109 const size_t) const override;
110 boost::optional<Kernel::V3D> generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng,
111 const BoundingBox &activeRegion, const size_t) const override;
112
113 // Rendering member functions
114 void draw() const override;
115 // Initialize Drawing
116 void initDraw() const override;
117 // Get Geometry Handler
118 std::shared_ptr<GeometryHandler> getGeometryHandler() const override;
120 void setGeometryHandler(const std::shared_ptr<GeometryHandler> &h);
121
122 detail::ShapeInfo::GeometryShape shape() const override;
123 const detail::ShapeInfo &shapeInfo() const override;
124
125 void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors, double &innerRadius,
126 double &radius, double &height) const override;
127
129 size_t numberOfVertices() const;
130 std::vector<double> getVertices() const;
131 const std::vector<Kernel::V3D> &getV3Ds() const;
132 size_t numberOfTriangles() const;
133 std::vector<uint32_t> getTriangles() const;
134
135 void rotate(const Kernel::Matrix<double> &);
136 void translate(const Kernel::V3D &);
137 void multiply(const Kernel::Matrix<double> &);
138 void scale(const double scaleFactor);
139 void updateGeometryHandler();
140
141private:
142 void initialize();
144 void getIntersections(const Kernel::V3D &start, const Kernel::V3D &direction,
145 std::vector<Kernel::V3D> &intersectionPoints,
146 std::vector<Mantid::Geometry::TrackDirection> &entryExitFlags) const;
147
149 bool getTriangle(const size_t index, Kernel::V3D &v1, Kernel::V3D &v2, Kernel::V3D &v3) const;
151 bool searchForObject(Kernel::V3D &point) const;
152
155
157 const double M_TOLERANCE = 0.000001;
158
160 std::shared_ptr<GeometryHandler> m_handler;
161
162 // String from which object may be defined
163 std::string m_string;
164
166 std::string m_id;
167
169 std::shared_ptr<vtkGeometryCacheReader> m_vtk_cache_reader;
171 std::shared_ptr<vtkGeometryCacheWriter> m_vtk_cache_writer;
172
175 std::vector<uint32_t> m_triangles;
176 std::vector<Kernel::V3D> m_vertices;
179};
180
181} // NAMESPACE Geometry
182} // NAMESPACE Mantid
double height
Definition: GetAllEi.cpp:155
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
double radius
Definition: Rasterize.cpp:31
double innerRadius
Definition: Rasterize.cpp:39
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
IObject : Interface for geometry objects.
Definition: IObject.h:41
Triangular Mesh Object.
Definition: MeshObject.h:50
Kernel::Material m_material
material composition
Definition: MeshObject.h:178
std::shared_ptr< vtkGeometryCacheWriter > m_vtk_cache_writer
a pointer to a class for writing to the geometry cache
Definition: MeshObject.h:171
MeshObject(const MeshObject &)=delete
Copy constructor.
virtual ~MeshObject()=default
Destructor.
std::vector< Kernel::V3D > m_vertices
Definition: MeshObject.h:176
void setID(const std::string &id) override
Definition: MeshObject.h:69
std::vector< uint32_t > m_triangles
Contents Triangles are specified by indices into a list of vertices.
Definition: MeshObject.h:175
IObject * clone() const override
Clone.
Definition: MeshObject.h:64
std::shared_ptr< GeometryHandler > m_handler
Geometry Handle for rendering.
Definition: MeshObject.h:160
IObject * cloneWithMaterial(const Kernel::Material &material) const override
Definition: MeshObject.h:65
std::string m_id
string to return as ID
Definition: MeshObject.h:166
const std::string & id() const override
Definition: MeshObject.h:70
BoundingBox m_boundingBox
Cache for object's bounding box.
Definition: MeshObject.h:154
MeshObject & operator=(const MeshObject &)=delete
Assignment operator.
int getName() const override
Definition: MeshObject.h:72
std::shared_ptr< vtkGeometryCacheReader > m_vtk_cache_reader
a pointer to a class for reading from the geometry cache
Definition: MeshObject.h:169
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.