Skip to content

Commit

Permalink
Merge pull request #590 from ANTsX/alloc_init
Browse files Browse the repository at this point in the history
ENH: Bump ITK and ANTs, initialize all memory allocated for images
  • Loading branch information
cookpa authored Mar 22, 2024
2 parents cd1e956 + de4b63b commit cb70f4a
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ py::capsule antsImageClone( py::capsule antsImage )
out_image->SetOrigin( in_image->GetOrigin() ) ;
out_image->SetDirection( in_image->GetDirection() );
//out_image->CopyInformation( in_image );
out_image->Allocate() ;
out_image->AllocateInitialized() ;

itk::ImageRegionConstIterator< InImageType > in_iterator( in_image , in_image->GetLargestPossibleRegion() ) ;
itk::ImageRegionIterator< OutImageType > out_iterator( out_image , out_image->GetLargestPossibleRegion() ) ;
Expand Down
6 changes: 3 additions & 3 deletions ants/lib/ANTsVersionConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*=========================================================================*/

#define ANTS_VERSION_MAJOR 2
#define ANTS_VERSION_MINOR 3
#define ANTS_VERSION_PATCH 5
#define ANTS_VERSION_MINOR 5
#define ANTS_VERSION_PATCH 1
#define ANTS_VERSION_TWEAK
#define ANTS_VERSION "v2.3.5.post95-g6f07ac5"
#define ANTS_VERSION "v2.5.1.post95-g2236a75"
2 changes: 1 addition & 1 deletion ants/lib/LOCAL_antsImageClone.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ py::capsule antsImageClone( py::capsule antsImage )
out_image->SetOrigin( in_image->GetOrigin() ) ;
out_image->SetDirection( in_image->GetDirection() );
//out_image->CopyInformation( in_image );
out_image->Allocate() ;
out_image->AllocateInitialized();

itk::ImageRegionConstIterator< InImageType > in_iterator( in_image , in_image->GetLargestPossibleRegion() ) ;
itk::ImageRegionIterator< OutImageType > out_iterator( out_image , out_image->GetLargestPossibleRegion() ) ;
Expand Down
3 changes: 1 addition & 2 deletions ants/lib/LOCAL_antsImageToImageMetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ ANTsImageToImageMetric< MetricBaseType > create_ants_metric(std::string pixeltyp
itkField->SetSpacing( moving->GetSpacing() );
itkField->SetOrigin( moving->GetOrigin() );
itkField->SetDirection( moving->GetDirection() );
itkField->Allocate();
//itkField->FillBuffer(0);
itkField->AllocateInitialized();

typename TransformType::Pointer idTransform = TransformType::New();
idTransform->SetDisplacementField( itkField );
Expand Down
6 changes: 3 additions & 3 deletions ants/lib/LOCAL_antsTransform.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ py::capsule antsTransformFromDisplacementField( py::capsule field )
itkField->SetSpacing( antsrField->GetSpacing() );
itkField->SetOrigin( antsrField->GetOrigin() );
itkField->SetDirection( antsrField->GetDirection() );
itkField->Allocate();
itkField->AllocateInitialized();

typedef itk::ImageRegionIteratorWithIndex<DisplacementFieldType> IteratorType;
IteratorType it( itkField, itkField->GetLargestPossibleRegion() );
Expand Down Expand Up @@ -143,7 +143,7 @@ py::capsule antsTransformToDisplacementField( py::capsule xfrm, py::capsule ref
antsrField->CopyInformation( domainImage );
antsrField->SetRegions( domainImage->GetLargestPossibleRegion() );
antsrField->SetNumberOfComponentsPerPixel( Dimension );
antsrField->Allocate();
antsrField->AllocateInitialized();

typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
IteratorType it( domainImage, domainImage->GetLargestPossibleRegion() );
Expand Down Expand Up @@ -213,7 +213,7 @@ PYBIND11_MODULE(antsTransform, m) {
m.def("transformImageD2UC4", &transformImage<itk::Transform<double,2, 2>, itk::Image<unsigned char, 2>>);
m.def("transformImageD3UC4", &transformImage<itk::Transform<double,3, 3>, itk::Image<unsigned char, 3>>);
m.def("transformImageD4UC4", &transformImage<itk::Transform<double,4, 4>, itk::Image<unsigned char, 4>>);

m.def("transformImageF2UI2", &transformImage<itk::Transform<float, 2, 2>, itk::Image<unsigned int, 2>>);
m.def("transformImageF3UI3", &transformImage<itk::Transform<float, 3, 3>, itk::Image<unsigned int, 3>>);
m.def("transformImageF4UI4", &transformImage<itk::Transform<float, 4, 4>, itk::Image<unsigned int, 4>>);
Expand Down
6 changes: 3 additions & 3 deletions ants/lib/LOCAL_composeDisplacementFields.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ py::capsule composeDisplacementFields( py::capsule & antsDisplacementField,
inputITKDisplacementField->SetRegions( fieldSize );
inputITKDisplacementField->SetSpacing( fieldSpacing );
inputITKDisplacementField->SetDirection( fieldDirection );
inputITKDisplacementField->Allocate();
inputITKDisplacementField->AllocateInitialized();

ITKFieldPointerType inputITKWarpingField = ITKFieldType::New();
inputITKWarpingField->SetOrigin( fieldOrigin );
inputITKWarpingField->SetRegions( fieldSize );
inputITKWarpingField->SetSpacing( fieldSpacing );
inputITKWarpingField->SetDirection( fieldDirection );
inputITKWarpingField->Allocate();
inputITKWarpingField->AllocateInitialized();

IteratorType ItF( inputITKDisplacementField, inputITKDisplacementField->GetRequestedRegion() );
IteratorType ItE( inputITKWarpingField, inputITKWarpingField->GetRequestedRegion() );
Expand Down Expand Up @@ -100,7 +100,7 @@ py::capsule composeDisplacementFields( py::capsule & antsDisplacementField,
antsField->CopyInformation( composer->GetOutput() );
antsField->SetRegions( composer->GetOutput()->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

ConstIteratorType ItI( composer->GetOutput(),
composer->GetOutput()->GetRequestedRegion() );
Expand Down
4 changes: 2 additions & 2 deletions ants/lib/LOCAL_fitBsplineDisplacementField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ py::capsule fitBsplineVectorImageHelper(
inputITKField->SetRegions( fieldSize );
inputITKField->SetSpacing( fieldSpacing );
inputITKField->SetDirection( fieldDirection );
inputITKField->Allocate();
inputITKField->AllocateInitialized();

IteratorType It( inputITKField, inputITKField->GetRequestedRegion() );
for( It.GoToBegin(); !It.IsAtEnd(); ++It )
Expand Down Expand Up @@ -190,7 +190,7 @@ py::capsule fitBsplineVectorImageHelper(
antsField->CopyInformation( bsplineFilter->GetOutput() );
antsField->SetRegions( bsplineFilter->GetOutput()->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

IteratorType ItB( bsplineFilter->GetOutput(),
bsplineFilter->GetOutput()->GetRequestedRegion() );
Expand Down
12 changes: 4 additions & 8 deletions ants/lib/LOCAL_fitBsplineDisplacementFieldToScatteredData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,21 @@ py::capsule fitBsplineVectorImageToScatteredDataHelper(
weightImage->SetSpacing( bsplineFilter->GetBSplineDomainSpacing() );
weightImage->SetDirection( bsplineFilter->GetBSplineDomainDirection() );
weightImage->SetRegions( bsplineFilter->GetBSplineDomainSize() );
weightImage->Allocate();
weightImage->FillBuffer( 0.0 );
weightImage->AllocateInitialized();

WeightImagePointerType countImage = WeightImageType::New();
countImage->SetOrigin( bsplineFilter->GetBSplineDomainOrigin() );
countImage->SetSpacing( bsplineFilter->GetBSplineDomainSpacing() );
countImage->SetDirection( bsplineFilter->GetBSplineDomainDirection() );
countImage->SetRegions( bsplineFilter->GetBSplineDomainSize() );
countImage->Allocate();
countImage->FillBuffer( 0.0 );
countImage->AllocateInitialized();

VectorType zeroVector( 0.0 );
ITKFieldPointerType rasterizedField = ITKFieldType::New();
rasterizedField->SetOrigin( bsplineFilter->GetBSplineDomainOrigin() );
rasterizedField->SetSpacing( bsplineFilter->GetBSplineDomainSpacing() );
rasterizedField->SetDirection( bsplineFilter->GetBSplineDomainDirection() );
rasterizedField->SetRegions( bsplineFilter->GetBSplineDomainSize() );
rasterizedField->Allocate();
rasterizedField->FillBuffer( zeroVector );
rasterizedField->AllocateInitialized();

for( unsigned int n = 0; n < numberOfPoints; n++ )
{
Expand Down Expand Up @@ -214,7 +210,7 @@ py::capsule fitBsplineVectorImageToScatteredDataHelper(
antsField->CopyInformation( bsplineFilter->GetOutput() );
antsField->SetRegions( bsplineFilter->GetOutput()->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

IteratorType It( bsplineFilter->GetOutput(),
bsplineFilter->GetOutput()->GetRequestedRegion() );
Expand Down
2 changes: 1 addition & 1 deletion ants/lib/LOCAL_fitBsplineObjectToScatteredData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ py::capsule fitBsplineVectorImageHelper(
antsField->SetSpacing( spacing );
antsField->SetVectorLength( DataDimension );
antsField->SetDirection( direction );
antsField->Allocate();
antsField->AllocateInitialized();

IteratorType It( bsplineFilter->GetOutput(),
bsplineFilter->GetOutput()->GetRequestedRegion() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ py::capsule fitThinPlateSplineVectorImageToScatteredDataHelper(
field->SetOrigin( fieldOrigin );
field->SetSpacing( fieldSpacing );
field->SetDirection( fieldDirection );
field->Allocate();
field->AllocateInitialized();
}

auto sourceLandmarks = PointSetType::New();
Expand Down Expand Up @@ -119,7 +119,7 @@ py::capsule fitThinPlateSplineVectorImageToScatteredDataHelper(
antsField->CopyInformation( field );
antsField->SetRegions( field->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

typename TransformType::InputPointType source;
typename TransformType::OutputPointType target;
Expand Down
4 changes: 2 additions & 2 deletions ants/lib/LOCAL_integrateVelocityField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ py::capsule integrateVelocityField( py::capsule & antsVelocityField,
ITKVelocityFieldPointerType inputITKVelocityField = ITKVelocityFieldType::New();
inputITKVelocityField->CopyInformation( inputVelocityField );
inputITKVelocityField->SetRegions( inputVelocityField->GetRequestedRegion() );
inputITKVelocityField->Allocate();
inputITKVelocityField->AllocateInitialized();

IteratorType It( inputITKVelocityField,
inputITKVelocityField->GetRequestedRegion() );
Expand Down Expand Up @@ -79,7 +79,7 @@ py::capsule integrateVelocityField( py::capsule & antsVelocityField,
antsField->CopyInformation( integrator->GetOutput() );
antsField->SetRegions( integrator->GetOutput()->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

ConstIteratorType ItI( integrator->GetOutput(),
integrator->GetOutput()->GetRequestedRegion() );
Expand Down
6 changes: 3 additions & 3 deletions ants/lib/LOCAL_invertDisplacementField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ py::capsule invertDisplacementField( py::capsule & antsDisplacementField,
inputITKDisplacementField->SetRegions( fieldSize );
inputITKDisplacementField->SetSpacing( fieldSpacing );
inputITKDisplacementField->SetDirection( fieldDirection );
inputITKDisplacementField->Allocate();
inputITKDisplacementField->AllocateInitialized();

ITKFieldPointerType inputITKInverseFieldInitialEstimate = ITKFieldType::New();
inputITKInverseFieldInitialEstimate->SetOrigin( fieldOrigin );
inputITKInverseFieldInitialEstimate->SetRegions( fieldSize );
inputITKInverseFieldInitialEstimate->SetSpacing( fieldSpacing );
inputITKInverseFieldInitialEstimate->SetDirection( fieldDirection );
inputITKInverseFieldInitialEstimate->Allocate();
inputITKInverseFieldInitialEstimate->AllocateInitialized();

IteratorType ItF( inputITKDisplacementField, inputITKDisplacementField->GetRequestedRegion() );
IteratorType ItE( inputITKInverseFieldInitialEstimate, inputITKInverseFieldInitialEstimate->GetRequestedRegion() );
Expand Down Expand Up @@ -108,7 +108,7 @@ py::capsule invertDisplacementField( py::capsule & antsDisplacementField,
antsField->CopyInformation( inverter->GetOutput() );
antsField->SetRegions( inverter->GetOutput()->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

ConstIteratorType ItI( inverter->GetOutput(),
inverter->GetOutput()->GetRequestedRegion() );
Expand Down
8 changes: 4 additions & 4 deletions ants/lib/LOCAL_mergeChannels.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ py::capsule mergeChannels( std::vector<void *> imageList )
vectorImage->SetOrigin( images[0]->GetOrigin() );
vectorImage->SetDirection( images[0]->GetDirection() );
vectorImage->SetNumberOfComponentsPerPixel( nImages );
vectorImage->Allocate();
vectorImage->AllocateInitialized();

// Fill image data
itk::ImageRegionIteratorWithIndex<VectorImageType> it( vectorImage,
Expand Down Expand Up @@ -75,7 +75,7 @@ py::capsule mergeChannels2( std::vector<py::capsule> imageList )
vectorImage->SetOrigin( images[0]->GetOrigin() );
vectorImage->SetDirection( images[0]->GetDirection() );
vectorImage->SetNumberOfComponentsPerPixel( nImages );
vectorImage->Allocate();
vectorImage->AllocateInitialized();

// Fill image data
itk::ImageRegionIteratorWithIndex<VectorImageType> it( vectorImage,
Expand Down Expand Up @@ -116,7 +116,7 @@ py::capsule mergeChannels3( std::vector<py::capsule> imageList )
vectorImage->SetOrigin( images[0]->GetOrigin() );
vectorImage->SetDirection( images[0]->GetDirection() );
//vectorImage->SetNumberOfComponentsPerPixel( nImages );
vectorImage->Allocate();
vectorImage->AllocateInitialized();

// Fill image data
itk::ImageRegionIteratorWithIndex<VectorImageType> it( vectorImage,
Expand Down Expand Up @@ -156,7 +156,7 @@ std::vector<py::capsule > splitChannels( py::capsule & antsimage )
image->SetSpacing( input->GetSpacing() );
image->SetOrigin( input->GetOrigin() );
image->SetDirection( input->GetDirection() );
image->Allocate();
image->AllocateInitialized();
images.push_back( image );
}

Expand Down
8 changes: 4 additions & 4 deletions ants/lib/LOCAL_simulateDisplacementField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ py::capsule simulateBsplineDisplacementField(py::capsule & antsDomainImage,
antsField->CopyInformation( domainImage );
antsField->SetRegions( domainImage->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

IteratorType It( bsplineSimulator->GetOutput(),
IteratorType It( bsplineSimulator->GetOutput(),
bsplineSimulator->GetOutput()->GetRequestedRegion() );
for( It.GoToBegin(); !It.IsAtEnd(); ++It )
{
Expand Down Expand Up @@ -116,9 +116,9 @@ py::capsule simulateExponentialDisplacementField(py::capsule & antsDomainImage,
antsField->CopyInformation( domainImage );
antsField->SetRegions( domainImage->GetRequestedRegion() );
antsField->SetVectorLength( Dimension );
antsField->Allocate();
antsField->AllocateInitialized();

IteratorType It( exponentialSimulator->GetOutput(),
IteratorType It( exponentialSimulator->GetOutput(),
exponentialSimulator->GetOutput()->GetRequestedRegion() );
for( It.GoToBegin(); !It.IsAtEnd(); ++It )
{
Expand Down
2 changes: 1 addition & 1 deletion ants/lib/ReadWriteData.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ ConvertTimeSeriesImageToMultiChannelImage( TTimeSeriesImageType *timeSeriesImage
multiChannelImage->SetOrigin( origin );
multiChannelImage->SetDirection( direction );
multiChannelImage->SetVectorLength( timeSeriesSize[ImageDimension] );
multiChannelImage->Allocate();
multiChannelImage->AllocateInitialized();

itk::ImageRegionIteratorWithIndex<MultiChannelImageType> It(
multiChannelImage, multiChannelImage->GetRequestedRegion() );
Expand Down
2 changes: 1 addition & 1 deletion scripts/configure_ANTsPy.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ COPY data\* %USERPROFILE%\.antspy

:: clone ANTs and move all files into library directory
SET antsgit=https://github.com/ANTsX/ANTs.git
SET antstag=6c29d9d1d62f158ca324d5fc8786fffc469998e7
SET antstag=2236a7589c73bbaf88c8bf34a821ba54e0e545d8
echo "ANTS;%antstag%" REM UNKNOWN: {"type":"Redirect","op":{"text":">>","type":"dgreat"},"file":{"text":"./data/softwareVersions.csv","type":"Word"}}
cd ants\lib
echo "123"
Expand Down
2 changes: 1 addition & 1 deletion scripts/configure_ANTsPy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cp data/* ~/.antspy/
# clone ANTs and move all files into library directory

antsgit=https://github.com/ANTsX/ANTs.git
antstag=6c29d9d1d62f158ca324d5fc8786fffc469998e7 # 3-15-24
antstag=2236a7589c73bbaf88c8bf34a821ba54e0e545d8 # 3-20-2024
echo "ANTS;${antstag}" >> ./data/softwareVersions.csv

cd ants/lib # go to lib dir
Expand Down
2 changes: 1 addition & 1 deletion scripts/configure_ITK.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SET CMAKE_BUILD_TYPE=Release

SET itkgit=https://github.com/InsightSoftwareConsortium/ITK.git
SET itktag=be79ceb0a9343c02dba310f5faee371941f6fa40
SET itktag=4535548a8539757c5fe9d81f8de5d804cd0a384f

:: if there is a directory but no git, remove it
if exist itksource\ (
Expand Down
2 changes: 1 addition & 1 deletion scripts/configure_ITK.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi

#cd ./src
itkgit=https://github.com/InsightSoftwareConsortium/ITK.git
itktag=be79ceb0a9343c02dba310f5faee371941f6fa40 # 3-15-24
itktag=4535548a8539757c5fe9d81f8de5d804cd0a384f # 2024-03-12
# if there is a directory but no git, remove it
if [[ -d itksource ]]; then
if [[ ! -d itksource/.git ]]; then
Expand Down

0 comments on commit cb70f4a

Please sign in to comment.