From add8a4edf406d2e3d400427520e7ea40ed8d3adc Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Fri, 17 Mar 2023 10:30:05 -0500 Subject: [PATCH 1/4] Added export png for colocal widget --- src/mvc/CoLocalizationWidget.cpp | 964 +------------------------------ src/mvc/CoLocalizationWidget.h | 2 + src/mvc/ScatterPlotWidget.cpp | 17 +- 3 files changed, 39 insertions(+), 944 deletions(-) diff --git a/src/mvc/CoLocalizationWidget.cpp b/src/mvc/CoLocalizationWidget.cpp index 1ec2fc1..9866079 100644 --- a/src/mvc/CoLocalizationWidget.cpp +++ b/src/mvc/CoLocalizationWidget.cpp @@ -28,13 +28,6 @@ CoLocalizationWidget::CoLocalizationWidget(QWidget* parent) : gstar::AbstractIma CoLocalizationWidget::~CoLocalizationWidget() { -/* //this is done elsewhere . should refactor it to be smart pointer - if(_model != nullptr) - { - delete _model; - } - _model = nullptr; -*/ } @@ -57,6 +50,9 @@ void CoLocalizationWidget::_createLayout() _cb_blue_element = new QComboBox(); connect(_cb_blue_element, SIGNAL(currentIndexChanged(QString)), this, SLOT(onColorSelected(QString))); + _btn_export_as_image = new QPushButton("Export as PNG"); + connect(_btn_export_as_image, &QPushButton::released, this, &CoLocalizationWidget::onExportPng); + _ck_quad_view = new QCheckBox("Quad View"); // TODO: save and load from pref check value connect(_ck_quad_view, &QCheckBox::stateChanged, this, &CoLocalizationWidget::onQuadViewChanged); @@ -73,6 +69,8 @@ void CoLocalizationWidget::_createLayout() hb->addWidget(_cb_blue_element); hb->addWidget(_ck_quad_view); + + hb->addWidget(_btn_export_as_image); hb->addStretch(); layout->addItem(hb); @@ -86,69 +84,10 @@ void CoLocalizationWidget::_createLayout() //createActions(); - /* - int rows = Preferences::inst()->getValue(STR_GRID_ROWS).toInt(); - int cols = Preferences::inst()->getValue(STR_GRID_COLS).toInt(); - if (rows < 1) - rows = 1; - if (cols < 1) - cols = 1; - onNewGridLayout(rows, cols); - */ - - /* - QString colormap = Preferences::inst()->getValue(STR_COLORMAP).toString(); - if (colormap.length() > 0) - { - _cb_colormap->setCurrentText(colormap); - } - //onColormapSelect(colormap); - */ setLayout(layout); } -//--------------------------------------------------------------------------- -/* -//--------------------------------------------------------------------------- - -void CoLocalizationWidget::on_global_contrast_changed(int state) -{ - if (state == Qt::CheckState::Checked) - { - _contrast_widget->setEnabled(true); - _imageViewWidget->setGlobalContrast(false); - } - else - { - _contrast_widget->setEnabled(false); - _imageViewWidget->setGlobalContrast(true); - } - - redrawCounts(); -} - -//--------------------------------------------------------------------------- - -void CoLocalizationWidget::on_log_color_changed(int state) -{ - Preferences::inst()->setValue(STR_LOG_SCALE_COLOR, _chk_log_color->isChecked()); - Preferences::inst()->setValue(STR_DISPLAY_COLOR_LEDGEND, _chk_disp_color_ledgend->isChecked()); - redrawCounts(); -} - -//--------------------------------------------------------------------------- - -void CoLocalizationWidget::on_min_max_contrast_changed() -{ - - _min_contrast_perc = _contrast_widget->getUserMin() / 100.0; - _max_contrast_perc = _contrast_widget->getUserMax() / 100.0; - redrawCounts(); - -} -*/ - //--------------------------------------------------------------------------- void CoLocalizationWidget::onQuadViewChanged(int value) @@ -398,282 +337,6 @@ void CoLocalizationWidget::setModel(MapsH5Model* model) } } -//--------------------------------------------------------------------------- -/* -void CoLocalizationWidget::on_export_csv_and_png(QPixmap png, ArrayDr* ev, ArrayDr* int_spec, ArrayDr* back_spec , ArrayDr* fit_spec, unordered_map* labeled_spectras) -{ - QDir save_path = QDir(_dataset_directory->text()); - QFileInfo file_info = QFileInfo(_dataset_directory->text()); - QString file_name = file_info.fileName(); - QString save_png; - QString save_csv; - save_path.cdUp(); - QString mesg = ""; - bool found = false; - if (save_path.cd("output")) - { - found = true; - } - else - { - save_path.cdUp(); - if (save_path.cd("output")) - { - found = true; - } - } - - if (false == found) - { - QString dirName = QFileDialog::getExistingDirectory(this, "Export directory", "."); - - // Dialog returns a nullptr string if user press cancel. - if (dirName.isNull() || dirName.isEmpty()) return; - - save_path = QDir(dirName); - - } - - save_png = QDir::cleanPath(save_path.absolutePath() + QDir::separator() + file_name + "_int_spec.png"); - save_csv = QDir::cleanPath(save_path.absolutePath() + QDir::separator() + file_name + "_int_spec.csv"); - - - if (false == png.save(save_png, "PNG")) - { - mesg.append("Failed to save PNG of spectra: "); - mesg.append(save_png); - mesg.append(" "); - } - else - { - mesg.append("Saved PNG of spectra: "); - mesg.append(save_png); - mesg.append(" "); - } - - - //bool save_fit_and_int_spectra(const std::string fullpath, const ArrayDr* energy, const ArrayDr* spectra, const ArrayDr* spectra_model, const ArrayDr* background, const unordered_map* fit_int_def_spec) - if (false == io::file::csv::save_fit_and_int_spectra_labeled(save_csv.toStdString(), ev, int_spec, fit_spec, back_spec, labeled_spectras)) - { - mesg.append("Failed to save CSV of spectra: "); - mesg.append(save_csv); - } - else - { - mesg.append("Saved CSV of spectra: "); - mesg.append(save_csv); - } - - - - QMessageBox::information(nullptr, "Export to CSV", mesg); -} - -//--------------------------------------------------------------------------- - -void CoLocalizationWidget::model_updated() -{ - if(_model == nullptr) - { - return; - } - - disconnect(_cb_analysis, SIGNAL(currentIndexChanged(QString)), this, SLOT(onAnalysisSelect(QString))); - - _dataset_directory->setText(_model->getFilePath()); - _dataset_name->setText(_model->getDatasetName()); - - std::string current_a; - - QString current_analysis = _cb_analysis->currentText(); - - QString save_normal_val = _cb_normalize->currentText(); - - _cb_normalize->clear(); - _cb_normalize->addItem("1"); - - std::map>* scalers = _model->getScalers(); - - if (scalers->count(STR_DS_IC) > 0) - { - _cb_normalize->addItem(QString(STR_DS_IC.c_str())); - } - if (scalers->count(STR_US_IC) > 0) - { - _cb_normalize->addItem(QString(STR_US_IC.c_str())); - } - if (scalers->count(STR_SR_CURRENT) > 0) - { - _cb_normalize->addItem(QString(STR_SR_CURRENT.c_str())); - } - - - _cb_normalize->setMinimumWidth(_cb_normalize->minimumSizeHint().width()); - - _cb_analysis->clear(); - std::vector analysis_types = _model->getAnalyzedTypes(); - - bool found_analysis = false; - for(auto& itr: analysis_types) - { - QString newVal = QString(itr.c_str()); - _cb_analysis->addItem(newVal); - current_a = itr; - if(current_analysis == newVal) - { - found_analysis = true; - } - } - - //create save ordered vector by element Z number with K , L, M lines - std::vector element_lines; - for (std::string el_name : data_struct::Element_Symbols) - { - element_lines.push_back(el_name); - } - for (std::string el_name : data_struct::Element_Symbols) - { - element_lines.push_back(el_name+"_L"); - } - for (std::string el_name : data_struct::Element_Symbols) - { - element_lines.push_back(el_name+"_M"); - } - - std::vector final_counts_to_add_before_scalers; - - final_counts_to_add_before_scalers.push_back(STR_COHERENT_SCT_AMPLITUDE); - final_counts_to_add_before_scalers.push_back(STR_COMPTON_AMPLITUDE); - final_counts_to_add_before_scalers.push_back(STR_SUM_ELASTIC_INELASTIC_AMP); - final_counts_to_add_before_scalers.push_back(STR_TOTAL_FLUORESCENCE_YIELD); - final_counts_to_add_before_scalers.push_back(STR_NUM_ITR); - final_counts_to_add_before_scalers.push_back(STR_RESIDUAL); - - data_struct::Fit_Count_Dict element_counts; - _model->getAnalyzedCounts(current_a, element_counts); - - const std::vector element_view_list = _imageViewWidget->getLabelList(); - - // get copy of elements to add the ones that were missed, usually pileups - data_struct::Fit_Count_Dict element_counts_not_added; - _model->getAnalyzedCounts(current_a, element_counts_not_added); - - _imageViewWidget->clearLabels(); - - // insert any region links - for (const auto& itr : _model->regionLinks()) - { - _imageViewWidget->addLabel(itr.first); - } - - // insert in z order - for (std::string el_name : element_lines) - { - if(element_counts.count(el_name) > 0) - { - QString val = QString(el_name.c_str()); - _imageViewWidget->addLabel(val); - element_counts_not_added.erase(el_name); - } - - } - - //add leftovers ( pile ups ) - for(auto& itr: element_counts_not_added) - { - // if it is not in the final add then add it - if(std::find(final_counts_to_add_before_scalers.begin(), final_counts_to_add_before_scalers.end(), itr.first) == final_counts_to_add_before_scalers.end()) - { - QString val = QString(itr.first.c_str()); - _imageViewWidget->addLabel(val); - } - } - - // add end of element list that are not elements - for (auto& itr : final_counts_to_add_before_scalers) - { - QString val = QString(itr.c_str()); - _imageViewWidget->addLabel(val); - } - - - std::vector scalers_to_add_first; - scalers_to_add_first.push_back(STR_SR_CURRENT); - scalers_to_add_first.push_back(STR_US_IC); - scalers_to_add_first.push_back(STR_DS_IC); - scalers_to_add_first.push_back(STR_ELT); - scalers_to_add_first.push_back(STR_ELAPSED_LIVE_TIME); - scalers_to_add_first.push_back(STR_ERT); - scalers_to_add_first.push_back(STR_ELAPSED_REAL_TIME); - scalers_to_add_first.push_back(STR_INPUT_COUNTS); - scalers_to_add_first.push_back(STR_ICR); - scalers_to_add_first.push_back("INCNT"); - scalers_to_add_first.push_back(STR_OUTPUT_COUNTS); - scalers_to_add_first.push_back(STR_OCR); - scalers_to_add_first.push_back("OUTCNT"); - scalers_to_add_first.push_back(STR_DEAD_TIME); - - scalers_to_add_first.push_back("abs_cfg"); - scalers_to_add_first.push_back("abs_ic"); - - scalers_to_add_first.push_back("H_dpc_cfg"); - scalers_to_add_first.push_back("V_dpc_cfg"); - - scalers_to_add_first.push_back("DPC1_IC"); - scalers_to_add_first.push_back("DPC2_IC"); - - scalers_to_add_first.push_back("dia1_dpc_cfg"); - scalers_to_add_first.push_back("dia2_dpc_cfg"); - - scalers_to_add_first.push_back("CFG_1"); - scalers_to_add_first.push_back(STR_CFG_2); - scalers_to_add_first.push_back(STR_CFG_3); - scalers_to_add_first.push_back(STR_CFG_4); - scalers_to_add_first.push_back(STR_CFG_5); - scalers_to_add_first.push_back("CFG_6"); - scalers_to_add_first.push_back("CFG_7"); - scalers_to_add_first.push_back("CFG_8"); - scalers_to_add_first.push_back("CFG_9"); - - - std::map> left_over_scalers = *scalers; - // add scalers in certain order - for (auto& itr : scalers_to_add_first) - { - if(scalers->count(itr) > 0) - { - _imageViewWidget->addLabel(QString(itr.c_str())); - left_over_scalers.erase(itr); - } - } - - // add rest of scalers - for (auto& itr : left_over_scalers) - { - _imageViewWidget->addLabel(QString(itr.first.c_str())); - } - - if(false == found_analysis) - { - current_analysis = QString(current_a.c_str()); - } - _cb_analysis->setCurrentText(current_analysis); - - _imageViewWidget->restoreLabels(element_view_list); - - for (int cntr = 0; cntr < _cb_normalize->count(); cntr++) - { - if (save_normal_val == _cb_normalize->itemText(cntr)) - { - _cb_normalize->setCurrentText(save_normal_val); - } - } - - redrawCounts(); - - connect(_cb_analysis, SIGNAL(currentIndexChanged(QString)), this, SLOT(onAnalysisSelect(QString))); -} -*/ //--------------------------------------------------------------------------- void CoLocalizationWidget::redrawCounts() @@ -689,46 +352,7 @@ void CoLocalizationWidget::redrawCounts() displayCounts(analysis_text, element.toStdString(), false, vidx); } } - /* - else - { - std::map > job_queue; - for (int vidx = 0; vidx < view_cnt; vidx++) - { - QString element = _imageViewWidget->getLabelAt(vidx); - if (_model != nullptr && _model->regionLinks().count(element) > 0) - { - _imageViewWidget->scene(vidx)->setPixmap(QPixmap::fromImage((_model->regionLinks().at(element)))); - } - else - { - job_queue[vidx] = Global_Thread_Pool::inst()->enqueue([this, vidx, analysis_text, element] { return generate_pixmap(analysis_text, element.toStdString(), false, vidx); }); - } - } - - while (job_queue.size() > 0) - { - std::vector to_delete; - for (auto& itr : job_queue) - { - _imageViewWidget->resetCoordsToZero(); - _imageViewWidget->scene(itr.first)->setPixmap(itr.second.get()); - if (m_imageHeightDim != nullptr && m_imageWidthDim != nullptr) - { - m_imageHeightDim->setCurrentText(QString::number(_imageViewWidget->scene(itr.first)->height())); - m_imageWidthDim->setCurrentText(QString::number(_imageViewWidget->scene(itr.first)->width())); - } - to_delete.push_back(itr.first); - } - - for (const auto& itr : to_delete) - { - job_queue.erase(itr); - } - } - } - */ //redraw annotations m_selectionModel->clear(); //m_imageViewWidget->setSceneModelAndSelection(_treeModel, _selectionModel); @@ -814,123 +438,6 @@ void CoLocalizationWidget::displayCounts(const std::string analysis_type, const } -//--------------------------------------------------------------------------- -/* -QPixmap CoLocalizationWidget::generate_pixmap(const std::string analysis_type, const std::string element, bool log_color, int grid_idx) -{ - if (_model != nullptr) - { - data_struct::Fit_Count_Dict fit_counts; - _model->getAnalyzedCounts(analysis_type, fit_counts); - std::map>* scalers = _model->getScalers(); - ArrayXXr normalized; - bool draw = false; - int height = 0; - int width = 0; - - if (fit_counts.count(element) > 0) - { - height = static_cast(fit_counts.at(element).rows()); - width = static_cast(fit_counts.at(element).cols()); - normalized = fit_counts.at(element); - draw = true; - } - - if (false == draw && scalers != nullptr) - { - if (scalers->count(element) > 0) - { - height = static_cast(scalers->at(element).rows()); - width = static_cast(scalers->at(element).cols()); - normalized = scalers->at(element); - draw = true; - } - } - - if (draw) - { - if (log_color) - { - normalized = normalized.log10(); - normalized = normalized.unaryExpr([](float v) { return std::isfinite(v) ? v : 0.0f; }); - } - - QImage image(width, height, QImage::Format_Indexed8); - image.setColorTable(*_selected_colormap); - - float counts_max; - float counts_min; - - counts_max = normalized.maxCoeff(); - counts_min = normalized.minCoeff(); - - //get user min max from contrast control - _imageViewWidget->getMinMaxAt(grid_idx, counts_min, counts_max); - - float max_min = counts_max - counts_min; - for (int row = 0; row < height; row++) - { - for (int col = 0; col < width; col++) - { - //first clamp the data to max min - float cnts = normalized(row, col); - cnts = std::min(counts_max, cnts); - cnts = std::max(counts_min, cnts); - //convert to pixel - uint data = (uint)(((cnts - counts_min) / max_min) * 255); - image.setPixel(col, row, data); - } - } - - if (height > 3 || _chk_disp_color_ledgend->isChecked() == true) - { - // add color map ledgend - int startH = height * .1; - int endH = height - startH; - int startW = width + 1; - int endW = width + cm_ledgend; - if (cm_ledgend == 3) - { - endW--; - } - - float inc = 255.0 / float(endH - startH); - float fcol = 255.0; - - for (int row = 0; row < height; row++) - { - if (row >= startH && row <= endH) - { - for (int col = width; col < width + cm_ledgend; col++) - { - if (col >= startW && col <= endW) - { - image.setPixel(col, row, uint(fcol)); - } - else - { - image.setPixel(col, row, uint(127)); - } - } - fcol -= inc; - fcol = std::max(fcol, float(0.0)); - } - else - { - for (int col = width; col < width + cm_ledgend; col++) - { - image.setPixel(col, row, uint(127)); - } - } - } - } - - return QPixmap::fromImage(image.convertToFormat(QImage::Format_RGB32)); - } - } - return QPixmap(); -} -*/ //--------------------------------------------------------------------------- void CoLocalizationWidget::windowChanged(Qt::WindowStates oldState, @@ -946,463 +453,38 @@ void CoLocalizationWidget::windowChanged(Qt::WindowStates oldState, } //--------------------------------------------------------------------------- -/* -void CoLocalizationWidget::on_export_image_pressed() -{ - //bring up dialog - if (_export_maps_dialog == nullptr) +void CoLocalizationWidget::onExportPng() +{ + if (_model != nullptr) { QDir export_model_dir = _model->getDir(); + QFileInfo finfo(export_model_dir.absolutePath()); export_model_dir.cdUp(); - export_model_dir.mkdir("export"); - export_model_dir.cd("export"); - export_model_dir.mkdir(_model->getDatasetName()); - export_model_dir.cd(_model->getDatasetName()); - - _export_maps_dialog = new ExportMapsDialog(export_model_dir.absolutePath()); - connect(_export_maps_dialog, &ExportMapsDialog::export_released, this, &CoLocalizationWidget::on_export_images); - } - _export_maps_dialog->show(); - -} - -//--------------------------------------------------------------------------- - -void CoLocalizationWidget::on_export_images() -{ - _export_maps_dialog->setRunEnabled(false); - - //get all maps - int view_cnt = _imageViewWidget->getViewCount(); - std::string analysis_text = _cb_analysis->currentText().toStdString(); - std::map > job_queue; - - - QDir export_model_dir = _export_maps_dialog->get_dir(); - int cur = 0; - - QDir png_dir = export_model_dir; - QDir tif8_dir = export_model_dir; - QDir tiff_dir = export_model_dir; - QDir ascii_dir = export_model_dir; + export_model_dir.cdUp(); + export_model_dir.cd("output"); - if (_export_maps_dialog->get_save_png()) - { - png_dir.mkdir("PNG"); - png_dir.cd("PNG"); - } - if (_export_maps_dialog->get_save_tiff()) - { - tif8_dir.mkdir("TIF_8bit"); - tif8_dir.cd("TIF_8bit"); - tiff_dir.mkdir("TIF_32FP"); - tiff_dir.cd("TIF_32FP"); - } + QDateTime date = QDateTime::currentDateTime(); + QString formattedTime = date.toString("yyyy.MM.dd_hh.mm.ss"); + QByteArray formattedTimeMsg = formattedTime.toLocal8Bit(); + QPixmap pixmap(rect().size()); + render(&pixmap, QPoint(), QRegion(rect())); - if (_export_maps_dialog->get_save_png() || _export_maps_dialog->get_save_tiff()) - { - if (_export_maps_dialog->get_export_all()) + QString apath = export_model_dir.absolutePath() + QDir::separator() + finfo.fileName() + QString("_colocalization_" + _curAnalysis + "_" + _cb_red_element->currentText() + "-" + _cb_green_element->currentText() + "-" + _cb_blue_element->currentText() + "_" + formattedTime); + QString png_path = QDir::cleanPath(apath + ".png"); + if (false == pixmap.save(png_path, "PNG")) { - std::vector normalizers = { STR_DS_IC , STR_US_IC, STR_SR_CURRENT, "Counts" }; - - std::vector analysis_types = _model->getAnalyzedTypes(); - for (auto& a_itr : analysis_types) - { - data_struct::Fit_Count_Dict element_counts; - _model->getAnalyzedCounts(a_itr, element_counts); - - if (_export_maps_dialog->get_save_png()) - { - png_dir.mkdir(QString(a_itr.c_str())); - png_dir.cd(QString(a_itr.c_str())); - } - if (_export_maps_dialog->get_save_tiff()) - { - tif8_dir.mkdir(QString(a_itr.c_str())); - tif8_dir.cd(QString(a_itr.c_str())); - tiff_dir.mkdir(QString(a_itr.c_str())); - tiff_dir.cd(QString(a_itr.c_str())); - } - - // Save 8 bit png and/or tiff - for (auto& e_itr : element_counts) - { - QPixmap pixmap = generate_pixmap(a_itr, e_itr.first, false, -1); - if (_export_maps_dialog->get_save_png()) - { - std::string save_file_name = a_itr + "-" + e_itr.first + ".png"; - if (false == pixmap.save(QDir::cleanPath(png_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())), "PNG")) - { - logE << "Could not save PNG for " << QDir::cleanPath(png_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"; - if (false == pixmap.save(QDir::cleanPath(tif8_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())), "TIFF")) - { - logE << "Could not save 8 bit TIFF for " << QDir::cleanPath(tif8_dir.absolutePath() + QDir::separator() + QString(save_file_name.c_str())).toStdString() << "\n"; - } - } - } - - // save normalized 32 bit float tiff - if (_export_maps_dialog->get_save_tiff()) - { - data_struct::ArrayXXr* normalizer = nullptr; - for (auto n_itr : normalizers) - { - tiff_dir.mkdir(QString(n_itr.c_str())); - tiff_dir.cd(QString(n_itr.c_str())); - - std::map>* scalers = _model->getScalers(); - if (scalers->count(n_itr) > 0) - { - normalizer = &(scalers->at(n_itr)); - } - Calibration_curve* calib_curve = _model->get_calibration_curve(a_itr, n_itr); - - for (auto& e_itr : element_counts) - { - std::string save_file_name_fp = a_itr + "-" + e_itr.first + "-"; - TIFF* tif = nullptr; - - data_struct::ArrayXXr counts = e_itr.second; - - //out_stream << e_itr.first; - if (calib_curve != nullptr && normalizer != nullptr) - { - if (calib_curve->calib_curve.count(e_itr.first) > 0) - { - save_file_name_fp += n_itr; - - float calib_val = static_cast(calib_curve->calib_curve.at(e_itr.first)); - - counts /= (*normalizer); - counts /= calib_val; - } - else - { - save_file_name_fp += "cts_s"; - } - } - else - { - save_file_name_fp += "cts_s"; - } - - save_file_name_fp += ".tif"; - - QString save_path = QDir::cleanPath(tiff_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, counts.data(), 4 * counts.cols() * counts.rows()); - TIFFClose(tif); - } - - tiff_dir.cdUp(); - } - } - - if (_export_maps_dialog->get_save_png()) - { - png_dir.cdUp(); - } - if (_export_maps_dialog->get_save_tiff()) - { - tif8_dir.cdUp(); - tiff_dir.cdUp(); - } - } + logE << "Could not save PNG for " << png_path.toStdString() << "\n"; } else { - _export_maps_dialog->status_callback(cur, view_cnt); - for (int vidx = 0; vidx < view_cnt; vidx++) + if (false == QDesktopServices::openUrl(QUrl::fromLocalFile(export_model_dir.absolutePath()))) { - QString element = _imageViewWidget->getLabelAt(vidx); - std::string el_str = element.toStdString(); - - job_queue[el_str] = Global_Thread_Pool::inst()->enqueue([this, vidx, analysis_text, element] { return generate_pixmap(analysis_text, element.toStdString(), _chk_log_color->isChecked(), vidx); }); - - - // save normalized 32 bit float tiff - std::string save_file_name_fp = analysis_text + "-" + el_str + "-"; - Calibration_curve* calib_curve = _model->get_calibration_curve(analysis_text, _cb_normalize->currentText().toStdString()); - TIFF* tif = nullptr; - data_struct::ArrayXXr counts; - - data_struct::Fit_Count_Dict element_counts; - _model->getAnalyzedCounts(analysis_text, element_counts); - if (element_counts.count(el_str) > 0) - { - counts = element_counts.at(el_str); - - if (calib_curve != nullptr && _normalizer != nullptr) - { - if (calib_curve->calib_curve.count(el_str) > 0) - { - save_file_name_fp += _cb_normalize->currentText().toStdString(); - - float calib_val = static_cast(calib_curve->calib_curve.at(el_str)); - - counts /= (*_normalizer); - counts /= calib_val; - } - } - } - else if (_model->getScalers()->count(el_str) > 0) - { - counts = _model->getScalers()->at(el_str); - } - save_file_name_fp += ".tif"; - - QString save_path = QDir::cleanPath(tiff_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, counts.cols()); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, counts.rows()); - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 32); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1); - TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, counts.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, counts.data(), 4 * counts.cols() * counts.rows()); - TIFFClose(tif); - + logE << "Failed to open dir " << export_model_dir.absolutePath().toStdString() << "\n"; } - - while (job_queue.size() > 0) - { - std::vector to_delete; - for (auto& itr : job_queue) - { - QPixmap pixmap = itr.second.get(); - - if (_export_maps_dialog->get_save_png()) - { - if (false == pixmap.save(QDir::cleanPath(png_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".png"), "PNG")) - { - logE << "Could not save PNG for " << QDir::cleanPath(png_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 == pixmap.save(QDir::cleanPath(tif8_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".tif"), "TIFF")) - { - logE << "Could not save 8 bit TIFF for " << QDir::cleanPath(tif8_dir.absolutePath() + QDir::separator() + QString(itr.first.c_str()) + ".tif").toStdString() << "\n"; - } - } - to_delete.push_back(itr.first); - cur++; - _export_maps_dialog->status_callback(cur, view_cnt); - } - - for (const auto& itr : to_delete) - { - job_queue.erase(itr); - } - } - } - } - if (_export_maps_dialog->get_save_ascii()) - { - ascii_dir.mkdir("ASCII"); - ascii_dir.cd("ASCII"); - - std::vector normalizers = { STR_DS_IC , STR_US_IC, STR_SR_CURRENT, "Counts" }; - - const std::vector x_axis = _model->get_x_axis(); - const std::vector y_axis = _model->get_y_axis(); - - std::vector analysis_types = _model->getAnalyzedTypes(); - - size_t cur = 0; - size_t total = analysis_types.size() * x_axis.size() * y_axis.size() * normalizers.size(); - _export_maps_dialog->status_callback(cur, total); - - - for (auto& a_itr : analysis_types) - { - data_struct::Fit_Count_Dict element_counts; - _model->getAnalyzedCounts(a_itr, element_counts); - - data_struct::ArrayXXr* normalizer = nullptr; - - ascii_dir.mkdir(QString(a_itr.c_str())); - ascii_dir.cd(QString(a_itr.c_str())); - - for (auto n_itr : normalizers) - { - - ascii_dir.mkdir(QString(n_itr.c_str())); - ascii_dir.cd(QString(n_itr.c_str())); - - std::map>* scalers = _model->getScalers(); - if (scalers->count(n_itr) > 0) - { - normalizer = &(scalers->at(n_itr)); - } - Calibration_curve* calib_curve = _model->get_calibration_curve(a_itr, n_itr); - - std::string save_file_name = ascii_dir.absolutePath().toStdString() + QDir::separator().toLatin1() + _model->getDatasetName().toStdString(); - - std::string sub_save_file = save_file_name + "-" + a_itr + "-" + n_itr + ".csv"; - std::ofstream out_stream(sub_save_file); - - logI << save_file_name << "\n"; - - if (out_stream.is_open()) - { - - out_stream << "ascii information for file: " << _model->getDatasetName().toStdString() << "\n"; - - - - if (a_itr == STR_FIT_ROI || n_itr == "Counts") - { - out_stream << "Analysis " << a_itr << " in cts/s \n"; - } - else - { - out_stream << "Analysis " << a_itr << " Normalized by " << n_itr << " ug/cm2 \n"; - } - - out_stream << "Y Pixel, X Pixel, Y Position, X Position, "; - for (auto& e_itr : element_counts) - { - out_stream << e_itr.first; - if (calib_curve != nullptr && normalizer != nullptr) - { - if (calib_curve->calib_curve.count(e_itr.first) > 0) - { - out_stream << " (ug/cm2) "; - } - else - { - out_stream << " (cts/s) "; - } - } - else - { - out_stream << " (cts/s) "; - } - out_stream << " , "; - } - out_stream << "\n"; - - for (int yidx = 0; yidx < y_axis.size(); yidx++) - { - for (int xidx = 0; xidx < x_axis.size(); xidx++) - { - - out_stream << yidx << " , " << xidx << " , " << y_axis.at(yidx) << " , " << x_axis.at(xidx) << " , "; - - for (auto& e_itr : element_counts) - { - float calib_val = 1.0; - double val = 1.0; - float e_val = (e_itr.second)(yidx, xidx); - if (a_itr == STR_FIT_ROI || n_itr == "Counts") - { - val = e_val; - } - else - { - if (calib_curve != nullptr && normalizer != nullptr) - { - if (calib_curve->calib_curve.count(e_itr.first) > 0) - { - calib_val = static_cast(calib_curve->calib_curve.at(e_itr.first)); - float n_val = (*normalizer)(yidx, xidx); - val = e_val / n_val / calib_val; - } - else - { - val = e_val; - } - } - else - { - val = e_val; - } - } - out_stream << val << " , "; - } - cur++; - _export_maps_dialog->status_callback(cur, total); - out_stream << "\n"; - } - if (false == _export_maps_dialog->isActiveWindow()) - { - out_stream.close(); - _export_maps_dialog->setRunEnabled(true); - return; - } - out_stream << "\n"; - } - out_stream.close(); - } - else - { - logE << "Could not save PNG for " << save_file_name << "\n"; - } - - ascii_dir.cdUp(); - } - ascii_dir.cdUp(); } } - if (_export_maps_dialog->get_save_screen()) - { - - QPixmap pixmap(_counts_window->rect().size()); - _counts_window->render(&pixmap, QPoint(), QRegion(_counts_window->rect())); - - QDateTime date = QDateTime::currentDateTime(); - QString formattedTime = date.toString("yyyy.MM.dd_hh.mm.ss"); - QByteArray formattedTimeMsg = formattedTime.toLocal8Bit(); - - qDebug() << "Date:" + formattedTime; - if (false == pixmap.save(QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString("screenshot_"+formattedTime+".png")), "PNG")) - { - logE << "Could not save PNG for " << QDir::cleanPath(export_model_dir.absolutePath() + QDir::separator() + QString("screenshot_" + formattedTime + ".png")).toStdString() << "\n"; - } - } - - _export_maps_dialog->setRunEnabled(true); - _export_maps_dialog->on_open(); - _export_maps_dialog->close(); } -*/ +//--------------------------------------------------------------------------- diff --git a/src/mvc/CoLocalizationWidget.h b/src/mvc/CoLocalizationWidget.h index 0d3eda2..ef04ce6 100644 --- a/src/mvc/CoLocalizationWidget.h +++ b/src/mvc/CoLocalizationWidget.h @@ -58,6 +58,8 @@ public slots: void onQuadViewChanged(int); + void onExportPng(); + protected: /** diff --git a/src/mvc/ScatterPlotWidget.cpp b/src/mvc/ScatterPlotWidget.cpp index b8e4f39..6eeecbd 100644 --- a/src/mvc/ScatterPlotWidget.cpp +++ b/src/mvc/ScatterPlotWidget.cpp @@ -42,6 +42,7 @@ ScatterPlotView::ScatterPlotView(bool display_log10, bool black_background, QWid _chart = new QtCharts::QChart(); _lb_roi = new QLabel("ROI:"); + _lb_roi->setAlignment(Qt::AlignRight); _cb_roi = new QComboBox(); _cb_roi->setSizeAdjustPolicy(QComboBox::AdjustToContents); connect(_cb_roi, qOverload(&QComboBox::currentIndexChanged), this, &ScatterPlotView::onNameChange); @@ -90,15 +91,25 @@ ScatterPlotView::ScatterPlotView(bool display_log10, bool black_background, QWid } _lb_corr_coef = new QLabel(); + _lb_corr_coef->setAlignment(Qt::AlignCenter); + + QLabel* lb_xaxis = new QLabel("X Axis:"); + lb_xaxis->setAlignment(Qt::AlignRight | Qt::AlignCenter); + + QLabel* lb_yaxis = new QLabel("Y Axis:"); + lb_yaxis->setAlignment(Qt::AlignRight | Qt::AlignCenter); + + QLabel* lb_coef = new QLabel("Correlation Coefficient:"); + lb_coef->setAlignment(Qt::AlignRight | Qt::AlignCenter); QHBoxLayout* hbox = new QHBoxLayout(); hbox->addWidget(_lb_roi); hbox->addWidget(_cb_roi); - hbox->addWidget(new QLabel("X Axis:")); + hbox->addWidget(lb_xaxis); hbox->addWidget(_cb_x_axis_element); - hbox->addWidget(new QLabel("Y Axis:")); + hbox->addWidget(lb_yaxis); hbox->addWidget(_cb_y_axis_element); - hbox->addWidget(new QLabel("Correlation Coefficient:")); + hbox->addWidget(lb_coef); hbox->addWidget(_lb_corr_coef); //hbox->addItem(new QSpacerItem(9999, 40, QSizePolicy::Maximum)); From 3ab901f9428d73e3a4d2dd273a0393497c1a15ae Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Fri, 17 Mar 2023 12:24:12 -0500 Subject: [PATCH 2/4] Can scan scalers for corr coef --- src/mvc/MapsElementsWidget.cpp | 13 - src/mvc/ScanCorrCoefDialog.cpp | 304 +++++++++++++++++ src/mvc/ScanCorrCoefDialog.h | 101 ++++++ src/mvc/ScatterPlotView.cpp | 527 +++++++++++++++++++++++++++++ src/mvc/ScatterPlotView.h | 113 +++++++ src/mvc/ScatterPlotWidget.cpp | 590 +-------------------------------- src/mvc/ScatterPlotWidget.h | 86 +---- 7 files changed, 1053 insertions(+), 681 deletions(-) create mode 100644 src/mvc/ScanCorrCoefDialog.cpp create mode 100644 src/mvc/ScanCorrCoefDialog.h create mode 100644 src/mvc/ScatterPlotView.cpp create mode 100644 src/mvc/ScatterPlotView.h diff --git a/src/mvc/MapsElementsWidget.cpp b/src/mvc/MapsElementsWidget.cpp index e486440..d30228c 100644 --- a/src/mvc/MapsElementsWidget.cpp +++ b/src/mvc/MapsElementsWidget.cpp @@ -79,19 +79,6 @@ MapsElementsWidget::~MapsElementsWidget() } _model = nullptr; */ - /* - if (_co_loc_widget != nullptr) - { - delete _co_loc_widget; - } - _co_loc_widget = nullptr; - - if(_spectra_widget != nullptr) - { - delete _spectra_widget; - } - _spectra_widget = nullptr; - */ } //--------------------------------------------------------------------------- diff --git a/src/mvc/ScanCorrCoefDialog.cpp b/src/mvc/ScanCorrCoefDialog.cpp new file mode 100644 index 0000000..b971cfb --- /dev/null +++ b/src/mvc/ScanCorrCoefDialog.cpp @@ -0,0 +1,304 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2023, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#include +#include +#include "stats/correlation_coefficient.h" +//#include "core/GlobalThreadPool.h" +#include "mvc/ScatterPlotView.h" + +//--------------------------------------------------------------------------- + +ScanCorrCoefDialog::ScanCorrCoefDialog(QWidget *parent) : QWidget(parent) +{ + _running = false; + _createLayout(); +} + +//--------------------------------------------------------------------------- + +ScanCorrCoefDialog::~ScanCorrCoefDialog() +{ + + +} + +//--------------------------------------------------------------------------- + +void ScanCorrCoefDialog::_createLayout() +{ + + _progressBarFiles = new QProgressBar(); + _progressBarFiles->setRange(0, 100); + + _btn_run = new QPushButton("Scan"); + connect(_btn_run, &QPushButton::released, this, &ScanCorrCoefDialog::onRun); + _btn_cancel = new QPushButton("Close"); + connect(_btn_cancel, &QPushButton::released, this, &ScanCorrCoefDialog::onClose); + + _processing_grp = new QGroupBox(); + QVBoxLayout* v_proc_layout = new QVBoxLayout(); + QHBoxLayout* h_layout = new QHBoxLayout(); + + _le_restrict_coef = new QLineEdit(); + _le_restrict_coef->setValidator(new QDoubleValidator(0.0, 1.0, 0.1, this)); + _le_restrict_coef->setText("0.85"); + + _ck_use_elements = new QCheckBox("Use Elements"); + _ck_use_elements->setChecked(true); + + _ck_use_scalers = new QCheckBox("Use Scalers"); + _ck_use_scalers->setChecked(false); + + _ck_use_rois = new QCheckBox("Use ROI's if available"); + _ck_use_rois->setChecked(false); + + QHBoxLayout* hbox = new QHBoxLayout(); + QLabel* lbl_Coef_Rest = new QLabel("Only save when Corr Coef is greater than:"); + hbox->addWidget(lbl_Coef_Rest); + hbox->addWidget(_le_restrict_coef); + + v_proc_layout->addItem(h_layout); + v_proc_layout->addItem(hbox); + v_proc_layout->addWidget(_ck_use_elements); + v_proc_layout->addWidget(_ck_use_scalers); + v_proc_layout->addWidget(_ck_use_rois); + + _processing_grp->setLayout(v_proc_layout); + _processing_grp->setTitle("Scan Correlation Coefficient"); + + QHBoxLayout* buttonlayout = new QHBoxLayout(); + buttonlayout->addWidget(_btn_run); + buttonlayout->addWidget(_btn_cancel); + + QHBoxLayout* proc_save_layout = new QHBoxLayout(); + proc_save_layout->addWidget(_processing_grp); + + QVBoxLayout* layout = new QVBoxLayout(); + layout->addItem(proc_save_layout); + layout->addItem(buttonlayout); + layout->addWidget(_progressBarFiles); + + setLayout(layout); +} + +//--------------------------------------------------------------------------- + +void ScanCorrCoefDialog::setRunEnabled(bool val) +{ + _processing_grp->setEnabled(val); + _btn_run->setEnabled(val); +} + +//--------------------------------------------------------------------------- + +void ScanCorrCoefDialog::setModel(std::string analysis_type, MapsH5Model* model) +{ + _model = model; + _analysis_type = analysis_type; +} + +//--------------------------------------------------------------------------- + +void ScanCorrCoefDialog::status_callback(size_t cur_block, size_t total_blocks) +{ + + if (_total_blocks != total_blocks) + { + _total_blocks = total_blocks; + _progressBarFiles->setRange(0, _total_blocks); + } + + _progressBarFiles->setValue(cur_block); + + QCoreApplication::processEvents(); +} + +//--------------------------------------------------------------------------- + +double proc_corr_coef(MapsH5Model* model, std::string analysis_type, double restrict_coef, std::pair name_pair) +{ + data_struct::ArrayXXr x_map; + data_struct::ArrayXXr y_map; + + data_struct::Fit_Count_Dict fit_counts; + model->getAnalyzedCounts(analysis_type, fit_counts); + std::map>* scalers = model->getScalers(); + + if (fit_counts.count(name_pair.first) > 0) + { + x_map = fit_counts.at(name_pair.first); + } + else if (scalers->count(name_pair.first) > 0) + { + x_map = scalers->at(name_pair.first); + } + + if (fit_counts.count(name_pair.second) > 0) + { + y_map = fit_counts.at(name_pair.second); + } + else if (scalers->count(name_pair.second) > 0) + { + y_map = scalers->at(name_pair.second); + } + + Eigen::Array x_arr; + Eigen::Array y_arr; + x_arr.resize(x_map.cols() * x_map.rows()); + y_arr.resize(x_map.cols() * x_map.rows()); + int n = 0; + + for (int y = 0; y < x_map.rows(); y++) + { + for (int x = 0; x < x_map.cols(); x++) + { + x_arr(n) = (double)x_map(y, x); + y_arr(n) = (double)y_map(y, x); + n++; + } + } + + double corr_coef = find_coefficient(x_arr, y_arr); + + return corr_coef; +} + +//--------------------------------------------------------------------------- + +void ScanCorrCoefDialog::onRun() +{ + //int foundCnt = 0; + _btn_run->setEnabled(false); + _running = true; + if (_model != nullptr) + { + bool use_elements = _ck_use_elements->isChecked(); + bool use_scalers = _ck_use_scalers->isChecked(); + bool use_rois = _ck_use_rois->isChecked(); + + std::vector total_names; + std::vector> el_pair_names; + + if (use_elements) + { + std::vector count_names = _model->count_names(); + for (auto& itr : count_names) + { + total_names.push_back(itr); + } + } + + if (use_scalers) + { + std::map>* scalers = _model->getScalers(); + for (auto& itr : *scalers) + { + total_names.push_back(itr.first); + } + } + + double restrict_coef = _le_restrict_coef->text().toDouble(); + while (total_names.size() > 0) + { + int last = total_names.size() - 1; + for (int i = 0; i < last; i++) + { + el_pair_names.push_back({ total_names[last], total_names[i] }); + } + total_names.pop_back(); + } + int total = el_pair_names.size(); + status_callback(0, total); + + ScatterPlotView* view = new ScatterPlotView(true, true, nullptr); + view->setModel(_model); + view->setAnalysisType(QString(_analysis_type.c_str())); + int cur = 0; + //std::map > job_queue; + for (int i = 0; i < el_pair_names.size(); i++) + { + //job_queue[i] = Global_Thread_Pool::inst()->enqueue([this, i, restrict_coef, el_pair_names] { return proc_corr_coef(_model, _analysis_type, restrict_coef, el_pair_names[i]); }); + double val = proc_corr_coef(_model, _analysis_type, restrict_coef, el_pair_names[i]); + if (val > restrict_coef || val < -restrict_coef) + { + //logI << key << " : " << val << "\n"; + view->setXYAxis("", QString(el_pair_names[i].first.c_str()), QString(el_pair_names[i].second.c_str())); + view->resize(1920, 1080); + view->exportPngCsv(); + } + cur++; + status_callback(cur, total); + QCoreApplication::processEvents(); + if (false == _running) + { + break; + } + } + + delete view; + /* + while (job_queue.size() > 0) + { + status_callback(total - job_queue.size(), total); + QCoreApplication::processEvents(); + + std::vector to_delete; + for (auto& itr : job_queue) + { + std::future_status status = itr.second.wait_for(std::chrono::milliseconds(10)); + if (status == std::future_status::ready) + { + std::string key = el_pair_names[itr.first].first + '/' + el_pair_names[itr.first].second; + double val = 0.0; + try + { + val = itr.second.get(); + } + catch (std::exception &e) + { + logE << e.what() << "\n"; + } + //corr_coef_map[key] = val; + + if (val > restrict_coef || val < -restrict_coef) + { + //foundCnt++; + logI << key << " : " << val << "\n"; + ScatterPlotView* view = new ScatterPlotView(true, true, nullptr); + view->setModel(_model); + view->setAnalysisType(QString(_analysis_type.c_str())); + view->setXYAxis("", QString(el_pair_names[itr.first].first.c_str()), QString(el_pair_names[itr.first].second.c_str())); + view->resize(1920, 1080); + view->exportPngCsv(); + delete view; + } + to_delete.push_back(itr.first); + } + } + + for (const auto& itr : to_delete) + { + job_queue.erase(itr); + } + } + status_callback(total - job_queue.size(), total); + QCoreApplication::processEvents(); + */ + } + _running = false; + _btn_run->setEnabled(true); + +} + +//--------------------------------------------------------------------------- + +void ScanCorrCoefDialog::onClose() +{ + _running = false; + close(); +} + +//--------------------------------------------------------------------------- diff --git a/src/mvc/ScanCorrCoefDialog.h b/src/mvc/ScanCorrCoefDialog.h new file mode 100644 index 0000000..c48eb6e --- /dev/null +++ b/src/mvc/ScanCorrCoefDialog.h @@ -0,0 +1,101 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2023, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#ifndef ScanCorrCoefDialog_DIALOG_H +#define ScanCorrCoefDialog_DIALOG_H + +/*---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "mvc/MapsH5Model.h" + +/*---------------------------------------------------------------------------*/ + + +class ScanCorrCoefDialog : public QWidget +{ + + Q_OBJECT + +public: + + /** + * Constructor. + */ + ScanCorrCoefDialog(QWidget *parent = nullptr); + + /** + * Destructor. + */ + ~ScanCorrCoefDialog(); + + void status_callback(size_t cur, size_t total); + + void setRunEnabled(bool val); + + void setModel(std::string analysis_type, MapsH5Model* model); + +public slots: + + void onRun(); + + void onClose(); + +protected: + + /** + * @brief Create layout + */ + void _createLayout(); + + QGroupBox* _processing_grp; + + QProgressBar *_progressBarFiles; + + QPushButton *_btn_run; + + QPushButton *_btn_cancel; + + QLineEdit* _le_restrict_coef; + + QCheckBox* _ck_use_elements; + + QCheckBox* _ck_use_scalers; + + QCheckBox* _ck_use_rois; + + MapsH5Model* _model; + + size_t _total_blocks; + + std::string _analysis_type; + + bool _running; + +}; + + +/*---------------------------------------------------------------------------*/ + +#endif + +/*---------------------------------------------------------------------------*/ diff --git a/src/mvc/ScatterPlotView.cpp b/src/mvc/ScatterPlotView.cpp new file mode 100644 index 0000000..3e75d80 --- /dev/null +++ b/src/mvc/ScatterPlotView.cpp @@ -0,0 +1,527 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2023, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include "preferences/Preferences.h" +#include "stats/correlation_coefficient.h" + + //--------------------------------------------------------------------------- + +ScatterPlotView::ScatterPlotView(bool display_log10, bool black_background, QWidget* parent) : QWidget(parent) +{ + + _model = nullptr; + _curAnalysis = QString(STR_FIT_NNLS.c_str()); + + _axisXLog10 = new QtCharts::QLogValueAxis(); + _axisXLog10->setTitleText(""); + _axisXLog10->setLabelFormat("%.1e"); + _axisXLog10->setBase(10.0); + + _axisX = new QtCharts::QValueAxis(); + _axisX->setTitleText(""); + _axisX->setLabelFormat("%f"); + + _axisYLog10 = new QtCharts::QLogValueAxis(); + _axisYLog10->setTitleText(""); + _axisYLog10->setLabelFormat("%.1e"); + _axisYLog10->setBase(10.0); + + _axisY = new QtCharts::QValueAxis(); + _axisY->setTitleText(""); + _axisY->setLabelFormat("%f"); + + _chart = new QtCharts::QChart(); + + _lb_roi = new QLabel("ROI:"); + _lb_roi->setAlignment(Qt::AlignRight); + _cb_roi = new QComboBox(); + _cb_roi->setSizeAdjustPolicy(QComboBox::AdjustToContents); + connect(_cb_roi, qOverload(&QComboBox::currentIndexChanged), this, &ScatterPlotView::onNameChange); + _cb_x_axis_element = new QComboBox(); + _cb_x_axis_element->setSizeAdjustPolicy(QComboBox::AdjustToContents); + connect(_cb_x_axis_element, qOverload(&QComboBox::currentIndexChanged), this, &ScatterPlotView::onNameChange); + _cb_y_axis_element = new QComboBox(); + _cb_y_axis_element->setSizeAdjustPolicy(QComboBox::AdjustToContents); + connect(_cb_y_axis_element, qOverload(&QComboBox::currentIndexChanged), this, &ScatterPlotView::onNameChange); + + _chartView = new QtCharts::QChartView(_chart); + + //setRenderHint(QPainter::Antialiasing); + _scatter_series = new QtCharts::QScatterSeries(); + QString marker_shape = Preferences::inst()->getValue(STR_PFR_MARKER_SHAPE).toString(); + if (marker_shape == "Circle") + { + _scatter_series->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeCircle); + } + else + { + _scatter_series->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeRectangle); + } + _scatter_series->setMarkerSize(1.0); + _scatter_series->setUseOpenGL(true); + _chart->addSeries(_scatter_series); + _display_log10 = display_log10; + if (_display_log10) + { + _chart->addAxis(_axisXLog10, Qt::AlignBottom); + _chart->addAxis(_axisYLog10, Qt::AlignLeft); + _scatter_series->attachAxis(_axisXLog10); + _scatter_series->attachAxis(_axisYLog10); + } + else + { + _chart->addAxis(_axisX, Qt::AlignBottom); + _chart->addAxis(_axisY, Qt::AlignLeft); + _scatter_series->attachAxis(_axisX); + _scatter_series->attachAxis(_axisY); + } + + if (black_background) + { + _chart->setBackgroundBrush(QBrush(QColor("black"))); + } + + _lb_corr_coef = new QLabel(); + _lb_corr_coef->setAlignment(Qt::AlignCenter); + + QLabel* lb_xaxis = new QLabel("X Axis:"); + lb_xaxis->setAlignment(Qt::AlignRight | Qt::AlignCenter); + + QLabel* lb_yaxis = new QLabel("Y Axis:"); + lb_yaxis->setAlignment(Qt::AlignRight | Qt::AlignCenter); + + QLabel* lb_coef = new QLabel("Correlation Coefficient:"); + lb_coef->setAlignment(Qt::AlignRight | Qt::AlignCenter); + + QHBoxLayout* hbox = new QHBoxLayout(); + hbox->addWidget(_lb_roi); + hbox->addWidget(_cb_roi); + hbox->addWidget(lb_xaxis); + hbox->addWidget(_cb_x_axis_element); + hbox->addWidget(lb_yaxis); + hbox->addWidget(_cb_y_axis_element); + hbox->addWidget(lb_coef); + hbox->addWidget(_lb_corr_coef); + //hbox->addItem(new QSpacerItem(9999, 40, QSizePolicy::Maximum)); + + QVBoxLayout* vbox = new QVBoxLayout(); + vbox->addItem(hbox); + vbox->addWidget(_chartView); + + setGridLinesVisible(Preferences::inst()->getValue(STR_PRF_ScatterPlot_GridLines).toBool()); + + setLayout(vbox); + +} + +//--------------------------------------------------------------------------- + +ScatterPlotView::~ScatterPlotView() +{ + +} + +void ScatterPlotView::exportPngCsv() +{ + if (_model != nullptr) + { + QDir dir = _model->getDir(); + QFileInfo finfo(dir.absolutePath()); + + //QPixmap pixmap(rect().size()); + //render(&pixmap, QPoint(), QRegion(rect())); + + QPixmap pixmap = _chartView->grab(); + QDateTime date = QDateTime::currentDateTime(); + QString formattedTime = date.toString("yyyy.MM.dd_hh.mm.ss"); + QByteArray formattedTimeMsg = formattedTime.toLocal8Bit(); + + dir.cdUp(); + dir.cdUp(); + dir.cd("output"); + + QString roi_name = _cb_roi->currentText(); + QString apath; + if (roi_name.length() > 0) + { + apath = dir.absolutePath() + QDir::separator() + finfo.fileName() + QString("_scatter_" + _curAnalysis + "_" + _cb_roi->currentText() + "-" + _cb_x_axis_element->currentText() + "-" + _cb_y_axis_element->currentText() + "_" + formattedTime); + } + else + { + apath = dir.absolutePath() + QDir::separator() + finfo.fileName() + QString("_scatter_" + _curAnalysis + "_" + _cb_x_axis_element->currentText() + "-" + _cb_y_axis_element->currentText() + "_" + formattedTime); + } + QString png_path = QDir::cleanPath(apath + ".png"); + if (false == pixmap.save(png_path, "PNG")) + { + logE << "Could not save PNG for " << png_path.toStdString() << "\n"; + } + else + { + if (false == QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()))) + { + logE << "Failed to open dir " << dir.absolutePath().toStdString() << "\n"; + } + } + + QString csv_path = QDir::cleanPath(apath + ".csv"); + _exportScatterPlotCSV(csv_path); + + } +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::_exportScatterPlotCSV(QString filePath) +{ + if (_model != nullptr) + { + data_struct::ArrayXXr x_map; + data_struct::ArrayXXr y_map; + if (_getXY_Maps(x_map, y_map)) + { + std::ofstream out_stream(filePath.toStdString()); + if (out_stream.is_open()) + { + out_stream << "ascii information for file: " << _model->getDatasetName().toStdString() << "\n"; + out_stream << "Analysis Type: " << _curAnalysis.toStdString() << "\n"; + out_stream << "X Axis Name: " << _cb_x_axis_element->currentText().toStdString() << "\n"; + out_stream << "Y Axis Name: " << _cb_y_axis_element->currentText().toStdString() << "\n"; + out_stream << "Rows: " << x_map.rows() << "\n"; + out_stream << "Cols: " << x_map.cols() << "\n"; + out_stream << "X Index, Y Index, X Value, Y Value \n"; + for (int y = 0; y < x_map.rows(); y++) + { + for (int x = 0; x < x_map.cols(); x++) + { + out_stream << x << "," << y << "," << x_map(y, x) << "," << y_map(y, x) << "\n"; + } + } + } + else + { + logE << "Could not open for writing scatter plot CSV : " << filePath.toStdString() << "\n"; + } + out_stream.close(); + } + } +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::setXYAxis(QString roi_name, QString x_axis_name, QString y_axis_name) +{ + _cb_roi->setCurrentText(roi_name); + _cb_x_axis_element->setCurrentText(x_axis_name); + _cb_y_axis_element->setCurrentText(y_axis_name); + _updatePlot(); +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::setShape(QtCharts::QScatterSeries::MarkerShape shape) +{ + _scatter_series->setMarkerShape(shape); + _updatePlot(); +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::setBlackBackground(int val) +{ + if (val == 0) + { + _chart->setBackgroundBrush(QBrush(QColor("white"))); + } + else + { + _chart->setBackgroundBrush(QBrush(QColor("black"))); + } +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::setLog10(int val) +{ + + if (val == 0) + { + _display_log10 = false; + _scatter_series->detachAxis(_axisXLog10); + _scatter_series->detachAxis(_axisYLog10); + + _chart->removeAxis(_axisXLog10); + _chart->removeAxis(_axisYLog10); + + _chart->addAxis(_axisX, Qt::AlignBottom); + _chart->addAxis(_axisY, Qt::AlignLeft); + + _scatter_series->attachAxis(_axisX); + _scatter_series->attachAxis(_axisY); + } + else + { + _display_log10 = true; + _scatter_series->detachAxis(_axisX); + _scatter_series->detachAxis(_axisY); + _chart->removeAxis(_axisX); + _chart->removeAxis(_axisY); + + _chart->addAxis(_axisXLog10, Qt::AlignBottom); + _chart->addAxis(_axisYLog10, Qt::AlignLeft); + _scatter_series->attachAxis(_axisXLog10); + _scatter_series->attachAxis(_axisYLog10); + } + _updatePlot(); + +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::onNameChange(QString name) +{ + _updatePlot(); +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::setModel(MapsH5Model* model) +{ + _model = model; + _updateNames(); +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::setAnalysisType(QString name) +{ + _curAnalysis = name; + _updateNames(); +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::_updateNames() +{ + if (_model != nullptr) + { + const std::unordered_map rois = _model->get_map_rois(); + + _cb_roi->clear(); + _cb_roi->addItem(" "); + for (auto& itr : rois) + { + _cb_roi->addItem(QString(itr.first.c_str())); + } + + std::vector map_names; + _model->generateNameLists(_curAnalysis, map_names); + QString xSavedName = _cb_x_axis_element->currentText(); + QString ySavedName = _cb_y_axis_element->currentText(); + _cb_x_axis_element->clear(); + _cb_y_axis_element->clear(); + + _cb_x_axis_element->addItem(" "); + _cb_y_axis_element->addItem(" "); + for (auto& itr : map_names) + { + _cb_x_axis_element->addItem(QString(itr.c_str())); + _cb_y_axis_element->addItem(QString(itr.c_str())); + } + + int xIdx = _cb_x_axis_element->findText(xSavedName); + int yIdx = _cb_y_axis_element->findText(ySavedName); + if (xIdx > -1) + { + _cb_x_axis_element->setCurrentIndex(xIdx); + } + if (yIdx > -1) + { + _cb_y_axis_element->setCurrentIndex(yIdx); + } + } + _updatePlot(); +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::updateMarkerSize(qreal val) +{ + _scatter_series->setMarkerSize(val); + _updatePlot(); +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::setGridLinesVisible(int val) +{ + if (val == 0) + { + _axisX->setGridLineVisible(false); + _axisY->setGridLineVisible(false); + _axisXLog10->setGridLineVisible(false); + _axisYLog10->setGridLineVisible(false); + } + else + { + _axisX->setGridLineVisible(true); + _axisY->setGridLineVisible(true); + _axisXLog10->setGridLineVisible(true); + _axisYLog10->setGridLineVisible(true); + } +} + +//--------------------------------------------------------------------------- + +bool ScatterPlotView::_getXY_Maps(data_struct::ArrayXXr &x_map, data_struct::ArrayXXr &y_map) +{ + bool foundX = false; + bool foundY = false; + + std::string xName = _cb_x_axis_element->currentText().toStdString(); + std::string yName = _cb_y_axis_element->currentText().toStdString(); + + data_struct::Fit_Count_Dict fit_counts; + _model->getAnalyzedCounts(_curAnalysis.toStdString(), fit_counts); + std::map>* scalers = _model->getScalers(); + + int xCnt = fit_counts.count(xName); + if (xCnt != 0) + { + x_map = fit_counts.at(xName); + foundX = true; + } + else + { + xCnt = scalers->count(xName); + if (xCnt != 0) + { + x_map = scalers->at(xName); + foundX = true; + } + } + + + int yCnt = fit_counts.count(yName); + if (yCnt != 0) + { + y_map = fit_counts.at(yName); + foundY = true; + } + else + { + yCnt = scalers->count(yName); + if (yCnt != 0) + { + y_map = scalers->at(yName); + foundY = true; + } + } + + return foundX && foundY; +} + +//--------------------------------------------------------------------------- + +void ScatterPlotView::_updatePlot() +{ + std::string xName = _cb_x_axis_element->currentText().toStdString(); + std::string yName = _cb_y_axis_element->currentText().toStdString(); + + + if (_model != nullptr) + { + data_struct::ArrayXXr x_map; + data_struct::ArrayXXr y_map; + + if (_getXY_Maps(x_map, y_map)) + { + _chart->removeSeries(_scatter_series); + _scatter_series->clear(); + + if (_display_log10) + { + x_map = x_map.unaryExpr([](float v) { return (v <= 0.0f) ? 0.0000001f : log10(v); }); + y_map = y_map.unaryExpr([](float v) { return (v <= 0.0f) ? 0.0000001f : log10(v); }); + } + + const std::unordered_map rois = _model->get_map_rois(); + + QString roi_name = _cb_roi->currentText(); + + if (rois.count(roi_name.toStdString()) > 0) + { + data_struct::ArrayXXr x_map_roi; + data_struct::ArrayXXr y_map_roi; + Map_ROI map_roi = rois.at(roi_name.toStdString()); + x_map_roi.resize(1, map_roi.pixel_list.size()); + y_map_roi.resize(1, map_roi.pixel_list.size()); + int i = 0; + for (auto& itr : map_roi.pixel_list) + { + x_map_roi(0,i) = x_map(itr.second, itr.first); + y_map_roi(0,i) = y_map(itr.second, itr.first); + i++; + } + x_map = x_map_roi; + y_map = y_map_roi; + } + float xMinVal = x_map.minCoeff(); + float yMinVal = y_map.minCoeff(); + + float xMaxVal = x_map.maxCoeff(); + float yMaxVal = y_map.maxCoeff(); + + Eigen::Array x_arr; + Eigen::Array y_arr; + x_arr.resize(x_map.cols() * x_map.rows()); + y_arr.resize(x_map.cols() * x_map.rows()); + int n = 0; + + for (int y = 0; y < x_map.rows(); y++) + { + for (int x = 0; x < x_map.cols(); x++) + { + x_arr(n) = (double)x_map(y, x); + y_arr(n) = (double)y_map(y, x); + _scatter_series->append(x_map(y,x), y_map(y,x)); + n++; + } + } + + double corr_coef = find_coefficient(x_arr, y_arr); + _lb_corr_coef->setText(QString::number(corr_coef)); + + _chart->addSeries(_scatter_series); + + _axisX->setTitleText(_cb_x_axis_element->currentText()); + _axisY->setTitleText(_cb_y_axis_element->currentText()); + _axisXLog10->setTitleText(_cb_x_axis_element->currentText()); + _axisYLog10->setTitleText(_cb_y_axis_element->currentText()); + QString sname = _cb_x_axis_element->currentText() + "/" + _cb_y_axis_element->currentText(); + + if (_display_log10) + { + _axisXLog10->setRange(xMinVal, xMaxVal); + _axisYLog10->setRange(yMinVal, yMaxVal); + } + else + { + _axisX->setRange(xMinVal, xMaxVal); + _axisY->setRange(yMinVal, yMaxVal); + } + + _scatter_series->setName(sname); + } + } + +} + +/*---------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ \ No newline at end of file diff --git a/src/mvc/ScatterPlotView.h b/src/mvc/ScatterPlotView.h new file mode 100644 index 0000000..3a4cca5 --- /dev/null +++ b/src/mvc/ScatterPlotView.h @@ -0,0 +1,113 @@ +/*----------------------------------------------------------------------------- + * Copyright (c) 2023, UChicago Argonne, LLC + * See LICENSE file. + *---------------------------------------------------------------------------*/ + +#ifndef SCATTER_PLOT_VIEW_H +#define SCATTER_PLOT_VIEW_H + +/*---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "mvc/MapsH5Model.h" +#include "mvc/ScanCorrCoefDialog.h" + + +//--------------------------------------------------------------------------- + +class ScatterPlotView : public QWidget +{ + + Q_OBJECT + +public: + + ScatterPlotView(bool display_log10, bool black_background, QWidget* parent = nullptr); + + ~ScatterPlotView(); + + void setModel(MapsH5Model* model); + + void setAnalysisType(QString curAnalysis); + + void updateMarkerSize(qreal val); + + void setLog10(int val); + + void setBlackBackground(int val); + + void setShape(QtCharts::QScatterSeries::MarkerShape shape); + + void setGridLinesVisible(int val); + + void exportPngCsv(); + + MapsH5Model* getModel() { return _model; } + + QString getAnalysisType() { return _curAnalysis; } + + void setXYAxis(QString roi_name, QString x_axis_name, QString y_axis_name); + +public slots: + + void onNameChange(QString); + +private: + + bool _getXY_Maps(data_struct::ArrayXXr& x_map, data_struct::ArrayXXr& y_map); + + void _updateNames(); + + void _updatePlot(); + + void _exportScatterPlotCSV(QString filePath); + + QtCharts::QLogValueAxis* _axisXLog10; + + QtCharts::QLogValueAxis* _axisYLog10; + + QtCharts::QValueAxis* _axisX; + + QtCharts::QValueAxis* _axisY; + + QLabel* _lb_roi; + + QComboBox* _cb_roi; + + QComboBox* _cb_x_axis_element; + + QComboBox* _cb_y_axis_element; + + QLabel* _lb_corr_coef; + + QtCharts::QChart* _chart; + + QtCharts::QChartView* _chartView; + + QtCharts::QScatterSeries* _scatter_series; + + QString _curAnalysis; + + bool _display_log10; + + MapsH5Model* _model; +}; + +//--------------------------------------------------------------------------- +/*---------------------------------------------------------------------------*/ + +#endif /* ScatterPlotView_H_ */ + +/*---------------------------------------------------------------------------*/ + diff --git a/src/mvc/ScatterPlotWidget.cpp b/src/mvc/ScatterPlotWidget.cpp index 6eeecbd..ec3c0ff 100644 --- a/src/mvc/ScatterPlotWidget.cpp +++ b/src/mvc/ScatterPlotWidget.cpp @@ -11,505 +11,9 @@ #include #include "preferences/Preferences.h" #include "stats/correlation_coefficient.h" -#include "core/GlobalThreadPool.h" - - //--------------------------------------------------------------------------- - -ScatterPlotView::ScatterPlotView(bool display_log10, bool black_background, QWidget* parent) : QWidget(parent) -{ - - _model = nullptr; - _curAnalysis = QString(STR_FIT_NNLS.c_str()); - - _axisXLog10 = new QtCharts::QLogValueAxis(); - _axisXLog10->setTitleText(""); - _axisXLog10->setLabelFormat("%.1e"); - _axisXLog10->setBase(10.0); - - _axisX = new QtCharts::QValueAxis(); - _axisX->setTitleText(""); - _axisX->setLabelFormat("%f"); - - _axisYLog10 = new QtCharts::QLogValueAxis(); - _axisYLog10->setTitleText(""); - _axisYLog10->setLabelFormat("%.1e"); - _axisYLog10->setBase(10.0); - - _axisY = new QtCharts::QValueAxis(); - _axisY->setTitleText(""); - _axisY->setLabelFormat("%f"); - - _chart = new QtCharts::QChart(); - - _lb_roi = new QLabel("ROI:"); - _lb_roi->setAlignment(Qt::AlignRight); - _cb_roi = new QComboBox(); - _cb_roi->setSizeAdjustPolicy(QComboBox::AdjustToContents); - connect(_cb_roi, qOverload(&QComboBox::currentIndexChanged), this, &ScatterPlotView::onNameChange); - _cb_x_axis_element = new QComboBox(); - _cb_x_axis_element->setSizeAdjustPolicy(QComboBox::AdjustToContents); - connect(_cb_x_axis_element, qOverload(&QComboBox::currentIndexChanged), this, &ScatterPlotView::onNameChange); - _cb_y_axis_element = new QComboBox(); - _cb_y_axis_element->setSizeAdjustPolicy(QComboBox::AdjustToContents); - connect(_cb_y_axis_element, qOverload(&QComboBox::currentIndexChanged), this, &ScatterPlotView::onNameChange); - - _chartView = new QtCharts::QChartView(_chart); - - //setRenderHint(QPainter::Antialiasing); - _scatter_series = new QtCharts::QScatterSeries(); - QString marker_shape = Preferences::inst()->getValue(STR_PFR_MARKER_SHAPE).toString(); - if (marker_shape == "Circle") - { - _scatter_series->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeCircle); - } - else - { - _scatter_series->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeRectangle); - } - _scatter_series->setMarkerSize(1.0); - _scatter_series->setUseOpenGL(true); - _chart->addSeries(_scatter_series); - _display_log10 = display_log10; - if (_display_log10) - { - _chart->addAxis(_axisXLog10, Qt::AlignBottom); - _chart->addAxis(_axisYLog10, Qt::AlignLeft); - _scatter_series->attachAxis(_axisXLog10); - _scatter_series->attachAxis(_axisYLog10); - } - else - { - _chart->addAxis(_axisX, Qt::AlignBottom); - _chart->addAxis(_axisY, Qt::AlignLeft); - _scatter_series->attachAxis(_axisX); - _scatter_series->attachAxis(_axisY); - } - - if (black_background) - { - _chart->setBackgroundBrush(QBrush(QColor("black"))); - } - - _lb_corr_coef = new QLabel(); - _lb_corr_coef->setAlignment(Qt::AlignCenter); - - QLabel* lb_xaxis = new QLabel("X Axis:"); - lb_xaxis->setAlignment(Qt::AlignRight | Qt::AlignCenter); - - QLabel* lb_yaxis = new QLabel("Y Axis:"); - lb_yaxis->setAlignment(Qt::AlignRight | Qt::AlignCenter); - - QLabel* lb_coef = new QLabel("Correlation Coefficient:"); - lb_coef->setAlignment(Qt::AlignRight | Qt::AlignCenter); - - QHBoxLayout* hbox = new QHBoxLayout(); - hbox->addWidget(_lb_roi); - hbox->addWidget(_cb_roi); - hbox->addWidget(lb_xaxis); - hbox->addWidget(_cb_x_axis_element); - hbox->addWidget(lb_yaxis); - hbox->addWidget(_cb_y_axis_element); - hbox->addWidget(lb_coef); - hbox->addWidget(_lb_corr_coef); - //hbox->addItem(new QSpacerItem(9999, 40, QSizePolicy::Maximum)); - - QVBoxLayout* vbox = new QVBoxLayout(); - vbox->addItem(hbox); - vbox->addWidget(_chartView); - - setGridLinesVisible(Preferences::inst()->getValue(STR_PRF_ScatterPlot_GridLines).toBool()); - - setLayout(vbox); - -} - -//--------------------------------------------------------------------------- - -ScatterPlotView::~ScatterPlotView() -{ - -} - -void ScatterPlotView::exportPngCsv() -{ - if (_model != nullptr) - { - QDir dir = _model->getDir(); - QFileInfo finfo(dir.absolutePath()); - - //QPixmap pixmap(rect().size()); - //render(&pixmap, QPoint(), QRegion(rect())); - - QPixmap pixmap = _chartView->grab(); - QDateTime date = QDateTime::currentDateTime(); - QString formattedTime = date.toString("yyyy.MM.dd_hh.mm.ss"); - QByteArray formattedTimeMsg = formattedTime.toLocal8Bit(); - - dir.cdUp(); - dir.cd("output"); - - QString apath = dir.absolutePath() + QDir::separator() + finfo.fileName() + QString("_scatter_" + _curAnalysis + "_" + _cb_x_axis_element->currentText() + "-" + _cb_y_axis_element->currentText() + "_" + formattedTime); - QString png_path = QDir::cleanPath(apath + ".png"); - if (false == pixmap.save(png_path, "PNG")) - { - logE << "Could not save PNG for " << png_path.toStdString() << "\n"; - } - else - { - if (false == QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath()))) - { - logE << "Failed to open dir " << dir.absolutePath().toStdString() << "\n"; - } - } - - QString csv_path = QDir::cleanPath(apath + ".csv"); - _exportScatterPlotCSV(csv_path); - - } -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::_exportScatterPlotCSV(QString filePath) -{ - if (_model != nullptr) - { - data_struct::ArrayXXr x_map; - data_struct::ArrayXXr y_map; - if (_getXY_Maps(x_map, y_map)) - { - std::ofstream out_stream(filePath.toStdString()); - if (out_stream.is_open()) - { - out_stream << "ascii information for file: " << _model->getDatasetName().toStdString() << "\n"; - out_stream << "Analysis Type: " << _curAnalysis.toStdString() << "\n"; - out_stream << "X Axis Name: " << _cb_x_axis_element->currentText().toStdString() << "\n"; - out_stream << "Y Axis Name: " << _cb_y_axis_element->currentText().toStdString() << "\n"; - out_stream << "Rows: " << x_map.rows() << "\n"; - out_stream << "Cols: " << x_map.cols() << "\n"; - out_stream << "X Index, Y Index, X Value, Y Value \n"; - for (int y = 0; y < x_map.rows(); y++) - { - for (int x = 0; x < x_map.cols(); x++) - { - out_stream << x << "," << y << "," << x_map(y, x) << "," << y_map(y, x) << "\n"; - } - } - } - else - { - logE << "Could not open for writing scatter plot CSV : " << filePath.toStdString() << "\n"; - } - out_stream.close(); - } - } -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::setShape(QtCharts::QScatterSeries::MarkerShape shape) -{ - _scatter_series->setMarkerShape(shape); - _updatePlot(); -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::setBlackBackground(int val) -{ - if (val == 0) - { - _chart->setBackgroundBrush(QBrush(QColor("white"))); - } - else - { - _chart->setBackgroundBrush(QBrush(QColor("black"))); - } -} //--------------------------------------------------------------------------- -void ScatterPlotView::setLog10(int val) -{ - - if (val == 0) - { - _display_log10 = false; - _scatter_series->detachAxis(_axisXLog10); - _scatter_series->detachAxis(_axisYLog10); - - _chart->removeAxis(_axisXLog10); - _chart->removeAxis(_axisYLog10); - - _chart->addAxis(_axisX, Qt::AlignBottom); - _chart->addAxis(_axisY, Qt::AlignLeft); - - _scatter_series->attachAxis(_axisX); - _scatter_series->attachAxis(_axisY); - } - else - { - _display_log10 = true; - _scatter_series->detachAxis(_axisX); - _scatter_series->detachAxis(_axisY); - _chart->removeAxis(_axisX); - _chart->removeAxis(_axisY); - - _chart->addAxis(_axisXLog10, Qt::AlignBottom); - _chart->addAxis(_axisYLog10, Qt::AlignLeft); - _scatter_series->attachAxis(_axisXLog10); - _scatter_series->attachAxis(_axisYLog10); - } - _updatePlot(); - -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::onNameChange(QString name) -{ - _updatePlot(); -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::setModel(MapsH5Model* model) -{ - _model = model; - _updateNames(); -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::setAnalysisType(QString name) -{ - _curAnalysis = name; - _updateNames(); -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::_updateNames() -{ - if (_model != nullptr) - { - const std::unordered_map rois = _model->get_map_rois(); - - _cb_roi->clear(); - _cb_roi->addItem(" "); - for (auto& itr : rois) - { - _cb_roi->addItem(QString(itr.first.c_str())); - } - - std::vector map_names; - _model->generateNameLists(_curAnalysis, map_names); - QString xSavedName = _cb_x_axis_element->currentText(); - QString ySavedName = _cb_y_axis_element->currentText(); - _cb_x_axis_element->clear(); - _cb_y_axis_element->clear(); - - _cb_x_axis_element->addItem(" "); - _cb_y_axis_element->addItem(" "); - for (auto& itr : map_names) - { - _cb_x_axis_element->addItem(QString(itr.c_str())); - _cb_y_axis_element->addItem(QString(itr.c_str())); - } - - int xIdx = _cb_x_axis_element->findText(xSavedName); - int yIdx = _cb_y_axis_element->findText(ySavedName); - if (xIdx > -1) - { - _cb_x_axis_element->setCurrentIndex(xIdx); - } - if (yIdx > -1) - { - _cb_y_axis_element->setCurrentIndex(yIdx); - } - } - _updatePlot(); -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::updateMarkerSize(qreal val) -{ - _scatter_series->setMarkerSize(val); - _updatePlot(); -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::setGridLinesVisible(int val) -{ - if (val == 0) - { - _axisX->setGridLineVisible(false); - _axisY->setGridLineVisible(false); - _axisXLog10->setGridLineVisible(false); - _axisYLog10->setGridLineVisible(false); - } - else - { - _axisX->setGridLineVisible(true); - _axisY->setGridLineVisible(true); - _axisXLog10->setGridLineVisible(true); - _axisYLog10->setGridLineVisible(true); - } -} - -//--------------------------------------------------------------------------- - -bool ScatterPlotView::_getXY_Maps(data_struct::ArrayXXr &x_map, data_struct::ArrayXXr &y_map) -{ - bool foundX = false; - bool foundY = false; - - std::string xName = _cb_x_axis_element->currentText().toStdString(); - std::string yName = _cb_y_axis_element->currentText().toStdString(); - - data_struct::Fit_Count_Dict fit_counts; - _model->getAnalyzedCounts(_curAnalysis.toStdString(), fit_counts); - std::map>* scalers = _model->getScalers(); - - int xCnt = fit_counts.count(xName); - if (xCnt != 0) - { - x_map = fit_counts.at(xName); - foundX = true; - } - else - { - xCnt = scalers->count(xName); - if (xCnt != 0) - { - x_map = scalers->at(xName); - foundX = true; - } - } - - - int yCnt = fit_counts.count(yName); - if (yCnt != 0) - { - y_map = fit_counts.at(yName); - foundY = true; - } - else - { - yCnt = scalers->count(yName); - if (yCnt != 0) - { - y_map = scalers->at(yName); - foundY = true; - } - } - - return foundX && foundY; -} - -//--------------------------------------------------------------------------- - -void ScatterPlotView::_updatePlot() -{ - std::string xName = _cb_x_axis_element->currentText().toStdString(); - std::string yName = _cb_y_axis_element->currentText().toStdString(); - - - if (_model != nullptr) - { - data_struct::ArrayXXr x_map; - data_struct::ArrayXXr y_map; - - if (_getXY_Maps(x_map, y_map)) - { - _chart->removeSeries(_scatter_series); - _scatter_series->clear(); - - if (_display_log10) - { - x_map = x_map.unaryExpr([](float v) { return (v <= 0.0f) ? 0.0000001f : log10(v); }); - y_map = y_map.unaryExpr([](float v) { return (v <= 0.0f) ? 0.0000001f : log10(v); }); - } - - const std::unordered_map rois = _model->get_map_rois(); - - QString roi_name = _cb_roi->currentText(); - - if (rois.count(roi_name.toStdString()) > 0) - { - data_struct::ArrayXXr x_map_roi; - data_struct::ArrayXXr y_map_roi; - Map_ROI map_roi = rois.at(roi_name.toStdString()); - x_map_roi.resize(1, map_roi.pixel_list.size()); - y_map_roi.resize(1, map_roi.pixel_list.size()); - int i = 0; - for (auto& itr : map_roi.pixel_list) - { - x_map_roi(0,i) = x_map(itr.second, itr.first); - y_map_roi(0,i) = y_map(itr.second, itr.first); - i++; - } - x_map = x_map_roi; - y_map = y_map_roi; - } - float xMinVal = x_map.minCoeff(); - float yMinVal = y_map.minCoeff(); - - float xMaxVal = x_map.maxCoeff(); - float yMaxVal = y_map.maxCoeff(); - - Eigen::Array x_arr; - Eigen::Array y_arr; - x_arr.resize(x_map.cols() * x_map.rows()); - y_arr.resize(x_map.cols() * x_map.rows()); - int n = 0; - - for (int y = 0; y < x_map.rows(); y++) - { - for (int x = 0; x < x_map.cols(); x++) - { - x_arr(n) = (double)x_map(y, x); - y_arr(n) = (double)y_map(y, x); - _scatter_series->append(x_map(y,x), y_map(y,x)); - n++; - } - } - - double corr_coef = find_coefficient(x_arr, y_arr); - _lb_corr_coef->setText(QString::number(corr_coef)); - - _chart->addSeries(_scatter_series); - - _axisX->setTitleText(_cb_x_axis_element->currentText()); - _axisY->setTitleText(_cb_y_axis_element->currentText()); - _axisXLog10->setTitleText(_cb_x_axis_element->currentText()); - _axisYLog10->setTitleText(_cb_y_axis_element->currentText()); - QString sname = _cb_x_axis_element->currentText() + "/" + _cb_y_axis_element->currentText(); - - if (_display_log10) - { - _axisXLog10->setRange(xMinVal, xMaxVal); - _axisYLog10->setRange(yMinVal, yMaxVal); - } - else - { - _axisX->setRange(xMinVal, xMaxVal); - _axisY->setRange(yMinVal, yMaxVal); - } - - _scatter_series->setName(sname); - } - } - -} - - -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ - ScatterPlotWidget::ScatterPlotWidget(QWidget* parent) : QWidget(parent) { _createLayout(); @@ -585,6 +89,7 @@ void ScatterPlotWidget::_createLayout() _options_layout = new QHBoxLayout(); + _options_layout->addWidget(_btn_scan_corr_coef); _options_layout->addWidget(_ck_display_log10); _options_layout->addWidget(_ck_display_grid_lines); _options_layout->addWidget(_ck_black_background); @@ -593,7 +98,6 @@ void ScatterPlotWidget::_createLayout() //options_layout->addWidget(_cb_shape); _options_layout->addWidget(_btn_add); _options_layout->addWidget(_btn_del); - _options_layout->addWidget(_btn_scan_corr_coef); _options_layout->addWidget(_btn_save_png); // options_layout->addItem(new QSpacerItem(9999, 40, QSizePolicy::Maximum)); @@ -743,98 +247,10 @@ void ScatterPlotWidget::onSavePng() //--------------------------------------------------------------------------- -double proc_corr_coef(MapsH5Model* model, std::string analysis_type, std::pair name_pair) -{ - data_struct::ArrayXXr x_map; - data_struct::ArrayXXr y_map; - - data_struct::Fit_Count_Dict fit_counts; - model->getAnalyzedCounts(analysis_type, fit_counts); - - x_map = fit_counts.at(name_pair.first); - y_map = fit_counts.at(name_pair.second); - - Eigen::Array x_arr; - Eigen::Array y_arr; - x_arr.resize(x_map.cols() * x_map.rows()); - y_arr.resize(x_map.cols() * x_map.rows()); - int n = 0; - - for (int y = 0; y < x_map.rows(); y++) - { - for (int x = 0; x < x_map.cols(); x++) - { - x_arr(n) = (double)x_map(y, x); - y_arr(n) = (double)y_map(y, x); - n++; - } - } - - double corr_coef = find_coefficient(x_arr, y_arr); - - return corr_coef; -} - -//--------------------------------------------------------------------------- - void ScatterPlotWidget::onScan() { - - MapsH5Model* model = _plot_view_list[0]->getModel(); - std::string analysis_type = _plot_view_list[0]->getAnalysisType().toStdString(); - if (model != nullptr) - { - std::unordered_map corr_coef_map; - std::vector count_names = model->count_names(); - std::vector> el_pair_names; - while (count_names.size() > 0) - { - int last = count_names.size() - 1; - for (int i = 0; i < last; i++) - { - el_pair_names.push_back({ count_names[last], count_names[i] }); - } - count_names.pop_back(); - } - int total = el_pair_names.size(); - emit updateProgressBar(0, total); - - std::map > job_queue; - for (int i = 0; i < el_pair_names.size(); i++) - { - job_queue[i] = Global_Thread_Pool::inst()->enqueue([this, i, model, analysis_type, el_pair_names] { return proc_corr_coef(model, analysis_type, el_pair_names[i]); }); - } - while (job_queue.size() > 0) - { - emit updateProgressBar(total - job_queue.size(), total); - QCoreApplication::processEvents(); - - std::vector to_delete; - for (auto& itr : job_queue) - { - std::future_status status = itr.second.wait_for(std::chrono::milliseconds(100)); - if (status == std::future_status::ready) - { - std::string key = el_pair_names[itr.first].first+'/'+ el_pair_names[itr.first].second; - double val = itr.second.get(); - corr_coef_map[key] = val; - if (val > 0.7 || val < -0.7) - { - logI << key << " : " << val << "\n"; - } - to_delete.push_back(itr.first); - } - } - - for (const auto& itr : to_delete) - { - job_queue.erase(itr); - } - } - emit updateProgressBar(total - job_queue.size(), total); - QCoreApplication::processEvents(); - } - + _scan_corr_coef_dialog.setModel(_plot_view_list[0]->getAnalysisType().toStdString(), _plot_view_list[0]->getModel()); + _scan_corr_coef_dialog.show(); } /*---------------------------------------------------------------------------*/ diff --git a/src/mvc/ScatterPlotWidget.h b/src/mvc/ScatterPlotWidget.h index f51cf4a..7cbb4a3 100644 --- a/src/mvc/ScatterPlotWidget.h +++ b/src/mvc/ScatterPlotWidget.h @@ -20,88 +20,10 @@ #include #include #include -#include +#include "mvc/MapsH5Model.h" +#include "mvc/ScatterPlotView.h" +#include "mvc/ScanCorrCoefDialog.h" - -//--------------------------------------------------------------------------- - -class ScatterPlotView : public QWidget -{ - - Q_OBJECT - -public: - - ScatterPlotView(bool display_log10, bool black_background, QWidget* parent = nullptr); - - ~ScatterPlotView(); - - void setModel(MapsH5Model* model); - - void setAnalysisType(QString curAnalysis); - - void updateMarkerSize(qreal val); - - void setLog10(int val); - - void setBlackBackground(int val); - - void setShape(QtCharts::QScatterSeries::MarkerShape shape); - - void setGridLinesVisible(int val); - - void exportPngCsv(); - - MapsH5Model* getModel() { return _model; } - - QString getAnalysisType() { return _curAnalysis; } - -public slots: - - void onNameChange(QString); - -private: - - bool _getXY_Maps(data_struct::ArrayXXr& x_map, data_struct::ArrayXXr& y_map); - - void _updateNames(); - - void _updatePlot(); - - void _exportScatterPlotCSV(QString filePath); - - QtCharts::QLogValueAxis* _axisXLog10; - - QtCharts::QLogValueAxis* _axisYLog10; - - QtCharts::QValueAxis* _axisX; - - QtCharts::QValueAxis* _axisY; - - QLabel* _lb_roi; - - QComboBox* _cb_roi; - - QComboBox* _cb_x_axis_element; - - QComboBox* _cb_y_axis_element; - - QLabel* _lb_corr_coef; - - QtCharts::QChart* _chart; - - QtCharts::QChartView* _chartView; - - QtCharts::QScatterSeries* _scatter_series; - - QString _curAnalysis; - - bool _display_log10; - - MapsH5Model* _model; -}; - -//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- class ScatterPlotWidget : public QWidget @@ -180,6 +102,8 @@ public slots: std::vector< ScatterPlotView*> _plot_view_list; + ScanCorrCoefDialog _scan_corr_coef_dialog; + }; From 2bd40615121b61519a02c1eab2437e4c7737d2a0 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Fri, 17 Mar 2023 12:31:13 -0500 Subject: [PATCH 3/4] Updated properties to scan corr coef dialog --- src/mvc/ScanCorrCoefDialog.cpp | 63 ++++++---------------------------- src/mvc/ScanCorrCoefDialog.h | 8 +++++ src/mvc/ScatterPlotWidget.cpp | 1 + 3 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/mvc/ScanCorrCoefDialog.cpp b/src/mvc/ScanCorrCoefDialog.cpp index b971cfb..757a132 100644 --- a/src/mvc/ScanCorrCoefDialog.cpp +++ b/src/mvc/ScanCorrCoefDialog.cpp @@ -6,7 +6,6 @@ #include #include #include "stats/correlation_coefficient.h" -//#include "core/GlobalThreadPool.h" #include "mvc/ScatterPlotView.h" //--------------------------------------------------------------------------- @@ -94,6 +93,15 @@ void ScanCorrCoefDialog::setRunEnabled(bool val) //--------------------------------------------------------------------------- +void ScanCorrCoefDialog::setViewProps(bool blog10, bool bdark, bool bgrid) +{ + _blog10 = blog10; + _bdark = bdark; + _bgrid = bgrid; +} + +//--------------------------------------------------------------------------- + void ScanCorrCoefDialog::setModel(std::string analysis_type, MapsH5Model* model) { _model = model; @@ -213,14 +221,13 @@ void ScanCorrCoefDialog::onRun() int total = el_pair_names.size(); status_callback(0, total); - ScatterPlotView* view = new ScatterPlotView(true, true, nullptr); + ScatterPlotView* view = new ScatterPlotView(_blog10, _bdark, nullptr); + view->setGridLinesVisible(_bgrid); view->setModel(_model); view->setAnalysisType(QString(_analysis_type.c_str())); int cur = 0; - //std::map > job_queue; for (int i = 0; i < el_pair_names.size(); i++) { - //job_queue[i] = Global_Thread_Pool::inst()->enqueue([this, i, restrict_coef, el_pair_names] { return proc_corr_coef(_model, _analysis_type, restrict_coef, el_pair_names[i]); }); double val = proc_corr_coef(_model, _analysis_type, restrict_coef, el_pair_names[i]); if (val > restrict_coef || val < -restrict_coef) { @@ -239,54 +246,6 @@ void ScanCorrCoefDialog::onRun() } delete view; - /* - while (job_queue.size() > 0) - { - status_callback(total - job_queue.size(), total); - QCoreApplication::processEvents(); - - std::vector to_delete; - for (auto& itr : job_queue) - { - std::future_status status = itr.second.wait_for(std::chrono::milliseconds(10)); - if (status == std::future_status::ready) - { - std::string key = el_pair_names[itr.first].first + '/' + el_pair_names[itr.first].second; - double val = 0.0; - try - { - val = itr.second.get(); - } - catch (std::exception &e) - { - logE << e.what() << "\n"; - } - //corr_coef_map[key] = val; - - if (val > restrict_coef || val < -restrict_coef) - { - //foundCnt++; - logI << key << " : " << val << "\n"; - ScatterPlotView* view = new ScatterPlotView(true, true, nullptr); - view->setModel(_model); - view->setAnalysisType(QString(_analysis_type.c_str())); - view->setXYAxis("", QString(el_pair_names[itr.first].first.c_str()), QString(el_pair_names[itr.first].second.c_str())); - view->resize(1920, 1080); - view->exportPngCsv(); - delete view; - } - to_delete.push_back(itr.first); - } - } - - for (const auto& itr : to_delete) - { - job_queue.erase(itr); - } - } - status_callback(total - job_queue.size(), total); - QCoreApplication::processEvents(); - */ } _running = false; _btn_run->setEnabled(true); diff --git a/src/mvc/ScanCorrCoefDialog.h b/src/mvc/ScanCorrCoefDialog.h index c48eb6e..5a8d8d7 100644 --- a/src/mvc/ScanCorrCoefDialog.h +++ b/src/mvc/ScanCorrCoefDialog.h @@ -50,6 +50,8 @@ class ScanCorrCoefDialog : public QWidget void status_callback(size_t cur, size_t total); + void setViewProps(bool blog10, bool bdark, bool bgrid); + void setRunEnabled(bool val); void setModel(std::string analysis_type, MapsH5Model* model); @@ -89,6 +91,12 @@ public slots: std::string _analysis_type; + bool _blog10; + + bool _bdark; + + bool _bgrid; + bool _running; }; diff --git a/src/mvc/ScatterPlotWidget.cpp b/src/mvc/ScatterPlotWidget.cpp index ec3c0ff..7ab3cbf 100644 --- a/src/mvc/ScatterPlotWidget.cpp +++ b/src/mvc/ScatterPlotWidget.cpp @@ -250,6 +250,7 @@ void ScatterPlotWidget::onSavePng() void ScatterPlotWidget::onScan() { _scan_corr_coef_dialog.setModel(_plot_view_list[0]->getAnalysisType().toStdString(), _plot_view_list[0]->getModel()); + _scan_corr_coef_dialog.setViewProps(_ck_display_log10->isChecked(), _ck_black_background->isChecked(), _ck_display_grid_lines->isChecked()); _scan_corr_coef_dialog.show(); } From 7ef95d511cf7fdde81ba67a34e427e4c6b149de3 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Fri, 17 Mar 2023 12:36:18 -0500 Subject: [PATCH 4/4] Disabled roi scatter scan for now. --- src/mvc/ScanCorrCoefDialog.cpp | 65 ++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/src/mvc/ScanCorrCoefDialog.cpp b/src/mvc/ScanCorrCoefDialog.cpp index 757a132..b215778 100644 --- a/src/mvc/ScanCorrCoefDialog.cpp +++ b/src/mvc/ScanCorrCoefDialog.cpp @@ -63,7 +63,7 @@ void ScanCorrCoefDialog::_createLayout() v_proc_layout->addItem(hbox); v_proc_layout->addWidget(_ck_use_elements); v_proc_layout->addWidget(_ck_use_scalers); - v_proc_layout->addWidget(_ck_use_rois); + //v_proc_layout->addWidget(_ck_use_rois); _processing_grp->setLayout(v_proc_layout); _processing_grp->setTitle("Scan Correlation Coefficient"); @@ -219,6 +219,13 @@ void ScanCorrCoefDialog::onRun() total_names.pop_back(); } int total = el_pair_names.size(); + /* + auto map_rois = _model->get_map_rois(); + if (_ck_use_rois->isChecked()); + { + total *= map_rois.size(); + } + */ status_callback(0, total); ScatterPlotView* view = new ScatterPlotView(_blog10, _bdark, nullptr); @@ -226,25 +233,53 @@ void ScanCorrCoefDialog::onRun() view->setModel(_model); view->setAnalysisType(QString(_analysis_type.c_str())); int cur = 0; - for (int i = 0; i < el_pair_names.size(); i++) + /* + if (use_rois) { - double val = proc_corr_coef(_model, _analysis_type, restrict_coef, el_pair_names[i]); - if (val > restrict_coef || val < -restrict_coef) + for (auto* roi_itr : map_rois) { - //logI << key << " : " << val << "\n"; - view->setXYAxis("", QString(el_pair_names[i].first.c_str()), QString(el_pair_names[i].second.c_str())); - view->resize(1920, 1080); - view->exportPngCsv(); + for (int i = 0; i < el_pair_names.size(); i++) + { + double val = proc_corr_coef(_model, _analysis_type, restrict_coef, el_pair_names[i]); + if (val > restrict_coef || val < -restrict_coef) + { + //logI << key << " : " << val << "\n"; + view->setXYAxis(QString(roi_itr.first.c_str()), QString(el_pair_names[i].first.c_str()), QString(el_pair_names[i].second.c_str())); + view->resize(1920, 1080); + view->exportPngCsv(); + } + cur++; + status_callback(cur, total); + QCoreApplication::processEvents(); + if (false == _running) + { + break; + } + } } - cur++; - status_callback(cur, total); - QCoreApplication::processEvents(); - if (false == _running) + } + else + { + */ + for (int i = 0; i < el_pair_names.size(); i++) { - break; + double val = proc_corr_coef(_model, _analysis_type, restrict_coef, el_pair_names[i]); + if (val > restrict_coef || val < -restrict_coef) + { + //logI << key << " : " << val << "\n"; + view->setXYAxis("", QString(el_pair_names[i].first.c_str()), QString(el_pair_names[i].second.c_str())); + view->resize(1920, 1080); + view->exportPngCsv(); + } + cur++; + status_callback(cur, total); + QCoreApplication::processEvents(); + if (false == _running) + { + break; + } } - } - + //} delete view; } _running = false;