From: Leonardo Florez-Valencia Date: Fri, 13 Feb 2015 21:57:13 +0000 (-0500) Subject: Some tests... Package is unstable right nowgit status! X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=22051707794a9153acbfc489ec9a933471f13406;p=FrontAlgorithms.git Some tests... Package is unstable right nowgit status! --- diff --git a/appli/examples/example_ImageAlgorithmRegionGrow_MultipleThresholds.cxx b/appli/examples/example_ImageAlgorithmRegionGrow_MultipleThresholds.cxx index 165dafb..1f4bf3f 100644 --- a/appli/examples/example_ImageAlgorithmRegionGrow_MultipleThresholds.cxx +++ b/appli/examples/example_ImageAlgorithmRegionGrow_MultipleThresholds.cxx @@ -38,22 +38,18 @@ TObserver; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { - if( argc < 8 ) + if( argc < 5 ) { std::cerr << "Usage: " << argv[ 0 ] - << " input_image s_x s_y s_z thr_0 thr_1 n_samples" << std::endl; + << " input_image thr_0 thr_1 n_samples" << std::endl; return( 1 ); } // fi std::string input_image_fn = argv[ 1 ]; - TImage::PointType seed_pnt; - seed_pnt[ 0 ] = std::atof( argv[ 2 ] ); - seed_pnt[ 1 ] = std::atof( argv[ 3 ] ); - seed_pnt[ 2 ] = std::atof( argv[ 4 ] ); - TPixel thr_0 = TPixel( std::atof( argv[ 5 ] ) ); - TPixel thr_1 = TPixel( std::atof( argv[ 6 ] ) ); - unsigned int n_samples = std::atoi( argv[ 7 ] ); + TPixel thr_0 = TPixel( std::atof( argv[ 2 ] ) ); + TPixel thr_1 = TPixel( std::atof( argv[ 3 ] ) ); + unsigned int n_samples = std::atoi( argv[ 4 ] ); // Read image TImageReader::Pointer input_image_reader = TImageReader::New( ); @@ -78,40 +74,43 @@ int main( int argc, char* argv[] ) vtk_image->SetInput( input_image ); vtk_image->Update( ); - vtkSmartPointer< vtkSphereSource > seed = - vtkSmartPointer< vtkSphereSource >::New( ); - seed->SetCenter( seed_pnt[ 0 ], seed_pnt[ 1 ], seed_pnt[ 2 ] ); - seed->SetRadius( min_spac * double( 5 ) ); - seed->Update( ); + /* TODO + vtkSmartPointer< vtkSphereSource > seed = + vtkSmartPointer< vtkSphereSource >::New( ); + seed->SetCenter( seed_pnt[ 0 ], seed_pnt[ 1 ], seed_pnt[ 2 ] ); + seed->SetRadius( min_spac * double( 5 ) ); + seed->Update( ); + */ fpa::VTK::ImageMPR view; view.SetBackground( 0.3, 0.2, 0.8 ); view.SetSize( 800, 800 ); view.SetImage( vtk_image->GetOutput( ) ); - view.AddPolyData( seed->GetOutput( ), 1, 0, 0 ); + // TODO: view.AddPolyData( seed->GetOutput( ), 1, 0, 0 ); view.Start( ); // Configure observer - TObserver::Pointer obs = TObserver::New( ); - obs->SetImage( input_image, view.GetWindow( ) ); - - // Configure algorithm - TFrontAlgorithm::Pointer algorithm = TFrontAlgorithm::New( ); - algorithm->AddThresholds( thr_0, thr_1, n_samples ); - - TImage::IndexType seed_idx; - input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx ); - algorithm->AddSeed( seed_idx, 0 ); - - algorithm->AddObserver( itk::AnyEvent( ), obs ); - algorithm->ThrowEventsOn( ); - algorithm->SetInput( input_image ); - algorithm->SetNeighborhoodOrder( 1 ); - algorithm->SetDerivativeThreshold( double( 3 ) ); - algorithm->Update( ); - - view.Start( ); - + /* TODO + TObserver::Pointer obs = TObserver::New( ); + obs->SetImage( input_image, view.GetWindow( ) ); + + // Configure algorithm + TFrontAlgorithm::Pointer algorithm = TFrontAlgorithm::New( ); + algorithm->AddThresholds( thr_0, thr_1, n_samples ); + + TImage::IndexType seed_idx; + input_image->TransformPhysicalPointToIndex( seed_pnt, seed_idx ); + algorithm->AddSeed( seed_idx, 0 ); + + algorithm->AddObserver( itk::AnyEvent( ), obs ); + algorithm->ThrowEventsOn( ); + algorithm->SetInput( input_image ); + algorithm->SetNeighborhoodOrder( 1 ); + algorithm->SetDerivativeThreshold( double( 3 ) ); + algorithm->Update( ); + + view.Start( ); + */ return( 0 ); } diff --git a/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx b/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx index 34420b2..24b3308 100644 --- a/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx +++ b/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx @@ -60,7 +60,11 @@ _QueuePop( ) _TNode node = this->Superclass::_QueuePop( ); if( this->_IsQueueEmpty( ) ) { - std::cerr << "ERROR!!!!" << std::endl; + // Replace queue + this->m_Queue = this->m_AuxiliaryQueue; + + // Move to next function + this->m_ActualFunction++; } // fi return( node ); @@ -71,10 +75,15 @@ template< class V, class R, class VV, class VC, class B > bool fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >:: _CheckMembership( const _TNode& n ) const { - bool ret = ( *( this->m_ActualFunction ) )->Evaluate( n.Vertex ); - if( !ret ) - this->m_AuxiliaryQueue.push( n ); - return( ret ); + if( this->m_ActualFunction != this->m_Functions.end( ) ) + { + bool ret = ( *( this->m_ActualFunction ) )->Evaluate( n.Vertex ); + if( !ret ) + this->m_AuxiliaryQueue.push( n ); + return( ret ); + } + else + return( false ); } #endif // __FPA__BASE__REGIONGROWWITHMULTIPLECRITERIA__HXX__ diff --git a/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx b/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx index 51e474b..0969b0c 100644 --- a/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx +++ b/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx @@ -20,9 +20,10 @@ AddThreshold( const TPixel& v ) else function->SetLowerThreshold( std::numeric_limits< TPixel >::min( ) ); std::cout - << typeid( TPixel ).name( ) << " " + << typeid( TPixel ).name( ) << " <<<----->>> " << function->GetLowerThreshold( ) << std::endl; + std::exit( 1 ); function->SetUpperThreshold( v ); this->AddMembershipFunction( function ); diff --git a/lib/fpa/VTK/ImageMPR.cxx b/lib/fpa/VTK/ImageMPR.cxx index d435bb8..b990900 100644 --- a/lib/fpa/VTK/ImageMPR.cxx +++ b/lib/fpa/VTK/ImageMPR.cxx @@ -1,13 +1,65 @@ #include +#include #include +#include + +class vtkUpdateCallback + : public vtkCommand +{ +public: + static vtkUpdateCallback *New() + { + return new vtkUpdateCallback; + } + virtual void Execute(vtkObject *caller, unsigned long eventId, void* + arguments) + { + vtkRenderWindowInteractor* iren = + static_cast< vtkRenderWindowInteractor* >( caller ); + if( caller == NULL ) + return; + + switch( iren->GetKeyCode( ) ) + { + case 'x': + case 'X': + { + bool eSeed = ( this->SeedWidget->GetProcessEvents( ) == 1 ); + if( eSeed ) + { + this->SeedWidget->ProcessEventsOff( ); + this->WidgetX->InteractionOn( ); + this->WidgetY->InteractionOn( ); + this->WidgetZ->InteractionOn( ); + } + else + { + this->SeedWidget->ProcessEventsOn( ); + this->WidgetX->InteractionOff( ); + this->WidgetY->InteractionOff( ); + this->WidgetZ->InteractionOff( ); + + } // fi + } + break; + default: + break; + + } // hctiws + } + +public: + vtkImagePlaneWidget* WidgetX; + vtkImagePlaneWidget* WidgetY; + vtkImagePlaneWidget* WidgetZ; + vtkSeedWidget2* SeedWidget; +}; // ------------------------------------------------------------------------- fpa::VTK::ImageMPR:: ImageMPR( ) { - // vtkSmartPointer< vtkImageData > m_Image; - this->m_Outline = vtkSmartPointer< vtkOutlineSource >::New( ); this->m_OutlineMapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); this->m_OutlineActor = vtkSmartPointer< vtkActor >::New( ); @@ -18,6 +70,38 @@ ImageMPR( ) this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( ); this->m_Window = vtkSmartPointer< vtkRenderWindow >::New( ); this->m_Interactor = vtkSmartPointer< vtkRenderWindowInteractor >::New( ); + + + + + + + handlePointRep3D = + vtkSmartPointer::New(); + //handlePointRep3D->AllOn(); + handlePointRep3D->GetProperty()->SetColor(1.,0.,1.); + seedRep = + vtkSmartPointer::New(); + seedRep->SetHandleRepresentation(handlePointRep3D); + seedWidget = vtkSmartPointer::New(); + + seedWidget->SetRepresentation(seedRep); + + this->m_WidgetX->KeyPressActivationOff( ); + this->m_WidgetY->KeyPressActivationOff( ); + this->m_WidgetZ->KeyPressActivationOff( ); + seedWidget->KeyPressActivationOff( ); + + // this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker ); + + + vtkUpdateCallback* onUpdate = vtkUpdateCallback::New(); + onUpdate->WidgetX = this->m_WidgetX; + onUpdate->WidgetY = this->m_WidgetY; + onUpdate->WidgetZ = this->m_WidgetZ; + onUpdate->SeedWidget = this->seedWidget; + + this->m_Interactor->AddObserver(vtkCommand::KeyPressEvent, onUpdate); } // ------------------------------------------------------------------------- @@ -97,6 +181,16 @@ SetImage( vtkImageData* image ) this->m_WidgetX->SetInteractor( this->m_Interactor ); this->m_WidgetY->SetInteractor( this->m_Interactor ); this->m_WidgetZ->SetInteractor( this->m_Interactor ); + seedWidget->SetInteractor(this->m_Interactor); + + this->m_WidgetX->On( ); + this->m_WidgetY->On( ); + this->m_WidgetZ->On( ); + seedWidget->On( ); + seedWidget->ProcessEventsOff( ); + this->m_Interactor->SetPicker( this->m_Picker ); + this->m_Interactor->GetPickingManager( )->AddPicker( this->m_Picker ); + this->m_Interactor->GetPickingManager( )->EnabledOn( ); } // ------------------------------------------------------------------------- diff --git a/lib/fpa/VTK/ImageMPR.h b/lib/fpa/VTK/ImageMPR.h index e7a65d3..6664d31 100644 --- a/lib/fpa/VTK/ImageMPR.h +++ b/lib/fpa/VTK/ImageMPR.h @@ -17,6 +17,45 @@ #include #include +#include +#include +#include +#include + +class vtkSeedWidget2 + : public vtkSeedWidget +{ +public: + // Description: + // Instantiate this class. + static vtkSeedWidget2 *New() + { + return new vtkSeedWidget2; + } + + // Description: + // Standard methods for a VTK class. + vtkTypeMacro(vtkSeedWidget2, vtkSeedWidget); + + virtual vtkPickingManager* GetPickingManager( ) + { + return( this->Superclass::GetPickingManager( ) ); + } + +protected: + vtkSeedWidget2() + : Superclass( ) + { + } + virtual ~vtkSeedWidget2() + { + } + +private: + vtkSeedWidget2(const vtkSeedWidget2&); //Not implemented + void operator=(const vtkSeedWidget2&); //Not implemented +}; + namespace fpa { namespace VTK @@ -56,6 +95,13 @@ namespace fpa std::vector< vtkSmartPointer< vtkPolyData > > m_PolyDatas; std::vector< vtkSmartPointer< vtkPolyDataMapper > > m_Mappers; std::vector< vtkSmartPointer< vtkActor > > m_Actors; + + + // Create the widget and its representation + vtkSmartPointer handlePointRep3D; + vtkSmartPointer seedRep; + vtkSmartPointer seedWidget; + }; } // ecapseman