diff --git a/src/gstar/ImageViewWidget.cpp b/src/gstar/ImageViewWidget.cpp index acefa5e..5eb3b2d 100644 --- a/src/gstar/ImageViewWidget.cpp +++ b/src/gstar/ImageViewWidget.cpp @@ -239,6 +239,34 @@ void ImageViewWidget::createSceneAndView(int rows, int cols) } } +//--------------------------------------------------------------------------- + +QImage ImageViewWidget::generate_img(ArrayXXr& int_img, QVector& colormap) +{ + float counts_max = int_img.maxCoeff(); + float counts_min = int_img.minCoeff(); + int width = static_cast(int_img.cols()); + int height = static_cast(int_img.rows()); + QImage image(width, height, QImage::Format_Indexed8); + image.setColorTable(colormap); + + 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 = int_img(row, col); + cnts = std::min(counts_max, cnts); + cnts = std::max(counts_min, cnts); + //convert to pixel + byte data = static_cast(((cnts - counts_min) / max_min) * 255.0); + image.setPixel(col, row, (uint)data); + } + } + return image; +} + /*---------------------------------------------------------------------------*/ void ImageViewWidget::redrawSubWindows() diff --git a/src/gstar/ImageViewWidget.h b/src/gstar/ImageViewWidget.h index e4cde65..a46db64 100644 --- a/src/gstar/ImageViewWidget.h +++ b/src/gstar/ImageViewWidget.h @@ -206,6 +206,8 @@ class ImageViewWidget void getMinMaxAt(int grid_idx, float &counts_min, float &counts_max); + QImage generate_img(ArrayXXr& int_img, QVector& colormap); + public slots: /** diff --git a/src/mvc/CoLocalizationWidget.cpp b/src/mvc/CoLocalizationWidget.cpp index 4f6c0ef..ddf01ef 100644 --- a/src/mvc/CoLocalizationWidget.cpp +++ b/src/mvc/CoLocalizationWidget.cpp @@ -10,6 +10,15 @@ CoLocalizationWidget::CoLocalizationWidget(QWidget* parent) : gstar::AbstractImageWidget(1, 1, parent) { _model = nullptr; + _first_pixmap_set = true; + int r = 0; + for (int i = 0; i < 256; ++i) + { + _red_colormap.append(qRgb(i, 0, 0)); + _green_colormap.append(qRgb(0, i, 0)); + _blue_colormap.append(qRgb(0, 0, i)); + } + setAnnotationsEnabled(false); _createLayout(); createActions(); @@ -42,12 +51,18 @@ void CoLocalizationWidget::_createLayout() m_imageViewWidget->setCountsVisible(false); _cb_red_element = new QComboBox(); - + connect(_cb_red_element, SIGNAL(currentIndexChanged(QString)), this, SLOT(onColorSelected(QString))); _cb_green_element = new QComboBox(); - + connect(_cb_green_element, SIGNAL(currentIndexChanged(QString)), this, SLOT(onColorSelected(QString))); _cb_blue_element = new QComboBox(); + connect(_cb_blue_element, SIGNAL(currentIndexChanged(QString)), this, SLOT(onColorSelected(QString))); + + _ck_quad_view = new QCheckBox("Quad View"); + // TODO: save and load from pref check value + connect(_ck_quad_view, &QCheckBox::stateChanged, this, &CoLocalizationWidget::onQuadViewChanged); QHBoxLayout* hb = new QHBoxLayout(); + hb->addStretch(); hb->addWidget(new QLabel("Red Element")); hb->addWidget(_cb_red_element); @@ -56,9 +71,12 @@ void CoLocalizationWidget::_createLayout() hb->addWidget(new QLabel("Blue Element")); hb->addWidget(_cb_blue_element); + + hb->addWidget(_ck_quad_view); + hb->addStretch(); layout->addItem(hb); - appendAnnotationTab(false); + //appendAnnotationTab(false); layout->addItem(gen_layout); //layout->addWidget(m_imageViewWidget); @@ -130,19 +148,106 @@ void CoLocalizationWidget::on_min_max_contrast_changed() } */ + +//--------------------------------------------------------------------------- + +void CoLocalizationWidget::onQuadViewChanged(int value) +{ + if (value == 0) + { + onNewGridLayout(1, 1); + } + else + { + onNewGridLayout(2, 2); + } + onColorSelected(" "); +} + +//--------------------------------------------------------------------------- + +void CoLocalizationWidget::onColorSelected(QString name) +{ + + QImage red_img; + QImage green_img; + QImage blue_img; + QImage sum_img; + + bool first = true; + + ArrayXXr int_img; + + if (_fit_counts.count(_cb_red_element->currentText().toStdString()) > 0) + { + red_img = m_imageViewWidget->generate_img(_fit_counts.at(_cb_red_element->currentText().toStdString()), _red_colormap); + sum_img = red_img.convertToFormat(QImage::Format_RGB32); + first = false; + } + if (_fit_counts.count(_cb_green_element->currentText().toStdString()) > 0) + { + green_img = m_imageViewWidget->generate_img(_fit_counts.at(_cb_green_element->currentText().toStdString()), _green_colormap); + if (first) + { + sum_img = green_img.convertToFormat(QImage::Format_RGB32); + first = false; + } + else + { + QPainter p(&sum_img); + p.setCompositionMode(QPainter::CompositionMode_Plus); + p.drawImage(0, 0, green_img.convertToFormat(QImage::Format_RGB32)); + p.end(); + } + } + if (_fit_counts.count(_cb_blue_element->currentText().toStdString()) > 0) + { + blue_img = m_imageViewWidget->generate_img(_fit_counts.at(_cb_blue_element->currentText().toStdString()), _blue_colormap); + if (first) + { + sum_img = blue_img.convertToFormat(QImage::Format_RGB32);; + first = false; + } + else + { + QPainter p(&sum_img); + p.setCompositionMode(QPainter::CompositionMode_Plus); + p.drawImage(0, 0, blue_img.convertToFormat(QImage::Format_RGB32)); + p.end(); + } + } + + if (_ck_quad_view->isChecked()) + { + m_imageViewWidget->scene(0)->setPixmap(QPixmap::fromImage(red_img.convertToFormat(QImage::Format_RGB32))); + m_imageViewWidget->scene(1)->setPixmap(QPixmap::fromImage(green_img.convertToFormat(QImage::Format_RGB32))); + m_imageViewWidget->scene(2)->setPixmap(QPixmap::fromImage(blue_img.convertToFormat(QImage::Format_RGB32))); + m_imageViewWidget->scene(3)->setPixmap(QPixmap::fromImage(sum_img.convertToFormat(QImage::Format_RGB32))); + } + else + { + m_imageViewWidget->scene(0)->setPixmap(QPixmap::fromImage(sum_img.convertToFormat(QImage::Format_RGB32))); + } + if (_first_pixmap_set) + { + m_imageViewWidget->clickFill(true); + _first_pixmap_set = false; + } +} + //--------------------------------------------------------------------------- void CoLocalizationWidget::onNewGridLayout(int rows, int cols) { - const std::vector element_view_list = m_imageViewWidget->getLabelList(); + //const std::vector element_view_list = m_imageViewWidget->getLabelList(); m_imageViewWidget->setSceneModelAndSelection(nullptr, nullptr); m_imageViewWidget->newGridLayout(rows, cols); + + m_imageViewWidget->setCoordsVisible(false); + m_imageViewWidget->setSelectorVisible(false); + m_imageViewWidget->setCountsVisible(false); //model_updated(); - m_imageViewWidget->restoreLabels(element_view_list); - redrawCounts(); - Preferences::inst()->setValue(STR_GRID_ROWS,rows); - Preferences::inst()->setValue(STR_GRID_COLS,cols); - Preferences::inst()->save(); + //m_imageViewWidget->restoreLabels(element_view_list); } //--------------------------------------------------------------------------- @@ -282,6 +387,139 @@ void CoLocalizationWidget::onSelectNormalizer(QString name) */ //--------------------------------------------------------------------------- +void CoLocalizationWidget::onSetAnalysisType(QString name) +{ + _curAnalysis = name; + + _cb_red_element->clear(); + _cb_green_element->clear(); + _cb_blue_element->clear(); + + _cb_red_element->addItem(QString(" ")); + _cb_green_element->addItem(QString(" ")); + _cb_blue_element->addItem(QString(" ")); + + if (_model != nullptr) + { + data_struct::Fit_Count_Dict fit_counts; + _model->getAnalyzedCounts(name.toStdString(), fit_counts); + std::map>* scalers = _model->getScalers(); + if (scalers != nullptr) + { + for (auto& itr : *scalers) + { + fit_counts.insert(itr); + } + } + + //copy + _fit_counts = fit_counts; + + //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); + + 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"); + + // insert in z order + for (std::string el_name : element_lines) + { + if (fit_counts.count(el_name) > 0) + { + _cb_red_element->addItem(QString(el_name.c_str())); + _cb_green_element->addItem(QString(el_name.c_str())); + _cb_blue_element->addItem(QString(el_name.c_str())); + fit_counts.erase(el_name); + } + + } + + // add end of element list that are not elements + for (auto& itr : final_counts_to_add_before_scalers) + { + if (fit_counts.count(itr) > 0) + { + _cb_red_element->addItem(QString(itr.c_str())); + _cb_green_element->addItem(QString(itr.c_str())); + _cb_blue_element->addItem(QString(itr.c_str())); + fit_counts.erase(itr); + } + } + + // add scalers in certain order + for (auto& itr : scalers_to_add_first) + { + if (fit_counts.count(itr) > 0) + { + _cb_red_element->addItem(QString(itr.c_str())); + _cb_green_element->addItem(QString(itr.c_str())); + _cb_blue_element->addItem(QString(itr.c_str())); + fit_counts.erase(itr); + } + } + + // add rest of scalers + for (auto& itr : fit_counts) + { + _cb_red_element->addItem(QString(itr.first.c_str())); + _cb_green_element->addItem(QString(itr.first.c_str())); + _cb_blue_element->addItem(QString(itr.first.c_str())); + } + } +} + +//--------------------------------------------------------------------------- + void CoLocalizationWidget::setModel(MapsH5Model* model) { if (_model != model) @@ -290,6 +528,7 @@ void CoLocalizationWidget::setModel(MapsH5Model* model) //model_updated(); if (_model != nullptr) { + onSetAnalysisType(_curAnalysis); } } } diff --git a/src/mvc/CoLocalizationWidget.h b/src/mvc/CoLocalizationWidget.h index 4a2d5ec..8f4b69b 100644 --- a/src/mvc/CoLocalizationWidget.h +++ b/src/mvc/CoLocalizationWidget.h @@ -52,6 +52,12 @@ public slots: void onNewGridLayout(int rows, int cols); + void onSetAnalysisType(QString name); + + void onColorSelected(QString); + + void onQuadViewChanged(int); + protected: /** @@ -79,6 +85,19 @@ public slots: QComboBox* _cb_blue_element; + QCheckBox* _ck_quad_view; + + QString _curAnalysis; + + data_struct::Fit_Count_Dict _fit_counts; + + QVector _red_colormap; + + QVector _green_colormap; + + QVector _blue_colormap; + + bool _first_pixmap_set; }; diff --git a/src/mvc/ImageSegROIDialog.cpp b/src/mvc/ImageSegROIDialog.cpp index 995b635..fbc3f76 100644 --- a/src/mvc/ImageSegROIDialog.cpp +++ b/src/mvc/ImageSegROIDialog.cpp @@ -632,34 +632,6 @@ bool ImageSegRoiDialog::_get_img(ArrayXXr &int_img, bool normalize) return !first; } -//--------------------------------------------------------------------------- - -QImage ImageSegRoiDialog::_generate_img(ArrayXXr& int_img) -{ - float counts_max = int_img.maxCoeff(); - float counts_min = int_img.minCoeff(); - int width = static_cast(int_img.cols()); - int height = static_cast(int_img.rows()); - QImage image(width, height, QImage::Format_Indexed8); - image.setColorTable(*_selected_colormap); - - 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 = int_img(row, col); - cnts = std::min(counts_max, cnts); - cnts = std::max(counts_min, cnts); - //convert to pixel - byte data = static_cast(((cnts - counts_min) / max_min) * 255.0); - image.setPixel(col, row, (uint)data); - } - } - return image; -} - //--------------------------------------------------------------------------- /* std::vector ImageSegRoiDialog::_generate_images(int num_images, cv::Mat& mat) @@ -743,9 +715,7 @@ void ImageSegRoiDialog::onImgSelection(QStandardItem* item) if (is_checked) { - QImage image = _generate_img(int_img); - - _int_img_widget->setPixMap(QPixmap::fromImage(image.convertToFormat(QImage::Format_RGB32))); + _int_img_widget->setImageFromArray(int_img, *_selected_colormap); } else if (false == _image_size.isEmpty()) { diff --git a/src/mvc/ImageSegROIDialog.h b/src/mvc/ImageSegROIDialog.h index d0a7805..b2b3647 100644 --- a/src/mvc/ImageSegROIDialog.h +++ b/src/mvc/ImageSegROIDialog.h @@ -86,8 +86,6 @@ private slots: bool _get_img(ArrayXXr& int_img, bool normalize); - QImage _generate_img(ArrayXXr& int_img); - //std::vector _generate_images(int num_images, cv::Mat& mat); //QImage _generate_sum_image(cv::Mat& mat, ArrayXXr& bg_img, uchar alpha=127); diff --git a/src/mvc/ImageSegWidget.cpp b/src/mvc/ImageSegWidget.cpp index ff35b1b..06eb7ad 100644 --- a/src/mvc/ImageSegWidget.cpp +++ b/src/mvc/ImageSegWidget.cpp @@ -42,6 +42,14 @@ void ImageSegWidget::createLayout() //--------------------------------------------------------------------------- +void ImageSegWidget::setImageFromArray(ArrayXXr& img_arr, QVector& colormap) +{ + QImage image = m_imageViewWidget->generate_img(img_arr, colormap); + setPixMap(QPixmap::fromImage(image.convertToFormat(QImage::Format_RGB32))); +} + +//--------------------------------------------------------------------------- + void ImageSegWidget::setPixMap(QPixmap pix) { m_imageViewWidget->scene(0)->setPixmap(pix); diff --git a/src/mvc/ImageSegWidget.h b/src/mvc/ImageSegWidget.h index 1ed4608..b595aa7 100644 --- a/src/mvc/ImageSegWidget.h +++ b/src/mvc/ImageSegWidget.h @@ -42,6 +42,8 @@ class ImageSegWidget void setPixMap(QPixmap pix); + void setImageFromArray(ArrayXXr& img_arr, QVector& colormap); + void clearAllRoiMasks(); void addRoiMask(gstar::RoiMaskGraphicsItem* roi); diff --git a/src/mvc/MapsElementsWidget.cpp b/src/mvc/MapsElementsWidget.cpp index 7072c57..d2a626a 100644 --- a/src/mvc/MapsElementsWidget.cpp +++ b/src/mvc/MapsElementsWidget.cpp @@ -117,7 +117,7 @@ void MapsElementsWidget::_createLayout(bool create_image_nav) _dataset_name = new QLabel(); hbox2->addWidget(new QLabel("Dataset: ")); hbox2->addWidget(_dataset_directory); - hbox2->addWidget(_dataset_name); + //hbox2->addWidget(_dataset_name); hbox2->addItem(new QSpacerItem(9999, 40, QSizePolicy::Maximum)); QSplitter* splitter = new QSplitter(); @@ -567,6 +567,7 @@ void MapsElementsWidget::displayContextMenu(QWidget* parent, void MapsElementsWidget::onAnalysisSelect(QString name) { _calib_curve = _model->get_calibration_curve(name.toStdString(), _cb_normalize->currentText().toStdString()); + _co_loc_widget->onSetAnalysisType(name); redrawCounts(); } @@ -743,6 +744,10 @@ void MapsElementsWidget::setModel(MapsH5Model* model) insertAndSelectAnnotation(m_roiTreeModel, m_roiTreeView, m_roiSelectionModel, roi); _spectra_widget->appendROISpectra(itr.first, (ArrayDr*)&(itr.second.int_spec), itr.second.color); } + + _co_loc_widget->onSetAnalysisType(_cb_analysis->currentText()); + _co_loc_widget->setModel(_model); + annoTabChanged(m_tabWidget->currentIndex()); } m_imageWidgetToolBar->clickFill();