Skip to content

Commit

Permalink
Merge pull request #77 from aglowacki/master
Browse files Browse the repository at this point in the history
Changed loading tiffs to fix exception and lockup in thread
  • Loading branch information
aglowacki authored Mar 1, 2024
2 parents 4efb3b7 + fafe109 commit b646b47
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/mvc/FittingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FittingDialog::FittingDialog(QWidget *parent) : QDialog(parent)
_elements_to_fit = nullptr;
_param_fit_routine.set_update_coherent_amplitude_on_fit(false);
_hybrid_fit_routine.set_update_coherent_amplitude_on_fit(false);
////_model.set_num_threads(std::thread::hardware_concurrency());
_createLayout();
}

Expand Down
43 changes: 33 additions & 10 deletions src/mvc/MapsWorkspaceFilesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,48 @@ void MapsWorkspaceFilesWidget::onOpenModel(const QStringList& names_list, MODEL_
}
else if (mt == MODEL_TYPE::VLM)
{
std::future< VLM_Model*> ret = Global_Thread_Pool::inst()->enqueue([this, name] { return _model->get_VLM_Model(name); });
std::future_status status;
do
{
status = ret.wait_for(std::chrono::milliseconds(100));
QCoreApplication::processEvents();
} while (status != std::future_status::ready);

VLM_Model* Model = ret.get();
VLM_Model* Model = _model->get_VLM_Model(name);

if (Model != nullptr)
{
load_status = LOADED;
Model->getImage();
emit loaded_model(name, mt);
}
else
{
load_status = FAILED_LOADING;
}
emit loaded_model(name, mt);
QCoreApplication::processEvents();
/*
std::future< VLM_Model*> ret = Global_Thread_Pool::inst()->enqueue([this, name] { return _model->get_VLM_Model(name); });
std::future_status status;
int cntr = 0;
do
{
status = ret.wait_for(std::chrono::milliseconds(100));
QCoreApplication::processEvents();
cntr++;
if (cntr > 1200)
{
load_status = FAILED_LOADING;
break;
}
} while (status != std::future_status::ready);
if (load_status == UNLOADED)
{
VLM_Model* Model = ret.get();
if (Model != nullptr)
{
load_status = LOADED;
Model->getImage();
emit loaded_model(name, mt);
}
else
{
load_status = FAILED_LOADING;
}
}*/
_vlm_tab_widget->loaded_file_status_changed(load_status, name);
}

Expand Down
34 changes: 32 additions & 2 deletions src/mvc/TIFF_Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,39 @@ bool TIFF_Model::load(QString filepath)
double range = maxVal - minVal;

_img = QImage(mat.cols, mat.rows, QImage::Format_ARGB32);
float val = 0.f;
for (int w = 0; w < mat.cols; w++)
{
for (int h = 0; h < mat.rows; h++)
{
float val = mat.at<float>(h, w);
uchar depth = mat.type() & CV_MAT_DEPTH_MASK;
switch (depth) {
case CV_8U:
val = (float)mat.at<unsigned char>(h, w);
break;
case CV_8S:
val = (float)mat.at<char>(h, w);
break;
case CV_16U:
val = (float)mat.at<unsigned short>(h, w);
break;
case CV_16S:
val = (float)mat.at<short>(h, w);
break;
case CV_32S:
val = (float)mat.at<int>(h, w);
break;
case CV_32F:
val = (float)mat.at<float>(h, w);
break;
case CV_64F:
val = (float)mat.at<double>(h, w);
break;
default:
val = 0.f;
break;
}
//float val = mat.at<float>(h, w);
_pixel_values(h, w) = val;
val = (val - minVal) / range;
int c = val * 255;
Expand All @@ -87,10 +115,12 @@ bool TIFF_Model::load(QString filepath)
}
catch (std::string& s)
{
logE << s << "\n";
return false;
}
catch (...)
catch (std::exception e)
{
logE << e.what() << "\n";
return false;
}

Expand Down

0 comments on commit b646b47

Please sign in to comment.