Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
81f9f39
ENH: Adding Remote Module for ITKv4
hjmjohnson May 16, 2013
4f8451a
STYLE: Useless ITK deprecated define removed.
hjmjohnson Jun 1, 2013
2dd1b9f
STYLE: Remove "ITK" from the module name.
XiaoxiaoLiu Aug 26, 2013
11008b5
ENH: Remote module is OFF by default.
XiaoxiaoLiu Aug 26, 2013
2c9b62a
STYLE: Clean up unnecesssary cmake script.
XiaoxiaoLiu Aug 26, 2013
2331f0d
BUG: Remove ITKTransform dependency.
XiaoxiaoLiu Aug 26, 2013
3abea84
Merge pull request #1 from XiaoxiaoLiu/master
hjmjohnson Aug 27, 2013
e7d661f
FIX: ITK warnings of deprecated EXCLUDE_FROM_ALL.
XiaoxiaoLiu Sep 12, 2013
b722dfa
Merge pull request #2 from XiaoxiaoLiu/master
hjmjohnson Sep 12, 2013
1c9f995
BUG: missing steps converting origin back to freesurfer space
Sep 20, 2013
8e6f38b
COMP: Add test for origin writing fix
Sep 24, 2013
01889c0
Merge pull request #3 from Chaircrusher/WriteOriginBug
Sep 24, 2013
42a2c55
COMP: fix precision of distance between origins test
Sep 24, 2013
a3a39c5
BUG: refine CanReadFile in MGHImageIO
Sep 25, 2013
536599b
BUG: as;dlfkj
Sep 25, 2013
d7e184c
BUG: refine CanReadFile in MGHImageIO
Sep 25, 2013
907889b
Merge branch 'master' of https://github.com/Slicer/itkMGHImageIO
Sep 25, 2013
aa33def
COMP: Disallow '.gz' extension
Oct 2, 2013
de832fd
DOC: fix comment
Oct 2, 2013
f30929e
BUG: Valgrind memory leak.
hjmjohnson Jan 31, 2014
82997ae
BUG: Fix KWStyle error for header guarder
blowekamp Mar 31, 2015
f76a905
Merge pull request #4 from blowekamp/master
jcfr Mar 31, 2015
66abfdc
ENH: Add ITK_OVERRIDE and ITK_NULLPTR designations
hjmjohnson Jun 9, 2015
93a2a01
Merge pull request #5 from Slicer/ITK_OVERRIDE_ITK_NULLPTR
hjmjohnson Jun 9, 2015
c801047
BUG: Fix KWStyle error for header guarderd in test
hjmjohnson Jul 9, 2015
3adcf22
Merge pull request #6 from Slicer/FixAnotherHeaderGuardStyle
hjmjohnson Jul 9, 2015
7616415
STYLE: Use ITK naming conventions for MGHIO.
hjmjohnson Jul 10, 2015
ce578aa
STYLE: Revert Use ITK naming conventions for MGHIO
hjmjohnson Jul 12, 2015
f69071e
COMP: Make MGHIO a shared libary
hjmjohnson Jul 12, 2015
21100ef
BUG: Test case was not verifying meta-data
hjmjohnson Jul 16, 2015
c6517e1
BUG: Correct DirectionCosine Interpretation
hjmjohnson Jul 16, 2015
3524aab
ENH: Improve TWrite for implicit type conversion
hjmjohnson Jul 16, 2015
0abd64d
ENH: Improve numerical statibility
hjmjohnson Jul 16, 2015
6faa792
BUG: MGH File writing bug fixed
hjmjohnson Jul 16, 2015
9e9ed60
Merge pull request #8 from Slicer/FIX_MGH
hjmjohnson Jul 16, 2015
d65651a
STYLE: Remove ITK style warning
hjmjohnson Jul 16, 2015
c2002a8
BUG: Ensure factory is registered once.
jcfr Dec 4, 2015
cee9f09
Merge pull request #9 from jcfr/3393-transform-image-io-as-shared
jcfr Dec 4, 2015
7dd9b36
STYLE: Use Macro for Function Deletion
zachary-williamson Jun 30, 2016
f30d9a3
Merge pull request #10 from zachary-williamson/master
hjmjohnson Jun 30, 2016
42138ee
ENH: Add FACTORY_NAMES parameter to itk_module() declaration
Oct 26, 2017
c863a12
ENH: Module can now be build as an external remote module
Nov 13, 2017
1980b1c
Merge pull request #11 from fbudin69500/Add_FACTORY_NAMES
jcfr Nov 13, 2017
3fae98f
ENH: Initial ITKv5 conversions.
hjmjohnson Dec 16, 2017
702a91e
ENH: ITKv5 override consistency
hjmjohnson Dec 17, 2017
7ddb9ff
COMP: Use C++11 override directly
hjmjohnson Dec 17, 2017
0a176ce
COMP: Use C++11 nullptr directly
hjmjohnson Dec 17, 2017
f75ae0e
ENH: Require cmake minimum version to be 3.9.5.
Jan 19, 2018
dc95823
Merge pull request #13 from Slicer/ITKv5
hjmjohnson Feb 12, 2018
a38a2ba
Merge pull request #12 from jhlegarreta/ChangeRequiredCMakeMinimumVer…
hjmjohnson Feb 12, 2018
aa480fc
STYLE: Modernize to C++11 conventions
hjmjohnson Feb 12, 2018
50be0bd
Merge pull request #18 from Slicer/ITKv5Style
hjmjohnson Feb 12, 2018
67e11de
STYLE: Prefer C++11 type alias over typedef
hjmjohnson Feb 13, 2018
9796d1b
Merge pull request #19 from Slicer/ITKv5Style
hjmjohnson Feb 13, 2018
4a5d523
STYLE: Prefer constexpr for const numeric literals
hjmjohnson Feb 13, 2018
d32d4f7
Merge pull request #20 from Slicer/ITKv5Style
hjmjohnson Feb 13, 2018
94f7003
COMP: Move ITK_DISALLOW_COPY_AND_ASSIGN calls to public section.
Apr 14, 2018
a749862
Merge pull request #21 from jhlegarreta/MoveDISALLOWCOPYANDASSIGNToPu…
hjmjohnson Apr 14, 2018
6268b04
COMP: Set the minimum required CMake version to 3.10.2.
May 5, 2018
6fca69e
Merge pull request #22 from jhlegarreta/UpdateCMakeMinimumRequiredVer…
thewtex May 6, 2018
3d69768
ENH: Add .gitattributes to allow running ITK clang-formatting scripts
hjmjohnson Feb 19, 2020
c4ab54a
ENH: Fix new enum changes from ITK and failed KWStyle test.
mseng10 Feb 18, 2020
2326be9
STYLE: Remove redundant void argument lists
hjmjohnson Feb 17, 2020
363a4fe
STYLE: Make prototype match definition names
hjmjohnson Feb 17, 2020
000000f
STYLE: Replace integer literals which are cast to bool.
hjmjohnson Feb 17, 2020
652e1ba
STYLE: Prefer = default to explicitly trivial implementations
hjmjohnson Feb 17, 2020
0f0ed34
STYLE: Remove redundant void argument lists
hjmjohnson Feb 17, 2020
f320627
PERF: readability container size empty
hjmjohnson Feb 18, 2020
019ee6d
DOC: Update copyright assignment to NumFOCUS
hjmjohnson Feb 19, 2020
e6ece2e
ENH: Make similar to template
hjmjohnson Feb 29, 2020
fab9d08
Merge pull request #23 from Slicer/ITKv5_1rc2
hjmjohnson Feb 29, 2020
a96deb6
STYLE: Rename ITK_DISALLOW_COPY_AND_ASSIGN to ITK_DISALLOW_COPY_AND_MOVE
mseng10 Oct 14, 2020
e069a8a
STYLE: Prefer itk::Math::abs for consistency.
hjmjohnson Dec 17, 2021
ee3ff52
STYLE: Standardize parameter names to argc and *argv[], replace ac/av
dzenanz Feb 15, 2022
fe9374d
ENH: Bump ITK and change http to https
tbirdso May 31, 2022
12490ee
BUG: Use the literal superclass name in itkTypeMacro
jhlegarreta Nov 11, 2023
3e5d7d8
COMP: Use modern macro for name of class
hjmjohnson Jan 25, 2025
c37212f
STYLE: Update clang-format to match ITK 2025-11-10
hjmjohnson Nov 10, 2025
fd120c3
ENH: Modernize CMake to use itk_module_add_library
blowekamp Jan 27, 2026
9cc6180
Merge pull request #46 from InsightSoftwareConsortium/modernize-cmake…
blowekamp Jan 27, 2026
c6448a2
ENH: Convert from md5 to .cid tags. (#49)
hjmjohnson Apr 23, 2026
674e55d
ENH: Ingest ITKMGHIO into Modules/IO
hjmjohnson Apr 27, 2026
94b0aa9
DOC: Add README.md pointing at archived upstream for MGHIO
hjmjohnson Apr 27, 2026
eb67aa4
COMP: Remove MGHIO.remote.cmake; now in-tree
hjmjohnson Apr 27, 2026
1505878
ENH: Enable MGHIO in CI via configure-ci
hjmjohnson Apr 27, 2026
bae17f6
COMP: Fix normalize-ingest-commits.py merge-commit handling
hjmjohnson Apr 27, 2026
a180130
STYLE: Simplify Modules/IO/MGHIO/CMakeLists.txt to in-tree pattern
hjmjohnson Apr 27, 2026
ca6487a
STYLE: Apply pre-commit fixes to MGHIO test CMakeLists.txt
hjmjohnson Apr 27, 2026
0b37537
STYLE: Apply gersemi to remaining MGHIO CMake files
hjmjohnson Apr 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Modules/IO/MGHIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project(MGHIO)
set(MGHIO_LIBRARIES MGHIO)
itk_module_impl()
66 changes: 66 additions & 0 deletions Modules/IO/MGHIO/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# MGHIO

In-tree ITK module providing an `itk::MGHImageIO` plugin for the
`.mgh` / `.mgz` (MGH) volume format used by the FreeSurfer
neuroimaging toolchain. The factory `itk::MGHImageIOFactory`
auto-registers with `itk::ImageIOFactory` so any
`itk::ImageFileReader` / `itk::ImageFileWriter` transparently picks
up `.mgh` / `.mgz` files when the module is enabled.

## Origin

Ingested from the standalone remote module
[**InsightSoftwareConsortium/itkMGHImageIO**](https://github.com/InsightSoftwareConsortium/itkMGHImageIO)
on 2026-04-27, at upstream commit
[`af74507c`](https://github.com/InsightSoftwareConsortium/itkMGHImageIO/commit/af74507c1ddc82722637c37d1f5d169e3000553a).
The upstream repository will be archived read-only after this PR
merges; it remains reachable at the URL above.

## What lives here

Per the v3 ingestion strategy (see
`Utilities/Maintenance/RemoteModuleIngest/INGESTION_STRATEGY.md`), only
paths matching the narrow whitelist (code, headers, tests, wrapping,
module CMake) crossed the merge boundary:

- `include/` — public C++ headers (`itkMGHImageIO.h`, `itkMGHImageIOFactory.h`).
- `src/` — non-template implementation.
- `test/` — CTest drivers and content-link stubs.
- `wrapping/` — Python wrapping descriptors.
- `CMakeLists.txt`, `itk-module.cmake` — build + module descriptors.

Every surviving commit preserves original authorship; `git blame`
walks across the merge boundary to upstream authors going back to the
module's earliest history.

## What was intentionally left upstream

Everything outside the whitelist stays in the archived upstream repo.
If you need any of it, clone
<https://github.com/InsightSoftwareConsortium/itkMGHImageIO>.

| Content in upstream | Why it did not ingest |
|---|---|
| `.github/`, `azure-pipelines.yml`, `Dockerfile` | Standalone-build CI scaffolding; not useful in-tree. |
| `CTestConfig.cmake`, `pyproject.toml`, `LICENSE`, `.clang-format` | Packaging / CI / style scaffolding superseded by ITK root. |
| Historical `Old/`, `paper/`, `docs/`, demo asset trees | Stripped by the whitelist to protect ITK's git pack from bloat. |

## Long-form documentation

- **Format reference** — see the FreeSurfer documentation:
<https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat>.
- **Standalone build + history** — see the archived upstream at
<https://github.com/InsightSoftwareConsortium/itkMGHImageIO>.

## Compliance level

Compliance Level 2 (Alpha — niche execution environment dependence:
FreeSurfer-format I/O). Carried forward from the
`MODULE_COMPLIANCE_LEVEL 2` declaration in the previous
`Modules/Remote/MGHIO.remote.cmake`.

## Content-link status

The 3 input content-links under `test/MD5/` are already in `.cid`
(IPFS Content Identifier) form; no `.md5` → `.cid` normalization is
required for this module.
160 changes: 160 additions & 0 deletions Modules/IO/MGHIO/include/itkMGHImageIO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

#ifndef itkMGHImageIO_h
#define itkMGHImageIO_h

#include "itkMatrix.h"
#include "itkImageIOBase.h"
#include <fstream>
#include "itk_zlib.h"

#include "MGHIOExport.h"

namespace itk
{
/** \class MGHImageIO
*
* \author Hans J. Johnson
* \brief Class that defines how to read MGH file format.
* Originally developed as part of the Slicer software
* package under grants XXXX
*
* \ingroup IOFilters
* \ingroup MGHIO
*/
class MGHIO_EXPORT MGHImageIO : public ImageIOBase
{
Comment thread
hjmjohnson marked this conversation as resolved.
public:
/** Standard class type alias. */
using Self = MGHImageIO;
using Superclass = ImageIOBase;
using Pointer = SmartPointer<Self>;

/** Method for creation through the object factory. */
itkNewMacro(Self);

/** Run-time type information (and related methods). */
itkOverrideGetNameOfClassMacro(MGHImageIO);

/*-------- This part of the interfaces deals with reading data. ----- */

/** Determine if the file can be read with this ImageIO implementation.
* \param FileNameToRead The name of the file to test for reading.
* \post Sets classes ImageIOBase::m_FileName variable to be FileNameToWrite
* \return Returns true if this ImageIO can read the file specified.
*/
bool
CanReadFile(const char * FileNameToRead) override;

/** Set the spacing and dimension information for the set filename. */
void
ReadImageInformation() override;

/** Reads the data from disk into the memory buffer provided. */
void
Read(void * pData) override;

/*-------- This part of the interfaces deals with writing data. ----- */

/** Determine if the file can be written with this ImageIO implementation.
* \param FileNameToWrite The name of the file to test for writing.
* \post Sets classes ImageIOBase::m_FileName variable to be FileNameToWrite
* \return Returns true if this ImageIO can write the file specified.
*/
bool
CanWriteFile(const char * name) override;

/** Set the spacing and dimension information for the set filename. */
void
WriteImageInformation() override;

/** Writes the data to disk from the memory buffer provided. Make sure
* that the IORegions has been set properly. */
void
Write(const void * buffer) override;

protected:
MGHImageIO();
~MGHImageIO() override;
void
PrintSelf(std::ostream & os, Indent indent) const override;

void
ReadVolumeHeader();

private:
static const int MRI_UCHAR = 0;
static const int MRI_INT = 1;
static const int MRI_FLOAT = 3;
static const int MRI_SHORT = 4;
static const int MRI_TENSOR = 6;
static const unsigned int FS_DIMENSION_HEADER_SIZE = sizeof(int) * 7;
static const unsigned int FS_RAS_HEADER_SIZE = (sizeof(float) * 15) + sizeof(short);
static const unsigned int FS_UNUSED_HEADER_SIZE = 256 - FS_RAS_HEADER_SIZE;
static const unsigned int FS_WHOLE_HEADER_SIZE =
FS_RAS_HEADER_SIZE + FS_DIMENSION_HEADER_SIZE + FS_UNUSED_HEADER_SIZE;

/** check if a filename is for a compressed file */
bool
IsCompressedFilename(const std::string fname);
/// processes the actual data buffer
void
SwapBytesIfNecessary(void * const buffer, const unsigned long numberOfPixels);

/// examines the direction cosines and creates encapsulation data
// void MriDirCos();

void
WriteHeader();

void
WriteData(const void * buffer);

void
PermuteFrameValues(const void * buffer, char * tempmemory);

unsigned int
GetComponentSize() const override;

std::string
GetOrientation(itk::Matrix<double> directions);

bool m_IsCompressed;
gzFile m_GZFile;
std::ofstream m_Output;

// Utility function to assist with writing to disk in the
// proper format. TInType is static_cast<TDiskType> type.
template <typename TInType, typename TDiskType>
int
TWrite(const TInType inValue);
template <typename TDiskType, typename TOutType>
int
TRead(TOutType & outValue);

int
TWrite(const char * buf, const unsigned long count);
void
OpenFile();
void
CloseFile();
};
} // end namespace itk

#endif // itkMGHImageIO_h
74 changes: 74 additions & 0 deletions Modules/IO/MGHIO/include/itkMGHImageIOFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

#ifndef itkMGHImageIOFactory_h
#define itkMGHImageIOFactory_h

#include "itkObjectFactoryBase.h"
#include "itkImageIOBase.h"

#include "MGHIOExport.h"

namespace itk
{
/** \class MGHImageIOFactory
* \brief Create instances of MGHImageIO objects using an object factory.
* \ingroup MGHIO
*/
class MGHIO_EXPORT MGHImageIOFactory : public ObjectFactoryBase
{
public:
ITK_DISALLOW_COPY_AND_MOVE(MGHImageIOFactory);

/** Standard class type alias */
using Self = MGHImageIOFactory;
using Superclass = ObjectFactoryBase;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;

/** Class methods used to interface with the registered factories **/
const char *
GetITKSourceVersion() const override;

const char *
GetDescription() const override;

/** Method for class instantiation **/
itkFactorylessNewMacro(Self);

/** Run-time type information (and related methods). */
itkOverrideGetNameOfClassMacro(MGHImageIOFactory);

/** Register one factory of this type */
static void
RegisterOneFactory()
{
MGHImageIOFactory::Pointer MGHFactory = MGHImageIOFactory::New();

ObjectFactoryBase::RegisterFactoryInternal(MGHFactory);
}

protected:
MGHImageIOFactory();
~MGHImageIOFactory() override;
void
PrintSelf(std::ostream & os, Indent indent) const override;
};
} // end namespace itk

#endif /// itkMGHImageIOFactory_h
20 changes: 20 additions & 0 deletions Modules/IO/MGHIO/itk-module.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(
DOCUMENTATION
"This modules contains an ImageIO class to read or write the
MGH file format that is an integral part of FreeSurfer based tools."
)

itk_module(
MGHIO
ENABLE_SHARED
DEPENDS
ITKIOImageBase
ITKZLIB
TEST_DEPENDS
ITKTestKernel
ITKTransform
EXCLUDE_FROM_DEFAULT
FACTORY_NAMES
ImageIO::MGH
DESCRIPTION "${DOCUMENTATION}"
)
7 changes: 7 additions & 0 deletions Modules/IO/MGHIO/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(
MGHIO_SRC
itkMGHImageIOFactory.cxx
itkMGHImageIO.cxx
)

itk_module_add_library(MGHIO ${MGHIO_SRC})
Loading
Loading