Commit ec0be5e1 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: interface for WarpedNiftyregImage

parent 2c542852
......@@ -50,6 +50,16 @@ public:
virtual std::shared_ptr<nifti_image> GetFloatingNiftiImage() = 0;
};
template< class TPixel >
class NiftyregWarpedImageInterface
{
public:
using Type = NiftyregWarpedImageInterface< TPixel >;
using Pointer = std::shared_ptr< Type >;
virtual std::shared_ptr<nifti_image> GetWarpedNiftiImage() = 0;
};
template< class TPixel >
struct Properties< NiftyregReferenceImageInterface< TPixel >>
{
......@@ -67,6 +77,15 @@ struct Properties< NiftyregFloatingImageInterface< TPixel >>
return { { keys::NameOfInterface, "NiftyregFloatingImageInterface" }, { keys::PixelType, PodString< TPixel >::Get() } };
}
};
template< class TPixel >
struct Properties< NiftyregWarpedImageInterface< TPixel >>
{
static const std::map< std::string, std::string > Get()
{
return{ { keys::NameOfInterface, "NiftyregWarpedImageInterface" }, { keys::PixelType, PodString< TPixel >::Get() } };
}
};
}
#endif // #define selxNiftyregInterfaces_h
......@@ -26,13 +26,15 @@
#include "_reg_f3d.h"
#include <string.h>
#include <array>
namespace selx
{
template< class TPixel >
class Niftyregf3dComponent :
public SuperElastixComponent<
Accepting< NiftyregReferenceImageInterface< TPixel >, NiftyregFloatingImageInterface< TPixel >>,
Providing< RunRegistrationInterface >
Providing< NiftyregWarpedImageInterface< TPixel >, RunRegistrationInterface >
>
{
public:
......@@ -41,7 +43,7 @@ public:
typedef Niftyregf3dComponent< TPixel > Self;
typedef SuperElastixComponent<
Accepting< NiftyregReferenceImageInterface< TPixel >, NiftyregFloatingImageInterface< TPixel >>,
Providing< RunRegistrationInterface >
Providing< NiftyregWarpedImageInterface< TPixel >, RunRegistrationInterface >
> Superclass;
typedef std::shared_ptr< Self > Pointer;
typedef std::shared_ptr< const Self > ConstPointer;
......@@ -53,6 +55,8 @@ public:
virtual int Set( typename NiftyregFloatingImageInterface< TPixel >::Pointer ) override;
virtual std::shared_ptr<nifti_image> GetWarpedNiftiImage() override;
virtual void RunRegistration() override;
virtual bool MeetsCriterion( const ComponentBase::CriterionType & criterion ) override;
......@@ -63,6 +67,9 @@ private:
reg_f3d< TPixel > * m_reg_f3d;
// m_warped_images is an array of 2 nifti images. Depending on the use case, typically only [0] is a valid image
std::unique_ptr< std::array<std::shared_ptr<nifti_image>,2>> m_warped_images;
protected:
// return the class name and the template arguments to uniquely identify this component.
......
......@@ -59,6 +59,14 @@ Niftyregf3dComponent< TPixel >
return 0;
}
template< class TPixel >
std::shared_ptr<nifti_image>
Niftyregf3dComponent< TPixel >
::GetWarpedNiftiImage()
{
return (*(this->m_warped_images.get()))[0];
}
template< class TPixel >
void
......@@ -67,8 +75,20 @@ 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();
memset(outputWarpedImage[0]->descrip, 0, 80);
strcpy(outputWarpedImage[0]->descrip, "Warped image using NiftyReg (reg_f3d)");
//encapsulate malloc-ed pointer in a smartpointer for proper memory ownership
this->m_warped_images = std::unique_ptr< std::array<std::shared_ptr<nifti_image>, 2>>(new std::array<std::shared_ptr<nifti_image>, 2>);
(*(this->m_warped_images.get()))[0] = std::shared_ptr<nifti_image>(outputWarpedImage[0], nifti_image_free);
(*(this->m_warped_images.get()))[1] = std::shared_ptr<nifti_image>(outputWarpedImage[1], nifti_image_free);
free(outputWarpedImage);
outputWarpedImage = NULL;
}
......
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