Orfeo Toolbox  4.0
otbStandardOneLineFilterWatcher.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
22 
23 namespace otb
24 {
25 
28  : m_StarsCount(50),
29  m_CurrentNbStars(-1)
30 {
31 }
32 
35  const char *comment)
36  : FilterWatcherBase(process, comment),
37  m_StarsCount(50),
38  m_CurrentNbStars(-1)
39 {
40 }
41 
44  const std::string& comment)
45  : FilterWatcherBase(process, comment.c_str()),
46  m_StarsCount(50),
47  m_CurrentNbStars(-1)
48 {
49 }
50 
51 void
54 {
55  if (m_Process)
56  {
57  int progressPercent = static_cast<int>(m_Process->GetProgress() * 100);
58  int nbStars = static_cast<int>(m_Process->GetProgress() * m_StarsCount);
59  int nbBlanks = m_StarsCount - nbStars;
60 
61  if (nbBlanks < 0)
62  {
63  nbBlanks = 0;
64  }
65 
66  if (nbStars > m_StarsCount)
67  {
68  nbStars = m_StarsCount;
69  }
70 
71  if (progressPercent > 100)
72  {
73  progressPercent = 100;
74  }
75 
76  if (nbStars > m_CurrentNbStars)
77  {
78  std::string stars(nbStars, '*');
79  std::string blanks(nbBlanks, ' ');
80 
81  std::cout << "\r"
82  << m_Comment
83  << ": "
84  << progressPercent << "% [" << stars << blanks << "]"
85  << std::flush;
86  }
87 
88  m_CurrentNbStars = nbStars;
89  }
90 }
91 
92 void
95 {
96  m_TimeProbe.Start();
97 }
98 
99 void
102 {
103  m_TimeProbe.Stop();
104 
105  // Ensure we don't depend on std::cout configuration
106  std::ostringstream elapsedTime;
107  elapsedTime.precision(1);
108  elapsedTime << m_TimeProbe.GetMean();
109 
110  std::cout << " ("
111  << elapsedTime.str()
112  << " seconds)"
113  << std::endl;
114 }
115 
116 } // end namespace otb

Generated at Sat Mar 8 2014 16:19:21 for Orfeo Toolbox with doxygen 1.8.3.1