Skip to content

Commit

Permalink
Merge pull request #50 from aglowacki/master
Browse files Browse the repository at this point in the history
multiple bug fixes
  • Loading branch information
Arthur Glowacki authored Jul 29, 2022
2 parents 69b441e + c5880b5 commit bc4f7ab
Show file tree
Hide file tree
Showing 42 changed files with 1,346 additions and 545 deletions.
42 changes: 21 additions & 21 deletions src/core/PythonLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ PythonLoader::PythonLoader()
PythonLoader::~PythonLoader()
{

logW<<"PythonLoader::~PythonLoader() \n\r";
logI<<"PythonLoader::~PythonLoader() \n\r";

if(m_foundFuncs)
{
Expand Down Expand Up @@ -151,7 +151,7 @@ void PythonLoader::callFunc(QString module,
else
{
PyErr_Print();
logW<<"Error PythonLoader::callFunc; returned wrong list size.";
logE<<"Error PythonLoader::callFunc; returned wrong list size.";
throw pyException(pyException::RETURN_WRONG_LIST_SIZE);
}
}
Expand Down Expand Up @@ -189,7 +189,7 @@ void PythonLoader::callFunc(QString module,
}
else
{
logW<<"Error PythonLoader::callFunc; returned wrong list size.";
logE<<"Error PythonLoader::callFunc; returned wrong list size.";
throw pyException(pyException::RETURN_WRONG_LIST_SIZE);
}
}
Expand Down Expand Up @@ -311,11 +311,11 @@ bool PythonLoader::init(QString sharedLibName)

if(false == sharedLibName.isEmpty())
{
logW<<"Searching for python library: "<<sharedLibName.toStdString()<<"\n";
logI<<"Searching for python library: "<<sharedLibName.toStdString()<<"\n";
myLib.setFileName(sharedLibName);
if(myLib.load())
{
logW<<"Found python library: "<<sharedLibName.toStdString() << "\n";
logI<<"Found python library: "<<sharedLibName.toStdString() << "\n";
foundLib = true;
}
}
Expand All @@ -325,7 +325,7 @@ bool PythonLoader::init(QString sharedLibName)
myLib.setFileName(itr);
if(myLib.load())
{
logW<<itr.toStdString() << "\n";
logI<<itr.toStdString() << "\n";
foundLib = true;
break;
}
Expand Down Expand Up @@ -484,7 +484,7 @@ bool PythonLoader::init(QString sharedLibName)



logW<<"All required python functions found.";
logI<<"All required python functions found.";
Py_Initialize();
m_foundFuncs = true;

Expand Down Expand Up @@ -513,40 +513,40 @@ bool PythonLoader::loadFunction(QString path,
sys_path = PySys_GetObject("path");
if (sys_path == nullptr)
return false;
logW<<"Python path object found."<<endl;
logI<<"Python path object found."<<endl;

int pyPathSize = PyList_Size(sys_path);
for (int ia=0; ia<pyPathSize; ia++)
{
PyObject *obj = PyList_GetItem(sys_path, ia);
QString QPyPath = QString(PyString_AsString(obj));
//Py_DecRef(obj);
logW<<"Python path = "<<QPyPath.toStdString() << "\n";
logI<<"Python path = "<<QPyPath.toStdString() << "\n";
}

pyPath = PyString_FromString(path.toStdString().c_str());
if (pyPath == nullptr)
return false;

logW<<"appending to python path: "<<path.toStdString() << "\n";
logI<<"appending to python path: "<<path.toStdString() << "\n";
if (PyList_Append(sys_path, pyPath) < 0)
throw pyException(pyException::COULD_NOT_APPEND_PATH_TO_PYPATH);
logW<<"Path appended";
logI<<"Path appended";

Py_DecRef(pyPath);
//Py_DecRef(sys_path);

logW<<"modulename "<<moduleName.toStdString() << "\n";
logI<<"modulename "<<moduleName.toStdString() << "\n";

PyObject *pyName = PyString_FromString(moduleName.toStdString().c_str());
if(pyName)
logW<<"pName init";
logI<<"pName init";
pyModule = PyImport_Import(pyName);
Py_DecRef(pyName);
}
else
{
logW<<"Reloaded python function ! " <<moduleName.toStdString()<<" "<<functionnName.toStdString() << "\n";
logI<<"Reloaded python function ! " <<moduleName.toStdString()<<" "<<functionnName.toStdString() << "\n";
pyFunc* pf = m_functionMap[pfKey];
if (pf != nullptr)
{
Expand All @@ -571,22 +571,22 @@ bool PythonLoader::loadFunction(QString path,
}
else
{
logW<<"Error: nullptr python module while reloading ! " <<moduleName.toStdString()<<" "<<functionnName.toStdString() << "\n";
logE<<"Error: nullptr python module while reloading ! " <<moduleName.toStdString()<<" "<<functionnName.toStdString() << "\n";
m_functionMap.remove(pfKey);
return false;
}
}
if (pyModule != nullptr)
{
logW<<"Module found";
logI<<"Module found";
pyFunc* pf = new pyFunc();
pf->pModule = pyModule;

pf->pFunc = PyObject_GetAttrString(pyModule,
functionnName.toStdString().c_str());
if (pf->pFunc && PyCallable_Check(pf->pFunc))
{
logW<<"function found and callable, adding: "<<moduleName.toStdString()<<" "<<functionnName.toStdString() << "\n";
logI<<"function found and callable, adding: "<<moduleName.toStdString()<<" "<<functionnName.toStdString() << "\n";
pf->pDict = PyDict_New();
//Py_IncRef(m_pDict);
//Py_IncRef(m_pArgs);
Expand Down Expand Up @@ -633,17 +633,17 @@ QStringList PythonLoader::getFunctionList(QString path, QString moduleName)
sys_path = PySys_GetObject("path");
if (sys_path == nullptr)
return funcList;
logW<<"Python path object found.";
logI<<"Python path object found.";

pyPath = PyString_FromString(path.toStdString().c_str());
if (pyPath == nullptr)
return funcList;


logW<<"appending to python path: "<<path.toStdString() << "\n";
logI<<"appending to python path: "<<path.toStdString() << "\n";
if (PyList_Append(sys_path, pyPath) < 0)
return funcList;
logW<<"Path appended";
logI<<"Path appended";

Py_DecRef(pyPath);

Expand Down Expand Up @@ -676,7 +676,7 @@ QStringList PythonLoader::getFunctionList(QString path, QString moduleName)
long lsize = PyList_Size(pRetVal);
if(lsize > 0)
{
logW<<"ret size = "<<lsize;
logI<<"ret size = "<<lsize;
for(int i=0; i<lsize; i++)
{
PyObject* funcTup = PyList_GetItem(pRetVal, i);
Expand Down
2 changes: 1 addition & 1 deletion src/core/PythonRegionCaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool PythonRegionCaller::CallFunc(QString name,
catch(PythonLoader::pyException ex)
{
//QMessageBox::critical(0, "Error", ex.what());
logW<<ex.what();
logE<<ex.what();
return false;
}

Expand Down
15 changes: 9 additions & 6 deletions src/gstar/ContrastDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ void ContrastDialog::set_array(const data_struct::ArrayXXr<float>* arr)
_min_max_slider->setMinMax(_arr->minCoeff(), _arr->maxCoeff());

data_struct::ArrayTr<float> pts;
int w = arr->rows();
int h = arr->cols();
pts.resize(w * h);
for (int i = 0; i < w; i++)
int h = arr->rows();
int w = arr->cols();
int t = arr->size();
pts.resize(t);
int s = 0;
for (int i = 0; i < h; i++)
{
for (int j = 0; j < h; j++)
for (int j = 0; j < w; j++)
{
pts((i * w) + j) = ((*arr)(i, j));
pts(s) = ((*arr)(i, j));
s++;
}
}
_historgram->updatePoints(pts);
Expand Down
83 changes: 56 additions & 27 deletions src/gstar/CoordinateWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using namespace gstar;
/*---------------------------------------------------------------------------*/

CoordinateWidget::CoordinateWidget(QWidget* parent)
CoordinateWidget::CoordinateWidget(bool vertical, QWidget* parent)
: QWidget(parent)
{

Expand All @@ -17,45 +17,74 @@ CoordinateWidget::CoordinateWidget(QWidget* parent)
m_lblPixelYCoordinate = nullptr;

m_lblXUnits = new QLabel("");
m_lblXUnits->setMinimumWidth(40);
// m_lblXUnits->setMinimumWidth(40);

m_lblYUnits = new QLabel("");
m_lblYUnits->setMinimumWidth(40);
// m_lblYUnits->setMinimumWidth(40);

m_lblZUnits = new QLabel("");
m_lblZUnits->setMinimumWidth(40);
// m_lblZUnits->setMinimumWidth(40);

//Add status bar underneath
m_lblPixelXCoordinate = new QLabel(tr("0"));
m_lblPixelXCoordinate->setMinimumWidth(70);
m_lblPixelXCoordinate->setMinimumWidth(50);
m_lblPixelYCoordinate = new QLabel(tr("0"));
m_lblPixelYCoordinate->setMinimumWidth(70);
m_lblPixelYCoordinate->setMinimumWidth(50);
m_lblPixelZCoordinate = new QLabel(tr("0"));
m_lblPixelZCoordinate->setMinimumWidth(70);
m_lblPixelZCoordinate->setMinimumWidth(50);

m_lblPixelXLabel = new QLabel(" X Coordinate :");
m_lblPixelXLabel->setMinimumWidth(40);
// m_lblPixelXLabel->setMinimumWidth(40);
m_lblPixelYLabel = new QLabel(" Y Coordinate :");
m_lblPixelYLabel->setMinimumWidth(40);
// m_lblPixelYLabel->setMinimumWidth(40);
m_lblPixelZLabel = new QLabel(" Z Coordinate :");
m_lblPixelZLabel->setMinimumWidth(40);

QHBoxLayout* coordHlayout = new QHBoxLayout();
coordHlayout->addWidget( m_lblPixelXLabel );
coordHlayout->addWidget( m_lblPixelXCoordinate );
coordHlayout->addWidget( m_lblXUnits );
coordHlayout->addWidget( m_lblPixelYLabel );
coordHlayout->addWidget( m_lblPixelYCoordinate );
coordHlayout->addWidget( m_lblYUnits );
coordHlayout->addWidget( m_lblPixelZLabel );
coordHlayout->addWidget( m_lblPixelZCoordinate );
coordHlayout->addWidget( m_lblZUnits );
coordHlayout->addStretch(1);

coordHlayout->setContentsMargins(QMargins(0,0,0,0));

setLayout(coordHlayout);

// m_lblPixelZLabel->setMinimumWidth(40);
if (false == vertical)
{
QHBoxLayout* coordHlayout = new QHBoxLayout();
coordHlayout->addWidget(m_lblPixelXLabel);
coordHlayout->addWidget(m_lblPixelXCoordinate);
coordHlayout->addWidget(m_lblXUnits);
coordHlayout->addWidget(m_lblPixelYLabel);
coordHlayout->addWidget(m_lblPixelYCoordinate);
coordHlayout->addWidget(m_lblYUnits);
coordHlayout->addWidget(m_lblPixelZLabel);
coordHlayout->addWidget(m_lblPixelZCoordinate);
coordHlayout->addWidget(m_lblZUnits);
coordHlayout->addStretch(1);

coordHlayout->setContentsMargins(QMargins(0, 0, 0, 0));

setLayout(coordHlayout);
}
else
{
QVBoxLayout* coordVlayout = new QVBoxLayout();
QHBoxLayout* coordHlayout1 = new QHBoxLayout();
coordHlayout1->addWidget(m_lblPixelXLabel);
coordHlayout1->addWidget(m_lblPixelXCoordinate);
coordHlayout1->addWidget(m_lblXUnits);
coordHlayout1->addStretch(1);
QHBoxLayout* coordHlayout2 = new QHBoxLayout();
coordHlayout2->addWidget(m_lblPixelYLabel);
coordHlayout2->addWidget(m_lblPixelYCoordinate);
coordHlayout2->addWidget(m_lblYUnits);
coordHlayout2->addStretch(1);
QHBoxLayout* coordHlayout3 = new QHBoxLayout();
coordHlayout3->addWidget(m_lblPixelZLabel);
coordHlayout3->addWidget(m_lblPixelZCoordinate);
coordHlayout3->addWidget(m_lblZUnits);
coordHlayout3->addStretch(1);

coordHlayout1->setContentsMargins(QMargins(0, 0, 0, 0));
coordHlayout2->setContentsMargins(QMargins(0, 0, 0, 0));
coordHlayout3->setContentsMargins(QMargins(0, 0, 0, 0));

coordVlayout->addItem(coordHlayout1);
coordVlayout->addItem(coordHlayout2);
coordVlayout->addItem(coordHlayout3);
setLayout(coordVlayout);
}
// m_decimalPreci = 2;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gstar/CoordinateWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace gstar
*
* @param the widget to which this widget is parented.
*/
CoordinateWidget(QWidget* parent = 0);
CoordinateWidget(bool vertical = false, QWidget* parent = 0);

/**
* Default destructor.
Expand Down
50 changes: 26 additions & 24 deletions src/gstar/ImageViewScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,30 +576,32 @@ void ImageViewScene::sceneSelectionChanged()
void ImageViewScene::setPixmap(QPixmap p)
{

// Set pixmap
if (m_pixItem != nullptr)
{
// Check against old image size and reset scene if necessary
if ((m_pixItem -> boundingRect()).width() != p.width() ||
(m_pixItem -> boundingRect()).height() != p.height())
{
m_pixItem -> setPixmap(p);
setSceneRect(m_pixItem -> boundingRect());
//updateROIs();
}
// New and old images have matching dimensions
else
{
m_pixItem -> setPixmap(p);
}

}
// Set first pixmap
else
{
m_pixItem = addPixmap(p);
//updateROIs();
}
// Set pixmap
if (m_pixItem != nullptr)
{
if (p.width() > 0 && p.height() > 0)
{
// Check against old image size and reset scene if necessary
if ((m_pixItem->boundingRect()).width() != p.width() ||
(m_pixItem->boundingRect()).height() != p.height())
{
m_pixItem->setPixmap(p);
setSceneRect(m_pixItem->boundingRect());
//updateROIs();
}
// New and old images have matching dimensions
else
{
m_pixItem->setPixmap(p);
}
}
}
// Set first pixmap
else
{
m_pixItem = addPixmap(p);
//updateROIs();
}

}

Expand Down
2 changes: 1 addition & 1 deletion src/gstar/ImageViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void ImageViewWidget::setGlobalContrast(bool val)
{
for (auto& itr : _sub_windows)
{
itr.btn_contrast->setEnabled(val);
itr.btn_contrast->setVisible(val);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/gstar/SubImageWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ SubImageWindow::SubImageWindow() : QObject()

counts_lookup = new gstar::CountsLookupTransformer();
counts_coord_model = new gstar::CoordinateModel(counts_lookup);
counts_coord_widget = new gstar::CoordinateWidget();
counts_coord_widget = new gstar::CoordinateWidget(true);
counts_coord_widget->setModel(counts_coord_model);
counts_coord_widget->setLabel("Counts:", "Min:", "Max:");
counts_coord_widget->setLabel("Counts: ", "Min: ", "Max: ");
counts_coord_widget->setUnitsLabel("cts/s");

btn_contrast = new QPushButton("C");
connect(btn_contrast, &QPushButton::pressed, this, &SubImageWindow::on_contrast_show);
btn_contrast->setEnabled(false);
btn_contrast->setVisible(false);

QHBoxLayout* hbox = new QHBoxLayout();
hbox->addWidget(counts_coord_widget);
Expand Down
Loading

0 comments on commit bc4f7ab

Please sign in to comment.