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