From 6811a7f591c2c0cbc5c26f68e7d0283395cf872c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Tue, 24 Oct 2017 16:30:55 -0500 Subject: [PATCH] ... --- lib/ivq/VTK/ImageToFourierSeriesFilter.cxx | 153 +++++++++++++++++++++ lib/ivq/VTK/ImageToFourierSeriesFilter.h | 67 +++++++++ 2 files changed, 220 insertions(+) create mode 100644 lib/ivq/VTK/ImageToFourierSeriesFilter.cxx create mode 100644 lib/ivq/VTK/ImageToFourierSeriesFilter.h diff --git a/lib/ivq/VTK/ImageToFourierSeriesFilter.cxx b/lib/ivq/VTK/ImageToFourierSeriesFilter.cxx new file mode 100644 index 0000000..b2ceb75 --- /dev/null +++ b/lib/ivq/VTK/ImageToFourierSeriesFilter.cxx @@ -0,0 +1,153 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= + +#include +#include +#include +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +typename ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +Self* ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +New( ) +{ + return( new Self( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +const _TFourierSeries& +ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +GetOutput( ) const +{ + return( this->m_FourierSeries ); +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +void ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +SetNumberOfHarmonics( unsigned int q ) +{ + if( this->m_FourierSeries.GetNumberOfHarmonics( ) != q ) + { + this->m_FourierSeries.SetNumberOfHarmonics( q ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +unsigned int ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +GetNumberOfHarmonics( ) const +{ + return( this->m_FourierSeries.GetNumberOfHarmonics( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +const double& ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +GetContourValue( ) const +{ + return( this->m_ContourValue ); +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +void ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +SetContourValue( const double& v ) +{ + if( this->m_ContourValue != v ) + { + this->m_ContourValue = v; + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +ImageToFourierSeriesFilter( ) + : vtkImageAlgorithm( ), + m_ContourValue( double( 0 ) ) +{ + this->SetNumberOfInputPorts( 1 ); + this->SetNumberOfOutputPorts( 0 ); + this->m_FourierSeries.SetNumberOfHarmonics( 1 ); +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +~ImageToFourierSeriesFilter( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +int ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +RequestData( + vtkInformation* information, + vtkInformationVector** input, + vtkInformationVector* output + ) +{ + // Get input polydata + vtkInformation* inInfo = input[ 0 ]->GetInformationObject( 0 ); + vtkImageData* image = + vtkImageData::SafeDownCast( + inInfo->Get( vtkDataObject::DATA_OBJECT( ) ) + ); + + // Extract contour + vtkSmartPointer< vtkMarchingSquares > ms = + vtkSmartPointer< vtkMarchingSquares >::New( ); + ms->SetInputData( image ); + ms->SetValue( 0, this->m_ContourValue ); + + vtkSmartPointer< vtkPolyDataConnectivityFilter > conn = + vtkSmartPointer< vtkPolyDataConnectivityFilter >::New( ); + conn->SetInputConnection( ms->GetOutputPort( ) ); + conn->SetExtractionModeToClosestPointRegion( ); + conn->SetClosestPoint( 0, 0, 0 ); + + // Compute fourier series + typedef ivq::VTK::PolyDataToFourierSeriesFilter< TFourierSeries > _TFilter; + vtkSmartPointer< _TFilter > filter = vtkSmartPointer< _TFilter >::New( ); + filter->SetInputConnection( conn->GetOutputPort( ) ); + filter->SetNumberOfHarmonics( this->m_FourierSeries.GetNumberOfHarmonics( ) ); + filter->Update( ); + this->m_FourierSeries = filter->GetOutput( ); + + return( 1 ); +} + +// ------------------------------------------------------------------------- +template< class _TFourierSeries > +int ivq::VTK::ImageToFourierSeriesFilter< _TFourierSeries >:: +RequestInformation( + vtkInformation* information, + vtkInformationVector** input, + vtkInformationVector* output + ) +{ + return( 1 ); +} + +// ------------------------------------------------------------------------- +#include + +template class ivq::VTK::ImageToFourierSeriesFilter< ivq::ITK::FourierSeries< float, 2 > >; +template class ivq::VTK::ImageToFourierSeriesFilter< ivq::ITK::FourierSeries< float, 3 > >; +template class ivq::VTK::ImageToFourierSeriesFilter< ivq::ITK::FourierSeries< double, 2 > >; +template class ivq::VTK::ImageToFourierSeriesFilter< ivq::ITK::FourierSeries< double, 3 > >; + +// eof - $RCSfile$ diff --git a/lib/ivq/VTK/ImageToFourierSeriesFilter.h b/lib/ivq/VTK/ImageToFourierSeriesFilter.h new file mode 100644 index 0000000..c18f007 --- /dev/null +++ b/lib/ivq/VTK/ImageToFourierSeriesFilter.h @@ -0,0 +1,67 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= +#ifndef __ivq__VTK__ImageToFourierSeriesFilter__h__ +#define __ivq__VTK__ImageToFourierSeriesFilter__h__ + +#include + +namespace ivq +{ + namespace VTK + { + /** + */ + template< class _TFourierSeries > + class ImageToFourierSeriesFilter + : public vtkImageAlgorithm + { + public: + typedef ImageToFourierSeriesFilter Self; + typedef _TFourierSeries TFourierSeries; + + public: + vtkTypeMacro( ImageToFourierSeriesFilter, vtkImageAlgorithm ); + + public: + static Self* New( ); + + const TFourierSeries& GetOutput( ) const; + void SetNumberOfHarmonics( unsigned int q ); + unsigned int GetNumberOfHarmonics( ) const; + const double& GetContourValue( ) const; + void SetContourValue( const double& v ); + + protected: + ImageToFourierSeriesFilter( ); + virtual ~ImageToFourierSeriesFilter( ); + + int RequestData( + vtkInformation* information, + vtkInformationVector** input, + vtkInformationVector* output + ); + int RequestInformation( + vtkInformation* information, + vtkInformationVector** input, + vtkInformationVector* output + ); + + private: + // Purposely not implemented + ImageToFourierSeriesFilter( const Self& ); + void operator=( const Self& ); + + protected: + TFourierSeries m_FourierSeries; + double m_ContourValue; + }; + + } // ecapseman + +} // ecapseman + +#endif // __ivq__VTK__ImageToFourierSeriesFilter__h__ + +// eof - $RCSfile$ -- 2.47.1