Skip to content

ENH: Update NrrdIO upstream with recent teem updates#5542

Merged
hjmjohnson merged 3 commits intomainfrom
update-nrrdio-upstream
Jan 21, 2026
Merged

ENH: Update NrrdIO upstream with recent teem updates#5542
hjmjohnson merged 3 commits intomainfrom
update-nrrdio-upstream

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

@hjmjohnson hjmjohnson commented Oct 3, 2025

Update for synchronizing with the upstream teem project

git clone https://git.code.sf.net/p/teem/nrrdio/nrrdio.git NrrdIO

This commit updates the ThirdParty NrrdIO library to the latest version
from the upstream Teem project. This update includes several
modernization efforts, bug fixes, and new features.

Major changes include:

  1. A decade of NrrdIO updates.
  2. Improved const-correctness
  3. Replace unsafe funcitons (i.e. sprintf -> snprintf and similar)
  4. Zero Run Length (ZRL) Encoding Support: Added a new encoding
    (encodingZRL.c) that supports reading ZRL-compressed NRRD files.
  5. Script Modernization:
    • Replaced legacy Perl scripts (mangle.pl, tail.pl, unteem.pl)
      with Python equivalents (mangle.py, tail.py, unteem.py).
    • Added 0-gen.sh to provide a reliable, documented way to
      regenerate NrrdIO from Teem sources.
  6. Code Style and Formatting:
    • Applied project-wide clang-format to improve consistency.
    • Added .clang-format configuration file to the source directory.
  7. Refactoring and Cleanup:
    • Refactored NrrdIO.h and NrrdIO.h.in for better maintainability.
    • Removed obsolete files including dio.c, qnanhibit.c, and
      associated CMake tests.
    • Renamed 000-README.txt to 0-README.txt.
  8. Build System Improvements:
    • Updated CMakeLists.txt to use modern CMake patterns.
    • Added ITK-specific library build requirements and installation
      rules for mangled headers.
  9. Legal and Documentation:
    • Updated copyright notices to include 2026.
    • Clarified licensing in 0-README.txt and LICENSE.

These changes ensure that ITK's NRRD support remains compatible with
the latest upstream developments while improving the developer
experience for maintaining the third-party module.

PR Checklist

@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:ThirdParty Issues affecting the ThirdParty module labels Oct 3, 2025
@hjmjohnson hjmjohnson marked this pull request as draft October 3, 2025 20:59
@hjmjohnson hjmjohnson changed the title update nrrdio upstream WIP: Update NrrdIO upstream Oct 3, 2025
@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Oct 5, 2025

This seems to work?

@hjmjohnson
Copy link
Copy Markdown
Member Author

This seems to work?

Yes. I'm working with @kindlmann to move Teem and NrrdIO from SVN to git on SourceForge. What is included in this patch set is proposed testing for patch sets that are not yet included upstream in NrrdIO or Teem.

I was just waiting for the dust to settle in the upstream changes before finalizing this and linking it to the stable git hashes upstream.

@hjmjohnson hjmjohnson force-pushed the update-nrrdio-upstream branch from 9e28ab9 to 0b4972d Compare October 23, 2025 01:43
@github-actions github-actions Bot added the type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct label Oct 23, 2025
@hjmjohnson hjmjohnson force-pushed the update-nrrdio-upstream branch 2 times, most recently from 18d0cf9 to f213542 Compare October 23, 2025 11:45
@blowekamp
Copy link
Copy Markdown
Member

Thank you for working on this.

When a new UpdateFromUpstream.sh process is added, as I recall the old code is usually deleted from the repo, then the directory is re-estabished with a sub-tree merge. So once the upstream work is completed, it does not need to be updated here before the new process is established.

@hjmjohnson
Copy link
Copy Markdown
Member Author

Thank you for working on this.

When a new UpdateFromUpstream.sh process is added, as I recall the old code is usually deleted from the repo, then the directory is re-estabished with a sub-tree merge. So once the upstream work is completed, it does not need to be updated here before the new process is established.

@blowekamp This may not work for NrrdIO. The central part of the NrrdIO git repo is a set of scripts that extract code from the teem source code base and replace the LGPL license with a BSD license, drop chunks of code that exist in teem, but are not needed for NrrdIO, and create the mangling headers. It is starter code for other projects to adapt from, but not necessarily useful on its own.

The set of scripts that extract data from teem does different things when the "itk" flag is passed in, and the "itk" variant of the extracted code has specializations for ITK that are not part of the central git repository. I'm working with Gordon to create a single codebase that is easier to maintain, but I'm not sure we will get there.

@blowekamp
Copy link
Copy Markdown
Member

I didn't see what occurs with running scripts with the itk variant in the repo:
https://sourceforge.net/p/teem/nrrdio/nrrdio.git/ci/main/tree/

But keep in mind the standard update script unarchived the git repo, and runs some scripts and command to clean up the code for the sub-tree commit. It sounds like the approach taken may still fit into the existing update framework. Here is an example of what happens for HDF5:

@kindlmann
Copy link
Copy Markdown
Contributor

I'm grateful for the continued work of @hjmjohnson on this, and I do believe "we will get there" as long as we keep communicating.

The new 0-gen.sh script in NrrdIO is a work-in-progress, but it's main goal is to (like Hans mentioned) do the necessary transformations of Teem source into a minimal set of NrrdIO sources. How much work it should do to anticipate ITK's subsequent use specifically, versus be configurable for any other application, is something I think we're still trying to determine. Anyone else interested is welcome to join the discussion at https://discord.gg/xBBqZGXkF7

@hjmjohnson hjmjohnson force-pushed the update-nrrdio-upstream branch 4 times, most recently from 8bbca14 to 677ca0e Compare October 24, 2025 17:14
@hjmjohnson
Copy link
Copy Markdown
Member Author

FYI: This is still being pursued. Upstream teem modifications are ongoing, and more extensive than originally thought. This is all good, but is taking a bit longer than anticipated.

@hjmjohnson hjmjohnson changed the title WIP: Update NrrdIO upstream ENH: Update NrrdIO upstream with recent teem updates Jan 18, 2026
@hjmjohnson hjmjohnson force-pushed the update-nrrdio-upstream branch from 677ca0e to 30405c8 Compare January 18, 2026 15:14
@github-actions github-actions Bot added type:Enhancement Improvement of existing methods or implementation and removed type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:ThirdParty Issues affecting the ThirdParty module labels Jan 18, 2026
The .clang-format file from June 2022 teem/NrrdIO
project is applied here to minimize code differences
with upstream changes.

This patch set will allow the upstream changes to
be more easily visible when added in a subsequent
patch.
The NrrdIO repository recently moved to git

```bash
ITK_SRC_ROOT=${HOME}/src/ITK
NRRDIO_SRC_ROOT=/tmp/teem
TEEM_SRC_ROOT=/tmp/teem
git clone https://git.code.sf.net/p/teem/nrrdio/nrrdio.git ${NRRDIO_SRC_ROOT}
git clone ssh://hjmjohnson@git.code.sf.net/p/teem/teem.git  ${TEEM_SRC_ROOT}
cp ${NRRDIO_SRC_ROOT}/*.py ${NRRDIO_SRC_ROOT}/*.sh ${NRRDIO_SRC_ROOT}/*.in ${ITK_SOURCE_ROOT}/Modules/ThirdParty/NrrdIO/src/NrrdIO
cd ${ITK_SOURCE_ROOT}/Modules/ThirdParty/NrrdIO/src/NrrdIO
TEEM_SRC_ROOT=${TEEM_SRC_ROOT} ./0-gen.sh itk # <- this extracts nrrdio from teem code with itk mangling
```

These changes represent the head of NrrdIO as of 2026-1-17, with
synchronization between the ITK codebase and the NrrdIO codebase.
@hjmjohnson hjmjohnson force-pushed the update-nrrdio-upstream branch from 30405c8 to 8cb80e6 Compare January 20, 2026 22:26
@hjmjohnson hjmjohnson marked this pull request as ready for review January 21, 2026 18:48
@hjmjohnson hjmjohnson requested a review from dzenanz January 21, 2026 18:49
@hjmjohnson hjmjohnson self-assigned this Jan 21, 2026
@hjmjohnson hjmjohnson added area:IO Issues affecting the IO module area:ThirdParty Issues affecting the ThirdParty module labels Jan 21, 2026
@hjmjohnson hjmjohnson added this to the ITK 6.0 Beta 2 milestone Jan 21, 2026
@hjmjohnson
Copy link
Copy Markdown
Member Author

hjmjohnson commented Jan 21, 2026

@kindlmann. I have finally returned to this and replaced nrrdio in ITK with the latest version from Jan 2026. There is very little that changes in the c code from upstream nrrdio and ITK files:

  1. Add the following to NrrdIO.h
/* THE FOLLOWING INCLUDE IS ONLY FOR THE ITK DISTRIBUTION.  
     This header mangles the symbols in the NrrdIO library, preventing 
     conflicts in applications linked against two versions of NrrdIO. */    
  #include "itk_NrrdIO_mangle.h"         
  1. Change

'# include <zlib.h>'
to
' # include "itk_zlib.h" ' in privateNrrd.h

Hans

Copy link
Copy Markdown
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

Changes mostly look good. I am compiling this locally.

add_definitions(-DTEEM_BUILD=1)

set(NRRDIO_COMPRESSION_LIBRARIES "")
if ( NOT "${NRRDIO_PREFIX}" STREQUAL "ITK" ) # <-- ITK START_REMOVE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this comment be # <-- ITK START_REPLACE?

@dzenanz dzenanz requested a review from blowekamp January 21, 2026 20:27
@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Jan 21, 2026

This might interact with changes in PR #5721.

@blowekamp
Copy link
Copy Markdown
Member

This might interact with changes in PR #5721.

My current working local changes keep the directory properties for third party libraries. Making third party modules more targets based is being separated.

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Jan 21, 2026

Most projects fail to build locally due to this missing symbol:

Build started at 15:56...
1>------ Build started: Project: ITKCommon1TestDriver, Configuration: RelWithDebInfo x64 ------
1>   Creating library C:/Dev/ITK-vs22/lib/RelWithDebInfo/ITKCommon1TestDriver.lib and object C:/Dev/ITK-vs22/lib/RelWithDebInfo/ITKCommon1TestDriver.exp
1>ITKIONRRD-6.0.lib(itkNrrdImageIO.obj) : error LNK2001: unresolved external symbol airFloatQNaN
1>C:\Dev\ITK-vs22\bin\RelWithDebInfo\ITKCommon1TestDriver.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "ITKCommon1TestDriver.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 58 up-to-date, 0 skipped ==========
========== Build completed at 15:56 and took 03.203 seconds ==========

This is an incremental, in-place build. I guess that matter?
Build: 158 succeeded, 357 failed, 474 up-to-date, 10 skipped

@hjmjohnson
Copy link
Copy Markdown
Member Author

Most projects fail to build locally due to this missing symbol:

Build started at 15:56...
1>------ Build started: Project: ITKCommon1TestDriver, Configuration: RelWithDebInfo x64 ------
1>   Creating library C:/Dev/ITK-vs22/lib/RelWithDebInfo/ITKCommon1TestDriver.lib and object C:/Dev/ITK-vs22/lib/RelWithDebInfo/ITKCommon1TestDriver.exp
1>ITKIONRRD-6.0.lib(itkNrrdImageIO.obj) : error LNK2001: unresolved external symbol airFloatQNaN
1>C:\Dev\ITK-vs22\bin\RelWithDebInfo\ITKCommon1TestDriver.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "ITKCommon1TestDriver.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 58 up-to-date, 0 skipped ==========
========== Build completed at 15:56 and took 03.203 seconds ==========

This is an incremental, in-place build. I guess that matter? Build: 158 succeeded, 357 failed, 474 up-to-date, 10 skipped

I think it does matter. I needed to do a clean build on windows. There is a NrrdIO.h in your build tree that likely needs to be removed. It used to be configured, but is no longer needed to be configured.

@hjmjohnson
Copy link
Copy Markdown
Member Author

@dzenanz I have local builds working on windows and mac and the CI is passing. Do you think we need to add something like

if (EXISTS ${CMAKE_BUILD_DIR}/NrrdIO.h)
  file(REMOVE ${CMAKE_BUILD_DIR}/NrrdIO.h)
endif()

to deal with the incremental build issue?

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Jan 21, 2026

That would be helpful. After removing C:\Dev\ITK-vs22\Modules\ThirdParty\NrrdIO\src\NrrdIO\NrrdIO.h, the build succeeds:

Build started at 17:27...
1>------ Build started: Project: ITKIONRRD, Configuration: RelWithDebInfo x64 ------
1>  itkNrrdImageIO.cxx
1>  ITKIONRRD.vcxproj -> C:\Dev\ITK-vs22\lib\RelWithDebInfo\ITKIONRRD-6.0.lib
2>------ Build started: Project: ITKCommon1TestDriver, Configuration: RelWithDebInfo x64 ------
2>     Creating library C:/Dev/ITK-vs22/lib/RelWithDebInfo/ITKCommon1TestDriver.lib and object C:/Dev/ITK-vs22/lib/RelWithDebInfo/ITKCommon1TestDriver.exp
2>  ITKCommon1TestDriver.vcxproj -> C:\Dev\ITK-vs22\bin\RelWithDebInfo\ITKCommon1TestDriver.exe
========== Build: 2 succeeded, 0 failed, 57 up-to-date, 0 skipped ==========
========== Build completed at 17:27 and took 31.819 seconds ==========

@blowekamp
Copy link
Copy Markdown
Member

to deal with the incremental build issue?

I don't think it's realistic to support incremental build like this, in general. It can add a lot of bloat to the CMake code that is difficult to figure out out down the road.

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Jan 21, 2026

Good point Brad. This is a one-time incremental build breakage. Finding and removing the offending file is not hard, and clean builds don't have this problem.

@hjmjohnson hjmjohnson merged commit 9d31936 into main Jan 21, 2026
17 checks passed
@hjmjohnson hjmjohnson deleted the update-nrrdio-upstream branch January 21, 2026 22:54
@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Jan 21, 2026

Thank you Hans for this big update! And also @kindlmann!

@N-Dekker
Copy link
Copy Markdown
Contributor

I locally encounter the following link errors, using VS2022 (Debug):

ITKIONRRD-6.0.lib(itkNrrdImageIO.obj) : error LNK2001: unresolved external symbol airFloatQNaN

Any clue?

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Jan 23, 2026

Hans already answered it. Removing the outdated header from build dir fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:IO Issues affecting the IO module area:ThirdParty Issues affecting the ThirdParty module type:Enhancement Improvement of existing methods or implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants