Commit 2c542852 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

BUG: png images fail to read due to library.

ENH: ecapsulate malloc-ed nifti image in a shared_ptr. SuperElastix/SuperElastix#39
parent 16a26651
......@@ -37,7 +37,7 @@ public:
using Type = NiftyregReferenceImageInterface< TPixel >;
using Pointer = std::shared_ptr< Type >;
virtual nifti_image * GetReferenceNiftiImage() = 0;
virtual std::shared_ptr<nifti_image> GetReferenceNiftiImage() = 0;
};
template< class TPixel >
......@@ -47,7 +47,7 @@ public:
using Type = NiftyregFloatingImageInterface< TPixel >;
using Pointer = std::shared_ptr< Type >;
virtual nifti_image * GetFloatingNiftiImage() = 0;
virtual std::shared_ptr<nifti_image> GetFloatingNiftiImage() = 0;
};
template< class TPixel >
......
......@@ -51,9 +51,9 @@ public:
NiftyregReadImageComponent( const std::string & name );
virtual ~NiftyregReadImageComponent();
virtual nifti_image * GetFloatingNiftiImage() override;
virtual std::shared_ptr<nifti_image> GetFloatingNiftiImage() override;
virtual nifti_image * GetReferenceNiftiImage() override;
virtual std::shared_ptr<nifti_image> GetReferenceNiftiImage() override;
virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
......
......@@ -35,18 +35,20 @@ NiftyregReadImageComponent< TPixel >::~NiftyregReadImageComponent()
template< class TPixel >
nifti_image *
std::shared_ptr<nifti_image>
NiftyregReadImageComponent< TPixel >::GetReferenceNiftiImage()
{
return reg_io_ReadImageFile( this->m_ImageFileName.c_str() );
std::shared_ptr<nifti_image> ptr(reg_io_ReadImageFile(this->m_ImageFileName.c_str()), nifti_image_free);
return ptr;
}
template< class TPixel >
nifti_image *
std::shared_ptr<nifti_image>
NiftyregReadImageComponent< TPixel >::GetFloatingNiftiImage()
{
return reg_io_ReadImageFile( this->m_ImageFileName.c_str() );
std::shared_ptr<nifti_image> ptr(reg_io_ReadImageFile(this->m_ImageFileName.c_str()), nifti_image_free);
return ptr;
}
......
......@@ -43,7 +43,7 @@ Niftyregf3dComponent< TPixel >
{
auto referenceimage = component->GetReferenceNiftiImage();
// connect the itk pipeline
this->m_reg_f3d->SetReferenceImage( referenceimage );
this->m_reg_f3d->SetReferenceImage( referenceimage.get() );
return 0;
}
......@@ -55,7 +55,7 @@ Niftyregf3dComponent< TPixel >
{
auto floatingimage = component->GetFloatingNiftiImage();
// connect the itk pipeline
this->m_reg_f3d->SetFloatingImage( floatingimage );
this->m_reg_f3d->SetFloatingImage( floatingimage.get() );
return 0;
}
......@@ -68,6 +68,7 @@ Niftyregf3dComponent< TPixel >
this->m_reg_f3d->UseSSD( 0, true );
this->m_reg_f3d->UseCubicSplineInterpolation();
this->m_reg_f3d->Run();
nifti_image** outputWarpedImage = m_reg_f3d->GetWarpedImage();
}
......
......@@ -72,8 +72,8 @@ TEST_F( NiftyregComponentTest, Register2d )
{
/** make example blueprint configuration */
BlueprintPointer blueprint = BlueprintPointer( new Blueprint() );
blueprint->SetComponent( "FixedImage", { { "NameOfClass", { "NiftyregReadImageComponent" } }, { "FileName", { this->dataManager->GetInputFile( "BrainProtonDensitySliceBorder20.png" ) } } } );
blueprint->SetComponent( "MovingImage", { { "NameOfClass", { "NiftyregReadImageComponent" } }, { "FileName", { this->dataManager->GetInputFile( "BrainProtonDensitySliceR10X13Y17.png" ) } } } );
blueprint->SetComponent( "FixedImage", { { "NameOfClass", { "NiftyregReadImageComponent" } }, { "FileName", { this->dataManager->GetInputFile( "BrainProtonDensitySliceBorder20.nii" ) } } } );
blueprint->SetComponent( "MovingImage", { { "NameOfClass", { "NiftyregReadImageComponent" } }, { "FileName", { this->dataManager->GetInputFile( "BrainProtonDensitySliceR10X13Y17.nii" ) } } } );
blueprint->SetComponent( "RegistrationMethod", { { "NameOfClass", { "Niftyregf3dComponent" } } } );
blueprint->SetComponent( "Controller", { { "NameOfClass", { "RegistrationControllerComponent" } } } );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment