From: dsarrut Date: Mon, 4 Oct 2010 08:04:16 +0000 (+0000) Subject: error are now handled by exception X-Git-Tag: v1.2.0~366 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f5e983965940b49d5724d825584e5c67220fc3d6;p=clitk.git error are now handled by exception --- diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index 5036c6e..0cbafaf 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -72,7 +72,7 @@ SET(vv_SRCS vvLabelImageLoaderWidget.cxx vvToolExtractPatient.cxx vvToolExtractLung.cxx - vvToolPlastimatch.cxx + # vvToolPlastimatch.cxx # vvToolConnectedComponentLabeling.cxx ) @@ -121,7 +121,7 @@ QT4_WRAP_CPP(vv_SRCS vvLabelImageLoaderWidget.h vvToolExtractPatient.h vvToolExtractLung.h - vvToolPlastimatch.h + # vvToolPlastimatch.h # vvToolConnectedComponentLabeling.h ) @@ -156,7 +156,7 @@ QT4_WRAP_UI(vv_UI_CXX qt_ui/vvLabelImageLoaderWidget.ui qt_ui/vvToolExtractPatient.ui qt_ui/vvToolExtractLung.ui - qt_ui/vvToolPlastimatch.ui + # qt_ui/vvToolPlastimatch.ui # qt_ui/vvToolConnectedComponentLabeling.ui ) diff --git a/vv/vvThreadedFilter.cxx b/vv/vvThreadedFilter.cxx index 1079b7f..0262126 100644 --- a/vv/vvThreadedFilter.cxx +++ b/vv/vvThreadedFilter.cxx @@ -60,9 +60,9 @@ void vvThreadedFilter::Update() this->setTerminationEnabled(true); std::string temp; while (this->isRunning()) { + // try { m_FilterBase = m_Filter->GetFilterBase(); // get filterbase is only set after Update if (m_FilterBase != NULL) { - // m_FilterBase->StopOnErrorOff(); // filter can be interrupted progress.SetProgress(m_FilterBase->GetCurrentStepNumber(), m_FilterBase->GetNumberOfSteps()); if (temp != m_FilterBase->GetCurrentStepName()) { @@ -81,7 +81,16 @@ void vvThreadedFilter::Update() void vvThreadedFilter::run() { assert(m_Filter != NULL); - m_Filter->Update(); + try { + m_Filter->Update(); + } + catch(clitk::ExceptionObject e) { + DD("vvThreadedFilter : exceptionobject handeled"); + DD(e.what()); + QApplication::restoreOverrideCursor(); + QMessageBox::information(new QWidget, tr("Error"), e.what()); + } + DD("end RUN"); } //------------------------------------------------------------------------------ @@ -89,16 +98,11 @@ void vvThreadedFilter::run() //------------------------------------------------------------------------------ void vvThreadedFilter::reject() { - // First, say the filter it must stop + // First, say the filter it must stop as soon as possible. We then + // wait that an exception occur in the main thread. if (m_FilterBase != NULL) { - m_FilterBase->SetMustStop(true); + m_FilterBase->Cancel(); } - // Indicate to the user it will stop - QApplication::restoreOverrideCursor(); - QMessageBox::information(new QWidget, tr("Error"), m_FilterBase->GetLastError().c_str()); - // Quit the thread (is it needed ?) - this->quit(); - emit ThreadInterrupted(); } //------------------------------------------------------------------------------ diff --git a/vv/vvToolExtractLung.cxx b/vv/vvToolExtractLung.cxx index c976b8c..3e63df8 100644 --- a/vv/vvToolExtractLung.cxx +++ b/vv/vvToolExtractLung.cxx @@ -76,7 +76,7 @@ void vvToolExtractLung::Initialize() { SetToolMenuName("Extract lungs"); SetToolIconFilename(":/common/icons/lung-overlay.png"); SetToolTip("Extract lung mask from thorax CT."); - // SetToolExperimental(true); + SetToolExperimental(true); // SetToolInMenu("Segmentation"); } //------------------------------------------------------------------------------ @@ -174,7 +174,7 @@ void vvToolExtractLung::apply() // Create new filter if (mFilter) delete mFilter; mFilter = new FilterType; // needed when thread cancel the filter - mFilter->StopOnErrorOff(); + // mFilter->StopOnErrorOff(); // mFilter->SetIOVerbose(true); mFilter->AddInputVVImage(mCurrentImage); // CT mFilter->AddInputVVImage(mPatient); // patient mask @@ -184,8 +184,13 @@ void vvToolExtractLung::apply() vvThreadedFilter thread; connect(&thread, SIGNAL(ThreadInterrupted()), this, SLOT(ThreadInterrupted())); thread.SetFilter(mFilter); - thread.Update(); + try { + thread.Update(); + } + catch(std::runtime_error e) { + DD("Error exception handling"); + DD(m_IsThreadInterrupted); // Check if the thread has been canceled. In this case, return if (m_IsThreadInterrupted) { m_IsThreadInterrupted = false; @@ -195,11 +200,12 @@ void vvToolExtractLung::apply() disconnect(&thread, SIGNAL(ThreadInterrupted()), this, SLOT(ThreadInterrupted())); // Check error during filter - if (mFilter->HasError()) { + // if (mFilter->HasError()) { QApplication::restoreOverrideCursor(); - QMessageBox::information(this,tr("Error"), mFilter->GetLastError().c_str()); + QMessageBox::information(this,tr("Error"), e.what());//mFilter->GetLastError().c_str()); return; - } + // } + } // end exception // Get output std::vector output = mFilter->GetOutputVVImages(); diff --git a/vv/vvToolExtractPatient.cxx b/vv/vvToolExtractPatient.cxx index c38dde5..947b5ff 100644 --- a/vv/vvToolExtractPatient.cxx +++ b/vv/vvToolExtractPatient.cxx @@ -74,7 +74,7 @@ void vvToolExtractPatient::Initialize() { SetToolMenuName("Extract Patient"); SetToolIconFilename(":/common/icons/Patient-overlay.png"); SetToolTip("Extract Patient mask from thorax CT."); - // SetToolExperimental(true); + SetToolExperimental(true); // SetToolInMenu("Segmentation"); } //------------------------------------------------------------------------------ @@ -174,7 +174,7 @@ void vvToolExtractPatient::apply() //if (mFilter) delete mFilter; DD("new filter"); mFilter = new FilterType; // needed when thread cancel the filter - mFilter->StopOnErrorOff(); + // mFilter->StopOnErrorOff(); // mFilter->SetIOVerbose(true); mFilter->AddInputVVImage(mCurrentImage); // CT // mFilter->AddInputVVImage(mPatient); // patient mask @@ -185,7 +185,11 @@ void vvToolExtractPatient::apply() vvThreadedFilter thread; connect(&thread, SIGNAL(ThreadInterrupted()), this, SLOT(ThreadInterrupted())); thread.SetFilter(mFilter); + + try { thread.Update(); + } + catch(std::runtime_error e) { // Check if the thread has been canceled. In this case, return if (m_IsThreadInterrupted) { @@ -196,10 +200,12 @@ void vvToolExtractPatient::apply() disconnect(&thread, SIGNAL(ThreadInterrupted()), this, SLOT(ThreadInterrupted())); // Check error during filter - if (mFilter->HasError()) { + // if (mFilter->HasError()) { QApplication::restoreOverrideCursor(); - QMessageBox::information(this,tr("Error"), mFilter->GetLastError().c_str()); + QMessageBox::information(this,tr("Error"), e.what());//mFilter->GetLastError().c_str()); return; + // } + } // Get output