Skip to content

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Aug 22, 2024

Documented that Iterator(image, region) constructors initialize the iterator at the beginning of the region. Added a GoogleTest unit test to checks this added specification.

@github-actions github-actions bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots 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 labels Aug 22, 2024
@N-Dekker N-Dekker force-pushed the GTest-ImageRegionIterator-CheckBeginAndEnd branch from c02faaa to bc2a55e Compare August 22, 2024 17:32
@N-Dekker N-Dekker changed the title Document that ImageRegionIterator constructors initialize at the begin, add GTest unit test Document that Iterator(image, region) constructors initialize at the begin, add GTest unit test Aug 22, 2024
Checks that an iterator, constructed by `IteratorType(image, region)` is at the
begin. Checks 22 different iterator types from Core/Common.
Explicitly specify that those constructors initialize the iterator at the begin
of the region.
@N-Dekker N-Dekker force-pushed the GTest-ImageRegionIterator-CheckBeginAndEnd branch from bc2a55e to 88b854f Compare August 24, 2024 11:12
@N-Dekker N-Dekker marked this pull request as ready for review August 26, 2024 13:32
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Aug 26, 2024
It is unnecessary to call GoToBegin() on an ITK iterator when it has just been constructed, by `Iterator(image, region)`. Such a function call just takes compile-time and run-time.

Supported by ITK pull request InsightSoftwareConsortium/ITK#4815 "Document that Iterator(image, region) constructors initialize at the begin, add GTest unit test"
Comment on lines +49 to +58
// Has_IsAtBegin tells whether the specified iterator type has an `IsAtBegin()` member function, returning a `bool`. It
// is inspired by "How to detect whether there is a specific member variable in class?", answered by Andy Prowl, Jan 25,
// 2013 at https://stackoverflow.com/a/14523787 (the `has_id` example).
template <typename TIterator, typename = bool>
struct Has_IsAtBegin : std::false_type
{};

template <typename TIterator>
struct Has_IsAtBegin<TIterator, decltype(std::declval<TIterator>().IsAtBegin())> : std::true_type
{};
Copy link
Contributor Author

@N-Dekker N-Dekker Aug 26, 2024

Choose a reason for hiding this comment

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


For the record,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, this Has_IsAtBegin<TIterator> meta-function is just an implementation detail of the unit test that I'm proposing. As a whole, I think this pull request is ready 😃

N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Aug 27, 2024
It is unnecessary to call GoToBegin() on an ITK iterator when it has just been constructed, by `Iterator(image, region)`. Such a function call just takes compile-time and run-time.

Supported by ITK pull request InsightSoftwareConsortium/ITK#4815 "Document that Iterator(image, region) constructors initialize at the begin, add GTest unit test"
Copy link
Member

@blowekamp blowekamp left a comment

Choose a reason for hiding this comment

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

LGTM. Just a commented on a small thought.



// Checks that an iterator that is just constructed by `IteratorType(image, region)` is at the begin.
TEST(ImageRegionIterator, IsConstructedAtBegin)
Copy link
Member

Choose a reason for hiding this comment

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

The is some 💪 use of variadict templates here. However with the nested dispatching of the functions how does test report a failure? Does it indicate the type? Is some Information needed the the "EXPECT" statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, here is my reply: #4815 (comment)

@dzenanz dzenanz merged commit 9eb1359 into InsightSoftwareConsortium:master Aug 28, 2024
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Aug 29, 2024
- Follow-up to pull request InsightSoftwareConsortium#4815
commit 66e6d8b
"ENH: Add GoogleTest unit test `ImageRegionIterator.IsConstructedAtBegin`"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Aug 29, 2024
Explicitly specify that those constructors from iterator types of
Modules/Filtering/ImageFrequency initialize the iterator at the begin of
the region.

- Follow-up to pull request InsightSoftwareConsortium#4815
commit 9eb1359
"DOC: Document Iterator(image, region) constructors initializing at begin"
@N-Dekker
Copy link
Contributor Author

N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Aug 30, 2024
When an ITK iterator is just constructed by `IteratorType(image, region)`, it
is already initialized at the begin of the region, as was tested and documented
by pull request InsightSoftwareConsortium#4815
commit 66e6d8b and 9eb1359.

- Follow-up to pull request InsightSoftwareConsortium#3953
commit 5a60ed0
"STYLE: Remove unnecessary iterator `GoToBegin()` calls from Filtering", 7 March 2023
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Sep 2, 2024
- Follow-up to pull request InsightSoftwareConsortium#4815
commit 66e6d8b
"ENH: Add GoogleTest unit test `ImageRegionIterator.IsConstructedAtBegin`"

Note: `FrequencyImageRegionIteratorWithIndex` and
`FrequencyImageRegionConstIteratorWithIndex` are excluded from this commit,
because they do not yet compile.
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Sep 2, 2024
Explicitly specify that those constructors from iterator types of
Modules/Filtering/ImageFrequency initialize the iterator at the begin of
the region.

Note: `FrequencyImageRegionIteratorWithIndex` and
`FrequencyImageRegionConstIteratorWithIndex` are excluded from this commit,
because they do not yet compile.

- Follow-up to pull request InsightSoftwareConsortium#4815
commit 9eb1359
"DOC: Document Iterator(image, region) constructors initializing at begin"
dzenanz pushed a commit that referenced this pull request Sep 3, 2024
When an ITK iterator is just constructed by `IteratorType(image, region)`, it
is already initialized at the begin of the region, as was tested and documented
by pull request #4815
commit 66e6d8b and 9eb1359.

- Follow-up to pull request #3953
commit 5a60ed0
"STYLE: Remove unnecessary iterator `GoToBegin()` calls from Filtering", 7 March 2023
dzenanz pushed a commit that referenced this pull request Sep 3, 2024
- Follow-up to pull request #4815
commit 66e6d8b
"ENH: Add GoogleTest unit test `ImageRegionIterator.IsConstructedAtBegin`"

Note: `FrequencyImageRegionIteratorWithIndex` and
`FrequencyImageRegionConstIteratorWithIndex` are excluded from this commit,
because they do not yet compile.
dzenanz pushed a commit that referenced this pull request Sep 3, 2024
Explicitly specify that those constructors from iterator types of
Modules/Filtering/ImageFrequency initialize the iterator at the begin of
the region.

Note: `FrequencyImageRegionIteratorWithIndex` and
`FrequencyImageRegionConstIteratorWithIndex` are excluded from this commit,
because they do not yet compile.

- Follow-up to pull request #4815
commit 9eb1359
"DOC: Document Iterator(image, region) constructors initializing at begin"
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 type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots 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.

3 participants