#include #include #include #include #include #include #include // ------------------------------------------------------------------------- cpPluginsITKImageGenericFilters_1::RegionOfInterestImageFilter:: RegionOfInterestImageFilter( ) : Superclass( ) { typedef cpInstances::Image _TImage; typedef cpInstances::BoundingBox _TBBox; this->_ConfigureInput< _TImage >( "Input", true, false ); this->_ConfigureInput< _TBBox >( "BoundingBox", true, false ); this->_ConfigureOutput< _TImage >( "Output" ); } // ------------------------------------------------------------------------- cpPluginsITKImageGenericFilters_1::RegionOfInterestImageFilter:: ~RegionOfInterestImageFilter( ) { } // ------------------------------------------------------------------------- void cpPluginsITKImageGenericFilters_1::RegionOfInterestImageFilter:: _GenerateData( ) { auto o = this->GetInputData( "Input" ); cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) this->_Error( "Invalid input image." ); } // ------------------------------------------------------------------------- template< class _TImage > void cpPluginsITKImageGenericFilters_1::RegionOfInterestImageFilter:: _GD0( _TImage* input ) { typedef cpInstances::BoundingBox _TBBox; typedef itk::RegionOfInterestImageFilter< _TImage, _TImage > _TFilter; typedef typename _TImage::IndexType _TIndex; typedef typename _TImage::PointType _TPoint; typedef typename _TImage::RegionType _TRegion; typedef typename _TImage::SizeType _TSize; auto bb = this->GetInput< _TBBox >( "BoundingBox" ); _TIndex i0, i1; input->TransformPhysicalPointToIndex( bb->GetMinimum< _TPoint >( ), i0 ); input->TransformPhysicalPointToIndex( bb->GetMaximum< _TPoint >( ), i1 ); _TSize size; for( unsigned int d = 0; d < _TImage::ImageDimension; ++d ) size[ d ] = i1[ d ] - i0[ d ] + 1; _TRegion region; region.SetIndex( i0 ); region.SetSize( size ); auto filter = this->_CreateITK< _TFilter >( ); filter->SetInput( input ); filter->SetRegionOfInterest( region ); filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); } // eof - $RCSfile$