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"

Wuttke, Joachim
committed
, m_size(FrameUtil::product_size(m_axes.reference()))
Frame::Frame(const Scale* ax0)
: Frame(std::vector<const Scale*>{ax0})
Frame::Frame(const Scale* ax0, const Scale* ax1)
: Frame(std::vector<const Scale*>{ax0, ax1})
Frame::Frame(const Frame&) = default;
Frame::~Frame() = default;
void Frame::setAxes(CloneableVector<const Scale> axes)
{
std::swap(m_axes, axes);
m_size = FrameUtil::product_size(m_axes.reference());
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);

Wuttke, Joachim
committed
size_t Frame::projectedIndex(size_t i, size_t k_axis) const

Wuttke, Joachim
committed
return i;

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

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

Wuttke, Joachim
committed
}
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;
}
{
std::vector<const Scale*> outaxes;
for (size_t k = 0; k < rank(); ++k) {
Scale* s = new Scale(axis(k).plottableScale());
outaxes.emplace_back(s);
}
return new Frame(std::move(outaxes));
}
Frame* Frame::flat() const
{
std::vector<const Scale*> outaxes;
for (const Scale* s : m_axes)
if (s->size() > 1)
outaxes.emplace_back(s->clone());
return new Frame(std::move(outaxes));
}
void Frame::setScale(size_t k_axis, Scale* scale)
{
m_axes.replace_at(k_axis, scale);
m_size = FrameUtil::product_size(m_axes.reference());
}