]> Creatis software - clitk.git/blob - vv/vvThreadedFilter.cxx
changes in license header
[clitk.git] / vv / vvThreadedFilter.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 // vv
20 #include "vvThreadedFilter.h"
21 #include "vvProgressDialog.h"
22
23 // Qt
24 #include <QMessageBox>
25
26 //------------------------------------------------------------------------------
27 vvThreadedFilter::vvThreadedFilter():
28   QThread()
29 {
30   m_Filter = NULL;
31 }
32 //------------------------------------------------------------------------------
33
34
35 //------------------------------------------------------------------------------
36 vvThreadedFilter::~vvThreadedFilter()
37 {
38 }
39 //------------------------------------------------------------------------------
40
41
42 //------------------------------------------------------------------------------
43 void vvThreadedFilter::SetFilter(clitk::ImageToImageGenericFilterBase * f)
44 {
45   m_Filter = f;
46 }
47 //------------------------------------------------------------------------------
48
49
50 //------------------------------------------------------------------------------
51 void vvThreadedFilter::Update()
52 {
53   assert(m_Filter != NULL);
54
55   // Show a progress bar while computing
56   vvProgressDialog progress("Computing ...",100);
57   progress.SetCancelButtonEnabled(true);
58   connect(&progress, SIGNAL(rejected()), this, SLOT(reject()));
59   this->start();
60   this->setTerminationEnabled(true);
61   std::string temp;
62   while (this->isRunning()) {
63     // try {
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());
70       }
71       temp = m_FilterBase->GetCurrentStepName();
72     }
73     this->wait(200); // in miliseconds
74     qApp->processEvents();
75   }
76 }
77 //------------------------------------------------------------------------------
78
79
80 //------------------------------------------------------------------------------
81 void vvThreadedFilter::run()
82 {
83   assert(m_Filter != NULL);
84   try {
85     m_Filter->Update();
86   }
87   catch(clitk::ExceptionObject e) {
88     DD("vvThreadedFilter : exceptionobject handeled");
89     DD(e.what());
90     QApplication::restoreOverrideCursor();
91     QMessageBox::information(new QWidget, tr("Error"), e.what());  
92   }
93   DD("end RUN");
94 }
95 //------------------------------------------------------------------------------
96
97
98 //------------------------------------------------------------------------------
99 void vvThreadedFilter::reject()
100 {
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();
105   }
106 }
107 //------------------------------------------------------------------------------
108
109
110
111