Skip to content

BUG: Fix selected ImageProcessing numeric conversions and ranges - #1888

Open
jmarquisbq wants to merge 43 commits into
BlueQuartzSoftware:developfrom
jmarquisbq:fix/unsafe-numeric-conversions-1874
Open

jmarquisbq wants to merge 43 commits into
BlueQuartzSoftware:developfrom
jmarquisbq:fix/unsafe-numeric-conversions-1874

Conversation

@jmarquisbq

@jmarquisbq jmarquisbq commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Correct unsafe numeric conversions and range calculations in 18 NXImageProcessing filters. This is partial C15 coverage: 19 approved findings are addressed, and the remaining C15 work stays outside this increment. 125 files changed, +14,597 / −1,090 lines.

Reviewer manual verification required

Joey: please run the Windows package and GUI checks below before approving the coordinated release. Automated nxrunner checks do not verify GUI loading, parameter controls, rendering or save/reopen behavior. Use packages built from the three tested companion revisions. Earlier manual signoff predates the develop rebases and does not close these checks.

Use a matching package with the updated filter help installed for the help-view checks. The runtime smoke archives described below use documentation-disabled builds.

  • Start each fresh Windows package and confirm that plugins load without a missing-dependency dialog.
  • In the OOC-enabled package, open Preferences and repeat the three bookmarks below under Force In-Memory and Force Out-of-Core. Start a fresh pipeline for each run. Use packaged inputs and shipped parameters; change only file locations needed on the test machine.
Packaged bookmark What to inspect after GUI preflight and execution
16 Phase and Angle Field Transforms Inspect Tangent, Inverse Sine and Inverse Cosine. They retain floating values and continuous gradients, including fractional values. Confirm that the arrays can be selected and rendered.
08 Powder Particle Watershed Segmentation Inspect Particle Labels. Particle regions remain distinct and their boundaries align with the source image. Confirm that the final labels render correctly.
19 Serial-Section Stack Reconstruction Inspect Serial Sections/Cell Data/Section Intensity. Confirm dimensions 256 x 256 x 8, spacing (0.5, 0.5, 1.0) and section order 000 through 007. Check that all eight preview TIFF slices are readable.
  • Save each representative result, close it, reopen its .dream3d file and select/render its output arrays again. Confirm the expected OOC storage indication in Force Out-of-Core mode. A storage icon alone is not proof of physical backing-file identity.
  • Add fresh Otsu Multiple Thresholds and Write Image filters to a scratch pipeline. Inspect their controls, tooltips and help. Confirm that Nonfinite Input Handling defaults to Error, that Warn and Continue is selectable and explained, and that Use Mask Array enables its linked mask controls. In Otsu, also check Masked Label. In Write Image, enable Create Color Table to check its linked nonfinite control. Automated tests cover the numerical policies and error paths.

Record the package identity, storage mode, bookmark and result for each check. Attach a screenshot or saved result if a field, boundary or slice order differs. These manual checks remain open until the reviewer records the results.

Known inherited limitations are separate: Tutorial 17 negative-origin TIFF output and the later copper pole-figure tuple shapes are tracked by the linked follow-ups in the test plan. They are not counted as passing output validation.

Develop bases and companion merge order

All three branches target develop and use fix/unsafe-numeric-conversions-1874. Required APIs and storage accounting already exist in develop.

Use this order for the coordinated C15 release:

  1. Merge simplnx #1888 for the numeric contracts and example migrations.
  2. Merge SimplnxOoc #11 after the implementation. Its disk-backed tests require the new output types, parameters and policies.
  3. Merge DREAM3DNX #1233 last for the coordinated Windows package and acceptance checks.

The following develop bases and C15 revisions were validated together on 12 November 2026:

Repository Tested develop base Tested C15 revision
simplnx 4c2b55f6849152cc1d0bfe9939a8666b77eeae4b 5e080a8ec87b681ee35b7ee190b23bb5cf640b40
SimplnxOoc d6d4bccd0305b1500c61606f7412ab08e53a60ed 1692f37b57e81367a8a836c0cbca814ba85b4a66
DREAM3DNX d405b304793be178e3f504249dcbdb2c53af5461 2ad8cf5982d651cb33789c6455f19b833871286f

Review companion

Download the HTML review companion. Open review-companion.html locally for filter summaries, approved contracts, migration guidance and expandable decision details. Current revision and test status are recorded here.

1. Math output types and integer limits

  • src/Plugins/NXImageProcessing/src/NXImageProcessing/utils/MathOutputUtilities.hpp supplies the selected output conversions.
  • Integer Acos, Asin and Tan inputs produce Float32 output. Integer Exp, ExpNegative, Log, Log10 and Sqrt inputs produce Float64 output. Floating inputs retain their existing types.
  • Square widens smaller integer outputs exactly and checks 64-bit overflow before multiplication.
  • Filter help records the precision/storage choices and migration options. Preserved fractions and nonfinite values can change later thresholds and segmentation. Integer-only consumers can reject promoted arrays.

2. Morphology and smoothing

HConvex and HMinima preserve native integer Height arithmetic and reject fractional Height for integer images. HConvex checks signed contrast overflow. CurvatureFlow and SmoothingRecursiveGaussian check terminal integer conversions, report clipping and reject nonfinite integer results. Their help records working-precision limits.

3. Segmentation, export and pipeline compatibility

ConnectedComponent checks provisional label capacity. MorphologicalWatershedFromMarkers checks marker ID conversion. Both offer Error and Warn policies, with Error as the default. OtsuMultipleThresholds checks label capacity and adds an explicit nonfinite policy, optional Bool/UInt8 mask and collision-checked excluded label. Active masks of a nonnumeric array kind return a clear preflight error.

ThresholdMaximumConnectedComponents checks Upper Boundary conversion and range arithmetic, corrects the midpoint, and retains the two-intensity-unit stopping tolerance. Its masks and downstream segmentation can change because of the corrected midpoint. WriteImage checks nonfinite color inputs and masks before committing slices; raw floating export retains its existing behavior.

Shipped bookmarks, Python variants and generated help use the matching contracts and parameters. Consumer-chain tests check supported migration paths. Includes, generated-header references and test tags follow the NXImageProcessing plugin name.

Test plan

Final source and package verification — 12 November 2026

  • Both coordinated Windows Release ALL_BUILD builds passed. The final shipping builds have test hooks disabled and embed the tested source revision.
  • The affected Otsu, writer and consumer selections passed 99/99 in-memory Release, 118/118 OOC Release and 99/99 in-memory Debug, with no failures or skips.
  • After the final local-name-only correction, both Release aggregate builds passed again. The Otsu selection passed 31/31 in-memory Release, 35/35 OOC Release and 31/31 in-memory Debug, with no failures or skips.
  • The complete independent final closing review is clean at the revisions above, across all three repositories and all seven architecture/implementation lenses.
  • Changed C++ passes clang-format 19.1.1 with the owning repository styles.
  • Focused final-head clang-tidy covers 57 translation units and 24 changed headers, including all six new headers. It reports zero introduced diagnostics. The final correction was analyzed freshly; 56 other results were reused only after compiler, command, configuration and physical dependency inputs matched exactly.

Two focused Gaussian declaration reports were reproduced on pinned develop for the exact parameter pairs. Whole-TU configured analysis remains non-clean and exits 1; a whole-project zero-warning result is not claimed. One earlier LLVM tool crash was preserved, then completed in an identical-input isolated retry. No analysis coverage gap remains.

Fresh Windows archive and bookmark checks

  • Both fresh CPack ZIPs passed CRC, source/runtime identity and dependency-origin checks. Runtime smoke builds use Release with tests, Python and documentation targets disabled.
  • External serial CTest ran all 18 complete affected bookmark prefixes in each storage mode: 36/36 packaged nxrunner invocations passed. Shipped parameters and distributed inputs were preserved; only file locations and an appended diagnostic writer were supplied by the local fixture.
  • 30/36 output rows passed readability, type/shape/ownership and bounded scientific comparison against the previously approved C15 results, with no numeric tolerance. Six rows reproduced the known inherited output blockers unchanged: Tutorial 17 and both copper bookmarks in both modes. These six are not output PASS. There were zero new or worsened output failures.

Launch PATH and profiles were isolated to the package and Windows. Static runtime identities match the owning final builds and configured dependencies. Core module sampling was complete in 33/36 runs; no observed module came from outside the package or Windows. Sampling does not prove every transient DLL load. The package campaign does not establish a new physical backing-file witness or a clean-VM/GUI pass. Actual disk-backed store assertions remain part of the OOC unit coverage.

The comparison baseline retains 22 retired source-path references after the plugin-folder rename. Each replacement pipeline was checked against the exact approved hash; these are recorded historical provenance gaps, not new output failures. The bounded comparator establishes compatibility, not independent mathematical correctness.

Earlier develop-integration regression evidence

Before the final mechanical/diagnostic/preflight corrections, the paired set at public eff78a69975437cfe58e0c81b57668d20c2689d9 and the unchanged companion revisions passed:

Selection In-memory build OOC build
C15 filters, engines, cache checks and consumer chains 558/558 664/664
Core, AtomicFile, DataStructure, CLI and acceptance checks 287/287 295/295
Broad OOC regression selection — 1,131/1,131

These earlier selections overlap and are not recounted as fresh final-head tests. The numerical/storage contracts outside the final corrections are unchanged. In-memory validation uses algorithm path 0; OOC uses path 1. The broad selection excluded benchmarks and ITK-named entries; the C15 selections separately ran 35 ITK-named golden cases in each build. No new benchmarks or rebases were performed.

Pending CI and package checks

  • Supported-platform CI passes with the three reviewed C15 revisions selected together. Jobs that use only develop dependencies do not validate this coordinated set.
  • The fresh archives pass deployment smoke checks on a clean Windows VM or release runner.

Earlier package evidence — 5 November 2026

Earlier C15 archives passed 36/36 packaged nxrunner invocations across the 18 bookmarks and two modes. Output checks passed 30/36 rows. Six rows reproduced the inherited TIFF and copper pole-figure blockers below. A physical Serial-Section output witness matched all 524,288 stored UInt8 values to the saved result. Jessica Marquis reported the representative startup and GUI checks passed in both modes.

Those results belong to earlier revisions. The fresh automated archive/bookmark checks above supersede the older runtime smoke evidence. The physical store witness and manual GUI signoff remain historical; current reviewer manual checks are still open.

Known inherited output limitations remain documented separately: Tutorial 17 negative-origin TIFF output (follow-up) and the later pole-figure tuple shapes in TxCopper_Exposed/TxCopper_Unexposed (follow-up). No correction for those cases is included here.

Related Issue

The C15 inventory and deferred scope are documented in the HTML review companion. This is partial coverage; no C15 issue closure is requested.

Related to #1870

@jmarquisbq jmarquisbq self-assigned this Oct 27, 2026
@jmarquisbq
jmarquisbq force-pushed the fix/unsafe-numeric-conversions-1874 branch 2 times, most recently from decbffd to 549b553 Compare November 3, 2026 16:01
joeykleingers added a commit to joeykleingers/simplnx that referenced this pull request Nov 12, 2026
Replace the knowledge-base entry that let the user choose only how a
NaN input value is handled with one rule for NaN and both infinities,
decided by where the value comes from. It follows the handling in
BlueQuartzSoftware#1888:

- Parameters: preflight rejects NaN, and rejects infinity unless the
  filter documentation gives it a meaning. Values stored into a
  floating-point array may be NaN or infinity.
- Values read from a file: the reader rejects nonfinite values where
  the format requires finite ones.
- Input array values that reach a comparison, range, histogram,
  threshold, color map, search, index or integer conversion: a
  Nonfinite Input Handling choice, Error (default) or Warn and
  Continue.
- Element-wise floating-point math passes IEEE results through and
  documents them.
- A computed nonfinite value for an integer output is an error naming
  the index and output type; finite out-of-range values are clipped
  with a warning, instead of NaN becoming 0.
- An undefined result for degenerate input is a documented NaN.

Update the saturating-cast and parameter-validation entries to match.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
@jmarquisbq
jmarquisbq force-pushed the fix/unsafe-numeric-conversions-1874 branch from e23107c to eff78a6 Compare November 12, 2026 19:17
@jmarquisbq
jmarquisbq marked this pull request as ready for review November 12, 2026 23:51
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

imikejackson pushed a commit to joeykleingers/simplnx that referenced this pull request Nov 13, 2026
Replace the knowledge-base entry that let the user choose only how a
NaN input value is handled with one rule for NaN and both infinities,
decided by where the value comes from. It follows the handling in
BlueQuartzSoftware#1888:

- Parameters: preflight rejects NaN, and rejects infinity unless the
  filter documentation gives it a meaning. Values stored into a
  floating-point array may be NaN or infinity.
- Values read from a file: the reader rejects nonfinite values where
  the format requires finite ones.
- Input array values that reach a comparison, range, histogram,
  threshold, color map, search, index or integer conversion: a
  Nonfinite Input Handling choice, Error (default) or Warn and
  Continue.
- Element-wise floating-point math passes IEEE results through and
  documents them.
- A computed nonfinite value for an integer output is an error naming
  the index and output type; finite out-of-range values are clipped
  with a warning, instead of NaN becoming 0.
- An undefined result for degenerate input is a documented NaN.

Update the saturating-cast and parameter-validation entries to match.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
imikejackson added a commit that referenced this pull request Nov 13, 2026
…1947)

* BUG: Reject kernel radii that morphology filters cannot represent

Kernel Radius is a UInt32 vector that preflight never checked. Execute
narrowed each component to int32, so a radius of 2147483648 or more
became negative, the structuring element came out empty and the filter
copied its input (top-hats and the gradient wrote zeros). Large radii
also overflowed the element-count and Safe Border size arithmetic.

- Add ValidateKernelRadius() and MakeCheckedStructuringElement() to
  StructuringElement.hpp: each radius must be at most 2147483646 and
  the element count must fit the offset vector. Allocation failures are
  returned as errors.
- Add ValidateMorphologyLayout() to MorphologyEngine.hpp. It checks the
  Safe Border padded extents and the signed coordinate, plane, volume
  and byte counts derived from the image and the radius. Preflight and
  every execution entry point call it before allocating.
- Use the flat-offset fold only when its offsets and staged indices fit
  int64, and clamp the packed binary word end without overflow.
- Negative radii in MakeStructuringElement() return an empty element
  before any negation, and its loops and shell arithmetic use int64.

Fixed filters: BinaryDilateImageFilter, BinaryErodeImageFilter,
BinaryMorphologicalClosingImageFilter,
BinaryMorphologicalOpeningImageFilter,
BinaryOpeningByReconstructionImageFilter, BlackTopHatImageFilter,
ClosingByReconstructionImageFilter, DilateObjectMorphologyImageFilter,
ErodeObjectMorphologyImageFilter, GrayscaleDilateImageFilter,
GrayscaleErodeImageFilter, GrayscaleMorphologicalClosingImageFilter,
GrayscaleMorphologicalOpeningImageFilter,
MorphologicalGradientImageFilter, OpeningByReconstructionImageFilter,
WhiteTopHatImageFilter.

Part of #1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* DOC: Decide NaN and infinity handling by where the value comes from

Replace the knowledge-base entry that let the user choose only how a
NaN input value is handled with one rule for NaN and both infinities,
decided by where the value comes from. It follows the handling in
#1888:

- Parameters: preflight rejects NaN, and rejects infinity unless the
  filter documentation gives it a meaning. Values stored into a
  floating-point array may be NaN or infinity.
- Values read from a file: the reader rejects nonfinite values where
  the format requires finite ones.
- Input array values that reach a comparison, range, histogram,
  threshold, color map, search, index or integer conversion: a
  Nonfinite Input Handling choice, Error (default) or Warn and
  Continue.
- Element-wise floating-point math passes IEEE results through and
  documents them.
- A computed nonfinite value for an integer output is an error naming
  the index and output type; finite out-of-range values are clipped
  with a warning, instead of NaN becoming 0.
- An undefined result for degenerate input is a documented NaN.

Update the saturating-cast and parameter-validation entries to match.

Part of #1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* BUG: Clip adaptive histogram equalization neighbors to the image

The Radius of AdaptiveHistogramEqualizationImageFilter is a UInt32
vector, and every neighbor loop walked the whole -r..r box and skipped
the neighbors outside the image. A radius near UINT32_MAX made each
voxel run billions of empty iterations, so the filter did not finish.

Each of the four neighbor loops (the generic and lookup-table plane
bodies and the generic and lookup-table 2D block bodies) now computes
its bounds clipped to the image before it iterates. The skipped
iterations are exactly the ones that were skipped before, in the same
order, so the accumulated sum, the in-bounds count and every output
value are unchanged. The linear uint8 paths already bounded their
traversal and are unchanged.

Part of #1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* REV: Restore the nonfinite skip rule and clear new clang-tidy findings

- Coding knowledge base: Warn and Continue excludes nonfinite values
  from the contributing samples and counts of reductions and
  neighborhood operations. The nonfinite-handling rules apply to new
  filters and to filters a change already fixes; bringing an existing
  filter's output type or failure behavior in line is a breaking change
  that its pull request names.
- Adaptive histogram equalization: rename the signed coordinates xi
  and yi to signedX and signedY.
- Morphology and structuring-element guards: camelCase local
  constants, checked std::array access, a kernel parameter name in the
  two new layout helpers, an explicit int64 slice product and
  parentheses in the bounding-box extents.

No behavior change.

* REV: Check kernel radii only in preflight

Filter preflight is the one place a filter's inputs are checked; the
shared morphology helpers do not repeat those checks.

- MakeCheckedStructuringElement() and ValidateMorphologyLayout() no
  longer re-run ValidateKernelRadius(); they document a validated radius
  as a precondition. The structuring element still converts allocation
  failures to an error, and the layout checks on the final geometry
  dimensions still run in preflight and execute.
- The kernel-radius tests also execute each filter with an invalid
  radius and check that it fails with the preflight code, creates no
  output and leaves the input unchanged. The test that called the
  helper directly with an invalid radius is removed.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>

* TEST: Use the NXImageProcessing plugin names after the rebase

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>

---------

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Co-authored-by: Michael Jackson <mike.jackson@bluequartz.net>
@jmarquisbq
jmarquisbq requested review from imikejackson and joeykleingers and removed request for imikejackson and joeykleingers November 13, 2026 16:38
return ConvertInvalidResult<OtsuHistogramResult>(std::move(rangeResult));
}
}
histogram.counts.front() += result.NaNCount + result.NegativeInfinityCount;

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.

[High] Otsu "Warn and Continue" keeps NaN/±inf in the histogram, which breaks the KB NaN-handling rule

histogram.counts.front() += NaNCount + NegativeInfinityCount; histogram.counts.back() += PositiveInfinityCount; puts every nonfinite sample in the endpoint bins. These counts then drive the class means and variances, so they move the fitted thresholds. The docs example confirms it: [0,0,4,4,NaN,-inf,+inf] gives counts [4,3] instead of [2,2].

The KB entry Let the user choose whether a NaN input value is an error or is skipped is binding: in Warning mode, "a reduction ... leaves the value out; a decision gives the NaN element a defined output." A histogram is one of the reductions the entry names. As written, an image with a few NaN pixels gets different thresholds, and so different phase fractions downstream, with only a generic warning.

Fix: in Warn mode, exclude nonfinite samples from counts (they are already left out of min/max). Give them one documented label, for example the lowest class or the Masked Label, and report the skipped count. Update OtsuMultipleThresholdsImageFilter.md, the parameter help and the Warn tests. If endpoint-bin participation was deliberately approved, amend the KB entry in this PR.

}
if(!warnOnNonfinite && (summary.NaNCount != 0 || summary.NegativeInfinityCount != 0 || summary.PositiveInfinityCount != 0))
{
return ConvertResultTo(MergeResults(std::move(status), MakeErrorResult(-28611, "Threshold Maximum Connected Components found image NaN or infinity during the initial scan. Select Warn and "

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.

[Low] The nonfinite Error messages don't name the array or tuple (Otsu -28654, TMCC -28611)

The KB NaN rule requires the Error message to name the array and the tuple, and to say which option skips the value. -28611 here and -28654 at OtsuImageEngine.hpp:444 name neither the input array nor the first offending tuple. WriteImage -27027 already does this correctly.

Fix: pass the input DataPath into the scan, record the first nonfinite flat index (as CurvatureFlowConversionState::recordNonFinite does), and format "Array 'X' has NaN at tuple N. Select ... to ...".

params.insert(
std::make_unique<BoolParameter>(k_ReturnBinMidpoint_Key, "ReturnBinMidpoint", "Should the threshold value be mid-point of the bin or the maximum? Default is to return bin maximum.", false));
params.insert(std::make_unique<ChoicesParameter>(
k_NonfiniteInputHandling_Key, "Nonfinite Input Handling",

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.

[Low] The new choices don't use the KB name "NaN Value Handling" / Error / Warning

The KB says the parameter is NaN Value Handling with the choices Error and Warning. Otsu (here), TMCC (ThresholdMaximumConnectedComponentsImageFilter.cpp:67) and WriteImage (WriteImageFilter.cpp:117) add "Nonfinite Input Handling" with "Error" / "Warn and Continue" instead. Users now see two names for the same concept.

Fix: use the KB name and labels. If the broader ±inf scope is intended, update the KB entry in the same PR so later filters follow one convention.

.NumberOfThresholds = filterArgs.value<uint8>(k_NumberOfThresholds_Key),
.LabelOffset = filterArgs.value<uint8>(k_LabelOffset_Key),
.MaskedLabel = filterArgs.value<uint8>(k_MaskedLabel_Key),
.WarnOnNonfinite = filterArgs.value<ChoicesParameter::ValueType>(k_NonfiniteInputHandling_Key) == 1,

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.

[Low] Choice values are compared with raw indexes (== 1, policy == 0)

This breaks the KB rule Compare a choice with its named value. The raw comparisons are here, at ThresholdMaximumConnectedComponentsImageFilter.cpp:129 (== 1) and at WriteImageColorUtilities.hpp:171 (policy == 0). WriteImageInputValues::NonfiniteInputHandling is stored as a raw uint64. If someone reorders the choices, Warn silently becomes Error, or the reverse.

Fix: add an enum (Error = 0, Warn = 1), store it in the InputValues, and compare with to_underlying(...), as ConnectedComponentLabelLimitHandling and MarkerIdConversionHandling already do.

if(lastLabel > 255)
{
return {.outputActions =
MakeErrorResult<OutputActions>(-8312, fmt::format("Label Offset ({}) plus Number Of Thresholds ({}) exceeds 255. Reduce either value to keep every class label within uint8.",

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.

[Low] Preflight and the engine each check the same conditions, with different codes and messages

For the same condition, the Otsu label interval is -8312/-8313 in preflight but -28603 in ApplyOtsuImage. The mask tuple count is -8314 in preflight but -8329 in ComputeOtsuHistogram. The TMCC NaN Upper Boundary check is the literal -28610 written twice (ThresholdMaximumConnectedComponentsImageFilter.cpp:98 and ThresholdMaximumConnectedComponentsEngine.hpp:473).

The KB rules Make every algorithm callable without its filter (write each check once in a static ValidateInputs() called from both places) and Give every condition its own error code (use the same named constant for the same condition) apply.

Fix: add ValidateOtsuInputs and ValidateThresholdMaxCCInputs next to the engines with named code constants, and call them from preflight and the engine entry.

return {};
}

class CurvatureFlowConversionState

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.

[Low] Shared engines gain filter-specific opt-in flags, and the default path still drops warnings

CheckedOutput and CheckedSmoothing are threaded through dozens of functions, so the FiniteDifference and RecursiveGaussian engines each have two contracts. The generic engine also carries CurvatureFlow-named state, codes and messages. The unchecked path keeps static_cast<T> and deliberately discards transfer warnings: MergeRecursiveGaussianResults at RecursiveGaussianEngine.hpp:73 returns Result<>{} on success. Sibling filters therefore still break Never drop a Result.

Fix: rename the state and codes generically (for example TerminalConversionState). File a follow-up issue to remove the unchecked branch so every caller keeps its warnings.


The filter does not allocate a complete RGB volume. It still requires a complete selected 2D RGB slice. A scale bar can require a second padded slice and a separate band. The image codec can allocate more memory for that slice. The source-buffer reservation is not a limit on total process memory.

Cancellation can leave slices that were committed earlier. Execution errors and warnings are returned through the filter result. The shared filter wrapper can replace a valid execution result with cancellation and lose its execution warnings; this inherited limit does not change the initial nonfinite-error file-preservation guarantee.

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.

[Low] User docs describe framework internals and are hard to read

Sentences such as "The shared filter wrapper can replace a valid execution result with cancellation and lose its execution warnings" describe a framework limitation, not filter behaviour. The same appears in MorphologicalWatershedFromMarkersImageFilter.md:54 and SmoothingRecursiveGaussianImageFilter.md:53. Long run-on paragraphs, for example in ConnectedComponentImageFilter.md:24, fail the plain-language documentation check for non-native English readers.

Fix: remove the framework-internals sentences and file the cancellation-wrapper issue instead. Reduce each new section to short statements: what each choice does, the default, and what changes for old pipelines.

The score counts connected components of the would-be **nonzero output**, including components whose size is exactly **Minimum Object Size In Pixels**. This parameter is a pixel/voxel count and defaults to *0*. It changes the search score; it does not remove small objects from the final output.

The input array must be single-component (scalar) and may be **any scalar type** (integer or floating point). The output is a fixed **uint8** binary image (**Inside Value** / **Outside Value**) regardless of the input element type. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Threshold Maximum Connected Components Image Filter, and matches it exactly (byte-identical binary output).
**Inside Value** defaults to *1* and **Outside Value** defaults to *0*. Both are dimensionless uint8 values. With these defaults, the score counts in-band regions. Inside0/Outside1 scores the complement. If both values are nonzero, all pixels participate as foreground. If both are zero, none participate. A nonzero Outside Value can connect regions that would otherwise be separate.

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.

[Nit] Missing spaces before numbers ("Inside0/Outside1", "threshold0", "midpoint101")

Lines 17, 19, 39 and 43 read "Inside0/Outside1", "selects threshold0", "Outside0" and "starting threshold1 ... midpoint101". The italic markers appear to have been lost. Replace with "Inside 0 / Outside 1", "threshold 0", "Outside 0", "threshold 1" and "midpoint 101".

DataPath imageGeometryPath;
DataPath imageDataArrayPath;
bool createColorTable = false;
uint64 NonfiniteInputHandling = 0;

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.

[Nit] Mixed member naming inside one struct

NonfiniteInputHandling sits among camelCase members (createColorTable, presetName). Likewise, ExactIntegerHeight, LabelLimitHandling and ConversionHandling sit next to camelCase differenceFromInput and shouldCancel in the ImageProcessingFilterUtilities.hpp execute functors. Match each struct's existing style.

if(histogram.binWidth == 0.0 && histogram.min == histogram.max)
{
Result<std::vector<float64>> result;
result.m_Expected = std::vector<float64>(options.NumberOfThresholds, histogram.min);

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.

[Nit] Results built by assigning m_Expected directly

result.m_Expected = ... here and at HistogramEngine.hpp:688 and ConnectedComponentEngine.hpp:490,1689 bypasses the Result API. Construct the value instead, for example return Result<std::vector<float64>>{std::move(value)};, as the replaced code did with Result<uint32>{numComponents}.

@joeykleingers
joeykleingers self-requested a review November 13, 2026 20:47
Return float32 for integer input so fractional radians and NaN can
be stored. Retain floating input types and array shapes.

Document the type change and downstream effects. Add independent
numeric checks and coverage for disk-backed arrays.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Return float32 for integer input so fractional radians and NaN can
be stored. Retain floating input types and array shapes.

Document the precision, storage and downstream effects. Add independent
principal-angle checks and tests for multi-component arrays.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use float64 output for integer input and preserve existing floating types.
Handle float32 overflow before narrowing and document storage, precision,
underflow and downstream mask changes. Add independent boundary and shape
checks. Paired Release builds and 16 in-core / 20 disk-configuration cases pass.
Configured clang-tidy remains nonpassing on existing/shared diagnostics;
source review and clang-format 19.1.1 checks pass.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use float64 output for integer input and retain existing floating types.
Convert before negation and handle float32 overflow explicitly. Document
precision, storage, underflow and downstream mask changes. Paired Release
builds and 15 in-core / 20 disk-configuration tests pass. Source review and
clang-format 19.1.1 pass; configured static checks retain existing diagnostics.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Produce float64 for integer inputs while preserving floating input types.
Keep IEEE domain outcomes and document precision, storage and downstream
changes. Add independent logarithm identities, native limits, floating
boundaries and shape tests. Paired Release builds and 15 in-core / 17
disk-configuration cases pass. Source review and clang-format pass;
configured static checks retain documented existing and oracle diagnostics.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Document the existing 64 MiB scratch target and minimum complete storage
slab. A slab can exceed the target or contain the full array. The filter
adds no separate full-volume calculation buffer. Numeric code and tests
are unchanged; source review verified the statement against the engine.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Document the existing 64 MiB scratch target and minimum complete storage
slab. A slab can exceed the target or contain the full array. The filter
adds no separate full-volume calculation buffer. Numeric code and tests
are unchanged; source review verified the statement against the engine.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Document the existing 64 MiB scratch target and minimum complete storage
slab. A slab can exceed the target or contain the full array. The filter
adds no separate full-volume calculation buffer. Numeric code and tests
are unchanged; source review verified the statement against the engine.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Default to an execution error before creating an ID above UINT32_MAX. Offer explicit legacy continuation with one immediate and retained warning while preserving uint32 labels, strict shared counting and existing allocation fallback.

Check all creation sites and warning lifetime. Cover native boundary decisions, small zero/reuse models, exact label maps and failure paths; document migration, memory costs and unreliable legacy output.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Add Error and legacy warning choices before marker flooding. Preserve exact native diagnostics, marker output types, bounded copy routes and delivered phase warnings. Add independent native seed, transfer-failure and disk-route checks, and document migration and downstream effects.

Validated paired full Windows Release builds, 28 InCore and 33 OOC cases, plus 17/19 related watershed checks. Source review and clang-format 19.1.1 pass. Configured clang-tidy remains nonpassing; existing/framework diagnostics and four nonblocking style findings are recorded for final review. Debug and cross-platform checks were not run.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Add Error and Warn nonfinite handling, linked bool/uint8 masking, distinct excluded labels and checked uint8 class intervals. Preserve selected nonfinite endpoint frequencies, ordinary finite solver behavior and native output labels. Guard unusable geometry and objective arithmetic, retain bounded parallel range scans and document migration and downstream effects.

Validated full paired Windows Release builds, 29 InCore and 33 OOC cases plus 9 HistogramEngine controls in each. Independent literal and rational expectations include the demonstrated first-centroid regression. Source review and clang-format 19.1.1 pass. Configured clang-tidy remains nonpassing with documented framework and style diagnostics. Debug, cross-platform, installed SDK and universal scientific validation are not claimed.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Add linked Error and Warn choices for unmasked nonfinite color-table input. Validate the global range before committing any slice, preserve masked finite range values and raw writing, and use writer-scoped native-distance and scaled floating normalization. Document first-color fallback, migration, precision and per-slice failure limits.

Validated paired full Windows Release builds and 58 InCore/62 OOC cases. Independent decoded RGB, native/subnormal interiors, raw floating files, slice layouts, all-slice sentinel preservation, I/O failures and real disk/mixed backing pass. Source review and clang-format 19.1.1 pass. Configured clang-tidy remains nonpassing with documented existing/framework and lexical diagnostics; Debug, cross-platform and measured peak memory are not claimed.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use native safe midpoints and spans, clamp upper controls before conversion, and add one explicit Error/Warn image policy. Preserve the two-unit stop, strict component counting and existing scoring. Define empty/no-finite fallbacks and rounded-state warnings, retain bounded parallel scans and document segmentation migration.

Validated paired full Windows Release builds, 40 InCore/48 OOC owning cases and 42/54 related controls. Independent native masks, actual disk/tile/3-D routes and failures pass. The float real-image regression actively retains legacy and corrected literal references; separate face-connected flood fill isolates the approved seed correction and 159 changed pixels. Source/fix review and clang-format 19.1.1 pass. Configured clang-tidy remains nonpassing; Debug, cross-platform, installed SDK and universal scientific proof are not claimed.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Describe the public cancellation limit on smoothing warnings and qualify
Otsu label compatibility when numeric checks reject a finite calculation.

Validation: source-aligned scoped review and documentation checks passed.
The unchanged numeric code passed paired full Release builds and all
ImageProcessing cases: 1445 InCore and 1651 OOC.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Document template and parameter roles, output state, threshold caller
preconditions, cancellation results and existing numerical rationale.
Executable C++ tokens and API signatures are unchanged.

Validation: exact clang-format 19.1.1, lexical token comparison and
independent local review passed. New and changed comment blocks have no
audit findings; unchanged older comments remain outside this correction.
The unchanged numerical code passed 516 InCore and 611 OOC test cases.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Add the new policy and mask parameters to the affected pipeline files.
Keep the approved Error defaults and disabled Otsu masking. Update the
matching examples and sidecars without changing scientific settings.

The strict prebuilt parameter-key test passes in both configurations.
Semantic and syntax checks pass for all 42 changed artifacts.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Accept zero or the positive bounded Float64 subnormal at the selected
underflow arguments. Retain the ordinary and Float32 assertions.

Validated the paired Release and targeted Debug selections.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use vectors for newly introduced non-Boolean buffers. Keep contiguous
Boolean buffers and document the exception. Preserve capacity, grants,
transfer order and result propagation.

Validated the paired Release ownership families and targeted Debug cases.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Run nine small producer-consumer cases with literal typed results.
Cover segmentation, persistence, export, morphology, edges and labels.
Require dispatch counters only from filters that expose them.

Validated all nine cases in Release and in the targeted Debug selection.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Give required scan batches priority and admit the optional ring only
from remaining charged capacity. Keep batched fallback and exact bins.

Reproduced the exact-grant one-value read regression. Paired Release
and targeted Debug tests passed with the correction.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Forward each reached row result in the checked X-tile route. Keep the
prior warnings on a later transfer error and the existing cancellation
boundaries.

Reproduced dropped row warnings, then passed the paired Release and
targeted Debug cases.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use a sized UInt8 mask page and document contiguous Boolean ownership.
Keep the page limit and image-write behavior. Paired writer cases passed.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Move the eight new errors away from existing OrientationAnalysis codes.
Update the exact assertions without changing validation or policy.
Paired owning tests passed.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Read a range-scan mask only for floating nonfinite classification.
Use the selected mask for both writers' slice reads. The regression
checks the mask transfer counts and decoded pixels in both algorithms.

Paired Release and targeted Debug checks passed.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Give output and outer failures unique diagnostic IDs. Keep scan IDs,
messages, partial-output behavior and collected warnings. Exercise the
outer catches through the existing late info callback.

Paired Release and targeted Debug checks passed.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
A rounded-up limit can equal the high endpoint even when the
unscaled width rounds to infinity. Use the existing scaled ratio
at equality and assert the decoded midpoint in both writers.

Reproduced the two decoded failures and passed paired Release
and targeted Debug checks.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Describe the Float64 output that the test already asserts. The
renamed case passes with 26 assertions in both Release and Debug
on the in-core and OOC configurations.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use named arguments and bounded views in numeric helpers. Keep the existing overwrite allocations. Limit test macro annotations to the two checks triggered by assertion expansion.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Update plugin includes and test labels after the plugin rename.
Keep the core utility namespace and numeric contracts unchanged.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Use the required helper namespace and C++20 ranges calls. Keep
palette arguments distinct and make index grouping explicit.

Record the existing contiguous-bool-buffer and namespace exceptions
at the lines that require them. Preserve numeric and storage behavior.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Check the active mask array kind before typed access. Return a clear
error for unsupported array kinds and preserve disabled-mask behavior.
Cover active and inactive StringArray masks with a preflight regression.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Include slice extents and the index limit in color-size errors. Keep
the existing guards and codes. Check the reported values and recovery
advice without allocating an oversized image.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Describe the supported numeric image input types. Keep the existing
Boolean mask guidance.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
Keep the error code and behavior unchanged.

Signed-off-by: Jessica Marquis <jessica.marquis@bluequartz.net>
@imikejackson
imikejackson force-pushed the fix/unsafe-numeric-conversions-1874 branch from 5e080a8 to 4652ca7 Compare November 13, 2026 21:14
@imikejackson

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

3 participants