|
|
(2 intermediate revisions by one other user not shown) |
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;
| |
| | |
| 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>
| |
| | |
| {{ITKCMakeLists|ObserveEvent}}
| |