]> Creatis software - FrontAlgorithms.git/commitdiff
More tests
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 9 Mar 2015 20:16:23 +0000 (15:16 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 9 Mar 2015 20:16:23 +0000 (15:16 -0500)
appli/examples/example_ImageAlgorithmDijkstra_03.cxx
appli/examples/example_ImageAlgorithm_Skeletonization.cxx
lib/fpa/Base/Algorithm.h
lib/fpa/Base/Events.h
lib/fpa/VTK/Image3DObserver.h
lib/fpa/VTK/Image3DObserver.hxx

index 3b354baf3b1dfcc2728596a24a0bceddbbc705cc..b3c04eb033305d165caf2f62a0e98e05427ca5cb 100644 (file)
@@ -54,6 +54,9 @@ public:
   typedef Superclass::InputImageType TImage;
   typedef std::deque< TVertex >      TVertices;
 
+  typedef Superclass::TEndEvent          TEndEvent;
+  typedef Superclass::TBacktrackingEvent TBacktrackingEvent;
+
 protected:
   typedef std::pair< TCost, TVertex >     _TCandidate;
   typedef std::multimap< TCost, TVertex > _TCandidates;
@@ -119,6 +122,8 @@ protected:
       if( this->m_Candidates.size( ) == 0 )
         return;
 
+      this->InvokeEvent( TEndEvent( ) );
+
       const TImage* input = this->GetInput( );
       TImage::SpacingType spacing = input->GetSpacing( );
 
@@ -137,7 +142,7 @@ protected:
       // are near thin branches
       _TCandidates::const_reverse_iterator cIt =
         this->m_Candidates.rbegin( );
-      for( int leo = 0; leo < 1 && cIt != this->m_Candidates.rend( ); ++cIt )
+      for( int backId = 0; backId < 100 && cIt != this->m_Candidates.rend( ); ++cIt )
       {
         // If pixel hasn't been visited, continue
         TVertex v = cIt->second;
@@ -170,8 +175,8 @@ protected:
 
         if( marks->GetPixel( max_vertex ) != _TMark( 0 ) )
           continue;
-        leo++;
-        std::cout << "Leaf: " << leo << " " << max_value << " " << max_vertex << std::endl;
+        backId++;
+        std::cout << "Leaf: " << backId << " " << max_value << " " << max_vertex << std::endl;
 
         bool start = true;
         do
@@ -210,6 +215,7 @@ protected:
             start = false;
           */
           // Next vertex in current path
+          this->InvokeEvent( TBacktrackingEvent( max_vertex, backId ) );
           max_vertex = this->_Parent( max_vertex );
 
         } while( max_vertex != this->_Parent( max_vertex ) );
@@ -221,14 +227,14 @@ protected:
         } // rof
       */
 
-      itk::ImageFileWriter< _TMarkImage >::Pointer w =
-        itk::ImageFileWriter< _TMarkImage >::New( );
-      w->SetInput( marks );
-      w->SetFileName( "marks.mhd" );
-      w->Update( );
-
       /*
-
+        itk::ImageFileWriter< _TMarkImage >::Pointer w =
+        itk::ImageFileWriter< _TMarkImage >::New( );
+        w->SetInput( marks );
+        w->SetFileName( "marks.mhd" );
+        w->Update( );
+        
+        
         this->m_Axes = vtkSmartPointer< vtkPolyData >::New( );
         vtkSmartPointer< vtkPoints > points =
         vtkSmartPointer< vtkPoints >::New( );
@@ -237,8 +243,8 @@ protected:
 
         {
 
-        leo++;
-        std::cout << "Leaf: " << leo << " " << cIt->first << " " << vIt << std::endl;
+        backId++;
+        std::cout << "Leaf: " << backId << " " << cIt->first << " " << vIt << std::endl;
         bool start = true;
         do
         {
index 98023c5353fec0bae3708ffd7045a55df4cbd29c..e0121bd6ba9c173d41a532a56e6d0cb0c507e1b8 100644 (file)
@@ -108,7 +108,7 @@ int main( int argc, char* argv[] )
   {
     // Configure observer
     TSegmentorObs::Pointer obs = TSegmentorObs::New( );
-    obs->SetImage( input_image, view.GetWindow( ) );
+    obs->SetRenderWindow( view.GetWindow( ) );
     segmentor->AddObserver( itk::AnyEvent( ), obs );
     segmentor->ThrowEventsOn( );
   }
index fc94fa85fb3dde3a52398ca30749e6e6a626383b..11cd4475f7b85485f75fc777d66bcde49c90c5d3 100644 (file)
@@ -50,11 +50,12 @@ namespace fpa
       typedef std::vector< _TCollisionSitesRow > _TCollisionSites;
 
     public:
-      typedef BaseEvent< _TNode >      TEvent;
-      typedef FrontEvent< _TNode >     TFrontEvent;
-      typedef MarkEvent< _TNode >      TMarkEvent;
-      typedef CollisionEvent< _TNode > TCollisionEvent;
-      typedef EndEvent< _TNode >       TEndEvent;
+      typedef BaseEvent< _TNode >          TEvent;
+      typedef FrontEvent< _TNode >         TFrontEvent;
+      typedef MarkEvent< _TNode >          TMarkEvent;
+      typedef CollisionEvent< _TNode >     TCollisionEvent;
+      typedef EndEvent< _TNode >           TEndEvent;
+      typedef BacktrackingEvent< TVertex > TBacktrackingEvent;
 
     public:
       itkTypeMacro( Algorithm, itkProcessObject );
index b7b9f4ed32118ee53296c94cfa3df7bd5c91b670..ad662abdf65d90886ba730d0d3e4dee81e7c3bb3 100644 (file)
@@ -127,6 +127,36 @@ namespace fpa
         { return( new EndEvent< N >( ) ); }
     };
 
+    /**
+     */
+    template< class N >
+    class BacktrackingEvent
+      : public BaseEvent< N >
+    {
+    public:
+      BacktrackingEvent( )
+        : BaseEvent< N >( )
+        { }
+      BacktrackingEvent( const N& n, const unsigned long& id )
+        : BaseEvent< N >( n ),
+          BackId( id )
+        { }
+      virtual ~BacktrackingEvent( )
+        { }
+      const char* GetEventName( ) const
+        { return( "fpa::Base::BacktrackingEvent" ); }
+      bool CheckEvent( const itk::EventObject* e ) const
+        {
+          return(
+            dynamic_cast< const BacktrackingEvent< N >* >( e ) != NULL
+            );
+        }
+      itk::EventObject* MakeObject( ) const
+        { return( new BacktrackingEvent< N >( ) ); }
+
+      unsigned long BackId;
+    };
+
   } // ecapseman
 
 } // ecapseman
index 4e7a43082a48c19bcd4a7043e792234a85a8e79a..344ede4bf0d599058456f2ffae4bd97a5cfacdfe 100644 (file)
@@ -36,6 +36,9 @@ namespace fpa
       itkNewMacro( Self );
       itkTypeMacro( Image3DObserver, itkCommand );
 
+      itkGetConstMacro( RenderPercentage, double );
+      itkSetMacro( RenderPercentage, double );
+
     public:
       void SetRenderWindow( R* rw );
       void Execute( itk::Object* c, const itk::EventObject& e )
@@ -55,6 +58,7 @@ namespace fpa
       R*            m_RenderWindow;
       unsigned long m_Count;
       unsigned long m_RenderCount;
+      double        m_RenderPercentage;
 
       TMarks::Pointer                      m_Marks;
       vtkSmartPointer< vtkPolyData >       m_Data;
index ff4e6456e50928abb657f67c7962d3f758ff9795..001924a70c077cd1ecfcf7e4070fac1adb898ec3 100644 (file)
@@ -21,20 +21,6 @@ void fpa::VTK::Image3DObserver< F, R >::
 SetRenderWindow( R* rw )
 {
   this->m_RenderWindow = rw;
-  /*
-    if( this->m_RenderWindow != NULL )
-    {
-    vtkRenderer* ren =
-    this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( );
-    if( ren != NULL )
-    {
-    ren->AddActor( this->m_PolyDataActor );
-    this->m_RenderWindow->Render( );
-
-    } // fi
-
-    } // fi
-  */
 }
 
 // -------------------------------------------------------------------------
@@ -42,12 +28,13 @@ template< class F, class R >
 void fpa::VTK::Image3DObserver< F, R >::
 Execute( const itk::Object* c, const itk::EventObject& e )
 {
-  typedef itk::ImageBase< 3 >         _TImage;
-  typedef typename F::TEvent          _TEvent;
-  typedef typename F::TFrontEvent     _TFrontEvent;
-  typedef typename F::TMarkEvent      _TMarkEvent;
-  typedef typename F::TCollisionEvent _TCollisionEvent;
-  typedef typename F::TEndEvent       _TEndEvent;
+  typedef itk::ImageBase< 3 >            _TImage;
+  typedef typename F::TEvent             _TEvent;
+  typedef typename F::TFrontEvent        _TFrontEvent;
+  typedef typename F::TMarkEvent         _TMarkEvent;
+  typedef typename F::TCollisionEvent    _TCollisionEvent;
+  typedef typename F::TEndEvent          _TEndEvent;
+  typedef typename F::TBacktrackingEvent _TBacktrackingEvent;
 
   // Check inputs
   if( this->m_RenderWindow == NULL )
@@ -97,16 +84,18 @@ Execute( const itk::Object* c, const itk::EventObject& e )
     this->m_Marks->SetDirection( image->GetDirection( ) );
     this->m_Marks->Allocate( );
     this->m_Marks->FillBuffer( -1 );
+    this->m_Count = 0;
+    this->m_RenderCount = reg.GetNumberOfPixels( );
 
   } // fi
 
-
   // Get possible events
   const _TEvent* evt = dynamic_cast< const _TEvent* >( &e );
   _TFrontEvent fevt;
   _TMarkEvent mevt;
   _TCollisionEvent cevt;
   _TEndEvent eevt;
+
   if( evt != NULL )
   {
     if( fevt.CheckEvent( evt ) )
@@ -126,77 +115,69 @@ Execute( const itk::Object* c, const itk::EventObject& e )
         this->m_Data->Modified( );
 
         this->m_Marks->SetPixel( evt->Node.Vertex, pId );
+        this->m_Count++;
 
-      } // fi
-      this->m_RenderWindow->Render( );
+        // Render visual debug
+        double per = double( this->m_RenderCount ) * this->m_RenderPercentage;
+        if( double( this->m_Count ) >= per )
+          this->m_RenderWindow->Render( );
+        if( double( this->m_Count ) >= per )
+          this->m_Count = 0;
 
-      /* TODO
-         if(
-         this->m_Vertices.find( evt->Node.Vertex ) == this->m_Vertices.end( )
-         )
-         {
-         unsigned long pId = this->m_PolyData->GetPoints( )->InsertNextPoint(
-         double( pnt[ 0 ] ), double( pnt[ 1 ] ), double( pnt[ 2 ] )
-         );
-         unsigned long cId = this->m_PolyData->GetVerts( )->InsertNextCell( 1 );
-         this->m_PolyData->GetVerts( )->InsertCellPoint( pId );
-         this->m_PolyData->Modified( );
-         this->m_Vertices[ evt->Node.Vertex ] = TVertexIds( pId, cId );
-
-         } // rof
-      */
+      } // fi
+      return;
     }
     else if( mevt.CheckEvent( evt ) )
     {
-      /*
-        typename TVertices::iterator vIt =
-        this->m_Vertices.find( evt->Node.Vertex );
-        if( vIt != this->m_Vertices.end( ) )
-        {
-        std::cout << "Erase " << evt->Node.Vertex << " " << vIt->second.second << std::endl;
-        } // fi
-      */
+      // TODO: std::cout << "mark" << std::endl;
+      return;
+
     } // fi
 
     if( cevt.CheckEvent( evt ) )
     {
       // TODO: std::cout << "collision" << std::endl;
+      return;
+
+    } // fi
+
+    if( eevt.CheckEvent( evt ) )
+    {
+      this->m_RenderWindow->Render( );
+      ren->RemoveActor( this->m_Actor );
+      this->m_RenderWindow->Render( );
+      this->m_Marks = NULL;
+      this->m_Data = NULL;
+      this->m_Mapper = NULL;
+      this->m_Actor = NULL;
+      return;
+
+    } // fi
+  }
+  else
+  {
+    const _TBacktrackingEvent* bevt =
+      dynamic_cast< const _TBacktrackingEvent* >( &e );
+    if( bevt != NULL )
+    {
+      static const unsigned long nColors = 10;
+      double back_id = double( bevt->BackId % nColors ) / double( nColors );
+      typename _TImage::PointType pnt;
+      image->TransformIndexToPhysicalPoint( bevt->Node, pnt );
+
+      long pId = this->m_Data->GetNumberOfPoints( );
+      this->m_Data->GetVerts( )->InsertNextCell( 1 );
+      this->m_Data->GetVerts( )->InsertCellPoint( pId );
+      this->m_Data->GetPoints( )->
+        InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
+      this->m_Data->GetPointData( )->
+        GetScalars( )->InsertNextTuple1( back_id );
+      this->m_Data->Modified( );
+      this->m_RenderWindow->Render( );
+
+      return;
 
     } // fi
-    /*
-      this->SetPixel(
-      evt->Node.Vertex,
-      Colors[ evt->Node.FrontId ][ 0 ],
-      Colors[ evt->Node.FrontId ][ 1 ],
-      Colors[ evt->Node.FrontId ][ 2 ],
-      Colors[ evt->Node.FrontId ][ 3 ]
-      );
-      else if( mevt.CheckEvent( evt ) )
-      this->SetPixel( evt->Node.Vertex, 255, 0, 0, 255 );
-
-      if( cevt.CheckEvent( evt ) )
-      this->SetPixel( evt->Node.Vertex, 100, 50, 25, 255 );
-    */
-    
-    // Update visualization
-    /* TODO
-       if( this->m_Number == 0 || this->m_Percentage < 0 )
-       this->Render( );
-       this->m_Number++;
-       this->m_Number %= this->m_Percentage;
-       if( eevt.CheckEvent( evt ) )
-       {
-       if( this->m_RenderWindow != NULL )
-       {
-       vtkRenderer* ren =
-       this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( );
-       ren->RemoveActor( this->m_PolyDataActor );
-       this->Render( );
-
-       } // fi
-
-       } // fi
-    */
 
   } // fi
 }
@@ -206,20 +187,9 @@ template< class F, class R >
 fpa::VTK::Image3DObserver< F, R >::
 Image3DObserver( )
   : Superclass( ),
-    m_RenderWindow( NULL )
+    m_RenderWindow( NULL ),
+    m_RenderPercentage( double( 0.0001 ) )
 {
-  /*
-    this->m_PolyData = vtkSmartPointer< vtkPolyData >::New( );
-    this->m_PolyDataMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
-    this->m_PolyDataActor = vtkSmartPointer< vtkActor >::New( );
-
-    this->m_PolyData->SetPoints( vtkPoints::New( ) );
-    this->m_PolyData->SetVerts( vtkCellArray::New( ) );
-
-    this->m_PolyDataMapper->SetInputData( this->m_PolyData );
-    this->m_PolyDataActor->SetMapper( this->m_PolyDataMapper );
-    this->m_PolyDataActor->GetProperty( )->SetColor( 0, 0, 1 );
-  */
 }
 
 #endif // __FPA__VTK__IMAGE3DOBSERVER__HXX__