ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Core/Common/ObserveAnEvent/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* 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.
*
*=========================================================================*/
#include "itkImage.h"
#include "itkCommand.h"
class MyCommand : public itk::Command
{
public:
itkNewMacro(MyCommand);
void
Execute(itk::Object * caller, const itk::EventObject & event) override
{
Execute((const itk::Object *)caller, event);
}
void
Execute(const itk::Object * caller, const itk::EventObject & event) override
{
if (!itk::ProgressEvent().CheckEvent(&event))
{
return;
}
const auto * processObject = dynamic_cast<const itk::ProcessObject *>(caller);
if (!processObject)
{
return;
}
std::cout << "Progress: " << processObject->GetProgress() << std::endl;
}
};
int
main()
{
constexpr unsigned int Dimension = 2;
using PixelType = unsigned char;
auto source = SourceType::New();
size.Fill(128);
source->SetSize(size);
SourceType::ArrayType sigma;
sigma.Fill(45.0);
source->SetSigma(sigma);
auto myCommand = MyCommand::New();
source->AddObserver(itk::ProgressEvent(), myCommand);
source->Update();
return EXIT_SUCCESS;
}
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:211
itk::Command
Superclass for callback/observer methods.
Definition: itkCommand.h:45
itk::Command::Execute
virtual void Execute(Object *caller, const EventObject &event)=0
itk::GaussianImageSource
Generate an n-dimensional image of a Gaussian.
Definition: itkGaussianImageSource.h:45
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:58
New
static Pointer New()
itkGaussianImageSource.h
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itkCommand.h