BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
Frame Class Reference

Description

Holds one or two axes.

Definition at line 27 of file Frame.h.

Collaboration diagram for Frame:
[legend]

Public Member Functions

 Frame (const std::vector< IAxis * > &axes)
 Constructor that takes ownership of supplied axes. More...
 
virtual ~Frame ()
 
std::vector< int > allIndices (size_t i_flat) const
 Returns vector of axes indices for given global index. More...
 
const IAxisaxis (size_t k_axis) const
 Returns axis with given serial number. More...
 
std::vector< IAxis * > cloned_axes () const
 Returns cloned axes. More...
 
bool hasSameSizes (const Frame &) const
 Returns true if both Frames have same rank, and all axes have same sizes. More...
 
bool operator== (const Frame &) const
 Returns true if both Frames have same rank, and all axes are equal. More...
 
double projectedCoord (size_t i_flat, size_t k_axis) const
 Returns the value of selected axis for given i_flat. More...
 
size_t projectedIndex (size_t i_flat, size_t k_axis) const
 Returns axis bin index for given global index. More...
 
size_t projectedSize (size_t k_axis) const
 Returns number of bins along axis. More...
 
size_t rank () const
 Returns number of dimensions. More...
 
size_t size () const
 Returns total number of bins. More...
 
size_t toGlobalIndex (const std::vector< unsigned > &axes_indices) const
 Returns global index for specified indices of axes. More...
 
const IAxisxAxis () const
 
const IAxisyAxis () const
 

Protected Attributes

OwningVector< IAxism_axes
 

Private Attributes

size_t m_size
 

Constructor & Destructor Documentation

◆ Frame()

Frame::Frame ( const std::vector< IAxis * > &  axes)

Constructor that takes ownership of supplied axes.

Definition at line 20 of file Frame.cpp.

21  : m_axes(axes)
22 {
23  m_size = 1;
24  for (size_t k = 0; k < rank(); ++k) {
25  ASSERT(axis(k).size() > 0);
26  m_size *= axis(k).size();
27  }
28 }
#define ASSERT(condition)
Definition: Assert.h:45
const IAxis & axis(size_t k_axis) const
Returns axis with given serial number.
Definition: Frame.h:46
size_t size() const
Returns total number of bins.
Definition: Frame.h:37
OwningVector< IAxis > m_axes
Definition: Frame.h:80
size_t m_size
Definition: Frame.h:83
size_t rank() const
Returns number of dimensions.
Definition: Frame.h:34
virtual size_t size() const =0
Returns the number of bins.

References ASSERT, axis(), m_size, rank(), size(), and IAxis::size().

Here is the call graph for this function:

◆ ~Frame()

Frame::~Frame ( )
virtualdefault

Member Function Documentation

◆ allIndices()

std::vector< int > Frame::allIndices ( size_t  i_flat) const

Returns vector of axes indices for given global index.

Parameters
i_flatThe global index of this data structure.
Returns
Vector of bin indices for all axes defined

Definition at line 48 of file Frame.cpp.

49 {
50  std::vector<int> result(rank());
51  for (size_t k = 0; k < rank(); ++k)
52  result[k] = projectedIndex(i_flat, k);
53  return result;
54 }
size_t projectedIndex(size_t i_flat, size_t k_axis) const
Returns axis bin index for given global index.
Definition: Frame.cpp:56

References projectedIndex(), and rank().

Referenced by DataUtils::Data::createRearrangedDataSet().

Here is the call graph for this function:

◆ axis()

const IAxis& Frame::axis ( size_t  k_axis) const
inline

Returns axis with given serial number.

Definition at line 46 of file Frame.h.

46 { return *m_axes.at(k_axis); }
T *const & at(int i) const
Definition: OwningVector.h:73

References OwningVector< T >::at(), and m_axes.

Referenced by Frame(), hasSameSizes(), and operator==().

Here is the call graph for this function:

◆ cloned_axes()

std::vector< IAxis * > Frame::cloned_axes ( ) const

Returns cloned axes.

Definition at line 32 of file Frame.cpp.

33 {
34  return m_axes.cloned_vector();
35 }
std::vector< T * > cloned_vector() const
Definition: OwningVector.h:81

References OwningVector< T >::cloned_vector(), and m_axes.

Referenced by IDetector::applyDetectorResolution(), and DiffUtil::relativeDifferenceField().

Here is the call graph for this function:

◆ hasSameSizes()

bool Frame::hasSameSizes ( const Frame o) const

Returns true if both Frames have same rank, and all axes have same sizes.

Definition at line 102 of file Frame.cpp.

103 {
104  if (rank() != o.rank())
105  return false;
106  for (size_t k = 0; k < rank(); ++k)
107  if (axis(k).size() != o.axis(k).size())
108  return false;
109  return true;
110 }

References axis(), rank(), and IAxis::size().

Referenced by Datafield::hasSameSizes().

Here is the call graph for this function:

◆ operator==()

bool Frame::operator== ( const Frame o) const

Returns true if both Frames have same rank, and all axes are equal.

Definition at line 92 of file Frame.cpp.

93 {
94  if (rank() != o.rank())
95  return false;
96  for (size_t k = 0; k < rank(); ++k)
97  if (axis(k) != o.axis(k))
98  return false;
99  return true;
100 }

References axis(), and rank().

Here is the call graph for this function:

◆ projectedCoord()

double Frame::projectedCoord ( size_t  i_flat,
size_t  k_axis 
) const

Returns the value of selected axis for given i_flat.

Parameters
i_flatThe global index of this data structure.
k_axisSerial number of selected axis.
Returns
corresponding bin center of selected axis

Definition at line 42 of file Frame.cpp.

43 {
44  auto axis_index = projectedIndex(i_flat, k_axis);
45  return (*m_axes[k_axis])[axis_index];
46 }

References m_axes, and projectedIndex().

Here is the call graph for this function:

◆ projectedIndex()

size_t Frame::projectedIndex ( size_t  i_flat,
size_t  k_axis 
) const

Returns axis bin index for given global index.

Parameters
i_flatThe global index of this data structure.
k_axisSerial number of selected axis.
Returns
Corresponding bin index for selected axis

Definition at line 56 of file Frame.cpp.

57 {
58  if (rank() == 1) {
59  return i_flat;
60  } else if (rank() == 2) {
61  if (k_axis == 0)
62  return (i_flat / m_axes[1]->size()) % m_axes[0]->size();
63  if (k_axis == 1)
64  return i_flat % m_axes[1]->size();
65  ASSERT(0);
66  }
67  ASSERT(0);
68  /* // generic code for rank>2 currently unused
69  size_t remainder(i_flat);
70  for (int k = rank() - 1; k >= 0; --k) {
71  size_t result = remainder % m_axes[k]->size();
72  if (k_axis == k)
73  return result;
74  remainder /= m_axes[k]->size();
75  }
76  */
77 }
size_t size() const
Definition: OwningVector.h:70

References ASSERT, m_axes, rank(), size(), and OwningVector< T >::size().

Referenced by allIndices(), ConvolutionDetectorResolution::apply2dConvolution(), and projectedCoord().

Here is the call graph for this function:

◆ projectedSize()

size_t Frame::projectedSize ( size_t  k_axis) const

Returns number of bins along axis.

Definition at line 37 of file Frame.cpp.

38 {
39  return m_axes[k_axis]->size();
40 }

References m_axes, and OwningVector< T >::size().

Here is the call graph for this function:

◆ rank()

size_t Frame::rank ( ) const
inline

Returns number of dimensions.

Definition at line 34 of file Frame.h.

34 { return m_axes.size(); }

References m_axes, and OwningVector< T >::size().

Referenced by Frame(), allIndices(), hasSameSizes(), operator==(), projectedIndex(), and toGlobalIndex().

Here is the call graph for this function:

◆ size()

size_t Frame::size ( ) const
inline

Returns total number of bins.

Definition at line 37 of file Frame.h.

37 { return m_size; }

References m_size.

Referenced by Frame(), Datafield::normalizedToMaximum(), projectedIndex(), Datafield::size(), and toGlobalIndex().

◆ toGlobalIndex()

size_t Frame::toGlobalIndex ( const std::vector< unsigned > &  axes_indices) const

Returns global index for specified indices of axes.

Parameters
axes_indicesVector of axes indices for all specified axes in this dataset
Returns
Corresponding global index

Definition at line 79 of file Frame.cpp.

80 {
81  ASSERT(axes_indices.size() == rank());
82  size_t result = 0;
83  size_t step_size = 1;
84  for (int k = rank() - 1; k >= 0; --k) {
85  ASSERT(axes_indices[k] < m_axes[k]->size());
86  result += axes_indices[k] * step_size;
87  step_size *= m_axes[k]->size();
88  }
89  return result;
90 }

References ASSERT, m_axes, rank(), size(), and OwningVector< T >::size().

Referenced by IO::readNicosData().

Here is the call graph for this function:

◆ xAxis()

const IAxis& Frame::xAxis ( ) const
inline

Definition at line 47 of file Frame.h.

47 { return *m_axes.at(0); }

References OwningVector< T >::at(), and m_axes.

Referenced by FramUtil::coordinatesFromBinf(), and FramUtil::coordinatesToBinf().

Here is the call graph for this function:

◆ yAxis()

const IAxis& Frame::yAxis ( ) const
inline

Definition at line 48 of file Frame.h.

48 { return *m_axes.at(1); }

References OwningVector< T >::at(), and m_axes.

Referenced by FramUtil::coordinatesFromBinf(), and FramUtil::coordinatesToBinf().

Here is the call graph for this function:

Member Data Documentation

◆ m_axes

OwningVector<IAxis> Frame::m_axes
protected

◆ m_size

size_t Frame::m_size
private

Definition at line 83 of file Frame.h.

Referenced by Frame(), and size().


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