Skip to content

Commit

Permalink
Merge pull request #52 from aglowacki/master
Browse files Browse the repository at this point in the history
Added mca files as raw for workspace
  • Loading branch information
Arthur Glowacki authored Sep 14, 2022
2 parents 3061611 + 19bec2d commit e5c642c
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ find_package(hdf5 CONFIG REQUIRED)
find_package(netCDF CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(ZeroMQ CONFIG REQUIRED)
find_package(TIFF REQUIRED)
find_package(XRF_Maps CONFIG REQUIRED COMPONENTS libxrf_io libxrf_fit)

if (libxrf_fit_FOUND)
Expand Down Expand Up @@ -205,6 +206,7 @@ IF (MSVC)
ws2_32.lib
rpcrt4.lib
iphlpapi.lib
${TIFF_LIBRARIES}
${Qt5Core_LIBRARIES}
${Qt5Charts_LIBRARIES}
netCDF::netcdf
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/ExportMapsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ExportMapsDialog::createLayout()
_save_screen->setChecked(false);

v_proc_layout->addItem(h_layout);
//v_proc_layout->addWidget(_export_tiff);
v_proc_layout->addWidget(_export_tiff);
v_proc_layout->addWidget(_export_png);
v_proc_layout->addWidget(_export_ascii);
v_proc_layout->addWidget(_export_all);
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/FitSpectraWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void FitSpectraWidget::replot_integrated_spectra(bool snipback)
_spectra_widget->append_spectra(DEF_STR_BACK_SPECTRA, &_spectra_background, (data_struct::Spectra<double>*) & _ev);

}
_spectra_widget->setXLabel("Energy (kEv)");
_spectra_widget->setXLabel("Energy (keV)");

/*
_showFitIntSpec = Preferences::inst()->getValue(STR_PFR_SHOW_FIT_INT_SPEC).toBool();
Expand Down
89 changes: 78 additions & 11 deletions src/mvc/MapsElementsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QSplitter>
#include <QFileDialog>
#include <QMessageBox>
#include <tiffio.h>
#include "io/file/aps/aps_fit_params_import.h"
#include <gstar/CountsLookupTransformer.h>
#include <limits>
Expand Down Expand Up @@ -1445,11 +1446,7 @@ void MapsElementsWidget::on_export_images()
QDir export_model_dir = _export_maps_dialog->get_dir();
int cur = 0;

if (_export_maps_dialog->get_save_tiff())
{

}
if (_export_maps_dialog->get_save_png())
if (_export_maps_dialog->get_save_png() || _export_maps_dialog->get_save_tiff())
{
if (_export_maps_dialog->get_export_all())
{
Expand All @@ -1463,11 +1460,50 @@ void MapsElementsWidget::on_export_images()

for (auto& e_itr : element_counts)
{
std::string save_file_name = a_itr + "-" + e_itr.first + ".png";
QPixmap pixmap = generate_pixmap(a_itr, e_itr.first, false, -1);
if (false == pixmap.save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())), "PNG"))
if (_export_maps_dialog->get_save_png())
{
logE << "Could not save PNG for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str()) + ".png").toStdString() << "\n";
std::string save_file_name = a_itr + "-" + e_itr.first + ".png";
QPixmap pixmap = generate_pixmap(a_itr, e_itr.first, false, -1);
if (false == pixmap.save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())), "PNG"))
{
logE << "Could not save PNG for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())).toStdString() << "\n";
}
}
if (_export_maps_dialog->get_save_tiff())
{
std::string save_file_name = a_itr + "-" + e_itr.first + "_8bit.tif";
QPixmap pixmap = generate_pixmap(a_itr, e_itr.first, false, -1);
if (false == pixmap.save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())), "TIFF"))
{
logE << "Could not save 8 bit TIFF for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())).toStdString() << "\n";
}

// save float 32bit
std::string save_file_name_fp = a_itr + "-" + e_itr.first + "_fp.tif";
TIFF* tif = nullptr;
QString save_path = QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name_fp.c_str()));
if ((tif = TIFFOpen(save_path.toStdString().c_str(), "w")) == NULL)
{
logE << "Could not open " << save_path.toStdString() << " for writing\n";
continue;
}

TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, e_itr.second.cols());
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, e_itr.second.rows());
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, e_itr.second.rows());
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
//TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
//TIFFSetField(tif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);

// Write the information to the file
// need to normaize the data by IC also
TIFFWriteEncodedStrip(tif, 0, e_itr.second.data(), 4 * e_itr.second.cols() * e_itr.second.rows());
TIFFClose(tif);

}
}
}
Expand All @@ -1487,9 +1523,40 @@ void MapsElementsWidget::on_export_images()
std::vector<std::string> to_delete;
for (auto& itr : job_queue)
{
if (false == itr.second.get().save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".png"), "PNG"))
if (_export_maps_dialog->get_save_png())
{
logE << "Could not save PNG for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".png").toStdString() << "\n";
if (false == itr.second.get().save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".png"), "PNG"))
{
logE << "Could not save PNG for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".png").toStdString() << "\n";
}
}
if (_export_maps_dialog->get_save_tiff())
{
//save 8 bit tiff
if (false == itr.second.get().save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".tif"), "TIFF"))
{
logE << "Could not save 8 bit TIFF for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".tif").toStdString() << "\n";
}

// save float 32bit
/*
std::string save_file_name_fp = a_itr + "-" + e_itr.first + "_fp.tif";
QImage image(e_itr.second.cols(), e_itr.second.rows(), QImage::Format_ARGB32);
for (int y = 0; y < e_itr.second.rows(); y++)
{
for (int x = 0; x < e_itr.second.cols(); x++)
{
image.setPixel(x, y, (uint)e_itr.second(y, x));
}
}
pixmap = QPixmap::fromImage(image);
if (false == pixmap.save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name_fp.c_str())), "TIFF"))
{
logE << "Could not save 32 bit float TIFF for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString(save_file_name_fp.c_str())).toStdString() << "\n";
}
*/
}
to_delete.push_back(itr.first);
cur++;
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/MapsWorkspaceFilesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void MapsWorkspaceFilesWidget::onOpenModel(const QStringList& names_list, MODEL_

QApplication::setOverrideCursor(Qt::WaitCursor);

if (name.endsWith(".mda"))
if (name.endsWith(".mda") || name.contains(".mca"))
{
QCoreApplication::processEvents();
// loading through background thread on windows seems to lock up on fopen
Expand Down
15 changes: 7 additions & 8 deletions src/mvc/MapsWorkspaceModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,16 @@ MapsWorkspaceModel::MapsWorkspaceModel() : QObject()
_dir = nullptr;

_all_h5_suffex.append("h5");
_all_h5_suffex.append("h50");
_all_h5_suffex.append("h51");
_all_h5_suffex.append("h52");
_all_h5_suffex.append("h53");
_all_h5_suffex.append("h54");
_all_h5_suffex.append("h55");
_all_h5_suffex.append("h56");
_all_h5_suffex.append("h57");
_all_h5_suffex.append("hdf5");

_mda_suffex.append("mda");
_mda_suffex.append("mca");
for (int i = 0; i < 20; i++)
{
_all_h5_suffex.append(QString("h5") + QString::number(i));
_mda_suffex.append(QString("mca") + QString::number(i));
}

_raw_suffex.append("h5");
_raw_suffex.append("hdf5");
_raw_suffex.append("emd");
Expand Down
2 changes: 1 addition & 1 deletion src/mvc/PerPixelFitWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void PerPixelFitWidget::runProcessing()
if (_perform_quantification->isChecked())
{
analysis_job.quantification_standard_filename = "maps_standardinfo.txt";
perform_quantification(&analysis_job);
perform_quantification(&analysis_job, true);
}
process_dataset_files(&analysis_job, &cb_func);
//QCoreApplication::processEvents();
Expand Down
4 changes: 2 additions & 2 deletions src/mvc/SpectraWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ void SpectraWidget::createLayout()
QHBoxLayout* options_layout = new QHBoxLayout();
options_layout->addWidget(new QLabel("Display Energy Min:"));
options_layout->addWidget(_display_eneergy_min);
options_layout->addWidget(new QLabel("KeV , "));
options_layout->addWidget(new QLabel("keV , "));

options_layout->addWidget(new QLabel("Display Energy Max:"));
options_layout->addWidget(_display_eneergy_max);
options_layout->addWidget(new QLabel("KeV"));
options_layout->addWidget(new QLabel("keV"));

/*
options_layout->addWidget(new QLabel(" | Display Height Min:"));
Expand Down

0 comments on commit e5c642c

Please sign in to comment.