otbWriterWatcherBase.h 4.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (C) 1999-2011 Insight Software Consortium
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
21

22 23
#ifndef otbWriterWatcherBase_h
#define otbWriterWatcherBase_h
24

25 26
#include "otbStopwatch.h"

27 28 29
#include "itkCommand.h"
#include "itkProcessObject.h"

30 31
#include "OTBCommonExport.h"

32 33 34
namespace otb
{

35 36 37 38 39 40 41 42 43 44 45 46
/** \class WriterWatcherBase
 *  \brief This class is an abstract class
 *         Provides an interface to progress task mechanic
 *
 *  Implement your callbacks
 *  \li ShowWriterProgress : callback called for each completed tile
 *  \li StartWriter        : callback called at the begin of tile writing
 *  \li EndWriter          : callback called at the end of tile writing
 *  \li ShowFilterProgress : callback called for each completed pixel
 *  \li StartFilter        : callback called at the begin of filter execution for a given tile
 *  \li EndFilter          : callback called at the end of filter execution for a given tile
 *
47 48
 *
 * \ingroup OTBCommon
49
 */
50
class OTBCommon_EXPORT WriterWatcherBase
51 52
{
public:
53

54 55 56
  /** Constructor. Takes a ProcessObject to monitor and an optional
   * comment string that is prepended to each event message. */
  WriterWatcherBase(itk::ProcessObject* process,
OTB Bot's avatar
OTB Bot committed
57
                    const char *comment = "");
58

59 60
  /** This other constructor is provided so that the user can set a different processing filter than the one
  just before process in the pipeline */
OTB Bot's avatar
OTB Bot committed
61
  WriterWatcherBase(itk::ProcessObject* process, itk::ProcessObject * source, const char *comment = "");
62

63 64
  /** Default constructor */
  WriterWatcherBase();
65

66 67
  /** Copy constructor */
  WriterWatcherBase(const WriterWatcherBase&);
68

69
  /** operator=  */
OTB Bot's avatar
OTB Bot committed
70
  void operator =(const WriterWatcherBase&);
71

72 73
  /** Destructor. */
  virtual ~WriterWatcherBase();
74

75 76 77 78 79
  const char *GetNameOfClass()
    {
    return (m_Process.GetPointer() ? m_Process->GetNameOfClass() : "None");
    }

80 81
  /** Methods to access member data */
  /** Get a pointer to the process object being watched. */
OTB Bot's avatar
OTB Bot committed
82
  itk::ProcessObject *GetProcess()
83 84 85
  {
    return m_Process.GetPointer();
  }
86

87
  /** Get the comment for the watcher. */
88
  std::string GetComment() const
89 90 91
  {
    return m_Comment;
  }
92

93 94
  /** Get a reference to the Stopwatch */
  otb::Stopwatch& GetStopwatch()
95
  {
96
    return m_Stopwatch;
97
  }
98

99
protected:
100

101 102
  /** Callback method to show the ProgressEvent from the writer */
  virtual void ShowWriterProgress() = 0;
103

104 105
  /** Callback method to show the StartEvent from the writer*/
  virtual void StartWriter() = 0;
106

107 108
  /** Callback method to show the EndEvent from the writer*/
  virtual void EndWriter() = 0;
109

110 111
  /** Callback method to show the ProgressEvent from the filter */
  virtual void ShowFilterProgress() = 0;
112

113 114
  /** Callback method to show the StartEvent from the filter*/
  virtual void StartFilter() = 0;
115

116 117
  /** Callback method to show the EndEvent from the filter*/
  virtual void EndFilter() = 0;
118

119
  /** Computing time */
120
  otb::Stopwatch m_Stopwatch;
121

122 123
  /** Associated comment */
  std::string m_Comment;
124

125 126
  /** Abstract process object */
  itk::ProcessObject::Pointer m_Process;
127

128 129
  /** Second abstract process object representing the source */
  itk::ProcessObject::Pointer m_SourceProcess;
130

131 132
  /** Internal type */
  typedef itk::SimpleMemberCommand<WriterWatcherBase> CommandType;
133

134 135
  /** Start writer callback */
  CommandType::Pointer m_StartWriterCommand;
136

137 138
  /** End writer callback */
  CommandType::Pointer m_EndWriterCommand;
139

140 141
  /** Progress writer callback */
  CommandType::Pointer m_ProgressWriterCommand;
142

143 144
  /** Start filter callback */
  CommandType::Pointer m_StartFilterCommand;
145

146 147
  /** End writer callback */
  CommandType::Pointer m_EndFilterCommand;
148

149 150
  /** Progress writer callback */
  CommandType::Pointer m_ProgressFilterCommand;
151

152 153
  /** Start oberserver */
  unsigned long m_StartWriterTag;
154

155 156
  /** End observer */
  unsigned long m_EndWriterTag;
157

158 159
  /** Progress observer */
  unsigned long m_ProgressWriterTag;
160

161 162
  /** Start oberserver */
  unsigned long m_StartFilterTag;
163

164 165
  /** End observer */
  unsigned long m_EndFilterTag;
166

167 168
  /** Progress observer */
  unsigned long m_ProgressFilterTag;
169

170
private:
171

172
};
173

174 175 176
} // end namespace otb

#endif