Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not modify disps/defs when converting them to defs #832

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Registration/cReg/AffineTransformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ mat44 AffineTransformation<dataType>::get_as_mat44() const
}

template<class dataType>
NiftiImageData3DDeformation<dataType> AffineTransformation<dataType>::get_as_deformation_field(const NiftiImageData<dataType> &ref) const
NiftiImageData3DDeformation<dataType> AffineTransformation<dataType>::get_as_deformation_field(const NiftiImageData<dataType> &ref, const bool) const
{
NiftiImageData3DDeformation<dataType> def;
def.create_from_3D_image(ref);
Expand Down
42 changes: 23 additions & 19 deletions src/Registration/cReg/NiftiImageData3DDeformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,29 @@ void NiftiImageData3DDeformation<dataType>::create_from_cpp(NiftiImageData3DTens
}

template<class dataType>
NiftiImageData3DDeformation<dataType> NiftiImageData3DDeformation<dataType>::get_as_deformation_field(const NiftiImageData<dataType> &ref) const
NiftiImageData3DDeformation<dataType> NiftiImageData3DDeformation<dataType>::get_as_deformation_field(const NiftiImageData<dataType> &ref, const bool use_ref) const
{
NiftiImageData3DDeformation<dataType> output_def;
output_def.create_from_3D_image(ref);
nifti_image * def_ptr = output_def.get_raw_nifti_sptr().get();

// Initialise the deformation field with an identity transformation
reg_tools_multiplyValueToImage(def_ptr,def_ptr,0.f);
reg_getDeformationFromDisplacement(def_ptr);
def_ptr->intent_p1=DEF_FIELD;

// Not marked const so have to copy unfortunately
std::shared_ptr<NiftiImageData3DDeformation<dataType> > copy_of_input_def_sptr =
this->clone();

reg_defField_compose(copy_of_input_def_sptr->get_raw_nifti_sptr().get(),
def_ptr,
nullptr);
return output_def;
if (!use_ref)
return *this;
else {
NiftiImageData3DDeformation<dataType> output_def;
output_def.create_from_3D_image(ref);
nifti_image * def_ptr = output_def.get_raw_nifti_sptr().get();

// Initialise the deformation field with an identity transformation
reg_tools_multiplyValueToImage(def_ptr,def_ptr,0.f);
reg_getDeformationFromDisplacement(def_ptr);
def_ptr->intent_p1=DEF_FIELD;

// Not marked const so have to copy unfortunately
std::shared_ptr<NiftiImageData3DDeformation<dataType> > copy_of_input_def_sptr =
this->clone();

reg_defField_compose(copy_of_input_def_sptr->get_raw_nifti_sptr().get(),
def_ptr,
nullptr);
return output_def;
}
}

template<class dataType>
Expand All @@ -97,7 +101,7 @@ NiftiImageData3DDeformation<dataType> NiftiImageData3DDeformation<dataType>::com
NiftiImageData3DDeformation def = transformations.at(0)->get_as_deformation_field(ref);

for (unsigned i=1; i<transformations.size(); ++i) {
NiftiImageData3DDeformation temp = transformations.at(i)->get_as_deformation_field(ref);
NiftiImageData3DDeformation temp = transformations.at(i)->get_as_deformation_field(ref, false);
reg_defField_compose(temp.get_raw_nifti_sptr().get(),def.get_raw_nifti_sptr().get(),nullptr);
}
return def;
Expand Down
44 changes: 25 additions & 19 deletions src/Registration/cReg/NiftiImageData3DDisplacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,32 @@ void NiftiImageData3DDisplacement<dataType>::create_from_3D_image(const NiftiIma
}

template<class dataType>
NiftiImageData3DDeformation<dataType> NiftiImageData3DDisplacement<dataType>::get_as_deformation_field(const NiftiImageData<dataType> &ref) const
NiftiImageData3DDeformation<dataType> NiftiImageData3DDisplacement<dataType>::get_as_deformation_field(const NiftiImageData<dataType> &ref, const bool use_ref) const
{
NiftiImageData3DDeformation<dataType> output_def;
output_def.create_from_3D_image(ref);
nifti_image * def_ptr = output_def.get_raw_nifti_sptr().get();

// Initialise the deformation field with an identity transformation
reg_tools_multiplyValueToImage(def_ptr,def_ptr,0.f);
reg_getDeformationFromDisplacement(def_ptr);
def_ptr->intent_p1=DEF_FIELD;

// Not marked const so have to copy unfortunately
std::shared_ptr<NiftiImageData3DDisplacement<dataType> > copy_of_input_disp_sptr =
this->clone();
// Convert displacement to deformation
reg_getDeformationFromDisplacement(copy_of_input_disp_sptr->get_raw_nifti_sptr().get());
reg_defField_compose(copy_of_input_disp_sptr->get_raw_nifti_sptr().get(),
def_ptr,
nullptr);
return output_def;
if (!use_ref) {
NiftiImageData3DDeformation<dataType> def(*this);
return def;
}
else {
NiftiImageData3DDeformation<dataType> output_def;
output_def.create_from_3D_image(ref);
nifti_image * def_ptr = output_def.get_raw_nifti_sptr().get();

// Initialise the deformation field with an identity transformation
reg_tools_multiplyValueToImage(def_ptr,def_ptr,0.f);
reg_getDeformationFromDisplacement(def_ptr);
def_ptr->intent_p1=DEF_FIELD;

// Not marked const so have to copy unfortunately
std::shared_ptr<NiftiImageData3DDisplacement<dataType> > copy_of_input_disp_sptr =
this->clone();
// Convert displacement to deformation
reg_getDeformationFromDisplacement(copy_of_input_disp_sptr->get_raw_nifti_sptr().get());
reg_defField_compose(copy_of_input_disp_sptr->get_raw_nifti_sptr().get(),
def_ptr,
nullptr);
return output_def;
}
}

template<class dataType>
Expand Down
8 changes: 6 additions & 2 deletions src/Registration/cReg/include/sirf/Reg/AffineTransformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ class AffineTransformation : public Transformation<dataType>
/// Destructor
virtual ~AffineTransformation() {}

/// Get as deformation field
virtual NiftiImageData3DDeformation<dataType> get_as_deformation_field(const NiftiImageData<dataType> &ref) const;
/// Get as deformation field.
///
/// Reference image **must** be used when converting a transformation matrix to a deformation.
/// For displacements and deformations, the reference can be used optionally. It **should** be used when composing transformations to be used for resampling
/// But is probably unnecessary for simply concatenating deformations.
virtual NiftiImageData3DDeformation<dataType> get_as_deformation_field(const NiftiImageData<dataType> &ref, const bool use_ref = true) const;

/// Deep copy
virtual AffineTransformation deep_copy() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ class NiftiImageData3DDeformation : public NiftiImageData3DTensor<dataType>, pub
/// Create from control point grid image
void create_from_cpp(NiftiImageData3DTensor<dataType> &cpp, const NiftiImageData<dataType> &ref);

/// Get as deformation field
virtual NiftiImageData3DDeformation get_as_deformation_field(const NiftiImageData<dataType> &ref) const;
/// Get as deformation field.
///
/// Reference image **must** be used when converting a transformation matrix to a deformation.
/// For displacements and deformations, the reference can be used optionally. It **should** be used when composing transformations to be used for resampling
/// But is probably unnecessary for simply concatenating deformations.
virtual NiftiImageData3DDeformation get_as_deformation_field(const NiftiImageData<dataType> &ref, const bool use_ref = true) const;

/// Compose multiple transformations into single deformation field
static NiftiImageData3DDeformation compose_single_deformation(const std::vector<const Transformation<dataType> *> &transformations, const NiftiImageData<dataType> &ref);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ class NiftiImageData3DDisplacement : public NiftiImageData3DTensor<dataType>, pu
/// Create from 3D image (fill with zeroes)
void create_from_3D_image(const NiftiImageData<dataType> &image);

/// Get as deformation field
virtual NiftiImageData3DDeformation<dataType> get_as_deformation_field(const NiftiImageData<dataType> &ref) const;
/// Get as deformation field.
///
/// Reference image **must** be used when converting a transformation matrix to a deformation.
/// For displacements and deformations, the reference can be used optionally. It **should** be used when composing transformations to be used for resampling
/// But is probably unnecessary for simply concatenating deformations.
virtual NiftiImageData3DDeformation<dataType> get_as_deformation_field(const NiftiImageData<dataType> &ref, const bool use_ref = true) const;

virtual ObjectHandle<DataContainer>* new_data_container_handle() const
{
Expand Down
8 changes: 6 additions & 2 deletions src/Registration/cReg/include/sirf/Reg/Transformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ class Transformation
/// Destructor
virtual ~Transformation() {}

/// Get as deformation field
virtual NiftiImageData3DDeformation<dataType> get_as_deformation_field(const NiftiImageData<dataType> &ref) const = 0;
/// Get as deformation field.
///
/// Reference image **must** be used when converting a transformation matrix to a deformation.
/// For displacements and deformations, the reference can be used optionally. It **should** be used when composing transformations to be used for resampling
/// But is probably unnecessary for simply concatenating deformations.
virtual NiftiImageData3DDeformation<dataType> get_as_deformation_field(const NiftiImageData<dataType> &ref, const bool use_ref = true) const = 0;

/// Write
virtual void write(const std::string &filename) const = 0;
Expand Down