Mantid
|
#include <HKLGenerator.h>
Classes | |
class | const_iterator |
The const_iterator class. More... | |
Public Member Functions | |
const const_iterator & | begin () const |
Returns an iterator to the beginning of the sequence. More... | |
const const_iterator & | end () const |
Returns an iterator which "points at" one element past the end. More... | |
HKLGenerator (const Kernel::V3D &hklMin, const Kernel::V3D &hklMax) | |
Constructs a generator that creates all indices from hklMin to hklMax. More... | |
HKLGenerator (const Kernel::V3D &hklMinMax) | |
Constructs a generator that creates all indices from -hklMinMax to hklMinMax. More... | |
HKLGenerator (const UnitCell &unitCell, double dMin) | |
Constructs a generator that creates all indices for the given cell up to dMin. More... | |
HKLGenerator (int hMinMax, int kMinMax, int lMinMax) | |
Constructs a generator that creates all indices from -h,-k,-l to h,k,l. More... | |
size_t | size () const |
Returns the number of HKLs to be generated. More... | |
virtual | ~HKLGenerator ()=default |
Private Member Functions | |
const_iterator | getBeginIterator () const |
Constructs an iterator that points to the beginning of the sequence. More... | |
Kernel::V3D | getEndHKL () const |
Returns the HKL "one past the maximum". More... | |
const_iterator | getEndIterator () const |
Constructs an iterator that points to an HKL one past the maximum. More... | |
size_t | getSize (const Kernel::V3D &min, const Kernel::V3D &max) const |
Returns the number of indices between min and max. More... | |
Private Attributes | |
const_iterator | m_begin |
const_iterator | m_end |
Kernel::V3D | m_hklMax |
Kernel::V3D | m_hklMin |
size_t | m_size |
HKLGenerator is a pseudo-container that helps in generating actual containers with V3D-objects representing Miller indices (HKL).
It's a common task to generate lists of Miller indices. The simplest way of doing that is to simply create a nested loop structure that goes through all combinations of H, K, L within some limits and then put them into a container (vector, list, set, ...):
for(int h = -hmin; h <= hmax; ++h) { for(int k = -kmin; k <= kmax; ++k) { for(int l = -lmin; l <= lmax; ++l) { hkls.emplace_back(h, k, l); } } }
In most cases the list is not used like that, instead it's filtered using some criteria, for example a certain range of d-spacings or others, so the reflection needs to be checked first:
... hkl = V3D(h, k, l) if(isOk(hkl)) { hkls.emplace_back(hkl); } ...
Instead of explicitly stating the triple-loop, HKLGenerator provides a shorter way for this process using a const_iterator. The first code example then becomes this:
HKLGenerator generator(V3D(hmin, kmin, lmin), V3D(hmax, kmax, lmax)); for(auto hkl = generator.begin(); hkl != generator.end(); ++hkl) { hkls.emplace_back(*hkl); }
Or even shorter, using std::copy:
HKLGenerator generator(V3D(hmin, kmin, lmin), V3D(hmax, kmax, lmax)); std::copy(generator.begin(), generator.end(), std::back_inserter(hkls));
It's also possible to use filters this way, but in a much easier fashion, using std::copy_remove_if (pre C++11) or std::copy_if (C++11):
pre C++11 std::copy_remove_if(generator.begin(), generator.end(), std::back_inserter(hkls), isNotOk)
C++11 std::copy_if(generator.begin(), generator.end(), std::back_inserter(hkls), isOk)
See the documentation for HKLFilter for more details on how to perform actual filtering.
Please be aware that the iterator increments infinitely if it passes the specified maximimum HKL. In that case K and L remain constant while H is incremented (until it overflows).
@author Michael Wedel, ESS @date 23/09/2015
Definition at line 82 of file HKLGenerator.h.
Mantid::Geometry::HKLGenerator::HKLGenerator | ( | const Kernel::V3D & | hklMin, |
const Kernel::V3D & | hklMax | ||
) |
Constructs a generator that creates all indices from hklMin to hklMax.
Definition at line 14 of file HKLGenerator.cpp.
Mantid::Geometry::HKLGenerator::HKLGenerator | ( | const Kernel::V3D & | hklMinMax | ) |
Constructs a generator that creates all indices from -hklMinMax to hklMinMax.
Definition at line 20 of file HKLGenerator.cpp.
Mantid::Geometry::HKLGenerator::HKLGenerator | ( | int | hMinMax, |
int | kMinMax, | ||
int | lMinMax | ||
) |
Constructs a generator that creates all indices from -h,-k,-l to h,k,l.
Definition at line 25 of file HKLGenerator.cpp.
References getBeginIterator(), getEndIterator(), getSize(), m_begin, m_end, m_hklMax, m_hklMin, and m_size.
Mantid::Geometry::HKLGenerator::HKLGenerator | ( | const UnitCell & | unitCell, |
double | dMin | ||
) |
Constructs a generator that creates all indices for the given cell up to dMin.
Definition at line 35 of file HKLGenerator.cpp.
References getBeginIterator(), getEndIterator(), getSize(), m_begin, m_end, m_hklMax, m_hklMin, and m_size.
|
virtualdefault |
|
inline |
Returns an iterator to the beginning of the sequence.
Definition at line 143 of file HKLGenerator.h.
Referenced by Mantid::Crystal::PredictSatellitePeaks::exec(), Mantid::Crystal::PredictPeaks::fillPossibleHKLsUsingGenerator(), Mantid::Geometry::ReflectionGenerator::getHKLs(), and Mantid::Geometry::ReflectionGenerator::getUniqueHKLs().
|
inline |
Returns an iterator which "points at" one element past the end.
Definition at line 146 of file HKLGenerator.h.
Referenced by Mantid::Crystal::PredictSatellitePeaks::exec(), Mantid::Crystal::PredictPeaks::fillPossibleHKLsUsingGenerator(), Mantid::Geometry::ReflectionGenerator::getHKLs(), and Mantid::Geometry::ReflectionGenerator::getUniqueHKLs().
|
private |
Constructs an iterator that points to the beginning of the sequence.
Definition at line 51 of file HKLGenerator.cpp.
References m_hklMax, and m_hklMin.
Referenced by HKLGenerator().
|
private |
Returns the HKL "one past the maximum".
Definition at line 59 of file HKLGenerator.cpp.
References m_hklMax, m_hklMin, Mantid::Kernel::V3D::X(), Mantid::Kernel::V3D::Y(), and Mantid::Kernel::V3D::Z().
Referenced by getEndIterator().
|
private |
Constructs an iterator that points to an HKL one past the maximum.
Definition at line 56 of file HKLGenerator.cpp.
References getEndHKL().
Referenced by HKLGenerator().
|
private |
Returns the number of indices between min and max.
Definition at line 45 of file HKLGenerator.cpp.
References Mantid::Kernel::V3D::X(), Mantid::Kernel::V3D::Y(), and Mantid::Kernel::V3D::Z().
Referenced by HKLGenerator().
|
inline |
Returns the number of HKLs to be generated.
Definition at line 140 of file HKLGenerator.h.
References m_size.
Referenced by Mantid::Crystal::PredictSatellitePeaks::exec(), Mantid::Crystal::PredictPeaks::fillPossibleHKLsUsingGenerator(), Mantid::Geometry::ReflectionGenerator::getHKLs(), and Mantid::Geometry::ReflectionGenerator::getUniqueHKLs().
|
private |
Definition at line 160 of file HKLGenerator.h.
Referenced by HKLGenerator().
|
private |
Definition at line 161 of file HKLGenerator.h.
Referenced by HKLGenerator().
|
private |
Definition at line 156 of file HKLGenerator.h.
Referenced by getBeginIterator(), getEndHKL(), and HKLGenerator().
|
private |
Definition at line 155 of file HKLGenerator.h.
Referenced by getBeginIterator(), getEndHKL(), and HKLGenerator().
|
private |
Definition at line 158 of file HKLGenerator.h.
Referenced by HKLGenerator().