From: Leonardo Florez-Valencia Date: Thu, 19 Nov 2015 00:06:47 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~298 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7478fcc087fe32cee83c18bd98ccf8afb2e8818b;p=cpPlugins.git ... --- diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index ce1f2fc..cf6a1f6 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -75,6 +75,7 @@ UpdateActualFilter( ) return; // Show outputs +#error ACA VOY for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) std::cout << *oIt << std::endl; diff --git a/lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.h b/lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.h new file mode 100644 index 0000000..f8fd354 --- /dev/null +++ b/lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.h @@ -0,0 +1,83 @@ +#ifndef __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__H__ +#define __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__H__ + +#include +#include +#include + +namespace cpExtensions +{ + namespace Algorithms + { + /** + */ + template< class I, class O = I > + class SpatialObjectMaskImageFilter + : public itk::InPlaceImageFilter< I, O > + { + public: + typedef SpatialObjectMaskImageFilter Self; + typedef itk::InPlaceImageFilter< I, O > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef I TInputImage; + typedef O TOutputImage; + + itkStaticConstMacro( InputDimension, unsigned int, I::ImageDimension ); + itkStaticConstMacro( OutputDimension, unsigned int, O::ImageDimension ); + +#ifdef ITK_USE_CONCEPT_CHECKING + // Begin concept checking + itkConceptMacro( + SameDimensionCheck1, + ( itk::Concept::SameDimension< InputDimension, OutputDimension > ) + ); + // End concept checking +#endif + + typedef typename I::RegionType TRegion; + typedef typename O::PixelType TOutPixel; + typedef itk::SpatialObject< InputDimension > TSpatialObject; + + public: + itkNewMacro( Self ); + itkTypeMacro( SpatialObjectMaskImageFilter, itk::InPlaceImageFilter ); + + itkGetObjectMacro( SpatialObject, TSpatialObject ); + itkGetConstObjectMacro( SpatialObject, TSpatialObject ); + itkGetConstMacro( OutsideValue, TOutPixel ); + + itkSetObjectMacro( SpatialObject, TSpatialObject ); + itkSetMacro( OutsideValue, TOutPixel ); + + protected: + SpatialObjectMaskImageFilter( ); + virtual ~SpatialObjectMaskImageFilter( ); + + virtual void GenerateOutputInformation( ); + virtual void ThreadedGenerateData( + const TRegion& region, itk::ThreadIdType threadId + ); + + private: + // Purposely not implemented. + SpatialObjectMaskImageFilter( const Self& other ); + Self& operator=( const Self& other ); + + protected: + typename TSpatialObject::Pointer m_SpatialObject; + TOutPixel m_OutsideValue; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +#include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.hxx b/lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.hxx new file mode 100644 index 0000000..2df9c6f --- /dev/null +++ b/lib/cpExtensions/Algorithms/SpatialObjectMaskImageFilter.hxx @@ -0,0 +1,91 @@ +#ifndef __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__HXX__ +#define __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__HXX__ + +#include +#include + +// ------------------------------------------------------------------------- +template< class I, class O > +cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >:: +SpatialObjectMaskImageFilter( ) + : Superclass( ) +{ + this->SetNumberOfRequiredInputs( 1 ); + this->InPlaceOff( ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >:: +~SpatialObjectMaskImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +template< class I, class O > +void cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >:: +GenerateOutputInformation( ) +{ + const I* in = + dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) ); + for( unsigned int idx = 0; idx < this->GetNumberOfOutputs( ); ++idx ) + { + itk::DataObject* out = this->GetOutput( idx ); + if( out ) + out->CopyInformation( in ); + + } // rof +} + +// ------------------------------------------------------------------------- +template< class I, class O > +void cpExtensions::Algorithms::SpatialObjectMaskImageFilter< I, O >:: +ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId ) +{ + if( this->m_SpatialObject.IsNull( ) ) + { + itkGenericExceptionMacro( << "No itk::SpatialObject given." ); + return; + + } // fi + + // Get inputs + const I* in = + dynamic_cast< const I* >( this->itk::ProcessObject::GetInput( 0 ) ); + O* out = this->GetOutput( 0 ); + const auto size0 = region.GetSize( 0 ); + if( size0 == 0 ) + return; + const auto nLines = region.GetNumberOfPixels( ) / size0; + + // Create iterators + itk::ImageScanlineConstIterator< I > iIt( in, region ); + itk::ImageScanlineIterator< O > oIt( out, region ); + itk::ProgressReporter progress( this, threadId, nLines ); + + // Main loop + typename TSpatialObject::PointType pnt; + while( !iIt.IsAtEnd( ) ) + { + while( !iIt.IsAtEndOfLine( ) ) + { + auto idx = iIt.GetIndex( ); + in->TransformIndexToPhysicalPoint( idx, pnt ); + if( this->m_SpatialObject->IsInside( pnt ) ) + oIt.Set( TOutPixel( iIt.Get( ) ) ); + else + oIt.Set( this->m_OutsideValue ); + ++iIt; + ++oIt; + + } // elihw + iIt.NextLine( ); + oIt.NextLine( ); + progress.CompletedPixel( ); + + } // elihw +} + +#endif // __CPEXTENSIONS__ALGORITHMS__SPATIALOBJECTMASKIMAGEFILTER__HXX__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/DataStructures/InfinitePlaneSpatialObject.h b/lib/cpExtensions/DataStructures/InfinitePlaneSpatialObject.h new file mode 100644 index 0000000..2f61766 --- /dev/null +++ b/lib/cpExtensions/DataStructures/InfinitePlaneSpatialObject.h @@ -0,0 +1,88 @@ +#ifndef __CPEXTENSIONS__DATASTRUCTURES__INFINITEPLANESPATIALOBJECT__H__ +#define __CPEXTENSIONS__DATASTRUCTURES__INFINITEPLANESPATIALOBJECT__H__ + +#include + +namespace cpExtensions +{ + namespace DataStructures + { + /** + */ + template< unsigned int D > + class InfinitePlaneSpatialObject + : public itk::SpatialObject< D > + { + public: + typedef InfinitePlaneSpatialObject Self; + typedef itk::SpatialObject< D > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef double ScalarType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::TransformType TransformType; + typedef typename Superclass::BoundingBoxType BoundingBoxType; + typedef typename PointType::VectorType VectorType; + + itkStaticConstMacro( NumberOfDimension, unsigned int, D ); + + public: + itkNewMacro( Self ); + itkTypeMacro( InfinitePlaneSpatialObject, itk::SpatialObject ); + + itkGetConstMacro( Center, PointType ); + itkGetConstMacro( Normal, VectorType ); + + public: + template< class P > + void SetCenter( const P& p ); + + template< class N > + void SetNormal( const N& n ); + + virtual bool ValueAt( + const PointType& point, double& value, + unsigned int depth = 0, char* name = NULL + ) const; + + virtual bool IsEvaluableAt( + const PointType& point, + unsigned int depth = 0, char* name = NULL + ) const; + + virtual bool IsInside( + const PointType& point, + unsigned int depth, char* name + ) const; + + virtual bool IsInside( const PointType& point ) const; + + virtual bool ComputeLocalBoundingBox( ) const; + + protected: + InfinitePlaneSpatialObject( ); + virtual ~InfinitePlaneSpatialObject( ); + virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const; + + private: + // Purposely not implemented. + InfinitePlaneSpatialObject( const Self& other ); + Self& operator=( const Self& other ); + + protected: + PointType m_Center; + VectorType m_Normal; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +#include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __CPEXTENSIONS__DATASTRUCTURES__INFINITEPLANESPATIALOBJECT__H__ + +// eof - $RCSfile$ diff --git a/lib/cpExtensions/DataStructures/InfinitePlaneSpatialObject.hxx b/lib/cpExtensions/DataStructures/InfinitePlaneSpatialObject.hxx new file mode 100644 index 0000000..fd68815 --- /dev/null +++ b/lib/cpExtensions/DataStructures/InfinitePlaneSpatialObject.hxx @@ -0,0 +1,109 @@ +#ifndef __CPEXTENSIONS__DATASTRUCTURES__INFINITEPLANESPATIALOBJECT__HXX__ +#define __CPEXTENSIONS__DATASTRUCTURES__INFINITEPLANESPATIALOBJECT__HXX__ + +// ------------------------------------------------------------------------- +template< unsigned int D > +template< class P > +void cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +SetCenter( const P& p ) +{ + for( unsigned int d = 0; d < D; ++d ) + this->m_Center[ d ] = ScalarType( p[ d ] ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +template< class N > +void cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +SetNormal( const N& n ) +{ + for( unsigned int d = 0; d < D; ++d ) + this->m_Normal[ d ] = ScalarType( n[ d ] ); + ScalarType nn = this->m_Normal.GetNorm( ); + if( nn > ScalarType( 0 ) ) + this->m_Normal /= nn; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +bool cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +ValueAt( + const PointType& point, double& value, unsigned int depth, char* name + ) const +{ + value = this->m_Normal * ( point - this->m_Center ); + return( value >= double( 0 ) ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +bool cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +IsEvaluableAt( + const PointType& point, unsigned int depth, char* name + ) const +{ + double value; + return( this->ValueAt( point, value, depth, name ) ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +bool cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +IsInside( + const PointType& point, unsigned int depth, char* name + ) const +{ + double value; + return( this->ValueAt( point, value, depth, name ) ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +bool cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +IsInside( const PointType& point ) const +{ + double value; + return( this->ValueAt( point, value, 0, NULL ) ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +bool cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +ComputeLocalBoundingBox( ) const +{ + return( false ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +InfinitePlaneSpatialObject( ) + : Superclass( ) +{ + this->m_Center.Fill( ScalarType( 0 ) ); + this->m_Normal.Fill( ScalarType( 0 ) ); + this->m_Normal[ 0 ] = ScalarType( 1 ); +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +~InfinitePlaneSpatialObject( ) +{ +} + +// ------------------------------------------------------------------------- +template< unsigned int D > +void cpExtensions::DataStructures::InfinitePlaneSpatialObject< D >:: +PrintSelf( std::ostream& os, itk::Indent indent ) const +{ + this->Superclass::PrintSelf( os, indent ); + os << indent << "Center: " << this->m_Center << std::endl; + os << indent << "Normal: " << this->m_Normal << std::endl; +} + +#endif // __CPEXTENSIONS__DATASTRUCTURES__INFINITEPLANESPATIALOBJECT__HXX__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt b/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt index 361ba10..2482a0b 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt +++ b/lib/cpPlugins/Plugins/BasicFilters/CMakeLists.txt @@ -11,6 +11,27 @@ FILE(GLOB LIB_SOURCES_C "*.c") FILE(GLOB LIB_SOURCES_CPP "*.cpp") FILE(GLOB LIB_SOURCES_CXX "*.cxx") +IF(USE_QT4) + SET( + LIB_QT_Headers + MacheteFilter.h + ) + SET( + LIB_QT_Sources + MacheteFilter.cxx + ) + + QT4_WRAP_CPP(LIB_QT_Wrapped_MOC_Sources ${LIB_QT_Headers}) + + SET( + LIB_SOURCES_CXX + ${LIB_SOURCES_CXX} + ${LIB_QT_Sources} + ${LIB_QT_Wrapped_MOC_Sources} + ) + +ENDIF(USE_QT4) + ## ===================== ## = Compilation rules = ## ===================== diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx index 3eb6006..36bb0e8 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx +++ b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.cxx @@ -1,25 +1,105 @@ #include "MacheteFilter.h" +#include +#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 ), + 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( ) +{ + std::cout << "reject" << std::endl; +} +#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 @@ -91,7 +171,13 @@ ExecConfigurationDialog( QWidget* parent ) 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 } // ------------------------------------------------------------------------- @@ -156,32 +242,55 @@ _FromMesh( cpPlugins::Interface::Mesh* mesh ) return( "" ); } -#include - // ------------------------------------------------------------------------- template< class I > std::string cpPlugins::BasicFilters::MacheteFilter:: _RealImage( itk::DataObject* dobj ) { - typedef typename I::PixelType _TPixel; - typedef itk::PlaneSpatialObject< I::ImageDimension > _TPlane; - typedef itk::SpatialObjectToImageFilter< _TPlane, I > _TMaskFilter; + typedef + cpExtensions::DataStructures:: + InfinitePlaneSpatialObject< I::ImageDimension > _TPlane; + typedef + cpExtensions::Algorithms:: + SpatialObjectMaskImageFilter< I > _TFilter; + typedef cpPlugins::Interface::DataObject _TDataObject; + 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 ); - typename _TMaskFilter::Pointer mask = _TMaskFilter::New( ); - mask->SetDirection( image->GetDirection( ) ); - mask->SetOrigin( image->GetOrigin( ) ); - mask->SetSize( image->GetRequestedRegion( ).GetSize( ) ); - mask->SetSpacing( image->GetSpacing( ) ); - mask->SetInsideValue( _TPixel( 1 ) ); - mask->SetOutsideValue( _TPixel( 0 ) ); - - typename itk::ImageFileWriter< I >::Pointer w = - itk::ImageFileWriter< I >::New( ); - w->SetInput( mask->GetOutput( ) ); - w->SetFileName( "mask.mhd" ); - w->Update( ); + _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( ); + + // Connect output (and correct its type) + auto name = this->GetOutput< _TDataObject >( "Output" )->GetName( ); + this->_MakeOutput< _TImage >( "Output" ); + _TImage* out = this->GetOutput< _TImage >( "Output" ); + if( out != NULL ) + { + out->SetITK< I >( filter->GetOutput( ) ); + out->SetName( name ); + return( "" ); + } + else + return( "MacheteFilter: output image not correctly created." ); } // eof - $RCSfile$ diff --git a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h index ad6669c..ff781f1 100644 --- a/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h +++ b/lib/cpPlugins/Plugins/BasicFilters/MacheteFilter.h @@ -4,6 +4,15 @@ #include #include +#include + +#ifdef cpPlugins_Interface_QT4 +#include +#include +#include +#include +#endif // cpPlugins_Interface_QT4 + // Some forward declarations class vtkPlaneWidget; @@ -19,11 +28,41 @@ namespace cpPlugins namespace BasicFilters { +#ifdef cpPlugins_Interface_QT4 + class MacheteFilter; + + /** + */ + class MacheteFilter_Dialog + : public QDialog + { + Q_OBJECT; + + public: + MacheteFilter_Dialog( + QWidget* parent, MacheteFilter* filter, Qt::WindowFlags f = 0 + ); + virtual ~MacheteFilter_Dialog( ); + + public slots: + void accept( ); + void reject( ); + + protected: + MacheteFilter* m_Filter; + QLabel* m_Title; + QGridLayout* m_MainLayout; + QVBoxLayout* m_ToolsLayout; + }; +#endif // cpPlugins_Interface_QT4 + /** */ class cpPluginsBasicFilters_EXPORT MacheteFilter : public cpPlugins::Interface::FilterObject { + friend class MacheteFilter_Dialog; + public: typedef MacheteFilter Self; typedef cpPlugins::Interface::FilterObject Superclass; @@ -58,7 +97,10 @@ namespace cpPlugins Self& operator=( const Self& ); protected: - vtkPlaneWidget* m_PlaneWidget; +#ifdef cpPlugins_Interface_QT4 + vtkPlaneWidget* m_PlaneWidget; + MacheteFilter_Dialog* m_Dialog; +#endif // cpPlugins_Interface_QT4 }; // ---------------------------------------------------------------------