#include "MacheteFilter.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef cpPlugins_Interface_QT4 #include // ------------------------------------------------------------------------- cpPlugins::BasicFilters::MacheteFilter_Dialog:: MacheteFilter_Dialog( QWidget* parent, MacheteFilter* filter, Qt::WindowFlags f ) : QDialog( parent, f | Qt::WindowStaysOnTopHint ), m_Filter( filter ) { this->m_Title = new QLabel( this ); this->m_Title->setText( "Execute machete 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::MacheteFilter_Dialog:: ~MacheteFilter_Dialog( ) { delete this->m_Title; delete this->m_ToolsLayout; delete this->m_MainLayout; } // ------------------------------------------------------------------------- void cpPlugins::BasicFilters::MacheteFilter_Dialog:: accept( ) { // Get interactive widget if( this->m_Filter == NULL ) return; vtkPlaneWidget* wdg = this->m_Filter->m_PlaneWidget; if( wdg == NULL ) return; // Get/Set plane parameters double center[ 3 ], normal[ 3 ]; wdg->GetCenter( center ); wdg->GetNormal( normal ); this->m_Filter->GetParameters( )->SetPoint( "PlaneCenter", 3, center ); this->m_Filter->GetParameters( )->SetVector( "PlaneNormal", 3, normal ); // Update filter auto plugins = this->m_Filter->GetPlugins( ); if( plugins != NULL ) { auto app = plugins->GetApplication( ); if( app != NULL ) app->UpdateActualFilter( ); } // fi } // ------------------------------------------------------------------------- void cpPlugins::BasicFilters::MacheteFilter_Dialog:: reject( ) { auto plugins = this->m_Filter->GetPlugins( ); if( plugins != NULL ) plugins->DeactivateFilter( ); this->Superclass::reject( ); } #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- cpPlugins::BasicFilters::MacheteFilter:: DialogResult cpPlugins::BasicFilters::MacheteFilter:: ExecConfigurationDialog( QWidget* parent ) { #ifdef cpPlugins_Interface_QT4 typedef cpExtensions::Interaction::ImageInteractorStyle _TImageStyle; // Choose a valid 3D interactor vtkRenderWindowInteractor* iren = NULL; auto iIt = this->m_Interactors.begin( ); for( ; iIt != this->m_Interactors.end( ) && iren == NULL; ++iIt ) { _TImageStyle* istyle = dynamic_cast< _TImageStyle* >( ( *iIt )->GetInteractorStyle( ) ); if( istyle == NULL ) iren = *iIt; } // rof if( iren == NULL ) return( Self::DialogResult_Cancel ); // Get bounding box double bbox[ 6 ]; cpPlugins::Interface::Image* image = this->GetInput< cpPlugins::Interface::Image >( "Input" ); bool input_found = false; if( image != NULL ) { image->GetVTK< vtkImageData >( )->GetBounds( bbox ); input_found = true; } // fi cpPlugins::Interface::Mesh* mesh = this->GetInput< cpPlugins::Interface::Mesh >( "Input" ); if( mesh != NULL ) { mesh->GetVTK< vtkPolyData >( )->GetBounds( bbox ); input_found = true; } // fi if( !input_found ) return( Self::DialogResult_Cancel ); // Create plane widget if( this->m_PlaneWidget != NULL ) this->m_PlaneWidget->Delete( ); this->m_PlaneWidget = vtkPlaneWidget::New( ); this->m_PlaneWidget->NormalToXAxisOn( ); this->m_PlaneWidget->SetCenter( ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ), ( bbox[ 3 ] + bbox[ 2 ] ) * double( 0.5 ), ( bbox[ 5 ] + bbox[ 4 ] ) * double( 0.5 ) ); this->m_PlaneWidget->SetOrigin( ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ), bbox[ 2 ], bbox[ 4 ] ); this->m_PlaneWidget->SetPoint1( ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ), bbox[ 3 ], bbox[ 4 ] ); this->m_PlaneWidget->SetPoint2( ( bbox[ 1 ] + bbox[ 0 ] ) * double( 0.5 ), bbox[ 2 ], bbox[ 5 ] ); this->m_PlaneWidget->SetResolution( 15 ); this->m_PlaneWidget->SetRepresentationToWireframe( ); this->m_PlaneWidget->SetInteractor( iren ); this->m_PlaneWidget->PlaceWidget( ); this->m_PlaneWidget->On( ); this->m_Dialog = new MacheteFilter_Dialog( NULL, this ); this->m_Dialog->show( ); return( Self::DialogResult_Modal ); #else // cpPlugins_Interface_QT4 return( Self::DialogResult_Cancel ); #endif // cpPlugins_Interface_QT4 } // ------------------------------------------------------------------------- cpPlugins::BasicFilters::MacheteFilter:: MacheteFilter( ) : Superclass( ), m_PlaneWidget( NULL ) { this->_AddInput( "Input" ); this->_MakeOutput< cpPlugins::Interface::DataObject >( "PositiveOutput" ); this->_MakeOutput< cpPlugins::Interface::DataObject >( "NegativeOutput" ); this->m_Parameters->ConfigureAsPoint( "PlaneCenter" ); this->m_Parameters->ConfigureAsVector( "PlaneNormal" ); } // ------------------------------------------------------------------------- cpPlugins::BasicFilters::MacheteFilter:: ~MacheteFilter( ) { if( this->m_PlaneWidget != NULL ) this->m_PlaneWidget->Delete( ); } // ------------------------------------------------------------------------- std::string cpPlugins::BasicFilters::MacheteFilter:: _GenerateData( ) { cpPlugins::Interface::Image* image = this->GetInput< cpPlugins::Interface::Image >( "Input" ); if( image != NULL ) return( this->_FromImage( image ) ); cpPlugins::Interface::Mesh* mesh = this->GetInput< cpPlugins::Interface::Mesh >( "Input" ); if( mesh == NULL ) return( this->_FromMesh( mesh ) ); return( "MacheteFilter: No valid input." ); } // ------------------------------------------------------------------------- std::string cpPlugins::BasicFilters::MacheteFilter:: _FromImage( cpPlugins::Interface::Image* image ) { itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _RealImage ); else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _RealImage ); else r = "MacheteFilter: Input image type not supported."; return( r ); } // ------------------------------------------------------------------------- std::string cpPlugins::BasicFilters::MacheteFilter:: _FromMesh( cpPlugins::Interface::Mesh* mesh ) { return( "" ); } // ------------------------------------------------------------------------- template< class I > std::string cpPlugins::BasicFilters::MacheteFilter:: _RealImage( itk::DataObject* dobj ) { typedef cpExtensions::DataStructures:: InfinitePlaneSpatialObject< I::ImageDimension > _TPlane; typedef cpExtensions::Algorithms:: SpatialObjectMaskImageFilter< I, I > _TFilter; typedef cpPlugins::Interface::DataObject _TObj; typedef cpPlugins::Interface::Image _TImage; typedef typename _TPlane::PointType _TPoint; typedef typename _TPlane::VectorType _TVector; typedef typename I::PixelType _TPixel; I* image = dynamic_cast< I* >( dobj ); _TPoint c = this->m_Parameters->GetPoint< _TPoint >( "PlaneCenter", I::ImageDimension ); _TVector n = this->m_Parameters->GetVector< _TVector >( "PlaneNormal", I::ImageDimension ); typename _TPlane::Pointer plane = _TPlane::New( ); plane->SetCenter( c ); plane->SetNormal( n ); // Configure filter _TFilter* filter = this->_CreateITK< _TFilter >( ); filter->SetInput( image ); filter->SetSpatialObject( plane ); filter->SetOutsideValue( _TPixel( 0 ) ); filter->Update( ); // Get output names auto pos_name = this->GetOutput< _TObj >( "PositiveOutput" )->GetName( ); auto neg_name = this->GetOutput< _TObj >( "NegativeOutput" )->GetName( ); // Connect outputs (and correct their types and names) _TImage* pos_out = this->GetOutput< _TImage >( "PositiveOutput" ); if( pos_out == NULL ) { this->_MakeOutput< _TImage >( "PositiveOutput" ); pos_out = this->GetOutput< _TImage >( "PositiveOutput" ); pos_out->SetName( pos_name ); } // fi _TImage* neg_out = this->GetOutput< _TImage >( "NegativeOutput" ); if( neg_out == NULL ) { this->_MakeOutput< _TImage >( "NegativeOutput" ); neg_out = this->GetOutput< _TImage >( "NegativeOutput" ); neg_out->SetName( neg_name ); } // fi // Assign outputs pos_out->SetITK< I >( filter->GetPositiveOutput( ) ); neg_out->SetITK< I >( filter->GetNegativeOutput( ) ); return( "" ); } // eof - $RCSfile$