Skip to content

Commit

Permalink
Merge pull request #56 from aglowacki/master
Browse files Browse the repository at this point in the history
Added colocalization widget
  • Loading branch information
Arthur Glowacki authored Mar 7, 2023
2 parents ae2adbc + d0ba235 commit 42fabce
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 354 deletions.
53 changes: 25 additions & 28 deletions src/gstar/AbstractImageWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ using namespace gstar;
AbstractImageWidget::AbstractImageWidget(int rows, int cols, QWidget* parent)
: QWidget(parent)
{

// Background
m_treeModel = nullptr;
m_annotationToolbar = nullptr;
m_coordinateModel = nullptr;
m_imageWidgetToolBar = nullptr;
m_range = nullptr;
m_imageWidthDim = nullptr;
m_imageHeightDim = nullptr;
m_tabWidget = new QTabWidget(this);
//m_tabWidget->setPalette(pal);
//m_tabWidget->setAutoFillBackground(true);
//m_tabWidget->addTab(layoutWidget, QIcon(), "Annotations");
//QPalette pal = this->palette();
//pal.setColor(this->backgroundRole(), Qt::white);
//this->setPalette(pal);
Expand Down Expand Up @@ -82,16 +86,10 @@ AbstractImageWidget::AbstractImageWidget(int rows, int cols, QWidget* parent)

createAnnotationToolBar();

m_tabWidget = new QTabWidget();
//m_tabWidget->setPalette(pal);
//m_tabWidget->setAutoFillBackground(true);

m_annotationsEnabled = true;
//add it in parent class so you can control what tab it is on.
//m_tabWidget->addTab(layoutWidget, QIcon(), "Annotations");

//m_lblPixelXCoordinate = nullptr;

//m_lblPixelXCoordinate = nullptr;
}

/*---------------------------------------------------------------------------*/
Expand All @@ -100,13 +98,14 @@ AbstractImageWidget::~AbstractImageWidget()
{

m_imageViewWidget->setSceneSelectionModel(nullptr);

if(m_treeModel != nullptr)
{
delete m_treeModel;
m_treeModel = nullptr;
}

if(m_treeModel != nullptr)
{
delete m_treeModel;
m_treeModel = nullptr;
}

/*
if(m_annotationToolbar != nullptr)
{
delete m_annotationToolbar;
Expand All @@ -118,7 +117,7 @@ AbstractImageWidget::~AbstractImageWidget()
delete m_imageWidgetToolBar;
m_imageWidgetToolBar = nullptr;
}

*/
}

/*---------------------------------------------------------------------------*/
Expand All @@ -145,21 +144,19 @@ void AbstractImageWidget::addRuler()

void AbstractImageWidget::appendAnnotationTab(bool bToolbar)
{
QVBoxLayout* infoLayout = new QVBoxLayout();
if (bToolbar)
{
infoLayout->addWidget(m_annotationToolbar->getToolBar());
}
infoLayout->addWidget(m_annoTreeView);

QVBoxLayout* infoLayout = new QVBoxLayout();
if (bToolbar)
{
infoLayout->addWidget(m_annotationToolbar->getToolBar());
}
infoLayout->addWidget(m_annoTreeView);

m_treeTabWidget = new QWidget(this);
//m_treeTabWidget->setPalette(pal);
//m_treeTabWidget->setAutoFillBackground(true);
m_treeTabWidget->setLayout(infoLayout);

m_tabWidget->addTab(m_treeTabWidget, QIcon(), "Annotations");
m_treeTabWidget = new QWidget(this);
//m_treeTabWidget->setPalette(pal);
//m_treeTabWidget->setAutoFillBackground(true);
m_treeTabWidget->setLayout(infoLayout);

m_tabWidget->addTab(m_treeTabWidget, QIcon(), "Annotations");
}

/*---------------------------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion src/gstar/AbstractImageWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AbstractImageWidget
/**
* Destructor.
*/
~AbstractImageWidget();
virtual ~AbstractImageWidget();

/**
* @brief appendTab
Expand Down
28 changes: 28 additions & 0 deletions src/gstar/ImageViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,34 @@ void ImageViewWidget::createSceneAndView(int rows, int cols)
}
}

//---------------------------------------------------------------------------

QImage ImageViewWidget::generate_img(ArrayXXr<float>& int_img, QVector<QRgb>& colormap)
{
float counts_max = int_img.maxCoeff();
float counts_min = int_img.minCoeff();
int width = static_cast<int>(int_img.cols());
int height = static_cast<int>(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<byte>(((cnts - counts_min) / max_min) * 255.0);
image.setPixel(col, row, (uint)data);
}
}
return image;
}

/*---------------------------------------------------------------------------*/

void ImageViewWidget::redrawSubWindows()
Expand Down
2 changes: 2 additions & 0 deletions src/gstar/ImageViewWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class ImageViewWidget

void getMinMaxAt(int grid_idx, float &counts_min, float &counts_max);

QImage generate_img(ArrayXXr<float>& int_img, QVector<QRgb>& colormap);

public slots:

/**
Expand Down
147 changes: 7 additions & 140 deletions src/mvc/BatchRoiFitWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
BatchRoiFitWidget::BatchRoiFitWidget(std::string directory, QWidget *parent) : QWidget(parent)
{

_cur_file = 0;
_cur_block = 0;
_total_blocks = 0;
_directory = directory;
if (_directory[directory.length() - 1] != DIR_END_CHAR)
{
Expand Down Expand Up @@ -49,39 +46,9 @@ void BatchRoiFitWidget::createLayout()
connect(_btn_run, &QPushButton::released, this, &BatchRoiFitWidget::runProcessing);
_btn_cancel = new QPushButton("Cancel");
connect(_btn_cancel, &QPushButton::released, this, &BatchRoiFitWidget::close);
/*
_processing_grp = new QGroupBox();
QVBoxLayout* v_proc_layout = new QVBoxLayout();
_proc_roi = new QCheckBox("Region of Interest Analysis");
_proc_nnls = new QCheckBox("Non-Negative Least Squares Analysis");
_proc_matrix = new QCheckBox("Per Pixel Matrix Analysis");

v_proc_layout->addWidget(_proc_roi);
v_proc_layout->addWidget(_proc_nnls);
v_proc_layout->addWidget(_proc_matrix);
_processing_grp->setLayout(v_proc_layout);
_processing_grp->setTitle("Processing Options");
_saving_grp = new QGroupBox();
QVBoxLayout* v_save_layout = new QVBoxLayout();
_save_avg = new QCheckBox("Generate Avg H5");
_save_v9 = new QCheckBox("Add v9 soft links");
_save_exchange = new QCheckBox("Add Exchange format");
_save_csv = new QCheckBox("Save CSV of integrated fits");
_perform_quantification = new QCheckBox("Perform Quantification (maps_standardinfo.txt)");
*/
_le_detectors = new QLineEdit("0,1,2,3,4,5,6");
/*
v_save_layout->addWidget(_save_avg);
v_save_layout->addWidget(_save_v9);
v_save_layout->addWidget(_save_exchange);
v_save_layout->addWidget(_save_csv);
v_save_layout->addWidget(_perform_quantification);
_saving_grp->setLayout(v_save_layout);
_saving_grp->setTitle("Export Options");
*/

_file_list_model = new QStandardItemModel();
_file_list_view = new QListView();
_file_list_view->setModel(_file_list_model);
Expand All @@ -90,11 +57,7 @@ void BatchRoiFitWidget::createLayout()
QHBoxLayout* buttonlayout = new QHBoxLayout();
buttonlayout->addWidget(_btn_run);
buttonlayout->addWidget(_btn_cancel);
/*
_proc_save_layout = new QHBoxLayout();
_proc_save_layout->addWidget(_processing_grp);
_proc_save_layout->addWidget(_saving_grp);
*/

QHBoxLayout* hbox_progresss_blocks = new QHBoxLayout();
hbox_progresss_blocks->addWidget(new QLabel("Current Fitting:"));
hbox_progresss_blocks->addWidget(_progressBarBlocks);
Expand Down Expand Up @@ -152,8 +115,6 @@ void BatchRoiFitWidget::updateFileList(std::unordered_map<QString, QFileInfo> ro
void BatchRoiFitWidget::runProcessing()
{
_btn_run->setEnabled(false);
// _processing_grp->setEnabled(false);
// _saving_grp->setEnabled(false);
_le_detectors->setEnabled(false);
_file_list_view->setEnabled(false);

Expand All @@ -162,20 +123,7 @@ void BatchRoiFitWidget::runProcessing()
data_struct::Analysis_Job<double> analysis_job;
analysis_job.dataset_directory = _directory;

/*
if (_proc_roi->isChecked())
{
analysis_job.fitting_routines.push_back(data_struct::Fitting_Routines::ROI);
}
if (_proc_nnls->isChecked())
{
analysis_job.fitting_routines.push_back(data_struct::Fitting_Routines::NNLS);
}
if (_proc_matrix->isChecked())
{
analysis_job.fitting_routines.push_back(data_struct::Fitting_Routines::GAUSS_MATRIX);
}
*/

QString dstring = _le_detectors->text();
if (dstring.length() > 0)
{
Expand Down Expand Up @@ -224,28 +172,7 @@ void BatchRoiFitWidget::runProcessing()
return;
}

/*
QModelIndex parent = QModelIndex();
for (int r = 0; r < _file_list_model->rowCount(parent); ++r)
{
QModelIndex index = _file_list_model->index(r, 0, parent);
QVariant name = _file_list_model->data(index);
analysis_job.dataset_files.push_back(name.toString().toStdString());
}
size_t total_file_range = 0;
if (analysis_job.quick_and_dirty == true)
{
total_file_range = (analysis_job.fitting_routines.size() * analysis_job.dataset_files.size());
}
else
{
total_file_range = (analysis_job.fitting_routines.size() * analysis_job.dataset_files.size() * analysis_job.detector_num_arr.size());
}
_progressBarFiles->setRange(0, total_file_range);
*/

if (io::file::init_analysis_job_detectors(&analysis_job))
{
_progressBarBlocks->setRange(0, _roi_map.size());
Expand All @@ -261,76 +188,16 @@ void BatchRoiFitWidget::runProcessing()
}
_progressBarFiles->setValue(i);
QCoreApplication::processEvents();
/*
/io::file::File_Scan::inst()->populate_netcdf_hdf5_files(_directory);
Callback_Func_Status_Def cb_func = std::bind(&BatchRoiFitWidget::status_callback, this, std::placeholders::_1, std::placeholders::_2);
//std::function<void(const Fit_Parameters* const, const Range* const, Spectra*)> cb_func = std::bind(&BatchRoiFitWidget::model_spectrum, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
if (_perform_quantification->isChecked())
{
analysis_job.quantification_standard_filename = "maps_standardinfo.txt";
perform_quantification(&analysis_job, true);
}
process_dataset_files(&analysis_job, &cb_func);
//QCoreApplication::processEvents();
_progressBarFiles->setValue(_roi_map.size());
_progressBarBlocks->setValue(_total_blocks);
QCoreApplication::processEvents();
*/
}
/*
if (_save_avg->isChecked())
{
analysis_job.generate_average_h5 = true;
}
//add v9 layout soft links
if (_save_v9->isChecked())
{
analysis_job.add_v9_layout = true;
}
//add exchange
if (_save_exchange->isChecked())
{
analysis_job.add_exchange_layout = true;

}

//export csv
if (_save_csv->isChecked())
{
analysis_job.export_int_fitted_to_csv = true;
}
iterate_datasets_and_update(analysis_job);
*/


_btn_run->setEnabled(true);
// _processing_grp->setEnabled(true);
// _saving_grp->setEnabled(true);
_le_detectors->setEnabled(true);
_file_list_view->setEnabled(true);
_btn_cancel->setText("Close");
emit processed_list_update(_file_list);
}

void BatchRoiFitWidget::status_callback(size_t cur_block, size_t total_blocks)
{
if (_total_blocks != total_blocks)
{
_total_blocks = total_blocks;
_progressBarBlocks->setRange(0, _total_blocks);
}
}

_cur_block = cur_block;
if (_cur_block == 0)
{
_cur_file++;
_progressBarFiles->setValue(_cur_file-1);
}
_progressBarBlocks->setValue(_cur_block);

QCoreApplication::processEvents();
}
/*---------------------------------------------------------------------------*/
Loading

0 comments on commit 42fabce

Please sign in to comment.