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://oncora1.lyon.fnclcc.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()) {
63 m_FilterBase = m_Filter->GetFilterBase(); // get filterbase is only set after Update
64 if (m_FilterBase != NULL) {
65 // m_FilterBase->StopOnErrorOff(); // filter can be interrupted
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 milisecond
74 qApp->processEvents();
77 //------------------------------------------------------------------------------
80 //------------------------------------------------------------------------------
81 void vvThreadedFilter::run()
83 assert(m_Filter != NULL);
86 //------------------------------------------------------------------------------
89 //------------------------------------------------------------------------------
90 void vvThreadedFilter::reject()
92 // First, say the filter it must stop
93 if (m_FilterBase != NULL) {
94 m_FilterBase->SetMustStop(true);
96 // Indicate to the user it will stop
97 QApplication::restoreOverrideCursor();
98 QMessageBox::information(new QWidget, tr("Error"), m_FilterBase->GetLastError().c_str());
99 // Quit the thread (is it needed ?)
101 emit ThreadInterrupted();
103 //------------------------------------------------------------------------------