From fa4eac039b6a726f68ed421d014ebb51449c769e Mon Sep 17 00:00:00 2001
From: Ming Fang <mingf2@illinois.edu>
Date: Tue, 25 May 2021 16:06:45 -0500
Subject: [PATCH] fix bug in save/saveas

---
 Headers/setup.h            |  2 +-
 Sources/MainWindow.cpp     | 15 ++++++++-------
 Sources/reconstruction.cpp |  4 ++++
 Sources/worker.cpp         |  5 ++++-
 imagerQt.pro               |  8 ++++++--
 5 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/Headers/setup.h b/Headers/setup.h
index 4063ea9..9af3158 100644
--- a/Headers/setup.h
+++ b/Headers/setup.h
@@ -111,7 +111,7 @@ public:
     // queue capacity
     ulong capacity=1024;
     // max number of cones to process
-    ulong maxN=1000;
+    ulong maxN=10000;
 };
 
 class Cone
diff --git a/Sources/MainWindow.cpp b/Sources/MainWindow.cpp
index e99f502..64a1585 100644
--- a/Sources/MainWindow.cpp
+++ b/Sources/MainWindow.cpp
@@ -50,7 +50,7 @@ MainWindow::MainWindow(QWidget *parent) :
     // update every 0.1 second
     QTimer *timer = new QTimer(this);
     connect(timer, &QTimer::timeout, this, QOverload<>::of(&MainWindow::redraw));
-    timer->start(100);
+    timer->start(1000);
 
     setWindowTitle(tr("Back projection"));
     ui->canvas->Canvas()->Modified();
@@ -99,6 +99,8 @@ MainWindow::~MainWindow()
     delete ui;
     if (image)
         delete image;
+    if (countsText)
+        delete countsText;
     if (config)
         delete config;
     for (int i = 0; i < longitudes.size(); ++i) {
@@ -226,12 +228,11 @@ bool MainWindow::handleSaveAs()
     QString fileName = QFileDialog::getSaveFileName(this,
             tr("Save Image"), "",
             tr("PNG file (*.png);;ROOT file (*.root);;C file (*.C);;text file (*.txt)"));
-    if (fileName.isEmpty())
-        return false;
-    else {
-        if (saveCanvas(fileName))
-            curFile = fileName;
+    if (!fileName.isEmpty() && saveCanvas(fileName)){
+        curFile = fileName;
+        return true;
     }
+    return false;
 }
 
 bool MainWindow::saveCanvas(const QString& fileName)
@@ -240,7 +241,7 @@ bool MainWindow::saveCanvas(const QString& fileName)
     QString ext=fileInfo.completeSuffix();
     bool saved=false;
     if (ext == "root" || ext == "png" || ext == "C") {
-//        qDebug() << "Save as " << ext << " file.";
+        qDebug() << "Save as " << ext << " file.";
         image->mMutex.lock();
         ui->canvas->Canvas()->SaveAs(fileName.toLocal8Bit().constData());
         image->mMutex.unlock();
diff --git a/Sources/reconstruction.cpp b/Sources/reconstruction.cpp
index 7426a88..fc19ee5 100644
--- a/Sources/reconstruction.cpp
+++ b/Sources/reconstruction.cpp
@@ -164,6 +164,10 @@ int RecoImage::addConesNormalized(std::vector<Cone>::const_iterator first,
         {
             for (int j = 0; j < config->phiBins; j++)
             {
+		// if (i==0&&j==0)
+		// {
+		//     std::cout << omp_get_num_threads() << '\n';
+		// }
                 ray = k->apex - config->xbs[i][j];
                 beta = getCosAngle(ray, k->axis);
                 sgmb2 = std::pow((ray/(ray*ray) + k->axis/(k->axis*k->axis)-
diff --git a/Sources/worker.cpp b/Sources/worker.cpp
index 819b09e..337b887 100644
--- a/Sources/worker.cpp
+++ b/Sources/worker.cpp
@@ -31,10 +31,13 @@ void Worker::run()
                 cones[i]=Cone(line);
                 i++;
             }
+            if (exitted)
+                break;
             localCounts+=i;
             // update image
             image->updateImage(cones.cbegin(), cones.cbegin()+i, true);
-            if (exitted || line.isNull() || localCounts >= config->maxN)
+//            if (exitted || in.atEnd() || localCounts >= config->maxN)
+            if (exitted || localCounts >= config->maxN)
                 break;
         }
     }
diff --git a/imagerQt.pro b/imagerQt.pro
index 221170b..1967a8e 100644
--- a/imagerQt.pro
+++ b/imagerQt.pro
@@ -47,14 +47,18 @@ FORMS += \
 
 QMAKE_LFLAGS += -fopenmp
 QMAKE_CXXFLAGS += -fopenmp
+#QMAKE_CXXFLAGS += -fsanitize=address
+#QMAKE_LFLAGS += -fsanitize=address
 LIBS += -fopenmp
 
+
+
 INCLUDEPATH += \
-    $(ROOTSYS)/include \
+    $$(ROOTSYS)/include \
     $$PWD/Headers
 
 LIBS += \
-    -L$(ROOTSYS)/lib -lCore -lImt -lRIO -lNet -lHist -lGraf \
+    -L$$(ROOTSYS)/lib -lCore -lImt -lRIO -lNet -lHist -lGraf \
     -lGraf3d -lGpad -lTree -lTreePlayer -lRint -lPostscript -lMatrix \
     -lPhysics -lMathCore -lThread -lMultiProc -pthread -lm -ldl -rdynamic
 
-- 
GitLab