#include "DoubleFloodImageFilter.h" #include #include #include #include #include #include #ifdef cpPlugins_Interface_QT4 #include // ------------------------------------------------------------------------- cpPlugins::BasicFilters::DoubleFloodImageFilter_Dialog:: DoubleFloodImageFilter_Dialog( QWidget* parent, DoubleFloodImageFilter* filter, Qt::WindowFlags f ) : QDialog( parent, f | Qt::WindowStaysOnTopHint ), m_Filter( filter ) { /* TODO this->m_Title = new QLabel( this ); this->m_Title->setText( "Execute simple vessel segmentation filter" ); this->m_MainLayout = new QGridLayout( this ); this->m_ToolsLayout = new QVBoxLayout( ); this->m_ToolsLayout->addWidget( this->m_Title ); this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 ); // Add buttons QDialogButtonBox* bb = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok ); QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) ); QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) ); this->m_ToolsLayout->addWidget( bb ); */ } // ------------------------------------------------------------------------- cpPlugins::BasicFilters::DoubleFloodImageFilter_Dialog:: ~DoubleFloodImageFilter_Dialog( ) { /* delete this->m_Title; delete this->m_ToolsLayout; delete this->m_MainLayout; */ } // ------------------------------------------------------------------------- void cpPlugins::BasicFilters::DoubleFloodImageFilter_Dialog:: accept( ) { /* // Get interactive widget if( this->m_Filter == NULL ) return; typedef cpExtensions::Interaction::ImageInteractorStyle _TImageStyle; typedef cpExtensions::Visualization::ImageSliceActors _TImageActors; // Get seeds unsigned int nTotalSeeds = 0; auto iIt = this->m_Filter->m_Interactors.begin( ); for( ; iIt != this->m_Filter->m_Interactors.end( ); ++iIt ) { _TImageStyle* istyle = dynamic_cast< _TImageStyle* >( ( *iIt )->GetInteractorStyle( ) ); if( istyle == NULL ) continue; // Get window level _TImageActors* actors = dynamic_cast< _TImageActors* >( istyle->GetAssociatedObject( ) ); if( actors != NULL ) { this->m_Filter->GetParameters( )->SetReal( "Window", actors->GetWindow( ) ); this->m_Filter->GetParameters( )->SetReal( "Level", actors->GetLevel( ) ); } // fi unsigned int nSeeds = istyle->GetNumberOfSeeds( ); for( unsigned int s = 0; s < nSeeds; ++s ) { if( nTotalSeeds < 2 ) { double seed[ 3 ]; istyle->GetSeedAsPoint( s, seed ); if( nTotalSeeds == 0 ) this->m_Filter->GetParameters( )->SetPoint( "Seed0", 3, seed ); else this->m_Filter->GetParameters( )->SetPoint( "Seed1", 3, seed ); } // fi nTotalSeeds++; } // rof } // rof // Update filter auto plugins = this->m_Filter->GetPlugins( ); if( plugins != NULL ) { auto app = plugins->GetApplication( ); if( app != NULL ) app->UpdateActualFilter( ); } // fi */ } // ------------------------------------------------------------------------- void cpPlugins::BasicFilters::DoubleFloodImageFilter_Dialog:: reject( ) { /* auto plugins = this->m_Filter->GetPlugins( ); if( plugins != NULL ) plugins->DeactivateFilter( ); this->Superclass::reject( ); */ } #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- cpPlugins::BasicFilters::DoubleFloodImageFilter:: DialogResult cpPlugins::BasicFilters::DoubleFloodImageFilter:: ExecConfigurationDialog( QWidget* parent ) { /* TODO #ifdef cpPlugins_Interface_QT4 typedef cpExtensions::Interaction::ImageInteractorStyle _TImageStyle; // Activate seed widgets bool at_least_one = false; auto iIt = this->m_Interactors.begin( ); for( ; iIt != this->m_Interactors.end( ); ++iIt ) { _TImageStyle* istyle = dynamic_cast< _TImageStyle* >( ( *iIt )->GetInteractorStyle( ) ); if( istyle != NULL ) { istyle->SeedWidgetOn( ); at_least_one = true; } // fi } // rof if( !at_least_one ) return( false ); // Create dialog this->m_Dialog = new DoubleFloodImageFilter_Dialog( NULL, this ); this->m_Dialog->show( ); return( true ); #else // cpPlugins_Interface_QT4 return( false ); #endif // cpPlugins_Interface_QT4 */ return( false ); } // ------------------------------------------------------------------------- cpPlugins::BasicFilters::DoubleFloodImageFilter:: DoubleFloodImageFilter( ) : Superclass( ) { /* TODO this->_AddInput( "Input" ); this->_MakeOutput< cpPlugins::Interface::Image >( "Output" ); this->m_Parameters->ConfigureAsPoint( "Seed0" ); this->m_Parameters->ConfigureAsPoint( "Seed1" ); this->m_Parameters->ConfigureAsReal( "Window" ); this->m_Parameters->ConfigureAsReal( "Level" ); this->m_Parameters->ConfigureAsUint( "InsideValue" ); this->m_Parameters->ConfigureAsUint( "OutsideValue" ); this->m_Parameters->SetReal( "Window", 0 ); this->m_Parameters->SetReal( "Level", 0 ); this->m_Parameters->SetUint( "InsideValue", 255 ); this->m_Parameters->SetUint( "OutsideValue", 0 ); */ } // ------------------------------------------------------------------------- cpPlugins::BasicFilters::DoubleFloodImageFilter:: ~DoubleFloodImageFilter( ) { } // ------------------------------------------------------------------------- std::string cpPlugins::BasicFilters::DoubleFloodImageFilter:: _GenerateData( ) { /* TODO cpPlugins::Interface::Image* image = this->GetInput< cpPlugins::Interface::Image >( "Input" ); if( image == NULL ) return( "DoubleFloodImageFilter: No input image." ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); else r = "DoubleFloodImageFilter: Input image type not supported."; return( r ); */ return( "" ); } // ------------------------------------------------------------------------- template< class I > std::string cpPlugins::BasicFilters::DoubleFloodImageFilter:: _GD0( itk::DataObject* image ) { /* TODO return( this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >( image ) ); */ return( "" ); } // ------------------------------------------------------------------------- /* TODO template< class I, class R = float > class cpPlugins_BasicFilters_DoubleFloodImageFilter_Function : public itk::ImageFunction< I, bool, R > { public: typedef cpPlugins_BasicFilters_DoubleFloodImageFilter_Function Self; typedef itk::ImageFunction< I, bool, R > Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; typedef typename Superclass::PointType TPoint; typedef typename Superclass::IndexType TIndex; typedef typename Superclass::ContinuousIndexType TCIndex; public: itkNewMacro( Self ); itkTypeMacro( cpPlugins_BasicFilters_DoubleFloodImageFilter_Function, itkImageFunction ); itkSetMacro( Window, double ); itkSetMacro( Level, double ); public: virtual bool Evaluate( const TPoint& point ) const { return( true ); } virtual bool EvaluateAtIndex( const TIndex& index ) const { if( !( this->IsInsideBuffer( index ) ) ) return( false ); const I* image = this->GetInputImage( ); double w2 = this->m_Window / double( 2 ); double min = this->m_Level - w2; double max = this->m_Level + w2; unsigned char val = double( 0 ); double x = double( image->GetPixel( index ) ); double m = double( 100 ) / this->m_Window; double b = ( this->m_Window - ( double( 2 ) * this->m_Level ) ); b *= double( 50 ) / this->m_Window; if( x > min && x < max ) val = ( unsigned char )( ( m * x ) + b ); if( this->m_Start ) { this->m_StartValue = val; this->m_Start = false; return( true ); } else return( std::abs( this->m_StartValue - val ) <= 2 ); } virtual bool EvaluateAtContinuousIndex( const TCIndex& index ) const { return( true ); } protected: cpPlugins_BasicFilters_DoubleFloodImageFilter_Function( ) : Superclass( ), m_Window( double( 0 ) ), m_Level( double( 0 ) ), m_Start( true ) { } virtual ~cpPlugins_BasicFilters_DoubleFloodImageFilter_Function( ) { } private: // Purposely not implemented cpPlugins_BasicFilters_DoubleFloodImageFilter_Function( const Self& other ); Self& operator=( const Self& other ); protected: double m_Window; double m_Level; mutable unsigned char m_StartValue; mutable bool m_Start; }; */ // ------------------------------------------------------------------------- template< class I, class O > inline std::string cpPlugins::BasicFilters::DoubleFloodImageFilter:: _RealGD( itk::DataObject* image ) { /* TODO typedef typename O::PixelType _OP; typedef cpPlugins_BasicFilters_DoubleFloodImageFilter_Function< I > _F; typedef itk::FloodFilledImageFunctionConditionalConstIterator< I, _F > _It; typename I::PointType pseed0, pseed1; pseed0 = this->m_Parameters->GetPoint< typename I::PointType >( "Seed0", I::ImageDimension ); pseed1 = this->m_Parameters->GetPoint< typename I::PointType >( "Seed1", I::ImageDimension ); double window = this->m_Parameters->GetReal( "Window" ); double level = this->m_Parameters->GetReal( "Level" ); _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) ); _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) ); const I* in = dynamic_cast< const I* >( image ); typename I::IndexType seed0, seed1; in->TransformPhysicalPointToIndex( pseed0, seed0 ); in->TransformPhysicalPointToIndex( pseed1, seed1 ); typename O::Pointer out = O::New( ); out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) ); out->SetRequestedRegion( in->GetRequestedRegion( ) ); out->SetBufferedRegion( in->GetBufferedRegion( ) ); out->SetOrigin( in->GetOrigin( ) ); out->SetDirection( in->GetDirection( ) ); out->SetSpacing( in->GetSpacing( ) ); out->Allocate( ); out->FillBuffer( out_val ); typename _F::Pointer f = _F::New( ); f->SetInputImage( in ); f->SetWindow( window ); f->SetLevel( level ); _It i( in, f ); i.AddSeed( seed0 ); i.AddSeed( seed1 ); for( i.GoToBegin( ); !i.IsAtEnd( ); ++i ) out->SetPixel( i.GetIndex( ), in_val ); // Connect output cpPlugins::Interface::Image* out_port = this->GetOutput< cpPlugins::Interface::Image >( "Output" ); if( out_port != NULL ) { out_port->SetITK< O >( out ); return( "" ); } else return( "DoubleFloodImageFilter: output not correctly created." ); */ return( "" ); } // eof - $RCSfile$