Skip to content

Add and use itk::ImageBase::AllocateInitialized()#4479

Merged
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:AllocateZeroInitializedPixelBuffer
Feb 27, 2024
Merged

Add and use itk::ImageBase::AllocateInitialized()#4479
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:AllocateZeroInitializedPixelBuffer

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Feb 24, 2024

The existing three possible ways to call Allocate(bool = false) (either by Allocate(true), Allocate(false), or Allocate()) may accidentally be confused, especially by novice ITK users.

The proposed AllocateZeroInitializedPixelBuffer() is intended to reduce the chance of such a confusion, and improve code readability. It is equivalent to Allocate(true).


For the record, "AllocateZeroInitializedPixelBuffer" was renamed to "AllocateInitialized", as suggested at #4479 (comment)

@github-actions github-actions bot added area:Python wrapping Python bindings for a class type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Numerics Issues affecting the Numerics module labels Feb 24, 2024
@N-Dekker
Copy link
Contributor Author

/azp run

@N-Dekker N-Dekker marked this pull request as ready for review February 25, 2024 13:40
@blowekamp
Copy link
Member

I find the member function name over verbose.

@dzenanz
Copy link
Member

dzenanz commented Feb 26, 2024

AllocateInitialized for the name? Docstring should have sufficient explanation about default values.

@N-Dekker
Copy link
Contributor Author

AllocateInitialized for the name?

Thanks for the suggestion @dzenanz. However, I would like the name to be self-explanatory. Until now it was a common practice to add a comment to actually explain the meaning of Allocate(true) with each Allocate(true) call. For example:

m_TemporaryPointer->Allocate(true); // initialize buffer to zero

m_TemporaryPointer->Allocate(true); // initialize buffer to zero

So do you (both) think the name AllocateInitialized is sufficiently self-explanatory? So that most people won't feel the need to look up the meaning, or add a comment like "initialize buffer to zero"?

@blowekamp
Copy link
Member

So do you (both) think the name AllocateInitialized is sufficiently self-explanatory? So that most people won't feel the need to look up the meaning, or add a comment like "initialize buffer to zero"?

I think the name is sufficient 👍

Equivalent to `Allocate(true)`. Aims to help improve readability of user code.
Replaced function calls of the form `image->Allocate(true)` with
`image->AllocateInitialized()`. Removed redundant comments that said something
like `// initialize buffer to zero`.
@N-Dekker N-Dekker force-pushed the AllocateZeroInitializedPixelBuffer branch from 492c355 to 527843e Compare February 26, 2024 17:28
@N-Dekker N-Dekker changed the title Add and use itk::ImageBase::AllocateZeroInitializedPixelBuffer() Add and use itk::ImageBase::AllocateInitialized() Feb 27, 2024
@dzenanz dzenanz merged commit 1b01d5c into InsightSoftwareConsortium:master Feb 27, 2024
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Mar 5, 2024
Replaced lines of code of the form

    image>Allocate();
    image>FillBuffer(zero);

With `image->AllocateInitialized();`.

Follow-up to pull request InsightSoftwareConsortium#4479
commit 47fe345
"ENH: Add `AllocateInitialized()` to ImageBase"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Mar 5, 2024
Replaced lines of code of the form

    image>Allocate();
    image>FillBuffer(zero);

With `image->AllocateInitialized();`.

Cases found by the regular expression `^(.+->)Allocate.+;\r\n\1FillBuffer`.

Follow-up to pull request InsightSoftwareConsortium#4479
commit 47fe345
"ENH: Add `AllocateInitialized()` to ImageBase"
hjmjohnson pushed a commit that referenced this pull request Mar 6, 2024
Replaced lines of code of the form

    image>Allocate();
    image>FillBuffer(zero);

With `image->AllocateInitialized();`.

Cases found by the regular expression `^(.+->)Allocate.+;\r\n\1FillBuffer`.

Follow-up to pull request #4479
commit 47fe345
"ENH: Add `AllocateInitialized()` to ImageBase"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jun 5, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jun 5, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jun 10, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jun 10, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jun 10, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Numerics Issues affecting the Numerics module area:Python wrapping Python bindings for a class area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants