Skip to content

ENH: Let Range classes do direct pixel access to itk::Image subclasses - #6905

Open
N-Dekker wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:Direct-pixel-access-derived-Image-type
Open

N-Dekker wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:Direct-pixel-access-derived-Image-type

Conversation

@N-Dekker

Copy link
Copy Markdown
Contributor

Until now, ImageBufferRange and ImageRegionRange would use a proxy to access the data of a subclass of itk::Image. With this commit, they will do direct pixel access instead, for those subclasses.

This commit may significantly improve the performance of iteration over the pixels of an itk::Image subclass. Moreover, it will address the compile errors, attempting to build OrfeoToolBox v10 against ITK 6.0 beta2, reported by Nicklas Larsson (@nilason) at #6898 saying:

itkCastImageFilter.hxx:167:84: error: non-const lvalue reference to type 'itk::Vector<double, 2>' cannot bind to an initializer list temporary
  167 |     std::conditional_t<isVariableLengthVector, OutputPixelType, OutputPixelType &> outputPixel{ *outputIt };
      |                                                                                    ^          ~~~~~~~~~~~~~

@github-actions github-actions Bot added type:Enhancement Improvement of existing methods or implementation 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 Sep 25, 2026
namespace
{
// Minimal subclass of itk::Image, used in static_assert statements below here.
class ImageSubclass : public itk::Image<int>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@N-Dekker
N-Dekker marked this pull request as ready for review September 25, 2026 10:26
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Refines pixel access detection for image subclasses.

Not ready to merge: the new trait comment and the previously reported subclass comments still violate a repository requirement.

Findings

  1. P2 Remove redundant trait comment ▶
  2. P2 Subclass pixel access lacks coverage ▶
  3. P2 Remove redundant subclass comments ▶
Summary

The PR enables direct pixel access for itk::Image subclasses and adds a buffer-range test that reads and writes subclass pixels. The new trait comment violates the repository’s prose requirement and must be addressed before merging.

Reviews (2) · Last reviewed commit: "ENH: Let Range classes do direct pixel a..."

Comment thread Modules/Core/Common/include/itkImageBufferRange.h Outdated
Comment thread Modules/Core/Common/test/itkImageBufferRangeGTest.cxx

namespace
{
// Minimal subclass of itk::Image, used in static_assert statements below here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Remove redundant subclass comments

This comment describes the class and assertions immediately below it; the counterpart in the region-range test does the same. Both violate the repository directive against in-source explanations of code already visible in the diff. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@greptile-apps

This comment has been minimized.

@N-Dekker
N-Dekker marked this pull request as draft September 25, 2026 11:20
@N-Dekker
N-Dekker force-pushed the Direct-pixel-access-derived-Image-type branch from f8db70d to b9ecfe3 Compare September 25, 2026 12:06
Until now, ImageBufferRange and ImageRegionRange would use a proxy to access
the data of a subclass of `itk::Image`. With this commit, they will do direct
pixel access instead, for those subclasses.

This commit may significantly improve the performance of iteration over the
pixels of an itk::Image subclass. Moreover, it will address the compile errors,
attempting to build OrfeoToolBox v10 against ITK 6.0 beta2, reported by Nicklas
Larsson at InsightSoftwareConsortium#6898 saying:

```
itkCastImageFilter.hxx:167:84: error: non-const lvalue reference to type 'itk::Vector<double, 2>' cannot bind to an initializer list temporary
  167 |     std::conditional_t<isVariableLengthVector, OutputPixelType, OutputPixelType &> outputPixel{ *outputIt };
      |                                                                                    ^          ~~~~~~~~~~~~~
```
@N-Dekker
N-Dekker force-pushed the Direct-pixel-access-derived-Image-type branch from b9ecfe3 to d4154b7 Compare September 25, 2026 12:15
@N-Dekker
N-Dekker marked this pull request as ready for review September 25, 2026 13:12
using InternalPixelType = typename TImage::InternalPixelType;
using AccessorFunctorType = typename TImage::AccessorFunctorType;

// Tells whether the specified template argument is a template specialization of itk::DefaultPixelAccessorFunctor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Remove redundant trait comment

The new comment restates what IsDefaultPixelAccessorFunctor expresses and exceeds the repository’s 100-character limit for in-source comments. It violates the requirement for short, useful comments rather than explanations already visible in the code. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't agree. I think the code should in general be human-readable without having to dive into commit history or discussions at GitHub. Where does the "100-character limit for in-source comments" come from? Such a limit does not make sense to me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You’re right that the comment can improve readability, and I overstated the rule as a general C++ style requirement. The 100-character limit comes from this PR’s AGENTS.md guidance, specifically Documentation/AI/prose-budget.md: it defines a one-line, ≤100-character budget for new in-source // comments. It is not a clang-format or general C++ requirement; .clang-format actually permits a 120-column limit.

That policy also says comments are appropriate when they preserve a non-obvious invariant. This comment explains the purpose of the trait, so retaining it is defensible; only its length exceeds that project-specific budget. A shorter version such as // Trait for the default pixel accessor functor. would preserve the explanation while complying. I’ll withdraw the request to remove the comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@hjmjohnson Can we please 🙏 drop the "100-character limit for in-source comments"? I see, it was introduced with your pull request #6241. But I believe it's A Good Thing to add in-source comments to explain non-obvious internal implementation details. It is no problem to me if they sometimes exceed 100 characters. However, it is a problem if contributors get discouraged when they add useful comments.

I don't think the explanation of essential parts of the internal implementation should just be hidden somewhere in the commit history.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AGENTS.md is a guidance for agents. It is useful for Greptile sometimes reminding us of this. A lot of the time, it is wrong, and can (and should) be simply disregarded. Clicking "Resolve conversation" accomplishes that.

Perhaps we should remove the 100 character limit for agents, and replace it by single-line limit, effectively deferring to clang-format 120-column limit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree. A single-line requirement is a clearer and more practical constraint here: it keeps comments readable and compatible with the repository’s 120-column formatting convention, while avoiding an arbitrary 100-character cutoff that can discourage useful explanations. The guidance could say that new // comments should fit on one line and follow the project’s formatting limit, rather than imposing a separate 100-character budget. For this comment, the existing explanation is reasonable and should not be treated as a defect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I proposed this change in #6906.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks — that addresses the concern. With the guidance change proposed in #6906, this comment is acceptable: it explains a non-obvious implementation detail and fits the project’s single-line formatting convention. I’m withdrawing the comment; no change is needed in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks but I still think the incentive is in the wrong direction. When proposing a useful comment, a guidance message from Greptile feels like a penalty, not a reward.

Anyway, do I understand correctly that contributors can avoid such AI generated guidance messages by using old-school C-style /* ... */ for comments that exceed 100 characters?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No—not as a recommended or intended workaround. If a checker only matched newly added // comments, a /* ... */ comment might technically evade that particular check, but that would be a loophole rather than a meaningful project convention.

The guidance should depend on readability and purpose, not comment syntax. This useful explanatory comment should simply be accepted. Under the proposed guidance from #6906, the relevant constraint is a readable single line within the project’s formatting limit—not an arbitrary 100-character penalty. I agree that Greptile should not frame a useful comment as a defect merely because it exceeds that old budget.

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good on a glance.

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:Enhancement Improvement of existing methods or implementation 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.

2 participants