# ITK not loading NRRD files any more

**URL:** https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224
**Category:** Engineering
**Created:** [June 21, 2021, 2:37pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224 "2021-06-21T14:37:35Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Fijoy\_Vadakkumpadan](https://discourse.itk.org/user_avatar/discourse.itk.org/fijoy_vadakkumpadan/32/1287_2.png) [@Fijoy\_Vadakkumpadan](https://discourse.itk.org/u/Fijoy_Vadakkumpadan)
#### Post date: [June 21, 2021, 2:37pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/1 "2021-06-21T14:37:36Z")

</div>

Hello,

Does ITK no longer fully support NRRD files?

I’m trying to upgrade the ITK version in my application from 4.10.1 to 5.1.1. Unfortunately, the new ITK version is throwing a floating point exception when attempting to load NRRD files. The exception occurs in this routine:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/c2b399eef1248465a848a26231de66a8c9715132/Modules/ThirdParty/NrrdIO/src/NrrdIO/simple.c#L1358>

I tried both GCC and ICC build of ITK 5.1.1, as well as ITK 5.2, but the problem persists. Strangely, my ITK builds are saving NRRD files successfully, but fails to load NRRD files, including the NRRD files they themselves save. As an example, the NRRD file linked below was saved by one my ITK builds, but the same ITK build fails to load it.  
[0.nrrd](https://discourse.itk.org/uploads/short-url/v8hbIuepE82B2KfECpsyhzY8rO9.nrrd) (350.2 KB)

Is anyone else seeing this issue? Any ideas as to how to resolve this error?

Thanks.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 21, 2021, 2:55pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/2 "2021-06-21T14:55:50Z")

</div>

I successfully opened `0.nrrd` in Slicer 4.11.20210226 which uses [ITK 5.1.2](https://github.com/Slicer/Slicer/blob/7a593c83780166ff9f43f002302e431c9deac06d/SuperBuild/External_ITK.cmake#L39), so I think this is something specific to your computer or compilation. Mixing GCC and ICC can cause problems. What is the exception message?

---

<div class="post-metadata">

### Author: ![Fijoy\_Vadakkumpadan](https://discourse.itk.org/user_avatar/discourse.itk.org/fijoy_vadakkumpadan/32/1287_2.png) [@Fijoy\_Vadakkumpadan](https://discourse.itk.org/u/Fijoy_Vadakkumpadan)
#### Post date: [June 21, 2021, 3:41pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/3 "2021-06-21T15:41:08Z")

</div>

Thanks for looking into it. The exception message is:

SIGFPE(0x4) - Floating point exception.  
[43311] at 0x00007F7E270DD443 :itk\_\_airSanityHelper (+0x3)

Both my ITK and application are built using ICC.

The machine I’m using is an Intel(R) Xeon(R) CPU E5-2450 v2 @ 2.50GHz. Below is my CMakeCache.txt file saved by ccmake containing the build options I used.  
[CMakeCache.txt](https://discourse.itk.org/uploads/short-url/oUoGW6zu2rWdtKeZ4kcRmIbCMxs.txt) (177.3 KB)

I do see some options in this file about NRRD. Should I be changing them? I didn’t see them as options to change when I ran the ccmake command (even after toggling advanced options), but I can try again.

Anything else I can experiment with?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 21, 2021, 5:03pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/4 "2021-06-21T17:03:38Z")

</div>

This has more to do with [floating point exceptions](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkFloatingPointExceptions.h) than with NRRD format. Maybe you gave some special floating-point related compiler options to ICC? Maybe ICC has different defaults from GCC?

---

<div class="post-metadata">

### Author: ![Fijoy\_Vadakkumpadan](https://discourse.itk.org/user_avatar/discourse.itk.org/fijoy_vadakkumpadan/32/1287_2.png) [@Fijoy\_Vadakkumpadan](https://discourse.itk.org/u/Fijoy_Vadakkumpadan)
#### Post date: [June 22, 2021, 8:36pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/5 "2021-06-22T20:36:40Z")

</div>

Thanks @dzenanz for the direction.

I have localized the issue to the source line below, which gets invoked with val set to DBL\_MAX (1.79769313486231571e+308).

> <https://github.com/InsightSoftwareConsortium/ITK/blob/047fa6934ac32711d1d7b84fa6eb81c72db01960/Modules/ThirdParty/NrrdIO/src/NrrdIO/miscAir.c#L52>

Based on my research so far, it seems that the NRRD IO module is expecting the \_airSanityHelper() routine to return Nan or Infinity, perhaps in compliance with IEEE 754. Like you said, it also seems there must be some compiler option I can set to get ICC to comply.

The only compiler options I was using were:  
–cache\_dir\_contents and -std=c++11 for CMAKE\_CXX\_FLAGS  
–cache\_dir\_contents -std=gnu99 for CMAKE\_C\_FLAGS

Based on research about getting ICC to comply with the IEEE standard, I tried adding the “-fp-model precise” option to the above, but that did not help. I had also tried compiling ITK with GCC and default options, and that had the same floating point exception issue.

Do you know what the \_airSanityHelper() routine expects here exactly?

Any specific compiler flags, or other ideas I can try?

Thanks.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 23, 2021, 12:52pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/6 "2021-06-23T12:52:26Z")

</div>

> [@Fijoy\_Vadakkumpadan](#):
>
> –cache\_dir\_contents -std=gnu99 for CMAKE\_C\_FLAGS

Can you change this to be the same as CXX flags, or remove it? `miscAir.c` is a C file. Or perhaps set it to C99 instead of GNU99?

---

<div class="post-metadata">

### Author: ![Fijoy\_Vadakkumpadan](https://discourse.itk.org/user_avatar/discourse.itk.org/fijoy_vadakkumpadan/32/1287_2.png) [@Fijoy\_Vadakkumpadan](https://discourse.itk.org/u/Fijoy_Vadakkumpadan)
#### Post date: [June 23, 2021, 11:56pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/7 "2021-06-23T23:56:47Z")

</div>

Hi @dzenanz,

After additional research and experimentation, I have isolated the issue to ITK’s FloatingPointExceptions class. Specifically, the itk::FloatingPointExceptions::Disable() function doesn’t disable exceptions, though the itk::FloatingPointExceptions:: HasFloatingPointExceptionsSupport() returns true.

The NRRD IO module actually attempts to disable the exceptions before calling sanity checks, here:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/384fc45b0cb08e7651ba5cbd8d8ae38f6ff92559/Modules/IO/NRRD/src/itkNrrdImageIO.cxx#L277>

But it’s ineffective in my case.

To confirm, I disabled the floating point exceptions myself in my application using the fenv.h API as demonstrated here:  
[https://www.visitusers.org/index.php?title=Suppressing\_Floating\_Point\_Exceptions](https://www.visitusers.org/index.php?title=Suppressing_Floating_Point_Exceptions)

The exceptions then disappeared, and I was able to load the NRRD file succesfully.

Perhaps there’s a bug in the itk::FloatingPointExceptions::Disable() function?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 23, 2021, 11:59pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/8 "2021-06-23T23:59:28Z")

</div>

@jcfr I think you last fiddled with floating point exceptions. Does anything in this case ring a bell?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 24, 2021, 12:58pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/9 "2021-06-24T12:58:11Z")

</div>

Does [PR 2612](https://github.com/InsightSoftwareConsortium/ITK/pull/2612) help you?

---

<div class="post-metadata">

### Author: ![Fijoy\_Vadakkumpadan](https://discourse.itk.org/user_avatar/discourse.itk.org/fijoy_vadakkumpadan/32/1287_2.png) [@Fijoy\_Vadakkumpadan](https://discourse.itk.org/u/Fijoy_Vadakkumpadan)
#### Post date: [June 24, 2021, 2:34pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/10 "2021-06-24T14:34:56Z")

</div>

@dzenanz, thanks for continuing to look into this.

I’m not sure if that commit will resolve the issue. Looking at the code, itk::FloatingPointExceptions::Disable() seems to end up calling the fenv.h API function fedisableexcept() with specific flags FE\_DIVBYZERO and FE\_INVALID. That is assuming ITK\_HAS\_FEENABLEEXCEPT is defined, which is true in my case (see my CMakeCache.txt file attached above).

But, as per the doc for itk::FloatingPointExceptions::Disable(), the call is supposed to disable all floating point exceptions, including FE\_OVERFLOW, which seems to be one of the exceptions the NRRD IO module will cause when it does a DBL\_MAX\*DBL\_MAX operation. So, the itk::FloatingPointExceptions::Disable() routine should call fedisableexcept() with the FE\_ALL\_EXCEPT flag, instead of 2 specific exception flags.

Does that make sense?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 24, 2021, 3:11pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/11 "2021-06-24T15:11:00Z")

</div>

The best course of action here seems to be for you to make a PR which fixes your problem. That seems to be `itk::FloatingPointExceptions::Disable()` to disable all floating point exceptions?

---

<div class="post-metadata">

### Author: ![Fijoy\_Vadakkumpadan](https://discourse.itk.org/user_avatar/discourse.itk.org/fijoy_vadakkumpadan/32/1287_2.png) [@Fijoy\_Vadakkumpadan](https://discourse.itk.org/u/Fijoy_Vadakkumpadan)
#### Post date: [June 24, 2021, 8:43pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/12 "2021-06-24T20:43:22Z")

</div>

Yep. Sure, I may have one of my teammates do the PR. We’ll keep this thread updated on the progress. Thanks for your help @dzenanz.

---

<div class="post-metadata">

### Author: ![Courtney\_Ambrozic](https://discourse.itk.org/user_avatar/discourse.itk.org/courtney_ambrozic/32/651_2.png) [@Courtney\_Ambrozic](https://discourse.itk.org/u/Courtney_Ambrozic)
#### Post date: [September 17, 2021, 2:54pm UTC](https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/13 "2021-09-17T14:54:29Z")

</div>

This PR was created and committed with the appropriate fix:

> <https://github.com/InsightSoftwareConsortium/ITK/commit/cd3f05eb0b0233f7d8a4e960ccc0b3b2a91f2fb1>
>
> itk::FloatingPointExceptions::Disable()
> 
> In this commit, a flag is added to disa…ble all floating point exceptions, rather than just two exceptions. This bug was identified in the following discussion thread: https://discourse.itk.org/t/itk-not-loading-nrrd-files-any-more/4224/10. This fix will resolve an exception that occurs when loading NRRD images.
