Skip to content
Snippets Groups Projects
Commit fd822951 authored by Ali Can Demiralp's avatar Ali Can Demiralp
Browse files

Merge branch 'develop'

parents c53e4e3a 7b021d82
Branches
Tags
No related merge requests found
################################################## Project ################################################## ################################################## Project ##################################################
cmake_minimum_required(VERSION 3.10 FATAL_ERROR) cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project (nifti VERSION 1.0 LANGUAGES CXX) project (nifti VERSION 1.0 LANGUAGES C)
list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set_property (GLOBAL PROPERTY USE_FOLDERS ON) set_property (GLOBAL PROPERTY USE_FOLDERS ON)
set (CMAKE_CXX_STANDARD 17) set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_VISIBILITY_PRESET hidden)
set (CMAKE_VISIBILITY_INLINES_HIDDEN 1)
include (set_max_warning_level) include (set_max_warning_level)
set_max_warning_level () set_max_warning_level ()
################################################## Options ################################################## ################################################## Options ##################################################
option(BUILD_SHARED_LIBS "Build shared (dynamic) libraries." ON)
option(BUILD_TESTS "Build tests." OFF) option(BUILD_TESTS "Build tests." OFF)
################################################## Sources ################################################## ################################################## Sources ##################################################
file(GLOB_RECURSE PROJECT_HEADERS include/*.h include/*.i include/*.hpp include/*.ipp) file(GLOB_RECURSE PROJECT_HEADERS include/*.h include/*.hpp)
file(GLOB_RECURSE PROJECT_SOURCES source/*.c source/*.cpp)
file(GLOB_RECURSE PROJECT_CMAKE_UTILS cmake/*.cmake) file(GLOB_RECURSE PROJECT_CMAKE_UTILS cmake/*.cmake)
file(GLOB_RECURSE PROJECT_MISC *.md *.txt) file(GLOB_RECURSE PROJECT_MISC *.md *.txt)
set (PROJECT_EXPORT_HPP include/${PROJECT_NAME}/export.hpp)
set (PROJECT_FILES set (PROJECT_FILES
${PROJECT_HEADERS} ${PROJECT_HEADERS}
${PROJECT_SOURCES}
${PROJECT_CMAKE_UTILS} ${PROJECT_CMAKE_UTILS}
${PROJECT_MISC}) ${PROJECT_MISC}
${PROJECT_EXPORT_HPP})
include (assign_source_group) include (assign_source_group)
assign_source_group(${PROJECT_FILES}) assign_source_group(${PROJECT_FILES})
...@@ -38,25 +45,31 @@ if (UNIX) ...@@ -38,25 +45,31 @@ if (UNIX)
list(APPEND PROJECT_COMPILE_DEFINITIONS -DHAVE_FDOPEN -DUSE_STAT) list(APPEND PROJECT_COMPILE_DEFINITIONS -DHAVE_FDOPEN -DUSE_STAT)
endif () endif ()
################################################## Targets ################################################## ################################################## Targets ##################################################
add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME} ${PROJECT_FILES})
target_include_directories(${PROJECT_NAME} INTERFACE target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>) $<INSTALL_INTERFACE:include> PRIVATE source)
target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_INCLUDE_DIRS}) target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDE_DIRS})
target_link_libraries (${PROJECT_NAME} INTERFACE ${PROJECT_LIBRARIES}) target_link_libraries (${PROJECT_NAME} PUBLIC ${PROJECT_LIBRARIES})
target_compile_definitions(${PROJECT_NAME} INTERFACE ${PROJECT_COMPILE_DEFINITIONS}) target_compile_definitions(${PROJECT_NAME} PUBLIC ${PROJECT_COMPILE_DEFINITIONS})
set_target_properties (${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
if(NOT BUILD_SHARED_LIBS)
string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS -D${PROJECT_NAME_UPPER}_STATIC)
endif()
# Hack for header-only project to appear in the IDEs. ################################################## Postbuild ##################################################
add_library(${PROJECT_NAME}_ STATIC ${PROJECT_FILES}) include (GenerateExportHeader)
target_include_directories(${PROJECT_NAME}_ PUBLIC string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
${CMAKE_CURRENT_SOURCE_DIR}/include generate_export_header(${PROJECT_NAME}
${CMAKE_CURRENT_BINARY_DIR}) EXPORT_FILE_NAME ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/export.hpp
target_include_directories(${PROJECT_NAME}_ PUBLIC ${PROJECT_INCLUDE_DIRS}) EXPORT_MACRO_NAME ${PROJECT_NAME_UPPER}_EXPORT
target_link_libraries (${PROJECT_NAME}_ PUBLIC ${PROJECT_LIBRARIES}) STATIC_DEFINE ${PROJECT_NAME_UPPER}_STATIC
target_compile_definitions(${PROJECT_NAME}_ PUBLIC ${PROJECT_COMPILE_DEFINITIONS}) )
set_target_properties (${PROJECT_NAME}_ PROPERTIES LINKER_LANGUAGE CXX)
################################################## Testing ################################################## ################################################## Testing ##################################################
if(BUILD_TESTS) if(BUILD_TESTS)
...@@ -79,7 +92,10 @@ if(BUILD_TESTS) ...@@ -79,7 +92,10 @@ if(BUILD_TESTS)
endif() endif()
################################################## Installation ################################################## ################################################## Installation ##################################################
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-config) install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-config
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
install(DIRECTORY include/ DESTINATION include) install(DIRECTORY include/ DESTINATION include)
install(EXPORT ${PROJECT_NAME}-config DESTINATION cmake) install(EXPORT ${PROJECT_NAME}-config DESTINATION cmake)
export (TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}-config.cmake) export (TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}-config.cmake)
...@@ -553,5 +553,3 @@ typedef struct { ...@@ -553,5 +553,3 @@ typedef struct {
/*=================*/ /*=================*/
#endif /* _NIFTI_IO_HEADER_ */ #endif /* _NIFTI_IO_HEADER_ */
#include "nifti1_io.i"
\ No newline at end of file
/** \file nifti2.h
\brief Header structure for NIFTI-2 format.
*/
#ifndef __NIFTI2_HEADER
#define __NIFTI2_HEADER
/*---------------------------------------------------------------------------*/
/* Changes to the header from NIFTI-1 to NIFTI-2 are intended to allow for
larger and more accurate fields. The changes are as follows:
- short dim[8] -> int64_t dim[8]
- float intent_p1,2,3 -> double intent_p1,2,3 (3 fields)
- float pixdim[8] -> double pixdim[8]
- float vox_offset -> int64_t vox_offset
- float scl_slope -> double scl_slope
- float scl_inter -> double scl_inter
- float cal_max -> double cal_max
- float cal_min -> double cal_min
- float slice_duration -> double slice_duration
- float toffset -> double toffset
- short slice_start -> int64_t slice_start
- short slice_end -> int64_t slice_end
- char slice_code -> int32_t slice_code
- char xyzt_units -> int32_t xyzt_units
- short intent_code -> int32_t intent_code
- short qform_code -> int32_t qform_code
- short sform_code -> int32_t sform_code
- float quatern_b,c,d -> double quatern_b,c,d (3 fields)
- float srow_x,y,z[4] -> double srow_x,y,z[4] (3 fields)
- char magic[4] -> char magic[8]
- char unused_str[15] -> padding added at the end of the header
- previously unused fields have been removed:
data_type, db_name, extents, session_error, regular, glmax, glmin
- the field order has been changed, notably with magic after sizeof_hdr
2 Jan, 2014 [rickr]
-----------------------------------------------------------------------------*/
#include <stdint.h>
/*=================*/
#ifdef __cplusplus
extern "C" {
#endif
/*=================*/
/*! \struct nifti_2_header
\brief Data structure defining the fields in the nifti2 header.
This binary header should be found at the beginning of a valid
NIFTI-2 header file.
*/
/* hopefully cross-platform solution to byte padding added by some compilers */
#pragma pack(push)
#pragma pack(1)
/*****************************/ /***********************/ /************/
struct nifti_2_header { /* NIFTI-2 usage */ /* NIFTI-1 usage */ /* offset */
/*****************************/ /***********************/ /************/
int32_t sizeof_hdr; /*!< MUST be 540 */ /* MUST be 348 */ /* 0 */
char magic[8]; /*!< MUST be valid signature */ /* char magic[4] */ /* 4 */
int16_t datatype; /*!< Defines data type! */ /* short datatype */ /* 12 */
int16_t bitpix; /*!< Number bits/voxel */ /* short bitpix */ /* 14 */
int64_t dim[8]; /*!< Data array dimensions */ /* short dim[8] */ /* 16 */
double intent_p1; /*!< 1st intent parameter */ /* float intent_p1 */ /* 80 */
double intent_p2; /*!< 2nd intent parameter */ /* float intent_p2 */ /* 88 */
double intent_p3; /*!< 3rd intent parameter */ /* float intent_p3 */ /* 96 */
double pixdim[8]; /*!< Grid spacings */ /* float pixdim[8] */ /* 104 */
int64_t vox_offset; /*!< Offset into .nii file */ /* float vox_offset */ /* 168 */
double scl_slope; /*!< Data scaling: slope */ /* float scl_slope */ /* 176 */
double scl_inter; /*!< Data scaling: offset */ /* float scl_inter */ /* 184 */
double cal_max; /*!< Max display intensity */ /* float cal_max */ /* 192 */
double cal_min; /*!< Min display intensity */ /* float cal_min */ /* 200 */
double slice_duration; /*!< Time for 1 slice */ /* float slice_duration*/ /* 208 */
double toffset; /*!< Time axis shift */ /* float toffset */ /* 216 */
int64_t slice_start; /*!< First slice index */ /* short slice_start */ /* 224 */
int64_t slice_end; /*!< Last slice index */ /* short slice_end */ /* 232 */
char descrip[80]; /*!< any text you like */ /* char descrip[80] */ /* 240 */
char aux_file[24]; /*!< auxiliary filename */ /* char aux_file[24] */ /* 320 */
int32_t qform_code; /*!< NIFTI_XFORM_* code */ /* short qform_code */ /* 344 */
int32_t sform_code; /*!< NIFTI_XFORM_* code */ /* short sform_code */ /* 348 */
double quatern_b; /*!< Quaternion b param */ /* float quatern_b */ /* 352 */
double quatern_c; /*!< Quaternion c param */ /* float quatern_c */ /* 360 */
double quatern_d; /*!< Quaternion d param */ /* float quatern_d */ /* 368 */
double qoffset_x; /*!< Quaternion x shift */ /* float qoffset_x */ /* 376 */
double qoffset_y; /*!< Quaternion y shift */ /* float qoffset_y */ /* 384 */
double qoffset_z; /*!< Quaternion z shift */ /* float qoffset_z */ /* 392 */
double srow_x[4]; /*!< 1st row affine transform*/ /* float srow_x[4] */ /* 400 */
double srow_y[4]; /*!< 2nd row affine transform*/ /* float srow_y[4] */ /* 432 */
double srow_z[4]; /*!< 3rd row affine transform*/ /* float srow_z[4] */ /* 464 */
int32_t slice_code; /*!< Slice timing order */ /* char slice_code */ /* 496 */
int32_t xyzt_units; /*!< Units of pixdim[1..4] */ /* char xyzt_units */ /* 500 */
int32_t intent_code; /*!< NIFTI_INTENT_* code */ /* short intent_code */ /* 504 */
char intent_name[16];/*!< name or meaning of data */ /* char intent_name[16]*/ /* 508 */
char dim_info; /*!< MRI slice ordering */ /* char dim_info */ /* 524 */
char unused_str[15]; /*!< unused, filled with \0 */ /* 525 */
}; /****** total bytes: 540 */
typedef struct nifti_2_header nifti_2_header;
/* restore packing behavior */
#pragma pack(pop)
/* base swap test on the suggested version check, rather than dim[0]
swap4(348)==1543569408, swap4(540)==469893120 */
#define NIFTI2_NEEDS_SWAP(h) \
((h).sizeof_hdr == 1543569408 || (h).sizeof_hdr == 469893120)
/*=================*/
#ifdef __cplusplus
}
#endif
/*=================*/
#endif /* __NIFTI2_HEADER */
/** \file nifti2_io.h
\brief Data structures for using nifti2_io API.
- Written by Bob Cox, SSCC NIMH
- Revisions by Rick Reynolds, SSCC NIMH
*/
#ifndef _NIFTI2_IO_HEADER_
#define _NIFTI2_IO_HEADER_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <ctype.h>
#ifndef DONT_INCLUDE_ANALYZE_STRUCT
#define DONT_INCLUDE_ANALYZE_STRUCT /*** not needed herein ***/
#endif
#include "nifti1.h" /*** NIFTI-1 header specification ***/
#include "nifti2.h" /*** NIFTI-2 header specification ***/
#include "znzlib.h"
/*=================*/
#ifdef __cplusplus
extern "C" {
#endif
/*=================*/
/*****===================================================================*****/
/***** File nifti2_io.h == Declarations for nifti2_io.c *****/
/*****...................................................................*****/
/***** This code is a modification of nifti1_io.h. *****/
/*****...................................................................*****/
/***** This code is released to the public domain. *****/
/*****...................................................................*****/
/***** Author: Robert W Cox, SSCC/DIRP/NIMH/NIH/DHHS/USA/EARTH *****/
/***** Date: August 2003 *****/
/*****...................................................................*****/
/***** Neither the National Institutes of Health (NIH), nor any of its *****/
/***** employees imply any warranty of usefulness of this software for *****/
/***** any purpose, and do not assume any liability for damages, *****/
/***** incidental or otherwise, caused by any use of this document. *****/
/*****===================================================================*****/
/* ......................................................................
Modified by: Mark Jenkinson (FMRIB Centre, University of Oxford, UK)
Date: July/August 2004
Mainly adding low-level IO and changing things to allow gzipped files
to be read and written
Full backwards compatability should have been maintained
......................................................................
Modified by: Rick Reynolds (SSCC/DIRP/NIMH, National Institutes of Health)
Date: December 2004
Modified and added many routines for I/O, particularly involving
extensions and nifti_brick_list.
......................................................................
Modified by: Rick Reynolds (SSCC/DIRP/NIMH, National Institutes of Health)
Date: August 2013
Converted to be based on nifti_2_header.
** NOT BACKWARD COMPATABLE **
These routines will read/write both NIFTI-1 and NIFTI-2 image files,
but modification to the _calling_ routies is necessary, since:
a. the main nifti_image type has changed (to nifti2_image)
b. some image field types have been altered (to have larger size)
c. some routines have been changed to apply to multiple NIFTI types
*/
/********************** Some sample data structures **************************/
typedef struct { /** 4x4 matrix struct **/
float m[4][4] ;
} mat44 ;
typedef struct { /** 3x3 matrix struct **/
float m[3][3] ;
} mat33 ;
typedef struct { /** 4x4 matrix struct (double) **/
double m[4][4] ;
} nifti_dmat44 ;
typedef struct { /** 3x3 matrix struct (double) **/
double m[3][3] ;
} nifti_dmat33 ;
/*...........................................................................*/
/*! \enum analyze_75_orient_code
* \brief Old-style analyze75 orientation
* codes.
*/
typedef enum _analyze75_orient_code {
a75_transverse_unflipped = 0,
a75_coronal_unflipped = 1,
a75_sagittal_unflipped = 2,
a75_transverse_flipped = 3,
a75_coronal_flipped = 4,
a75_sagittal_flipped = 5,
a75_orient_unknown = 6
} analyze_75_orient_code;
/*! \struct nifti_image
\brief High level data structure for open nifti datasets in the
nifti2_io API. Note that this structure is not part of the
nifti2 format definition; it is used to implement one API
for reading/writing datasets in the nifti1 or nifti2 formats.
Field types changed for NIFTI-2 (note: ALL floats to doubles):
nx, ny, ..., nw, dim, nvox,
dx, dy, ..., dw, pixdim,
scl_slope, scl_inter, cal_min, cal_max,
slice_start, slice_end, slice_duration,
quatern_b,c,d, qoffset_x,y,z, qfac,
qto_xyz,ijk, sto_xyz,ijk,
toffset, intent_p1,2,3, iname_offset
*/
typedef struct { /*!< Image storage struct **/
int64_t ndim ; /*!< last dimension greater than 1 (1..7) */
int64_t nx ; /*!< dimensions of grid array */
int64_t ny ; /*!< dimensions of grid array */
int64_t nz ; /*!< dimensions of grid array */
int64_t nt ; /*!< dimensions of grid array */
int64_t nu ; /*!< dimensions of grid array */
int64_t nv ; /*!< dimensions of grid array */
int64_t nw ; /*!< dimensions of grid array */
int64_t dim[8] ; /*!< dim[0]=ndim, dim[1]=nx, etc. */
int64_t nvox ; /*!< number of voxels = nx*ny*nz*...*nw */
int nbyper ; /*!< bytes per voxel, matches datatype */
int datatype ; /*!< type of data in voxels: DT_* code */
double dx ; /*!< grid spacings */
double dy ; /*!< grid spacings */
double dz ; /*!< grid spacings */
double dt ; /*!< grid spacings */
double du ; /*!< grid spacings */
double dv ; /*!< grid spacings */
double dw ; /*!< grid spacings */
double pixdim[8] ; /*!< pixdim[1]=dx, etc. */
double scl_slope ; /*!< scaling parameter - slope */
double scl_inter ; /*!< scaling parameter - intercept */
double cal_min ; /*!< calibration parameter, minimum */
double cal_max ; /*!< calibration parameter, maximum */
int qform_code ; /*!< codes for (x,y,z) space meaning */
int sform_code ; /*!< codes for (x,y,z) space meaning */
int freq_dim ; /*!< indexes (1,2,3, or 0) for MRI */
int phase_dim ; /*!< directions in dim[]/pixdim[] */
int slice_dim ; /*!< directions in dim[]/pixdim[] */
int slice_code ; /*!< code for slice timing pattern */
int64_t slice_start ; /*!< index for start of slices */
int64_t slice_end ; /*!< index for end of slices */
double slice_duration ; /*!< time between individual slices */
/*! quaternion transform parameters
[when writing a dataset, these are used for qform, NOT qto_xyz] */
double quatern_b , quatern_c , quatern_d ,
qoffset_x , qoffset_y , qoffset_z ,
qfac ;
nifti_dmat44 qto_xyz ; /*!< qform: transform (i,j,k) to (x,y,z) */
nifti_dmat44 qto_ijk ; /*!< qform: transform (x,y,z) to (i,j,k) */
nifti_dmat44 sto_xyz ; /*!< sform: transform (i,j,k) to (x,y,z) */
nifti_dmat44 sto_ijk ; /*!< sform: transform (x,y,z) to (i,j,k) */
double toffset ; /*!< time coordinate offset */
int xyz_units ; /*!< dx,dy,dz units: NIFTI_UNITS_* code */
int time_units ; /*!< dt units: NIFTI_UNITS_* code */
int nifti_type ; /*!< see NIFTI_FTYPE_* codes, below:
0==ANALYZE,
1==NIFTI-1 (1 file),
2==NIFTI-1 (2 files),
3==NIFTI-ASCII (1 file)
4==NIFTI-2 (1 file),
5==NIFTI-2 (2 files) */
int intent_code ; /*!< statistic type (or something) */
double intent_p1 ; /*!< intent parameters */
double intent_p2 ; /*!< intent parameters */
double intent_p3 ; /*!< intent parameters */
char intent_name[16] ; /*!< optional description of intent data */
char descrip[80] ; /*!< optional text to describe dataset */
char aux_file[24] ; /*!< auxiliary filename */
char *fname ; /*!< header filename (.hdr or .nii) */
char *iname ; /*!< image filename (.img or .nii) */
int64_t iname_offset ; /*!< offset into iname where data starts */
int swapsize ; /*!< swap unit in image data (might be 0) */
int byteorder ; /*!< byte order on disk (MSB_ or LSB_FIRST) */
void *data ; /*!< pointer to data: nbyper*nvox bytes */
int num_ext ; /*!< number of extensions in ext_list */
nifti1_extension * ext_list ; /*!< array of extension structs (with data) */
analyze_75_orient_code analyze75_orient; /*!< for old analyze files, orient */
} nifti_image ;
/* allow clarity */
typedef nifti_image nifti2_image;
typedef struct {
int ndim ; /*!< last dimension greater than 1 (1..7) */
int nx ; /*!< dimensions of grid array */
int ny ; /*!< dimensions of grid array */
int nz ; /*!< dimensions of grid array */
int nt ; /*!< dimensions of grid array */
int nu ; /*!< dimensions of grid array */
int nv ; /*!< dimensions of grid array */
int nw ; /*!< dimensions of grid array */
int dim[8] ; /*!< dim[0]=ndim, dim[1]=nx, etc. */
int64_t nvox ; /*!< number of voxels = nx*ny*nz*...*nw */
int nbyper ; /*!< bytes per voxel, matches datatype */
int datatype ; /*!< type of data in voxels: DT_* code */
float dx ; /*!< grid spacings */
float dy ; /*!< grid spacings */
float dz ; /*!< grid spacings */
float dt ; /*!< grid spacings */
float du ; /*!< grid spacings */
float dv ; /*!< grid spacings */
float dw ; /*!< grid spacings */
float pixdim[8] ; /*!< pixdim[1]=dx, etc. */
float scl_slope ; /*!< scaling parameter - slope */
float scl_inter ; /*!< scaling parameter - intercept */
float cal_min ; /*!< calibration parameter, minimum */
float cal_max ; /*!< calibration parameter, maximum */
int qform_code ; /*!< codes for (x,y,z) space meaning */
int sform_code ; /*!< codes for (x,y,z) space meaning */
int freq_dim ; /*!< indexes (1,2,3, or 0) for MRI */
int phase_dim ; /*!< directions in dim[]/pixdim[] */
int slice_dim ; /*!< directions in dim[]/pixdim[] */
int slice_code ; /*!< code for slice timing pattern */
int slice_start ; /*!< index for start of slices */
int slice_end ; /*!< index for end of slices */
float slice_duration ; /*!< time between individual slices */
/*! quaternion transform parameters
[when writing a dataset, these are used for qform, NOT qto_xyz] */
float quatern_b , quatern_c , quatern_d ,
qoffset_x , qoffset_y , qoffset_z ,
qfac ;
mat44 qto_xyz ; /*!< qform: transform (i,j,k) to (x,y,z) */
mat44 qto_ijk ; /*!< qform: transform (x,y,z) to (i,j,k) */
mat44 sto_xyz ; /*!< sform: transform (i,j,k) to (x,y,z) */
mat44 sto_ijk ; /*!< sform: transform (x,y,z) to (i,j,k) */
float toffset ; /*!< time coordinate offset */
int xyz_units ; /*!< dx,dy,dz units: NIFTI_UNITS_* code */
int time_units ; /*!< dt units: NIFTI_UNITS_* code */
int nifti_type ; /*!< 0==ANALYZE, 1==NIFTI-1 (1 file),
2==NIFTI-1 (2 files),
3==NIFTI-ASCII (1 file) */
int intent_code ; /*!< statistic type (or something) */
float intent_p1 ; /*!< intent parameters */
float intent_p2 ; /*!< intent parameters */
float intent_p3 ; /*!< intent parameters */
char intent_name[16] ; /*!< optional description of intent data */
char descrip[80] ; /*!< optional text to describe dataset */
char aux_file[24] ; /*!< auxiliary filename */
char *fname ; /*!< header filename (.hdr or .nii) */
char *iname ; /*!< image filename (.img or .nii) */
int iname_offset ; /*!< offset into iname where data starts */
int swapsize ; /*!< swap unit in image data (might be 0) */
int byteorder ; /*!< byte order on disk (MSB_ or LSB_FIRST) */
void *data ; /*!< pointer to data: nbyper*nvox bytes */
int num_ext ; /*!< number of extensions in ext_list */
nifti1_extension * ext_list ; /*!< array of extension structs (with data) */
analyze_75_orient_code analyze75_orient; /*!< for old analyze files, orient */
} nifti1_image ;
/* struct for return from nifti_image_read_bricks() */
typedef struct {
int64_t nbricks; /* the number of allocated pointers in 'bricks' */
int64_t bsize; /* the length of each data block, in bytes */
void ** bricks; /* array of pointers to data blocks */
} nifti_brick_list;
/*****************************************************************************/
/*------------------ NIfTI version of ANALYZE 7.5 structure -----------------*/
/* (based on fsliolib/dbh.h, but updated for version 7.5) */
typedef struct {
/* header info fields - describes the header overlap with NIfTI */
/* ------------------ */
int sizeof_hdr; /* 0 + 4 same */
char data_type[10]; /* 4 + 10 same */
char db_name[18]; /* 14 + 18 same */
int extents; /* 32 + 4 same */
short int session_error; /* 36 + 2 same */
char regular; /* 38 + 1 same */
char hkey_un0; /* 39 + 1 40 bytes */
/* image dimension fields - describes image sizes */
short int dim[8]; /* 0 + 16 same */
short int unused8; /* 16 + 2 intent_p1... */
short int unused9; /* 18 + 2 ... */
short int unused10; /* 20 + 2 intent_p2... */
short int unused11; /* 22 + 2 ... */
short int unused12; /* 24 + 2 intent_p3... */
short int unused13; /* 26 + 2 ... */
short int unused14; /* 28 + 2 intent_code */
short int datatype; /* 30 + 2 same */
short int bitpix; /* 32 + 2 same */
short int dim_un0; /* 34 + 2 slice_start */
float pixdim[8]; /* 36 + 32 same */
float vox_offset; /* 68 + 4 same */
float funused1; /* 72 + 4 scl_slope */
float funused2; /* 76 + 4 scl_inter */
float funused3; /* 80 + 4 slice_end, */
/* slice_code, */
/* xyzt_units */
float cal_max; /* 84 + 4 same */
float cal_min; /* 88 + 4 same */
float compressed; /* 92 + 4 slice_duration */
float verified; /* 96 + 4 toffset */
int glmax,glmin; /* 100 + 8 108 bytes */
/* data history fields - optional */
char descrip[80]; /* 0 + 80 same */
char aux_file[24]; /* 80 + 24 same */
char orient; /* 104 + 1 NO GOOD OVERLAP */
char originator[10]; /* 105 + 10 FROM HERE DOWN... */
char generated[10]; /* 115 + 10 */
char scannum[10]; /* 125 + 10 */
char patient_id[10]; /* 135 + 10 */
char exp_date[10]; /* 145 + 10 */
char exp_time[10]; /* 155 + 10 */
char hist_un0[3]; /* 165 + 3 */
int views; /* 168 + 4 */
int vols_added; /* 172 + 4 */
int start_field; /* 176 + 4 */
int field_skip; /* 180 + 4 */
int omax, omin; /* 184 + 8 */
int smax, smin; /* 192 + 8 200 bytes */
} nifti_analyze75; /* total: 348 bytes */
/*****************************************************************************/
/*--------------- Prototypes of functions defined in this file --------------*/
char const * nifti_datatype_string ( int dt ) ;
char const *nifti_units_string ( int uu ) ;
char const *nifti_intent_string ( int ii ) ;
char const *nifti_xform_string ( int xx ) ;
char const *nifti_slice_string ( int ss ) ;
char const *nifti_orientation_string( int ii ) ;
int nifti_is_inttype( int dt ) ;
mat44 nifti_mat44_inverse ( mat44 R ) ;
nifti_dmat44 nifti_dmat44_inverse( nifti_dmat44 R ) ;
int nifti_mat44_to_dmat44(mat44 * fm, nifti_dmat44 * dm);
int nifti_dmat44_to_mat44(nifti_dmat44 * dm, mat44 * fm);
nifti_dmat33 nifti_dmat33_inverse( nifti_dmat33 R ) ;
nifti_dmat33 nifti_dmat33_polar ( nifti_dmat33 A ) ;
double nifti_dmat33_rownorm( nifti_dmat33 A ) ;
double nifti_dmat33_colnorm( nifti_dmat33 A ) ;
double nifti_dmat33_determ ( nifti_dmat33 R ) ;
nifti_dmat33 nifti_dmat33_mul ( nifti_dmat33 A , nifti_dmat33 B ) ;
mat33 nifti_mat33_inverse( mat33 R ) ;
mat33 nifti_mat33_polar ( mat33 A ) ;
float nifti_mat33_rownorm( mat33 A ) ;
float nifti_mat33_colnorm( mat33 A ) ;
float nifti_mat33_determ ( mat33 R ) ;
mat33 nifti_mat33_mul ( mat33 A , mat33 B ) ;
void nifti_swap_2bytes ( int64_t n , void *ar ) ;
void nifti_swap_4bytes ( int64_t n , void *ar ) ;
void nifti_swap_8bytes ( int64_t n , void *ar ) ;
void nifti_swap_16bytes( int64_t n , void *ar ) ;
void nifti_swap_Nbytes ( int64_t n , int siz , void *ar ) ;
int nifti_datatype_is_valid (int dtype, int for_nifti);
int nifti_datatype_from_string (const char * name);
const char * nifti_datatype_to_string(int dtype);
int nifti_header_version (const char * buf, int nbytes);
int64_t nifti_get_filesize( const char *pathname ) ;
void swap_nifti_header ( void * h , int ni_ver ) ;
void old_swap_nifti_header( struct nifti_1_header *h , int is_nifti );
void nifti_swap_as_analyze( nifti_analyze75 *h );
void nifti_swap_as_nifti1( nifti_1_header *h );
void nifti_swap_as_nifti2( nifti_2_header *h );
/* main read/write routines */
nifti_image *nifti_image_read_bricks(const char *hname , int64_t nbricks,
const int64_t *blist, nifti_brick_list * NBL);
int nifti_image_load_bricks(nifti_image *nim , int64_t nbricks,
const int64_t *blist, nifti_brick_list * NBL);
void nifti_free_NBL( nifti_brick_list * NBL );
nifti_image *nifti_image_read ( const char *hname , int read_data);
int nifti_image_load ( nifti_image *nim);
void nifti_image_unload ( nifti_image *nim);
void nifti_image_free ( nifti_image *nim);
int64_t nifti_read_collapsed_image( nifti_image * nim,
const int64_t dims[8], void ** data);
int64_t nifti_read_subregion_image(nifti_image *nim, int64_t *start_index,
int64_t *region_size, void ** data);
void nifti_image_write ( nifti_image * nim ) ;
void nifti_image_write_bricks(nifti_image * nim,
const nifti_brick_list * NBL);
void nifti_image_infodump( const nifti_image * nim ) ;
void nifti_disp_lib_hist( int ver ) ; /* to display library history */
void nifti_disp_lib_version( void ) ; /* to display library version */
int nifti_disp_matrix_orient( const char * mesg, nifti_dmat44 mat );
int nifti_disp_type_list( int which );
char * nifti_image_to_ascii ( const nifti_image * nim ) ;
nifti_image *nifti_image_from_ascii( const char * str, int * bytes_read ) ;
int64_t nifti_get_volsize(const nifti_image *nim) ;
/* basic file operations */
int nifti_set_filenames(nifti_image * nim, const char * prefix, int check,
int set_byte_order);
char * nifti_makehdrname (const char * prefix, int nifti_type, int check,
int comp);
char * nifti_makeimgname (const char * prefix, int nifti_type, int check,
int comp);
int is_nifti_file (const char *hname);
char * nifti_find_file_extension(const char * name);
int nifti_is_complete_filename(const char* fname);
int nifti_validfilename(const char* fname);
int disp_nifti_1_header(const char * info, const nifti_1_header * hp ) ;
int disp_nifti_2_header( const char * info, const nifti_2_header * hp ) ;
void nifti_set_debug_level( int level ) ;
void nifti_set_skip_blank_ext( int skip ) ;
void nifti_set_allow_upper_fext( int allow ) ;
int nifti_get_alter_cifti( void );
void nifti_set_alter_cifti( int alter_cifti );
int nifti_alter_cifti_dims(nifti_image * nim);
int valid_nifti_brick_list(nifti_image * nim , int64_t nbricks,
const int64_t * blist, int disp_error);
/* znzFile operations */
znzFile nifti_image_open(const char * hname, char * opts, nifti_image ** nim);
znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data,
const char* opts);
znzFile nifti_image_write_hdr_img2( nifti_image *nim , int write_opts ,
const char* opts, znzFile imgfile, const nifti_brick_list * NBL);
int64_t nifti_read_buffer(znzFile fp, void* datatptr, int64_t ntot,
nifti_image *nim);
int nifti_write_all_data(znzFile fp, nifti_image * nim,
const nifti_brick_list * NBL);
int64_t nifti_write_buffer(znzFile fp, const void * buffer, int64_t numbytes);
nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen,
int read_data);
znzFile nifti_write_ascii_image(nifti_image *nim, const nifti_brick_list * NBL,
const char * opts, int write_data, int leave_open);
void nifti_datatype_sizes( int datatype , int *nbyper, int *swapsize ) ;
void nifti_dmat44_to_quatern(nifti_dmat44 R ,
double *qb, double *qc, double *qd,
double *qx, double *qy, double *qz,
double *dx, double *dy, double *dz, double *qfac);
nifti_dmat44 nifti_quatern_to_dmat44( double qb, double qc, double qd,
double qx, double qy, double qz,
double dx, double dy, double dz, double qfac );
nifti_dmat44 nifti_make_orthog_dmat44( double r11, double r12, double r13 ,
double r21, double r22, double r23 ,
double r31, double r32, double r33 ) ;
void nifti_mat44_to_quatern( mat44 R ,
float *qb, float *qc, float *qd,
float *qx, float *qy, float *qz,
float *dx, float *dy, float *dz, float *qfac ) ;
mat44 nifti_quatern_to_mat44( float qb, float qc, float qd,
float qx, float qy, float qz,
float dx, float dy, float dz, float qfac );
mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 ,
float r21, float r22, float r23 ,
float r31, float r32, float r33 ) ;
int nifti_short_order(void) ; /* CPU byte order */
/* Orientation codes that might be returned from nifti_mat44_to_orientation().*/
#define NIFTI_L2R 1 /* Left to Right */
#define NIFTI_R2L 2 /* Right to Left */
#define NIFTI_P2A 3 /* Posterior to Anterior */
#define NIFTI_A2P 4 /* Anterior to Posterior */
#define NIFTI_I2S 5 /* Inferior to Superior */
#define NIFTI_S2I 6 /* Superior to Inferior */
void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) ;
void nifti_dmat44_to_orientation( nifti_dmat44 R,
int *icod, int *jcod, int *kcod ) ;
/*--------------------- Low level IO routines ------------------------------*/
char * nifti_findhdrname (const char* fname);
char * nifti_findimgname (const char* fname , int nifti_type);
int nifti_is_gzfile (const char* fname);
char * nifti_makebasename(const char* fname);
/* other routines */
int nifti_convert_nim2n1hdr(const nifti_image* nim, nifti_1_header * hdr);
int nifti_convert_nim2n2hdr(const nifti_image* nim, nifti_2_header * hdr);
nifti_1_header * nifti_make_new_n1_header(const int64_t arg_dims[], int dtype);
nifti_2_header * nifti_make_new_n2_header(const int64_t arg_dims[], int dtype);
void * nifti_read_header(const char *hname, int *nver, int check);
nifti_1_header * nifti_read_n1_hdr(const char *hname, int *swapped, int check);
nifti_2_header * nifti_read_n2_hdr(const char *hname, int *swapped, int check);
nifti_image * nifti_copy_nim_info(const nifti_image * src);
nifti_image * nifti_make_new_nim(const int64_t dims[], int datatype,
int data_fill);
nifti_image * nifti_simple_init_nim(void);
nifti_image * nifti_convert_n1hdr2nim(nifti_1_header nhdr,const char *fname);
nifti_image * nifti_convert_n2hdr2nim(nifti_2_header nhdr,const char *fname);
int nifti_looks_like_cifti(nifti_image * nim);
int nifti_hdr1_looks_good (const nifti_1_header * hdr);
int nifti_hdr2_looks_good (const nifti_2_header * hdr);
int nifti_is_valid_datatype (int dtype);
int nifti_is_valid_ecode (int ecode);
int nifti_nim_is_valid (nifti_image * nim, int complain);
int nifti_nim_has_valid_dims (nifti_image * nim, int complain);
int is_valid_nifti_type (int nifti_type);
int nifti_test_datatype_sizes (int verb);
int nifti_type_and_names_match (nifti_image * nim, int show_warn);
int nifti_update_dims_from_array(nifti_image * nim);
void nifti_set_iname_offset (nifti_image *nim);
int nifti_set_type_from_names (nifti_image * nim);
int nifti_add_extension(nifti_image * nim, const char * data, int len,
int ecode );
int nifti_compiled_with_zlib (void);
int nifti_copy_extensions (nifti_image *nim_dest,const nifti_image *nim_src);
int nifti_free_extensions (nifti_image *nim);
int64_t * nifti_get_int64list(int64_t nvals , const char *str);
int * nifti_get_intlist (int nvals , const char *str);
char * nifti_strdup (const char *str);
int valid_nifti_extensions(const nifti_image *nim);
int nifti_valid_header_size(int ni_ver, int whine);
/*-------------------- Some C convenience macros ----------------------------*/
/* NIfTI-1.1 extension codes:
see http://nifti.nimh.nih.gov/nifti-1/documentation/faq#Q21 */
#define NIFTI_ECODE_IGNORE 0 /* changed from UNKNOWN, 29 June 2005 */
#define NIFTI_ECODE_DICOM 2 /* intended for raw DICOM attributes */
#define NIFTI_ECODE_AFNI 4 /* Robert W Cox: rwcox@nih.gov
https://afni.nimh.nih.gov/afni */
#define NIFTI_ECODE_COMMENT 6 /* plain ASCII text only */
#define NIFTI_ECODE_XCEDE 8 /* David B Keator: dbkeator@uci.edu
http://www.nbirn.net/Resources
/Users/Applications/
/xcede/index.htm */
#define NIFTI_ECODE_JIMDIMINFO 10 /* Mark A Horsfield:
mah5@leicester.ac.uk
http://someplace/something */
#define NIFTI_ECODE_WORKFLOW_FWDS 12 /* Kate Fissell: fissell@pitt.edu
http://kraepelin.wpic.pitt.edu
/~fissell/NIFTI_ECODE_WORKFLOW_FWDS
/NIFTI_ECODE_WORKFLOW_FWDS.html */
#define NIFTI_ECODE_FREESURFER 14 /* http://surfer.nmr.mgh.harvard.edu */
#define NIFTI_ECODE_PYPICKLE 16 /* embedded Python objects
http://niftilib.sourceforge.net
/pynifti */
/* LONI MiND codes: http://www.loni.ucla.edu/twiki/bin/view/Main/MiND */
#define NIFTI_ECODE_MIND_IDENT 18 /* Vishal Patel: vishal.patel@ucla.edu*/
#define NIFTI_ECODE_B_VALUE 20
#define NIFTI_ECODE_SPHERICAL_DIRECTION 22
#define NIFTI_ECODE_DT_COMPONENT 24
#define NIFTI_ECODE_SHC_DEGREEORDER 26 /* end LONI MiND codes */
#define NIFTI_ECODE_VOXBO 28 /* Dan Kimberg: www.voxbo.org */
#define NIFTI_ECODE_CARET 30 /* John Harwell: john@brainvis.wustl.edu
http://brainvis.wustl.edu/wiki
/index.php/Caret:Documentation
:CaretNiftiExtension */
#define NIFTI_ECODE_CIFTI 32 /* CIFTI-2_Main_FINAL_1March2014.pdf */
#define NIFTI_ECODE_VARIABLE_FRAME_TIMING 34
/* 36 is currently unassigned, waiting on NIFTI_ECODE_AGILENT_PROCPAR */
#define NIFTI_ECODE_EVAL 38 /* Munster University Hospital */
/* http://www.mathworks.com/matlabcentral/fileexchange/42997-dicom-to-nifti-converter */
#define NIFTI_ECODE_MATLAB 40 /* MATLAB extension */
#define NIFTI_MAX_ECODE 40 /******* maximum extension code *******/
/* nifti_type file codes */
#define NIFTI_FTYPE_ANALYZE 0 /* old ANALYZE */
#define NIFTI_FTYPE_NIFTI1_1 1 /* NIFTI-1 */
#define NIFTI_FTYPE_NIFTI1_2 2
#define NIFTI_FTYPE_ASCII 3
#define NIFTI_FTYPE_NIFTI2_1 4 /* NIFTI-2 */
#define NIFTI_FTYPE_NIFTI2_2 5
#define NIFTI_MAX_FTYPE 5 /* this should match the maximum code */
/*------------------------------------------------------------------------*/
/*-- the rest of these apply only to nifti2_io.c, check for _NIFTI2_IO_C_ */
#ifdef _NIFTI2_IO_C_
typedef struct {
int debug; /*!< debug level for status reports */
int skip_blank_ext; /*!< skip extender if no extensions */
int allow_upper_fext; /*!< allow uppercase file extensions */
int alter_cifti; /*!< convert CIFTI dimensions */
} nifti_global_options;
typedef struct {
int type; /* should match the NIFTI_TYPE_ #define */
int nbyper; /* bytes per value, matches nifti_image */
int swapsize; /* bytes per swap piece, matches nifti_image */
char const * const name; /* text string to match #define */
} nifti_type_ele;
#undef LNI_FERR /* local nifti file error, to be compact and repetative */
#define LNI_FERR(func,msg,file) \
fprintf(stderr,"** ERROR (%s): %s '%s'\n",func,msg,file)
#undef swap_2
#undef swap_4
#define swap_2(s) nifti_swap_2bytes(1,&(s)) /* s: 2-byte short; swap in place */
#define swap_4(v) nifti_swap_4bytes(1,&(v)) /* v: 4-byte value; swap in place */
/***** isfinite() is a C99 macro, which is
present in many C implementations already *****/
#undef IS_GOOD_FLOAT
#undef FIXED_FLOAT
#ifdef isfinite /* use isfinite() to check floats/doubles for goodness */
# define IS_GOOD_FLOAT(x) isfinite(x) /* check if x is a "good" float */
# define FIXED_FLOAT(x) (isfinite(x) ? (x) : 0) /* fixed if bad */
#else
# define IS_GOOD_FLOAT(x) 1 /* don't check it */
# define FIXED_FLOAT(x) (x) /* don't fix it */
#endif
#undef ASSIF /* assign v to *p, if possible */
#define ASSIF(p,v) if( (p)!=NULL ) *(p) = (v)
#undef MSB_FIRST
#undef LSB_FIRST
#undef REVERSE_ORDER
#define LSB_FIRST 1
#define MSB_FIRST 2
#define REVERSE_ORDER(x) (3-(x)) /* convert MSB_FIRST <--> LSB_FIRST */
#define LNI_MAX_NIA_EXT_LEN 100000 /* consider a longer extension invalid */
#undef NIFTI_IS_16_BIT_INT
#define NIFTI_IS_16_BIT_INT(x) ((x) <= 32767 && (x) >= -32768)
#endif /* _NIFTI2_IO_C_ section */
/*------------------------------------------------------------------------*/
/*=================*/
#ifdef __cplusplus
}
#endif
/*=================*/
#endif /* _NIFTI2_IO_HEADER_ */
#include "nifti2_io.i"
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -120,5 +120,3 @@ int znzprintf(znzFile stream, const char *format, ...); ...@@ -120,5 +120,3 @@ int znzprintf(znzFile stream, const char *format, ...);
/*=================*/ /*=================*/
#endif #endif
#include "znzlib.i"
\ No newline at end of file
#define _NIFTI1_IO_C_ #define _NIFTI1_IO_C_
#include "nifti/nifti1_io.h" /* typedefs, prototypes, macros, etc. */
/*****===================================================================*****/ /*****===================================================================*****/
/***** Sample functions to deal with NIFTI-1 and ANALYZE files *****/ /***** Sample functions to deal with NIFTI-1 and ANALYZE files *****/
/*****...................................................................*****/ /*****...................................................................*****/
......
...@@ -21,6 +21,8 @@ NB: seeks for writable files with compression are quite restricted ...@@ -21,6 +21,8 @@ NB: seeks for writable files with compression are quite restricted
*/ */
#include "nifti/znzlib.h"
/* /*
znzlib.c (zipped or non-zipped library) znzlib.c (zipped or non-zipped library)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment