From 11e35edc49196410d7088a24a39dadcf3eba8992 Mon Sep 17 00:00:00 2001 From: "Stephen R. Aylward" Date: Wed, 26 Jun 2024 10:28:01 -0400 Subject: [PATCH] ENH: Update to support ITK >= 5.4 and MetaIO versioning (#163) Updated to ITKv5.4 include: * ITK_NULLPTR -> nullptr * ITK_OVERRIDE -> override MetaIO updates include * use of itksys instead of std for ifstream/ofstream * use of metaio version 1 features with spatial objects --- .../ComputeTubeProbability.cxx | 11 +- .../Testing/ConvertTubesToImageTest.py | 2 +- include/tubeShrinkImageWithBlending.hxx | 4 +- src/Filtering.cmake | 2 + src/Filtering/itkImageRegionSplitter.h | 4 +- .../itktubeShrinkWithBlendingImageFilter.hxx | 6 +- src/IO/itktubePDFSegmenterParzenIO.hxx | 5 +- src/MetaIO/itktubeMetaClassPDF.cxx | 157 +++++---------- src/MetaIO/itktubeMetaClassPDF.h | 28 +-- src/MetaIO/itktubeMetaLDA.cxx | 18 +- src/MetaIO/itktubeMetaLDA.h | 11 +- src/MetaIO/itktubeMetaNJetLDA.cxx | 18 +- src/MetaIO/itktubeMetaNJetLDA.h | 11 +- src/MetaIO/itktubeMetaRidgeSeed.cxx | 16 +- src/MetaIO/itktubeMetaRidgeSeed.h | 12 +- src/MetaIO/itktubeMetaTubeExtractor.cxx | 16 +- src/MetaIO/itktubeMetaTubeExtractor.h | 11 +- src/Registration.cmake | 2 - src/Registration/itkImageRegionSplitter.h | 183 ------------------ src/Registration/itkImageRegionSplitter.hxx | 136 ------------- .../itkScaleSkewAngle2DTransform.h | 16 +- src/Registration/itkSimilarity2DTransform.h | 18 +- src/Registration/itkSimilarity2DTransform.hxx | 2 +- src/Segmentation/itktubeRadiusExtractor2.hxx | 16 +- .../Segmentation/itktubeTubeExtractorTest.cxx | 14 +- 25 files changed, 192 insertions(+), 527 deletions(-) delete mode 100644 src/Registration/itkImageRegionSplitter.h delete mode 100644 src/Registration/itkImageRegionSplitter.hxx diff --git a/examples/Applications/ComputeTubeProbability/ComputeTubeProbability.cxx b/examples/Applications/ComputeTubeProbability/ComputeTubeProbability.cxx index 2b9cee36c..9c8b4862c 100644 --- a/examples/Applications/ComputeTubeProbability/ComputeTubeProbability.cxx +++ b/examples/Applications/ComputeTubeProbability/ComputeTubeProbability.cxx @@ -92,7 +92,7 @@ int DoIt( int argc, char * argv[] ) itk::Point pnt; itk::Index< VDimension > indx; tube->Update(); - + for( unsigned int i=0; iGetNumberOfPoints(); i++ ) { // Get point @@ -102,8 +102,13 @@ int DoIt( int argc, char * argv[] ) pnt = tubePoint.GetPositionInWorldSpace(); // Get closest voxel - meanImage->TransformPhysicalPointToIndex( pnt, indx ); - + bool success = meanImage->TransformPhysicalPointToIndex( pnt, indx ); + if( !success ) + { + ::tube::WarningMessage("Point is outside of image bounds."); + continue; + } + // Write value of ATLAS EMD file at voxel writeStream << meanImage->GetPixel( indx ) << std::endl; } diff --git a/examples/Applications/ConvertTubesToImage/Testing/ConvertTubesToImageTest.py b/examples/Applications/ConvertTubesToImage/Testing/ConvertTubesToImageTest.py index 3c451bea4..530567494 100644 --- a/examples/Applications/ConvertTubesToImage/Testing/ConvertTubesToImageTest.py +++ b/examples/Applications/ConvertTubesToImage/Testing/ConvertTubesToImageTest.py @@ -5,7 +5,7 @@ # Append ITK libs sys.path.append(os.path.join(os.environ['ITK_BUILD_DIR'], 'Wrapping/Generators/Python')) -sys.path.append(os.path.join(os.environ['ITK_BUILD_DIR'], 'lib') +sys.path.append(os.path.join(os.environ['ITK_BUILD_DIR'], 'lib')) # Append TubeTK libs : sys.path.append(os.environ['TUBETK_BUILD_DIR'], 'TubeTK-build/lib/TubeTK') diff --git a/include/tubeShrinkImageWithBlending.hxx b/include/tubeShrinkImageWithBlending.hxx index 5c7330472..09828506a 100644 --- a/include/tubeShrinkImageWithBlending.hxx +++ b/include/tubeShrinkImageWithBlending.hxx @@ -87,7 +87,7 @@ ShrinkImageWithBlending< TInputImage, TOutputImage > os << indent << "UseLog:" << m_Filter->GetUseLog() << std::endl; - if( m_Filter->GetInputMipPointImage() != ITK_NULLPTR ) + if( m_Filter->GetInputMipPointImage() != nullptr ) { os << indent << "Input MIP Point Image: " << m_Filter->GetInputMipPointImage() << std::endl; @@ -97,7 +97,7 @@ ShrinkImageWithBlending< TInputImage, TOutputImage > os << indent << "Input MIP Point Image: NULL" << std::endl; } - if( m_Filter->GetOutputMipPointImage() != ITK_NULLPTR ) + if( m_Filter->GetOutputMipPointImage() != nullptr ) { os << indent << "Output MIP Point Image: " << m_Filter->GetOutputMipPointImage() << std::endl; diff --git a/src/Filtering.cmake b/src/Filtering.cmake index 280c9b6ce..d974f6667 100644 --- a/src/Filtering.cmake +++ b/src/Filtering.cmake @@ -22,6 +22,7 @@ set( TubeTK_Filtering_H_Files Filtering/itkGeneralizedDistanceTransformImageFilter.h + Filtering/itkImageRegionSplitter.h Filtering/itktubeAnisotropicCoherenceEnhancingDiffusionImageFilter.h Filtering/itktubeAnisotropicDiffusionTensorFunction.h Filtering/itktubeAnisotropicDiffusionTensorImageFilter.h @@ -65,6 +66,7 @@ set( TubeTK_Filtering_H_Files set( TubeTK_Filtering_HXX_Files Filtering/itkGeneralizedDistanceTransformImageFilter.txx + Filtering/itkImageRegionSplitter.hxx Filtering/itktubeAnisotropicCoherenceEnhancingDiffusionImageFilter.hxx Filtering/itktubeAnisotropicDiffusionTensorFunction.hxx Filtering/itktubeAnisotropicDiffusionTensorImageFilter.hxx diff --git a/src/Filtering/itkImageRegionSplitter.h b/src/Filtering/itkImageRegionSplitter.h index 2eb506b35..94f5198f5 100644 --- a/src/Filtering/itkImageRegionSplitter.h +++ b/src/Filtering/itkImageRegionSplitter.h @@ -119,7 +119,7 @@ class ImageRegionSplitter:public ImageRegionSplitterBase virtual unsigned int GetNumberOfSplitsInternal( unsigned int, const IndexValueType regionIndex[], const SizeValueType regionSize[], - unsigned int requestedNumber ) const ITK_OVERRIDE + unsigned int requestedNumber ) const override { // this function adapts the legecy method, defined in this class // be used by the ImageRegionSplitterBase. @@ -137,7 +137,7 @@ class ImageRegionSplitter:public ImageRegionSplitterBase unsigned int i, unsigned int numberOfPieces, IndexValueType regionIndex[], - SizeValueType regionSize[] ) const ITK_OVERRIDE + SizeValueType regionSize[] ) const override { // this function adapts the legecy method, defined in this class // be used by the ImageRegionSplitterBase. diff --git a/src/Filtering/itktubeShrinkWithBlendingImageFilter.hxx b/src/Filtering/itktubeShrinkWithBlendingImageFilter.hxx index 6851d58c2..1128b32ff 100644 --- a/src/Filtering/itktubeShrinkWithBlendingImageFilter.hxx +++ b/src/Filtering/itktubeShrinkWithBlendingImageFilter.hxx @@ -38,8 +38,8 @@ template< class TInputImage, class TOutputImage > ShrinkWithBlendingImageFilter< TInputImage, TOutputImage > ::ShrinkWithBlendingImageFilter( void ) { - m_InputMipPointImage = ITK_NULLPTR; - m_OutputMipPointImage = ITK_NULLPTR; + m_InputMipPointImage = nullptr; + m_OutputMipPointImage = nullptr; m_Overlap.Fill( 0 ); @@ -357,7 +357,7 @@ ShrinkWithBlendingImageFilter< TInputImage, TOutputImage > progress.CompletedPixel(); } - if( inputMipPointItPtr != ITK_NULLPTR ) + if( inputMipPointItPtr != nullptr ) { delete inputMipPointItPtr; } diff --git a/src/IO/itktubePDFSegmenterParzenIO.hxx b/src/IO/itktubePDFSegmenterParzenIO.hxx index e1c87eaa2..67f51c5f0 100644 --- a/src/IO/itktubePDFSegmenterParzenIO.hxx +++ b/src/IO/itktubePDFSegmenterParzenIO.hxx @@ -198,8 +198,6 @@ Read( const char * _headerName ) std::cout << "MetaClassPDF: M_SetupReadFields" << std::endl; } - MetaClassPDF classPDFReader; - std::vector< MET_FieldRecordType * > metaFields; MET_FieldRecordType * mF; @@ -485,6 +483,9 @@ Read( const char * _headerName ) 0.005 * spacing[j] ) { std::cout << "ERROR: Spacing mismatch" << std::endl; + std::cout << " Spacing[" << j << "] = " << spacing[j] << std::endl; + std::cout << " PDFSpacing[" << j << "] = " + << m_PDFSegmenter->GetBinSize()[j] << std::endl; for( unsigned int f=0; fGetNumberOfFeatures(), + MetaClassPDF::InitializeEssential( tmpPDF->GetNumberOfFeatures(), tmpPDF->GetNumberOfBinsPerFeature(), tmpPDF->GetBinMin(), tmpPDF->GetBinSize(), NULL ); @@ -320,13 +287,6 @@ Clear( void ) MetaImage::Clear(); - for( int i=0; i(_binSize[i]); - minD[i] = _binMin[i]; + binMin[i] = _binMin[i]; } MetaImage::InitializeEssential( _nFeatures, nBins, binSize, MET_FLOAT, 1, ( void * )_elementData, true ); - MetaImage::Origin( minD ); + MetaImage::Origin( binMin ); MetaImage::CompressedData( true ); @@ -391,33 +347,32 @@ GetNumberOfFeatures( void ) const void MetaClassPDF:: SetNumberOfBinsPerFeature( const VectorUIntType & _nBinsPerFeature ) { - m_NumberOfBinsPerFeature = _nBinsPerFeature; - int nBins[10]; + double binSize[10]; for( int i = 0; i < MetaImage::NDims(); ++i ) { nBins[i] = _nBinsPerFeature[i]; + binSize[i] = MetaImage::ElementSpacing()[i]; } MetaImage::InitializeEssential( MetaImage::NDims(), nBins, - MetaImage::ElementSpacing(), MET_FLOAT, 1, - ( float * )( MetaImage::ElementData() ) ); + binSize, MET_FLOAT, 1, ( float * )( MetaImage::ElementData() ) ); } -const MetaClassPDF::VectorUIntType & MetaClassPDF:: +const MetaClassPDF::VectorUIntType MetaClassPDF:: GetNumberOfBinsPerFeature( void ) const { + VectorUIntType nBinsPerFeature; + nBinsPerFeature.resize( MetaImage::NDims() ); for( int i = 0; i < MetaImage::NDims(); i++ ) { - m_NumberOfBinsPerFeature[i] = MetaImage::DimSize()[i]; + nBinsPerFeature[i] = MetaImage::DimSize()[i]; } - return m_NumberOfBinsPerFeature; + return nBinsPerFeature; } void MetaClassPDF:: SetBinMin( const VectorDoubleType & _binMin ) { - m_BinMin = _binMin; - double binMinTemp[10]; for( int i = 0; i < MetaImage::NDims(); i++ ) { @@ -426,21 +381,21 @@ SetBinMin( const VectorDoubleType & _binMin ) MetaImage::Origin( binMinTemp ); } -const MetaClassPDF::VectorDoubleType & MetaClassPDF:: +const MetaClassPDF::VectorDoubleType MetaClassPDF:: GetBinMin( void ) const { + VectorDoubleType binMin; + binMin.resize( MetaImage::NDims() ); for( int i = 0; i < MetaImage::NDims(); i++ ) { - m_BinMin[i] = MetaImage::Origin()[i]; + binMin[i] = MetaImage::Origin()[i]; } - return m_BinMin; + return binMin; } void MetaClassPDF:: SetBinSize( const VectorDoubleType & _binSize ) { - m_BinSize = _binSize; - float binSizeTemp[10]; for( int i = 0; i < MetaImage::NDims(); i++ ) { @@ -449,14 +404,16 @@ SetBinSize( const VectorDoubleType & _binSize ) MetaImage::ElementSpacing( binSizeTemp ); } -const MetaClassPDF::VectorDoubleType & MetaClassPDF:: +const MetaClassPDF::VectorDoubleType MetaClassPDF:: GetBinSize( void ) const { + VectorDoubleType binSize; + binSize.resize( MetaImage::NDims() ); for( int i = 0; i < MetaImage::NDims(); i++ ) { - m_BinSize[i] = MetaImage::ElementSpacing()[i]; + binSize[i] = MetaImage::ElementSpacing()[i]; } - return m_BinSize; + return binSize; } void MetaClassPDF:: @@ -484,7 +441,7 @@ SetObjectId( const VectorIntType & _objectId ) m_ObjectId = _objectId; } -const MetaClassPDF::VectorIntType & MetaClassPDF:: +const MetaClassPDF::VectorIntType MetaClassPDF:: GetObjectId( void ) const { return m_ObjectId; @@ -496,7 +453,7 @@ SetObjectPDFWeight( const VectorDoubleType & _objectPDFWeight ) m_ObjectPDFWeight = _objectPDFWeight; } -const MetaClassPDF::VectorDoubleType & MetaClassPDF:: +const MetaClassPDF::VectorDoubleType MetaClassPDF:: GetObjectPDFWeight( void ) const { return m_ObjectPDFWeight; @@ -639,24 +596,24 @@ Read( const char * _headerName ) } bool MetaClassPDF:: -CanReadStream( std::ifstream * _stream ) const +CanReadStream( METAIO_STREAM::ifstream * _stream ) const { return MetaImage::CanReadStream( _stream ); } bool MetaClassPDF:: -ReadStream( std::ifstream * _stream ) +ReadStream( METAIO_STREAM::ifstream * _stream ) { if( META_DEBUG ) { std::cout << "MetaClassPDF: ReadStream" << std::endl; } - M_Destroy(); + MetaClassPDF::M_Destroy(); - Clear(); + MetaClassPDF::Clear(); - M_SetupReadFields(); + MetaClassPDF::M_SetupReadFields(); if( m_ReadStream ) { @@ -675,8 +632,20 @@ ReadStream( std::ifstream * _stream ) m_ReadStream = NULL; - InitializeEssential( MetaImage::NDims(), m_NumberOfBinsPerFeature, - m_BinMin, m_BinSize, ( float * )( m_ElementData ) ); + VectorUIntType nBinsPerFeature; + nBinsPerFeature.resize( MetaImage::NDims() ); + VectorDoubleType binMin; + binMin.resize( MetaImage::NDims() ); + VectorDoubleType binSize; + binSize.resize( MetaImage::NDims() ); + for( int i = 0; i < MetaImage::NDims(); i++ ) + { + nBinsPerFeature[i] = MetaImage::DimSize()[i]; + binMin[i] = MetaImage::Origin()[i]; + binSize[i] = MetaImage::ElementSpacing()[i]; + } + MetaClassPDF::InitializeEssential( MetaImage::NDims(), nBinsPerFeature, + binMin, binSize, ( float * )( m_ElementData ) ); return true; } @@ -688,7 +657,7 @@ Write( const char * _headerName ) } bool MetaClassPDF:: -WriteStream( std::ofstream * _stream ) +WriteStream( METAIO_STREAM::ofstream * _stream ) { return MetaImage::WriteStream( _stream ); } @@ -702,8 +671,6 @@ M_SetupReadFields( void ) << std::endl; } - MetaImage::Clear(); - MetaImage::M_SetupReadFields(); MET_FieldRecordType * mF; @@ -769,20 +736,6 @@ M_SetupReadFields( void ) void MetaClassPDF:: M_SetupWriteFields( void ) { - double binMinTemp[10]; - for( int i = 0; i < MetaImage::NDims(); i++ ) - { - binMinTemp[i] = m_BinMin[i]; - } - MetaImage::Origin( binMinTemp ); - - float binSizeTemp[10]; - for( int i = 0; i < MetaImage::NDims(); i++ ) - { - binSizeTemp[i] = static_cast(m_BinSize[i]); - } - MetaImage::ElementSpacing( binSizeTemp ); - MetaImage::M_SetupWriteFields(); MET_FieldRecordType * mF_LastField; // ElementDataFileName @@ -928,16 +881,6 @@ M_Read( void ) unsigned int nFeatures = static_cast< unsigned int >( MetaImage::NDims() ); - m_BinMin.resize( nFeatures ); - m_BinSize.resize( nFeatures ); - m_NumberOfBinsPerFeature.resize( nFeatures ); - for( unsigned int i = 0; i < nFeatures; ++i ) - { - m_NumberOfBinsPerFeature[i] = MetaImage::DimSize()[i]; - m_BinMin[i] = MetaImage::Origin()[i]; - m_BinSize[i] = MetaImage::ElementSpacing()[i]; - } - MET_FieldRecordType * mF = MET_GetFieldRecord( "NObjects", &m_Fields ); unsigned int nObjects = ( unsigned int )mF->value[0]; diff --git a/src/MetaIO/itktubeMetaClassPDF.h b/src/MetaIO/itktubeMetaClassPDF.h index c49b39c24..47d46820c 100644 --- a/src/MetaIO/itktubeMetaClassPDF.h +++ b/src/MetaIO/itktubeMetaClassPDF.h @@ -24,9 +24,13 @@ limitations under the License. #ifndef __itktubeMetaClassPDF_h #define __itktubeMetaClassPDF_h -#include "metaImage.h" - +#include #include +#include + +#ifndef METAIO_STREAM +#define METAIO_STREAM std +#endif namespace itk { @@ -100,24 +104,24 @@ class MetaClassPDF : private MetaImage unsigned int GetNumberOfFeatures( void ) const; void SetNumberOfBinsPerFeature( const VectorUIntType & _nBins ); - const VectorUIntType & GetNumberOfBinsPerFeature( void ) const; + const VectorUIntType GetNumberOfBinsPerFeature( void ) const; void SetBinMin( const VectorDoubleType & _binMin ); - const VectorDoubleType & GetBinMin( void ) const; + const VectorDoubleType GetBinMin( void ) const; void SetBinSize( const VectorDoubleType & _binSize ); - const VectorDoubleType & GetBinSize( void ) const; + const VectorDoubleType GetBinSize( void ) const; void SetPDF( float * _pdfData ); float * GetPDF( void ); // Data is freed when reader is destroyed float * ExportPDF( void ); // Data persists when reader destroyed void SetObjectId( const VectorIntType & _objectIds ); - const VectorIntType & GetObjectId( void ) const; + const VectorIntType GetObjectId( void ) const; void SetObjectPDFWeight( const VectorDoubleType & _objectWeights ); - const VectorDoubleType & GetObjectPDFWeight( void ) const; + const VectorDoubleType GetObjectPDFWeight( void ) const; void SetVoidId( int _voidId ); int GetVoidId( void ) const; @@ -148,13 +152,13 @@ class MetaClassPDF : private MetaImage virtual bool Read( const char * _headerName = NULL ); - virtual bool CanReadStream( std::ifstream * _stream ) const; + virtual bool CanReadStream( METAIO_STREAM::ifstream * _stream ) const; - virtual bool ReadStream( std::ifstream * _stream ); + virtual bool ReadStream( METAIO_STREAM::ifstream * _stream ); virtual bool Write( const char * _headerName = NULL ); - virtual bool WriteStream( std::ofstream * _stream ); + virtual bool WriteStream( METAIO_STREAM::ofstream * _stream ); protected: @@ -164,10 +168,6 @@ class MetaClassPDF : private MetaImage virtual bool M_Read( void ); - mutable VectorUIntType m_NumberOfBinsPerFeature; - mutable VectorDoubleType m_BinMin; - mutable VectorDoubleType m_BinSize; - VectorIntType m_ObjectId; VectorDoubleType m_ObjectPDFWeight; int m_VoidId; diff --git a/src/MetaIO/itktubeMetaLDA.cxx b/src/MetaIO/itktubeMetaLDA.cxx index 20da4f0f0..2b9deddc0 100644 --- a/src/MetaIO/itktubeMetaLDA.cxx +++ b/src/MetaIO/itktubeMetaLDA.cxx @@ -418,7 +418,7 @@ ::CanRead( const char * headerName ) const } // Now check the file content. - std::ifstream inputStream; + METAIO_STREAM::ifstream inputStream; inputStream.open( headerName, std::ios::in | std::ios::binary ); @@ -450,9 +450,9 @@ ::Read( const char * headerName ) this->FileName( headerName ); } - std::ifstream * const tmpStream = new std::ifstream(); + METAIO_STREAM::ifstream * const tmpStream = new METAIO_STREAM::ifstream(); - tmpStream->open( m_FileName, + tmpStream->open( m_FileName.c_str(), std::ios::in | std::ios::binary ); if( !tmpStream->rdbuf()->is_open() ) @@ -472,7 +472,7 @@ ::Read( const char * headerName ) } bool MetaLDA -::CanReadStream( std::ifstream * stream ) const +::CanReadStream( METAIO_STREAM::ifstream * stream ) const { if( !std::strncmp( MET_ReadForm( *stream ).c_str(), "LDA", 3 ) ) { @@ -483,7 +483,7 @@ ::CanReadStream( std::ifstream * stream ) const } bool MetaLDA -::ReadStream( std::ifstream * stream ) +::ReadStream( METAIO_STREAM::ifstream * stream ) { if( META_DEBUG ) { @@ -531,10 +531,10 @@ ::Write( const char * headerName ) MET_SetFileSuffix( m_FileName, "mlda" ); - std::ofstream * const tmpWriteStream = new - std::ofstream(); + METAIO_STREAM::ofstream * const tmpWriteStream = new + METAIO_STREAM::ofstream(); - tmpWriteStream->open( m_FileName, std::ios::binary + tmpWriteStream->open( m_FileName.c_str(), std::ios::binary | std::ios::out ); if( !tmpWriteStream->rdbuf()->is_open() ) @@ -554,7 +554,7 @@ ::Write( const char * headerName ) } bool MetaLDA -::WriteStream( std::ofstream * stream ) +::WriteStream( METAIO_STREAM::ofstream * stream ) { if( m_WriteStream != NULL ) { diff --git a/src/MetaIO/itktubeMetaLDA.h b/src/MetaIO/itktubeMetaLDA.h index dfd421de6..0bcf297e7 100644 --- a/src/MetaIO/itktubeMetaLDA.h +++ b/src/MetaIO/itktubeMetaLDA.h @@ -24,8 +24,13 @@ limitations under the License. #ifndef __itktubeMetaLDA_h #define __itktubeMetaLDA_h +#include #include +#ifndef METAIO_STREAM +#define METAIO_STREAM std +#endif + #include #include #include @@ -116,13 +121,13 @@ class MetaLDA : public MetaForm virtual bool Read( const char * headerName = NULL ); - virtual bool CanReadStream( std::ifstream * stream ) const; + virtual bool CanReadStream( METAIO_STREAM::ifstream * stream ) const; - virtual bool ReadStream( std::ifstream * stream ); + virtual bool ReadStream( METAIO_STREAM::ifstream * stream ); virtual bool Write( const char * headerName = NULL ); - virtual bool WriteStream( std::ofstream * stream ); + virtual bool WriteStream( METAIO_STREAM::ofstream * stream ); protected: diff --git a/src/MetaIO/itktubeMetaNJetLDA.cxx b/src/MetaIO/itktubeMetaNJetLDA.cxx index f91ed1ae3..f570d0148 100644 --- a/src/MetaIO/itktubeMetaNJetLDA.cxx +++ b/src/MetaIO/itktubeMetaNJetLDA.cxx @@ -306,7 +306,7 @@ ::CanRead( const char * headerName ) const } // Now check the file content. - std::ifstream inputStream; + METAIO_STREAM::ifstream inputStream; inputStream.open( headerName, std::ios::in | std::ios::binary ); @@ -332,9 +332,9 @@ ::Read( const char * headerName ) this->FileName( headerName ); } - std::ifstream * const tmpStream = new std::ifstream(); + METAIO_STREAM::ifstream * const tmpStream = new METAIO_STREAM::ifstream(); - tmpStream->open( m_FileName, + tmpStream->open( m_FileName.c_str(), std::ios::in | std::ios::binary ); if( !tmpStream->rdbuf()->is_open() ) @@ -355,7 +355,7 @@ ::Read( const char * headerName ) } bool MetaNJetLDA -::CanReadStream( std::ifstream * stream ) const +::CanReadStream( METAIO_STREAM::ifstream * stream ) const { if( !std::strncmp( MET_ReadForm( *stream ).c_str(), "NJetLDA", 7 ) ) { @@ -366,7 +366,7 @@ ::CanReadStream( std::ifstream * stream ) const } bool MetaNJetLDA -::ReadStream( std::ifstream * stream ) +::ReadStream( METAIO_STREAM::ifstream * stream ) { if( META_DEBUG ) { @@ -415,10 +415,10 @@ ::Write( const char * headerName ) MET_SetFileSuffix( m_FileName, "mnda" ); - std::ofstream * const tmpWriteStream = new - std::ofstream(); + METAIO_STREAM::ofstream * const tmpWriteStream = new + METAIO_STREAM::ofstream(); - tmpWriteStream->open( m_FileName, + tmpWriteStream->open( m_FileName.c_str(), std::ios::binary | std::ios::out ); if( !tmpWriteStream->rdbuf()->is_open() ) @@ -438,7 +438,7 @@ ::Write( const char * headerName ) } bool MetaNJetLDA -::WriteStream( std::ofstream * stream ) +::WriteStream( METAIO_STREAM::ofstream * stream ) { if( m_WriteStream != NULL ) { diff --git a/src/MetaIO/itktubeMetaNJetLDA.h b/src/MetaIO/itktubeMetaNJetLDA.h index 4106152ac..99f740ed8 100644 --- a/src/MetaIO/itktubeMetaNJetLDA.h +++ b/src/MetaIO/itktubeMetaNJetLDA.h @@ -25,11 +25,16 @@ limitations under the License. #include "itktubeMetaLDA.h" +#include #include #include #include +#ifndef METAIO_STREAM +#define METAIO_STREAM std +#endif + namespace itk { @@ -117,13 +122,13 @@ class MetaNJetLDA : public MetaLDA virtual bool Read( const char * headerName = NULL ); - virtual bool CanReadStream( std::ifstream * stream ) const; + virtual bool CanReadStream( METAIO_STREAM::ifstream * stream ) const; - virtual bool ReadStream( std::ifstream * stream ); + virtual bool ReadStream( METAIO_STREAM::ifstream * stream ); virtual bool Write( const char * headerName = NULL ); - virtual bool WriteStream( std::ofstream * stream ); + virtual bool WriteStream( METAIO_STREAM::ofstream * stream ); protected: diff --git a/src/MetaIO/itktubeMetaRidgeSeed.cxx b/src/MetaIO/itktubeMetaRidgeSeed.cxx index 8f3ace0ea..948e0b5ae 100644 --- a/src/MetaIO/itktubeMetaRidgeSeed.cxx +++ b/src/MetaIO/itktubeMetaRidgeSeed.cxx @@ -427,7 +427,7 @@ CanRead( const char * _headerName ) const } // Now check the file content - std::ifstream inputStream; + METAIO_STREAM::ifstream inputStream; inputStream.open( _headerName, std::ios::in | std::ios::binary ); @@ -453,9 +453,9 @@ Read( const char * _headerName ) FileName( _headerName ); } - std::ifstream * tmpStream = new std::ifstream; + METAIO_STREAM::ifstream * tmpStream = new METAIO_STREAM::ifstream; - tmpStream->open( m_FileName, std::ios::in | + tmpStream->open( m_FileName.c_str(), std::ios::in | std::ios::binary ); if( !tmpStream->rdbuf()->is_open() ) @@ -476,7 +476,7 @@ Read( const char * _headerName ) } bool MetaRidgeSeed:: -CanReadStream( std::ifstream * _stream ) const +CanReadStream( METAIO_STREAM::ifstream * _stream ) const { if( !std::strncmp( MET_ReadForm( * _stream ).c_str(), "RidgeSeed", 9 ) ) { @@ -487,7 +487,7 @@ CanReadStream( std::ifstream * _stream ) const } bool MetaRidgeSeed:: -ReadStream( std::ifstream * _stream ) +ReadStream( METAIO_STREAM::ifstream * _stream ) { if( META_DEBUG ) { @@ -535,9 +535,9 @@ Write( const char * _headName ) MET_SetFileSuffix( m_FileName, ".mrs" ); - std::ofstream * tmpWriteStream = new std::ofstream; + METAIO_STREAM::ofstream * tmpWriteStream = new METAIO_STREAM::ofstream; - tmpWriteStream->open( m_FileName, std::ios::binary | + tmpWriteStream->open( m_FileName.c_str(), std::ios::binary | std::ios::out ); if( !tmpWriteStream->rdbuf()->is_open() ) @@ -558,7 +558,7 @@ Write( const char * _headName ) } bool MetaRidgeSeed:: -WriteStream( std::ofstream * _stream ) +WriteStream( METAIO_STREAM::ofstream * _stream ) { if( m_WriteStream != NULL ) { diff --git a/src/MetaIO/itktubeMetaRidgeSeed.h b/src/MetaIO/itktubeMetaRidgeSeed.h index e93a68546..e698a4799 100644 --- a/src/MetaIO/itktubeMetaRidgeSeed.h +++ b/src/MetaIO/itktubeMetaRidgeSeed.h @@ -24,10 +24,16 @@ limitations under the License. #ifndef __itktubeMetaRidgeSeed_h #define __itktubeMetaRidgeSeed_h + #include "itktubeMetaLDA.h" +#include #include +#ifndef METAIO_STREAM +#define METAIO_STREAM std +#endif + namespace itk { @@ -125,13 +131,13 @@ class MetaRidgeSeed : public MetaLDA virtual bool Read( const char * _headerName = NULL ); - virtual bool CanReadStream( std::ifstream * _stream ) const; + virtual bool CanReadStream( METAIO_STREAM::ifstream * _stream ) const; - virtual bool ReadStream( std::ifstream * _stream ); + virtual bool ReadStream( METAIO_STREAM::ifstream * _stream ); virtual bool Write( const char * _headName = NULL ); - virtual bool WriteStream( std::ofstream * _stream ); + virtual bool WriteStream( METAIO_STREAM::ofstream * _stream ); protected: void M_Destroy( void ); diff --git a/src/MetaIO/itktubeMetaTubeExtractor.cxx b/src/MetaIO/itktubeMetaTubeExtractor.cxx index fe6351ba5..fc0770275 100644 --- a/src/MetaIO/itktubeMetaTubeExtractor.cxx +++ b/src/MetaIO/itktubeMetaTubeExtractor.cxx @@ -481,7 +481,7 @@ CanRead( const char *_headerName ) const } // Now check the file content - std::ifstream inputStream; + METAIO_STREAM::ifstream inputStream; inputStream.open( _headerName, std::ios::in | std::ios::binary ); @@ -508,9 +508,9 @@ Read( const char *_headerName ) FileName( _headerName ); } - std::ifstream * tmpStream = new std::ifstream; + METAIO_STREAM::ifstream * tmpStream = new METAIO_STREAM::ifstream; - tmpStream->open( m_FileName, std::ios::in | + tmpStream->open( m_FileName.c_str(), std::ios::in | std::ios::binary ); if( !tmpStream->rdbuf()->is_open() ) @@ -532,7 +532,7 @@ Read( const char *_headerName ) bool MetaTubeExtractor:: -CanReadStream( std::ifstream * _stream ) const +CanReadStream( METAIO_STREAM::ifstream * _stream ) const { if( !std::strncmp( MET_ReadForm( *_stream ).c_str(), "TubeExtractor", 10 ) ) @@ -544,7 +544,7 @@ CanReadStream( std::ifstream * _stream ) const } bool MetaTubeExtractor:: -ReadStream( std::ifstream * _stream ) +ReadStream( METAIO_STREAM::ifstream * _stream ) { if( META_DEBUG ) { @@ -595,9 +595,9 @@ Write( const char *_headName ) MET_SetFileSuffix( m_FileName, ".mtp" ); - std::ofstream * tmpWriteStream = new std::ofstream; + METAIO_STREAM::ofstream * tmpWriteStream = new METAIO_STREAM::ofstream; - tmpWriteStream->open( m_FileName, std::ios::binary | + tmpWriteStream->open( m_FileName.c_str(), std::ios::binary | std::ios::out ); if( !tmpWriteStream->rdbuf()->is_open() ) @@ -616,7 +616,7 @@ Write( const char *_headName ) } bool MetaTubeExtractor:: -WriteStream( std::ofstream * _stream ) +WriteStream( METAIO_STREAM::ofstream * _stream ) { if( m_WriteStream != NULL ) { diff --git a/src/MetaIO/itktubeMetaTubeExtractor.h b/src/MetaIO/itktubeMetaTubeExtractor.h index ec58b0ce8..85f98dd15 100644 --- a/src/MetaIO/itktubeMetaTubeExtractor.h +++ b/src/MetaIO/itktubeMetaTubeExtractor.h @@ -24,11 +24,16 @@ limitations under the License. #ifndef __itktubeMetaTubeExtractor_h #define __itktubeMetaTubeExtractor_h +#include #include #include #include +#ifndef METAIO_STREAM +#define METAIO_STREAM std +#endif + namespace itk { @@ -127,13 +132,13 @@ class MetaTubeExtractor : public MetaForm virtual bool CanRead( const char * _headerName = NULL ) const; virtual bool Read( const char * _headerName = NULL ); - virtual bool CanReadStream( std::ifstream * _stream ) const; + virtual bool CanReadStream( METAIO_STREAM::ifstream * _stream ) const; - virtual bool ReadStream( std::ifstream * _stream ); + virtual bool ReadStream( METAIO_STREAM::ifstream * _stream ); virtual bool Write( const char *_headName = NULL ); - virtual bool WriteStream( std::ofstream * _stream ); + virtual bool WriteStream( METAIO_STREAM::ofstream * _stream ); protected: diff --git a/src/Registration.cmake b/src/Registration.cmake index 222a78dc8..ea709e081 100644 --- a/src/Registration.cmake +++ b/src/Registration.cmake @@ -26,7 +26,6 @@ set( TubeTK_Registration_H_Files Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h Registration/itkBSplineImageToImageRegistrationMethod.h Registration/itkImageRegionMomentsCalculator.h - Registration/itkImageRegionSplitter.h Registration/itkImageToImageRegistrationHelper.h Registration/itkImageToImageRegistrationMethod.h Registration/itkInitialImageToImageRegistrationMethod.h @@ -60,7 +59,6 @@ set( TubeTK_Registration_HXX_Files Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.hxx Registration/itkBSplineImageToImageRegistrationMethod.hxx Registration/itkImageRegionMomentsCalculator.hxx - Registration/itkImageRegionSplitter.hxx Registration/itkImageToImageRegistrationHelper.hxx Registration/itkImageToImageRegistrationMethod.hxx Registration/itkInitialImageToImageRegistrationMethod.hxx diff --git a/src/Registration/itkImageRegionSplitter.h b/src/Registration/itkImageRegionSplitter.h deleted file mode 100644 index 36dbea740..000000000 --- a/src/Registration/itkImageRegionSplitter.h +++ /dev/null @@ -1,183 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -Licensed under the Apache License, Version 2.0 ( the "License" ); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -=========================================================================*/ - -#ifndef __itkImageRegionSplitter_h -#define __itkImageRegionSplitter_h - -#include "itkImageRegion.h" -#include "itkImageRegionSplitterBase.h" - -namespace itk -{ -/** \class ImageRegionSplitter - * \brief Divide a region into several pieces. - * - * ImageRegionSplitter divides an ImageRegion into smaller regions. - * ImageRegionSplitter is used by the StreamingImageFilter to divide a - * requested output region into a series of smaller requests of the - * pipeline. This object has two basic methods: GetNumberOfSplits() - * and GetSplit(). - * - * GetNumberOfSplits() is used to determine how may subregions a given - * region can be divided. You call GetNumberOfSplits with an argument - * that is the number of subregions you want. If the image region can - * support that number of subregions, that number is returned. - * Otherwise, the maximum number of splits less then or equal to the - * argumen be returned. For example, if a region splitter class only divides - * a region into horizontal slabs, then the maximum number of splits - * will be the number of rows in the region. - * - * GetSplit() returns the ith of N subregions ( as an ImageRegion object ). - * - * This ImageRegionSplitter class divides a region along the outermost - * dimension. If the outermost dimension has size 1 ( i.e. a volume - * with a single slice ), the ImageRegionSplitter will divide the - * region along the next outermost dimension. If that dimension has size 1, - * the process continues with the next outermost dimension. - * - * Other ImageRegionSplitter subclasses could divide an image into - * more uniform shaped regions instead of slabs. - * - * \deprecated The new class ImageRegionSplitterSlowDimension can be - * used as a drop in replacement for functionality as it - * implements the same algorithm. The ImageRegionSplitterBase is now - * the abstract base class for all image splitter. New splitting - * object should be derived from that class. - * - * \sa ImageRegionSplitterSlowDimension - * \sa ImageRegionSplitterBase - * - * \ingroup ITKDeprecated - */ - -template< unsigned int VImageDimension > -class ImageRegionSplitter:public ImageRegionSplitterBase -{ -public: - /** Standard class typedefs. */ - typedef ImageRegionSplitter Self; - typedef ImageRegionSplitterBase Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( ImageRegionSplitter, Object ); - - /** Dimension of the image available at compile time. */ - itkStaticConstMacro( ImageDimension, unsigned int, VImageDimension ); - - /** Dimension of the image available at run time. */ - static unsigned int GetImageDimension() - { - return VImageDimension; - } - - /** Index typedef support. An index is used to access pixel values. */ - typedef Index< VImageDimension > IndexType; - - /** Size typedef support. A size is used to define region bounds. */ - typedef Size< VImageDimension > SizeType; - typedef typename SizeType::SizeValueType SizeValueType; - - /** Region typedef support. */ - typedef ImageRegion< VImageDimension > RegionType; - - /** How many pieces can the specifed region be split? A given region - * cannot always be divided into the requested number of pieces. For - * instance, if the numberOfPieces exceeds the number of pixels along - * a certain dimensions, then some splits will not be possible. This - * method returns a number less than or equal to the requested number - * of pieces. */ - virtual unsigned int GetNumberOfSplits( const RegionType & region, - unsigned int requestedNumber ); - - - /** Get a region definition that represents the ith piece a specified region. - * The "numberOfPieces" must be equal to what - * GetNumberOfSplits() returns. */ - virtual RegionType GetSplit( unsigned int i, unsigned int numberOfPieces, - const RegionType & region ); - -protected: - ImageRegionSplitter() {} - ~ImageRegionSplitter() {} - - virtual unsigned int GetNumberOfSplitsInternal( unsigned int, - const IndexValueType regionIndex[], - const SizeValueType regionSize[], - unsigned int requestedNumber ) const ITK_OVERRIDE - { - // this function adapts the legecy method, defined in this class - // be used by the ImageRegionSplitterBase. - IndexType idx; - idx.SetIndex( regionIndex ); - SizeType sz; - sz.SetSize( regionSize ); - RegionType region = RegionType( idx, sz ); - - Self *nonconst_this = const_cast( this ); - return nonconst_this->GetNumberOfSplits( region, requestedNumber ); - } - - virtual unsigned int GetSplitInternal( unsigned int dim, - unsigned int i, - unsigned int numberOfPieces, - IndexValueType regionIndex[], - SizeValueType regionSize[] ) const ITK_OVERRIDE - { - // this function adapts the legecy method, defined in this class - // be used by the ImageRegionSplitterBase. - IndexType idx; - idx.SetIndex( regionIndex ); - SizeType sz; - sz.SetSize( regionSize ); - RegionType region = RegionType( idx, sz ); - - Self *nonconst_this = const_cast( this ); - region = nonconst_this->GetSplit( i, numberOfPieces, region ); - - for( unsigned int d = 0; d < dim; ++d ) - { - regionIndex[d] = region.GetIndex( d ); - regionSize[d] = region.GetSize( d ); - } - return numberOfPieces; - } - - virtual void PrintSelf( std::ostream & os, Indent indent ) const override; - -private: - //purposely not implemented - ImageRegionSplitter( const ImageRegionSplitter & ); - //purposely not implemented - void operator=( const ImageRegionSplitter & ); -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkImageRegionSplitter.hxx" -#endif - -#endif diff --git a/src/Registration/itkImageRegionSplitter.hxx b/src/Registration/itkImageRegionSplitter.hxx deleted file mode 100644 index f46e9302a..000000000 --- a/src/Registration/itkImageRegionSplitter.hxx +++ /dev/null @@ -1,136 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -Licensed under the Apache License, Version 2.0 ( the "License" ); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -=========================================================================*/ - -#ifndef __itkImageRegionSplitter_hxx -#define __itkImageRegionSplitter_hxx - -#include - -namespace itk -{ -/** - * - */ -template< unsigned int VImageDimension > -unsigned int -ImageRegionSplitter< VImageDimension > -::GetNumberOfSplits( const RegionType & region, unsigned int requestedNumber ) -{ - const SizeType & regionSize = region.GetSize(); - - // split on the outermost dimension available - int splitAxis = VImageDimension - 1; - while( regionSize[splitAxis] == 1 ) - { - --splitAxis; - if( splitAxis < 0 ) - { // cannot split - itkDebugMacro( " Cannot Split" ); - return 1; - } - } - - // determine the actual number of pieces that will be generated - const SizeValueType range = regionSize[splitAxis]; - const unsigned int valuesPerPiece = - Math::Ceil< unsigned int >( range / ( double )requestedNumber ); - const unsigned int maxPieceUsed = - Math::Ceil< unsigned int >( range / ( double )valuesPerPiece ) - 1; - - return maxPieceUsed + 1; -} - -/** - * - */ -template< unsigned int VImageDimension > -ImageRegion< VImageDimension > -ImageRegionSplitter< VImageDimension > -::GetSplit( unsigned int i, unsigned int numberOfPieces, - const RegionType & region ) -{ - int splitAxis; - RegionType splitRegion; - IndexType splitIndex; - SizeType splitSize, regionSize; - - // Initialize the splitRegion to the requested region - splitRegion = region; - splitIndex = splitRegion.GetIndex(); - splitSize = splitRegion.GetSize(); - - regionSize = region.GetSize(); - - // split on the outermost dimension available - splitAxis = VImageDimension - 1; - while( regionSize[splitAxis] == 1 ) - { - --splitAxis; - if( splitAxis < 0 ) - { // cannot split - itkDebugMacro( " Cannot Split" ); - return splitRegion; - } - } - - // determine the actual number of pieces that will be generated - SizeValueType range = regionSize[splitAxis]; - int valuesPerPiece = - Math::Ceil< int >( range / ( double )numberOfPieces ); - int maxPieceUsed = - Math::Ceil< int >( range / ( double )valuesPerPiece ) - 1; - - // Split the region - if( ( int )i < maxPieceUsed ) - { - splitIndex[splitAxis] += i * valuesPerPiece; - splitSize[splitAxis] = valuesPerPiece; - } - if( ( int )i == maxPieceUsed ) - { - splitIndex[splitAxis] += i * valuesPerPiece; - // last piece needs to process the "rest" dimension being split - splitSize[splitAxis] = splitSize[splitAxis] - i * valuesPerPiece; - } - - // set the split region ivars - splitRegion.SetIndex( splitIndex ); - splitRegion.SetSize( splitSize ); - - itkDebugMacro( " Split Piece: " << splitRegion ); - - return splitRegion; -} - -/** - * - */ -template< unsigned int VImageDimension > -void -ImageRegionSplitter< VImageDimension > -::PrintSelf( std::ostream & os, Indent indent ) const -{ - Superclass::PrintSelf( os, indent ); -} -} // end namespace itk - -#endif diff --git a/src/Registration/itkScaleSkewAngle2DTransform.h b/src/Registration/itkScaleSkewAngle2DTransform.h index 117daf3e5..668878153 100644 --- a/src/Registration/itkScaleSkewAngle2DTransform.h +++ b/src/Registration/itkScaleSkewAngle2DTransform.h @@ -106,9 +106,9 @@ class ITK_TEMPLATE_EXPORT ScaleSkewAngle2DTransform : * Orthogonality testing is bypassed in this case. * * \sa MatrixOffsetTransformBase::SetMatrix() */ - virtual void SetMatrix(const MatrixType & matrix) ITK_OVERRIDE; + virtual void SetMatrix(const MatrixType & matrix) override; virtual void SetMatrix(const MatrixType & matrix, - const TParametersValueType tolerance) ITK_OVERRIDE; + const TParametersValueType tolerance) override; /** Set the transformation from a container of parameters * This is typically used by optimizers. @@ -118,9 +118,9 @@ class ITK_TEMPLATE_EXPORT ScaleSkewAngle2DTransform : * 3-4 Scale * 5-6 Skew ** */ - virtual void SetParameters(const ParametersType & parameters) ITK_OVERRIDE; + virtual void SetParameters(const ParametersType & parameters) override; - virtual const ParametersType & GetParameters(void) const ITK_OVERRIDE; + virtual const ParametersType & GetParameters(void) const override; itkGetMacro( UseSingleScale, bool ); itkSetMacro( UseSingleScale, bool ); @@ -133,13 +133,13 @@ class ITK_TEMPLATE_EXPORT ScaleSkewAngle2DTransform : itkGetConstReferenceMacro(Skew, SkewVectorType); - void SetIdentity() ITK_OVERRIDE; + void SetIdentity() override; /** This method computes the Jacobian matrix of the transformation. * given point or vector, returning the transformed point or * vector. The rank of the Jacobian will also indicate if the * transform is invertible at this point. */ - virtual void ComputeJacobianWithRespectToParameters( const InputPointType & p, JacobianType & jacobian) const ITK_OVERRIDE; + virtual void ComputeJacobianWithRespectToParameters( const InputPointType & p, JacobianType & jacobian) const override; protected: ScaleSkewAngle2DTransform(); @@ -164,9 +164,9 @@ class ITK_TEMPLATE_EXPORT ScaleSkewAngle2DTransform : } /** Compute the components of the rotation matrix in the superclass. */ - void ComputeMatrix(void) ITK_OVERRIDE; + void ComputeMatrix(void) override; - void ComputeMatrixParameters(void) ITK_OVERRIDE; + void ComputeMatrixParameters(void) override; private: ITK_DISALLOW_COPY_AND_MOVE(ScaleSkewAngle2DTransform); diff --git a/src/Registration/itkSimilarity2DTransform.h b/src/Registration/itkSimilarity2DTransform.h index 90ecb92b1..47f87438d 100644 --- a/src/Registration/itkSimilarity2DTransform.h +++ b/src/Registration/itkSimilarity2DTransform.h @@ -141,7 +141,7 @@ class ITK_TEMPLATE_EXPORT Similarity2DTransform : * * \sa Transform::SetParameters() * \sa Transform::SetFixedParameters() */ - virtual void SetParameters(const ParametersType & parameters) ITK_OVERRIDE; + virtual void SetParameters(const ParametersType & parameters) override; /** Get the parameters that uniquely define the transform * This is typically used by optimizers. @@ -152,15 +152,15 @@ class ITK_TEMPLATE_EXPORT Similarity2DTransform : * * \sa Transform::GetParameters() * \sa Transform::GetFixedParameters() */ - virtual const ParametersType & GetParameters() const ITK_OVERRIDE; + virtual const ParametersType & GetParameters() const override; /** This method computes the Jacobian matrix of the transformation * at a given input point. */ - virtual void ComputeJacobianWithRespectToParameters( const InputPointType & p, JacobianType & jacobian) const ITK_OVERRIDE; + virtual void ComputeJacobianWithRespectToParameters( const InputPointType & p, JacobianType & jacobian) const override; /** Set the transformation to an identity. */ - virtual void SetIdentity() ITK_OVERRIDE; + virtual void SetIdentity() override; /** * This method creates and returns a new Similarity2DTransform object @@ -172,7 +172,7 @@ class ITK_TEMPLATE_EXPORT Similarity2DTransform : bool GetInverse(Self *inverse) const; /** Return an inverse of this transform. */ - virtual InverseTransformBasePointer GetInverseTransform() const ITK_OVERRIDE; + virtual InverseTransformBasePointer GetInverseTransform() const override; /** * This method creates and returns a new Similarity2DTransform object @@ -193,7 +193,7 @@ class ITK_TEMPLATE_EXPORT Similarity2DTransform : * \sa MatrixOffsetTransformBase::SetMatrix() * */ - virtual void SetMatrix(const MatrixType & matrix) ITK_OVERRIDE; + virtual void SetMatrix(const MatrixType & matrix) override; /** * Set the rotation Matrix of a Similarity 2D Transform @@ -208,7 +208,7 @@ class ITK_TEMPLATE_EXPORT Similarity2DTransform : * \sa MatrixOffsetTransformBase::SetMatrix() * */ - virtual void SetMatrix(const MatrixType & matrix, const TParametersValueType tolerance) ITK_OVERRIDE; + virtual void SetMatrix(const MatrixType & matrix, const TParametersValueType tolerance) override; protected: Similarity2DTransform(unsigned int outputSpaceDimension, unsigned int parametersDimension); @@ -224,13 +224,13 @@ class ITK_TEMPLATE_EXPORT Similarity2DTransform : /** Compute matrix from angle and scale. This is used in Set methods * to update the underlying matrix whenever a transform parameter * is changed. */ - virtual void ComputeMatrix(void) ITK_OVERRIDE; + virtual void ComputeMatrix(void) override; /** Compute the angle and scale from the matrix. This is used to compute * transform parameters from a given matrix. This is used in * MatrixOffsetTransformBase::Compose() and * MatrixOffsetTransformBase::GetInverse(). */ - virtual void ComputeMatrixParameters(void) ITK_OVERRIDE; + virtual void ComputeMatrixParameters(void) override; /** Set the scale without updating underlying variables. */ void SetVarScale(ScaleType scale) diff --git a/src/Registration/itkSimilarity2DTransform.hxx b/src/Registration/itkSimilarity2DTransform.hxx index 938a4f6c3..5f682dab3 100644 --- a/src/Registration/itkSimilarity2DTransform.hxx +++ b/src/Registration/itkSimilarity2DTransform.hxx @@ -267,7 +267,7 @@ Similarity2DTransform { return inv.GetPointer(); } - return ITK_NULLPTR; + return nullptr; } diff --git a/src/Segmentation/itktubeRadiusExtractor2.hxx b/src/Segmentation/itktubeRadiusExtractor2.hxx index 0efe02948..55418c0da 100644 --- a/src/Segmentation/itktubeRadiusExtractor2.hxx +++ b/src/Segmentation/itktubeRadiusExtractor2.hxx @@ -288,11 +288,14 @@ RadiusExtractor2 typename std::vector< TubePointType >::iterator pntIter; pntIter = m_KernelTube->GetPoints().begin(); + IndexType kernelPointI; + if ( !m_InputImage->TransformPhysicalPointToIndex( + pntIter->GetPositionInObjectSpace(), kernelPointI ) ) + { + ::tube::WarningMessage( "Kernel point is outside of image bounds." ); + } for( unsigned int i = 0; i < ImageDimension; ++i ) { - IndexType kernelPointI; - m_InputImage->TransformPhysicalPointToIndex( - m_KernelTube->GetPoints()[0].GetPositionInObjectSpace(), kernelPointI ); minXI[i] = static_cast< int >( kernelPointI[i] - bufferI[i] ); maxXI[i] = static_cast< int >( kernelPointI[i] + bufferI[i] ); } @@ -301,8 +304,11 @@ RadiusExtractor2 while( pntIter != m_KernelTube->GetPoints().end() ) { IndexType kernelPointI; - m_InputImage->TransformPhysicalPointToIndex( - pntIter->GetPositionInObjectSpace(), kernelPointI ); + if( !m_InputImage->TransformPhysicalPointToIndex( + pntIter->GetPositionInObjectSpace(), kernelPointI ) ) + { + ::tube::WarningMessage( "Kernel point is outside of image bounds." ); + } for( unsigned int i = 0; i < ImageDimension; ++i ) { tempI = static_cast< int >( kernelPointI[i] - bufferI[i] ); diff --git a/test/Segmentation/itktubeTubeExtractorTest.cxx b/test/Segmentation/itktubeTubeExtractorTest.cxx index 2e6e3cdbb..a45605a95 100644 --- a/test/Segmentation/itktubeTubeExtractorTest.cxx +++ b/test/Segmentation/itktubeTubeExtractorTest.cxx @@ -184,15 +184,23 @@ int itktubeTubeExtractorTest( int argc, char * argv[] ) != TubeOpType::RidgeExtractorType::SUCCESS ) { TubeOpType::ContinuousIndexType x1; - im->TransformPhysicalPointToContinuousIndex( pntX1, x1 ); + bool success = im->TransformPhysicalPointToContinuousIndex( pntX1, x1 ); std::cout << "Local tube test failed. No tube found." << std::endl; std::cout << " Source = " << pntX << " (" << x0 << ")" << std::endl; - std::cout << " Result = " << pntX1 << " (" << x1 << ")" << std::endl; + std::cout << " Result = " << pntX1 << " (" << x1 << ": valid = " << success << ")" << std::endl; ++failures; continue; } + TubeOpType::ContinuousIndexType x1; - im->TransformPhysicalPointToContinuousIndex( pntX1, x1 ); + bool success = im->TransformPhysicalPointToContinuousIndex( pntX1, x1 ); + if (!success) + { + std::cout << "Local tube test failed. Result outside of image." << std::endl; + std::cout << " Result = " << pntX1 << " Index = " << x1 << std::endl; + ++failures; + continue; + } double diff = 0; for( unsigned int i=0; i