Repository navigation
Conversation
…rator" Lines rearranged verbatim from a6ccc9d; the next commit edits in place.
The original inheritance-based design of the iterator class pairs has several problems, notably the pervasive need to const_cast away the pointer-to-const member whenever an iterator needs write access. This opens up opportunities for accidental or deliberate const-correctness violation. This refactor makes itk::ImageIterator a standalone template class that models both read-only and read/write access semantics based solely on the constness of the template type. ImageConstIterator<T> then functionally acts as an alias template for ImageIterator<const T>. It is implemented as a minimal derived class due to CTAD not being available for alias templates pre-C++20.
ImageIterator<const T> converted only from ImageIterator<T>, so the documented equivalence with ImageConstIterator<T> held one way, and the comparison operators accepted iterators over unrelated images. One trait now states the allowed conversion (same image, never dropping const) for all iterators; comparisons require the same image. C++20 compilers use requires-clauses and operator<=>, and C++26 compilers name the forbidden read-only to writable conversion.
… image constness" Lines rearranged verbatim from ec2f839; the next commit edits in place.
ImageRegionIterator<T> inherited from ImageRegionConstIterator<T> and cast away const to write, so ImageRegionIterator<const T> could write to a const image (InsightSoftwareConsortium#7003). ImageRegionIterator now derives from ImageIterator<T> and writes only when T is not const; ImageRegionConstIterator<T> is ImageRegionIterator<const T>, with deduction guides for smart and raw pointers. Both headers provide both classes.
…by image constness" Lines rearranged verbatim from a5a675c; the next commit edits in place.
Apply the ImageRegionIterator design to the scanline pair, so ImageScanlineIterator<const T> cannot write and the const_cast in Set() and Value() goes away.
…age constness" Lines rearranged verbatim from 0daca48; the next commit edits in place.
ImageReverseConstIterator offered a public Set() that cast away const, and the writable reverse iterators accepted read-only sources. The four reverse classes now share ImageRegionReverseIterator<T>, writable only when T is not const; the other names derive from it, so every existing method remains except writes through a const image. Conversion from a forward iterator now sets the row span from the current position; before, the span end was computed from a span begin that was not yet set. The GetBufferPointer test now converts from a writable iterator, since conversion from a read-only one is removed.
… by image constness" Lines rearranged verbatim from a9611d9; the next commit edits in place.
Apply the ImageIterator design to the root of the WithIndex family: ImageIteratorWithIndex<T> holds the position as a pointer to const pixels only when T is const, so Set() and Value() need no const_cast and are absent for const images. ImageConstIteratorWithIndex<T> is ImageIteratorWithIndex<const T>.
…image constness" Lines rearranged verbatim from f748995; the next commit edits in place.
Apply the ImageIteratorWithIndex design to the region, linear, slice, random, random non-repeating, and region exclusion iterators. Each XxxIteratorWithIndex<T> derives from its writable base, inherits the constness-gated Set() and Value(), and XxxConstIteratorWithIndex<T> is XxxIteratorWithIndex<const T>. The random non-repeating conversion deep-copies the permutation it owns.
…ator access by constness" Lines rearranged verbatim from 2d24382; the next commit edits in place.
The frequency-layout iterators and ReflectiveImageRegionIterator inherited from read-only bases and cast away const to write. They now derive from the writable WithIndex iterators, so writes need no cast and are unavailable for const images; each Const name is the iterator over the const image.
… access by image constness" Lines rearranged verbatim from c056797; the next commit edits in place.
LineIterator and PathIterator wrote through a const_cast of the const image held by their read-only bases. Each is now the iterator, writable only when TImage is not const, and the Const name iterates over the const image. PathIterator::Value() read a nonexistent member, so it could not compile; it now returns the current pixel.
The writable flood-filled iterators cast away the const image held by ConditionalConstIterator to write a pixel. They now keep the writable image pointer their constructor receives, offer Set() only for non-const images, and read through the const image without a cast.
Adds compile-time checks that the indexed iterators keep the ITK 5 ImageIteratorDimension constant, that the exclusion iterator can be built from a plain ImageIteratorWithIndex, and that Value() is assignable only for iterators over a non-const image.
Member
|
Awesome dzenanz! Thank you! We still have concerns that need to be addressed. |
Member
Author
|
It is a lot easier to review this way. I am still going through this. |
Member
Author
|
The last commit I somewhat carefully looked at is 632f19c. |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a temporary PR, to help review the changes in #7065.