ENH: remove redundant WriteImage overloads#2165
ENH: remove redundant WriteImage overloads#2165blowekamp merged 1 commit intoInsightSoftwareConsortium:masterfrom
Conversation
|
I would rather postpone the introduction of C++17 |
2896df7 to
6d68d72
Compare
The thing is, I don't have any |
|
This convenience function is not a big reason to go down that hole. And generally, ITK does not deal with strings much - mostly for file names and metadata dictionary. |
|
Maybe we need the |
|
If we do need them, this PR is pointless. Does anyone have a suggestion of doing this with less than 8 overloads? |
My initial expectation is that only |
|
@blowekamp 1 signature produces: If I also add |
|
I will leave this open for a while, in case someone gets some brilliant ideas. But I am essentially abandoning this PR, and when I see this after a week has passed I will formally close it (assuming no new ideas). |
|
Honestly I'm still in favor of passing the image by reference, instead of by smart/raw pointer. None of the overloads would have been necessary then. |
|
That just places the burden on the user. It becomes annoying really quickly. |
Then why, in your opinion, did C++ introduce pass by (const) reference for parameters? |
|
Sorry for accidentally editing your comment @dzenanz ! |
|
ITK was designed in the C++98 world, before |
|
|
|
I believe some additional conversion with the std::SmartPoitner with const/non-const should help give the convenience of implicit conversion here. Alternatively, we could just a In the convenience vs verbosity, the traditionally chooses to be clear and verbose. |
|
Most images we want saved are held in a smart pointer, I believe that signature is more important. Also, since smart pointer has a constructor from raw pointer, there should be an automatic conversion. Sadly, compilers fail to do it. |
I believe you may mean the usage is important, not the signature. This one function seems to work: This might be useful too: The in function meta-programming could be refactored into a meta-struct, something called like "MakeSmartPointer". @N-Dekker I bet you could make it work with references too... but that may get little to messy :) |
|
@blowekamp you are free to take over this PR or create a new one. I believe you should have the right to push/amend this branch in my fork. |
6d68d72 to
2e9ac8e
Compare
2e9ac8e to
871672b
Compare
dzenanz
left a comment
There was a problem hiding this comment.
Looks great! Awesome that you added a specific test.
|
I can't formally approve my own PR, but I approve! |
| ImageType * image_rptr = image_ptr.GetPointer(); | ||
| itk::WriteImage(image_rptr, "test1.mha"); | ||
|
|
||
| ImageType * image_crptr = image_ptr.GetPointer(); |
There was a problem hiding this comment.
Shouldn't here be a const ImageType * image_crptr = image_ptr.GetConstPointer(); or something else involving const qualifier?
871672b to
9fedb70
Compare
|
Thanks for addressing my comments about the new test that you added! I think the test is still somewhat limited, as it only tests that it is possible to call Anyway, that would be a nice future extension, in my opinion. |
N-Dekker
left a comment
There was a problem hiding this comment.
I'm very glad that all (seven!) redundant WriteImage overloads can be removed this way 😄
|
@N-Dekker That you for your comments and suggestions. This problem seemed rather simple to begin with but with the requirements of implicit template parameters, and support for numerous input proved challenging due to implicit conversion not working with the implicit template parameters. What we have finally iterated towards is a new ( to me at least ), flexible and maintainable way to implement functions taking itk::Image pointers.
I don't believe that we have this functionality with ITK and the GTest framework and it would likely need some measures for tolerance for pixels and metadata. |
|
I am seeing the following in testing errors: I am using an anonymous name space for file local class declarations. I guess this is no longer allowed. What is the preferred way? |
I don't know right off the bat. I would have to search, maybe see other GTests. |
9fedb70 to
89da201
Compare
Reduce to only one signature and use meta-programming to always convert the input image type to SmartPointer<const T>, and ensure that the writer is instantiated with a non-constant image type.
89da201 to
d8af208
Compare
|
Why did you change |
…mageFunction ENH: remove redundant WriteImage overloads
This is a follow-up to #2160 which was merged a bit too fast.