ITK/Examples/Utilities/ObserveEvent: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Need a real image.)
(Deprecated content that is moved to sphinx)
 
Line 1: Line 1:
This example demonstrates how to observe and event that is invoked by a filter.
{{warning|1=The media wiki content on this page is no longer maintained.  The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releases.  In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
}}


==ObserveEvent.cxx==
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
<source lang="cpp">
#include "itkBinaryNotImageFilter.h"
#include "itkCommand.h"
 
typedef itk::Image<unsigned char, 2>  ImageType;
static void CreateImageObserve(ImageType::Pointer image);
 
typedef itk::Image<unsigned char, 2>  ImageType;
 
class MyCommand : public itk::Command
{
  public:
    itkNewMacro( MyCommand );
 
  public:
 
    void Execute(itk::Object *caller, const itk::EventObject & event)
    {
      Execute( (const itk::Object *)caller, event);
    }
 
    void Execute(const itk::Object * object, const itk::EventObject & event)
    {
      std::cout << "Command called." << std::endl;
    }
 
};
 
int main(int, char*[])
{
  ImageType::Pointer image = ImageType::New();
  CreateImageObserve(image);
 
  typedef itk::BinaryNotImageFilter <ImageType>
          BinaryNotImageFilterType;
 
  BinaryNotImageFilterType::Pointer filter = BinaryNotImageFilterType::New();
  filter->SetInput(image);
 
  MyCommand::Pointer myCommand = MyCommand::New();
  filter->AddObserver(itk::ProgressEvent(), myCommand);
 
  filter->Update();
 
 
  return EXIT_SUCCESS;
}
 
void CreateImageObserve(ImageType::Pointer image)
{
  // Create an image
  ImageType::IndexType start;
  start.Fill(0);
 
  ImageType::SizeType size;
  size.Fill(100);
 
  ImageType::RegionType region(start, size);
 
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(0);
 
}
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 18:18, 31 May 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.

[ITK Sphinx Examples]