Mantid
Loading...
Searching...
No Matches
ShapeFactory.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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 "MantidGeometry/DllConfig.h"
13#include "MantidKernel/Matrix.h"
14#include "MantidKernel/V3D.h"
15#ifndef Q_MOC_RUN
16#include <memory>
17#include <optional>
18#endif
19#include <map>
20
21//----------------------------------------------------------------------
22// Forward declarations
23//----------------------------------------------------------------------
25namespace Poco {
26namespace XML {
27class Element;
28}
29} // namespace Poco
31
32namespace Mantid {
33
34namespace Geometry {
35class Surface;
36class IObject;
37class CSGObject;
38
44
45 void rotatePoints(const std::vector<double> &rotationMatrix) {
46 lfb.rotate(rotationMatrix);
47 lft.rotate(rotationMatrix);
48 lbb.rotate(rotationMatrix);
49 rfb.rotate(rotationMatrix);
50 }
51};
52
53struct Hexahedron {
54 Kernel::V3D lfb; // left front bottom
55 Kernel::V3D lft; // left front top
56 Kernel::V3D lbb; // left back bottom
57 Kernel::V3D lbt; // left back top
58 Kernel::V3D rfb; // right front bottom
59 Kernel::V3D rft; // right front top
60 Kernel::V3D rbb; // right back bottom
61 Kernel::V3D rbt; // right back top
62
63 void rotatePoints(const std::vector<double> &rotationMatrix) {
64 lfb.rotate(rotationMatrix);
65 lft.rotate(rotationMatrix);
66 lbb.rotate(rotationMatrix);
67 lbt.rotate(rotationMatrix);
68 rfb.rotate(rotationMatrix);
69 rft.rotate(rotationMatrix);
70 rbb.rotate(rotationMatrix);
71 rbt.rotate(rotationMatrix);
72 }
73};
90class MANTID_GEOMETRY_DLL ShapeFactory {
91public:
92 std::shared_ptr<CSGObject> createShape(Poco::XML::Element *pElem);
93 std::shared_ptr<CSGObject> createShape(std::string shapeXML, bool addTypeTag = true);
94
95 static std::shared_ptr<CSGObject> createSphere(const Kernel::V3D &centre, double radius);
96 static std::shared_ptr<CSGObject> createHexahedralShape(double xlb, double xlf, double xrf, double xrb, double ylb,
97 double ylf, double yrf, double yrb);
100 std::string addGoniometerTag(const Kernel::Matrix<double> &rotateMatrix, std::string xml);
103 std::string addAppliedGoniometerTag(const Kernel::Matrix<double> &bakedRotation, std::string xml);
106 std::string rebakeGoniometer(const Kernel::Matrix<double> &newBake, std::string xml,
107 const Kernel::Matrix<double> &currentBake);
109 static Kernel::Matrix<double> goniometerFromXML(const std::string &xml);
112 static Kernel::Matrix<double> appliedGoniometerFromXML(const std::string &xml);
113 static Kernel::Matrix<double> generateMatrix(double xRotation, double yRotation, double zRotation);
114 static Kernel::Matrix<double> generateXRotation(double xRotation);
115 static Kernel::Matrix<double> generateYRotation(double yRotation);
116 static Kernel::Matrix<double> generateZRotation(double zRotation);
117
118private:
119 static std::string sphereAlgebra(const int surfaceID);
120 std::string parseSphere(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
121 std::string parseInfinitePlane(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
122 std::string parseInfiniteCylinder(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim,
123 int &l_id);
124 std::string parseCylinder(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
125 std::string parseHollowCylinder(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
126
127 CuboidCorners parseCuboid(Poco::XML::Element *pElem);
128 std::string parseCuboid(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
129 std::string parseInfiniteCone(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
130 std::string parseCone(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
131
132 static std::string parseHexahedronFromStruct(const Hexahedron &hex, std::map<int, std::shared_ptr<Surface>> &prim,
133 int &l_id);
134 Hexahedron parseHexahedron(Poco::XML::Element *pElem);
135 std::string parseHexahedron(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
136 std::string parseTaperedGuide(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
137 std::string parseTorus(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
138 std::string parseSliceOfCylinderRing(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim,
139 int &l_id);
140
141 Poco::XML::Element *getShapeElement(Poco::XML::Element *pElem, const std::string &name);
142 Poco::XML::Element *getOptionalShapeElement(Poco::XML::Element *pElem, const std::string &name);
143 static double getDoubleAttribute(Poco::XML::Element *pElem, const std::string &name);
144 Kernel::V3D parsePosition(Poco::XML::Element *pElem);
145 void createGeometryHandler(Poco::XML::Element *, const std::shared_ptr<CSGObject> &);
146 static std::string insertMatrixTag(const std::string &tagName, const Kernel::Matrix<double> &matrix, std::string xml);
147 static Kernel::Matrix<double> parseMatrixElement(Poco::XML::Element *pElem);
148 static std::optional<Kernel::Matrix<double>> matrixFromXMLTag(const std::string &xml, const std::string &tagName);
149
150 Kernel::Matrix<double> m_gonioRotateMatrix = Kernel::Matrix<double>(3, 3, 1);
151 Kernel::Matrix<double> m_rotateAllMatrix = Kernel::Matrix<double>(3, 3, 1);
152};
153
154} // namespace Geometry
155} // namespace Mantid
std::string name
Definition Run.cpp:60
double centre
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Numerical Matrix class.
Definition Matrix.h:41
Class for 3D vectors.
Definition V3D.h:35
void rotate(const Matrix< double > &) noexcept
Rotate a point by a matrix.
Definition V3D.cpp:214
Helper class which provides the Collimation Length for SANS instruments.
void rotatePoints(const std::vector< double > &rotationMatrix)
void rotatePoints(const std::vector< double > &rotationMatrix)