Orfeo Toolbox  3.16
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  const char *comment)
29  : FilterWatcherBase(process, comment)
30 {
31  m_StarsCount = 50;
32  m_CurrentNbStars = -1;
33 }
34 
37  const std::string& comment)
38  : FilterWatcherBase(process, comment.c_str())
39 {
40  m_StarsCount = 50;
41 }
42 
45 {
46  // Initialize state
47  m_StarsCount = watch.m_StarsCount;
48 }
49 
50 void
53 {
54  // Initialize state
56  m_StarsCount = watch.m_StarsCount;
57 }
58 
59 void
62 {
63  if (m_Process)
64  {
65  int progressPercent = static_cast<int>(m_Process->GetProgress() * 100);
66  int nbStars = static_cast<int>(m_Process->GetProgress() * m_StarsCount);
67  int nbBlanks = m_StarsCount - nbStars;
68 
69  if (nbBlanks < 0)
70  {
71  nbBlanks = 0;
72  }
73 
74  if (nbStars > m_StarsCount)
75  {
76  nbStars = m_StarsCount;
77  }
78 
79  if (progressPercent > 100)
80  {
81  progressPercent = 100;
82  }
83 
84  if (nbStars > m_CurrentNbStars)
85  {
86  std::string stars(nbStars, '*');
87  std::string blanks(nbBlanks, ' ');
88 
89  std::cout << "\r"
90  << m_Comment
91  << ": "
92  << progressPercent << "% [" << stars << blanks << "]"
93  << std::flush;
94  }
95 
96  m_CurrentNbStars = nbStars;
97  }
98 }
99 
100 void
103 {
104  m_TimeProbe.Start();
105 }
106 
107 void
110 {
111  m_TimeProbe.Stop();
112 
113  // Ensure we don't depend on std::cout configuration
114  std::ostringstream elapsedTime;
115  elapsedTime.precision(1);
116  elapsedTime << m_TimeProbe.GetMeanTime();
117 
118  std::cout << " ("
119  << elapsedTime.str()
120  << " seconds)"
121  << std::endl;
122 }
123 
124 } // end namespace otb

Generated at Sun Feb 3 2013 00:48:36 for Orfeo Toolbox with doxygen 1.8.1.1