Skip to content

BUG: Validate geometry transform values and rotation axes - #1952

Open
joeykleingers wants to merge 4 commits into
BlueQuartzSoftware:developfrom
joeykleingers:bug/c14-geometry-transforms
Open

joeykleingers wants to merge 4 commits into
BlueQuartzSoftware:developfrom
joeykleingers:bug/c14-geometry-transforms

Conversation

@joeykleingers

@joeykleingers joeykleingers commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Geometry creation and transformation filters now reject spacing, origin, scale, cell-length, padding and rotation values outside their domain, instead of producing NaN or infinite geometry, dividing by zero, or wrapping unsigned arithmetic. The axis-angle rotation matrix normalizes large and tiny finite axes correctly. Results that depend on the geometry's current metadata are checked when the filter executes, before anything changes. 37 files changed, +1840 / −96 lines.

1. Rotation axes

  • ImageRotationUtilities::ValidateRotationAxisAngle() requires four values, a finite nonzero axis and a finite angle, with a separate error for each.
  • GenerateRotationTransformationMatrix() keeps its signature. It scales the axis by its largest component and normalizes it in float64; the angle arithmetic is unchanged. Invalid input returns an all-NaN matrix instead of undefined behavior.
  • Apply Transformation To Geometry and Rotate Sample Reference Frame validate the axis-angle value in preflight.

The axis was normalized in float32: a zero axis produced NaN, an axis such as {0,0,1e20} overflowed the squared norm and {1e-22,0,0} underflowed it, so valid rotations produced wrong matrices.

2. Spacing, origin, scale, cell length and padding

  • GeometryUtilities::ValidateFiniteVector(), ValidatePositiveFiniteVector() and ComputePaddedDimensions() (widened, checked padded extents and tuple product).
  • Create Geometry (Image type) and Create Image Geometry: Spacing finite and > 0, Origin finite.
  • Set Image Geom Origin Scaling: enabled Spacing and Origin values; disabled vectors are no longer read.
  • Partition Geometry (Advanced): Cell Length finite and > 0 and Partition Grid Origin finite, checked before the geometry branch, so RectGrid and node geometries are covered as well as Image Geometries.
  • Apply Transformation To Geometry: preflight checks the selected Translation, Scale or Rotation. Image Geometry scale must be positive; node geometries keep zero and negative scale (reflections).
  • Pad Image Geometry: preflight rejects negative padding; padded dimensions use checked usize arithmetic.

Preflight is the one place these parameters are checked. The algorithms document the parameter properties they rely on as preconditions; the shared rotation-matrix function keeps its own axis-angle check because Read H5 EBSD also passes it unvalidated file-header values.

3. Results that depend on existing geometry metadata

Scaled spacing, translated, padded and centered origins, and padded dimensions combine a parameter with the geometry's current spacing, origin or dimensions. Those values can still change upstream during execution (for example after a precomputed-matrix transformation), and IFilter::execute() reruns preflight, so preflight only warns about them. They are rejected when the filter executes, before the geometry changes: UpdateImageGeomAction gains an opt-in check that runs in Execute mode before either setter, and Pad Image Geometry checks at algorithm entry, using source dimensions as placeholders in preflight.

4. Center Origin

#1911 fixed the two Center Origin defects this pull request also fixed (the copied action that dropped the flag, and the offset for negative or mixed-sign origins). This pull request keeps that behavior: UpdateImageGeomAction now computes the centered origin with the same signed offset before either setter runs, so the execution check can reject a nonfinite result before the geometry changes, and clone() also copies the new validation flag.

Changed behavior

  • New preflight errors for nonfinite origins, translations and scales; zero, negative or nonfinite Image Geometry spacing, scale and cell length; negative padding; and invalid rotation axes or angles. New codes are -86000 to -86032 and -86050 to -86053; existing codes are kept for conditions they already reported (Partition Geometry -3003 to -3005, Pad Image Geometry -4010).
  • Operations whose results overflow or underflow fail when the filter executes, after a preflight warning.
  • Rotate Sample Reference Frame reports the axis or angle error instead of the non-principal-rotation error for zero or nonfinite axes, and accepts large finite axes such as {0,0,1e20} at 90°.
  • Advanced Partition Geometry now rejects negative cell lengths for RectGrid and node geometries too.
  • Output for every previously valid value with a representable result is unchanged; rotation matrices for ordinary axes differ by at most 2e-6.

Family entries fixed

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

Entry Fix
Rotation axis normalization (ImageRotationUtilities.cpp:184, moved from #1875) Section 1
ApplyTransformationToGeometryFilter scale (GeometryTransformation.cpp:222) and translation (:213) Sections 2–3
PartitionGeometryFilter cell length (Advanced) and partition grid origin (:206) Section 2
SetImageGeomOriginScalingFilter spacing (:110) and origin (:107) Sections 2–3
PadImageGeometryFilter padding (:152) Sections 2–3
CreateGeometryFilter / CreateImageGeometryFilter spacing (the spacing part of the CreateImageGeometryAction.cpp:58 entry) and origin (:225) Section 2

It also fixes the Rotate Sample Reference Frame large-axis entry in #1908 (BUG: Fixes silent WRONG_DATA and CRASH bugs); the filter's V&V page has a note.

Not part of this pull request: the Partition Geometry cell-count and Create Geometry dimension parts of those entries, and the Partition Geometry bounding-box relations (later pull requests for #1873); existing geometry metadata that is already invalid (#1875); file-header values (#1877).

Integration notes:

Test plan

Related Issue

Related to #1873

@joeykleingers joeykleingers self-assigned this Nov 11, 2026

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

Reviewed simplnx #1952 at f151d087115a8e9e40230f0d2c0c74b4c8be997d. Coverage includes all 37 changed files.

Please address the two small corrections below. No Critical or Important implementation defects were found.

  • Nit — Match the UI labels (CONFIRMED; documentation). In SetImageGeomOriginScalingFilter.md:41, replace Change Spacing with Set Spacing and both instances of Change Origin with Set Origin. The current wording names controls that differ from the labels in parameters().
  • Nit — Include the standard header for the new API type (CONFIRMED; C++ practice). ImageRotationUtilities.hpp:37 introduces std::string_view in the public validation API. Add #include <string_view> directly to this header instead of relying on transitive includes.

Optional future V&V note: During the planned V&V rewrite, map the new rotation validation branches and tests into the coverage tables. The validation change note records the change, but the tables do not yet map errors -86051 through -86053. V&V updates are intentionally deferred. This note does not block this PR, and no V&V update is requested here.

The rotation normalization, checked padding arithmetic and action cloning checked out. The affected filter, action and reader consumers were traced. The architecture and implementation were examined through all seven review lenses. No actionable architectural concerns were found.

Validation on this head:

  • The Linux Release aggregate build passed.
  • Serial CTest passed 136/136 selected entries, including all 35 new test cases, with zero skipped.
  • Clang-format 19.1.1 passed all 28 changed C/C++ files.
  • Scoped clang-tidy 19.1.0 was not clean on style/include diagnostics. There were no parse failures. Updated translation units were checked again after the final commit; applicable evidence was reused for unchanged code.
  • Debug and real out-of-core execution were not independently rerun. CI results from the preceding head do not validate this head.

REQUEST CHANGES for the two small corrections above. The V&V note is optional and deferred.

@joeykleingers

Copy link
Copy Markdown
Contributor Author

Both items are fixed in 23ab28f:

  • SetImageGeomOriginScalingFilter.md now names the options by their on-screen labels, Set Spacing and Set Origin.
  • ImageRotationUtilities.hpp includes <string_view> directly.

The affected tests pass on macOS Release (161/161). The V&V coverage-table note is left for the planned V&V rewrite, as you suggested.

@joeykleingers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

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

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

Reviewed simplnx PR #1952 at 23ab28ffa9ac85b1f1c3c0e933b84d13dee12fb3. Coverage includes all 37 changed files.

1. Findings

No actionable findings. Both corrections from the previous review are complete: the documentation uses the on-screen option labels, and ImageRotationUtilities.hpp directly includes <string_view>.

2. Architecture and correctness

All seven review lenses covered implementation and architecture. No actionable architectural concerns were found. The review checked rotation normalization, checked padding arithmetic, deferred metadata validation, action cloning, and affected filter, reader and Python consumers.

The regression assertions use hand-computed rotation matrices, padding extents and expected output values. The new parameter checks use values available in preflight. Checks that depend on geometry metadata that upstream filters can change remain deferred to execution.

3. Validation and limits

  • 3.1 New checks: clang-format 19.1.1 passed all 28 changed C/C++ files. The diff whitespace check passed. The comment audit reported 56 diagnostics, none on added lines; manual review found no actionable documentation issue introduced by this PR.
  • 3.2 Current-head CI: GitHub reports successful Linux, Windows, macOS and formatting checks. Azure log retrieval failed, so the CI test counts were not independently inspected.
  • 3.3 Reused evidence: the earlier Linux Release build and serial CTest run passed 136/136 selected entries, including all 35 new test cases, at f151d087115a8e9e40230f0d2c0c74b4c8be997d. Changes after that commit correct documentation labels and add the direct include; runtime code is unchanged.
  • 3.4 Remaining limits: no new build or runtime tests were run for this follow-up review. Debug and real out-of-core execution remain independently unverified. Clang-tidy was not rerun; the earlier scoped run had style/include diagnostics and no parse failures.
  • 3.5 Deferred V&V: the coverage-table mapping remains optional and deferred to the planned V&V rewrite. No V&V update is requested in this PR.

4. Verdict

APPROVE — no actionable findings within the reviewed scope.

@joeykleingers
joeykleingers force-pushed the bug/c14-geometry-transforms branch from 23ab28f to 0f28142 Compare November 13, 2026 19:38
@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-geometry-transforms branch from 0f28142 to 792163b Compare November 14, 2026 15:13
@joeykleingers

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

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

The axis-angle rotation matrix normalized its axis in float32 without a
check. A zero axis produced NaN, a large finite axis such as
{0,0,1e20} overflowed the squared norm, and a tiny axis such as
{1e-22,0,0} underflowed it, so valid rotations produced wrong matrices.
A vector shorter than four values was read out of bounds.

- Add ImageRotationUtilities::ValidateRotationAxisAngle(): four values,
  a finite nonzero axis and a finite angle, each with its own error.
- GenerateRotationTransformationMatrix() keeps its signature. It scales
  the axis by its largest component and normalizes it in float64; the
  angle arithmetic is unchanged. Invalid input returns an all-NaN matrix
  instead of undefined behavior.
- RotateSampleRefFrame validates the Axis-Angle value in preflight and
  at algorithm entry. Zero or nonfinite axes now report the axis or
  angle error instead of the non-principal-rotation error, and large
  axes such as {0,0,1e20} at 90 degrees are accepted.

Matrices for ordinary axes are unchanged to within 2e-6.

Part of BlueQuartzSoftware#1873.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
Image Geometry creation and transform filters accepted zero, negative,
NaN or infinite spacing, origins, scales and cell lengths, and negative
padding, producing invalid geometry, division by zero or unsigned wrap.

- Add GeometryUtilities::ValidateFiniteVector(),
  ValidatePositiveFiniteVector() and ComputePaddedDimensions().
- CreateGeometry, CreateImageGeometry and SetImageGeomOriginScaling
  require positive finite spacing and finite origins; PartitionGeometry
  checks Advanced Cell Length and Partition Grid Origin before its
  geometry branch, so RectGrid and node geometries are covered too.
- ApplyTransformationToGeometry validates the selected Translation,
  Scale or Rotation in preflight and at algorithm entry through
  ValidateTransformationParameters(). Image Geometry scale must be
  positive; node geometries keep zero and negative scale.
- PadImageGeometry rejects negative padding and computes padded
  dimensions with widened, checked arithmetic in preflight and at
  algorithm entry.
- Results that depend on existing geometry metadata (scaled spacing,
  translated, padded or centered origins, padded dimensions) are
  checked when the filter executes, before the geometry changes;
  preflight only warns, because the metadata can still change upstream.
  UpdateImageGeomAction gains an opt-in check for this.
- UpdateImageGeomAction::clone() now keeps the Center Origin flag, and
  Center Origin places negative or mixed-sign origins at the geometry's
  center as documented.

Apart from the two Center Origin corrections above, output for every
previously valid value with a representable result is unchanged.

Part of BlueQuartzSoftware#1873.

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

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

- ApplyTransformationToGeometry, PadImageGeometry and
  RotateSampleRefFrame no longer re-validate Translation, Scale,
  Rotation, padding signs or the rotation axis-angle at algorithm entry.
  ValidateTransformationParameters() and the padding sign check now live
  with their filters' preflight.
- PadImageGeometry still checks, when it executes, the padded dimensions
  and origin it computes from the final geometry, because those can
  differ from what preflight sees.
- Tests that called the algorithms directly to reach these errors now
  run the filters. Value checks keep their codes; wrong-length vectors
  now fail parameter validation (-1, naming the expected size), and a
  malformed inactive vector is accepted.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
- The Set Image Geom Origin Scaling documentation names the Set Spacing
  and Set Origin options by their on-screen labels.
- ImageRotationUtilities.hpp includes <string_view> for its public
  validation function instead of relying on a transitive include.

Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
@imikejackson
imikejackson force-pushed the bug/c14-geometry-transforms branch from 792163b to f438170 Compare November 14, 2026 19:23
@imikejackson

Copy link
Copy Markdown
Contributor

/azp run

@imikejackson
imikejackson enabled auto-merge (squash) November 14, 2026 19:24
@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