]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/VTK/Image3DObserver.hxx
Almost there...
[FrontAlgorithms.git] / lib / fpa / VTK / Image3DObserver.hxx
index 46ef743729d70197309dd18c9f505a1b395138f3..721a89d5309f60c635134b8d6446069a8f263d03 100644 (file)
@@ -28,14 +28,18 @@ 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 typename F::TBacktrackingEvent    _TBacktrackingEvent;
+  typedef itk::ImageBase< 3 >         _TImage;
+  typedef typename F::TStartEvent     _TStartEvent;
+  typedef typename F::TStartLoopEvent _TStartLoopEvent;
+  typedef typename F::TEndEvent       _TEndEvent;
+  typedef typename F::TEndLoopEvent   _TEndLoopEvent;
+  typedef typename F::TAliveEvent     _TAliveEvent;
+  typedef typename F::TFrontEvent     _TFrontEvent;
+  typedef typename F::TFreezeEvent    _TFreezeEvent;
+
+  typedef typename F::TStartBacktrackingEvent _TStartBacktrackingEvent;
   typedef typename F::TEndBacktrackingEvent _TEndBacktrackingEvent;
+  typedef typename F::TBacktrackingEvent _TBacktrackingEvent;
 
   // Check inputs
   if( this->m_RenderWindow == NULL )
@@ -51,122 +55,118 @@ Execute( const itk::Object* c, const itk::EventObject& e )
   if( image == NULL )
     return;
 
-  // Create actor
-  _TImage::RegionType reg = image->GetLargestPossibleRegion( );
-  _TImage::SizeType siz = reg.GetSize( );
-  if( this->m_Data.GetPointer( ) == NULL )
+  const _TStartEvent* startEvt = dynamic_cast< const _TStartEvent* >( &e );
+  const _TStartBacktrackingEvent* startBackEvt =
+    dynamic_cast< const _TStartBacktrackingEvent* >( &e );
+  if( startEvt != NULL || startBackEvt != NULL )
   {
-    this->m_Data   = vtkSmartPointer< vtkPolyData >::New( );
-    this->m_Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
-    this->m_Actor  = vtkSmartPointer< vtkActor >::New( );
-
-    vtkSmartPointer< vtkPoints > points =
-      vtkSmartPointer< vtkPoints >::New( );
-    vtkSmartPointer< vtkCellArray > vertices =
-      vtkSmartPointer< vtkCellArray >::New( );
-    vtkSmartPointer< vtkFloatArray > scalars =
-      vtkSmartPointer< vtkFloatArray >::New( );
-    this->m_Data->SetPoints( points );
-    this->m_Data->SetVerts( vertices );
-    this->m_Data->GetPointData( )->SetScalars( scalars );
-
-    this->m_Mapper->SetInputData( this->m_Data );
-    this->m_Actor->SetMapper( this->m_Mapper );
-    ren->AddActor( this->m_Actor );
-
-    this->m_Marks = TMarks::New( );
-    this->m_Marks->SetLargestPossibleRegion(
-      image->GetLargestPossibleRegion( )
-      );
-    this->m_Marks->SetRequestedRegion( image->GetRequestedRegion( ) );
-    this->m_Marks->SetBufferedRegion( image->GetBufferedRegion( ) );
-    this->m_Marks->SetOrigin( image->GetOrigin( ) );
-    this->m_Marks->SetSpacing( image->GetSpacing( ) );
-    this->m_Marks->SetDirection( image->GetDirection( ) );
-    this->m_Marks->Allocate( );
-    this->m_Marks->FillBuffer( -1 );
-    this->m_Count = 0;
-    this->m_RenderCount = reg.GetNumberOfPixels( );
+    // Create actor
+    _TImage::RegionType reg = image->GetLargestPossibleRegion( );
+    _TImage::SizeType siz = reg.GetSize( );
+    if( this->m_Data.GetPointer( ) == NULL )
+    {
+      this->m_Data   = vtkSmartPointer< vtkPolyData >::New( );
+      this->m_Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+      this->m_Actor  = vtkSmartPointer< vtkActor >::New( );
+
+      vtkSmartPointer< vtkPoints > points =
+        vtkSmartPointer< vtkPoints >::New( );
+      vtkSmartPointer< vtkCellArray > vertices =
+        vtkSmartPointer< vtkCellArray >::New( );
+      vtkSmartPointer< vtkFloatArray > scalars =
+        vtkSmartPointer< vtkFloatArray >::New( );
+      this->m_Data->SetPoints( points );
+      this->m_Data->SetVerts( vertices );
+      this->m_Data->GetPointData( )->SetScalars( scalars );
+
+      this->m_Mapper->SetInputData( this->m_Data );
+      this->m_Actor->SetMapper( this->m_Mapper );
+      ren->AddActor( this->m_Actor );
+
+      this->m_Marks = TMarks::New( );
+      this->m_Marks->SetLargestPossibleRegion(
+        image->GetLargestPossibleRegion( )
+        );
+      this->m_Marks->SetRequestedRegion( image->GetRequestedRegion( ) );
+      this->m_Marks->SetBufferedRegion( image->GetBufferedRegion( ) );
+      this->m_Marks->SetOrigin( image->GetOrigin( ) );
+      this->m_Marks->SetSpacing( image->GetSpacing( ) );
+      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
+    } // fi
+    return;
 
-  // Get possible events
-  const _TEvent* evt = dynamic_cast< const _TEvent* >( &e );
-  _TFrontEvent fevt;
-  _TMarkEvent mevt;
-  _TCollisionEvent cevt;
-  _TEndEvent eevt;
+  } // fi
 
-  if( evt != NULL )
+  const _TAliveEvent* aliveEvt = dynamic_cast< const _TAliveEvent* >( &e );
+  const _TFrontEvent* frontEvt = dynamic_cast< const _TFrontEvent* >( &e );
+  if( aliveEvt != NULL || frontEvt != NULL )
   {
-    if( fevt.CheckEvent( evt ) )
-    {
-      if( this->m_Marks->GetPixel( evt->Node.Vertex ) == -1 )
-      {
-        typename _TImage::PointType pnt;
-        image->TransformIndexToPhysicalPoint( evt->Node.Vertex, 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( 0.5 );
-        this->m_Data->Modified( );
-
-        this->m_Marks->SetPixel( evt->Node.Vertex, pId );
-        this->m_Count++;
-
-        // 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;
-
-      } // fi
-      return;
-    }
-    else if( mevt.CheckEvent( evt ) )
+    _TImage::IndexType vertex;
+    if( aliveEvt != NULL )
+      vertex = aliveEvt->Vertex;
+    else if( frontEvt != NULL )
+      vertex = frontEvt->Vertex;
+
+    if( this->m_Marks->GetPixel( vertex ) == -1 )
     {
-      // TODO: std::cout << "mark" << std::endl;
-      return;
+      typename _TImage::PointType pnt;
+      image->TransformIndexToPhysicalPoint( vertex, pnt );
 
-    } // fi
+      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( 0.5 );
+      this->m_Data->Modified( );
 
-    if( cevt.CheckEvent( evt ) )
-    {
-      // TODO: std::cout << "collision" << std::endl;
-      return;
+      this->m_Marks->SetPixel( vertex, pId );
+      this->m_Count++;
+
+      // 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;
 
     } // fi
+    return;
 
-    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
 
-    } // fi
-  }
-  else
+  const _TEndEvent* endEvt = dynamic_cast< const _TEndEvent* >( &e );
+  if( endEvt != NULL )
+  {
+    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
+
+
+  const _TBacktrackingEvent* backEvt =
+    dynamic_cast< const _TBacktrackingEvent* >( &e );
+  const _TEndBacktrackingEvent* endBackEvt =
+    dynamic_cast< const _TEndBacktrackingEvent* >( &e );
+  if( backEvt != NULL )
   {
-    const _TBacktrackingEvent* bevt =
-      dynamic_cast< const _TBacktrackingEvent* >( &e );
-    const _TEndBacktrackingEvent* ebevt =
-      dynamic_cast< const _TEndBacktrackingEvent* >( &e );
-    if( bevt != NULL )
-    {
       static const unsigned long nColors = 10;
-      double back_id = double( bevt->BackId % nColors ) / double( nColors );
+      double back_id =
+        double( backEvt->FrontId % nColors ) / double( nColors );
       typename _TImage::PointType pnt;
-      image->TransformIndexToPhysicalPoint( bevt->Node, pnt );
+      image->TransformIndexToPhysicalPoint( backEvt->Vertex, pnt );
 
       long pId = this->m_Data->GetNumberOfPoints( );
       this->m_Data->GetVerts( )->InsertNextCell( 1 );
@@ -180,14 +180,17 @@ Execute( const itk::Object* c, const itk::EventObject& e )
 
     } // fi
 
-    if( ebevt != NULL )
+    if( endBackEvt != NULL )
     {
       this->m_RenderWindow->Render( );
+      /* TODO: DEBUG
+         std::cout << "Press enter: " << std::ends;
+         int aux;
+         std::cin >> aux;
+      */
       return;
 
     } // fi
-
-  } // fi
 }
 
 // -------------------------------------------------------------------------