Skip to content

Commit

Permalink
Merge branch 'nifti-private-for-release' into release
Browse files Browse the repository at this point in the history
Change-Id: I3792383eac33d9413dd61e97634ec1d71f86265d
  • Loading branch information
thewtex committed Aug 25, 2017
2 parents 8b738df + 940f68e commit 35a7420
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
25 changes: 23 additions & 2 deletions Modules/IO/NIFTI/include/itkNiftiImageIO.h
Expand Up @@ -23,7 +23,6 @@

#include <fstream>
#include "itkImageIOBase.h"
#include <nifti1_io.h>

namespace itk
{
Expand Down Expand Up @@ -128,7 +127,29 @@ class ITKIONIFTI_EXPORT NiftiImageIO:public ImageIOBase

void SetImageIOMetadataFromNIfTI();

nifti_image *m_NiftiImage;
//This proxy class provides a nifti_image pointer interface to the internal implementation
//of itk::NiftiImageIO, while hiding the niftilib interface from the external ITK interface.
class NiftiImageProxy;

//This class has ownership of the proxy and is thereby holder of the nifti_image pointer.
class NiftiImageHolder
{
private:
NiftiImageProxy* const m_NiftiImageProxy;
public:
NiftiImageHolder();
~NiftiImageHolder();
NiftiImageProxy& GetNiftiImageProxy();

private:
NiftiImageHolder(const NiftiImageHolder&) ITK_DELETED_FUNCTION;
NiftiImageHolder& operator=(const NiftiImageHolder &) ITK_DELETED_FUNCTION;
};

//Note that it is essential that m_NiftiImageHolder is defined before m_NiftiImage, to ensure that
//m_NiftiImage can directly get a proxy from m_NiftiImageHolder during NiftiImageIO construction.
NiftiImageHolder m_NiftiImageHolder;
NiftiImageProxy& m_NiftiImage;

double m_RescaleSlope;
double m_RescaleIntercept;
Expand Down
3 changes: 1 addition & 2 deletions Modules/IO/NIFTI/itk-module.cmake
Expand Up @@ -3,11 +3,10 @@ set(DOCUMENTATION "This modules contains an ImageIO class to read or write the

itk_module(ITKIONIFTI
ENABLE_SHARED
DEPENDS
ITKNIFTI
PRIVATE_DEPENDS
ITKIOImageBase
ITKTransform
ITKNIFTI
TEST_DEPENDS
ITKTestKernel
ITKNIFTI
Expand Down
44 changes: 42 additions & 2 deletions Modules/IO/NIFTI/src/itkNiftiImageIO.cxx
Expand Up @@ -19,6 +19,7 @@
#include "itkIOCommon.h"
#include "itkMetaDataObject.h"
#include "itkSpatialOrientationAdapter.h"
#include <nifti1_io.h>

namespace itk
{
Expand Down Expand Up @@ -389,8 +390,47 @@ ::GenerateStreamableReadRegionFromRequestedRegion(const ImageIORegion & requeste
return requestedRegion;
}

NiftiImageIO::NiftiImageIO():
m_NiftiImage(ITK_NULLPTR),

//This internal proxy class provides a pointer-like interface to a nifti_image*, by supporting
//conversions between proxy and nifti_image pointer and arrow syntax (e.g., m_NiftiImage->data).
class NiftiImageIO::NiftiImageProxy
{
nifti_image* m_ptr;
public:
NiftiImageProxy(nifti_image* ptr) :
m_ptr(ptr)
{
}

operator nifti_image*()
{
return m_ptr;
}

nifti_image* operator->()
{
return m_ptr;
}
};

NiftiImageIO::NiftiImageHolder::NiftiImageHolder() :
m_NiftiImageProxy(new NiftiImageProxy(ITK_NULLPTR))
{
}

NiftiImageIO::NiftiImageHolder::~NiftiImageHolder()
{
delete m_NiftiImageProxy;
}

NiftiImageIO::NiftiImageProxy& NiftiImageIO::NiftiImageHolder::GetNiftiImageProxy()
{
return *m_NiftiImageProxy;
}


NiftiImageIO::NiftiImageIO() :
m_NiftiImage(m_NiftiImageHolder.GetNiftiImageProxy()),
m_RescaleSlope(1.0),
m_RescaleIntercept(0.0),
m_OnDiskComponentType(UNKNOWNCOMPONENTTYPE),
Expand Down

0 comments on commit 35a7420

Please sign in to comment.