Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
JNIfTI support modular (cmake -DUSE_JNIFTI=OFF ..)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Feb 10, 2022
1 parent 1000d15 commit 973526c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions SuperBuild/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions console/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions console/main_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 8 additions & 2 deletions console/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
15 changes: 11 additions & 4 deletions console/nii_dicom_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ctype.h> //toupper
#include <float.h>
#include <math.h>
Expand Down Expand Up @@ -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'");
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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);
Expand All @@ -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<keylen;i++){
Expand Down Expand Up @@ -4658,12 +4662,15 @@ int nii_savejnii(char *niiFilename, struct nifti_1_header hdr, unsigned char *im
cJSON_Delete(root);
return EXIT_SUCCESS;
} // nii_savejnii()
#endif //#ifdef myEnableJNIfTI

int nii_saveForeign(char *niiFilename, struct nifti_1_header hdr, unsigned char *im, struct TDCMopts opts, struct TDICOMdata d, struct TDTI4D *dti4D, int numDTI) {
if (opts.saveFormat == kSaveFormatMGH)
return nii_saveMGH(niiFilename, hdr, im, opts, d, dti4D, numDTI);
#ifdef myEnableJNIfTI
else if (opts.saveFormat == kSaveFormatJNII || opts.saveFormat == kSaveFormatBNII)
return nii_savejnii(niiFilename, hdr, im, opts, d, dti4D, numDTI);
#endif
return nii_saveNRRD(niiFilename, hdr, im, opts, d, dti4D, numDTI);
}// nii_saveForeign()

Expand Down

0 comments on commit 973526c

Please sign in to comment.