-
-
Notifications
You must be signed in to change notification settings - Fork 664
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
WIP: Add static member, itk::Image::CreateInitialized(const RegionType &)
#4599
base: master
Are you sure you want to change the base?
WIP: Add static member, itk::Image::CreateInitialized(const RegionType &)
#4599
Conversation
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::CreateInitialized
aims 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"
).