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#endif
18#include <map>
19
20//----------------------------------------------------------------------
21// Forward declarations
22//----------------------------------------------------------------------
24namespace Poco {
25namespace XML {
26class Element;
27}
28} // namespace Poco
30
31namespace Mantid {
32
33namespace Geometry {
34class Surface;
35class IObject;
36class CSGObject;
37
43
44 void rotatePoints(const std::vector<double> &rotationMatrix) {
45 lfb.rotate(rotationMatrix);
46 lft.rotate(rotationMatrix);
47 lbb.rotate(rotationMatrix);
48 rfb.rotate(rotationMatrix);
49 }
50};
51
52struct Hexahedron {
53 Kernel::V3D lfb; // left front bottom
54 Kernel::V3D lft; // left front top
55 Kernel::V3D lbb; // left back bottom
56 Kernel::V3D lbt; // left back top
57 Kernel::V3D rfb; // right front bottom
58 Kernel::V3D rft; // right front top
59 Kernel::V3D rbb; // right back bottom
60 Kernel::V3D rbt; // right back top
61
62 void rotatePoints(const std::vector<double> &rotationMatrix) {
63 lfb.rotate(rotationMatrix);
64 lft.rotate(rotationMatrix);
65 lbb.rotate(rotationMatrix);
66 lbt.rotate(rotationMatrix);
67 rfb.rotate(rotationMatrix);
68 rft.rotate(rotationMatrix);
69 rbb.rotate(rotationMatrix);
70 rbt.rotate(rotationMatrix);
71 }
72};
89class MANTID_GEOMETRY_DLL ShapeFactory {
90public:
91 std::shared_ptr<CSGObject> createShape(Poco::XML::Element *pElem);
92 std::shared_ptr<CSGObject> createShape(std::string shapeXML, bool addTypeTag = true);
93
94 static std::shared_ptr<CSGObject> createSphere(const Kernel::V3D &centre, double radius);
95 static std::shared_ptr<CSGObject> createHexahedralShape(double xlb, double xlf, double xrf, double xrb, double ylb,
96 double ylf, double yrf, double yrb);
97 std::string addGoniometerTag(const Kernel::Matrix<double> &rotateMatrix, std::string xml);
98 static Kernel::Matrix<double> generateMatrix(double xRotation, double yRotation, double zRotation);
99 static Kernel::Matrix<double> generateXRotation(double xRotation);
100 static Kernel::Matrix<double> generateYRotation(double yRotation);
101 static Kernel::Matrix<double> generateZRotation(double zRotation);
102
103private:
104 static std::string sphereAlgebra(const int surfaceID);
105 std::string parseSphere(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
106 std::string parseInfinitePlane(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
107 std::string parseInfiniteCylinder(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim,
108 int &l_id);
109 std::string parseCylinder(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
110 std::string parseHollowCylinder(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
111
112 CuboidCorners parseCuboid(Poco::XML::Element *pElem);
113 std::string parseCuboid(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
114 std::string parseInfiniteCone(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
115 std::string parseCone(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
116
117 static std::string parseHexahedronFromStruct(const Hexahedron &hex, std::map<int, std::shared_ptr<Surface>> &prim,
118 int &l_id);
119 Hexahedron parseHexahedron(Poco::XML::Element *pElem);
120 std::string parseHexahedron(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
121 std::string parseTaperedGuide(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
122 std::string parseTorus(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim, int &l_id);
123 std::string parseSliceOfCylinderRing(Poco::XML::Element *pElem, std::map<int, std::shared_ptr<Surface>> &prim,
124 int &l_id);
125
126 Poco::XML::Element *getShapeElement(Poco::XML::Element *pElem, const std::string &name);
127 Poco::XML::Element *getOptionalShapeElement(Poco::XML::Element *pElem, const std::string &name);
128 double getDoubleAttribute(Poco::XML::Element *pElem, const std::string &name);
129 Kernel::V3D parsePosition(Poco::XML::Element *pElem);
130 void createGeometryHandler(Poco::XML::Element *, const std::shared_ptr<CSGObject> &);
131
132 Kernel::Matrix<double> m_gonioRotateMatrix = Kernel::Matrix<double>(3, 3, 1);
133 Kernel::Matrix<double> m_rotateAllMatrix = Kernel::Matrix<double>(3, 3, 1);
134};
135
136} // namespace Geometry
137} // namespace Mantid
double radius
Definition: Rasterize.cpp:31
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Definition: ShapeFactory.h:89
Numerical Matrix class.
Definition: Matrix.h:42
Class for 3D vectors.
Definition: V3D.h:34
void rotate(const Matrix< double > &) noexcept
Rotate a point by a matrix.
Definition: V3D.cpp:217
Helper class which provides the Collimation Length for SANS instruments.
Definition: Algorithm.h:30
void rotatePoints(const std::vector< double > &rotationMatrix)
Definition: ShapeFactory.h:44
void rotatePoints(const std::vector< double > &rotationMatrix)
Definition: ShapeFactory.h:62