Skip to content

Commit e812711

Browse files
committed
MRISurfOverlay/gifti.cpp - preparation for supporting multiple overlays in one file
- gifti.cpp: add getShapeStatIntentCount() to return SHAPE and <STATS> intent counts - MRISurfOverlay: add private function __getFrameCount() to return frame count to be processed
1 parent 78fe20d commit e812711

File tree

4 files changed

+102
-10
lines changed

4 files changed

+102
-10
lines changed

include/MRISurfOverlay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class MRISurfOverlay
9999
bool __isStatsData(int nthOverlay);
100100
bool __isShapeMeasurement(int nthOverlay);
101101

102+
int __getFrameCount();
103+
102104
int __nVertices;
103105
int __nFaces; // # of triangles, we need this for MRI_CURV_FILE output
104106

include/gifti.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ int MRISwriteGIFTISurface(MRIS *mris, gifti_image *image, const char *out_fname)
4242

4343
// function to output multiple overlays
4444
int MRISwriteGIFTICombined(MRIS *mris, MRISurfOverlay *poverlays, const char *out_fname);
45+
4546
// overloaded functions to handle combined GIFTI with multiple intents
4647
int MRISwriteGIFTIIntent(MRIS *mris, const MRI *mri, int stframe, int endframe, gifti_image *image, int intent_code, const char *out_fname, const char *curv_fname, const char *datatype);
4748
int MRISwriteGIFTIShape(MRIS *mris, const MRI *mri, int stframe, int endframe, gifti_image *image, int intent_code, const char *curv_fname, const char *datatype);
4849
int MRISwriteGIFTIStats(MRIS *mris, const MRI *mri, int stframe, int endframe, gifti_image *image, int intent_code, const char *curv_fname, const char *datatype);
4950

51+
// function to return SHAPE and <STATS> intent counts
52+
int getShapeStatIntentCount(const char *fgifti);
53+
5054

5155

5256
#endif

utils/MRISurfOverlay.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,32 @@ bool MRISurfOverlay::__isStatsData(int nthOverlay)
683683

684684
return statsData;
685685
}
686+
687+
int MRISurfOverlay::__getFrameCount()
688+
{
689+
int count = 0;
690+
for (int n = 0; n < __noverlay; n++)
691+
{
692+
int overlayFormat = getFileFormat(__overlayInfo[n].__foverlay);
693+
if (overlayFormat == MRI_MGH_FILE)
694+
{
695+
MRI *tempMRI = MRIreadHeader(__overlayInfo[n].__foverlay, MRI_MGH_FILE);
696+
if (tempMRI == NULL)
697+
return count;
698+
699+
count += tempMRI->nframes;
700+
MRIfree(&tempMRI);
701+
}
702+
else if (overlayFormat == GIFTI_FILE)
703+
{
704+
int intents = getShapeStatIntentCount(__overlayInfo[__currFrame].__foverlay);
705+
count += intents;
706+
}
707+
else // MRI_CURV_FILE, ASCII_FILE, VTK_FILE, and old curv format
708+
count++;
709+
710+
__overlayInfo[n].__format = overlayFormat;
711+
}
712+
713+
return count;
714+
}

utils/gifti.cpp

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum, MRI *outmri,
11101110
gifti_free_image(image);
11111111

11121112
return mris;
1113-
}
1113+
} // end of mrisReadGIFTIdanum()
11141114

11151115

11161116
/*-----------------------------------------------------------
@@ -1275,7 +1275,7 @@ MRI *MRISreadGiftiAsMRI(const char *fname, int read_volume)
12751275
/* And we're done. */
12761276
gifti_free_image(image);
12771277
return (mri);
1278-
}
1278+
} // end of MRISreadGiftiAsMRI()
12791279

12801280
/*
12811281
* insert username and current date into meta data
@@ -1359,7 +1359,7 @@ int MRISwriteGIFTI(MRIS *mris, int intent_code, const char *out_fname, const cha
13591359
gifti_free_image(image);
13601360

13611361
return ERROR_NONE;
1362-
}
1362+
} // end of MRISwriteGIFTI()
13631363

13641364
/*-----------------------------------------------------------
13651365
Parameters: MRI structure (surface-encoded volume),
@@ -1471,7 +1471,7 @@ int mriWriteGifti(MRI *mri, const char *out_fname)
14711471
gifti_free_image(image);
14721472

14731473
return ERROR_NONE;
1474-
}
1474+
} // end of mriWriteGifti()
14751475

14761476

14771477

@@ -1524,7 +1524,7 @@ int MRISwriteGIFTIIntent(MRIS *mris, int intent_code, gifti_image *image, const
15241524
} // end of if NIFTI_INTENT_<stats>
15251525

15261526
return NO_ERROR;
1527-
} // end of MRISwriteGIFTIIntent()
1527+
} // end of MRISwriteGIFTIIntent(MRIS *mris, ...)
15281528

15291529

15301530
/*
@@ -1613,7 +1613,7 @@ int MRISwriteGIFTIShape(MRIS *mris, gifti_image *image, int intent_code, const c
16131613
}
16141614

16151615
return NO_ERROR;
1616-
} // end of MRISwriteGIFTIShape()
1616+
} // end of MRISwriteGIFTIShape(MRIS *mris, ...)
16171617

16181618

16191619
/*
@@ -1676,7 +1676,7 @@ int MRISwriteGIFTIStats(MRIS *mris, gifti_image *image, int intent_code)
16761676
}
16771677

16781678
return NO_ERROR;
1679-
} // end of MRISwriteGIFTIStats()
1679+
} // end of MRISwriteGIFTIStats(MRIS *mris, ...)
16801680

16811681

16821682
/*
@@ -2304,7 +2304,7 @@ int MRISwriteGIFTIIntent(MRIS *mris, const MRI *mri, int stframe, int endframe,
23042304
} // end of if NIFTI_INTENT_<stats>
23052305

23062306
return NO_ERROR;
2307-
}
2307+
} // end of MRISwriteGIFTIIntent(MRIS *mris, const MRI *mri, ...)
23082308

23092309

23102310
/*
@@ -2424,7 +2424,7 @@ int MRISwriteGIFTIShape(MRIS *mris, const MRI *mri, int stframe, int endframe, g
24242424
#endif
24252425

24262426
return NO_ERROR;
2427-
} // end of MRISwriteGIFTIShape()
2427+
} // end of MRISwriteGIFTIShape(MRIS *mris, const MRI *mri, ...)
24282428

24292429

24302430
/*
@@ -2513,4 +2513,61 @@ int MRISwriteGIFTIStats(MRIS *mris, const MRI *mri, int stframe, int endframe, g
25132513
#endif
25142514

25152515
return NO_ERROR;
2516-
} // end of MRISwriteGIFTIStats()
2516+
} // end of MRISwriteGIFTIStats(MRIS *mris, const MRI *mri, ...)
2517+
2518+
2519+
int getShapeStatIntentCount(const char *fgifti)
2520+
{
2521+
/*
2522+
* attempt to read the file
2523+
*/
2524+
gifti_image *image = gifti_read_image(fgifti, 1);
2525+
if (NULL == image) {
2526+
fprintf(stderr, "getShapeStatIntentCount(): gifti_read_image() returned NULL\n");
2527+
return 0;
2528+
}
2529+
2530+
// make sure version is recoded before validation
2531+
if (!strcmp(image->version, "1")) {
2532+
free(image->version);
2533+
image->version = strcpyalloc(GIFTI_XML_VERSION);
2534+
}
2535+
2536+
/*
2537+
* check for compliance
2538+
*/
2539+
int valid = gifti_valid_gifti_image(image, 1);
2540+
if (valid == 0) {
2541+
fprintf(stderr, "getShapeStatIntentCount(): GIFTI file %s is invalid!\n", fgifti);
2542+
gifti_free_image(image);
2543+
return 0;
2544+
}
2545+
2546+
/*
2547+
* Now parse the DataArrays, count NIFTI_INTENT_SHAPE and NIFTI_INTENT_<stat>
2548+
*/
2549+
int count = 0;
2550+
int endDAnum = image->numDA;
2551+
for (int numDA = 0; numDA < endDAnum; numDA++) {
2552+
giiDataArray *darray = image->darray[numDA];
2553+
2554+
// skip these intents
2555+
if ((darray->intent == NIFTI_INTENT_POINTSET) ||
2556+
(darray->intent == NIFTI_INTENT_TRIANGLE) ||
2557+
(darray->intent == NIFTI_INTENT_LABEL) ||
2558+
(darray->intent == NIFTI_INTENT_GENMATRIX) ||
2559+
(darray->intent == NIFTI_INTENT_VECTOR) ||
2560+
(darray->intent == NIFTI_INTENT_RGB_VECTOR) ||
2561+
(darray->intent == NIFTI_INTENT_RGBA_VECTOR))
2562+
continue;
2563+
2564+
count++;
2565+
}
2566+
2567+
/*
2568+
* And we're done.
2569+
*/
2570+
gifti_free_image(image);
2571+
2572+
return count;
2573+
} // end of getShapeStatIntentCount()

0 commit comments

Comments
 (0)