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

Đang mở Phù hợp với người mới
#1,906 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
data

Hướng nghiên cứu

Bắt đầu từ ConvertHexGridToSquareGridFilter.cpp, nơi bước kiểm tra sơ bộ so sánh inputPath.extension() với các chuỗi .ctf và .ang bằng toán tử phân biệt chữ hoa chữ thường, và từ Algorithms/ConvertHexGridToSquareGrid.cpp, Converter::operator(), nơi có cùng kiểm tra đó. Chuyển phần mở rộng sang chữ thường bằng StringUtilities::toLower ở cả hai nơi. Chạy kiểm thử HoldRepro902 trong ConvertHexGridToSquareGridTest.cpp: tệp .ANG phải vượt qua kiểm tra sơ bộ và thực thi, còn tệp .CTF viết hoa phải trả về -44601.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
C++
Star
18
Fork
15
Merge trung bình
3 ngày 20 giờ
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của BlueQuartzSoftware/simplnx

Tất cả issue của BlueQuartzSoftware/simplnx

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.