From 973526c55a8c1b447ea79a242be547f5210b9959 Mon Sep 17 00:00:00 2001 From: neurolabusc Date: Thu, 10 Feb 2022 08:41:25 -0500 Subject: [PATCH] JNIfTI support modular (cmake -DUSE_JNIFTI=OFF ..) --- SuperBuild/SuperBuild.cmake | 2 ++ console/CMakeLists.txt | 11 ++++++++--- console/{base64.c => base64.cpp} | 0 console/{cJSON.c => cJSON.cpp} | 0 console/main_console.cpp | 10 ++++++++++ console/makefile | 10 ++++++++-- console/nii_dicom_batch.cpp | 15 +++++++++++---- 7 files changed, 39 insertions(+), 9 deletions(-) rename console/{base64.c => base64.cpp} (100%) rename console/{cJSON.c => cJSON.cpp} (100%) diff --git a/SuperBuild/SuperBuild.cmake b/SuperBuild/SuperBuild.cmake index 2a0a956f..3f011f0c 100644 --- a/SuperBuild/SuperBuild.cmake +++ b/SuperBuild/SuperBuild.cmake @@ -40,6 +40,7 @@ option(USE_TURBOJPEG "Use TurboJPEG to decode classic JPEG" OFF) option(USE_JASPER "Build with JPEG2000 support using Jasper" OFF) option(USE_OPENJPEG "Build with JPEG2000 support using OpenJPEG" OFF) option(USE_JPEGLS "Build with JPEG-LS support using CharLS" OFF) +option(USE_JNIFTI "Build with JNIFTI support" ON) option(BATCH_VERSION "Build dcm2niibatch for multiple conversions" OFF) @@ -139,6 +140,7 @@ ExternalProject_Add(console -DUSE_TURBOJPEG:BOOL=${USE_TURBOJPEG} -DUSE_JASPER:BOOL=${USE_JASPER} -DUSE_JPEGLS:BOOL=${USE_JPEGLS} + -DUSE_JNIFTI:BOOL=${USE_JNIFTI} -DZLIB_IMPLEMENTATION:STRING=${ZLIB_IMPLEMENTATION} -DZLIB_ROOT:PATH=${ZLIB_ROOT} # OpenJPEG diff --git a/console/CMakeLists.txt b/console/CMakeLists.txt index abed9047..5c85ba6f 100644 --- a/console/CMakeLists.txt +++ b/console/CMakeLists.txt @@ -74,9 +74,14 @@ set(DCM2NIIX_SRCS nifti1_io_core.cpp nii_foreign.cpp nii_ortho.cpp - nii_dicom_batch.cpp - cJSON.c - base64.c) + nii_dicom_batch.cpp) + + +option(USE_JNIfTI "Build with JNIfTI support" ON) +if(USE_JNIFTI) + add_definitions(-DmyEnableJNIfTI) + set(DCM2NIIX_SRCS ${DCM2NIIX_SRCS} cJSON.cpp base64.cpp) +endif() option(USE_JPEGLS "Build with JPEG-LS support using CharLS" OFF) if(USE_JPEGLS) diff --git a/console/base64.c b/console/base64.cpp similarity index 100% rename from console/base64.c rename to console/base64.cpp diff --git a/console/cJSON.c b/console/cJSON.cpp similarity index 100% rename from console/cJSON.c rename to console/cJSON.cpp diff --git a/console/main_console.cpp b/console/main_console.cpp index aa141c40..48539dbe 100644 --- a/console/main_console.cpp +++ b/console/main_console.cpp @@ -80,7 +80,11 @@ void showHelp(const char *argv[], struct TDCMopts opts) { printf(" -ba : anonymize BIDS (y/n, default %c)\n", bool2Char(opts.isAnonymizeBIDS)); printf(" -c : comment stored in NIfTI aux_file (provide up to 24 characters e.g. '-c first_visit')\n"); printf(" -d : directory search depth. Convert DICOMs in sub-folders of in_folder? (0..9, default %d)\n", opts.dirSearchDepth); +#ifdef myEnableJNIfTI printf(" -e : export as NRRD (y) or MGH (o) or JSON/JNIfTI (j) or BJNIfTI (b) instead of NIfTI (y/n/o/j/b, default n)\n"); +#else + printf(" -e : export as NRRD (y) or MGH (o) instead of NIfTI (y/n/o/j/b, default n)\n"); +#endif #ifdef mySegmentByAcq #define kQstr " %%q=sequence number," #else @@ -363,6 +367,12 @@ int main(int argc, const char *argv[]) { opts.saveFormat = kSaveFormatJNII; if ((argv[i][0] == 'b') || (argv[i][0] == 'B') || (argv[i][0] == '4')) opts.saveFormat = kSaveFormatBNII; + #ifndef myEnableJNIfTI + if ((opts.saveFormat == kSaveFormatJNII) || (opts.saveFormat == kSaveFormatBNII)) { + printf("Recompile for JNIfTI support.\n"); + return EXIT_SUCCESS; + } + #endif } else if ((argv[i][1] == 'g') && ((i + 1) < argc)) { i++; if (invalidParam(i, argv)) diff --git a/console/makefile b/console/makefile index 3f37cb04..3b14bfa9 100644 --- a/console/makefile +++ b/console/makefile @@ -13,7 +13,13 @@ CFLAGS=-s -O3 #run "JPEGLS=1 make" for JPEGLS build JFLAGS= ifeq "$(JPEGLS)" "1" - JFLAGS=-std=c++14 -DmyEnableJPEGLS charls/jpegls.cpp charls/jpegmarkersegment.cpp charls/interface.cpp charls/jpegstreamwriter.cpp charls/jpegstreamreader.cpp + JFLAGS=-std=c++14 -DmyEnableJPEGLS charls/jpegls.cpp charls/jpegmarkersegment.cpp charls/interface.cpp charls/jpegstreamwriter.cpp charls/jpegstreamreader.cpp +endif + +#run "JNIfTI=0 make" to disable JNIFTI build +JSFLAGS= +ifneq "$(JNIfTI)" "0" + JSFLAGS=-DmyEnableJNIfTI base64.cpp cJSON.cpp endif ifneq ($(OS),Windows_NT) @@ -31,4 +37,4 @@ ifneq ($(OS),Windows_NT) endif endif all: - g++ $(CFLAGS) -I. $(JFLAGS) main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp base64.c cJSON.c -o dcm2niix -DmyDisableOpenJPEG + g++ $(CFLAGS) -I. $(JSFLAGS) $(JFLAGS) main_console.cpp nii_foreign.cpp nii_dicom.cpp jpg_0XC3.cpp ujpeg.cpp nifti1_io_core.cpp nii_ortho.cpp nii_dicom_batch.cpp -o dcm2niix -DmyDisableOpenJPEG diff --git a/console/nii_dicom_batch.cpp b/console/nii_dicom_batch.cpp index 9371c920..61b8b207 100644 --- a/console/nii_dicom_batch.cpp +++ b/console/nii_dicom_batch.cpp @@ -38,8 +38,10 @@ #endif #include "nii_dicom.h" #include "nii_ortho.h" -#include "base64.h" -#include "cJSON.h" +#ifdef myEnableJNIfTI + #include "base64.h" + #include "cJSON.h" +#endif #include //toupper #include #include @@ -3298,10 +3300,12 @@ void nii_createDummyFilename(char *niiFilename, struct TDCMopts opts) { strcat(niiFilename, ".nhdr'"); else strcat(niiFilename, ".nrrd'"); + #ifdef myEnableJNIfTI } else if (opts.saveFormat == kSaveFormatJNII) { strcat(niiFilename, ".jnii'"); } else if (opts.saveFormat == kSaveFormatBNII) { strcat(niiFilename, ".bnii'"); + #endif } else { if (opts.isGz) strcat(niiFilename, ".nii.gz'"); @@ -4098,6 +4102,7 @@ int nii_saveNRRD(char *niiFilename, struct nifti_1_header hdr, unsigned char *im enum TZipMethod {zmZlib, zmGzip, zmBase64}; +#ifdef myEnableJNIfTI #ifdef Z_DEFLATED int zmat_run(const size_t inputsize, unsigned char *inputstr, size_t *outputsize, unsigned char **outputbuf, const int zipid, int *ret, const int iscompress){ @@ -4174,7 +4179,6 @@ int zmat_run(const size_t inputsize, unsigned char *inputstr, size_t *outputsize count++; } *outputsize=zs.total_out; - if(*ret!=Z_STREAM_END && *ret!=Z_OK) return -3; inflateEnd(&zs); @@ -4185,7 +4189,7 @@ int zmat_run(const size_t inputsize, unsigned char *inputstr, size_t *outputsize return 0; } -#endif +#endif //Z_DEFLATED int jnifti_lookup(int *keyid, int keylen, int val){ for(int i=0;i