From aa45f543a6e4b4065277cd5ea38e4e46d1095789 Mon Sep 17 00:00:00 2001 From: alexandergetka Date: Mon, 20 Jul 2020 15:56:13 -0400 Subject: [PATCH 1/5] Confetti src change, fix #763, misc fixes --- scripts/linux-makeself | 3 +- .../confetti_source/pyGUI/ConfettiCore.py | 44 ++++++++++--- src/view/gui/Slicer.cpp | 61 ++++++++++++++++++- src/view/gui/SlicerManager.cpp | 18 ++---- src/view/gui/fHelpTutorial.cpp | 2 +- src/view/gui/fMainWindow.cpp | 15 +++-- src/view/gui/fMainWindow.h | 2 +- 7 files changed, 109 insertions(+), 36 deletions(-) diff --git a/scripts/linux-makeself b/scripts/linux-makeself index 82970c542..c357c8598 100755 --- a/scripts/linux-makeself +++ b/scripts/linux-makeself @@ -119,8 +119,7 @@ install_captk () { fi echo "Done." - echo "To run CaPTk, locate to where CaPTk is installed and enter the command \"./CaPTk/${ver}/captk\" in your console." - + echo "To run CaPTk, change to the directory where CaPTk is installed and enter the command \"./CaPTk/${ver}/captk\" in your console." } # Print license with a reader diff --git a/src/applications/individualApps/confetti_source/pyGUI/ConfettiCore.py b/src/applications/individualApps/confetti_source/pyGUI/ConfettiCore.py index 3d37e78cf..6a298259f 100755 --- a/src/applications/individualApps/confetti_source/pyGUI/ConfettiCore.py +++ b/src/applications/individualApps/confetti_source/pyGUI/ConfettiCore.py @@ -4,30 +4,54 @@ import ctypes from ctypes import CFUNCTYPE, c_int,c_char,c_char_p import numpy +# Update 7/2/2020: Modified ConfettiCore.py to accommodate nuitka packaging. class ConfettiApi(): def __init__(self): try: - self.libraryName =self.getCoreModulePath() - self.CoreModule = ctypes.cdll.LoadLibrary(self.libraryName) - self.listner= None - self.txtCallback_ref = None - except: + self.libraryName = os.path.normpath(self.getCoreModulePath()) + self.CoreModule = ctypes.cdll.LoadLibrary(self.libraryName) + print "Successfully loaded the ConfettiCore binary." + self.listner= None + self.txtCallback_ref = None + except Exception as e: self.CoreModule= None - print("Failed to load ConfettiCore binary") + print("Failed to load ConfettiCore binary. Exception: ") + print(e) def getCoreModulePath(self): if os.name is 'nt': libraryName = "ConfettiCore.dll" else: libraryName = "libConfettiCore.so" - if getattr(sys, 'frozen', False): + if (getattr(sys, 'frozen', False)): application_path = os.path.dirname(sys.executable) elif __file__: - application_path = os.path.dirname(__file__) - baseDir=os.path.join(application_path, '..' ) + print "Using __file__" + if os.name is 'nt': + application_path = self.attemptWindowsLongPathFix(os.path.dirname(__file__)) + else: + application_path = os.path.dirname(__file__) + baseDir=os.path.join(application_path, '..' ) # use to search directory above dist + # match if dll found in either this or one-higher directory + for root, dirs, files in os.walk(application_path): + for file in files: + if libraryName in file: + return (os.path.join(root, file)) for root, dirs, files in os.walk(baseDir): for file in files: if libraryName in file: - return (os.path.join(root, file)) + return (os.path.join(root, file)) + + def attemptWindowsLongPathFix(self, in_path): + # Do not call this on non-Windows platforms. + try: + path = unicode(in_path) + except Exception as e: + print(e) + GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW + buffer = ctypes.create_unicode_buffer(GetLongPathName(path, 0, 0)) + GetLongPathName(path, buffer, len(buffer)) + print buffer.value + return buffer.value def registerCppCallback(self): if self.CoreModule is None: diff --git a/src/view/gui/Slicer.cpp b/src/view/gui/Slicer.cpp index 23e428fa2..0a1d91724 100644 --- a/src/view/gui/Slicer.cpp +++ b/src/view/gui/Slicer.cpp @@ -199,9 +199,64 @@ void Slicer::SetInitPosition() void Slicer::SetCurrentPosition(double x, double y, double z) { - mCursor[0] = x; - mCursor[1] = y; - mCursor[2] = z; + double X = (x - this->GetInput()->GetOrigin()[0]) / this->GetInput()->GetSpacing()[0]; + double Y = (y - this->GetInput()->GetOrigin()[1]) / this->GetInput()->GetSpacing()[1]; + double Z = (z - this->GetInput()->GetOrigin()[2]) / this->GetInput()->GetSpacing()[2]; + + // round up pixel values + X = ROUND(X); + Y = ROUND(Y); + Z = ROUND(Z); + + // Force pixel pos within bounds of image if not already +#if VTK_MAJOR_VERSION <= 5 + int minX = this->GetInput()->GetWholeExtent()[0]; + int maxX = this->GetInput()->GetWholeExtent()[1]; + int minY = this->GetInput()->GetWholeExtent()[2]; + int maxY = this->GetInput()->GetWholeExtent()[3]; + int minZ = this->GetInput()->GetWholeExtent()[4]; + int maxZ = this->GetInput()->GetWholeExtent()[5]; +#else + int minX = this->GetInput()->GetExtent()[0]; + int maxX = this->GetInput()->GetExtent()[1]; + int minY = this->GetInput()->GetExtent()[2]; + int maxY = this->GetInput()->GetExtent()[3]; + int minZ = this->GetInput()->GetExtent()[4]; + int maxZ = this->GetInput()->GetExtent()[5]; +#endif + if (X < minX) + { + X = minX; + } + else if (X > maxX) + { + X = maxX; + } + if (Y < minY) + { + Y = minY; + } + else if (Y > maxY) + { + Y = maxY; + } + if (Z < minZ) + { + Z = minZ; + } + else if (Z > maxZ) + { + Z = maxZ; + } + // Re-update world pos to match new pixel pos + x = X * this->GetInput()->GetSpacing()[0] + this->GetInput()->GetOrigin()[0]; + y = Y * this->GetInput()->GetSpacing()[1] + this->GetInput()->GetOrigin()[1]; + z = Z * this->GetInput()->GetSpacing()[2] + this->GetInput()->GetOrigin()[2]; + + // Set cursor to match new world pos + mCursor[0] = x; + mCursor[1] = y; + mCursor[2] = z; } void Slicer::SetInteractorStyle(vtkInteractorStyle * style) diff --git a/src/view/gui/SlicerManager.cpp b/src/view/gui/SlicerManager.cpp index 2a1162b1e..9dc57eba3 100644 --- a/src/view/gui/SlicerManager.cpp +++ b/src/view/gui/SlicerManager.cpp @@ -601,21 +601,11 @@ void SlicerManager::UpdateInfoOnCursorPosition(int slicer) z = Z * mSlicers[slicer]->GetInput()->GetSpacing()[2] + mSlicers[slicer]->GetInput()->GetOrigin()[2]; // double value = -VTK_DOUBLE_MAX; -#if VTK_MAJOR_VERSION <= 5 - if (X >= mSlicers[slicer]->GetInput()->GetWholeExtent()[0] && X <= mSlicers[slicer]->GetInput()->GetWholeExtent()[1] && - Y >= mSlicers[slicer]->GetInput()->GetWholeExtent()[2] && Y <= mSlicers[slicer]->GetInput()->GetWholeExtent()[3] && - Z >= mSlicers[slicer]->GetInput()->GetWholeExtent()[4] && Z <= mSlicers[slicer]->GetInput()->GetWholeExtent()[5]) -#else - if (X >= mSlicers[slicer]->GetInput()->GetExtent()[0] && X <= mSlicers[slicer]->GetInput()->GetExtent()[1] && - Y >= mSlicers[slicer]->GetInput()->GetExtent()[2] && Y <= mSlicers[slicer]->GetInput()->GetExtent()[3] && - Z >= mSlicers[slicer]->GetInput()->GetExtent()[4] && Z <= mSlicers[slicer]->GetInput()->GetExtent()[5]) -#endif - { - // mSlicers[slicer]->GetInput() - value = this->GetScalarComponentAsDouble(mSlicers[slicer]->GetInput(), X, Y, Z); - emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(), x, y, z, X, Y, Z, value); - } + value = this->GetScalarComponentAsDouble(mSlicers[slicer]->GetInput(), X, Y, Z); + // Update position to specified or bounded coords + emit UpdatePosition(mSlicers[slicer]->GetCursorVisibility(), x, y, z, X, Y, Z, value); + } void SlicerManager::Activated() diff --git a/src/view/gui/fHelpTutorial.cpp b/src/view/gui/fHelpTutorial.cpp index 964125393..bd3b1ba16 100644 --- a/src/view/gui/fHelpTutorial.cpp +++ b/src/view/gui/fHelpTutorial.cpp @@ -87,7 +87,7 @@ fHelpTutorial::fHelpTutorial() if (!cbica::fileExists(m_helpFileFullPath)) { - cbica::Logging(loggerFile, "Unable to start help page, file '" + m_helpFileFullPath + "' not found"); + cbica::Logging(loggerFile, "Unable to start about page, file '" + m_helpFileFullPath + "' not found"); } else { diff --git a/src/view/gui/fMainWindow.cpp b/src/view/gui/fMainWindow.cpp index 03212b888..b8141c673 100644 --- a/src/view/gui/fMainWindow.cpp +++ b/src/view/gui/fMainWindow.cpp @@ -582,10 +582,13 @@ fMainWindow::fMainWindow() connect(supportMenu, SIGNAL(triggered(QAction*)), this, SLOT(help_Download(QAction*))); connect(actionModelLibrary, SIGNAL(triggered()), this, SLOT(OpenModelLibrary())); + + mHelpDlg = new fHelpDialog(); + mHelpTutorial = new fHelpTutorial(); connect(help_systeminformation, SIGNAL(triggered()), this, SLOT(OnSystemInformationMenuClicked())); - connect(&mHelpTutorial, SIGNAL(skipTutorialOnNextRun(bool)), this, SLOT(skipTutorial(bool))); + connect(mHelpTutorial, SIGNAL(skipTutorialOnNextRun(bool)), this, SLOT(skipTutorial(bool))); for (size_t i = 0; i < vectorOfGBMApps.size(); i++) { @@ -944,7 +947,7 @@ fMainWindow::fMainWindow() statusBar()->addPermanentWidget(m_progressBar); m_progressBar->setValue(0); - mHelpDlg = new fHelpDialog(); + recurrencePanel.SetCurrentLoggerPath(m_tempFolderLocation); msubtypePanel.SetCurrentLoggerPath(m_tempFolderLocation); @@ -1132,7 +1135,7 @@ std::string fMainWindow::ConversionFrom2Dto3D(const std::string &fileName) void fMainWindow::about() { //#if CAPTK_PACKAGE_PROJECT - mHelpTutorial.show(); + mHelpTutorial->show(); //#endif } @@ -2289,6 +2292,7 @@ void fMainWindow::CloseImage(QTableWidgetItem* item) void fMainWindow::MousePositionChanged(int visibility, double x, double y, double z, double X, double Y, double Z, double value) { + infoPanel->setCurrentInfo(visibility, x, y, z, X, Y, Z, value); tumorPanel->HighlightCurrentSelctedPoints(x, y, z, X, Y, Z, value); } @@ -2724,9 +2728,10 @@ void fMainWindow::MoveSlicerCursor(double x, double y, double z, int mode) mSlicerManagers[mCurrentPickedImageIndex]->GetSlicer(0)->SetCurrentPosition(x, y, z); // mSlicerManagers[mCurrentPickedImageIndex]->Picked(); + mSlicerManagers[mCurrentPickedImageIndex]->UpdateInfoOnCursorPosition(0); mSlicerManagers[mCurrentPickedImageIndex]->UpdateViews(0); mSlicerManagers[mCurrentPickedImageIndex]->UpdateLinked(0); - mSlicerManagers[mCurrentPickedImageIndex]->UpdateInfoOnCursorPosition(0); + } else if (mode == 1) { @@ -2738,9 +2743,9 @@ void fMainWindow::MoveSlicerCursor(double x, double y, double z, int mode) mSlicerManagers[mCurrentPickedImageIndex]->GetSlicer(0)->SetCurrentPosition(x, y, z); // mSlicerManagers[mCurrentPickedImageIndex]->Picked(); + mSlicerManagers[mCurrentPickedImageIndex]->UpdateInfoOnCursorPosition(0); mSlicerManagers[mCurrentPickedImageIndex]->UpdateViews(0); mSlicerManagers[mCurrentPickedImageIndex]->UpdateLinked(0); - mSlicerManagers[mCurrentPickedImageIndex]->UpdateInfoOnCursorPosition(0); } propogateSlicerPosition(); } diff --git a/src/view/gui/fMainWindow.h b/src/view/gui/fMainWindow.h index 665ac00a7..d889e73c7 100644 --- a/src/view/gui/fMainWindow.h +++ b/src/view/gui/fMainWindow.h @@ -1563,7 +1563,7 @@ public slots: Fetalbrain mfetalbrain; fHelpDialog* mHelpDlg; - fHelpTutorial mHelpTutorial; + fHelpTutorial* mHelpTutorial; std::string t1cePath; std::string m_imagetype_string; From 8f646529c453700f0a7bcd4a31901b21cc78aabd Mon Sep 17 00:00:00 2001 From: alexandergetka Date: Tue, 21 Jul 2020 00:17:01 -0400 Subject: [PATCH 2/5] confetti application find fix --- src/view/gui/fMainWindow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/view/gui/fMainWindow.cpp b/src/view/gui/fMainWindow.cpp index b8141c673..a78dda7c0 100644 --- a/src/view/gui/fMainWindow.cpp +++ b/src/view/gui/fMainWindow.cpp @@ -344,7 +344,7 @@ fMainWindow::fMainWindow() { nonNativeAppPaths_wrap.erase(0, 1); } - nonNativeAppPaths_wrap = nonNativeAppPaths_wrap + " itksnap"; + nonNativeAppPaths_wrap = nonNativeAppPaths_wrap + " itksnap" + " confetti"; m_pyGUIApps = cbica::stringSplit(nonNativeAppPaths_wrap, " "); nonNativeAppPaths_wrap = std::string(CAPTK_APP_LIST_PY_CLI); if (nonNativeAppPaths_wrap[0] == ' ') @@ -358,7 +358,8 @@ fMainWindow::fMainWindow() { if (m_pyGUIApps[i] == "confetti") { - m_pyGUIApps[i] = "ConfettiGUI"; + // Below line causes getApplicationPath to fail in developer mode + //m_pyGUIApps[i] = "ConfettiGUI"; } if ((m_pyGUIApps[i] == "librabatch") || (m_pyGUIApps[i] == "librasingle")) { From 689c60aae99a1610d6360e4ce6d9c657832c42c7 Mon Sep 17 00:00:00 2001 From: alexandergetka Date: Tue, 21 Jul 2020 02:16:32 -0400 Subject: [PATCH 3/5] match confetti call to same style as other apps --- src/view/gui/fMainWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/view/gui/fMainWindow.cpp b/src/view/gui/fMainWindow.cpp index a78dda7c0..165dc7096 100644 --- a/src/view/gui/fMainWindow.cpp +++ b/src/view/gui/fMainWindow.cpp @@ -6129,8 +6129,8 @@ void fMainWindow::ApplicationLIBRASingle() void fMainWindow::ApplicationConfetti() { - std::string scriptToCall = m_allNonNativeApps["ConfettiGUI"]; - + std::string scriptToCall = m_allNonNativeApps["confetti"]; + if (startExternalProcess(scriptToCall.c_str(), QStringList()) != 0) { ShowErrorMessage("Confetti failed to execute. Please check installation requirements and retry.", this); From 0ca5d2df00b0e2c28b6b9503090110361a9ffa43 Mon Sep 17 00:00:00 2001 From: alexandergetka Date: Tue, 21 Jul 2020 04:47:53 -0400 Subject: [PATCH 4/5] Update fMainWindow.cpp --- src/view/gui/fMainWindow.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/view/gui/fMainWindow.cpp b/src/view/gui/fMainWindow.cpp index 165dc7096..755f23124 100644 --- a/src/view/gui/fMainWindow.cpp +++ b/src/view/gui/fMainWindow.cpp @@ -356,11 +356,6 @@ fMainWindow::fMainWindow() size_t allAppCounter = 0; for (size_t i = 0; i < m_pyGUIApps.size(); i++) { - if (m_pyGUIApps[i] == "confetti") - { - // Below line causes getApplicationPath to fail in developer mode - //m_pyGUIApps[i] = "ConfettiGUI"; - } if ((m_pyGUIApps[i] == "librabatch") || (m_pyGUIApps[i] == "librasingle")) { m_pyGUIApps[i] = "libra"; From c3dca77f4be5bd6461f119d311b0d95ebfc09128 Mon Sep 17 00:00:00 2001 From: alexandergetka Date: Tue, 21 Jul 2020 11:23:19 -0400 Subject: [PATCH 5/5] add help tutorial to fmainwindow destructor --- src/view/gui/fMainWindow.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/view/gui/fMainWindow.cpp b/src/view/gui/fMainWindow.cpp index 89531f16e..8d0f2017f 100644 --- a/src/view/gui/fMainWindow.cpp +++ b/src/view/gui/fMainWindow.cpp @@ -1013,6 +1013,9 @@ fMainWindow::~fMainWindow() file.close(); } + if (mHelpTutorial) + delete mHelpTutorial; + if (mHelpDlg) delete mHelpDlg;