Skip to content

BUG: Validate sampling, resampling and geometry count values - #1964

Draft
joeykleingers wants to merge 11 commits into
BlueQuartzSoftware:developfrom
joeykleingers:bug/c14-sampling-resampling
Draft

joeykleingers wants to merge 11 commits into
BlueQuartzSoftware:developfrom
joeykleingers:bug/c14-sampling-resampling

Conversation

@joeykleingers

@joeykleingers joeykleingers commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Sampling, resampling, scan-path and geometry-creation filters now reject spacing, resolution, sigma, origin, angle, count and dimension values outside their domain, instead of looping forever, dividing by zero, converting NaN or infinite values to integers, or wrapping signed counts to huge unsigned sizes. Values that a user types are checked by the parameter itself: NumberParameter and VectorParameter take optional bounds, and every floating-point number and vector parameter rejects NaN and infinity. Values that depend on the final geometry (resampled layouts, hull grids, edge sample counts, partition indices, interpolation kernels) are checked when the filter executes. NaN and infinity in input data (array values and input geometry metadata) pass through; a filter checks them only where they would reach undefined behavior. 105 files changed, +6430 / −592 lines.

1. Parameter bounds

  • src/simplnx/Parameters/NumberBounds.hpp — NumberBounds<T>: optional inclusive or exclusive lower and upper limits, presets Positive(), NonNegative(), GreaterThan(), AtLeast(), LessThan(), AtMost(), Between()
  • src/simplnx/Parameters/NumberParameter.{hpp,cpp}, VectorParameter.{hpp,cpp} — store the bounds and check them in validate(); a vector bound applies to every component
  • test/DynamicFilterInstantiationTest.cpp — the bounds, and a check that every filter's default values satisfy its own parameters

IFilter::preflight() already validates every active parameter before preflightImpl() and skips parameters that a linked option turns off, so the GUI, nxrunner and Python all get these checks. The parameter layer has its own codes: -86200 (NaN or infinity), -86201 (below the lower limit) and -86202 (above the upper limit). Each message names the parameter by its on-screen name and gives the value.

Every floating-point NumberParameter and VectorParameter in every filter rejects NaN and infinity by default, also without bounds. A parameter can allow them with setAllowNonFinite(true); no filter needs that today. Parameter UUIDs and the JSON format of the values do not change. The bounds are not yet shown in the DREAM3D-NX parameter widgets or the generated parameter tables.

2. Spatial sampling and resampling values

  • src/simplnx/Utilities/ImageProcessing/ImageGeometryResample.{hpp,cpp} — ComputeResampledImageLayout() and the checked resampling axis maps
  • src/Plugins/SimplnxCore/src/SimplnxCore/Filters/*Filter.cpp — parameter bounds and the remaining preflight checks
  • test/ImageGeometryResampleTest.cpp — tests for the shared resampling code

Bounds on the parameters:

  • Create AM Scan Paths: Hatch Spacing > 0.
  • Point Sample Edge Geometry: Sampling Spacing > 0.
  • Resample Data: New Spacing and Scale Factor > 0.
  • Approximate Point Cloud Hull: Grid Resolution > 0; Minimum Number of Empty Neighbors at most 26.
  • Uncertain Regular Grid Sample Surface Mesh: Spacing > 0.
  • Regular Grid Sample Surface Mesh: Spacing > 0.
  • Interpolate Point Cloud To Regular Grid: Kernel Size ≥ 0; Gaussian Sigmas 0.001 through 1000.

The finite requirement covers the angles, origins, uncertainty, sphere and Custom Z Value of these filters. Compute Coordinate Threshold keeps its preflight check that the sphere radius is greater than 0, because a vector bound applies to every component.

Resampled spacing, dimensions and tuple products, the hull's voxel bounds and grid product, and each edge's sample count depend on the final geometry. Preflight warns and uses unit placeholder dimensions and spacing when the current geometry gives a layout that cannot be represented; execution recomputes the layout from the final metadata and returns an error before converting or allocating. The hull check covers the grid with its one-voxel empty border, which is added in integer arithmetic so that it is kept for voxel indices beyond 2^53.

Create AM Scan Paths counts its hatch lines as integers instead of adding Hatch Spacing to a float32 position, so a spacing too small to move the position stops with an error instead of looping forever.

3. Geometry and sampling counts

  • src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/PartitionGeometry*.cpp — final-grid checks and the checked coordinate-to-partition conversion
  • src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/InterpolatePointCloudToRegularGrid.{hpp,cpp} — ComputeKernelLayout()

Bounds on the parameters:

  • Partition Geometry: Number Of Cells Per Axis at least 1 (it was cast to usize before the <= 0 check, so negative values passed); Cell Length > 0; Starting Feature ID ≥ 0. Preflight also rejects partition products that overflow and partition IDs that do not fit int32.
  • Create Geometry (Image) and Create Image Geometry: Dimensions at least 1, Spacing > 0. Preflight rejects dimension products that overflow.
  • Resample Data (Exact Dimensions) and Resample Rect Grid To Image Geom (Dimensions): at least 1.
  • Feature Face Curvature: Neighborhood Ring Count at least 1.
  • Point Sample Triangle Geometry: Number of Sample Points ≥ 0. Zero returns an empty vertex geometry without drawing samples.

Checked during execution: an existing partition grid's spacing, product and ID range; each coordinate-to-partition-index conversion; and the interpolation kernel's radius, size and storage, from the final spacing. Preflight warns when the current spacing gives a kernel that cannot be represented.

4. Read Image Stack resampling

  • src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp

Scaling is at least 1 percent and Exact 2D Dimensions at least 1, through parameter bounds that apply only to the selected resampling option. In Exact 2D Dimensions mode, the output X and Y dimensions are the given values. The X/Y layout is planned from one slice, and the stack product is checked before reading the slices. Exact 2D Dimensions is no longer read when another mode is selected.

5. NaN and infinity in input data

  • docs/Coding_Knowledge_Base.md — "Decide NaN and infinity handling by where the value comes from"
  • src/simplnx/DataStructure/Geometry/INodeGeometry0D.cpp — isPlane()

Array values, file values and the origin, spacing, bounds and coordinates of an input geometry are not rejected for being NaN or infinite. A filter checks them only where they would reach undefined behavior: an integer conversion, an index, size, count or loop bound, an ordering, or a float32 narrowing.

  • Partition Geometry: a point outside the partition grid gets the outside ID, also when the grid origin is infinite. A point inside the grid whose cell conversion is NaN or out of range fails with -86215. With +inf spacing every point is in the first cell. The Direct algorithm uses the real axis offsets and checks actual tuples when an axis map cannot be proven safe; rectilinear bounds are read in blocks of 4096.
  • Resampling (Resample Data, Read Images [3D Stack]): a destination cell outside the source on any axis is filled with zeros. -86137 is returned only when a cell inside the source on the other axes needs an unsafe conversion, for example a source and destination that share an infinite origin.
  • Interpolate Point Cloud To Regular Grid: each vertex's cell conversion is checked after the mask and bounds checks (-86251), instead of calling ImageGeom::getIndex(), whose comparisons NaN passes.
  • Approximate Point Cloud Hull: each vertex's voxel is checked before its int64 conversion (-86248). A NaN vertex never wins the extent comparisons, so the extent check alone did not catch it.
  • Create AM Scan Paths: the first and each reconstructed hatch position are checked before narrowing to float32 (-86249, -86250); intersections are sorted with NaN after every number.
  • INodeGeometry0D::isPlane() compares every coordinate with the first instead of inserting the coordinates into a std::set<float32>, which is undefined with NaN.

Finite spacing at or below 0 is still an error, with each filter's existing code (for example -86136 and -86212).

The knowledge base entry now says: typed number and vector parameters reject NaN and infinity; input data passes through; a filter guards only the undefined-behavior points above. For an ordering it uses NaN after every number, and for deduplication NaN is equal only to NaN.

Preflight is the one place for checks on the values a user types. The algorithms state the properties they rely on as @pre conditions and check only values that preflight cannot know.

Changed behavior

  • Every floating-point number and vector parameter in every filter rejects NaN and infinity before preflightImpl() (-86200).
  • New errors for the values in sections 1–4 come from the parameter layer (-86200 to -86202). The per-filter codes for these conditions are removed: -3012 to -3014 (Partition Geometry), -7362 to -7364 (Resample Rect Grid To Image Geom), -11000 (Interpolate Point Cloud To Regular Grid), -11001 (Approximate Point Cloud Hull), -11500 and -11502 (Resample Data), -23508 (Read Image Stack), and -86007 to -86010, -86014 and -86015 (Create Geometry, Create Image Geometry and Partition Geometry origin, spacing and cell length).
  • Checks that bounds cannot express keep their own codes in -86124 to -86251, one code per condition.
  • Results that depend on the final geometry fail when the filter executes, after a preflight warning where preflight can see them.
  • NaN and infinite input-geometry metadata and coordinates are accepted unless they reach an unsafe conversion (section 5).
  • Uniform interpolation no longer checks the inactive Gaussian Sigmas.
  • Output for every previously valid value is unchanged.

Family entries fixed

This pull request fixes these entries of #1873; the issue stays open for its other parameter classes:

Entry Fix
CreateAMScanPathsFilter hatch spacing (CreateAMScanPaths.cpp:190) and rotation angle (:421) Sections 1–2
PointSampleEdgeGeometryFilter sampling spacing (PointSampleEdgeGeometry.cpp:73) Sections 1–2
ResampleImageGeomFilter spacing and exact dimensions (ImageGeometryResample.cpp:260) Sections 1–3
ApproximatePointCloudHullFilter grid resolution (ApproximatePointCloudHullFilter.cpp:86) and empty-neighbor maximum (ApproximatePointCloudHull.cpp:178) Sections 1–2
UncertainRegularGridSampleSurfaceMeshFilter spacing, origin and uncertainty (:138) Sections 1–2
InterpolatePointCloudToRegularGridFilter Gaussian sigmas (:172) and kernel size (InterpolatePointCloudToRegularGrid.cpp:417) Sections 1–3
ComputeCoordinateThresholdFilter sphere (:165) Sections 1–2
ExtractFeatureBoundaries2DFilter custom Z (ExtractFeatureBoundaries2D.cpp:265) Section 1
RegularGridSampleSurfaceMeshFilter origin (:200) Section 1
PartitionGeometryFilter cell counts and Advanced origin (the count part of the :550 entry; :206) Sections 1, 3
ResampleRectGridToImageGeomFilter dimensions (:113) Sections 1, 3
CreateGeometryFilter / CreateImageGeometryFilter dimensions (the dimension part of the CreateImageGeometryAction.cpp:58 entry) Sections 1, 3
FeatureFaceCurvatureFilter ring count (:58) Sections 1, 3
PointSampleTriangleGeometryFilter sample count (PointSampleTriangleGeometry.cpp:64) Sections 1, 3
ReadImageStackFilter exact 2D dimensions (:302) Sections 1, 4

Not part of this pull request: the Partition Geometry bounding-box and Compute Coordinate Threshold rectangle relations, and the Read Image Stack origin and spacing overrides (later pull requests for #1873); bounds on the other filters' parameters, and showing bounds in the DREAM3D-NX widgets (#1991); cancellation in the Create AM Scan Paths hatch loop (#1876); results that overflow float32 from finite values (#1874); and Partition Geometry reading coordinates during preflight (#1798).

Test plan

  • New tests reproduce the defects on develop where that is safe (accepted invalid spacing, sigmas, origins, angles, counts and dimensions; zero exact dimensions that give infinite spacing) and pass with the fix. Cases where develop reaches undefined behavior (nonfinite-to-integer conversions, non-terminating loops, oversized allocations) are tested against the fixed code only. Controls check inactive options, valid boundaries, zero sample points, provisional pipeline geometry that becomes valid during execution, and both Direct and Scanline partition paths.
  • Parameter bounds: exclusive and inclusive limits, NaN and infinity by default and when allowed, vector components, and every filter's defaults (Number Parameter Value Bounds, Vector Parameter Value Bounds, Numeric Parameter Defaults).
  • Nonfinite input data: exterior points with NaN or infinite metadata get the outside ID or zero fill; reached conversions fail with their codes; masked NaN vertices are skipped; NaN-last ordering laws; isPlane() with NaN; a 4096 × 2 × 1 rectilinear grid across the bound-reading block boundary on both partition paths.
  • Affected tests, in-core Release on macOS: 165/165.
  • Affected tests, out-of-core Release (DREAM3DNX_ENABLE_OOC=ON, SIMPLNX_TEST_ALGORITHM_PATH=1) on macOS: 169/169.
  • Full out-of-core suite on macOS, ctest -L "^ooc$" -LE benchmark: 1053/1053.
  • CI passes.

Related Issue

Related to #1873
Related to #1991

@joeykleingers joeykleingers self-assigned this Nov 12, 2026
@azure-pipelines

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

@joeykleingers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

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

@joeykleingers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

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

@joeykleingers
joeykleingers force-pushed the bug/c14-sampling-resampling branch from 8e77db8 to 93e1900 Compare November 14, 2026 15:13
@joeykleingers
joeykleingers marked this pull request as ready for review November 14, 2026 15:18
@joeykleingers
joeykleingers force-pushed the bug/c14-sampling-resampling branch from 93e1900 to 9b7907c Compare November 16, 2026 19:32
@joeykleingers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

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

@imikejackson imikejackson 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.

This whole PR is going to be redesigned as a NumberParameter and VectorParameter update instead.

@imikejackson

Copy link
Copy Markdown
Contributor

Why this pull request has "Request changes"

The defects that this pull request fixes are real, and the analysis behind them is careful. The changes are requested because of the design, not because of the individual fixes.

1. The same check is written again in each filter

Most of the preflight changes check one value that the user typed: finite, greater than 0, at least 1, or in a range. This pull request adds about 20 of these checks. Each has its own error code (-86100 to -86174) and its own test. #1952 and #1973 do the same thing in other filters. Each new filter must remember to write the check again.

simplnx already has the place for this check. IFilter::preflight() calls ValueParameter::validate() for each active parameter before preflightImpl(), and it skips parameters that a linked option turns off. But NumberParameter<T>::validateNumber() accepts every value, and VectorParameter<T>::validateVector() checks only the length.

#1991 adds optional bounds to NumberParameter and VectorParameter, and makes every floating-point number parameter reject NaN and infinity. With this, the Hatch Spacing check becomes one argument on the parameter:

params.insert(std::make_unique<Float32Parameter>(k_HatchSpacing_Key, "Hatch Spacing",
    "The orthogonal distance between each generated vector.", 0.14f, Float32Parameter::Bounds::Positive()));

The parameter layer gets its own error codes. A filter's preflight no longer checks a single value that the user typed, and the per-filter codes for these conditions (the new -861xx codes and the old -3012 to -3014, -7362 to -7364, -11000, -11001, -11500, -11502 and -23508 for these conditions) are removed.

We will add the bounds on this branch and convert the filters that this pull request changes. The checks that must stay in a filter stay: relations between parameters, products and overflow, and values that depend on the final geometry (checked when the filter executes).

2. Findings in the parts that stay

These findings apply to the code that does not move to the parameter layer:

  • Important: Create AM Scan Paths can still run forever with a valid Hatch Spacing. CreateAMScanPaths.cpp:190 loops with lineY += lineSpacing in float. Near Y = 1000, 1000.0f + 1e-5f == 1000.0f, so a Hatch Spacing of 1e-5 never moves lineY and the loop does not end. The new check (finite and > 0) accepts this value. Count the lines as an integer (in float64), check the count, and loop on the integer index.
  • Important: no test makes the Partition Geometry coordinate pre-pass fail. The pre-pass in PartitionGeometryDirect.cpp (RectGrid and node geometries) protects the unchecked getIndex calls in the workers, but no test gives it a NaN coordinate. A test with a NaN RectGrid bound and one with an unmasked NaN vertex, on both algorithm paths, is necessary.
  • Important: ReadImageStackFilter.md no longer says what Exact X/Y Dimensions mode does. The sentence that the output X and Y dimensions are set to the given values was replaced by the limits only.
  • Minor: the serial pre-pass in Partition Geometry reads every coordinate on one thread before the parallel workers. For a RectGrid, check each axis (O(nx + ny + nz)) instead.
  • Minor: one error code for more than one condition (for example -86113, -86125, -86136, -86165 and -86171). Each condition needs its own code.
  • Minor: messages and documentation use developer words such as "cannot fit usize", "representable", "float32 square", "subnormal" and "no workload limit". Write what the user did wrong and what to change. Use the on-screen parameter names ("New Spacing", not "Spacing").
  • Minor: some new code goes past the BUG: C14: Parameter values not validated in preflight in 65 filters #1873 entries. Examples: byte-count overflow checks that cannot occur after the int32 range check, exported detail:: helpers that only tests call, and the bulk-I/O failure change in ImageGeometryResample that the description does not list. BUG: C15: Unsafe numeric conversion and range computation in 39 filters #1874 tracks overflow from finite values.
  • Nit: a std::cout in InterpolatePointCloudToRegularGridTest.cpp, #include lines in the middle of test files, and a second using namespace nx::core; in two filters.

3. Defect found that this pull request did not cause

Resample Image Geom in Exact Dimensions mode can make one cell fewer than the user asks for (s = 1, d = 1, E = 7 gives 6 cells). This is now item L99 in #1908.

Next steps

This branch was rebased onto develop after #1952 was merged; only the three commits of this pull request are left. We will add the bounds from #1991 and the fixes above as new commits on this branch, and then ask for review again.

joeykleingers and others added 9 commits November 19, 2026 10:16
Sampling, resampling and scan-path filters accepted zero, negative,
NaN or infinite spacing, resolutions, sigmas, origins, angles and
coordinates, which led to division by zero, loops that never end,
float-to-integer conversions of nonfinite values and NaN output.

- Preflight rejects invalid active values in Create AM Scan Paths,
  Point Sample Edge Geometry, Resample Image Geom, Approximate Point
  Cloud Hull, Uncertain Regular Grid Sample Surface Mesh, Interpolate
  Point Cloud To Regular Grid (Gaussian sigmas), Compute Coordinate
  Threshold (sphere), Extract Feature Boundaries 2D (custom Z) and
  Regular Grid Sample Surface Mesh (origin). Inactive options are not
  checked.
- Values derived from the final geometry (resampled spacing and
  dimensions, hull grid bounds, edge sample counts, resampling axis
  maps) are checked when the filter executes, before any conversion or
  allocation; preflight warns and uses safe placeholders when the
  current geometry gives an unrepresentable layout.
- Add ValidateResamplingParameters() and ComputeResampledImageLayout()
  for the shared resampling code.

Output for every previously valid value is unchanged.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
Geometry-creation, partitioning, resampling, curvature, point-sampling
and interpolation filters accepted zero or negative counts, signed
values that wrapped to huge unsigned dimensions, nonfinite kernel
sizes and dimension products that overflow, which led to empty or
corrupt geometries, division by zero, huge allocations and
float-to-integer conversions that are undefined behavior.

- Preflight rejects negative Partition Geometry counts, partition
  products and ID ranges that cannot be represented (Basic, Advanced
  and Bounding Box modes), zero dimensions in Create Geometry (Image),
  Create Image Geometry, Resample Image Geom (Exact Dimensions) and
  Resample Rect Grid To Image Geom, Neighborhood Ring Count below 1 in
  Feature Face Curvature, negative Number of Sample Points in Point
  Sample Triangle Geometry and nonfinite Kernel Size in Interpolate
  Point Cloud To Regular Grid. Inactive options are not checked.
- Values derived from final geometry are checked when the filter
  executes, before conversion or allocation: an existing partition
  grid's metadata, product and ID range, each coordinate-to-partition
  index conversion, and the interpolation kernel radius, size and
  storage. Preflight warns when the current geometry gives an
  unrepresentable kernel.
- Add GeometryUtilities::ValidateImageDimensions() for the shared
  positive-dimension check.
- A zero sample count now returns an empty vertex geometry without
  drawing samples; masked vertices are skipped before their
  coordinates are converted.

Output for every previously valid value is unchanged.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
Read Image Stack accepted zero Exact 2D Dimensions and nonfinite
Scaling, and read the Exact 2D Dimensions vector even when another
resampling mode was selected. Zero dimensions produced infinite
spacing in the resampled slices.

- Preflight checks only the active resampling option, before reading
  slice metadata or creating output actions: Exact 2D Dimensions must
  be at least 1 with a representable product, and Scaling must be
  finite and at least 1 percent. These use the shared resampling
  checks.
- Inactive resampling options are no longer read or checked.

Output for every previously valid value is unchanged.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
Check numeric parameter values before filter preflight.
Reject NaN and infinity by default. Check filter defaults in tests.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Use parameter bounds for sampling and resampling inputs.
Prevent stalled hatch loops and check partition coordinates.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Use the names of the parameters in the application.
Describe how Read Image Stack sets the X and Y dimensions.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Plan Read Image Stack X/Y resampling from one slice and check the
stack product. Keep the worker error when resampling is canceled.
Give the outside ID for an empty existing partition grid.
Give each hull grid failure its own code and a recovery step.
Merge split algorithm documentation blocks. Remove unused includes.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Give each interpolation preview warning and the RectGrid bound check
their own codes. Check the Read Image Stack size one time.
Name only the active controls in the resampling messages.
Use CamelCase names for the NumberBounds members.
Restore the knowledge base rules that bounds cannot express.
Make the resampling cancellation test independent of thread count.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
Declare the Gaussian Sigmas range on the parameter. Remove the filter
check of the sigma squares, because the range keeps 2 * sigma * sigma
a finite, nonzero value. Add an input data warning about NaN values
to the Approximate Point Cloud Hull documentation.

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
@imikejackson
imikejackson force-pushed the bug/c14-sampling-resampling branch from ecc5cf8 to c06e312 Compare November 19, 2026 15:52
@imikejackson

Copy link
Copy Markdown
Contributor

@jmarquisbq - This PR needs to be reviewed by you since both @joeykleingers and I have commits.

NaN and infinity in input data (array values, file values and the
origin, spacing, bounds and coordinates of an input geometry) are no
longer rejected. A check stays only where such a value would reach an
integer conversion, an index, a loop bound, an ordering or a float32
narrowing. Typed number and vector parameters still reject NaN and
infinity through their bounds.

- Partition Geometry no longer rejects a partition grid with a
  nonfinite origin or spacing, or input coordinates and rectilinear
  bounds that are nonfinite. An exterior point gets the outside ID; a
  point that reaches the cell conversion with a nonfinite or
  out-of-range quotient fails with -86215. The Direct algorithm uses
  the real axis offsets and checks actual tuples when an axis map
  cannot be proven safe. Rectilinear bounds are read in blocks.
- Resampling (Resample Data, Read Images [3D Stack]) no longer rejects
  a prepared geometry with a nonfinite origin, and keeps only the
  finite nonpositive spacing check. A destination cell exterior on any
  axis is zero-filled; -86137 is returned only when a cell that is
  inside on the other axes needs an unsafe conversion.
- Interpolate Point Cloud to Regular Grid keeps only the finite
  nonpositive spacing check and checks each vertex's cell conversion
  after the mask and bounds checks (-86251), instead of calling the
  unchecked ImageGeom::getIndex().
- Approximate Point Cloud Hull checks each vertex's voxel before the
  int64 cast (-86248); a NaN vertex no longer reaches it.
- Create AM Scan Paths checks the first and reconstructed hatch
  positions before narrowing to float32 (-86249, -86250) and sorts
  intersections with NaN after every number.
- INodeGeometry0D::isPlane() compares every coordinate with the first
  instead of inserting them into a std::set<float32>, which NaN made
  undefined.
- The shared resampling messages name the output spacing instead of
  New Spacing.
- Removed the unused ResampleImageGeom::ComputeAxisSourceIndices().

Freed error codes: -86171, -86172, -86211, -86228, -86247.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
Rewrite the knowledge base entry "Decide NaN and infinity handling by
where the value comes from". Typed number and vector parameters still
reject NaN and infinity by default. Array values, file values and
input geometry data pass through without rejection, warning or a
nonfinite-handling choice; a filter checks them only where they would
reach undefined behavior (integer conversion, an index, size, count or
loop bound, an ordering or equivalence, float32 narrowing or a
standard library precondition). Separate the ordering rule (NaN after
every number) from the equivalence rule (NaN equal only to NaN).

Part of BlueQuartzSoftware#1873.

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

Copy link
Copy Markdown
Contributor Author

@imikejackson @jmarquisbq I added two commits on top of Mike's rework:

  • b0b32e133 BUG: Pass nonfinite geometry data through and check only the conversions
  • 51da44415 DOC: Pass nonfinite input data through and guard undefined behavior

They apply the NaN and infinity rule from our meeting. Typed number and vector parameters keep rejecting NaN and infinity through the new bounds. Array values, file values and input geometry metadata pass through, and a filter checks them only where they would reach undefined behavior. The knowledge base entry "Decide NaN and infinity handling by where the value comes from" now says this.

  • Partition Geometry, Resample Data and Read Images [3D Stack] no longer reject a grid with a nonfinite origin or spacing, or nonfinite coordinates and bounds. A point outside the grid gets the outside ID or a zero-filled cell. A point that needs the unsafe conversion still fails (-86215, -86137).
  • New checks where NaN reached an integer conversion or an ordering:
    • Interpolate Point Cloud To Regular Grid: each vertex's cell conversion (-86251).
    • Approximate Point Cloud Hull: each vertex's voxel (-86248).
    • Create AM Scan Paths: the hatch positions before narrowing to float32 (-86249, -86250), and a NaN-last intersection sort.
    • INodeGeometry0D::isPlane() no longer puts coordinates into a std::set<float32>.
  • The shared resampling messages say "output spacing" instead of New Spacing.
  • Freed codes: -86171, -86172, -86211, -86228, -86247.

Validation on macOS, Release: affected tests 165/165 in-core and 169/169 out-of-core; full out-of-core suite 1053/1053. I also updated the description for the parameter bounds and this change.

@joeykleingers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

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

@imikejackson

Copy link
Copy Markdown
Contributor

@joeykleingers I moved this PR back to draft and set it to In Progress. This is about your last two commits (b0b32e133 and 51da44415). I want to explain why.

Why. Your commits remove the nonfinite checks on geometry data and guard only the integer conversions. That follows the "garbage in, garbage out" rule, and for values in data arrays I understand the reasoning. But an ImageGeom with a NaN or infinite origin or spacing (or a zero or negative spacing) is not "data". It is an invalid geometry by definition, because its cells have no position. No filter or parameter lets a user create one today. It can still come in from a .dream3d file, from the header of an image or EBSD file, from Python, or from a filter that computes the geometry from bad vertices. I do not want every filter that reads a geometry to guard against this. In this PR, that guard is the fallback path in Partition Geometry (TryMapPartitionAxis, the axis proof, the per-tuple slow path and the bounds block reader). It is about 250 lines of code for one behavior change: an infinite origin or spacing now gives output instead of an error.

The plan. Issue #1994 makes geometry validity an invariant at the point where the values are set:

  • ImageGeom::setOrigin() and setSpacing() return Result<>. The origin must be finite, and the spacing must be finite and greater than zero.
  • RectGridGeom::setBounds() requires finite, strictly increasing bounds.
  • The geometry actions, the .dream3d reader and the Python bindings report an error for an invalid value. Filters that compute a geometry also report an error.
  • File readers report an error for an invalid origin or spacing in the file. They get linked Set Origin / Set Spacing parameters (defaults 0, 0, 0 and 1, 1, 1) so the user can override the values and still load the file.

I am implementing this on the branch api/imagegeom-result-setters. The PR for it will say that it is a precondition for this PR.

Merge order:

  1. The ENH: Reject a nonfinite or nonpositive ImageGeom origin or spacing and nonfinite RectGridGeom bounds #1994 PR merges first.
  2. Only after that, this PR is rebased onto develop and cleaned up. Downstream filters can then rely on a valid geometry, so the per-filter geometry nonfinite checks and fallback paths go away (mostly the Partition Geometry part of b0b32e133, and the matching parts in resampling and Interpolate Point Cloud to Regular Grid). The checks that protect against undefined behavior from vertex coordinates and array values can stay.
  3. Then this PR merges.

Knowledge base. The rewritten entry in 51da44415 lists "the origin, spacing, bounds and coordinates of an input geometry" as input data that passes through. That will conflict with #1994. Image origin and spacing and rectilinear bounds will be geometry invariants, not input data. We need to change that entry in the cleanup.

Separately, I am no longer sure about the "garbage in, garbage out" rule for NaN and infinity in data arrays either. When a float array contains NaN or infinity, we cannot know whether the values are intentional, and the output is then undefined for the user. I would like to talk with you about that on its own, outside this PR.

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.

ENH: Validate number parameter values with optional bounds in the parameter

2 participants