ITK/Examples/Utilities/ObserveEvent

From KitwarePublic
< ITK‎ | Examples
Revision as of 00:26, 1 February 2011 by Daviddoria (talk | contribs) (Created page with "This example demonstrates how to observe and event that is invoked by a filter. ==ObserveEvent.cxx== <source lang="cpp"> #include "itkBinaryNotImageFilter.h" #include "itkComman...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This example demonstrates how to observe and event that is invoked by a filter.

ObserveEvent.cxx

<source lang="cpp">

  1. include "itkBinaryNotImageFilter.h"
  2. include "itkCommand.h"

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();
 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;

}

</source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(ObserveEvent)

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(ObserveEvent ObserveEvent.cpp) TARGET_LINK_LIBRARIES(ObserveEvent ITKCommon)


</source>