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 +
14#include <memory>
15
16namespace Mantid::Geometry {
17
19
20GeometryHandler::GeometryHandler(const std::shared_ptr<CSGObject> &obj)
21 : m_triangulator(new detail::GeometryTriangulator(obj.get())), m_csgObj(obj.get()) {}
22
24 : m_triangulator(new detail::GeometryTriangulator(obj)), m_csgObj(obj) {}
25
27
29 m_triangulator = std::make_unique<detail::GeometryTriangulator>(detail::makeRenderingMesh(obj));
30 return *this;
31}
32
34
36 m_triangulator = std::make_unique<detail::GeometryTriangulator>(detail::makeRenderingMesh(obj));
37 return *this;
38}
39
41 if (handler.m_csgObj) {
42 m_csgObj = handler.m_csgObj;
43 if (handler.m_triangulator)
45 }
46 if (handler.m_objComp)
47 m_objComp = handler.m_objComp;
48 if (handler.m_shapeInfo)
49 m_shapeInfo = handler.m_shapeInfo;
50}
51
53 std::swap(this->m_csgObj, handler.m_csgObj);
54 std::swap(this->m_triangulator, handler.m_triangulator);
55 std::swap(this->m_objComp, handler.m_objComp);
56 std::swap(this->m_shapeInfo, handler.m_shapeInfo);
57 return *this;
58}
59
62
63std::shared_ptr<GeometryHandler> GeometryHandler::clone() const { return std::make_shared<GeometryHandler>(*this); }
64
73
75 if (m_csgObj != nullptr)
77 render();
78}
79
81 if (canTriangulate())
82 return m_triangulator->numTriangleFaces();
83 return 0;
84}
85
87 if (canTriangulate())
88 return m_triangulator->numTriangleVertices();
89 return 0;
90}
91
92const std::vector<double> &GeometryHandler::getTriangleVertices() const {
93 static std::vector<double> empty;
94 if (canTriangulate())
95 return m_triangulator->getTriangleVertices();
96 return empty;
97}
98
99const std::vector<uint32_t> &GeometryHandler::getTriangleFaces() const {
100 static std::vector<uint32_t> empty;
101 if (canTriangulate())
102 return m_triangulator->getTriangleFaces();
103 return empty;
104}
105
106void GeometryHandler::setGeometryCache(size_t nPts, size_t nFaces, std::vector<double> &&pts,
107 std::vector<uint32_t> &&faces) {
108 if (canTriangulate()) {
109 m_triangulator->setGeometryCache(nPts, nFaces, std::move(pts), std::move(faces));
110 }
111}
112
113void GeometryHandler::GetObjectGeom(detail::ShapeInfo::GeometryShape &type, std::vector<Kernel::V3D> &vectors,
114 double &innerRadius, double &radius, double &height) const {
116 if (m_shapeInfo)
117 m_shapeInfo->getObjectGeometry(type, vectors, innerRadius, radius, height);
118}
119
121 m_triangulator.reset(nullptr);
123}
124} // namespace Mantid::Geometry
double height
Definition GetAllEi.cpp:155
double obj
the value of the quadratic function
Constructive Solid Geometry object.
Definition CSGObject.h:51
void updateGeometryHandler()
Updates the geometry handler if needed.
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...
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)