Skip to content

ENH: Reject a nonfinite or nonpositive ImageGeom origin or spacing and nonfinite RectGridGeom bounds #1994

Open

Description

@imikejackson

Summary

Request: make "the origin and spacing are finite, and every spacing value is greater than zero" an invariant of ImageGeom. Check it where a geometry gets its origin and spacing, not in each filter that reads them. ImageGeom::setOrigin() and ImageGeom::setSpacing() change to return Result<>, so a caller gets an error for a NaN, infinite, zero or negative value instead of an invalid geometry. Apply the same rule to the X, Y and Z bounds arrays of a RectGridGeom: RectGridGeom::setBounds() already returns Result<> and would also reject NaN and infinite bound values.

Why: an image geometry with a NaN or infinite origin or spacing is invalid by definition. It has no meaningful cell positions. This is different from NaN in a data array, which can be intentional data. Today such a geometry is accepted, and each filter that uses it must either reject it or guard every place where a coordinate becomes a cell index (an integer conversion that is undefined behavior for NaN and infinity). PR #1964 shows both approaches. Its first commits added per-filter rejections (for example in Partition Geometry, Resample Data and Interpolate Point Cloud to Regular Grid). A later commit removed them and added per-coordinate conversion checks, including a fallback path in Partition Geometry for grids with a nonfinite origin. With the invariant, downstream filters can state it as a precondition and need neither.

How it works now:

  • ImageGeom::setSpacing() and ImageGeom::setOrigin() return void and store any value (ImageGeom.cpp).
  • The parameters of Create Image Geometry and similar filters now reject NaN and infinity (ENH: Validate number parameter values with optional bounds in the parameter #1991), but other paths do not:
    • reading a .dream3d file with such values;
    • image and EBSD readers that take spacing and origin from a file header (MHA, NRRD, NIfTI, VTK structured points, Zeiss TXM, ANG and CTF step sizes, and others). A header value of nan, or one too large for float32, is stored as is;
    • Python, which binds CreateImageGeometryAction and UpdateImageGeomAction with raw origin and spacing values;
    • geometries computed from data. For example, Map Point Cloud to Regular Grid computes spacing and origin from the vertex extents, so one infinite vertex gives an infinite spacing and a NaN origin.
  • RectGridGeom::setBounds() checks the bounds arrays but not their values.

Where it applies: ImageGeom and RectGridGeom in src/simplnx/DataStructure/Geometry/, the geometry I/O for .dream3d files, CreateImageGeometryAction and UpdateImageGeomAction, the Python bindings, and about 80 non-test call sites of setSpacing()/setOrigin() across the core library and the plugins (readers, crop, pad, resample, rotate, append, and geometry-creating filters). Out-of-tree plugins that call these setters must be updated too.

Still open: whether a reader that finds an invalid origin or spacing in a file fails or warns, whether a value that is valid only in preflight (for example, not yet known) needs a separate path, and whether the RectGridGeom bounds check also requires increasing bound values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions