1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Detector/DetectorItem.cpp
//! @brief Implements classes DetectorItems.
//!
//! @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 "GUI/Model/Detector/DetectorItem.h"
#include "Base/Axis/Scale.h"
#include "Base/Const/Units.h"
#include "Base/Util/Assert.h"
#include "Device/Detector/SphericalDetector.h"
#include "Device/Mask/IShape2D.h"
#include "Device/Resolution/ResolutionFunction2DGaussian.h"
#include "GUI/Model/Mask/MasksSet.h"
#include "GUI/Model/Util/Backup.h"
namespace {
namespace Tag {
const QString ExpandResolutionFuncGroupbox("ExpandResolutionFuncGroupbox");
const QString AlphaAxis("AlphaAxis");
const QString PhiAxis("PhiAxis");
const QString ResolutionFunction("ResolutionFunction");
const QString MaskContainer("MaskContainer");
} // namespace Tag
} // namespace
DetectorItem::DetectorItem()
: m_masks(std::make_unique<MasksSet>())
{
m_phi_axis.setProperties("phi", "deg", -1, 1, RealLimits::limited(-90, 90));
m_alpha_axis.setProperties("alpha", "deg", 0, 2, RealLimits::limited(-90, 90));
m_resolution_function.simpleInit("Resolution function", "Detector resolution function",
ResolutionFunctionCatalog::Type::None);
}
DetectorItem::~DetectorItem() = default;
std::unique_ptr<IDetector> DetectorItem::createDetectorFromAxes() const
{
return std::make_unique<SphericalDetector>(
m_phi_axis.nbins(), Units::deg2rad(m_phi_axis.min().dVal()),
Units::deg2rad(m_phi_axis.max().dVal()), m_alpha_axis.nbins(),
Units::deg2rad(m_alpha_axis.min().dVal()), Units::deg2rad(m_alpha_axis.max().dVal()));
}
Frame DetectorItem::createFrame() const
{
return {createDetectorFromAxes()->frame()};
}
std::unique_ptr<IDetector> DetectorItem::createDetector() const
{
auto result = createDetectorFromAxes();
for (const MaskItem* t : *m_masks) {
if (t->isVisible()) {
if (const auto* ii = dynamic_cast<const RegionOfInterestItem*>(t)) {
result->setRegionOfInterest(ii->xLow().dVal(), ii->yLow().dVal(), ii->xUp().dVal(),
ii->yUp().dVal());
} else {
std::unique_ptr<IShape2D> shape(t->createShape());
result->addMask(*shape, t->maskValue());
}
}
}
if (auto resFunc = createResolutionFunction())
result->setResolutionFunction(*resFunc);
return result;
}
void DetectorItem::setMasks(const MasksSet* source)
{
GUI::Util::copyContents(source, m_masks.get());
}
std::unique_ptr<IResolutionFunction2D> DetectorItem::createResolutionFunction() const
{
return m_resolution_function.certainItem()->createResolutionFunction();
}
void DetectorItem::writeTo(QXmlStreamWriter* w) const
{
XML::writeTaggedElement(w, Tag::PhiAxis, m_phi_axis);
XML::writeTaggedElement(w, Tag::AlphaAxis, m_alpha_axis);
XML::writeTaggedElement(w, Tag::ResolutionFunction, m_resolution_function);
XML::writeTaggedValue(w, Tag::ExpandResolutionFuncGroupbox, expandResolutionFunc);
XML::writeTaggedElement(w, Tag::MaskContainer, *m_masks);
}
void DetectorItem::readFrom(QXmlStreamReader* r)
{
while (r->readNextStartElement()) {
QString tag = r->name().toString();
if (tag == Tag::PhiAxis)
XML::readTaggedElement(r, tag, m_phi_axis);
else if (tag == Tag::AlphaAxis)
XML::readTaggedElement(r, tag, m_alpha_axis);
else if (tag == Tag::ResolutionFunction)
XML::readTaggedElement(r, tag, m_resolution_function);
else if (tag == Tag::ExpandResolutionFuncGroupbox)
expandResolutionFunc = XML::readTaggedBool(r, tag);
else if (tag == Tag::MaskContainer)
XML::readTaggedElement(r, tag, *m_masks);
else
r->skipCurrentElement();
}
}
|