BUG: C19: Geometry coordinates and length units in 8 filters

Abierto
#1,878 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 6 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
backend, data

Línea de trabajo

Start with the eight checklist entries and the linked code locations, then read the relevant filter algorithms and existing tests. Reproduce each finding with the stated small input and an independent expected value; follow the issue’s unit and cell-center rules for fixes. Done means each confirmed finding has a failing test and a corrected result, with related tests and exemplars updated.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Summary

Some filters set the wrong length unit on a geometry, or compute positions half a cell (or half a step) away from the correct position. Readers create an Image Geometry without a unit, so the geometry gets the Micrometer default. Other filters compute coordinates themselves and use the cell minimum corner where the cell center is meant. The output is wrong and the filter gives no error.

As of develop 419f9db35 (2026-10-21) this class has 8 open findings in 8 filters: 0 CRASH, 8 WRONG_DATA, 0 MINOR. An automated code-reading sweep found them on develop 4a7b71e5f (2026-10-08). Each finding was re-checked by reading the code on develop 419f9db35. Each finding is a candidate: nobody has run it yet.

Mechanism

This class has two sub-patterns.

1. The length unit is not set from the file or the parameter. CreateImageGeometryAction has a default unit argument. A reader that omits the argument compiles, and the new Image Geometry gets Micrometer:

CreateImageGeometryAction.hpp#L31-L32

  CreateImageGeometryAction(const DataPath& path, const DimensionType& dims, const OriginType& origin, const SpacingType& spacing, const std::string& cellAttributeMatrixName,
                            IGeometry::LengthUnit units = IGeometry::LengthUnit::Micrometer);

A second form of this sub-pattern is a raw cast of the Length Unit choice index to the enum, for example ReadBinaryCTNorthstar.cpp#L80:

  geom.setUnits(static_cast<IGeometry::LengthUnit>(inputValues->LengthUnit));

The choice list comes from IGeometry::GetAllLengthUnitStrings(). It puts Unspecified at index 27 and Unknown at index 28. In the enum, Unspecified = 100U and Unknown = 101U. The cast is correct for indices 0-26 only.

2. Half-cell or half-step coordinate offset. The Image Geometry origin is the minimum corner of cell 0. The center of cell i is origin + (i + 0.5) * spacing. ImageGeom::getCoordsf already uses this rule (ImageGeom.cpp#L323-L330). Some filters compute positions themselves and use the minimum corner instead, for example FlyingEdges.hpp#L1287-L1289:

    float32 xPos = zeroPos[0] + i * spacing[0];
    float32 yPos = zeroPos[1] + j * spacing[1];
    float32 zPos = zeroPos[2] + k * spacing[2];

The output geometry, surface or file is then shifted by half a cell (or half a sample step). No filter of this class is fixed yet.

Rule

Decision needed: no rule for this class is decided yet. Options:

  • Units, option A: Remove the default unit argument from CreateImageGeometryAction so that every caller must pass a unit. This makes the compiler find every reader that omits it.
  • Units, option B: Change the default to IGeometry::LengthUnit::Unspecified, and pass the real unit in every reader that knows it.
  • Choice index to enum: Map every Length Unit choice index to IGeometry::LengthUnit through one shared lookup (for example a function next to GetAllLengthUnitStrings()). Do not cast the index directly.
  • Coordinates: Compute cell positions through the ImageGeom helpers (getCoordsf / getCoords for cell centers, origin for the minimum bound). Where a filter samples a different grid (for example a pole-figure image), use min + (i + 0.5) * step for the center of sample i, and document the convention.

How to fix

  1. Decide the unit rule above. Then pass the unit at each CreateImageGeometryAction call in the checklist. For NIfTI, parse xyzt_units and use Unspecified when the unit is not known. For NRRD in ReadImageFilter, pass the selected Length Unit.
  2. Add one shared choice-index-to-LengthUnit lookup. Replace the raw cast in ReadBinaryCTNorthstar.cpp. The same raw cast also exists in ReadImageFilter.cpp (line 387), ImportFijiMontageFilter.cpp (line 189), CreateGeometry.cpp (line 85) and ReadBinaryCTNorthstarFilter.cpp (lines 515 and 524). These lines are not separate findings in this list (not confirmed whether another issue tracks them); fix them with the same lookup. Find all with git grep -n "static_cast<IGeometry::LengthUnit>". Do not change the HDF5 readers (ImageGeomIO.cpp and the others): they cast a stored enum value, not a choice index.
  3. For each half-cell finding, replace the local coordinate formula with the cell-center rule. Change the code, the test expectations and the exemplars together. Use an independent oracle for the new expected values; do not copy the new output into the test.
  4. These fixes do not need new error codes. If you add a preflight warning (for example an unknown NIfTI unit), use the error-code range of that filter. Codes are more negative than -10000, and each filter uses one range of 100 codes. Check uniqueness with git grep -nE -- "-NNNN([^0-9]|$)" on develop and on open PR refs.

How to test

  • Write the failing test first.
  • Units: Read a small test file whose unit is known (for example a NIfTI file with xyzt_units = millimeter, a .vgi file with unit = mm, a .nrrd file with Length Unit = Millimeter). Check that ImageGeom::getUnits() returns IGeometry::LengthUnit::Millimeter. For the choice-index finding, set Length Unit to Unspecified and to Unknown, and check that the result is LengthUnit::Unspecified and LengthUnit::Unknown.
  • Coordinates: Use a small Image Geometry with origin (0,0,0) and spacing (1,1,1). Compute the expected positions by hand from the cell-center rule. Examples: a Cell Data step between cells 0 and 1 gives a FlyingEdges3D surface at x = 1.0; dims (2,1,1) gives VTK rectilinear X coordinates 0, 1, 2; an edge of length 1 with three samples gives cumulative distances 1/6, 1/2, 5/6. For ComputeGBCDPoleFigure, use Output Image Dimension = 3 and check the pixel center positions against -1 + (l + 0.5) * (2/3). Test both the Direct and the Scanline algorithm through the existing algorithm-selection test scope.

Conventions

  • Make one PR for the whole class. Make one commit for each filter.
  • Start each commit message with BUG:. Add a Signed-off-by line. Do not add AI attribution.
  • Start every fix with a unit test that fails on develop. If you cannot reproduce a finding, write that in the PR and on this issue with the reason. Do not force a fix.
  • Value checks need an independent expected result (oracle). Do not use the output of the code under test as the expected result.
  • Run ctest serially. Do not use -j, because the tests depend on each other.
  • Format with clang-format 19.1.1 and the repository .clang-format.
  • Do not add sentences to the filter documentation about input requirements. The generated parameter table documents them.
  • If a fix touches a filter that has a V&V report (src/Plugins/<Plugin>/vv/<Filter>.md), update every file of the V&V package of that filter (report, deviations, provenance, test tables). V&V documents reference DREAM3D 6.5.171 only.
  • Rebase on develop. Do not merge develop into the branch.

Checklist

  • WRONG_DATA · ComputeGBCDPoleFigureFilter · ComputeGBCDPoleFigureDirect.cpp:107 — Set Output Image Dimension to an odd value (for example 3). The position uses integer n/2, so each sample is half a pixel away from the cell center of the created Image Geometry. Scanline has the same formula. ComputeGBCDPoleFigureFilter#4

  • WRONG_DATA · FlyingEdges3DFilter · FlyingEdges.hpp:1287 — Use any Image Geometry with Cell Data. getPosCube puts the cube corner at origin + i*spacing (the cell minimum corner), not at the cell center, so the contour surface is shifted by -0.5 cell on each axis. (related: #1808) FlyingEdges3DFilter#6

  • WRONG_DATA · PointSampleEdgeGeometryFilter · PointSampleEdgeGeometry.cpp:122 — Set Calculate Cumulative Sample Distance = true on any edge. The vertices are placed at start + halfDel + j*del, but the stored distance is step*j, so each value is half a step too short. (related: #1797) PointSampleEdgeGeometryFilter#4

  • WRONG_DATA · ReadBinaryCTNorthstarFilter · ReadBinaryCTNorthstar.cpp:80 — Set Length Unit = Unspecified (choice index 27) or Unknown (index 28). The code casts the index directly to IGeometry::LengthUnit, but those enum values are 100 and 101, so the Image Geometry gets a unit value that is not in the enum. ReadBinaryCTNorthstarFilter#4

  • WRONG_DATA · ReadImageFilter · ReadImageFilter.cpp:148 — Read a .nrrd file with Length Unit = Millimeter. The NRRD preflight path creates the Image Geometry without a unit argument, so the geometry gets the Micrometer default. Only the raster image path applies Length Unit. ReadImageFilter#4

  • WRONG_DATA · ReadNIfTIFileFilter · ReadNIfTIFileFilter.cpp:249 — Read any NIfTI file with xyzt_units = NIFTI_UNITS_MM (the usual case for MRI/CT). The filter does not parse xyzt_units and does not pass a unit, so the millimeter spacing is labeled Micrometer. ReadNIfTIFileFilter#5

  • WRONG_DATA · ReadVolumeGraphicsFileFilter · ReadVolumeGraphicsFileFilter.cpp:435 — Read a .vgi file with unit = mm in [geometry] (for example the test file). The filter parses metadata.Units = Millimeter but does not pass it to CreateImageGeometryAction, so the geometry gets Micrometer. ReadVolumeGraphicsFileFilter#2

  • WRONG_DATA · WriteVtkRectilinearGridFilter · WriteVtkRectilinearGrid.cpp:44 — Write any Image Geometry. The coordinates start at origin - 0.5*spacing, but the Image Geometry origin is the minimum corner, so the written grid is shifted by half a cell. (related: #1794) WriteVtkRectilinearGridFilter#1

  • WRONG_DATA · ResampleImageGeomFilter · src/simplnx/Utilities/ImageProcessing/ImageGeometryResample.cpp:80 — Nearest-neighbor resampling uses destination-cell corners instead of centers. For unit source spacing and destination spacing 3, it selects source cells [0,3] instead of [1,4]. Class: C19a; origin: sweep. Mike's PR #1913 overlaps this helper; check its exact patch before editing and avoid duplicating its work.

  • WRONG_DATA · NearestPointFuseRegularGridsFilter · NearestPointFuseRegularGridsDirect.cpp:51 and NearestPointFuseRegularGridsScanline.cpp:36 — Both routes sample reference-cell corners instead of centers and select the wrong source cells. One filter finding covers both routes. Class: C19a; origin: sweep. C07's same-filter findings are different defects. Mike's PR #1913 overlaps the related resampling helper; reconcile that overlap before related coordinate changes.

Related issues

  • #1808 BUG: FlyingEdges3D shifts cell-data contours by half a cell (same as FlyingEdges3DFilter#6)
  • #1797 BUG: Preserve the endpoint offset in sampled edge distances (same as PointSampleEdgeGeometryFilter#4)
  • #1794 BUG: Rectilinear VTK export shifts cell data by half a voxel (same as WriteVtkRectilinearGridFilter#1)

Close these issues from the PR that fixes the matching finding.

Out of scope

  • No finding of this class is in a filter that has a V&V report (0 findings excluded).
  • The HDF5 geometry readers cast a stored enum value, not a choice index. They are not part of this class.
Lenguaje dominante
C++
Estrellas
18
Forks
15
Merge medio
4 d 23 h
PR fusionados (30 d)
42

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de BlueQuartzSoftware/simplnx

Todos los issues de BlueQuartzSoftware/simplnx

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.