From: Leonardo Florez-Valencia Date: Mon, 9 Mar 2015 20:16:23 +0000 (-0500) Subject: More tests X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=97940c7ac873a39428e8739b2d47ca8485cff70e;p=FrontAlgorithms.git More tests --- diff --git a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx index 3b354ba..b3c04eb 100644 --- a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx +++ b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx @@ -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 { diff --git a/appli/examples/example_ImageAlgorithm_Skeletonization.cxx b/appli/examples/example_ImageAlgorithm_Skeletonization.cxx index 98023c5..e0121bd 100644 --- a/appli/examples/example_ImageAlgorithm_Skeletonization.cxx +++ b/appli/examples/example_ImageAlgorithm_Skeletonization.cxx @@ -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( ); } diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index fc94fa8..11cd447 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -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 ); diff --git a/lib/fpa/Base/Events.h b/lib/fpa/Base/Events.h index b7b9f4e..ad662ab 100644 --- a/lib/fpa/Base/Events.h +++ b/lib/fpa/Base/Events.h @@ -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 diff --git a/lib/fpa/VTK/Image3DObserver.h b/lib/fpa/VTK/Image3DObserver.h index 4e7a430..344ede4 100644 --- a/lib/fpa/VTK/Image3DObserver.h +++ b/lib/fpa/VTK/Image3DObserver.h @@ -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; 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__