Mantid
Loading...
Searching...
No Matches
GeometryHandler.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
15#include <memory>
16
17namespace Mantid::Geometry {
18
20
21GeometryHandler::GeometryHandler(const std::shared_ptr<CSGObject> &obj)
22 : m_triangulator(new detail::GeometryTriangulator(obj.get())), m_csgObj(obj.get()) {}
23
25 : m_triangulator(new detail::GeometryTriangulator(obj)), m_csgObj(obj) {}
26
28
30 m_triangulator = std::make_unique<detail::GeometryTriangulator>(detail::makeRenderingMesh(obj));
31 return *this;
32}
33
35
37 m_triangulator = std::make_unique<detail::GeometryTriangulator>(detail::makeRenderingMesh(obj));
38 return *this;
39}
40
42 if (handler.m_csgObj) {
43 m_csgObj = handler.m_csgObj;
44 if (handler.m_triangulator)
46 }
47 if (handler.m_objComp)
48 m_objComp = handler.m_objComp;
49 if (handler.m_shapeInfo)
50 m_shapeInfo = handler.m_shapeInfo;
51}
52
54 std::swap(this->m_csgObj, handler.m_csgObj);
55 std::swap(this->m_triangulator, handler.m_triangulator);
56 std::swap(this->m_objComp, handler.m_objComp);
57 std::swap(this->m_shapeInfo, handler.m_shapeInfo);
58 return *this;
59}
60
63
64std::shared_ptr<GeometryHandler> GeometryHandler::clone() const { return std::make_shared<GeometryHandler>(*this); }
65
67 if (m_shapeInfo)
69 else if (m_objComp != nullptr)
71 else if (canTriangulate())
73}
74
76 if (m_csgObj != nullptr)
78 render();
79}
80
82 if (canTriangulate())
83 return m_triangulator->numTriangleFaces();
84 return 0;
85}
86
88 if (canTriangulate())
89 return m_triangulator->numTriangleVertices();
90 return 0;
91}
92
93const std::vector<double> &GeometryHandler::getTriangleVertices() const {
94 static std::vector<double> empty;
95 if (canTriangulate())
96 return m_triangulator->getTriangleVertices();
97 return empty;
98}
99
100const std::vector<uint32_t> &GeometryHandler::getTriangleFaces() const {
101 static std::vector<uint32_t> empty;
102 if (canTriangulate())
103 return m_triangulator->getTriangleFaces();
104 return empty;
105}
106
107void GeometryHandler::setGeometryCache(size_t nPts, size_t nFaces, std::vector<double> &&pts,
108 std::vector<uint32_t> &&faces) {
109 if (canTriangulate()) {
110 m_triangulator->setGeometryCache(nPts, nFaces, std::move(pts), std::move(faces));
111 }
112}
113
114void GeometryHandler::GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors,
115 double &innerRadius, double &radius, double &height) const {
117 if (m_shapeInfo)
118 m_shapeInfo->getObjectGeometry(type, vectors, innerRadius, radius, height);
119}
120
122 m_triangulator.reset(nullptr);
124}
125} // namespace Mantid::Geometry
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
Constructive Solid Geometry object.
Definition: CSGObject.h:51
void updateGeometryHandler()
Updates the geometry handler if needed.
Definition: CSGObject.cpp:2173
Handles rendering of all object Geometry.
void setGeometryCache(size_t nPts, size_t nFaces, std::vector< double > &&pts, std::vector< uint32_t > &&faces)
Sets the geometry cache using the triangulation information provided.
IObjComponent * m_objComp
ObjComponent that uses this geometry handler.
GeometryHandler & operator=(const MeshObject &obj)
void setShapeInfo(detail::ShapeInfo &&shapeInfo)
CSGObject * m_csgObj
Object that uses this geometry handler.
GeometryHandler(IObjComponent *comp)
Constructor.
void render() const
Render Object or ObjComponent.
const std::vector< double > & getTriangleVertices() const
Extract the vertices of the triangles.
void GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector< Kernel::V3D > &vector, double &innerRadius, double &radius, double &height) const
return the actual type and points of one of the "standard" objects, cuboid/cone/cyl/sphere
size_t numberOfPoints() const
get the number of points or vertices
std::unique_ptr< detail::GeometryTriangulator > m_triangulator
const std::vector< uint32_t > & getTriangleFaces() const
Extract the Faces of the triangles.
size_t numberOfTriangles() const
get the number of triangles
std::shared_ptr< GeometryHandler > clone() const
void initialize() const
Prepare/Initialize Object/ObjComponent to be rendered.
std::shared_ptr< detail::ShapeInfo > m_shapeInfo
const detail::ShapeInfo & shapeInfo() const
Object Component class, this class brings together the physical attributes of the component to the po...
Definition: IObjComponent.h:37
Triangular Mesh Object.
Definition: MeshObject.h:50
GeometryTriangulator : Triangulates object surfaces.
MANTID_GEOMETRY_DLL void renderIObjComponent(const IObjComponent &objComp)
Render IObjComponent.
MANTID_GEOMETRY_DLL void renderTriangulated(detail::GeometryTriangulator &triangulator)
Render Traingulated Surface.
MANTID_GEOMETRY_DLL void renderShape(const detail::ShapeInfo &shapeInfo)
Renders a sphere, cuboid, hexahedron, cone or cylinder.
std::unique_ptr< Geometry::RenderingMesh > makeRenderingMesh(const Adaptee &adaptee)