BUG: Convert Hexagonal Grid Data to Square Grid Data rejects an .ang file with an uppercase extension

Abierto Apto para principiantes
#1,906 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp
Área
data

Línea de trabajo

Empieza en ConvertHexGridToSquareGridFilter.cpp, donde la comprobación previa compara inputPath.extension() con las cadenas .ctf y .ang usando operadores sensibles a mayúsculas, y en Algorithms/ConvertHexGridToSquareGrid.cpp, Converter::operator(), que tiene la misma comprobación. Convierte la extensión a minúsculas con StringUtilities::toLower en ambos lugares. Ejecuta la prueba HoldRepro902 en ConvertHexGridToSquareGridTest.cpp: un archivo .ANG debería pasar la comprobación previa y ejecutarse, y un .CTF en mayúsculas debería devolver -44601.

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

Descripción

bug

Problem

Convert Hexagonal Grid Data to Square Grid Data (TSL - .ang) (ConvertHexGridToSquareGridFilter) rejects a valid .ang file when the extension is not all lower case. A file named scan.ANG or scan.Ang fails preflight with error -44602, "The file extension '.ANG' was not detected correctly". The same file renamed to scan.ang converts correctly.

  • Expected: the filter accepts the extension regardless of case, as the other EBSD readers do.
  • Actual: preflight and execute fail with -44602.
  • Occurs on develop b51d6c353.

Legacy DREAM3D issue BlueQuartzSoftware/DREAM3D#902 asked for case-insensitive extension checks in every filter that reads files. This filter still has the case-sensitive check.

Steps to Reproduce

  1. Copy a valid hexagonal-grid .ang file (for example single/hex_grid.ang from convert_hex_grid_to_square_grid_test.tar.gz) to probe.ANG.
  2. Add Convert Hexagonal Grid Data to Square Grid Data (TSL - .ang) to a pipeline.
  3. Turn off Convert Multiple Files, set Input File to probe.ANG, set an Output Directory, set Output Prefix to Sqr_ and set Spacing to 0.05, 0.0403.
  4. Preflight shows error -44602.
  5. Rename the file to probe.ang and preflight again. It passes, and execute writes Sqr_probe.ang.

Cause

Preflight compares std::filesystem::path::extension() with ".ang" and ".ctf" using == and !=, so the comparison is case-sensitive:

ConvertHexGridToSquareGridFilter.cpp#L143-L150

  if(inputPath.extension() == ("." + ebsdlib::Ctf::FileExt))
  {
    return MakePreflightErrorResult(-44601, "Ctf files are not on a hexagonal grid and do not need to be converted");
  }
  else if(inputPath.extension() != ("." + ebsdlib::Ang::FileExt))
  {
    return MakePreflightErrorResult(-44602, fmt::format("The file extension '{}' was not detected correctly for file '{}'", inputPath.extension().string(), inputPath.string()));
  }

The algorithm has the same case-sensitive comparison before it reads each file:

ConvertHexGridToSquareGrid.cpp#L45-L46

    if(inputPath.extension() == ("." + ebsdlib::Ang::FileExt))
    {

A side effect: an uppercase .CTF file gets the misleading -44602 message, not the -44601 "Ctf files ... do not need to be converted" message.

Verification Unit Test

Add to src/Plugins/OrientationAnalysis/test/ConvertHexGridToSquareGridTest.cpp. It uses the k_HexToSqrTestFilesDir and k_Spacing constants that are already in that file. This is the test as it was run (it was written as a probe, so its name has the HoldRepro902 prefix):


TEST_CASE("HoldRepro902 ConvertHexGrid accepts uppercase ANG", "[HoldRepro]")
{
  UnitTest::LoadPlugins();
  const UnitTest::TestFileSentinel sentinel(unit_test::k_TestFilesDir, "convert_hex_grid_to_square_grid_test.tar.gz", k_HexToSqrTestFilesDir);
  const fs::path source = fs::path(unit_test::k_TestFilesDir.view()) / k_HexToSqrTestFilesDir / "single/hex_grid.ang";
  const fs::path root = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "HoldRepro902Hex";
  fs::create_directories(root);
  for(const std::string extension : {".ang", ".ANG"})
  {
    const fs::path input = root / ("probe" + extension);
    fs::copy_file(source, input, fs::copy_options::overwrite_existing);
    ConvertHexGridToSquareGridFilter filter;
    auto args = filter.getDefaultArguments();
    args.insertOrAssign(ConvertHexGridToSquareGridFilter::k_MultipleFiles_Key, std::make_any<bool>(false));
    args.insertOrAssign(ConvertHexGridToSquareGridFilter::k_InputPath_Key, std::make_any<fs::path>(input));
    args.insertOrAssign(ConvertHexGridToSquareGridFilter::k_OutputPath_Key, std::make_any<fs::path>(root / (extension == ".ang" ? "lower" : "upper")));
    args.insertOrAssign(ConvertHexGridToSquareGridFilter::k_OutputPrefix_Key, std::make_any<std::string>("Sqr_"));
    args.insertOrAssign(ConvertHexGridToSquareGridFilter::k_Spacing_Key, std::make_any<std::vector<float32>>(k_Spacing));
    DataStructure ds;
    const auto preflight = filter.preflight(ds, args);
    WARN(fmt::format("Hex {} preflight valid={}", extension, preflight.outputActions.valid()));
    if(preflight.outputActions.invalid())
      for(const auto& e : preflight.outputActions.errors())
      {
        WARN(fmt::format("{}: {}", e.code, e.message));
      }
    CHECK(preflight.outputActions.valid());
    const auto result = filter.execute(ds, args);
    if(result.result.invalid())
      for(const auto& e : result.result.errors())
      {
        WARN(fmt::format("Hex {} execute {}: {}", extension, e.code, e.message));
      }
    CHECK(result.result.valid());
    if(result.result.valid())
    {
      const auto out = root / (extension == ".ang" ? "lower" : "upper") / ("Sqr_probe" + extension);
      CHECK(fs::exists(out));
    }
  }
}

Run only this test:

<build-dir>/bin/OrientationAnalysisUnitTest "HoldRepro902 ConvertHexGrid accepts uppercase ANG"

Failure output on develop b51d6c353 (macOS arm64, ci-macos-arm64 preset). The .ang control passes; .ANG fails:

warning:
  Hex .ang preflight valid=true
warning:
  Hex .ANG preflight valid=false
warning:
  -44602: The file extension '.ANG' was not detected correctly for file '.../test_output/HoldRepro902Hex/probe.ANG'
FAILED:
  CHECK( preflight.outputActions.valid() )
with expansion:
  false
warning:
  Hex .ANG execute -44602: The file extension '.ANG' was not detected correctly for file '.../test_output/HoldRepro902Hex/probe.ANG'
FAILED:
  CHECK( result.result.valid() )
with expansion:
  false

Proposed Fix

Compare the lower-case extension in both places. StringUtilities::toLower in src/simplnx/Utilities/StringUtilities.hpp already does this, and EbsdToH5EbsdFilter uses it since PR #1749.

In ConvertHexGridToSquareGridFilter.cpp (preflight):

  const std::string extension = StringUtilities::toLower(inputPath.extension().string());
  if(extension == ("." + ebsdlib::Ctf::FileExt))
  {
    return MakePreflightErrorResult(-44601, "Ctf files are not on a hexagonal grid and do not need to be converted");
  }
  else if(extension != ("." + ebsdlib::Ang::FileExt))
  {
    ...
  }

In Algorithms/ConvertHexGridToSquareGrid.cpp, Converter::operator(), make the same change. With Convert Multiple Files on, preflight checks only the first generated file, so the algorithm check also matters for the other files. The output file keeps the input file name, so Sqr_probe.ANG is written for probe.ANG.

Notes

  • EbsdToH5EbsdFilter had the same problem in preflight, fixed by PR #1749. Its execute check (EbsdToH5Ebsd.cpp#L155-L157) is still case-sensitive. A probe on develop b51d6c353 shows that .ANG passes preflight and fails at execute with -99512. That item is tracked in #1867 as EbsdToH5EbsdFilter#1. It is not part of this issue.
  • The file parameter itself (FileSystemPathParameter) already accepts probe.ANG: the -44602 error comes from the filter's own check above.
Lenguaje dominante
C++
Estrellas
18
Forks
15
Merge medio
4 d 6 h
PR fusionados (30 d)
24

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.