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

Multipexing-hkem: allows the use of multiple "anatomical" images #424

Merged
merged 18 commits into from Jan 14, 2020

Conversation

danieldeidda
Copy link
Collaborator

This needs to be merged before the "only_functional" pull request! @ashgillman

Copy link
Collaborator

@ashgillman ashgillman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Looks good to me, just one small indentation recommendation.

src/iterative/KOSMAPOSL/KOSMAPOSLReconstruction.cxx Outdated Show resolved Hide resolved
@ashgillman
Copy link
Collaborator

Actually, there are merge conflicts.

<<<<<<< MHKEM
  std::vector<shared_ptr<TargetT> > &get_anatomical_prior_sptr();
=======
  shared_ptr<const TargetT> get_anatomical_prior_sptr() const;
>>>>>>> master

Recommend:

  std::vector<shared_ptr<TargetT> > get_anatomical_prior_sptr() const;

<<<<<<< MHKEM
  void set_anatomical_prior_sptr(shared_ptr<TargetT>&, int &index);
  void set_anatomical_image_filenames(std::string&, int &index);
=======
  void set_anatomical_prior_sptr(shared_ptr<TargetT>);

  void set_anatomical_image_filenames(const std::string&);
>>>>>>> master

Recommend:

  void set_anatomical_prior_sptr(shared_ptr<TargetT>, int index);
  void set_anatomical_image_filenames(const std::string&, int index);

<<<<<<< MHKEM
std::vector<shared_ptr<TargetT> > &KOSMAPOSLReconstruction<TargetT>::get_anatomical_prior_sptr()
=======
shared_ptr<const TargetT> KOSMAPOSLReconstruction<TargetT>::get_anatomical_prior_sptr() const
>>>>>>> master

Not sure here... The & should go from the top one, but should it also have a const?


<<<<<<< MHKEM
set_anatomical_prior_sptr (shared_ptr<TargetT>& arg, int &index)
=======
set_anatomical_prior_sptr (shared_ptr<TargetT> arg)
>>>>>>> master

Recommend:

set_anatomical_prior_sptr (shared_ptr<TargetT>arg, int &index)

@ashgillman
Copy link
Collaborator

Not sure why the Appveyor failed, did it build locally?

@ashgillman
Copy link
Collaborator

Also, this appears to solve #416, as the code looks like it would gracefully accept an empty list?

@danieldeidda
Copy link
Collaborator Author

Not sure why the Appveyor failed, did it build locally?

not sure but it runs on my computer

@ashgillman
Copy link
Collaborator

The build error is:

/home/travis/build/UCL/STIR/src/iterative/KOSMAPOSL/KOSMAPOSLReconstruction.cxx:218:7: error: no matching function for call to ‘std::vector<boost::shared_ptr<stir::DiscretisedDensity<3, float> >, std::allocator<boost::shared_ptr<stir::DiscretisedDensity<3, float> > > >::push_back(std::auto_ptr<stir::DiscretisedDensity<3, float> >)’

       this->anatomical_prior_sptr.push_back(read_from_file<TargetT>(anatomical_image_filenames[i]));

       ^

But strangely only occurs when building on Linux with -DDISABLE_CERN_ROOT=1.

Is this an issue with shared_ptr vs auto_ptr?

@ashgillman
Copy link
Collaborator

@KrisThielemans
@danieldeidda and I are scratching our heads a little here. Daniel is unable to reproduce locally.

Pointers from std not boost are now preferred, correct? Any idea why DISABLE_CERN_ROOT would change the behaviour?

@robbietuk
Copy link
Collaborator

if not DISABLE_CERN_ROOT enables cxx11:

STIR/CMakeLists.txt

Lines 103 to 115 in 71c03a1

if(NOT DISABLE_CERN_ROOT)
find_package(CERN_ROOT)
if (CERN_ROOT_FOUND)
message(STATUS "ROOT Version: ${CERN_ROOT_VERSION}")
# Find which major version this is
string(REPLACE "." ";" _VERSION_LIST ${CERN_ROOT_VERSION})
list(GET _VERSION_LIST 0 CERN_ROOT_VERSION_MAJOR)
if (${CERN_ROOT_VERSION_MAJOR} GREATER 5)
message(STATUS "This ROOT version needs C++-11, so we will enable this.")
UseCXX(11)
endif()
endif()
endif()

Perhaps it is a cxx version problem?

@ashgillman
Copy link
Collaborator

ashgillman commented Dec 2, 2019 via email

@rijobro
Copy link
Collaborator

rijobro commented Dec 2, 2019

But this should be the same for Daniel building locally.

What do you mean by this?

STIR should be compatible with pre-C++11. So I think that the DISABLE_CERN_ROOT isn't causing the problem. It's just flagging it up, since C++11 gets disabled when DISABLE_CERN_ROOT=OFF.

@KrisThielemans
Copy link
Collaborator

As @rijobro almost says, DISABLE_CERN_ROOT=ON means no particular C++ standard is asked for, so it's up to the compiler default to choose one. On Travis, there's some ancient compilers (gcc4 etc) that default to pre-C++11. Hardly anybody has these anymore...

In any case, it's a pre-C++11 bug. you cannot have a vector<auto_ptr<T> >, see e.g. https://stackoverflow.com/questions/111478/why-is-it-wrong-to-use-stdauto-ptr-with-standard-containers.

Probably best is to work-around it like

 shared_ptr<TargetT> an_im_sptr(read_from_file<TargetT>(anatomical_image_filenames[i]));
 this->anatomical_prior_sptr.push_back( an_im_sptr);

and make anatomical_prior_sptr a vector<shared_ptr<...>>.

Copy link
Collaborator

@KrisThielemans KrisThielemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this somehow backwards compatible for SIRF. SIRF 2.1 was released with STIR 4.0.0-alpha. If we change interface between 4.0.0-alpha and 4.0.0, it'll be somewhat confusing...

might be doable with overloading and default arguments of functions.

Comment on lines 68 to 72
do symmetry 90degrees min phi := 1
do_symmetry_180degrees_min_phi:= 1
do_symmetry_swap_s:= 1
do_symmetry_swap_segment:= 1
do_symmetry_shift_z:= 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not have these here. confusing for most people


input file := my_noisy_prompts_1ax_pos.hs

; Daniel: here we have the possibility to choose the parameters which define the kernel matrix and the name of the MR image.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove "Daniel" (I mean the string, not the person!)

void set_num_neighbours(const int);
void set_num_non_zero_feat(const int);
void set_sigma_m(const double);
void set_sigma_m(double&, int &index);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please no references in arguments of a set function

@@ -235,12 +235,12 @@ class KOSMAPOSLReconstruction:

/*! Create a matrix similarly to calculate_norm_matrix() but this is done for the anatomical image, */
/*! which does not change over iteration.*/
void calculate_norm_const_matrix(TargetT &normm,
void calculate_norm_const_matrix(std::vector<shared_ptr<TargetT> > normm,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't have any output apparently, but only side-effects? is that correct? best to document. Please make normm a reference, const if input`, non-const if output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes normm is the output, i forgot the reference

@@ -170,17 +171,14 @@ initialise_keymap()
// this->parser.add_key("anatomical image filename",&this->anatomical_image_filenames);
this->parser.add_key("number of neighbours",&this->num_neighbours);
this->parser.add_key("number of non-zero feature elements",&this->num_non_zero_feat);
this->parser.add_key("sigma_m",&this->sigma_m);
this->parser.add_key("sigma_m",&sigma_m);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not this->?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason, I probably forgot it

}

template <typename TargetT>
void
KOSMAPOSLReconstruction<TargetT>::
set_anatomical_image_filenames(const std::string& arg)
set_anatomical_image_filenames(std::string &arg, int index)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arg is an input argument, need to have it const

examples/samples/KOSMAPOSL_mhkem.par Show resolved Hide resolved
@@ -196,7 +196,7 @@ class KOSMAPOSLReconstruction:
//! Anatomical image filename
std::vector<std::string> anatomical_image_filenames;

std::vector<shared_ptr<TargetT> > anatomical_prior_sptr,kmnorm_sptr;
std::vector<std::shared_ptr<TargetT> > anatomical_prior_sptr,kmnorm_sptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no std::shared_ptr please. it'll break. just shared_ptr

@KrisThielemans
Copy link
Collaborator

@danieldeidda is this for next year? I might try to get 4.0 beta out during the holidays...

Copy link
Collaborator Author

@danieldeidda danieldeidda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danieldeidda is this for next year? I might try to get 4.0 beta out during the holidays...

Sorry I left it bit. This can be done in these days, I will review the comments and apply the modification. I remember we said something about the sigma_m being a vector now that can be an issue for SIRF

@@ -235,12 +235,12 @@ class KOSMAPOSLReconstruction:

/*! Create a matrix similarly to calculate_norm_matrix() but this is done for the anatomical image, */
/*! which does not change over iteration.*/
void calculate_norm_const_matrix(TargetT &normm,
void calculate_norm_const_matrix(std::vector<shared_ptr<TargetT> > normm,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes normm is the output, i forgot the reference

@@ -170,17 +171,14 @@ initialise_keymap()
// this->parser.add_key("anatomical image filename",&this->anatomical_image_filenames);
this->parser.add_key("number of neighbours",&this->num_neighbours);
this->parser.add_key("number of non-zero feature elements",&this->num_non_zero_feat);
this->parser.add_key("sigma_m",&this->sigma_m);
this->parser.add_key("sigma_m",&sigma_m);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason, I probably forgot it

if (this->anatomical_image_filenames.size()>1){
error("At the moment you can only use one anatomical image %s");
if (!this->anatomical_image_filenames.size()==sigma_m.size()){
error("The number of sigma_m parameters must be the same as the numberof anatomical image filenames %s");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably best not to put any argument

Copy link
Collaborator

@KrisThielemans KrisThielemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

travis etc are all happy so this is great. I have a few tiny ones left. Please check if SIRF 2.1 compiles/runs with this version as wel (it probably does)l. Then good to go.

src/include/stir/KOSMAPOSL/KOSMAPOSLReconstruction.h Outdated Show resolved Hide resolved
src/iterative/KOSMAPOSL/KOSMAPOSLReconstruction.cxx Outdated Show resolved Hide resolved
@danieldeidda
Copy link
Collaborator Author

SIRF compiles with the last commit

@KrisThielemans KrisThielemans merged commit 83a35bb into UCL:master Jan 14, 2020
@KrisThielemans
Copy link
Collaborator

thanks @danieldeidda

by the way, ci skip needs to be [ci skip] for it to prevent CI running...

@danieldeidda
Copy link
Collaborator Author

danieldeidda commented Jan 14, 2020 via email

@ashgillman ashgillman mentioned this pull request Jan 30, 2020
@danieldeidda danieldeidda deleted the MHKEM branch April 15, 2020 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants