Newer
Older
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file Base/Axis/Frame.cpp
//! @brief Implements class Frame.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "Base/Axis/Frame.h"
#include "Base/Util/Assert.h"

Wuttke, Joachim
committed
: m_axes(std::move(axes))
, m_size(FrameUtil::product_size(m_axes.reference()))
Frame::Frame(const Scale*&& ax0)
: m_axes(std::vector<const Scale*>{std::move(ax0)})
, m_size(FrameUtil::product_size(m_axes.reference()))
{
}
Frame::Frame(const Scale*&& ax0, const Scale*&& ax1)
: m_axes(std::vector<const Scale*>{std::move(ax0), std::move(ax1)})
, m_size(FrameUtil::product_size(m_axes.reference()))
{
}
Frame* Frame::clone() const
{
return new Frame(m_axes.cloned_vector());
}
Frame::~Frame() = default;
size_t Frame::rank() const
{
return m_axes.size();
}
size_t Frame::size() const
{
return m_size;
}
double Frame::projectedCoord(size_t i_flat, size_t k_axis) const
auto axis_index = projectedIndex(i_flat, k_axis);
std::vector<int> Frame::allIndices(size_t i_flat) const
for (size_t k = 0; k < rank(); ++k)
result[k] = projectedIndex(i_flat, k);
size_t Frame::projectedIndex(size_t i_flat, size_t k_axis) const

Wuttke, Joachim
committed
return i_flat;

Wuttke, Joachim
committed
return (i_flat / m_axes[1]->size()) % m_axes[0]->size();

Wuttke, Joachim
committed
}
}
size_t Frame::toGlobalIndex(const std::vector<unsigned>& axes_indices) const
{
ASSERT(axes_indices.size() == rank());
size_t result = 0;
size_t step_size = 1;
for (int k = rank() - 1; k >= 0; --k) {
ASSERT(axes_indices[k] < m_axes[k]->size());
result += axes_indices[k] * step_size;
step_size *= m_axes[k]->size();
}
return result;
}
bool Frame::operator==(const Frame& o) const
{
if (axis(k) != o.axis(k))
return false;
return true;
}
std::vector<const Scale*> Frame::clonedAxes() const
{
return m_axes.cloned_vector();
}
bool Frame::hasSameSizes(const Frame& o) const
{
if (axis(k).size() != o.axis(k).size())
return false;
return true;
}
Frame* Frame::plottableFrame() const
{
std::vector<const Scale*> outaxes;
for (const Scale* s : m_axes)
outaxes.emplace_back(new Scale(s->plottableScale()));
return new Frame(std::move(outaxes));
}