Mantid
Loading...
Searching...
No Matches
SymmetryElementFactory.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2015 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
11#include "MantidGeometry/DllConfig.h"
14
15#include <map>
16#include <memory>
17#include <unordered_set>
18
19namespace Mantid {
20namespace Geometry {
21
36class MANTID_GEOMETRY_DLL AbstractSymmetryElementGenerator {
37public:
39
41 virtual SymmetryElement_sptr generateElement(const SymmetryOperation &operation) const = 0;
42
45 virtual bool canProcess(const SymmetryOperation &operation) const = 0;
46};
47
48using AbstractSymmetryElementGenerator_sptr = std::shared_ptr<AbstractSymmetryElementGenerator>;
49
56public:
57 SymmetryElement_sptr generateElement(const SymmetryOperation &operation) const override;
58 bool canProcess(const SymmetryOperation &operation) const override;
59};
60
67public:
68 SymmetryElement_sptr generateElement(const SymmetryOperation &operation) const override;
69 bool canProcess(const SymmetryOperation &operation) const override;
70};
71
78public:
79 SymmetryElement_sptr generateElement(const SymmetryOperation &operation) const override;
80 bool canProcess(const SymmetryOperation &operation) const override;
81};
82
83MANTID_GEOMETRY_DLL gsl_matrix *getGSLMatrix(const Kernel::IntMatrix &matrix);
84MANTID_GEOMETRY_DLL gsl_matrix *getGSLIdentityMatrix(size_t rows, size_t cols);
85
101public:
102protected:
103 V3R determineTranslation(const SymmetryOperation &operation) const;
104 V3R determineAxis(const Kernel::IntMatrix &matrix) const;
105
106 virtual std::string determineSymbol(const SymmetryOperation &operation) const = 0;
107};
108
117public:
118 SymmetryElement_sptr generateElement(const SymmetryOperation &operation) const override;
119 bool canProcess(const SymmetryOperation &operation) const override;
120
121protected:
122 SymmetryElementRotation::RotationSense determineRotationSense(const SymmetryOperation &operation,
123 const V3R &rotationAxis) const;
124
125 std::string determineSymbol(const SymmetryOperation &operation) const override;
126};
127
138public:
139 SymmetryElement_sptr generateElement(const SymmetryOperation &operation) const override;
140 bool canProcess(const SymmetryOperation &operation) const override;
141
142protected:
143 std::string determineSymbol(const SymmetryOperation &operation) const override;
144
145 static std::map<V3R, std::string> g_glideSymbolMap;
146};
147
188class MANTID_GEOMETRY_DLL SymmetryElementFactoryImpl {
189public:
190 virtual ~SymmetryElementFactoryImpl() = default;
191
192 SymmetryElement_sptr createSymElement(const SymmetryOperation &operation);
193
197 template <typename T> void subscribeSymmetryElementGenerator(const std::string &generatorClassName) {
198 AbstractSymmetryElementGenerator_sptr generator = std::make_shared<T>();
199
200 if (isSubscribed(generatorClassName)) {
201 throw std::runtime_error("A generator with name '" + generatorClassName + "' is already registered.");
202 }
203
204 subscribe(generator, generatorClassName);
205 }
206
207protected:
208 bool isSubscribed(const std::string &generatorClassName) const;
209 void subscribe(const AbstractSymmetryElementGenerator_sptr &generator, const std::string &generatorClassName);
210
211 SymmetryElement_sptr createFromPrototype(const std::string &identifier) const;
212 AbstractSymmetryElementGenerator_sptr getGenerator(const SymmetryOperation &operation) const;
213 void insertPrototype(const std::string &identifier, const SymmetryElement_sptr &prototype);
214
215 std::vector<AbstractSymmetryElementGenerator_sptr> m_generators;
216 std::unordered_set<std::string> m_generatorNames;
217 std::map<std::string, SymmetryElement_sptr> m_prototypes;
218
219private:
221};
222
224
225} // namespace Geometry
226} // namespace Mantid
227
228namespace Mantid {
229namespace Kernel {
230EXTERN_MANTID_GEOMETRY template class MANTID_GEOMETRY_DLL
232}
233} // namespace Mantid
234
235#define DECLARE_SYMMETRY_ELEMENT_GENERATOR(classname) \
236 namespace { \
237 Mantid::Kernel::RegistrationHelper register_symmetry_element_generator_##classname(( \
238 (Mantid::Geometry::SymmetryElementFactory::Instance().subscribeSymmetryElementGenerator<classname>(#classname)), \
239 0)); \
240 }
SymmetryElementFactoryImpl does not generate SymmetryElement objects directly.
virtual SymmetryElement_sptr generateElement(const SymmetryOperation &operation) const =0
Must generate a valid SymmetryElement from the given operation.
virtual bool canProcess(const SymmetryOperation &operation) const =0
Should return true if the generator can produce a valid SymmetryElement from the provided SymmetryOpe...
This factory takes a SymmetryOperation and generates the corresponding SymmetryElement.
std::unordered_set< std::string > m_generatorNames
std::map< std::string, SymmetryElement_sptr > m_prototypes
std::vector< AbstractSymmetryElementGenerator_sptr > m_generators
void subscribeSymmetryElementGenerator(const std::string &generatorClassName)
Subscribes the generator of type T with its class name into the factory, throws std::runtime_error if...
This implementation of AbstractSymmetryElementGenerator produces only identity elements.
This implementation of AbstractSymmetryElementGenerator produces only inversion elements.
SymmetryElementMirrorGenerator also inherits from SymmetryElementWithAxisGenerator.
static std::map< V3R, std::string > g_glideSymbolMap
SymmetryElementRotationGenerator inherits from SymmetryElementWithAxisGenerator, using its methods fo...
This implementation of AbstractSymmetryElementGenerator produces only translation elements.
SymmetryElementWithAxisGenerator does not create any elements directly, it serves as a base for Symme...
virtual std::string determineSymbol(const SymmetryOperation &operation) const =0
Crystallographic symmetry operations are composed of a rotational component, which is represented by ...
Manage the lifetime of a class intended to be a singleton.
MANTID_GEOMETRY_DLL gsl_matrix * getGSLIdentityMatrix(size_t rows, size_t cols)
Returns a GSL-indentity matrix.
std::shared_ptr< AbstractSymmetryElementGenerator > AbstractSymmetryElementGenerator_sptr
MANTID_GEOMETRY_DLL gsl_matrix * getGSLMatrix(const Kernel::IntMatrix &matrix)
Returns a GSL-matrix for the given IntMatrix.
std::shared_ptr< SymmetryElement > SymmetryElement_sptr
Helper class which provides the Collimation Length for SANS instruments.
Policy class controlling creation of the singleton Implementation classes should mark their default c...