Skip to content

ENH: use utf-8 via manifest on Windows#1401

Merged
N-Dekker merged 1 commit intoSuperElastix:mainfrom
codeling:UseUf8ManifestWindows
Feb 6, 2026
Merged

ENH: use utf-8 via manifest on Windows#1401
N-Dekker merged 1 commit intoSuperElastix:mainfrom
codeling:UseUf8ManifestWindows

Conversation

@codeling
Copy link
Contributor

@codeling codeling commented Feb 3, 2026

Elastix was not able to correctly handle special characters in some folder/file name parameter input on Windows; Elastix would interpret those names incorrectly, resulting in errors.

Test cases:

  • Failing (1): With parameter -out C:\tmp\elöx\result-transform:
ERROR: the output directory "C:\tmp\el÷x\result-transform\" does not exist.
You are responsible for creating it.

(The folder C:\tmp\elöx\result-transform did exist before the call)

  • Failing (2): With parameter -t0 C:\tmp\elx\input\initialTransförmParameter.txt:
itk::ExceptionObject (000000CF80DBF190)
Location: "unknown"
File: C:\Source\elastix\src\Core\ComponentBaseClasses\elxTransformBase.hxx
Line: 202
Description: ITK ERROR: SimilarityTransformElastix(000001D8B0FBAAD8): ERROR: the file C:\tmp\elx\input\initialTransf÷rmParameter.txt does not exist!
Errors occurred!

(the file C:\tmp\elx\input\initialTransförmParameter.txt did exist before the call)

  • Working (tested with 796175c) - special characters already correctly interpreted previously:
    • in the moving/fixed volume file name (e.g. -m C:\tmp\elx\input\möving.mha / -f C:\tmp\elx\input\fäxed.mha)
    • The content of the file given via -t0 parameter is already read as UTF-8, and a .h5 file referenced from within that file (TransformFileName) is already correctly loaded when containing special characters

This PR fixes the 2 failing test cases specified above. It adds an application manifest to switch the executable's locale to utf-8 (available since Windows 10 1903, so for every still supported Windows version); this is same as e.g. applied in Slicer . Also the console output is switched to utf-8.

Note: A similar workaround (but setting locale to utf-8 systemwide instead of for the application alone) was already proposed in this issue way back in 2021 for fixing special character issues; the way this PR handles it does not require any action by the user and should just enable special characters working fine on any system >= 1903.

@N-Dekker
Copy link
Member

N-Dekker commented Feb 3, 2026

Very interesting, thanks Bernhard! I see you did quite some research to get it right 👍 👍 👍

I think it would be good to have a test for this improvements. Similar to the existing test on spaces in output path names:

file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest")
file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces")
file(MAKE_DIRECTORY "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces/name with spaces")
add_test(NAME OutputDirectoryPathContainingSpacesTest
COMMAND ${EXECUTABLE_OUTPUT_PATH}/elastix
-f "${TestDataDir}/2D_2x2_square_object_at_(1,3).mhd"
-m "${TestDataDir}/2D_2x2_square_object_at_(2,1).mhd"
-p "${TestDataDir}/parameters.2D.NC.translation.ASGD.txt"
-out "${TestOutputDir}/OutputDirectoryPathContainingSpacesTest/path with spaces/name with spaces")

Do you still have time to add such a test? Otherwise, I'll see if I can add it myself.

@codeling
Copy link
Contributor Author

codeling commented Feb 3, 2026

Do you still have time to add such a test? Otherwise, I'll see if I can add it myself.

Done (see added commit).
I have added an additional test case - parameter files with special characters in them also caused failures.

Since I'm not really familiar with the intial transform file format, I just added the first (AI-generated) content that made elastix run successfully (it might not really contain a useful transform).

@N-Dekker
Copy link
Member

N-Dekker commented Feb 3, 2026

Thanks @codeling, looks cool!

By the way, GitHub warns me that your commits are "Unverified", saying:

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Learn about vigilant mode

Do you have a clue? Otherwise I think I'll just ignore the warning 😃

@codeling codeling force-pushed the UseUf8ManifestWindows branch from e44a181 to 64cfb10 Compare February 3, 2026 16:22
@codeling
Copy link
Contributor Author

codeling commented Feb 3, 2026

Do you have a clue? Otherwise I think I'll just ignore the warning

Ah yes, I typically sign my commits but hadn't set it up on that machine yet. I have resubmitted my changes now as single squashed signed commit!

@codeling codeling force-pushed the UseUf8ManifestWindows branch from 64cfb10 to d73dafc Compare February 3, 2026 16:59
@codeling
Copy link
Contributor Author

codeling commented Feb 4, 2026

In a ctest run, 3 tests are failing (elastix_run_example_COMPARE_IM, elastix_run_3DCT_lung.MI.bspline.ASGD.001_COMPARE_TP and TransformixTest), but at least on my machine, they also already fail without my fix, so I suppose this isn't something that this PR breaks.

Copy link
Member

@N-Dekker N-Dekker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, Bernhard! Really cool!

@N-Dekker N-Dekker merged commit 3bc29d6 into SuperElastix:main Feb 6, 2026
5 checks passed
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.

2 participants