]> Creatis software - FrontAlgorithms.git/blob - examples/MoriRegionGrow_00.cxx
d0dabff9eca404d19327bce07a350a6007b71153
[FrontAlgorithms.git] / examples / MoriRegionGrow_00.cxx
1 #include <itkCommand.h>
2 #include <itkImage.h>
3 #include <itkImageFileReader.h>
4 #include <itkImageFileWriter.h>
5 #include <fpa/Image/MoriRegionGrow.h>
6
7 // -------------------------------------------------------------------------
8 typedef itk::Image< unsigned char, 2 >               TImage;
9 typedef itk::ImageFileReader< TImage >               TReader;
10 typedef itk::ImageFileWriter< TImage >               TWriter;
11 typedef fpa::Image::MoriRegionGrow< TImage, TImage > TFilter;
12
13 // -------------------------------------------------------------------------
14 /**
15  */
16 class MyObserver
17   : public itk::Command
18 {
19 public:
20   typedef TFilter::TStartEvent     TStartEvent;
21   typedef TFilter::TEndEvent       TEndEvent;
22   typedef TFilter::TStartLoopEvent TStartLoopEvent;
23   typedef TFilter::TEndLoopEvent   TEndLoopEvent;
24   typedef TFilter::TPushEvent      TPushEvent;
25   typedef TFilter::TPopEvent       TPopEvent;
26   typedef TFilter::TMarkEvent      TMarkEvent;
27
28 public:
29   itkNewMacro( MyObserver );
30
31 public:
32   virtual void Execute(
33     itk::Object* caller, const itk::EventObject& event
34     ) override
35     {
36       this->Execute( const_cast< const itk::Object* >( caller ), event );
37     }
38   virtual void Execute(
39     const itk::Object* object, const itk::EventObject& event
40     ) override
41     {
42       /* TODO
43          if( TStartEvent( ).CheckEvent( &event ) )
44          std::cout << "Start" << std::endl;
45          else if( TEndEvent( ).CheckEvent( &event ) )
46          std::cout << "End" << std::endl;
47          else if( TStartLoopEvent( ).CheckEvent( &event ) )
48          std::cout << "StartLoop" << std::endl;
49          else if( TEndLoopEvent( ).CheckEvent( &event ) )
50          std::cout << "EndLoop" << std::endl;
51          else if( TMarkEvent( ).CheckEvent( &event ) )
52          {
53          const TMarkEvent* mark = dynamic_cast< const TMarkEvent* >( &event );
54          std::cout << "Mark: " << mark->Vertex << std::endl;
55
56          } // fi
57       */
58       /* TODO
59          TPushEvent;
60          TPopEvent;
61       */
62     }
63 };
64
65 // -------------------------------------------------------------------------
66 int main( int argc, char* argv[] )
67 {
68   if( argc < 3 )
69   {
70     std::cerr
71       << "Usage: " << argv[ 0 ]
72       << " input_filename output_filename" << std::endl;
73     return( 1 );
74
75   } // fi
76   std::string in_fname = argv[ 1 ];
77   std::string out_fname = argv[ 2 ];
78   int seed_x = 111;
79   int seed_y = 91;
80
81   TReader::Pointer reader = TReader::New( );
82   reader->SetFileName( in_fname );
83
84   TImage::IndexType seed;
85   seed[ 0 ] = seed_x;
86   seed[ 1 ] = seed_y;
87
88   TFilter::Pointer filter = TFilter::New( );
89   filter->SetInput( reader->GetOutput( ) );
90   filter->SetLower( 0 );
91   filter->SetUpper( 255 );
92   filter->SetStep( 1 );
93   filter->SetInsideValue( 255 );
94   filter->SetOutsideValue( 0 );
95   filter->AddSeed( seed, filter->GetInsideValue( ) );
96
97   /* TODO
98      MyObserver::Pointer obs = MyObserver::New( );
99      filter->AddObserver( itk::AnyEvent( ), obs );
100   */
101
102   TWriter::Pointer writer = TWriter::New( );
103   writer->SetInput( filter->GetOutput( ) );
104   writer->SetFileName( out_fname );
105   writer->Update( );
106
107   return( 0 );
108 }
109
110 // eof - $RCSfile$