diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e41de2..72580fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -205,6 +206,7 @@ IF (MSVC) ws2_32.lib rpcrt4.lib iphlpapi.lib + ${TIFF_LIBRARIES} ${Qt5Core_LIBRARIES} ${Qt5Charts_LIBRARIES} netCDF::netcdf diff --git a/src/mvc/ExportMapsDialog.cpp b/src/mvc/ExportMapsDialog.cpp index bfc1b63..145a9d8 100644 --- a/src/mvc/ExportMapsDialog.cpp +++ b/src/mvc/ExportMapsDialog.cpp @@ -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); diff --git a/src/mvc/FitSpectraWidget.cpp b/src/mvc/FitSpectraWidget.cpp index a4dce1a..f2faecf 100644 --- a/src/mvc/FitSpectraWidget.cpp +++ b/src/mvc/FitSpectraWidget.cpp @@ -391,7 +391,7 @@ void FitSpectraWidget::replot_integrated_spectra(bool snipback) _spectra_widget->append_spectra(DEF_STR_BACK_SPECTRA, &_spectra_background, (data_struct::Spectra*) & _ev); } - _spectra_widget->setXLabel("Energy (kEv)"); + _spectra_widget->setXLabel("Energy (keV)"); /* _showFitIntSpec = Preferences::inst()->getValue(STR_PFR_SHOW_FIT_INT_SPEC).toBool(); diff --git a/src/mvc/MapsElementsWidget.cpp b/src/mvc/MapsElementsWidget.cpp index ab90fc3..3aa0a45 100644 --- a/src/mvc/MapsElementsWidget.cpp +++ b/src/mvc/MapsElementsWidget.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "io/file/aps/aps_fit_params_import.h" #include #include @@ -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()) { @@ -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); + } } } @@ -1487,9 +1523,40 @@ void MapsElementsWidget::on_export_images() std::vector 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++; diff --git a/src/mvc/MapsWorkspaceFilesWidget.cpp b/src/mvc/MapsWorkspaceFilesWidget.cpp index 7815f96..b82b199 100644 --- a/src/mvc/MapsWorkspaceFilesWidget.cpp +++ b/src/mvc/MapsWorkspaceFilesWidget.cpp @@ -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 diff --git a/src/mvc/MapsWorkspaceModel.cpp b/src/mvc/MapsWorkspaceModel.cpp index ea97d01..c429e59 100644 --- a/src/mvc/MapsWorkspaceModel.cpp +++ b/src/mvc/MapsWorkspaceModel.cpp @@ -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"); diff --git a/src/mvc/PerPixelFitWidget.cpp b/src/mvc/PerPixelFitWidget.cpp index e0e2635..5e398e9 100644 --- a/src/mvc/PerPixelFitWidget.cpp +++ b/src/mvc/PerPixelFitWidget.cpp @@ -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(); diff --git a/src/mvc/SpectraWidget.cpp b/src/mvc/SpectraWidget.cpp index b1f2332..770151d 100644 --- a/src/mvc/SpectraWidget.cpp +++ b/src/mvc/SpectraWidget.cpp @@ -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:"));