WIP: Add static member, itk::Image::CreateInitialized(const RegionType &)#4599
WIP: Add static member, itk::Image::CreateInitialized(const RegionType &)#4599N-Dekker wants to merge 2 commits intoInsightSoftwareConsortium:mainfrom
itk::Image::CreateInitialized(const RegionType &)#4599Conversation
| auto image = ImageType::New(); | ||
| { | ||
| auto image = ImageType::CreateInitialized([&reader] { | ||
| ImageType::RegionType region = reader->GetOutput()->GetLargestPossibleRegion(); | ||
| region.SetIndex(0, 10); | ||
| image->SetRegions(region); | ||
| image->AllocateInitialized(); | ||
| } | ||
| return region; | ||
| }()); |
There was a problem hiding this comment.
FYI, this was probably the most interesting use case that I found. In the original code, the variable region was already kept inside a very small scope, between { and }. The proposed pull request places the region variable inside a lambda, in order to keep its scope small.
|
Are there any similarly named methods to "Obj::CreateInitialized"? What about something like Note: I'm not suggesting preference, but starting a conversion about what may be the best and most consistent interface. |
Thanks for asking @blowekamp I agree that it's good to discuss the name.
What do you think? |
|
Good points. We also need to consider other image type such as VectorImage, and LabelMap and even module image types like RLE image. Perhaps |
VectorImage would need an extra parameter to specify the vector length. So I think it would need to have its own static member function I'm not sure about supporting Just like |
Aims to simplify creating an image with an allocated buffer of zero-initialized pixels.
Replaced more than sixty cases of code like:
auto image = ImageType::New();
image->SetRegions(region);
image->AllocateInitialized();
with the following single statement:
auto image = ImageType::CreateInitialized(region);
in ITK test files ("itk*Test*.cxx").
519ab58 to
a8ac2f1
Compare
|
@blowekamp I guess a static Just something to be taken into account. I'm not against a free function template like |
itk::Image::CreateInitializedaims to simplify creating an image with an allocated buffer of zero-initialized pixels.Replaced more than sixty cases of code like:
with the following single statement:
auto image = ImageType::CreateInitialized(region);in ITK test files (
"itk*Test*.cxx").