8000 Add QuerySubBlockDirectory command by ptahmose · Pull Request #20 · ptahmose/MEXlibCZI · GitHub
[go: up one dir, main page]

Skip to content

Add QuerySubBlockDirectory command - #20

Merged
ptahmose merged 12 commits into
masterfrom
jbl/QuerySubBlockDirectory
Oct 21, 2026
Merged

ptahmose merged 12 commits into
masterfrom
jbl/QuerySubBlockDirectory

Conversation

@ptahmose
@ptahmose ptahmose commented Oct 20, 2026 •
Copy link
Copy Markdown
Owner

Addresses #18.

Adds a new command QuerySubBlockDirectory(handle, [filter]) which returns information about the subblocks in the subblock directory without reading any subblock data. This allows e.g. reconstructing the dimensional order of a file and loading bitmaps on demand using the returned Index.

Filter (optional struct): Coordinate (struct: dimension letter -> set of values), Roi ([x y w h]), OnlyLayer0.

Result: a 1x1 struct of arrays (there may be millions of subblocks): Index, Mode, Pixeltype (numeric enum codes, documented), CoordinateDimensions (shared string, e.g. 'ZCT'), Coordinate (N x D int32), LogicalRect, PhysicalSize, MIndex. Missing dimensions / invalid M-index are intmin('int32'). No ordering is guaranteed.

Notes:

  • Docs added to doc/commands.markdown; MATLAB and Octave tests added.
  • Unknown filter fields are silently ignored, as the app API cannot enumerate struct field names.

ptahmose and others added 3 commits October 20, 2026 10:43
Returns information about all (or a filtered subset of) subblocks as a
struct of arrays, without reading the subblocks from the file. Filter
supports coordinate sets, ROI and pyramid-layer-0.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI left a comment
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.

🟡 Changes recommended

Filter parsing permits unsafe sparse-array reads and incorrect uint32 results, and CI does not execute the new Octave tests.

3 open issues
What changed in this PR

Adds QuerySubBlockDirectory to inspect CZI subblock metadata without reading image data, supporting image-order reconstruction and on-demand loading.

Changes:

  • Adds filtered directory queries returning a struct of arrays.
  • Documents the command and adds MATLAB/Octave tests.
  • Registers the command and increments the minor version.
File Description
tests/​octave/​test_querysubblockdirectory.m Adds Octave query tests.
tests/​MATLAB/​TestMEXlib_QuerySubBlockDirectory.m Adds MATLAB query tests.
lib/​src/​mexFunctions.cpp Registers the command.
lib/​src/​implementation/​CziReader.h Declares query and filter interfaces.
lib/​src/​implementation/​CziReader.cpp Implements filtering and result construction.
lib/​src/​functions/​func_querysubblockdirectory.h Declares command handlers.
lib/​src/​functions/​func_querysubblockdirectory.cpp Parses arguments and executes queries.
lib/​CMakeLists.txt Includes new command sources.
doc/​commands.markdown Documents filters, results, and examples.
CMakeLists.txt Increments the minor version.

Review effort: Balanced

…xing, run Octave test in CI

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI left a comment
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.

🔵 Needs a closer look

Input validation still permits sparse-buffer misreads and silently rounds fractional coordinate filters.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

Medium severity Reject nonintegral floating-point coordinates

lib/​src/​functions/​func_querysubblockdirectory.cpp:48

TryGetInt32 rounds floating-point inputs with lrint/lrintf rather than checking integrality (argsutils.cpp:152–175). Consequently, Coordinate.C = 0.6 silently selects channel 1, although 1 is not in the supplied set. Reject floating-point elements that differ from their converted integer values, and add regression tests for fractional double and single coordinates.

Medium severity Reject sparse and nonscalar inputs in OnlyLayer0

lib/​src/​functions/​func_querysubblockdirectory.cpp:71

OnlyLayer0 accepts arrays even though it requires a scalar, and neither branch rejects sparse storage before reading element zero. For example, sparse([0 1]) reads the stored 1 rather than the leading zero, silently enabling layer-0 filtering. An all-zero sparse input has no stored element to interpret this way. Require exactly one element and reject sparse inputs before either typed getter. Add regression tests for sparse and nonscalar values.

Medium severity Reject sparse handles before integer conversion

lib/​src/​functions/​func_querysubblockdirectory.cpp:108

Sparse double handles pass this check, but Execute calls TryGetInt32, which reads the first stored value without accounting for sparse indices (argsutils.cpp:29–39). A sparse array with a leading zero can therefore be interpreted as a different handle, while an all-zero sparse input has no stored element to read. Reject sparse handles before conversion and add a regression test.

3 resolved since last review

Review effort: Balanced

…scalar inputs)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI left a comment
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.

🟡 Changes recommended

Filter validation and large coordinate-set lookup costs remain unresolved.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Out-of-range values are incorrectly accepted as int32

lib/​src/​functions/​func_querysubblockdirectory.cpp:34

single(2147483648) passes this integral check, and the indexed TryGetInt32 also accepts it because its float upper bound rounds INT_MAX up to 2147483648 (argsutils.cpp:170). The value cannot be represented in int32, so a coordinate filter or ROI origin can change instead of being rejected. Check the bounds in double precision before conversion, and add regression tests for this boundary in both MATLAB and Octave.

Medium severity Coordinate lookups are quadratic due to repeated linear scans

lib/​src/​implementation/​CziReader.cpp:668

Each coordinate-set lookup scans the entire vector, and this predicate runs in both directory passes. With 100,000 subblocks at distinct T coordinates and Coordinate.T = 0:99999, the query performs about 10 billion comparisons despite reading no image data. Please pre-index each filter set once (for example, sort it during parsing and use binary search here) so large coordinate selections do not make this directory-only query quadratic.

Review effort: Balanced

ptahmose and others added 2 commit 8000 s October 20, 2026 14:39
…range-check ints

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… filled

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI left a comment
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.

🔵 Needs a closer look

Native libCZI integration and MATLAB/Octave runtime behavior still need human validation.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Use dimension bounds that ignore missing coordinates, derive output dimensions from reader statistics, and streamline two-pass result construction while preserving ROI and layer filtering.
Reflect ZCT dimensions, sentinel values for missing coordinates, and filtering behavior for absent dimensions.
Update QuerySubBlockDirectory tests to verify:
- Full ZCT coordinate dimensions
- Missing dimensions represented by intmin
- Matching subblocks with absent queried dimensions
- Correct empty-result coordinate shapes
Copilot AI left a comment
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.

🟡 Changes recommended

Coordinate interval overflow and zero-sized ROI handling can produce incorrect query results.

3 open issues

Review effort: Balanced

Comment thread lib/src/implementation/CziReader.cpp Resolved
Comment thread doc/commands.markdown Resolved
ptahmose and others added 2 commits October 21, 2026 19:14
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Updated the description of 'CoordinateDimensions' to clarify its independence from the filter and subblock matching.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@ptahmose
ptahmose marked this pull request as ready for review October 21, 2026 17:24
@ptahmose
ptahmose merged commit e48da5b into master Oct 21, 2026
4 checks passed
@ptahmose
ptahmose deleted the jbl/QuerySubBlockDirectory branch October 21, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0