otbFilterWatcherBase.cxx 5.03 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 24 25 26 27 28

#include "otbFilterWatcherBase.h"

namespace otb
{

FilterWatcherBase
::FilterWatcherBase()
29
: m_Comment("Not watching an object"),
30
  m_Process(ITK_NULLPTR),
31 32 33 34 35
  m_StartTag(0),
  m_EndTag(0),
  m_ProgressTag(0),
  m_Started(false),
  m_Ended(false)
36 37 38 39 40
{
}

FilterWatcherBase
::FilterWatcherBase(itk::ProcessObject* process,
41
                    const char *comment)
42 43 44 45 46 47 48
: m_Comment(comment),
  m_Process(process),
  m_StartTag(0),
  m_EndTag(0),
  m_ProgressTag(0),
  m_Started(false),
  m_Ended(false)
49 50 51 52 53
{
  // Create a series of commands
  m_StartFilterCommand = CommandType::New();
  m_EndFilterCommand = CommandType::New();
  m_ProgressFilterCommand = CommandType::New();
54

55 56
  // Assign the callbacks
  m_StartFilterCommand->SetCallbackFunction(this,
57
                                            &FilterWatcherBase::StartFilterCallback);
58
  m_EndFilterCommand->SetCallbackFunction(this,
59
                                          &FilterWatcherBase::EndFilterCallback);
60
  m_ProgressFilterCommand->SetCallbackFunction(this,
61
                                               &FilterWatcherBase::ShowProgressCallback);
62

63 64
  // Add the commands as observers
  m_StartTag = m_Process->AddObserver(itk::StartEvent(),
65
                                      m_StartFilterCommand);
66

67
  m_EndTag = m_Process->AddObserver(itk::EndEvent(),
68
                                    m_EndFilterCommand);
69

70
  m_ProgressTag = m_Process->AddObserver(itk::ProgressEvent(),
71
                                         m_ProgressFilterCommand);
72 73 74
}

FilterWatcherBase
OTB Bot's avatar
STYLE  
OTB Bot committed
75
::FilterWatcherBase(const FilterWatcherBase& watch)
76 77 78
{
  // Remove any observers we have on the old process object
  if (m_Process)
OTB Bot's avatar
STYLE  
OTB Bot committed
79 80 81
    {
    m_Process->RemoveAllObservers();
    }
82

83
  // Initialize state
84
  m_Stopwatch = watch.m_Stopwatch;
85 86
  m_Process = watch.m_Process;
  m_Comment = watch.m_Comment;
87

88 89 90
  m_StartTag = 0;
  m_EndTag = 0;
  m_ProgressTag = 0;
91 92
  m_Started = false;
  m_Ended = false;
93

94 95
  // Create a series of commands
  if (m_Process)
OTB Bot's avatar
STYLE  
OTB Bot committed
96
    {
97 98 99 100 101 102
    m_StartFilterCommand = CommandType::New();
    m_EndFilterCommand = CommandType::New();
    m_ProgressFilterCommand = CommandType::New();

    // Assign the callbacks
    m_StartFilterCommand->SetCallbackFunction(this,
103
                                              &FilterWatcherBase::StartFilterCallback);
104
    m_EndFilterCommand->SetCallbackFunction(this,
105
                                            &FilterWatcherBase::EndFilterCallback);
106
    m_ProgressFilterCommand->SetCallbackFunction(this,
107
                                                 &FilterWatcherBase::ShowProgressCallback);
108 109 110 111 112

    // Add the commands as observers
    m_StartTag = m_Process->AddObserver(itk::StartEvent(), m_StartFilterCommand);
    m_EndTag = m_Process->AddObserver(itk::EndEvent(), m_EndFilterCommand);
    m_ProgressTag
OTB Bot's avatar
STYLE  
OTB Bot committed
113 114
      = m_Process->AddObserver(itk::ProgressEvent(), m_ProgressFilterCommand);
    }
115 116 117 118
}

void
FilterWatcherBase
OTB Bot's avatar
STYLE  
OTB Bot committed
119
::operator =(const FilterWatcherBase& watch)
120 121 122
{
  // Remove any observers we have on the old process object
  if (m_Process)
OTB Bot's avatar
STYLE  
OTB Bot committed
123 124 125
    {
    m_Process->RemoveAllObservers();
    }
126

127
  // Initialize state
128
  m_Stopwatch = watch.m_Stopwatch;
129 130
  m_Process = watch.m_Process;
  m_Comment = watch.m_Comment;
131

132 133 134
  m_StartTag = 0;
  m_EndTag = 0;
  m_ProgressTag = 0;
135

136 137
  // Create a series of commands
  if (m_Process)
OTB Bot's avatar
STYLE  
OTB Bot committed
138
    {
139 140 141 142 143 144
    m_StartFilterCommand = CommandType::New();
    m_EndFilterCommand = CommandType::New();
    m_ProgressFilterCommand = CommandType::New();

    // Assign the callbacks
    m_StartFilterCommand->SetCallbackFunction(this,
145
                                              &FilterWatcherBase::StartFilterCallback);
146
    m_EndFilterCommand->SetCallbackFunction(this,
147
                                            &FilterWatcherBase::EndFilterCallback);
148
    m_ProgressFilterCommand->SetCallbackFunction(this,
149
                                                 &FilterWatcherBase::ShowProgressCallback);
150 151 152 153 154

    // Add the commands as observers
    m_StartTag = m_Process->AddObserver(itk::StartEvent(), m_StartFilterCommand);
    m_EndTag = m_Process->AddObserver(itk::EndEvent(), m_EndFilterCommand);
    m_ProgressTag
OTB Bot's avatar
STYLE  
OTB Bot committed
155 156
      = m_Process->AddObserver(itk::ProgressEvent(), m_ProgressFilterCommand);
    }
157 158 159 160 161 162 163
}

FilterWatcherBase
::~FilterWatcherBase()
{
  // Remove any observers we have on the old process object
  if (m_Process)
OTB Bot's avatar
STYLE  
OTB Bot committed
164 165 166
    {
    m_Process->RemoveAllObservers();
    }
167 168 169
}

} // end namespace otb