From d054d8c8f86998e3644fc8c1253df27cd483fe4c Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Wed, 14 Sep 2016 23:25:52 -0500 Subject: [PATCH] Spline widget finished. --- appli/examples/plugins/ImageTracer.cxx | 61 ++-- lib/cpPlugins/DataObjects/Image.cxx | 39 ++- lib/cpPlugins/DataObjects/Image.h | 7 +- lib/cpPlugins/DataObjects/Image.hxx | 46 +++ plugins/ImageMeshFilters/RasterMeshFilter.cxx | 294 ++++++++++++++++++ plugins/ImageMeshFilters/RasterMeshFilter.h | 51 +++ .../TriangleMeshToBinaryImageFilter.cxx | 134 -------- .../TriangleMeshToBinaryImageFilter.h | 32 -- plugins/Widgets/SeedWidget.cxx | 1 + plugins/Widgets/SplineWidget.cxx | 1 + 10 files changed, 475 insertions(+), 191 deletions(-) create mode 100644 plugins/ImageMeshFilters/RasterMeshFilter.cxx create mode 100644 plugins/ImageMeshFilters/RasterMeshFilter.h delete mode 100644 plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.cxx delete mode 100644 plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.h diff --git a/appli/examples/plugins/ImageTracer.cxx b/appli/examples/plugins/ImageTracer.cxx index a8624d1..00ff0e8 100644 --- a/appli/examples/plugins/ImageTracer.cxx +++ b/appli/examples/plugins/ImageTracer.cxx @@ -14,14 +14,6 @@ #include #include -/* TODO - #include - #include - #include - #include - #include -*/ - #endif // cpExtensions_QT4 //---------------------------------------------------------------------------- @@ -56,14 +48,21 @@ int main( int argc, char* argv[] ) typedef cpPlugins::Interface::Workspace _TWorkspace; _TWorkspace::Pointer ws = _TWorkspace::New( ); ws->PrintExecutionOn( ); + ws->Load( argv[ 1 ] ); // Configure filters - auto reader = ws->CreateFilter( "IO", "ImageReader", "reader" ); - auto widget = ws->CreateFilter( "Widgets", "SplineWidget", "spline" ); - ws->Connect( "reader", "spline", "Output", "Input" ); - auto params = reader->GetParameters( ); - for( int i = 1; i < argc; ++i ) - params->AddToOpenFileNameList( "FileNames", argv[ i ] ); + /* TODO + auto reader = ws->CreateFilter( "IO", "ImageReader", "reader" ); + auto widget = ws->CreateFilter( "Widgets", "SplineWidget", "spline" ); + ws->Connect( "reader", "spline", "Output", "Input" ); + auto params = reader->GetParameters( ); + for( int i = 1; i < argc; ++i ) + params->AddToOpenFileNameList( "FileNames", argv[ i ] ); + */ + auto reader = ws->GetFilter( "reader" ); + auto spline = ws->GetFilter( "spline" ); + auto seeds = ws->GetFilter( "seeds" ); + auto axis = ws->GetFilter( "axis" ); // Execute reader try @@ -85,17 +84,37 @@ int main( int argc, char* argv[] ) view.SetImage( reader->GetOutputData< vtkImageData >( "Output" ), 2, "image" ); - widget->AddInteractor( view.GetInteractor( ) ); - widget->Update( ); + spline->AddInteractor( view.GetInteractor( ) ); + spline->Update( ); + seeds->AddInteractor( view.GetInteractor( ) ); + seeds->Update( ); // Start application and show data wnd.setCentralWidget( &view ); wnd.show( ); - int r = app.exec( ); - widget->Modified( ); - widget->Update( ); - widget->GetOutputData< vtkPolyData >( "Output" )->Print( std::cout ); - return( r ); + app.exec( ); + spline->Modified( ); + spline->Update( ); + + wnd.show( ); + app.exec( ); + + seeds->Modified( ); + seeds->Update( ); + axis->Update( ); + // view.Add( axis->GetOutputData< vtkPolyData >( "Output" ) ); + wnd.show( ); + return( app.exec( ) ); + + // TODO: widget->GetOutputData< vtkPolyData >( "Output" )->Print( std::cout ); + + /* + auto raster = ws->CreateFilter( "MeshToImageFilters", "RasterMeshFilter", "raster" ); + ws->Connect( "spline", "raster", "Output", "Input" ); + ws->Connect( "reader", "raster", "Output", "Template" ); + raster->Update( ); + */ + #else // cpExtensions_QT4 return( 0 ); #endif // cpExtensions_QT4 diff --git a/lib/cpPlugins/DataObjects/Image.cxx b/lib/cpPlugins/DataObjects/Image.cxx index 1d6da8d..da575bb 100644 --- a/lib/cpPlugins/DataObjects/Image.cxx +++ b/lib/cpPlugins/DataObjects/Image.cxx @@ -1,4 +1,5 @@ #include +#include // ------------------------------------------------------------------------- void cpPlugins::DataObjects::Image:: @@ -20,9 +21,41 @@ SetITK( itk::LightObject* o ) void cpPlugins::DataObjects::Image:: SetVTK( vtkObjectBase* o ) { - this->Superclass::SetVTK( o ); - std::cerr << "Image: TODO this!!!!" << std::endl; - std::exit( 1 ); + vtkImageData* img = dynamic_cast< vtkImageData* >( img ); + this->Superclass::SetVTK( img ); + if( img == NULL ) + { + this->m_ITK = NULL; + this->m_ITKvVTK = NULL; + this->Modified( ); + return; + + } // fi + + // Connect both worlds + this->_VTK_2_ITK_0< unsigned char >( img ); + /* TODO + switch( img->GetScalarType( ) ) + { + case VTK_CHAR: this->_VTK_2_ITK_0< char >( img ); break; + case VTK_SHORT: this->_VTK_2_ITK_0< short >( img ); break; + case VTK_INT: this->_VTK_2_ITK_0< int >( img ); break; + case VTK_LONG: this->_VTK_2_ITK_0< long >( img ); break; + case VTK_UNSIGNED_CHAR: this->_VTK_2_ITK_0< unsigned char >( img ); break; + case VTK_UNSIGNED_SHORT: this->_VTK_2_ITK_0< unsigned short >( img ); break; + case VTK_UNSIGNED_INT: this->_VTK_2_ITK_0< unsigned int >( img ); break; + case VTK_UNSIGNED_LONG: this->_VTK_2_ITK_0< unsigned long >( img ); break; + case VTK_FLOAT: this->_VTK_2_ITK_0< float >( img ); break; + case VTK_DOUBLE: this->_VTK_2_ITK_0< double >( img ); break; + default: + { + this->m_ITK = NULL; + this->m_ITKvVTK = NULL; + + } + } // hctiws + */ + this->Modified( ); } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/DataObjects/Image.h b/lib/cpPlugins/DataObjects/Image.h index 107c69e..bfe1d67 100644 --- a/lib/cpPlugins/DataObjects/Image.h +++ b/lib/cpPlugins/DataObjects/Image.h @@ -40,6 +40,12 @@ namespace cpPlugins template< class _TImage > inline void _ITK_2_VTK_1( _TImage* image ); + template< class _TPixel > + inline void _VTK_2_ITK_0( vtkImageData* image ); + + template< class _TPixel, unsigned int _VDim > + inline void _VTK_2_ITK_1( vtkImageData* image ); + private: // Purposely not implemented Image( const Self& ); @@ -54,7 +60,6 @@ namespace cpPlugins } // ecapseman #include -#include #endif // __cpPlugins__DataObjects__Image__h__ diff --git a/lib/cpPlugins/DataObjects/Image.hxx b/lib/cpPlugins/DataObjects/Image.hxx index ea76d1e..3b0bd8e 100644 --- a/lib/cpPlugins/DataObjects/Image.hxx +++ b/lib/cpPlugins/DataObjects/Image.hxx @@ -2,8 +2,11 @@ #define __cpPlugins__DataObjects__Image__hxx__ #include +#include #include +#include #include +#include // ------------------------------------------------------------------------- template< unsigned int _VDim > @@ -48,6 +51,49 @@ _ITK_2_VTK_1( _TImage* image ) this->m_VTK = f->GetOutput( ); } +// ------------------------------------------------------------------------- +template< class _TPixel > +void cpPlugins::DataObjects::Image:: +_VTK_2_ITK_0( vtkImageData* image ) +{ + if( image->GetDataDimension( ) == 2 ) + this->_VTK_2_ITK_1< _TPixel, 2 >( image ); + else if( image->GetDataDimension( ) == 3 ) + this->_VTK_2_ITK_1< _TPixel, 3 >( image ); + else + { + this->m_ITK = NULL; + this->m_ITKvVTK = NULL; + + } // fi +} + +// ------------------------------------------------------------------------- +template< class _TPixel, unsigned int _VDim > +void cpPlugins::DataObjects::Image:: +_VTK_2_ITK_1( vtkImageData* image ) +{ + typedef itk::Image< _TPixel, _VDim > _TImage; + typedef itk::VTKImageToImageFilter< _TImage > _TFilter; + _TFilter* f = dynamic_cast< _TFilter* >( this->m_ITKvVTK.GetPointer( ) ); + + std::cout << typeid( _TImage ).name( ) << std::endl; + + if( f == NULL ) + { + typename _TFilter::Pointer nf = _TFilter::New( ); + this->m_ITKvVTK = nf; + f = nf.GetPointer( ); + + } // fi + f->SetInput( image ); + f->Update( ); + + // Keep object track + this->m_VTK = image; + this->m_ITK = f->GetOutput( ); +} + #endif // __cpPlugins__DataObjects__Image__hxx__ // eof - $RCSfile$ diff --git a/plugins/ImageMeshFilters/RasterMeshFilter.cxx b/plugins/ImageMeshFilters/RasterMeshFilter.cxx new file mode 100644 index 0000000..f2ac07f --- /dev/null +++ b/plugins/ImageMeshFilters/RasterMeshFilter.cxx @@ -0,0 +1,294 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +// ------------------------------------------------------------------------- +cpPluginsImageMeshFilters::RasterMeshFilter:: +RasterMeshFilter( ) + : Superclass( ) +{ + typedef cpPlugins::BaseObjects::DataObject _TDataObject; + typedef cpPlugins::DataObjects::Image _TImage; + typedef cpPlugins::DataObjects::Mesh _TMesh; + + this->_ConfigureInput< _TMesh >( "Input", true, false ); + this->_ConfigureInput< _TDataObject >( "Template", false, false ); + this->_ConfigureOutput< _TImage >( "Output" ); + + this->m_Parameters.ConfigureAsUint( "InsideValue" ); + this->m_Parameters.ConfigureAsUint( "OutsideValue" ); + this->m_Parameters.ConfigureAsUint( "MinimumSize" ); + + this->m_Parameters.SetUint( "InsideValue", 1 ); + this->m_Parameters.SetUint( "OutsideValue", 0 ); + this->m_Parameters.SetUint( "MinimumSize", 100 ); +} + +// ------------------------------------------------------------------------- +cpPluginsImageMeshFilters::RasterMeshFilter:: +~RasterMeshFilter( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsImageMeshFilters::RasterMeshFilter:: +_GenerateData( ) +{ + typedef itk::Mesh< float, 3 > _3F; + typedef itk::Mesh< double, 3 > _3D; + + bool is_2d = false; + auto pd = this->GetInputData< vtkPolyData >( "Input" ); + if( pd != NULL ) + { + double bounds[ 6 ]; + pd->GetBounds( bounds ); + is_2d = ( bounds[ 4 ] == bounds[ 5 ] ); + + } // fi + if( !is_2d ) + { + auto _3f = this->GetInputData< _3F >( "Input" ); + auto _3d = this->GetInputData< _3D >( "Input" ); + if ( _3f != NULL ) this->_GD0_3D( _3f ); + else if( _3d != NULL ) this->_GD0_3D( _3d ); + else this->_Error( "No valid input mesh." ); + } + else + this->_GD0_2D( pd ); +} + +// ------------------------------------------------------------------------- +template< class _TMesh > +void cpPluginsImageMeshFilters::RasterMeshFilter:: +_GD0_2D( _TMesh* mesh ) +{ + typedef itk::ImageBase< 2 > _TImageBase; + typedef itk::Image< unsigned char, 2 > _TImage; + typedef cpPlugins::DataObjects::BoundingBox _TBB; + typedef typename _TImage::PointType _TPoint; + + static const unsigned int PAD = 10; + + _TImage::Pointer white = this->GetOutputData< _TImage >( "Output" ); + if( white.IsNull( ) ) + white = _TImage::New( ); + + // Get configuration values + typename _TImage::SpacingType spac; + typename _TImage::SizeType size; + typename _TImage::PointType origin; + typename _TImage::DirectionType direction; + typename _TImage::IndexType index; + + auto in_bb = this->GetInput< _TBB >( "Template" ); + auto in_im = this->GetInputData< _TImageBase >( "Template" ); + if( in_im != NULL ) + { + spac = in_im->GetSpacing( ); + size = in_im->GetLargestPossibleRegion( ).GetSize( ); + origin = in_im->GetOrigin( ); + direction = in_im->GetDirection( ); + index = in_im->GetLargestPossibleRegion( ).GetIndex( ); + } + else + { + _TPoint minBB, maxBB; + if( in_bb != NULL ) + { + minBB = in_bb->GetMinimum< _TPoint >( ); + maxBB = in_bb->GetMaximum< _TPoint >( ); + } + else + { + double bounds[ 6 ]; + mesh->GetBounds( bounds ); + minBB[ 0 ] = bounds[ 0 ]; + minBB[ 1 ] = bounds[ 1 ]; + maxBB[ 0 ] = bounds[ 2 ]; + maxBB[ 1 ] = bounds[ 3 ]; + + } // fi + + double lx = double( maxBB[ 0 ] - minBB[ 0 ] ); + double ly = double( maxBB[ 1 ] - minBB[ 1 ] ); + double lm = ( lx < ly )? lx: ly; + + // Compute spacing + spac.Fill( lm / double( this->m_Parameters.GetUint( "MinimumSize" ) ) ); + + // Compute size + size[ 0 ] = ( unsigned long )( std::ceil( lx / spac[ 0 ] ) ); + size[ 1 ] = ( unsigned long )( std::ceil( ly / spac[ 1 ] ) ); + + // ... add some padding pixels + size[ 0 ] += PAD; + size[ 1 ] += PAD; + + // Set origin + origin = minBB; + origin[ 0 ] -= double( PAD >> 1 ) * spac[ 0 ]; + origin[ 1 ] -= double( PAD >> 1 ) * spac[ 1 ]; + + // Remaining values + direction.SetIdentity( ); + index.Fill( 0 ); + + } // fi + + // Configure output image + _TImage::RegionType region; + region.SetSize( size ); + region.SetIndex( index ); + white->SetSpacing( spac ); + white->SetRegions( region ); + white->SetOrigin( origin ); + white->SetDirection( direction ); + white->Allocate( ); + white->FillBuffer( this->m_Parameters.GetUint( "InsideValue" ) ); + if( this->m_WhiteImage.IsNull( ) ) + this->m_WhiteImage = TImage::New( ); + this->m_WhiteImage->SetITK( white ); + vtkImageData* white_vtk = this->m_WhiteImage->GetVTK< vtkImageData >( ); + + // Configure mini-pipeline + if( this->m_Stripper.GetPointer( ) == NULL ) + this->m_Stripper = vtkSmartPointer< vtkStripper >::New( ); + this->m_Stripper->SetInputData( mesh ); + this->m_Stripper->Update( ); + + if( this->m_Extruder.GetPointer( ) == NULL ) + this->m_Extruder = vtkSmartPointer< vtkLinearExtrusionFilter >::New( ); + this->m_Extruder->SetInputConnection( this->m_Stripper->GetOutputPort( ) ); + this->m_Extruder->SetScaleFactor( double( 1 ) ); + this->m_Extruder->SetExtrusionTypeToNormalExtrusion( ); + this->m_Extruder->SetVector( 0, 0, 1 ); + this->m_Extruder->Update( ); + + if( this->m_PolyDataToStencil.GetPointer( ) == NULL ) + this->m_PolyDataToStencil = + vtkSmartPointer< vtkPolyDataToImageStencil >::New( ); + this->m_PolyDataToStencil->SetTolerance( 0 ); + this->m_PolyDataToStencil->SetInputConnection( this->m_Extruder->GetOutputPort( ) ); + this->m_PolyDataToStencil->SetOutputOrigin( white_vtk->GetOrigin( ) ); + this->m_PolyDataToStencil->SetOutputSpacing( white_vtk->GetSpacing( ) ); + this->m_PolyDataToStencil->SetOutputWholeExtent( white_vtk->GetExtent( ) ); + this->m_PolyDataToStencil->Update( ); + + this->m_ImageStencil = this->_CreateVTK< vtkImageStencil >( ); + this->m_ImageStencil->SetInputData( white_vtk ); + this->m_ImageStencil->SetStencilConnection( this->m_PolyDataToStencil->GetOutputPort( ) ); + this->m_ImageStencil->ReverseStencilOff( ); + this->m_ImageStencil->SetBackgroundValue( this->m_Parameters.GetUint( "OutsideValue" ) ); + this->m_ImageStencil->Update( ); + this->GetOutput( "Output" )->SetVTK( this->m_ImageStencil->GetOutput( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TMesh > +void cpPluginsImageMeshFilters::RasterMeshFilter:: +_GD0_3D( _TMesh* mesh ) +{ + typedef unsigned char _TPixel; + typedef cpPlugins::DataObjects::BoundingBox _TBB; + typedef itk::ImageBase< _TMesh::PointDimension > _TImageBase; + typedef itk::Image< _TPixel, _TMesh::PointDimension > _TImage; + typedef itk::TriangleMeshToBinaryImageFilter< _TMesh, _TImage > _TFilter; + typedef typename _TImage::PointType _TPoint; + + static const unsigned int PAD = 10; + + _TFilter* filter = this->_CreateITK< _TFilter >( ); + this->m_WhiteImage = NULL; + this->m_Stripper = NULL; + this->m_Extruder = NULL; + this->m_PolyDataToStencil = NULL; + this->m_ImageStencil = NULL; + + // Get configuration values + typename _TImage::SpacingType spac; + typename _TImage::SizeType size; + typename _TImage::PointType origin; + typename _TImage::DirectionType direction; + typename _TImage::IndexType index; + + auto in_bb = this->GetInput< _TBB >( "Template" ); + auto in_im = this->GetInputData< _TImageBase >( "Template" ); + if( in_im != NULL ) + { + spac = in_im->GetSpacing( ); + size = in_im->GetLargestPossibleRegion( ).GetSize( ); + origin = in_im->GetOrigin( ); + direction = in_im->GetDirection( ); + index = in_im->GetLargestPossibleRegion( ).GetIndex( ); + } + else + { + _TPoint minBB, maxBB; + if( in_bb != NULL ) + { + minBB = in_bb->GetMinimum< _TPoint >( ); + maxBB = in_bb->GetMaximum< _TPoint >( ); + } + else + { + auto bb = mesh->GetBoundingBox( ); + minBB = bb->GetMinimum( ); + maxBB = bb->GetMaximum( ); + + } // fi + + double lx = double( maxBB[ 0 ] - minBB[ 0 ] ); + double ly = double( maxBB[ 1 ] - minBB[ 1 ] ); + double lz = double( maxBB[ 2 ] - minBB[ 2 ] ); + double lm = ( lx < ly )? lx: ly; + lm = ( lm < lz )? lm: lz; + + // Compute spacing + spac.Fill( lm / double( this->m_Parameters.GetUint( "MinimumSize" ) ) ); + + // Compute size + size[ 0 ] = ( unsigned long )( std::ceil( lx / spac[ 0 ] ) ); + size[ 1 ] = ( unsigned long )( std::ceil( ly / spac[ 1 ] ) ); + size[ 2 ] = ( unsigned long )( std::ceil( lz / spac[ 2 ] ) ); + + // ... add some padding pixels + size[ 0 ] += PAD; + size[ 1 ] += PAD; + size[ 2 ] += PAD; + + // Set origin + origin = minBB; + origin[ 0 ] -= double( PAD >> 1 ) * spac[ 0 ]; + origin[ 1 ] -= double( PAD >> 1 ) * spac[ 1 ]; + origin[ 2 ] -= double( PAD >> 1 ) * spac[ 2 ]; + + // Remaining values + direction.SetIdentity( ); + index.Fill( 0 ); + + } // fi + + // Execute + filter->SetInput( mesh ); + filter->SetSpacing( spac ); + filter->SetSize( size ); + filter->SetOrigin( origin ); + filter->SetDirection( direction ); + filter->SetIndex( index ); + filter->SetInsideValue( this->m_Parameters.GetUint( "InsideValue" ) ); + filter->SetOutsideValue( this->m_Parameters.GetUint( "OutsideValue" ) ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/ImageMeshFilters/RasterMeshFilter.h b/plugins/ImageMeshFilters/RasterMeshFilter.h new file mode 100644 index 0000000..d6c1953 --- /dev/null +++ b/plugins/ImageMeshFilters/RasterMeshFilter.h @@ -0,0 +1,51 @@ +#ifndef __cpPluginsImageMesh__RasterMeshFilter__h__ +#define __cpPluginsImageMesh__RasterMeshFilter__h__ + +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +class vtkStripper; +class vtkLinearExtrusionFilter; +class vtkPolyDataToImageStencil; +class vtkImageStencil; + +// ------------------------------------------------------------------------- +namespace cpPluginsImageMeshFilters +{ + /** + */ + class cpPluginsImageMeshFilters_EXPORT RasterMeshFilter + : public cpPlugins::BaseObjects::ProcessObject + { + cpPluginsObject( + RasterMeshFilter, + cpPlugins::BaseObjects::ProcessObject, + MeshToImageFilters + ); + + public: + typedef cpPlugins::DataObjects::Image TImage; + + protected: + template< class _TMesh > + inline void _GD0_2D( _TMesh* mesh ); + + template< class _TMesh > + inline void _GD0_3D( _TMesh* mesh ); + + protected: + TImage::Pointer m_WhiteImage; + vtkSmartPointer< vtkStripper > m_Stripper; + vtkSmartPointer< vtkLinearExtrusionFilter > m_Extruder; + vtkSmartPointer< vtkPolyDataToImageStencil > m_PolyDataToStencil; + vtkSmartPointer< vtkImageStencil > m_ImageStencil; + }; + +} // ecapseman + +#endif // __cpPluginsImageMesh__RasterMeshFilter__h__ + +// eof - $RCSfile$ diff --git a/plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.cxx b/plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.cxx deleted file mode 100644 index b5f4e19..0000000 --- a/plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.cxx +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include - -#include -#include - -// ------------------------------------------------------------------------- -cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter:: -TriangleMeshToBinaryImageFilter( ) - : Superclass( ) -{ - this->_ConfigureInput< cpPlugins::DataObjects::Mesh >( "Input", true, false ); - this->_ConfigureInput< cpPlugins::DataObjects::BoundingBox >( "BoundingBox", true, false ); - this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" ); - - this->m_Parameters.ConfigureAsUint( "InsideValue" ); - this->m_Parameters.ConfigureAsUint( "OutsideValue" ); - this->m_Parameters.ConfigureAsUint( "MinimumSize" ); - - this->m_Parameters.SetUint( "InsideValue", 1 ); - this->m_Parameters.SetUint( "OutsideValue", 0 ); - this->m_Parameters.SetUint( "MinimumSize", 100 ); -} - -// ------------------------------------------------------------------------- -cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter:: -~TriangleMeshToBinaryImageFilter( ) -{ -} - -// ------------------------------------------------------------------------- -void cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter:: -_GenerateData( ) -{ - typedef itk::Mesh< float, 3 > _3F; - typedef itk::Mesh< double, 3 > _3D; - - auto _3f = this->GetInputData< _3F >( "Input" ); - auto _3d = this->GetInputData< _3D >( "Input" ); - if ( _3f != NULL ) this->_GD0( _3f ); - else if( _3d != NULL ) this->_GD0( _3d ); - else this->_Error( "No valid input mesh." ); -} - -// ------------------------------------------------------------------------- -template< class _TMesh > -void cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter:: -_GD0( _TMesh* mesh ) -{ - this->_GD1< _TMesh, unsigned char >( mesh ); -} - -// ------------------------------------------------------------------------- -template< class _TMesh, class _TPixel > -void cpPluginsImageMeshFilters::TriangleMeshToBinaryImageFilter:: -_GD1( _TMesh* mesh ) -{ - typedef cpPlugins::DataObjects::BoundingBox _TBB; - typedef itk::Image< _TPixel, _TMesh::PointDimension > _TImage; - typedef itk::TriangleMeshToBinaryImageFilter< _TMesh, _TImage > _TFilter; - typedef typename _TImage::PointType _TPoint; - - static const unsigned int PAD = 10; - - _TFilter* filter = this->_CreateITK< _TFilter >( ); - - auto in_bb = dynamic_cast< _TBB* >( this->GetInput( "BoundingBox" ) ); - _TPoint minBB, maxBB; - if( in_bb == NULL ) - { - auto bb = mesh->GetBoundingBox( ); - minBB = bb->GetMinimum( ); - maxBB = bb->GetMaximum( ); - } - else - { - minBB = in_bb->GetMinimum< _TPoint >( ); - maxBB = in_bb->GetMaximum< _TPoint >( ); - - } // fi - - double lx = double( maxBB[ 0 ] - minBB[ 0 ] ); - double ly = double( maxBB[ 1 ] - minBB[ 1 ] ); - double lz = double( maxBB[ 2 ] - minBB[ 2 ] ); - double lm = ( lx < ly )? lx: ly; - lm = ( lm < lz )? lm: lz; - - // Compute spacing - double mSpac = lm / double( this->m_Parameters.GetUint( "MinimumSize" ) ); - typename _TImage::SpacingType spac; - spac.Fill( mSpac ); - filter->SetSpacing( spac ); - - // Compute size - typename _TImage::SizeType size; - size[ 0 ] = ( unsigned long )( std::ceil( lx / mSpac ) ); - size[ 1 ] = ( unsigned long )( std::ceil( ly / mSpac ) ); - size[ 2 ] = ( unsigned long )( std::ceil( lz / mSpac ) ); - - // ... add some padding pixels - size[ 0 ] += PAD; - size[ 1 ] += PAD; - size[ 2 ] += PAD; - filter->SetSize( size ); - - // Set origin - typename _TImage::PointType origin = minBB; - origin[ 0 ] -= double( PAD >> 1 ) * spac[ 0 ]; - origin[ 1 ] -= double( PAD >> 1 ) * spac[ 1 ]; - origin[ 2 ] -= double( PAD >> 1 ) * spac[ 2 ]; - filter->SetOrigin( origin ); - - // Remaining values - typename _TImage::DirectionType direction; - direction.SetIdentity( ); - filter->SetDirection( direction ); - - typename _TImage::IndexType index; - index.Fill( 0 ); - filter->SetIndex( index ); - - // Execute - filter->SetInput( mesh ); - filter->SetInsideValue( this->m_Parameters.GetUint( "InsideValue" ) ); - filter->SetOutsideValue( this->m_Parameters.GetUint( "OutsideValue" ) ); - filter->Update( ); - - // Connect output - this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); -} - -// eof - $RCSfile$ diff --git a/plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.h b/plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.h deleted file mode 100644 index 7361ca1..0000000 --- a/plugins/ImageMeshFilters/TriangleMeshToBinaryImageFilter.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __CPPLUGINSIMAGEMESH__TRIANGLEMESHTOBINARYIMAGEFILTER__H__ -#define __CPPLUGINSIMAGEMESH__TRIANGLEMESHTOBINARYIMAGEFILTER__H__ - -#include -#include - -namespace cpPluginsImageMeshFilters -{ - /** - */ - class cpPluginsImageMeshFilters_EXPORT TriangleMeshToBinaryImageFilter - : public cpPlugins::BaseObjects::ProcessObject - { - cpPluginsObject( - TriangleMeshToBinaryImageFilter, - cpPlugins::BaseObjects::ProcessObject, - MeshToImageFilters - ); - - protected: - template< class _TMesh > - inline void _GD0( _TMesh* mesh ); - - template< class _TMesh, class _TPixel > - inline void _GD1( _TMesh* mesh ); - }; - -} // ecapseman - -#endif // __CPPLUGINSIMAGEMESH__TRIANGLEMESHTOBINARYIMAGEFILTER__H__ - -// eof - $RCSfile$ diff --git a/plugins/Widgets/SeedWidget.cxx b/plugins/Widgets/SeedWidget.cxx index e12fc11..8ff3019 100644 --- a/plugins/Widgets/SeedWidget.cxx +++ b/plugins/Widgets/SeedWidget.cxx @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff --git a/plugins/Widgets/SplineWidget.cxx b/plugins/Widgets/SplineWidget.cxx index c6e7116..74680df 100644 --- a/plugins/Widgets/SplineWidget.cxx +++ b/plugins/Widgets/SplineWidget.cxx @@ -3,6 +3,7 @@ #include #include +#include #include #include -- 2.45.1