1 #include <itkCommand.h>
3 #include <itkImageFileWriter.h>
4 #include <fpa/Image/RegionGrow.h>
6 // -------------------------------------------------------------------------
7 typedef itk::Image< unsigned char, 2 > TImage;
8 typedef fpa::Image::RegionGrow< TImage, TImage > TFilter;
9 typedef itk::ImageFileWriter< TImage > TWriter;
11 // -------------------------------------------------------------------------
18 typedef TFilter::TStartEvent TStartEvent;
19 typedef TFilter::TEndEvent TEndEvent;
20 typedef TFilter::TStartLoopEvent TStartLoopEvent;
21 typedef TFilter::TEndLoopEvent TEndLoopEvent;
22 typedef TFilter::TPushEvent TPushEvent;
23 typedef TFilter::TPopEvent TPopEvent;
24 typedef TFilter::TMarkEvent TMarkEvent;
27 itkNewMacro( MyObserver );
31 itk::Object* caller, const itk::EventObject& event
34 this->Execute( const_cast< const itk::Object* >( caller ), event );
37 const itk::Object* object, const itk::EventObject& event
40 if( TStartEvent( ).CheckEvent( &event ) )
41 std::cout << "Start" << std::endl;
42 else if( TEndEvent( ).CheckEvent( &event ) )
43 std::cout << "End" << std::endl;
44 else if( TStartLoopEvent( ).CheckEvent( &event ) )
45 std::cout << "StartLoop" << std::endl;
46 else if( TEndLoopEvent( ).CheckEvent( &event ) )
47 std::cout << "EndLoop" << std::endl;
48 else if( TMarkEvent( ).CheckEvent( &event ) )
50 const TMarkEvent* mark = dynamic_cast< const TMarkEvent* >( &event );
51 std::cout << "Mark: " << mark->Vertex << std::endl;
61 // -------------------------------------------------------------------------
62 int main( int argc, char* argv[] )
64 TImage::SizeType size;
67 TImage::Pointer input = TImage::New( );
68 input->SetRegions( size );
70 input->FillBuffer( 0 );
72 TImage::RegionType region = input->GetLargestPossibleRegion( );
73 TImage::PointType p0, p1, p2;
74 input->TransformIndexToPhysicalPoint( region.GetIndex( ), p0 );
75 input->TransformIndexToPhysicalPoint(
76 region.GetIndex( ) + region.GetSize( ), p1
78 p2 = ( p0.GetVectorFromOrigin( ) + p1.GetVectorFromOrigin( ) ) * 0.5;
79 TImage::IndexType seed;
80 input->TransformPhysicalPointToIndex( p2, seed );
82 TFilter::Pointer filter = TFilter::New( );
83 filter->SetInput( input );
84 filter->SetInsideValue( 255 );
85 filter->SetOutsideValue( 0 );
86 filter->AddSeed( seed, filter->GetInsideValue( ) );
88 MyObserver::Pointer obs = MyObserver::New( );
89 filter->AddObserver( itk::AnyEvent( ), obs );
92 TWriter::Pointer writer = TWriter::New( );
93 writer->SetInput( filter->GetOutput( ) );
94 writer->SetFileName( "RegionGrow_00.png" );