]> Creatis software - clitk.git/blob - common/clitkFilterBase.cxx
changes in license header
[clitk.git] / common / clitkFilterBase.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 // clitk
20 #include "clitkFilterBase.h"
21 #include "clitkCommon.h"
22
23 //--------------------------------------------------------------------
24 clitk::FilterBase::FilterBase() 
25 {
26   SetVerboseOptionFlag(false);
27   SetCurrentStepNumber(0);
28   SetCurrentStepBaseId("");
29   VerboseWarningFlagOn();
30   VerboseWarningFlagOff();
31   VerboseMemoryFlagOff();
32   SetWarning("");
33   VerboseWarningFlagOn();
34   m_IsCancelled = false;
35 }
36 //--------------------------------------------------------------------
37
38
39 //--------------------------------------------------------------------
40 void clitk::FilterBase::SetWarning(std::string e)
41 {
42   m_Warning = e;
43   if (GetVerboseWarningFlag()) {
44     std::cout << GetWarning() << std::endl;
45   }
46 }
47 //--------------------------------------------------------------------
48
49
50 //--------------------------------------------------------------------
51 void clitk::FilterBase::StartNewStep(std::string s) 
52 {
53   if (Cancelled()) {
54     throw clitk::ExceptionObject("Filter is canceled.");
55   }
56
57   m_CurrentStepNumber++;
58   if (GetCurrentStepBaseId() != "") {
59     std::ostringstream oss;
60     oss << GetCurrentStepBaseId() << "." << m_CurrentStepNumber;
61     SetCurrentStepId(oss.str());
62   }
63   else {
64     std::ostringstream oss;
65     oss << m_CurrentStepNumber;
66     SetCurrentStepId(oss.str());
67   }
68
69   m_CurrentStepName = "Step "+GetCurrentStepId()+" -- "+s;
70   if (GetVerboseStepFlag()) {
71     std::cout << m_CurrentStepName << std::endl;
72     //"Step " << GetCurrentStepId() << " -- " << s << std::endl;
73   }
74 }
75 //--------------------------------------------------------------------
76
77
78 //--------------------------------------------------------------------
79 void clitk::FilterBase::StopCurrentStep() 
80 {
81   
82 }
83 //--------------------------------------------------------------------
84
85
86 //--------------------------------------------------------------------
87 void clitk::FilterBase::Cancel()
88 {
89   m_IsCancelled = true;
90 }
91 //--------------------------------------------------------------------
92
93
94 //--------------------------------------------------------------------
95 bool clitk::FilterBase::Cancelled()
96 {
97   return m_IsCancelled;
98 }
99 //--------------------------------------------------------------------
100
101
102 //--------------------------------------------------------------------
103 void clitk::FilterBase::StartSubStep() {
104   m_SubstepNumbers.push_back(GetCurrentStepNumber());
105   m_SubstepID.push_back(GetCurrentStepId());
106   SetCurrentStepBaseId(GetCurrentStepId());
107   SetCurrentStepNumber(0);;
108 }
109 //--------------------------------------------------------------------
110
111
112 //--------------------------------------------------------------------
113 void clitk::FilterBase::StopSubStep() {
114   int s = m_SubstepNumbers.back();
115   m_SubstepNumbers.pop_back();
116   SetCurrentStepNumber(s);
117   m_SubstepID.pop_back();
118   if (m_SubstepID.size() != 0) {
119     SetCurrentStepBaseId(m_SubstepID.back());  }
120   else SetCurrentStepBaseId("");
121 }