1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
20 #include "vvThreadedFilter.h"
21 #include "vvProgressDialog.h"
24 #include <QMessageBox>
26 //------------------------------------------------------------------------------
27 vvThreadedFilter::vvThreadedFilter():
32 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 vvThreadedFilter::~vvThreadedFilter()
39 //------------------------------------------------------------------------------
42 //------------------------------------------------------------------------------
43 void vvThreadedFilter::SetFilter(clitk::ImageToImageGenericFilterBase * f)
47 //------------------------------------------------------------------------------
50 //------------------------------------------------------------------------------
51 void vvThreadedFilter::Update()
53 assert(m_Filter != NULL);
55 // Show a progress bar while computing
56 vvProgressDialog progress("Computing ...",100);
57 progress.SetCancelButtonEnabled(true);
58 connect(&progress, SIGNAL(rejected()), this, SLOT(reject()));
60 this->setTerminationEnabled(true);
62 while (this->isRunning()) {
64 m_FilterBase = m_Filter->GetFilterBase(); // get filterbase is only set after Update
65 if (m_FilterBase != NULL) {
66 progress.SetProgress(m_FilterBase->GetCurrentStepNumber(),
67 m_FilterBase->GetNumberOfSteps());
68 if (temp != m_FilterBase->GetCurrentStepName()) {
69 progress.AddToText(m_FilterBase->GetCurrentStepName());
71 temp = m_FilterBase->GetCurrentStepName();
73 this->wait(200); // in miliseconds
74 qApp->processEvents();
77 //------------------------------------------------------------------------------
80 //------------------------------------------------------------------------------
81 void vvThreadedFilter::run()
83 assert(m_Filter != NULL);
87 catch(clitk::ExceptionObject e) {
88 DD("vvThreadedFilter : exceptionobject handeled");
90 QApplication::restoreOverrideCursor();
91 QMessageBox::information(new QWidget, tr("Error"), e.what());
95 //------------------------------------------------------------------------------
98 //------------------------------------------------------------------------------
99 void vvThreadedFilter::reject()
101 // First, say the filter it must stop as soon as possible. We then
102 // wait that an exception occur in the main thread.
103 if (m_FilterBase != NULL) {
104 m_FilterBase->Cancel();
107 //------------------------------------------------------------------------------