#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$