Skip to content

Commit

Permalink
ignore_trigger_times options (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Apr 3, 2021
1 parent 5a9c98c commit ccf263d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
4 changes: 4 additions & 0 deletions console/main_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void showHelp(const char * argv[], struct TDCMopts opts) {
#endif
printf(" --big-endian : byte order (y/n/o, default o) [y=big-end, n=little-end, o=optimal/native]\n");
printf(" --progress : report progress (y/n, default n)\n");
printf(" --ignore_trigger_times : disregard values in 0018,1060 and 0020,9153\n");
printf(" --terse : omit filename post-fixes (can cause overwrites)\n");
printf(" --version : report version\n");
printf(" --xml : Slicer format features\n");
Expand Down Expand Up @@ -286,6 +287,9 @@ int main(int argc, const char * argv[])
opts.isSaveNativeEndian = false;
printf("NIfTI data will be little-endian\n");
}
} else if ( ! strcmp(argv[i], "--ignore_trigger_times")) {
opts.isIgnoreTriggerTimes = true;
printf("ignore_trigger_times may have unintended consequences (issue 499)\n");
} else if ( ! strcmp(argv[i], "--terse")) {
opts.isAddNamePostFixes = false;
} else if ( ! strcmp(argv[i], "--version")) {
Expand Down
23 changes: 22 additions & 1 deletion console/nii_dicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4094,7 +4094,10 @@ int compareTDCMdimRev(void const *item1, void const *item2) {

#endif // USING_R

struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, struct TDTI4D *dti4D) {
struct TDICOMdata readDICOMx(char * fname, struct TDCMprefs* prefs, struct TDTI4D *dti4D) {
//struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, struct TDTI4D *dti4D) {
int isVerbose = prefs->isVerbose;
int compressFlag = prefs->compressFlag;
struct TDICOMdata d = clear_dicom_data();
d.imageNum = 0; //not set
strcpy(d.protocolName, ""); //erase dummy with empty
Expand Down Expand Up @@ -5641,6 +5644,7 @@ uint32_t kSequenceDelimitationItemTag = 0xFFFE +(0xE0DD << 16 );
sqDepth00189114 = sqDepth - 1;
break;
case kTriggerDelayTime: { //0x0020+uint32_t(0x9153<< 16 ) //FD
if (prefs->isIgnoreTriggerTimes) break;//issue499
if (d.manufacturer != kMANUFACTURER_PHILIPS) break;
//if (isVerbose < 2) break;
double trigger = dcmFloatDouble(lLength, &buffer[lPos],d.isLittleEndian);
Expand Down Expand Up @@ -5839,6 +5843,7 @@ uint32_t kSequenceDelimitationItemTag = 0xFFFE +(0xE0DD << 16 );
d.imagingFrequency = dcmStrFloat(lLength, &buffer[lPos]);
break;
case kTriggerTime: {
if (prefs->isIgnoreTriggerTimes) break;//issue499
//untested method to detect slice timing for GE PSD “epi” with multiphase option
// will not work for current PSD “epiRT” (BrainWave RT, fMRI/DTI package provided by Medical Numerics)
if ((d.manufacturer != kMANUFACTURER_GE) && (d.manufacturer != kMANUFACTURER_PHILIPS)) break; //issue384
Expand Down Expand Up @@ -7316,6 +7321,22 @@ if (d.isHasPhase)
return d;
} // readDICOM()

void setDefaultPrefs (struct TDCMprefs *prefs) {
prefs->isVerbose = false;
prefs->compressFlag = kCompressSupport;
prefs->isIgnoreTriggerTimes = false;
}

struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, struct TDTI4D *dti4D) {
struct TDCMprefs prefs;
setDefaultPrefs(&prefs);
prefs.isVerbose = isVerbose;
prefs.compressFlag = compressFlag;
TDICOMdata ret = readDICOMx(fname, &prefs, dti4D);
return ret;
}


struct TDICOMdata readDICOM(char * fname) {
struct TDTI4D *dti4D = (struct TDTI4D *)malloc(sizeof(struct TDTI4D)); //unused
TDICOMdata ret = readDICOMv(fname, false, kCompressSupport, dti4D);
Expand Down
10 changes: 8 additions & 2 deletions console/nii_dicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern "C" {
#define kCPUsuf " " //unknown CPU
#endif

#define kDCMdate "v1.0.20210317"
#define kDCMdate "v1.0.20210403"
#define kDCMvers kDCMdate " " kJP2suf kLSsuf kCCsuf kCPUsuf

static const int kMaxEPI3D = 1024; //maximum number of EPI images in Siemens Mosaic
Expand Down Expand Up @@ -195,12 +195,18 @@ static const uint8_t MAX_NUMBER_OF_DIMENSIONS = 8;
bool isRealIsPhaseMapHz, isPrivateCreatorRemap, isHasOverlay, isEPI, isIR, isPartialFourier, isDiffusion, isVectorFromBMatrix, isRawDataStorage, isGrayscaleSoftcopyPresentationState, isStackableSeries, isCoilVaries, isNonParallelSlices, isBVecWorldCoordinates, isSegamiOasis, isXA10A, isScaleOrTEVaries, isScaleVariesEnh, isDerived, isXRay, isMultiEcho, isValid, is3DAcq, is2DAcq, isExplicitVR, isLittleEndian, isPlanarRGB, isSigned, isHasPhase, isHasImaginary, isHasReal, isHasMagnitude,isHasMixed, isFloat, isResampled, isLocalizer;
char phaseEncodingRC, patientSex;
};
struct TDCMprefs {
int isVerbose, compressFlag, isIgnoreTriggerTimes;
};

size_t nii_ImgBytes(struct nifti_1_header hdr);
void setDefaultPrefs (struct TDCMprefs *prefs);
int isSameFloatGE (float a, float b);
void getFileNameX( char *pathParent, const char *path, int maxLen);
struct TDICOMdata readDICOMv(char * fname, int isVerbose, int compressFlag, struct TDTI4D *dti4D);
struct TDICOMdata readDICOM(char * fname);
struct TDICOMdata readDICOMx(char * fname, struct TDCMprefs* prefs, struct TDTI4D *dti4D);

struct TDICOMdata readDICOM(char * fname);
struct TDICOMdata clear_dicom_data(void);
struct TDICOMdata nii_readParRec (char * parname, int isVerbose, struct TDTI4D *dti4D, bool isReadPhase);
unsigned char * nii_flipY(unsigned char* bImg, struct nifti_1_header *h);
Expand Down
18 changes: 16 additions & 2 deletions console/nii_dicom_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ bool is_exe(const char* path) { //requires #include <sys/stat.h>
}// is_dir()
#endif

void opts2Prefs (struct TDCMopts* opts, struct TDCMprefs *prefs) {
setDefaultPrefs(prefs);
prefs->isVerbose = opts->isVerbose;
prefs->compressFlag = opts->compressFlag;
prefs->isIgnoreTriggerTimes = opts->isIgnoreTriggerTimes;
}

void geCorrectBvecs(struct TDICOMdata *d, int sliceDir, struct TDTI *vx, int isVerbose){
//0018,1312 phase encoding is either in row or column direction
//0043,1039 (or 0043,a039). b value (as the first number in the string).
Expand Down Expand Up @@ -6234,6 +6241,8 @@ int singleDICOM(struct TDCMopts* opts, char *fname) {
struct TDICOMdata *dcmList = (struct TDICOMdata *)malloc( sizeof(struct TDICOMdata));
struct TDTI4D *dti4D = (struct TDTI4D *)malloc(sizeof(struct TDTI4D));
struct TSearchList nameList;
struct TDCMprefs prefs;
opts2Prefs (opts, &prefs);
nameList.maxItems = 1; // larger requires more memory, smaller more passes
nameList.str = (char **) malloc((nameList.maxItems+1) * sizeof(char *)); //reserve one pointer (32 or 64 bits) per potential file
nameList.numItems = 0;
Expand All @@ -6242,7 +6251,8 @@ int singleDICOM(struct TDCMopts* opts, char *fname) {
nameList.numItems++;
TDCMsort * dcmSort = (TDCMsort *)malloc(sizeof(TDCMsort));
dcmList[0].converted2NII = 1;
dcmList[0] = readDICOMv(nameList.str[0], opts->isVerbose, opts->compressFlag, dti4D); //ignore compile warning - memory only freed on first of 2 passes
dcmList[0] = readDICOMx(nameList.str[0], &prefs, dti4D); //ignore compile warning - memory only freed on first of 2 passes
//dcmList[0] = readDICOMv(nameList.str[0], opts->isVerbose, opts->compressFlag, dti4D); //ignore compile warning - memory only freed on first of 2 passes
fillTDCMsort(dcmSort[0], 0, dcmList[0]);
int ret = saveDcm2Nii(1, dcmSort, dcmList, &nameList, *opts, dti4D);
freeNameList(nameList);
Expand Down Expand Up @@ -6678,6 +6688,8 @@ int nii_loadDirCore(char *indir, struct TDCMopts* opts) {
// struct TDICOMdata dcmList [nameList.numItems]; //<- this exhausts the stack for large arrays
struct TDICOMdata *dcmList = (struct TDICOMdata *)malloc(nameList.numItems * sizeof(struct TDICOMdata));
struct TDTI4D *dti4D = (struct TDTI4D *)malloc(sizeof(struct TDTI4D));
struct TDCMprefs prefs;
opts2Prefs (opts, &prefs);
int nConvertTotal = 0;
bool compressionWarning = false;
bool convertError = false;
Expand All @@ -6696,7 +6708,8 @@ int nii_loadDirCore(char *indir, struct TDCMopts* opts) {
convertError = true;
continue;
}
dcmList[i] = readDICOMv(nameList.str[i], opts->isVerbose, opts->compressFlag, dti4D); //ignore compile warning - memory only freed on first of 2 passes
dcmList[i] = readDICOMx(nameList.str[i], &prefs, dti4D); //ignore compile warning - memory only freed on first of 2 passes
//dcmList[i] = readDICOMv(nameList.str[i], opts->isVerbose, opts->compressFlag, dti4D); //ignore compile warning - memory only freed on first of 2 passes
if (opts->isIgnoreSeriesInstanceUID)
dcmList[i].seriesUidCrc = dcmList[i].seriesNum;
//if (!dcmList[i].isValid) printf(">>>>Not a valid DICOM %s\n", nameList.str[i]);
Expand Down Expand Up @@ -7248,6 +7261,7 @@ void setDefaultOpts (struct TDCMopts *opts, const char * argv[]) { //either "set
opts->isSaveNativeEndian = true;
opts->isAddNamePostFixes = true; //e.g. "_e2" added for second echo
opts->isTestx0021x105E = false; //GE test slice times stored in 0021,105E
opts->isIgnoreTriggerTimes = false;
opts->isSaveNRRD = false;
opts->isPipedGz = false; //e.g. pipe data directly to pigz instead of saving uncompressed to disk
opts->isSave3D = false;
Expand Down
2 changes: 1 addition & 1 deletion console/nii_dicom_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C" {
#define MAX_NUM_SERIES 16

struct TDCMopts {
bool isTestx0021x105E, isAddNamePostFixes, isSaveNativeEndian, isSaveNRRD, isOneDirAtATime, isRenameNotConvert, isSave3D, isGz, isPipedGz, isFlipY, isCreateBIDS, isSortDTIbyBVal, isAnonymizeBIDS, isOnlyBIDS, isCreateText, isForceOnsetTimes,isIgnoreDerivedAnd2D, isPhilipsFloatNotDisplayScaling, isTiltCorrect, isRGBplanar, isOnlySingleFile, isForceStackDCE, isIgnoreSeriesInstanceUID, isRotate3DAcq, isCrop;
bool isIgnoreTriggerTimes, isTestx0021x105E, isAddNamePostFixes, isSaveNativeEndian, isSaveNRRD, isOneDirAtATime, isRenameNotConvert, isSave3D, isGz, isPipedGz, isFlipY, isCreateBIDS, isSortDTIbyBVal, isAnonymizeBIDS, isOnlyBIDS, isCreateText, isForceOnsetTimes,isIgnoreDerivedAnd2D, isPhilipsFloatNotDisplayScaling, isTiltCorrect, isRGBplanar, isOnlySingleFile, isForceStackDCE, isIgnoreSeriesInstanceUID, isRotate3DAcq, isCrop;
int isMaximize16BitRange, isForceStackSameSeries, nameConflictBehavior, isVerbose, isProgress, compressFlag, dirSearchDepth, gzLevel; //support for compressed data 0=none,
char filename[512], outdir[512], indir[512], pigzname[512], optsname[512], indirParent[512], imageComments[24];
double seriesNumber[MAX_NUM_SERIES]; //requires double must store -1 (report but do not convert) as well as seriesUidCrc (uint32)
Expand Down

0 comments on commit ccf263d

Please sign in to comment.