X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FVTK%2FImage3DObserver.hxx;h=001924a70c077cd1ecfcf7e4070fac1adb898ec3;hb=97940c7ac873a39428e8739b2d47ca8485cff70e;hp=ff4e6456e50928abb657f67c7962d3f758ff9795;hpb=818377732bc3fd1b02ca56bc78c225345a5fac27;p=FrontAlgorithms.git diff --git a/lib/fpa/VTK/Image3DObserver.hxx b/lib/fpa/VTK/Image3DObserver.hxx index ff4e645..001924a 100644 --- a/lib/fpa/VTK/Image3DObserver.hxx +++ b/lib/fpa/VTK/Image3DObserver.hxx @@ -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__