]> Creatis software - clitk.git/blob - vv/vvThreadedFilter.cxx
*** empty log message ***
[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://oncora1.lyon.fnclcc.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   DD("vvThreadedFilter");
31   m_Filter = NULL;
32 }
33 //------------------------------------------------------------------------------
34
35
36 //------------------------------------------------------------------------------
37 vvThreadedFilter::~vvThreadedFilter()
38 {
39 }
40 //------------------------------------------------------------------------------
41
42
43 //------------------------------------------------------------------------------
44 void vvThreadedFilter::SetFilter(clitk::ImageToImageGenericFilterBase * f)
45 {
46   DD("SetFilter");
47   m_Filter = f;
48 }
49 //------------------------------------------------------------------------------
50
51
52 //------------------------------------------------------------------------------
53 void vvThreadedFilter::Update()
54 {
55   assert(m_Filter != NULL);
56
57   // Show a progress bar while computing
58   vvProgressDialog progress("Computing ...",100);
59   connect(&progress, SIGNAL(rejected()), this, SLOT(reject()));
60   this->start();
61   this->setTerminationEnabled(true);
62   std::string temp;
63   while (this->isRunning()) {
64     DD(this->isRunning());
65     m_FilterBase = m_Filter->GetFilterBase(); // get filterbase only after Update
66     if (m_FilterBase != NULL) {
67       progress.SetProgress(m_FilterBase->GetCurrentStepNumber(), 
68                            m_FilterBase->GetNumberOfSteps());
69       if (temp != m_FilterBase->GetCurrentStepName()) {
70         progress.AddToText(m_FilterBase->GetCurrentStepName());
71       }
72       temp = m_FilterBase->GetCurrentStepName();
73     }
74     this->wait(200); // in milisecond
75     qApp->processEvents();
76   }
77   DD("after loop");
78 }
79 //------------------------------------------------------------------------------
80
81
82 //------------------------------------------------------------------------------
83 void vvThreadedFilter::run()
84 {
85   assert(m_Filter != NULL);
86   m_Filter->Update();
87 }
88 //------------------------------------------------------------------------------
89
90
91 //------------------------------------------------------------------------------
92 void vvThreadedFilter::reject()
93 {
94   DD("vvThreadedFilter::reject");
95   this->quit();
96   // if (m_Filter != NULL) {
97 //     m_Filter->MustStop();
98 //   }
99   DD("after terminate");
100 }
101 //------------------------------------------------------------------------------
102
103
104
105