Mantid
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Geometry::HKLGenerator Class Reference

HKLGenerator. More...

#include <HKLGenerator.h>

Classes

class  const_iterator
 The const_iterator class. More...
 

Public Member Functions

const const_iteratorbegin () const
 Returns an iterator to the beginning of the sequence. More...
 
const const_iteratorend () 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
 

Detailed Description

HKLGenerator.

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.

Constructor & Destructor Documentation

◆ HKLGenerator() [1/4]

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.

◆ HKLGenerator() [2/4]

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.

◆ HKLGenerator() [3/4]

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.

◆ HKLGenerator() [4/4]

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.

◆ ~HKLGenerator()

virtual Mantid::Geometry::HKLGenerator::~HKLGenerator ( )
virtualdefault

Member Function Documentation

◆ begin()

const const_iterator & Mantid::Geometry::HKLGenerator::begin ( ) const
inline

◆ end()

const const_iterator & Mantid::Geometry::HKLGenerator::end ( ) const
inline

◆ getBeginIterator()

HKLGenerator::const_iterator Mantid::Geometry::HKLGenerator::getBeginIterator ( ) const
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().

◆ getEndHKL()

V3D Mantid::Geometry::HKLGenerator::getEndHKL ( ) const
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().

◆ getEndIterator()

HKLGenerator::const_iterator Mantid::Geometry::HKLGenerator::getEndIterator ( ) const
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().

◆ getSize()

size_t Mantid::Geometry::HKLGenerator::getSize ( const Kernel::V3D min,
const Kernel::V3D max 
) const
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().

◆ size()

size_t Mantid::Geometry::HKLGenerator::size ( ) const
inline

Member Data Documentation

◆ m_begin

const_iterator Mantid::Geometry::HKLGenerator::m_begin
private

Definition at line 160 of file HKLGenerator.h.

Referenced by HKLGenerator().

◆ m_end

const_iterator Mantid::Geometry::HKLGenerator::m_end
private

Definition at line 161 of file HKLGenerator.h.

Referenced by HKLGenerator().

◆ m_hklMax

Kernel::V3D Mantid::Geometry::HKLGenerator::m_hklMax
private

Definition at line 156 of file HKLGenerator.h.

Referenced by getBeginIterator(), getEndHKL(), and HKLGenerator().

◆ m_hklMin

Kernel::V3D Mantid::Geometry::HKLGenerator::m_hklMin
private

Definition at line 155 of file HKLGenerator.h.

Referenced by getBeginIterator(), getEndHKL(), and HKLGenerator().

◆ m_size

size_t Mantid::Geometry::HKLGenerator::m_size
private

Definition at line 158 of file HKLGenerator.h.

Referenced by HKLGenerator().


The documentation for this class was generated from the following files: