BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SaveProjectionsAssistant Class Reference

Description

Assistant class which save all projections of IndensityDataItem into ASCII file.

Definition at line 29 of file SaveProjectionsAssistant.h.

Collaboration diagram for SaveProjectionsAssistant:
[legend]

Classes

struct  Projection
 
struct  ProjectionsData
 

Public Member Functions

 SaveProjectionsAssistant ()
 
 ~SaveProjectionsAssistant ()
 
void saveProjections (QWidget *parent, IntensityDataItem *intensityItem)
 Calls file open dialog and writes projection data as ASCII. More...
 

Private Member Functions

QString projectionFileHeader (ProjectionsData &projectionsData)
 Returns projections header. For projections along x it will be "# x y=6.0194 y=33.5922 y=61.9417". More...
 
QVector< SessionItem * > projectionItems (const QString &projectionsType, IntensityDataItem *intensityItem)
 Returns vector of ProjectionItems sorted according to axis value. More...
 
ProjectionsData projectionsData (const QString &projectionsType, IntensityDataItem *intensityItem)
 Returns projections data for all projections of given type (horizontal, vertical). More...
 
QString projectionsToString (const QString &projectionsType, IntensityDataItem *intensityItem)
 Generates multi-line string with projections data of given type (horizontal, vertical). More...
 

Private Attributes

std::unique_ptr< Datafield > m_field
 

Constructor & Destructor Documentation

◆ SaveProjectionsAssistant()

SaveProjectionsAssistant::SaveProjectionsAssistant ( )
default

◆ ~SaveProjectionsAssistant()

SaveProjectionsAssistant::~SaveProjectionsAssistant ( )
default

Member Function Documentation

◆ projectionFileHeader()

QString SaveProjectionsAssistant::projectionFileHeader ( ProjectionsData projectionsData)
private

Returns projections header. For projections along x it will be "# x y=6.0194 y=33.5922 y=61.9417".

Definition at line 179 of file SaveProjectionsAssistant.cpp.

180 {
181  QString xcol, ycol;
182 
183  projectionsData.is_horizontal ? xcol = "# x" : xcol = "# y";
184  projectionsData.is_horizontal ? ycol = " y=" : ycol = " x=";
185 
186  QString result;
187  result.append(QString("%1").arg(xcol, -bin_centers_colwidth));
188 
189  for (auto& data : projectionsData.projections)
190  result.append(QString("%1%2").arg(ycol).arg(data.axis_value,
191  -(bin_values_colwidth - ycol.size()), 'f', 4));
192  result.append("\n");
193 
194  return result;
195 }
ProjectionsData projectionsData(const QString &projectionsType, IntensityDataItem *intensityItem)
Returns projections data for all projections of given type (horizontal, vertical).

References SaveProjectionsAssistant::ProjectionsData::is_horizontal, SaveProjectionsAssistant::ProjectionsData::projections, and projectionsData().

Referenced by projectionsToString().

Here is the call graph for this function:

◆ projectionItems()

QVector< SessionItem * > SaveProjectionsAssistant::projectionItems ( const QString &  projectionsType,
IntensityDataItem intensityItem 
)
private

Returns vector of ProjectionItems sorted according to axis value.

Definition at line 167 of file SaveProjectionsAssistant.cpp.

169 {
170  auto result = intensityItem->projectionContainerItem()->childrenOfType(projectionsType);
171  std::sort(result.begin(), result.end(),
172  projectionsType == HorizontalLineItem::M_TYPE ? horiz_less_posy : vert_less_posx);
173  return result;
174 }
static constexpr auto M_TYPE
Definition: MaskItems.h:147
ProjectionContainerItem * projectionContainerItem()
QVector< SessionItem * > childrenOfType(const QString &model_type) const
Returns a vector of all children of the given type.

References SessionItem::childrenOfType(), HorizontalLineItem::M_TYPE, and IntensityDataItem::projectionContainerItem().

Referenced by projectionsData().

Here is the call graph for this function:

◆ projectionsData()

SaveProjectionsAssistant::ProjectionsData SaveProjectionsAssistant::projectionsData ( const QString &  projectionsType,
IntensityDataItem intensityItem 
)
private

Returns projections data for all projections of given type (horizontal, vertical).

Definition at line 130 of file SaveProjectionsAssistant.cpp.

132 {
133  ProjectionsData result;
134  result.is_horizontal = (projectionsType != VerticalLineItem::M_TYPE);
135 
136  for (auto* item : projectionItems(projectionsType, intensityItem)) {
137  std::unique_ptr<Datafield> field;
139 
140  if (item->modelType() == HorizontalLineItem::M_TYPE) {
141  data.axis_value = polymorphic_downcast<HorizontalLineItem*>(item)->posY();
142  field.reset(m_field->xProjection(data.axis_value));
143  } else {
144  data.axis_value = polymorphic_downcast<VerticalLineItem*>(item)->posX();
145  field.reset(m_field->yProjection(data.axis_value));
146  }
147 
148 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
149  auto values = field->flatVector();
150  auto centers = field->axis(0).binCenters();
151  data.bin_values = QVector<double>(values.begin(), values.end());
152  if (result.bin_centers.isEmpty())
153  result.bin_centers = QVector<double>(centers.begin(), centers.end());
154 #else
155  data.bin_values = QVector<double>::fromStdVector(hist->binValues());
156  if (result.bin_centers.isEmpty())
157  result.bin_centers = QVector<double>::fromStdVector(hist->binCenters());
158 #endif
159 
160  result.projections.push_back(data);
161  }
162  return result;
163 }
std::unique_ptr< Datafield > m_field
QVector< SessionItem * > projectionItems(const QString &projectionsType, IntensityDataItem *intensityItem)
Returns vector of ProjectionItems sorted according to axis value.
static constexpr auto M_TYPE
Definition: MaskItems.h:131
double axis_value
value on axis where projection has been made

References SaveProjectionsAssistant::Projection::axis_value, SaveProjectionsAssistant::ProjectionsData::bin_centers, SaveProjectionsAssistant::Projection::bin_values, SaveProjectionsAssistant::ProjectionsData::is_horizontal, m_field, VerticalLineItem::M_TYPE, HorizontalLineItem::M_TYPE, projectionItems(), and SaveProjectionsAssistant::ProjectionsData::projections.

Referenced by projectionFileHeader(), and projectionsToString().

Here is the call graph for this function:

◆ projectionsToString()

QString SaveProjectionsAssistant::projectionsToString ( const QString &  projectionsType,
IntensityDataItem intensityItem 
)
private

Generates multi-line string with projections data of given type (horizontal, vertical).

Definition at line 103 of file SaveProjectionsAssistant.cpp.

105 {
106  QString result;
107  QTextStream out(&result);
108 
109  auto projData = projectionsData(projectionsType, intensityItem);
110 
111  if (projData.projections.isEmpty())
112  return result;
113 
114  out << projectionFileHeader(projData);
115 
116  auto bin_centers = projData.bin_centers;
117 
118  for (int i_point = 0; i_point < bin_centers.size(); ++i_point) {
119  out << to_double_str(bin_centers[i_point]) << " ";
120  for (auto& data : projData.projections)
121  out << to_scientific_str(data.bin_values[i_point]);
122  out << "\n";
123  }
124  return result;
125 }
QString projectionFileHeader(ProjectionsData &projectionsData)
Returns projections header. For projections along x it will be "# x y=6.0194 y=33....

References projectionFileHeader(), and projectionsData().

Referenced by saveProjections().

Here is the call graph for this function:

◆ saveProjections()

void SaveProjectionsAssistant::saveProjections ( QWidget *  parent,
IntensityDataItem intensityItem 
)

Calls file open dialog and writes projection data as ASCII.

Definition at line 68 of file SaveProjectionsAssistant.cpp.

69 {
70  ASSERT(intensityItem);
71 
72  QString defaultName = gSessionData->projectDocument.value()->userExportDir() + "/untitled.txt";
73  QString fileName = QFileDialog::getSaveFileName(
74  parent, "Save projections data", defaultName, "", nullptr,
75  appSettings->useNativeFileDialog() ? QFileDialog::Options()
76  : QFileDialog::DontUseNativeDialog);
77 
78  if (fileName.isEmpty())
79  return;
80 
81  QFile file(fileName);
82  if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
83  throw Error("TestGUI::Project::Utils::createTestFile() -> Error. "
84  "Can't create file");
85 
86  m_field.reset(intensityItem->getDatafield());
87 
88  QTextStream out(&file);
89 
90  out << "# Projections along x-axis (horizontal projections) \n";
91  out << projectionsToString(HorizontalLineItem::M_TYPE, intensityItem);
92  out << "\n";
93 
94  out << "# Projections along y-axis (vertical projections) \n";
95  out << projectionsToString(VerticalLineItem::M_TYPE, intensityItem);
96  out << "\n";
97 
98  file.close();
99 }
ApplicationSettings * appSettings
global pointer to the instance
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
bool useNativeFileDialog() const
Datafield * getDatafield()
Definition: DataItem.h:41
QString projectionsToString(const QString &projectionsType, IntensityDataItem *intensityItem)
Generates multi-line string with projections data of given type (horizontal, vertical).
std::optional< ProjectDocument * > projectDocument
Definition: SessionData.h:27

References appSettings, Error, DataItem::getDatafield(), gSessionData, m_field, VerticalLineItem::M_TYPE, HorizontalLineItem::M_TYPE, SessionData::projectDocument, projectionsToString(), and ApplicationSettings::useNativeFileDialog().

Referenced by ProjectionsEditorActions::onSaveAction().

Here is the call graph for this function:

Member Data Documentation

◆ m_field

std::unique_ptr<Datafield> SaveProjectionsAssistant::m_field
private

Definition at line 50 of file SaveProjectionsAssistant.h.

Referenced by projectionsData(), and saveProjections().


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