diff --git a/.clang-format b/.clang-format index f31bad7b1b8..625afe8072c 100644 --- a/.clang-format +++ b/.clang-format @@ -15,18 +15,18 @@ BinPackArguments: false BinPackParameters: false # Use customized breaks for braces to conform with old FS coding patterns -#BreakBeforeBraces: Custom -#BraceWrapping: -# AfterClass: true +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: true # AfterControlStatement: true # AfterEnum: true -# AfterFunction: true - # AfterNamespace: true + AfterFunction: true + AfterNamespace: true # AfterObjCDeclaration: true - # AfterStruct: true + AfterStruct: true # AfterUnion: true # BeforeCatch: true -# BeforeElse: true + BeforeElse: true # IndentBraces: false # Enforce indentation, width and use of tabs/vs spaces diff --git a/utils/Bruker.c b/utils/Bruker.c index c19b571f244..7b158a47df4 100644 --- a/utils/Bruker.c +++ b/utils/Bruker.c @@ -159,7 +159,8 @@ char *BRUCKER_C_VERSION = "$Revision: 1.12 $"; #define V4_LOAD(v, x, y, z, r) (VECTOR_ELT(v, 1) = x, VECTOR_ELT(v, 2) = y, VECTOR_ELT(v, 3) = z, VECTOR_ELT(v, 4) = r); -MRI *brukerRead(char *fname, int read_volume) { +MRI *brukerRead(char *fname, int read_volume) +{ char methodFile[1024]; char acqpFile[1024]; char dataFile[1024]; @@ -214,7 +215,8 @@ MRI *brukerRead(char *fname, int read_volume) { } int checkBrukerFiles( - char *fname, char *methodFile, char *acqpFile, char *dataFile, char *d3procFile, char *recoFile, int flag) { + char *fname, char *methodFile, char *acqpFile, char *dataFile, char *d3procFile, char *recoFile, int flag) +{ struct stat stat_buf; if (stat(fname, &stat_buf) < 0) { @@ -272,7 +274,8 @@ int checkBrukerFiles( return 1; } -int splitParameterValue(char *sWholeLine, char *sParameter, char *sValue) { +int splitParameterValue(char *sWholeLine, char *sParameter, char *sValue) +{ char *p0, *p1; // check to make sure that ## is at the beginning @@ -300,7 +303,8 @@ int splitParameterValue(char *sWholeLine, char *sParameter, char *sValue) { return 1; } -int readBrukerD3proc(char *d3procFile, int *px, int *py, int *pz, int *ptype, int *pnframes) { +int readBrukerD3proc(char *d3procFile, int *px, int *py, int *pz, int *ptype, int *pnframes) +{ FILE *fp = 0; char line[512]; char Value[128]; @@ -326,13 +330,15 @@ int readBrukerD3proc(char *d3procFile, int *px, int *py, int *pz, int *ptype, in lRead = sscanf(Value, "%d", pz); else if (!strcmp(Parameter, "$IM_SIT")) { sscanf(Value, "%d", pz); - } else if (!strcmp(Parameter, "$IM_SIT")) { + } + else if (!strcmp(Parameter, "$IM_SIT")) { sscanf(Value, "%d", pnframes); if (*pnframes > 1) { fprintf(stderr, "ERROR: nframes %d but one is supported.\n", *pnframes); return 0; } - } else if (!strcmp(Parameter, "$DATTYPE")) { + } + else if (!strcmp(Parameter, "$DATTYPE")) { if (strcmp(Value, "ip_short") == 0) *ptype = MRI_SHORT; else if (strcmp(Value, "ip_int") == 0) @@ -350,7 +356,8 @@ int readBrukerD3proc(char *d3procFile, int *px, int *py, int *pz, int *ptype, in return 1; } -int buildVoxToRASTransform(MRI *mri, BrukerTransform *pTran) { +int buildVoxToRASTransform(MRI *mri, BrukerTransform *pTran) +{ MATRIX *transposMatrix; MATRIX *voxmmMatrix; MATRIX *swapMatrix; @@ -494,7 +501,8 @@ int buildVoxToRASTransform(MRI *mri, BrukerTransform *pTran) { mri->z_r = *MATRIX_RELT(rottranMatrix, 1, 3); mri->z_a = *MATRIX_RELT(rottranMatrix, 2, 3); mri->z_s = *MATRIX_RELT(rottranMatrix, 3, 3); - } else // 2d case just fake + } + else // 2d case just fake { mri->x_r = -1; mri->x_a = 0; @@ -511,7 +519,8 @@ int buildVoxToRASTransform(MRI *mri, BrukerTransform *pTran) { mri->xsize = pTran->vox_size[1]; mri->ysize = pTran->vox_size[0]; mri->zsize = pTran->vox_size[2]; - } else { + } + else { mri->xsize = pTran->vox_size[0]; mri->ysize = pTran->vox_size[1]; mri->zsize = pTran->vox_size[2]; @@ -533,7 +542,8 @@ int buildVoxToRASTransform(MRI *mri, BrukerTransform *pTran) { return 1; } -int readBrukerAcqp(char *acqpFile, double *pTR, double *pTE, double *pTI, double *pflip_angle, BrukerTransform *bTran) { +int readBrukerAcqp(char *acqpFile, double *pTR, double *pTE, double *pTI, double *pflip_angle, BrukerTransform *bTran) +{ FILE *fp = 0; char line[512]; char Parameter[256]; @@ -614,21 +624,24 @@ int readBrukerAcqp(char *acqpFile, double *pTR, double *pTE, double *pTI, double return 0; } sscanf(line, "%lf", &bTran->read_offset); - } else if (!strcmp(Parameter, "$ACQ_phase1_offset")) { + } + else if (!strcmp(Parameter, "$ACQ_phase1_offset")) { if (!fgets(line, sizeof(line), fp)) { fprintf(stderr, "ERROR: float value must follow ACQ_phase1_offset"); fclose(fp); return 0; } sscanf(line, "%lf", &bTran->phase1_offset); - } else if (!strcmp(Parameter, "$ACQ_slice_offset")) { + } + else if (!strcmp(Parameter, "$ACQ_slice_offset")) { if (!fgets(line, sizeof(line), fp)) { fprintf(stderr, "ERROR: float value must follow ACQ_slice_offset"); fclose(fp); return 0; } sscanf(line, "%lf", &bTran->slice_offset); - } else if (!strcmp(Parameter, "$ACQ_grad_matrix")) { + } + else if (!strcmp(Parameter, "$ACQ_grad_matrix")) { if (!fgets(line, sizeof(line), fp)) { fprintf(stderr, "ERROR: float value must follow ACQ_slice_offset"); fclose(fp); @@ -654,7 +667,8 @@ int readBrukerAcqp(char *acqpFile, double *pTR, double *pTE, double *pTI, double return 1; } -int readBrukerReco(char *recoFile, BrukerTransform *pTran) { +int readBrukerReco(char *recoFile, BrukerTransform *pTran) +{ FILE *fp = 0; char line[512]; char Parameter[256]; @@ -683,7 +697,8 @@ int readBrukerReco(char *recoFile, BrukerTransform *pTran) { } sscanf(line, "%d", &pTran->transposition); - } else if (!strcmp(Parameter, "$RECO_fov")) { + } + else if (!strcmp(Parameter, "$RECO_fov")) { // lRead = sscanf(Value, "%d", &dim); pTran->dim = dim; @@ -700,12 +715,14 @@ int readBrukerReco(char *recoFile, BrukerTransform *pTran) { if (dim == 3) { sscanf(line, "%lf %lf %lf", &pTran->fov[0], &pTran->fov[1], &pTran->fov[2]); - } else if (dim == 2) { + } + else if (dim == 2) { sscanf(line, "%lf %lf", &pTran->fov[0], &pTran->fov[1]); pTran->fov[2] = pTran->fov[0]; } - } else if (!strcmp(Parameter, "$RECO_size")) { + } + else if (!strcmp(Parameter, "$RECO_size")) { // lRead = sscanf(Value, "%d", &dim); if (dim != 3) fprintf(stderr, "INFO: size dimension is %d. The data is not a 3D volume.\n", dim); @@ -721,7 +738,8 @@ int readBrukerReco(char *recoFile, BrukerTransform *pTran) { sscanf(line, "%d %d", &pTran->size[0], &pTran->size[1]); pTran->size[2] = pTran->size[0]; // just fake } - } else if (!strcmp(Parameter, "$RECO_ft_size")) { + } + else if (!strcmp(Parameter, "$RECO_ft_size")) { // lRead = sscanf(Value, "%d", &dim); if (dim != 3) fprintf(stderr, "INFO: ft_size dimension is %d. The data is not a 3D volume.\n", dim); @@ -737,7 +755,8 @@ int readBrukerReco(char *recoFile, BrukerTransform *pTran) { sscanf(line, "%d %d", &pTran->ft_size[0], &pTran->ft_size[1]); pTran->ft_size[2] = pTran->ft_size[0]; // just fake } - } else if (!strcmp(Parameter, "$RECO_wordtype")) { + } + else if (!strcmp(Parameter, "$RECO_wordtype")) { if ((strncmp(Value, "_16BIT_SGN_INT", 13) == 0)) pTran->type = MRI_SHORT; else if ((strncmp(Value, "_32BIT_SGN_INT", 13) == 0)) @@ -746,9 +765,11 @@ int readBrukerReco(char *recoFile, BrukerTransform *pTran) { fprintf(stderr, "INFO: unsupported data type %s\n", Value); return 0; } - } else if (!strcmp(Parameter, "$RECO_mode")) { + } + else if (!strcmp(Parameter, "$RECO_mode")) { printf("INFO: reconstruction mode was %s\n", Value); - } else if (!strcmp(Parameter, "ORIGIN")) { + } + else if (!strcmp(Parameter, "ORIGIN")) { printf("INFO: software by %s\n", Value); } } @@ -764,7 +785,8 @@ int readBrukerReco(char *recoFile, BrukerTransform *pTran) { extern void swab(const void *from, void *to, size_t n); #endif -int readBrukerVolume(MRI *mri, char *dataFile) { +int readBrukerVolume(MRI *mri, char *dataFile) +{ FILE *fp = 0; int k, j; int nread; @@ -824,7 +846,8 @@ int readBrukerVolume(MRI *mri, char *dataFile) { return 1; } -int is_bruker(char *fname) { +int is_bruker(char *fname) +{ struct stat stat_buf; char methodFile[512]; char acqpFile[512]; diff --git a/utils/DICOMRead.c b/utils/DICOMRead.c index 707758d982e..782036e78ae 100644 --- a/utils/DICOMRead.c +++ b/utils/DICOMRead.c @@ -92,7 +92,8 @@ static const char *rllEncoded_UID = "1.2.840.10008.1.2.5"; be unpacked as one run. If using mri_convert, it can be passed with the --sdcmlist. -----------------------------------------------------------------*/ -MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { +MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) +{ SDCMFILEINFO *sdfi; DCM_ELEMENT *element; SDCMFILEINFO **sdfi_list; @@ -244,7 +245,8 @@ MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { fflush(stderr); return (NULL); } - } else { + } + else { vol = MRIallocHeader(ncols, nrows, nslices, vol_datatype, nframes); if (vol == NULL) { fprintf(stderr, "ERROR: could not alloc MRI header \n"); @@ -290,7 +292,8 @@ MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { // and earlier. printf("Computing TR with number of slices\n"); vol->tr = sdfi->RepetitionTime * (sdfi->VolDim[2]); - } else + } + else vol->tr = sdfi->RepetitionTime; /* Need to add any gap (eg, as in a hammer sequence */ printf("Repetition Time = %g, TR = %g ms\n", sdfi->RepetitionTime, vol->tr); @@ -393,7 +396,8 @@ MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { exit(1); } FileNameUse = tmpfile; - } else { + } + else { IsCompressed = 0; FileNameUse = sdfi->FileName; } @@ -438,7 +442,8 @@ MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { a SHORT, but now we're saving as FLOATs.. */ // val = 8*MinSliceScaleFactor*(*(pixeldata++))/sdfi->SliceScaleFactor; val = ((float)*(pixeldata++)) / sdfi->SliceScaleFactor; - } else + } + else val = *(pixeldata++); MRIsetVoxVal(vol, col, row, slice, frame, val); } @@ -467,7 +472,8 @@ MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { frame = 0; slice++; } - } else { // is a mosaic + } + else { // is a mosaic /*---------------------------------------------*/ /* It is a mosaic -- load entire volume for this frame from pixel data */ frame = nthfile; @@ -522,7 +528,8 @@ MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { voltmp = MRIreverseSliceOrder(vol, NULL); MRIfree(&vol); vol = voltmp; - } else + } + else printf("INFO: no Siemens slice order reversal detected (good!). \n"); if (IsDWI) { @@ -569,7 +576,8 @@ MRI *sdcmLoadVolume(const char *dcmfile, int LoadVolume, int nthonly) { This is what is needed for autoscaled diffusion data. TW 03/22/2012 */ -MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { +MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) +{ SDCMFILEINFO *sdfi; DCM_ELEMENT *element; SDCMFILEINFO **sdfi_list; @@ -603,7 +611,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { global_progress_range[1] = nstart + (nend - nstart) / 3; if (SDCMListFile != NULL) { SeriesList = ReadSiemensSeries(SDCMListFile, &nlist, dcmfile); - } else { + } + else { SeriesList = ScanSiemensSeries(dcmfile, &nlist); } @@ -643,7 +652,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { /* First File in the Run */ if (nthonly < 0) { sdfi = sdfi_list[0]; - } else { + } + else { sdfi = sdfi_list[nthonly]; } @@ -705,7 +715,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { if (LoadVolume) { if (nthonly < 0) { vol = MRIallocSequence(ncols, nrows, nslices, MRI_FLOAT, nframes); - } else { + } + else { vol = MRIallocSequence(ncols, nrows, nslices, MRI_FLOAT, 1); } if (vol == NULL) { @@ -713,7 +724,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { fflush(stderr); return (NULL); } - } else { + } + else { vol = MRIallocHeader(ncols, nrows, nslices, MRI_FLOAT, nframes); if (vol == NULL) { fprintf(stderr, "ERROR: could not alloc MRI header \n"); @@ -745,7 +757,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { vol->FieldStrength = sdfi->FieldStrength; if (!sdfi->IsMosaic) { vol->tr = sdfi->RepetitionTime; - } else { + } + else { /* The TR definition will depend upon the software version */ tmpstring = sdcmExtractNumarisVer(sdfi->NumarisVer, &Maj, &Min, &MinMin); if (tmpstring != NULL) { @@ -759,7 +772,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { // and earlier. printf("Computing TR with number of slices\n"); vol->tr = sdfi->RepetitionTime * (sdfi->VolDim[2]); - } else { + } + else { vol->tr = sdfi->RepetitionTime; } /* Need to add any gap (eg, as in a hammer sequence */ @@ -772,7 +786,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { // Phase Enc Direction if (sdfi->PhEncDir == NULL) { vol->pedir = strcpyalloc("UNKNOWN"); - } else { + } + else { vol->pedir = strcpyalloc(sdfi->PhEncDir); str_toupper(vol->pedir); } @@ -790,18 +805,21 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { printf("This looks like an MGH DTI volume\n"); if (getenv("UNPACK_MGH_DTI") != NULL) { sscanf(getenv("UNPACK_MGH_DTI"), "%d", &TryDTI); - } else { + } + else { TryDTI = 1; } if (TryDTI) { DoDTI = 1; - } else { + } + else { DoDTI = 0; } if (!DoDTI) { printf(" but not getting bvec info because UNPACK_MGH_DTI is 0\n"); } - } else { + } + else { DoDTI = 0; } if (DoDTI && !sdfi->IsMosaic) { @@ -945,7 +963,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { frame = 0; slice++; } - } else { + } + else { /*---------------------------------------------*/ /* It is a mosaic -- load entire volume for this frame from pixel data */ frame = nthfile; @@ -990,7 +1009,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { voltmp = MRIreverseSliceOrder(vol, NULL); MRIfree(&vol); vol = voltmp; - } else { + } + else { printf("INFO: no Siemens slice order reversal detected (good!). \n"); } @@ -1048,7 +1068,8 @@ MRI *sdcmLoadVolumeAutoScale(const char *dcmfile, int LoadVolume, int nthonly) { \fn MATRIX *sdcmAutoAlignMatrix(const char *dcmfile) \brief Extracts the Auto Align Matrix from the Siemens ascii header. */ -MATRIX *sdcmAutoAlignMatrix(const char *dcmfile) { +MATRIX *sdcmAutoAlignMatrix(const char *dcmfile) +{ char *tmpstr; char sdcmtag[1000]; int n, row, col; @@ -1073,7 +1094,8 @@ MATRIX *sdcmAutoAlignMatrix(const char *dcmfile) { tmpstr = SiemensAsciiTagEx(dcmfile, sdcmtag, 0); if (tmpstr == NULL) { v = 0; - } else { + } + else { sscanf(tmpstr, "%lf", &v); free(tmpstr); } @@ -1100,7 +1122,8 @@ MATRIX *sdcmAutoAlignMatrix(const char *dcmfile) { a pointer to the object (or NULL upon failure). Author: Douglas Greve 9/6/2001 ---------------------------------------------------------------*/ -DCM_ELEMENT *GetElementFromFile(const char *dicomfile, long grpid, long elid) { +DCM_ELEMENT *GetElementFromFile(const char *dicomfile, long grpid, long elid) +{ DCM_OBJECT *object = 0; CONDITION cond; DCM_ELEMENT *element; @@ -1142,7 +1165,8 @@ DCM_ELEMENT *GetElementFromFile(const char *dicomfile, long grpid, long elid) { a pointer to the object (or NULL upon failure). Author: Douglas Greve ---------------------------------------------------------------*/ -DCM_OBJECT *GetObjectFromFile(const char *fname, unsigned long options) { +DCM_OBJECT *GetObjectFromFile(const char *fname, unsigned long options) +{ CONDITION cond; DCM_OBJECT *object = 0; int ok; @@ -1186,7 +1210,8 @@ DCM_OBJECT *GetObjectFromFile(const char *fname, unsigned long options) { Use FreeElementData() to free the data portion. Author: Douglas N. Greve, 9/6/2001 -------------------------------------------------------------------*/ -int AllocElementData(DCM_ELEMENT *e) { +int AllocElementData(DCM_ELEMENT *e) +{ switch (e->representation) { case DCM_AE: case DCM_AS: @@ -1247,7 +1272,8 @@ int AllocElementData(DCM_ELEMENT *e) { For string elements, it just copies the string and adds a terminator. For others, it just uses sprrintf. ---------------------------------------------------------------*/ -char *ElementValueString(DCM_ELEMENT *e, int DoBackslash) { +char *ElementValueString(DCM_ELEMENT *e, int DoBackslash) +{ char *evstring; int n, len; char tmpstr[20000]; @@ -1338,7 +1364,8 @@ char *ElementValueString(DCM_ELEMENT *e, int DoBackslash) { See also AllocElementData(). Author: Douglas N. Greve, 9/6/2001 -------------------------------------------------------------------*/ -int FreeElementData(DCM_ELEMENT *e) { +int FreeElementData(DCM_ELEMENT *e) +{ switch (e->representation) { case DCM_AE: case DCM_AS: @@ -1408,7 +1435,8 @@ int FreeElementData(DCM_ELEMENT *e) { Checks DICOM tag (8,70). Author: Douglas N. Greve, 9/6/2001 -------------------------------------------------------------------*/ -int IsSiemensDICOM(const char *dcmfile) { +int IsSiemensDICOM(const char *dcmfile) +{ DCM_ELEMENT *e; // printf("Entering IsSiemensDICOM (%s)\n",dcmfile); @@ -1452,7 +1480,8 @@ int IsSiemensDICOM(const char *dcmfile) { /* The original SiemensQsciiTag() is too slow */ /* make sure that returned value be freed if non-null */ -char *SiemensAsciiTagEx(const char *dcmfile, const char *TagString, int cleanup) { +char *SiemensAsciiTagEx(const char *dcmfile, const char *TagString, int cleanup) +{ static char filename[1024] = ""; static char **lists = 0; static int count = 0; @@ -1551,7 +1580,8 @@ char *SiemensAsciiTagEx(const char *dcmfile, const char *TagString, int cleanup) // do not include the chars ' ###' if (strncmp(buf, "### ASCCONV BEGIN", 17) == 0) { startOfAscii = 1; - } else if (strncmp(buf, "### ASCCONV END ###", 19) == 0) { + } + else if (strncmp(buf, "### ASCCONV END ###", 19) == 0) { startOfAscii = 0; } @@ -1574,7 +1604,8 @@ char *SiemensAsciiTagEx(const char *dcmfile, const char *TagString, int cleanup) lists[MAX_ASCIILIST + i] = (char *)0; } MAX_ASCIILIST = newSize; - } else { + } + else { // this should not happen, but hey just in case. // Ascii tag is not essential and thus allow it to pass. fprintf(stderr, @@ -1598,7 +1629,8 @@ char *SiemensAsciiTagEx(const char *dcmfile, const char *TagString, int cleanup) sscanf(lists[i], "%*s %*s %s", tmpstr2); VariableValue = (char *)calloc(strlen(tmpstr2) + 17, sizeof(char)); memmove(VariableValue, tmpstr2, strlen(tmpstr2)); - } else { + } + else { continue; } } @@ -1636,7 +1668,8 @@ char *SiemensAsciiTagEx(const char *dcmfile, const char *TagString, int cleanup) Author: Douglas N. Greve, 9/6/2001 -----------------------------------------------------------------*/ -char *SiemensAsciiTag(const char *dcmfile, const char *TagString, int flag) { +char *SiemensAsciiTag(const char *dcmfile, const char *TagString, int flag) +{ char linestr[4000]; char tmpstr2[500]; FILE *fp; @@ -1744,7 +1777,8 @@ char *SiemensAsciiTag(const char *dcmfile, const char *TagString, int flag) { See sdcmMosaicSliceRes(). Author: Douglas N. Greve, 9/6/2001 -----------------------------------------------------------------------*/ -int dcmGetVolRes(const char *dcmfile, float *ColRes, float *RowRes, float *SliceRes) { +int dcmGetVolRes(const char *dcmfile, float *ColRes, float *RowRes, float *SliceRes) +{ DCM_ELEMENT *e; char *s; int ns, n; @@ -1799,7 +1833,8 @@ int dcmGetVolRes(const char *dcmfile, float *ColRes, float *RowRes, float *Slice SliceResElTag1 = 0x50; else SliceResElTag1 = 0x88; - } else + } + else printf("Tag 18,23 is null, cannot automatically determine SliceResElTag\n"); printf("SliceResElTag order is %lx then %lx\n", SliceResElTag1, SliceResElTag2); } @@ -1835,7 +1870,8 @@ int dcmGetVolRes(const char *dcmfile, float *ColRes, float *RowRes, float *Slice Returns -1 if error. Author: Douglas N. Greve, 9/25/2001 -----------------------------------------------------------------------*/ -int dcmGetSeriesNo(const char *dcmfile) { +int dcmGetSeriesNo(const char *dcmfile) +{ DCM_ELEMENT *e; int SeriesNo; @@ -1858,7 +1894,8 @@ int dcmGetSeriesNo(const char *dcmfile) { Returns -1 if error. Author: Douglas N. Greve, 9/6/2001 -----------------------------------------------------------------------*/ -int dcmGetNRows(const char *dcmfile) { +int dcmGetNRows(const char *dcmfile) +{ DCM_ELEMENT *e; int NRows; @@ -1885,7 +1922,8 @@ int dcmGetNRows(const char *dcmfile) { Returns -1 if error. Author: Douglas N. Greve, 9/6/2001 -----------------------------------------------------------------------*/ -int dcmGetNCols(const char *dcmfile) { +int dcmGetNCols(const char *dcmfile) +{ DCM_ELEMENT *e; int NCols; @@ -1910,7 +1948,8 @@ int dcmGetNCols(const char *dcmfile) { Returns 1 if error. Author: Douglas N. Greve, 9/10/2001 -----------------------------------------------------------------------*/ -int dcmImageDirCos(const char *dcmfile, float *Vcx, float *Vcy, float *Vcz, float *Vrx, float *Vry, float *Vrz) { +int dcmImageDirCos(const char *dcmfile, float *Vcx, float *Vcy, float *Vcz, float *Vrx, float *Vry, float *Vrz) +{ DCM_ELEMENT *e; char *s; int n, nbs; @@ -1972,7 +2011,8 @@ int dcmImageDirCos(const char *dcmfile, float *Vcx, float *Vcy, float *Vcz, floa Returns 1 if error. Author: Douglas N. Greve, 9/10/2001 -----------------------------------------------------------------------*/ -int dcmImagePosition(const char *dcmfile, float *x, float *y, float *z) { +int dcmImagePosition(const char *dcmfile, float *x, float *y, float *z) +{ DCM_ELEMENT *e; char *s; int n, nbs; @@ -2024,7 +2064,8 @@ int dcmImagePosition(const char *dcmfile, float *x, float *y, float *z) { Returns 1 if error. Author: Douglas N. Greve, 9/10/2001 -----------------------------------------------------------------------*/ -int sdcmSliceDirCos(const char *dcmfile, float *Vsx, float *Vsy, float *Vsz) { +int sdcmSliceDirCos(const char *dcmfile, float *Vsx, float *Vsy, float *Vsz) +{ char *tmpstr; float rms; @@ -2084,7 +2125,8 @@ int sdcmSliceDirCos(const char *dcmfile, float *Vsx, float *Vsy, float *Vsz) { Author: Douglas N. Greve, 9/6/2001 -----------------------------------------------------------------------*/ -int sdcmIsMosaic(const char *dcmfile, int *pNcols, int *pNrows, int *pNslices, int *pNframes) { +int sdcmIsMosaic(const char *dcmfile, int *pNcols, int *pNrows, int *pNslices, int *pNframes) +{ DCM_ELEMENT *e; char *PhEncDir; int Nrows, Ncols; @@ -2150,7 +2192,8 @@ int sdcmIsMosaic(const char *dcmfile, int *pNcols, int *pNrows, int *pNslices, i /* Each row is a different phase encode */ NrowsExp = (int)(rint(PhEncFOV / RowRes)); NcolsExp = (int)(rint(ReadOutFOV / ColRes)); - } else { + } + else { /* Each column is a different phase encode */ NrowsExp = (int)(rint(ReadOutFOV / RowRes)); NcolsExp = (int)(rint(PhEncFOV / ColRes)); @@ -2162,7 +2205,8 @@ int sdcmIsMosaic(const char *dcmfile, int *pNcols, int *pNrows, int *pNslices, i tmpstr = getenv("NROWS_OVERRIDE"); if (tmpstr == NULL) { *pNrows = NrowsExp; - } else { + } + else { sscanf(tmpstr, "%d", pNrows); printf("Overriding number of rows with %d\n", *pNrows); } @@ -2171,7 +2215,8 @@ int sdcmIsMosaic(const char *dcmfile, int *pNcols, int *pNrows, int *pNslices, i tmpstr = getenv("NCOLS_OVERRIDE"); if (tmpstr == NULL) { *pNcols = NcolsExp; - } else { + } + else { sscanf(tmpstr, "%d", pNcols); printf("Overriding number of columns with %d\n", *pNcols); } @@ -2185,7 +2230,8 @@ int sdcmIsMosaic(const char *dcmfile, int *pNcols, int *pNrows, int *pNslices, i } sscanf(tmpstr, "%d", pNslices); free(tmpstr); - } else { + } + else { sscanf(tmpstr, "%d", pNslices); printf("Overriding number of slices with %d\n", *pNslices); } @@ -2210,7 +2256,8 @@ int sdcmIsMosaic(const char *dcmfile, int *pNcols, int *pNrows, int *pNslices, i the DICOM header and some from the Siemens ASCII header. The pixel data are not loaded. ----------------------------------------------------------------*/ -SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { +SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) +{ DCM_OBJECT *object = 0; SDCMFILEINFO *sdcmfi; CONDITION cond; @@ -2322,7 +2369,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { cond = GetDoubleFromString(&object, tag, &dtmp); if (cond == DCM_NORMAL) { sdcmfi->FlipAngle = (float)M_PI * dtmp / 180.0; - } else { + } + else { sdcmfi->FlipAngle = 0; } @@ -2364,7 +2412,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { // This can cause problems with DTI scans if lRepetitions is actually set sscanf(strtmp, "%d", &(sdcmfi->lRepetitions)); free(strtmp); - } else { + } + else { strtmp = SiemensAsciiTag(dcmfile, "sDiffusion.lDiffDirections", 0); strtmp2 = SiemensAsciiTag(dcmfile, "sWiPMemBlock.alFree[8]", 0); if (strtmp != NULL && strtmp2 != NULL) { @@ -2375,7 +2424,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { // printf("nDiffDirections = %d, nB0 = %d\n",nDiffDirections,nB0); // printf("%s %g %d\n",sdcmfi->PulseSequence, // sdcmfi->bValue, sdcmfi->nthDirection); - } else { + } + else { sdcmfi->lRepetitions = 0; } if (strtmp) { @@ -2392,7 +2442,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { if (strtmp != NULL) { sscanf(strtmp, "%d", &(sdcmfi->SliceArraylSize)); free(strtmp); - } else { + } + else { sdcmfi->SliceArraylSize = 0; } @@ -2400,7 +2451,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { if (strtmp != NULL) { sscanf(strtmp, "%f", &(sdcmfi->PhEncFOV)); free(strtmp); - } else { + } + else { sdcmfi->PhEncFOV = 0; } @@ -2408,7 +2460,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { if (strtmp != NULL) { sscanf(strtmp, "%f", &(sdcmfi->ReadoutFOV)); free(strtmp); - } else { + } + else { sdcmfi->ReadoutFOV = 0; } @@ -2478,7 +2531,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { if (sdcmfi->IsMosaic) { sdcmIsMosaic(dcmfile, &(sdcmfi->VolDim[0]), &(sdcmfi->VolDim[1]), &(sdcmfi->VolDim[2]), &(sdcmfi->NFrames)); - } else { + } + else { sdcmfi->VolDim[0] = sdcmfi->NImageCols; sdcmfi->VolDim[1] = sdcmfi->NImageRows; } @@ -2506,7 +2560,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { sdcmfi->bvecx = xbvec; sdcmfi->bvecy = ybvec; sdcmfi->bvecz = zbvec; - } else { + } + else { sdcmfi->bval = 0; sdcmfi->bvecx = 0; sdcmfi->bvecy = 0; @@ -2524,7 +2579,8 @@ SDCMFILEINFO *GetSDCMFileInfo(const char *dcmfile) { return (sdcmfi); } /*----------------------------------------------------------*/ -int DumpSDCMFileInfo(FILE *fp, SDCMFILEINFO *sdcmfi) { +int DumpSDCMFileInfo(FILE *fp, SDCMFILEINFO *sdcmfi) +{ fprintf(fp, "FileName \t\t%s\n", sdcmfi->FileName); fprintf(fp, "Identification\n"); fprintf(fp, "\tNumarisVer %s\n", sdcmfi->NumarisVer); @@ -2575,7 +2631,8 @@ int DumpSDCMFileInfo(FILE *fp, SDCMFILEINFO *sdcmfi) { } /*-----------------------------------------------------------------*/ -int FreeSDCMFileInfo(SDCMFILEINFO **ppsdcmfi) { +int FreeSDCMFileInfo(SDCMFILEINFO **ppsdcmfi) +{ SDCMFILEINFO *p; p = *ppsdcmfi; @@ -2624,7 +2681,8 @@ int FreeSDCMFileInfo(SDCMFILEINFO **ppsdcmfi) { Minor number is the number after VA. The MinorMinor number is the number the Minor. -------------------------------------------------------------------*/ -char *sdcmExtractNumarisVer(const char *e_18_1020, int *Maj, int *Min, int *MinMin) { +char *sdcmExtractNumarisVer(const char *e_18_1020, int *Maj, int *Min, int *MinMin) +{ int l, n, m; char *ver; @@ -2694,7 +2752,8 @@ char *sdcmExtractNumarisVer(const char *e_18_1020, int *Maj, int *Min, int *MinM Author: Douglas Greve. Date: 09/10/2001 *------------------------------------------------------------------*/ -SDCMFILEINFO **ScanSiemensDCMDir(const char *PathName, int *NSDCMFiles) { +SDCMFILEINFO **ScanSiemensDCMDir(const char *PathName, int *NSDCMFiles) +{ struct dirent **NameList; int i, pathlength; int NFiles; @@ -2800,7 +2859,8 @@ SDCMFILEINFO **ScanSiemensDCMDir(const char *PathName, int *NSDCMFiles) { Author: Douglas Greve. Date: 09/10/2001 *------------------------------------------------------------------*/ -SDCMFILEINFO **LoadSiemensSeriesInfo(char **SeriesList, int nList) { +SDCMFILEINFO **LoadSiemensSeriesInfo(char **SeriesList, int nList) +{ SDCMFILEINFO **sdfi_list; int n; @@ -2850,7 +2910,8 @@ SDCMFILEINFO **LoadSiemensSeriesInfo(char **SeriesList, int nList) { Author: Douglas Greve. Date: 09/25/2001 *------------------------------------------------------------------*/ -char **ReadSiemensSeries(const char *ListFile, int *nList, const char *dcmfile) { +char **ReadSiemensSeries(const char *ListFile, int *nList, const char *dcmfile) +{ FILE *fp; char **SeriesList; char tmpstr[1000]; @@ -2935,7 +2996,8 @@ char **ReadSiemensSeries(const char *ListFile, int *nList, const char *dcmfile) Author: Douglas Greve. Date: 09/25/2001 *------------------------------------------------------------------*/ -char **ScanSiemensSeries(const char *dcmfile, int *nList) { +char **ScanSiemensSeries(const char *dcmfile, int *nList) +{ int SeriesNo, SeriesNoTest; char *PathName; int NFiles, i; @@ -3011,7 +3073,8 @@ char **ScanSiemensSeries(const char *dcmfile, int *nList) { } /*-----------------------------------------------------------*/ -int SortSDCMFileInfo(SDCMFILEINFO **sdcmfi_list, int nlist) { +int SortSDCMFileInfo(SDCMFILEINFO **sdcmfi_list, int nlist) +{ qsort(sdcmfi_list, nlist, sizeof(SDCMFILEINFO **), CompareSDCMFileInfo); return (0); } @@ -3076,7 +3139,8 @@ int SortSDCMFileInfo(SDCMFILEINFO **sdcmfi_list, int nlist) { note 2, the image number comparison should never be reached. 4. For non-mosaics, image number increases for later acquisitions. -----------------------------------------------------------*/ -int CompareSDCMFileInfo(const void *a, const void *b) { +int CompareSDCMFileInfo(const void *a, const void *b) +{ SDCMFILEINFO *sdcmfi1; SDCMFILEINFO *sdcmfi2; int n; @@ -3160,7 +3224,8 @@ int CompareSDCMFileInfo(const void *a, const void *b) { /*----------------------------------------------------------- sdfiAssignRunNo2() - assigns run number based on series number -----------------------------------------------------------*/ -int sdfiAssignRunNo2(SDCMFILEINFO **sdfi_list, int nlist) { +int sdfiAssignRunNo2(SDCMFILEINFO **sdfi_list, int nlist) +{ SDCMFILEINFO *sdfi, *sdfitmp, *sdfi0; int nthfile, NRuns, nthrun, nthslice, nthframe; int nfilesperrun = 0, firstpass, nframes; @@ -3208,7 +3273,8 @@ int sdfiAssignRunNo2(SDCMFILEINFO **sdfi_list, int nlist) { nthfile++; if (nthfile < nfilesperrun) { sdfitmp = sdfi_list[RunList[nthfile]]; - } else { + } + else { break; } } @@ -3256,7 +3322,8 @@ int sdfiAssignRunNo2(SDCMFILEINFO **sdfi_list, int nlist) { /*----------------------------------------------------------- sdfiRunNoList() - returns a list of run numbers -----------------------------------------------------------*/ -int *sdfiRunNoList(SDCMFILEINFO **sdfi_list, int nlist, int *NRuns) { +int *sdfiRunNoList(SDCMFILEINFO **sdfi_list, int nlist, int *NRuns) +{ SDCMFILEINFO *sdfi; int nthfile, PrevRunNo; int *RunNoList; @@ -3286,7 +3353,8 @@ int *sdfiRunNoList(SDCMFILEINFO **sdfi_list, int nlist, int *NRuns) { /*----------------------------------------------------------- sdfiCountRuns() - counts the number of runs in the list -----------------------------------------------------------*/ -int sdfiCountRuns(SDCMFILEINFO **sdfi_list, int nlist) { +int sdfiCountRuns(SDCMFILEINFO **sdfi_list, int nlist) +{ SDCMFILEINFO *sdfi; int nthfile, NRuns, PrevRunNo; @@ -3307,7 +3375,8 @@ int sdfiCountRuns(SDCMFILEINFO **sdfi_list, int nlist) { given run. This differs from sdfiNFilesInRun() in that this takes a run number instead of a file name. -----------------------------------------------------------*/ -int sdfiCountFilesInRun(int RunNo, SDCMFILEINFO **sdfi_list, int nlist) { +int sdfiCountFilesInRun(int RunNo, SDCMFILEINFO **sdfi_list, int nlist) +{ SDCMFILEINFO *sdfi; int nthfile, NFilesInRun; @@ -3324,7 +3393,8 @@ int sdfiCountFilesInRun(int RunNo, SDCMFILEINFO **sdfi_list, int nlist) { sdfiFirstFileInRun() - returns the name of the first file in the given run. -----------------------------------------------------------*/ -char *sdfiFirstFileInRun(int RunNo, SDCMFILEINFO **sdfi_list, int nlist) { +char *sdfiFirstFileInRun(int RunNo, SDCMFILEINFO **sdfi_list, int nlist) +{ SDCMFILEINFO *sdfi; int nthfile, len; char *FirstFileName; @@ -3375,7 +3445,8 @@ char *sdfiFirstFileInRun(int RunNo, SDCMFILEINFO **sdfi_list, int nlist) { 2. For non-mosaics with multiple frames, the number of frames (ie, ->NFrames) is also determined here. -----------------------------------------------------------*/ -int sdfiAssignRunNo(SDCMFILEINFO **sdcmfi_list, int nfiles) { +int sdfiAssignRunNo(SDCMFILEINFO **sdcmfi_list, int nfiles) +{ int nthfile, nthrun, nthslice, nthframe, serno, sernotest; int nfilesperrun; int ncols, nrows, nslices, nframes; @@ -3438,7 +3509,8 @@ int sdfiAssignRunNo(SDCMFILEINFO **sdcmfi_list, int nfiles) { if (nthfile < nfiles) { sdfi = sdcmfi_list[nthfile]; sernotest = sdfi->SeriesNo; - } else { + } + else { sernotest = -1; break; } @@ -3518,7 +3590,8 @@ int sdfiAssignRunNo(SDCMFILEINFO **sdcmfi_list, int nfiles) { dcmfile. The RunNo member is then returned. The sdfi_list must have been sorted into runs with sdfiAssignRunNo(). ------------------------------------------------------------------*/ -int sdfiRunNo(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist) { +int sdfiRunNo(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist) +{ int nthfile; SDCMFILEINFO *sdfi; @@ -3538,7 +3611,8 @@ int sdfiRunNo(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist) { with dcmfile. The Run Number for dcmfile is obtained using sdfiRunNo(). The list is searched for all the files with the same Run Number. ------------------------------------------------------------------*/ -int sdfiNFilesInRun(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist) { +int sdfiNFilesInRun(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist) +{ int nthfile; int RunNo; int NFilesInRun; @@ -3564,7 +3638,8 @@ int sdfiNFilesInRun(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist) { share the same Run Number. The number in the list is passed as NRunList. ------------------------------------------------------------------*/ -int *sdfiRunFileList(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist, int *NRunList) { +int *sdfiRunFileList(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist, int *NRunList) +{ int nthfile, nthfileinrun; SDCMFILEINFO *sdfi; int *RunList; @@ -3620,7 +3695,8 @@ int *sdfiRunFileList(const char *dcmfile, SDCMFILEINFO **sdfi_list, int nlist, i the from non-mosaic volumes with identical slice prescriptions. This change was made on 7/28/05. -----------------------------------------------------------------------*/ -int sdfiFixImagePosition(SDCMFILEINFO *sdfi) { +int sdfiFixImagePosition(SDCMFILEINFO *sdfi) +{ char *strtmp, *dcmfile; MATRIX *ras_c, *R, *crs_c, *ras0; int r; @@ -3689,7 +3765,8 @@ int sdfiFixImagePosition(SDCMFILEINFO *sdfi) { Author: Douglas N. Greve, 9/12/2001. Updated 12/19/02. -----------------------------------------------------------------------*/ -int sdfiVolCenter(SDCMFILEINFO *sdfi) { +int sdfiVolCenter(SDCMFILEINFO *sdfi) +{ int r, c; float Mdc[3][3], FoV[3]; @@ -3722,7 +3799,8 @@ int sdfiVolCenter(SDCMFILEINFO *sdfi) { have the same slice position. Author: Douglas N. Greve, 9/12/2001 -----------------------------------------------------------------------*/ -int sdfiSameSlicePos(SDCMFILEINFO *sdfi1, SDCMFILEINFO *sdfi2) { +int sdfiSameSlicePos(SDCMFILEINFO *sdfi1, SDCMFILEINFO *sdfi2) +{ static float eps = 0; if (eps == 0) { char *pc; @@ -3762,7 +3840,8 @@ int sdfiSameSlicePos(SDCMFILEINFO *sdfi1, SDCMFILEINFO *sdfi2) { Author: Douglas N. Greve, 7/28/05 -----------------------------------------------------------------------*/ -int sdfiIsSliceOrderReversed(SDCMFILEINFO *sdfi) { +int sdfiIsSliceOrderReversed(SDCMFILEINFO *sdfi) +{ int correv, sagrev, trarev; char *dcmfile, *strtmp; @@ -3839,7 +3918,8 @@ int sdfiIsSliceOrderReversed(SDCMFILEINFO *sdfi) { input: structure DICOMInfo output: prints specific DICOM fields *******************************************************/ -void PrintDICOMInfo(DICOMInfo *dcminfo) { +void PrintDICOMInfo(DICOMInfo *dcminfo) +{ int i; char str[256]; @@ -3851,28 +3931,32 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { printf("Date and time\n"); if (IsTagPresent[DCM_StudyDate]) { sprintf(str, "%s", dcminfo->StudyDate); - } else { + } + else { strcpy(str, "not found"); } printf("\tstudy date\t\t%s\n", str); if (IsTagPresent[DCM_StudyTime]) { sprintf(str, "%s", dcminfo->StudyTime); - } else { + } + else { strcpy(str, "not found"); } printf("\tstudy time\t\t%s\n", str); if (IsTagPresent[DCM_SeriesTime]) { sprintf(str, "%s", dcminfo->SeriesTime); - } else { + } + else { strcpy(str, "not found"); } printf("\tseries time\t\t%s\n", str); if (IsTagPresent[DCM_AcquisitionTime]) { sprintf(str, "%s", dcminfo->AcquisitionTime); - } else { + } + else { strcpy(str, "not found"); } printf("\tacquisition time\t%s\n", str); @@ -3880,14 +3964,16 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { printf("Identification\n"); if (IsTagPresent[DCM_PatientName]) { sprintf(str, "%s", dcminfo->PatientName); - } else { + } + else { strcpy(str, "not found"); } printf("\tpatient name\t\t%s\n", str); if (IsTagPresent[DCM_Manufacturer]) { sprintf(str, "%s", dcminfo->Manufacturer); - } else { + } + else { strcpy(str, "not found"); } printf("\tmanufacturer\t\t%s\n", str); @@ -3895,14 +3981,16 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { printf("Dimensions\n"); if (IsTagPresent[DCM_Rows]) { sprintf(str, "%d", dcminfo->Rows); - } else { + } + else { strcpy(str, "not found"); } printf("\tnumber of rows\t\t%s\n", str); if (IsTagPresent[DCM_Columns]) { sprintf(str, "%d", dcminfo->Columns); - } else { + } + else { strcpy(str, "not found"); } printf("\tnumber of columns\t%s\n", str); @@ -3911,21 +3999,24 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { if (IsTagPresent[DCM_xsize]) { sprintf(str, "%g", dcminfo->xsize); - } else { + } + else { strcpy(str, "not found"); } printf("\tpixel width\t\t%s\n", str); if (IsTagPresent[DCM_ysize]) { sprintf(str, "%g", dcminfo->ysize); - } else { + } + else { strcpy(str, "not found"); } printf("\tpixel height\t\t%s\n", str); if (IsTagPresent[DCM_SliceThickness]) { sprintf(str, "%g", dcminfo->SliceThickness); - } else { + } + else { strcpy(str, "not found"); } printf("\tslice thickness\t\t%s\n", str); @@ -3934,7 +4025,8 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { if (IsTagPresent[DCM_ImageNumber]) { sprintf(str, "%d", dcminfo->ImageNumber); - } else { + } + else { strcpy(str, "not found"); } printf("\timage number\t\t%s (might be not reliable)\n", str); @@ -3946,42 +4038,48 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { printf("Acquisition parameters\n"); if (IsTagPresent[DCM_EchoTime]) { sprintf(str, "%g", dcminfo->EchoTime); - } else { + } + else { strcpy(str, "not found"); } printf("\techo time\t\t%s\n", str); if (IsTagPresent[DCM_RepetitionTime]) { sprintf(str, "%g", dcminfo->RepetitionTime); - } else { + } + else { strcpy(str, "not found"); } printf("\trepetition time\t\t%s\n", str); if (IsTagPresent[DCM_InversionTime]) { sprintf(str, "%g", dcminfo->InversionTime); - } else { + } + else { strcpy(str, "not found"); } printf("\tinversion time\t\t%s\n", str); if (IsTagPresent[DCM_EchoNumber]) { sprintf(str, "%d", dcminfo->EchoNumber); - } else { + } + else { strcpy(str, "not found"); } printf("\techo number\t\t%s\n", str); if (IsTagPresent[DCM_FlipAngle]) { sprintf(str, "%g", dcminfo->FlipAngle); - } else { + } + else { strcpy(str, "not found"); } printf("\tflip angle\t\t%s\n", str); if (IsTagPresent[DCM_BitsAllocated]) { sprintf(str, "%d", dcminfo->BitsAllocated); - } else { + } + else { strcpy(str, "not found"); } printf("\tbits allocated\t\t%s\n", str); @@ -3994,7 +4092,8 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { printf("%g ", dcminfo->FirstImagePosition[i]); } printf("\n"); - } else { + } + else { printf("notfound\n"); } @@ -4004,7 +4103,8 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { printf("%g ", dcminfo->LastImagePosition[i]); } printf("\n"); - } else { + } + else { printf("notfound\n"); } @@ -4014,14 +4114,16 @@ void PrintDICOMInfo(DICOMInfo *dcminfo) { printf("%g ", dcminfo->ImageOrientation[i]); } printf("\n"); - } else { + } + else { printf("notfound\n"); } printf("-------------------------------------------------\n\n"); } -CONDITION GetString(DCM_OBJECT **object, DCM_TAG tag, char **st) { +CONDITION GetString(DCM_OBJECT **object, DCM_TAG tag, char **st) +{ DCM_ELEMENT attribute; CONDITION cond; void *ctx; @@ -4040,7 +4142,8 @@ CONDITION GetString(DCM_OBJECT **object, DCM_TAG tag, char **st) { return cond; } -CONDITION GetUSFromString(DCM_OBJECT **object, DCM_TAG tag, unsigned short *us) { +CONDITION GetUSFromString(DCM_OBJECT **object, DCM_TAG tag, unsigned short *us) +{ DCM_ELEMENT attribute; CONDITION cond; char *s; @@ -4060,7 +4163,8 @@ CONDITION GetUSFromString(DCM_OBJECT **object, DCM_TAG tag, unsigned short *us) return cond; } -CONDITION GetShortFromString(DCM_OBJECT **object, DCM_TAG tag, short *sh) { +CONDITION GetShortFromString(DCM_OBJECT **object, DCM_TAG tag, short *sh) +{ DCM_ELEMENT attribute; CONDITION cond; char *s; @@ -4080,7 +4184,8 @@ CONDITION GetShortFromString(DCM_OBJECT **object, DCM_TAG tag, short *sh) { return cond; } -CONDITION GetUSFromUS(DCM_OBJECT **object, DCM_TAG tag, unsigned short *us) { +CONDITION GetUSFromUS(DCM_OBJECT **object, DCM_TAG tag, unsigned short *us) +{ DCM_ELEMENT attribute; CONDITION cond; void *ctx, *ot; @@ -4099,7 +4204,8 @@ CONDITION GetUSFromUS(DCM_OBJECT **object, DCM_TAG tag, unsigned short *us) { return cond; } -CONDITION GetShortFromShort(DCM_OBJECT **object, DCM_TAG tag, short *ss) { +CONDITION GetShortFromShort(DCM_OBJECT **object, DCM_TAG tag, short *ss) +{ DCM_ELEMENT attribute; CONDITION cond; void *ctx, *ot; @@ -4118,7 +4224,8 @@ CONDITION GetShortFromShort(DCM_OBJECT **object, DCM_TAG tag, short *ss) { return cond; } -CONDITION GetPixelData_Save(DCM_OBJECT **object, DCM_TAG tag, unsigned short **ad) { +CONDITION GetPixelData_Save(DCM_OBJECT **object, DCM_TAG tag, unsigned short **ad) +{ DCM_ELEMENT attribute; CONDITION cond; void *ctx, *ot; @@ -4136,7 +4243,8 @@ CONDITION GetPixelData_Save(DCM_OBJECT **object, DCM_TAG tag, unsigned short **a return cond; } -CONDITION GetPixelData(DCM_OBJECT **object, DCM_TAG tag, void **ad) { +CONDITION GetPixelData(DCM_OBJECT **object, DCM_TAG tag, void **ad) +{ DCM_ELEMENT attribute; CONDITION cond; void *ctx, *ot; @@ -4163,7 +4271,8 @@ CONDITION GetPixelData(DCM_OBJECT **object, DCM_TAG tag, void **ad) { return cond; } -CONDITION GetDoubleFromString(DCM_OBJECT **object, DCM_TAG tag, double *d) { +CONDITION GetDoubleFromString(DCM_OBJECT **object, DCM_TAG tag, double *d) +{ DCM_ELEMENT attribute; CONDITION cond; char *s; @@ -4183,7 +4292,8 @@ CONDITION GetDoubleFromString(DCM_OBJECT **object, DCM_TAG tag, double *d) { return cond; } -CONDITION GetMultiDoubleFromString(DCM_OBJECT **object, DCM_TAG tag, double *d[], int multiplicity) { +CONDITION GetMultiDoubleFromString(DCM_OBJECT **object, DCM_TAG tag, double *d[], int multiplicity) +{ DCM_ELEMENT attribute; CONDITION cond; char *s, *ss; @@ -4218,7 +4328,8 @@ CONDITION GetMultiDoubleFromString(DCM_OBJECT **object, DCM_TAG tag, double *d[] return cond; } -CONDITION GetMultiShortFromString(DCM_OBJECT **object, DCM_TAG tag, short *us[], int multiplicity) { +CONDITION GetMultiShortFromString(DCM_OBJECT **object, DCM_TAG tag, short *us[], int multiplicity) +{ DCM_ELEMENT attribute; CONDITION cond; char *s, *ss; @@ -4261,7 +4372,8 @@ CONDITION GetMultiShortFromString(DCM_OBJECT **object, DCM_TAG tag, short *us[], output: fills in structure DICOMInfo with DICOM meta-header fields *******************************************************/ -CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, int ImageNumber) { +CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, int ImageNumber) +{ DCM_OBJECT **object = (DCM_OBJECT **)calloc(1, sizeof(DCM_OBJECT *)); DCM_TAG tag; CONDITION cond, cond2 = DCM_NORMAL; @@ -4302,7 +4414,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag TransferSystaxUID not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_TransferSyntaxUID] = true; } @@ -4339,7 +4452,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag Manufacturer not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_Manufacturer] = true; } @@ -4353,7 +4467,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag PatientName not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_PatientName] = true; } @@ -4367,7 +4482,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag StudyDate not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_StudyDate] = true; } @@ -4381,7 +4497,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag StudyTime not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_StudyTime] = true; } @@ -4395,7 +4512,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag SeriesTime not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_SeriesTime] = true; } @@ -4409,7 +4527,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag AcquisitionTime not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_AcquisitionTime] = true; } @@ -4429,10 +4548,12 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag Slice Thickness not found\n"); #endif - } else { + } + else { IsTagPresent[DCM_SliceThickness] = true; } - } else { + } + else { IsTagPresent[DCM_SliceThickness] = true; } @@ -4443,7 +4564,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in dcminfo->ImageNumber = ImageNumber; cond2 = cond; printf("WARNING: tag ImageNumber not found in %s\n", fname); - } else { + } + else { IsTagPresent[DCM_ImageNumber] = true; } @@ -4453,7 +4575,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in if (cond != DCM_NORMAL || dcminfo->SeriesNumber == 0) { cond2 = cond; printf("WARNING: tag SeriesNumber not found in %s\n", fname); - } else { + } + else { IsTagPresent[DCM_SeriesNumber] = true; } @@ -4466,7 +4589,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag Rows not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_Rows] = true; } @@ -4479,7 +4603,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag Columns not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_Columns] = true; } @@ -4493,7 +4618,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag Pixel spacing not found in %s\n", fname); #endif - } else { + } + else { dcminfo->xsize = tmp[0]; dcminfo->ysize = tmp[1]; IsTagPresent[DCM_xsize] = true; @@ -4509,7 +4635,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag BitsAllocated not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_BitsAllocated] = true; } @@ -4522,7 +4649,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag RepetitionTime not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_RepetitionTime] = true; } @@ -4535,7 +4663,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag EchoTime not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_EchoTime] = true; } @@ -4555,7 +4684,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag FlipAngle not found in %s\n", fname); #endif - } else { + } + else { dcminfo->FlipAngle = M_PI * dcminfo->FlipAngle / 180.0; IsTagPresent[DCM_FlipAngle] = true; } @@ -4569,7 +4699,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag InversionTime not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_InversionTime] = true; } @@ -4582,7 +4713,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag EchoNumber not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_EchoNumber] = true; } @@ -4599,7 +4731,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in #ifdef _DEBUG printf("WARNING: tag image position not found in %s\n", fname); #endif - } else { + } + else { IsTagPresent[DCM_ImagePosition] = true; for (i = 0; i < 3; i++) { dcminfo->ImagePosition[i] = tmp[i]; @@ -4615,7 +4748,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in } cond2 = cond; printf("WARNING: tag image orientation not found in %s\n", fname); - } else { + } + else { IsTagPresent[DCM_ImageOrientation] = true; for (i = 0; i < 6; i++) { dcminfo->ImageOrientation[i] = tmp[i]; @@ -4641,7 +4775,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in cond = GetString(object, tag, &strtmp); if (cond != DCM_NORMAL) { dcminfo->PhEncDir = NULL; - } else { + } + else { dcminfo->PhEncDir = deblank(strtmp); free(strtmp); } @@ -4668,7 +4803,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in dcminfo->bvecx = xbvec; dcminfo->bvecy = ybvec; dcminfo->bvecz = zbvec; - } else { + } + else { dcminfo->bval = 0; dcminfo->bvecx = 0; dcminfo->bvecy = 0; @@ -4712,7 +4848,8 @@ CONDITION GetDICOMInfo(const char *fname, DICOMInfo *dcminfo, BOOL ReadImage, in informations stored in first array element *******************************************************/ -void *ReadDICOMImage(int nfiles, DICOMInfo **aDicomInfo) { +void *ReadDICOMImage(int nfiles, DICOMInfo **aDicomInfo) +{ int n, i, j, bitsAllocated, numberOfFrames, offset, nvox; DICOMInfo dcminfo; unsigned char *PixelData8, *v8 = NULL; @@ -4771,7 +4908,8 @@ void *ReadDICOMImage(int nfiles, DICOMInfo **aDicomInfo) { v8[offset + j] = PixelData8[j]; if (PixelData8[j] > max8) { max8 = PixelData8[j]; - } else if (PixelData8[j] < min8) { + } + else if (PixelData8[j] < min8) { min8 = PixelData8[j]; } } @@ -4786,7 +4924,8 @@ void *ReadDICOMImage(int nfiles, DICOMInfo **aDicomInfo) { v16[offset + j] = PixelData16[j]; if (PixelData16[j] > max16) { max16 = PixelData16[j]; - } else if (PixelData16[j] < min16) { + } + else if (PixelData16[j] < min16) { min16 = PixelData16[j]; } } @@ -4817,7 +4956,8 @@ void *ReadDICOMImage(int nfiles, DICOMInfo **aDicomInfo) { // ReadDICOMImage2 // /////////////////////////////////////////////////////////////////// -void *ReadDICOMImage2(int nfiles, DICOMInfo **aDicomInfo, int startIndex) { +void *ReadDICOMImage2(int nfiles, DICOMInfo **aDicomInfo, int startIndex) +{ int n, i, j, bitsAllocated, numberOfFrames, offset, nvox; DICOMInfo dcminfo; unsigned char *PixelData8, *v8 = NULL; @@ -4875,7 +5015,8 @@ void *ReadDICOMImage2(int nfiles, DICOMInfo **aDicomInfo, int startIndex) { v8[offset + j] = PixelData8[j]; if (PixelData8[j] > max8) { max8 = PixelData8[j]; - } else if (PixelData8[j] < min8) { + } + else if (PixelData8[j] < min8) { min8 = PixelData8[j]; } } @@ -4891,7 +5032,8 @@ void *ReadDICOMImage2(int nfiles, DICOMInfo **aDicomInfo, int startIndex) { v16[offset + j] = PixelData16[j]; if (PixelData16[j] > max16) { max16 = PixelData16[j]; - } else if (PixelData16[j] < min16) { + } + else if (PixelData16[j] < min16) { min16 = PixelData16[j]; } } @@ -4934,7 +5076,8 @@ void *ReadDICOMImage2(int nfiles, DICOMInfo **aDicomInfo, int startIndex) { *******************************************************/ -void SortFiles(char *fNames[], int nFiles, DICOMInfo ***ptrDicomArray, int *nStudies) { +void SortFiles(char *fNames[], int nFiles, DICOMInfo ***ptrDicomArray, int *nStudies) +{ int n, npermut; BOOL done; @@ -5008,7 +5151,8 @@ void SortFiles(char *fNames[], int nFiles, DICOMInfo ***ptrDicomArray, int *nStu output: true if file is DICOM part 10 (version 3.0) compliant *******************************************************/ -int IsDICOM(const char *fname) { +int IsDICOM(const char *fname) +{ int d; FILE *fp; CONDITION cond; @@ -5024,7 +5168,8 @@ int IsDICOM(const char *fname) { // use the cached value if the fname is the same as privious one if (d == 0 && !strcmp(fname, file)) { return yes; // used before - } else { + } + else { yes = 0; // initialize strcpy(file, fname); // save the current filename } @@ -5111,14 +5256,16 @@ int IsDICOM(const char *fname) { // cache the current value if (cond == DCM_NORMAL) { yes = 1; - } else { + } + else { yes = 0; } return (cond == DCM_NORMAL); } /*---------------------------------------------------------------*/ -static int DCMPrintCond(CONDITION cond) { +static int DCMPrintCond(CONDITION cond) +{ switch (cond) { case DCM_NORMAL: printf("DCM_NORMAL\n"); @@ -5153,7 +5300,8 @@ static int DCMPrintCond(CONDITION cond) { output: array of files listed in directory, and number of files *******************************************************/ -int ScanDir(const char *PathName, char ***FileNames, int *NumberOfFiles) { +int ScanDir(const char *PathName, char ***FileNames, int *NumberOfFiles) +{ char **pfn; struct dirent **NameList; int i, length, pathlength; @@ -5187,7 +5335,8 @@ int ScanDir(const char *PathName, char ***FileNames, int *NumberOfFiles) { int scandir(const char *dir, struct_dirent ***namelist, int (*select)(const struct_dirent *), - int (*compar)(const void *, const void *)) { + int (*compar)(const void *, const void *)) +{ DIR *d; struct_dirent *entry; register int i = 0; @@ -5227,7 +5376,8 @@ int scandir(const char *dir, } #endif #ifndef HAVE_ALPHASORT -int alphasort(const void *a, const void *b) { +int alphasort(const void *a, const void *b) +{ struct_dirent **da = (struct_dirent **)a; struct_dirent **db = (struct_dirent **)b; return (strcmp((*da)->d_name, (*db)->d_name)); @@ -5245,7 +5395,8 @@ int alphasort(const void *a, const void *b) { DICOMRead2() - generic dicom reader. It should be possible to use this for everything but siemens mosaics. --------------------------------------------------------------*/ -MRI *DICOMRead2(const char *dcmfile, int LoadVolume) { +MRI *DICOMRead2(const char *dcmfile, int LoadVolume) +{ char **FileNames, *dcmdir; DICOMInfo RefDCMInfo, TmpDCMInfo, **dcminfo; int nfiles, nframes, nslices, r, c, s, f, err, fid; @@ -5372,7 +5523,8 @@ MRI *DICOMRead2(const char *dcmfile, int LoadVolume) { "WARNING: the number of frames * number of slices is less than\n" "the number of dicom files.\n"); // dont error exit, because we have enough files to complete the deal - } else { + } + else { printf( "ERROR: the number of frames * number of slices does\n" "not equal the number of dicom files.\n"); @@ -5483,7 +5635,8 @@ MRI *DICOMRead2(const char *dcmfile, int LoadVolume) { // Phase Enc Direction if (RefDCMInfo.PhEncDir == NULL) { mri->pedir = strcpyalloc("UNKNOWN"); - } else { + } + else { mri->pedir = strcpyalloc(RefDCMInfo.PhEncDir); str_toupper(mri->pedir); } @@ -5549,7 +5702,8 @@ MRI *DICOMRead2(const char *dcmfile, int LoadVolume) { exit(1); } FileNameUse = tmpfile; - } else { + } + else { IsCompressed = 0; FileNameUse = dcminfo[nthfile]->FileName; } @@ -5611,7 +5765,8 @@ MRI *DICOMRead2(const char *dcmfile, int LoadVolume) { when determining the number of frames and slices (eg, see DCMCountFrames()). ----------------------------------------------------------*/ -int CompareDCMFileInfo(const void *a, const void *b) { +int CompareDCMFileInfo(const void *a, const void *b) +{ DICOMInfo *dcmfi1; DICOMInfo *dcmfi2; int n; @@ -5689,7 +5844,8 @@ int CompareDCMFileInfo(const void *a, const void *b) { } /*-----------------------------------------------------------*/ -int SortDCMFileInfo(DICOMInfo **dcmfi_list, int nlist) { +int SortDCMFileInfo(DICOMInfo **dcmfi_list, int nlist) +{ qsort(dcmfi_list, nlist, sizeof(DICOMInfo **), CompareDCMFileInfo); return (0); } @@ -5702,7 +5858,8 @@ int SortDCMFileInfo(DICOMInfo **dcmfi_list, int nlist) { the slice position changes from that of the first file. The number of slices is then the number of files/nframes. -----------------------------------------------------------*/ -int DCMCountFrames(DICOMInfo **dcmfi_list, int nlist) { +int DCMCountFrames(DICOMInfo **dcmfi_list, int nlist) +{ // Assumes they have been sorted int nframes, nth, c, stop; double ImgPos0[3], d[3]; @@ -5738,7 +5895,8 @@ int DCMCountFrames(DICOMInfo **dcmfi_list, int nlist) { in the dicom series will sort to the first slice in the volume. For EPI, this is important for slice timing correction. -----------------------------------------------------------*/ -int DCMSliceDir(DICOMInfo **dcmfi_list, int nlist) { +int DCMSliceDir(DICOMInfo **dcmfi_list, int nlist) +{ // Assumes they have been sorted int nth, c, stop; double ImgPos0[3], d[3], dlength; @@ -5823,7 +5981,8 @@ int DCMSliceDir(DICOMInfo **dcmfi_list, int nlist) { output: array of file names that are DICOM 3.0 compliant *******************************************************/ -int CleanFileNames(char **FileNames, int NumberOfDICOMFiles, char ***CleanedFileNames) { +int CleanFileNames(char **FileNames, int NumberOfDICOMFiles, char ***CleanedFileNames) +{ char **pfn; int i, j, length; @@ -5845,7 +6004,8 @@ int CleanFileNames(char **FileNames, int NumberOfDICOMFiles, char ***CleanedFile /* kteich - renamed this to myRound because round() was causing versioning problems */ -int myRound(double d) { +int myRound(double d) +{ double c, f, ddown, dup; c = ceil(d); @@ -5854,7 +6014,8 @@ int myRound(double d) { dup = c - d; if (ddown < dup) { return (int)f; - } else { + } + else { return (int)c; } } @@ -5868,7 +6029,8 @@ int myRound(double d) { called-by: DICOMInfo2MRI *******************************************************/ -void DebugPrint(FILE *fp, const char *msg, ...) { +void DebugPrint(FILE *fp, const char *msg, ...) +{ #ifndef __OPTIMIZE va_list ap; va_start(ap, msg); @@ -6008,7 +6170,8 @@ and finally c_ras = center = T3x3 * n/2 if (i < 2) // convert LP to RA { s[i] = dcm->FirstImagePosition[i] - dcm->LastImagePosition[i]; - } else // S stays the same + } + else // S stays the same { s[i] = dcm->LastImagePosition[i] - dcm->FirstImagePosition[i]; } @@ -6018,7 +6181,8 @@ and finally c_ras = center = T3x3 * n/2 for (i = 0; i < 3; i++) { s[i] /= rms; } - } else { + } + else { // build s[i] from c[i] and r[i] // there is an ambiguity in sign due to left-handed // or right-handed coords @@ -6101,7 +6265,8 @@ and finally c_ras = center = T3x3 * n/2 input: array of 16-bit pixels, number of elements output: array of 8-bit pixels *******************************************************/ -unsigned char *DICOM16To8(unsigned short *v16, int nvox) { +unsigned char *DICOM16To8(unsigned short *v16, int nvox) +{ unsigned char *v8; int i; double min16, max16, min8, max8, ratio; @@ -6139,7 +6304,8 @@ unsigned char *DICOM16To8(unsigned short *v16, int nvox) { output: fill in MRI structure, including the image *******************************************************/ -int DICOMInfo2MRI(DICOMInfo *dcm, void *data, MRI *mri) { +int DICOMInfo2MRI(DICOMInfo *dcm, void *data, MRI *mri) +{ long n; int i, j, k; unsigned char *data8; @@ -6205,7 +6371,8 @@ int DICOMInfo2MRI(DICOMInfo *dcm, void *data, MRI *mri) { This routine is used for non-Siemens DICOM files *******************************************************/ -int DICOMRead(const char *FileName, MRI **mri, int ReadImage) { +int DICOMRead(const char *FileName, MRI **mri, int ReadImage) +{ MRI *pmri = NULL; char **CleanedFileNames, **FileNames, *c, PathName[256]; int i, NumberOfFiles, NumberOfDICOMFiles, nStudies, error; @@ -6228,7 +6395,8 @@ int DICOMRead(const char *FileName, MRI **mri, int ReadImage) { c = strrchr(FileName, '/'); if (c == NULL) { PathName[0] = '\0'; - } else { + } + else { length = (int)(c - FileName); strncpy(PathName, FileName, length); PathName[length] = '/'; @@ -6255,7 +6423,8 @@ int DICOMRead(const char *FileName, MRI **mri, int ReadImage) { if (NumberOfDICOMFiles == 0) { fprintf(stderr, "no DICOM files found. Exit\n"); exit(1); - } else { + } + else { printf("%d DICOM 3.0 files in list\n", NumberOfDICOMFiles); } @@ -6282,7 +6451,8 @@ int DICOMRead(const char *FileName, MRI **mri, int ReadImage) { fp = fopen("dicom.log", "w"); if (fp == NULL) { printf("Can not create file dicom.log\n"); - } else { + } + else { printf("Starting filenames for the studies\n"); for (i = 0; i < NumberOfDICOMFiles; i++) { fprintf(fp, "%s\t%d\n", aDicomInfo[i]->FileName, aDicomInfo[i]->ImageNumber); @@ -6326,7 +6496,8 @@ int DICOMRead(const char *FileName, MRI **mri, int ReadImage) { } free((void *)startIndices); - } else // only 1 studies + } + else // only 1 studies { nextIndex = inputIndex + NumberOfDICOMFiles; } @@ -6416,7 +6587,8 @@ int DICOMRead(const char *FileName, MRI **mri, int ReadImage) { the bvalues and bvects, then zero is still returned but bvals and bvecs are set to 0. */ -int dcmGetDWIParams(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) { +int dcmGetDWIParams(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) +{ DCM_ELEMENT *e; CONDITION cond; DCM_TAG tag; @@ -6449,16 +6621,19 @@ int dcmGetDWIParams(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybv if (Gdiag_no > 0) printf("Attempting to get DWI Parameters from Siemens DICOM\n"); err = dcmGetDWIParamsSiemens(dcm, pbval, pxbvec, pybvec, pzbvec); if (err) return (err); - } else if (strcmp(e->d.string, "GE MEDICAL SYSTEMS") == 0) { + } + else if (strcmp(e->d.string, "GE MEDICAL SYSTEMS") == 0) { if (Gdiag_no > 0) printf("Attempting to get DWI Parameters from GE DICOM\n"); err = dcmGetDWIParamsGE(dcm, pbval, pxbvec, pybvec, pzbvec); if (err) return (err); - } else if (strcmp(e->d.string, "Philips Medical Systems ") == 0) { + } + else if (strcmp(e->d.string, "Philips Medical Systems ") == 0) { // Note: need space at the end of 'Systems' above if (Gdiag_no > 0) printf("Attempting to get DWI Parameters from Phlips DICOM\n"); err = dcmGetDWIParamsPhilips(dcm, pbval, pxbvec, pybvec, pzbvec); if (err) return (err); - } else { + } + else { printf("ERROR: don't know how to get DWI parameters from --%s--\n", e->d.string); fflush(stdout); return (1); @@ -6483,7 +6658,8 @@ int dcmGetDWIParams(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybv return (0); } -int dcmGetDWIParamsPhilips(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) { +int dcmGetDWIParamsPhilips(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) +{ DCM_ELEMENT *e; CONDITION cond; DCM_TAG tag; @@ -6555,7 +6731,8 @@ int dcmGetDWIParamsPhilips(DCM_OBJECT *dcm, double *pbval, double *pxbvec, doubl voxel space already. However, gradients are converted to RAS. Returns 0 if no error. */ -int dcmGetDWIParamsGE(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) { +int dcmGetDWIParamsGE(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) +{ DCM_ELEMENT *e; CONDITION cond; DCM_TAG tag; @@ -6664,7 +6841,8 @@ int dcmGetDWIParamsGE(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *py exists, then gets bvec from 0x100e. If not, then uses an alternative method. Returns 0 if everything ok. Gradients transformed to RAS. */ -int dcmGetDWIParamsSiemens(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) { +int dcmGetDWIParamsSiemens(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) +{ DCM_ELEMENT *e; CONDITION cond; DCM_TAG tag; @@ -6691,7 +6869,8 @@ int dcmGetDWIParamsSiemens(DCM_OBJECT *dcm, double *pbval, double *pxbvec, doubl if (Gdiag_no > 0) printf(" bval 0x19,0x100c does not exist, try alternative method\n"); err = dcmGetDWIParamsSiemensAlt(dcm, pbval, pxbvec, pybvec, pzbvec); if (err) return (err); - } else { + } + else { // The bvalue tag does exist, get gradients if (Gdiag_no > 0) printf(" bval 0x19,0x100c does exist, getting gradients\n"); AllocElementData(e); @@ -6785,7 +6964,8 @@ int dcmGetDWIParamsSiemens(DCM_OBJECT *dcm, double *pbval, double *pxbvec, doubl the sequence was not diffusion weighted. This makes it hard to do error checking. */ -int dcmGetDWIParamsSiemensAlt(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) { +int dcmGetDWIParamsSiemensAlt(DCM_OBJECT *dcm, double *pbval, double *pxbvec, double *pybvec, double *pzbvec) +{ DCM_ELEMENT *e; CONDITION cond; DCM_TAG tag; @@ -6921,8 +7101,8 @@ int dcmGetDWIParamsSiemensAlt(DCM_OBJECT *dcm, double *pbval, double *pxbvec, do Differs from dcmImageDirCos() in that it uses an object instead of opening a file. Returns 1 if error, 0 otherwise. */ -int dcmImageDirCosObject( - DCM_OBJECT *dcm, double *Vcx, double *Vcy, double *Vcz, double *Vrx, double *Vry, double *Vrz) { +int dcmImageDirCosObject(DCM_OBJECT *dcm, double *Vcx, double *Vcy, double *Vcz, double *Vrx, double *Vry, double *Vrz) +{ DCM_ELEMENT *e; CONDITION cond; DCM_TAG tag; @@ -6987,7 +7167,8 @@ int dcmImageDirCosObject( will be arbitrary. */ MATRIX *ImageDirCos2Slice( - double Vcx, double Vcy, double Vcz, double Vrx, double Vry, double Vrz, double *Vsx, double *Vsy, double *Vsz) { + double Vcx, double Vcy, double Vcz, double Vrx, double Vry, double Vrz, double *Vsx, double *Vsy, double *Vsz) +{ VECTOR *Vc, *Vr, *Vs; MATRIX *Mdc; diff --git a/utils/MARS_DT_Boundary.c b/utils/MARS_DT_Boundary.c index 2c14a842d94..7a8bebfc8bb 100644 --- a/utils/MARS_DT_Boundary.c +++ b/utils/MARS_DT_Boundary.c @@ -26,7 +26,8 @@ final_cost: array of size N of type double. MARS_DT_Boundary will save the outp NOTE: vertNbors is 1-based arrays are 1-based!! */ -void MARS_DT_Boundary(int *sv, int numVerts, int maxNeighbors, int *vertNbors, double *costNbors, double *final_cost) { +void MARS_DT_Boundary(int *sv, int numVerts, int maxNeighbors, int *vertNbors, double *costNbors, double *final_cost) +{ MIN_HEAP *MH; int *prev_neighbor, neighbor; int i, result, heap_size; diff --git a/utils/MRIio_old.c b/utils/MRIio_old.c index ad72052aad7..f7afa7a674a 100644 --- a/utils/MRIio_old.c +++ b/utils/MRIio_old.c @@ -37,12 +37,14 @@ static void MGHprint_error(char *str); -static void MGHprint_error(char *str) { +static void MGHprint_error(char *str) +{ printf("%s", str); exit(0); } -char *lmalloc(unsigned long size) { +char *lmalloc(unsigned long size) +{ char *p; p = malloc(size); @@ -50,7 +52,8 @@ char *lmalloc(unsigned long size) { return p; } -char *lcalloc(size_t nmemb, size_t size) { +char *lcalloc(size_t nmemb, size_t size) +{ char *p; p = calloc(nmemb, size); @@ -58,7 +61,8 @@ char *lcalloc(size_t nmemb, size_t size) { return p; } -void file_name(char *fpref, char *fname, int num, char *form) { +void file_name(char *fpref, char *fname, int num, char *form) +{ char ext[10]; sprintf(ext, form, num); @@ -66,7 +70,8 @@ void file_name(char *fpref, char *fname, int num, char *form) { strcat(fname, ext); } -void buffer_to_image(unsigned char *buf, unsigned char **im, int ysize, int xsize) { +void buffer_to_image(unsigned char *buf, unsigned char **im, int ysize, int xsize) +{ int i, j; unsigned long k; float sum; @@ -83,7 +88,8 @@ void buffer_to_image(unsigned char *buf, unsigned char **im, int ysize, int xsiz */ } -void image_to_buffer(unsigned char **im, unsigned char *buf, int ysize, int xsize) { +void image_to_buffer(unsigned char **im, unsigned char *buf, int ysize, int xsize) +{ int i, j; unsigned long k; diff --git a/utils/afni.c b/utils/afni.c index ced7a212f88..f4a7b5473b0 100644 --- a/utils/afni.c +++ b/utils/afni.c @@ -65,7 +65,8 @@ extern void swab(const void *from, void *to, size_t n); static float afni_orientations[][3] = { {-1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}}; -void AFinit(AF *pAF) { +void AFinit(AF *pAF) +{ pAF->dataset_rank[0] = 0; pAF->dataset_rank[1] = 0; pAF->dataset_dimensions[0] = 0; @@ -94,14 +95,16 @@ void AFinit(AF *pAF) { pAF->brick_float_facs = 0; } -void AFclean(AF *pAF) { +void AFclean(AF *pAF) +{ if (pAF->numchars) free(pAF->idcode_string); if (pAF->numstats) free(pAF->brick_stats); if (pAF->numtypes) free(pAF->brick_types); if (pAF->numfacs) free(pAF->brick_float_facs); } -void printAFNIHeader(AF *pAF) { +void printAFNIHeader(AF *pAF) +{ char types[][8] = {"byte", "short", "float", "complex"}; int i; @@ -127,7 +130,8 @@ void printAFNIHeader(AF *pAF) { printf("====================================================================\n"); } -static int *get_afni_int(FILE *fp, int count, char *name) { +static int *get_afni_int(FILE *fp, int count, char *name) +{ int *buf = NULL; int i; char line[STRLEN]; @@ -177,7 +181,8 @@ static int *get_afni_int(FILE *fp, int count, char *name) { } /* end get_afni_int() */ -static float *get_afni_float(FILE *fp, int count, char *name) { +static float *get_afni_float(FILE *fp, int count, char *name) +{ float *buf = NULL; int i; char line[STRLEN]; @@ -229,7 +234,8 @@ static float *get_afni_float(FILE *fp, int count, char *name) { } /* end get_afni_float() */ -static char *get_afni_string(FILE *fp, int count, char *name) { +static char *get_afni_string(FILE *fp, int count, char *name) +{ char *buf; int i; char c; @@ -272,7 +278,8 @@ static char *get_afni_string(FILE *fp, int count, char *name) { } /* end get_afni_string() */ -int readAFNIHeader(FILE *fp, AF *pAF) { +int readAFNIHeader(FILE *fp, AF *pAF) +{ char line[STRLEN], line2[STRLEN]; int i, j; char type[STRLEN], name[STRLEN]; @@ -318,13 +325,16 @@ int readAFNIHeader(FILE *fp, AF *pAF) { if (strncmp(type, "string-attribute", 16) == 0) { s = get_afni_string(fp, count, name); if (s == 0) return (0); - } else if (strncmp(type, "float-attribute", 15) == 0) { + } + else if (strncmp(type, "float-attribute", 15) == 0) { f = get_afni_float(fp, count, name); if (f == 0) return (0); - } else if (strncmp(type, "integer-attribute", 17) == 0) { + } + else if (strncmp(type, "integer-attribute", 17) == 0) { ip = get_afni_int(fp, count, name); if (ip == 0) return (0); - } else { + } + else { errno = 0; ErrorReturn(0, (ERROR_BADPARM, "read_afni_header(): unknown type %s", type)); } @@ -333,7 +343,8 @@ int readAFNIHeader(FILE *fp, AF *pAF) { if (strcmp(name, "DATASET_RANK") == 0) { pAF->dataset_rank[0] = ip[0]; pAF->dataset_rank[1] = ip[1]; - } else if (strcmp(name, "DATASET_DIMENSIONS") == 0) { + } + else if (strcmp(name, "DATASET_DIMENSIONS") == 0) { // check errors for getting non-integer if (strncmp(type, "integer-attribute", 17) != 0) { errno = 0; @@ -354,13 +365,16 @@ int readAFNIHeader(FILE *fp, AF *pAF) { pAF->dataset_dimensions[2] = ip[2]; // mark got the info on dimension gotten = gotten | DATASET_DIMENSIONS_FLAG; - } else if (strcmp(name, "TYPESTRING") == 0) { + } + else if (strcmp(name, "TYPESTRING") == 0) { strcpy(pAF->typestring, s); // s is src - } else if (strcmp(name, "SCENE_DATA") == 0) { + } + else if (strcmp(name, "SCENE_DATA") == 0) { pAF->scene_data[0] = ip[0]; pAF->scene_data[1] = ip[1]; pAF->scene_data[2] = ip[2]; - } else if (strcmp(name, "ORIENT_SPECIFIC") == 0) { + } + else if (strcmp(name, "ORIENT_SPECIFIC") == 0) { // error check to make sure 3 integers if (strncmp(type, "integer-attribute", 17) != 0) { errno = 0; @@ -391,7 +405,8 @@ int readAFNIHeader(FILE *fp, AF *pAF) { pAF->orient_specific[2] = ip[2]; gotten = gotten | ORIENT_SPECIFIC_FLAG; - } else if (strcmp(name, "ORIGIN") == 0) { + } + else if (strcmp(name, "ORIGIN") == 0) { if (count < 3) { errno = 0; ErrorReturn( @@ -410,7 +425,8 @@ int readAFNIHeader(FILE *fp, AF *pAF) { pAF->origin[2] = f[2]; gotten = gotten | ORIGIN_FLAG; - } else if (strcmp(name, "DELTA") == 0) { + } + else if (strcmp(name, "DELTA") == 0) { if (strncmp(type, "float-attribute", 15) != 0) { errno = 0; ErrorReturn(0, @@ -435,7 +451,8 @@ int readAFNIHeader(FILE *fp, AF *pAF) { else if (strcmp(name, "IDCODE_STRING") == 0) { pAF->idcode_string = (char *)malloc(sizeof(char) * count); strcpy(pAF->idcode_string, s); - } else if (strcmp(name, "BYTEORDER_STRING") == 0) { + } + else if (strcmp(name, "BYTEORDER_STRING") == 0) { if (strncmp(type, "string-attribute", 16) != 0) { errno = 0; ErrorReturn(0, @@ -446,11 +463,13 @@ int readAFNIHeader(FILE *fp, AF *pAF) { } strcpy(pAF->byteorder_string, s); gotten = gotten | BYTEORDER_STRING_FLAG; - } else if (strcmp(name, "BRICK_STATS") == 0) { + } + else if (strcmp(name, "BRICK_STATS") == 0) { pAF->numstats = count; pAF->brick_stats = (float *)malloc(sizeof(float) * count); for (i = 0; i < count; ++i) pAF->brick_stats[i] = f[i]; - } else if (strcmp(name, "BRICK_TYPES") == 0) { + } + else if (strcmp(name, "BRICK_TYPES") == 0) { pAF->numtypes = count; pAF->brick_types = (int *)malloc(sizeof(int) * count); for (i = 0; i < count; ++i) pAF->brick_types[i] = ip[i]; @@ -469,7 +488,8 @@ int readAFNIHeader(FILE *fp, AF *pAF) { pAF->numfacs = count; pAF->brick_float_facs = (float *)malloc(sizeof(float) * count); for (i = 0; i < count; ++i) pAF->brick_float_facs[i] = f[i]; - } else /* ignore unknown variables */ + } + else /* ignore unknown variables */ { } @@ -498,7 +518,8 @@ int readAFNIHeader(FILE *fp, AF *pAF) { } // before calling this function initialize sM -int findMinMaxByte(unsigned char *pS, size_t count, float *fMin, float *fMax) { +int findMinMaxByte(unsigned char *pS, size_t count, float *fMin, float *fMax) +{ size_t i; float fv; // initialize to the first element @@ -514,7 +535,8 @@ int findMinMaxByte(unsigned char *pS, size_t count, float *fMin, float *fMax) { return 0; } -int findMinMaxShort(short *pS, size_t count, float *fMin, float *fMax) { +int findMinMaxShort(short *pS, size_t count, float *fMin, float *fMax) +{ size_t i; float fv; // initialize to the first element @@ -530,7 +552,8 @@ int findMinMaxShort(short *pS, size_t count, float *fMin, float *fMax) { return 0; } -int findMinMaxFloat(float *pF, size_t count, float *fMin, float *fMax) { +int findMinMaxFloat(float *pF, size_t count, float *fMin, float *fMax) +{ size_t i; // initialize to the first element float fmin = *pF; @@ -545,7 +568,8 @@ int findMinMaxFloat(float *pF, size_t count, float *fMin, float *fMax) { } /*------------------------------------------------------*/ -MRI *afniRead(const char *fname, int read_volume) { +MRI *afniRead(const char *fname, int read_volume) +{ FILE *fp; char header_fname[STRLEN]; char *c; @@ -761,7 +785,8 @@ MRI *afniRead(const char *fname, int read_volume) { if (af.numfacs != 0 && af.brick_float_facs[0] != 0.) { header->type = MRI_FLOAT; scaling = af.brick_float_facs[0]; - } else { + } + else { if (bytes_per_voxel == 1) header->type = MRI_UCHAR; else if (bytes_per_voxel == 2) @@ -805,7 +830,8 @@ MRI *afniRead(const char *fname, int read_volume) { if (bytes_per_voxel == 2) // short { swab(pmem, pmem, mri->width * 2); - } else if (bytes_per_voxel == 4) // float + } + else if (bytes_per_voxel == 4) // float { pf = (float *)pmem; for (i = 0; i < mri->width; i++, pf++) *pf = swapFloat(*pf); @@ -837,7 +863,8 @@ MRI *afniRead(const char *fname, int read_volume) { ++ps; } findMinMaxShort((short *)pmem, mri->width, &flMin, &flMax); - } else if (bytes_per_voxel == 4) // float + } + else if (bytes_per_voxel == 4) // float { pf = (float *)pmem; for (i = 0; i < mri->width; i++) { @@ -852,12 +879,14 @@ MRI *afniRead(const char *fname, int read_volume) { fMin = flMin; fMax = flMax; initialized = 1; - } else { + } + else { if (flMin < fMin) fMin = flMin; if (flMax > fMax) fMax = flMax; // printf("\n fmin =%f, fmax = %f, local min = %f, max = %f\n", fMin, fMax, flMin, flMax); } - } else { + } + else { fclose(fp); MRIfree(&header); errno = 0; @@ -872,8 +901,9 @@ MRI *afniRead(const char *fname, int read_volume) { printf("BRICK_STATS min = %f <--> actual min = %f\n", af.brick_stats[0 + 2 * frame], fMin * scaling); printf("BRICK_STATS max = %f <--> actual max = %f\n", af.brick_stats[1 + 2 * frame], fMax * scaling); } - } // nframes - } else // not reading volume + } // nframes + } + else // not reading volume mri = MRIcopy(header, NULL); strcpy(mri->fname, fname); @@ -887,7 +917,8 @@ MRI *afniRead(const char *fname, int read_volume) { } /* end afniRead() */ -int afniWrite(MRI *mri, const char *fname) { +int afniWrite(MRI *mri, const char *fname) +{ char header_fname[STRLEN]; FILE *fp; int i, j, k; @@ -945,7 +976,8 @@ int afniWrite(MRI *mri, const char *fname) { dest_type = MRI_SHORT; else dest_type = MRI_FLOAT; - } else if (mri->type == MRI_UCHAR) + } + else if (mri->type == MRI_UCHAR) bytes_per_voxel = 1; else if (mri->type == MRI_SHORT) bytes_per_voxel = 2; diff --git a/utils/annotation.c b/utils/annotation.c index 245c16ddd88..2f7b6f453f6 100644 --- a/utils/annotation.c +++ b/utils/annotation.c @@ -41,7 +41,8 @@ #include "annotation.h" #undef ANNOTATION_SRC -typedef struct { +typedef struct +{ int index; int r, g, b; int annotation; @@ -52,7 +53,8 @@ static ATABLE_ELT *atable; static int num_entries = 0; /*-----------------------------------------------*/ -int print_annotation_table(FILE *fp) { +int print_annotation_table(FILE *fp) +{ int n; if (num_entries <= 0) { read_annotation_table(); @@ -65,7 +67,8 @@ int print_annotation_table(FILE *fp) { } /*-----------------------------------------------*/ -int print_annotation_colortable(FILE *fp) { +int print_annotation_colortable(FILE *fp) +{ int n; if (num_entries <= 0) { read_annotation_table(); @@ -77,7 +80,8 @@ int print_annotation_colortable(FILE *fp) { return (0); } -int read_named_annotation_table(char *name) { +int read_named_annotation_table(char *name) +{ FILE *fp; char *cp, fname[STRLEN], line[STRLEN]; int i; @@ -94,7 +98,8 @@ int read_named_annotation_table(char *name) { cp = "."; } sprintf(fname, "%s/%s", cp, name); - } else { + } + else { cp = ""; /* use path in name */ sprintf(fname, "%s", name); } @@ -129,7 +134,8 @@ int read_named_annotation_table(char *name) { } /*-----------------------------------------------*/ -int read_annotation_table(void) { +int read_annotation_table(void) +{ FILE *fp; char *cp, fname[STRLEN], line[STRLEN]; int i; @@ -146,7 +152,8 @@ int read_annotation_table(void) { if (annotation_table_file == NULL) { sprintf(fname, "%s/Simple_surface_labels2009.txt", cp); - } else { + } + else { sprintf(fname, "%s", annotation_table_file); } @@ -178,7 +185,8 @@ int read_annotation_table(void) { } return (NO_ERROR); } -int annotation_to_index(int annotation) { +int annotation_to_index(int annotation) +{ int i; if (num_entries <= 0) { @@ -194,7 +202,8 @@ int annotation_to_index(int annotation) { return (-1); } -char *index_to_name(int index) { +char *index_to_name(int index) +{ int i; if (num_entries <= 0) { @@ -217,7 +226,8 @@ char *index_to_name(int index) { return ("NOT_FOUND"); } -int index_to_annotation(int index) { +int index_to_annotation(int index) +{ int i; if (num_entries <= 0) { @@ -233,7 +243,8 @@ int index_to_annotation(int index) { return (-1); } -char *annotation_to_name(int annotation, int *pindex) { +char *annotation_to_name(int annotation, int *pindex) +{ int i; if (num_entries <= 0) { @@ -268,7 +279,8 @@ char *annotation_to_name(int annotation, int *pindex) { given the index of the annotation in the color table. If no vertices with the index can be found, returns NULL. ------------------------------------------------------------*/ -LABEL *annotation2label(int annotid, MRIS *Surf) { +LABEL *annotation2label(int annotid, MRIS *Surf) +{ int npoints, vtxno, annot, vtxannotid; VERTEX *vtx; LABEL *label; @@ -281,7 +293,8 @@ LABEL *annotation2label(int annotid, MRIS *Surf) { // Given this annotation, find its index in the ctab if (Surf->ct) { CTABfindAnnotation(Surf->ct, annot, &vtxannotid); - } else { + } + else { vtxannotid = annotation_to_index(annot); } if (vtxannotid == annotid) { @@ -303,7 +316,8 @@ LABEL *annotation2label(int annotid, MRIS *Surf) { annot = Surf->vertices[vtxno].annotation; if (Surf->ct) { CTABfindAnnotation(Surf->ct, annot, &vtxannotid); - } else { + } + else { vtxannotid = annotation_to_index(annot); } if (vtxannotid == annotid) { @@ -317,7 +331,8 @@ LABEL *annotation2label(int annotid, MRIS *Surf) { return (label); } -int set_atable_from_ctable(COLOR_TABLE *pct) { +int set_atable_from_ctable(COLOR_TABLE *pct) +{ CTE *cte; int i; @@ -349,7 +364,8 @@ int set_atable_from_ctable(COLOR_TABLE *pct) { return (NO_ERROR); } -int MRISdivideAnnotation(MRI_SURFACE *mris, int *nunits) { +int MRISdivideAnnotation(MRI_SURFACE *mris, int *nunits) +{ int *done, vno, index, nadded, i, num, j, annot, new_annot; VERTEX *v; COLOR_TABLE *ct; @@ -434,7 +450,8 @@ int MRISdivideAnnotation(MRI_SURFACE *mris, int *nunits) { } v->annotation = new_annot; } - } else { + } + else { offset++; found = 0; } @@ -457,7 +474,8 @@ int MRISdivideAnnotation(MRI_SURFACE *mris, int *nunits) { return the # of additional parcellation units that have been added */ -int MRISdivideAnnotationUnit(MRI_SURFACE *mris, int annot, int nunits) { +int MRISdivideAnnotationUnit(MRI_SURFACE *mris, int annot, int nunits) +{ int vno, num, min_vno; VERTEX *v, *vc; float cx, cy, cz, dist, min_dist, evalues[3], u, w, dx, dy, dz, min_dot, max_dot, e1x, e1y, e1z, dot; @@ -607,7 +625,8 @@ int MRISdivideAnnotationUnit(MRI_SURFACE *mris, int annot, int nunits) { parcnames[1] = "rostralmiddlefrontal"; MRISmergeAnnotations(surf, 2, parcnames, "frontal"); */ -int MRISmergeAnnotations(MRIS *mris, int nparcs, char **parcnames, char *newparcname) { +int MRISmergeAnnotations(MRIS *mris, int nparcs, char **parcnames, char *newparcname) +{ int err, nthparc, parcid, nnewparcs, nthnewparc, m, match; int vtxno, *annotlist; COLOR_TABLE *ct; @@ -690,7 +709,8 @@ int MRISmergeAnnotations(MRIS *mris, int nparcs, char **parcnames, char *newparc the color table, it is given a value equal to the base (assumes base is "unknown"). */ -MRI *MRISannot2seg(MRIS *surf, int base) { +MRI *MRISannot2seg(MRIS *surf, int base) +{ int k, annot, annotid; MRI *seg; @@ -700,7 +720,8 @@ MRI *MRISannot2seg(MRIS *surf, int base) { annot = surf->vertices[k].annotation; if (surf->ct) { CTABfindAnnotation(surf->ct, annot, &annotid); - } else { + } + else { annotid = annotation_to_index(annot); } if (annotid == -1) { @@ -716,7 +737,8 @@ MRI *MRISannot2seg(MRIS *surf, int base) { Creates a binary overlay that is 1 for vertices as the border of parcellations and 0 everywhere else. */ -MRI *MRISannot2border(MRIS *surf) { +MRI *MRISannot2border(MRIS *surf) +{ int k, annot, nnbrs, nthnbr, knbr, nbrannot, isborder; MRI *border; @@ -747,7 +769,8 @@ MRI *MRISannot2border(MRIS *surf) { Lobar division type can be specified by the 'a_lobeDivisionType' -- see 'mris_annotation2Label.c' for the enumerated types. */ -int MRISaparc2lobes(MRIS *surf, int a_lobeDivisionType) { +int MRISaparc2lobes(MRIS *surf, int a_lobeDivisionType) +{ int parcCount = 0; char *parcnames[64]; @@ -846,7 +869,8 @@ int MRISaparc2lobes(MRIS *surf, int a_lobeDivisionType) { by dividing some aparcs or other geometric manipulations. Based on conversations with Jim Fallon. -----------------------------------------------------------------*/ -int MRISfbirnAnnot(MRIS *surf) { +int MRISfbirnAnnot(MRIS *surf) +{ int *nunits; int area32p, area32v, superiorfrontal, medialorbitofrontal; int rostralanteriorcingulate, rostralmiddlefrontal; @@ -924,7 +948,8 @@ int MRISfbirnAnnot(MRIS *surf) { loaded. *nsegs returns the number of parcellations. **segidlist is a list of the parcellation id numbers (usually just 0 to nsegs-1. */ -double *MRISannotDice(MRIS *surf1, MRIS *surf2, int *nsegs, int **segidlist) { +double *MRISannotDice(MRIS *surf1, MRIS *surf2, int *nsegs, int **segidlist) +{ MRI *seg1, *seg2; int k, id1, id2, k1 = 0, k2 = 0, vtxno; int nsegid1, *segidlist1; diff --git a/utils/art1.c b/utils/art1.c index c5a313c22d3..703d6e354b5 100644 --- a/utils/art1.c +++ b/utils/art1.c @@ -122,7 +122,8 @@ void artFastLearn(ART1 *art1, int j); Returns: ----------------------------------------------------------------------*/ -ART1 *Art1Alloc(int ninputs, int max_f2, double rho) { +ART1 *Art1Alloc(int ninputs, int max_f2, double rho) +{ ART1 *art1; art1 = (ART1 *)InsCalloc(1, sizeof(ART1)); @@ -150,7 +151,8 @@ ART1 *Art1Alloc(int ninputs, int max_f2, double rho) { Returns: ----------------------------------------------------------------------*/ -ART1 *Art1Read(char *fname) { +ART1 *Art1Read(char *fname) +{ ART1 *art1; int ninputs, noutputs, max_f2, i, j; double zj, rho, beta; @@ -186,7 +188,8 @@ ART1 *Art1Read(char *fname) { Returns: ----------------------------------------------------------------------*/ -int Art1Write(ART1 *art1, char *fname) { +int Art1Write(ART1 *art1, char *fname) +{ FILE *fp; int i, j; double zj; @@ -213,7 +216,8 @@ int Art1Write(ART1 *art1, char *fname) { Returns: ----------------------------------------------------------------------*/ -int Art1Free(ART1 **art1) { +int Art1Free(ART1 **art1) +{ InsFree((*art1)->scratch); InsFree((*art1)->f0); InsFree((*art1)->f1); @@ -231,7 +235,8 @@ int Art1Free(ART1 **art1) { Returns: ----------------------------------------------------------------------*/ -int Art1Process(ART1 *art1, double *I) { +int Art1Process(ART1 *art1, double *I) +{ // int nclass; int i, class; @@ -254,7 +259,8 @@ int Art1Process(ART1 *art1, double *I) { /* find the closest feed-forward match and force it's use */ for (i = 0; i < art1->noutputs; i++) art1->flags[i] &= ~ART1_RESET; class = artFeedForward(art1); - } else /* allocate new f2 node for this category */ + } + else /* allocate new f2 node for this category */ { class = art1->class = art1->noutputs++; art1->flags[class] = ART1_COMMITTED; @@ -273,7 +279,8 @@ int Art1Process(ART1 *art1, double *I) { Returns: ----------------------------------------------------------------------*/ -void artInitWeights(ART1 *art1) { +void artInitWeights(ART1 *art1) +{ int i, j; double *zj; @@ -299,7 +306,8 @@ void artInitWeights(ART1 *art1) { Returns: ----------------------------------------------------------------------*/ -int artFeedBack(ART1 *art1, int class) { +int artFeedBack(ART1 *art1, int class) +{ int j, ninputs; double match, norm_I_int_zj, norm_I; @@ -328,7 +336,8 @@ int artFeedBack(ART1 *art1, int class) { { art1->flags[j] |= ART1_RESET; return (0); - } else + } + else return (1); /* resonance */ } /*---------------------------------------------------------------------- @@ -338,7 +347,8 @@ int artFeedBack(ART1 *art1, int class) { Returns: ----------------------------------------------------------------------*/ -int artFeedForward(ART1 *art1) { +int artFeedForward(ART1 *art1) +{ int max_j, j; // double f2; double max_out; @@ -372,7 +382,8 @@ int artFeedForward(ART1 *art1) { Returns: ----------------------------------------------------------------------*/ -double artChoice(ART1 *art1, int j) { +double artChoice(ART1 *art1, int j) +{ double Tj, *zj, norm_zj, norm_I_int_zj; zj = Mzj(art1, 0, j); /* address of jth nodes weights */ @@ -384,7 +395,8 @@ double artChoice(ART1 *art1, int j) { norm_zj = norm(zj, art1->ninputs); Tj = (double)norm_I_int_zj / (art1->beta + (double)norm_zj); - } else /* Tj = |I| * ALPHA(j) */ + } + else /* Tj = |I| * ALPHA(j) */ { Tj = (double)norm(art1->f0, art1->ninputs); Tj *= ALPHA(art1, j); @@ -395,7 +407,8 @@ double artChoice(ART1 *art1, int j) { take the intersection of vectors a and b, and return it in vector c. All vectors have length 'len'. */ -void intersect(double huge *a, double huge *b, double huge *c, int len) { +void intersect(double huge *a, double huge *b, double huge *c, int len) +{ register int i; for (i = 0; i < len; i++, a++, b++, c++) *c = MIN(*a, *b); @@ -404,7 +417,8 @@ void intersect(double huge *a, double huge *b, double huge *c, int len) { /* take the norm (city block) of vector a of length 'len'. */ -double norm(double huge *a, int len) { +double norm(double huge *a, int len) +{ register int i; double norm_val; @@ -422,7 +436,8 @@ double norm(double huge *a, int len) { f2->f1 learning: zj = I ^ zj */ -void artFastLearn(ART1 *art1, int j) { +void artFastLearn(ART1 *art1, int j) +{ // double norm_I_int_zj; int i; @@ -435,7 +450,8 @@ void artFastLearn(ART1 *art1, int j) { *Mzj(art1, i, j) = art1->scratch[i]; } } -int Art1SetParms(ART1 *art1, double rho) { +int Art1SetParms(ART1 *art1, double rho) +{ art1->rho = rho; return (NO_ERROR); } diff --git a/utils/artmap.c b/utils/artmap.c index b9a5db3ac87..d64dbffc53a 100644 --- a/utils/artmap.c +++ b/utils/artmap.c @@ -102,7 +102,8 @@ void mapLearn(ARTMAP *artmap, int ja, int jb); Returns: ----------------------------------------------------------------------*/ -ARTMAP *ArtmapAlloc(int ninputs, int noutputs, double rho_bar, int max_f2) { +ARTMAP *ArtmapAlloc(int ninputs, int noutputs, double rho_bar, int max_f2) +{ ARTMAP *artmap; artmap = (ARTMAP *)InsCalloc(1, sizeof(ARTMAP)); @@ -132,7 +133,8 @@ ARTMAP *ArtmapAlloc(int ninputs, int noutputs, double rho_bar, int max_f2) { Returns: ----------------------------------------------------------------------*/ -ARTMAP *ArtmapRead(char *fname) { +ARTMAP *ArtmapRead(char *fname) +{ ARTMAP *artmap; int ninputs, noutputs, f2nodes, i, j, k, wj; double zj; @@ -181,7 +183,8 @@ ARTMAP *ArtmapRead(char *fname) { Returns: ----------------------------------------------------------------------*/ -int ArtmapWrite(ARTMAP *artmap, char *fname) { +int ArtmapWrite(ARTMAP *artmap, char *fname) +{ FILE *fp; int i, j, k, wj; double zj; @@ -216,7 +219,8 @@ int ArtmapWrite(ARTMAP *artmap, char *fname) { Returns: ----------------------------------------------------------------------*/ -int ArtmapFree(ARTMAP **artmap) { +int ArtmapFree(ARTMAP **artmap) +{ InsFree((*artmap)->scratch); InsFree((*artmap)->f0); InsFree((*artmap)->f1); @@ -236,7 +240,8 @@ int ArtmapFree(ARTMAP **artmap) { Returns: ----------------------------------------------------------------------*/ -int ArtmapProcess(ARTMAP *artmap, double *I) { +int ArtmapProcess(ARTMAP *artmap, double *I) +{ int class; if (Gdiag & DIAG_WRITE) printf("ArtmapProcess()\n"); @@ -258,7 +263,8 @@ int ArtmapProcess(ARTMAP *artmap, double *I) { Returns: ----------------------------------------------------------------------*/ -int artProcess(ARTMAP *artmap, double *I) { +int artProcess(ARTMAP *artmap, double *I) +{ int nclass, i, class = 0; for (i = 0; i < artmap->ninputs; i++) artmap->f0[i] = artmap->f1[i] = I[i]; @@ -290,7 +296,8 @@ int artProcess(ARTMAP *artmap, double *I) { Returns: ----------------------------------------------------------------------*/ -int ArtmapLearn(ARTMAP *artmap, double *I, int class) { +int ArtmapLearn(ARTMAP *artmap, double *I, int class) +{ int artClass; if (Gdiag & DIAG_WRITE) printf("ArtmapLearn(%d)\n", class); @@ -311,7 +318,8 @@ int ArtmapLearn(ARTMAP *artmap, double *I, int class) { artmap->flags[artmap->class] |= ARTMAP_COMMITTED; artmap->ncommitted++; break; - } else + } + else return (-1); /* out of memory */ } if (artClass != class) { @@ -333,7 +341,8 @@ int ArtmapLearn(ARTMAP *artmap, double *I, int class) { Returns: ----------------------------------------------------------------------*/ -static void artInitWeights(ARTMAP *artmap) { +static void artInitWeights(ARTMAP *artmap) +{ int i, j, k; double *zj; @@ -365,7 +374,8 @@ static void artInitWeights(ARTMAP *artmap) { Returns: ----------------------------------------------------------------------*/ -static int artFeedBack(ARTMAP *artmap, int class) { +static int artFeedBack(ARTMAP *artmap, int class) +{ int j, ninputs; double match, norm_I_int_zj, norm_I; @@ -395,7 +405,8 @@ static int artFeedBack(ARTMAP *artmap, int class) { { artmap->flags[j] |= ARTMAP_RESET; return (0); - } else + } + else return (1); /* resonance */ } @@ -406,7 +417,8 @@ static int artFeedBack(ARTMAP *artmap, int class) { Returns: ----------------------------------------------------------------------*/ -static int artFeedForward(ARTMAP *artmap) { +static int artFeedForward(ARTMAP *artmap) +{ int max_j, j; // double f2, double max_out; @@ -441,7 +453,8 @@ static int artFeedForward(ARTMAP *artmap) { Returns: ----------------------------------------------------------------------*/ -static double artChoice(ARTMAP *artmap, int j) { +static double artChoice(ARTMAP *artmap, int j) +{ double Tj, *zj, norm_zj, norm_I_int_zj; zj = Mzj(artmap, 0, j); /* address of jth nodes weights */ @@ -453,7 +466,8 @@ static double artChoice(ARTMAP *artmap, int j) { norm_zj = norm(zj, artmap->ninputs); Tj = (double)norm_I_int_zj / (artmap->beta + (double)norm_zj); - } else /* Tj = |I| * ALPHA(j) */ + } + else /* Tj = |I| * ALPHA(j) */ { Tj = (double)norm(artmap->f0, artmap->ninputs); Tj *= ALPHA(artmap, j); @@ -465,7 +479,8 @@ static double artChoice(ARTMAP *artmap, int j) { take the intersection of vectors a and b, and return it in vector c. All vectors have length 'len'. */ -static void intersect(double huge *a, double huge *b, double huge *c, int len) { +static void intersect(double huge *a, double huge *b, double huge *c, int len) +{ register int i; for (i = 0; i < len; i++, a++, b++, c++) *c = MIN(*a, *b); @@ -474,7 +489,8 @@ static void intersect(double huge *a, double huge *b, double huge *c, int len) { /* take the norm (city block) of vector a of length 'len'. */ -static double norm(double huge *a, int len) { +static double norm(double huge *a, int len) +{ register int i; double norm_val; @@ -492,7 +508,8 @@ static double norm(double huge *a, int len) { f2->f1 learning: zj = I ^ zj */ -static void artFastLearn(ARTMAP *artmap, int j) { +static void artFastLearn(ARTMAP *artmap, int j) +{ // double norm_I_int_zj; int i; @@ -517,7 +534,8 @@ static void artFastLearn(ARTMAP *artmap, int j) { Returns: ----------------------------------------------------------------------*/ -int mapFeedForward(ARTMAP *artmap, int class) { +int mapFeedForward(ARTMAP *artmap, int class) +{ int k, apredict; if (class < 0) return (-1); /* ARTa did not make a choice */ @@ -544,7 +562,8 @@ int mapFeedForward(ARTMAP *artmap, int class) { Returns: ----------------------------------------------------------------------*/ -void mapLearn(ARTMAP *artmap, int aclass, int mapclass) { +void mapLearn(ARTMAP *artmap, int aclass, int mapclass) +{ register int k, *wj; if (Gdiag & DIAG_WRITE) printf("mapLearn(%d-->%d)\n", aclass, mapclass); diff --git a/utils/aseg_edit_svm.c b/utils/aseg_edit_svm.c index f282fabe14a..c4e53ffdfe9 100644 --- a/utils/aseg_edit_svm.c +++ b/utils/aseg_edit_svm.c @@ -51,7 +51,8 @@ float **build_svm_training_data(VOXEL_LIST *vl_total, MRI **mri_laplacian, MRI *mri_dtrans, int wsize, - int nscales) { + int nscales) +{ float **svm_inputs; int i, ninputs; MRI *mri_dtrans_grad; @@ -93,7 +94,8 @@ float *build_svm_inputs_at_voxel(VOXEL_LIST *vl, MRI *mri_dtrans_grad, int wsize, int nscales, - float *svm_inputs) { + float *svm_inputs) +{ int s, xk, yk, zk, xi, yi, zi, x, y, z, ninputs, whalf, input; whalf = (wsize - 1) / 2; diff --git a/utils/autoencoder.c b/utils/autoencoder.c index 5a80e383b87..0851aa2fb11 100644 --- a/utils/autoencoder.c +++ b/utils/autoencoder.c @@ -60,7 +60,8 @@ static int CSAEcomputeGradient(CSAE *csae, static double aeApplyAccumulatedGradient(AE *ae, SAE_INTEGRATION_PARMS *parms); static int reset_constant_nodes(AE *ae, double thresh); -AE *SAEfindLastLayer(SAE *sae, AE *ae) { +AE *SAEfindLastLayer(SAE *sae, AE *ae) +{ if (ae == NULL) return (SAEfindLastLayer(sae, sae->first)); else if (ae->next) @@ -69,7 +70,8 @@ AE *SAEfindLastLayer(SAE *sae, AE *ae) { return (ae); } -SAE *SAEalloc(int whalf, int nlevels, int type, double scale) { +SAE *SAEalloc(int whalf, int nlevels, int type, double scale) +{ SAE *sae; int ninputs, wsize, nhidden, noutputs; @@ -99,7 +101,8 @@ SAE *SAEalloc(int whalf, int nlevels, int type, double scale) { return (sae); } -static AE *AEalloc(AE *prev, int ninputs, int nhidden, int noutputs) { +static AE *AEalloc(AE *prev, int ninputs, int nhidden, int noutputs) +{ AE *ae; int i, j, k; double norm, w, wt_lim = .1; @@ -211,7 +214,8 @@ static AE *AEalloc(AE *prev, int ninputs, int nhidden, int noutputs) { return (ae); } -static void AEfree(AE **pae) { +static void AEfree(AE **pae) +{ AE *ae = *pae; *pae = NULL; @@ -244,7 +248,8 @@ static void AEfree(AE **pae) { free(ae->average_act); } -void SAEfree(SAE **psae) { +void SAEfree(SAE **psae) +{ SAE *sae = *psae; AE *ae, *next; @@ -259,7 +264,8 @@ void SAEfree(SAE **psae) { free(sae); } -AE *SAEaddLayer(SAE *sae, float scale) { +AE *SAEaddLayer(SAE *sae, float scale) +{ AE *ae, *last; int nhidden, noutputs; @@ -273,7 +279,8 @@ AE *SAEaddLayer(SAE *sae, float scale) { return (ae); } -SAE *SAEtrainLayer(SAE *sae, AE *layer, MRI **mri, double tol) { +SAE *SAEtrainLayer(SAE *sae, AE *layer, MRI **mri, double tol) +{ int x, y, z; for (x = 0; x < mri[0]->width; x++) @@ -284,7 +291,8 @@ SAE *SAEtrainLayer(SAE *sae, AE *layer, MRI **mri, double tol) { } return (sae); } -double SAEcomputeTotalRMS(SAE *sae, MRI **mri) { +double SAEcomputeTotalRMS(SAE *sae, MRI **mri) +{ int x, y, z, nvox; double rms, total_rms; @@ -305,12 +313,14 @@ double SAEcomputeTotalRMS(SAE *sae, MRI **mri) { return (total_rms / nvox); } -VECTOR *SAEactivateNetwork(SAE *sae) { +VECTOR *SAEactivateNetwork(SAE *sae) +{ AEactivateLayer(sae->first, sae->first->v_input); return (sae->first->v_output); } -static int AEactivateLayer(AE *ae, VECTOR *v_input) { +static int AEactivateLayer(AE *ae, VECTOR *v_input) +{ int row, ninputs = ae->v_input->rows; double o, net; @@ -355,7 +365,8 @@ static int AEactivateLayer(AE *ae, VECTOR *v_input) { VECTOR *SAEactivateLastHiddenLayer(SAE *sae, MRI *mri) { return (sae->first->v_output); } -double SAEcomputeRMS(SAE *sae) { +double SAEcomputeRMS(SAE *sae) +{ VECTOR *v_output; int row; double error, rms; @@ -367,7 +378,8 @@ double SAEcomputeRMS(SAE *sae) { error = VECTOR_ELT(sae->first->v_input, row) - VECTOR_ELT(sae->first->v_output, row); rms += error * error; } - } else { + } + else { row = (sae->first->v_input->rows + 1) / 2; error = VECTOR_ELT(sae->first->v_input, row) - VECTOR_ELT(sae->first->v_output, 1); rms = error * error; @@ -375,7 +387,8 @@ double SAEcomputeRMS(SAE *sae) { } return (sqrt(rms / row)); } -static double AEcomputeRMS(AE *ae) { +static double AEcomputeRMS(AE *ae) +{ int row; double error, rms; @@ -385,7 +398,8 @@ static double AEcomputeRMS(AE *ae) { error = VECTOR_ELT(ae->v_input, row) - VECTOR_ELT(ae->v_output, row); rms += error * error; } - } else { + } + else { row = (ae->v_input->rows + 1) / 2; error = VECTOR_ELT(ae->v_input, row) - VECTOR_ELT(ae->v_output, 1); rms = error * error; @@ -396,7 +410,8 @@ static double AEcomputeRMS(AE *ae) { } // NOTE: input MRI must be type float and scaled to be 0->1 (that is, scale down MRI_UCHAR vols by 255) -double SAEtrainFromMRI(SAE *sae, MRI **mri_pyramid, SAE_INTEGRATION_PARMS *parms) { +double SAEtrainFromMRI(SAE *sae, MRI **mri_pyramid, SAE_INTEGRATION_PARMS *parms) +{ double error = 0.0, rms, last_rms, total_rms, last_total_rms, pct_decrease, running_last_rms, G_rms, G_last_rms = 1e10; int x, y, z, iter = 0, visited, ind, nvox, calls = 0; @@ -564,7 +579,8 @@ double SAEtrainFromMRI(SAE *sae, MRI **mri_pyramid, SAE_INTEGRATION_PARMS *parms } // NOTE: input MRI must be type float and scaled to be 0->1 (that is, scale down MRI_UCHAR vols by 255) -double SAEtrainFromVoxlist(SAE *sae, VOXEL_LIST *vl, MRI **mri_pyramid, SAE_INTEGRATION_PARMS *parms) { +double SAEtrainFromVoxlist(SAE *sae, VOXEL_LIST *vl, MRI **mri_pyramid, SAE_INTEGRATION_PARMS *parms) +{ double error = 0.0, rms, last_rms, total_rms, last_total_rms, pct_decrease, running_last_rms, G_rms, G_last_rms = 1e10; int x, y, z, iter = 0, visited, ind, calls = 0, *indices, i; @@ -728,7 +744,8 @@ static int CSAEcomputeGradient(CSAE *csae, int start_index, int end_index, int *indices, - SAE_INTEGRATION_PARMS *parms) { + SAE_INTEGRATION_PARMS *parms) +{ int ind, i, j, k, whalf, x, y, z, ninputs, nhidden, noutputs, num_indices; AEclearGradients(ae); @@ -781,7 +798,8 @@ static int CSAEcomputeGradient(CSAE *csae, return (NO_ERROR); } -static int AEclearGradients(AE *ae) { +static int AEclearGradients(AE *ae) +{ int j; if (ae->m_grad_input_to_hidden == NULL) return (NO_ERROR); @@ -813,7 +831,8 @@ Out[8]= --------------- */ -static double AEaccumulateGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) { +static double AEaccumulateGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) +{ double rms = 0, error, wt; int i, j, k, ninputs, nhidden, noutputs; @@ -839,7 +858,8 @@ static double AEaccumulateGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) { error = VECTOR_ELT(ae->v_error, k) = VECTOR_ELT(ae->v_output, k) - VECTOR_ELT(ae->v_input, k); rms += error * error; } - } else { + } + else { int ind; ind = (ninputs + 1) / 2; rms = VECTOR_ELT(ae->v_error, 1) = VECTOR_ELT(ae->v_output, 1) - VECTOR_ELT(ae->v_input, ind); @@ -948,7 +968,8 @@ static double AEaccumulateGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) { return (rms); } -static double aeApplyAccumulatedGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) { +static double aeApplyAccumulatedGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) +{ double rms = 0, dt, momentum, Egrad, Erandom; int ninputs, nhidden, noutputs; @@ -992,7 +1013,8 @@ static double aeApplyAccumulatedGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) { MatrixCopy(ae->m_grad_hidden_to_output, ae->m_previous_step_hidden_to_output); MatrixCopy(ae->m_grad_input_to_hidden, ae->m_previous_step_input_to_hidden); rms = sqrt(rms / noutputs); - } else if (parms->integration_type == INTEGRATE_CONJUGATE_GRADIENT) { + } + else if (parms->integration_type == INTEGRATE_CONJUGATE_GRADIENT) { double beta, best_dt, orig_dt, rms, best_rms; static int callno = 0; @@ -1043,7 +1065,8 @@ static double aeApplyAccumulatedGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) { VectorCopy(ae->v_grad_hidden_bias, parms->v_prev_grad_hidden_bias) ; parms->norm_hidden_bias = VectorLen(parms->v_prev_grad_hidden_bias) ; parms->norm_hidden_bias *= parms->norm_hidden_bias ; #endif - } else if (parms->integration_type == INTEGRATE_BOLTZMANN_MACHINE) { + } + else if (parms->integration_type == INTEGRATE_BOLTZMANN_MACHINE) { static MATRIX *m_hidden_to_output_delta = NULL, *m_input_to_hidden_delta = NULL, *v_hidden_bias_delta = NULL, *v_output_bias_delta = NULL; double acceptance_val; @@ -1082,14 +1105,16 @@ static double aeApplyAccumulatedGradient(AE *ae, SAE_INTEGRATION_PARMS *parms) { MatrixAdd(ae->v_grad_hidden_bias, ae->v_hidden_bias, ae->v_hidden_bias); MatrixAdd(ae->m_grad_hidden_to_output, ae->m_hidden_to_output, ae->m_hidden_to_output); MatrixAdd(ae->m_grad_input_to_hidden, ae->m_input_to_hidden, ae->m_input_to_hidden); - } else + } + else DiagBreak(); } return (rms); } -static int aeApplyGradient(AE *ae, SAE_INTEGRATION_PARMS *parms, double dt) { +static int aeApplyGradient(AE *ae, SAE_INTEGRATION_PARMS *parms, double dt) +{ static MATRIX *m_grad_hidden_to_output, *m_grad_input_to_hidden; static VECTOR *v_grad_hidden_bias, *v_grad_output_bias; @@ -1113,7 +1138,8 @@ static int aeApplyGradient(AE *ae, SAE_INTEGRATION_PARMS *parms, double dt) { return (NO_ERROR); } -static double AEtrain(AE *ae, SAE_INTEGRATION_PARMS *parms) { +static double AEtrain(AE *ae, SAE_INTEGRATION_PARMS *parms) +{ double rms = 0, error, dt, momentum, Egrad, Erandom, wt; int i, j, k, ninputs, nhidden, noutputs; @@ -1141,7 +1167,8 @@ static double AEtrain(AE *ae, SAE_INTEGRATION_PARMS *parms) { error = VECTOR_ELT(ae->v_error, k) = VECTOR_ELT(ae->v_output, k) - VECTOR_ELT(ae->v_input, k); rms += error * error; } - } else { + } + else { int ind; ind = (ninputs + 1) / 2; rms = VECTOR_ELT(ae->v_error, 1) = VECTOR_ELT(ae->v_output, 1) - VECTOR_ELT(ae->v_input, ind); @@ -1304,7 +1331,8 @@ static double AEtrain(AE *ae, SAE_INTEGRATION_PARMS *parms) { MatrixCopy(ae->m_grad_hidden_to_output, ae->m_previous_step_hidden_to_output); MatrixCopy(ae->m_grad_input_to_hidden, ae->m_previous_step_input_to_hidden); rms = sqrt(rms / noutputs); - } else if (parms->integration_type == INTEGRATE_CONJUGATE_GRADIENT) { + } + else if (parms->integration_type == INTEGRATE_CONJUGATE_GRADIENT) { double beta, best_dt, orig_dt, rms, best_rms; static int callno = 0; @@ -1355,7 +1383,8 @@ static double AEtrain(AE *ae, SAE_INTEGRATION_PARMS *parms) { VectorCopy(ae->v_grad_hidden_bias, parms->v_prev_grad_hidden_bias) ; parms->norm_hidden_bias = VectorLen(parms->v_prev_grad_hidden_bias) ; parms->norm_hidden_bias *= parms->norm_hidden_bias ; #endif - } else if (parms->integration_type == INTEGRATE_BOLTZMANN_MACHINE) { + } + else if (parms->integration_type == INTEGRATE_BOLTZMANN_MACHINE) { static MATRIX *m_hidden_to_output_delta = NULL, *m_input_to_hidden_delta = NULL, *v_hidden_bias_delta = NULL, *v_output_bias_delta = NULL; double acceptance_val; @@ -1394,14 +1423,16 @@ static double AEtrain(AE *ae, SAE_INTEGRATION_PARMS *parms) { MatrixAdd(ae->v_grad_hidden_bias, ae->v_hidden_bias, ae->v_hidden_bias); MatrixAdd(ae->m_grad_hidden_to_output, ae->m_hidden_to_output, ae->m_hidden_to_output); MatrixAdd(ae->m_grad_input_to_hidden, ae->m_input_to_hidden, ae->m_input_to_hidden); - } else + } + else DiagBreak(); } return (rms); } -VECTOR *SAEfillInputVector(MRI **mri, int nlevels, int x0, int y0, int z0, int whalf, VECTOR *v_input) { +VECTOR *SAEfillInputVector(MRI **mri, int nlevels, int x0, int y0, int z0, int whalf, VECTOR *v_input) +{ int i, n, xk, yk, zk; double x, y, z, xi, yi, zi, scale, val, zmin, zmax; @@ -1414,7 +1445,8 @@ VECTOR *SAEfillInputVector(MRI **mri, int nlevels, int x0, int y0, int z0, int w if (mri[0]->depth > 1) { zmin = -whalf; zmax = whalf; - } else + } + else zmin = zmax = 0; for (n = 0; n < nlevels; n++) { scale = pow(2.0, n); @@ -1450,7 +1482,8 @@ VECTOR *SAEfillInputVector(MRI **mri, int nlevels, int x0, int y0, int z0, int w return (v_input); } -MRI *SAEvectorToMRI(VECTOR *v_input, int nlevels, int whalf, MRI *mri) { +MRI *SAEvectorToMRI(VECTOR *v_input, int nlevels, int whalf, MRI *mri) +{ int xk, yk, zk, i, wsize, n, zsize; wsize = (2 * whalf) + 1; @@ -1469,7 +1502,8 @@ MRI *SAEvectorToMRI(VECTOR *v_input, int nlevels, int whalf, MRI *mri) { return (mri); } -MRI *SAEinputWeightsToMRI(SAE *sae, MRI *mri) { +MRI *SAEinputWeightsToMRI(SAE *sae, MRI *mri) +{ int xk, yk, zk, i, wsize, frame, hidden, n; wsize = (2 * sae->whalf) + 1; @@ -1493,7 +1527,8 @@ MRI *SAEinputWeightsToMRI(SAE *sae, MRI *mri) { return (mri); } -int SAEwrite(SAE *sae, char *fname) { +int SAEwrite(SAE *sae, char *fname) +{ FILE *fp; AE *ae; int i, n; @@ -1515,7 +1550,8 @@ int SAEwrite(SAE *sae, char *fname) { fclose(fp); return (NO_ERROR); } -static int AEwrite(AE *ae, FILE *fp) { +static int AEwrite(AE *ae, FILE *fp) +{ MatrixWriteInto(fp, ae->m_input_to_hidden); MatrixWriteInto(fp, ae->v_output_bias); MatrixWriteInto(fp, ae->v_hidden_bias); @@ -1526,7 +1562,8 @@ static int AEwrite(AE *ae, FILE *fp) { fwriteInt(ae->ksize, fp); return (NO_ERROR); } -static AE *AEread(FILE *fp, AE *prev) { +static AE *AEread(FILE *fp, AE *prev) +{ AE *ae; MATRIX *m_input_to_hidden, *v_output_bias; @@ -1549,7 +1586,8 @@ static AE *AEread(FILE *fp, AE *prev) { return (ae); } -SAE *SAEread(char *fname) { +SAE *SAEread(char *fname) +{ FILE *fp; int whalf, nencoders, i, type, nlevels, n; SAE *sae; @@ -1578,7 +1616,8 @@ SAE *SAEread(char *fname) { return (sae); } -void AEdump(AE *ae) { +void AEdump(AE *ae) +{ if (ae->v_input->rows == 1) { printf("f(I=%2.2f * wij=%2.2f + bj=%2.2f = %2.2f) = %2.2f * wjk=%2.2f + bk=%2.2f = %2.2f, E=%2.2f\n", ae->v_input->rptr[1][1], @@ -1631,7 +1670,8 @@ void AEdump(AE *ae) { MatrixPrint(Gstdout, ae->v_grad_output_bias); } } -static int AEsaveState(AE *ae) { +static int AEsaveState(AE *ae) +{ ae->m_saved_input_to_hidden = MatrixCopy(ae->m_input_to_hidden, ae->m_saved_input_to_hidden); ae->m_saved_hidden_to_output = MatrixCopy(ae->m_hidden_to_output, ae->m_saved_hidden_to_output); ae->v_saved_hidden_bias = MatrixCopy(ae->v_hidden_bias, ae->v_saved_hidden_bias); @@ -1639,7 +1679,8 @@ static int AEsaveState(AE *ae) { return (NO_ERROR); } -static int AErestoreState(AE *ae) { +static int AErestoreState(AE *ae) +{ MatrixCopy(ae->m_saved_input_to_hidden, ae->m_input_to_hidden); MatrixCopy(ae->m_saved_hidden_to_output, ae->m_hidden_to_output); MatrixCopy(ae->v_saved_hidden_bias, ae->v_hidden_bias); @@ -1651,7 +1692,8 @@ static int AErestoreState(AE *ae) { int CSAEwrite(CSAE *csae, char *fname) { return (SAEwrite(csae->sae, fname)); } -CSAE *CSAEalloc(int type, int nlayers, int *ksizes, int *ngroups, MRI *mri_inputs) { +CSAE *CSAEalloc(int type, int nlayers, int *ksizes, int *ngroups, MRI *mri_inputs) +{ int whalf = (ksizes[0] - 1) / 2, layer; double scale; AE *ae; @@ -1674,7 +1716,8 @@ CSAE *CSAEalloc(int type, int nlayers, int *ksizes, int *ngroups, MRI *mri_input } return (csae); } -int CSAEfillInputs(CSAE *csae, MRI *mri_inputs, VECTOR *v_visible, int x0, int y0, int z0, int ksize) { +int CSAEfillInputs(CSAE *csae, MRI *mri_inputs, VECTOR *v_visible, int x0, int y0, int z0, int ksize) +{ int xk, yk, xi, yi, whalf, v, f; float val; @@ -1691,7 +1734,8 @@ int CSAEfillInputs(CSAE *csae, MRI *mri_inputs, VECTOR *v_visible, int x0, int y return (NO_ERROR); } -MRI *CSAEcreateOutputs(CSAE *csae, MRI *mri_inputs, int first_layer, int last_layer) { +MRI *CSAEcreateOutputs(CSAE *csae, MRI *mri_inputs, int first_layer, int last_layer) +{ int layer, x, y, z, h; // int whalf; MRI *mri_layer_inputs, *mri_outputs = NULL; @@ -1722,7 +1766,8 @@ MRI *CSAEcreateOutputs(CSAE *csae, MRI *mri_inputs, int first_layer, int last_la return (mri_outputs); } -AE *CSAEaddLayer(CSAE *csae, int ksize, int nhidden) { +AE *CSAEaddLayer(CSAE *csae, int ksize, int nhidden) +{ AE *ae, *last; int ninputs; // float scale; @@ -1738,8 +1783,8 @@ AE *CSAEaddLayer(CSAE *csae, int ksize, int nhidden) { return (ae); } // NOTE: input MRI must be type float and scaled to be 0->1 (that is, scale down MRI_UCHAR vols by 255) -double CSAEtrainLayerFromVoxlist( - CSAE *csae, int layer, VOXEL_LIST *vl, MRI **mri_pyramid, SAE_INTEGRATION_PARMS *parms) { +double CSAEtrainLayerFromVoxlist(CSAE *csae, int layer, VOXEL_LIST *vl, MRI **mri_pyramid, SAE_INTEGRATION_PARMS *parms) +{ double total_rms, last_total_rms, pct_decrease, running_last_rms = 0, running_rms; int iter = 0, ind, *indices, end_index, end_mini_batch, always, never, nbad, i; double dt, acceptance_sigma, proposal_sigma, tol, min_rms; @@ -1842,7 +1887,8 @@ double CSAEtrainLayerFromVoxlist( min_rms, nbad, parms->max_no_progress); - } else { + } + else { printf("new min RMS %2.4f found (previous %2.4f)\n", total_rms, min_rms); min_rms = total_rms; nbad = 0; @@ -1887,7 +1933,8 @@ double CSAEtrainLayerFromVoxlist( return (total_rms); } -MRI *CSAElayerWeightsToMRI(CSAE *csae, int layer) { +MRI *CSAElayerWeightsToMRI(CSAE *csae, int layer) +{ MRI *mri = NULL, *mri_prev, *mri_counts; int width, whalf, whalf_prev, x, y, xk, yk, v, h, count, xp, yp, hp; AE *ae, *ae_prev; @@ -1951,7 +1998,8 @@ MRI *CSAElayerWeightsToMRI(CSAE *csae, int layer) { } return (mri); } -MRI *SAElayerWeightsToMRI(SAE *sae, int layer) { +MRI *SAElayerWeightsToMRI(SAE *sae, int layer) +{ MRI *mri = NULL, *mri_prev, *mri_counts; int width, whalf_prev, x, y, xk, yk, v, h, count, xp, yp, hp; AE *ae, *ae_prev; @@ -2018,7 +2066,8 @@ MRI *SAElayerWeightsToMRI(SAE *sae, int layer) { } return (mri); } -double CSAEcomputeTotalRMS(CSAE *csae, int layer, MRI **mri) { +double CSAEcomputeTotalRMS(CSAE *csae, int layer, MRI **mri) +{ int x, y, z, nvox; double rms, total_rms; AE *ae; @@ -2041,7 +2090,8 @@ double CSAEcomputeTotalRMS(CSAE *csae, int layer, MRI **mri) { } return (total_rms / nvox); } -static double AEcomputeHiddenRMS(AE *ae, SAE_INTEGRATION_PARMS *parms) { +static double AEcomputeHiddenRMS(AE *ae, SAE_INTEGRATION_PARMS *parms) +{ int j; double target, rms, hidden, nhidden; @@ -2063,7 +2113,8 @@ double CSAEcomputeVoxlistRMS(CSAE *csae, int start_index, int end_index, int *always, - int *never) { + int *never) +{ int x, y, z, nvox, i, ind, *histo, h, nhidden, iz, num_indices; double class_rms, rms, total_rms, total_class_rms; AE *ae; @@ -2141,7 +2192,8 @@ double CSAEcomputeVoxlistRMS(CSAE *csae, free(histo); return (total_rms / nvox); } -CSAE *CSAEread(char *fname) { +CSAE *CSAEread(char *fname) +{ CSAE *csae; SAE *sae; int layer; @@ -2166,7 +2218,8 @@ CSAE *CSAEread(char *fname) { return (csae); } -static int reset_constant_nodes(AE *ae, double thresh) { +static int reset_constant_nodes(AE *ae, double thresh) +{ static int calls = 0; int i, j, nreset = 0, ninputs; float mean, std, val; diff --git a/utils/backprop.c b/utils/backprop.c index 1255531dfdf..828cc40b717 100644 --- a/utils/backprop.c +++ b/utils/backprop.c @@ -145,7 +145,8 @@ static int bpChangeNumberOfNets(FILE *fp, int nnets); int coef = -1; BACKPROP *BackpropAlloc( - int ninputs, int noutputs, int nhidden, float trate, float momentum, float *mean_out, float *std_out) { + int ninputs, int noutputs, int nhidden, float trate, float momentum, float *mean_out, float *std_out) +{ BACKPROP *backprop; backprop = (BACKPROP *)InsCalloc(1, sizeof(BACKPROP)); @@ -179,7 +180,8 @@ BACKPROP *BackpropAlloc( Returns: ----------------------------------------------------------------------*/ -int BackpropFileNumberOfNets(char *fname) { +int BackpropFileNumberOfNets(char *fname) +{ BPFILE_HEADER hd; FILE *fp; @@ -188,7 +190,8 @@ int BackpropFileNumberOfNets(char *fname) { if (!fp) return (-1); fclose(fp); fp = fopen(fname, "r+"); - } else + } + else fp = stdin; if (fread(&hd, sizeof(hd), 1, fp) != 1) @@ -214,7 +217,8 @@ int BackpropFileNumberOfNets(char *fname) { Returns: ----------------------------------------------------------------------*/ -BACKPROP *BackpropRead(char *fname, int netno) { +BACKPROP *BackpropRead(char *fname, int netno) +{ BACKPROP *backprop; int ninputs, noutputs, nhidden, ubytes, swapped = 0; FILE *fp; @@ -226,7 +230,8 @@ BACKPROP *BackpropRead(char *fname, int netno) { if (!fp) return (NULL); fclose(fp); fp = fopen(fname, "r+"); - } else + } + else fp = stdin; if (fread(&hd, sizeof(hd), 1, fp) != 1) @@ -305,7 +310,8 @@ BACKPROP *BackpropRead(char *fname, int netno) { Returns: ----------------------------------------------------------------------*/ -BACKPROP *BackpropCopy(BACKPROP *bp_src, BACKPROP *bp_dst) { +BACKPROP *BackpropCopy(BACKPROP *bp_src, BACKPROP *bp_dst) +{ if (bp_dst && ((bp_dst->ninputs != bp_src->ninputs) || (bp_dst->noutputs != bp_src->noutputs) || (bp_dst->nhidden != bp_src->nhidden))) BackpropFree(&bp_dst); @@ -350,7 +356,8 @@ BACKPROP *BackpropCopy(BACKPROP *bp_src, BACKPROP *bp_dst) { Returns: ----------------------------------------------------------------------*/ -static void bpCopyLayer(LAYER *lsrc, LAYER *ldst) { +static void bpCopyLayer(LAYER *lsrc, LAYER *ldst) +{ int nweights; nweights = lsrc->nunits * lsrc->ninputs; @@ -370,7 +377,8 @@ static void bpCopyLayer(LAYER *lsrc, LAYER *ldst) { Returns: ----------------------------------------------------------------------*/ -int BackpropWrite(BACKPROP *backprop, char *fname, int argc, char *argv[], char *comments, int mode) { +int BackpropWrite(BACKPROP *backprop, char *fname, int argc, char *argv[], char *comments, int mode) +{ FILE *fp = NULL; int i; char *user, *time_str; @@ -462,7 +470,8 @@ int BackpropWrite(BACKPROP *backprop, char *fname, int argc, char *argv[], char Returns: ----------------------------------------------------------------------*/ -int BackpropProcess(BACKPROP *backprop, float *I) { +int BackpropProcess(BACKPROP *backprop, float *I) +{ int i, class = -1; LAYER *hidden, *output; float maxX; @@ -505,7 +514,8 @@ int BackpropProcess(BACKPROP *backprop, float *I) { convert the output range to unnormalized format ----------------------------------------------------------------------*/ #define NO_CONVERT 0 -static void bpUnnormalizeOutputs(BACKPROP *backprop) { +static void bpUnnormalizeOutputs(BACKPROP *backprop) +{ float mean, std; int i; LAYER *output; @@ -526,7 +536,8 @@ static void bpUnnormalizeOutputs(BACKPROP *backprop) { Returns: scale targets to desired range ----------------------------------------------------------------------*/ -static void bpNormalizeTargets(BACKPROP *backprop, float *targets) { +static void bpNormalizeTargets(BACKPROP *backprop, float *targets) +{ float mean, std; int i; @@ -545,7 +556,8 @@ static void bpNormalizeTargets(BACKPROP *backprop, float *targets) { Returns: convert targets back to original unnormalized range ----------------------------------------------------------------------*/ -static void bpUnnormalizeTargets(BACKPROP *backprop, float *targets) { +static void bpUnnormalizeTargets(BACKPROP *backprop, float *targets) +{ float mean, std; int i; @@ -566,7 +578,8 @@ static void bpUnnormalizeTargets(BACKPROP *backprop, float *targets) { scale outputs to desired range ----------------------------------------------------------------------*/ #define NO_CONVERT 0 -static void bpUnnormalizeOutputs(BACKPROP *backprop) { +static void bpUnnormalizeOutputs(BACKPROP *backprop) +{ float scale, min_out; int i; LAYER *output; @@ -591,7 +604,8 @@ static void bpUnnormalizeOutputs(BACKPROP *backprop) { Returns: scale outputs to desired range ----------------------------------------------------------------------*/ -static void bpNormalizeTargets(BACKPROP *backprop, float *targets) { +static void bpNormalizeTargets(BACKPROP *backprop, float *targets) +{ float scale, min_out; int i; @@ -614,7 +628,8 @@ static void bpNormalizeTargets(BACKPROP *backprop, float *targets) { Returns: scale outputs to desired range ----------------------------------------------------------------------*/ -static void bpUnnormalizeTargets(BACKPROP *backprop, float *targets) { +static void bpUnnormalizeTargets(BACKPROP *backprop, float *targets) +{ float scale, min_out; int i; @@ -637,7 +652,8 @@ static void bpUnnormalizeTargets(BACKPROP *backprop, float *targets) { Returns: ----------------------------------------------------------------------*/ -static void bpLayerFeedForward(float *I, LAYER *layer, int nlin) { +static void bpLayerFeedForward(float *I, LAYER *layer, int nlin) +{ int i, j, nunits, ninputs; float *pbias, *px; register float net, *Ii, *wij; @@ -687,7 +703,8 @@ float BackpropTrainEpoch( BACKPROP *bp, int ntrials, int (*io_func)(float *inputs, float *targets, int index, int ninputs, int noutputs, void *user), - void *user) { + void *user) +{ char *input_tested; float *inputs, *targets, error_ratio; int tested, index, min_trial, max_trial, i; @@ -768,12 +785,14 @@ learning_rate = learning_rate * TRATE_INCREASE. { bp->trate = bp->trate * bp->trate_down; bp->momentum = 0.0f; - } else /* new error is acceptable, use new network */ + } + else /* new error is acceptable, use new network */ { if (new_bp->sse < bp->sse) /* error decreased, increase trate */ { new_bp->trate = new_bp->trate * new_bp->trate_up; - } else /* error increased by a little NEW!!!! */ + } + else /* error increased by a little NEW!!!! */ { new_bp->trate = new_bp->trate * new_bp->trate_down; /* new_bp->momentum = 0.0f ;*/ @@ -801,7 +820,8 @@ learning_rate = learning_rate * TRATE_INCREASE. Returns: ----------------------------------------------------------------------*/ -float BackpropLearn(BACKPROP *backprop, float *inputs, float *targets) { +float BackpropLearn(BACKPROP *backprop, float *inputs, float *targets) +{ // int bpClass; int i; LAYER *hidden, *output; @@ -854,7 +874,8 @@ float BackpropLearn(BACKPROP *backprop, float *inputs, float *targets) { Returns: ----------------------------------------------------------------------*/ -static void bpCalculateOutputDeltas(BACKPROP *backprop, float *targets) { +static void bpCalculateOutputDeltas(BACKPROP *backprop, float *targets) +{ LAYER *output; float *ptarget, *px, *pdelta, target; int j, nunits; @@ -885,7 +906,8 @@ static void bpCalculateOutputDeltas(BACKPROP *backprop, float *targets) { Returns: ----------------------------------------------------------------------*/ -static void bpCalculateHiddenDeltas(BACKPROP *backprop) { +static void bpCalculateHiddenDeltas(BACKPROP *backprop) +{ LAYER *output, *hidden; int i, j, hnunits, onunits; register float *pdeli, *pdelj; @@ -933,7 +955,8 @@ static void bpCalculateHiddenDeltas(BACKPROP *backprop) { Returns: ----------------------------------------------------------------------*/ -static void bpInitLayer(LAYER *layer, int ninputs, int nunits) { +static void bpInitLayer(LAYER *layer, int ninputs, int nunits) +{ long nweights; layer->ninputs = ninputs; @@ -954,7 +977,8 @@ static void bpInitLayer(LAYER *layer, int ninputs, int nunits) { Returns: ----------------------------------------------------------------------*/ -static void bpUpdateLayerWeights(LAYER *layer, float *I, float trate, float momentum) { +static void bpUpdateLayerWeights(LAYER *layer, float *I, float trate, float momentum) +{ int i, j, nunits, ninputs; float delta, one_minus_momentum, db, *Ii; register float dw, *dwij, *wij; @@ -1001,7 +1025,8 @@ static void bpUpdateLayerWeights(LAYER *layer, float *I, float trate, float mome Returns: ----------------------------------------------------------------------*/ -static void bpInitLayerWeights(LAYER *layer) { +static void bpInitLayerWeights(LAYER *layer) +{ int i, j; double rlim; @@ -1022,7 +1047,8 @@ static void bpInitLayerWeights(LAYER *layer) { Returns: ----------------------------------------------------------------------*/ -static void bpReadLayer(FILE *fp, LAYER *layer) { +static void bpReadLayer(FILE *fp, LAYER *layer) +{ int i, j, scanned; scanned = fscanf(fp, "%d %d\n", &layer->ninputs, &layer->nunits); @@ -1062,7 +1088,8 @@ static void bpReadLayer(FILE *fp, LAYER *layer) { Returns: ----------------------------------------------------------------------*/ -static void bpWriteLayer(FILE *fp, LAYER *layer) { +static void bpWriteLayer(FILE *fp, LAYER *layer) +{ int i, j; fprintf(fp, "%d %d\n", layer->ninputs, layer->nunits); @@ -1081,7 +1108,8 @@ static void bpWriteLayer(FILE *fp, LAYER *layer) { Returns: ----------------------------------------------------------------------*/ -int BackpropFree(BACKPROP **pbackprop) { +int BackpropFree(BACKPROP **pbackprop) +{ BACKPROP *backprop; backprop = *pbackprop; @@ -1099,7 +1127,8 @@ int BackpropFree(BACKPROP **pbackprop) { Returns: ----------------------------------------------------------------------*/ -static void bpFreeLayer(LAYER *layer) { +static void bpFreeLayer(LAYER *layer) +{ InsFree(layer->x); InsHfree(layer->w); InsHfree(layer->dw); @@ -1123,7 +1152,8 @@ static void bpFreeLayer(LAYER *layer) { #define TINY 0.000001f #endif -float BackpropError(BACKPROP *bp, float *targets) { +float BackpropError(BACKPROP *bp, float *targets) +{ float bpError, total, error; int i, nunits; LAYER *output; @@ -1169,7 +1199,8 @@ float BackpropError(BACKPROP *bp, float *targets) { Returns: ----------------------------------------------------------------------*/ -int BackpropErrorReset(BACKPROP *bp) { +int BackpropErrorReset(BACKPROP *bp) +{ memset(bp->errors, 0, bp->noutputs * sizeof(float)); return (0); @@ -1181,7 +1212,8 @@ int BackpropErrorReset(BACKPROP *bp) { Returns: ----------------------------------------------------------------------*/ -int BackpropSetParms(BACKPROP *bp, float trate_up, float trate_down, float error_ratio) { +int BackpropSetParms(BACKPROP *bp, float trate_up, float trate_down, float error_ratio) +{ bp->trate_up = trate_up; bp->trate_down = trate_down; bp->error_ratio = error_ratio; @@ -1238,7 +1270,8 @@ BackpropEpochComplete(BACKPROP *bp) Returns: ----------------------------------------------------------------------*/ -static long bpFileNewEnd(FILE *fp, BPFILE_HEADER *hd, int swapped) { +static long bpFileNewEnd(FILE *fp, BPFILE_HEADER *hd, int swapped) +{ long end; int err; @@ -1261,7 +1294,8 @@ static long bpFileNewEnd(FILE *fp, BPFILE_HEADER *hd, int swapped) { Returns: ----------------------------------------------------------------------*/ -static long bpFileSeekEndPtr(FILE *fp, BPFILE_HEADER *hd, int swapped) { +static long bpFileSeekEndPtr(FILE *fp, BPFILE_HEADER *hd, int swapped) +{ long next; /* @@ -1292,7 +1326,8 @@ static long bpFileSeekEndPtr(FILE *fp, BPFILE_HEADER *hd, int swapped) { Returns: ----------------------------------------------------------------------*/ -static long bpFileSeekNet(FILE *fp, BPFILE_HEADER *hd, int netno, int swapped) { +static long bpFileSeekNet(FILE *fp, BPFILE_HEADER *hd, int netno, int swapped) +{ int index; long next; @@ -1322,7 +1357,8 @@ static long bpFileSeekNet(FILE *fp, BPFILE_HEADER *hd, int netno, int swapped) { Returns: ----------------------------------------------------------------------*/ -static int bpChangeNumberOfNets(FILE *fp, int nnets) { +static int bpChangeNumberOfNets(FILE *fp, int nnets) +{ BPFILE_HEADER hd; DiagPrintf(DIAG_WRITE, "bpChangeNumberOfNets(%d)\n", nnets); diff --git a/utils/bfileio.c b/utils/bfileio.c index d983e066922..d582df52bfe 100644 --- a/utils/bfileio.c +++ b/utils/bfileio.c @@ -51,7 +51,8 @@ extern int errno; /* ------------------------- */ -int byteswapbufdouble(void *buf, long int nbufbytes) { +int byteswapbufdouble(void *buf, long int nbufbytes) +{ register char *cbuf, c; register long int n, nmax; @@ -80,7 +81,8 @@ int byteswapbufdouble(void *buf, long int nbufbytes) { } /* ------------------------- */ -int byteswapbuffloat(void *buf, long int nbufbytes) { +int byteswapbuffloat(void *buf, long int nbufbytes) +{ register char *cbuf, c; register long int n, nmax; @@ -101,7 +103,8 @@ int byteswapbuffloat(void *buf, long int nbufbytes) { } /* ------------------------- */ -int byteswapbufshort(void *buf, long int nbufbytes) { +int byteswapbufshort(void *buf, long int nbufbytes) +{ register char *cbuf, c; register long int n, nmax; @@ -121,7 +124,8 @@ int byteswapbufshort(void *buf, long int nbufbytes) { architecture designated by either a 0 or 1, compatible with the designation in the .hdr file 0 = non-PC, 1 = PC. --------------------------------------------------------*/ -int bf_getarchendian(void) { +int bf_getarchendian(void) +{ int endian; short tmp = 1; char *ctmp; @@ -134,7 +138,8 @@ int bf_getarchendian(void) { return (endian); } /*---------------------------------------------*/ -char *bf_getstemfromname(char *bfname) { +char *bf_getstemfromname(char *bfname) +{ extern int bferr; extern char bfmsg[BFMSGLEN]; int len, stemlen; @@ -162,7 +167,8 @@ char *bf_getstemfromname(char *bfname) { return (stem); } /*---------------------------------------------*/ -int bf_gettypefromname(char *bfname) { +int bf_gettypefromname(char *bfname) +{ extern int bferr; extern char bfmsg[BFMSGLEN]; int len; @@ -192,7 +198,8 @@ int bf_gettypefromname(char *bfname) { } /*---------------------------------------------*/ -int bf_readheader(char *hdrfile, int *nrows, int *ncols, int *nfrms, int *endian) { +int bf_readheader(char *hdrfile, int *nrows, int *ncols, int *nfrms, int *endian) +{ extern int bferr; extern char bfmsg[BFMSGLEN]; FILE *fp; @@ -218,7 +225,8 @@ int bf_readheader(char *hdrfile, int *nrows, int *ncols, int *nfrms, int *endian return (0); } /*---------------------------------------------*/ -int bf_writeheader(char *hdrfile, int nrows, int ncols, int nfrms, int endian) { +int bf_writeheader(char *hdrfile, int nrows, int ncols, int nfrms, int endian) +{ extern int bferr; extern char bfmsg[BFMSGLEN]; FILE *fp; @@ -241,7 +249,8 @@ int bf_writeheader(char *hdrfile, int nrows, int ncols, int nfrms, int endian) { return (0); } /*---------------------------------------------*/ -int bf_getbfiledim(char *bfname, int *nrows, int *ncols, int *nfrms, int *endian, int *type) { +int bf_getbfiledim(char *bfname, int *nrows, int *ncols, int *nfrms, int *endian, int *type) +{ char *stem = NULL; char hdrfile[1000]; int err; @@ -263,7 +272,8 @@ int bf_getbfiledim(char *bfname, int *nrows, int *ncols, int *nfrms, int *endian return (0); } /*---------------------------------------------*/ -float *bf_ldbfile(char *bfname, int *nrows, int *ncols, int *nfrms) { +float *bf_ldbfile(char *bfname, int *nrows, int *ncols, int *nfrms) +{ extern int bferr; extern char bfmsg[BFMSGLEN]; short *sdata = NULL; @@ -355,7 +365,8 @@ float *bf_ldbfile(char *bfname, int *nrows, int *ncols, int *nfrms) { return (fdata); } /*---------------------------------------------*/ -int bf_svbfile(float *bfdata, char *bfname, int nrows, int ncols, int nfrms, int svendian) { +int bf_svbfile(float *bfdata, char *bfname, int nrows, int ncols, int nfrms, int svendian) +{ extern int bferr; extern char bfmsg[BFMSGLEN]; char *stem = NULL; @@ -411,7 +422,8 @@ int bf_svbfile(float *bfdata, char *bfname, int nrows, int ncols, int nfrms, int fdatadealloc = 1; memmove(fdata, bfdata, ntot * sizeof(float)); byteswapbuffloat(fdata, ntot * sizeof(float)); - } else + } + else fdata = bfdata; /* write the data to the named file */ @@ -469,7 +481,8 @@ int bf_svbfile(float *bfdata, char *bfname, int nrows, int ncols, int nfrms, int counting the number of stem_%03d.hdr files, starting with 0. ---------------------------------------------------*/ -int bf_getnslices(char *stem) { +int bf_getnslices(char *stem) +{ FILE *fp; int nslices; char bfile[1000]; @@ -494,7 +507,8 @@ int bf_getnslices(char *stem) { based on the extension of stem_000. Returns 0 if the file does not exist. --------------------------------------------------------*/ -int bf_getvoltype(char *stem) { +int bf_getvoltype(char *stem) +{ FILE *fp; char bfile[1000], *ext; @@ -520,7 +534,8 @@ int bf_getvoltype(char *stem) { return (0); } /* -------------------------------------------------------- */ -int bf_getvoldim(char *stem, int *nrows, int *ncols, int *nslcs, int *nfrms, int *endian, int *type) { +int bf_getvoldim(char *stem, int *nrows, int *ncols, int *nslcs, int *nfrms, int *endian, int *type) +{ char hdrfile[1000]; int err; @@ -539,7 +554,8 @@ int bf_getvoldim(char *stem, int *nrows, int *ncols, int *nslcs, int *nfrms, int } /*-----------------------------------------------*/ -int bf_dumpvolinfo(FILE *fp, BF_DATA *bfd) { +int bf_dumpvolinfo(FILE *fp, BF_DATA *bfd) +{ fprintf(fp, "nrows %d \n", bfd->nrows); fprintf(fp, "ncols %d \n", bfd->ncols); fprintf(fp, "nslcs %d \n", bfd->nslcs); @@ -548,7 +564,8 @@ int bf_dumpvolinfo(FILE *fp, BF_DATA *bfd) { } /* ------------------------------------------------- */ -int bf_freebfd(BF_DATA **bfd) { +int bf_freebfd(BF_DATA **bfd) +{ int n; /* Free the data */ @@ -571,7 +588,8 @@ int bf_freebfd(BF_DATA **bfd) { } /* -----------------------------------------------------------*/ -BF_DATA *bf_preallocbfd(int nrows, int ncols, int nslcs, int nfrms) { +BF_DATA *bf_preallocbfd(int nrows, int ncols, int nslcs, int nfrms) +{ BF_DATA *bfd; if (nrows == 0 || ncols == 0 || nslcs == 0 || nfrms == 0) { @@ -602,7 +620,8 @@ BF_DATA *bf_preallocbfd(int nrows, int ncols, int nslcs, int nfrms) { return (bfd); } /* -----------------------------------------------------------*/ -int bf_iswritable(char *fname) { +int bf_iswritable(char *fname) +{ extern int bferr; FILE *fp; char tmpstr[2000]; @@ -616,7 +635,8 @@ int bf_iswritable(char *fname) { return (1); } /* -----------------------------------------------------------*/ -int bf_volume_exists(char *stem) { +int bf_volume_exists(char *stem) +{ char fname[1000]; FILE *fp; @@ -628,7 +648,8 @@ int bf_volume_exists(char *stem) { return (1); } /* -----------------------------------------------------------*/ -int bf_delete_volume(char *stem) { +int bf_delete_volume(char *stem) +{ char fname[1000]; int nrows, ncols, nslcs, nfrms, endian, type; int err, slice; @@ -654,7 +675,8 @@ int bf_delete_volume(char *stem) { return (0); } /* -----------------------------------------------------------*/ -BF_DATA *bf_allocbfd(int nrows, int ncols, int nslcs, int nfrms) { +BF_DATA *bf_allocbfd(int nrows, int ncols, int nslcs, int nfrms) +{ int slice, nperslice; BF_DATA *bfd; @@ -677,7 +699,8 @@ BF_DATA *bf_allocbfd(int nrows, int ncols, int nslcs, int nfrms) { return (bfd); } /*---------------------------------------------------------*/ -BF_DATA *bf_ldvolume(char *stem) { +BF_DATA *bf_ldvolume(char *stem) +{ BF_DATA *bfd; int nrows, ncols, nslcs, nfrms, endian, type; int err, slice; @@ -709,7 +732,8 @@ BF_DATA *bf_ldvolume(char *stem) { return (bfd); } /*---------------------------------------------------------*/ -BF_DATA *bf_ldslice(char *stem, int slice) { +BF_DATA *bf_ldslice(char *stem, int slice) +{ BF_DATA *bfd; int nrows, ncols, nfrms, endian, type; int err; @@ -742,7 +766,8 @@ BF_DATA *bf_ldslice(char *stem, int slice) { return (bfd); } /*---------------------------------------------------------*/ -int bf_svvolume(BF_DATA *bfd, char *stem, int svendian, int svtype) { +int bf_svvolume(BF_DATA *bfd, char *stem, int svendian, int svtype) +{ int err, slice; char bfname[1000], *ext; float *fdata; @@ -769,7 +794,8 @@ int bf_svvolume(BF_DATA *bfd, char *stem, int svendian, int svtype) { return (0); } /*---------------------------------------------------------*/ -int bf_svslice(BF_DATA *bfd, char *stem, int slice, int svendian, int svtype) { +int bf_svslice(BF_DATA *bfd, char *stem, int slice, int svendian, int svtype) +{ int err; char bfname[1000], *ext; float *fdata; @@ -803,7 +829,8 @@ int bf_svslice(BF_DATA *bfd, char *stem, int slice, int svendian, int svtype) { macro, define the macro BF_DEBUG; this will cause BF_GETVAL to point to bf_getval for easier debugging. -------------------------------------------------------------*/ -float bf_getval(BF_DATA *bfd, int r, int c, int s, int f) { +float bf_getval(BF_DATA *bfd, int r, int c, int s, int f) +{ float val; int i; @@ -844,7 +871,8 @@ float bf_getval(BF_DATA *bfd, int r, int c, int s, int f) { macro, define the macro BF_DEBUG; this will cause BF_SETVAL to point to bf_setval for easier debugging. -------------------------------------------------------------*/ -int bf_setval(float val, BF_DATA *bfd, int r, int c, int s, int f) { +int bf_setval(float val, BF_DATA *bfd, int r, int c, int s, int f) +{ int i; if (s < 0 || s >= bfd->nslcs) { @@ -878,7 +906,8 @@ int bf_setval(float val, BF_DATA *bfd, int r, int c, int s, int f) { Computes the index in a slice corresonding to row r, column c, and frame f. -------------------------------------------------------------*/ -int bf_rcf2index(BF_DATA *bfd, int r, int c, int f) { +int bf_rcf2index(BF_DATA *bfd, int r, int c, int f) +{ int index; index = c + r * bfd->ncols + f * bfd->nrowcols; @@ -907,7 +936,8 @@ int bf_index2rcf(BF_DATA *bfd, int index, int *r, int *c, int *f) /* ---------------------------------------------------------- bf_get_minmax() - finds the global minimum and maximum. ----------------------------------------------------------*/ -int bf_get_minmax(BF_DATA *bfd, float *bfdmin, float *bfdmax) { +int bf_get_minmax(BF_DATA *bfd, float *bfdmin, float *bfdmax) +{ int r, c, s, f; float val; @@ -931,7 +961,8 @@ int bf_get_minmax(BF_DATA *bfd, float *bfdmin, float *bfdmax) { bf_rescale() - rescales the data in a bfile data structure to the new min and max. ----------------------------------------------------------*/ -int bf_rescale(BF_DATA *bfd, float min, float max) { +int bf_rescale(BF_DATA *bfd, float min, float max) +{ int r, c, s, f; float val, bfdmin, bfdmax, bfdrange, range; diff --git a/utils/box.c b/utils/box.c index 7a3f618a355..48e68b73030 100644 --- a/utils/box.c +++ b/utils/box.c @@ -37,11 +37,13 @@ #include "macros.h" #include "proto.h" -int BoxPrint(BOX *box, FILE *fp) { +int BoxPrint(BOX *box, FILE *fp) +{ fprintf(fp, "BOX: x: %d --> %d, y: %d --> %d, z: %d --> %d\n", box->x0, box->x1, box->y0, box->y1, box->z0, box->z1); return (NO_ERROR); } -int BoxExpand(BOX *box_src, BOX *box_dst, int dx, int dy, int dz) { +int BoxExpand(BOX *box_src, BOX *box_dst, int dx, int dy, int dz) +{ box_dst->x0 = MAX(box_src->x0 - dx, 0); box_dst->y0 = MAX(box_src->y0 - dy, 0); box_dst->z0 = MAX(box_src->z0 - dz, 0); diff --git a/utils/chklc.c b/utils/chklc.c index 4aa77b6f4b7..d644099f500 100644 --- a/utils/chklc.c +++ b/utils/chklc.c @@ -78,7 +78,8 @@ static const char *permission_msg = " chmod a+r %s\n" "---------------------------------------------------------------------------\n"; -void chklc(void) { +void chklc(void) +{ char dirname[STRLEN], *cp, *alt; FILE *lfile = NULL; char *email; @@ -104,7 +105,8 @@ void chklc(void) { #else exit(-1); #endif - } else { + } + else { strncpy(dirname, cp, STRLEN); } @@ -185,7 +187,8 @@ void chklc(void) { printf("ERROR: crypt() returned null with 4-line file\n"); exit(1); } - } else { + } + else { // We have a 3 line license file. if (Gdiag_no > 0 && first_time) printf("3 line license file\n"); #ifdef Darwin @@ -236,7 +239,8 @@ void chklc(void) { // 1 - passed // // if failed, error msg will be returned in msg. make sure msg is pre-allocated with enough space -int chklc2(char *msg) { +int chklc2(char *msg) +{ char dirname[STRLEN], *cp, *alt; FILE *lfile = NULL; char *email; @@ -261,7 +265,8 @@ int chklc2(char *msg) { #else exit(-1); #endif - } else { + } + else { strncpy(dirname, cp, STRLEN); } @@ -332,7 +337,8 @@ int chklc2(char *msg) { // We have a 4 line license file. strcpy(key, key2); crypt_gkey = crypt(gkey, "FS"); - } else { + } + else { // We have a 3 line license file. #ifdef Darwin // On Darwin systems the key produced with a salt of '*C' @@ -363,7 +369,8 @@ int chklc2(char *msg) { } #ifndef Darwin -void cmp_glib_version(void) { +void cmp_glib_version(void) +{ int i; char *GNU_LIBC_VERSION_MAX = "2.15"; int glibc_max[2], glibc_current[2]; diff --git a/utils/chronometer.c b/utils/chronometer.c index 9d21573f16f..58463ea158a 100644 --- a/utils/chronometer.c +++ b/utils/chronometer.c @@ -21,7 +21,8 @@ static float GetMilliSeconds(const struct timeval t1, const struct timeval t2); // =========================================================== -float GetMilliSeconds(const struct timeval t1, const struct timeval t2) { +float GetMilliSeconds(const struct timeval t1, const struct timeval t2) +{ // Returns the difference in ms between two timevals float secs, musecs, msecs; @@ -35,7 +36,8 @@ float GetMilliSeconds(const struct timeval t1, const struct timeval t2) { // =========================================================== -void InitChronometer(Chronometer *theChronometer) { +void InitChronometer(Chronometer *theChronometer) +{ // Prepares a timer for use theChronometer->running = kStopped; @@ -45,7 +47,8 @@ void InitChronometer(Chronometer *theChronometer) { // =========================================================== -void StartChronometer(Chronometer *theChronometer) { +void StartChronometer(Chronometer *theChronometer) +{ // Starts the timer running // Sanity check @@ -60,7 +63,8 @@ void StartChronometer(Chronometer *theChronometer) { // =========================================================== -void StopChronometer(Chronometer *theChronometer) { +void StopChronometer(Chronometer *theChronometer) +{ // Stops the current timer struct timeval tStop; @@ -80,7 +84,8 @@ void StopChronometer(Chronometer *theChronometer) { // ============================================================ -void ResetChronometer(Chronometer *theChronometer) { +void ResetChronometer(Chronometer *theChronometer) +{ // For the C library, this is a wrapper InitChronometer(theChronometer); @@ -88,7 +93,8 @@ void ResetChronometer(Chronometer *theChronometer) { // ============================================================ -float GetChronometerValue(const Chronometer *theChronometer) { +float GetChronometerValue(const Chronometer *theChronometer) +{ // Returns the time in milliseconds struct timeval now; float msecs; @@ -106,7 +112,8 @@ float GetChronometerValue(const Chronometer *theChronometer) { // ============================================================ -float GetAverageChronometerValue(const Chronometer *theChronometer) { +float GetAverageChronometerValue(const Chronometer *theChronometer) +{ // Returns the time in milliseconds averaged over the number of starts float msecs; diff --git a/utils/chronometerpp.cpp b/utils/chronometerpp.cpp index 02457aa89e4..c874696484e 100644 --- a/utils/chronometerpp.cpp +++ b/utils/chronometerpp.cpp @@ -27,10 +27,12 @@ #include "chronometer.hpp" -namespace SciGPU { -namespace Utilities { - -std::ostream &operator<<(std::ostream &os, const SciGPU::Utilities::Chronometer &timer) { +namespace SciGPU +{ +namespace Utilities +{ +std::ostream &operator<<(std::ostream &os, const SciGPU::Utilities::Chronometer &timer) +{ os << std::setw(9) << std::setprecision(6) << timer.GetAverageTime() << " ms (avg) "; os << std::setw(9) << std::setprecision(6) << timer.GetTime() << " ms (tot)"; diff --git a/utils/class_array.c b/utils/class_array.c index 8270af0935a..141e00bf8c6 100644 --- a/utils/class_array.c +++ b/utils/class_array.c @@ -55,7 +55,8 @@ float **CAbuildTrainingData(VOXEL_LIST *vl_total, MRI **mri_2nd_deriv_s, int wsize, int nscales, - int which_inputs) { + int which_inputs) +{ float **ca_inputs; int i, ninputs; MRI *mri_dtrans_grad; @@ -100,7 +101,8 @@ float *CAbuildInputsAtVoxel(VOXEL_LIST *vl, int wsize, int nscales, float *svm_inputs, - int which_inputs) { + int which_inputs) +{ int s, xk, yk, zk, xi, yi, zi, x, y, z, ninputs, whalf, input; whalf = (wsize - 1) / 2; @@ -165,7 +167,8 @@ float **CAbuildInputs(VOXEL_LIST *vl_total, int which_inputs, int wsize, int nscales, - float *sigmas) { + float *sigmas) +{ float **svm_inputs; MRI *mri_grad[MAX_SCALES], *mri_kernel, *mri_smooth[MAX_SCALES], *mri_laplacian[MAX_SCALES], *mri_dtrans, *mri_2nd_deriv_s[MAX_SCALES]; @@ -206,7 +209,8 @@ float **CAbuildInputs(VOXEL_LIST *vl_total, return (svm_inputs); } -int ca_ninputs(int which_inputs) { +int ca_ninputs(int which_inputs) +{ int num = 0; if (which_inputs & CA_INPUT_INTENSITY) num++; @@ -229,7 +233,8 @@ CA *CAalloc(int width, int nscales, char *c1_name, char *c2_name, - float *sigmas) { + float *sigmas) +{ CLASSIFIER_ATLAS *ca; int x, y, z, o, ninputs; @@ -288,7 +293,8 @@ CA *CAalloc(int width, return (ca); } -int CAtrain(CA *ca, VOXEL_LIST *vl, MRI *mri_norm, MRI *mri_aseg, int source_label, int target_label) { +int CAtrain(CA *ca, VOXEL_LIST *vl, MRI *mri_norm, MRI *mri_aseg, int source_label, int target_label) +{ float *classes, **inputs, nx, ny, nz, mag; int i, xi, yi, zi, o, vertices[3], v; MRI *mri_normals; @@ -355,13 +361,15 @@ int CAtrain(CA *ca, VOXEL_LIST *vl, MRI *mri_norm, MRI *mri_aseg, int source_lab return (NO_ERROR); } -int CAsetSVMparms(CA *ca, double svm_C, double svm_tol, int svm_max_iter) { +int CAsetSVMparms(CA *ca, double svm_C, double svm_tol, int svm_max_iter) +{ ca->svm_C = svm_C; ca->tol = svm_tol; ca->max_iter = svm_max_iter; return (NO_ERROR); } -int CAvoxelToIndex(CA *ca, double x, double y, double z, double *pxd, double *pyd, double *pzd) { +int CAvoxelToIndex(CA *ca, double x, double y, double z, double *pxd, double *pyd, double *pzd) +{ static VECTOR *v1 = NULL, *v2; if (v1 == NULL) { @@ -380,7 +388,8 @@ int CAvoxelToIndex(CA *ca, double x, double y, double z, double *pxd, double *py return (NO_ERROR); } -static int clUpdateStatistics(CA *ca, CLASSIFIER *cl, float *inputs, int output) { +static int clUpdateStatistics(CA *ca, CLASSIFIER *cl, float *inputs, int output) +{ int i; if (cl->c1_means == NULL) { @@ -397,7 +406,8 @@ static int clUpdateStatistics(CA *ca, CLASSIFIER *cl, float *inputs, int output) if (output >= 0) { cl->c1_means[i] += inputs[i]; cl->c1_vars[i] += (inputs[i] * inputs[i]); - } else { + } + else { cl->c2_means[i] += inputs[i]; cl->c2_vars[i] += (inputs[i] * inputs[i]); } @@ -410,7 +420,8 @@ static int clUpdateStatistics(CA *ca, CLASSIFIER *cl, float *inputs, int output) return (NO_ERROR); } -static int clCompleteTraining(CA *ca, CLASSIFIER *cl) { +static int clCompleteTraining(CA *ca, CLASSIFIER *cl) +{ int i; if (cl->c1_ntraining > 0) { @@ -430,7 +441,8 @@ static int clCompleteTraining(CA *ca, CLASSIFIER *cl) { } #define MAX_INPUTS 10000 -int CAcompleteTraining(CA *ca) { +int CAcompleteTraining(CA *ca) +{ int x, y, z, o, i, nvars; double vars[MAX_INPUTS]; CLASSIFIER *cl; @@ -487,7 +499,8 @@ int CAcompleteTraining(CA *ca) { } return (NO_ERROR); } -int CAwrite(CA *ca, char *fname) { +int CAwrite(CA *ca, char *fname) +{ FILE *fp; int i, x, y, z, o; CLASSIFIER *cl; @@ -539,7 +552,8 @@ int CAwrite(CA *ca, char *fname) { fclose(fp); return (NO_ERROR); } -CA *CAread(char *fname) { +CA *CAread(char *fname) +{ CA *ca = NULL; #if 0 float sigmas[MAX_SCALES] ; @@ -552,7 +566,8 @@ CA *CAread(char *fname) { return (ca); } -MRI *CAclassifyBorder(CA *ca, MRI *mri_norm, MRI *mri_aseg, MRI *mri_output, int border, int label) { +MRI *CAclassifyBorder(CA *ca, MRI *mri_norm, MRI *mri_aseg, MRI *mri_output, int border, int label) +{ MRI *mri_border, *mri_tmp = NULL, *mri_normals; int i; VOXEL_LIST *vl; @@ -586,7 +601,8 @@ MRI *CAclassifyBorder(CA *ca, MRI *mri_norm, MRI *mri_aseg, MRI *mri_output, int return (mri_output); } -float CAclassifyVoxel(CA *ca, MRI *mri_normals, int x, int y, int z, float *inputs) { +float CAclassifyVoxel(CA *ca, MRI *mri_normals, int x, int y, int z, float *inputs) +{ double xd, yd, zd, nx, ny, nz, mag, output, c1d, c2d; int xi, yi, zi, o, i; CLASSIFIER *cl; @@ -630,7 +646,8 @@ float CAclassifyVoxel(CA *ca, MRI *mri_normals, int x, int y, int z, float *inpu } return (output); } -static MRI *caComputeSurfaceNormals(MRI *mri_aseg, MRI *mri_normals, int label) { +static MRI *caComputeSurfaceNormals(MRI *mri_aseg, MRI *mri_normals, int label) +{ MRI *mri_tmp, *mri_tmp2, *mri_ctrl; int i; @@ -654,7 +671,8 @@ static MRI *caComputeSurfaceNormals(MRI *mri_aseg, MRI *mri_normals, int label) return (mri_normals); } static MATRIX *compute_ras_basis_vectors( - MRI *mri_aseg_orig, MRI *mri_aseg_edit, int label, int width, int height, int depth, int pad) { + MRI *mri_aseg_orig, MRI *mri_aseg_edit, int label, int width, int height, int depth, int pad) +{ MRI_REGION box1, box2, box; MRI *mri_aligned, *mri_tmp; MATRIX *m_xform, *m_trans, *m_tmp, *m_id, *m_inv, *m_targ, *m_src, *m_tmp2, *m_evectors; diff --git a/utils/cluster.c b/utils/cluster.c index 3719c85ad5c..cda890175d0 100644 --- a/utils/cluster.c +++ b/utils/cluster.c @@ -85,7 +85,8 @@ static int normalizeObservation(CLUSTER_SET *cs, VECTOR *v_obs) ; Description Print the contents of a CLUSTER_SET to a file. ------------------------------------------------------*/ -int CSprint(CLUSTER_SET *cs, FILE *fp) { +int CSprint(CLUSTER_SET *cs, FILE *fp) +{ int c; fprintf(fp, @@ -114,7 +115,8 @@ int CSprint(CLUSTER_SET *cs, FILE *fp) { allocate and initialize a CLUSTER_SET structure in preparation for clustering a data set. ------------------------------------------------------*/ -CLUSTER_SET *CSinit(int max_clusters, int ninputs, int normalize) { +CLUSTER_SET *CSinit(int max_clusters, int ninputs, int normalize) +{ CLUSTER_SET *cs; int c; @@ -157,7 +159,8 @@ CLUSTER_SET *CSinit(int max_clusters, int ninputs, int normalize) { Free a CLUSTER_SET structure and all memory that it has allocated. ------------------------------------------------------*/ -int CSfree(CLUSTER_SET **pcs) { +int CSfree(CLUSTER_SET **pcs) +{ CLUSTER_SET *cs; int c; @@ -183,7 +186,8 @@ int CSfree(CLUSTER_SET **pcs) { allocate the internal variables of the given cluster and initialize them to reasonable values. ------------------------------------------------------*/ -static int clusterInit(CLUSTER *cluster, int ninputs) { +static int clusterInit(CLUSTER *cluster, int ninputs) +{ cluster->m_scatter = MatrixAlloc(ninputs, ninputs, MATRIX_REAL); if (!cluster->m_scatter) ErrorExit(ERROR_NO_MEMORY, "clusterInit(%d): could not allocate scatter matrix", ninputs); cluster->v_means = VectorAlloc(ninputs, MATRIX_REAL); @@ -204,7 +208,8 @@ static int clusterInit(CLUSTER *cluster, int ninputs) { Free a CLUSTER structure and all memory that it has allocated. ------------------------------------------------------*/ -static int clusterFree(CLUSTER *cluster) { +static int clusterFree(CLUSTER *cluster) +{ if (cluster->m_scatter) MatrixFree(&cluster->m_scatter); if (cluster->v_means) VectorFree(&cluster->v_means); if (cluster->evalues) free(cluster->evalues); @@ -219,7 +224,8 @@ static int clusterFree(CLUSTER *cluster) { Description Add this observation to the appropriate cluster. ------------------------------------------------------*/ -int CSnewObservation(CLUSTER_SET *cs, VECTOR *v_obs) { +int CSnewObservation(CLUSTER_SET *cs, VECTOR *v_obs) +{ int c, min_cluster; float min_dist, dist; @@ -247,7 +253,8 @@ int CSnewObservation(CLUSTER_SET *cs, VECTOR *v_obs) { A pass has just been made through the data set, divide the cluster with the maximum variance. ------------------------------------------------------*/ -int CSdivide(CLUSTER_SET *cs) { +int CSdivide(CLUSTER_SET *cs) +{ int c, max_cluster, nobs, max_obs; float max_variance, variance; @@ -292,7 +299,8 @@ int CSdivide(CLUSTER_SET *cs) { Description Add this observation to the appropriate cluster. ------------------------------------------------------*/ -static int clusterNewObservation(CLUSTER *cluster, VECTOR *v_obs) { +static int clusterNewObservation(CLUSTER *cluster, VECTOR *v_obs) +{ float covariance; int row, col; @@ -316,7 +324,8 @@ static int clusterNewObservation(CLUSTER *cluster, VECTOR *v_obs) { Determine the distance from this cluster to the observation vector. ------------------------------------------------------*/ -static float clusterDistance(CLUSTER_SET *cs, CLUSTER *cluster, VECTOR *v_obs) { +static float clusterDistance(CLUSTER_SET *cs, CLUSTER *cluster, VECTOR *v_obs) +{ float dist, mean, sigma, v1, v2, d; int row; @@ -350,7 +359,8 @@ static float clusterDistance(CLUSTER_SET *cs, CLUSTER *cluster, VECTOR *v_obs) { a round of observations is done - complete the calculation of means and scatter matrices for this cluster ------------------------------------------------------*/ -static int clusterComputeStatistics(CLUSTER_SET *cs, CLUSTER *cluster) { +static int clusterComputeStatistics(CLUSTER_SET *cs, CLUSTER *cluster) +{ float mean_a, mean_b, covariance; int nobs, row, col; @@ -380,14 +390,16 @@ static int clusterComputeStatistics(CLUSTER_SET *cs, CLUSTER *cluster) { { MatrixRegularize(cluster->m_scatter, cluster->m_scatter); cluster->m_inverse = MatrixInverse(cluster->m_scatter, cluster->m_inverse); - } else + } + else cluster->m_inverse = MatrixSVDInverse(cluster->m_scatter, cluster->m_inverse); cluster->det = MatrixDeterminant(cluster->m_scatter); if (cluster->det <= 0.0f) cluster->norm = 1.0f; /* no good choice */ else cluster->norm = 1.0f / sqrt(cluster->det); - } else { + } + else { cluster->ill_conditioned = 0; cluster->m_inverse = MatrixInverse(cluster->m_scatter, cluster->m_inverse); cluster->norm = 1.0f / sqrt(cluster->det); @@ -412,7 +424,8 @@ static int clusterComputeStatistics(CLUSTER_SET *cs, CLUSTER *cluster) { fprintf(stderr, "inverse scatter matrix:\n") ; MatrixPrint(stderr, cluster->m_inverse) ; #endif - } else + } + else return (ERROR_BADPARM); #if 0 ErrorReturn(ERROR_BADPARM, @@ -440,7 +453,8 @@ static int clusterComputeStatistics(CLUSTER_SET *cs, CLUSTER *cluster) { Description Print the contents of a cluster to a file. ------------------------------------------------------*/ -static int clusterPrint(CLUSTER *cluster, FILE *fp) { +static int clusterPrint(CLUSTER *cluster, FILE *fp) +{ /* int i ;*/ fprintf(fp, "cluster %d has %d observations. Seed:", cluster->cno, cluster->nsamples); @@ -471,7 +485,8 @@ static int clusterPrint(CLUSTER *cluster, FILE *fp) { Compute the variance of this cluster to decide whether (and how) it should be split. ------------------------------------------------------*/ -static float clusterVariance(CLUSTER *cluster) { +static float clusterVariance(CLUSTER *cluster) +{ float variance; int i; @@ -490,7 +505,8 @@ static float clusterVariance(CLUSTER *cluster) { ------------------------------------------------------*/ #define SMALL 1e-4 -static CLUSTER *clusterDivide(CLUSTER *csrc, CLUSTER *cdst) { +static CLUSTER *clusterDivide(CLUSTER *csrc, CLUSTER *cdst) +{ VECTOR *v_e; float len; @@ -547,7 +563,8 @@ static CLUSTER *clusterDivide(CLUSTER *csrc, CLUSTER *cdst) { inverse of the within-cluster scatter matrix, and Sb is the between cluster scatter matrix. ------------------------------------------------------*/ -int CScluster(CLUSTER_SET *cs, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm), void *parm) { +int CScluster(CLUSTER_SET *cs, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm), void *parm) +{ int obs_no, epoch = 0; VECTOR *v_obs; @@ -603,7 +620,8 @@ int CScluster(CLUSTER_SET *cs, int (*get_observation_func)(VECTOR *v_obs, int no Go through all the clusters and clear their mean and scatter matrices. ------------------------------------------------------*/ -int CSreset(CLUSTER_SET *cs) { +int CSreset(CLUSTER_SET *cs) +{ int c; CLUSTER *cluster; @@ -625,7 +643,8 @@ int CSreset(CLUSTER_SET *cs) { Compute the covariances and means of all the clusters (performed after each complete pass through the data). ------------------------------------------------------*/ -int CScomputeStatistics(CLUSTER_SET *cs) { +int CScomputeStatistics(CLUSTER_SET *cs) +{ int c, c1; for (c = 0; c < cs->nclusters; c++) @@ -652,7 +671,8 @@ int CScomputeStatistics(CLUSTER_SET *cs) { ------------------------------------------------------*/ int CScomputeDimensionStatistics(CLUSTER_SET *cs, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm), - void *parm) { + void *parm) +{ int obs_no = 0, i; VECTOR *v_obs; float v, mean; @@ -715,7 +735,8 @@ normalizeObservation(CLUSTER_SET *cs, VECTOR *v_obs) clusters are represented in terms of the original measurement spaces. ------------------------------------------------------*/ -int CSrenormalize(CLUSTER_SET *cs) { +int CSrenormalize(CLUSTER_SET *cs) +{ int c, row; CLUSTER *cluster; float mean, sigma; @@ -742,7 +763,8 @@ int CSrenormalize(CLUSTER_SET *cs) { Write a CLUSTER_SET and all it's associated parameters into the specified file. ------------------------------------------------------*/ -int CSwriteInto(FILE *fp, CLUSTER_SET *cs) { +int CSwriteInto(FILE *fp, CLUSTER_SET *cs) +{ int i; fprintf( @@ -771,7 +793,8 @@ int CSwriteInto(FILE *fp, CLUSTER_SET *cs) { associated parameters into the specified file. ------------------------------------------------------*/ -CLUSTER_SET *CSreadFrom(FILE *fp, CLUSTER_SET *cs) { +CLUSTER_SET *CSreadFrom(FILE *fp, CLUSTER_SET *cs) +{ int i, ninputs, max_clusters, normalize, nobs, nsamples, nclusters; char *cp, line[200]; @@ -785,7 +808,8 @@ CLUSTER_SET *CSreadFrom(FILE *fp, CLUSTER_SET *cs) { cs->ninputs = ninputs; cs->max_clusters = max_clusters; cs->normalize = normalize; - } else + } + else cs = CSinit(max_clusters, ninputs, normalize); cs->nobs = nobs; @@ -819,7 +843,8 @@ CLUSTER_SET *CSreadFrom(FILE *fp, CLUSTER_SET *cs) { Write a CLUSTER_SET and all it's associated parameters into the specified file. ------------------------------------------------------*/ -static int clusterWriteInto(FILE *fp, CLUSTER *cluster) { +static int clusterWriteInto(FILE *fp, CLUSTER *cluster) +{ fprintf(fp, "\n# cluster %d (nobs, nsamples, cno, det)\n", cluster->cno); fprintf(fp, "%d %d %d %f\n", cluster->nobs, cluster->nsamples, cluster->cno, cluster->det); fprintf(fp, "# scatter matrix:\n"); @@ -842,7 +867,8 @@ static int clusterWriteInto(FILE *fp, CLUSTER *cluster) { associated parameters into the specified file. ------------------------------------------------------*/ -static CLUSTER *clusterReadFrom(FILE *fp, CLUSTER *cluster) { +static CLUSTER *clusterReadFrom(FILE *fp, CLUSTER *cluster) +{ char *cp, line[200]; cp = fgetl(line, 199, fp); @@ -867,14 +893,16 @@ static CLUSTER *clusterReadFrom(FILE *fp, CLUSTER *cluster) { { MatrixRegularize(cluster->m_scatter, cluster->m_scatter); cluster->m_inverse = MatrixInverse(cluster->m_scatter, cluster->m_inverse); - } else + } + else cluster->m_inverse = MatrixSVDInverse(cluster->m_scatter, cluster->m_inverse); cluster->det = MatrixDeterminant(cluster->m_scatter); if (cluster->det <= 0.0f) cluster->norm = 1.0f; /* no good choice */ else cluster->norm = 1.0f / sqrt(cluster->det); - } else { + } + else { cluster->norm = 1.0f / sqrt(cluster->det); cluster->ill_conditioned = 0; cluster->m_inverse = MatrixInverse(cluster->m_scatter, cluster->m_inverse); @@ -900,7 +928,8 @@ static CLUSTER *clusterReadFrom(FILE *fp, CLUSTER *cluster) { Description Copy the data from one cluster into another. ------------------------------------------------------*/ -static int clusterCopy(CLUSTER *csrc, CLUSTER *cdst) { +static int clusterCopy(CLUSTER *csrc, CLUSTER *cdst) +{ MatrixCopy(csrc->m_scatter, cdst->m_scatter); if (csrc->m_inverse) MatrixCopy(csrc->m_inverse, cdst->m_inverse); if (csrc->m_evectors) MatrixCopy(csrc->m_evectors, cdst->m_evectors); diff --git a/utils/cma.c b/utils/cma.c index 2bb23e9ddec..30277af07e7 100644 --- a/utils/cma.c +++ b/utils/cma.c @@ -48,7 +48,8 @@ extern int errno; -int CMAfreeOutlineField(CMAoutlineField **of) { +int CMAfreeOutlineField(CMAoutlineField **of) +{ CMAoutlineField *ofp; int i; @@ -81,7 +82,8 @@ int CMAfreeOutlineField(CMAoutlineField **of) { } /* end CMAfreeOutlineField() */ -CMAoutlineField *CMAoutlineFieldAlloc(int width, int height) { +CMAoutlineField *CMAoutlineFieldAlloc(int width, int height) +{ CMAoutlineField *of; int i; @@ -146,7 +148,8 @@ CMAoutlineField *CMAoutlineFieldAlloc(int width, int height) { } /* end CMAoutlineFieldAlloc() */ -int CMAclearFillField(CMAoutlineField *field) { +int CMAclearFillField(CMAoutlineField *field) +{ int i; for (i = 0; i < field->height; i++) @@ -158,7 +161,8 @@ int CMAclearFillField(CMAoutlineField *field) { } /* end CMAclearFillField() */ /* fills with CMA_FILL_INTERIOR to non-zero values */ -int CMAfill(CMAoutlineField *field, short seed_x, short seed_y) { +int CMAfill(CMAoutlineField *field, short seed_x, short seed_y) +{ if (seed_x < 0 || seed_x >= field->width) return (NO_ERROR); if (seed_y < 0 || seed_y >= field->height) return (NO_ERROR); @@ -176,7 +180,8 @@ int CMAfill(CMAoutlineField *field, short seed_x, short seed_y) { } /* end CMAfill() */ -int CMAclaimPoints(CMAoutlineField *field, short label, short *points, int n_points, short seed_x, short seed_y) { +int CMAclaimPoints(CMAoutlineField *field, short label, short *points, int n_points, short seed_x, short seed_y) +{ int i, j; short x, y; @@ -237,21 +242,24 @@ int CMAclaimPoints(CMAoutlineField *field, short label, short *points, int n_poi } /* end CMAclaimPoints() */ -int CMAvalueClaims(CMAoutlineClaim *claim) { +int CMAvalueClaims(CMAoutlineClaim *claim) +{ int i; for (i = 0; i < MAX_OUTLINE_CLAIMS; i++) claim->claim_values[i] = 0.0; if (claim->n_claims == 0) { claim->no_label_claim = 0.5; - } else if (claim->n_claims == 1) { + } + else if (claim->n_claims == 1) { if (claim->interior_claim_flag == 1) claim->claim_values[0] = 1.0; else { claim->claim_values[0] = 0.5; claim->no_label_claim = 0.5; } - } else { + } + else { float ct = 1.0 / (float)claim->n_claims; for (i = 0; i < claim->n_claims; i++) claim->claim_values[i] = ct; } @@ -260,7 +268,8 @@ int CMAvalueClaims(CMAoutlineClaim *claim) { } /* end CMAvalueClaims() */ -int CMAvalueAllClaims(CMAoutlineField *field) { +int CMAvalueAllClaims(CMAoutlineField *field) +{ int i, j; for (i = 0; i < field->width; i++) @@ -270,7 +279,8 @@ int CMAvalueAllClaims(CMAoutlineField *field) { } /* end CMAvalueAllClaims() */ -int CMAaddWeightedTotals(CMAoutlineClaim *claim, float weight, float *claim_totals) { +int CMAaddWeightedTotals(CMAoutlineClaim *claim, float weight, float *claim_totals) +{ int i; /* we've checked the label range in CMAclaimPoints() */ @@ -284,7 +294,8 @@ int CMAaddWeightedTotals(CMAoutlineClaim *claim, float weight, float *claim_tota } /* end CMAaddWeightedTotals() */ /* returns the label with the greatest claim to a given pixel */ -short CMAtotalClaims(CMAoutlineField *field, int x, int y) { +short CMAtotalClaims(CMAoutlineField *field, int x, int y) +{ float claim_totals[MAX_CMA_LABEL + 1]; float best_claim; short best_index; @@ -331,7 +342,8 @@ short CMAtotalClaims(CMAoutlineField *field, int x, int y) { } /* end CMAtotalClaims() */ -int CMAassignLabels(CMAoutlineField *field) { +int CMAassignLabels(CMAoutlineField *field) +{ int i, j; CMAclearFillField(field); @@ -345,7 +357,8 @@ int CMAassignLabels(CMAoutlineField *field) { } /* end CMAassignLabels() */ -int CMAzeroOutlines(CMAoutlineField *field) { +int CMAzeroOutlines(CMAoutlineField *field) +{ int i, j; for (i = 0; i < field->width; i++) @@ -360,8 +373,8 @@ int CMAzeroOutlines(CMAoutlineField *field) { #include "error.h" #include "macros.h" #include "mrisurf.h" -int insert_ribbon_into_aseg( - MRI *mri_src_aseg, MRI *mri_aseg, MRI_SURFACE *mris_white, MRI_SURFACE *mris_pial, int hemi) { +int insert_ribbon_into_aseg(MRI *mri_src_aseg, MRI *mri_aseg, MRI_SURFACE *mris_white, MRI_SURFACE *mris_pial, int hemi) +{ MRI *mri_ribbon, *mri_white; int x, y, z, gm_label, wm_label, label, nbr_label, dont_change; @@ -422,13 +435,15 @@ int insert_ribbon_into_aseg( } if (dont_change == 0) MRIsetVoxVal(mri_aseg, x, y, z, 0, gm_label); } - } else // not in ribbon + } + else // not in ribbon { if (MRIgetVoxVal(mri_white, x, y, z, 0) > 0) // inside white surface - disambiguate { if (label == gm_label) // gm inside white surface should be wm MRIsetVoxVal(mri_aseg, x, y, z, 0, wm_label); - } else if (label == gm_label) // gm outside ribbon should be unknown + } + else if (label == gm_label) // gm outside ribbon should be unknown MRIsetVoxVal(mri_aseg, x, y, z, 0, Unknown); } } @@ -448,7 +463,8 @@ int insert_ribbon_into_aseg( subcortical gray does not include brainstem or cerebellum cortex. \param SegId - segmentation id number */ -int IsSubCorticalGray(int SegId) { +int IsSubCorticalGray(int SegId) +{ if (SegId == Left_Thalamus) return (1); if (SegId == Right_Thalamus) return (1); if (SegId == Left_Thalamus_Proper) return (1); @@ -486,7 +502,8 @@ everything else. Note that there is no partial volume correction. \param ribbon is the ribbon.mgz, which has non-zero values for everything inside the pial surf. */ -double SupraTentorialVolCorrection(MRI *aseg, MRI *ribbon) { +double SupraTentorialVolCorrection(MRI *aseg, MRI *ribbon) +{ int c, r, s, SegId; double vol = 0; int RibbonVal, VoxSize; @@ -559,7 +576,8 @@ pial. \param ribbon - ribbon \param hemi - 1=left, 2=right */ -double CorticalGMVolCorrection(MRI *aseg, MRI *ribbon, int hemi) { +double CorticalGMVolCorrection(MRI *aseg, MRI *ribbon, int hemi) +{ int c, r, s, SegId; double vol = 0, vol2 = 0; int RibbonVal, VoxSize; @@ -644,7 +662,8 @@ fail. It only changes the voxel values and has no effect on the volume geometry. \param aseg - segmentation */ -MRI *MRIlrswapAseg(MRI *aseg) { +MRI *MRIlrswapAseg(MRI *aseg) +{ MRI *asegswap; int c, r, s, id, id2; @@ -910,7 +929,8 @@ with ribbon values if the aseg is CtxGM or CtxWM or unknown. \param aseg - aseg.mgz segmentation \param ribbon - ribbon.mgz segmentation */ -MRI *MRIfixAsegWithRibbon(MRI *aseg, MRI *ribbon, MRI *asegfixed) { +MRI *MRIfixAsegWithRibbon(MRI *aseg, MRI *ribbon, MRI *asegfixed) +{ int c, r, s, asegid, ribbonid; asegfixed = MRIcopy(aseg, asegfixed); @@ -940,7 +960,8 @@ surface-based analysis. It also computes the same values based on volume-based analysis to check against the surface-based results. \param subject */ -double *ComputeBrainVolumeStats(char *subject, char *suffix, char *sdir) { +double *ComputeBrainVolumeStats(char *subject, char *suffix, char *sdir) +{ char tmpstr[2000]; char *SUBJECTS_DIR; MRI *aseg, *ribbon, *asegfixed, *brainmask; @@ -1007,7 +1028,8 @@ double *ComputeBrainVolumeStats(char *subject, char *suffix, char *sdir) { if (ribbon == NULL) return (NULL); asegfixed = MRIfixAsegWithRibbon(aseg, ribbon, NULL); ribbonRead = 1; - } else { + } + else { printf("WARNING: %s does not exist, ribbon based measurements will be inaccurate\n", tmpstr); ribbon = aseg; asegfixed = aseg; @@ -1208,7 +1230,8 @@ double *ComputeBrainVolumeStats(char *subject, char *suffix, char *sdir) { \brief Creates a segmentation volume where the segmentation is that of tissue type (tissue type info in the ctab). */ -MRI *MRIseg2TissueType(MRI *seg, COLOR_TABLE *ct, MRI *tt) { +MRI *MRIseg2TissueType(MRI *seg, COLOR_TABLE *ct, MRI *tt) +{ int c, r, s, segid; if (ct->ctabTissueType == NULL) { @@ -1244,7 +1267,8 @@ MRI *MRIseg2TissueType(MRI *seg, COLOR_TABLE *ct, MRI *tt) { \brief Creates a volume with only the segmentations in the given tissue type. Tissue type info in the ctab. */ -MRI *MRIextractTissueTypeSeg(MRI *seg, COLOR_TABLE *ct, int tt, MRI *ttseg) { +MRI *MRIextractTissueTypeSeg(MRI *seg, COLOR_TABLE *ct, int tt, MRI *ttseg) +{ int c, r, s, segid; if (ct->ctabTissueType == NULL) { @@ -1286,7 +1310,8 @@ MRI *MRIextractTissueTypeSeg(MRI *seg, COLOR_TABLE *ct, int tt, MRI *ttseg) { each entry. \return 0 if no error, 1 if error */ -int CheckSegTissueType(MRI *seg, COLOR_TABLE *ct) { +int CheckSegTissueType(MRI *seg, COLOR_TABLE *ct) +{ int c, r, s, n, segid, err; err = 1; @@ -1326,7 +1351,8 @@ int CheckSegTissueType(MRI *seg, COLOR_TABLE *ct) { fill in voxels from the masked out tissue types. This technique is used for GTM partial volume correction. Tissue type info in the ctab. */ -MRI **MRIdilateSegWithinTT(MRI *seg, int nDils, COLOR_TABLE *ct, MRI **r) { +MRI **MRIdilateSegWithinTT(MRI *seg, int nDils, COLOR_TABLE *ct, MRI **r) +{ MRI *segtt = NULL; int nc, tt; // char tmpstr[1000]; @@ -1358,7 +1384,8 @@ MRI **MRIdilateSegWithinTT(MRI *seg, int nDils, COLOR_TABLE *ct, MRI **r) { structure and performs GTMdefaultSegReplacmentList(). Writes out stats. */ -int Seg2NbrNonBrainWrapper(char *subject, char *segname, COLOR_TABLE *ctab, char *statname, double threshmm) { +int Seg2NbrNonBrainWrapper(char *subject, char *segname, COLOR_TABLE *ctab, char *statname, double threshmm) +{ char *SUBJECTS_DIR, tmpstr[2000]; MRI *seg, *mritmp; int nReplace, SrcReplace[1000], TrgReplace[1000]; @@ -1411,7 +1438,8 @@ int Seg2NbrNonBrainWrapper(char *subject, char *segname, COLOR_TABLE *ctab, char PrintSegStat(fp, segstat). Note that a single non-brain voxel may be counted multiple times. */ -SEGSTAT *Seg2NbrNonBrain(MRI *seg, COLOR_TABLE *ctab, double threshmm) { +SEGSTAT *Seg2NbrNonBrain(MRI *seg, COLOR_TABLE *ctab, double threshmm) +{ int c, r, s, cB, rB, sB, nthseg, segno, segnoB, FreeCTab; int *segnolist, *count, *segcount, nsegs; double threshvox, d2, dc2, dr2, dc, dr, ds, voxsize, threshmm2; diff --git a/utils/cmat.c b/utils/cmat.c index deae51922fb..fd44f75708b 100644 --- a/utils/cmat.c +++ b/utils/cmat.c @@ -33,7 +33,8 @@ #include "cmat.h" #include "error.h" -CMAT *CMATread(const char *fname) { +CMAT *CMATread(const char *fname) +{ CMAT *cmat; int nlabels, i, j, ind1, ind2; FILE *fp; @@ -86,7 +87,8 @@ CMAT *CMATread(const char *fname) { return (cmat); } -int CMATwrite(CMAT *cmat, const char *fname) { +int CMATwrite(CMAT *cmat, const char *fname) +{ FILE *fp; int i, j; @@ -110,7 +112,8 @@ int CMATwrite(CMAT *cmat, const char *fname) { return (NO_ERROR); } -CMAT *CMATalloc(int nlabels, int *labels) { +CMAT *CMATalloc(int nlabels, int *labels) +{ CMAT *cmat; int i; @@ -138,7 +141,8 @@ CMAT *CMATalloc(int nlabels, int *labels) { return (cmat); } -int CMATfree(CMAT **pcmat) { +int CMATfree(CMAT **pcmat) +{ CMAT *cmat; int i, j; @@ -159,7 +163,8 @@ int CMATfree(CMAT **pcmat) { free(cmat); return (NO_ERROR); } -CMAT *CMATtransform(CMAT *csrc, TRANSFORM *xform, MRI *mri_src, MRI *mri_dst, CMAT *cdst) { +CMAT *CMATtransform(CMAT *csrc, TRANSFORM *xform, MRI *mri_src, MRI *mri_dst, CMAT *cdst) +{ int i, j; cdst = CMATalloc(csrc->nlabels, csrc->labels); @@ -175,7 +180,8 @@ CMAT *CMATtransform(CMAT *csrc, TRANSFORM *xform, MRI *mri_src, MRI *mri_dst, CM return (cdst); } -int CMATtoVoxel(CMAT *cmat, MRI *mri) { +int CMATtoVoxel(CMAT *cmat, MRI *mri) +{ int i, j; cmat->coords = LABEL_COORDS_VOXEL; @@ -190,7 +196,8 @@ int CMATtoVoxel(CMAT *cmat, MRI *mri) { return (NO_ERROR); } -int CMATtoTKreg(CMAT *cmat, MRI *mri) { +int CMATtoTKreg(CMAT *cmat, MRI *mri) +{ int i, j; cmat->coords = LABEL_COORDS_TKREG_RAS; @@ -205,7 +212,8 @@ int CMATtoTKreg(CMAT *cmat, MRI *mri) { return (NO_ERROR); } -int CMATtoScannerRAS(CMAT *cmat, MRI *mri) { +int CMATtoScannerRAS(CMAT *cmat, MRI *mri) +{ int i, j; cmat->coords = LABEL_COORDS_SCANNER_RAS; diff --git a/utils/cmdargs.c b/utils/cmdargs.c index d5ec53c422c..61ea993c742 100644 --- a/utils/cmdargs.c +++ b/utils/cmdargs.c @@ -39,7 +39,8 @@ const char *CMDSrcVersion(void) { return ("$Id: cmdargs.c,v 1.3 2011/03/02 00:04 CMDargNErr() - prints a msg as to the number of arguments needed by a flag and then exits. ------------------------------------------------------------------------ */ -void CMDargNErr(char *option, int n) { +void CMDargNErr(char *option, int n) +{ if (n == 1) fprintf(stderr, "ERROR: %s flag needs %d argument\n", option, n); else @@ -50,7 +51,8 @@ void CMDargNErr(char *option, int n) { CMDisFlag() - returns 1 if the arg string starts with a double-dash. The double-dash, ie, "--" indicates that the arg is a flag. ---------------------------------------------------------------*/ -int CMDisFlag(char *arg) { +int CMDisFlag(char *arg) +{ int len; len = strlen(arg); if (len < 2) return (0); @@ -63,7 +65,8 @@ int CMDisFlag(char *arg) { "-". This often happens when the user accidentally specifies a flag with a single dash instead of a double-dash. -----------------------------------------------------------------------*/ -int CMDsingleDash(char *arg) { +int CMDsingleDash(char *arg) +{ int len; len = strlen(arg); if (len < 2) return (0); @@ -76,7 +79,8 @@ int CMDsingleDash(char *arg) { it does NOT start with a double-dash). This is good for reading in a variable number of arguments for a flag. nth is 0-based. ---------------------------------------------------------------*/ -int CMDnthIsArg(int nargc, char **argv, int nth) { +int CMDnthIsArg(int nargc, char **argv, int nth) +{ /* check that there are enough args for nth to exist */ if (nargc <= nth) return (0); /* check whether the nth arg is a flag */ @@ -86,7 +90,8 @@ int CMDnthIsArg(int nargc, char **argv, int nth) { /*------------------------------------------------------------ CMDstringMatch() - returns 1 if the two strings match ------------------------------------------------------------*/ -int CMDstringMatch(char *str1, char *str2) { +int CMDstringMatch(char *str1, char *str2) +{ if (str1 == NULL && str2 != NULL) return (0); if (str2 == NULL && str1 != NULL) return (0); if (!strcmp(str1, str2)) return (1); @@ -101,7 +106,8 @@ int CMDprintUsage(FILE *fp, char *ProgName) { return (0); } /*------------------------------------------------------------ CMDusageExit() - same as CMDprintUsage() but exits. ------------------------------------------------------------*/ -int CMDusageExit(char *ProgName) { +int CMDusageExit(char *ProgName) +{ CMDprintUsage(stdout, ProgName); exit(1); } diff --git a/utils/colortab.c b/utils/colortab.c index 52e364d6aec..8e34f7ca312 100644 --- a/utils/colortab.c +++ b/utils/colortab.c @@ -61,7 +61,8 @@ Reads in 7th column as tissue type COLOR_TABLE *CTABreadASCII(const char *fname) { return CTABreadASCII2(fname, 1); } -COLOR_TABLE *CTABreadASCII2(const char *fname, int checkDuplicateNames) { +COLOR_TABLE *CTABreadASCII2(const char *fname, int checkDuplicateNames) +{ COLOR_TABLE *ct; char line[STRLEN], *cp; int max_structure; @@ -132,7 +133,8 @@ COLOR_TABLE *CTABreadASCII2(const char *fname, int checkDuplicateNames) { ct->entries[structure]->bi, ct->entries[structure]->ai); ctabDuplicates++; - } else { + } + else { /* Try to create a new entry.*/ ct->entries[structure] = (CTE *)malloc(sizeof(CTE)); if (NULL == ct->entries[structure]) { @@ -180,7 +182,8 @@ COLOR_TABLE *CTABreadASCII2(const char *fname, int checkDuplicateNames) { \brief reads tissue type from header of a ctab (line that start with #ctTType) as written by CTABwriteFileASCIItt(). */ -COLOR_TABLE *CTABreadASCIIttHeader(const char *fname) { +COLOR_TABLE *CTABreadASCIIttHeader(const char *fname) +{ FILE *fp; COLOR_TABLE *ct = NULL; int nct, ni, segid, segidmax; @@ -252,7 +255,8 @@ COLOR_TABLE *CTABreadASCIIttHeader(const char *fname) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABfree(COLOR_TABLE **pct) { +int CTABfree(COLOR_TABLE **pct) +{ int i; COLOR_TABLE *ct; @@ -278,7 +282,8 @@ int CTABfree(COLOR_TABLE **pct) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -COLOR_TABLE *CTABdeepCopy(COLOR_TABLE *ct) { +COLOR_TABLE *CTABdeepCopy(COLOR_TABLE *ct) +{ COLOR_TABLE *copy; int structure; @@ -338,7 +343,8 @@ COLOR_TABLE *CTABdeepCopy(COLOR_TABLE *ct) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -COLOR_TABLE *CTABreadFromBinary(FILE *fp) { +COLOR_TABLE *CTABreadFromBinary(FILE *fp) +{ COLOR_TABLE *ct; int version; @@ -355,14 +361,16 @@ COLOR_TABLE *CTABreadFromBinary(FILE *fp) { /* With v1, we pass in the "version" number we just got, as it's the number of entries. */ ct = CTABreadFromBinaryV1(fp, version); - } else { + } + else { /* Take the negative to get the real version number. */ version = -version; /* Read the right version. */ if (version == 2) { ct = CTABreadFromBinaryV2(fp); - } else { + } + else { /* Unsupported version. */ ErrorReturn(NULL, (ERROR_BADFILE, "CTABreadFromBinary: unknown version")); } @@ -373,7 +381,8 @@ COLOR_TABLE *CTABreadFromBinary(FILE *fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABwriteIntoBinary(COLOR_TABLE *ct, FILE *fp) { +int CTABwriteIntoBinary(COLOR_TABLE *ct, FILE *fp) +{ int result; if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABwriteIntoBinary: ct was NULL")); @@ -402,7 +411,8 @@ int CTABwriteIntoBinary(COLOR_TABLE *ct, FILE *fp) { this function which uses a brute force search to over 10 max iterations to find a unique set. */ -COLOR_TABLE *CTABalloc(int nentries) { +COLOR_TABLE *CTABalloc(int nentries) +{ COLOR_TABLE *ct; int structure; @@ -475,7 +485,8 @@ COLOR_TABLE *CTABalloc(int nentries) { entries. This is just a brute force search over at most nmax tries to find a set that are unique. */ -int CTABunique(COLOR_TABLE *ct, int nmax) { +int CTABunique(COLOR_TABLE *ct, int nmax) +{ int n; n = 0; while (n < nmax) { @@ -494,7 +505,8 @@ int CTABunique(COLOR_TABLE *ct, int nmax) { \fn int CTABcountRepeats(COLOR_TABLE *ct) \brief Returns the number of pairs of entries that have the same RGB */ -int CTABcountRepeats(COLOR_TABLE *ct) { +int CTABcountRepeats(COLOR_TABLE *ct) +{ int i, j, nrepeats; nrepeats = 0; for (i = 0; i < ct->nentries; i++) { @@ -515,7 +527,8 @@ int CTABcountRepeats(COLOR_TABLE *ct) { \fn int CTABrandom(COLOR_TABLE *ct) \brief Fills an already allocated color table with random colors */ -int CTABrandom(COLOR_TABLE *ct) { +int CTABrandom(COLOR_TABLE *ct) +{ int structure; /* Set all entries to random colors. */ for (structure = 0; structure < ct->nentries; structure++) { @@ -535,7 +548,8 @@ int CTABrandom(COLOR_TABLE *ct) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -COLOR_TABLE *CTABreadFromBinaryV1(FILE *fp, int nentries) { +COLOR_TABLE *CTABreadFromBinaryV1(FILE *fp, int nentries) +{ COLOR_TABLE *ct; int structure, len; char *name; @@ -629,7 +643,8 @@ COLOR_TABLE *CTABreadFromBinaryV1(FILE *fp, int nentries) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABwriteIntoBinaryV1(COLOR_TABLE *ct, FILE *fp) { +int CTABwriteIntoBinaryV1(COLOR_TABLE *ct, FILE *fp) +{ int i; int t; @@ -667,7 +682,8 @@ int CTABwriteIntoBinaryV1(COLOR_TABLE *ct, FILE *fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -COLOR_TABLE *CTABreadFromBinaryV2(FILE *fp) { +COLOR_TABLE *CTABreadFromBinaryV2(FILE *fp) +{ COLOR_TABLE *ct; int nentries, num_entries_to_read, i; int structure, len; @@ -781,7 +797,8 @@ COLOR_TABLE *CTABreadFromBinaryV2(FILE *fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABwriteIntoBinaryV2(COLOR_TABLE *ct, FILE *fp) { +int CTABwriteIntoBinaryV2(COLOR_TABLE *ct, FILE *fp) +{ int structure; int i, t; int num_entries_to_write; @@ -832,7 +849,8 @@ int CTABwriteIntoBinaryV2(COLOR_TABLE *ct, FILE *fp) { znzlib support -------------------------------------------------------------------*/ -COLOR_TABLE *znzCTABreadFromBinary(znzFile fp) { +COLOR_TABLE *znzCTABreadFromBinary(znzFile fp) +{ COLOR_TABLE *ct; int version; @@ -849,14 +867,16 @@ COLOR_TABLE *znzCTABreadFromBinary(znzFile fp) { /* With v1, we pass in the "version" number we just got, as it's the number of entries. */ ct = znzCTABreadFromBinaryV1(fp, version); - } else { + } + else { /* Take the negative to get the real version number. */ version = -version; /* Read the right version. */ if (version == 2) { ct = znzCTABreadFromBinaryV2(fp); - } else { + } + else { /* Unsupported version. */ ErrorReturn(NULL, (ERROR_BADFILE, "CTABreadFromBinary: unknown version")); } @@ -867,7 +887,8 @@ COLOR_TABLE *znzCTABreadFromBinary(znzFile fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int znzCTABwriteIntoBinary(COLOR_TABLE *ct, znzFile fp) { +int znzCTABwriteIntoBinary(COLOR_TABLE *ct, znzFile fp) +{ int result; if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABwriteIntoBinary: ct was NULL")); @@ -890,7 +911,8 @@ int znzCTABwriteIntoBinary(COLOR_TABLE *ct, znzFile fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -COLOR_TABLE *znzCTABreadFromBinaryV1(znzFile fp, int nentries) { +COLOR_TABLE *znzCTABreadFromBinaryV1(znzFile fp, int nentries) +{ COLOR_TABLE *ct; int structure, len; char *name; @@ -980,7 +1002,8 @@ COLOR_TABLE *znzCTABreadFromBinaryV1(znzFile fp, int nentries) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int znzCTABwriteIntoBinaryV1(COLOR_TABLE *ct, znzFile fp) { +int znzCTABwriteIntoBinaryV1(COLOR_TABLE *ct, znzFile fp) +{ int i; int t; @@ -1018,7 +1041,8 @@ int znzCTABwriteIntoBinaryV1(COLOR_TABLE *ct, znzFile fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -COLOR_TABLE *znzCTABreadFromBinaryV2(znzFile fp) { +COLOR_TABLE *znzCTABreadFromBinaryV2(znzFile fp) +{ COLOR_TABLE *ct; int nentries, num_entries_to_read, i; int structure, len; @@ -1128,7 +1152,8 @@ COLOR_TABLE *znzCTABreadFromBinaryV2(znzFile fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int znzCTABwriteIntoBinaryV2(COLOR_TABLE *ct, znzFile fp) { +int znzCTABwriteIntoBinaryV2(COLOR_TABLE *ct, znzFile fp) +{ int structure; int i, t; int num_entries_to_write; @@ -1177,7 +1202,8 @@ int znzCTABwriteIntoBinaryV2(COLOR_TABLE *ct, znzFile fp) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABcopyFileName(COLOR_TABLE *ct, char *name, size_t name_len) { +int CTABcopyFileName(COLOR_TABLE *ct, char *name, size_t name_len) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABcopyName: ct was NULL")); if (NULL == name) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABcopyName: output parameter was NULL")); @@ -1188,7 +1214,8 @@ int CTABcopyFileName(COLOR_TABLE *ct, char *name, size_t name_len) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABgetNumberOfValidEntries(COLOR_TABLE *ct, int *num) { +int CTABgetNumberOfValidEntries(COLOR_TABLE *ct, int *num) +{ int valid_entries; int structure; @@ -1206,7 +1233,8 @@ int CTABgetNumberOfValidEntries(COLOR_TABLE *ct, int *num) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABgetNumberOfTotalEntries(COLOR_TABLE *ct, int *num) { +int CTABgetNumberOfTotalEntries(COLOR_TABLE *ct, int *num) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABgetNumberOfTotalEntries: ct was NULL")); if (NULL == num) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABgetNumberOfTotalEntries: num was NULL")); @@ -1216,7 +1244,8 @@ int CTABgetNumberOfTotalEntries(COLOR_TABLE *ct, int *num) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABisEntryValid(COLOR_TABLE *ct, int index, int *valid) { +int CTABisEntryValid(COLOR_TABLE *ct, int index, int *valid) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABisEntryValid: ct was NULL")); if (index < 0 || index >= ct->nentries) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABisEntryValid: index %d was OOB", index)); @@ -1230,7 +1259,8 @@ int CTABisEntryValid(COLOR_TABLE *ct, int index, int *valid) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABrgbAtIndexi(COLOR_TABLE *ct, int index, int *r, int *g, int *b) { +int CTABrgbAtIndexi(COLOR_TABLE *ct, int index, int *r, int *g, int *b) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbAtIndexi: ct was NULL")); if (index < 0 || index >= ct->nentries) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbAtIndexi: index %d was OOB", index)); @@ -1248,7 +1278,8 @@ int CTABrgbAtIndexi(COLOR_TABLE *ct, int index, int *r, int *g, int *b) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABrgbAtIndexf(COLOR_TABLE *ct, int index, float *r, float *g, float *b) { +int CTABrgbAtIndexf(COLOR_TABLE *ct, int index, float *r, float *g, float *b) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbAtIndexf: ct was NULL")); if (index < 0 || index >= ct->nentries) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbAtIndexf: index %d was OOB", index)); @@ -1266,7 +1297,8 @@ int CTABrgbAtIndexf(COLOR_TABLE *ct, int index, float *r, float *g, float *b) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABrgbaAtIndexi(COLOR_TABLE *ct, int index, int *r, int *g, int *b, int *a) { +int CTABrgbaAtIndexi(COLOR_TABLE *ct, int index, int *r, int *g, int *b, int *a) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbaAtIndexi: ct was NULL")); if (index < 0 || index >= ct->nentries) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbaAtIndexi: index %d was OOB", index)); @@ -1285,7 +1317,8 @@ int CTABrgbaAtIndexi(COLOR_TABLE *ct, int index, int *r, int *g, int *b, int *a) /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABrgbaAtIndexf(COLOR_TABLE *ct, int index, float *r, float *g, float *b, float *a) { +int CTABrgbaAtIndexf(COLOR_TABLE *ct, int index, float *r, float *g, float *b, float *a) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbaAtIndexf: ct was NULL")); if (index < 0 || index >= ct->nentries) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABrgbaAtIndexf: index %d was OOB", index)); @@ -1304,7 +1337,8 @@ int CTABrgbaAtIndexf(COLOR_TABLE *ct, int index, float *r, float *g, float *b, f /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABcopyName(COLOR_TABLE *ct, int index, char *name, size_t name_len) { +int CTABcopyName(COLOR_TABLE *ct, int index, char *name, size_t name_len) +{ if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABcopyName: ct was NULL")); if (index < 0 || index >= ct->nentries) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABcopyName: index %d was OOB", index)); @@ -1321,7 +1355,8 @@ int CTABcopyName(COLOR_TABLE *ct, int index, char *name, size_t name_len) { CTABrgb2Annotation(int r, int g, int b) Converts an rgb triplet into an annotation value. ----------------------------------------------------------------*/ -int CTABrgb2Annotation(int r, int g, int b) { +int CTABrgb2Annotation(int r, int g, int b) +{ int annotation; annotation = (b << 16) + (g << 8) + r; return (annotation); @@ -1331,7 +1366,8 @@ int CTABrgb2Annotation(int r, int g, int b) { CTABentryNameToIndex(char *EntryName, COLOR_TABLE *ct) Return the color table index given the name of the entry. ----------------------------------------------------------------*/ -int CTABentryNameToIndex(char *EntryName, COLOR_TABLE *ct) { +int CTABentryNameToIndex(char *EntryName, COLOR_TABLE *ct) +{ CTE *cte; int i; @@ -1348,7 +1384,8 @@ int CTABentryNameToIndex(char *EntryName, COLOR_TABLE *ct) { CTABentryNameToIndex(char *EntryName, COLOR_TABLE *ct) Return the color table annotation given the name of the entry. ----------------------------------------------------------------*/ -int CTABentryNameToAnnotation(char *EntryName, COLOR_TABLE *ct) { +int CTABentryNameToAnnotation(char *EntryName, COLOR_TABLE *ct) +{ CTE *cte; int index, annotation; index = CTABentryNameToIndex(EntryName, ct); @@ -1361,7 +1398,8 @@ int CTABentryNameToAnnotation(char *EntryName, COLOR_TABLE *ct) { CTABannotationAtIndex() - given the index into the ctab, compute the annotation from the rgb values. ----------------------------------------------------------------*/ -int CTABannotationAtIndex(COLOR_TABLE *ct, int index, int *annot) { +int CTABannotationAtIndex(COLOR_TABLE *ct, int index, int *annot) +{ CTE *e; int annotation; @@ -1388,7 +1426,8 @@ int CTABannotationAtIndex(COLOR_TABLE *ct, int index, int *annot) { this function is named incorrectly -- it should be something like CTABannot2Index). -----------------------------------------------------------------*/ -int CTABfindAnnotation(COLOR_TABLE *ct, int annotation, int *index) { +int CTABfindAnnotation(COLOR_TABLE *ct, int annotation, int *index) +{ int r, g, b; int result; @@ -1410,7 +1449,8 @@ int CTABfindAnnotation(COLOR_TABLE *ct, int annotation, int *index) { return the name of this annotation label. returns "NOT_FOUND" if annotation not found in colortable. -----------------------------------------------------------------*/ -const char *CTABgetAnnotationName(COLOR_TABLE *ct, int annotation) { +const char *CTABgetAnnotationName(COLOR_TABLE *ct, int annotation) +{ int r, g, b; int index = -1; @@ -1430,7 +1470,8 @@ const char *CTABgetAnnotationName(COLOR_TABLE *ct, int annotation) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABfindDuplicateAnnotations(COLOR_TABLE *ct) { +int CTABfindDuplicateAnnotations(COLOR_TABLE *ct) +{ int idx1; int idx2; int dupCount = 0; @@ -1467,7 +1508,8 @@ int CTABfindDuplicateAnnotations(COLOR_TABLE *ct) { /*------------------------------------------------------------------- ----------------------------------------------------------------*/ -int CTABfindDuplicateNames(COLOR_TABLE *ct) { +int CTABfindDuplicateNames(COLOR_TABLE *ct) +{ int idx1; int idx2; int dupCount = 0; @@ -1491,7 +1533,8 @@ int CTABfindDuplicateNames(COLOR_TABLE *ct) { return dupCount / 2; } -int CTABfindIndexFromAnnotation(COLOR_TABLE *ct, int annot, int *index) { +int CTABfindIndexFromAnnotation(COLOR_TABLE *ct, int annot, int *index) +{ int r, g, b; AnnotToRGB(annot, r, g, b); // macro @@ -1502,7 +1545,8 @@ int CTABfindIndexFromAnnotation(COLOR_TABLE *ct, int annot, int *index) { index into the color table that matches the RGB (yes, this function is named incorrectly -- it should be something like CTABrgb2Index). -----------------------------------------------------------------*/ -int CTABfindRGBi(COLOR_TABLE *ct, int r, int g, int b, int *index) { +int CTABfindRGBi(COLOR_TABLE *ct, int r, int g, int b, int *index) +{ int structure; if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABfindRGBi: ct was NULL")); @@ -1529,7 +1573,8 @@ int CTABfindRGBi(COLOR_TABLE *ct, int r, int g, int b, int *index) { index into the color table that matches the name (yes, this function is named incorrectly -- it should be something like CTABname2Index). -----------------------------------------------------------------*/ -int CTABfindName(COLOR_TABLE *ct, const char *name, int *index) { +int CTABfindName(COLOR_TABLE *ct, const char *name, int *index) +{ int structure; if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABfindName: ct was NULL")); @@ -1554,7 +1599,8 @@ int CTABfindName(COLOR_TABLE *ct, const char *name, int *index) { CTABfindEntryByName() - given the string name of a structure, return the entry number( NOT index!) in the color table that matches the name -----------------------------------------------------------------*/ -int CTABfindEntryByName(COLOR_TABLE *ct, const char *name, int *nEntry) { +int CTABfindEntryByName(COLOR_TABLE *ct, const char *name, int *nEntry) +{ int structure; if (NULL == ct) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "CTABfindName: ct was NULL")); @@ -1578,7 +1624,8 @@ int CTABfindEntryByName(COLOR_TABLE *ct, const char *name, int *nEntry) { } /*--------------------------------------------------------------*/ -int CTABprintASCII(COLOR_TABLE *ct, FILE *fp) { +int CTABprintASCII(COLOR_TABLE *ct, FILE *fp) +{ int structure; char *tmpstr; @@ -1604,7 +1651,8 @@ int CTABprintASCII(COLOR_TABLE *ct, FILE *fp) { } /*--------------------------------------------------------------*/ -int CTABwriteFileASCII(COLOR_TABLE *ct, const char *fname) { +int CTABwriteFileASCII(COLOR_TABLE *ct, const char *fname) +{ FILE *fp; int result; @@ -1627,7 +1675,8 @@ int CTABwriteFileASCII(COLOR_TABLE *ct, const char *fname) { Creates a new color table by adding name to input table. Colors are assigned randomly. -------------------------------------------------------*/ -COLOR_TABLE *CTABaddEntry(COLOR_TABLE *ctold, const char *name) { +COLOR_TABLE *CTABaddEntry(COLOR_TABLE *ctold, const char *name) +{ COLOR_TABLE *ct; COLOR_TABLE_ENTRY *cte; int nentries, i; @@ -1661,7 +1710,8 @@ describes the tissue classes, and (3) the schema name. \param ct - color table with tissue type info (may or may not be null depending upon the schema) */ -COLOR_TABLE *TissueTypeSchema(COLOR_TABLE *ct, char *schema) { +COLOR_TABLE *TissueTypeSchema(COLOR_TABLE *ct, char *schema) +{ if (strcmp(schema, "default-jan-2014") == 0) { ct = TissueTypeSchemaDefault(ct); return (ct); @@ -1681,7 +1731,8 @@ default FreeSurfer schema. \param ct - color table with tissue type info (if null then uses FreeSurferColorLUT.txt) */ -COLOR_TABLE *TissueTypeSchemaDefault(COLOR_TABLE *ct) { +COLOR_TABLE *TissueTypeSchemaDefault(COLOR_TABLE *ct) +{ COLOR_TABLE_ENTRY *cte; FSENV *fsenv; char tmpstr[2000]; @@ -1827,7 +1878,8 @@ default FreeSurfer schema and includes a Head tissue type \param ct - color table with tissue type info (if null then uses FreeSurferColorLUT.txt) */ -COLOR_TABLE *TissueTypeSchemaDefaultHead(COLOR_TABLE *ct) { +COLOR_TABLE *TissueTypeSchemaDefaultHead(COLOR_TABLE *ct) +{ COLOR_TABLE_ENTRY *cte; FSENV *fsenv; char tmpstr[2000]; @@ -2011,7 +2063,8 @@ COLOR_TABLE *TissueTypeSchemaDefaultHead(COLOR_TABLE *ct) { with ribbon values if the aseg is CtxGM or CtxWM or unknown. \param ct - color table with tissue type info */ -int CTABprintASCIItt(COLOR_TABLE *ct, FILE *fp) { +int CTABprintASCIItt(COLOR_TABLE *ct, FILE *fp) +{ int structure; char *tmpstr; COLOR_TABLE_ENTRY *cte; @@ -2064,7 +2117,8 @@ int CTABprintASCIItt(COLOR_TABLE *ct, FILE *fp) { with ribbon values if the aseg is CtxGM or CtxWM or unknown. \param ct - color table with tissue type info */ -int CTABwriteFileASCIItt(COLOR_TABLE *ct, const char *fname) { +int CTABwriteFileASCIItt(COLOR_TABLE *ct, const char *fname) +{ FILE *fp = fopen(fname, "w"); if (fp == NULL) { printf("ERROR: could not open %s for writing\n", fname); @@ -2082,7 +2136,8 @@ int CTABwriteFileASCIItt(COLOR_TABLE *ct, const char *fname) { already has an item for that structure, it is deleted and the new one is used to overwrite it. */ -int CTABmerge(COLOR_TABLE *ct, const COLOR_TABLE *merge) { +int CTABmerge(COLOR_TABLE *ct, const COLOR_TABLE *merge) +{ int n; CTE *cte, *cte0; @@ -2099,7 +2154,8 @@ int CTABmerge(COLOR_TABLE *ct, const COLOR_TABLE *merge) { return (0); } -static int ctabMinDist(COLOR_TABLE *ct, int r, int g, int b) { +static int ctabMinDist(COLOR_TABLE *ct, int r, int g, int b) +{ int i, dist, min_dist = 3 * 256; for (i = 0; i < ct->nentries; i++) { @@ -2117,7 +2173,8 @@ static int ctabMinDist(COLOR_TABLE *ct, int r, int g, int b) { The new entry will be at least min_dist from any existing rgb value so it can be visually distinguished (rdist+gdist+bdist) */ -int CTABaddUniqueEntry(COLOR_TABLE *ct, char *name, int min_dist) { +int CTABaddUniqueEntry(COLOR_TABLE *ct, char *name, int min_dist) +{ int dist, i, r, g, b; COLOR_TABLE_ENTRY *cte, **pcte; diff --git a/utils/connectcomp.c b/utils/connectcomp.c index 3aafa889d4d..d8a28c07c3a 100644 --- a/utils/connectcomp.c +++ b/utils/connectcomp.c @@ -41,7 +41,8 @@ static int xoff26[26] = {0, 1, 0, 0, -1, 0, 1, 1, -1, -1, 1, 1, -1, -1, 0, 0, 0, static int yoff26[26] = {1, 0, 0, -1, 0, 0, 1, -1, 1, -1, 0, 0, 0, 0, 1, 1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1}; static int zoff26[26] = {0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1}; -void RemoveHoles(MRI *orivol) { +void RemoveHoles(MRI *orivol) +{ /* This function assumes the object is disconnected to the volume boundary. It first finds the bkground CC that connected with the volume boundary, then set all the voxels of the volume to object value(1) except for this CC. @@ -109,7 +110,8 @@ void GrassFire(MRI *orivol, int *minY, int *maxY, int *minZ, - int *maxZ) { + int *maxZ) +{ /* This function does binary region growing from seed Pt. It assumes that object has value != 0, while bkground = 0. minX,maxX,...,maxZ denote the boundary of the current region. @@ -189,7 +191,8 @@ void GrassFire6(MRI *orivol, int *minY, int *maxY, int *minZ, - int *maxZ) { + int *maxZ) +{ /* This function does binary region growing from seed Pt. It assumes that object has value != 0, while bkground = 0. minX,maxX,...,maxZ denote the boundary of the current region. @@ -268,7 +271,8 @@ void GrassFire18(MRI *orivol, int *minY, int *maxY, int *minZ, - int *maxZ) { + int *maxZ) +{ /* This function does binary region growing from seed Pt. It assumes that object has value != 0, while bkground = 0. minX,maxX,...,maxZ denote the boundary of the current region. @@ -337,7 +341,8 @@ void GrassFire18(MRI *orivol, return; } -void GetLargestCC6(MRI *orivol) { +void GetLargestCC6(MRI *orivol) +{ /* This function keeps the largest CC, and reset all other CC to bgvalue (0) */ MRI *Label; int i, j, k; @@ -387,7 +392,8 @@ void GetLargestCC6(MRI *orivol) { return; } -void GetLargestCC18(MRI *orivol) { +void GetLargestCC18(MRI *orivol) +{ /* This function keeps the largest CC, and reset all other CC to bgvalue (0) */ MRI *Label; int i, j, k; @@ -437,7 +443,8 @@ void GetLargestCC18(MRI *orivol) { return; } -MRI *Dilation6(MRI *ori, MRI *out, int R) { +MRI *Dilation6(MRI *ori, MRI *out, int R) +{ int i, j, k, index, ci, cj, ck, count, XN, YN, ZN; MRI *tmpvol; @@ -494,7 +501,8 @@ MRI *Dilation6(MRI *ori, MRI *out, int R) { return (out); } -MRI *Erosion6(MRI *ori, MRI *out, int R) { +MRI *Erosion6(MRI *ori, MRI *out, int R) +{ int i, j, k, index, ci, cj, ck, count, XN, YN, ZN; MRI *tmpvol; @@ -552,7 +560,8 @@ MRI *Erosion6(MRI *ori, MRI *out, int R) { return (out); } -MRI *Dilation26(MRI *ori, MRI *out, int R) { +MRI *Dilation26(MRI *ori, MRI *out, int R) +{ int i, j, k, index, ci, cj, ck, count, XN, YN, ZN; MRI *tmpvol; @@ -613,7 +622,8 @@ MRI *Dilation26(MRI *ori, MRI *out, int R) { return (out); } -MRI *Erosion26(MRI *ori, MRI *out, int R) { +MRI *Erosion26(MRI *ori, MRI *out, int R) +{ int i, j, k, index, ci, cj, ck, count, XN, YN, ZN; MRI *tmpvol; @@ -671,7 +681,8 @@ MRI *Erosion26(MRI *ori, MRI *out, int R) { return (out); } -MRI *BinaryOpen6(MRI *ori, MRI *out, int R) { +MRI *BinaryOpen6(MRI *ori, MRI *out, int R) +{ /* This function assumes input volume is binary. It performs openning on the input volume using a structure element defined as R-times convolution of the basic SE (6, or 18). @@ -687,7 +698,8 @@ MRI *BinaryOpen6(MRI *ori, MRI *out, int R) { return (out); } -MRI *BinaryOpen26(MRI *ori, MRI *out, int R) { +MRI *BinaryOpen26(MRI *ori, MRI *out, int R) +{ /* This function assumes input volume is binary. It performs openning on the input volume using a structure element defined as R-times convolution of the basic SE (6, or 18). @@ -705,7 +717,8 @@ MRI *BinaryOpen26(MRI *ori, MRI *out, int R) { return (out); } -MRI *BinaryClose6(MRI *ori, MRI *out, int R) { +MRI *BinaryClose6(MRI *ori, MRI *out, int R) +{ /* This function assumes input volume is binary. It performs openning on the input volume using a structure element defined as R-times convolution of the basic SE (6, or 18). @@ -721,7 +734,8 @@ MRI *BinaryClose6(MRI *ori, MRI *out, int R) { return (out); } -MRI *BinaryClose26(MRI *ori, MRI *out, int R) { +MRI *BinaryClose26(MRI *ori, MRI *out, int R) +{ /* This function assumes input volume is binary. It performs openning on the input volume using a structure element defined as R-times convolution of the basic SE (6, or 18). @@ -777,7 +791,8 @@ MRI *BinaryClose26(MRI *ori, MRI *out, int R) { /*--------------------------------------------------------------------------- // Construct an empty MYlist with specified capacity and capacity increment //-------------------------------------------------------------------------*/ -MYlist myList2(int elementSize, int capacity, int capacityIncrement) { +MYlist myList2(int elementSize, int capacity, int capacityIncrement) +{ MYlist list; void *data; @@ -810,7 +825,8 @@ MYlist myList2(int elementSize, int capacity, int capacityIncrement) { // Construct an empty MYlist with specified capacity and default // capacity increment as 100 //-------------------------------------------------------------------------*/ -MYlist myList1(int elementSize, int capacity) { +MYlist myList1(int elementSize, int capacity) +{ MYlist list; list = myList2(elementSize, capacity, 100); @@ -822,7 +838,8 @@ MYlist myList1(int elementSize, int capacity) { // Construct an empty MYlist with default capacity as 0 and // capacity increment as 100 //-------------------------------------------------------------------------*/ -MYlist myList(int elementSize) { +MYlist myList(int elementSize) +{ MYlist list; list = myList2(elementSize, 0, 100); @@ -834,7 +851,8 @@ MYlist myList(int elementSize) { // Construct an empty MYlist with specified size, all the elements are set to // zero //-------------------------------------------------------------------------*/ -MYlist myListOfSize(int size, int elementSize) { +MYlist myListOfSize(int size, int elementSize) +{ MYlist list; char *data; int i; @@ -858,7 +876,8 @@ MYlist myListOfSize(int size, int elementSize) { /*--------------------------------------------------------------------------- // Delete this list //-------------------------------------------------------------------------*/ -void myListDelete(MYlist list) { +void myListDelete(MYlist list) +{ void *data; data = myListData(list); @@ -869,7 +888,8 @@ void myListDelete(MYlist list) { /*--------------------------------------------------------------------------- // Add an element to this list //-------------------------------------------------------------------------*/ -void myListAddElement(MYlist list, void *element) { +void myListAddElement(MYlist list, void *element) +{ int size, capacity, elementSize, capacityIncrement; void *data; @@ -884,7 +904,8 @@ void myListAddElement(MYlist list, void *element) { if (data == NULL) { /* initial list */ data = (void *)myMalloc(elementSize * capacity); - } else { + } + else { /* allocate a larger list */ data = (void *)myRealloc(data, elementSize * capacity); } @@ -898,7 +919,8 @@ void myListAddElement(MYlist list, void *element) { /*--------------------------------------------------------------------------- // Add an integer to this list (must be a list consists of only integers) //-------------------------------------------------------------------------*/ -void myListAddInt(MYlist list, int element) { +void myListAddInt(MYlist list, int element) +{ int size, capacity, elementSize, capacityIncrement; int *data; @@ -914,7 +936,8 @@ void myListAddInt(MYlist list, int element) { if (data == NULL) { /* initial list */ data = (int *)myMalloc(elementSize * capacity); - } else { + } + else { /* allocate a larger list */ data = (int *)myRealloc(data, elementSize * capacity); } @@ -928,7 +951,8 @@ void myListAddInt(MYlist list, int element) { /*--------------------------------------------------------------------------- // Add an array to this list //-------------------------------------------------------------------------*/ -void myListAddArray(MYlist list, void *array, int num) { +void myListAddArray(MYlist list, void *array, int num) +{ int size, capacity, elementSize, capacityIncrement, actualIncrement; void *data; @@ -945,7 +969,8 @@ void myListAddArray(MYlist list, void *array, int num) { if (data == NULL) { /* initial list */ data = (void *)myMalloc(elementSize * capacity); - } else { + } + else { /* allocate a larger list */ data = (void *)myRealloc(data, elementSize * capacity); } @@ -959,7 +984,8 @@ void myListAddArray(MYlist list, void *array, int num) { /*--------------------------------------------------------------------------- // Insert an element into the list at the specified index //-------------------------------------------------------------------------*/ -int myListInsertElementAt(MYlist list, int index, void *element) { +int myListInsertElementAt(MYlist list, int index, void *element) +{ int size, elementSize; void *data; void *tempPtr; @@ -992,7 +1018,8 @@ int myListInsertElementAt(MYlist list, int index, void *element) { /*--------------------------------------------------------------------------- // Retrieve an element from this list at a given index //-------------------------------------------------------------------------*/ -int myListElementAt(MYlist list, int index, void *element) { +int myListElementAt(MYlist list, int index, void *element) +{ int size, elementSize; void *data; @@ -1011,7 +1038,8 @@ int myListElementAt(MYlist list, int index, void *element) { /*--------------------------------------------------------------------------- // Sets a list element at a given index //-------------------------------------------------------------------------*/ -int myListSetElementAt(MYlist list, int index, void *element) { +int myListSetElementAt(MYlist list, int index, void *element) +{ int size, elementSize; void *data; @@ -1031,7 +1059,8 @@ int myListSetElementAt(MYlist list, int index, void *element) { /*--------------------------------------------------------------------------- // Removes all elements from this list and sets its size to zero //-------------------------------------------------------------------------*/ -int myListRemoveElementAt(MYlist list, int index) { +int myListRemoveElementAt(MYlist list, int index) +{ int size, elementSize; void *data; char *currentPtr, *nextPtr; @@ -1064,7 +1093,8 @@ void myListRemoveAllElements(MYlist list) { myListSetSize(list, 0); } /*--------------------------------------------------------------------------- // Trim this list to current size //-------------------------------------------------------------------------*/ -void myListTrim(MYlist list) { +void myListTrim(MYlist list) +{ void *data; int size, elementSize; @@ -1077,7 +1107,8 @@ void myListTrim(MYlist list) { myListSetCapacity(list, size); } -void myListInfo(MYlist list) { +void myListInfo(MYlist list) +{ int elementSize, size, capacity, capacityIncrement; elementSize = myListElementSize(list); @@ -1095,7 +1126,8 @@ void myListInfo(MYlist list) { /*--------------------------------------------------------------------------- // pop out the top element from the stack //-------------------------------------------------------------------------*/ -void myStackPop(MYstack stack, void *element) { +void myStackPop(MYstack stack, void *element) +{ int size, elementSize; void *data; @@ -1110,7 +1142,8 @@ void myStackPop(MYstack stack, void *element) { /*--------------------------------------------------------------------------- // Construct an empty MYqueue with specified capacity and capacity increment //-------------------------------------------------------------------------*/ -MYqueue myQueue2(int elementSize, int capacity, int capacityIncrement) { +MYqueue myQueue2(int elementSize, int capacity, int capacityIncrement) +{ MYqueue queue; queue = (MYqueue)myMalloc(sizeof(MYqueueStruct)); @@ -1125,7 +1158,8 @@ MYqueue myQueue2(int elementSize, int capacity, int capacityIncrement) { // Construct an empty MYqueue with specified capacity and default // capacity increment as 100 //-------------------------------------------------------------------------*/ -MYqueue myQueue1(int elementSize, int capacity) { +MYqueue myQueue1(int elementSize, int capacity) +{ MYqueue queue; queue = myQueue2(elementSize, capacity, 100); @@ -1136,7 +1170,8 @@ MYqueue myQueue1(int elementSize, int capacity) { /*--------------------------------------------------------------------------- // default constructor //-------------------------------------------------------------------------*/ -MYqueue myQueue(int elementSize) { +MYqueue myQueue(int elementSize) +{ MYqueue queue; queue = myQueue2(elementSize, 0, 100); @@ -1151,7 +1186,8 @@ void myQueueEnsureSize(MYqueue queue) { myListSetSize(queue->list, myQueueSize(q /*--------------------------------------------------------------------------- // delete the queue and its memory //-------------------------------------------------------------------------*/ -void myQueueDelete(MYqueue queue) { +void myQueueDelete(MYqueue queue) +{ myListDelete(queue->list); free(queue); } @@ -1159,14 +1195,16 @@ void myQueueDelete(MYqueue queue) { /*--------------------------------------------------------------------------- // removes all elements from the queue without releasing memory //-------------------------------------------------------------------------*/ -void myQueueRemoveAllElements(MYqueue queue) { +void myQueueRemoveAllElements(MYqueue queue) +{ queue->start = 0; queue->end = -1; myQueueEnsureSize(queue); } /* a private function for clean queue, ie. move things to the front */ -void myQueueMoveToFront(MYqueue queue) { +void myQueueMoveToFront(MYqueue queue) +{ void *data; void *s1, *s2; int elementSize, start, end; @@ -1186,7 +1224,8 @@ void myQueueMoveToFront(MYqueue queue) { /*--------------------------------------------------------------------------- // push an element to the end of the queue //-------------------------------------------------------------------------*/ -void myQueuePush(MYqueue queue, void *element) { +void myQueuePush(MYqueue queue, void *element) +{ int size, capacity; int q = MY_QUEUE_Q; /* this is the factor determines the frequency of cleaning */ @@ -1207,7 +1246,8 @@ void myQueuePush(MYqueue queue, void *element) { /*--------------------------------------------------------------------------- // push an array to the end of the queue //-------------------------------------------------------------------------*/ -void myQueuePushArray(MYqueue queue, void *array, int num) { +void myQueuePushArray(MYqueue queue, void *array, int num) +{ int size, capacity; int q = MY_QUEUE_Q; /* this is the factor determines the frequency of cleaning */ @@ -1229,7 +1269,8 @@ void myQueuePushArray(MYqueue queue, void *array, int num) { // pop out the first element from the queue //-------------------------------------------------------------------------*/ -int myQueuePop(MYqueue queue, void *element) { +int myQueuePop(MYqueue queue, void *element) +{ int start; start = queue->start; @@ -1237,7 +1278,8 @@ int myQueuePop(MYqueue queue, void *element) { myListElementAt(queue->list, start, element); /* get the first one */ queue->start = start + 1; return (1); /* correctly got the result */ - } else { + } + else { return (0); /* element is undefined */ } } @@ -1245,7 +1287,8 @@ int myQueuePop(MYqueue queue, void *element) { /*--------------------------------------------------------------------------- // trim the queue to its current size //-------------------------------------------------------------------------*/ -void myQueueTrim(MYqueue queue) { +void myQueueTrim(MYqueue queue) +{ myQueueMoveToFront(queue); myListTrim(queue->list); @@ -1254,7 +1297,8 @@ void myQueueTrim(MYqueue queue) { /*--------------------------------------------------------------------------- // extract an array from the queue //-------------------------------------------------------------------------*/ -void *myQueueToArray(MYqueue queue) { +void *myQueueToArray(MYqueue queue) +{ void *arr, *data; int size, elementSize; @@ -1263,7 +1307,8 @@ void *myQueueToArray(MYqueue queue) { if (size == 0) { arr = NULL; - } else { + } + else { data = myListData(queue->list); arr = (void *)myMalloc(elementSize * size); memcpy(arr, (char *)data + queue->start * elementSize, size * elementSize); @@ -1272,20 +1317,23 @@ void *myQueueToArray(MYqueue queue) { return (arr); } -void myQueueInfo(MYqueue queue) { +void myQueueInfo(MYqueue queue) +{ printf(" start = %d\n", queue->start); printf(" end = %d\n", queue->end); myListInfo(queue->list); } -void *myMalloc(int size) { +void *myMalloc(int size) +{ register void *value = (void *)malloc(size); if (value == 0) myError("Virtual memory exhausted!"); return value; } -void *myRealloc(void *ptr, int size) { +void *myRealloc(void *ptr, int size) +{ register void *value = (void *)realloc(ptr, size); if (value == 0) myError("Virtual memory exhausted!"); @@ -1293,7 +1341,8 @@ void *myRealloc(void *ptr, int size) { } /* Prints error message */ -void myError(char error_text[]) { +void myError(char error_text[]) +{ fprintf(stderr, "Utility run-time error:\n"); fprintf(stderr, "%s\n", error_text); fprintf(stderr, "Now exiting to system.\n"); diff --git a/utils/corio.c b/utils/corio.c index 155c44e8d5f..1e6516fccaa 100644 --- a/utils/corio.c +++ b/utils/corio.c @@ -64,7 +64,8 @@ extern int errno; #include "corio.h" /*-------------------------------------*/ -unsigned char **alloc_cor(void) { +unsigned char **alloc_cor(void) +{ unsigned char **COR; int n; @@ -84,7 +85,8 @@ unsigned char **alloc_cor(void) { return (COR); } /*-------------------------------------*/ -int free_cor(unsigned char ***pppCOR) { +int free_cor(unsigned char ***pppCOR) +{ int n; unsigned char **COR; @@ -97,7 +99,8 @@ int free_cor(unsigned char ***pppCOR) { } /*-------------------------------------*/ -unsigned char **ld_cor(char *cordir) { +unsigned char **ld_cor(char *cordir) +{ unsigned char **COR; int n; char fname[1000]; @@ -133,7 +136,8 @@ unsigned char **ld_cor(char *cordir) { return (COR); } /*-------------------------------------------------*/ -int cordir_iswritable(char *cordir) { +int cordir_iswritable(char *cordir) +{ char tmpstr[2000]; FILE *fp; @@ -151,7 +155,8 @@ int cordir_iswritable(char *cordir) { } /*-------------------------------------------------*/ -int sv_cor(unsigned char **COR, char *cordir) { +int sv_cor(unsigned char **COR, char *cordir) +{ int n; char fname[1000]; FILE *fp; @@ -211,7 +216,8 @@ int sv_cor(unsigned char **COR, char *cordir) { return (0); } /*-------------------------------------------------*/ -unsigned char getcorval(unsigned char **COR, int row, int col, int slc) { +unsigned char getcorval(unsigned char **COR, int row, int col, int slc) +{ if (col < 0 || col > 255) { fprintf(stderr, "getcorval: col = %d, out of bounds\n", col); return (0); @@ -228,7 +234,8 @@ unsigned char getcorval(unsigned char **COR, int row, int col, int slc) { return (*(COR[slc] + col + row * 256)); } /*-------------------------------------------------*/ -int setcorval(unsigned char val, unsigned char **COR, int row, int col, int slc) { +int setcorval(unsigned char val, unsigned char **COR, int row, int col, int slc) +{ if (col < 0 || col > 255) { fprintf(stderr, "setcorval: col = %d, out of bounds\n", col); return (1); diff --git a/utils/cpputils.cpp b/utils/cpputils.cpp index b8dd571d8b3..e71a7ec9f2a 100644 --- a/utils/cpputils.cpp +++ b/utils/cpputils.cpp @@ -47,7 +47,8 @@ using namespace std; /* This function finds the closest distance of voxels with the distance d of volume mri_dist to the surface mris. */ -extern "C" MRI *MRISsignedFixedDistanceTransform(MRI_SURFACE *mris, MRI *mri_dist, double distance) { +extern "C" MRI *MRISsignedFixedDistanceTransform(MRI_SURFACE *mris, MRI *mri_dist, double distance) +{ int res; // Save the MRIS surface verts @@ -178,7 +179,8 @@ extern "C" MRI *MRISsignedFixedDistanceTransform(MRI_SURFACE *mris, MRI *mri_dis * around 4 to 5 minutes ) but it's very accurate. returned MRI structure (mri_out) is an MRI_INT MRI volume with voxels * inside having the value 1 and voxels outside with value 0. */ -extern "C" MRI *MRISfillInterior2(MRI_SURFACE *mris, MRI *mri_interior) { +extern "C" MRI *MRISfillInterior2(MRI_SURFACE *mris, MRI *mri_interior) +{ MRI *_mridist, *mri_out; _mridist = MRIcloneDifferentType(mri_interior, MRI_FLOAT); diff --git a/utils/ctrpoints.c b/utils/ctrpoints.c index 124db6e862c..3297830e5ff 100644 --- a/utils/ctrpoints.c +++ b/utils/ctrpoints.c @@ -38,7 +38,8 @@ extern char *cuserid(char *); -MPoint *MRIreadControlPoints(const char *fname, int *count, int *useRealRAS) { +MPoint *MRIreadControlPoints(const char *fname, int *count, int *useRealRAS) +{ FILE *fp; char *cp, line[STRLEN]; int i = 0; @@ -88,12 +89,14 @@ MPoint *MRIreadControlPoints(const char *fname, int *count, int *useRealRAS) { i = sscanf(cp, "%f %f %f", &xw, &yw, &zw); if (i == 3) { num_control_points++; - } else // new format + } + else // new format { i = sscanf(cp, "%s %d", text, &val); if (strcmp("numpoints", text) == 0 && i == 2) { numpoints = val; - } else if (strcmp("useRealRAS", text) == 0 && i == 2) { + } + else if (strcmp("useRealRAS", text) == 0 && i == 2) { *useRealRAS = val; } } @@ -124,7 +127,8 @@ MPoint *MRIreadControlPoints(const char *fname, int *count, int *useRealRAS) { return pointArray; } -int MRIwriteControlPoints(const MPoint *pointArray, int count, int useRealRAS, const char *fname) { +int MRIwriteControlPoints(const MPoint *pointArray, int count, int useRealRAS, const char *fname) +{ FILE *fp; int i; int res; @@ -165,7 +169,8 @@ int MRIwriteControlPoints(const MPoint *pointArray, int count, int useRealRAS, c } // (mr) uses LTA to map point array: -MPoint *MRImapControlPoints(const MPoint *pointArray, int count, int useRealRAS, MPoint *trgArray, LTA *lta) { +MPoint *MRImapControlPoints(const MPoint *pointArray, int count, int useRealRAS, MPoint *trgArray, LTA *lta) +{ if (trgArray == NULL) trgArray = (MPoint *)malloc(count * sizeof(MPoint)); if (!lta->xforms[0].src.valid) ErrorExit(ERROR_BADPARM, "MRImapControlPoints LTA src geometry not valid!\n"); @@ -244,7 +249,8 @@ MPoint *MRImapControlPoints(const MPoint *pointArray, int count, int useRealRAS, in the given volume. The col, row slice remain floating point. Note: UseRealRAS has not really been tested. */ -MPoint *ControlPoints2Vox(MPoint *ras, int npoints, int UseRealRAS, MRI *vol) { +MPoint *ControlPoints2Vox(MPoint *ras, int npoints, int UseRealRAS, MRI *vol) +{ MPoint *crs; int n; MATRIX *vox2ras, *ras2vox, *vras, *vcrs = NULL; @@ -285,7 +291,8 @@ MPoint *ControlPoints2Vox(MPoint *ras, int npoints, int UseRealRAS, MRI *vol) { *M, MPoint *outctr) \brief Multiplies the xyz of the control points by the given matrix */ -MPoint *ControlPointsApplyMatrix(MPoint *srcctr, int nctrpoints, MATRIX *M, MPoint *outctr) { +MPoint *ControlPointsApplyMatrix(MPoint *srcctr, int nctrpoints, MATRIX *M, MPoint *outctr) +{ int n; MATRIX *srcras = NULL, *outras = NULL; @@ -316,7 +323,8 @@ MPoint *ControlPointsApplyMatrix(MPoint *srcctr, int nctrpoints, MATRIX *M, MPoi points in control.dat bring the contol points into the "talairach" (ie, fsaverage) space. */ -MATRIX *ControlPoints2TalMatrix(char *subject) { +MATRIX *ControlPoints2TalMatrix(char *subject) +{ MATRIX *Ta, *Na, *Tv, *Nv, *invNa, *invTv, *XFM, *M; char *SUBJECTS_DIR, tmpstr[2000]; MRI *fsa, *vol; @@ -376,7 +384,8 @@ MATRIX *ControlPoints2TalMatrix(char *subject) { converts them to talairach (fsaverage) space. If a subject does not have a control.dat then it is skipped. */ -MPoint *GetTalControlPoints(char **subjectlist, int nsubjects, int *pnctrtot) { +MPoint *GetTalControlPoints(char **subjectlist, int nsubjects, int *pnctrtot) +{ int nthsubject, nc, nctot, CPUseRealRAS, k; MPoint *subjctr, *fsactr, *ctr = NULL; char *SUBJECTS_DIR, tmpstr[2000]; @@ -430,7 +439,8 @@ MPoint *GetTalControlPoints(char **subjectlist, int nsubjects, int *pnctrtot) { converts them to talairach (fsaverage) space. If a subject does not have a control.dat then it is skipped. */ -MPoint *GetTalControlPointsSFile(const char *subjectlistfile, int *pnctrtot) { +MPoint *GetTalControlPointsSFile(const char *subjectlistfile, int *pnctrtot) +{ MPoint *ctr; FILE *fp; int nsubjects, r; diff --git a/utils/cvector.c b/utils/cvector.c index c2276dd122e..0a9398576e8 100644 --- a/utils/cvector.c +++ b/utils/cvector.c @@ -35,7 +35,8 @@ #include "mrisurf.h" #include "sig.h" -int cvector_compute_variance(float *var, float *mean, int norm, int num) { +int cvector_compute_variance(float *var, float *mean, int norm, int num) +{ int i; for (i = 0; i < num; i++) { @@ -45,20 +46,23 @@ int cvector_compute_variance(float *var, float *mean, int norm, int num) { } return (NO_ERROR); } -int cvector_normalize(float *v, float norm, int num) { +int cvector_normalize(float *v, float norm, int num) +{ int i; for (i = 0; i < num; i++) v[i] /= norm; return (NO_ERROR); } -int cvector_accumulate_square(float *v, float *vtotal, int num) { +int cvector_accumulate_square(float *v, float *vtotal, int num) +{ int i; for (i = 0; i < num; i++) vtotal[i] += v[i] * v[i]; return (NO_ERROR); } -int cvector_accumulate(float *v, float *vtotal, int num) { +int cvector_accumulate(float *v, float *vtotal, int num) +{ int i; for (i = 0; i < num; i++) vtotal[i] += v[i]; @@ -73,7 +77,8 @@ double cvector_compute_t_test(float *c1_mean, int num_class2, float *pvals, int num, - int *pvno) { + int *pvno) +{ int i; double t, numer, denom, p, max_p; @@ -85,7 +90,8 @@ double cvector_compute_t_test(float *c1_mean, if (FZERO(denom)) { t = 0; p = 0.0f; - } else { + } + else { if (num_class1 == 1 || num_class2 == 1) { int dof_out = num_class1 + num_class2; /* @@ -93,7 +99,8 @@ double cvector_compute_t_test(float *c1_mean, then use standard deviation rather than standard error. */ denom = sqrt((dof_out - 1) * ((c1_var[i] / num_class1) + (c2_var[i] / num_class2))); - } else + } + else denom = sqrt((c1_var[i] / num_class1) + (c2_var[i] / num_class2)); t = numer / denom; p = sigt(t, num_class1 + num_class2 - 2); @@ -109,7 +116,8 @@ double cvector_compute_t_test(float *c1_mean, } return (max_p); } -double cvector_compute_mean_diff(float *c1_mean, float *c2_mean, float *vmean_diff, int num, int *pvno) { +double cvector_compute_mean_diff(float *c1_mean, float *c2_mean, float *vmean_diff, int num, int *pvno) +{ int i; double max_diff; @@ -125,13 +133,15 @@ double cvector_compute_mean_diff(float *c1_mean, float *c2_mean, float *vmean_di return (max_diff); } -int cvector_subtract(float *v1, float *v2, float *vdst, int num) { +int cvector_subtract(float *v1, float *v2, float *vdst, int num) +{ int i; for (i = 0; i < num; i++) vdst[i] = v1[i] - v2[i]; return (NO_ERROR); } -int cvector_mark_low_prob_vertices(float *pvals, float pthresh, MRI_SURFACE *mris) { +int cvector_mark_low_prob_vertices(float *pvals, float pthresh, MRI_SURFACE *mris) +{ int i, num; for (num = i = 0; i < mris->nvertices; i++) { @@ -152,7 +162,8 @@ double cvector_compute_dist_free_snr(float **c1_thickness, float *c2_mean, float *vsnr, int num, - int *pi) { + int *pi) +{ int i, max_i, n, correct, total; double max_snr, mean, snr; @@ -167,7 +178,8 @@ double cvector_compute_dist_free_snr(float **c1_thickness, for (n = 0; n < num_class2; n++) if (c2_thickness[n][i] < mean) correct++; - } else { + } + else { for (n = 0; n < num_class1; n++) if (c1_thickness[n][i] < mean) correct++; @@ -187,7 +199,8 @@ double cvector_compute_dist_free_snr(float **c1_thickness, return (max_snr); } double cvector_compute_snr( - float *c1_mean, float *c2_mean, float *vvar, float *vsnr, int num, int *pi, float bonferroni, int stat_type) { + float *c1_mean, float *c2_mean, float *vvar, float *vsnr, int num, int *pi, float bonferroni, int stat_type) +{ double snr; switch (stat_type) { @@ -200,7 +213,8 @@ double cvector_compute_snr( return (snr); } double cvector_compute_snr_F( - float *c1_mean, float *c2_mean, float *vvar, float *snr, int num, int *pi, float bonferroni) { + float *c1_mean, float *c2_mean, float *vvar, float *snr, int num, int *pi, float bonferroni) +{ int i, max_i; float f, max_snr; @@ -222,7 +236,8 @@ double cvector_compute_snr_F( *pi = max_i; return (max_snr); } -double cvector_len(float *v, int num) { +double cvector_len(float *v, int num) +{ int i; double len; @@ -232,7 +247,8 @@ double cvector_len(float *v, int num) { return (len); } -float *cvector_alloc(int num) { +float *cvector_alloc(int num) +{ float *v; v = (float *)calloc(num, sizeof(float)); @@ -240,14 +256,16 @@ float *cvector_alloc(int num) { return (v); } -int cvector_clear(float *v, int num) { +int cvector_clear(float *v, int num) +{ int i; for (i = 0; i < num; i++) v[i] = 0; return (NO_ERROR); } int cvector_add_variances( - float *c1_var, float *c2_var, int num_class1, int num_class2, float *vtotal_var, int nvertices) { + float *c1_var, float *c2_var, int num_class1, int num_class2, float *vtotal_var, int nvertices) +{ int i, total_dof; total_dof = num_class1 + num_class2; @@ -257,7 +275,8 @@ int cvector_add_variances( } int cvector_multiply_variances( - float *c1_var, float *c2_var, int num_class1, int num_class2, float *vtotal_var, int nvertices) { + float *c1_var, float *c2_var, int num_class1, int num_class2, float *vtotal_var, int nvertices) +{ int i, total_dof; total_dof = num_class1 + num_class2; @@ -286,7 +305,8 @@ int cvector_track_best_snr(float *vsnr, int avgs, int num, float fthresh, - int *pnum_found) { + int *pnum_found) +{ int i, n; *pnum_found = 0; @@ -326,7 +346,8 @@ int cvector_track_best_stats(float *vpvals, int avgs, int num, float fthresh, - int *pnum_found) { + int *pnum_found) +{ int i, n; *pnum_found = 0; @@ -347,7 +368,8 @@ int cvector_track_best_stats(float *vpvals, return (NO_ERROR); } -int cvector_copy(float *v1, float *v2, int num) { +int cvector_copy(float *v1, float *v2, int num) +{ int i; for (i = 0; i < num; i++) v2[i] = v1[i]; @@ -355,7 +377,8 @@ int cvector_copy(float *v1, float *v2, int num) { return (NO_ERROR); } -int cvector_extract_best_avg(float *vbest_avgs, float *vsrc, float *vdst, int navgs, int num) { +int cvector_extract_best_avg(float *vbest_avgs, float *vsrc, float *vdst, int navgs, int num) +{ int i; for (i = 0; i < num; i++) { @@ -363,7 +386,8 @@ int cvector_extract_best_avg(float *vbest_avgs, float *vsrc, float *vdst, int na } return (NO_ERROR); } -double cvector_average_in_label(float *v, LABEL *area, int num) { +double cvector_average_in_label(float *v, LABEL *area, int num) +{ int i; double avg; @@ -375,12 +399,14 @@ double cvector_average_in_label(float *v, LABEL *area, int num) { return (avg); } -typedef struct { +typedef struct +{ float snr; int index; } SORT_ELT; int compare_sort_elts(const void *vse1, const void *vse2); -int compare_sort_elts(const void *vse1, const void *vse2) { +int compare_sort_elts(const void *vse1, const void *vse2) +{ const SORT_ELT *se1, *se2; se1 = vse1; @@ -388,7 +414,8 @@ int compare_sort_elts(const void *vse1, const void *vse2) { return (se2->snr > se1->snr); } -int *cvector_sort(float *vbest_snr, int nvertices) { +int *cvector_sort(float *vbest_snr, int nvertices) +{ int *sorted_vertices, i; SORT_ELT *se_table; @@ -416,7 +443,8 @@ double cvector_compute_pvalues(float *c1_mean, float *pvals, int num, int stat_type, - int *pvno) { + int *pvno) +{ switch (stat_type) { default: case STAT_T: @@ -428,7 +456,8 @@ double cvector_compute_pvalues(float *c1_mean, return (NO_ERROR); } -int cvector_scalar_mul(float *v, float m, int num) { +int cvector_scalar_mul(float *v, float m, int num) +{ int i; for (i = 0; i < num; i++) v[i] *= m; @@ -436,7 +465,8 @@ int cvector_scalar_mul(float *v, float m, int num) { return (NO_ERROR); } -int cvector_set(float *v, float val, int num) { +int cvector_set(float *v, float val, int num) +{ int i; for (i = 0; i < num; i++) v[i] = val; diff --git a/utils/dcdflib.c b/utils/dcdflib.c index 3d0624934b2..75256d87af2 100644 --- a/utils/dcdflib.c +++ b/utils/dcdflib.c @@ -72,7 +72,8 @@ static void E0001(int, ----------------------------------------------------------------------- */ -double algdiv(double *a, double *b) { +double algdiv(double *a, double *b) +{ static double c0 = .833333333333333e-01; static double c1 = -.277777777760991e-02; static double c2 = .793650666825390e-03; @@ -1645,7 +1646,8 @@ void cdfbet(int *which, double *p, double *q, double *x, double *y, double *a, d */ cumbet(x, y, a, b, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating X and Y */ @@ -1688,7 +1690,8 @@ void cdfbet(int *which, double *p, double *q, double *x, double *y, double *a, d *bound = 1.0e0; S400: S390:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Computing A */ @@ -1722,7 +1725,8 @@ void cdfbet(int *which, double *p, double *q, double *x, double *y, double *a, d *bound = inf; S470: S460:; - } else if (4 == *which) { + } + else if (4 == *which) { /* Computing B */ @@ -2010,7 +2014,8 @@ void cdfbin( */ cumbin(s, xn, pr, ompr, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating S */ @@ -2042,7 +2047,8 @@ void cdfbin( *bound = *xn; S400: S390:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Calculating XN */ @@ -2076,7 +2082,8 @@ void cdfbin( *bound = inf; S470: S460:; - } else if (4 == *which) { + } + else if (4 == *which) { /* Calculating PR and OMPR */ @@ -2324,7 +2331,8 @@ void cdfchi(int *which, double *p, double *q, double *x, double *df, int *status *status = 10; return; } - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating X */ @@ -2361,7 +2369,8 @@ void cdfchi(int *which, double *p, double *q, double *x, double *df, int *status *bound = inf; S300: S290:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Calculating DF */ @@ -2578,7 +2587,8 @@ void cdfchn(int *which, double *p, double *q, double *x, double *df, double *pno */ cumchn(x, df, pnonc, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating X */ @@ -2606,7 +2616,8 @@ void cdfchn(int *which, double *p, double *q, double *x, double *df, double *pno *bound = inf; S180: S170:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Calculating DF */ @@ -2635,7 +2646,8 @@ void cdfchn(int *which, double *p, double *q, double *x, double *df, double *pno *bound = inf; S230: S220:; - } else if (4 == *which) { + } + else if (4 == *which) { /* Calculating PNONC */ @@ -2873,7 +2885,8 @@ void cdff(int *which, double *p, double *q, double *f, double *dfn, double *dfd, */ cumf(f, dfn, dfd, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating F */ @@ -2906,7 +2919,8 @@ void cdff(int *which, double *p, double *q, double *f, double *dfn, double *dfd, *bound = inf; S280: S270:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Calculating DFN */ @@ -2940,7 +2954,8 @@ void cdff(int *which, double *p, double *q, double *f, double *dfn, double *dfd, *bound = inf; S350: S340:; - } else if (4 == *which) { + } + else if (4 == *which) { /* Calculating DFD */ @@ -3174,7 +3189,8 @@ void cdffnc( */ cumfnc(f, dfn, dfd, phonc, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating F */ @@ -3202,7 +3218,8 @@ void cdffnc( *bound = inf; S200: S190:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Calculating DFN */ @@ -3231,7 +3248,8 @@ void cdffnc( *bound = inf; S250: S240:; - } else if (4 == *which) { + } + else if (4 == *which) { /* Calculating DFD */ @@ -3260,7 +3278,8 @@ void cdffnc( *bound = inf; S300: S290:; - } else if (5 == *which) { + } + else if (5 == *which) { /* Calculating PHONC */ @@ -3516,7 +3535,8 @@ void cdfgam(int *which, double *p, double *q, double *x, double *shape, double * xscale = *x * *scale; cumgam(&xscale, shape, p, q); if (porq > 1.5e0) *status = 10; - } else if (2 == *which) { + } + else if (2 == *which) { /* Computing X */ @@ -3525,11 +3545,13 @@ void cdfgam(int *which, double *p, double *q, double *x, double *shape, double * if (ierr < 0.0e0) { *status = 10; return; - } else { + } + else { *x = xx / *scale; *status = 0; } - } else if (3 == *which) { + } + else if (3 == *which) { /* Computing SHAPE */ @@ -3568,7 +3590,8 @@ void cdfgam(int *which, double *p, double *q, double *x, double *shape, double * *bound = inf; S320: S310:; - } else if (4 == *which) { + } + else if (4 == *which) { /* Computing SCALE */ @@ -3577,7 +3600,8 @@ void cdfgam(int *which, double *p, double *q, double *x, double *shape, double * if (ierr < 0.0e0) { *status = 10; return; - } else { + } + else { *scale = xx / *x; *status = 0; } @@ -3837,7 +3861,8 @@ void cdfnbn( */ cumnbn(s, xn, pr, ompr, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating S */ @@ -3870,7 +3895,8 @@ void cdfnbn( *bound = inf; S380: S370:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Calculating XN */ @@ -3903,7 +3929,8 @@ void cdfnbn( *bound = inf; S450: S440:; - } else if (4 == *which) { + } + else if (4 == *which) { /* Calculating PR and OMPR */ @@ -4132,19 +4159,22 @@ void cdfnor(int *which, double *p, double *q, double *x, double *mean, double *s */ z = (*x - *mean) / *sd; cumnor(&z, p, q); - } else if (2 == *which) { + } + else if (2 == *which) { /* Computing X */ z = dinvnr(p, q); *x = *sd * z + *mean; - } else if (3 == *which) { + } + else if (3 == *which) { /* Computing the MEAN */ z = dinvnr(p, q); *mean = *x - *sd * z; - } else if (4 == *which) { + } + else if (4 == *which) { /* Computing SD */ @@ -4332,7 +4362,8 @@ void cdfpoi(int *which, double *p, double *q, double *s, double *xlam, int *stat */ cumpoi(s, xlam, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Calculating S */ @@ -4365,7 +4396,8 @@ void cdfpoi(int *which, double *p, double *q, double *s, double *xlam, int *stat *bound = inf; S260: S250:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Calculating XLAM */ @@ -4574,7 +4606,8 @@ void cdft(int *which, double *p, double *q, double *t, double *df, int *status, */ cumt(t, df, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { /* Computing T .. Get initial approximation for T @@ -4609,7 +4642,8 @@ void cdft(int *which, double *p, double *q, double *t, double *df, int *status, *bound = rtinf; S240: S230:; - } else if (3 == *which) { + } + else if (3 == *which) { /* Computing DF */ @@ -4773,7 +4807,8 @@ void cdftnc(int *which, double *p, double *q, double *t, double *df, double *pno if (1 == *which) { cumtnc(t, df, pnonc, p, q); *status = 0; - } else if (2 == *which) { + } + else if (2 == *which) { *t = 5.0e0; T1 = -inf; T2 = inf; @@ -4799,7 +4834,8 @@ void cdftnc(int *which, double *p, double *q, double *t, double *df, double *pno *bound = inf; S150: S140:; - } else if (3 == *which) { + } + else if (3 == *which) { *df = 5.0e0; T7 = zero; T8 = tent4; @@ -4825,7 +4861,8 @@ void cdftnc(int *which, double *p, double *q, double *t, double *df, double *pno *bound = inf; S200: S190:; - } else if (4 == *which) { + } + else if (4 == *which) { *pnonc = 5.0e0; T11 = -tent4; T12 = tent4; @@ -5303,7 +5340,8 @@ void cumf(double *f, double *dfn, double *dfd, double *cum, double *ccum) if (xx > half) { yy = prod / dsum; xx = done - yy; - } else + } + else yy = done - xx; T1 = *dfd * half; T2 = *dfn * half; @@ -5421,7 +5459,8 @@ void cumfnc(double *f, double *dfn, double *dfd, double *pnonc, double *cum, dou if (yy > half) { xx = prod / dsum; yy = done - xx; - } else + } + else xx = done - yy; T2 = *dfn * half + (double)icent; T3 = *dfd * half; @@ -6002,7 +6041,8 @@ void cumtnc(double *t, double *df, double *pnonc, double *cum, double *ccum) if (qrevs) { tt = -*t; dpnonc = -*pnonc; - } else { + } + else { tt = *t; dpnonc = *pnonc; } @@ -6056,7 +6096,8 @@ void cumtnc(double *t, double *df, double *pnonc, double *cum, double *ccum) if (qrevs) { *cum = zero; *ccum = one; - } else { + } + else { *cum = one; *ccum = zero; } @@ -6140,7 +6181,8 @@ void cumtnc(double *t, double *df, double *pnonc, double *cum, double *ccum) if (qrevs) { *cum = half * *ccum; *ccum = one - *cum; - } else { + } + else { *ccum = half * *ccum; *cum = one - *ccum; } @@ -6309,7 +6351,8 @@ static void E0000(int IENTRY, double *zrelst, double *zrelto, double *zsmall, - double *zstpmu) { + double *zstpmu) +{ #define qxmon(zx, zy, zz) (int)((zx) <= (zy) && (zy) <= (zz)) static double absstp, abstol, big, fbig, fsmall, relstp, reltol, small, step, stpmul, xhi, xlb, xlo, xsave, xub, yy; static int i99999; @@ -6735,7 +6778,8 @@ static void E0001(int IENTRY, double *zabstl, double *zreltl, double *zxhi, - double *zxlo) { + double *zxlo) +{ #define ftol(zx) (0.5e0 * fifdmax1(abstol, reltol * fabs((zx)))) static double a, abstol, b, c, d, fa, fb, fc, fd, fda, fdb, m, mb, p, q, reltol, tol, w, xxhi, xxlo; static int ext, i99999; @@ -7976,7 +8020,8 @@ double Xgamm(double *a) if (*a < 0.0e0) Xgamm = 1.0e0 / (Xgamm * s) / x; return Xgamm; } -void grat1(double *a, double *x, double *r, double *p, double *q, double *eps) { +void grat1(double *a, double *x, double *r, double *p, double *q, double *eps) +{ static int K2 = 0; static double a2n, a2nm1, am0, an, an0, b2n, b2nm1, c, cma, g, h, j, l, sum, t, tol, w, z, T1, T3; /* @@ -9087,18 +9132,14 @@ double fifdsign(double mag, double sign) Truncates a double precision number to a long integer ************************************************************************/ long fifidint(double a) -/* a - number to be truncated */ { - return (long)(a); -} +/* a - number to be truncated */ { return (long)(a); } /************************************************************************ FIFMOD: returns the modulo of a and b ************************************************************************/ long fifmod(long a, long b) /* a - numerator */ -/* b - denominator */ { - return a % b; -} +/* b - denominator */ { return a % b; } /************************************************************************ FTNSTOP: Prints msg to standard error and then exits @@ -9109,7 +9150,8 @@ void ftnstop(char *msg) if (msg != NULL) fprintf(stderr, "%s\n", msg); exit(EXIT_FAILURE); /* EXIT_FAILURE from stdlib.h, or use an int */ } -double sigf(float F, int df1, int df2) { +double sigf(float F, int df1, int df2) +{ double q, p, bound, d_df1, d_df2, d_F; double sig; int status, which; diff --git a/utils/dct.c b/utils/dct.c index e66defe98b6..2665915facb 100644 --- a/utils/dct.c +++ b/utils/dct.c @@ -36,7 +36,8 @@ #define FOV 256.0 -DCT *DCTalloc(int ncoef, MRI *mri_source) { +DCT *DCTalloc(int ncoef, MRI *mri_source) +{ DCT *dct; dct = (DCT *)calloc(1, sizeof(DCT)); if (dct == NULL) ErrorExit(ERROR_NOMEMORY, "DCTalloc(%d): allocation failed", ncoef); @@ -63,7 +64,8 @@ DCT *DCTalloc(int ncoef, MRI *mri_source) { DCTupdate(dct); return (dct); } -int DCTfree(DCT **pdct) { +int DCTfree(DCT **pdct) +{ DCT *dct; dct = *pdct; @@ -84,7 +86,8 @@ int DCTfree(DCT **pdct) { free(dct); return (NO_ERROR); } -int DCTcreateMatrix(DCT *dct, MRI *mri, int skip) { +int DCTcreateMatrix(DCT *dct, MRI *mri, int skip) +{ int Nx, Ny, Nz, vox, k, N, i; double dk; MATRIX *m; @@ -134,7 +137,8 @@ int DCTcreateMatrix(DCT *dct, MRI *mri, int skip) { return (NO_ERROR); } -DCT *DCTcopy(DCT *dct_src, DCT *dct_dst) { +DCT *DCTcopy(DCT *dct_src, DCT *dct_dst) +{ if (dct_dst == NULL) dct_dst = DCTalloc(dct_src->ncoef, dct_src->mri_source); MatrixCopyRealRegion(dct_src->v_xk, dct_dst->v_xk, 1, 1, MIN(dct_src->v_xk->rows, dct_dst->v_xk->rows), 1, 1, 1); @@ -143,7 +147,8 @@ DCT *DCTcopy(DCT *dct_src, DCT *dct_dst) { return (dct_dst); } -MRI *DCTapply(DCT *dct, MRI *mri_src, MRI *mri_target, MRI *mri_dst, int sample_type) { +MRI *DCTapply(DCT *dct, MRI *mri_src, MRI *mri_target, MRI *mri_dst, int sample_type) +{ int x, y, z; double xd, yd, zd; double val; @@ -178,7 +183,8 @@ MRI *DCTapply(DCT *dct, MRI *mri_src, MRI *mri_target, MRI *mri_dst, int sample_ VectorFree(&v2); return (mri_dst); } -MRI *DCTapplyInverse(DCT *dct, MRI *mri_src, MRI *mri_dst, int sample_type) { +MRI *DCTapplyInverse(DCT *dct, MRI *mri_src, MRI *mri_dst, int sample_type) +{ int x, y, z; double xs, ys, zs; double val; @@ -199,7 +205,8 @@ MRI *DCTapplyInverse(DCT *dct, MRI *mri_src, MRI *mri_dst, int sample_type) { return (mri_dst); } -int DCTtransformVoxlist(DCT *dct, VOXEL_LIST *vl) { +int DCTtransformVoxlist(DCT *dct, VOXEL_LIST *vl) +{ int i; double x, y, z, xd, yd, zd; @@ -216,7 +223,8 @@ int DCTtransformVoxlist(DCT *dct, VOXEL_LIST *vl) { return (NO_ERROR); } -int DCTinverseTransformVoxlist(DCT *dct, VOXEL_LIST *vl) { +int DCTinverseTransformVoxlist(DCT *dct, VOXEL_LIST *vl) +{ int i, x, y, z; MATRIX *m_vox2vox; static VECTOR *v1 = NULL, *v2; @@ -269,7 +277,8 @@ int DCTinverseTransformVoxlist(DCT *dct, VOXEL_LIST *vl) { MatrixFree(&m_vox2vox); return (NO_ERROR); } -int DCTtransformPoint(DCT *dct, int x, int y, int z, double *px, double *py, double *pz) { +int DCTtransformPoint(DCT *dct, int x, int y, int z, double *px, double *py, double *pz) +{ double xd, yd, zd; xd = MatrixRowDotProduct(dct->m_x_basis, x + 1, dct->v_xk); @@ -281,7 +290,8 @@ int DCTtransformPoint(DCT *dct, int x, int y, int z, double *px, double *py, dou return (NO_ERROR); } -int DCTinverseTransformPoint(DCT *dct, double x, double y, double z, double *px, double *py, double *pz) { +int DCTinverseTransformPoint(DCT *dct, double x, double y, double z, double *px, double *py, double *pz) +{ double xd, yd, zd; int xi, yi, zi; @@ -304,7 +314,8 @@ int DCTinverseTransformPoint(DCT *dct, double x, double y, double z, double *px, return (NO_ERROR); } -int DCTdump(DCT *dct, FILE *fp) { +int DCTdump(DCT *dct, FILE *fp) +{ int k; fprintf(fp, "DCT (%d):\n", dct->ncoef); for (k = 1; k <= dct->ncoef; k++) @@ -314,7 +325,8 @@ int DCTdump(DCT *dct, FILE *fp) { return (NO_ERROR); } static int soap_bubble(double *in_vals, double *ctrl, double *out_vals, int N, double max_change_allowed); -int DCTupdate(DCT *dct) { +int DCTupdate(DCT *dct) +{ double *x_wts, *y_wts, *z_wts, xd, yd, zd, jcd, jfd, *wts, *inv, *fwd, jd; int jc, jf, x, y, z, N, i, j, Ninv; @@ -402,7 +414,8 @@ int DCTupdate(DCT *dct) { free(z_wts); return (NO_ERROR); } -static int soap_bubble(double *in_vals, double *ctrl, double *out_vals, int N, double max_change_allowed) { +static int soap_bubble(double *in_vals, double *ctrl, double *out_vals, int N, double max_change_allowed) +{ double *tmp_vals, max_change, change, out_val, min_val, max_val; int iter, i, j, num; diff --git a/utils/density.c b/utils/density.c index b8f32000d0c..bd05fa2dc34 100644 --- a/utils/density.c +++ b/utils/density.c @@ -34,7 +34,8 @@ #include "proto.h" // nint #include "utils.h" // fgetl -DENSITY *DensityHistogramEstimate(MRI *mri1, MRI *mri2, int nbins, float sigma, int *valid1, int *valid2) { +DENSITY *DensityHistogramEstimate(MRI *mri1, MRI *mri2, int nbins, float sigma, int *valid1, int *valid2) +{ DENSITY *pdf; int x, y, bin1, bin2, nvox, n1, n2, n; float val1, val2, scale1, scale2; @@ -64,12 +65,14 @@ DENSITY *DensityHistogramEstimate(MRI *mri1, MRI *mri2, int nbins, float sigma, ErrorExit(ERROR_NOMEMORY, "DensityHistogramEstimate: could not allocate lookup tables (%d, %d)\n", n1, n2); if (valid1) { for (n = 0; n < n1; n++) pdf->valid1[n] = valid1[n]; - } else + } + else memset(pdf->valid1, 1, n1 * sizeof(int)); if (valid2) { for (n = 0; n < n2; n++) pdf->valid2[n] = valid2[n]; - } else + } + else memset(pdf->valid2, 1, n2 * sizeof(int)); for (nvox = 0, x = 0; x < mri1->width; x++) { @@ -112,7 +115,8 @@ DENSITY *DensityHistogramEstimate(MRI *mri1, MRI *mri2, int nbins, float sigma, printf("histogram computed with %d dofs\n", nvox); return (pdf); } -int DensityWrite(DENSITY *pdf, char *fname) { +int DensityWrite(DENSITY *pdf, char *fname) +{ FILE *fp; int i, j, n; #if 0 @@ -150,7 +154,8 @@ int DensityWrite(DENSITY *pdf, char *fname) { return (NO_ERROR); } -DENSITY *DensityRead(char *fname) { +DENSITY *DensityRead(char *fname) +{ DENSITY *pdf; FILE *fp; int i, j, nbins, n; @@ -220,7 +225,8 @@ DENSITY *DensityRead(char *fname) { return (pdf); } #define BIG_AND_NEGATIVE -1000000 -double DensityLogLikelihood(DENSITY *pdf, float val1, float val2) { +double DensityLogLikelihood(DENSITY *pdf, float val1, float val2) +{ int bin1, bin2, nbins; double p; @@ -238,7 +244,8 @@ double DensityLogLikelihood(DENSITY *pdf, float val1, float val2) { return (log(p)); } -MRI *DensityLikelihoodImage(MRI *mri1, MRI *mri2, MRI *mri_ll, MATRIX *m, DENSITY *pdf, MRI *mri_seg, int inverse) { +MRI *DensityLikelihoodImage(MRI *mri1, MRI *mri2, MRI *mri_ll, MATRIX *m, DENSITY *pdf, MRI *mri_seg, int inverse) +{ double val_src, val_dst, xs, ys, thick, ll; int x, y; VECTOR *v_src, *v_dst; @@ -269,7 +276,8 @@ MRI *DensityLikelihoodImage(MRI *mri1, MRI *mri2, MRI *mri_ll, MATRIX *m, DENSIT if (MRIindexNotInVolume(mri1, xs, ys, 0) == 0) { val_dst = MRIvox(mri2, x, y, 0); MRIsampleVolumeSlice(mri1, xs, ys, 0, &val_src, MRI_CORONAL); - } else { + } + else { val_src = val_dst = -1000000; } if (inverse) diff --git a/utils/diag.c b/utils/diag.c index 198b7030549..efd2857d881 100644 --- a/utils/diag.c +++ b/utils/diag.c @@ -94,7 +94,8 @@ static int (*diag_vfprintf)(FILE *fp, const char *fmt, va_list args) = vfprintf; ------------------------------------------------------------------------*/ unsigned long DiagInit(char *fname, int (*vfprint)(FILE *fp, const char *fmt, va_list args), - int (*vprint)(const char *fmt, va_list args)) { + int (*vprint)(const char *fmt, va_list args)) +{ char *cp = 0; unsigned long diag = 0L; @@ -162,7 +163,8 @@ unsigned long DiagInit(char *fname, Description ------------------------------------------------------*/ -int DiagShowImage(unsigned long diag_bits, int win, int which, IMAGE *I, char *fmt, ...) { +int DiagShowImage(unsigned long diag_bits, int win, int which, IMAGE *I, char *fmt, ...) +{ #if 0 char name[100] ; va_list args ; @@ -192,7 +194,8 @@ int DiagShowImage(unsigned long diag_bits, int win, int which, IMAGE *I, char *f Description ------------------------------------------------------*/ -int DiagDrawBox(unsigned long diag_bits, int win, int row0, int col, int rows, int cols, int color) { +int DiagDrawBox(unsigned long diag_bits, int win, int row0, int col, int rows, int cols, int color) +{ int i; i = win; i = row0; @@ -215,7 +218,8 @@ int DiagDrawBox(unsigned long diag_bits, int win, int row0, int col, int rows, i Description ------------------------------------------------------*/ -int DiagCloseWindow(unsigned long diag_bits, int win) { +int DiagCloseWindow(unsigned long diag_bits, int win) +{ if (diag_bits && !(diag_bits & Gdiag)) return (-1); win = win + (int)diag_bits; /* to remove warning */ @@ -228,7 +232,8 @@ int DiagCloseWindow(unsigned long diag_bits, int win) { Description ------------------------------------------------------*/ -int DiagCreateWindow(unsigned long diag_bits, int wrows, int wcols, int rows, int cols) { +int DiagCreateWindow(unsigned long diag_bits, int wrows, int wcols, int rows, int cols) +{ int win = -1; #if 0 int i; @@ -257,7 +262,8 @@ int DiagCreateWindow(unsigned long diag_bits, int wrows, int wcols, int rows, in Description ------------------------------------------------------*/ -int DiagFprintf(unsigned long diag_bits, char *fmt, ...) { +int DiagFprintf(unsigned long diag_bits, char *fmt, ...) +{ static int first = 1; va_list args; FILE *fp; @@ -282,7 +288,8 @@ int DiagFprintf(unsigned long diag_bits, char *fmt, ...) { Description ------------------------------------------------------*/ -int DiagPrintf(unsigned long diag_bits, char *fmt, ...) { +int DiagPrintf(unsigned long diag_bits, char *fmt, ...) +{ va_list args; if (diag_bits && !(diag_bits & Gdiag)) return (-1); @@ -307,7 +314,8 @@ void DiagBreak(void) {} Description dummy for break points in debugger ------------------------------------------------------*/ -void DiagHeartbeat(float pct_done) { +void DiagHeartbeat(float pct_done) +{ static float old_pct = -10.0f; #if 0 @@ -335,7 +343,8 @@ void DiagHeartbeat(float pct_done) { Description dummy for break points in debugger ------------------------------------------------------*/ -void DiagShowPctDone(float pct_done, int nprints) { +void DiagShowPctDone(float pct_done, int nprints) +{ static float old_pct = -10.0f; if (pct_done < old_pct) old_pct = -20; @@ -345,7 +354,8 @@ void DiagShowPctDone(float pct_done, int nprints) { } } -int check_finite(char *where, double what) { +int check_finite(char *where, double what) +{ if (!isfinite(what)) { ErrorPrintf(ERROR_BADPARM, "%s not finite!\n", where); DiagBreak(); diff --git a/utils/diffuse.c b/utils/diffuse.c index 1ac817adc79..662509c8228 100644 --- a/utils/diffuse.c +++ b/utils/diffuse.c @@ -47,7 +47,8 @@ float sx[9] = {-0.25f, 0.0f, 0.25f, -0.5f, 0.0f, 0.5f, -0.25f, 0.0f, 0.25f}; ----------------------------------------------------------------------*/ #define g(I, k) exp((-1.0 / (k)) * fabs((double)(I))) #define LAMBDA 0.25 -int ImageDiffuse(IMAGE *inImage, IMAGE *outImage, double k, int niter, int which, double slope, KIMAGE *kimage) { +int ImageDiffuse(IMAGE *inImage, IMAGE *outImage, double k, int niter, int which, double slope, KIMAGE *kimage) +{ IMAGE *fSrcImage, *fDstImage; if (outImage->pixel_format != inImage->pixel_format) { @@ -117,7 +118,8 @@ int ImageDiffuse(IMAGE *inImage, IMAGE *outImage, double k, int niter, int which #define KERNEL_MUL 0.125f #endif -int ImageDiffuseCurvature(IMAGE *inImage, IMAGE *outImage, double A, int niter, double slope, KIMAGE *kimage) { +int ImageDiffuseCurvature(IMAGE *inImage, IMAGE *outImage, double A, int niter, double slope, KIMAGE *kimage) +{ int x, y, i, rows, cols, *xE, *yN, *xW, *yS, ys, yn, xe, xw, ci; float c[9], fvals[9], dst_val; FILE *fp; @@ -309,7 +311,8 @@ static float ykernel[KSIZE * 3]; #endif -int ImageDiffuseHV(IMAGE *inImage, IMAGE *outImage, double k, int niter, double slope, KIMAGE *kimage) { +int ImageDiffuseHV(IMAGE *inImage, IMAGE *outImage, double k, int niter, double slope, KIMAGE *kimage) +{ int x, y, i, rows, cols, *xE, *yN, *xW, *yS, ys, yn, xe, xw, ci; float c[9], fvals[9], dst_val; FILE *fp; @@ -377,14 +380,16 @@ int ImageDiffuseHV(IMAGE *inImage, IMAGE *outImage, double k, int niter, double if (!ImageCheckSize(inImage, xImage, 0, 0, 0)) { if (xImage) ImageFree(&xImage); xImage = ImageAlloc(rows, cols, PFFLOAT, 1); - } else { + } + else { xImage->rows = rows; xImage->cols = cols; } if (!ImageCheckSize(inImage, yImage, 0, 0, 0)) { if (yImage) ImageFree(&yImage); yImage = ImageAlloc(rows, cols, PFFLOAT, 1); - } else { + } + else { yImage->rows = rows; yImage->cols = cols; } @@ -520,7 +525,8 @@ int ImageDiffuseHV(IMAGE *inImage, IMAGE *outImage, double k, int niter, double #define C(grad, k) ((float)exp(-0.5f * SQR((float)fabs((grad)) / k))) -int ImageDiffusePerona(IMAGE *inImage, IMAGE *outImage, double k, int niter, double slope, KIMAGE *kimage) { +int ImageDiffusePerona(IMAGE *inImage, IMAGE *outImage, double k, int niter, double slope, KIMAGE *kimage) +{ int x, y, i, rows, cols, *xE, *yN, *xW, *yS, ys, yn, xe, xw, ci; float c[9], fvals[9], dst_val; FILE *fp; @@ -675,7 +681,8 @@ int ImageDiffusePerona(IMAGE *inImage, IMAGE *outImage, double k, int niter, dou } #else -int ImageDiffusePerona(IMAGE *inImage, IMAGE *outImage, double k, int niter, double slope, KIMAGE *kimage) { +int ImageDiffusePerona(IMAGE *inImage, IMAGE *outImage, double k, int niter, double slope, KIMAGE *kimage) +{ UCHAR *csrc, *cdst; float *fsrc, *fdst, fcval, feval, fwval, fnval, fsval, fdval; int x, y, cval, eval, wval, nval, sval, i, dval; @@ -770,7 +777,8 @@ int ImageDiffusePerona(IMAGE *inImage, IMAGE *outImage, double k, int niter, dou Description: ----------------------------------------------------------------------*/ -int ImageCurvature(IMAGE *inImage, float A, IMAGE *gradImage) { +int ImageCurvature(IMAGE *inImage, float A, IMAGE *gradImage) +{ static IMAGE *xImage = NULL, *yImage = NULL; int x, y, rows, cols; float *xpix, *ypix, *gradpix, xval, yval, gval, Asq; @@ -780,14 +788,16 @@ int ImageCurvature(IMAGE *inImage, float A, IMAGE *gradImage) { if (!ImageCheckSize(inImage, xImage, 0, 0, 0)) { if (xImage) ImageFree(&xImage); xImage = ImageAlloc(rows, cols, PFFLOAT, 1); - } else { + } + else { xImage->rows = rows; xImage->cols = cols; } if (!ImageCheckSize(inImage, yImage, 0, 0, 0)) { if (yImage) ImageFree(&yImage); yImage = ImageAlloc(rows, cols, PFFLOAT, 1); - } else { + } + else { yImage->rows = rows; yImage->cols = cols; } diff --git a/utils/dti.c b/utils/dti.c index 2bdb4bec6fb..dcdbc7c09b9 100644 --- a/utils/dti.c +++ b/utils/dti.c @@ -49,7 +49,8 @@ // Return the CVS version of this file. const char *DTIsrcVersion(void) { return ("$Id: dti.c,v 1.30 2015/04/22 16:49:32 greve Exp $"); } /* --------------------------------------------- */ -int DTIfree(DTI **pdti) { +int DTIfree(DTI **pdti) +{ DTI *dti; dti = *pdti; if (dti->GradFile) free(dti->GradFile); @@ -111,7 +112,8 @@ int DTIparamsFromSiemensAscii(const char *fname, float *bValue, int *nDir, int * return (0); } /*------------------------------------------------------------*/ -int DTIloadGradients(DTI *dti, const char *GradFile) { +int DTIloadGradients(DTI *dti, const char *GradFile) +{ static char tmpstr[2000]; FILE *fp; int c, r, n; @@ -165,7 +167,8 @@ int DTIloadGradients(DTI *dti, const char *GradFile) { } /*--------------------------------------------------------*/ -DTI *DTIstructFromSiemensAscii(const char *fname) { +DTI *DTIstructFromSiemensAscii(const char *fname) +{ int err; float bval; DTI *dti; @@ -205,7 +208,8 @@ DTI *DTIstructFromSiemensAscii(const char *fname) { } /*--------------------------------------------------------*/ -int DTInormGradDir(DTI *dti) { +int DTInormGradDir(DTI *dti) +{ int r, c; double len, maxlen; @@ -227,7 +231,8 @@ int DTInormGradDir(DTI *dti) { return (0); } /*--------------------------------------------------------*/ -int DTIdesignMatrix(DTI *dti) { +int DTIdesignMatrix(DTI *dti) +{ int r, xr; double bval; MATRIX *g; @@ -257,7 +262,8 @@ int DTIdesignMatrix(DTI *dti) { } /*---------------------------------------------------------*/ -MRI *DTIbeta2Tensor(MRI *beta, MRI *mask, MRI *tensor) { +MRI *DTIbeta2Tensor(MRI *beta, MRI *mask, MRI *tensor) +{ int c, r, s; double m, v; @@ -316,7 +322,8 @@ MRI *DTIbeta2Tensor(MRI *beta, MRI *mask, MRI *tensor) { return (tensor); } /*---------------------------------------------------------*/ -int DTItensor2Eig(MRI *tensor, MRI *mask, MRI **evals, MRI **evec1, MRI **evec2, MRI **evec3) { +int DTItensor2Eig(MRI *tensor, MRI *mask, MRI **evals, MRI **evec1, MRI **evec2, MRI **evec3) +{ int c, r, s, a, b, n; double m; MATRIX *T, *Evec; @@ -392,7 +399,8 @@ int DTItensor2Eig(MRI *tensor, MRI *mask, MRI **evals, MRI **evec1, MRI **evec2, DTIsortEV() - sorts the eigenvalues and eigenvectors from max to min. ---------------------------------------------------------*/ -int DTIsortEV(float *EigVals, MATRIX *EigVecs) { +int DTIsortEV(float *EigVals, MATRIX *EigVecs) +{ int r; static MATRIX *EigVecsTmp = NULL; static float EigValsTmp[3]; @@ -405,7 +413,8 @@ int DTIsortEV(float *EigVals, MATRIX *EigVecs) { if (EigVals[1] > EigVals[2]) { // 1st > 2nd > 3rd -- nothing to do return (0); - } else { + } + else { // 1st > 3rd > 2nd -- swap 2nd and 3rd cols for (r = 1; r <= 3; r++) { EigVecs->rptr[r][2] = EigVecsTmp->rptr[r][3]; @@ -428,7 +437,8 @@ int DTIsortEV(float *EigVals, MATRIX *EigVecs) { EigVals[1 - 1] = EigValsTmp[2 - 1]; EigVals[2 - 1] = EigValsTmp[1 - 1]; return (0); - } else { + } + else { // 2nd > 3rd > 1st for (r = 1; r <= 3; r++) { EigVecs->rptr[r][1] = EigVecsTmp->rptr[r][2]; @@ -454,7 +464,8 @@ int DTIsortEV(float *EigVals, MATRIX *EigVecs) { EigVals[2 - 1] = EigValsTmp[1 - 1]; EigVals[3 - 1] = EigValsTmp[2 - 1]; return (0); - } else { + } + else { // 3rd > 2nd > 1st for (r = 1; r <= 3; r++) { EigVecs->rptr[r][1] = EigVecsTmp->rptr[r][3]; @@ -479,7 +490,8 @@ int DTIsortEV(float *EigVals, MATRIX *EigVecs) { regression parameter. This should be the average volume when bvalue=0. ---------------------------------------------------------*/ -MRI *DTIbeta2LowB(MRI *beta, MRI *mask, MRI *lowb) { +MRI *DTIbeta2LowB(MRI *beta, MRI *mask, MRI *lowb) +{ int c, r, s; double m, v; @@ -512,7 +524,8 @@ MRI *DTIbeta2LowB(MRI *beta, MRI *mask, MRI *lowb) { DTItensor2ADC() - computes apparent diffusion coefficient as the trace/3. ---------------------------------------------------------*/ -MRI *DTItensor2ADC(MRI *tensor, MRI *mask, MRI *adc) { +MRI *DTItensor2ADC(MRI *tensor, MRI *mask, MRI *adc) +{ int c, r, s; double m, v1, v2, v3, vadc; @@ -545,7 +558,8 @@ MRI *DTItensor2ADC(MRI *tensor, MRI *mask, MRI *adc) { return (adc); } /*------------------------------------------------------------*/ -MRI *DTIeigvals2FA(MRI *evals, MRI *mask, MRI *FA) { +MRI *DTIeigvals2FA(MRI *evals, MRI *mask, MRI *FA) +{ int c, r, s; double m, v1, v2, v3, vmean, vsse, vnorm, v; @@ -583,7 +597,8 @@ MRI *DTIeigvals2FA(MRI *evals, MRI *mask, MRI *FA) { /*------------------------------------------------------------ DTIeigvals2RA() - relative anisotropy ------------------------------------------------------------*/ -MRI *DTIeigvals2RA(MRI *evals, MRI *mask, MRI *RA) { +MRI *DTIeigvals2RA(MRI *evals, MRI *mask, MRI *RA) +{ int c, r, s; double m, v1, v2, v3, vmean, vsse, v; @@ -611,7 +626,8 @@ MRI *DTIeigvals2RA(MRI *evals, MRI *mask, MRI *RA) { if (vmean != 0) { vsse = pow(v1 - vmean, 2.0) + pow(v2 - vmean, 2.0) + pow(v3 - vmean, 2.0); v = sqrt(vsse / (3.0 * vmean)); - } else + } + else v = 0; MRIsetVoxVal(RA, c, r, s, 0, v); } @@ -624,7 +640,8 @@ MRI *DTIeigvals2RA(MRI *evals, MRI *mask, MRI *RA) { DTIeigvals2VR() - volume ratio measure of anisotropy. Actually, 1-VR is used so that it increases with anisotropy. ------------------------------------------------------------*/ -MRI *DTIeigvals2VR(MRI *evals, MRI *mask, MRI *VR) { +MRI *DTIeigvals2VR(MRI *evals, MRI *mask, MRI *VR) +{ int c, r, s; double m, v1, v2, v3, vmean, v; @@ -665,7 +682,8 @@ MRI *DTIeigvals2VR(MRI *evals, MRI *mask, MRI *VR) { read in by FSL's dtifit with -b option. They put all the bvalues on one line. ----------------------------------------------------------------*/ -int DTIfslBValFile(DTI *dti, const char *bvalfname) { +int DTIfslBValFile(DTI *dti, const char *bvalfname) +{ FILE *fp; int n; @@ -686,7 +704,8 @@ int DTIfslBValFile(DTI *dti, const char *bvalfname) { by FSL's dtifit with -r option. They put all the gradients on three lines (ie, there are 3 rows and nsamples columns). ----------------------------------------------------------------*/ -int DTIfslBVecFile(DTI *dti, const char *bvecfname) { +int DTIfslBVecFile(DTI *dti, const char *bvecfname) +{ FILE *fp; int n, c; @@ -709,7 +728,8 @@ int DTIfslBVecFile(DTI *dti, const char *bvecfname) { \fn MRI *DTIsynthDWI(MATRIX *X, MRI *beta, MRI *mask, MRI *synth); \brief Computes exp(-X*beta). Currently mask has no effect. */ -MRI *DTIsynthDWI(MATRIX *X, MRI *beta, MRI *mask, MRI *synth) { +MRI *DTIsynthDWI(MATRIX *X, MRI *beta, MRI *mask, MRI *synth) +{ synth = fMRImatrixMultiply(beta, X, synth); if (synth == NULL) return (NULL); synth = MRIexp(synth, 1, -1, NULL, synth); @@ -720,7 +740,8 @@ MRI *DTIsynthDWI(MATRIX *X, MRI *beta, MRI *mask, MRI *synth) { \fn MRI *DTIivc(MRI *evec, MRI *mask, MRI *ivc) \brief Computes intervoxel coherence */ -MRI *DTIivc(MRI *evec, MRI *mask, MRI *ivc) { +MRI *DTIivc(MRI *evec, MRI *mask, MRI *ivc) +{ int c, r, s, f, dc, dr, ds, err; double v1, v2, vsum, angle, anglesum, m; int nhits; @@ -732,7 +753,8 @@ MRI *DTIivc(MRI *evec, MRI *mask, MRI *ivc) { return (NULL); } MRIcopyHeader(evec, ivc); - } else { + } + else { err = MRIdimMismatch(evec, ivc, 0); if (err) { printf("ERROR: DTIivc(): output dimension mismatch (%d)\n", err); @@ -792,7 +814,8 @@ MRI *DTIivc(MRI *evec, MRI *mask, MRI *ivc) { \brief Loads in bvalues from text file. It does not matter whether they are all on the same line or not. */ -MATRIX *DTIloadBValues(const char *bvalfile) { +MATRIX *DTIloadBValues(const char *bvalfile) +{ FILE *fp; double b; int nbvalues; @@ -846,7 +869,8 @@ MATRIX *DTIloadBValues(const char *bvalfile) { return (bvals); } /*---------------------------------------------------------------------*/ -int DTIwriteBValues(MATRIX *bvals, const char *bvalfile) { +int DTIwriteBValues(MATRIX *bvals, const char *bvalfile) +{ FILE *fp; int n; @@ -865,7 +889,8 @@ int DTIwriteBValues(MATRIX *bvals, const char *bvalfile) { \brief Loads in gradient directions from text file. Each line has a different 3-component vector (not the same as FSL). */ -MATRIX *DTIloadBVectors(const char *bvecfile) { +MATRIX *DTIloadBVectors(const char *bvecfile) +{ FILE *fp; double gx, gy, gz; int nbvecs, isFSL; @@ -920,7 +945,8 @@ MATRIX *DTIloadBVectors(const char *bvecfile) { } nbvecs++; } - } else { + } + else { printf("Detected BVec file as FSL formatted\n"); for (nbvecs = 0; nbvecs < bvecs->rows; nbvecs++) { if (fscanf(fp, "%f", &(bvecs->rptr[nbvecs + 1][1]))) { @@ -945,7 +971,8 @@ MATRIX *DTIloadBVectors(const char *bvecfile) { return (bvecs); } /*---------------------------------------------------------------------*/ -int DTIwriteBVectors(MATRIX *bvecs, const char *bvecfile) { +int DTIwriteBVectors(MATRIX *bvecs, const char *bvecfile) +{ FILE *fp; int n; @@ -961,7 +988,8 @@ int DTIwriteBVectors(MATRIX *bvecs, const char *bvecfile) { } /*--------------------------------------------------------*/ -DTI *DTIstructFromBFiles(const char *bvalfile, const char *bvecfile) { +DTI *DTIstructFromBFiles(const char *bvalfile, const char *bvecfile) +{ MATRIX *bvals, *bvecs; DTI *dti; @@ -992,7 +1020,8 @@ DTI *DTIstructFromBFiles(const char *bvalfile, const char *bvecfile) { /*-------------------------------------------------------------------------*/ // ep_bX#N X = bvalue N = nth acq for that bvalue -int DTIparsePulseSeqName(const char *pulseseq, double *bValue, int *nthDirection) { +int DTIparsePulseSeqName(const char *pulseseq, double *bValue, int *nthDirection) +{ int n; const char *pc; char tmpstr[100]; @@ -1035,7 +1064,8 @@ int DTIparsePulseSeqName(const char *pulseseq, double *bValue, int *nthDirection has more than 3 elements. Returns -1 if error, 1 if FSL, 0 if not FSL. */ -int DTIisFSLBVec(const char *fname) { +int DTIisFSLBVec(const char *fname) +{ FILE *fp; char tmpstr[10000], *s; float f; @@ -1060,7 +1090,8 @@ int DTIisFSLBVec(const char *fname) { \brief Computes radial diffusivity, which is the average of the 2nd and 3rd eigenvalues. */ -MRI *DTIradialDiffusivity(MRI *evals, MRI *mask, MRI *RD) { +MRI *DTIradialDiffusivity(MRI *evals, MRI *mask, MRI *RD) +{ int c, r, s; double m, v2, v3, vmean; @@ -1092,7 +1123,8 @@ MRI *DTIradialDiffusivity(MRI *evals, MRI *mask, MRI *RD) { return (RD); } -int DTIbvecChangeSpace(MRI *vol, int desired_bvec_space) { +int DTIbvecChangeSpace(MRI *vol, int desired_bvec_space) +{ int b, i, f; MATRIX *Mdc, *M, *bvec; diff --git a/utils/dtk.fs.c b/utils/dtk.fs.c index ae19222f871..0b153368897 100644 --- a/utils/dtk.fs.c +++ b/utils/dtk.fs.c @@ -56,7 +56,8 @@ double trkvisOffset = 0.5; const char *DTKFSSrcVersion(void) { return ("$Id: dtk.fs.c,v 1.5 2011/03/02 00:04:43 nicks Exp $"); } /*----------------------------------------------------------------*/ -DTK_TRACK_SET *DTKloadTrackSet(char *trkfile, char *mrifile) { +DTK_TRACK_SET *DTKloadTrackSet(char *trkfile, char *mrifile) +{ DTK_TRACK_SET *dtkset; FILE *fp; size_t nread; @@ -79,7 +80,8 @@ DTK_TRACK_SET *DTKloadTrackSet(char *trkfile, char *mrifile) { if (fname == NULL) { printf("WARNING: DTKloadTrackSet(): cannot find matching MRI file for %s\n", trkfile); } - } else + } + else fname = mrifile; if (fname) { printf("DTKloadTrackSet(): reading geometry from %s\n", fname); @@ -138,7 +140,8 @@ DTK_TRACK_SET *DTKloadTrackSet(char *trkfile, char *mrifile) { return (dtkset); } /* --------------------------------------------- */ -int DTKwriteTrackSet(char *trkfile, DTK_TRACK_SET *dtkset) { +int DTKwriteTrackSet(char *trkfile, DTK_TRACK_SET *dtkset) +{ FILE *fp; int nthtrk; float dc, dr, ds; @@ -159,7 +162,8 @@ int DTKwriteTrackSet(char *trkfile, DTK_TRACK_SET *dtkset) { return (0); } /*---------------------------------------------------------------------*/ -DTK_TRACK *DTKreadTrack(FILE *fp, int n_scalars, int n_properties, float dc, float dr, float ds) { +DTK_TRACK *DTKreadTrack(FILE *fp, int n_scalars, int n_properties, float dc, float dr, float ds) +{ int npoints, n, ns; DTK_TRACK *trk; float x, y, z; @@ -199,7 +203,8 @@ DTK_TRACK *DTKreadTrack(FILE *fp, int n_scalars, int n_properties, float dc, flo return (trk); } /*-------------------------------------------------------------*/ -int DTKwriteTrack(FILE *fp, DTK_TRACK *trk, float dc, float dr, float ds) { +int DTKwriteTrack(FILE *fp, DTK_TRACK *trk, float dc, float dr, float ds) +{ int n, ns; float x, y, z; @@ -218,7 +223,8 @@ int DTKwriteTrack(FILE *fp, DTK_TRACK *trk, float dc, float dr, float ds) { return (0); } /*-----------------------------------------------------------*/ -int DTKprintTrack(FILE *fp, DTK_TRACK *trk) { +int DTKprintTrack(FILE *fp, DTK_TRACK *trk) +{ int n, ns; for (n = 0; n < trk->npoints; n++) { fprintf(fp, "%d %f %f %f ", n, trk->c[n], trk->r[n], trk->s[n]); @@ -228,7 +234,8 @@ int DTKprintTrack(FILE *fp, DTK_TRACK *trk) { return (0); } /*-------------------------------------------------------------------*/ -DTK_TRACK *DTKcopyTrack(DTK_TRACK *trk) { +DTK_TRACK *DTKcopyTrack(DTK_TRACK *trk) +{ DTK_TRACK *newtrk; int n, ns; newtrk = DTKallocTrack(trk->npoints, trk->n_scalars, trk->n_properties); @@ -245,7 +252,8 @@ DTK_TRACK *DTKcopyTrack(DTK_TRACK *trk) { return (newtrk); } /*-------------------------------------------------------------------*/ -DTK_TRACK *DTKallocTrack(int npoints, int n_scalars, int n_properties) { +DTK_TRACK *DTKallocTrack(int npoints, int n_scalars, int n_properties) +{ DTK_TRACK *trk; int ns; @@ -269,7 +277,8 @@ DTK_TRACK *DTKallocTrack(int npoints, int n_scalars, int n_properties) { return (trk); } /*-------------------------------------------------------------*/ -MRI *DTKmapEndPoints(DTK_TRACK_SET *dtkset) { +MRI *DTKmapEndPoints(DTK_TRACK_SET *dtkset) +{ MRI *mri, *t; int ntrk, c, r, s, nlast, n; DTK_TRACK *trk; @@ -304,7 +313,8 @@ MRI *DTKmapEndPoints(DTK_TRACK_SET *dtkset) { } /*-------------------------------------------------------------*/ -int DTKlabelTracks(DTK_TRACK_SET *trkset, MRI *seg) { +int DTKlabelTracks(DTK_TRACK_SET *trkset, MRI *seg) +{ int nthtrk, c, r, s, n; DTK_TRACK *trk; int ndiv = 2000, nthdiv; @@ -337,7 +347,8 @@ int DTKlabelTracks(DTK_TRACK_SET *trkset, MRI *seg) { } /*-------------------------------------------------------------*/ -int DTKlabelTracks0(DTK_TRACK_SET *trkset, MRI *seg) { +int DTKlabelTracks0(DTK_TRACK_SET *trkset, MRI *seg) +{ int nthtrk, c, r, s, n; DTK_TRACK *trk; // printf("Labeling tracks\n"); @@ -362,7 +373,8 @@ int DTKlabelTracks0(DTK_TRACK_SET *trkset, MRI *seg) { /*--------------------------------------------------------*/ // must first DTKlabelTracks(); -DTK_TRACK_SET *DTKextractCC(DTK_TRACK_SET *trkset) { +DTK_TRACK_SET *DTKextractCC(DTK_TRACK_SET *trkset) +{ int n, nthtrk, id, isCC; DTK_TRACK *trk; DTK_TRACK_SET *newset; @@ -393,7 +405,8 @@ DTK_TRACK_SET *DTKextractCC(DTK_TRACK_SET *trkset) { } /*---------------------------------------------------------------*/ -DTK_TRACK_SET *DTKextractSeg(DTK_TRACK_SET *trkset, int segid) { +DTK_TRACK_SET *DTKextractSeg(DTK_TRACK_SET *trkset, int segid) +{ int n, nthtrk, id, isSeg; DTK_TRACK *trk; DTK_TRACK_SET *newset; @@ -426,7 +439,8 @@ DTK_TRACK_SET *DTKextractSeg(DTK_TRACK_SET *trkset, int segid) { } /*---------------------------------------------------------------*/ -DTK_TRACK_SET *DTKextractSegEndPoints(DTK_TRACK_SET *trkset, int segid) { +DTK_TRACK_SET *DTKextractSegEndPoints(DTK_TRACK_SET *trkset, int segid) +{ int nthtrk; DTK_TRACK *trk; DTK_TRACK_SET *newset; @@ -452,7 +466,8 @@ DTK_TRACK_SET *DTKextractSegEndPoints(DTK_TRACK_SET *trkset, int segid) { } /*-------------------------------------------------------------*/ -int DTKprintHeader(FILE *fp, DTK_HDR *trkh) { +int DTKprintHeader(FILE *fp, DTK_HDR *trkh) +{ fprintf(fp, "id_string %s\n", trkh->id_string); fprintf(fp, "dim %d %d %d\n", trkh->dim[0], trkh->dim[1], trkh->dim[2]); fprintf(fp, "voxel_size %f %f %f\n", trkh->voxel_size[0], trkh->voxel_size[1], trkh->voxel_size[2]); @@ -465,7 +480,8 @@ int DTKprintHeader(FILE *fp, DTK_HDR *trkh) { fprintf(fp, "hdr_size %d\n", trkh->hdr_size); return (0); } -LABEL *DTKtrack2Label(DTK_TRACK *trk) { +LABEL *DTKtrack2Label(DTK_TRACK *trk) +{ LABEL *trklabel; int n; MRI *mri; @@ -503,7 +519,8 @@ LABEL *DTKtrack2Label(DTK_TRACK *trk) { through the voxel, the remainder are the track numbers of the passing tracks. --------------------------------------------------------------*/ -MRI *DTKmapTrackNos(DTK_TRACK_SET *trkset) { +MRI *DTKmapTrackNos(DTK_TRACK_SET *trkset) +{ MRI *mri, *t; int ntrk, c, r, s, n, nhits, nmaxhits = 10000; DTK_TRACK *trk; @@ -544,7 +561,8 @@ MRI *DTKmapTrackNos(DTK_TRACK_SET *trkset) { } /*----------------------------------------------------------------*/ -MRI *DTKsegROI(DTK_TRACK_SET *trkset, MRI *seg, int segid) { +MRI *DTKsegROI(DTK_TRACK_SET *trkset, MRI *seg, int segid) +{ MRI *mri, *tracknos; int c, r, s, id, nthid, idlist[1000], ntracks, id0, n0, trackno, n; int term, cT = 0, rT = 0, sT = 0, idT = 0, pct = 0; @@ -612,7 +630,8 @@ MRI *DTKsegROI(DTK_TRACK_SET *trkset, MRI *seg, int segid) { // Get the most frequently occuring label id0 = most_frequent_int_list(idlist, nthid, &n0); pct = nint(1000.0 * n0 / nthid); // 10x percent - } else + } + else id0 = 0; // nothing appropriate MRIsetVoxVal(mri, c, r, s, 0, id0); diff --git a/utils/error.c b/utils/error.c index 93dfe996fe9..395445be094 100644 --- a/utils/error.c +++ b/utils/error.c @@ -68,7 +68,8 @@ int Gerror = NO_ERROR; GLOBAL FUNCTIONS -------------------------------------------------------*/ -void SetErrorExitDoneFile(char *DoneFile) { +void SetErrorExitDoneFile(char *DoneFile) +{ extern char *ErrorExitDoneFile; ErrorExitDoneFile = DoneFile; } @@ -80,7 +81,8 @@ void SetErrorExitDoneFile(char *DoneFile) { Description ------------------------------------------------------*/ -static void rgb_error(char *error_str) { +static void rgb_error(char *error_str) +{ ErrorPrintf(ERROR_BADPARM, error_str); return; } @@ -94,7 +96,8 @@ static void rgb_error(char *error_str) { ------------------------------------------------------*/ int ErrorInit(char *fname, int (*vfprint)(FILE *fp, const char *fmt, va_list args), - int (*vprint)(const char *fmt, va_list args)) { + int (*vprint)(const char *fmt, va_list args)) +{ FSinit(); error_exit = (void *)exit; i_seterror(rgb_error); @@ -116,7 +119,8 @@ int ErrorInit(char *fname, Description ------------------------------------------------------*/ -void ErrorExit(int ecode, const char *fmt, ...) { +void ErrorExit(int ecode, const char *fmt, ...) +{ va_list args; extern char *ErrorExitDoneFile; @@ -153,7 +157,8 @@ void ErrorExit(int ecode, const char *fmt, ...) { ErrorExit(). If no error occurs during processing, then the process should run ErrorWriteDoneFile(DoneFile, 0); */ -int ErrorWriteDoneFile(char *DoneFile, int errorcode) { +int ErrorWriteDoneFile(char *DoneFile, int errorcode) +{ FILE *fp; if (DoneFile == NULL) return (0); fp = fopen(DoneFile, "w"); @@ -170,7 +175,8 @@ int ErrorWriteDoneFile(char *DoneFile, int errorcode) { Description ------------------------------------------------------*/ -int ErrorPrintf(int ecode, const char *fmt, ...) { +int ErrorPrintf(int ecode, const char *fmt, ...) +{ va_list args; FILE *fp; @@ -205,7 +211,8 @@ int ErrorPrintf(int ecode, const char *fmt, ...) { Description ------------------------------------------------------*/ -int ErrorSetExitFunc(void (*exit_func)(int ecode)) { +int ErrorSetExitFunc(void (*exit_func)(int ecode)) +{ error_exit = exit_func; return (1); } diff --git a/utils/evschutils.c b/utils/evschutils.c index afc2d997c0d..4b80235d98e 100644 --- a/utils/evschutils.c +++ b/utils/evschutils.c @@ -43,7 +43,8 @@ static int EVScompare(const void *evsch1, const void *evsch2); /*-------------------------------------------------------------*/ -EVENT_SCHEDULE *EVSAlloc(int nevents, int allocweight) { +EVENT_SCHEDULE *EVSAlloc(int nevents, int allocweight) +{ EVENT_SCHEDULE *EvSch; EvSch = (EVENT_SCHEDULE *)calloc(sizeof(EVENT_SCHEDULE), 1); @@ -60,7 +61,8 @@ EVENT_SCHEDULE *EVSAlloc(int nevents, int allocweight) { return (EvSch); } /*-------------------------------------------------------------*/ -int EVSfree(EVENT_SCHEDULE **ppEvSch) { +int EVSfree(EVENT_SCHEDULE **ppEvSch) +{ EVENT_SCHEDULE *pEvSch; pEvSch = *ppEvSch; @@ -83,7 +85,8 @@ int EVSfree(EVENT_SCHEDULE **ppEvSch) { an FIR design matrix. -------------------------------------------------------------*/ MATRIX *EVS2FIRmtx( - int EvId, EVSCH *EvSch, float tDelay, float TR, int Ntps, float PSDMin, float PSDMax, float dPSD, MATRIX *X) { + int EvId, EVSCH *EvSch, float tDelay, float TR, int Ntps, float PSDMin, float PSDMax, float dPSD, MATRIX *X) +{ float tMax, tmp, PSDWindow, tPSD, PSD; int RSR, Npsds, nthPSD, n, rA, rB; @@ -161,7 +164,8 @@ uniformly in time. */ all events types. The matrices for the individual event types are horizontally concatenated. ---------------------------------------------------------------------*/ -MATRIX *EVSfirMtxAll(EVSCH *EvSch, float tDelay, float TR, int Ntps, float PSDMin, float PSDMax, float dPSD) { +MATRIX *EVSfirMtxAll(EVSCH *EvSch, float tDelay, float TR, int Ntps, float PSDMin, float PSDMax, float dPSD) +{ int ev; MATRIX *Xevfir = NULL, *Xtmp = NULL, *Xfir = NULL; @@ -182,7 +186,8 @@ MATRIX *EVSfirMtxAll(EVSCH *EvSch, float tDelay, float TR, int Ntps, float PSDMi return (Xfir); } /*-------------------------------------------------------------*/ -int EVSPrint(FILE *fp, EVENT_SCHEDULE *EvSch) { +int EVSPrint(FILE *fp, EVENT_SCHEDULE *EvSch) +{ int n; for (n = 0; n < EvSch->nevents; n++) { // fprintf(fp,"%3d %8.4f %3d ",n,EvSch->tevent[n],EvSch->eventid[n]); @@ -200,7 +205,8 @@ int EVSPrint(FILE *fp, EVENT_SCHEDULE *EvSch) { '-0.00'. This is PURELY for cosmetic reasons since it is usually the first thing that users see. -----------------------------------------------------------------*/ -int EVSwritePar(char *parfile, EVENT_SCHEDULE *EvSch, char **labels, float tPreScan, float tMax) { +int EVSwritePar(char *parfile, EVENT_SCHEDULE *EvSch, char **labels, float tPreScan, float tMax) +{ FILE *fp; float NullDur = 0.0, tNull = 0.0, t = 0.0; int n, id; @@ -271,7 +277,8 @@ EVENT_SCHEDULE *EVSsynth(int nEvTypes, float tPreScan, int nCB1Search, float tNullMin, - float tNullMax) { + float tNullMax) +{ int id, m, n, nevents, nSlotsNull, nSlotsTot, *EvSeq, nNullMax; float tStimTot, t, tScanTot, tNullTot; EVENT_SCHEDULE *EvSch; @@ -356,7 +363,8 @@ EVENT_SCHEDULE *EVSsynth(int nEvTypes, t += tPer[id - 1]; t += tNullMin; m++; - } else + } + else t += tRes; } @@ -371,7 +379,8 @@ EVENT_SCHEDULE *EVSsynth(int nEvTypes, EVScb1Optimize() - search for an event sequence which will minimize the first-order counter-balancing error. -----------------------------------------------------------*/ -EVSCH *EVScb1Optimize(int nEvTypes, int *nEvReps, int nSearch) { +EVSCH *EVScb1Optimize(int nEvTypes, int *nEvReps, int nSearch) +{ EVSCH *EvSch, *EvSchBest = NULL; int n; @@ -390,7 +399,8 @@ EVSCH *EVScb1Optimize(int nEvTypes, int *nEvReps, int nSearch) { if (EvSchBest->cb1err > EvSch->cb1err) { EVSfree(&EvSchBest); EvSchBest = EvSch; - } else + } + else EVSfree(&EvSch); } } @@ -402,7 +412,8 @@ EVSCH *EVScb1Optimize(int nEvTypes, int *nEvReps, int nSearch) { given number of event types and number of repetitions per event. -----------------------------------------------------------*/ -EVSCH *EVSRandSequence(int nEvTypes, int *nEvReps) { +EVSCH *EVSRandSequence(int nEvTypes, int *nEvReps) +{ EVSCH *EvSch; int nevents, m, n, nthev; @@ -433,7 +444,8 @@ EVSCH *EVSRandSequence(int nEvTypes, int *nEvReps) { /*------------------------------------------ EVSmaxId() - return the maximum id. ------------------------------------------*/ -int EVSmaxId(EVSCH *EvSch) { +int EVSmaxId(EVSCH *EvSch) +{ int n, id, condmax; condmax = -1; @@ -448,7 +460,8 @@ int EVSmaxId(EVSCH *EvSch) { EVSreadPar() - read an event schedule stored in paradigm file format. -------------------------------------------------------------*/ -EVENT_SCHEDULE *EVSreadPar(char *parfile) { +EVENT_SCHEDULE *EVSreadPar(char *parfile) +{ FILE *fp; EVENT_SCHEDULE *EvSch; int nevents, id, ev; @@ -500,7 +513,8 @@ EVENT_SCHEDULE *EVSreadPar(char *parfile) { RandPerm() - returns a list of randomly permuted integers between 0 and N-1. Should be the same as matlab's. ------------------------------------------------------------*/ -int *RandPerm(int N, int *v) { +int *RandPerm(int N, int *v) +{ int tmp, n, n2; if (v == NULL) v = (int *)calloc(sizeof(int), N); @@ -523,7 +537,8 @@ int *RandPerm(int N, int *v) { Returns 0 upon successfully finding a legal sequence. Returns -1 if the maximum number of iterations is exceeded. -----------------------------------------------------------------*/ -int RandPermListLimit0(int N, int *v, int lim, int nitersmax) { +int RandPermListLimit0(int N, int *v, int lim, int nitersmax) +{ int niters, runlenmax, runlen, n; niters = 0; @@ -553,7 +568,8 @@ int RandPermListLimit0(int N, int *v, int lim, int nitersmax) { /*--------------------------------------------------------------- RandPermList() - randomly permutes members of the given list. ------------------------------------------------------------*/ -int RandPermList(int N, int *v) { +int RandPermList(int N, int *v) +{ int *p, *vp, n; if (v == NULL) { @@ -576,7 +592,8 @@ int RandPermList(int N, int *v) { value in the cost element. Sorts so that the maximum cost is first (is descending order). ---------------------------------------------------------*/ -int EVSsort(EVSCH **EvSchList, int nList) { +int EVSsort(EVSCH **EvSchList, int nList) +{ qsort(EvSchList, nList, sizeof(EVSCH **), EVScompare); return (0); } @@ -585,7 +602,8 @@ int EVSsort(EVSCH **EvSchList, int nList) { Compares based on he cost element so that the maximum cost is first (is descending order). --------------------------------------------------------------*/ -static int EVScompare(const void *evsch1, const void *evsch2) { +static int EVScompare(const void *evsch1, const void *evsch2) +{ EVSCH *EvSch1, *EvSch2; EvSch1 = *((EVSCH **)evsch1); @@ -604,7 +622,8 @@ static int EVScompare(const void *evsch1, const void *evsch2) { condition i was followed by condition j. This does not include condition 0. --------------------------------------------------------------*/ -MATRIX *EVScb1Matrix(EVSCH *EvSch) { +MATRIX *EVScb1Matrix(EVSCH *EvSch) +{ MATRIX *Ncb1; int nthev, i, j; @@ -627,7 +646,8 @@ MATRIX *EVScb1Matrix(EVSCH *EvSch) { Pcb1 should sum to 1.0, but this will not be the case for which ever condition the sequence ends on. --------------------------------------------------------------*/ -MATRIX *EVScb1ProbMatrix(EVSCH *EvSch) { +MATRIX *EVScb1ProbMatrix(EVSCH *EvSch) +{ MATRIX *Ncb1, *Pcb1 = NULL; int i, j; @@ -651,7 +671,8 @@ MATRIX *EVScb1ProbMatrix(EVSCH *EvSch) { j, which is just equal to the probability of condition j. This does not include condition 0. --------------------------------------------------------------*/ -MATRIX *EVScb1IdealProbMatrix(EVSCH *EvSch) { +MATRIX *EVScb1IdealProbMatrix(EVSCH *EvSch) +{ MATRIX *IdealPcb1; int i, j; @@ -675,7 +696,8 @@ MATRIX *EVScb1IdealProbMatrix(EVSCH *EvSch) { probability matrix and the actual matrix, averaged over all the elements in the matrix. ------------------------------------------------------------*/ -float EVScb1Error(EVSCH *EvSch) { +float EVScb1Error(EVSCH *EvSch) +{ MATRIX *IdealPcb1, *Pcb1; int i, j; float cb1err; @@ -702,7 +724,8 @@ float EVScb1Error(EVSCH *EvSch) { EVScostId() - converts from a string indicating a cost function to a numeric id that can be used in a case statement. ----------------------------------------------------------------*/ -int EVScostId(char *CostString) { +int EVScostId(char *CostString) +{ if (!strcmp("eff", CostString)) return (EVS_COST_EFF); if (!strcmp("effinv", CostString)) return (EVS_COST_EFF_INV); if (!strcmp("vrfavg", CostString)) return (EVS_COST_VRFAVG); @@ -717,7 +740,8 @@ int EVScostId(char *CostString) { statement) indicating a cost function to a human-readable string. ----------------------------------------------------------------*/ -char *EVScostString(int CostId) { +char *EVScostString(int CostId) +{ switch (CostId) { case EVS_COST_UNKNOWN: return ("unknown"); @@ -748,7 +772,8 @@ char *EVScostString(int CostId) { EVScost() - compute the cost of the event schedule based on the cost function (specified with CostId). ------------------------------------------------------------------*/ -float EVScost(EVSCH *EvSch, int CostId, float *params) { +float EVScost(EVSCH *EvSch, int CostId, float *params) +{ switch (CostId) { case EVS_COST_EFF: /* efficiency */ @@ -789,7 +814,8 @@ float EVScost(EVSCH *EvSch, int CostId, float *params) { modified to compute the VRF differently when there are different numbers of stimuli in each event type.x -------------------------------------------------------------------*/ -int EVSdesignMtxStats(MATRIX *Xtask, MATRIX *Xnuis, EVSCH *EvSch, MATRIX *C, MATRIX *W) { +int EVSdesignMtxStats(MATRIX *Xtask, MATRIX *Xnuis, EVSCH *EvSch, MATRIX *C, MATRIX *W) +{ MATRIX *X = NULL, *Xt = NULL, *XtX = NULL; MATRIX *iXtX = NULL, *VRF = NULL, *Ct = NULL, *CiXtX = NULL, *CiXtXCt = NULL; int r, m, nTaskAvgs, nNuisAvgs, nAvgs, Cfree, J; @@ -849,7 +875,8 @@ int EVSdesignMtxStats(MATRIX *Xtask, MATRIX *Xnuis, EVSCH *EvSch, MATRIX *C, MAT MatrixFree(&CiXtX); MatrixFree(&CiXtXCt); MatrixFree(&VRF); - } else + } + else r = 1; MatrixFree(&X); @@ -884,7 +911,8 @@ int EVSdesignMtxStats(MATRIX *Xtask, MATRIX *Xnuis, EVSCH *EvSch, MATRIX *C, MAT 3-1=2 dPSDs. -------------------------------------------------------------*/ MATRIX *EVSfirXtXIdeal( - int nEvTypes, int *nEvReps, float *EvDur, float TR, int Ntp, float PSDMin, float PSDMax, float dPSD) { + int nEvTypes, int *nEvReps, float *EvDur, float TR, int Ntp, float PSDMin, float PSDMax, float dPSD) +{ MATRIX *XtX = NULL; int Npsd, Navgs, npsd1, npsd2, nevt1, nevt2; int n, nslots, nshift; @@ -922,7 +950,8 @@ MATRIX *EVSfirXtXIdeal( vx = 0.0; else vx = nEvReps[nevt1] * nEvReps[nevt1] / nslots; - } else { + } + else { /* off-diagonal block */ if (nshift == 0 || (nshift > 0 && nshift < EvDur_dPSD[nevt2]) || (nshift < 0 && -nshift < EvDur_dPSD[nevt1])) @@ -944,7 +973,8 @@ MATRIX *EVSfirXtXIdeal( on the amount of time since the end of the last event. This penalizes based on a refractory model. --------------------------------------------------------*/ -int EVSrefractory(EVSCH *sch, double alpha, double T, double dtmin) { +int EVSrefractory(EVSCH *sch, double alpha, double T, double dtmin) +{ int n, idprev; double tonprev, durprev, tonev, dt = 0.0, toffprev; diff --git a/utils/fcd.c b/utils/fcd.c index c381c0fc391..40a74d5ef16 100644 --- a/utils/fcd.c +++ b/utils/fcd.c @@ -43,7 +43,8 @@ static MRI *build_distance_by_intensity_histo( MRI *mri_norm, MRI *mri_dist, MRI *mri_aseg, double dist_spacing, double max_dist); static int augment_thicknesses(FCD_DATA *fcd, MRI *mri_pvals, double min_dist, double max_dist, double thresh); -static int most_frequent_label(MRI *mri_seg, MRI_SEGMENT *mseg) { +static int most_frequent_label(MRI *mri_seg, MRI_SEGMENT *mseg) +{ int label_counts[MAX_CMA_LABELS], i, max_count, max_label, label; memset(label_counts, 0, sizeof(label_counts)); @@ -65,7 +66,8 @@ static int most_frequent_label(MRI *mri_seg, MRI_SEGMENT *mseg) { #define MAX_DIST 10 #define DIST_SPACING .5 -FCD_DATA *FCDloadData(char *sdir, char *subject, char *suffix_in) { +FCD_DATA *FCDloadData(char *sdir, char *subject, char *suffix_in) +{ FCD_DATA *fcd; char fname[STRLEN]; MRI *mri_interior, *mri_dist, *mri_int_lh, *mri_int_rh, *mri_pvals; @@ -303,7 +305,8 @@ FCD_DATA *FCDloadData(char *sdir, char *subject, char *suffix_in) { return (fcd); } -static int sort_labels(FCD_DATA *fcd) { +static int sort_labels(FCD_DATA *fcd) +{ int i; qsort(fcd->labels, fcd->nlabels, sizeof(LABEL *), compare_labels); @@ -313,7 +316,8 @@ static int sort_labels(FCD_DATA *fcd) { return (NO_ERROR); } -static int compare_labels(const void *v1, const void *v2) { +static int compare_labels(const void *v1, const void *v2) +{ LABEL *l1, *l2; l1 = *((LABEL **)v1); @@ -327,7 +331,8 @@ static int compare_labels(const void *v1, const void *v2) { return (0); // equal } -int FCDcomputeThicknessLabels(FCD_DATA *fcd, double thickness_thresh, double sigma, int size_thresh) { +int FCDcomputeThicknessLabels(FCD_DATA *fcd, double thickness_thresh, double sigma, int size_thresh) +{ MRI *mri_lh, *mri_rh, *mri_lh_diff, *mri_rh_diff; int niter, vno, s; MRI_SEGMENTATION *mriseg; @@ -413,7 +418,8 @@ int FCDcomputeThicknessLabels(FCD_DATA *fcd, double thickness_thresh, double sig if (base_label) { break; } - } else { + } + else { base_label = label; } if (val >= 0) { @@ -422,7 +428,8 @@ int FCDcomputeThicknessLabels(FCD_DATA *fcd, double thickness_thresh, double sig if (val > val2) { MRIsetVoxVal(fcd->mri_thickness_increase, xvi, yvi, zvi, 0, val); } - } else { + } + else { val2 = MRIgetVoxVal(fcd->mri_thickness_decrease, xvi, yvi, zvi, 0); // check if another thread already populated this voxel if (val < val2) { @@ -475,7 +482,8 @@ int FCDcomputeThicknessLabels(FCD_DATA *fcd, double thickness_thresh, double sig if (base_label) { break; } - } else { + } + else { base_label = label; } @@ -484,7 +492,8 @@ int FCDcomputeThicknessLabels(FCD_DATA *fcd, double thickness_thresh, double sig if (val > val2) { MRIsetVoxVal(fcd->mri_thickness_increase, xvi, yvi, zvi, 0, val); } - } else { + } + else { val2 = MRIgetVoxVal(fcd->mri_thickness_decrease, xvi, yvi, zvi, 0); if (val < val2) { MRIsetVoxVal(fcd->mri_thickness_decrease, xvi, yvi, zvi, 0, val); @@ -533,7 +542,8 @@ int FCDcomputeThicknessLabels(FCD_DATA *fcd, double thickness_thresh, double sig return (fcd->nlabels); } -int FCDwriteLabels(FCD_DATA *fcd, char *dir) { +int FCDwriteLabels(FCD_DATA *fcd, char *dir) +{ int s; char label_name[STRLEN]; @@ -549,7 +559,8 @@ int FCDwriteLabels(FCD_DATA *fcd, char *dir) { return (NO_ERROR); } -static int fcdFreeLabels(FCD_DATA *fcd) { +static int fcdFreeLabels(FCD_DATA *fcd) +{ int s; for (s = 0; s < fcd->nlabels; s++) @@ -560,7 +571,8 @@ static int fcdFreeLabels(FCD_DATA *fcd) { return (NO_ERROR); } -int FCDfree(FCD_DATA **pfcd) { +int FCDfree(FCD_DATA **pfcd) +{ FCD_DATA *fcd; fcd = *pfcd; @@ -625,7 +637,8 @@ int FCDfree(FCD_DATA **pfcd) { } static MRI *build_distance_by_intensity_histo( - MRI *mri_norm, MRI *mri_dist, MRI *mri_aseg, double dist_spacing, double max_dist) { + MRI *mri_norm, MRI *mri_dist, MRI *mri_aseg, double dist_spacing, double max_dist) +{ HISTOGRAM2D *h_dist_by_int; int x, y, z, b1, b2, label; float val, dist; @@ -690,7 +703,8 @@ static MRI *build_distance_by_intensity_histo( pval = HISTO2DgetCount(h_dist_by_int, dist, val); if (pval > 0) { pval = -log10(pval); - } else { + } + else { pval = -10000; } MRIsetVoxVal(mri_pvals, x, y, z, 0, pval); @@ -700,7 +714,8 @@ static MRI *build_distance_by_intensity_histo( return (mri_pvals); } -static int augment_thicknesses(FCD_DATA *fcd, MRI *mri_pvals, double min_dist, double max_dist, double thresh) { +static int augment_thicknesses(FCD_DATA *fcd, MRI *mri_pvals, double min_dist, double max_dist, double thresh) +{ int h, vno; VERTEX *v; MRI_SURFACE *mris; @@ -722,7 +737,8 @@ static int augment_thicknesses(FCD_DATA *fcd, MRI *mri_pvals, double min_dist, d { mri_thickness = fcd->lh_thickness_on_lh; mris = fcd->mris_lh; - } else // right hemi + } + else // right hemi { mri_thickness = fcd->rh_thickness_on_rh; mris = fcd->mris_rh; diff --git a/utils/fftutils.c b/utils/fftutils.c index 98f4f8eb46f..9818f8dbdd0 100644 --- a/utils/fftutils.c +++ b/utils/fftutils.c @@ -47,10 +47,12 @@ static int _rev = 0; int *reversedBits; int **_reverseBits = NULL; static int _lookupTabletLength = -1; -typedef struct complex { +typedef struct complex +{ double a, b; } complex; -typedef struct complexF { +typedef struct complexF +{ float a, b; } complexF; @@ -62,26 +64,31 @@ static complexF **_uILookupF = NULL; static float *uRLookup = NULL; static float *uILookup = NULL; -static void FFTerror(char *string) { +static void FFTerror(char *string) +{ fprintf(stdout, "\nFFT Error: %s\n", string); exit(1); } -void FFTdebugAssert(int b, char *string) { +void FFTdebugAssert(int b, char *string) +{ if (!b) FFTerror(string); } -static void Swap(float *a, float *b) { +static void Swap(float *a, float *b) +{ float temp = *a; *a = *b; *b = temp; } int FFTisPowerOf2(int x) { return (x & (x - 1)) == 0; } -int FFTpow2(int exponent) { +int FFTpow2(int exponent) +{ if (exponent >= 0 && exponent < 31) return 1 << exponent; return 0; } -int FFTlog2(int x) { // ceiling of FFTlog2 +int FFTlog2(int x) +{ // ceiling of FFTlog2 if (x <= 65536) { if (x <= 256) { if (x <= 16) { @@ -150,7 +157,8 @@ int FFTlog2(int x) { // ceiling of FFTlog2 return 31; } -static void ReorderArray(float *data, int data_length) { +static void ReorderArray(float *data, int data_length) +{ FFTdebugAssert(data != NULL, "ReorderArray : Data = Null"); int length = data_length / 2; int numberOfBits = FFTlog2(length); @@ -181,7 +189,8 @@ static void ReorderArray(float *data, int data_length) { } } -static int _ReverseBits(int bits, int n) { +static int _ReverseBits(int bits, int n) +{ int bitsReversed = 0; int i; for (i = 0; i < n; i++) { @@ -190,7 +199,8 @@ static int _ReverseBits(int bits, int n) { } return bitsReversed; } -static void InitializeReverseBits(int levels) { +static void InitializeReverseBits(int levels) +{ int i, j; if (_reverseBits) free(_reverseBits); _reverseBits = (int **)malloc((levels + 1) * sizeof(int *)); @@ -203,7 +213,8 @@ static void InitializeReverseBits(int levels) { } } -static void InitializeComplexRotations(int levels) { +static void InitializeComplexRotations(int levels) +{ int ln = levels; if (_uRLookup) free(_uRLookup); @@ -258,7 +269,8 @@ static void InitializeComplexRotations(int levels) { } } -static void SyncLookupTableLength(int length) { +static void SyncLookupTableLength(int length) +{ FFTdebugAssert(length < 1024 * 10, "SyncLookupTableLength : length too big"); FFTdebugAssert(length >= 0, "SyncLookupTableLength : length<0"); if (length > _lookupTabletLength) { @@ -269,7 +281,8 @@ static void SyncLookupTableLength(int length) { } } -static void copy_vect(float *vect, complexF **mat, int level, int signIndex, int M) { +static void copy_vect(float *vect, complexF **mat, int level, int signIndex, int M) +{ int j; if (signIndex) for (j = 0; j < M; j++) vect[j] = mat[level][j].b; @@ -285,7 +298,8 @@ static void copy_vect(float *vect, complexF **mat, int level, int signIndex, int The direction means either from time to frequency, or from frequency to time. ------------------------------------------------------*/ -static void FFT(float *data, int data_length, int length, int direction) { +static void FFT(float *data, int data_length, int length, int direction) +{ FFTdebugAssert(data != NULL, "FFT : DATA = NULL"); FFTdebugAssert(data_length >= length * 2, "FFT : data_length < length*2"); FFTdebugAssert(FFTisPowerOf2(length) == 1, "FFT : length is not a power of 2"); @@ -351,7 +365,8 @@ static void FFT(float *data, int data_length, int length, int direction) { The vector data will be : A E H h G g F f */ -void RFFT(float *data, int data_length, int length, int direction) { +void RFFT(float *data, int data_length, int length, int direction) +{ FFTdebugAssert(data != NULL, "RFFT :data"); FFTdebugAssert(data_length >= length, "RFFT : length must be at least as large as data_length parameter"); FFTdebugAssert(FFTisPowerOf2(length) == 1, "RFFT : length must be a power of 2"); @@ -362,7 +377,8 @@ void RFFT(float *data, int data_length, int length, int direction) { if (direction == FourierForward) { c2 = -0.5f; FFT(data, data_length, length / 2, direction); - } else { + } + else { c2 = 0.5f; theta = -theta; } @@ -393,7 +409,8 @@ void RFFT(float *data, int data_length, int length, int direction) { float hir = data[0]; data[0] = hir + data[1]; data[1] = hir - data[1]; - } else { + } + else { float hir = data[0]; data[0] = c1 * (hir + data[1]); data[1] = c1 * (hir - data[1]); @@ -404,7 +421,8 @@ void RFFT(float *data, int data_length, int length, int direction) { RFFTforward performs a real FFT. Here, the result is given in the two vectors : re and im ------------------------------------------------------*/ -void RFFTforward(float *data, int length, float *re, float *im) { +void RFFTforward(float *data, int length, float *re, float *im) +{ int j; RFFT(data, length, length, FourierForward); re[0] = data[0]; @@ -424,7 +442,8 @@ void RFFTforward(float *data, int length, float *re, float *im) { one vector for the real parts and one for the imag ones. The results are given the same way. ------------------------------------------------------*/ -void CFFTforward(float *re, float *im, int length) { +void CFFTforward(float *re, float *im, int length) +{ float *rec, *imc; int j; rec = (float *)malloc(length * sizeof(float)); @@ -456,7 +475,8 @@ void CFFTforward(float *re, float *im, int length) { /*----------------------------------------------------- CFFTbackward performs a cplx FFT inverse . ------------------------------------------------------*/ -void CFFTbackward(float *re, float *im, int length) { +void CFFTbackward(float *re, float *im, int length) +{ float *a, *b; int j; a = (float *)malloc(length * sizeof(float)); @@ -498,7 +518,8 @@ void CFFTbackward(float *re, float *im, int length) { only 1D-FFT. We perform one 1D-FFT, then we swith 2 coords and perform another 1D-FFT and we repeat this process once. ------------------------------------------------------*/ -void FFTswitch_with_z(float ***vect, int dimension, int is_y) { +void FFTswitch_with_z(float ***vect, int dimension, int is_y) +{ float ***res; int x, y, z; res = (float ***)malloc(dimension * sizeof(float **)); @@ -521,7 +542,8 @@ void FFTswitch_with_z(float ***vect, int dimension, int is_y) { free(res); } -float ***FFTinv_quarter(float ***vect, int dimension) { +float ***FFTinv_quarter(float ***vect, int dimension) +{ int transl = dimension / 2; int x, y, z, k, j; float ***res; @@ -554,7 +576,8 @@ float ***FFTinv_quarter(float ***vect, int dimension) { } return (res); } -float argument(float re, float im) { +float argument(float re, float im) +{ if (re == 0 && im == 0) return 0; if (re > 0) return (atan(im / re)); if (re < 0) { @@ -569,7 +592,8 @@ float argument(float re, float im) { return (-M_PI / 2); } -void FFTreim_to_modarg(float ***re_mod, float ***im_arg, int l) { +void FFTreim_to_modarg(float ***re_mod, float ***im_arg, int l) +{ int x, y, z; float a, b; for (z = 0; z < l; z++) @@ -582,7 +606,8 @@ void FFTreim_to_modarg(float ***re_mod, float ***im_arg, int l) { } } -void FFTmodarg_to_reim(float ***re_mod, float ***im_arg, int l) { +void FFTmodarg_to_reim(float ***re_mod, float ***im_arg, int l) +{ int x, y, z; float a, b; for (z = 0; z < l; z++) @@ -595,7 +620,8 @@ void FFTmodarg_to_reim(float ***re_mod, float ***im_arg, int l) { } } -float FFTdist(int x, int y, int z, int len) { +float FFTdist(int x, int y, int z, int len) +{ return ((x - (float)len / 2) * (x - (float)len / 2) + (y - (float)len / 2) * (y - (float)len / 2) + (z - (float)len / 2) * (z - (float)len / 2)); } diff --git a/utils/field_code.c b/utils/field_code.c index cc3400609ee..fcf0fe5654e 100644 --- a/utils/field_code.c +++ b/utils/field_code.c @@ -32,7 +32,8 @@ #include "field_code.h" -char *ReturnFieldName(int which_field) { +char *ReturnFieldName(int which_field) +{ switch (which_field) { case OVERLAY_FRAME: return (OVERLAY_NAME); @@ -90,7 +91,8 @@ char *ReturnFieldName(int which_field) { return NULL; } -int IsDistanceField(int which_field) { +int IsDistanceField(int which_field) +{ switch (which_field) { case OVERLAY_FRAME: return (0); @@ -146,12 +148,14 @@ int IsDistanceField(int which_field) { return 0; } -int InitFieldLabel(FIELD_LABEL *label) { +int InitFieldLabel(FIELD_LABEL *label) +{ memset(label, 0, sizeof(FIELD_LABEL)); return NO_ERROR; } -int SetFieldLabel(FIELD_LABEL *label, int field, int frame, float l_corr, float l_pcorr, int navgs, int which_norm) { +int SetFieldLabel(FIELD_LABEL *label, int field, int frame, float l_corr, float l_pcorr, int navgs, int which_norm) +{ label->field = field; label->frame = frame; label->type = IsDistanceField(field); @@ -164,7 +168,8 @@ int SetFieldLabel(FIELD_LABEL *label, int field, int frame, float l_corr, float return NO_ERROR; } -int SetFieldName(FIELD_LABEL *label, char *name) { +int SetFieldName(FIELD_LABEL *label, char *name) +{ label->name = name; return (NO_ERROR); } diff --git a/utils/filter.c b/utils/filter.c index 8578d4cd9d1..432d336b4ce 100644 --- a/utils/filter.c +++ b/utils/filter.c @@ -79,7 +79,8 @@ extern int Gx, Gy; Description: ----------------------------------------------------------------------*/ -IMAGE *ImageNitShiFilter(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsize, double sigma, IMAGE *Idst) { +IMAGE *ImageNitShiFilter(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsize, double sigma, IMAGE *Idst) +{ static IMAGE *IE = NULL, *IF = NULL, *IG = NULL, *Iblur = NULL; IMAGE *Iin, *Iout; int rows, cols, x, y, whalf, xk, yk, xs, ys; @@ -97,7 +98,8 @@ IMAGE *ImageNitShiFilter(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsize, double si Iin = ImageAlloc(rows, cols, PFFLOAT, 1); ImageCopy(Isrc, Iin); ImageValRange(Isrc, &fmin, &fmax); - } else + } + else Iin = Isrc; if (!Idst) Idst = ImageAlloc(rows, cols, PFFLOAT, 1); @@ -199,7 +201,8 @@ IMAGE *ImageNitShiFilter(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsize, double si Description: ----------------------------------------------------------------------*/ -int ImageBuildExponentialFilter(IMAGE *gradImage, int wsize, float k, IMAGE *offsetImage, IMAGE *filterSequence) { +int ImageBuildExponentialFilter(IMAGE *gradImage, int wsize, float k, IMAGE *offsetImage, IMAGE *filterSequence) +{ int rows, cols, x, y, whalf, xc, yc, x0, y0, dx, dy, frame; float fpix, *g, norm, val, *filterPix; static float *gaussian = NULL; @@ -247,7 +250,8 @@ int ImageBuildExponentialFilter(IMAGE *gradImage, int wsize, float k, IMAGE *off if (offsetImage) { dx = nint(*IMAGEFpix(offsetImage, x0, y0)); dy = nint(*IMAGEIseq_pix(offsetImage, x0, y0, 1)); - } else + } + else dx = dy = 0; norm = 0.0f; @@ -312,7 +316,8 @@ int ImageSpaceVariantFilter(IMAGE *inImage, IMAGE *filterSequence, IMAGE *outIma Description: ----------------------------------------------------------------------*/ -int ImageExponentialFilter(IMAGE *inImage, IMAGE *gradImage, int wsize, float k, IMAGE *offsetImage, IMAGE *outImage) { +int ImageExponentialFilter(IMAGE *inImage, IMAGE *gradImage, int wsize, float k, IMAGE *offsetImage, IMAGE *outImage) +{ int rows, cols, x, y, whalf, xc, yc, x0, y0, dx, dy; float fpix, *g, norm, val, *filterPix, *filter, *outPix; static float w, *gaussian; @@ -364,7 +369,8 @@ int ImageExponentialFilter(IMAGE *inImage, IMAGE *gradImage, int wsize, float k, if (offsetImage) { dx = nint(*IMAGEFpix(offsetImage, x0, y0)); dy = nint(*IMAGEFseq_pix(offsetImage, x0, y0, 1)); - } else + } + else dx = dy = 0; norm = 0.0f; @@ -444,7 +450,8 @@ int ImageExponentialFilter(IMAGE *inImage, IMAGE *gradImage, int wsize, float k, Description: ----------------------------------------------------------------------*/ static int compare_sort_array(const void *pf1, const void *pf2); -int ImageMedianFilter(IMAGE *inImage, int wsize, IMAGE *offsetImage, IMAGE *outImage) { +int ImageMedianFilter(IMAGE *inImage, int wsize, IMAGE *offsetImage, IMAGE *outImage) +{ static float *sort_array = NULL; static int sort_size = 0; int ecode, x0, y0, rows, cols, x, y, whalf, yc, dx, dy, frame, wsq, median_index; @@ -463,7 +470,8 @@ int ImageMedianFilter(IMAGE *inImage, int wsize, IMAGE *offsetImage, IMAGE *outI ImageScale(inImage, inImage, 0.0f, 255.0f); ImageCopy(inImage, Iin); ImageScale(inImage, inImage, min_val, max_val); /* restore old image */ - } else + } + else Iin = inImage; if (inImage->pixel_format != PFBYTE) @@ -518,7 +526,8 @@ int ImageMedianFilter(IMAGE *inImage, int wsize, IMAGE *offsetImage, IMAGE *outI if (offsetImage) { dx = nint(*IMAGEFpix(offsetImage, x0, y0)); dy = nint(*IMAGEFseq_pix(offsetImage, x0, y0, 1)); - } else + } + else dx = dy = 0; for (sptr = sort_array, y = -whalf; y <= whalf; y++) { @@ -565,7 +574,8 @@ int ImageMedianFilter(IMAGE *inImage, int wsize, IMAGE *offsetImage, IMAGE *outI } return (0); } -static int compare_sort_array(const void *pf1, const void *pf2) { +static int compare_sort_array(const void *pf1, const void *pf2) +{ register float f1, f2; f1 = *(float *)pf1; @@ -584,7 +594,8 @@ static int compare_sort_array(const void *pf1, const void *pf2) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageConvolveGaussianByte(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int dst_frameno) { +IMAGE *ImageConvolveGaussianByte(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int dst_frameno) +{ static IMAGE *Itmp = NULL; int ksize; float *kernel; @@ -614,7 +625,8 @@ IMAGE *ImageConvolveGaussianByte(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int ds Description: ----------------------------------------------------------------------*/ -IMAGE *ImageConvolveGaussian(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int dst_frameno) { +IMAGE *ImageConvolveGaussian(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int dst_frameno) +{ static IMAGE *Itmp = NULL; int ksize; float *kernel, *buf; @@ -645,7 +657,8 @@ IMAGE *ImageConvolveGaussian(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int dst_fr Description: ----------------------------------------------------------------------*/ -IMAGE *ImageCircularConvolveGaussian(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int dst_frameno) { +IMAGE *ImageCircularConvolveGaussian(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, int dst_frameno) +{ static IMAGE *Itmp = NULL; int ksize; float *kernel, *buf; @@ -681,7 +694,8 @@ IMAGE *ImageCircularConvolveGaussian(IMAGE *Isrc, IMAGE *gImage, IMAGE *Iout, in Description: ----------------------------------------------------------------------*/ -IMAGE *ImageConvolveGaussianFrames(IMAGE *Isrc, IMAGE *gImage, IMAGE *Idst) { +IMAGE *ImageConvolveGaussianFrames(IMAGE *Isrc, IMAGE *gImage, IMAGE *Idst) +{ int frame, src_frames, dst_frames; byte *src_buf, *dst_buf; @@ -710,7 +724,8 @@ IMAGE *ImageConvolveGaussianFrames(IMAGE *Isrc, IMAGE *gImage, IMAGE *Idst) { Description: ----------------------------------------------------------------------*/ -void ImageConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { +void ImageConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) +{ int x, y, width, height, halflen; register int i; float *outPix; @@ -767,7 +782,8 @@ void ImageConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { *outPix++ = total; } } - } else { + } + else { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { inBase = IMAGEFpix(I, x, 0); @@ -785,7 +801,8 @@ void ImageConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { Description: ----------------------------------------------------------------------*/ -void ImageCircularConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { +void ImageCircularConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) +{ int x, y, width, height, halflen, xi, yi; register int i; float *outPix; @@ -814,7 +831,8 @@ void ImageCircularConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { *outPix++ = total; } } - } else { + } + else { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { inBase = IMAGEFpix(I, x, 0); @@ -838,7 +856,8 @@ void ImageCircularConvolve1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { Description: ----------------------------------------------------------------------*/ -void ImageConvolve1dByte(IMAGE *I, IMAGE *J, float k[], int len, int axis) { +void ImageConvolve1dByte(IMAGE *I, IMAGE *J, float k[], int len, int axis) +{ int x, y, width, height, halflen; register int i; register float *ki, total; @@ -895,7 +914,8 @@ void ImageConvolve1dByte(IMAGE *I, IMAGE *J, float k[], int len, int axis) { *outPix++ = (byte)total; } } - } else { + } + else { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { inBase = IMAGEpix(I, x, 0); @@ -919,7 +939,8 @@ void ImageConvolve1dByte(IMAGE *I, IMAGE *J, float k[], int len, int axis) { #define K_A 0.4f static float kernel[KERNEL_SIZE] = {0.25f - K_A / 2.0f, .25f, K_A, 0.25f, 0.25f - K_A / 2.0f}; -IMAGE *ImageReduce(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageReduce(IMAGE *Isrc, IMAGE *Idst) +{ int rows, cols; static IMAGE *Itmp = NULL; @@ -933,7 +954,8 @@ IMAGE *ImageReduce(IMAGE *Isrc, IMAGE *Idst) { if (!Itmp) { Itmp = ImageAlloc(rows, cols, PFFLOAT, 1); if (!Itmp) return (NULL); - } else { + } + else { ImageSetSize(Itmp, rows, cols); ImageClearArea(Itmp, 0, 0, -1, -1, 0.0f, -1); } @@ -944,7 +966,8 @@ IMAGE *ImageReduce(IMAGE *Isrc, IMAGE *Idst) { if (!ImageCheckSize(Isrc, Idst, rows, cols, 0)) { if (Idst) ImageFree(&Idst); Idst = ImageAlloc(rows, cols, PFFLOAT, 1); - } else + } + else ImageSetSize(Idst, rows, cols); /* blur vertically */ @@ -967,7 +990,8 @@ IMAGE *ImageReduce(IMAGE *Isrc, IMAGE *Idst) { Description: use k[] to scale the image down by 2. ----------------------------------------------------------------------*/ -void ImageReduce1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { +void ImageReduce1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) +{ int x, y, i, Jwidth, Jheight, xi, yi, halflen, Iwidth, Iheight; float total; @@ -1005,7 +1029,8 @@ void ImageReduce1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { *IMAGEFpix(J, x, y) = total; } } - } else { + } + else { for (y = 0; y < Jheight; y++) { for (x = 0; x < Jwidth; x++) { total = 0.0f; @@ -1046,7 +1071,8 @@ void ImageReduce1d(IMAGE *I, IMAGE *J, float k[], int len, int axis) { construct a gaussian bump which tails to 0. Returns an image which is ((4*xsigma)+1) x ((4*ysigma)+1) ----------------------------------------------------------------------*/ -IMAGE *ImageGaussian(float xsigma, float ysigma) { +IMAGE *ImageGaussian(float xsigma, float ysigma) +{ IMAGE *image; float norm, ytwo_sigma, xtwo_sigma, fx, fy, k; int x, y, xlen, ylen, xhalf, yhalf; @@ -1106,7 +1132,8 @@ IMAGE *ImageGaussian(float xsigma, float ysigma) { Returns an image which is (8*sigma)+1 (Nitzberg and Shiota, 1993) ----------------------------------------------------------------------*/ -IMAGE *ImageGaussian1d(float sigma, int max_len) { +IMAGE *ImageGaussian1d(float sigma, int max_len) +{ IMAGE *image; float norm, two_sigma, fx, k; int x, half, len; @@ -1145,7 +1172,8 @@ IMAGE *ImageGaussian1d(float sigma, int max_len) { Description: ----------------------------------------------------------------------*/ -int ImageSobel(IMAGE *Isrc, IMAGE *gradImage, IMAGE *dxImage, IMAGE *dyImage) { +int ImageSobel(IMAGE *Isrc, IMAGE *gradImage, IMAGE *dxImage, IMAGE *dyImage) +{ static IMAGE *xImage = NULL, *yImage = NULL; IMAGE *Iin; int x, y, rows, cols; @@ -1154,7 +1182,8 @@ int ImageSobel(IMAGE *Isrc, IMAGE *gradImage, IMAGE *dxImage, IMAGE *dyImage) { if (Isrc->pixel_format != PFFLOAT) { Iin = ImageAlloc(Isrc->rows, Isrc->cols, PFFLOAT, 1); ImageCopy(Isrc, Iin); - } else + } + else Iin = Isrc; rows = Isrc->rows; @@ -1164,7 +1193,8 @@ int ImageSobel(IMAGE *Isrc, IMAGE *gradImage, IMAGE *dxImage, IMAGE *dyImage) { if (!ImageCheckSize(Isrc, xImage, 0, 0, 0)) { if (xImage) ImageFree(&xImage); xImage = ImageAlloc(rows, cols, PFFLOAT, 1); - } else + } + else ImageSetSize(xImage, rows, cols); dxImage = xImage; @@ -1174,7 +1204,8 @@ int ImageSobel(IMAGE *Isrc, IMAGE *gradImage, IMAGE *dxImage, IMAGE *dyImage) { if (!ImageCheckSize(Isrc, yImage, 0, 0, 0)) { if (yImage) ImageFree(&yImage); yImage = ImageAlloc(rows, cols, PFFLOAT, 1); - } else + } + else ImageSetSize(yImage, rows, cols); dyImage = yImage; @@ -1217,7 +1248,8 @@ int ImageSobel(IMAGE *Isrc, IMAGE *gradImage, IMAGE *dxImage, IMAGE *dyImage) { */ #define FAST_SOBEL 1 #if !FAST_SOBEL -int ImageSobelX(IMAGE *Isrc, IMAGE *xImage) { +int ImageSobelX(IMAGE *Isrc, IMAGE *xImage) +{ register float *tl_pix, *ml_pix, *bl_pix, *tr_pix, *mr_pix, *br_pix, *outPtr; int rows, cols, row, col; @@ -1261,7 +1293,8 @@ use overlapping windows to speed up sobel calculation -0.50 0 0.50 -0.25 0 0.25 ----------------------------------------------------------------------*/ -int ImageSobelX(IMAGE *Isrc, IMAGE *xImage) { +int ImageSobelX(IMAGE *Isrc, IMAGE *xImage) +{ register float *tr_pix, *mr_pix, *br_pix, *outPtr, left, middle, right; int rows, cols, row, col; @@ -1301,7 +1334,8 @@ int ImageSobelX(IMAGE *Isrc, IMAGE *xImage) { 0.25 .50 0.25 ----------------------------------------------------------------------*/ #if !FAST_SOBEL -int ImageSobelY(IMAGE *Isrc, IMAGE *yImage) { +int ImageSobelY(IMAGE *Isrc, IMAGE *yImage) +{ register float *tl_pix, *tm_pix, *tr_pix, *bl_pix, *bm_pix, *br_pix, *outPtr; int rows, cols, row, col; @@ -1345,7 +1379,8 @@ use overlapping windows to speed up sobel calculation 0 0 0 0.25 .50 0.25 ----------------------------------------------------------------------*/ -int ImageSobelY(IMAGE *Isrc, IMAGE *yImage) { +int ImageSobelY(IMAGE *Isrc, IMAGE *yImage) +{ register float *tr_pix, *br_pix, *outPtr, left, middle, right; int rows, cols, row, col; @@ -1380,7 +1415,8 @@ int ImageSobelY(IMAGE *Isrc, IMAGE *yImage) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageXDerivative(IMAGE *Isrc, IMAGE *xImage) { +IMAGE *ImageXDerivative(IMAGE *Isrc, IMAGE *xImage) +{ if (!xImage) xImage = ImageAlloc(Isrc->rows, Isrc->cols, PFFLOAT, 1); ImageConvolve3x3(Isrc, sx, xImage); @@ -1392,7 +1428,8 @@ IMAGE *ImageXDerivative(IMAGE *Isrc, IMAGE *xImage) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageYDerivative(IMAGE *Isrc, IMAGE *yImage) { +IMAGE *ImageYDerivative(IMAGE *Isrc, IMAGE *yImage) +{ if (!yImage) yImage = ImageAlloc(Isrc->rows, Isrc->cols, PFFLOAT, 1); ImageConvolve3x3(Isrc, sy, yImage); @@ -1404,7 +1441,8 @@ IMAGE *ImageYDerivative(IMAGE *Isrc, IMAGE *yImage) { Description: ----------------------------------------------------------------------*/ -int ImageConvolve3x3(IMAGE *Isrc, float kernel[], IMAGE *outImage) { +int ImageConvolve3x3(IMAGE *Isrc, float kernel[], IMAGE *outImage) +{ int rows, cols, x, y, xk, yk, k, xi, yi, frame; float *fkpix, sum, *fopix, *fipix; @@ -1459,7 +1497,8 @@ static int yoffsets[] = {-1, 0, 0, 0, 1}; static float weights[] = {ONE_EIGHTH, ONE_EIGHTH, -0.5f, ONE_EIGHTH, ONE_EIGHTH}; #define LAPLACIAN_POINTS (sizeof(xoffsets) / sizeof(xoffsets[0])) -IMAGE *ImageLaplacian(IMAGE *Isrc, IMAGE *outImage) { +IMAGE *ImageLaplacian(IMAGE *Isrc, IMAGE *outImage) +{ int rows, cols, x, y, xi, yi, i; float *fkpix, sum, *fopix, fival; @@ -1506,7 +1545,8 @@ IMAGE *ImageLaplacian(IMAGE *Isrc, IMAGE *outImage) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageSigmaFilter(IMAGE *Isrc, int wsize, float nsigma, IMAGE *Ioffset, IMAGE *Idst) { +IMAGE *ImageSigmaFilter(IMAGE *Isrc, int wsize, float nsigma, IMAGE *Ioffset, IMAGE *Idst) +{ float *sort_array; int x0, y0, rows, cols, x, y, whalf, yc, dx, dy, frame, wsq, w, npix; float *sptr, *outPix, min_val, max_val, *inPix, val, mean, sigma, sigma_thresh, filter_val; @@ -1520,7 +1560,8 @@ IMAGE *ImageSigmaFilter(IMAGE *Isrc, int wsize, float nsigma, IMAGE *Ioffset, IM Iin = ImageAlloc(rows, cols, PFFLOAT, 1); ImageCopy(Isrc, Iin); ImageValRange(Isrc, &min_val, &max_val); - } else + } + else Iin = Isrc; if (!Idst) Idst = ImageAlloc(rows, cols, PFFLOAT, 1); @@ -1547,7 +1588,8 @@ IMAGE *ImageSigmaFilter(IMAGE *Isrc, int wsize, float nsigma, IMAGE *Ioffset, IM if (Ioffset) { dx = nint(*IMAGEFpix(Ioffset, x0, y0)); dy = nint(*IMAGEFseq_pix(Ioffset, x0, y0, 1)); - } else + } + else dx = dy = 0; for (sptr = sort_array, y = -whalf; y <= whalf; y++) { @@ -1618,7 +1660,8 @@ IMAGE *ImageSigmaFilter(IMAGE *Isrc, int wsize, float nsigma, IMAGE *Ioffset, IM ----------------------------------------------------------------------*/ static int imageMeanFilter3x3(IMAGE *Isrc, IMAGE *Idst); static int imageMeanFilter2x2(IMAGE *Isrc, IMAGE *Idst); -IMAGE *ImageMeanFilter(IMAGE *Isrc, int wsize, IMAGE *Idst) { +IMAGE *ImageMeanFilter(IMAGE *Isrc, int wsize, IMAGE *Idst) +{ IMAGE *Iout; int rows, cols; @@ -1658,7 +1701,8 @@ IMAGE *ImageMeanFilter(IMAGE *Isrc, int wsize, IMAGE *Idst) { Description: ----------------------------------------------------------------------*/ -static int imageMeanFilter3x3(IMAGE *Isrc, IMAGE *Idst) { +static int imageMeanFilter3x3(IMAGE *Isrc, IMAGE *Idst) +{ float left, middle, right, *top, *center, *bottom, *out; int rows, cols, row, col, cols_minus_1, rows_minus_1; @@ -1787,7 +1831,8 @@ static int imageMeanFilter3x3(IMAGE *Isrc, IMAGE *Idst) { convolve with a 2x2 averaging filter using overlap for efficient implementation ----------------------------------------------------------------------*/ -static int imageMeanFilter2x2(IMAGE *Isrc, IMAGE *Idst) { +static int imageMeanFilter2x2(IMAGE *Isrc, IMAGE *Idst) +{ float left, right, *top, *bottom, *out; int rows, cols, row, col, cols_minus_1, rows_minus_1; @@ -1862,7 +1907,8 @@ static int imageMeanFilter2x2(IMAGE *Isrc, IMAGE *Idst) { Description: gray-scale 3x3 dilation - local max ----------------------------------------------------------------------*/ -IMAGE *ImageGreyDilate(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageGreyDilate(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Iout; int rows, cols, x, y, xk, yk, xi, yi, frame; float image_fmin, image_fmax, fmax, *fopix, *fipix; @@ -1930,7 +1976,8 @@ IMAGE *ImageGreyDilate(IMAGE *Isrc, IMAGE *Idst) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageGreyErode(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageGreyErode(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Iout; int rows, cols, x, y, xk, yk, xi, yi, frame; float image_fmin, image_fmax, fmin, *fopix, *fipix; @@ -1999,7 +2046,8 @@ IMAGE *ImageGreyErode(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ -IMAGE *ImageCorrelate(IMAGE *Itemplate, IMAGE *Isrc, int zeropad, IMAGE *Icorr) { +IMAGE *ImageCorrelate(IMAGE *Itemplate, IMAGE *Isrc, int zeropad, IMAGE *Icorr) +{ IMAGE *Iconj, *Ifcorr, *Ifsrc, *Ireal, *Iimag, *Iftmp; int ecode; @@ -2034,7 +2082,8 @@ IMAGE *ImageCorrelate(IMAGE *Itemplate, IMAGE *Isrc, int zeropad, IMAGE *Icorr) ImageCombine(Ireal, Iimag, Icorr); ImageFree(&Ireal); ImageFree(&Iimag); - } else { + } + else { ecode = h_flipquad(Icorr, Icorr); if (ecode != HIPS_OK) ErrorExit(ecode, "ImageCorrelate: h_flipquad failed (%d)\n", ecode); } @@ -2057,7 +2106,8 @@ IMAGE *ImageCorrelate(IMAGE *Itemplate, IMAGE *Isrc, int zeropad, IMAGE *Icorr) region of the point x0,y0. The size of the correlation region is given by wsize ------------------------------------------------------*/ -IMAGE *ImageCorrelateRegion(IMAGE *Isrc, IMAGE *Ikernel, IMAGE *Idst, int row0, int col0, int wsize) { +IMAGE *ImageCorrelateRegion(IMAGE *Isrc, IMAGE *Ikernel, IMAGE *Idst, int row0, int col0, int wsize) +{ int col_offset, row_offset, row, col, rows, cols, whalf, krow0, kcol0, rowstart, rowend, colstart, colend, krow, kcol, drow, dcol; CPIX *src, *kernel; @@ -2109,7 +2159,8 @@ IMAGE *ImageCorrelateRegion(IMAGE *Isrc, IMAGE *Ikernel, IMAGE *Idst, int row0, return (Idst); } -IMAGE *ImageLOGFilter(IMAGE *Isrc, float sigma, IMAGE *Idst) { +IMAGE *ImageLOGFilter(IMAGE *Isrc, float sigma, IMAGE *Idst) +{ IMAGE *Ig, *Itmp; Ig = ImageGaussian1d(sigma, 0); @@ -2124,7 +2175,8 @@ IMAGE *ImageLOGFilter(IMAGE *Isrc, float sigma, IMAGE *Idst) { ImageFree(&Ig); return (Idst); } -IMAGE *ImageDOGFilter(IMAGE *Isrc, float psigma, float nsigma, IMAGE *Idst) { +IMAGE *ImageDOGFilter(IMAGE *Isrc, float psigma, float nsigma, IMAGE *Idst) +{ IMAGE *Igp, *Ign, *Itmpp, *Itmpn; Igp = ImageGaussian1d(psigma, 0); diff --git a/utils/fio.c b/utils/fio.c index c684f2f43e7..8648849ad32 100644 --- a/utils/fio.c +++ b/utils/fio.c @@ -42,7 +42,8 @@ int fio_npushes = -1; char fio_dirstack[FIO_NPUSHES_MAX][1000]; -FILE *MGHopen_file(const char *fname, const char *rwmode) { +FILE *MGHopen_file(const char *fname, const char *rwmode) +{ FILE *f1; if ((f1 = fopen(fname, rwmode)) == NULL) { @@ -52,14 +53,16 @@ FILE *MGHopen_file(const char *fname, const char *rwmode) { return f1; } -int putf(float f, FILE *fp) { +int putf(float f, FILE *fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) f = swapFloat(f); #endif return (fwrite(&f, 4, 1, fp)); } -float getf(FILE *fp) { +float getf(FILE *fp) +{ float f; if (fread(&f, 4, 1, fp) != 1) { @@ -71,7 +74,8 @@ float getf(FILE *fp) { return f; } -int fread1(int *v, FILE *fp) { +int fread1(int *v, FILE *fp) +{ unsigned char c; int ret; @@ -80,7 +84,8 @@ int fread1(int *v, FILE *fp) { return (ret); } -int fread2(int *v, FILE *fp) { +int fread2(int *v, FILE *fp) +{ short s; int ret; @@ -92,7 +97,8 @@ int fread2(int *v, FILE *fp) { return (ret); } -int fread3(int *v, FILE *fp) { +int fread3(int *v, FILE *fp) +{ unsigned int i = 0; int ret; @@ -104,7 +110,8 @@ int fread3(int *v, FILE *fp) { return (ret); } -int fread4(float *v, FILE *fp) { +int fread4(float *v, FILE *fp) +{ float f; int ret; @@ -116,13 +123,15 @@ int fread4(float *v, FILE *fp) { return (ret); } -int fwrite1(int v, FILE *fp) { +int fwrite1(int v, FILE *fp) +{ unsigned char c = (unsigned char)v; return (fwrite(&c, 1, 1, fp)); } -int fwrite2(int v, FILE *fp) { +int fwrite2(int v, FILE *fp) +{ short s; if (v > 0x7fff) /* don't let it overflow */ @@ -136,7 +145,8 @@ int fwrite2(int v, FILE *fp) { return (fwrite(&s, 2, 1, fp)); } -int fwrite3(int v, FILE *fp) { +int fwrite3(int v, FILE *fp) +{ unsigned int i = (unsigned int)(v << 8); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -145,20 +155,23 @@ int fwrite3(int v, FILE *fp) { return (fwrite(&i, 3, 1, fp)); } -int fwrite4(int v, FILE *fp) { +int fwrite4(int v, FILE *fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) v = swapInt(v); #endif return (fwrite(&v, 4, 1, fp)); } -int fwriteShort(short s, FILE *fp) { +int fwriteShort(short s, FILE *fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) s = swapShort(s); #endif return (fwrite(&s, sizeof(short), 1, fp)); } -double freadDouble(FILE *fp) { +double freadDouble(FILE *fp) +{ double d; int ret; @@ -170,7 +183,8 @@ double freadDouble(FILE *fp) { return (d); } -int freadInt(FILE *fp) { +int freadInt(FILE *fp) +{ int i; if (fread(&i, sizeof(int), 1, fp) != 1) { @@ -181,7 +195,8 @@ int freadInt(FILE *fp) { #endif return (i); } -long long freadLong(FILE *fp) { +long long freadLong(FILE *fp) +{ long long i; if (fread(&i, sizeof(long long), 1, fp) != 1) { @@ -193,7 +208,8 @@ long long freadLong(FILE *fp) { return (i); } -short freadShort(FILE *fp) { +short freadShort(FILE *fp) +{ short s; if (fread(&s, sizeof(short), 1, fp) != 1) { @@ -214,7 +230,8 @@ short freadShort(FILE *fp) { /* while (fread..Ex(., fp)) */ /* dosomething(); */ /*******************************************************/ -int freadFloatEx(float *pf, FILE *fp) { +int freadFloatEx(float *pf, FILE *fp) +{ int ret; ret = fread(pf, sizeof(float), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -223,7 +240,8 @@ int freadFloatEx(float *pf, FILE *fp) { return ret; } -int freadDoubleEx(double *pd, FILE *fp) { +int freadDoubleEx(double *pd, FILE *fp) +{ int ret; ret = fread(pd, sizeof(double), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -232,7 +250,8 @@ int freadDoubleEx(double *pd, FILE *fp) { return ret; } -int freadIntEx(int *pi, FILE *fp) { +int freadIntEx(int *pi, FILE *fp) +{ int nread; nread = fread(pi, sizeof(int), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -241,7 +260,8 @@ int freadIntEx(int *pi, FILE *fp) { return (nread); } -int freadShortEx(short *ps, FILE *fp) { +int freadShortEx(short *ps, FILE *fp) +{ int nread; nread = fread(ps, sizeof(short), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -251,14 +271,16 @@ int freadShortEx(short *ps, FILE *fp) { } /******************************************************/ -int fwriteInt(int v, FILE *fp) { +int fwriteInt(int v, FILE *fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) v = swapInt(v); #endif return (fwrite(&v, sizeof(int), 1, fp)); } -int fwriteLong(long long v, FILE *fp) { +int fwriteLong(long long v, FILE *fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) v = swapLong64(v); #endif @@ -266,7 +288,8 @@ int fwriteLong(long long v, FILE *fp) { } /*----------------------------------------*/ -float freadFloat(FILE *fp) { +float freadFloat(FILE *fp) +{ char buf[4]; float f; int ret; @@ -284,7 +307,8 @@ float freadFloat(FILE *fp) { return (f); } /*----------------------------------------*/ -int fwriteFloat(float f, FILE *fp) { +int fwriteFloat(float f, FILE *fp) +{ int ret; char buf[4]; memmove(buf, &f, 4); @@ -297,7 +321,8 @@ int fwriteFloat(float f, FILE *fp) { return (ret); } /*----------------------------------------*/ -int fwriteDouble(double d, FILE *fp) { +int fwriteDouble(double d, FILE *fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) d = swapDouble(d); #endif @@ -305,7 +330,8 @@ int fwriteDouble(double d, FILE *fp) { } /*------ znzlib support ------------*/ -int znzread1(int *v, znzFile fp) { +int znzread1(int *v, znzFile fp) +{ unsigned char c; int ret; @@ -314,7 +340,8 @@ int znzread1(int *v, znzFile fp) { return (ret); } -int znzread2(int *v, znzFile fp) { +int znzread2(int *v, znzFile fp) +{ short s; int ret; @@ -326,7 +353,8 @@ int znzread2(int *v, znzFile fp) { return (ret); } -int znzread3(int *v, znzFile fp) { +int znzread3(int *v, znzFile fp) +{ unsigned int i = 0; int ret; @@ -338,7 +366,8 @@ int znzread3(int *v, znzFile fp) { return (ret); } -int znzread4(float *v, znzFile fp) { +int znzread4(float *v, znzFile fp) +{ float f; int ret; @@ -350,13 +379,15 @@ int znzread4(float *v, znzFile fp) { return (ret); } -int znzwrite1(int v, znzFile fp) { +int znzwrite1(int v, znzFile fp) +{ unsigned char c = (unsigned char)v; return (znzwrite(&c, 1, 1, fp)); } -int znzwrite2(int v, znzFile fp) { +int znzwrite2(int v, znzFile fp) +{ short s; if (v > 0x7fff) /* don't let it overflow */ @@ -370,7 +401,8 @@ int znzwrite2(int v, znzFile fp) { return (znzwrite(&s, 2, 1, fp)); } -int znzwrite3(int v, znzFile fp) { +int znzwrite3(int v, znzFile fp) +{ unsigned int i = (unsigned int)(v << 8); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -379,21 +411,24 @@ int znzwrite3(int v, znzFile fp) { return (znzwrite(&i, 3, 1, fp)); } -int znzwrite4(int v, znzFile fp) { +int znzwrite4(int v, znzFile fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) v = swapInt(v); #endif return (znzwrite(&v, 4, 1, fp)); } -int znzwriteShort(short s, znzFile fp) { +int znzwriteShort(short s, znzFile fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) s = swapShort(s); #endif return (znzwrite(&s, sizeof(short), 1, fp)); } -double znzreadDouble(znzFile fp) { +double znzreadDouble(znzFile fp) +{ double d; int ret; @@ -405,7 +440,8 @@ double znzreadDouble(znzFile fp) { return (d); } -int znzreadInt(znzFile fp) { +int znzreadInt(znzFile fp) +{ int i; if (znzread(&i, sizeof(int), 1, fp) != 1) { @@ -417,7 +453,8 @@ int znzreadInt(znzFile fp) { return (i); } -long long znzreadLong(znzFile fp) { +long long znzreadLong(znzFile fp) +{ long long i; if (znzread(&i, sizeof(long long), 1, fp) != 1) { @@ -429,7 +466,8 @@ long long znzreadLong(znzFile fp) { return (i); } -short znzreadShort(znzFile fp) { +short znzreadShort(znzFile fp) +{ int nread; short s; @@ -453,7 +491,8 @@ short znzreadShort(znzFile fp) { because TAGwrite() does not do a byte order swap. Use znzTAGreadFloat() instead of znzreadFloatEx(). */ -int znzreadFloatEx(float *pf, znzFile fp) { +int znzreadFloatEx(float *pf, znzFile fp) +{ int ret; ret = znzread(pf, sizeof(float), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -462,7 +501,8 @@ int znzreadFloatEx(float *pf, znzFile fp) { return ret; } -int znzreadDoubleEx(double *pd, znzFile fp) { +int znzreadDoubleEx(double *pd, znzFile fp) +{ int ret; ret = znzread(pd, sizeof(double), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -471,7 +511,8 @@ int znzreadDoubleEx(double *pd, znzFile fp) { return ret; } -int znzreadIntEx(int *pi, znzFile fp) { +int znzreadIntEx(int *pi, znzFile fp) +{ int nread; nread = znzread(pi, sizeof(int), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -480,7 +521,8 @@ int znzreadIntEx(int *pi, znzFile fp) { return (nread); } -int znzreadShortEx(short *ps, znzFile fp) { +int znzreadShortEx(short *ps, znzFile fp) +{ int nread; nread = znzread(ps, sizeof(short), 1, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -490,14 +532,16 @@ int znzreadShortEx(short *ps, znzFile fp) { } /******************************************************/ -int znzwriteInt(int v, znzFile fp) { +int znzwriteInt(int v, znzFile fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) v = swapInt(v); #endif return (znzwrite(&v, sizeof(int), 1, fp)); } -int znzwriteLong(long long v, znzFile fp) { +int znzwriteLong(long long v, znzFile fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) v = swapLong64(v); #endif @@ -505,7 +549,8 @@ int znzwriteLong(long long v, znzFile fp) { } /*----------------------------------------*/ -float znzreadFloat(znzFile fp) { +float znzreadFloat(znzFile fp) +{ char buf[4]; float f; int ret; @@ -523,7 +568,8 @@ float znzreadFloat(znzFile fp) { return (f); } /*----------------------------------------*/ -int znzwriteFloat(float f, znzFile fp) { +int znzwriteFloat(float f, znzFile fp) +{ int ret; char buf[4]; memmove(buf, &f, 4); @@ -536,7 +582,8 @@ int znzwriteFloat(float f, znzFile fp) { return (ret); } /*----------------------------------------*/ -int znzwriteDouble(double d, znzFile fp) { +int znzwriteDouble(double d, znzFile fp) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) d = swapDouble(d); #endif @@ -548,7 +595,8 @@ int znzwriteDouble(double d, znzFile fp) { of the unix dirname. Author: Douglas Greve, 9/10/2001 ------------------------------------------------------*/ -char *fio_dirname(const char *pathname) { +char *fio_dirname(const char *pathname) +{ int l, n; char *dirname; @@ -605,7 +653,8 @@ char *fio_dirname(const char *pathname) { of the unix basename. Author: Douglas Greve, 9/10/2001 ------------------------------------------------------*/ -char *fio_basename(const char *pathname, const char *ext) { +char *fio_basename(const char *pathname, const char *ext) +{ int l, n, lext; char *basename, *tmp; @@ -658,7 +707,8 @@ char *fio_basename(const char *pathname, const char *ext) { fio_extension() - returns the extension of the given filename. Author: Douglas Greve, 1/30/2002 -------------------------------------------------------------*/ -char *fio_extension(const char *pathname) { +char *fio_extension(const char *pathname) +{ int lpathname, n, lext; char *ext; @@ -691,7 +741,8 @@ char *fio_extension(const char *pathname) { dirname is treated as path to a filename. It will return 0 if the directory does not exist. ----------------------------------------------------- */ -int fio_DirIsWritable(const char *dirname, int fname) { +int fio_DirIsWritable(const char *dirname, int fname) +{ FILE *fp; char tmpstr[2000]; @@ -711,7 +762,8 @@ int fio_DirIsWritable(const char *dirname, int fname) { /*----------------------------------------------------- fio_FileExistsReadable() - file exists and is readable -----------------------------------------------------*/ -int fio_FileExistsReadable(const char *fname) { +int fio_FileExistsReadable(const char *fname) +{ FILE *fp; fp = fopen(fname, "r"); @@ -724,7 +776,8 @@ int fio_FileExistsReadable(const char *fname) { /*----------------------------------------------------- fio_IsDirectory(fname) - fname exists and is a directory -----------------------------------------------------*/ -int fio_IsDirectory(const char *fname) { +int fio_IsDirectory(const char *fname) +{ FILE *fp; struct stat buf; int err; @@ -740,7 +793,8 @@ int fio_IsDirectory(const char *fname) { fio_NLines() - get the number of lines. The line length should not exceed 4000 characters. ------------------------------------------------------------*/ -int fio_NLines(const char *fname) { +int fio_NLines(const char *fname) +{ FILE *fp; int nrows; char tmpstring[4001]; @@ -759,7 +813,8 @@ int fio_NLines(const char *fname) { } /*------------------------------------------------------------------------*/ -int fio_pushd(const char *dir) { +int fio_pushd(const char *dir) +{ extern int fio_npushes; extern char fio_dirstack[FIO_NPUSHES_MAX][1000]; int err; @@ -784,7 +839,8 @@ int fio_pushd(const char *dir) { return (0); } /*------------------------------------------------------------------------*/ -int fio_popd(void) { +int fio_popd(void) +{ extern int fio_npushes; extern char fio_dirstack[FIO_NPUSHES_MAX][1000]; int err; @@ -810,7 +866,8 @@ int fio_popd(void) { by pushing into the file dir, getting the cwd, appending the file basename to the cwd to get the full path, then popping the stack. -------------------------------------------------------------------*/ -char *fio_fullpath(const char *fname) { +char *fio_fullpath(const char *fname) +{ static char cwd[1000]; char *dirname, *basename; char *fullpath; @@ -840,7 +897,8 @@ char *fio_fullpath(const char *fname) { } // Replicates mkdir -p -int fio_mkdirp(const char *path, mode_t mode) { +int fio_mkdirp(const char *path, mode_t mode) +{ int l, n, m, nthseg, err; char seg[2000], path2[2000]; memset(path2, '\0', 2000); @@ -882,7 +940,8 @@ int fio_mkdirp(const char *path, mode_t mode) { The CRs can be replaced with a new line with cat file | sed 's/\r/\n/g' > newfile */ -int fio_FileHasCarriageReturn(char *fname) { +int fio_FileHasCarriageReturn(char *fname) +{ FILE *fp; char c; int n; diff --git a/utils/flash.c b/utils/flash.c index d7ffdbafa5f..64ec2c7fbfc 100644 --- a/utils/flash.c +++ b/utils/flash.c @@ -36,7 +36,8 @@ extern const char *Progname; #define T1_STEP_SIZE 5 #define T1_TO_INDEX(T1) (nint((T1 - MIN_T1) / T1_STEP_SIZE)) -typedef struct { +typedef struct +{ double *flash; /* forward model f(T1,TR,alpha) */ double TR; double alpha; @@ -55,7 +56,8 @@ static int ntables = 0; static double FLASHforwardModelLookup(double T1, double PD, double TR, double flip_angle); -double dFlash_dT1(double T1, double PD, double TR, double flip_angle, double TE) { +double dFlash_dT1(double T1, double PD, double TR, double flip_angle, double TE) +{ double e1, numer, denom; e1 = exp(TR / T1); @@ -66,7 +68,8 @@ double dFlash_dT1(double T1, double PD, double TR, double flip_angle, double TE) return (numer / denom); } -double dFlash_dPD(double T1, double PD, double TR, double flip_angle, double TE) { +double dFlash_dPD(double T1, double PD, double TR, double flip_angle, double TE) +{ double e1, numer, denom; e1 = exp(TR / T1); @@ -76,7 +79,8 @@ double dFlash_dPD(double T1, double PD, double TR, double flip_angle, double TE) return (numer / denom); } -double FLASHforwardModel(double T1, double PD, double TR, double flip_angle, double TE) { +double FLASHforwardModel(double T1, double PD, double TR, double flip_angle, double TE) +{ double FLASH, E1; double CFA, SFA; @@ -88,7 +92,8 @@ double FLASHforwardModel(double T1, double PD, double TR, double flip_angle, dou if (!DZERO(T1)) FLASH *= (1 - E1) / (1 - CFA * E1); return (FLASH); } -MRI *MRIparameterMapsToFlash(MRI *mri_src, MRI *mri_dst, double *TRs, double *TEs, double *FAs, int nflash) { +MRI *MRIparameterMapsToFlash(MRI *mri_src, MRI *mri_dst, double *TRs, double *TEs, double *FAs, int nflash) +{ int x, y, z, n; double T1, PD; double val; @@ -114,7 +119,8 @@ MRI *MRIparameterMapsToFlash(MRI *mri_src, MRI *mri_dst, double *TRs, double *TE return (mri_dst); } -int compute_T1_PD(int nvolumes, float *image_vals, double *TRs, double *FAs, double *TEs, double *pT1, double *pPD) { +int compute_T1_PD(int nvolumes, float *image_vals, double *TRs, double *FAs, double *TEs, double *pT1, double *pPD) +{ double best_T1, best_PD, norm_im, norm_pred, sse, best_sse, T1, pred_vals[MAX_FLASH_VOLUMES], error, upper_T1, lower_T1, mid_T1, upper_sse, lower_sse, mid_sse, upper_norm, mid_norm, lower_norm, range; int i, j, upper_j, lower_j, mid_j, niter; @@ -207,7 +213,8 @@ int compute_T1_PD(int nvolumes, float *image_vals, double *TRs, double *FAs, dou best_T1 = lower_T1; best_PD = norm_im / lower_norm; best_sse = lower_sse; - } else if (upper_sse < mid_sse) /* make upper new mid */ + } + else if (upper_sse < mid_sse) /* make upper new mid */ { mid_sse = upper_sse; mid_j = upper_j; @@ -238,14 +245,16 @@ int compute_T1_PD(int nvolumes, float *image_vals, double *TRs, double *FAs, dou *pPD = best_PD; return (NO_ERROR); } -static double FLASHforwardModelLookup(double T1, double PD, double TR, double flip_angle) { +static double FLASHforwardModelLookup(double T1, double PD, double TR, double flip_angle) +{ double FLASH; FLASH = lookup_flash_value(TR, flip_angle, PD, T1); return (FLASH); } -static int build_lookup_table(double tr, double flip_angle, double te, double min_T1, double max_T1, double step) { +static int build_lookup_table(double tr, double flip_angle, double te, double min_T1, double max_T1, double step) +{ FLT *flt; int i; double T1; @@ -273,7 +282,8 @@ static int build_lookup_table(double tr, double flip_angle, double te, double mi return (NO_ERROR); } -static FLT *find_lookup_table(double TR, double flip_angle) { +static FLT *find_lookup_table(double TR, double flip_angle) +{ int i; for (i = 0; i < ntables; i++) @@ -283,13 +293,15 @@ static FLT *find_lookup_table(double TR, double flip_angle) { return (&lookup_tables[i]); } -int FlashBuildLookupTables(int nvolumes, double *TRs, double *FAs, double *TEs) { +int FlashBuildLookupTables(int nvolumes, double *TRs, double *FAs, double *TEs) +{ int n; for (n = 0; n < nvolumes; n++) build_lookup_table(TRs[n], FAs[n], TEs[n], MIN_T1, MAX_T1, T1_STEP_SIZE); return (NO_ERROR); } -static double lookup_flash_value(double TR, double flip_angle, double PD, double T1) { +static double lookup_flash_value(double TR, double flip_angle, double PD, double T1) +{ int index; FLT *flt; double FLASH; @@ -304,7 +316,8 @@ static double lookup_flash_value(double TR, double flip_angle, double PD, double FLASH = PD * flt->flash[index]; return (FLASH); } -double FLASHforwardModelT2star(double T1, double PD, double T2star, double TR, double flip_angle, double TE) { +double FLASHforwardModelT2star(double T1, double PD, double T2star, double TR, double flip_angle, double TE) +{ double FLASH, E1; double CFA, SFA; diff --git a/utils/fmarchmesh.c b/utils/fmarchmesh.c index 083d1e0adb5..83d36d4e4a9 100644 --- a/utils/fmarchmesh.c +++ b/utils/fmarchmesh.c @@ -37,7 +37,8 @@ float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsigned char *label); float ComputeTInAcute(float, float, float, float, float); -float *FastMarchMesh(MRI_SURFACE *mesh, int *contour, int numinitvert, float thred) { +float *FastMarchMesh(MRI_SURFACE *mesh, int *contour, int numinitvert, float thred) +{ /* Compute the geodesic distance of surface vertices to the initial contour*/ /* vector 'contour' contains the indices of the vertice at the initial contour, i.e., vertices with zero distance. numinitvert is the size of @@ -217,7 +218,8 @@ float *FastMarchMesh(MRI_SURFACE *mesh, int *contour, int numinitvert, float thr /* compute the new T for vIDc based on the current T values of vIDa & vIDb */ /* Unfold the mesh around edge AB if C is an obtuse angle */ /* see Kimmel and Sethian for derivation of these formulae */ -float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsigned char *label) { +float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsigned char *label) +{ float a, b, c; VERTEX *Va, *Vb, *Vc; unsigned char la, lb; @@ -291,7 +293,8 @@ float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsig if (la == ALIVE && lb == ALIVE) { t = ComputeTInAcute(Ta, Tb, a, b, c); return t; - } else + } + else return (MIN(b + Ta, a + Tb)); /* Infinity + sth = Infinity */ } @@ -335,7 +338,8 @@ float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsig if (n0 == P2ID && n1 != UNotID) { UID = n1; break; - } else if (n1 == P2ID && n0 != UNotID) { + } + else if (n1 == P2ID && n0 != UNotID) { UID = n0; break; } @@ -374,14 +378,16 @@ float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsig P2A = UA; P2B = UB; P2C = UC; - } else if (UB > (UC + BC)) { /* Unfold along P2U */ + } + else if (UB > (UC + BC)) { /* Unfold along P2U */ UNotID = P1ID; P1ID = UID; P1P2 = P2U; P1A = UA; P1B = UB; P1C = UC; - } else { /* Stop Unfolding and compute T*/ + } + else { /* Stop Unfolding and compute T*/ /* Compute the actual lengthes */ UC = sqrt(UC); UA = sqrt(UA); @@ -389,14 +395,17 @@ float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsig if (label[UID] == (unsigned char)ALIVE) { if (la == ALIVE) { t1 = ComputeTInAcute(Ta, T[UID], UC, b, UA); - } else + } + else t1 = INFINITY; if (lb == ALIVE) { t2 = ComputeTInAcute(Tb, T[UID], UC, a, UB); - } else + } + else t2 = INFINITY; return MIN(t1, t2); - } else + } + else return (MIN(b + Ta, a + Tb)); } @@ -415,7 +424,8 @@ float ReCompute(int vIDc, int vIDa, int vIDb, MRI_SURFACE *mesh, float *T, unsig return (MIN(b + Ta, a + Tb)); } -float ComputeTInAcute(float Ta, float Tb, float a, float b, float c) { +float ComputeTInAcute(float Ta, float Tb, float a, float b, float c) +{ float t1, t2, t, CD, costheta; float aa, bb, cc, u, tmp; diff --git a/utils/fmriutils.c b/utils/fmriutils.c index 5e850725da7..ab307fb0a56 100644 --- a/utils/fmriutils.c +++ b/utils/fmriutils.c @@ -62,7 +62,8 @@ double round(double x); const char *fMRISrcVersion(void) { return ("$Id: fmriutils.c,v 1.80 2016/11/01 20:25:12 greve Exp $"); } /*--------------------------------------------------------*/ -MRI *fMRImatrixMultiply(MRI *inmri, MATRIX *M, MRI *outmri) { +MRI *fMRImatrixMultiply(MRI *inmri, MATRIX *M, MRI *outmri) +{ int c, r, s, fin, fout; int nframesout; float val; @@ -87,7 +88,8 @@ MRI *fMRImatrixMultiply(MRI *inmri, MATRIX *M, MRI *outmri) { return (NULL); } MRIcopyHeader(inmri, outmri); - } else { + } + else { if (outmri->width != inmri->width || outmri->height != inmri->height || outmri->depth != inmri->depth || outmri->nframes != nframesout) { printf("ERROR: fMRImatrixMultiply: output dimension mismatch\n"); @@ -131,7 +133,8 @@ and resets DOFAdjust=1. \param mask - only compute where mask > 0.5 (or everywhere if mask is NULL) \param covar - output (can be NULL). */ -MRI *fMRIcovariance(MRI *fmri, int Lag, float DOFAdjust, MRI *mask, MRI *covar) { +MRI *fMRIcovariance(MRI *fmri, int Lag, float DOFAdjust, MRI *mask, MRI *covar) +{ int RemoveMean = 0; int DOF, DOFLag, c, r, s, f; double sumv1v2, val1, val2, valmean; @@ -203,7 +206,8 @@ and resets DOFAdjust=1. \param mask - only compute where mask > 0.5 (or everywhere if mask is NULL) \param ar1 - output (can be NULL). */ -MRI *fMRItemporalAR1(MRI *fmri, float DOFAdjust, MRI *mask, MRI *ar1) { +MRI *fMRItemporalAR1(MRI *fmri, float DOFAdjust, MRI *mask, MRI *ar1) +{ int c, r, s; double voxvar, voxcovar; MRI *var, *covar; @@ -246,7 +250,8 @@ MRI *fMRItemporalAR1(MRI *fmri, float DOFAdjust, MRI *mask, MRI *ar1) { squares is added to that already in sumsqr. If sumsqr is NULL, it will be allocated. --------------------------------------------------------*/ -MRI *fMRIsumSquare(MRI *fmri, int Update, MRI *sumsqr) { +MRI *fMRIsumSquare(MRI *fmri, int Update, MRI *sumsqr) +{ int c, r, s, f, n; float v; float *pfmri = NULL, *psumsqr = NULL; @@ -258,7 +263,8 @@ MRI *fMRIsumSquare(MRI *fmri, int Update, MRI *sumsqr) { return (NULL); } MRIcopyHeader(fmri, sumsqr); - } else { + } + else { if (sumsqr->width != fmri->width || sumsqr->height != fmri->height || sumsqr->depth != fmri->depth) { printf("ERROR: fMRIsumsqriance: output dimension mismatch\n"); return (NULL); @@ -289,7 +295,8 @@ MRI *fMRIsumSquare(MRI *fmri, int Update, MRI *sumsqr) { } /*--------------------------------------------------------------------*/ -MRI *fMRIcomputeT(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *t) { +MRI *fMRIcomputeT(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *t) +{ int c, r, s; MATRIX *Xt, *XtX, *iXtX, *CiXtX, *Ct, *CiXtXCt; float srf, cesval, std; @@ -313,7 +320,8 @@ MRI *fMRIcomputeT(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *t) { return (NULL); } MRIcopyHeader(ces, t); - } else { + } + else { if (t->width != ces->width || t->height != ces->height || t->depth != ces->depth) { printf("ERROR: fMRIcomputeT: output dimension mismatch\n"); return (NULL); @@ -358,7 +366,8 @@ MRI *fMRIcomputeT(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *t) { } /*--------------------------------------------------------*/ -MRI *fMRIsigT(MRI *t, float DOF, MRI *sig) { +MRI *fMRIsigT(MRI *t, float DOF, MRI *sig) +{ int c, r, s, f; float tval, sigtval; @@ -369,7 +378,8 @@ MRI *fMRIsigT(MRI *t, float DOF, MRI *sig) { return (NULL); } MRIcopyHeader(t, sig); - } else { + } + else { if (t->width != sig->width || t->height != sig->height || t->depth != sig->depth || t->nframes != sig->nframes) { printf("ERROR: fMRIsigT: output dimension mismatch\n"); return (NULL); @@ -397,7 +407,8 @@ MRI *fMRIsigT(MRI *t, float DOF, MRI *sig) { } /*--------------------------------------------------------------------*/ -MRI *fMRIcomputeF(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *F) { +MRI *fMRIcomputeF(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *F) +{ int c, r, s, f, J; MATRIX *Xt, *XtX, *iXtX, *CiXtX, *Ct, *CiXtXCt, *iCiXtXCt; MATRIX *M, *cesvect, *cesvectt, *voxF; @@ -417,7 +428,8 @@ MRI *fMRIcomputeF(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *F) { return (NULL); } MRIcopyHeader(ces, F); - } else { + } + else { if (F->width != ces->width || F->height != ces->height || F->depth != ces->depth) { printf("ERROR: fMRIcomputeT: output dimension mismatch\n"); return (NULL); @@ -480,7 +492,8 @@ MRI *fMRIcomputeF(MRI *ces, MATRIX *X, MATRIX *C, MRI *var, MRI *F) { // DOF1 = dof of den (same as t DOF) // DOF2 = dof of num (number of rows in C) // Note: order is rev relative to fsfast's FTest.m -MRI *fMRIsigF(MRI *F, float DOFDen, float DOFNum, MRI *sig) { +MRI *fMRIsigF(MRI *F, float DOFDen, float DOFNum, MRI *sig) +{ int c, r, s, f; float Fval, sigFval; @@ -491,7 +504,8 @@ MRI *fMRIsigF(MRI *F, float DOFDen, float DOFNum, MRI *sig) { return (NULL); } MRIcopyHeader(F, sig); - } else { + } + else { if (F->width != sig->width || F->height != sig->height || F->depth != sig->depth || F->nframes != sig->nframes) { printf("ERROR: fMRIsigF: output dimension mismatch\n"); return (NULL); @@ -520,7 +534,8 @@ MRI *fMRIsigF(MRI *F, float DOFDen, float DOFNum, MRI *sig) { /*-------------------------------------------------------- fMRInskip() - skip the first nskip frames --------------------------------------------------------*/ -MRI *fMRInskip(MRI *inmri, int nskip, MRI *outmri) { +MRI *fMRInskip(MRI *inmri, int nskip, MRI *outmri) +{ int c, r, s, fin, fout; int nframesout; float val; @@ -538,7 +553,8 @@ MRI *fMRInskip(MRI *inmri, int nskip, MRI *outmri) { return (NULL); } MRIcopyHeader(inmri, outmri); - } else { + } + else { if (outmri->width != inmri->width || outmri->height != inmri->height || outmri->depth != inmri->depth || outmri->nframes != nframesout) { printf("ERROR: fMRInskip: output dimension mismatch\n"); @@ -569,7 +585,8 @@ MRI *fMRInskip(MRI *inmri, int nskip, MRI *outmri) { /*-------------------------------------------------------- fMRIndrop() - drop the last ndrop frames --------------------------------------------------------*/ -MRI *fMRIndrop(MRI *inmri, int ndrop, MRI *outmri) { +MRI *fMRIndrop(MRI *inmri, int ndrop, MRI *outmri) +{ int c, r, s, fin, fout; int nframesout; float val; @@ -587,7 +604,8 @@ MRI *fMRIndrop(MRI *inmri, int ndrop, MRI *outmri) { return (NULL); } MRIcopyHeader(inmri, outmri); - } else { + } + else { if (outmri->width != inmri->width || outmri->height != inmri->height || outmri->depth != inmri->depth || outmri->nframes != nframesout) { printf("ERROR: fMRIndrop: output dimension mismatch\n"); @@ -618,7 +636,8 @@ MRI *fMRIndrop(MRI *inmri, int ndrop, MRI *outmri) { /*-------------------------------------------------------- fMRIframe() - extract the nth frame. frame is 0-based. --------------------------------------------------------*/ -MRI *fMRIframe(MRI *inmri, int frame, MRI *outmri) { +MRI *fMRIframe(MRI *inmri, int frame, MRI *outmri) +{ int c, r, s, nframesout; float val; @@ -636,7 +655,8 @@ MRI *fMRIframe(MRI *inmri, int frame, MRI *outmri) { } MRIcopyHeader(inmri, outmri); MRIcopyPulseParameters(inmri, outmri); - } else { + } + else { if (outmri->width != inmri->width || outmri->height != inmri->height || outmri->depth != inmri->depth || outmri->nframes != nframesout) { printf("ERROR: fMRIframe: output dimension mismatch\n"); @@ -665,7 +685,8 @@ MRI *fMRIframe(MRI *inmri, int frame, MRI *outmri) { \brief Inserts the specified frame from the source mri into the target frame of the fmri. If fmri is NULL, then it is allocated with frame+1 frames. */ -MRI *fMRIinsertFrame(MRI *srcmri, int srcframe, MRI *fmri, int frame) { +MRI *fMRIinsertFrame(MRI *srcmri, int srcframe, MRI *fmri, int frame) +{ int c, r, s; double v; @@ -696,7 +717,8 @@ MRI *fMRIinsertFrame(MRI *srcmri, int srcframe, MRI *fmri, int frame) { } /*---------------------------------------------------------------*/ -MATRIX *MRItoMatrix(MRI *mri, int c, int r, int s, int Mrows, int Mcols, MATRIX *M) { +MATRIX *MRItoMatrix(MRI *mri, int c, int r, int s, int Mrows, int Mcols, MATRIX *M) +{ int mr, mc, f; if (M == NULL) @@ -724,7 +746,8 @@ MATRIX *MRItoMatrix(MRI *mri, int c, int r, int s, int Mrows, int Mcols, MATRIX } /*---------------------------------------------------------------*/ -MATRIX *MRItoSymMatrix(MRI *mri, int c, int r, int s, MATRIX *M) { +MATRIX *MRItoSymMatrix(MRI *mri, int c, int r, int s, MATRIX *M) +{ int mr, mc, f, Msize, nframesexp; if (M == NULL) { @@ -751,7 +774,8 @@ MATRIX *MRItoSymMatrix(MRI *mri, int c, int r, int s, MATRIX *M) { } /*---------------------------------------------------------------*/ -int MRIfromMatrix(MRI *mri, int c, int r, int s, MATRIX *M, MRI *FrameMask) { +int MRIfromMatrix(MRI *mri, int c, int r, int s, MATRIX *M, MRI *FrameMask) +{ int mr, mc, f, nf; nf = mri->nframes; @@ -795,7 +819,8 @@ int MRIfromMatrix(MRI *mri, int c, int r, int s, MATRIX *M, MRI *FrameMask) { } /*---------------------------------------------------------------*/ -int MRIfromSymMatrix(MRI *mri, int c, int r, int s, MATRIX *M) { +int MRIfromSymMatrix(MRI *mri, int c, int r, int s, MATRIX *M) +{ int mr, mc, f, nframesexp; nframesexp = M->rows * (M->rows + 1) / 2; @@ -823,7 +848,8 @@ int MRIfromSymMatrix(MRI *mri, int c, int r, int s, MATRIX *M) { variances for WLMS. Can be done in-place. If mask, then ignores voxels where mask<0.5. Weights must be > 0. *------------------------------------------------------*/ -MRI *MRInormWeights(MRI *w, int sqrtFlag, int invFlag, MRI *mask, MRI *wn) { +MRI *MRInormWeights(MRI *w, int sqrtFlag, int invFlag, MRI *mask, MRI *wn) +{ int c, r, s, f; double v, vsum, m; @@ -889,7 +915,8 @@ MRI *MRInormWeights(MRI *w, int sqrtFlag, int invFlag, MRI *mask, MRI *wn) { efficient. So why have MRIglmFit() and MRIglmTest()? So that the variance can be smoothed between the two if desired. --------------------------------------------------------------------*/ -int MRIglmFitAndTest(MRIGLM *mriglm) { +int MRIglmFitAndTest(MRIGLM *mriglm) +{ int c, r, s, n, nc, nr, ns, nf, pctdone; float m, Xcond; long nvoxtot, nthvox; @@ -1037,7 +1064,8 @@ int MRIglmFitAndTest(MRIGLM *mriglm) { MRIglmFit() - fits glm (beta and rvar) on a voxel-by-voxel basis. Made to be followed by MRIglmTest(). See notes on MRIglmFitandTest() --------------------------------------------------------------------*/ -int MRIglmFit(MRIGLM *mriglm) { +int MRIglmFit(MRIGLM *mriglm) +{ int c, r, s, nc, nr, ns, nf, pctdone; float m, Xcond; long nvoxtot, nthvox; @@ -1143,7 +1171,8 @@ int MRIglmFit(MRIGLM *mriglm) { MRIglmTest() - tests glm contrasts on a voxel-by-voxel basis. Made to be preceded by MRIglmFit(). See notes on MRIglmFitandTest() --------------------------------------------------------------------*/ -int MRIglmTest(MRIGLM *mriglm) { +int MRIglmTest(MRIGLM *mriglm) +{ int c, r, s, n, nc, nr, ns, nf, pctdone; float m; long nvoxtot, nthvox; @@ -1243,7 +1272,8 @@ int MRIglmTest(MRIGLM *mriglm) { here. If Xg has already been loaded into X, then it is not loaded again unless mriglm->w is non-null. -------------------------------------------------------------------------*/ -int MRIglmLoadVox(MRIGLM *mriglm, int c, int r, int s, int LoadBeta) { +int MRIglmLoadVox(MRIGLM *mriglm, int c, int r, int s, int LoadBeta) +{ int f, n, nthreg, nthf, nf; double v; static int nfprev = -1; @@ -1287,7 +1317,8 @@ int MRIglmLoadVox(MRIGLM *mriglm, int c, int r, int s, int LoadBeta) { mriglm->glm->X->rptr[nthf][nthreg] = mriglm->Xg->rptr[f][n]; // X=Xg nthreg++; } - } else + } + else nthreg = mriglm->Xg->cols + 1; // Load the global per-voxel regressors matrix, X = [X pvr] @@ -1341,7 +1372,8 @@ int MRIglmLoadVox(MRIGLM *mriglm, int c, int r, int s, int LoadBeta) { MRIglmNRegTot() - computes the total number of regressors based on the number of columns in Xg + number of per-voxel regressors ----------------------------------------------------------------*/ -int MRIglmNRegTot(MRIGLM *mriglm) { +int MRIglmNRegTot(MRIGLM *mriglm) +{ mriglm->nregtot = mriglm->Xg->cols + mriglm->npvr; return (mriglm->nregtot); } @@ -1350,7 +1382,8 @@ int MRIglmNRegTot(MRIGLM *mriglm) { MRItoVector() - copies all the frames from the given voxel in to a vector. ----------------------------------------------------------------*/ -VECTOR *MRItoVector(MRI *mri, int c, int r, int s, VECTOR *v) { +VECTOR *MRItoVector(MRI *mri, int c, int r, int s, VECTOR *v) +{ int f; if (v == NULL) v = MatrixAlloc(mri->nframes, 1, MATRIX_REAL); @@ -1363,7 +1396,8 @@ VECTOR *MRItoVector(MRI *mri, int c, int r, int s, VECTOR *v) { nth frame of the signvol. The values of the input are changed. All frames of the input volume are affected. --------------------------------------------------------------*/ -int MRIsetSign(MRI *invol, MRI *signvol, int frame) { +int MRIsetSign(MRI *invol, MRI *signvol, int frame) +{ int c, r, s, f; double v, sgn; @@ -1392,7 +1426,8 @@ int MRIsetSign(MRI *invol, MRI *signvol, int frame) { MRI *MRIvolMax(MRI *vol, MRI *out) - the value at each voxel is the maximum over the frames at that voxel. --------------------------------------------------------------*/ -MRI *MRIvolMax(MRI *invol, MRI *out) { +MRI *MRIvolMax(MRI *invol, MRI *out) +{ int c, r, s, f; double v, max; @@ -1427,7 +1462,8 @@ MRI *MRIvolMax(MRI *invol, MRI *out) { special is done with the sign (ie, a negative value can be the minimum). --------------------------------------------------------------*/ -MRI *MRIvolMin(MRI *invol, MRI *out) { +MRI *MRIvolMin(MRI *invol, MRI *out) +{ int c, r, s, f; double v, min; @@ -1471,7 +1507,8 @@ Pages 653-660. \param multi-frame input vol \param out - can be NULL */ -MRI *MRIconjunct(MRI *invol, MRI *out) { +MRI *MRIconjunct(MRI *invol, MRI *out) +{ int c, r, s, f; double v, min, minsign; @@ -1510,7 +1547,8 @@ MRI *MRIconjunct(MRI *invol, MRI *out) { is the frame index of the maximum over the frames at that voxel. base is added to the index. --------------------------------------------------------------*/ -MRI *MRIvolMaxIndex(MRI *invol, int base, MRI *mask, MRI *out) { +MRI *MRIvolMaxIndex(MRI *invol, int base, MRI *mask, MRI *out) +{ int c, r, s, f, index; double v, max, m; @@ -1556,7 +1594,8 @@ MRI *MRIvolMaxIndex(MRI *invol, int base, MRI *mask, MRI *out) { value still returned). If signflag = +1, then only the pos max is found. If signflag = -1, then only the neg max is found. --------------------------------------------------------------*/ -double MRIframeMax(MRI *vol, int frame, MRI *mask, int signflag, int *cmax, int *rmax, int *smax) { +double MRIframeMax(MRI *vol, int frame, MRI *mask, int signflag, int *cmax, int *rmax, int *smax) +{ int c, r, s, nhits; double v, vmax, m; @@ -1620,7 +1659,8 @@ double MRIframeMax(MRI *vol, int frame, MRI *mask, int signflag, int *cmax, int /*--------------------------------------------------------------- MRIframeMean() - computes mean over frames of each voxel. --------------------------------------------------------------*/ -MRI *MRIframeMean(MRI *vol, MRI *volmn) { +MRI *MRIframeMean(MRI *vol, MRI *volmn) +{ int c, r, s, f; double v; @@ -1644,7 +1684,8 @@ MRI *MRIframeMean(MRI *vol, MRI *volmn) { /*--------------------------------------------------------------- MRIframeMedian() - computes median over frames of each voxel. --------------------------------------------------------------*/ -MRI *MRIframeMedian(MRI *vol, MRI *volmn) { +MRI *MRIframeMedian(MRI *vol, MRI *volmn) +{ int c, r, s, f; float *t = (float *)calloc(vol->nframes, sizeof(float)); @@ -1668,7 +1709,8 @@ MRI *MRIframeMedian(MRI *vol, MRI *volmn) { /*--------------------------------------------------------------- MRIframeSum() - computes sum over frames of each voxel. --------------------------------------------------------------*/ -MRI *MRIframeSum(MRI *vol, MRI *volsum) { +MRI *MRIframeSum(MRI *vol, MRI *volsum) +{ int c, r, s, f; double v; @@ -1692,7 +1734,8 @@ MRI *MRIframeSum(MRI *vol, MRI *volsum) { /*--------------------------------------------------------------- fMRIdetrend() - returns (I-inv(X'*X)*X')*y ---------------------------------------------------------------*/ -MRI *fMRIdetrend(MRI *y, MATRIX *X) { +MRI *fMRIdetrend(MRI *y, MATRIX *X) +{ MATRIX *Xt, *XtX, *iXtX, *B; MRI *beta, *yhat, *res; @@ -1733,7 +1776,8 @@ MRI *fMRIdetrend(MRI *y, MATRIX *X) { other trends have been removed. It works regardless of the DOF of the time series. --------------------------------------------------------------------*/ -MRI *fMRIspatialAR1(MRI *src, MRI *mask, MRI *ar1) { +MRI *fMRIspatialAR1(MRI *src, MRI *mask, MRI *ar1) +{ int c, r, s, f, dc, dr, ds, skip, nhits; MRI *srcsumsq, *srctmp; double m, c1sum, c2sum, r1sum, r2sum, s1sum, s2sum; @@ -1745,7 +1789,8 @@ MRI *fMRIspatialAR1(MRI *src, MRI *mask, MRI *ar1) { if (src->type != MRI_FLOAT) { srctmp = MRISeqchangeType(src, MRI_FLOAT, 0, 0, 0); freetmp = 1; - } else { + } + else { srctmp = src; freetmp = 0; } @@ -1898,7 +1943,8 @@ MRI *fMRIspatialAR1(MRI *src, MRI *mask, MRI *ar1) { compute the AR2 at that point. BUG: this function is sensitive to the time series DOF (assumes it is nframes-1). --------------------------------------------------------------*/ -MRI *fMRIspatialAR2(MRI *src, MRI *mask, MRI *ar2) { +MRI *fMRIspatialAR2(MRI *src, MRI *mask, MRI *ar2) +{ int c, r, s, f, nframes, dc, dr, ds, skip; MRI *srcvar, *srctmp; double m, c1sum, c2sum, r1sum, r2sum, s1sum, s2sum; @@ -1910,7 +1956,8 @@ MRI *fMRIspatialAR2(MRI *src, MRI *mask, MRI *ar2) { if (src->type != MRI_FLOAT) { srctmp = MRISeqchangeType(src, MRI_FLOAT, 0, 0, 0); freetmp = 1; - } else { + } + else { srctmp = src; freetmp = 0; } @@ -2057,7 +2104,8 @@ MRI *fMRIspatialAR2(MRI *src, MRI *mask, MRI *ar2) { fMRIspatialAR1Mean() - computes gobal mean of spatial AR1 for col, row, and slice separately. ----------------------------------------------------------*/ -int fMRIspatialAR1Mean(MRI *ar1, MRI *mask, double *car1mn, double *rar1mn, double *sar1mn) { +int fMRIspatialAR1Mean(MRI *ar1, MRI *mask, double *car1mn, double *rar1mn, double *sar1mn) +{ int c, r, s; long nhits; double m, car1sum, rar1sum, sar1sum; @@ -2100,7 +2148,8 @@ int fMRIspatialAR1Mean(MRI *ar1, MRI *mask, double *car1mn, double *rar1mn, doub fMRIspatialAR2Mean() - computes gobal mean of spatial AR2 for col, row, and slice separately. ----------------------------------------------------------*/ -int fMRIspatialAR2Mean(MRI *src, MRI *mask, double *car2mn, double *rar2mn, double *sar2mn) { +int fMRIspatialAR2Mean(MRI *src, MRI *mask, double *car2mn, double *rar2mn, double *sar2mn) +{ int c, r, s; long nhits; double m, car2sum, rar2sum, sar2sum; @@ -2152,7 +2201,8 @@ int fMRIspatialAR2Mean(MRI *src, MRI *mask, double *car2mn, double *rar2mn, doub \param out - prealloced output (or NULL) \return out */ -MRI *fMRIaddOffset(MRI *in, MRI *offset, MRI *mask, MRI *out) { +MRI *fMRIaddOffset(MRI *in, MRI *offset, MRI *mask, MRI *out) +{ int c, r, s, f; double val0, val, m; @@ -2164,7 +2214,8 @@ MRI *fMRIaddOffset(MRI *in, MRI *offset, MRI *mask, MRI *out) { if (out == NULL) { out = MRIcloneBySpace(in, MRI_FLOAT, -1); if (out == NULL) return (NULL); - } else { + } + else { if (MRIdimMismatch(in, out, 1)) { printf("ERROR: fMRIaddOffset: input/output dim mismatch\n"); return (NULL); @@ -2190,7 +2241,8 @@ MRI *fMRIaddOffset(MRI *in, MRI *offset, MRI *mask, MRI *out) { return (out); } /*-----------------------------------------------------------------*/ -MRI *fMRIsubSample(MRI *f, int Start, int Delta, int Stop, MRI *fsub) { +MRI *fMRIsubSample(MRI *f, int Start, int Delta, int Stop, MRI *fsub) +{ int nframessub; int frame, subframe; int r, c, s; @@ -2234,7 +2286,8 @@ MRI *fMRIsubSample(MRI *f, int Start, int Delta, int Stop, MRI *fsub) { \fn MRI *fMRIexcludeFrames(MRI *f, int *ExcludeFrames, int nExclude, MRI *fex) \brief Creates a new MRI by excluding the given set of rows. */ -MRI *fMRIexcludeFrames(MRI *f, int *ExcludeFrames, int nExclude, MRI *fex) { +MRI *fMRIexcludeFrames(MRI *f, int *ExcludeFrames, int nExclude, MRI *fex) +{ int skip, m, nframesNew, c, r, s, frame, subframe; double v; @@ -2270,7 +2323,8 @@ MRI *fMRIexcludeFrames(MRI *f, int *ExcludeFrames, int nExclude, MRI *fex) { \param gstdmsec - gaussian stddev in milisec (divided by src->tr) \param targ - output */ -MRI *fMRItemporalGaussian(MRI *src, double gstdmsec, MRI *targ) { +MRI *fMRItemporalGaussian(MRI *src, double gstdmsec, MRI *targ) +{ MATRIX *G, *v; int c, r, s, f; double sum; @@ -2282,7 +2336,8 @@ MRI *fMRItemporalGaussian(MRI *src, double gstdmsec, MRI *targ) { return (NULL); } MRIcopy(src, targ); - } else { + } + else { if (src->width != targ->width) { printf("ERROR: MRItemporalGaussian: width dimension mismatch\n"); return (NULL); @@ -2328,7 +2383,8 @@ MRI *fMRItemporalGaussian(MRI *src, double gstdmsec, MRI *targ) { return (targ); } -MRI *fMRIkurtosis(MRI *y, MRI *mask) { +MRI *fMRIkurtosis(MRI *y, MRI *mask) +{ MRI *k; int c, r, s, f; double v, mn, m4 = 0, m2 = 0, g2, delta, b1, b2, n; @@ -2379,7 +2435,8 @@ MRI *fMRIkurtosis(MRI *y, MRI *mask) { \param mask - skip voxels where mask < 0.0001 \param nsamples - samples to use in the simulation (eg, 10000) */ -MRI *MRIpkurtosis(MRI *kvals, int dof, MRI *mask, int nsamples) { +MRI *MRIpkurtosis(MRI *kvals, int dof, MRI *mask, int nsamples) +{ MRI *nmri, *kmri, *pkmri; double *ksynth, pk, kvox, v; int m, c, r, s, f, ind; @@ -2425,7 +2482,8 @@ MRI *MRIpkurtosis(MRI *kvals, int dof, MRI *mask, int nsamples) { every other. \param ntp - number of time points */ -MATRIX *ASLinterpMatrix(int ntp) { +MATRIX *ASLinterpMatrix(int ntp) +{ int r, c0, nrows, IsOdd; MATRIX *M; @@ -2460,7 +2518,8 @@ MATRIX *ASLinterpMatrix(int ntp) { This is especially important when comparing to matlab. Make sure to use fMRIfromMatrix() to undo it. */ -MATRIX *fMRItoMatrix(MRI *fmri, MATRIX *M) { +MATRIX *fMRItoMatrix(MRI *fmri, MATRIX *M) +{ int nthcol, nvox, c, r, s, f; double v; @@ -2498,7 +2557,8 @@ MATRIX *fMRItoMatrix(MRI *fmri, MATRIX *M) { Make sure to use fMRItoMatrix() to undo it. fmri cannot be NULL! */ -int fMRIfromMatrix(MATRIX *M, MRI *fmri) { +int fMRIfromMatrix(MATRIX *M, MRI *fmri) +{ int nthcol, nvox, c, r, s, f; double v; @@ -2528,7 +2588,8 @@ int fMRIfromMatrix(MATRIX *M, MRI *fmri) { de-meaned and normalized to unit variance making this a matrix of Pearson correlations. */ -MRI *fMRIspatialCorMatrix(MRI *fmri) { +MRI *fMRIspatialCorMatrix(MRI *fmri) +{ int nvox; MRI *scm; MATRIX *M, *Mt, *MtM; @@ -2578,7 +2639,8 @@ MRI *fMRIspatialCorMatrix(MRI *fmri) { \param mri - source volume with triples \param mask - skip voxels where mask < 0.0001 */ -MRI *fMRIdistance(MRI *mri, MRI *mask) { +MRI *fMRIdistance(MRI *mri, MRI *mask) +{ MRI *d; double dx, dy, dz, v; int c, r, s, f, fd; @@ -2622,7 +2684,8 @@ MRI *fMRIdistance(MRI *mri, MRI *mask) { \fn MRI *fMRIcumSum(MRI *inmri, MRI *mask, MRI *outmri) \brief Computes cumulative sum over frames. */ -MRI *fMRIcumSum(MRI *inmri, MRI *mask, MRI *outmri) { +MRI *fMRIcumSum(MRI *inmri, MRI *mask, MRI *outmri) +{ int c, r, s, f; double val; @@ -2633,7 +2696,8 @@ MRI *fMRIcumSum(MRI *inmri, MRI *mask, MRI *outmri) { return (NULL); } MRIcopyHeader(inmri, outmri); - } else { + } + else { if (outmri->width != inmri->width || outmri->height != inmri->height || outmri->depth != inmri->depth || outmri->nframes != outmri->nframes) { printf("ERROR: fMRIcumSum(): output dimension mismatch\n"); @@ -2661,7 +2725,8 @@ MRI *fMRIcumSum(MRI *inmri, MRI *mask, MRI *outmri) { \fn MRI *fMRIcumTrapZ(MRI *y, MATRIX *t, MRI *mask, MRI *yz) \brief Computes trapezoidal integration (like matlab cumtrapz) */ -MRI *fMRIcumTrapZ(MRI *y, MATRIX *t, MRI *mask, MRI *yz) { +MRI *fMRIcumTrapZ(MRI *y, MATRIX *t, MRI *mask, MRI *yz) +{ int c, r, s, f; double v, vprev, vsum, dt; @@ -2702,7 +2767,8 @@ MRI *fMRIcumTrapZ(MRI *y, MATRIX *t, MRI *mask, MRI *yz) { so that the sum of the squares of the weights is 1. This vector is ready to be used in a GLM. */ -MATRIX *HalfLife2Weight(double HalfLifeMin, MATRIX *tSec) { +MATRIX *HalfLife2Weight(double HalfLifeMin, MATRIX *tSec) +{ MATRIX *w; int n; double TDecayMin, TDecaySec, v, wsum, *wd; @@ -2731,7 +2797,8 @@ MATRIX *HalfLife2Weight(double HalfLifeMin, MATRIX *tSec) { \brief normalizes (ie, removes mean, divides by sqrt of the sum of squares) the time course at each voxel. */ -MRI *MRIframeNorm(MRI *src, MRI *mask, MRI *fnorm) { +MRI *MRIframeNorm(MRI *src, MRI *mask, MRI *fnorm) +{ MRI *mn, *var; int c, r, s, f; double v, mnv, sss; @@ -2775,7 +2842,8 @@ MRI *MRIframeNorm(MRI *src, MRI *mask, MRI *fnorm) { two volumes. If v2==NULL, then v2 is formed from v1 by left-right reversing the columns. */ -MRI *fMRIxcorr(MRI *v1, MRI *v2, MRI *mask, MRI *xcorr) { +MRI *fMRIxcorr(MRI *v1, MRI *v2, MRI *mask, MRI *xcorr) +{ MRI *fnorm1, *fnorm2 = NULL; int c, c2, r, s, f; double val1, val2, sum; @@ -2800,7 +2868,8 @@ MRI *fMRIxcorr(MRI *v1, MRI *v2, MRI *mask, MRI *xcorr) { if (Gdiag_no > 0) printf("MRIxcorr(): normalizing vol 2\n"); fflush(stdout); fnorm2 = MRIframeNorm(v2, mask, NULL); - } else + } + else printf("MRIxcorr(): reversing columns\n"); fflush(stdout); @@ -2838,7 +2907,8 @@ MRI *fMRIxcorr(MRI *v1, MRI *v2, MRI *mask, MRI *xcorr) { by the spatial stddev. If a mask is supplied, then only computes the mean and stddev within the mask. *--------------------------------------------------------------*/ -MRI *SpatialINorm(MRI *vol, MRI *mask, MRI *outvol) { +MRI *SpatialINorm(MRI *vol, MRI *mask, MRI *outvol) +{ int c, r, s, f, m; double gmean, gstddev, gmax, v; @@ -2872,7 +2942,8 @@ MRI *SpatialINorm(MRI *vol, MRI *mask, MRI *outvol) { assumess that the mean and any other trends have been removed. It works regardless of the DOF of the time series. --------------------------------------------------------------------*/ -MRI *fMRIspatialARN(MRI *src, MRI *mask, int N, MRI *arN) { +MRI *fMRIspatialARN(MRI *src, MRI *mask, int N, MRI *arN) +{ int c, r, s, f, dc, dr, ds, nhits, lag; MRI *srcsumsq, *srctmp; double m, sumsq0, sumsqnbr, ar, arsum, sum, v0, vnbr; @@ -2882,7 +2953,8 @@ MRI *fMRIspatialARN(MRI *src, MRI *mask, int N, MRI *arN) { if (src->type != MRI_FLOAT) { srctmp = MRISeqchangeType(src, MRI_FLOAT, 0, 0, 0); freetmp = 1; - } else { + } + else { srctmp = src; freetmp = 0; } diff --git a/utils/fsPrintHelp.c b/utils/fsPrintHelp.c index b66a861379a..9a0c612753e 100644 --- a/utils/fsPrintHelp.c +++ b/utils/fsPrintHelp.c @@ -79,7 +79,8 @@ int outputHelpDoc(const xmlDocPtr doc) if (tagNameIs("intro", argumentElement) || tagNameIs("argument", argumentElement)) { if (first == 1) { first = 0; - } else { + } + else { printf("\n"); } } @@ -107,7 +108,8 @@ int outputHelpDoc(const xmlDocPtr doc) if (tagNameIs("intro", outputElement) || tagNameIs("output", outputElement)) { if (first == 1) { first = 0; - } else { + } + else { printf("\n"); } } @@ -115,7 +117,8 @@ int outputHelpDoc(const xmlDocPtr doc) } outputElement = outputElement->next; } - } else { + } + else { printContents(doc, cur); } } @@ -127,7 +130,8 @@ int outputHelpDoc(const xmlDocPtr doc) return 0; // success } -static int FileExists(const char *fname) { +static int FileExists(const char *fname) +{ FILE *fp = fopen(fname, "r"); if (fp) { fclose(fp); @@ -196,7 +200,8 @@ int outputHelpXml(const unsigned char *text, unsigned int size) } // Changes a string to upper case -static void toUpperCase(char *c) { +static void toUpperCase(char *c) +{ int i; for (i = 0; *(c + i) != '\0'; i++) { *(c + i) = toupper(*(c + i)); @@ -204,7 +209,8 @@ static void toUpperCase(char *c) { } // Replaces the first underscore or dash in a string with a space -static void replaceUnderscore(char *c) { +static void replaceUnderscore(char *c) +{ char *pos = strchr(c, '_'); if (pos != NULL) { *pos = ' '; @@ -216,7 +222,8 @@ static void replaceUnderscore(char *c) { } // Prints the name of a tag in the correct format -static void printName(xmlNodePtr cur) { +static void printName(xmlNodePtr cur) +{ char *n = malloc(strlen((char *)cur->name) + 1); strcpy(n, (char *)cur->name); toUpperCase(n); @@ -227,7 +234,8 @@ static void printName(xmlNodePtr cur) { // Prints the text of a tag in the correct format // at most FSPRINT_MAX_CHARS characters per line with the correct number of tabs #define FSPRINT_MAX_CHARS 78 -static void printContents(xmlDocPtr doc, xmlNodePtr cur) { +static void printContents(xmlDocPtr doc, xmlNodePtr cur) +{ xmlChar *contents; contents = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); int i = 0, j; @@ -248,11 +256,13 @@ static void printContents(xmlDocPtr doc, xmlNodePtr cur) { if (*(contents + j) == '\n') { j++; break; - } else if (wrdLen((char *)(contents + j)) > FSPRINT_MAX_CHARS - tabNum * 8) { + } + else if (wrdLen((char *)(contents + j)) > FSPRINT_MAX_CHARS - tabNum * 8) { for (j = j; j < FSPRINT_MAX_CHARS - tabNum * 8 + i; j++) { printf("%c", *(contents + j)); } - } else { + } + else { printf("%c", *(contents + j)); } } @@ -267,7 +277,8 @@ static int tagNameIs(char *c, xmlNodePtr cur) { return !(xmlStrcasecmp(cur->name // Counts the number of chars until the next space, dash, underscore, slash, // or end of the string // Used to keep a word from running on two lines -static int wrdLen(char *c) { +static int wrdLen(char *c) +{ int i; for (i = 0; i < strlen(c); i++) { if (*(c + i) == ' ' || *(c + i) == '_' || *(c + i) == '/') { @@ -279,7 +290,8 @@ static int wrdLen(char *c) { #ifdef BUILD_MAIN //------------------------------------------------------------------- -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ if (argv[1] == NULL) { // assuming input is being piped (ie 'cat somefile.help.xml | fsPrintHelp') argv[1] = "/dev/stdin"; diff --git a/utils/fs_cost_function.cpp b/utils/fs_cost_function.cpp index 2fead9e79e8..00546bbedc0 100644 --- a/utils/fs_cost_function.cpp +++ b/utils/fs_cost_function.cpp @@ -32,24 +32,28 @@ fs_cost_function::fs_cost_function(float (*function)(float[])) { SetFunction(fun fs_cost_function::fs_cost_function(float (*function)(float[]), void (*functionGradient)(float[], float[]), - int numberOfUnknowns) { + int numberOfUnknowns) +{ SetFunction(function); SetFunctionGradient(functionGradient); set_number_of_unknowns(numberOfUnknowns); } -fs_cost_function::~fs_cost_function() { +fs_cost_function::~fs_cost_function() +{ mFunction = NULL; mFunctionGradient = NULL; } void fs_cost_function::SetFunction(float (*function)(float[])) { mFunction = function; } -void fs_cost_function::SetFunctionGradient(void (*functionGradient)(float[], float[])) { +void fs_cost_function::SetFunctionGradient(void (*functionGradient)(float[], float[])) +{ mFunctionGradient = functionGradient; } -double fs_cost_function::f(const vnl_vector< double > &x) { +double fs_cost_function::f(const vnl_vector< double > &x) +{ int numberOfParameters = x.size(); float p[numberOfParameters + 1]; @@ -63,7 +67,8 @@ double fs_cost_function::f(const vnl_vector< double > &x) { return value; } -void fs_cost_function::gradf(vnl_vector< double > const &x, vnl_vector< double > &gradient) { +void fs_cost_function::gradf(vnl_vector< double > const &x, vnl_vector< double > &gradient) +{ int numberOfParameters = static_cast< int >(x.size()); float p[numberOfParameters + 1]; @@ -80,7 +85,8 @@ void fs_cost_function::gradf(vnl_vector< double > const &x, vnl_vector< double > void fs_cost_function::copyFromVNLToFloat(float *floatVector, const vnl_vector< double > vnlVector, - int numberOfParameters) { + int numberOfParameters) +{ for (int i = 0; i < numberOfParameters; i++) { // TODO: index starting at 1--legacy indexing from NR that the old // functions passed in will have diff --git a/utils/fs_lbfgs.cpp b/utils/fs_lbfgs.cpp index 55a59c2bccc..8508fb59995 100644 --- a/utils/fs_lbfgs.cpp +++ b/utils/fs_lbfgs.cpp @@ -39,13 +39,15 @@ fs_lbfgs::fs_lbfgs(vnl_cost_function &f) : fs_lbfgs_subject(), f_(&f) { init_par //: Called by constructors. // Memory is set to 5, line_search_accuracy to 0.9, default_step_length to 1. -void fs_lbfgs::init_parameters() { +void fs_lbfgs::init_parameters() +{ memory = 5; line_search_accuracy = 0.9; default_step_length = 1.0; } -bool fs_lbfgs::minimize(vnl_vector< double > &x) { +bool fs_lbfgs::minimize(vnl_vector< double > &x) +{ /* Local variables */ /* The driver for vnl_lbfgs must always declare LB2 as EXTERNAL */ @@ -98,7 +100,8 @@ bool fs_lbfgs::minimize(vnl_vector< double > &x) { if (this->num_evaluations_ == 0) { this->start_error_ = f; best_f = f; - } else if (f < best_f) { + } + else if (f < best_f) { best_x = x; best_f = f; diff --git a/utils/fs_lbfgs_observer.cpp b/utils/fs_lbfgs_observer.cpp index 14031dd2466..967eec51346 100644 --- a/utils/fs_lbfgs_observer.cpp +++ b/utils/fs_lbfgs_observer.cpp @@ -27,7 +27,8 @@ #include "fs_vnl/fs_lbfgs_observer.h" -fs_lbfgs_observer::fs_lbfgs_observer() { +fs_lbfgs_observer::fs_lbfgs_observer() +{ mNumberOfOptimalUpdates = 0; mStepFunction = NULL; @@ -37,7 +38,8 @@ fs_lbfgs_observer::fs_lbfgs_observer() { fs_lbfgs_observer::~fs_lbfgs_observer() {} -void fs_lbfgs_observer::update(double bestF, vnl_vector< double > *bestX) { +void fs_lbfgs_observer::update(double bestF, vnl_vector< double > *bestX) +{ if (hasStepFunction() || hasUserCallbackFunction()) { const int n = bestX->size(); @@ -63,16 +65,19 @@ bool fs_lbfgs_observer::hasUserCallbackFunction() { return (mUserCallbackFunctio int fs_lbfgs_observer::getNumberOfOptimalUpdates() { return mNumberOfOptimalUpdates; } -void fs_lbfgs_observer::setStepFunction(void (*stepFunction)(int itno, float sse, void *parms, float *p), void *parms) { +void fs_lbfgs_observer::setStepFunction(void (*stepFunction)(int itno, float sse, void *parms, float *p), void *parms) +{ mStepFunction = stepFunction; mStepFunctionParms = parms; } -void fs_lbfgs_observer::setUserCallbackFunction(void (*userCallbackFunction)(float[])) { +void fs_lbfgs_observer::setUserCallbackFunction(void (*userCallbackFunction)(float[])) +{ mUserCallbackFunction = userCallbackFunction; } -void fs_lbfgs_observer::copyVnlToFloat(const vnl_vector< double > *input, float *output, const int n) { +void fs_lbfgs_observer::copyVnlToFloat(const vnl_vector< double > *input, float *output, const int n) +{ for (int i = 0; i < n; i++) { // legacy one indexing output[i + 1] = static_cast< float >((*input)(i)); diff --git a/utils/fs_lbfgs_subject.cpp b/utils/fs_lbfgs_subject.cpp index 01b63a04c61..2ebd58d4273 100644 --- a/utils/fs_lbfgs_subject.cpp +++ b/utils/fs_lbfgs_subject.cpp @@ -31,7 +31,8 @@ fs_lbfgs_subject::~fs_lbfgs_subject() {} void fs_lbfgs_subject::setObserver(fs_lbfgs_observer *observer) { mObserver = observer; } -void fs_lbfgs_subject::notify(double bestF, vnl_vector< double > *bestX) { +void fs_lbfgs_subject::notify(double bestF, vnl_vector< double > *bestX) +{ // we might want a number of observers, but right now we only have one if (mObserver != NULL) { mObserver->update(bestF, bestX); diff --git a/utils/fs_powell.cpp b/utils/fs_powell.cpp index 2a46c2e3661..eda5692130b 100644 --- a/utils/fs_powell.cpp +++ b/utils/fs_powell.cpp @@ -48,7 +48,8 @@ extern "C" { #include #endif -class fs_powell_1dfun : public vnl_cost_function { +class fs_powell_1dfun : public vnl_cost_function +{ public: fs_powell *powell_; vnl_cost_function *f_; @@ -57,23 +58,28 @@ class fs_powell_1dfun : public vnl_cost_function { vnl_vector< double > dx_; vnl_vector< double > tmpx_; fs_powell_1dfun(int n, vnl_cost_function *f, fs_powell *p) - : vnl_cost_function(1), powell_(p), f_(f), n_(n), x0_(n), dx_(n), tmpx_(n) {} + : vnl_cost_function(1), powell_(p), f_(f), n_(n), x0_(n), dx_(n), tmpx_(n) + { + } - void init(vnl_vector< double > const &x0, vnl_vector< double > const &dx) { + void init(vnl_vector< double > const &x0, vnl_vector< double > const &dx) + { x0_ = x0; dx_ = dx; assert(x0.size() == n_); assert(dx.size() == n_); } - double f(const vnl_vector< double > &x) { + double f(const vnl_vector< double > &x) + { uninit(x[0], tmpx_); double e = f_->f(tmpx_); powell_->pub_report_eval(e); return e; } - void uninit(double lambda, vnl_vector< double > &out) { + void uninit(double lambda, vnl_vector< double > &out) + { for (unsigned int i = 0; i < n_; ++i) out[i] = x0_[i] + lambda * dx_[i]; } }; diff --git a/utils/fsenv.c b/utils/fsenv.c index 92ab68c28ac..dc13bbfe35a 100644 --- a/utils/fsenv.c +++ b/utils/fsenv.c @@ -40,7 +40,8 @@ // Return the CVS version of this file. const char *FSENVsrcVersion(void) { return ("$Id: fsenv.c,v 1.7 2015/04/16 18:49:31 greve Exp $"); } -FSENV *FSENVgetenv(void) { +FSENV *FSENVgetenv(void) +{ FSENV *fsenv; char *pc, tmpstr[2000]; struct utsname uts; @@ -101,13 +102,15 @@ FSENV *FSENVgetenv(void) { return (NULL); } fsenv->desired_bvec_space = b; - } else + } + else fsenv->desired_bvec_space = BVEC_SPACE_VOXEL; return (fsenv); } /*-----------------------------------------------*/ -int FSENVfree(FSENV **ppenv) { +int FSENVfree(FSENV **ppenv) +{ FSENV *env = *ppenv; free(env->FREESURFER_HOME); free(env->SUBJECTS_DIR); @@ -125,7 +128,8 @@ int FSENVfree(FSENV **ppenv) { } /*-----------------------------------------------*/ -int FSENVprintenv(FILE *fp, FSENV *env) { +int FSENVprintenv(FILE *fp, FSENV *env) +{ fprintf(fp, "FREESURFER_HOME %s\n", env->FREESURFER_HOME); fprintf(fp, "SUBJECTS_DIR %s\n", env->SUBJECTS_DIR); fprintf(fp, "user %s\n", env->user); @@ -138,7 +142,8 @@ int FSENVprintenv(FILE *fp, FSENV *env) { } /*-----------------------------------------------*/ -char *FSENVgetSUBJECTS_DIR(void) { +char *FSENVgetSUBJECTS_DIR(void) +{ char *pc = getenv("SUBJECTS_DIR"); if (pc == NULL) { printf("FSENVgetSUBJECTS_DIR: SUBJECTS_DIR not defined\n"); @@ -148,7 +153,8 @@ char *FSENVgetSUBJECTS_DIR(void) { } /*-----------------------------------------------*/ -int FSENVsetSUBJECTS_DIR(char *SUBJECTS_DIR) { +int FSENVsetSUBJECTS_DIR(char *SUBJECTS_DIR) +{ setenv("SUBJECTS_DIR", SUBJECTS_DIR, 1); return (0); } diff --git a/utils/fsglm.c b/utils/fsglm.c index cba3c8e6943..c3604cc7fce 100644 --- a/utils/fsglm.c +++ b/utils/fsglm.c @@ -155,7 +155,8 @@ const char *GLMSrcVersion(void) { return ("$Id: fsglm.c,v 1.34 2015/04/15 19:55: GLManalyze() - fill y, X, ncontrasts, and C in the glm and run this to fit and test. -----------------------------------------------------------*/ -int GLManalyze(GLMMAT *glm) { +int GLManalyze(GLMMAT *glm) +{ GLMcMatrices(glm); GLMxMatrices(glm); GLMfit(glm); @@ -169,7 +170,8 @@ int GLManalyze(GLMMAT *glm) { of the matrices (that's done by GLMfit(), GLMtest(), and GLMcMatrices(), and GLMxMatrices. -------------------------------------------------------*/ -GLMMAT *GLMalloc(void) { +GLMMAT *GLMalloc(void) +{ int n; GLMMAT *glm; @@ -234,7 +236,8 @@ GLMMAT *GLMalloc(void) { /*-------------------------------------------------------------------- GLMdof() - computes DOF = #Xrows - #Xcols ------------------------------------------------------------------*/ -int GLMdof(GLMMAT *glm) { +int GLMdof(GLMMAT *glm) +{ glm->dof = glm->X->rows - glm->X->cols; if (glm->dof == 0 && glm->AllowZeroDOF) glm->dof = 1; return (glm->dof); @@ -245,7 +248,8 @@ int GLMdof(GLMMAT *glm) { and the dims are correct, then just returns. If dims are not correct, frees and then allocs. ------------------------------------------------------------------*/ -int GLMallocX(GLMMAT *glm, int nrows, int ncols) { +int GLMallocX(GLMMAT *glm, int nrows, int ncols) +{ if (glm->X != NULL) { if (glm->X->rows == nrows && glm->X->cols == ncols) return (0); @@ -261,7 +265,8 @@ int GLMallocX(GLMMAT *glm, int nrows, int ncols) { and the dims are correct, then just returns. If dims are not correct, frees and then allocs. ------------------------------------------------------------------*/ -int GLMallocY(GLMMAT *glm) { +int GLMallocY(GLMMAT *glm) +{ if (glm->y != NULL) { if (glm->y->rows == glm->X->rows && glm->y->cols == 1) return (0); @@ -277,7 +282,8 @@ int GLMallocY(GLMMAT *glm) { been alloced and the dims are correct, then just returns. If dims are not correct, frees and then allocs. ------------------------------------------------------------------*/ -int GLMallocYFFxVar(GLMMAT *glm) { +int GLMallocYFFxVar(GLMMAT *glm) +{ if (glm->yffxvar != NULL) { if (glm->yffxvar->rows == glm->X->rows && glm->yffxvar->cols == 1) return (0); @@ -292,7 +298,8 @@ int GLMallocYFFxVar(GLMMAT *glm) { GLMfree() - frees all the matrices associcated with the GLM struct, and the GLM struct itself. ------------------------------------------------------------------*/ -int GLMfree(GLMMAT **pglm) { +int GLMfree(GLMMAT **pglm) +{ int n; GLMMAT *glm; glm = *pglm; @@ -349,7 +356,8 @@ int GLMfree(GLMMAT **pglm) { this within GLMtest(), but GLMtest() may be run many times whereas Ct only needs to be computed once. ----------------------------------------------------------------*/ -int GLMcMatrices(GLMMAT *glm) { +int GLMcMatrices(GLMMAT *glm) +{ int n, err; for (n = 0; n < glm->ncontrasts; n++) { @@ -379,7 +387,8 @@ int GLMcMatrices(GLMMAT *glm) { glm->Xcdt[n] = MatrixTranspose(glm->Xcd[n], NULL); glm->sumXcd[n] = MatrixSum(glm->Xcd[n], 1, NULL); glm->sumXcd2[n] = MatrixSumSquare(glm->Xcd[n], 1, NULL); - } else + } + else glm->Dt[n] = NULL; // make sure } return (0); @@ -393,7 +402,8 @@ int GLMcMatrices(GLMMAT *glm) { than once. Eg, when doing an analysis where the desgin matrix is the same at all voxels, then it is not necessary. ---------------------------------------------------------------*/ -int GLMxMatrices(GLMMAT *glm) { +int GLMxMatrices(GLMMAT *glm) +{ int n, c, r; MATRIX *Mtmp, *Xnorm, *Xtnorm, *Xscale, *XtX; double v; @@ -412,7 +422,8 @@ int GLMxMatrices(GLMMAT *glm) { Xnorm = MatrixNormalizeCol(glm->X, NULL, Xscale); Xtnorm = MatrixTranspose(Xnorm, NULL); XtX = MatrixMultiplyD(Xtnorm, Xnorm, NULL); - } else + } + else XtX = glm->XtX; Mtmp = MatrixInverse(XtX, glm->iXtX); @@ -455,7 +466,8 @@ int GLMxMatrices(GLMMAT *glm) { do spatial filtering on the eres). XtX and iXtX must have been computed by GLMxMatrices() first. ---------------------------------------------------------------*/ -int GLMfit(GLMMAT *glm) { +int GLMfit(GLMMAT *glm) +{ int f; if (glm->ill_cond_flag) return (0); @@ -488,7 +500,8 @@ int GLMfit(GLMMAT *glm) { GLMtest() - tests all the contrasts for the given GLM. Must have already run GLMcMatrices(), GLMxMatrices(), and GLMfit(). See also GLMtestFFX(). ------------------------------------------------------------------------*/ -int GLMtest(GLMMAT *glm) { +int GLMtest(GLMMAT *glm) +{ int n; double dtmp; static MATRIX *F = NULL, *mtmp = NULL; @@ -553,9 +566,11 @@ int GLMtest(GLMMAT *glm) { (glm->Xcdyhatd[n]->rptr[1][1] - glm->sumXcd[n]->rptr[1][1] * glm->sumyhatd[n]->rptr[1][1]) / sqrt((glm->sumXcd2[n]->rptr[1][1] - glm->sumXcd[n]->rptr[1][1] * glm->sumXcd[n]->rptr[1][1]) * (glm->sumyhatd2[n]->rptr[1][1] - glm->sumyhatd[n]->rptr[1][1] * glm->sumyhatd[n]->rptr[1][1])); - } else + } + else glm->pcc[n] = 0; - } else { + } + else { // this usually happens when the var is close to 0. But if this is // happening, should probably use a mask. glm->F[n] = 0; @@ -572,7 +587,8 @@ int GLMtest(GLMMAT *glm) { GLMtestFFx() - tests all the contrasts for the given GLM. Must have already run GLMcMatrices(), GLMxMatrices(), and GLMfit(). See also GLMtest(). ------------------------------------------------------------------------*/ -int GLMtestFFx(GLMMAT *glm) { +int GLMtestFFx(GLMMAT *glm) +{ double val; int n, r, c; static MATRIX *F = NULL, *mtmp = NULL; @@ -611,7 +627,8 @@ int GLMtestFFx(GLMMAT *glm) { glm->F[n] = F->rptr[1][1]; glm->p[n] = sc_cdf_fdist_Q(glm->F[n], glm->C[n]->rows, glm->ffxdof); glm->igCVM[n] = mtmp; - } else { + } + else { // this usually happens when the var is close to 0. But if this is // happening, should probably use a mask. glm->F[n] = 0; @@ -634,7 +651,8 @@ int GLMtestFFx(GLMMAT *glm) { tested, where each contrast matrix is 2-by-ncols. Returns the number of msec used. -----------------------------------------------------------*/ -int GLMprofile(int nrows, int ncols, int ncon, int niters) { +int GLMprofile(int nrows, int ncols, int ncon, int niters) +{ int n, c, msec; GLMMAT *glm; struct timeb then; @@ -673,7 +691,8 @@ int GLMprofile(int nrows, int ncols, int ncon, int niters) { /*--------------------------------------------------------- GLMsynth() - synthesizes y, X, and Cs and fits and tests. ---------------------------------------------------------*/ -GLMMAT *GLMsynth(void) { +GLMMAT *GLMsynth(void) +{ static char tmpstr[1000]; int nrows, ncols, ncon, c; GLMMAT *glm; @@ -709,7 +728,8 @@ GLMMAT *GLMsynth(void) { the failure is passed back. If there is no failure, then the max rvar is passed. ---------------------------------------------------------*/ -int GLMresynthTest(int niters, double *prvar) { +int GLMresynthTest(int niters, double *prvar) +{ int nrows, ncols, n; GLMMAT *glm; double rvarmax; @@ -749,7 +769,8 @@ int GLMresynthTest(int niters, double *prvar) { GLMdump() - saves a lot of the stuff from the GLMMAT struct into ascii files in the given directory. ---------------------------------------------------------*/ -int GLMdump(char *dumpdir, GLMMAT *glm) { +int GLMdump(char *dumpdir, GLMMAT *glm) +{ char fname[1000], condir[1000]; FILE *fp; int c; @@ -844,7 +865,8 @@ int GLMdump(char *dumpdir, GLMMAT *glm) { condition number is computed and returned through cond so that the calling program can decide whether it is ill-conditioned. ------------------------------------------------------------------*/ -MATRIX *GLMpmfMatrix(MATRIX *C, double *cond, MATRIX *P) { +MATRIX *GLMpmfMatrix(MATRIX *C, double *cond, MATRIX *P) +{ MATRIX *Ct = NULL, *CCt = NULL, *iCCt = NULL, *CtiCCt = NULL; if (P != NULL) { diff --git a/utils/fsinit.c b/utils/fsinit.c index 4f43241e261..92a4830b538 100644 --- a/utils/fsinit.c +++ b/utils/fsinit.c @@ -5,7 +5,8 @@ #include #endif -int FSinit(void) { +int FSinit(void) +{ // char *cp; if (getenv("FS_DISABLE_LANG") == NULL) if (!setlocale(LC_NUMERIC, "en_US")) { diff --git a/utils/gca.c b/utils/gca.c index bcbc0ba9280..7eaf12bf487 100644 --- a/utils/gca.c +++ b/utils/gca.c @@ -236,7 +236,8 @@ static int boundsCheck(int *pix, int *piy, int *piz, MRI *mri); static void set_equilavent_classes(int *equivalent_classes); -double GCAimageLikelihoodAtNode(GCA *gca, GCA_NODE *gcan, float *vals, int label) { +double GCAimageLikelihoodAtNode(GCA *gca, GCA_NODE *gcan, float *vals, int label) +{ GC1D *gc; float likelihood; @@ -248,7 +249,8 @@ double GCAimageLikelihoodAtNode(GCA *gca, GCA_NODE *gcan, float *vals, int label static int initialize_ventricle_alignment(MRI *mri_seg, MRI *mri, MATRIX *m_L, char *base_name, int border, int label); -void GCAsetVolGeom(GCA *gca, VOL_GEOM *vg) { +void GCAsetVolGeom(GCA *gca, VOL_GEOM *vg) +{ vg->width = gca->width; vg->height = gca->height; vg->depth = gca->depth; @@ -270,7 +272,8 @@ void GCAsetVolGeom(GCA *gca, VOL_GEOM *vg) { vg->valid = 1; } -void GCAcopyDCToMRI(GCA *gca, MRI *mri) { +void GCAcopyDCToMRI(GCA *gca, MRI *mri) +{ mri->x_r = gca->x_r; mri->y_r = gca->y_r; mri->z_r = gca->z_r; @@ -296,7 +299,8 @@ void GCAcopyDCToMRI(GCA *gca, MRI *mri) { MatrixFree(&tmp); } -void GCAcopyDCToGCA(GCA *gca, GCA *gca_dst) { +void GCAcopyDCToGCA(GCA *gca, GCA *gca_dst) +{ gca_dst->x_r = gca->x_r; gca_dst->y_r = gca->y_r; gca_dst->z_r = gca->z_r; @@ -322,7 +326,8 @@ void GCAcopyDCToGCA(GCA *gca, GCA *gca_dst) { gca_dst->mri_tal__ = MRIcopy(gca->mri_tal__, gca_dst->mri_tal__); } -void GCAcleanup(GCA *gca) { +void GCAcleanup(GCA *gca) +{ if (gca->mri_node__) { MRIfree(&gca->mri_node__); gca->mri_node__ = 0; @@ -366,7 +371,8 @@ void GCAcleanup(GCA *gca) { } // set up mri's used in GCA -void GCAsetup(GCA *gca) { +void GCAsetup(GCA *gca) +{ // set up node part ///////////////////// if (gca->mri_node__) { MRIfree(&gca->mri_node__); @@ -469,7 +475,8 @@ void GCAsetup(GCA *gca) { // using the values of mri, modify gca // now we can keep track of voxelToRAS info even for non-standard type // This has the potential of changing direction cosines -void GCAreinit(MRI *mri, GCA *gca) { +void GCAreinit(MRI *mri, GCA *gca) +{ // Keep the direction cosine the same to avoid used by // different mri // modify direction cosines etc. @@ -518,7 +525,8 @@ void GCAreinit(MRI *mri, GCA *gca) { fflush(stdout); } -GCA_PRIOR *getGCAP(GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv) { +GCA_PRIOR *getGCAP(GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv) +{ int xp, yp, zp; GCA_PRIOR *gcap = NULL; @@ -529,7 +537,8 @@ GCA_PRIOR *getGCAP(GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int return (gcap); } -GCA_PRIOR *getGCAPfloat(GCA *gca, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv) { +GCA_PRIOR *getGCAPfloat(GCA *gca, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv) +{ int xp, yp, zp; GCA_PRIOR *gcap = NULL; @@ -540,7 +549,8 @@ GCA_PRIOR *getGCAPfloat(GCA *gca, MRI *mri, TRANSFORM *transform, float xv, floa return (gcap); } -GCA_NODE *getGCAN(GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv) { +GCA_NODE *getGCAN(GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv) +{ int xn, yn, zn; GCA_NODE *gcan = NULL; @@ -551,7 +561,8 @@ GCA_NODE *getGCAN(GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int return (gcan); } -float getPrior(GCA_PRIOR *gcap, int label) { +float getPrior(GCA_PRIOR *gcap, int label) +{ int n; if (gcap == NULL) { @@ -567,7 +578,8 @@ float getPrior(GCA_PRIOR *gcap, int label) { if (n >= gcap->nlabels) { if (gcap->total_training > 0) { return (0.1f / (float)gcap->total_training); /* make it unlikely */ - } else { + } + else { return (VERY_UNLIKELY); } } @@ -578,7 +590,8 @@ float getPrior(GCA_PRIOR *gcap, int label) { return (gcap->priors[n]); } -int GCAisPossible(GCA *gca, MRI *mri, int label, TRANSFORM *transform, int x, int y, int z, int use_mrf) { +int GCAisPossible(GCA *gca, MRI *mri, int label, TRANSFORM *transform, int x, int y, int z, int use_mrf) +{ int n, i, found, nbr_label, xnbr, ynbr, znbr, xn, yn, zn; GCA_PRIOR *gcap = NULL; GC1D *gc; @@ -673,7 +686,8 @@ nbr_priors(GCA *gca, int label, int x0, int y0, int z0) } #endif -static float get_node_prior(GCA *gca, int label, int xn, int yn, int zn) { +static float get_node_prior(GCA *gca, int label, int xn, int yn, int zn) +{ int xp, yp, zp; GCA_PRIOR *gcap; @@ -683,7 +697,8 @@ static float get_node_prior(GCA *gca, int label, int xn, int yn, int zn) { return (VERY_UNLIKELY); } return (getPrior(gcap, label)); - } else { + } + else { return (VERY_UNLIKELY); } } @@ -691,7 +706,8 @@ static float get_node_prior(GCA *gca, int label, int xn, int yn, int zn) { // use the same function for bounds checking // if (ix, iy, iz) is within mri volume, returns NO_ERROR // otherwise ERROR_BADPARAM -static int boundsCheck(int *pix, int *piy, int *piz, MRI *mri) { +static int boundsCheck(int *pix, int *piy, int *piz, MRI *mri) +{ int ix = *pix; int iy = *piy; int iz = *piz; @@ -699,15 +715,20 @@ static int boundsCheck(int *pix, int *piy, int *piz, MRI *mri) { if (ix < 0) { errCode = ERROR_BADPARM; - } else if (iy < 0) { + } + else if (iy < 0) { errCode = ERROR_BADPARM; - } else if (iz < 0) { + } + else if (iz < 0) { errCode = ERROR_BADPARM; - } else if (ix > mri->width - 1) { + } + else if (ix > mri->width - 1) { errCode = ERROR_BADPARM; - } else if (iy > mri->height - 1) { + } + else if (iy > mri->height - 1) { errCode = ERROR_BADPARM; - } else if (iz > mri->depth - 1) { + } + else if (iz > mri->depth - 1) { errCode = ERROR_BADPARM; } @@ -742,7 +763,8 @@ static int boundsCheck(int *pix, int *piy, int *piz, MRI *mri) { return errCode; } -static int gcaNodeToPrior(const GCA *gca, int xn, int yn, int zn, int *pxp, int *pyp, int *pzp) { +static int gcaNodeToPrior(const GCA *gca, int xn, int yn, int zn, int *pxp, int *pyp, int *pzp) +{ // initialize errCode int errCode = NO_ERROR; @@ -768,7 +790,8 @@ static int gcaNodeToPrior(const GCA *gca, int xn, int yn, int zn, int *pxp, int return errCode; } -int GCApriorToNode(const GCA *gca, int xp, int yp, int zp, int *pxn, int *pyn, int *pzn) { +int GCApriorToNode(const GCA *gca, int xp, int yp, int zp, int *pxn, int *pyn, int *pzn) +{ int errCode = NO_ERROR; ///////////////////////////////////////////////////////////////////// // Note that prior and node share the common direction cosines/translation @@ -818,7 +841,8 @@ int GCApriorToNode(const GCA *gca, int xp, int yp, int zp, int *pxn, int *pyn, i return errCode; } -static int dump_gcan(GCA *gca, GCA_NODE *gcan, FILE *fp, int verbose, GCA_PRIOR *gcap) { +static int dump_gcan(GCA *gca, GCA_NODE *gcan, FILE *fp, int verbose, GCA_PRIOR *gcap) +{ int n, i, j, n1; GC1D *gc; float prior; @@ -893,7 +917,8 @@ static int dump_gcan(GCA *gca, GCA_NODE *gcan, FILE *fp, int verbose, GCA_PRIOR //////////////////////////////////////////////////////////////// // transform from template -> node //////////////////////////////////////////////////////////////// -int GCAvoxelToNodeReal(GCA *gca, MRI *mri, double xv, double yv, double zv, double *pxn, double *pyn, double *pzn) { +int GCAvoxelToNodeReal(GCA *gca, MRI *mri, double xv, double yv, double zv, double *pxn, double *pyn, double *pzn) +{ // i_to_r // mri -----> RAS // | | @@ -932,7 +957,8 @@ int GCAvoxelToNodeReal(GCA *gca, MRI *mri, double xv, double yv, double zv, doub return NO_ERROR; } -int GCAvoxelToNode(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxn, int *pyn, int *pzn) { +int GCAvoxelToNode(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxn, int *pyn, int *pzn) +{ int ixn, iyn, izn, xp, yp, zp; int errCode = NO_ERROR; @@ -951,7 +977,8 @@ int GCAvoxelToNode(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxn, int *py } // use rounding to compute the index, not truncation -int GCAvoxelToNodeNearest(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxn, int *pyn, int *pzn) { +int GCAvoxelToNodeNearest(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxn, int *pyn, int *pzn) +{ double xn, yn, zn; int ixn, iyn, izn; int errCode = NO_ERROR; @@ -982,7 +1009,8 @@ int GCAvoxelToPriorReal(const GCA *gca, const double zv, double *pxp, double *pyp, - double *pzp) { + double *pzp) +{ // printf("GCAvoxelToPriorReal1\n"); #if 0 MATRIX *rasFromVoxel = mri->i_to_r__; //extract_i_to_r(mri); @@ -1028,7 +1056,8 @@ int GCAvoxelToPriorReal(const GCA *gca, } int GCAvoxelToPrior( - const GCA *gca, const MRI *mri, const int xv, const int yv, const int zv, int *pxp, int *pyp, int *pzp) { + const GCA *gca, const MRI *mri, const int xv, const int yv, const int zv, int *pxp, int *pyp, int *pzp) +{ double xp, yp, zp; int ixp, iyp, izp; int errCode = NO_ERROR; @@ -1063,7 +1092,8 @@ int GCAvoxelToPrior( } // use rounding to compute the index, not truncation -int GCAvoxelToPriorNearest(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxp, int *pyp, int *pzp) { +int GCAvoxelToPriorNearest(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxp, int *pyp, int *pzp) +{ double xp, yp, zp; int ixp, iyp, izp; int errCode = NO_ERROR; @@ -1087,7 +1117,8 @@ int GCAvoxelToPriorNearest(GCA *gca, MRI *mri, int xv, int yv, int zv, int *pxp, ///////////////////////////////////////////////////////////////////// // transform node->template ///////////////////////////////////////////////////////////////////// -int GCAnodeToVoxelReal(GCA *gca, MRI *mri, double xn, double yn, double zn, double *pxv, double *pyv, double *pzv) { +int GCAnodeToVoxelReal(GCA *gca, MRI *mri, double xn, double yn, double zn, double *pxv, double *pyv, double *pzv) +{ // r_to_i // mri <----- RAS // ^ ^ @@ -1110,7 +1141,8 @@ int GCAnodeToVoxelReal(GCA *gca, MRI *mri, double xn, double yn, double zn, doub return NO_ERROR; } -int GCAnodeToVoxel(GCA *gca, MRI *mri, int xn, int yn, int zn, int *pxv, int *pyv, int *pzv) { +int GCAnodeToVoxel(GCA *gca, MRI *mri, int xn, int yn, int zn, int *pxv, int *pyv, int *pzv) +{ double xv, yv, zv; int ixv, iyv, izv; int errCode = NO_ERROR; @@ -1139,7 +1171,8 @@ int GCAnodeToVoxel(GCA *gca, MRI *mri, int xn, int yn, int zn, int *pxv, int *py ////////////////////////////////////////////////////////////////////// // transform from prior-> template ////////////////////////////////////////////////////////////////////// -int GCApriorToVoxelReal(GCA *gca, MRI *mri, double xp, double yp, double zp, double *pxv, double *pyv, double *pzv) { +int GCApriorToVoxelReal(GCA *gca, MRI *mri, double xp, double yp, double zp, double *pxv, double *pyv, double *pzv) +{ int tid; MATRIX *rasFromPrior = gca->prior_i_to_r__; // extract_i_to_r(gca->mri_prior__); @@ -1162,7 +1195,8 @@ int GCApriorToVoxelReal(GCA *gca, MRI *mri, double xp, double yp, double zp, dou return NO_ERROR; } -int GCApriorToVoxel(GCA *gca, MRI *mri, int xp, int yp, int zp, int *pxv, int *pyv, int *pzv) { +int GCApriorToVoxel(GCA *gca, MRI *mri, int xp, int yp, int zp, int *pxv, int *pyv, int *pzv) +{ double xv, yv, zv; int ixv, iyv, izv; int errCode = NO_ERROR; @@ -1202,7 +1236,8 @@ int GCApriorToVoxel(GCA *gca, MRI *mri, int xp, int yp, int zp, int *pxv, int *p // transform from source -> template space -> prior ////////////////////////////////////////////////////////////////////// int GCAsourceVoxelToPrior( - const GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, int *pxp, int *pyp, int *pzp) { + const GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, int *pxp, int *pyp, int *pzp) +{ float xt, yt, zt; double xrt, yrt, zrt; int retval = NO_ERROR; @@ -1225,9 +1260,11 @@ int GCAsourceVoxelToPrior( yt = yrt; zt = zrt; // TransformSample(transform, xv, yv, zv, &xt, &yt, &zt) ; - } else + } + else ErrorExit(ERROR_BADPARM, "GCAsourceVoxelToPrior: needs vox-to-vox transform"); - } else // morph 3d type can go directly from source to template + } + else // morph 3d type can go directly from source to template { TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); } @@ -1275,7 +1312,8 @@ int GCAsourceVoxelToPrior( } int GCAsourceFloatVoxelToPrior( - GCA *gca, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv, int *pxp, int *pyp, int *pzp) { + GCA *gca, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv, int *pxp, int *pyp, int *pzp) +{ float xt, yt, zt; double xrt, yrt, zrt, xrp, yrp, zrp; @@ -1289,9 +1327,11 @@ int GCAsourceFloatVoxelToPrior( yt = yrt; zt = zrt; // TransformSample(transform, xv, yv, zv, &xt, &yt, &zt) ; - } else + } + else ErrorExit(ERROR_BADPARM, "GCAsourceVoxelToPrior: needs vox-to-vox transform"); - } else // morph 3d type can go directly from source to template + } + else // morph 3d type can go directly from source to template { TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); } @@ -1308,7 +1348,8 @@ int GCAsourceFloatVoxelToPrior( } int GCAsourceFloatVoxelToPriorReal( - GCA *gca, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv, double *pxp, double *pyp, double *pzp) { + GCA *gca, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv, double *pxp, double *pyp, double *pzp) +{ float xt, yt, zt; double xrt, yrt, zrt, xrp, yrp, zrp; @@ -1322,9 +1363,11 @@ int GCAsourceFloatVoxelToPriorReal( yt = yrt; zt = zrt; // TransformSample(transform, xv, yv, zv, &xt, &yt, &zt) ; - } else + } + else ErrorExit(ERROR_BADPARM, "GCAsourceVoxelToPrior: needs vox-to-vox transform"); - } else // morph 3d type can go directly from source to template + } + else // morph 3d type can go directly from source to template { TransformSampleReal2(transform, xv, yv, zv, &xt, &yt, &zt); } @@ -1343,7 +1386,8 @@ int GCAsourceFloatVoxelToPriorReal( // transform from source -> template space -> prior ///////////////////////////////////////////////////////////////////// int GCAsourceVoxelToNode( - const GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, int *pxn, int *pyn, int *pzn) { + const GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, int *pxn, int *pyn, int *pzn) +{ #if 1 int xp, yp, zp; @@ -1364,9 +1408,11 @@ int GCAsourceVoxelToNode( xt = xrt; yt = yrt; zt = zrt; - } else + } + else ErrorExit(ERROR_BADPARM, "GCAsourceVoxelToNode: needs vox-to-vox transform"); - } else { + } + else { TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); } #if USE_ROUND @@ -1402,7 +1448,8 @@ int GCAsourceVoxelToNode( ////////////////////////////////////////////////////////////////////// // get the matrix that transforms prior coordinates into source voxel coords //////////////////////////////////////////////////////////////////// -MATRIX *GCAgetPriorToSourceVoxelMatrix(GCA *gca, const MRI *mri, TRANSFORM *transform) { +MATRIX *GCAgetPriorToSourceVoxelMatrix(GCA *gca, const MRI *mri, TRANSFORM *transform) +{ MATRIX *rasFromPrior = gca->prior_i_to_r__; // extract_i_to_r(gca->mri_prior__); MATRIX *voxelFromRAS = gca->mri_tal__->r_to_i__; // extract_r_to_i(mri); @@ -1441,7 +1488,8 @@ int GCApriorToSourceVoxelFloat(GCA *gca, const int zp, float *pxv, float *pyv, - float *pzv) { + float *pzv) +{ int width, height, depth; double xt, yt, zt; float xv, yv, zv; @@ -1504,15 +1552,20 @@ int GCApriorToSourceVoxelFloat(GCA *gca, // TransformSampleInverse(transform, xt, yt, zt, &xc, &yc, &zc); if (xc < 0) { errCode = ERROR_BADPARM; - } else if (yc < 0) { + } + else if (yc < 0) { errCode = ERROR_BADPARM; - } else if (zc < 0) { + } + else if (zc < 0) { errCode = ERROR_BADPARM; - } else if (xc > (width - 1)) { + } + else if (xc > (width - 1)) { errCode = ERROR_BADPARM; - } else if (yc > (height - 1)) { + } + else if (yc > (height - 1)) { errCode = ERROR_BADPARM; - } else if (zc > (depth - 1)) { + } + else if (zc > (depth - 1)) { errCode = ERROR_BADPARM; } xv = xc; @@ -1524,9 +1577,11 @@ int GCApriorToSourceVoxelFloat(GCA *gca, yv = yc/mri->ysize; zv = zc/mri->zsize; #endif - } else + } + else ErrorExit(ERROR_BADPARM, "GCApriorToSourceVoxelFloat: needs vox-to-vox transform"); - } else // go directly from template to source + } + else // go directly from template to source { TransformSampleInverse(transform, xt, yt, zt, &xv, &yv, &zv); } @@ -1537,7 +1592,8 @@ int GCApriorToSourceVoxelFloat(GCA *gca, } int GCAnodeToSourceVoxelFloat( - GCA *gca, MRI *mri, TRANSFORM *transform, int xn, int yn, int zn, float *pxv, float *pyv, float *pzv) { + GCA *gca, MRI *mri, TRANSFORM *transform, int xn, int yn, int zn, float *pxv, float *pyv, float *pzv) +{ int width, height, depth; double xt, yt, zt; float xv, yv, zv; @@ -1556,21 +1612,27 @@ int GCAnodeToSourceVoxelFloat( // TransformSampleInverse(transform, xt, yt, zt, &xc, &yc, &zc); if (xc < 0) { errCode = ERROR_BADPARM; - } else if (yc < 0) { + } + else if (yc < 0) { errCode = ERROR_BADPARM; - } else if (zc < 0) { + } + else if (zc < 0) { errCode = ERROR_BADPARM; - } else if (xc > (width - 1)) { + } + else if (xc > (width - 1)) { errCode = ERROR_BADPARM; - } else if (yc > (height - 1)) { + } + else if (yc > (height - 1)) { errCode = ERROR_BADPARM; - } else if (zc > (depth - 1)) { + } + else if (zc > (depth - 1)) { errCode = ERROR_BADPARM; } xv = xc; yv = yc; zv = zc; - } else // template to source + } + else // template to source { TransformSampleInverse(transform, xt, yt, zt, &xv, &yv, &zv); } @@ -1580,22 +1642,27 @@ int GCAnodeToSourceVoxelFloat( return errCode; } -int GCAnodeToSourceVoxel( - GCA *gca, MRI *mri, TRANSFORM *transform, int xn, int yn, int zn, int *pxv, int *pyv, int *pzv) { +int GCAnodeToSourceVoxel(GCA *gca, MRI *mri, TRANSFORM *transform, int xn, int yn, int zn, int *pxv, int *pyv, int *pzv) +{ float xf, yf, zf; int errCode = NO_ERROR; errCode = GCAnodeToSourceVoxelFloat(gca, mri, transform, xn, yn, zn, &xf, &yf, &zf); if (xf < 0) { errCode = ERROR_BADPARM; - } else if (yf < 0) { + } + else if (yf < 0) { errCode = ERROR_BADPARM; - } else if (zf < 0) { + } + else if (zf < 0) { errCode = ERROR_BADPARM; - } else if (xf > (mri->width - 1)) { + } + else if (xf > (mri->width - 1)) { errCode = ERROR_BADPARM; - } else if (yf > (mri->height - 1)) { + } + else if (yf > (mri->height - 1)) { errCode = ERROR_BADPARM; - } else if (zf > (mri->depth - 1)) { + } + else if (zf > (mri->depth - 1)) { errCode = ERROR_BADPARM; } @@ -1613,22 +1680,28 @@ int GCApriorToSourceVoxel(GCA *gca, const int zp, int *pxv, int *pyv, - int *pzv) { + int *pzv) +{ float xf, yf, zf; int errCode = NO_ERROR; errCode = GCApriorToSourceVoxelFloat(gca, mri, transform, xp, yp, zp, &xf, &yf, &zf); if (xf < 0) { errCode = ERROR_BADPARM; - } else if (yf < 0) { + } + else if (yf < 0) { errCode = ERROR_BADPARM; - } else if (zf < 0) { + } + else if (zf < 0) { errCode = ERROR_BADPARM; - } else if (xf > (mri->width - 1)) { + } + else if (xf > (mri->width - 1)) { errCode = ERROR_BADPARM; - } else if (yf > (mri->height - 1)) { + } + else if (yf > (mri->height - 1)) { errCode = ERROR_BADPARM; - } else if (zf > (mri->depth - 1)) { + } + else if (zf > (mri->depth - 1)) { errCode = ERROR_BADPARM; } @@ -1638,19 +1711,22 @@ int GCApriorToSourceVoxel(GCA *gca, return errCode; } -GCA *GCAalloc(int ninputs, float prior_spacing, float node_spacing, int width, int height, int depth, int flags) { +GCA *GCAalloc(int ninputs, float prior_spacing, float node_spacing, int width, int height, int depth, int flags) +{ int max_labels; if (flags & GCA_NO_GCS) { max_labels = 0; - } else { + } + else { max_labels = DEFAULT_MAX_LABELS_PER_GCAN; } return (gcaAllocMax(ninputs, prior_spacing, node_spacing, width, height, depth, max_labels, flags)); } GCA *gcaAllocMax( - int ninputs, float prior_spacing, float node_spacing, int width, int height, int depth, int max_labels, int flags) { + int ninputs, float prior_spacing, float node_spacing, int width, int height, int depth, int max_labels, int flags) +{ GCA *gca; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -1785,7 +1861,8 @@ GCA *gcaAllocMax( return (gca); } -int GCAfree(GCA **pgca) { +int GCAfree(GCA **pgca) +{ GCA *gca; int x, y, z; @@ -1822,7 +1899,8 @@ int GCAfree(GCA **pgca) { return (NO_ERROR); } -int GCANfree(GCA_NODE *gcan, int ninputs) { +int GCANfree(GCA_NODE *gcan, int ninputs) +{ if (gcan->nlabels) { free(gcan->labels); free_gcs(gcan->gcs, gcan->nlabels, ninputs); @@ -1830,7 +1908,8 @@ int GCANfree(GCA_NODE *gcan, int ninputs) { return (NO_ERROR); } -int GCAPfree(GCA_PRIOR *gcap) { +int GCAPfree(GCA_PRIOR *gcap) +{ if (gcap->nlabels) { free(gcap->labels); free(gcap->priors); @@ -1838,7 +1917,8 @@ int GCAPfree(GCA_PRIOR *gcap) { return (NO_ERROR); } -void PrintInfoOnLabels(GCA *gca, int label, int xn, int yn, int zn, int xp, int yp, int zp, int x, int y, int z) { +void PrintInfoOnLabels(GCA *gca, int label, int xn, int yn, int zn, int xp, int yp, int zp, int x, int y, int z) +{ GCA_NODE *gcan; GCA_PRIOR *gcap; GC1D *gc; @@ -1876,7 +1956,8 @@ void PrintInfoOnLabels(GCA *gca, int label, int xn, int yn, int zn, int xp, int fflush(stdout); } -int GCAtrainCovariances(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform) { +int GCAtrainCovariances(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform) +{ int x, y, z, width, height, depth, label, xn, yn, zn; float vals[MAX_GCA_INPUTS]; int xp, yp, zp, holes_filled = 0; @@ -1998,7 +2079,8 @@ int GCAtrainCovariances(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *t { if (xn == Gx && yn == Gy && zn == Gz) printf("filling node hole at (%d, %d, %d) %s\n", xn, yn, zn, cma_label_to_name(label)); - } else { + } + else { load_vals(mri_inputs, x, y, z, vals, gca->ninputs); GCAupdateNodeCovariance(gca, mri_inputs, xn, yn, zn, vals, label); } @@ -2019,7 +2101,8 @@ int GCAtrainCovariances(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *t } #include -int GCAtrain(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform, GCA *gca_prune, int noint) { +int GCAtrain(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform, GCA *gca_prune, int noint) +{ int x, y, z, width, height, depth, label, xn, yn, zn, holes_filled, /*i, xnbr, ynbr, znbr, xn_nbr, yn_nbr, zn_nbr,*/ xp, yp, zp; float vals[MAX_GCA_INPUTS]; @@ -2279,7 +2362,8 @@ int GCAtrain(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform, G return (NO_ERROR); } -int GCAwrite(GCA *gca, const char *fname) { +int GCAwrite(GCA *gca, const char *fname) +{ znzFile file; int x, y, z, n, i, j; GCA_NODE *gcan; @@ -2426,7 +2510,8 @@ int GCAwrite(GCA *gca, const char *fname) { return (NO_ERROR); } -GCA *GCAread(const char *fname) { +GCA *GCAread(const char *fname) +{ znzFile file; int x, y, z, n, i, j; GCA *gca; @@ -2460,7 +2545,8 @@ GCA *GCAread(const char *fname) { ninputs = znzreadInt(file); if (version == 3.0) { flags = znzreadInt(file); - } else { + } + else { flags = 0; } @@ -2506,7 +2592,8 @@ GCA *GCAread(const char *fname) { x, y, z); - } else // no labels assigned to this node + } + else // no labels assigned to this node { gcan->labels = 0; gcan->gcs = 0; @@ -2556,8 +2643,9 @@ GCA *GCAread(const char *fname) { } } } - } else /* current version - stores priors at different - resolution than densities */ + } + else /* current version - stores priors at different + resolution than densities */ { if (!FEQUAL(version, GCA_UCHAR_VERSION) && !FEQUAL(version, GCA_INT_VERSION)) { // fclose(fp) ; @@ -2625,7 +2713,8 @@ GCA *GCAread(const char *fname) { x, y, z); - } else // no labels at this node + } + else // no labels at this node { gcan->labels = 0; gcan->gcs = 0; @@ -2639,7 +2728,8 @@ GCA *GCAread(const char *fname) { // gcan->labels[n] = (unsigned short)znzread1(file) ; znzread1(&tempZNZ, file); gcan->labels[n] = (unsigned short)tempZNZ; - } else { + } + else { gcan->labels[n] = (unsigned short)znzreadInt(file); } @@ -2716,7 +2806,8 @@ GCA *GCAread(const char *fname) { x, y, z); - } else // no labels assigned to this priors + } + else // no labels assigned to this priors { gcap->labels = 0; gcap->priors = 0; @@ -2725,7 +2816,8 @@ GCA *GCAread(const char *fname) { if (version == GCA_UCHAR_VERSION) { znzread1(&tempZNZ, file); gcap->labels[n] = (unsigned short)tempZNZ; - } else { + } + else { gcap->labels[n] = (unsigned short)znzreadInt(file); } if (gcap->labels[n] > gca->max_label) gca->max_label = gcap->labels[n]; @@ -2855,7 +2947,8 @@ GCA *GCAread(const char *fname) { return (gca); } -static int GCAupdatePrior(GCA *gca, MRI *mri, int xn, int yn, int zn, int label) { +static int GCAupdatePrior(GCA *gca, MRI *mri, int xn, int yn, int zn, int label) +{ int n; GCA_PRIOR *gcap; @@ -2918,7 +3011,8 @@ static int GCAupdatePrior(GCA *gca, MRI *mri, int xn, int yn, int zn, int label) return (NO_ERROR); } -static int GCAupdateNodeCovariance(GCA *gca, MRI *mri, int xn, int yn, int zn, float *vals, int label) { +static int GCAupdateNodeCovariance(GCA *gca, MRI *mri, int xn, int yn, int zn, float *vals, int label) +{ int n, r, c, v; GCA_NODE *gcan; GC1D *gc; @@ -2968,8 +3062,8 @@ static int GCAupdateNodeCovariance(GCA *gca, MRI *mri, int xn, int yn, int zn, f return (NO_ERROR); } -static int GCAupdateNode( - GCA *gca, MRI *mri, int xn, int yn, int zn, float *vals, int label, GCA *gca_prune, int noint) { +static int GCAupdateNode(GCA *gca, MRI *mri, int xn, int yn, int zn, float *vals, int label, GCA *gca_prune, int noint) +{ int n, i; GCA_NODE *gcan; GC1D *gc; @@ -3078,7 +3172,8 @@ static int GCAupdateNode( /* these will be updated when training is complete */ if (noint) { gc->n_just_priors++; - } else { + } + else { // vals[] array is the values of inputs at this point for (i = 0; i < gca->ninputs; i++) { gc->means[i] += vals[i]; @@ -3097,7 +3192,8 @@ static int GCAupdateNode( return (NO_ERROR); } -int GCAcompleteMeanTraining(GCA *gca) { +int GCAcompleteMeanTraining(GCA *gca) +{ int x, y, z, n, total_nodes, total_gcs, i, j, holes_filled, total_brain_gcs, total_brain_nodes, r; float nsamples; GCA_NODE *gcan; @@ -3141,7 +3237,8 @@ int GCAcompleteMeanTraining(GCA *gca) { gc->means[r] /= nsamples; check_finite("GCAcompleteMeanTraining: mean", gc->means[r]); } - } else { + } + else { int r; for (r = 0; r < gca->ninputs; r++) { gc->means[r] = -1; /* mark it for later processing */ @@ -3220,7 +3317,8 @@ int GCAcompleteMeanTraining(GCA *gca) { return (NO_ERROR); } -int GCAcompleteCovarianceTraining(GCA *gca) { +int GCAcompleteCovarianceTraining(GCA *gca) +{ int x, y, z, n, holes_filled, r, c, v, nregs = 0, nsamples; GCA_NODE *gcan; GC1D *gc; @@ -3411,7 +3509,8 @@ int GCAcompleteCovarianceTraining(GCA *gca) { return (NO_ERROR); } -MRI *GCAlabel(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform) { +MRI *GCAlabel(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform) +{ int x, width, height, depth, num_pv, use_partial_volume_stuff; #if INTERP_PRIOR float prior; @@ -3578,7 +3677,8 @@ MRI *GCAlabel(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform) { ///////////////////////////////////////////// // set the value MRIsetVoxVal(mri_dst, x, y, z, 0, label); - } else { + } + else { MRIsetVoxVal(mri_dst, x, y, z, 0, 0); // unknown } } // z loop @@ -3588,7 +3688,8 @@ MRI *GCAlabel(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform) { return (mri_dst); } -MRI *GCAlabelProbabilities(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform) { +MRI *GCAlabelProbabilities(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform) +{ int x, width, height, depth; width = mri_inputs->width; @@ -3647,7 +3748,8 @@ MRI *GCAlabelProbabilities(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *t max_p = 255; } MRIsetVoxVal(mri_dst, x, y, z, 0, (BUFTYPE)max_p); - } else { + } + else { MRIsetVoxVal(mri_dst, x, y, z, 0, 255); // 0; } } @@ -3658,7 +3760,8 @@ MRI *GCAlabelProbabilities(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *t } MRI *GCAcomputeTopNProbabilities( - MRI *mri_inputs, GCA *gca, MRI *mri_labels, MRI *mri_dst, TRANSFORM *transform, int max_labels) { + MRI *mri_inputs, GCA *gca, MRI *mri_labels, MRI *mri_dst, TRANSFORM *transform, int max_labels) +{ int x, y, z, width, height, depth, label, xn, yn, zn, n; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -3718,7 +3821,8 @@ MRI *GCAcomputeTopNProbabilities( if (n < gcap->nlabels) { MRIsetVoxVal(mri_dst, x, y, z, 2 * n, label_probs[n].label); MRIsetVoxVal(mri_dst, x, y, z, 2 * n + 1, -label_probs[n].prob); // remove the negative from before - } else { + } + else { MRIsetVoxVal(mri_dst, x, y, z, 2 * n, -1); MRIsetVoxVal(mri_dst, x, y, z, 2 * n + 1, 0); } @@ -3731,7 +3835,8 @@ MRI *GCAcomputeTopNProbabilities( return (mri_dst); } -MRI *GCAcomputeProbabilities(MRI *mri_inputs, GCA *gca, MRI *mri_labels, MRI *mri_dst, TRANSFORM *transform) { +MRI *GCAcomputeProbabilities(MRI *mri_inputs, GCA *gca, MRI *mri_labels, MRI *mri_dst, TRANSFORM *transform) +{ int x, y, z, width, height, depth, label, xn, yn, zn, n; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -3801,7 +3906,8 @@ MRI *GCAcomputeProbabilities(MRI *mri_inputs, GCA *gca, MRI *mri_labels, MRI *mr #define STARTING_T 500 MRI *GCAannealUnlikelyVoxels( - MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, int max_iter, MRI *mri_fixed, double prior_factor) { + MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, int max_iter, MRI *mri_fixed, double prior_factor) +{ int x, y, z, width, depth, height, *x_indices, *y_indices, *z_indices, nindices, index, iter, nchanged, xn, yn, zn, n, nbad, old_label; double log_posterior, T, delta_E, p, rn, new_posterior, old_posterior, total_posterior; @@ -3888,7 +3994,8 @@ MRI *GCAannealUnlikelyVoxels( } nchanged++; total_posterior += new_posterior; - } else { + } + else { total_posterior += old_posterior; if (old_posterior < log(1.0f / (float)gcan->total_training)) { nbad++; @@ -3917,7 +4024,8 @@ MRI *GCAannealUnlikelyVoxels( return (mri_dst); } -GCA *GCAreduce(GCA *gca_src) { +GCA *GCAreduce(GCA *gca_src) +{ #if 0 GCA *gca_dst ; int xs, ys, zs, xd, yd, zd, swidth, sheight, sdepth, @@ -4070,7 +4178,8 @@ GCA *GCAreduce(GCA *gca_src) { #endif } -MRI *GCAclassify(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, int max_labels) { +MRI *GCAclassify(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, int max_labels) +{ int x, y, z, width, height, depth, xn, yn, zn, n; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -4132,7 +4241,8 @@ MRI *GCAclassify(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, if (n < gcan->nlabels) { MRIseq_vox(mri_dst, x, y, z, n * 2) = label_probs[n].label; MRIseq_vox(mri_dst, x, y, z, n * 2 + 1) = (BUFTYPE)nint(255.0 * label_probs[n].prob / total_p); - } else { + } + else { MRIseq_vox(mri_dst, x, y, z, n * 2) = 255; MRIseq_vox(mri_dst, x, y, z, n * 2 + 1) = 0; } @@ -4145,7 +4255,8 @@ MRI *GCAclassify(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, return (mri_dst); } -int compare_sort_probabilities(const void *plp1, const void *plp2) { +int compare_sort_probabilities(const void *plp1, const void *plp2) +{ LABEL_PROB *lp1, *lp2; lp1 = (LABEL_PROB *)plp1; @@ -4153,7 +4264,8 @@ int compare_sort_probabilities(const void *plp1, const void *plp2) { if (lp1->prob > lp2->prob) { return (1); - } else if (lp1->prob < lp2->prob) { + } + else if (lp1->prob < lp2->prob) { return (-1); } @@ -4161,7 +4273,8 @@ int compare_sort_probabilities(const void *plp1, const void *plp2) { } int GCAremoveOutlyingSamples( - GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, float nsigma) { + GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, float nsigma) +{ int x, y, z, width, height, depth, i, nremoved, xp, yp, zp; double dist; float vals[MAX_GCA_INPUTS]; @@ -4222,7 +4335,8 @@ int GCAremoveOutlyingSamples( } float GCAnormalizedLogSampleProbability( - GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) { + GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) +{ int x, y, z, width, height, depth, xn, yn, zn, i, n, xp, yp, zp; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -4287,8 +4401,8 @@ float GCAnormalizedLogSampleProbability( return ((float)total_log_p); } -float GCAcomputeLabelIntensityVariance( - GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples) { +float GCAcomputeLabelIntensityVariance(GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples) +{ int i, tid, nthreads, label_counts[MAX_CMA_LABELS], label, max_label, nlabels; double label_means[MAX_CMA_LABELS], label_vars[MAX_CMA_LABELS], total_var; MATRIX *m_prior2source_voxel = NULL; @@ -4313,7 +4427,9 @@ float GCAcomputeLabelIntensityVariance( */ #ifdef HAVE_OPENMP #pragma omp parallel - { nthreads = omp_get_num_threads(); } + { + nthreads = omp_get_num_threads(); + } #else nthreads = 1; #endif @@ -4355,7 +4471,8 @@ float GCAcomputeLabelIntensityVariance( yp = gcas[i].yp; zp = gcas[i].zp; GCApriorToSourceVoxel(gca, mri_inputs, transform, xp, yp, zp, &x, &y, &z); - } else { + } + else { V3_X(v_src[tid]) = xp = gcas[i].xp; V3_Y(v_src[tid]) = yp = gcas[i].yp; V3_Z(v_src[tid]) = zp = gcas[i].zp; @@ -4386,7 +4503,8 @@ float GCAcomputeLabelIntensityVariance( label_vars[label] += (vals[0] * vals[0]); if (FZERO(vals[0]) && gcas[i].label == Gdiag_no) DiagBreak(); - } else { // outside the voxel + } + else { // outside the voxel label_means[gcas[i].label] += 1000000; // BIG label_vars[gcas[i].label] += 1000000; // BIG } @@ -4413,7 +4531,8 @@ float GCAcomputeLabelIntensityVariance( } float GCAcomputeLogSampleProbability( - GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) { + GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) +{ int i, tid, nthreads; double total_log_p; MATRIX *m_prior2source_voxel = NULL; @@ -4437,7 +4556,9 @@ float GCAcomputeLogSampleProbability( */ #ifdef HAVE_OPENMP #pragma omp parallel - { nthreads = omp_get_num_threads(); } + { + nthreads = omp_get_num_threads(); + } #else nthreads = 1; #endif @@ -4478,7 +4599,8 @@ float GCAcomputeLogSampleProbability( yp = gcas[i].yp; zp = gcas[i].zp; GCApriorToSourceVoxel(gca, mri_inputs, transform, xp, yp, zp, &x, &y, &z); - } else { + } + else { V3_X(v_src[tid]) = xp = gcas[i].xp; V3_Y(v_src[tid]) = yp = gcas[i].yp; V3_Z(v_src[tid]) = zp = gcas[i].zp; @@ -4504,7 +4626,8 @@ float GCAcomputeLogSampleProbability( DiagBreak(); } if (log_p < -clamp) log_p = -clamp; - } else { // outside the voxel + } + else { // outside the voxel log_p = -1000000; // BIG_AND_NEGATIVE; // log(VERY_UNLIKELY); // BIG_AND_NEGATIVE; // outside_log_p += log_p; @@ -4523,7 +4646,8 @@ float GCAcomputeLogSampleProbability( } float GCAcomputeLogSampleProbabilityLongitudinal( - GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) { + GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) +{ int x, y, z, width, height, depth, i, xp, yp, zp; float vals[MAX_GCA_INPUTS]; double total_log_p, log_p; @@ -4590,7 +4714,8 @@ float GCAcomputeLogSampleProbabilityLongitudinal( DiagBreak(); } } - } else // outside the voxel + } + else // outside the voxel { log_p = -1000000; // BIG_AND_NEGATIVE; // log(VERY_UNLIKELY); // BIG_AND_NEGATIVE; @@ -4615,7 +4740,8 @@ float GCAcomputeLogSampleProbabilityLongitudinal( } float GCAcomputeLogSampleProbabilityUsingCoords( - GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) { + GCA *gca, GCA_SAMPLE *gcas, MRI *mri_inputs, TRANSFORM *transform, int nsamples, double clamp) +{ int x, y, z, width, height, depth, xp, yp, zp, xn, yn, zn, i; float vals[MAX_GCA_INPUTS]; double total_log_p, log_p; @@ -4655,7 +4781,8 @@ float GCAcomputeLogSampleProbabilityUsingCoords( DiagBreak(); fprintf(stdout, "total log p not finite at (%d, %d, %d)\n", x, y, z); } - } else { + } + else { log_p = log(VERY_UNLIKELY); // BIG_AND_NEGATIVE; total_log_p += log_p; gcas[i].log_p = log_p; @@ -4670,7 +4797,8 @@ float GCAcomputeLogSampleProbabilityUsingCoords( compute the probability of the image given the transform and the class stats. */ -float GCAcomputeLogImageProbability(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform) { +float GCAcomputeLogImageProbability(GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform) +{ int x, y, z, width, height, depth, xn, yn, zn, n, label; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -4810,7 +4938,8 @@ GCAsampleStats(GCA *gca, MRI *mri, int class, #define MIN_SPACING 8 -int GCAtransformSamples(GCA *gca_src, GCA *gca_dst, GCA_SAMPLE *gcas, int nsamples) { +int GCAtransformSamples(GCA *gca_src, GCA *gca_dst, GCA_SAMPLE *gcas, int nsamples) +{ int scale, i, label, xd, yd, zd, xs, ys, zs, n, xk, yk, zk, xd0, yd0, zd0, min_y_i, xdn, ydn, zdn; float max_p, min_v, vscale, min_y, prior; GCA_NODE *gcan; @@ -4904,7 +5033,8 @@ static int exclude_classes[] = { static int compare_gca_samples(const void *pc1, const void *pc2); -static int compare_gca_samples(const void *pgcas1, const void *pgcas2) { +static int compare_gca_samples(const void *pgcas1, const void *pgcas2) +{ register GCA_SAMPLE *gcas1, *gcas2; gcas1 = (GCA_SAMPLE *)pgcas1; @@ -4949,7 +5079,8 @@ static int compare_gca_samples(const void *pgcas1, const void *pgcas2) { if (gcas1->prior > gcas2->prior) { return (-1); - } else if (gcas1->prior < gcas2->prior) { + } + else if (gcas1->prior < gcas2->prior) { return (1); } @@ -4957,7 +5088,8 @@ static int compare_gca_samples(const void *pgcas1, const void *pgcas2) { } #define MAX_SPACING 16 /* mm */ -GCA_SAMPLE *GCAfindStableSamplesByLabel(GCA *gca, int nsamples, float min_prior) { +GCA_SAMPLE *GCAfindStableSamplesByLabel(GCA *gca, int nsamples, float min_prior) +{ GCA_SAMPLE *gcas, *ordered_labels[MAX_DIFFERENT_LABELS], *gcas2; GCA_PRIOR *gcap; GC1D *gc; @@ -5136,12 +5268,14 @@ GCA_SAMPLE *GCAfindStableSamplesByLabel(GCA *gca, int nsamples, float min_prior) for (c = r; c < gca->ninputs; c++, v++) { if (c == r) { ordered_labels[label][i].covars[v] = 1.0; - } else { + } + else { ordered_labels[label][i].covars[v] = 0; } } } - } else { + } + else { int r, c, v; for (v = r = 0; r < gca->ninputs; r++) { ordered_labels[label][i].means[r] = gc->means[r]; @@ -5240,7 +5374,8 @@ GCA_SAMPLE *GCAfindStableSamplesByLabel(GCA *gca, int nsamples, float min_prior) return (gcas); } -GCA_SAMPLE *GCAfindContrastSamples(GCA *gca, int *pnsamples, int min_spacing, float min_prior) { +GCA_SAMPLE *GCAfindContrastSamples(GCA *gca, int *pnsamples, int min_spacing, float min_prior) +{ #if 0 GCA_SAMPLE *gcas ; GC1D *gc ; @@ -5501,7 +5636,8 @@ GCA_SAMPLE *GCAfindStableSamples(GCA *gca, float min_prior, int *exclude_list, int unknown_nbr_spacing, - int vent_spacing) { + int vent_spacing) +{ GCA_SAMPLE *gcas; int xi, yi, zi, width, height, depth, label, nfound; int label_counts[MAX_DIFFERENT_LABELS], best_label, nzeros, r; @@ -5577,9 +5713,11 @@ GCA_SAMPLE *GCAfindStableSamples(GCA *gca, prior_stride = (float)min_spacing / (float)gca->prior_spacing; if (prior_stride >= 2.5) { prior_factor = .5; - } else if (prior_stride >= 1.5) { + } + else if (prior_stride >= 1.5) { prior_factor = .75; - } else { + } + else { prior_factor = .9; } @@ -5624,7 +5762,8 @@ GCA_SAMPLE *GCAfindStableSamples(GCA *gca, if ((different_nbr_max_labels(gca, x, y, z, unknown_nbr_spacing, 0) > 0) && (exclude_list && exclude_list[0] == 0) && (priors[0] >= min_prior) && (priors[0] >= .5 * max_priors[0])) { best_label = 0; - } else { + } + else { best_label = -1; } @@ -5679,11 +5818,13 @@ GCA_SAMPLE *GCAfindStableSamples(GCA *gca, nfound++; } } - } else { + } + else { DiagBreak(); } } - } else { + } + else { /* find best gc with this label */ if (gcaFindBestSample(gca, x, y, z, best_label, prior_stride / 2, &gcas[nfound]) == NO_ERROR) { for (r = 0; r < gca->ninputs; r++) { @@ -5723,7 +5864,8 @@ GCA_SAMPLE *GCAfindStableSamples(GCA *gca, return (gcas); } GCA_SAMPLE *GCAfindExteriorSamples( - GCA *gca, int *pnsamples, int min_spacing, float min_prior, int unknown_nbr_spacing, int use_ventricles) { + GCA *gca, int *pnsamples, int min_spacing, float min_prior, int unknown_nbr_spacing, int use_ventricles) +{ GCA_SAMPLE *gcas; int xi, yi, zi, width, height, depth, nfound; int nzeros, r, best_label, label; @@ -5851,7 +5993,8 @@ GCA_SAMPLE *GCAfindExteriorSamples( nzeros++; nfound++; } - } else { + } + else { DiagBreak(); } } @@ -5870,7 +6013,8 @@ GCA_SAMPLE *GCAfindExteriorSamples( ////////////////////////////////////////////////////////////////// // write segmented volume for sampled points // the values are set only at prior_spacing/size -int GCAwriteSamples(GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname) { +int GCAwriteSamples(GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname) +{ int n, xv, yv, zv; MRI *mri_dst; @@ -5886,7 +6030,8 @@ int GCAwriteSamples(GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const ch if (gcas[n].label > 0) // if label non-zero (!unknown) { MRIsetVoxVal(mri_dst, xv, yv, zv, 0, gcas[n].label); - } else // unknown label changed to + } + else // unknown label changed to { MRIsetVoxVal(mri_dst, xv, yv, zv, 0, Left_undetermined); } @@ -5908,7 +6053,8 @@ int GCAwriteSamples(GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const ch \fn MRI *GCAtoMLLabel(GCA *gca, MRI *mri) \brief Creates a seg volume with the most likely a priori label in the GCA */ -MRI *GCAtoMLLabel(GCA *gca, MRI *mri) { +MRI *GCAtoMLLabel(GCA *gca, MRI *mri) +{ int width, height, depth, x; width = gca->node_width; @@ -5959,7 +6105,8 @@ MRI *GCAtoMLLabel(GCA *gca, MRI *mri) { \brief Creates a volume with the probability of the most likely a priori label in the GCA */ -MRI *GCAtoAPrioriMax(GCA *gca, MRI *mri) { +MRI *GCAtoAPrioriMax(GCA *gca, MRI *mri) +{ int width, height, depth, x; width = gca->node_width; @@ -6009,7 +6156,8 @@ MRI *GCAtoAPrioriMax(GCA *gca, MRI *mri) { } /*--------------------------------------------------------------------------------*/ -MRI *GCAmri(GCA *gca, MRI *mri) { +MRI *GCAmri(GCA *gca, MRI *mri) +{ int frame, width, height, depth, x, y, z, xp, yp, zp, n, xn, yn, zn; float val; GC1D *gc; @@ -6054,7 +6202,8 @@ MRI *GCAmri(GCA *gca, MRI *mri) { return (mri); } -MRI *GCAlabelMri(GCA *gca, MRI *mri, int label, TRANSFORM *transform) { +MRI *GCAlabelMri(GCA *gca, MRI *mri, int label, TRANSFORM *transform) +{ int width, height, depth, x, y, z, xn, yn, zn, n, frame; float val; GC1D *gc = NULL; @@ -6140,7 +6289,8 @@ MRI *GCAlabelMri(GCA *gca, MRI *mri, int label, TRANSFORM *transform) { return (mri); } -static int different_nbr_max_labels(GCA *gca, int x, int y, int z, int wsize, int label) { +static int different_nbr_max_labels(GCA *gca, int x, int y, int z, int wsize, int label) +{ int xk, yk, zk, xi, yi, zi, nbrs, n, width, height, depth, max_label; GCA_PRIOR *gcap; double max_p; @@ -6252,7 +6402,8 @@ static int gcaRegionStats(GCA *gca, int wsize, float *priors, float *vars, - float means[MAX_DIFFERENT_LABELS][MAX_GCA_INPUTS]) { + float means[MAX_DIFFERENT_LABELS][MAX_GCA_INPUTS]) +{ int xk, yk, zk, xi, yi, zi, width, height, depth, label, n, total_training, r, l; GCA_PRIOR *gcap; GC1D *gc; @@ -6333,7 +6484,8 @@ static int gcaRegionStats(GCA *gca, } return (NO_ERROR); } -static int gcaFindBestSample(GCA *gca, int x, int y, int z, int label, int wsize, GCA_SAMPLE *gcas) { +static int gcaFindBestSample(GCA *gca, int x, int y, int z, int label, int wsize, GCA_SAMPLE *gcas) +{ int xk, yk, zk, xi, yi, zi, width, height, depth, n, best_n, best_x, best_y, best_z, xn, yn, zn, r, c, v; GCA_PRIOR *gcap; GC1D *gc, *best_gc; @@ -6603,7 +6755,8 @@ gcaFindClosestMeanSample(GCA *gca, // same as GCAtransformAndWriteSamples except here we write // the -logp into the volume instead of the seg label int GCAtransformAndWriteSamplePvals( - GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname, TRANSFORM *transform) { + GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname, TRANSFORM *transform) +{ int i, n, xv, yv, zv; MRI *mri_dst; float vals[MAX_GCA_INPUTS]; @@ -6663,7 +6816,8 @@ int GCAtransformAndWriteSamplePvals( // same as GCAtransformAndWriteSamples except here we write // the mean into the volume instead of the seg label int GCAtransformAndWriteSampleMeans( - GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname, TRANSFORM *transform) { + GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname, TRANSFORM *transform) +{ int n, xv, yv, zv, f; MRI *mri_dst; GCA_PRIOR *gcap; @@ -6709,7 +6863,8 @@ int GCAtransformAndWriteSampleMeans( } // create a volume mapped to the current mri volume int GCAtransformAndWriteSamples( - GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname, TRANSFORM *transform) { + GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, const char *fname, TRANSFORM *transform) +{ int n, xv, yv, zv, label; MRI *mri_dst; @@ -6724,9 +6879,11 @@ int GCAtransformAndWriteSamples( if (!GCApriorToSourceVoxel(gca, mri_dst, transform, gcas[n].xp, gcas[n].yp, gcas[n].zp, &xv, &yv, &zv)) { if (gcas[n].label > 0) { label = gcas[n].label; - } else if (gcas[n].label == 0) { + } + else if (gcas[n].label == 0) { label = 29; /* Left undetermined - visible */ - } else { + } + else { label = 0; /* Left undetermined - visible */ } @@ -6758,7 +6915,8 @@ int GCAtransformAndWriteSamples( return (NO_ERROR); } -static int mriFillRegion(MRI *mri, int x, int y, int z, int frame, float fill_val, int whalf) { +static int mriFillRegion(MRI *mri, int x, int y, int z, int frame, float fill_val, int whalf) +{ int xi, xk, yi, yk, zi, zk; for (xk = -whalf; xk <= whalf; xk++) { @@ -6774,7 +6932,8 @@ static int mriFillRegion(MRI *mri, int x, int y, int z, int frame, float fill_va return (NO_ERROR); } -static int gcaFindIntensityBounds(GCA *gca, float *pmin, float *pmax) { +static int gcaFindIntensityBounds(GCA *gca, float *pmin, float *pmax) +{ int width, depth, height, x, y, z, n, label, r; GCA_NODE *gcan; GC1D *gc; @@ -6832,7 +6991,8 @@ static int gcaFindIntensityBounds(GCA *gca, float *pmin, float *pmax) { } return (NO_ERROR); } -static int gcaFindMaxPriors(GCA *gca, float *max_priors) { +static int gcaFindMaxPriors(GCA *gca, float *max_priors) +{ int width, depth, height, x, y, z, n, label; GCA_PRIOR *gcap; @@ -6879,7 +7039,8 @@ static int bad_i = 0 ; #endif // segmented volume here -static int GCAupdateNodeGibbsPriors(GCA *gca, MRI *mri, int xn, int yn, int zn, int xl, int yl, int zl, int label) { +static int GCAupdateNodeGibbsPriors(GCA *gca, MRI *mri, int xn, int yn, int zn, int xl, int yl, int zl, int label) +{ int n, i, xnbr, ynbr, znbr, nbr_label; GCA_NODE *gcan; GC1D *gc; @@ -6972,7 +7133,8 @@ static int GCAupdateNodeGibbsPriors(GCA *gca, MRI *mri, int xn, int yn, int zn, zn, MAX_NBR_LABELS); continue; - } else { + } + else { gc->labels[i][gc->nlabels[i]++] = nbr_label; } #endif @@ -7273,7 +7435,8 @@ GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, } #endif -MRI *GCAanneal(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, int max_iter, double prior_factor) { +MRI *GCAanneal(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, int max_iter, double prior_factor) +{ int x, y, z, width, height, depth, label, val, iter, xn, yn, zn, n, nchanged, index, nindices, old_label; short *x_indices, *y_indices, *z_indices; GCA_NODE *gcan; @@ -7347,7 +7510,8 @@ MRI *GCAanneal(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, in mri_probs = GCAlabelProbabilities(mri_inputs, gca, mri_dst, transform); MRIorderIndices(mri_probs, x_indices, y_indices, z_indices); MRIfree(&mri_probs); - } else + } + else MRIcomputeVoxelPermutation(mri_inputs, x_indices, y_indices, z_indices); nchanged = 0; @@ -7392,7 +7556,8 @@ MRI *GCAanneal(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, in if (label != old_label) { nchanged++; MRIsetVoxVal(mri_changed, x, y, z, 0, 1); - } else { + } + else { MRIsetVoxVal(mri_changed, x, y, z, 0, 0); } MRIsetVoxVal(mri_dst, x, y, z, 0, label); @@ -7405,7 +7570,8 @@ MRI *GCAanneal(MRI *mri_inputs, GCA *gca, MRI *mri_dst, TRANSFORM *transform, in printf("pass %d: %d changed. image ll: %2.3f (CMA=%2.3f)\n", iter + 1, nchanged, ll, lcma); else printf("pass %d: %d changed. image ll: %2.3f\n", iter + 1, nchanged, ll); - } else { + } + else { printf("pass %d: %d changed.\n", iter + 1, nchanged); } MRIdilate(mri_changed, mri_changed); @@ -7436,7 +7602,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, int restart, void (*update_func)(MRI *), double min_prior_factor, - double max_prior_factor) { + double max_prior_factor) +{ int x, y, z, width, height, depth, iter, nchanged, min_changed, index, nindices, fixed; short *x_indices, *y_indices, *z_indices; double prior_factor, old_posterior, lcma = 0.0; @@ -7506,7 +7673,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, if (MRIgetVoxVal(mri_fixed, x, y, z, 0)) { MRIsetVoxVal(mri_changed, x, y, z, 0, 1); } - } else + } + else // everything is marked { MRIsetVoxVal(mri_changed, x, y, z, 0, 1); @@ -7522,7 +7690,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, old_posterior = GCAgibbsImageLogPosterior(gca, mri_dst, mri_inputs, transform, prior_factor); // get the per voxel value old_posterior /= (double)(width * depth * height); - } else { + } + else { old_posterior = 0; } @@ -7566,7 +7735,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, } nindices = index; mri_probs = NULL; - } else if (iter == 0) { + } + else if (iter == 0) { /* char fname[STRLEN], *cp ;*/ /* int nfixed ;*/ @@ -7581,7 +7751,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, // sorted according to ascending order of probs MRIorderIndices(mri_probs, x_indices, y_indices, z_indices); MRIfree(&mri_probs); - } else + } + else // randomize the indices value ((0 -> width*height*depth) MRIcomputeVoxelPermutation(mri_inputs, x_indices, y_indices, z_indices); @@ -7690,7 +7861,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, nchanged++; // mark it as changed MRIsetVoxVal(mri_changed, x, y, z, 0, 1); - } else { + } + else { MRIsetVoxVal(mri_changed, x, y, z, 0, 0); } // assign new label @@ -7796,7 +7968,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, prior_factor); else // currently this is executed printf("pass %d: %d changed. image ll: %2.3f, PF=%2.3f\n", iter + 1, nchanged, ll, prior_factor); - } else { + } + else { printf("pass %d: %d changed.\n", iter + 1, nchanged); } @@ -7854,7 +8027,8 @@ MRI *GCAreclassifyUsingGibbsPriors(MRI *mri_inputs, MRIclear(mri_fixed); } fixed = 0; - } else { + } + else { prior_factor *= 2; if (prior_factor < max_prior_factor) fprintf(stdout, "setting PRIOR_FACTOR to %2.4f\n", prior_factor); } @@ -7970,8 +8144,8 @@ gcaGibbsSort(GCA *gca, MRI *mri_labels, MRI *mri_inputs, } #endif -double GCAgibbsImageLogPosterior( - GCA *gca, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform, double prior_factor) { +double GCAgibbsImageLogPosterior(GCA *gca, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform, double prior_factor) +{ int x, width, depth, height; double total_log_posterior; @@ -8001,7 +8175,8 @@ double GCAgibbsImageLogPosterior( } return (total_log_posterior); } -static double gcaGibbsImpossibleConfiguration(GCA *gca, MRI *mri_labels, int x, int y, int z, TRANSFORM *transform) { +static double gcaGibbsImpossibleConfiguration(GCA *gca, MRI *mri_labels, int x, int y, int z, TRANSFORM *transform) +{ int xn, yn, zn, xnbr, ynbr, znbr, nbr_label, label, i, j, n; GCA_NODE *gcan; GC1D *gc; @@ -8037,7 +8212,8 @@ static double gcaGibbsImpossibleConfiguration(GCA *gca, MRI *mri_labels, int x, if (FZERO(gc->label_priors[i][j])) { return (1); /* never occurred (and this never should) */ } - } else /* never occurred - make it unlikely */ + } + else /* never occurred - make it unlikely */ { if (x == Ggca_x && y == Ggca_y && z == Ggca_z) { DiagBreak(); @@ -8052,7 +8228,8 @@ static double gcaGibbsImpossibleConfiguration(GCA *gca, MRI *mri_labels, int x, } double GCAnbhdGibbsLogPosterior( - GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, int y, int z, TRANSFORM *transform, double gibbs_coef) { + GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, int y, int z, TRANSFORM *transform, double gibbs_coef) +{ double total_log_posterior /*, log_posterior*/; /* int i, xnbr, ynbr, znbr ;*/ @@ -8079,7 +8256,8 @@ double GCAnbhdGibbsLogPosterior( } double GCAwindowPosteriorLogProbability( - GCA *gca, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform, int x, int y, int z, int whalf) { + GCA *gca, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform, int x, int y, int z, int whalf) +{ int xi, yi, zi, xk, yk, zk, nvox; double total_posterior, posterior; @@ -8101,7 +8279,8 @@ double GCAwindowPosteriorLogProbability( } double GCAvoxelGibbsLogPosterior( - GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, int y, int z, TRANSFORM *transform, double gibbs_coef) { + GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, int y, int z, TRANSFORM *transform, double gibbs_coef) +{ double log_posterior /*, dist*/, nbr_prior; int xn, yn, zn, xnbr, ynbr, znbr, nbr_label, label, i, j, n; GCA_NODE *gcan = 0; @@ -8130,7 +8309,8 @@ double GCAvoxelGibbsLogPosterior( // unknown label out of the fov { return (0.0); - } else { + } + else { return (10 * BIG_AND_NEGATIVE); } } @@ -8162,7 +8342,8 @@ double GCAvoxelGibbsLogPosterior( // could not find the label, then if (n >= gcan->nlabels) { gc = GCAfindClosestValidGC(gca, xn, yn, zn, label, 0); - } else { + } + else { gc = &gcan->gcs[n]; } if (gc == NULL) { @@ -8183,7 +8364,8 @@ double GCAvoxelGibbsLogPosterior( nbr_prior = 0.0; if (gc->nlabels == NULL) { nbr_prior += log(0.1f / (float)gcan->total_training); - } else { + } + else { for (i = 0; i < GIBBS_NEIGHBORS; i++) { xnbr = mri_labels->xi[x + xnbr_offset[i]]; ynbr = mri_labels->yi[y + ynbr_offset[i]]; @@ -8197,12 +8379,14 @@ double GCAvoxelGibbsLogPosterior( if (j < gc->nlabels[i]) { if (!FZERO(gc->label_priors[i][j])) { nbr_prior += log(gc->label_priors[i][j]); - } else { + } + else { nbr_prior += log(0.1f / (float)gcan->total_training); } /*BIG_AND_NEGATIVE */ check_finite("GCAvoxelGibbsLogPosterior: label_priors", nbr_prior); - } else /* never occurred - make it unlikely */ + } + else /* never occurred - make it unlikely */ { if (x == Ggca_x && y == Ggca_y && z == Ggca_z) { DiagBreak(); @@ -8222,7 +8406,8 @@ double GCAvoxelGibbsLogPosterior( if (check_finite("GCAvoxelGibbsLogPosterior: final", log_posterior) == 0) { DiagBreak(); } - } else { + } + else { return (10 * BIG_AND_NEGATIVE); // return (log(VERY_UNLIKELY)) ; } @@ -8241,7 +8426,8 @@ double GCAvoxelGibbsLogPosterior( return (log_posterior); } // the posterior of an image given a segmentation without any MRF -double GCAimagePosteriorLogProbability(GCA *gca, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform) { +double GCAimagePosteriorLogProbability(GCA *gca, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform) +{ double log_posterior; int x, y, z, num = 0; @@ -8264,7 +8450,8 @@ double GCAimagePosteriorLogProbability(GCA *gca, MRI *mri_labels, MRI *mri_input return (log_posterior / (float)num); } -double GCAvoxelLogPosterior(GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, int y, int z, TRANSFORM *transform) { +double GCAvoxelLogPosterior(GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, int y, int z, TRANSFORM *transform) +{ double log_posterior /*, dist*/; int xn, yn, zn, label, n; GCA_NODE *gcan = 0; @@ -8290,7 +8477,8 @@ double GCAvoxelLogPosterior(GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, i if (label == Unknown) // okay for there to be an { return (0.0); // unknown label out of the fov - } else { + } + else { return (10 * BIG_AND_NEGATIVE); } } @@ -8347,7 +8535,8 @@ double GCAvoxelLogPosterior(GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, i if (check_finite("GCAvoxelGibbsLogPosterior: final", log_posterior) == 0) { DiagBreak(); } - } else { + } + else { return (10 * BIG_AND_NEGATIVE); // return (log(VERY_UNLIKELY)) ; } @@ -8355,7 +8544,8 @@ double GCAvoxelLogPosterior(GCA *gca, MRI *mri_labels, MRI *mri_inputs, int x, i return (log_posterior); } -MRI *GCAbuildMostLikelyVolume(GCA *gca, MRI *mri) { +MRI *GCAbuildMostLikelyVolume(GCA *gca, MRI *mri) +{ int x, y, z, xn, yn, zn, width, depth, height, n, xp, yp, zp, r; const GCA_NODE *gcan; const GCA_PRIOR *gcap; @@ -8424,12 +8614,14 @@ MRI *GCAbuildMostLikelyVolume(GCA *gca, MRI *mri) { for (r = 0; r < gca->ninputs; r++) { MRIsetVoxVal(mri, x, y, z, r, gc_max->means[r]); } - } else { + } + else { for (r = 0; r < gca->ninputs; r++) { MRIsetVoxVal(mri, x, y, z, r, 0); } } - } else { + } + else { for (r = 0; r < gca->ninputs; r++) { MRIsetVoxVal(mri, x, y, z, r, 0); } @@ -8441,7 +8633,8 @@ MRI *GCAbuildMostLikelyVolume(GCA *gca, MRI *mri) { return (mri); } -MRI *GCAbuildMostLikelyVolumeFrame(GCA *gca, MRI *mri, int frame) { +MRI *GCAbuildMostLikelyVolumeFrame(GCA *gca, MRI *mri, int frame) +{ int x, y, z, xn, yn, zn, width, depth, height, n, xp, yp, zp; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -8505,18 +8698,21 @@ MRI *GCAbuildMostLikelyVolumeFrame(GCA *gca, MRI *mri, int frame) { return (mri); } -GC1D *GCAfindPriorGC(const GCA *gca, int xp, int yp, int zp, int label) { +GC1D *GCAfindPriorGC(const GCA *gca, int xp, int yp, int zp, int label) +{ int xn, yn, zn; if (!GCApriorToNode(gca, xp, yp, zp, &xn, &yn, &zn)) { return (GCAfindGC(gca, xn, yn, zn, label)); - } else { + } + else { return NULL; } } #if 1 -GC1D *GCAfindGC(const GCA *gca, int xn, int yn, int zn, int label) { +GC1D *GCAfindGC(const GCA *gca, int xn, int yn, int zn, int label) +{ int n; GCA_NODE *gcan; @@ -8609,7 +8805,8 @@ MRI *GCAconstrainLabelTopology(GCA *gca, MRIsegmentFree(&mriseg); nex = NCHOROID; ex = choroid_labels; - } else { + } + else { mri_in_main_segment = NULL; nex = 0; ex = NULL; @@ -8689,7 +8886,8 @@ static int gcaReclassifySegment(GCA *gca, int old_label, TRANSFORM *transform, int *exclude_list, - int nexcluded) { + int nexcluded) +{ int i; for (i = 0; i < mseg->nvoxels; i++) { @@ -8725,7 +8923,8 @@ static int gcaReclassifyVoxel(GCA *gca, int old_label, TRANSFORM *transform, int *exclude_list, - int nexcluded) { + int nexcluded) +{ int nbr_labels[MAX_CMA_LABELS], xi, yi, zi, xk, yk, zk, i, new_label, ex, skip; double max_p, p; @@ -8802,7 +9001,8 @@ static int gcaReclassifyVoxel(GCA *gca, #define V_WHALF (V_WSIZE - 1) / 2 #define V_THRESH ((V_WSIZE * V_WSIZE / 2)) #if 1 -MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, int target_label) { +MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, int target_label) +{ int nchanged, x, y, z, width, height, depth, xn, yn, zn, xk, yk, zk, xi, yi, zi, label, total_changed, i, j, count, found, xmin, xmax, ymin, ymax, zmin, zmax; GCA_NODE *gcan; @@ -8927,7 +9127,8 @@ MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, T gc = GCAfindGC(gca, xn, yn, zn, label); if (gc == NULL) { dist_label = 10000; // ??? - } else { + } + else { dist_label = GCAmahDistIdentityCovariance(gc, vals, gca->ninputs); } gc = GCAfindGC(gca, xn, yn, zn, target_label); @@ -8988,7 +9189,8 @@ MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, T return (mri_dst); } #else -MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, int target_label) { +MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, int target_label) +{ int nchanged, x, y, z, width, height, depth, xn, yn, zn, xi, yi, zi, xk, yk, zk, label, total_changed, i; GCA_NODE *gcan; GC1D *gc, *gc_vent; @@ -9056,7 +9258,8 @@ MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, T gc = GCAfindGC(gca, xn, yn, zn, label); if (gc == NULL) { plabel = 0.0; - } else + } + else plabel = GCAcomputeConditionalDensity(gc, vals, gca->ninputs, label); gc = GCAfindGC(gca, xn, yn, zn, target_label); if (gc == NULL) @@ -9116,7 +9319,8 @@ MRI *GCAexpandVentricle(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, T } #endif #define MAX_CORTICAL_ITERATIONS 10 -MRI *GCAexpandCortex(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform) { +MRI *GCAexpandCortex(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform) +{ int nchanged, x, y, z, width, height, depth, xn, yn, zn, xi, yi, zi, xk, yk, zk, label, total_changed, i, wm_nbr, gray_nbr, left; GCA_NODE *gcan; @@ -9176,7 +9380,8 @@ MRI *GCAexpandCortex(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRAN label = nint(MRIgetVoxVal(mri_dst, xi, yi, zi, 0)); if (label == Left_Cerebral_Cortex || label == Left_Cerebral_White_Matter) { left = 1; - } else if (label == Right_Cerebral_Cortex || label == Right_Cerebral_White_Matter) { + } + else if (label == Right_Cerebral_Cortex || label == Right_Cerebral_White_Matter) { left = 0; } } @@ -9209,8 +9414,9 @@ MRI *GCAexpandCortex(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRAN gray_nbr = 0; } /* shouldn't ever happen */ - } else if ((label == Left_Cerebral_White_Matter || label == Right_Cerebral_White_Matter) && - (gc_wm == NULL)) { + } + else if ((label == Left_Cerebral_White_Matter || label == Right_Cerebral_White_Matter) && + (gc_wm == NULL)) { wm_nbr = label; gc_wm = GCAfindSourceGC(gca, mri_src, transform, xi, yi, zi, label); if (!gc_wm) { @@ -9280,7 +9486,8 @@ MRI *GCAexpandCortex(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRAN nchanged++; MRIsetVoxVal(mri_tmp, x, y, z, 0, wm_nbr); } - } else if (gc_gm) /* might change to gm */ + } + else if (gc_gm) /* might change to gm */ { if (gdist < ldist && GCAisPossible(gca, mri_inputs, gray_nbr, transform, x, y, z, 0)) { int olabel = nint(MRIgetVoxVal(mri_tmp, x, y, z, 0)); @@ -9327,7 +9534,8 @@ MRI *GCAexpandCortex(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRAN } MRI *GCAexpandLabelIntoWM( - GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, MRI *mri_fixed, int target_label) { + GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, MRI *mri_fixed, int target_label) +{ int nchanged, x, y, z, width, height, depth, xn, yn, zn, xi, yi, zi, xk, yk, zk, nbr_label, n, label, total_changed, i; GCA_NODE *gcan, *gcan_nbr; @@ -9473,7 +9681,8 @@ MRI *GCAexpandLabelIntoWM( return (mri_dst); } -int GCArankSamples(GCA *gca, GCA_SAMPLE *gcas, int nsamples, int *ordered_indices) { +int GCArankSamples(GCA *gca, GCA_SAMPLE *gcas, int nsamples, int *ordered_indices) +{ LABEL_PROB *label_probs; int i; @@ -9496,7 +9705,8 @@ int GCArankSamples(GCA *gca, GCA_SAMPLE *gcas, int nsamples, int *ordered_indice #include "mrinorm.h" MRI *GCAnormalizeSamples( - MRI *mri_in, GCA *gca, GCA_SAMPLE *gcas, int nsamples, TRANSFORM *transform, const char *ctl_point_fname) { + MRI *mri_in, GCA *gca, GCA_SAMPLE *gcas, int nsamples, TRANSFORM *transform, const char *ctl_point_fname) +{ MRI *mri_dst, *mri_ctrl, *mri_bias; int xv, yv, zv, n, x, y, z, width, height, depth, xn, yn, zn, num, total, input, T1_index = 0; float bias; @@ -9582,7 +9792,8 @@ MRI *GCAnormalizeSamples( MRIsampleVolumeFrame(mri_in, x, y, z, T1_index, &val); bias = NO_BIAS * DEFAULT_DESIRED_WHITE_MATTER_VALUE / val; MRISvox(mri_bias, x, y, z) = (short)nint(bias); - } else /* find atlas point this maps to */ + } + else /* find atlas point this maps to */ { int n, max_n; GC1D *gc; @@ -9684,7 +9895,8 @@ MRI *GCAnormalizeSamples( #endif MRISvox(mri_bias, xv, yv, zv) = (short)nint(bias); - } else { + } + else { MRIvox(mri_ctrl, xv, yv, zv) = CONTROL_NONE; } } @@ -9780,7 +9992,8 @@ MRI *GCAnormalizeSamples( case MRI_UCHAR: if (val < 0) { val = 0; - } else if (val > 255) { + } + else if (val > 255) { val = 255; } MRIseq_vox(mri_dst, x, y, z, input) = (BUFTYPE)nint(val); @@ -9848,7 +10061,8 @@ void GCAnormalizeSamplesOneChannel(MRI *mri_in, if (ctl_point_fname) { MRI3dUseFileControlPoints(mri_ctrl, ctl_point_fname); nctrl = MRInormAddFileControlPoints(mri_ctrl, CONTROL_MARKED, NULL); - } else { + } + else { nctrl = 0; } @@ -9867,7 +10081,8 @@ void GCAnormalizeSamplesOneChannel(MRI *mri_in, MRIsampleVolumeFrame(mri_in, x, y, z, input_index, &val); bias = NO_BIAS * DEFAULT_DESIRED_WHITE_MATTER_VALUE / val; MRISvox(mri_bias, x, y, z) = (short)nint(bias); - } else /* find atlas point this maps to */ + } + else /* find atlas point this maps to */ { int n, max_n; GC1D *gc; @@ -9967,7 +10182,8 @@ void GCAnormalizeSamplesOneChannel(MRI *mri_in, #endif MRISvox(mri_bias, xv, yv, zv) = (short)nint(bias); - } else { + } + else { MRIvox(mri_ctrl, xv, yv, zv) = CONTROL_NONE; } } @@ -10048,7 +10264,8 @@ void GCAnormalizeSamplesOneChannel(MRI *mri_in, MRIfree(&mri_bias); mri_bias = mri_smooth; MRIfree(&mri_kernel); - } else // if manually specified control points, don't let them be overwhelmed + } + else // if manually specified control points, don't let them be overwhelmed { MRI *mri_kernel, *mri_smooth; mri_smooth = MRIsoapBubble(mri_bias, mri_ctrl, NULL, 10, -1); @@ -10099,7 +10316,8 @@ MRI *GCAnormalizeSamplesAllChannels(MRI *mri_in, int nsamples, TRANSFORM *transform, char *ctl_point_fname, - double bias_sigma) { + double bias_sigma) +{ MRI *mri_dst; int input; @@ -10113,7 +10331,8 @@ MRI *GCAnormalizeSamplesAllChannels(MRI *mri_in, MRIcopyFrame(mri_frame, mri_dst, 0, input); MRIfree(&mri_frame); } - } else { + } + else { for (input = 0; input < gca->ninputs; input++) { GCAnormalizeSamplesOneChannel(mri_dst, gca, gcas, nsamples, transform, ctl_point_fname, input, bias_sigma); } @@ -10123,7 +10342,8 @@ MRI *GCAnormalizeSamplesAllChannels(MRI *mri_in, } MRI *GCAnormalizeSamplesT1PD( - MRI *mri_in, GCA *gca, GCA_SAMPLE *gcas, int nsamples, TRANSFORM *transform, char *ctl_point_fname) { + MRI *mri_in, GCA *gca, GCA_SAMPLE *gcas, int nsamples, TRANSFORM *transform, char *ctl_point_fname) +{ MRI *mri_dst, *mri_ctrl, *mri_bias; int xv, yv, zv, n, x, y, z, width, height, depth, out_val, xn, yn, zn, num, total; double val; @@ -10257,7 +10477,8 @@ MRI *GCAnormalizeSamplesT1PD( #endif MRISvox(mri_bias, xv, yv, zv) = (short)nint(bias); - } else { + } + else { MRIvox(mri_ctrl, xv, yv, zv) = CONTROL_NONE; } } @@ -10349,7 +10570,8 @@ MRI *GCAnormalizeSamplesT1PD( return (mri_dst); } -float GCAlabelProbability(MRI *mri_src, GCA *gca, TRANSFORM *transform, float x, float y, float z, int label) { +float GCAlabelProbability(MRI *mri_src, GCA *gca, TRANSFORM *transform, float x, float y, float z, int label) +{ int xn, yn, zn; GCA_NODE *gcan; GC1D *gc; @@ -10370,16 +10592,19 @@ float GCAlabelProbability(MRI *mri_src, GCA *gca, TRANSFORM *transform, float x, if (gc == NULL) { plabel = 0.0; - } else { + } + else { plabel = GCAcomputeConditionalDensity(gc, vals, gca->ninputs, label); } - } else { + } + else { plabel = 0.0; } return (plabel); } -static GCA_NODE *findSourceGCAN(GCA *gca, MRI *mri_src, TRANSFORM *transform, int x, int y, int z) { +static GCA_NODE *findSourceGCAN(GCA *gca, MRI *mri_src, TRANSFORM *transform, int x, int y, int z) +{ int xn, yn, zn; GCA_NODE *gcan = NULL; @@ -10419,7 +10644,8 @@ getLabelMean(GCA_NODE *gcan, int label, float *pvar, float *means, int ninputs) } #endif MRI *GCAmaxPosteriorBorders( - GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, int max_iter, float min_ratio) { + GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform, int max_iter, float min_ratio) +{ int nchanged, x, y, z, width, height, depth, label, total_changed, i; MRI *mri_tmp; @@ -10485,7 +10711,8 @@ MRI *GCAmaxPosteriorBorders( printf("%d border labels changed to MLE ...\n", total_changed); return (mri_dst); } -static int borderVoxel(MRI *mri, int x, int y, int z) { +static int borderVoxel(MRI *mri, int x, int y, int z) +{ int xi, yi, zi, xk, yk, zk, label; label = nint(MRIgetVoxVal(mri, x, y, z, 0)); @@ -10509,7 +10736,8 @@ static int borderVoxel(MRI *mri, int x, int y, int z) { } static int GCAmaxLikelihoodBorderLabel( - GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform, int x, int y, int z, float min_ratio) { + GCA *gca, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform, int x, int y, int z, float min_ratio) +{ float p, max_p, vals[MAX_GCA_INPUTS]; int label, i, xi, yi, zi, best_label, orig_label, n; GCA_NODE *gcan; @@ -10546,7 +10774,8 @@ static int GCAmaxLikelihoodBorderLabel( z, best_label); max_p = 0.0; - } else { + } + else { max_p = GCAcomputeConditionalDensity(gc, vals, gca->ninputs, best_label); } @@ -10608,7 +10837,8 @@ static int GCAmaxLikelihoodBorderLabel( return (best_label); } -int GCAcomputeLabelStats(GCA *gca, int target_label, float *pvar, float *means) { +int GCAcomputeLabelStats(GCA *gca, int target_label, float *pvar, float *means) +{ int x, y, z, n, r; double var, dof, total_dof; GC1D *gc; @@ -10652,7 +10882,8 @@ int GCAcomputeLabelStats(GCA *gca, int target_label, float *pvar, float *means) return (NO_ERROR); } int GCAhistogramTissueStatistics( - GCA *gca, MRI *mri_T1, MRI *mri_PD, MRI *mri_labeled, TRANSFORM *transform, const char *fname) { + GCA *gca, MRI *mri_T1, MRI *mri_PD, MRI *mri_labeled, TRANSFORM *transform, const char *fname) +{ int x, y, z, n, label, biggest_label, T1, PD, xp, yp, zp; GCA_NODE *gcan; GCA_TISSUE_PARMS *gca_tp; @@ -10728,7 +10959,8 @@ int GCAhistogramTissueStatistics( (zp < 0 || zp >= mri_T1->depth)) { continue; } - } else { + } + else { xp = x; yp = y; zp = z; @@ -10751,7 +10983,8 @@ int GCAhistogramTissueStatistics( return (NO_ERROR); } -int GCAnormalizeTissueStatistics(GCA *gca) { +int GCAnormalizeTissueStatistics(GCA *gca) +{ int n; double nsamples; GCA_TISSUE_PARMS *gca_tp; @@ -10778,7 +11011,8 @@ int GCAnormalizeTissueStatistics(GCA *gca) { return (NO_ERROR); } -char *cma_label_to_name(int label) { +char *cma_label_to_name(int label) +{ static char name[STRLEN]; if (label == Unknown) { @@ -11536,7 +11770,8 @@ char *cma_label_to_name(int label) { return (name); } -MRI *GCArelabel_cortical_gray_and_white(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform) { +MRI *GCArelabel_cortical_gray_and_white(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform) +{ int nchanged, x, y, z, width, height, depth, total_changed, label, xn, yn, zn, left, new_wm, new_gray; MRI *mri_tmp; GCA_NODE *gcan; @@ -11607,11 +11842,13 @@ MRI *GCArelabel_cortical_gray_and_white(GCA *gca, MRI *mri_inputs, MRI *mri_src, if (left) { grayPrior = getPrior(gcap, Left_Cerebral_Cortex); wmPrior = getPrior(gcap, Left_Cerebral_White_Matter); - } else { + } + else { grayPrior = getPrior(gcap, Right_Cerebral_Cortex); wmPrior = getPrior(gcap, Right_Cerebral_White_Matter); } - } else { + } + else { grayPrior = -1; wmPrior = -1; } @@ -11630,7 +11867,8 @@ MRI *GCArelabel_cortical_gray_and_white(GCA *gca, MRI *mri_inputs, MRI *mri_src, //"< wm_dist (%.2f), // but grayPrior(%.2f) < wmPrior(%.2f)\n", // x, y, z, gray_dist, wm_dist, grayPrior, wmPrior); - } else { + } + else { // if prior is not high, // then you can change gray->white if (grayPrior < 0.9 && grayPrior > 0 && wmPrior > 0) @@ -11675,7 +11913,8 @@ MRI *GCArelabel_cortical_gray_and_white(GCA *gca, MRI *mri_inputs, MRI *mri_src, // count changed label if (label == Left_Cerebral_Cortex || label == Right_Cerebral_Cortex) { new_gray++; - } else { + } + else { new_wm++; } nchanged++; @@ -11699,7 +11938,8 @@ MRI *GCArelabel_cortical_gray_and_white(GCA *gca, MRI *mri_inputs, MRI *mri_src, 100.0f * (float)new_wm / total_changed); return (mri_dst); } -int GCAdump(GCA *gca, MRI *mri, int x, int y, int z, TRANSFORM *transform, FILE *fp, int verbose) { +int GCAdump(GCA *gca, MRI *mri, int x, int y, int z, TRANSFORM *transform, FILE *fp, int verbose) +{ int xn, yn, zn, xp, yp, zp; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -11724,10 +11964,12 @@ int GCAdump(GCA *gca, MRI *mri, int x, int y, int z, TRANSFORM *transform, FILE printf("\nGCAdump: prior point is outside.\n"); } dump_gcan(gca, gcan, fp, verbose, gcap); - } else { + } + else { printf("\nGCAdump: prior point is outside.\n"); } - } else { + } + else { printf("\nGCAdump: node point is outside.\n"); } return (NO_ERROR); @@ -11853,7 +12095,8 @@ static GCA_SAMPLE *gcaExtractThresholdedRegionLabelAsSamples(GCA *gca, int yp, int zp, int wsize, - float pthresh) { + float pthresh) +{ int i, width, height, depth, x, y, z, xi, yi, zi, xk, yk, zk, whalf, r, c, v; int nsamples = 0; GCA_SAMPLE *gcas; @@ -11915,7 +12158,8 @@ static GCA_SAMPLE *gcaExtractThresholdedRegionLabelAsSamples(GCA *gca, gc = GCAfindPriorGC(gca, xp, yp, zp, label); if (gcap) { prior = getPrior(gcap, label); - } else { + } + else { prior = 0; } if (!gc || !gcap || prior < pthresh) { @@ -11958,8 +12202,8 @@ static GCA_SAMPLE *gcaExtractThresholdedRegionLabelAsSamples(GCA *gca, return (gcas); } -static GCA_SAMPLE *gcaExtractLabelAsSamples( - GCA *gca, MRI *mri_labeled, TRANSFORM *transform, int *pnsamples, int label) { +static GCA_SAMPLE *gcaExtractLabelAsSamples(GCA *gca, MRI *mri_labeled, TRANSFORM *transform, int *pnsamples, int label) +{ int i, nsamples, width, height, depth, x, y, z, xp, yp, zp, n, r, c, v; GCA_SAMPLE *gcas; GCA_PRIOR *gcap; @@ -12037,7 +12281,8 @@ static GCA_SAMPLE *gcaExtractLabelAsSamples( #define MIN_MEAN_SAMPLES 10 #define SAMPLE_PCT 0.20 -int GCArenormalize(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform) { +int GCArenormalize(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform) +{ int x, y, z, n, label, biggest_label, nsamples, val, *ordered_indices, i, index, width, height, depth; float mean, var, *means, *stds, *gca_means; GCA_NODE *gcan; @@ -12107,7 +12352,8 @@ int GCArenormalize(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform gca_means[label], nsamples, stds[label]); - } else { + } + else { gca_means[label] = stds[label] = means[label] = 1.0; } @@ -12131,7 +12377,8 @@ int GCArenormalize(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform if (nint(nsamples * SAMPLE_PCT) < MIN_MEAN_SAMPLES) { nsamples = MIN_MEAN_SAMPLES; - } else { + } + else { nsamples = nint(SAMPLE_PCT * (float)nsamples); } @@ -12190,7 +12437,8 @@ int GCArenormalize(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform free(gca_means); return (NO_ERROR); } -int GCArenormalizeAdaptive(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform, int wsize, float pthresh) { +int GCArenormalizeAdaptive(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform, int wsize, float pthresh) +{ int x, y, z, n, label, xp, yp, zp, peak, orig_wsize, frame; #if 0 int i, index, *ordered_indices ; @@ -12326,7 +12574,8 @@ int GCArenormalizeAdaptive(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *t #define MEAN_RESOLUTION 8 -int GCArenormalizeLabels(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform) { +int GCArenormalizeLabels(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *transform) +{ int x, y, z, n, label, biggest_label, nsamples, xv, yv, zv, *ordered_indices, i, index, width, height, depth; float mean, var, val; GCA_NODE *gcan; @@ -12366,7 +12615,8 @@ int GCArenormalizeLabels(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *tra if (nint(nsamples * SAMPLE_PCT) < MIN_SAMPLES) { nsamples = MIN_SAMPLES; - } else { + } + else { nsamples = nint(SAMPLE_PCT * (float)nsamples); } @@ -12434,7 +12684,8 @@ int GCArenormalizeLabels(MRI *mri_in, MRI *mri_labeled, GCA *gca, TRANSFORM *tra } if (MRISvox(mri_control, x, y, z) == 0) { MRIFvox(mri_means, x, y, z) = val; - } else { + } + else { MRIFvox(mri_means, x, y, z) += val; } MRISvox(mri_control, x, y, z)++; @@ -12650,7 +12901,8 @@ GCArenormalizeIntensities(GCA *gca, int *labels, float *intensities, int num) labels and intensities have pairs of modes to update the gca with. */ -int GCArenormalizeIntensities(GCA *gca, int *labels, float *intensities, int num) { +int GCArenormalizeIntensities(GCA *gca, int *labels, float *intensities, int num) +{ float *scales, mode; int xn, yn, zn, n, i, label; GCA_NODE *gcan; @@ -12704,7 +12956,8 @@ int GCArenormalizeIntensities(GCA *gca, int *labels, float *intensities, int num if (gc->means[0] < 1 && gcan->labels[n] == 0) // too close to 0 to scale { gc->means[0] = intensities[i] / 3; - } else + } + else gc->means[0] = scales[i] * gc->means[0]; } } @@ -12715,7 +12968,8 @@ int GCArenormalizeIntensities(GCA *gca, int *labels, float *intensities, int num return (NO_ERROR); } #endif -int GCAunifyVariance(GCA *gca) { +int GCAunifyVariance(GCA *gca) +{ int xn, yn, zn, n, r, c, v; GCA_NODE *gcan; GC1D *gc; @@ -12730,7 +12984,8 @@ int GCAunifyVariance(GCA *gca) { for (c = r; c < gca->ninputs; c++, v++) { if (r == c) { gc->covars[v] = MIN_VAR; - } else { + } + else { gc->covars[v] = 0.0; } } @@ -12743,7 +12998,8 @@ int GCAunifyVariance(GCA *gca) { return (NO_ERROR); } -int GCAlabelMode(GCA *gca, int label, float *modes) { +int GCAlabelMode(GCA *gca, int label, float *modes) +{ int xn, yn, zn, n, r; GCA_NODE *gcan; GC1D *gc; @@ -12793,7 +13049,8 @@ int GCAlabelMode(GCA *gca, int label, float *modes) { } return (NO_ERROR); } -int GCAclassMode(GCA *gca, int class, float *modes) { +int GCAclassMode(GCA *gca, int class, float *modes) +{ int xn, yn, zn, n, r; GCA_NODE *gcan; GC1D *gc; @@ -12865,7 +13122,8 @@ int GCAclassMode(GCA *gca, int class, float *modes) { return (NO_ERROR); } -int GCAlabelMean(GCA *gca, int label, float *means) { +int GCAlabelMean(GCA *gca, int label, float *means) +{ int xn, yn, zn, n, r; GCA_NODE *gcan; GC1D *gc; @@ -12906,7 +13164,8 @@ int GCAlabelMean(GCA *gca, int label, float *means) { } return (NO_ERROR); } -int GCAlabelVar(GCA *gca, int label, float *vars) { +int GCAlabelVar(GCA *gca, int label, float *vars) +{ int xn, yn, zn, n, c, r, v; GCA_NODE *gcan; GC1D *gc; @@ -12948,7 +13207,8 @@ int GCAlabelVar(GCA *gca, int label, float *vars) { } return (NO_ERROR); } -int GCAclassMean(GCA *gca, int class, float *means) { +int GCAclassMean(GCA *gca, int class, float *means) +{ int xn, yn, zn, n, r, label; GCA_NODE *gcan; GC1D *gc; @@ -13009,7 +13269,8 @@ int GCAclassMean(GCA *gca, int class, float *means) { return (NO_ERROR); } -int GCAregularizeConditionalDensities(GCA *gca, float smooth) { +int GCAregularizeConditionalDensities(GCA *gca, float smooth) +{ int xn, yn, zn, n, i, label, max_label, r; GCA_NODE *gcan; GC1D *gc; @@ -13084,7 +13345,8 @@ int GCAregularizeConditionalDensities(GCA *gca, float smooth) { free(means); return (NO_ERROR); } -int GCArenormalizeToFlash(GCA *gca, char *tissue_parms_fname, MRI *mri) { +int GCArenormalizeToFlash(GCA *gca, char *tissue_parms_fname, MRI *mri) +{ FILE *fp; char *cp, line[STRLEN]; int labels[MAX_GCA_LABELS], nlabels; @@ -13120,7 +13382,8 @@ int GCArenormalizeToFlash(GCA *gca, char *tissue_parms_fname, MRI *mri) { return (NO_ERROR); } -int GCAmeanFilterConditionalDensities(GCA *gca, float navgs) { +int GCAmeanFilterConditionalDensities(GCA *gca, float navgs) +{ /* won't work for covariances */ int xn, yn, zn, xn1, yn1, zn1, n, label, max_label, niter, f; GCA_NODE *gcan; @@ -13265,7 +13528,8 @@ int GCAmeanFilterConditionalDensities(GCA *gca, float navgs) { #define OFFSET_SIZE 25 double BOX_SIZE = 60; /* mm */ double HALF_BOX = (60 / 2); -int GCAhistoScaleImageIntensities(GCA *gca, MRI *mri, int noskull) { +int GCAhistoScaleImageIntensities(GCA *gca, MRI *mri, int noskull) +{ float x0, y0, z0, fmin, fmax, min_real_val; int mri_peak, r, max_T1_weighted_image = 0, min_real_bin, peak; float wm_means[MAX_GCA_INPUTS], tmp[MAX_GCA_INPUTS], scales[MAX_GCA_INPUTS], max_wm /*, scale*/; @@ -13360,7 +13624,8 @@ int GCAhistoScaleImageIntensities(GCA *gca, MRI *mri, int noskull) { { min_real_val = 0.25 * fmax; } - } else { + } + else { if (min_real_val > 0.5 * fmax) /* for non skull-stripped images */ { min_real_val = 0.5 * fmax; @@ -13437,7 +13702,8 @@ int GCAhistoScaleImageIntensities(GCA *gca, MRI *mri, int noskull) { HISTOclearBins(h_mri, h_mri, MAX_CONFORMED_WM_VAL + 1, 255); } mri_peak = HISTOfindLastPeak(h_mri, 2 * HISTO_WINDOW_SIZE, MIN_HISTO_PCT); - } else { + } + else { mri_peak = HISTOfindHighestPeakInRegion(h_mri, 1, h_mri->nbins); } if ((h_mri->nbins <= mri_peak) || (mri_peak < 0)) { @@ -13447,7 +13713,8 @@ int GCAhistoScaleImageIntensities(GCA *gca, MRI *mri, int noskull) { h_mri->nbins, mri_peak); mri_peak = 0; - } else { + } + else { mri_peak = h_mri->bins[mri_peak]; } printf("before smoothing, mri peak at %d\n", mri_peak); @@ -13482,7 +13749,8 @@ int GCAhistoScaleImageIntensities(GCA *gca, MRI *mri, int noskull) { h_mri->nbins, mri_peak); mri_peak = 0; - } else { + } + else { mri_peak = h_smooth->bins[mri_peak]; } @@ -13526,7 +13794,8 @@ int GCAhistoScaleImageIntensities(GCA *gca, MRI *mri, int noskull) { /* each input frame is a different time point for the same subject. */ -int GCAhistoScaleImageIntensitiesLongitudinal(GCA *gca, MRI *mri, int noskull) { +int GCAhistoScaleImageIntensitiesLongitudinal(GCA *gca, MRI *mri, int noskull) +{ float x0, y0, z0, fmin, fmax, min_real_val, val; int mri_peak, r, max_T1_weighted_image = 0, min_real_bin, peak, frame; float wm_means[MAX_GCA_INPUTS], tmp[MAX_GCA_INPUTS], scales[MAX_GCA_INPUTS], max_wm /*, scale*/; @@ -13596,7 +13865,8 @@ int GCAhistoScaleImageIntensitiesLongitudinal(GCA *gca, MRI *mri, int noskull) { { val = 0.25 * fmax; } - } else { + } + else { if (val > 0.5 * fmax) /* for non skull-stripped images */ { val = 0.5 * fmax; @@ -13682,7 +13952,8 @@ int GCAhistoScaleImageIntensitiesLongitudinal(GCA *gca, MRI *mri, int noskull) { HISTOclearBins(h_mri, h_mri, MAX_CONFORMED_WM_VAL + 1, 255); } mri_peak = HISTOfindLastPeak(h_mri, 2 * HISTO_WINDOW_SIZE, MIN_HISTO_PCT); - } else { + } + else { mri_peak = HISTOfindHighestPeakInRegion(h_mri, 1, h_mri->nbins); } if ((h_mri->nbins <= mri_peak) || (mri_peak < 0)) { @@ -13692,7 +13963,8 @@ int GCAhistoScaleImageIntensitiesLongitudinal(GCA *gca, MRI *mri, int noskull) { h_mri->nbins, mri_peak); mri_peak = 0; - } else { + } + else { mri_peak = h_mri->bins[mri_peak]; } printf("before smoothing, mri peak at %d\n", mri_peak); @@ -13715,7 +13987,8 @@ int GCAhistoScaleImageIntensitiesLongitudinal(GCA *gca, MRI *mri, int noskull) { h_mri->nbins, mri_peak); mri_peak = 0; - } else { + } + else { mri_peak = h_smooth->bins[mri_peak]; } printf( @@ -13740,7 +14013,8 @@ int GCAhistoScaleImageIntensitiesLongitudinal(GCA *gca, MRI *mri, int noskull) { return (NO_ERROR); } -int GCAhisto(GCA *gca, int nbins, int **pcounts) { +int GCAhisto(GCA *gca, int nbins, int **pcounts) +{ int *counts, x, y, z; GCA_NODE *gcan; @@ -13761,7 +14035,8 @@ int GCAhisto(GCA *gca, int nbins, int **pcounts) { return (NO_ERROR); } -int GCArenormalizeToExample(GCA *gca, MRI *mri_seg, MRI *mri_T1) { +int GCArenormalizeToExample(GCA *gca, MRI *mri_seg, MRI *mri_T1) +{ float intensities[MAX_CMA_LABEL + 1]; int x, y, z, label, labels[MAX_CMA_LABEL + 1], width, height, depth, counts[MAX_CMA_LABEL + 1]; @@ -13806,7 +14081,8 @@ int GCArenormalizeToExample(GCA *gca, MRI *mri_seg, MRI *mri_T1) { HISTOplot(h, "h.plt"); } intensities[label] = h->bins[peak]; - } else { + } + else { intensities[label] /= (float)counts[label]; } } @@ -13815,7 +14091,8 @@ int GCArenormalizeToExample(GCA *gca, MRI *mri_seg, MRI *mri_T1) { return (NO_ERROR); } -static GC1D *findGCInWindow(GCA *gca, int x0, int y0, int z0, int label, int wsize) { +static GC1D *findGCInWindow(GCA *gca, int x0, int y0, int z0, int label, int wsize) +{ GC1D *gc, *gc_min; int x, y, z, n, whalf; double dist, min_dist; @@ -13854,7 +14131,8 @@ static GC1D *findGCInWindow(GCA *gca, int x0, int y0, int z0, int label, int wsi return (gc_min); } -GC1D *GCAfindClosestValidGC(GCA *gca, int x0, int y0, int z0, int label, int check_var) { +GC1D *GCAfindClosestValidGC(GCA *gca, int x0, int y0, int z0, int label, int check_var) +{ GC1D *gc, *gc_min; int x, y, z, n, wsize; double dist, min_dist, det; @@ -13892,7 +14170,8 @@ GC1D *GCAfindClosestValidGC(GCA *gca, int x0, int y0, int z0, int label, int che m_cov_inv = load_inverse_covariance_matrix(gc, m_cov_inv, gca->ninputs); if (m_cov_inv == NULL) { det = -1; - } else { + } + else { det *= 1; // MatrixFree(&m_cov_inv) ; } if ((check_var && det <= MIN_DET) || gc->ntraining == 0) { @@ -13949,7 +14228,8 @@ GC1D *GCAfindClosestValidGC(GCA *gca, int x0, int y0, int z0, int label, int che return (gc_min); } -static int gcaCheck(GCA *gca) { +static int gcaCheck(GCA *gca) +{ int x, y, z, ret = NO_ERROR, n, r, c, v; GCA_NODE *gcan; GC1D *gc; @@ -13978,7 +14258,8 @@ static int gcaCheck(GCA *gca) { return (ret); } int GCAcomputeVoxelLikelihoods( - GCA *gca, MRI *mri_in, int x, int y, int z, TRANSFORM *transform, int *labels, double *likelihoods) { + GCA *gca, MRI *mri_in, int x, int y, int z, TRANSFORM *transform, int *labels, double *likelihoods) +{ GCA_NODE *gcan; int xn, yn, zn, n; float vals[MAX_GCA_INPUTS]; @@ -13991,12 +14272,14 @@ int GCAcomputeVoxelLikelihoods( likelihoods[n] = GCAcomputeConditionalDensity(&gcan->gcs[n], vals, gca->ninputs, labels[n]); } return (gcan->nlabels); - } else { + } + else { return 0; } } -int GCAmaxLikelihoodLabel(const GCA_NODE *gcan, float *vals, int ninputs, float *plikelihood) { +int GCAmaxLikelihoodLabel(const GCA_NODE *gcan, float *vals, int ninputs, float *plikelihood) +{ double p, max_p; int n, best_label; @@ -14019,7 +14302,8 @@ int GCAmaxLikelihoodLabel(const GCA_NODE *gcan, float *vals, int ninputs, float } return (best_label); } -double GCAcomputeConditionalDensity(GC1D *gc, float *vals, int ninputs, int label) { +double GCAcomputeConditionalDensity(GC1D *gc, float *vals, int ninputs, int label) +{ double p, dist; /* compute 1-d Mahalanobis distance */ @@ -14036,7 +14320,8 @@ double GCAcomputeConditionalDensity(GC1D *gc, float *vals, int ninputs, int labe } return (p); } -double GCAcomputeNormalizedConditionalDensity(GCA *gca, int xp, int yp, int zp, float *vals, int label) { +double GCAcomputeNormalizedConditionalDensity(GCA *gca, int xp, int yp, int zp, float *vals, int label) +{ GCA_PRIOR *gcap; GC1D *gc; int n; @@ -14068,7 +14353,8 @@ double GCAcomputeNormalizedConditionalDensity(GCA *gca, int xp, int yp, int zp, return (plabel); } -static double gcaComputeLogDensity(GC1D *gc, float *vals, int ninputs, float prior, int label) { +static double gcaComputeLogDensity(GC1D *gc, float *vals, int ninputs, float prior, int label) +{ double log_p; log_p = GCAcomputeConditionalLogDensity(gc, vals, ninputs, label); @@ -14076,7 +14362,8 @@ static double gcaComputeLogDensity(GC1D *gc, float *vals, int ninputs, float pri return (log_p); } -double GCAcomputeConditionalLogDensity(const GC1D *gc, float *vals, int ninputs, int label) { +double GCAcomputeConditionalLogDensity(const GC1D *gc, float *vals, int ninputs, int label) +{ double log_p, det; /* compute 1-d Mahalanobis distance */ @@ -14094,7 +14381,8 @@ double GCAcomputeConditionalLogDensity(const GC1D *gc, float *vals, int ninputs, return (log_p); } -GCA_SAMPLE *GCAfindAllSamples(GCA *gca, int *pnsamples, int *exclude_list, int unknown_nbr_spacing) { +GCA_SAMPLE *GCAfindAllSamples(GCA *gca, int *pnsamples, int *exclude_list, int unknown_nbr_spacing) +{ GCA_SAMPLE *gcas; GCA_PRIOR *gcap; GC1D *gc; @@ -14240,7 +14528,8 @@ GCA_SAMPLE *GCAfindAllSamples(GCA *gca, int *pnsamples, int *exclude_list, int u gcas[i].covars[v] = gc->covars[v]; } } - } else // not found + } + else // not found { badcount++; for (v = r = 0; r < gca->ninputs; r++) { @@ -14248,7 +14537,8 @@ GCA_SAMPLE *GCAfindAllSamples(GCA *gca, int *pnsamples, int *exclude_list, int u for (c = r; c < gca->ninputs; c++, v++) { if (c == r) { gcas[i].covars[v] = 1.0; - } else { + } + else { gcas[i].covars[v] = 0.0; } } @@ -14267,7 +14557,8 @@ GCA_SAMPLE *GCAfindAllSamples(GCA *gca, int *pnsamples, int *exclude_list, int u *pnsamples = nsamples; return (gcas); } -int GCAcomputeMAPlabelAtLocation(GCA *gca, int xp, int yp, int zp, float *vals, int *pmax_n, float *plog_p) { +int GCAcomputeMAPlabelAtLocation(GCA *gca, int xp, int yp, int zp, float *vals, int *pmax_n, float *plog_p) +{ GCA_PRIOR *gcap; GC1D *gc; int n, max_n, max_label; @@ -14319,7 +14610,8 @@ int GCAcomputeMAPlabelAtLocation(GCA *gca, int xp, int yp, int zp, float *vals, } return (max_label); // return most probable label } -int GCAcomputeMLElabelAtLocation(GCA *gca, int xp, int yp, int zp, float *vals, int *pmax_n, float *plog_p) { +int GCAcomputeMLElabelAtLocation(GCA *gca, int xp, int yp, int zp, float *vals, int *pmax_n, float *plog_p) +{ GCA_PRIOR *gcap; GC1D *gc; int n, max_n, max_label; @@ -14368,7 +14660,8 @@ int GCAcomputeMLElabelAtLocation(GCA *gca, int xp, int yp, int zp, float *vals, } return (max_label); } -GC1D *alloc_gcs(int nlabels, int flags, int ninputs) { +GC1D *alloc_gcs(int nlabels, int flags, int ninputs) +{ GC1D *gcs; int i; @@ -14401,7 +14694,8 @@ GC1D *alloc_gcs(int nlabels, int flags, int ninputs) { return (gcs); } -int free_gcs(GC1D *gcs, int nlabels, int ninputs) { +int free_gcs(GC1D *gcs, int nlabels, int ninputs) +{ int i, j; for (i = 0; i < nlabels; i++) { @@ -14431,7 +14725,8 @@ int free_gcs(GC1D *gcs, int nlabels, int ninputs) { return (NO_ERROR); } -int copy_gcs(int nlabels, GC1D *gcs_src, GC1D *gcs_dst, int ninputs) { +int copy_gcs(int nlabels, GC1D *gcs_src, GC1D *gcs_dst, int ninputs) +{ int i, j, k, r, c, v; for (i = 0; i < nlabels; i++) { @@ -14463,7 +14758,8 @@ int copy_gcs(int nlabels, GC1D *gcs_src, GC1D *gcs_dst, int ninputs) { return (NO_ERROR); } -int GCAfreeGibbs(GCA *gca) { +int GCAfreeGibbs(GCA *gca) +{ int x, y, z, n, i; GCA_NODE *gcan; GC1D *gc; @@ -14498,7 +14794,8 @@ int GCAfreeGibbs(GCA *gca) { return (NO_ERROR); } -int GCAcomputeSampleCoords(GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, TRANSFORM *transform) { +int GCAcomputeSampleCoords(GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, TRANSFORM *transform) +{ int n, x, y, z; TransformInvert(transform, mri); @@ -14526,7 +14823,8 @@ int GCAcomputeSampleCoords(GCA *gca, MRI *mri, GCA_SAMPLE *gcas, int nsamples, T } static HISTOGRAM *gcaHistogramSamples( - GCA *gca, GCA_SAMPLE *gcas, MRI *mri, TRANSFORM *transform, int nsamples, HISTOGRAM *histo, int frame) { + GCA *gca, GCA_SAMPLE *gcas, MRI *mri, TRANSFORM *transform, int nsamples, HISTOGRAM *histo, int frame) +{ int i; double mean, var; double val; @@ -14535,7 +14833,8 @@ static HISTOGRAM *gcaHistogramSamples( if (!histo) { MRIvalRangeFrame(mri, &fmin, &fmax, frame); histo = HISTOalloc(nint(fmax - fmin + 1)); - } else { + } + else { HISTOclear(histo, histo); } @@ -14550,7 +14849,8 @@ static HISTOGRAM *gcaHistogramSamples( var = var / (double)nsamples - mean * mean; return (histo); } -int GCArenormalizeFromAtlas(GCA *gca, GCA *gca_template) { +int GCArenormalizeFromAtlas(GCA *gca, GCA *gca_template) +{ int xs, ys, zs, xt, yt, zt, ns, label, v; float scale; GCA_NODE *gcan; @@ -14588,7 +14888,8 @@ int GCArenormalizeFromAtlas(GCA *gca, GCA *gca_template) { return (NO_ERROR); } -void load_vals(const MRI *mri_inputs, float x, float y, float z, float *vals, int ninputs) { +void load_vals(const MRI *mri_inputs, float x, float y, float z, float *vals, int ninputs) +{ int n; double val; @@ -14600,7 +14901,8 @@ void load_vals(const MRI *mri_inputs, float x, float y, float z, float *vals, in } } -double GCAmahDist(const GC1D *gc, const float *vals, const int ninputs) { +double GCAmahDist(const GC1D *gc, const float *vals, const int ninputs) +{ static VECTOR *v_means = NULL, *v_vals = NULL; static MATRIX *m_cov = NULL, *m_cov_inv; int i; @@ -14649,7 +14951,8 @@ double GCAmahDist(const GC1D *gc, const float *vals, const int ninputs) { return (dsq); } -double GCAmahDistIdentityCovariance(GC1D *gc, float *vals, int ninputs) { +double GCAmahDistIdentityCovariance(GC1D *gc, float *vals, int ninputs) +{ static VECTOR *v_means = NULL, *v_vals = NULL; int i; double dsq; @@ -14683,7 +14986,8 @@ double GCAcomputePosteriorDensity(GCA_PRIOR *gcap, int xn, int yn, int zn, - GCA *gca) { + GCA *gca) +{ GC1D *gc; double p; @@ -14692,7 +14996,8 @@ double GCAcomputePosteriorDensity(GCA_PRIOR *gcap, p = GCAcomputeConditionalDensity(gc, vals, ninputs, gcan->labels[node_n]); p *= getPrior(gcap, gcan->labels[node_n]); - } else // n refers to gcap index + } + else // n refers to gcap index { gc = gcanGetGC(gcan, gcap->labels[prior_n]); @@ -14710,7 +15015,8 @@ double GCAcomputePosteriorDensity(GCA_PRIOR *gcap, return (p); } -VECTOR *load_mean_vector(const GC1D *gc, VECTOR *v_means, const int ninputs) { +VECTOR *load_mean_vector(const GC1D *gc, VECTOR *v_means, const int ninputs) +{ int n; if (v_means == NULL) { @@ -14724,7 +15030,8 @@ VECTOR *load_mean_vector(const GC1D *gc, VECTOR *v_means, const int ninputs) { return (v_means); } -MATRIX *load_covariance_matrix(const GC1D *gc, MATRIX *m_cov, const int ninputs) { +MATRIX *load_covariance_matrix(const GC1D *gc, MATRIX *m_cov, const int ninputs) +{ int n, m, i; // printf("In load cov matrix; ninpupts = %d \n", ninputs); if (m_cov == NULL) { @@ -14744,7 +15051,8 @@ MATRIX *load_covariance_matrix(const GC1D *gc, MATRIX *m_cov, const int ninputs) return (m_cov); } -int set_mean_vector(GC1D *gc, VECTOR *v_means, int ninputs) { +int set_mean_vector(GC1D *gc, VECTOR *v_means, int ninputs) +{ int n; for (n = 0; n < ninputs; n++) { @@ -14754,7 +15062,8 @@ int set_mean_vector(GC1D *gc, VECTOR *v_means, int ninputs) { return (NO_ERROR); } -int set_covariance_matrix(GC1D *gc, MATRIX *m_cov, int ninputs) { +int set_covariance_matrix(GC1D *gc, MATRIX *m_cov, int ninputs) +{ int n, m, i; for (i = n = 0; n < ninputs; n++) @@ -14768,7 +15077,8 @@ int set_covariance_matrix(GC1D *gc, MATRIX *m_cov, int ninputs) { return (NO_ERROR); } -MATRIX *load_inverse_covariance_matrix(GC1D *gc, MATRIX *m_inv_cov, int ninputs) { +MATRIX *load_inverse_covariance_matrix(GC1D *gc, MATRIX *m_inv_cov, int ninputs) +{ static MATRIX *m_cov[_MAX_FS_THREADS] = {NULL}; #ifdef HAVE_OPENMP int tid = omp_get_thread_num(); @@ -14790,7 +15100,8 @@ MATRIX *load_inverse_covariance_matrix(GC1D *gc, MATRIX *m_inv_cov, int ninputs) return (m_inv_cov); } -double covariance_determinant(const GC1D *gc, const int ninputs) { +double covariance_determinant(const GC1D *gc, const int ninputs) +{ double det; int tid; static MATRIX *m_cov[_MAX_FS_THREADS]; @@ -14817,7 +15128,8 @@ double covariance_determinant(const GC1D *gc, const int ninputs) { return (det); } -static double gcaComputeSampleLogDensity(GCA_SAMPLE *gcas, float *vals, int ninputs) { +static double gcaComputeSampleLogDensity(GCA_SAMPLE *gcas, float *vals, int ninputs) +{ double log_p; log_p = gcaComputeSampleConditionalLogDensity(gcas, vals, ninputs, gcas->label); @@ -14825,7 +15137,8 @@ static double gcaComputeSampleLogDensity(GCA_SAMPLE *gcas, float *vals, int ninp return (log_p); } -static double gcaComputeSampleConditionalLogDensity(GCA_SAMPLE *gcas, float *vals, int ninputs, int label) { +static double gcaComputeSampleConditionalLogDensity(GCA_SAMPLE *gcas, float *vals, int ninputs, int label) +{ double log_p, det; #if 0 @@ -14841,7 +15154,8 @@ static double gcaComputeSampleConditionalLogDensity(GCA_SAMPLE *gcas, float *val } return (log_p); } -static VECTOR *load_sample_mean_vector(GCA_SAMPLE *gcas, VECTOR *v_means, int ninputs) { +static VECTOR *load_sample_mean_vector(GCA_SAMPLE *gcas, VECTOR *v_means, int ninputs) +{ int n; if (v_means == NULL) { @@ -14854,7 +15168,8 @@ static VECTOR *load_sample_mean_vector(GCA_SAMPLE *gcas, VECTOR *v_means, int ni return (v_means); } -static MATRIX *load_sample_covariance_matrix(GCA_SAMPLE *gcas, MATRIX *m_cov, int ninputs) { +static MATRIX *load_sample_covariance_matrix(GCA_SAMPLE *gcas, MATRIX *m_cov, int ninputs) +{ int n, m, i; if (m_cov == NULL) { @@ -14869,7 +15184,8 @@ static MATRIX *load_sample_covariance_matrix(GCA_SAMPLE *gcas, MATRIX *m_cov, in return (m_cov); } -static double sample_covariance_determinant(GCA_SAMPLE *gcas, int ninputs) { +static double sample_covariance_determinant(GCA_SAMPLE *gcas, int ninputs) +{ double det; static MATRIX *m_cov = NULL; @@ -14884,7 +15200,8 @@ static double sample_covariance_determinant(GCA_SAMPLE *gcas, int ninputs) { det = MatrixDeterminant(m_cov); return (det); } -double GCAsampleMahDist(GCA_SAMPLE *gcas, float *vals, int ninputs) { +double GCAsampleMahDist(GCA_SAMPLE *gcas, float *vals, int ninputs) +{ static VECTOR *v_means = NULL, *v_vals = NULL; static MATRIX *m_cov = NULL, *m_cov_inv; int i; @@ -14931,7 +15248,8 @@ double GCAsampleMahDist(GCA_SAMPLE *gcas, float *vals, int ninputs) { return (dsq); } #if 1 -static double gcaComputeSampleConditionalDensity(GCA_SAMPLE *gcas, float *vals, int ninputs, int label) { +static double gcaComputeSampleConditionalDensity(GCA_SAMPLE *gcas, float *vals, int ninputs, int label) +{ double p, dist; /* compute 1-d Mahalanobis distance */ @@ -14949,7 +15267,8 @@ static double gcaComputeSampleConditionalDensity(GCA_SAMPLE *gcas, float *vals, return (p); } #endif -int GCAlabelExists(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z, int label) { +int GCAlabelExists(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z, int label) +{ #if 0 int xn, yn, zn ; @@ -14970,7 +15289,8 @@ int GCAlabelExists(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z #endif } -GC1D *GCAfindSourceGC(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z, int label) { +GC1D *GCAfindSourceGC(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z, int label) +{ int xn, yn, zn; GC1D *gc = NULL; @@ -14979,7 +15299,8 @@ GC1D *GCAfindSourceGC(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, in } return (gc); } -int GCAfreeSamples(GCA_SAMPLE **pgcas, int nsamples) { +int GCAfreeSamples(GCA_SAMPLE **pgcas, int nsamples) +{ GCA_SAMPLE *gcas; int i; @@ -15001,7 +15322,8 @@ int GCAfreeSamples(GCA_SAMPLE **pgcas, int nsamples) { free(gcas); return (NO_ERROR); } -int GCAnormalizePD(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) { +int GCAnormalizePD(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) +{ double mri_PD = 0.0, gca_PD = 0.0; int n, x, y, z, brain_node, nvals, label; GCA_PRIOR *gcap; @@ -15046,7 +15368,8 @@ int GCAnormalizePD(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) { return (NO_ERROR); } GCA *GCAcreateWeightedFlashGCAfromParameterGCA( - GCA *gca_T1PD, double *TR, double *fa, double *TE, int nflash, double *wts, double lambda) { + GCA *gca_T1PD, double *TR, double *fa, double *TE, int nflash, double *wts, double lambda) +{ GCA *gca_flash; GCA_PRIOR *gcap_src, *gcap_dst; GCA_NODE *gcan_src, *gcan_dst; @@ -15205,7 +15528,8 @@ GCA *GCAcreateWeightedFlashGCAfromParameterGCA( if (T1 < MIN_T1) { gc_dst->regularized = 1; m_cov_dst = MatrixIdentity(gca_flash->ninputs, m_cov_dst); - } else { + } + else { m_cov_src = load_covariance_matrix(gc_src, m_cov_src, gca_T1PD->ninputs); m_jacobian_T = MatrixTranspose(m_jacobian, m_jacobian_T); m_tmp = MatrixMultiply(m_cov_src, m_jacobian_T, m_tmp); @@ -15250,7 +15574,8 @@ GCA *GCAcreateWeightedFlashGCAfromParameterGCA( return (gca_flash); } -GCA *GCAcreateFlashGCAfromParameterGCA(GCA *gca_T1PD, double *TR, double *fa, double *TE, int nflash, double lambda) { +GCA *GCAcreateFlashGCAfromParameterGCA(GCA *gca_T1PD, double *TR, double *fa, double *TE, int nflash, double lambda) +{ GCA *gca_flash; GCA_PRIOR *gcap_src, *gcap_dst; GCA_NODE *gcan_src, *gcan_dst; @@ -15403,7 +15728,8 @@ GCA *GCAcreateFlashGCAfromParameterGCA(GCA *gca_T1PD, double *TR, double *fa, do #define MIN_T1 50 if (T1 < MIN_T1) { m_cov_dst = MatrixIdentity(gca_flash->ninputs, m_cov_dst); - } else { + } + else { m_cov_src = load_covariance_matrix(gc_src, m_cov_src, gca_T1PD->ninputs); m_jacobian_T = MatrixTranspose(m_jacobian, m_jacobian_T); m_tmp = MatrixMultiply(m_cov_src, m_jacobian_T, m_tmp); @@ -15447,7 +15773,8 @@ GCA *GCAcreateFlashGCAfromParameterGCA(GCA *gca_T1PD, double *TR, double *fa, do return (gca_flash); } -int GCAfixSingularCovarianceMatrices(GCA *gca) { +int GCAfixSingularCovarianceMatrices(GCA *gca) +{ int x, y, z, fixed = 0, i, r, c, n, num, nparams, regularized = 0; GCA_NODE *gcan; GC1D *gc; @@ -15482,7 +15809,8 @@ int GCAfixSingularCovarianceMatrices(GCA *gca) { } } } - } else { + } + else { for (num = 0, x = 0; x < gca->node_width; x++) { for (y = 0; y < gca->node_height; y++) { for (z = 0; z < gca->node_depth; z++) { @@ -15522,7 +15850,8 @@ int GCAfixSingularCovarianceMatrices(GCA *gca) { } min_det = min_det / pow(10.0, gca->ninputs); printf(" using min determinant for regularization = %2.1f\n", min_det); - } else { + } + else { min_det = MIN_DET; } @@ -15566,7 +15895,8 @@ int GCAfixSingularCovarianceMatrices(GCA *gca) { MatrixFree(&m); } } - } else /* not singular - check if it is ill-conditioned */ + } + else /* not singular - check if it is ill-conditioned */ { if (gc->regularized == 0) { DiagBreak(); @@ -15629,7 +15959,8 @@ int GCAfixSingularCovarianceMatrices(GCA *gca) { regularized); return (NO_ERROR); } -int GCAregularizeCovarianceMatrices(GCA *gca, double lambda) { +int GCAregularizeCovarianceMatrices(GCA *gca, double lambda) +{ int x, y, z, r, n, num, nparams; GCA_NODE *gcan; GC1D *gc; @@ -15677,7 +16008,8 @@ int GCAregularizeCovarianceMatrices(GCA *gca, double lambda) { } min_det = min_det / pow(10.0, gca->ninputs); printf(" using min determinant for regularization = %2.1f\n", min_det); - } else { + } + else { min_det = MIN_DET; } @@ -15720,7 +16052,8 @@ int GCAregularizeCovarianceMatrices(GCA *gca, double lambda) { return (NO_ERROR); } -int GCAsetFlashParameters(GCA *gca, double *TRs, double *FAs, double *TEs) { +int GCAsetFlashParameters(GCA *gca, double *TRs, double *FAs, double *TEs) +{ int n; printf("setting GCA flash parameters to:\n"); @@ -15734,7 +16067,8 @@ int GCAsetFlashParameters(GCA *gca, double *TRs, double *FAs, double *TEs) { return (NO_ERROR); } -GCA *GCAcreateFlashGCAfromFlashGCA(GCA *gca_flash_src, double *TR, double *fa, double *TE, int nflash) { +GCA *GCAcreateFlashGCAfromFlashGCA(GCA *gca_flash_src, double *TR, double *fa, double *TE, int nflash) +{ GCA *gca_flash_dst; GCA_PRIOR *gcap_src, *gcap_dst; GCA_NODE *gcan_src, *gcan_dst; @@ -15984,7 +16318,8 @@ GCA *GCAcreateFlashGCAfromFlashGCA(GCA *gca_flash_src, double *TR, double *fa, d return (gca_flash_dst); } -int GCAnormalizeMeans(GCA *gca, float target) { +int GCAnormalizeMeans(GCA *gca, float target) +{ int x, y, z, frame, n; double norm; double val; @@ -16015,7 +16350,8 @@ int GCAnormalizeMeans(GCA *gca, float target) { return (NO_ERROR); } -int GCAregularizeCovariance(GCA *gca, float regularize) { +int GCAregularizeCovariance(GCA *gca, float regularize) +{ int x, y, z, i, r, c, n, num, nparams; GCA_NODE *gcan; GC1D *gc; @@ -16100,7 +16436,8 @@ int GCAregularizeCovariance(GCA *gca, float regularize) { return (NO_ERROR); } -MATRIX *GCAlabelCovariance(GCA *gca, int label, MATRIX *m_total) { +MATRIX *GCAlabelCovariance(GCA *gca, int label, MATRIX *m_total) +{ int xn, yn, zn, n; GCA_NODE *gcan; GC1D *gc; @@ -16126,7 +16463,8 @@ MATRIX *GCAlabelCovariance(GCA *gca, int label, MATRIX *m_total) { MatrixScalarMul(m_cov, prior, m_cov); if (m_total == NULL) { m_total = MatrixCopy(m_cov, NULL); - } else { + } + else { MatrixAdd(m_cov, m_total, m_total); } } @@ -16147,7 +16485,8 @@ MATRIX *GCAlabelCovariance(GCA *gca, int label, MATRIX *m_total) { return (m_total); } -int GCAlabelMeanFromImage(GCA *gca, TRANSFORM *transform, MRI *mri, int label, float *means) { +int GCAlabelMeanFromImage(GCA *gca, TRANSFORM *transform, MRI *mri, int label, float *means) +{ int xn, yn, zn, n, r, xv, yv, zv; GCA_NODE *gcan; GC1D *gc; @@ -17143,7 +17482,8 @@ int GCAmapRenormalizeWithAlignment(GCA *gca, FILE *logfp, const char *base_name, LTA **plta, - int handle_expanded_ventricles) { + int handle_expanded_ventricles) +{ return (GCAcomputeRenormalizationWithAlignment( gca, mri, transform, logfp, base_name, plta, handle_expanded_ventricles, NULL, NULL, NULL, NULL)); } @@ -17154,7 +17494,8 @@ int GCAmapRenormalizeWithAlignmentLongitudinal(GCA *gca, FILE *logfp, const char *base_name, LTA **plta, - int handle_expanded_ventricles) { + int handle_expanded_ventricles) +{ return (GCAcomputeRenormalizationWithAlignmentLongitudinal( gca, mri, transform, logfp, base_name, plta, handle_expanded_ventricles, NULL, NULL, NULL, NULL)); } @@ -17170,7 +17511,8 @@ int GCAseqRenormalizeWithAlignment(GCA *gca, float *old_label_scales, float *old_label_offsets, float *old_label_peaks, - int *old_label_computed) { + int *old_label_computed) +{ if (old_label_scales == NULL || old_label_offsets == NULL || old_label_peaks == NULL || old_label_computed == NULL) ErrorExit(ERROR_BADPARM, "%s ERROR: GCA seqRenormalize old_label needs to " @@ -17202,7 +17544,8 @@ int GCAseqRenormalizeWithAlignment(GCA *gca, // printf("%d old: %f new: %f final: ",l,old_label_scales[l], plabel_scales[l]); old_label_offsets[l] = plabel_scales[l] * old_label_offsets[l] + plabel_offsets[l]; old_label_scales[l] *= plabel_scales[l]; - } else // no old label info -> coyp offsets and scales + } + else // no old label info -> coyp offsets and scales { old_label_offsets[l] = plabel_offsets[l]; old_label_scales[l] = plabel_scales[l]; @@ -17265,7 +17608,8 @@ int GCAseqRenormalizeWithAlignment(GCA *gca, static int mtl_labels[] = {Left_Amygdala, Right_Amygdala, Left_Hippocampus, Right_Hippocampus}; #define MTL_LABELS (sizeof(mtl_labels) / sizeof(mtl_labels[0])) -MRI *MRImarkPossibleBorders(MRI *mri, MRI *mri_borders, float border_thresh) { +MRI *MRImarkPossibleBorders(MRI *mri, MRI *mri_borders, float border_thresh) +{ int x, y, z, xk, yk, zk, xi, yi, zi; float val, val0; @@ -17302,7 +17646,8 @@ MRI *MRImarkPossibleBorders(MRI *mri, MRI *mri_borders, float border_thresh) { } return (mri_borders); } -typedef struct { +typedef struct +{ int nsubjects; int nlabels; int ntypes; // how many different acquisition types are there @@ -17317,7 +17662,8 @@ typedef struct { char **subjects; } LABEL_HISTOS, LH; -static LABEL_HISTOS *lhAlloc(int nsubjects, int nlabels, int ntypes) { +static LABEL_HISTOS *lhAlloc(int nsubjects, int nlabels, int ntypes) +{ LABEL_HISTOS *lh; int s, n; @@ -17351,7 +17697,8 @@ static LABEL_HISTOS *lhAlloc(int nsubjects, int nlabels, int ntypes) { return (lh); } -static int lhComputeMRIHistos(LH *lh, MRI *mri_norm, int nerode) { +static int lhComputeMRIHistos(LH *lh, MRI *mri_norm, int nerode) +{ MRI *mri_label, *mri_eroded; // int n ; @@ -17375,7 +17722,8 @@ static int lhComputeMRIHistos(LH *lh, MRI *mri_norm, int nerode) { return (NO_ERROR); } -static double lhComputeSimilarity(LH *lh, int s) { +static double lhComputeSimilarity(LH *lh, int s) +{ double total_sim; #if 0 double sim, total_sim ; @@ -17393,7 +17741,8 @@ static double lhComputeSimilarity(LH *lh, int s) { } #define MAX_SUBJECTS 10000 -static int lhFindMostSimilarAcquisitionType(LH *lh, MRI *mri_norm) { +static int lhFindMostSimilarAcquisitionType(LH *lh, MRI *mri_norm) +{ int max_ind, s, nsubjects[MAX_SUBJECTS], n; double max_sim, sim; @@ -17425,7 +17774,8 @@ static int lhFindMostSimilarAcquisitionType(LH *lh, MRI *mri_norm) { return (max_ind); } -static int lhFree(LH **plh) { +static int lhFree(LH **plh) +{ LH *lh; int s, n; @@ -17450,7 +17800,8 @@ static int lhFree(LH **plh) { return (NO_ERROR); } -static LABEL_HISTOS *lhRead(char *fname) { +static LABEL_HISTOS *lhRead(char *fname) +{ FILE *fp; int nsubjects, nlabels, s, n, cnt, i, label, ntypes; LABEL_HISTOS *lh; @@ -17530,7 +17881,8 @@ int GCAmapRenormalizeWithHistograms(GCA *gca, float *plabel_scales, float *plabel_offsets, float *plabel_peaks, - int *plabel_computed) { + int *plabel_computed) +{ int l, frame, j, gca_peak, acq_type, s, num; float label_scales[MAX_CMA_LABELS], label_peaks[MAX_CMA_LABELS], label_offsets[MAX_CMA_LABELS], lower_thresh, upper_thresh; @@ -17541,7 +17893,8 @@ int GCAmapRenormalizeWithHistograms(GCA *gca, if (FileExists("label_scales.dat")) { lh = lhRead("label_scales.dat"); - } else { + } + else { char *cp = getenv("FREESURFER_HOME"), fname[STRLEN]; sprintf(fname, "%s/average/label_scales.dat", cp); @@ -17769,7 +18122,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, float *plabel_scales, float *plabel_offsets, float *plabel_peaks, - int *plabel_computed) { + int *plabel_computed) +{ HISTOGRAM *h_mri, *h_gca, *h_mtl = NULL, *h_caudate; int l, nbins, i, x, y, z, num, frame, bin, j, n, computed[MAX_CMA_LABELS], b, label, k, border = BORDER_SIZE, gca_peak, mri_peak; @@ -17812,7 +18166,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, printf("renormalizing by structure alignment....\n"); if (plta) { lta = *plta; - } else { + } + else { lta = NULL; } mri_borders = MRImarkPossibleBorders(mri, NULL, 15); @@ -17849,11 +18204,14 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, if (transform->type != MORPH_3D_TYPE) { if (IS_HIPPO(l) || IS_AMYGDALA(l) || IS_CAUDATE(l) || IS_PUTAMEN(l) || IS_PALLIDUM(l)) { border = BORDER_SIZE + 1; // need more context for hippo - } else if (IS_GM(l)) { + } + else if (IS_GM(l)) { border = 0; - } else if (IS_WHITE_CLASS(l)) { + } + else if (IS_WHITE_CLASS(l)) { border = WM_BORDER_SIZE; - } else { + } + else { border = BORDER_SIZE; } GCAbuildMostLikelyVolumeForStructure(gca, mri_seg, l, border, transform, mri_labels); @@ -17929,7 +18287,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, if (n >= lta->num_xforms) { n = -1; // indicate no xform found } - } else // no transform specified by caller + } + else // no transform specified by caller { n = -1; } @@ -17951,7 +18310,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, initialize_ventricle_alignment(mri_seg, mri, m_L, label_base_name, border, l); } MRIfaridAlignImages(mri_seg, mri, m_L); - } else { + } + else { // assume that cortical gm goes as wm if ((l == Left_Cerebral_Cortex) && computed[Left_Cerebral_White_Matter] != 0) { if (m_by_label[Left_Cerebral_White_Matter]) m_L = MatrixCopy(m_by_label[Left_Cerebral_White_Matter], m_L); @@ -17997,7 +18357,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, MatrixFree(&m_L); m_L = MRIgetVoxelToVoxelXform(mri_seg, mri); } - } else // use previously computed transform + } + else // use previously computed transform { m_L = MatrixCopy(lta->xforms[n].m_L, NULL); } @@ -18018,7 +18379,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, GCAbuildMostLikelyVolumeForStructure(gca, mri_seg, l, 0, transform, NULL); MRIerode(mri_seg, mri_seg); MRIerode(mri_seg, mri_seg); - } else { + } + else { /* put ventricles back in for erosion to remove (otherwise a bunch of hippo gets removed */ @@ -18044,14 +18406,16 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, } mri_aligned = MRIlinearTransform(mri_seg, NULL, m_L); - } else // 3d morph already done - don't bother aligning + } + else // 3d morph already done - don't bother aligning { m_L = NULL; if (l == Left_Cerebral_White_Matter || l == Right_Cerebral_White_Matter) { // wm so big it's hard to localize with a linear xform GCAbuildMostLikelyVolumeForStructure(gca, mri_seg, l, 0, transform, NULL); MRIerode(mri_seg, mri_seg); - } else { + } + else { GCAbuildMostLikelyVolumeForStructure(gca, mri_seg, l, 0, transform, NULL); } mri_aligned = MRIerode(mri_seg, NULL); @@ -18098,7 +18462,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, bin = nint((val - fmin) / h_mri->bin_size); if (bin >= h_mri->nbins) { bin = h_mri->nbins - 1; - } else if (bin < 0) { + } + else if (bin < 0) { bin = 0; } @@ -18248,7 +18613,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, if (plta && (!IS_GM(l))) // GM will be copied from WM later { m_by_label[l] = m_L; // store if for assembling an LTA later - } else { + } + else { MatrixFree(&m_L); } } @@ -18309,7 +18675,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, if (IS_LAT_VENT(l)) { if (label_scales[l] < 0.4) { label_scales[l] = 0.4; - } else if (label_scales[l] > 1.5) { + } + else if (label_scales[l] > 1.5) { label_scales[l] = 1.5; } } @@ -18359,7 +18726,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, HISTOplot(h_gca, fname); } } - } else { + } + else { printf("overlap = %g, overlap_threshold = %g\n", overlap, overlap_threshold); printf("insufficient overlap %2.4f in histograms - rejecting\n", overlap); } @@ -18379,7 +18747,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, for (j = 0; j <= 1; j++) { if (j == 0) { l = Left_Caudate; - } else { + } + else { l = Right_Caudate; } h_gca = gcaGetLabelHistogram(gca, l, 0, 1); @@ -18402,7 +18771,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, upper_thresh); label_scales[l] = 1.0; label_offsets[l] = 1.0; - } else { + } + else { label_peaks[l] = label_peaks[l] * label_scales[l] + label_offsets[l]; if (logfp) { @@ -18455,7 +18825,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, upper_thresh); label_scales[l] = 1.0; label_offsets[l] = 1.0; - } else { + } + else { label_peaks[l] = label_peaks[l] * label_scales[l] + label_offsets[l]; if (logfp) { @@ -18555,7 +18926,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, label_scales[rhl], label_offsets[rhl], label_peaks[rhl]); - } else if (computed[rh_labels[k]] && !computed[lh_labels[k]]) { + } + else if (computed[rh_labels[k]] && !computed[lh_labels[k]]) { lhl = lh_labels[k]; rhl = rh_labels[k]; label_scales[lhl] = label_scales[rhl]; @@ -18586,7 +18958,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, if (num == 0) { mean_gm_scale = 1; mean_gm_offset = 0; - } else { + } + else { mean_gm_scale /= (float)num; mean_gm_offset /= (float)num; } @@ -18605,7 +18978,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, if (num == 0) { mean_wm_scale = 1; mean_wm_offset = 0; - } else { + } + else { mean_wm_scale /= (float)num; mean_wm_offset /= (float)num; } @@ -18624,7 +18998,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, if (num == 0) { mean_csf_scale = 1; mean_csf_offset = 0; - } else { + } + else { mean_csf_scale /= (float)num; mean_csf_offset /= (float)num; } @@ -18721,11 +19096,13 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, label_scales[l] = mean_csf_scale; label_offsets[l] = mean_csf_offset; computed[l] = 1; - } else if (equiv_class[l] == 2) { + } + else if (equiv_class[l] == 2) { label_scales[l] = mean_wm_scale; label_offsets[l] = mean_wm_offset; computed[l] = 1; - } else if (equiv_class[l] == 3) { + } + else if (equiv_class[l] == 3) { label_scales[l] = mean_gm_scale; label_offsets[l] = mean_gm_offset; computed[l] = 1; @@ -18967,7 +19344,8 @@ int GCAcomputeRenormalizationWithAlignment(GCA *gca, // other side of the other if ((fabs(delta_j) > fabs(delta_i)) && !FZERO(delta_j)) { delta_j /= fabs(delta_j); // make it +-1 - } else if (!FZERO(delta_i)) { + } + else if (!FZERO(delta_i)) { delta_i /= fabs(delta_i); // make it +-1 } } @@ -19090,7 +19468,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, float *plabel_scales, float *plabel_offsets, float *plabel_peaks, - int *plabel_computed) { + int *plabel_computed) +{ HISTOGRAM *h_mri, *h_gca, *h_mtl = NULL, *h_caudate; int l, nbins, i, x, y, z, num, frame, bin, j, computed[MAX_CMA_LABELS], label, k, gca_peak, mri_peak; float fmin, fmax, label_scales[MAX_CMA_LABELS], overlap, mean_gm_scale, mean_wm_scale, mean_csf_scale, @@ -19163,7 +19542,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, // wm so big it's hard to localize with a linear xform GCAbuildMostLikelyVolumeForStructure(gca, mri_seg, l, 0, transform, NULL); MRIerode(mri_seg, mri_seg); - } else { + } + else { GCAbuildMostLikelyVolumeForStructure(gca, mri_seg, l, 0, transform, NULL); } mri_aligned = MRIerode(mri_seg, NULL); @@ -19451,7 +19831,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, HISTOplot(h_gca, fname); } } - } else { + } + else { printf("overlap = %g, overlap_threshold = %g\n", overlap, overlap_threshold); printf("insufficient overlap %2.4f in histograms - rejecting\n", overlap); } @@ -19491,7 +19872,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, upper_thresh); label_scales[l] = 1.0; label_offsets[l] = 1.0; - } else { + } + else { label_peaks[l] = label_peaks[l] * label_scales[l] + label_offsets[l]; if (logfp) { @@ -19544,7 +19926,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, upper_thresh); label_scales[l] = 1.0; label_offsets[l] = 1.0; - } else { + } + else { label_peaks[l] = label_peaks[l] * label_scales[l] + label_offsets[l]; if (logfp) { @@ -19644,7 +20027,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, label_scales[rhl], label_offsets[rhl], label_peaks[rhl]); - } else if (computed[rh_labels[k]] && !computed[lh_labels[k]]) { + } + else if (computed[rh_labels[k]] && !computed[lh_labels[k]]) { lhl = lh_labels[k]; rhl = rh_labels[k]; label_scales[lhl] = label_scales[rhl]; @@ -19675,7 +20059,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, if (num == 0) { mean_gm_scale = 1; mean_gm_offset = 0; - } else { + } + else { mean_gm_scale /= (float)num; mean_gm_offset /= (float)num; } @@ -19694,7 +20079,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, if (num == 0) { mean_wm_scale = 1; mean_wm_offset = 0; - } else { + } + else { mean_wm_scale /= (float)num; mean_wm_offset /= (float)num; } @@ -19713,7 +20099,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, if (num == 0) { mean_csf_scale = 1; mean_csf_offset = 0; - } else { + } + else { mean_csf_scale /= (float)num; mean_csf_offset /= (float)num; } @@ -19808,11 +20195,13 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, label_scales[l] = mean_csf_scale; label_offsets[l] = mean_csf_offset; computed[l] = 1; - } else if (equiv_class[l] == 2) { + } + else if (equiv_class[l] == 2) { label_scales[l] = mean_wm_scale; label_offsets[l] = mean_wm_offset; computed[l] = 1; - } else if (equiv_class[l] == 3) { + } + else if (equiv_class[l] == 3) { label_scales[l] = mean_gm_scale; label_offsets[l] = mean_gm_offset; computed[l] = 1; @@ -20154,7 +20543,8 @@ int GCAcomputeRenormalizationWithAlignmentLongitudinal(GCA *gca, return (NO_ERROR); } -int GCAapplyRenormalization(GCA *gca, float *label_scales, float *label_offsets, int frame) { +int GCAapplyRenormalization(GCA *gca, float *label_scales, float *label_offsets, int frame) +{ int xn, yn, zn, l, i; GCA_NODE *gcan; GC1D *gc; @@ -20237,7 +20627,8 @@ int GCAapplyRenormalization(GCA *gca, float *label_scales, float *label_offsets, // other side of the other if ((fabs(delta_j) > fabs(delta_i)) && !FZERO(delta_j)) { delta_j /= fabs(delta_j); // make it +-1 - } else if (!FZERO(delta_i)) { + } + else if (!FZERO(delta_i)) { delta_i /= fabs(delta_i); // make it +-1 } } @@ -20300,7 +20691,8 @@ int GCAapplyRenormalization(GCA *gca, float *label_scales, float *label_offsets, } static float pthresh = 0.5; -int GCAmapRenormalize(GCA *gca, MRI *mri, TRANSFORM *transform) { +int GCAmapRenormalize(GCA *gca, MRI *mri, TRANSFORM *transform) +{ HISTOGRAM *h, *hsmooth; int l, xp, yp, zp, nbins, i, x, y, z, xn, yn, zn, num, frame, bin; float fmin, fmax, prior, label_scales[MAX_CMA_LABELS], label_modes[MAX_CMA_LABELS], modes[MAX_GCA_INPUTS], std, peak, @@ -20386,7 +20778,8 @@ int GCAmapRenormalize(GCA *gca, MRI *mri, TRANSFORM *transform) { bin = nint((val - fmin) / h->bin_size); if (bin >= h->nbins) { bin = h->nbins - 1; - } else if (bin < 0) { + } + else if (bin < 0) { bin = 0; } @@ -20587,7 +20980,8 @@ int GCAmapRenormalize(GCA *gca, MRI *mri, TRANSFORM *transform) { // other side of the other if ((fabs(delta_j) > fabs(delta_i)) && !FZERO(delta_j)) { delta_j /= fabs(delta_j); // make it +-1 - } else if (!FZERO(delta_i)) { + } + else if (!FZERO(delta_i)) { delta_i /= fabs(delta_i); // make it +-1 } } @@ -20663,7 +21057,8 @@ int GCAmapRenormalize(GCA *gca, MRI *mri, TRANSFORM *transform) { return (NO_ERROR); } -int GCAmapRenormalizeByClass(GCA *gca, MRI *mri, TRANSFORM *transform) { +int GCAmapRenormalizeByClass(GCA *gca, MRI *mri, TRANSFORM *transform) +{ HISTOGRAM *h, *hsmooth; int l, nbins, i, x, y, z, max_p_label, xn, yn, zn, num, frame, bin, n, label, c, max_label; float fmin, fmax, prior, label_scales[MAX_CMA_LABELS], class_modes[NTISSUE_CLASSES], class_scales[NTISSUE_CLASSES], @@ -20768,7 +21163,8 @@ int GCAmapRenormalizeByClass(GCA *gca, MRI *mri, TRANSFORM *transform) { bin = nint((val - fmin) / h->bin_size); if (bin >= h->nbins) { bin = h->nbins - 1; - } else if (bin < 0) { + } + else if (bin < 0) { bin = 0; } @@ -20875,11 +21271,14 @@ int GCAmapRenormalizeByClass(GCA *gca, MRI *mri, TRANSFORM *transform) { if (IS_GRAY_CLASS(l)) { label_scales[l] = class_scales[GM_CLASS]; - } else if (IS_CSF_CLASS(l)) { + } + else if (IS_CSF_CLASS(l)) { label_scales[l] = class_scales[CSF_CLASS]; - } else if (IS_WHITE_CLASS(l)) { + } + else if (IS_WHITE_CLASS(l)) { label_scales[l] = class_scales[WM_CLASS]; - } else + } + else switch (l) { case Right_VentralDC: case Left_VentralDC: @@ -21027,7 +21426,8 @@ int GCAmapRenormalizeByClass(GCA *gca, MRI *mri, TRANSFORM *transform) { #define NLABELS 4 static int labels[NLABELS] = {Dura, Bone, SC_FAT_MUSCLE, CSF_SA}; -MRI *GCArelabelNonbrain(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform) { +MRI *GCArelabelNonbrain(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, TRANSFORM *transform) +{ int x, y, z, xn, yn, zn, width, height, depth, label, i, total_changed = 0, n, nchanged; int max_i = 0; GC1D *gcs[NLABELS]; @@ -21273,7 +21673,8 @@ MRI *GCArelabelNonbrain(GCA *gca, MRI *mri_inputs, MRI *mri_src, MRI *mri_dst, T return (mri_dst); } -int GCAreplaceLabels(GCA *gca, int in_label, int out_label) { +int GCAreplaceLabels(GCA *gca, int in_label, int out_label) +{ int x, y, z, n; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -21308,7 +21709,8 @@ int GCAreplaceLabels(GCA *gca, int in_label, int out_label) { return (NO_ERROR); } -int GCAreplaceRightWithLeft(GCA *gca) { +int GCAreplaceRightWithLeft(GCA *gca) +{ GCAreplaceLabels(gca, Right_Cerebral_Exterior, Left_Cerebral_Exterior); GCAreplaceLabels(gca, Right_Cerebral_White_Matter, Left_Cerebral_White_Matter); GCAreplaceLabels(gca, Right_Cerebral_Cortex, Left_Cerebral_Cortex); @@ -21334,7 +21736,8 @@ int GCAreplaceRightWithLeft(GCA *gca) { return (NO_ERROR); } -GCA_NODE *GCAbuildRegionalGCAN(const GCA *gca, int xn, int yn, int zn, int wsize) { +GCA_NODE *GCAbuildRegionalGCAN(const GCA *gca, int xn, int yn, int zn, int wsize) +{ GCA_NODE *gcan, *gcan_nbr; GCA_PRIOR *gcap; int n, xi, yi, zi, xk, yk, zk, nlabels = 0, whalf, xp, yp, zp, label, total_training[MAX_CMA_LABELS + 1], @@ -21420,7 +21823,8 @@ GCA_NODE *GCAbuildRegionalGCAN(const GCA *gca, int xn, int yn, int zn, int wsize VectorFree(&v_tmp); return (gcan); } -GCA_PRIOR *GCAbuildRegionalGCAP(const GCA *gca, int xp, int yp, int zp, int wsize) { +GCA_PRIOR *GCAbuildRegionalGCAP(const GCA *gca, int xp, int yp, int zp, int wsize) +{ GCA_PRIOR *gcap, *gcap_nbr; int n, xi, yi, zi, xk, yk, zk, nlabels = 0, whalf, label, total_training[MAX_CMA_LABELS + 1], used[MAX_CMA_LABELS + 1]; @@ -21485,7 +21889,8 @@ GCA_PRIOR *GCAbuildRegionalGCAP(const GCA *gca, int xp, int yp, int zp, int wsiz return (gcap); } -int GCAfreeRegionalGCAN(GCA_NODE **pgcan) { +int GCAfreeRegionalGCAN(GCA_NODE **pgcan) +{ GCA_NODE *gcan; gcan = *pgcan; @@ -21496,7 +21901,8 @@ int GCAfreeRegionalGCAN(GCA_NODE **pgcan) { return (NO_ERROR); } -GCA *GCAcompactify(GCA *gca) { +GCA *GCAcompactify(GCA *gca) +{ int width, height, depth; GCA_PRIOR *gcap = 0; GCA_NODE *gcan = 0; @@ -21603,7 +22009,8 @@ GCA *GCAcompactify(GCA *gca) { } MRI *GCAreplaceImpossibleLabels( - MRI *mri_inputs, GCA *gca, MRI *mri_in_labels, MRI *mri_out_labels, TRANSFORM *transform) { + MRI *mri_inputs, GCA *gca, MRI *mri_in_labels, MRI *mri_out_labels, TRANSFORM *transform) +{ int x, y, z, width, height, depth, label, xn, yn, zn, n, found, nchanged; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -21666,7 +22073,8 @@ MRI *GCAreplaceImpossibleLabels( return (mri_out_labels); } -double compute_partial_volume_log_posterior(GCA *gca, GCA_NODE *gcan, GCA_PRIOR *gcap, float *vals, int l1, int l2) { +double compute_partial_volume_log_posterior(GCA *gca, GCA_NODE *gcan, GCA_PRIOR *gcap, float *vals, int l1, int l2) +{ GC1D *gc1, *gc2; int i; double p1, p2, p, alpha, u, v, p_alpha, dist; @@ -21675,7 +22083,8 @@ double compute_partial_volume_log_posterior(GCA *gca, GCA_NODE *gcan, GCA_PRIOR for (i = 0; i < gcan->nlabels; i++) { if (gcan->labels[i] == l1) { gc1 = &gcan->gcs[i]; - } else if (gcan->labels[i] == l2) { + } + else if (gcan->labels[i] == l2) { gc2 = &gcan->gcs[i]; } } @@ -21687,7 +22096,8 @@ double compute_partial_volume_log_posterior(GCA *gca, GCA_NODE *gcan, GCA_PRIOR for (i = 0; i < gcap->nlabels; i++) { if (gcap->labels[i] == l1) { p1 = gcap->priors[i]; - } else if (gcap->labels[i] == l2) { + } + else if (gcap->labels[i] == l2) { p2 = gcap->priors[i]; } } @@ -21703,7 +22113,8 @@ double compute_partial_volume_log_posterior(GCA *gca, GCA_NODE *gcan, GCA_PRIOR return (log(p)); } -static int gcaRelabelSegment(GCA *gca, TRANSFORM *transform, MRI *mri_inputs, MRI *mri_dst, MRI_SEGMENT *mseg) { +static int gcaRelabelSegment(GCA *gca, TRANSFORM *transform, MRI *mri_inputs, MRI *mri_dst, MRI_SEGMENT *mseg) +{ int i, n, x, y, z, labels[MAX_CMA_LABEL + 1], label, max_label, old_label, debug = 0; double max_posterior, new_posterior; GCA_PRIOR *gcap; @@ -21773,7 +22184,8 @@ static int gcaRelabelSegment(GCA *gca, TRANSFORM *transform, MRI *mri_inputs, MR return (old_label != max_label); } -MRI *GCAmarkImpossible(GCA *gca, MRI *mri_labeled, MRI *mri_dst, TRANSFORM *transform) { +MRI *GCAmarkImpossible(GCA *gca, MRI *mri_labeled, MRI *mri_dst, TRANSFORM *transform) +{ int x, y, z, label; if (mri_dst == NULL) { @@ -21795,7 +22207,8 @@ MRI *GCAmarkImpossible(GCA *gca, MRI *mri_labeled, MRI *mri_dst, TRANSFORM *tran return (mri_dst); } -int GCAmaxLabel(GCA *gca) { +int GCAmaxLabel(GCA *gca) +{ int x, y, z, max_label, n; GCA_PRIOR *gcap; @@ -21816,7 +22229,8 @@ int GCAmaxLabel(GCA *gca) { } MRI *GCAbuildMostLikelyVolumeForStructure( - const GCA *gca, MRI *mri, int label, int border, TRANSFORM *transform, MRI *mri_labels) { + const GCA *gca, MRI *mri, int label, int border, TRANSFORM *transform, MRI *mri_labels) +{ int z, width, depth, height; MRI *mri_tmp; MRI_SEGMENTATION *mriseg; @@ -21914,12 +22328,14 @@ MRI *GCAbuildMostLikelyVolumeForStructure( for (r = 0; r < gca->ninputs; r++) { MRIsetVoxVal(mri, x, y, z, r, gc_max->means[r]); } - } else { + } + else { for (r = 0; r < gca->ninputs; r++) { MRIsetVoxVal(mri, x, y, z, r, 0); } } - } else { + } + else { for (r = 0; r < gca->ninputs; r++) { MRIsetVoxVal(mri, x, y, z, r, 0); } @@ -21934,7 +22350,8 @@ MRI *GCAbuildMostLikelyVolumeForStructure( "GCAmostLikelyVolumeForStructure: " "label %s segmentation failed", cma_label_to_name(label)); - } else if (mriseg->nsegments > 1) // use largest segment + } + else if (mriseg->nsegments > 1) // use largest segment { #if 0 MRI *mri_tmp ; @@ -22163,7 +22580,8 @@ gcaComputeHistogramNormalization(GCA *gca, HISTOGRAM *h_mri, int label) } #endif -static HISTOGRAM *gcaGetLabelHistogram(GCA *gca, int label, int frame, int border) { +static HISTOGRAM *gcaGetLabelHistogram(GCA *gca, int label, int frame, int border) +{ HISTOGRAM *h_gca; int zn, b; @@ -22214,7 +22632,8 @@ static HISTOGRAM *gcaGetLabelHistogram(GCA *gca, int label, int frame, int borde } #if INTERP_PRIOR -static float gcaComputePrior(GCA *gca, MRI *mri, TRANSFORM *transform, int x0, int y0, int z0, int label) { +static float gcaComputePrior(GCA *gca, MRI *mri, TRANSFORM *transform, int x0, int y0, int z0, int label) +{ double x, y, z, xmd, ymd, zmd, xpd, ypd, zpd, prior; int xm, ym, zm, xp, yp, zp; GCA_PRIOR *gcap; @@ -22276,7 +22695,8 @@ static float gcaComputePrior(GCA *gca, MRI *mri, TRANSFORM *transform, int x0, i #endif -static void set_equilavent_classes(int *equivalent_classes) { +static void set_equilavent_classes(int *equivalent_classes) +{ int i; for (i = 0; i < MAX_CMA_LABELS; i++) { @@ -22375,7 +22795,8 @@ static void set_equilavent_classes(int *equivalent_classes) { return; } -MRI *GCAbuildMostLikelyLabelVolume(GCA *gca, MRI *mri) { +MRI *GCAbuildMostLikelyLabelVolume(GCA *gca, MRI *mri) +{ /* this function creates a label volume and will be used to register a subject's manual label to it, as a way to get linear registration from the subject to the gca for gca training */ @@ -22434,10 +22855,12 @@ MRI *GCAbuildMostLikelyLabelVolume(GCA *gca, MRI *mri) { } } MRIsetVoxVal(mri, x, y, z, 0, max_label); - } else { + } + else { MRIsetVoxVal(mri, x, y, z, 0, 0); } - } else { + } + else { MRIsetVoxVal(mri, x, y, z, 0, 0); } } @@ -22447,7 +22870,8 @@ MRI *GCAbuildMostLikelyLabelVolume(GCA *gca, MRI *mri) { return (mri); } -MRI *GCAbuildMostLikelyLabelProbabilityVolume(GCA *gca) { +MRI *GCAbuildMostLikelyLabelProbabilityVolume(GCA *gca) +{ /* this function creates a label volume and will be used to register a subject's manual label to it, as a way to get linear registration from the subject to the gca for gca training */ @@ -22495,10 +22919,12 @@ MRI *GCAbuildMostLikelyLabelProbabilityVolume(GCA *gca) { } } MRIsetVoxVal(mri, x, y, z, 0, max_prior); - } else { + } + else { MRIsetVoxVal(mri, x, y, z, 0, 0); } - } else { + } + else { MRIsetVoxVal(mri, x, y, z, 0, 0); } } @@ -22508,7 +22934,8 @@ MRI *GCAbuildMostLikelyLabelProbabilityVolume(GCA *gca) { return (mri); } -int GCAcomputeLabelMeansAndCovariances(GCA *gca, int target_label, MATRIX **p_mcov, VECTOR **p_vmeans) { +int GCAcomputeLabelMeansAndCovariances(GCA *gca, int target_label, MATRIX **p_mcov, VECTOR **p_vmeans) +{ int x, y, z, n, r; double var, dof, total_dof; GC1D *gc; @@ -22565,7 +22992,8 @@ int GCAcomputeLabelMeansAndCovariances(GCA *gca, int target_label, MATRIX **p_mc #define WSIZE 5 #define WHALF ((WSIZE - 1) / 2) -static double compute_conditional_density(MATRIX *m_inv_cov, VECTOR *v_means, VECTOR *v_vals) { +static double compute_conditional_density(MATRIX *m_inv_cov, VECTOR *v_means, VECTOR *v_vals) +{ double p, dist, det; int ninputs; @@ -22577,7 +23005,8 @@ static double compute_conditional_density(MATRIX *m_inv_cov, VECTOR *v_means, VE return (p); } -static int load_val_vector(VECTOR *v_means, MRI *mri_inputs, int x, int y, int z) { +static int load_val_vector(VECTOR *v_means, MRI *mri_inputs, int x, int y, int z) +{ int n; for (n = 0; n < mri_inputs->nframes; n++) { @@ -22586,7 +23015,8 @@ static int load_val_vector(VECTOR *v_means, MRI *mri_inputs, int x, int y, int z return (NO_ERROR); } -MRI *GCAlabelWMandWMSAs(GCA *gca, MRI *mri_inputs, MRI *mri_src_labels, MRI *mri_dst_labels, TRANSFORM *transform) { +MRI *GCAlabelWMandWMSAs(GCA *gca, MRI *mri_inputs, MRI *mri_src_labels, MRI *mri_dst_labels, TRANSFORM *transform) +{ int h, wm_label, wmsa_label, x, y, z, label, nwm, nwmsa, nunknown, ngm, ncaudate, caudate_label, gm_label, n, found, i, NotWMSA; MATRIX *m_cov_wm, *m_cov_wmsa, *m_inv_cov_wmsa, *m_inv_cov_wm, *m_I, *m_cov_un, *m_inv_cov_un; @@ -22608,7 +23038,8 @@ MRI *GCAlabelWMandWMSAs(GCA *gca, MRI *mri_inputs, MRI *mri_src_labels, MRI *mri wmsa_label = Left_WM_hypointensities; caudate_label = Left_Caudate; gm_label = Left_Cerebral_Cortex; - } else { + } + else { wm_label = Right_Cerebral_White_Matter; wmsa_label = Right_WM_hypointensities; caudate_label = Right_Caudate; @@ -22675,7 +23106,8 @@ MRI *GCAlabelWMandWMSAs(GCA *gca, MRI *mri_inputs, MRI *mri_src_labels, MRI *mri if (nwm + nwmsa + nunknown < 0.9 * WSIZE * WSIZE * WSIZE) { continue; } - } else if (nwm + nwmsa < .9 * WSIZE * WSIZE * WSIZE) + } + else if (nwm + nwmsa < .9 * WSIZE * WSIZE * WSIZE) // somewhat arbitrary - the bulk of the nbhd { continue; @@ -22802,7 +23234,8 @@ MRI *GCAlabelWMandWMSAs(GCA *gca, MRI *mri_inputs, MRI *mri_src_labels, MRI *mri for (n = 0; n < mri_inputs->nframes; n++) if (fabs(VECTOR_ELT(v_dif_wmsa, n + 1)) >= fabs(VECTOR_ELT(v_dif_label, n + 1))) NotWMSA = 1; if (!NotWMSA) label = wmsa_label; - } else if (label == wm_label) { + } + else if (label == wm_label) { VectorSubtract(v_vals, v_mean_wm, v_dif_label); if (x == Ggca_x && y == Ggca_y && z == Ggca_z) printf( @@ -22814,7 +23247,8 @@ MRI *GCAlabelWMandWMSAs(GCA *gca, MRI *mri_inputs, MRI *mri_src_labels, MRI *mri for (n = 0; n < mri_inputs->nframes; n++) if (fabs(VECTOR_ELT(v_dif_wmsa, n + 1)) >= fabs(VECTOR_ELT(v_dif_label, n + 1))) NotWMSA = 1; if (!NotWMSA || (wmsa_dist * 3 < wm_dist)) label = wmsa_label; - } else if (label == Unknown) { + } + else if (label == Unknown) { VectorSubtract(v_vals, v_mean_un, v_dif_label); if (x == Ggca_x && y == Ggca_y && z == Ggca_z) printf( @@ -22853,7 +23287,8 @@ MRI *GCAlabelWMandWMSAs(GCA *gca, MRI *mri_inputs, MRI *mri_src_labels, MRI *mri #undef WSIZE #endif #define WSIZE 7 -static MRI *expand_ventricle(MRI *mri_src, MRI *mri, MRI *mri_dst, float thresh, int nvox_thresh, int xdir) { +static MRI *expand_ventricle(MRI *mri_src, MRI *mri, MRI *mri_dst, float thresh, int nvox_thresh, int xdir) +{ int nfilled, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, nvox, prev_nfilled, iter = 0; MRI_REGION box; MRI *mri_tmp = NULL; @@ -22870,7 +23305,8 @@ static MRI *expand_ventricle(MRI *mri_src, MRI *mri, MRI *mri_dst, float thresh, if (xdir > 0) { xmin = MAX(0, box.x); xmax = MIN(mri->width - 1, box.x + box.dx); // expand by 1 - } else { + } + else { xmin = MAX(0, box.x - 1); xmax = MIN(mri->width - 1, box.x + box.dx - 1); } @@ -22912,14 +23348,16 @@ static MRI *expand_ventricle(MRI *mri_src, MRI *mri, MRI *mri_dst, float thresh, MRIfree(&mri_tmp); return (mri_dst); } -static MRI *fill_ventricles(MRI *mri_seg, MRI *mri, int border, MRI *mri_dst, int label) { +static MRI *fill_ventricles(MRI *mri_seg, MRI *mri, int border, MRI *mri_dst, int label) +{ int i, left; float fmin, fmax; for (i = 0; i < border + 2; i++) { if (i == 0) { mri_dst = MRIerode(mri_seg, mri_dst); - } else { + } + else { MRIerode(mri_dst, mri_dst); } } @@ -22932,7 +23370,8 @@ static MRI *fill_ventricles(MRI *mri_seg, MRI *mri, int border, MRI *mri_dst, in return (mri_dst); } -static int initialize_ventricle_alignment(MRI *mri_seg, MRI *mri, MATRIX *m_L, char *base_name, int border, int label) { +static int initialize_ventricle_alignment(MRI *mri_seg, MRI *mri, MATRIX *m_L, char *base_name, int border, int label) +{ MRI *mri_vent, *mri_vent_dist, *mri_gca_vent, *mri_gca_vent_dist, *mri_mask; MRI_REGION box; @@ -23018,7 +23457,8 @@ static int initialize_ventricle_alignment(MRI *mri_seg, MRI *mri, MATRIX *m_L, c FreeSurferLUT.txt is loaded and the names are extracted rather than using those in cma.h. -------------------------------------------------------------------------*/ -COLOR_TABLE *GCAcolorTableCMA(GCA *gca) { +COLOR_TABLE *GCAcolorTableCMA(GCA *gca) +{ int nl, n, c, r, s, nmax; int labelhitlist[1000]; // probably only need 256 COLOR_TABLE *ct, *ct0; @@ -23079,7 +23519,8 @@ COLOR_TABLE *GCAcolorTableCMA(GCA *gca) { // use the names from FreeSurferColorLUT.txt. sprintf(ct->entries[n]->name, "%s", ct0->entries[n]->name); // printf("%d %s %s\n", n,cma_label_to_name(n),ct->entries[n]->name); - } else { + } + else { // If this index is not represented, then free and NULL // its entry. free(ct->entries[n]); @@ -23090,7 +23531,8 @@ COLOR_TABLE *GCAcolorTableCMA(GCA *gca) { return (ct); } #if 1 -double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform, int penalize_zero_brain, MRI *mri_orig) { +double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform, int penalize_zero_brain, MRI *mri_orig) +{ int x, y, z, xn, yn, zn, label, xp, yp, zp, num, nz, nout, n; GCA_PRIOR *gcap; GC1D *gc; @@ -23194,7 +23636,8 @@ double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform, in nz++; log_p += min_log_p; } - } else { + } + else { log_p += min_log_p; nz++; } @@ -23221,7 +23664,8 @@ double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform, in return (total_log_p / (double)num); } #else -double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) { +double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) +{ int x, y, z, width, height, depth, xn, yn, zn, n, label /*, found*/, xp, yp, zp; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -23250,17 +23694,20 @@ double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) { GCAsourceVoxelToNode(gca, mri_inputs, transform, x, y, z, &xn, &yn, &zn); if (xn < 0) { xn = 0; - } else if (xn >= gca->node_width) { + } + else if (xn >= gca->node_width) { xn = gca->node_width - 1; } if (yn < 0) { yn = 0; - } else if (yn >= gca->node_height) { + } + else if (yn >= gca->node_height) { yn = gca->node_height - 1; } if (zn < 0) { zn = 0; - } else if (zn >= gca->node_depth) { + } + else if (zn >= gca->node_depth) { zn = gca->node_depth - 1; } @@ -23268,23 +23715,27 @@ double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) { GCAsourceVoxelToPrior(gca, mri_inputs, transform, x, y, z, &xp, &yp, &zp); if (xp < 0) { xp = 0; - } else if (xp >= gca->prior_width) { + } + else if (xp >= gca->prior_width) { xp = gca->prior_width - 1; } if (yp < 0) { yp = 0; - } else if (yp >= gca->prior_height) { + } + else if (yp >= gca->prior_height) { yp = gca->prior_height - 1; } if (zp < 0) { zp = 0; - } else if (zp >= gca->prior_depth) { + } + else if (zp >= gca->prior_depth) { zp = gca->prior_depth - 1; } gcap = &gca->priors[xp][yp][zp]; if (gcap == NULL || gcan->nlabels == 1) { label = gcan->labels[0]; - } else { + } + else { label = gcaMaxPriorLabel(gca, mri_inputs, transform, x, y, z); } for (n = 0; n < gcan->nlabels; n++) { @@ -23294,7 +23745,8 @@ double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) { } if (n < gcan->nlabels) { gc = &gcan->gcs[n]; - } else { + } + else { gc = GCAfindClosestValidGC(gca, xn, yn, zn, label, 0); } @@ -23371,7 +23823,8 @@ double GCAimageLogLikelihood(GCA *gca, MRI *mri_inputs, TRANSFORM *transform) { } #endif -MRI *GCAcomputeLikelihoodImage(GCA *gca, MRI *mri_inputs, MRI *mri_labeled, TRANSFORM *transform) { +MRI *GCAcomputeLikelihoodImage(GCA *gca, MRI *mri_inputs, MRI *mri_labeled, TRANSFORM *transform) +{ int x, y, z, label; double likelihood; float vals[MAX_GCA_INPUTS]; @@ -23397,7 +23850,8 @@ MRI *GCAcomputeLikelihoodImage(GCA *gca, MRI *mri_inputs, MRI *mri_labeled, TRAN return (mri_likelihood); } #if 1 -static int gcaMaxPriorLabel(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { +static int gcaMaxPriorLabel(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) +{ int n, max_label; GCA_PRIOR *gcap; float maxp; @@ -23475,7 +23929,8 @@ static int compute_posterior_scale_change(GCA *gca, int *contra_labels, float *scales, int nlabels, - float step_size) { + float step_size) +{ float dk[NUM_ENTROPY_LABELS]; double prior, plike, dist; int x, y, z, xn, yn, zn, l, num[NUM_ENTROPY_LABELS], ind; @@ -23543,7 +23998,8 @@ static int compute_posterior_scale_change(GCA *gca, } return (NO_ERROR); } -int GCArenormalizeWithEntropyMinimization(GCA *gca, MRI *mri, TRANSFORM *transform, FILE *logfp) { +int GCArenormalizeWithEntropyMinimization(GCA *gca, MRI *mri, TRANSFORM *transform, FILE *logfp) +{ float scales[NUM_ENTROPY_LABELS], ll, last_posterior, peaks[NUM_ENTROPY_LABELS], contra_peaks[NUM_CONTRA_LABELS], pct_change, last_scales[NUM_ENTROPY_LABELS]; int i, done = 0, peak_bin; @@ -23769,7 +24225,8 @@ GCAcomputeScaledMeanEntropy(GCA *gca, return(-entropy_total/num) ; } #endif -double GCAcomputeMeanEntropy(GCA *gca, MRI *mri, TRANSFORM *transform) { +double GCAcomputeMeanEntropy(GCA *gca, MRI *mri, TRANSFORM *transform) +{ double entropy, entropy_total, p[MAX_LABELS_PER_GCAN], ptotal, max_p; int x, y, z, c, xn, yn, zn, num, max_c; GCA_PRIOR *gcap; @@ -23826,7 +24283,8 @@ double GCAcomputeMeanEntropy(GCA *gca, MRI *mri, TRANSFORM *transform) { return (-entropy_total / num); } -static int gcaScale(GCA *gca, int *labels, int *contra_labels, float *scales, int nlabels, int dir) { +static int gcaScale(GCA *gca, int *labels, int *contra_labels, float *scales, int nlabels, int dir) +{ int label_indices[MAX_CMA_LABEL + 1], x, y, z, n, label, ind, i; GC1D *gc; GCA_NODE *gcan; @@ -23855,7 +24313,8 @@ static int gcaScale(GCA *gca, int *labels, int *contra_labels, float *scales, in for (i = 0; i < gca->ninputs; i++) { if (dir > 0) { gc->means[i] *= scale; - } else { + } + else { gc->means[i] /= scale; } } @@ -23866,7 +24325,8 @@ static int gcaScale(GCA *gca, int *labels, int *contra_labels, float *scales, in return (NO_ERROR); } -int GCAgetMaxPriorLabelAtVoxel(GCA *gca, MRI *mri, int x, int y, int z, TRANSFORM *transform, double *p_prior) { +int GCAgetMaxPriorLabelAtVoxel(GCA *gca, MRI *mri, int x, int y, int z, TRANSFORM *transform, double *p_prior) +{ int xp, yp, zp; Real xpf, ypf, zpf; @@ -23882,12 +24342,14 @@ int GCAgetMaxPriorLabelAtVoxel(GCA *gca, MRI *mri, int x, int y, int z, TRANSFOR return (-1); } -int GCAgetMaxPriorLabel(GCA *gca, int xp, int yp, int zp, double *p_prior) { +int GCAgetMaxPriorLabel(GCA *gca, int xp, int yp, int zp, double *p_prior) +{ GCA_PRIOR *gcap; gcap = &gca->priors[xp][yp][zp]; return (gcapGetMaxPriorLabel(gcap, p_prior)); } -static int gcapGetMaxPriorLabel(GCA_PRIOR *gcap, double *p_prior) { +static int gcapGetMaxPriorLabel(GCA_PRIOR *gcap, double *p_prior) +{ int n, best_label = 0; float max_p; @@ -23926,7 +24388,8 @@ gcapBrainIsPossible(GCA_PRIOR *gcap) return(possible) ; } #endif -float GCAcomputeLabelPosterior(GCA *gca, TRANSFORM *transform, MRI *mri, float x, float y, float z, int label) { +float GCAcomputeLabelPosterior(GCA *gca, TRANSFORM *transform, MRI *mri, float x, float y, float z, int label) +{ float p, plabel, vals[MAX_GCA_INPUTS], ptotal; GCA_PRIOR *gcap; int n, olabel; @@ -23939,7 +24402,8 @@ float GCAcomputeLabelPosterior(GCA *gca, TRANSFORM *transform, MRI *mri, float x if (gcap->total_training > 0) { plabel = .01 / gcap->total_training; - } else { + } + else { plabel = 0.0; } for (ptotal = 0.0, n = 0; n < gcap->nlabels; n++) { @@ -23958,7 +24422,8 @@ float GCAcomputeLabelPosterior(GCA *gca, TRANSFORM *transform, MRI *mri, float x return (plabel); } -float GCAcomputeLabelLikelihood(GCA *gca, TRANSFORM *transform, MRI *mri, float x, float y, float z, int label) { +float GCAcomputeLabelLikelihood(GCA *gca, TRANSFORM *transform, MRI *mri, float x, float y, float z, int label) +{ float p, plabel, vals[MAX_GCA_INPUTS], ptotal; GCA_PRIOR *gcap; int n, olabel, found = 0; @@ -23970,7 +24435,8 @@ float GCAcomputeLabelLikelihood(GCA *gca, TRANSFORM *transform, MRI *mri, float if (gcap->total_training > 0) { plabel = .01 / gcap->total_training; - } else { + } + else { plabel = 0.0; } for (ptotal = 0.0, n = 0; n < gcap->nlabels; n++) { @@ -23996,7 +24462,8 @@ float GCAcomputeLabelLikelihood(GCA *gca, TRANSFORM *transform, MRI *mri, float gc = GCAfindClosestValidGC(gca, xn, yn, zn, label, 0); if (gc == NULL) { DiagBreak(); - } else { + } + else { load_vals(mri, x, y, z, vals, gca->ninputs); plabel = GCAcomputeConditionalDensity(gc, vals, gca->ninputs, label); ptotal += plabel; @@ -24010,7 +24477,8 @@ float GCAcomputeLabelLikelihood(GCA *gca, TRANSFORM *transform, MRI *mri, float return (plabel); } -int GCAstructureBoundingBox(GCA *gca, int label, MRI_REGION *box) { +int GCAstructureBoundingBox(GCA *gca, int label, MRI_REGION *box) +{ int x, y, z, xmin, ymin, zmin, xmax, ymax, zmax, n; GCA_PRIOR *gcap; @@ -24060,7 +24528,8 @@ int GCAstructureBoundingBox(GCA *gca, int label, MRI_REGION *box) { box->dz = zmax - zmin + 1; return (NO_ERROR); } -int GCArenormalizeClass(GCA *gca, int class, float scale_to_wm) { +int GCArenormalizeClass(GCA *gca, int class, float scale_to_wm) +{ float wm_mode, class_mode, scale; int x, y, z, n, same_class, r; GCA_NODE *gcan; @@ -24115,7 +24584,8 @@ int GCArenormalizeClass(GCA *gca, int class, float scale_to_wm) { } static int nbr_labels[GIBBS_NEIGHBORS][MAX_CMA_LABELS][MAX_CMA_LABELS]; -static GCA_NODE *gcaBuildNbhdGCAN(GCA *gca, int x, int y, int z, int wsize, float sigma) { +static GCA_NODE *gcaBuildNbhdGCAN(GCA *gca, int x, int y, int z, int wsize, float sigma) +{ GCA_NODE *gcan, *gcan_total; int labels[MAX_CMA_LABELS], n, xi, yi, zi, xk, yk, zk, whalf, nlabels, n2, n3, n4, r, c, v, i; GC1D *gc, *gc_total; @@ -24249,7 +24719,8 @@ static GCA_NODE *gcaBuildNbhdGCAN(GCA *gca, int x, int y, int z, int wsize, floa for (i = 0; i < GIBBS_NEIGHBORS; i++) { if (gc_total->nlabels[i] == 0) { DiagBreak(); - } else { + } + else { gc_total->labels[i] = (unsigned short *)calloc(gc_total->nlabels[i], sizeof(short)); if (gc_total->labels[i] == NULL) ErrorExit(ERROR_NOMEMORY, "gcaBuildNbhdGCAN: could not allocate %d:%d labels", gc_total->nlabels[i], i); @@ -24263,7 +24734,8 @@ static GCA_NODE *gcaBuildNbhdGCAN(GCA *gca, int x, int y, int z, int wsize, floa if (nbr_labels[i][gcan_total->labels[n]][n2]) { if (nlabels >= gc_total->nlabels[i]) { DiagBreak(); - } else { + } + else { gc_total->labels[i][nlabels++] = n2; // label n2 is nbr in position i } } @@ -24349,7 +24821,8 @@ static GCA_NODE *gcaBuildNbhdGCAN(GCA *gca, int x, int y, int z, int wsize, floa for (c = r; c < gca->ninputs; c++, v++) { if (gc_total->ntraining == 0) { DiagBreak(); - } else { + } + else { gc_total->covars[v] /= gc_training[n]; } } @@ -24388,7 +24861,8 @@ static GCA_NODE *gcaBuildNbhdGCAN(GCA *gca, int x, int y, int z, int wsize, floa return (gcan_total); } -static GCA_PRIOR *gcaBuildNbhdGCAP(GCA *gca, int x, int y, int z, int wsize, float sigma, GCA *gca_smooth) { +static GCA_PRIOR *gcaBuildNbhdGCAP(GCA *gca, int x, int y, int z, int wsize, float sigma, GCA *gca_smooth) +{ GCA_PRIOR *gcap, *gcap_total; int labels[MAX_CMA_LABELS], n, xi, yi, zi, xk, yk, zk, whalf, nlabels, n2; double norm, wt, two_sigma_sq, dsq, total_wt, total_training; @@ -24589,7 +25063,8 @@ static GCA_PRIOR *gcaBuildNbhdGCAP(GCA *gca, int x, int y, int z, int wsize, flo return (gcap_total); } -GC1D *gcanGetGC(GCA_NODE *gcan, int label) { +GC1D *gcanGetGC(GCA_NODE *gcan, int label) +{ int n; GC1D *gc = NULL; @@ -24608,7 +25083,8 @@ MRI *GCAreclassifyUnlikelyVoxels(GCA *gca, MRI *mri_aseg_changed, float mah_dist_thresh, int wsize, - float sigma) { + float sigma) +{ int x, y, z, max_label, nchanged, iter = 0; GCA_NODE *gcan_total, *gcan; GCA_PRIOR *gcap_total, *gcap; @@ -24738,7 +25214,8 @@ static double gcaGibbsLogPosterior(GCA *gca, int z, GCA_PRIOR *gcap, GCA_NODE *gcan, - TRANSFORM *transform) { + TRANSFORM *transform) +{ double log_posterior, nbr_prior; int xnbr, ynbr, znbr, nbr_label, i, j, n; GC1D *gc = 0; @@ -24786,12 +25263,14 @@ static double gcaGibbsLogPosterior(GCA *gca, if (j < gc->nlabels[i]) { if (!FZERO(gc->label_priors[i][j])) { nbr_prior += log(gc->label_priors[i][j]); - } else { + } + else { nbr_prior += log(0.1f / (float)gcan->total_training); } /*BIG_AND_NEGATIVE */ check_finite("gcaGibbsLogPosterior: label_priors", nbr_prior); - } else /* never occurred - make it unlikely */ + } + else /* never occurred - make it unlikely */ { if (x == Ggca_x && y == Ggca_y && z == Ggca_z) { DiagBreak(); @@ -24821,7 +25300,8 @@ MRI *GCAcomputeOptimalScale(GCA *gca, int wsize, double min_sigma, double max_sigma, - double delta_sigma) { + double delta_sigma) +{ int x, y, z; GCA_NODE *gcan_total; GCA_PRIOR *gcap_total; @@ -24895,7 +25375,8 @@ MRI *GCAcomputeOptimalScale(GCA *gca, return (mri_sigma); } MRI *GCAreclassifyVoxelsAtOptimalScale( - GCA *gca, TRANSFORM *transform, MRI *mri_inputs, MRI *mri_aseg, MRI *mri_aseg_changed, MRI *mri_sigma, int wsize) { + GCA *gca, TRANSFORM *transform, MRI *mri_inputs, MRI *mri_aseg, MRI *mri_aseg_changed, MRI *mri_sigma, int wsize) +{ int x, y, z, max_label, nchanged, iter = 0; GCA_NODE *gcan_total; GCA_PRIOR *gcap_total; @@ -24996,7 +25477,8 @@ MRI *GCAreclassifyVoxelsAtOptimalScale( MRIfree(&mri_changed); return (mri_aseg_changed); } -int GCAcheck(GCA *gca) { +int GCAcheck(GCA *gca) +{ int error, xp, yp, zp, n, xn, yn, zn, label; GCA_PRIOR *gcap; GC1D *gc; @@ -25030,7 +25512,8 @@ int GCAcheck(GCA *gca) { return (error); } -GCA *GCAcopy(GCA *gca_src, GCA *gca_dst) { +GCA *GCAcopy(GCA *gca_src, GCA *gca_dst) +{ if (gca_dst == NULL) gca_dst = GCAalloc(gca_src->ninputs, gca_src->prior_spacing, @@ -25055,7 +25538,8 @@ GCA *GCAcopy(GCA *gca_src, GCA *gca_dst) { memmove(gca_dst->TEs, gca_src->TEs, sizeof(gca_src->TEs)); return (gca_dst); } -GCA *GCAsmooth(GCA *gca, double sigma) { +GCA *GCAsmooth(GCA *gca, double sigma) +{ GCA_NODE *gcan_total, *gcan; GCA_PRIOR *gcap_total, *gcap; int xp, yp, zp, xn, yn, zn, wsize, n; @@ -25179,7 +25663,8 @@ GCA *GCAsmooth(GCA *gca, double sigma) { } return (gca_smooth); } -GCA *GCAnodeDownsample2(GCA *gca) { +GCA *GCAnodeDownsample2(GCA *gca) +{ GCA_NODE *gcan_total, *gcan; GCA_PRIOR *gcap_total, *gcap; int xp, yp, zp, xn, yn, zn, wsize, n, xn2, yn2, zn2; @@ -25310,7 +25795,8 @@ GCA *GCAnodeDownsample2(GCA *gca) { return (gca_smooth); } int GCAsourceVoxelToPriorReal( - GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, double *pxp, double *pyp, double *pzp) { + GCA *gca, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, double *pxp, double *pyp, double *pzp) +{ float xt, yt, zt; double xrt, yrt, zrt; int retval; @@ -25331,9 +25817,11 @@ int GCAsourceVoxelToPriorReal( zt = zrt*mri->zsize; #endif // TransformSample(transform, xv, yv, zv, &xt, &yt, &zt) ; - } else + } + else ErrorExit(ERROR_BADPARM, "GCAsourceVoxelToPrior: needs vox-to-vox transform"); - } else // morph 3d type can go directly from source to template + } + else // morph 3d type can go directly from source to template { // printf("GCAsourcevoxelToPriorReal: (xv,yv,zv) = (%d,%d,%d).\n", xv, yv, zv); TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); @@ -25387,7 +25875,8 @@ int GCAinsertLabels(GCA *gca, int *insert_labels, int *insert_intensities, int insert_coords[MAX_INSERTIONS][3], - int *insert_whalf) { + int *insert_whalf) +{ int xn, yn, zn, xp, yp, zp, i, l, label, x, y, z, found, n, whalf; int xk, yk, zk, xi, yi, zi; GCA_NODE *gcan; @@ -25564,7 +26053,8 @@ float GCAcomputeNumberOfGoodFittingSamples( fprintf(stdout, "total log p not finite at (%d, %d, %d)\n", x, y, z); DiagBreak(); } - } else // outside the volume + } + else // outside the volume { log_p = -1000000; // BIG_AND_NEGATIVE; // log(VERY_UNLIKELY); // BIG_AND_NEGATIVE; @@ -25588,7 +26078,8 @@ float GCAcomputeNumberOfGoodFittingSamples( return ((float)total_log_p); } -int GCAreadLabelIntensities(char *fname, float *label_scales, float *label_offsets) { +int GCAreadLabelIntensities(char *fname, float *label_scales, float *label_offsets) +{ FILE *fp; int l; char *cp, line[STRLEN]; @@ -25617,7 +26108,8 @@ int GCAreadLabelIntensities(char *fname, float *label_scales, float *label_offse return (NO_ERROR); } -int GCAremoveHemi(GCA *gca, int lh) { +int GCAremoveHemi(GCA *gca, int lh) +{ int x, y, z, n, r; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -25666,7 +26158,8 @@ int GCAremoveHemi(GCA *gca, int lh) { } gcap->nlabels = 1; gcap->labels[0] = Unknown; - } else { + } + else { for (n = 0; n < gcap->nlabels; n++) { if ((lh && (IS_LH_CLASS(gcap->labels[n]))) || (!lh && (IS_RH_CLASS(gcap->labels[n])))) { gcap->labels[n] = Unknown; @@ -25684,7 +26177,8 @@ int GCAremoveHemi(GCA *gca, int lh) { return (NO_ERROR); } -int GCAupdateDistributions(GCA *gca, MRI *mri, TRANSFORM *transform) { +int GCAupdateDistributions(GCA *gca, MRI *mri, TRANSFORM *transform) +{ int x, y, z, nvals, label, xv, yv, zv, n, node_label; float vals[MAX_GCA_INPUTS], *all_vals, med; GCA_NODE *gcan; @@ -25732,7 +26226,8 @@ int GCAupdateDistributions(GCA *gca, MRI *mri, TRANSFORM *transform) { return (NO_ERROR); } -int GCAremoveLabel(GCA *gca, int label) { +int GCAremoveLabel(GCA *gca, int label) +{ int x, y, z, n, r; GCA_NODE *gcan; GCA_PRIOR *gcap; @@ -25768,7 +26263,8 @@ int GCAremoveLabel(GCA *gca, int label) { return (NO_ERROR); } -int is_possible_wmsa(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z, int whalf) { +int is_possible_wmsa(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z, int whalf) +{ GCA_PRIOR *gcap; int xp, yp, zp, xi, yi, zi; float left_wmsa, right_wmsa, never_thresh, wmsa; @@ -25793,7 +26289,8 @@ int is_possible_wmsa(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int return (0); // wmsa has never occurred here } -double cortex_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { +double cortex_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) +{ GCA_PRIOR *gcap; int xp, yp, zp; float left_gm, right_gm; @@ -25808,7 +26305,8 @@ double cortex_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int return (left_gm + right_gm); } -double wm_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { +double wm_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) +{ GCA_PRIOR *gcap; int xp, yp, zp; float left_wm, right_wm, wmsa; @@ -25824,7 +26322,8 @@ double wm_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { return (left_wm + right_wm + wmsa); } -double csf_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { +double csf_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) +{ GCA_PRIOR *gcap; int xp, yp, zp, n; float prior; @@ -25842,7 +26341,8 @@ double csf_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) return (prior); } -double gm_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { +double gm_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) +{ GCA_PRIOR *gcap; int xp, yp, zp, n; float prior; @@ -25860,7 +26360,8 @@ double gm_prior(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { return (prior); } -int GCAisLeftHemisphere(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) { +int GCAisLeftHemisphere(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, int z) +{ GCA_PRIOR *gcap; float lh_prior, rh_prior; int n; @@ -25869,7 +26370,8 @@ int GCAisLeftHemisphere(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, for (lh_prior = rh_prior = 0.0, n = 0; n < gcap->nlabels; n++) if (IS_LH_CLASS(gcap->labels[n])) { lh_prior += gcap->priors[n]; - } else if (IS_RH_CLASS(gcap->labels[n])) { + } + else if (IS_RH_CLASS(gcap->labels[n])) { rh_prior += gcap->priors[n]; } @@ -25906,7 +26408,8 @@ int GCAisLeftHemisphere(GCA *gca, MRI *mri, TRANSFORM *transform, int x, int y, gca.mode000?.can.mgh should be pretty close to gca.mode0000.mgh. It is not exact, maybe because of the conversion to uchar (which mri_ca_normalize requires). */ -MRI *GCAsampleToVol(MRI *mri, GCA *gca, TRANSFORM *transform, MRI **seg, MRI *out) { +MRI *GCAsampleToVol(MRI *mri, GCA *gca, TRANSFORM *transform, MRI **seg, MRI *out) +{ int z; if (out == NULL) { @@ -25971,7 +26474,8 @@ MRI *GCAsampleToVol(MRI *mri, GCA *gca, TRANSFORM *transform, MRI **seg, MRI *ou return (out); } -MRI *GCAsampleToVolWMSAprob(MRI *mri, GCA *gca, TRANSFORM *transform, MRI *out) { +MRI *GCAsampleToVolWMSAprob(MRI *mri, GCA *gca, TRANSFORM *transform, MRI *out) +{ int z; if (out == NULL) { @@ -26027,7 +26531,8 @@ MRI *GCAsampleToVolWMSAprob(MRI *mri, GCA *gca, TRANSFORM *transform, MRI *out) // relabels a given voxel to WMSA if it was not already // and if its mahalanobis distance to WMSAs is closer to that of WM // as determined by the labeled voxels in a n-half neighborhood -int MRIwmsaHalo(MRI *mri_inputs, MRI *mri_labeled, int n) { +int MRIwmsaHalo(MRI *mri_inputs, MRI *mri_labeled, int n) +{ int h, label, nwm, nwmsa, ngm, x, y, z, wmsa_label, wm_label, gm_label, a, b, changed; double wm_mdist = 0, wmsa_mdist = 0, caudate_mdist = 0, vent_mdist = 0; VECTOR *v_vals = NULL, *wm_means, *wmsa_means, *caudate_means, *vent_means; @@ -26069,7 +26574,8 @@ int MRIwmsaHalo(MRI *mri_inputs, MRI *mri_labeled, int n) { wmsa_label = Right_WM_hypointensities; wm_label = Right_Cerebral_White_Matter; gm_label = Right_Cerebral_Cortex; - } else { + } + else { wmsa_label = Left_WM_hypointensities; wm_label = Left_Cerebral_White_Matter; gm_label = Left_Cerebral_Cortex; @@ -26179,7 +26685,8 @@ int MRIwmsaHalo(MRI *mri_inputs, MRI *mri_labeled, int n) { return (NO_ERROR); } -WMSA *WMSAalloc(int nreftissues) { +WMSA *WMSAalloc(int nreftissues) +{ WMSA *wmsa; wmsa = (WMSA *)calloc(sizeof(WMSA), 1); wmsa->nreftissues = nreftissues; @@ -26189,7 +26696,8 @@ WMSA *WMSAalloc(int nreftissues) { return (wmsa); } -int MRIwmsaHalo2(WMSA *wmsa) { +int MRIwmsaHalo2(WMSA *wmsa) +{ int ok, i, j, k, a, b, c, d, x, y, z, changed, nwmsa1, nwmsa2, nwmsa, ngm1, ngm2, ngm, nmatches, label; int wmsa_labels[] = {78, 79}; int gm_labels[] = {3, 42}; @@ -26281,7 +26789,8 @@ int MRIwmsaHalo2(WMSA *wmsa) { for (d = 0; d < nmodalities; d++) { if (wmsacomp[c][d] == 0) { // meanWMSA > meanRefTissue if (v_vals->rptr[d + 1][1] < reftissue_means[c]->rptr[d + 1][1]) nmatches = nmatches + 1; - } else // meanWMSA < meanRefTissue + } + else // meanWMSA < meanRefTissue if (v_vals->rptr[d + 1][1] > reftissue_means[c]->rptr[d + 1][1]) nmatches = nmatches + 1; @@ -26306,7 +26815,8 @@ int MRIwmsaHalo2(WMSA *wmsa) { if (nwmsa1 > nwmsa2) { // left hemisphere MRIsetVoxVal(wmsa->seg, x, y, z, 0, wmsa_labels[0]); changed++; - } else { // right hemi + } + else { // right hemi MRIsetVoxVal(wmsa->seg, x, y, z, 0, wmsa_labels[1]); changed++; } @@ -26332,7 +26842,8 @@ int MRIwmsaHalo2(WMSA *wmsa) { MatrixFree(&wmsa_inv_covs); return (NO_ERROR); } -void GCAinitLabelsFromMRI(GCA *gca, MRI *mri_labels) { +void GCAinitLabelsFromMRI(GCA *gca, MRI *mri_labels) +{ int x, y, z, label; GCA_PRIOR *gcap; GCA_NODE *gcan; diff --git a/utils/gcaboundary.c b/utils/gcaboundary.c index 6db7af501a4..25ba158393b 100644 --- a/utils/gcaboundary.c +++ b/utils/gcaboundary.c @@ -79,7 +79,8 @@ static int gcabUpdateNode(GCAB *gcab, int xn, int yn, int zn, double val1, doubl static int gcabFindClosestIcoVertex( GCAB *gcab, TRANSFORM *transform, float x0, float y0, float z0, float nx, float ny, float nz); static int gcabValsToBins(GCAB *gcab, double val1, double val2, float grad, float *pi1f, float *pi2f, float *pgf); -GCAB *GCABalloc(GCA *gca, int spacing, int ico_order, int nintensity_bins, int ngrad_bins, int target_label) { +GCAB *GCABalloc(GCA *gca, int spacing, int ico_order, int nintensity_bins, int ngrad_bins, int target_label) +{ GCAB *gcab; GCABS *gcabs; int width, height, depth, x, y, z, vno, i1, x1, y1, z1; @@ -164,7 +165,8 @@ GCAB *GCABalloc(GCA *gca, int spacing, int ico_order, int nintensity_bins, int n return (gcab); } -int GCABfree(GCAB **pgcab) { +int GCABfree(GCAB **pgcab) +{ GCAB *gcab; gcab = *pgcab; @@ -174,7 +176,8 @@ int GCABfree(GCAB **pgcab) { return (NO_ERROR); } -int GCABcompleteTraining(GCAB *gcab) { +int GCABcompleteTraining(GCAB *gcab) +{ int x, y, z, i1, i2, vno; GCABS *gcabs; @@ -213,7 +216,8 @@ double GCABgetProbability(GCAB *gcab, float z0, float nx, float ny, - float nz) { + float nz) +{ float xn, yn, zn, xi, yi, zi, xo, yo, zo, xd, yd, zd, xi0, yi0, zi0, d, dx, dy, dz, xo0, yo0, zo0; int vno, oob, xb, yb, zb, xu, yu, zu, x, y, z, num; double grad, p, pdelI, mag, pI_total, val1, val2, pI_in, pI_out, e1x, e2x, e1y, e2y, e1z, e2z, d1, d2; @@ -431,7 +435,8 @@ double GCABgetPin(GCAB *gcab, float z0, float nx, float ny, - float nz) { + float nz) +{ float xn, yn, zn, xi, yi, zi, xo, yo, zo, xd, yd, zd, xi0, yi0, zi0, d, dx, dy, dz, xo0, yo0, zo0; int vno, oob, xb, yb, zb, xu, yu, zu, x, y, z, num; double grad, p, pdelI, mag, pI_total, val1, val2, pI_in, pI_out, e1x, e2x, e1y, e2y, e1z, e2z, d1, d2; @@ -649,7 +654,8 @@ double GCABgetPout(GCAB *gcab, float z0, float nx, float ny, - float nz) { + float nz) +{ float xn, yn, zn, xi, yi, zi, xo, yo, zo, xd, yd, zd, xi0, yi0, zi0, d, dx, dy, dz, xo0, yo0, zo0; int vno, oob, xb, yb, zb, xu, yu, zu, x, y, z, num; double grad, p, pdelI, mag, pI_total, val1, val2, pI_in, pI_out, e1x, e2x, e1y, e2y, e1z, e2z, d1, d2; @@ -867,7 +873,8 @@ double GCABgetPgrad(GCAB *gcab, float z0, float nx, float ny, - float nz) { + float nz) +{ float xn, yn, zn, xi, yi, zi, xo, yo, zo, xd, yd, zd, xi0, yi0, zi0, d, dx, dy, dz, xo0, yo0, zo0; int vno, oob, xb, yb, zb, xu, yu, zu, x, y, z, num; double grad, p, pdelI, mag, pI_total, val1, val2, pI_in, pI_out, e1x, e2x, e1y, e2y, e1z, e2z, d1, d2; @@ -1076,7 +1083,8 @@ double GCABgetPgrad(GCAB *gcab, return (p); } -int GCABtrain(GCAB *gcab, MRI *mri_int, MRI *mri_seg, TRANSFORM *transform, int target_label) { +int GCABtrain(GCAB *gcab, MRI *mri_int, MRI *mri_seg, TRANSFORM *transform, int target_label) +{ int x, y, z, oob, border; float xn, yn, zn; MRI *mri_border, *mri_dist, *mri_tmp; @@ -1113,7 +1121,8 @@ int GCABtrain(GCAB *gcab, MRI *mri_int, MRI *mri_seg, TRANSFORM *transform, int } int GCABsourceVoxelToNode( - GCAB *gcab, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv, float *pxn, float *pyn, float *pzn) { + GCAB *gcab, MRI *mri, TRANSFORM *transform, float xv, float yv, float zv, float *pxn, float *pyn, float *pzn) +{ float xt, yt, zt; double xrt, yrt, zrt; LTA *lta; @@ -1128,9 +1137,11 @@ int GCABsourceVoxelToNode( xt = xrt; yt = yrt; zt = zrt; - } else + } + else ErrorExit(ERROR_BADPARM, "GCAsourceVoxelToNode: needs vox-to-vox transform"); - } else { + } + else { TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); } if (Ggca_x == xv && Ggca_y == yv && Ggca_z == zv && DIAG_VERBOSE_ON) @@ -1146,7 +1157,8 @@ int GCABsourceVoxelToNode( //////////////////////////////////////////////////////////////// // transform from template -> node //////////////////////////////////////////////////////////////// -int GCABvoxelToNode(GCAB *gcab, float xv, float yv, float zv, float *pxn, float *pyn, float *pzn) { +int GCABvoxelToNode(GCAB *gcab, float xv, float yv, float zv, float *pxn, float *pyn, float *pzn) +{ float xn, yn, zn; xn = *pxn = xv / gcab->spacing; @@ -1156,7 +1168,8 @@ int GCABvoxelToNode(GCAB *gcab, float xv, float yv, float zv, float *pxn, float return (ERROR_OUT_OF_BOUNDS); return NO_ERROR; } -int GCABwrite(GCAB *gcab, char *fname) { +int GCABwrite(GCAB *gcab, char *fname) +{ FILE *fp; int x, y, z, vno, i1, i2; GCABS *gcabs; @@ -1234,7 +1247,8 @@ int GCABwrite(GCAB *gcab, char *fname) { return (NO_ERROR); } -GCAB *GCABread(char *fname, GCA *gca) { +GCAB *GCABread(char *fname, GCA *gca) +{ FILE *fp; int x, y, z, vno, i1, i2, spacing, ico_order, nibins, ngbins, label, nvertices; float version; @@ -1322,7 +1336,8 @@ static int gcabUpdateDistributions(GCAB *gcab, float xn, float yn, float zn, - int target_label) { + int target_label) +{ float nx, ny, nz, xi, yi, zi, xo, yo, zo, xd, yd, zd, dx, dy, dz, d, xi0, yi0, zi0, xo0, yo0, zo0, x0, y0, z0; int vno, label, xb, yb, zb, xu, yu, zu; double grad, mag, val1, val2, e1x, e2x, e1y, e2y, e1z, e2z, d1, d2; @@ -1339,7 +1354,8 @@ static int gcabUpdateDistributions(GCAB *gcab, xo = x + nx; yo = y + ny; zo = z + nz; - } else // current voxel is on outside border + } + else // current voxel is on outside border { xo = x; yo = y; @@ -1451,7 +1467,8 @@ static int gcabUpdateDistributions(GCAB *gcab, return (NO_ERROR); } -static int gcabUpdateNodeIout(GCAB *gcab, int xn, int yn, int zn, double val2, int vno, float wt) { +static int gcabUpdateNodeIout(GCAB *gcab, int xn, int yn, int zn, double val2, int vno, float wt) +{ float i1f, i2f, i2d, gbinf; int i2b, i2u; GCABS *gcabs; @@ -1487,7 +1504,8 @@ static int gcabUpdateNodeIout(GCAB *gcab, int xn, int yn, int zn, double val2, i return (NO_ERROR); } -static int gcabUpdateNodeIin(GCAB *gcab, int xn, int yn, int zn, double val1, int vno, float wt) { +static int gcabUpdateNodeIin(GCAB *gcab, int xn, int yn, int zn, double val1, int vno, float wt) +{ float i1f, i2f, i1d, gbinf; int i1b, i1u; GCABS *gcabs; @@ -1523,7 +1541,8 @@ static int gcabUpdateNodeIin(GCAB *gcab, int xn, int yn, int zn, double val1, in return (NO_ERROR); } -static int gcabUpdateNode(GCAB *gcab, int xn, int yn, int zn, double val1, double val2, float grad, int vno, float wt) { +static int gcabUpdateNode(GCAB *gcab, int xn, int yn, int zn, double val1, double val2, float grad, int vno, float wt) +{ float i1f, i2f, i1d, i2d, gbinf, gbind; int i1b, i2b, i1u, i2u, gbinb, gbinu; GCABS *gcabs; @@ -1581,7 +1600,8 @@ static int gcabComputeBorderNormal(GCAB *gcab, float *pnx, float *pny, float *pnz, - int target_label) { + int target_label) +{ int olabel, x1, y1, z1, xk, yk, zk, label, num, max_n; float nx, ny, nz, mag; @@ -1609,7 +1629,8 @@ static int gcabComputeBorderNormal(GCAB *gcab, nx /= num; ny /= num; nz /= num; - } else + } + else DiagBreak(); if (olabel != target_label) // make normal point outwards @@ -1635,7 +1656,8 @@ static int gcabComputeBorderNormal(GCAB *gcab, } static int gcabFindClosestIcoVertex( - GCAB *gcab, TRANSFORM *transform, float x0, float y0, float z0, float nx, float ny, float nz) { + GCAB *gcab, TRANSFORM *transform, float x0, float y0, float z0, float nx, float ny, float nz) +{ int n, max_n; float xa0, ya0, za0, xa1, ya1, za1, mag, dot, max_dot; @@ -1662,7 +1684,8 @@ static int gcabFindClosestIcoVertex( return (max_n); } -static int gcabValsToBins(GCAB *gcab, double val1, double val2, float grad, float *pi1f, float *pi2f, float *pgf) { +static int gcabValsToBins(GCAB *gcab, double val1, double val2, float grad, float *pi1f, float *pi2f, float *pgf) +{ if (val1 < gcab->min_intensity) val1 = gcab->min_intensity; if (val1 > gcab->max_intensity) val1 = gcab->max_intensity; if (val2 < gcab->min_intensity) val2 = gcab->min_intensity; @@ -1675,7 +1698,8 @@ static int gcabValsToBins(GCAB *gcab, double val1, double val2, float grad, floa return (NO_ERROR); } -static MRI *gcabWritePDFToMRI(GCAB *gcab, MRI *mri, int x, int y, int z) { +static MRI *gcabWritePDFToMRI(GCAB *gcab, MRI *mri, int x, int y, int z) +{ int vno, i1, i2; GCABS *gcabs; @@ -1687,7 +1711,8 @@ static MRI *gcabWritePDFToMRI(GCAB *gcab, MRI *mri, int x, int y, int z) { for (i2 = 0; i2 < gcab->nintensity_bins; i2++) MRIsetVoxVal(mri, vno, i1, i2, 0, gcabs->pdfs[vno][i1][i2]); return (mri); } -static MRI *gcabWriteMRIToPDF(GCAB *gcab, MRI *mri, int x, int y, int z) { +static MRI *gcabWriteMRIToPDF(GCAB *gcab, MRI *mri, int x, int y, int z) +{ int vno, i1, i2; GCABS *gcabs; @@ -1697,7 +1722,8 @@ static MRI *gcabWriteMRIToPDF(GCAB *gcab, MRI *mri, int x, int y, int z) { for (i2 = 0; i2 < gcab->nintensity_bins; i2++) gcabs->pdfs[vno][i1][i2] = MRIgetVoxVal(mri, vno, i1, i2, 0); return (NO_ERROR); } -int GCABsmoothPDFs(GCAB *gcab, float sigma) { +int GCABsmoothPDFs(GCAB *gcab, float sigma) +{ int x, y, z; MRI *mri_kernel; @@ -1715,7 +1741,8 @@ int GCABsmoothPDFs(GCAB *gcab, float sigma) { return (NO_ERROR); } -static int gcabSmoothPDF(GCAB *gcab, int x, int y, int z, MRI *mri_kernel) { +static int gcabSmoothPDF(GCAB *gcab, int x, int y, int z, MRI *mri_kernel) +{ MRI *mri_pdf, *mri_tmp; int width, height, depth, klen; float *kernel; @@ -1738,7 +1765,8 @@ static int gcabSmoothPDF(GCAB *gcab, int x, int y, int z, MRI *mri_kernel) { return (NO_ERROR); } -static double gcabSamplePDF(GCAB *gcab, GCABS *gcabs, int which, int vno, double val) { +static double gcabSamplePDF(GCAB *gcab, GCABS *gcabs, int which, int vno, double val) +{ double p, p1, p2; float index_f = 0, index_d, dummy; int index_b, index_u; diff --git a/utils/gcalinearnode.cpp b/utils/gcalinearnode.cpp index 966277afd48..8d9bb4f07b2 100644 --- a/utils/gcalinearnode.cpp +++ b/utils/gcalinearnode.cpp @@ -34,17 +34,19 @@ using namespace std; #include "gcalinearnode.hpp" -namespace Freesurfer { - +namespace Freesurfer +{ // ==================================================== -void GCAlinearNode::PrintStats(ostream &os) const { +void GCAlinearNode::PrintStats(ostream &os) const +{ os << "Stats for GCAlinearNode" << endl; os << " Exhumation time = " << this->tExhume << endl; os << " Inhumation time = " << this->tInhume << endl; } // ========================================== -void GCAlinearNode::Exhume(const GCA *const src) { +void GCAlinearNode::Exhume(const GCA *const src) +{ /*! This method is responsible for extracting data from the source GCA, and packing into the linear arrays @@ -163,13 +165,15 @@ void GCAlinearNode::Exhume(const GCA *const src) { // ==================================================== -const_GCAnode GCAlinearNode::GetConstNode(const int ix, const int iy, const int iz) const { +const_GCAnode GCAlinearNode::GetConstNode(const int ix, const int iy, const int iz) const +{ return (const_GCAnode(ix, iy, iz, *this)); } // ==================================================== -void GCAlinearNode::Inhume(GCA *dst) const { +void GCAlinearNode::Inhume(GCA *dst) const +{ /*! Stores data back from the linear arrays into a GCA. This removes the existing node structure, and reallocates @@ -333,7 +337,8 @@ void GCAlinearNode::Inhume(GCA *dst) const { // ==================================================== -void GCAlinearNode::Allocate(void) { +void GCAlinearNode::Allocate(void) +{ /*! Allocates the main arrays according to the values stored in the dimension member @@ -368,7 +373,8 @@ void GCAlinearNode::Allocate(void) { // ==================================================== -void GCAlinearNode::ExtractDims(const GCA *const src) { +void GCAlinearNode::ExtractDims(const GCA *const src) +{ /*! Fills in the dimensions required from the given GCA. Does this by looping over all voxels, and finding the @@ -401,7 +407,8 @@ void GCAlinearNode::ExtractDims(const GCA *const src) { for (unsigned int iNeighbour = 0; iNeighbour < GIBBS_NEIGHBORHOOD; iNeighbour++) { this->n6D += gc1d->nlabels[iNeighbour]; } - } else { + } + else { this->hasGibbsNeighbourhood = false; } } @@ -412,7 +419,8 @@ void GCAlinearNode::ExtractDims(const GCA *const src) { // ==================================================== -void GCAlinearNode::ScorchNodes(GCA *targ) const { +void GCAlinearNode::ScorchNodes(GCA *targ) const +{ /*! Deletes all of the node related things from a GCA, prior to inhumation of new data @@ -432,7 +440,8 @@ void GCAlinearNode::ScorchNodes(GCA *targ) const { // ############################################################### -const_GCAnode_GC1D const_GCAnode::GetConstGC1D(const int iGC1D) const { +const_GCAnode_GC1D const_GCAnode::GetConstGC1D(const int iGC1D) const +{ if ((iGC1D < 0) || (iGC1D >= this->myGC1Dcount)) { std::cerr << __FUNCTION__ << ": Out of range " << iGC1D << std::endl; abort(); diff --git a/utils/gcalinearprior.cpp b/utils/gcalinearprior.cpp index 870ea601601..fa6aec94935 100644 --- a/utils/gcalinearprior.cpp +++ b/utils/gcalinearprior.cpp @@ -34,16 +34,19 @@ using namespace std; #include "gcalinearprior.hpp" -namespace Freesurfer { +namespace Freesurfer +{ // ========================================== -void GCAlinearPrior::PrintStats(ostream &os) const { +void GCAlinearPrior::PrintStats(ostream &os) const +{ os << "Stats for GCAlinearPrior" << endl; os << " Exhumation time = " << this->tExhume << endl; os << " Inhumation time = " << this->tInhume << endl; } // ========================================== -void GCAlinearPrior::ExtractDims(const GCA *const src) { +void GCAlinearPrior::ExtractDims(const GCA *const src) +{ /*! Fills in the dimensions required from the given GCA. Does this by looping over all voxels, and finding the @@ -66,7 +69,8 @@ void GCAlinearPrior::ExtractDims(const GCA *const src) { } // ========================================== -void GCAlinearPrior::Allocate(void) { +void GCAlinearPrior::Allocate(void) +{ /*! Allocates the main arrays according to the 'dimension' members. @@ -105,7 +109,8 @@ void GCAlinearPrior::Allocate(void) { // ========================================== -void GCAlinearPrior::Exhume(const GCA *const src) { +void GCAlinearPrior::Exhume(const GCA *const src) +{ /*! This method is responsible for extracting GCA_PRIOR data from the source GCA, and packing into the linear arrays @@ -154,12 +159,14 @@ void GCAlinearPrior::Exhume(const GCA *const src) { } // ========================================== -const_GCAprior GCAlinearPrior::GetConstPrior(const int ix, const int iy, const int iz) const { +const_GCAprior GCAlinearPrior::GetConstPrior(const int ix, const int iy, const int iz) const +{ return (const_GCAprior(ix, iy, iz, *this)); } // ========================================== -void GCAlinearPrior::Inhume(GCA *dst) const { +void GCAlinearPrior::Inhume(GCA *dst) const +{ /*! Stores data about the priors back into the target GCA. @@ -229,7 +236,8 @@ void GCAlinearPrior::Inhume(GCA *dst) const { // ========================================== -void GCAlinearPrior::ScorchPriors(GCA *targ) const { +void GCAlinearPrior::ScorchPriors(GCA *targ) const +{ /*! This method destroys the priors structure of a GCA, prior to inhumation of new data diff --git a/utils/gcamcomputeLabelsLinearCPU.cpp b/utils/gcamcomputeLabelsLinearCPU.cpp index 393b6a0b3a7..0da68766c60 100644 --- a/utils/gcamcomputeLabelsLinearCPU.cpp +++ b/utils/gcamcomputeLabelsLinearCPU.cpp @@ -31,7 +31,8 @@ #include "gcamcomputeLabelsLinearCPU.h" -int GCAMcomputeLabelsLinearCPU(MRI *mri, GCA_MORPH *gcam) { +int GCAMcomputeLabelsLinearCPU(MRI *mri, GCA_MORPH *gcam) +{ int nchanged = 0; if (gcam->gca == NULL) { diff --git a/utils/gcamorph.c b/utils/gcamorph.c index 964bd0766ef..188bda62c65 100644 --- a/utils/gcamorph.c +++ b/utils/gcamorph.c @@ -290,7 +290,8 @@ static int Galigned = 0; #define MIN_NODE_DIST (1) #define MIN_NODE_DIST_SQ (MIN_NODE_DIST * MIN_NODE_DIST) -void GCAMwriteGeom(const GCA_MORPH *gcam, znzFile file) { +void GCAMwriteGeom(const GCA_MORPH *gcam, znzFile file) +{ char buf[512]; // src volume info @@ -341,7 +342,8 @@ void GCAMwriteGeom(const GCA_MORPH *gcam, znzFile file) { znzwrite(buf, sizeof(char), 512, file); } -void GCAMreadGeom(GCA_MORPH *gcam, znzFile file) { +void GCAMreadGeom(GCA_MORPH *gcam, znzFile file) +{ // src volume info gcam->image.valid = znzreadInt(file); gcam->image.width = znzreadInt(file); @@ -388,7 +390,8 @@ void GCAMreadGeom(GCA_MORPH *gcam, znzFile file) { znzread(gcam->atlas.fname, sizeof(char), 512, file); } -int GCAMwrite(const GCA_MORPH *gcam, const char *fname) { +int GCAMwrite(const GCA_MORPH *gcam, const char *fname) +{ znzFile file; // FILE *fp=0 ; int x, y, z; @@ -481,7 +484,8 @@ int GCAMwrite(const GCA_MORPH *gcam, const char *fname) { If the inverse must be computed, then it reads in the header for mri/orig.mgz. See also GCAMreadAndInvert(). -----------------------------------------------------------------*/ -int GCAMwriteInverse(const char *gcamfname, GCA_MORPH *gcam) { +int GCAMwriteInverse(const char *gcamfname, GCA_MORPH *gcam) +{ char *gcamdir, *mridir, tmpstr[2000], *gcambase; MRI *mri; int freegcam; @@ -530,7 +534,8 @@ int GCAMwriteInverse(const char *gcamfname, GCA_MORPH *gcam) { return (0); } -int GCAMwriteInverseNonTal(const char *gcamfname, GCA_MORPH *gcam) { +int GCAMwriteInverseNonTal(const char *gcamfname, GCA_MORPH *gcam) +{ char tmpstr[2000]; MRI *mri; int freegcam; @@ -583,7 +588,8 @@ int GCAMwriteInverseNonTal(const char *gcamfname, GCA_MORPH *gcam) { if the morph must be explicitly inverted, it will read in the header for mri/orig.mgz (or die trying). ----------------------------------------------------------------------*/ -GCA_MORPH *GCAMreadAndInvert(const char *gcamfname) { +GCA_MORPH *GCAMreadAndInvert(const char *gcamfname) +{ GCA_MORPH *gcam; char tmpstr[2000], *gcamdir, *mridir; MRI *mri; @@ -637,7 +643,8 @@ GCA_MORPH *GCAMreadAndInvert(const char *gcamfname) { if (gcam->mri_zind == NULL) { printf("ERROR: reading %s\n", tmpstr); } - } else { + } + else { // Must invert explicitly printf("Inverting Morph\n"); mridir = fio_dirname(gcamdir); @@ -657,7 +664,8 @@ GCA_MORPH *GCAMreadAndInvert(const char *gcamfname) { return (gcam); } -GCA_MORPH *GCAMreadAndInvertNonTal(const char *gcamfname) { +GCA_MORPH *GCAMreadAndInvertNonTal(const char *gcamfname) +{ GCA_MORPH *gcam; char tmpstr[2000], *gcamdir; MRI *mri; @@ -711,7 +719,8 @@ GCA_MORPH *GCAMreadAndInvertNonTal(const char *gcamfname) { if (gcam->mri_zind == NULL) { printf("ERROR: reading %s\n", tmpstr); } - } else { + } + else { // Must invert explicitly printf("Inverting Morph\n"); // Need template mri @@ -726,7 +735,8 @@ GCA_MORPH *GCAMreadAndInvertNonTal(const char *gcamfname) { printf("WARN: cannot acccess %s\n", tmpstr); printf("WARN: using %s\n", altname); strcpy(tmpstr, altname); - } else { + } + else { mridir = fio_dirname(mridir); sprintf(altname, "%s/mri/norm.mgz", mridir); @@ -752,7 +762,8 @@ GCA_MORPH *GCAMreadAndInvertNonTal(const char *gcamfname) { //! A thin pipeline segment to save a GPU copy double GCAMregisterPipelineAndComputeRMS( - GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARMS *parms, double *last_rms, int *level_steps, int i) { + GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARMS *parms, double *last_rms, int *level_steps, int i) +{ double result; #ifdef GCAM_REGISTER_PIPELINE_GPU printf("%s: On GPU\n", __FUNCTION__); @@ -770,7 +781,8 @@ double GCAMregisterPipelineAndComputeRMS( return result; } -void GCAMregister_pctLoop_saveBefore(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, const int level) { +void GCAMregister_pctLoop_saveBefore(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, const int level) +{ char fname[STRLEN]; MRI *mri_gca, *mri_tmp; @@ -780,7 +792,8 @@ void GCAMregister_pctLoop_saveBefore(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS sprintf(fname, "%s_target.mgz", parms->base_name); printf("writing target volume to %s...\n", fname); MRIwrite(mri, fname); - } else { + } + else { mri_gca = MRIclone(mri, NULL); GCAMbuildMostLikelyVolume(gcam, mri_gca); if (mri_gca->nframes > 1) { @@ -798,7 +811,8 @@ void GCAMregister_pctLoop_saveBefore(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS } } -void GCAMregister_pctLoop_saveAfter(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, const int level) { +void GCAMregister_pctLoop_saveAfter(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, const int level) +{ char fname[STRLEN]; char path[STRLEN], fname_only[STRLEN]; FileNameOnly(parms->write_fname, fname_only); @@ -819,7 +833,8 @@ void GCAMregister_pctLoop(GCA_MORPH *gcam, MRI *mri_smooth, double *rms, double *last_rms, - double *pct_change) { + double *pct_change) +{ int level_steps; int i = 0; @@ -859,7 +874,8 @@ void GCAMregister_pctLoop(GCA_MORPH *gcam, } while (*pct_change > parms->tol); } -int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { +int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) +{ char fname[STRLEN]; int level, navgs, l2, relabel, orig_relabel, start_t = 0, passno; MRI *mri_smooth = NULL, *mri_kernel; @@ -997,7 +1013,8 @@ int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { } if (parms->levels < 0) { parms->levels = DEFAULT_PYRAMID_LEVELS; - } else if (parms->levels >= MAX_PYRAMID_LEVELS) { + } + else if (parms->levels >= MAX_PYRAMID_LEVELS) { parms->levels = MAX_PYRAMID_LEVELS; } @@ -1009,11 +1026,13 @@ int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { if (parms->log_fp == NULL) { if (parms->start_t == 0) { parms->log_fp = fopen(fname, "w"); - } else { + } + else { parms->log_fp = fopen(fname, "a"); } } - } else { + } + else { parms->log_fp = NULL; } @@ -1023,7 +1042,8 @@ int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { // make node to have the max_prior label values if (parms->relabel_avgs >= parms->navgs && parms->relabel) { GCAMcomputeLabels(mri, gcam); - } else { + } + else { GCAMcomputeMaxPriorLabels(gcam); } @@ -1058,13 +1078,15 @@ int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { parms->l_elastic = l_elastic; parms->l_elastic = l_elastic / ((parms->navgs) + 1); printf("setting elastic coefficient to %2.3f\n", parms->l_elastic); - } else { + } + else { #if 0 parms->l_smoothness = l_smooth / (sqrt(parms->navgs)+1) ; #else if (DZERO(parms->l_binary) && DZERO(parms->l_area_intensity) && parms->scale_smoothness) { parms->l_smoothness = l_smooth / ((parms->navgs) + 1); - } else { + } + else { parms->l_smoothness = l_smooth; } #endif @@ -1076,7 +1098,8 @@ int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { if (DZERO(parms->sigma)) { mri_smooth = MRIcopy(mri, mri_smooth); if (parms->mri_binary) parms->mri_binary_smooth = MRIcopy(parms->mri_binary, parms->mri_binary_smooth); - } else { + } + else { // if (Gdiag & DIAG_SHOW) printf("blurring input image with Gaussian with sigma=%2.3f...\n", parms->sigma); mri_kernel = MRIgaussian1d(parms->sigma, 100); @@ -1175,7 +1198,8 @@ int GCAMregister(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { return (NO_ERROR); } -GCA_MORPH *GCAMread(const char *fname) { +GCA_MORPH *GCAMread(const char *fname) +{ GCA_MORPH *gcam; znzFile file; int x, y, z, width, height, depth; @@ -1241,7 +1265,8 @@ GCA_MORPH *GCAMread(const char *fname) { if (FZERO(gcamn->origx) && FZERO(gcamn->origy) && FZERO(gcamn->origz) && FZERO(gcamn->x) && FZERO(gcamn->y) && FZERO(gcamn->z)) { gcamn->invalid = GCAM_POSITION_INVALID; - } else { + } + else { if (x == 0 || x == width - 1 || y == 0 || y == height - 1 || z == 0 || z == depth - 1) gcamn->invalid = GCAM_AREA_INVALID; else @@ -1321,7 +1346,8 @@ GCA_MORPH *GCAMread(const char *fname) { return (gcam); } -GCA_MORPH *GCAMalloc(const int width, const int height, const int depth) { +GCA_MORPH *GCAMalloc(const int width, const int height, const int depth) +{ GCA_MORPH *gcam; int x, y, z; @@ -1383,7 +1409,8 @@ GCA_MORPH *GCAMalloc(const int width, const int height, const int depth) { return (gcam); } -int GCAMinitVolGeom(GCAM *gcam, MRI *mri_image, MRI *mri_atlas) { +int GCAMinitVolGeom(GCAM *gcam, MRI *mri_image, MRI *mri_atlas) +{ if (gcam->type == GCAM_VOX) /* in some other voxel coords */ { GCAMrasToVox(gcam, mri_image); @@ -1397,7 +1424,8 @@ int GCAMinitVolGeom(GCAM *gcam, MRI *mri_image, MRI *mri_atlas) { return (NO_ERROR); } -int GCAMpreserveLabelMetricProperties(GCA_MORPH *gcam, LABEL *area, MRI *mri) { +int GCAMpreserveLabelMetricProperties(GCA_MORPH *gcam, LABEL *area, MRI *mri) +{ int n, xv, yv, zv; GCA_MORPH_NODE *gcamn; double xvd, yvd, zvd; @@ -1418,7 +1446,8 @@ int GCAMpreserveLabelMetricProperties(GCA_MORPH *gcam, LABEL *area, MRI *mri) { } return (NO_ERROR); } -int GCAMinit(GCA_MORPH *gcam, MRI *mri_image, GCA *gca, TRANSFORM *transform, int relabel) { +int GCAMinit(GCA_MORPH *gcam, MRI *mri_image, GCA *gca, TRANSFORM *transform, int relabel) +{ GCA_MORPH_NODE *gcamn; GC1D *gc; GCA_PRIOR *gcap; @@ -1559,10 +1588,12 @@ int GCAMinit(GCA_MORPH *gcam, MRI *mri_image, GCA *gca, TRANSFORM *transform, in if (relabel) { GCAMcomputeLabels(mri_image, gcam); - } else { + } + else { GCAMcomputeMaxPriorLabels(gcam); } - } else /* no gca specified */ + } + else /* no gca specified */ { VECTOR *v1, *v2; MATRIX *m_L; @@ -1708,7 +1739,8 @@ int GCAMinit(GCA_MORPH *gcam, MRI *mri_image, GCA *gca, TRANSFORM *transform, in //////////////////////////////////////////////// // user is responsible for freeing gca inside // the gcam. -int GCAMfree(GCA_MORPH **pgcam) { +int GCAMfree(GCA_MORPH **pgcam) +{ GCA_MORPH *gcam; gcam = *pgcam; @@ -1721,7 +1753,8 @@ int GCAMfree(GCA_MORPH **pgcam) { //////////////////////////////////////////////// // user is responsible for freeing gca inside // the gcam. -int GCAMfreeContents(GCA_MORPH *gcam) { +int GCAMfreeContents(GCA_MORPH *gcam) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -1751,7 +1784,8 @@ int GCAMfreeContents(GCA_MORPH *gcam) { #define GCAM_LLT_OUTPUT 0 -int gcamLogLikelihoodTerm(GCA_MORPH *gcam, const MRI *mri, const MRI *mri_smooth, double l_log_likelihood) { +int gcamLogLikelihoodTerm(GCA_MORPH *gcam, const MRI *mri, const MRI *mri_smooth, double l_log_likelihood) +{ #ifdef GCAM_LL_TERM_GPU if (DZERO(l_log_likelihood)) { return (NO_ERROR); @@ -1797,7 +1831,9 @@ int gcamLogLikelihoodTerm(GCA_MORPH *gcam, const MRI *mri, const MRI *mri_smooth #ifdef HAVE_OPENMP #pragma omp parallel - { nthreads = omp_get_num_threads(); } + { + nthreads = omp_get_num_threads(); + } #else nthreads = 1; #endif @@ -1842,7 +1878,8 @@ int gcamLogLikelihoodTerm(GCA_MORPH *gcam, const MRI *mri, const MRI *mri_smooth MatrixClear(v_means[tid]); MatrixIdentity(gcam->ninputs, m_inv_cov[tid]); MatrixScalarMul(m_inv_cov[tid], 1.0 / (MIN_VAR), m_inv_cov[tid]); /* variance=4 is min */ - } else { + } + else { #if 0 if (parms->relabel) { @@ -1948,7 +1985,8 @@ int gcamLogLikelihoodTerm(GCA_MORPH *gcam, const MRI *mri, const MRI *mri_smooth /* */ -int gcamLikelihoodTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_likelihood, GCA_MORPH_PARMS *parms) { +int gcamLikelihoodTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_likelihood, GCA_MORPH_PARMS *parms) +{ int x, y, z, len, xi, yi, zi, x0, y0, z0, half_len; double dx, dy, dz; float val, mean, var; @@ -2009,7 +2047,8 @@ int gcamLikelihoodTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_like } } } - } else /* haven't written the multi-input case yet */ + } + else /* haven't written the multi-input case yet */ { ErrorExit(ERROR_UNSUPPORTED, "vector-based likelihood not written yet"); } @@ -2054,7 +2093,8 @@ static float ***last_sse = NULL; #define GCAM_LLENERGY_OUTPUT 0 -double gcamLogLikelihoodEnergy(const GCA_MORPH *gcam, MRI *mri) { +double gcamLogLikelihoodEnergy(const GCA_MORPH *gcam, MRI *mri) +{ /* NOTE: The only reason *mri is not declared 'const' is because I can't figure out how to make MRIwrite accept a const MRI @@ -2156,7 +2196,8 @@ double gcamLogLikelihoodEnergy(const GCA_MORPH *gcam, MRI *mri) { // Compute 'error' for this node if (gcamn->gc) { error = GCAmahDist(gcamn->gc, vals, gcam->ninputs) + log(covariance_determinant(gcamn->gc, gcam->ninputs)); - } else { + } + else { int n; // Note that the for loop sets error=0 on the first iteration for (n = 0, error = 0.0; n < gcam->ninputs; n++) { @@ -2219,7 +2260,8 @@ double gcamLogLikelihoodEnergy(const GCA_MORPH *gcam, MRI *mri) { return (sse); } -int gcamDistanceTerm(GCA_MORPH *gcam, MRI *mri, double l_distance) { +int gcamDistanceTerm(GCA_MORPH *gcam, MRI *mri, double l_distance) +{ double dx, dy, dz, error, d0, d, xdelta, ydelta, zdelta; int x, y, z, xk, yk, zk, xn, yn, zn, width, height, depth, num; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -2308,7 +2350,8 @@ int gcamDistanceTerm(GCA_MORPH *gcam, MRI *mri, double l_distance) { return (NO_ERROR); } -double gcamDistanceEnergy(GCA_MORPH *gcam, MRI *mri) { +double gcamDistanceEnergy(GCA_MORPH *gcam, MRI *mri) +{ double sse = 0.0, dx, dy, dz, error, node_sse, d0, d; int x, y, z, xk, yk, zk, xn, yn, zn, width, height, depth, num; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -2385,7 +2428,8 @@ double gcamDistanceEnergy(GCA_MORPH *gcam, MRI *mri) { #define AREA_NEIGHBORS 8 const float jac_scale = 10; #if 1 -int gcamJacobianTerm(GCA_MORPH *gcam, const MRI *mri, double l_jacobian, double ratio_thresh) { +int gcamJacobianTerm(GCA_MORPH *gcam, const MRI *mri, double l_jacobian, double ratio_thresh) +{ #ifdef GCAM_JACOB_TERM_GPU printf("%s: On GPU\n", __FUNCTION__); gcamJacobianTermGPU(gcam, l_jacobian, jac_scale); @@ -2477,7 +2521,9 @@ int gcamJacobianTerm(GCA_MORPH *gcam, const MRI *mri, double l_jacobian, double #ifdef HAVE_OPENMP #pragma omp parallel - { n_omp_threads = omp_get_num_threads(); } + { + n_omp_threads = omp_get_num_threads(); + } #else n_omp_threads = 1; #endif @@ -2557,7 +2603,8 @@ int gcamJacobianTerm(GCA_MORPH *gcam, const MRI *mri, double l_jacobian, double #else -int gcamJacobianTerm(GCA_MORPH *gcam, MRI *mri, double l_jacobian, double ratio_thresh) { +int gcamJacobianTerm(GCA_MORPH *gcam, MRI *mri, double l_jacobian, double ratio_thresh) +{ int i, j, k, num, xi, yi, zi, xk, yk, zk = 0; double dx, dy, dz, norm, max_norm; GCA_MORPH_NODE *gcamn; @@ -2702,7 +2749,8 @@ int gcamJacobianTerm(GCA_MORPH *gcam, MRI *mri, double l_jacobian, double ratio_ } #endif -int gcamAreaTerm(GCA_MORPH *gcam, double l_area) { +int gcamAreaTerm(GCA_MORPH *gcam, double l_area) +{ int i, j, k; double dx, dy, dz; GCA_MORPH_NODE *gcamn; @@ -2730,7 +2778,8 @@ int gcamAreaTerm(GCA_MORPH *gcam, double l_area) { return (NO_ERROR); } -int gcamAreaSmoothnessTerm(GCA_MORPH *gcam, MRI *mri, double l_area_smoothness) { +int gcamAreaSmoothnessTerm(GCA_MORPH *gcam, MRI *mri, double l_area_smoothness) +{ int i, j, k; double dx, dy, dz, Ix, Iy, Iz, norm, nc; GCA_MORPH_NODE *gcamn; @@ -2774,7 +2823,8 @@ int gcamAreaSmoothnessTerm(GCA_MORPH *gcam, MRI *mri, double l_area_smoothness) } int gcamJacobianTermAtNode( - GCA_MORPH *gcam, const MRI *mri, double l_jacobian, int i, int j, int k, double *pdx, double *pdy, double *pdz) { + GCA_MORPH *gcam, const MRI *mri, double l_jacobian, int i, int j, int k, double *pdx, double *pdy, double *pdz) +{ GCA_MORPH_NODE *gcamn, *gcamni, *gcamnj, *gcamnk; float delta, ratio; int n, width, height, depth, invert; @@ -2815,7 +2865,8 @@ int gcamJacobianTermAtNode( v_i_x_j[tid] = VectorAlloc(3, MATRIX_REAL); v_k_x_i[tid] = VectorAlloc(3, MATRIX_REAL); v_tmp[tid] = VectorAlloc(3, MATRIX_REAL); - } else { + } + else { V3_CLEAR(v_grad[tid]); } @@ -2905,7 +2956,8 @@ int gcamJacobianTermAtNode( { orig_area = gcamn->orig_area1; area = gcamn->area1; - } else // left-handed coordinate system + } + else // left-handed coordinate system { orig_area = gcamn->orig_area2; area = gcamn->area2; @@ -3028,7 +3080,8 @@ int gcamJacobianTermAtNode( #define NLT_PAD 10 int gcamVolumeChangeTermAtNode( - GCA_MORPH *gcam, MRI *mri, double l_area, int i, int j, int k, double *pdx, double *pdy, double *pdz) { + GCA_MORPH *gcam, MRI *mri, double l_area, int i, int j, int k, double *pdx, double *pdy, double *pdz) +{ GCA_MORPH_NODE *gcamn, *gcamni, *gcamnj, *gcamnk; float delta, total_delta = 0; int n, width = 0, height = 0, depth = 0, num, invert; @@ -3050,7 +3103,8 @@ int gcamVolumeChangeTermAtNode( v_i_x_j = VectorAlloc(3, MATRIX_REAL); v_k_x_i = VectorAlloc(3, MATRIX_REAL); v_tmp = VectorAlloc(3, MATRIX_REAL); - } else { + } + else { V3_CLEAR(v_grad); } @@ -3175,7 +3229,8 @@ int gcamVolumeChangeTermAtNode( { orig_area = gcamn->orig_area1; area = gcamn->area1; - } else // left-handed coordinate system + } + else // left-handed coordinate system { orig_area = gcamn->orig_area2; area = gcamn->area2; @@ -3244,7 +3299,8 @@ int gcamVolumeChangeTermAtNode( return (NO_ERROR); } -int gcamAreaTermAtNode(GCA_MORPH *gcam, double l_area, int i, int j, int k, double *pdx, double *pdy, double *pdz) { +int gcamAreaTermAtNode(GCA_MORPH *gcam, double l_area, int i, int j, int k, double *pdx, double *pdy, double *pdz) +{ GCA_MORPH_NODE *gcamn, *gcamni, *gcamnj, *gcamnk; float delta; int n, width = 0, height = 0, depth = 0, num, invert; @@ -3269,7 +3325,8 @@ int gcamAreaTermAtNode(GCA_MORPH *gcam, double l_area, int i, int j, int k, doub v_i_x_j = VectorAlloc(3, MATRIX_REAL); v_k_x_i = VectorAlloc(3, MATRIX_REAL); v_tmp = VectorAlloc(3, MATRIX_REAL); - } else { + } + else { V3_CLEAR(v_grad); } @@ -3450,7 +3507,8 @@ void SetGinvalid(const int val) { Ginvalid = val; } #define GCAM_CMP_OUTPUT 0 #if 1 -int gcamComputeMetricProperties(GCA_MORPH *gcam) { +int gcamComputeMetricProperties(GCA_MORPH *gcam) +{ #if GCAM_CMP_OUTPUT static unsigned int nCalls = 0; const unsigned int gcamCMPoutputFreq = 10; @@ -3479,7 +3537,9 @@ int gcamComputeMetricProperties(GCA_MORPH *gcam) { Ginvalid = 0; #ifdef HAVE_OPENMP #pragma omp parallel - { nthreads = omp_get_num_threads(); } + { + nthreads = omp_get_num_threads(); + } #else nthreads = 1; #endif @@ -3549,7 +3609,8 @@ int gcamComputeMetricProperties(GCA_MORPH *gcam) { // Accumulate onto common determinant gcamn->area += area1; } - } else { + } + else { // Going to the 'right' would fall out of the volume gcamn->area1 = 0; } @@ -3582,7 +3643,8 @@ int gcamComputeMetricProperties(GCA_MORPH *gcam) { // Accumulate onto common determinant gcamn->area += area2; } - } else { + } + else { // Going to the 'left' would fall out of the volume gcamn->area2 = 0; } @@ -3591,7 +3653,8 @@ int gcamComputeMetricProperties(GCA_MORPH *gcam) { if (num > 0) { // Store the average of computed determinants in the common determinant gcamn->area = gcamn->area / (float)num; // average volume - } else { + } + else { // If no determinants computed, this node becomes invalid if (i == Gx && j == Gy && k == Gz) { DiagBreak(); @@ -3658,7 +3721,8 @@ int gcamComputeMetricProperties(GCA_MORPH *gcam) { return (NO_ERROR); } #else -int gcamComputeMetricProperties(GCA_MORPH *gcam) { +int gcamComputeMetricProperties(GCA_MORPH *gcam) +{ double area; int i, j, k, width, height, depth, num, n, invert; GCA_MORPH_NODE *gcamn, *gcamni, *gcamnj, *gcamnk; @@ -3785,7 +3849,8 @@ int gcamComputeMetricProperties(GCA_MORPH *gcam) { gcamn = &gcam->nodes[i][j][k]; if (num > 0) { gcamn->area = area / (float)num; // average volume - } else { + } + else { if (i == Gx && j == Gy && k == Gz) { DiagBreak(); } @@ -3820,7 +3885,8 @@ int gcamComputeMetricProperties(GCA_MORPH *gcam) { #define GCAM_JACOBENERGY_OUTPUT 0 -double gcamJacobianEnergy(const GCA_MORPH *gcam, MRI *mri) { +double gcamJacobianEnergy(const GCA_MORPH *gcam, MRI *mri) +{ double sse = 0; #if GCAM_JACOBENERGY_OUTPUT @@ -3879,7 +3945,8 @@ double gcamJacobianEnergy(const GCA_MORPH *gcam, MRI *mri) { exponent = -gcam->exp_k * ratio; if (exponent > MAX_EXP) { delta = 0.0; - } else { + } + else { delta = log(1 + exp(exponent)) /* / gcam->exp_k */; } @@ -3904,7 +3971,8 @@ double gcamJacobianEnergy(const GCA_MORPH *gcam, MRI *mri) { if (exponent > MAX_EXP) { delta = MAX_EXP; - } else { + } + else { delta = log(1 + exp(exponent)) /* / gcam->exp_k */; } @@ -3934,7 +4002,8 @@ double gcamJacobianEnergy(const GCA_MORPH *gcam, MRI *mri) { return (sse); } -double gcamAreaEnergy(GCA_MORPH *gcam) { +double gcamAreaEnergy(GCA_MORPH *gcam) +{ double sse = 0.0, error; int i, j, k, width, height, depth; GCA_MORPH_NODE *gcamn; @@ -3971,7 +4040,8 @@ double gcamAreaEnergy(GCA_MORPH *gcam) { Applied inverse gcam morph to input. Currently NN and non-NN interpolation cases are treated differently. */ -MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int sample_type) { +MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int sample_type) +{ if (!sample_type) // NN interpolation { TRANSFORM _transform, *transform = &_transform; @@ -4001,7 +4071,8 @@ MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int samp if (GCAsourceVoxelToPriorReal(gcam->gca, mri_morphed, transform, x, y, z, &xr, &yr, &zr) != NO_ERROR) { continue; } - } else { + } + else { if (GCAMsampleInverseMorph(gcam, (float)x, (float)y, (float)z, &xf, &yf, &zf) != NO_ERROR) { continue; } @@ -4021,7 +4092,8 @@ MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int samp } return (mri_morphed); - } else { + } + else { #if 0 MRI *mri_warp ; @@ -4109,7 +4181,8 @@ MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int samp // if image is resampled often (e.g. in registration algo) { MRIsampleSeqBSpline(bspline, x, y, z, orig_vals, 0, frames - 1); - } else { + } + else { MRIsampleSeqVolumeType(mri_in, x, y, z, orig_vals, 0, frames - 1, sample_type); } #else @@ -4214,7 +4287,8 @@ MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int samp // if image is resampled often (e.g. in registration algo) { MRIsampleSeqBSpline(bspline, x, y, z, vals, 0, frames - 1); - } else { + } + else { MRIsampleSeqVolume(mri_s_morphed, x, y, z, vals, 0, frames - 1); } for (f = 0; f < frames; f++) { @@ -4231,7 +4305,8 @@ MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int samp /* copy from short image to BUFTYPE one */ if (!mri_morphed) { mri_morphed = MRIclone(mri_in, NULL); - } else { + } + else { MRIclear(mri_morphed); } @@ -4286,7 +4361,8 @@ MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int samp weight = (float)MRIFvox(mri_weights, x, y, z); if (weight > .1) { MRIvox(mri_ctrl, x, y, z) = 1; - } else { + } + else { MRIvox(mri_ctrl, x, y, z) = 0; } } @@ -4319,7 +4395,8 @@ MRI *GCAMmorphFromAtlas(MRI *mri_in, GCA_MORPH *gcam, MRI *mri_morphed, int samp GCAMmorphPlistFromAtlas: Applies inverse gcam morph to input point list. */ -int GCAMmorphPlistFromAtlas(int N, float *points_in, GCA_MORPH *gcam, float *points_out) { +int GCAMmorphPlistFromAtlas(int N, float *points_in, GCA_MORPH *gcam, float *points_out) +{ int sample_type = 0; // more options for sampling types: on the to do list int counter = 0; @@ -4361,7 +4438,8 @@ int GCAMmorphPlistFromAtlas(int N, float *points_in, GCA_MORPH *gcam, float *poi GCAMmorphPlistToSource: Transforms a list of points from the target space back to the source space. */ -int GCAMmorphPlistToSource(int N, float *points_in, GCA_MORPH *gcam, float *points_out) { +int GCAMmorphPlistToSource(int N, float *points_in, GCA_MORPH *gcam, float *points_out) +{ int sample_type = 0; // more options for sampling types: on the to do list int counter = 0; @@ -4397,7 +4475,8 @@ int GCAMmorphPlistToSource(int N, float *points_in, GCA_MORPH *gcam, float *poin return (1); } -MRI *GCAMmorphToAtlas(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame, int sample_type) { +MRI *GCAMmorphToAtlas(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame, int sample_type) +{ int width, height, depth, x, y, z, start_frame, end_frame; int out_of_gcam; float xd, yd, zd; @@ -4405,7 +4484,8 @@ MRI *GCAMmorphToAtlas(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame if (frame >= 0 && frame < mri_src->nframes) { start_frame = end_frame = frame; - } else { + } + else { start_frame = 0; end_frame = mri_src->nframes - 1; } @@ -4442,7 +4522,8 @@ MRI *GCAMmorphToAtlas(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame yoff = 24.88; zoff = -18.85; printf("INFO: adding MGH tal offset (%2.1f, %2.1f, %2.1f) to xform\n", xoff, yoff, zoff); - } else { + } + else { xoff = yoff = zoff = 0; } @@ -4485,10 +4566,12 @@ MRI *GCAMmorphToAtlas(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame if (xd > -1 && yd > -1 && zd > 0 && xd < mri_src->width && yd < mri_src->height && zd < mri_src->depth) { if (sample_type == SAMPLE_CUBIC_BSPLINE) { MRIsampleBSpline(bspline, xd, yd, zd, frame, &val); - } else + } + else MRIsampleVolumeFrameType(mri_src, xd, yd, zd, frame, sample_type, &val); // printf("Within GCAMmorphToAtlas: (%d, %d, %d): (%f, %f, %f): %f \n", x, y, z, xd, yd, zd, val) ; - } else { + } + else { val = 0.0; } MRIsetVoxVal(mri_morphed, x, y, z, frame - start_frame, val); @@ -4512,13 +4595,15 @@ MRI *GCAMmorphToAtlas(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame // now we cache transform and thus we have to do the following whenever // we change direction cosines MRIreInitCache(mri_morphed); - } else { + } + else { useVolGeomToMRI(&gcam->atlas, mri_morphed); } return (mri_morphed); } -MRI *GCAMmorphToAtlasWithDensityCorrection(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame) { +MRI *GCAMmorphToAtlasWithDensityCorrection(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame) +{ int width, height, depth, x, y, z, start_frame, end_frame; float xd, yd, zd; double val, jacobian; @@ -4534,7 +4619,8 @@ MRI *GCAMmorphToAtlasWithDensityCorrection(MRI *mri_src, GCA_MORPH *gcam, MRI *m depth = mri_morphed->depth; if (frame >= 0 && frame < mri_src->nframes) { start_frame = end_frame = frame; - } else { + } + else { start_frame = 0; end_frame = mri_src->nframes - 1; } @@ -4570,14 +4656,16 @@ MRI *GCAMmorphToAtlasWithDensityCorrection(MRI *mri_src, GCA_MORPH *gcam, MRI *m return (mri_morphed); } -MRI *GCAMmorphToAtlasType(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame, int interp_type) { +MRI *GCAMmorphToAtlasType(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int frame, int interp_type) +{ int width, height, depth, x, y, z, start_frame, end_frame; float xd, yd, zd; double val; if (frame >= 0 && frame < mri_src->nframes) { start_frame = end_frame = frame; - } else { + } + else { start_frame = 0; end_frame = mri_src->nframes - 1; } @@ -4623,9 +4711,11 @@ MRI *GCAMmorphToAtlasType(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int f // if image is resampled often (e.g. in registration algo) { MRIsampleBSpline(bspline, xd, yd, zd, frame, &val); - } else + } + else MRIsampleVolumeFrameType(mri_src, xd, yd, zd, frame, interp_type, &val); - } else { + } + else { val = 0.0; } MRIsetVoxVal(mri_morphed, x, y, z, frame - start_frame, val); @@ -4644,13 +4734,15 @@ MRI *GCAMmorphToAtlasType(MRI *mri_src, GCA_MORPH *gcam, MRI *mri_morphed, int f return (mri_morphed); } -int log_integration_parms(FILE *fp, GCA_MORPH_PARMS *parms) { +int log_integration_parms(FILE *fp, GCA_MORPH_PARMS *parms) +{ char *cp, host_name[STRLEN]; cp = getenv("HOST"); if (cp) { strcpy(host_name, cp); - } else { + } + else { strcpy(host_name, "unknown"); } @@ -4799,7 +4891,8 @@ static int nodesCompressed1, nodesCompressed2, nodesCompressed3; static int inconsistentLabelNodes; static float maxGradient, gradientArea; -int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARMS *parms) { +int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARMS *parms) +{ #ifdef GCAM_REGISTER_LEVEL_GPU printf("%s: On GPU\n", __FUNCTION__); gcamRegisterLevelGPU(gcam, mri, mri_smooth, parms); @@ -4953,7 +5046,8 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM parms->dt = min_dt; max_small = parms->nsmall; tol = parms->tol; - } else /* take some momentum steps */ + } + else /* take some momentum steps */ { max_small = 2 * parms->nsmall; tol = parms->tol / 2; @@ -5080,7 +5174,8 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM last_pct_change = pct_change; if (FZERO(last_rms)) { pct_change = 0.0; - } else { + } + else { pct_change = 100.0 * (last_rms - rms) / last_rms; } if ((pct_change < last_pct_change) || FZERO(pct_change)) { @@ -5088,7 +5183,8 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM printf("pct change decreased\n"); } increasing = 0; - } else /* could check for last_pct_change == 0 here */ + } + else /* could check for last_pct_change == 0 here */ { increasing = 1; } @@ -5165,7 +5261,8 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM which = GCAM_INTEGRATE_OPTIMAL; rms = GCAMcomputeRMS(gcam, mri, parms); good_step = good_step_ever = done = 0; - } else if ((++nsmall >= max_small) || (pct_change <= 0)) { + } + else if ((++nsmall >= max_small) || (pct_change <= 0)) { if (parms->integration_type == GCAM_INTEGRATE_BOTH) { if (!good_step) { done++; @@ -5179,11 +5276,13 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM which = GCAM_INTEGRATE_OPTIMAL; rms = GCAMcomputeRMS(gcam, mri, parms); good_step = good_step_ever = done = 0; - } else { + } + else { n++; break; } - } else /* switch integration types */ + } + else /* switch integration types */ { reduced = 0; if (which == GCAM_INTEGRATE_FIXED) { @@ -5194,7 +5293,8 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM gcamRemoveCompressedNodes(gcam, mri, parms, parms->ratio_thresh); } /* will search around this value */ - } else { + } + else { #if 0 if (good_step && parms->regrid == True) { @@ -5212,7 +5312,8 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM #else if (!DZERO(min_dt)) { parms->dt = min_dt; - } else { + } + else { min_dt = parms->dt = (sqrt(parms->navgs) + 1.0f) * orig_dt; } #endif @@ -5225,12 +5326,14 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM good_step = nsmall = 0; gcamClearMomentum(gcam); } - } else { + } + else { n++; break; } } - } else if (pct_change >= tol) /* took at least one good step */ + } + else if (pct_change >= tol) /* took at least one good step */ { good_step = good_step_ever = 1; done = 0; /* for integration type == BOTH, apply both types again */ @@ -5262,7 +5365,8 @@ int GCAMregisterLevel(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARM return (NO_ERROR); } -int mriFillRegion(MRI *mri, int x, int y, int z, int fill_val, int whalf) { +int mriFillRegion(MRI *mri, int x, int y, int z, int fill_val, int whalf) +{ int xi, xk, yi, yk, zi, zk; for (xk = -whalf; xk <= whalf; xk++) { @@ -5278,7 +5382,8 @@ int mriFillRegion(MRI *mri, int x, int y, int z, int fill_val, int whalf) { return (NO_ERROR); } -int write_snapshot(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, int iter) { +int write_snapshot(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, int iter) +{ char fname[STRLEN], base_name[STRLEN]; MRI *mri_morphed, *mri_samples; GCA_MORPH_NODE *gcamn; @@ -5295,7 +5400,8 @@ int write_snapshot(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, int iter) sprintf(base_name, "%s_%4.4d", parms->base_name, iter); if (getenv("DONT_COMPRESS")) { sprintf(fname, "%s.mgh", base_name); - } else { + } + else { sprintf(fname, "%s.mgz", base_name); } printf("writing snapshot to %s\n", fname); @@ -5310,7 +5416,8 @@ int write_snapshot(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, int iter) sprintf(base_name, "%s_%4.4d", parms->base_name, iter); if (getenv("DONT_COMPRESS")) { sprintf(fname, "%s_intensity.mgh", base_name); - } else { + } + else { sprintf(fname, "%s_intensity.mgz", base_name); } printf("writing snapshot to %s\n", fname); @@ -5331,7 +5438,8 @@ int write_snapshot(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, int iter) sprintf(base_name, "d2.%s_%4.4d", parms->base_name, iter); if (getenv("DONT_COMPRESS")) { sprintf(fname, "%s.mgh", base_name); - } else { + } + else { sprintf(fname, "%s.mgz", base_name); } printf("writing snapshot to %s\n", fname); @@ -5347,7 +5455,8 @@ int write_snapshot(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, int iter) sprintf(base_name, "d2.%s_%4.4d", parms->base_name, iter); if (getenv("DONT_COMPRESS")) { sprintf(fname, "%s_intensity.mgh", base_name); - } else { + } + else { sprintf(fname, "%s_intensity.mgz", base_name); } printf("writing snapshot to %s\n", fname); @@ -5417,20 +5526,27 @@ int write_snapshot(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, int iter) return (NO_ERROR); } -int boundsCheckf(float x, float y, float z, int width, int height, int depth) { +int boundsCheckf(float x, float y, float z, int width, int height, int depth) +{ if (x >= width) { return ERROR_BADPARM; - } else if (y >= height) { + } + else if (y >= height) { return ERROR_BADPARM; - } else if (z >= depth) { + } + else if (z >= depth) { return ERROR_BADPARM; - } else if (x < 0) { + } + else if (x < 0) { return ERROR_BADPARM; - } else if (y < 0) { + } + else if (y < 0) { return ERROR_BADPARM; - } else if (z < 0) { + } + else if (z < 0) { return ERROR_BADPARM; - } else { + } + else { return NO_ERROR; } } @@ -5448,7 +5564,8 @@ int boundsCheckf(float x, float y, float z, int width, int height, int depth) { (but not really), computes the CRS in the UnMorphed-anatomical-space volume. This should produce the inverse of GCAMsampleInverseMorph(). ---------------------------------------------------------------------------*/ -int GCAMsampleMorph(const GCA_MORPH *gcam, float x, float y, float z, float *pxd, float *pyd, float *pzd) { +int GCAMsampleMorph(const GCA_MORPH *gcam, float x, float y, float z, float *pxd, float *pyd, float *pzd) +{ int xm, xp, ym, yp, zm, zp, width, height, depth; float xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ int errCode = NO_ERROR; @@ -5510,7 +5627,8 @@ int GCAMsampleMorph(const GCA_MORPH *gcam, float x, float y, float z, float *pxd produce the inverse of GCAMsampleMorph(). ---------------------------------------------------------------------------*/ int GCAMsampleInverseMorph( - GCA_MORPH *gcam, float cAnat, float rAnat, float sAnat, float *cMorph, float *rMorph, float *sMorph) { + GCA_MORPH *gcam, float cAnat, float rAnat, float sAnat, float *cMorph, float *rMorph, float *sMorph) +{ int err; double v; @@ -5546,7 +5664,8 @@ int GCAMsampleInverseMorph( if there was some other problem. Typical distances are less than 0.5, which does not seem all that great to me. Also, not all input CRSs will be valid. -------------------------------------------------------------------------*/ -int GCAMsampleMorphCheck(GCA_MORPH *gcam, float thresh, float cMorph, float rMorph, float sMorph) { +int GCAMsampleMorphCheck(GCA_MORPH *gcam, float thresh, float cMorph, float rMorph, float sMorph) +{ int err; float cAnat, rAnat, sAnat; float cMorph2, rMorph2, sMorph2; @@ -5597,7 +5716,8 @@ int GCAMsampleMorphCheck(GCA_MORPH *gcam, float thresh, float cMorph, float rMor also GCAMsampleInverseMorphRAS(). --------------------------------------------------------------------------*/ int GCAMsampleMorphRAS( - GCA_MORPH *gcam, float xMorph, float yMorph, float zMorph, float *xAnat, float *yAnat, float *zAnat) { + GCA_MORPH *gcam, float xMorph, float yMorph, float zMorph, float *xAnat, float *yAnat, float *zAnat) +{ static int init_needed = 1, err; static MATRIX *ras = NULL, *crs = NULL, *vox2ras = NULL, *ras2vox = NULL; float cMorph, rMorph, sMorph; @@ -5656,7 +5776,8 @@ int GCAMsampleMorphRAS( also GCAMsampleMorphRAS(). --------------------------------------------------------------------------*/ int GCAMsampleInverseMorphRAS( - GCA_MORPH *gcam, float xAnat, float yAnat, float zAnat, float *xMorph, float *yMorph, float *zMorph) { + GCA_MORPH *gcam, float xAnat, float yAnat, float zAnat, float *xMorph, float *yMorph, float *zMorph) +{ static int init_needed = 1, err; static MATRIX *ras = NULL, *crs = NULL, *vox2ras = NULL, *ras2vox = NULL; float cMorph = 0., rMorph = 0., sMorph = 0.; @@ -5712,7 +5833,8 @@ int GCAMsampleInverseMorphRAS( GCAMmorphSurf() - compute the vertex xyz in the morph space. Replaces vertex xyz. Does not recompute the metric properties of the surface. ---------------------------------------------------------------------*/ -int GCAMmorphSurf(MRIS *mris, GCA_MORPH *gcam) { +int GCAMmorphSurf(MRIS *mris, GCA_MORPH *gcam) +{ int vtxno, err; VERTEX *v; float Mx = 0, My = 0, Mz = 0; @@ -5734,7 +5856,8 @@ int GCAMmorphSurf(MRIS *mris, GCA_MORPH *gcam) { return (0); } -double GCAMcomputeRMS(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { +double GCAMcomputeRMS(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) +{ double rms; #ifdef GCAM_COMPUTE_RMS_GPU @@ -5754,7 +5877,8 @@ double GCAMcomputeRMS(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { } #define BIN_SCALE 1 -double gcamComputeSSE(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { +double gcamComputeSSE(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) +{ double sse; double elastic_sse = 0; @@ -5870,7 +5994,8 @@ double gcamComputeSSE(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { return (sse); } -int gcamComputeGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARMS *parms) { +int gcamComputeGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PARMS *parms) +{ #ifdef GCAM_COMPUTE_GRADIENT_GPU printf("%s: On GPU\n", __FUNCTION__); gcamComputeGradientGPU(gcam, mri, mri_smooth, parms); @@ -5978,7 +6103,8 @@ int gcamComputeGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, GCA_MORPH_PA return (NO_ERROR); } -double gcamMaxGradient(GCA_MORPH *gcam) { +double gcamMaxGradient(GCA_MORPH *gcam) +{ int x, y, z; double dx, dy, dz, norm, max_grad; GCA_MORPH_NODE *gcamn; @@ -5999,7 +6125,8 @@ double gcamMaxGradient(GCA_MORPH *gcam) { return (max_grad); } -int gcamLimitGradientMagnitude(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri) { +int gcamLimitGradientMagnitude(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri) +{ /*! This appears to be a null operation, according to the #ifdefs both here and in gcamJacobianTerm @@ -6107,7 +6234,8 @@ int gcamLimitGradientMagnitude(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri MRIsampleVolumeFrameType(parms->mri_dist_map, gcamn->x, gcamn->y, gcamn->z, frame, SAMPLE_TRILINEAR, &dist); printf("dist:target = %2.2f:%2.2f ", dist, gcamn->target_dist); - } else { + } + else { printf("vals(means) = "); load_vals(mri, gcamn->x, gcamn->y, gcamn->z, vals, gcam->ninputs); for (r = 0; r < gcam->ninputs; r++) printf("%2.1f (%2.1f) ", vals[r], gcamn->gc ? gcamn->gc->means[r] : -0.0); @@ -6154,7 +6282,8 @@ int gcamLimitGradientMagnitude(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri return (NO_ERROR); } -int gcamSmoothnessTerm(GCA_MORPH *gcam, const MRI *mri, const double l_smoothness) { +int gcamSmoothnessTerm(GCA_MORPH *gcam, const MRI *mri, const double l_smoothness) +{ #ifdef GCAM_SMOOTH_TERM_GPU printf("%s: On GPU\n", __FUNCTION__); gcamSmoothnessTermGPU(gcam, l_smoothness); @@ -6278,7 +6407,8 @@ int gcamSmoothnessTerm(GCA_MORPH *gcam, const MRI *mri, const double l_smoothnes #define GCAM_SMOOTHNESS_OUTPUT 0 -double gcamElasticEnergy(const GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) { +double gcamElasticEnergy(const GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) +{ MRI *mri_warp, *mri_sobel[3]; int x, y, z, dim1, dim2; double energy, val1, val2, lambda, mu, rigid_energy, volume_change, svals[3][3]; @@ -6322,7 +6452,8 @@ double gcamElasticEnergy(const GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) { return (energy); } -int gcamElasticTerm(const GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) { +int gcamElasticTerm(const GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) +{ MRI *mri_warp, *mri_tmp, *mri_divergence, *mri_laplacian, *mri_grad, *mri_kernel; int x, y, z, dim; double val1, val2, grad[3], lambda, mu; @@ -6375,7 +6506,8 @@ int gcamElasticTerm(const GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) { return (NO_ERROR); } -double gcamSmoothnessEnergy(const GCA_MORPH *gcam, const MRI *mri) { +double gcamSmoothnessEnergy(const GCA_MORPH *gcam, const MRI *mri) +{ /*! Computes a load of derivatives (of some description). I don't know the purpose of the MRI argument, since it's @@ -6503,7 +6635,8 @@ double gcamSmoothnessEnergy(const GCA_MORPH *gcam, const MRI *mri) { return (sse); } -int gcamLSmoothnessTerm(GCA_MORPH *gcam, MRI *mri, double l_smoothness) { +int gcamLSmoothnessTerm(GCA_MORPH *gcam, MRI *mri, double l_smoothness) +{ double vx, vy, vz, vnx, vny, vnz, dx, dy, dz; int x, y, z, xk, yk, zk, xn, yn, zn, width, height, depth, num; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -6595,7 +6728,8 @@ int gcamLSmoothnessTerm(GCA_MORPH *gcam, MRI *mri, double l_smoothness) { return (NO_ERROR); } -double gcamLSmoothnessEnergy(GCA_MORPH *gcam, MRI *mri) { +double gcamLSmoothnessEnergy(GCA_MORPH *gcam, MRI *mri) +{ double sse = 0.0, vx, vy, vz, vnx, vny, vnz, error, node_sse, dx, dy, dz; int x, y, z, xk, yk, zk, xn, yn, zn, width, height, depth, num; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -6665,7 +6799,8 @@ double gcamLSmoothnessEnergy(GCA_MORPH *gcam, MRI *mri) { return (sse); } -int gcamSpringTerm(GCA_MORPH *gcam, double l_spring, double ratio_thresh) { +int gcamSpringTerm(GCA_MORPH *gcam, double l_spring, double ratio_thresh) +{ double xc, yc, zc, dx, dy, dz; int x, y, z, xk, yk, zk, xn, yn, zn, width, height, depth, num; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -6840,7 +6975,8 @@ gcamInvalidSpringTerm(GCA_MORPH *gcam, double l_spring) } #endif -double gcamSpringEnergy(GCA_MORPH *gcam, double ratio_thresh) { +double gcamSpringEnergy(GCA_MORPH *gcam, double ratio_thresh) +{ double sse = 0.0, xc, yc, zc, node_sse, dx, dy, dz; int x, y, z, xk, yk, zk, xn, yn, zn, width, height, depth, num; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -6909,7 +7045,8 @@ double gcamSpringEnergy(GCA_MORPH *gcam, double ratio_thresh) { return (sse); } -int gcamClearGradient(GCA_MORPH *gcam) { +int gcamClearGradient(GCA_MORPH *gcam) +{ int x, y, z; for (x = 0; x < gcam->width; x++) @@ -6919,7 +7056,8 @@ int gcamClearGradient(GCA_MORPH *gcam) { return (NO_ERROR); } -int gcamApplyGradient(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) { +int gcamApplyGradient(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) +{ int x, y, z; float dx, dy, dz, dt, momentum; GCA_MORPH_NODE *gcamn; @@ -6971,7 +7109,8 @@ int gcamApplyGradient(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms) { return (NO_ERROR); } -int gcamClearMomentum(GCA_MORPH *gcam) { +int gcamClearMomentum(GCA_MORPH *gcam) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -6993,7 +7132,8 @@ int gcamClearMomentum(GCA_MORPH *gcam) { Description ------------------------------------------------------*/ -int finitep(float f) { +int finitep(float f) +{ if (!isfinite(f)) { return (0); } @@ -7003,7 +7143,8 @@ int finitep(float f) { return (1); } -int GCAMcomputeLabels(MRI *mri, GCA_MORPH *gcam) { +int GCAMcomputeLabels(MRI *mri, GCA_MORPH *gcam) +{ int x, y, z, width, height, depth, label, n, nchanged = 0; float vals[MAX_GCA_INPUTS]; GCA_MORPH_NODE *gcamn; @@ -7083,7 +7224,8 @@ int GCAMcomputeLabels(MRI *mri, GCA_MORPH *gcam) { gcamn->gc ? sqrt(covariance_determinant(gcamn->gc, gcam->ninputs)) : 0.0, gcamn->prior, vals[0]); - } else /* out of FOV probably */ + } + else /* out of FOV probably */ { gcamn->label = label; gcamn->n = 0; @@ -7116,7 +7258,8 @@ int GCAMcomputeLabels(MRI *mri, GCA_MORPH *gcam) { return (nchanged); } -int GCAMcomputeMaxPriorLabels(GCA_MORPH *gcam) { +int GCAMcomputeMaxPriorLabels(GCA_MORPH *gcam) +{ int x, y, z, width, height, depth, label, n, nchanged = 0, max_n; GCA_MORPH_NODE *gcamn; GC1D *gc; @@ -7164,7 +7307,8 @@ int GCAMcomputeMaxPriorLabels(GCA_MORPH *gcam) { GCApriorToNode(gcam->gca, x, y, z, &xn, &yn, &zn); gcamn->gc = gc = GCAfindClosestValidGC(gcam->gca, xn, yn, zn, label, 0); } - } else /* out of FOV probably */ + } + else /* out of FOV probably */ { int xn, yn, zn; GCApriorToNode(gcam->gca, x, y, z, &xn, &yn, &zn); @@ -7195,7 +7339,8 @@ int GCAMcomputeMaxPriorLabels(GCA_MORPH *gcam) { return (NO_ERROR); } -MRI *GCAMbuildMostLikelyVolume(GCA_MORPH *gcam, MRI *mri) { +MRI *GCAMbuildMostLikelyVolume(GCA_MORPH *gcam, MRI *mri) +{ int x, y, z, xn, yn, zn, width, depth, height, n; GCA_MORPH_NODE *gcamn; float val; @@ -7235,7 +7380,8 @@ MRI *GCAMbuildMostLikelyVolume(GCA_MORPH *gcam, MRI *mri) { for (n = 0; n < gcam->ninputs; n++) { if (gcamn->gc) { val = gcamn->gc->means[n]; - } else { + } + else { val = 0; } @@ -7259,7 +7405,8 @@ MRI *GCAMbuildMostLikelyVolume(GCA_MORPH *gcam, MRI *mri) { } } } - } else // no gca + } + else // no gca { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { @@ -7277,7 +7424,8 @@ MRI *GCAMbuildMostLikelyVolume(GCA_MORPH *gcam, MRI *mri) { for (n = 0; n < gcam->ninputs; n++) { if (gcamn->gc) { val = gcamn->gc->means[n]; - } else { + } + else { val = 0; } @@ -7305,7 +7453,8 @@ MRI *GCAMbuildMostLikelyVolume(GCA_MORPH *gcam, MRI *mri) { return (mri); } -MRI *GCAMbuildVolume(GCA_MORPH *gcam, MRI *mri) { +MRI *GCAMbuildVolume(GCA_MORPH *gcam, MRI *mri) +{ int x, y, z, xn, yn, zn, width, depth, height, n; GCA_MORPH_NODE *gcamn; float val; @@ -7340,7 +7489,8 @@ MRI *GCAMbuildVolume(GCA_MORPH *gcam, MRI *mri) { for (n = 0; n < gcam->ninputs; n++) { if (gcamn->gc) { val = gcamn->gc->means[n]; - } else { + } + else { val = 0; } @@ -7367,7 +7517,8 @@ MRI *GCAMbuildVolume(GCA_MORPH *gcam, MRI *mri) { return (mri); } -int GCAMinvert(GCA_MORPH *gcam, MRI *mri) { +int GCAMinvert(GCA_MORPH *gcam, MRI *mri) +{ int x, y, z, width, height, depth, xv, yv, zv; MRI *mri_ctrl, *mri_counts; GCA_MORPH_NODE *gcamn; @@ -7563,7 +7714,8 @@ int GCAMinvert(GCA_MORPH *gcam, MRI *mri) { return (NO_ERROR); } -int GCAMfreeInverse(GCA_MORPH *gcam) { +int GCAMfreeInverse(GCA_MORPH *gcam) +{ if (gcam->mri_xind) { MRIfree(&gcam->mri_xind); } @@ -7576,7 +7728,8 @@ int GCAMfreeInverse(GCA_MORPH *gcam) { return (NO_ERROR); } -int gcamUndoGradient(GCA_MORPH *gcam) { +int gcamUndoGradient(GCA_MORPH *gcam) +{ int x, y, z; float dx, dy, dz; GCA_MORPH_NODE *gcamn; @@ -7622,7 +7775,8 @@ int gcamUndoGradient(GCA_MORPH *gcam) { return (NO_ERROR); } -int gcamReadMRI(GCA_MORPH *gcam, MRI *mri, int which) { +int gcamReadMRI(GCA_MORPH *gcam, MRI *mri, int which) +{ int x, y, z, i; float d; GCA_MORPH_NODE *gcamn; @@ -7710,7 +7864,8 @@ int gcamReadMRI(GCA_MORPH *gcam, MRI *mri, int which) { return (NO_ERROR); } -MRI *GCAMwriteMRI(GCA_MORPH *gcam, MRI *mri, int which) { +MRI *GCAMwriteMRI(GCA_MORPH *gcam, MRI *mri, int which) +{ int x, y, z; float d; GCA_MORPH_NODE *gcamn; @@ -7774,7 +7929,8 @@ MRI *GCAMwriteMRI(GCA_MORPH *gcam, MRI *mri, int which) { d = -log10(fabs(d)); else d = log10(fabs(d)); - } else + } + else d = 0; break; case GCAM_X_GRAD: @@ -7838,7 +7994,8 @@ MRI *GCAMwriteMRI(GCA_MORPH *gcam, MRI *mri, int which) { return (mri); } -int gcamSmoothGradient(GCA_MORPH *gcam, int navgs) { +int gcamSmoothGradient(GCA_MORPH *gcam, int navgs) +{ #ifdef GCAM_SMOOTH_GRADIENT_GPU printf("%s: On GPU\n", __FUNCTION__); gcamSmoothGradientGPU(gcam, navgs); @@ -7991,7 +8148,8 @@ int gcamSmoothGradient(GCA_MORPH *gcam, int navgs) { return (NO_ERROR); } -int GCAMsetStatus(GCA_MORPH *gcam, int status) { +int GCAMsetStatus(GCA_MORPH *gcam, int status) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -8008,7 +8166,8 @@ int GCAMsetStatus(GCA_MORPH *gcam, int status) { return (NO_ERROR); } -int GCAMsetLabelStatus(GCA_MORPH *gcam, int label, int status) { +int GCAMsetLabelStatus(GCA_MORPH *gcam, int label, int status) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -8031,7 +8190,8 @@ int GCAMsetLabelStatus(GCA_MORPH *gcam, int label, int status) { #define GCAM_FOTS_OUTPUT 0 #define GCAM_FOTS_TIMERS 0 -double gcamFindOptimalTimeStep(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri) { +double gcamFindOptimalTimeStep(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri) +{ #if GCAM_FOTS_TIMERS Chronometer tFOTS; @@ -8126,7 +8286,8 @@ double gcamFindOptimalTimeStep(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri continue; } } - } else { + } + else { prev_neg = suppressed = 0; } @@ -8313,7 +8474,8 @@ double gcamFindOptimalTimeStep(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, MRI *mri #define GCAM_LABELENERGY_OUTPUT 0 -double gcamLabelEnergy(const GCA_MORPH *gcam, const MRI *mri, const double label_dist) { +double gcamLabelEnergy(const GCA_MORPH *gcam, const MRI *mri, const double label_dist) +{ #if GCAM_LABELENERGY_OUTPUT const unsigned int gcamLabelEnergyOutputFreq = 10; static unsigned int nCalls = 0; @@ -8370,7 +8532,8 @@ double gcamLabelEnergy(const GCA_MORPH *gcam, const MRI *mri, const double label #define GCAM_REMOVE_LABEL_OUTLIERS_OUTPUT 0 -int remove_label_outliers(GCA_MORPH *gcam, MRI *mri_dist, const int whalf, const double thresh) { +int remove_label_outliers(GCA_MORPH *gcam, MRI *mri_dist, const int whalf, const double thresh) +{ int nremoved; #ifdef GCAM_LABEL_TERM_REMOVE_OUTLIERS_GPU @@ -8592,7 +8755,8 @@ int remove_label_outliers(GCA_MORPH *gcam, MRI *mri_dist, const int whalf, const #define GCAM_LABEL_COPYDELTAS_OUTPUT 0 -void gcamLabelTermCopyDeltas(GCA_MORPH *gcam, const MRI *mri_dist, const double l_label) { +void gcamLabelTermCopyDeltas(GCA_MORPH *gcam, const MRI *mri_dist, const double l_label) +{ #ifdef GCAM_LABEL_TERM_COPYDELTAS_GPU printf("%s: On GPU\n", __FUNCTION__); @@ -8650,7 +8814,8 @@ void gcamLabelTermCopyDeltas(GCA_MORPH *gcam, const MRI *mri_dist, const double #define GCAM_LABEL_POSTANTCONSIST_OUTPUT 0 -int gcamLabelTermPostAntConsistency(GCA_MORPH *gcam, MRI *mri_dist) { +int gcamLabelTermPostAntConsistency(GCA_MORPH *gcam, MRI *mri_dist) +{ /*! The main loop within this routine is very nasty. Each voxel depends on those on either side in x, @@ -8756,7 +8921,8 @@ int gcamLabelTermPostAntConsistency(GCA_MORPH *gcam, MRI *mri_dist) { #define GCAM_LABELFINAL_OUTPUT 0 -int gcamLabelTermFinalUpdate(GCA_MORPH *gcam, const MRI *mri_dist, const double l_label) { +int gcamLabelTermFinalUpdate(GCA_MORPH *gcam, const MRI *mri_dist, const double l_label) +{ #ifdef GCAM_LABEL_TERM_FINAL_GPU int num; @@ -8818,7 +8984,8 @@ int gcamLabelTermFinalUpdate(GCA_MORPH *gcam, const MRI *mri_dist, const double //! Sliced out of gcamLabelTerm void gcamLabelTermMainLoop( - GCA_MORPH *gcam, const MRI *mri, MRI *mri_dist, const double l_label, const double label_dist, MRI *mri_twm) { + GCA_MORPH *gcam, const MRI *mri, MRI *mri_dist, const double l_label, const double label_dist, MRI *mri_twm) +{ #ifdef GCAM_LABEL_TERM_MAINLOOP_GPU printf("%s: On GPU\n", __FUNCTION__); @@ -9018,7 +9185,8 @@ void gcamLabelTermMainLoop( min_dist = yk; } } - } else if (!ctrl_point_found) // adjust estimated position to be at most likely value + } + else if (!ctrl_point_found) // adjust estimated position to be at most likely value { double log_p, max_log_p; double ykmin, ykmax; @@ -9100,7 +9268,8 @@ void gcamLabelTermMainLoop( #define GCAM_LABEL_TERM_TIMERS 0 -void SetInconsistentLabelNodes(const int val) { +void SetInconsistentLabelNodes(const int val) +{ /*! This is a call back from the GPU version of Label Term. I'm not sure if the inconsistentLabelNodes global is @@ -9111,7 +9280,8 @@ void SetInconsistentLabelNodes(const int val) { #define GCAM_LABEL_TERM_OUTPUT 0 -int gcamLabelTerm(GCA_MORPH *gcam, const MRI *mri, double l_label, double label_dist, MRI *mri_twm) { +int gcamLabelTerm(GCA_MORPH *gcam, const MRI *mri, double l_label, double label_dist, MRI *mri_twm) +{ #ifdef GCAM_LABEL_TERM_MAINLOOP_GPU printf("%s: On GPU\n", __FUNCTION__); @@ -9194,7 +9364,8 @@ int gcamLabelTerm(GCA_MORPH *gcam, const MRI *mri, double l_label, double label_ return (NO_ERROR); } -int gcamMapTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_map) { +int gcamMapTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_map) +{ int x = 0, y = 0, z = 0, n = 0, i = 0; int xn[_MAX_FS_THREADS], yn[_MAX_FS_THREADS], zn[_MAX_FS_THREADS]; int tid; @@ -9339,7 +9510,8 @@ int gcamMapTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_map) { return (NO_ERROR); } -double gcamMapEnergy(GCA_MORPH *gcam, MRI *mri) { +double gcamMapEnergy(GCA_MORPH *gcam, MRI *mri) +{ int x, y, z, n, xn, yn, zn; double sse, node_prob, prob; GCA_MORPH_NODE *gcamn; @@ -9410,7 +9582,8 @@ gcamMLElabelAtLocation(GCA_MORPH *gcam, int x, int y, int z, float *vals) } #endif -int GCAMstoreMetricProperties(GCA_MORPH *gcam) { +int GCAMstoreMetricProperties(GCA_MORPH *gcam) +{ int x, y, z; gcamComputeMetricProperties(gcam); @@ -9432,7 +9605,8 @@ int GCAMstoreMetricProperties(GCA_MORPH *gcam) { return (NO_ERROR); } -int GCAMcomputeOriginalProperties(GCA_MORPH *gcam) { +int GCAMcomputeOriginalProperties(GCA_MORPH *gcam) +{ GCAMcopyNodePositions(gcam, CURRENT_POSITIONS, SAVED_POSITIONS); GCAMcopyNodePositions(gcam, ORIGINAL_POSITIONS, CURRENT_POSITIONS); gcamComputeMetricProperties(gcam); @@ -9442,7 +9616,8 @@ int GCAMcomputeOriginalProperties(GCA_MORPH *gcam) { return (NO_ERROR); } -int GCAMcopyNodePositions(GCA_MORPH *gcam, int from, int to) { +int GCAMcopyNodePositions(GCA_MORPH *gcam, int from, int to) +{ #ifdef GCAM_COPY_NODE_POSITIONS_GPU printf("%s: On GPU\n", __FUNCTION__); GCAMcopyNodePositionsGPU(gcam, from, to); @@ -9583,7 +9758,8 @@ int GCAMcopyNodePositions(GCA_MORPH *gcam, int from, int to) { return (NO_ERROR); } -int gcamRemoveCompressedNodes(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, float compression_ratio) { +int gcamRemoveCompressedNodes(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, float compression_ratio) +{ GCA_MORPH_PARMS saved_parms = *parms; double min_dt, orig_dt, rms, last_rms, pct_change, max_grad, lattice_spacing; int old_compressed, new_compressed, i, delta, integration_type, done, nsmall, good_step, nfixed = 0, start_neg; @@ -9686,12 +9862,14 @@ int gcamRemoveCompressedNodes(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, good_step = 0; printf("switching integration type to optimal\n"); } - } else { + } + else { printf("switching integration type to fixed\n"); nfixed = 0; integration_type = GCAM_INTEGRATE_FIXED; } - } else { + } + else { nsmall = 0; good_step = 1; } @@ -9716,7 +9894,8 @@ int gcamRemoveCompressedNodes(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms, #define MAX_NEG_ITER 100 -int GCAMremoveNegativeNodes(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { +int GCAMremoveNegativeNodes(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) +{ GCA_MORPH_PARMS saved_parms = *parms; double min_dt, orig_dt = parms->orig_dt, rms, last_rms, pct_change; int old_neg, new_neg, i, run; @@ -9790,7 +9969,8 @@ int GCAMremoveNegativeNodes(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { return (NO_ERROR); } -int check_gcam(const GCAM *gcam) { +int check_gcam(const GCAM *gcam) +{ if ((abs(gcam->width) > 10000) || (abs(gcam->height) > 10000) || (abs(gcam->depth) > 10000)) { DiagBreak(); printf("gcam dimensions invalid - (%d, %d, %d)\n", gcam->width, gcam->height, gcam->depth); @@ -9828,7 +10008,8 @@ int check_gcam(const GCAM *gcam) { #define MAX_TEMPORAL_WM 3 int is_temporal_wm( - const GCA_MORPH *gcam, const MRI *mri, const GCA_NODE *gcan, float xf, float yf, float zf, int ninputs) { + const GCA_MORPH *gcam, const MRI *mri, const GCA_NODE *gcan, float xf, float yf, float zf, int ninputs) +{ int yk, label, nwhite; float vals[MAX_GCA_INPUTS], yi; @@ -9853,7 +10034,8 @@ int is_temporal_wm( label = GCAmaxLikelihoodLabel(gcan, vals, gcam->ninputs, NULL); if (IS_WM(label) || IS_THALAMUS(label)) { nwhite++; - } else { + } + else { break; /* if moving inferiorly and find non-wm voxel, then stop counting - should be hippo */ } } @@ -9861,7 +10043,8 @@ int is_temporal_wm( return (nwhite <= MAX_TEMPORAL_WM); /* must be main body of white matter - too much of it */ } -int GCAMapplyTransform(GCA_MORPH *gcam, TRANSFORM *transform) { +int GCAMapplyTransform(GCA_MORPH *gcam, TRANSFORM *transform) +{ int x, y, z; float xf, yf, zf; GCA_MORPH_NODE *gcamn; @@ -9900,7 +10083,8 @@ int GCAMapplyTransform(GCA_MORPH *gcam, TRANSFORM *transform) { } return (NO_ERROR); } -int GCAMapplyInverseTransform(GCA_MORPH *gcam, TRANSFORM *transform) { +int GCAMapplyInverseTransform(GCA_MORPH *gcam, TRANSFORM *transform) +{ int x, y, z; float xf, yf, zf; GCA_MORPH_NODE *gcamn; @@ -9940,7 +10124,8 @@ int GCAMapplyInverseTransform(GCA_MORPH *gcam, TRANSFORM *transform) { } return (NO_ERROR); } -int GCAMmarkNegativeNodesInvalid(GCA_MORPH *gcam) { +int GCAMmarkNegativeNodesInvalid(GCA_MORPH *gcam) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -9957,7 +10142,8 @@ int GCAMmarkNegativeNodesInvalid(GCA_MORPH *gcam) { } return (NO_ERROR); } -int GCAMmarkNegativeBorderNodesInvalid(GCA_MORPH *gcam) { +int GCAMmarkNegativeBorderNodesInvalid(GCA_MORPH *gcam) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -9978,7 +10164,8 @@ int GCAMmarkNegativeBorderNodesInvalid(GCA_MORPH *gcam) { return (NO_ERROR); } -int zero_vals(float *vals, int nvals) { +int zero_vals(float *vals, int nvals) +{ int n, z; for (z = 1, n = 0; n < nvals; n++) @@ -9990,7 +10177,8 @@ int zero_vals(float *vals, int nvals) { return (z); } -int different_neighbor_labels(const GCA_MORPH *gcam, const int x, const int y, const int z, const int whalf) { +int different_neighbor_labels(const GCA_MORPH *gcam, const int x, const int y, const int z, const int whalf) +{ int label, num, i, j, k; label = gcam->nodes[x][y][z].label; @@ -10018,7 +10206,8 @@ int different_neighbor_labels(const GCA_MORPH *gcam, const int x, const int y, c return (num); } -MRI *gcamCreateJacobianImage(GCA_MORPH *gcam) { +MRI *gcamCreateJacobianImage(GCA_MORPH *gcam) +{ GCA_MORPH_NODE *gcamn; MRI *mri; int x, y, z; @@ -10033,10 +10222,12 @@ MRI *gcamCreateJacobianImage(GCA_MORPH *gcam) { gcamn = &gcam->nodes[x][y][z]; if (!FZERO(gcamn->area)) { jacobian = gcamn->orig_area / gcamn->area; - } else { + } + else { if (FZERO(gcamn->orig_area)) { jacobian = 1; - } else { + } + else { jacobian = .001; } } @@ -10052,7 +10243,8 @@ MRI *gcamCreateJacobianImage(GCA_MORPH *gcam) { return (mri); } -MRI *GCAMextract_density_map(MRI *mri_seg, MRI *mri_intensity, GCA_MORPH *gcam, int target_label, MRI *mri_out) { +MRI *GCAMextract_density_map(MRI *mri_seg, MRI *mri_intensity, GCA_MORPH *gcam, int target_label, MRI *mri_out) +{ int whalf, x, y, z /*, xv, yv, zv*/; // float xa, ya, za ; MRI *mri_density; @@ -10157,7 +10349,8 @@ MRI *GCAMextract_density_map(MRI *mri_seg, MRI *mri_intensity, GCA_MORPH *gcam, return (mri_out); } -int GCAMsample(GCA_MORPH *gcam, float xv, float yv, float zv, float *px, float *py, float *pz) { +int GCAMsample(GCA_MORPH *gcam, float xv, float yv, float zv, float *px, float *py, float *pz) +{ double xt, yt, zt; #if 0 int xi, yi, zi ; @@ -10202,7 +10395,8 @@ int GCAMsample(GCA_MORPH *gcam, float xv, float yv, float zv, float *px, float * *pz = zt; return (NO_ERROR); } -int GCAMinitLabels(GCA_MORPH *gcam, MRI *mri_labeled) { +int GCAMinitLabels(GCA_MORPH *gcam, MRI *mri_labeled) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -10215,12 +10409,14 @@ int GCAMinitLabels(GCA_MORPH *gcam, MRI *mri_labeled) { gcamn = &gcam->nodes[x][y][z]; if (mri_labeled == NULL) { gcamn->label = gcamn->gc ? 128 : 0; - } else { + } + else { gcamn->label = MRIgetVoxVal(mri_labeled, x, y, z, 0); } if (gcamn->label > 0) { DiagBreak(); - } else { + } + else { DiagBreak(); } } @@ -10231,7 +10427,8 @@ int GCAMinitLabels(GCA_MORPH *gcam, MRI *mri_labeled) { #define MAX_NODES 1000 #define AINT_NBHD_SIZE 0 -double gcamAreaIntensityEnergy(GCA_MORPH *gcam, MRI *mri, NODE_LOOKUP_TABLE *nlt) { +double gcamAreaIntensityEnergy(GCA_MORPH *gcam, MRI *mri, NODE_LOOKUP_TABLE *nlt) +{ double sse, val, image_val, sum_v, sum_uv, error, c, distsq, x0, y0, z0, dx, dy, dz, max_increase; int x, y, z, xn, yn, zn, i, debug = 0, nbrs = 0, x1, y1, z1, xk, yk, zk, xi, yi, zi, xmax, ymax, zmax; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -10319,7 +10516,8 @@ double gcamAreaIntensityEnergy(GCA_MORPH *gcam, MRI *mri, NODE_LOOKUP_TABLE *nlt DiagBreak(); error = image_val; continue; - } else { + } + else { error = image_val - sum_uv / sum_v; } if (x == Gx && y == Gy && z == Gz) { @@ -10357,7 +10555,8 @@ double gcamAreaIntensityEnergy(GCA_MORPH *gcam, MRI *mri, NODE_LOOKUP_TABLE *nlt return (sse); } -double gcamBinaryEnergy(GCA_MORPH *gcam, MRI *mri) { +double gcamBinaryEnergy(GCA_MORPH *gcam, MRI *mri) +{ int x, y, z; double sse, error; double val; @@ -10375,12 +10574,14 @@ double gcamBinaryEnergy(GCA_MORPH *gcam, MRI *mri) { MRIsampleVolumeType(mri, gcamn->x, gcamn->y, gcamn->z, &val, SAMPLE_TRILINEAR); if ((gcamn->label == 0) || (gcamn->status & GCAM_BINARY_ZERO)) { error = 0 - val; - } else { + } + else { error = 1 - val; } if ((abs(error) < .1) && gcamn->invalid == GCAM_VALID) { Galigned++; - } else { + } + else { DiagBreak(); if (gcamn->label > 0) { DiagBreak(); @@ -10409,7 +10610,8 @@ double gcamBinaryEnergy(GCA_MORPH *gcam, MRI *mri) { #define MAX_NBR_NODES 30000 int gcamAreaIntensityTerm( - GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_area_intensity, NODE_LOOKUP_TABLE *nlt, float sigma) { + GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_area_intensity, NODE_LOOKUP_TABLE *nlt, float sigma) +{ double val, image_val, error, dx, dy, dz, sum_cv, Ix, Iy, Iz, c, distsq, sum_cuv, dxI, dyI, dzI, predicted_val, norm; int x, y, z, xn, yn, zn, i, x1, y1, z1, wsize, xi, yi, zi, xk, yk, zk, nbrs; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -10652,7 +10854,8 @@ int gcamAreaIntensityTerm( return (NO_ERROR); } -int gcamBinaryTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, MRI *mri_dist, double l_binary) { +int gcamBinaryTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, MRI *mri_dist, double l_binary) +{ int x, y, z; double sse, error, dx, dy, dz, odx, ody, odz, norm; double val; @@ -10690,7 +10893,8 @@ int gcamBinaryTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, MRI *mri_dist, do odz /= norm; if ((gcamn->label == 0) || (gcamn->status & GCAM_BINARY_ZERO)) { error = 0 - val; - } else { + } + else { error = 1 - val; } @@ -12168,7 +12372,8 @@ GCAMmorphFieldFromAtlas(GCA_MORPH *gcam, MRI *mri, int which, int save_inversion return(mri_morphed) ; } #else -MRI *GCAMmorphFieldFromAtlas(GCA_MORPH *gcam, MRI *mri, int which, int save_inversions, int filter) { +MRI *GCAMmorphFieldFromAtlas(GCA_MORPH *gcam, MRI *mri, int which, int save_inversions, int filter) +{ MRI *mri_morphed, *mri_atlas; int x, y, z, xm, ym, zm, type, frame; double val; @@ -12313,7 +12518,8 @@ MRI *GCAMmorphFieldFromAtlas(GCA_MORPH *gcam, MRI *mri, int which, int save_inve return (mri_morphed); } #endif -int GCAMexpand(GCA_MORPH *gcam, float distance) { +int GCAMexpand(GCA_MORPH *gcam, float distance) +{ int i, j, k, num; double cx, cy, cz, dx, dy, dz, norm; GCA_MORPH_NODE *gcamn; @@ -12364,7 +12570,8 @@ int GCAMexpand(GCA_MORPH *gcam, float distance) { return (NO_ERROR); } -GCA_MORPH *GCAMregrid(GCA_MORPH *gcam, MRI *mri_dst, int pad, GCA_MORPH_PARMS *parms, MRI **pmri) { +GCA_MORPH *GCAMregrid(GCA_MORPH *gcam, MRI *mri_dst, int pad, GCA_MORPH_PARMS *parms, MRI **pmri) +{ MRI *mri_tmp, *mri_labeled, *mri_means, *mri_covars, *mri_origx, *mri_origy, *mri_origz, *mri_tmp2, *mri_xn, *mri_yn, *mri_zn; MRI_REGION box; @@ -12469,7 +12676,8 @@ GCA_MORPH *GCAMregrid(GCA_MORPH *gcam, MRI *mri_dst, int pad, GCA_MORPH_PARMS *p if (DIAG_VERBOSE_ON && Gdiag & DIAG_WRITE) { MRIwrite(mri_means, "m.mgz"); } - } else { + } + else { mri_means = mri_covars = NULL; } @@ -12608,7 +12816,8 @@ GCA_MORPH *GCAMregrid(GCA_MORPH *gcam, MRI *mri_dst, int pad, GCA_MORPH_PARMS *p TransformFree(&transform); if (pmri) { *pmri = mri_labeled; - } else { + } + else { MRIfree(&mri_labeled); } if (DIAG_VERBOSE_ON) { @@ -12662,7 +12871,8 @@ GCA_MORPH *GCAMregrid(GCA_MORPH *gcam, MRI *mri_dst, int pad, GCA_MORPH_PARMS *p MRI *GCAMinitDensities(GCA_MORPH *gcam, MRI *mri_lowres_seg, MRI *mri_intensities, - GCAM_LABEL_TRANSLATION_TABLE *gcam_ltt) { + GCAM_LABEL_TRANSLATION_TABLE *gcam_ltt) +{ GCA_MORPH_NODE *gcamn; int i, in_label, out_label, bin, x, y, z, x1, y1, z1, x2, y2, z2, n; MATRIX *m_vox2vox; @@ -12761,7 +12971,8 @@ MRI *GCAMinitDensities(GCA_MORPH *gcam, if (MRIvoxelsInLabel(mri_eroded, out_label) >= 25) { h = MRIhistogramLabelRegion(mri_intensities, mri_eroded, &bbox, out_label, 0); HISTOfillHoles(h); - } else { + } + else { h = MRIhistogramLabelRegion(mri_intensities, mri_xformed_aseg, &bbox, out_label, 0); } MRIfree(&mri_eroded); @@ -12771,7 +12982,8 @@ MRI *GCAMinitDensities(GCA_MORPH *gcam, HISTOplot(hsmooth, "hsmooth.plt"); if (IS_LAT_VENT(out_label)) { bin = HISTOfindFirstPeak(hsmooth, 3, .1); - } else { + } + else { bin = HISTOfindHighestPeakInRegion(hsmooth, 0, hsmooth->nbins); } val = hsmooth->bins[bin]; @@ -12782,7 +12994,8 @@ MRI *GCAMinitDensities(GCA_MORPH *gcam, means[out_label] = val; means[in_label] = gcam_ltt->scales[i] * val; - } else { + } + else { means[in_label] = gcam_ltt->means[i]; } if (gcam_ltt->second_labels[i] == 0) // otherwise will reestimate later @@ -12897,7 +13110,8 @@ MRI *GCAMinitDensities(GCA_MORPH *gcam, } return (mri_xformed_aseg); } -GCA_MORPH *GCAMlinearTransform(GCA_MORPH *gcam_src, MATRIX *m_vox2vox, GCA_MORPH *gcam_dst) { +GCA_MORPH *GCAMlinearTransform(GCA_MORPH *gcam_src, MATRIX *m_vox2vox, GCA_MORPH *gcam_dst) +{ int x, y, z; VECTOR *v1, *v2; GCA_MORPH_NODE *gcamn_src, *gcamn_dst; @@ -12930,7 +13144,8 @@ GCA_MORPH *GCAMlinearTransform(GCA_MORPH *gcam_src, MATRIX *m_vox2vox, GCA_MORPH return (gcam_dst); } -int GCAMrasToVox(GCA_MORPH *gcam, MRI *mri) { +int GCAMrasToVox(GCA_MORPH *gcam, MRI *mri) +{ MATRIX *m; int x, y, z; GCA_MORPH_NODE *gcamn; @@ -12942,7 +13157,8 @@ int GCAMrasToVox(GCA_MORPH *gcam, MRI *mri) { if (mri == NULL) { m = VGgetRasToVoxelXform(&gcam->image, NULL, 0); - } else { + } + else { m = MRIgetRasToVoxelXform(mri); } if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { @@ -13000,7 +13216,8 @@ int GCAMrasToVox(GCA_MORPH *gcam, MRI *mri) { return (NO_ERROR); } -int GCAMvoxToRas(GCA_MORPH *gcam) { +int GCAMvoxToRas(GCA_MORPH *gcam) +{ MATRIX *m; int x, y, z; GCA_MORPH_NODE *gcamn; @@ -13053,7 +13270,8 @@ int GCAMvoxToRas(GCA_MORPH *gcam) { return (NO_ERROR); } -NODE_LOOKUP_TABLE *gcamCreateNodeLookupTable(GCA_MORPH *gcam, MRI *mri, NODE_LOOKUP_TABLE *nlt) { +NODE_LOOKUP_TABLE *gcamCreateNodeLookupTable(GCA_MORPH *gcam, MRI *mri, NODE_LOOKUP_TABLE *nlt) +{ int x, y, z, xi, yi, zi, index; GCA_MORPH_NODE *gcamn; MRI *mri_tmp; @@ -13176,7 +13394,8 @@ NODE_LOOKUP_TABLE *gcamCreateNodeLookupTable(GCA_MORPH *gcam, MRI *mri, NODE_LOO return (nlt); } -int gcamFreeNodeLookupTable(NODE_LOOKUP_TABLE **pnlt) { +int gcamFreeNodeLookupTable(NODE_LOOKUP_TABLE **pnlt) +{ NODE_LOOKUP_TABLE *nlt; int x, y, z; @@ -13202,13 +13421,15 @@ int gcamFreeNodeLookupTable(NODE_LOOKUP_TABLE **pnlt) { free(nlt); return (NO_ERROR); } -int GCAMresetLabelNodeStatus(GCA_MORPH *gcam) { +int GCAMresetLabelNodeStatus(GCA_MORPH *gcam) +{ GCAMremoveStatus(gcam, GCAM_LABEL_NODE); GCAMremoveStatus(gcam, GCAM_IGNORE_LIKELIHOOD); return (NO_ERROR); } -int GCAMaddStatus(GCA_MORPH *gcam, int status) { +int GCAMaddStatus(GCA_MORPH *gcam, int status) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -13224,7 +13445,8 @@ int GCAMaddStatus(GCA_MORPH *gcam, int status) { return (NO_ERROR); } -int GCAMremoveStatus(GCA_MORPH *gcam, int status) { +int GCAMremoveStatus(GCA_MORPH *gcam, int status) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -13297,7 +13519,8 @@ gcamSetGradientToNbrAverage(GCA_MORPH *gcam, int x, int y, int z) return(NO_ERROR) ; } #endif -int GCAMremoveCompressedRegions(GCA_MORPH *gcam, float min_ratio) { +int GCAMremoveCompressedRegions(GCA_MORPH *gcam, float min_ratio) +{ int ncompressed_before, ncompressed_after, niter; GCA_MORPH_PARMS parms; @@ -13341,7 +13564,8 @@ int GCAMremoveCompressedRegions(GCA_MORPH *gcam, float min_ratio) { return (NO_ERROR); } -int GCAMcountCompressedNodes(GCA_MORPH *gcam, float min_ratio) { +int GCAMcountCompressedNodes(GCA_MORPH *gcam, float min_ratio) +{ int i, j, k, ncompressed, compressed; GCA_MORPH_NODE *gcamn; float ratio1, ratio2; @@ -13390,7 +13614,8 @@ int gcamComputeMostLikelyDirection(GCA_MORPH *gcam, MRI *mri_nbhd, double *pdx, double *pdy, - double *pdz) { + double *pdz) +{ int xi, yi, zi, xk, yk, zk, x, y, z, whalf, x1, y1, z1; double val, max_val, max_dist, dist, max_x, max_y, max_z; static MRI *mri_int = NULL; @@ -13475,7 +13700,8 @@ int gcamComputeMostLikelyDirection(GCA_MORPH *gcam, return (NO_ERROR); } -int GCAMaddIntensitiesFromImage(GCA_MORPH *gcam, MRI *mri_target) { +int GCAMaddIntensitiesFromImage(GCA_MORPH *gcam, MRI *mri_target) +{ int x, y, z, num; double val, mean; GCA_MORPH_NODE *gcamn; @@ -13508,7 +13734,8 @@ int GCAMaddIntensitiesFromImage(GCA_MORPH *gcam, MRI *mri_target) { num++; mean += val; gcamn->label = 128; // something real here - } else { + } + else { DiagBreak(); } gcamn->gc->covars[0] = SQR(0.05 * val); // assume SNR=20 or so @@ -13555,7 +13782,8 @@ int GCAMaddIntensitiesFromImage(GCA_MORPH *gcam, MRI *mri_target) { return (NO_ERROR); } -GCA_MORPH *GCAMcreateFromIntensityImage(MRI *mri_source, MRI *mri_target, TRANSFORM *transform) { +GCA_MORPH *GCAMcreateFromIntensityImage(MRI *mri_source, MRI *mri_target, TRANSFORM *transform) +{ GCA_MORPH *gcam; int x, y, z, num; double val, mean; @@ -13586,7 +13814,8 @@ GCA_MORPH *GCAMcreateFromIntensityImage(MRI *mri_source, MRI *mri_target, TRANSF num++; mean += val; gcamn->label = 128; // something real here - } else { + } + else { DiagBreak(); } gcamn->gc->covars[0] = SQR(0.05 * val); // assume SNR=20 or so @@ -13634,7 +13863,8 @@ GCA_MORPH *GCAMcreateFromIntensityImage(MRI *mri_source, MRI *mri_target, TRANSF // GCAMinitLabels(gcam, NULL) ; return (gcam); } -int GCAMsetVariances(GCA_MORPH *gcam, float var) { +int GCAMsetVariances(GCA_MORPH *gcam, float var) +{ int x, y, z, r; GCA_MORPH_NODE *gcamn; @@ -13657,7 +13887,8 @@ int GCAMsetVariances(GCA_MORPH *gcam, float var) { return (NO_ERROR); } -int GCAMthresholdLikelihoodStatus(GCAM *gcam, MRI *mri, float thresh) { +int GCAMthresholdLikelihoodStatus(GCAM *gcam, MRI *mri, float thresh) +{ int x, y, z; double val; GCA_MORPH_NODE *gcamn; @@ -13672,7 +13903,8 @@ int GCAMthresholdLikelihoodStatus(GCAM *gcam, MRI *mri, float thresh) { val = MRIgetVoxVal(mri, x, y, z, 0); if (val <= thresh) { gcamn->status |= (GCAM_IGNORE_LIKELIHOOD | GCAM_NEVER_USE_LIKELIHOOD); - } else { + } + else { DiagBreak(); } } @@ -13681,7 +13913,8 @@ int GCAMthresholdLikelihoodStatus(GCAM *gcam, MRI *mri, float thresh) { return (NO_ERROR); } -int gcamConstrainJacobian(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { +int gcamConstrainJacobian(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) +{ double alpha, delta, lower_alpha, upper_alpha, rms, min_jacobian, max_jacobian, start_rms; int done = 0; @@ -13717,7 +13950,8 @@ int gcamConstrainJacobian(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { delta = alpha - lower_alpha; lower_alpha = alpha; rms = GCAMcomputeRMS(gcam, mri, parms); - } else // invalid movement - make upper alpha lower + } + else // invalid movement - make upper alpha lower { delta = upper_alpha - alpha; upper_alpha = alpha; @@ -13729,7 +13963,8 @@ int gcamConstrainJacobian(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { return (NO_ERROR); } -int gcamCheckJacobian(GCA_MORPH *gcam, float min_jacobian, float max_jacobian) { +int gcamCheckJacobian(GCA_MORPH *gcam, float min_jacobian, float max_jacobian) +{ int i, j, k; GCA_MORPH_NODE *gcamn; float ratio; @@ -13756,7 +13991,8 @@ int gcamCheckJacobian(GCA_MORPH *gcam, float min_jacobian, float max_jacobian) { return (1); } -int gcamSetTotalMovement(GCA_MORPH *gcam, float alpha) { +int gcamSetTotalMovement(GCA_MORPH *gcam, float alpha) +{ int i, j, k; double dx, dy, dz; GCA_MORPH_NODE *gcamn; @@ -13779,7 +14015,8 @@ int gcamSetTotalMovement(GCA_MORPH *gcam, float alpha) { return (NO_ERROR); } -int GCAMreinitWithLTA(GCA_MORPH *gcam, LTA *lta, MRI *mri, GCA_MORPH_PARMS *parms) { +int GCAMreinitWithLTA(GCA_MORPH *gcam, LTA *lta, MRI *mri, GCA_MORPH_PARMS *parms) +{ GCA_MORPH_NODE *gcamn; GCA *gca; int x, y, z, width, height, depth, i, level, navgs, first = 1; @@ -13794,11 +14031,13 @@ int GCAMreinitWithLTA(GCA_MORPH *gcam, LTA *lta, MRI *mri, GCA_MORPH_PARMS *parm if (parms->log_fp == NULL) { if (parms->start_t == 0) { parms->log_fp = fopen(fname, "w"); - } else { + } + else { parms->log_fp = fopen(fname, "a"); } } - } else { + } + else { parms->log_fp = NULL; } @@ -13886,7 +14125,8 @@ int GCAMreinitWithLTA(GCA_MORPH *gcam, LTA *lta, MRI *mri, GCA_MORPH_PARMS *parm gcamn->ys = V3_Y(v_dst); gcamn->zs = V3_Z(v_dst); gcamn->status |= GCAM_TARGET_DEFINED; - } else // no label specific xform - don't know where it should go + } + else // no label specific xform - don't know where it should go { gcamn->xs = gcamn->x; gcamn->ys = gcamn->y; @@ -14067,7 +14307,8 @@ int GCAMreinitWithLTA(GCA_MORPH *gcam, LTA *lta, MRI *mri, GCA_MORPH_PARMS *parm return (NO_ERROR); } -int gcamComputeTargetGradient(GCA_MORPH *gcam) { +int gcamComputeTargetGradient(GCA_MORPH *gcam) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -14080,7 +14321,8 @@ int gcamComputeTargetGradient(GCA_MORPH *gcam) { gcamn->dx = gcamn->xs - gcamn->x; gcamn->dy = gcamn->ys - gcamn->y; gcamn->dz = gcamn->zs - gcamn->z; - } else // no label specific xform - don't know where it should go + } + else // no label specific xform - don't know where it should go { gcamn->dx = gcamn->dy = gcamn->dz = 0; } @@ -14090,7 +14332,8 @@ int gcamComputeTargetGradient(GCA_MORPH *gcam) { return (NO_ERROR); } -MATRIX *gcamComputeOptimalTargetLinearTransform(GCA_MORPH *gcam, MATRIX *m_L, double reg) { +MATRIX *gcamComputeOptimalTargetLinearTransform(GCA_MORPH *gcam, MATRIX *m_L, double reg) +{ int x, y, z, ncols, col; GCA_MORPH_NODE *gcamn; MATRIX *m_U, *m_V, *m_Uinv, *m_I; @@ -14202,7 +14445,8 @@ MATRIX *gcamComputeOptimalTargetLinearTransform(GCA_MORPH *gcam, MATRIX *m_L, do return (m_L); } -int gcamApplyLinearTransform(GCA_MORPH *gcam, MATRIX *m_L) { +int gcamApplyLinearTransform(GCA_MORPH *gcam, MATRIX *m_L) +{ VECTOR *v_src, *v_dst; int x, y, z; GCA_MORPH_NODE *gcamn; @@ -14231,7 +14475,8 @@ int gcamApplyLinearTransform(GCA_MORPH *gcam, MATRIX *m_L) { return (NO_ERROR); } -int gcamShowCompressed(GCA_MORPH *gcam, FILE *fp) { +int gcamShowCompressed(GCA_MORPH *gcam, FILE *fp) +{ int n1, n2, n3, n4; n1 = GCAMcountCompressedNodes(gcam, 0.5); n2 = GCAMcountCompressedNodes(gcam, 0.25); @@ -14241,7 +14486,8 @@ int gcamShowCompressed(GCA_MORPH *gcam, FILE *fp) { return (n1 + n2 + n3 + n4); } -int gcamSuppressNegativeGradients(GCA_MORPH *gcam, float scale) { +int gcamSuppressNegativeGradients(GCA_MORPH *gcam, float scale) +{ int i, j, k /*, in, jn, kn, i1, j1, k1 */; GCA_MORPH_NODE *gcamn; @@ -14302,7 +14548,8 @@ int gcamSuppressNegativeGradients(GCA_MORPH *gcam, float scale) { return (NO_ERROR); } -int gcamWriteDiagnostics(GCA_MORPH *gcam) { +int gcamWriteDiagnostics(GCA_MORPH *gcam) +{ FILE *fp; static int dbg = 0; static int callno = 0; @@ -14335,7 +14582,8 @@ int gcamWriteDiagnostics(GCA_MORPH *gcam) { return (NO_ERROR); } -int gcamCheck(GCA_MORPH *gcam, MRI *mri) { +int gcamCheck(GCA_MORPH *gcam, MRI *mri) +{ GCA_MORPH_NODE *gcamn; int x, y, z, first = 1, num; float orig_area, dif1, dif2; @@ -14393,7 +14641,8 @@ int gcamCheck(GCA_MORPH *gcam, MRI *mri) { return (NO_ERROR); } -GCA_MORPH *GCAMupsample2(GCA_MORPH *gcam) { +GCA_MORPH *GCAMupsample2(GCA_MORPH *gcam) +{ int xn, yn, zn, xo, yo, zo; GCA_MORPH *gcam_new; GCA_MORPH_NODE *gcamn_old, *gcamn_new; @@ -14479,7 +14728,8 @@ GCA_MORPH *GCAMupsample2(GCA_MORPH *gcam) { return (NO_ERROR); } -int GCAMignoreZero(GCA_MORPH *gcam, MRI *mri_target) { +int GCAMignoreZero(GCA_MORPH *gcam, MRI *mri_target) +{ int x, y, z; double val; GCA_MORPH_NODE *gcamn; @@ -14505,7 +14755,8 @@ int GCAMignoreZero(GCA_MORPH *gcam, MRI *mri_target) { return (NO_ERROR); } -int GCAMremoveIgnoreZero(GCA_MORPH *gcam, MRI *mri_target) { +int GCAMremoveIgnoreZero(GCA_MORPH *gcam, MRI *mri_target) +{ int x, y, z; double val; GCA_MORPH_NODE *gcamn; @@ -14530,7 +14781,8 @@ int GCAMremoveIgnoreZero(GCA_MORPH *gcam, MRI *mri_target) { } MATRIX *gcamComputeOptimalLinearTransformInRegion( - GCA_MORPH *gcam, MRI *mri_mask, MATRIX *m_L, int x0, int y0, int z0, int whalf) { + GCA_MORPH *gcam, MRI *mri_mask, MATRIX *m_L, int x0, int y0, int z0, int whalf) +{ int ncols, col, xi, yi, zi, xk, yk, zk; GCA_MORPH_NODE *gcamn; MATRIX *m_U, *m_V, *m_Uinv; @@ -14672,7 +14924,8 @@ MATRIX *gcamComputeOptimalLinearTransformInRegion( return (m_L); } -int gcamExpansionTerm(GCA_MORPH *gcam, MRI *mri, double l_expansion) { +int gcamExpansionTerm(GCA_MORPH *gcam, MRI *mri, double l_expansion) +{ double sse, error_0, error_n, dx, dy, dz; int x, y, z, xi, yi, zi, xk, yk, zk; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -14837,7 +15090,8 @@ int gcamExpansionTerm(GCA_MORPH *gcam, MRI *mri, double l_expansion) { return (NO_ERROR); } -double gcamExpansionEnergy(GCA_MORPH *gcam, MRI *mri) { +double gcamExpansionEnergy(GCA_MORPH *gcam, MRI *mri) +{ double sse, error_0, error_n, sse_node; int x, y, z, xi, yi, zi, xk, yk, zk; GCA_MORPH_NODE *gcamn, *gcamn_nbr; @@ -14968,7 +15222,8 @@ double gcamExpansionEnergy(GCA_MORPH *gcam, MRI *mri) { return (sse); } -int GCAMmatchVentricles(GCA_MORPH *gcam, MRI *mri) { +int GCAMmatchVentricles(GCA_MORPH *gcam, MRI *mri) +{ int label, ven_nbr, x, y, z, xi, yi, zi, xk, yk, zk, nchanged = 0, n; GCA_MORPH_NODE *gcamn, *gcamn_nbr; float vals[MAX_GCA_INPUTS]; @@ -15052,7 +15307,8 @@ int GCAMmatchVentricles(GCA_MORPH *gcam, MRI *mri) { gcamn->gc ? sqrt(covariance_determinant(gcamn->gc, gcam->ninputs)) : 0.0, gcamn->prior, vals[0]); - } else /* out of FOV probably */ + } + else /* out of FOV probably */ { gcamn->label = label; gcamn->n = 0; @@ -15075,7 +15331,8 @@ int GCAMmatchVentricles(GCA_MORPH *gcam, MRI *mri) { return (NO_ERROR); } -int GCAMdeformVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { +int GCAMdeformVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) +{ double rms, last_rms, orig_dt, min_dt, pct_change; int navgs, level; @@ -15086,11 +15343,13 @@ int GCAMdeformVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { if (parms->log_fp == NULL) { if (parms->start_t == 0) { parms->log_fp = fopen(fname, "w"); - } else { + } + else { parms->log_fp = fopen(fname, "a"); } } - } else { + } + else { parms->log_fp = NULL; } orig_dt = parms->dt; @@ -15184,7 +15443,8 @@ int GCAMdeformVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { return (NO_ERROR); } -int gcamComputePeriventricularWMDeformation(GCA_MORPH *gcam, MRI *mri) { +int gcamComputePeriventricularWMDeformation(GCA_MORPH *gcam, MRI *mri) +{ int ven_nbr, x, y, z, xi, yi, zi, xk, yk, zk; GCA_MORPH_NODE *gcamn, *gcamn_nbr; float vals[MAX_GCA_INPUTS]; @@ -15304,7 +15564,8 @@ int gcamComputePeriventricularWMDeformation(GCA_MORPH *gcam, MRI *mri) { return (NO_ERROR); } -HISTOGRAM *gcamJacobianHistogram(GCA_MORPH *gcam, HISTOGRAM *h) { +HISTOGRAM *gcamJacobianHistogram(GCA_MORPH *gcam, HISTOGRAM *h) +{ int i, j, k, bin_no, nbins; GCA_MORPH_NODE *gcamn; double jmin, jmax, jac, orig_area; @@ -15340,13 +15601,15 @@ HISTOGRAM *gcamJacobianHistogram(GCA_MORPH *gcam, HISTOGRAM *h) { nbins = 512; bin_size = (jmax - jmin + 1) / (float)nbins; printf("setting bin_size to %2.2f\n", bin_size); - } else { + } + else { nbins = ceil((jmax - jmin + 1) / bin_size); printf("using %d bins\n", nbins); } if (h == NULL) { h = HISTOalloc(nbins); - } else { + } + else { HISTOrealloc(h, nbins); } @@ -15371,7 +15634,8 @@ HISTOGRAM *gcamJacobianHistogram(GCA_MORPH *gcam, HISTOGRAM *h) { } return (h); } -int GCAMnormalizeIntensities(GCA_MORPH *gcam, MRI *mri_target) { +int GCAMnormalizeIntensities(GCA_MORPH *gcam, MRI *mri_target) +{ int x, y, z, num, peak; double val, mean, std, low_thresh, hi_thresh; GCA_MORPH_NODE *gcamn; @@ -15477,7 +15741,8 @@ int GCAMnormalizeIntensities(GCA_MORPH *gcam, MRI *mri_target) { return (NO_ERROR); } -int GCAMsmoothConditionalDensities(GCA_MORPH *gcam, float sigma) { +int GCAMsmoothConditionalDensities(GCA_MORPH *gcam, float sigma) +{ MRI *mri, *mri_kernel, *mri_smooth; mri = GCAMwriteMRI(gcam, NULL, GCAM_MEANS); @@ -15490,7 +15755,8 @@ int GCAMsmoothConditionalDensities(GCA_MORPH *gcam, float sigma) { return (NO_ERROR); } -int dtrans_label_to_frame(GCA_MORPH_PARMS *mp, int label) { +int dtrans_label_to_frame(GCA_MORPH_PARMS *mp, int label) +{ int frame; #if 1 @@ -15571,7 +15837,8 @@ int dtrans_label_to_frame(GCA_MORPH_PARMS *mp, int label) { return (frame); } -int gcamDistanceTransformTerm(GCA_MORPH *gcam, MRI *mri_source, MRI *mri, double l_dtrans, GCA_MORPH_PARMS *mp) { +int gcamDistanceTransformTerm(GCA_MORPH *gcam, MRI *mri_source, MRI *mri, double l_dtrans, GCA_MORPH_PARMS *mp) +{ int x, y, z, frame, label; GCA_MORPH_NODE *gcamn; double dist, dx, dy, dz, error; @@ -15651,7 +15918,8 @@ int gcamDistanceTransformTerm(GCA_MORPH *gcam, MRI *mri_source, MRI *mri, double return (NO_ERROR); } -double gcamDistanceTransformEnergy(GCA_MORPH *gcam, MRI *mri_source, MRI *mri, GCA_MORPH_PARMS *mp) { +double gcamDistanceTransformEnergy(GCA_MORPH *gcam, MRI *mri_source, MRI *mri, GCA_MORPH_PARMS *mp) +{ double sse = 0.0; int x, y, z, frame, label; GCA_MORPH_NODE *gcamn; @@ -15719,7 +15987,8 @@ double gcamDistanceTransformEnergy(GCA_MORPH *gcam, MRI *mri_source, MRI *mri, G return (sse); } -int GCAMsetTargetDistancesForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_dist, int label) { +int GCAMsetTargetDistancesForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_dist, int label) +{ int x, y, z, l, xv, yv, zv; GCA_MORPH_NODE *gcamn; @@ -15732,7 +16001,8 @@ int GCAMsetTargetDistancesForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_di gcamn = &gcam->nodes[x][y][z]; if (gcam->gca) { GCApriorToVoxel(gcam->gca, mri_labels, x, y, z, &xv, &yv, &zv); - } else { + } + else { xv = x; yv = y; zv = z; @@ -15751,7 +16021,8 @@ int GCAMsetTargetDistancesForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_di } return (NO_ERROR); } -int GCAMsetMeansForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_vals, int label) { +int GCAMsetMeansForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_vals, int label) +{ int x, y, z, l, r, xv, yv, zv; GCA_MORPH_NODE *gcamn; @@ -15764,7 +16035,8 @@ int GCAMsetMeansForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_vals, int la gcamn = &gcam->nodes[x][y][z]; if (gcam->gca) { GCApriorToVoxel(gcam->gca, mri_labels, x, y, z, &xv, &yv, &zv); - } else { + } + else { xv = x; yv = y; zv = z; @@ -15788,7 +16060,8 @@ int GCAMsetMeansForLabel(GCA_MORPH *gcam, MRI *mri_labels, MRI *mri_vals, int la } return (NO_ERROR); } -MRI *GCAMbuildLabelVolume(GCA_MORPH *gcam, MRI *mri) { +MRI *GCAMbuildLabelVolume(GCA_MORPH *gcam, MRI *mri) +{ int x, y, z, xn, yn, zn, width, depth, height, label; GCA_MORPH_NODE *gcamn; @@ -15830,7 +16103,8 @@ MRI *GCAMbuildLabelVolume(GCA_MORPH *gcam, MRI *mri) { } } } - } else // no gca + } + else // no gca { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { @@ -15854,7 +16128,8 @@ MRI *GCAMbuildLabelVolume(GCA_MORPH *gcam, MRI *mri) { return (mri); } -double gcamMultiscaleEnergy(GCA_MORPH *gcam, MRI *mri) { +double gcamMultiscaleEnergy(GCA_MORPH *gcam, MRI *mri) +{ GCAM_MS *gcam_ms = (GCAM_MS *)gcam->vgcam_ms; double vox_pval, total_log_pval, pval; int x, y, z, s, xn, yn, zn, n; @@ -15894,7 +16169,8 @@ double gcamMultiscaleEnergy(GCA_MORPH *gcam, MRI *mri) { } if (DZERO(vox_pval)) { DiagBreak(); - } else { + } + else { total_log_pval += log(vox_pval); } } @@ -15902,7 +16178,8 @@ double gcamMultiscaleEnergy(GCA_MORPH *gcam, MRI *mri) { return (-total_log_pval); } -int gcamMultiscaleTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_multiscale) { +int gcamMultiscaleTerm(GCA_MORPH *gcam, MRI *mri, MRI *mri_smooth, double l_multiscale) +{ GCAM_MS *gcam_ms = (GCAM_MS *)gcam->vgcam_ms; double pval, dx, dy, dz, Ix, Iy, Iz, Ierror, norm; int x, y, z, s, xn, yn, zn, n; @@ -16265,7 +16542,8 @@ MRI *GCAMMScomputeOptimalScale(GCAM_MS *gcam_ms, return (mri_sigma); } #if 1 -double GCAMlogPosterior(GCA_MORPH *gcam, MRI *mri_inputs) { +double GCAMlogPosterior(GCA_MORPH *gcam, MRI *mri_inputs) +{ double total_log_posterior, logp; int x, y, z, real_label; GCA_NODE *gcan; @@ -16338,7 +16616,8 @@ double GCAMlogPosterior(GCA_MORPH *gcam, MRI *mri_inputs) { return (total_log_posterior); } #else -double GCAMlogPosteriorDensity(GCA_MORPH *gcam, MRI *mri_inputs) { +double GCAMlogPosteriorDensity(GCA_MORPH *gcam, MRI *mri_inputs) +{ double total_log_posterior; int x, y, z; GCA_NODE *gcan; @@ -16398,7 +16677,8 @@ double GCAMlogPosteriorDensity(GCA_MORPH *gcam, MRI *mri_inputs) { } #endif MRI *GCAMcreateDistanceTransforms( - MRI *mri_source, MRI *mri_target, MRI *mri_all_dtrans, float max_dist, GCA_MORPH *gcam, MRI **pmri_atlas_dist_map) { + MRI *mri_source, MRI *mri_target, MRI *mri_all_dtrans, float max_dist, GCA_MORPH *gcam, MRI **pmri_atlas_dist_map) +{ MRI *mri_dtrans, *mri_atlas_dtrans, *mri_atlas_dist_map; int frame, label; char fname[STRLEN]; @@ -16513,7 +16793,8 @@ GCAMcreateDistanceTransforms(GCA_MORPH *gcam, MRI *mri, MRI *mri_all_dtrans, int GCAMwriteDistanceTransforms(GCA_MORPH *gcam, MRI *mri_source_dist_map, MRI *mri_atlas_dist_map, - const char *dist_name) { + const char *dist_name) +{ char fname[STRLEN]; int i, label; @@ -16527,7 +16808,8 @@ int GCAMwriteDistanceTransforms(GCA_MORPH *gcam, return (NO_ERROR); } MRI *GCAMreadDistanceTransforms( - GCA_MORPH *gcam, MRI *mri, MRI *mri_all_dtrans, MRI **pmri_atlas_dtrans, const char *dist_name, double max_dist) { + GCA_MORPH *gcam, MRI *mri, MRI *mri_all_dtrans, MRI **pmri_atlas_dtrans, const char *dist_name, double max_dist) +{ MRI *mri_tmp; int i, label; char fname[STRLEN]; @@ -16565,7 +16847,8 @@ MRI *GCAMreadDistanceTransforms( compute a gauss-newton step matching the source and atlas images and put the resulting vector field into mri_v */ -int MRIcomputeGaussNewtonStep(MRI *mri_source, MRI *mri_atlas, MRI *mri_v, MRI *mri_labels, GCA_MORPH_PARMS *parms) { +int MRIcomputeGaussNewtonStep(MRI *mri_source, MRI *mri_atlas, MRI *mri_v, MRI *mri_labels, GCA_MORPH_PARMS *parms) +{ MATRIX *m_J, *m_J_t, *m_inv, *m_I, *m_tmp = NULL, *v_r, *v_v, *m_tmp2 = NULL, *m_D; int x, y, z, frame, label; double Ix, Iy, Iz, dx, dy, dz, tval, sval, error, lambda = .1; @@ -16667,7 +16950,8 @@ int MRIcomputeGaussNewtonStep(MRI *mri_source, MRI *mri_atlas, MRI *mri_v, MRI * } #if 1 -int gcamScaleAndSquare(MRI *mri_s_old, MRI *mri_s_new) { +int gcamScaleAndSquare(MRI *mri_s_old, MRI *mri_s_new) +{ int x, y, z; double dx, dy, dz, dx_old, dy_old, dz_old; @@ -16712,7 +16996,8 @@ int gcamScaleAndSquare(MRI *mri_s_old, MRI *mri_s_new) { return (NO_ERROR); } #endif -MRI *MRIcomposeWarps(MRI *mri_warp1, MRI *mri_warp2, MRI *mri_dst) { +MRI *MRIcomposeWarps(MRI *mri_warp1, MRI *mri_warp2, MRI *mri_dst) +{ int x, y, z; double dx2, dy2, dz2, dx1, dy1, dz1; @@ -16858,7 +17143,8 @@ int GCAMdemonsRegister(GCA_MORPH *gcam, GCA_MORPH_PARMS *parms, double max_dist, MRI *mri_pvals, - MRI *mri_atlas_dtrans_orig) { + MRI *mri_atlas_dtrans_orig) +{ double vmax_allowed, dt, N, old_sse, new_sse, vmax, pct_change; MRI *mri_s_new, *mri_s_old, *mri_kernel, *mri_morphed, *mri_current_dtrans = NULL, *mri_warp, *mri_current_labels, *mri_dtrans, *mri_atlas_dtrans; @@ -16878,11 +17164,13 @@ int GCAMdemonsRegister(GCA_MORPH *gcam, if (parms->log_fp == NULL) { if (parms->start_t == 0) { parms->log_fp = fopen(fname, "w"); - } else { + } + else { parms->log_fp = fopen(fname, "a"); } } - } else { + } + else { parms->log_fp = NULL; } @@ -17149,7 +17437,8 @@ int GCAMdemonsRegister(GCA_MORPH *gcam, return (NO_ERROR); } -int GCAMcompose(GCA_MORPH *gcam, MRI *mri_warp) { +int GCAMcompose(GCA_MORPH *gcam, MRI *mri_warp) +{ int xp, yp, zp, xv, yv, zv; double dx, dy, dz; GCA_MORPH_NODE *gcamn; @@ -17170,7 +17459,8 @@ int GCAMcompose(GCA_MORPH *gcam, MRI *mri_warp) { } return (NO_ERROR); } -int GCAMreadWarpFromMRI(GCA_MORPH *gcam, const MRI *mri_warp) { +int GCAMreadWarpFromMRI(GCA_MORPH *gcam, const MRI *mri_warp) +{ int xp, yp, zp, xv, yv, zv; double dx, dy, dz; GCA_MORPH_NODE *gcamn; @@ -17215,7 +17505,8 @@ int GCAMreadWarpFromMRI(GCA_MORPH *gcam, const MRI *mri_warp) { } return (NO_ERROR); } -int GCAMreadPositionsFromMRI(GCA_MORPH *gcam, const MRI *mri_pos) { +int GCAMreadPositionsFromMRI(GCA_MORPH *gcam, const MRI *mri_pos) +{ int xp, yp, zp, xv, yv, zv; double x, y, z; GCA_MORPH_NODE *gcamn; @@ -17261,7 +17552,8 @@ int GCAMreadPositionsFromMRI(GCA_MORPH *gcam, const MRI *mri_pos) { return (NO_ERROR); } -int GCAMreadInverseWarpFromMRI(GCA_MORPH *gcam, MRI *mri_warp) { +int GCAMreadInverseWarpFromMRI(GCA_MORPH *gcam, MRI *mri_warp) +{ int xv, yv, zv; double dx, dy, dz; @@ -17289,7 +17581,8 @@ int GCAMreadInverseWarpFromMRI(GCA_MORPH *gcam, MRI *mri_warp) { return (NO_ERROR); } -MRI *MRIapplyMorph(MRI *mri_source, MRI *mri_warp, MRI *mri_dst, int sample_type) { +MRI *MRIapplyMorph(MRI *mri_source, MRI *mri_warp, MRI *mri_dst, int sample_type) +{ int x, y, z, f; double dx, dy, dz, xd, yd, zd, val; @@ -17317,7 +17610,8 @@ MRI *MRIapplyMorph(MRI *mri_source, MRI *mri_warp, MRI *mri_dst, int sample_type // if image is resampled often (e.g. in registration algo) { MRIsampleBSpline(bspline, xd, yd, zd, f, &val); - } else { + } + else { MRIsampleVolumeFrameType(mri_source, xd, yd, zd, f, sample_type, &val); } MRIsetVoxVal(mri_dst, x, y, z, f, val); @@ -17333,7 +17627,8 @@ MRI *MRIapplyMorph(MRI *mri_source, MRI *mri_warp, MRI *mri_dst, int sample_type return (mri_dst); } -double MRImorphSSE(MRI *mri_source, MRI *mri_atlas, MRI *mri_warp) { +double MRImorphSSE(MRI *mri_source, MRI *mri_atlas, MRI *mri_warp) +{ int x, y, z, f; double dx, dy, dz, xd, yd, zd, sval, tval, error, sse; @@ -17360,7 +17655,8 @@ double MRImorphSSE(MRI *mri_source, MRI *mri_atlas, MRI *mri_warp) { sse = sse / (mri_atlas->width * mri_atlas->height * mri_atlas->depth * mri_atlas->nframes); return (sse); } -MRI *MRIcreateDistanceTransforms(MRI *mri, MRI *mri_all_dtrans, float max_dist, int *labels, int nlabels) { +MRI *MRIcreateDistanceTransforms(MRI *mri, MRI *mri_all_dtrans, float max_dist, int *labels, int nlabels) +{ MRI *mri_dtrans; int frame; char fname[STRLEN]; @@ -17390,7 +17686,8 @@ MRI *MRIcreateDistanceTransforms(MRI *mri, MRI *mri_all_dtrans, float max_dist, mri_all_dtrans->outside_val = max_dist; return (mri_all_dtrans); } -MRI *MRInormalizeInteriorDistanceTransform(MRI *mri_src_dist, MRI *mri_ref_dist, MRI *mri_dst_dist) { +MRI *MRInormalizeInteriorDistanceTransform(MRI *mri_src_dist, MRI *mri_ref_dist, MRI *mri_dst_dist) +{ int frame; float min_ref_dist, max_val, min_src_dist; @@ -17408,13 +17705,15 @@ MRI *MRInormalizeInteriorDistanceTransform(MRI *mri_src_dist, MRI *mri_ref_dist, return (mri_dst_dist); } MRI *MRIcomputeDistanceTransformStep( - MRI *mri_source, MRI *mri_atlas, MRI *mri_delta, MRI *mri_atlas_labels, GCA_MORPH_PARMS *parms) { + MRI *mri_source, MRI *mri_atlas, MRI *mri_delta, MRI *mri_atlas_labels, GCA_MORPH_PARMS *parms) +{ int x, y, z, frame, label; double Ix, Iy, Iz, dx, dy, dz, tval, sval, error, norm; if (mri_delta == NULL) { mri_delta = MRIallocSequence(mri_atlas->width, mri_atlas->height, mri_atlas->depth, MRI_FLOAT, 3); - } else { + } + else { MRIclear(mri_delta); } @@ -17472,7 +17771,8 @@ MRI *MRIcomputeDistanceTransformStep( return (mri_delta); } -double MRIlabelMorphSSE(MRI *mri_source, MRI *mri_atlas, MRI *mri_warp) { +double MRIlabelMorphSSE(MRI *mri_source, MRI *mri_atlas, MRI *mri_warp) +{ int x, y, z, src_label, atlas_label, nvox; double dx, dy, dz, xd, yd, zd, sval, sse; @@ -17517,7 +17817,8 @@ double MRIlabelMorphSSE(MRI *mri_source, MRI *mri_atlas, MRI *mri_warp) { sse = sse / nvox; return (sse); } -MRI *GCAMwriteWarpToMRI(const GCA_MORPH *gcam, MRI *mri_warp) { +MRI *GCAMwriteWarpToMRI(const GCA_MORPH *gcam, MRI *mri_warp) +{ int x, y, z; double xp, yp, zp; float xw, yw, zw; @@ -17557,7 +17858,8 @@ MRI *GCAMwriteWarpToMRI(const GCA_MORPH *gcam, MRI *mri_warp) { for (z = 0; z < mri_warp->depth; z++) { if (gcam->gca) { GCAvoxelToPriorReal(gcam->gca, mri_warp, x, y, z, &xp, &yp, &zp); - } else { + } + else { xp = x; yp = y; zp = z; // same resolution @@ -17572,7 +17874,8 @@ MRI *GCAMwriteWarpToMRI(const GCA_MORPH *gcam, MRI *mri_warp) { return (mri_warp); } -MRI *GCAMwritePositionsToMRI(const GCA_MORPH *gcam, MRI *mri_pos) { +MRI *GCAMwritePositionsToMRI(const GCA_MORPH *gcam, MRI *mri_pos) +{ int x, y, z; double xp, yp, zp; float xw, yw, zw; @@ -17612,7 +17915,8 @@ MRI *GCAMwritePositionsToMRI(const GCA_MORPH *gcam, MRI *mri_pos) { for (z = 0; z < mri_pos->depth; z++) { if (gcam->gca) { GCAvoxelToPriorReal(gcam->gca, mri_pos, x, y, z, &xp, &yp, &zp); - } else { + } + else { xp = x; yp = y; zp = z; // same resolution @@ -17627,7 +17931,8 @@ MRI *GCAMwritePositionsToMRI(const GCA_MORPH *gcam, MRI *mri_pos) { return (mri_pos); } -MRI *GCAMwriteInverseWarpToMRI(GCA_MORPH *gcam, MRI *mri_warp) { +MRI *GCAMwriteInverseWarpToMRI(GCA_MORPH *gcam, MRI *mri_warp) +{ int x, y, z; double xp, yp, zp; double xw, yw, zw; @@ -17667,7 +17972,8 @@ MRI *GCAMSreclassifyUsingGibbsPriors(MRI *mri_inputs, int max_iter, int restart, void (*update_func)(MRI *), - MRI *mri_s_index) { + MRI *mri_s_index) +{ int x, y, z, width, height, depth, label, val, iter, n, nchanged, min_changed, index, nindices, old_label, s, max_s; short *x_indices, *y_indices, *z_indices; GCA_PRIOR *gcap; @@ -17714,7 +18020,8 @@ MRI *GCAMSreclassifyUsingGibbsPriors(MRI *mri_inputs, old_posterior = GCAMMSgibbsImageLogPosterior(gcam_ms, mri_dst, mri_inputs, transform, mri_s_index); // get the per voxel value old_posterior /= (double)(width * depth * height); - } else { + } + else { old_posterior = 0; } @@ -17732,7 +18039,8 @@ MRI *GCAMSreclassifyUsingGibbsPriors(MRI *mri_inputs, } } nindices = index; - } else if (iter == 0) { + } + else if (iter == 0) { /* char fname[STRLEN], *cp ;*/ if (gca_write_iterations) { @@ -17746,7 +18054,8 @@ MRI *GCAMSreclassifyUsingGibbsPriors(MRI *mri_inputs, // sorted according to ascending order of probs MRIorderIndices(mri_probs, x_indices, y_indices, z_indices); MRIfree(&mri_probs); - } else + } + else // randomize the indices value ((0 -> width*height*depth) MRIcomputeVoxelPermutation(mri_inputs, x_indices, y_indices, z_indices); @@ -17859,7 +18168,8 @@ MRI *GCAMSreclassifyUsingGibbsPriors(MRI *mri_inputs, nchanged++; // mark it as changed MRIvox(mri_changed, x, y, z) = 1; - } else { + } + else { MRIvox(mri_changed, x, y, z) = 0; } // assign new label @@ -17893,7 +18203,8 @@ MRI *GCAMSreclassifyUsingGibbsPriors(MRI *mri_inputs, lcma); else // currently this is executed printf("pass %d: %d changed. image ll: %2.3f\n", iter + 1, nchanged, ll); - } else { + } + else { printf("pass %d: %d changed.\n", iter + 1, nchanged); } @@ -17949,7 +18260,8 @@ MRI *GCAMSreclassifyUsingGibbsPriors(MRI *mri_inputs, } #endif double GCAMMSgibbsImageLogPosterior( - GCAM_MS *gcam_ms, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform, MRI *mri_s_index) { + GCAM_MS *gcam_ms, MRI *mri_labels, MRI *mri_inputs, TRANSFORM *transform, MRI *mri_s_index) +{ int x, y, z, width, depth, height, s; double total_log_posterior, log_posterior; GCA *gca; @@ -17977,7 +18289,8 @@ double GCAMMSgibbsImageLogPosterior( return (total_log_posterior); } -static MRI *GCAMreplaceWarpAtInvalidNodes(GCAM *gcam, MRI *mri_warp, MRI *mri_warp_dst, MRI *mri_neg_atlas) { +static MRI *GCAMreplaceWarpAtInvalidNodes(GCAM *gcam, MRI *mri_warp, MRI *mri_warp_dst, MRI *mri_neg_atlas) +{ int x, y, z, f, num, xi, yi, zi, xk, yk, zk; double means[3]; MRI *mri_dilated = MRIdilate(mri_neg_atlas, NULL); @@ -18022,7 +18335,8 @@ static MRI *GCAMreplaceWarpAtInvalidNodes(GCAM *gcam, MRI *mri_warp, MRI *mri_wa return (mri_warp_dst); } -int GCAMremoveSingularitiesAndReadWarpFromMRI(GCA_MORPH *gcam, MRI *mri_warp) { +int GCAMremoveSingularitiesAndReadWarpFromMRI(GCA_MORPH *gcam, MRI *mri_warp) +{ int xp, last_neg, wsize, iter, max_iter, nbhd = 1, max_noprogress, noprogress, min_neg, i; double max_nbhd; MRI *mri_warp_tmp = NULL, *mri_neg, *mri_neg_orig, *mri_neg_atlas; @@ -18136,7 +18450,8 @@ int GCAMremoveSingularitiesAndReadWarpFromMRI(GCA_MORPH *gcam, MRI *mri_warp) { printf("neg = %d, increasing nbhd size to %d\n", gcam->neg, nbhd); } } - } else { + } + else { noprogress = 0; min_neg = gcam->neg; } @@ -18152,13 +18467,15 @@ int GCAMremoveSingularitiesAndReadWarpFromMRI(GCA_MORPH *gcam, MRI *mri_warp) { return (NO_ERROR); } MRI *replace_labels( - MRI *mri_src_labels, MRI *mri_dst_labels, int combine_labels[8][2], int ncombine_labels, GCA_MORPH_PARMS *parms) { + MRI *mri_src_labels, MRI *mri_dst_labels, int combine_labels[8][2], int ncombine_labels, GCA_MORPH_PARMS *parms) +{ int n, *dtrans_labels, ndtrans, n2; mri_dst_labels = MRIcopy(mri_src_labels, mri_dst_labels); if (parms) { ndtrans = parms->ndtrans; - } else { + } + else { ndtrans = 0; } for (n = 0; n < ncombine_labels; n++) { @@ -18188,7 +18505,8 @@ MRI *replace_labels( return (mri_dst_labels); } -int fix_borders(GCA_MORPH *gcam) { +int fix_borders(GCA_MORPH *gcam) +{ int x, y, z; GCA_MORPH_NODE *gcamn0, *gcamn1; @@ -18239,7 +18557,8 @@ int fix_borders(GCA_MORPH *gcam) { return (NO_ERROR); } -MRI *GCAMestimateLameConstants(GCA_MORPH *gcam) { +MRI *GCAMestimateLameConstants(GCA_MORPH *gcam) +{ MRI *mri_lame, *mri_warp, *mri_sobel[3]; int x, y, z, dim1, dim2; double energy, val1, val2, lambda, mu, rigid_energy, volume_change; @@ -18282,7 +18601,8 @@ MRI *GCAMestimateLameConstants(GCA_MORPH *gcam) { return (mri_lame); } -int GCAMconcatenate(GCA_MORPH *gcam1, GCA_MORPH *gcam2, GCA_MORPH *gcam_composed) { +int GCAMconcatenate(GCA_MORPH *gcam1, GCA_MORPH *gcam2, GCA_MORPH *gcam_composed) +{ // printf("Entering GCAMconcatenate \n") ; // x, y, z are the col, row, and slice (and xyz) in the gcam/target volume @@ -18358,7 +18678,8 @@ int GCAMconcatenate(GCA_MORPH *gcam1, GCA_MORPH *gcam2, GCA_MORPH *gcam_composed // >>>>>>>>>>>>>>>>>> -GCA_MORPH *GCAMfillInverse(GCA_MORPH *gcam) { +GCA_MORPH *GCAMfillInverse(GCA_MORPH *gcam) +{ MRI *mri; char tmpstr[2000]; int width, height, depth; @@ -18418,7 +18739,8 @@ GCA_MORPH *GCAMfillInverse(GCA_MORPH *gcam) { } return (inv_gcam); } -GCA_MORPH *GCAMdownsample2(GCA_MORPH *gcam) { +GCA_MORPH *GCAMdownsample2(GCA_MORPH *gcam) +{ int xs, ys, zs, xd, yd, zd, labels[MAX_CMA_LABEL + 1], l, max_l, max_count; GCA_MORPH_NODE *gcamn_src, *gcamn_dst; GCA_MORPH *gcam_dst; @@ -18518,7 +18840,8 @@ GCA_MORPH *GCAMdownsample2(GCA_MORPH *gcam) { return (gcam_dst); } -int GCAMdilateUseLikelihood(GCA_MORPH *gcam, int ndilations) { +int GCAMdilateUseLikelihood(GCA_MORPH *gcam, int ndilations) +{ MRI *mri; int x, y, z, i; GCA_MORPH_NODE *gcamn; @@ -18557,7 +18880,8 @@ int GCAMdilateUseLikelihood(GCA_MORPH *gcam, int ndilations) { return (NO_ERROR); } -static MRI *gcamLabelToMRI(GCA_MORPH *gcam, MRI *mri, int label) { +static MRI *gcamLabelToMRI(GCA_MORPH *gcam, MRI *mri, int label) +{ int x, y, z; GCA_MORPH_NODE *gcamn; @@ -18588,7 +18912,8 @@ static MRI *gcamLabelToMRI(GCA_MORPH *gcam, MRI *mri, int label) { #include "mrisegment.h" #include "voxlist.h" -static int grow_ventricles(MRI *mri_vent, MRI *mri_inputs, int whalf, int thresh) { +static int grow_ventricles(MRI *mri_vent, MRI *mri_inputs, int whalf, int thresh) +{ VOXLIST *vl = NULL; int nadded, x, y, z, i, wsize, pass = 0; MRI *mri_dilated = NULL, *mri_border = NULL; @@ -18643,7 +18968,8 @@ static int grow_ventricles(MRI *mri_vent, MRI *mri_inputs, int whalf, int thresh return (NO_ERROR); } -int GCAMcomputeVentricleExpansionGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_vent, int navgs) { +int GCAMcomputeVentricleExpansionGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_vent, int navgs) +{ int x, y, z; GCA_MORPH_NODE *gcamn; MRI *mri_vent_atlas_dist, *mri_vent_atlas, *mri_vent_atlas_dist_grad; @@ -18690,7 +19016,8 @@ int GCAMcomputeVentricleExpansionGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_ve gcamn->dx = MRIgetVoxVal(mri_vent_atlas_dist_grad, x, y, z, 0); gcamn->dy = MRIgetVoxVal(mri_vent_atlas_dist_grad, x, y, z, 1); gcamn->dz = MRIgetVoxVal(mri_vent_atlas_dist_grad, x, y, z, 2); - } else // it is ventricle in the atlas. If it's not ventricle in image move away from vents + } + else // it is ventricle in the atlas. If it's not ventricle in image move away from vents { MRIsampleVolume(mri, gcamn->x, gcamn->y, gcamn->z, &val); if (val > thresh) // too bright to be ventricle @@ -18700,9 +19027,10 @@ int GCAMcomputeVentricleExpansionGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_ve gcamn->dz = -MRIgetVoxVal(mri_vent_atlas_dist_grad, x, y, z, 2); } } - } else if (IS_UNKNOWN(gcamn->label) && (different_neighbor_labels(gcam, x, y, z, 1) > - 0)) { // use a ring of unknowns outside brain to prevent surface of - // brain from moving too far inward + } + else if (IS_UNKNOWN(gcamn->label) && (different_neighbor_labels(gcam, x, y, z, 1) > + 0)) { // use a ring of unknowns outside brain to prevent surface of + // brain from moving too far inward #if 0 gcamn->dx = -outside_scale*MRIgetVoxVal(mri_vent_atlas_dist_grad, x, y, z, 0) ; gcamn->dy = -outside_scale*MRIgetVoxVal(mri_vent_atlas_dist_grad, x, y, z, 1) ; @@ -18733,7 +19061,8 @@ int GCAMcomputeVentricleExpansionGradient(GCA_MORPH *gcam, MRI *mri, MRI *mri_ve return (NO_ERROR); } -int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { +int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) +{ char fname[STRLEN]; int navgs, which, fixed_steps = 0, n, label, x, y, z, xp, yp, zp, passno = 0; double val, base_sigma, pct_change, rms, last_rms = 0.0, orig_dt, l_orig_smooth, min_dt, l_elastic, tol, start_rms, @@ -18904,7 +19233,8 @@ int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { vmean, vsigma, new_thresh); - } else { + } + else { new_thresh = (csigma * vmean + vsigma * cmean) / (csigma + vsigma); printf("using robust Gaussian fitting - new thresh at %2.1f (V: %2.1f +- %2.1f, C: %2.1f +- %2.1f, )\n", new_thresh, @@ -18960,7 +19290,8 @@ int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { } if (parms->levels < 0) { parms->levels = DEFAULT_PYRAMID_LEVELS; - } else if (parms->levels >= MAX_PYRAMID_LEVELS) { + } + else if (parms->levels >= MAX_PYRAMID_LEVELS) { parms->levels = MAX_PYRAMID_LEVELS; } @@ -18972,13 +19303,15 @@ int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { if (parms->log_fp == NULL) { if (parms->start_t == 0) { parms->log_fp = fopen(fname, "w"); - } else { + } + else { parms->log_fp = fopen(fname, "a"); } } fprintf(parms->log_fp, "expanding ventricular system\n"); log_integration_parms(parms->log_fp, parms); - } else { + } + else { parms->log_fp = NULL; } @@ -18991,7 +19324,8 @@ int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { // make node to have the max_prior label values if (parms->relabel_avgs >= parms->navgs && parms->relabel) { GCAMcomputeLabels(mri, gcam); - } else { + } + else { GCAMcomputeMaxPriorLabels(gcam); } @@ -19009,7 +19343,8 @@ int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { parms->l_smoothness = l_orig_smooth / (sqrt(parms->navgs) + 1); if (parms->integration_type == GCAM_INTEGRATE_OPTIMAL || parms->integration_type == GCAM_INTEGRATE_BOTH) { which = GCAM_INTEGRATE_OPTIMAL; - } else { + } + else { which = GCAM_INTEGRATE_FIXED; } @@ -19076,11 +19411,13 @@ int GCAMregisterVentricles(GCA_MORPH *gcam, MRI *mri, GCA_MORPH_PARMS *parms) { fixed_steps++; which = GCAM_INTEGRATE_FIXED; min_dt = parms->dt = (sqrt(parms->navgs) + 1.0f) * orig_dt; - } else { + } + else { fixed_steps = 0; } parms->dt = min_dt; - } else { + } + else { fixed_steps++; min_dt = parms->dt = (sqrt(parms->navgs) + 1.0f) * orig_dt; } @@ -19222,7 +19559,8 @@ GCAMsetNegativeNodeStatus(GCA_MORPH *gcam, int status) } #endif -static int most_likely_label(GCA_MORPH *gcam, TRANSFORM *transform, int xp, int yp, int zp, MRI *mri_inputs) { +static int most_likely_label(GCA_MORPH *gcam, TRANSFORM *transform, int xp, int yp, int zp, MRI *mri_inputs) +{ int n, best_label; float p, max_p, x, y, z; GCA_PRIOR *gcap; @@ -19248,7 +19586,8 @@ static int most_likely_label(GCA_MORPH *gcam, TRANSFORM *transform, int xp, int the col, row, slice in the source image. The geometry is set to match that of the atlas image. */ -MRI *GCAMtoMRI(GCAM *gcam, MRI *mri) { +MRI *GCAMtoMRI(GCAM *gcam, MRI *mri) +{ int c; if (mri == NULL) { diff --git a/utils/gcamorphcpu.cpp b/utils/gcamorphcpu.cpp index 67a8d0e555b..03cd0640d5e 100644 --- a/utils/gcamorphcpu.cpp +++ b/utils/gcamorphcpu.cpp @@ -27,9 +27,10 @@ #include "gcamorphcpu.hpp" -namespace Freesurfer { - -void GCAmorphCPU::CheckIntegrity(void) const { +namespace Freesurfer +{ +void GCAmorphCPU::CheckIntegrity(void) const +{ bool good; good = this->rx.MatchDims(this->ry); @@ -71,7 +72,8 @@ void GCAmorphCPU::CheckIntegrity(void) const { // ----------------------------- -void GCAmorphCPU::AllocateFromTemplate(const GPU::Classes::GCAmorphGPU &src) { +void GCAmorphCPU::AllocateFromTemplate(const GPU::Classes::GCAmorphGPU &src) +{ src.CheckIntegrity(); const dim3 dims = src.d_rx.GetDims(); @@ -79,7 +81,8 @@ void GCAmorphCPU::AllocateFromTemplate(const GPU::Classes::GCAmorphGPU &src) { this->AllocateAll(dims.x, dims.y, dims.z); } -void GCAmorphCPU::AllocateAll(const unsigned int nx, const unsigned int ny, const unsigned int nz) { +void GCAmorphCPU::AllocateAll(const unsigned int nx, const unsigned int ny, const unsigned int nz) +{ GCAmorphCPU::tAllocate.Start(); this->rx.Allocate(nx, ny, nz); @@ -119,7 +122,8 @@ void GCAmorphCPU::AllocateAll(const unsigned int nx, const unsigned int ny, cons // -------------------------------- -void GCAmorphCPU::GetFromGPU(const GPU::Classes::GCAmorphGPU &src) { +void GCAmorphCPU::GetFromGPU(const GPU::Classes::GCAmorphGPU &src) +{ /*! Retrieves linearly packed data from the GPU. Assumes that the current object has already allocated its memory @@ -181,7 +185,8 @@ void GCAmorphCPU::GetFromGPU(const GPU::Classes::GCAmorphGPU &src) { GCAmorphCPU::tGetTot.Stop(); } -void GCAmorphCPU::PutOnGPU(GPU::Classes::GCAmorphGPU &dst) const { +void GCAmorphCPU::PutOnGPU(GPU::Classes::GCAmorphGPU &dst) const +{ /*! Puts the linearly packed data back on the GPU. Requires preallocated data @@ -245,7 +250,8 @@ void GCAmorphCPU::PutOnGPU(GPU::Classes::GCAmorphGPU &dst) const { // ---------------------------------------------- -void GCAmorphCPU::ShowTimings(void) { +void GCAmorphCPU::ShowTimings(void) +{ #ifdef CUDA_SHOW_TIMINGS std::cout << "==================================" << std::endl; std::cout << "GCAmorphCPU timers" << std::endl; diff --git a/utils/gcamorphtestutils.cpp b/utils/gcamorphtestutils.cpp index dd60523cbb2..47289d414a4 100644 --- a/utils/gcamorphtestutils.cpp +++ b/utils/gcamorphtestutils.cpp @@ -36,7 +36,8 @@ using namespace std; // ====================================================================== -GCAMorphUtils::GCAMorphUtils(void) : varTypeMap(), scalarTypeMap() { +GCAMorphUtils::GCAMorphUtils(void) : varTypeMap(), scalarTypeMap() +{ std::cout << __FUNCTION__ << ": Will not write out saved, saved2 and saved original positions" << std::endl; std::cout << __FUNCTION__ << ": Will not write out spacing scalar value" << std::endl; @@ -102,7 +103,8 @@ GCAMorphUtils::GCAMorphUtils(void) : varTypeMap(), scalarTypeMap() { } } -void GCAMorphUtils::Write(const GCAM *src, string fName) const { +void GCAMorphUtils::Write(const GCAM *src, string fName) const +{ // Construct the filename, using fName passed by value fName += ".nc"; @@ -217,7 +219,8 @@ void GCAMorphUtils::Write(const GCAM *src, string fName) const { if (gcamn.gc != NULL) { mean.at(i1d) = gcamn.gc->means[0]; variance.at(i1d) = gcamn.gc->covars[0]; - } else { + } + else { mean.at(i1d) = -1; variance.at(i1d) = -1; } @@ -273,7 +276,8 @@ void GCAMorphUtils::Write(const GCAM *src, string fName) const { // --------------- -void GCAMorphUtils::Read(GCAM **dst, string fName) const { +void GCAMorphUtils::Read(GCAM **dst, string fName) const +{ // Make sure input pointer is NULL if (*dst != NULL) { cerr << __FUNCTION__ << ": dst pointer not NULL!" << endl; @@ -458,7 +462,8 @@ void GCAMorphUtils::Read(GCAM **dst, string fName) const { gcamn.gc = alloc_gcs(1, 0, 1); gcamn.gc->means[0] = mean.at(i1d); gcamn.gc->covars[0] = variance.at(i1d); - } else { + } + else { gcamn.gc = NULL; } } diff --git a/utils/gcarray.c b/utils/gcarray.c index 82c5e2007b1..2fe1ec2dba2 100644 --- a/utils/gcarray.c +++ b/utils/gcarray.c @@ -74,7 +74,8 @@ int GCarrayFinish(GCARRAY *gcarray); scale pixels, with scale/2 at the left margin. ------------------------------------------------------*/ -GCARRAY *GCarrayAlloc(MRI *mri_template, int scale, int nvars) { +GCARRAY *GCarrayAlloc(MRI *mri_template, int scale, int nvars) +{ GCARRAY *gcarray; int x, y, z, width, height, depth; double xw, yw, zw; @@ -142,7 +143,8 @@ GCARRAY *GCarrayAlloc(MRI *mri_template, int scale, int nvars) { Description ------------------------------------------------------*/ -int GCarrayFree(GCARRAY **pgcarray) { +int GCarrayFree(GCARRAY **pgcarray) +{ GCARRAY *gcarray; int x, y, z; @@ -178,7 +180,8 @@ int GCarrayFree(GCARRAY **pgcarray) { go through again and compute the covariance matrices. ------------------------------------------------------*/ -GCARRAY *GCarrayTrainAll(GCARRAY *gcarray, char *training_file_name, int scale, int ninputs) { +GCARRAY *GCarrayTrainAll(GCARRAY *gcarray, char *training_file_name, int scale, int ninputs) +{ char source_fname[100], target_fname[100], line[300], *cp; FILE *fp; int fno, nfiles; @@ -321,7 +324,8 @@ int GCarrayFinish(GCARRAY *gcarray) { return (NO_ERROR); } #define LO_LIM 60 #define HI_LIM 150 -int GCarrayTrain(GCARRAY *gcarray, MRI *mri_src, MRI *mri_zscore, MRI *mri_target) { +int GCarrayTrain(GCARRAY *gcarray, MRI *mri_src, MRI *mri_zscore, MRI *mri_target) +{ MATRIX *m_inputs[NCLASSES]; GCLASSIFY *gc, **pgc; int x, y, z, x0, y0, z0, x1, y1, z1, xm, ym, zm, xv, yv, zv, width, depth, height, scale, classno, nclasses, @@ -432,7 +436,8 @@ int GCarrayTrain(GCARRAY *gcarray, MRI *mri_src, MRI *mri_zscore, MRI *mri_targe ------------------------------------------------------*/ #define PRETTY_SURE .90f -MRI *GCarrayClassify(GCARRAY *gcarray, MRI *mri_src, MRI *mri_dst, float conf, MRI *mri_probs, MRI *mri_classes) { +MRI *GCarrayClassify(GCARRAY *gcarray, MRI *mri_src, MRI *mri_dst, float conf, MRI *mri_probs, MRI *mri_classes) +{ MATRIX *m_inputs; GCLASSIFY *gc; int x, y, z, xc, yc, zc, width, depth, height, scale, classno, swidth, sheight, sdepth; @@ -542,7 +547,8 @@ MRI *GCarrayClassify(GCARRAY *gcarray, MRI *mri_src, MRI *mri_dst, float conf, M Description ------------------------------------------------------*/ -int GCarrayToVoxel(GCARRAY *gcarray, int xc, int yc, int zc, int *pxv, int *pyv, int *pzv) { +int GCarrayToVoxel(GCARRAY *gcarray, int xc, int yc, int zc, int *pxv, int *pyv, int *pzv) +{ int scale; scale = gcarray->scale; @@ -559,7 +565,8 @@ int GCarrayToVoxel(GCARRAY *gcarray, int xc, int yc, int zc, int *pxv, int *pyv, Description ------------------------------------------------------*/ -int GCarrayVoxelToClass(GCARRAY *gcarray, int xv, int yv, int zv, int *pxc, int *pyc, int *pzc) { +int GCarrayVoxelToClass(GCARRAY *gcarray, int xv, int yv, int zv, int *pxc, int *pyc, int *pzc) +{ int scale; scale = gcarray->scale; @@ -576,7 +583,8 @@ int GCarrayVoxelToClass(GCARRAY *gcarray, int xv, int yv, int zv, int *pxc, int Description ------------------------------------------------------*/ -int GCarraySetTransform(GCARRAY *gcarray, Transform *transform, Transform *inverse_transform) { +int GCarraySetTransform(GCARRAY *gcarray, Transform *transform, Transform *inverse_transform) +{ gcarray->transform = transform; gcarray->inverse_transform = inverse_transform; return (NO_ERROR); @@ -589,7 +597,8 @@ int GCarraySetTransform(GCARRAY *gcarray, Transform *transform, Transform *inver Description ------------------------------------------------------*/ -GCARRAY *GCarrayRead(char *fname) { +GCARRAY *GCarrayRead(char *fname) +{ GCARRAY *gcarray; FILE *fp; int width, height, depth, nvars, scale, x, y, z; @@ -643,7 +652,8 @@ GCARRAY *GCarrayRead(char *fname) { Description ------------------------------------------------------*/ -int GCarrayWrite(GCARRAY *gcarray, char *fname) { +int GCarrayWrite(GCARRAY *gcarray, char *fname) +{ FILE *fp; int x, y, z; @@ -682,7 +692,8 @@ int GCarrayWrite(GCARRAY *gcarray, char *fname) { Description ------------------------------------------------------*/ -MRI *GCarrayThreshold(GCARRAY *gcarray, MRI *mri_probs, MRI *mri_classes, MRI *mri_dst, float threshold) { +MRI *GCarrayThreshold(GCARRAY *gcarray, MRI *mri_probs, MRI *mri_classes, MRI *mri_dst, float threshold) +{ int x, y, z, width, height, depth, class; float *pprobs, prob; BUFTYPE *pclasses, *pdst; @@ -721,7 +732,8 @@ MRI *GCarrayThreshold(GCARRAY *gcarray, MRI *mri_probs, MRI *mri_classes, MRI *m Description ------------------------------------------------------*/ -GCLASSIFY *MRIgetClassifier(GCARRAY *gcarray, MRI *mri, int x, int y, int z) { +GCLASSIFY *MRIgetClassifier(GCARRAY *gcarray, MRI *mri, int x, int y, int z) +{ GCLASSIFY *gc; double xt, yt, zt; int width, depth, height, scale, xc, yc, zc, xv, yv, zv; @@ -778,7 +790,8 @@ GCLASSIFY *MRIgetClassifier(GCARRAY *gcarray, MRI *mri, int x, int y, int z) { Description update the means using this set of images ------------------------------------------------------*/ -int GCarrayUpdateMeans(GCARRAY *gcarray, MRI *mris[], MRI *mri_target, int nimages) { +int GCarrayUpdateMeans(GCARRAY *gcarray, MRI *mris[], MRI *mri_target, int nimages) +{ GCLASSIFY *gc; GCLASS *gcl; int x, y, z, xc, yc, zc, width, depth, height, scale, classno, swidth, sheight, sdepth; @@ -878,7 +891,8 @@ int GCarrayUpdateMeans(GCARRAY *gcarray, MRI *mris[], MRI *mri_target, int nimag Description update the covariance estimates based on new observations ------------------------------------------------------*/ -int GCarrayUpdateCovariances(GCARRAY *gcarray, MRI *mris[], MRI *mri_target, int nimages) { +int GCarrayUpdateCovariances(GCARRAY *gcarray, MRI *mris[], MRI *mri_target, int nimages) +{ GCLASSIFY *gc; GCLASS *gcl; int x, y, z, xc, yc, zc, width, depth, height, scale, classno, swidth, sheight, sdepth, col, row; @@ -984,7 +998,8 @@ int GCarrayUpdateCovariances(GCARRAY *gcarray, MRI *mris[], MRI *mri_target, int Description compute the means for each class ------------------------------------------------------*/ -int GCarrayComputeMeans(GCARRAY *gcarray) { +int GCarrayComputeMeans(GCARRAY *gcarray) +{ GCLASSIFY *gc, **pgc; GCLASS *gcl; int x, y, z, width, depth, height, classno, nclasses, nobs, row; @@ -1027,7 +1042,8 @@ int GCarrayComputeMeans(GCARRAY *gcarray) { Description compute the means for each class ------------------------------------------------------*/ -int GCarrayComputeCovariances(GCARRAY *gcarray) { +int GCarrayComputeCovariances(GCARRAY *gcarray) +{ GCLASSIFY *gc, **pgc; GCLASS *gcl; int x, y, z, width, depth, height, classno, nclasses, row, col; diff --git a/utils/gcautils.cpp b/utils/gcautils.cpp index 32bfc1ed932..7ec2ceadc79 100644 --- a/utils/gcautils.cpp +++ b/utils/gcautils.cpp @@ -30,9 +30,10 @@ // ============================================================ -namespace Freesurfer { - -void GetGCAstats(const GCA *const src) { +namespace Freesurfer +{ +void GetGCAstats(const GCA *const src) +{ std::cout << "GCA Vital Statistics" << std::endl; std::cout << "ninputs : " << src->ninputs << std::endl; @@ -46,7 +47,8 @@ void GetGCAstats(const GCA *const src) { // -------------------------------------- -void GetGCAnodeStats(const GCA *const src) { +void GetGCAnodeStats(const GCA *const src) +{ std::cout << "Stats from nodes:" << std::endl; unsigned int nx, ny, nz; @@ -93,7 +95,8 @@ void GetGCAnodeStats(const GCA *const src) { // -------------------------------------- -void GetGCApriorStats(const GCA *const src) { +void GetGCApriorStats(const GCA *const src) +{ std::cout << "Stats from priors:" << std::endl; unsigned int nx, ny, nz; diff --git a/utils/gclass.c b/utils/gclass.c index a02553bd798..0d5a517efc1 100644 --- a/utils/gclass.c +++ b/utils/gclass.c @@ -66,7 +66,8 @@ Description ------------------------------------------------------*/ -GCLASSIFY *GCalloc(int nclasses, int nvars, char *class_names[]) { +GCLASSIFY *GCalloc(int nclasses, int nvars, char *class_names[]) +{ GCLASSIFY *gc; GCLASS *gcl; int cno; @@ -156,7 +157,8 @@ GCLASSIFY *GCalloc(int nclasses, int nvars, char *class_names[]) { is the # of observations, and the # of cols is the # of variables. ------------------------------------------------------*/ -int GCtrain(GCLASSIFY *gc, int class, MATRIX *m_inputs) { +int GCtrain(GCLASSIFY *gc, int class, MATRIX *m_inputs) +{ GCLASS *gcl; gcl = &gc->classes[class]; @@ -181,7 +183,8 @@ int GCtrain(GCLASSIFY *gc, int class, MATRIX *m_inputs) { Description ------------------------------------------------------*/ -int GCfree(GCLASSIFY **pgc) { +int GCfree(GCLASSIFY **pgc) +{ GCLASSIFY *gc; GCLASS *gcl; int cno; @@ -212,7 +215,8 @@ int GCfree(GCLASSIFY **pgc) { Description ------------------------------------------------------*/ -int GCclassify(GCLASSIFY *gc, MATRIX *m_x, MATRIX *m_priors, float *prisk) { +int GCclassify(GCLASSIFY *gc, MATRIX *m_x, MATRIX *m_priors, float *prisk) +{ int cno, class = -1; GCLASS *gcl; static MATRIX *m_xT = NULL, *m_tmp, *m_tmp2, *m_tmp3; @@ -277,7 +281,8 @@ int GCclassify(GCLASSIFY *gc, MATRIX *m_x, MATRIX *m_priors, float *prisk) { Description save a classifier to disk in an already opened file ------------------------------------------------------*/ -int GCasciiWriteInto(FILE *fp, GCLASSIFY *gc) { +int GCasciiWriteInto(FILE *fp, GCLASSIFY *gc) +{ int classno; fprintf(fp, "%d %d %d\n", gc->nclasses, gc->nvars, gc->type); @@ -294,7 +299,8 @@ int GCasciiWriteInto(FILE *fp, GCLASSIFY *gc) { read a classifier from disk in ASCII format from an already opened file. ------------------------------------------------------*/ -GCLASSIFY *GCasciiReadFrom(FILE *fp, GCLASSIFY *gc) { +GCLASSIFY *GCasciiReadFrom(FILE *fp, GCLASSIFY *gc) +{ int classno, nclasses, nvars, type; if (fscanf(fp, "%d %d %d\n", &nclasses, &nvars, &type) != 3) @@ -303,7 +309,8 @@ GCLASSIFY *GCasciiReadFrom(FILE *fp, GCLASSIFY *gc) { if (!gc) { gc = GCalloc(nclasses, nvars, NULL); if (!gc) ErrorReturn(NULL, (ERROR_BADFILE, "GCasciiReadFrom: GCalloc failed")); - } else if ((gc->nclasses != nclasses) || (gc->nvars != nvars)) + } + else if ((gc->nclasses != nclasses) || (gc->nvars != nvars)) ErrorReturn(NULL, (ERROR_BADPARM, "GCasciiReadFrom: specified classifier is of wrong form")); for (classno = 0; classno < gc->nclasses; classno++) GCasciiReadClassFrom(fp, &gc->classes[classno]); @@ -318,7 +325,8 @@ GCLASSIFY *GCasciiReadFrom(FILE *fp, GCLASSIFY *gc) { Description write a single class to disk in ascii format ------------------------------------------------------*/ -int GCasciiWriteClassInto(FILE *fp, GCLASS *gcl) { +int GCasciiWriteClassInto(FILE *fp, GCLASS *gcl) +{ fprintf(fp, "%d %f %d\n", gcl->classno, gcl->w0, gcl->nobs); fprintf(fp, "%s\n", gcl->class_name); MatrixAsciiWriteInto(fp, gcl->m_covariance); @@ -335,7 +343,8 @@ int GCasciiWriteClassInto(FILE *fp, GCLASS *gcl) { Description read a single class from disk in ascii format ------------------------------------------------------*/ -GCLASS *GCasciiReadClassFrom(FILE *fp, GCLASS *gcl) { +GCLASS *GCasciiReadClassFrom(FILE *fp, GCLASS *gcl) +{ char class_name[CLASS_NAME_LEN], *cp; if (fscanf(fp, "%d %f %d\n", &gcl->classno, &gcl->w0, &gcl->nobs) != 3) @@ -362,7 +371,8 @@ GCLASS *GCasciiReadClassFrom(FILE *fp, GCLASS *gcl) { static components. After this call, the classifier should be ready for use. ------------------------------------------------------*/ -int GCinit(GCLASSIFY *gc, int class) { +int GCinit(GCLASSIFY *gc, int class) +{ GCLASS *gcl; MATRIX *m_sigma_inverse, *m_uT, *m_tmp, *m_tmp2; float det; diff --git a/utils/gcsa.c b/utils/gcsa.c index 750815a19c8..d3d37b77b68 100644 --- a/utils/gcsa.c +++ b/utils/gcsa.c @@ -75,7 +75,8 @@ static int load_inputs(VERTEX *v, double *v_inputs, int ninputs); static int fill_cpn_holes(GCSA *gcsa); static int fill_gcsan_holes(GCSA *gcsa); -GCSA *GCSAalloc(int ninputs, int icno_priors, int icno_classifiers) { +GCSA *GCSAalloc(int ninputs, int icno_priors, int icno_classifiers) +{ char fname[STRLEN], *cp; int i, n; GCSA *gcsa; @@ -171,7 +172,8 @@ GCSA *GCSAalloc(int ninputs, int icno_priors, int icno_classifiers) { return (gcsa); } -int GCSAfree(GCSA **pgcsa) { +int GCSAfree(GCSA **pgcsa) +{ int i, n; GCSA *gcsa; GCSA_NODE *gcsan; @@ -216,7 +218,8 @@ int GCSAfree(GCSA **pgcsa) { v->origx,y,z should have original coordinates. second fundamental form should have been computed on */ -int GCSAtrainMeans(GCSA *gcsa, MRI_SURFACE *mris) { +int GCSAtrainMeans(GCSA *gcsa, MRI_SURFACE *mris) +{ int vno, vno_prior, vno_classifier; VERTEX *v, *v_prior, *v_classifier; GCSA_NODE *gcsan; @@ -258,7 +261,8 @@ int GCSAtrainMeans(GCSA *gcsa, MRI_SURFACE *mris) { return (NO_ERROR); } -int GCSAtrainCovariances(GCSA *gcsa, MRI_SURFACE *mris) { +int GCSAtrainCovariances(GCSA *gcsa, MRI_SURFACE *mris) +{ int vno, vno_classifier, vno_prior; VERTEX *v, *v_classifier, *v_prior; GCSA_NODE *gcsan; @@ -287,27 +291,31 @@ int GCSAtrainCovariances(GCSA *gcsa, MRI_SURFACE *mris) { return (NO_ERROR); } -VERTEX *GCSAsourceToClassifierVertex(GCSA *gcsa, VERTEX *v) { +VERTEX *GCSAsourceToClassifierVertex(GCSA *gcsa, VERTEX *v) +{ VERTEX *vdst; vdst = MHTfindClosestVertex(gcsa->mht_classifiers, gcsa->mris_classifiers, v); return (vdst); } /*------------------------------------------------------------------*/ -VERTEX *GCSAsourceToPriorVertex(GCSA *gcsa, VERTEX *v) { +VERTEX *GCSAsourceToPriorVertex(GCSA *gcsa, VERTEX *v) +{ VERTEX *vdst; vdst = MHTfindClosestVertex(gcsa->mht_priors, gcsa->mris_priors, v); return (vdst); } /*------------------------------------------------------------------*/ -int GCSAsourceToPriorVertexNo(GCSA *gcsa, VERTEX *v) { +int GCSAsourceToPriorVertexNo(GCSA *gcsa, VERTEX *v) +{ int vdstno; float dmin; vdstno = MHTfindClosestVertexNo(gcsa->mht_priors, gcsa->mris_priors, v, &dmin); return (vdstno); } -static int GCSAupdateNodeMeans(GCSA_NODE *gcsan, int label, double *v_inputs, int ninputs) { +static int GCSAupdateNodeMeans(GCSA_NODE *gcsan, int label, double *v_inputs, int ninputs) +{ int n, i; GCS *gcs; @@ -370,7 +378,8 @@ static int GCSAupdateNodeMeans(GCSA_NODE *gcsan, int label, double *v_inputs, in return (NO_ERROR); } -int GCSAnormalizeMeans(GCSA *gcsa) { +int GCSAnormalizeMeans(GCSA *gcsa) +{ int vno, n, total_gcs, total_cps; GCSA_NODE *gcsan; GCS *gcs; @@ -396,7 +405,8 @@ int GCSAnormalizeMeans(GCSA *gcsa) { return (NO_ERROR); } -static int GCSAupdateNodeCovariance(GCSA_NODE *gcsan, int label, double *v_inputs, int ninputs) { +static int GCSAupdateNodeCovariance(GCSA_NODE *gcsan, int label, double *v_inputs, int ninputs) +{ int n, i, j; GCS *gcs; double cov, mean1, mean2; @@ -424,7 +434,8 @@ static int GCSAupdateNodeCovariance(GCSA_NODE *gcsan, int label, double *v_input return (NO_ERROR); } -int GCSAnormalizeCovariances(GCSA *gcsa) { +int GCSAnormalizeCovariances(GCSA *gcsa) +{ int vno, n, cno, i, j; GCSA_NODE *gcsan; GCS *gcs; @@ -451,7 +462,8 @@ int GCSAnormalizeCovariances(GCSA *gcsa) { if (min_var < MIN_VAR) min_var = MIN_VAR; if (*MATRIX_RELT(gcs->m_cov, i, i) < min_var) *MATRIX_RELT(gcs->m_cov, i, i) = min_var; } - } else { + } + else { for (i = 1; i <= gcsa->ninputs; i++) { mean = VECTOR_ELT(gcs->v_means, i); min_var = mean * .1; @@ -473,7 +485,8 @@ int GCSAnormalizeCovariances(GCSA *gcsa) { m_inv = MatrixIdentity(gcsa->ninputs, NULL); if (!m_inv) { fprintf(stderr, "vno %d, n = %d, m_cov is singular!\n", vno, n); - } else + } + else MatrixFree(&m_inv); } } @@ -497,7 +510,8 @@ int GCSAnormalizeCovariances(GCSA *gcsa) { return (NO_ERROR); } -int GCSAwrite(GCSA *gcsa, char *fname) { +int GCSAwrite(GCSA *gcsa, char *fname) +{ FILE *fp; int vno, n, i, j; GCSA_NODE *gcsan; @@ -574,7 +588,8 @@ int GCSAwrite(GCSA *gcsa, char *fname) { return (NO_ERROR); } -GCSA *GCSAread(char *fname) { +GCSA *GCSAread(char *fname) +{ FILE *fp; int vno, n, ninputs, icno_classifiers, icno_priors, magic, i, j; GCSA_NODE *gcsan; @@ -703,7 +718,8 @@ GCSA *GCSAread(char *fname) { return (gcsa); } /*---------------------------------------------------------*/ -int GCSAbuildMostLikelyLabels(GCSA *gcsa, MRI_SURFACE *mris) { +int GCSAbuildMostLikelyLabels(GCSA *gcsa, MRI_SURFACE *mris) +{ int vno, vno_prior, max_label, n; VERTEX *v; //, *v_prior ; CP_NODE *cpn; @@ -738,7 +754,8 @@ int GCSAbuildMostLikelyLabels(GCSA *gcsa, MRI_SURFACE *mris) { } static int Gvno = -1; -int GCSAlabel(GCSA *gcsa, MRI_SURFACE *mris) { +int GCSAlabel(GCSA *gcsa, MRI_SURFACE *mris) +{ int vno, vno_classifier, label, vno_prior; VERTEX *v, *v_classifier, *v_prior; GCSA_NODE *gcsan; @@ -793,7 +810,8 @@ int GCSAlabel(GCSA *gcsa, MRI_SURFACE *mris) { } static int GCSANclassify( - GCSA_NODE *gcsan, CP_NODE *cpn, double *v_inputs, int ninputs, double *pprob, int *exclude_list, int nexcluded) { + GCSA_NODE *gcsan, CP_NODE *cpn, double *v_inputs, int ninputs, double *pprob, int *exclude_list, int nexcluded) +{ int n, best_label, i, j, skip; double p, ptotal, max_p, det; CP *cp; @@ -859,7 +877,8 @@ static int GCSANclassify( return (best_label); } -int dump_gcsan(GCSA_NODE *gcsan, CP_NODE *cpn, FILE *fp, int verbose) { +int dump_gcsan(GCSA_NODE *gcsan, CP_NODE *cpn, FILE *fp, int verbose) +{ int n, index, i, j; GCS *gcs; char *name; @@ -882,7 +901,8 @@ int dump_gcsan(GCSA_NODE *gcsan, CP_NODE *cpn, FILE *fp, int verbose) { MatrixPrint(fp, gcs->v_means); fprintf(fp, "\tcovariance:\n"); MatrixPrint(fp, gcs->m_cov); - } else { + } + else { fprintf(fp, "\tmean %2.2f +- %2.1f\n", VECTOR_ELT(gcs->v_means, 1), sqrt(*MATRIX_RELT(gcs->m_cov, 1, 1))); } if (verbose) { @@ -898,7 +918,8 @@ int dump_gcsan(GCSA_NODE *gcsan, CP_NODE *cpn, FILE *fp, int verbose) { return (NO_ERROR); } -int GCSAdump(GCSA *gcsa, int vno, MRI_SURFACE *mris, FILE *fp) { +int GCSAdump(GCSA *gcsa, int vno, MRI_SURFACE *mris, FILE *fp) +{ int vno_classifier, vno_prior; VERTEX *vclassifier, *v, *vprior; GCSA_NODE *gcsan; @@ -926,7 +947,8 @@ int GCSAdump(GCSA *gcsa, int vno, MRI_SURFACE *mris, FILE *fp) { return (NO_ERROR); } -static int GCSAupdateNodeGibbsPriors(CP_NODE *cpn, int label, MRI_SURFACE *mris, int vno) { +static int GCSAupdateNodeGibbsPriors(CP_NODE *cpn, int label, MRI_SURFACE *mris, int vno) +{ int n, i, j, m, nbr_label; CP *cp; VERTEX *v, *vn; @@ -1033,7 +1055,8 @@ static int GCSAupdateNodeGibbsPriors(CP_NODE *cpn, int label, MRI_SURFACE *mris, return (NO_ERROR); } -static int edge_to_index(VERTEX *v, VERTEX *vn) { +static int edge_to_index(VERTEX *v, VERTEX *vn) +{ float dx, dy, dz, dot1, dot2, index, x_dist, y_dist, z_dist; /* first find out which of the principal directions the edge connecting v @@ -1067,7 +1090,8 @@ static int edge_to_index(VERTEX *v, VERTEX *vn) { int gcsa_write_iterations = 0; char *gcsa_write_fname = NULL; -int GCSAreclassifyUsingGibbsPriors(GCSA *gcsa, MRI_SURFACE *mris) { +int GCSAreclassifyUsingGibbsPriors(GCSA *gcsa, MRI_SURFACE *mris) +{ int *indices; int n, vno, i, nchanged, label, best_label, old_label, vno_prior, vno_classifier, niter, examined; double ll, max_ll; @@ -1168,7 +1192,8 @@ int GCSAreclassifyUsingGibbsPriors(GCSA *gcsa, MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScomputeVertexPermutation(MRI_SURFACE *mris, int *indices) { +int MRIScomputeVertexPermutation(MRI_SURFACE *mris, int *indices) +{ int i, index, tmp; for (i = 0; i < mris->nvertices; i++) { @@ -1185,7 +1210,8 @@ int MRIScomputeVertexPermutation(MRI_SURFACE *mris, int *indices) { } static double gcsaNbhdGibbsLogLikelihood( - GCSA *gcsa, MRI_SURFACE *mris, double *v_inputs, int vno, double gibbs_coef, int label) { + GCSA *gcsa, MRI_SURFACE *mris, double *v_inputs, int vno, double gibbs_coef, int label) +{ double total_ll, ll; int n, old_annotation; VERTEX *v; @@ -1206,8 +1232,8 @@ static double gcsaNbhdGibbsLogLikelihood( return (total_ll); } -static double gcsaVertexGibbsLogLikelihood( - GCSA *gcsa, MRI_SURFACE *mris, double *v_inputs, int vno, double gibbs_coef) { +static double gcsaVertexGibbsLogLikelihood(GCSA *gcsa, MRI_SURFACE *mris, double *v_inputs, int vno, double gibbs_coef) +{ double ll, nbr_prior, det; int nbr_label, label, i, j, np, n, nc, vno_prior, vno_classifier; GCSA_NODE *gcsan; @@ -1275,7 +1301,8 @@ static double gcsaVertexGibbsLogLikelihood( nbr_prior += log(cp->label_priors[i][j]); else nbr_prior += BIG_AND_NEGATIVE; - } else /* never occurred - make it unlikely */ + } + else /* never occurred - make it unlikely */ { nbr_prior += BIG_AND_NEGATIVE; } @@ -1298,7 +1325,8 @@ getCP(CP_NODE *cpn, int label) } #endif -static GCS *getGC(GCSA_NODE *gcsan, int label, int *pn) { +static GCS *getGC(GCSA_NODE *gcsan, int label, int *pn) +{ int n; for (n = 0; n < gcsan->nlabels; n++) @@ -1309,7 +1337,8 @@ static GCS *getGC(GCSA_NODE *gcsan, int label, int *pn) { return (NULL); } -int GCSAreclassifyLabel(GCSA *gcsa, MRI_SURFACE *mris, LABEL *area) { +int GCSAreclassifyLabel(GCSA *gcsa, MRI_SURFACE *mris, LABEL *area) +{ int i, n, vno, annotation, best_label, max_ll, ll, nchanged, total; VERTEX *v, *vn; double v_inputs[100]; @@ -1355,7 +1384,8 @@ int GCSAreclassifyLabel(GCSA *gcsa, MRI_SURFACE *mris, LABEL *area) { return (total); } -static int load_inputs(VERTEX *v, double *v_inputs, int ninputs) { +static int load_inputs(VERTEX *v, double *v_inputs, int ninputs) +{ v_inputs[0] = v->val; if (ninputs > 1) v_inputs[1] = v->val2; if (ninputs > 2) v_inputs[2] = v->imag_val; @@ -1363,7 +1393,8 @@ static int load_inputs(VERTEX *v, double *v_inputs, int ninputs) { } #if 1 -static int fill_cpn_holes(GCSA *gcsa) { +static int fill_cpn_holes(GCSA *gcsa) +{ int min_n, vno, n, i, nholes, nfilled, vno_classifier; double dist, min_dist; float x, y, z; @@ -1466,7 +1497,8 @@ static int fill_cpn_holes(GCSA *gcsa) { return (NO_ERROR); } -static int fill_gcsan_holes(GCSA *gcsa) { +static int fill_gcsan_holes(GCSA *gcsa) +{ int min_n, vno, n, nholes, nfilled; double dist, min_dist; float x, y, z; @@ -1531,7 +1563,8 @@ static int fill_gcsan_holes(GCSA *gcsa) { return (NO_ERROR); } #else -static int fill_cpn_holes(GCSA *gcsa) { +static int fill_cpn_holes(GCSA *gcsa) +{ int vno, n, nholes, nfilled, filled, i; VERTEX *v; CP_NODE *cpn, *cpn_nbr; @@ -1572,7 +1605,8 @@ static int fill_cpn_holes(GCSA *gcsa) { return (NO_ERROR); } -static int fill_gcsan_holes(GCSA *gcsa) { +static int fill_gcsan_holes(GCSA *gcsa) +{ int vno, n, i, nholes, nfilled, filled; VERTEX *v; GCSA_NODE *gcsan, *gcsan_nbr; @@ -1603,7 +1637,8 @@ static int fill_gcsan_holes(GCSA *gcsa) { } #endif -static int add_gc_to_gcsan(GCSA_NODE *gcsan_src, int nsrc, GCSA_NODE *gcsan_dst) { +static int add_gc_to_gcsan(GCSA_NODE *gcsan_src, int nsrc, GCSA_NODE *gcsan_dst) +{ int ndst; for (ndst = 0; ndst < gcsan_dst->nlabels; ndst++) @@ -1640,7 +1675,8 @@ static int add_gc_to_gcsan(GCSA_NODE *gcsan_src, int nsrc, GCSA_NODE *gcsan_dst) gcsan_dst->gcs[ndst].m_cov = MatrixCopy(gcsan_src->gcs[nsrc].m_cov, NULL); gcsan_dst->gcs[ndst].v_means = MatrixCopy(gcsan_src->gcs[nsrc].v_means, NULL); gcsan_dst->max_labels = gcsan_dst->nlabels; - } else /* add to existing GCS */ + } + else /* add to existing GCS */ { GCS *gcs_src, *gcs_dst; MATRIX *m_src, *m_dst; @@ -1858,7 +1894,8 @@ findClosestNode(GCSA *gcsa, int vno, int label) } #endif -int GCSAputInputType(GCSA *gcsa, int type, char *fname, int navgs, int flags, int ino) { +int GCSAputInputType(GCSA *gcsa, int type, char *fname, int navgs, int flags, int ino) +{ if (ino < 0 || ino >= gcsa->ninputs) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, @@ -1875,7 +1912,8 @@ int GCSAputInputType(GCSA *gcsa, int type, char *fname, int navgs, int flags, in return (NO_ERROR); } -int GCSAsetCovariancesToIdentity(GCSA *gcsa) { +int GCSAsetCovariancesToIdentity(GCSA *gcsa) +{ GCSA_NODE *gcsan; GCS *gcs; int i, n; @@ -1893,7 +1931,8 @@ int GCSAsetCovariancesToIdentity(GCSA *gcsa) { } #define MIN_DET 1e-7 -int gcsaFixSingularCovarianceMatrices(GCSA *gcsa) { +int gcsaFixSingularCovarianceMatrices(GCSA *gcsa) +{ int j, fixed = 0, r, n, num, nparams, regularized = 0; GCSA_NODE *gcsan; GCS *gcs; @@ -1931,7 +1970,8 @@ int gcsaFixSingularCovarianceMatrices(GCSA *gcsa) { } min_det = min_det / pow(100.0, gcsa->ninputs); printf(" using min determinant for regularization = %2.3f\n", min_det); - } else + } + else min_det = MIN_DET; for (regularized = fixed = j = 0; j < gcsa->mris_classifiers->nvertices; j++) { @@ -1948,7 +1988,8 @@ int gcsaFixSingularCovarianceMatrices(GCSA *gcsa) { for (r = 0; r < gcsa->ninputs; r++) { *MATRIX_RELT(gcs->m_cov, r + 1, r + 1) += vars[r]; } - } else /* not singular - check if it is ill-conditioned */ + } + else /* not singular - check if it is ill-conditioned */ { if ((gcs->total_training * gcsa->ninputs < 2 * nparams && det < 0.1) || ((det < min_det) && (gcs->total_training < 4 * nparams))) { @@ -1983,7 +2024,8 @@ int gcsaFixSingularCovarianceMatrices(GCSA *gcsa) { return (NO_ERROR); } -int GCSArelabelWithAseg(GCSA *gcsa, MRI_SURFACE *mris, MRI *mri_aseg) { +int GCSArelabelWithAseg(GCSA *gcsa, MRI_SURFACE *mris, MRI *mri_aseg) +{ int old_index, vno, vno_classifier, vno_prior, label, index, changed, cc_annotation; VERTEX *v, *v_classifier, *v_prior; GCSA_NODE *gcsan; @@ -2017,14 +2059,16 @@ int GCSArelabelWithAseg(GCSA *gcsa, MRI_SURFACE *mris, MRI *mri_aseg) { CTABannotationAtIndex(mris->ct, index, &v->annotation); changed++; } - } else if (IS_LAT_VENT(label) || IS_THALAMUS(label) || IS_CAUDATE(label)) { + } + else if (IS_LAT_VENT(label) || IS_THALAMUS(label) || IS_CAUDATE(label)) { CTABfindName(mris->ct, "Medial_wall", &index); if (index < 0) CTABfindName(mris->ct, "unknown", &index); if (index != old_index && index >= 0) { CTABannotationAtIndex(mris->ct, index, &v->annotation); changed++; } - } else if (old_index >= 0 && mris->ct && !stricmp(mris->ct->entries[old_index]->name, "corpuscallosum")) { + } + else if (old_index >= 0 && mris->ct && !stricmp(mris->ct->entries[old_index]->name, "corpuscallosum")) { // find 2nd most likely label that isn't callosum CTABannotationAtIndex(mris->ct, old_index, &cc_annotation); label = GCSANclassify(gcsan, cpn, v_inputs, gcsa->ninputs, &p, &cc_annotation, 1); @@ -2037,7 +2081,8 @@ int GCSArelabelWithAseg(GCSA *gcsa, MRI_SURFACE *mris, MRI *mri_aseg) { printf("%d labels changed using aseg\n", changed); return (NO_ERROR); } -int GCSAreclassifyMarked(GCSA *gcsa, MRI_SURFACE *mris, int mark, int *exclude_list, int nexcluded) { +int GCSAreclassifyMarked(GCSA *gcsa, MRI_SURFACE *mris, int mark, int *exclude_list, int nexcluded) +{ int old_index, vno, vno_classifier, vno_prior, label, index, changed, num, n; VERTEX *v, *v_classifier, *v_prior, *vn; GCSA_NODE *gcsan; diff --git a/utils/geodesics.cpp b/utils/geodesics.cpp index c247e1c734c..58072fb4cc0 100644 --- a/utils/geodesics.cpp +++ b/utils/geodesics.cpp @@ -23,20 +23,23 @@ extern "C" { } // Vertex -struct Vertex { +struct Vertex +{ float x, y; int id; }; // StackItem -struct StackItem { +struct StackItem +{ Vertex a, b, c; int idx; float mina, maxa; }; // Triangle -struct Triangle { +struct Triangle +{ float length[3]; float angle[3]; int vert[3]; @@ -51,7 +54,8 @@ static Vertex extendedPoint(Vertex A, Vertex B, float dA, float dB, float dAB); static std::pair< int, int > makeKey(int a, int b); static void progressBar(float progress); -extern "C" Geodesics *computeGeodesics(MRIS *surf, float maxdist) { +extern "C" Geodesics *computeGeodesics(MRIS *surf, float maxdist) +{ int msec; struct timeb mytimer; TimerStart(&mytimer); @@ -208,15 +212,18 @@ extern "C" Geodesics *computeGeodesics(MRIS *surf, float maxdist) { if ((current_angle < min_angle)) { C = A; A = D; - } else if ((current_angle > max_angle)) { + } + else if ((current_angle > max_angle)) { C = B; B = D; - } else if (((current_angle <= max_angle) && (current_angle >= min_angle))) { + } + else if (((current_angle <= max_angle) && (current_angle >= min_angle))) { // add geodesic to path map if shorter than the previous distance: edge = pathmap.find(makeKey(vertexID, D.id)); if (edge != pathmap.end()) { if ((distance < edge->second) || (edge->second < 0.0)) edge->second = distance; - } else { + } + else { pathmap.insert(make_pair(makeKey(vertexID, D.id), distance)); } // push triangle to the stack: @@ -334,7 +341,8 @@ extern "C" Geodesics *computeGeodesics(MRIS *surf, float maxdist) { return geo; } -extern "C" void geodesicsWrite(Geodesics *geo, int nvertices, char *fname) { +extern "C" void geodesicsWrite(Geodesics *geo, int nvertices, char *fname) +{ int vtxno; FILE *fp; int msec; @@ -361,7 +369,8 @@ extern "C" void geodesicsWrite(Geodesics *geo, int nvertices, char *fname) { fclose(fp); } -extern "C" Geodesics *geodesicsRead(char *fname, int *pnvertices) { +extern "C" Geodesics *geodesicsRead(char *fname, int *pnvertices) +{ int magic, nthvtx; char tmpstr[1000]; FILE *fp; @@ -408,7 +417,8 @@ extern "C" Geodesics *geodesicsRead(char *fname, int *pnvertices) { \fn int geodesicsUniquify(Geodesics *geod) \brief Removes relicants from the v (and dist) lists; vnum is updated. */ -extern "C" int geodesicsUniquify(Geodesics *geod) { +extern "C" int geodesicsUniquify(Geodesics *geod) +{ int nthnbr, *vlist, nunique, k, *vuniq; float *dist; @@ -446,7 +456,8 @@ extern "C" int geodesicsUniquify(Geodesics *geod) { return (nunique); } -static int getIndex(int *arr, int vid) { +static int getIndex(int *arr, int vid) +{ int idx = std::distance(arr, std::find(arr, arr + 3, vid)); // this can be removed: if (idx > 2) { @@ -456,14 +467,16 @@ static int getIndex(int *arr, int vid) { return idx; } -static float distanceBetween(int v1, int v2, MRIS *surf) { +static float distanceBetween(int v1, int v2, MRIS *surf) +{ VERTEX *vert = &surf->vertices[v1]; int *ns = vert->v; int idx = std::distance(ns, std::find(ns, ns + vert->vnum, v2)); return vert->dist[idx]; } -static int findNeighbor(int faceidx, int v1, int v2, MRIS *surf) { +static int findNeighbor(int faceidx, int v1, int v2, MRIS *surf) +{ VERTEX *vert = &surf->vertices[v1]; int f; for (int nf = 0; nf < vert->num; nf++) { @@ -476,7 +489,8 @@ static int findNeighbor(int faceidx, int v1, int v2, MRIS *surf) { return -1; } -static Vertex extendedPoint(Vertex A, Vertex B, float dA, float dB, float dAB) { +static Vertex extendedPoint(Vertex A, Vertex B, float dA, float dB, float dAB) +{ Vertex D; float a, h, px, py; a = (dA * dA - dB * dB + dAB * dAB) / (2 * dAB); @@ -488,14 +502,16 @@ static Vertex extendedPoint(Vertex A, Vertex B, float dA, float dB, float dAB) { return D; } -static std::pair< int, int > makeKey(int a, int b) { +static std::pair< int, int > makeKey(int a, int b) +{ if (a < b) return std::pair< int, int >(a, b); else return std::pair< int, int >(b, a); } -static void progressBar(float progress) { +static void progressBar(float progress) +{ if (!isatty(fileno(stdout))) return; int barwidth = 25; std::cout << " ["; diff --git a/utils/getdelim.c b/utils/getdelim.c index d79094ef621..c27a99d7885 100644 --- a/utils/getdelim.c +++ b/utils/getdelim.c @@ -41,7 +41,8 @@ necessary. Returns the number of characters read (not including the null terminator), or -1 on error or EOF. */ -ssize_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *fp) { +ssize_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *fp) +{ ssize_t result = 0; size_t cur_len = 0; diff --git a/utils/gifti_io.c b/utils/gifti_io.c index e60430a72eb..b3d2808e885 100644 --- a/utils/gifti_io.c +++ b/utils/gifti_io.c @@ -163,7 +163,8 @@ static gifti_type_ele gifti_type_list[] = { {NIFTI_TYPE_COMPLEX256, 32, 16, "NIFTI_TYPE_COMPLEX256"}}; /*! this list provides a link between intent codes and their name strings */ -typedef struct { +typedef struct +{ int code; char *name; } gifti_intent_ele; @@ -232,7 +233,8 @@ static gifti_globals G = {1}; /*! user variable accessor functions - basically use gxml interface */ int gifti_get_verb(void) { return G.verb; } -int gifti_set_verb(int level) { +int gifti_set_verb(int level) +{ G.verb = level; return 1; } @@ -243,7 +245,8 @@ int gifti_set_b64_check(int level) { return gxml_set_b64_check(level); } int gifti_get_update_ok(void) { return gxml_get_update_ok(); } int gifti_set_update_ok(int level) { return gxml_set_update_ok(level); } int gifti_get_zlevel(void) { return gxml_get_zlevel(); } -int gifti_set_zlevel(int level) { +int gifti_set_zlevel(int level) +{ /* note that the default currently results in 6 */ if (level != GZ_DEFAULT_COMPRESSION && (level < 0 || level > 9)) { fprintf(stderr, "** invalid zlevel, must be %d (default) or {0..9}\n", GZ_DEFAULT_COMPRESSION); @@ -256,7 +259,8 @@ int gifti_get_xml_buf_size(void) { return gxml_get_buf_size(); } int gifti_set_xml_buf_size(int buf_size) { return gxml_set_buf_size(buf_size); } /*! reset user variables to their defaults(via set to -1) */ -int gifti_reset_user_vars(void) { +int gifti_reset_user_vars(void) +{ gxml_set_verb(-1); gxml_set_dstore(-1); gxml_set_indent(-1); @@ -280,7 +284,8 @@ int gifti_reset_user_vars(void) { * * return 0 on success */ /*-------------------------------------------------------------------*/ -int gifti_str2attr_gifti(gifti_image *gim, const char *attr, const char *val) { +int gifti_str2attr_gifti(gifti_image *gim, const char *attr, const char *val) +{ if (!gim || !attr || !val) { fprintf(stderr, "** GS2AG: bad params (%p,%p,%p)\n", (void *)gim, (void *)attr, (void *)val); return 1; @@ -291,17 +296,20 @@ int gifti_str2attr_gifti(gifti_image *gim, const char *attr, const char *val) { if (!strcmp(attr, "Version")) { if (gim->version) free(gim->version); /* lose any old copy */ gim->version = gifti_strdup(val); - } else if (!strcmp(attr, "NumberOfDataArrays")) { + } + else if (!strcmp(attr, "NumberOfDataArrays")) { gim->numDA = atol(val); if (gim->numDA < 0) { fprintf(stderr, "** invalid NumberOfDataArrays attribute: %s\n", val); gim->numDA = 0; return 1; } - } else if (!strcmp(attr, "xmlns:xsi") || !strcmp(attr, "xsi:noNamespaceSchemaLocation")) { + } + else if (!strcmp(attr, "xmlns:xsi") || !strcmp(attr, "xsi:noNamespaceSchemaLocation")) { if (G.verb > 1) fprintf(stderr, "-- have GIFTI attr, '%s'='%s'\n", attr, val); return 1; - } else { + } + else { if (G.verb > 1) fprintf(stderr, "** unknown GIFTI attrib, '%s'='%s'\n", attr, val); return 1; } @@ -319,7 +327,8 @@ int gifti_str2attr_gifti(gifti_image *gim, const char *attr, const char *val) { * return an allocated gifti_image struct on success, * NULL on error */ /*-------------------------------------------------------------------*/ -gifti_image *gifti_read_image(const char *fname, int read_data) { +gifti_image *gifti_read_image(const char *fname, int read_data) +{ if (!fname) { fprintf(stderr, "** gifti_read_image: missing filename\n"); return NULL; @@ -344,7 +353,8 @@ gifti_image *gifti_read_image(const char *fname, int read_data) { * return an allocated gifti_image struct on success, * NULL on error */ /*-------------------------------------------------------------------*/ -gifti_image *gifti_read_da_list(const char *fname, int read_data, const int *dalist, int len) { +gifti_image *gifti_read_da_list(const char *fname, int read_data, const int *dalist, int len) +{ if (!fname) { fprintf(stderr, "** gifti_read_da_list: missing filename\n"); return NULL; @@ -363,13 +373,15 @@ gifti_image *gifti_read_da_list(const char *fname, int read_data, const int *dal * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_write_image(gifti_image *gim, const char *fname, int write_data) { +int gifti_write_image(gifti_image *gim, const char *fname, int write_data) +{ int errs = 0; if (!gim) { fprintf(stderr, "** gifti_write_image, missing gifti_image\n"); errs++; - } else if (!fname) { + } + else if (!fname) { fprintf(stderr, "** gifti_write_image: missing filename\n"); errs++; } @@ -388,7 +400,8 @@ int gifti_write_image(gifti_image *gim, const char *fname, int write_data) { * * the pointer is garbage after this call */ /*-------------------------------------------------------------------*/ -int gifti_free_image(gifti_image *gim) { +int gifti_free_image(gifti_image *gim) +{ if (!gim) { if (G.verb > 2) fprintf(stderr, "** free gifti_image w/NULL pointer\n"); return 1; @@ -415,7 +428,8 @@ int gifti_free_image(gifti_image *gim) { * * the pointer is garbage after this call */ /*-------------------------------------------------------------------*/ -int gifti_free_image_contents(gifti_image *gim) { +int gifti_free_image_contents(gifti_image *gim) +{ if (!gim) { if (G.verb > 2) fprintf(stderr, "** GFIC: free w/NULL gifti_image ptr\n"); return 1; @@ -441,7 +455,8 @@ int gifti_free_image_contents(gifti_image *gim) { * * passing NULL is okay */ /*-------------------------------------------------------------------*/ -int gifti_free_nvpairs(nvpairs *p) { +int gifti_free_nvpairs(nvpairs *p) +{ int c; if (!p) { @@ -471,7 +486,8 @@ int gifti_free_nvpairs(nvpairs *p) { * * passing NULL is okay */ /*-------------------------------------------------------------------*/ -int gifti_free_LabelTable(giiLabelTable *T) { +int gifti_free_LabelTable(giiLabelTable *T) +{ int c; if (!T) { @@ -507,7 +523,8 @@ int gifti_free_LabelTable(giiLabelTable *T) { * * passing NULL is okay */ /*-------------------------------------------------------------------*/ -int gifti_free_DataArray_list(giiDataArray **darray, int numDA) { +int gifti_free_DataArray_list(giiDataArray **darray, int numDA) +{ int c; if (!darray) { @@ -534,7 +551,8 @@ int gifti_free_DataArray_list(giiDataArray **darray, int numDA) { * * passing NULL is okay */ /*-------------------------------------------------------------------*/ -int gifti_free_DataArray(giiDataArray *darray) { +int gifti_free_DataArray(giiDataArray *darray) +{ if (!darray) { if (G.verb > 3) fprintf(stderr, "** tried to free NULL darray ptr\n"); return 1; @@ -563,7 +581,8 @@ int gifti_free_DataArray(giiDataArray *darray) { *! free the CoordSystem array from a DataArray * passing NULL is okay */ /*-------------------------------------------------------------------*/ -int gifti_free_CS_list(giiDataArray *da) { +int gifti_free_CS_list(giiDataArray *da) +{ int c; if (!da) return 0; @@ -588,7 +607,8 @@ int gifti_free_CS_list(giiDataArray *da) { * * passing NULL is okay */ /*-------------------------------------------------------------------*/ -int gifti_free_CoordSystem(giiCoordSystem *cs) { +int gifti_free_CoordSystem(giiCoordSystem *cs) +{ if (!cs) return 0; if (G.verb > 3) fprintf(stderr, "-- freeing giiCoordSystem\n"); @@ -617,7 +637,8 @@ int gifti_free_CoordSystem(giiCoordSystem *cs) { * if add_to_extras, add any bad attribute pairs to ex_atrs * else whine about any bad ones and return */ /*-------------------------------------------------------------------*/ -int gifti_set_DA_atrs(giiDataArray *da, const char **attr, int alen, int add_to_extras) { +int gifti_set_DA_atrs(giiDataArray *da, const char **attr, int alen, int add_to_extras) +{ int c, length = alen; if (!da || !attr) { @@ -638,7 +659,8 @@ int gifti_set_DA_atrs(giiDataArray *da, const char **attr, int alen, int add_to_ /* a bad name=value pair, maybe add to ex_atrs */ if (add_to_extras) { if (gifti_add_to_nvpairs(&da->ex_atrs, attr[c], attr[c + 1])) return 1; - } else { + } + else { if (G.verb > 0) fprintf(stderr, "** set_darray_atrs, bad pair '%s'='%s'\n", attr[c], attr[c + 1]); return 1; } @@ -660,7 +682,8 @@ int gifti_set_DA_atrs(giiDataArray *da, const char **attr, int alen, int add_to_ * return 1, if valid * 0, if not */ /*-------------------------------------------------------------------*/ -int gifti_valid_DataArray(const giiDataArray *da, int whine) { +int gifti_valid_DataArray(const giiDataArray *da, int whine) +{ int errs = 0, nbyper; if (!da) { @@ -727,7 +750,8 @@ int gifti_valid_DataArray(const giiDataArray *da, int whine) { /*---------------------------------------------------------------------- *! check whether pointers are valid and consistent with length */ /*-------------------------------------------------------------------*/ -int gifti_valid_nvpairs(const nvpairs *nvp, int whine) { +int gifti_valid_nvpairs(const nvpairs *nvp, int whine) +{ int c; if (!nvp) { @@ -768,7 +792,8 @@ int gifti_valid_nvpairs(const nvpairs *nvp, int whine) { * * no check is done on the actual indices or labels */ /*-------------------------------------------------------------------*/ -int gifti_valid_LabelTable(const giiLabelTable *T, int whine) { +int gifti_valid_LabelTable(const giiLabelTable *T, int whine) +{ float *rgba; int c, c2; @@ -817,7 +842,8 @@ int gifti_valid_LabelTable(const giiLabelTable *T, int whine) { /*---------------------------------------------------------------------- *! check the bounds on num_dim */ /*-------------------------------------------------------------------*/ -int gifti_valid_num_dim(int num_dim, int whine) { +int gifti_valid_num_dim(int num_dim, int whine) +{ if (num_dim <= 0 || num_dim > GIFTI_DARRAY_DIM_LEN) { if (G.verb > 3 || whine) fprintf(stderr, "** invalid num_dim = %d\n", num_dim); return 0; @@ -828,7 +854,8 @@ int gifti_valid_num_dim(int num_dim, int whine) { /*---------------------------------------------------------------------- *! check that the datatype is in the list */ /*-------------------------------------------------------------------*/ -int gifti_valid_datatype(int dtype, int whine) { +int gifti_valid_datatype(int dtype, int whine) +{ int c; /* check for valid */ @@ -843,7 +870,8 @@ int gifti_valid_datatype(int dtype, int whine) { /*---------------------------------------------------------------------- *! check that nbyper is one of the values in gifti_type_list */ /*-------------------------------------------------------------------*/ -int gifti_valid_nbyper(int nbyper, int whine) { +int gifti_valid_nbyper(int nbyper, int whine) +{ int c; /* check for valid */ @@ -864,7 +892,8 @@ int gifti_valid_nbyper(int nbyper, int whine) { * - datatype is valid (required to check nbyper) * - nbyper is correct */ /*-------------------------------------------------------------------*/ -int gifti_valid_dims(const giiDataArray *da, int whine) { +int gifti_valid_dims(const giiDataArray *da, int whine) +{ long long vals = 1; int c, nbyper; @@ -920,7 +949,8 @@ int gifti_valid_dims(const giiDataArray *da, int whine) { * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_str2attr_darray(giiDataArray *DA, const char *attr, const char *value) { +int gifti_str2attr_darray(giiDataArray *DA, const char *attr, const char *value) +{ if (!DA || !attr || !value) { if (G.verb > 0) fprintf(stderr, "** G_S2A_D: bad params (%p,%p,%p)\n", (void *)DA, (void *)attr, (void *)value); return 1; @@ -966,7 +996,8 @@ int gifti_str2attr_darray(giiDataArray *DA, const char *attr, const char *value) } /* return 0 (UNDEFINED) on failure */ -static int str2list_index(char *list[], int max, const char *str) { +static int str2list_index(char *list[], int max, const char *str) +{ int index; if (!list || !str) { if (G.verb > 0) fprintf(stderr, "** str2list: bad params (%p,%p)\n", (void *)list, (void *)str); @@ -982,7 +1013,8 @@ static int str2list_index(char *list[], int max, const char *str) { /*---------------------------------------------------------------------- *! return the index for a GIFTI_IND_ORD_* string */ /*-------------------------------------------------------------------*/ -int gifti_str2ind_ord(const char *str) { +int gifti_str2ind_ord(const char *str) +{ int rv = str2list_index(gifti_index_order_list, GIFTI_IND_ORD_MAX, str); if (rv <= GIFTI_IND_ORD_UNDEF && G.verb > 1) fprintf(stderr, "** bad index order, '%s'\n", str); return rv; @@ -991,7 +1023,8 @@ int gifti_str2ind_ord(const char *str) { /*---------------------------------------------------------------------- *! return the index for a GIFTI_ENDODING_* string */ /*-------------------------------------------------------------------*/ -int gifti_str2encoding(const char *str) { +int gifti_str2encoding(const char *str) +{ int rv = str2list_index(gifti_encoding_list, GIFTI_ENCODING_MAX, str); if (rv <= GIFTI_ENCODING_UNDEF && G.verb > 1) fprintf(stderr, "** bad data encoding, '%s'\n", str); return rv; @@ -1003,7 +1036,8 @@ int gifti_str2encoding(const char *str) { * This function is meant to index into one of the gifti_*_list arrays, * while being certain that the index is not out of range. */ /*-------------------------------------------------------------------*/ -char *gifti_list_index2string(char *list[], int index) { +char *gifti_list_index2string(char *list[], int index) +{ int lsize; /* list size cannot be computed from the passed pointer */ if (list == gifti_index_order_list) @@ -1033,7 +1067,8 @@ char *gifti_list_index2string(char *list[], int index) { /*---------------------------------------------------------------------- *! return the NIFTI_TYPE_ value corresponding to the given string */ /*-------------------------------------------------------------------*/ -int gifti_str2datatype(const char *str) { +int gifti_str2datatype(const char *str) +{ int len = sizeof(gifti_type_list) / sizeof(gifti_type_ele); int c; @@ -1046,7 +1081,8 @@ int gifti_str2datatype(const char *str) { /*---------------------------------------------------------------------- *! return the GIFTI_ENDIAN_ value corresponding to the given string */ /*-------------------------------------------------------------------*/ -int gifti_str2endian(const char *str) { +int gifti_str2endian(const char *str) +{ int rv = str2list_index(gifti_endian_list, GIFTI_ENDIAN_MAX, str); if (rv <= GIFTI_ENCODING_UNDEF && G.verb > 1) fprintf(stderr, "** bad endian, '%s'\n", G_CHECK_NULL_STR(str)); return rv; @@ -1055,7 +1091,8 @@ int gifti_str2endian(const char *str) { /*---------------------------------------------------------------------- *! return the NIFTI_TYPE_ value string corresponding to the given type */ /*-------------------------------------------------------------------*/ -char *gifti_datatype2str(int type) { +char *gifti_datatype2str(int type) +{ int len = sizeof(gifti_type_list) / sizeof(gifti_type_ele); int c; @@ -1068,7 +1105,8 @@ char *gifti_datatype2str(int type) { /*---------------------------------------------------------------------- *! simply set the struct contents to empty */ /*-------------------------------------------------------------------*/ -int gifti_clear_nvpairs(nvpairs *p) { +int gifti_clear_nvpairs(nvpairs *p) +{ if (!p) return 1; p->length = 0; @@ -1081,7 +1119,8 @@ int gifti_clear_nvpairs(nvpairs *p) { /*---------------------------------------------------------------------- *! simply set the struct contents to empty */ /*-------------------------------------------------------------------*/ -int gifti_clear_LabelTable(giiLabelTable *p) { +int gifti_clear_LabelTable(giiLabelTable *p) +{ if (!p) return 1; p->length = 0; @@ -1095,7 +1134,8 @@ int gifti_clear_LabelTable(giiLabelTable *p) { /*---------------------------------------------------------------------- *! simply set the struct contents to empty */ /*-------------------------------------------------------------------*/ -int gifti_clear_CoordSystem(giiCoordSystem *p) { +int gifti_clear_CoordSystem(giiCoordSystem *p) +{ if (!p) return 1; p->dataspace = NULL; @@ -1108,7 +1148,8 @@ int gifti_clear_CoordSystem(giiCoordSystem *p) { /*---------------------------------------------------------------------- *! add an empty CoordSystem struct to the DataArray */ /*-------------------------------------------------------------------*/ -int gifti_add_empty_CS(giiDataArray *da) { +int gifti_add_empty_CS(giiDataArray *da) +{ if (!da) return 1; /* be safe, if anything looks bad, start clean */ @@ -1151,7 +1192,8 @@ int gifti_add_empty_CS(giiDataArray *da) { * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_add_empty_darray(gifti_image *gim, int num_to_add) { +int gifti_add_empty_darray(gifti_image *gim, int num_to_add) +{ giiDataArray *dptr; int c, ntot, nnew = num_to_add > 0 ? num_to_add : 1; @@ -1192,7 +1234,8 @@ int gifti_add_empty_darray(gifti_image *gim, int num_to_add) { * this allocates memory for the p->name and p->value arrays, along * with duplicating the passed name/value strings */ /*-------------------------------------------------------------------*/ -int gifti_add_to_nvpairs(nvpairs *p, const char *name, const char *value) { +int gifti_add_to_nvpairs(nvpairs *p, const char *name, const char *value) +{ int index; if (!p || !name || !value) { @@ -1207,7 +1250,8 @@ int gifti_add_to_nvpairs(nvpairs *p, const char *name, const char *value) { if (!p->name || !p->value) { fprintf(stderr, "** GATN: failed to realloc %d pointers\n", p->length); return 1; - } else if (G.verb > 3) + } + else if (G.verb > 3) fprintf(stderr, "++ add_nvp [%d]: '%s', '%s'\n", p->length, name ? name : "NULL", value ? value : "NULL"); index = p->length - 1; @@ -1225,7 +1269,8 @@ int gifti_add_to_nvpairs(nvpairs *p, const char *name, const char *value) { /*---------------------------------------------------------------------- *! display the contents of the nvpairs struct */ /*-------------------------------------------------------------------*/ -int gifti_disp_nvpairs(const char *mesg, const nvpairs *p) { +int gifti_disp_nvpairs(const char *mesg, const nvpairs *p) +{ int c; if (mesg) { @@ -1250,7 +1295,8 @@ int gifti_disp_nvpairs(const char *mesg, const nvpairs *p) { /*---------------------------------------------------------------------- *! display the contents of the LabelTable struct */ /*-------------------------------------------------------------------*/ -int gifti_disp_LabelTable(const char *mesg, const giiLabelTable *p) { +int gifti_disp_LabelTable(const char *mesg, const giiLabelTable *p) +{ float *rgba; int c; @@ -1284,7 +1330,8 @@ int gifti_disp_LabelTable(const char *mesg, const giiLabelTable *p) { /*---------------------------------------------------------------------- *! display the contents of the CoordSystem struct */ /*-------------------------------------------------------------------*/ -int gifti_disp_CoordSystem(const char *mesg, const giiCoordSystem *p) { +int gifti_disp_CoordSystem(const char *mesg, const giiCoordSystem *p) +{ int c1, c2; if (mesg) { @@ -1317,7 +1364,8 @@ int gifti_disp_CoordSystem(const char *mesg, const giiCoordSystem *p) { * * if 'subs' is set, display the contents of the sub-structures */ /*-------------------------------------------------------------------*/ -int gifti_disp_DataArray(const char *mesg, const giiDataArray *p, int subs) { +int gifti_disp_DataArray(const char *mesg, const giiDataArray *p, int subs) +{ int c; fprintf(stderr, "--------------------------------------------------\n"); @@ -1388,7 +1436,8 @@ int gifti_disp_DataArray(const char *mesg, const giiDataArray *p, int subs) { * if 'subs' is set, display the contents of the sub-structures, such * as all of the DataArray elements */ /*-------------------------------------------------------------------*/ -int gifti_disp_gifti_image(const char *mesg, const gifti_image *p, int subs) { +int gifti_disp_gifti_image(const char *mesg, const gifti_image *p, int subs) +{ fprintf(stderr, "==================================================\n"); if (mesg) { @@ -1441,7 +1490,8 @@ int gifti_disp_gifti_image(const char *mesg, const gifti_image *p, int subs) { * if in_mb is set, return the (rounded) number of megabytes * (i.e. 17 is 17 MB) */ /*-------------------------------------------------------------------*/ -long long gifti_gim_DA_size(const gifti_image *p, int in_mb) { +long long gifti_gim_DA_size(const gifti_image *p, int in_mb) +{ long long bytes = 0; int c; @@ -1470,7 +1520,8 @@ long long gifti_gim_DA_size(const gifti_image *p, int in_mb) { * * nbyper and swapsize are filled only if the pointers are set */ /*-------------------------------------------------------------------*/ -int gifti_datatype_sizes(int datatype, int *nbyper, int *swapsize) { +int gifti_datatype_sizes(int datatype, int *nbyper, int *swapsize) +{ int c; for (c = sizeof(gifti_type_list) / sizeof(gifti_type_ele) - 1; c > 0; c--) @@ -1490,7 +1541,8 @@ int gifti_datatype_sizes(int datatype, int *nbyper, int *swapsize) { /*---------------------------------------------------------------------- *! compute the total number of data values in a DataArray element */ /*-------------------------------------------------------------------*/ -long long gifti_darray_nvals(const giiDataArray *da) { +long long gifti_darray_nvals(const giiDataArray *da) +{ long long ndim = 1; int c; @@ -1517,7 +1569,8 @@ long long gifti_darray_nvals(const giiDataArray *da) { /*---------------------------------------------------------------------- *! find giiDataArray element #index of the given intent */ /*-------------------------------------------------------------------*/ -giiDataArray *gifti_find_DA(gifti_image *gim, int intent, int index) { +giiDataArray *gifti_find_DA(gifti_image *gim, int intent, int index) +{ int c, nfound; if (!gim || !gifti_intent_is_valid(intent) || index < 0) { @@ -1541,7 +1594,8 @@ giiDataArray *gifti_find_DA(gifti_image *gim, int intent, int index) { * * 'list' should be freed or taken */ /*-------------------------------------------------------------------*/ -int gifti_find_DA_list(gifti_image *gim, int intent, giiDataArray ***list, int *len) { +int gifti_find_DA_list(gifti_image *gim, int intent, giiDataArray ***list, int *len) +{ int c, nfound; if (!gim || !gifti_intent_is_valid(intent) || !list || !len) { @@ -1590,7 +1644,8 @@ int gifti_find_DA_list(gifti_image *gim, int intent, giiDataArray ***list, int * * * no allocation is done here */ /*-------------------------------------------------------------------*/ -char *gifti_get_meta_value(const nvpairs *nvp, const char *name) { +char *gifti_get_meta_value(const nvpairs *nvp, const char *name) +{ int c; if (!nvp || !name) { @@ -1621,7 +1676,8 @@ char *gifti_get_meta_value(const nvpairs *nvp, const char *name) { * define rows to be the number of nodes, which should be the slowest * changing element, depending on the index order (kuru kuru pa) */ /*-------------------------------------------------------------------*/ -int gifti_DA_rows_cols(giiDataArray *da, long long *rows, long long *cols) { +int gifti_DA_rows_cols(giiDataArray *da, long long *rows, long long *cols) +{ *rows = da->dims[0]; /* init */ *cols = 1; @@ -1631,7 +1687,8 @@ int gifti_DA_rows_cols(giiDataArray *da, long long *rows, long long *cols) { /* treat Dim[0] as nodes (they change most slowly) */ *rows = da->dims[0]; *cols = (*rows) ? da->nvals / *rows : 1; /* be safe */ - } else { + } + else { if (!gifti_valid_num_dim(da->num_dim, 1)) { fprintf(stderr, "** cannot assign DA_rows_cols"); return 1; @@ -1647,7 +1704,8 @@ int gifti_DA_rows_cols(giiDataArray *da, long long *rows, long long *cols) { /*---------------------------------------------------------------------- *! print the gifti library history string */ /*-------------------------------------------------------------------*/ -void gifti_disp_lib_hist(void) { +void gifti_disp_lib_hist(void) +{ int c, len = sizeof(gifti_history) / sizeof(char *); for (c = 0; c < len; c++) fputs(gifti_history[c], stdout); } @@ -1665,7 +1723,8 @@ char *gifticlib_version(void) { return gifti_version; } /*---------------------------------------------------------------------- *! print the gifti DTD URL */ /*-------------------------------------------------------------------*/ -void gifti_disp_dtd_url(void) { +void gifti_disp_dtd_url(void) +{ printf("The GIFTI Document Type Definition (DTD) is at:\n %s\n", GIFTI_XML_DTD_SOURCE); } @@ -1675,7 +1734,8 @@ void gifti_disp_dtd_url(void) { * if mesg is set, print the message first * if fp is not set, print to stdout */ /*-------------------------------------------------------------------*/ -int gifti_disp_hex_data(const char *mesg, const void *data, int len, FILE *fp) { +int gifti_disp_hex_data(const char *mesg, const void *data, int len, FILE *fp) +{ const char *dp = (const char *)data; FILE *stream; int c; @@ -1694,7 +1754,8 @@ int gifti_disp_hex_data(const char *mesg, const void *data, int len, FILE *fp) { /*---------------------------------------------------------------------- *! swap sets of 2-byte values */ /*-------------------------------------------------------------------*/ -int gifti_swap_2bytes(void *data, long long nsets) { +int gifti_swap_2bytes(void *data, long long nsets) +{ char *cp1 = (char *)data, *cp2; char tval; long long c; @@ -1713,7 +1774,8 @@ int gifti_swap_2bytes(void *data, long long nsets) { /*---------------------------------------------------------------------- *! swap sets of 4-byte values */ /*-------------------------------------------------------------------*/ -int gifti_swap_4bytes(void *data, long long nsets) { +int gifti_swap_4bytes(void *data, long long nsets) +{ char *cp0 = (char *)data, *cp1, *cp2; char tval; long long c; @@ -1742,7 +1804,8 @@ int gifti_swap_4bytes(void *data, long long nsets) { * if N = 2 or N = 4: call explicit function for that size (speed) * else : swap in a loop */ /*-------------------------------------------------------------------*/ -int gifti_swap_Nbytes(void *data, long long nsets, int swapsize) { +int gifti_swap_Nbytes(void *data, long long nsets, int swapsize) +{ char *cp0, *cp1, *cp2; char tval; long long c; @@ -1783,7 +1846,8 @@ int gifti_swap_Nbytes(void *data, long long nsets, int swapsize) { /*---------------------------------------------------------------------- *! return the current CPU endian: GIFTI_ENDIAN_BIG or _LITTLE */ /*-------------------------------------------------------------------*/ -int gifti_get_this_endian(void) { +int gifti_get_this_endian(void) +{ int one = 1; char *cp = (char *)&one; @@ -1797,11 +1861,13 @@ int gifti_get_this_endian(void) { * * return whether bytes were swapped */ /*-------------------------------------------------------------------*/ -int gifti_check_swap(void *data, int endian, long long nsets, int swapsize) { +int gifti_check_swap(void *data, int endian, long long nsets, int swapsize) +{ if (!data || nsets < 0 || swapsize < 0) { fprintf(stderr, "** check_swap: bad params (%p,%lld, %d)\n", (void *)data, nsets, swapsize); return 0; - } else if (endian <= GIFTI_ENDIAN_UNDEF || endian > GIFTI_ENDIAN_MAX) { + } + else if (endian <= GIFTI_ENDIAN_UNDEF || endian > GIFTI_ENDIAN_MAX) { fprintf(stderr, "** check_swap: invalid endian %d\n", endian); return 0; } @@ -1826,7 +1892,8 @@ int gifti_check_swap(void *data, int endian, long long nsets, int swapsize) { * * return 0 on success */ /*-------------------------------------------------------------------*/ -int gifti_read_extern_DA_data(giiDataArray *da) { +int gifti_read_extern_DA_data(giiDataArray *da) +{ FILE *fp; long long nbytes, nread; @@ -1837,10 +1904,12 @@ int gifti_read_extern_DA_data(giiDataArray *da) { if (da->ext_offset < 0) { fprintf(stderr, "** want external DA data with bad offset %lld\n", da->ext_offset); return 1; - } else if (da->data) { + } + else if (da->data) { fprintf(stderr, "** want external DA data but data already allocated\n"); return 1; - } else if (!gifti_valid_dims(da, 1)) { + } + else if (!gifti_valid_dims(da, 1)) { fprintf(stderr, "** cannot read external DA data with bad dims...\n"); return 1; } @@ -1887,7 +1956,8 @@ int gifti_read_extern_DA_data(giiDataArray *da) { * * return 0 on success */ /*-------------------------------------------------------------------*/ -int gifti_write_extern_DA_data(giiDataArray *da) { +int gifti_write_extern_DA_data(giiDataArray *da) +{ FILE *fp; long long nbytes, nwritten, posn; @@ -1898,10 +1968,12 @@ int gifti_write_extern_DA_data(giiDataArray *da) { if (da->ext_offset < 0) { fprintf(stderr, "** bad offset for external DA data write, %lld\n", da->ext_offset); return 1; - } else if (!da->data) { + } + else if (!da->data) { fprintf(stderr, "** no data for external DA data write\n"); return 1; - } else if (!gifti_valid_dims(da, 1)) { + } + else if (!gifti_valid_dims(da, 1)) { fprintf(stderr, "** cannot write external DA data with bad dims...\n"); return 1; } @@ -1955,7 +2027,8 @@ int gifti_write_extern_DA_data(giiDataArray *da) { * * return 0 on success */ /*-------------------------------------------------------------------*/ -int gifti_set_extern_filelist(gifti_image *gim, int nfiles, char **files) { +int gifti_set_extern_filelist(gifti_image *gim, int nfiles, char **files) +{ giiDataArray *da; long long nbytes, offset; int nper; @@ -2028,7 +2101,8 @@ int gifti_set_extern_filelist(gifti_image *gim, int nfiles, char **files) { * * return 0 on failure (NIFTI_INTENT_NONE) */ /*-------------------------------------------------------------------*/ -int gifti_intent_from_string(const char *name) { +int gifti_intent_from_string(const char *name) +{ int tablen = sizeof(gifti_intent_list) / sizeof(gifti_intent_ele); int c; @@ -2045,7 +2119,8 @@ int gifti_intent_from_string(const char *name) { * corresponding macro label as a string. The dtype code is the * macro value defined in nifti1.h. */ /*-------------------------------------------------------------------*/ -char *gifti_intent_to_string(int code) { +char *gifti_intent_to_string(int code) +{ int tablen = sizeof(gifti_intent_list) / sizeof(gifti_intent_ele); int c; @@ -2058,7 +2133,8 @@ char *gifti_intent_to_string(int code) { /*---------------------------------------------------------------------*/ /*! Return whether the given code is a valid NIFTI_INTENT code. */ /*-------------------------------------------------------------------*/ -int gifti_intent_is_valid(int code) { +int gifti_intent_is_valid(int code) +{ int tablen = sizeof(gifti_intent_list) / sizeof(gifti_intent_ele); int c; @@ -2071,7 +2147,8 @@ int gifti_intent_is_valid(int code) { /*---------------------------------------------------------------------*/ /*! duplicate the given string */ /*-------------------------------------------------------------------*/ -char *gifti_strdup(const char *src) { +char *gifti_strdup(const char *src) +{ char *newstr; int len; @@ -2101,7 +2178,8 @@ char *gifti_strdup(const char *src) { * * return the address of the newly allocated structure */ /*-------------------------------------------------------------------*/ -giiDataArray *gifti_copy_DataArray(const giiDataArray *orig, int get_data) { +giiDataArray *gifti_copy_DataArray(const giiDataArray *orig, int get_data) +{ giiDataArray *gnew; int c; @@ -2129,7 +2207,8 @@ giiDataArray *gifti_copy_DataArray(const giiDataArray *orig, int get_data) { if (!gnew->coordsys) { fprintf(stderr, "** copy_DA: failed to alloc %d CS pointers\n", gnew->numCS); gnew->numCS = 0; - } else + } + else for (c = 0; c < gnew->numCS; c++) gnew->coordsys[c] = gifti_copy_CoordSystem(orig->coordsys[c]); } @@ -2140,7 +2219,8 @@ giiDataArray *gifti_copy_DataArray(const giiDataArray *orig, int get_data) { if (!gnew->data) /* continue? */ fprintf(stderr, "** copy DA, failed to alloc %lld bytes for data\n", gnew->nvals * gnew->nbyper); memcpy(gnew->data, orig->data, gnew->nvals * gnew->nbyper); - } else + } + else gnew->data = NULL; /* last and certainly least, ex_atrs */ @@ -2152,7 +2232,8 @@ giiDataArray *gifti_copy_DataArray(const giiDataArray *orig, int get_data) { /*---------------------------------------------------------------------*/ /*! dupliate the giiCoordSystem struct (passing NULL is okay) */ /*-------------------------------------------------------------------*/ -giiCoordSystem *gifti_copy_CoordSystem(const giiCoordSystem *src) { +giiCoordSystem *gifti_copy_CoordSystem(const giiCoordSystem *src) +{ giiCoordSystem *csnew; int r, c; @@ -2178,7 +2259,8 @@ giiCoordSystem *gifti_copy_CoordSystem(const giiCoordSystem *src) { /*---------------------------------------------------------------------*/ /*! dupliate the contents of the giiLabelTable struct */ /*-------------------------------------------------------------------*/ -int gifti_copy_LabelTable(giiLabelTable *dest, const giiLabelTable *src) { +int gifti_copy_LabelTable(giiLabelTable *dest, const giiLabelTable *src) +{ int c; if (!src || !dest) { @@ -2222,7 +2304,8 @@ int gifti_copy_LabelTable(giiLabelTable *dest, const giiLabelTable *src) { * * return 0 on success */ /*-------------------------------------------------------------------*/ -int gifti_copy_nvpairs(nvpairs *dest, const nvpairs *src) { +int gifti_copy_nvpairs(nvpairs *dest, const nvpairs *src) +{ if (!dest || !src) { fprintf(stderr, "** copy_NVP, bad params (%p,%p)\n", (void *)dest, (void *)src); return 1; @@ -2248,7 +2331,8 @@ int gifti_copy_nvpairs(nvpairs *dest, const nvpairs *src) { /*---------------------------------------------------------------------*/ /*! dupliate the list of strings */ /*-------------------------------------------------------------------*/ -char **gifti_copy_char_list(char **list, int len) { +char **gifti_copy_char_list(char **list, int len) +{ char **newlist = NULL; int c; @@ -2271,7 +2355,8 @@ char **gifti_copy_char_list(char **list, int len) { * * return 0 on success, 1 on failure to find, -1 on error */ /*-------------------------------------------------------------------*/ -int gifti_copy_gifti_meta(gifti_image *dest, gifti_image *src, const char *name) { +int gifti_copy_gifti_meta(gifti_image *dest, gifti_image *src, const char *name) +{ char *value; if (!dest || !src || !name) { @@ -2294,7 +2379,8 @@ int gifti_copy_gifti_meta(gifti_image *dest, gifti_image *src, const char *name) * * return 0 on success, 1 on failure to find, -1 on error */ /*-------------------------------------------------------------------*/ -int gifti_copy_DA_meta_many(gifti_image *dest, gifti_image *src, const char *name, const int *dalist, int len) { +int gifti_copy_DA_meta_many(gifti_image *dest, gifti_image *src, const char *name, const int *dalist, int len) +{ int c, index, use_list, numDA, rv = 0; if (!dest || !dest->darray || !src || !src->darray || !name) { @@ -2337,7 +2423,8 @@ int gifti_copy_DA_meta_many(gifti_image *dest, gifti_image *src, const char *nam * * return 0 on success, 1 on failure to find, -1 on error */ /*-------------------------------------------------------------------*/ -int gifti_copy_DA_meta(giiDataArray *dest, giiDataArray *src, const char *name) { +int gifti_copy_DA_meta(giiDataArray *dest, giiDataArray *src, const char *name) +{ char *value; if (!dest || !src || !name) { @@ -2359,7 +2446,8 @@ int gifti_copy_DA_meta(giiDataArray *dest, giiDataArray *src, const char *name) * * return 0 on success, 1 on failure to find, -1 on error */ /*-------------------------------------------------------------------*/ -int gifti_copy_all_DA_meta(giiDataArray *dest, giiDataArray *src) { +int gifti_copy_all_DA_meta(giiDataArray *dest, giiDataArray *src) +{ int c, rv = 0; if (!dest || !src) { @@ -2379,7 +2467,8 @@ int gifti_copy_all_DA_meta(giiDataArray *dest, giiDataArray *src) { * * return 0 if they are the same, 1 if they differ */ /*-------------------------------------------------------------------*/ -int gifti_compare_gifti_images(const gifti_image *g1, const gifti_image *g2, int comp_data, int verb) { +int gifti_compare_gifti_images(const gifti_image *g1, const gifti_image *g2, int comp_data, int verb) +{ int diffs = 0, data_diffs = 0, gdiffs = 0, c, rv, numDA; int lverb = verb; /* possibly override passed 'verb' */ @@ -2434,7 +2523,8 @@ int gifti_compare_gifti_images(const gifti_image *g1, const gifti_image *g2, int * * return 0 if they are the same, 1 if they differ */ /*-------------------------------------------------------------------*/ -int gifti_compare_gifti_data(const gifti_image *g1, const gifti_image *g2, int verb) { +int gifti_compare_gifti_data(const gifti_image *g1, const gifti_image *g2, int verb) +{ int lverb = verb, c, diffs = 0, numDA; if (G.verb > lverb) lverb = G.verb; @@ -2471,7 +2561,8 @@ int gifti_compare_gifti_data(const gifti_image *g1, const gifti_image *g2, int v return 0; } -int gifti_compare_DA_data(const giiDataArray *d1, const giiDataArray *d2, int verb) { +int gifti_compare_DA_data(const giiDataArray *d1, const giiDataArray *d2, int verb) +{ long long nbytes, offset; if (!d1 || !d2) { @@ -2505,7 +2596,8 @@ int gifti_compare_DA_data(const giiDataArray *d1, const giiDataArray *d2, int ve /* compare everything but darray * (for diffs, only print if verb > 1) */ -int gifti_compare_gims_only(const gifti_image *g1, const gifti_image *g2, int verb) { +int gifti_compare_gims_only(const gifti_image *g1, const gifti_image *g2, int verb) +{ int diffs = 0; int lverb = verb; /* possibly override passed 'verb' */ @@ -2530,7 +2622,8 @@ int gifti_compare_gims_only(const gifti_image *g1, const gifti_image *g2, int ve if (lverb <= 1) return 1; } /* else both NULL, which means equal */ - } else if (strcmp(g1->version, g2->version)) { + } + else if (strcmp(g1->version, g2->version)) { diffs++; if (lverb > 1) fprintf(stderr, "-- diff in GIFTI version: %s vs. %s\n", g1->version, g2->version); if (lverb <= 1) return 1; @@ -2570,7 +2663,8 @@ int gifti_compare_gims_only(const gifti_image *g1, const gifti_image *g2, int ve } /*! return 0 if equal, 1 if diffs, 2 if data diffs (and 3 if both diffs) */ -int gifti_compare_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int comp_data, int verb) { +int gifti_compare_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int comp_data, int verb) +{ long long offset; int c, top, diffs = 0, data_diffs = 0; int lverb = verb; /* possibly override passed 'verb' */ @@ -2746,7 +2840,8 @@ int gifti_compare_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int co * * return 1 if they are approximately the same, 0 if otherwise */ /*-------------------------------------------------------------------*/ -int gifti_approx_gifti_images(const gifti_image *g1, const gifti_image *g2, int comp_data, int verb) { +int gifti_approx_gifti_images(const gifti_image *g1, const gifti_image *g2, int comp_data, int verb) +{ int diffs = 0, c, numDA; int lverb = verb; /* possibly override passed 'verb' */ @@ -2802,7 +2897,8 @@ int gifti_approx_gifti_images(const gifti_image *g1, const gifti_image *g2, int * 3 : print all diffs * */ -int gifti_approx_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int comp_data, int verb) { +int gifti_approx_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int comp_data, int verb) +{ int c, top, can_comp, offset, diffs = 0; int lverb = verb; /* possibly override passed 'verb' */ @@ -2812,7 +2908,8 @@ int gifti_approx_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int com if (!d1 && !d2) { if (lverb > 2) printf("-- approx DA: have NULL\n"); return 1; /* yes, these are equal */ - } else if (!d1 || !d2) { + } + else if (!d1 || !d2) { if (lverb > 2) printf("-- approx DA: have one NULL\n"); return 0; /* not approximately equal */ } @@ -2861,7 +2958,8 @@ int gifti_approx_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int com if (lverb > 1) printf("-- approx DA: triange diff at offset %d\n", offset); if (lverb < 3) return 0; } - } else { + } + else { offset = gifti_approx_diff_offset(d1->data, d2->data, d1->nvals, d1->datatype, 1.0); if (offset >= 0) { diffs |= 2; @@ -2877,7 +2975,8 @@ int gifti_approx_DA_pair(const giiDataArray *d1, const giiDataArray *d2, int com * * apply the same verb as above */ -static int can_compare_DA_data(const giiDataArray *d1, const giiDataArray *d2, int verb) { +static int can_compare_DA_data(const giiDataArray *d1, const giiDataArray *d2, int verb) +{ int c, top, rv = 1; int lverb = verb; /* possibly override passed 'verb' */ @@ -2958,7 +3057,8 @@ static int can_compare_DA_data(const giiDataArray *d1, const giiDataArray *d2, i * * only state diffs in the verb=3 case */ /*-------------------------------------------------------------------*/ -int gifti_compare_nvpairs(const nvpairs *p1, const nvpairs *p2, int verb) { +int gifti_compare_nvpairs(const nvpairs *p1, const nvpairs *p2, int verb) +{ char *value; int lverb = verb; /* possibly override passed verb */ int c, diffs = 0; @@ -2992,7 +3092,8 @@ int gifti_compare_nvpairs(const nvpairs *p1, const nvpairs *p2, int verb) { if (!value) { if (lverb > 2) printf("-- nvp list 2 missing Name: '%s'\n", p1->name[c]); diffs++; - } else if (strcmp(value, p1->value[c])) { + } + else if (strcmp(value, p1->value[c])) { if (lverb > 2) printf("-- nvp diff for Name '%s':\n '%s' vs. '%s'\n", p1->name[c], p1->value[c], value); diffs++; } @@ -3020,7 +3121,8 @@ int gifti_compare_nvpairs(const nvpairs *p1, const nvpairs *p2, int verb) { * * only state diffs in the verb=3 case */ /*-------------------------------------------------------------------*/ -int gifti_compare_labeltable(const giiLabelTable *t1, const giiLabelTable *t2, int verb) { +int gifti_compare_labeltable(const giiLabelTable *t1, const giiLabelTable *t2, int verb) +{ return compare_labeltables(t1, t2, verb, 0); } @@ -3031,7 +3133,8 @@ int gifti_compare_labeltable(const giiLabelTable *t1, const giiLabelTable *t2, i * * only state diffs in the verb=3 case */ /*-------------------------------------------------------------------*/ -int gifti_approx_labeltables(const giiLabelTable *t1, const giiLabelTable *t2, int verb) { +int gifti_approx_labeltables(const giiLabelTable *t1, const giiLabelTable *t2, int verb) +{ return (!compare_labeltables(t1, t2, verb, 1)); } @@ -3042,7 +3145,8 @@ int gifti_approx_labeltables(const giiLabelTable *t1, const giiLabelTable *t2, i * * if approx, compare RBGA approximately */ /*-------------------------------------------------------------------*/ -static int compare_labeltables(const giiLabelTable *t1, const giiLabelTable *t2, int verb, int approx) { +static int compare_labeltables(const giiLabelTable *t1, const giiLabelTable *t2, int verb, int approx) +{ int lverb = verb; /* possibly override passed verb */ int c, offset, diffs = 0; // int roff = 0; @@ -3109,7 +3213,8 @@ static int compare_labeltables(const giiLabelTable *t1, const giiLabelTable *t2, * 0: if both pointers are NULL * 1: if exactly one is NULL */ /*-------------------------------------------------------------------*/ -int gifti_strdiff(const char *s1, const char *s2) { +int gifti_strdiff(const char *s1, const char *s2) +{ if (!s1 || !s2) { if (s1 || s2) return 1; /* one NULL means different */ @@ -3125,7 +3230,8 @@ int gifti_strdiff(const char *s1, const char *s2) { * * only state diffs in the verb=3 case */ /*-------------------------------------------------------------------*/ -int gifti_compare_coordsys(const giiCoordSystem *s1, const giiCoordSystem *s2, int comp_data, int verb) { +int gifti_compare_coordsys(const giiCoordSystem *s1, const giiCoordSystem *s2, int comp_data, int verb) +{ long long offset; int lverb = verb; /* possibly override passed verb */ int diffs = 0; @@ -3144,7 +3250,8 @@ int gifti_compare_coordsys(const giiCoordSystem *s1, const giiCoordSystem *s2, i if (lverb < 3) return 1; diffs++; } - } else if (strcmp(s1->dataspace, s2->dataspace)) { + } + else if (strcmp(s1->dataspace, s2->dataspace)) { if (lverb > 2) printf("-- coordsys dspace diff: %s vs. %s\n", s1->dataspace, s2->dataspace); if (lverb < 3) return 1; diffs++; @@ -3156,7 +3263,8 @@ int gifti_compare_coordsys(const giiCoordSystem *s1, const giiCoordSystem *s2, i if (lverb < 3) return 1; diffs++; } - } else if (strcmp(s1->xformspace, s2->xformspace)) { + } + else if (strcmp(s1->xformspace, s2->xformspace)) { if (lverb > 2) printf("-- coordsys xformspace diff: %s vs. %s\n", s1->xformspace, s2->xformspace); if (lverb < 3) return 1; diffs++; @@ -3181,7 +3289,8 @@ int gifti_compare_coordsys(const giiCoordSystem *s1, const giiCoordSystem *s2, i * * return byte position of difference, so that < 0 means no difference */ /*-------------------------------------------------------------------*/ -long long gifti_compare_raw_data(const void *p1, const void *p2, long long length) { +long long gifti_compare_raw_data(const void *p1, const void *p2, long long length) +{ long long posn; char *d1 = (char *)p1, *d2 = (char *)p2; @@ -3228,7 +3337,8 @@ long long gifti_compare_raw_data(const void *p1, const void *p2, long long lengt * * (return -1 if the pointers differ in whether they are set) */ /*-------------------------------------------------------------------*/ -long long gifti_approx_diff_offset(const void *p1, const void *p2, long long length, int ni_type, double limit) { +long long gifti_approx_diff_offset(const void *p1, const void *p2, long long length, int ni_type, double limit) +{ long long posn; double llim = limit; /* local limit (passed limit or default) */ @@ -3359,7 +3469,8 @@ long long gifti_approx_diff_offset(const void *p1, const void *p2, long long len * * require consistent wrapping, but allow for varying first vertex */ /*-------------------------------------------------------------------*/ -int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_type) { +int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_type) +{ int posn = -1; /* if either pointer is not set, we're out of here */ @@ -3376,9 +3487,11 @@ int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_ for (posn = 0; posn < ntri; posn++, d1 += 3, d2 += 3) { if (*d1 == *d2) { /* same first index */ if (d1[1] != d2[1] || d1[2] != d2[2]) break; - } else if (d1[0] == d2[1]) { /* index off by 1 */ + } + else if (d1[0] == d2[1]) { /* index off by 1 */ if (d1[1] != d2[2] || d1[2] != d2[0]) break; - } else if (d1[0] == d2[2]) { /* index off by 2 */ + } + else if (d1[0] == d2[2]) { /* index off by 2 */ if (d1[1] != d2[0] || d1[2] != d2[1]) break; } } @@ -3389,9 +3502,11 @@ int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_ for (posn = 0; posn < ntri; posn++, d1 += 3, d2 += 3) { if (*d1 == *d2) { /* same first index */ if (d1[1] != d2[1] || d1[2] != d2[2]) break; - } else if (d1[0] == d2[1]) { /* index off by 1 */ + } + else if (d1[0] == d2[1]) { /* index off by 1 */ if (d1[1] != d2[2] || d1[2] != d2[0]) break; - } else if (d1[0] == d2[2]) { /* index off by 2 */ + } + else if (d1[0] == d2[2]) { /* index off by 2 */ if (d1[1] != d2[0] || d1[2] != d2[1]) break; } } @@ -3402,9 +3517,11 @@ int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_ for (posn = 0; posn < ntri; posn++, d1 += 3, d2 += 3) { if (*d1 == *d2) { /* same first index */ if (d1[1] != d2[1] || d1[2] != d2[2]) break; - } else if (d1[0] == d2[1]) { /* index off by 1 */ + } + else if (d1[0] == d2[1]) { /* index off by 1 */ if (d1[1] != d2[2] || d1[2] != d2[0]) break; - } else if (d1[0] == d2[2]) { /* index off by 2 */ + } + else if (d1[0] == d2[2]) { /* index off by 2 */ if (d1[1] != d2[0] || d1[2] != d2[1]) break; } } @@ -3415,9 +3532,11 @@ int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_ for (posn = 0; posn < ntri; posn++, d1 += 3, d2 += 3) { if (*d1 == *d2) { /* same first index */ if (d1[1] != d2[1] || d1[2] != d2[2]) break; - } else if (d1[0] == d2[1]) { /* index off by 1 */ + } + else if (d1[0] == d2[1]) { /* index off by 1 */ if (d1[1] != d2[2] || d1[2] != d2[0]) break; - } else if (d1[0] == d2[2]) { /* index off by 2 */ + } + else if (d1[0] == d2[2]) { /* index off by 2 */ if (d1[1] != d2[0] || d1[2] != d2[1]) break; } } @@ -3428,9 +3547,11 @@ int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_ for (posn = 0; posn < ntri; posn++, d1 += 3, d2 += 3) { if (*d1 == *d2) { /* same first index */ if (d1[1] != d2[1] || d1[2] != d2[2]) break; - } else if (d1[0] == d2[1]) { /* index off by 1 */ + } + else if (d1[0] == d2[1]) { /* index off by 1 */ if (d1[1] != d2[2] || d1[2] != d2[0]) break; - } else if (d1[0] == d2[2]) { /* index off by 2 */ + } + else if (d1[0] == d2[2]) { /* index off by 2 */ if (d1[1] != d2[0] || d1[2] != d2[1]) break; } } @@ -3441,9 +3562,11 @@ int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_ for (posn = 0; posn < ntri; posn++, d1 += 3, d2 += 3) { if (*d1 == *d2) { /* same first index */ if (d1[1] != d2[1] || d1[2] != d2[2]) break; - } else if (d1[0] == d2[1]) { /* index off by 1 */ + } + else if (d1[0] == d2[1]) { /* index off by 1 */ if (d1[1] != d2[2] || d1[2] != d2[0]) break; - } else if (d1[0] == d2[2]) { /* index off by 2 */ + } + else if (d1[0] == d2[2]) { /* index off by 2 */ if (d1[1] != d2[0] || d1[2] != d2[1]) break; } } @@ -3465,7 +3588,8 @@ int gifti_triangle_diff_offset(const void *p1, const void *p2, int ntri, int ni_ * * possibly write a trailing newline */ /*-------------------------------------------------------------------*/ -int gifti_disp_raw_data(const void *data, int type, int nvals, int newline, FILE *stream) { +int gifti_disp_raw_data(const void *data, int type, int nvals, int newline, FILE *stream) +{ FILE *fp = stream ? stream : stdout; char *dp, fbuf[64]; int c, size; @@ -3529,7 +3653,8 @@ int gifti_disp_raw_data(const void *data, int type, int nvals, int newline, FILE * return 1 if something was cleared * 0 if not */ /*-------------------------------------------------------------------*/ -int gifti_clear_float_zeros(char *str) { +int gifti_clear_float_zeros(char *str) +{ char *dp, *valp; int len; @@ -3552,7 +3677,8 @@ int gifti_clear_float_zeros(char *str) { /*---------------------------------------------------------------------- *! set all DataArray attributes of the given name to the given value */ /*-------------------------------------------------------------------*/ -int gifti_set_atr_in_DAs(gifti_image *gim, const char *name, const char *value, const int *dalist, int len) { +int gifti_set_atr_in_DAs(gifti_image *gim, const char *name, const char *value, const int *dalist, int len) +{ int c, ind; if (!gim || !name || !value) { @@ -3598,7 +3724,8 @@ int gifti_set_atr_in_DAs(gifti_image *gim, const char *name, const char *value, /*---------------------------------------------------------------------- *! set MetaData name/value pairs in all DAs in list (or all in gim) */ /*-------------------------------------------------------------------*/ -int gifti_set_DA_meta(gifti_image *gim, const char *name, const char *value, const int *dalist, int len, int replace) { +int gifti_set_DA_meta(gifti_image *gim, const char *name, const char *value, const int *dalist, int len, int replace) +{ int c, ind; if (!gim || !name || !value) { @@ -3646,7 +3773,8 @@ int gifti_set_DA_meta(gifti_image *gim, const char *name, const char *value, con * * note that if numDA <= 0, the function returns an empty gifti_image */ /*-------------------------------------------------------------------*/ -gifti_image *gifti_create_image(int numDA, int intent, int dtype, int ndim, const int *dims, int alloc_data) { +gifti_image *gifti_create_image(int numDA, int intent, int dtype, int ndim, const int *dims, int alloc_data) +{ gifti_image *gim; int c, errs = 0; @@ -3721,7 +3849,8 @@ gifti_image *gifti_create_image(int numDA, int intent, int dtype, int ndim, cons * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_alloc_DA_data(gifti_image *gim, const int *dalist, int len) { +int gifti_alloc_DA_data(gifti_image *gim, const int *dalist, int len) +{ giiDataArray *da; long long nbytes, ntot = 0; int c, index, nset = 0, use_list, numDA; @@ -3782,7 +3911,8 @@ int gifti_alloc_DA_data(gifti_image *gim, const int *dalist, int len) { * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_set_dims_all_DA(gifti_image *gim, int ndim, const int *dims) { +int gifti_set_dims_all_DA(gifti_image *gim, int ndim, const int *dims) +{ long long nvals; int c, d, nset = 0; @@ -3826,7 +3956,8 @@ int gifti_set_dims_all_DA(gifti_image *gim, int ndim, const int *dims) { * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_update_nbyper(gifti_image *gim) { +int gifti_update_nbyper(gifti_image *gim) +{ giiDataArray *da; int c, errs = 0; @@ -3849,7 +3980,8 @@ int gifti_update_nbyper(gifti_image *gim) { * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_set_DA_defaults(giiDataArray *da) { +int gifti_set_DA_defaults(giiDataArray *da) +{ int c; if (!da) { @@ -3884,7 +4016,8 @@ int gifti_set_DA_defaults(giiDataArray *da) { /*---------------------------------------------------------------------- *! clear the DataArray element */ /*-------------------------------------------------------------------*/ -int gifti_clear_DataArray(giiDataArray *da) { +int gifti_clear_DataArray(giiDataArray *da) +{ if (!da) { fprintf(stderr, "** NULL in clear_DataArray\n"); return 1; @@ -3910,7 +4043,8 @@ int gifti_clear_DataArray(giiDataArray *da) { * return 0 on success * 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_clear_gifti_image(gifti_image *gim) { +int gifti_clear_gifti_image(gifti_image *gim) +{ if (!gim) { fprintf(stderr, "** NULL in clear_gifti_image\n"); return 1; @@ -3936,7 +4070,8 @@ int gifti_clear_gifti_image(gifti_image *gim) { * * may write faster gxml function for this, if it seems important */ /*-------------------------------------------------------------------*/ -int gifti_read_dset_numDA(const char *fname) { +int gifti_read_dset_numDA(const char *fname) +{ gifti_image *gim; int numDA; @@ -3963,7 +4098,8 @@ int gifti_read_dset_numDA(const char *fname) { /*---------------------------------------------------------------------- *! return whether the list values are from min to max */ /*-------------------------------------------------------------------*/ -int gifti_valid_int_list(const int *list, int len, int min, int max, int whine) { +int gifti_valid_int_list(const int *list, int len, int min, int max, int whine) +{ int c; if (!list || len <= 0) return 0; @@ -3978,16 +4114,19 @@ int gifti_valid_int_list(const int *list, int len, int min, int max, int whine) } /* return whether any DAs in list have data */ -static int DA_data_exists(gifti_image *gim, const int *dalist, int len) { +static int DA_data_exists(gifti_image *gim, const int *dalist, int len) +{ int length, uselist = 0; int c, ind; if (!dalist || len <= 0) { /* then scan all DA elements */ length = gim->numDA; if (length <= 0) return 0; - } else if (!gifti_valid_int_list(dalist, len, 0, gim->numDA - 1, 1)) { + } + else if (!gifti_valid_int_list(dalist, len, 0, gim->numDA - 1, 1)) { return 0; - } else { + } + else { uselist = 1; length = len; } @@ -4007,7 +4146,8 @@ static int DA_data_exists(gifti_image *gim, const int *dalist, int len) { * * return 0 on success, 1 on error */ /*-------------------------------------------------------------------*/ -int gifti_add_to_meta(giiMetaData *md, const char *name, const char *value, int replace) { +int gifti_add_to_meta(giiMetaData *md, const char *name, const char *value, int replace) +{ int c; if (!md || !name || !value) return 1; @@ -4033,7 +4173,8 @@ int gifti_add_to_meta(giiMetaData *md, const char *name, const char *value, int if (md->value[c]) free(md->value[c]); md->value[c] = gifti_strdup(value); return 0; - } else { + } + else { fprintf(stderr, "** G_add_to_meta: name '%s', already exists\n", name); return 1; } @@ -4069,7 +4210,8 @@ int gifti_add_to_meta(giiMetaData *md, const char *name, const char *value, int * * return 1 if valid, 0 otherwise */ /*-------------------------------------------------------------------*/ -int gifti_valid_gifti_image(gifti_image *gim, int whine) { +int gifti_valid_gifti_image(gifti_image *gim, int whine) +{ int c, errs = 0; float gim_version = 0.0f, gifti_xml_version = 0.0f; @@ -4109,7 +4251,8 @@ int gifti_valid_gifti_image(gifti_image *gim, int whine) { if (!gifti_valid_DataArray(gim->darray[c], whine)) { if (G.verb > 3) fprintf(stderr, "-- DA[%d] has errors\n", c); errs++; - } else if (G.verb > 4) + } + else if (G.verb > 4) fprintf(stderr, "-- DA[%d] is VALID\n", c); } @@ -4138,7 +4281,8 @@ int gifti_valid_gifti_image(gifti_image *gim, int whine) { * * return 1 if true, 0 otherwise */ /*-------------------------------------------------------------------*/ -int gifti_image_has_data(const gifti_image *gim) { +int gifti_image_has_data(const gifti_image *gim) +{ int c; if (!gim || !gim->darray || gim->numDA <= 0) return 0; @@ -4161,7 +4305,8 @@ int gifti_image_has_data(const gifti_image *gim) { * * return a pointer to the newly allocated structure */ /*-------------------------------------------------------------------*/ -gifti_image *gifti_copy_gifti_image(const gifti_image *gold, int copy_data) { +gifti_image *gifti_copy_gifti_image(const gifti_image *gold, int copy_data) +{ gifti_image *gnew; int c, errs = 0; /* check for errors at each step */ @@ -4222,7 +4367,8 @@ gifti_image *gifti_copy_gifti_image(const gifti_image *gold, int copy_data) { * if data exists, convert it (free old, allocate new) * else, leave as NULL */ /*-------------------------------------------------------------------*/ -int gifti_convert_to_float(gifti_image *gim) { +int gifti_convert_to_float(gifti_image *gim) +{ giiDataArray *da; void *olddata; int oldtype, newtype = NIFTI_TYPE_FLOAT32; /* for future? */ @@ -4305,7 +4451,8 @@ int gifti_convert_to_float(gifti_image *gim) { } /* copy old data to float array */ -static int copy_data_as_float(void *dest, int dtype, void *src, int stype, long long nvals) { +static int copy_data_as_float(void *dest, int dtype, void *src, int stype, long long nvals) +{ float *dptr = (float *)dest; long long c; diff --git a/utils/gifti_local.c b/utils/gifti_local.c index bbcf9c8fd2c..e111907ad1f 100644 --- a/utils/gifti_local.c +++ b/utils/gifti_local.c @@ -41,7 +41,8 @@ /* * */ -static giiDataArray *gifti_alloc_and_add_darray(gifti_image *image) { +static giiDataArray *gifti_alloc_and_add_darray(gifti_image *image) +{ if (!image) { fprintf(stderr, "** gifti_alloc_and_add_darray: NULL image\n"); return NULL; @@ -62,7 +63,8 @@ static giiDataArray *gifti_alloc_and_add_darray(gifti_image *image) { /* * */ -static double gifti_get_DA_value_2D(giiDataArray *da, int row, int col) { +static double gifti_get_DA_value_2D(giiDataArray *da, int row, int col) +{ int dim0_index, dim1_index; int dims_0 = 0, dims_1 = 0; @@ -82,10 +84,12 @@ static double gifti_get_DA_value_2D(giiDataArray *da, int row, int col) { } dims_0 = da->dims[0]; dims_1 = 1; // 1D data - } else if (da->num_dim != 2) { + } + else if (da->num_dim != 2) { fprintf(stderr, "** gifti_get_DA_value_2D, array dim is %d\n", da->num_dim); exit(1); - } else { + } + else { dims_0 = da->dims[0]; dims_1 = da->dims[1]; } @@ -94,12 +98,14 @@ static double gifti_get_DA_value_2D(giiDataArray *da, int row, int col) { if (GIFTI_IND_ORD_ROW_MAJOR == da->ind_ord) { dim0_index = row; dim1_index = col; - } else if (GIFTI_IND_ORD_COL_MAJOR == da->ind_ord) { + } + else if (GIFTI_IND_ORD_COL_MAJOR == da->ind_ord) { // NJS NOTE: notice that order is treated as row/col, so that the // calling sequence can just assume row major dim0_index = row; // col; dim1_index = col; // row; - } else { + } + else { fprintf(stderr, "** gifti_get_DA_value_2D, unknown ind_ord: %d\n", da->ind_ord); exit(1); } @@ -201,7 +207,8 @@ static double gifti_get_DA_value_2D(giiDataArray *da, int row, int col) { /* * */ -static void gifti_set_DA_value_2D(giiDataArray *da, int row, int col, double value) { +static void gifti_set_DA_value_2D(giiDataArray *da, int row, int col, double value) +{ int dim0_index, dim1_index; int dims_0 = 0, dims_1 = 0; @@ -221,10 +228,12 @@ static void gifti_set_DA_value_2D(giiDataArray *da, int row, int col, double val } dims_0 = da->dims[0]; dims_1 = 1; // 1D data - } else if (da->num_dim != 2) { + } + else if (da->num_dim != 2) { fprintf(stderr, "** gifti_set_DA_value_2D, array dim is %d\n", da->num_dim); exit(1); - } else { + } + else { dims_0 = da->dims[0]; dims_1 = da->dims[1]; } @@ -233,7 +242,8 @@ static void gifti_set_DA_value_2D(giiDataArray *da, int row, int col, double val if (GIFTI_IND_ORD_ROW_MAJOR == da->ind_ord) { dim0_index = row; dim1_index = col; - } else { + } + else { dim0_index = col; dim1_index = row; } @@ -332,7 +342,8 @@ static void gifti_set_DA_value_2D(giiDataArray *da, int row, int col, double val if daNum is not -1, then read only the data in data array number daNum -------------------------------------------------------------------*/ -MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { +MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) +{ /* * attempt to read the file */ @@ -471,7 +482,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { for (numDA = 0; numDA < image->numDA; numDA++) { if (image->darray[numDA]->intent == NIFTI_INTENT_POINTSET) { coords = image->darray[numDA]; - } else if (image->darray[numDA]->intent == NIFTI_INTENT_TRIANGLE) { + } + else if (image->darray[numDA]->intent == NIFTI_INTENT_TRIANGLE) { faces = image->darray[numDA]; } } @@ -486,7 +498,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { if (coords->ind_ord == GIFTI_IND_ORD_ROW_MAJOR) { // RowMajorOrder gifti_DA_rows_cols(coords, &num_vertices, &num_cols); - } else { + } + else { // ColumnMajorOrder gifti_DA_rows_cols(coords, &num_cols, &num_vertices); } @@ -505,7 +518,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { if (faces->ind_ord == GIFTI_IND_ORD_ROW_MAJOR) { // RowMajorOrder gifti_DA_rows_cols(faces, &num_faces, &num_cols); - } else { + } + else { // ColumnMajorOrder gifti_DA_rows_cols(faces, &num_cols, &num_faces); } @@ -538,9 +552,11 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { char *hemi = gifti_get_meta_value(&coords->meta, "AnatomicalStructurePrimary"); if (hemi && (strcmp(hemi, "CortexRight") == 0)) { mris->hemisphere = RIGHT_HEMISPHERE; - } else if (hemi && (strcmp(hemi, "CortexLeft") == 0)) { + } + else if (hemi && (strcmp(hemi, "CortexLeft") == 0)) { mris->hemisphere = LEFT_HEMISPHERE; - } else { + } + else { mris->hemisphere = NO_HEMISPHERE; } @@ -830,18 +846,22 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { // else good to do, so store this node index info node_index = darray; continue; - } else { + } + else { /* Check the number of vertices, so we dont trounce the mris struct */ long long num_vertices = 0; long long num_cols = 0; long long expected_num_cols = 1; if (darray->intent == NIFTI_INTENT_VECTOR) { expected_num_cols = 3; - } else if (darray->intent == NIFTI_INTENT_RGB_VECTOR) { + } + else if (darray->intent == NIFTI_INTENT_RGB_VECTOR) { expected_num_cols = 3; - } else if (darray->intent == NIFTI_INTENT_RGBA_VECTOR) { + } + else if (darray->intent == NIFTI_INTENT_RGBA_VECTOR) { expected_num_cols = 4; - } else if (darray->intent == NIFTI_INTENT_GENMATRIX) { + } + else if (darray->intent == NIFTI_INTENT_GENMATRIX) { expected_num_cols = 9; } gifti_DA_rows_cols(darray, &num_vertices, &num_cols); @@ -871,7 +891,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { "been read! Skipping data in array #%d in file %s\n", numDA, fname); - } else { + } + else { found_curv_data++; if (node_index) // sparse data storage @@ -884,7 +905,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { } mris->vertices[vno].curv = (float)gifti_get_DA_value_2D(darray, nindex, 0); } - } else // regular indexing + } + else // regular indexing { int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -895,7 +917,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { } } } - } else if (darray->intent == NIFTI_INTENT_LABEL) { + } + else if (darray->intent == NIFTI_INTENT_LABEL) { // 'label' data goes into the 'annotation' data element of mris if ((NULL == mris->ct) || (NULL == ct)) // sanity-check { @@ -912,7 +935,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { { vno = gifti_get_DA_value_2D(node_index, nindex, 0); da_index = nindex; - } else // regular indexing + } + else // regular indexing { da_index = vno; } @@ -955,12 +979,14 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { if (++nindex >= num_index_nodes) { break; } - } else // regular indexing + } + else // regular indexing { vno++; } } - } else if (darray->intent == NIFTI_INTENT_VECTOR) { + } + else if (darray->intent == NIFTI_INTENT_VECTOR) { // 'vector' data goes in our 'dx,dy,dz' data element of mris int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -971,7 +997,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { mris->vertices[vno].dy = (float)gifti_get_DA_value_2D(darray, vno, 1); mris->vertices[vno].dz = (float)gifti_get_DA_value_2D(darray, vno, 2); } - } else if ((darray->intent == NIFTI_INTENT_RGB_VECTOR) || (darray->intent == NIFTI_INTENT_RGBA_VECTOR)) { + } + else if ((darray->intent == NIFTI_INTENT_RGB_VECTOR) || (darray->intent == NIFTI_INTENT_RGBA_VECTOR)) { // 'rgba' data goes in our 'annotation' data element of mris int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -986,7 +1013,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { if (red > 1) { r = (int)red; - } else { + } + else { r = (int)floor(red * 256); } if (r > 255) { @@ -994,7 +1022,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { } if (green > 1) { g = (int)green; - } else { + } + else { g = (int)floor(green * 256); } if (g > 255) { @@ -1002,7 +1031,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { } if (blue > 1) { b = (int)blue; - } else { + } + else { b = (int)floor(blue * 256); } if (b > 255) { @@ -1011,12 +1041,14 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { MRISRGBToAnnot(r, g, b, mris->vertices[vno].annotation); } - } else if (darray->intent == NIFTI_INTENT_GENMATRIX) { + } + else if (darray->intent == NIFTI_INTENT_GENMATRIX) { fprintf(stderr, "WARNING: ignoring unsupported data array NIFTI_INTENT_GENMATRIX" " in file %s\n", fname); - } else { + } + else { // 'statistics' and all other kinds of data we'll put in both our // 'stat' and 'val' data elements of the mris structure if (found_statval_data) { @@ -1025,7 +1057,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { "been read! Skipping data in array #%d in file %s\n", numDA, fname); - } else { + } + else { found_statval_data++; if (node_index) // sparse data storage @@ -1039,7 +1072,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { mris->vertices[vno].val = (float)gifti_get_DA_value_2D(darray, nindex, 0); mris->vertices[vno].stat = (float)gifti_get_DA_value_2D(darray, nindex, 0); } - } else // regular indexing + } + else // regular indexing { int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -1062,7 +1096,8 @@ MRIS *mrisReadGIFTIdanum(const char *fname, MRIS *mris, int daNum) { return mris; } -MRI_SURFACE *mrisReadGIFTIfile(const char *fname, MRI_SURFACE *mris) { +MRI_SURFACE *mrisReadGIFTIfile(const char *fname, MRI_SURFACE *mris) +{ // default read routine (read all data arrays) return mrisReadGIFTIdanum(fname, mris, -1); } @@ -1075,7 +1110,8 @@ MRI_SURFACE *mrisReadGIFTIfile(const char *fname, MRI_SURFACE *mris) { This routine will only read NIFTI_INTENT_TIME_SERIES data arrays. -----------------------------------------------------------*/ -MRI *MRISreadGiftiAsMRI(const char *fname, int read_volume) { +MRI *MRISreadGiftiAsMRI(const char *fname, int read_volume) +{ /* Attempt to read the file. */ gifti_image *image = gifti_read_image(fname, 1); if (NULL == image) { @@ -1109,7 +1145,8 @@ MRI *MRISreadGiftiAsMRI(const char *fname, int read_volume) { if (NULL == scalars) { if (++da_num >= image->numDA) { break; - } else { + } + else { continue; } } @@ -1119,7 +1156,8 @@ MRI *MRISreadGiftiAsMRI(const char *fname, int read_volume) { if (num_vertices == -1) { num_vertices = nvertices; num_cols = ncols; - } else { + } + else { if (num_vertices <= 0 || num_vertices != nvertices || ncols != 1) { fprintf(stderr, "MRISreadGiftiAsMRI: malformed time-series data array in file " @@ -1198,7 +1236,8 @@ MRI *MRISreadGiftiAsMRI(const char *fname, int read_volume) { /* * insert username and current date into meta data */ -static void insertCommonMetaData(giiMetaData *md) { +static void insertCommonMetaData(giiMetaData *md) +{ #if 0 #include uuid_t uuid; @@ -1244,7 +1283,8 @@ static void insertCommonMetaData(giiMetaData *md) { if NIFTI_INTENT_LABEL, then write LabelTable and annotations if NIFTI_INTENT_, then write .stats data ------------------------------------------------------------------------*/ -int MRISwriteGIFTI(MRIS *mris, int intent_code, const char *out_fname, const char *curv_fname) { +int MRISwriteGIFTI(MRIS *mris, int intent_code, const char *out_fname, const char *curv_fname) +{ if (NULL == mris || NULL == out_fname) { fprintf(stderr, "MRISwriteGIFTI: invalid parameter\n"); return ERROR_BADPARM; @@ -1669,7 +1709,8 @@ int MRISwriteGIFTI(MRIS *mris, int intent_code, const char *out_fname, const cha if (mris->ct->entries[idx]->name) { // printf("idx=%d, name=%s\n",idx,mris->ct->entries[idx]->name); labeltable.label[idx] = strcpyalloc(mris->ct->entries[idx]->name); - } else { + } + else { char tmpname[30]; sprintf(tmpname, "unknown_%d", idx); printf("idx=%d, name=NULL, assigned as %s (is the colortable correct?)\n", idx, tmpname); @@ -1680,7 +1721,8 @@ int MRISwriteGIFTI(MRIS *mris, int intent_code, const char *out_fname, const cha (0 == strcmp(labeltable.label[idx], "Unknown"))) { // make certain unknown region is completely empty, invisible rgba[0] = rgba[1] = rgba[2] = rgba[3] = 0.0f; - } else { + } + else { rgba[0] = mris->ct->entries[idx]->rf; rgba[1] = mris->ct->entries[idx]->gf; rgba[2] = mris->ct->entries[idx]->bf; @@ -1865,7 +1907,8 @@ int MRISwriteGIFTI(MRIS *mris, int intent_code, const char *out_fname, const cha Description: writes a GIFTI file containing functional or timeseries data -----------------------------------------------------------*/ -int mriWriteGifti(MRI *mri, const char *out_fname) { +int mriWriteGifti(MRI *mri, const char *out_fname) +{ if (NULL == mri || NULL == out_fname) { fprintf(stderr, "mriWriteGifti: invalid input parameters\n"); return ERROR_BADPARM; diff --git a/utils/gifti_test.c b/utils/gifti_test.c index c80e121a796..627004471f9 100644 --- a/utils/gifti_test.c +++ b/utils/gifti_test.c @@ -6,7 +6,8 @@ #include "gifti_test.h" -int show_help() { +int show_help() +{ fprintf(stderr, "------------------------------------------------------------\n" "gifti_test - test reading/writing a GIFTI dataset\n" @@ -47,7 +48,8 @@ int show_help() { return 0; } -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ gifti_image *gim; char *infile = NULL, *gfile = NULL; int *slist = NULL, slen = 0; @@ -73,28 +75,36 @@ int main(int argc, char *argv[]) { fprintf(stderr, "** invalid parm to -encoding: %s\n", argv[ac]); return 1; } - } else if (!strcmp(argv[ac], "-gifti_hist")) { + } + else if (!strcmp(argv[ac], "-gifti_hist")) { gifti_disp_lib_hist(); return 0; - } else if (!strcmp(argv[ac], "-gifti_ver")) { + } + else if (!strcmp(argv[ac], "-gifti_ver")) { gifti_disp_lib_version(); return 0; - } else if (!strcmp(argv[ac], "-gfile")) { + } + else if (!strcmp(argv[ac], "-gfile")) { ac++; CHECK_NEXT_OPT(ac, argc, "-gfile"); gfile = argv[ac]; - } else if (!strcmp(argv[ac], "-help")) { + } + else if (!strcmp(argv[ac], "-help")) { show_help(); return 1; - } else if (!strcmp(argv[ac], "-infile")) { + } + else if (!strcmp(argv[ac], "-infile")) { ac++; CHECK_NEXT_OPT(ac, argc, "-infile"); infile = argv[ac]; - } else if (!strcmp(argv[ac], "-no_data")) { + } + else if (!strcmp(argv[ac], "-no_data")) { data = 0; - } else if (!strcmp(argv[ac], "-show")) { + } + else if (!strcmp(argv[ac], "-show")) { show = 1; - } else if (!strcmp(argv[ac], "-slist")) { + } + else if (!strcmp(argv[ac], "-slist")) { ac++; CHECK_NEXT_OPT(ac, argc, "-slist"); slen = atol(argv[ac]); @@ -120,11 +130,13 @@ int main(int argc, char *argv[]) { return 1; } } - } else if (!strcmp(argv[ac], "-verb")) { + } + else if (!strcmp(argv[ac], "-verb")) { ac++; CHECK_NEXT_OPT(ac, argc, "-verb"); gifti_set_verb(atoi(argv[ac])); - } else { + } + else { fprintf(stderr, "** unknown option: '%s'\n", argv[ac]); return 1; } @@ -165,7 +177,8 @@ int main(int argc, char *argv[]) { return 0; } -int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_suf) { +int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_suf) +{ giiDataArray *da; FILE *fp; char *name = prefix; @@ -190,7 +203,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su fclose(fp); if (nbuf) free(nbuf); return 1; - } else if (gifti_DA_rows_cols(dt, &trows, &tcols)) { + } + else if (gifti_DA_rows_cols(dt, &trows, &tcols)) { fclose(fp); if (nbuf) free(nbuf); return 1; @@ -211,7 +225,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su if (da->ind_ord == GIFTI_IND_ORD_COL_MAJOR) { fprintf(stderr, "-- writing coord rows in reverse order\n"); for (c = rows - 1; c >= 0; c--) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); - } else { + } + else { fprintf(stderr, "-- writing coord rows in normal order\n"); for (c = 0; c < rows; c++) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); } @@ -225,7 +240,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su if (da->ind_ord == GIFTI_IND_ORD_COL_MAJOR) { fprintf(stderr, "-- writing triangle rows in reverse order\n"); for (c = rows - 1; c >= 0; c--) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); - } else { + } + else { fprintf(stderr, "-- writing triangle rows in normal order\n"); for (c = 0; c < rows; c++) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); } @@ -235,7 +251,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su return 0; } -int ewrite_data_line(void *data, int type, int row, int cols, int spaces, int trail0, FILE *fp) { +int ewrite_data_line(void *data, int type, int row, int cols, int spaces, int trail0, FILE *fp) +{ int c; if (!data || row < 0 || cols <= 0 || !fp) return 1; @@ -325,7 +342,8 @@ int ewrite_data_line(void *data, int type, int row, int cols, int spaces, int tr } /* write out as cols by rows (else we'd use ewrite_data_line) */ -int ewrite_many_lines(void **data, int type, long long cols, long long rows, int spaces, FILE *fp) { +int ewrite_many_lines(void **data, int type, long long cols, long long rows, int spaces, FILE *fp) +{ long long r, c; if (!data || rows == 0 || cols == 0 || !fp) return 1; diff --git a/utils/gifti_tool.c b/utils/gifti_tool.c index 80393296f37..c3f1f9b832b 100644 --- a/utils/gifti_tool.c +++ b/utils/gifti_tool.c @@ -41,7 +41,8 @@ static char *g_history[] = { static char g_version[] = "gifti_tool version 1.3, 24 December 2009"; /* globals: verbosity, for now */ -typedef struct { +typedef struct +{ int verb; } gt_globs; gt_globs G = {1}; @@ -59,7 +60,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts); static int show_version(void); /* the main event */ -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ gt_opts opts; int rv = 0; @@ -93,7 +95,8 @@ int main(int argc, char *argv[]) { * 0 : success, continue * -1 : failure, terminate */ -static int process_opts(int argc, char *argv[], gt_opts *opts) { +static int process_opts(int argc, char *argv[], gt_opts *opts) +{ int ac, c; if (argc <= 1) { @@ -106,22 +109,28 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { if (!strcmp(argv[ac], "-help")) { show_help(); return 1; - } else if (!strcmp(argv[ac], "-hist")) { + } + else if (!strcmp(argv[ac], "-hist")) { show_hist(); return 1; - } else if (!strcmp(argv[ac], "-ver")) { + } + else if (!strcmp(argv[ac], "-ver")) { show_version(); return 1; - } else if (!strcmp(argv[ac], "-gifti_dtd_url")) { + } + else if (!strcmp(argv[ac], "-gifti_dtd_url")) { gifti_disp_dtd_url(); return 1; - } else if (!strcmp(argv[ac], "-gifti_hist")) { + } + else if (!strcmp(argv[ac], "-gifti_hist")) { gifti_disp_lib_hist(); return 1; - } else if (!strcmp(argv[ac], "-gifti_ver")) { + } + else if (!strcmp(argv[ac], "-gifti_ver")) { gifti_disp_lib_version(); return 1; - } else if (!strcmp(argv[ac], "-gifti_zlib")) { + } + else if (!strcmp(argv[ac], "-gifti_zlib")) { printf("library compiled %s ZLIB\n", GIFTI_COMP_WITH_ZLIB ? "with" : "without"); return 1; } @@ -138,7 +147,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { else if (!strcmp(argv[ac], "-approx_gifti")) { opts->approx_gifti = 1; opts->gt_compare = 1; - } else if (!strcmp(argv[ac], "-b64_check")) { + } + else if (!strcmp(argv[ac], "-b64_check")) { ac++; CHECK_NEXT_OPT(ac, argc, "-b64_check"); if (!strcmp(argv[ac], "NONE")) @@ -155,33 +165,40 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { fprintf(stderr, "** invalid parm to -b64_check: %s\n", argv[ac]); return -1; } - } else if (!strcmp(argv[ac], "-buf_size")) { + } + else if (!strcmp(argv[ac], "-buf_size")) { ac++; CHECK_NEXT_OPT(ac, argc, "-buf_size"); opts->buf_size = atoi(argv[ac]); /* compare options */ - } else if (!strcmp(argv[ac], "-compare_data")) { + } + else if (!strcmp(argv[ac], "-compare_data")) { opts->comp_data = 1; opts->gt_compare = 1; - } else if (!strcmp(argv[ac], "-compare_gifti")) { + } + else if (!strcmp(argv[ac], "-compare_gifti")) { opts->comp_gifti = 1; opts->gt_compare = 1; - } else if (!strcmp(argv[ac], "-compare_verb")) { + } + else if (!strcmp(argv[ac], "-compare_verb")) { ac++; CHECK_NEXT_OPT(ac, argc, "-compare_verb"); opts->comp_verb = atoi(argv[ac]); /* copy options */ - } else if (!strcmp(argv[ac], "-copy_gifti_meta")) { + } + else if (!strcmp(argv[ac], "-copy_gifti_meta")) { opts->copy_gim_meta = 1; ac++; CHECK_NEXT_OPT(ac, argc, "-copy_gifti_meta"); if (add_to_str_list(&opts->gim_meta, argv[ac])) return -1; - } else if (!strcmp(argv[ac], "-copy_DA_meta")) { + } + else if (!strcmp(argv[ac], "-copy_DA_meta")) { opts->copy_DA_meta = 1; ac++; CHECK_NEXT_OPT(ac, argc, "-copy_DA_meta"); if (add_to_str_list(&opts->DA_meta, argv[ac])) return -1; - } else if (!strcmp(argv[ac], "-DA_index_list")) { + } + else if (!strcmp(argv[ac], "-DA_index_list")) { ac++; for (c = 0; (ac < argc) && (argv[ac][0] != '-'); ac++, c++) if (add_to_int_list(&opts->DAlist, atoi(argv[ac]))) return -1; @@ -192,7 +209,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } /* and back up if we've looked too far */ if (ac < argc && argv[ac][0] == '-') ac--; - } else if (!strcmp(argv[ac], "-encoding")) { + } + else if (!strcmp(argv[ac], "-encoding")) { ac++; CHECK_NEXT_OPT(ac, argc, "-encoding"); if (!strcmp(argv[ac], "ASCII")) @@ -205,13 +223,16 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { fprintf(stderr, "** invalid parm to -encoding: %s\n", argv[ac]); return -1; } - } else if (!strcmp(argv[ac], "-gifti_test")) { + } + else if (!strcmp(argv[ac], "-gifti_test")) { opts->gt_test = 1; - } else if (!strcmp(argv[ac], "-indent")) { + } + else if (!strcmp(argv[ac], "-indent")) { ac++; CHECK_NEXT_OPT(ac, argc, "-indent"); opts->indent = atoi(argv[ac]); - } else if (!strncmp(argv[ac], "-infile", 7)) { /* maybe infiles... */ + } + else if (!strncmp(argv[ac], "-infile", 7)) { /* maybe infiles... */ ac++; for (c = 0; (ac < argc) && (argv[ac][0] != '-'); ac++, c++) if (add_to_str_list(&opts->infiles, argv[ac])) return -1; @@ -222,9 +243,11 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } /* and back up if we've looked too far */ if (ac < argc && argv[ac][0] == '-') ac--; - } else if (!strcmp(argv[ac], "-mod_add_data")) { + } + else if (!strcmp(argv[ac], "-mod_add_data")) { opts->mod_add_data = 1; - } else if (!strcmp(argv[ac], "-mod_DA_atr")) { + } + else if (!strcmp(argv[ac], "-mod_DA_atr")) { opts->mod_DA_atr = 1; ac++; if (ac > argc - 2 || argv[ac][0] == '-' || argv[ac + 1][0] == '-') { @@ -233,7 +256,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } if (add_to_str_list(&opts->DA_atrs, argv[ac]) || add_to_str_list(&opts->DA_atrs, argv[ac + 1])) return -1; ac++; /* and consume last arg */ - } else if (!strcmp(argv[ac], "-mod_DA_meta")) { + } + else if (!strcmp(argv[ac], "-mod_DA_meta")) { opts->mod_DA_meta = 1; ac++; if (ac > argc - 2 || argv[ac][0] == '-' || argv[ac + 1][0] == '-') { @@ -242,7 +266,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } if (add_to_str_list(&opts->DA_meta, argv[ac]) || add_to_str_list(&opts->DA_meta, argv[ac + 1])) return -1; ac++; /* and consume last arg */ - } else if (!strcmp(argv[ac], "-mod_DAs")) { + } + else if (!strcmp(argv[ac], "-mod_DAs")) { ac++; for (c = 0; (ac < argc) && (argv[ac][0] != '-'); ac++, c++) if (add_to_int_list(&opts->DAmodlist, atoi(argv[ac]))) return -1; @@ -253,7 +278,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } /* and back up if we've looked too far */ if (ac < argc && argv[ac][0] == '-') ac--; - } else if (!strcmp(argv[ac], "-mod_gim_atr")) { + } + else if (!strcmp(argv[ac], "-mod_gim_atr")) { opts->mod_gim_atr = 1; ac++; if (ac > argc - 2 || argv[ac][0] == '-' || argv[ac + 1][0] == '-') { @@ -262,7 +288,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } if (add_to_str_list(&opts->gim_atrs, argv[ac]) || add_to_str_list(&opts->gim_atrs, argv[ac + 1])) return -1; ac++; /* and consume last arg */ - } else if (!strcmp(argv[ac], "-mod_gim_meta")) { + } + else if (!strcmp(argv[ac], "-mod_gim_meta")) { opts->mod_gim_meta = 1; ac++; if (ac > argc - 2 || argv[ac][0] == '-' || argv[ac + 1][0] == '-') { @@ -271,15 +298,19 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } if (add_to_str_list(&opts->gim_meta, argv[ac]) || add_to_str_list(&opts->gim_meta, argv[ac + 1])) return -1; ac++; /* and consume last arg */ - } else if (!strcmp(argv[ac], "-mod_to_float")) { + } + else if (!strcmp(argv[ac], "-mod_to_float")) { opts->mod_to_float = 1; - } else if (!strcmp(argv[ac], "-new_dset")) { + } + else if (!strcmp(argv[ac], "-new_dset")) { if (add_to_str_list(&opts->infiles, "MAKE_IM")) return -1; - } else if (!strcmp(argv[ac], "-new_numDA")) { + } + else if (!strcmp(argv[ac], "-new_numDA")) { ac++; CHECK_NEXT_OPT(ac, argc, "-new_numDA"); opts->new_numDA = atol(argv[ac]); - } else if (!strcmp(argv[ac], "-new_intent")) { + } + else if (!strcmp(argv[ac], "-new_intent")) { ac++; CHECK_NEXT_OPT(ac, argc, "-new_intent"); opts->new_intent = gifti_intent_from_string(argv[ac]); @@ -287,7 +318,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { fprintf(stderr, "** invalid intent '%s'\n", argv[ac]); return -1; } - } else if (!strcmp(argv[ac], "-new_dtype")) { + } + else if (!strcmp(argv[ac], "-new_dtype")) { ac++; CHECK_NEXT_OPT(ac, argc, "-new_dtype"); opts->new_dtype = gifti_str2datatype(argv[ac]); @@ -295,11 +327,13 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { fprintf(stderr, "** invalid datatype '%s'\n", argv[ac]); return -1; } - } else if (!strcmp(argv[ac], "-new_ndim")) { + } + else if (!strcmp(argv[ac], "-new_ndim")) { ac++; CHECK_NEXT_OPT(ac, argc, "-new_ndim"); opts->new_ndim = atol(argv[ac]); - } else if (!strcmp(argv[ac], "-new_dims")) { + } + else if (!strcmp(argv[ac], "-new_dims")) { ac++; for (c = 0; ac < argc && c < GIFTI_DARRAY_DIM_LEN && argv[ac][0] != '-'; ac++, c++) opts->new_dims[c] = atol(argv[ac]); @@ -308,13 +342,17 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { return -1; } ac--; /* You've gone too far, go to your room! */ - } else if (!strcmp(argv[ac], "-new_data")) { + } + else if (!strcmp(argv[ac], "-new_data")) { opts->new_data = 1; - } else if (!strcmp(argv[ac], "-no_data")) { + } + else if (!strcmp(argv[ac], "-no_data")) { opts->dstore = 0; - } else if (!strcmp(argv[ac], "-no_updates")) { + } + else if (!strcmp(argv[ac], "-no_updates")) { opts->update_ok = 0; - } else if (!strcmp(argv[ac], "-read_DAs")) { + } + else if (!strcmp(argv[ac], "-read_DAs")) { ac++; for (c = 0; (ac < argc) && (argv[ac][0] != '-'); ac++, c++) if (add_to_int_list(&opts->DAlistr, atoi(argv[ac]))) return -1; @@ -325,7 +363,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } /* and back up if we've looked too far */ if (ac < argc && argv[ac][0] == '-') ac--; - } else if (!strcmp(argv[ac], "-set_extern_filelist")) { + } + else if (!strcmp(argv[ac], "-set_extern_filelist")) { opts->set_extern = 1; ac++; for (c = 0; (ac < argc) && (argv[ac][0] != '-'); ac++, c++) @@ -337,26 +376,32 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { } /* and back up if we've looked too far */ if (ac < argc && argv[ac][0] == '-') ac--; - } else if (!strcmp(argv[ac], "-show_gifti")) { + } + else if (!strcmp(argv[ac], "-show_gifti")) { opts->gt_display = 1; opts->show_gifti = 1; - } else if (!strcmp(argv[ac], "-write_1D")) { + } + else if (!strcmp(argv[ac], "-write_1D")) { ac++; CHECK_NEXT_OPT(ac, argc, "-write_1D"); opts->ofile_1D = argv[ac]; - } else if (!strcmp(argv[ac], "-write_asc")) { + } + else if (!strcmp(argv[ac], "-write_asc")) { ac++; CHECK_NEXT_OPT(ac, argc, "-write_asc"); opts->ofile_asc = argv[ac]; - } else if (!strcmp(argv[ac], "-write_gifti")) { + } + else if (!strcmp(argv[ac], "-write_gifti")) { ac++; CHECK_NEXT_OPT(ac, argc, "-write_gifti"); opts->ofile_gifti = argv[ac]; - } else if (!strcmp(argv[ac], "-zlevel")) { + } + else if (!strcmp(argv[ac], "-zlevel")) { ac++; CHECK_NEXT_OPT(ac, argc, "-zlevel"); opts->zlevel = atoi(argv[ac]); - } else { + } + else { fprintf(stderr, "** unknown option: '%s'\n", argv[ac]); return 1; } @@ -407,7 +452,8 @@ static int process_opts(int argc, char *argv[], gt_opts *opts) { return 0; } -static int free_gt_opts(gt_opts *opts) { +static int free_gt_opts(gt_opts *opts) +{ if (opts->DAlist.len > 0 && opts->DAlist.list) free(opts->DAlist.list); if (opts->DAlistr.len > 0 && opts->DAlistr.list) free(opts->DAlistr.list); if (opts->DAmodlist.len > 0 && opts->DAmodlist.list) free(opts->DAmodlist.list); @@ -441,7 +487,8 @@ static int free_gt_opts(gt_opts *opts) { return 0; } -int gt_display(gt_opts *opts) { +int gt_display(gt_opts *opts) +{ gifti_image *gim; int c, rv = 0; @@ -458,7 +505,8 @@ int gt_display(gt_opts *opts) { if (!gim) { fprintf(stderr, "** gt_display: failed to read '%s'\n", opts->infiles.list[c]); rv = 1; - } else + } + else gifti_free_image(gim); } @@ -466,7 +514,8 @@ int gt_display(gt_opts *opts) { } /* compare gifti structures and/or included data */ -int gt_compare(gt_opts *opts) { +int gt_compare(gt_opts *opts) +{ gifti_image *gimA; gifti_image *gimB; int rv0 = 0, rv1 = 0; @@ -512,7 +561,8 @@ int gt_compare(gt_opts *opts) { } /* copy MetaData between GIFTI elements or some DataArray elements */ -int gt_copy(gt_opts *opts) { +int gt_copy(gt_opts *opts) +{ gifti_image *src; gifti_image *dest; char **names; @@ -544,7 +594,8 @@ int gt_copy(gt_opts *opts) { if (opts->gim_meta.len == 1 && !strcmp(opts->gim_meta.list[0], "ALL")) { names = src->meta.name; for (c = 0; c < src->meta.length; c++) rv |= gifti_copy_gifti_meta(dest, src, names[c]); - } else { + } + else { names = opts->gim_meta.list; for (c = 0; c < opts->gim_meta.len; c++) rv |= gifti_copy_gifti_meta(dest, src, names[c]); } @@ -556,13 +607,16 @@ int gt_copy(gt_opts *opts) { if (src->numDA != dest->numDA || src->numDA <= 0) { fprintf(stderr, "** bad numDA for DA MD copy, %d, %d\n", src->numDA, dest->numDA); rv = 1; - } else if (!src->darray || !dest->darray) { + } + else if (!src->darray || !dest->darray) { fprintf(stderr, "** invalid darray pointers for copy\n"); rv = 1; - } else { /* all seems well, copy all meta from src to dest */ + } + else { /* all seems well, copy all meta from src to dest */ for (c = 0; c < src->numDA; c++) rv |= gifti_copy_all_DA_meta(dest->darray[c], src->darray[c]); } - } else { + } + else { names = opts->DA_meta.list; for (c = 0; c < opts->DA_meta.len; c++) rv |= gifti_copy_DA_meta_many(dest, src, names[c], opts->DAlist.list, opts->DAlist.len); @@ -577,7 +631,8 @@ int gt_copy(gt_opts *opts) { return rv; } -int gt_test(gt_opts *opts) { +int gt_test(gt_opts *opts) +{ gifti_image *gim; int c, rv = 0; @@ -592,7 +647,8 @@ int gt_test(gt_opts *opts) { if (!gim) { fprintf(stderr, "** gt_test: failed to read '%s'\n", opts->infiles.list[c]); rv = 1; - } else + } + else gifti_free_image(gim); } @@ -607,7 +663,8 @@ int gt_test(gt_opts *opts) { * * input: there can be only one (immortal? Sean Connery?) */ -int gt_write(gt_opts *opts) { +int gt_write(gt_opts *opts) +{ gifti_image *gim; int rv; @@ -633,7 +690,8 @@ int gt_write(gt_opts *opts) { } /* apply encoding, and allow other formats */ -int gt_write_dataset(gt_opts *opts, gifti_image *gim) { +int gt_write_dataset(gt_opts *opts, gifti_image *gim) +{ int c; if (!gim) { @@ -699,7 +757,8 @@ int gt_write_dataset(gt_opts *opts, gifti_image *gim) { * Note that the DA list selection requires reading the dataset twice, * first to compute the number of DA elements. */ -gifti_image *gt_read_dataset(gt_opts *opts, char *fname) { +gifti_image *gt_read_dataset(gt_opts *opts, char *fname) +{ gifti_image *gim; char *fcopy = NULL, *iptr, *infile = fname; int *dalist = NULL, numDA = -1; @@ -791,7 +850,8 @@ gifti_image *gt_read_dataset(gt_opts *opts, char *fname) { /* init any options that should not default to 0 (so 0 means something, * or the default is non-zero) */ -static int init_opts(gt_opts *opts) { +static int init_opts(gt_opts *opts) +{ memset(opts, 0, sizeof(gt_opts)); /* gt_* should init to 0 */ @@ -815,7 +875,8 @@ static int init_opts(gt_opts *opts) { return 0; } -static int disp_gt_opts(char *mesg, gt_opts *opts, FILE *stream) { +static int disp_gt_opts(char *mesg, gt_opts *opts, FILE *stream) +{ FILE *fp = stream ? stream : stdout; if (mesg) fputs(mesg, fp); @@ -924,7 +985,8 @@ static int disp_gt_opts(char *mesg, gt_opts *opts, FILE *stream) { return 0; } -static int show_str_list(const char *mesg, gt_str_list *list, FILE *fp) { +static int show_str_list(const char *mesg, gt_str_list *list, FILE *fp) +{ FILE *stream = fp ? fp : stdout; int c; @@ -945,19 +1007,22 @@ static int show_str_list(const char *mesg, gt_str_list *list, FILE *fp) { return 0; } -static int show_hist(void) { +static int show_hist(void) +{ int c, len = sizeof(g_history) / sizeof(char *); for (c = 0; c < len; c++) fputs(g_history[c], stdout); putchar('\n'); return 0; } -static int show_version(void) { +static int show_version(void) +{ puts(g_version); return 0; } -static int show_help() { +static int show_help() +{ printf( "------------------------------------------------------------\n" "gifti_tool - create, display, modify or compare GIFTI datasets\n" @@ -1505,7 +1570,8 @@ static int show_help() { return 0; } -int write_as_asc(gifti_image *gim, char *prefix) { +int write_as_asc(gifti_image *gim, char *prefix) +{ giiDataArray *dac; /* coords */ giiDataArray *dat; /* triangles */ @@ -1524,7 +1590,8 @@ int write_as_asc(gifti_image *gim, char *prefix) { /* if dlist contains 1 element, write out as 2-D list, else each DA must have only 1 dimension */ -int write_1D_file(giiDataArray **dlist, int len, char *prefix, int add_suf) { +int write_1D_file(giiDataArray **dlist, int len, char *prefix, int add_suf) +{ giiDataArray *da; FILE *fp; char *name = prefix; @@ -1558,11 +1625,13 @@ int write_1D_file(giiDataArray **dlist, int len, char *prefix, int add_suf) { if (da->ind_ord == GIFTI_IND_ORD_COL_MAJOR) { fprintf(stderr, "-- writing data rows in reverse order\n"); for (c = rows - 1; c >= 0; c--) ewrite_data_line(da->data, da->datatype, c, cols, 0, 0, fp); - } else { + } + else { fprintf(stderr, "-- writing data rows in normal order\n"); for (c = 0; c < rows; c++) ewrite_data_line(da->data, da->datatype, c, cols, 0, 0, fp); } - } else { /* write da->nvals lines of 'num values */ + } + else { /* write da->nvals lines of 'num values */ void **vlist = (void **)malloc(len * sizeof(void *)); int fail = 0; @@ -1574,10 +1643,12 @@ int write_1D_file(giiDataArray **dlist, int len, char *prefix, int add_suf) { if (!vlist[c]) { fprintf(stderr, "** DA[%lld] has no data, bailing...\n", c); fail = 1; - } else if (dlist[c]->nvals != dlist[0]->nvals) { + } + else if (dlist[c]->nvals != dlist[0]->nvals) { fprintf(stderr, "** d[%lld] has %lld vals, but d[0] has %lld\n", c, dlist[c]->nvals, dlist[0]->nvals); fail = 1; - } else if (dlist[c]->datatype != dlist[0]->datatype) { + } + else if (dlist[c]->datatype != dlist[0]->datatype) { fprintf(stderr, "** d[%lld] has type %d, but d[0] has %d\n", c, dlist[c]->datatype, dlist[0]->datatype); fail = 1; } @@ -1610,7 +1681,8 @@ int write_1D_file(giiDataArray **dlist, int len, char *prefix, int add_suf) { return 0; } -int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_suf) { +int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_suf) +{ giiDataArray *da; FILE *fp; char *name = prefix; @@ -1635,7 +1707,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su fclose(fp); if (nbuf) free(nbuf); return 1; - } else if (gifti_DA_rows_cols(dt, &trows, &tcols)) { + } + else if (gifti_DA_rows_cols(dt, &trows, &tcols)) { fclose(fp); if (nbuf) free(nbuf); return 1; @@ -1656,7 +1729,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su if (da->ind_ord == GIFTI_IND_ORD_COL_MAJOR) { fprintf(stderr, "-- writing coord rows in reverse order\n"); for (c = rows - 1; c >= 0; c--) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); - } else { + } + else { fprintf(stderr, "-- writing coord rows in normal order\n"); for (c = 0; c < rows; c++) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); } @@ -1670,7 +1744,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su if (da->ind_ord == GIFTI_IND_ORD_COL_MAJOR) { fprintf(stderr, "-- writing triangle rows in reverse order\n"); for (c = rows - 1; c >= 0; c--) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); - } else { + } + else { fprintf(stderr, "-- writing triangle rows in normal order\n"); for (c = 0; c < rows; c++) ewrite_data_line(da->data, da->datatype, c, cols, 0, 1, fp); } @@ -1680,7 +1755,8 @@ int write_surf_file(giiDataArray *dc, giiDataArray *dt, char *prefix, int add_su return 0; } -int ewrite_data_line(void *data, int type, int row, int cols, int spaces, int trail0, FILE *fp) { +int ewrite_data_line(void *data, int type, int row, int cols, int spaces, int trail0, FILE *fp) +{ int c; if (!data || row < 0 || cols <= 0 || !fp) { static int show = 1; @@ -1779,7 +1855,8 @@ int ewrite_data_line(void *data, int type, int row, int cols, int spaces, int tr } /* write out as cols by rows (else we'd use ewrite_data_line) */ -int ewrite_many_lines(void **data, int type, long long cols, long long rows, int spaces, FILE *fp) { +int ewrite_many_lines(void **data, int type, long long cols, long long rows, int spaces, FILE *fp) +{ long long r, c; if (!data || rows == 0 || cols == 0 || !fp) return 1; @@ -1899,7 +1976,8 @@ int ewrite_many_lines(void **data, int type, long long cols, long long rows, int * - only bother to alloc one pointer at a time (don't need efficiency here) * - return 0 on success *----------------------------------------------------------------------*/ -static int add_to_int_list(gt_int_list *ilist, int val) { +static int add_to_int_list(gt_int_list *ilist, int val) +{ if (ilist->len == 0) ilist->list = NULL; /* just to be safe */ ilist->len++; ilist->list = (int *)realloc(ilist->list, ilist->len * sizeof(int)); @@ -1918,7 +1996,8 @@ static int add_to_int_list(gt_int_list *ilist, int val) { * - only bother to alloc one pointer at a time (don't need efficiency here) * - return 0 on success *----------------------------------------------------------------------*/ -static int add_to_str_list(gt_str_list *slist, char *str) { +static int add_to_str_list(gt_str_list *slist, char *str) +{ if (slist->len == 0) slist->list = NULL; /* just to be safe */ slist->len++; slist->list = (char **)realloc(slist->list, slist->len * sizeof(char *)); @@ -1932,7 +2011,8 @@ static int add_to_str_list(gt_str_list *slist, char *str) { return 0; } -int gt_modify_dset(gt_opts *opts, gifti_image *gim) { +int gt_modify_dset(gt_opts *opts, gifti_image *gim) +{ gt_int_list *ilist; int c, errs = 0; @@ -1962,7 +2042,8 @@ int gt_modify_dset(gt_opts *opts, gifti_image *gim) { /* apply to list */ for (c = 0; c < opts->DAmodlist.len; c++) errs += gifti_set_DA_atrs(gim->darray[ilist->list[c]], (const char **)opts->DA_atrs.list, opts->DA_atrs.len, 0); - } else /* apply to all DA elements */ + } + else /* apply to all DA elements */ for (c = 0; c < gim->numDA; c++) errs += gifti_set_DA_atrs(gim->darray[c], (const char **)opts->DA_atrs.list, opts->DA_atrs.len, 0); } diff --git a/utils/gifti_tool.h b/utils/gifti_tool.h index 399c330fc29..4f31c21f09e 100644 --- a/utils/gifti_tool.h +++ b/utils/gifti_tool.h @@ -1,16 +1,19 @@ #ifndef GIFTI_TOOL_H #define GIFTI_TOOL_H -typedef struct { +typedef struct +{ int len; char **list; } gt_str_list; -typedef struct { +typedef struct +{ int len; int *list; } gt_int_list; -typedef struct { +typedef struct +{ /* main action flags */ int gt_compare; /* somehow compare 2 datasets */ int gt_copy; /* copy things between 2 datasets */ diff --git a/utils/gifti_xml.c b/utils/gifti_xml.c index 4700a4fe3ac..27ad014da8b 100644 --- a/utils/gifti_xml.c +++ b/utils/gifti_xml.c @@ -462,7 +462,8 @@ static unsigned char b64_decode_table[256] = { /* note: the buffer needs to be large enough to contain any contiguous piece of (CDATA?) text, o.w. it will require parsing in pieces */ -gifti_image *gxml_read_image(const char *fname, int read_data, const int *dalist, int dalen) { +gifti_image *gxml_read_image(const char *fname, int read_data, const int *dalist, int dalen) +{ gxml_data *xd = &GXD; /* point to global struct */ XML_Parser parser; unsigned blen; @@ -565,7 +566,8 @@ gifti_image *gxml_read_image(const char *fname, int read_data, const int *dalist } /* free da_list and buffers */ -static int free_xd_data(gxml_data *xd) { +static int free_xd_data(gxml_data *xd) +{ if (xd->da_list) { free(xd->da_list); xd->da_list = NULL; @@ -592,7 +594,8 @@ static int free_xd_data(gxml_data *xd) { * create a 'taken' list, matching xd->da_len (but unset) * for each index, if it is not set, find one and copy */ -static int apply_da_list_order(gxml_data *xd, const int *orig, int len) { +static int apply_da_list_order(gxml_data *xd, const int *orig, int len) +{ giiDataArray **newlist; int *taken; /* whether xd->da_list[i] was used */ int newc, oldc, errors = 0, nDA; @@ -628,14 +631,16 @@ static int apply_da_list_order(gxml_data *xd, const int *orig, int len) { fprintf(stderr, "** ADLO: failed to find index %d in da_list\n", orig[newc]); errors++; continue; - } else if (xd->verb > 3) + } + else if (xd->verb > 3) fprintf(stderr, "++ found orig index %d at sorted list %d\n", orig[newc], oldc); /* either steal the pointer or copy the DA */ if (!taken[oldc]) { taken[oldc] = 1; /* mark it as taken */ newlist[newc] = xd->gim->darray[oldc]; - } else { /* we must make a new copy */ + } + else { /* we must make a new copy */ newlist[newc] = gifti_copy_DataArray(xd->gim->darray[oldc], 1); if (!newlist[newc]) errors++; } @@ -669,14 +674,16 @@ static int apply_da_list_order(gxml_data *xd, const int *orig, int len) { } /* return 0 on success */ -int gxml_write_image(gifti_image *gim, const char *fname, int write_data) { +int gxml_write_image(gifti_image *gim, const char *fname, int write_data) +{ gxml_data *xd = &GXD; /* point to global struct */ FILE *fp; if (!gim) { fprintf(stderr, "** GXML write: no gifti_image\n"); return 1; - } else if (!fname) { + } + else if (!fname) { fprintf(stderr, "** GXML write: no filename\n"); return 1; } @@ -731,7 +738,8 @@ int gxml_write_image(gifti_image *gim, const char *fname, int write_data) { /*! verb is the vebose level, with 0 meaning "only report errors" (up to 7) */ int gxml_get_verb(void) { return GXD.verb; } -int gxml_set_verb(int val) { +int gxml_set_verb(int val) +{ if (val == -1) GXD.verb = 1; else if (val >= 0) @@ -741,7 +749,8 @@ int gxml_set_verb(int val) { /*! the dstore flag controls whether data is read from a GIFTI file */ int gxml_get_dstore(void) { return GXD.dstore; } -int gxml_set_dstore(int val) { +int gxml_set_dstore(int val) +{ if (val) GXD.dstore = 1; /* includes -1 as applying the default */ else @@ -751,7 +760,8 @@ int gxml_set_dstore(int val) { /*! indent is the number of spaces per indent level written to a GIFTI file */ int gxml_get_indent(void) { return GXD.indent; } -int gxml_set_indent(int val) { +int gxml_set_indent(int val) +{ if (val == -1) GXD.indent = 3; else if (val >= 0) @@ -763,7 +773,8 @@ int gxml_set_indent(int val) { /*! buf_size is the size of the XML I/O buffer given to expat */ int gxml_get_buf_size(void) { return GXD.buf_size; } -int gxml_set_buf_size(int val) { +int gxml_set_buf_size(int val) +{ if (val == -1) GXD.buf_size = GXML_DEF_BSIZE; else if (val > 0) @@ -788,7 +799,8 @@ int gxml_set_b64_check(int val) /* -1 means apply default */ /*! update_ok tells the library whether it is allowed to modify metadata */ int gxml_get_update_ok(void) { return GXD.update_ok; } -int gxml_set_update_ok(int val) { +int gxml_set_update_ok(int val) +{ if (val == -1) GXD.update_ok = 1; /* default is yes */ else if (val >= 0) @@ -802,7 +814,8 @@ int gxml_set_update_ok(int val) { (of 6, I believe) and value levels being in {0..9} (with 0 meaning no compression) */ int gxml_get_zlevel(void) { return GXD.zlevel; } -int gxml_set_zlevel(int val) { +int gxml_set_zlevel(int val) +{ if (val == -1) GXD.zlevel = GZ_DEFAULT_COMPRESSION; else if (val >= 0 && val <= 9) @@ -813,7 +826,8 @@ int gxml_set_zlevel(int val) { } /*----------------------- END accessor functions -----------------------*/ -static int init_gxml_data(gxml_data *dp, int doall, const int *dalist, int len) { +static int init_gxml_data(gxml_data *dp, int doall, const int *dalist, int len) +{ int errs = 0; if (doall) { /* user modifiable - init all to defaults */ @@ -828,7 +842,8 @@ static int init_gxml_data(gxml_data *dp, int doall, const int *dalist, int len) if (dalist && len > 0) { if (short_sorted_da_list(dp, dalist, len)) errs++; /* continue */ - } else { + } + else { dp->da_list = NULL; dp->da_len = 0; } @@ -864,7 +879,8 @@ static int init_gxml_data(gxml_data *dp, int doall, const int *dalist, int len) return errs; } -static int short_sorted_da_list(gxml_data *dp, const int *dalist, int len) { +static int short_sorted_da_list(gxml_data *dp, const int *dalist, int len) +{ int *da_copy, c, cind; /* first, duplicate list */ @@ -902,7 +918,8 @@ static int short_sorted_da_list(gxml_data *dp, const int *dalist, int len) { } /* for qsort */ -static int int_compare(const void *v0, const void *v1) { +static int int_compare(const void *v0, const void *v1) +{ int *i0 = (int *)v0; int *i1 = (int *)v1; @@ -913,14 +930,16 @@ static int int_compare(const void *v0, const void *v1) { /* ---------------------------------------------------------------------- */ -static void show_depth(int depth, int show, FILE *fp) { +static void show_depth(int depth, int show, FILE *fp) +{ if (show) fprintf(fp, "%*s %02d ", 3 * depth, "", depth); else fprintf(fp, "%*s ", 3 * depth, ""); } -static void show_enames(FILE *fp) { +static void show_enames(FILE *fp) +{ int c; fprintf(fp, "-------------------------------\n" @@ -929,7 +948,8 @@ static void show_enames(FILE *fp) { fprintf(fp, "-------------------------------\n"); } -static int ename2type(const char *name) { +static int ename2type(const char *name) +{ int etype; for (etype = GXML_ETYPE_LAST; etype > GXML_ETYPE_INVALID; etype--) if (!strcmp(name, enames[etype])) break; @@ -937,7 +957,8 @@ static int ename2type(const char *name) { } /* name should be null terminated */ -static int epush(gxml_data *xd, int etype, const char *ename, const char **attr) { +static int epush(gxml_data *xd, int etype, const char *ename, const char **attr) +{ if (xd->depth < 0 || xd->depth > GXML_MAX_DEPTH) { fprintf(stderr, "** push: stack depth %d out of [0,%d] range\n", xd->depth, GXML_MAX_DEPTH); xd->errors++; @@ -1007,7 +1028,8 @@ static int epush(gxml_data *xd, int etype, const char *ename, const char **attr) } /* initialize the gifti_element and set attributes */ -static int push_gifti(gxml_data *xd, const char **attr) { +static int push_gifti(gxml_data *xd, const char **attr) +{ gifti_image *gim; int c; @@ -1037,7 +1059,8 @@ static int push_gifti(gxml_data *xd, const char **attr) { } /* simply verify that we have not been here before */ -static int push_meta(gxml_data *xd) { +static int push_meta(gxml_data *xd) +{ giiMetaData *md = find_current_MetaData(xd, 0); if (md->length != 0 || md->name || md->value) { @@ -1049,7 +1072,8 @@ static int push_meta(gxml_data *xd) { } /* find the parent struct, and return its meta field */ -static giiMetaData *find_current_MetaData(gxml_data *xd, int cdepth) { +static giiMetaData *find_current_MetaData(gxml_data *xd, int cdepth) +{ giiDataArray *da; giiMetaData *md; int da_ind, parent; @@ -1075,7 +1099,8 @@ static giiMetaData *find_current_MetaData(gxml_data *xd, int cdepth) { return NULL; } md = &da->meta; - } else { + } + else { fprintf(stderr, "** FMeta: child of invalid parent '%s'\n", enames[parent]); return NULL; } @@ -1084,7 +1109,8 @@ static giiMetaData *find_current_MetaData(gxml_data *xd, int cdepth) { } /* we will add a pair, so update length and allocate pointers */ -static int push_md(gxml_data *xd) { +static int push_md(gxml_data *xd) +{ giiMetaData *md = find_current_MetaData(xd, 1); /* MD is 1 below */ if (!md) return 1; /* error were printed */ @@ -1107,7 +1133,8 @@ static int push_md(gxml_data *xd) { } /* set cdata to the current meta->name address, and clear it */ -static int push_name(gxml_data *xd) { +static int push_name(gxml_data *xd) +{ giiMetaData *md = find_current_MetaData(xd, 2); /* name is 2 below */ if (!md) return 1; @@ -1120,7 +1147,8 @@ static int push_name(gxml_data *xd) { } /* set cdata to the current meta->value address, and clear it */ -static int push_value(gxml_data *xd) { +static int push_value(gxml_data *xd) +{ giiMetaData *md = find_current_MetaData(xd, 2); /* value is 2 below */ if (!md) return 1; @@ -1133,7 +1161,8 @@ static int push_value(gxml_data *xd) { } /* check that LT is currently empty */ -static int push_LT(gxml_data *xd) { +static int push_LT(gxml_data *xd) +{ giiLabelTable *lt = &xd->gim->labeltable; if (lt->length || lt->key || lt->label) { @@ -1147,7 +1176,8 @@ static int push_LT(gxml_data *xd) { * (note that the Key (or Index) attribute is required) * * 'Index' attribute has been replaced by 'Key' 7 Mar 2010 */ -static int push_label(gxml_data *xd, const char **attr) { +static int push_label(gxml_data *xd, const char **attr) +{ giiLabelTable *lt = &xd->gim->labeltable; float rgba[4] = {0.0, 0.0, 0.0, 0.0}; int key = 0, rv; @@ -1165,12 +1195,14 @@ static int push_label(gxml_data *xd, const char **attr) { if (!attr) { fprintf(stderr, "** Label %d missing attributes\n", lt->length - 1); lt->key[lt->length - 1] = 0; - } else { + } + else { /* get any known attributes */ rv = get_label_attrs(xd, attr, &key, rgba); if (rv == 1) { lt->key[lt->length - 1] = key; - } else if (rv == 2) { + } + else if (rv == 2) { lt->key[lt->length - 1] = key; (void)add_label_rgba(xd, lt, rgba); } /* else error already printed */ @@ -1184,7 +1216,8 @@ static int push_label(gxml_data *xd, const char **attr) { } /* add the rgba entries to the LabelTable, length is already updated */ -static int add_label_rgba(gxml_data *xd, giiLabelTable *lt, float *rgba) { +static int add_label_rgba(gxml_data *xd, giiLabelTable *lt, float *rgba) +{ if (!xd || !lt || !rgba) { fprintf(stderr, "** add_label_rgba, bad params\n"); return 1; @@ -1211,7 +1244,8 @@ static int add_label_rgba(gxml_data *xd, giiLabelTable *lt, float *rgba) { /* get key and RGBA attributes, if they exist * return 1 if key, 2 if key+rgba, 0 if neither, -1 on error */ -static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rgba) { +static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rgba) +{ giiLabelTable *lt = &xd->gim->labeltable; const char **aptr; char *endp; /* for verifying float read */ @@ -1235,10 +1269,12 @@ static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rg if (!strcmp(*aptr, "Key")) { *key = atoi(aptr[1]); found |= (1 << 0); - } else if (!strcmp(*aptr, "Index")) { /* old form of Key */ + } + else if (!strcmp(*aptr, "Index")) { /* old form of Key */ *key = atoi(aptr[1]); found |= (1 << 0); - } else if (!strcmp(*aptr, "Red")) { + } + else if (!strcmp(*aptr, "Red")) { rgba[0] = strtod(aptr[1], &endp); if (endp <= aptr[1]) { fprintf(stderr, "** bad GIFTI label %d Red attr\n", lind); @@ -1246,7 +1282,8 @@ static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rg return -1; } found |= (1 << 1); - } else if (!strcmp(*aptr, "Green")) { + } + else if (!strcmp(*aptr, "Green")) { rgba[1] = strtod(aptr[1], &endp); if (endp <= aptr[1]) { fprintf(stderr, "** bad GIFTI label %d Green attr\n", lind); @@ -1254,7 +1291,8 @@ static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rg return -1; } found |= (1 << 2); - } else if (!strcmp(*aptr, "Blue")) { + } + else if (!strcmp(*aptr, "Blue")) { rgba[2] = strtod(aptr[1], &endp); if (endp <= aptr[1]) { fprintf(stderr, "** bad GIFTI label %d Blue attr\n", lind); @@ -1262,7 +1300,8 @@ static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rg return -1; } found |= (1 << 3); - } else if (!strcmp(*aptr, "Alpha")) { + } + else if (!strcmp(*aptr, "Alpha")) { rgba[3] = strtod(aptr[1], &endp); if (endp <= aptr[1]) { fprintf(stderr, "** bad GIFTI label %d Alpha attr\n", lind); @@ -1270,7 +1309,8 @@ static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rg return -1; } found |= (1 << 4); - } else { + } + else { fprintf(stderr, "** unknown GIFTI label %d attr\n", lind); show_attrs(xd, GXML_ETYPE_LABEL, attr); return -1; @@ -1280,7 +1320,8 @@ static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rg if (found == 0) { fprintf(stderr, "** GIFTI label %d, missing 'Key' attr\n", lind); return 0; - } else if (found != 1 && found != 31) { + } + else if (found != 1 && found != 31) { fprintf(stderr, "** GIFTI label %d, partial attributes\n", lind); show_attrs(xd, GXML_ETYPE_LABEL, attr); return -1; @@ -1298,7 +1339,8 @@ static int get_label_attrs(gxml_data *xd, const char **attr, int *key, float *rg } /* initialize the gifti_element and set attributes */ -static int push_darray(gxml_data *xd, const char **attr) { +static int push_darray(gxml_data *xd, const char **attr) +{ giiDataArray *da; /* maintain a count of the number seen */ @@ -1309,7 +1351,8 @@ static int push_darray(gxml_data *xd, const char **attr) { { if (xd->verb > 1) fprintf(stderr, "++ keeping DA[%d]\n", xd->eleDA - 1); xd->da_ind++; - } else { + } + else { if (xd->verb > 1) fprintf(stderr, "++ skipping DA[%d]\n", xd->eleDA - 1); xd->skip = xd->depth; return 1; /* return and skip this element */ @@ -1333,7 +1376,8 @@ static int push_darray(gxml_data *xd, const char **attr) { } /* check for base64 errors, needed uncompression, and byte swapping */ -static int pop_darray(gxml_data *xd) { +static int pop_darray(gxml_data *xd) +{ giiDataArray *da = xd->gim->darray[xd->gim->numDA - 1]; /* current DA */ if (!da) return 1; @@ -1370,7 +1414,8 @@ static int pop_darray(gxml_data *xd) { fprintf(stderr, " (zlib failure, corrupted data)\n"); else if (rv != Z_OK) fprintf(stderr, " (zlib failure, unknown error %d)\n", rv); - } else if (xd->verb > 2 || (xd->verb > 1 && xd->gim->numDA == 1)) + } + else if (xd->verb > 2 || (xd->verb > 1 && xd->gim->numDA == 1)) fprintf(stderr, "-- uncompressed buffer (%.2f%% of %lld bytes)\n", 100.0 * xd->dind / olen, olen); if (olen != da->nvals * da->nbyper) { @@ -1403,7 +1448,8 @@ static int pop_darray(gxml_data *xd) { } /* make space for a new CS structure in the current DataArray */ -static int push_cstm(gxml_data *xd) { +static int push_cstm(gxml_data *xd) +{ giiDataArray *da = xd->gim->darray[xd->gim->numDA - 1]; /* current DA */ if (da->intent != NIFTI_INTENT_POINTSET && xd->verb > 0) @@ -1419,7 +1465,8 @@ static int push_cstm(gxml_data *xd) { } /* verify the processing buffer space, alloc data space */ -static int push_data(gxml_data *xd) { +static int push_data(gxml_data *xd) +{ giiDataArray *da = xd->gim->darray[xd->gim->numDA - 1]; /* current DA */ int zsize; @@ -1460,14 +1507,16 @@ static int push_data(gxml_data *xd) { if (!da->data) { fprintf(stderr, "** PD: failed to alloc %lld bytes for darray[%d]\n", da->nvals * da->nbyper, xd->gim->numDA - 1); return 1; - } else if (xd->verb > 3) + } + else if (xd->verb > 3) fprintf(stderr, "++ PD: alloc %lld bytes for darray[%d]\n", da->nvals * da->nbyper, xd->gim->numDA - 1); return 0; } /* point cdata to the correct location and init */ -static int push_dspace(gxml_data *xd) { +static int push_dspace(gxml_data *xd) +{ int CSind = xd->gim->darray[xd->gim->numDA - 1]->numCS - 1; if (CSind < 0) { fprintf(stderr, "** PD: bad numCS %d in darray %d, skipping...", CSind + 1, xd->gim->numDA - 1); @@ -1488,7 +1537,8 @@ static int push_dspace(gxml_data *xd) { } /* point cdata to the correct location and init */ -static int push_xspace(gxml_data *xd) { +static int push_xspace(gxml_data *xd) +{ int CSind = xd->gim->darray[xd->gim->numDA - 1]->numCS - 1; if (CSind < 0) { fprintf(stderr, "** PX: bad numCS %d in darray %d, skipping...", CSind + 1, xd->gim->numDA - 1); @@ -1509,7 +1559,8 @@ static int push_xspace(gxml_data *xd) { } /* verify the processing buffer space */ -static int push_xform(gxml_data *xd) { +static int push_xform(gxml_data *xd) +{ int CSind = xd->gim->darray[xd->gim->numDA - 1]->numCS - 1; if (CSind < 0) { fprintf(stderr, "** PXform: bad numCS %d in darray %d, skipping...", CSind + 1, xd->gim->numDA - 1); @@ -1539,7 +1590,8 @@ static int push_xform(gxml_data *xd) { return 0; } -static int epop(gxml_data *xd, int etype, const char *ename) { +static int epop(gxml_data *xd, int etype, const char *ename) +{ giiDataArray *da; xd->cdata = NULL; /* clear fields for future use */ @@ -1548,7 +1600,8 @@ static int epop(gxml_data *xd, int etype, const char *ename) { if (xd->skip == xd->depth) { /* just completed skip element */ if (xd->verb > 2) fprintf(stderr, "-- popping skip element '%s' at depth %d\n", ename, xd->depth); xd->skip = 0; /* clear skip level */ - } else { /* may peform pop action for this element */ + } + else { /* may peform pop action for this element */ switch (etype) { default: /* do nothing special */ break; @@ -1600,7 +1653,8 @@ static int epop(gxml_data *xd, int etype, const char *ename) { } /* return the number of bytes of leading whitespace, up to a max of len */ -static int whitespace_len(const char *str, int len) { +static int whitespace_len(const char *str, int len) +{ int c; if (!str || !*str || len < 1) return 0; for (c = 0; c < len; c++) @@ -1609,7 +1663,8 @@ static int whitespace_len(const char *str, int len) { return len; } -static void show_attrs(gxml_data *xd, int etype, const char **attr) { +static void show_attrs(gxml_data *xd, int etype, const char **attr) +{ int count; show_depth(xd->depth, 1, stderr); fprintf(stderr, ": element %s\n", enames[etype]); @@ -1619,7 +1674,8 @@ static void show_attrs(gxml_data *xd, int etype, const char **attr) { } } -static void XMLCALL cb_start_ele(void *udata, const char *ename, const char **attr) { +static void XMLCALL cb_start_ele(void *udata, const char *ename, const char **attr) +{ gxml_data *xd = (gxml_data *)udata; int etype; @@ -1632,7 +1688,8 @@ static void XMLCALL cb_start_ele(void *udata, const char *ename, const char **at } /* if ending Data, clear prev_end_check */ -static void XMLCALL cb_end_ele(void *udata, const char *ename) { +static void XMLCALL cb_end_ele(void *udata, const char *ename) +{ gxml_data *xd = (gxml_data *)udata; epop(xd, ename2type(ename), ename); @@ -1655,7 +1712,8 @@ static void XMLCALL cb_end_ele(void *udata, const char *ename) { prev_end_check = 0 apply number (though it may change later) */ -static void XMLCALL cb_char(void *udata, const char *cdata, int length) { +static void XMLCALL cb_char(void *udata, const char *cdata, int length) +{ gxml_data *xd = (gxml_data *)udata; const char *str = cdata; int len = length, wlen = 0, parent; @@ -1728,7 +1786,8 @@ static void XMLCALL cb_char(void *udata, const char *cdata, int length) { * * append the new data and null terminate * ---------------------------------------------------------------------- */ -static int append_to_cdata(gxml_data *xd, const char *cdata, int len) { +static int append_to_cdata(gxml_data *xd, const char *cdata, int len) +{ int offset; if (!xd || !cdata || len <= 0) { fprintf(stderr, "** A2CD, bad params (%p,%p,%d)\n", (void *)xd, (void *)cdata, len); @@ -1737,7 +1796,8 @@ static int append_to_cdata(gxml_data *xd, const char *cdata, int len) { if (!*xd->cdata) { offset = 0; xd->clen = len + 1; /* first time, alloc for null */ - } else { + } + else { offset = xd->clen - 1; xd->clen += len; } @@ -1757,13 +1817,15 @@ static int append_to_cdata(gxml_data *xd, const char *cdata, int len) { } /* this must go to the data of the latest darray struct */ -static int append_to_data(gxml_data *xd, const char *cdata, int len) { +static int append_to_data(gxml_data *xd, const char *cdata, int len) +{ giiDataArray *da = xd->gim->darray[xd->gim->numDA - 1]; /* current DA */ if (!da || !xd->dlen || !xd->ddata || xd->dind < 0) { fprintf(stderr, "** A2D: bad setup (%p,%d,%p,%lld)\n", (void *)da, xd->dlen, (void *)xd->ddata, xd->dind); return 1; - } else if (!da->data) { + } + else if (!da->data) { fprintf(stderr, "** A2D: no data allocated\n"); return 1; } @@ -1804,7 +1866,8 @@ static int append_to_data(gxml_data *xd, const char *cdata, int len) { * rem_bytes_in -= copy_len * dind = updated offset into output da->data buffer */ -static int append_to_data_b64(gxml_data *xd, char *dest, long long tot_bytes, const char *cdata, int cdlen) { +static int append_to_data_b64(gxml_data *xd, char *dest, long long tot_bytes, const char *cdata, int cdlen) +{ const char *cptr; long long rem_bytes_out; /* remaining length in darray->data */ int rem_bytes_in = cdlen; /* remaining length in cdata */ @@ -1826,7 +1889,8 @@ static int append_to_data_b64(gxml_data *xd, char *dest, long long tot_bytes, co if (copy_len > rem_bytes_in) { unused = copy_len - rem_bytes_in; /* unused at end of buffer */ copy_len = rem_bytes_in; - } else + } + else unused = 0; /* copy the data to our intermediate buffer @@ -1883,7 +1947,8 @@ static int append_to_data_b64(gxml_data *xd, char *dest, long long tot_bytes, co * * return the number of bad characters noted */ -static int copy_b64_data(gxml_data *xd, const char *src, char *dest, int src_len, int *dest_len) { +static int copy_b64_data(gxml_data *xd, const char *src, char *dest, int src_len, int *dest_len) +{ const unsigned char *usrc = (const unsigned char *)src; int c, errs = 0, apply_len; @@ -1949,7 +2014,8 @@ static int copy_b64_data(gxml_data *xd, const char *src, char *dest, int src_len return errs; } -static int count_bad_b64_chars(const char *src, int len) { +static int count_bad_b64_chars(const char *src, int len) +{ const unsigned char *usrc = (const unsigned char *)src; int c, bad = 0; @@ -1959,7 +2025,8 @@ static int count_bad_b64_chars(const char *src, int len) { return bad; } -static int show_bad_b64_chars(const char *src, int len) { +static int show_bad_b64_chars(const char *src, int len) +{ const unsigned char *usrc = (const unsigned char *)src; int c, bad = 0; @@ -1978,7 +2045,8 @@ static int show_bad_b64_chars(const char *src, int len) { } /* this must go to the data of the latest darray struct */ -static int append_to_data_ascii(gxml_data *xd, const char *cdata, int len) { +static int append_to_data_ascii(gxml_data *xd, const char *cdata, int len) +{ static int mod_prev = 0; giiDataArray *da = xd->gim->darray[xd->gim->numDA - 1]; /* current DA */ @@ -2013,7 +2081,8 @@ static int append_to_data_ascii(gxml_data *xd, const char *cdata, int len) { if (copy_len > rem_len) { unused = copy_len - rem_len; /* unused at end of buffer */ copy_len = rem_len; - } else + } + else unused = 0; /* copy it to our buffer and null terminate */ @@ -2069,7 +2138,8 @@ static int append_to_data_ascii(gxml_data *xd, const char *cdata, int len) { /* this must go to the xform of the latest darray struct */ /* (process as 1-D array) */ -static int append_to_xform(gxml_data *xd, const char *cdata, int len) { +static int append_to_xform(gxml_data *xd, const char *cdata, int len) +{ static int mod_prev = 0; giiDataArray *da = xd->gim->darray[xd->gim->numDA - 1]; /* current DA */ @@ -2083,7 +2153,8 @@ static int append_to_xform(gxml_data *xd, const char *cdata, int len) { fprintf( stderr, "** A2X: bad setup (%p,%d,%p,%lld,%d)\n", (void *)da, xd->xlen, (void *)xd->xdata, xd->dind, da->numCS); return 1; - } else if (xd->verb > 4) + } + else if (xd->verb > 4) fprintf(stderr, "++ appending %d bytes to xform\n", len); CSind = da->numCS - 1; @@ -2115,7 +2186,8 @@ static int append_to_xform(gxml_data *xd, const char *cdata, int len) { if (copy_len > rem_len) { unused = copy_len - rem_len; /* unused at end of buffer */ copy_len = rem_len; - } else + } + else unused = 0; /* copy it to our buffer and null terminate */ @@ -2186,7 +2258,8 @@ static int append_to_xform(gxml_data *xd, const char *cdata, int len) { o EOL use is not allowed o padding is expected (using '=') */ -static int decode_b64(gxml_data *xd, char *cdata, int cdlen, char *dptr, long long *needed) { +static int decode_b64(gxml_data *xd, char *cdata, int cdlen, char *dptr, long long *needed) +{ unsigned char *din = (unsigned char *)cdata; unsigned char *dout = (unsigned char *)dptr; int blocks = cdlen / 4, rem = cdlen % 4; @@ -2235,7 +2308,8 @@ static int decode_b64(gxml_data *xd, char *cdata, int cdlen, char *dptr, long lo read failure happens only when no characters are processed */ -static int decode_ascii(gxml_data *xd, char *cdata, int cdlen, int type, void *dptr, long long *nvals, int *mod_prev) { +static int decode_ascii(gxml_data *xd, char *cdata, int cdlen, int type, void *dptr, long long *nvals, int *mod_prev) +{ char *p1, *p2; /* for strtoX */ char *prev; /* for remain */ double dval; /* for strtod */ @@ -2457,7 +2531,8 @@ static int decode_ascii(gxml_data *xd, char *cdata, int cdlen, int type, void *d if (isspace(*p1)) { remain = cdlen - (p1 - cdata); *mod_prev = 0; - } else if (prev) { + } + else if (prev) { remain = cdlen - (prev - cdata); *mod_prev = 1; /* still looking at previous val */ } @@ -2471,7 +2546,8 @@ static int decode_ascii(gxml_data *xd, char *cdata, int cdlen, int type, void *d return remain; } -static void XMLCALL cb_instr(void *udata, const char *target, const char *data) { +static void XMLCALL cb_instr(void *udata, const char *target, const char *data) +{ gxml_data *xd = (gxml_data *)udata; if (xd->verb > 3) { show_depth(xd->depth, 1, stderr); @@ -2479,7 +2555,8 @@ static void XMLCALL cb_instr(void *udata, const char *target, const char *data) } } -static void XMLCALL cb_comment(void *udata, const char *str) { +static void XMLCALL cb_comment(void *udata, const char *str) +{ gxml_data *xd = (gxml_data *)udata; if (xd->verb > 1) { show_depth(xd->depth, 1, stderr); @@ -2487,7 +2564,8 @@ static void XMLCALL cb_comment(void *udata, const char *str) { } } -static void XMLCALL cb_cdata_start(void *udata) { +static void XMLCALL cb_cdata_start(void *udata) +{ gxml_data *xd = (gxml_data *)udata; if (xd->verb > 3) { @@ -2497,12 +2575,14 @@ static void XMLCALL cb_cdata_start(void *udata) { (void)epush(xd, GXML_ETYPE_CDATA, enames[GXML_ETYPE_CDATA], NULL); } -static void XMLCALL cb_cdata_end(void *udata) { +static void XMLCALL cb_cdata_end(void *udata) +{ gxml_data *xd = (gxml_data *)udata; epop(xd, GXML_ETYPE_CDATA, enames[GXML_ETYPE_CDATA]); } -static void XMLCALL cb_default(void *udata, const char *str, int length) { +static void XMLCALL cb_default(void *udata, const char *str, int length) +{ gxml_data *xd = (gxml_data *)udata; int wlen = whitespace_len(str, length); int len = length; @@ -2520,7 +2600,8 @@ static void XMLCALL cb_default(void *udata, const char *str, int length) { } } -static void XMLCALL cb_xml_dec(void *udata, const char *ver, const char *enc, int standalone) { +static void XMLCALL cb_xml_dec(void *udata, const char *ver, const char *enc, int standalone) +{ gxml_data *xd = (gxml_data *)udata; if (xd->verb > 2) { show_depth(xd->depth, 1, stderr); @@ -2529,7 +2610,8 @@ static void XMLCALL cb_xml_dec(void *udata, const char *ver, const char *enc, in } static void XMLCALL -cb_start_doctype(void *udata, const char *doctype, const char *sysid, const char *pubid, int has_subset) { +cb_start_doctype(void *udata, const char *doctype, const char *sysid, const char *pubid, int has_subset) +{ gxml_data *xd = (gxml_data *)udata; if (xd->verb > 2) { show_depth(xd->depth, 1, stderr); @@ -2543,7 +2625,8 @@ cb_start_doctype(void *udata, const char *doctype, const char *sysid, const char } } -static void XMLCALL cb_end_doctype(void *udata) { +static void XMLCALL cb_end_doctype(void *udata) +{ gxml_data *xd = (gxml_data *)udata; if (xd->verb > 2) { show_depth(xd->depth, 1, stderr); @@ -2551,7 +2634,8 @@ static void XMLCALL cb_end_doctype(void *udata) { } } -static void XMLCALL cb_elem_dec(void *udata, const char *ename, XML_Content *content) { +static void XMLCALL cb_elem_dec(void *udata, const char *ename, XML_Content *content) +{ gxml_data *xd = (gxml_data *)udata; if (xd->verb > 2) { show_depth(xd->depth, 1, stderr); @@ -2566,7 +2650,8 @@ static void XMLCALL cb_elem_dec(void *udata, const char *ename, XML_Content *con } } -static XML_Parser init_xml_parser(void *user_data) { +static XML_Parser init_xml_parser(void *user_data) +{ XML_Parser parser; parser = XML_ParserCreate(NULL); @@ -2589,7 +2674,8 @@ static XML_Parser init_xml_parser(void *user_data) { return parser; } -static int show_stack(char *mesg, gxml_data *xd) { +static int show_stack(char *mesg, gxml_data *xd) +{ int c; if (!xd) return 1; if (mesg) fputs(mesg, stderr); @@ -2599,7 +2685,8 @@ static int show_stack(char *mesg, gxml_data *xd) { return 0; } -static int stack_is_valid(gxml_data *xd) { +static int stack_is_valid(gxml_data *xd) +{ int valid, etype, parent, bad_parent; if (xd->depth < 0) return 0; @@ -2677,7 +2764,8 @@ static int stack_is_valid(gxml_data *xd) { } /* if bsize is no longer correct, update it and realloc the buffer */ -static int reset_xml_buf(gxml_data *xd, char **buf, int *bsize) { +static int reset_xml_buf(gxml_data *xd, char **buf, int *bsize) +{ if (*bsize == xd->buf_size) { if (xd->verb > 3) fprintf(stderr, "-- buffer kept at %d bytes\n", *bsize); return 0; @@ -2700,7 +2788,8 @@ static int reset_xml_buf(gxml_data *xd, char **buf, int *bsize) { /* decide how big a processing buffer should be (either for a small xform matrix or a Data element) */ -static int partial_buf_size(long long nbytes) { +static int partial_buf_size(long long nbytes) +{ int ibytes = (int)nbytes; /* never more than 10 MB, anyway */ if (ibytes <= GXML_MIN_BSIZE) return GXML_MIN_BSIZE; @@ -2713,7 +2802,8 @@ static int partial_buf_size(long long nbytes) { } /* update xd->buf_size, used prior to reset_xml_buf */ -static int update_xml_buf_size(gxml_data *xd, long long bytes) { +static int update_xml_buf_size(gxml_data *xd, long long bytes) +{ int new_size; if (!xd || bytes < 0) { @@ -2731,7 +2821,8 @@ static int update_xml_buf_size(gxml_data *xd, long long bytes) { } /* used to update any buffer, as the pointer address is passed in */ -static int update_partial_buffer(char **buf, int *blen, long long bytes, int full) { +static int update_partial_buffer(char **buf, int *blen, long long bytes, int full) +{ int bsize = partial_buf_size(bytes); if (full) bsize = bytes; /* want entire buffer */ @@ -2755,7 +2846,8 @@ static int update_partial_buffer(char **buf, int *blen, long long bytes, int ful return 0; } -static int gxml_write_gifti(gxml_data *xd, FILE *fp) { +static int gxml_write_gifti(gxml_data *xd, FILE *fp) +{ gifti_image *gim = xd->gim; int c, offset; @@ -2787,7 +2879,8 @@ static int gxml_write_gifti(gxml_data *xd, FILE *fp) { /* write the giiDataArray */ if (!gim->darray) { if (xd->verb > 0) fprintf(stderr, "** gifti_image, missing darray\n"); - } else { + } + else { for (c = 0; c < gim->numDA; c++) ewrite_darray(xd, gim->darray[c], fp); } @@ -2797,7 +2890,8 @@ static int gxml_write_gifti(gxml_data *xd, FILE *fp) { return 0; } -static int ewrite_darray(gxml_data *xd, giiDataArray *da, FILE *fp) { +static int ewrite_darray(gxml_data *xd, giiDataArray *da, FILE *fp) +{ int spaces = xd->indent * xd->depth; int offset, c; char dimstr[5] = "Dim0"; @@ -2844,7 +2938,8 @@ static int ewrite_darray(gxml_data *xd, giiDataArray *da, FILE *fp) { } /* this depends on ind_ord, how to write out lines */ -static int ewrite_data(gxml_data *xd, giiDataArray *da, FILE *fp) { +static int ewrite_data(gxml_data *xd, giiDataArray *da, FILE *fp) +{ long long c, rows, cols; int spaces = xd->indent * xd->depth; int errs = 0; @@ -2870,9 +2965,11 @@ static int ewrite_data(gxml_data *xd, giiDataArray *da, FILE *fp) { gifti_DA_rows_cols(da, &rows, &cols); /* product will be nvals */ for (c = 0; c < rows; c++) ewrite_data_line(da->data, da->datatype, c, cols, spaces + xd->indent, fp); fprintf(fp, "%*s", spaces, ""); - } else if (da->encoding == GIFTI_ENCODING_B64BIN) { + } + else if (da->encoding == GIFTI_ENCODING_B64BIN) { gxml_disp_b64_data(NULL, da->data, da->nvals * da->nbyper, fp); - } else if (da->encoding == GIFTI_ENCODING_B64GZ) { + } + else if (da->encoding == GIFTI_ENCODING_B64GZ) { #ifdef HAVE_ZLIB /* for compiling, higher level test elsewhere */ uLongf blen = da->nvals * da->nbyper * 1.01 + 12; /* zlib.net */ int rv = 0; @@ -2892,17 +2989,20 @@ static int ewrite_data(gxml_data *xd, giiDataArray *da, FILE *fp) { else fprintf(stderr, "unknown error %d\n", rv); errs++; - } else if (xd->verb > 2) + } + else if (xd->verb > 2) fprintf(stderr, "-- compression succeeded\n"); gxml_disp_b64_data(NULL, xd->zdata, blen, fp); #else fprintf(stderr, "** ewrite_data: no ZLIB to compress with\n"); #endif - } else if (da->encoding == GIFTI_ENCODING_EXTBIN) { + } + else if (da->encoding == GIFTI_ENCODING_EXTBIN) { /* write to external file */ if (gifti_write_extern_DA_data(da)) errs = 1; - } else { + } + else { fprintf(stderr, "** unknown data encoding, %d\n", da->encoding); errs = 1; } @@ -2919,7 +3019,8 @@ static int ewrite_data(gxml_data *xd, giiDataArray *da, FILE *fp) { x = b64_encode_table[((a & 3) << 4) | (b >> 4)], \ y = b64_encode_table[((b & 0xF) << 2) | (c >> 6)], \ z = b64_encode_table[c & 0x3F]) -static int gxml_disp_b64_data(const char *mesg, const void *data, int len, FILE *fp) { +static int gxml_disp_b64_data(const char *mesg, const void *data, int len, FILE *fp) +{ const unsigned char *dp = (const unsigned char *)data; unsigned char w, x, y, z; FILE *stream; @@ -2941,7 +3042,8 @@ static int gxml_disp_b64_data(const char *mesg, const void *data, int len, FILE if (rem == 1) { GII_B64_encode3(dp[0], 0, 0, w, x, y, z); fprintf(stream, "%c%c==", w, x); - } else if (rem == 2) { + } + else if (rem == 2) { GII_B64_encode3(dp[0], dp[1], 0, w, x, y, z); fprintf(stream, "%c%c%c=", w, x, y); } @@ -2950,7 +3052,8 @@ static int gxml_disp_b64_data(const char *mesg, const void *data, int len, FILE return 0; } -static int ewrite_coordsys(gxml_data *xd, giiCoordSystem *cs, FILE *fp) { +static int ewrite_coordsys(gxml_data *xd, giiCoordSystem *cs, FILE *fp) +{ int c, spaces = xd->indent * xd->depth; if (!cs) return 0; /* okay, may not exist */ @@ -2974,7 +3077,8 @@ static int ewrite_coordsys(gxml_data *xd, giiCoordSystem *cs, FILE *fp) { } /* write one 'row' ('cols' values) of data in text */ -static int ewrite_data_line(void *data, int type, long long row, long long cols, int space, FILE *fp) { +static int ewrite_data_line(void *data, int type, long long row, long long cols, int space, FILE *fp) +{ int c; if (!data || row < 0 || cols <= 0 || !fp) return 1; @@ -3065,7 +3169,8 @@ static int ewrite_data_line(void *data, int type, long long row, long long cols, return 0; } -static int ewrite_double_line(double *data, int nvals, int space, FILE *fp) { +static int ewrite_double_line(double *data, int nvals, int space, FILE *fp) +{ int c; if (!data || nvals <= 0 || !fp) return 1; @@ -3077,7 +3182,8 @@ static int ewrite_double_line(double *data, int nvals, int space, FILE *fp) { return 0; } -static int ewrite_text_ele(int ele, const char *cdata, const char *attr, int spaces, int in_CDATA, FILE *fp) { +static int ewrite_text_ele(int ele, const char *cdata, const char *attr, int spaces, int in_CDATA, FILE *fp) +{ int index = ele; if (ele < 0 || ele > GXML_MAX_ELEN) index = 0; /* be safe */ @@ -3096,7 +3202,8 @@ static int ewrite_text_ele(int ele, const char *cdata, const char *attr, int spa return 0; } -static int ewrite_LT(gxml_data *xd, giiLabelTable *lt, int in_CDATA, FILE *fp) { +static int ewrite_LT(gxml_data *xd, giiLabelTable *lt, int in_CDATA, FILE *fp) +{ char attr[256] = ""; float *rgba; int c, spaces = xd->indent * xd->depth; @@ -3127,7 +3234,8 @@ static int ewrite_LT(gxml_data *xd, giiLabelTable *lt, int in_CDATA, FILE *fp) { rgba[2], rgba[3]); rgba += 4; - } else + } + else sprintf(attr, " Key=\"%d\"", lt->key[c]); ewrite_text_ele(GXML_ETYPE_LABEL, lt->label[c], attr, spaces + xd->indent, in_CDATA, fp); @@ -3137,7 +3245,8 @@ static int ewrite_LT(gxml_data *xd, giiLabelTable *lt, int in_CDATA, FILE *fp) { return 0; } -static int ewrite_meta(gxml_data *xd, giiMetaData *md, FILE *fp) { +static int ewrite_meta(gxml_data *xd, giiMetaData *md, FILE *fp) +{ int c, spaces = xd->indent * xd->depth; if (xd->verb > 3) fprintf(stderr, "++ write giiMetaData\n"); @@ -3173,7 +3282,8 @@ static int ewrite_meta(gxml_data *xd, giiMetaData *md, FILE *fp) { } /* print a list of attributes, indented to the same level */ -static int ewrite_ex_atrs(gxml_data *xd, nvpairs *nvp, int offset, int first, FILE *fp) { +static int ewrite_ex_atrs(gxml_data *xd, nvpairs *nvp, int offset, int first, FILE *fp) +{ int c, spaces = xd->indent * xd->depth + offset; if (xd->verb > 2) fprintf(stderr, "++ write %d ex_atr's\n", nvp->length); @@ -3186,7 +3296,8 @@ static int ewrite_ex_atrs(gxml_data *xd, nvpairs *nvp, int offset, int first, FI return 0; } -static int ewrite_int_attr(const char *name, int value, int spaces, int first, FILE *fp) { +static int ewrite_int_attr(const char *name, int value, int spaces, int first, FILE *fp) +{ fprintf(fp, "%s%*s%s=\"%d\"", (first) ? "" : "\n", /* maybe a newline */ @@ -3197,7 +3308,8 @@ static int ewrite_int_attr(const char *name, int value, int spaces, int first, F return 0; } -static int ewrite_long_long_attr(const char *name, long long value, int spaces, int first, FILE *fp) { +static int ewrite_long_long_attr(const char *name, long long value, int spaces, int first, FILE *fp) +{ fprintf(fp, "%s%*s%s=\"%lld\"", (first) ? "" : "\n", /* maybe a newline */ @@ -3208,7 +3320,8 @@ static int ewrite_long_long_attr(const char *name, long long value, int spaces, return 0; } -static int ewrite_str_attr(const char *name, const char *value, int spaces, int first, FILE *fp) { +static int ewrite_str_attr(const char *name, const char *value, int spaces, int first, FILE *fp) +{ fprintf(fp, "%s%*s%s=\"%s\"", (first) ? "" : "\n", /* maybe a newline */ @@ -3219,7 +3332,8 @@ static int ewrite_str_attr(const char *name, const char *value, int spaces, int return 0; } -static int gxml_write_preamble(FILE *fp) { +static int gxml_write_preamble(FILE *fp) +{ char *version = GIFTI_XML_VERSION; char *encoding = GIFTI_XML_ENCODING; char *dtd = GIFTI_XML_DTD_SOURCE; @@ -3230,7 +3344,8 @@ static int gxml_write_preamble(FILE *fp) { return 0; } -static int disp_gxml_data(char *mesg, gxml_data *dp, int show_all) { +static int disp_gxml_data(char *mesg, gxml_data *dp, int show_all) +{ if (mesg) fputs(mesg, stderr); if (!dp) return 1; diff --git a/utils/gtm.c b/utils/gtm.c index 665d00dbaba..6990dbb9d3b 100644 --- a/utils/gtm.c +++ b/utils/gtm.c @@ -54,7 +54,8 @@ #endif /*------------------------------------------------------------------------------------*/ -int GTMSEGprint(GTMSEG *gtmseg, FILE *fp) { +int GTMSEGprint(GTMSEG *gtmseg, FILE *fp) +{ fprintf(fp, "subject %s\n", gtmseg->subject); fprintf(fp, "USF %d\n", gtmseg->USF); fprintf(fp, "OutputUSF %d\n", gtmseg->OutputUSF); @@ -63,7 +64,8 @@ int GTMSEGprint(GTMSEG *gtmseg, FILE *fp) { fprintf(fp, "wmannotfile %s\n", gtmseg->wmannotfile); fprintf(fp, "wmlhbase %d\n", gtmseg->wmlhbase); fprintf(fp, "wmrhbase %d\n", gtmseg->wmrhbase); - } else + } + else fprintf(fp, "wmannotfile NULL\n"); fprintf(fp, "ctxannotfile %s\n", gtmseg->ctxannotfile); fprintf(fp, "ctxlhbase %d\n", gtmseg->ctxlhbase); @@ -82,7 +84,8 @@ int GTMSEGprint(GTMSEG *gtmseg, FILE *fp) { } /*------------------------------------------------------------------------------------*/ -int MRIgtmSeg(GTMSEG *gtmseg) { +int MRIgtmSeg(GTMSEG *gtmseg) +{ int err, *segidlist, nsegs, n; char *SUBJECTS_DIR, tmpstr[5000]; MRI *apas, *aseg, *hrseg, *ctxseg; @@ -143,7 +146,8 @@ int MRIgtmSeg(GTMSEG *gtmseg) { MRISripUnknown(gtmseg->rhw); gtmseg->lhw->ct->idbase = gtmseg->wmlhbase; gtmseg->rhw->ct->idbase = gtmseg->wmrhbase; - } else + } + else printf("Not segmenting WM\n"); sprintf(tmpstr, "%s/%s/label/lh.%s", SUBJECTS_DIR, gtmseg->subject, gtmseg->ctxannotfile); @@ -218,7 +222,8 @@ int MRIgtmSeg(GTMSEG *gtmseg) { printf(" t = %6.4f\n", TimerStop(&timer) / 1000.0); fflush(stdout); ctxseg = MRIannot2CerebralWMSeg(ctxseg, gtmseg->lhw, gtmseg->rhw, gtmseg->dmax, NULL, ctxseg); - } else + } + else printf("Not subsegmenting WM\n"); gtmseg->seg = MRIreplaceList(ctxseg, gtmseg->srclist, gtmseg->targlist, gtmseg->nlist, NULL, NULL); @@ -269,7 +274,8 @@ vessel). CC subsegs are merged into a single label 192. It is assumed that ReplaceThis and WithThat are arrays that have already been allocated. It is also assumed that nReplace has been initialized. The result is that items are added to the list. */ -int GTMdefaultSegReplacmentList(int *nReplace, int *ReplaceThis, int *WithThat) { +int GTMdefaultSegReplacmentList(int *nReplace, int *ReplaceThis, int *WithThat) +{ int nlist; nlist = *nReplace; @@ -365,7 +371,8 @@ determined from the white surf annot. Entries for subcortical structures are determined from ctSubCort (which should have tissue type set for all relevant structures). */ -COLOR_TABLE *GTMSEGctab(GTMSEG *gtmseg, COLOR_TABLE *ctSubCort) { +COLOR_TABLE *GTMSEGctab(GTMSEG *gtmseg, COLOR_TABLE *ctSubCort) +{ int nsegs, *segidlist, *segidhit, n, m, hit, segid, err; COLOR_TABLE *ct, *ct0; CTE *cte, *cte0; @@ -554,7 +561,8 @@ COLOR_TABLE *GTMSEGctab(GTMSEG *gtmseg, COLOR_TABLE *ctSubCort) { of voxels for the seg, and betavar for each seg and frame. Also computes the max and min VRF. */ -int VRFStats(GTM *gtm, double *vrfmean, double *vrfmin, double *vrfmax) { +int VRFStats(GTM *gtm, double *vrfmean, double *vrfmin, double *vrfmax) +{ int n, nvox, segid, f; double vrf; @@ -599,7 +607,8 @@ int VRFStats(GTM *gtm, double *vrfmean, double *vrfmin, double *vrfmax) { \brief Creates the vrf.dat file in the output folder. This is a text file that reports several statistics including the variance reduction factor (VRF). */ -int WriteVRFStats(char *fname, GTM *gtm) { +int WriteVRFStats(char *fname, GTM *gtm) +{ int n, segid, nvox; double vrf; FILE *fp; @@ -644,7 +653,8 @@ int WriteVRFStats(char *fname, GTM *gtm) { \brief Computes global mean for GM, GM+WM, and GM+WM+CSF, each weighted according to number of voxels in each ROI. */ -int GTMglobalStats(GTM *gtm) { +int GTMglobalStats(GTM *gtm) +{ int nthseg, segid, tt, f, ngm, ngmwm, ngmwmcsf; double v; @@ -698,7 +708,8 @@ int GTMglobalStats(GTM *gtm) { \fn int GTMfree(GTM **pGTM) \brief Frees a lot of stuff, but not everything. */ -int GTMfree(GTM **pGTM) { +int GTMfree(GTM **pGTM) +{ GTM *gtm = *pGTM; MRIfree(>m->yvol); @@ -723,7 +734,8 @@ int GTMfree(GTM **pGTM) { \brief Converts the input gtm->yvol to a matrix using GTMvol2mat(). It is important that this be done conistently with X, etc. */ -int GTMmatrixY(GTM *gtm) { +int GTMmatrixY(GTM *gtm) +{ gtm->y = GTMvol2mat(gtm, gtm->yvol, NULL); return (0); } @@ -733,7 +745,8 @@ int GTMmatrixY(GTM *gtm) { \brief Computes the number of voxels in the mask. If the mask is NULL, then just computes the number of voxels in the input. */ -int GTMsetNMask(GTM *gtm) { +int GTMsetNMask(GTM *gtm) +{ if (gtm->mask) gtm->nmask = MRIcountAboveThreshold(gtm->mask, 0.5); else @@ -745,7 +758,8 @@ int GTMsetNMask(GTM *gtm) { \fn int GTMpsfStd(GTM *gtm) \brief Convert the PSF {crs}FWHM to a standard deviation. */ -int GTMpsfStd(GTM *gtm) { +int GTMpsfStd(GTM *gtm) +{ gtm->cStd = gtm->cFWHM / sqrt(log(256.0)); gtm->rStd = gtm->rFWHM / sqrt(log(256.0)); gtm->sStd = gtm->sFWHM / sqrt(log(256.0)); @@ -757,7 +771,8 @@ int GTMpsfStd(GTM *gtm) { \brief Compute a sorted list of segmentation IDs from the segmentation itself (excludes 0). Just runs MRIsegIdListNot0(). */ -int GTMsegidlist(GTM *gtm) { +int GTMsegidlist(GTM *gtm) +{ gtm->segidlist = MRIsegIdListNot0(gtm->anatseg, >m->nsegs, 0); return (0); } @@ -767,7 +782,8 @@ int GTMsegidlist(GTM *gtm) { \brief Allocates the GTM structure but nothing in the structure. sets PadThresh = .0001; */ -GTM *GTMalloc() { +GTM *GTMalloc() +{ GTM *gtm; gtm = (GTM *)calloc(sizeof(GTM), 1); gtm->PadThresh = .0001; @@ -792,7 +808,8 @@ GTM *GTMalloc() { an individual seg in GTMbuildX(). A similar method is used by GTMautoMask() to create a bounding box around the head mask. */ -int GTMnPad(GTM *gtm) { +int GTMnPad(GTM *gtm) +{ double maxFWHM, maxStd; maxFWHM = MAX(gtm->cFWHM / gtm->yvol->xsize, MAX(gtm->rFWHM / gtm->yvol->ysize, gtm->sFWHM / gtm->yvol->zsize)); if (maxFWHM > 0) { @@ -800,7 +817,8 @@ int GTMnPad(GTM *gtm) { maxStd = maxFWHM * sqrt(log(256.0)); gtm->nPad = ceil(sqrt(-log(gtm->PadThresh * maxStd * sqrt(2 * M_PI)) * 2 * maxStd)); printf("maxFWHM = %g (voxels), PadThresh=%g, nPad=%d\n", maxFWHM, gtm->PadThresh, gtm->nPad); - } else + } + else gtm->nPad = 1; return (0); } @@ -812,7 +830,8 @@ int GTMnPad(GTM *gtm) { Also will rescale if rescaling. Returns 1 and computes condition number if matrix cannot be inverted. Otherwise returns 0. */ -int GTMsolve(GTM *gtm) { +int GTMsolve(GTM *gtm) +{ struct timeb timer; int n, f; double sum; @@ -870,7 +889,8 @@ int GTMsolve(GTM *gtm) { on the matrix data must be consistent when going from vol to matrix and back. See also GTMbuildX() and GTMvol2mat(). */ -MRI *GTMmat2vol(GTM *gtm, MATRIX *m, MRI *vol) { +MRI *GTMmat2vol(GTM *gtm, MATRIX *m, MRI *vol) +{ int k, c, r, s, f; if (vol == NULL) { @@ -905,7 +925,8 @@ MRI *GTMmat2vol(GTM *gtm, MATRIX *m, MRI *vol) { on the matrix data must be consistent when going from vol to matrix and back. See also GTMbuildX() and GTMmat2vol(). */ -MATRIX *GTMvol2mat(GTM *gtm, MRI *vol, MATRIX *m) { +MATRIX *GTMvol2mat(GTM *gtm, MRI *vol, MATRIX *m) +{ int k, c, r, s, f; if (m == NULL) { @@ -942,7 +963,8 @@ MATRIX *GTMvol2mat(GTM *gtm, MRI *vol, MATRIX *m) { \brief Computes the residual variance in each segmentation. Not perfect because the resdiual has spill-over. Hopefully it is meaningful for something. */ -int GTMsegrvar(GTM *gtm) { +int GTMsegrvar(GTM *gtm) +{ int c, r, s, f, k; int nthseg = 0, segid; double v; @@ -992,7 +1014,8 @@ int GTMsegrvar(GTM *gtm) { It is a QA metric to compare against the GTM. If masking, it will not be accurate for segs outside the brain. */ -int GTMrbv(GTM *gtm) { +int GTMrbv(GTM *gtm) +{ int c, r, s, f, nthseg, segid; double val, v, vhat0, vhat, v2; LTA *lta; @@ -1033,7 +1056,8 @@ int GTMrbv(GTM *gtm) { MRI *tmp = MRIextractRegion(gtm->rbvsegmasked, NULL, region); MRIfree(>m->rbvsegmasked); gtm->rbvsegmasked = tmp; - } else + } + else gtm->rbvsegmasked = gtm->rbvseg; gtm->anat2rbv = TransformRegDat2LTA(gtm->anatconf, gtm->rbvsegmasked, NULL); strcpy(gtm->anat2rbv->subject, gtm->anat2pet->subject); @@ -1169,7 +1193,8 @@ int GTMrbv(GTM *gtm) { include reducing the FoV of the rbv seg to a tight box around the brain. This is done in GTMrbv(). */ -int GTMrbvseg(GTM *gtm) { +int GTMrbvseg(GTM *gtm) +{ double res; LTA *new2seg; // *seg2new; // @@ -1202,7 +1227,8 @@ int GTMrbvseg(GTM *gtm) { registration is not needed. Use GTMrbv() instead since it manages memory much better and provides the same output. */ -int GTMrbv0(GTM *gtm) { +int GTMrbv0(GTM *gtm) +{ int c, r, s, f, nthseg, segid; double val, v, vhat0, vhat, v2; LTA *lta; @@ -1351,7 +1377,8 @@ int GTMrbv0(GTM *gtm) { cortex only, Target=2 means subcorticalgm only, Target=3 means both cortical and subcortical GM. Tissue type IDs are hard-coded. */ -int GTMmgxpvc(GTM *gtm, int Target) { +int GTMmgxpvc(GTM *gtm, int Target) +{ int nthseg, segid, r, tt, f; MATRIX *betaNotTarg, *yNotTarg, *ydiff; double sum; @@ -1406,7 +1433,8 @@ int GTMmgxpvc(GTM *gtm, int Target) { \brief Performs Muller-Gartner PVC. Hardcodes tissue type IDs to be frame0=cortex, frame1=subcortexgm, frame2=WM. */ -int GTMmgpvc(GTM *gtm) { +int GTMmgpvc(GTM *gtm) +{ int c, r, s, f; double vgmpsf, vwmpsf, vwmtac, vtac, vmgtac; // MRI *ctxpvf, *subctxpvf, *gmpvf; @@ -1477,7 +1505,8 @@ int GTMmgpvc(GTM *gtm) { } // Compute the MG reference TAC -int GTMmgRefTAC(GTM *gtm) { +int GTMmgRefTAC(GTM *gtm) +{ int f, nhits, n, found, nthseg, segid; double sum; @@ -1510,7 +1539,8 @@ int GTMmgRefTAC(GTM *gtm) { \brief Performs Meltzer PVC. Hardcodes tissue type IDs to be 0=cortex, 1=subcortexgm, 2=WM. */ -int GTMmeltzerpvc(GTM *gtm) { +int GTMmeltzerpvc(GTM *gtm) +{ int c, r, s, f, k, segid, nhits; double vgmwmpsf, v, sum; MRI *ctxpvf, *subctxpvf, *wmpvf, *gmwmpvf, *gmwmpvfpsf, *mritmp, *nhitseg; @@ -1599,7 +1629,8 @@ int GTMmeltzerpvc(GTM *gtm) { then exponentially distributed noise is added. The noisy volume is replicated nReps times with different noise in each rep. */ -int GTMsynth(GTM *gtm, int NoiseSeed, int nReps) { +int GTMsynth(GTM *gtm, int NoiseSeed, int nReps) +{ MATRIX *yhat; MRI *mritmp; @@ -1630,7 +1661,8 @@ int GTMsynth(GTM *gtm, int NoiseSeed, int nReps) { \brief Smooths the synthesized volume (ysynth) to create the ysynthsm vol. Should give the same result as X*beta. */ -int GTMsmoothSynth(GTM *gtm) { +int GTMsmoothSynth(GTM *gtm) +{ if (gtm->ysynth == NULL) GTMsynth(gtm, 0, 0); gtm->ysynthsm = MRIgaussianSmoothNI(gtm->ysynth, gtm->cStd, gtm->rStd, gtm->sStd, gtm->ysynthsm); if (gtm->UseMBrad) { @@ -1663,7 +1695,8 @@ int GTMsmoothSynth(GTM *gtm) { \fn int GTMcheckX(MATRIX *X) \brief Checks that all colums sum to 1 */ -int GTMcheckX(MATRIX *X) { +int GTMcheckX(MATRIX *X) +{ int r, c, count; double sum, d, dmax; @@ -1688,7 +1721,8 @@ int GTMcheckX(MATRIX *X) { \brief Builds the GTM design matrix both with (X) and without (X0) PSF. If gtm->DoVoxFracCor=1 then corrects for volume fraction effect. */ -int GTMbuildX(GTM *gtm) { +int GTMbuildX(GTM *gtm) +{ int nthseg, err; struct timeb timer; @@ -1809,7 +1843,8 @@ int GTMbuildX(GTM *gtm) { If frame < 0, then all frames are are computed. If frame >= 0, then synth will have only one frame reprsenting the passed frame. */ -MRI *GTMsegSynth(GTM *gtm, int frame, MRI *synth) { +MRI *GTMsegSynth(GTM *gtm, int frame, MRI *synth) +{ int c, r, s, f, segid, segno, nframes; if (frame < 0) @@ -1841,7 +1876,8 @@ MRI *GTMsegSynth(GTM *gtm, int frame, MRI *synth) { } if (frame < 0) { for (f = 0; f < gtm->beta->cols; f++) MRIsetVoxVal(synth, c, r, s, f, gtm->beta->rptr[segno + 1][f + 1]); - } else + } + else MRIsetVoxVal(synth, c, r, s, 0, gtm->beta->rptr[segno + 1][frame + 1]); } } @@ -1855,7 +1891,8 @@ MRI *GTMsegSynth(GTM *gtm, int frame, MRI *synth) { \fn int GTMprintMGRefTAC(GTM *gtm, FILE *fp) \brief Prints the Muller-Gartner WM reference TAC to the given file pointer */ -int GTMprintMGRefTAC(GTM *gtm, FILE *fp) { +int GTMprintMGRefTAC(GTM *gtm, FILE *fp) +{ int f; for (f = 0; f < gtm->yvol->nframes; f++) fprintf(fp, "%3d %10.5f\n", f, gtm->mg_reftac->rptr[f + 1][1]); @@ -1867,7 +1904,8 @@ int GTMprintMGRefTAC(GTM *gtm, FILE *fp) { \fn int GTMwriteMGRefTAC(GTM *gtm, char *filename) \brief Writes the Muller-Gartner WM reference TAC to the given file */ -int GTMwriteMGRefTAC(GTM *gtm, char *filename) { +int GTMwriteMGRefTAC(GTM *gtm, char *filename) +{ FILE *fp; fp = fopen(filename, "w"); GTMprintMGRefTAC(gtm, fp); @@ -1881,7 +1919,8 @@ int GTMwriteMGRefTAC(GTM *gtm, char *filename) { \brief Computes global rescaling factor and applies it to yvol, beta, and y. The factor = 100/mean(beta_i) where i is the list of scale seg IDs (scale_ref_ids) */ -int GTMrescale(GTM *gtm) { +int GTMrescale(GTM *gtm) +{ int f, n, nthseg, segid, found, nhits; double sum; @@ -1917,7 +1956,8 @@ int GTMrescale(GTM *gtm) { \fn int GTMsteadyState(GTM *gtm) \brief out = (in - ref)*dcf/(scale*bpc) */ -int GTMsteadyState(GTM *gtm) { +int GTMsteadyState(GTM *gtm) +{ int f, n, c, r, s; double v, y, ref; @@ -1950,7 +1990,8 @@ int GTMsteadyState(GTM *gtm) { \brief Computes a t-test for each contrast. This includes computing gamma, gammavar, t, and p. */ -int GTMttest(GTM *gtm) { +int GTMttest(GTM *gtm) +{ MATRIX *Ct, *CiXtX, *CiXtXCt; int n, f, nframes; GTMCON *gtmc; @@ -1985,7 +2026,8 @@ int GTMttest(GTM *gtm) { \brief Creates an ASCII file in the output folder for each contrast with gamma, gammavar, t, and p */ -int GTMwriteContrasts(GTM *gtm) { +int GTMwriteContrasts(GTM *gtm) +{ int n, nframes, f; GTMCON *gtmc; char tmpstr[5000]; @@ -2019,7 +2061,8 @@ int GTMwriteContrasts(GTM *gtm) { \brief Checks the segmentation IDs used for rescaling, MG, KM Ref, and KM HB to make sure that they are in the segmentation. */ -int GTMcheckRefIds(GTM *gtm) { +int GTMcheckRefIds(GTM *gtm) +{ int n, m, ok; if (gtm->rescale) { @@ -2098,7 +2141,8 @@ int GTMcheckRefIds(GTM *gtm) { \brief Prints the segmentation IDs used for rescaling, MG, KM Ref, and KM HB to the given FILE pointer. */ -int GTMprintRefIds(GTM *gtm, FILE *fp) { +int GTMprintRefIds(GTM *gtm, FILE *fp) +{ int n; if (gtm->rescale) { @@ -2133,7 +2177,8 @@ int GTMprintRefIds(GTM *gtm, FILE *fp) { to the output folder. The HB TAC is written as both an ascii file and a nii.gz (the later needed for KM analysis with mri_glmfit) */ -int GTMrefTAC(GTM *gtm) { +int GTMrefTAC(GTM *gtm) +{ int f, n, nthseg, segid; double sum; char tmpstr[5000]; @@ -2192,7 +2237,8 @@ int GTMrefTAC(GTM *gtm) { \fn int GTMprintReplaceList(FILE *fp, const int nReplace, const int *ReplaceThis, const int *WithThat) \brief Prints the replacement list to the FILE pointer. */ -int GTMprintReplaceList(FILE *fp, const int nReplace, const int *ReplaceThis, const int *WithThat) { +int GTMprintReplaceList(FILE *fp, const int nReplace, const int *ReplaceThis, const int *WithThat) +{ int n; for (n = 0; n < nReplace; n++) fprintf(fp, "%5d %5d\n", ReplaceThis[n], WithThat[n]); return (0); @@ -2203,7 +2249,8 @@ int GTMprintReplaceList(FILE *fp, const int nReplace, const int *ReplaceThis, co \brief Checks replacement list to make sure that no item in ReplaceThis list appears in the WithThat list. */ -int GTMcheckReplaceList(const int nReplace, const int *ReplaceThis, const int *WithThat) { +int GTMcheckReplaceList(const int nReplace, const int *ReplaceThis, const int *WithThat) +{ int n, m; for (n = 0; n < nReplace; n++) { for (m = 0; m < nReplace; m++) { @@ -2222,7 +2269,8 @@ int GTMcheckReplaceList(const int nReplace, const int *ReplaceThis, const int *W is the segmentation ID to replace the second is the segmentation ID to replace it with. It will ignore any line that begins with a #. */ -int GTMloadReplacmentList(const char *fname, int *nReplace, int *ReplaceThis, int *WithThat) { +int GTMloadReplacmentList(const char *fname, int *nReplace, int *ReplaceThis, int *WithThat) +{ FILE *fp; int nlist, r, nth; char tmpstr[1001], *s; @@ -2267,7 +2315,8 @@ int GTMloadReplacmentList(const char *fname, int *nReplace, int *ReplaceThis, in matrices. The header of the full FoV PET is kept in gtm->yvol_full_fov but the pixel data are freed to reduce storage. */ -int GTMautoMask(GTM *gtm) { +int GTMautoMask(GTM *gtm) +{ LTA *lta; double std; @@ -2302,7 +2351,8 @@ int GTMautoMask(GTM *gtm) { Also writes rvar.gm.dat in the output folder. The value is computed as the sum of res.^2 in GM divided by the number of GM voxels.x */ -int GTMrvarGM(GTM *gtm) { +int GTMrvarGM(GTM *gtm) +{ COLOR_TABLE *ct; int f, s, c, r, n, nhits, nhitsb, segid, tt; double sum, sumb; @@ -2392,7 +2442,8 @@ int GTMrvarGM(GTM *gtm) { tissue type in its own frame \param nrad defines neighborhood as (2*nrad+1)^3 voxels */ -MRI **GTMlocal(GTM *gtm, MRI **pvc) { +MRI **GTMlocal(GTM *gtm, MRI **pvc) +{ int c, tt, nTT, nvmax; struct timeb timer; MRI *pvfpsf; @@ -2587,7 +2638,8 @@ MRI **GTMlocal(GTM *gtm, MRI **pvc) { \brief Computes the percent of each tissue type contributing to each segmentation. */ -int GTMttPercent(GTM *gtm) { +int GTMttPercent(GTM *gtm) +{ int nTT, k, s, c, r, segid, nthseg, mthseg, mthsegid, tt; double sum; @@ -2633,7 +2685,8 @@ int GTMttPercent(GTM *gtm) { \fn int GTMsegid2nthseg(GTM *gtm, int segid) \breif Returns the nthseg of the given segid */ -int GTMsegid2nthseg(GTM *gtm, int segid) { +int GTMsegid2nthseg(GTM *gtm, int segid) +{ int nthseg, ok; ok = 0; for (nthseg = 0; nthseg < gtm->nsegs; nthseg++) { diff --git a/utils/gw_ic2562.c b/utils/gw_ic2562.c index f0e423b330f..a14d46feb1b 100644 --- a/utils/gw_ic2562.c +++ b/utils/gw_ic2562.c @@ -2025,7 +2025,8 @@ MRI_SURFACE *ic2562_make_two_icos(float x1, float y1, float z1, float r1, float //------------------------------------------------------ if (fno < ICO_NFACES) { vn = gw_ic2562_faces[fno].vno[n1] - 1; /* make it zero-based */ - } else { + } + else { vn = gw_ic2562_faces[fno - ICO_NFACES].vno[n1] - 1 + ICO_NVERTICES; /* make it zero-based */ } diff --git a/utils/gw_utils.c b/utils/gw_utils.c index 57d38ec874c..98109598df4 100644 --- a/utils/gw_utils.c +++ b/utils/gw_utils.c @@ -41,10 +41,8 @@ -- Zero-based vertex and face numbering -------------------------------------------------*/ -MRI_SURFACE *GWU_make_surface_from_lists(GWUTILS_VERTEX *vertices, - int vertexcount, - GWUTILS_FACE *faces, - int facecount) { +MRI_SURFACE *GWU_make_surface_from_lists(GWUTILS_VERTEX *vertices, int vertexcount, GWUTILS_FACE *faces, int facecount) +{ MRI_SURFACE *mris; int vno, fno, n, vn, n1, n2; VERTEX *v = NULL; @@ -181,7 +179,8 @@ MRI_SURFACE *GWU_make_surface_from_lists(GWUTILS_VERTEX *vertices, (because what to do when mht->vres is large?) just a way to read out the MHT data in 3D ---------------------------------------------------------*/ -MRI *MRIFromMHTandMRIS(MHT *mht, MRIS *mris, MFMM_Option_t mfmm_option) { +MRI *MRIFromMHTandMRIS(MHT *mht, MRIS *mris, MFMM_Option_t mfmm_option) +{ MRI *amri; int mhtvx, mhtvy, mhtvz; // MHT "voxels" int mrix, mriy, mriz; // MRI voxels @@ -260,7 +259,8 @@ static char local_Progversion[100] = "uninitialized"; static char local_Logfilepath[1000] = "uninitialized"; //---------------------------------------- -int gw_log_init(char *AProgname, char *AProgversion, char *ALogfilepath, int newfile) { // 0 for OK +int gw_log_init(char *AProgname, char *AProgversion, char *ALogfilepath, int newfile) +{ // 0 for OK //---------------------------------------- FILE *afile; int rslt = 0; @@ -269,20 +269,23 @@ int gw_log_init(char *AProgname, char *AProgversion, char *ALogfilepath, int new strcpy(local_Logfilepath, ALogfilepath); if (newfile) { afile = fopen(local_Logfilepath, "w"); - } else { + } + else { afile = fopen(local_Logfilepath, "a"); } if (afile) { fclose(afile); - } else { + } + else { rslt = 1; } return rslt; } //------------------------------ -void gw_log_message(char *msg) { +void gw_log_message(char *msg) +{ //------------------------------ FILE *afile; afile = fopen(local_Logfilepath, "a"); @@ -291,7 +294,8 @@ void gw_log_message(char *msg) { } //------------------------------ -static void nowstr(char *buf) { +static void nowstr(char *buf) +{ //------------------------------ time_t tim; struct tm *tmr; @@ -304,7 +308,8 @@ static void nowstr(char *buf) { } //------------------------------ -void gw_log_timestamp(char *label) { +void gw_log_timestamp(char *label) +{ //------------------------------ char datestr[100]; char msg[200]; @@ -315,13 +320,15 @@ void gw_log_timestamp(char *label) { } //------------------------------ -void gw_log_begin(void) { +void gw_log_begin(void) +{ //------------------------------ gw_log_timestamp("Begin"); } //------------------------------ -void gw_log_end(void) { +void gw_log_end(void) +{ //------------------------------ gw_log_timestamp("End"); } diff --git a/utils/handle.c b/utils/handle.c index 1c3ea38b2fa..ca7353b9e65 100644 --- a/utils/handle.c +++ b/utils/handle.c @@ -38,7 +38,8 @@ #ifndef Linux int not_used_000(void); -int not_used_000(void) { +int not_used_000(void) +{ int i; i = 0; return (i); @@ -71,7 +72,8 @@ MACROS AND CONSTANTS STRUCTURES ----------------------------------------------------------------------*/ -typedef struct { +typedef struct +{ void *ptr; int status; } HandleInfo; @@ -106,7 +108,8 @@ If the current handle space is used up, grow the handle table. the newly allocated handle. ----------------------------------------------------------------------*/ PTR_HANDLE -HandleAlloc(void *ptr) { +HandleAlloc(void *ptr) +{ HandleInfo *handleInfo; PTR_HANDLE handle; @@ -128,7 +131,8 @@ Free a previously allocated handle. Returns: nothing. ----------------------------------------------------------------------*/ -void HandleFree(PTR_HANDLE handle) { +void HandleFree(PTR_HANDLE handle) +{ HandleInfo *handleInfo; if (HandleOk(handle) <= 0) ESCAPE(ERROR_BADPARM, "HandleFree: bad handle %d", handle); @@ -148,7 +152,8 @@ turn a handle into the pointer which it reprents. Returns: the pointer which the handle represents. ----------------------------------------------------------------------*/ -void *HandleToPtr(PTR_HANDLE handle) { +void *HandleToPtr(PTR_HANDLE handle) +{ HandleInfo *handleInfo; if (HandleOk(handle) <= 0) ESCAPE(ERROR_BADPARM, "HandleToPtr: bad handle %d", handle); @@ -168,7 +173,8 @@ determine whether a handle is a valid one. -1 if the handle is ok and not allocated 0 if the handle is out of range. ----------------------------------------------------------------------*/ -int HandleOk(PTR_HANDLE handle) { +int HandleOk(PTR_HANDLE handle) +{ HandleInfo *handleInfo; if ((handle <= (PTR_HANDLE)0) || (handle > nhandles)) return (0); @@ -189,7 +195,8 @@ the current information into it. Returns: nothing. ----------------------------------------------------------------------*/ -static void growHandleTable(void) { +static void growHandleTable(void) +{ HandleInfo *newTable; int newMaxHandles = 0; diff --git a/utils/heap.c b/utils/heap.c index 45bdb82e822..4dafce636aa 100644 --- a/utils/heap.c +++ b/utils/heap.c @@ -25,7 +25,8 @@ /*--------------------------------------------------------------------------- // Construct an empty PGlist with specified capacity and capacity increment //-------------------------------------------------------------------------*/ -PGlist pgList2(int elementSize, int capacity, int capacityIncrement) { +PGlist pgList2(int elementSize, int capacity, int capacityIncrement) +{ PGlist list; void *data; @@ -58,7 +59,8 @@ PGlist pgList2(int elementSize, int capacity, int capacityIncrement) { // Construct an empty PGlist with specified capacity and default // capacity increment as 100 //-------------------------------------------------------------------------*/ -PGlist pgList1(int elementSize, int capacity) { +PGlist pgList1(int elementSize, int capacity) +{ PGlist list; list = pgList2(elementSize, capacity, 100); @@ -70,7 +72,8 @@ PGlist pgList1(int elementSize, int capacity) { // Construct an empty PGlist with default capacity as 0 and // capacity increment as 100 //-------------------------------------------------------------------------*/ -PGlist pgList(int elementSize) { +PGlist pgList(int elementSize) +{ PGlist list; list = pgList2(elementSize, 0, 100); @@ -82,7 +85,8 @@ PGlist pgList(int elementSize) { // Construct an empty PGlist with specified size, all the elements are set to // zero //-------------------------------------------------------------------------*/ -PGlist pgListOfSize(int size, int elementSize) { +PGlist pgListOfSize(int size, int elementSize) +{ PGlist list; char *data; int i; @@ -106,7 +110,8 @@ PGlist pgListOfSize(int size, int elementSize) { /*--------------------------------------------------------------------------- // Delete this list //-------------------------------------------------------------------------*/ -void pgListDelete(PGlist list) { +void pgListDelete(PGlist list) +{ void *data; data = pgListData(list); @@ -117,7 +122,8 @@ void pgListDelete(PGlist list) { /*--------------------------------------------------------------------------- // Add an element to this list //-------------------------------------------------------------------------*/ -void pgListAddElement(PGlist list, void *element) { +void pgListAddElement(PGlist list, void *element) +{ int size, capacity, elementSize, capacityIncrement; void *data; @@ -132,7 +138,8 @@ void pgListAddElement(PGlist list, void *element) { capacity += capacityIncrement; pgListSetCapacity(list, capacity); data = (void *)malloc(elementSize * capacity); - } else { + } + else { /* allocate a larger list */ capacity += capacityIncrement; pgListSetCapacity(list, capacity); @@ -148,7 +155,8 @@ void pgListAddElement(PGlist list, void *element) { /*--------------------------------------------------------------------------- // Insert an element into the list at the specified index //-------------------------------------------------------------------------*/ -int pgListInsertElementAt(PGlist list, int index, void *element) { +int pgListInsertElementAt(PGlist list, int index, void *element) +{ int size, elementSize; void *data; void *tempPtr; @@ -181,7 +189,8 @@ int pgListInsertElementAt(PGlist list, int index, void *element) { /*--------------------------------------------------------------------------- // Retrieve an element from this list at a given index //-------------------------------------------------------------------------*/ -int pgListElementAt(PGlist list, int index, void *element) { +int pgListElementAt(PGlist list, int index, void *element) +{ int size, elementSize; void *data; @@ -200,7 +209,8 @@ int pgListElementAt(PGlist list, int index, void *element) { /*--------------------------------------------------------------------------- // Sets a list element at a given index //-------------------------------------------------------------------------*/ -int pgListSetElementAt(PGlist list, int index, void *element) { +int pgListSetElementAt(PGlist list, int index, void *element) +{ int size, elementSize; void *data; @@ -220,7 +230,8 @@ int pgListSetElementAt(PGlist list, int index, void *element) { /*--------------------------------------------------------------------------- // Removes all elements from this list and sets its size to zero //-------------------------------------------------------------------------*/ -int pgListRemoveElementAt(PGlist list, int index) { +int pgListRemoveElementAt(PGlist list, int index) +{ int size, elementSize; void *data; char *currentPtr, *nextPtr; @@ -253,7 +264,8 @@ void pgListRemoveAllElements(PGlist list) { pgListSetSize(list, 0); } /*--------------------------------------------------------------------------- // Trim this list to current size //-------------------------------------------------------------------------*/ -void pgListTrim(PGlist list) { +void pgListTrim(PGlist list) +{ void *data; int size, elementSize; @@ -266,7 +278,8 @@ void pgListTrim(PGlist list) { pgListSetCapacity(list, size); } -void pgListInfo(PGlist list) { +void pgListInfo(PGlist list) +{ int elementSize, size, capacity, capacityIncrement; elementSize = pgListElementSize(list); @@ -281,7 +294,8 @@ void pgListInfo(PGlist list) { printf("\n"); } -Xheap xhInitEmpty() { +Xheap xhInitEmpty() +{ Xheap H; XheapElement he; @@ -298,7 +312,8 @@ Xheap xhInitEmpty() { return (H); } -Xheap xhInit(XheapElement *array, int N) { +Xheap xhInit(XheapElement *array, int N) +{ Xheap H; XheapElement *data, he; int i, *p; @@ -326,7 +341,8 @@ Xheap xhInit(XheapElement *array, int N) { /* destroy the heap and free the memory */ void xhDestroy(Xheap H) { pgListDelete(H); } -int xhUpHeap(int k, Xheap H) { +int xhUpHeap(int k, Xheap H) +{ XheapElement *a, v; int k_father; int *p; @@ -349,7 +365,8 @@ int xhUpHeap(int k, Xheap H) { return (k); } -int xhDownHeap(int k, Xheap H) { +int xhDownHeap(int k, Xheap H) +{ XheapElement *a, v; int N, k_minson; int *p; @@ -376,7 +393,8 @@ int xhDownHeap(int k, Xheap H) { return (k); } -int xhInsert(double value, int id, int *p, Xheap H) { +int xhInsert(double value, int id, int *p, Xheap H) +{ // XheapElement *a; XheapElement v; int N, k; @@ -395,7 +413,8 @@ int xhInsert(double value, int id, int *p, Xheap H) { } /* remove the smallest element */ -XheapElement xhRemove(Xheap H) { +XheapElement xhRemove(Xheap H) +{ XheapElement v, *a; int N; @@ -415,7 +434,8 @@ XheapElement xhRemove(Xheap H) { /* replace the smallest value with a new value if the new value is smaller otherwise the new value is returned and the heap is unchanged */ -XheapElement xhReplace(double value, int id, int *p, Xheap H) { +XheapElement xhReplace(double value, int id, int *p, Xheap H) +{ XheapElement *a, v; a = (XheapElement *)pgListData(H); @@ -426,7 +446,8 @@ XheapElement xhReplace(double value, int id, int *p, Xheap H) { a[1].id = id; a[1].p = p; xhDownHeap(1, H); - } else { + } + else { v.value = value; v.id = id; v.p = p; @@ -435,7 +456,8 @@ XheapElement xhReplace(double value, int id, int *p, Xheap H) { } /* delete an item in the heap and its value is returned */ -XheapElement xhDelete(int k, Xheap H) { +XheapElement xhDelete(int k, Xheap H) +{ XheapElement *a, v; int N; @@ -455,7 +477,8 @@ XheapElement xhDelete(int k, Xheap H) { } /* change the value of an item and its original value is returned */ -XheapElement xhChange(int k, double value, int id, int *p, Xheap H) { +XheapElement xhChange(int k, double value, int id, int *p, Xheap H) +{ XheapElement *a, v; a = (XheapElement *)pgListData(H); @@ -475,7 +498,8 @@ XheapElement xhChange(int k, double value, int id, int *p, Xheap H) { } /* change the value of an item and its original value is returned */ -XheapElement xhChangeValue(int k, double value, Xheap H) { +XheapElement xhChangeValue(int k, double value, Xheap H) +{ XheapElement *a, v; a = (XheapElement *)pgListData(H); @@ -492,7 +516,8 @@ XheapElement xhChangeValue(int k, double value, Xheap H) { return (v); } -XheapElement xhGet(int k, Xheap H) { +XheapElement xhGet(int k, Xheap H) +{ XheapElement v; pgListElementAt(H, k, &v); diff --git a/utils/hippo.c b/utils/hippo.c index c0429106a8a..d0e3efd7804 100644 --- a/utils/hippo.c +++ b/utils/hippo.c @@ -34,7 +34,8 @@ static int non_hippo_labels[] = { }; #define NUM_NON_HIPPO_LABELS (sizeof(non_hippo_labels) / sizeof(non_hippo_labels[0])) -MRI *HIPPOremoveNonHippoLabels(MRI *mri_src, MRI *mri_dst) { +MRI *HIPPOremoveNonHippoLabels(MRI *mri_src, MRI *mri_dst) +{ int i, label; mri_dst = MRIcopy(mri_src, mri_dst); @@ -45,7 +46,8 @@ MRI *HIPPOremoveNonHippoLabels(MRI *mri_src, MRI *mri_dst) { } return (mri_dst); } -MRI *HIPPOestimateIntensityImage(MRI *mri_hippo_labels, MRI *mri_aseg, MRI *mri_intensity, MRI *mri_dst) { +MRI *HIPPOestimateIntensityImage(MRI *mri_hippo_labels, MRI *mri_aseg, MRI *mri_intensity, MRI *mri_dst) +{ GCAM_LABEL_TRANSLATION_TABLE gcam_ltt; int i, x, y, z, in_label, out_label; diff --git a/utils/histo.c b/utils/histo.c index a3f0eee8415..ca3d43867b4 100644 --- a/utils/histo.c +++ b/utils/histo.c @@ -47,7 +47,8 @@ Description ------------------------------------------------------*/ -int HISTOfree(HISTOGRAM **phisto) { +int HISTOfree(HISTOGRAM **phisto) +{ HISTOGRAM *histo; histo = *phisto; @@ -56,15 +57,18 @@ int HISTOfree(HISTOGRAM **phisto) { if (histo->bins) { free(histo->bins); histo->bins = NULL; - } else + } + else DiagBreak(); if (histo->counts) { free(histo->counts); histo->counts = NULL; - } else + } + else DiagBreak(); free(histo); - } else + } + else DiagBreak(); return (NO_ERROR); @@ -77,7 +81,8 @@ int HISTOfree(HISTOGRAM **phisto) { Description ------------------------------------------------------*/ -int HISTOdump(HISTOGRAM *histo, FILE *fp) { +int HISTOdump(HISTOGRAM *histo, FILE *fp) +{ int bin_no; if (!histo) @@ -91,7 +96,8 @@ int HISTOdump(HISTOGRAM *histo, FILE *fp) { return (NO_ERROR); } -HISTOGRAM *HISTOrealloc(HISTOGRAM *histo, int nbins) { +HISTOGRAM *HISTOrealloc(HISTOGRAM *histo, int nbins) +{ if (histo == NULL) return (HISTOalloc(nbins)); if (histo->bins) free(histo->bins); @@ -112,7 +118,8 @@ HISTOGRAM *HISTOrealloc(HISTOGRAM *histo, int nbins) { Description ------------------------------------------------------*/ -HISTOGRAM *HISTOalloc(int nbins) { +HISTOGRAM *HISTOalloc(int nbins) +{ HISTOGRAM *histo; histo = (HISTOGRAM *)calloc(1, sizeof(HISTOGRAM)); @@ -134,7 +141,8 @@ HISTOGRAM *HISTOalloc(int nbins) { Description ------------------------------------------------------*/ -HISTOGRAM *HISTOcrunch(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOcrunch(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) +{ int b, deleted; if (!histo_dst) histo_dst = HISTOalloc(histo_src->nbins); @@ -161,7 +169,8 @@ HISTOGRAM *HISTOcrunch(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { Description ------------------------------------------------------*/ -HISTOGRAM *HISTOcopy(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOcopy(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) +{ if (!histo_dst) histo_dst = HISTOalloc(histo_src->nbins); histo_dst->nbins = histo_src->nbins; histo_dst->bin_size = histo_src->bin_size; @@ -183,7 +192,8 @@ HISTOGRAM *HISTOcopy(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { Treat histo_src as a function mapping input intensities to output intensities, and numerically invert it. ------------------------------------------------------*/ -HISTOGRAM *HISTOinvert(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int max_dst) { +HISTOGRAM *HISTOinvert(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int max_dst) +{ int b, bdst, val, max_count; histo_dst = HISTOclear(histo_src, histo_dst); @@ -227,7 +237,8 @@ HISTOGRAM *HISTOinvert(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int max_dst) Description ------------------------------------------------------*/ -HISTOGRAM *HISTOnormalize(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int max_out) { +HISTOGRAM *HISTOnormalize(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int max_out) +{ int max_count, b; float scale; @@ -251,7 +262,8 @@ HISTOGRAM *HISTOnormalize(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int max_ou Description ------------------------------------------------------*/ -HISTOGRAM *HISTOclear(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOclear(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) +{ if (!histo_dst) histo_dst = HISTOalloc(histo_src->nbins); memset(histo_dst->counts, 0, histo_dst->nbins * sizeof(*histo_dst->counts)); @@ -267,7 +279,8 @@ HISTOGRAM *HISTOclear(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { Description ------------------------------------------------------*/ -HISTOGRAM *HISTOclearCounts(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOclearCounts(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) +{ if (!histo_dst) { histo_dst = HISTOalloc(histo_src->nbins); memmove(histo_dst->bins, histo_src->bins, sizeof(*histo_src->bins)); @@ -289,7 +302,8 @@ HISTOGRAM *HISTOclearCounts(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { mappings into a composite transformation (first histo1 then histo2). ------------------------------------------------------*/ -HISTOGRAM *HISTOcompose(HISTOGRAM *histo1, HISTOGRAM *histo2, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOcompose(HISTOGRAM *histo1, HISTOGRAM *histo2, HISTOGRAM *histo_dst) +{ int b, val; if (!histo_dst) histo_dst = HISTOalloc(histo1->nbins); @@ -310,7 +324,8 @@ HISTOGRAM *HISTOcompose(HISTOGRAM *histo1, HISTOGRAM *histo2, HISTOGRAM *histo_d Description ------------------------------------------------------*/ -HISTOGRAM *HISTOfillZeros(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOfillZeros(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) +{ int b, val; histo_dst = HISTOcopy(histo_src, histo_dst); @@ -342,7 +357,8 @@ HISTOGRAM *HISTOfillZeros(HISTOGRAM *histo_src, HISTOGRAM *histo_dst) { ------------------------------------------------------*/ #define MAX_STRETCH 2 -HISTOGRAM *HISTOcomposeInvert(HISTOGRAM *histo_fwd, HISTOGRAM *histo_inv, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOcomposeInvert(HISTOGRAM *histo_fwd, HISTOGRAM *histo_inv, HISTOGRAM *histo_dst) +{ int b, binv, val, max_fwd, max_inv, stretch; float ffwd, next = 0.0f, prev; @@ -387,7 +403,8 @@ HISTOGRAM *HISTOcomposeInvert(HISTOGRAM *histo_fwd, HISTOGRAM *histo_inv, HISTOG Description ------------------------------------------------------*/ -HISTOGRAM *HISTOadd(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOadd(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) +{ int b; float *pc1, *pc2, *pcdst; @@ -398,7 +415,8 @@ HISTOGRAM *HISTOadd(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) { histo_dst->max = h1->max; histo_dst->bin_size = h1->bin_size; if (h2 == NULL) h2 = histo_dst; - } else + } + else histo_dst->nbins = h1->nbins; pc1 = &h1->counts[0]; @@ -416,7 +434,8 @@ HISTOGRAM *HISTOadd(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) { Description ------------------------------------------------------*/ -HISTOGRAM *HISTOmul(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOmul(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) +{ int b; float *pc1, *pc2, *pcdst; @@ -440,7 +459,8 @@ HISTOGRAM *HISTOmul(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) { Description ------------------------------------------------------*/ -HISTOGRAM *HISTOsubtract(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) { +HISTOGRAM *HISTOsubtract(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) +{ int b; float *pc1, *pc2, *pcdst; @@ -464,7 +484,8 @@ HISTOGRAM *HISTOsubtract(HISTOGRAM *h1, HISTOGRAM *h2, HISTOGRAM *histo_dst) { Description ------------------------------------------------------*/ -HISTOGRAM *HISTOclearBins(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int min_val, int max_val) { +HISTOGRAM *HISTOclearBins(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int min_val, int max_val) +{ int b; if (!histo_src) return (NULL); @@ -488,7 +509,8 @@ HISTOGRAM *HISTOclearBins(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, int min_va Description ------------------------------------------------------*/ #define MAX_LEN 2000 -HISTOGRAM *HISTOsmooth(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, float sigma) { +HISTOGRAM *HISTOsmooth(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, float sigma) +{ float norm, two_sigma, fx, k, kernel[MAX_LEN], total; int x, half, len, b, kx, b1, nbins; @@ -496,7 +518,8 @@ HISTOGRAM *HISTOsmooth(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, float sigma) if (!histo_dst) { histo_dst = HISTOcopy(histo_src, NULL); HISTOclearCounts(histo_dst, histo_dst); - } else { + } + else { if (histo_dst->nbins < histo_src->nbins) { // fprintf(stderr, "realloc: histo_dst->nbins = %d, " //"histo_src->nbins = %d\n", @@ -553,7 +576,8 @@ HISTOGRAM *HISTOsmooth(HISTOGRAM *histo_src, HISTOGRAM *histo_dst, float sigma) Description ------------------------------------------------------*/ -int HISTOfindLastPeakRelative(HISTOGRAM *h, int wsize, float min_pct) { +int HISTOfindLastPeakRelative(HISTOGRAM *h, int wsize, float min_pct) +{ int peak, b, bw, nbins, whalf, other_val; float max_count, min_count, center_val; @@ -591,7 +615,8 @@ int HISTOfindLastPeakRelative(HISTOGRAM *h, int wsize, float min_pct) { Description ------------------------------------------------------*/ -int HISTOfindFirstPeakRelative(HISTOGRAM *h, int wsize, float min_pct) { +int HISTOfindFirstPeakRelative(HISTOGRAM *h, int wsize, float min_pct) +{ int peak, b, bw, nbins, whalf, other_val; float max_count, min_count, center_val; @@ -629,7 +654,8 @@ int HISTOfindFirstPeakRelative(HISTOGRAM *h, int wsize, float min_pct) { Description ------------------------------------------------------*/ -int HISTOfindLastPeak(HISTOGRAM *h, int wsize, float min_pct) { +int HISTOfindLastPeak(HISTOGRAM *h, int wsize, float min_pct) +{ int peak, b, bw, nbins, whalf; float min_count, max_count, center_val, other_val; @@ -670,7 +696,8 @@ int HISTOfindLastPeak(HISTOGRAM *h, int wsize, float min_pct) { Description ------------------------------------------------------*/ -int HISTOfindFirstPeak(HISTOGRAM *h, int wsize, float min_pct) { +int HISTOfindFirstPeak(HISTOGRAM *h, int wsize, float min_pct) +{ int peak, b, bw, nbins, whalf; float center_val, max_count, other_val, min_count; @@ -715,7 +742,8 @@ int HISTOfindFirstPeak(HISTOGRAM *h, int wsize, float min_pct) { Description ------------------------------------------------------*/ -int HISTOfindValley(HISTOGRAM *h, int wsize, int I0, int I1) { +int HISTOfindValley(HISTOGRAM *h, int wsize, int I0, int I1) +{ int valley, b, bw, nbins, whalf, center_val, max_count, other_val, b0, b1; // find max, and find bins corresponding to I0 and I1 @@ -765,7 +793,8 @@ int HISTOfindValley(HISTOGRAM *h, int wsize, int I0, int I1) { */ #define MIN_STD 1.9 -int HISTOfindLastPeakInRegion(HISTOGRAM *h, int wsize, float min_pct, int I0, int I1) { +int HISTOfindLastPeakInRegion(HISTOGRAM *h, int wsize, float min_pct, int I0, int I1) +{ int peak, b, bw, nbins, whalf, b0, b1; float mean_count, min_count, max_count, other_val, center_val, total; @@ -820,7 +849,8 @@ int HISTOfindLastPeakInRegion(HISTOGRAM *h, int wsize, float min_pct, int I0, in Description ------------------------------------------------------*/ -int HISTOfindFirstPeakInRegion(HISTOGRAM *h, int wsize, float min_pct, int b0, int b1) { +int HISTOfindFirstPeakInRegion(HISTOGRAM *h, int wsize, float min_pct, int b0, int b1) +{ int peak, b, bw, nbins, whalf; float center_val, max_count, other_val, min_count, total; @@ -862,7 +892,8 @@ int HISTOfindFirstPeakInRegion(HISTOGRAM *h, int wsize, float min_pct, int b0, i Description ------------------------------------------------------*/ -int HISTOfindHighestPeakInRegion(HISTOGRAM *h, int b0, int b1) { +int HISTOfindHighestPeakInRegion(HISTOGRAM *h, int b0, int b1) +{ // int nbins; int b, max_count_bin; float val, max_count; @@ -895,7 +926,8 @@ int HISTOfindHighestPeakInRegion(HISTOGRAM *h, int b0, int b1) { Description ------------------------------------------------------*/ -int HISTOplot(HISTOGRAM *histo, char *fname) { +int HISTOplot(HISTOGRAM *histo, char *fname) +{ FILE *fp; int bin_no, bmin, bmax; @@ -919,7 +951,8 @@ int HISTOplot(HISTOGRAM *histo, char *fname) { the standard deviation of the peak around it's mean must be at least two or above. */ -int HISTOcountPeaksInRegion(HISTOGRAM *h, int wsize, float min_pct, int *peaks, int max_peaks, int b0, int b1) { +int HISTOcountPeaksInRegion(HISTOGRAM *h, int wsize, float min_pct, int *peaks, int max_peaks, int b0, int b1) +{ int npeaks = 0, peak_index; do { @@ -931,7 +964,8 @@ int HISTOcountPeaksInRegion(HISTOGRAM *h, int wsize, float min_pct, int *peaks, return (npeaks); } -int HISTOaddSample(HISTOGRAM *histo, float val, float bmin, float bmax) { +int HISTOaddSample(HISTOGRAM *histo, float val, float bmin, float bmax) +{ int bin_no; float bin_size; @@ -940,7 +974,8 @@ int HISTOaddSample(HISTOGRAM *histo, float val, float bmin, float bmax) { bmin = histo->min; bmax = histo->max; bin_size = histo->bin_size; - } else + } + else bin_size = (bmax - bmin) / ((float)histo->nbins - 1); bin_no = nint((val - bmin) / bin_size); @@ -956,7 +991,8 @@ int HISTOaddSample(HISTOGRAM *histo, float val, float bmin, float bmax) { return (bin_no); } -int HISTOaddFractionalSample(HISTOGRAM *histo, float val, float bmin, float bmax, float frac) { +int HISTOaddFractionalSample(HISTOGRAM *histo, float val, float bmin, float bmax, float frac) +{ int bin_no; float bin_size; @@ -965,7 +1001,8 @@ int HISTOaddFractionalSample(HISTOGRAM *histo, float val, float bmin, float bmax bmin = histo->min; bmax = histo->max; bin_size = histo->bin_size; - } else + } + else bin_size = (bmax - bmin) / ((float)histo->nbins - 1); bin_no = nint((val - bmin) / bin_size); @@ -977,7 +1014,8 @@ int HISTOaddFractionalSample(HISTOGRAM *histo, float val, float bmin, float bmax return (bin_no); } -int HISTOfindPreviousValley(HISTOGRAM *h, int b0) { +int HISTOfindPreviousValley(HISTOGRAM *h, int b0) +{ int b; float prev_val, val; @@ -992,7 +1030,8 @@ int HISTOfindPreviousValley(HISTOGRAM *h, int b0) { return (-1); } -int HISTOfindNextValley(HISTOGRAM *h, int b0) { +int HISTOfindNextValley(HISTOGRAM *h, int b0) +{ int b; float prev_val, val; @@ -1007,7 +1046,8 @@ int HISTOfindNextValley(HISTOGRAM *h, int b0) { return (-1); } -int HISTOfindNextPeak(HISTOGRAM *h, int b0, int whalf) { +int HISTOfindNextPeak(HISTOGRAM *h, int b0, int whalf) +{ int b, bk, peak = 0; float val; @@ -1025,7 +1065,8 @@ int HISTOfindNextPeak(HISTOGRAM *h, int b0, int whalf) { return (peak ? b : -1); } -int HISTOfindPreviousPeak(HISTOGRAM *h, int b0, int whalf) { +int HISTOfindPreviousPeak(HISTOGRAM *h, int b0, int whalf) +{ int b, bk, peak = 0; float val; @@ -1043,7 +1084,8 @@ int HISTOfindPreviousPeak(HISTOGRAM *h, int b0, int whalf) { return (peak ? b : -1); } -int HISTOfindStartOfPeak(HISTOGRAM *h, int b0, float pct_peak) { +int HISTOfindStartOfPeak(HISTOGRAM *h, int b0, float pct_peak) +{ int b, b1; float val, thresh; @@ -1059,7 +1101,8 @@ int HISTOfindStartOfPeak(HISTOGRAM *h, int b0, float pct_peak) { return (b); } -int HISTOfindEndOfPeak(HISTOGRAM *h, int b0, float pct_peak) { +int HISTOfindEndOfPeak(HISTOGRAM *h, int b0, float pct_peak) +{ int b, b1; float val, thresh; @@ -1076,7 +1119,8 @@ int HISTOfindEndOfPeak(HISTOGRAM *h, int b0, float pct_peak) { return (b); } -int HISTOfindCurrentPeak(HISTOGRAM *histo, int b0, int wsize, float min_pct) { +int HISTOfindCurrentPeak(HISTOGRAM *histo, int b0, int wsize, float min_pct) +{ int b, whalf, bw, peak, nbins = histo->nbins; float next_count, prev_count, other_val, center_val; float max_count, min_count; @@ -1121,7 +1165,8 @@ int HISTOfindCurrentPeak(HISTOGRAM *histo, int b0, int wsize, float min_pct) { return (b); } } - } else /* search backwards */ + } + else /* search backwards */ { for (b = b0; b >= 0; b--) { if (b >= histo->nbins) continue; @@ -1151,7 +1196,8 @@ int HISTOfindCurrentPeak(HISTOGRAM *histo, int b0, int wsize, float min_pct) { return (-1); } -int HISTOfillHoles(HISTO *h) { +int HISTOfillHoles(HISTO *h) +{ int b, min_b, max_b, *filled, niter; double max_change, new_val, change; @@ -1191,7 +1237,8 @@ int HISTOfillHoles(HISTO *h) { return (NO_ERROR); } -float HISTOtotalInRegion(HISTO *h, int b0, int b1) { +float HISTOtotalInRegion(HISTO *h, int b0, int b1) +{ int b; float total = 0.0; @@ -1204,7 +1251,8 @@ float HISTOtotalInRegion(HISTO *h, int b0, int b1) { float HISTOtotal(HISTO *h) { return HISTOtotalInRegion(h, 0, h->nbins - 1); } -int HISTOclearZeroBin(HISTOGRAM *h) { +int HISTOclearZeroBin(HISTOGRAM *h) +{ int b; if (h->bins[0] > h->bin_size) // zero bin not in range @@ -1217,7 +1265,8 @@ int HISTOclearZeroBin(HISTOGRAM *h) { return (NO_ERROR); } -int HISTOfindBinWithCount(HISTOGRAM *h, float val) { +int HISTOfindBinWithCount(HISTOGRAM *h, float val) +{ int b, min_b; double min_dist, dist; @@ -1234,7 +1283,8 @@ int HISTOfindBinWithCount(HISTOGRAM *h, float val) { return (min_b); } -int HISTOfindBin(HISTOGRAM *h, float val) { +int HISTOfindBin(HISTOGRAM *h, float val) +{ int b; if (h->bin_size == 1) return ((int)val - h->bins[0]); @@ -1244,7 +1294,8 @@ int HISTOfindBin(HISTOGRAM *h, float val) { return (0); } -double HISTOgetCount(HISTOGRAM *h, float bin_val) { +double HISTOgetCount(HISTOGRAM *h, float bin_val) +{ int b; b = HISTOfindBin(h, bin_val); @@ -1252,7 +1303,8 @@ double HISTOgetCount(HISTOGRAM *h, float bin_val) { return (h->counts[b]); } -HISTO *HISTOclearBG(HISTOGRAM *hsrc, HISTOGRAM *hdst, int *pbg_end) { +HISTO *HISTOclearBG(HISTOGRAM *hsrc, HISTOGRAM *hdst, int *pbg_end) +{ int b0, nv; float min_count; @@ -1271,7 +1323,8 @@ HISTO *HISTOclearBG(HISTOGRAM *hsrc, HISTOGRAM *hdst, int *pbg_end) { return (hdst); } -double HISTOcorrelate(HISTOGRAM *h1, HISTOGRAM *h2) { +double HISTOcorrelate(HISTOGRAM *h1, HISTOGRAM *h2) +{ int b1, b2, h2_done[256]; double correlation, c1, c2, norm1, norm2; @@ -1298,7 +1351,8 @@ double HISTOcorrelate(HISTOGRAM *h1, HISTOGRAM *h2) { return (correlation); } -static double histoComputeLinearFitCorrelation(HISTOGRAM *h1, HISTOGRAM *h2, double a, double b) { +static double histoComputeLinearFitCorrelation(HISTOGRAM *h1, HISTOGRAM *h2, double a, double b) +{ // this one uses correlation instead of SSE, and should be more robust! int b1, b2; double correlation, c1, c2; @@ -1331,7 +1385,8 @@ static double histoComputeLinearFitCorrelation(HISTOGRAM *h1, HISTOGRAM *h2, dou #define NSTEPS 1000 double HISTOfindLinearFit( - HISTOGRAM *h1, HISTOGRAM *h2, double amin, double amax, double bmin, double bmax, float *pa, float *pb) { + HISTOGRAM *h1, HISTOGRAM *h2, double amin, double amax, double bmin, double bmax, float *pa, float *pb) +{ double a, b, correlation, best_correlation, best_a, best_b, astep, bstep; best_correlation = histoComputeLinearFitCorrelation(h1, h2, 1.0, 0.0); @@ -1357,7 +1412,8 @@ double HISTOfindLinearFit( return (best_correlation); } -HISTO *HISTOlinearScale(HISTOGRAM *hsrc, HISTOGRAM *hdst, float scale, float offset) { +HISTO *HISTOlinearScale(HISTOGRAM *hsrc, HISTOGRAM *hdst, float scale, float offset) +{ int b; hdst = HISTOcopy(hsrc, hdst); @@ -1370,7 +1426,8 @@ HISTO *HISTOlinearScale(HISTOGRAM *hsrc, HISTOGRAM *hdst, float scale, float off return (hdst); } -float HISTOthreshSum(HISTOGRAM *h_mask, HISTOGRAM *h_src, float m_thresh) { +float HISTOthreshSum(HISTOGRAM *h_mask, HISTOGRAM *h_src, float m_thresh) +{ int b; float total; @@ -1381,7 +1438,8 @@ float HISTOthreshSum(HISTOGRAM *h_mask, HISTOGRAM *h_src, float m_thresh) { return (total); } -HISTOGRAM *HISTOmakePDF(HISTO *h_src, HISTO *h_dst) { +HISTOGRAM *HISTOmakePDF(HISTO *h_src, HISTO *h_dst) +{ int b; float total; @@ -1403,7 +1461,8 @@ HISTOGRAM *HISTOmakePDF(HISTO *h_src, HISTO *h_dst) { between min and max. The first bin is centered at min. The last bin is centered at max. This makes the bin size (max-min)/(nbins-1). -------------------------------------------------------------------*/ -HISTO *HISTObins(int nbins, double min, double max) { +HISTO *HISTObins(int nbins, double min, double max) +{ HISTO *h; int n; @@ -1420,7 +1479,8 @@ HISTO *HISTObins(int nbins, double min, double max) { HISTOcount() - builds histogram based on samples. Must have already allocated hist and set bin centers. -------------------------------------------------------------------*/ -int HISTOcount(HISTO *h, double *samples, int nsamples) { +int HISTOcount(HISTO *h, double *samples, int nsamples) +{ int n, bin; for (n = 0; n < nsamples; n++) { @@ -1435,7 +1495,8 @@ int HISTOcount(HISTO *h, double *samples, int nsamples) { HISTOvalToBin() - returns the histogram bin number for the given value. ----------------------------------------------------------*/ -int HISTOvalToBin(HISTO *h, double val) { +int HISTOvalToBin(HISTO *h, double val) +{ int bin, nthbin; double d, dmin; @@ -1452,14 +1513,16 @@ int HISTOvalToBin(HISTO *h, double val) { return (bin); } -int HISTOvalToBinDirect(HISTOGRAM *histo, float val) { +int HISTOvalToBinDirect(HISTOGRAM *histo, float val) +{ int bin_no; bin_no = nint((float)(val - histo->min) / (float)histo->bin_size); return (bin_no); } -float HISTOvalToCount(HISTOGRAM *histo, float val) { +float HISTOvalToCount(HISTOGRAM *histo, float val) +{ int bin_no; if (histo == NULL) return (0.0); bin_no = nint((float)(val - histo->min) / (float)histo->bin_size); @@ -1467,7 +1530,8 @@ float HISTOvalToCount(HISTOGRAM *histo, float val) { return (histo->counts[bin_no]); } -HISTOGRAM *HISTOinit(HISTOGRAM *h, int nbins, double mn, double mx) { +HISTOGRAM *HISTOinit(HISTOGRAM *h, int nbins, double mn, double mx) +{ int b; if (h == NULL) @@ -1489,7 +1553,8 @@ HISTOGRAM *HISTOinit(HISTOGRAM *h, int nbins, double mn, double mx) { return (h); } -int HISTOwriteInto(HISTOGRAM *h, FILE *fp) { +int HISTOwriteInto(HISTOGRAM *h, FILE *fp) +{ int b; fwriteInt(h->nbins, fp); @@ -1502,7 +1567,8 @@ int HISTOwriteInto(HISTOGRAM *h, FILE *fp) { return (NO_ERROR); } -HISTOGRAM *HISTOreadFrom(FILE *fp) { +HISTOGRAM *HISTOreadFrom(FILE *fp) +{ int b, nbins; HISTOGRAM *h; @@ -1516,7 +1582,8 @@ HISTOGRAM *HISTOreadFrom(FILE *fp) { for (b = 0; b < h->nbins; b++) h->counts[b] = freadFloat(fp); return (h); } -double HISTOfindMedian(HISTOGRAM *h) { +double HISTOfindMedian(HISTOGRAM *h) +{ double median, total, total2; int b; @@ -1538,7 +1605,8 @@ double HISTOfindMedian(HISTOGRAM *h) { return (median); } -HISTOGRAM *HISTOmakeReverseCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) { +HISTOGRAM *HISTOmakeReverseCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) +{ int b, b2; double total = 0; HISTOGRAM *habs; @@ -1551,7 +1619,8 @@ HISTOGRAM *HISTOmakeReverseCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) { for (total = 0.0, b2 = habs->nbins - 1; b2 >= 0; b2--) if (fabs(habs->bins[b2]) >= hdst->bins[b]) total += habs->counts[b2]; hdst->counts[b] = total; - } else + } + else hdst->counts[b] = 0; } @@ -1560,7 +1629,8 @@ HISTOGRAM *HISTOmakeReverseCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) { HISTOfree(&habs); return (hdst); } -HISTOGRAM *HISTOmakeCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) { +HISTOGRAM *HISTOmakeCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) +{ int b, b2; double total = 0; HISTOGRAM *habs; @@ -1573,7 +1643,8 @@ HISTOGRAM *HISTOmakeCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) { for (total = 0.0, b2 = 0; b2 < habs->nbins; b2++) if (fabs(habs->bins[b2]) <= hdst->bins[b]) total += habs->counts[b2]; hdst->counts[b] = total; - } else + } + else hdst->counts[b] = 0; } @@ -1583,7 +1654,8 @@ HISTOGRAM *HISTOmakeCDF(HISTOGRAM *hsrc, HISTOGRAM *hdst) { return (hdst); } -int HISTOrobustGaussianFit(HISTOGRAM *h, double max_percentile, double *poffset, double *psigma) { +int HISTOrobustGaussianFit(HISTOGRAM *h, double max_percentile, double *poffset, double *psigma) +{ int peak, bin, min_bin, max_bin, zbin, n; HISTOGRAM *habs, *hcdf, *hz, *hs; double thresh, sigma, delta_sigma, max_sigma, predicted_val, val, sqrt_2pi, sse, best_sigma, best_sse, error, scale, @@ -1610,7 +1682,8 @@ int HISTOrobustGaussianFit(HISTOGRAM *h, double max_percentile, double *poffset, if (bin < 0) { bin = HISTOfindBinWithCount(hcdf, max_percentile); thresh = hcdf->bins[bin]; // threshold for computing variance - } else // found a valid next valley. Now look backwards to find bulk of distribution + } + else // found a valid next valley. Now look backwards to find bulk of distribution { while (h->counts[bin] < h->counts[peak] * max_percentile && bin > peak + 1) // don't fit way out on tails of distribution @@ -1699,7 +1772,8 @@ int HISTOrobustGaussianFit(HISTOGRAM *h, double max_percentile, double *poffset, return (NO_ERROR); } -HISTOGRAM *HISTOgaussianCDF(HISTOGRAM *h, double mean, double sigma, int nbins) { +HISTOGRAM *HISTOgaussianCDF(HISTOGRAM *h, double mean, double sigma, int nbins) +{ HISTOGRAM *hpdf; hpdf = HISTOgaussianPDF(h, mean, sigma, nbins); @@ -1708,7 +1782,8 @@ HISTOGRAM *HISTOgaussianCDF(HISTOGRAM *h, double mean, double sigma, int nbins) return (h); } -HISTOGRAM *HISTOgaussianPDF(HISTOGRAM *h, double mean, double sigma, int nbins) { +HISTOGRAM *HISTOgaussianPDF(HISTOGRAM *h, double mean, double sigma, int nbins) +{ int bin; double val, sqrt_2pi; @@ -1730,7 +1805,8 @@ HISTOGRAM *HISTOgaussianPDF(HISTOGRAM *h, double mean, double sigma, int nbins) if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) HISTOplot(h, "h.plt"); return (h); } -HISTOGRAM *HISTOabs(HISTOGRAM *h, HISTOGRAM *habs) { +HISTOGRAM *HISTOabs(HISTOGRAM *h, HISTOGRAM *habs) +{ int b, pbins, pbin; double mx, mn; @@ -1754,7 +1830,8 @@ HISTOGRAM *HISTOabs(HISTOGRAM *h, HISTOGRAM *habs) { } return (habs); } -HISTOGRAM *HISTOscalarMul(HISTOGRAM *hsrc, float mul, HISTOGRAM *hdst) { +HISTOGRAM *HISTOscalarMul(HISTOGRAM *hsrc, float mul, HISTOGRAM *hdst) +{ int b; if (!hdst) @@ -1767,7 +1844,8 @@ HISTOGRAM *HISTOscalarMul(HISTOGRAM *hsrc, float mul, HISTOGRAM *hdst) { return (hdst); } -HISTOGRAM *HISTOscalarAdd(HISTOGRAM *hsrc, float add, HISTOGRAM *hdst) { +HISTOGRAM *HISTOscalarAdd(HISTOGRAM *hsrc, float add, HISTOGRAM *hdst) +{ int b; if (!hdst) @@ -1780,7 +1858,8 @@ HISTOGRAM *HISTOscalarAdd(HISTOGRAM *hsrc, float add, HISTOGRAM *hdst) { return (hdst); } -double HISTOgetEntropy(HISTOGRAM *h) { +double HISTOgetEntropy(HISTOGRAM *h) +{ double total = (double)HISTOtotal(h); double entropy = 0.0, p; int b; @@ -1794,7 +1873,8 @@ double HISTOgetEntropy(HISTOGRAM *h) { return (entropy); } -HISTOGRAM *HISTOsoapBubbleZeros(HISTOGRAM *hsrc, HISTOGRAM *hdst, int niters) { +HISTOGRAM *HISTOsoapBubbleZeros(HISTOGRAM *hsrc, HISTOGRAM *hdst, int niters) +{ int n, b, *control; double *tmp; @@ -1826,7 +1906,8 @@ HISTOGRAM *HISTOsoapBubbleZeros(HISTOGRAM *hsrc, HISTOGRAM *hdst, int niters) { free(control); return (hdst); } -int HISTOfindMaxDerivative(HISTOGRAM *h, double min_count, double max_count, int whalf, int grad_dir) { +int HISTOfindMaxDerivative(HISTOGRAM *h, double min_count, double max_count, int whalf, int grad_dir) +{ int index, i0, peak_index, num = 0; double prev_val, next_val, max_d, d; @@ -1854,7 +1935,8 @@ int HISTOfindMaxDerivative(HISTOGRAM *h, double min_count, double max_count, int /************************** 2D Histogram stuff starts *************** */ -HISTOGRAM2D *HISTO2Dalloc(int nbins1, int nbins2) { +HISTOGRAM2D *HISTO2Dalloc(int nbins1, int nbins2) +{ HISTOGRAM2D *histo; int i; @@ -1876,7 +1958,8 @@ HISTOGRAM2D *HISTO2Dalloc(int nbins1, int nbins2) { return (histo); } -int HISTO2Dfree(HISTOGRAM2D **phisto) { +int HISTO2Dfree(HISTOGRAM2D **phisto) +{ HISTOGRAM2D *histo; int i; @@ -1888,16 +1971,19 @@ int HISTO2Dfree(HISTOGRAM2D **phisto) { if (histo->counts) { for (i = 0; i < histo->nbins1; i++) free(histo->counts[i]); free(histo->counts); - } else + } + else DiagBreak(); free(histo); - } else + } + else DiagBreak(); return (NO_ERROR); } -int HISTO2Ddump(HISTOGRAM2D *histo, FILE *fp) { +int HISTO2Ddump(HISTOGRAM2D *histo, FILE *fp) +{ int bin1, bin2; if (!histo) @@ -1918,7 +2004,8 @@ int HISTO2Ddump(HISTOGRAM2D *histo, FILE *fp) { } return (NO_ERROR); } -int HISTO2Dwrite(HISTOGRAM2D *h, char *fname) { +int HISTO2Dwrite(HISTOGRAM2D *h, char *fname) +{ FILE *fp; int ret; @@ -1927,7 +2014,8 @@ int HISTO2Dwrite(HISTOGRAM2D *h, char *fname) { fclose(fp); return (ret); } -int HISTO2DwriteInto(HISTOGRAM2D *h, FILE *fp) { +int HISTO2DwriteInto(HISTOGRAM2D *h, FILE *fp) +{ int b1, b2; fwriteInt(h->nbins1, fp); @@ -1945,7 +2033,8 @@ int HISTO2DwriteInto(HISTOGRAM2D *h, FILE *fp) { for (b2 = 0; b2 < h->nbins2; b2++) fwriteFloat(h->counts[b1][b2], fp); return (NO_ERROR); } -HISTOGRAM2D *HISTO2Dread(char *fname) { +HISTOGRAM2D *HISTO2Dread(char *fname) +{ HISTOGRAM2D *histo; FILE *fp; @@ -1957,7 +2046,8 @@ HISTOGRAM2D *HISTO2Dread(char *fname) { return (histo); } -HISTOGRAM2D *HISTO2DreadFrom(FILE *fp) { +HISTOGRAM2D *HISTO2DreadFrom(FILE *fp) +{ int b1, nbins1, b2, nbins2; HISTOGRAM2D *h; @@ -1977,7 +2067,8 @@ HISTOGRAM2D *HISTO2DreadFrom(FILE *fp) { for (b2 = 0; b2 < h->nbins2; b2++) h->counts[b1][b2] = freadFloat(fp); return (h); } -HISTOGRAM2D *HISTO2Dclear(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst) { +HISTOGRAM2D *HISTO2Dclear(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst) +{ int b; if (!histo_dst) histo_dst = HISTO2Dalloc(histo_src->nbins1, histo_src->nbins2); @@ -1989,7 +2080,8 @@ HISTOGRAM2D *HISTO2Dclear(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst) { return (histo_dst); } -HISTOGRAM2D *HISTO2Dinit(HISTOGRAM2D *h, int nbins1, int nbins2, double mn1, int mx1, double mn2, double mx2) { +HISTOGRAM2D *HISTO2Dinit(HISTOGRAM2D *h, int nbins1, int nbins2, double mn1, int mx1, double mn2, double mx2) +{ int b; if (h == NULL) @@ -2009,7 +2101,8 @@ HISTOGRAM2D *HISTO2Dinit(HISTOGRAM2D *h, int nbins1, int nbins2, double mn1, int return (h); } -HISTOGRAM2D *HISTO2Drealloc(HISTOGRAM2D *histo, int nbins1, int nbins2) { +HISTOGRAM2D *HISTO2Drealloc(HISTOGRAM2D *histo, int nbins1, int nbins2) +{ int b; if (histo == NULL) return (HISTO2Dalloc(nbins1, nbins2)); @@ -2031,7 +2124,8 @@ HISTOGRAM2D *HISTO2Drealloc(HISTOGRAM2D *histo, int nbins1, int nbins2) { return (histo); } int HISTO2DaddFractionalSample( - HISTOGRAM2D *histo, float val1, float val2, float bmin1, float bmax1, float bmin2, float bmax2, float frac) { + HISTOGRAM2D *histo, float val1, float val2, float bmin1, float bmax1, float bmin2, float bmax2, float frac) +{ int bin_no1, bin_no2; float bin_size1, bin_size2; @@ -2040,7 +2134,8 @@ int HISTO2DaddFractionalSample( bmin1 = histo->min1; bmax1 = histo->max1; bin_size1 = histo->bin_size1; - } else + } + else bin_size1 = (bmax1 - bmin1) / ((float)histo->nbins1 - 1); bin_no1 = nint((val1 - bmin1) / bin_size1); @@ -2049,7 +2144,8 @@ int HISTO2DaddFractionalSample( bmin2 = histo->min2; bmax2 = histo->max2; bin_size2 = histo->bin_size2; - } else + } + else bin_size2 = (bmax2 - bmin2) / ((float)histo->nbins2 - 1); bin_no2 = nint((val2 - bmin2) / bin_size2); @@ -2061,7 +2157,8 @@ int HISTO2DaddFractionalSample( return (NO_ERROR); } -int HISTO2DaddSample(HISTOGRAM2D *histo, float val1, float val2, float bmin1, float bmax1, float bmin2, float bmax2) { +int HISTO2DaddSample(HISTOGRAM2D *histo, float val1, float val2, float bmin1, float bmax1, float bmin2, float bmax2) +{ int bin_no1, bin_no2; float bin_size1, bin_size2; @@ -2070,7 +2167,8 @@ int HISTO2DaddSample(HISTOGRAM2D *histo, float val1, float val2, float bmin1, fl bmin1 = histo->min1; bmax1 = histo->max1; bin_size1 = histo->bin_size1; - } else + } + else bin_size1 = (bmax1 - bmin1) / ((float)histo->nbins1 - 1); bin_no1 = nint((val1 - bmin1) / bin_size1); @@ -2079,7 +2177,8 @@ int HISTO2DaddSample(HISTOGRAM2D *histo, float val1, float val2, float bmin1, fl bmin2 = histo->min2; bmax2 = histo->max2; bin_size2 = histo->bin_size2; - } else + } + else bin_size2 = (bmax2 - bmin2) / ((float)histo->nbins2 - 1); bin_no2 = nint((val2 - bmin2) / bin_size2); @@ -2090,7 +2189,8 @@ int HISTO2DaddSample(HISTOGRAM2D *histo, float val1, float val2, float bmin1, fl return (NO_ERROR); } -int HISTO2Dplot(HISTOGRAM2D *histo, char *fname) { +int HISTO2Dplot(HISTOGRAM2D *histo, char *fname) +{ FILE *fp; int bin_no1, bmin1, bmax1, bin_no2, bmin2, bmax2; @@ -2123,7 +2223,8 @@ int HISTO2Dplot(HISTOGRAM2D *histo, char *fname) { return (NO_ERROR); } -HISTOGRAM2D *HISTO2Dcopy(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst) { +HISTOGRAM2D *HISTO2Dcopy(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst) +{ int b; if (!histo_dst) histo_dst = HISTO2Dalloc(histo_src->nbins1, histo_src->nbins2); @@ -2144,7 +2245,8 @@ HISTOGRAM2D *HISTO2Dcopy(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst) { return (histo_dst); } -HISTOGRAM2D *HISTO2DmakePDF(HISTO2D *h_src, HISTO2D *h_dst) { +HISTOGRAM2D *HISTO2DmakePDF(HISTO2D *h_src, HISTO2D *h_dst) +{ int b1, b2; double total, unlikely; @@ -2164,7 +2266,8 @@ HISTOGRAM2D *HISTO2DmakePDF(HISTO2D *h_src, HISTO2D *h_dst) { return (h_dst); } -int HISTO2DfindBin1(HISTOGRAM2D *h, float val) { +int HISTO2DfindBin1(HISTOGRAM2D *h, float val) +{ int b; if (h->bin_size1 == 1) return ((int)val - h->min1); @@ -2174,7 +2277,8 @@ int HISTO2DfindBin1(HISTOGRAM2D *h, float val) { return (0); } -int HISTO2DfindBin2(HISTOGRAM2D *h, float val) { +int HISTO2DfindBin2(HISTOGRAM2D *h, float val) +{ int b; if (h->bin_size2 == 1) return ((int)val - h->min2); @@ -2184,7 +2288,8 @@ int HISTO2DfindBin2(HISTOGRAM2D *h, float val) { return (0); } -double HISTO2DgetCount(HISTOGRAM2D *h, float bin_val1, float bin_val2) { +double HISTO2DgetCount(HISTOGRAM2D *h, float bin_val1, float bin_val2) +{ int b1, b2; b1 = HISTO2DfindBin1(h, bin_val1); @@ -2209,7 +2314,8 @@ double HISTO2DgetCount(HISTOGRAM2D *h, float bin_val1, float bin_val2) { Description ------------------------------------------------------*/ #define MAX_LEN 2000 -HISTOGRAM2D *HISTO2Dsmooth(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma) { +HISTOGRAM2D *HISTO2Dsmooth(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma) +{ float norm, two_sigma, fx, k, kernel[MAX_LEN], total; int x, half, len, b1, b2, kx, nbins1, nbins2, y, ky, b1k, b2k, i; @@ -2223,7 +2329,8 @@ HISTOGRAM2D *HISTO2Dsmooth(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float histo_dst->bin_size2 = histo_src->bin_size2; histo_dst->min2 = histo_src->min2; histo_dst->max2 = histo_src->max2; - } else { + } + else { if ((histo_dst->nbins1 < histo_src->nbins1) || (histo_dst->nbins2 < histo_src->nbins2)) { // fprintf(stderr, "realloc: histo_dst->nbins = %d, " //"histo_src->nbins = %d\n", @@ -2293,7 +2400,8 @@ HISTOGRAM2D *HISTO2Dsmooth(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float return (histo_dst); } #if 1 -HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma1, float sigma2) { +HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma1, float sigma2) +{ float norm, k, total; int x, half1, half2, len1, len2, b1, b2, kx, nbins1, nbins2, y, ky, b1k, b2k, dist; @@ -2307,7 +2415,8 @@ HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo histo_dst->bin_size2 = histo_src->bin_size2; histo_dst->min2 = histo_src->min2; histo_dst->max2 = histo_src->max2; - } else { + } + else { if ((histo_dst->nbins1 < histo_src->nbins1) || (histo_dst->nbins2 < histo_src->nbins2)) { // fprintf(stderr, "realloc: histo_dst->nbins = %d, " //"histo_src->nbins = %d\n", @@ -2367,7 +2476,8 @@ HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo } #else #if 1 -HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma1, float sigma2) { +HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma1, float sigma2) +{ float norm, two_sigma, fx, k, k1, k2, kernel1[MAX_LEN], kernel2[MAX_LEN], total; int x, half1, half2, len1, len2, b1, b2, kx, nbins1, nbins2, y, ky, b1k, b2k; @@ -2381,7 +2491,8 @@ HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo histo_dst->bin_size2 = histo_src->bin_size2; histo_dst->min2 = histo_src->min2; histo_dst->max2 = histo_src->max2; - } else { + } + else { if ((histo_dst->nbins1 < histo_src->nbins1) || (histo_dst->nbins2 < histo_src->nbins2)) { // fprintf(stderr, "realloc: histo_dst->nbins = %d, " //"histo_src->nbins = %d\n", @@ -2477,7 +2588,8 @@ HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo return (histo_dst); } #else -HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma1, float sigma2) { +HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma1, float sigma2) +{ HISTO2D *h_tmp; h_tmp = HISTO2DsmoothBins1(histo_src, NULL, sigma1); histo_dst = HISTO2DsmoothBins2(h_tmp, histo_dst, sigma2); @@ -2486,7 +2598,8 @@ HISTOGRAM2D *HISTO2DsmoothAnisotropic(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo } #endif #endif -HISTOGRAM2D *HISTO2DsmoothBins1(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma) { +HISTOGRAM2D *HISTO2DsmoothBins1(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma) +{ float norm, two_sigma, fx, k, kernel[MAX_LEN], total; int x, half, len, b1, b2, kx, nbins1, nbins2, b1k; @@ -2500,7 +2613,8 @@ HISTOGRAM2D *HISTO2DsmoothBins1(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, histo_dst->bin_size2 = histo_src->bin_size2; histo_dst->min2 = histo_src->min2; histo_dst->max2 = histo_src->max2; - } else { + } + else { if ((histo_dst->nbins1 < histo_src->nbins1) || (histo_dst->nbins2 < histo_src->nbins2)) { // fprintf(stderr, "realloc: histo_dst->nbins = %d, " //"histo_src->nbins = %d\n", @@ -2564,7 +2678,8 @@ HISTOGRAM2D *HISTO2DsmoothBins1(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, return (histo_dst); } -HISTOGRAM2D *HISTO2DsmoothBins2(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma) { +HISTOGRAM2D *HISTO2DsmoothBins2(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, float sigma) +{ float norm, two_sigma, fx, k, kernel[MAX_LEN], total; int x, kx, half, len, b1, b2, nbins1, nbins2, b2k; @@ -2578,7 +2693,8 @@ HISTOGRAM2D *HISTO2DsmoothBins2(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, histo_dst->bin_size2 = histo_src->bin_size2; histo_dst->min2 = histo_src->min2; histo_dst->max2 = histo_src->max2; - } else { + } + else { if ((histo_dst->nbins1 < histo_src->nbins1) || (histo_dst->nbins2 < histo_src->nbins2)) { // fprintf(stderr, "realloc: histo_dst->nbins = %d, " //"histo_src->nbins = %d\n", @@ -2642,7 +2758,8 @@ HISTOGRAM2D *HISTO2DsmoothBins2(HISTOGRAM2D *histo_src, HISTOGRAM2D *histo_dst, return (histo_dst); } -HISTOGRAM2D *HISTO2DsoapBubbleZeros(HISTOGRAM2D *hsrc, HISTOGRAM2D *hdst, int niters) { +HISTOGRAM2D *HISTO2DsoapBubbleZeros(HISTOGRAM2D *hsrc, HISTOGRAM2D *hdst, int niters) +{ int n, b1, b2, **control, num; double **tmp, val; @@ -2732,7 +2849,8 @@ HISTOGRAM2D *HISTO2DsoapBubbleZeros(HISTOGRAM2D *hsrc, HISTOGRAM2D *hdst, int ni free(control); return (hdst); } -float HISTOcomputeFWHM(HISTOGRAM *h, int peak) { +float HISTOcomputeFWHM(HISTOGRAM *h, int peak) +{ int width, max_width; float thresh, fwhm; @@ -2747,7 +2865,8 @@ float HISTOcomputeFWHM(HISTOGRAM *h, int peak) { return (fwhm); } -double HISTOrmsDifference(HISTOGRAM *h1, HISTOGRAM *h2) { +double HISTOrmsDifference(HISTOGRAM *h1, HISTOGRAM *h2) +{ int b; double rms, error; @@ -2757,7 +2876,8 @@ double HISTOrmsDifference(HISTOGRAM *h1, HISTOGRAM *h2) { } return (sqrt(rms / h1->nbins)); } -double HISTOearthMoversDistance(HISTOGRAM *h1, HISTOGRAM *h2) { +double HISTOearthMoversDistance(HISTOGRAM *h1, HISTOGRAM *h2) +{ double emd = 0.0; h1 = HISTOcopy(h1, NULL); @@ -2770,7 +2890,8 @@ double HISTOearthMoversDistance(HISTOGRAM *h1, HISTOGRAM *h2) { return (emd); } -double HISTOksDistance(HISTOGRAM *h1, HISTOGRAM *h2) { +double HISTOksDistance(HISTOGRAM *h1, HISTOGRAM *h2) +{ double ks_dist, dist, c2; int b; @@ -2790,8 +2911,8 @@ double HISTOksDistance(HISTOGRAM *h1, HISTOGRAM *h2) { return (ks_dist); } -HISTOGRAM *HISTOeraseRightmostPeak( - HISTOGRAM *hsrc, HISTOGRAM *hdst, int whalf, float min_pct, int min_val, int max_val) { +HISTOGRAM *HISTOeraseRightmostPeak(HISTOGRAM *hsrc, HISTOGRAM *hdst, int whalf, float min_pct, int min_val, int max_val) +{ int bmin, bmax, b; hdst = HISTOcopy(hsrc, hdst); @@ -2807,7 +2928,8 @@ HISTOGRAM *HISTOeraseRightmostPeak( HISTOerase(hdst, MAX(0, b - 1), bmax); return (hdst); } -int HISTOerase(HISTOGRAM *h, int bmin, int bmax) { +int HISTOerase(HISTOGRAM *h, int bmin, int bmax) +{ int b; bmin = MAX(0, bmin); @@ -2816,7 +2938,8 @@ int HISTOerase(HISTOGRAM *h, int bmin, int bmax) { if (bmax == h->nbins - 1) h->nbins = bmin - 1; return (NO_ERROR); } -int HISTOisPeak(HISTOGRAM *h, int bin, int whalf) { +int HISTOisPeak(HISTOGRAM *h, int bin, int whalf) +{ int b, bmin, bmax; float val; diff --git a/utils/ic12.c b/utils/ic12.c index 40a06680462..79662d151a4 100644 --- a/utils/ic12.c +++ b/utils/ic12.c @@ -44,7 +44,8 @@ IC_FACE ic12_faces[ICO_NFACES] { { 6, 7, 11 } }, { { 6, 2, 7 } }, { { 2, 8, 7 } }, { { 2, 3, 8 } }, { { 3, 9, 8 } }, { { 9, 10, 12 } }, { { 10, 11, 12 } }, { { 11, 7, 12 } }, { { 7, 8, 12 } }, { { 8, 9, 12 } } }; // clang-format on -MRI_SURFACE *ic12_make_surface(int max_vertices, int max_faces) { +MRI_SURFACE *ic12_make_surface(int max_vertices, int max_faces) +{ MRI_SURFACE *mris; int vno, fno, n, vn, n1, n2; VERTEX *v; diff --git a/utils/ic163842.c b/utils/ic163842.c index a9de23011a0..681b6a68292 100644 --- a/utils/ic163842.c +++ b/utils/ic163842.c @@ -37,7 +37,8 @@ static int static_read_icosahedron(void); IC_VERTEX *ic163842_vertices = NULL; IC_FACE *ic163842_faces = NULL; -MRI_SURFACE *ic163842_make_surface(int max_vertices, int max_faces) { +MRI_SURFACE *ic163842_make_surface(int max_vertices, int max_faces) +{ MRI_SURFACE *mris; int vno, fno, n, vn, n1, n2; VERTEX *v; @@ -151,7 +152,8 @@ MRI_SURFACE *ic163842_make_surface(int max_vertices, int max_faces) { first_time = 1; return (mris); } -static int static_read_icosahedron(void) { +static int static_read_icosahedron(void) +{ FILE *fp; char line[200], *cp; int vno, fno, vno1, vno2, vno3, n; diff --git a/utils/ic2562.c b/utils/ic2562.c index d586e9f7bec..f4c9a149089 100644 --- a/utils/ic2562.c +++ b/utils/ic2562.c @@ -7725,7 +7725,8 @@ IC_FACE ic2562_faces[5120] = } ; // clang-format on -MRI_SURFACE *ic2562_make_surface(int max_vertices, int max_faces) { +MRI_SURFACE *ic2562_make_surface(int max_vertices, int max_faces) +{ MRI_SURFACE *mris; int vno, fno, n, vn, n1, n2; VERTEX *v; diff --git a/utils/ic42.c b/utils/ic42.c index 99e1acaffc4..9b5aa8c176c 100644 --- a/utils/ic42.c +++ b/utils/ic42.c @@ -64,7 +64,8 @@ IC_FACE ic42_faces[ICO_NFACES] { { 40, 32, 41 } }, { { 40, 41, 12 } }, { { 7, 35, 41 } }, { { 35, 8, 42 } }, { { 41, 35, 42 } }, { { 41, 42, 12 } }, { { 8, 37, 42 } }, { { 37, 9, 39 } }, { { 42, 37, 39 } }, { { 42, 39, 12 } } }; // clang-format on -MRI_SURFACE *ic42_make_surface(int max_vertices, int max_faces) { +MRI_SURFACE *ic42_make_surface(int max_vertices, int max_faces) +{ MRI_SURFACE *mris; int vno, fno, n, vn, n1, n2; VERTEX *v; diff --git a/utils/ic642.c b/utils/ic642.c index d2497c509ff..8513cd19f25 100644 --- a/utils/ic642.c +++ b/utils/ic642.c @@ -1964,7 +1964,8 @@ IC_FACE ic642_faces[1280] = {{ 634, 607, 12 }} } ; // clang-format on -MRI_SURFACE *ic642_make_surface(int max_vertices, int max_faces) { +MRI_SURFACE *ic642_make_surface(int max_vertices, int max_faces) +{ MRI_SURFACE *mris; int vno, fno, n, vn, n1, n2; VERTEX *v; diff --git a/utils/icosahedron.c b/utils/icosahedron.c index fab6fef1606..89497263d26 100644 --- a/utils/icosahedron.c +++ b/utils/icosahedron.c @@ -1717,7 +1717,8 @@ IC_FACE ic4_faces[5120] = { {{2561, 2559, 2197}}, {{2561, 2197, 558}}, {{624, 2560, 2562}}, {{2560, 642, 2561}}, {{2562, 2560, 2561}}, {{2562, 2561, 558}}, {{624, 2562, 2478}}, {{2562, 558, 2202}}, {{2478, 2562, 2202}}, {{2478, 2202, 12}}}; -MRI_SURFACE *ICOreadOverAlloc(const char *fname, double pct_over) { +MRI_SURFACE *ICOreadOverAlloc(const char *fname, double pct_over) +{ ICOSAHEDRON *ico; int fno, vno, n1, n2, n, vn; MRI_SURFACE *mris; @@ -1863,7 +1864,8 @@ MRI_SURFACE *ICOreadOverAlloc(const char *fname, double pct_over) { free(ico); return (mris); } -MRI_SURFACE *ICOread(const char *fname) { +MRI_SURFACE *ICOread(const char *fname) +{ ICOSAHEDRON *ico; int fno, vno, n1, n2, n, vn; MRI_SURFACE *mris; @@ -2014,7 +2016,8 @@ MRI_SURFACE *ICOread(const char *fname) { file "FREESURFER_HOME/lib/bem/ic%d.tri" where %d is the "order". As read in, the vertices of the icosahedron are on the unit sphere. -------------------------------------------------------------------*/ -ICOSAHEDRON *read_icosahedron_by_order(int order) { +ICOSAHEDRON *read_icosahedron_by_order(int order) +{ char fname[STRLEN], *FREESURFER_HOME; FREESURFER_HOME = getenv("FREESURFER_HOME"); @@ -2025,7 +2028,8 @@ ICOSAHEDRON *read_icosahedron_by_order(int order) { return (read_icosahedron(fname)); } -ICOSAHEDRON *read_icosahedron(const char *fname) { +ICOSAHEDRON *read_icosahedron(const char *fname) +{ FILE *fp; char line[200], *cp; int vno, fno, vno1, vno2, vno3, n, nvertices, nfaces; @@ -2056,11 +2060,13 @@ ICOSAHEDRON *read_icosahedron(const char *fname) { x = y; y = z; z = nx; - } else if (count == 6) // else x, y, z, nx, ny, nz + } + else if (count == 6) // else x, y, z, nx, ny, nz { vno = n + 1; // keep x, y, z as is - } else + } + else break; ico->vertices[vno - 1].x = x; ico->vertices[vno - 1].y = y; @@ -2096,7 +2102,8 @@ ICOSAHEDRON *read_icosahedron(const char *fname) { return (ico); } -int ICOreadVertexPositions(MRI_SURFACE *mris, const char *fname, int which) { +int ICOreadVertexPositions(MRI_SURFACE *mris, const char *fname, int which) +{ ICOSAHEDRON *ico; int vno; VERTEX *v; @@ -2143,7 +2150,8 @@ int ICOreadVertexPositions(MRI_SURFACE *mris, const char *fname, int which) { Note: I (doug) don't know I'm using the term "order" properly. I did not know what else to call this particular property. -------------------------------------------------------------------*/ -MRI_SURFACE *ReadIcoByOrder(int IcoOrder, float RescaleFactor) { +MRI_SURFACE *ReadIcoByOrder(int IcoOrder, float RescaleFactor) +{ char *FREESURFER_HOME, trifile[2048]; MRI_SURFACE *surf; VERTEX *v; @@ -2175,7 +2183,8 @@ MRI_SURFACE *ReadIcoByOrder(int IcoOrder, float RescaleFactor) { of vertices. Converts the number of vertices into the "order", then calls ReadIcoByOrder(). ------------------------------------------------------------------*/ -MRI_SURFACE *ReadIcoByNVtxs(int nIcoVtxs, float RescaleFactor) { +MRI_SURFACE *ReadIcoByNVtxs(int nIcoVtxs, float RescaleFactor) +{ MRI_SURFACE *surf; int IcoOrder; @@ -2192,7 +2201,8 @@ MRI_SURFACE *ReadIcoByNVtxs(int nIcoVtxs, float RescaleFactor) { Note: I (doug) don't know I'm using the term "order" properly. I did not know what else to call this particular property. --------------------------------------------------------------*/ -int IcoOrderFromNVtxs(int nIcoVtxs) { +int IcoOrderFromNVtxs(int nIcoVtxs) +{ int IcoOrder = -1; switch (nIcoVtxs) { @@ -2227,7 +2237,8 @@ int IcoOrderFromNVtxs(int nIcoVtxs) { /*------------------------------------------------------------- IcoNVtxsFromOrder() --------------------------------------------------------------*/ -int IcoNVtxsFromOrder(int IcoOrder) { +int IcoNVtxsFromOrder(int IcoOrder) +{ int nIcoVtxs = -1; switch (IcoOrder) { @@ -2260,7 +2271,8 @@ int IcoNVtxsFromOrder(int IcoOrder) { return (nIcoVtxs); } -int IcoFindNClosestVertices(IC_VERTEX *vertices, int nvertices, float nx, float ny, float nz, int num, int *pv) { +int IcoFindNClosestVertices(IC_VERTEX *vertices, int nvertices, float nx, float ny, float nz, int num, int *pv) +{ int index, max_n, nout, found, n; double max_dot, dot; @@ -2290,7 +2302,8 @@ int IcoFindNClosestVertices(IC_VERTEX *vertices, int nvertices, float nx, float return (pv[0]); } -int IcoFindClosestVertex(IC_VERTEX *vertices, int nvertices, float nx, float ny, float nz) { +int IcoFindClosestVertex(IC_VERTEX *vertices, int nvertices, float nx, float ny, float nz) +{ int n, max_n; float mag, dot, max_dot; @@ -2311,7 +2324,8 @@ int IcoFindClosestVertex(IC_VERTEX *vertices, int nvertices, float nx, float ny, return (max_n); } -static ICO_FACE_LIST *ICPbuildFaceList(MRI_SURFACE *ico1, MRI_SURFACE *ico2) { +static ICO_FACE_LIST *ICPbuildFaceList(MRI_SURFACE *ico1, MRI_SURFACE *ico2) +{ ICO_FACE_LIST *icf; FACE *f1, *f2; int fno1, fno2, min_fno, index; @@ -2390,7 +2404,8 @@ static ICO_FACE_LIST *ICPbuildFaceList(MRI_SURFACE *ico1, MRI_SURFACE *ico2) { return (icf); } -ICO_PYRAMID *ICPread(int min_level, int max_level) { +ICO_PYRAMID *ICPread(int min_level, int max_level) +{ ICO_PYRAMID *icp; char *cp, fname[STRLEN]; int ico_no; diff --git a/utils/image.c b/utils/image.c index faf95f30968..0b37cefc7cd 100644 --- a/utils/image.c +++ b/utils/image.c @@ -70,7 +70,8 @@ Description ------------------------------------------------------*/ -IMAGE *ImageAlloc(int rows, int cols, int format, int nframes) { +IMAGE *ImageAlloc(int rows, int cols, int format, int nframes) +{ IMAGE *I; int ecode; @@ -89,7 +90,8 @@ IMAGE *ImageAlloc(int rows, int cols, int format, int nframes) { Description ------------------------------------------------------*/ -IMAGE *ImageAllocHeader(int rows, int cols, int format, int nframes) { +IMAGE *ImageAllocHeader(int rows, int cols, int format, int nframes) +{ IMAGE *I; I = (IMAGE *)calloc(1, sizeof(IMAGE)); @@ -107,7 +109,8 @@ IMAGE *ImageAllocHeader(int rows, int cols, int format, int nframes) { Description stolen from hips2 code and modified to allocate multiple frames. ------------------------------------------------------*/ -int ImageAllocBuffer(IMAGE *I) { +int ImageAllocBuffer(IMAGE *I) +{ int fcb, cb; long npix; @@ -125,7 +128,8 @@ int ImageAllocBuffer(IMAGE *I) { fcb = I->fcol / 8; cb = (I->ocols + 7) / 8; I->firstpix = I->image + ((cb * I->frow) + fcb); - } else + } + else I->firstpix = I->image + (((long)I->ocols * (long)I->frow) + (long)I->fcol) * I->sizepix; I->imdealloc = TRUE; hmemset(I->image, 0, I->sizeimage * I->num_frame); @@ -138,7 +142,8 @@ int ImageAllocBuffer(IMAGE *I) { Description ------------------------------------------------------*/ -int ImageFree(IMAGE **pI) { +int ImageFree(IMAGE **pI) +{ IMAGE *I = *pI; if (!I) ErrorExit(ERROR_BADPARM, "ImageFree: null pointer"); @@ -154,7 +159,8 @@ int ImageFree(IMAGE **pI) { Description ------------------------------------------------------*/ -int ImageUpdateHeader(IMAGE *I, const char *fname) { +int ImageUpdateHeader(IMAGE *I, const char *fname) +{ FILE *fp; int ecode; @@ -174,7 +180,8 @@ int ImageUpdateHeader(IMAGE *I, const char *fname) { Description ------------------------------------------------------*/ -IMAGE *ImageThreshold(IMAGE *Isrc, IMAGE *Idst, float threshold) { +IMAGE *ImageThreshold(IMAGE *Isrc, IMAGE *Idst, float threshold) +{ // int ecode; Pixelval p; @@ -192,7 +199,8 @@ IMAGE *ImageThreshold(IMAGE *Isrc, IMAGE *Idst, float threshold) { Description ------------------------------------------------------*/ -IMAGE *ImageDFT(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageDFT(IMAGE *Isrc, IMAGE *Idst) +{ /*float loglen ;*/ int ecode; IMAGE *Itmp; @@ -205,7 +213,8 @@ IMAGE *ImageDFT(IMAGE *Isrc, IMAGE *Idst) { Itmp = ImageAlloc(Isrc->rows, Isrc->cols, PFFLOAT, 1); ImageCopy(Isrc, Itmp); Isrc = Itmp; - } else + } + else Itmp = NULL; if (Isrc->pixel_format != PFCOMPLEX) { @@ -215,7 +224,8 @@ IMAGE *ImageDFT(IMAGE *Isrc, IMAGE *Idst) { ImageFree(&Idst); ErrorReturn(NULL, (ecode, "ImageDFT: h_toc failed (%d)\n", ecode)); } - } else + } + else ImageCopy(Isrc, Idst); ecode = h_fourtr(Idst); @@ -241,7 +251,8 @@ IMAGE *ImageDFT(IMAGE *Isrc, IMAGE *Idst) { perform the inverse fourier transform of the input image, scaling the output by 1/n. ------------------------------------------------------*/ -IMAGE *ImageInverseDFT(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageInverseDFT(IMAGE *Isrc, IMAGE *Idst) +{ /*float loglen ;*/ IMAGE *Itmp; int ecode; @@ -266,7 +277,8 @@ IMAGE *ImageInverseDFT(IMAGE *Isrc, IMAGE *Idst) { if (Idst->pixel_format != PFCOMPLEX) { hips_cplxtor = CPLX_REAL; h_tof(Itmp, Idst); - } else + } + else ImageCopy(Itmp, Idst); #if 1 @@ -284,7 +296,8 @@ IMAGE *ImageInverseDFT(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ -IMAGE *ImageMul(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) { +IMAGE *ImageMul(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) +{ int ecode; if (!Idst) Idst = ImageAlloc(Isrc1->rows, Isrc1->cols, Isrc1->pixel_format, Isrc1->num_frame); @@ -301,7 +314,8 @@ IMAGE *ImageMul(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) { Description ------------------------------------------------------*/ -IMAGE *ImageResize(IMAGE *Isrc, IMAGE *Idst, int drows, int dcols) { +IMAGE *ImageResize(IMAGE *Isrc, IMAGE *Idst, int drows, int dcols) +{ float x_scale, y_scale; int ecode; IMAGE *Itmp; @@ -356,7 +370,8 @@ IMAGE *ImageResize(IMAGE *Isrc, IMAGE *Idst, int drows, int dcols) { ImageFree(&Itmp); } ImageCopy(Isrc, Idst); - } else { + } + else { ecode = h_reduce(Isrc, Idst, nint(1.0f / x_scale), nint(1.0f / y_scale)); if (ecode != HIPS_OK) ErrorExit( @@ -375,7 +390,8 @@ IMAGE *ImageResize(IMAGE *Isrc, IMAGE *Idst, int drows, int dcols) { Description ------------------------------------------------------*/ -IMAGE *ImageCopy(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageCopy(IMAGE *Isrc, IMAGE *Idst) +{ int old, ecode, frame, nframes; byte *src_image, *dst_image; @@ -399,7 +415,8 @@ IMAGE *ImageCopy(IMAGE *Isrc, IMAGE *Idst) { if (Idst->pixel_format == Isrc->pixel_format) { ecode = h_copy(Isrc, Idst); if (ecode != HIPS_OK) ErrorExit(ecode, "ImageCopy: h_copy failed (%d)\n", ecode); - } else { + } + else { switch (Idst->pixel_format) { case PFDOUBLE: old = hips_cplxtor; @@ -467,7 +484,8 @@ IMAGE *ImageCopy(IMAGE *Isrc, IMAGE *Idst) { #define DISCEDGE_VARCRIT 0.0f #define DISCEDGE_SIZE 7 -IMAGE *ImageEdgeDetect(IMAGE *Isrc, IMAGE *Idst, float sigma, int wsize, float lthresh, float uthresh, int dothin) { +IMAGE *ImageEdgeDetect(IMAGE *Isrc, IMAGE *Idst, float sigma, int wsize, float lthresh, float uthresh, int dothin) +{ int ecode; IMAGE *Iout; float fmin = 0., fmax = 0.; @@ -514,7 +532,8 @@ ImageCopyArea(IMAGE *Isrc, IMAGE *Idst, int srow, int scol, Description ------------------------------------------------------*/ -int ImageClearArea(IMAGE *I, int r0, int c0, int rows, int cols, float val, int frame) { +int ImageClearArea(IMAGE *I, int r0, int c0, int rows, int cols, float val, int frame) +{ float *fptr; int row, col, start_frame, end_frame; byte *cptr, cval; @@ -531,7 +550,8 @@ int ImageClearArea(IMAGE *I, int r0, int c0, int rows, int cols, float val, int if (frame < 0) { start_frame = 0; end_frame = I->num_frame - 1; - } else + } + else start_frame = end_frame = frame; for (frame = start_frame; frame <= end_frame; frame++) { @@ -562,7 +582,8 @@ int ImageClearArea(IMAGE *I, int r0, int c0, int rows, int cols, float val, int Description ------------------------------------------------------*/ -float ImageFindPeak(IMAGE *I, int *prow, int *pcol, float *pval) { +float ImageFindPeak(IMAGE *I, int *prow, int *pcol, float *pval) +{ float max_val, *fpix, val; int max_row = -1, max_col = -1, row, col, rows, cols; @@ -596,7 +617,8 @@ float ImageFindPeak(IMAGE *I, int *prow, int *pcol, float *pval) { Description ------------------------------------------------------*/ -IMAGE *ImagePowerSpectrum(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImagePowerSpectrum(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Idft, *Iconj; if (!Idst) Idst = ImageAlloc(Isrc->rows, Isrc->cols, PFFLOAT, Isrc->num_frame); @@ -643,7 +665,8 @@ imageLargeEnough(IMAGE *Isrc, IMAGE *Idst) Description ------------------------------------------------------*/ -IMAGE *ImageNormalizePix(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageNormalizePix(IMAGE *Isrc, IMAGE *Idst) +{ float scale, fmin = 0.0f, fmax = 0.0f; int ecode; Pixelval pmin, pmax; @@ -692,7 +715,8 @@ IMAGE *ImageNormalizePix(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ -IMAGE *ImageConjugate(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageConjugate(IMAGE *Isrc, IMAGE *Idst) +{ CPIX *spix, *dpix; long npix, i; @@ -721,7 +745,8 @@ IMAGE *ImageConjugate(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ -Pixelval ImageAccum(IMAGE *Isrc) { +Pixelval ImageAccum(IMAGE *Isrc) +{ Pixelval retval; int row, col, endrow, endcol; float real, imag; @@ -757,7 +782,8 @@ Pixelval ImageAccum(IMAGE *Isrc) { Description ------------------------------------------------------*/ -MATRIX *ImageToMatrix(IMAGE *I) { +MATRIX *ImageToMatrix(IMAGE *I) +{ MATRIX *mat; int format = 0; long bytes; @@ -788,7 +814,8 @@ MATRIX *ImageToMatrix(IMAGE *I) { Description ------------------------------------------------------*/ -IMAGE *ImageFromMatrix(MATRIX *matrix, IMAGE *I) { +IMAGE *ImageFromMatrix(MATRIX *matrix, IMAGE *I) +{ int format; long bytes; @@ -812,7 +839,8 @@ IMAGE *ImageFromMatrix(MATRIX *matrix, IMAGE *I) { Description ------------------------------------------------------*/ -IMAGE *ImageInverse(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageInverse(IMAGE *Isrc, IMAGE *Idst) +{ MATRIX *mat, *mat_inverse; mat = ImageToMatrix(Isrc); @@ -829,7 +857,8 @@ IMAGE *ImageInverse(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ -IMAGE *ImageMatrixMul(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) { +IMAGE *ImageMatrixMul(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) +{ MATRIX *mat1, *mat2, *mat_dst; if (Isrc2->rows != Isrc1->cols) @@ -856,7 +885,8 @@ IMAGE *ImageMatrixMul(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) { output purposes unless the supplied one is already in float format. ------------------------------------------------------*/ -IMAGE *ImageScale(IMAGE *Isrc, IMAGE *Idst, float new_min, float new_max) { +IMAGE *ImageScale(IMAGE *Isrc, IMAGE *Idst, float new_min, float new_max) +{ float scale, old_min, old_max; int ecode, nframes, frame; Pixelval pmin, pmax; @@ -953,7 +983,8 @@ IMAGE *ImageScale(IMAGE *Isrc, IMAGE *Idst, float new_min, float new_max) { Description ------------------------------------------------------*/ -int ImageCheckSize(IMAGE *inImage, IMAGE *outImage, int rows, int cols, int nframes) { +int ImageCheckSize(IMAGE *inImage, IMAGE *outImage, int rows, int cols, int nframes) +{ long inPix, outPix; if (!outImage) return (0); @@ -980,7 +1011,8 @@ int ImageCheckSize(IMAGE *inImage, IMAGE *outImage, int rows, int cols, int nfra Description: change the size of an image ----------------------------------------------------------------------*/ -int ImageSetSize(IMAGE *I, int rows, int cols) { +int ImageSetSize(IMAGE *I, int rows, int cols) +{ if (!ImageCheckSize(I, I, rows, cols, 0)) return (0); I->frow = I->fcol = 0; @@ -995,7 +1027,8 @@ int ImageSetSize(IMAGE *I, int rows, int cols) { Description: ----------------------------------------------------------------------*/ -int ImageCopyFrames(IMAGE *inImage, IMAGE *outImage, int start, int nframes, int dst_frame) { +int ImageCopyFrames(IMAGE *inImage, IMAGE *outImage, int start, int nframes, int dst_frame) +{ byte *cIn, *cOut; unsigned int *iIn, *iOut; float *fsrc, *fdst; @@ -1117,7 +1150,8 @@ int ImageCopyFrames(IMAGE *inImage, IMAGE *outImage, int start, int nframes, int Description: ----------------------------------------------------------------------*/ -int ImageScaleRange(IMAGE *image, float fmin, float fmax, int low, int high) { +int ImageScaleRange(IMAGE *image, float fmin, float fmax, int low, int high) +{ int size; byte *csrc, cmin_val, cmax_val, cval; int *isrc, imin_val, imax_val, ival; @@ -1189,7 +1223,8 @@ int ImageScaleRange(IMAGE *image, float fmin, float fmax, int low, int high) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageRescale(IMAGE *inImage, IMAGE *outImage, float scale) { +IMAGE *ImageRescale(IMAGE *inImage, IMAGE *outImage, float scale) +{ int rows, cols; cols = nint((float)inImage->cols * scale); @@ -1212,7 +1247,8 @@ IMAGE *ImageRescale(IMAGE *inImage, IMAGE *outImage, float scale) { Description: ----------------------------------------------------------------------*/ -int ImageScaleDown(IMAGE *inImage, IMAGE *outImage, float scale) { +int ImageScaleDown(IMAGE *inImage, IMAGE *outImage, float scale) +{ int inRow, inCol, outRow, outCol, inCols, inRows, outRows, outCols, frame; UCHAR *outPix; byte *in_image, *out_image; @@ -1297,7 +1333,8 @@ int ImageScaleDown(IMAGE *inImage, IMAGE *outImage, float scale) { ImageFree(&Itmp); } ImageCopy(inImage, outImage); - } else { + } + else { foutPix = IMAGEFpix(outImage, 0, 0); for (outRow = 0; outRow < outRows; outRow++) for (outCol = 0; outCol < outCols; outCol++, foutPix++) { @@ -1337,7 +1374,8 @@ int ImageScaleDown(IMAGE *inImage, IMAGE *outImage, float scale) { Description: ----------------------------------------------------------------------*/ -int ImageScaleUp(IMAGE *inImage, IMAGE *outImage, float scale) { +int ImageScaleUp(IMAGE *inImage, IMAGE *outImage, float scale) +{ int inRow, inCol, outRow, outCol, inCols, inRows, endCol, endRow, outRows, outCols, frame; UCHAR *inPix, *outPix; UINT *inIPix, *outIPix; @@ -1473,7 +1511,8 @@ int ImageScaleUp(IMAGE *inImage, IMAGE *outImage, float scale) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageDifferentialScale(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols) { +IMAGE *ImageDifferentialScale(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols) +{ int rows, cols; if (!Iout) Iout = ImageAlloc(outRows, outCols, Isrc->pixel_format, Isrc->num_frame); @@ -1496,7 +1535,8 @@ IMAGE *ImageDifferentialScale(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols Description: ----------------------------------------------------------------------*/ -int ImageDifferentialScaleDown(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols) { +int ImageDifferentialScaleDown(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols) +{ int inRow, inCol, outRow, outCol, inCols, inRows, frame; UCHAR *outPix; byte *in_image, *out_image; @@ -1605,7 +1645,8 @@ int ImageDifferentialScaleDown(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCol Description: ----------------------------------------------------------------------*/ -int ImageDifferentialScaleUp(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols) { +int ImageDifferentialScaleUp(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols) +{ int inRow, inCol, outRow, outCol, inCols, inRows, endCol, endRow, frame; UCHAR *inPix, *outPix; UINT *inIPix, *outIPix; @@ -1745,7 +1786,8 @@ int ImageDifferentialScaleUp(IMAGE *Isrc, IMAGE *Iout, int outRows, int outCols) Description: ----------------------------------------------------------------------*/ -int ImageReflect(IMAGE *inImage, IMAGE *outImage, int how) { +int ImageReflect(IMAGE *inImage, IMAGE *outImage, int how) +{ int x, y, ymax; unsigned char *src, *dst; //, *tmp; unsigned int *isrc, *idst; //, *itmp; @@ -1810,7 +1852,8 @@ int ImageReflect(IMAGE *inImage, IMAGE *outImage, int how) { Description: add multiplicative "speckle" noise to an image. ----------------------------------------------------------------------*/ -int ImageAddSpeckleNoise(IMAGE *inImage, IMAGE *outImage, float amp) { +int ImageAddSpeckleNoise(IMAGE *inImage, IMAGE *outImage, float amp) +{ long npix; float *inPix, *outPix, noise, out; byte *psrc, *pdst; @@ -1858,7 +1901,8 @@ int ImageAddSpeckleNoise(IMAGE *inImage, IMAGE *outImage, float amp) { corrupt an image with salt & pepper noise: randomly generated 0s and 1s. ----------------------------------------------------------------------*/ -int ImageAddSaltNoise(IMAGE *inImage, IMAGE *outImage, float density) { +int ImageAddSaltNoise(IMAGE *inImage, IMAGE *outImage, float density) +{ long npix; float *inPix, *outPix, noise, in; byte *psrc, *pdst, bin; @@ -1910,7 +1954,8 @@ int ImageAddSaltNoise(IMAGE *inImage, IMAGE *outImage, float density) { Description: corrupt an image with additive zero mean gaussian noise. ----------------------------------------------------------------------*/ -int ImageAddNoise(IMAGE *inImage, IMAGE *outImage, float amp) { +int ImageAddNoise(IMAGE *inImage, IMAGE *outImage, float amp) +{ long npix; float *inPix, *outPix, gnoise, out; byte *psrc, *pdst; @@ -1954,7 +1999,8 @@ int ImageAddNoise(IMAGE *inImage, IMAGE *outImage, float amp) { Description: ----------------------------------------------------------------------*/ -int ImageValRange(IMAGE *image, float *pfmin, float *pfmax) { +int ImageValRange(IMAGE *image, float *pfmin, float *pfmax) +{ float fmax, fmin, *fpix; double dmax, dmin, *dpix; unsigned int size, imax, imin, *ipix; /* "unsiged" added dng */ @@ -2031,7 +2077,8 @@ int ImageValRange(IMAGE *image, float *pfmin, float *pfmax) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageCatSeq(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) { +IMAGE *ImageCatSeq(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) +{ IMAGE *Itmp; int num_frame, frameno; @@ -2045,7 +2092,8 @@ IMAGE *ImageCatSeq(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) { if (Isrc1) { ImageCopyFrames(Isrc1, Itmp, 0, Isrc1->num_frame, 0); frameno = Isrc1->num_frame; - } else + } + else frameno = 0; ImageCopyFrames(Isrc2, Itmp, 0, Isrc2->num_frame, frameno); @@ -2079,7 +2127,8 @@ IMAGE *ImageCatSeq(IMAGE *Isrc1, IMAGE *Isrc2, IMAGE *Idst) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageMulScale(IMAGE *Isrc, IMAGE *Idst, Pixelval *p) { +IMAGE *ImageMulScale(IMAGE *Isrc, IMAGE *Idst, Pixelval *p) +{ int ecode; fs_hsize_t size; float real, imag, sreal, simag; @@ -2115,7 +2164,8 @@ IMAGE *ImageMulScale(IMAGE *Isrc, IMAGE *Idst, Pixelval *p) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageAddScalar(IMAGE *Isrc, IMAGE *Idst, float scalar) { +IMAGE *ImageAddScalar(IMAGE *Isrc, IMAGE *Idst, float scalar) +{ fs_hsize_t size; float *fpix; @@ -2140,7 +2190,8 @@ IMAGE *ImageAddScalar(IMAGE *Isrc, IMAGE *Idst, float scalar) { Description: replace pixels of value 'inpix' with the value 'outpix' ----------------------------------------------------------------------*/ -IMAGE *ImageReplace(IMAGE *Isrc, IMAGE *Idst, float inpix, float outpix) { +IMAGE *ImageReplace(IMAGE *Isrc, IMAGE *Idst, float inpix, float outpix) +{ float *fin, *fout; byte *cin, *cout, cinpix, coutpix; fs_hsize_t npix; @@ -2159,7 +2210,8 @@ IMAGE *ImageReplace(IMAGE *Isrc, IMAGE *Idst, float inpix, float outpix) { if (*fin == inpix) { *fout++ = outpix; fin++; - } else + } + else *fout++ = *fin++; } break; @@ -2172,7 +2224,8 @@ IMAGE *ImageReplace(IMAGE *Isrc, IMAGE *Idst, float inpix, float outpix) { if (*cin == cinpix) { *cout++ = coutpix; cin++; - } else + } + else *cout++ = *cin++; } break; @@ -2192,7 +2245,8 @@ IMAGE *ImageReplace(IMAGE *Isrc, IMAGE *Idst, float inpix, float outpix) { 1 - images are linearly independent -1 - images are linearly dependent ----------------------------------------------------------------------*/ -int ImageCmp(IMAGE *Isrc, IMAGE *Idst) { +int ImageCmp(IMAGE *Isrc, IMAGE *Idst) +{ int ret, ecode; IMAGE *Idiv; Pixelval pmin, pmax; @@ -2236,7 +2290,8 @@ int ImageCmp(IMAGE *Isrc, IMAGE *Idst) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageAbs(IMAGE *inImage, IMAGE *outImage) { +IMAGE *ImageAbs(IMAGE *inImage, IMAGE *outImage) +{ UCHAR *cIn, *cOut; UINT *iIn, *iOut; float *fIn, *fOut; @@ -2305,7 +2360,8 @@ IMAGE *ImageAbs(IMAGE *inImage, IMAGE *outImage) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageAdd(IMAGE *Is1, IMAGE *Is2, IMAGE *Idst) { +IMAGE *ImageAdd(IMAGE *Is1, IMAGE *Is2, IMAGE *Idst) +{ int ecode; if (!Idst) Idst = ImageAlloc(Is1->rows, Is1->cols, Is1->pixel_format, Is1->num_frame); @@ -2321,7 +2377,8 @@ IMAGE *ImageAdd(IMAGE *Is1, IMAGE *Is2, IMAGE *Idst) { Description: Idst = Is1 - Is2 ----------------------------------------------------------------------*/ -IMAGE *ImageSubtract(IMAGE *Is1, IMAGE *Is2, IMAGE *Idst) { +IMAGE *ImageSubtract(IMAGE *Is1, IMAGE *Is2, IMAGE *Idst) +{ int ecode; if (!Idst) Idst = ImageAlloc(Is1->rows, Is1->cols, Is1->pixel_format, Is1->num_frame); @@ -2336,7 +2393,8 @@ IMAGE *ImageSubtract(IMAGE *Is1, IMAGE *Is2, IMAGE *Idst) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageExtractInto(IMAGE *Isrc, IMAGE *Idst, int x0, int y0, int dx, int dy, int xdst, int ydst) { +IMAGE *ImageExtractInto(IMAGE *Isrc, IMAGE *Idst, int x0, int y0, int dx, int dy, int xdst, int ydst) +{ CPIX *cpsrc, *cpdst; UCHAR *csrc, *cdst; float *fsrc, *fdst; @@ -2423,7 +2481,8 @@ IMAGE *ImageExtractInto(IMAGE *Isrc, IMAGE *Idst, int x0, int y0, int dx, int dy Description: ----------------------------------------------------------------------*/ -IMAGE *ImageExtract(IMAGE *Isrc, IMAGE *Idst, int x0, int y0, int dx, int dy) { +IMAGE *ImageExtract(IMAGE *Isrc, IMAGE *Idst, int x0, int y0, int dx, int dy) +{ UCHAR *csrc, *cdst; float *fsrc, *fdst; int xin, yin, xout, yout, x1, y1, yend, xend; @@ -2478,7 +2537,8 @@ IMAGE *ImageExtract(IMAGE *Isrc, IMAGE *Idst, int x0, int y0, int dx, int dy) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageZeroMean(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageZeroMean(IMAGE *Isrc, IMAGE *Idst) +{ int frameno, rows, cols, row, col, pix_per_frame, nframes; float ftotal, fmean, *fSrcPtr, *fDstPtr, *fSrcBase, *fDstBase; @@ -2526,7 +2586,8 @@ IMAGE *ImageZeroMean(IMAGE *Isrc, IMAGE *Idst) { form the covariance matrix treating each frame of Isrc as an observation. ----------------------------------------------------------------------*/ -IMAGE *ImageCovarMatrix(IMAGE *image, float **pmeans) { +IMAGE *ImageCovarMatrix(IMAGE *image, float **pmeans) +{ static IMAGE *zimage = NULL; /* zero-mean version of image */ IMAGE *cimage; int rows, cols, row, col, crow, ccol, crows, ccols, pix_per_frame, nframes, frameno, i; @@ -2629,12 +2690,14 @@ IMAGE *ImageCovarMatrix(IMAGE *image, float **pmeans) { static int compare_evalues(const void *l1, const void *l2); -typedef struct { +typedef struct +{ int eno; float evalue; } EIGEN_VALUE, EVALUE; -static int compare_evalues(const void *l1, const void *l2) { +static int compare_evalues(const void *l1, const void *l2) +{ EVALUE *e1, *e2; e1 = (EVALUE *)l1; @@ -2662,7 +2725,8 @@ static int compare_evalues(const void *l1, const void *l2) { where mx is the mean vector of the x variables. ----------------------------------------------------------------------*/ -IMAGE *ImagePrincipalComponents(IMAGE *image, int nterms, IMAGE **pcoefImage) { +IMAGE *ImagePrincipalComponents(IMAGE *image, int nterms, IMAGE **pcoefImage) +{ IMAGE *cimage, *pcImage, *zImage, *coefImage; float *evalues, *evectors; int frameno, nframes, row, col, rows, cols, pix_per_frame, i, nevalues, frame; @@ -2802,7 +2866,8 @@ IMAGE *ImagePrincipalComponents(IMAGE *image, int nterms, IMAGE **pcoefImage) { repeatedly, each call using an 'nframes' subset of coefImage starting at 'start'. ----------------------------------------------------------------------*/ -IMAGE *ImageReconstruct(IMAGE *pcImage, IMAGE *coefImage, IMAGE *xrImage, int start, int nframes) { +IMAGE *ImageReconstruct(IMAGE *pcImage, IMAGE *coefImage, IMAGE *xrImage, int start, int nframes) +{ int rows, cols, frame, nterms, term, i, pix_per_frame, pix_per_coef_frame; float *fPcPtr, *fXPtr, *fCoefPtr, *means, *Mx, ftotal; float *fBasePcPtr, *fBaseCoefPtr; @@ -2872,7 +2937,8 @@ IMAGE *ImageReconstruct(IMAGE *pcImage, IMAGE *coefImage, IMAGE *xrImage, int st Description: normalize the amplitude of a complex image. ----------------------------------------------------------------------*/ -IMAGE *ImageNormalizeComplex(IMAGE *Isrc, IMAGE *Idst, float thresh) { +IMAGE *ImageNormalizeComplex(IMAGE *Isrc, IMAGE *Idst, float thresh) +{ int rows, cols; long npix; CPIX *src, *dst; @@ -2911,7 +2977,8 @@ IMAGE *ImageNormalizeComplex(IMAGE *Isrc, IMAGE *Idst, float thresh) { treat each frame in the sequence as a rows x cols dimensional vector and normalize it so its length is 1. ----------------------------------------------------------------------*/ -int ImageNormalizeFrames(IMAGE *Isrc, IMAGE *Idst) { +int ImageNormalizeFrames(IMAGE *Isrc, IMAGE *Idst) +{ float flen, *fsrcPtr, *fdstPtr, fval; int frameno, rows, cols; long npix, pix_per_frame; @@ -2954,7 +3021,8 @@ int ImageNormalizeFrames(IMAGE *Isrc, IMAGE *Idst) { Description: generate a complex image from a real and an imaginary one ----------------------------------------------------------------------*/ -IMAGE *ImageCombine(IMAGE *Ireal, IMAGE *Iimag, IMAGE *Idst) { +IMAGE *ImageCombine(IMAGE *Ireal, IMAGE *Iimag, IMAGE *Idst) +{ int x, y, rows, cols; float *real, *imag; CPIX *dst; @@ -2987,7 +3055,8 @@ IMAGE *ImageCombine(IMAGE *Ireal, IMAGE *Iimag, IMAGE *Idst) { Description: flip an image about its horizontal axis ----------------------------------------------------------------------*/ -IMAGE *ImageInvert(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageInvert(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Ireal, *Iimag; int ecode; @@ -3016,7 +3085,8 @@ IMAGE *ImageInvert(IMAGE *Isrc, IMAGE *Idst) { Description: generate a complex image from a real and an imaginary one ----------------------------------------------------------------------*/ -IMAGE *ImageSplit(IMAGE *Icomp, IMAGE *Ireal, IMAGE *Iimag) { +IMAGE *ImageSplit(IMAGE *Icomp, IMAGE *Ireal, IMAGE *Iimag) +{ int x, y, rows, cols; float *real, *imag = NULL; double *dreal, *dimag = NULL; @@ -3085,7 +3155,8 @@ IMAGE *ImageSplit(IMAGE *Icomp, IMAGE *Ireal, IMAGE *Iimag) { Description: shrink an image using Gaussian blurred sampling. ----------------------------------------------------------------------*/ -IMAGE *ImageShrink(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageShrink(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Iin, *Iout, *Igaussian; int srows, scols, drows, dcols, x, y, xc, yc, xhalf, yhalf, xk, yk, ys; float smax, smin, xscale, yscale, *dpix; @@ -3101,7 +3172,8 @@ IMAGE *ImageShrink(IMAGE *Isrc, IMAGE *Idst) { Iin = ImageAlloc(srows, scols, PFFLOAT, 1); ImageCopy(Isrc, Iin); ImageValRange(Isrc, &smin, &smax); - } else + } + else Iin = Isrc; if (Idst->pixel_format != PFFLOAT) @@ -3179,7 +3251,8 @@ IMAGE *ImageShrink(IMAGE *Isrc, IMAGE *Idst) { Description: perform histogram equalization on an image ----------------------------------------------------------------------*/ -IMAGE *ImageHistoEqualize(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageHistoEqualize(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Iin, *Iout; struct hips_histo histogram; int ecode, count; @@ -3227,7 +3300,8 @@ IMAGE *ImageHistoEqualize(IMAGE *Isrc, IMAGE *Idst) { 0-255 ----------------------------------------------------------------------*/ #include "rescale.h" -IMAGE *ImageConvertToByte(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageConvertToByte(IMAGE *Isrc, IMAGE *Idst) +{ int MinPoint[2], MaxPoint[2], ecode; if (!Idst) Idst = ImageAlloc(Isrc->rows, Isrc->cols, PFBYTE, 1); @@ -3246,7 +3320,8 @@ IMAGE *ImageConvertToByte(IMAGE *Isrc, IMAGE *Idst) { static void break_now(void); static void break_now(void) {} -int ImageStatistics(IMAGE *Isrc, float *pmean, float *pvar) { +int ImageStatistics(IMAGE *Isrc, float *pmean, float *pvar) +{ long npix; float *pix, total, dif, mean; IMAGE *I = NULL; @@ -3254,7 +3329,8 @@ int ImageStatistics(IMAGE *Isrc, float *pmean, float *pvar) { if (Isrc->pixel_format != PFFLOAT) { I = ImageAlloc(I->rows, I->cols, PFFLOAT, 1); ImageCopy(Isrc, I); - } else + } + else I = Isrc; npix = I->numpix; @@ -3292,7 +3368,8 @@ int ImageStatistics(IMAGE *Isrc, float *pmean, float *pvar) { Description: pad an image with zeros out to the next power of 2. ----------------------------------------------------------------------*/ -IMAGE *ImageZeroPad(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageZeroPad(IMAGE *Isrc, IMAGE *Idst) +{ int drows, dcols, scols, srows, dcol, drow; scols = Isrc->cols; @@ -3315,7 +3392,8 @@ IMAGE *ImageZeroPad(IMAGE *Isrc, IMAGE *Idst) { Description: extract the interior region of a zero-padded image ----------------------------------------------------------------------*/ -IMAGE *ImageUnpad(IMAGE *Isrc, IMAGE *Idst, int rows, int cols) { +IMAGE *ImageUnpad(IMAGE *Isrc, IMAGE *Idst, int rows, int cols) +{ int row0, col0; if (!Idst) Idst = ImageAlloc(rows, cols, Isrc->pixel_format, Isrc->num_frame); @@ -3335,7 +3413,8 @@ IMAGE *ImageUnpad(IMAGE *Isrc, IMAGE *Idst, int rows, int cols) { Description: determine whether the values in an image are valid or not ----------------------------------------------------------------------*/ -int ImageValid(IMAGE *I) { +int ImageValid(IMAGE *I) +{ long size, total, bad, swapped_bad; float *fpix; double *dpix, exponent, val; @@ -3484,7 +3563,8 @@ int ImageValid(IMAGE *I) { Description: compute the pixel entropy of an image ----------------------------------------------------------------------*/ -double ImageEntropy(IMAGE *I, int pairflag) { +double ImageEntropy(IMAGE *I, int pairflag) +{ IMAGE *Itmp = NULL, *Ibyte; int *table, ecode, nframes, frame, count; double total_entropy = 0.0; @@ -3529,7 +3609,8 @@ double ImageEntropy(IMAGE *I, int pairflag) { Description: downsample an image by 2 (no lowpass filtering) ----------------------------------------------------------------------*/ -IMAGE *ImageDownsample2(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageDownsample2(IMAGE *Isrc, IMAGE *Idst) +{ int srows, scols, drows, dcols, drow, dcol; float *sptr, *dptr; @@ -3564,7 +3645,8 @@ IMAGE *ImageDownsample2(IMAGE *Isrc, IMAGE *Idst) { downsample an image by 2 in the x direction (no lowpass filtering) ----------------------------------------------------------------------*/ -IMAGE *ImageDownsample2Horizontal(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageDownsample2Horizontal(IMAGE *Isrc, IMAGE *Idst) +{ int srows, scols, drows, dcols, drow, dcol; byte *sptr, *dptr; @@ -3600,7 +3682,8 @@ IMAGE *ImageDownsample2Horizontal(IMAGE *Isrc, IMAGE *Idst) { upsample an image by 2 using a peg filter for interpolation (convolution with 2x2 array of ones) ----------------------------------------------------------------------*/ -IMAGE *ImageUpsample2(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageUpsample2(IMAGE *Isrc, IMAGE *Idst) +{ static IMAGE *Itmp = NULL; int srows, scols, drows, dcols, srow, scol; float *sptr, *dptr; @@ -3623,7 +3706,8 @@ IMAGE *ImageUpsample2(IMAGE *Isrc, IMAGE *Idst) { if (!ImageCheckSize(Idst, Itmp, 0, 0, 0)) { if (Itmp) ImageFree(&Itmp); Itmp = ImageAlloc(drows, dcols, Isrc->pixel_format, Isrc->num_frame); - } else + } + else ImageSetSize(Itmp, drows, dcols); /* first interleave zeros in the final-sized image */ @@ -3648,7 +3732,8 @@ IMAGE *ImageUpsample2(IMAGE *Isrc, IMAGE *Idst) { calculate the Root Mean-Squared difference between two images. ----------------------------------------------------------------------*/ -float ImageRMSDifference(IMAGE *I1_in, IMAGE *I2_in) { +float ImageRMSDifference(IMAGE *I1_in, IMAGE *I2_in) +{ float dif, rms, *pix1, *pix2; int width, height, x, y, frame; IMAGE *I1, *I2; @@ -3658,13 +3743,15 @@ float ImageRMSDifference(IMAGE *I1_in, IMAGE *I2_in) { if (I1_in->pixel_format != PFFLOAT) { I1 = ImageAlloc(height, width, PFFLOAT, 1); ImageCopy(I1_in, I1); - } else + } + else I1 = I1_in; if (I2_in->pixel_format != PFFLOAT) { I2 = ImageAlloc(height, width, PFFLOAT, 1); ImageCopy(I2_in, I2); - } else + } + else I2 = I2_in; rms = 0.0f; diff --git a/utils/imageio.c b/utils/imageio.c index 34d1219e878..1a5ff2ce19c 100644 --- a/utils/imageio.c +++ b/utils/imageio.c @@ -99,7 +99,8 @@ static byte endian = END_UNDEF; Description ------------------------------------------------------*/ -int ImageWrite(IMAGE *I, const char *fname) { +int ImageWrite(IMAGE *I, const char *fname) +{ FILE *fp; // int ecode; @@ -112,7 +113,8 @@ int ImageWrite(IMAGE *I, const char *fname) { return (0); } -static byte FindMachineEndian(void) { +static byte FindMachineEndian(void) +{ short int word = 0x0001; char *bite = (char *)&word; return (bite[0] ? END_SMALL : END_BIG); @@ -125,7 +127,8 @@ static byte FindMachineEndian(void) { Description ------------------------------------------------------*/ -int ImageFWrite(IMAGE *I, FILE *fp, const char *fname) { +int ImageFWrite(IMAGE *I, FILE *fp, const char *fname) +{ byte *image; int ecode, type, frame; char buf[100]; @@ -175,7 +178,8 @@ int ImageFWrite(IMAGE *I, FILE *fp, const char *fname) { return (0); } -static void ImageSwapEndian(IMAGE *I) { +static void ImageSwapEndian(IMAGE *I) +{ DCPIX *dcpix, dcval; CPIX *cpix, cval; double *dpix, dval; @@ -229,7 +233,8 @@ static void ImageSwapEndian(IMAGE *I) { Description ------------------------------------------------------*/ -IMAGE *ImageFRead(FILE *fp, const char *fname, int start, int nframes) { +IMAGE *ImageFRead(FILE *fp, const char *fname, int start, int nframes) +{ int ecode, end_frame, frame, count = 1; IMAGE *I; byte *startpix, end = END_UNDEF; @@ -250,7 +255,8 @@ IMAGE *ImageFRead(FILE *fp, const char *fname, int start, int nframes) { { start = 0; nframes = I->num_frame; - } else /* read only specified frames */ + } + else /* read only specified frames */ { if (fseek(fp, (long)I->sizeimage * (long)start, SEEK_CUR) < 0) { ImageFree(&I); @@ -297,7 +303,8 @@ IMAGE *ImageFRead(FILE *fp, const char *fname, int start, int nframes) { Description ------------------------------------------------------*/ -IMAGE *ImageReadFrames(const char *fname, int start, int nframes) { +IMAGE *ImageReadFrames(const char *fname, int start, int nframes) +{ IMAGE *I; FILE *fp; @@ -315,7 +322,8 @@ IMAGE *ImageReadFrames(const char *fname, int start, int nframes) { Description ------------------------------------------------------*/ -IMAGE *ImageReadHeader(const char *fname) { +IMAGE *ImageReadHeader(const char *fname) +{ IMAGE *I = NULL; FILE *fp; int type, frame; @@ -340,7 +348,8 @@ IMAGE *ImageReadHeader(const char *fname) { Description ------------------------------------------------------*/ -IMAGE *ImageFReadHeader(FILE *fp, const char *fname) { +IMAGE *ImageFReadHeader(FILE *fp, const char *fname) +{ IMAGE *I = NULL; int ecode; int type, frame; @@ -400,7 +409,8 @@ IMAGE *ImageFReadHeader(FILE *fp, const char *fname) { read an image from file and convert it to the specified format. ------------------------------------------------------*/ -IMAGE *ImageReadType(const char *fname, int pixel_format) { +IMAGE *ImageReadType(const char *fname, int pixel_format) +{ IMAGE *Itmp, *I; Itmp = ImageRead(fname); @@ -409,7 +419,8 @@ IMAGE *ImageReadType(const char *fname, int pixel_format) { I = ImageAlloc(Itmp->rows, Itmp->cols, pixel_format, Itmp->num_frame); ImageCopy(Itmp, I); ImageFree(&Itmp); - } else + } + else I = Itmp; return (I); @@ -421,7 +432,8 @@ IMAGE *ImageReadType(const char *fname, int pixel_format) { Description ------------------------------------------------------*/ -IMAGE *ImageRead(const char *fname) { +IMAGE *ImageRead(const char *fname) +{ IMAGE *I = NULL; MATRIX *mat; FILE *fp; @@ -478,7 +490,8 @@ IMAGE *ImageRead(const char *fname) { Description ------------------------------------------------------*/ -int ImageType(const char *fname) { +int ImageType(const char *fname) +{ char *dot, buf[200]; strcpy(buf, fname); @@ -498,7 +511,8 @@ int ImageType(const char *fname) { Description ------------------------------------------------------*/ -int ImageFrame(const char *fname) { +int ImageFrame(const char *fname) +{ char *number, buf[200]; int frame; @@ -508,7 +522,8 @@ int ImageFrame(const char *fname) { if (number) { sscanf(number + 1, "%d", &frame); *number = 0; - } else + } + else frame = 0; return (frame); @@ -522,7 +537,8 @@ int ImageFrame(const char *fname) { header and data space for it. Returns the newly allocated image. ----------------------------------------------------------------------*/ -int ImageReadInto(const char *fname, IMAGE *I, int image_no) { +int ImageReadInto(const char *fname, IMAGE *I, int image_no) +{ FILE *fp; int ecode; @@ -546,7 +562,8 @@ int ImageReadInto(const char *fname, IMAGE *I, int image_no) { Description: write a hips image to file 'fname' ----------------------------------------------------------------------*/ -int ImageWriteFrames(IMAGE *image, const char *fname, int start, int nframes) { +int ImageWriteFrames(IMAGE *image, const char *fname, int start, int nframes) +{ IMAGE *tmp_image; tmp_image = ImageAlloc(image->rows, image->cols, image->pixel_format, nframes); @@ -561,7 +578,8 @@ int ImageWriteFrames(IMAGE *image, const char *fname, int start, int nframes) { Description: decompose a file name, extracting the type and the frame #. ----------------------------------------------------------------------*/ -int ImageUnpackFileName(const char *inFname, int *pframe, int *ptype, char *outFname) { +int ImageUnpackFileName(const char *inFname, int *pframe, int *ptype, char *outFname) +{ char *number, *dot, buf[STRLEN]; if (inFname != outFname) strcpy(outFname, inFname); @@ -572,7 +590,8 @@ int ImageUnpackFileName(const char *inFname, int *pframe, int *ptype, char *outF { if (sscanf(number + 1, "%d", pframe) < 1) *pframe = -1; *number = 0; - } else + } + else *pframe = -1; if (dot) { @@ -593,7 +612,8 @@ int ImageUnpackFileName(const char *inFname, int *pframe, int *ptype, char *outF *ptype = RGBI_IMAGE; else *ptype = HIPS_IMAGE; - } else + } + else *ptype = HIPS_IMAGE; return (NO_ERROR); @@ -604,7 +624,8 @@ int ImageUnpackFileName(const char *inFname, int *pframe, int *ptype, char *outF Description: return the number of frames stored in the file 'fname' ----------------------------------------------------------------------*/ -int ImageNumFrames(const char *fname) { +int ImageNumFrames(const char *fname) +{ IMAGE I; FILE *fp; int frame, type, ecode, nframes; @@ -632,7 +653,8 @@ int ImageNumFrames(const char *fname) { append an image to the end of a hips sequence file, incrementing the number of frames recorded in the header. ----------------------------------------------------------------------*/ -int ImageAppend(IMAGE *I, const char *fname) { +int ImageAppend(IMAGE *I, const char *fname) +{ FILE *fp; int ecode, frame = 0, nframes; IMAGE Iheader, *Iframe; @@ -674,7 +696,8 @@ int ImageAppend(IMAGE *I, const char *fname) { ErrorReturn(-4, (ERROR_BADFILE, "ImageAppend: fwrite_image frame %d failed (%d)\n", ecode, frame)); } unlink(tmpname); - } else /* seek back to start and increment # of frames */ + } + else /* seek back to start and increment # of frames */ { if (fseek(fp, 0L, SEEK_SET) < 0) ErrorReturn(-2, (ERROR_BADFILE, "ImageAppend(%s): could not seek to end")); ecode = fwrite_header(fp, &Iheader, fname); @@ -699,7 +722,8 @@ int ImageAppend(IMAGE *I, const char *fname) { Read a TIFF image from a file. ----------------------------------------------------------------------*/ -static IMAGE *TiffReadImage(const char *fname, int frame0) { +static IMAGE *TiffReadImage(const char *fname, int frame0) +{ IMAGE *I; TIFF *tif = TIFFOpen(fname, "r"); int type = PFBYTE; // just make compiler happy @@ -958,7 +982,8 @@ static IMAGE *TiffReadImage(const char *fname, int frame0) { *IMAGEpix(I, col + bit, index) = ((byte_ & bitmask) > 0); bitmask = bitmask << 1; } - } else // fillorder == FILLORDER_MSB2LSB + } + else // fillorder == FILLORDER_MSB2LSB { for (bitmask = 0x01 << 7, bit = 0; bit < 8; bit++) { if (col + bit == Gx && index == Gy) DiagBreak(); @@ -970,7 +995,8 @@ static IMAGE *TiffReadImage(const char *fname, int frame0) { free(bitmap); } - } else if (nsamples == 4) // RGB model + alpha + } + else if (nsamples == 4) // RGB model + alpha { int s; unsigned char *ipix; @@ -992,7 +1018,8 @@ static IMAGE *TiffReadImage(const char *fname, int frame0) { ipix += nsamples; } free(buf); - } else if (nsamples == 3) // RGB model + } + else if (nsamples == 3) // RGB model { switch (bits_per_sample) { default: @@ -1073,7 +1100,8 @@ void __eprintf(void) {} Description: Read the header info from a tiff image. ----------------------------------------------------------------------*/ -static IMAGE *TiffReadHeader(const char *fname, IMAGE *I) { +static IMAGE *TiffReadHeader(const char *fname, IMAGE *I) +{ TIFF *tif = TIFFOpen(fname, "r"); int width, height, bits_per_sample; //, ret, extra_samples; short nsamples; @@ -1130,7 +1158,8 @@ static IMAGE *TiffReadHeader(const char *fname, IMAGE *I) { Description: Write an image to disk in TIFF format. ----------------------------------------------------------------------*/ -static int TiffWriteImage(IMAGE *I, const char *fname, int frame) { +static int TiffWriteImage(IMAGE *I, const char *fname, int frame) +{ TIFF *out; short bits_per_sample, samples_per_pixel, sample_format; int row, frames; @@ -1249,18 +1278,21 @@ static IMAGE *JPEGReadHeader(FILE *fp, IMAGE *I) { return (NULL); } static int JPEGWriteImage(IMAGE *I, const char *fname, int frame) { return (0); } static IMAGE *PGMReadImage(const char *fname) { ErrorReturn(NULL, (ERROR_UNSUPPORTED, "pgm not supported on IRIX")); } static IMAGE *PGMReadHeader(FILE *fp, IMAGE *I) { ErrorReturn(NULL, (ERROR_UNSUPPORTED, "pgm not supported on IRIX")); } -static int PGMWriteImage(IMAGE *I, const char *fname, int frame) { +static int PGMWriteImage(IMAGE *I, const char *fname, int frame) +{ ErrorReturn(NULL, (ERROR_UNSUPPORTED, "pgm not supported on IRIX")); } static IMAGE *PPMReadImage(const char *fname) { ErrorReturn(NULL, (ERROR_UNSUPPORTED, "ppm not supported on IRIX")); } static IMAGE *PPMReadHeader(FILE *fp, IMAGE *I) { ErrorReturn(NULL, (ERROR_UNSUPPORTED, "ppm not supported on IRIX")); } static IMAGE *PBMReadImage(const char *fname) { ErrorReturn(NULL, (ERROR_UNSUPPORTED, "pbm not supported on IRIX")); } static IMAGE *PBMReadHeader(FILE *fp, IMAGE *I) { ErrorReturn(NULL, (ERROR_UNSUPPORTED, "pbm not supported on IRIX")); } -static int PPMWriteImage(IMAGE *I, const char *fname, int frame) { +static int PPMWriteImage(IMAGE *I, const char *fname, int frame) +{ ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "ppm not supported on IRIX")); } #else -static IMAGE *PGMReadHeader(FILE *fp, IMAGE *I) { +static IMAGE *PGMReadHeader(FILE *fp, IMAGE *I) +{ int rows, cols, format; gray maxval; @@ -1274,7 +1306,8 @@ static IMAGE *PGMReadHeader(FILE *fp, IMAGE *I) { return I; } -static IMAGE *PGMReadImage(const char *fname) { +static IMAGE *PGMReadImage(const char *fname) +{ FILE *infile; IMAGE *I; int rows, cols, format, i; @@ -1292,7 +1325,8 @@ static IMAGE *PGMReadImage(const char *fname) { return I; } -static int PPMWriteImage(IMAGE *I, const char *fname, int frame) { +static int PPMWriteImage(IMAGE *I, const char *fname, int frame) +{ FILE *outf; int i, j; byte pval; @@ -1322,7 +1356,8 @@ static int PPMWriteImage(IMAGE *I, const char *fname, int frame) { return NO_ERROR; } -static int PGMWriteImage(IMAGE *I, const char *fname, int frame) { +static int PGMWriteImage(IMAGE *I, const char *fname, int frame) +{ FILE *outf; int i; @@ -1340,7 +1375,8 @@ static int PGMWriteImage(IMAGE *I, const char *fname, int frame) { return NO_ERROR; } -static IMAGE *PBMReadImage(const char *fname) { +static IMAGE *PBMReadImage(const char *fname) +{ FILE *infile; IMAGE *I; int rows, cols, i, j; @@ -1362,7 +1398,8 @@ static IMAGE *PBMReadImage(const char *fname) { return I; } -static IMAGE *PPMReadImage(const char *fname) { +static IMAGE *PPMReadImage(const char *fname) +{ FILE *infile; IMAGE *I; int rows, cols, format, i, j; @@ -1390,7 +1427,8 @@ static IMAGE *PPMReadImage(const char *fname) { return I; } -static IMAGE *PBMReadHeader(FILE *fp, IMAGE *I) { +static IMAGE *PBMReadHeader(FILE *fp, IMAGE *I) +{ int rows, cols, format; pbm_readpbminit(fp, &cols, &rows, &format); @@ -1403,7 +1441,8 @@ static IMAGE *PBMReadHeader(FILE *fp, IMAGE *I) { return I; } -static IMAGE *PPMReadHeader(FILE *fp, IMAGE *I) { +static IMAGE *PPMReadHeader(FILE *fp, IMAGE *I) +{ int rows, cols, format; gray maxval; @@ -1417,7 +1456,8 @@ static IMAGE *PPMReadHeader(FILE *fp, IMAGE *I) { return I; } -static IMAGE *JPEGReadImage(const char *fname) { +static IMAGE *JPEGReadImage(const char *fname) +{ FILE *infile; IMAGE *I; struct jpeg_decompress_struct cinfo; @@ -1450,7 +1490,8 @@ static IMAGE *JPEGReadImage(const char *fname) { return I; } -static IMAGE *JPEGReadHeader(FILE *fp, IMAGE *I) { +static IMAGE *JPEGReadHeader(FILE *fp, IMAGE *I) +{ struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -1470,7 +1511,8 @@ static IMAGE *JPEGReadHeader(FILE *fp, IMAGE *I) { return (I); } -static int JPEGWriteImage(IMAGE *I, const char *fname, int frame) { +static int JPEGWriteImage(IMAGE *I, const char *fname, int frame) +{ FILE *outf; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; diff --git a/utils/imautils.c b/utils/imautils.c index 18ef99a2fb0..37ccfafedef 100644 --- a/utils/imautils.c +++ b/utils/imautils.c @@ -47,7 +47,8 @@ static int imaGetKeyEntryNo(const char *key); the caller is responsible for dealloc. If the architecture is Intel0-based, the byte order is reversed based on nybtes. --------------------------------------------------------------------*/ -void *imaLoadVal(FILE *imafp, int offset, int nbytes, int nitems, void *pval) { +void *imaLoadVal(FILE *imafp, int offset, int nbytes, int nitems, void *pval) +{ int r; /* Go to the designated offset relative to the start of the file*/ @@ -91,7 +92,8 @@ void *imaLoadVal(FILE *imafp, int offset, int nbytes, int nitems, void *pval) { string, and, for strings, the number of characters in the string. The order is arbitrary. --------------------------------------------------------------------*/ -void MkImaDictionary(void) { +void MkImaDictionary(void) +{ // extern int nImaDictionary, ImaDictionaryGood; int n = 0; @@ -168,7 +170,8 @@ void MkImaDictionary(void) { } /*-------------------------------------------------------------------- --------------------------------------------------------------------*/ -static int imaSetDictEntry(int nthEntry, char *key, int offset, char *typestring, int nitems) { +static int imaSetDictEntry(int nthEntry, char *key, int offset, char *typestring, int nitems) +{ int type; if (nthEntry >= NMAX_IMA_DICTIONARY) { @@ -199,7 +202,8 @@ static int imaSetDictEntry(int nthEntry, char *key, int offset, char *typestring This is just a list of the items in the dictionary, not the values from a file. ---------------------------------------------------------------*/ -void DumpImaDictionary(FILE *fp) { +void DumpImaDictionary(FILE *fp) +{ // extern IMA_DICTIONARY_ENTRY ImaDictionary[NMAX_IMA_DICTIONARY]; // extern int nImaDictionary, ImaDictionaryGood; int n; @@ -218,7 +222,8 @@ void DumpImaDictionary(FILE *fp) { DumpImaDictionaryVal() - dumps the dictionary to a file stream, including the corresponding values from a given ima file. ---------------------------------------------------------------*/ -int DumpImaDictionaryVal(FILE *fp, const char *imafile) { +int DumpImaDictionaryVal(FILE *fp, const char *imafile) +{ // extern IMA_DICTIONARY_ENTRY ImaDictionary[NMAX_IMA_DICTIONARY]; // extern int nImaDictionary, ImaDictionaryGood; char *key, *typestring; @@ -284,7 +289,8 @@ int DumpImaDictionaryVal(FILE *fp, const char *imafile) { value and the data type. The value is derefferenced based on the data type and printed. No spaces or newlines are printed. --------------------------------------------------------------------*/ -int imaPrintVal(FILE *fp, int type, void *pval) { +int imaPrintVal(FILE *fp, int type, void *pval) +{ switch (type) { case IMA_TYPE_SHORT: fprintf(fp, "%d", *((short *)pval)); @@ -313,7 +319,8 @@ int imaPrintVal(FILE *fp, int type, void *pval) { imaLoadValFromKey() - loads a value from a file stream given the key in the IMA dictionary. --------------------------------------------------------------------*/ -void *imaLoadValFromKey(FILE *imafp, const char *key, void *pval) { +void *imaLoadValFromKey(FILE *imafp, const char *key, void *pval) +{ // extern IMA_DICTIONARY_ENTRY ImaDictionary[NMAX_IMA_DICTIONARY]; // extern int ImaDictionaryGood; int n, offset, typesize, nitems, nbytes; @@ -349,7 +356,8 @@ void *imaLoadValFromKey(FILE *imafp, const char *key, void *pval) { imaTypeFromKey() - returns the interger code of the data type (IMA_TYPE_XXX) of an entry in the IMA dictionary given the key. --------------------------------------------------------------------*/ -int imaTypeFromKey(const char *key) { +int imaTypeFromKey(const char *key) +{ // extern IMA_DICTIONARY_ENTRY ImaDictionary[NMAX_IMA_DICTIONARY]; // extern int ImaDictionaryGood; int n; @@ -364,7 +372,8 @@ int imaTypeFromKey(const char *key) { /*-------------------------------------------------------------------- imaGetKeyEntryNo() - return the entry number of the key. --------------------------------------------------------------------*/ -static int imaGetKeyEntryNo(const char *key) { +static int imaGetKeyEntryNo(const char *key) +{ // extern IMA_DICTIONARY_ENTRY ImaDictionary[NMAX_IMA_DICTIONARY]; // extern int nImaDictionary, ImaDictionaryGood; int n; @@ -381,7 +390,8 @@ static int imaGetKeyEntryNo(const char *key) { imaTypeFromString() - returns the interger type code (IMA_TYPE_XXX) given the string name of the type. --------------------------------------------------------------------*/ -int imaTypeFromString(const char *typestring) { +int imaTypeFromString(const char *typestring) +{ int i; for (i = 0; i < 6; i++) { // printf("%d %s\n",i,imaTypeString[i]); @@ -398,7 +408,8 @@ int imaTypeFromString(const char *typestring) { distance between slices is computed from the slice thickness and the distance factor. --------------------------------------------------------------------*/ -IMAFILEINFO *imaLoadFileInfo(const char *imafile) { +IMAFILEINFO *imaLoadFileInfo(const char *imafile) +{ IMAFILEINFO *ifi; FILE *fp; int itmp, len, err; @@ -551,7 +562,8 @@ IMAFILEINFO *imaLoadFileInfo(const char *imafile) { if (!ifi->IsMosaic) { ifi->NFilesPerFrame = ifi->VolDim[2]; ifi->NFrames = 1; - } else { + } + else { nVolVoxs = ifi->VolDim[0] * ifi->VolDim[1] * ifi->VolDim[2]; nMosVoxs = ifi->NImageRows * ifi->NImageCols; ifi->NFilesPerFrame = (int)(ceil((float)nVolVoxs / nMosVoxs)); @@ -572,7 +584,8 @@ IMAFILEINFO *imaLoadFileInfo(const char *imafile) { return (ifi); } /*--------------------------------------------------------------------*/ -short *imaReadPixelData(IMAFILEINFO *ifi, short *PixelData) { +short *imaReadPixelData(IMAFILEINFO *ifi, short *PixelData) +{ FILE *fp; int npixels, alloced = 0; int nread, r; @@ -622,7 +635,8 @@ short *imaReadPixelData(IMAFILEINFO *ifi, short *PixelData) { return (PixelData); } /*--------------------------------------------------------------------*/ -int imaDumpFileInfo(FILE *fp, IMAFILEINFO *ifi) { +int imaDumpFileInfo(FILE *fp, IMAFILEINFO *ifi) +{ fprintf(fp, "FileName %s\n", ifi->FileName); fprintf(fp, "PatientName %s\n", ifi->PatientName); fprintf(fp, "PatientDOB %s\n", ifi->PatientDOB); @@ -667,7 +681,8 @@ int imaDumpFileInfo(FILE *fp, IMAFILEINFO *ifi) { /*-------------------------------------------------------------------- imaParseName() - studyno-seriesno-imageno.ima --------------------------------------------------------------------*/ -int imaParseName(const char *imafile, int *StudyNo, int *SeriesNo, int *ImageNo, char *Separator) { +int imaParseName(const char *imafile, int *StudyNo, int *SeriesNo, int *ImageNo, char *Separator) +{ char *imabase; int baselen, n, m; char tmpstr[500]; @@ -750,7 +765,8 @@ int imaParseName(const char *imafile, int *StudyNo, int *SeriesNo, int *ImageNo, imaHasIMAExtension() - returns 1 if the given file name ends in a .ima (or .IMA) extension. --------------------------------------------------------------------*/ -int imaHasIMAExtension(const char *filename) { +int imaHasIMAExtension(const char *filename) +{ char *ext; ext = fio_extension(filename); @@ -765,7 +781,8 @@ int imaHasIMAExtension(const char *filename) { file. Returns 0 if it is not a Siemens IMA file or if the file does not exist. --------------------------------------------------------------------*/ -int imaIsSiemensIMA(const char *imafile) { +int imaIsSiemensIMA(const char *imafile) +{ FILE *fp; char *Manufacturer; @@ -793,7 +810,8 @@ int imaIsSiemensIMA(const char *imafile) { file in the series, and up to determine the last. The number in the series is then last-first+1. --------------------------------------------------------------------*/ -int imaCountFilesInSeries(const char *imafile, int *FirstImageNo) { +int imaCountFilesInSeries(const char *imafile, int *FirstImageNo) +{ int StudyNo, SeriesNo, ImageNo, LastImageNo; char *imadir = NULL, *imaext; int err, n; diff --git a/utils/inverse.c b/utils/inverse.c index 052d83ca508..3392055787e 100644 --- a/utils/inverse.c +++ b/utils/inverse.c @@ -33,7 +33,8 @@ #include "macros.h" #include "matrix.h" -IOP *IOPRead(char *fname, int hemi) { +IOP *IOPRead(char *fname, int hemi) +{ IOP *iop; int i, j, k, jc, d, dipoles_in_decimation; FILE *fp; @@ -117,7 +118,8 @@ IOP *IOPRead(char *fname, int hemi) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } iop->dipole_vertices[j] = d; - } else { + } + else { if (fscanf(fp, "%*d") != 0) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } @@ -131,7 +133,8 @@ IOP *IOPRead(char *fname, int hemi) { *MATRIX_RELT(iop->pvals, j + 1, 1) = f; f = fabs(f); if (f < iop->pthresh) iop->pthresh = f; - } else { + } + else { if (fscanf(fp, "%*f") != 0) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } @@ -146,7 +149,8 @@ IOP *IOPRead(char *fname, int hemi) { #if 0 vertex[iop->dipole_vertices[j]].val = f; #endif - } else { + } + else { if (fscanf(fp, "%*f") != 0) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } @@ -160,7 +164,8 @@ IOP *IOPRead(char *fname, int hemi) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } *MATRIX_RELT(iop->m_iop, j * iop->ndipoles_per_location + jc + 1, k + 1) = f; - } else { + } + else { if (fscanf(fp, "%*f") != 0) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } @@ -177,7 +182,8 @@ IOP *IOPRead(char *fname, int hemi) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } *MATRIX_RELT(iop->m_forward, k + 1, j * iop->ndipoles_per_location + jc + 1) = f; - } else { + } + else { if (fscanf(fp, "%*f") != 0) { ErrorPrintf(ERROR_BAD_FILE, "IOPRead: can't read parameter\n"); } @@ -187,7 +193,8 @@ IOP *IOPRead(char *fname, int hemi) { } } } - } else { + } + else { printf("Can't read binary .iop files\n"); } fclose(fp); @@ -201,7 +208,8 @@ IOP *IOPRead(char *fname, int hemi) { return (iop); } int IOPWrite(IOP *iop, char *fname) { return (NO_ERROR); } -int IOPFree(IOP **piop) { +int IOPFree(IOP **piop) +{ IOP *iop; iop = *piop; @@ -215,7 +223,8 @@ int IOPFree(IOP **piop) { return (NO_ERROR); } -int IOPNormalize(IOP *iop) { +int IOPNormalize(IOP *iop) +{ int j, k, jc; double sum, val; @@ -236,7 +245,8 @@ int IOPNormalize(IOP *iop) { } return (NO_ERROR); } -MATRIX *IOPapplyInverseOperator(IOP *iop, REC *rec, MATRIX *m_sol) { +MATRIX *IOPapplyInverseOperator(IOP *iop, REC *rec, MATRIX *m_sol) +{ m_sol = MatrixMultiply(iop->m_iop, rec->m_data, NULL); return (m_sol); } diff --git a/utils/ipmpar.c b/utils/ipmpar.c index 391625cc58c..e611640c636 100644 --- a/utils/ipmpar.c +++ b/utils/ipmpar.c @@ -90,7 +90,8 @@ int ipmpar(int *); ----------------------------------------------------------------------- .. Scalar Arguments .. */ -int ipmpar(int *i) { +int ipmpar(int *i) +{ static int imach[11]; static int ipmpar; /* MACHINE CONSTANTS FOR AMDAHL MACHINES. */ diff --git a/utils/joint_histo.c b/utils/joint_histo.c index f00cc835d8e..1bbfb21ddfa 100644 --- a/utils/joint_histo.c +++ b/utils/joint_histo.c @@ -40,7 +40,8 @@ inline float flmax(float a, float b) { return (a > b) ? a : b; } Description ------------------------------------------------------*/ -int JHISTOfree(JOINT_HISTOGRAM **pjhisto) { +int JHISTOfree(JOINT_HISTOGRAM **pjhisto) +{ JOINT_HISTOGRAM *jhisto; jhisto = *pjhisto; @@ -49,10 +50,12 @@ int JHISTOfree(JOINT_HISTOGRAM **pjhisto) { if (jhisto->counts) { free(jhisto->counts); jhisto->counts = NULL; - } else + } + else DiagBreak(); free(jhisto); - } else + } + else DiagBreak(); return (NO_ERROR); @@ -65,7 +68,8 @@ int JHISTOfree(JOINT_HISTOGRAM **pjhisto) { Description ------------------------------------------------------*/ -int JHISTOdump(JOINT_HISTOGRAM *jhisto, FILE *fp) { +int JHISTOdump(JOINT_HISTOGRAM *jhisto, FILE *fp) +{ int bin_no_1, bin_no_2; if (!jhisto) @@ -81,7 +85,8 @@ int JHISTOdump(JOINT_HISTOGRAM *jhisto, FILE *fp) { return (NO_ERROR); } -int JHISTOwriteInto(JOINT_HISTOGRAM *h, FILE *fp) { +int JHISTOwriteInto(JOINT_HISTOGRAM *h, FILE *fp) +{ int b1, b2; fwriteInt(h->nbins_1, fp); @@ -96,7 +101,8 @@ int JHISTOwriteInto(JOINT_HISTOGRAM *h, FILE *fp) { return (NO_ERROR); } -JOINT_HISTOGRAM *JHISTOreadFrom(FILE *fp) { +JOINT_HISTOGRAM *JHISTOreadFrom(FILE *fp) +{ int b1, b2, nbins_1, nbins_2; //, sample_count; JOINT_HISTOGRAM *jh; @@ -114,7 +120,8 @@ JOINT_HISTOGRAM *JHISTOreadFrom(FILE *fp) { return (jh); } -JOINT_HISTOGRAM *JHISTOalloc(int nbins_1, int nbins_2) { +JOINT_HISTOGRAM *JHISTOalloc(int nbins_1, int nbins_2) +{ JOINT_HISTOGRAM *jhisto; jhisto = (JOINT_HISTOGRAM *)calloc(1, sizeof(JOINT_HISTOGRAM)); @@ -131,7 +138,8 @@ JOINT_HISTOGRAM *JHISTOalloc(int nbins_1, int nbins_2) { return (jhisto); } -JOINT_HISTOGRAM *JHISTOrealloc(JOINT_HISTOGRAM *jhisto, int nbins_1, int nbins_2) { +JOINT_HISTOGRAM *JHISTOrealloc(JOINT_HISTOGRAM *jhisto, int nbins_1, int nbins_2) +{ if (jhisto == NULL) return (JHISTOalloc(nbins_1, nbins_2)); if (jhisto->counts) free(jhisto->counts); @@ -146,7 +154,8 @@ JOINT_HISTOGRAM *JHISTOrealloc(JOINT_HISTOGRAM *jhisto, int nbins_1, int nbins_2 ////////////////// ////////////////// -int JHISTOfindBin(JOINT_HISTOGRAM *jhisto, double val1, double val2) { +int JHISTOfindBin(JOINT_HISTOGRAM *jhisto, double val1, double val2) +{ int bins1 = jhisto->nbins_1; int bins2 = jhisto->nbins_2; @@ -159,7 +168,8 @@ int JHISTOfindBin(JOINT_HISTOGRAM *jhisto, double val1, double val2) { return (i * bins2 + j); } -void JHISTOfill(MRI *mri1, MRI *mri2, JOINT_HISTOGRAM *jhisto) { +void JHISTOfill(MRI *mri1, MRI *mri2, JOINT_HISTOGRAM *jhisto) +{ // MRIcheckVolDims(mri1, mri2); int width = mri1->width; @@ -198,7 +208,8 @@ void JHISTOfill(MRI *mri1, MRI *mri2, JOINT_HISTOGRAM *jhisto) { fclose(fp); } -double JHISTOgetEntropy(JOINT_HISTOGRAM *jhisto) { +double JHISTOgetEntropy(JOINT_HISTOGRAM *jhisto) +{ double result = 0, p; int i, count; int total_bucket_count = jhisto->nbins_1 * jhisto->nbins_2; diff --git a/utils/kernel.c b/utils/kernel.c index 42fdf0a0944..5b064a84c2b 100644 --- a/utils/kernel.c +++ b/utils/kernel.c @@ -55,7 +55,8 @@ Description: ----------------------------------------------------------------------*/ -KIMAGE *KernelImageAlloc(int rows, int cols, int krows, int kcols) { +KIMAGE *KernelImageAlloc(int rows, int cols, int krows, int kcols) +{ KIMAGE *kimage; int kernel_bytes, row, col; @@ -82,7 +83,8 @@ KIMAGE *KernelImageAlloc(int rows, int cols, int krows, int kcols) { Description: ----------------------------------------------------------------------*/ -KIMAGE *KernelImageClone(KIMAGE *kimage) { +KIMAGE *KernelImageClone(KIMAGE *kimage) +{ KIMAGE *knew; knew = KernelImageAlloc(kimage->rows, kimage->cols, kimage->krows, kimage->kcols); @@ -93,7 +95,8 @@ KIMAGE *KernelImageClone(KIMAGE *kimage) { Description: ----------------------------------------------------------------------*/ -void KernelImageCopy(KIMAGE *ksrc, KIMAGE *kdst) { +void KernelImageCopy(KIMAGE *ksrc, KIMAGE *kdst) +{ int row, col; for (row = 0; row < ksrc->rows; row++) { @@ -105,7 +108,8 @@ void KernelImageCopy(KIMAGE *ksrc, KIMAGE *kdst) { Description: ----------------------------------------------------------------------*/ -void KernelCopy(KIMAGE *ksrc, KIMAGE *kdst, int src_row, int src_col, int dst_row, int dst_col) { +void KernelCopy(KIMAGE *ksrc, KIMAGE *kdst, int src_row, int src_col, int dst_row, int dst_col) +{ int row, col, cols; KERNEL *src_kernel, *dst_kernel; register float *src_w, *dst_w; @@ -126,7 +130,8 @@ void KernelCopy(KIMAGE *ksrc, KIMAGE *kdst, int src_row, int src_col, int dst_ro Description: ----------------------------------------------------------------------*/ -void KernelInit(KIMAGE *kimage, int row, int col) { +void KernelInit(KIMAGE *kimage, int row, int col) +{ KERNEL *kernel; int halfrows, halfcols, wrow; @@ -181,7 +186,8 @@ void KernelInit(KIMAGE *kimage, int row, int col) { Description: ----------------------------------------------------------------------*/ -void KernelImageFree(KIMAGE *kimage) { +void KernelImageFree(KIMAGE *kimage) +{ int row, col; for (row = 0; row < kimage->rows; row++) { @@ -198,7 +204,8 @@ void KernelImageFree(KIMAGE *kimage) { free all the contents of the kernel, but not the kernel itself ----------------------------------------------------------------------*/ -void KernelFree(KERNEL *kernel) { +void KernelFree(KERNEL *kernel) +{ int wrow; for (wrow = 0; wrow < kernel->rows; wrow++) free(kernel->weights[wrow]); @@ -210,7 +217,8 @@ void KernelFree(KERNEL *kernel) { Description: ----------------------------------------------------------------------*/ -void KernelImageDump(KIMAGE *kimage, FILE *fp) { +void KernelImageDump(KIMAGE *kimage, FILE *fp) +{ int row, col, krow, kcol; KERNEL *kernel; @@ -241,7 +249,8 @@ void KernelImageDump(KIMAGE *kimage, FILE *fp) { Description: ----------------------------------------------------------------------*/ -void KernelDiscount(KIMAGE *kimage, int row, int col, float weight) { +void KernelDiscount(KIMAGE *kimage, int row, int col, float weight) +{ KERNEL *kernel; register float *w; int cols; @@ -260,7 +269,8 @@ void KernelDiscount(KIMAGE *kimage, int row, int col, float weight) { Description: ----------------------------------------------------------------------*/ -void KernelUpdate(KIMAGE *ksrc, KIMAGE *kdst, int dst_row, int dst_col, int src_row, int src_col, float weight) { +void KernelUpdate(KIMAGE *ksrc, KIMAGE *kdst, int dst_row, int dst_col, int src_row, int src_col, float weight) +{ KERNEL *src_kernel, *dst_kernel; register float *w; int row, col, src_rows, src_cols, dst_rows, dst_cols, dst_row0, dst_col0, src_row0, src_col0, drow, dcol; @@ -304,7 +314,8 @@ void KernelUpdate(KIMAGE *ksrc, KIMAGE *kdst, int dst_row, int dst_col, int src_ Description: ----------------------------------------------------------------------*/ -void KernelImageNormalize(KIMAGE *kimage) { +void KernelImageNormalize(KIMAGE *kimage) +{ int row, col; for (row = 0; row < kimage->rows; row++) { @@ -316,7 +327,8 @@ void KernelImageNormalize(KIMAGE *kimage) { Description: ----------------------------------------------------------------------*/ -void KernelNormalize(KIMAGE *kimage, int row, int col) { +void KernelNormalize(KIMAGE *kimage, int row, int col) +{ KERNEL *kernel; register float *w, total; int krow, kcol, cols, krows, kcols; @@ -397,7 +409,8 @@ void KernelNormalize(KIMAGE *kimage, int row, int col) { Description: ----------------------------------------------------------------------*/ -void KernelImageConvolve(KIMAGE *kimage, IMAGE *src_image, IMAGE *dst_image) { +void KernelImageConvolve(KIMAGE *kimage, IMAGE *src_image, IMAGE *dst_image) +{ int src_row, src_rows, src_cols, start_col, start_row; int dst_row, dst_col, dst_rows, dst_cols; int krow, kcol, krows, kcols, row0, col0; @@ -437,14 +450,16 @@ void KernelImageConvolve(KIMAGE *kimage, IMAGE *src_image, IMAGE *dst_image) { { start_col = -col0; col0 = 0; - } else + } + else start_col = 0; if (row0 < 0) /* kernel extends off of left edge of image */ { start_row = -row0; row0 = 0; - } else + } + else start_row = 0; total = 0.0f; @@ -465,7 +480,8 @@ void KernelImageConvolve(KIMAGE *kimage, IMAGE *src_image, IMAGE *dst_image) { Description: ----------------------------------------------------------------------*/ -void KernelImageWrite(KIMAGE *kimage, char *fname, int argc, char *argv[]) { +void KernelImageWrite(KIMAGE *kimage, char *fname, int argc, char *argv[]) +{ IMAGE *image; int i; char str[100]; @@ -489,7 +505,8 @@ void KernelImageWrite(KIMAGE *kimage, char *fname, int argc, char *argv[]) { Description: ----------------------------------------------------------------------*/ -KIMAGE *KernelImageRead(char *fname) { +KIMAGE *KernelImageRead(char *fname) +{ KIMAGE *kimage; IMAGE *image; @@ -506,7 +523,8 @@ KIMAGE *KernelImageRead(char *fname) { Description: ----------------------------------------------------------------------*/ -IMAGE *KernelImageToSeq(KIMAGE *kimage) { +IMAGE *KernelImageToSeq(KIMAGE *kimage) +{ IMAGE *image; int num_frame, row, col, rows, cols, krow, kcol, krows, kcols, pix_per_frame, row0, col0, drow, dcol, npix, col_dif, row_dif; @@ -553,7 +571,8 @@ IMAGE *KernelImageToSeq(KIMAGE *kimage) { { kcol = -dcol; dcol = 0; - } else + } + else kcol = 0; npix = kcols - abs(col_dif); @@ -572,7 +591,8 @@ IMAGE *KernelImageToSeq(KIMAGE *kimage) { Description: ----------------------------------------------------------------------*/ -KIMAGE *KernelImageFromSeq(IMAGE *image) { +KIMAGE *KernelImageFromSeq(IMAGE *image) +{ int rows, cols, krows, kcols, row, col, krow, kcol, pix_per_frame, row0, col0, drow, dcol, npix, col_dif, row_dif; KERNEL *kernel; float *fsrc, *fdst, *fbase; @@ -621,7 +641,8 @@ KIMAGE *KernelImageFromSeq(IMAGE *image) { { kcol = -dcol; dcol = 0; - } else + } + else kcol = 0; npix = kcols - abs(col_dif); diff --git a/utils/kinput.c b/utils/kinput.c index 738b684ab5b..05b118aad7b 100644 --- a/utils/kinput.c +++ b/utils/kinput.c @@ -47,7 +47,8 @@ static float kinputGetPoint(HIPSPyramid *pyr, int x, int y, int level); Description: ----------------------------------------------------------------------*/ KINPUT *KinputAlloc( - int rows, int cols, int nscales, int input_size, float sigma, float sigma_scale_factor, int abs_gradient) { + int rows, int cols, int nscales, int input_size, float sigma, float sigma_scale_factor, int abs_gradient) +{ KINPUT *kinput; int scale; @@ -84,7 +85,8 @@ KINPUT *KinputAlloc( Description: ----------------------------------------------------------------------*/ -int KinputFree(KINPUT **pkinput) { +int KinputFree(KINPUT **pkinput) +{ KINPUT *kinput; int scale; @@ -112,7 +114,8 @@ int KinputFree(KINPUT **pkinput) { Description: ----------------------------------------------------------------------*/ -int KinputInit(KINPUT *kinput, IMAGE *image) { +int KinputInit(KINPUT *kinput, IMAGE *image) +{ int scale; #if USE_PYRAMID @@ -145,7 +148,8 @@ int KinputInit(KINPUT *kinput, IMAGE *image) { Description: ----------------------------------------------------------------------*/ -int KinputVector(KINPUT *kinput, int x0, int y0) { +int KinputVector(KINPUT *kinput, int x0, int y0) +{ int x, y, x1, y1, rows, cols, scale, neg_half, half_in; float *in, xval, yval; @@ -214,7 +218,8 @@ int KinputVector(KINPUT *kinput, int x0, int y0) { } #if USE_PYRAMID -static float kinputGetPoint(IMAGEPyramid *pyr, int x, int y, int level) { +static float kinputGetPoint(IMAGEPyramid *pyr, int x, int y, int level) +{ float val; int x1, x2, y1, y2, cols, rows, cols0, rows0; diff --git a/utils/label.c b/utils/label.c index d9667c97d12..5f4ef413bfb 100644 --- a/utils/label.c +++ b/utils/label.c @@ -56,7 +56,8 @@ static Transform *labelLoadTransform(const char *subject_name, const char *sdir, #define MAX_VERTICES 500000 /*----------------------------------------------------- ------------------------------------------------------*/ -LABEL *LabelReadFrom(const char *subject_name, FILE *fp) { +LABEL *LabelReadFrom(const char *subject_name, FILE *fp) +{ LABEL *area; char line[STRLEN], subjects_dir[STRLEN], *cp, *str; int vno, nlines; @@ -121,7 +122,8 @@ LABEL *LabelReadFrom(const char *subject_name, FILE *fp) { return (area); } -LABEL *LabelRead(const char *subject_name, const char *label_name) { +LABEL *LabelRead(const char *subject_name, const char *label_name) +{ LABEL *area; char fname[STRLEN], *cp, subjects_dir[STRLEN], lname[STRLEN]; char label_name0[STRLEN]; @@ -150,7 +152,8 @@ LABEL *LabelRead(const char *subject_name, const char *label_name) { label_name = lname; sprintf(fname, "%s/%s/label/%s.label", subjects_dir, subject_name, label_name); - } else { + } + else { strcpy(fname, label_name); cp = getenv("SUBJECTS_DIR"); if (!cp) @@ -189,7 +192,8 @@ LABEL *LabelRead(const char *subject_name, const char *label_name) { Description ------------------------------------------------------*/ -int LabelDump(FILE *fp, LABEL *area) { +int LabelDump(FILE *fp, LABEL *area) +{ int n; fprintf(fp, "label %s, from subject %s %s\n", area->name, area->subject_name, area->space); @@ -204,7 +208,8 @@ int LabelDump(FILE *fp, LABEL *area) { Description ------------------------------------------------------*/ -int LabelFree(LABEL **parea) { +int LabelFree(LABEL **parea) +{ LABEL *area; area = *parea; @@ -222,7 +227,8 @@ int LabelFree(LABEL **parea) { Description ------------------------------------------------------*/ -int LabelToCanonical(LABEL *area, MRI_SURFACE *mris) { +int LabelToCanonical(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -244,7 +250,8 @@ int LabelToCanonical(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelToCurrent(LABEL *area, MRI_SURFACE *mris) { +int LabelToCurrent(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -266,7 +273,8 @@ int LabelToCurrent(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelFromCanonical(LABEL *area, MRI_SURFACE *mris) { +int LabelFromCanonical(LABEL *area, MRI_SURFACE *mris) +{ int n, vno, ui, vi, vlist[500000], nvertices; VERTEX *v; MRI_SP *mrisp; @@ -461,7 +469,8 @@ LabelFromTalairach(LABEL *area, MRI_SURFACE *mris) return(NO_ERROR) ; } #else -int LabelFromTalairach(LABEL *area, MRI_SURFACE *mris) { +int LabelFromTalairach(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -484,7 +493,8 @@ int LabelFromTalairach(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelToFlat(LABEL *area, MRI_SURFACE *mris) { +int LabelToFlat(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; MRIS_HASH_TABLE *mht; @@ -499,7 +509,8 @@ int LabelToFlat(LABEL *area, MRI_SURFACE *mris) { area->lv[n].x = v->x; area->lv[n].y = v->y; area->lv[n].z = v->z; - } else /* in canonical coordinate system - find closest vertex */ + } + else /* in canonical coordinate system - find closest vertex */ { #if 0 vno = @@ -527,7 +538,8 @@ int LabelToFlat(LABEL *area, MRI_SURFACE *mris) { MHTfree(&mht); return (NO_ERROR); } -int LabelWriteInto(LABEL *area, FILE *fp) { +int LabelWriteInto(LABEL *area, FILE *fp) +{ int n, num, nbytes; for (num = n = 0; n < area->n_points; n++) @@ -572,7 +584,8 @@ int LabelWriteInto(LABEL *area, FILE *fp) { Description ------------------------------------------------------*/ -int LabelWrite(LABEL *area, const char *label_name) { +int LabelWrite(LABEL *area, const char *label_name) +{ char fname[STRLEN], *cp, subjects_dir[STRLEN], lname[STRLEN]; FILE *fp; int ret; @@ -593,11 +606,13 @@ int LabelWrite(LABEL *area, const char *label_name) { Progname); strcpy(subjects_dir, cp); sprintf(fname, "%s/%s/label/%s.label", subjects_dir, area->subject_name, label_name); - } else { + } + else { cp = strrchr(lname, '.'); if (cp && stricmp(cp, ".label") == 0) { strcpy(fname, label_name); - } else { + } + else { sprintf(fname, "%s.label", label_name); } } @@ -616,7 +631,8 @@ int LabelWrite(LABEL *area, const char *label_name) { Description ------------------------------------------------------*/ -int LabelRipRestOfSurface(LABEL *area, MRI_SURFACE *mris) { +int LabelRipRestOfSurface(LABEL *area, MRI_SURFACE *mris) +{ int vno, n; VERTEX *v; @@ -648,7 +664,8 @@ int LabelRipRestOfSurface(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelRipRestOfSurfaceWithThreshold(LABEL *area, MRI_SURFACE *mris, float thresh) { +int LabelRipRestOfSurfaceWithThreshold(LABEL *area, MRI_SURFACE *mris, float thresh) +{ int vno, n; VERTEX *v; @@ -681,7 +698,8 @@ int LabelRipRestOfSurfaceWithThreshold(LABEL *area, MRI_SURFACE *mris, float thr Description ------------------------------------------------------*/ -int LabelRemoveOverlap(LABEL *area1, LABEL *area2) { +int LabelRemoveOverlap(LABEL *area1, LABEL *area2) +{ int n1, n2, vno; for (n1 = 0; n1 < area1->n_points; n1++) { @@ -703,7 +721,8 @@ int LabelRemoveOverlap(LABEL *area1, LABEL *area2) { Description: elements are not removed, only the deleted flag is set ------------------------------------------------------*/ -int LabelIntersect(LABEL *area1, LABEL *area2) { +int LabelIntersect(LABEL *area1, LABEL *area2) +{ int n, vno; int vmin, vmax, vnum; int *isec; @@ -759,7 +778,8 @@ int LabelIntersect(LABEL *area1, LABEL *area2) { Description ------------------------------------------------------*/ -LABEL *LabelAlloc(int max_points, char *subject_name, char *label_name) { +LABEL *LabelAlloc(int max_points, char *subject_name, char *label_name) +{ LABEL *area; char *cp, subjects_dir[STRLEN]; @@ -776,7 +796,8 @@ LABEL *LabelAlloc(int max_points, char *subject_name, char *label_name) { Progname); strcpy(subjects_dir, cp); strcpy(area->subject_name, subject_name); - } else { + } + else { if (label_name) { strncpy(area->name, label_name, STRLEN - 1); } @@ -802,7 +823,8 @@ LABEL *LabelAlloc(int max_points, char *subject_name, char *label_name) { Description ------------------------------------------------------*/ -int LabelCurvFill(LABEL *area, int *vertex_list, int nvertices, int max_vertices, MRI_SURFACE *mris) { +int LabelCurvFill(LABEL *area, int *vertex_list, int nvertices, int max_vertices, MRI_SURFACE *mris) +{ int n, nfilled, nv; float min_curv, max_curv, curv_thresh; VERTEX *v, *vn; @@ -835,7 +857,8 @@ int LabelCurvFill(LABEL *area, int *vertex_list, int nvertices, int max_vertices } if (-min_curv > max_curv) { curv_thresh = min_curv; - } else { + } + else { curv_thresh = max_curv; } curv_thresh *= 0.1; /* 10% of max */ @@ -886,7 +909,8 @@ int LabelCurvFill(LABEL *area, int *vertex_list, int nvertices, int max_vertices Description ------------------------------------------------------*/ -int LabelFillMarked(LABEL *area, MRI_SURFACE *mris) { +int LabelFillMarked(LABEL *area, MRI_SURFACE *mris) +{ int n, nfilled, nv; VERTEX *v, *vn; LV *lv, *lvn; @@ -940,7 +964,8 @@ int LabelFillMarked(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelFillAnnotated(LABEL *area, MRI_SURFACE *mris) { +int LabelFillAnnotated(LABEL *area, MRI_SURFACE *mris) +{ int n, nfilled, nv, annotation; VERTEX *v, *vn; LV *lv, *lvn; @@ -995,7 +1020,8 @@ int LabelFillAnnotated(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelFillAll(LABEL *area, int *vertex_list, int nvertices, int max_vertices, MRI_SURFACE *mris) { +int LabelFillAll(LABEL *area, int *vertex_list, int nvertices, int max_vertices, MRI_SURFACE *mris) +{ int n, nfilled, nv; VERTEX *v, *vn; LV *lv, *lvn; @@ -1062,7 +1088,8 @@ int LabelFillAll(LABEL *area, int *vertex_list, int nvertices, int max_vertices, Description ------------------------------------------------------*/ -static Transform *labelLoadTransform(const char *subject_name, const char *sdir, General_transform *transform) { +static Transform *labelLoadTransform(const char *subject_name, const char *sdir, General_transform *transform) +{ char xform_fname[STRLEN]; sprintf(xform_fname, "%s/%s/mri/transforms/talairach.xfm", sdir, subject_name); @@ -1079,7 +1106,8 @@ static Transform *labelLoadTransform(const char *subject_name, const char *sdir, Description ------------------------------------------------------*/ -int LabelTalairachTransform(LABEL *area, MRI_SURFACE *mris) { +int LabelTalairachTransform(LABEL *area, MRI_SURFACE *mris) +{ int n; LV *lv; double x, y, z, xt, yt, zt; @@ -1105,7 +1133,8 @@ int LabelTalairachTransform(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelSphericalTransform(LABEL *area, MRI_SURFACE *mris) { +int LabelSphericalTransform(LABEL *area, MRI_SURFACE *mris) +{ int n; LV *lv; VERTEX *v; @@ -1126,7 +1155,8 @@ int LabelSphericalTransform(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -MATRIX *LabelCovarianceMatrix(LABEL *area, MATRIX *mCov) { +MATRIX *LabelCovarianceMatrix(LABEL *area, MATRIX *mCov) +{ MATRIX *mInputs; int i; LV *lv; @@ -1150,7 +1180,8 @@ MATRIX *LabelCovarianceMatrix(LABEL *area, MATRIX *mCov) { Description ------------------------------------------------------*/ -LABEL *LabelCombine(LABEL *asrc, LABEL *adst) { +LABEL *LabelCombine(LABEL *asrc, LABEL *adst) +{ LABEL *atmp; int n; LV *vsrc, *vdst; @@ -1181,7 +1212,8 @@ LABEL *LabelCombine(LABEL *asrc, LABEL *adst) { Description ------------------------------------------------------*/ -LABEL *LabelCopy(LABEL *asrc, LABEL *adst) { +LABEL *LabelCopy(LABEL *asrc, LABEL *adst) +{ if (!adst) { adst = LabelAlloc(asrc->max_points, asrc->subject_name, asrc->name); } @@ -1210,7 +1242,8 @@ LABEL *LabelCopy(LABEL *asrc, LABEL *adst) { Sets the 'deleted' flag of a label point if it is a duplicate. Does not actually remove duplicats! ------------------------------------------------------*/ -int LabelRemoveDuplicates(LABEL *area) { +int LabelRemoveDuplicates(LABEL *area) +{ int n1, n2, deleted = 0; LV *lv1, *lv2; @@ -1226,7 +1259,8 @@ int LabelRemoveDuplicates(LABEL *area) { if (lv1->vno >= 0 && lv2->vno >= 0 && lv1->vno == lv2->vno) { deleted++; lv2->deleted = 1; - } else if (lv1->vno < 0 && lv2->vno < 0) { + } + else if (lv1->vno < 0 && lv2->vno < 0) { if (FEQUAL(lv1->x, lv2->x) && FEQUAL(lv1->y, lv2->y) && FEQUAL(lv1->z, lv2->z)) { deleted++; lv2->deleted = 1; @@ -1244,7 +1278,8 @@ int LabelRemoveDuplicates(LABEL *area) { Sets the 'deleted' flag of a label point if it is a duplicate. Does not actually remove duplicats! ------------------------------------------------------*/ -LABEL *LabelRemoveAlmostDuplicates(LABEL *area, double dist, LABEL *ldst) { +LABEL *LabelRemoveAlmostDuplicates(LABEL *area, double dist, LABEL *ldst) +{ int n1, n2, deleted = 0; LV *lv1, *lv2; @@ -1260,7 +1295,8 @@ LABEL *LabelRemoveAlmostDuplicates(LABEL *area, double dist, LABEL *ldst) { if (lv1->vno >= 0 && lv2->vno >= 0 && lv1->vno == lv2->vno) { deleted++; lv2->deleted = 1; - } else if (lv1->vno < 0 && lv2->vno < 0) { + } + else if (lv1->vno < 0 && lv2->vno < 0) { if (fabs(lv1->x - lv2->x) < dist && fabs(lv1->y - lv2->y) < dist && fabs(lv1->z - lv2->z) < dist) { deleted++; lv2->deleted = 1; @@ -1272,7 +1308,8 @@ LABEL *LabelRemoveAlmostDuplicates(LABEL *area, double dist, LABEL *ldst) { ldst = LabelCompact(area, ldst); return (ldst); } -LABEL *LabelCompact(LABEL *lsrc, LABEL *ldst) { +LABEL *LabelCompact(LABEL *lsrc, LABEL *ldst) +{ int i, n; for (i = n = 0; i < lsrc->n_points; i++) if (lsrc->lv[i].deleted == 0) n++; @@ -1302,7 +1339,8 @@ LABEL *LabelCompact(LABEL *lsrc, LABEL *ldst) { } /*-----------------------------------------------------*/ -double LabelArea(LABEL *area, MRI_SURFACE *mris) { +double LabelArea(LABEL *area, MRI_SURFACE *mris) +{ int i; double total_area; LV *lv; @@ -1325,7 +1363,8 @@ double LabelArea(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelMean(LABEL *area, double *px, double *py, double *pz) { +int LabelMean(LABEL *area, double *px, double *py, double *pz) +{ int i, n; double x, y, z; LV *lv; @@ -1351,7 +1390,8 @@ int LabelMean(LABEL *area, double *px, double *py, double *pz) { Description ------------------------------------------------------*/ -double LabelMeanIntensity(LABEL *area, MRI *mri) { +double LabelMeanIntensity(LABEL *area, MRI *mri) +{ int i; double x, y, z, mean, val; LV *lv; @@ -1380,7 +1420,8 @@ double LabelMeanIntensity(LABEL *area, MRI *mri) { Description ------------------------------------------------------*/ -double LabelVariance(LABEL *area, double ux, double uy, double uz) { +double LabelVariance(LABEL *area, double ux, double uy, double uz) +{ int i, n; double xd, yd, zd, dsq; LV *lv; @@ -1405,7 +1446,8 @@ double LabelVariance(LABEL *area, double ux, double uy, double uz) { Description ------------------------------------------------------*/ -int LabelMark(LABEL *area, MRI_SURFACE *mris) { +int LabelMark(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -1429,7 +1471,8 @@ int LabelMark(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelAddToMark(LABEL *area, MRI_SURFACE *mris, int val_to_add) { +int LabelAddToMark(LABEL *area, MRI_SURFACE *mris, int val_to_add) +{ int n, vno; VERTEX *v; @@ -1452,7 +1495,8 @@ int LabelAddToMark(LABEL *area, MRI_SURFACE *mris, int val_to_add) { Description ------------------------------------------------------*/ -int LabelMarkWithThreshold(LABEL *area, MRI_SURFACE *mris, float thresh) { +int LabelMarkWithThreshold(LABEL *area, MRI_SURFACE *mris, float thresh) +{ int n, vno; VERTEX *v; @@ -1478,7 +1522,8 @@ int LabelMarkWithThreshold(LABEL *area, MRI_SURFACE *mris, float thresh) { has its marked flag turned on. ------------------------------------------------------*/ -int LabelMarkUndeleted(LABEL *area, MRI_SURFACE *mris) { +int LabelMarkUndeleted(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -1507,7 +1552,8 @@ int LabelMarkUndeleted(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelUnmark(LABEL *area, MRI_SURFACE *mris) { +int LabelUnmark(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -1528,7 +1574,8 @@ int LabelUnmark(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelToOriginal(LABEL *area, MRI_SURFACE *mris) { +int LabelToOriginal(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -1554,7 +1601,8 @@ int LabelToOriginal(LABEL *area, MRI_SURFACE *mris) { corresponding white coords from the surface and writes them in the label. ------------------------------------------------------*/ -int LabelToWhite(LABEL *area, MRI_SURFACE *mris) { +int LabelToWhite(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -1578,7 +1626,8 @@ int LabelToWhite(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -LABEL *LabelFromMarkedSurface(MRI_SURFACE *mris) { +LABEL *LabelFromMarkedSurface(MRI_SURFACE *mris) +{ int vno, npoints, n; LABEL *area; VERTEX *v; @@ -1620,7 +1669,8 @@ LABEL *LabelFromMarkedSurface(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -LABEL *LabelFromMarkValue(MRI_SURFACE *mris, int mark) { +LABEL *LabelFromMarkValue(MRI_SURFACE *mris, int mark) +{ int vno, npoints, n; LABEL *area; VERTEX *v; @@ -1657,7 +1707,8 @@ LABEL *LabelFromMarkValue(MRI_SURFACE *mris, int mark) { } /*----------------------------------------------------- ------------------------------------------------------*/ -int LabelAddToSurfaceMark(LABEL *area, MRI_SURFACE *mris, int mark_to_add) { +int LabelAddToSurfaceMark(LABEL *area, MRI_SURFACE *mris, int mark_to_add) +{ int n, vno; VERTEX *v; @@ -1678,7 +1729,8 @@ int LabelAddToSurfaceMark(LABEL *area, MRI_SURFACE *mris, int mark_to_add) { } /*----------------------------------------------------- ------------------------------------------------------*/ -int LabelMarkSurface(LABEL *area, MRI_SURFACE *mris) { +int LabelMarkSurface(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -1706,7 +1758,8 @@ int LabelMarkSurface(LABEL *area, MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int LabelIsCompletelyUnassigned(LABEL *area, int *unassigned) { +int LabelIsCompletelyUnassigned(LABEL *area, int *unassigned) +{ int i; if (NULL == area) { @@ -1737,7 +1790,8 @@ int LabelIsCompletelyUnassigned(LABEL *area, int *unassigned) { Description ------------------------------------------------------*/ #include "mrishash.h" -int LabelFillUnassignedVertices(MRI_SURFACE *mris, LABEL *area, int coords) { +int LabelFillUnassignedVertices(MRI_SURFACE *mris, LABEL *area, int coords) +{ int n, i, vno, min_vno, nfilled = 0, max_vno; LV *lv; MHT *mht; @@ -1834,7 +1888,8 @@ int LabelFillUnassignedVertices(MRI_SURFACE *mris, LABEL *area, int coords) { return (nfilled); } -LABEL *LabelSphericalCombine(MRI_SURFACE *mris, LABEL *asrc, MRIS_HASH_TABLE *mht, MRI_SURFACE *mris_dst, LABEL *adst) { +LABEL *LabelSphericalCombine(MRI_SURFACE *mris, LABEL *asrc, MRIS_HASH_TABLE *mht, MRI_SURFACE *mris_dst, LABEL *adst) +{ int vno, n, nfilled, m; VERTEX *v, *vdst, *vn, *vsrc; LABEL_VERTEX *lv_dst; @@ -1881,7 +1936,8 @@ LABEL *LabelSphericalCombine(MRI_SURFACE *mris, LABEL *asrc, MRIS_HASH_TABLE *mh lv_dst = labelFindVertexNumber(adst, vdst - mris_dst->vertices); if (lv_dst == NULL) { lv_dst = &adst->lv[adst->n_points++]; - } else if (lv_dst - adst->lv == Gdiag_no) { + } + else if (lv_dst - adst->lv == Gdiag_no) { DiagBreak(); } lv_dst->vno = vdst - mris_dst->vertices; @@ -1957,7 +2013,8 @@ LABEL *LabelSphericalCombine(MRI_SURFACE *mris, LABEL *asrc, MRIS_HASH_TABLE *mh lv_dst = labelFindVertexNumber(adst, v->v[m]); if (lv_dst == NULL) { lv_dst = &adst->lv[adst->n_points++]; - } else if (lv_dst - adst->lv == Gdiag_no) { + } + else if (lv_dst - adst->lv == Gdiag_no) { DiagBreak(); } lv_dst->x = adst->lv[n].x; @@ -1983,7 +2040,8 @@ LABEL *LabelSphericalCombine(MRI_SURFACE *mris, LABEL *asrc, MRIS_HASH_TABLE *mh return (adst); } -int LabelNormalizeStats(LABEL *area, float norm) { +int LabelNormalizeStats(LABEL *area, float norm) +{ LABEL_VERTEX *lv; int n; @@ -1998,7 +2056,8 @@ int LabelNormalizeStats(LABEL *area, float norm) { MaskSurfLabel() - removes vertices from a label based on the value of those vertices in a surface mask. -------------------------------------------------------------*/ -LABEL *MaskSurfLabel(LABEL *lbl, MRI *SurfMask, float thresh, char *masksign, int frame) { +LABEL *MaskSurfLabel(LABEL *lbl, MRI *SurfMask, float thresh, char *masksign, int frame) +{ LABEL *msklbl; int n, vno, ok, noverlap; float maskval; @@ -2069,7 +2128,8 @@ LABEL *MaskSurfLabel(LABEL *lbl, MRI *SurfMask, float thresh, char *masksign, in return (msklbl); } -int LabelErode(LABEL *area, MRI_SURFACE *mris, int num_times) { +int LabelErode(LABEL *area, MRI_SURFACE *mris, int num_times) +{ int n, label_vno, vno, neighbor_index, neighbor_vno, found_nbr_off; VERTEX *vn; @@ -2132,7 +2192,8 @@ int LabelErode(LABEL *area, MRI_SURFACE *mris, int num_times) { return (NO_ERROR); } -int LabelDilate(LABEL *area, MRI_SURFACE *mris, int num_times, int coords) { +int LabelDilate(LABEL *area, MRI_SURFACE *mris, int num_times, int coords) +{ int n, neighbor_index, neighbor_vno, found, vno; VERTEX *vn, *v; @@ -2209,7 +2270,8 @@ int LabelDilate(LABEL *area, MRI_SURFACE *mris, int num_times, int coords) { return (NO_ERROR); } -static LABEL_VERTEX *labelFindVertexNumber(LABEL *area, int vno) { +static LABEL_VERTEX *labelFindVertexNumber(LABEL *area, int vno) +{ int n; LABEL_VERTEX *lv; @@ -2222,7 +2284,8 @@ static LABEL_VERTEX *labelFindVertexNumber(LABEL *area, int vno) { return (NULL); } -int LabelSetStat(LABEL *area, float stat) { +int LabelSetStat(LABEL *area, float stat) +{ int n; for (n = 0; n < area->n_points; n++) { @@ -2232,7 +2295,8 @@ int LabelSetStat(LABEL *area, float stat) { return (NO_ERROR); } -int LabelMarkStats(LABEL *area, MRI_SURFACE *mris) { +int LabelMarkStats(LABEL *area, MRI_SURFACE *mris) +{ int n, vno; VERTEX *v; @@ -2248,7 +2312,8 @@ int LabelMarkStats(LABEL *area, MRI_SURFACE *mris) { return (NO_ERROR); } -LABEL *LabelFillHoles(LABEL *area_src, MRI_SURFACE *mris, int coords) { +LABEL *LabelFillHoles(LABEL *area_src, MRI_SURFACE *mris, int coords) +{ MRI *mri; int i, dst_index, vno, xi, yi, zi, xk, yk, zk, found, x2, y2, z2, nchanged; double xw, yw, zw, xv, yv, zv; @@ -2356,7 +2421,8 @@ LABEL *LabelFillHoles(LABEL *area_src, MRI_SURFACE *mris, int coords) { MRIfree(&mri); return (area_dst); } -LABEL *LabelFillHolesWithOrig(LABEL *area_src, MRI_SURFACE *mris) { +LABEL *LabelFillHolesWithOrig(LABEL *area_src, MRI_SURFACE *mris) +{ MRI *mri; int i, dst_index, vno; double xw, yw, zw, xv, yv, zv; @@ -2376,7 +2442,8 @@ LABEL *LabelFillHolesWithOrig(LABEL *area_src, MRI_SURFACE *mris) { // MRIworldToVoxel(mri, xw, yw, zw, &xv, &yv, &zv) ; if (mris->useRealRAS) { MRIworldToVoxel(mri, xw, yw, zw, &xv, &yv, &zv); - } else { + } + else { MRIsurfaceRASToVoxel(mri, xw, yw, zw, &xv, &yv, &zv); } MRIvox(mri, nint(xv), nint(yv), nint(zv)) = 1; @@ -2409,7 +2476,8 @@ LABEL *LabelFillHolesWithOrig(LABEL *area_src, MRI_SURFACE *mris) { otherwise returns the number of the label point that corresponds to the vertex number. ---------------------------------------------------------------*/ -int LabelHasVertex(int vtxno, LABEL *lb) { +int LabelHasVertex(int vtxno, LABEL *lb) +{ int n; for (n = 0; n < lb->n_points; n++) if (lb->lv[n].vno == vtxno) { @@ -2422,7 +2490,8 @@ int LabelHasVertex(int vtxno, LABEL *lb) { to have max_points. If something goes wrong, returns 1 without changing anything. Otherwise returns 0. ---------------------------------------------------------------*/ -LABEL *LabelRealloc(LABEL *lb, int max_points) { +LABEL *LabelRealloc(LABEL *lb, int max_points) +{ LV *lvtmp; if (lb == NULL) return (LabelAlloc(max_points, NULL, NULL)); @@ -2446,7 +2515,8 @@ LABEL *LabelRealloc(LABEL *lb, int max_points) { match the code, then it silently returns NULL. Note: this generates the same result as the code in mri_cor2label.c. ------------------------------------------------------------*/ -LABEL *LabelfromASeg(MRI *aseg, int segcode) { +LABEL *LabelfromASeg(MRI *aseg, int segcode) +{ int c, r, s, nlabel, v; LABEL *lb; MATRIX *Vox2RAS, *crs, *ras; @@ -2513,7 +2583,8 @@ LABEL *LabelfromASeg(MRI *aseg, int segcode) { VertexIsInLabel() - returns a 1 if the given vertex number is in the label. Label must be surface-based. ---------------------------------------------------------------*/ -int VertexIsInLabel(int vtxno, LABEL *label) { +int VertexIsInLabel(int vtxno, LABEL *label) +{ int n; for (n = 0; n < label->n_points; n++) @@ -2527,7 +2598,8 @@ int VertexIsInLabel(int vtxno, LABEL *label) { LabelBoundary() - returns a label of all the points in the input label on the edge/boundary. Label must be surface-based. ---------------------------------------------------------------*/ -LABEL *LabelBoundary(LABEL *label, MRIS *surf) { +LABEL *LabelBoundary(LABEL *label, MRIS *surf) +{ int n, nnbrs, nthnbr, vtxno, nbrvtxno; LABEL *boundary; @@ -2559,7 +2631,8 @@ LABEL *LabelBoundary(LABEL *label, MRIS *surf) { then the shape is a plane. If order=2, then it is a quad, 3 for cubic. Returns the regression coefficients. ---------------------------------------------------------------*/ -MATRIX *LabelFitXYZ(LABEL *label, int order) { +MATRIX *LabelFitXYZ(LABEL *label, int order) +{ int n; MATRIX *X, *Xt, *XtX, *iXtX, *iXtXXt, *y, *beta; @@ -2606,7 +2679,8 @@ MATRIX *LabelFitXYZ(LABEL *label, int order) { return (beta); } -LABEL *LabelInFOV(MRI_SURFACE *mris, MRI *mri, float pad) { +LABEL *LabelInFOV(MRI_SURFACE *mris, MRI *mri, float pad) +{ LABEL *area; int vno, npoints; VERTEX *v; @@ -2679,7 +2753,8 @@ LABEL *LabelInFOV(MRI_SURFACE *mris, MRI *mri, float pad) { // LabelWrite(area, "./lh.all.label"); return (area); } -LABEL *LabelTranslate(LABEL *area, LABEL *area_offset, float dx, float dy, float dz) { +LABEL *LabelTranslate(LABEL *area, LABEL *area_offset, float dx, float dy, float dz) +{ int i; if (area_offset == NULL) { @@ -2694,7 +2769,8 @@ LABEL *LabelTranslate(LABEL *area, LABEL *area_offset, float dx, float dy, float return (area_offset); } -int LabelUnassign(LABEL *area) { +int LabelUnassign(LABEL *area) +{ int i; for (i = 0; i < area->n_points; i++) { @@ -2707,7 +2783,8 @@ int LabelUnassign(LABEL *area) { MRISlabelInvert(MRIS *surf, LABEL *label) Creates a label with all the vertices NOT in the input label. ---------------------------------------------------------------*/ -LABEL *MRISlabelInvert(MRIS *surf, LABEL *label) { +LABEL *MRISlabelInvert(MRIS *surf, LABEL *label) +{ MRI *tmpmri; LABEL *invlabel; int n, vtxno, ninv, nlabel; @@ -2742,7 +2819,8 @@ LABEL *MRISlabelInvert(MRIS *surf, LABEL *label) { MRIfree(&tmpmri); return (invlabel); } -int LabelCopyStatsToSurface(LABEL *area, MRI_SURFACE *mris, int which) { +int LabelCopyStatsToSurface(LABEL *area, MRI_SURFACE *mris, int which) +{ int n, vno; VERTEX *v; @@ -2767,7 +2845,8 @@ int LabelCopyStatsToSurface(LABEL *area, MRI_SURFACE *mris, int which) { return (NO_ERROR); } -int LabelThreshold(LABEL *area, float thresh) { +int LabelThreshold(LABEL *area, float thresh) +{ int n, ndel; LABEL_VERTEX *lv; @@ -2781,7 +2860,8 @@ int LabelThreshold(LABEL *area, float thresh) { return (ndel); } -int LabelCropAnterior(LABEL *area, float anterior_dist) { +int LabelCropAnterior(LABEL *area, float anterior_dist) +{ int n; float amax; @@ -2802,7 +2882,8 @@ int LabelCropAnterior(LABEL *area, float anterior_dist) { return (NO_ERROR); } -int LabelCropPosterior(LABEL *area, float anterior_dist) { +int LabelCropPosterior(LABEL *area, float anterior_dist) +{ int n; float amax; @@ -2823,7 +2904,8 @@ int LabelCropPosterior(LABEL *area, float anterior_dist) { return (NO_ERROR); } -int LabelMaskSurface(LABEL *area, MRI_SURFACE *mris) { +int LabelMaskSurface(LABEL *area, MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -2839,7 +2921,8 @@ int LabelMaskSurface(LABEL *area, MRI_SURFACE *mris) { MRISclearMarks(mris); return (NO_ERROR); } -int LabelMaskSurfaceVolume(LABEL *area, MRI *mri, float nonmask_val) { +int LabelMaskSurfaceVolume(LABEL *area, MRI *mri, float nonmask_val) +{ int vno, n, x, y, z, f; uchar *marked; long nvox; @@ -2861,7 +2944,8 @@ int LabelMaskSurfaceVolume(LABEL *area, MRI *mri, float nonmask_val) { free(marked); return (NO_ERROR); } -int LabelCentroid(LABEL *area, MRI_SURFACE *mris, double *px, double *py, double *pz, int *pvno) { +int LabelCentroid(LABEL *area, MRI_SURFACE *mris, double *px, double *py, double *pz, int *pvno) +{ int vno, num, n; VERTEX *v; double xc, yc, zc; @@ -2904,7 +2988,8 @@ int LabelCentroid(LABEL *area, MRI_SURFACE *mris, double *px, double *py, double return (NO_ERROR); } -int LabelFillVolume(MRI *mri, LABEL *area, int fillval) { +int LabelFillVolume(MRI *mri, LABEL *area, int fillval) +{ int n; double xv, yv, zv; LABEL_VERTEX *lv; @@ -2917,7 +3002,8 @@ int LabelFillVolume(MRI *mri, LABEL *area, int fillval) { return (NO_ERROR); } -int LabelSetVals(MRI_SURFACE *mris, LABEL *area, float fillval) { +int LabelSetVals(MRI_SURFACE *mris, LABEL *area, float fillval) +{ int n; LABEL_VERTEX *lv; @@ -2932,7 +3018,8 @@ int LabelSetVals(MRI_SURFACE *mris, LABEL *area, float fillval) { convert the label coords from tkreg (surface) RAS to scanner RAS. Note that this assumes that the label coords are in tkreg space */ -LABEL *LabelToScannerRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) { +LABEL *LabelToScannerRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) +{ int i; MATRIX *M_surface_to_RAS = RASFromSurfaceRAS_(mri); VECTOR *v1, *v2; @@ -2967,7 +3054,8 @@ LABEL *LabelToScannerRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) { convert the label coords from tkreg (surface) RAS to scanner RAS. Note that this assumes that the label coords are in tkreg space */ -LABEL *LabelFromScannerRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) { +LABEL *LabelFromScannerRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) +{ int i; MATRIX *M_surface_to_RAS = RASFromSurfaceRAS_(mri), *M_surface_from_RAS; VECTOR *v1, *v2; @@ -3006,7 +3094,8 @@ LABEL *LabelFromScannerRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) { convert the label coords from tkreg (surface) RAS to voxels. Note that this assumes that the label coords are in tkreg space */ -LABEL *LabelToVoxel(LABEL *lsrc, MRI *mri, LABEL *ldst) { +LABEL *LabelToVoxel(LABEL *lsrc, MRI *mri, LABEL *ldst) +{ int i; MATRIX *M_surface_to_vox = RASFromSurfaceRAS_(mri); VECTOR *v1, *v2; @@ -3040,7 +3129,8 @@ LABEL *LabelToVoxel(LABEL *lsrc, MRI *mri, LABEL *ldst) { MatrixFree(&M_surface_to_vox); return (ldst); } -LABEL *LabelClone(LABEL *a) { +LABEL *LabelClone(LABEL *a) +{ LABEL *l; l = LabelAlloc(a->max_points, a->subject_name, a->name); l->mri_template = a->mri_template; @@ -3052,7 +3142,8 @@ LABEL *LabelClone(LABEL *a) { return (l); } -LABEL *LabelTransform(LABEL *lsrc, TRANSFORM *xform, MRI *mri, LABEL *ldst) { +LABEL *LabelTransform(LABEL *lsrc, TRANSFORM *xform, MRI *mri, LABEL *ldst) +{ int i; MATRIX *M; VECTOR *v1, *v2; @@ -3092,7 +3183,8 @@ LABEL *LabelTransform(LABEL *lsrc, TRANSFORM *xform, MRI *mri, LABEL *ldst) { return (ldst); } -LABEL *LabelVoxelToSurfaceRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) { +LABEL *LabelVoxelToSurfaceRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) +{ int i; double xs, ys, zs; @@ -3121,7 +3213,8 @@ LABEL *LabelVoxelToSurfaceRAS(LABEL *lsrc, MRI *mri, LABEL *ldst) { controls how finely the face is filled. delta should be between 0 and 1. */ -LABEL *LabelBaryFill(MRIS *mris, LABEL *srclabel, double delta) { +LABEL *LabelBaryFill(MRIS *mris, LABEL *srclabel, double delta) +{ MRI *mri; LABEL *outlabel; int k, ok, n, vtxno, nPerTriangle, nTriangles, nthlab; @@ -3186,7 +3279,8 @@ LABEL *LabelBaryFill(MRIS *mris, LABEL *srclabel, double delta) { return (outlabel); } -LABEL *LabelSampleToSurface(MRI_SURFACE *mris, LABEL *area, MRI *mri_template, int coords) { +LABEL *LabelSampleToSurface(MRI_SURFACE *mris, LABEL *area, MRI *mri_template, int coords) +{ int n, i, vno, min_vno, nfilled = 0, max_vno; LV *lv; static MHT *mht = NULL; @@ -3358,7 +3452,8 @@ LABEL *LabelSampleToSurface(MRI_SURFACE *mris, LABEL *area, MRI *mri_template, i return (area_dst); } -int LabelInit(LABEL *area, MRI *mri_template, MRI_SURFACE *mris, int coords) { +int LabelInit(LABEL *area, MRI *mri_template, MRI_SURFACE *mris, int coords) +{ double xv, yv, zv, max_spacing, x, y, z, min_dist, dx, dy, dz, vx, vy, vz, dist; int n, max_vno, min_vno, i, vno; MHBT *bucket; @@ -3493,7 +3588,8 @@ int LabelInit(LABEL *area, MRI *mri_template, MRI_SURFACE *mris, int coords) { return (NO_ERROR); } -int LabelAddVoxel(LABEL *area, int xv, int yv, int zv, int coords, int *vertices, int *pnvertices) { +int LabelAddVoxel(LABEL *area, int xv, int yv, int zv, int coords, int *vertices, int *pnvertices) +{ MHBT *bucket; MHB *bin; int n, min_vno, i, vno; @@ -3604,7 +3700,8 @@ int LabelAddVoxel(LABEL *area, int xv, int yv, int zv, int coords, int *vertices return (min_vno); } -int LabelDeleteVoxel(LABEL *area, int xv, int yv, int zv, int *vertices, int *pnvertices) { +int LabelDeleteVoxel(LABEL *area, int xv, int yv, int zv, int *vertices, int *pnvertices) +{ int n, ndeleted; LV *lv; @@ -3640,7 +3737,8 @@ int LabelDeleteVoxel(LABEL *area, int xv, int yv, int zv, int *vertices, int *pn from the surface coords and updates vertex_label_ind; this function does neither of those. */ -LABEL *LabelAddPoint(LABEL *label, LV *lv) { +LABEL *LabelAddPoint(LABEL *label, LV *lv) +{ // alloc label if nec if (label == NULL) label = LabelAlloc(100, NULL, NULL); // realloc label if nec @@ -3661,7 +3759,8 @@ LABEL *LabelAddPoint(LABEL *label, LV *lv) { nothing is done and -1 is returned. See also LabelDeleteVertex() and LabelAddPoint(). */ -int LabelAddVertex(LABEL *area, int vno, int coords) { +int LabelAddVertex(LABEL *area, int vno, int coords) +{ LV *lv; int n; double xv, yv, zv, x, y, z; @@ -3690,7 +3789,8 @@ int LabelAddVertex(LABEL *area, int vno, int coords) { return (NO_ERROR); } -int LabelDeleteVertex(LABEL *area, int vno, int coords) { +int LabelDeleteVertex(LABEL *area, int vno, int coords) +{ int n; if (area->vertex_label_ind[vno] < 0) return (-1); @@ -3699,7 +3799,8 @@ int LabelDeleteVertex(LABEL *area, int vno, int coords) { area->lv[n].deleted = 1; return (NO_ERROR); } -static int update_vertex_indices(LABEL *area) { +static int update_vertex_indices(LABEL *area) +{ int vno, n; MRI_SURFACE *mris = (MRI_SURFACE *)(area->mris); @@ -3711,7 +3812,8 @@ static int update_vertex_indices(LABEL *area) { if (area->lv[n].deleted == 0) area->vertex_label_ind[area->lv[n].vno] = n; return (NO_ERROR); } -LABEL *LabelApplyMatrix(LABEL *lsrc, MATRIX *m, LABEL *ldst) { +LABEL *LabelApplyMatrix(LABEL *lsrc, MATRIX *m, LABEL *ldst) +{ int n; VECTOR *v1, *v2; @@ -3739,7 +3841,8 @@ LABEL *LabelApplyMatrix(LABEL *lsrc, MATRIX *m, LABEL *ldst) { VectorFree(&v2); return (ldst); } -static int labelGetSurfaceRasCoords(LABEL *area, LABEL_VERTEX *lv, float *px, float *py, float *pz) { +static int labelGetSurfaceRasCoords(LABEL *area, LABEL_VERTEX *lv, float *px, float *py, float *pz) +{ double xv, yv, zv, xw, yw, zw; switch (area->coords) { @@ -3762,7 +3865,8 @@ static int labelGetSurfaceRasCoords(LABEL *area, LABEL_VERTEX *lv, float *px, fl return (NO_ERROR); } -static int labelGetVoxelCoords(LABEL *area, LABEL_VERTEX *lv, float *px, float *py, float *pz) { +static int labelGetVoxelCoords(LABEL *area, LABEL_VERTEX *lv, float *px, float *py, float *pz) +{ double xv, yv, zv; switch (area->coords) { diff --git a/utils/lpafile.c b/utils/lpafile.c index 426455f2f4b..ab85931424f 100644 --- a/utils/lpafile.c +++ b/utils/lpafile.c @@ -47,7 +47,8 @@ static void lpafAllocParms(IMAGE *I); #define NFLUSH 10 /* flush after every 10th write */ #define INIT_VAL 10000 /* initial value of parameters */ -int LPAFreadImageAnswer(LPAF *lpaf, int current) { +int LPAFreadImageAnswer(LPAF *lpaf, int current) +{ char *fullname, fname[100]; FILE *fp; IMAGE Iheader; @@ -126,7 +127,8 @@ int LPAFreadImageAnswer(LPAF *lpaf, int current) { return (1); } -int LPAFresetImageAnswer(LPAF *lpaf, int current) { +int LPAFresetImageAnswer(LPAF *lpaf, int current) +{ char *fullname, tmpname[100], fname[100]; IMAGE Iheader, *I; FILE *infp, *outfp; @@ -188,7 +190,8 @@ int LPAFresetImageAnswer(LPAF *lpaf, int current) { return (1); } -int LPAFwriteImageAnswer(LPAF *lpaf, int current) { +int LPAFwriteImageAnswer(LPAF *lpaf, int current) +{ char *fullname, tmpname[100], fname[100]; IMAGE Iheader, *I; FILE *infp, *outfp; @@ -250,7 +253,8 @@ int LPAFwriteImageAnswer(LPAF *lpaf, int current) { return (1); } -LP_ANSWER_FILE *LPAFcreate(char *out_fname, int argc, char *argv[]) { +LP_ANSWER_FILE *LPAFcreate(char *out_fname, int argc, char *argv[]) +{ LP_ANSWER_FILE *lpaf; int i, nentries, nfiles, entryno; @@ -270,7 +274,8 @@ LP_ANSWER_FILE *LPAFcreate(char *out_fname, int argc, char *argv[]) { unlink(lpaf->fname); lpaf->fp = fopen(lpaf->fname, "a+b"); if (!lpaf->fp) ErrorReturn(NULL, (ERROR_NO_FILE, "LPAFcreate: could not open %s", out_fname)); - } else + } + else lpaf->fp = NULL; lpaf->nfiles = nfiles; @@ -294,7 +299,8 @@ LP_ANSWER_FILE *LPAFcreate(char *out_fname, int argc, char *argv[]) { return (lpaf); } -static int lpafFillEntries(LP_ANSWER_FILE *lpaf, char *fname, int entryno) { +static int lpafFillEntries(LP_ANSWER_FILE *lpaf, char *fname, int entryno) +{ int nentries, type, i, num; char buf[100], *base_name, line[200], *cp; FILE *fp; @@ -328,7 +334,8 @@ static int lpafFillEntries(LP_ANSWER_FILE *lpaf, char *fname, int entryno) { return (nentries); } -static void lpafDump(FILE *fp, LP_ANSWER_FILE *lpaf) { +static void lpafDump(FILE *fp, LP_ANSWER_FILE *lpaf) +{ int i; if (strcmp(lpaf->fname, "test")) return; @@ -339,7 +346,8 @@ static void lpafDump(FILE *fp, LP_ANSWER_FILE *lpaf) { /* filename (centroid) (x, y) ... */ #define FILE_FMT "%s (%3d, %3d) (%3d, %3d) (%3d, %3d) (%3d, %3d) (%3d, %3d)\n" -int LPAFwrite(LPAF *lpaf, int current) { +int LPAFwrite(LPAF *lpaf, int current) +{ LP_BOX *lpb; LPAFwriteImageAnswer(lpaf, current); @@ -350,7 +358,8 @@ int LPAFwrite(LPAF *lpaf, int current) { { if (fseek(lpaf->fp, lpb->fpos, SEEK_SET) < 0) ErrorReturn(-1, (ERROR_BADFILE, "LPAFwrite could not seek to %ld", lpb->fpos)); - } else + } + else lpb->fpos = ftell(lpaf->fp); if (current > lpaf->last_written) @@ -381,7 +390,8 @@ int LPAFwrite(LPAF *lpaf, int current) { return (0); } -int LPAFread(LPAF *lpaf, int current) { +int LPAFread(LPAF *lpaf, int current) +{ LP_BOX *lpb; char line[300], *cp; @@ -426,7 +436,8 @@ int LPAFread(LPAF *lpaf, int current) { return (abs(lpb->xc) < INIT_VAL); /* handles garbages as well as unwritten */ } -int LPAFset(LPAF *lpaf, int current, int *xp, int *yp, int xc, int yc) { +int LPAFset(LPAF *lpaf, int current, int *xp, int *yp, int xc, int yc) +{ LP_BOX *lpb; int i; @@ -442,7 +453,8 @@ int LPAFset(LPAF *lpaf, int current, int *xp, int *yp, int xc, int yc) { #define NPARAMS 10 -static void lpafAllocParms(IMAGE *I) { +static void lpafAllocParms(IMAGE *I) +{ int frame, nframes, i; struct extpar *params; diff --git a/utils/machine.c b/utils/machine.c index 175f5a1e934..0f838a20501 100644 --- a/utils/machine.c +++ b/utils/machine.c @@ -27,7 +27,8 @@ #include "machine.h" -double swapDouble(double d) { +double swapDouble(double d) +{ size_t typeSize = sizeof(double); char *pVar = (char *)(&d); char tmp; @@ -44,7 +45,8 @@ double swapDouble(double d) { return w; } -long64 swapLong64(long64 l) { +long64 swapLong64(long64 l) +{ size_t typeSize = sizeof(long64); char *pVar = (char *)(&l); char tmp; @@ -74,7 +76,8 @@ typedef union { } SWAP_LONG32; /* does not work for 64 bit OS */ -long32 swapLong32(long32 l) { +long32 swapLong32(long32 l) +{ SWAP_LONG32 sl; short s; @@ -91,7 +94,8 @@ long32 swapLong32(long32 l) { return (sl.l); } -float swapFloat(float f) { +float swapFloat(float f) +{ SWAP_LONG32 sl; short s; @@ -113,7 +117,8 @@ typedef union { char buf[sizeof(short)]; } SWAP_SHORT; -short swapShort(short s) { +short swapShort(short s) +{ SWAP_SHORT ss; char c; @@ -150,7 +155,8 @@ swapDouble(double d) } */ -int swapInt(int i) { +int swapInt(int i) +{ SWAP_LONG32 sl; short s; @@ -176,7 +182,8 @@ int swapInt(int i) { 3. This is consistent with the endianness flag in the bshort/bfloat format. --------------------------------------------------------*/ -int Arch486(void) { +int Arch486(void) +{ int endian; short tmp = 1; char *ctmp; @@ -194,7 +201,8 @@ int Arch486(void) { in Buf. nitems is the number of nBytesPerItem-byte items in Buf. ---------------------------------------------------------*/ -int ByteSwapBuf(void *Buf, long int nItems, int nBytesPerItem) { +int ByteSwapBuf(void *Buf, long int nItems, int nBytesPerItem) +{ switch (nBytesPerItem) { case 1: break; @@ -218,7 +226,8 @@ int ByteSwapBuf(void *Buf, long int nItems, int nBytesPerItem) { Reverses the byte order of each 2-byte buffer of buf2. nitems is the number of 2-byte items in buf2; ---------------------------------------------------------*/ -int ByteSwap2(void *buf2, long int nitems) { +int ByteSwap2(void *buf2, long int nitems) +{ register char *cbuf, ctmp; register long int n; @@ -236,7 +245,8 @@ int ByteSwap2(void *buf2, long int nitems) { Reverses the byte order of each 4-byte buffer of buf4. nitems is the number of 4-byte items in buf4; ---------------------------------------------------------*/ -int ByteSwap4(void *buf4, long int nitems) { +int ByteSwap4(void *buf4, long int nitems) +{ register char *cbuf, ctmp; register long int n; @@ -262,7 +272,8 @@ int ByteSwap4(void *buf4, long int nitems) { Reverses the byte order of each 8-byte buffer of buf8. nitems is the number of 8-byte items in buf8; ---------------------------------------------------------*/ -int ByteSwap8(void *buf8, long int nitems) { +int ByteSwap8(void *buf8, long int nitems) +{ register char *cbuf, ctmp; register long int n; diff --git a/utils/matfile.c b/utils/matfile.c index 590cf330d8a..749157a4304 100644 --- a/utils/matfile.c +++ b/utils/matfile.c @@ -57,18 +57,21 @@ int MLFCfree(MLFC **ppmlfc); #endif static int (*mat_printf)(const char *szFormat, ...) = NULL; -int Matlab_Install_printf(int (*new_printf)(const char *szFormat, ...)) { +int Matlab_Install_printf(int (*new_printf)(const char *szFormat, ...)) +{ mat_printf = new_printf; return (0); } -int MatlabWrite(MATRIX *mat, const char *fname, const char *name) { +int MatlabWrite(MATRIX *mat, const char *fname, const char *name) +{ if (!name) return (MatFileWrite(fname, mat->data, mat->rows, mat->cols, "matrix")); return (MatFileWrite(fname, mat->data, mat->rows, mat->cols, name)); } -MATRIX *MatlabRead(const char *fname) { +MATRIX *MatlabRead(const char *fname) +{ MATRIX *mat; MATFILE mf; FILE *fp; @@ -119,7 +122,8 @@ MATRIX *MatlabRead(const char *fname) { #else if (mf.imagf) { fptr = (float *)MATRIX_CELT(mat, row, 1); - } else + } + else fptr = MATRIX_RELT(mat, row, 1); #endif @@ -137,7 +141,8 @@ MATRIX *MatlabRead(const char *fname) { return (mat); } -MATFILE *MatFileRead(const char *fname, int type) { +MATFILE *MatFileRead(const char *fname, int type) +{ MATFILE *mf; FILE *fp; char *name; @@ -198,7 +203,8 @@ MATFILE *MatFileRead(const char *fname, int type) { return (mf); } -int MatFileWrite(const char *fname, float *data, int rows, int cols, const char *name) { +int MatFileWrite(const char *fname, float *data, int rows, int cols, const char *name) +{ int row, col, nitems, mtype; float *fptr; FILE *fp; @@ -267,7 +273,8 @@ int MatFileWrite(const char *fname, float *data, int rows, int cols, const char return (0); } -static void matFree(double **matrix, int rows, int cols) { +static void matFree(double **matrix, int rows, int cols) +{ int i; i = cols; /* prevents warning */ @@ -276,7 +283,8 @@ static void matFree(double **matrix, int rows, int cols) { free(matrix); } -static double **matAlloc(int rows, int cols) { +static double **matAlloc(int rows, int cols) +{ double **matrix; int i; @@ -299,7 +307,8 @@ static double **matAlloc(int rows, int cols) { return (matrix); } -static int readMatFile(FILE *fp, MATFILE *mf, double **real_matrix, double **imag_matrix) { +static int readMatFile(FILE *fp, MATFILE *mf, double **real_matrix, double **imag_matrix) +{ int row, col, type, nitems; short sval; long lval; @@ -333,7 +342,8 @@ static int readMatFile(FILE *fp, MATFILE *mf, double **real_matrix, double **ima ERROR_BADFILE, "unsupported matlab format %d (%s)\n", type, type == MAT_FLOAT ? "float" : "unknown"); break; } - } else { /* if (mf.version == 4) */ + } + else { /* if (mf.version == 4) */ type = (int)mf->type - ((int)mf->type / 1000) * 1000; /* remove 1000s */ type = type - type / 100 * 100; /* remove 100s from type */ type = type / 10 * 10; /* 10s digit specifies data type */ @@ -445,7 +455,8 @@ static int readMatFile(FILE *fp, MATFILE *mf, double **real_matrix, double **ima } /*---------------------------------------------------------*/ -char *MatReadHeader0(FILE *fp, MATFILE *mf) { +char *MatReadHeader0(FILE *fp, MATFILE *mf) +{ int nitems; char *name; @@ -489,7 +500,8 @@ char *MatReadHeader0(FILE *fp, MATFILE *mf) { return (name); } -static void swapBytes(MATFILE *mf) { +static void swapBytes(MATFILE *mf) +{ mf->type = swapLong32(mf->type); mf->mrows = swapLong32(mf->mrows); mf->ncols = swapLong32(mf->ncols); @@ -501,7 +513,8 @@ static void swapBytes(MATFILE *mf) { variables from a matlab file and return the matrix associated with the given variable name. -------------------------------------------------------------*/ -MATRIX *ReadMatlabFileVariable(const char *fname, const char *varname) { +MATRIX *ReadMatlabFileVariable(const char *fname, const char *varname) +{ MLFC *mlfc; int n; MATRIX *M; @@ -529,7 +542,8 @@ MATRIX *ReadMatlabFileVariable(const char *fname, const char *varname) { variables from a matlab file, including the variable name and data matrix. -------------------------------------------------------------*/ -MLFC *ReadMatlabFileContents(const char *fname) { +MLFC *ReadMatlabFileContents(const char *fname) +{ MLFC *mlfc; MATRIX *mat; MATFILE mf; @@ -609,7 +623,8 @@ MLFC *ReadMatlabFileContents(const char *fname) { } /*-------------------------------------------------------*/ -int MLFCprint(FILE *fp, MLFC *mlfc) { +int MLFCprint(FILE *fp, MLFC *mlfc) +{ int n; fprintf(fp, "mfile: %s\n", mlfc->mfile); @@ -625,7 +640,8 @@ int MLFCprint(FILE *fp, MLFC *mlfc) { } /*-------------------------------------------------------*/ -int MLFCfree(MLFC **ppmlfc) { +int MLFCfree(MLFC **ppmlfc) +{ MLFC *mlfc; int n; @@ -650,7 +666,8 @@ int MLFCfree(MLFC **ppmlfc) { should not be NULL (but does not check that there is an imaginary part to read in). --------------------------------------------------------------*/ -static int znzreadMatFile(char *unbuff, MATFILE *mf, double **real_matrix, double **imag_matrix) { +static int znzreadMatFile(char *unbuff, MATFILE *mf, double **real_matrix, double **imag_matrix) +{ int row, col, type, offset = 0; short sval = 1; long lval = 1; @@ -743,7 +760,8 @@ static int znzreadMatFile(char *unbuff, MATFILE *mf, double **real_matrix, doubl return (0); } /*--------------------------------------------------------------*/ -MATRIX *MatlabRead2(const char *fname) { +MATRIX *MatlabRead2(const char *fname) +{ MATRIX *mat; MATFILE mf; FILE *znzfp = NULL; @@ -809,7 +827,8 @@ MATRIX *MatlabRead2(const char *fname) { #else if (mf.imagf) { fptr = (float *)MATRIX_CELT(mat, row, 1); - } else + } + else fptr = MATRIX_RELT(mat, row, 1); #endif @@ -834,7 +853,8 @@ MATRIX *MatlabRead2(const char *fname) { element. If it has elements that are compressed, then it does not read anything. Returns NULL if something fails or if compressed. -------------------------------------------------------------------*/ -char *MatReadHeader(FILE *fp, MATFILE *mf, long32 *compressed) { +char *MatReadHeader(FILE *fp, MATFILE *mf, long32 *compressed) +{ int nitems, padding; char *name; char a, b, c, d, m; @@ -925,7 +945,8 @@ char *MatReadHeader(FILE *fp, MATFILE *mf, long32 *compressed) { d = fgetc(fp); ungetc(d, fp); ungetc(c, fp); - } else { + } + else { a = fgetc(fp); b = fgetc(fp); c = fgetc(fp); @@ -944,7 +965,8 @@ char *MatReadHeader(FILE *fp, MATFILE *mf, long32 *compressed) { // If name does not fill up an 8 byte segment, read past the filler padding = 8 - ((int)mf->namlen - (int)mf->namlen / 8 * 8); fseek(fp, padding, SEEK_CUR); - } else { /*small data element*/ + } + else { /*small data element*/ fread(&(mf->namlen), 1, fourbytes, fp); if (DIFFERENT_ENDIAN(mf)) mf->namlen = swapLong32(mf->namlen); memmove(&namlen_temp, &mf->namlen, sizeof(short)); @@ -1011,7 +1033,8 @@ char *MatReadHeader(FILE *fp, MATFILE *mf, long32 *compressed) { a compressed element. Does not actually interpret the data as a matrix, just uncompresses it into a buffer. ----------------------------------------------------------------*/ -char *znzMatReadHeader(FILE *fp, MATFILE *mf, char **data) { +char *znzMatReadHeader(FILE *fp, MATFILE *mf, char **data) +{ char *name = NULL; char m, c; char endian; @@ -1088,7 +1111,8 @@ char *znzMatReadHeader(FILE *fp, MATFILE *mf, char **data) { padding = 48 + ((((int)mf->namlen - 1) / 8) + 1); memmove(&(mf->type), &unbuff[padding], sizeof(long)); if (DIFFERENT_ENDIAN(mf)) mf->type = swapLong32(mf->type); - } else { + } + else { /*small data*/ memmove(&(mf->namlen), &unbuff[40], sizeof(long)); if (DIFFERENT_ENDIAN(mf)) mf->namlen = swapLong32(mf->namlen); diff --git a/utils/matrix.c b/utils/matrix.c index 675c65e0558..0393a474435 100644 --- a/utils/matrix.c +++ b/utils/matrix.c @@ -67,7 +67,8 @@ MATRIX *MatrixCalculateEigenSystemHelper(MATRIX *m, float *evalues, MATRIX *m_ev */ int MatrixIsSymmetric(MATRIX *matrix); -MATRIX *MatrixCopy(const MATRIX *mIn, MATRIX *mOut) { +MATRIX *MatrixCopy(const MATRIX *mIn, MATRIX *mOut) +{ int row, rows, cols, col; if (mIn == NULL) { @@ -95,7 +96,8 @@ MATRIX *MatrixCopy(const MATRIX *mIn, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixInverse(const MATRIX *mIn, MATRIX *mOut) { +MATRIX *MatrixInverse(const MATRIX *mIn, MATRIX *mOut) +{ float **a, **y; int isError, i, j, rows, cols, alloced = 0; MATRIX *mTmp; @@ -161,7 +163,8 @@ MATRIX *MatrixInverse(const MATRIX *mIn, MATRIX *mOut) { MatrixFree(&mQuad); MatrixFree(&mReal); MatrixFree(&mImag); - } else { + } + else { mTmp = MatrixCopy(mIn, NULL); a = mTmp->rptr; @@ -200,7 +203,8 @@ MATRIX *MatrixInverse(const MATRIX *mIn, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixAlloc(const int rows, const int cols, const int type) { +MATRIX *MatrixAlloc(const int rows, const int cols, const int type) +{ MATRIX *mat; int row, nelts; #ifdef _POSIX_MAPPED_FILES @@ -294,7 +298,8 @@ MATRIX *MatrixAlloc(const int rows, const int cols, const int type) { return (mat); } -int MatrixFree(MATRIX **pmat) { +int MatrixFree(MATRIX **pmat) +{ MATRIX *mat; if (!pmat) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MatrixFree: NULL pmat POINTER!\n")); @@ -316,7 +321,8 @@ int MatrixFree(MATRIX **pmat) { munmap((void *)mat->data, (nelts + 2) * sizeof(float)); #endif fclose(mat->mmapfile); - } else { + } + else { free(mat->data); } @@ -331,7 +337,8 @@ int MatrixFree(MATRIX **pmat) { \brief Multiplies two matrices. The accumulation is done with double, which is more accurate than MatrixMultiplyD() which uses float. */ -MATRIX *MatrixMultiplyD(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { +MATRIX *MatrixMultiplyD(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) +{ int col, row, i, rows, cols, m1_cols; float *r3; register float *r1, *r2; @@ -364,7 +371,8 @@ MATRIX *MatrixMultiplyD(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { else m3 = MatrixAlloc(m1->rows, m2->cols, m1->type); if (!m3) return (NULL); - } else if ((m3->rows != m1->rows) || (m3->cols != m2->cols)) { + } + else if ((m3->rows != m1->rows) || (m3->cols != m2->cols)) { printf("MatrixMultiplyD(): m1/m2 dim mismatch\n break %s:%d\n", __FILE__, __LINE__); ErrorReturn(NULL, (ERROR_BADPARM, @@ -402,7 +410,8 @@ MATRIX *MatrixMultiplyD(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { *r3++ = val; } } - } else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_COMPLEX)) { + } + else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_COMPLEX)) { for (row = 1; row <= rows; row++) { for (col = 1; col <= cols; col++) { for (i = 1; i <= m1->cols; i++) { @@ -417,7 +426,8 @@ MATRIX *MatrixMultiplyD(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { } } } - } else if ((m1->type == MATRIX_REAL) && (m2->type == MATRIX_COMPLEX)) { + } + else if ((m1->type == MATRIX_REAL) && (m2->type == MATRIX_COMPLEX)) { for (row = 1; row <= rows; row++) { for (col = 1; col <= cols; col++) { for (i = 1; i <= m1->cols; i++) { @@ -431,7 +441,8 @@ MATRIX *MatrixMultiplyD(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { } } } - } else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_REAL)) { + } + else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_REAL)) { for (row = 1; row <= rows; row++) { for (col = 1; col <= cols; col++) { for (i = 1; i <= m1->cols; i++) { @@ -456,7 +467,8 @@ MATRIX *MatrixMultiplyD(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { \brief Multiplies two matrices. The accumulation is done with float. Consider using MatrixMultiplyD() which uses double. */ -MATRIX *MatrixMultiply(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { +MATRIX *MatrixMultiply(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) +{ int col, row, i, rows, cols, m1_cols; float *r3; register float val, *r1, *r2; @@ -477,7 +489,8 @@ MATRIX *MatrixMultiply(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { else m3 = MatrixAlloc(m1->rows, m2->cols, m1->type); if (!m3) return (NULL); - } else if ((m3->rows != m1->rows) || (m3->cols != m2->cols)) { + } + else if ((m3->rows != m1->rows) || (m3->cols != m2->cols)) { printf("MatrixMultiply(): m3 dim mismatch\n break %s:%d\n", __FILE__, __LINE__); ErrorReturn(NULL, (ERROR_BADPARM, @@ -522,7 +535,8 @@ MATRIX *MatrixMultiply(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { *r3++ = val; } } - } else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_COMPLEX)) { + } + else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_COMPLEX)) { for (row = 1; row <= rows; row++) { for (col = 1; col <= cols; col++) { for (i = 1; i <= m1->cols; i++) { @@ -537,7 +551,8 @@ MATRIX *MatrixMultiply(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { } } } - } else if ((m1->type == MATRIX_REAL) && (m2->type == MATRIX_COMPLEX)) { + } + else if ((m1->type == MATRIX_REAL) && (m2->type == MATRIX_COMPLEX)) { for (row = 1; row <= rows; row++) { for (col = 1; col <= cols; col++) { for (i = 1; i <= m1->cols; i++) { @@ -551,7 +566,8 @@ MATRIX *MatrixMultiply(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { } } } - } else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_REAL)) { + } + else if ((m1->type == MATRIX_COMPLEX) && (m2->type == MATRIX_REAL)) { for (row = 1; row <= rows; row++) { for (col = 1; col <= cols; col++) { for (i = 1; i <= m1->cols; i++) { @@ -571,7 +587,8 @@ MATRIX *MatrixMultiply(const MATRIX *m1, const MATRIX *m2, MATRIX *m3) { return (m3); } -int MatrixPrint(FILE *fp, const MATRIX *mat) { +int MatrixPrint(FILE *fp, const MATRIX *mat) +{ int row, col, rows, cols; if (fp == NULL) { @@ -608,7 +625,8 @@ int MatrixPrint(FILE *fp, const MATRIX *mat) { return (NO_ERROR); } -int MatrixPrintWithString(FILE *fp, MATRIX *m, char *Pre, char *Post) { +int MatrixPrintWithString(FILE *fp, MATRIX *m, char *Pre, char *Post) +{ int err; fprintf(fp, "%s", Pre); err = MatrixPrint(fp, m); @@ -617,7 +635,8 @@ int MatrixPrintWithString(FILE *fp, MATRIX *m, char *Pre, char *Post) { return (err); } -int MatrixPrintFmt(FILE *fp, const char *fmt, MATRIX *mat) { +int MatrixPrintFmt(FILE *fp, const char *fmt, MATRIX *mat) +{ int row, col, rows, cols; if (fp == NULL) { @@ -652,7 +671,8 @@ int MatrixPrintFmt(FILE *fp, const char *fmt, MATRIX *mat) { return (NO_ERROR); } -int MatrixPrintOneLine(FILE *fp, MATRIX *mat) { +int MatrixPrintOneLine(FILE *fp, MATRIX *mat) +{ int row, col, rows, cols; rows = mat->rows; @@ -682,7 +702,8 @@ int MatrixPrintOneLine(FILE *fp, MATRIX *mat) { return (NO_ERROR); } -int MatrixPrintTranspose(FILE *fp, MATRIX *mat) { +int MatrixPrintTranspose(FILE *fp, MATRIX *mat) +{ int row, col, rows, cols; rows = mat->rows; @@ -713,7 +734,8 @@ int MatrixPrintTranspose(FILE *fp, MATRIX *mat) { return (NO_ERROR); } -MATRIX *MatrixReadTxt(const char *fname, MATRIX *mat) { +MATRIX *MatrixReadTxt(const char *fname, MATRIX *mat) +{ FILE *fp; int rows, cols, row, col, nlinemax, nread; char line[1000]; @@ -787,12 +809,14 @@ MATRIX *MatrixReadTxt(const char *fname, MATRIX *mat) { #endif MATRIX *MatrixRead(const char *fname) { return (MatlabRead(fname)); } -int MatrixWrite(MATRIX *mat, const char *fname, const char *name) { +int MatrixWrite(MATRIX *mat, const char *fname, const char *name) +{ if (!name) return (MatlabWrite(mat, fname, fname)); /* name of matrix in .mat file */ return (MatlabWrite(mat, fname, name)); } -MATRIX *MatrixIdentity(int n, MATRIX *mat) { +MATRIX *MatrixIdentity(int n, MATRIX *mat) +{ int i; if (!mat) @@ -805,7 +829,8 @@ MATRIX *MatrixIdentity(int n, MATRIX *mat) { return (mat); } -MATRIX *MatrixTranspose(MATRIX *mIn, MATRIX *mOut) { +MATRIX *MatrixTranspose(MATRIX *mIn, MATRIX *mOut) +{ int row, col, rows, cols; if (!mOut) { @@ -826,7 +851,8 @@ MATRIX *MatrixTranspose(MATRIX *mIn, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixAdd(const MATRIX *m1, const MATRIX *m2, MATRIX *mOut) { +MATRIX *MatrixAdd(const MATRIX *m1, const MATRIX *m2, MATRIX *mOut) +{ int row, col, rows, cols; rows = m1->rows; @@ -855,7 +881,8 @@ MATRIX *MatrixAdd(const MATRIX *m1, const MATRIX *m2, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixSubtract(const MATRIX *m1, const MATRIX *m2, MATRIX *mOut) { +MATRIX *MatrixSubtract(const MATRIX *m1, const MATRIX *m2, MATRIX *mOut) +{ int row, col, rows, cols; rows = m1->rows; @@ -887,7 +914,8 @@ MATRIX *MatrixSubtract(const MATRIX *m1, const MATRIX *m2, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixScalarMul(const MATRIX *mIn, const float val, MATRIX *mOut) { +MATRIX *MatrixScalarMul(const MATRIX *mIn, const float val, MATRIX *mOut) +{ int row, col, rows, cols; if (!mOut) { @@ -912,14 +940,16 @@ MATRIX *MatrixScalarMul(const MATRIX *mIn, const float val, MATRIX *mOut) { } return (mOut); } -MATRIX *VectorZeroMean(const MATRIX *mIn, MATRIX *mOut) { +MATRIX *VectorZeroMean(const MATRIX *mIn, MATRIX *mOut) +{ double mean; mean = VectorMean(mIn); return (MatrixScalarAdd(mIn, -mean, mOut)); } -MATRIX *MatrixScalarAdd(const MATRIX *mIn, const float val, MATRIX *mOut) { +MATRIX *MatrixScalarAdd(const MATRIX *mIn, const float val, MATRIX *mOut) +{ int row, col, rows, cols; if (!mOut) { @@ -945,7 +975,8 @@ MATRIX *MatrixScalarAdd(const MATRIX *mIn, const float val, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixClear(MATRIX *mat) { +MATRIX *MatrixClear(MATRIX *mat) +{ int rows, row, cols; rows = mat->rows; @@ -955,7 +986,8 @@ MATRIX *MatrixClear(MATRIX *mat) { return (mat); } -MATRIX *MatrixSquareElts(MATRIX *mIn, MATRIX *mOut) { +MATRIX *MatrixSquareElts(MATRIX *mIn, MATRIX *mOut) +{ int row, col, rows, cols; float val; @@ -985,7 +1017,8 @@ MATRIX *MatrixSquareElts(MATRIX *mIn, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixSqrtElts(MATRIX *mIn, MATRIX *mOut) { +MATRIX *MatrixSqrtElts(MATRIX *mIn, MATRIX *mOut) +{ int row, col, rows, cols; float val; @@ -1015,7 +1048,8 @@ MATRIX *MatrixSqrtElts(MATRIX *mIn, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixSignedSquareElts(MATRIX *mIn, MATRIX *mOut) { +MATRIX *MatrixSignedSquareElts(MATRIX *mIn, MATRIX *mOut) +{ int row, col, rows, cols; float val; @@ -1045,7 +1079,8 @@ MATRIX *MatrixSignedSquareElts(MATRIX *mIn, MATRIX *mOut) { return (mOut); } -MATRIX *MatrixMakeDiagonal(MATRIX *mSrc, MATRIX *mDst) { +MATRIX *MatrixMakeDiagonal(MATRIX *mSrc, MATRIX *mDst) +{ int row, rows, col, cols; if (!mDst) mDst = MatrixClone(mSrc); @@ -1067,7 +1102,8 @@ MATRIX *MatrixMakeDiagonal(MATRIX *mSrc, MATRIX *mDst) { /* mDiag is a column vector. */ -MATRIX *MatrixDiag(MATRIX *mDiag, MATRIX *mOut) { +MATRIX *MatrixDiag(MATRIX *mDiag, MATRIX *mOut) +{ int row, rows, col, cols, nout; rows = mDiag->rows; @@ -1077,7 +1113,8 @@ MATRIX *MatrixDiag(MATRIX *mDiag, MATRIX *mOut) { if (!mOut) { mOut = MatrixAlloc(nout, nout, mDiag->type); if (!mOut) return (NULL); - } else + } + else MatrixClear(mOut); if ((nout != mOut->rows) || (nout != mOut->cols)) @@ -1088,7 +1125,8 @@ MATRIX *MatrixDiag(MATRIX *mDiag, MATRIX *mOut) { if (rows != 1) { // column vector for (row = 1; row <= rows; row++) mOut->rptr[row][row] = mDiag->rptr[row][1]; - } else { + } + else { // row vector for (col = 1; col <= cols; col++) mOut->rptr[col][col] = mDiag->rptr[1][col]; } @@ -1103,7 +1141,8 @@ MATRIX *MatrixCopyRegion(const MATRIX *mSrc, const int rows, const int cols, const int dest_row, - const int dest_col) { + const int dest_col) +{ int srow, scol, drow, dcol, srows, scols, drows, dcols, end_row, end_col; if ((dest_col < 1) || (dest_row < 1)) @@ -1152,7 +1191,8 @@ MATRIX *MatrixCopyRealRegion(const MATRIX *mSrc, const int rows, const int cols, const int dest_row, - const int dest_col) { + const int dest_col) +{ int srow, scol, drow, dcol, srows, scols, drows, dcols, end_row, end_col; if ((dest_col < 1) || (dest_row < 1)) @@ -1202,7 +1242,8 @@ MATRIX *MatrixCopyImagRegion(const MATRIX *mSrc, const int rows, const int cols, const int dest_row, - const int dest_col) { + const int dest_col) +{ int srow, scol, drow, dcol, srows, scols, drows, dcols, end_row, end_col; if ((dest_col < 1) || (dest_row < 1)) @@ -1246,7 +1287,8 @@ MATRIX *MatrixCopyImagRegion(const MATRIX *mSrc, } /*--------------------------------------------------------------------*/ -MATRIX *MatrixSetRegion(MATRIX *mSrc, MATRIX *mDst, int start_row, int start_col, int rows, int cols, float val) { +MATRIX *MatrixSetRegion(MATRIX *mSrc, MATRIX *mDst, int start_row, int start_col, int rows, int cols, float val) +{ int r, c, end_row, end_col; end_row = start_row + rows - 1; @@ -1287,7 +1329,8 @@ MATRIX *MatrixSetRegion(MATRIX *mSrc, MATRIX *mDst, int start_row, int start_col } /*--------------------------------------------------------------------*/ -MATRIX *MatrixRealToComplex(MATRIX *mReal, MATRIX *mImag, MATRIX *mOut) { +MATRIX *MatrixRealToComplex(MATRIX *mReal, MATRIX *mImag, MATRIX *mOut) +{ int rows, cols, row, col; rows = mReal->rows; @@ -1314,12 +1357,14 @@ float MatrixDeterminant(MATRIX *mIn) { return OpenMatrixDeterminant(mIn); } static int compare_evalues(const void *l1, const void *l2); -typedef struct { +typedef struct +{ int eno; float evalue; } EIGEN_VALUE, EVALUE; -static int compare_evalues(const void *l1, const void *l2) { +static int compare_evalues(const void *l1, const void *l2) +{ EVALUE *e1, *e2; e1 = (EVALUE *)l1; @@ -1327,7 +1372,8 @@ static int compare_evalues(const void *l1, const void *l2) { return (fabs(e1->evalue) < fabs(e2->evalue) ? 1 : -1); } -MATRIX *MatrixCalculateEigenSystemHelper(MATRIX *m, float *evalues, MATRIX *m_evectors, int isSymmetric) { +MATRIX *MatrixCalculateEigenSystemHelper(MATRIX *m, float *evalues, MATRIX *m_evectors, int isSymmetric) +{ int col, i, nevalues, row; EVALUE *eigen_values; MATRIX *mTmp; @@ -1343,7 +1389,8 @@ MATRIX *MatrixCalculateEigenSystemHelper(MATRIX *m, float *evalues, MATRIX *m_ev if (isSymmetric) { if (OpenEigenSystem(m->data, m->rows, evalues, mTmp->data) != NO_ERROR) return (NULL); - } else { + } + else { if (OpenNonSymmetricEigenSystem(m->data, m->rows, evalues, mTmp->data) != NO_ERROR) return (NULL); } @@ -1369,7 +1416,8 @@ MATRIX *MatrixCalculateEigenSystemHelper(MATRIX *m, float *evalues, MATRIX *m_ev return (m_evectors); } -int MatrixIsSymmetric(MATRIX *matrix) { +int MatrixIsSymmetric(MATRIX *matrix) +{ int row; int col; int isSymmetric = 1; @@ -1387,7 +1435,8 @@ int MatrixIsSymmetric(MATRIX *matrix) { return isSymmetric; } -MATRIX *MatrixEigenSystem(MATRIX *m, float *evalues, MATRIX *m_evectors) { +MATRIX *MatrixEigenSystem(MATRIX *m, float *evalues, MATRIX *m_evectors) +{ int isSymmetric = MatrixIsSymmetric(m); return MatrixCalculateEigenSystemHelper(m, evalues, m_evectors, isSymmetric); @@ -1473,7 +1522,8 @@ static void svd(float **A, float **V, float *z, int m, int n) */ /* This looks to be the same as [u s v] = svd(mA), where v = mV, and s = diag(v_z) */ -MATRIX *MatrixSVD(MATRIX *mA, VECTOR *v_z, MATRIX *mV) { +MATRIX *MatrixSVD(MATRIX *mA, VECTOR *v_z, MATRIX *mV) +{ // mV = MatrixIdentity(mA->rows, mV) ; // svd(mA->rptr, mV->rptr, v_z->data, mA->rows, mA->cols) ; @@ -1483,7 +1533,8 @@ MATRIX *MatrixSVD(MATRIX *mA, VECTOR *v_z, MATRIX *mV) { return (mV); } -float MatrixSVDEigenValues(MATRIX *m, float *evalues) { +float MatrixSVDEigenValues(MATRIX *m, float *evalues) +{ float cond; VECTOR *v_w; MATRIX *m_U, *m_V; @@ -1536,7 +1587,8 @@ float MatrixSVDEigenValues(MATRIX *m, float *evalues) { */ #define TOO_SMALL 1e-4 -MATRIX *MatrixSVDInverse(MATRIX *m, MATRIX *m_inverse) { +MATRIX *MatrixSVDInverse(MATRIX *m, MATRIX *m_inverse) +{ VECTOR *v_w; MATRIX *m_U, *m_V, *m_w, *m_Ut, *m_tmp; int row, rows, cols; @@ -1583,7 +1635,8 @@ MATRIX *MatrixSVDInverse(MATRIX *m, MATRIX *m_inverse) { return (m_inverse); } -MATRIX *MatrixAllocTranslation(int n, double *trans) { +MATRIX *MatrixAllocTranslation(int n, double *trans) +{ MATRIX *mat; int i; @@ -1592,7 +1645,8 @@ MATRIX *MatrixAllocTranslation(int n, double *trans) { return (mat); } -MATRIX *MatrixReallocRotation(int n, float angle, int which, MATRIX *m) { +MATRIX *MatrixReallocRotation(int n, float angle, int which, MATRIX *m) +{ float s, c; if (!m) m = MatrixIdentity(n, NULL); @@ -1625,7 +1679,8 @@ MATRIX *MatrixReallocRotation(int n, float angle, int which, MATRIX *m) { MATRIX *MatrixAllocRotation(int n, float angle, int which) { return (MatrixReallocRotation(n, angle, which, NULL)); } -MATRIX *MatrixCovariance(MATRIX *mInputs, MATRIX *mCov, VECTOR *mMeans) { +MATRIX *MatrixCovariance(MATRIX *mInputs, MATRIX *mCov, VECTOR *mMeans) +{ int ninputs, nvars, input, var, var2; float *means, covariance, obs1, obs2; @@ -1679,7 +1734,8 @@ MATRIX *MatrixCovariance(MATRIX *mInputs, MATRIX *mCov, VECTOR *mMeans) { must be called with the means and total # of inputs before the covariance matrix is valid. */ -MATRIX *MatrixUpdateCovariance(MATRIX *mInputs, MATRIX *mCov, MATRIX *mMeans) { +MATRIX *MatrixUpdateCovariance(MATRIX *mInputs, MATRIX *mCov, MATRIX *mMeans) +{ int ninputs, nvars, input, var, var2; float covariance, obs1, obs2, mean1, mean2; @@ -1734,7 +1790,8 @@ MATRIX *MatrixUpdateCovariance(MATRIX *mInputs, MATRIX *mCov, MATRIX *mMeans) { update the means based on a new set of observation vectors. Notet that the user must keep track of the total # observations */ -MATRIX *MatrixUpdateMeans(MATRIX *mInputs, MATRIX *mMeans, VECTOR *mNobs) { +MATRIX *MatrixUpdateMeans(MATRIX *mInputs, MATRIX *mMeans, VECTOR *mNobs) +{ int ninputs, nvars, input, var; float *means; @@ -1754,7 +1811,8 @@ MATRIX *MatrixUpdateMeans(MATRIX *mInputs, MATRIX *mMeans, VECTOR *mNobs) { MatrixUpdateMeans. The user must supply a vector containing the # of observations of each variable. */ -MATRIX *MatrixFinalMeans(VECTOR *mMeans, VECTOR *mNobs) { +MATRIX *MatrixFinalMeans(VECTOR *mMeans, VECTOR *mNobs) +{ int nvars, var, n; float *means; @@ -1775,7 +1833,8 @@ MATRIX *MatrixFinalMeans(VECTOR *mMeans, VECTOR *mNobs) { MatrixUpdateCovariance. The user must supply a vector containing the # of observations per variable. */ -MATRIX *MatrixFinalCovariance(MATRIX *mInputs, MATRIX *mCov, VECTOR *mNobs) { +MATRIX *MatrixFinalCovariance(MATRIX *mInputs, MATRIX *mCov, VECTOR *mNobs) +{ int ninputs, nvars, var, var2; float covariance; @@ -1811,7 +1870,8 @@ MATRIX *MatrixFinalCovariance(MATRIX *mInputs, MATRIX *mCov, VECTOR *mNobs) { return (mCov); } -int MatrixAsciiWrite(const char *fname, MATRIX *m) { +int MatrixAsciiWrite(const char *fname, MATRIX *m) +{ FILE *fp; int ret; @@ -1822,7 +1882,8 @@ int MatrixAsciiWrite(const char *fname, MATRIX *m) { return (ret); } -MATRIX *MatrixAsciiRead(const char *fname, MATRIX *m) { +MATRIX *MatrixAsciiRead(const char *fname, MATRIX *m) +{ FILE *fp; fp = fopen(fname, "r"); @@ -1832,7 +1893,8 @@ MATRIX *MatrixAsciiRead(const char *fname, MATRIX *m) { return (m); } -int MatrixAsciiWriteInto(FILE *fp, MATRIX *m) { +int MatrixAsciiWriteInto(FILE *fp, MATRIX *m) +{ int row, col; fprintf(fp, "%d %d %d\n", m->type, m->rows, m->cols); @@ -1848,7 +1910,8 @@ int MatrixAsciiWriteInto(FILE *fp, MATRIX *m) { return (NO_ERROR); } -MATRIX *MatrixAsciiReadFrom(FILE *fp, MATRIX *m) { +MATRIX *MatrixAsciiReadFrom(FILE *fp, MATRIX *m) +{ int type, rows, cols, row, col; char *cp, line[200]; @@ -1860,7 +1923,8 @@ MATRIX *MatrixAsciiReadFrom(FILE *fp, MATRIX *m) { if (!m) { m = MatrixAlloc(rows, cols, type); if (!m) ErrorReturn(NULL, (ERROR_BADFILE, "MatrixAsciiReadFrom: could not allocate matrix")); - } else { + } + else { if (m->rows != rows || m->cols != cols || m->type != type) ErrorReturn(m, (ERROR_BADFILE, "MatrixAsciiReadFrom: specified matrix does not match file")); } @@ -1869,7 +1933,8 @@ MATRIX *MatrixAsciiReadFrom(FILE *fp, MATRIX *m) { if (m->type == MATRIX_COMPLEX) { if (fscanf(fp, "%f %f ", &MATRIX_CELT_REAL(m, row, col), &MATRIX_CELT_IMAG(m, row, col)) != 2) ErrorReturn(NULL, (ERROR_BADFILE, "MatrixAsciiReadFrom: could not scan element (%d, %d)", row, col)); - } else if (fscanf(fp, "%f ", &m->rptr[row][col]) != 1) + } + else if (fscanf(fp, "%f ", &m->rptr[row][col]) != 1) ErrorReturn(NULL, (ERROR_BADFILE, "MatrixAsciiReadFrom: could not scan element (%d, %d)", row, col)); } fscanf(fp, "\n"); @@ -1878,7 +1943,8 @@ MATRIX *MatrixAsciiReadFrom(FILE *fp, MATRIX *m) { return (m); } -int MatrixWriteInto(FILE *fp, MATRIX *m) { +int MatrixWriteInto(FILE *fp, MATRIX *m) +{ int row, col; fwriteInt(m->type, fp); @@ -1890,14 +1956,16 @@ int MatrixWriteInto(FILE *fp, MATRIX *m) { if (m->type == MATRIX_COMPLEX) { fwriteDouble(MATRIX_CELT_REAL(m, row, col), fp); fwriteDouble(MATRIX_CELT_IMAG(m, row, col), fp); - } else + } + else fwriteDouble(m->rptr[row][col], fp); } } return (NO_ERROR); } -MATRIX *MatrixReadFrom(FILE *fp, MATRIX *m) { +MATRIX *MatrixReadFrom(FILE *fp, MATRIX *m) +{ int row, col, rows, cols, type; type = freadInt(fp); @@ -1907,7 +1975,8 @@ MATRIX *MatrixReadFrom(FILE *fp, MATRIX *m) { if (!m) { m = MatrixAlloc(rows, cols, type); if (!m) ErrorReturn(NULL, (ERROR_BADFILE, "MatrixReadFrom: could not allocate matrix")); - } else { + } + else { if (m->rows != rows || m->cols != cols || m->type != type) ErrorReturn(m, (ERROR_BADFILE, "MatrixReadFrom: specified matrix does not match file")); } @@ -1917,7 +1986,8 @@ MATRIX *MatrixReadFrom(FILE *fp, MATRIX *m) { if (m->type == MATRIX_COMPLEX) { MATRIX_CELT_REAL(m, row, col) = freadDouble(fp); MATRIX_CELT_IMAG(m, row, col) = freadDouble(fp); - } else + } + else m->rptr[row][col] = freadDouble(fp); } } @@ -1928,7 +1998,8 @@ MATRIX *MatrixReadFrom(FILE *fp, MATRIX *m) { /* calculate and return the Euclidean norm of the vector v. */ -float VectorLen(const VECTOR *v) { +float VectorLen(const VECTOR *v) +{ int i; float len, vi; @@ -1941,7 +2012,8 @@ float VectorLen(const VECTOR *v) { } /* compute the dot product of 2 vectors */ -float VectorDot(const VECTOR *v1, const VECTOR *v2) { +float VectorDot(const VECTOR *v1, const VECTOR *v2) +{ int i; float dot; @@ -1952,7 +2024,8 @@ float VectorDot(const VECTOR *v1, const VECTOR *v2) { } /* compute the dot product of 2 vectors */ -float VectorNormalizedDot(VECTOR *v1, VECTOR *v2) { +float VectorNormalizedDot(VECTOR *v1, VECTOR *v2) +{ float dot, l1, l2; l1 = VectorLen(v1); @@ -1967,7 +2040,8 @@ float VectorNormalizedDot(VECTOR *v1, VECTOR *v2) { extract a column of the matrix m and return it in the vector v. */ -VECTOR *MatrixColumn(MATRIX *m, VECTOR *v, int col) { +VECTOR *MatrixColumn(MATRIX *m, VECTOR *v, int col) +{ int row; if (!v) v = VectorAlloc(m->rows, MATRIX_REAL); @@ -1977,7 +2051,8 @@ VECTOR *MatrixColumn(MATRIX *m, VECTOR *v, int col) { } /* calcuate and return the Euclidean distance between two vectors */ -float VectorDistance(VECTOR *v1, VECTOR *v2) { +float VectorDistance(VECTOR *v1, VECTOR *v2) +{ int row; float dist, d; @@ -1992,7 +2067,8 @@ float VectorDistance(VECTOR *v1, VECTOR *v2) { /* compute the outer product of the vectors v1 and v2. */ -MATRIX *VectorOuterProduct(VECTOR *v1, VECTOR *v2, MATRIX *m) { +MATRIX *VectorOuterProduct(VECTOR *v1, VECTOR *v2, MATRIX *m) +{ int row, col, rows, cols; float r; @@ -2016,7 +2092,8 @@ MATRIX *VectorOuterProduct(VECTOR *v1, VECTOR *v2, MATRIX *m) { non-singular. */ #define SMALL 1e-4 -MATRIX *MatrixRegularize(MATRIX *mIn, MATRIX *mOut) { +MATRIX *MatrixRegularize(MATRIX *mIn, MATRIX *mOut) +{ int rows, cols, row; float ran_num; @@ -2038,7 +2115,8 @@ MATRIX *MatrixRegularize(MATRIX *mIn, MATRIX *mOut) { } /* see if a matrix is singular */ -int MatrixSingular(MATRIX *m) { +int MatrixSingular(MATRIX *m) +{ #if 1 VECTOR *v_w; MATRIX *m_U, *m_V; @@ -2075,7 +2153,8 @@ int MatrixSingular(MATRIX *m) { #endif } -int MatrixIsZero(MATRIX *m) { +int MatrixIsZero(MATRIX *m) +{ int row, col; double val; @@ -2094,7 +2173,8 @@ int MatrixIsZero(MATRIX *m) { /* calcluate the condition # of a matrix using svd */ -float MatrixConditionNumber(MATRIX *m) { +float MatrixConditionNumber(MATRIX *m) +{ float cond; VECTOR *v_w; MATRIX *m_U, *m_V; @@ -2133,7 +2213,8 @@ float MatrixConditionNumber(MATRIX *m) { MatrixNSConditionNumber() - condition of a non-square matrix. Works for square matrices as well. -----------------------------------------------------------*/ -float MatrixNSConditionNumber(MATRIX *m) { +float MatrixNSConditionNumber(MATRIX *m) +{ float cond; MATRIX *mt, *p; @@ -2158,7 +2239,8 @@ float MatrixNSConditionNumber(MATRIX *m) { calculate the cross product of two vectors and return the result in vdst, allocating it if necessary. */ -VECTOR *VectorCrossProduct(const VECTOR *v1, const VECTOR *v2, VECTOR *vdst) { +VECTOR *VectorCrossProduct(const VECTOR *v1, const VECTOR *v2, VECTOR *vdst) +{ float x1, x2, y1, y2, z1, z2; if (v1->rows != 3 && v1->cols != 1) ErrorReturn(NULL, (ERROR_BADPARM, "VectorCrossProduct: must be 3-vectors")); @@ -2181,7 +2263,8 @@ VECTOR *VectorCrossProduct(const VECTOR *v1, const VECTOR *v2, VECTOR *vdst) { /* compute the triple scalar product v1 x v2 . v3 */ -float VectorTripleProduct(const VECTOR *v1, const VECTOR *v2, const VECTOR *v3) { +float VectorTripleProduct(const VECTOR *v1, const VECTOR *v2, const VECTOR *v3) +{ float x1, x2, y1, y2, z1, z2, x3, y3, z3, total; if (v1->rows != 3 && v1->cols != 1) ErrorReturn(0.0f, (ERROR_BADPARM, "VectorCrossProduct: must be 3-vectors")); @@ -2202,7 +2285,8 @@ float VectorTripleProduct(const VECTOR *v1, const VECTOR *v2, const VECTOR *v3) return (total); } -VECTOR *VectorNormalize(const VECTOR *vin, VECTOR *vout) { +VECTOR *VectorNormalize(const VECTOR *vin, VECTOR *vout) +{ float len; int row, col, rows, cols; @@ -2219,7 +2303,8 @@ VECTOR *VectorNormalize(const VECTOR *vin, VECTOR *vout) { return (vout); } -float VectorAngle(const VECTOR *v1, const VECTOR *v2) { +float VectorAngle(const VECTOR *v1, const VECTOR *v2) +{ float angle, l1, l2, dot, norm; l1 = VectorLen(v1); @@ -2234,7 +2319,8 @@ float VectorAngle(const VECTOR *v1, const VECTOR *v2) { return (angle); } -double Vector3Angle(VECTOR *v1, VECTOR *v2) { +double Vector3Angle(VECTOR *v1, VECTOR *v2) +{ double angle, l1, l2, dot, norm, x, y, z; x = V3_X(v1); @@ -2256,16 +2342,16 @@ double Vector3Angle(VECTOR *v1, VECTOR *v2) { return (angle); } -void XYZ_NORMALIZED_LOAD(XYZ *xyz, float *xyz_length, float x, float y, float z) { - float len = *xyz_length = sqrt((double)x*(double)x + - (double)y*(double)y + - (double)z*(double)z); - +void XYZ_NORMALIZED_LOAD(XYZ *xyz, float *xyz_length, float x, float y, float z) +{ + float len = *xyz_length = sqrt((double)x * (double)x + (double)y * (double)y + (double)z * (double)z); + if (len == 0.0f) { xyz->x = 1.0f; xyz->y = 0.0f; xyz->z = 0.0f; - } else { + } + else { float len_inv = 1.0f / len; xyz->x = x * len_inv; xyz->y = y * len_inv; @@ -2273,7 +2359,8 @@ void XYZ_NORMALIZED_LOAD(XYZ *xyz, float *xyz_length, float x, float y, float z) } } -float XYZApproxAngle(XYZ const *normalizedXYZ, float x2, float y2, float z2) { +float XYZApproxAngle(XYZ const *normalizedXYZ, float x2, float y2, float z2) +{ double x1 = normalizedXYZ->x; double y1 = normalizedXYZ->y; double z1 = normalizedXYZ->z; @@ -2344,7 +2431,8 @@ float XYZApproxAngle(XYZ const *normalizedXYZ, float x2, float y2, float z2) { return (angle); } -int MatrixWriteTxt(const char *fname, MATRIX *mat) { +int MatrixWriteTxt(const char *fname, MATRIX *mat) +{ FILE *fp; int row, col; @@ -2360,7 +2448,8 @@ int MatrixWriteTxt(const char *fname, MATRIX *mat) { return (NO_ERROR); } -MATRIX *MatrixPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) { +MATRIX *MatrixPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) +{ MATRIX *mT, *mTm, *mTm_inv; if (m->rows < m->cols) { @@ -2394,7 +2483,8 @@ MATRIX *MatrixPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) { return (m_pseudo_inv); } -MATRIX *MatrixRightPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) { +MATRIX *MatrixRightPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) +{ MATRIX *mT, *mmT, *mmT_inv; /* build mT (m mT)-1 */ @@ -2414,7 +2504,8 @@ MATRIX *MatrixRightPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) { return (m_pseudo_inv); } -int MatrixCheck(MATRIX *m) { +int MatrixCheck(MATRIX *m) +{ int rows, cols, r, c; rows = m->rows; @@ -2427,7 +2518,8 @@ int MatrixCheck(MATRIX *m) { return (NO_ERROR); } -MATRIX *MatrixReshape(MATRIX *m_src, MATRIX *m_dst, int rows, int cols) { +MATRIX *MatrixReshape(MATRIX *m_src, MATRIX *m_dst, int rows, int cols) +{ int r1, c1, r2, c2; if (m_dst) { @@ -2460,7 +2552,8 @@ MATRIX *MatrixReshape(MATRIX *m_src, MATRIX *m_dst, int rows, int cols) { } /*------------------------------------------------------------*/ -float MatrixTrace(MATRIX *M) { +float MatrixTrace(MATRIX *M) +{ int n, nmax; float trace; @@ -2481,7 +2574,8 @@ float MatrixTrace(MATRIX *M) { pointer to mcat (or the new matrix) is returned. If m1 is NULL, m2 is copied into mcat. If m2 is NULL, m1 is copied into mcat. -------------------------------------------------------------------*/ -MATRIX *MatrixHorCat(MATRIX *m1, MATRIX *m2, MATRIX *mcat) { +MATRIX *MatrixHorCat(MATRIX *m1, MATRIX *m2, MATRIX *mcat) +{ int r, c1, c2, c; if (m1 == NULL && m2 == NULL) { @@ -2539,7 +2633,8 @@ MATRIX *MatrixHorCat(MATRIX *m1, MATRIX *m2, MATRIX *mcat) { pointer to mcat (or the new matrix) is returned. If m1 is NULL, m2 is copied into mcat. If m2 is NULL, m1 is copied into mcat. -------------------------------------------------------------------*/ -MATRIX *MatrixVertCat(MATRIX *m1, MATRIX *m2, MATRIX *mcat) { +MATRIX *MatrixVertCat(MATRIX *m1, MATRIX *m2, MATRIX *mcat) +{ int r, r1, r2, c; if (m1 == NULL && m2 == NULL) { @@ -2600,7 +2695,8 @@ MATRIX *MatrixVertCat(MATRIX *m1, MATRIX *m2, MATRIX *mcat) { If X is NULL, then a matrix rows-by-cols is alloced. If X is non-NULL, then rows and cols are ignored. -------------------------------------------------------------*/ -MATRIX *MatrixConstVal(float val, int rows, int cols, MATRIX *X) { +MATRIX *MatrixConstVal(float val, int rows, int cols, MATRIX *X) +{ int r, c; if (X == NULL) X = MatrixAlloc(rows, cols, MATRIX_REAL); @@ -2619,7 +2715,8 @@ MATRIX *MatrixConstVal(float val, int rows, int cols, MATRIX *X) { matrix rows-by-cols is alloced. If X is non-NULL, then rows and cols are ignored. ------------------------------------------------------------------*/ -MATRIX *MatrixZero(int rows, int cols, MATRIX *X) { +MATRIX *MatrixZero(int rows, int cols, MATRIX *X) +{ X = MatrixConstVal(0, rows, cols, X); return (X); } @@ -2629,14 +2726,16 @@ MATRIX *MatrixZero(int rows, int cols, MATRIX *X) { \fn MATRIX *MatrixSum(MATRIX *m, int dim, MATRIX *msum) \brief Computes the sum given matrix */ -MATRIX *MatrixSum(MATRIX *m, int dim, MATRIX *msum) { +MATRIX *MatrixSum(MATRIX *m, int dim, MATRIX *msum) +{ int outrows, outcols; int r, c; if (dim == 1) { /* sum over the rows */ outrows = 1; outcols = m->cols; - } else { /* sum over the cols */ + } + else { /* sum over the cols */ outrows = m->rows; outcols = 1; } @@ -2660,7 +2759,8 @@ MATRIX *MatrixSum(MATRIX *m, int dim, MATRIX *msum) { msum->rptr[r][1] += m->rptr[r][c]; } } - } else { /* Just copy vector to output */ + } + else { /* Just copy vector to output */ if (dim == 1) for (c = 1; c <= m->cols; c++) msum->rptr[1][c] = m->rptr[1][c]; else @@ -2674,14 +2774,16 @@ MATRIX *MatrixSum(MATRIX *m, int dim, MATRIX *msum) { \fn MATRIX *MatrixSumSquare(MATRIX *m, int dim, MATRIX *msumsq) \brief Computes the sum of the squares of the given matrix */ -MATRIX *MatrixSumSquare(MATRIX *m, int dim, MATRIX *msumsq) { +MATRIX *MatrixSumSquare(MATRIX *m, int dim, MATRIX *msumsq) +{ int outrows, outcols; int r, c; if (dim == 1) { /* sum over the rows */ outrows = 1; outcols = m->cols; - } else { /* sum over the cols */ + } + else { /* sum over the cols */ outrows = m->rows; outcols = 1; } @@ -2705,7 +2807,8 @@ MATRIX *MatrixSumSquare(MATRIX *m, int dim, MATRIX *msumsq) { msumsq->rptr[r][1] += (m->rptr[r][c] * m->rptr[r][c]); } } - } else { /* Just copy vector to output */ + } + else { /* Just copy vector to output */ if (dim == 1) for (c = 1; c <= m->cols; c++) msumsq->rptr[1][c] = (m->rptr[1][c] * m->rptr[1][c]); else @@ -2715,7 +2818,8 @@ MATRIX *MatrixSumSquare(MATRIX *m, int dim, MATRIX *msumsq) { return (msumsq); } /*----------------------------------------------------------------*/ -double MatrixSumElts(MATRIX *m) { +double MatrixSumElts(MATRIX *m) +{ int r, c; double msum; @@ -2726,7 +2830,8 @@ double MatrixSumElts(MATRIX *m) { } /*----------------------------------------------------------------*/ -double VectorRange(MATRIX *v, double *pVmin, double *pVmax) { +double VectorRange(MATRIX *v, double *pVmin, double *pVmax) +{ double min, max, val; int r, c; @@ -2747,7 +2852,8 @@ double VectorRange(MATRIX *v, double *pVmin, double *pVmax) { } /*----------------------------------------------------------------*/ -double VectorSum(const MATRIX *v) { +double VectorSum(const MATRIX *v) +{ double sum; int r, c; @@ -2758,7 +2864,8 @@ double VectorSum(const MATRIX *v) { } /*----------------------------------------------------------------*/ -double VectorMean(const MATRIX *v) { +double VectorMean(const MATRIX *v) +{ double sum, mean; sum = VectorSum(v); @@ -2768,7 +2875,8 @@ double VectorMean(const MATRIX *v) { } /*----------------------------------------------------------------*/ -double VectorVar(MATRIX *v, double *pMean) { +double VectorVar(MATRIX *v, double *pMean) +{ double f, mean, sum2, var; int r, c; @@ -2789,14 +2897,16 @@ double VectorVar(MATRIX *v, double *pMean) { } /*----------------------------------------------------------------*/ -double VectorStdDev(MATRIX *v, double *pMean) { +double VectorStdDev(MATRIX *v, double *pMean) +{ double var; var = VectorVar(v, pMean); return (sqrt(var)); } /*----------------------------------------------------------------*/ -MATRIX *MatrixDRand48(int rows, int cols, MATRIX *m) { +MATRIX *MatrixDRand48(int rows, int cols, MATRIX *m) +{ int r, c; if (m == NULL) m = MatrixAlloc(rows, cols, MATRIX_REAL); @@ -2812,7 +2922,8 @@ MATRIX *MatrixDRand48(int rows, int cols, MATRIX *m) { } /*----------------------------------------------------------------*/ -MATRIX *MatrixDRand48ZeroMean(int rows, int cols, MATRIX *m) { +MATRIX *MatrixDRand48ZeroMean(int rows, int cols, MATRIX *m) +{ int r, c; if (m == NULL) m = MatrixAlloc(rows, cols, MATRIX_REAL); @@ -2841,7 +2952,8 @@ MATRIX *MatrixDRand48ZeroMean(int rows, int cols, MATRIX *m) { Return: D -----------------------------------------------------------------*/ -MATRIX *MatrixFactorSqrSVD(MATRIX *M, int Invert, MATRIX *D) { +MATRIX *MatrixFactorSqrSVD(MATRIX *M, int Invert, MATRIX *D) +{ static int matalloc = 1; static VECTOR *S = NULL; static MATRIX *U = NULL, *V = NULL, *Vt = NULL; @@ -2931,7 +3043,8 @@ MATRIX *MatrixFactorSqrSVD(MATRIX *M, int Invert, MATRIX *D) { above and including the main, and (3) Symetric: both upper and lower. ---------------------------------------------------------*/ -MATRIX *MatrixToeplitz(VECTOR *v, MATRIX *T, int Type) { +MATRIX *MatrixToeplitz(VECTOR *v, MATRIX *T, int Type) +{ int r, c; if (Type != MATRIX_SYM && Type != MATRIX_UPPER && Type != MATRIX_LOWER) { @@ -2942,7 +3055,8 @@ MATRIX *MatrixToeplitz(VECTOR *v, MATRIX *T, int Type) { if (T == NULL) { T = MatrixAlloc(v->rows, v->rows, MATRIX_REAL); if (T == NULL) return (NULL); - } else { + } + else { if (T->rows != v->rows || T->cols != v->rows) { printf("ERROR: dimension mismatch\n"); return (NULL); @@ -2970,7 +3084,8 @@ MATRIX *MatrixToeplitz(VECTOR *v, MATRIX *T, int Type) { \fn MATRIX *MatrixNormalizeColScale(MATRIX *m, MATRIX *scale) \brief Computes the scaling used for MatrixNormalizeCol() */ -MATRIX *MatrixNormalizeColScale(MATRIX *m, MATRIX *scale) { +MATRIX *MatrixNormalizeColScale(MATRIX *m, MATRIX *scale) +{ int r, c; double sum2, v; @@ -2993,7 +3108,8 @@ MATRIX *MatrixNormalizeColScale(MATRIX *m, MATRIX *scale) { \fn MATRIX *MatrixNormalizeCol(MATRIX *m, MATRIX *mcnorm) \brief Rescales m so that sum(col^2)=1 */ -MATRIX *MatrixNormalizeCol(MATRIX *m, MATRIX *mcnorm, MATRIX *scale) { +MATRIX *MatrixNormalizeCol(MATRIX *m, MATRIX *mcnorm, MATRIX *scale) +{ int r, c, FreeScale = 1; double v; @@ -3003,7 +3119,8 @@ MATRIX *MatrixNormalizeCol(MATRIX *m, MATRIX *mcnorm, MATRIX *scale) { printf("ERROR: MatrixNormalizeCol: could not alloc\n"); return (NULL); } - } else { + } + else { if (mcnorm->rows != m->rows || mcnorm->cols != m->cols) { printf("ERROR: MatrixNormalizeCol: dimension mismatch\n"); return (NULL); @@ -3029,7 +3146,8 @@ MATRIX *MatrixNormalizeCol(MATRIX *m, MATRIX *mcnorm, MATRIX *scale) { return (mcnorm); } -MATRIX *MatrixSimilarityTransform(MATRIX *m_src, MATRIX *m_mul, MATRIX *m_dst) { +MATRIX *MatrixSimilarityTransform(MATRIX *m_src, MATRIX *m_mul, MATRIX *m_dst) +{ MATRIX *m_mul_T, *m_tmp; m_mul_T = MatrixTranspose(m_mul, NULL); @@ -3045,7 +3163,8 @@ MATRIX *MatrixSimilarityTransform(MATRIX *m_src, MATRIX *m_mul, MATRIX *m_dst) { curve is centered at the meanth row and has std. The mean can be non-integer. If norm == 1, then the sum is adjusted to be 1. ---------------------------------------------------------------*/ -MATRIX *GaussianVector(int len, float mean, float std, int norm, MATRIX *g) { +MATRIX *GaussianVector(int len, float mean, float std, int norm, MATRIX *g) +{ int n; float v, sum, var, f; @@ -3082,7 +3201,8 @@ MATRIX *GaussianVector(int len, float mean, float std, int norm, MATRIX *g) { deviation std. If norm == 1, then the sum of each row is adjusted to be 1. The matrix will be len-by-len. ---------------------------------------------------------------*/ -MATRIX *GaussianMatrix(int len, float std, int norm, MATRIX *G) { +MATRIX *GaussianMatrix(int len, float std, int norm, MATRIX *G) +{ int r, c; float d, v, sum, var, f; @@ -3124,7 +3244,8 @@ MATRIX *GaussianMatrix(int len, float std, int norm, MATRIX *G) { return (G); } -MATRIX *MatrixSVDPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) { +MATRIX *MatrixSVDPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) +{ int rows = m->rows; int cols = m->cols; if (rows < cols) { @@ -3133,7 +3254,8 @@ MATRIX *MatrixSVDPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) { MatrixFree(&mT); mT = m_pseudo_inv; m_pseudo_inv = MatrixTranspose(mT, NULL); - } else { + } + else { int r, c; MATRIX *m_U, *m_V, *m_Ur, *m_Vr, *m_Sr, *m_tmp, *m_S; VECTOR *v_S; @@ -3178,7 +3300,8 @@ MATRIX *MatrixSVDPseudoInverse(MATRIX *m, MATRIX *m_pseudo_inv) { 3rd row of X. The rows in NewRowOrder are 1-based. See also RandPermList() in evschutils.c. CANNOT be done in-place. -----------------------------------------------------------------*/ -MATRIX *MatrixReorderRows(MATRIX *X, int *NewRowOrder, MATRIX *XRO) { +MATRIX *MatrixReorderRows(MATRIX *X, int *NewRowOrder, MATRIX *XRO) +{ int r, c; if (XRO == NULL) XRO = MatrixAlloc(X->rows, X->cols, MATRIX_REAL); for (r = 1; r <= X->rows; r++) { @@ -3193,7 +3316,8 @@ MATRIX *MatrixReorderRows(MATRIX *X, int *NewRowOrder, MATRIX *XRO) { MatrixRandPermRows() - randomly reorders the rows of the input matrix. -----------------------------------------------------------------*/ -int MatrixRandPermRows(MATRIX *X) { +int MatrixRandPermRows(MATRIX *X) +{ int *NewRowOrder, r; MATRIX *X0; @@ -3211,7 +3335,8 @@ int MatrixRandPermRows(MATRIX *X) { orthogonal. Computes X'*X and examines the off diagonals. If any are greater than 2*FLT_MIN, then returns 1. --------------------------------------------------------------------*/ -int MatrixColsAreNotOrthog(MATRIX *X) { +int MatrixColsAreNotOrthog(MATRIX *X) +{ MATRIX *Xt, *XtX; int r, c; @@ -3231,7 +3356,8 @@ int MatrixColsAreNotOrthog(MATRIX *X) { return (0); } -double MatrixMahalanobisDistance(VECTOR *v_mean, MATRIX *m_inv_cov, VECTOR *v) { +double MatrixMahalanobisDistance(VECTOR *v_mean, MATRIX *m_inv_cov, VECTOR *v) +{ VECTOR *v_dif, *v_tmp; double dist; @@ -3255,7 +3381,8 @@ should include the head (100 in RAS coord) \param m2 4x4 affine transformation (may be NULL) \param radius of the ball to be considered */ -double MatrixTransformDistance(MATRIX *m1, MATRIX *m2, double radius) { +double MatrixTransformDistance(MATRIX *m1, MATRIX *m2, double radius) +{ MATRIX *drigid = MatrixCopy(m1, NULL); if (m2) drigid = MatrixSubtract(drigid, m2, drigid); @@ -3300,7 +3427,8 @@ double MatrixTransformDistance(MATRIX *m1, MATRIX *m2, double radius) { /* for 3d vector macros */ #include "tritri.h" -int MatrixOrthonormalizeTransform(MATRIX *m_L) { +int MatrixOrthonormalizeTransform(MATRIX *m_L) +{ double dot, c1[3], c2[3], c3[3], len; int i; @@ -3351,7 +3479,8 @@ int MatrixOrthonormalizeTransform(MATRIX *m_L) { return (NO_ERROR); } -MATRIX *MatrixAsciiReadRaw(const char *fname, MATRIX *m) { +MATRIX *MatrixAsciiReadRaw(const char *fname, MATRIX *m) +{ FILE *fp; int rows, cols, row, col; char line[10 * STRLEN], *cp; @@ -3387,7 +3516,8 @@ MATRIX *MatrixAsciiReadRaw(const char *fname, MATRIX *m) { return (m); } -int MatrixToRigidParameters(MATRIX *m, double *pxr, double *pyr, double *pzr, double *pxt, double *pyt, double *pzt) { +int MatrixToRigidParameters(MATRIX *m, double *pxr, double *pyr, double *pzr, double *pxt, double *pyt, double *pzt) +{ // M = Mx * My * Mz *pxr = atan2(*MATRIX_RELT(m, 2, 3), *MATRIX_RELT(m, 3, 3)); *pyr = asin(-*MATRIX_RELT(m, 1, 3)); @@ -3397,7 +3527,8 @@ int MatrixToRigidParameters(MATRIX *m, double *pxr, double *pyr, double *pzr, do *pzt = *MATRIX_RELT(m, 3, 4); return (NO_ERROR); } -MATRIX *MatrixFromRigidParameters(MATRIX *m, double xr, double yr, double zr, double xt, double yt, double zt) { +MATRIX *MatrixFromRigidParameters(MATRIX *m, double xr, double yr, double zr, double xt, double yt, double zt) +{ if (m == NULL) m = MatrixAlloc(4, 4, MATRIX_REAL); *MATRIX_RELT(m, 1, 1) = cos(yr) * cos(zr); @@ -3420,7 +3551,8 @@ MATRIX *MatrixFromRigidParameters(MATRIX *m, double xr, double yr, double zr, do return (m); } -int MatrixCheckFinite(MATRIX *m) { +int MatrixCheckFinite(MATRIX *m) +{ int r, c, retval = NO_ERROR; for (r = 1; r < m->rows; r++) @@ -3437,7 +3569,8 @@ int MatrixCheckFinite(MATRIX *m) { \fn MATRIX *MatrixKron(MATRIX *m1, MATRIX *m2, MATRIX *k) \brief Kronecker tensor product. */ -MATRIX *MatrixKron(MATRIX *m1, MATRIX *m2, MATRIX *k) { +MATRIX *MatrixKron(MATRIX *m1, MATRIX *m2, MATRIX *k) +{ int rows, cols; int r1, c1, r2, c2, r, c; double v1, v2; @@ -3451,7 +3584,8 @@ MATRIX *MatrixKron(MATRIX *m1, MATRIX *m2, MATRIX *k) { printf("ERROR: MatrixKron: could not alloc %d %d\n", rows, cols); return (NULL); } - } else { + } + else { if (k->rows != rows || k->cols != cols) { printf("ERROR: MatrixKron: dimension mismatch %d %d vs %d %d\n", rows, cols, k->rows, k->cols); return (NULL); @@ -3479,7 +3613,8 @@ MATRIX *MatrixKron(MATRIX *m1, MATRIX *m2, MATRIX *k) { \fn double MatrixRowDotProduct(MATRIX *m, int row, VECTOR *v) \brief dot product of a vector with the row of a matrix */ -double MatrixRowDotProduct(MATRIX *m, int row, VECTOR *v) { +double MatrixRowDotProduct(MATRIX *m, int row, VECTOR *v) +{ double dot; int col; @@ -3491,7 +3626,8 @@ double MatrixRowDotProduct(MATRIX *m, int row, VECTOR *v) { \fn MATRIX *MatrixDemean(MATRIX *M, MATRIX *Mdm) \brief Removes the mean from each column */ -MATRIX *MatrixDemean(MATRIX *M, MATRIX *Mdm) { +MATRIX *MatrixDemean(MATRIX *M, MATRIX *Mdm) +{ int r, c; double vsum, vmean; @@ -3517,7 +3653,8 @@ MATRIX *MatrixDemean(MATRIX *M, MATRIX *Mdm) { \brief Creates a new matrix by excluding the given set of rows. \param Src - source matrix. */ -MATRIX *MatrixExcludeFrames(MATRIX *Src, int *ExcludeFrames, int nExclude) { +MATRIX *MatrixExcludeFrames(MATRIX *Src, int *ExcludeFrames, int nExclude) +{ MATRIX *Trg = NULL; int q, n, skip, m, c, nframesNew; @@ -3542,14 +3679,16 @@ MATRIX *MatrixExcludeFrames(MATRIX *Src, int *ExcludeFrames, int nExclude) { \fn int MatrixIsIdentity(MATRIX *m) \brief returns 1 if matrix m is the identity matrix, 0 otherwise */ -int MatrixIsIdentity(MATRIX *m) { +int MatrixIsIdentity(MATRIX *m) +{ int r, c; for (r = 1; r < m->rows; r++) for (c = 1; c < m->cols; c++) { if (r == c) { if (FEQUAL(*MATRIX_RELT(m, r, c), 1) == 0) return (0); - } else if (FEQUAL(*MATRIX_RELT(m, r, c), 0.0) == 0) + } + else if (FEQUAL(*MATRIX_RELT(m, r, c), 0.0) == 0) return (0); } return (1); @@ -3559,7 +3698,8 @@ int MatrixIsIdentity(MATRIX *m) { \fn MATRIX *MatrixCumTrapZ(MATRIX *y, MATRIX *t, MATRIX *yz) \brief Computes trapezoidal integration (like matlab cumtrapz) */ -MATRIX *MatrixCumTrapZ(MATRIX *y, MATRIX *t, MATRIX *yz) { +MATRIX *MatrixCumTrapZ(MATRIX *y, MATRIX *t, MATRIX *yz) +{ if (yz == NULL) yz = MatrixAlloc(y->rows, y->cols, MATRIX_REAL); int c, f; @@ -3610,7 +3750,8 @@ MATRIX *MatrixCumTrapZ(MATRIX *y, MATRIX *t, MATRIX *yz) { Brace Jovanovich. */ -MATRIX *ANOVAContrast(int *FLevels, int nFactors, int *FactorList, int nFactorList) { +MATRIX *ANOVAContrast(int *FLevels, int nFactors, int *FactorList, int nFactorList) +{ int n, nthFactor, InList; MATRIX *M, *Mf, *K; @@ -3660,7 +3801,8 @@ MATRIX *ANOVAContrast(int *FLevels, int nFactors, int *FactorList, int nFactorLi \brief Summing vector for main effect of a factor. nLevels = number of levels in the factor. */ -MATRIX *ANOVASummingVector(int nLevels) { +MATRIX *ANOVASummingVector(int nLevels) +{ MATRIX *S; S = MatrixConstVal(1, 1, nLevels, NULL); return (S); @@ -3672,14 +3814,16 @@ MATRIX *ANOVASummingVector(int nLevels) { levels in the factor, Level is the one-based level number to select. Used to create a Simple Main Effect ANOVA matrix. */ -MATRIX *ANOVASelectionVector(int nLevels, int Level) { +MATRIX *ANOVASelectionVector(int nLevels, int Level) +{ MATRIX *S; S = MatrixConstVal(0, 1, nLevels, NULL); S->rptr[1][Level] = 1; return (S); } //--------------------------------------------------------- -MATRIX *ANOVAOmnibus(int nLevels) { +MATRIX *ANOVAOmnibus(int nLevels) +{ MATRIX *O; int r; O = MatrixAlloc(nLevels - 1, nLevels, MATRIX_REAL); @@ -3689,7 +3833,8 @@ MATRIX *ANOVAOmnibus(int nLevels) { } return (O); } -double MatrixSSE(MATRIX *m1, MATRIX *m2) { +double MatrixSSE(MATRIX *m1, MATRIX *m2) +{ int r, c; double sse, error; @@ -3701,7 +3846,8 @@ double MatrixSSE(MATRIX *m1, MATRIX *m2) { return (sse); } -double MatrixRMS(MATRIX *m1, MATRIX *m2) { +double MatrixRMS(MATRIX *m1, MATRIX *m2) +{ double sse; sse = MatrixSSE(m1, m2); @@ -3715,7 +3861,8 @@ double MatrixRMS(MATRIX *m1, MATRIX *m2) { load balancing when parallelizing with Open MP (makes it almost 2x faster). */ -MATRIX *MatrixMtM(MATRIX *m, MATRIX *mout) { +MATRIX *MatrixMtM(MATRIX *m, MATRIX *mout) +{ int c1, c2, n, rows, cols; static int *c1list = NULL, *c2list = NULL, ntot = 0; @@ -3805,7 +3952,8 @@ MATRIX *MatrixMtM(MATRIX *m, MATRIX *mout) { \brief Computes the skew (3rd moment) of the values in each column of y. If y has multiple columns, a skew is computed for each one.xx */ -MATRIX *MatrixSkew(MATRIX *y, MATRIX *s) { +MATRIX *MatrixSkew(MATRIX *y, MATRIX *s) +{ int c, r; double mn, m2, m3, g1, delta, n, adj; @@ -3842,7 +3990,8 @@ MATRIX *MatrixSkew(MATRIX *y, MATRIX *s) { in each column of y. If y has multiple columns, a kurtosis is computed for each one.x */ -MATRIX *MatrixKurtosis(MATRIX *y, MATRIX *k) { +MATRIX *MatrixKurtosis(MATRIX *y, MATRIX *k) +{ int c, r; double mn, m4 = 0, m2 = 0, g2, delta, b1, b2, n; @@ -3882,7 +4031,8 @@ MATRIX *MatrixKurtosis(MATRIX *y, MATRIX *k) { explicitly. This can be helpful whan A is a large matrix. Accumlates using double. OpenMP capable. */ -MATRIX *MatrixAtB(MATRIX *A, MATRIX *B, MATRIX *mout) { +MATRIX *MatrixAtB(MATRIX *A, MATRIX *B, MATRIX *mout) +{ int colA; if (A->rows != B->rows) { @@ -3939,7 +4089,8 @@ MATRIX *MatrixAtB(MATRIX *A, MATRIX *B, MATRIX *mout) { between two matrices. If dthresh is > 0, then prints more info about each element whose diff is > dthresh */ -double MatrixMaxAbsDiff(MATRIX *m1, MATRIX *m2, double dthresh) { +double MatrixMaxAbsDiff(MATRIX *m1, MATRIX *m2, double dthresh) +{ int r, c; double d, dmax; if (m1->rows != m2->rows || m1->cols != m2->cols) { @@ -3965,7 +4116,8 @@ double MatrixMaxAbsDiff(MATRIX *m1, MATRIX *m2, double dthresh) { number of columns or else a null matrix is returned and err=1. Otherwise err=0. */ -MATRIX *MatrixColNullSpace(MATRIX *M, int *err) { +MATRIX *MatrixColNullSpace(MATRIX *M, int *err) +{ MATRIX *u, *s, *v, *M2; int dim, r, c, dimmax, ndim; double thresh = 0; @@ -3990,7 +4142,8 @@ MATRIX *MatrixColNullSpace(MATRIX *M, int *err) { M2->rptr[r][c] = M->rptr[r][c]; } } - } else + } + else M2 = MatrixCopy(M, NULL); // Compute SVD M2 = u*s*v' @@ -4006,7 +4159,8 @@ MATRIX *MatrixColNullSpace(MATRIX *M, int *err) { for (dim = 1; dim <= s->cols; dim++) if (s->rptr[1][dim] < thresh) break; dim--; - } else + } + else dim = 0; ndim = M->rows - dim; // dim of the null space @@ -4059,7 +4213,8 @@ MATRIX *MatrixColNullSpace(MATRIX *M, int *err) { \brief Computes the residual forming matrix R = I - X*inv(X'*X)*X'; */ -MATRIX *MatrixResidualForming(MATRIX *X, MATRIX *R) { +MATRIX *MatrixResidualForming(MATRIX *X, MATRIX *R) +{ MATRIX *Xt, *XtX, *iXtX, *I, *XiXtX, *XiXtXXt; Xt = MatrixTranspose(X, NULL); diff --git a/utils/mgh_filter.c b/utils/mgh_filter.c index 55371276d4d..6a37821d9df 100644 --- a/utils/mgh_filter.c +++ b/utils/mgh_filter.c @@ -41,7 +41,8 @@ static void bandpass(float data[], int nn, float lo, float hi); void bpfilter(FLOATTYPE **data, int nchan, int nsamp, float lo, float hi); /* End prototypes */ -static void four1(float data[], int nn, int isign) { +static void four1(float data[], int nn, int isign) +{ int n, mmax, m, j, istep, i; double wtemp, wr, wpr, wpi, wi, theta; float tempr, tempi; @@ -108,7 +109,8 @@ static void lowpass(float data[],int nn,float hi) } #endif -static void bandpass(float data[], int nn, float lo, float hi) { +static void bandpass(float data[], int nn, float lo, float hi) +{ // float norm, float f, fl, fh, w, wh, wl; int i; @@ -130,7 +132,8 @@ static void bandpass(float data[], int nn, float lo, float hi) { four1(data - 1, nn, -1); } -void bpfilter(FLOATTYPE **data, int nchan, int nsamp, float lo, float hi) { +void bpfilter(FLOATTYPE **data, int nchan, int nsamp, float lo, float hi) +{ float *tmpvec; int i, j; diff --git a/utils/mgh_matrix.c b/utils/mgh_matrix.c index cf489541bd9..69fe32e6c27 100644 --- a/utils/mgh_matrix.c +++ b/utils/mgh_matrix.c @@ -33,7 +33,8 @@ #include "mgh_matrix.h" -FLOATTYPE *MGH_vector(int n) { +FLOATTYPE *MGH_vector(int n) +{ FLOATTYPE *h; h = (FLOATTYPE *)calloc(n, sizeof(FLOATTYPE)); @@ -44,7 +45,8 @@ FLOATTYPE *MGH_vector(int n) { return h; } -int *MGH_ivector(int n) { +int *MGH_ivector(int n) +{ int *h; h = (int *)calloc(n, sizeof(int)); @@ -55,7 +57,8 @@ int *MGH_ivector(int n) { return h; } -FLOATTYPE **MGH_matrix(int n, int m) { +FLOATTYPE **MGH_matrix(int n, int m) +{ FLOATTYPE **h; int i; @@ -68,7 +71,8 @@ FLOATTYPE **MGH_matrix(int n, int m) { return h; } -void print_matrix(FLOATTYPE **a, int m, int n) { +void print_matrix(FLOATTYPE **a, int m, int n) +{ int i, j; if (n > 0) { @@ -82,7 +86,8 @@ void print_matrix(FLOATTYPE **a, int m, int n) { } } -void read_matrix(FILE *fptr, FLOATTYPE **a, int m, int n) { +void read_matrix(FILE *fptr, FLOATTYPE **a, int m, int n) +{ int i, j; float f; @@ -95,7 +100,8 @@ void read_matrix(FILE *fptr, FLOATTYPE **a, int m, int n) { } } -void print_vector(FLOATTYPE *v, int n) { +void print_vector(FLOATTYPE *v, int n) +{ int i; for (i = 0; i < n; i++) { @@ -104,7 +110,8 @@ void print_vector(FLOATTYPE *v, int n) { printf("\n\n"); } -void row_vector(FLOATTYPE **a, FLOATTYPE *v, int i, int n) { +void row_vector(FLOATTYPE **a, FLOATTYPE *v, int i, int n) +{ int j; for (j = 0; j < n; j++) { @@ -112,7 +119,8 @@ void row_vector(FLOATTYPE **a, FLOATTYPE *v, int i, int n) { } } -void vector_to_matrix(FLOATTYPE *v, FLOATTYPE **a, int m, int n) { +void vector_to_matrix(FLOATTYPE *v, FLOATTYPE **a, int m, int n) +{ int i, j, indx = 0; for (i = 0; i < m; i++) @@ -121,14 +129,16 @@ void vector_to_matrix(FLOATTYPE *v, FLOATTYPE **a, int m, int n) { } } -void scale_matrix(FLOATTYPE **a, FLOATTYPE s, int n, int m) { +void scale_matrix(FLOATTYPE **a, FLOATTYPE s, int n, int m) +{ int i, j; for (i = 0; i < n; i++) for (j = 0; j < m; j++) a[i][j] *= s; } -void normalize_matrix(FLOATTYPE **a, int n, int m) { +void normalize_matrix(FLOATTYPE **a, int n, int m) +{ FLOATTYPE sum = 0; int i, j; @@ -137,35 +147,40 @@ void normalize_matrix(FLOATTYPE **a, int n, int m) { /* scale_matrix(a,n/sum,n,m); */ } -void matrix_copy(FLOATTYPE **a, FLOATTYPE **b, int n, int m) { +void matrix_copy(FLOATTYPE **a, FLOATTYPE **b, int n, int m) +{ int i, j; for (i = 0; i < n; i++) for (j = 0; j < m; j++) b[i][j] = a[i][j]; } -void matrix_copy2(FLOATTYPE **a, FLOATTYPE **b, int n, int m, int sno, int smo, int tno, int tmo) { +void matrix_copy2(FLOATTYPE **a, FLOATTYPE **b, int n, int m, int sno, int smo, int tno, int tmo) +{ int i, j; for (i = 0; i < n; i++) for (j = 0; j < m; j++) b[i + tno][j + tmo] = a[i + sno][j + smo]; } -void matrix_transpose(FLOATTYPE **a, FLOATTYPE **at, int n, int m) { +void matrix_transpose(FLOATTYPE **a, FLOATTYPE **at, int n, int m) +{ int i, j; for (i = 0; i < m; i++) for (j = 0; j < n; j++) at[i][j] = a[j][i]; } -void matrix_add(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) { +void matrix_add(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) +{ int i, j; for (i = 0; i < n; i++) for (j = 0; j < m; j++) c[i][j] = a[i][j] + b[i][j]; } -void matrix_multiply(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) { +void matrix_multiply(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) +{ FLOATTYPE sum; int i, j, k; @@ -178,7 +193,8 @@ void matrix_multiply(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) } } -void matrix_multiply2(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m, int l) { +void matrix_multiply2(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m, int l) +{ FLOATTYPE sum; int i, j, k; @@ -191,7 +207,8 @@ void matrix_multiply2(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m, } } -void matrix_angles(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) { +void matrix_angles(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) +{ FLOATTYPE sum, asum, bsum; int i, j, k; @@ -208,19 +225,22 @@ void matrix_angles(FLOATTYPE **a, FLOATTYPE **b, FLOATTYPE **c, int n, int m) { } } -void vector_subtract(FLOATTYPE *a, FLOATTYPE *b, FLOATTYPE *c, int n) { +void vector_subtract(FLOATTYPE *a, FLOATTYPE *b, FLOATTYPE *c, int n) +{ int i; for (i = 0; i < n; i++) c[i] = a[i] - b[i]; } -void vector_add(FLOATTYPE *a, FLOATTYPE *b, FLOATTYPE *c, FLOATTYPE fa, FLOATTYPE fb, int n) { +void vector_add(FLOATTYPE *a, FLOATTYPE *b, FLOATTYPE *c, FLOATTYPE fa, FLOATTYPE fb, int n) +{ int i; for (i = 0; i < n; i++) c[i] = fa * a[i] + fb * b[i]; } -void vector_multiply(FLOATTYPE **a, FLOATTYPE *b, FLOATTYPE *c, int n, int m) { +void vector_multiply(FLOATTYPE **a, FLOATTYPE *b, FLOATTYPE *c, int n, int m) +{ FLOATTYPE sum; int i, j; @@ -231,7 +251,8 @@ void vector_multiply(FLOATTYPE **a, FLOATTYPE *b, FLOATTYPE *c, int n, int m) { } } -void derivative_matrix(FLOATTYPE **D, int dy, int dx) { +void derivative_matrix(FLOATTYPE **D, int dy, int dx) +{ int i, j, n = dx * dy; for (i = 0; i < n; i++) @@ -242,14 +263,16 @@ void derivative_matrix(FLOATTYPE **D, int dy, int dx) { } } -void MGH_identity_matrix(FLOATTYPE **I, int n) { +void MGH_identity_matrix(FLOATTYPE **I, int n) +{ int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) I[i][j] = (i == j) ? 1.0 : 0.0; } -void regularization_matrix(FLOATTYPE **R, int n) { +void regularization_matrix(FLOATTYPE **R, int n) +{ int i, j; for (i = 0; i < n; i++) @@ -261,7 +284,8 @@ void regularization_matrix(FLOATTYPE **R, int n) { } } -void covariance_matrix(FLOATTYPE **R, int n) { +void covariance_matrix(FLOATTYPE **R, int n) +{ int i, j; for (i = 0; i < n; i++) @@ -271,7 +295,8 @@ void covariance_matrix(FLOATTYPE **R, int n) { } } -void mgh_ludcmp(FLOATTYPE **a, int n, int *indx, FLOATTYPE *d) { +void mgh_ludcmp(FLOATTYPE **a, int n, int *indx, FLOATTYPE *d) +{ int i, imax = 0, j, k; /* imax = 0 to shut up gcc */ FLOATTYPE big, dum, sum, temp; FLOATTYPE *vv, *vector(); @@ -320,7 +345,8 @@ void mgh_ludcmp(FLOATTYPE **a, int n, int *indx, FLOATTYPE *d) { free(vv); } -void mgh_lubksb(FLOATTYPE **a, int n, int *indx, FLOATTYPE *b) { +void mgh_lubksb(FLOATTYPE **a, int n, int *indx, FLOATTYPE *b) +{ int i, ii = -1, ip, j; FLOATTYPE sum; @@ -341,7 +367,8 @@ void mgh_lubksb(FLOATTYPE **a, int n, int *indx, FLOATTYPE *b) { } } -void inverse(FLOATTYPE **a, FLOATTYPE **y, int n) { +void inverse(FLOATTYPE **a, FLOATTYPE **y, int n) +{ FLOATTYPE d, *col; int i, j, *indx; @@ -356,7 +383,8 @@ void inverse(FLOATTYPE **a, FLOATTYPE **y, int n) { } } -FLOATTYPE determinant(FLOATTYPE **a, int n) { +FLOATTYPE determinant(FLOATTYPE **a, int n) +{ FLOATTYPE d; int j, *indx; @@ -367,7 +395,8 @@ FLOATTYPE determinant(FLOATTYPE **a, int n) { return d; } -FLOATTYPE MGH_svd(FLOATTYPE **A, FLOATTYPE **V, FLOATTYPE *z, int m, int n) { +FLOATTYPE MGH_svd(FLOATTYPE **A, FLOATTYPE **V, FLOATTYPE *z, int m, int n) +{ int i, j, k, count; FLOATTYPE c, s, p, q, r, v, toll = 0.1; @@ -386,7 +415,8 @@ FLOATTYPE MGH_svd(FLOATTYPE **A, FLOATTYPE **V, FLOATTYPE *z, int m, int n) { if (q < r) { c = 0; s = 1; - } else { + } + else { q = q - r; v = sqrt(4 * p * p + q * q); c = sqrt((v + q) / (2 * v)); @@ -434,7 +464,8 @@ static FLOATTYPE maxarg1, maxarg2; #define SIGN(a, b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) #endif -void mgh_svdcmp(FLOATTYPE **a, FLOATTYPE *w, FLOATTYPE **v, int m, int n) { +void mgh_svdcmp(FLOATTYPE **a, FLOATTYPE *w, FLOATTYPE **v, int m, int n) +{ int flag, i, its, j, jj, k, l = 0, nm = 0; /* Keep gcc happy */ FLOATTYPE c, f, h, s, x, y, z; FLOATTYPE anorm = 0.0, g = 0.0, scale = 0.0; @@ -524,7 +555,8 @@ void mgh_svdcmp(FLOATTYPE **a, FLOATTYPE *w, FLOATTYPE **v, int m, int n) { } } for (j = i; j < m; j++) a[j][i] *= g; - } else { + } + else { for (j = i; j < m; j++) a[j][i] = 0.0; } ++a[i][i]; diff --git a/utils/min_heap.c b/utils/min_heap.c index 397943ec287..97bc7f45bbd 100644 --- a/utils/min_heap.c +++ b/utils/min_heap.c @@ -13,7 +13,8 @@ static int Min_HeapifyDown(MIN_HEAP *MH, int index); static int Min_HeapifyUp(MIN_HEAP *MH, int index); MIN_HEAP -*Min_HeapAllocate(int max_size, int max_id_array_size) { +*Min_HeapAllocate(int max_size, int max_id_array_size) +{ MIN_HEAP *MH; int i; @@ -39,7 +40,8 @@ MIN_HEAP } for (i = 0; i < max_id_array_size; i++) MH->id_array[i] = -1; - } else { + } + else { fprintf(stderr, "Min_HeapAllocate: max_id_array_size is 0!!\n"); return (NULL); } @@ -48,7 +50,8 @@ MIN_HEAP return MH; } -static int Min_HeapExchangeElements(MIN_HEAP *MH, int i, int j) { +static int Min_HeapExchangeElements(MIN_HEAP *MH, int i, int j) +{ double tempHeapKey; int tempID = 0; void *tempData; @@ -66,12 +69,14 @@ static int Min_HeapExchangeElements(MIN_HEAP *MH, int i, int j) { if (i == j) { fprintf(stderr, "Min_HeapExchangeElements: The indices %d and %d are the same!!\n", i, j); return (ERROR); - } else if (i < j) { + } + else if (i < j) { if (j != 2 * i + 1 && j != 2 * i + 2) { fprintf(stderr, "Min_HeapExchangeElements: %d is not the child of %d!!\n", j, i); return (ERROR); } - } else { + } + else { if (i != 2 * j + 1 && i != 2 * j + 2) { fprintf(stderr, "Min_HeapExchangeElements: %d is not the child of %d!!\n", i, j); return (ERROR); @@ -101,7 +106,8 @@ static int Min_HeapExchangeElements(MIN_HEAP *MH, int i, int j) { return (NO_ERROR); } -int Min_HeapEditKeyIndexID(MIN_HEAP *MH, int id, double newKey) { +int Min_HeapEditKeyIndexID(MIN_HEAP *MH, int id, double newKey) +{ double tempKey; if (id < 0 || id >= MH->max_id_array_size) { @@ -119,24 +125,29 @@ int Min_HeapEditKeyIndexID(MIN_HEAP *MH, int id, double newKey) { if (tempKey > newKey) { Min_HeapifyUp(MH, MH->id_array[id]); - } else if (tempKey < newKey) { + } + else if (tempKey < newKey) { Min_HeapifyDown(MH, MH->id_array[id]); - } else { + } + else { // key same as before, nothing to do } return (NO_ERROR); } -int Min_HeapQueryKeyIndexID(MIN_HEAP *MH, int id, double *key) { +int Min_HeapQueryKeyIndexID(MIN_HEAP *MH, int id, double *key) +{ if (Min_HeapIdIsInHeap(MH, id)) { *key = MH->MHE_array[MH->id_array[id]].HeapKey; return (NO_ERROR); - } else { + } + else { return (-1); } } -int Min_HeapExtract(MIN_HEAP *MH, double *key, void **data, int *id) { +int Min_HeapExtract(MIN_HEAP *MH, double *key, void **data, int *id) +{ if (MH->CurrHeapSize == 0) { fprintf(stderr, "Min_HeapExtract: There's no element to be extracted!!\n"); return (ERROR); @@ -162,7 +173,8 @@ int Min_HeapExtract(MIN_HEAP *MH, double *key, void **data, int *id) { } // Min_HeapifyDown assumes index might be bigger than its children but everyone above it is ok -static int Min_HeapifyDown(MIN_HEAP *MH, int index) { +static int Min_HeapifyDown(MIN_HEAP *MH, int index) +{ int left, right, smallest, curr_index; if (index < 0 || index >= MH->CurrHeapSize) { @@ -183,7 +195,8 @@ static int Min_HeapifyDown(MIN_HEAP *MH, int index) { smallest = curr_index; if (right < MH->CurrHeapSize && MH->MHE_array[right].HeapKey < MH->MHE_array[smallest].HeapKey) smallest = right; - } else { + } + else { smallest = curr_index; } @@ -199,7 +212,8 @@ static int Min_HeapifyDown(MIN_HEAP *MH, int index) { } // Min_HeapifyUp assumes index's parent might be bigger than it, but everyone belong it is ok. -static int Min_HeapifyUp(MIN_HEAP *MH, int index) { +static int Min_HeapifyUp(MIN_HEAP *MH, int index) +{ int parent, curr_index; if (index < 0 || index >= MH->CurrHeapSize) { @@ -217,7 +231,8 @@ static int Min_HeapifyUp(MIN_HEAP *MH, int index) { if (MH->MHE_array[parent].HeapKey > MH->MHE_array[curr_index].HeapKey) { Min_HeapExchangeElements(MH, parent, curr_index); curr_index = parent; - } else { + } + else { break; } } @@ -225,7 +240,8 @@ static int Min_HeapifyUp(MIN_HEAP *MH, int index) { return (NO_ERROR); } -int Min_HeapIdIsInHeap(MIN_HEAP *MH, int id) { +int Min_HeapIdIsInHeap(MIN_HEAP *MH, int id) +{ if (id < 0 || id >= MH->max_id_array_size) return (NOT_IN_HEAP); if (MH->id_array[id] < 0) @@ -234,7 +250,8 @@ int Min_HeapIdIsInHeap(MIN_HEAP *MH, int id) { return (IS_IN_HEAP); } -int Min_HeapInsert(MIN_HEAP *MH, double key, void *data, int id) { +int Min_HeapInsert(MIN_HEAP *MH, double key, void *data, int id) +{ if (id < 0 || id >= MH->max_id_array_size) { fprintf(stderr, "Min_HeapInsert: ID %d is out of range. id_array size is %d\n", id, MH->max_id_array_size); return (ERROR); @@ -250,7 +267,8 @@ int Min_HeapInsert(MIN_HEAP *MH, double key, void *data, int id) { stderr, "Min_HeapInsert: Heap runs out of space. Current version doesn't allocate more space when heap is full!!\n"); return (ERROR); - } else { + } + else { MH->MHE_array[MH->CurrHeapSize].HeapKey = key; MH->MHE_array[MH->CurrHeapSize].Data = data; MH->MHE_array[MH->CurrHeapSize].id = id; @@ -263,14 +281,16 @@ int Min_HeapInsert(MIN_HEAP *MH, double key, void *data, int id) { return (NO_ERROR); } -int Min_HeapFree(MIN_HEAP *MH) { +int Min_HeapFree(MIN_HEAP *MH) +{ free(MH->MHE_array); if (MH->id_array) free(MH->id_array); free(MH); return (NO_ERROR); } -void Min_HeapInternalCheck(MIN_HEAP *MH, int PrintContent) { +void Min_HeapInternalCheck(MIN_HEAP *MH, int PrintContent) +{ int i, total = 0; int child1, child2; diff --git a/utils/mincutils.c b/utils/mincutils.c index 2f59ffce197..ca02cad52c5 100644 --- a/utils/mincutils.c +++ b/utils/mincutils.c @@ -32,7 +32,8 @@ #include "mri.h" /*-----------------------------------------------------*/ -int DumpMINCAxes(FILE *fp, MINCAXES *MA) { +int DumpMINCAxes(FILE *fp, MINCAXES *MA) +{ int i; fprintf(fp, @@ -57,7 +58,8 @@ int DumpMINCAxes(FILE *fp, MINCAXES *MA) { } /*-----------------------------------------------------*/ -MINCAXES *ConfigMINCAxes(MRI *mri) { +MINCAXES *ConfigMINCAxes(MRI *mri) +{ MINCAXES *MA; int va; @@ -107,7 +109,8 @@ MINCAXES *ConfigMINCAxes(MRI *mri) { } /*-----------------------------------------------------*/ -int NameMINCAxes(MINCAXES *MA) { +int NameMINCAxes(MINCAXES *MA) +{ int xspacehit, yspacehit, zspacehit; int xspaceid, yspaceid, zspaceid; char *space[3]; @@ -142,11 +145,13 @@ int NameMINCAxes(MINCAXES *MA) { colspaceid = xspaceid; MA->VolCenterVox[0] = (MA->Axis[0].Len - 1) / 2; xspacehit = 1; - } else if (col_dc_y >= row_dc_y && col_dc_y >= slc_dc_y) { + } + else if (col_dc_y >= row_dc_y && col_dc_y >= slc_dc_y) { colspaceid = yspaceid; MA->VolCenterVox[1] = (MA->Axis[0].Len - 1) / 2; yspacehit = 1; - } else if (col_dc_z >= row_dc_z && col_dc_z >= slc_dc_z) { + } + else if (col_dc_z >= row_dc_z && col_dc_z >= slc_dc_z) { colspaceid = zspaceid; MA->VolCenterVox[2] = (MA->Axis[0].Len - 1) / 2; zspacehit = 1; @@ -157,11 +162,13 @@ int NameMINCAxes(MINCAXES *MA) { rowspaceid = xspaceid; MA->VolCenterVox[0] = (MA->Axis[1].Len - 1) / 2; xspacehit = 1; - } else if (!yspacehit && row_dc_y >= slc_dc_y) { + } + else if (!yspacehit && row_dc_y >= slc_dc_y) { rowspaceid = yspaceid; MA->VolCenterVox[1] = (MA->Axis[1].Len - 1) / 2; yspacehit = 1; - } else if (!zspacehit && row_dc_z >= slc_dc_z) { + } + else if (!zspacehit && row_dc_z >= slc_dc_z) { rowspaceid = zspaceid; MA->VolCenterVox[2] = (MA->Axis[1].Len - 1) / 2; zspacehit = 1; @@ -172,7 +179,8 @@ int NameMINCAxes(MINCAXES *MA) { slcspaceid = xspaceid; MA->VolCenterVox[0] = (MA->Axis[2].Len - 1) / 2; xspacehit = 1; - } else if (!yspacehit) { + } + else if (!yspacehit) { slcspaceid = yspaceid; MA->VolCenterVox[1] = (MA->Axis[2].Len - 1) / 2; yspacehit = 1; @@ -215,7 +223,8 @@ int NameMINCAxes(MINCAXES *MA) { return (0); } /*-----------------------------------------------------*/ -int MINCAxesStorageOrder(MINCAXES *MA) { +int MINCAxesStorageOrder(MINCAXES *MA) +{ int ncols, nrows, nslcs; int col, row, slc; @@ -232,25 +241,30 @@ int MINCAxesStorageOrder(MINCAXES *MA) { if (nrows >= nslcs) { MA->VoxAxisStorageOrder[1] = row; MA->VoxAxisStorageOrder[2] = slc; - } else { + } + else { MA->VoxAxisStorageOrder[1] = slc; MA->VoxAxisStorageOrder[2] = row; } - } else if (nrows >= nslcs) { + } + else if (nrows >= nslcs) { MA->VoxAxisStorageOrder[0] = row; if (ncols >= nslcs) { MA->VoxAxisStorageOrder[1] = col; MA->VoxAxisStorageOrder[2] = slc; - } else { + } + else { MA->VoxAxisStorageOrder[1] = slc; MA->VoxAxisStorageOrder[2] = col; } - } else { + } + else { MA->VoxAxisStorageOrder[0] = slc; if (ncols >= nrows) { MA->VoxAxisStorageOrder[1] = col; MA->VoxAxisStorageOrder[2] = row; - } else { + } + else { MA->VoxAxisStorageOrder[1] = row; MA->VoxAxisStorageOrder[2] = col; } diff --git a/utils/minmaxrc.c b/utils/minmaxrc.c index 28f5751021f..208a75e9108 100644 --- a/utils/minmaxrc.c +++ b/utils/minmaxrc.c @@ -38,7 +38,8 @@ #include "minmaxrc.h" /************************************************************/ -int h_minmaxrc(struct header *phdSrc, Pixelval *Min, int MinPoint[2], Pixelval *Max, int MaxPoint[2]) { +int h_minmaxrc(struct header *phdSrc, Pixelval *Min, int MinPoint[2], Pixelval *Max, int MaxPoint[2]) +{ switch (phdSrc->pixel_format) { case PFBYTE: return (h_minmaxrc_b(phdSrc, (byte *)Min, MinPoint, (byte *)Max, MaxPoint)); @@ -54,7 +55,8 @@ int h_minmaxrc(struct header *phdSrc, Pixelval *Min, int MinPoint[2], Pixelval * } /************************************************************/ -int h_minmaxrc_b(struct header *phdSrc, byte *Min, int MinPoint[2], byte *Max, int MaxPoint[2]) { +int h_minmaxrc_b(struct header *phdSrc, byte *Min, int MinPoint[2], byte *Max, int MaxPoint[2]) +{ register int r, c; register byte x, *p; @@ -74,7 +76,8 @@ int h_minmaxrc_b(struct header *phdSrc, byte *Min, int MinPoint[2], byte *Max, i *Max = x; MaxPoint[0] = r; MaxPoint[1] = c; - } else if (x < *Min) { + } + else if (x < *Min) { *Min = x; MinPoint[0] = r; MinPoint[1] = c; @@ -84,7 +87,8 @@ int h_minmaxrc_b(struct header *phdSrc, byte *Min, int MinPoint[2], byte *Max, i return (HIPS_OK); } /************************************************************/ -int h_minmaxrc_s(struct header *phdSrc, short *Min, int MinPoint[2], short *Max, int MaxPoint[2]) { +int h_minmaxrc_s(struct header *phdSrc, short *Min, int MinPoint[2], short *Max, int MaxPoint[2]) +{ register int r, c; register short x, *p; @@ -104,7 +108,8 @@ int h_minmaxrc_s(struct header *phdSrc, short *Min, int MinPoint[2], short *Max, *Max = x; MaxPoint[0] = r; MaxPoint[1] = c; - } else if (x < *Min) { + } + else if (x < *Min) { *Min = x; MinPoint[0] = r; MinPoint[1] = c; @@ -114,7 +119,8 @@ int h_minmaxrc_s(struct header *phdSrc, short *Min, int MinPoint[2], short *Max, return (HIPS_OK); } /************************************************************/ -int h_minmaxrc_i(struct header *phdSrc, int *Min, int MinPoint[2], int *Max, int MaxPoint[2]) { +int h_minmaxrc_i(struct header *phdSrc, int *Min, int MinPoint[2], int *Max, int MaxPoint[2]) +{ register int r, c; register int x, *p; @@ -134,7 +140,8 @@ int h_minmaxrc_i(struct header *phdSrc, int *Min, int MinPoint[2], int *Max, int *Max = x; MaxPoint[0] = r; MaxPoint[1] = c; - } else if (x < *Min) { + } + else if (x < *Min) { *Min = x; MinPoint[0] = r; MinPoint[1] = c; @@ -144,7 +151,8 @@ int h_minmaxrc_i(struct header *phdSrc, int *Min, int MinPoint[2], int *Max, int return (HIPS_OK); } /************************************************************/ -int h_minmaxrc_f(struct header *phdSrc, float *Min, int MinPoint[2], float *Max, int MaxPoint[2]) { +int h_minmaxrc_f(struct header *phdSrc, float *Min, int MinPoint[2], float *Max, int MaxPoint[2]) +{ register int r, c; register float x, *p; @@ -164,7 +172,8 @@ int h_minmaxrc_f(struct header *phdSrc, float *Min, int MinPoint[2], float *Max, *Max = x; MaxPoint[0] = r; MaxPoint[1] = c; - } else if (x < *Min) { + } + else if (x < *Min) { *Min = x; MinPoint[0] = r; MinPoint[1] = c; diff --git a/utils/morph.c b/utils/morph.c index e62011f3817..bc4e23ca907 100644 --- a/utils/morph.c +++ b/utils/morph.c @@ -654,7 +654,8 @@ static unsigned char *lut_pointers[] = { Description ------------------------------------------------------*/ static unsigned char thicken_se[9] = {255, 1, 255, 1, 1, 1, 255, 1, 255}; -IMAGE *ImageDilate(IMAGE *Isrc, IMAGE *Idst, int which) { +IMAGE *ImageDilate(IMAGE *Isrc, IMAGE *Idst, int which) +{ // int ecode, int center_row, center_col; IMAGE Ise, *Iin, *Itmp, *Iout; @@ -668,7 +669,8 @@ IMAGE *ImageDilate(IMAGE *Isrc, IMAGE *Idst, int which) { Iin = ImageAlloc(Isrc->rows, Isrc->cols, PFBYTE, Isrc->num_frame); ImageCopy(Itmp, Iin); ImageFree(&Itmp); - } else + } + else Iin = Isrc; if (Idst->pixel_format != PFBYTE) @@ -714,7 +716,8 @@ IMAGE *ImageDilate(IMAGE *Isrc, IMAGE *Idst, int which) { Description ------------------------------------------------------*/ -IMAGE *ImageErode(IMAGE *Isrc, IMAGE *Idst, int which) { +IMAGE *ImageErode(IMAGE *Isrc, IMAGE *Idst, int which) +{ // int i = which; /* prevents warning */ // IMAGE *tmp; // tmp = Isrc; /* prevents warning */ @@ -728,7 +731,8 @@ IMAGE *ImageErode(IMAGE *Isrc, IMAGE *Idst, int which) { Description ------------------------------------------------------*/ -IMAGE *ImageMorph(IMAGE *Isrc, IMAGE *Idst, int which) { +IMAGE *ImageMorph(IMAGE *Isrc, IMAGE *Idst, int which) +{ IMAGE *Iin, *Itmp, *Iout, *Ifiltered; unsigned char *lut; @@ -743,7 +747,8 @@ IMAGE *ImageMorph(IMAGE *Isrc, IMAGE *Idst, int which) { Iin = ImageAlloc(Isrc->rows, Isrc->cols, PFBYTE, Isrc->num_frame); ImageCopy(Itmp, Iin); ImageFree(&Itmp); - } else { + } + else { Iin = Isrc; ImageScale(Isrc, Isrc, MORPH_BACKGROUND, MORPH_FOREGROUND); } @@ -778,7 +783,8 @@ IMAGE *ImageMorph(IMAGE *Isrc, IMAGE *Idst, int which) { Description ------------------------------------------------------*/ -IMAGE *ImageClose(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageClose(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Itmp, *Iin, *Iout; if (!Idst) Idst = ImageAlloc(Isrc->rows, Isrc->cols, PFBYTE, Isrc->num_frame); @@ -788,7 +794,8 @@ IMAGE *ImageClose(IMAGE *Isrc, IMAGE *Idst) { Iin = ImageAlloc(Isrc->rows, Isrc->cols, PFBYTE, Isrc->num_frame); ImageCopy(Itmp, Iin); ImageFree(&Itmp); - } else /* image already in byte format */ + } + else /* image already in byte format */ { Iin = Isrc; ImageScale(Isrc, Isrc, MORPH_BACKGROUND, MORPH_FOREGROUND); @@ -820,7 +827,8 @@ IMAGE *ImageClose(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ -IMAGE *ImageOpen(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageOpen(IMAGE *Isrc, IMAGE *Idst) +{ IMAGE *Itmp, *Iin, *Iout; if (!Idst) Idst = ImageAlloc(Isrc->rows, Isrc->cols, PFBYTE, Isrc->num_frame); @@ -830,7 +838,8 @@ IMAGE *ImageOpen(IMAGE *Isrc, IMAGE *Idst) { Iin = ImageAlloc(Isrc->rows, Isrc->cols, PFBYTE, Isrc->num_frame); ImageCopy(Itmp, Iin); ImageFree(&Itmp); - } else /* image already in byte format */ + } + else /* image already in byte format */ { Iin = Isrc; ImageScale(Isrc, Isrc, MORPH_BACKGROUND, MORPH_FOREGROUND); @@ -863,7 +872,8 @@ IMAGE *ImageOpen(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ static int filter[3][3] = {{1, 8, 64}, {2, 16, 128}, {4, 32, 256}}; -static void morphFilter(IMAGE *Isrc, IMAGE *Idst) { +static void morphFilter(IMAGE *Isrc, IMAGE *Idst) +{ register unsigned char *spix; int rows, cols, row, col, row_start, row_end, col_start, col_end, *dpix; // int row_pix; @@ -906,7 +916,8 @@ static void morphFilter(IMAGE *Isrc, IMAGE *Idst) { Description ------------------------------------------------------*/ -static void morphApplyLut(IMAGE *Isrc, IMAGE *Idst, unsigned char *lut) { +static void morphApplyLut(IMAGE *Isrc, IMAGE *Idst, unsigned char *lut) +{ int row, col, rows, cols, *spix; register unsigned char *dpix; //, *endpix; diff --git a/utils/mosaic.c b/utils/mosaic.c index 8429dfd9bc9..1817bf15c9a 100644 --- a/utils/mosaic.c +++ b/utils/mosaic.c @@ -82,7 +82,8 @@ in the image --------------------------------------------------------*/ int VolSS2MosSS( - int cvol, int rvol, int svol, int ncvol, int nrvol, int ncmos, int nrmos, int *cmos, int *rmos, int *OutOfBounds) { + int cvol, int rvol, int svol, int ncvol, int nrvol, int ncmos, int nrmos, int *cmos, int *rmos, int *OutOfBounds) +{ int nctmos; // int nrtmos; int ctmos, rtmos; @@ -147,7 +148,8 @@ int MosSS2VolSS(int cmos, int *cvol, int *rvol, int *svol, - int *OutOfBounds) { + int *OutOfBounds) +{ int nctmos; // int nrtmos; int ctmos, rtmos; @@ -212,7 +214,8 @@ int MosSS2VolSS(int cmos, CheckMosaic(void) - this is just a diagnostic that prints info to stdout. ----------------------------------------------------------*/ -int CheckMosaic(void) { +int CheckMosaic(void) +{ int cvol, rvol, svol, ncvol, nrvol, nsvol; int ncmos, nrmos, cmos, rmos; int cvol2, rvol2, svol2; diff --git a/utils/mri.c b/utils/mri.c index bb2cffbdf38..70ce1311ecf 100644 --- a/utils/mri.c +++ b/utils/mri.c @@ -162,7 +162,8 @@ static long mris_alloced = 0; Note: MRIgetVoxelToRasXform is #defined to be extract_i_to_r(). ----------------------------------------------------------------*/ -MATRIX *MRIxfmCRS2XYZ(const MRI *mri, int base) { +MATRIX *MRIxfmCRS2XYZ(const MRI *mri, int base) +{ MATRIX *m; MATRIX *Pcrs, *PxyzOffset; @@ -226,7 +227,8 @@ MATRIX *MRIxfmCRS2XYZ(const MRI *mri, int base) { \fn MATRIX *MRImatrixOfDirectionCosines(MRI *mri, MATRIX *Mdc) \brief Fills Mdc with direction cosines */ -MATRIX *MRImatrixOfDirectionCosines(MRI *mri, MATRIX *Mdc) { +MATRIX *MRImatrixOfDirectionCosines(MRI *mri, MATRIX *Mdc) +{ if (Mdc == NULL) Mdc = MatrixZero(4, 4, NULL); Mdc->rptr[1][1] = mri->x_r; Mdc->rptr[2][1] = mri->x_a; @@ -244,7 +246,8 @@ MATRIX *MRImatrixOfDirectionCosines(MRI *mri, MATRIX *Mdc) { \fn MATRIX *MRImatrixOfVoxelSizes(MRI *mri, MATRIX *D) \brief Creaetes diagonal matrix D with voxel sizes on diagonal */ -MATRIX *MRImatrixOfVoxelSizes(MRI *mri, MATRIX *D) { +MATRIX *MRImatrixOfVoxelSizes(MRI *mri, MATRIX *D) +{ if (D == NULL) D = MatrixZero(4, 4, NULL); D->rptr[1][1] = mri->xsize; D->rptr[2][2] = mri->ysize; @@ -256,7 +259,8 @@ MATRIX *MRImatrixOfVoxelSizes(MRI *mri, MATRIX *D) { \fn MATRIX *MRImatrixOfTranslations(MRI *mri, MATRIX *P0) \brief Creates 4x4 matrix which implements the translation */ -MATRIX *MRImatrixOfTranslations(MRI *mri, MATRIX *P0) { +MATRIX *MRImatrixOfTranslations(MRI *mri, MATRIX *P0) +{ MATRIX *Vox2ScannerRAS; int k; if (P0 == NULL) P0 = MatrixZero(4, 4, NULL); @@ -275,7 +279,8 @@ MATRIX *MRImatrixOfTranslations(MRI *mri, MATRIX *P0) { non-zero voxels base correctly (eg, SPM expects vox2ras to be 1-based). Note: MRIgetVoxelToRasXform is #defined to be extract_i_to_r(). ---------------------------------------------------------------------------*/ -MATRIX *extract_i_to_r(const MRI *mri) { +MATRIX *extract_i_to_r(const MRI *mri) +{ MATRIX *m; m = MRIxfmCRS2XYZ(mri, 0); return (m); @@ -284,7 +289,8 @@ MATRIX *extract_i_to_r(const MRI *mri) { extract_r_to_i() - computes scanner ras2vox. See also extract_i_to_r() and MRIxfmCRS2XYZ() ---------------------------------------------------------------------*/ -MATRIX *extract_r_to_i(const MRI *mri) { +MATRIX *extract_r_to_i(const MRI *mri) +{ MATRIX *m_ras_to_voxel, *m_voxel_to_ras; m_voxel_to_ras = extract_i_to_r(mri); m_ras_to_voxel = MatrixInverse(m_voxel_to_ras, NULL); @@ -301,7 +307,8 @@ MATRIX *extract_r_to_i(const MRI *mri) { MRIsetVox2RASFromMatrixUnitTest(). See also niftiSformToMri() int mriio.c. */ -int MRIsetVox2RASFromMatrix(MRI *mri, MATRIX *m_vox2ras) { +int MRIsetVox2RASFromMatrix(MRI *mri, MATRIX *m_vox2ras) +{ double rx, ax, sx, ry, ay, sy, rz, az, sz; double P0r, P0a, P0s; double xsize, ysize, zsize; @@ -349,7 +356,8 @@ int MRIsetVox2RASFromMatrix(MRI *mri, MATRIX *m_vox2ras) { \brief Unit test for MRIsetVox2RASFromMatrix(). Note the geometry params of the mri struct might be changed. */ -int MRIsetVox2RASFromMatrixUnitTest(MRI *mri) { +int MRIsetVox2RASFromMatrixUnitTest(MRI *mri) +{ MATRIX *Vox2RAS, *Vox2RASb; int c, r; double err; @@ -387,7 +395,8 @@ int MRIsetVox2RASFromMatrixUnitTest(MRI *mri) { arbitrary, they must be applied consistently. See also: surfaceRASFromVoxel_ and voxelFromSurfaceRAS_. -------------------------------------------------------------*/ -MATRIX *MRIxfmCRS2XYZtkreg(const MRI *mri) { +MATRIX *MRIxfmCRS2XYZtkreg(const MRI *mri) +{ MRI *tmp; MATRIX *K; @@ -424,7 +433,8 @@ MATRIX *MRIxfmCRS2XYZtkreg(const MRI *mri) { transform between the column, row, and slice of a voxel and the x, y, z of that voxel as expected by FSL/FLIRT. -------------------------------------------------------------*/ -MATRIX *MRIxfmCRS2XYZfsl(MRI *mri) { +MATRIX *MRIxfmCRS2XYZfsl(MRI *mri) +{ MATRIX *vox2ras; vox2ras = MatrixAlloc(4, 4, MATRIX_REAL); vox2ras->rptr[1][1] = mri->xsize; @@ -444,7 +454,8 @@ MATRIX *MRIxfmCRS2XYZfsl(MRI *mri) { See also: MRItkRegMtx, MRIxfmCRS2XYZtkreg, MRIxfmCRS2XYZ -------------------------------------------------------------------*/ -MATRIX *MRItkReg2Native(MRI *ref, MRI *mov, MATRIX *R) { +MATRIX *MRItkReg2Native(MRI *ref, MRI *mov, MATRIX *R) +{ MATRIX *Kref, *Kmov; MATRIX *Tref, *Tmov, *D; MATRIX *invKmov, *invTref; @@ -500,7 +511,8 @@ MATRIX *MRItkReg2Native(MRI *ref, MRI *mov, MATRIX *R) { the identity. This function could have been called MRInative2TkReg(). ---------------------------------------------------------------*/ -MATRIX *MRItkRegMtx(MRI *ref, MRI *mov, MATRIX *D) { +MATRIX *MRItkRegMtx(MRI *ref, MRI *mov, MATRIX *D) +{ MATRIX *Kref, *Kmov; MATRIX *Tref, *Tmov, *R; MATRIX *invTmov, *invKref, *invD; @@ -543,7 +555,8 @@ MATRIX *MRItkRegMtx(MRI *ref, MRI *mov, MATRIX *D) { is assumed to be the identity (which will return the same thing as MRItkRegMtx()). See also MRIvoxToVoxFromTkRegMtx(). */ -MATRIX *MRItkRegMtxFromVox2Vox(MRI *ref, MRI *mov, MATRIX *vox2vox) { +MATRIX *MRItkRegMtxFromVox2Vox(MRI *ref, MRI *mov, MATRIX *vox2vox) +{ MATRIX *Kref, *Kmov; MATRIX *R, *invKref; @@ -572,7 +585,8 @@ MATRIX *MRItkRegMtxFromVox2Vox(MRI *ref, MRI *mov, MATRIX *vox2vox) { mov volume. If tkR is NULL, it is assumed to be the identity. See also MRItkRegMtxFromVox2Vox(). */ -MATRIX *MRIvoxToVoxFromTkRegMtx(MRI *mov, MRI *targ, MATRIX *tkR) { +MATRIX *MRIvoxToVoxFromTkRegMtx(MRI *mov, MRI *targ, MATRIX *tkR) +{ MATRIX *ras2vox_mov, *vox2ras_mov, *vox2ras_targ, *vox2vox; vox2ras_mov = MRIxfmCRS2XYZtkreg(mov); ras2vox_mov = MatrixInverse(vox2ras_mov, NULL); @@ -580,7 +594,8 @@ MATRIX *MRIvoxToVoxFromTkRegMtx(MRI *mov, MRI *targ, MATRIX *tkR) { if (tkR) { vox2vox = MatrixMultiply(ras2vox_mov, tkR, NULL); MatrixMultiply(vox2vox, vox2ras_targ, vox2vox); - } else + } + else vox2vox = MatrixMultiply(ras2vox_mov, vox2ras_targ, NULL); MatrixFree(&vox2ras_mov); MatrixFree(&ras2vox_mov); @@ -638,7 +653,8 @@ MATRIX *MRIvoxToVoxFromTkRegMtx(MRI *mov, MRI *targ, MATRIX *tkR) { type of matrix in the float2int variable. It will be either FLT2INT_TKREG or FLT2INT_ROUND (constants defined in resample.h). ---------------------------------------------------------------*/ -MATRIX *MRIfixTkReg(MRI *mov, MATRIX *R) { +MATRIX *MRIfixTkReg(MRI *mov, MATRIX *R) +{ int n, ntest = 1000; MATRIX *Pxyz, *Pcrs, *PcrsTkReg; MATRIX *PxyzT, *PxyzPxyzT, *invPxyzPxyzT; @@ -706,7 +722,8 @@ MATRIX *MRIfixTkReg(MRI *mov, MATRIX *R) { from the mov to the ref whereas the tkreg matrix maps from the ref to the mov. -------------------------------------------------------------------*/ -MATRIX *MRIfsl2TkReg(MRI *ref, MRI *mov, MATRIX *FSLRegMat) { +MATRIX *MRIfsl2TkReg(MRI *ref, MRI *mov, MATRIX *FSLRegMat) +{ MATRIX *RegMat = NULL, *invDmov, *Tmov, *Dref; MATRIX *invFSLRegMat, *invTref, *Tref; MATRIX *Qmov, *Qref; @@ -795,7 +812,8 @@ MATRIX *MRIfsl2TkReg(MRI *ref, MRI *mov, MATRIX *FSLRegMat) { mov to the ref whereas the tkreg matrix maps from the ref to the mov. -------------------------------------------------------------------*/ -MATRIX *MRItkreg2FSL(MRI *ref, MRI *mov, MATRIX *tkRegMat) { +MATRIX *MRItkreg2FSL(MRI *ref, MRI *mov, MATRIX *tkRegMat) +{ MATRIX *FSLRegMat = NULL, *Dmov, *Tmov, *invTmov, *Tref, *Dref, *invDref; MATRIX *Qmov, *Qref; char *FSLOUTPUTTYPE = NULL; @@ -894,7 +912,8 @@ MATRIX *MRItkreg2FSL(MRI *ref, MRI *mov, MATRIX *tkRegMat) { found in SPM matrices) to 0-based CRS, ie, CRS0 = Q*CRS1 (assuming that CRS1 has been packed with a 1 in the 4th component. --------------------------------------------------------------------------*/ -MATRIX *MtxCRS1toCRS0(MATRIX *Q) { +MATRIX *MtxCRS1toCRS0(MATRIX *Q) +{ int r, c; if (Q == NULL) @@ -924,7 +943,8 @@ MATRIX *MtxCRS1toCRS0(MATRIX *Q) { voxel (ie, col,row,slice=0). Typically, P0 is known from some source (eg, dicom header) and the c_{ras} needs to be computed. -----------------------------------------------------------------*/ -int MRIp0ToCRAS(MRI *mri, double r0, double a0, double s0) { +int MRIp0ToCRAS(MRI *mri, double r0, double a0, double s0) +{ MATRIX *vox2ras, *CRScenter, *RAScenter; // Get the vox2ras matrix. @@ -977,7 +997,8 @@ int MRIp0ToCRAS(MRI *mri, double r0, double a0, double s0) { with the bore) instead of head-first-supine (HFS). This is often the case with monkeys. ---------------------------------------------------------------*/ -int MRIhfs2Sphinx(MRI *mri) { +int MRIhfs2Sphinx(MRI *mri) +{ double tmpxa, tmpya, tmpza, tmpca; // Negate right to make it left @@ -1009,7 +1030,8 @@ int MRIhfs2Sphinx(MRI *mri) { \fn size_t MRIsizeof(int mritype) \brief Returns the sizeof() the MRI data type */ -size_t MRIsizeof(int mritype) { +size_t MRIsizeof(int mritype) +{ switch (mritype) { case MRI_UCHAR: return (sizeof(char)); @@ -1041,7 +1063,8 @@ size_t MRIsizeof(int mritype) { to the pixel data (instead of an MRI struct), which makes it several times faster but less general. */ -inline double MRIptr2dbl(void *pmric, int mritype) { +inline double MRIptr2dbl(void *pmric, int mritype) +{ double v = 0; switch (mritype) { case MRI_UCHAR: @@ -1073,7 +1096,8 @@ inline double MRIptr2dbl(void *pmric, int mritype) { to the pixel data (instead of an MRI struct), which makes it several times faster but less general. */ -inline void MRIdbl2ptr(double v, void *pmric, int mritype) { +inline void MRIdbl2ptr(double v, void *pmric, int mritype) +{ switch (mritype) { case MRI_UCHAR: *((char *)pmric) = nint(v); @@ -1104,7 +1128,8 @@ inline void MRIdbl2ptr(double v, void *pmric, int mritype) { \param int f - frame \return float intensity x derivative at the given col, row, slice, frame */ -float MRIgetVoxDx(MRI *mri, int c, int r, int s, int f) { +float MRIgetVoxDx(MRI *mri, int c, int r, int s, int f) +{ float Ip1, Im1; Ip1 = MRIgetVoxVal(mri, c + 1, r, s, f); @@ -1123,7 +1148,8 @@ float MRIgetVoxDx(MRI *mri, int c, int r, int s, int f) { \return float intensity y derivative at the given col, row, slice, frame This function is general but slow. See also MRIptr2dbl(). */ -float MRIgetVoxDy(MRI *mri, int c, int r, int s, int f) { +float MRIgetVoxDy(MRI *mri, int c, int r, int s, int f) +{ float Ip1, Im1; Ip1 = MRIgetVoxVal(mri, c, r + 1, s, f); @@ -1141,7 +1167,8 @@ float MRIgetVoxDy(MRI *mri, int c, int r, int s, int f) { \param int f - frame \return float intensity z derivative at the given col, row, slice, frame */ -float MRIgetVoxDz(MRI *mri, int c, int r, int s, int f) { +float MRIgetVoxDz(MRI *mri, int c, int r, int s, int f) +{ float Ip1, Im1; Ip1 = MRIgetVoxVal(mri, c, r, s + 1, f); @@ -1160,7 +1187,8 @@ float MRIgetVoxDz(MRI *mri, int c, int r, int s, int f) { \return float value at the given col, row, slice, frame This function is general but slow. See also MRIptr2dbl(). */ -inline float MRIgetVoxVal(const MRI *mri, int c, int r, int s, int f) { +inline float MRIgetVoxVal(const MRI *mri, int c, int r, int s, int f) +{ // bounds checks: if (c < 0) return mri->outside_val; if (r < 0) return mri->outside_val; @@ -1220,7 +1248,8 @@ inline float MRIgetVoxVal(const MRI *mri, int c, int r, int s, int f) { \return int - 0 if ok, 1 if mri->type is unrecognized. This function is general but slow. See also MRIdbl2ptr(). */ -inline int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval) { +inline int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval) +{ // clipping switch (mri->type) { case MRI_UCHAR: @@ -1291,7 +1320,8 @@ inline int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval) { MRIinterpCode() - returns the numeric interpolation code given the name of the interpolation method. -----------------------------------------------------------------*/ -int MRIinterpCode(char *InterpString) { +int MRIinterpCode(char *InterpString) +{ if (!strncasecmp(InterpString, "nearest", 3)) return (SAMPLE_NEAREST); if (!strncasecmp(InterpString, "trilinear", 3)) return (SAMPLE_TRILINEAR); if (!strncasecmp(InterpString, "tli", 3)) return (SAMPLE_TRILINEAR); @@ -1305,7 +1335,8 @@ int MRIinterpCode(char *InterpString) { MRIinterpString() - returns the the name of the interpolation method given numeric interpolation code -----------------------------------------------------------------*/ -char *MRIinterpString(int InterpCode) { +char *MRIinterpString(int InterpCode) +{ switch (InterpCode) { case SAMPLE_NEAREST: return ("nearest"); @@ -1327,7 +1358,8 @@ char *MRIinterpString(int InterpCode) { name of the precision. This corresponds to the value of the type field in the MRI structure. -----------------------------------------------------------------*/ -int MRIprecisionCode(char *PrecisionString) { +int MRIprecisionCode(char *PrecisionString) +{ if (!strcasecmp(PrecisionString, "uchar")) return (MRI_UCHAR); if (!strcasecmp(PrecisionString, "short")) return (MRI_SHORT); if (!strcasecmp(PrecisionString, "int")) return (MRI_INT); @@ -1342,7 +1374,8 @@ int MRIprecisionCode(char *PrecisionString) { numeric precision code. The code corresponds to the value of the type field in the MRI structure. -----------------------------------------------------------------*/ -char *MRIprecisionString(int PrecisionCode) { +char *MRIprecisionString(int PrecisionCode) +{ switch (PrecisionCode) { case MRI_UCHAR: return ("uchar"); @@ -1365,18 +1398,21 @@ char *MRIprecisionString(int PrecisionCode) { /*----------------------------------------------------- ------------------------------------------------------*/ -int MRImatch(MRI *mri1, MRI *mri2) { +int MRImatch(MRI *mri1, MRI *mri2) +{ return ((mri1->width == mri2->width) && (mri1->height == mri2->height) && (mri1->depth == mri2->depth) && (mri1->type == mri2->type)); } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRImatchDimensions(MRI *mri1, MRI *mri2) { +int MRImatchDimensions(MRI *mri1, MRI *mri2) +{ return ((mri1->width == mri2->width) && (mri1->height == mri2->height) && (mri1->depth == mri2->depth) && (FEQUAL(mri1->xsize, mri2->xsize)) && (FEQUAL(mri1->ysize, mri2->ysize)) && (FEQUAL(mri1->zsize, mri2->zsize))); } -MRI *MRIlinearScale(MRI *mri_src, MRI *mri_dst, float scale, float offset, int only_nonzero) { +MRI *MRIlinearScale(MRI *mri_src, MRI *mri_dst, float scale, float offset, int only_nonzero) +{ int width, height, depth, x, y, z, frame; float val; @@ -1405,7 +1441,8 @@ MRI *MRIlinearScale(MRI *mri_src, MRI *mri_dst, float scale, float offset, int o } return (mri_dst); } -double MRIrmsDifferenceNonzero(MRI *mri1, MRI *mri2) { +double MRIrmsDifferenceNonzero(MRI *mri1, MRI *mri2) +{ int width, height, depth, x, y, z, frame, nvox; float val1, val2; double sse; @@ -1433,7 +1470,8 @@ double MRIrmsDifferenceNonzero(MRI *mri1, MRI *mri2) { } /*----------------------------------------------------- ------------------------------------------------------*/ -MRI *MRIscalarMul(MRI *mri_src, MRI *mri_dst, float scalar) { +MRI *MRIscalarMul(MRI *mri_src, MRI *mri_dst, float scalar) +{ int width, height, depth, x, y, z, frame; BUFTYPE *psrc, *pdst; float *pfsrc, *pfdst, dval; @@ -1452,7 +1490,8 @@ MRI *MRIscalarMul(MRI *mri_src, MRI *mri_dst, float scalar) { dval = MRIgetVoxVal(mri_src, x, y, z, frame); MRIsetVoxVal(mri_dst, x, y, z, frame, dval * scalar); } - } else + } + else switch (mri_src->type) { case MRI_UCHAR: psrc = &MRIseq_vox(mri_src, 0, y, z, frame); @@ -1484,7 +1523,8 @@ MRI *MRIscalarMul(MRI *mri_src, MRI *mri_dst, float scalar) { } /*----------------------------------------------------- ------------------------------------------------------*/ -MRI *MRIscalarMulFrame(MRI *mri_src, MRI *mri_dst, float scalar, int frame) { +MRI *MRIscalarMulFrame(MRI *mri_src, MRI *mri_dst, float scalar, int frame) +{ int width, height, depth, x, y, z; BUFTYPE *psrc, *pdst; float *pfsrc, *pfdst, dval; @@ -1525,7 +1565,8 @@ MRI *MRIscalarMulFrame(MRI *mri_src, MRI *mri_dst, float scalar, int frame) { } return (mri_dst); } -int MRIlabelValRange(MRI *mri, MRI *mri_labeled, int label, float *pmin, float *pmax) { +int MRIlabelValRange(MRI *mri, MRI *mri_labeled, int label, float *pmin, float *pmax) +{ int width, height, depth, x, y, z, frame, l, first = 1; float fmin, fmax, val; @@ -1558,7 +1599,8 @@ int MRIlabelValRange(MRI *mri, MRI *mri_labeled, int label, float *pmin, float * } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIvalRange(MRI *mri, float *pmin, float *pmax) { +int MRIvalRange(MRI *mri, float *pmin, float *pmax) +{ int width, height, depth, x, y, z, frame; float fmin, fmax, *pf, val; BUFTYPE *pb; @@ -1643,7 +1685,8 @@ int MRIvalRange(MRI *mri, float *pmin, float *pmax) { *pmax = fmax; return (NO_ERROR); } -int MRInonzeroValRange(MRI *mri, float *pmin, float *pmax) { +int MRInonzeroValRange(MRI *mri, float *pmin, float *pmax) +{ int width, height, depth, x, y, z, frame; float fmin, fmax, val; @@ -1672,7 +1715,8 @@ int MRInonzeroValRange(MRI *mri, float *pmin, float *pmax) { } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIvalRangeFrame(MRI *mri, float *pmin, float *pmax, int frame) { +int MRIvalRangeFrame(MRI *mri, float *pmin, float *pmax, int frame) +{ int width, height, depth, x, y, z; float fmin, fmax, *pf, val; BUFTYPE *pb; @@ -1740,7 +1784,8 @@ int MRIvalRangeFrame(MRI *mri, float *pmin, float *pmax, int frame) { } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIvalRangeRegion(MRI *mri, float *pmin, float *pmax, MRI_REGION *region) { +int MRIvalRangeRegion(MRI *mri, float *pmin, float *pmax, MRI_REGION *region) +{ int width, height, depth, x, y, z, x0, y0, z0; float fmin, fmax, *pf, val; BUFTYPE *pb; @@ -1806,7 +1851,8 @@ int MRIvalRangeRegion(MRI *mri, float *pmin, float *pmax, MRI_REGION *region) { } /*----------------------------------------------------- ------------------------------------------------------*/ -MRI_REGION *MRIclipRegion(MRI *mri, MRI_REGION *reg_src, MRI_REGION *reg_clip) { +MRI_REGION *MRIclipRegion(MRI *mri, MRI_REGION *reg_src, MRI_REGION *reg_clip) +{ int x2, y2, z2; x2 = MIN(mri->width - 1, reg_src->x + reg_src->dx - 1); @@ -1822,7 +1868,8 @@ MRI_REGION *MRIclipRegion(MRI *mri, MRI_REGION *reg_src, MRI_REGION *reg_clip) { } /*----------------------------------------------------- ------------------------------------------------------*/ -MRI *MRIvalScale(MRI *mri_src, MRI *mri_dst, float flo, float fhi) { +MRI *MRIvalScale(MRI *mri_src, MRI *mri_dst, float flo, float fhi) +{ int width, height, depth, x, y, z, f; float fmin, fmax, *pf_src, *pf_dst, val, scale; short *ps_src, *ps_dst; @@ -1847,7 +1894,8 @@ MRI *MRIvalScale(MRI *mri_src, MRI *mri_dst, float flo, float fhi) { val = (val - fmin) * scale + flo; MRIsetVoxVal(mri_dst, x, y, z, f, val); } - } else + } + else switch (mri_src->type) // same voxel types { case MRI_FLOAT: @@ -1895,7 +1943,8 @@ MRI *MRIvalScale(MRI *mri_src, MRI *mri_dst, float flo, float fhi) { /*----------------------------------------------------- ------------------------------------------------------*/ MRI *MRIconfThresh( - MRI *mri_src, MRI *mri_probs, MRI *mri_classes, MRI *mri_dst, float thresh, int min_target, int max_target) { + MRI *mri_src, MRI *mri_probs, MRI *mri_classes, MRI *mri_dst, float thresh, int min_target, int max_target) +{ int x, y, z, width, height, depth, class; float *pprobs, prob; BUFTYPE *pclasses, *pdst, *psrc, src; @@ -1929,7 +1978,8 @@ MRI *MRIconfThresh( } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIboundingBoxNbhd(MRI *mri, int thresh, int wsize, MRI_REGION *box) { +int MRIboundingBoxNbhd(MRI *mri, int thresh, int wsize, MRI_REGION *box) +{ int width, height, depth, x, y, z, x1, y1, z1, xi, yi, zi, xk, yk, zk, whalf, in_brain; BUFTYPE *psrc; float *pfsrc; @@ -2060,7 +2110,8 @@ int MRIboundingBoxNbhd(MRI *mri, int thresh, int wsize, MRI_REGION *box) { ------------------------------------------------------*/ #define MIN_DARK 10 -int MRIfindApproximateSkullBoundingBox(MRI *mri, int thresh, MRI_REGION *box) { +int MRIfindApproximateSkullBoundingBox(MRI *mri, int thresh, MRI_REGION *box) +{ int width, height, depth, x, y, z, x1, y1, z1; int ndark, max_dark, start, nlight, max_light, done = 0; double means[3]; @@ -2088,7 +2139,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = x; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark > max_dark) { max_dark = ndark; @@ -2114,7 +2166,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = x; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark >= max_dark) { max_dark = ndark; @@ -2134,7 +2187,8 @@ bright stuff 'outside' of brain */ done = 0; means[1] -= 10; printf("left/right detection failed, moving y coord to %d from %d\n", nint(means[1]) + 10, nint(means[1])); - } else + } + else done = 1; } while (!done); @@ -2149,7 +2203,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = y; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark >= max_dark) { max_dark = ndark; @@ -2183,7 +2238,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = y; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark >= max_dark) { max_dark = ndark; @@ -2209,7 +2265,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = z; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark >= max_dark) { max_dark = ndark; @@ -2235,7 +2292,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = z; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark >= max_dark) { max_dark = ndark; @@ -2261,7 +2319,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = z; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark >= max_dark) { max_dark = ndark; @@ -2283,7 +2342,8 @@ bright stuff 'outside' of brain */ if (!ndark) start = z; ndark++; nlight = 0; - } else { + } + else { if (++nlight > MAX_LIGHT) max_dark = 0; if (ndark >= max_dark) { max_dark = ndark; @@ -2304,7 +2364,8 @@ bright stuff 'outside' of brain */ } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIboundingBox(MRI *mri, int thresh, MRI_REGION *box) { +int MRIboundingBox(MRI *mri, int thresh, MRI_REGION *box) +{ int width, height, depth, x, y, z, x1, y1, z1; BUFTYPE *psrc; float *pfsrc; @@ -2400,7 +2461,8 @@ int MRIboundingBox(MRI *mri, int thresh, MRI_REGION *box) { } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIcheckSize(MRI *mri_src, MRI *mri_check, int width, int height, int depth) { +int MRIcheckSize(MRI *mri_src, MRI *mri_check, int width, int height, int depth) +{ if (!mri_check) return (0); if (!width) width = mri_src->width; @@ -2413,7 +2475,8 @@ int MRIcheckSize(MRI *mri_src, MRI *mri_check, int width, int height, int depth) } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRItransformRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *src_region, MRI_REGION *dst_region) { +int MRItransformRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *src_region, MRI_REGION *dst_region) +{ double xw, yw, zw, xt, yt, zt, xv, yv, zv; if (getSliceDirection(mri_src) != getSliceDirection(mri_dst)) @@ -2466,8 +2529,8 @@ int MRItransformRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *src_region, MRI_R } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIvoxelToVoxel( - MRI *mri_src, MRI *mri_dst, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt) { +int MRIvoxelToVoxel(MRI *mri_src, MRI *mri_dst, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt) +{ double xw, yw, zw, xt, yt, zt; #if 0 @@ -2504,12 +2567,14 @@ int MRIvoxelToVoxel( if (MRIgeometryMatched(mri_src, mri_dst) == 0) { MRIvoxelToWorld(mri_src, xv, yv, zv, &xw, &yw, &zw); MRIworldToVoxel(mri_dst, xw, yw, zw, pxt, pyt, pzt); - } else { + } + else { *pxt = xv; *pyt = yv; *pzt = zv; } - } else { + } + else { MRIvoxelToWorld(mri_src, xv, yv, zv, &xw, &yw, &zw); if (mri_src->linear_transform) transform_point(mri_src->linear_transform, xw, yw, zw, &xt, &yt, &zt); @@ -2532,7 +2597,8 @@ int MRIvoxelToVoxel( } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIvoxelToTalairachVoxel(MRI *mri, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt) { +int MRIvoxelToTalairachVoxel(MRI *mri, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt) +{ double xw, yw, zw, xt, yt, zt; #if 0 @@ -2571,7 +2637,8 @@ int MRIvoxelToTalairachVoxel(MRI *mri, double xv, double yv, double zv, double * } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIvoxelToTalairach(MRI *mri, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt) { +int MRIvoxelToTalairach(MRI *mri, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt) +{ double xw, yw, zw; #if 0 @@ -2610,7 +2677,8 @@ int MRIvoxelToTalairach(MRI *mri, double xv, double yv, double zv, double *pxt, } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRItalairachToVoxel(MRI *mri, double xt, double yt, double zt, double *pxv, double *pyv, double *pzv) { +int MRItalairachToVoxel(MRI *mri, double xt, double yt, double zt, double *pxv, double *pyv, double *pzv) +{ double xw, yw, zw; #if 0 @@ -2649,7 +2717,8 @@ int MRItalairachToVoxel(MRI *mri, double xt, double yt, double zt, double *pxv, } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRItalairachVoxelToVoxel(MRI *mri, double xtv, double ytv, double ztv, double *pxv, double *pyv, double *pzv) { +int MRItalairachVoxelToVoxel(MRI *mri, double xtv, double ytv, double ztv, double *pxv, double *pyv, double *pzv) +{ double xw, yw, zw, xt, yt, zt; #if 0 @@ -2689,7 +2758,8 @@ int MRItalairachVoxelToVoxel(MRI *mri, double xtv, double ytv, double ztv, doubl } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRItalairachVoxelToWorld(MRI *mri, double xtv, double ytv, double ztv, double *pxw, double *pyw, double *pzw) { +int MRItalairachVoxelToWorld(MRI *mri, double xtv, double ytv, double ztv, double *pxw, double *pyw, double *pzw) +{ double xw, yw, zw, xt, yt, zt; #if 0 @@ -2733,7 +2803,8 @@ int MRItalairachVoxelToWorld(MRI *mri, double xtv, double ytv, double ztv, doubl ------------------------------------------------------*/ #define V4_LOAD(v, x, y, z, r) (VECTOR_ELT(v, 1) = x, VECTOR_ELT(v, 2) = y, VECTOR_ELT(v, 3) = z, VECTOR_ELT(v, 4) = r); -int MRIvoxelToWorld(MRI *mri, double xv, double yv, double zv, double *pxw, double *pyw, double *pzw) { +int MRIvoxelToWorld(MRI *mri, double xv, double yv, double zv, double *pxw, double *pyw, double *pzw) +{ AffineVector vw, vv; // if the transform is not cached yet, then @@ -2764,14 +2835,16 @@ int MRIvoxelToWorld(MRI *mri, double xv, double yv, double zv, double *pxw, doub } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIworldToTalairachVoxel(MRI *mri, double xw, double yw, double zw, double *pxv, double *pyv, double *pzv) { +int MRIworldToTalairachVoxel(MRI *mri, double xw, double yw, double zw, double *pxv, double *pyv, double *pzv) +{ double xt, yt, zt; if (mri->linear_transform == NULL) { xt = xw; yt = yw; zt = zw; - } else + } + else transform_point(mri->linear_transform, xw, yw, zw, &xt, &yt, &zt); MRIworldToVoxel(mri, xt, yt, zt, pxv, pyv, pzv); @@ -2779,7 +2852,8 @@ int MRIworldToTalairachVoxel(MRI *mri, double xw, double yw, double zw, double * } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIworldToVoxelIndex(MRI *mri, double xw, double yw, double zw, int *pxv, int *pyv, int *pzv) { +int MRIworldToVoxelIndex(MRI *mri, double xw, double yw, double zw, int *pxv, int *pyv, int *pzv) +{ double xv, yv, zv; MRIworldToVoxel(mri, xw, yw, zw, &xv, &yv, &zv); // Changed on 7/25/08 so that it rounds intead of truncates @@ -2802,7 +2876,8 @@ int MRIworldToVoxelIndex(MRI *mri, double xw, double yw, double zw, int *pxv, in surface RAS is wrong otherwise. */ -MATRIX *surfaceRASFromVoxel_(MRI *mri) { +MATRIX *surfaceRASFromVoxel_(MRI *mri) +{ MATRIX *vox2ras; // Compute i_to_r and r_to_i if it has not been done yet. This is @@ -2848,7 +2923,8 @@ MATRIX *surfaceRASFromVoxel_(MRI *mri) { is compute the tkregister-style Vox2RAS/RAS2Vox, so now it simply invertes the matrix from MRIxfmCRS2XYZtkreg(mri). *-------------------------------------------------------------------*/ -MATRIX *voxelFromSurfaceRAS_(MRI *mri) { +MATRIX *voxelFromSurfaceRAS_(MRI *mri) +{ MATRIX *vox2ras, *ras2vox; // Compute i_to_r and r_to_i if it has not been done yet. This is // not necessary for this function, but it was in Tosa's original @@ -2888,7 +2964,8 @@ MATRIX *voxelFromSurfaceRAS_(MRI *mri) { intermediate matrices are alloced, inverted, and dealloced, so it might not be a good thing to have inside a loop. --------------------------------------------------------------*/ -MATRIX *surfaceRASFromRAS_(MRI *mri) { +MATRIX *surfaceRASFromRAS_(MRI *mri) +{ MATRIX *sRASFromRAS; MATRIX *Vox2TkRAS, *Vox2RAS; @@ -2917,7 +2994,8 @@ MATRIX *surfaceRASFromRAS_(MRI *mri) { intermediate matrices are alloced, inverted, and dealloced, so it might not be a good thing to have inside a loop. --------------------------------------------------------------*/ -MATRIX *RASFromSurfaceRAS_(MRI *mri) { +MATRIX *RASFromSurfaceRAS_(MRI *mri) +{ MATRIX *RASFromSRAS; MATRIX *Vox2TkRAS, *Vox2RAS; @@ -2946,7 +3024,8 @@ MATRIX *RASFromSurfaceRAS_(MRI *mri) { and dealloced, so it might not be a good thing to have inside a loop. -------------------------------------------------------------*/ -int MRIRASToSurfaceRAS(MRI *mri, double xr, double yr, double zr, double *xsr, double *ysr, double *zsr) { +int MRIRASToSurfaceRAS(MRI *mri, double xr, double yr, double zr, double *xsr, double *ysr, double *zsr) +{ MATRIX *surfaceRASFromRAS = 0; VECTOR *v, *sr; v = VectorAlloc(4, MATRIX_REAL); @@ -2966,7 +3045,8 @@ int MRIRASToSurfaceRAS(MRI *mri, double xr, double yr, double zr, double *xsr, d scanner RAS. Note: intermediate matrices are alloced, inverted, and dealloced, so it might not be a good thing to have inside a loop. -------------------------------------------------------------*/ -int MRIsurfaceRASToRAS(MRI *mri, double xsr, double ysr, double zsr, double *xr, double *yr, double *zr) { +int MRIsurfaceRASToRAS(MRI *mri, double xsr, double ysr, double zsr, double *xr, double *yr, double *zr) +{ MATRIX *RASFromSurfaceRAS = 0; VECTOR *v, *r; v = VectorAlloc(4, MATRIX_REAL); @@ -2983,7 +3063,8 @@ int MRIsurfaceRASToRAS(MRI *mri, double xsr, double ysr, double zsr, double *xr, } //-------------------------------------------------------------- -int MRIvoxelToSurfaceRAS(MRI *mri, double xv, double yv, double zv, double *xs, double *ys, double *zs) { +int MRIvoxelToSurfaceRAS(MRI *mri, double xv, double yv, double zv, double *xs, double *ys, double *zs) +{ MATRIX *sRASFromVoxel; VECTOR *vv, *sr; @@ -3006,7 +3087,8 @@ int MRIvoxelToSurfaceRAS(MRI *mri, double xv, double yv, double zv, double *xs, /* extract the RASToVoxel Matrix */ MATRIX *GetSurfaceRASToVoxelMatrix(MRI *mri) { return voxelFromSurfaceRAS_(mri); } -int MRIsurfaceRASToVoxel(MRI *mri, double xr, double yr, double zr, double *xv, double *yv, double *zv) { +int MRIsurfaceRASToVoxel(MRI *mri, double xr, double yr, double zr, double *xv, double *yv, double *zv) +{ MATRIX *voxelFromSRAS; static VECTOR *sr = NULL, *vv = NULL; @@ -3026,7 +3108,8 @@ int MRIsurfaceRASToVoxel(MRI *mri, double xr, double yr, double zr, double *xv, } // same as above, but don't free matrix. Won't work if mri is changing -int MRIsurfaceRASToVoxelCached(MRI *mri, double xr, double yr, double zr, double *xv, double *yv, double *zv) { +int MRIsurfaceRASToVoxelCached(MRI *mri, double xr, double yr, double zr, double *xv, double *yv, double *zv) +{ static MATRIX *voxelFromSRAS = NULL; static VECTOR *sr = NULL, *vv = NULL; @@ -3044,7 +3127,8 @@ int MRIsurfaceRASToVoxelCached(MRI *mri, double xr, double yr, double zr, double } /*------------------------------------------------------*/ -int MRIworldToVoxel(MRI *mri, double xw, double yw, double zw, double *pxv, double *pyv, double *pzv) { +int MRIworldToVoxel(MRI *mri, double xw, double yw, double zw, double *pxv, double *pyv, double *pzv) +{ /* These internal workspaces are now static. They will 'leak' in that they will not be freed at exit @@ -3093,7 +3177,8 @@ int MRIworldToVoxel(MRI *mri, double xw, double yw, double zw, double *pxv, doub } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIinitHeader(MRI *mri) { +int MRIinitHeader(MRI *mri) +{ mri->ptype = 2; /* most of these are in mm */ @@ -3150,7 +3235,8 @@ int MRIinitHeader(MRI *mri) { * * @return NO_ERROR */ -int MRIreInitCache(MRI *mri) { +int MRIreInitCache(MRI *mri) +{ MATRIX *tmp; AffineMatrixFree(&(mri->i_to_r__)); @@ -3176,10 +3262,12 @@ int MRIreInitCache(MRI *mri) { Description change the direction of slices ------------------------------------------------------*/ -MRI *MRIextract(MRI *mri_src, MRI *mri_dst, int x0, int y0, int z0, int dx, int dy, int dz) { +MRI *MRIextract(MRI *mri_src, MRI *mri_dst, int x0, int y0, int z0, int dx, int dy, int dz) +{ return (MRIextractInto(mri_src, mri_dst, x0, y0, z0, dx, dy, dz, 0, 0, 0)); } -MRI *MRIcopyFrames(MRI *mri_src, MRI *mri_dst, int src_start_frame, int src_end_frame, int dst_start_frame) { +MRI *MRIcopyFrames(MRI *mri_src, MRI *mri_dst, int src_start_frame, int src_end_frame, int dst_start_frame) +{ int fno, offset; if (mri_dst == NULL) { @@ -3214,7 +3302,8 @@ MRI *MRIcopyFrames(MRI *mri_src, MRI *mri_dst, int src_start_frame, int src_end_ \breif Extracts the given region from the source MRI. See also MRIinsertRegion(). */ -MRI *MRIextractRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *region) { +MRI *MRIextractRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *region) +{ MRI_REGION box; if (region == NULL) { @@ -3232,7 +3321,8 @@ MRI *MRIextractRegion(MRI *mri_src, MRI *mri_dst, MRI_REGION *region) { \breif Takes an MRI struct that covers the given region and inserts it into a larger volume from which the region was extracted. See also MRIextractRegion(). */ -MRI *MRIinsertRegion(MRI *regionvol, MRI_REGION *region, MRI *temp, MRI *out) { +MRI *MRIinsertRegion(MRI *regionvol, MRI_REGION *region, MRI *temp, MRI *out) +{ int col, row, slc, f; double val; @@ -3262,7 +3352,8 @@ MRI *MRIinsertRegion(MRI *regionvol, MRI_REGION *region, MRI *temp, MRI *out) { Description Extract a cubic region of an MR image and return it to the caller ------------------------------------------------------*/ -MRI *MRIextractIntoRegion(MRI *mri_src, MRI *mri_dst, int x0, int y0, int z0, MRI_REGION *region) { +MRI *MRIextractIntoRegion(MRI *mri_src, MRI *mri_dst, int x0, int y0, int z0, MRI_REGION *region) +{ return (MRIextractInto( mri_src, mri_dst, x0, y0, z0, region->dx, region->dy, region->dz, region->x, region->y, region->z)); } @@ -3274,8 +3365,8 @@ MRI *MRIextractIntoRegion(MRI *mri_src, MRI *mri_dst, int x0, int y0, int z0, MR Description Extract a cubic region of an MR image and return it to the caller ------------------------------------------------------*/ -MRI *MRIextractInto( - MRI *mri_src, MRI *mri_dst, int x0, int y0, int z0, int dx, int dy, int dz, int x1, int y1, int z1) { +MRI *MRIextractInto(MRI *mri_src, MRI *mri_dst, int x0, int y0, int z0, int dx, int dy, int dz, int x1, int y1, int z1) +{ int width, height, depth, ys, zs, yd, zd, bytes, frame, xsize, ysize, zsize, dst_alloced = 0; double c_r, c_a, c_s; @@ -3397,7 +3488,8 @@ MRI *MRIextractInto( Description change the direction of slices ------------------------------------------------------*/ -MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { +MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) +{ int width, height, depth, x1, x2, x3; BUFTYPE *psrc, val, *pdst; @@ -3425,7 +3517,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { if (!mri_dst) { mri_dst = MRIalloc(depth, height, width, mri_src->type); MRIcopyHeader(mri_src, mri_dst); - } else if (depth != mri_dst->width || height != mri_dst->height || width != mri_dst->depth) { + } + else if (depth != mri_dst->width || height != mri_dst->height || width != mri_dst->depth) { ErrorReturn(NULL, (ERROR_BADPARM, "MRIreslice: invalid destination size (%d, %d, %d)", @@ -3443,8 +3536,9 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { } } } - } else if ((src_slice_direction == MRI_HORIZONTAL && slice_direction == MRI_CORONAL) || - (src_slice_direction == MRI_CORONAL && slice_direction == MRI_HORIZONTAL)) { + } + else if ((src_slice_direction == MRI_HORIZONTAL && slice_direction == MRI_CORONAL) || + (src_slice_direction == MRI_CORONAL && slice_direction == MRI_HORIZONTAL)) { /* horizontal images are top to bottom of the head, thus the depth axis points from the top of the head to the neck, with x from ear to ear @@ -3457,7 +3551,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { if (!mri_dst) { mri_dst = MRIalloc(width, depth, height, mri_src->type); MRIcopyHeader(mri_src, mri_dst); - } else if (depth != mri_dst->height || height != mri_dst->depth || width != mri_dst->width) + } + else if (depth != mri_dst->height || height != mri_dst->depth || width != mri_dst->width) ErrorReturn(NULL, (ERROR_BADPARM, "MRIreslice: invalid destination size (%d, %d, %d)", @@ -3475,7 +3570,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { } } } - } else if ((src_slice_direction == MRI_SAGITTAL && slice_direction == MRI_HORIZONTAL)) { + } + else if ((src_slice_direction == MRI_SAGITTAL && slice_direction == MRI_HORIZONTAL)) { /* horizontal images are top to bottom of the head, thus the depth axis @@ -3490,7 +3586,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { if (!mri_dst) { mri_dst = MRIalloc(width, depth, height, mri_src->type); MRIcopyHeader(mri_src, mri_dst); - } else if (depth != mri_dst->height || height != mri_dst->depth || width != mri_dst->width) + } + else if (depth != mri_dst->height || height != mri_dst->depth || width != mri_dst->width) ErrorReturn(NULL, (ERROR_BADPARM, "MRIreslice: invalid destination size (%d, %d, %d)", @@ -3507,7 +3604,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { } } } - } else if (src_slice_direction == MRI_HORIZONTAL && slice_direction == MRI_SAGITTAL) { + } + else if (src_slice_direction == MRI_HORIZONTAL && slice_direction == MRI_SAGITTAL) { /* horizontal images are top to bottom of the head, thus the depth axis @@ -3522,7 +3620,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { if (!mri_dst) { mri_dst = MRIalloc(width, depth, height, mri_src->type); MRIcopyHeader(mri_src, mri_dst); - } else if (depth != mri_dst->height || height != mri_dst->depth || width != mri_dst->width) + } + else if (depth != mri_dst->height || height != mri_dst->depth || width != mri_dst->width) ErrorReturn(NULL, (ERROR_BADPARM, "MRIreslice: invalid destination size (%d, %d, %d)", @@ -3539,7 +3638,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { } } } - } else + } + else switch (src_slice_direction) { default: MRIfree(&mri_dst); @@ -3562,7 +3662,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { if (!mri_dst) { mri_dst = MRIalloc(depth, height, width, mri_src->type); MRIcopyHeader(mri_src, mri_dst); - } else if (depth != mri_dst->width || height != mri_dst->height || width != mri_dst->depth) + } + else if (depth != mri_dst->width || height != mri_dst->height || width != mri_dst->depth) ErrorReturn(NULL, (ERROR_BADPARM, "MRIreslice: invalid destination size (%d, %d, %d)", @@ -3610,7 +3711,8 @@ MRI *MRIreslice(MRI *mri_src, MRI *mri_dst, int slice_direction) { Description Set an MRI intensity values to 0 ------------------------------------------------------*/ -int MRIclear(MRI *mri) { +int MRIclear(MRI *mri) +{ int width, depth, height, bytes, y, z, frame, nframes; width = mri->width; @@ -3662,7 +3764,8 @@ int MRIclear(MRI *mri) { eigenvalues are returned in the array evalues and the means in means (these last two must be three elements long.) ------------------------------------------------------*/ -int MRIcenterOfMass(MRI *mri, double *means, BUFTYPE threshold) { +int MRIcenterOfMass(MRI *mri, double *means, BUFTYPE threshold) +{ int width, height, depth, x, y, z; long npoints; double mx, my, mz, weight; @@ -3697,7 +3800,8 @@ int MRIcenterOfMass(MRI *mri, double *means, BUFTYPE threshold) { means[0] = mx; means[1] = my; means[2] = mz; - } else + } + else means[0] = means[1] = means[2] = 0.0f; return (NO_ERROR); @@ -3713,7 +3817,8 @@ int MRIcenterOfMass(MRI *mri, double *means, BUFTYPE threshold) { eigenvalues are returned in the array evalues and the means in means (these last two must be three elements long.) ------------------------------------------------------*/ -int MRIprincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, double *means, BUFTYPE threshold) { +int MRIprincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, double *means, BUFTYPE threshold) +{ int width, height, depth, x, y, z; long npoints; MATRIX *mCov, *mX, *mXT, *mTmp; @@ -3748,7 +3853,8 @@ int MRIprincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, double * means[0] = mx; means[1] = my; means[2] = mz; - } else + } + else means[0] = means[1] = means[2] = 0.0f; mX = MatrixAlloc(3, 1, MATRIX_REAL); /* zero-mean coordinate vector */ @@ -3791,7 +3897,8 @@ int MRIprincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, double * low_thresh <= val <= hi_thresh ------------------------------------------------------*/ int MRIprincipleComponentsRange( - MRI *mri, MATRIX *mEvectors, float *evalues, double *means, float low_thresh, float hi_thresh) { + MRI *mri, MATRIX *mEvectors, float *evalues, double *means, float low_thresh, float hi_thresh) +{ int width, height, depth, x, y, z; long npoints; MATRIX *mCov, *mX, *mXT, *mTmp; @@ -3827,7 +3934,8 @@ int MRIprincipleComponentsRange( means[0] = mx; means[1] = my; means[2] = mz; - } else + } + else means[0] = means[1] = means[2] = 0.0f; mX = MatrixAlloc(3, 1, MATRIX_REAL); /* zero-mean coordinate vector */ @@ -3868,7 +3976,8 @@ int MRIprincipleComponentsRange( eigenvalues are returned in the array evalues and the means in means (these last two must be three elements long.) ------------------------------------------------------*/ -int MRIbinaryPrincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, double *means, BUFTYPE threshold) { +int MRIbinaryPrincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, double *means, BUFTYPE threshold) +{ int width, height, depth, x, y, z; BUFTYPE *psrc, val; long npoints; @@ -3908,7 +4017,8 @@ int MRIbinaryPrincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, do means[0] = mx; means[1] = my; means[2] = mz; - } else + } + else means[0] = means[1] = means[2] = 0.0f; mX = MatrixAlloc(3, 1, MATRIX_REAL); /* zero-mean coordinate vector */ @@ -3947,7 +4057,8 @@ int MRIbinaryPrincipleComponents(MRI *mri, MATRIX *mEvectors, float *evalues, do Description threshold an MRI. ------------------------------------------------------*/ -MRI *MRIthresholdRangeInto(MRI *mri_src, MRI *mri_dst, BUFTYPE low_val, BUFTYPE hi_val) { +MRI *MRIthresholdRangeInto(MRI *mri_src, MRI *mri_dst, BUFTYPE low_val, BUFTYPE hi_val) +{ int width, height, depth, x, y, z, f; float val; @@ -3978,7 +4089,8 @@ MRI *MRIthresholdRangeInto(MRI *mri_src, MRI *mri_dst, BUFTYPE low_val, BUFTYPE Description threshold an MRI -- only 1st frame! ------------------------------------------------------*/ -MRI *MRIthreshold(MRI *mri_src, MRI *mri_dst, float threshold) { +MRI *MRIthreshold(MRI *mri_src, MRI *mri_dst, float threshold) +{ int width, height, depth, x, y, z, f; float val; @@ -4011,7 +4123,8 @@ MRI *MRIthreshold(MRI *mri_src, MRI *mri_dst, float threshold) { Description threshold an MRI considering all the frames ------------------------------------------------------*/ -MRI *MRIthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) { +MRI *MRIthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) +{ int frame, width, height, depth, x, y, z, f, n; float val; @@ -4033,7 +4146,8 @@ MRI *MRIthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) { if (n > 0) { val = 0; for (f = 0; f < frame; f++) MRIsetVoxVal(mri_dst, x, y, z, 0, val); - } else { + } + else { for (f = 0; f < frame; f++) { val = MRIgetVoxVal(mri_src, x, y, z, f); MRIsetVoxVal(mri_dst, x, y, z, f, val); @@ -4045,7 +4159,8 @@ MRI *MRIthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) { return (mri_dst); } -MRI *MRIupperthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) { +MRI *MRIupperthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) +{ int frame, width, height, depth, x, y, z, f, n; float val; @@ -4068,7 +4183,8 @@ MRI *MRIupperthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) { // val = threshold; LZ 12202012 val = 0; for (f = 0; f < frame; f++) MRIsetVoxVal(mri_dst, x, y, z, f, val); - } else { + } + else { for (f = 0; f < frame; f++) { val = MRIgetVoxVal(mri_src, x, y, z, f); MRIsetVoxVal(mri_dst, x, y, z, f, val); @@ -4080,7 +4196,8 @@ MRI *MRIupperthresholdAllFrames(MRI *mri_src, MRI *mri_dst, float threshold) { return (mri_dst); } // Only threshold the specified frame -MRI *MRIthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) { +MRI *MRIthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) +{ int f, width, height, depth, x, y, z, w; float val; @@ -4101,7 +4218,8 @@ MRI *MRIthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) { if (w == frame - 1) { if (val < threshold) val = 0; MRIsetVoxVal(mri_dst, x, y, z, frame - 1, val); - } else + } + else MRIsetVoxVal(mri_dst, x, y, z, w, val); } } @@ -4110,7 +4228,8 @@ MRI *MRIthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) { return (mri_dst); } -MRI *MRIupperthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) { +MRI *MRIupperthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) +{ int f, width, height, depth, x, y, z, w; float val; @@ -4133,7 +4252,8 @@ MRI *MRIupperthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int fra // val = threshold ; // MRIsetVoxVal(mri_dst, x, y, z, frame-1, val) ; MRIsetVoxVal(mri_dst, x, y, z, frame - 1, 0); - } else + } + else MRIsetVoxVal(mri_dst, x, y, z, w, val); } } @@ -4144,7 +4264,8 @@ MRI *MRIupperthresholdFrame(MRI *mri_src, MRI *mri_dst, float threshold, int fra } // Threshold all frames using one frame -MRI *MRIthresholdByFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) { +MRI *MRIthresholdByFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) +{ int f, width, height, depth, x, y, z, w; float val; @@ -4166,7 +4287,8 @@ MRI *MRIthresholdByFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) if (val < threshold) val = 0; if (w == frame - 1) { MRIsetVoxVal(mri_dst, x, y, z, frame - 1, val); - } else + } + else MRIsetVoxVal(mri_dst, x, y, z, w, val); } } @@ -4184,7 +4306,8 @@ MRI *MRIthresholdByFrame(MRI *mri_src, MRI *mri_dst, float threshold, int frame) Description threshold an MRI. ------------------------------------------------------*/ -MRI *MRIinvertContrast(MRI *mri_src, MRI *mri_dst, float threshold) { +MRI *MRIinvertContrast(MRI *mri_src, MRI *mri_dst, float threshold) +{ int width, height, depth, x, y, z; BUFTYPE *psrc, *pdst, val; @@ -4217,7 +4340,8 @@ MRI *MRIinvertContrast(MRI *mri_src, MRI *mri_dst, float threshold) { Description threshold an MRI. ------------------------------------------------------*/ -MRI *MRIbinarizeNoThreshold(MRI *mri_src, MRI *mri_dst) { +MRI *MRIbinarizeNoThreshold(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, f, z; if (!mri_dst) mri_dst = MRIclone(mri_src, NULL); @@ -4255,7 +4379,8 @@ MRI *MRIbinarizeNoThreshold(MRI *mri_src, MRI *mri_dst) { Description threshold an MRI. ------------------------------------------------------*/ -MRI *MRIbinarize(MRI *mri_src, MRI *mri_dst, float threshold, float low_val, float hi_val) { +MRI *MRIbinarize(MRI *mri_src, MRI *mri_dst, float threshold, float low_val, float hi_val) +{ int width, height, depth, f, z; if (!mri_dst) mri_dst = MRIclone(mri_src, NULL); @@ -4293,7 +4418,8 @@ MRI *MRIbinarize(MRI *mri_src, MRI *mri_dst, float threshold, float low_val, flo } /*-----------------------------------------------------*/ -MRI *MRIsubtract(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIsubtract(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int nframes, width, height, depth, x, y, z, f, s; float v1, v2, v = 0.0; BUFTYPE *p1 = NULL, *p2 = NULL, *pdst = NULL; @@ -4459,7 +4585,8 @@ MRI *MRIsubtract(MRI *mri1, MRI *mri2, MRI *mri_dst) } #endif -MRI *MRIabsdiff(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIabsdiff(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z; BUFTYPE *p1, *p2, *pdst, v1, v2; float f1, f2; @@ -4489,7 +4616,8 @@ MRI *MRIabsdiff(MRI *mri1, MRI *mri2, MRI *mri_dst) { } } } - } else { + } + else { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { @@ -4506,7 +4634,8 @@ MRI *MRIabsdiff(MRI *mri1, MRI *mri2, MRI *mri_dst) { \fn MRI *MRIabs(MRI *mri_src, MRI *mri_dst) \brief Computes the abs() of each voxel */ -MRI *MRIabs(MRI *mri_src, MRI *mri_dst) { +MRI *MRIabs(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, nframes, x, y, z, f; float val; @@ -4536,7 +4665,8 @@ MRI *MRIabs(MRI *mri_src, MRI *mri_dst) { \fn MRI *MRIpos(MRI *mri_src, MRI *mri_dst) \brief If a voxel is negative, sets it to 0. */ -MRI *MRIpos(MRI *mri_src, MRI *mri_dst) { +MRI *MRIpos(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, nframes, x, y, z, f; float val; @@ -4567,7 +4697,8 @@ MRI *MRIpos(MRI *mri_src, MRI *mri_dst) { \fn MRI *MRIpos(MRI *mri_src, MRI *mri_dst) \brief If a voxel is postive, sets it to 0. */ -MRI *MRIneg(MRI *mri_src, MRI *mri_dst) { +MRI *MRIneg(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, nframes, x, y, z, f; float val; @@ -4596,7 +4727,8 @@ MRI *MRIneg(MRI *mri_src, MRI *mri_dst) { } /*-----------------------------------------------------*/ -MRI *MRIadd(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIadd(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int nframes, width, height, depth, x, y, z, f, s; float v1, v2, v = 0.0; BUFTYPE *p1 = NULL, *p2 = NULL, *pdst = NULL; @@ -4790,7 +4922,8 @@ MRI *MRIadd(MRI *mri1, MRI *mri2, MRI *mri_dst) { /*----------------------------------------------------------- MRIaverage() - computes average of source and destination. ------------------------------------------------------*/ -MRI *MRIaverage(MRI *mri_src, int dof, MRI *mri_dst) { +MRI *MRIaverage(MRI *mri_src, int dof, MRI *mri_dst) +{ int width, height, depth, x, y, z, f; double src, dst; @@ -4835,7 +4968,8 @@ MRI *MRIaverage(MRI *mri_src, int dof, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRImultiply(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRImultiply(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z; float f1, f2; @@ -4867,7 +5001,8 @@ MRI *MRImultiply(MRI *mri1, MRI *mri2, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIscaleAndMultiply(MRI *mri1, float scale, MRI *mri2, MRI *mri_dst) { +MRI *MRIscaleAndMultiply(MRI *mri1, float scale, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z; BUFTYPE *p1, *p2, *pdst; float out_val; @@ -4900,7 +5035,8 @@ MRI *MRIscaleAndMultiply(MRI *mri1, float scale, MRI *mri2, MRI *mri_dst) { } /*----------------------------------------------------- ------------------------------------------------------*/ -MRI *MRIdivide(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIdivide(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z; BUFTYPE *p1, *p2, *pdst; @@ -4931,7 +5067,8 @@ MRI *MRIdivide(MRI *mri1, MRI *mri2, MRI *mri_dst) { } } } - } else /* both UCHAR volumes */ + } + else /* both UCHAR volumes */ { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { @@ -4942,7 +5079,8 @@ MRI *MRIdivide(MRI *mri1, MRI *mri2, MRI *mri_dst) { if (!*p2) { *pdst = FZERO(*p1) ? 0 : 255; p2++; - } else { + } + else { *pdst++ = *p1++ / *p2++; // printf("%d / %d = %d\n", *pdst, *p1, *p2); } @@ -4957,7 +5095,8 @@ MRI *MRIdivide(MRI *mri1, MRI *mri2, MRI *mri_dst) { header info and allocs the pixel space (but does not copy pixel data). ------------------------------------------------------*/ -MRI *MRIclone(const MRI *mri_src, MRI *mri_dst) { +MRI *MRIclone(const MRI *mri_src, MRI *mri_dst) +{ if (!mri_dst) mri_dst = MRIallocSequence(mri_src->width, mri_src->height, mri_src->depth, mri_src->type, mri_src->nframes); @@ -4974,7 +5113,8 @@ MRI *MRIclone(const MRI *mri_src, MRI *mri_dst) { Does not copy pixel data. */ -MRI *MRIcloneBySpace(MRI *mri_src, int type, int nframes) { +MRI *MRIcloneBySpace(MRI *mri_src, int type, int nframes) +{ MRI *mri_dst; if (type < 0) type = mri_src->type; if (nframes < 0) nframes = mri_src->nframes; @@ -4988,7 +5128,8 @@ MRI *MRIcloneBySpace(MRI *mri_src, int type, int nframes) { Description Copy one MRI into another (including header info) ------------------------------------------------------*/ -MRI *MRIcloneRoi(MRI *mri_src, MRI *mri_dst) { +MRI *MRIcloneRoi(MRI *mri_src, MRI *mri_dst) +{ int w, h, d; w = mri_src->width - mri_src->roi.x; @@ -5011,7 +5152,8 @@ MRI *MRIcloneRoi(MRI *mri_src, MRI *mri_dst) { \return 0 on success, 1 if error Has no effect if input is already chuncked */ -int MRIchunk(MRI **pmri) { +int MRIchunk(MRI **pmri) +{ MRI *mritmp; if ((*pmri)->ischunked) return (0); // printf("Chunking\n"); @@ -5026,7 +5168,8 @@ int MRIchunk(MRI **pmri) { /*---------------------------------------------------------- Copy one MRI into another (including header info and data) -----------------------------------------------------------*/ -MRI *MRIcopy(MRI *mri_src, MRI *mri_dst) { +MRI *MRIcopy(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, bytes, x, y, z, frame, val; float *fdst, *fsrc; BUFTYPE *csrc, *cdst; @@ -5079,7 +5222,8 @@ MRI *MRIcopy(MRI *mri_src, MRI *mri_dst) { } } } - } else { + } + else { switch (mri_src->type) { case MRI_FLOAT: switch (mri_dst->type) { @@ -5210,7 +5354,8 @@ MRI *MRIcopy(MRI *mri_src, MRI *mri_dst) { Allocate a lookup table that allows indices which are outside the image region. ------------------------------------------------------*/ -int MRIallocIndices(MRI *mri) { +int MRIallocIndices(MRI *mri) +{ int width, height, depth, i; width = mri->width; @@ -5265,7 +5410,8 @@ int MRIallocIndices(MRI *mri) { \fn MRI *MRIallocChunk(int width, int height, int depth, int type, int nframes) \brief Alloc pixel data in MRI struct as one big buffer. */ -MRI *MRIallocChunk(int width, int height, int depth, int type, int nframes) { +MRI *MRIallocChunk(int width, int height, int depth, int type, int nframes) +{ MRI *mri; int slice, row; void *p; @@ -5329,7 +5475,8 @@ MRI *MRIallocChunk(int width, int height, int depth, int type, int nframes) { depending on the FS_USE_MRI_CHUNK environment variable. */ /*-------------------------------------------------------------*/ -MRI *MRIallocSequence(int width, int height, int depth, int type, int nframes) { +MRI *MRIallocSequence(int width, int height, int depth, int type, int nframes) +{ MRI *mri; int slice, row, bpp; BUFTYPE *buf; @@ -5463,7 +5610,8 @@ MRI *MRIallocSequence(int width, int height, int depth, int type, int nframes) { \fn MRI *MRIallocHeader(int width, int height, int depth, int type, int nframes) \brief allocate an MRI data structure but not space for the image data */ -MRI *MRIallocHeader(int width, int height, int depth, int type, int nframes) { +MRI *MRIallocHeader(int width, int height, int depth, int type, int nframes) +{ MRI *mri; int i; @@ -5562,7 +5710,8 @@ MRI *MRIalloc(int width, int height, int depth, int type) { return (MRIallocSequ /*----------------------------------------------------- Free and MRI data structure and all its attached memory ------------------------------------------------------*/ -int MRIfree(MRI **pmri) { +int MRIfree(MRI **pmri) +{ MRI *mri; int slice, i; #if !USE_ELECTRIC_FENCE @@ -5597,7 +5746,8 @@ int MRIfree(MRI **pmri) { } free(mri->slices); } - } else { + } + else { // printf("Freeing MRI Chunk\n"); free(mri->chunk); mri->chunk = NULL; @@ -5636,7 +5786,8 @@ int MRIfree(MRI **pmri) { \brief Frees frames of the mri struct starting at start_frame. Cannot be run on mri struct with chunked mem management. */ -int MRIfreeFrames(MRI *mri, int start_frame) { +int MRIfreeFrames(MRI *mri, int start_frame) +{ int slice, row, end_frame; if (mri->ischunked) { @@ -5666,7 +5817,8 @@ int MRIfreeFrames(MRI *mri, int start_frame) { \fn MRIdump(MRI *mri, FILE *fp) \brief Dump the MRI header to a file */ -int MRIdump(MRI *mri, FILE *fp) { +int MRIdump(MRI *mri, FILE *fp) +{ fprintf(fp, "%6.6s = %s\n", "fname", mri->fname); fprintf(fp, "%6.6s = %d\n", "height", mri->height); fprintf(fp, "%6.6s = %d\n", "width", mri->width); @@ -5709,7 +5861,8 @@ int MRIdump(MRI *mri, FILE *fp) { \fn int MRIdumpBuffer(MRI *mri, FILE *fp) \brief Dump the non-zero elements of an MRI buffer to a file */ -int MRIdumpBuffer(MRI *mri, FILE *fp) { +int MRIdumpBuffer(MRI *mri, FILE *fp) +{ int x, y, z; for (z = 0; z < mri->depth; z++) { @@ -5734,7 +5887,8 @@ int MRIdumpBuffer(MRI *mri, FILE *fp) { \fn int MRIpeak(MRI *mri, int *px, int *py, int *pz) \brief Find the peak intensity in an MRI image. */ -int MRIpeak(MRI *mri, int *px, int *py, int *pz) { +int MRIpeak(MRI *mri, int *px, int *py, int *pz) +{ int max_row, max_col, max_slice, row, col, slice, width, height, depth; BUFTYPE val, max_val, *im; long lval, lmax_val, *lim; @@ -5812,7 +5966,8 @@ int MRIpeak(MRI *mri, int *px, int *py, int *pz) { /* compare two headers to see if they are the same voxel and ras coords */ -int MRIcompareHeaders(MRI *mri1, MRI *mri2) { +int MRIcompareHeaders(MRI *mri1, MRI *mri2) +{ if (mri1 == NULL || mri2 == NULL) return (1); // not the same if (!FEQUAL(mri1->xsize, mri2->xsize)) return (1); if (!FEQUAL(mri1->ysize, mri2->ysize)) return (1); @@ -5853,7 +6008,8 @@ int MRIcompareHeaders(MRI *mri1, MRI *mri2) { Does not copy the dimension lengths, only the geometry, pulse seq, etc. Does not copy ischunked or chunk pointer. ------------------------------------------------------*/ -MRI *MRIcopyHeader(const MRI *mri_src, MRI *mri_dst) { +MRI *MRIcopyHeader(const MRI *mri_src, MRI *mri_dst) +{ int i; if (mri_dst == NULL) @@ -5950,7 +6106,8 @@ MRI *MRIcopyHeader(const MRI *mri_src, MRI *mri_dst) { Translate the MRI image mri_src by the vector dx, dy, dz and store the result in mri_dst. ------------------------------------------------------*/ -MRI *MRItranslate(MRI *mri_src, MRI *mri_dst, double dx, double dy, double dz) { +MRI *MRItranslate(MRI *mri_src, MRI *mri_dst, double dx, double dy, double dz) +{ int y1, y2, y3, width, height, depth; BUFTYPE *pdst; double x1, x2, x3, val; @@ -5995,7 +6152,8 @@ MRI *MRItranslate(MRI *mri_src, MRI *mri_dst, double dx, double dy, double dz) { Rotate mri_src around the Y axis and return the result in mri_dst ------------------------------------------------------*/ -MRI *MRIrotateX(MRI *mri_src, MRI *mri_dst, float x_angle) { +MRI *MRIrotateX(MRI *mri_src, MRI *mri_dst, float x_angle) +{ int width, height, depth; MATRIX *m, *mO; @@ -6032,7 +6190,8 @@ MRI *MRIrotateX(MRI *mri_src, MRI *mri_dst, float x_angle) { Rotate mri_src around the Y axis and return the result in mri_dst ------------------------------------------------------*/ -MRI *MRIrotateY(MRI *mri_src, MRI *mri_dst, float y_angle) { +MRI *MRIrotateY(MRI *mri_src, MRI *mri_dst, float y_angle) +{ int width, height, depth; MATRIX *m, *mO; @@ -6070,7 +6229,8 @@ MRI *MRIrotateY(MRI *mri_src, MRI *mri_dst, float y_angle) { Rotate mri_src around the Z axis and return the result in mri_dst ------------------------------------------------------*/ -MRI *MRIrotateZ(MRI *mri_src, MRI *mri_dst, float z_angle) { +MRI *MRIrotateZ(MRI *mri_src, MRI *mri_dst, float z_angle) +{ int width, height, depth; MATRIX *m, *mO; @@ -6105,7 +6265,8 @@ MRI *MRIrotateZ(MRI *mri_src, MRI *mri_dst, float z_angle) { Rotate mri_src around the Y axis and return the result in mri_dst ------------------------------------------------------*/ -MRI *MRIrotateX_I(MRI *mri_src, MRI *mri_dst, float x_angle) { +MRI *MRIrotateX_I(MRI *mri_src, MRI *mri_dst, float x_angle) +{ int width, height, depth; MATRIX *m; @@ -6136,7 +6297,8 @@ MRI *MRIrotateX_I(MRI *mri_src, MRI *mri_dst, float x_angle) { Rotate mri_src around the Y axis and return the result in mri_dst ------------------------------------------------------*/ -MRI *MRIrotateY_I(MRI *mri_src, MRI *mri_dst, float y_angle) { +MRI *MRIrotateY_I(MRI *mri_src, MRI *mri_dst, float y_angle) +{ int width, height, depth; MATRIX *m; @@ -6167,7 +6329,8 @@ MRI *MRIrotateY_I(MRI *mri_src, MRI *mri_dst, float y_angle) { Rotate mri_src around the Z axis and return the result in mri_dst ------------------------------------------------------*/ -MRI *MRIrotateZ_I(MRI *mri_src, MRI *mri_dst, float z_angle) { +MRI *MRIrotateZ_I(MRI *mri_src, MRI *mri_dst, float z_angle) +{ int width, height, depth; MATRIX *m; @@ -6196,7 +6359,8 @@ MRI *MRIrotateZ_I(MRI *mri_src, MRI *mri_dst, float z_angle) { Scale the MRI image mri_src by sx,sy,sz in the x, y, and z directions respectively. ------------------------------------------------------*/ -MRI *MRIscale(MRI *mri_src, MRI *mri_dst, float sx, float sy, float sz) { +MRI *MRIscale(MRI *mri_src, MRI *mri_dst, float sx, float sy, float sz) +{ int width, height, depth; MATRIX *m; @@ -6230,7 +6394,8 @@ MRI *MRIscale(MRI *mri_src, MRI *mri_dst, float sx, float sy, float sz) { Description Rotate about the point mO ------------------------------------------------------*/ -MRI *MRIrotate(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) { +MRI *MRIrotate(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) +{ int x1, x2, x3, y1, y2, y3, width, height, depth, y1o, y2o, y3o, freeit; MATRIX *mX, *mY; /* original and transformed coordinate systems */ MATRIX *mRinv; /* inverse of R */ @@ -6252,7 +6417,8 @@ MRI *MRIrotate(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) { mO->rptr[2][1] = (double)mri_src->height / 2.0; mO->rptr[3][1] = (double)mri_src->depth / 2.0; freeit = 1; - } else + } + else freeit = 0; mX = MatrixAlloc(3, 1, MATRIX_REAL); /* input coordinates */ @@ -6297,7 +6463,8 @@ MRI *MRIrotate(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) { Description Rotate about the point mO using trilinear interpolation ------------------------------------------------------*/ -MRI *MRIrotate_I(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) { +MRI *MRIrotate_I(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) +{ int y1, y2, y3, width, height, depth, y1o, y2o, y3o, freeit; MATRIX *mX, *mY; /* original and transformed coordinate systems */ MATRIX *mRinv; /* inverse of R */ @@ -6321,7 +6488,8 @@ MRI *MRIrotate_I(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) { mO->rptr[2][1] = (double)mri_src->height / 2.0; mO->rptr[3][1] = (double)mri_src->depth / 2.0; freeit = 1; - } else + } + else freeit = 0; mX = MatrixAlloc(3, 1, MATRIX_REAL); /* input coordinates */ @@ -6370,7 +6538,8 @@ MRI *MRIrotate_I(MRI *mri_src, MRI *mri_dst, MATRIX *mR, MATRIX *mO) { Perform an affine coordinate transformation x' = Ax + B on the MRI image mri_src into mri_dst ------------------------------------------------------*/ -MRI *MRIaffine(MRI *mri_src, MRI *mri_dst, MATRIX *mA, MATRIX *mB) { +MRI *MRIaffine(MRI *mri_src, MRI *mri_dst, MATRIX *mA, MATRIX *mB) +{ int x1, x2, x3, y1, y2, y3, width, height, depth; MATRIX *mX, *mY; /* original and transformed coordinate systems */ @@ -6420,7 +6589,8 @@ MRI *MRIaffine(MRI *mri_src, MRI *mri_dst, MATRIX *mA, MATRIX *mB) { Description Convert a slice of an MRI data structure into a HIPS image. ------------------------------------------------------*/ -IMAGE *MRItoImageView(MRI *mri, IMAGE *I, int slice, int view, int frame) { +IMAGE *MRItoImageView(MRI *mri, IMAGE *I, int slice, int view, int frame) +{ int width, height, depth, x, y, yp, w, h, d, xm, ym, zm, format; float fmin, fmax, frac, xres = 1.0, yres = 1.0; double val; @@ -6745,7 +6915,8 @@ IMAGE *MRItoImageView(MRI *mri, IMAGE *I, int slice, int view, int frame) { Description Convert a slice of an MRI data structure into a HIPS image. ------------------------------------------------------*/ -IMAGE *MRItoImage(MRI *mri, IMAGE *I, int slice) { +IMAGE *MRItoImage(MRI *mri, IMAGE *I, int slice) +{ int width, height, y, yp; width = mri->width; @@ -6791,7 +6962,8 @@ IMAGE *MRItoImage(MRI *mri, IMAGE *I, int slice) { return (I); } -MRI *ImageToMRI(IMAGE *I) { +MRI *ImageToMRI(IMAGE *I) +{ MRI *mri; int width, height, depth, type, nframes, y, yp, x; int frames; @@ -6880,8 +7052,9 @@ MRI *ImageToMRI(IMAGE *I) { b = (rgb >> 16) & 0x00ff; MRIseq_vox(mri, x, y, 0, frames) = rgb; // MRIseq_vox(mri, x, y, 0, frames) = (0.299*r + 0.587*g + 0.114*b); ; // standard tv - //conversion - } else + // conversion + } + else MRIseq_vox(mri, x, y, 0, frames) = *IMAGEpix(I, x, yp); break; case MRI_SHORT: @@ -6900,8 +7073,9 @@ MRI *ImageToMRI(IMAGE *I) { b = (rgb >> 16) & 0x00ff; MRIseq_vox(mri, x, y, 0, frames) = rgb; // MRIseq_vox(mri, x, y, 0, frames) = (0.299*r + 0.587*g + 0.114*b); ; // standard tv - //conversion - } else { + // conversion + } + else { if (*IMAGESpix(I, x, yp) < 0) DiagBreak(); if (I->pixel_format == PFSHORT) MRIIseq_vox(mri, x, y, 0, frames) = (int)((unsigned short)(*IMAGESpix(I, x, yp))); @@ -6932,7 +7106,8 @@ MRI *ImageToMRI(IMAGE *I) { Description Build an MRI from all values s.t. min_val <= val <= max_val ------------------------------------------------------*/ -MRI *MRIextractValues(MRI *mri_src, MRI *mri_dst, float min_val, float max_val) { +MRI *MRIextractValues(MRI *mri_src, MRI *mri_dst, float min_val, float max_val) +{ BUFTYPE *psrc, *pdst, val; float *pfsrc, *pfdst, fval; int frame, x, y, z, width, height, depth; @@ -6989,7 +7164,8 @@ MRI *MRIextractValues(MRI *mri_src, MRI *mri_dst, float min_val, float max_val) is different than MRIdownsampleN() in that arbitrary sizes can be used and values are not give to pixel data (if pixel data alloced). */ -MRI *MRIresize(MRI *mri, double xsize, double ysize, double zsize, int nframes) { +MRI *MRIresize(MRI *mri, double xsize, double ysize, double zsize, int nframes) +{ MATRIX *V, *crsTrueCenter, *crsTrueCenter3, *rasTrueCenter4, *rasTrueCenter, *M, *P0, *crsCenter, *rasCenter, *crsTrueCenterNew; int width, height, depth; @@ -7103,7 +7279,8 @@ MRI *MRIupsample2(MRI *mri_src, MRI *mri_dst) { return (MRIupsampleN(mri_src, mr Upsample volume by integer factor. No error checking, upsample factor must be valid. ------------------------------------------------------*/ -MRI *MRIupsampleN(MRI *mri_src, MRI *mri_dst, int N) { +MRI *MRIupsampleN(MRI *mri_src, MRI *mri_dst, int N) +{ int width, depth, height, x, y, z, f; double val; MATRIX *Vox2RAS, *CRS0, *RAS0; @@ -7175,7 +7352,8 @@ MRI *MRIupsampleN(MRI *mri_src, MRI *mri_dst, int N) { \breif Uses MRIupsampleN() to upsample the data set, then divides by N*N*N to conserve the sum of all the values; */ -MRI *MRIupsampleNConserve(MRI *mri_src, MRI *mri_dst, int N) { +MRI *MRIupsampleNConserve(MRI *mri_src, MRI *mri_dst, int N) +{ double d = N * N * N, v; int c, r, s, f; MRI *mri_srctmp; @@ -7200,7 +7378,8 @@ MRI *MRIupsampleNConserve(MRI *mri_src, MRI *mri_dst, int N) { return (mri_dst); } -MRI *MRIdownsample2LabeledVolume(MRI *mri_src, MRI *mri_dst) { +MRI *MRIdownsample2LabeledVolume(MRI *mri_src, MRI *mri_dst) +{ int width, depth, height, x, y, z, x1, y1, z1, counts[256], label, max_count, out_label, zmin, zmax; width = mri_src->width / 2; @@ -7281,7 +7460,8 @@ MRI *MRIdownsample2LabeledVolume(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIdownsample2(MRI *mri_src, MRI *mri_dst) { +MRI *MRIdownsample2(MRI *mri_src, MRI *mri_dst) +{ int width, depth, height, x, y, z, x1, y1, z1; BUFTYPE *psrc; short *pssrc; @@ -7382,7 +7562,8 @@ MRI *MRIdownsample2(MRI *mri_src, MRI *mri_dst) { \param Fs - downsample factor for slices (depth) \param KeepType - set to non-0 to keep precision of src, otherwise float */ -MRI *MRIdownsampleN(MRI *src, MRI *dst, int Fc, int Fr, int Fs, int KeepType) { +MRI *MRIdownsampleN(MRI *src, MRI *dst, int Fc, int Fr, int Fs, int KeepType) +{ int c0, r0, s0, c, r, s, f; int width, height, depth, type; double val; @@ -7465,7 +7646,8 @@ MRI *MRIdownsampleN(MRI *src, MRI *dst, int Fc, int Fr, int Fs, int KeepType) { /*----------------------------------------------------- MRIdownsampleNOld(). Use MRIdownsampleN() instead. ------------------------------------------------------*/ -MRI *MRIdownsampleNOld(MRI *mri_src, MRI *mri_dst, int N) { +MRI *MRIdownsampleNOld(MRI *mri_src, MRI *mri_dst, int N) +{ int width, depth, height, x, y, z, x1, y1, z1; BUFTYPE *psrc; short *pssrc; @@ -7558,7 +7740,8 @@ MRI *MRIdownsampleNOld(MRI *mri_src, MRI *mri_dst, int N) { MRI MRIvalueFill(MRI *mri, float value) -- fills an mri volume with the given value. Type of mri can be anything. -------------------------------------------------------------*/ -int MRIvalueFill(MRI *mri, float value) { +int MRIvalueFill(MRI *mri, float value) +{ int c, r, s, f; for (c = 0; c < mri->width; c++) { @@ -7597,8 +7780,8 @@ int MRIvalueFill(MRI *mri, float value) { and for which the corresponding voxel in mri_src is below threshold. ------------------------------------------------------*/ -MRI *MRIfill( - MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, int threshold, int fill_val, int max_count) { +MRI *MRIfill(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, int threshold, int fill_val, int max_count) +{ int width, height, depth, x, y, z, nfilled, xmin, xmax, ymin, ymax, zmin, zmax, on, x0, x1, y0, y1, z0, z1; BUFTYPE *psrc, *pdst, val; @@ -7694,7 +7877,8 @@ MRI *MRIfill( Description ------------------------------------------------------*/ -MRI *MRIfillFG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, int threshold, int fill_val, int *npix) { +MRI *MRIfillFG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, int threshold, int fill_val, int *npix) +{ int width, height, depth, x, y, z, nfilled, xmin, xmax, ymin, ymax, zmin, zmax, on, x0, x1, y0, y1, z0, z1, total_pix; BUFTYPE *psrc, *pdst, val; @@ -7792,7 +7976,8 @@ MRI *MRIfillFG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, i Description ------------------------------------------------------*/ -MRI *MRIfillBG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, int threshold, int fill_val, int *npix) { +MRI *MRIfillBG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, int threshold, int fill_val, int *npix) +{ int width, height, depth, x, y, z, nfilled, xmin, xmax, ymin, ymax, zmin, zmax, on, x0, x1, y0, y1, z0, z1, total_pix; BUFTYPE *psrc, *pdst, val; @@ -7892,7 +8077,8 @@ MRI *MRIfillBG(MRI *mri_src, MRI *mri_dst, int seed_x, int seed_y, int seed_z, i Description ------------------------------------------------------*/ -int MRIsetResolution(MRI *mri, float xres, float yres, float zres) { +int MRIsetResolution(MRI *mri, float xres, float yres, float zres) +{ mri->ps = (xres + yres + zres) / 3.0f; mri->xsize = xres; mri->ysize = yres; @@ -7925,7 +8111,8 @@ int MRIsetResolution(MRI *mri, float xres, float yres, float zres) { Description ------------------------------------------------------*/ -int MRIsetTransform(MRI *mri, General_transform *transform) { +int MRIsetTransform(MRI *mri, General_transform *transform) +{ mri->transform = *transform; mri->linear_transform = get_linear_transform_ptr(transform); mri->inverse_linear_transform = get_inverse_linear_transform_ptr(transform); @@ -7939,7 +8126,8 @@ int MRIsetTransform(MRI *mri, General_transform *transform) { Description ------------------------------------------------------*/ -MRI *MRIextractTalairachPlane(MRI *mri_src, MRI *mri_dst, int orientation, int x, int y, int z, int wsize) { +MRI *MRIextractTalairachPlane(MRI *mri_src, MRI *mri_dst, int orientation, int x, int y, int z, int wsize) +{ double e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int whalf, xk, yk, xi, yi, zi; double ex, ey, ez, len, x0, y0, z0; @@ -8059,7 +8247,8 @@ MRI *MRIextractArbitraryPlane(MRI *mri_src, int x, int y, int z, - int wsize) { + int wsize) +{ double xbase, ybase, zbase; int whalf, xk, yk, xi, yi, zi; @@ -8100,7 +8289,8 @@ MRI *MRIextractArbitraryPlane(MRI *mri_src, Description ------------------------------------------------------*/ -int MRIeraseTalairachPlaneNew(MRI *mri, MRI *mri_mask, int orientation, int x, int y, int z, int wsize, int fill_val) { +int MRIeraseTalairachPlaneNew(MRI *mri, MRI *mri_mask, int orientation, int x, int y, int z, int wsize, int fill_val) +{ double e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int whalf, xk, yk, xi, yi, zi, xki, yki, x0, y0; double ex, ey, ez, len, xt0, yt0, zt0; @@ -8204,7 +8394,8 @@ int MRIeraseTalairachPlaneNew(MRI *mri, MRI *mri_mask, int orientation, int x, i Description ------------------------------------------------------*/ -int MRIeraseTalairachPlane(MRI *mri, MRI *mri_mask, int orientation, int x, int y, int z, int wsize, int fill_val) { +int MRIeraseTalairachPlane(MRI *mri, MRI *mri_mask, int orientation, int x, int y, int z, int wsize, int fill_val) +{ double e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int whalf, xk, yk, xi, yi, zi; double ex, ey, ez, len; @@ -8303,7 +8494,8 @@ int MRIeraseTalairachPlane(MRI *mri, MRI *mri_mask, int orientation, int x, int Description ------------------------------------------------------*/ -MRI *MRIextractPlane(MRI *mri_src, MRI *mri_dst, int orientation, int where) { +MRI *MRIextractPlane(MRI *mri_src, MRI *mri_dst, int orientation, int where) +{ int x, y, z, width, height; switch (orientation) { @@ -8358,7 +8550,8 @@ MRI *MRIextractPlane(MRI *mri_src, MRI *mri_dst, int orientation, int where) { Description ------------------------------------------------------*/ -MRI *MRIfillPlane(MRI *mri_mask, MRI *mri_dst, int orientation, int where, int fillval) { +MRI *MRIfillPlane(MRI *mri_mask, MRI *mri_dst, int orientation, int where, int fillval) +{ int x, y, z, width, height; switch (orientation) { @@ -8409,7 +8602,8 @@ MRI *MRIfillPlane(MRI *mri_mask, MRI *mri_dst, int orientation, int where, int f Description ------------------------------------------------------*/ -int MRIerasePlane(MRI *mri, float x0, float y0, float z0, float dx, float dy, float dz, int fill_val) { +int MRIerasePlane(MRI *mri, float x0, float y0, float z0, float dx, float dy, float dz, int fill_val) +{ int *pxi, *pyi, *pzi, xi, yi, zi, x, y, z; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, maxlen, l1, l2; @@ -8459,7 +8653,8 @@ int MRIerasePlane(MRI *mri, float x0, float y0, float z0, float dx, float dy, fl Description Interpolate the volume to cubic voxels. ------------------------------------------------------*/ -MRI *MRIinterpolate(MRI *mri_src, MRI *mri_dst) { +MRI *MRIinterpolate(MRI *mri_src, MRI *mri_dst) +{ int xs, ys, zs, xd, yd, zd, max_dim, xorig, yorig, zorig, dorig; float sx, sy, sz, psize; int width, height, depth, i; @@ -8473,7 +8668,8 @@ MRI *MRIinterpolate(MRI *mri_src, MRI *mri_dst) { if (width > height) { max_dim = width > depth ? width : depth; psize = width > depth ? mri_src->xsize : mri_src->zsize; - } else { + } + else { max_dim = height > depth ? height : depth; psize = height > depth ? mri_src->ysize : mri_src->zsize; } @@ -8584,7 +8780,8 @@ MRI *MRIinterpolate(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -int MRIsampleVolumeFrame(const MRI *mri, double x, double y, double z, const int frame, double *pval) { +int MRIsampleVolumeFrame(const MRI *mri, double x, double y, double z, const int frame, double *pval) +{ int OutOfBounds; int xm, xp, ym, yp, zm, zp, width, height, depth; double val, xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ @@ -8706,7 +8903,8 @@ int MRIsampleVolumeFrame(const MRI *mri, double x, double y, double z, const int #ifndef uchar #define uchar unsigned char #endif -int MRIsampleLabeledVolume(MRI *mri, double x, double y, double z, double *pval, unsigned char ucharLabel) { +int MRIsampleLabeledVolume(MRI *mri, double x, double y, double z, double *pval, unsigned char ucharLabel) +{ /* m's are the mri grid locations less than x (or y or z) (i.e. floor(x), p's are essentially rounding up to the next grid location greater than x */ @@ -8793,7 +8991,8 @@ int MRIsampleLabeledVolume(MRI *mri, double x, double y, double z, double *pval, Description ------------------------------------------------------*/ -int MRIsampleVolumeType(const MRI *mri, double x, double y, double z, double *pval, int type) { +int MRIsampleVolumeType(const MRI *mri, double x, double y, double z, double *pval, int type) +{ int xv, yv, zv; int OutOfBounds; @@ -8853,7 +9052,8 @@ int MRIsampleVolumeType(const MRI *mri, double x, double y, double z, double *pv Description ------------------------------------------------------*/ int MRIsampleVolumeFrameType( - const MRI *mri, const double x, const double y, const double z, const int frame, int type, double *pval) { + const MRI *mri, const double x, const double y, const double z, const int frame, int type, double *pval) +{ int xv, yv, zv; int OutOfBounds; @@ -8918,10 +9118,12 @@ int MRIsampleVolumeFrameType( return (NO_ERROR); } -int MRIinterpolateIntoVolume(MRI *mri, double x, double y, double z, double val) { +int MRIinterpolateIntoVolume(MRI *mri, double x, double y, double z, double val) +{ return (MRIinterpolateIntoVolumeFrame(mri, x, y, z, 0, val)); } -int MRIinterpolateIntoVolumeFrame(MRI *mri, double x, double y, double z, int frame, double val) { +int MRIinterpolateIntoVolumeFrame(MRI *mri, double x, double y, double z, int frame, double val) +{ int OutOfBounds; int xm, xp, ym, yp, zm, zp, width, height, depth; double xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ @@ -9021,7 +9223,8 @@ int MRIinterpolateIntoVolumeFrame(MRI *mri, double x, double y, double z, int fr single-frame volume. See MRIsampleSeqVolume() for sampling multi-frame. -------------------------------------------------------------------*/ -int MRIsampleVolume(const MRI *mri, double x, double y, double z, double *pval) { +int MRIsampleVolume(const MRI *mri, double x, double y, double z, double *pval) +{ int OutOfBounds; int xm, xp, ym, yp, zm, zp, width, height, depth; double val, xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ @@ -9112,7 +9315,8 @@ int MRIsampleVolume(const MRI *mri, double x, double y, double z, double *pval) sampled at the same time (this can be important in time-sensitive applications). -------------------------------------------------------------------*/ -int MRIsampleSeqVolume(const MRI *mri, double x, double y, double z, float *valvect, int firstframe, int lastframe) { +int MRIsampleSeqVolume(const MRI *mri, double x, double y, double z, float *valvect, int firstframe, int lastframe) +{ int OutOfBounds; int f, xm, xp, ym, yp, zm, zp, width, height, depth; double xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ @@ -9212,7 +9416,8 @@ int MRIsampleSeqVolume(const MRI *mri, double x, double y, double z, float *valv // testing - LZ int MRIsampleSeqVolumeType( - MRI *mri, double x, double y, double z, float *valvect, int firstframe, int lastframe, int type) { + MRI *mri, double x, double y, double z, float *valvect, int firstframe, int lastframe, int type) +{ int OutOfBounds; int /*f,xm, xp, ym, yp, zm, zp, */ f, width, height, depth; // double xmd, ymd, zmd, xpd, ypd, zpd ; /* d's are distances */ @@ -9362,7 +9567,8 @@ int MRIsampleSeqVolumeType( \description Computes the kernel used for trilinear interpolation. See also MRIsampleSeqVolume(). */ -double *MRItrilinKernel(MRI *mri, double c, double r, double s, double *kernel) { +double *MRItrilinKernel(MRI *mri, double c, double r, double s, double *kernel) +{ int OutOfBounds; int f, xm, xp, ym, yp, zm, zp, width, height, depth; double xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ @@ -9416,7 +9622,8 @@ double *MRItrilinKernel(MRI *mri, double c, double r, double s, double *kernel) used by MRIcubicSampleVolume ------------------------------------------------------*/ -double localeval(double x, int iter) { +double localeval(double x, int iter) +{ double p; switch (iter) { case 0: @@ -9450,7 +9657,8 @@ double localeval(double x, int iter) { uses localeval above ------------------------------------------------------*/ -int MRIcubicSampleVolume(const MRI *mri, double x, double y, double z, double *pval) { +int MRIcubicSampleVolume(const MRI *mri, double x, double y, double z, double *pval) +{ int OutOfBounds; int width, height, depth; int ix_low, iy_low, iz_low, ix, iy, iz; @@ -9555,7 +9763,8 @@ int MRIcubicSampleVolume(const MRI *mri, double x, double y, double z, double *p return (NO_ERROR); } -int MRIcubicSampleVolumeFrame(MRI *mri, double x, double y, double z, int frame, double *pval) { +int MRIcubicSampleVolumeFrame(MRI *mri, double x, double y, double z, int frame, double *pval) +{ int OutOfBounds; int width, height, depth; int ix_low, iy_low, iz_low, ix, iy, iz; @@ -9670,7 +9879,8 @@ int MRIcubicSampleVolumeFrame(MRI *mri, double x, double y, double z, int frame, ------------------------------------------------------*/ #define IMIN(a, b) (a < b ? a : b) #define IMAX(a, b) (a > b ? a : b) -double ham_sinc(double x, double fullwidth) { +double ham_sinc(double x, double fullwidth) +{ double ham; if (fabs(x) < 1.0e-5) ham = 1.0; @@ -9682,7 +9892,8 @@ double ham_sinc(double x, double fullwidth) { } /*-------------------------------------------------------------------------*/ -int MRIsincSampleVolume(const MRI *mri, double x, double y, double z, int hw, double *pval) { +int MRIsincSampleVolume(const MRI *mri, double x, double y, double z, int hw, double *pval) +{ int OutOfBounds; int width, height, depth; int nwidth; @@ -9776,13 +9987,15 @@ int MRIsincSampleVolume(const MRI *mri, double x, double y, double z, int hw, do *pval = 65535.0; else *pval = sum_z; - } else + } + else *pval = 0.0; return (NO_ERROR); } -int MRIsincSampleVolumeFrame(MRI *mri, double x, double y, double z, int frame, int hw, double *pval) { +int MRIsincSampleVolumeFrame(MRI *mri, double x, double y, double z, int frame, int hw, double *pval) +{ int OutOfBounds; int width, height, depth; int nwidth; @@ -9876,7 +10089,8 @@ int MRIsincSampleVolumeFrame(MRI *mri, double x, double y, double z, int frame, *pval = 65535.0; else *pval = sum_z; - } else + } + else *pval = 0.0; return (NO_ERROR); @@ -9891,7 +10105,8 @@ int MRIsincSampleVolumeFrame(MRI *mri, double x, double y, double z, int frame, volume. In this case the index of the nearest neighbor can safely be computed as the nearest integer to col, row, and slice. -----------------------------------------------------------------*/ -int MRIindexNotInVolume(const MRI *mri, const double col, const double row, const double slice) { +int MRIindexNotInVolume(const MRI *mri, const double col, const double row, const double slice) +{ float nicol, nirow, nislice; /* unambiguously in the volume */ @@ -9917,7 +10132,8 @@ int MRIindexNotInVolume(const MRI *mri, const double col, const double row, cons Interpolate the volume directional derivative using trilinear interpolation. ------------------------------------------------------*/ -float MRIsampleCardinalDerivative(MRI *mri, int x, int y, int z, int xk, int yk, int zk) { +float MRIsampleCardinalDerivative(MRI *mri, int x, int y, int z, int xk, int yk, int zk) +{ float d; if (xk) @@ -9937,7 +10153,8 @@ float MRIsampleCardinalDerivative(MRI *mri, int x, int y, int z, int xk, int yk, Interpolate the volume directional derivative using trilinear interpolation. ------------------------------------------------------*/ -float MRIsampleXDerivative(MRI *mri, int x, int y, int z, int dir) { +float MRIsampleXDerivative(MRI *mri, int x, int y, int z, int dir) +{ float dx; int yk, zk, xi, yi, zi, nvox; @@ -9965,7 +10182,8 @@ float MRIsampleXDerivative(MRI *mri, int x, int y, int z, int dir) { Interpolate the volume directional derivative using trilinear interpolation. ------------------------------------------------------*/ -float MRIsampleYDerivative(MRI *mri, int x, int y, int z, int dir) { +float MRIsampleYDerivative(MRI *mri, int x, int y, int z, int dir) +{ float dy; int xk, zk, xi, yi, zi, nvox; @@ -9993,7 +10211,8 @@ float MRIsampleYDerivative(MRI *mri, int x, int y, int z, int dir) { Interpolate the volume directional derivative using trilinear interpolation. ------------------------------------------------------*/ -float MRIsampleZDerivative(MRI *mri, int x, int y, int z, int dir) { +float MRIsampleZDerivative(MRI *mri, int x, int y, int z, int dir) +{ float dz; int xk, yk, xi, yi, zi, nvox; @@ -10013,7 +10232,8 @@ float MRIsampleZDerivative(MRI *mri, int x, int y, int z, int dir) { return (dz); } int MRIsampleVolumeDirectionScale( - MRI *mri, double x, double y, double z, double dx, double dy, double dz, double *pmag, double sigma) { + MRI *mri, double x, double y, double z, double dx, double dy, double dz, double *pmag, double sigma) +{ int width, height, depth; double xp1, xm1, yp1, ym1, zp1, zm1, len; double dist, val, k, ktotal, step_size, total_val; @@ -10058,7 +10278,8 @@ int MRIsampleVolumeDirectionScale( } int MRIsampleVolumeDerivativeScale( - MRI *mri, double x, double y, double z, double dx, double dy, double dz, double *pmag, double sigma) { + MRI *mri, double x, double y, double z, double dx, double dy, double dz, double *pmag, double sigma) +{ int width, height, depth; double xp1, xm1, yp1, ym1, zp1, zm1, vp1, vm1, len; double dist, val, k, ktotal, step_size; @@ -10112,7 +10333,8 @@ int MRIsampleVolumeDerivativeScale( Interpolate the volume directional derivative using trilinear interpolation. ------------------------------------------------------*/ -int MRIsampleVolumeDerivative(MRI *mri, double x, double y, double z, double dx, double dy, double dz, double *pmag) { +int MRIsampleVolumeDerivative(MRI *mri, double x, double y, double z, double dx, double dy, double dz, double *pmag) +{ int width, height, depth; double xp1, xm1, yp1, ym1, zp1, zm1, vp1, vm1, len; @@ -10171,7 +10393,8 @@ int MRIsampleVolumeDerivative(MRI *mri, double x, double y, double z, double dx, Description Interpolate the volume gradient to cubic voxels. ------------------------------------------------------*/ -int MRIsampleVolumeGradient(MRI *mri, double x, double y, double z, double *pdx, double *pdy, double *pdz) { +int MRIsampleVolumeGradient(MRI *mri, double x, double y, double z, double *pdx, double *pdy, double *pdz) +{ int width, height, depth; double xp1, xm1, yp1, ym1, zp1, zm1; @@ -10233,7 +10456,8 @@ int MRIsampleVolumeGradient(MRI *mri, double x, double y, double z, double *pdx, Interpolate the volume gradient to cubic voxels. ------------------------------------------------------*/ int MRIsampleVolumeGradientFrame( - const MRI *mri, double x, double y, double z, double *pdx, double *pdy, double *pdz, int frame) { + const MRI *mri, double x, double y, double z, double *pdx, double *pdy, double *pdz, int frame) +{ int width, height, depth; double xp1, xm1, yp1, ym1, zp1, zm1; @@ -10281,7 +10505,8 @@ int MRIsampleVolumeGradientFrame( Description ------------------------------------------------------*/ -int MRIneighborsOn(MRI *mri, int x0, int y0, int z0, int min_val) { +int MRIneighborsOn(MRI *mri, int x0, int y0, int z0, int min_val) +{ int nbrs = 0; if (MRIgetVoxVal(mri, mri->xi[x0 - 1], y0, z0, 0) >= min_val) nbrs++; @@ -10299,7 +10524,8 @@ int MRIneighborsOn(MRI *mri, int x0, int y0, int z0, int min_val) { Description ------------------------------------------------------*/ -int MRIneighborsOn3x3(MRI *mri, int x, int y, int z, int min_val) { +int MRIneighborsOn3x3(MRI *mri, int x, int y, int z, int min_val) +{ int xk, yk, zk, xi, yi, zi, nbrs; for (nbrs = 0, zk = -1; zk <= 1; zk++) { @@ -10322,7 +10548,8 @@ int MRIneighborsOn3x3(MRI *mri, int x, int y, int z, int min_val) { Description ------------------------------------------------------*/ -int MRIneighborsInWindow(MRI *mri, int x, int y, int z, int wsize, int val) { +int MRIneighborsInWindow(MRI *mri, int x, int y, int z, int wsize, int val) +{ int xk, yk, zk, xi, yi, zi, nbrs, whalf; whalf = (wsize - 1) / 2; @@ -10347,7 +10574,8 @@ int MRIneighborsInWindow(MRI *mri, int x, int y, int z, int wsize, int val) { Description ------------------------------------------------------*/ -int MRIneighbors(MRI *mri, int x0, int y0, int z0, int val) { +int MRIneighbors(MRI *mri, int x0, int y0, int z0, int val) +{ int nbrs = 0; if (nint(MRIgetVoxVal(mri, mri->xi[x0 - 1], y0, z0, 0)) == val) nbrs++; @@ -10365,7 +10593,8 @@ int MRIneighbors(MRI *mri, int x0, int y0, int z0, int val) { Description ------------------------------------------------------*/ -int MRIneighborsInRange(MRI *mri, int x0, int y0, int z0, int frame, float low_val, float hi_val) { +int MRIneighborsInRange(MRI *mri, int x0, int y0, int z0, int frame, float low_val, float hi_val) +{ int nbrs = 0; float val; @@ -10390,7 +10619,8 @@ int MRIneighborsInRange(MRI *mri, int x0, int y0, int z0, int frame, float low_v Description ------------------------------------------------------*/ -int MRIneighbors3x3(MRI *mri, int x, int y, int z, int val) { +int MRIneighbors3x3(MRI *mri, int x, int y, int z, int val) +{ int xk, yk, zk, xi, yi, zi, nbrs; for (nbrs = 0, zk = -1; zk <= 1; zk++) { @@ -10408,7 +10638,8 @@ int MRIneighbors3x3(MRI *mri, int x, int y, int z, int val) { } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIneighborsOff(MRI *mri, int x0, int y0, int z0, int min_val) { +int MRIneighborsOff(MRI *mri, int x0, int y0, int z0, int min_val) +{ int nbrs = 0; if (MRIvox(mri, x0 - 1, y0, z0) < min_val) nbrs++; @@ -10421,7 +10652,8 @@ int MRIneighborsOff(MRI *mri, int x0, int y0, int z0, int min_val) { } /*----------------------------------------------------- ------------------------------------------------------*/ -int MRIneighborsOff3x3(MRI *mri, int x, int y, int z, int min_val) { +int MRIneighborsOff3x3(MRI *mri, int x, int y, int z, int min_val) +{ int xk, yk, zk, xi, yi, zi, nbrs; for (nbrs = 0, zk = -1; zk <= 1; zk++) { @@ -10441,7 +10673,8 @@ int MRIneighborsOff3x3(MRI *mri, int x, int y, int z, int min_val) { Perform an linear coordinate transformation x' = Ax on the MRI image mri_src into mri_dst ------------------------------------------------------*/ -MRI *MRIinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) { +MRI *MRIinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) +{ MATRIX *m_inv; m_inv = MatrixInverse(mA, NULL); @@ -10458,7 +10691,8 @@ MRI *MRIinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) { Convert a transform from RAS to voxel coordinates, then apply it to an MRI. ------------------------------------------------------*/ -MRI *MRIapplyRASlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform) { +MRI *MRIapplyRASlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform) +{ MATRIX *m_voxel_xform; m_voxel_xform = MRIrasXformToVoxelXform(mri_src, mri_dst, m_ras_xform, NULL); @@ -10472,7 +10706,8 @@ MRI *MRIapplyRASlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform) Convert a transform from RAS to voxel coordinates, then apply it to an MRI. ------------------------------------------------------*/ -MRI *MRIapplyRASlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform, int interp) { +MRI *MRIapplyRASlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform, int interp) +{ MATRIX *m_voxel_xform; m_voxel_xform = MRIrasXformToVoxelXform(mri_src, mri_dst, m_ras_xform, NULL); @@ -10486,7 +10721,8 @@ MRI *MRIapplyRASlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_ Convert a transform from RAS to voxel coordinates, then apply it to an MRI. ------------------------------------------------------*/ -MRI *MRIapplyRASinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform) { +MRI *MRIapplyRASinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform) +{ MATRIX *m_voxel_xform; m_voxel_xform = MRIrasXformToVoxelXform(mri_src, mri_dst, m_ras_xform, NULL); @@ -10499,7 +10735,8 @@ MRI *MRIapplyRASinverseLinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras Perform an linear coordinate transformation x' = Ax on the MRI image mri_src into mri_dst using sinc interp. ------------------------------------------------------*/ -MRI *MRIsincTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int hw) { +MRI *MRIsincTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int hw) +{ int y1, y2, y3, width, height, depth; VECTOR *v_X, *v_Y; /* original and transformed coordinate systems */ MATRIX *mAinv; /* inverse of mA */ @@ -10565,7 +10802,8 @@ MRI *MRIsincTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int hw) { interpolation. This the operations under this function name can now (2/20/02) be found under MRIlinearTransformInterp(). -----------------------------------------------------------------*/ -MRI *MRIlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) { +MRI *MRIlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) +{ mri_dst = MRIlinearTransformInterp(mri_src, mri_dst, mA, SAMPLE_TRILINEAR); return (mri_dst); } @@ -10574,7 +10812,8 @@ MRI *MRIlinearTransform(MRI *mri_src, MRI *mri_dst, MATRIX *mA) { x' = Ax on the MRI image mri_src into mri_dst using the specified interpolation method. A is a voxel-to-voxel transform. ------------------------------------------------------------------*/ -MRI *MRIlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int InterpMethod) { +MRI *MRIlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int InterpMethod) +{ int y1, y2, y3, width, height, depth, frame; VECTOR *v_X, *v_Y; /* original and transformed coordinate systems */ MATRIX *mAinv; /* inverse of mA */ @@ -10683,7 +10922,8 @@ MRI *MRIlinearTransformInterp(MRI *mri_src, MRI *mri_dst, MATRIX *mA, int Interp return (mri_dst); } -MRI *MRIconcatenateFrames(MRI *mri_frame1, MRI *mri_frame2, MRI *mri_dst) { +MRI *MRIconcatenateFrames(MRI *mri_frame1, MRI *mri_frame2, MRI *mri_dst) +{ int width, height, depth, x, y, z; BUFTYPE *pf1, *pf2, *pdst1, *pdst2; @@ -10715,7 +10955,8 @@ MRI *MRIconcatenateFrames(MRI *mri_frame1, MRI *mri_frame2, MRI *mri_dst) { } /*----------------------------------------------------- ------------------------------------------------------*/ -MRI *MRIcopyFrame(MRI *mri_src, MRI *mri_dst, int src_frame, int dst_frame) { +MRI *MRIcopyFrame(MRI *mri_src, MRI *mri_dst, int src_frame, int dst_frame) +{ int width, height, depth, x, y, z; width = mri_src->width; @@ -10746,7 +10987,8 @@ MRI *MRIcopyFrame(MRI *mri_src, MRI *mri_dst, int src_frame, int dst_frame) { Description compute the mean in a frame of all values ------------------------------------------------------*/ -double MRImeanFrame(MRI *mri, int frame) { +double MRImeanFrame(MRI *mri, int frame) +{ int width, height, depth, x, y, z; double mean; double val; @@ -10767,7 +11009,8 @@ double MRImeanFrame(MRI *mri, int frame) { } } mean /= (double)(width * height * depth); - } else { + } + else { for (mean = 0.0, frame = 0; frame < mri->nframes; frame++) for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { @@ -10790,7 +11033,8 @@ double MRImeanFrame(MRI *mri, int frame) { Description compute the mean in a frame of all values ------------------------------------------------------*/ -double MRImeanFrameNonzeroMask(MRI *mri, int frame, MRI *mri_mask) { +double MRImeanFrameNonzeroMask(MRI *mri, int frame, MRI *mri_mask) +{ int width, height, depth, x, y, z, nvox; double mean; double val; @@ -10814,7 +11058,8 @@ double MRImeanFrameNonzeroMask(MRI *mri, int frame, MRI *mri_mask) { } } mean /= nvox; - } else { + } + else { for (mean = 0.0, frame = 0; frame < mri->nframes; frame++) for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { @@ -10838,7 +11083,8 @@ double MRImeanFrameNonzeroMask(MRI *mri, int frame, MRI *mri_mask) { Description compute the mean in a frame of all values above thresh ------------------------------------------------------*/ -double MRImeanFrameThresh(MRI *mri, int frame, float thresh) { +double MRImeanFrameThresh(MRI *mri, int frame, float thresh) +{ int width, height, depth, x, y, z, num; double mean; double val; @@ -10870,7 +11116,8 @@ double MRImeanFrameThresh(MRI *mri, int frame, float thresh) { dimensions to their original values. The values of the volume can be rescaled between f_low and f_high. ------------------------------------------------------------*/ -MRI *MRISeqchangeType(MRI *vol, int dest_type, float f_low, float f_high, int no_scale_option_flag) { +MRI *MRISeqchangeType(MRI *vol, int dest_type, float f_low, float f_high, int no_scale_option_flag) +{ int nslices, nframes, i; MRI *mri; @@ -10909,7 +11156,8 @@ MRI *MRISeqchangeType(MRI *vol, int dest_type, float f_low, float f_high, int no with optional rescaling. Use MRISeqchangeType() for 3D or 4D volumes. ---------------------------------------------------------*/ -MRI *MRIchangeType(MRI *src, int dest_type, float f_low, float f_high, int no_scale_option_flag) { +MRI *MRIchangeType(MRI *src, int dest_type, float f_low, float f_high, int no_scale_option_flag) +{ MRI *dest = NULL; int i, j, k; float val; @@ -11010,7 +11258,8 @@ MRI *MRIchangeType(MRI *src, int dest_type, float f_low, float f_high, int no_sc // MRIFvox(dest, i, j, k) = (float)val; MRIsetVoxVal(dest, i, j, k, frame, val); } - } else { + } + else { long nonzero = 0; /* ----- build a histogram ----- */ @@ -11147,7 +11396,8 @@ MRI *MRIchangeType(MRI *src, int dest_type, float f_low, float f_high, int no_sc } /* end MRIchangeType() */ /*-----------------------------------------------------*/ -MATRIX *MRIgetResampleMatrix(MRI *src, MRI *template_vol) { +MATRIX *MRIgetResampleMatrix(MRI *src, MRI *template_vol) +{ MATRIX *src_mat, *dest_mat; /* from i to ras */ float src_det, dest_det; MATRIX *src_inv, *m; @@ -11243,11 +11493,13 @@ MATRIX *MRIgetResampleMatrix(MRI *src, MRI *template_vol) { } /* end MRIreslice() */ -MRI *MRIresample(MRI *src, MRI *template_vol, int resample_type) { +MRI *MRIresample(MRI *src, MRI *template_vol, int resample_type) +{ return (MRIresampleFill(src, template_vol, resample_type, 0)); } /* end MRIresample() */ -MRI *MRIresampleFill(MRI *src, MRI *template_vol, int resample_type, float fill_val) { +MRI *MRIresampleFill(MRI *src, MRI *template_vol, int resample_type, float fill_val) +{ MRI *dest = NULL; MATRIX *m; int nframe; @@ -11388,7 +11640,8 @@ MRI *MRIresampleFill(MRI *src, MRI *template_vol, int resample_type, float fill_ } } MRIfree(&mri_votes); - } else + } + else for (nframe = 0; nframe < template_vol->nframes; nframe++) { for (di = 0; di < template_vol->width; di++) { for (dj = 0; dj < template_vol->height; dj++) { @@ -11429,13 +11682,16 @@ MRI *MRIresampleFill(MRI *src, MRI *template_vol, int resample_type, float fill_ if (resample_type == SAMPLE_SINC) { MRIsincSampleVolumeFrame(src, si_ff, sj_ff, sk_ff, nframe, 5, &pval); val = (float)pval; - } else if (resample_type == SAMPLE_CUBIC) { + } + else if (resample_type == SAMPLE_CUBIC) { MRIcubicSampleVolumeFrame(src, si_ff, sj_ff, sk_ff, nframe, &pval); val = (float)pval; - } else if (resample_type == SAMPLE_CUBIC_BSPLINE) { + } + else if (resample_type == SAMPLE_CUBIC_BSPLINE) { MRIsampleBSpline(bspline, si_ff, sj_ff, sk_ff, nframe, &pval); val = (float)pval; - } else { + } + else { i_good_flag = (si >= 0 && si < src->width); i1_good_flag = (si + 1 >= 0 && si + 1 < src->width); j_good_flag = (sj >= 0 && sj < src->height); @@ -11590,19 +11846,22 @@ MRI *MRIresampleFill(MRI *src, MRI *template_vol, int resample_type, float fill_ val = val000; else val = val001; - } else { + } + else { if (sk_f < 0.5) val = val010; else val = val011; } - } else { + } + else { if (sj_f < 0.5) { if (sk_f < 0.5) val = val100; else val = val101; - } else { + } + else { if (sk_f < 0.5) val = val110; else @@ -11812,7 +12071,8 @@ MRI *MRIresampleFill(MRI *src, MRI *template_vol, int resample_type, float fill_ } /* end MRIresample() */ -int MRIlimits(MRI *mri, float *min, float *max) { +int MRIlimits(MRI *mri, float *min, float *max) +{ float val; int i, j, k, f; @@ -11896,7 +12156,8 @@ int MRIlimits(MRI *mri, float *min, float *max) { } /* end MRIlimits() */ -int MRIprintStats(MRI *mri, FILE *stream) { +int MRIprintStats(MRI *mri, FILE *stream) +{ float min, max, mean, std; int n; double com[3]; @@ -11917,7 +12178,8 @@ int MRIprintStats(MRI *mri, FILE *stream) { } /* end MRIprintStats() */ -int MRIstats(MRI *mri, float *min, float *max, int *n_voxels, float *mean, float *std) { +int MRIstats(MRI *mri, float *min, float *max, int *n_voxels, float *mean, float *std) +{ float val; float sum, sq_sum; int i, j, k, t; @@ -12025,7 +12287,8 @@ int MRIstats(MRI *mri, float *min, float *max, int *n_voxels, float *mean, float } /* end MRIstats() */ -float MRIvolumeDeterminant(MRI *mri) { +float MRIvolumeDeterminant(MRI *mri) +{ MATRIX *m; float det; @@ -12074,7 +12337,8 @@ int stuff_four_by_four(MATRIX *m, float m41, float m42, float m43, - float m44) { + float m44) +{ if (m == NULL) { ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "stuff_four_by_four(): matrix is NULL")); } @@ -12104,7 +12368,8 @@ int stuff_four_by_four(MATRIX *m, } /* end stuff_four_by_four() */ -int apply_i_to_r(MRI *mri, MATRIX *m) { +int apply_i_to_r(MRI *mri, MATRIX *m) +{ float x_r, x_a, x_s; float y_r, y_a, y_s; float z_r, z_a, z_s; @@ -12166,7 +12431,8 @@ int apply_i_to_r(MRI *mri, MATRIX *m) { } /* end apply_i_to_r() */ -MATRIX *MRIrasXformToVoxelXform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform, MATRIX *m_voxel_xform) { +MATRIX *MRIrasXformToVoxelXform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform, MATRIX *m_voxel_xform) +{ MATRIX *m_ras_to_voxel, *m_voxel_to_ras, *m_tmp; if (!mri_dst) mri_dst = mri_src; /* assume they will be in the same space */ @@ -12184,7 +12450,8 @@ MATRIX *MRIrasXformToVoxelXform(MRI *mri_src, MRI *mri_dst, MATRIX *m_ras_xform, return (m_voxel_xform); } -MATRIX *MRIvoxelXformToRasXform(MRI *mri_src, MRI *mri_dst, MATRIX *m_voxel_xform, MATRIX *m_ras_xform) { +MATRIX *MRIvoxelXformToRasXform(MRI *mri_src, MRI *mri_dst, MATRIX *m_voxel_xform, MATRIX *m_ras_xform) +{ MATRIX *m_ras_to_voxel, *m_voxel_to_ras, *m_tmp; if (!mri_dst) mri_dst = mri_src; /* assume they will be in the same space */ @@ -12202,7 +12469,8 @@ MATRIX *MRIvoxelXformToRasXform(MRI *mri_src, MRI *mri_dst, MATRIX *m_voxel_xfor return (m_ras_xform); } -int MRIsetVoxelToRasXform(MRI *mri, MATRIX *m_vox2ras) { +int MRIsetVoxelToRasXform(MRI *mri, MATRIX *m_vox2ras) +{ float ci, cj, ck; mri->x_r = *MATRIX_RELT(m_vox2ras, 1, 1) / mri->xsize; @@ -12232,7 +12500,8 @@ int MRIsetVoxelToRasXform(MRI *mri, MATRIX *m_vox2ras) { } /* eof */ -MRI *MRIscaleMeanIntensities(MRI *mri_src, MRI *mri_ref, MRI *mri_dst) { +MRI *MRIscaleMeanIntensities(MRI *mri_src, MRI *mri_ref, MRI *mri_dst) +{ int width, height, depth, x, y, z, val; double ref_mean, src_mean, nref_vox, nsrc_vox, scale; @@ -12276,7 +12545,8 @@ MRI *MRIscaleMeanIntensities(MRI *mri_src, MRI *mri_ref, MRI *mri_dst) { return (mri_dst); } -MRI *MRIsmoothParcellation(MRI *mri, int smooth_parcellation_count) { +MRI *MRIsmoothParcellation(MRI *mri, int smooth_parcellation_count) +{ MRI *mri2; int i, j, k; short vals[26]; @@ -12339,7 +12609,8 @@ MRI *MRIsmoothParcellation(MRI *mri, int smooth_parcellation_count) { } /* end MRIsmoothParcellation() */ -int MRIeraseBorderPlanes(MRI *mri, int border_size) { +int MRIeraseBorderPlanes(MRI *mri, int border_size) +{ int x, y, z, i, f; for (f = 0; f < mri->nframes; f++) @@ -12371,14 +12642,16 @@ int MRIeraseBorderPlanes(MRI *mri, int border_size) { return (NO_ERROR); } -int MRIcopyPulseParameters(MRI *mri_src, MRI *mri_dst) { +int MRIcopyPulseParameters(MRI *mri_src, MRI *mri_dst) +{ mri_dst->flip_angle = mri_src->flip_angle; mri_dst->tr = mri_src->tr; mri_dst->te = mri_src->te; mri_dst->ti = mri_src->ti; return (NO_ERROR); } -float MRIfindNearestNonzero(MRI *mri, int wsize, double xr, double yr, double zr, float max_dist) { +float MRIfindNearestNonzero(MRI *mri, int wsize, double xr, double yr, double zr, float max_dist) +{ int xk, yk, zk, xi, yi, zi, whalf, x, y, z; float dist, min_dist, min_val, dx, dy, dz; dist = 0.0; @@ -12414,7 +12687,8 @@ float MRIfindNearestNonzero(MRI *mri, int wsize, double xr, double yr, double zr if (max_dist > 0 && dist > max_dist) return (0); return (min_val); } -int MRImaxInNbhd6Connected(MRI *mri, int x, int y, int z, int frame) { +int MRImaxInNbhd6Connected(MRI *mri, int x, int y, int z, int frame) +{ int xk, yk, zk, xi, yi, zi; double max_val, val; @@ -12433,7 +12707,8 @@ int MRImaxInNbhd6Connected(MRI *mri, int x, int y, int z, int frame) { return (max_val); } -int MRImaxInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame) { +int MRImaxInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame) +{ int xk, yk, zk, xi, yi, zi, whalf; double max_val, val; @@ -12452,7 +12727,8 @@ int MRImaxInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame) { return (max_val); } -int MRImeanNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame) { +int MRImeanNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame) +{ int xk, yk, zk, xi, yi, zi, whalf, total; double mean, val; @@ -12474,7 +12750,8 @@ int MRImeanNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame) { return (mean / total); } -int MRIcountNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) { +int MRIcountNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) +{ int xk, yk, zk, xi, yi, zi, whalf, total; whalf = (wsize - 1) / 2; @@ -12490,7 +12767,8 @@ int MRIcountNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) { } return (total); } -int MRIareNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) { +int MRIareNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) +{ int xk, yk, zk, xi, yi, zi, whalf; whalf = (wsize - 1) / 2; @@ -12506,8 +12784,8 @@ int MRIareNonzeroInNbhd(MRI *mri, int wsize, int x, int y, int z) { } return (0); } -float MRIfindNearestNonzeroLocation( - MRI *mri, int wsize, double xr, double yr, double zr, int *pxv, int *pyv, int *pzv) { +float MRIfindNearestNonzeroLocation(MRI *mri, int wsize, double xr, double yr, double zr, int *pxv, int *pyv, int *pzv) +{ int xk, yk, zk, xi, yi, zi, whalf, x, y, z; float dist, min_dist, min_val, dx, dy, dz; @@ -12546,7 +12824,8 @@ float MRIfindNearestNonzeroLocation( return (min_val); } -MRI *MRIfromTalairach(MRI *mri_src, MRI *mri_dst) { +MRI *MRIfromTalairach(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, xv, yv, zv; double xt, yt, zt, xn, yn, zn, val; @@ -12565,7 +12844,8 @@ MRI *MRIfromTalairach(MRI *mri_src, MRI *mri_dst) { if ((xv >= 0 && xv < mri_src->width) && (yv >= 0 && yv < mri_src->height) && (zv >= 0 && zv < mri_src->depth)) { MRIsampleVolume(mri_src, xt, yt, zt, &val); MRIvox(mri_dst, x, y, z) = val; - } else + } + else MRIvox(mri_dst, x, y, z) = 0; } } @@ -12573,7 +12853,8 @@ MRI *MRIfromTalairach(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -MRI *MRItoTalairach(MRI *mri_src, MRI *mri_dst) { +MRI *MRItoTalairach(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, xv, yv, zv; double xt, yt, zt, xn, yn, zn, val; @@ -12592,7 +12873,8 @@ MRI *MRItoTalairach(MRI *mri_src, MRI *mri_dst) { if ((xv >= 0 && xv < mri_src->width) && (yv >= 0 && yv < mri_src->height) && (zv >= 0 && zv < mri_src->depth)) { MRIsampleVolume(mri_src, xn, yn, zn, &val); MRIvox(mri_dst, x, y, z) = val; - } else + } + else MRIvox(mri_dst, x, y, z) = 0; } } @@ -12608,7 +12890,8 @@ MRI *MRItoTalairach(MRI *mri_src, MRI *mri_dst) { in outmri. If outmri is NULL, the output MRI is alloced and its pointer returned. ------------------------------------------------------------------*/ -MRI *MRIlog10(MRI *inmri, MRI *mask, MRI *outmri, int negflag) { +MRI *MRIlog10(MRI *inmri, MRI *mask, MRI *outmri, int negflag) +{ int c, r, s, f; double val, m; @@ -12620,7 +12903,8 @@ MRI *MRIlog10(MRI *inmri, MRI *mask, MRI *outmri, int negflag) { return (NULL); } MRIcopyHeader(inmri, outmri); - } else { + } + else { if (inmri->width != outmri->width || inmri->height != outmri->height || inmri->depth != outmri->depth || inmri->nframes != outmri->nframes) { printf("ERROR: MRIlog10: output dimension mismatch\n"); @@ -12652,7 +12936,8 @@ MRI *MRIlog10(MRI *inmri, MRI *mask, MRI *outmri, int negflag) { MRIFseq_vox(outmri, c, r, s, f) = log10(fabs(val)); else MRIFseq_vox(outmri, c, r, s, f) = -log10(val); - } else { + } + else { if (val < 0) MRIFseq_vox(outmri, c, r, s, f) = -log10(fabs(val)); else @@ -12679,7 +12964,8 @@ MRI *MRIlog10(MRI *inmri, MRI *mask, MRI *outmri, int negflag) { is important because this is run on raw data (dti). -------------------------------------------------------*/ #define EPSILON 0.25 -MRI *MRIlog(MRI *in, MRI *mask, double a, double b, MRI *out) { +MRI *MRIlog(MRI *in, MRI *mask, double a, double b, MRI *out) +{ int c, r, s, f, n, ncols, nrows, nslices, nframes; float m; float *pout = NULL; @@ -12795,7 +13081,8 @@ MRI *MRIlog(MRI *in, MRI *mask, double a, double b, MRI *out) { mrimean. The frames of mrimean are replicated nreps times, each rep gets different noise */ -MRI *MRIrandexp(MRI *mrimean, MRI *binmask, unsigned long int seed, int nreps, MRI *mrirandexp) { +MRI *MRIrandexp(MRI *mrimean, MRI *binmask, unsigned long int seed, int nreps, MRI *mrirandexp) +{ int err, c, r, s, f, f2, m, nthrep, nframestot; RFS *rfs; double mu, L, v, q; @@ -12806,7 +13093,8 @@ MRI *MRIrandexp(MRI *mrimean, MRI *binmask, unsigned long int seed, int nreps, M mrirandexp = MRIallocSequence(mrimean->width, mrimean->height, mrimean->depth, MRI_FLOAT, nframestot); MRIcopyHeader(mrimean, mrirandexp); MRIcopyPulseParameters(mrimean, mrirandexp); - } else { + } + else { err = MRIdimMismatch(mrimean, mrirandexp, 0); if (err) { printf("ERROR: MRIrandexp(): dimension mismatch\n"); @@ -12864,7 +13152,8 @@ MRI *MRIrandexp(MRI *mrimean, MRI *binmask, unsigned long int seed, int nreps, M MRIrandn() - fills an MRI structure with values sampled from a normal distribution with mean avg and standard devation stddev. --------------------------------------------------------*/ -MRI *MRIrandn(int ncols, int nrows, int nslices, int nframes, float avg, float stddev, MRI *mri) { +MRI *MRIrandn(int ncols, int nrows, int nslices, int nframes, float avg, float stddev, MRI *mri) +{ int c, r, s, f; if (mri == NULL) { @@ -12873,7 +13162,8 @@ MRI *MRIrandn(int ncols, int nrows, int nslices, int nframes, float avg, float s printf("ERROR: MRIrandn: could not alloc\n"); return (NULL); } - } else { + } + else { if (mri->width != ncols || mri->height != nrows || mri->depth != nslices || mri->nframes != nframes) { printf("ERROR: MRIrandn: dimension mismatch\n"); return (NULL); @@ -12904,7 +13194,8 @@ MRI *MRIrandn(int ncols, int nrows, int nslices, int nframes, float avg, float s pdf(x) = r*((r*(x-avg+1))^(r-1)) * exp(-r*(x-avg+1)) / (r-1)! when order=1, this generates an exponential distribution. --------------------------------------------------------*/ -MRI *MRIrande(int ncols, int nrows, int nslices, int nframes, float avg, int order, MRI *mri) { +MRI *MRIrande(int ncols, int nrows, int nslices, int nframes, float avg, int order, MRI *mri) +{ int c, r, s, f; if (mri == NULL) { @@ -12913,7 +13204,8 @@ MRI *MRIrande(int ncols, int nrows, int nslices, int nframes, float avg, int ord printf("ERROR: MRIrande: could not alloc\n"); return (NULL); } - } else { + } + else { if (mri->width != ncols || mri->height != nrows || mri->depth != nslices || mri->nframes != nframes) { printf("ERROR: MRIrande: dimension mismatch\n"); return (NULL); @@ -12944,7 +13236,8 @@ MRI *MRIrande(int ncols, int nrows, int nslices, int nframes, float avg, int ord it will alloc a MRI_FLOAT volume, otherwise, it will use the type as specified in mri. --------------------------------------------------------*/ -MRI *MRIdrand48(int ncols, int nrows, int nslices, int nframes, float min, float max, MRI *mri) { +MRI *MRIdrand48(int ncols, int nrows, int nslices, int nframes, float min, float max, MRI *mri) +{ int c, r, s, f, n; float range, v; BUFTYPE *pmri = NULL; @@ -12959,7 +13252,8 @@ MRI *MRIdrand48(int ncols, int nrows, int nslices, int nframes, float min, float printf("ERROR: MRIdrand48: could not alloc\n"); return (NULL); } - } else { + } + else { if (mri->width != ncols || mri->height != nrows || mri->depth != nslices || mri->nframes != nframes) { printf("ERROR: MRIdrand48: dimension mismatch\n"); return (NULL); @@ -13020,7 +13314,8 @@ MRI *MRIdrand48(int ncols, int nrows, int nslices, int nframes, float min, float the given CDF. See PDFsampleCDF(). CDF[n] is the probability that the random number is <= xCDF[n]. --------------------------------------------------------------------*/ -MRI *MRIsampleCDF(int ncols, int nrows, int nslices, int nframes, double *xCDF, double *CDF, int nCDF, MRI *mri) { +MRI *MRIsampleCDF(int ncols, int nrows, int nslices, int nframes, double *xCDF, double *CDF, int nCDF, MRI *mri) +{ int c, r, s, f; if (mri == NULL) { @@ -13029,7 +13324,8 @@ MRI *MRIsampleCDF(int ncols, int nrows, int nslices, int nframes, double *xCDF, printf("ERROR: MRIsampleCDF: could not alloc\n"); return (NULL); } - } else { + } + else { if (mri->width != ncols || mri->height != nrows || mri->depth != nslices || mri->nframes != nframes) { printf("ERROR: MRIsampleCDF: dimension mismatch\n"); return (NULL); @@ -13057,7 +13353,8 @@ MRI *MRIsampleCDF(int ncols, int nrows, int nslices, int nframes, double *xCDF, NULL, it will alloc a MRI_FLOAT volume, otherwise, it will use the type as specified in mri. --------------------------------------------------------*/ -MRI *MRIconst(int ncols, int nrows, int nslices, int nframes, float val, MRI *mri) { +MRI *MRIconst(int ncols, int nrows, int nslices, int nframes, float val, MRI *mri) +{ int c, r, s, f, n; BUFTYPE *pmri = NULL; short *psmri = NULL; @@ -13071,7 +13368,8 @@ MRI *MRIconst(int ncols, int nrows, int nslices, int nframes, float val, MRI *mr printf("ERROR: MRIdconst: could not alloc\n"); return (NULL); } - } else { + } + else { if (mri->width != ncols || mri->height != nrows || mri->depth != nslices || mri->nframes != nframes) { printf("ERROR: MRIconst: dimension mismatch\n"); return (NULL); @@ -13127,7 +13425,8 @@ MRI *MRIconst(int ncols, int nrows, int nslices, int nframes, float val, MRI *mr } /*--------------------------------------------------------------*/ -int MRInormalizeSequence(MRI *mri, float target) { +int MRInormalizeSequence(MRI *mri, float target) +{ int x, y, z, frame; double norm; double val; @@ -13165,7 +13464,8 @@ int MRInormalizeSequence(MRI *mri, float target) { return (NO_ERROR); } -double MRIstdInLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_mean, int label) { +double MRIstdInLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_mean, int label) +{ int x, y, z, nvox, l; double mean, var = 0.0; float val; @@ -13189,7 +13489,8 @@ double MRIstdInLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_mean, int label) { return (sqrt(var / nvox)); } -MATRIX *MRIcovarianceInLabelMultispectral(MRI *mri_src, MRI *mri_labeled, VECTOR *v_means, int label) { +MATRIX *MRIcovarianceInLabelMultispectral(MRI *mri_src, MRI *mri_labeled, VECTOR *v_means, int label) +{ MATRIX *m_cov; int f1, f2, x, y, z, nvox, l; double mean1, mean2; @@ -13224,7 +13525,8 @@ MATRIX *MRIcovarianceInLabelMultispectral(MRI *mri_src, MRI *mri_labeled, VECTOR return (m_cov); } -VECTOR *MRImeanInLabelMultispectral(MRI *mri_src, MRI *mri_labeled, int label) { +VECTOR *MRImeanInLabelMultispectral(MRI *mri_src, MRI *mri_labeled, int label) +{ int f, x, y, z, nvox, l; double mean; float val; @@ -13252,7 +13554,8 @@ VECTOR *MRImeanInLabelMultispectral(MRI *mri_src, MRI *mri_labeled, int label) { } return (v_means); } -double MRImeanInLabel(MRI *mri_src, MRI *mri_labeled, int label) { +double MRImeanInLabel(MRI *mri_src, MRI *mri_labeled, int label) +{ int x, y, z, nvox, l; double mean = 0.0; float val; @@ -13274,7 +13577,8 @@ double MRImeanInLabel(MRI *mri_src, MRI *mri_labeled, int label) { return (mean / nvox); } -double MRImeanAndStdInLabel(MRI *mri_src, MRI *mri_labeled, int label, double *pstd) { +double MRImeanAndStdInLabel(MRI *mri_src, MRI *mri_labeled, int label, double *pstd) +{ int x, y, z, nvox, l; double mean = 0.0; double var = 0; @@ -13301,7 +13605,8 @@ double MRImeanAndStdInLabel(MRI *mri_src, MRI *mri_labeled, int label, double *p } double MRImeanInLabelInRegion( - MRI *mri_src, MRI *mri_labeled, int label, int x0, int y0, int z0, int whalf, double *psigma) { + MRI *mri_src, MRI *mri_labeled, int label, int x0, int y0, int z0, int whalf, double *psigma) +{ int x, y, z, nvox, l; double mean = 0.0; double var = 0.0; @@ -13332,7 +13637,8 @@ double MRImeanInLabelInRegion( } return (mean); } -double MRImaxInLabelInRegion(MRI *mri_src, MRI *mri_labeled, int label, int x0, int y0, int z0, int whalf) { +double MRImaxInLabelInRegion(MRI *mri_src, MRI *mri_labeled, int label, int x0, int y0, int z0, int whalf) +{ int x, y, z; int l; float val; @@ -13358,7 +13664,8 @@ double MRImaxInLabelInRegion(MRI *mri_src, MRI *mri_labeled, int label, int x0, return (max); } -MRI *MRImakePositive(MRI *mri_src, MRI *mri_dst) { +MRI *MRImakePositive(MRI *mri_src, MRI *mri_dst) +{ float fmin, fmax, val; int x, y, z, f; @@ -13380,7 +13687,8 @@ MRI *MRImakePositive(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -MRI *MRIeraseNegative(MRI *mri_src, MRI *mri_dst) { +MRI *MRIeraseNegative(MRI *mri_src, MRI *mri_dst) +{ int x, y, z; float val; @@ -13396,7 +13704,8 @@ MRI *MRIeraseNegative(MRI *mri_src, MRI *mri_dst) { } return (mri_dst); } -int MRIsampleVolumeSlice(MRI *mri, double x, double y, double z, double *pval, int slice_direction) { +int MRIsampleVolumeSlice(MRI *mri, double x, double y, double z, double *pval, int slice_direction) +{ int OutOfBounds; int xm, xp, ym, yp, zm, zp, width, height, depth; double val, xmd, ymd, xpd, ypd; /* d's are distances */ @@ -13455,7 +13764,8 @@ int MRIsampleVolumeSlice(MRI *mri, double x, double y, double z, double *pval, i #define MRI_VOX_LABEL_PARTIAL_VOLUME_OUTPUT 0 float MRIvoxelsInLabelWithPartialVolumeEffects( - const MRI *mri, const MRI *mri_vals, const int label, MRI *mri_mixing_coef, MRI *mri_nbr_labels) { + const MRI *mri, const MRI *mri_vals, const int label, MRI *mri_mixing_coef, MRI *mri_nbr_labels) +{ enum { maxlabels = 20000 }; float volume; #if (defined(FS_CUDA) && defined(GCAMORPH_ON_GPU)) @@ -13529,7 +13839,8 @@ float MRIvoxelsInLabelWithPartialVolumeEffects( if (border == 0) { volume += vox_vol; - } else { /* compute partial volume */ + } + else { /* compute partial volume */ MRIcomputeLabelNbhd(mri, mri_vals, x, y, z, nbr_label_counts, label_means, 1, maxlabels); MRIcomputeLabelNbhd(mri, mri_vals, x, y, z, label_counts, label_means, 7, maxlabels); @@ -13592,7 +13903,8 @@ float MRIvoxelsInLabelWithPartialVolumeEffects( MRIsetVoxVal(mri_mixing_coef, x, y, z, 0, 1.0); } } - } else { + } + else { // compute partial volume pct mean_nbr = label_means[nbr_label]; pv = (val - mean_nbr) / (mean_label - mean_nbr); @@ -13623,7 +13935,8 @@ float MRIvoxelsInLabelWithPartialVolumeEffects( // return nbr label to caller if (vox_label != label) { MRIsetVoxVal(mri_nbr_labels, x, y, z, 0, vox_label); - } else { + } + else { MRIsetVoxVal(mri_nbr_labels, x, y, z, 0, nbr_label); } } @@ -13639,7 +13952,8 @@ float MRIvoxelsInLabelWithPartialVolumeEffects( return (volume); } -MRI *MRImakeDensityMap(MRI *mri, MRI *mri_vals, int label, MRI *mri_dst, float orig_res) { +MRI *MRImakeDensityMap(MRI *mri, MRI *mri_vals, int label, MRI *mri_dst, float orig_res) +{ float vox_vol, volume, current_res; int x, y, z, nbr_label_counts[MAX_CMA_LABELS], ndilates; int label_counts[MAX_CMA_LABELS], this_label, border; @@ -13729,7 +14043,8 @@ MRI *MRImakeDensityMap(MRI *mri, MRI *mri_vals, int label, MRI *mri_dst, float o #define MRI_MARK_LABEL_BORDER_VOXELS_OUTPUT 0 -MRI *MRImarkLabelBorderVoxels(const MRI *mri_src, MRI *mri_dst, int label, int mark, int six_connected) { +MRI *MRImarkLabelBorderVoxels(const MRI *mri_src, MRI *mri_dst, int label, int mark, int six_connected) +{ #if MRI_MARK_LABEL_BORDER_VOXELS_OUTPUT const unsigned int outputFreq = 10; static unsigned int nCalls = 0; @@ -13789,7 +14104,8 @@ int MRIcomputeLabelNbhd(const MRI *mri_labels, int *label_counts, float *label_means, const int whalf, - const int max_labels) { + const int max_labels) +{ int xi, yi, zi, xk, yk, zk, label; float val; @@ -13836,7 +14152,8 @@ int MRIcomputeLabelNbhd(const MRI *mri_labels, * @param pa output ptr to c_a * @param ps output ptr to c_s */ -void MRIcalcCRASforSampledVolume(MRI *src, MRI *dst, double *pr, double *pa, double *ps) { +void MRIcalcCRASforSampledVolume(MRI *src, MRI *dst, double *pr, double *pa, double *ps) +{ // get the voxel position of the "center" voxel of the dst in the src volume // i.e. sample is 2, then get the voxel position 64 in the src volume // thus it is 128.5 (in the src) for 64 (in the dst) @@ -13930,7 +14247,8 @@ void MRIcalcCRASforSampledVolume(MRI *src, MRI *dst, double *pr, double *pa, dou * @param ps c_s */ void MRIcalcCRASforExtractedVolume( - MRI *src, MRI *dst, int x0, int y0, int z0, int x1, int y1, int z1, double *pr, double *pa, double *ps) { + MRI *src, MRI *dst, int x0, int y0, int z0, int x1, int y1, int z1, double *pr, double *pa, double *ps) +{ double cx, cy, cz; // The "center" voxel position of the // extracted volume in the original voxel position @@ -13978,7 +14296,8 @@ void MRIcalcCRASforExtractedVolume( } // transform is the hires to lowres vox-to-vox transform -void MRIcalcCRASforHiresVolume(MRI *hires, MRI *lowres, MATRIX *vox_xform, double *pr, double *pa, double *ps) { +void MRIcalcCRASforHiresVolume(MRI *hires, MRI *lowres, MATRIX *vox_xform, double *pr, double *pa, double *ps) +{ // get where the center of hires volume goes to in the lowres volume double cx, cy, cz; double dx, dy, dz; @@ -14005,7 +14324,8 @@ void MRIcalcCRASforHiresVolume(MRI *hires, MRI *lowres, MATRIX *vox_xform, doubl // Just rotating the original volume make the non-zero voxels go // outside of the rotated volume. This routine will keep the // center of the rotated volume at the right location. -MRI *MRIsrcTransformedCentered(MRI *src, MRI *dst, MATRIX *stod_voxtovox, int interp_method) { +MRI *MRIsrcTransformedCentered(MRI *src, MRI *dst, MATRIX *stod_voxtovox, int interp_method) +{ double cr, ca, cs; MRI *rotated; MATRIX *stosrotVox; @@ -14047,7 +14367,8 @@ MRI *MRIsrcTransformedCentered(MRI *src, MRI *dst, MATRIX *stod_voxtovox, int in // using the src and orig_dst to modify // the direction cosines and c_(ras) value // so that it will be rotated in the RAS space but no pixel is sampled -MRI *MRITransformedCenteredMatrix(MRI *src, MRI *orig_dst, MATRIX *m_L) { +MRI *MRITransformedCenteredMatrix(MRI *src, MRI *orig_dst, MATRIX *m_L) +{ LTA *lta; MRI *mri_dst; @@ -14058,7 +14379,8 @@ MRI *MRITransformedCenteredMatrix(MRI *src, MRI *orig_dst, MATRIX *m_L) { LTAfree(<a); return (mri_dst); } -MRI *MRITransformedCentered(MRI *src, MRI *orig_dst, LTA *lta) { +MRI *MRITransformedCentered(MRI *src, MRI *orig_dst, LTA *lta) +{ MRI *dst = 0; double cx, cy, cz; double cr, ca, cs; @@ -14257,7 +14579,8 @@ MRI *MRITransformedCentered(MRI *src, MRI *orig_dst, LTA *lta) { return dst; } -int MRIcropBoundingBox(MRI *mri, MRI_REGION *box) { +int MRIcropBoundingBox(MRI *mri, MRI_REGION *box) +{ box->x = MAX(0, box->x); box->y = MAX(0, box->y); box->z = MAX(0, box->z); @@ -14267,7 +14590,8 @@ int MRIcropBoundingBox(MRI *mri, MRI_REGION *box) { return (NO_ERROR); } -MATRIX *MRIgetVoxelToVoxelXform(MRI *mri_src, MRI *mri_dst) { +MATRIX *MRIgetVoxelToVoxelXform(MRI *mri_src, MRI *mri_dst) +{ MATRIX *m_ras2vox_dst, *m_vox2ras_src, *m_vox2vox; m_vox2ras_src = MRIgetVoxelToRasXform(mri_src); @@ -14282,7 +14606,8 @@ MATRIX *MRIgetVoxelToVoxelXform(MRI *mri_src, MRI *mri_dst) { MRIfovCol(mri) - computes the edge-to-edge FOV in the column direction. fov is in mm. -------------------------------------------------------------*/ -float MRIfovCol(MRI *mri) { +float MRIfovCol(MRI *mri) +{ MATRIX *M, *v, *a, *b, *d; float fov; @@ -14319,7 +14644,8 @@ float MRIfovCol(MRI *mri) { get the direction cosines "about right". --------------------------------------------------------------------*/ -int MRIorientationStringToDircos(MRI *mri, char *ostr) { +int MRIorientationStringToDircos(MRI *mri, char *ostr) +{ int c, r = 0; double Mdc[3][3], v = 0; char *errstr; @@ -14390,7 +14716,8 @@ int MRIorientationStringToDircos(MRI *mri, char *ostr) { ok, otherwise is returns a string that lists all the errors it encountered. ---------------------------------------------------------------*/ -char *MRIcheckOrientationString(char *ostr) { +char *MRIcheckOrientationString(char *ostr) +{ int c, nsag = 0, ncor = 0, nax = 0, err; char errstr[1000], *errstrret = NULL; char tmpstr[1000]; @@ -14467,7 +14794,8 @@ char *MRIcheckOrientationString(char *ostr) { important, but upper case is used here. If ras_good_flag == 0, then ostr = ??? and 1 is returned. ------------------------------------------------------------------*/ -int MRIdircosToOrientationString(MRI *mri, char *ostr) { +int MRIdircosToOrientationString(MRI *mri, char *ostr) +{ int c; float Mdc[3][3], sag, cor, ax; @@ -14524,7 +14852,8 @@ int MRIdircosToOrientationString(MRI *mri, char *ostr) { orientation base on the direction cosine. If mri->ras_good_flag=0, then "unknown" is returned. -------------------------------------------------------------------*/ -char *MRIsliceDirectionName(MRI *mri) { +char *MRIsliceDirectionName(MRI *mri) +{ char ostr[4]; char *slicedir = NULL; char *rtstr; @@ -14549,7 +14878,8 @@ char *MRIsliceDirectionName(MRI *mri) { * This is deprecated. Please use MRIextractDistanceMap in fastmarching.h * instead **/ -MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist, int label, float max_dist, int mode, MRI *mri_mask) { +MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist, int label, float max_dist, int mode, MRI *mri_mask) +{ const int width = mri_src->width; const int height = mri_src->height; const int depth = mri_src->depth; @@ -14557,7 +14887,8 @@ MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist, int label, float max_dist if (mri_dist == NULL) { mri_dist = MRIalloc(width, height, depth, MRI_FLOAT); MRIcopyHeader(mri_src, mri_dist); - } else + } + else MRIclear(mri_dist); // these are the modes in fastmarching... @@ -14571,10 +14902,12 @@ MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist, int label, float max_dist // DTRANS_MODE_SIGNED is negative inside and positive outside. This // corresponds to both. mode = both_signed; - } else if (mode == DTRANS_MODE_UNSIGNED) { + } + else if (mode == DTRANS_MODE_UNSIGNED) { // DTRANS_MODE_UNSIGNED is positive inside and positive outside mode = both_unsigned; - } else if (mode == DTRANS_MODE_OUTSIDE) { + } + else if (mode == DTRANS_MODE_OUTSIDE) { // DTRANS_MODE_OUTSIDE is zero inside and positive outside mode = outside; } @@ -14584,7 +14917,8 @@ MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist, int label, float max_dist MRI *mri_tmp = MRIchangeType(mri_src, MRI_FLOAT, 0, 1, 1); mri_dist = MRIextractDistanceMap(mri_tmp, mri_dist, label, max_dist, mode, mri_mask); MRIfree(&mri_tmp); - } else + } + else mri_dist = MRIextractDistanceMap(mri_src, mri_dist, label, max_dist, mode, mri_mask); mri_dist->outside_val = max_dist; @@ -14599,7 +14933,8 @@ MRI *MRIdistanceTransform(MRI *mri_src, MRI *mri_dist, int label, float max_dist using FreeSurfer unpacking (ie, DICOMRead.c), it should only need to be done to mosaics. Note: cannot be done in-place! -------------------------------------------------------------------*/ -MRI *MRIreverseSliceOrder(MRI *invol, MRI *outvol) { +MRI *MRIreverseSliceOrder(MRI *invol, MRI *outvol) +{ int c, r, s1, s2, f; double val; @@ -14630,7 +14965,8 @@ MRI *MRIreverseSliceOrder(MRI *invol, MRI *outvol) { cosines in the header to conform (LIA) coronal direction. Returns NULL if RAS good flag not set or if main axis ambiguous (should not happen).*/ -MRI *MRIconformSliceOrder(MRI *mri) { +MRI *MRIconformSliceOrder(MRI *mri) +{ if (!mri->ras_good_flag) { fprintf(stderr, "MRIconformSliceOrder: direction cosines not set.\n"); return (NULL); @@ -14680,7 +15016,8 @@ MRI *MRIconformSliceOrder(MRI *mri) { #define NDIRS 3 static int dirs[NDIRS][3] = {{0, 0, 1}, {0, 1, 0}, {1, 0, 0}}; -MRI *MRInonMaxSuppress(MRI *mri_src, MRI *mri_sup, float thresh, int thresh_dir) { +MRI *MRInonMaxSuppress(MRI *mri_src, MRI *mri_sup, float thresh, int thresh_dir) +{ int x, y, z, i, max_i; double val, dx, dy, dz, Ix, Iy, Iz; double dot, max_dot, p1_x, p1_y, p1_z, p2_x, p2_y, p2_z; @@ -14764,7 +15101,8 @@ MRI *MRInonMaxSuppress(MRI *mri_src, MRI *mri_sup, float thresh, int thresh_dir) return (mri_sup); } -MRI *MRIextractRegionAndPad(MRI *mri_src, MRI *mri_dst, MRI_REGION *region, int pad) { +MRI *MRIextractRegionAndPad(MRI *mri_src, MRI *mri_dst, MRI_REGION *region, int pad) +{ MRI *mri_tmp; MRI_REGION box; MATRIX *m_src_vox2ras, *m_trans, *m_dst_vox2ras; @@ -14806,7 +15144,8 @@ MRI *MRIextractRegionAndPad(MRI *mri_src, MRI *mri_dst, MRI_REGION *region, int return (mri_dst); } -MRI *MRIsetValuesOutsideRegion(MRI *mri_src, MRI_REGION *region, MRI *mri_dst, float val) { +MRI *MRIsetValuesOutsideRegion(MRI *mri_src, MRI_REGION *region, MRI *mri_dst, float val) +{ int x, y, z; mri_dst = MRIcopy(mri_src, mri_dst); @@ -14825,7 +15164,8 @@ MRI *MRIsetValuesOutsideRegion(MRI *mri_src, MRI_REGION *region, MRI *mri_dst, f return (mri_dst); } -int MRIlabelsInNbhd6(MRI *mri, int x, int y, int z, int label) { +int MRIlabelsInNbhd6(MRI *mri, int x, int y, int z, int label) +{ int xi, yi, zi, xk, yk, zk, count; for (count = 0, zk = -1; zk <= 1; zk++) { @@ -14842,7 +15182,8 @@ int MRIlabelsInNbhd6(MRI *mri, int x, int y, int z, int label) { return (count); } -int MRIlabelsInNbhd(MRI *mri, int x, int y, int z, int whalf, int label) { +int MRIlabelsInNbhd(MRI *mri, int x, int y, int z, int whalf, int label) +{ int xi, yi, zi, xk, yk, zk, count; for (count = 0, zk = -whalf; zk <= whalf; zk++) { @@ -14858,7 +15199,8 @@ int MRIlabelsInNbhd(MRI *mri, int x, int y, int z, int whalf, int label) { return (count); } -int MRIlabelsInPlanarNbhd(MRI *mri, int x, int y, int z, int whalf, int label, int which) { +int MRIlabelsInPlanarNbhd(MRI *mri, int x, int y, int z, int whalf, int label, int which) +{ int xi, yi, zi, xk, yk, zk, count; switch (which) { @@ -14896,7 +15238,8 @@ int MRIlabelsInPlanarNbhd(MRI *mri, int x, int y, int z, int whalf, int label, i return (count); } -MRI *MRImatchMeanIntensity(MRI *mri_source, MRI *mri_target, MRI *mri_source_scaled) { +MRI *MRImatchMeanIntensity(MRI *mri_source, MRI *mri_target, MRI *mri_source_scaled) +{ float mean_source, mean_target, scale; mri_source_scaled = MRIcopy(mri_source, mri_source_scaled); @@ -14924,7 +15267,8 @@ MRI *MRImatchMeanIntensity(MRI *mri_source, MRI *mri_target, MRI *mri_source_sca // NJS calculated scale factor, with newest talairach_with_skull.lta: 2150 // NJS: scale factor must be passed by caller, since it depends on which // transform is being passed-in -double MRIestimateTIV(char *theLtaFile, double theScaleFactor, double *theAtlasDet) { +double MRIestimateTIV(char *theLtaFile, double theScaleFactor, double *theAtlasDet) +{ LTA *atlas_lta; double atlas_det = 0, atlas_icv = 0; @@ -14944,7 +15288,8 @@ double MRIestimateTIV(char *theLtaFile, double theScaleFactor, double *theAtlasD return atlas_icv; } -int MRInormalizeFrames(MRI *mri) { +int MRInormalizeFrames(MRI *mri) +{ int c, r, s, f; double mean, var, val, std; @@ -14975,7 +15320,8 @@ int MRInormalizeFrames(MRI *mri) { } // divides by mean (per voxel across frames) -int MRInormalizeFramesMean(MRI *mri) { +int MRInormalizeFramesMean(MRI *mri) +{ int c, r, s, f; double mean, val; @@ -15003,7 +15349,8 @@ int MRInormalizeFramesMean(MRI *mri) { } // divides by all frames by first -int MRInormalizeFramesFirst(MRI *mri) { +int MRInormalizeFramesFirst(MRI *mri) +{ int c, r, s, f; double val, val1; @@ -15026,7 +15373,8 @@ int MRInormalizeFramesFirst(MRI *mri) { return (ERROR_NONE); } -MRI *MRIzeroMean(MRI *mri_src, MRI *mri_dst) { +MRI *MRIzeroMean(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, f; double mean; @@ -15054,7 +15402,8 @@ MRI *MRIzeroMean(MRI *mri_src, MRI *mri_dst) { /* remove the mean from the timecourse at each voxel. */ -MRI *MRIzeroMeanTimecourse(MRI *mri_src, MRI *mri_dst) { +MRI *MRIzeroMeanTimecourse(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, f; double mean, val; @@ -15077,7 +15426,8 @@ MRI *MRIzeroMeanTimecourse(MRI *mri_src, MRI *mri_dst) { /* compute the mean from the timecourse at each voxel. */ -MRI *MRImeanTimecourse(MRI *mri_src, MRI *mri_dst) { +MRI *MRImeanTimecourse(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, f; double mean; @@ -15101,7 +15451,8 @@ MRI *MRImeanTimecourse(MRI *mri_src, MRI *mri_dst) { /*--------------------------------------------------------------- MRIsort() - sorts the frames of each voxel in ascending order. ---------------------------------------------------------------*/ -MRI *MRIsort(MRI *in, MRI *mask, MRI *sorted) { +MRI *MRIsort(MRI *in, MRI *mask, MRI *sorted) +{ int c, r, s, f, ncols, nrows, nslices, nframes; float m; double *vf; @@ -15151,7 +15502,8 @@ MRI *MRIsort(MRI *in, MRI *mask, MRI *sorted) { CompareDoubles() - simply compares two doubles in a way compatible with qsort. ------------------------------------------------*/ -int CompareDoubles(const void *a, const void *b) { +int CompareDoubles(const void *a, const void *b) +{ double ad, bd; ad = *((double *)a); @@ -15161,7 +15513,8 @@ int CompareDoubles(const void *a, const void *b) { if (ad > bd) return (+1); return (0); } -MRI *MRIaddScalar(MRI *mri_src, MRI *mri_dst, float scalar) { +MRI *MRIaddScalar(MRI *mri_src, MRI *mri_dst, float scalar) +{ float val; int x, y, z, f; @@ -15176,7 +15529,8 @@ MRI *MRIaddScalar(MRI *mri_src, MRI *mri_dst, float scalar) { } return (mri_dst); } -int MRIgeometryMatched(MRI *mri1, MRI *mri2) { +int MRIgeometryMatched(MRI *mri1, MRI *mri2) +{ if (mri1->width != mri2->width || mri1->height != mri2->height || mri1->depth != mri2->depth) return (0); if (!FEQUAL(mri1->xsize, mri2->xsize) || !FEQUAL(mri1->ysize, mri2->ysize) || !FEQUAL(mri1->zsize, mri2->zsize)) @@ -15186,7 +15540,8 @@ int MRIgeometryMatched(MRI *mri1, MRI *mri2) { return (1); } -MRI *MRIfillHoles(MRI *mri_src, MRI *mri_fill, int thresh) { +MRI *MRIfillHoles(MRI *mri_src, MRI *mri_fill, int thresh) +{ int nfilled, ntotal = 0, cnt, cntmax = thresh; int im0, x0, i0, z, i, x; int v, vmax, ylim0, ylim1, xlim0, xlim1; @@ -15229,7 +15584,8 @@ MRI *MRIfillHoles(MRI *mri_src, MRI *mri_fill, int thresh) { if (Gdiag & DIAG_SHOW) fprintf(stderr, "total of %d holes filled\n", ntotal); return (mri_fill); } -int *MRIhistogramLabels(MRI *mri, int *counts, int max_label) { +int *MRIhistogramLabels(MRI *mri, int *counts, int max_label) +{ int x, y, z, label; if (counts == NULL) counts = (int *)calloc(max_label + 1, sizeof(*counts)); @@ -15243,7 +15599,8 @@ int *MRIhistogramLabels(MRI *mri, int *counts, int max_label) { return (counts); } -int MRIlabelBoundingBox(MRI *mri, int label, MRI_REGION *region) { +int MRIlabelBoundingBox(MRI *mri, int label, MRI_REGION *region) +{ int x, y, z, l, x1, y1, z1; region->x = mri->width; @@ -15274,7 +15631,8 @@ int MRIlabelBoundingBox(MRI *mri, int label, MRI_REGION *region) { MRIcopyVolGeomToMRI - copies the volume geometry passed in into the MRI structure. -------------------------------------------------------------------*/ -int MRIcopyVolGeomToMRI(MRI *mri, const VOL_GEOM *vg) { +int MRIcopyVolGeomToMRI(MRI *mri, const VOL_GEOM *vg) +{ mri->xsize = vg->xsize; mri->ysize = vg->ysize; mri->zsize = vg->zsize; @@ -15296,7 +15654,8 @@ int MRIcopyVolGeomToMRI(MRI *mri, const VOL_GEOM *vg) { MRIcopyVolGeomToMRI - copies the volume geometry passed in into the MRI structure. -------------------------------------------------------------------*/ -int MRIcopyVolGeomFromMRI(const MRI *mri, VOL_GEOM *vg) { +int MRIcopyVolGeomFromMRI(const MRI *mri, VOL_GEOM *vg) +{ vg->xsize = mri->xsize; vg->ysize = mri->ysize; vg->zsize = mri->zsize; @@ -15319,7 +15678,8 @@ int MRIcopyVolGeomFromMRI(const MRI *mri, VOL_GEOM *vg) { strcpy(vg->fname, mri->fname); return (NO_ERROR); } -int MRIfillRegion(MRI *mri, int x, int y, int z, float fill_val, int whalf) { +int MRIfillRegion(MRI *mri, int x, int y, int z, float fill_val, int whalf) +{ int xi, xk, yi, yk, zi, zk; for (xk = -whalf; xk <= whalf; xk++) { @@ -15340,7 +15700,8 @@ MRI *MRImatchIntensityRatio(MRI *mri_source, double min_scale, double max_scale, double low_thresh, - double high_thresh) { + double high_thresh) +{ HISTOGRAM *h; int x, y, z, bin, peak; float val_source, val_target, ratio; @@ -15387,7 +15748,8 @@ MRI *MRImatchIntensityRatio(MRI *mri_source, return (mri_matched); } -int MRIcountThreshInNbhd(MRI *mri, int wsize, int x, int y, int z, float thresh) { +int MRIcountThreshInNbhd(MRI *mri, int wsize, int x, int y, int z, float thresh) +{ int xk, yk, zk, xi, yi, zi, whalf, total; whalf = (wsize - 1) / 2; @@ -15403,7 +15765,8 @@ int MRIcountThreshInNbhd(MRI *mri, int wsize, int x, int y, int z, float thresh) } return (total); } -int MRIfillBox(MRI *mri, MRI_REGION *box, float fillval) { +int MRIfillBox(MRI *mri, MRI_REGION *box, float fillval) +{ int x, y, z, xmin, xmax, ymin, ymax, zmin, zmax; xmin = MAX(0, box->x); @@ -15418,7 +15781,8 @@ int MRIfillBox(MRI *mri, MRI_REGION *box, float fillval) { return (NO_ERROR); } -MRI *MRIcloneDifferentType(MRI *mri_src, int type) { +MRI *MRIcloneDifferentType(MRI *mri_src, int type) +{ MRI *mri_dst; if (type == mri_src->type) return (MRIclone(mri_src, NULL)); @@ -15428,7 +15792,8 @@ MRI *MRIcloneDifferentType(MRI *mri_src, int type) { return (mri_dst); } -double MRImaxNorm(MRI *mri) { +double MRImaxNorm(MRI *mri) +{ double max_norm, norm, val; int x, y, z, f; @@ -15446,11 +15811,13 @@ double MRImaxNorm(MRI *mri) { } static int compare_sort_mri(const void *plp1, const void *plp2); -typedef struct { +typedef struct +{ unsigned char x, y, z, val; } SORT_VOXEL; -static int compare_sort_mri(const void *psv1, const void *psv2) { +static int compare_sort_mri(const void *psv1, const void *psv2) +{ SORT_VOXEL *sv1, *sv2; sv1 = (SORT_VOXEL *)psv1; @@ -15463,7 +15830,8 @@ static int compare_sort_mri(const void *psv1, const void *psv2) { return (0); } -int MRIorderIndices(MRI *mri, short *x_indices, short *y_indices, short *z_indices) { +int MRIorderIndices(MRI *mri, short *x_indices, short *y_indices, short *z_indices) +{ int width, height, depth, nindices, index, x, y, z; SORT_VOXEL *sort_voxels; @@ -15495,7 +15863,8 @@ int MRIorderIndices(MRI *mri, short *x_indices, short *y_indices, short *z_indic free(sort_voxels); return (NO_ERROR); } -int MRIcomputeVoxelPermutation(MRI *mri, short *x_indices, short *y_indices, short *z_indices) { +int MRIcomputeVoxelPermutation(MRI *mri, short *x_indices, short *y_indices, short *z_indices) +{ int width, height, depth, tmp, nindices, i, index; width = mri->width, height = mri->height; @@ -15524,7 +15893,8 @@ int MRIcomputeVoxelPermutation(MRI *mri, short *x_indices, short *y_indices, sho } return (NO_ERROR); } -MRI *MRImaskZero(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) { +MRI *MRImaskZero(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) +{ int x, y, z; if (mri_dst == NULL) mri_dst = MRIclone(mri_src, NULL); @@ -15540,7 +15910,8 @@ MRI *MRImaskZero(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) { return (mri_dst); } -const char *MRItype2str(int type) { +const char *MRItype2str(int type) +{ switch (type) { case MRI_UCHAR: return ("uchar"); @@ -15561,7 +15932,8 @@ const char *MRItype2str(int type) { } #define MAX_VOX 5000 #define MAX_FOV 300 -int MRIfindSliceWithMostStructure(MRI *mri_aseg, int slice_direction, int label) { +int MRIfindSliceWithMostStructure(MRI *mri_aseg, int slice_direction, int label) +{ int max_slice, max_vox, cor_vox[MAX_VOX], hor_vox[MAX_VOX], sag_vox[MAX_VOX], x, y, z, i, vox = 0; float r, a, s, vsize; VECTOR *v_ras, *v_vox; @@ -15620,7 +15992,8 @@ int MRIfindSliceWithMostStructure(MRI *mri_aseg, int slice_direction, int label) } return (max_slice); } -double MRIrmsDiff(MRI *mri1, MRI *mri2) { +double MRIrmsDiff(MRI *mri1, MRI *mri2) +{ double rms, val1, val2; int x, y, z, nvox; @@ -15640,7 +16013,8 @@ double MRIrmsDiff(MRI *mri1, MRI *mri2) { // compute root mean square of 'in', which is assumed to be multi-framed // writes to 'out' -void MRIrms(MRI *in, MRI *out) { +void MRIrms(MRI *in, MRI *out) +{ int f, z, y, x; int width = in->width; int height = in->height; @@ -15673,7 +16047,8 @@ void MRIrms(MRI *in, MRI *out) { } } -int MRImaskLabel(MRI *mri_src, MRI *mri_dst, MRI *mri_labeled, int label_to_mask, float out_val) { +int MRImaskLabel(MRI *mri_src, MRI *mri_dst, MRI *mri_labeled, int label_to_mask, float out_val) +{ int x, y, z, label; if (mri_dst != mri_src) mri_dst = MRIcopy(mri_src, mri_dst); @@ -15685,7 +16060,8 @@ int MRImaskLabel(MRI *mri_src, MRI *mri_dst, MRI *mri_labeled, int label_to_mask } return (NO_ERROR); } -int MRIcomputeVolumeFractions(MRI *mri_src, MATRIX *m_vox2vox, MRI *mri_seg, MRI *mri_fractions) { +int MRIcomputeVolumeFractions(MRI *mri_src, MATRIX *m_vox2vox, MRI *mri_seg, MRI *mri_fractions) +{ int x, y, z, xs, ys, zs, label; VECTOR *v1, *v2; MRI *mri_counts; @@ -15724,7 +16100,8 @@ int MRIcomputeVolumeFractions(MRI *mri_src, MATRIX *m_vox2vox, MRI *mri_seg, MRI if (label >= 0 && label <= mri_fractions->nframes) { val = MRIgetVoxVal(mri_fractions, xs, ys, zs, label - 1); // labels are frame+1 MRIsetVoxVal(mri_fractions, xs, ys, zs, label - 1, val + 1); - } else + } + else DiagBreak(); } } @@ -15741,7 +16118,8 @@ int MRIcomputeVolumeFractions(MRI *mri_src, MATRIX *m_vox2vox, MRI *mri_seg, MRI val = MRIgetVoxVal(mri_fractions, x, y, z, label); MRIsetVoxVal(mri_fractions, x, y, z, label, val / count); } - } else // sample in other direction + } + else // sample in other direction { V3_X(v1) = x; V3_Y(v1) = y; @@ -15767,7 +16145,8 @@ int MRIcomputeVolumeFractions(MRI *mri_src, MATRIX *m_vox2vox, MRI *mri_seg, MRI return (NO_ERROR); } -float MRImaxInRegion(MRI *mri, int x, int y, int z, int whalf) { +float MRImaxInRegion(MRI *mri, int x, int y, int z, int whalf) +{ int xi, yi, zi, xk, yk, zk; float max_val, val; @@ -15784,7 +16163,8 @@ float MRImaxInRegion(MRI *mri, int x, int y, int z, int whalf) { } return (max_val); } -MRI *MRIaverageFrames(MRI *mri_src, MRI *mri_dst, int start_frame, int end_frame) { +MRI *MRIaverageFrames(MRI *mri_src, MRI *mri_dst, int start_frame, int end_frame) +{ int x, y, z, f, nframes; float sum; @@ -15805,7 +16185,8 @@ MRI *MRIaverageFrames(MRI *mri_src, MRI *mri_dst, int start_frame, int end_frame return (mri_dst); } -MRI *MRIaddToFrame(MRI *mri_src, MRI *mri_to_add, MRI *mri_dst, int src_frame_no, int dst_frame_no) { +MRI *MRIaddToFrame(MRI *mri_src, MRI *mri_to_add, MRI *mri_dst, int src_frame_no, int dst_frame_no) +{ int x, y, z; float val; @@ -15821,7 +16202,8 @@ MRI *MRIaddToFrame(MRI *mri_src, MRI *mri_to_add, MRI *mri_dst, int src_frame_no return (mri_dst); } -MRI *MRIcomputeMeanAndStandardDeviation(MRI *mri_src, MRI *mri_dst, int dof) { +MRI *MRIcomputeMeanAndStandardDeviation(MRI *mri_src, MRI *mri_dst, int dof) +{ int x, y, z; float mean, sum_sq, std; @@ -15843,7 +16225,8 @@ MRI *MRIcomputeMeanAndStandardDeviation(MRI *mri_src, MRI *mri_dst, int dof) { return (mri_dst); } -MRI *MRIdivideFrames(MRI *mri1, MRI *mri2, int frame1, int frame2, MRI *mri_dst) { +MRI *MRIdivideFrames(MRI *mri1, MRI *mri2, int frame1, int frame2, MRI *mri_dst) +{ int x, y, z; float val1, val2, val; @@ -15865,7 +16248,8 @@ MRI *MRIdivideFrames(MRI *mri1, MRI *mri2, int frame1, int frame2, MRI *mri_dst) return (mri_dst); } -MATRIX *MRIcopyFramesToMatrixRows(MRI *mri, MATRIX *m_dst, int start_frame, int nframes, int dst_row) { +MATRIX *MRIcopyFramesToMatrixRows(MRI *mri, MATRIX *m_dst, int start_frame, int nframes, int dst_row) +{ int x, y, z, i, r, f; if (m_dst == NULL) m_dst = MatrixAlloc(nframes, mri->width * mri->height * mri->depth, MATRIX_REAL); @@ -15886,7 +16270,8 @@ MATRIX *MRIcopyFramesToMatrixRows(MRI *mri, MATRIX *m_dst, int start_frame, int // This function computes the means and covariances of a particular label // Within a given nbhd of a voxel with the coordinates x y z int MRIcomputeNbhdMeansandCovariances( - MRI *mri_inputs, MRI *mri_labeled, int label, int x, int y, int z, int nbhd, MATRIX **p_mcov, VECTOR **p_vmeans) { + MRI *mri_inputs, MRI *mri_labeled, int label, int x, int y, int z, int nbhd, MATRIX **p_mcov, VECTOR **p_vmeans) +{ int a, size, n, xi, yi, zi, xk, yk, zk; MATRIX *m_cov_total, *m_data; VECTOR *v_means; @@ -15936,7 +16321,8 @@ int MRIcomputeNbhdMeansandCovariances( return (NO_ERROR); } -int MRIcomputeWMMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) { +int MRIcomputeWMMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) +{ int a, h, x, y, z, n, wm_label; MATRIX *m_data, *m_data_final, *cov_final; VECTOR *means_final; @@ -15953,7 +16339,8 @@ int MRIcomputeWMMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX ** for (h = 0; h <= 1; h++) { if (h == 0) { wm_label = Right_Cerebral_White_Matter; - } else { + } + else { wm_label = Left_Cerebral_White_Matter; } @@ -15985,7 +16372,8 @@ int MRIcomputeWMMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX ** } int MRIcomputeLabelMeansandCovariances( - MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans, int *labels, int nbhd) { + MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans, int *labels, int nbhd) +{ int a, x, y, z, l, n, length; length = sizeof(labels) / sizeof(int); length = 1; @@ -16012,7 +16400,8 @@ int MRIcomputeLabelMeansandCovariances( } a++; } - } else { + } + else { for (n = 0; n < mri_inputs->nframes; n++) { m_data->rptr[a][n + 1] = MRIgetVoxVal(mri_inputs, x, y, z, n); } @@ -16034,7 +16423,8 @@ int MRIcomputeLabelMeansandCovariances( } int MRIcomputeLabelMeansandCovariances2( - MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans, int *labels, int nlabels, int nbhd) { + MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans, int *labels, int nlabels, int nbhd) +{ int a, x, y, z, l, n; a = 1; MATRIX *m_data, *m_data_final, *cov_final, *means_final; @@ -16058,7 +16448,8 @@ int MRIcomputeLabelMeansandCovariances2( } a++; } - } else { + } + else { for (n = 0; n < mri_inputs->nframes; n++) { m_data->rptr[a][n + 1] = MRIgetVoxVal(mri_inputs, x, y, z, n); } @@ -16079,7 +16470,8 @@ int MRIcomputeLabelMeansandCovariances2( return (NO_ERROR); } -int MRIcomputeWMSAMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) { +int MRIcomputeWMSAMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) +{ int a, h, x, y, z, n, wmsa_label; MATRIX *m_data, *m_data_final, *cov_final; VECTOR *means_final; @@ -16096,7 +16488,8 @@ int MRIcomputeWMSAMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX for (h = 0; h <= 1; h++) { if (h == 0) { wmsa_label = Right_WM_hypointensities; - } else { + } + else { wmsa_label = Left_WM_hypointensities; } @@ -16123,7 +16516,8 @@ int MRIcomputeWMSAMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX return (NO_ERROR); } -int MRIcomputeCaudateMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) { +int MRIcomputeCaudateMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) +{ int a, h, x, y, z, n, caudate_label; MATRIX *m_data, *m_data_final, *cov_final; VECTOR *means_final; @@ -16140,7 +16534,8 @@ int MRIcomputeCaudateMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATR for (h = 0; h <= 1; h++) { if (h == 0) { caudate_label = Right_Caudate; - } else { + } + else { caudate_label = Left_Caudate; } @@ -16169,7 +16564,8 @@ int MRIcomputeCaudateMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATR return (NO_ERROR); } -int MRIcomputeVentMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) { +int MRIcomputeVentMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX **p_mcov, VECTOR **p_vmeans) +{ int a, h, x, y, z, n, vent_label; MATRIX *m_data, *m_data_final, *cov_final; VECTOR *means_final; @@ -16186,7 +16582,8 @@ int MRIcomputeVentMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX for (h = 0; h <= 1; h++) { if (h == 0) { vent_label = Right_Lateral_Ventricle; - } else { + } + else { vent_label = Left_Lateral_Ventricle; } @@ -16225,7 +16622,8 @@ int MRIcomputeVentMeansandCovariances(MRI *mri_inputs, MRI *mri_labeled, MATRIX second frame is assumed to be a count (that is, it was a previously created mosaic. */ -MRI *MRImakeMosaic(MRI **mri, int nimages, int rectify) { +MRI *MRImakeMosaic(MRI **mri, int nimages, int rectify) +{ float x0, x1, y0, y1, z0, z1, sum, minval; MRI *mri_mosaic; int i, width, height, depth, x, y, z, xd, yd, zd, count; @@ -16318,7 +16716,8 @@ MRI *MRImakeMosaic(MRI **mri, int nimages, int rectify) { old_count = (int)MRIgetVoxVal(mri[i], x, y, z, 1); count += old_count; sum += (old_count * val); - } else { + } + else { count++; sum += val; } @@ -16358,7 +16757,8 @@ MRI *MRImakeMosaic(MRI **mri, int nimages, int rectify) { VectorFree(&v_vox2); return (mri_mosaic); } -double MRImeanAndVarianceInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame, double *pvar) { +double MRImeanAndVarianceInNbhd(MRI *mri, int wsize, int x, int y, int z, int frame, double *pvar) +{ int xk, yk, zk, xi, yi, zi, whalf, total; double mean, val, var; @@ -16387,7 +16787,8 @@ double MRImeanAndVarianceInNbhd(MRI *mri, int wsize, int x, int y, int z, int fr Description: corrupt an image with additive zero mean gaussian noise. ----------------------------------------------------------------------*/ -MRI *MRIaddNoise(MRI *mri_in, MRI *mri_out, float amp) { +MRI *MRIaddNoise(MRI *mri_in, MRI *mri_out, float amp) +{ float out, gnoise; int x, y, z, f; @@ -16405,7 +16806,8 @@ MRI *MRIaddNoise(MRI *mri_in, MRI *mri_out, float amp) { return (mri_out); } -MRI *MRIcombineDistanceTransforms(MRI *mri_src1, MRI *mri_src2, MRI *mri_dst) { +MRI *MRIcombineDistanceTransforms(MRI *mri_src1, MRI *mri_src2, MRI *mri_dst) +{ int x, y, z, f; float val1, val2; @@ -16420,11 +16822,13 @@ MRI *MRIcombineDistanceTransforms(MRI *mri_src1, MRI *mri_src2, MRI *mri_dst) { val1 = MRIgetVoxVal(mri_src1, x, y, z, f); val2 = MRIgetVoxVal(mri_src2, x, y, z, f); if (val2 < 0 && val1 > 0) { - val1 = val2; // in the interior of 1 - } else if (val2 > 0 && val1 > val2) // exterior of both, but closer to border of 2 + val1 = val2; // in the interior of 1 + } + else if (val2 > 0 && val1 > val2) // exterior of both, but closer to border of 2 { val1 = val2; - } else if (val2 < 0 && val1 < val2) { + } + else if (val2 < 0 && val1 < val2) { val1 = val2; // interior of both, but closer to border of 2 } diff --git a/utils/mri2.c b/utils/mri2.c index 6c4fd3b773a..d3d28af34fe 100644 --- a/utils/mri2.c +++ b/utils/mri2.c @@ -70,7 +70,8 @@ mri_load_bvolume() -- same as bf_ldvolume() but returns an MRI structure instead of a BF_DATA. See bfileio.h. -------------------------------------------------------------*/ -MRI *mri_load_bvolume(char *bfstem) { +MRI *mri_load_bvolume(char *bfstem) +{ BF_DATA *bfvol; MRI *vol; int r, c, s, f; @@ -108,7 +109,8 @@ MRI *mri_load_bvolume(char *bfstem) { mri_save_as_bvolume() - same as bf_svvolume() but takes an MRI sturucture as input. See also bfileio.h. -------------------------------------------------------------*/ -int mri_save_as_bvolume(MRI *vol, char *stem, int svendian, int svtype) { +int mri_save_as_bvolume(MRI *vol, char *stem, int svendian, int svtype) +{ BF_DATA *bfvol; int r, c, s, f; float val; @@ -138,7 +140,8 @@ int mri_save_as_bvolume(MRI *vol, char *stem, int svendian, int svtype) { /*------------------------------------------------------------- mri_load_bvolume_frame() -- loads a single frame as an MRI. -------------------------------------------------------------*/ -MRI *mri_load_bvolume_frame(char *bfstem, int frameno) { +MRI *mri_load_bvolume_frame(char *bfstem, int frameno) +{ BF_DATA *bfvol; MRI *vol; int r, c, s; @@ -191,7 +194,8 @@ MRI *mri_load_bvolume_frame(char *bfstem, int frameno) { of unsigned char), the MRI can be rescaled to 0-255 by setting the rescale flag to non-zero. See also corio.h. -------------------------------------------------------------*/ -int mri_save_as_cor(MRI *vol, char *cordir, int frame, int rescale) { +int mri_save_as_cor(MRI *vol, char *cordir, int frame, int rescale) +{ unsigned char **COR; int r, c, s; int rmax, cmax, smax; @@ -248,7 +252,8 @@ int mri_save_as_cor(MRI *vol, char *cordir, int frame, int rescale) { outvol if non-null, otherwise allocates an output volume. Can be done in-place. Rescales across all frames. ------------------------------------------------------------*/ -MRI *mri_rescale(MRI *vol, float min, float max, MRI *outvol) { +MRI *mri_rescale(MRI *vol, float min, float max, MRI *outvol) +{ int r, c, s, f; float val, volmin, volmax, range; // float volrange; @@ -298,7 +303,8 @@ MRI *mri_rescale(MRI *vol, float min, float max, MRI *outvol) { /*------------------------------------------------------------ mri_minmax() -- gets min and max values of volume ------------------------------------------------------------*/ -int mri_minmax(MRI *vol, float *min, float *max) { +int mri_minmax(MRI *vol, float *min, float *max) +{ int r, c, s, f; float val; @@ -326,7 +332,8 @@ int mri_minmax(MRI *vol, float *min, float *max) { squared before spatial averaging and then square-rooted before saving again. -----------------------------------------------------------*/ -int mri_framepower(MRI *vol, float *framepower) { +int mri_framepower(MRI *vol, float *framepower) +{ int r, c, s, f; float val; @@ -384,7 +391,8 @@ int mri_framepower(MRI *vol, float *framepower) { number of voxels in vol that meet the threshold criteria (ie, the number of 1's in volbin). -----------------------------------------------------------------*/ -MRI *mri_binarize(MRI *vol, float thresh, char *tail, int invert, MRI *volbin, int *nover) { +MRI *mri_binarize(MRI *vol, float thresh, char *tail, int invert, MRI *volbin, int *nover) +{ int r, c, s, f, tailcode; float val; int b, onval, offval; @@ -409,14 +417,16 @@ MRI *mri_binarize(MRI *vol, float thresh, char *tail, int invert, MRI *volbin, i if (voltmp == NULL) return (NULL); MRIcopyHeader(vol, voltmp); MRIcopyPulseParameters(vol, voltmp); - } else + } + else voltmp = volbin; if (!invert) { onval = 1; offval = 0; printf("NOT INVERTING\n"); - } else { + } + else { onval = 0; offval = 1; printf("INVERTING\n"); @@ -454,7 +464,8 @@ MRI *mri_binarize(MRI *vol, float thresh, char *tail, int invert, MRI *volbin, i /*-------------------------------------------------------- mri_load_cor_as_float() --------------------------------------------------------*/ -MRI *mri_load_cor_as_float(char *cordir) { +MRI *mri_load_cor_as_float(char *cordir) +{ MRI *ucvol; MRI *vol; int r, c, s; @@ -483,7 +494,8 @@ MRI *mri_load_cor_as_float(char *cordir) { } /* ---------------------------------------- */ /* not tested */ -MRI *mri_load_wfile(char *wfile) { +MRI *mri_load_wfile(char *wfile) +{ FILE *fp; int i, ilat, num, vtx, nvertices; int *vtxnum; @@ -526,7 +538,8 @@ MRI *mri_load_wfile(char *wfile) { mri_sizeof() - returns the size of the data type of the MRI volume (in number of bytes). ------------------------------------------------------------*/ -size_t mri_sizeof(MRI *vol) { +size_t mri_sizeof(MRI *vol) +{ size_t bytes = 0; switch (vol->type) { @@ -552,7 +565,8 @@ size_t mri_sizeof(MRI *vol) { /*------------------------------------------------------------ mri_reshape() -- ------------------------------------------------------------*/ -MRI *mri_reshape(MRI *vol, int ncols, int nrows, int nslices, int nframes) { +MRI *mri_reshape(MRI *vol, int ncols, int nrows, int nslices, int nframes) +{ MRI *outvol; int r, c, s, f, nv1, nv2; int r2, c2, s2, f2; @@ -631,7 +645,8 @@ MRI *mri_reshape(MRI *vol, int ncols, int nrows, int nslices, int nframes) { \brief Reshapes the MRI structure to have nvox columns, 1 row, and 1 slice; does not change the number of frames. */ -MRI *MRIreshape1d(MRI *src, MRI *trg) { +MRI *MRIreshape1d(MRI *src, MRI *trg) +{ int ncols, nrows, nslices, nvox, nframes; ncols = src->width; nrows = src->height; @@ -665,7 +680,8 @@ MRI *MRIreshape1d(MRI *src, MRI *trg) { param is a generic parameter. For sinc, param is the hw parameter, otherwise, it currently has no meaning. ---------------------------------------------------------------*/ -int MRIvol2Vol(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param) { +int MRIvol2Vol(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param) +{ #ifdef FS_CUDA int cudaReturn; #else @@ -841,7 +857,8 @@ int MRIvol2Vol(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param) { return (0); } -int MRIvol2VolR(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param, MATRIX *RRot) { +int MRIvol2VolR(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param, MATRIX *RRot) +{ int ct, rt, st, f; int ics, irs, iss; float fcs, frs, fss; @@ -939,7 +956,8 @@ int MRIvol2VolR(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param, for (col = 1; col <= 3; col++) { MRIsetVoxVal(targ, ct, rt, st, col - 1, VECTOR_ELT(RotVector, col)); } - } else // if(nframes == 9) + } + else // if(nframes == 9) { int row, col; for (row = 1; row <= 3; row++) @@ -980,7 +998,8 @@ int MRIvol2VolR(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param, \param InterCode - SAMPLE_NEAREST, SAMPLE_TRILINEAR, SAMPLE_SINC. Sinc probably does not work. */ -int MRIvol2VolTkReg(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, float param) { +int MRIvol2VolTkReg(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, float param) +{ MATRIX *vox2vox = NULL; MATRIX *Tmov, *invTmov, *Ttarg; int err; @@ -993,7 +1012,8 @@ int MRIvol2VolTkReg(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, float p // vox2vox = invTmov*R*Ttarg vox2vox = MatrixMultiply(invTmov, Rtkreg, vox2vox); MatrixMultiply(vox2vox, Ttarg, vox2vox); - } else + } + else vox2vox = NULL; // resample @@ -1017,7 +1037,8 @@ int MRIvol2VolTkReg(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, float p \param targ - target volume \param Vt2s - vox2vox transform from target to source (can be NULL) */ -MRI *MRIvol2VolTLKernel(MRI *src, MRI *targ, MATRIX *Vt2s) { +MRI *MRIvol2VolTLKernel(MRI *src, MRI *targ, MATRIX *Vt2s) +{ int ct, rt, st, f; int ics, irs, iss; float fcs, frs, fss; @@ -1087,7 +1108,8 @@ MRI *MRIvol2VolTLKernel(MRI *src, MRI *targ, MATRIX *Vt2s) { non-zero voxels in the mask is created. */ -MRI *MRImaskAndUpsample(MRI *src, MRI *mask, int UpsampleFactor, int nPad, int DoConserve, LTA **src2out) { +MRI *MRImaskAndUpsample(MRI *src, MRI *mask, int UpsampleFactor, int nPad, int DoConserve, LTA **src2out) +{ MRI *srcmask, *srcus; MRI_REGION *region; @@ -1110,7 +1132,8 @@ MRI *MRImaskAndUpsample(MRI *src, MRI *mask, int UpsampleFactor, int nPad, int D srcus = MRIupsampleNConserve(srcmask, NULL, UpsampleFactor); else srcus = MRIupsampleN(srcmask, NULL, UpsampleFactor); - } else + } + else srcus = srcmask; *src2out = TransformRegDat2LTA(src, srcus, NULL); // src2srcus @@ -1127,7 +1150,8 @@ MRI *MRImaskAndUpsample(MRI *src, MRI *mask, int UpsampleFactor, int nPad, int D 3 slices mismatch 4 frames mismatch - note: frameflag must = 1 to check frames ---------------------------------------------------------------*/ -int MRIdimMismatch(const MRI *v1, const MRI *v2, int frameflag) { +int MRIdimMismatch(const MRI *v1, const MRI *v2, int frameflag) +{ if (v1->width != v2->width) return (1); if (v1->height != v2->height) return (2); if (v1->depth != v2->depth) return (3); @@ -1190,7 +1214,8 @@ int MRIfdr2vwth(MRI **vollist, int log10flag, MRI **masklist, double *vwth, - MRI **ovollist) { + MRI **ovollist) +{ MRI *vol, *mask, *ovol; double *p = NULL, val = 0.0, valnull = 0.0, maskval; int Nv, np, c, r, s, frame, nthvol; @@ -1355,7 +1380,8 @@ int MRIfdr2vwth(MRI **vollist, in the mask are less than 0.5 are excluded from the computation of the covariance matrix, and Nv becomes the number points in the mask. ------------------------------------------------------------------*/ -MATRIX *MRIcovarianceMatrix(MRI *mri, MRI *mask) { +MATRIX *MRIcovarianceMatrix(MRI *mri, MRI *mask) +{ int UseMask = 0, nmask, f1, f2; int r, c, s; double sum, v1, v2; @@ -1378,7 +1404,8 @@ MATRIX *MRIcovarianceMatrix(MRI *mri, MRI *mask) { return (NULL); } UseMask = 1; - } else { + } + else { // Otherwise use all voxels/vertices nmask = mri->width * mri->height * mri->depth; UseMask = 0; @@ -1420,7 +1447,8 @@ MATRIX *MRIcovarianceMatrix(MRI *mri, MRI *mask) { non-null, uses only the voxels for which mask>0.5. When complete, D = U*S*V'; -------------------------------------------------------------------*/ -int MRIpca(MRI *D, MATRIX **pU, VECTOR **pS, MRI **pV, MRI *mask) { +int MRIpca(MRI *D, MATRIX **pU, VECTOR **pS, MRI **pV, MRI *mask) +{ int dim, dim_real, nvoxels, c, r, s, f, UseMask, nmask = 0; MATRIX *M, *VV, *UinvS, *Fd, *Fv; VECTOR *S2; @@ -1436,7 +1464,8 @@ int MRIpca(MRI *D, MATRIX **pU, VECTOR **pS, MRI **pV, MRI *mask) { for (r = 0; r < D->height; r++) for (s = 0; s < D->depth; s++) if (UseMask && MRIgetVoxVal(mask, c, r, s, 0) > 0.5) nmask++; - } else { + } + else { UseMask = 0; nmask = nvoxels; } @@ -1520,7 +1549,8 @@ int MRIpca(MRI *D, MATRIX **pU, VECTOR **pS, MRI **pV, MRI *mask) { (3) var spanned by 1-nth EVs, (3) percent var spanned by nth, (4) perent var spanned by 1-nth EVs, --------------------------------------------------------------*/ -int PrintPCAStats(FILE *fp, MATRIX *Spca) { +int PrintPCAStats(FILE *fp, MATRIX *Spca) +{ int n; double totvar, v, vsum; @@ -1540,7 +1570,8 @@ int PrintPCAStats(FILE *fp, MATRIX *Spca) { WritePCAStats() - writes pca summary statistics to a file. see PrintPCAStats() for more info. --------------------------------------------------------------*/ -int WritePCAStats(char *fname, MATRIX *Spca) { +int WritePCAStats(char *fname, MATRIX *Spca) +{ FILE *fp; fp = fopen(fname, "w"); if (fp == NULL) { @@ -1553,7 +1584,8 @@ int WritePCAStats(char *fname, MATRIX *Spca) { /*--------------------------------------------------------------- MRIsqrt() - computes sqrt(fabs(v)). Calls MRIsquraRoot(). ---------------------------------------------------------------*/ -MRI *MRIsqrt(MRI *invol, MRI *outvol) { +MRI *MRIsqrt(MRI *invol, MRI *outvol) +{ outvol = MRIsquareRoot(invol, NULL, outvol); return (outvol); } @@ -1570,7 +1602,8 @@ MRI *MRIsqrt(MRI *invol, MRI *outvol) { it gets the data type of mri1. If it is specified, it can be any data type. */ -MRI *MRImax(MRI *mri1, MRI *mri2, MRI *out) { +MRI *MRImax(MRI *mri1, MRI *mri2, MRI *out) +{ int c, r, s, f, n, ncols, nrows, nslices, nframes; void *pmri1 = NULL, *pmri2 = NULL, *pout = NULL; double v1 = 0, v2 = 0, v; @@ -1632,7 +1665,8 @@ MRI *MRImax(MRI *mri1, MRI *mri2, MRI *out) { MRImaxAbsDiff() - finds the voxel where the two volumes differ the most. ---------------------------------------------------------------*/ -double MRImaxAbsDiff(MRI *vol1, MRI *vol2, int *cmax, int *rmax, int *smax, int *fmax) { +double MRImaxAbsDiff(MRI *vol1, MRI *vol2, int *cmax, int *rmax, int *smax, int *fmax) +{ int c, r, s, f; double v1, v2, maxdiff; @@ -1657,7 +1691,8 @@ double MRImaxAbsDiff(MRI *vol1, MRI *vol2, int *cmax, int *rmax, int *smax, int return (maxdiff); } /* --------------------------------------------------------------- */ -MRI *MRImultiplyConst(MRI *src, double vconst, MRI *dst) { +MRI *MRImultiplyConst(MRI *src, double vconst, MRI *dst) +{ int r, c, s, f; double v; @@ -1680,7 +1715,8 @@ MRI *MRImultiplyConst(MRI *src, double vconst, MRI *dst) { return (dst); } /* --------------------------------------------------------------- */ -MRI *MRIaddConst(MRI *src, double vconst, MRI *dst) { +MRI *MRIaddConst(MRI *src, double vconst, MRI *dst) +{ int r, c, s, f; double v; @@ -1711,7 +1747,8 @@ MRI *MRIaddConst(MRI *src, double vconst, MRI *dst) { it does not meet the frame criteria in mri, then it will be set to 0. Note: if mask is not null, it's values will be changed. --------------------------------------------------------------------*/ -MRI *MRIframeBinarize(MRI *mri, double thresh, MRI *mask) { +MRI *MRIframeBinarize(MRI *mri, double thresh, MRI *mask) +{ int c, r, s, f, n, premask; double val, m; premask = 1; @@ -1748,7 +1785,8 @@ MRI *MRIframeBinarize(MRI *mri, double thresh, MRI *mask) { outside the mask (ie, mask < 0.5) are set to 0 (if out=NULL) or the previous value of out. */ -MRI *MRIexp(MRI *mri, double a, double b, MRI *mask, MRI *out) { +MRI *MRIexp(MRI *mri, double a, double b, MRI *mask, MRI *out) +{ int c, r, s, f; double val, valout, m; int err; @@ -1759,7 +1797,8 @@ MRI *MRIexp(MRI *mri, double a, double b, MRI *mask, MRI *out) { printf("ERROR: MRIexp: could not alloc\n"); return (NULL); } - } else { + } + else { err = MRIdimMismatch(mri, out, 1); if (err) { printf("ERROR: MRIexp(): output dimension mismatch (%d)\n", err); @@ -1795,7 +1834,8 @@ MRI *MRIexp(MRI *mri, double a, double b, MRI *mask, MRI *out) { outside the mask (ie, mask < 0.5) are set to 0 (if out=NULL) or the previous value of out. */ -MRI *MRIsum(MRI *mri1, MRI *mri2, double a, double b, MRI *mask, MRI *out) { +MRI *MRIsum(MRI *mri1, MRI *mri2, double a, double b, MRI *mask, MRI *out) +{ int c, r, s, f; double val1, val2, valout, m; int err; @@ -1812,7 +1852,8 @@ MRI *MRIsum(MRI *mri1, MRI *mri2, double a, double b, MRI *mask, MRI *out) { printf("ERROR: MRIsum: could not alloc\n"); return (NULL); } - } else { + } + else { err = MRIdimMismatch(mri1, out, 1); if (err) { printf("ERROR: MRIsum(): output dimension mismatch (%d)\n", err); @@ -1847,7 +1888,8 @@ MRI *MRIsum(MRI *mri1, MRI *mri2, double a, double b, MRI *mask, MRI *out) { (2) Fraction of occurances (ie noccurances/nframes) Note: input will be sorted in asc order */ -MRI *MRIvote(MRI *in, MRI *mask, MRI *vote) { +MRI *MRIvote(MRI *in, MRI *mask, MRI *vote) +{ int c, r, s, f, f0, ncols, nrows, nslices, nframes; float m; double vmax, v, v0; @@ -1934,7 +1976,8 @@ column, row, and slice at the given frame. The neighborhood size is within delta of the center voxel and includes the center voxel. Ie, the number of voxels searched is (2*delta + 1)^3 */ -int MRImostFreqNeighbor(MRI *mri, int c, int r, int s, int f, int delta) { +int MRImostFreqNeighbor(MRI *mri, int c, int r, int s, int f, int delta) +{ int dc, dr, ds, cn, rn, sn, nbr; int nlist, *list, nmax, nside; @@ -1974,7 +2017,8 @@ int MRImostFreqNeighbor(MRI *mri, int c, int r, int s, int f, int delta) { anatomical volume, the anatomical volume should be the targ parameter, and the functional should be the mov parameter. */ -int MRImakeVox2VoxReg(MRI *targ, MRI *mov, int regtype, char *regname, mriTransformRef *transform) { +int MRImakeVox2VoxReg(MRI *targ, MRI *mov, int regtype, char *regname, mriTransformRef *transform) +{ int retcode = 0; char *cur_char, *base_end; int err; @@ -2041,7 +2085,8 @@ int MRImakeVox2VoxReg(MRI *targ, MRI *mov, int regtype, char *regname, mriTransf generate one from our data file location. */ if (VOX2VOXREGTYPE_FILE == regtype) { strncpy(fullregname, regname, sizeof(fullregname)); - } else if (VOX2VOXREGTYPE_FIND == regtype) { + } + else if (VOX2VOXREGTYPE_FIND == regtype) { /* Copy the movable volume name and find the last / in the file name. From there, copy in "register.dat" for our file name. */ @@ -2147,7 +2192,8 @@ int MRImakeVox2VoxReg(MRI *targ, MRI *mov, int regtype, char *regname, mriTransf \fn double MRIsum2All(MRI *mri) \brief squares and then sums all the voxels. */ -double MRIsum2All(MRI *mri) { +double MRIsum2All(MRI *mri) +{ int c, r, s, f; double sum2all, val; @@ -2169,7 +2215,8 @@ double MRIsum2All(MRI *mri) { \brief Squares the value at each voxel. Values outside of the mask are set to 0. mask can be NULL. */ -MRI *MRIsquare(MRI *in, MRI *mask, MRI *out) { +MRI *MRIsquare(MRI *in, MRI *mask, MRI *out) +{ int c, r, s, f; double val, mval; @@ -2202,7 +2249,8 @@ MRI *MRIsquare(MRI *in, MRI *mask, MRI *out) { Values outside of the mask are set to 0. mask can be NULL. */ -MRI *MRIsquareRoot(MRI *in, MRI *mask, MRI *out) { +MRI *MRIsquareRoot(MRI *in, MRI *mask, MRI *out) +{ int c, r, s, f; double val, mval; @@ -2220,7 +2268,8 @@ MRI *MRIsquareRoot(MRI *in, MRI *mask, MRI *out) { for (f = 0; f < in->nframes; f++) { if (mval > 0.5) { val = MRIgetVoxVal(in, c, r, s, f); - } else + } + else val = 0.0; MRIsetVoxVal(out, c, r, s, f, sqrt(fabs(val))); } @@ -2233,7 +2282,8 @@ MRI *MRIsquareRoot(MRI *in, MRI *mask, MRI *out) { \fn MRI *MRIsqr(MRI *in, MRI *out) \brief Square of the value at each voxel. */ -MRI *MRIsqr(MRI *in, MRI *out) { +MRI *MRIsqr(MRI *in, MRI *out) +{ int c, r, s, f; double val; @@ -2263,7 +2313,8 @@ MRI *MRIsqr(MRI *in, MRI *out) { visualizing the voxel sampling. Set fthresh = .1, fmax=3.5, and use linear blending. */ -MRI *MRIchecker(MRI *mri, MRI *checker) { +MRI *MRIchecker(MRI *mri, MRI *checker) +{ int c, r, s, f; double cval = 0, rval = 0, sval = 0, fval = 0; @@ -2309,7 +2360,8 @@ MRI *MRIchecker(MRI *mri, MRI *checker) { \fn MRI *MRIgrid(MRI *mri, int dc, int dr, int ds, float val, MRI *grid) \brief Creates a grid pattern. */ -MRI *MRIgrid(MRI *mri, int dc, int dr, int ds, float val, MRI *grid) { +MRI *MRIgrid(MRI *mri, int dc, int dr, int ds, float val, MRI *grid) +{ int c, r, s, f; if (grid == NULL) { @@ -2342,7 +2394,8 @@ MRI *MRIgrid(MRI *mri, int dc, int dr, int ds, float val, MRI *grid) { \param targ - target volume \param Rt2s - ras2ras transform from target to source (can be NULL, but why?) */ -MRI *MRIvol2VolDelta(MRI *mov, MRI *targ, MATRIX *Rt2s) { +MRI *MRIvol2VolDelta(MRI *mov, MRI *targ, MATRIX *Rt2s) +{ int ct, rt, st; double dx, dy, dz; MATRIX *targCRS, *targRAS = NULL, *movRAS = NULL, *targVox2RAS, *targVox2movRAS; @@ -2404,7 +2457,8 @@ MRI *MRIvol2VolDelta(MRI *mov, MRI *targ, MATRIX *Rt2s) { \param crs1 - col, row, slice to start cropping (inclusive) \param crs2 - col, row, slice to end cropping (inclusive) */ -MRI *MRIcrop(MRI *mri, int c1, int r1, int s1, int c2, int r2, int s2) { +MRI *MRIcrop(MRI *mri, int c1, int r1, int s1, int c2, int r2, int s2) +{ int c, r, s, f, Nc, Nr, Ns; MRI *crop; MATRIX *Vox2RAS, *crs, *P0; @@ -2470,7 +2524,8 @@ MRI *MRIcrop(MRI *mri, int c1, int r1, int s1, int c2, int r2, int s2) { \param crs2 - col, row, slice in template at which cropping ended (inclusive) */ -MRI *MRIuncrop(MRI *mri, MRI *crop, int c1, int r1, int s1, int c2, int r2, int s2) { +MRI *MRIuncrop(MRI *mri, MRI *crop, int c1, int r1, int s1, int c2, int r2, int s2) +{ int c, r, s, f; MRI *uncrop; double v; @@ -2507,7 +2562,8 @@ MRI *MRIuncrop(MRI *mri, MRI *crop, int c1, int r1, int s1, int c2, int r2, int \brief Reverses the order of the slices and updates the vox2ras matrix. */ -MRI *MRIreverseSlices(MRI *in, MRI *out) { +MRI *MRIreverseSlices(MRI *in, MRI *out) +{ int c, r, s, f; MATRIX *M, *invM, *Sin, *Sout; double v; @@ -2559,7 +2615,8 @@ MRI *MRIreverseSlices(MRI *in, MRI *out) { return (out); } /*----------------------------------------------------------------*/ -MRI *MRIcutEndSlices(MRI *mri, int ncut) { +MRI *MRIcutEndSlices(MRI *mri, int ncut) +{ MRI *out; int nslices; int c, r, s, f, scut; @@ -2597,7 +2654,8 @@ MRI *MRIcutEndSlices(MRI *mri, int ncut) { *pnlist. The volume need not be an int or char, but it is probably what it will be. */ -int *MRIsegIdListExclude0(MRI *seg, int *pnlist, int frame) { +int *MRIsegIdListExclude0(MRI *seg, int *pnlist, int frame) +{ int *segidlist, *segidlist2, n, m, has0; segidlist = MRIsegIdList(seg, pnlist, frame); @@ -2629,7 +2687,8 @@ int *MRIsegIdListExclude0(MRI *seg, int *pnlist, int frame) { excluding segid=0. The number in the list is *nsegs. The volume need not be an int or char, but it is probably what it will be. */ -int *MRIsegIdListNot0(MRI *seg, int *nsegs, int frame) { +int *MRIsegIdListNot0(MRI *seg, int *nsegs, int frame) +{ int *segidlist0, *segidlist, msegs, nthseg; segidlist0 = MRIsegIdList(seg, nsegs, frame); // remove 0 from the list @@ -2651,7 +2710,8 @@ int *MRIsegIdListNot0(MRI *seg, int *nsegs, int frame) { the volume. The number in the list is *nlist. The volume need not be an int or char, but it is probably what it will be. */ -int *MRIsegIdList(MRI *seg, int *nlist, int frame) { +int *MRIsegIdList(MRI *seg, int *nlist, int frame) +{ int nvoxels, r, c, s, nth; int *tmplist = NULL; int *segidlist = NULL; @@ -2684,7 +2744,8 @@ int *MRIsegIdList(MRI *seg, int *nlist, int frame) { should have the same number of segs. Note: to get the name of the seg, CTABcopyName(ctab,segidlist[k],tmpstr,sizeof(tmpstr)); */ -double *MRIsegDice(MRI *seg1, MRI *seg2, int *nsegs, int **segidlist) { +double *MRIsegDice(MRI *seg1, MRI *seg2, int *nsegs, int **segidlist) +{ int k, c, r, s, id1, id2, k1 = 0, k2 = 0; int nsegid1, *segidlist1; int nsegid2, *segidlist2; @@ -2757,7 +2818,8 @@ double *MRIsegDice(MRI *seg1, MRI *seg2, int *nsegs, int **segidlist) { Note that if there is no difference, all voxels will have the value of VOXEL_UNCHANGED. See also MRIsegMergeDiff(). */ -MRI *MRIsegDiff(MRI *old, MRI *new, int *DiffFlag) { +MRI *MRIsegDiff(MRI *old, MRI *new, int *DiffFlag) +{ MRI *diff; int c, r, s; int vold, vnew, vdiff; @@ -2794,7 +2856,8 @@ MRI *MRIsegDiff(MRI *old, MRI *new, int *DiffFlag) { have a diff value other than VOXEL_UNCHANGED take their value from the "diff" segmentation. See also MRIsegDiff(). */ -MRI *MRIsegMergeDiff(MRI *old, MRI *diff) { +MRI *MRIsegMergeDiff(MRI *old, MRI *diff) +{ MRI *new; int c, r, s; int vold, vdiff, vnew; @@ -2828,7 +2891,8 @@ MRI *MRIsegMergeDiff(MRI *old, MRI *diff) { a control parameter. When 0, there is no bias. 1 is full bias. */ -MRI *MRIhalfCosBias(MRI *in, double alpha, MRI *out) { +MRI *MRIhalfCosBias(MRI *in, double alpha, MRI *out) +{ int c, r, s, f; double v, w; @@ -2850,7 +2914,8 @@ MRI *MRIhalfCosBias(MRI *in, double alpha, MRI *out) { return (out); } -int MRIvol2VolVSM(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param, MRI *vsm) { +int MRIvol2VolVSM(MRI *src, MRI *targ, MATRIX *Vt2s, int InterpCode, float param, MRI *vsm) +{ int ct, rt, st, f; int ics, irs, iss, cvsm, rvsm; float fcs, frs, fss; @@ -2992,7 +3057,8 @@ MRI *MRIvol2surfVSM(const MRI *SrcVol, float ProjFrac, int ProjType, int nskip, - MRI *TrgVol) { + MRI *TrgVol) +{ MATRIX *ras2vox, *vox2ras; AffineVector Scrs, Txyz; AffineMatrix ras2voxAffine; @@ -3029,7 +3095,8 @@ MRI *MRIvol2surfVSM(const MRI *SrcVol, TrgVol = MRIallocSequence(TrgSurf->nvertices, 1, 1, MRI_FLOAT, SrcVol->nframes); if (TrgVol == NULL) return (NULL); MRIcopyHeader(SrcVol, TrgVol); - } else { + } + else { if (TrgVol->width != TrgSurf->nvertices || TrgVol->nframes != SrcVol->nframes) { printf("ERROR: MRIvol2surfVSM: dimension mismatch (%d,%d), or (%d,%d)\n", TrgVol->width, @@ -3078,7 +3145,8 @@ MRI *MRIvol2surfVSM(const MRI *SrcVol, ProjNormDist(&Tx, &Ty, &Tz, TrgSurf, vtx, ProjFrac); else ProjNormFracThick(&Tx, &Ty, &Tz, TrgSurf, vtx, ProjFrac); - } else { + } + else { Tx = v->x; Ty = v->y; Tz = v->z; @@ -3142,7 +3210,8 @@ MRI *MRIvol2surfVSM(const MRI *SrcVol, MRIsampleSeqVolume(SrcVol, fcol, frow, fslc, valvect, 0, SrcVol->nframes - 1); if (Gdiag_no == vtx) printf("val = %f\n", valvect[0]); for (frm = 0; frm < SrcVol->nframes; frm++) MRIFseq_vox(TrgVol, vtx, 0, 0, frm) = valvect[frm]; - } else { + } + else { for (frm = 0; frm < SrcVol->nframes; frm++) { switch (InterpMethod) { case SAMPLE_NEAREST: @@ -3180,7 +3249,8 @@ MRI *MRIvol2surfVSM(const MRI *SrcVol, return (TrgVol); } -int MRIvol2VolTkRegVSM(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, float param, MRI *vsm) { +int MRIvol2VolTkRegVSM(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, float param, MRI *vsm) +{ MATRIX *vox2vox = NULL; MATRIX *Tmov, *invTmov, *Ttarg; int err; @@ -3193,7 +3263,8 @@ int MRIvol2VolTkRegVSM(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, floa // vox2vox = invTmov*R*Ttarg vox2vox = MatrixMultiply(invTmov, Rtkreg, vox2vox); MatrixMultiply(vox2vox, Ttarg, vox2vox); - } else + } + else vox2vox = NULL; // resample @@ -3221,7 +3292,8 @@ int MRIvol2VolTkRegVSM(MRI *mov, MRI *targ, MATRIX *Rtkreg, int InterpCode, floa the source. It is possible that no source voxels map to a given target voxel (but probably not likely if targ is lowres). */ -MRI *MRIvol2VolFill(MRI *src, MRI *mask, LTA *lta, int UpsampleFactor, int DoConserve, MRI *outfill) { +MRI *MRIvol2VolFill(MRI *src, MRI *mask, LTA *lta, int UpsampleFactor, int DoConserve, MRI *outfill) +{ int c, r, s, ct, rt, st, f, nhits, nPad = 2; MATRIX *crssrc, *crstarg, *v2v, *vmusinv; double vsrc, vout; @@ -3248,7 +3320,8 @@ MRI *MRIvol2VolFill(MRI *src, MRI *mask, LTA *lta, int UpsampleFactor, int DoCon if (Gdiag_no > 0) printf("MRIvol2VolFill(): not using inverse\n"); v2v = ltatmp->xforms[0].m_L; vgtarg = ltatmp->xforms[lta->num_xforms - 1].dst; - } else { + } + else { // Invert the matrix if the LTA goes in the wrong direction if (Gdiag_no > 0) printf("MRIvol2VolFill(): using inverse\n"); LTAfillInverse(ltatmp); @@ -3263,7 +3336,8 @@ MRI *MRIvol2VolFill(MRI *src, MRI *mask, LTA *lta, int UpsampleFactor, int DoCon v2v = MatrixMultiply(v2v, vmusinv, v2v); MatrixFree(&vmusinv); LTAfree(&src2srcmus); - } else + } + else srcmus = src; if (outfill == NULL) { @@ -3350,7 +3424,8 @@ MRI *MRIvol2VolFill(MRI *src, MRI *mask, LTA *lta, int UpsampleFactor, int DoCon \brief Creates a segmentation boundary volume in which voxels whose neighbors are the same seg are set to 0. */ -MRI *MRIsegBoundary(MRI *seg) { +MRI *MRIsegBoundary(MRI *seg) +{ MRI *boundary; int c, r, s, dc, dr, ds; int cseg, nseg, b; @@ -3395,7 +3470,8 @@ MRI *MRIsegBoundary(MRI *seg) { \brief Creates a 1-frame volume with the value at frame 0 equal to the slice number. */ -MRI *MRIsliceNo(MRI *in, MRI *out) { +MRI *MRIsliceNo(MRI *in, MRI *out) +{ int c, r, s; if (out == NULL) { out = MRIalloc(in->width, in->height, in->depth, MRI_FLOAT); @@ -3419,7 +3495,8 @@ MRI *MRIsliceNo(MRI *in, MRI *out) { at frame 0 equal to the voxel index, eg, sliceno*nrows*ncols + rowno*ncols + col. */ -MRI *MRIindexNo(MRI *in, MRI *out) { +MRI *MRIindexNo(MRI *in, MRI *out) +{ int c, r, s, index; if (out == NULL) { out = MRIalloc(in->width, in->height, in->depth, MRI_FLOAT); @@ -3446,7 +3523,8 @@ MRI *MRIindexNo(MRI *in, MRI *out) { at frame 0 equal to the column number, frame 1 the row, and frame 2 the slice. */ -MRI *MRIcrs(MRI *in, MRI *out) { +MRI *MRIcrs(MRI *in, MRI *out) +{ int c, r, s; if (out == NULL) { @@ -3472,8 +3550,8 @@ MRI *MRIcrs(MRI *in, MRI *out) { segmentation. Returns the number of voxels in the segmentation. ---------------------------------------------------------*/ -int MRIsegStats( - MRI *seg, int segid, MRI *mri, int frame, float *min, float *max, float *range, float *mean, float *std) { +int MRIsegStats(MRI *seg, int segid, MRI *mri, int frame, float *min, float *max, float *range, float *mean, float *std) +{ int id, nvoxels, r, c, s; double val, sum, sum2; @@ -3511,7 +3589,8 @@ int MRIsegStats( if (nvoxels != 0) { *mean = sum / nvoxels; - } else { + } + else { *mean = 0.0; } @@ -3531,16 +3610,9 @@ int MRIsegStats( \brief Computes stats based on the the middle 100-2*Pct values, ie, it trims Pct off the ends. */ -int MRIsegStatsRobust(MRI *seg, - int segid, - MRI *mri, - int frame, - float *min, - float *max, - float *range, - float *mean, - float *std, - float Pct) { +int MRIsegStatsRobust( + MRI *seg, int segid, MRI *mri, int frame, float *min, float *max, float *range, float *mean, float *std, float Pct) +{ int id, nvoxels, r, c, s, k, m; double val, sum, sum2; float *vlist; @@ -3617,7 +3689,8 @@ int MRIsegStatsRobust(MRI *seg, segmentation. favg must be preallocated to number of frames. favg = (double *) calloc(sizeof(double),mri->nframes); ---------------------------------------------------------*/ -int MRIsegFrameAvg(MRI *seg, int segid, MRI *mri, double *favg) { +int MRIsegFrameAvg(MRI *seg, int segid, MRI *mri, double *favg) +{ int id, nvoxels, r, c, s, f; double val; @@ -3652,7 +3725,8 @@ int MRIsegFrameAvg(MRI *seg, int segid, MRI *mri, double *favg) { } MRI *MRImask_with_T2_and_aparc_aseg( - MRI *mri_src, MRI *mri_dst, MRI *mri_T2, MRI *mri_aparc_aseg, float T2_thresh, int mm_from_exterior) { + MRI *mri_src, MRI *mri_dst, MRI *mri_T2, MRI *mri_aparc_aseg, float T2_thresh, int mm_from_exterior) +{ int x, y, z, nremoved, i; MRI *mri_bright, *mri_mask, *mri_tmp = NULL; @@ -3667,7 +3741,8 @@ MRI *MRImask_with_T2_and_aparc_aseg( GetLargestCC6(mri_aparc_aseg); // remove disconnected background components MRIand(mri_mask, mri_aparc_aseg, mri_mask, 1); MRIopenN(mri_mask, mri_mask, 3); // third order open will remove thin chains of bright T2 that are in the interior - } else // just use T2 + } + else // just use T2 { GetLargestCC6(mri_mask); } @@ -3712,7 +3787,8 @@ MRI *MRImask_with_T2_and_aparc_aseg( \brief Extracts a list of unique segmentation IDs from the volume. Includes 0. */ -int *MRIsegmentationList(MRI *seg, int *pListLength) { +int *MRIsegmentationList(MRI *seg, int *pListLength) +{ int c, r, s, n, nvox; int *list, *voxlist; @@ -3749,7 +3825,8 @@ int *MRIsegmentationList(MRI *seg, int *pListLength) { making it consistent with matlab. This order must be used when creating the y-matrix. */ -MATRIX *BuildGTM0(MRI *seg, MRI *mask, double cFWHM, double rFWHM, double sFWHM, MATRIX *X) { +MATRIX *BuildGTM0(MRI *seg, MRI *mask, double cFWHM, double rFWHM, double sFWHM, MATRIX *X) +{ int c, r, s, nmask, nsegs, nthseg, mthseg, segid, *segidlist, has0; double cStd, rStd, sStd, val; MRI *roimask = NULL, *roimasksm = NULL; @@ -3838,7 +3915,8 @@ MATRIX *BuildGTM0(MRI *seg, MRI *mask, double cFWHM, double rFWHM, double sFWHM, \brief Computes fisher transform. The input should be a correlation coefficient with values between -1 and +1 */ -MRI *MRIfisherTransform(MRI *rho, MRI *mask, MRI *out) { +MRI *MRIfisherTransform(MRI *rho, MRI *mask, MRI *out) +{ int c, r, s, f; double v, ft; @@ -3870,7 +3948,8 @@ MRI *MRIfisherTransform(MRI *rho, MRI *mask, MRI *out) { \fn MRI *MRIbinarizeMatch(MRI *seg, int match, int frame, MRI *out) \brief Binarizes a volume based on the voxels values that match the match value. */ -MRI *MRIbinarizeMatch(MRI *seg, int *MatchList, int nList, int frame, MRI *out) { +MRI *MRIbinarizeMatch(MRI *seg, int *MatchList, int nList, int frame, MRI *out) +{ int c, r, s, m, n; if (out == NULL) { @@ -3909,7 +3988,8 @@ MRI *MRIbinarizeMatch(MRI *seg, int *MatchList, int nList, int frame, MRI *out) be NULL. This is really meant for the aseg to be the aseg.mgz with cortex = 3,42 and cerebralwm = 2,41. */ -MRI *MRIhiresSeg(MRI *aseg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, int USF, LTA **aseg2hrseg) { +MRI *MRIhiresSeg(MRI *aseg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, int USF, LTA **aseg2hrseg) +{ MRI *asegus, *lhwvol, *rhwvol, *lhpvol, *rhpvol, *seg; int c, r, s, asegv, lhwv, rhwv, lhpv, rhpv, segv, lhRibbon, rhRibbon, Ribbon, SubCort; int nPad = 2; @@ -3927,7 +4007,8 @@ MRI *MRIhiresSeg(MRI *aseg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, int USF, asegus = aseg; *aseg2hrseg = TransformRegDat2LTA(aseg, aseg, NULL); // Identity } - } else { + } + else { // aseg might be null for testing purposes if (lhw->vg.valid == 0) { printf("ERROR: MRIhiresSeg(): if aseg=NULL, then surface volume geometry must be valid\n"); @@ -4016,7 +4097,8 @@ MRI *MRIhiresSeg(MRI *aseg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, int USF, // but not if you are expecting the labels to be correct. if (lhRibbon) segv = Left_Cerebral_Cortex; if (rhRibbon) segv = Right_Cerebral_Cortex; - } else { + } + else { /* To get here, it cannot be in the true ribbon so, if the aseg says it is CorticalGM, that is wrong. The question is, what is right? Probably WM xCSF , but ideally, this should @@ -4026,12 +4108,14 @@ MRI *MRIhiresSeg(MRI *aseg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, int USF, segv = Left_Cerebral_White_Matter; else segv = UnknownFill; - } else if (asegv == Right_Cerebral_Cortex) { + } + else if (asegv == Right_Cerebral_Cortex) { if (rhpv) segv = Right_Cerebral_White_Matter; else segv = UnknownFill; - } else { + } + else { // To get here aseg can only be CerebralWM, CSF_ExtraCerebral, Head_ExtraCerebral // or something else outside of the brain. if (asegv != Left_Cerebral_White_Matter && asegv != Right_Cerebral_White_Matter && @@ -4061,7 +4145,8 @@ MRI *MRIhiresSeg(MRI *aseg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, int USF, The return is an array of MRIs, one for each tissue type. The output volume is that of the dst volume geometry in seg2vol. */ -MRI *MRIpartialVolumeFraction(LTA *seg2vol, MRI *seg, double resmm, COLOR_TABLE *ct, MRI *pvf) { +MRI *MRIpartialVolumeFraction(LTA *seg2vol, MRI *seg, double resmm, COLOR_TABLE *ct, MRI *pvf) +{ MRI *ttseg; int nTT, nsegs, *segidlist; VOL_GEOM *vg; @@ -4143,7 +4228,8 @@ MRI *MRIpartialVolumeFractionAS(LTA *aseg2vol, int USF, double resmm, COLOR_TABLE *ct, - MRI *pvf) { + MRI *pvf) +{ MRI *hrseg; LTA *aseg2hrseg, *hrseg2aseg, *hrseg2vol, *ltaArray[2]; @@ -4171,7 +4257,8 @@ MRI *MRIpartialVolumeFractionAS(LTA *aseg2vol, \brief Count the number of times there is a match in seg at the given frame within the mask (mask can be null). */ -int MRIcountMatches(const MRI *seg, const int MatchVal, const int frame, const MRI *mask) { +int MRIcountMatches(const MRI *seg, const int MatchVal, const int frame, const MRI *mask) +{ int nMatches = 0; int c; @@ -4198,7 +4285,8 @@ int MRIcountMatches(const MRI *seg, const int MatchVal, const int frame, const M the segmentation are used. Note: this makes no attempt whatsoever to do a true segmentation of extra-cerebral CSF!!! The seg (or out if non-NULL) must not be UCHAR. */ -MRI *MRIaddExtraCerebralCSF(MRI *seg, int nDil, MRI *out) { +MRI *MRIaddExtraCerebralCSF(MRI *seg, int nDil, MRI *out) +{ int c, r, s, n, nxcsf; MRI *mask = NULL; @@ -4244,7 +4332,8 @@ MRI *MRIaddExtraCerebralCSF(MRI *seg, int nDil, MRI *out) { \fn COLOR_TABLE *CTABpruneCTab(const COLOR_TABLE *ct0, MRI *seg) \brief Creates a new CTAB with only the segments in seg */ -COLOR_TABLE *CTABpruneCTab(const COLOR_TABLE *ct0, MRI *seg) { +COLOR_TABLE *CTABpruneCTab(const COLOR_TABLE *ct0, MRI *seg) +{ COLOR_TABLE *ct; int *segidlist, nsegs, segid, n; @@ -4287,7 +4376,8 @@ COLOR_TABLE *CTABpruneCTab(const COLOR_TABLE *ct0, MRI *seg) { be run on the pial surfaces before using this function. The output will be the same size as seg. */ -MRI *MRIannot2CorticalSeg(MRI *seg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, LTA *anat2seg, MRI *ctxseg) { +MRI *MRIannot2CorticalSeg(MRI *seg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, LTA *anat2seg, MRI *ctxseg) +{ MATRIX *AnatVox2SurfRAS, *SegVox2SurfRAS; float hashres = 16; MHT *lhw_hash = NULL, *rhw_hash = NULL, *lhp_hash = NULL, *rhp_hash = NULL; @@ -4377,7 +4467,8 @@ MRI *MRIannot2CorticalSeg(MRI *seg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, phash = lhp_hash; psurf = lhp; // wmval = Left_Cerebral_White_Matter; - } else { + } + else { wsurf = rhw; whash = rhw_hash; phash = rhp_hash; @@ -4458,7 +4549,8 @@ MRI *MRIannot2CorticalSeg(MRI *seg, MRIS *lhw, MRIS *lhp, MRIS *rhw, MRIS *rhp, (see MRIunsegmentWM()). This function basically is what is done when creating wmparc.mgz. */ -MRI *MRIannot2CerebralWMSeg(MRI *seg, MRIS *lhw, MRIS *rhw, double DistThresh, LTA *anat2seg, MRI *wmseg) { +MRI *MRIannot2CerebralWMSeg(MRI *seg, MRIS *lhw, MRIS *rhw, double DistThresh, LTA *anat2seg, MRI *wmseg) +{ MATRIX *AnatVox2SurfRAS, *SegVox2SurfRAS; float hashres = 16; MHT *lhw_hash = NULL, *rhw_hash = NULL; @@ -4534,7 +4626,8 @@ MRI *MRIannot2CerebralWMSeg(MRI *seg, MRIS *lhw, MRIS *rhw, double DistThresh, L wsurf = lhw; whash = lhw_hash; wmunknown = 5001; - } else { + } + else { wsurf = rhw; whash = rhw_hash; wmunknown = 5002; @@ -4563,7 +4656,8 @@ MRI *MRIannot2CerebralWMSeg(MRI *seg, MRIS *lhw, MRIS *rhw, double DistThresh, L segv = annotid + wsurf->ct->idbase; else segv = wmunknown; // no annotation present - } else + } + else segv = wmunknown; MRIsetVoxVal(wmseg, c, r, s, 0, segv); } @@ -4589,7 +4683,8 @@ MRI *MRIannot2CerebralWMSeg(MRI *seg, MRIS *lhw, MRIS *rhw, double DistThresh, L space the surface anatomical space. If NULL, then it assumes that the surface VOL_GEOM and the seg share a scanner RAS space. This function can be used to relabel hypointensities and CC. */ -MRI *MRIunsegmentWM(MRI *seg, MRIS *lhw, MRIS *rhw, int *segidlist, int nlist, LTA *anat2seg, MRI *wmseg) { +MRI *MRIunsegmentWM(MRI *seg, MRIS *lhw, MRIS *rhw, int *segidlist, int nlist, LTA *anat2seg, MRI *wmseg) +{ MATRIX *AnatVox2SurfRAS, *SegVox2SurfRAS; float hashres = 16; MHT *lhw_hash = NULL, *rhw_hash = NULL; @@ -4709,7 +4804,8 @@ MRI *MRIunsegmentWM(MRI *seg, MRIS *lhw, MRIS *rhw, int *segidlist, int nlist, L then it assumes that the surface VOL_GEOM and the seg share a scanner RAS space. See also MRIunsegmentWM(). */ -MRI *MRIrelabelHypoHemi(MRI *seg, MRIS *lhw, MRIS *rhw, LTA *anat2seg, MRI *wmseg) { +MRI *MRIrelabelHypoHemi(MRI *seg, MRIS *lhw, MRIS *rhw, LTA *anat2seg, MRI *wmseg) +{ MATRIX *AnatVox2SurfRAS, *SegVox2SurfRAS; float hashres = 16; MHT *lhw_hash = NULL, *rhw_hash = NULL; @@ -4820,7 +4916,8 @@ MRI *MRIrelabelHypoHemi(MRI *seg, MRIS *lhw, MRIS *rhw, LTA *anat2seg, MRI *wmse upper limit is used This is used prior to running MRIhiresSeg(). It's a long story. Can be done in-place. Ideally, seg is something like aparc+aseg.mgz */ -MRI *MRIunsegmentCortex(MRI *seg, int lhmin, int lhmax, int rhmin, int rhmax, MRI *out) { +MRI *MRIunsegmentCortex(MRI *seg, int lhmin, int lhmax, int rhmin, int rhmax, MRI *out) +{ int c; if (out == NULL) { @@ -4864,7 +4961,8 @@ MRI *MRIunsegmentCortex(MRI *seg, int lhmin, int lhmax, int rhmin, int rhmax, MR none of the nearest neighbors are in the segidlist, the hypo is not relabeled. */ -MRI *MRIrelabelNonWMHypos(MRI *seg0, int *segidlist, int nsegs, int *outsegidlist) { +MRI *MRIrelabelNonWMHypos(MRI *seg0, int *segidlist, int nsegs, int *outsegidlist) +{ int c, r, s, c0, r0, s0, k, n, loop, nchanged, mfsegid, nbrmax, nthnbr, nhits, segid, hit; int *clist, *rlist, *slist, *hitlist, nbrlist[3 * 3 * 3], nchangedtot; MRI *seg, *newseg; @@ -4983,7 +5081,8 @@ MRI *MRIrelabelNonWMHypos(MRI *seg0, int *segidlist, int nsegs, int *outsegidlis number of non-null entries in the table. The value is set the to count for that entry in the ctab. */ -MRI *CTABcount2MRI(COLOR_TABLE *ct, MRI *seg) { +MRI *CTABcount2MRI(COLOR_TABLE *ct, MRI *seg) +{ int n, ntot; MRI *mri; float voxsize; diff --git a/utils/mriBSpline.c b/utils/mriBSpline.c index 298d03b7662..2f1243df14d 100644 --- a/utils/mriBSpline.c +++ b/utils/mriBSpline.c @@ -69,7 +69,8 @@ static double InitialCausalCoefficient(double c[], /* coefficients */ zn *= z; } return (Sum); - } else { + } + else { /* full loop */ zn = z; iz = 1.0 / z; @@ -139,15 +140,18 @@ static void ConvertToInterpolationCoefficients(double c[], /* input samples // get and set line routines need to be improved (speedup by grabbing a // whole row in data block...) -static void getZLine(const MRI *mri, int x, int y, int f, double Line[]) { +static void getZLine(const MRI *mri, int x, int y, int f, double Line[]) +{ int z; for (z = 0; z < mri->depth; z++) Line[z] = MRIgetVoxVal(mri, x, y, z, f); } -static void getZLineStop(const MRI *mri, int x, int y, int f, double Line[], int zstop) { +static void getZLineStop(const MRI *mri, int x, int y, int f, double Line[], int zstop) +{ int z; for (z = 0; z < zstop; z++) Line[z] = MRIgetVoxVal(mri, x, y, z, f); } -static void setZLine(MRI *mri, int x, int y, int f, double Line[]) { +static void setZLine(MRI *mri, int x, int y, int f, double Line[]) +{ int z; if (x >= mri->width) { printf("X limit error\n"); @@ -169,19 +173,23 @@ static void setZLine(MRI *mri, int x, int y, int f, double Line[]) { MRIsetVoxVal(mri, x, y, z, f, 0); else MRIsetVoxVal(mri, x, y, z, f, nint(Line[z])); - } else + } + else MRIsetVoxVal(mri, x, y, z, f, (float)Line[z]); } } -static void getYLine(const MRI *mri, int x, int z, int f, double Line[]) { +static void getYLine(const MRI *mri, int x, int z, int f, double Line[]) +{ int y; for (y = 0; y < mri->height; y++) Line[y] = MRIgetVoxVal(mri, x, y, z, f); } -static void getYLineStop(const MRI *mri, int x, int z, int f, double Line[], int ystop) { +static void getYLineStop(const MRI *mri, int x, int z, int f, double Line[], int ystop) +{ int y; for (y = 0; y < ystop; y++) Line[y] = MRIgetVoxVal(mri, x, y, z, f); } -static void setYLine(MRI *mri, int x, int z, int f, double Line[]) { +static void setYLine(MRI *mri, int x, int z, int f, double Line[]) +{ int y; if (x >= mri->width) { printf("X limit error\n"); @@ -203,11 +211,13 @@ static void setYLine(MRI *mri, int x, int z, int f, double Line[]) { MRIsetVoxVal(mri, x, y, z, f, 0); else MRIsetVoxVal(mri, x, y, z, f, nint(Line[y])); - } else + } + else MRIsetVoxVal(mri, x, y, z, f, (float)Line[y]); } } -static void getXLine(const MRI *mri, int y, int z, int f, double Line[]) { +static void getXLine(const MRI *mri, int y, int z, int f, double Line[]) +{ int x; for (x = 0; x < mri->width; x++) Line[x] = MRIgetVoxVal(mri, x, y, z, f); } @@ -216,7 +226,8 @@ static void getXLine(const MRI *mri, int y, int z, int f, double Line[]) { // int x; // for (x=0;x= mri->height) { printf("Y limit error\n"); @@ -239,12 +250,14 @@ static void setXLine(MRI *mri, int y, int z, int f, double Line[]) { MRIsetVoxVal(mri, x, y, z, f, 0); else MRIsetVoxVal(mri, x, y, z, f, nint(Line[x])); - } else + } + else MRIsetVoxVal(mri, x, y, z, f, (float)Line[x]); } } -static int initPoles(double Pole[4], int SplineDegree) { +static int initPoles(double Pole[4], int SplineDegree) +{ int NbPoles = 0; /* recover the poles from a lookup table */ switch (SplineDegree) { @@ -299,7 +312,8 @@ static int initPoles(double Pole[4], int SplineDegree) { return NbPoles; } -static void BsplineWeights(int SplineDegree, const double *val, const int *index, double *weights) { +static void BsplineWeights(int SplineDegree, const double *val, const int *index, double *weights) +{ double w, w2, w4, t, t0, t1; switch (SplineDegree) { case 2: @@ -490,7 +504,8 @@ static void BsplineWeights(int SplineDegree, const double *val, const int *index Author: Michael Unser, NIH, BEIP, May 1992 ---------------------------------------------------------------------------- */ -static void PyramidFilterSplinel2(double g[], long *ng, double *h, long *nh, long Order) { +static void PyramidFilterSplinel2(double g[], long *ng, double *h, long *nh, long Order) +{ switch (Order) { case 0L: *ng = 1L; @@ -597,7 +612,8 @@ static void PyramidFilterSplinel2(double g[], long *ng, double *h, long *nh, lon ---------------------------------------------------------------------------- */ -static void PyramidFilterSplineL2(double g[], long *ng, double h[], long *nh, long Order) { +static void PyramidFilterSplineL2(double g[], long *ng, double h[], long *nh, long Order) +{ switch (Order) { case 0L: *ng = 1L; @@ -754,7 +770,8 @@ static void PyramidFilterSplineL2(double g[], long *ng, double h[], long *nh, lo Daniel Sage, EPFL, Biomedical Imaging Group, November 1999 ---------------------------------------------------------------------------- */ -static void PyramidFilterCentered(double g[], long *ng, double h[], long *nh, long Order) { +static void PyramidFilterCentered(double g[], long *ng, double h[], long *nh, long Order) +{ switch (Order) { case 0: g[0] = 1; @@ -944,7 +961,8 @@ static void PyramidFilterCentered(double g[], long *ng, double h[], long *nh, lo Daniel Sage, EPFL, Biomedical Imaging Group, November 1999 ---------------------------------------------------------------------------- */ -static void PyramidFilterCenteredL2(double g[], long *ng, double h[], long *nh, long Order) { +static void PyramidFilterCenteredL2(double g[], long *ng, double h[], long *nh, long Order) +{ switch (Order) { case 0: g[0] = 1.; @@ -1339,7 +1357,8 @@ static void PyramidFilterCenteredL2(double g[], long *ng, double h[], long *nh, FALSE if it is not a centered filter ---------------------------------------------------------------------------- */ -static int GetPyramidFilter(char *Filter, long Order, double g[], long *ng, double h[], long *nh, short *IsCentered) { +static int GetPyramidFilter(char *Filter, long Order, double g[], long *ng, double h[], long *nh, short *IsCentered) +{ ng[0] = -1L; nh[0] = -1L; *IsCentered = FALSE; @@ -1389,7 +1408,8 @@ static int GetPyramidFilter(char *Filter, long Order, double g[], long *ng, doub Daniel Sage, EPFL, Biomedical Imaging Group, April 1999 ---------------------------------------------------------------------------- */ -static void ReduceStandard_1D(double In[], long NxIn, double Out[], double g[], long ng) { +static void ReduceStandard_1D(double In[], long NxIn, double Out[], double g[], long ng) +{ long k, i, i1, i2; long kk, kn, nred, n; @@ -1445,7 +1465,8 @@ static void ReduceStandard_1D(double In[], long NxIn, double Out[], double g[], Daniel Sage, EPFL, Biomedical Imaging Group, April 1999 ---------------------------------------------------------------------------- */ -static void ExpandStandard_1D(double In[], long NxIn, double Out[], double h[], long nh) { +static void ExpandStandard_1D(double In[], long NxIn, double Out[], double h[], long nh) +{ long k, j, i, i1, i2; long kn, nexp, n; @@ -1504,7 +1525,8 @@ static void ExpandStandard_1D(double In[], long NxIn, double Out[], double h[], Daniel Sage, EPFL, Biomedical Imaging Group, April 1999 ---------------------------------------------------------------------------- */ -static void ReduceCentered_1D(double In[], long NxIn, double Out[], double g[], long ng) { +static void ReduceCentered_1D(double In[], long NxIn, double Out[], double g[], long ng) +{ double *y_tmp; long k, i, i1, i2; long kk, kn, nred, n; @@ -1570,7 +1592,8 @@ static void ReduceCentered_1D(double In[], long NxIn, double Out[], double g[], Daniel Sage, EPFL, Biomedical Imaging Group, April 1999 ---------------------------------------------------------------------------- */ -static void ExpandCentered_1D(double In[], long NxIn, double Out[], double h[], long nh) { +static void ExpandCentered_1D(double In[], long NxIn, double Out[], double h[], long nh) +{ long k, i, j, i1, k0, i2; long kk, kn, nexp, n; @@ -1625,7 +1648,8 @@ static void ExpandCentered_1D(double In[], long NxIn, double Out[], double h[], Router function to call ReduceStandard_1D or ReduceCentered_1D ---------------------------------------------------------------------------- */ -static void Reduce_1D(double In[], long NxIn, double Out[], double g[], long ng, short IsCentered) { +static void Reduce_1D(double In[], long NxIn, double Out[], double g[], long ng, short IsCentered) +{ if (IsCentered) ReduceCentered_1D(In, NxIn, Out, g, ng); else @@ -1640,7 +1664,8 @@ static void Reduce_1D(double In[], long NxIn, double Out[], double g[], long ng, Router function to call ExpandStandard_1D or ExpandCentered_1D ---------------------------------------------------------------------------- */ -static void Expand_1D(double In[], long NxIn, double Out[], double h[], long nh, short IsCentered) { +static void Expand_1D(double In[], long NxIn, double Out[], double h[], long nh, short IsCentered) +{ if (IsCentered) ExpandCentered_1D(In, NxIn, Out, h, nh); else @@ -1649,7 +1674,8 @@ static void Expand_1D(double In[], long NxIn, double Out[], double h[], long nh, /*--------------------------------------------------------------------------*/ -extern MRI_BSPLINE *MRIallocBSpline(int width, int height, int depth, int nframes) { +extern MRI_BSPLINE *MRIallocBSpline(int width, int height, int depth, int nframes) +{ MRI_BSPLINE *bspline = (MRI_BSPLINE *)calloc(1, sizeof(MRI_BSPLINE)); if (!bspline) ErrorExit(ERROR_NO_MEMORY, "MRIalloc: could not allocate MRI_BSPLINE\n"); bspline->coeff = MRIallocSequence(width, height, depth, MRI_FLOAT, nframes); @@ -1659,7 +1685,8 @@ extern MRI_BSPLINE *MRIallocBSpline(int width, int height, int depth, int nframe return bspline; } -extern int MRIfreeBSpline(MRI_BSPLINE **pbspline) { +extern int MRIfreeBSpline(MRI_BSPLINE **pbspline) +{ MRI_BSPLINE *bspline = *pbspline; if (!bspline) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIfreeBSpline: null pointer\n")); MRIfree(&bspline->coeff); @@ -1669,7 +1696,8 @@ extern int MRIfreeBSpline(MRI_BSPLINE **pbspline) { return (NO_ERROR); } -extern MRI_BSPLINE *MRItoBSpline(const MRI *mri_src, MRI_BSPLINE *bspline, int degree) { +extern MRI_BSPLINE *MRItoBSpline(const MRI *mri_src, MRI_BSPLINE *bspline, int degree) +{ printf("MRItoBSpline degree %i\n", degree); double *Lines[_MAX_FS_THREADS]; @@ -1723,7 +1751,9 @@ extern MRI_BSPLINE *MRItoBSpline(const MRI *mri_src, MRI_BSPLINE *bspline, int d /* convert the image samples into interpolation coefficients */ #ifdef HAVE_OPENMP #pragma omp parallel - { nthreads = omp_get_num_threads(); } + { + nthreads = omp_get_num_threads(); + } #else nthreads = 1; #endif @@ -1893,7 +1923,8 @@ extern int MRIsampleBSpline(const MRI_BSPLINE *bspline, /* input B-spline array yIndex[l] = j++; zIndex[l] = k++; } - } else { + } + else { i = (long)floor(x + 0.5) - SplineDegree / 2; j = (long)floor(y + 0.5) - SplineDegree / 2; k = (long)floor(z + 0.5) - SplineDegree / 2; @@ -1990,7 +2021,8 @@ extern int MRIsampleBSpline(const MRI_BSPLINE *bspline, /* input B-spline array } extern int MRIsampleSeqBSpline( - const MRI_BSPLINE *bspline, double x, double y, double z, float *valvect, int firstframe, int lastframe) { + const MRI_BSPLINE *bspline, double x, double y, double z, float *valvect, int firstframe, int lastframe) +{ int f; int OutOfBounds = MRIindexNotInVolume(bspline->coeff, x, y, z); if (OutOfBounds == 1) { @@ -2021,7 +2053,8 @@ extern int MRIsampleSeqBSpline( yIndex[l] = j++; zIndex[l] = k++; } - } else { + } + else { i = (long)floor(x + 0.5) - SplineDegree / 2; j = (long)floor(y + 0.5) - SplineDegree / 2; k = (long)floor(z + 0.5) - SplineDegree / 2; @@ -2110,7 +2143,9 @@ MRI *MRIlinearTransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, MATRIX int nthreads = 1, tid = 0; #ifdef HAVE_OPENMP #pragma omp parallel - { nthreads = omp_get_num_threads(); } + { + nthreads = omp_get_num_threads(); + } #endif mAinv = MatrixInverse(mA, NULL); /* will sample from dst back to src */ @@ -2119,7 +2154,8 @@ MRI *MRIlinearTransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, MATRIX if (!mri_dst) { // mri_dst = MRIclone(mri_src, NULL) ; mri_dst = MRIcloneDifferentType(bspline->coeff, bspline->srctype); - } else + } + else MRIclear(mri_dst); width = mri_dst->width; @@ -2182,7 +2218,8 @@ MRI *MRIlinearTransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, MATRIX return (mri_dst); } -MRI *MRIapplyRASlinearTransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, MATRIX *m_ras_xform) { +MRI *MRIapplyRASlinearTransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, MATRIX *m_ras_xform) +{ MATRIX *m_voxel_xform; m_voxel_xform = MRIrasXformToVoxelXform(bspline->coeff, mri_dst, m_ras_xform, NULL); @@ -2264,7 +2301,8 @@ MRI *LTAtransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, LTA *lta) mri_dst->type = bspline->srctype; // make sure the geometry is taken from the transform, not from src: useVolGeomToMRI(&tran->dst, mri_dst); - } else if (getenv("USE_AVERAGE305")) { + } + else if (getenv("USE_AVERAGE305")) { fprintf(stderr, "INFO: Environmental variable " "USE_AVERAGE305 set\n"); @@ -2286,7 +2324,8 @@ MRI *LTAtransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, LTA *lta) // do the following whenever // we change direction cosines MRIreInitCache(mri_dst); - } else { + } + else { fprintf(stderr, "INFO: Transform dst volume " "info is not used (valid flag = 0).\n"); @@ -2303,7 +2342,8 @@ MRI *LTAtransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, LTA *lta) if (lta->type == LINEAR_RAS_TO_RAS) { // don't need any info from dst(in lta) only from mri_dst: return (MRIapplyRASlinearTransformBSpline(bspline, mri_dst, lta->xforms[0].m_L)); - } else if (lta->type == LINEAR_VOX_TO_VOX) // vox-to-vox + } + else if (lta->type == LINEAR_VOX_TO_VOX) // vox-to-vox { // convert to ras_to_ras using xforms from lta if available // this strips geometry information and allows to use the @@ -2312,7 +2352,8 @@ MRI *LTAtransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, LTA *lta) // we use the geometry from the passed source and target image if (lta->xforms[0].dst.valid) { i2r = vg_i_to_r(<a->xforms[0].dst); // allocated - } else { + } + else { fprintf(stderr, "INFO: LTA dst geometry information missing!\n" " We assume that the dst volume passed is the\n" @@ -2322,7 +2363,8 @@ MRI *LTAtransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, LTA *lta) tmp = MatrixMultiply(i2r, lta->xforms[0].m_L, NULL); if (lta->xforms[0].src.valid) { r2i = vg_r_to_i(<a->xforms[0].src); // allocated - } else { + } + else { fprintf(stderr, "INFO: LTA src geometry information missing!\n" " We assume that the src volume passed is the\n" @@ -2362,11 +2404,13 @@ MRI *LTAtransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, LTA *lta) return(MRIlinearTransformBSpline(bspline, mri_dst, lta->xforms[0].m_L)) ; }*/ - } else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { + } + else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { // must have both transform src and dst geometry information LTAchangeType(lta, LINEAR_RAS_TO_RAS); return (MRIapplyRASlinearTransformBSpline(bspline, mri_dst, lta->xforms[0].m_L)); - } else + } + else ErrorExit(ERROR_BADPARM, "LTAtransformBSpline: unknown linear transform\n"); } @@ -2389,7 +2433,8 @@ MRI *LTAtransformBSpline(const MRI_BSPLINE *bspline, MRI *mri_dst, LTA *lta) #define SPLINE_CENT "Centered Spline" /* Centered Spline filter (l2-norm) */ #define SPLINE_CENT_L2 "Centered Spline L2" /* Centered Spline filter (L2-norm) */ -extern MRI *MRIdownsample2BSpline(const MRI *mri_src, MRI *mri_dst) { +extern MRI *MRIdownsample2BSpline(const MRI *mri_src, MRI *mri_dst) +{ double *InBuffer; /* Input buffer to 1D process */ double *OutBuffer; /* Output buffer to 1D process */ double g[MAXF]; /* Coefficients of the reduce filter */ @@ -2439,7 +2484,8 @@ extern MRI *MRIdownsample2BSpline(const MRI *mri_src, MRI *mri_dst) { Reduce_1D(InBuffer, NxIn, OutBuffer, g, ng, IsCentered); // printf(" f %i z %i y %i NxOut %i width %i\n",kf,kz,ky,NxOut,mri_tmp->width); setXLine(mri_tmp, ky, kz, kf, OutBuffer); - } else { + } + else { getXLine(mri_src, ky, kz, kf, InBuffer); setXLine(mri_tmp, ky, kz, kf, InBuffer); } @@ -2471,7 +2517,8 @@ extern MRI *MRIdownsample2BSpline(const MRI *mri_src, MRI *mri_dst) { getYLine(mri_tmp, kx, kz, kf, InBuffer); Reduce_1D(InBuffer, NyIn, OutBuffer, g, ng, IsCentered); setYLine(mri_tmp2, kx, kz, kf, OutBuffer); - } else { + } + else { getYLine(mri_tmp, kx, kz, kf, InBuffer); setYLine(mri_tmp2, kx, kz, kf, InBuffer); } @@ -2513,7 +2560,8 @@ extern MRI *MRIdownsample2BSpline(const MRI *mri_src, MRI *mri_dst) { getZLine(mri_tmp2, kx, ky, kf, InBuffer); Reduce_1D(InBuffer, NzIn, OutBuffer, g, ng, IsCentered); setZLine(mri_dst, kx, ky, kf, OutBuffer); - } else { + } + else { getZLine(mri_tmp2, kx, ky, kf, InBuffer); setZLine(mri_dst, kx, ky, kf, InBuffer); } @@ -2556,7 +2604,8 @@ extern MRI *MRIdownsample2BSpline(const MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -extern MRI *MRIupsample2BSpline(const MRI *mri_src, MRI *mri_dst) { +extern MRI *MRIupsample2BSpline(const MRI *mri_src, MRI *mri_dst) +{ double *InBuffer; /* Input buffer to 1D process */ double *OutBuffer; /* Output buffer to 1D process */ double g[MAXF]; /* Coefficients of the reduce filter */ @@ -2621,7 +2670,8 @@ extern MRI *MRIupsample2BSpline(const MRI *mri_src, MRI *mri_dst) { getXLine(mri_src, ky, kz, kf, InBuffer); Expand_1D(InBuffer, NxIn, OutBuffer, h, nh, IsCentered); setXLine(mri_dst, ky, kz, kf, OutBuffer); - } else { + } + else { getXLine(mri_src, ky, kz, kf, InBuffer); setXLine(mri_dst, ky, kz, kf, InBuffer); } @@ -2648,7 +2698,8 @@ extern MRI *MRIupsample2BSpline(const MRI *mri_src, MRI *mri_dst) { getYLineStop(mri_dst, kx, kz, kf, InBuffer, NyIn); Expand_1D(InBuffer, NyIn, OutBuffer, h, nh, IsCentered); setYLine(mri_dst, kx, kz, kf, OutBuffer); - } else { + } + else { getYLine(mri_src, kx, kz, kf, InBuffer); setYLine(mri_dst, kx, kz, kf, InBuffer); } @@ -2675,7 +2726,8 @@ extern MRI *MRIupsample2BSpline(const MRI *mri_src, MRI *mri_dst) { getZLineStop(mri_dst, kx, ky, kf, InBuffer, NzIn); Expand_1D(InBuffer, NzIn, OutBuffer, h, nh, IsCentered); setZLine(mri_dst, kx, ky, kf, OutBuffer); - } else { + } + else { getZLine(mri_src, kx, ky, kf, InBuffer); setZLine(mri_dst, kx, ky, kf, InBuffer); } diff --git a/utils/mriFunctionalDataAccess.c b/utils/mriFunctionalDataAccess.c index f3f0889419d..cf7efa75830 100644 --- a/utils/mriFunctionalDataAccess.c +++ b/utils/mriFunctionalDataAccess.c @@ -90,7 +90,8 @@ FunD_tErr FunD_New(mriFunctionalDataRef *opVolume, char *isRegistrationFileName, int inScalarSize, mriVolumeRef iAnatomicalVolume, - tBoolean ibIsLeftHemisphere) { + tBoolean ibIsLeftHemisphere) +{ mriFunctionalDataRef this = NULL; FunD_tErr eResult = FunD_tErr_NoError; @@ -122,7 +123,8 @@ FunD_tErr FunD_New(mriFunctionalDataRef *opVolume, if (NULL != isRegistrationFileName) { DebugNote(("Saving registration file name")); strcpy(this->msRegistrationFileName, isRegistrationFileName); - } else { + } + else { strcpy(this->msRegistrationFileName, ""); } @@ -208,7 +210,8 @@ FunD_tErr FunD_New(mriFunctionalDataRef *opVolume, return eResult; } -FunD_tErr FunD_Delete(mriFunctionalDataRef *iopVolume) { +FunD_tErr FunD_Delete(mriFunctionalDataRef *iopVolume) +{ FunD_tErr eResult = FunD_tErr_NoError; mriFunctionalDataRef this = NULL; int column = 0; @@ -264,7 +267,8 @@ FunD_tErr FunD_Delete(mriFunctionalDataRef *iopVolume) { FunD_tErr FunD_ReshapeIfScalar_(mriFunctionalDataRef this, int inNumValues, tBoolean *obReshaped, - tBoolean ibIsLeftHemisphere) { + tBoolean ibIsLeftHemisphere) +{ FunD_tErr eResult = FunD_tErr_NoError; MRI *reshapedVolume = NULL; @@ -286,7 +290,8 @@ FunD_tErr FunD_ReshapeIfScalar_(mriFunctionalDataRef this, mri_tmp = MRIextractInto( this->mpData, NULL, 0, 0, 0, this->mpData->width / 2, this->mpData->height, this->mpData->depth, 0, 0, 0); mri_tmp2 = MRIcopyFrames(mri_tmp, NULL, 0, inNumValues - 1, 0); - } else { + } + else { mri_tmp = MRIextractInto(this->mpData, NULL, 0, @@ -340,7 +345,8 @@ FunD_tErr FunD_ReshapeIfScalar_(mriFunctionalDataRef this, return eResult; } -FunD_tErr FunD_FindAndParseStemHeader_(mriFunctionalDataRef this) { +FunD_tErr FunD_FindAndParseStemHeader_(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; tBoolean bFoundFile = FALSE; char sFileName[FunD_knPathLen] = "", *ptmp; @@ -418,23 +424,27 @@ FunD_tErr FunD_FindAndParseStemHeader_(mriFunctionalDataRef this) { nValuesRead = fscanf(pHeader, "%f", &this->mTimeResolution); bGood = (1 == nValuesRead); bSomethingRead = TRUE; - } else if (strcmp(sKeyword, "TPreStim") == 0) { + } + else if (strcmp(sKeyword, "TPreStim") == 0) { DebugNote(("Reading TPreStim")); nValuesRead = fscanf(pHeader, "%f", &fPreStimSecs); bGood = (1 == nValuesRead); bSomethingRead = TRUE; - } else if (strcmp(sKeyword, "nCond") == 0) { + } + else if (strcmp(sKeyword, "nCond") == 0) { DebugNote(("Reading nCond")); nValuesRead = fscanf(pHeader, "%d", &this->mNumConditions); bGood = (1 == nValuesRead); this->mbNullConditionPresent = TRUE; bSomethingRead = TRUE; - } else if (strcmp(sKeyword, "Nh") == 0) { + } + else if (strcmp(sKeyword, "Nh") == 0) { DebugNote(("Reading Nh")); nValuesRead = fscanf(pHeader, "%d", &this->mNumTimePoints); bGood = (1 == nValuesRead); bSomethingRead = TRUE; - } else if (strcmp(sKeyword, "SumXtX") == 0) { + } + else if (strcmp(sKeyword, "SumXtX") == 0) { DebugNote(("Reading SumXtX")); nNumValues = pow(this->mNumTimePoints * (this->mNumConditions - 1), 2); for (nValue = 0; nValue < nNumValues; nValue++) { @@ -443,7 +453,8 @@ FunD_tErr FunD_FindAndParseStemHeader_(mriFunctionalDataRef this) { } } bSomethingRead = TRUE; - } else if (strcmp(sKeyword, "hCovMtx") == 0) { + } + else if (strcmp(sKeyword, "hCovMtx") == 0) { /* Allocate the covariance matrix. It's the size of the number of time points times conditions (minus null condition) on both sides. */ @@ -497,7 +508,8 @@ FunD_tErr FunD_FindAndParseStemHeader_(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_GuessMetaInformation_(mriFunctionalDataRef this) { +FunD_tErr FunD_GuessMetaInformation_(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_GuessMetaInformation_( this=%p )", this)); @@ -524,7 +536,8 @@ FunD_tErr FunD_GuessMetaInformation_(mriFunctionalDataRef this) { FunD_tErr FunD_ParseRegistrationAndInitMatricies_(mriFunctionalDataRef this, FunD_tRegistrationType iType, - mriVolumeRef iAnatomicalVolume) { + mriVolumeRef iAnatomicalVolume) +{ FunD_tErr eResult = FunD_tErr_NoError; char sBasePath[1024] = ""; char sFileName[1024] = ""; @@ -691,7 +704,8 @@ FunD_tErr FunD_ParseRegistrationAndInitMatricies_(mriFunctionalDataRef this, return eResult; } -FunD_tErr FunD_RestoreRegistration(mriFunctionalDataRef this) { +FunD_tErr FunD_RestoreRegistration(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_RestoreRegistration( this=%p )", this)); @@ -715,7 +729,8 @@ FunD_tErr FunD_RestoreRegistration(mriFunctionalDataRef this) { } FunD_tErr FunD_SetClientCoordBounds( - mriFunctionalDataRef this, int inXMin, int inYMin, int inZMin, int inXMax, int inYMax, int inZMax) { + mriFunctionalDataRef this, int inXMin, int inYMin, int inZMin, int inXMax, int inYMax, int inZMax) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction( @@ -759,7 +774,8 @@ FunD_tErr FunD_SetClientCoordBounds( return eResult; } -FunD_tErr FunD_SetConversionMethod(mriFunctionalDataRef this, FunD_tConversionMethod iMethod) { +FunD_tErr FunD_SetConversionMethod(mriFunctionalDataRef this, FunD_tConversionMethod iMethod) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_SetConversionMethod( this=%p, iMethod=%d )", this, iMethod)); @@ -784,7 +800,8 @@ FunD_tErr FunD_SetConversionMethod(mriFunctionalDataRef this, FunD_tConversionMe return eResult; } -FunD_tErr FunD_GetSampleType(mriFunctionalDataRef this, FunD_tSampleType *oType) { +FunD_tErr FunD_GetSampleType(mriFunctionalDataRef this, FunD_tSampleType *oType) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction( @@ -813,7 +830,8 @@ FunD_tErr FunD_GetSampleType(mriFunctionalDataRef this, FunD_tSampleType *oType) return eResult; } -FunD_tErr FunD_SetSampleType(mriFunctionalDataRef this, FunD_tSampleType iType) { +FunD_tErr FunD_SetSampleType(mriFunctionalDataRef this, FunD_tSampleType iType) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_SetSampleType( this=%p, iType=%d )", this, (int)iType)); @@ -837,7 +855,8 @@ FunD_tErr FunD_SetSampleType(mriFunctionalDataRef this, FunD_tSampleType iType) return eResult; } -FunD_tErr FunD_ClientSpaceIsTkRegRAS(mriFunctionalDataRef this) { +FunD_tErr FunD_ClientSpaceIsTkRegRAS(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; MATRIX *identity = NULL; Trns_tErr eTrns = Trns_tErr_NoErr; @@ -873,7 +892,8 @@ FunD_tErr FunD_ClientSpaceIsTkRegRAS(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_IsScalar(mriFunctionalDataRef this, tBoolean *obScalar) { +FunD_tErr FunD_IsScalar(mriFunctionalDataRef this, tBoolean *obScalar) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_IsScalar( this=%p, obScalar=%p )", this, obScalar)); @@ -903,7 +923,8 @@ FunD_tErr FunD_IsScalar(mriFunctionalDataRef this, tBoolean *obScalar) { way to do this. - RKT */ #define BE_SUPA_FAST -FunD_tErr FunD_GetData(mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, int iTimePoint, float *oValue) { +FunD_tErr FunD_GetData(mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, int iTimePoint, float *oValue) +{ FunD_tErr eResult = FunD_tErr_NoError; xVoxel funcIdx; float fValue = 0; @@ -943,7 +964,8 @@ FunD_tErr FunD_GetData(mriFunctionalDataRef this, xVoxelRef iClientVox, int iCon DebugNote(("Converting client to func idx")); #endif FunD_ConvertClientToFloatFuncIdx_(this, iClientVox, &funcIdx); - } else { + } + else { xVoxl_Copy(&funcIdx, iClientVox); } @@ -975,7 +997,8 @@ FunD_tErr FunD_GetData(mriFunctionalDataRef this, xVoxelRef iClientVox, int iCon } FunD_tErr FunD_GetSampledData( - mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, int iTimePoint, float *oValue) { + mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, int iTimePoint, float *oValue) +{ FunD_tErr eResult = FunD_tErr_NoError; xVoxel funcIdx; float fValue = 0; @@ -1015,7 +1038,8 @@ FunD_tErr FunD_GetSampledData( DebugNote(("Converting client to func idx")); #endif FunD_ConvertClientToFloatFuncIdx_(this, iClientVox, &funcIdx); - } else { + } + else { xVoxl_Copy(&funcIdx, iClientVox); } @@ -1046,10 +1070,8 @@ FunD_tErr FunD_GetSampledData( return eResult; } -FunD_tErr FunD_GetDataForAllTimePoints(mriFunctionalDataRef this, - xVoxelRef iClientVox, - int iCondition, - float *oaValue) { +FunD_tErr FunD_GetDataForAllTimePoints(mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, float *oaValue) +{ FunD_tErr eResult = FunD_tErr_NoError; xVoxel funcIdx; int nTimePoint = 0; @@ -1075,7 +1097,8 @@ FunD_tErr FunD_GetDataForAllTimePoints(mriFunctionalDataRef this, if (!this->mbScalar) { DebugNote(("Converting client to func idx")); FunD_ConvertClientToFloatFuncIdx_(this, iClientVox, &funcIdx); - } else { + } + else { xVoxl_Copy(&funcIdx, iClientVox); } @@ -1101,7 +1124,8 @@ FunD_tErr FunD_GetDataForAllTimePoints(mriFunctionalDataRef this, } FunD_tErr FunD_GetDeviation( - mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, int iTimePoint, float *oValue) { + mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, int iTimePoint, float *oValue) +{ FunD_tErr eResult = FunD_tErr_NoError; xVoxel funcIdx; float fCovariance = 0; @@ -1132,7 +1156,8 @@ FunD_tErr FunD_GetDeviation( if (0 == iCondition) { DebugNote(("Setting return value")); *oValue = 0; - } else { + } + else { DebugNote(("Getting cov mtx for cond %d tp %d\n", iCondition, iTimePoint)); nCovMtx = ((iCondition - 1) * this->mNumTimePoints) + iTimePoint; fCovariance = this->mCovMtx[nCovMtx][nCovMtx]; @@ -1140,7 +1165,8 @@ FunD_tErr FunD_GetDeviation( if (!this->mbScalar) { DebugNote(("Converting client to func idx")); FunD_ConvertClientToFuncIdx_(this, iClientVox, &funcIdx); - } else { + } + else { xVoxl_Copy(&funcIdx, iClientVox); } @@ -1163,7 +1189,8 @@ FunD_tErr FunD_GetDeviation( FunD_tErr FunD_GetDeviationForAllTimePoints(mriFunctionalDataRef this, xVoxelRef iClientVox, int iCondition, - float *oaValue) { + float *oaValue) +{ FunD_tErr eResult = FunD_tErr_NoError; int nTimePoint = 0; xVoxel funcIdx; @@ -1190,7 +1217,8 @@ FunD_tErr FunD_GetDeviationForAllTimePoints(mriFunctionalDataRef this, if (!this->mbScalar) { DebugNote(("Converting client to func idx")); FunD_ConvertClientToFuncIdx_(this, iClientVox, &funcIdx); - } else { + } + else { xVoxl_Copy(&funcIdx, iClientVox); } @@ -1200,7 +1228,8 @@ FunD_tErr FunD_GetDeviationForAllTimePoints(mriFunctionalDataRef this, if (0 == iCondition) { DebugNote(("Setting return value")); oaValue[nTimePoint] = 0; - } else { + } + else { DebugNote(("Getting sigma value")); FunD_GetSigma_(this, &funcIdx, nTimePoint, &fSigma); @@ -1222,7 +1251,8 @@ FunD_tErr FunD_GetDeviationForAllTimePoints(mriFunctionalDataRef this, return eResult; } -FunD_tErr FunD_Smooth(mriFunctionalDataRef this, int iTimePoint, int iCondition, float iSigma) { +FunD_tErr FunD_Smooth(mriFunctionalDataRef this, int iTimePoint, int iCondition, float iSigma) +{ FunD_tErr eResult = FunD_tErr_NoError; MRI *kernel = NULL; @@ -1265,7 +1295,8 @@ FunD_tErr FunD_Smooth(mriFunctionalDataRef this, int iTimePoint, int iCondition, return eResult; } -FunD_tErr FunD_NormalizeOverAll(mriFunctionalDataRef this) { +FunD_tErr FunD_NormalizeOverAll(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_NormalizeOverAll( this=%p )", this)); @@ -1289,7 +1320,8 @@ FunD_tErr FunD_NormalizeOverAll(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_ConvertTimePointToSecond(mriFunctionalDataRef this, int iTimePoint, float *oSecond) { +FunD_tErr FunD_ConvertTimePointToSecond(mriFunctionalDataRef this, int iTimePoint, float *oSecond) +{ FunD_tErr eResult = FunD_tErr_NoError; float timeAtFirstPoint = 0; @@ -1323,7 +1355,8 @@ FunD_tErr FunD_ConvertTimePointToSecond(mriFunctionalDataRef this, int iTimePoin return eResult; } -FunD_tErr FunD_ConvertSecondToTimePoint(mriFunctionalDataRef this, float iSecond, int *oTimePoint) { +FunD_tErr FunD_ConvertSecondToTimePoint(mriFunctionalDataRef this, float iSecond, int *oTimePoint) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction( @@ -1353,7 +1386,8 @@ FunD_tErr FunD_ConvertSecondToTimePoint(mriFunctionalDataRef this, float iSecond return eResult; } -FunD_tErr FunD_SetTimeResolution(mriFunctionalDataRef this, float iTimeResolution) { +FunD_tErr FunD_SetTimeResolution(mriFunctionalDataRef this, float iTimeResolution) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_SetTimeResolution( this=%p, iTimeResolution=%f )", this, iTimeResolution)); @@ -1378,7 +1412,8 @@ FunD_tErr FunD_SetTimeResolution(mriFunctionalDataRef this, float iTimeResolutio return eResult; } -FunD_tErr FunD_SetNumPreStimTimePoints(mriFunctionalDataRef this, int iNumPoints) { +FunD_tErr FunD_SetNumPreStimTimePoints(mriFunctionalDataRef this, int iNumPoints) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_SetNumPreStimTimePoints( this=%p, iNumPoints=%d)", this, iNumPoints)); @@ -1403,7 +1438,8 @@ FunD_tErr FunD_SetNumPreStimTimePoints(mriFunctionalDataRef this, int iNumPoints return eResult; } -FunD_tErr FunD_GetSubjectName(mriFunctionalDataRef this, char *oSubjectName) { +FunD_tErr FunD_GetSubjectName(mriFunctionalDataRef this, char *oSubjectName) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_GetSubjectName( this=%p, oSubjectName=%s)", this, oSubjectName)); @@ -1428,7 +1464,8 @@ FunD_tErr FunD_GetSubjectName(mriFunctionalDataRef this, char *oSubjectName) { return eResult; } -FunD_tErr FunD_GetNumTimePoints(mriFunctionalDataRef this, int *oNumTimePoints) { +FunD_tErr FunD_GetNumTimePoints(mriFunctionalDataRef this, int *oNumTimePoints) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_GetNumTimePoints( this=%p, oNumTimePoints=%p)", this, oNumTimePoints)); @@ -1453,7 +1490,8 @@ FunD_tErr FunD_GetNumTimePoints(mriFunctionalDataRef this, int *oNumTimePoints) return eResult; } -FunD_tErr FunD_GetNumConditions(mriFunctionalDataRef this, int *oNumConditions) { +FunD_tErr FunD_GetNumConditions(mriFunctionalDataRef this, int *oNumConditions) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_GetNumConditions( this=%p, oNumConditions=%p)", this, oNumConditions)); @@ -1478,7 +1516,8 @@ FunD_tErr FunD_GetNumConditions(mriFunctionalDataRef this, int *oNumConditions) return eResult; } -FunD_tErr FunD_GetTimeResolution(mriFunctionalDataRef this, float *oTimeResolution) { +FunD_tErr FunD_GetTimeResolution(mriFunctionalDataRef this, float *oTimeResolution) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_Get( this=%p, oTimeResolution=%p)", this, oTimeResolution)); @@ -1503,7 +1542,8 @@ FunD_tErr FunD_GetTimeResolution(mriFunctionalDataRef this, float *oTimeResoluti return eResult; } -FunD_tErr FunD_GetNumPreStimTimePoints(mriFunctionalDataRef this, int *oNumPoints) { +FunD_tErr FunD_GetNumPreStimTimePoints(mriFunctionalDataRef this, int *oNumPoints) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_GetNumPreStimTimePoints( this=%p, oNumPoints=%p)", this, oNumPoints)); @@ -1528,7 +1568,8 @@ FunD_tErr FunD_GetNumPreStimTimePoints(mriFunctionalDataRef this, int *oNumPoint return eResult; } -FunD_tErr FunD_GetValueRange(mriFunctionalDataRef this, float *oMin, float *oMax) { +FunD_tErr FunD_GetValueRange(mriFunctionalDataRef this, float *oMin, float *oMax) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_GetValueRange( this=%p, oMin=%p, oMax=%p)", this, oMin, oMax)); @@ -1554,7 +1595,8 @@ FunD_tErr FunD_GetValueRange(mriFunctionalDataRef this, float *oMin, float *oMax return eResult; } -FunD_tErr FunD_IsErrorDataPresent(mriFunctionalDataRef this, tBoolean *oPresent) { +FunD_tErr FunD_IsErrorDataPresent(mriFunctionalDataRef this, tBoolean *oPresent) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_IsErrorDataPresent( this=%p, oPresent=%p)", this, oPresent)); @@ -1579,7 +1621,8 @@ FunD_tErr FunD_IsErrorDataPresent(mriFunctionalDataRef this, tBoolean *oPresent) return eResult; } -FunD_tErr FunD_GetBoundsInClientSpace(mriFunctionalDataRef this, xVoxelRef oBeginCorner, xVoxelRef oEndCorner) { +FunD_tErr FunD_GetBoundsInClientSpace(mriFunctionalDataRef this, xVoxelRef oBeginCorner, xVoxelRef oEndCorner) +{ FunD_tErr eResult = FunD_tErr_NoError; xVoxel curIdx; xVoxel curClient; @@ -1638,7 +1681,8 @@ FunD_tErr FunD_GetBoundsInClientSpace(mriFunctionalDataRef this, xVoxelRef oBegi return eResult; } -FunD_tErr FunD_GetValueAtPercentile(mriFunctionalDataRef this, float iPercentile, float *oValue) { +FunD_tErr FunD_GetValueAtPercentile(mriFunctionalDataRef this, float iPercentile, float *oValue) +{ FunD_tErr eResult = FunD_tErr_NoError; int numValues = 0; int targetCount = 0; @@ -1770,7 +1814,8 @@ FunD_tErr FunD_CalcFDRThreshold(mriFunctionalDataRef this, int iSign, float iRate, MRI *iMaskVolume, - float *oThresholdMin) { + float *oThresholdMin) +{ FunD_tErr eResult = FunD_tErr_NoError; int eMRI = ERROR_NONE; int nFrame = 0; @@ -1858,7 +1903,8 @@ FunD_tErr FunD_CalcFDRThreshold(mriFunctionalDataRef this, return eResult; } -FunD_tErr FunD_SaveRegistration(mriFunctionalDataRef this) { +FunD_tErr FunD_SaveRegistration(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; fMRI_REG *regInfo = NULL; struct stat fileInfo; @@ -1976,7 +2022,8 @@ FunD_tErr FunD_SaveRegistration(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_SetRegistrationToIdentity(mriFunctionalDataRef this) { +FunD_tErr FunD_SetRegistrationToIdentity(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; MATRIX *identity = NULL; @@ -2012,7 +2059,8 @@ FunD_tErr FunD_SetRegistrationToIdentity(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_ApplyTransformToRegistration(mriFunctionalDataRef this, MATRIX *iTransform) { +FunD_tErr FunD_ApplyTransformToRegistration(mriFunctionalDataRef this, MATRIX *iTransform) +{ FunD_tErr eResult = FunD_tErr_NoError; Trns_tErr eTransform = Trns_tErr_NoErr; MATRIX *invTransform = NULL; @@ -2053,7 +2101,8 @@ FunD_tErr FunD_ApplyTransformToRegistration(mriFunctionalDataRef this, MATRIX *i return eResult; } -FunD_tErr FunD_TranslateRegistration(mriFunctionalDataRef this, float ifDistance, tAxis iAxis) { +FunD_tErr FunD_TranslateRegistration(mriFunctionalDataRef this, float ifDistance, tAxis iAxis) +{ FunD_tErr eResult = FunD_tErr_NoError; Trns_tErr eTransform = Trns_tErr_NoErr; @@ -2086,7 +2135,8 @@ FunD_tErr FunD_TranslateRegistration(mriFunctionalDataRef this, float ifDistance return eResult; } -FunD_tErr FunD_RotateRegistration(mriFunctionalDataRef this, float ifDegrees, tAxis iAxis, xVoxelRef iCenterFuncRAS) { +FunD_tErr FunD_RotateRegistration(mriFunctionalDataRef this, float ifDegrees, tAxis iAxis, xVoxelRef iCenterFuncRAS) +{ FunD_tErr eResult = FunD_tErr_NoError; Trns_tErr eTransform = Trns_tErr_NoErr; float fX = 0; @@ -2141,7 +2191,8 @@ FunD_tErr FunD_RotateRegistration(mriFunctionalDataRef this, float ifDegrees, tA return eResult; } -FunD_tErr FunD_ScaleRegistration(mriFunctionalDataRef this, float ifFactor, tAxis iAxis) { +FunD_tErr FunD_ScaleRegistration(mriFunctionalDataRef this, float ifFactor, tAxis iAxis) +{ FunD_tErr eResult = FunD_tErr_NoError; Trns_tErr eTransform = Trns_tErr_NoErr; @@ -2174,7 +2225,8 @@ FunD_tErr FunD_ScaleRegistration(mriFunctionalDataRef this, float ifFactor, tAxi return eResult; } -FunD_tErr FunD_DebugPrint(mriFunctionalDataRef this) { +FunD_tErr FunD_DebugPrint(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_DebugPrint( this=%p )", this)); @@ -2216,7 +2268,8 @@ FunD_tErr FunD_DebugPrint(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_ResampleData_(mriFunctionalDataRef this) { +FunD_tErr FunD_ResampleData_(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; MRI *volume = NULL; int nTimePoint = 0; @@ -2266,13 +2319,15 @@ FunD_tErr FunD_ResampleData_(mriFunctionalDataRef this) { if (!this->mbScalar) { DebugNote(("Converting client to func idx")); FunD_ConvertClientToFuncIdx_(this, &clientIdx, &funcIdx); - } else { + } + else { xVoxl_Copy(&funcIdx, &clientIdx); } eResult = FunD_VerifyFuncIdx_(this, &funcIdx); if (FunD_tErr_NoError == eResult) { FunD_GetValue_(this, this->mpData, &funcIdx, nCondition, nTimePoint, &value); - } else { + } + else { continue; } @@ -2307,7 +2362,8 @@ FunD_tErr FunD_ResampleData_(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_CalcFrequencies_(mriFunctionalDataRef this, int iNumBins) { +FunD_tErr FunD_CalcFrequencies_(mriFunctionalDataRef this, int iNumBins) +{ FunD_tErr eResult = FunD_tErr_NoError; int *aFrequencies = NULL; int nCondition = 0; @@ -2371,7 +2427,8 @@ FunD_tErr FunD_CalcFrequencies_(mriFunctionalDataRef this, int iNumBins) { return eResult; } -char *FunD_GetErrorString(FunD_tErr iErr) { +char *FunD_GetErrorString(FunD_tErr iErr) +{ if (!(iErr >= 0 && iErr < FunD_tErr_knNumErrorCodes)) { iErr = FunD_tErr_InvalidErrorCode; } @@ -2381,7 +2438,8 @@ char *FunD_GetErrorString(FunD_tErr iErr) { #ifndef FUND_USE_MACROS -void FunD_ConvertClientToFuncIdx_(mriFunctionalDataRef this, xVoxelRef iClientVox, xVoxelRef oFuncIdx) { +void FunD_ConvertClientToFuncIdx_(mriFunctionalDataRef this, xVoxelRef iClientVox, xVoxelRef oFuncIdx) +{ Trns_tErr eTransform = Trns_tErr_NoErr; DebugEnterFunction( @@ -2435,7 +2493,8 @@ void FunD_ConvertClientToFuncIdx_(mriFunctionalDataRef this, xVoxelRef iClientVo DebugExitFunction; } -void FunD_ConvertClientToFloatFuncIdx_(mriFunctionalDataRef this, xVoxelRef iClientVox, xVoxelRef oFuncIdx) { +void FunD_ConvertClientToFloatFuncIdx_(mriFunctionalDataRef this, xVoxelRef iClientVox, xVoxelRef oFuncIdx) +{ Trns_tErr eTransform = Trns_tErr_NoErr; DebugEnterFunction( @@ -2464,7 +2523,8 @@ void FunD_ConvertClientToFloatFuncIdx_(mriFunctionalDataRef this, xVoxelRef iCli #endif -void FunD_ConvertClientToFuncRAS_(mriFunctionalDataRef this, xVoxelRef iClientVox, xVoxelRef oFuncRAS) { +void FunD_ConvertClientToFuncRAS_(mriFunctionalDataRef this, xVoxelRef iClientVox, xVoxelRef oFuncRAS) +{ Trns_tErr eTransform = Trns_tErr_NoErr; DebugEnterFunction( @@ -2498,7 +2558,8 @@ void FunD_ConvertClientToFuncRAS_(mriFunctionalDataRef this, xVoxelRef iClientVo DebugExitFunction; } -void FunD_ConvertFuncIdxToClient_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, xVoxelRef oClientVox) { +void FunD_ConvertFuncIdxToClient_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, xVoxelRef oClientVox) +{ Trns_tErr eTransform = Trns_tErr_NoErr; DebugEnterFunction( @@ -2528,7 +2589,8 @@ void FunD_ConvertFuncIdxToClient_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, DebugExitFunction; } -void FunD_ConvertRASToFuncIdx_(mriFunctionalDataRef this, xVoxelRef iRAS, xVoxelRef oFuncIdx) { +void FunD_ConvertRASToFuncIdx_(mriFunctionalDataRef this, xVoxelRef iRAS, xVoxelRef oFuncIdx) +{ Trns_tErr eTransform = Trns_tErr_NoErr; DebugEnterFunction( @@ -2582,7 +2644,8 @@ void FunD_ConvertRASToFuncIdx_(mriFunctionalDataRef this, xVoxelRef iRAS, xVoxel DebugExitFunction; } -void FunD_ConvertFuncIdxToFuncRAS_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, xVoxelRef oFuncRAS) { +void FunD_ConvertFuncIdxToFuncRAS_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, xVoxelRef oFuncRAS) +{ Trns_tErr eTransform = Trns_tErr_NoErr; DebugEnterFunction( @@ -2615,7 +2678,8 @@ void FunD_ConvertFuncIdxToFuncRAS_(mriFunctionalDataRef this, xVoxelRef iFuncIdx #ifndef FUND_USE_MACROS void FunD_GetValue_( - mriFunctionalDataRef this, MRI *iData, xVoxelRef iIdx, int inCondition, int inTimePoint, float *oValue) { + mriFunctionalDataRef this, MRI *iData, xVoxelRef iIdx, int inCondition, int inTimePoint, float *oValue) +{ int nFrame = 0; FunD_GetDataFrameNumber(inCondition, inTimePoint, &nFrame); @@ -2661,7 +2725,8 @@ void FunD_GetValue_( } void FunD_GetSampledValue_( - mriFunctionalDataRef this, MRI *iData, xVoxelRef iIdx, int inCondition, int inTimePoint, float *oValue) { + mriFunctionalDataRef this, MRI *iData, xVoxelRef iIdx, int inCondition, int inTimePoint, float *oValue) +{ int nFrame = 0; FunD_GetDataFrameNumber(inCondition, inTimePoint, &nFrame); @@ -2678,7 +2743,8 @@ void FunD_GetSampledValue_( } void FunD_SetValue_( - mriFunctionalDataRef this, MRI *iData, xVoxelRef iIdx, int inCondition, int inTimePoint, float iValue) { + mriFunctionalDataRef this, MRI *iData, xVoxelRef iIdx, int inCondition, int inTimePoint, float iValue) +{ int nFrame = 0; FunD_GetDataFrameNumber(inCondition, inTimePoint, &nFrame); @@ -2706,7 +2772,8 @@ void FunD_SetValue_( #endif /* FUND_USE_MACROS */ -void FunD_GetSigma_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, int inTimePoint, float *oSigma) { +void FunD_GetSigma_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, int inTimePoint, float *oSigma) +{ int nFrame = 0; FunD_GetSigmaFrameNumber(inTimePoint, &nFrame); @@ -2733,7 +2800,8 @@ void FunD_GetSigma_(mriFunctionalDataRef this, xVoxelRef iFuncIdx, int inTimePoi } } -FunD_tErr FunD_Verify(mriFunctionalDataRef this) { +FunD_tErr FunD_Verify(mriFunctionalDataRef this) +{ FunD_tErr eResult = FunD_tErr_NoError; // DebugEnterFunction( ("FunD_Verify( this=%p )", this) ); @@ -2750,7 +2818,8 @@ FunD_tErr FunD_Verify(mriFunctionalDataRef this) { return eResult; } -FunD_tErr FunD_VerifyFuncIdx_(mriFunctionalDataRef this, xVoxelRef iFuncIdx) { +FunD_tErr FunD_VerifyFuncIdx_(mriFunctionalDataRef this, xVoxelRef iFuncIdx) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugAssertThrowX((NULL != this && NULL != iFuncIdx), eResult, FunD_tErr_InvalidParameter); @@ -2768,7 +2837,8 @@ FunD_tErr FunD_VerifyFuncIdx_(mriFunctionalDataRef this, xVoxelRef iFuncIdx) { return eResult; } -FunD_tErr FunD_VerifyTimePoint(mriFunctionalDataRef this, int iTimePoint) { +FunD_tErr FunD_VerifyTimePoint(mriFunctionalDataRef this, int iTimePoint) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_VerifyTimePoint( this=%p, iTimePoint=%p )", this, iTimePoint)); @@ -2787,7 +2857,8 @@ FunD_tErr FunD_VerifyTimePoint(mriFunctionalDataRef this, int iTimePoint) { return eResult; } -FunD_tErr FunD_VerifyCondition(mriFunctionalDataRef this, int iCondition) { +FunD_tErr FunD_VerifyCondition(mriFunctionalDataRef this, int iCondition) +{ FunD_tErr eResult = FunD_tErr_NoError; DebugEnterFunction(("FunD_VerifyTimePoint( this=%p, iCondition=%p )", this, iCondition)); diff --git a/utils/mriHeadPointList.c b/utils/mriHeadPointList.c index 0a7ff9f853a..2c07f9a0a4b 100644 --- a/utils/mriHeadPointList.c +++ b/utils/mriHeadPointList.c @@ -43,7 +43,8 @@ char *HPtL_ksaErrorStrings[HPtL_knNumErrorCodes] = { "Last point.", "Invalid error code."}; -HPtL_tErr HPtL_New(mriHeadPointListRef *oList, char *isListName, char *isTransformName, MATRIX *iClientTransform) { +HPtL_tErr HPtL_New(mriHeadPointListRef *oList, char *isListName, char *isTransformName, MATRIX *iClientTransform) +{ mriHeadPointListRef this = NULL; HPtL_tErr eResult = HPtL_tErr_NoErr; @@ -130,7 +131,8 @@ HPtL_tErr HPtL_New(mriHeadPointListRef *oList, char *isListName, char *isTransfo return eResult; } -HPtL_tErr HPtL_Delete(mriHeadPointListRef *iopList) { +HPtL_tErr HPtL_Delete(mriHeadPointListRef *iopList) +{ mriHeadPointListRef this = NULL; HPtL_tErr eResult = HPtL_tErr_NoErr; @@ -174,7 +176,8 @@ HPtL_tErr HPtL_Delete(mriHeadPointListRef *iopList) { return eResult; } -HPtL_tErr HPtL_ReadHeadListFile_(mriHeadPointListRef this, char *isListName) { +HPtL_tErr HPtL_ReadHeadListFile_(mriHeadPointListRef this, char *isListName) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; FILE *file = NULL; char sLine[1024] = ""; @@ -266,7 +269,8 @@ HPtL_tErr HPtL_ReadHeadListFile_(mriHeadPointListRef this, char *isListName) { return eResult; } -HPtL_tErr HPtL_CreateTransform_(mriHeadPointListRef this, char *isTransformName, MATRIX *iClientTransform) { +HPtL_tErr HPtL_CreateTransform_(mriHeadPointListRef this, char *isTransformName, MATRIX *iClientTransform) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; char sTransformName[256] = ""; char *psSuffix = NULL; @@ -310,11 +314,13 @@ HPtL_tErr HPtL_CreateTransform_(mriHeadPointListRef this, char *isTransformName, if (NULL != psSuffix) { DebugNote(("Creating transform name. Replacing .hpts with .trans")); strcpy(psSuffix, ".trans"); - } else { + } + else { eResult = HPtL_tErr_InvalidParameter; goto error; } - } else { + } + else { DebugNote(("Copying transform name")); strcpy(sTransformName, isTransformName); } @@ -419,7 +425,8 @@ HPtL_tErr HPtL_CreateTransform_(mriHeadPointListRef this, char *isTransformName, return eResult; } -HPtL_tErr HPtL_ConvertListToClientSpace_(mriHeadPointListRef this) { +HPtL_tErr HPtL_ConvertListToClientSpace_(mriHeadPointListRef this) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; HPtL_tHeadPointRef pHeadPt = NULL; @@ -462,7 +469,8 @@ HPtL_tErr HPtL_ConvertListToClientSpace_(mriHeadPointListRef this) { return eResult; } -HPtL_tErr HPtL_WriteTransform(mriHeadPointListRef this, char *isDest) { +HPtL_tErr HPtL_WriteTransform(mriHeadPointListRef this, char *isDest) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; char sTransform[256] = ""; MATRIX *mTmp = NULL; @@ -482,7 +490,8 @@ HPtL_tErr HPtL_WriteTransform(mriHeadPointListRef this, char *isDest) { /* if null arg, use saved transform name */ if (NULL == isDest) { strcpy(sTransform, this->msTransformFile); - } else { + } + else { strcpy(sTransform, isDest); } @@ -536,7 +545,8 @@ HPtL_tErr HPtL_WriteTransform(mriHeadPointListRef this, char *isDest) { return eResult; } -HPtL_tErr HPtL_WriteHeadPointFile(mriHeadPointListRef this, char *isDest) { +HPtL_tErr HPtL_WriteHeadPointFile(mriHeadPointListRef this, char *isDest) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; char sFilename[256] = ""; FILE *file = NULL; @@ -550,7 +560,8 @@ HPtL_tErr HPtL_WriteHeadPointFile(mriHeadPointListRef this, char *isDest) { /* if null arg, use saved name */ if (NULL == isDest) { strcpy(sFilename, this->msPointFile); - } else { + } + else { strcpy(sFilename, isDest); } /* attempt to open the file */ @@ -590,7 +601,8 @@ HPtL_tErr HPtL_WriteHeadPointFile(mriHeadPointListRef this, char *isDest) { HPtL_tErr HPtL_ResetIterator(mriHeadPointListRef this, HPtL_tIterationPlane iPlane, float ifPlaneNumber, - float ifPlaneRange) { + float ifPlaneRange) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; eResult = HPtL_Verify(this); @@ -619,7 +631,8 @@ HPtL_tErr HPtL_ResetIterator(mriHeadPointListRef this, return eResult; } -HPtL_tErr HPtL_NextPoint(mriHeadPointListRef this, HPtL_tHeadPointRef *opPoint) { +HPtL_tErr HPtL_NextPoint(mriHeadPointListRef this, HPtL_tHeadPointRef *opPoint) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; HPtL_tHeadPointRef point = NULL; tBoolean bGoodPoint = FALSE; @@ -686,7 +699,8 @@ HPtL_tErr HPtL_FindNearestPoint(mriHeadPointListRef this, HPtL_tIterationPlane iPlane, float ifPlaneRange, xVoxelRef iWhere, - HPtL_tHeadPointRef *opPoint) { + HPtL_tHeadPointRef *opPoint) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; float fPlane = 0; HPtL_tHeadPointRef pPoint = NULL; @@ -766,7 +780,8 @@ HPtL_tErr HPtL_FindNearestPoint(mriHeadPointListRef this, HPtL_tErr HPtL_FindFlattenedNearestPoint(mriHeadPointListRef this, HPtL_tIterationPlane iPlane, xVoxelRef iWhere, - HPtL_tHeadPointRef *opPoint) { + HPtL_tHeadPointRef *opPoint) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; float fDistance = 0; HPtL_tHeadPointRef pNearestPoint = NULL; @@ -830,7 +845,8 @@ HPtL_tErr HPtL_FindFlattenedNearestPoint(mriHeadPointListRef this, return eResult; } -HPtL_tErr HPtL_RestoreTransform(mriHeadPointListRef this) { +HPtL_tErr HPtL_RestoreTransform(mriHeadPointListRef this) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; Trns_tErr eTransform = Trns_tErr_NoErr; MATRIX *mTransform = NULL; @@ -867,7 +883,8 @@ HPtL_tErr HPtL_RestoreTransform(mriHeadPointListRef this) { return eResult; } -HPtL_tErr HPtL_ApplyTransform(mriHeadPointListRef this, MATRIX *iTransform) { +HPtL_tErr HPtL_ApplyTransform(mriHeadPointListRef this, MATRIX *iTransform) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; Trns_tErr eTransform = Trns_tErr_NoErr; @@ -910,7 +927,8 @@ HPtL_tErr HPtL_ApplyTransform(mriHeadPointListRef this, MATRIX *iTransform) { return eResult; } -HPtL_tErr HPtL_Translate(mriHeadPointListRef this, float ifDistance, tAxis iAxis) { +HPtL_tErr HPtL_Translate(mriHeadPointListRef this, float ifDistance, tAxis iAxis) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; Trns_tErr eTransform = Trns_tErr_NoErr; @@ -948,7 +966,8 @@ HPtL_tErr HPtL_Translate(mriHeadPointListRef this, float ifDistance, tAxis iAxis return eResult; } -HPtL_tErr HPtL_Rotate(mriHeadPointListRef this, float ifDegrees, tAxis iAxis) { +HPtL_tErr HPtL_Rotate(mriHeadPointListRef this, float ifDegrees, tAxis iAxis) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; Trns_tErr eTransform = Trns_tErr_NoErr; @@ -986,7 +1005,8 @@ HPtL_tErr HPtL_Rotate(mriHeadPointListRef this, float ifDegrees, tAxis iAxis) { return eResult; } -HPtL_tErr HPtL_Scale(mriHeadPointListRef this, float ifFactor, tAxis iAxis) { +HPtL_tErr HPtL_Scale(mriHeadPointListRef this, float ifFactor, tAxis iAxis) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; Trns_tErr eTransform = Trns_tErr_NoErr; @@ -1024,7 +1044,8 @@ HPtL_tErr HPtL_Scale(mriHeadPointListRef this, float ifFactor, tAxis iAxis) { return eResult; } -HPtL_tErr HPtL_AlignPointToClientVoxel(mriHeadPointListRef this, HPtL_tHeadPointRef iPoint, xVoxelRef iClientVox) { +HPtL_tErr HPtL_AlignPointToClientVoxel(mriHeadPointListRef this, HPtL_tHeadPointRef iPoint, xVoxelRef iClientVox) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; xVoxel destPt; xVoxel srcPt; @@ -1096,7 +1117,8 @@ HPtL_tErr HPtL_AlignPointToClientVoxel(mriHeadPointListRef this, HPtL_tHeadPoint return eResult; } -HPtL_tErr HPtL_Verify(mriHeadPointListRef this) { +HPtL_tErr HPtL_Verify(mriHeadPointListRef this) +{ HPtL_tErr eResult = HPtL_tErr_NoErr; /* check for null ptr */ @@ -1116,7 +1138,8 @@ HPtL_tErr HPtL_Verify(mriHeadPointListRef this) { return eResult; } -char *HPtL_GetErrorString(HPtL_tErr ieCode) { +char *HPtL_GetErrorString(HPtL_tErr ieCode) +{ HPtL_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= HPtL_knNumErrorCodes) { diff --git a/utils/mriSurface.c b/utils/mriSurface.c index 22d60ed984d..e054be188b4 100644 --- a/utils/mriSurface.c +++ b/utils/mriSurface.c @@ -45,7 +45,8 @@ char *Surf_ksaVertexSets[Surf_knNumVertexSets] = {"main", "original", "pial"}; static xVoxel sTmpVertex; -Surf_tErr Surf_New(mriSurfaceRef *opSurface, char *isFileName) { +Surf_tErr Surf_New(mriSurfaceRef *opSurface, char *isFileName) +{ mriSurfaceRef this = NULL; Surf_tErr eResult = Surf_tErr_NoErr; mriTransformRef transform = NULL; @@ -129,7 +130,8 @@ Surf_tErr Surf_New(mriSurfaceRef *opSurface, char *isFileName) { return eResult; } -Surf_tErr Surf_Delete(mriSurfaceRef *iopSurface) { +Surf_tErr Surf_Delete(mriSurfaceRef *iopSurface) +{ mriSurfaceRef this = NULL; Surf_tErr eResult = Surf_tErr_NoErr; @@ -176,7 +178,8 @@ Surf_tErr Surf_Delete(mriSurfaceRef *iopSurface) { return eResult; } -Surf_tErr Surf_SetTransform(mriSurfaceRef this, mriTransformRef iTransform) { +Surf_tErr Surf_SetTransform(mriSurfaceRef this, mriTransformRef iTransform) +{ Surf_tErr eResult = Surf_tErr_NoErr; eResult = Surf_Verify(this); @@ -214,7 +217,8 @@ Surf_tErr Surf_SetTransform(mriSurfaceRef this, mriTransformRef iTransform) { return eResult; } -Surf_tErr Surf_LoadVertexSet(mriSurfaceRef this, char *isName, Surf_tVertexSet iSet) { +Surf_tErr Surf_LoadVertexSet(mriSurfaceRef this, char *isName, Surf_tVertexSet iSet) +{ Surf_tErr eResult = Surf_tErr_NoErr; int eMRIS = NO_ERROR; @@ -275,7 +279,8 @@ Surf_tErr Surf_LoadVertexSet(mriSurfaceRef this, char *isName, Surf_tVertexSet i return eResult; } -Surf_tErr Surf_WriteValues(mriSurfaceRef this, char *isFileName) { +Surf_tErr Surf_WriteValues(mriSurfaceRef this, char *isFileName) +{ Surf_tErr eResult = Surf_tErr_NoErr; int vno; @@ -307,7 +312,8 @@ Surf_tErr Surf_WriteValues(mriSurfaceRef this, char *isFileName) { return eResult; } -Surf_tErr Surf_IsVertexSetLoaded(mriSurfaceRef this, Surf_tVertexSet iSet, tBoolean *obIsLoaded) { +Surf_tErr Surf_IsVertexSetLoaded(mriSurfaceRef this, Surf_tVertexSet iSet, tBoolean *obIsLoaded) +{ Surf_tErr eResult = Surf_tErr_NoErr; eResult = Surf_Verify(this); @@ -331,7 +337,8 @@ Surf_tErr Surf_IsVertexSetLoaded(mriSurfaceRef this, Surf_tVertexSet iSet, tBool return eResult; } -Surf_tErr Surf_LoadAnnotation(mriSurfaceRef this, char *isFileName) { +Surf_tErr Surf_LoadAnnotation(mriSurfaceRef this, char *isFileName) +{ Surf_tErr eResult = Surf_tErr_NoErr; int eMRIS = NO_ERROR; @@ -361,7 +368,8 @@ Surf_tErr Surf_LoadAnnotation(mriSurfaceRef this, char *isFileName) { return eResult; } -Surf_tErr Surf_IsInternalColorTablePresent(mriSurfaceRef this, tBoolean *obPresent) { +Surf_tErr Surf_IsInternalColorTablePresent(mriSurfaceRef this, tBoolean *obPresent) +{ Surf_tErr eResult = Surf_tErr_NoErr; eResult = Surf_Verify(this); @@ -385,7 +393,8 @@ Surf_tErr Surf_IsInternalColorTablePresent(mriSurfaceRef this, tBoolean *obPrese return eResult; } -Surf_tErr Surf_NewColorTableFromInternal(mriSurfaceRef this, COLOR_TABLE **opTable) { +Surf_tErr Surf_NewColorTableFromInternal(mriSurfaceRef this, COLOR_TABLE **opTable) +{ Surf_tErr eResult = Surf_tErr_NoErr; COLOR_TABLE *colorTable = NULL; @@ -420,7 +429,8 @@ Surf_tErr Surf_NewColorTableFromInternal(mriSurfaceRef this, COLOR_TABLE **opTab return eResult; } -Surf_tErr Surf_ConvertSurfaceToClientSpace_(mriSurfaceRef this, Surf_tVertexSet iSet) { +Surf_tErr Surf_ConvertSurfaceToClientSpace_(mriSurfaceRef this, Surf_tVertexSet iSet) +{ Surf_tErr eResult = Surf_tErr_NoErr; int nFaceIdx = 0; face_type *face = NULL; @@ -496,7 +506,8 @@ Surf_tErr Surf_ConvertSurfaceToClientSpace_(mriSurfaceRef this, Surf_tVertexSet return eResult; } -Surf_tErr Surf_SetIteratorPosition(mriSurfaceRef this, xVoxelRef iPlane) { +Surf_tErr Surf_SetIteratorPosition(mriSurfaceRef this, xVoxelRef iPlane) +{ Surf_tErr eResult = Surf_tErr_NoErr; eResult = Surf_Verify(this); @@ -508,10 +519,12 @@ Surf_tErr Surf_SetIteratorPosition(mriSurfaceRef this, xVoxelRef iPlane) { if (xVoxl_GetFloatX(iPlane) != 0) { this->mIterOrientation = Surf_tOrientation_X; this->mfIterPlane = xVoxl_GetFloatX(iPlane); - } else if (xVoxl_GetFloatY(iPlane) != 0) { + } + else if (xVoxl_GetFloatY(iPlane) != 0) { this->mIterOrientation = Surf_tOrientation_Y; this->mfIterPlane = xVoxl_GetFloatY(iPlane); - } else if (xVoxl_GetFloatZ(iPlane) != 0) { + } + else if (xVoxl_GetFloatZ(iPlane) != 0) { this->mIterOrientation = Surf_tOrientation_Z; this->mfIterPlane = xVoxl_GetFloatZ(iPlane); } @@ -538,7 +551,8 @@ Surf_tErr Surf_GetNextAndNeighborVertex(mriSurfaceRef this, xVoxelRef oNextVoxel, int *onNextIndex, xVoxelRef oNeighborVoxel, - int *onNeighborIndex) { + int *onNeighborIndex) +{ Surf_tErr eResult = Surf_tErr_NoErr; tBoolean bFaceFound = FALSE; Surf_tFaceRef face = NULL; @@ -586,7 +600,8 @@ Surf_tErr Surf_GetNextAndNeighborVertex(mriSurfaceRef this, less than some amount, use this face. */ if (fabs(fVertexPlane - this->mfIterPlane) <= this->mfLongestEdge) { bFaceFound = TRUE; - } else { + } + else { this->mnCurFace++; } } @@ -648,7 +663,8 @@ Surf_tErr Surf_GetNextAndNeighborVertex(mriSurfaceRef this, return eResult; } -Surf_tErr Surf_CopyGeometryInformation(mriSurfaceRef this, VOL_GEOM *ioVolumeGeometry) { +Surf_tErr Surf_CopyGeometryInformation(mriSurfaceRef this, VOL_GEOM *ioVolumeGeometry) +{ Surf_tErr eResult = Surf_tErr_NoErr; DebugEnterFunction( @@ -676,7 +692,8 @@ Surf_tErr Surf_CopyGeometryInformation(mriSurfaceRef this, VOL_GEOM *ioVolumeGeo return eResult; } -Surf_tErr Surf_TransformToVolumeGeometry(mriSurfaceRef this, VOL_GEOM *iVolumeGeometry) { +Surf_tErr Surf_TransformToVolumeGeometry(mriSurfaceRef this, VOL_GEOM *iVolumeGeometry) +{ Surf_tErr eResult = Surf_tErr_NoErr; int eMRIS = ERROR_NONE; MRI *mri = NULL; @@ -737,7 +754,8 @@ Surf_tErr Surf_TransformToVolumeGeometry(mriSurfaceRef this, VOL_GEOM *iVolumeGe } Surf_tErr Surf_GetNthVertex( - mriSurfaceRef this, Surf_tVertexSet iSet, int inIndex, xVoxelRef oVoxel, char *osDescription) { + mriSurfaceRef this, Surf_tVertexSet iSet, int inIndex, xVoxelRef oVoxel, char *osDescription) +{ Surf_tErr eResult = Surf_tErr_NoErr; vertex_type *vertex = NULL; @@ -785,7 +803,8 @@ Surf_tErr Surf_GetNthVertex( } Surf_tErr Surf_GetClosestVertexVoxel( - mriSurfaceRef this, Surf_tVertexSet iSet, xVoxelRef iClientVoxel, xVoxelRef oClientVoxel, char *osDescription) { + mriSurfaceRef this, Surf_tVertexSet iSet, xVoxelRef iClientVoxel, xVoxelRef oClientVoxel, char *osDescription) +{ Surf_tErr eResult = Surf_tErr_NoErr; xVoxel surfaceVoxel; vertex_type *vertex = NULL; @@ -832,7 +851,8 @@ Surf_tErr Surf_GetClosestVertexVoxel( return eResult; } -float Surf_GetVertexCoord(vertex_type *iVertex, Surf_tVertexSet iSet, Surf_tOrientation iOrientation) { +float Surf_GetVertexCoord(vertex_type *iVertex, Surf_tVertexSet iSet, Surf_tOrientation iOrientation) +{ switch (iSet) { case Surf_tVertexSet_Main: switch (iOrientation) { @@ -886,7 +906,8 @@ float Surf_GetVertexCoord(vertex_type *iVertex, Surf_tVertexSet iSet, Surf_tOrie } Surf_tErr Surf_SetVertexValue( - mriSurfaceRef this, Surf_tVertexSet iVertexSet, Surf_tValueSet iValueSet, xVoxelRef iClientVoxel, float iValue) { + mriSurfaceRef this, Surf_tVertexSet iVertexSet, Surf_tValueSet iValueSet, xVoxelRef iClientVoxel, float iValue) +{ Surf_tErr eResult = Surf_tErr_NoErr; xVoxel surfaceVoxel; VERTEX *vertex = NULL; @@ -939,7 +960,8 @@ Surf_tErr Surf_SetVertexValue( } Surf_tErr Surf_GetVertexValue( - mriSurfaceRef this, Surf_tVertexSet iVertexSet, Surf_tValueSet iValueSet, xVoxelRef iClientVoxel, float *opValue) { + mriSurfaceRef this, Surf_tVertexSet iVertexSet, Surf_tValueSet iValueSet, xVoxelRef iClientVoxel, float *opValue) +{ Surf_tErr eResult = Surf_tErr_NoErr; xVoxel surfaceVoxel; VERTEX *vertex = NULL; @@ -981,7 +1003,8 @@ Surf_tErr Surf_GetVertexValue( return eResult; } -Surf_tErr Surf_GetVertexAnnotationByIndex(mriSurfaceRef this, int iVertexIndex, int *oAnnotation) { +Surf_tErr Surf_GetVertexAnnotationByIndex(mriSurfaceRef this, int iVertexIndex, int *oAnnotation) +{ Surf_tErr eResult = Surf_tErr_NoErr; eResult = Surf_Verify(this); @@ -1011,7 +1034,8 @@ Surf_tErr Surf_GetVertexAnnotationByIndex(mriSurfaceRef this, int iVertexIndex, return eResult; } -Surf_tErr Surf_GetDistance(mriSurfaceRef this, xVoxelRef iClientVoxel1, xVoxelRef iClientVoxel2, float *ofDistance) { +Surf_tErr Surf_GetDistance(mriSurfaceRef this, xVoxelRef iClientVoxel1, xVoxelRef iClientVoxel2, float *ofDistance) +{ Surf_tErr eResult = Surf_tErr_NoErr; xVoxel surfaceVoxel1; xVoxel surfaceVoxel2; @@ -1051,7 +1075,8 @@ Surf_tErr Surf_GetDistance(mriSurfaceRef this, xVoxelRef iClientVoxel1, xVoxelRe return eResult; } -Surf_tErr Surf_GetMRIS(mriSurfaceRef this, MRIS **opSurface) { +Surf_tErr Surf_GetMRIS(mriSurfaceRef this, MRIS **opSurface) +{ Surf_tErr eResult = Surf_tErr_NoErr; eResult = Surf_Verify(this); @@ -1075,7 +1100,8 @@ Surf_tErr Surf_GetMRIS(mriSurfaceRef this, MRIS **opSurface) { return eResult; } -Surf_tErr Surf_GetSurfaceSetName(Surf_tVertexSet iSet, char *osName) { +Surf_tErr Surf_GetSurfaceSetName(Surf_tVertexSet iSet, char *osName) +{ Surf_tErr eResult = Surf_tErr_NoErr; if (iSet < 0 || iSet >= Surf_knNumVertexSets || NULL == osName) { @@ -1098,7 +1124,8 @@ Surf_tErr Surf_GetSurfaceSetName(Surf_tVertexSet iSet, char *osName) { return eResult; } -Surf_tErr Surf_UsesRealRAS(mriSurfaceRef this, tBoolean *obUseRealRAS) { +Surf_tErr Surf_UsesRealRAS(mriSurfaceRef this, tBoolean *obUseRealRAS) +{ Surf_tErr eResult = Surf_tErr_NoErr; eResult = Surf_Verify(this); @@ -1121,7 +1148,8 @@ Surf_tErr Surf_UsesRealRAS(mriSurfaceRef this, tBoolean *obUseRealRAS) { return eResult; } -Surf_tErr Surf_AverageVertexPositions(mriSurfaceRef this, int inNumAverages) { +Surf_tErr Surf_AverageVertexPositions(mriSurfaceRef this, int inNumAverages) +{ Surf_tErr eResult = Surf_tErr_NoErr; int eMRIS = NO_ERROR; @@ -1162,7 +1190,8 @@ void Surf_GetClosestVertex(mriSurfaceRef this, xVoxelRef iSurfaceVoxel, vertex_type **opVertex, int *onIndex, - float *ofDistance) { + float *ofDistance) +{ vertex_type *currentVertex = NULL; int nVertex = 0; int nBestVertex = -1; @@ -1221,10 +1250,8 @@ void Surf_GetClosestVertex(mriSurfaceRef this, return; } -void Surf_ConvertVertexToVoxel(vertex_type *iVertex, - Surf_tVertexSet iSet, - mriTransformRef iTransform, - xVoxelRef oVoxel) { +void Surf_ConvertVertexToVoxel(vertex_type *iVertex, Surf_tVertexSet iSet, mriTransformRef iTransform, xVoxelRef oVoxel) +{ /* if we don't have a transform, just copy vertex into voxel */ if (NULL == iTransform) { oVoxel->mfX = ((iSet == Surf_tVertexSet_Main) ? iVertex->x @@ -1239,7 +1266,8 @@ void Surf_ConvertVertexToVoxel(vertex_type *iVertex, Surf_GetVertexCoord( iVertex, iSet, Surf_tOrientation_Y ), Surf_GetVertexCoord( iVertex, iSet, Surf_tOrientation_Z )); #endif - } else { + } + else { /* stuff the vertex into a voxel */ #if 0 xVoxl_SetFloat( &sTmpVertex, @@ -1269,7 +1297,8 @@ void Surf_ConvertVertexToVoxel(vertex_type *iVertex, } } -void Surf_ConvertVoxelToSurfaceSpace(xVoxelRef iVoxel, mriTransformRef iTransform, xVoxelRef oSurfVox) { +void Surf_ConvertVoxelToSurfaceSpace(xVoxelRef iVoxel, mriTransformRef iTransform, xVoxelRef oSurfVox) +{ #if 0 static MATRIX * BtoRAS = NULL; static MATRIX * tmp1 = NULL; @@ -1279,7 +1308,8 @@ void Surf_ConvertVoxelToSurfaceSpace(xVoxelRef iVoxel, mriTransformRef iTransfor /* if we don't have a transform, just copy vertex into voxel */ if (NULL == iTransform) { xVoxl_Copy(oSurfVox, iVoxel); - } else { + } + else { /* transform voxel */ /* RKT: In the opposite of this function, CovertVertexToVoxel, we use CovertBRAStoB, so we'll use ConvertBtoRAS here. Even though @@ -1319,7 +1349,8 @@ void Surf_ConvertVoxelToSurfaceSpace(xVoxelRef iVoxel, mriTransformRef iTransfor } } -Surf_tErr Surf_Verify(mriSurfaceRef this) { +Surf_tErr Surf_Verify(mriSurfaceRef this) +{ Surf_tErr eResult = Surf_tErr_NoErr; /* check for null ptr */ @@ -1339,7 +1370,8 @@ Surf_tErr Surf_Verify(mriSurfaceRef this) { return eResult; } -char *Surf_GetErrorString(Surf_tErr ieCode) { +char *Surf_GetErrorString(Surf_tErr ieCode) +{ Surf_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= Surf_knNumErrorCodes) { diff --git a/utils/mriTransform.c b/utils/mriTransform.c index 17eb19837ac..c029d626b66 100644 --- a/utils/mriTransform.c +++ b/utils/mriTransform.c @@ -41,7 +41,8 @@ char *Trns_ksaErrorStrings[Trns_knNumErrorCodes] = { "LTA import (LTAread) failed.", "Invalid error code."}; -Trns_tErr Trns_New(mriTransformRef *opTransform) { +Trns_tErr Trns_New(mriTransformRef *opTransform) +{ Trns_tErr eResult = Trns_tErr_NoErr; mriTransformRef this = NULL; @@ -85,7 +86,8 @@ Trns_tErr Trns_New(mriTransformRef *opTransform) { return eResult; } -Trns_tErr Trns_NewFromLTA(mriTransformRef *opTransform, char *isLTAFileName) { +Trns_tErr Trns_NewFromLTA(mriTransformRef *opTransform, char *isLTAFileName) +{ Trns_tErr eResult = Trns_tErr_NoErr; mriTransformRef this = NULL; LTA *LTATransform = NULL; @@ -155,7 +157,8 @@ Trns_tErr Trns_NewFromLTA(mriTransformRef *opTransform, char *isLTAFileName) { return eResult; } -Trns_tErr Trns_Delete(mriTransformRef *iopTransform) { +Trns_tErr Trns_Delete(mriTransformRef *iopTransform) +{ Trns_tErr eResult = Trns_tErr_NoErr; mriTransformRef this = NULL; @@ -219,7 +222,8 @@ Trns_tErr Trns_Delete(mriTransformRef *iopTransform) { return eResult; } -Trns_tErr Trns_DeepClone(mriTransformRef this, mriTransformRef *opTransform) { +Trns_tErr Trns_DeepClone(mriTransformRef this, mriTransformRef *opTransform) +{ Trns_tErr eResult = Trns_tErr_NoErr; mriTransformRef clone = NULL; @@ -261,7 +265,8 @@ Trns_tErr Trns_DeepClone(mriTransformRef this, mriTransformRef *opTransform) { return eResult; } -Trns_tErr Trns_CopyAtoRAS(mriTransformRef this, MATRIX *iAtoRAS) { +Trns_tErr Trns_CopyAtoRAS(mriTransformRef this, MATRIX *iAtoRAS) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -292,7 +297,8 @@ Trns_tErr Trns_CopyAtoRAS(mriTransformRef this, MATRIX *iAtoRAS) { return eResult; } -Trns_tErr Trns_CopyBtoRAS(mriTransformRef this, MATRIX *iBtoRAS) { +Trns_tErr Trns_CopyBtoRAS(mriTransformRef this, MATRIX *iBtoRAS) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -323,7 +329,8 @@ Trns_tErr Trns_CopyBtoRAS(mriTransformRef this, MATRIX *iBtoRAS) { return eResult; } -Trns_tErr Trns_CopyARAStoBRAS(mriTransformRef this, MATRIX *iARAStoBRAS) { +Trns_tErr Trns_CopyARAStoBRAS(mriTransformRef this, MATRIX *iARAStoBRAS) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -354,7 +361,8 @@ Trns_tErr Trns_CopyARAStoBRAS(mriTransformRef this, MATRIX *iARAStoBRAS) { return eResult; } -Trns_tErr Trns_GetAtoRAS(mriTransformRef this, MATRIX **opMatrix) { +Trns_tErr Trns_GetAtoRAS(mriTransformRef this, MATRIX **opMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -378,7 +386,8 @@ Trns_tErr Trns_GetAtoRAS(mriTransformRef this, MATRIX **opMatrix) { return eResult; } -Trns_tErr Trns_GetBtoRAS(mriTransformRef this, MATRIX **opMatrix) { +Trns_tErr Trns_GetBtoRAS(mriTransformRef this, MATRIX **opMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -402,7 +411,8 @@ Trns_tErr Trns_GetBtoRAS(mriTransformRef this, MATRIX **opMatrix) { return eResult; } -Trns_tErr Trns_GetARAStoBRAS(mriTransformRef this, MATRIX **opMatrix) { +Trns_tErr Trns_GetARAStoBRAS(mriTransformRef this, MATRIX **opMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -425,7 +435,8 @@ Trns_tErr Trns_GetARAStoBRAS(mriTransformRef this, MATRIX **opMatrix) { return eResult; } -Trns_tErr Trns_GetAtoB(mriTransformRef this, MATRIX **opMatrix) { +Trns_tErr Trns_GetAtoB(mriTransformRef this, MATRIX **opMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -448,7 +459,8 @@ Trns_tErr Trns_GetAtoB(mriTransformRef this, MATRIX **opMatrix) { return eResult; } -Trns_tErr Trns_GetBtoA(mriTransformRef this, MATRIX **opMatrix) { +Trns_tErr Trns_GetBtoA(mriTransformRef this, MATRIX **opMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -476,7 +488,8 @@ Trns_tErr Trns_GetBtoA(mriTransformRef this, MATRIX **opMatrix) { fprintf(stderr, "%s\n", l); \ MatrixPrint(stderr, m); -Trns_tErr Trns_ApplyTransform(mriTransformRef this, MATRIX *iTransform) { +Trns_tErr Trns_ApplyTransform(mriTransformRef this, MATRIX *iTransform) +{ Trns_tErr eResult = Trns_tErr_NoErr; MATRIX *mTranslation = NULL; MATRIX *mTranslationInv = NULL; @@ -613,7 +626,8 @@ Trns_tErr Trns_ApplyTransform(mriTransformRef this, MATRIX *iTransform) { return eResult; } -Trns_tErr Trns_ExtractTranslationMatrix(MATRIX *iTransform, MATRIX *oTranslation) { +Trns_tErr Trns_ExtractTranslationMatrix(MATRIX *iTransform, MATRIX *oTranslation) +{ if (NULL == iTransform || NULL == oTranslation) { return Trns_tErr_InvalidParameter; } @@ -627,7 +641,8 @@ Trns_tErr Trns_ExtractTranslationMatrix(MATRIX *iTransform, MATRIX *oTranslation return Trns_tErr_NoErr; } -Trns_tErr Trns_ExtractRotationMatrix(MATRIX *iTransform, MATRIX *oRotation) { +Trns_tErr Trns_ExtractRotationMatrix(MATRIX *iTransform, MATRIX *oRotation) +{ MATRIX *mScale = NULL; MATRIX *mTmp = NULL; int n = 0; @@ -651,7 +666,8 @@ Trns_tErr Trns_ExtractRotationMatrix(MATRIX *iTransform, MATRIX *oRotation) { for (n = 1; n <= 3; n++) if (!FZERO(*MATRIX_RELT(mScale, n, n))) { *MATRIX_RELT(mScale, n, n) = 1.0 / *MATRIX_RELT(mScale, n, n); - } else { + } + else { *MATRIX_RELT(mScale, n, n) = 1.0; } @@ -664,7 +680,8 @@ Trns_tErr Trns_ExtractRotationMatrix(MATRIX *iTransform, MATRIX *oRotation) { return Trns_tErr_NoErr; } -Trns_tErr Trns_ExtractScaleMatrix(MATRIX *iTransform, MATRIX *oScale) { +Trns_tErr Trns_ExtractScaleMatrix(MATRIX *iTransform, MATRIX *oScale) +{ MATRIX *mTmp = NULL; VECTOR *vTmp = NULL; float fFactor = 0; @@ -716,7 +733,8 @@ Trns_tErr Trns_ExtractScaleMatrix(MATRIX *iTransform, MATRIX *oScale) { return Trns_tErr_NoErr; } -Trns_tErr Trns_Translate(mriTransformRef this, float ifAmount, tAxis iAxis) { +Trns_tErr Trns_Translate(mriTransformRef this, float ifAmount, tAxis iAxis) +{ Trns_tErr eResult = Trns_tErr_NoErr; MATRIX *mTransform = NULL; MATRIX *mOld = NULL; @@ -780,7 +798,8 @@ Trns_tErr Trns_Translate(mriTransformRef this, float ifAmount, tAxis iAxis) { return eResult; } -Trns_tErr Trns_Rotate(mriTransformRef this, float ifDegrees, tAxis iAxis) { +Trns_tErr Trns_Rotate(mriTransformRef this, float ifDegrees, tAxis iAxis) +{ Trns_tErr eResult = Trns_tErr_NoErr; MATRIX *mTransform = NULL; MATRIX *mOld = NULL; @@ -835,7 +854,8 @@ Trns_tErr Trns_Rotate(mriTransformRef this, float ifDegrees, tAxis iAxis) { return eResult; } -Trns_tErr Trns_Scale(mriTransformRef this, float ifFactor, tAxis iAxis) { +Trns_tErr Trns_Scale(mriTransformRef this, float ifFactor, tAxis iAxis) +{ Trns_tErr eResult = Trns_tErr_NoErr; MATRIX *mTransform = NULL; MATRIX *mOld = NULL; @@ -889,7 +909,8 @@ Trns_tErr Trns_Scale(mriTransformRef this, float ifFactor, tAxis iAxis) { return eResult; } -Trns_tErr Trns_ConvertAtoB(mriTransformRef this, xVoxelRef iAVoxel, xVoxelRef oBVoxel) { +Trns_tErr Trns_ConvertAtoB(mriTransformRef this, xVoxelRef iAVoxel, xVoxelRef oBVoxel) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -929,7 +950,8 @@ Trns_tErr Trns_ConvertAtoB(mriTransformRef this, xVoxelRef iAVoxel, xVoxelRef oB return eResult; } -Trns_tErr Trns_ConvertAtoRAS(mriTransformRef this, xVoxelRef iAVoxel, xVoxelRef oRASVoxel) { +Trns_tErr Trns_ConvertAtoRAS(mriTransformRef this, xVoxelRef iAVoxel, xVoxelRef oRASVoxel) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -971,7 +993,8 @@ Trns_tErr Trns_ConvertAtoRAS(mriTransformRef this, xVoxelRef iAVoxel, xVoxelRef return eResult; } -Trns_tErr Trns_ConvertBtoA(mriTransformRef this, xVoxelRef iBVoxel, xVoxelRef oAVoxel) { +Trns_tErr Trns_ConvertBtoA(mriTransformRef this, xVoxelRef iBVoxel, xVoxelRef oAVoxel) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1011,7 +1034,8 @@ Trns_tErr Trns_ConvertBtoA(mriTransformRef this, xVoxelRef iBVoxel, xVoxelRef oA return eResult; } -Trns_tErr Trns_ConvertBtoRAS(mriTransformRef this, xVoxelRef iBVoxel, xVoxelRef oRASVoxel) { +Trns_tErr Trns_ConvertBtoRAS(mriTransformRef this, xVoxelRef iBVoxel, xVoxelRef oRASVoxel) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1053,7 +1077,8 @@ Trns_tErr Trns_ConvertBtoRAS(mriTransformRef this, xVoxelRef iBVoxel, xVoxelRef return eResult; } -Trns_tErr Trns_ConvertBRAStoB(mriTransformRef this, xVoxelRef iBRASVoxel, xVoxelRef oBVoxel) { +Trns_tErr Trns_ConvertBRAStoB(mriTransformRef this, xVoxelRef iBRASVoxel, xVoxelRef oBVoxel) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1093,7 +1118,8 @@ Trns_tErr Trns_ConvertBRAStoB(mriTransformRef this, xVoxelRef iBRASVoxel, xVoxel return eResult; } -Trns_tErr Trns_ConvertMatrixAtoB(mriTransformRef this, MATRIX *iAMatrix, MATRIX *oBMatrix) { +Trns_tErr Trns_ConvertMatrixAtoB(mriTransformRef this, MATRIX *iAMatrix, MATRIX *oBMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1123,7 +1149,8 @@ Trns_tErr Trns_ConvertMatrixAtoB(mriTransformRef this, MATRIX *iAMatrix, MATRIX return eResult; } -Trns_tErr Trns_ConvertMatrixAtoRAS(mriTransformRef this, MATRIX *iAMatrix, MATRIX *oRASMatrix) { +Trns_tErr Trns_ConvertMatrixAtoRAS(mriTransformRef this, MATRIX *iAMatrix, MATRIX *oRASMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1153,7 +1180,8 @@ Trns_tErr Trns_ConvertMatrixAtoRAS(mriTransformRef this, MATRIX *iAMatrix, MATRI return eResult; } -Trns_tErr Trns_ConvertMatrixBtoA(mriTransformRef this, MATRIX *iBMatrix, MATRIX *oAMatrix) { +Trns_tErr Trns_ConvertMatrixBtoA(mriTransformRef this, MATRIX *iBMatrix, MATRIX *oAMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1183,7 +1211,8 @@ Trns_tErr Trns_ConvertMatrixBtoA(mriTransformRef this, MATRIX *iBMatrix, MATRIX return eResult; } -Trns_tErr Trns_ConvertMatrixBtoRAS(mriTransformRef this, MATRIX *iBMatrix, MATRIX *oRASMatrix) { +Trns_tErr Trns_ConvertMatrixBtoRAS(mriTransformRef this, MATRIX *iBMatrix, MATRIX *oRASMatrix) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1215,7 +1244,8 @@ Trns_tErr Trns_ConvertMatrixBtoRAS(mriTransformRef this, MATRIX *iBMatrix, MATRI /* don't use the next function when copying mAtoB or mBtoA */ /* they will be replaced by recalculated ones */ -Trns_tErr Trns_CalcMatricies_(mriTransformRef this) { +Trns_tErr Trns_CalcMatricies_(mriTransformRef this) +{ Trns_tErr eResult = Trns_tErr_NoErr; MATRIX *tmp = NULL; @@ -1257,7 +1287,8 @@ Trns_tErr Trns_CalcMatricies_(mriTransformRef this) { return eResult; } -Trns_tErr Trns_Verify(mriTransformRef this) { +Trns_tErr Trns_Verify(mriTransformRef this) +{ Trns_tErr eResult = Trns_tErr_NoErr; /* check for null ptr */ @@ -1277,11 +1308,13 @@ Trns_tErr Trns_Verify(mriTransformRef this) { return eResult; } -void Trns_Signal(char *isFuncName, int inLineNum, Trns_tErr ieCode) { +void Trns_Signal(char *isFuncName, int inLineNum, Trns_tErr ieCode) +{ DebugPrint(("Signal in %s, line %d: %d, %s", isFuncName, inLineNum, ieCode, Trns_GetErrorString(ieCode))); } -char *Trns_GetErrorString(Trns_tErr ieCode) { +char *Trns_GetErrorString(Trns_tErr ieCode) +{ Trns_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= Trns_knNumErrorCodes) { @@ -1291,7 +1324,8 @@ char *Trns_GetErrorString(Trns_tErr ieCode) { return Trns_ksaErrorStrings[eCode]; } -void Trns_DebugPrint_(mriTransformRef this) { +void Trns_DebugPrint_(mriTransformRef this) +{ if (NULL != this->mAtoRAS) { DebugPrint(("A to RAS:\n")); MatrixPrint(stderr, this->mAtoRAS); @@ -1327,7 +1361,8 @@ void Trns_DebugPrint_(mriTransformRef this) { MatrixPrint(stderr, this->mAtoB); } } -Trns_tErr Trns_GetType(mriTransformRef this, int *ptype) { +Trns_tErr Trns_GetType(mriTransformRef this, int *ptype) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); @@ -1351,7 +1386,8 @@ Trns_tErr Trns_GetType(mriTransformRef this, int *ptype) { return eResult; } -Trns_tErr Trns_CopyAtoB(mriTransformRef this, MATRIX *iAtoB) { +Trns_tErr Trns_CopyAtoB(mriTransformRef this, MATRIX *iAtoB) +{ Trns_tErr eResult = Trns_tErr_NoErr; eResult = Trns_Verify(this); diff --git a/utils/mriVolume.c b/utils/mriVolume.c index 7aef67e0836..33142a174b8 100644 --- a/utils/mriVolume.c +++ b/utils/mriVolume.c @@ -62,7 +62,8 @@ char Volm_ksaErrorStrings[Volm_knNumErrorCodes][Volm_knErrStringLen] = { "Error reading FREESURFER_HOME/average/mni305.cor.mgz while trying to population destination information in " "the display transform."}; -Volm_tErr Volm_New(mriVolumeRef *opVolume) { +Volm_tErr Volm_New(mriVolumeRef *opVolume) +{ Volm_tErr eResult = Volm_tErr_NoErr; mriVolumeRef this = NULL; MATRIX *tmpMatrix = NULL; @@ -149,7 +150,8 @@ Volm_tErr Volm_New(mriVolumeRef *opVolume) { return eResult; } -Volm_tErr Volm_Delete(mriVolumeRef *iopVolume) { +Volm_tErr Volm_Delete(mriVolumeRef *iopVolume) +{ Volm_tErr eResult = Volm_tErr_NoErr; mriVolumeRef this = NULL; @@ -214,7 +216,8 @@ Volm_tErr Volm_Delete(mriVolumeRef *iopVolume) { return eResult; } -Volm_tErr Volm_DeepClone(mriVolumeRef this, mriVolumeRef *opVolume) { +Volm_tErr Volm_DeepClone(mriVolumeRef this, mriVolumeRef *opVolume) +{ Volm_tErr eResult = Volm_tErr_NoErr; Trns_tErr eTransform = Trns_tErr_NoErr; mriVolumeRef clone = NULL; @@ -317,7 +320,8 @@ Volm_tErr Volm_DeepClone(mriVolumeRef this, mriVolumeRef *opVolume) { return eResult; } -Volm_tErr Volm_CreateFromVolume(mriVolumeRef this, mriVolumeRef iVolume) { +Volm_tErr Volm_CreateFromVolume(mriVolumeRef this, mriVolumeRef iVolume) +{ Volm_tErr eResult = Volm_tErr_NoErr; int nDimensionX = 0; int nDimensionY = 0; @@ -382,7 +386,8 @@ Volm_tErr Volm_CreateFromVolume(mriVolumeRef this, mriVolumeRef iVolume) { return eResult; } -Volm_tErr Volm_ImportData(mriVolumeRef this, char *isSource) { +Volm_tErr Volm_ImportData(mriVolumeRef this, char *isSource) +{ Volm_tErr eResult = Volm_tErr_NoErr; MRI *mriVolume = NULL; @@ -423,7 +428,8 @@ Volm_tErr Volm_ImportData(mriVolumeRef this, char *isSource) { return eResult; } -Volm_tErr Volm_SetFromMRI_(mriVolumeRef this, MRI *iMRI) { +Volm_tErr Volm_SetFromMRI_(mriVolumeRef this, MRI *iMRI) +{ Volm_tErr eResult = Volm_tErr_NoErr; MATRIX *identity = NULL; MATRIX *scannerTransform = NULL; @@ -535,7 +541,8 @@ Volm_tErr Volm_SetFromMRI_(mriVolumeRef this, MRI *iMRI) { return eResult; } -Volm_tErr Volm_CalculateMRIIdxToAnaIdx_(mriVolumeRef this) { +Volm_tErr Volm_CalculateMRIIdxToAnaIdx_(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; MATRIX *identity = NULL; MATRIX *idxToRASTransform = NULL; @@ -623,10 +630,8 @@ Volm_tErr Volm_CalculateMRIIdxToAnaIdx_(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_GetMaxValueAtMRIIdx_(mriVolumeRef this, - xVoxelRef iMRIIdx, - mri_tOrientation iOrientation, - float *oValue) { +Volm_tErr Volm_GetMaxValueAtMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, mri_tOrientation iOrientation, float *oValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -668,7 +673,8 @@ Volm_tErr Volm_GetMaxValueAtMRIIdx_(mriVolumeRef this, return eResult; } -Volm_tErr Volm_ExportNormToCOR(mriVolumeRef this, char *isPath) { +Volm_tErr Volm_ExportNormToCOR(mriVolumeRef this, char *isPath) +{ Volm_tErr eResult = Volm_tErr_NoErr; char sPath[mri_knPathLen] = ""; int eMRI = NO_ERROR; @@ -682,7 +688,8 @@ Volm_tErr Volm_ExportNormToCOR(mriVolumeRef this, char *isPath) { /* if out isPath is null, use the original path. */ if (NULL == isPath) { xUtil_strncpy(sPath, this->msOriginalPath, sizeof(sPath)); - } else { + } + else { xUtil_strncpy(sPath, isPath, sizeof(sPath)); } @@ -704,7 +711,8 @@ Volm_tErr Volm_ExportNormToCOR(mriVolumeRef this, char *isPath) { return eResult; } -Volm_tErr Volm_Save(mriVolumeRef this, char *isFileName, tBoolean ibSaveFileName) { +Volm_tErr Volm_Save(mriVolumeRef this, char *isFileName, tBoolean ibSaveFileName) +{ Volm_tErr eResult = Volm_tErr_NoErr; char sFileName[mri_knPathLen] = ""; int eMRI = NO_ERROR; @@ -718,7 +726,8 @@ Volm_tErr Volm_Save(mriVolumeRef this, char *isFileName, tBoolean ibSaveFileName /* if out isFileName is null, use the original. */ if (NULL == isFileName) { xUtil_strncpy(sFileName, this->msOriginalPath, sizeof(sFileName)); - } else { + } + else { xUtil_strncpy(sFileName, isFileName, sizeof(sFileName)); } @@ -742,7 +751,8 @@ Volm_tErr Volm_Save(mriVolumeRef this, char *isFileName, tBoolean ibSaveFileName return eResult; } -Volm_tErr Volm_LoadDisplayTransform(mriVolumeRef this, char *isFileName) { +Volm_tErr Volm_LoadDisplayTransform(mriVolumeRef this, char *isFileName) +{ Volm_tErr eResult = Volm_tErr_NoErr; TRANSFORM *transform = NULL; int eTransform = ERROR_NONE; @@ -839,7 +849,8 @@ Volm_tErr Volm_LoadDisplayTransform(mriVolumeRef this, char *isFileName) { return eResult; } -Volm_tErr Volm_UnloadDisplayTransform(mriVolumeRef this) { +Volm_tErr Volm_UnloadDisplayTransform(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_UnloadDisplayTransform( this=%p )", this)); @@ -866,7 +877,8 @@ Volm_tErr Volm_UnloadDisplayTransform(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_CopyGeometryInformation(mriVolumeRef this, VOL_GEOM *ioVolumeGeometry) { +Volm_tErr Volm_CopyGeometryInformation(mriVolumeRef this, VOL_GEOM *ioVolumeGeometry) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -894,7 +906,8 @@ Volm_tErr Volm_CopyGeometryInformation(mriVolumeRef this, VOL_GEOM *ioVolumeGeom return eResult; } -void Volm_GetIntColorAtIdx(mriVolumeRef this, xVoxelRef iIdx, xColor3nRef oColor) { +void Volm_GetIntColorAtIdx(mriVolumeRef this, xVoxelRef iIdx, xColor3nRef oColor) +{ float x, y, z; float value = 0; int colorIdx = 0; @@ -909,7 +922,8 @@ void Volm_GetIntColorAtIdx(mriVolumeRef this, xVoxelRef iIdx, xColor3nRef oColor if (Volm_VerifyIdx_(this, &disp) == Volm_tErr_NoErr) { Volm_GetSampledValueAtIdx_(this, &disp, &value); } - } else { + } + else { /* Get the sampled value. Cap it to the color min and max. If in between that, calculate the color index between 0 and 255. */ Volm_GetSampledValueAtIdx_(this, iIdx, &value); @@ -917,16 +931,19 @@ void Volm_GetIntColorAtIdx(mriVolumeRef this, xVoxelRef iIdx, xColor3nRef oColor if (value <= this->mfColorMin) { colorIdx = 0; - } else if (value >= this->mfColorMax) { + } + else if (value >= this->mfColorMax) { colorIdx = 255; - } else { + } + else { colorIdx = (int)(Volm_knNumColorTableEntries * (value - this->mfColorMin) / (this->mfColorMax - this->mfColorMin)); } *oColor = this->manColorTable[colorIdx]; } -void Volm_GetMaxIntColorAtIdx(mriVolumeRef this, xVoxelRef iIdx, mri_tOrientation iOrientation, xColor3nRef oColor) { +void Volm_GetMaxIntColorAtIdx(mriVolumeRef this, xVoxelRef iIdx, mri_tOrientation iOrientation, xColor3nRef oColor) +{ xVoxel MRI; float value = 0; int colorIdx = 0; @@ -939,7 +956,8 @@ void Volm_GetMaxIntColorAtIdx(mriVolumeRef this, xVoxelRef iIdx, mri_tOrientatio *oColor = this->manColorTable[colorIdx]; } -Volm_tErr Volm_GetDimensions(mriVolumeRef this, int *onDimensionX, int *onDimensionY, int *onDimensionZ) { +Volm_tErr Volm_GetDimensions(mriVolumeRef this, int *onDimensionX, int *onDimensionY, int *onDimensionZ) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -968,7 +986,8 @@ Volm_tErr Volm_GetDimensions(mriVolumeRef this, int *onDimensionX, int *onDimens return eResult; } -Volm_tErr Volm_GetNumberOfFrames(mriVolumeRef this, int *onDimensionFrames) { +Volm_tErr Volm_GetNumberOfFrames(mriVolumeRef this, int *onDimensionFrames) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -997,7 +1016,8 @@ Volm_tErr Volm_GetNumberOfFrames(mriVolumeRef this, int *onDimensionFrames) { return eResult; } -Volm_tErr Volm_GetType(mriVolumeRef this, int *onType) { +Volm_tErr Volm_GetType(mriVolumeRef this, int *onType) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_GetType( this=%p, onType=%p )", this, onType)); @@ -1025,7 +1045,8 @@ Volm_tErr Volm_GetType(mriVolumeRef this, int *onType) { return eResult; } -Volm_tErr Volm_GetValueMinMax(mriVolumeRef this, float *ofMin, float *ofMax) { +Volm_tErr Volm_GetValueMinMax(mriVolumeRef this, float *ofMin, float *ofMax) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_GetValueMinMax( this=%p, ofMin=%p, ofMax )", this, ofMin, ofMax)); @@ -1052,7 +1073,8 @@ Volm_tErr Volm_GetValueMinMax(mriVolumeRef this, float *ofMin, float *ofMax) { return eResult; } -Volm_tErr Volm_GetResampleMethod(mriVolumeRef this, Volm_tResampleMethod *oMethod) { +Volm_tErr Volm_GetResampleMethod(mriVolumeRef this, Volm_tResampleMethod *oMethod) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1081,7 +1103,8 @@ Volm_tErr Volm_GetResampleMethod(mriVolumeRef this, Volm_tResampleMethod *oMetho return eResult; } -Volm_tErr Volm_SetResampleMethod(mriVolumeRef this, Volm_tResampleMethod iMethod) { +Volm_tErr Volm_SetResampleMethod(mriVolumeRef this, Volm_tResampleMethod iMethod) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_SetResampleMethod( this=%p, iMethod=%d )", this, (int)iMethod)); @@ -1124,7 +1147,8 @@ Volm_tErr Volm_SetResampleMethod(mriVolumeRef this, Volm_tResampleMethod iMethod return eResult; } -Volm_tErr Volm_GetSampleType(mriVolumeRef this, Volm_tSampleType *oType) { +Volm_tErr Volm_GetSampleType(mriVolumeRef this, Volm_tSampleType *oType) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1153,7 +1177,8 @@ Volm_tErr Volm_GetSampleType(mriVolumeRef this, Volm_tSampleType *oType) { return eResult; } -Volm_tErr Volm_SetSampleType(mriVolumeRef this, Volm_tSampleType iType) { +Volm_tErr Volm_SetSampleType(mriVolumeRef this, Volm_tSampleType iType) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_SetSampleType( this=%p, iType=%d )", this, (int)iType)); @@ -1177,7 +1202,8 @@ Volm_tErr Volm_SetSampleType(mriVolumeRef this, Volm_tSampleType iType) { return eResult; } -Volm_tErr Volm_GetValueAtIdx(mriVolumeRef this, xVoxelRef iIdx, float *oValue) { +Volm_tErr Volm_GetValueAtIdx(mriVolumeRef this, xVoxelRef iIdx, float *oValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1209,13 +1235,15 @@ Volm_tErr Volm_GetValueAtIdx(mriVolumeRef this, xVoxelRef iIdx, float *oValue) { return eResult; } -Volm_tErr Volm_GetValueAtIdxUnsafe(mriVolumeRef this, xVoxelRef iIdx, float *oValue) { +Volm_tErr Volm_GetValueAtIdxUnsafe(mriVolumeRef this, xVoxelRef iIdx, float *oValue) +{ Volm_GetValueAtIdx_(this, iIdx, oValue); return Volm_tErr_NoErr; } -Volm_tErr Volm_SetValueAtIdx(mriVolumeRef this, xVoxelRef iIdx, float iValue) { +Volm_tErr Volm_SetValueAtIdx(mriVolumeRef this, xVoxelRef iIdx, float iValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1255,7 +1283,8 @@ Volm_tErr Volm_SetValueAtIdx(mriVolumeRef this, xVoxelRef iIdx, float iValue) { return eResult; } -Volm_tErr Volm_GetValueAtIdxFrame(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) { +Volm_tErr Volm_GetValueAtIdxFrame(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1290,13 +1319,15 @@ Volm_tErr Volm_GetValueAtIdxFrame(mriVolumeRef this, xVoxelRef iIdx, int iFrame, return eResult; } -Volm_tErr Volm_GetValueAtIdxFrameUnsafe(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) { +Volm_tErr Volm_GetValueAtIdxFrameUnsafe(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) +{ Volm_GetValueAtIdxFrame_(this, iIdx, iFrame, oValue); return Volm_tErr_NoErr; } -Volm_tErr Volm_SetValueAtIdxFrame(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float iValue) { +Volm_tErr Volm_SetValueAtIdxFrame(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float iValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1330,7 +1361,8 @@ Volm_tErr Volm_SetValueAtIdxFrame(mriVolumeRef this, xVoxelRef iIdx, int iFrame, return eResult; } -Volm_tErr Volm_GetValueAtMRIIdx(mriVolumeRef this, xVoxelRef iMRIIdx, float *oValue) { +Volm_tErr Volm_GetValueAtMRIIdx(mriVolumeRef this, xVoxelRef iMRIIdx, float *oValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1361,7 +1393,8 @@ Volm_tErr Volm_GetValueAtMRIIdx(mriVolumeRef this, xVoxelRef iMRIIdx, float *oVa return eResult; } -Volm_tErr Volm_SetValueAtMRIIdx(mriVolumeRef this, xVoxelRef iMRIIdx, float iValue) { +Volm_tErr Volm_SetValueAtMRIIdx(mriVolumeRef this, xVoxelRef iMRIIdx, float iValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1400,7 +1433,8 @@ Volm_tErr Volm_SetValueAtMRIIdx(mriVolumeRef this, xVoxelRef iMRIIdx, float iVal return eResult; } -Volm_tErr Volm_HasTalTransform(mriVolumeRef this, tBoolean *obHasTransform) { +Volm_tErr Volm_HasTalTransform(mriVolumeRef this, tBoolean *obHasTransform) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_HasTalTransform( this=%p, obHasTransform=%p)", this, obHasTransform)); @@ -1415,7 +1449,8 @@ Volm_tErr Volm_HasTalTransform(mriVolumeRef this, tBoolean *obHasTransform) { /* Return true if we have a tal transform, false if not. */ if (NULL != this->mpMriValues->linear_transform) { *obHasTransform = TRUE; - } else { + } + else { *obHasTransform = FALSE; } @@ -1428,7 +1463,8 @@ Volm_tErr Volm_HasTalTransform(mriVolumeRef this, tBoolean *obHasTransform) { return eResult; } -Volm_tErr Volm_ConvertIdxToRAS(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oRAS) { +Volm_tErr Volm_ConvertIdxToRAS(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oRAS) +{ Volm_tErr eResult = Volm_tErr_NoErr; xVoxel mriIdx; double rasX = 0; @@ -1467,7 +1503,8 @@ Volm_tErr Volm_ConvertIdxToRAS(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oRAS return eResult; } -Volm_tErr Volm_ConvertRASToIdx(mriVolumeRef this, xVoxelRef iRAS, xVoxelRef oIdx) { +Volm_tErr Volm_ConvertRASToIdx(mriVolumeRef this, xVoxelRef iRAS, xVoxelRef oIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; double idxX = 0; double idxY = 0; @@ -1504,7 +1541,8 @@ Volm_tErr Volm_ConvertRASToIdx(mriVolumeRef this, xVoxelRef iRAS, xVoxelRef oIdx return eResult; } -Volm_tErr Volm_ConvertIdxToMNITal(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oMNITal) { +Volm_tErr Volm_ConvertIdxToMNITal(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oMNITal) +{ Volm_tErr eResult = Volm_tErr_NoErr; xVoxel scannerRAS; double talX = 0; @@ -1549,7 +1587,8 @@ Volm_tErr Volm_ConvertIdxToMNITal(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef o return eResult; } -Volm_tErr Volm_ConvertIdxToTal(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oTal) { +Volm_tErr Volm_ConvertIdxToTal(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oTal) +{ Volm_tErr eResult = Volm_tErr_NoErr; xVoxel scannerRAS; double talX = 0; @@ -1587,7 +1626,8 @@ Volm_tErr Volm_ConvertIdxToTal(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oTal if (xVoxl_GetFloatZ(&tal) > 0) { DebugNote(("Converting to real tal with >0 transform")); Trns_ConvertAtoB(this->mMNITalGtzToRealTalTransform, &tal, oTal); - } else { + } + else { DebugNote(("Converting to real tal with <0 transform")); Trns_ConvertAtoB(this->mMNITalLtzToRealTalTransform, &tal, oTal); } @@ -1601,7 +1641,8 @@ Volm_tErr Volm_ConvertIdxToTal(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oTal return eResult; } -Volm_tErr Volm_ConvertTalToIdx(mriVolumeRef this, xVoxelRef iTal, xVoxelRef oIdx) { +Volm_tErr Volm_ConvertTalToIdx(mriVolumeRef this, xVoxelRef iTal, xVoxelRef oIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; double idxX = 0; double idxY = 0; @@ -1627,7 +1668,8 @@ Volm_tErr Volm_ConvertTalToIdx(mriVolumeRef this, xVoxelRef iTal, xVoxelRef oIdx if (xVoxl_GetFloatZ(iTal) > 0) { DebugNote(("Converting to mni tal with >0 transform")); Trns_ConvertBtoA(this->mMNITalGtzToRealTalTransform, iTal, &mniTal); - } else { + } + else { DebugNote(("Converting to mni tal with <=0 transform")); Trns_ConvertBtoA(this->mMNITalLtzToRealTalTransform, iTal, &mniTal); } @@ -1653,7 +1695,8 @@ Volm_tErr Volm_ConvertTalToIdx(mriVolumeRef this, xVoxelRef iTal, xVoxelRef oIdx return eResult; } -Volm_tErr Volm_ConvertIdxToScanner(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oScanner) { +Volm_tErr Volm_ConvertIdxToScanner(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oScanner) +{ Volm_tErr eResult = Volm_tErr_NoErr; xVoxel mriIdx; @@ -1688,7 +1731,8 @@ Volm_tErr Volm_ConvertIdxToScanner(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef return eResult; } -Volm_tErr Volm_ConvertMRIIdxToScanner(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oScanner) { +Volm_tErr Volm_ConvertMRIIdxToScanner(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oScanner) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1718,7 +1762,8 @@ Volm_tErr Volm_ConvertMRIIdxToScanner(mriVolumeRef this, xVoxelRef iMRIIdx, xVox return eResult; } -Volm_tErr Volm_ConvertIdxToMRIIdx(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oMRIIdx) { +Volm_tErr Volm_ConvertIdxToMRIIdx(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef oMRIIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1753,7 +1798,8 @@ Volm_tErr Volm_ConvertIdxToMRIIdx(mriVolumeRef this, xVoxelRef iIdx, xVoxelRef o return eResult; } -Volm_tErr Volm_ConvertMRIIdxToIdx(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oIdx) { +Volm_tErr Volm_ConvertMRIIdxToIdx(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1788,7 +1834,8 @@ Volm_tErr Volm_ConvertMRIIdxToIdx(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRe return eResult; } -Volm_tErr Volm_ConvertMRIIdxToRAS(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oRAS) { +Volm_tErr Volm_ConvertMRIIdxToRAS(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oRAS) +{ Volm_tErr eResult = Volm_tErr_NoErr; double rasX = 0; double rasY = 0; @@ -1822,7 +1869,8 @@ Volm_tErr Volm_ConvertMRIIdxToRAS(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRe return eResult; } -Volm_tErr Volm_ConvertRASToMRIIdx(mriVolumeRef this, xVoxelRef iRAS, xVoxelRef oMRIIdx) { +Volm_tErr Volm_ConvertRASToMRIIdx(mriVolumeRef this, xVoxelRef iRAS, xVoxelRef oMRIIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; double idxX = 0; double idxY = 0; @@ -1854,7 +1902,8 @@ Volm_tErr Volm_ConvertRASToMRIIdx(mriVolumeRef this, xVoxelRef iRAS, xVoxelRef o return eResult; } -Volm_tErr Volm_ConvertMRIIdxToSurfaceRAS(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oSurfaceRAS) { +Volm_tErr Volm_ConvertMRIIdxToSurfaceRAS(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oSurfaceRAS) +{ Volm_tErr eResult = Volm_tErr_NoErr; double rasX = 0; double rasY = 0; @@ -1893,7 +1942,8 @@ Volm_tErr Volm_ConvertMRIIdxToSurfaceRAS(mriVolumeRef this, xVoxelRef iMRIIdx, x return eResult; } -Volm_tErr Volm_ConvertSurfaceRASToMRIIdx(mriVolumeRef this, xVoxelRef iSurfaceRAS, xVoxelRef oMRIIdx) { +Volm_tErr Volm_ConvertSurfaceRASToMRIIdx(mriVolumeRef this, xVoxelRef iSurfaceRAS, xVoxelRef oMRIIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; double idxX = 0; double idxY = 0; @@ -1930,7 +1980,8 @@ Volm_tErr Volm_ConvertSurfaceRASToMRIIdx(mriVolumeRef this, xVoxelRef iSurfaceRA return eResult; } -Volm_tErr Volm_GetMRIIdxToAnaIdxTransform(mriVolumeRef this, mriTransformRef *opTransform) { +Volm_tErr Volm_GetMRIIdxToAnaIdxTransform(mriVolumeRef this, mriTransformRef *opTransform) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -1961,7 +2012,8 @@ Volm_tErr Volm_GetMRIIdxToAnaIdxTransform(mriVolumeRef this, mriTransformRef *op return eResult; } -Volm_tErr Volm_Flood(mriVolumeRef this, Volm_tFloodParams *iParams) { +Volm_tErr Volm_Flood(mriVolumeRef this, Volm_tFloodParams *iParams) +{ Volm_tErr eResult = Volm_tErr_NoErr; xList_tErr eList = xList_tErr_NoErr; xListRef list = NULL; @@ -2061,7 +2113,8 @@ Volm_tErr Volm_Flood(mriVolumeRef this, Volm_tFloodParams *iParams) { if (FALSE == iParams->mComparatorFunc(curVoxel, fValue, iParams->mComparatorFuncData)) { continue; } - } else { + } + else { /* Compare ths source value and the original value. */ switch (iParams->mComparatorType) { case Volm_tValueComparator_LTE: @@ -2171,7 +2224,8 @@ Volm_tErr Volm_Flood(mriVolumeRef this, Volm_tFloodParams *iParams) { return eResult; } -Volm_tErr Volm_VisitAllVoxels(mriVolumeRef this, Volm_tVisitFunction iFunc, void *ipData) { +Volm_tErr Volm_VisitAllVoxels(mriVolumeRef this, Volm_tVisitFunction iFunc, void *ipData) +{ Volm_tErr eResult = Volm_tErr_NoErr; Volm_tVisitCommand eVisit = Volm_tVisitComm_Continue; tBoolean bGo = TRUE; @@ -2230,7 +2284,8 @@ Volm_tErr Volm_VisitAllVoxels(mriVolumeRef this, Volm_tVisitFunction iFunc, void return eResult; } -Volm_tErr Volm_FindMaxValues(mriVolumeRef this) { +Volm_tErr Volm_FindMaxValues(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; float value = 0; int nX = 0; @@ -2310,7 +2365,8 @@ Volm_tErr Volm_FindMaxValues(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_MakeColorTable(mriVolumeRef this) { +Volm_tErr Volm_MakeColorTable(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; float min = 0; float max = 0; @@ -2340,7 +2396,8 @@ Volm_tErr Volm_MakeColorTable(mriVolumeRef this) { this->manColorTable[entry].mnGreen = 0; this->manColorTable[entry].mnBlue = 0; } - } else { + } + else { for (entry = 0; entry < Volm_knNumColorTableEntries; entry++) { /* Get the corresponding value for this entry, where entry 0 = min and entry Volm_knNumColorTableEntries = max. */ @@ -2378,7 +2435,8 @@ Volm_tErr Volm_MakeColorTable(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_SetBrightnessAndContrast(mriVolumeRef this, float ifBrightness, float ifContrast) { +Volm_tErr Volm_SetBrightnessAndContrast(mriVolumeRef this, float ifBrightness, float ifContrast) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -2409,7 +2467,8 @@ Volm_tErr Volm_SetBrightnessAndContrast(mriVolumeRef this, float ifBrightness, f return eResult; } -Volm_tErr Volm_SetColorMinMax(mriVolumeRef this, float ifMin, float ifMax) { +Volm_tErr Volm_SetColorMinMax(mriVolumeRef this, float ifMin, float ifMax) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -2453,7 +2512,8 @@ Volm_tErr Volm_SetColorMinMax(mriVolumeRef this, float ifMin, float ifMax) { return eResult; } -Volm_tErr Volm_GetBrightnessAndContrast(mriVolumeRef this, float *ofBrightness, float *ofContrast) { +Volm_tErr Volm_GetBrightnessAndContrast(mriVolumeRef this, float *ofBrightness, float *ofContrast) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -2481,7 +2541,8 @@ Volm_tErr Volm_GetBrightnessAndContrast(mriVolumeRef this, float *ofBrightness, return eResult; } -Volm_tErr Volm_SaveToSnapshot(mriVolumeRef this) { +Volm_tErr Volm_SaveToSnapshot(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; int nSize = 0; @@ -2529,7 +2590,8 @@ Volm_tErr Volm_SaveToSnapshot(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_RestoreFromSnapshot(mriVolumeRef this) { +Volm_tErr Volm_RestoreFromSnapshot(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; int nSize = 0; @@ -2573,7 +2635,8 @@ Volm_tErr Volm_RestoreFromSnapshot(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_Rotate(mriVolumeRef this, mri_tOrientation iAxis, float ifDegrees) { +Volm_tErr Volm_Rotate(mriVolumeRef this, mri_tOrientation iAxis, float ifDegrees) +{ Volm_tErr eResult = Volm_tErr_NoErr; MRI *newNorm = NULL; float fRadians = 0; @@ -2620,7 +2683,8 @@ Volm_tErr Volm_Rotate(mriVolumeRef this, mri_tOrientation iAxis, float ifDegrees return eResult; } -Volm_tErr Volm_Threshold(mriVolumeRef this, float iThreshold, tBoolean ibAbove, float iNewValue) { +Volm_tErr Volm_Threshold(mriVolumeRef this, float iThreshold, tBoolean ibAbove, float iNewValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; float value = 0; xVoxel idx; @@ -2660,7 +2724,8 @@ Volm_tErr Volm_Threshold(mriVolumeRef this, float iThreshold, tBoolean ibAbove, return eResult; } -Volm_tErr Volm_Flip(mriVolumeRef this, mri_tOrientation iAxis) { +Volm_tErr Volm_Flip(mriVolumeRef this, mri_tOrientation iAxis) +{ Volm_tErr eResult = Volm_tErr_NoErr; float value = 0; float flippedValue = 0; @@ -2734,7 +2799,8 @@ Volm_tErr Volm_Flip(mriVolumeRef this, mri_tOrientation iAxis) { return eResult; } -Volm_tErr Volm_SetAllValues(mriVolumeRef this, float iNewValue) { +Volm_tErr Volm_SetAllValues(mriVolumeRef this, float iNewValue) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_SetAllValues( this=%p, iNewValue=%d )", this, (int)iNewValue)); @@ -2755,7 +2821,8 @@ Volm_tErr Volm_SetAllValues(mriVolumeRef this, float iNewValue) { return eResult; } -Volm_tErr Volm_CopySubjectName(mriVolumeRef this, char *oSubjectName, int inDestLen) { +Volm_tErr Volm_CopySubjectName(mriVolumeRef this, char *oSubjectName, int inDestLen) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -2784,7 +2851,8 @@ Volm_tErr Volm_CopySubjectName(mriVolumeRef this, char *oSubjectName, int inDest return eResult; } -Volm_tErr Volm_CopyVolumeName(mriVolumeRef this, char *oVolumeName, int inDestLen) { +Volm_tErr Volm_CopyVolumeName(mriVolumeRef this, char *oVolumeName, int inDestLen) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -2813,7 +2881,8 @@ Volm_tErr Volm_CopyVolumeName(mriVolumeRef this, char *oVolumeName, int inDestLe return eResult; } -Volm_tErr Volm_CopySourceDir(mriVolumeRef this, char *oSourceDir, int inDestLen) { +Volm_tErr Volm_CopySourceDir(mriVolumeRef this, char *oSourceDir, int inDestLen) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction( @@ -2842,7 +2911,8 @@ Volm_tErr Volm_CopySourceDir(mriVolumeRef this, char *oSourceDir, int inDestLen) return eResult; } -Volm_tErr Volm_(mriVolumeRef this) { +Volm_tErr Volm_(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_( this=%p )", this)); @@ -2863,7 +2933,8 @@ Volm_tErr Volm_(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_SetSubjectName(mriVolumeRef this, char *isName) { +Volm_tErr Volm_SetSubjectName(mriVolumeRef this, char *isName) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_SetSubjectName( this=%p, isName=%s )", this, isName)); @@ -2887,7 +2958,8 @@ Volm_tErr Volm_SetSubjectName(mriVolumeRef this, char *isName) { return eResult; } -Volm_tErr Volm_SetVolumeName(mriVolumeRef this, char *isName) { +Volm_tErr Volm_SetVolumeName(mriVolumeRef this, char *isName) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_SetVolumeName( this=%p, isName=%s )", this, isName)); @@ -2911,7 +2983,8 @@ Volm_tErr Volm_SetVolumeName(mriVolumeRef this, char *isName) { return eResult; } -Volm_tErr Volm_ExtractAndSetSubjectName(mriVolumeRef this, char *isSource) { +Volm_tErr Volm_ExtractAndSetSubjectName(mriVolumeRef this, char *isSource) +{ Volm_tErr eResult = Volm_tErr_NoErr; int nChar = 0; int nWordChar = 0; @@ -2951,7 +3024,8 @@ Volm_tErr Volm_ExtractAndSetSubjectName(mriVolumeRef this, char *isSource) { nWordChar++; sWord += sizeof(char); } - } else { + } + else { /* look for 'subjects' in the title */ DebugNote(("Looking for subjects/ in source")); sWord = strstr(isSource, "subjects/"); @@ -2972,7 +3046,8 @@ Volm_tErr Volm_ExtractAndSetSubjectName(mriVolumeRef this, char *isSource) { nWordChar++; nChar++; } - } else { + } + else { /* else just use the last part */ nChar = 0; DebugNote(("Scooting to last slash")); @@ -2987,7 +3062,8 @@ Volm_tErr Volm_ExtractAndSetSubjectName(mriVolumeRef this, char *isSource) { if (isSource[nLastSlash] == '/') { DebugNote(("Copying everything from last slash to end of source")); xUtil_strncpy(sName, &(isSource[nLastSlash + 1]), sizeof(sName)); - } else { + } + else { DebugNote(("Copying entire source")); xUtil_strncpy(sName, isSource, sizeof(sName)); } @@ -3007,7 +3083,8 @@ Volm_tErr Volm_ExtractAndSetSubjectName(mriVolumeRef this, char *isSource) { return eResult; } -Volm_tErr Volm_ExtractAndSetVolumeName(mriVolumeRef this, char *isSource) { +Volm_tErr Volm_ExtractAndSetVolumeName(mriVolumeRef this, char *isSource) +{ Volm_tErr eResult = Volm_tErr_NoErr; int nChar = 0; int nLastSlash = 0; @@ -3035,7 +3112,8 @@ Volm_tErr Volm_ExtractAndSetVolumeName(mriVolumeRef this, char *isSource) { if (isSource[nLastSlash] == '/') { DebugNote(("Copying in source name from char %d", nLastSlash + 1)); xUtil_strncpy(this->msVolumeName, &(isSource[nLastSlash + 1]), sizeof(this->msVolumeName)); - } else { + } + else { DebugNote(("Copying in whole source name")); xUtil_strncpy(this->msVolumeName, isSource, sizeof(this->msVolumeName)); } @@ -3049,7 +3127,8 @@ Volm_tErr Volm_ExtractAndSetVolumeName(mriVolumeRef this, char *isSource) { return eResult; } -Volm_tErr Volm_SetMinVoxelSizeToOne(mriVolumeRef this) { +Volm_tErr Volm_SetMinVoxelSizeToOne(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; float scale, fov_x, fov_y, fov_z; @@ -3096,7 +3175,8 @@ Volm_tErr Volm_SetMinVoxelSizeToOne(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_Conform(mriVolumeRef this) { +Volm_tErr Volm_Conform(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; MRI *conformed = NULL; @@ -3128,7 +3208,8 @@ Volm_tErr Volm_Conform(mriVolumeRef this) { /* ======================================== BEGIN FUNCTION VERION OF MACROS */ #ifndef VOLM_USE_MACROS -void Volm_ConvertScreenIdxToMRIIdx_(mriVolumeRef this, xVoxelRef iScreenIdx, xVoxelRef oMRIIdx) { +void Volm_ConvertScreenIdxToMRIIdx_(mriVolumeRef this, xVoxelRef iScreenIdx, xVoxelRef oMRIIdx) +{ /* Stuff the screen index. */ DebugNote(("Stuffing iScreenIdx into vector")); *MATRIX_RELT(this->mpTmpScreenIdx, 1, 1) = xVoxl_GetFloatX(iScreenIdx); @@ -3155,7 +3236,8 @@ void Volm_ConvertScreenIdxToMRIIdx_(mriVolumeRef this, xVoxelRef iScreenIdx, xVo } } -void Volm_ConvertMRIIdxToScreenIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oScreenIdx) { +void Volm_ConvertMRIIdxToScreenIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxelRef oScreenIdx) +{ /* Stuff the mri index. */ DebugNote(("Stuffing iMRIIdx into vector")); *MATRIX_RELT(this->mpTmpMRIIdx, 1, 1) = xVoxl_GetFloatX(iMRIIdx); @@ -3181,7 +3263,8 @@ void Volm_ConvertMRIIdxToScreenIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, xVoxel } } -void Volm_GetValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float *oValue) { +void Volm_GetValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float *oValue) +{ int x, y, z; /* First convert to MRI index, and then switch on the volume data @@ -3220,7 +3303,8 @@ void Volm_GetValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float *oValue) { } } -void Volm_GetValueAtMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, float *oValue) { +void Volm_GetValueAtMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, float *oValue) +{ switch (this->mpMriValues->type) { case MRI_UCHAR: *oValue = MRIvox(this->mpMriValues, xVoxl_GetX(iMRIIdx), xVoxl_GetY(iMRIIdx), xVoxl_GetZ(iMRIIdx)); @@ -3243,7 +3327,8 @@ void Volm_GetValueAtMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, float *oValue) } } -void Volm_GetValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) { +void Volm_GetValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) +{ /* First convert to MRI index, and then switch on the volume data type and use the proper MRIvox access function to get the value. */ @@ -3291,7 +3376,8 @@ void Volm_GetValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, flo } } -void Volm_GetSampledValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float *oValue) { +void Volm_GetSampledValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float *oValue) +{ double value; /* First convert to MRI index, then use the MRI access function to @@ -3308,7 +3394,8 @@ void Volm_GetSampledValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float *oValue *oValue = (float)value; } -void Volm_GetSampledValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) { +void Volm_GetSampledValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float *oValue) +{ double value; /* First convert to MRI index, then use the MRI access function to @@ -3326,7 +3413,8 @@ void Volm_GetSampledValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFra *oValue = (float)value; } -void Volm_SetValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float iValue) { +void Volm_SetValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float iValue) +{ /* First convert to MRI index, and then switch on the volume data type and use the proper MRIvox access function to set the value. */ @@ -3363,7 +3451,8 @@ void Volm_SetValueAtIdx_(mriVolumeRef this, xVoxelRef iIdx, float iValue) { } } -void Volm_SetValueAtMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, float iValue) { +void Volm_SetValueAtMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, float iValue) +{ switch (this->mpMriValues->type) { default: break; @@ -3385,7 +3474,8 @@ void Volm_SetValueAtMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx, float iValue) } } -void Volm_SetValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float iValue) { +void Volm_SetValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, float iValue) +{ /* First convert to MRI index, and then switch on the volume data type and use the proper MRIvox access function to set the value. */ @@ -3434,7 +3524,8 @@ void Volm_SetValueAtIdxFrame_(mriVolumeRef this, xVoxelRef iIdx, int iFrame, flo #endif /* VOLM_USE_MACROS */ /* ======================================== END OF FUNCTION VERION OF MACROS */ -Volm_tErr Volm_Verify(mriVolumeRef this) { +Volm_tErr Volm_Verify(mriVolumeRef this) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugEnterFunction(("Volm_Verify( this=%p )", this)); @@ -3452,7 +3543,8 @@ Volm_tErr Volm_Verify(mriVolumeRef this) { return eResult; } -Volm_tErr Volm_VerifyIdx(mriVolumeRef this, xVoxelRef iIdx) { +Volm_tErr Volm_VerifyIdx(mriVolumeRef this, xVoxelRef iIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; eResult = Volm_Verify(this); @@ -3467,7 +3559,8 @@ Volm_tErr Volm_VerifyIdx(mriVolumeRef this, xVoxelRef iIdx) { return eResult; } -Volm_tErr Volm_VerifyIdx_(mriVolumeRef this, xVoxelRef iIdx) { +Volm_tErr Volm_VerifyIdx_(mriVolumeRef this, xVoxelRef iIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; xVoxel mriIdx; @@ -3484,7 +3577,8 @@ Volm_tErr Volm_VerifyIdx_(mriVolumeRef this, xVoxelRef iIdx) { return eResult; } -Volm_tErr Volm_VerifyMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx) { +Volm_tErr Volm_VerifyMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugAssertThrowX((xVoxl_GetX(iMRIIdx) >= 0 && xVoxl_GetRoundX(iMRIIdx) < this->mnDimensionX && @@ -3498,7 +3592,8 @@ Volm_tErr Volm_VerifyMRIIdx_(mriVolumeRef this, xVoxelRef iMRIIdx) { return eResult; } -Volm_tErr Volm_VerifyIdxInMRIBounds(mriVolumeRef this, xVoxelRef iScreenIdx) { +Volm_tErr Volm_VerifyIdxInMRIBounds(mriVolumeRef this, xVoxelRef iScreenIdx) +{ Volm_tErr eResult = Volm_tErr_NoErr; eResult = Volm_Verify(this); @@ -3535,7 +3630,8 @@ Volm_tErr Volm_VerifyIdxInMRIBounds(mriVolumeRef this, xVoxelRef iScreenIdx) { return eResult; } -Volm_tErr Volm_VerifyFrame_(mriVolumeRef this, int iFrame) { +Volm_tErr Volm_VerifyFrame_(mriVolumeRef this, int iFrame) +{ Volm_tErr eResult = Volm_tErr_NoErr; DebugAssertThrowX((iFrame >= 0 && iFrame < this->mnDimensionFrame), eResult, Volm_tErr_InvalidIdx); @@ -3546,7 +3642,8 @@ Volm_tErr Volm_VerifyFrame_(mriVolumeRef this, int iFrame) { return eResult; } -char *Volm_GetErrorString(Volm_tErr ieCode) { +char *Volm_GetErrorString(Volm_tErr ieCode) +{ Volm_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= Volm_knNumErrorCodes) { diff --git a/utils/mri_conform.c b/utils/mri_conform.c index ecb9b7c408c..250714670bf 100644 --- a/utils/mri_conform.c +++ b/utils/mri_conform.c @@ -41,7 +41,8 @@ double round(double); // why is this never defined?!? extern int errno; -MATRIX *MRIgetConformMatrix(MRI *mri) { +MATRIX *MRIgetConformMatrix(MRI *mri) +{ MRI *templ; MATRIX *m_resample; @@ -76,7 +77,8 @@ MATRIX *MRIgetConformMatrix(MRI *mri) { return (m_resample); } -MRI *MRIconform(MRI *mri) { +MRI *MRIconform(MRI *mri) +{ MRI *templ, *mri2, *res; // int conform_width; // double conform_size; @@ -140,7 +142,8 @@ MRI *MRIconform(MRI *mri) { } /* end MRIconform() */ -MRI *MRIconformedTemplate(MRI *mri, int conform_width, double conform_size, int KeepDC) { +MRI *MRIconformedTemplate(MRI *mri, int conform_width, double conform_size, int KeepDC) +{ MRI *template; char ostr[4]; int iLR, iIS, iAP, Nvox[3], FoV[3], conform_FoV, c; @@ -193,7 +196,8 @@ MRI *MRIconformedTemplate(MRI *mri, int conform_width, double conform_size, int if (ostr[iLR] == 'L') { K->rptr[1][iLR + 1] = step; K->rptr[1][4] = pad; - } else { + } + else { K->rptr[1][iLR + 1] = -step; K->rptr[1][4] = conform_width - pad; } @@ -203,7 +207,8 @@ MRI *MRIconformedTemplate(MRI *mri, int conform_width, double conform_size, int if (ostr[iIS] == 'I') { K->rptr[2][iIS + 1] = step; K->rptr[2][4] = pad; - } else { + } + else { K->rptr[2][iIS + 1] = -step; K->rptr[2][4] = conform_width - pad; } @@ -213,7 +218,8 @@ MRI *MRIconformedTemplate(MRI *mri, int conform_width, double conform_size, int if (ostr[iAP] == 'A') { K->rptr[3][iAP + 1] = step; K->rptr[3][4] = pad; - } else { + } + else { K->rptr[3][iAP + 1] = -step; K->rptr[3][4] = conform_width - pad; } @@ -237,7 +243,8 @@ MRI *MRIconformedTemplate(MRI *mri, int conform_width, double conform_size, int MatrixFree(&invK); MatrixFree(&Smri); MatrixFree(&Stemp); - } else { + } + else { // replicates old method exactly template->x_r = -1.0; template->x_a = 0.0; diff --git a/utils/mri_fastmarching.cpp b/utils/mri_fastmarching.cpp index cf78cf796ac..fb16e47819a 100644 --- a/utils/mri_fastmarching.cpp +++ b/utils/mri_fastmarching.cpp @@ -25,7 +25,8 @@ #include "fastmarching.h" extern "C" MRI *MRIextractDistanceMap( - MRI *mri_src, MRI *mri_dst, int label, float max_distance, int mode, MRI *mri_mask) { + MRI *mri_src, MRI *mri_dst, int label, float max_distance, int mode, MRI *mri_mask) +{ MRI *mri_distance = NULL; #if 0 @@ -79,7 +80,8 @@ extern "C" MRI *MRIextractDistanceMap( "ERROR : incompatible structure with mri_dst:\n" "mri_dst->type=%d != MRI_FLOAT\n", mri_dst->type); - } else { + } + else { // set values to zero for (int z = 0; z < mri_dst->depth; z++) for (int y = 0; y < mri_dst->height; y++) diff --git a/utils/mri_identify.c b/utils/mri_identify.c index ece530d8132..bb6c1787c59 100644 --- a/utils/mri_identify.c +++ b/utils/mri_identify.c @@ -49,7 +49,8 @@ extern int errno; int stricmp(char *str1, char *str2); #endif -char *type_to_string(int type) { +char *type_to_string(int type) +{ char *typestring; char *tmpstr; int lentmp; @@ -141,7 +142,8 @@ char *type_to_string(int type) { return (typestring); } -int string_to_type(const char *string) { +int string_to_type(const char *string) +{ int type = MRI_VOLUME_TYPE_UNKNOWN; char ls[STRLEN]; @@ -192,7 +194,8 @@ int string_to_type(const char *string) { } /* end string_to_type() */ // why the routine does not check ANALYZE4D? -int mri_identify(const char *fname_passed) { +int mri_identify(const char *fname_passed) +{ char fname[STRLEN]; int type = 0; char *ext; @@ -382,7 +385,8 @@ int mri_identify(const char *fname_passed) { This can be dependent on order, if more than one file type exists with the same stem. */ -int IDtypeFromStem(const char *stem) { +int IDtypeFromStem(const char *stem) +{ char tmpstr[2000]; sprintf(tmpstr, "%s.nii", stem); @@ -410,7 +414,8 @@ int IDtypeFromStem(const char *stem) { \fn int IDstemFromName(char *stem) \brief Returns the file stem by looking for various extensions. */ -char *IDstemFromName(const char *name) { +char *IDstemFromName(const char *name) +{ char *stem = NULL; const char *ext; int len; @@ -472,7 +477,8 @@ char *IDstemFromName(const char *name) { \fn int IDextensionFromName(char *stem) \brief Returns the file extension by looking for various extensions. */ -char *IDextensionFromName(const char *name) { +char *IDextensionFromName(const char *name) +{ int len; char *ext; @@ -519,7 +525,8 @@ char *IDextensionFromName(const char *name) { This can be dependent on order, if more than one file type exists with the same stem. */ -char *IDnameFromStem(const char *stem) { +char *IDnameFromStem(const char *stem) +{ char tmpstr[2000]; sprintf(tmpstr, "%s.nii", stem); @@ -552,7 +559,8 @@ char *IDnameFromStem(const char *stem) { return (NULL); } -int is_cor(const char *fname) { +int is_cor(const char *fname) +{ struct stat stat_buf; char *fname2, *base; int iscor = 0; @@ -574,7 +582,8 @@ int is_cor(const char *fname) { } /* end is_cor() */ -int is_brik(const char *fname) { +int is_brik(const char *fname) +{ char *dot; dot = strrchr(fname, '.'); @@ -587,7 +596,8 @@ int is_brik(const char *fname) { } /* end is_brik() */ -int is_siemens(const char *fname) { +int is_siemens(const char *fname) +{ FILE *fp; char string[4]; char *dot; @@ -642,7 +652,8 @@ int is_siemens(const char *fname) { } /* end is_siemens() */ -int is_genesis(const char *fname) { +int is_genesis(const char *fname) +{ FILE *fp; long32 magic; char *dot; @@ -674,7 +685,8 @@ int is_genesis(const char *fname) { } /* end is_genesis() */ -int is_ge_lx(const char *fname) { +int is_ge_lx(const char *fname) +{ FILE *fp; long32 magic; @@ -699,7 +711,8 @@ int is_ge_lx(const char *fname) { } /* end is_ge_lx() */ -int is_analyze(const char *fname) { +int is_analyze(const char *fname) +{ FILE *fp; dsr hdr; char hfname[STRLEN], *dot; @@ -739,7 +752,8 @@ int is_analyze(const char *fname) { } /* end is_analyze() */ -int is_mnc(const char *fname) { +int is_mnc(const char *fname) +{ char buf[3]; FILE *fp; char *dot; @@ -775,7 +789,8 @@ int is_mnc(const char *fname) { } /* end is_mnc() */ -int is_mgh(const char *fname) { +int is_mgh(const char *fname) +{ FILE *fp; int width, height, depth, nframes; // int version, type, dof; @@ -809,7 +824,8 @@ int is_mgh(const char *fname) { } /* end is_mgh() */ /*--------------------------------------*/ -int is_bshort(const char *fname) { +int is_bshort(const char *fname) +{ char *dot; dot = strrchr(fname, '.'); if (dot) { @@ -820,7 +836,8 @@ int is_bshort(const char *fname) { } /* end is_bshort() */ /*--------------------------------------*/ -int is_bfloat(const char *fname) { +int is_bfloat(const char *fname) +{ char *dot; dot = strrchr(fname, '.'); if (dot) { @@ -830,7 +847,8 @@ int is_bfloat(const char *fname) { return (0); } /* end is_bfloat() */ /*--------------------------------------*/ -int is_bhdr(const char *fname) { +int is_bhdr(const char *fname) +{ char *dot; dot = strrchr(fname, '.'); if (dot) { @@ -843,7 +861,8 @@ int is_bhdr(const char *fname) { bhdr_stem(). Given fname = stem.bhdr, returns stem. --------------------------------------*/ -char *bhdr_stem(const char *fname) { +char *bhdr_stem(const char *fname) +{ char *stem; int i, len; @@ -866,7 +885,8 @@ char *bhdr_stem(const char *fname) { where precision is either bfloat or bshort. This can then be used as input to MRIread(). --------------------------------------------*/ -char *bhdr_firstslicefname(const char *fname) { +char *bhdr_firstslicefname(const char *fname) +{ char *stem, *firstslicefname; int len; @@ -896,7 +916,8 @@ char *bhdr_firstslicefname(const char *fname) { stem_000.precision on disk, where precision is either bfloat or bshort. --------------------------------------------------------------*/ -char *bhdr_precisionstring(const char *fname) { +char *bhdr_precisionstring(const char *fname) +{ char *stem, *precision; char tmpstr[2000]; @@ -928,7 +949,8 @@ char *bhdr_precisionstring(const char *fname) { on disk, where precision is either bfloat or bshort. If bfloat, then returns MRI_FLOAT. If bshort, then returns MRI_SHORT. ---------------------------------------------------------------------*/ -int bhdr_precision(const char *fname) { +int bhdr_precision(const char *fname) +{ char *stem; char tmpstr[2000]; @@ -952,7 +974,8 @@ int bhdr_precision(const char *fname) { } /*--------------------------------------*/ -int is_sdt(const char *fname) { +int is_sdt(const char *fname) +{ char header_fname[STR_LEN]; char *dot; FILE *fp; @@ -982,7 +1005,8 @@ int is_sdt(const char *fname) { } /* end is_sdt() */ -int is_gdf(const char *fname) { +int is_gdf(const char *fname) +{ char *dot; dot = strrchr(fname, '.'); @@ -994,7 +1018,8 @@ int is_gdf(const char *fname) { } /* end is_gdf() */ -int is_otl(const char *fname) { +int is_otl(const char *fname) +{ char *dot; dot = strrchr(fname, '.'); @@ -1008,7 +1033,8 @@ int is_otl(const char *fname) { int is_ximg(const char *fname) { return (FALSE); } /* end is_ximg() */ -int is_nifti1(const char *fname) { +int is_nifti1(const char *fname) +{ char fname_stem[STRLEN]; char hdr_fname[STRLEN]; char *dot; @@ -1051,7 +1077,8 @@ int is_nifti1(const char *fname) { } /* end is_nifti1() */ -int is_nii(const char *fname) { +int is_nii(const char *fname) +{ char *dot; FILE *fp; char magic[4]; @@ -1091,7 +1118,8 @@ int is_nii(const char *fname) { } /* end is_nii() */ -int is_nrrd(const char *fname) { +int is_nrrd(const char *fname) +{ char *dot; FILE *fp; char magic[4]; @@ -1171,7 +1199,8 @@ END c++ version of is_nrrd() /*---------------------------------------- IDisCurv() - surface curve file format ----------------------------------------*/ -int IDisCurv(const char *curvfile) { +int IDisCurv(const char *curvfile) +{ int magno; FILE *fp; diff --git a/utils/mri_level_set.c b/utils/mri_level_set.c index 816746dfce4..6b99323437d 100644 --- a/utils/mri_level_set.c +++ b/utils/mri_level_set.c @@ -72,7 +72,8 @@ /* solve ut + f |grad(u)| = e uxx */ -MRI *MRIregionGrow(MRI *mri_src, MRI *mri_distance, float x0, float y0, float z0, int niter) { +MRI *MRIregionGrow(MRI *mri_src, MRI *mri_distance, float x0, float y0, float z0, int niter) +{ int width, height, depth, t, x, y, z, xp1, xm1, yp1, ym1, zp1, zm1, write_iter; double dx, dy, dz, dxx, dyy, dzz, dxy, dxz, dyz, dist_xp1, dist_xm1, dist_yp1, dist_ym1, dist_zp1, dist_zm1, dist, km, denom, mag, dist_xp1yp1, dist_xp1zp1, dist_yp1zp1, grad, F, laplacian, dx_f, dx_b, dy_f, dy_b, dz_f, dz_b, sdx, @@ -305,7 +306,8 @@ MRI *MRIregionGrow(MRI *mri_src, MRI *mri_distance, float x0, float y0, float z0 Description: ----------------------------------------------------------------------*/ -MRI *MRIbuildDistanceMap(MRI *mri_src, MRI *mri_distance, float x0, float y0, float z0, float r) { +MRI *MRIbuildDistanceMap(MRI *mri_src, MRI *mri_distance, float x0, float y0, float z0, float r) +{ int width, height, depth, x, y, z; float dist, xdist, ydist, zdist, norm; @@ -340,7 +342,8 @@ MRI *MRIbuildDistanceMap(MRI *mri_src, MRI *mri_distance, float x0, float y0, fl Description: ----------------------------------------------------------------------*/ -MRI *MRIextractInterior(MRI *mri_src, MRI *mri_distance, MRI *mri_dst) { +MRI *MRIextractInterior(MRI *mri_src, MRI *mri_distance, MRI *mri_dst) +{ int width, height, depth, x, y, z; float *pdist, dist; BUFTYPE *pdst, *psrc; @@ -373,7 +376,8 @@ MRI *MRIextractInterior(MRI *mri_src, MRI *mri_distance, MRI *mri_dst) { Description: ----------------------------------------------------------------------*/ -MRI *MRIupdateDistanceMap(MRI *mri_distance) { +MRI *MRIupdateDistanceMap(MRI *mri_distance) +{ int width, height, depth, x, y, z, xk, yk, zk, x0, y0, z0, xmin, ymin, zmin; float dist, min_dist, xdist, ydist, zdist; diff --git a/utils/mri_tess.c b/utils/mri_tess.c index 53b4e468d9b..e0a8f99e0d1 100644 --- a/utils/mri_tess.c +++ b/utils/mri_tess.c @@ -51,19 +51,22 @@ extern const char *Progname; #define FACEINCREASE 1.2 #define VERTEXINCREASE 1.2 -typedef struct quad_face_type_ { +typedef struct quad_face_type_ +{ int imnr, i, j, f; int num; int v[4]; } quad_face_type; -typedef struct quad_vertex_type_ { +typedef struct quad_vertex_type_ +{ int imnr, i, j; int num; int f[9]; } quad_vertex_type; -typedef struct tesselation_parms_ { +typedef struct tesselation_parms_ +{ /*labeled volume*/ MRI *mri; @@ -240,7 +243,8 @@ static void initImage(tesselation_parms *parms) /*initialization of tesselation_parms*/ /*note that not all the fields are allocated*/ -static void initTesselationParms(tesselation_parms *parms) { +static void initTesselationParms(tesselation_parms *parms) +{ int i, j, k, n; int depth, width, height; int *xmin, *ymin, *zmin, *xmax, *ymax, *zmax; @@ -327,7 +331,8 @@ static void initTesselationParms(tesselation_parms *parms) { parms->all_flag = 0; } -static int freeTesselationParms(tesselation_parms **parms) { +static int freeTesselationParms(tesselation_parms **parms) +{ int j, k; tesselation_parms *tmp = *parms; int depth, width, height; @@ -354,7 +359,8 @@ static int freeTesselationParms(tesselation_parms **parms) { return (NO_ERROR); } -static void allocateTesselation(tesselation_parms *parms) { +static void allocateTesselation(tesselation_parms *parms) +{ int imgsize = parms->imgsize; parms->face = (quad_face_type *)lcalloc(MAXFACES, sizeof(quad_face_type)); parms->maxfaces = MAXFACES; @@ -373,7 +379,8 @@ static void allocateTesselation(tesselation_parms *parms) { ErrorExit(ERROR_NO_MEMORY, "MRIStesselate: local tesselation tables"); } -static void freeTesselation(tesselation_parms *parms) { +static void freeTesselation(tesselation_parms *parms) +{ free(parms->face); free(parms->face_index_table0); free(parms->face_index_table1); @@ -391,7 +398,8 @@ static void freeTesselation(tesselation_parms *parms) { /* This may be the same as that in mrisurf.c. Whoever wrote it should NOT have done this. Very bad programming. */ -static int mrisFindNeighbors2(MRI_SURFACE *mris) { +static int mrisFindNeighbors2(MRI_SURFACE *mris) +{ int n0, n1, i, k, m, n, vno, vtotal, ntotal, vtmp[MAX_NEIGHBORS]; FACE *f; VERTEX *v; @@ -477,7 +485,8 @@ static int mrisFindNeighbors2(MRI_SURFACE *mris) { return (NO_ERROR); } -static int saveTesselation(tesselation_parms *parms) { +static int saveTesselation(tesselation_parms *parms) +{ int vno, m, n, fno; int pct_over = 1; quad_face_type *face2; @@ -553,7 +562,8 @@ static int saveTesselation(tesselation_parms *parms) { mris->faces[fno + 1].v[0] = face2->v[2]; mris->faces[fno + 1].v[1] = face2->v[3]; mris->faces[fno + 1].v[2] = face2->v[1]; - } else { + } + else { /* 1st triangle */ mris->faces[fno].v[0] = face2->v[0]; mris->faces[fno].v[1] = face2->v[1]; @@ -634,7 +644,8 @@ static int saveTesselation(tesselation_parms *parms) { return (NO_ERROR); } -MRIS *MRISconcatenateQuadSurfaces(int number_of_labels, MRIS **mris_tab) { +MRIS *MRISconcatenateQuadSurfaces(int number_of_labels, MRIS **mris_tab) +{ MRIS *mris; int nvertices, nfaces, n, count, countvnbr, vno, fno; @@ -665,7 +676,8 @@ MRIS *MRISconcatenateQuadSurfaces(int number_of_labels, MRIS **mris_tab) { return mris; } -static void reallocateVertices(tesselation_parms *parms) { +static void reallocateVertices(tesselation_parms *parms) +{ quad_vertex_type *tmp; int k, n; int vertex_index = parms->vertex_index; @@ -683,7 +695,8 @@ static void reallocateVertices(tesselation_parms *parms) { free(parms->vertex); parms->vertex = tmp; } -static void reallocateFaces(tesselation_parms *parms) { +static void reallocateFaces(tesselation_parms *parms) +{ quad_face_type *tmp; int k, n; int face_index = parms->face_index; @@ -704,7 +717,8 @@ static void reallocateFaces(tesselation_parms *parms) { parms->face = tmp; } -static void add_face(int imnr, int i, int j, int f, int prev_flag, tesselation_parms *parms) { +static void add_face(int imnr, int i, int j, int f, int prev_flag, tesselation_parms *parms) +{ int pack = f * parms->imgsize + i * parms->width + j; int face_index = parms->face_index; @@ -721,7 +735,8 @@ static void add_face(int imnr, int i, int j, int f, int prev_flag, tesselation_p parms->face_index++; } -static int add_vertex(int imnr, int i, int j, tesselation_parms *parms) { +static int add_vertex(int imnr, int i, int j, tesselation_parms *parms) +{ // int pack = i*(parms->width+1)+j; int vertex_index = parms->vertex_index; @@ -734,7 +749,8 @@ static int add_vertex(int imnr, int i, int j, tesselation_parms *parms) { return parms->vertex_index++; } -static int facep(int im0, int i0, int j0, int im1, int i1, int j1, tesselation_parms *parms) { +static int facep(int im0, int i0, int j0, int im1, int i1, int j1, tesselation_parms *parms) +{ unsigned char ***im = parms->im; int value = parms->current_label; return (im0 >= parms->zmin && im0 <= parms->zmax && i0 >= parms->ymin && i0 <= parms->ymax && j0 >= parms->xmin && @@ -743,17 +759,9 @@ static int facep(int im0, int i0, int j0, int im1, int i1, int j1, tesselation_p ((im[im0][i0][j0] == value || im[im1][i1][j1] == value) || parms->all_flag)); } -static void check_face(int im0, - int i0, - int j0, - int im1, - int i1, - int j1, - int f, - int n, - int v_ind, - int prev_flag, - tesselation_parms *parms) { +static void check_face( + int im0, int i0, int j0, int im1, int i1, int j1, int f, int n, int v_ind, int prev_flag, tesselation_parms *parms) +{ int f_pack = f * parms->imgsize + i0 * parms->width + j0; int f_ind; unsigned char ***im = parms->im; @@ -777,17 +785,9 @@ static void check_face(int im0, } } -static void check_face2(int im0, - int i0, - int j0, - int im1, - int i1, - int j1, - int f, - int n, - int v_ind, - int prev_flag, - tesselation_parms *parms) { +static void check_face2( + int im0, int i0, int j0, int im1, int i1, int j1, int f, int n, int v_ind, int prev_flag, tesselation_parms *parms) +{ int f_pack = f * parms->imgsize + i0 * parms->width + j0; int f_ind; @@ -802,7 +802,8 @@ static void check_face2(int im0, if (parms->vertex[v_ind].num < 9) parms->vertex[v_ind].f[parms->vertex[v_ind].num++] = f_ind; } -static void make_surface(tesselation_parms *parms) { +static void make_surface(tesselation_parms *parms) +{ int imnr, i, j, f_pack, v_ind, f; int n; @@ -878,7 +879,8 @@ static void make_surface(tesselation_parms *parms) { typedef unsigned char CNBH[2][2][2]; -static int computeconnectedcomponents(CNBH *tab) { +static int computeconnectedcomponents(CNBH *tab) +{ int i, j, k, a, b, c, ik, jk, kk, ct; int nvox, label, sum; int comp_table[12]; @@ -916,7 +918,8 @@ static int computeconnectedcomponents(CNBH *tab) { ; (*tab)[i][j][k] = ct + 1; // label the new basin comp_table[ct] = 1; // note that this number is taken - } else { + } + else { min_val = 11; // merging into the smallest value @@ -949,7 +952,8 @@ static int computeconnectedcomponents(CNBH *tab) { return nvox; } -static void make_surface_with_connectivity(tesselation_parms *parms) { +static void make_surface_with_connectivity(tesselation_parms *parms) +{ int imnr, i, j, k, f_pack, v_ind, f, a, b, c, label, nlabels, comp, m; int n, slcx, slcy, slcz, indx, indy, indz; CNBH tab; @@ -1138,7 +1142,8 @@ static void make_surface_with_connectivity(tesselation_parms *parms) { MRIfree(&mri); } -MRIS *MRIScreateSurfaceFromVolume(MRI *mri, int label, int connectivity) { +MRIS *MRIScreateSurfaceFromVolume(MRI *mri, int label, int connectivity) +{ tesselation_parms *parms; MRIS **mris_table, *mris; @@ -1173,7 +1178,8 @@ MRIS *MRIScreateSurfaceFromVolume(MRI *mri, int label, int connectivity) { return mris; } -MRIS **MRIScreateSurfacesFromVolume(MRI *mri, int number_of_labels, int *labelvalues, int connectivity) { +MRIS **MRIScreateSurfacesFromVolume(MRI *mri, int number_of_labels, int *labelvalues, int connectivity) +{ tesselation_parms *parms; MRIS **mris_table; diff --git a/utils/mri_topology.c b/utils/mri_topology.c index 01918d14621..031cc8ff51e 100644 --- a/utils/mri_topology.c +++ b/utils/mri_topology.c @@ -47,7 +47,8 @@ // //////////////////////////////////////////////////////////////////// -int connectivityNumber(int connectivity) { +int connectivityNumber(int connectivity) +{ int con; switch (connectivity) { case 1: @@ -69,7 +70,8 @@ int connectivityNumber(int connectivity) { return con; } -int associatedConnectivity(int connectivity) { +int associatedConnectivity(int connectivity) +{ switch (connectivity) { case 1: return 2; @@ -89,7 +91,8 @@ int associatedConnectivity(int connectivity) { } } -Nbh *loadNbh(MRI *mri, Nbh *nbh_dst, int i, int j, int k, int label) { +Nbh *loadNbh(MRI *mri, Nbh *nbh_dst, int i, int j, int k, int label) +{ int a, b, c; Nbh *nbh; @@ -109,7 +112,8 @@ Nbh *loadNbh(MRI *mri, Nbh *nbh_dst, int i, int j, int k, int label) { return nbh; } -Nbh *loadSNbh(MRI *mri, Nbh *nbh_dst, int i, int j, int k, int label) { +Nbh *loadSNbh(MRI *mri, Nbh *nbh_dst, int i, int j, int k, int label) +{ int a, b, c; Nbh *nbh; @@ -129,7 +133,8 @@ Nbh *loadSNbh(MRI *mri, Nbh *nbh_dst, int i, int j, int k, int label) { return nbh; } -Nbh *N_6_1(Nbh *nbh_src, Nbh *nbh_dst) { +Nbh *N_6_1(Nbh *nbh_src, Nbh *nbh_dst) +{ int i, j, k; Nbh *nbh; if (!nbh_dst) { @@ -141,7 +146,8 @@ Nbh *N_6_1(Nbh *nbh_src, Nbh *nbh_dst) { if ((*nbh_src)[1][1][0]) (*nbh)[1][1][0] = 1; if ((*nbh_src)[1][1][2]) (*nbh)[1][1][2] = 1; return nbh; - } else + } + else nbh = nbh_dst; if ((*nbh_src)[0][1][1]) (*nbh)[0][1][1] = TMP; @@ -162,7 +168,8 @@ Nbh *N_6_1(Nbh *nbh_src, Nbh *nbh_dst) { return nbh; } -Nbh *N_6_2(Nbh *nbh_src, Nbh *nbh_dst) { +Nbh *N_6_2(Nbh *nbh_src, Nbh *nbh_dst) +{ int i, j, k; Nbh *nbh; @@ -203,7 +210,8 @@ Nbh *N_6_2(Nbh *nbh_src, Nbh *nbh_dst) { return nbh; } -Nbh *N_6_3(Nbh *nbh_src, Nbh *nbh_dst) { +Nbh *N_6_3(Nbh *nbh_src, Nbh *nbh_dst) +{ int i, j, k; Nbh *nbh; @@ -261,7 +269,8 @@ Nbh *N_6_3(Nbh *nbh_src, Nbh *nbh_dst) { return nbh; } -Nbh *N_18_1(Nbh *nbh_src, Nbh *nbh_dst) { +Nbh *N_18_1(Nbh *nbh_src, Nbh *nbh_dst) +{ int i, j, k; Nbh *nbh; @@ -288,13 +297,15 @@ Nbh *N_18_1(Nbh *nbh_src, Nbh *nbh_dst) { (*nbh)[i][j][k] = 1; else (*nbh)[i][j][k] = 0; - } else + } + else (*nbh)[i][j][k] = 0; return nbh; } -Nbh *N_18_2(Nbh *nbh_src, Nbh *nbh_dst) { +Nbh *N_18_2(Nbh *nbh_src, Nbh *nbh_dst) +{ int i, j, k; Nbh *nbh; @@ -360,7 +371,8 @@ Nbh *N_18_2(Nbh *nbh_src, Nbh *nbh_dst) { return nbh; } -Nbh *N_26_1(Nbh *nbh_src, Nbh *nbh_dst) { +Nbh *N_26_1(Nbh *nbh_src, Nbh *nbh_dst) +{ int i, j, k; Nbh *nbh; @@ -382,7 +394,8 @@ Nbh *N_26_1(Nbh *nbh_src, Nbh *nbh_dst) { return nbh; } -Nbh *Nnk(Nbh *nbh_src, Nbh *nbh_dst, int connectivity) { +Nbh *Nnk(Nbh *nbh_src, Nbh *nbh_dst, int connectivity) +{ Nbh *nbh; if (!nbh_dst) @@ -411,7 +424,8 @@ Nbh *Nnk(Nbh *nbh_src, Nbh *nbh_dst, int connectivity) { return nbh; } -int checkNbh(MRI *mri, int i, int j, int k, int label, int connectivity) { +int checkNbh(MRI *mri, int i, int j, int k, int label, int connectivity) +{ int a, b, c; int con, sum; con = connectivityNumber(connectivity); @@ -427,7 +441,8 @@ int checkNbh(MRI *mri, int i, int j, int k, int label, int connectivity) { return 0; } -int checkSNbh(MRI *mri, int i, int j, int k, int label, int connectivity) { +int checkSNbh(MRI *mri, int i, int j, int k, int label, int connectivity) +{ int a, b, c; int con, sum; con = connectivityNumber(connectivity); @@ -443,7 +458,8 @@ int checkSNbh(MRI *mri, int i, int j, int k, int label, int connectivity) { return 0; } -int checkSimple(Nbh *nbh, int connectivity) { +int checkSimple(Nbh *nbh, int connectivity) +{ Nbh bnbh, dnbh; reverseNbh(nbh, &bnbh); if (checkTn(nbh, &dnbh, connectivity) == 1 && checkTn(&bnbh, &dnbh, associatedConnectivity(connectivity)) == 1) @@ -452,7 +468,8 @@ int checkSimple(Nbh *nbh, int connectivity) { } // compute the topological number associated with a Nbh and a certain connectivity -int checkTn(Nbh *nbh_src, Nbh *nbh_dst, int connectivity) { +int checkTn(Nbh *nbh_src, Nbh *nbh_dst, int connectivity) +{ int i, j, k, a, b, c, ik, jk, kk, ct; int con, nvox, label, sum; int comp_table[MAX_COMP + 2]; @@ -500,7 +517,8 @@ int checkTn(Nbh *nbh_src, Nbh *nbh_dst, int connectivity) { ; (*nbh)[i][j][k] = ct + 1; // label the new basin comp_table[ct] = 1; // note that this number is taken - } else { + } + else { min_val = MAX_COMP + 1; // merging into the smallest value @@ -535,7 +553,8 @@ int checkTn(Nbh *nbh_src, Nbh *nbh_dst, int connectivity) { return nvox; } -int checkSP(Nbh *fgnbh_src, Nbh *fgnbh_dst, int *fgtp, Nbh *bgnbh_src, Nbh *bgnbh_dst, int *bgtp, int connectivity) { +int checkSP(Nbh *fgnbh_src, Nbh *fgnbh_dst, int *fgtp, Nbh *bgnbh_src, Nbh *bgnbh_dst, int *bgtp, int connectivity) +{ (*fgtp) = checkTn(fgnbh_src, fgnbh_dst, connectivity); (*bgtp) = checkTn(bgnbh_src, bgnbh_dst, associatedConnectivity(connectivity)); @@ -549,7 +568,8 @@ int checkSP(Nbh *fgnbh_src, Nbh *fgnbh_dst, int *fgtp, Nbh *bgnbh_src, Nbh *bgnb // for the Strong Connectivity, the two points are assumed to be inside X, Y-adjacent // and x1 is insice N26(x1) int checkSC( - MRI *mri, int i0, int j0, int k0, int i1, int j1, int k1, int inside_label, int outside_label, int connectivity) { + MRI *mri, int i0, int j0, int k0, int i1, int j1, int k1, int inside_label, int outside_label, int connectivity) +{ Nbh nbh1, nbh2; int u, v, w, a, b, c, loop; @@ -582,7 +602,8 @@ int checkSC( // Check if two points are weakly X-connected with respect to Y // for the Weak Connectivity, the two points are assumed to be inside X, Y-adjacent int checkWC( - MRI *mri, int i0, int j0, int k0, int i1, int j1, int k1, int inside_label, int outside_label, int connectivity) { + MRI *mri, int i0, int j0, int k0, int i1, int j1, int k1, int inside_label, int outside_label, int connectivity) +{ int a, b, c, loop; Nbh nbh; @@ -602,7 +623,8 @@ int checkWC( return 1; } -Nbh *loadNbh2(unsigned char ***im, int x, int y, int z, int label) { +Nbh *loadNbh2(unsigned char ***im, int x, int y, int z, int label) +{ Nbh *nbh = (Nbh *)malloc(sizeof(Nbh)); int i, j, k; @@ -626,7 +648,8 @@ Nbh *loadNbh2(unsigned char ***im, int x, int y, int z, int label) { return nbh; } -Nbh *reverseNbh(Nbh *nbh_src, Nbh *nbh_dst) { +Nbh *reverseNbh(Nbh *nbh_src, Nbh *nbh_dst) +{ Nbh *nbh; int i, j, k; if (nbh_dst) @@ -652,7 +675,8 @@ Nbh *reverseNbh(Nbh *nbh_src, Nbh *nbh_dst) { // /////////////////////////////////////////////////////////////////////// -typedef struct Cell { +typedef struct Cell +{ struct Cell *next, *previous; int x, y, z; unsigned char type; @@ -711,7 +735,8 @@ typedef struct Cell { #define MINMAX(a, b, c) MIN(a, MAX(b, c)) #define PROB(x) MINMAX(MAXPROB, MINPROB, x) -typedef struct { +typedef struct +{ int number_of_bins; int reference_max_cell; int ncells; @@ -721,7 +746,8 @@ typedef struct { Cell ***table; } List; -typedef struct ConnectedComponent { +typedef struct ConnectedComponent +{ struct ConnectedComponent *next, *previous; int ncells; int maxcells; @@ -731,14 +757,16 @@ typedef struct ConnectedComponent { unsigned char found; } ConnectedComponent; -typedef struct SEGMENTATION { +typedef struct SEGMENTATION +{ int ncomponents; int maxcomponents; ConnectedComponent *components; void *ccs; } SEGMENTATION; -typedef struct CCSorting { +typedef struct CCSorting +{ int number_of_bins; int reference_max_component; int ncomponents; @@ -749,7 +777,8 @@ typedef struct CCSorting { } CCS; /*parameters used by the process*/ -typedef struct TC_PARMS { +typedef struct TC_PARMS +{ // to allow the printing of the errors int verbose_mode; @@ -887,7 +916,8 @@ static int componentMerge(TC_PARMS *parms, int s0, int s1); static void SaveOrigMaps(TC_PARMS *parms); static TC_PARMS *initTC_PARMSfromMRITOPOLOGY_PARMS(MRI_TOPOLOGY_PARMS *parms); -static List *initList(int nbr_of_bins, int width, int height, int depth) { +static List *initList(int nbr_of_bins, int width, int height, int depth) +{ int k, i, j; List *list; if (nbr_of_bins < 1) nbr_of_bins = BIN_NBR; @@ -919,7 +949,8 @@ static List *initList(int nbr_of_bins, int width, int height, int depth) { return list; } -static int listFree(List **list) { +static int listFree(List **list) +{ int k, j, height, depth; List *l = *list; *list = NULL; @@ -938,7 +969,8 @@ static int listFree(List **list) { return NO_ERROR; } -static int removeCell(List *list, Cell *old_cell) { +static int removeCell(List *list, Cell *old_cell) +{ int ref; Cell *ncell; float old_prior = old_cell->prior; @@ -952,7 +984,8 @@ static int removeCell(List *list, Cell *old_cell) { { list->sorting[ref] = ncell; if (ncell) ncell->previous = NULL; - } else // non first element of the list + } + else // non first element of the list { old_cell->previous->next = ncell; if (ncell) ncell->previous = old_cell->previous; @@ -973,7 +1006,8 @@ static int removeCell(List *list, Cell *old_cell) { return NO_ERROR; } -static int addCell(List *list, Cell *new_cell) { +static int addCell(List *list, Cell *new_cell) +{ Cell *cell, *pcell; int ref; float new_prior = new_cell->prior; @@ -988,7 +1022,8 @@ static int addCell(List *list, Cell *new_cell) { new_cell->next = NULL; new_cell->previous = NULL; list->sorting[ref] = new_cell; - } else // find the correct location + } + else // find the correct location { if (new_prior > cell->prior) // must be the first element { @@ -996,8 +1031,9 @@ static int addCell(List *list, Cell *new_cell) { new_cell->previous = NULL; list->sorting[ref] = new_cell; cell->previous = new_cell; - } else // must find the correct location - { // in this case, we put the cell at the last correct location + } + else // must find the correct location + { // in this case, we put the cell at the last correct location pcell = cell; cell = cell->next; while ((cell != NULL) && (cell->prior >= new_prior)) { @@ -1018,7 +1054,8 @@ static int addCell(List *list, Cell *new_cell) { return NO_ERROR; } -static CCS *initCCS(int nbr_of_bins, SEGMENTATION *segmentation) { +static CCS *initCCS(int nbr_of_bins, SEGMENTATION *segmentation) +{ CCS *ccs; if (nbr_of_bins < 1) nbr_of_bins = NBR_OF_COMPTS; @@ -1032,7 +1069,8 @@ static CCS *initCCS(int nbr_of_bins, SEGMENTATION *segmentation) { return ccs; } -static int CCSfree(CCS **ccs) { +static int CCSfree(CCS **ccs) +{ CCS *c = *ccs; *ccs = NULL; @@ -1042,7 +1080,8 @@ static int CCSfree(CCS **ccs) { return NO_ERROR; } -static int ccsSortComponents(CCS *ccs) { +static int ccsSortComponents(CCS *ccs) +{ int k; ConnectedComponent *cmpt; @@ -1059,7 +1098,8 @@ static int ccsSortComponents(CCS *ccs) { return NO_ERROR; } -static int removeComponent(CCS *ccs, ConnectedComponent *old_cmpt) { +static int removeComponent(CCS *ccs, ConnectedComponent *old_cmpt) +{ int ref; ConnectedComponent *ncmpt; float old_cost = old_cmpt->cost; @@ -1073,7 +1113,8 @@ static int removeComponent(CCS *ccs, ConnectedComponent *old_cmpt) { { ccs->sorting[ref] = ncmpt; if (ncmpt) ncmpt->previous = NULL; - } else // non first element of the list + } + else // non first element of the list { old_cmpt->previous->next = ncmpt; if (ncmpt) ncmpt->previous = old_cmpt->previous; @@ -1094,7 +1135,8 @@ static int removeComponent(CCS *ccs, ConnectedComponent *old_cmpt) { return NO_ERROR; } -static int addComponent(CCS *ccs, ConnectedComponent *new_component) { +static int addComponent(CCS *ccs, ConnectedComponent *new_component) +{ ConnectedComponent *component, *pcomponent; int ref; float new_cost = new_component->cost; @@ -1109,7 +1151,8 @@ static int addComponent(CCS *ccs, ConnectedComponent *new_component) { new_component->next = NULL; new_component->previous = NULL; ccs->sorting[ref] = new_component; - } else // find the correct location + } + else // find the correct location { if (new_cost > component->cost) // must be the first element { @@ -1117,8 +1160,9 @@ static int addComponent(CCS *ccs, ConnectedComponent *new_component) { new_component->previous = NULL; ccs->sorting[ref] = new_component; component->previous = new_component; - } else // must find the correct location - { // in this case, we put the component at the last correct location + } + else // must find the correct location + { // in this case, we put the component at the last correct location pcomponent = component; component = component->next; while ((component != NULL) && (component->cost >= new_cost)) { @@ -1139,7 +1183,8 @@ static int addComponent(CCS *ccs, ConnectedComponent *new_component) { return NO_ERROR; } -static int reallocateComponent(ConnectedComponent *cc, int maxcells) { +static int reallocateComponent(ConnectedComponent *cc, int maxcells) +{ int k; Cell **oldcells; @@ -1155,7 +1200,8 @@ static int reallocateComponent(ConnectedComponent *cc, int maxcells) { return NO_ERROR; } -static int reallocateSegmentation(SEGMENTATION *segmentation, int maxcomponents) { +static int reallocateSegmentation(SEGMENTATION *segmentation, int maxcomponents) +{ int k, n; CCS *ccs; ConnectedComponent *oldcc; @@ -1179,7 +1225,8 @@ static int reallocateSegmentation(SEGMENTATION *segmentation, int maxcomponents) return NO_ERROR; } -static int addCellToComponent(ConnectedComponent *cc, Cell *cell) { +static int addCellToComponent(ConnectedComponent *cc, Cell *cell) +{ if (cc->ncells >= cc->maxcells) reallocateComponent(cc, nint(cc->maxcells * 1.5)); cc->cells[cc->ncells] = cell; @@ -1190,7 +1237,8 @@ static int addCellToComponent(ConnectedComponent *cc, Cell *cell) { return NO_ERROR; } -static int componentNew(SEGMENTATION *segmentation) { +static int componentNew(SEGMENTATION *segmentation) +{ int s; if (segmentation->ncomponents >= segmentation->maxcomponents) reallocateSegmentation(segmentation, nint(segmentation->maxcomponents * 1.5)); @@ -1201,7 +1249,8 @@ static int componentNew(SEGMENTATION *segmentation) { return (s); } -static SEGMENTATION *segmentationAlloc(int maxcomponents, int maxcells) { +static SEGMENTATION *segmentationAlloc(int maxcomponents, int maxcells) +{ SEGMENTATION *segmentation; ConnectedComponent *cc; int k; @@ -1220,7 +1269,8 @@ static SEGMENTATION *segmentationAlloc(int maxcomponents, int maxcells) { return segmentation; } -static int segmentationFree(SEGMENTATION **segmentation) { +static int segmentationFree(SEGMENTATION **segmentation) +{ int k; SEGMENTATION *seg = *segmentation; @@ -1236,7 +1286,8 @@ static int segmentationFree(SEGMENTATION **segmentation) { return NO_ERROR; } -static int initCCSSEG(TC_PARMS *parms) { +static int initCCSSEG(TC_PARMS *parms) +{ parms->segmentation = segmentationAlloc(MAXCOMPONENTS, MAXCELLS); parms->ccs = initCCS(NBR_OF_COMPTS, parms->segmentation); parms->segmentation->ccs = parms->ccs; @@ -1244,7 +1295,8 @@ static int initCCSSEG(TC_PARMS *parms) { return NO_ERROR; } -static int TC_PARMSfree(TC_PARMS **parms) { +static int TC_PARMSfree(TC_PARMS **parms) +{ TC_PARMS *p = *parms; *parms = NULL; @@ -1275,7 +1327,8 @@ static int TC_PARMSfree(TC_PARMS **parms) { return NO_ERROR; } -static void setBorderValueToSegmentation(TC_PARMS *parms, int s, int dst) { +static void setBorderValueToSegmentation(TC_PARMS *parms, int s, int dst) +{ SEGMENTATION *segmentation = parms->segmentation; Cell ***table = parms->list->table; int i, j, k; @@ -1310,7 +1363,8 @@ static void setBorderValueToSegmentation(TC_PARMS *parms, int s, int dst) { for (j = dst; j < height - dst; j++) addCellToComponent(&segmentation->components[s], &table[k][j][i]); } -static void setBorderValue(MRI *mri, int val, int dst) { +static void setBorderValue(MRI *mri, int val, int dst) +{ int i, j, k; int width, height, depth; @@ -1384,7 +1438,8 @@ static void setBorderValue(MRI *mri, int val, int dst) { static float f(float x) { return x; } -static int initCellsFromMap(TC_PARMS *parms) { +static int initCellsFromMap(TC_PARMS *parms) +{ int i, j, k; int width, height, depth; float cost, dval, val, pval, A, prior; @@ -1422,7 +1477,8 @@ static int initCellsFromMap(TC_PARMS *parms) { { pval = MRIFvox(mri_fprior, i, j, k); cost = MRIFvox(mri_fcost, i, j, k); - } else { + } + else { pval = MRIFvox(mri_bprior, i, j, k); cost = MRIFvox(mri_bcost, i, j, k); } @@ -1451,7 +1507,8 @@ static int initCellsFromMap(TC_PARMS *parms) { { prior = MRIFvox(mri_fprior, i, j, k); cost = MRIFvox(mri_fcost, i, j, k); - } else { + } + else { prior = MRIFvox(mri_bprior, i, j, k); cost = MRIFvox(mri_bcost, i, j, k); } @@ -1474,7 +1531,8 @@ static int initCellsFromMap(TC_PARMS *parms) { { pval = MRIFvox(mri_fprior, i, j, k); cost = MRIFvox(mri_fcost, i, j, k); - } else { + } + else { pval = MRIFvox(mri_bprior, i, j, k); cost = MRIFvox(mri_bcost, i, j, k); } @@ -1531,7 +1589,8 @@ static int initCellsFromMap(TC_PARMS *parms) { return NO_ERROR; } -static void addBorderVoxels(TC_PARMS *parms, int dst) { +static void addBorderVoxels(TC_PARMS *parms, int dst) +{ int i, j, k; MRI *mri = parms->mri_bin; int width, height, depth; @@ -1599,7 +1658,8 @@ static void addBorderVoxels(TC_PARMS *parms, int dst) { } } -static float computeMap(TC_PARMS *parms) { +static float computeMap(TC_PARMS *parms) +{ int width, height, depth, i, j, k, x, y, z, xinit, yinit, zinit, val, n, nlabels, *tab; MRI *mri_seg = parms->mri_seg, *mri = parms->mri_bin, *mri_psi = parms->mri_prob, *mri_pcsi = parms->mri_cprob; double map; @@ -1633,7 +1693,8 @@ static float computeMap(TC_PARMS *parms) { return map; } -static int computeNLabels(TC_PARMS *parms) { +static int computeNLabels(TC_PARMS *parms) +{ int width, height, depth, i, j, k, x, y, z, xinit, yinit, zinit, val, n, nlabels, *tab; MRI *mri_seg = parms->mri_seg, *mri = parms->mri_bin; int nb, count; @@ -1677,7 +1738,8 @@ static int computeNLabels(TC_PARMS *parms) { return nb; } -static void SmoothImage(MRI *mri, TC_PARMS *parms) { +static void SmoothImage(MRI *mri, TC_PARMS *parms) +{ MRI *mri_bin = parms->mri_bin, *mri_tmp; int width, height, depth, i, j, k, a, b, c; float average, val; @@ -1704,7 +1766,8 @@ static void SmoothImage(MRI *mri, TC_PARMS *parms) { val += 1.0f; } MRIFvox(mri, i, j, k) = average / val; - } else if (nint(MRIgetVoxVal(mri_bin, i, j, k, 0)) == B_R) { + } + else if (nint(MRIgetVoxVal(mri_bin, i, j, k, 0)) == B_R) { average = 0; val = 0.0f; for (a = -1; a < 2; a++) @@ -1721,12 +1784,14 @@ static void SmoothImage(MRI *mri, TC_PARMS *parms) { } #define MRI_PI 3.14159 -static double gauss(double x, double m, double v) { +static double gauss(double x, double m, double v) +{ return (1. / (sqrt((double)2. * MRI_PI * v)) * exp(-(double)0.5 * SQR((x - m)) / v)); } #define NLABELS 50 -static void initProb(TC_PARMS *parms) { +static void initProb(TC_PARMS *parms) +{ GCA *gca; GCA_PRIOR *gcap; GCA_NODE *gcan; @@ -1920,7 +1985,8 @@ static void initProb(TC_PARMS *parms) { if (!parms->transform) free(transform); } -static void initCostMaps(TC_PARMS *parms) { +static void initCostMaps(TC_PARMS *parms) +{ int i, j, k, width, depth, height; MRI *mri = parms->mri_bin, *mri_fcost, *mri_bcost, *mri_psi, *mri_pcsi, *mri_dist; char fname[100]; @@ -1991,7 +2057,8 @@ static void initCostMaps(TC_PARMS *parms) { } } -static void initPriorMaps(TC_PARMS *parms) { +static void initPriorMaps(TC_PARMS *parms) +{ int i, j, k, width, depth, height; MRI *mri = parms->mri_bin, *mri_dist = parms->mri_dist, *mri_fprior, *mri_bprior, *mri_psi, *mri_pcsi; char fname[100]; @@ -2046,7 +2113,8 @@ static void initPriorMaps(TC_PARMS *parms) { } } -static void guessSegmentation(TC_PARMS *parms) { +static void guessSegmentation(TC_PARMS *parms) +{ GCA *gca; GCA_PRIOR *gcap; GCA_NODE *gcan; @@ -2213,7 +2281,8 @@ static void guessSegmentation(TC_PARMS *parms) { MRIwrite(mri_seg, "/tmp/tmp"); } -static void initImages(TC_PARMS *parms) { +static void initImages(TC_PARMS *parms) +{ int i, j, k, width, depth, height, xinit, yinit, zinit, a, b, c; MRI *mri, *mri_bin, *mri_dist, *mri_prob, *mri_cprob, *mri_labeled; int changed, con, sum, absval, val; @@ -2336,7 +2405,8 @@ static void initImages(TC_PARMS *parms) { changed = 1; if (absval + 1 > max_dist_int) max_dist_int = absval + 1; } - } else if (nint(MRIgetVoxVal(mri_bin, i, j, k, 0)) == B_R) // outside the volume + } + else if (nint(MRIgetVoxVal(mri_bin, i, j, k, 0)) == B_R) // outside the volume { con = associatedConnectivity(parms->b_c); absval = 1000; @@ -2390,7 +2460,8 @@ static void initImages(TC_PARMS *parms) { MRIFvox(mri_cprob, i + 2, j + 2, k + 2) = 1.0f - MRIFvox(mri_prob, i + 2, j + 2, k + 2); } MRIfree(&mri_tmp); - } else + } + else initProb(parms); // allocate and init mri_labeled volume @@ -2408,7 +2479,8 @@ static void initImages(TC_PARMS *parms) { if (parms->mapsfname) SaveOrigMaps(parms); } -static int mriChangeLabel(MRI *mri, int src, int dst) { +static int mriChangeLabel(MRI *mri, int src, int dst) +{ int i, j, k, width, height, depth, count; width = mri->width; @@ -2427,7 +2499,8 @@ static int mriChangeLabel(MRI *mri, int src, int dst) { return NO_ERROR; } -static void modifyImage(TC_PARMS *parms) { +static void modifyImage(TC_PARMS *parms) +{ int i, j, k; int width, height, depth; int xinit, yinit, zinit; @@ -2467,7 +2540,8 @@ static void modifyImage(TC_PARMS *parms) { } } -static MSV *findPoint(TC_PARMS *parms, MSV *point) { +static MSV *findPoint(TC_PARMS *parms, MSV *point) +{ MSV *pt; MRI *mri = parms->mri_bin, *mri_labeled = parms->mri_labeled; int border_labels[27], nlabels; @@ -2510,7 +2584,8 @@ static MSV *findPoint(TC_PARMS *parms, MSV *point) { pt->y = y; pt->z = z; } - } else { + } + else { loadNbh(mri, &fnbh, x, y, z, RESIDUE); if (checkTn(&fnbh, &fnbh, associatedconnectivity) == 0) { MRIsetVoxVal(mri, x, y, z, 0, BODY); @@ -2518,7 +2593,8 @@ static MSV *findPoint(TC_PARMS *parms, MSV *point) { addCellToComponent(&parms->segmentation->components[s], &parms->list->table[z][y][x]); MRISvox(parms->mri_labeled, x, y, z) = s; addComponent(parms->ccs, &parms->segmentation->components[s]); - } else { + } + else { maxprior = table[z][y][x].prior; pt->x = x; pt->y = y; @@ -2526,7 +2602,8 @@ static MSV *findPoint(TC_PARMS *parms, MSV *point) { } } }; - } else { + } + else { maxprior = -1; for (z = 1; (z < depth - 1); z++) for (y = 1; (y < height - 1); y++) @@ -2584,7 +2661,8 @@ static MSV *findPoint(TC_PARMS *parms, MSV *point) { pt->y = y; pt->z = z; } - } else { + } + else { loadNbh(mri, &fnbh, x, y, z, RESIDUE); if (checkTn(&fnbh, &fnbh, associatedconnectivity) == 0) { MRIsetVoxVal(mri, x, y, z, 0, BODY); @@ -2592,7 +2670,8 @@ static MSV *findPoint(TC_PARMS *parms, MSV *point) { addCellToComponent(&parms->segmentation->components[s], &parms->list->table[z][y][x]); addComponent(parms->ccs, &parms->segmentation->components[s]); MRISvox(parms->mri_labeled, x, y, z) = s; - } else { + } + else { parms->nlabels = 0; maxprior = table[z][y][x].prior; pt->x = x; @@ -2610,7 +2689,8 @@ static MSV *findPoint(TC_PARMS *parms, MSV *point) { return pt; } -static MSV *findMLVoxel(TC_PARMS *parms, MSV *point) { +static MSV *findMLVoxel(TC_PARMS *parms, MSV *point) +{ MSV *pt; List *list = parms->list; Cell *cell; @@ -2658,7 +2738,8 @@ static MSV *findMLVoxel(TC_PARMS *parms, MSV *point) { pt->y = cell->y; pt->z = cell->z; loop = 0; - } else { + } + else { cell->type = NONSIMPLE; cell = cell->next; } @@ -2666,7 +2747,8 @@ static MSV *findMLVoxel(TC_PARMS *parms, MSV *point) { } } } - } else { + } + else { border_labels = parms->border_labels; con = connectivityNumber(connectivity); mri_labeled = parms->mri_labeled; @@ -2735,7 +2817,8 @@ static MSV *findMLVoxel(TC_PARMS *parms, MSV *point) { pt->y = cell->y; pt->z = cell->z; loop = 0; - } else { + } + else { cell->type = NONSIMPLE; cell = cell->next; } @@ -2752,7 +2835,8 @@ static MSV *findMLVoxel(TC_PARMS *parms, MSV *point) { return pt; } -static int findNeighbors(TC_PARMS *parms, MSV *pt) { +static int findNeighbors(TC_PARMS *parms, MSV *pt) +{ int a, b, c, sum, con, val, x, y, z; List *list = parms->list; MRI *mri = parms->mri_bin; @@ -2781,7 +2865,8 @@ static int findNeighbors(TC_PARMS *parms, MSV *pt) { return NO_ERROR; } -static void changeLabelfromList(TC_PARMS *parms) { +static void changeLabelfromList(TC_PARMS *parms) +{ List *list = parms->list; int k, x, y, z; Cell *cell, *ncell; @@ -2801,7 +2886,8 @@ static void changeLabelfromList(TC_PARMS *parms) { } } -static int segmentVoxel(TC_PARMS *parms, MSV *pt) { +static int segmentVoxel(TC_PARMS *parms, MSV *pt) +{ int nlabels = parms->nlabels, *border_labels = parms->border_labels; SEGMENTATION *segmentation = parms->segmentation, *seg; ConnectedComponent *cc; @@ -2856,7 +2942,8 @@ static int segmentVoxel(TC_PARMS *parms, MSV *pt) { if (parms->c_c == parms->f_c) { seg = parms->F_Rseg; ccs = parms->F_Rccs; - } else { + } + else { seg = parms->B_Rseg; ccs = parms->B_Rccs; } @@ -2888,7 +2975,8 @@ static int segmentVoxel(TC_PARMS *parms, MSV *pt) { return NO_ERROR; } -static void CTExpansion(TC_PARMS *parms) { +static void CTExpansion(TC_PARMS *parms) +{ MSV pt; int x, y, z, count = 0; List *list = parms->list; @@ -2926,7 +3014,8 @@ static void CTExpansion(TC_PARMS *parms) { changeLabelfromList(parms); } -static int componentMerge(TC_PARMS *parms, int s0, int s1) { +static int componentMerge(TC_PARMS *parms, int s0, int s1) +{ SEGMENTATION *segmentation = parms->segmentation; MRI *mri_labeled = parms->mri_labeled; ConnectedComponent *cc0, *cc1; @@ -2963,7 +3052,8 @@ static int componentMerge(TC_PARMS *parms, int s0, int s1) { // assumes that the important labels are BODY,RESIDUE // eventually assignes the ISOLATED label to some voxels -static int segmentBody(TC_PARMS *parms) { +static int segmentBody(TC_PARMS *parms) +{ MSV msv; int s, x, y, z; @@ -2993,7 +3083,8 @@ static int segmentBody(TC_PARMS *parms) { return NO_ERROR; } -static int segmentConnectedComponents(TC_PARMS *parms, Cell **list, int ncells) { +static int segmentConnectedComponents(TC_PARMS *parms, Cell **list, int ncells) +{ SEGMENTATION *segmentation = parms->segmentation; MRI *mri = parms->mri_bin, *mri_labeled = parms->mri_labeled; ConnectedComponent *cc; @@ -3068,7 +3159,8 @@ static int segmentConnectedComponents(TC_PARMS *parms, Cell **list, int ncells) } // analyze two RCCs to see if they need to be merged together! -static int analyzeRCCs(TC_PARMS *parms, SEGMENTATION *bccseg, int rcc0, int rcc1) { +static int analyzeRCCs(TC_PARMS *parms, SEGMENTATION *bccseg, int rcc0, int rcc1) +{ int x0, y0, z0, x1, y1, z1, ncells0, ncells1, a, b, c; Cell **list0, **list1; int loop, m, n, l, p, sum; @@ -3088,7 +3180,8 @@ static int analyzeRCCs(TC_PARMS *parms, SEGMENTATION *bccseg, int rcc0, int rcc1 list1 = parms->segmentation->components[rcc1].cells; ncells0 = parms->segmentation->components[rcc0].ncells; ncells1 = parms->segmentation->components[rcc1].ncells; - } else { + } + else { list0 = parms->segmentation->components[rcc1].cells; list1 = parms->segmentation->components[rcc0].cells; ncells0 = parms->segmentation->components[rcc1].ncells; @@ -3161,7 +3254,8 @@ static int analyzeRCCs(TC_PARMS *parms, SEGMENTATION *bccseg, int rcc0, int rcc1 } // return !=-1 only if an RCC is found with a label smaller than rcc -static int findRCC(TC_PARMS *parms, int rcc) { +static int findRCC(TC_PARMS *parms, int rcc) +{ int label; int x, y, z, a, b, c, k, loop, val1, val2; MRI *mri_bin = parms->mri_bin, *mri_labeled = parms->mri_labeled; @@ -3190,7 +3284,8 @@ static int findRCC(TC_PARMS *parms, int rcc) { } #define MAX_BORDER_LABELS 50 -static int mergeRCC(TC_PARMS *parms, SEGMENTATION *segmentation) { +static int mergeRCC(TC_PARMS *parms, SEGMENTATION *segmentation) +{ int k, nrcccomponents, rcclabel, nlabels, maxlabels, *border_labels, *tmp, m; // ConnectedComponent *component; int count; @@ -3233,7 +3328,8 @@ static int mergeRCC(TC_PARMS *parms, SEGMENTATION *segmentation) { } #define CELLNBR 10000 -static int computeResidualSegmentation(TC_PARMS *parms) { +static int computeResidualSegmentation(TC_PARMS *parms) +{ int i, j, k, n; int width, height, depth; MRI *mri = parms->mri_bin; @@ -3302,7 +3398,8 @@ static void PrintSurfaceStatistics(MRI *mri,int label,int connectivity) #endif -static int backgroundSegmentation(TC_PARMS *parms) { +static int backgroundSegmentation(TC_PARMS *parms) +{ int s; // first segmentation of the main connecting component @@ -3318,7 +3415,8 @@ static int backgroundSegmentation(TC_PARMS *parms) { return NO_ERROR; } -static void SaveOrigMaps(TC_PARMS *parms) { +static void SaveOrigMaps(TC_PARMS *parms) +{ MRI *mri; char fname[100]; int width, height, depth, x, y, z; @@ -3358,7 +3456,8 @@ static void SaveOrigMaps(TC_PARMS *parms) { MRIfree(&mri); } -static void SaveInitMaps(TC_PARMS *parms) { +static void SaveInitMaps(TC_PARMS *parms) +{ MRI *mri, *mri_cost, *mri_seg; char fname[100]; int width, height, depth, k, l, x, y, z; @@ -3435,7 +3534,8 @@ static void SaveInitMaps(TC_PARMS *parms) { MRIfree(&mri_cost); } -static int initSegmentation(TC_PARMS *parms) { +static int initSegmentation(TC_PARMS *parms) +{ if (parms->verbose_mode) { fprintf(stderr, "\n***********************************************"); fprintf(stderr, "\nINITIALIZATION OF THE SEGMENTATION"); @@ -3504,7 +3604,8 @@ static int initSegmentation(TC_PARMS *parms) { return NO_ERROR; } -static int findandRemoveComponents(TC_PARMS *parms) { +static int findandRemoveComponents(TC_PARMS *parms) +{ CCS *ccs; ConnectedComponent *cc, *ncc; MRI *mri = parms->mri_bin, *mri_labeled = parms->mri_labeled, *mri_prior, *mri_cost; @@ -3525,7 +3626,8 @@ static int findandRemoveComponents(TC_PARMS *parms) { label = B_R; mri_prior = parms->mri_bprior; mri_cost = parms->mri_bcost; - } else { + } + else { ccs = parms->B_Bccs; // body seg = parms->B_Bseg; label = F_R; @@ -3575,7 +3677,8 @@ static int findandRemoveComponents(TC_PARMS *parms) { label = B_R; mri_prior = parms->mri_bprior; mri_cost = parms->mri_bcost; - } else { + } + else { ccs = parms->B_Rccs; // residue seg = parms->B_Rseg; label = F_R; @@ -3621,7 +3724,8 @@ static int findandRemoveComponents(TC_PARMS *parms) { label = B_R; mri_prior = parms->mri_bprior; mri_cost = parms->mri_bcost; - } else { + } + else { ccs = parms->F_Rccs; // residue seg = parms->F_Rseg; label = F_R; @@ -3662,13 +3766,15 @@ static int findandRemoveComponents(TC_PARMS *parms) { return check; } -static int updateVolume(TC_PARMS *parms) { +static int updateVolume(TC_PARMS *parms) +{ if (parms->c_c == parms->f_c) { mriChangeLabel(parms->mri_bin, F_B, BODY); mriChangeLabel(parms->mri_bin, F_R, RESIDUE); parms->segmentation = parms->F_Bseg; parms->ccs = parms->F_Bccs; - } else { + } + else { mriChangeLabel(parms->mri_bin, B_B, BODY); mriChangeLabel(parms->mri_bin, B_R, RESIDUE); parms->segmentation = parms->B_Bseg; @@ -3678,13 +3784,15 @@ static int updateVolume(TC_PARMS *parms) { return NO_ERROR; } -static int resetVolume(TC_PARMS *parms) { +static int resetVolume(TC_PARMS *parms) +{ // PrintSurfaceStatistics(parms->mri_bin,BODY,parms->c_c); if (parms->c_c == parms->f_c) { mriChangeLabel(parms->mri_bin, BODY, F_B); mriChangeLabel(parms->mri_bin, RESIDUE, F_R); - } else { + } + else { mriChangeLabel(parms->mri_bin, BODY, B_B); mriChangeLabel(parms->mri_bin, RESIDUE, B_R); } @@ -3692,7 +3800,8 @@ static int resetVolume(TC_PARMS *parms) { return NO_ERROR; } -static int updateResidualSegmentation(TC_PARMS *parms) { +static int updateResidualSegmentation(TC_PARMS *parms) +{ int i, j, k; int width, height, depth; MRI *mri = parms->mri_bin, *mri_labeled = parms->mri_labeled; @@ -3704,7 +3813,8 @@ static int updateResidualSegmentation(TC_PARMS *parms) { if (parms->c_c == parms->f_c) { parms->segmentation = parms->F_Rseg; parms->ccs = parms->F_Rccs; - } else { + } + else { parms->segmentation = parms->B_Rseg; parms->ccs = parms->B_Rccs; } @@ -3727,7 +3837,8 @@ static int updateResidualSegmentation(TC_PARMS *parms) { } #define INITCOST 100000000.0 -static float updateThreshold(TC_PARMS *parms, int type) { +static float updateThreshold(TC_PARMS *parms, int type) +{ int ref, k; CCS *bccs, *rccs; ConnectedComponent *cc; @@ -3737,7 +3848,8 @@ static float updateThreshold(TC_PARMS *parms, int type) { { bccs = parms->F_Bccs; rccs = parms->F_Rccs; - } else { + } + else { bccs = parms->B_Bccs; rccs = parms->B_Rccs; } @@ -3780,7 +3892,8 @@ static float updateThreshold(TC_PARMS *parms, int type) { return MIN(th1, th2); } -static int correctSegmentation(TC_PARMS *parms) { +static int correctSegmentation(TC_PARMS *parms) +{ float threshold, th1, th2; if (parms->verbose_mode) { fprintf(stderr, "\n****************************************************"); @@ -3793,11 +3906,13 @@ static int correctSegmentation(TC_PARMS *parms) { { parms->c_c = parms->f_c; parms->threshold = updateThreshold(parms, parms->c_c); - } else if (parms->mode == 2) // priority to the background ! + } + else if (parms->mode == 2) // priority to the background ! { parms->c_c = parms->b_c; parms->threshold = updateThreshold(parms, parms->c_c); - } else { + } + else { th1 = updateThreshold(parms, parms->f_c); // foreground correction -> priority background th2 = updateThreshold(parms, parms->b_c); // background threshold = MIN(th1, th2); @@ -3884,7 +3999,8 @@ static int correctSegmentation(TC_PARMS *parms) { // at this point the volume F_R is topologically correct // Just need to add point without changing the topology -static int finalConditionalExpansion(TC_PARMS *parms) { +static int finalConditionalExpansion(TC_PARMS *parms) +{ int width, height, depth, n, ref, x, y, z, xinit, yinit, zinit, i, j, k, val; // int label; int nlabels = parms->nblabels, *tab = parms->labels, test; @@ -3981,7 +4097,8 @@ static int finalConditionalExpansion(TC_PARMS *parms) { return NO_ERROR; } -static TC_PARMS *initTC_PARMSfromMRITOPOLOGY_PARMS(MRI_TOPOLOGY_PARMS *parms) { +static TC_PARMS *initTC_PARMSfromMRITOPOLOGY_PARMS(MRI_TOPOLOGY_PARMS *parms) +{ TC_PARMS *p; int n; @@ -4014,7 +4131,8 @@ static TC_PARMS *initTC_PARMSfromMRITOPOLOGY_PARMS(MRI_TOPOLOGY_PARMS *parms) { return p; } -MRI *MRIcorrectTopology(MRI *mri_orig, MRI *mri_seg, MRI *mri_output, MRI_TOPOLOGY_PARMS *mritopparms) { +MRI *MRIcorrectTopology(MRI *mri_orig, MRI *mri_seg, MRI *mri_output, MRI_TOPOLOGY_PARMS *mritopparms) +{ TC_PARMS *parms; parms = initTC_PARMSfromMRITOPOLOGY_PARMS(mritopparms); @@ -4048,7 +4166,8 @@ MRI *MRIcorrectTopology(MRI *mri_orig, MRI *mri_seg, MRI *mri_output, MRI_TOPOLO return mri_output; } -MRI_TOPOLOGY_PARMS *MRI_TOPOLOGY_PARMSalloc(void) { +MRI_TOPOLOGY_PARMS *MRI_TOPOLOGY_PARMSalloc(void) +{ MRI_TOPOLOGY_PARMS *parms; parms = (MRI_TOPOLOGY_PARMS *)calloc(1, sizeof(MRI_TOPOLOGY_PARMS)); return parms; diff --git a/utils/mri_transform.c b/utils/mri_transform.c index 3befd7a407a..901563d66e5 100644 --- a/utils/mri_transform.c +++ b/utils/mri_transform.c @@ -28,7 +28,8 @@ static float mfStartY, mfEndY; static float mfStartZ, mfEndZ; static float mfSizeX, mfSizeY, mfSizeZ; -void trans_SetBounds(float ifStartX, float ifEndX, float ifStartY, float ifEndY, float ifStartZ, float ifEndZ) { +void trans_SetBounds(float ifStartX, float ifEndX, float ifStartY, float ifEndY, float ifStartZ, float ifEndZ) +{ mfStartX = ifStartX; mfEndX = ifEndX; mfStartY = ifStartY; @@ -37,13 +38,15 @@ void trans_SetBounds(float ifStartX, float ifEndX, float ifStartY, float ifEndY, mfEndZ = ifEndZ; } -void trans_SetResolution(float ifSizeX, float ifSizeY, float ifSizeZ) { +void trans_SetResolution(float ifSizeX, float ifSizeY, float ifSizeZ) +{ mfSizeX = ifSizeX; mfSizeY = ifSizeY; mfSizeZ = ifSizeZ; } -void trans_RASToVoxelIndex(double irRASX, double irRASY, double irRASZ, int *onVoxX, int *onVoxY, int *onVoxZ) { +void trans_RASToVoxelIndex(double irRASX, double irRASY, double irRASZ, int *onVoxX, int *onVoxY, int *onVoxZ) +{ double orVoxX, orVoxY, orVoxZ; trans_RASToVoxel(irRASX, irRASY, irRASZ, &orVoxX, &orVoxY, &orVoxZ); @@ -52,7 +55,8 @@ void trans_RASToVoxelIndex(double irRASX, double irRASY, double irRASZ, int *onV *onVoxZ = (int)orVoxZ; } -void trans_RASToVoxel(double irRASX, double irRASY, double irRASZ, double *orVoxX, double *orVoxY, double *orVoxZ) { +void trans_RASToVoxel(double irRASX, double irRASY, double irRASZ, double *orVoxX, double *orVoxY, double *orVoxZ) +{ /* we need to stay in the same type so as not to typecast thee conversion to int until right at the very end. */ @@ -66,13 +70,15 @@ void trans_RASToVoxel(double irRASX, double irRASY, double irRASZ, double *orVox *orVoxZ = ((fRASY - mfStartZ) / mfSizeZ); } -void trans_VoxelToRAS(double irVoxX, double irVoxY, double irVoxZ, double *orRASX, double *orRASY, double *orRASZ) { +void trans_VoxelToRAS(double irVoxX, double irVoxY, double irVoxZ, double *orRASX, double *orRASY, double *orRASZ) +{ *orRASX = (double)(mfEndX - (irVoxX * mfSizeX)); *orRASY = (double)(mfStartZ + (irVoxZ * mfSizeZ)); *orRASZ = (double)(-(mfStartY + (irVoxY * mfSizeY))); } -void trans_VoxelIndexToRAS(int inVoxX, int inVoxY, int inVoxZ, double *orRASX, double *orRASY, double *orRASZ) { +void trans_VoxelIndexToRAS(int inVoxX, int inVoxY, int inVoxZ, double *orRASX, double *orRASY, double *orRASZ) +{ // double irVoxX, irVoxY, irVoxZ; // irVoxX = (double)inVoxX; diff --git a/utils/mriclass.c b/utils/mriclass.c index 95938f76a83..915bc118c9d 100644 --- a/utils/mriclass.c +++ b/utils/mriclass.c @@ -56,7 +56,8 @@ STRUCTURES -------------------------------------------------------*/ -typedef struct { +typedef struct +{ FILE *fp; int npixels[MAX_INPUTS]; MRIC *mric; @@ -99,7 +100,8 @@ static int mricFillInputParms(MRIC *mric, FILE *fp, int round, GET_INPUT_PARMS * Description Free an MRIC structure and all its members. ------------------------------------------------------*/ -int MRICfree(MRIC **pmric) { +int MRICfree(MRIC **pmric) +{ MRIC *mric; int round; @@ -129,7 +131,8 @@ int MRICfree(MRIC **pmric) { Description ------------------------------------------------------*/ -MRIC *MRICalloc(int nrounds, int *types, int *features, void *parms) { +MRIC *MRICalloc(int nrounds, int *types, int *features, void *parms) +{ MRIC *mric; int f, ninputs, round; @@ -179,7 +182,8 @@ MRIC *MRICalloc(int nrounds, int *types, int *features, void *parms) { Description ------------------------------------------------------*/ -int MRICretrain(MRIC *mric, char *file_name) { +int MRICretrain(MRIC *mric, char *file_name) +{ char line[300], *cp; FILE *fp; int nfiles, round; @@ -214,7 +218,8 @@ int MRICretrain(MRIC *mric, char *file_name) { Description ------------------------------------------------------*/ -int MRICtrain(MRIC *mric, char *file_name, char *prior_fname) { +int MRICtrain(MRIC *mric, char *file_name, char *prior_fname) +{ char line[300], *cp; FILE *fp; int nfiles, round; @@ -224,7 +229,8 @@ int MRICtrain(MRIC *mric, char *file_name, char *prior_fname) { mric->mri_priors = MRIread(prior_fname); if (!mric->mri_priors) ErrorReturn(ERROR_NO_FILE, (ERROR_NO_FILE, "MRICtrain: could not load prior file '%s'", prior_fname)); - } else + } + else mric->mri_priors = NULL; /* first figure out the total # of files */ @@ -257,7 +263,8 @@ int MRICtrain(MRIC *mric, char *file_name, char *prior_fname) { Description ------------------------------------------------------*/ -MRIC *MRICread(char *fname) { +MRIC *MRICread(char *fname) +{ MRIC *mric; int ninputs, type[MAX_ROUNDS], features[MAX_ROUNDS], round, nrounds; FILE *fp; @@ -309,7 +316,8 @@ MRIC *MRICread(char *fname) { Description ------------------------------------------------------*/ -MRIC *MRICquickRead(char *fname) { +MRIC *MRICquickRead(char *fname) +{ MRIC *mric; int ninputs, type[MAX_ROUNDS], features[MAX_ROUNDS], round, nrounds; FILE *fp; @@ -356,7 +364,8 @@ MRIC *MRICquickRead(char *fname) { Description ------------------------------------------------------*/ -int MRICwrite(MRIC *mric, char *fname) { +int MRICwrite(MRIC *mric, char *fname) +{ FILE *fp; int round; @@ -396,7 +405,8 @@ int MRICwrite(MRIC *mric, char *fname) { #define PRETTY_SURE .90f #define CLASS_SCALE ((BUFTYPE)1) -MRI *MRICclassify(MRIC *mric, MRI *mri_src, MRI *mri_dst, float conf, MRI *mri_probs, MRI *mri_classes) { +MRI *MRICclassify(MRIC *mric, MRI *mri_src, MRI *mri_dst, float conf, MRI *mri_probs, MRI *mri_classes) +{ MATRIX *m_priors; VECTOR *v_inputs; GCLASSIFY *gc; @@ -502,7 +512,8 @@ MRI *MRICclassify(MRIC *mric, MRI *mri_src, MRI *mri_dst, float conf, MRI *mri_p max_white_class = c; } white_prob += p; - } else { + } + else { if (p > max_non_white_prob) { max_non_white_prob = p; max_non_white_class = c; @@ -513,7 +524,8 @@ MRI *MRICclassify(MRIC *mric, MRI *mri_src, MRI *mri_dst, float conf, MRI *mri_p if (white_prob > non_white_prob) { classno = max_white_class; prob = white_prob; - } else { + } + else { classno = max_non_white_class; prob = non_white_prob; } @@ -532,7 +544,8 @@ MRI *MRICclassify(MRIC *mric, MRI *mri_src, MRI *mri_dst, float conf, MRI *mri_p *pdst++ = 255; else *pdst++ = src; - } else + } + else *pdst++ = 0 /*src*/; } } @@ -564,7 +577,8 @@ static int region_size = DEFAULT_REGION_SIZE; static int region_height = 0; static int region_width = 0; -int MRICsetRegionSize(MRIC *mric, int rwidth, int rheight, int rdepth) { +int MRICsetRegionSize(MRIC *mric, int rwidth, int rheight, int rdepth) +{ int old_rsize = region_size; region_size = rdepth; region_height = rheight; @@ -579,7 +593,8 @@ int MRICsetRegionSize(MRIC *mric, int rwidth, int rheight, int rdepth) { Description ------------------------------------------------------*/ -int MRICresetRegionSize(MRIC *mric) { +int MRICresetRegionSize(MRIC *mric) +{ int old_rsize = region_size; region_size = DEFAULT_REGION_SIZE; region_height = region_width = 0; @@ -593,7 +608,8 @@ int MRICresetRegionSize(MRIC *mric) { Description ------------------------------------------------------*/ -int MRICcomputeInputs(MRIC *mric, MRI *mri, int x, int y, int z, VECTOR *v_inputs, int features) { +int MRICcomputeInputs(MRIC *mric, MRI *mri, int x, int y, int z, VECTOR *v_inputs, int features) +{ static int old_features = 0; static MRI_REGION region = {0, 0, 0, 0, 0, 0}; static MRI *mri_prev = NULL, *mri_zscore3 = NULL, *mri_zscore5 = NULL, *mri_direction = NULL, *mri_mean3 = NULL, @@ -792,7 +808,8 @@ int MRICcomputeInputs(MRIC *mric, MRI *mri, int x, int y, int z, VECTOR *v_input MRIwrite(mri_min5, "min5.mnc"); } } - } else + } + else buffered++; /* x0,y0,z0 are coordinates in region based images (not input mri or polv) */ @@ -848,7 +865,8 @@ int MRICcomputeInputs(MRIC *mric, MRI *mri, int x, int y, int z, VECTOR *v_input contains the class # based on intensity thresholds either provided by the user, or defaults if parms are 0. ------------------------------------------------------*/ -MRI *MRICbuildTargetImage(MRI *mri_src, MRI *mri_target, MRI *mri_wm, int lo_lim, int hi_lim) { +MRI *MRICbuildTargetImage(MRI *mri_src, MRI *mri_target, MRI *mri_wm, int lo_lim, int hi_lim) +{ int x, y, z, width, height, depth; BUFTYPE *psrc, *pwm, *ptarget, src, wm, target, *pthin, thin; MRI *mri_thin; @@ -889,7 +907,8 @@ MRI *MRICbuildTargetImage(MRI *mri_src, MRI *mri_target, MRI *mri_wm, int lo_lim } } } - } else if (src > hi_lim) + } + else if (src > hi_lim) target = BRIGHT_MATTER; else if (src < lo_lim) target = BACKGROUND; @@ -911,7 +930,8 @@ MRI *MRICbuildTargetImage(MRI *mri_src, MRI *mri_target, MRI *mri_wm, int lo_lim ------------------------------------------------------*/ #define COUNT_IMAGE GAUSSIAN_NCLASSES -MRI *MRICupdatePriors(MRI *mri_target, MRI *mri_priors, int scale) { +MRI *MRICupdatePriors(MRI *mri_target, MRI *mri_priors, int scale) +{ int width, height, depth, x, y, z, class, w, h, d, xt, yt, zt; BUFTYPE *ptarget; double xrt, yrt, zrt; @@ -961,7 +981,8 @@ MRI *MRICupdatePriors(MRI *mri_target, MRI *mri_priors, int scale) { Normalize the priors by dividing by the total # of times each pixel has been mapped. ------------------------------------------------------*/ -int MRInormalizePriors(MRI *mri_priors) { +int MRInormalizePriors(MRI *mri_priors) +{ int width, height, depth, x, y, z, class; float *pnorm, norm; @@ -995,7 +1016,8 @@ int MRInormalizePriors(MRI *mri_priors) { Description ------------------------------------------------------*/ -int MRICupdateStatistics(MRIC *mric, int round, MRI *mri_src, MRI *mri_wm, MRI_REGION *box) { +int MRICupdateStatistics(MRIC *mric, int round, MRI *mri_src, MRI *mri_wm, MRI_REGION *box) +{ GCLASSIFY *gc; GCLASS *gcl; int x, y, z, classno, row, col, x1, y1, z1; @@ -1056,7 +1078,8 @@ int MRICupdateStatistics(MRIC *mric, int round, MRI *mri_src, MRI *mri_wm, MRI_R Description ------------------------------------------------------*/ -int MRICcomputeStatistics(MRIC *mric, int round) { +int MRICcomputeStatistics(MRIC *mric, int round) +{ GCLASSIFY *gc; GCLASS *gcl; int classno, nclasses, nobs, row, col; @@ -1098,7 +1121,8 @@ int MRICcomputeStatistics(MRIC *mric, int round) { Description ------------------------------------------------------*/ -char *MRICclassName(MRIC *mric, int round, int classno) { +char *MRICclassName(MRIC *mric, int round, int classno) +{ char *class_name = "unknown"; switch (mric->type[round]) { @@ -1118,7 +1142,8 @@ char *MRICclassName(MRIC *mric, int round, int classno) { Description ------------------------------------------------------*/ -int MRICdump(FILE *fp, MRIC *mric) { +int MRICdump(FILE *fp, MRIC *mric) +{ GCLASSIFY *gc; GCLASS *gcl; int classno, nclasses, fno, round; @@ -1150,7 +1175,8 @@ int MRICdump(FILE *fp, MRIC *mric) { Description ------------------------------------------------------*/ -char *MRICfeatureName(MRIC *mric, int round, int feature_number) { +char *MRICfeatureName(MRIC *mric, int round, int feature_number) +{ int f, fno; /* first ninputs-1 correspond to inputs #s, rest to frames in priors */ @@ -1189,7 +1215,8 @@ char *MRICfeatureName(MRIC *mric, int round, int feature_number) { Description ------------------------------------------------------*/ -char *MRICfeatureNumberToName(int feature_number) { +char *MRICfeatureNumberToName(int feature_number) +{ int f, fno; /* find bit which corresponds to this # */ @@ -1235,7 +1262,8 @@ char *MRICfeatureNumberToName(int feature_number) { Description ------------------------------------------------------*/ -int MRICfeatureNumberCode(int feature_number) { +int MRICfeatureNumberCode(int feature_number) +{ int f, fno; /* find bit which corresponds to this # */ @@ -1254,7 +1282,8 @@ int MRICfeatureNumberCode(int feature_number) { Description ------------------------------------------------------*/ -int MRICfeatureCode(MRIC *mric, int round, int feature_number) { +int MRICfeatureCode(MRIC *mric, int round, int feature_number) +{ int f, fno; /* first ninputs-1 correspond to inputs #s, rest to frames in priors */ @@ -1273,7 +1302,8 @@ int MRICfeatureCode(MRIC *mric, int round, int feature_number) { Description ------------------------------------------------------*/ -int MRICfeatureNumber(MRIC *mric, int round, int feature_code) { +int MRICfeatureNumber(MRIC *mric, int round, int feature_code) +{ int f, fno; /* first ninputs-1 correspond to inputs #s, rest to frames in priors */ @@ -1295,7 +1325,8 @@ int MRICfeatureNumber(MRIC *mric, int round, int feature_code) { compute the statistics (means and covariances) for a Gaussian classifier. ------------------------------------------------------*/ -static int mricComputeGCStatistics(MRIC *mric, FILE *fp, int nfiles, int round) { +static int mricComputeGCStatistics(MRIC *mric, FILE *fp, int nfiles, int round) +{ char source_fname[100], target_fname[100], line[300], *cp; int fno; MRI *mri_src, *mri_target; @@ -1342,7 +1373,8 @@ static int mricComputeGCStatistics(MRIC *mric, FILE *fp, int nfiles, int round) Description Train a Radial Basis Function classifier. ------------------------------------------------------*/ -static int mricTrainRBF(MRIC *mric, FILE *fp, int nfiles, int round) { +static int mricTrainRBF(MRIC *mric, FILE *fp, int nfiles, int round) +{ char *cp, source_fname[100], line[100]; GET_INPUT_PARMS parms; int fno; @@ -1375,7 +1407,8 @@ static int mricTrainRBF(MRIC *mric, FILE *fp, int nfiles, int round) { Description Train a Radial Basis Function classifier. ------------------------------------------------------*/ -static int mricRetrainRBF(MRIC *mric, FILE *fp, int nfiles, int round) { +static int mricRetrainRBF(MRIC *mric, FILE *fp, int nfiles, int round) +{ char *cp, source_fname[100], line[100]; GET_INPUT_PARMS parms; int fno; @@ -1408,7 +1441,8 @@ static int mricRetrainRBF(MRIC *mric, FILE *fp, int nfiles, int round) { Description Fill the elements of a GET_INPUT_PARMS structure. ------------------------------------------------------*/ -static int mricFillInputParms(MRIC *mric, FILE *fp, int round, GET_INPUT_PARMS *parms) { +static int mricFillInputParms(MRIC *mric, FILE *fp, int round, GET_INPUT_PARMS *parms) +{ char *cp, source_fname[100], line[100]; int fno; MRI *mri; @@ -1438,7 +1472,8 @@ static int mricFillInputParms(MRIC *mric, FILE *fp, int round, GET_INPUT_PARMS * generate a set of inputs for a specific point in space for a specific image. ------------------------------------------------------*/ -static int mricGetClassifierInput(VECTOR *v_inputs, int no, void *parm, int same_class, int *pclass) { +static int mricGetClassifierInput(VECTOR *v_inputs, int no, void *parm, int same_class, int *pclass) +{ char *cp, source_fname[100], line[100], wm_fname[100]; int ino, x, y, z, obs_no, width, height, depth, fno, round; GET_INPUT_PARMS *parms; @@ -1529,7 +1564,8 @@ static int mricGetClassifierInput(VECTOR *v_inputs, int no, void *parm, int same the training set (means and variances). Useful for clustering analysis. ------------------------------------------------------*/ -int MRICexamineTrainingSet(MRIC *mric, char *file_name, int round) { +int MRICexamineTrainingSet(MRIC *mric, char *file_name, int round) +{ char *cp, source_fname[100], line[100]; GET_INPUT_PARMS parms; int fno; @@ -1571,7 +1607,8 @@ int MRICexamineTrainingSet(MRIC *mric, char *file_name, int round) { ------------------------------------------------------*/ #define SCATTER_ROUND 0 -int MRICbuildScatterPlot(MRIC *mric, int class, MATRIX *m_scatter, char *training_file_name) { +int MRICbuildScatterPlot(MRIC *mric, int class, MATRIX *m_scatter, char *training_file_name) +{ int obs_no = 0, i, x, y, nbins; // int half_bins, bin_offset; VECTOR *v_obs; @@ -1643,7 +1680,8 @@ int MRICbuildScatterPlot(MRIC *mric, int class, MATRIX *m_scatter, char *trainin Find the next observation for a given class. Stolen from rbf.c, but both really need it so.... ------------------------------------------------------*/ -static int mricGetClassObservation(GET_INPUT_PARMS *parms, VECTOR *v_obs, int desired_class_obs_no, int class) { +static int mricGetClassObservation(GET_INPUT_PARMS *parms, VECTOR *v_obs, int desired_class_obs_no, int class) +{ int ret, classno, obs_no, class_obs_no; static int last_class = -1; static int last_class_obs = -1; @@ -1655,7 +1693,8 @@ static int mricGetClassObservation(GET_INPUT_PARMS *parms, VECTOR *v_obs, int de /* start at one past previous observation, not at start */ class_obs_no = last_class_obs; obs_no = last_obs + 1; - } else + } + else class_obs_no = obs_no = 0; do { @@ -1667,7 +1706,8 @@ static int mricGetClassObservation(GET_INPUT_PARMS *parms, VECTOR *v_obs, int de last_class = classno; last_obs = obs_no - 1; last_class_obs = desired_class_obs_no; - } else + } + else last_class = last_obs = last_class_obs = -1; return (ret); diff --git a/utils/mricurv.c b/utils/mricurv.c index 02fa11c2484..3457b2b6279 100644 --- a/utils/mricurv.c +++ b/utils/mricurv.c @@ -42,7 +42,8 @@ static float computeLocalCurvature(int *ref_tab, int connectivity); -float Nbhcurvature(Nbh *nbh, int connectivity) { +float Nbhcurvature(Nbh *nbh, int connectivity) +{ int a, b, c, ref; int reference_table[8]; float curv; @@ -66,7 +67,8 @@ float Nbhcurvature(Nbh *nbh, int connectivity) { return curv; } -float MRIcurvature(MRI *mri, int i, int j, int k, int label, int connectivity) { +float MRIcurvature(MRI *mri, int i, int j, int k, int label, int connectivity) +{ int a, b, c, ref; int reference_table[8]; float curv; @@ -90,7 +92,8 @@ float MRIcurvature(MRI *mri, int i, int j, int k, int label, int connectivity) { return curv; } -typedef struct VerTex { +typedef struct VerTex +{ float x, y, z; int f[20]; int fnum; @@ -98,7 +101,8 @@ typedef struct VerTex { int vnum; int marked; } VerTex; -typedef struct FaCe { +typedef struct FaCe +{ int v[3]; float nx, ny, nz, area; } FaCe; @@ -112,7 +116,8 @@ static float fz[12] = {0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1}; #define MAX_VERTICES 100 #define MAX_FACES 40 -static float computeLocalCurvature(int *ref_tab, int connectivity) { +static float computeLocalCurvature(int *ref_tab, int connectivity) +{ int number_of_vertices; VerTex vertex[MAX_VERTICES]; int number_of_faces, reference, refdst; @@ -840,7 +845,8 @@ static float computeLocalCurvature(int *ref_tab, int connectivity) { maxcurv = 0; for (n = 0; n < kvt_nbr; n++) maxcurv += curvature[n]; maxcurv /= (float)kvt_nbr; - } else { + } + else { maxcurv = 0; m = 0; for (n = 0; n < kvt_nbr; n++) @@ -852,7 +858,8 @@ static float computeLocalCurvature(int *ref_tab, int connectivity) { return curvature[m]; } -static void computeCurvature(VerTex *vertex, int nvt, FaCe *face, int nfc, int *ref_tab, int nb, float *curv) { +static void computeCurvature(VerTex *vertex, int nvt, FaCe *face, int nfc, int *ref_tab, int nb, float *curv) +{ int n, m, reference; VECTOR *v_n, *v_e1, *v_e2, *v; float nx, ny, nz, area, dx, dy, dz, y, r2, u1, u2, YR2, R4; @@ -914,7 +921,8 @@ static void computeCurvature(VerTex *vertex, int nvt, FaCe *face, int nfc, int * VectorFree(&v_e2); } -static void computeFaceProperties(VerTex *vertex, int nvt, FaCe *face, int nfc) { +static void computeFaceProperties(VerTex *vertex, int nvt, FaCe *face, int nfc) +{ int n; float nx, ny, nz, area, dx1, dx2, dy1, dy2, dz1, dz2; diff --git a/utils/mrifilter.c b/utils/mrifilter.c index eddb84071ee..227e4ce1c17 100644 --- a/utils/mrifilter.c +++ b/utils/mrifilter.c @@ -84,7 +84,8 @@ static int compare_sort_array(const void *pc1, const void *pc2); ------------------------------------------------------*/ #define NORM 1.0f -MRI *MRIdirectionMapUchar(MRI *mri_grad, MRI *mri_dst, int wsize) { +MRI *MRIdirectionMapUchar(MRI *mri_grad, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0; float dir, dot, *xpix, *ypix, *zpix, dx, dy, dz, ox, oy, oz, norm; BUFTYPE *dir_pix; @@ -129,7 +130,8 @@ MRI *MRIdirectionMapUchar(MRI *mri_grad, MRI *mri_dst, int wsize) { return (mri_dst); } -MRI *MRIdirectionMap(MRI *mri_grad, MRI *mri_dst, int wsize) { +MRI *MRIdirectionMap(MRI *mri_grad, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0; float dir, dot, *xpix, *ypix, *zpix, dx, dy, dz, ox, oy, oz, *dir_pix, norm; @@ -181,7 +183,8 @@ MRI *MRIdirectionMap(MRI *mri_grad, MRI *mri_dst, int wsize) { Description ------------------------------------------------------*/ #define SCALE_FACTOR 10.0f -MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction, MRI *mri_dir) { +MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction, MRI *mri_dir) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0; float dir, dot, *xpix, *ypix, *zpix, dx, dy, dz, ox, oy, oz, len, *dir_xpix, *dir_ypix, *dir_zpix; BUFTYPE *pdir; @@ -200,7 +203,8 @@ MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction, MRI *mri_d for (y = whalf; y < height - whalf; y++) { if (mri_dir) { pdir = &MRIvox(mri_dir, whalf, y, z); - } else { + } + else { pdir = NULL; } @@ -264,7 +268,8 @@ MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction, MRI *mri_d #endif if (ISSMALL(dir)) { ox = oy = oz = 0.0f; - } else if (dir > 0.0f) { + } + else if (dir > 0.0f) { ox = -ox; oy = -oy; oz = -oz; @@ -274,7 +279,8 @@ MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction, MRI *mri_d *dir_xpix++ = 0.0f; *dir_ypix++ = 0.0f; *dir_zpix++ = 0.0f; - } else { + } + else { *dir_xpix++ = ox; *dir_ypix++ = oy; *dir_zpix++ = oz; @@ -283,9 +289,11 @@ MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction, MRI *mri_d if (pdir) { if (ISSMALL(dir)) { *pdir++ = OFFSET_ZERO; - } else if (dir < 0.0f) { + } + else if (dir < 0.0f) { *pdir++ = OFFSET_GRADIENT_DIRECTION; - } else { + } + else { *pdir++ = OFFSET_NEGATIVE_GRADIENT_DIRECTION; } } @@ -302,7 +310,8 @@ MRI *MRIoffsetDirection(MRI *mri_grad, int wsize, MRI *mri_direction, MRI *mri_d Description ------------------------------------------------------*/ -MRI *MRIoffsetMagnitude(MRI *mri_src, MRI *mri_dst, int maxsteps) { +MRI *MRIoffsetMagnitude(MRI *mri_src, MRI *mri_dst, int maxsteps) +{ int width, height, depth, x, y, z, x1, y1, z1, steps; float odx, ody, odz, dx, dy, dz, *xpix, *ypix, *zpix, len, dot = 0.0f, adx, ady, adz; signed char *dst_xpix, *dst_ypix, *dst_zpix; @@ -337,10 +346,12 @@ MRI *MRIoffsetMagnitude(MRI *mri_src, MRI *mri_dst, int maxsteps) { if ((adx > ady) && (adx > adz)) /* scale using x component */ { len = adx; - } else if (ady > adz) /* scale using y component */ + } + else if (ady > adz) /* scale using y component */ { len = ady; - } else /* scale using z component */ + } + else /* scale using z component */ { len = adz; } @@ -368,7 +379,8 @@ MRI *MRIoffsetMagnitude(MRI *mri_src, MRI *mri_dst, int maxsteps) { if (!FZERO(dot)) { steps--; } - } else { + } + else { steps = 0; } x1 = x + nint((float)steps * odx); @@ -391,7 +403,8 @@ MRI *MRIoffsetMagnitude(MRI *mri_src, MRI *mri_dst, int maxsteps) { Description ------------------------------------------------------*/ -MRI *MRIapplyOffset(MRI *mri_src, MRI *mri_dst, MRI *mri_offset) { +MRI *MRIapplyOffset(MRI *mri_src, MRI *mri_dst, MRI *mri_offset) +{ int width, height, depth, x, y, z, dx, dy, dz; signed char *pdx, *pdy, *pdz; char *pdst; @@ -452,7 +465,8 @@ MRI *MRIapplyOffset(MRI *mri_src, MRI *mri_dst, MRI *mri_offset) { Description ------------------------------------------------------*/ -MRI *MRIdiffuse(MRI *mri_src, MRI *mri_dst, double k, int niter, int which, double slope) { +MRI *MRIdiffuse(MRI *mri_src, MRI *mri_dst, double k, int niter, int which, double slope) +{ switch (which) { case FILTER_DIFFUSE_GRAD: mri_dst = MRIdiffusePerona(mri_src, mri_dst, k, niter, slope); @@ -470,7 +484,8 @@ MRI *MRIdiffuse(MRI *mri_src, MRI *mri_dst, double k, int niter, int which, doub Description ------------------------------------------------------*/ -MRI *MRIdiffuseCurvature(MRI *mri_src, MRI *mri_dst, double A, int niter, double slope) { +MRI *MRIdiffuseCurvature(MRI *mri_src, MRI *mri_dst, double A, int niter, double slope) +{ if (!mri_dst) { mri_dst = MRIclone(mri_src, NULL); } @@ -489,7 +504,8 @@ MRI *MRIdiffuseCurvature(MRI *mri_src, MRI *mri_dst, double A, int niter, double #define NUM_NEIGH 6 #define KERNEL_MUL (1.0f / ((float)NUM_NEIGH)) -MRI *MRIdiffusePerona(MRI *mri_src, MRI *mri_dst, double k, int niter, double slope) { +MRI *MRIdiffusePerona(MRI *mri_src, MRI *mri_dst, double k, int niter, double slope) +{ int x, y, z, i, width, height, depth, *xE, *yN, *xW, *yS, *zD, *zU, ys, yn, xe, xw, zu, zd, ci; float c[NUM_NEIGH + 1], fvals[NUM_NEIGH + 1], dst_val; MRI *mri_tmp = NULL, *mri_mag = NULL, *mri_grad = NULL; @@ -916,7 +932,8 @@ MRIzSobelRegion(MRI *mri_src, MRI *mri_z, int frame, MRI_REGION *region) } #endif -MRI *MRIdivergence(MRI *mri_src, MRI *mri_divergence) { +MRI *MRIdivergence(MRI *mri_src, MRI *mri_divergence) +{ MRI *mri_sobel; int x, y, z; double dU_dx, dU_dy, dU_dz; @@ -939,7 +956,8 @@ MRI *MRIdivergence(MRI *mri_src, MRI *mri_divergence) { } // compute the laplacian of the input volume (6-connected) -MRI *MRIlaplacian(MRI *mri_src, MRI *mri_laplacian) { +MRI *MRIlaplacian(MRI *mri_src, MRI *mri_laplacian) +{ int x, y, z, f; float lap; @@ -975,7 +993,8 @@ MRI *MRIlaplacian(MRI *mri_src, MRI *mri_laplacian) { Compute two vectors orthogonal to each other and to a third ------------------------------------------------------*/ int compute_tangent_vectors( - float nx, float ny, float nz, float *pe1x, float *pe1y, float *pe1z, float *pe2x, float *pe2y, float *pe2z) { + float nx, float ny, float nz, float *pe1x, float *pe1y, float *pe1z, float *pe2x, float *pe2y, float *pe2z) +{ float vx, vy, vz, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, len; /* pick some other unit non-linearly dependent vector */ @@ -983,7 +1002,8 @@ int compute_tangent_vectors( vx = ny; vy = nx; vz = nz; - } else { + } + else { vx = ny; vy = nz; vz = nx; @@ -999,7 +1019,8 @@ int compute_tangent_vectors( fprintf(stderr, "zero tangent vector computed!!\n"); DiagBreak(); exit(0); - } else { + } + else { e1_x /= len; e1_y /= len; e1_z /= len; @@ -1043,7 +1064,8 @@ int compute_tangent_vectors( Description compute the 2nd derivative in the specified direction ------------------------------------------------------*/ -MRI *MRI2ndDirectionalDerivative(MRI *mri_src, MRI *mri_deriv, float nx, float ny, float nz) { +MRI *MRI2ndDirectionalDerivative(MRI *mri_src, MRI *mri_deriv, float nx, float ny, float nz) +{ int x, y, z, dn, d1, d2; float deriv, xf, yf, zf, e1x, e1y, e1z, e2x, e2y, e2z, wt = 1; double val; @@ -1096,7 +1118,8 @@ MRI *MRI2ndDirectionalDerivative(MRI *mri_src, MRI *mri_deriv, float nx, float n Description ------------------------------------------------------*/ -MRI *MRIsobelFrame(MRI *mri_src, MRI *mri_grad, MRI *mri_mag, int frame) { +MRI *MRIsobelFrame(MRI *mri_src, MRI *mri_grad, MRI *mri_mag, int frame) +{ MRI *mri_frame; mri_frame = MRIcopyFrame(mri_src, NULL, frame, 0); @@ -1111,7 +1134,8 @@ MRI *MRIsobelFrame(MRI *mri_src, MRI *mri_grad, MRI *mri_mag, int frame) { Description ------------------------------------------------------*/ -MRI *MRIsobel(MRI *mri_src, MRI *mri_grad, MRI *mri_mag) { +MRI *MRIsobel(MRI *mri_src, MRI *mri_grad, MRI *mri_mag) +{ int x, y, z, width, height, depth; float *px, *py, *pz, xval, yval, zval, *pmag; @@ -1145,7 +1169,8 @@ MRI *MRIsobel(MRI *mri_src, MRI *mri_grad, MRI *mri_mag) { } } } - } else { + } + else { for (z = 0; z < depth; z++) { float mag; @@ -1176,7 +1201,8 @@ MRI *MRIsobel(MRI *mri_src, MRI *mri_grad, MRI *mri_mag) { Description ------------------------------------------------------*/ -MRI *MRIxSobel(MRI *mri_src, MRI *mri_x, int frame) { +MRI *MRIxSobel(MRI *mri_src, MRI *mri_x, int frame) +{ register BUFTYPE *tr_pix, *mr_pix, *br_pix; int x, y, z, width, height, depth; float *outPtr, left, middle, right; @@ -1225,7 +1251,8 @@ MRI *MRIxSobel(MRI *mri_src, MRI *mri_x, int frame) { return (mri_x); } -MRI *MRIxSobelForAllTypes(MRI *mri_src, MRI *mri_x, int frame) { +MRI *MRIxSobelForAllTypes(MRI *mri_src, MRI *mri_x, int frame) +{ int tr_pix[3], mr_pix[3], br_pix[3]; float tr_pix_val, mr_pix_val, br_pix_val; int x, y, z, width, height, depth; @@ -1304,7 +1331,8 @@ MRI *MRIxSobelForAllTypes(MRI *mri_src, MRI *mri_x, int frame) { Description ------------------------------------------------------*/ -MRI *MRIySobel(MRI *mri_src, MRI *mri_y, int frame) { +MRI *MRIySobel(MRI *mri_src, MRI *mri_y, int frame) +{ register BUFTYPE *tr_pix, *br_pix; int width, height, depth, x, y, z; float *outPtr, left, middle, right; @@ -1350,7 +1378,8 @@ MRI *MRIySobel(MRI *mri_src, MRI *mri_y, int frame) { return (mri_y); } -MRI *MRIySobelForAllTypes(MRI *mri_src, MRI *mri_y, int frame) { +MRI *MRIySobelForAllTypes(MRI *mri_src, MRI *mri_y, int frame) +{ int tr_pix[3], br_pix[3]; float tr_pix_val, br_pix_val; int x, y, z, width, height, depth; @@ -1422,7 +1451,8 @@ MRI *MRIySobelForAllTypes(MRI *mri_src, MRI *mri_y, int frame) { Description calculate a z derivitive in the x-z plane ------------------------------------------------------*/ -MRI *MRIzSobel(MRI *mri_src, MRI *mri_z, int frame) { +MRI *MRIzSobel(MRI *mri_src, MRI *mri_z, int frame) +{ register BUFTYPE *tr_pix, *br_pix; int width, height, depth, x, y, z; float *outPtr, left, middle, right; @@ -1469,7 +1499,8 @@ MRI *MRIzSobel(MRI *mri_src, MRI *mri_z, int frame) { return (mri_z); } -MRI *MRIzSobelForAllTypes(MRI *mri_src, MRI *mri_z, int frame) { +MRI *MRIzSobelForAllTypes(MRI *mri_src, MRI *mri_z, int frame) +{ int tr_pix[3], br_pix[3]; float tr_pix_val, br_pix_val; int x, y, z, width, height, depth; @@ -1538,7 +1569,8 @@ MRI *MRIzSobelForAllTypes(MRI *mri_src, MRI *mri_z, int frame) { Description compute a zscore for an image ------------------------------------------------------*/ -MRI *MRIzScore(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std) { +MRI *MRIzScore(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std) +{ MRI_REGION region; region.x = region.y = region.z = 0; @@ -1561,7 +1593,8 @@ MRI *MRIzScore(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std) { while mri_src is presumed to be the original (full size) image. ------------------------------------------------------*/ -MRI *MRIzScoreRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std, MRI_REGION *region) { +MRI *MRIzScoreRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std, MRI_REGION *region) +{ int width, height, depth, x, y, z, x0, y0, z0; BUFTYPE *psrc; float *pmean, *pstd, std, *pdst; @@ -1619,7 +1652,8 @@ MRI *MRIzScoreRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std, MR *pdst++ = 0.0f; psrc++; pmean++; - } else { + } + else { *pdst++ = ((float)*psrc++ - *pmean++) / std; } } @@ -1636,7 +1670,8 @@ MRI *MRIzScoreRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_std, MR Description perform a mean filter on the input MRI ------------------------------------------------------*/ -MRI *MRImeanRegion(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *region) { +MRI *MRImeanRegion(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *region) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, val, xk, yk, zk, xi, yi, zi; float *pdst, wcubed; @@ -1715,7 +1750,8 @@ MRI *MRImeanRegion(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *region) { been computed with the same region, and is therefore in the same coordinate system as the destination image. ------------------------------------------------------*/ -MRI *MRIstdRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize, MRI_REGION *region) { +MRI *MRIstdRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize, MRI_REGION *region) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, xk, yk, zk, xi, yi, zi; float *pdst, wcubed, mean, *pmean, variance, f; @@ -1791,7 +1827,8 @@ MRI *MRIstdRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize, MRI_REGI } if (FZERO(wcubed)) { *pdst = 0.0; - } else { + } + else { *pdst++ = sqrt(variance / wcubed); } } @@ -1808,7 +1845,8 @@ MRI *MRIstdRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize, MRI_REGI Description perform a mean filter on the input MRI ------------------------------------------------------*/ -MRI *MRImeanByte(MRI *mri_src, MRI *mri_dst, int wsize) { +MRI *MRImeanByte(MRI *mri_src, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, val; BUFTYPE *psrc, *pdst; float wcubed; @@ -1877,7 +1915,8 @@ MRI *MRImeanByte(MRI *mri_src, MRI *mri_dst, int wsize) { return (mri_dst); } -MRI *MRImeanInMask(MRI *mri_src, MRI *mri_dst, MRI *mri_mask, int wsize) { +MRI *MRImeanInMask(MRI *mri_src, MRI *mri_dst, MRI *mri_mask, int wsize) +{ int width, height, depth, whalf, num; // float wcubed; int x, y, z, x0, y0, z0; @@ -1931,7 +1970,8 @@ MRI *MRImeanInMask(MRI *mri_src, MRI *mri_dst, MRI *mri_mask, int wsize) { return (mri_dst); } -MRI *MRIstdInMask(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_mask, int wsize) { +MRI *MRIstdInMask(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_mask, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, xi, yi, zi; float wcubed, mean, variance, f; @@ -1985,7 +2025,8 @@ MRI *MRIstdInMask(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_mask, int } if (wcubed == 0) { MRIsetVoxVal(mri_dst, x, y, z, 0, 0); - } else { + } + else { MRIsetVoxVal(mri_dst, x, y, z, 0, sqrt(variance / wcubed)); } } @@ -2002,7 +2043,8 @@ MRI *MRIstdInMask(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, MRI *mri_mask, int Description perform a mean filter on the input MRI ------------------------------------------------------*/ -MRI *MRImean(MRI *mri_src, MRI *mri_dst, int wsize) { +MRI *MRImean(MRI *mri_src, MRI *mri_dst, int wsize) +{ int width, height, depth, whalf; // float wcubed; @@ -2062,7 +2104,8 @@ MRI *MRImean(MRI *mri_src, MRI *mri_dst, int wsize) { return (mri_dst); } -MRI *MRIinvert(MRI *mri_src, MRI *mri_dst) { +MRI *MRIinvert(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z; float val, max_val; @@ -2091,7 +2134,8 @@ MRI *MRIinvert(MRI *mri_src, MRI *mri_dst) { max_val = val; } MRIsetVoxVal(mri_dst, x, y, z, 0, val); - } else { + } + else { MRIsetVoxVal(mri_dst, x, y, z, 0, 0); // set inverse of 0 to 0 } } @@ -2129,7 +2173,8 @@ MRI *MRIinvert(MRI *mri_src, MRI *mri_dst) { Description perform a median filter on the input MRI ------------------------------------------------------*/ -MRI *MRImedian(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *box) { +MRI *MRImedian(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *box) +{ static float *sort_array = NULL; static int sort_size = 0; int width, height, depth, x, y, z, whalf, x0, y0, z0, frame, median_index, wcubed, yi, zi, xmin, xmax, ymin, ymax, @@ -2171,7 +2216,8 @@ MRI *MRImedian(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *box) { xmax = box->x + box->dx - 1; ymax = box->y + box->dy - 1; zmax = box->z + box->dz - 1; - } else { + } + else { xmin = ymin = zmin = 0; xmax = width - 1; ymax = height - 1; @@ -2216,7 +2262,8 @@ MRI *MRImedian(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *box) { xmax = box->x + box->dx - 1; ymax = box->y + box->dy - 1; zmax = box->z + box->dz - 1; - } else { + } + else { xmin = ymin = zmin = 0; xmax = width - 1; ymax = height - 1; @@ -2254,7 +2301,8 @@ MRI *MRImedian(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *box) { Description perform a generalized median filter on the input MRI ------------------------------------------------------*/ -MRI *MRIorder(MRI *mri_src, MRI *mri_dst, int wsize, float pct) { +MRI *MRIorder(MRI *mri_src, MRI *mri_dst, int wsize, float pct) +{ static float *sort_array = NULL; static int sort_size = 0; int width, height, depth, x, y, z, whalf, x0, y0, z0, order_index, wcubed, yi, zi; @@ -2303,7 +2351,8 @@ MRI *MRIorder(MRI *mri_src, MRI *mri_dst, int wsize, float pct) { } return (mri_dst); } -static int compare_sort_array(const void *pc1, const void *pc2) { +static int compare_sort_array(const void *pc1, const void *pc2) +{ register float c1, c2; c1 = *(float *)pc1; @@ -2312,7 +2361,8 @@ static int compare_sort_array(const void *pc1, const void *pc2) { /* return(c1 > c2 ? 1 : c1 == c2 ? 0 : -1) ;*/ if (c1 > c2) { return (1); - } else if (c1 < c2) { + } + else if (c1 < c2) { return (-1); } @@ -2327,7 +2377,8 @@ static int compare_sort_array(const void *pc1, const void *pc2) { Returns an image which is (8*sigma)+1 (Nitzberg and Shiota, 1993) ----------------------------------------------------------------------*/ -MRI *MRIgaussian1d(float sigma, int max_len) { +MRI *MRIgaussian1d(float sigma, int max_len) +{ MRI *mri; float norm, two_sigma, fx, k; int x, half, len; @@ -2360,7 +2411,8 @@ MRI *MRIgaussian1d(float sigma, int max_len) { fx = (float)(x - half); if (fabs(fx) <= two_sigma) { k = (float)exp((double)(-fx * fx / (two_sigma * sigma))); - } else if (two_sigma < fabs(fx) && fabs(fx) <= 4.0f * sigma) + } + else if (two_sigma < fabs(fx) && fabs(fx) <= 4.0f * sigma) k = 1.0f / (16.0f * (float)(M_E * M_E)) * (float)pow(4.0f - fabs(fx) / (double)sigma, 4.0); else { k = 0; @@ -2386,7 +2438,8 @@ MRI *MRIgaussian1d(float sigma, int max_len) { calculate the standard deviation of the MRI in a wsize window around each point ------------------------------------------------------*/ -MRI *MRIstd(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) { +MRI *MRIstd(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, xi, yi, zi; float wcubed, mean, variance, f; @@ -2434,7 +2487,8 @@ MRI *MRIstd(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) { } if (wcubed == 0) { MRIsetVoxVal(mri_dst, x, y, z, 0, 0); - } else { + } + else { MRIsetVoxVal(mri_dst, x, y, z, 0, sqrt(variance / wcubed)); } } @@ -2451,7 +2505,8 @@ MRI *MRIstd(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) { calculate the standard deviation of the MRI in a wsize window around each point ------------------------------------------------------*/ -MRI *MRIstdNonzero(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) { +MRI *MRIstdNonzero(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, xi, yi, zi; float wcubed, mean, variance, f; @@ -2505,7 +2560,8 @@ MRI *MRIstdNonzero(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) { } if (wcubed == 0) { MRIsetVoxVal(mri_dst, x, y, z, 0, 0); - } else { + } + else { MRIsetVoxVal(mri_dst, x, y, z, 0, sqrt(variance / wcubed)); } } @@ -2517,7 +2573,8 @@ MRI *MRIstdNonzero(MRI *mri_src, MRI *mri_dst, MRI *mri_mean, int wsize) { /*----------------------------------------------------- MRIconvolveGaussian() - see also MRIgaussianSmooth(); ------------------------------------------------------*/ -MRI *MRIconvolveGaussian(MRI *mri_src, MRI *mri_dst, MRI *mri_gaussian) { +MRI *MRIconvolveGaussian(MRI *mri_src, MRI *mri_dst, MRI *mri_gaussian) +{ // int width, height, depth; int klen; #ifndef FS_CUDA @@ -2560,7 +2617,8 @@ MRI *MRIconvolveGaussian(MRI *mri_src, MRI *mri_dst, MRI *mri_gaussian) { #else if (mri_dst == mri_src) { mri_tmp = mri_dst = MRIclone(mri_src, NULL); - } else { + } + else { mri_tmp = NULL; } @@ -2605,7 +2663,8 @@ MRI *MRIconvolveGaussian(MRI *mri_src, MRI *mri_dst, MRI *mri_gaussian) { This function calls the non-isotropic gaussian smoother MRIgaussianSmoothNI(). See also MRIconvolveGaussian() and MRImaskedGaussianSmooth(). -------------------------------------------------------------------*/ -MRI *MRIgaussianSmooth(MRI *src, double std, int norm, MRI *targ) { +MRI *MRIgaussianSmooth(MRI *src, double std, int norm, MRI *targ) +{ if (!norm) { printf("ERROR: MRIgaussianSmooth: norm must be non-zero\n"); return (NULL); @@ -2626,7 +2685,8 @@ MRI *MRIgaussianSmooth(MRI *src, double std, int norm, MRI *targ) { the src and binmask. The targ should end up being the same as the mask. See also MRIgaussianSmooth(). ---------------------------------------------------------------------------*/ -MRI *MRImaskedGaussianSmooth(MRI *src, MRI *binmask, double std, MRI *targ) { +MRI *MRImaskedGaussianSmooth(MRI *src, MRI *binmask, double std, MRI *targ) +{ MRI *binmasksm, *srcmasked; int c, r, s, f; double m, v; @@ -2677,7 +2737,8 @@ MRI *MRImaskedGaussianSmooth(MRI *src, MRI *binmask, double std, MRI *targ) { MRIsetVoxVal(targ, c, r, s, f, 0.0); } continue; - } else { + } + else { // If inside the mask, divide target voxel by smoothed mask value m = MRIgetVoxVal(binmasksm, c, r, s, 0); for (f = 0; f < src->nframes; f++) { @@ -2702,7 +2763,8 @@ MRI *MRImaskedGaussianSmooth(MRI *src, MRI *binmask, double std, MRI *targ) { * @param src * @param dst */ -static void MRImodifySampledHeader(MRI *mri_src, MRI *mri_dst) { +static void MRImodifySampledHeader(MRI *mri_src, MRI *mri_dst) +{ double c_r, c_a, c_s; if (!mri_dst) { @@ -2741,7 +2803,8 @@ static void MRImodifySampledHeader(MRI *mri_src, MRI *mri_dst) { variances, reduced, then back to stds and appended to the mean image. ------------------------------------------------------*/ -MRI *MRIreduceMeanAndStdByte(MRI *mri_src, MRI *mri_dst) { +MRI *MRIreduceMeanAndStdByte(MRI *mri_src, MRI *mri_dst) +{ MRI *mri_var, *mri_var_reduced, *mri_means_reduced, *mri_std_reduced; int nframes; @@ -2795,7 +2858,8 @@ MRI *MRIreduceMeanAndStdByte(MRI *mri_src, MRI *mri_dst) { variances, reduced, then back to stds and appended to the mean image. ------------------------------------------------------*/ -MRI *MRIreduceMeanAndStd(MRI *mri_src, MRI *mri_dst) { +MRI *MRIreduceMeanAndStd(MRI *mri_src, MRI *mri_dst) +{ MRI *mri_var, *mri_var_reduced, *mri_means_reduced, *mri_std_reduced; int nframes; @@ -2847,7 +2911,8 @@ MRI *MRIreduceMeanAndStd(MRI *mri_src, MRI *mri_dst) { #define KERNEL_SIZE 5 #define K_A 0.4f static float kernel[KERNEL_SIZE] = {0.25f - K_A / 2.0f, .25f, K_A, 0.25f, 0.25f - K_A / 2.0f}; -MRI *MRIreduce(MRI *mri_src, MRI *mri_dst) { +MRI *MRIreduce(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth; MRI *mtmp1, *mtmp2 = NULL; MATRIX *m_vox2ras, *m_scale, *m_tmp; @@ -2867,7 +2932,8 @@ MRI *MRIreduce(MRI *mri_src, MRI *mri_dst) { mri_dst = MRIreduce1d(mtmp2, mri_dst, kernel, KERNEL_SIZE, MRI_DEPTH); // null then create MRI_FLOAT volume MRIfree(&mtmp1); - } else { + } + else { mri_dst = MRIreduce1d(mtmp1, mri_dst, kernel, KERNEL_SIZE, MRI_HEIGHT); } @@ -2897,7 +2963,8 @@ MRI *MRIreduce(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -MRI *MRIreduce2D(MRI *mri_src, MRI *mri_dst) { +MRI *MRIreduce2D(MRI *mri_src, MRI *mri_dst) +{ int width, height; // int depth; MRI *mtmp1; @@ -2926,7 +2993,8 @@ MRI *MRIreduce2D(MRI *mri_src, MRI *mri_dst) { Description Sae as above, but produce a byte image as output. ------------------------------------------------------*/ -MRI *MRIreduceByte(MRI *mri_src, MRI *mri_dst) { +MRI *MRIreduceByte(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth; MRI *mtmp1, *mtmp2; @@ -2958,7 +3026,8 @@ MRI *MRIreduceByte(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIconvolve1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) { +MRI *MRIconvolve1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) +{ int width, height, depth; #ifndef FS_CUDA int x = 0, y = 0, z = 0, halflen, *xi, *yi, *zi; @@ -2986,9 +3055,11 @@ MRI *MRIconvolve1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int #else if (mri_dst->type == MRI_UCHAR) { return (MRIconvolve1dByte(mri_src, mri_dst, k, len, axis, src_frame, dst_frame)); - } else if (mri_dst->type == MRI_SHORT) { + } + else if (mri_dst->type == MRI_SHORT) { return (MRIconvolve1dShort(mri_src, mri_dst, k, len, axis, src_frame, dst_frame)); - } else if (mri_dst->type == MRI_INT) { + } + else if (mri_dst->type == MRI_INT) { return (MRIconvolve1dInt(mri_src, mri_dst, k, len, axis, src_frame, dst_frame)); } @@ -3229,7 +3300,8 @@ MRI *MRIconvolve1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int Description ------------------------------------------------------*/ -MRI *MRIconvolve1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) { +MRI *MRIconvolve1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) +{ int x, y, z, width, height, halflen, depth, *xi, *yi, *zi; register int i; BUFTYPE *inBase; @@ -3371,7 +3443,8 @@ MRI *MRIconvolve1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, Description ------------------------------------------------------*/ -MRI *MRIconvolve1dShort(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) { +MRI *MRIconvolve1dShort(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) +{ int x, y, z, width, height, halflen, depth, *xi, *yi, *zi; register int i; short *inBase; @@ -3456,7 +3529,8 @@ MRI *MRIconvolve1dShort(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, Description ------------------------------------------------------*/ -MRI *MRIconvolve1dInt(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) { +MRI *MRIconvolve1dInt(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) +{ int x, y, z, width, height, halflen, depth, *xi, *yi, *zi; register int i; int *inBase; @@ -3541,7 +3615,8 @@ MRI *MRIconvolve1dInt(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, i Description ------------------------------------------------------*/ -MRI *MRIconvolve1dFloat(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) { +MRI *MRIconvolve1dFloat(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, int src_frame, int dst_frame) +{ int x, y, z, width, height, halflen, depth, *xi, *yi, *zi; register int i; float *inBase; @@ -3626,7 +3701,8 @@ MRI *MRIconvolve1dFloat(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis, Description ------------------------------------------------------*/ -MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { +MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) +{ int x, y, z, i, dheight, dwidth, ddepth, xi, yi, zi, halflen; int sheight, swidth, sdepth; float total, val; @@ -3674,7 +3750,8 @@ MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { xi = 2 * x + i - halflen; if (xi < 0) { xi = 0; - } else if (xi >= swidth) { + } + else if (xi >= swidth) { xi = swidth - 1; } @@ -3699,7 +3776,8 @@ MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { yi = 2 * y + i - halflen; if (yi < 0) { yi = 0; - } else if (yi >= sheight) { + } + else if (yi >= sheight) { yi = sheight - 1; } @@ -3725,7 +3803,8 @@ MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { zi = 2 * z + i - halflen; if (zi < 0) { zi = 0; - } else if (zi >= sdepth) { + } + else if (zi >= sdepth) { zi = sdepth - 1; } @@ -3752,7 +3831,8 @@ MRI *MRIreduce1d(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { Description ------------------------------------------------------*/ -MRI *MRIreduceSlice(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { +MRI *MRIreduceSlice(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) +{ int x, y, z, i, dheight, dwidth, ddepth, xi, yi, zi, halflen; int sheight, swidth, sdepth; float total, val; @@ -3796,7 +3876,8 @@ MRI *MRIreduceSlice(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { xi = 2 * x + i - halflen; if (xi < 0) { xi = 0; - } else if (xi >= swidth) { + } + else if (xi >= swidth) { xi = swidth - 1; } @@ -3821,7 +3902,8 @@ MRI *MRIreduceSlice(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { yi = 2 * y + i - halflen; if (yi < 0) { yi = 0; - } else if (yi >= sheight) { + } + else if (yi >= sheight) { yi = sheight - 1; } @@ -3848,7 +3930,8 @@ MRI *MRIreduceSlice(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { Description ------------------------------------------------------*/ -MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { +MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) +{ int x, y, z, i, dheight, dwidth, ddepth, xi, yi, zi, halflen; int sheight, swidth, sdepth; float total; @@ -3885,7 +3968,8 @@ MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { xi = 2 * x + i - halflen; if (xi < 0) { xi = 0; - } else if (xi >= swidth) { + } + else if (xi >= swidth) { xi = swidth - 1; } @@ -3909,7 +3993,8 @@ MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { yi = 2 * y + i - halflen; if (yi < 0) { yi = 0; - } else if (yi >= sheight) { + } + else if (yi >= sheight) { yi = sheight - 1; } @@ -3934,7 +4019,8 @@ MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { zi = 2 * z + i - halflen; if (zi < 0) { zi = 0; - } else if (zi >= sdepth) { + } + else if (zi >= sdepth) { zi = sdepth - 1; } @@ -3961,7 +4047,8 @@ MRI *MRIreduce1dByte(MRI *mri_src, MRI *mri_dst, float *k, int len, int axis) { Cross-correlate two MRIs, limitting the extent of the correlation to window_size ------------------------------------------------------*/ -MRI *MRIxcorrWindow(MRI *mri_ref, MRI *mri_in, MRI *mri_dst, int window_size) { +MRI *MRIxcorrWindow(MRI *mri_ref, MRI *mri_in, MRI *mri_dst, int window_size) +{ int width, height, depth, xoff, yoff, zoff, x0, y0, z0, kx, ky, kz, whalf, x, y, z, dst_width, dst_height, dst_depth, kxend; BUFTYPE *pref, *pin, ref, in; @@ -4055,7 +4142,8 @@ MRI *MRIxcorrWindow(MRI *mri_ref, MRI *mri_in, MRI *mri_dst, int window_size) { correlation to window_size and normalizing by the energy in the window. ------------------------------------------------------*/ -MRI *MRInxcorrWindow(MRI *mri_ref, MRI *mri_in, MRI *mri_dst, int window_size) { +MRI *MRInxcorrWindow(MRI *mri_ref, MRI *mri_in, MRI *mri_dst, int window_size) +{ int width, height, depth, xoff, yoff, zoff, x0, y0, z0, kx, ky, kz, kxend, whalf, x, y, z, dst_width, dst_height, dst_depth; BUFTYPE *pref, *pin, ref, in; @@ -4136,7 +4224,8 @@ MRI *MRInxcorrWindow(MRI *mri_ref, MRI *mri_in, MRI *mri_dst, int window_size) { norm = 1.0f; /* disable normalization (for now) */ if (!FZERO(norm)) { dst /= norm; - } else { + } + else { dst = 0.0f; } @@ -4155,7 +4244,8 @@ MRI *MRInxcorrWindow(MRI *mri_ref, MRI *mri_in, MRI *mri_dst, int window_size) { Description Cross-correlate to MRIs ------------------------------------------------------*/ -long MRIcorrelate(MRI *mri_ref, MRI *mri_in, int xoff, int yoff, int zoff) { +long MRIcorrelate(MRI *mri_ref, MRI *mri_in, int xoff, int yoff, int zoff) +{ int row, col, slice, width, height, depth; long total; BUFTYPE *pref, *pin, ref, in; @@ -4268,7 +4358,8 @@ MRIremoveHoles(MRI *mri_src, MRI*mri_dst, int wsize, float pct) images are just too big). ------------------------------------------------------*/ #define VARIANCE_SCALING 15 -MRI *MRIstdsToVariances(MRI *mri_std, MRI *mri_var, int source_frame) { +MRI *MRIstdsToVariances(MRI *mri_std, MRI *mri_var, int source_frame) +{ int x, y, z, width, height, depth; float std, var; BUFTYPE *pstd, *pvar; @@ -4305,7 +4396,8 @@ MRI *MRIstdsToVariances(MRI *mri_std, MRI *mri_var, int source_frame) { Description Inverse of above procedure. ------------------------------------------------------*/ -MRI *MRIvariancesToStds(MRI *mri_var, MRI *mri_std, int dst_frame) { +MRI *MRIvariancesToStds(MRI *mri_var, MRI *mri_std, int dst_frame) +{ int x, y, z, width, height, depth; float std, var; BUFTYPE *pstd, *pvar; @@ -4347,7 +4439,8 @@ MRI *MRIvariancesToStds(MRI *mri_var, MRI *mri_std, int dst_frame) { variances, convolved, then back to stds and appended to the mean image. ------------------------------------------------------*/ -MRI *MRIconvolveGaussianMeanAndStdByte(MRI *mri_src, MRI *mri_dst, MRI *mri_gaussian) { +MRI *MRIconvolveGaussianMeanAndStdByte(MRI *mri_src, MRI *mri_dst, MRI *mri_gaussian) +{ MRI *mri_var, *mri_var_blurred, *mri_means_blurred, *mri_std_blurred; int nframes; @@ -4393,7 +4486,8 @@ MRI *MRIconvolveGaussianMeanAndStdByte(MRI *mri_src, MRI *mri_dst, MRI *mri_gaus Description ------------------------------------------------------*/ -MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) { +MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, width, height, depth, xk, yk, zk, xi, yi, zi, slabel, dlabel, nw, ng; BUFTYPE *psrc, *pdst; @@ -4438,8 +4532,9 @@ MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) { break; } } - } else if (slabel == MRI_NOT_WHITE) /*see if it is next - to an MRI_WHITE */ + } + else if (slabel == MRI_NOT_WHITE) /*see if it is next + to an MRI_WHITE */ { for (zk = -1; zk <= 1; zk++) { zi = mri_src->zi[z + zk]; @@ -4465,14 +4560,16 @@ MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) { if (dlabel == MRI_WHITE) { nw++; - } else if (dlabel == MRI_NOT_WHITE) { + } + else if (dlabel == MRI_NOT_WHITE) { ng++; } *pdst++ = dlabel; } } } - } else // not UCHAR + } + else // not UCHAR { for (nw = ng = z = 0; z < depth; z++) { for (y = 0; y < height; y++) { @@ -4505,8 +4602,9 @@ MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) { break; } } - } else if (slabel == MRI_NOT_WHITE) /*see if it is next - to an MRI_WHITE */ + } + else if (slabel == MRI_NOT_WHITE) /*see if it is next + to an MRI_WHITE */ { for (zk = -1; zk <= 1; zk++) { zi = mri_src->zi[z + zk]; @@ -4532,7 +4630,8 @@ MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) { if (dlabel == MRI_WHITE) { nw++; - } else if (dlabel == MRI_NOT_WHITE) { + } + else if (dlabel == MRI_NOT_WHITE) { ng++; } MRIsetVoxVal(mri_dst, x, y, z, 0, dlabel); @@ -4548,7 +4647,8 @@ MRI *MRImarkBorderVoxels(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -int MRIborderClassifyVoxel(MRI *mri_src, MRI *mri_labeled, int wsize, int x, int y, int z, float *ppw, float *ppg) { +int MRIborderClassifyVoxel(MRI *mri_src, MRI *mri_labeled, int wsize, int x, int y, int z, float *ppw, float *ppg) +{ int xk, yk, zk, xi, yi, zi, nw, ng, whalf, val; // int width, height, depth; float wvar, wmean, gvar, gmean, wsq, gsq, pg, pw, dist, ptotal; @@ -4573,7 +4673,8 @@ int MRIborderClassifyVoxel(MRI *mri_src, MRI *mri_labeled, int wsize, int x, int ng++; gsq += val * val; gmean += val; - } else if (MRIgetVoxVal(mri_labeled, xi, yi, zi, 0) == MRI_WHITE) { + } + else if (MRIgetVoxVal(mri_labeled, xi, yi, zi, 0) == MRI_WHITE) { nw++; wsq += val * val; wmean += val; @@ -4584,14 +4685,16 @@ int MRIborderClassifyVoxel(MRI *mri_src, MRI *mri_labeled, int wsize, int x, int if (nw) { wmean /= (float)nw; wvar = wsq / (float)nw - wmean * wmean; - } else { + } + else { wmean = wvar = 1.0; } if (ng) { gmean /= (float)ng; gvar = gsq / (float)ng - gmean * gmean; - } else { + } + else { gmean = gvar = 1.0; } @@ -4627,7 +4730,8 @@ int MRIborderClassifyVoxel(MRI *mri_src, MRI *mri_labeled, int wsize, int x, int Description ------------------------------------------------------*/ -int MRIreclassifyBorder(MRI *mri_src, MRI *mri_labeled, MRI *mri_border, MRI *mri_dst, int wsize) { +int MRIreclassifyBorder(MRI *mri_src, MRI *mri_labeled, MRI *mri_border, MRI *mri_dst, int wsize) +{ int x, y, z, width, height, depth, nw, ng, nchanged, ntested; float label, new_label, border; @@ -4679,7 +4783,8 @@ int MRIreclassifyBorder(MRI *mri_src, MRI *mri_labeled, MRI *mri_border, MRI *mr Description ------------------------------------------------------*/ -int MRIreclassify(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, float wm_low, float gray_hi, int wsize) { +int MRIreclassify(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, float wm_low, float gray_hi, int wsize) +{ int x, y, z, width, height, depth, nw, ng, nchanged, ntested, w, nmulti; int label, new_label, src; float pw, pg, gtotal, wtotal; @@ -4715,7 +4820,8 @@ int MRIreclassify(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, float wm_low, fl } if (gtotal > wtotal) { new_label = MRI_NOT_WHITE; - } else { + } + else { new_label = MRI_WHITE; } } @@ -4754,7 +4860,8 @@ int MRIreclassify(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, float wm_low, fl Description ------------------------------------------------------*/ -int MRIclassifyAmbiguous(MRI *mri_src, MRI *mri_labeled, MRI *mri_border, MRI *mri_dst, int wsize) { +int MRIclassifyAmbiguous(MRI *mri_src, MRI *mri_labeled, MRI *mri_border, MRI *mri_dst, int wsize) +{ int x, y, z, width, height, depth, nw, ng, nchanged, ntested; BUFTYPE *plabeled, *pdst, label, new_label; // BUFTYPE *psrc; @@ -4809,7 +4916,8 @@ int MRIclassifyAmbiguous(MRI *mri_src, MRI *mri_labeled, MRI *mri_border, MRI *m Description ------------------------------------------------------*/ -MRI *MRIremoveBrightStuff(MRI *mri_src, MRI *mri_dst, int threshold) { +MRI *MRIremoveBrightStuff(MRI *mri_src, MRI *mri_dst, int threshold) +{ int x, y, z, width, height, depth; BUFTYPE *psrc, *pdst, val; @@ -4843,7 +4951,8 @@ MRI *MRIremoveBrightStuff(MRI *mri_src, MRI *mri_dst, int threshold) { Description ------------------------------------------------------*/ -MRI *MRIwindow(MRI *mri_src, MRI *mri_dst, int which, float x0, float y0, float z0, float parm) { +MRI *MRIwindow(MRI *mri_src, MRI *mri_dst, int which, float x0, float y0, float z0, float parm) +{ int x, y, z, height, depth, width, val; double w, dist, dx, dy, dz; @@ -4910,7 +5019,8 @@ int MRIcomputeClassStatistics(MRI *mri_T1, float *pmean_wm, float *psigma_wm, float *pmean_gm, - float *psigma_gm) { + float *psigma_gm) +{ MRI *mri_border; int x, y, z, width, height, depth, label, border_label, ngray, nwhite, nbins, bin, peak; double white_min, white_max, white_mean, white_std, gray_min, gray_max, gray_mean, gray_std, val; @@ -4971,7 +5081,8 @@ int MRIcomputeClassStatistics(MRI *mri_T1, } h_white->counts[bin]++; } - } else if (border_label == MRI_NOT_WHITE) /* gray bordering white */ + } + else if (border_label == MRI_NOT_WHITE) /* gray bordering white */ { if ((val >= gray_low && val <= gray_hi) || gray_low < 0) { ngray++; @@ -5032,7 +5143,8 @@ int MRIcomputeClassStatistics(MRI *mri_T1, return (NO_ERROR); } -MRI *MRIthreshModeFilter(MRI *mri_src, MRI *mri_dst, int niter, float thresh) { +MRI *MRIthreshModeFilter(MRI *mri_src, MRI *mri_dst, int niter, float thresh) +{ int x, y, z, n, width, height, depth, histo[256], xk, yk, zk, xi, yi, zi, val, i, max_histo, max_i, changed, orig_label; @@ -5098,7 +5210,8 @@ MRI *MRIthreshModeFilter(MRI *mri_src, MRI *mri_dst, int niter, float thresh) { return (mri_dst); } -MRI *MRImodeFilterWithControlPoints(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) { +MRI *MRImodeFilterWithControlPoints(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) +{ int x, y, z, n, width, height, depth, histo[256], xk, yk, zk, xi, yi, zi, val, i, max_histo, max_i, npts; MRI *mri_tmp; @@ -5164,7 +5277,8 @@ MRI *MRImodeFilterWithControlPoints(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, i return (mri_dst); } -MRI *MRImodeFilter(MRI *mri_src, MRI *mri_dst, int niter) { +MRI *MRImodeFilter(MRI *mri_src, MRI *mri_dst, int niter) +{ int x, y, z, n, width, height, depth, *histo, xk, yk, zk, xi, yi, zi, val, i, max_histo, max_i, max_val, start_val; MRI *mri_tmp; float fmin, fmax; @@ -5227,7 +5341,8 @@ MRI *MRImodeFilter(MRI *mri_src, MRI *mri_dst, int niter) { return (mri_dst); } -MRI *MRIgradientDir2ndDerivative(MRI *mri_src, MRI *mri_dst, int wsize) { +MRI *MRIgradientDir2ndDerivative(MRI *mri_src, MRI *mri_dst, int wsize) +{ float dI_d2; int x, y, z, width, height, depth; @@ -5246,7 +5361,8 @@ MRI *MRIgradientDir2ndDerivative(MRI *mri_src, MRI *mri_dst, int wsize) { } } } - } else { + } + else { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { @@ -5260,7 +5376,8 @@ MRI *MRIgradientDir2ndDerivative(MRI *mri_src, MRI *mri_dst, int wsize) { return (mri_dst); } -MRI *MRIsmoothLabel(MRI *mri_intensity, MRI *mri_label, MRI *mri_smooth, int niter, int label, float min_change) { +MRI *MRIsmoothLabel(MRI *mri_intensity, MRI *mri_label, MRI *mri_smooth, int niter, int label, float min_change) +{ int x, y, z, n, xi, yi, zi, xk, yk, zk, i, l; float val, val_mean, change, max_change; MRI *mri_tmp; @@ -5314,7 +5431,8 @@ MRI *MRIsmoothLabel(MRI *mri_intensity, MRI *mri_label, MRI *mri_smooth, int nit } MRI *MRIsmoothLabel6Connected( - MRI *mri_intensity, MRI *mri_label, MRI *mri_smooth, int niter, int label, int fixed_label, float min_change) { + MRI *mri_intensity, MRI *mri_label, MRI *mri_smooth, int niter, int label, int fixed_label, float min_change) +{ int x, n, i, nthreads; float max_change[_MAX_FS_THREADS], max_change_overall; MRI *mri_tmp; @@ -5323,7 +5441,9 @@ MRI *MRIsmoothLabel6Connected( mri_smooth = MRIcopy(mri_intensity, mri_smooth); #ifdef HAVE_OPENMP #pragma omp parallel - { nthreads = omp_get_num_threads(); } + { + nthreads = omp_get_num_threads(); + } #else nthreads = 1; #endif @@ -5388,7 +5508,8 @@ MRI *MRIsmoothLabel6Connected( return (mri_smooth); } -MRI *MRIxDerivative(MRI *mri_src, MRI *mri_dx) { +MRI *MRIxDerivative(MRI *mri_src, MRI *mri_dx) +{ int x, y, z; double dx; @@ -5413,7 +5534,8 @@ MRI *MRIxDerivative(MRI *mri_src, MRI *mri_dx) { return (mri_dx); } -MRI *MRIyDerivative(MRI *mri_src, MRI *mri_dy) { +MRI *MRIyDerivative(MRI *mri_src, MRI *mri_dy) +{ int x, y, z; double dy; @@ -5435,7 +5557,8 @@ MRI *MRIyDerivative(MRI *mri_src, MRI *mri_dy) { return (mri_dy); } -MRI *MRIzDerivative(MRI *mri_src, MRI *mri_dz) { +MRI *MRIzDerivative(MRI *mri_src, MRI *mri_dz) +{ int x, y, z; double dz; @@ -5465,7 +5588,8 @@ MRI *MRIzDerivative(MRI *mri_src, MRI *mri_dz) { \brief creates an MRI image with a 3D gaussian distribution */ -MRI *MRI_Gaussian(int len, float std, int norm, int xsize, int ysize, int zsize) { +MRI *MRI_Gaussian(int len, float std, int norm, int xsize, int ysize, int zsize) +{ int x, y, z; float val; float var = std * std; @@ -5491,7 +5615,8 @@ MRI *MRI_Gaussian(int len, float std, int norm, int xsize, int ysize, int zsize) first is the modulus (whose quarters has been shifted), the second is the argument */ -MRI *MRI_fft(MRI *mri_src, MRI *dst) { +MRI *MRI_fft(MRI *mri_src, MRI *dst) +{ int dimension, w, h, d; int x, y, z, k, j, f; float ***src, ***dst_r, ***dst_i; @@ -5505,7 +5630,8 @@ MRI *MRI_fft(MRI *mri_src, MRI *dst) { if (!FFTisPowerOf2(mri_src->depth) || !FFTisPowerOf2(mri_src->height) || !FFTisPowerOf2(mri_src->width)) { if (d >= w) { dimension = (d >= h ? d : h); - } else { + } + else { dimension = (h >= w ? h : w); } dimension = FFTpow2(FFTlog2(dimension)); @@ -5523,11 +5649,13 @@ MRI *MRI_fft(MRI *mri_src, MRI *dst) { for (x = 0; x < dimension; x++) { if (z >= mri_src->depth || y >= mri_src->height || x >= mri_src->width) { MRIsetVoxVal(new_mri, x, y, z, f, 0); - } else + } + else MRIsetVoxVal(new_mri, x, y, z, f, MRIgetVoxVal(mri_src, x, y, z, f)); } mri_src = new_mri; - } else { + } + else { dimension = mri_src->depth; } @@ -5538,7 +5666,8 @@ MRI *MRI_fft(MRI *mri_src, MRI *dst) { return (NULL); } MRIcopy(mri_src, dst); - } else { + } + else { if (mri_src->width != dst->width) { printf("ERROR: MRI_fft: width dimension mismatch\n"); return (NULL); @@ -5641,7 +5770,8 @@ MRI *MRI_fft(MRI *mri_src, MRI *dst) { from the size of the image in the frequency domain. */ -MRI *MRI_ifft(MRI *src, MRI *dst, int w, int h, int d) { +MRI *MRI_ifft(MRI *src, MRI *dst, int w, int h, int d) +{ int dimension; int x, y, z, k, j, f; float ***dst_r, ***dst_i; @@ -5659,7 +5789,8 @@ MRI *MRI_ifft(MRI *src, MRI *dst, int w, int h, int d) { return (NULL); } MRIcopyHeader(src, dst); - } else { + } + else { if (w != dst->width) { printf("ERROR: MRI_ifft: width dimension mismatch\n"); return (NULL); @@ -5758,7 +5889,8 @@ MRI *MRI_ifft(MRI *src, MRI *dst, int w, int h, int d) { the shifted modulus by a gaussian MRI, and then computes the inverse FFT. The result is in dst. */ -MRI *MRI_fft_gaussian(MRI *src, MRI *dst, float std, int norm) { +MRI *MRI_fft_gaussian(MRI *src, MRI *dst, float std, int norm) +{ MRI *src_fft = NULL, *fft_sm = NULL, *g; MRI *g_fft, *temp; int dimension, f; @@ -5770,7 +5902,8 @@ MRI *MRI_fft_gaussian(MRI *src, MRI *dst, float std, int norm) { return (NULL); } MRIcopy(src, dst); - } else { + } + else { if (src->width != dst->width) { printf("ERROR: MRI_fft_gaussian: width dimension mismatch\n"); return (NULL); @@ -5824,7 +5957,8 @@ MRI *MRI_fft_gaussian(MRI *src, MRI *dst, float std, int norm) { inverse FFT. The result is in dst. */ -MRI *MRI_fft_lowpass(MRI *src, MRI *dst, int percent) { +MRI *MRI_fft_lowpass(MRI *src, MRI *dst, int percent) +{ MRI *src_fft; int x, y, z, f; @@ -5835,7 +5969,8 @@ MRI *MRI_fft_lowpass(MRI *src, MRI *dst, int percent) { return (NULL); } MRIcopy(src, dst); - } else { + } + else { if (src->width != dst->width) { printf("ERROR: MRI_fft_lowpass: width dimension mismatch\n"); return (NULL); @@ -5886,7 +6021,8 @@ MRI *MRI_fft_lowpass(MRI *src, MRI *dst, int percent) { "percent" percent of the lowest freqs, and then computes the inverse FFT. The result is in dst. */ -MRI *MRI_fft_highpass(MRI *src, MRI *dst, int percent) { +MRI *MRI_fft_highpass(MRI *src, MRI *dst, int percent) +{ MRI *src_fft; int x, y, z, f; @@ -5897,7 +6033,8 @@ MRI *MRI_fft_highpass(MRI *src, MRI *dst, int percent) { return (NULL); } MRIcopy(src, dst); - } else { + } + else { if (src->width != dst->width) { printf("ERROR: MRI_fft_highpass: width dimension mismatch\n"); return (NULL); @@ -5942,7 +6079,8 @@ MRI *MRI_fft_highpass(MRI *src, MRI *dst, int percent) { in-place. Handles multiple frames. See also MRIconvolveGaussian() and MRImaskedGaussianSmooth(). -------------------------------------------------------------------*/ -MRI *MRIgaussianSmoothNI(MRI *src, double cstd, double rstd, double sstd, MRI *targ) { +MRI *MRIgaussianSmoothNI(MRI *src, double cstd, double rstd, double sstd, MRI *targ) +{ int c, r, s, cstop, rstop, sstop; MATRIX *G; MATRIX *vr = NULL, *vc = NULL, *vs = NULL; @@ -5955,7 +6093,8 @@ MRI *MRIgaussianSmoothNI(MRI *src, double cstd, double rstd, double sstd, MRI *t return (NULL); } MRIcopy(src, targ); - } else { + } + else { if (src->width != targ->width) { printf("ERROR: MRIgaussianSmoothNI: width dimension mismatch\n"); return (NULL); @@ -6148,7 +6287,8 @@ MRI *MRIgaussianSmoothNI(MRI *src, double cstd, double rstd, double sstd, MRI *t return (targ); } -MRI *MRIsegmentationSurfaceNormals(MRI *mri_seg, MRI *mri_normals, int label, MRI **pmri_ctrl) { +MRI *MRIsegmentationSurfaceNormals(MRI *mri_seg, MRI *mri_normals, int label, MRI **pmri_ctrl) +{ int x, y, z, border; float nx, ny, nz; MRI *mri_border; @@ -6184,7 +6324,8 @@ MRI *MRIsegmentationSurfaceNormals(MRI *mri_seg, MRI *mri_normals, int label, MR } int MRIcomputeBorderNormalAtVoxel( - MRI *mri_seg, int x0, int y0, int z0, float *pnx, float *pny, float *pnz, int target_label) { + MRI *mri_seg, int x0, int y0, int z0, float *pnx, float *pny, float *pnz, int target_label) +{ int olabel, x1, y1, z1, xk, yk, zk, label, num; float nx, ny, nz, mag; @@ -6214,7 +6355,8 @@ int MRIcomputeBorderNormalAtVoxel( nx /= num; ny /= num; nz /= num; - } else { + } + else { DiagBreak(); } @@ -6241,7 +6383,8 @@ int MRIcomputeBorderNormalAtVoxel( /* normalize the length of the sequence at each voxel to be unity. */ -MRI *MRInormalizeFrameVectorLength(MRI *mri_src, MRI *mri_dst) { +MRI *MRInormalizeFrameVectorLength(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, f; float val, mag; @@ -6271,7 +6414,8 @@ MRI *MRInormalizeFrameVectorLength(MRI *mri_src, MRI *mri_dst) { /* normalize the length of the sequence at each voxel to be unity. */ -MRI *MRIcomputeFrameVectorLength(MRI *mri_src, MRI *mri_dst) { +MRI *MRIcomputeFrameVectorLength(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, f; float val, mag; @@ -6294,7 +6438,8 @@ MRI *MRIcomputeFrameVectorLength(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -MRI *MRIcomputeFrameVectorL1Length(MRI *mri_src, MRI *mri_dst) { +MRI *MRIcomputeFrameVectorL1Length(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, f; float val, mag; @@ -6317,7 +6462,8 @@ MRI *MRIcomputeFrameVectorL1Length(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -MRI *MRInbrThresholdLabel(MRI *mri_src, MRI *mri_dst, int label, int out_label, int whalf, float thresh) { +MRI *MRInbrThresholdLabel(MRI *mri_src, MRI *mri_dst, int label, int out_label, int whalf, float thresh) +{ int x, y, z, count, total; if (mri_dst != mri_src) mri_dst = MRIcopy(mri_src, mri_dst); @@ -6351,7 +6497,8 @@ MRI *MRInbrThresholdLabel(MRI *mri_src, MRI *mri_dst, int label, int out_label, every DeltaD along that line and convolved with the Gaussian kernel. Cannot be done in-place. */ -MRI *MRImotionBlur2D(MRI *src, MB2D *mb, MRI *out) { +MRI *MRImotionBlur2D(MRI *src, MB2D *mb, MRI *out) +{ int c; struct timeb timer; @@ -6547,7 +6694,8 @@ MRI *MRImotionBlur2D(MRI *src, MB2D *mb, MRI *out) { return (out); } -int MB2Dfree(MB2D **pmb) { +int MB2Dfree(MB2D **pmb) +{ MB2D *mb = *pmb; if (mb->d0) MRIfree(&mb->d0); @@ -6560,7 +6708,8 @@ int MB2Dfree(MB2D **pmb) { return (0); } -MB2D *MB2Dcopy(MB2D *src, int CopyMRI, MB2D *copy) { +MB2D *MB2Dcopy(MB2D *src, int CopyMRI, MB2D *copy) +{ if (copy == NULL) copy = (MB2D *)calloc(sizeof(MB2D), 1); copy->type = src->type; copy->offset = src->offset; @@ -6593,7 +6742,8 @@ MB2D *MB2Dcopy(MB2D *src, int CopyMRI, MB2D *copy) { \brief Creates a grid of ones separated by skip. All the slices are the same. Good for testing MRImotionBlur2D(). */ -MRI *MB2Dgrid(MRI *template, int skip, MRI *outvol) { +MRI *MB2Dgrid(MRI *template, int skip, MRI *outvol) +{ int c, r, s, c0, r0, dc, dr, f; double radmax; diff --git a/utils/mriflood.c b/utils/mriflood.c index 87455d2f2f9..8ea428a91db 100644 --- a/utils/mriflood.c +++ b/utils/mriflood.c @@ -59,21 +59,24 @@ int IllegalCorticalNeighbour(MRI *mri_masked, MRI *mri_white, int i, int j, int void MRIcorrecthippocampus(MRI *mri_masked, MRI *mri_dst); // return number of bits on ( possible values are 0 through 8 ) -static int countBits(MRI *mri, int i, int j, int k) { +static int countBits(MRI *mri, int i, int j, int k) +{ int nvox; nvox = (int)MRIgetVoxVal(mri, i, j, k, 0); return (((nvox >> 7) & 1) + ((nvox >> 6) & 1) + ((nvox >> 5) & 1) + ((nvox >> 4) & 1) + ((nvox >> 3) & 1) + ((nvox >> 2) & 1) + ((nvox >> 1) & 1) + (nvox & 1)); } // return true if count of the right voxel > 4, else false -static int likely(MRI *mri, int i, int j, int k) { +static int likely(MRI *mri, int i, int j, int k) +{ if (countBits(mri, i, j, k) > 4) return 1; else return 0; } -static void likelinessHistogram(MRI *mri, char *msg) { +static void likelinessHistogram(MRI *mri, char *msg) +{ int i, j, k; long Hist[] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -87,7 +90,8 @@ static void likelinessHistogram(MRI *mri, char *msg) { } #ifndef __OPTIMIZE__ -void DebugVoxel(char *msg, MRI *mri, int x, int y, int z) { +void DebugVoxel(char *msg, MRI *mri, int x, int y, int z) +{ printf("================================================================\n"); printf("%s (%d,%d,%d) = %d\n", msg, x, y, z, MRIvox(mri, x, y, z)); } @@ -96,7 +100,8 @@ void DebugVoxel(char *msg, MRI *mri, int x, int y, int z) { /* MRIribbon determines the space between the inner and outer MRI surfaces provided, */ /* and creates a volume in mri_dst corresponding to the input format mri_src */ -MRI *MRISribbon(MRI_SURFACE *inner_mris, MRI_SURFACE *outer_mris, MRI *mri_src, MRI *mri_dst) { +MRI *MRISribbon(MRI_SURFACE *inner_mris, MRI_SURFACE *outer_mris, MRI *mri_src, MRI *mri_dst) +{ MRI *mri_inter; /* Allocate new MRI structures as needed */ @@ -152,7 +157,8 @@ MRI *MRISribbon(MRI_SURFACE *inner_mris, MRI_SURFACE *outer_mris, MRI *mri_src, the format for the output, to match size and type. The */ /* surface is recreated in the MRI space (mri_dst) from the tesselated surface (mris) as voxels of 255 */ -MRI *MRISshell(MRI *mri_src, MRI_SURFACE *mris, MRI *mri_dst, int clearflag) { +MRI *MRISshell(MRI *mri_src, MRI_SURFACE *mris, MRI *mri_dst, int clearflag) +{ int width, height, depth, i, j, imnr, fno, numu, numv, u, v; // int imnr0; // float ps, st, xx0, xx1, yy0, yy1, zz0, zz1; @@ -250,7 +256,8 @@ MRI *MRISshell(MRI *mri_src, MRI_SURFACE *mris, MRI *mri_dst, int clearflag) { /* Floods MRI volume from outermost corners inward */ /* Fill with 1, boundary is anything but 0 and 1 */ // mri_src is just a dummy -MRI *MRISfloodoutside(MRI *mri_src, MRI *mri_dst) { +MRI *MRISfloodoutside(MRI *mri_src, MRI *mri_dst) +{ int newfilled, width, height, depth, i, j, k, v1, v2, v3; mri_dst = MRIcopy(mri_src, mri_dst); @@ -429,7 +436,8 @@ newfilled++; return mri_dst; } -MRI *MRISaccentuate(MRI *mri_src, MRI *mri_dst, int lo_thresh, int hi_thresh) { +MRI *MRISaccentuate(MRI *mri_src, MRI *mri_dst, int lo_thresh, int hi_thresh) +{ int width, height, depth, i, j, k; float val; @@ -454,7 +462,8 @@ MRI *MRISaccentuate(MRI *mri_src, MRI *mri_dst, int lo_thresh, int hi_thresh) { /* Set mri_dst voxel to 255 for every mri_src voxel for which the majority of subvoxels is set. */ -MRI *MRImajority(MRI *mri_src, MRI *mri_dst) { +MRI *MRImajority(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, i, j, k, vox; long counts[] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; float val; @@ -485,7 +494,8 @@ MRI *MRImajority(MRI *mri_src, MRI *mri_dst) { return mri_dst; } -MRI *MRIbitwisenot(MRI *mri_src, MRI *mri_dst) { +MRI *MRIbitwisenot(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, i, j, k, vox; width = mri_src->width; @@ -511,7 +521,8 @@ MRI *MRIbitwisenot(MRI *mri_src, MRI *mri_dst) { /* Partial shell fills the voxel space with a superresolution surface - */ /* each voxel is divided into 8 subvoxels represented by the 8 bits of the */ /* unsigned char in the MRI structure. */ -MRI *MRISpartialshell(MRI *mri_src, MRI_SURFACE *mris, MRI *mri_dst, int clearflag) { +MRI *MRISpartialshell(MRI *mri_src, MRI_SURFACE *mris, MRI *mri_dst, int clearflag) +{ int width, height, depth, i, j, imnr, isub, jsub, isubmnr, fno, numu, numv, u, v; // int imnr0; // float ps, st, xx0, xx1, yy0, yy1, zz0, zz1; @@ -617,7 +628,8 @@ MRI *MRISpartialshell(MRI *mri_src, MRI_SURFACE *mris, MRI *mri_dst, int clearfl return mri_dst; } -MRI *MRIbitwiseor(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIbitwiseor(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z; // BUFTYPE *p1, *p2, *pdst; BUFTYPE v1, v2; @@ -643,7 +655,8 @@ MRI *MRIbitwiseor(MRI *mri1, MRI *mri2, MRI *mri_dst) { return (mri_dst); } -MRI *MRIbitwiseand(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIbitwiseand(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z; // BUFTYPE *p1, *p2, *pdst; BUFTYPE v1, v2; @@ -672,7 +685,8 @@ MRI *MRIbitwiseand(MRI *mri1, MRI *mri2, MRI *mri_dst) { /* Floods MRI volume from outermost corners inward. */ /* Upon return, mri_dst contains the filled volume NOT including the shell. */ /* mri_src and mri_dst cannot be the same volume! */ -MRI *MRISpartialfloodoutside(MRI *mri_src, MRI *mri_dst) { +MRI *MRISpartialfloodoutside(MRI *mri_src, MRI *mri_dst) +{ int newfilled, width, height, depth, i, j, k, is, js, ks, isub, jsub, ksub; int val; @@ -773,7 +787,8 @@ MRI *MRISpartialribbon(MRI_SURFACE *inner_mris_lh, MRI_SURFACE *outer_mris_rh, MRI *mri_src, MRI *mri_dst, - MRI *mri_mask) { + MRI *mri_mask) +{ MRI *mri_inter1, *mri_inter2, *mri_inter3; /* Allocate new MRI structures as needed */ @@ -918,7 +933,8 @@ MRI *MRISpartialribbon(MRI_SURFACE *inner_mris_lh, return mri_dst; } -MRI *MRImergecortexwhitecma(MRI *mri_cortex, MRI *mri_white, MRI *mri_cma, MRI *mri_left, MRI *mri_dst) { +MRI *MRImergecortexwhitecma(MRI *mri_cortex, MRI *mri_white, MRI *mri_cma, MRI *mri_left, MRI *mri_dst) +{ /* mri_cortex = cerebral cortex is labelled as 255, all else is 0. mri_white = white matter and some of the inner gray matter shell is labelled as 255, all else is 0. @@ -983,7 +999,8 @@ MRI *MRImergecortexwhitecma(MRI *mri_cortex, MRI *mri_white, MRI *mri_cma, MRI * else countwhiteunknown++; } - } else if ((vox == Right_Cerebral_Cortex) || (vox == Right_Cerebral_White_Matter)) { + } + else if ((vox == Right_Cerebral_Cortex) || (vox == Right_Cerebral_White_Matter)) { if (likelyWhite && (countBitsWhite >= countBitsCortex)) MRIsetVoxVal(mri_dst, i, j, k, 0, Right_Cerebral_White_Matter); else if (likelyCortex) @@ -995,7 +1012,8 @@ MRI *MRImergecortexwhitecma(MRI *mri_cortex, MRI *mri_white, MRI *mri_cma, MRI * else countwhiteunknown++; } - } else if (vox == Unknown) { + } + else if (vox == Unknown) { // cases are // countBitsWhite >= countBitsCortex >=0 // countBitsCortex > countBitsWhite >=0 @@ -1046,7 +1064,8 @@ MRI *MRImergecortexwhitecma(MRI *mri_cortex, MRI *mri_white, MRI *mri_cma, MRI * break; } countunknowncortex++; - } else + } + else countunknownunknown++; // we don't change unknown state } // vox unknown @@ -1064,7 +1083,8 @@ MRI *MRImergecortexwhitecma(MRI *mri_cortex, MRI *mri_white, MRI *mri_cma, MRI * /* Return 1 for left, 0 for right (searched a cube of sidelength halfside*2+1). */ -int HemisphereVote(MRI *mri_cma, int i, int j, int k, int halfside) { +int HemisphereVote(MRI *mri_cma, int i, int j, int k, int halfside) +{ int x, y, z, vox; float leftvote, rightvote; int width, height, depth; @@ -1114,7 +1134,8 @@ int HemisphereVote(MRI *mri_cma, int i, int j, int k, int halfside) { float distance(float x, float y, float z) { return sqrt(x * x + y * y + z * z); } -void MRIerodecerebralcortex(MRI *mri_masked, MRI *mri_cma, MRI *mri_white, MRI *mri_left) { +void MRIerodecerebralcortex(MRI *mri_masked, MRI *mri_cma, MRI *mri_white, MRI *mri_left) +{ int width, height, depth, i, j, k, vox, erodedvoxelcount, olderodedvoxelcount, unknowncount; int erodewhitecount; int erodecortexcma; @@ -1143,9 +1164,10 @@ void MRIerodecerebralcortex(MRI *mri_masked, MRI *mri_cma, MRI *mri_white, MRI * if ((int)MRIgetVoxVal(mri_cma, i, j, k, 0) != Unknown) { MRIsetVoxVal(mri_masked, i, j, k, 0, MRIgetVoxVal(mri_cma, i, j, k, 0)); erodecortexcma++; // illegal and thus take the cma value again - } else { /* if the voxel needs to be eroded, - but the CMA didn't label it, - check if it's in the white matter volume. */ + } + else { /* if the voxel needs to be eroded, + but the CMA didn't label it, + check if it's in the white matter volume. */ // if (MRIvox(mri_white,i,j,k)==255) if (likely(mri_white, i, j, k)) { switch (HemisphereVote(mri_cma, i, j, k, NEIGHBOURHALFSIDE)) { @@ -1165,7 +1187,8 @@ void MRIerodecerebralcortex(MRI *mri_masked, MRI *mri_cma, MRI *mri_white, MRI * } // printf("labelled as white (%d,%d,%d)\n", i,j,k); erodewhitecount++; - } else { + } + else { // printf("Voxel labelled as cortex, // not in white matter volume (%d,%d,%d)\n",i,j,k); MRIsetVoxVal(mri_masked, i, j, k, 0, Unknown); @@ -1186,7 +1209,8 @@ void MRIerodecerebralcortex(MRI *mri_masked, MRI *mri_cma, MRI *mri_white, MRI * printf("\tcortex became unknown : %8d\n", unknowncount); } -int IllegalCorticalNeighbour(MRI *mri_masked, MRI *mri_white, int i, int j, int k) { +int IllegalCorticalNeighbour(MRI *mri_masked, MRI *mri_white, int i, int j, int k) +{ int width, height, depth, x, y, z, vox, illegalflag; int nvox, ii, jj, kk; width = mri_masked->width; @@ -1237,8 +1261,9 @@ int IllegalCorticalNeighbour(MRI *mri_masked, MRI *mri_white, int i, int j, int // (%d,%d,%d) ventricle and (%d,%d,%d) cortical\n", // ii,jj,kk, x,y,z, i, j, k); continue; - } else if (nvox == Unknown) // CMA labelled as unknown, - // then check if it is in white volume + } + else if (nvox == Unknown) // CMA labelled as unknown, + // then check if it is in white volume { if (likely(mri_white, ii, jj, kk)) // nvox = MRIvox(mri_white, ii, jj, kk); @@ -1248,10 +1273,12 @@ int IllegalCorticalNeighbour(MRI *mri_masked, MRI *mri_white, int i, int j, int else illegalflag++; } - } else + } + else illegalflag++; - } else if ((vox == Left_Caudate) || (vox == Right_Caudate) || (vox == Left_Thalamus) || - (vox == Left_Thalamus_Proper) || (vox == Right_Thalamus) || (vox == Right_Thalamus_Proper)) { + } + else if ((vox == Left_Caudate) || (vox == Right_Caudate) || (vox == Left_Thalamus) || + (vox == Left_Thalamus_Proper) || (vox == Right_Thalamus) || (vox == Right_Thalamus_Proper)) { illegalflag++; } // debug illegal check voxel values for voxels near i,j,k @@ -1264,7 +1291,8 @@ int IllegalCorticalNeighbour(MRI *mri_masked, MRI *mri_white, int i, int j, int return ((illegalflag > 0) ? 1 : 0); } -void MRIcorrecthippocampus(MRI *mri_masked, MRI *mri_dst) { +void MRIcorrecthippocampus(MRI *mri_masked, MRI *mri_dst) +{ /* mri_dst must differ from mri_masked. */ int width, height, depth, i, j, k, vox, hippocount; @@ -1307,7 +1335,8 @@ void MRIcorrecthippocampus(MRI *mri_masked, MRI *mri_dst) { printf("\tcortex became white : %8d\n", hippocount); } -MRI *MRISfillInteriorOld(MRI_SURFACE *mris, double resolution, MRI *mri_interior) { +MRI *MRISfillInteriorOld(MRI_SURFACE *mris, double resolution, MRI *mri_interior) +{ int width, height, depth, x, y, z, val, saved_use_Real_RAS, interior_alloced; MATRIX *m_vox2ras; MRI *mri_shell, *mri_outside; @@ -1322,7 +1351,8 @@ MRI *MRISfillInteriorOld(MRI_SURFACE *mris, double resolution, MRI *mri_interior MRIclear(mri_interior); m_vox2ras = MRIgetVoxelToRasXform(mri_interior); mri_shell = MRIcloneDifferentType(mri_interior, MRI_FLOAT); - } else { + } + else { interior_alloced = 1; width = ceil((mris->xhi - mris->xlo) / resolution); height = ceil((mris->yhi - mris->ylo) / resolution); @@ -1397,7 +1427,8 @@ MRISfillInteriorOld() and MRISfillInteriorRibbonTest(). \param resolution - only used if mri_dst is NULL \param mri_dst - output */ -MRI *MRISfillInterior(MRI_SURFACE *mris, double resolution, MRI *mri_dst) { +MRI *MRISfillInterior(MRI_SURFACE *mris, double resolution, MRI *mri_dst) +{ int col, row, slc, fno, numu, numv, u, v, nhits, width, height, depth; double x0, y0, z0, x1, y1, z1, x2, y2, z2, d0, d1, d2, dmax; double px0, py0, pz0, px1, py1, pz1, px, py, pz; @@ -1623,7 +1654,8 @@ generated using a ray tracing algorithm. Typical results are that the new MRISfillInterior() will overlap ribbon.mgz to better than 99.5% but is on the order of 20 times faster. */ -int MRISfillInteriorRibbonTest(char *subject, int UseNew, FILE *fp) { +int MRISfillInteriorRibbonTest(char *subject, int UseNew, FILE *fp) +{ FSENV *fsenv; char tmpstr[4000], *hemistr = NULL, *surfname = NULL; MRI *ribbon; diff --git a/utils/mrihisto.c b/utils/mrihisto.c index 614ab4be8bf..de2d16d4075 100644 --- a/utils/mrihisto.c +++ b/utils/mrihisto.c @@ -72,7 +72,8 @@ static HISTOGRAM *mriHistogramLabel(MRI *mri, int nbins, HISTOGRAM *histo, LABEL Description ------------------------------------------------------*/ -MRI *MRIapplyHistogram(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo) { +MRI *MRIapplyHistogram(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo) +{ int width, height, depth, x, y, z; BUFTYPE *psrc, *pdst, sval, dval; @@ -103,7 +104,8 @@ MRI *MRIapplyHistogram(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo) { Description ------------------------------------------------------*/ -HISTOGRAM *MRIhistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION *region) { +HISTOGRAM *MRIhistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION *region) +{ int overlap; float fmin, fmax, bin_size; // BUFTYPE bmin, bmax; @@ -174,7 +176,8 @@ HISTOGRAM *MRIhistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION HISTOadd(histo, histo_right, histo); HISTOfree(&histo_left); HISTOfree(&histo_right); - } else + } + else mriHistogramRegion(mri, nbins, histo, region); mri_prev = mri; @@ -189,7 +192,8 @@ HISTOGRAM *MRIhistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION Description ------------------------------------------------------*/ -HISTOGRAM *MRIhistogramLabelStruct(MRI *mri, int nbins, HISTOGRAM *histo, LABEL *label) { +HISTOGRAM *MRIhistogramLabelStruct(MRI *mri, int nbins, HISTOGRAM *histo, LABEL *label) +{ float fmin, fmax, bin_size; MRIvalRange(mri, &fmin, &fmax); @@ -214,7 +218,8 @@ HISTOGRAM *MRIhistogramLabelStruct(MRI *mri, int nbins, HISTOGRAM *histo, LABEL return (histo); } -static HISTOGRAM *mriHistogramLabel(MRI *mri, int nbins, HISTOGRAM *histo, LABEL *label) { +static HISTOGRAM *mriHistogramLabel(MRI *mri, int nbins, HISTOGRAM *histo, LABEL *label) +{ // int width, height, depth; int x, y, z, bin_no, i; float fmin, fmax, bin_size, val; @@ -223,7 +228,8 @@ static HISTOGRAM *mriHistogramLabel(MRI *mri, int nbins, HISTOGRAM *histo, LABEL if (mri->type == MRI_UCHAR) { fmin = 0; fmax = 255; - } else + } + else MRIvalRange(mri, &fmin, &fmax); if (!nbins) nbins = nint(fmax - fmin + 1.0); @@ -243,7 +249,8 @@ static HISTOGRAM *mriHistogramLabel(MRI *mri, int nbins, HISTOGRAM *histo, LABEL fmax = 255; fmin = 0; bin_size = 1; - } else + } + else bin_size = histo->bin_size = (fmax - fmin + 1) / (float)nbins; // width = mri->width; // height = mri->height; @@ -305,7 +312,8 @@ static HISTOGRAM *mriHistogramLabel(MRI *mri, int nbins, HISTOGRAM *histo, LABEL Description ------------------------------------------------------*/ -static HISTOGRAM *mriHistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION *region) { +static HISTOGRAM *mriHistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION *region) +{ int width, height, depth, x, y, z, bin_no, x0, y0, z0; float fmin, fmax; BUFTYPE val, *psrc; @@ -418,7 +426,8 @@ static HISTOGRAM *mriHistogramRegion(MRI *mri, int nbins, HISTOGRAM *histo, MRI_ Description ------------------------------------------------------*/ -MRI *MRIhistoEqualizeRegion(MRI *mri_src, MRI *mri_dst, int low, MRI_REGION *region) { +MRI *MRIhistoEqualizeRegion(MRI *mri_src, MRI *mri_dst, int low, MRI_REGION *region) +{ HISTOGRAM *histo_eq; if (region == NULL) { @@ -442,7 +451,8 @@ MRI *MRIhistoEqualizeRegion(MRI *mri_src, MRI *mri_dst, int low, MRI_REGION *reg Description ------------------------------------------------------*/ -MRI *MRIapplyHistogramToRegion(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo, MRI_REGION *region) { +MRI *MRIapplyHistogramToRegion(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo, MRI_REGION *region) +{ int width, height, depth, x, y, z, x0, y0, z0; BUFTYPE *psrc, *pdst, sval, dval; @@ -482,7 +492,8 @@ MRI *MRIapplyHistogramToRegion(MRI *mri_src, MRI *mri_dst, HISTOGRAM *histo, MRI Description ------------------------------------------------------*/ -HISTOGRAM *MRIgetEqualizeHistoRegion(MRI *mri, HISTOGRAM *histo_eq, int low, MRI_REGION *region, int norm) { +HISTOGRAM *MRIgetEqualizeHistoRegion(MRI *mri, HISTOGRAM *histo_eq, int low, MRI_REGION *region, int norm) +{ int i, nbins; HISTOGRAM *histo; float *pc, *pdst, total, total_pix; @@ -535,7 +546,8 @@ HISTOGRAM *MRIgetEqualizeHistoRegion(MRI *mri, HISTOGRAM *histo_eq, int low, MRI Description ------------------------------------------------------*/ -HISTOGRAM *MRIgetEqualizeHisto(MRI *mri, HISTOGRAM *histo_eq, int low, int high, int norm) { +HISTOGRAM *MRIgetEqualizeHisto(MRI *mri, HISTOGRAM *histo_eq, int low, int high, int norm) +{ int i, total, total_pix; HISTOGRAM *histo; @@ -568,7 +580,8 @@ HISTOGRAM *MRIgetEqualizeHisto(MRI *mri, HISTOGRAM *histo_eq, int low, int high, HISTOfree(&histo); return (histo_eq); } -MRI *MRIhistogramNormalize(MRI *mri_src, MRI *mri_template, MRI *mri_dst) { +MRI *MRIhistogramNormalize(MRI *mri_src, MRI *mri_template, MRI *mri_dst) +{ float scale, offset; HISTOGRAM *h_src, *h_template; @@ -582,7 +595,8 @@ MRI *MRIhistogramNormalize(MRI *mri_src, MRI *mri_template, MRI *mri_dst) { HISTOfree(&h_template); return (mri_dst); } -MRI *MRIscaleIntensities(MRI *mri_src, MRI *mri_dst, float scale, float offset) { +MRI *MRIscaleIntensities(MRI *mri_src, MRI *mri_dst, float scale, float offset) +{ int x, y, z, f; float val; @@ -607,7 +621,8 @@ MRI *MRIscaleIntensities(MRI *mri_src, MRI *mri_dst, float scale, float offset) Description ------------------------------------------------------*/ -MRI *MRIhistoEqualize(MRI *mri_src, MRI *mri_template, MRI *mri_dst, int low, int high) { +MRI *MRIhistoEqualize(MRI *mri_src, MRI *mri_template, MRI *mri_dst, int low, int high) +{ HISTOGRAM *histo_src, *histo_template; int width, height, depth, x, y, z, index, sval, dval; float pct; @@ -660,7 +675,8 @@ MRI *MRIhistoEqualize(MRI *mri_src, MRI *mri_template, MRI *mri_dst, int low, in Description ------------------------------------------------------*/ -MRI *MRIcrunch(MRI *mri_src, MRI *mri_dst) { +MRI *MRIcrunch(MRI *mri_src, MRI *mri_dst) +{ HISTOGRAM *histo; int b, deleted; @@ -687,7 +703,8 @@ MRI *MRIcrunch(MRI *mri_src, MRI *mri_dst) { Description compute a histogram of all frames in the input image ------------------------------------------------------*/ -HISTOGRAM *MRIhistogram(MRI *mri, int nbins) { +HISTOGRAM *MRIhistogram(MRI *mri, int nbins) +{ int width, height, depth, x, y, z, bin_no, frame; HISTOGRAM *histo; float fmin, fmax; @@ -715,7 +732,8 @@ HISTOGRAM *MRIhistogram(MRI *mri, int nbins) { } return (histo); } -HISTOGRAM *MRIhistogramLabelRegion(MRI *mri, MRI *mri_labeled, MRI_REGION *region, int label, int nbins) { +HISTOGRAM *MRIhistogramLabelRegion(MRI *mri, MRI *mri_labeled, MRI_REGION *region, int label, int nbins) +{ int width, height, depth, x, y, z, bin_no, x0, x1, y0, y1, z0, z1; HISTOGRAM *histo; float fmin, fmax; @@ -786,7 +804,8 @@ HISTOGRAM *MRIhistogramLabelRegion(MRI *mri, MRI *mri_labeled, MRI_REGION *regio Description ------------------------------------------------------*/ -HISTOGRAM *MRIhistogramLabel(MRI *mri, MRI *mri_labeled, int label, int nbins) { +HISTOGRAM *MRIhistogramLabel(MRI *mri, MRI *mri_labeled, int label, int nbins) +{ int width, height, depth, x, y, z, bin_no; HISTOGRAM *histo; float fmin, fmax; @@ -885,7 +904,8 @@ HISTOGRAM *MRIhistogramLabel(MRI *mri, MRI *mri_labeled, int label, int nbins) { #define Y_DB 153 #define Z_DB 128 -MRI *MRIhistoSegment(MRI *mri_src, MRI *mri_labeled, int wm_low, int wm_hi, int gray_hi, int wsize, float sigma) { +MRI *MRIhistoSegment(MRI *mri_src, MRI *mri_labeled, int wm_low, int wm_hi, int gray_hi, int wsize, float sigma) +{ int width, height, depth, x, y, z, whalf, in_val, label, nvox, valley, wm_peak, gray_peak, nlabeled; // int thresh; BUFTYPE *pdst, *psrc; @@ -1006,7 +1026,8 @@ MRI *MRIhistoSegment(MRI *mri_src, MRI *mri_labeled, int wm_low, int wm_hi, int else if (in_val >= valley) { nlabeled++; *pdst++ = MRI_WHITE; - } else { + } + else { nlabeled++; *pdst++ = MRI_NOT_WHITE; } @@ -1046,7 +1067,8 @@ MRI *MRIhistoSegmentVoxel(MRI *mri_src, int z, HISTOGRAM *histo, HISTOGRAM *hsmooth, - float sigma) { + float sigma) +{ int whalf, in_val, valley, wm_peak, gray_peak /*, thresh */; MRI_REGION region; float sig; @@ -1137,7 +1159,8 @@ MRI *MRIhistoSegmentVoxel(MRI *mri_src, Description ------------------------------------------------------*/ HISTOGRAM *MRIhistogramVoxel( - MRI *mri, int nbins, HISTOGRAM *histo, int x0, int y0, int z0, int wsize, MRI *mri_thresh, float thresh) { + MRI *mri, int nbins, HISTOGRAM *histo, int x0, int y0, int z0, int wsize, MRI *mri_thresh, float thresh) +{ int whalf; float fmin, fmax; MRI_REGION region; @@ -1173,7 +1196,8 @@ HISTOGRAM *MRIhistogramVoxel( return (histo); } HISTOGRAM *MRIhistogramRegionWithThreshold( - MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION *region, MRI *mri_thresh, float thresh, int frame) { + MRI *mri, int nbins, HISTOGRAM *histo, MRI_REGION *region, MRI *mri_thresh, float thresh, int frame) +{ int width, height, depth, z, x0, y0, z0, tid; float fmin, fmax; #ifdef HAVE_OPENMP @@ -1269,7 +1293,8 @@ HISTOGRAM *MRIhistogramRegionWithThreshold( return (histo); } #define NBINS 1000 -double MRIfindPercentile(MRI *mri, double percentile, int frame) { +double MRIfindPercentile(MRI *mri, double percentile, int frame) +{ int x, y, z, val, bin; HISTO *histo, *hcdf; float min_val, max_val; diff --git a/utils/mriio.c b/utils/mriio.c index 733b1a371e1..9e66f3dfc76 100644 --- a/utils/mriio.c +++ b/utils/mriio.c @@ -206,7 +206,8 @@ static int n_unknown_labels; // this is a one way of setting direction cosine // when the direction cosine is not provided in the volume. // may not agree with the volume. what can we do? Let them set by themselves. -int setDirectionCosine(MRI *mri, int orientation) { +int setDirectionCosine(MRI *mri, int orientation) +{ switch (orientation) { case MRI_CORONAL: // x is from right to left. // y is from top to neck, z is from back to front @@ -264,7 +265,8 @@ int setDirectionCosine(MRI *mri, int orientation) { #define isCloseToOne(a) (fabs(fabs(a) - 1) < 0.1) // here I take the narrow view of slice_direction -int getSliceDirection(MRI *mri) { +int getSliceDirection(MRI *mri) +{ int direction = MRI_UNDEFINED; if (!strcmp(MRIsliceDirectionName(mri), "coronal")) @@ -291,7 +293,8 @@ int getSliceDirection(MRI *mri) { // For surface, we currently cannot handle volumes with general slice direction // nor we cannot handle non-conformed volumes -int mriOKforSurface(MRI *mri) { +int mriOKforSurface(MRI *mri) +{ // first check slice direction if (getSliceDirection(mri) != MRI_CORONAL) return 0; // remove slice size limitation @@ -304,7 +307,8 @@ int mriOKforSurface(MRI *mri) { return 1; } -int mriConformed(MRI *mri) { +int mriConformed(MRI *mri) +{ // first check slice direction if (getSliceDirection(mri) != MRI_CORONAL) return 0; @@ -318,7 +322,8 @@ int mriConformed(MRI *mri) { return 1; } -float MRIfindMinSize(MRI *mri, int *conform_width) { +float MRIfindMinSize(MRI *mri, int *conform_width) +{ double xsize, ysize, zsize, minsize; double fwidth, fheight, fdepth, fmax; xsize = mri->xsize; @@ -335,7 +340,8 @@ float MRIfindMinSize(MRI *mri, int *conform_width) { // z > y > x x min if (xsize > ysize) { minsize = (ysize > zsize) ? zsize : ysize; - } else { + } + else { minsize = (zsize > xsize) ? xsize : zsize; } @@ -348,7 +354,8 @@ float MRIfindMinSize(MRI *mri, int *conform_width) { // pick the largest if (fwidth > fheight) { fmax = (fwidth > fdepth) ? fwidth : fdepth; - } else { + } + else { fmax = (fdepth > fheight) ? fdepth : fheight; } @@ -363,7 +370,8 @@ float MRIfindMinSize(MRI *mri, int *conform_width) { } // this function is called when conform is done -int MRIfindRightSize(MRI *mri, float conform_size) { +int MRIfindRightSize(MRI *mri, float conform_size) +{ // user gave the conform_size double xsize, ysize, zsize; double fwidth, fheight, fdepth, fmax; @@ -381,7 +389,8 @@ int MRIfindRightSize(MRI *mri, float conform_size) { // pick the largest if (fwidth > fheight) { fmax = (fwidth > fdepth) ? fwidth : fdepth; - } else { + } + else { fmax = (fdepth > fheight) ? fdepth : fheight; } // get the width with conform_size @@ -421,7 +430,8 @@ int MRIfindRightSize(MRI *mri, float conform_size) { return conform_width; } -void setMRIforSurface(MRI *mri) { +void setMRIforSurface(MRI *mri) +{ if (!mriOKforSurface(mri)) ErrorExit(ERROR_BADPARM, "%s: the volume is not conformed, that is, " @@ -445,7 +455,8 @@ void setMRIforSurface(MRI *mri) { #endif } -int mriio_command_line(int argc, char *argv[]) { +int mriio_command_line(int argc, char *argv[]) +{ int i; int length; char *c; @@ -470,7 +481,8 @@ int mriio_command_line(int argc, char *argv[]) { } /* end mriio_command_line() */ -int mriio_set_subject_name(const char *name) { +int mriio_set_subject_name(const char *name) +{ if (subject_name == NULL) subject_name = (char *)malloc(STRLEN); if (subject_name == NULL) { @@ -493,14 +505,16 @@ int mriio_set_subject_name(const char *name) { } /* end mriio_set_subject_name() */ -void mriio_set_gdf_crop_flag(int new_gdf_crop_flag) { +void mriio_set_gdf_crop_flag(int new_gdf_crop_flag) +{ gdf_crop_flag = new_gdf_crop_flag; return; } /* end mriio_set_gdf_crop_flag() */ -int MRIgetVolumeName(const char *string, char *name_only) { +int MRIgetVolumeName(const char *string, char *name_only) +{ char *at, *pound; strcpy(name_only, string); @@ -515,7 +529,8 @@ int MRIgetVolumeName(const char *string, char *name_only) { } /* end MRIgetVolumeName() */ -MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int end_frame) { +MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int end_frame) +{ MRI *mri, *mri2; IMAGE *I; char fname_copy[STRLEN]; @@ -544,9 +559,11 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int strcat(fname_copy, "/"); strcat(fname_copy, fname); free(cwd); - } else // why fail? + } + else // why fail? strcpy(fname_copy, fname); - } else + } + else strcpy(fname_copy, fname); at = strrchr(fname_copy, '@'); @@ -571,7 +588,8 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "mri_read(): unknown type '%s'\n", at)); } - } else if (type == MRI_VOLUME_TYPE_UNKNOWN) { + } + else if (type == MRI_VOLUME_TYPE_UNKNOWN) { type = mri_identify(fname_copy); if (type == MRI_VOLUME_TYPE_UNKNOWN) { errno = 0; @@ -600,7 +618,8 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "mri_read(): bad end frame ('%s')\n", colon)); } - } else { + } + else { start_frame = end_frame = strtol(pound, &ep, 10); if (*ep != '\0') { errno = 0; @@ -631,40 +650,54 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int if (type == MRI_CORONAL_SLICE_DIRECTORY) { mri = corRead(fname_copy, volume_flag); - } else if (type == SIEMENS_FILE) { + } + else if (type == SIEMENS_FILE) { mri = siemensRead(fname_copy, volume_flag); - } else if (type == MRI_GCA_FILE) { + } + else if (type == MRI_GCA_FILE) { mri = readGCA(fname_copy, start_frame, end_frame); start_frame = -1; - } else if (type == BHDR) { + } + else if (type == BHDR) { ptmpstr = bhdr_firstslicefname(fname_copy); t = bhdr_precision(fname_copy); mri = bvolumeRead(ptmpstr, volume_flag, t); free(ptmpstr); - } else if (type == BSHORT_FILE) { + } + else if (type == BSHORT_FILE) { // mri = bshortRead(fname_copy, volume_flag); mri = bvolumeRead(fname_copy, volume_flag, MRI_SHORT); - } else if (type == BFLOAT_FILE) { + } + else if (type == BFLOAT_FILE) { // mri = bfloatRead(fname_copy, volume_flag); mri = bvolumeRead(fname_copy, volume_flag, MRI_FLOAT); - } else if (type == GENESIS_FILE) { + } + else if (type == GENESIS_FILE) { mri = genesisRead(fname_copy, volume_flag); - } else if (type == SIGNA_FILE) { + } + else if (type == SIGNA_FILE) { mri = signaRead(fname_copy, volume_flag); - } else if (type == GE_LX_FILE) { + } + else if (type == GE_LX_FILE) { mri = gelxRead(fname_copy, volume_flag); - } else if (type == MRI_ANALYZE_FILE || type == MRI_ANALYZE4D_FILE) { + } + else if (type == MRI_ANALYZE_FILE || type == MRI_ANALYZE4D_FILE) { mri = analyzeRead(fname_copy, volume_flag); - } else if (type == BRIK_FILE) { + } + else if (type == BRIK_FILE) { mri = afniRead(fname_copy, volume_flag); - } else if (type == MRI_MINC_FILE) { + } + else if (type == MRI_MINC_FILE) { // mri = mincRead2(fname_copy, volume_flag); mri = mincRead(fname_copy, volume_flag); - } else if (type == SDT_FILE) { + } + else if (type == SDT_FILE) { mri = sdtRead(fname_copy, volume_flag); - } else if (type == MRI_MGH_FILE) { + } + else if (type == MRI_MGH_FILE) { mri = mghRead(fname_copy, volume_flag, -1); - } else if (type == MGH_MORPH) { + } + else if (type == MGH_MORPH) { GCA_MORPH *gcam; gcam = GCAMread(fname_copy); if (gcam == NULL) ErrorReturn(NULL, (ERROR_BADPARM, "MRIread(%s): could not read .m3z\n", fname_copy)); @@ -678,7 +711,8 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int } GCAMfree(&gcam); - } else if (type == MGH_AUTOENCODER) { + } + else if (type == MGH_AUTOENCODER) { SAE *sae; sae = SAEread(fname_copy); if (sae == NULL) ErrorReturn(NULL, (ERROR_BADPARM, "MRIread(%s): could not read autoencoder\n", fname_copy)); @@ -687,31 +721,40 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int start_frame = 0; end_frame = mri->nframes - 1; SAEfree(&sae); - } else if (type == GDF_FILE) { + } + else if (type == GDF_FILE) { mri = gdfRead(fname_copy, volume_flag); - } else if (type == DICOM_FILE) { + } + else if (type == DICOM_FILE) { if (!UseDICOMRead2) DICOMRead(fname_copy, &mri, volume_flag); else mri = DICOMRead2(fname_copy, volume_flag); - } else if (type == SIEMENS_DICOM_FILE) { + } + else if (type == SIEMENS_DICOM_FILE) { // mri_convert -nth option sets start_frame = nth. otherwise -1 mri = sdcmLoadVolume(fname_copy, volume_flag, start_frame); start_frame = -1; // in order to avoid the later processing on start_frame and end_frame // read the comment later on end_frame = 0; - } else if (type == BRUKER_FILE) { + } + else if (type == BRUKER_FILE) { mri = brukerRead(fname_copy, volume_flag); - } else if (type == XIMG_FILE) { + } + else if (type == XIMG_FILE) { mri = ximgRead(fname_copy, volume_flag); - } else if (type == NIFTI1_FILE) { + } + else if (type == NIFTI1_FILE) { mri = nifti1Read(fname_copy, volume_flag); - } else if (type == NII_FILE) { + } + else if (type == NII_FILE) { mri = niiRead(fname_copy, volume_flag); - } else if (type == NRRD_FILE) { + } + else if (type == NRRD_FILE) { mri = mriNrrdRead(fname_copy, volume_flag); - } else if (type == MRI_CURV_FILE) + } + else if (type == MRI_CURV_FILE) mri = MRISreadCurvAsMRI(fname_copy, volume_flag); else if (type == GIFTI_FILE) mri = MRISreadGiftiAsMRI(fname_copy, volume_flag); @@ -719,7 +762,8 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int I = ImageRead(fname_copy); mri = ImageToMRI(I); ImageFree(&I); - } else { + } + else { fprintf(stderr, "mri_read(): type = %d\n", type); errno = 0; ErrorReturn(NULL, @@ -849,7 +893,8 @@ MRI *mri_read(const char *fname, int type, int volume_flag, int start_frame, int } /* end mri_read() */ -static int nan_inf_check(MRI *mri) { +static int nan_inf_check(MRI *mri) +{ int i, j, k, t; if (mri->type != MRI_FLOAT) return (NO_ERROR); @@ -862,10 +907,12 @@ static int nan_inf_check(MRI *mri) { if (devIsinf((MRIFseq_vox(mri, i, j, k, t))) != 0) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "nan_inf_check(): Inf at voxel %d, %d, %d, %d", i, j, k, t)); - } else if (devIsnan((MRIFseq_vox(mri, i, j, k, t)))) { + } + else if (devIsnan((MRIFseq_vox(mri, i, j, k, t)))) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "nan_inf_check(): NaN at voxel %d, %d, %d, %d", i, j, k, t)); - } else { + } + else { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, @@ -882,7 +929,8 @@ static int nan_inf_check(MRI *mri) { } /* end nan_inf_check() */ -MRI *MRIreadType(const char *fname, int type) { +MRI *MRIreadType(const char *fname, int type) +{ MRI *mri; chklc(); @@ -893,7 +941,8 @@ MRI *MRIreadType(const char *fname, int type) { } /* end MRIreadType() */ -MRI *MRIread(const char *fname) { +MRI *MRIread(const char *fname) +{ char buf[STRLEN]; MRI *mri = NULL; @@ -922,7 +971,8 @@ MRI *MRIread(const char *fname) { // allow picking one frame out of many frame // currently implemented only for Siemens dicom file -MRI *MRIreadEx(const char *fname, int nthframe) { +MRI *MRIreadEx(const char *fname, int nthframe) +{ char buf[STRLEN]; MRI *mri = NULL; @@ -942,7 +992,8 @@ MRI *MRIreadEx(const char *fname, int nthframe) { } /* end MRIread() */ -MRI *MRIreadInfo(const char *fname) { +MRI *MRIreadInfo(const char *fname) +{ MRI *mri = NULL; mri = mri_read(fname, MRI_VOLUME_TYPE_UNKNOWN, FALSE, -1, -1); @@ -956,7 +1007,8 @@ MRI *MRIreadInfo(const char *fname) { If type is MRI_VOLUME_TYPE_UNKNOWN, then the type will be inferred from the file name. ---------------------------------------------------------------*/ -MRI *MRIreadHeader(const char *fname, int type) { +MRI *MRIreadHeader(const char *fname, int type) +{ int usetype; MRI *mri = NULL; char modFname[STRLEN]; @@ -972,9 +1024,11 @@ MRI *MRIreadHeader(const char *fname, int type) { strcat(modFname, "/"); strcat(modFname, fname); free(cwd); - } else // why fail? + } + else // why fail? strcpy(modFname, fname); - } else + } + else strcpy(modFname, fname); if (usetype == MRI_VOLUME_TYPE_UNKNOWN) { @@ -994,7 +1048,8 @@ MRI *MRIreadHeader(const char *fname, int type) { } /* end MRIreadInfo() */ -int MRIwriteType(MRI *mri, const char *fname, int type) { +int MRIwriteType(MRI *mri, const char *fname, int type) +{ struct stat stat_buf; int error = 0; char *fstem; @@ -1002,7 +1057,8 @@ int MRIwriteType(MRI *mri, const char *fname, int type) { if (type == MRI_CORONAL_SLICE_DIRECTORY) { error = corWrite(mri, fname); - } else { + } + else { /* ----- all remaining types should write to a filename, not to within a directory, so check that it isn't an existing directory name we've been passed. @@ -1026,33 +1082,42 @@ int MRIwriteType(MRI *mri, const char *fname, int type) { if (type == MRI_MINC_FILE) { error = mincWrite(mri, fname); - } else if (type == IMAGE_FILE) { + } + else if (type == IMAGE_FILE) { IMAGE *image; if (mri->depth != 1) ErrorExit(ERROR_BADPARM, "MRIwriteType(%s): image files cannnot have depth > 1\n", fname); image = MRItoImage(mri, NULL, 0); ImageWrite(image, fname); ImageFree(&image); - } else if (type == BHDR) { + } + else if (type == BHDR) { fstem = bhdr_stem(fname); if (mri->type == MRI_SHORT) { sprintf(tmpstr, "%s_000.bshort", fstem); error = bvolumeWrite(mri, tmpstr, MRI_SHORT); - } else { + } + else { sprintf(tmpstr, "%s_000.bfloat", fstem); error = bvolumeWrite(mri, tmpstr, MRI_FLOAT); } free(fstem); - } else if (type == BSHORT_FILE) { + } + else if (type == BSHORT_FILE) { error = bvolumeWrite(mri, fname, MRI_SHORT); - } else if (type == BFLOAT_FILE) { + } + else if (type == BFLOAT_FILE) { error = bvolumeWrite(mri, fname, MRI_FLOAT); - } else if (type == MRI_ANALYZE_FILE) { + } + else if (type == MRI_ANALYZE_FILE) { error = analyzeWrite(mri, fname); - } else if (type == MRI_ANALYZE4D_FILE) { + } + else if (type == MRI_ANALYZE4D_FILE) { error = analyzeWrite4D(mri, fname); - } else if (type == BRIK_FILE) { + } + else if (type == BRIK_FILE) { error = afniWrite(mri, fname); - } else if (type == MGH_MORPH) { + } + else if (type == MGH_MORPH) { GCA_MORPH *gcam; if (mri->nframes != 3) @@ -1063,61 +1128,81 @@ int MRIwriteType(MRI *mri, const char *fname, int type) { GCAMreadWarpFromMRI(gcam, mri); GCAMwrite(gcam, fname); GCAMfree(&gcam); - } else if (type == ITK_MORPH) { + } + else if (type == ITK_MORPH) { if (mri->nframes != 3) ErrorReturn(-1, (ERROR_UNSUPPORTED, "MRIwriteType: itk warp - input mri must have 3 frames, not %d", mri->nframes)); error = itkMorphWrite(mri, fname); - } else if (type == MRI_MGH_FILE) { + } + else if (type == MRI_MGH_FILE) { error = mghWrite(mri, fname, -1); - } else if (type == GDF_FILE) { + } + else if (type == GDF_FILE) { error = gdfWrite(mri, fname); - } else if (type == NIFTI1_FILE) { + } + else if (type == NIFTI1_FILE) { error = nifti1Write(mri, fname); - } else if (type == NII_FILE) { + } + else if (type == NII_FILE) { // printf("Before writing nii file \n"); error = niiWrite(mri, fname); // printf("The error code is: %d\n", error); - } else if (type == NRRD_FILE) { + } + else if (type == NRRD_FILE) { error = mriNrrdWrite(mri, fname); - } else if (type == GIFTI_FILE) { + } + else if (type == GIFTI_FILE) { error = mriWriteGifti(mri, fname); - } else if (type == GENESIS_FILE) { + } + else if (type == GENESIS_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of GENESIS file type not supported")); - } else if (type == GE_LX_FILE) { + } + else if (type == GE_LX_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of GE LX file type not supported")); - } else if (type == SIEMENS_FILE) { + } + else if (type == SIEMENS_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of SIEMENS file type not supported")); - } else if (type == SDT_FILE) { + } + else if (type == SDT_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of SDT file type not supported")); - } else if (type == OTL_FILE) { + } + else if (type == OTL_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of OTL file type not supported")); - } else if (type == RAW_FILE) { + } + else if (type == RAW_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of RAW file type not supported")); - } else if (type == SIGNA_FILE) { + } + else if (type == SIGNA_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of SIGNA file type not supported")); - } else if (type == DICOM_FILE) { + } + else if (type == DICOM_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of DICOM file type not supported")); - } else if (type == SIEMENS_DICOM_FILE) { + } + else if (type == SIEMENS_DICOM_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of SIEMENS DICOM file type not supported")); - } else if (type == BRUKER_FILE) { + } + else if (type == BRUKER_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of BRUKER file type not supported")); - } else if (type == XIMG_FILE) { + } + else if (type == XIMG_FILE) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIwriteType(): writing of XIMG file type not supported")); - } else if (type == MRI_CORONAL_SLICE_DIRECTORY) { + } + else if (type == MRI_CORONAL_SLICE_DIRECTORY) { // already processed above - } else { + } + else { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, @@ -1150,7 +1235,8 @@ int MRIwriteType(MRI *mri, const char *fname, int type) { } /* end MRIwriteType() */ -int MRIwriteFrame(MRI *mri, const char *fname, int frame) { +int MRIwriteFrame(MRI *mri, const char *fname, int frame) +{ MRI *mri_tmp; if (frame >= mri->nframes) @@ -1161,7 +1247,8 @@ int MRIwriteFrame(MRI *mri, const char *fname, int frame) { return (NO_ERROR); } -int MRIwrite(MRI *mri, const char *fname) { +int MRIwrite(MRI *mri, const char *fname) +{ int int_type = -1; int error; @@ -1195,7 +1282,8 @@ int MRIwrite(MRI *mri, const char *fname) { #define ENDZ_FLAG 0x00001000 /* trivially time course clean */ -static MRI *corRead(const char *fname, int read_volume) { +static MRI *corRead(const char *fname, int read_volume) +{ MRI *mri; struct stat stat_buf; char fname_use[STRLEN]; @@ -1277,66 +1365,90 @@ static MRI *corRead(const char *fname, int read_volume) { if (strncmp(line, "imnr0 ", 6) == 0) { sscanf(line, "%*s %d", &imnr0); gotten = gotten | IMNR0_FLAG; - } else if (strncmp(line, "imnr1 ", 6) == 0) { + } + else if (strncmp(line, "imnr1 ", 6) == 0) { sscanf(line, "%*s %d", &imnr1); gotten = gotten | IMNR1_FLAG; - } else if (strncmp(line, "ptype ", 6) == 0) { + } + else if (strncmp(line, "ptype ", 6) == 0) { sscanf(line, "%*s %d", &ptype); gotten = gotten | PTYPE_FLAG; - } else if (strncmp(line, "x ", 2) == 0) { + } + else if (strncmp(line, "x ", 2) == 0) { sscanf(line, "%*s %d", &x); gotten = gotten | X_FLAG; - } else if (strncmp(line, "y ", 2) == 0) { + } + else if (strncmp(line, "y ", 2) == 0) { sscanf(line, "%*s %d", &y); gotten = gotten | Y_FLAG; - } else if (strncmp(line, "fov ", 4) == 0) { + } + else if (strncmp(line, "fov ", 4) == 0) { sscanf(line, "%*s %lf", &fov); - } else if (strncmp(line, "thick ", 6) == 0) { + } + else if (strncmp(line, "thick ", 6) == 0) { sscanf(line, "%*s %lf", &thick); gotten = gotten | THICK_FLAG; - } else if (strncmp(line, "flip ", 5) == 0) { + } + else if (strncmp(line, "flip ", 5) == 0) { sscanf(line + 11, "%f", &flip_angle); flip_angle = RADIANS(flip_angle); - } else if (strncmp(line, "psiz ", 5) == 0) { + } + else if (strncmp(line, "psiz ", 5) == 0) { sscanf(line, "%*s %lf", &psiz); gotten = gotten | PSIZ_FLAG; - } else if (strncmp(line, "locatn ", 7) == 0) { + } + else if (strncmp(line, "locatn ", 7) == 0) { sscanf(line, "%*s %lf", &locatn); - } else if (strncmp(line, "strtx ", 6) == 0) { + } + else if (strncmp(line, "strtx ", 6) == 0) { sscanf(line, "%*s %f", &strtx); gotten = gotten | STRTX_FLAG; - } else if (strncmp(line, "endx ", 5) == 0) { + } + else if (strncmp(line, "endx ", 5) == 0) { sscanf(line, "%*s %f", &endx); gotten = gotten | ENDX_FLAG; - } else if (strncmp(line, "strty ", 6) == 0) { + } + else if (strncmp(line, "strty ", 6) == 0) { sscanf(line, "%*s %f", &strty); gotten = gotten | STRTY_FLAG; - } else if (strncmp(line, "endy ", 5) == 0) { + } + else if (strncmp(line, "endy ", 5) == 0) { sscanf(line, "%*s %f", &endy); gotten = gotten | ENDY_FLAG; - } else if (strncmp(line, "strtz ", 6) == 0) { + } + else if (strncmp(line, "strtz ", 6) == 0) { sscanf(line, "%*s %f", &strtz); gotten = gotten | STRTZ_FLAG; - } else if (strncmp(line, "endz ", 5) == 0) { + } + else if (strncmp(line, "endz ", 5) == 0) { sscanf(line, "%*s %f", &endz); gotten = gotten | ENDZ_FLAG; - } else if (strncmp(line, "tr ", 3) == 0) { + } + else if (strncmp(line, "tr ", 3) == 0) { sscanf(line, "%*s %f", &tr); - } else if (strncmp(line, "te ", 3) == 0) { + } + else if (strncmp(line, "te ", 3) == 0) { sscanf(line, "%*s %f", &te); - } else if (strncmp(line, "ti ", 3) == 0) { + } + else if (strncmp(line, "ti ", 3) == 0) { sscanf(line, "%*s %f", &ti); - } else if (strncmp(line, "ras_good_flag ", 14) == 0) { + } + else if (strncmp(line, "ras_good_flag ", 14) == 0) { sscanf(line, "%*s %d", &ras_good_flag); - } else if (strncmp(line, "x_ras ", 6) == 0) { + } + else if (strncmp(line, "x_ras ", 6) == 0) { sscanf(line, "%*s %f %f %f", &x_r, &x_a, &x_s); - } else if (strncmp(line, "y_ras ", 6) == 0) { + } + else if (strncmp(line, "y_ras ", 6) == 0) { sscanf(line, "%*s %f %f %f", &y_r, &y_a, &y_s); - } else if (strncmp(line, "z_ras ", 6) == 0) { + } + else if (strncmp(line, "z_ras ", 6) == 0) { sscanf(line, "%*s %f %f %f", &z_r, &z_a, &z_s); - } else if (strncmp(line, "c_ras ", 6) == 0) { + } + else if (strncmp(line, "c_ras ", 6) == 0) { sscanf(line, "%*s %f %f %f", &c_r, &c_a, &c_s); - } else if (strncmp(line, "xform", 5) == 0 || strncmp(line, "transform", 9) == 0) { + } + else if (strncmp(line, "xform", 5) == 0 || strncmp(line, "transform", 9) == 0) { sscanf(line, "%*s %s", xform); } } @@ -1503,7 +1615,8 @@ static MRI *corRead(const char *fname, int read_volume) { mri->free_transform = 1; strcpy(mri->transform_fname, xform_use); if (DIAG_VERBOSE_ON) fprintf(stderr, "INFO: loaded talairach xform : %s\n", mri->transform_fname); - } else { + } + else { errno = 0; ErrorPrintf(ERROR_BAD_FILE, "error loading transform from %s", xform_use); mri->linear_transform = NULL; @@ -1539,7 +1652,8 @@ static MRI *corRead(const char *fname, int read_volume) { } /* end corRead() */ -static int corWrite(MRI *mri, const char *fname) { +static int corWrite(MRI *mri, const char *fname) +{ struct stat stat_buf; char fname_use[STRLEN]; char *fbase; @@ -1687,7 +1801,8 @@ static int corWrite(MRI *mri, const char *fname) { } /* end corWrite() */ -static MRI *siemensRead(const char *fname, int read_volume_flag) { +static MRI *siemensRead(const char *fname, int read_volume_flag) +{ int file_n, n_low, n_high; char fname_use[STRLEN]; MRI *mri; @@ -1852,7 +1967,8 @@ static MRI *siemensRead(const char *fname, int read_volume_flag) { } mos_r = mos_c = 1; mosaic_size = 1; - } else { + } + else { if (rows % base_raw_matrix_size != 0) { errno = 0; ErrorReturn(NULL, @@ -2102,7 +2218,8 @@ static MRI *siemensRead(const char *fname, int read_volume_flag) { } /* end siemensRead() */ /*-----------------------------------------------------------*/ -static MRI *mincRead(const char *fname, int read_volume) { +static MRI *mincRead(const char *fname, int read_volume) +{ // double wx, wy, wz; MRI *mri; Volume vol; @@ -2911,7 +3028,8 @@ static int NormalizeVector(float *v, int n) #endif /*----------------------------------------------------------*/ /* time course clean */ -static int mincWrite(MRI *mri, const char *fname) { +static int mincWrite(MRI *mri, const char *fname) +{ Volume minc_volume; STRING dimension_names[4] = {"xspace", "yspace", "zspace", "time"}; nc_type nc_data_type; @@ -3046,19 +3164,24 @@ static int mincWrite(MRI *mri, const char *fname) { if (mri->type == MRI_UCHAR) { nc_data_type = NC_BYTE; signed_flag = 0; - } else if (mri->type == MRI_SHORT) { + } + else if (mri->type == MRI_SHORT) { nc_data_type = NC_SHORT; signed_flag = 1; - } else if (mri->type == MRI_INT) { + } + else if (mri->type == MRI_INT) { nc_data_type = NC_LONG; signed_flag = 1; - } else if (mri->type == MRI_LONG) { + } + else if (mri->type == MRI_LONG) { nc_data_type = NC_LONG; signed_flag = 1; - } else if (mri->type == MRI_FLOAT) { + } + else if (mri->type == MRI_FLOAT) { nc_data_type = NC_FLOAT; signed_flag = 1; - } else { + } + else { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "mincWrite(): bad data type (%d) in mri structure", mri->type)); } @@ -3190,7 +3313,8 @@ static int mincWrite(MRI *mri, const char *fname) { bvolumeWrite() - replaces bshortWrite and bfloatWrite. Bug: fname_passed must the the stem, not the full file name. -----------------------------------------------------------------*/ -static int bvolumeWrite(MRI *vol, const char *fname_passed, int type) { +static int bvolumeWrite(MRI *vol, const char *fname_passed, int type) +{ int i, j, t; char fname[STRLEN]; short *bufshort; @@ -3255,7 +3379,8 @@ static int bvolumeWrite(MRI *vol, const char *fname_passed, int type) { mri->depth = nslices; mri->nframes = nframes; dealloc = 1; - } else { + } + else { mri = vol; dealloc = 0; } @@ -3389,14 +3514,17 @@ static int bvolumeWrite(MRI *vol, const char *fname_passed, int type) { errno = 0; ErrorPrintf(ERROR_BADPARM, "bvolumeWrite(): environment variable SUBJECTS_DIR unset"); if (dealloc) MRIfree(&mri); - } else { + } + else { sprintf(subject_dir, "%s/%s", subjects_dir, sn); if (stat(subject_dir, &stat_buf) < 0) { fprintf(stderr, "can't stat %s; writing to bhdr instead\n", subject_dir); - } else { + } + else { if (!S_ISDIR(stat_buf.st_mode)) { fprintf(stderr, "%s is not a directory; writing to bhdr instead\n", subject_dir); - } else { + } + else { sprintf(subject_volume_dir, "%s/mri/T1", subject_dir); subject_info = MRIreadInfo(subject_volume_dir); if (subject_info == NULL) { @@ -3791,7 +3919,8 @@ static int bvolumeWrite(MRI *vol, const char *fname_passed, int type) { fclose(fp); if (result != NO_ERROR) return (result); - } else + } + else MRIfree(&subject_info); if (dealloc) MRIfree(&mri); @@ -3800,7 +3929,8 @@ static int bvolumeWrite(MRI *vol, const char *fname_passed, int type) { } /* end bvolumeWrite() */ -static MRI *get_b_info(const char *fname_passed, int read_volume, char *directory, char *stem, int type) { +static MRI *get_b_info(const char *fname_passed, int read_volume, char *directory, char *stem, int type) +{ MRI *mri, *mri2; FILE *fp; int nslices = 0, nt; @@ -3949,7 +4079,8 @@ static MRI *get_b_info(const char *fname_passed, int read_volume, char *director } strcpy(mri->fname, fname_passed); - } else { + } + else { /* ----- get defaults ----- */ if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) fprintf(stderr, @@ -4035,7 +4166,8 @@ static MRI *get_b_info(const char *fname_passed, int read_volume, char *director /*------------------------------------------------------------------- bvolumeRead() - this replaces bshortRead and bfloatRead. -------------------------------------------------------------------*/ -static MRI *bvolumeRead(const char *fname_passed, int read_volume, int type) { +static MRI *bvolumeRead(const char *fname_passed, int read_volume, int type) +{ MRI *mri; FILE *fp; char fname[STRLEN]; @@ -4078,7 +4210,8 @@ static MRI *bvolumeRead(const char *fname_passed, int read_volume, int type) { if ((fp = fopen(fname, "r")) == NULL) { fprintf(stderr, "ERROR: can't open file %s; assuming big-endian bvolume\n", fname); swap_bytes_flag = 0; - } else { + } + else { fscanf(fp, "%*d %*d %*d %d", &swap_bytes_flag); #if (BYTE_ORDER == LITTLE_ENDIAN) swap_bytes_flag = !swap_bytes_flag; @@ -4351,7 +4484,8 @@ static int orient_with_register(MRI *mri) } /* end orient_with_register() */ #endif -int decompose_b_fname(const char *fname, char *dir, char *stem) { +int decompose_b_fname(const char *fname, char *dir, char *stem) +{ char *slash, *dot, *stem_start, *underscore; int fname_length; int und_pos; @@ -4381,7 +4515,8 @@ int decompose_b_fname(const char *fname, char *dir, char *stem) { if (slash == NULL) { stem_start = fname_copy; sprintf(dir, "."); - } else { + } + else { *slash = '\0'; strcpy(dir, fname_copy); stem_start = slash + 1; @@ -4410,7 +4545,8 @@ int decompose_b_fname(const char *fname, char *dir, char *stem) { } /* end decompose_b_fname() */ /*-------------------------------------------------------------*/ -static int write_bhdr(MRI *mri, FILE *fp) { +static int write_bhdr(MRI *mri, FILE *fp) +{ float vl; /* vector length */ float tlr, tla, tls; /* top left coordinates */ float trr, tra, trs; /* top right coordinates */ @@ -4530,7 +4666,8 @@ static int write_bhdr(MRI *mri, FILE *fp) { } /* end write_bhdr() */ /*------------------------------------------------------*/ -int read_bhdr(MRI *mri, FILE *fp) { +int read_bhdr(MRI *mri, FILE *fp) +{ char line[STRLEN]; char *l; float tlr = 0.; @@ -4582,7 +4719,8 @@ int read_bhdr(MRI *mri, FILE *fp) { else if (strncmp(l, "image_tr: ", 10) == 0) { sscanf(l, "%*s %f", &mri->tr); mri->tr = 1000.0 * mri->tr; // convert from sec to msec - } else if (strncmp(l, "image_ti: ", 10) == 0) + } + else if (strncmp(l, "image_ti: ", 10) == 0) sscanf(l, "%*s %f", &mri->ti); else if (strncmp(l, "flip_angle: ", 10) == 0) sscanf(l, "%*s %lf", &mri->flip_angle); @@ -4649,7 +4787,8 @@ int read_bhdr(MRI *mri, FILE *fp) { mri->x_r = xr / mri->xsize; mri->x_a = xa / mri->xsize; mri->x_s = xs / mri->xsize; - } else // fake values + } + else // fake values { mri->xsize = 1; mri->x_r = -1; @@ -4665,7 +4804,8 @@ int read_bhdr(MRI *mri, FILE *fp) { mri->y_r = yr / mri->ysize; mri->y_a = ya / mri->ysize; mri->y_s = ys / mri->ysize; - } else // fake values + } + else // fake values { mri->ysize = 1; mri->y_r = 0; @@ -4718,7 +4858,8 @@ int read_bhdr(MRI *mri, FILE *fp) { } /* end read_bhdr() */ -static MRI *genesisRead(const char *fname, int read_volume) { +static MRI *genesisRead(const char *fname, int read_volume) +{ char fname_format[STRLEN]; char fname_format2[STRLEN]; char fname_dir[STRLEN]; @@ -4750,7 +4891,8 @@ static MRI *genesisRead(const char *fname, int read_volume) { if (getenv("GE_ODD")) { odd_only = 1; printf("only using odd # GE files\n"); - } else if (getenv("GE_EVEN")) { + } + else if (getenv("GE_EVEN")) { even_only = 1; printf("only using even # GE files\n"); } @@ -4766,7 +4908,8 @@ static MRI *genesisRead(const char *fname, int read_volume) { if (c == NULL) { fname_dir[0] = '\0'; strcpy(fname_base, fname); - } else { + } + else { strncpy(fname_dir, fname, (c - fname + 1)); fname_dir[c - fname + 1] = '\0'; strcpy(fname_base, c + 1); @@ -4795,11 +4938,13 @@ static MRI *genesisRead(const char *fname, int read_volume) { // another type %s%%03d.MR" must be examined sprintf(fname_format, "%s%%d.MR", fname_base); sprintf(fname_format2, "%s%%03d.MR", fname_base); - } else { + } + else { errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "genesisRead(): can't determine file name format for %s", fname)); } - } else { + } + else { errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "genesisRead(): can't determine file name format for %s", fname)); } @@ -4830,7 +4975,8 @@ static MRI *genesisRead(const char *fname, int read_volume) { sprintf(fname_use, fname_format, im_high); } while (FileExists(fname_use)); im_high -= 2; - } else { + } + else { im_low = im_init; do { im_low--; @@ -4861,7 +5007,8 @@ static MRI *genesisRead(const char *fname, int read_volume) { sprintf(fname_use, fname_format2, im_high2); } while (FileExists(fname_use)); im_high2--; - } else { + } + else { im_high2 = im_low2 = 0; } // now decide which one to pick @@ -4931,7 +5078,8 @@ static MRI *genesisRead(const char *fname, int read_volume) { header->nframes = freadShort(fp); if (header->nframes > 1) { printf("multi-echo genesis file detected (%d echoes)...\n", header->nframes); - } else if (header->nframes == 0) { + } + else if (header->nframes == 0) { printf("zero frames specified in file - setting to 1\n"); header->nframes = 1; } @@ -5079,7 +5227,8 @@ static MRI *genesisRead(const char *fname, int read_volume) { } /* end genesisRead() */ -static MRI *gelxRead(const char *fname, int read_volume) { +static MRI *gelxRead(const char *fname, int read_volume) +{ char fname_format[STRLEN]; char fname_dir[STRLEN]; char fname_base[STRLEN]; @@ -5114,7 +5263,8 @@ static MRI *gelxRead(const char *fname, int read_volume) { if (c == NULL) { fname_dir[0] = '\0'; strcpy(fname_base, fname); - } else { + } + else { strncpy(fname_dir, fname, (c - fname + 1)); fname_dir[c - fname + 1] = '\0'; strcpy(fname_base, c + 1); @@ -5137,7 +5287,8 @@ static MRI *gelxRead(const char *fname, int read_volume) { im_init = atoi(c + 1); *c = '\0'; sprintf(fname_format, "%si%%d", fname_base); - } else { + } + else { errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "genesisRead(): can't determine file name format for %s", fname)); } @@ -5319,7 +5470,8 @@ static MRI *gelxRead(const char *fname, int read_volume) { SPM_START_FRAME and uses its value as the number of the first frame for an SPM series. If this variable does not exist, then uses 1. ----------------------------------------------------------------------*/ -int GetSPMStartFrame(void) { +int GetSPMStartFrame(void) +{ char *s; int startframe; s = getenv("SPM_START_FRAME"); @@ -5341,7 +5493,8 @@ int GetSPMStartFrame(void) { ppstem == NULL). Note: the files must actually exist. -------------------------------------------------------------------------*/ -int CountAnalyzeFiles(const char *analyzefname, int nzpad, char **ppstem) { +int CountAnalyzeFiles(const char *analyzefname, int nzpad, char **ppstem) +{ int len, ncopy; char *stem, fmt[1000], fname[1000]; int nfiles, keepcounting, startframe; @@ -5360,7 +5513,8 @@ int CountAnalyzeFiles(const char *analyzefname, int nzpad, char **ppstem) { " with zero pad variable.\n"); return (-1); } - } else { + } + else { ncopy = len; if (nzpad < 0) nfiles = 1; } @@ -5401,7 +5555,8 @@ int CountAnalyzeFiles(const char *analyzefname, int nzpad, char **ppstem) { return (nfiles); } /*-------------------------------------------------------------------------*/ -static int DumpAnalyzeHeader(FILE *fp, dsr *hdr) { +static int DumpAnalyzeHeader(FILE *fp, dsr *hdr) +{ fprintf(fp, "Header Key\n"); fprintf(fp, " sizeof_hdr %d\n", hdr->hk.sizeof_hdr); fprintf(fp, " data_type %s\n", hdr->hk.data_type); @@ -5442,7 +5597,8 @@ static int DumpAnalyzeHeader(FILE *fp, dsr *hdr) { return (0); } /*-------------------------------------------------------------------------*/ -static dsr *ReadAnalyzeHeader(const char *hdrfile, int *swap, int *mritype, int *bytes_per_voxel) { +static dsr *ReadAnalyzeHeader(const char *hdrfile, int *swap, int *mritype, int *bytes_per_voxel) +{ FILE *fp; dsr *hdr; @@ -5467,26 +5623,32 @@ static dsr *ReadAnalyzeHeader(const char *hdrfile, int *swap, int *mritype, int if (hdr->dime.datatype == DT_UNSIGNED_CHAR) { *mritype = MRI_UCHAR; *bytes_per_voxel = 1; - } else if (hdr->dime.datatype == DT_SIGNED_SHORT) { + } + else if (hdr->dime.datatype == DT_SIGNED_SHORT) { *mritype = MRI_SHORT; *bytes_per_voxel = 2; - } else if (hdr->dime.datatype == DT_UINT16) { + } + else if (hdr->dime.datatype == DT_UINT16) { // Can happen if this is nifti printf( "Unsigned short not supported, but trying to read it \n" "in as a signed short. Will be ok if no vals >= 32k.\n"); *mritype = MRI_SHORT; *bytes_per_voxel = 2; - } else if (hdr->dime.datatype == DT_SIGNED_INT) { + } + else if (hdr->dime.datatype == DT_SIGNED_INT) { *mritype = MRI_INT; *bytes_per_voxel = 4; - } else if (hdr->dime.datatype == DT_FLOAT) { + } + else if (hdr->dime.datatype == DT_FLOAT) { *mritype = MRI_FLOAT; *bytes_per_voxel = 4; - } else if (hdr->dime.datatype == DT_DOUBLE) { + } + else if (hdr->dime.datatype == DT_DOUBLE) { *mritype = MRI_FLOAT; *bytes_per_voxel = 8; - } else { + } + else { free(hdr); errno = 0; ErrorReturn(NULL, @@ -5503,7 +5665,8 @@ static dsr *ReadAnalyzeHeader(const char *hdrfile, int *swap, int *mritype, int analyzeRead() - see the end of file for the old (pre-10/11/01) analyzeRead(). The fname can take one of several forms. -------------------------------------------------------------------------*/ -static MRI *analyzeRead(const char *fname, int read_volume) { +static MRI *analyzeRead(const char *fname, int read_volume) +{ extern int N_Zero_Pad_Input; int nfiles, k, nread; char *stem; @@ -5543,7 +5706,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { sprintf(hdrfile, fmt, startframe, "hdr"); sprintf(matfile, fmt, startframe, "mat"); sprintf(imgfile, fmt, startframe, "img"); - } else { + } + else { sprintf(hdrfile, "%s.hdr", stem); sprintf(matfile, "%s.mat", stem); sprintf(imgfile, "%s.img", stem); @@ -5580,7 +5744,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { if (nfiles == 1) { nframes = hdr->dime.dim[4]; if (nframes == 0) nframes = 1; - } else + } + else nframes = nfiles; ncols = hdr->dime.dim[1]; @@ -5628,7 +5793,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { printf(" may not be matlab4 mat file ... proceeding without it.\n"); fflush(stdout); cantreadmatfile = 1; - } else { + } + else { /* Convert from 1-based to 0-based */ Q = MtxCRS1toCRS0(Q); T = MatrixMultiply(T1, Q, T); @@ -5671,7 +5837,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { T->rptr[2][4] = -mri->ysize * (mri->height / 2.0); T->rptr[3][4] = -mri->zsize * (mri->depth / 2.0); T->rptr[4][4] = 1.; - } else if (hdr->hist.orient == 1) /* x = -r, y = s, z = a */ + } + else if (hdr->hist.orient == 1) /* x = -r, y = s, z = a */ { strcpy(direction, "coronal unflipped"); T = MatrixAlloc(4, 4, MATRIX_REAL); @@ -5682,7 +5849,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { T->rptr[2][4] = -mri->zsize * (mri->depth / 2.0); T->rptr[3][4] = -mri->ysize * (mri->height / 2.0); T->rptr[4][4] = 1.; - } else if (hdr->hist.orient == 2) /* x = a, y = s, z = -r */ + } + else if (hdr->hist.orient == 2) /* x = a, y = s, z = -r */ { strcpy(direction, "sagittal unflipped"); T = MatrixAlloc(4, 4, MATRIX_REAL); @@ -5693,7 +5861,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { T->rptr[2][4] = -mri->xsize * (mri->width / 2.0); T->rptr[3][4] = -mri->ysize * (mri->height / 2.0); T->rptr[4][4] = 1.; - } else if (hdr->hist.orient == 3) /* x = -r, y = -a, z = s */ + } + else if (hdr->hist.orient == 3) /* x = -r, y = -a, z = s */ { strcpy(direction, "transverse flipped"); T = MatrixAlloc(4, 4, MATRIX_REAL); @@ -5704,7 +5873,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { T->rptr[2][4] = mri->ysize * (mri->height / 2.0); T->rptr[3][4] = -mri->zsize * (mri->depth / 2.0); T->rptr[4][4] = 1.; - } else if (hdr->hist.orient == 4) /* x = -r, y = -s, z = a */ + } + else if (hdr->hist.orient == 4) /* x = -r, y = -s, z = a */ { strcpy(direction, "coronal flipped"); T = MatrixAlloc(4, 4, MATRIX_REAL); @@ -5715,7 +5885,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { T->rptr[2][4] = -mri->zsize * (mri->depth / 2.0); T->rptr[3][4] = mri->ysize * (mri->height / 2.0); T->rptr[4][4] = 1.; - } else if (hdr->hist.orient == 5) /* x = a, y = -s, z = -r */ + } + else if (hdr->hist.orient == 5) /* x = a, y = -s, z = -r */ { strcpy(direction, "sagittal flipped"); T = MatrixAlloc(4, 4, MATRIX_REAL); @@ -5748,7 +5919,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { "WARNING: assuming %s\n", matfile, direction); - } else { + } + else { // It's probably not a good idea to set this to 1, but setting it // to 0 created all kinds of problems with mghRead() which will // force dir cos to be Coronal if rasgood<0. @@ -5765,7 +5937,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { matfile); } } - } else { + } + else { // Just read in this one file as nifti to get vox2ras matrix // What a hack. mritmp = MRIreadHeader(imgfile, NIFTI1_FILE); @@ -5882,7 +6055,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { for (width = 0; width < mri->width; width++) { MRIFvox(mri, width, row, slice) = (float)*dp++; } - } else { + } + else { /*copy*/ memmove(mri->slices[k][row], buf, bytes_per_voxel * mri->width); } @@ -5933,7 +6107,8 @@ static MRI *analyzeRead(const char *fname, int read_volume) { series can be saved from mri_convert by specifying the basename and adding "--out_type spm". See also analyzeWrite4D(). DNG ---------------------------------------------------------------*/ -static int analyzeWrite(MRI *mri, const char *fname) { +static int analyzeWrite(MRI *mri, const char *fname) +{ int len; int error_value; @@ -5955,14 +6130,16 @@ static int analyzeWrite(MRI *mri, const char *fname) { by DNG to be able to save a particular frame so that it could be used to write out an entire series. ---------------------------------------------------------------*/ -static void printDirCos(MRI *mri) { +static void printDirCos(MRI *mri) +{ fprintf(stderr, "Direction cosines for %s are:\n", mri->fname); fprintf(stderr, " x_r = %8.4f, y_r = %8.4f, z_r = %8.4f, c_r = %10.4f\n", mri->x_r, mri->y_r, mri->z_r, mri->c_r); fprintf(stderr, " x_a = %8.4f, y_a = %8.4f, z_a = %8.4f, c_a = %10.4f\n", mri->x_a, mri->y_a, mri->z_a, mri->c_a); fprintf(stderr, " x_s = %8.4f, y_s = %8.4f, z_s = %8.4f, c_s = %10.4f\n", mri->x_s, mri->y_s, mri->z_s, mri->c_s); } -static int analyzeWriteFrame(MRI *mri, const char *fname, int frame) { +static int analyzeWriteFrame(MRI *mri, const char *fname, int frame) +{ dsr hdr; float max, min, det; MATRIX *T, *invT; @@ -6043,7 +6220,8 @@ static int analyzeWriteFrame(MRI *mri, const char *fname, int frame) { if (mri->type == MRI_UCHAR) { hdr.dime.datatype = DT_UNSIGNED_CHAR; bytes_per_voxel = 1; - } else if (mri->type == MRI_SHORT) { + } + else if (mri->type == MRI_SHORT) { hdr.dime.datatype = DT_SIGNED_SHORT; bytes_per_voxel = 2; } @@ -6051,10 +6229,12 @@ static int analyzeWriteFrame(MRI *mri, const char *fname, int frame) { else if (mri->type == MRI_INT || mri->type == MRI_LONG) { hdr.dime.datatype = DT_SIGNED_INT; bytes_per_voxel = 4; - } else if (mri->type == MRI_FLOAT) { + } + else if (mri->type == MRI_FLOAT) { hdr.dime.datatype = DT_FLOAT; bytes_per_voxel = 4; - } else { + } + else { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "analyzeWriteFrame(): bad data type %d", mri->type)); } @@ -6209,7 +6389,8 @@ static int analyzeWriteFrame(MRI *mri, const char *fname, int frame) { } /* end analyzeWriteFrame() */ /*-------------------------------------------------------------*/ -static int analyzeWriteSeries(MRI *mri, const char *fname) { +static int analyzeWriteSeries(MRI *mri, const char *fname) +{ extern int N_Zero_Pad_Output; int frame; int err; @@ -6244,7 +6425,8 @@ static int analyzeWriteSeries(MRI *mri, const char *fname) { /*--------------------------------------------------------------- analyzeWrite4D() - saves data in analyze 4D format. ---------------------------------------------------------------*/ -static int analyzeWrite4D(MRI *mri, const char *fname) { +static int analyzeWrite4D(MRI *mri, const char *fname) +{ dsr hdr; float max, min, det; MATRIX *T, *invT; @@ -6310,7 +6492,8 @@ static int analyzeWrite4D(MRI *mri, const char *fname) { if (mri->type == MRI_UCHAR) { hdr.dime.datatype = DT_UNSIGNED_CHAR; bytes_per_voxel = 1; - } else if (mri->type == MRI_SHORT) { + } + else if (mri->type == MRI_SHORT) { hdr.dime.datatype = DT_SIGNED_SHORT; bytes_per_voxel = 2; } @@ -6318,10 +6501,12 @@ static int analyzeWrite4D(MRI *mri, const char *fname) { else if (mri->type == MRI_INT || mri->type == MRI_LONG) { hdr.dime.datatype = DT_SIGNED_INT; bytes_per_voxel = 4; - } else if (mri->type == MRI_FLOAT) { + } + else if (mri->type == MRI_FLOAT) { hdr.dime.datatype = DT_FLOAT; bytes_per_voxel = 4; - } else { + } + else { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "analyzeWrite4D(): bad data type %d", mri->type)); } @@ -6451,7 +6636,8 @@ static int analyzeWrite4D(MRI *mri, const char *fname) { } /* end analyzeWrite4D() */ /*-------------------------------------------------------------*/ -static void swap_analyze_header(dsr *hdr) { +static void swap_analyze_header(dsr *hdr) +{ int i; char c; @@ -6664,7 +6850,8 @@ static int center_voxel_to_voxel_center(MRI *mri, float x, float y, float z) } /* end center_voxel_to_voxel_center() */ #endif // if 0 -static MRI *gdfRead(const char *fname, int read_volume) { +static MRI *gdfRead(const char *fname, int read_volume) +{ MRI *mri; FILE *fp; char line[STRLEN]; @@ -6712,46 +6899,60 @@ static MRI *gdfRead(const char *fname, int read_volume) { if (strncmp(line, "IMAGE_FILE_PATH", 15) == 0) { sscanf(line, "%*s %s", file_path); path_d = TRUE; - } else if (strncmp(line, "IP_RES", 6) == 0) { + } + else if (strncmp(line, "IP_RES", 6) == 0) { sscanf(line, "%*s %f %f", &ipr[0], &ipr[1]); ipr_d = TRUE; - } else if (strncmp(line, "SL_THICK", 8) == 0) { + } + else if (strncmp(line, "SL_THICK", 8) == 0) { sscanf(line, "%*s %f", &st); st_d = TRUE; - } else if (strncmp(line, "UNITS", 5) == 0) { + } + else if (strncmp(line, "UNITS", 5) == 0) { sscanf(line, "%*s %s", units_string); u_d = TRUE; - } else if (strncmp(line, "SIZE", 4) == 0) { + } + else if (strncmp(line, "SIZE", 4) == 0) { sscanf(line, "%*s %d %d", &size[0], &size[1]); s_d = TRUE; - } else if (strncmp(line, "FS_X_RAS", 8) == 0) { + } + else if (strncmp(line, "FS_X_RAS", 8) == 0) { sscanf(line, "%*s %f %f %f", &x_r, &x_a, &x_s); x_ras_d = TRUE; - } else if (strncmp(line, "FS_Y_RAS", 8) == 0) { + } + else if (strncmp(line, "FS_Y_RAS", 8) == 0) { sscanf(line, "%*s %f %f %f", &y_r, &y_a, &y_s); y_ras_d = TRUE; - } else if (strncmp(line, "FS_Z_RAS", 8) == 0) { + } + else if (strncmp(line, "FS_Z_RAS", 8) == 0) { sscanf(line, "%*s %f %f %f", &z_r, &z_a, &z_s); z_ras_d = TRUE; - } else if (strncmp(line, "FS_C_RAS", 8) == 0) { + } + else if (strncmp(line, "FS_C_RAS", 8) == 0) { sscanf(line, "%*s %f %f %f", &c_r, &c_a, &c_s); c_ras_d = TRUE; - } else if (strncmp(line, "DATA_TYPE", 9) == 0) { + } + else if (strncmp(line, "DATA_TYPE", 9) == 0) { strcpy(data_type_string, &line[10]); dt_d = TRUE; - } else if (strncmp(line, "ORIENTATION", 11) == 0) { + } + else if (strncmp(line, "ORIENTATION", 11) == 0) { sscanf(line, "%*s %s", orientation_string); strcpy(os_orig, orientation_string); o_d = TRUE; - } else if (strncmp(line, "FILE_OFFSET", 11) == 0) { + } + else if (strncmp(line, "FILE_OFFSET", 11) == 0) { sscanf(line, "%*s %d", &file_offset); - } else if (strncmp(line, "MIN_CROP", 8) == 0) { + } + else if (strncmp(line, "MIN_CROP", 8) == 0) { sscanf(line, "%*s %f %f %f", &min_crop[0], &min_crop[1], &min_crop[2]); have_min_crop = TRUE; - } else if (strncmp(line, "MAX_CROP", 8) == 0) { + } + else if (strncmp(line, "MAX_CROP", 8) == 0) { sscanf(line, "%*s %f %f %f", &max_crop[0], &max_crop[1], &max_crop[2]); have_max_crop = TRUE; - } else { + } + else { } } @@ -6773,7 +6974,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { "missing field ORIENTATION in file %s, " "but you've got {xyz}_{ras}, so never mind\n", fname); - } else { + } + else { printf("missing field ORIENTATION in file %s; assuming 'coronal'\n", fname); sprintf(orientation_string, "coronal"); } @@ -6933,7 +7135,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { mri->z_a = z_a; mri->z_s = z_s; mri->ras_good_flag = TRUE; - } else { + } + else { /* direction cosine is not set. we pick a particular kind of direction cosine. If the volume is different you have @@ -6951,7 +7154,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { mri->c_r = c_r; mri->c_a = c_a; mri->c_s = c_s; - } else { + } + else { mri->c_r = mri->c_a = mri->c_s = 0.0; printf("warning: gdf volume may be incorrectly centered\n"); } @@ -6965,7 +7169,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { errno = 0; ErrorReturn(NULL, (ERROR_NOMEMORY, "gdfRead(): error allocating %d bytes for read buffer", mri->width)); } - } else if (mri->type == MRI_SHORT) { + } + else if (mri->type == MRI_SHORT) { sbuf = (short *)malloc(mri->width * sizeof(short)); if (sbuf == NULL) { MRIfree(&mri); @@ -6973,7 +7178,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { ErrorReturn(NULL, (ERROR_NOMEMORY, "gdfRead(): error allocating %d bytes for read buffer", mri->width * sizeof(short))); } - } else if (mri->type == MRI_FLOAT) { + } + else if (mri->type == MRI_FLOAT) { fbuf = (float *)malloc(mri->width * sizeof(float)); if (fbuf == NULL) { MRIfree(&mri); @@ -6981,7 +7187,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { ErrorReturn(NULL, (ERROR_NOMEMORY, "gdfRead(): error allocating %d bytes for read buffer", mri->width * sizeof(float))); } - } else { + } + else { MRIfree(&mri); errno = 0; ErrorReturn(NULL, @@ -7090,7 +7297,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { } } } - } else { + } + else { printf("NOTICE: not cropping GDF data\n"); } @@ -7098,7 +7306,8 @@ static MRI *gdfRead(const char *fname, int read_volume) { } /* end gdfRead() */ -static int gdfWrite(MRI *mri, const char *fname) { +static int gdfWrite(MRI *mri, const char *fname) +{ FILE *fp; int i, j; char im_fname[STRLEN]; @@ -7224,7 +7433,8 @@ static int parc_fill(short label_value, short seed_x, short seed_y) } /* end parc_fill() */ #endif -static int register_unknown_label(const char *label) { +static int register_unknown_label(const char *label) +{ int i; if (n_unknown_labels == MAX_UNKNOWN_LABELS) return (NO_ERROR); @@ -7240,14 +7450,16 @@ static int register_unknown_label(const char *label) { } /* end register_unknown_label() */ -static int clear_unknown_labels(void) { +static int clear_unknown_labels(void) +{ n_unknown_labels = 0; return (NO_ERROR); } /* end clear_unknown_labels() */ -static int print_unknown_labels(const char *prefix) { +static int print_unknown_labels(const char *prefix) +{ int i; for (i = 0; i < n_unknown_labels; i++) printf("%s%s\n", prefix, unknown_labels[i]); @@ -7257,7 +7469,8 @@ static int print_unknown_labels(const char *prefix) { } /* end print_unknown_labels() */ static int read_otl_file( - FILE *fp, MRI *mri, int slice, COLOR_TABLE *ctab, int fill_flag, int translate_label_flag, int zero_outlines_flag) { + FILE *fp, MRI *mri, int slice, COLOR_TABLE *ctab, int fill_flag, int translate_label_flag, int zero_outlines_flag) +{ int n_outlines = -1; int n_rows, n_cols; char label[STRLEN], label_to_compare[STRLEN]; @@ -7397,7 +7610,8 @@ static int read_otl_file( label, slice); internal_structures_flag = FALSE; - } else + } + else internal_structures_flag = TRUE; } } @@ -7436,7 +7650,8 @@ static int read_otl_file( CMAfreeOutlineField(&of); errno = 0; ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "undefined TYPE in otl file %d", slice)); - } else { + } + else { CMAfreeOutlineField(&of); errno = 0; ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "unsupported TYPE \"%s\" in otl file %d", type, slice)); @@ -7473,7 +7688,8 @@ static int read_otl_file( } sscanf(line, "%hd %hd", &(points[2 * row]), &(points[2 * row + 1])); } - } else { + } + else { n_read = fread(points, 2, n_rows * 2, fp); if (n_read != n_rows * 2) { free(points); @@ -7533,7 +7749,8 @@ static int read_otl_file( if (j < 0) /* all dashes! */ { /* for now, let this fall through to an unknown label */ - } else /* j is the index of the last non-dash character */ + } + else /* j is the index of the last non-dash character */ { label_to_compare[j + 1] = '\0'; } @@ -7552,7 +7769,8 @@ static int read_otl_file( if (label_value == -1) { register_unknown_label(label); - } else { + } + else { for (j = 0; j < n_rows; j++) cma_field[points[2 * j]][points[2 * j + 1]] = label_value; CMAclaimPoints(of, label_value, points, n_rows, seed_x, seed_y); @@ -7586,7 +7804,8 @@ static int read_otl_file( } /* end read_otl_file() */ -int list_labels_in_otl_file(FILE *fp) { +int list_labels_in_otl_file(FILE *fp) +{ char line[STRLEN]; int main_header_flag; int n_outlines = -1; @@ -7722,7 +7941,8 @@ int list_labels_in_otl_file(FILE *fp) { else if (type[0] == '\0') { errno = 0; ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "undefined TYPE in otl file")); - } else { + } + else { errno = 0; ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "unsupported TYPE \"%s\" in otl file", type)); } @@ -7754,7 +7974,8 @@ int list_labels_in_otl_file(FILE *fp) { } sscanf(line, "%hd %hd", &(points[2 * row]), &(points[2 * row + 1])); } - } else { + } + else { n_read = fread(points, 2, n_rows * 2, fp); if (n_read != n_rows * 2) { free(points); @@ -7787,7 +8008,8 @@ int list_labels_in_otl_file(FILE *fp) { } /* end list_labels_in_otl_file() */ -MRI *MRIreadOtl(const char *fname, int width, int height, int slices, const char *color_file_name, int flags) { +MRI *MRIreadOtl(const char *fname, int width, int height, int slices, const char *color_file_name, int flags) +{ char stem[STRLEN]; int i; MRI *mri; @@ -7902,7 +8124,8 @@ MRI *MRIreadOtl(const char *fname, int width, int height, int slices, const char if (n_unknown_labels == 0) { printf("no unknown labels\n"); - } else { + } + else { printf("unknown labels:\n"); print_unknown_labels(" "); } @@ -7919,7 +8142,8 @@ MRI *MRIreadOtl(const char *fname, int width, int height, int slices, const char #define XIMG_PIXEL_DATA_OFFSET 8432 #define XIMG_IMAGE_HEADER_OFFSET 2308 -static MRI *ximgRead(const char *fname, int read_volume) { +static MRI *ximgRead(const char *fname, int read_volume) +{ char fname_format[STRLEN]; char fname_dir[STRLEN]; char fname_base[STRLEN]; @@ -7957,7 +8181,8 @@ static MRI *ximgRead(const char *fname, int read_volume) { if (c == NULL) { fname_dir[0] = '\0'; strcpy(fname_base, fname); - } else { + } + else { strncpy(fname_dir, fname, (c - fname + 1)); fname_dir[c - fname + 1] = '\0'; strcpy(fname_base, c + 1); @@ -7967,7 +8192,8 @@ static MRI *ximgRead(const char *fname, int read_volume) { if (strncmp(fname_base, "I.", 2) == 0) { im_init = atoi(&fname_base[2]); sprintf(fname_format, "I.%%03d"); - } else if (strlen(fname_base) >= 3) /* avoid core dumps below... */ + } + else if (strlen(fname_base) >= 3) /* avoid core dumps below... */ { c = &fname_base[strlen(fname_base) - 3]; if (strcmp(c, ".MR") == 0) { @@ -7978,11 +8204,13 @@ static MRI *ximgRead(const char *fname, int read_volume) { im_init = atoi(c); *c = '\0'; sprintf(fname_format, "%s%%d.MR", fname_base); - } else { + } + else { errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "genesisRead(): can't determine file name format for %s", fname)); } - } else { + } + else { errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "genesisRead(): can't determine file name format for %s", fname)); } @@ -8206,7 +8434,8 @@ static MRI *ximgRead(const char *fname, int read_volume) { MRISreadCurvAsMRI() - reads freesurfer surface curv format as an MRI. -----------------------------------------------------------*/ -static MRI *MRISreadCurvAsMRI(const char *curvfile, int read_volume) { +static MRI *MRISreadCurvAsMRI(const char *curvfile, int read_volume) +{ int magno, k, vnum, fnum, vals_per_vertex; float curv; FILE *fp; @@ -8250,7 +8479,8 @@ static MRI *MRISreadCurvAsMRI(const char *curvfile, int read_volume) { Automatically detects whether an input is Ico7 and reshapes. -----------------------------------------------------------------*/ -static MRI *nifti1Read(const char *fname, int read_volume) { +static MRI *nifti1Read(const char *fname, int read_volume) +{ char hdr_fname[STRLEN]; char img_fname[STRLEN]; char fname_stem[STRLEN]; @@ -8316,7 +8546,8 @@ static MRI *nifti1Read(const char *fname, int read_volume) { else if (space_units == NIFTI_UNITS_UNKNOWN) { printf("nifti1Read(): NIFTI_UNITS_UNKNOWN, assuming mm\n"); space_units_factor = 1.0; - } else { + } + else { ErrorReturn(NULL, (ERROR_BADFILE, "nifti1Read(): unknown space units %d in %s", space_units, hdr_fname)); } @@ -8330,7 +8561,8 @@ static MRI *nifti1Read(const char *fname, int read_volume) { else { if (hdr.dim[4] > 1) { ErrorReturn(NULL, (ERROR_BADFILE, "nifti1Read(): unknown time units %d in %s", time_units, hdr_fname)); - } else + } + else time_units_factor = 0; } @@ -8354,22 +8586,27 @@ static MRI *nifti1Read(const char *fname, int read_volume) { if (hdr.datatype == DT_UNSIGNED_CHAR) { fs_type = MRI_UCHAR; bytes_per_voxel = 1; - } else if (hdr.datatype == DT_SIGNED_SHORT) { + } + else if (hdr.datatype == DT_SIGNED_SHORT) { fs_type = MRI_SHORT; bytes_per_voxel = 2; - } else if (hdr.datatype == DT_UINT16) { + } + else if (hdr.datatype == DT_UINT16) { // This will not always work ... printf("INFO: this is an unsiged short. I'll try to read it, but\n"); printf(" it might not work if there are values over 32k\n"); fs_type = MRI_SHORT; bytes_per_voxel = 2; - } else if (hdr.datatype == DT_SIGNED_INT) { + } + else if (hdr.datatype == DT_SIGNED_INT) { fs_type = MRI_INT; bytes_per_voxel = 4; - } else if (hdr.datatype == DT_FLOAT) { + } + else if (hdr.datatype == DT_FLOAT) { fs_type = MRI_FLOAT; bytes_per_voxel = 4; - } else { + } + else { ErrorReturn(NULL, (ERROR_UNSUPPORTED, "nifti1Read(): unsupported datatype %d " @@ -8377,7 +8614,8 @@ static MRI *nifti1Read(const char *fname, int read_volume) { hdr.datatype, hdr_fname)); } - } else // we must scale the voxel values + } + else // we must scale the voxel values { if (hdr.datatype != DT_UNSIGNED_CHAR && hdr.datatype != DT_SIGNED_SHORT && hdr.datatype != DT_SIGNED_INT && hdr.datatype != DT_FLOAT && hdr.datatype != DT_DOUBLE && hdr.datatype != DT_INT8 && hdr.datatype != DT_UINT16 && @@ -8431,7 +8669,8 @@ static MRI *nifti1Read(const char *fname, int read_volume) { return (NULL); } mri->ras_good_flag = 1; - } else if (hdr.qform_code != 0) { + } + else if (hdr.qform_code != 0) { // Then, try the qform, if that is ok fprintf(stderr, "INFO: using NIfTI-1 qform \n"); if (niftiQformToMri(mri, &hdr) != NO_ERROR) { @@ -8439,7 +8678,8 @@ static MRI *nifti1Read(const char *fname, int read_volume) { return (NULL); } mri->ras_good_flag = 1; - } else { + } + else { // Should probably just die here. printf("WARNING: neither NIfTI-1 qform or sform are valid\n"); printf("WARNING: your volume will probably be incorrectly oriented\n"); @@ -8499,7 +8739,8 @@ static MRI *nifti1Read(const char *fname, int read_volume) { } exec_progress_callback(k, mri->depth, t, mri->nframes); } - } else // voxel value scaling needed + } + else // voxel value scaling needed { if (hdr.datatype == DT_UNSIGNED_CHAR) { unsigned char *buf; @@ -8725,7 +8966,8 @@ static MRI *nifti1Read(const char *fname, int read_volume) { edit both. Automatically detects whether an input is Ico7 and reshapes. -----------------------------------------------------------------*/ -static int nifti1Write(MRI *mri0, const char *fname) { +static int nifti1Write(MRI *mri0, const char *fname) +{ FILE *fp; int j, k, t; BUFTYPE *buf; @@ -8744,7 +8986,8 @@ static int nifti1Write(MRI *mri0, const char *fname) { // printf("nifit1Write: reshaping\n"); mri = mri_reshape(mri0, 27307, 1, 6, mri0->nframes); FreeMRI = 1; - } else + } + else mri = mri0; shortmax = (int)(pow(2.0, 15.0)); @@ -8800,23 +9043,30 @@ static int nifti1Write(MRI *mri0, const char *fname) { if (mri->type == MRI_UCHAR) { hdr.datatype = DT_UNSIGNED_CHAR; hdr.bitpix = 8; - } else if (mri->type == MRI_INT) { + } + else if (mri->type == MRI_INT) { hdr.datatype = DT_SIGNED_INT; hdr.bitpix = 32; - } else if (mri->type == MRI_LONG) { + } + else if (mri->type == MRI_LONG) { hdr.datatype = DT_SIGNED_INT; hdr.bitpix = 32; - } else if (mri->type == MRI_FLOAT) { + } + else if (mri->type == MRI_FLOAT) { hdr.datatype = DT_FLOAT; hdr.bitpix = 32; - } else if (mri->type == MRI_SHORT) { + } + else if (mri->type == MRI_SHORT) { hdr.datatype = DT_SIGNED_SHORT; hdr.bitpix = 16; - } else if (mri->type == MRI_BITMAP) { + } + else if (mri->type == MRI_BITMAP) { ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "nifti1Write(): data type MRI_BITMAP unsupported")); - } else if (mri->type == MRI_TENSOR) { + } + else if (mri->type == MRI_TENSOR) { ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "nifti1Write(): data type MRI_TENSOR unsupported")); - } else { + } + else { ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "nifti1Write(): unknown data type %d", mri->type)); } @@ -8894,7 +9144,8 @@ static int nifti1Write(MRI *mri0, const char *fname) { edit both. Automatically detects whether an input is Ico7 and reshapes. -----------------------------------------------------------------*/ -static MRI *niiRead(const char *fname, int read_volume) { +static MRI *niiRead(const char *fname, int read_volume) +{ znzFile fp; MRI *mri, *mritmp; struct nifti_1_header hdr; @@ -8962,7 +9213,8 @@ static MRI *niiRead(const char *fname, int read_volume) { else if (space_units == NIFTI_UNITS_UNKNOWN) { printf("niiRead(): NIFTI_UNITS_UNKNOWN, assuming mm\n"); space_units_factor = 1.0; - } else + } + else ErrorReturn(NULL, (ERROR_BADFILE, "niiRead(): unknown space units %d in %s", space_units, fname)); time_units = XYZT_TO_TIME(hdr.xyzt_units); @@ -9011,31 +9263,38 @@ static MRI *niiRead(const char *fname, int read_volume) { if (hdr.datatype == DT_UNSIGNED_CHAR) { fs_type = MRI_UCHAR; bytes_per_voxel = 1; - } else if (hdr.datatype == DT_SIGNED_SHORT) { + } + else if (hdr.datatype == DT_SIGNED_SHORT) { fs_type = MRI_SHORT; bytes_per_voxel = 2; - } else if (hdr.datatype == DT_UINT16) { + } + else if (hdr.datatype == DT_UINT16) { // This will not always work ... printf("INFO: this is an unsiged short. I'll try to read it, but\n"); printf(" it might not work if there are values over 32k\n"); fs_type = MRI_SHORT; bytes_per_voxel = 2; - } else if (hdr.datatype == DT_SIGNED_INT) { + } + else if (hdr.datatype == DT_SIGNED_INT) { fs_type = MRI_INT; bytes_per_voxel = 4; - } else if (hdr.datatype == DT_FLOAT) { + } + else if (hdr.datatype == DT_FLOAT) { fs_type = MRI_FLOAT; bytes_per_voxel = 4; - } else if (hdr.datatype == DT_DOUBLE) { + } + else if (hdr.datatype == DT_DOUBLE) { fs_type = MRI_FLOAT; bytes_per_voxel = 8; printf("niiRead(): detected input as 64 bit double, reading in as 32 bit float\n"); - } else { + } + else { ErrorReturn( NULL, (ERROR_UNSUPPORTED, "niiRead(): unsupported datatype %d (with scl_slope = 0) in %s", hdr.datatype, fname)); } - } else { + } + else { // we must scale the voxel values if (hdr.datatype != DT_UNSIGNED_CHAR && hdr.datatype != DT_SIGNED_SHORT && hdr.datatype != DT_SIGNED_INT && hdr.datatype != DT_FLOAT && hdr.datatype != DT_DOUBLE && hdr.datatype != DT_INT8 && hdr.datatype != DT_UINT16 && @@ -9084,7 +9343,8 @@ static MRI *niiRead(const char *fname, int read_volume) { return (NULL); } mri->ras_good_flag = 1; - } else if (hdr.qform_code != 0) { + } + else if (hdr.qform_code != 0) { // Then, try the qform, if that is ok fprintf(stderr, "INFO: using NIfTI-1 qform \n"); if (niftiQformToMri(mri, &hdr) != NO_ERROR) { @@ -9092,7 +9352,8 @@ static MRI *niiRead(const char *fname, int read_volume) { return (NULL); } mri->ras_good_flag = 1; - } else { + } + else { // Should probably just die here. fprintf(stderr, "WARNING: neither NIfTI-1 qform or sform are valid\n"); fprintf(stderr, "WARNING: your volume will probably be incorrectly oriented\n"); @@ -9190,7 +9451,8 @@ static MRI *niiRead(const char *fname, int read_volume) { } free(fbuf); free(dbuf); - } else { + } + else { // voxel value scaling needed if (hdr.datatype == DT_UNSIGNED_CHAR) { unsigned char *buf; @@ -9415,7 +9677,8 @@ static MRI *niiRead(const char *fname, int read_volume) { edit both. Automatically detects whether an input is Ico7 and reshapes. -----------------------------------------------------------------*/ -static int niiWrite(MRI *mri0, const char *fname) { +static int niiWrite(MRI *mri0, const char *fname) +{ znzFile fp; int j, k, t; BUFTYPE *buf; @@ -9437,7 +9700,8 @@ static int niiWrite(MRI *mri0, const char *fname) { // printf("niiWrite: reshaping\n"); mri = mri_reshape(mri0, 27307, 1, 6, mri0->nframes); FreeMRI = 1; - } else + } + else mri = mri0; shortmax = (int)(pow(2.0, 15.0)); @@ -9496,23 +9760,30 @@ static int niiWrite(MRI *mri0, const char *fname) { if (mri->type == MRI_UCHAR) { hdr.datatype = DT_UNSIGNED_CHAR; hdr.bitpix = 8; - } else if (mri->type == MRI_INT) { + } + else if (mri->type == MRI_INT) { hdr.datatype = DT_SIGNED_INT; hdr.bitpix = 32; - } else if (mri->type == MRI_LONG) { + } + else if (mri->type == MRI_LONG) { hdr.datatype = DT_SIGNED_INT; hdr.bitpix = 32; - } else if (mri->type == MRI_FLOAT) { + } + else if (mri->type == MRI_FLOAT) { hdr.datatype = DT_FLOAT; hdr.bitpix = 32; - } else if (mri->type == MRI_SHORT) { + } + else if (mri->type == MRI_SHORT) { hdr.datatype = DT_SIGNED_SHORT; hdr.bitpix = 16; - } else if (mri->type == MRI_BITMAP) { + } + else if (mri->type == MRI_BITMAP) { ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "niiWrite(): data type MRI_BITMAP unsupported")); - } else if (mri->type == MRI_TENSOR) { + } + else if (mri->type == MRI_TENSOR) { ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "niiWrite(): data type MRI_TENSOR unsupported")); - } else { + } + else { ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "niiWrite(): unknown data type %d", mri->type)); } @@ -9589,7 +9860,8 @@ static int niiWrite(MRI *mri0, const char *fname) { /*------------------------------------------------------------------ itkMorphWrite() -----------------------------------------------------------------*/ -static int itkMorphWrite(MRI *mri, const char *fname) { +static int itkMorphWrite(MRI *mri, const char *fname) +{ znzFile fp; int j, k, t; BUFTYPE *buf; @@ -9643,7 +9915,8 @@ static int itkMorphWrite(MRI *mri, const char *fname) { if (mri->type == MRI_FLOAT) { hdr.datatype = DT_FLOAT; hdr.bitpix = 32; - } else { + } + else { ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "itkMorphWrite(): unknown data type %d", mri->type)); } @@ -9713,7 +9986,8 @@ static int itkMorphWrite(MRI *mri, const char *fname) { } /* end itkMorphWrite() */ -static int niftiSformToMri(MRI *mri, struct nifti_1_header *hdr) { +static int niftiSformToMri(MRI *mri, struct nifti_1_header *hdr) +{ int err; MATRIX *sform; sform = MatrixConstVal(0, 4, 4, NULL); @@ -9740,7 +10014,8 @@ static int niftiSformToMri(MRI *mri, struct nifti_1_header *hdr) { return (err); } /* end niftiSformToMri() */ -static int niftiQformToMri(MRI *mri, struct nifti_1_header *hdr) { +static int niftiQformToMri(MRI *mri, struct nifti_1_header *hdr) +{ float a, b, c, d; float r11, r12, r13; float r21, r22, r23; @@ -9759,7 +10034,8 @@ static int niftiQformToMri(MRI *mri, struct nifti_1_header *hdr) { c *= a; d *= a; a = 0.0; - } else + } + else a = sqrt(a); r11 = a * a + b * b - c * c - d * d; @@ -9821,7 +10097,8 @@ static int niftiQformToMri(MRI *mri, struct nifti_1_header *hdr) { mriToNiftiSform() - just copies the vox2ras to sform and sets the xform code to scanner anat. ---------------------------------------------------------------------*/ -static int mriToNiftiSform(MRI *mri, struct nifti_1_header *hdr) { +static int mriToNiftiSform(MRI *mri, struct nifti_1_header *hdr) +{ MATRIX *vox2ras; int c; vox2ras = MRIxfmCRS2XYZ(mri, 0); @@ -9836,7 +10113,8 @@ static int mriToNiftiSform(MRI *mri, struct nifti_1_header *hdr) { } /*---------------------------------------------------------------------*/ -static int mriToNiftiQform(MRI *mri, struct nifti_1_header *hdr) { +static int mriToNiftiQform(MRI *mri, struct nifti_1_header *hdr) +{ MATRIX *i_to_r; float r11, r12, r13; float r21, r22, r23; @@ -9917,7 +10195,8 @@ static int mriToNiftiQform(MRI *mri, struct nifti_1_header *hdr) { "WARNING: bad orientation matrix (determinant = 0) " "in nifti1 file ...\n"); printf(" ... continuing.\n"); - } else if (r_det > 0.0) + } + else if (r_det > 0.0) qfac = 1.0; else { r13 = -r13; @@ -9935,7 +10214,8 @@ static int mriToNiftiQform(MRI *mri, struct nifti_1_header *hdr) { b = 0.25 * (r32 - r23) / a; c = 0.25 * (r13 - r31) / a; d = 0.25 * (r21 - r12) / a; - } else { + } + else { xd = 1.0 + r11 - (r22 + r33); yd = 1.0 + r22 - (r11 + r33); zd = 1.0 + r33 - (r11 + r22); @@ -9945,12 +10225,14 @@ static int mriToNiftiQform(MRI *mri, struct nifti_1_header *hdr) { c = 0.25 * (r12 + r21) / b; d = 0.25 * (r13 + r31) / b; a = 0.25 * (r32 - r23) / b; - } else if (yd > 1.0) { + } + else if (yd > 1.0) { c = 0.5 * sqrt(yd); b = 0.25 * (r12 + r21) / c; d = 0.25 * (r23 + r32) / c; a = 0.25 * (r13 - r31) / c; - } else { + } + else { d = 0.5 * sqrt(zd); b = 0.25 * (r13 + r31) / d; c = 0.25 * (r23 + r32) / d; @@ -9986,7 +10268,8 @@ static int mriToNiftiQform(MRI *mri, struct nifti_1_header *hdr) { } /* end mriToNiftiQform() */ -static void swap_nifti_1_header(struct nifti_1_header *hdr) { +static void swap_nifti_1_header(struct nifti_1_header *hdr) +{ int i; hdr->sizeof_hdr = swapInt(hdr->sizeof_hdr); @@ -10030,7 +10313,8 @@ static void swap_nifti_1_header(struct nifti_1_header *hdr) { } /* end swap_nifti_1_header */ -MRI *MRIreadGeRoi(const char *fname, int n_slices) { +MRI *MRIreadGeRoi(const char *fname, int n_slices) +{ MRI *mri; int i; char prefix[STRLEN], postfix[STRLEN]; @@ -10136,7 +10420,8 @@ MRI *MRIreadGeRoi(const char *fname, int n_slices) { static int data_size[] = {1, 4, 4, 4, 2}; -static MRI *sdtRead(const char *fname, int read_volume) { +static MRI *sdtRead(const char *fname, int read_volume) +{ char header_fname[STR_LEN]; char line[STR_LEN]; char *colon, *dot; @@ -10186,7 +10471,8 @@ static MRI *sdtRead(const char *fname, int read_volume) { fname, ndim)); } - } else if (strcmp(line, "dim") == 0) { + } + else if (strcmp(line, "dim") == 0) { if (ndim == -1) { fclose(fp); errno = 0; @@ -10196,7 +10482,8 @@ static MRI *sdtRead(const char *fname, int read_volume) { if (ndim == 3) { sscanf(colon, "%d %d %d", &dim[0], &dim[1], &dim[2]); dim[3] = 1; - } else { + } + else { sscanf(colon, "%d %d %d %d", &dim[0], &dim[1], &dim[2], &dim[3]); if (dim[3] != 1) { fclose(fp); @@ -10209,7 +10496,8 @@ static MRI *sdtRead(const char *fname, int read_volume) { dim[3])); } } - } else if (strcmp(line, "dataType") == 0) { + } + else if (strcmp(line, "dataType") == 0) { while (isspace((int)*colon)) colon++; if (strncmp(colon, "BYTE", 4) == 0) data_type = MRI_UCHAR; @@ -10223,12 +10511,14 @@ static MRI *sdtRead(const char *fname, int read_volume) { fclose(fp); errno = 0; ErrorReturn(NULL, (ERROR_UNSUPPORTED, "sdtRead(%s): unsupported data type '%s'\n", fname, colon)); - } else { + } + else { fclose(fp); errno = 0; ErrorReturn(NULL, (ERROR_BADFILE, "sdtRead(%s): unknown data type '%s'\n", fname, colon)); } - } else if (strcmp(line, "interval") == 0) { + } + else if (strcmp(line, "interval") == 0) { if (ndim == 3) sscanf(colon, "%f %f %f", &xsize, &ysize, &zsize); else @@ -10236,7 +10526,8 @@ static MRI *sdtRead(const char *fname, int read_volume) { xsize *= 10.0; ysize *= 10.0; zsize *= 10.0; - } else if (strcmp(line, "sdtOrient") == 0) { + } + else if (strcmp(line, "sdtOrient") == 0) { while (isspace((int)*colon)) colon++; if (strncmp(colon, "sag", 3) == 0) orientation = MRI_SAGITTAL; @@ -10249,7 +10540,8 @@ static MRI *sdtRead(const char *fname, int read_volume) { errno = 0; ErrorReturn(NULL, (ERROR_BADFILE, "sdtRead(%s): unknown orientation %s\n", fname, colon)); } - } else { + } + else { } } } @@ -10276,7 +10568,8 @@ static MRI *sdtRead(const char *fname, int read_volume) { if (mri == NULL) return (NULL); fclose(fp); - } else { + } + else { mri = MRIallocHeader(dim[0], dim[1], dim[2], data_type, dim[3]); if (mri == NULL) return (NULL); } @@ -10309,7 +10602,8 @@ static MRI *sdtRead(const char *fname, int read_volume) { } /* end sdtRead() */ -MRI *MRIreadRaw(FILE *fp, int width, int height, int depth, int type) { +MRI *MRIreadRaw(FILE *fp, int width, int height, int depth, int type) +{ MRI *mri; BUFTYPE *buf; int slice, pixels; @@ -10353,7 +10647,8 @@ MRI *MRIreadRaw(FILE *fp, int width, int height, int depth, int type) { return (mri); } -static void int_local_buffer_to_image(int *buf, MRI *mri, int slice, int frame) { +static void int_local_buffer_to_image(int *buf, MRI *mri, int slice, int frame) +{ int y, width, height; int *pslice; @@ -10483,7 +10778,8 @@ image_to_float_buffer(float *buf, MRI *mri, int slice) } #endif -static void long32_local_buffer_to_image(long32 *buf, MRI *mri, int slice, int frame) { +static void long32_local_buffer_to_image(long32 *buf, MRI *mri, int slice, int frame) +{ int y, width, height; long32 *pslice; @@ -10496,7 +10792,8 @@ static void long32_local_buffer_to_image(long32 *buf, MRI *mri, int slice, int f } } -static void float_local_buffer_to_image(float *buf, MRI *mri, int slice, int frame) { +static void float_local_buffer_to_image(float *buf, MRI *mri, int slice, int frame) +{ int y, width, height; float *pslice; @@ -10509,7 +10806,8 @@ static void float_local_buffer_to_image(float *buf, MRI *mri, int slice, int fra } } -static void short_local_buffer_to_image(short *buf, MRI *mri, int slice, int frame) { +static void short_local_buffer_to_image(short *buf, MRI *mri, int slice, int frame) +{ int y, width, height; short *pslice; @@ -10522,7 +10820,8 @@ static void short_local_buffer_to_image(short *buf, MRI *mri, int slice, int fra } } -static void local_buffer_to_image(BUFTYPE *buf, MRI *mri, int slice, int frame) { +static void local_buffer_to_image(BUFTYPE *buf, MRI *mri, int slice, int frame) +{ int y, width, height; BUFTYPE *pslice; @@ -10535,7 +10834,8 @@ static void local_buffer_to_image(BUFTYPE *buf, MRI *mri, int slice, int frame) } } -int znzTAGwriteMRIframes(znzFile fp, MRI *mri) { +int znzTAGwriteMRIframes(znzFile fp, MRI *mri) +{ long long len = 0, fstart, fend, here; int fno, i; MRI_FRAME *frame; @@ -10612,7 +10912,8 @@ int znzTAGwriteMRIframes(znzFile fp, MRI *mri) { return (NO_ERROR); } -int znzTAGreadMRIframes(znzFile fp, MRI *mri, long len) { +int znzTAGreadMRIframes(znzFile fp, MRI *mri, long len) +{ int fno, i; long long fstart, fend; MRI_FRAME *frame; @@ -10688,7 +10989,8 @@ int znzTAGreadMRIframes(znzFile fp, MRI *mri, long len) { // declare function pointer // static int (*myclose)(FILE *stream); -static MRI *mghRead(const char *fname, int read_volume, int frame) { +static MRI *mghRead(const char *fname, int read_volume, int frame) +{ MRI *mri; znzFile fp; int start_frame, end_frame, width, height, depth, nframes, type, x, y, z, bpv, dof, bytes, version, ival, @@ -10711,7 +11013,8 @@ static MRI *mghRead(const char *fname, int read_volume, int frame) { if (!stricmp(ext, "mgz") || strstr(fname, "mgh.gz")) { gzipped = 1; valid_ext = 1; - } else if (!stricmp(ext, "mgh")) { + } + else if (!stricmp(ext, "mgh")) { valid_ext = 1; } } @@ -10722,7 +11025,8 @@ static MRI *mghRead(const char *fname, int read_volume, int frame) { errno = 0; ErrorReturn(NULL, (ERROR_BADPARM, "mghRead(%s, %d): could not open file", fname, frame)); } - } else { + } + else { ErrorReturn(NULL, (ERROR_BADPARM, "mghRead(%s, %d): could not open file.\n" @@ -10805,21 +11109,25 @@ static MRI *mghRead(const char *fname, int read_volume, int frame) { total_bytes = (long)mri->nframes * width * height * depth * bpv; for (count = 0; count < total_bytes - STRLEN; count += STRLEN) znzread(buf, STRLEN, 1, fp); znzread(buf, total_bytes - count, 1, fp); - } else + } + else znzseek(fp, (long)mri->nframes * width * height * depth * bpv, SEEK_CUR); - } else { + } + else { if (frame >= 0) { start_frame = end_frame = frame; if (gzipped) { // pipe cannot seek long count; for (count = 0; count < (long)frame * width * height * depth * bpv; count++) znzgetc(fp); - } else + } + else znzseek(fp, (long)frame * width * height * depth * bpv, SEEK_CUR); nframes = 1; - } else { /* hack - # of frames < -1 means to only read in that - many frames. Otherwise I would have had to change the whole - MRIread interface and that was too much of a pain. Sorry. - */ + } + else { /* hack - # of frames < -1 means to only read in that + many frames. Otherwise I would have had to change the whole + MRIread interface and that was too much of a pain. Sorry. + */ if (frame < -1) nframes = frame * -1; start_frame = 0; @@ -10901,7 +11209,8 @@ static MRI *mghRead(const char *fname, int read_volume, int frame) { mri->c_a = c_a; mri->c_s = c_s; if (good_ras_flag > 0) mri->ras_good_flag = 1; - } else { + } + else { if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) fprintf(stderr, "-----------------------------------------------------------------\n" @@ -10966,7 +11275,8 @@ static MRI *mghRead(const char *fname, int read_volume, int frame) { mri->inverse_linear_transform = get_inverse_linear_transform_ptr(&mri->transform); mri->free_transform = 1; if (DIAG_VERBOSE_ON) fprintf(stderr, "INFO: loaded talairach xform : %s\n", mri->transform_fname); - } else { + } + else { errno = 0; ErrorPrintf(ERROR_BAD_FILE, "error loading transform from %s", mri->transform_fname); mri->linear_transform = NULL; @@ -11026,7 +11336,8 @@ static MRI *mghRead(const char *fname, int read_volume, int frame) { return (mri); } -static int mghWrite(MRI *mri, const char *fname, int frame) { +static int mghWrite(MRI *mri, const char *fname, int frame) +{ znzFile fp; int ival, start_frame, end_frame, x, y, z, width, height, depth, unused_space_size, flen; char buf[UNUSED_SPACE_SIZE + 1]; @@ -11050,7 +11361,8 @@ static int mghWrite(MRI *mri, const char *fname, int frame) { if (!stricmp(ext, "mgz") || strstr(fname, "mgh.gz")) { gzipped = 1; valid_ext = 1; - } else if (!stricmp(ext, "mgh")) { + } + else if (!stricmp(ext, "mgh")) { valid_ext = 1; } } @@ -11060,7 +11372,8 @@ static int mghWrite(MRI *mri, const char *fname, int frame) { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "mghWrite(%s, %d): could not open file", fname, frame)); } - } else { + } + else { errno = 0; ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, @@ -11215,7 +11528,8 @@ static int mghWrite(MRI *mri, const char *fname, int frame) { \param mri - input \param order[4] - new order of old dims */ -MRI *MRIreorder4(MRI *mri, int order[4]) { +MRI *MRIreorder4(MRI *mri, int order[4]) +{ MRI *new; int n, olddims[4], newdims[4]; int dold[4], dnew[4]; @@ -11267,7 +11581,8 @@ MRIreorder(). xdim,ydim,zdim indicate which dimension the given dimension moves to. So xdim=2 indicates that the cols of the source become the rows of the destination. The dims can be signed. */ -int MRIreorderVox2RAS(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim) { +int MRIreorderVox2RAS(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim) +{ MATRIX *Q, *Msrc, *Mdst; // Source vox2ras @@ -11316,7 +11631,8 @@ can be signed indicating a reversal. xdim, ydim, zdim values are only volumes will share RAS space (and can be alligned with a header registration. Handles multiple frames. */ -MRI *MRIreorder(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim) { +MRI *MRIreorder(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim) +{ int width, height, depth, xs, ys, zs, xd, yd, zd, x, y, z, f; int srcdims[3], dstdims[3]; float srcsizes[3], dstsizes[3]; @@ -11530,7 +11846,8 @@ MRI *MRIreorder(MRI *mri_src, MRI *mri_dst, int xdim, int ydim, int zdim) { Write the MRI header information to the file COR-.info in the directory specified by 'fpref' ------------------------------------------------------*/ -int MRIwriteInfo(MRI *mri, const char *fpref) { +int MRIwriteInfo(MRI *mri, const char *fpref) +{ FILE *fp; char fname[STRLEN]; int slice_direction; @@ -11601,7 +11918,8 @@ int MRIwriteInfo(MRI *mri, const char *fpref) { Write an MRI header and a set of data files to the directory specified by 'fpref' ------------------------------------------------------*/ -int MRIappend(MRI *mri, const char *fpref) { +int MRIappend(MRI *mri, const char *fpref) +{ int type, frame; char fname[STRLEN]; @@ -11616,7 +11934,8 @@ int MRIappend(MRI *mri, const char *fpref) { return (NO_ERROR); } -static int mghAppend(MRI *mri, const char *fname, int frame) { +static int mghAppend(MRI *mri, const char *fname, int frame) +{ FILE *fp; int start_frame, end_frame, x, y, z, width, height, depth, nframes; @@ -11681,7 +12000,8 @@ static int mghAppend(MRI *mri, const char *fname, int frame) { Description ------------------------------------------------------*/ -int MRIunpackFileName(const char *inFname, int *pframe, int *ptype, char *outFname) { +int MRIunpackFileName(const char *inFname, int *pframe, int *ptype, char *outFname) +{ char *number = NULL, *at = NULL, buf[STRLEN]; struct stat stat_buf; @@ -11699,7 +12019,8 @@ int MRIunpackFileName(const char *inFname, int *pframe, int *ptype, char *outFna { if (sscanf(number + 1, "%d", pframe) < 1) *pframe = -1; *number = 0; - } else + } + else *pframe = -1; if (at) { @@ -11730,7 +12051,8 @@ int MRIunpackFileName(const char *inFname, int *pframe, int *ptype, char *outFna errno = 0; ErrorExit(ERROR_UNSUPPORTED, "unknown file type %s", at); } - } else /* no '@' found */ + } + else /* no '@' found */ { *ptype = -1; @@ -11783,7 +12105,8 @@ int MRIunpackFileName(const char *inFname, int *pframe, int *ptype, char *outFna formats include: wfile, paint, w, bshort, bfloat, COR, analyze, analyze4d, spm. ---------------------------------------------------------------*/ -int MRIwriteAnyFormat(MRI *mri, const char *fileid, const char *fmt, int mriframe, MRIS *surf) { +int MRIwriteAnyFormat(MRI *mri, const char *fileid, const char *fmt, int mriframe, MRIS *surf) +{ int fmtid, err, n, r, c, s; float *v = NULL, f; MRI *mritmp = NULL; @@ -11847,7 +12170,8 @@ int MRIwriteAnyFormat(MRI *mri, const char *fileid, const char *fmt, int mrifram } } } - } else + } + else mritmp = mri; /*------------ Save using MRIwrite or MRIwriteType ---------*/ @@ -11863,7 +12187,8 @@ int MRIwriteAnyFormat(MRI *mri, const char *fileid, const char *fmt, int mrifram printf("ERROR: MRIwriteAnyFormat: could not write to %s\n", fileid); return (1); } - } else { + } + else { /* Try to infer the type and save (format is NULL) */ err = MRIwrite(mritmp, fileid); if (err) { @@ -13139,7 +13464,8 @@ static void nflip(unsigned char *buf, int b, int n) #endif #include "gca.h" -static MRI *readGCA(const char *fname, int start_frame, int end_frame) { +static MRI *readGCA(const char *fname, int start_frame, int end_frame) +{ GCA *gca; MRI *mri; @@ -13199,7 +13525,8 @@ static MRI *readGCA(const char *fname, int start_frame, int end_frame) { return (mri); } -MRI *MRIremoveNaNs(MRI *mri_src, MRI *mri_dst) { +MRI *MRIremoveNaNs(MRI *mri_src, MRI *mri_dst) +{ int x, nans = 0, width; if (mri_dst != mri_src) mri_dst = MRIcopy(mri_src, mri_dst); @@ -13232,7 +13559,8 @@ MRI *MRIremoveNaNs(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -int MRIaddCommandLine(MRI *mri, char *cmdline) { +int MRIaddCommandLine(MRI *mri, char *cmdline) +{ int i; if (mri->ncmds >= MAX_CMDS) ErrorExit(ERROR_NOMEMORY, "MRIaddCommandLine: can't add cmd %s (%d)", cmdline, mri->ncmds); @@ -13247,7 +13575,8 @@ int MRIaddCommandLine(MRI *mri, char *cmdline) { niiPrintHdr() - this dumps (most of) the nifti header to the given stream. ------------------------------------------------------------------*/ -static int niiPrintHdr(FILE *fp, struct nifti_1_header *hdr) { +static int niiPrintHdr(FILE *fp, struct nifti_1_header *hdr) +{ int n; fprintf(fp, "sizeof_hdr %d \n", hdr->sizeof_hdr); fprintf(fp, "data_type %s \n", hdr->data_type); diff --git a/utils/mriio_nrrd.c b/utils/mriio_nrrd.c index ce2e5bf52e3..451bc9c0799 100644 --- a/utils/mriio_nrrd.c +++ b/utils/mriio_nrrd.c @@ -40,7 +40,8 @@ #include "utils.h" extern MRI *mriNrrdReadDiffusion(char *fname, int read_volume); -MRI *mriNrrdRead(char *fname, int read_volume) { +MRI *mriNrrdRead(char *fname, int read_volume) +{ if (!nrrdSanity()) { fprintf(stderr, "\n"); fprintf(stderr, "!!! nrrd sanity check FAILED: fix and re-compile\n"); @@ -143,7 +144,8 @@ MRI *mriNrrdRead(char *fname, int read_volume) { unsigned char *_uc = (unsigned char *)nin->data; MRIseq_vox(mri, x, y, z, f) = (BUFTYPE)_uc[index]; } - } else if (type == MRI_SHORT) { + } + else if (type == MRI_SHORT) { for (f = 0; f < nframes; f++) for (z = 0; z < depth; z++) for (y = 0; y < height; y++) @@ -152,7 +154,8 @@ MRI *mriNrrdRead(char *fname, int read_volume) { short *_s = (short *)nin->data; MRISseq_vox(mri, x, y, z, f) = (short)_s[index]; } - } else if (type == MRI_INT) { + } + else if (type == MRI_INT) { for (f = 0; f < nframes; f++) for (z = 0; z < depth; z++) for (y = 0; y < height; y++) @@ -161,7 +164,8 @@ MRI *mriNrrdRead(char *fname, int read_volume) { int *_i = (int *)nin->data; MRIIseq_vox(mri, x, y, z, f) = (int)_i[index]; } - } else if (type == MRI_LONG) { + } + else if (type == MRI_LONG) { for (f = 0; f < nframes; f++) for (z = 0; z < depth; z++) for (y = 0; y < height; y++) @@ -170,7 +174,8 @@ MRI *mriNrrdRead(char *fname, int read_volume) { long *_l = (long *)nin->data; MRILseq_vox(mri, x, y, z, f) = (long)_l[index]; } - } else if (type == MRI_FLOAT) { + } + else if (type == MRI_FLOAT) { for (f = 0; f < nframes; f++) for (z = 0; z < depth; z++) for (y = 0; y < height; y++) @@ -179,7 +184,8 @@ MRI *mriNrrdRead(char *fname, int read_volume) { float *_f = (float *)nin->data; MRIFseq_vox(mri, x, y, z, f) = (float)_f[index]; } - } else { + } + else { printf("mriNrrdRead: Unsupported type=%d\n", type); return NULL; } @@ -214,6 +220,7 @@ MRI *mriNrrdRead(char *fname, int read_volume) { return mri; } -int mriNrrdWrite(MRI *mri, char *fname) { +int mriNrrdWrite(MRI *mri, char *fname) +{ ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "mriNrrdWrite(): Nrrd output not supported!")); } diff --git a/utils/mriio_nrrd_itk.cpp b/utils/mriio_nrrd_itk.cpp index dac9d21aa7e..90e9ffdd0bd 100644 --- a/utils/mriio_nrrd_itk.cpp +++ b/utils/mriio_nrrd_itk.cpp @@ -29,11 +29,13 @@ extern "C" { #include "error.h" #include "mri.h" -MRI *mriNrrdReadDiffusion(char *fname, int read_volume) { +MRI *mriNrrdReadDiffusion(char *fname, int read_volume) +{ ErrorReturn(NULL, (ERROR_UNSUPPORTED, "mriNrrdReadDiffusion(): Nrrd input of diffusion data not supported!")); return NULL; } -int mriNrrdWriteDiffusion(MRI *mri, char *fname) { +int mriNrrdWriteDiffusion(MRI *mri, char *fname) +{ ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "mriNrrdWriteDiffusion(): Nrrd diffusion data output not supported!")); } @@ -104,7 +106,8 @@ MRI *mriNrrdReadDiffusion(char *fname, int read_volume); int mriNrrdWriteDiffusion(MRI *mri, char *fname); } -MRI *mriNrrdReadDiffusion(char *fname, int read_volume) { +MRI *mriNrrdReadDiffusion(char *fname, int read_volume) +{ typedef itk::DiffusionTensor3D< float > PixelType; typedef itk::Image< PixelType, 3 > DiffusionImageType; typedef itk::ImageFileReader< DiffusionImageType > ReaderType; @@ -246,7 +249,8 @@ MRI *mriNrrdReadDiffusion(char *fname, int read_volume) { return mri; } -int mriNrrdWriteDiffusion(MRI *mri, char *fname) { +int mriNrrdWriteDiffusion(MRI *mri, char *fname) +{ // just give an error until write function is complete and tested ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, diff --git a/utils/mrimorph.c b/utils/mrimorph.c index ba880290b7c..bab4be01b40 100644 --- a/utils/mrimorph.c +++ b/utils/mrimorph.c @@ -130,13 +130,15 @@ static int debug_z = -1; #define MAX_LABELS 1000 -void showTran(float p[]) { +void showTran(float p[]) +{ printf("after pass:transform: ( %.2f, %.2f, %.2f, %.2f)\n", p[1], p[2], p[3], p[4]); printf(" ( %.2f, %.2f, %.2f, %.2f)\n", p[5], p[6], p[7], p[8]); printf(" ( %.2f, %.2f, %.2f, %.2f)\n", p[9], p[10], p[11], p[12]); } -int MatrixPrintHires(FILE *fp, MATRIX *mat) { +int MatrixPrintHires(FILE *fp, MATRIX *mat) +{ int row, col, rows, cols; if (fp == NULL) { @@ -176,7 +178,8 @@ int MatrixPrintHires(FILE *fp, MATRIX *mat) { Description ------------------------------------------------------*/ -HISTOGRAM *MRIhorizontalHistogram(MRI *mri, int thresh_low, int thresh_hi) { +HISTOGRAM *MRIhorizontalHistogram(MRI *mri, int thresh_low, int thresh_hi) +{ HISTOGRAM *histo; int x, y, z, width, height, depth, npix, val; @@ -206,7 +209,8 @@ HISTOGRAM *MRIhorizontalHistogram(MRI *mri, int thresh_low, int thresh_hi) { Description ------------------------------------------------------*/ -HISTOGRAM *MRIhorizontalBoundingBoxHistogram(MRI *mri, int thresh) { +HISTOGRAM *MRIhorizontalBoundingBoxHistogram(MRI *mri, int thresh) +{ HISTOGRAM *histo; int x, y, z, width, height, depth, xmin, xmax, zmin, zmax; @@ -243,7 +247,8 @@ HISTOGRAM *MRIhorizontalBoundingBoxHistogram(MRI *mri, int thresh) { \fn int MRIcountAboveThreshold(MRI *mri, int thresh) \brief Returns the number of voxels above the given threshold ------------------------------------------------------*/ -int MRIcountAboveThreshold(MRI *mri, double thresh) { +int MRIcountAboveThreshold(MRI *mri, double thresh) +{ int x, y, z, width, height, depth, count; double val; @@ -269,7 +274,8 @@ int MRIcountAboveThreshold(MRI *mri, double thresh) { Description ------------------------------------------------------*/ -MRI *MRIlabel(MRI *mri_src, MRI *mri_dst, int *pnlabels) { +MRI *MRIlabel(MRI *mri_src, MRI *mri_dst, int *pnlabels) +{ int l, x, y, z, width, height, depth, *pxi, *pyi, *pzi, xi, yi, zi, total_on, total_labeled, labeled, xk, yk, zk; BUFTYPE *psrc, *plabel; @@ -296,7 +302,8 @@ MRI *MRIlabel(MRI *mri_src, MRI *mri_dst, int *pnlabels) { *plabel = l; labeled = 1; total_labeled++; - } else + } + else plabel++; } } @@ -341,7 +348,8 @@ MRI *MRIlabel(MRI *mri_src, MRI *mri_dst, int *pnlabels) { Description ------------------------------------------------------*/ -int MRIlabelBoundingBoxes(MRI *mri, MRI_REGION *bboxes, int nlabels) { +int MRIlabelBoundingBoxes(MRI *mri, MRI_REGION *bboxes, int nlabels) +{ int l, x, y, z, width, height, depth, x0, x1, y0, y1, z0, z1; BUFTYPE *plabel; @@ -391,7 +399,8 @@ int MRIlabelBoundingBoxes(MRI *mri, MRI_REGION *bboxes, int nlabels) { Description ------------------------------------------------------*/ -int MRIeraseOtherLabels(MRI *mri_src, MRI *mri_dst, int label) { +int MRIeraseOtherLabels(MRI *mri_src, MRI *mri_dst, int label) +{ int x, y, z, width, height, depth; BUFTYPE *psrc, *pdst; @@ -421,7 +430,8 @@ int MRIeraseOtherLabels(MRI *mri_src, MRI *mri_dst, int label) { Description ------------------------------------------------------*/ -int MRIeraseLabel(MRI *mri_src, MRI *mri_dst, int label) { +int MRIeraseLabel(MRI *mri_src, MRI *mri_dst, int label) +{ int x, y, z, width, height, depth; BUFTYPE *psrc, *pdst, l; @@ -452,7 +462,8 @@ int MRIeraseLabel(MRI *mri_src, MRI *mri_dst, int label) { Description ------------------------------------------------------*/ -int MRIfindHorizontalLabelLimits(MRI *mri, int label, int *xmins, int *xmaxs) { +int MRIfindHorizontalLabelLimits(MRI *mri, int label, int *xmins, int *xmaxs) +{ int x, y, z, width, height, depth, ymin; BUFTYPE *psrc; @@ -502,7 +513,8 @@ int MRIfindHorizontalLabelLimits(MRI *mri, int label, int *xmins, int *xmaxs) { #define DISTANCE_BELOW_SPINAL_FUSION 40.0 -MRI *MRIfindNeck(MRI *mri_src, MRI *mri_dst, int thresh_low, int thresh_hi, MP *parms, int dir, NECK_PARMS *np) { +MRI *MRIfindNeck(MRI *mri_src, MRI *mri_dst, int thresh_low, int thresh_hi, MP *parms, int dir, NECK_PARMS *np) +{ MRI *mri_label, *mri_thresh, *mri_midline, *mri_rot; int nlabels, l, max_dy, spinal_label, xmins[256], xmaxs[256], y; MRI_REGION bboxes[MAX_LABELS], *spinal_bbox, in_bbox; @@ -704,7 +716,8 @@ MRI *MRIfindNeck(MRI *mri_src, MRI *mri_dst, int thresh_low, int thresh_hi, MP * #endif #define WSIZE 21 #define WHALF ((WSIZE - 1) / 2) -static MRI *find_midline(MRI *mri_src, MRI *mri_thresh, float *px) { +static MRI *find_midline(MRI *mri_src, MRI *mri_thresh, float *px) +{ MRI *mri_dst; MRI_REGION bbox; int count, min_count, x, x0, xmid; @@ -743,7 +756,8 @@ static MRI *find_midline(MRI *mri_src, MRI *mri_thresh, float *px) { Description Compute the centroid of a label (in mm coordinates) ------------------------------------------------------*/ -int MRIlabelCentroid(MRI *mri, int target_l, float *px, float *py, float *pz) { +int MRIlabelCentroid(MRI *mri, int target_l, float *px, float *py, float *pz) +{ int l, x, y, z, width, height, depth, nvox; BUFTYPE *plabel; float thick, x0, y0, z0; @@ -771,7 +785,8 @@ int MRIlabelCentroid(MRI *mri, int target_l, float *px, float *py, float *pz) { *px = x0 / nvox; *py = y0 / nvox; *pz = z0 / nvox; - } else + } + else *px = *py = *pz = 0.0f; return (NO_ERROR); @@ -784,7 +799,8 @@ int MRIlabelCentroid(MRI *mri, int target_l, float *px, float *py, float *pz) { Description Compute the area of all labels (in mm^3) ------------------------------------------------------*/ -int MRIlabelAreas(MRI *mri, float *areas, int nlabels) { +int MRIlabelAreas(MRI *mri, float *areas, int nlabels) +{ int l, x, y, z, width, height, depth; BUFTYPE *plabel; float voxel_area; @@ -837,7 +853,8 @@ int MRIlabelAreas(MRI *mri, float *areas, int nlabels) { #define MIN_SPINAL_CX (128 - MAX_SPINAL_WIDTH / 2) #define MAX_SPINAL_CX (128 + MAX_SPINAL_WIDTH / 2) -static int find_spinal_fusion(MRI *mri_thresh, float *px, float *py, float *pz) { +static int find_spinal_fusion(MRI *mri_thresh, float *px, float *py, float *pz) +{ MRI *mri_label, *mri_slice; float areas[MAX_LABELS], spinal_area, aspect, corner_dist, thick, x0, y0, z0; int y, found, nlabels, l, spinal_l = 0; @@ -925,7 +942,8 @@ static int find_spinal_fusion(MRI *mri_thresh, float *px, float *py, float *pz) Description ------------------------------------------------------*/ -int MRIinitTranslation(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) { +int MRIinitTranslation(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) +{ MATRIX *m_translation; float in_means[4], ref_means[4]; double dx, dy, dz; @@ -971,7 +989,8 @@ int MRIinitTranslation(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) { #define MIN_DZ (1.0 / MAX_DZ) #define MAX_RATIO 1.1 -int MRIinitScaling(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) { +int MRIinitScaling(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) +{ MATRIX *m_scaling; float sx, sy, sz, dx, dy, dz; MRI_REGION in_bbox, ref_bbox; @@ -1028,7 +1047,8 @@ int MRIinitScaling(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) { ------------------------------------------------------*/ #define MIN_PYR_WIDTH 16 #define USE_PYRAMID 1 -int MRIlinearAlign(MRI *mri_in, MRI *mri_ref, MP *parms) { +int MRIlinearAlign(MRI *mri_in, MRI *mri_ref, MP *parms) +{ #if USE_PYRAMID int nlevels, max_levels, i; MRI *mri_in_pyramid[MAX_LEVELS], *mri_ref_pyramid[MAX_LEVELS]; @@ -1114,7 +1134,8 @@ int MRIlinearAlign(MRI *mri_in, MRI *mri_ref, MP *parms) { fflush(stdout); MRIfree(&mri_kernel); mriLinearAlignPyramidLevel(mri_in_blur, mri_ref_blur, parms); - } else + } + else mriLinearAlignPyramidLevel(mri_in, mri_ref, parms); } parms->dt = dt; @@ -1168,7 +1189,8 @@ int MRIlinearAlign(MRI *mri_in, MRI *mri_ref, MP *parms) { Description ------------------------------------------------------*/ -int MRIfindMeans(MRI *mri, float *means) { +int MRIfindMeans(MRI *mri, float *means) +{ int width, height, depth, x, y, z, val, npoints, mx, my, mz; BUFTYPE *psrc; @@ -1197,7 +1219,8 @@ int MRIfindMeans(MRI *mri, float *means) { means[0] = (float)mx / npoints; means[1] = (float)my / npoints; means[2] = (float)mz / npoints; - } else + } + else means[0] = means[1] = means[2] = 0.0f; return (NO_ERROR); @@ -1210,7 +1233,8 @@ int MRIfindMeans(MRI *mri, float *means) { Description ------------------------------------------------------*/ -int MRIfindCenterOfBrain(MRI *mri, float *px0, float *py0, float *pz0) { +int MRIfindCenterOfBrain(MRI *mri, float *px0, float *py0, float *pz0) +{ #if 1 int x, y, z, width, height, depth; float x0, y0, z0, total, val; @@ -1238,7 +1262,8 @@ int MRIfindCenterOfBrain(MRI *mri, float *px0, float *py0, float *pz0) { *px0 = x0 / (float)total; *py0 = y0 / (float)total; *pz0 = z0 / (float)total; - } else { + } + else { *px0 = width / 2; *py0 = height / 2; *pz0 = depth / 2; @@ -1262,7 +1287,8 @@ int MRIfindCenterOfBrain(MRI *mri, float *px0, float *py0, float *pz0) { ------------------------------------------------------*/ -static int mriLinearAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) { +static int mriLinearAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) +{ double rms, old_rms, dt; int k, n, nsmall = 0; MATRIX *m_L; @@ -1378,7 +1404,8 @@ static int mriLinearAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *pa an input image after a linear transformation of the input coordinate system. ------------------------------------------------------*/ -static double mriIntensityRMS(MRI *mri_in, MRI *mri_ref, LTA *lta, double l_intensity, NECK_PARMS *np) { +static double mriIntensityRMS(MRI *mri_in, MRI *mri_ref, LTA *lta, double l_intensity, NECK_PARMS *np) +{ int x1, x2, x3, width, height, depth; VECTOR *v_X, *v_Y; /* original and transformed coordinate systems */ double val, y1, y2, y3, thick; @@ -1428,7 +1455,8 @@ static double mriIntensityRMS(MRI *mri_in, MRI *mri_ref, LTA *lta, double l_inte std /= mean_std; if (DZERO(std)) std = 1.0; delta = (val - (double)in_val) / std; - } else /* out of bounds, assume in val is 0 */ + } + else /* out of bounds, assume in val is 0 */ delta = (0.0 - in_val) / mean_std; if (fabs(delta) > 20) DiagBreak(); delta *= dot; @@ -1453,7 +1481,8 @@ static double mriIntensityRMS(MRI *mri_in, MRI *mri_ref, LTA *lta, double l_inte Description ------------------------------------------------------*/ -static int writeSnapshot(MRI *mri, MORPH_PARMS *parms, int n) { +static int writeSnapshot(MRI *mri, MORPH_PARMS *parms, int n) +{ MRI *mri_tmp; char fname[STRLEN]; TRANSFORM transform; @@ -1515,7 +1544,8 @@ static int writeSnapshot(MRI *mri, MORPH_PARMS *parms, int n) { Description ------------------------------------------------------*/ static double ltaGradientStep( - MRI *mri_in, MRI *mri_ref, LTA *lta, double dt, double momentum, NECK_PARMS *np, double tmul) { + MRI *mri_in, MRI *mri_ref, LTA *lta, double dt, double momentum, NECK_PARMS *np, double tmul) +{ int width, height, depth; VECTOR *v_X, *v_Y, *v_Yk; /* original and transformed coordinate systems */ MATRIX *m_tmp, *m_L, *m_dT_X_T; @@ -1579,7 +1609,8 @@ static double ltaGradientStep( else std = mean_std; MRIsampleVolumeGradient(mri_ref, y1, y2, y3, &dx, &dy, &dz); - } else { + } + else { std = mean_std; val = 0.0f; dx = dy = dz = 0.0f; @@ -1690,7 +1721,8 @@ static double ltaGradientStep( Description ------------------------------------------------------*/ -static int openLogFile(MORPH_PARMS *parms) { +static int openLogFile(MORPH_PARMS *parms) +{ char fname[STRLEN]; if ((Gdiag & DIAG_WRITE) && (parms->log_fp == NULL)) { @@ -1736,7 +1768,8 @@ static int openLogFile(MORPH_PARMS *parms) { Description ------------------------------------------------------*/ -static int logIntegration(MORPH_PARMS *parms, int n, double rms) { +static int logIntegration(MORPH_PARMS *parms, int n, double rms) +{ if (Gdiag & DIAG_WRITE) { fprintf(parms->log_fp, "%3.3d: rms = %2.3f\n", n + 1, rms); fflush(parms->log_fp); @@ -1821,7 +1854,8 @@ static double m3dSSE(MRI *mri_in, MORPH_3D *m3d, double *pintensity_rms, double *pdistance_rms, - double *parea_rms) { + double *parea_rms) +{ double sse, intensity_sse, area_sse, distance_sse, nvox, nlarea_sse, compression_sse; intensity_sse = m3dCorrelationSSE(mri_in, mri_ref, m3d, &parms->in_np); @@ -1846,7 +1880,8 @@ static double m3dSSE(MRI *mri_in, Description Compute correlation SSE ------------------------------------------------------*/ -static double m3dCorrelationSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d, NECK_PARMS *np) { +static double m3dCorrelationSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d, NECK_PARMS *np) +{ double sse; int width, height, depth, x, y, z, xsi, ysi, zsi, *pxi, *pyi, *pzi; MORPH_NODE *mn; @@ -1889,7 +1924,8 @@ static double m3dCorrelationSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d, NECK_P MRIsampleVolume(mri_ref, xd, yd, zd, &ref_val); MRIsampleVolumeFrame(mri_ref, xd, yd, zd, 1, &ref_std); ref_std /= mean_std; - } else { + } + else { ref_std = mean_std; ref_val = 0.0; } @@ -1920,7 +1956,8 @@ static double m3dCorrelationSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d, NECK_P Description Compute SSE for distance term. ------------------------------------------------------*/ -static double m3dDistanceSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) { +static double m3dDistanceSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) +{ int i, j, k, width, height, depth, n; MORPH_NODE *mn, *mn_nbr; MNP *mnp; @@ -2001,7 +2038,8 @@ static double m3dDistanceSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) { Description Compute SSE for area term. ------------------------------------------------------*/ -static double m3dNonlinearAreaSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d, MORPH_PARMS *parms) { +static double m3dNonlinearAreaSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d, MORPH_PARMS *parms) +{ double sse, delta, n3, ratio, exponent; int i, j, k, width, height, depth; MORPH_NODE *mn; @@ -2057,7 +2095,8 @@ static double m3dNonlinearAreaSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d, MORP Description Compute SSE for area term. ------------------------------------------------------*/ -static double m3dAreaSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) { +static double m3dAreaSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) +{ double sse, delta, n3; int i, j, k, width, height, depth; MORPH_NODE *mn; @@ -2098,7 +2137,8 @@ static double m3dAreaSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) { Description Allocate and initialize 3D properties ------------------------------------------------------*/ -static int m3dAllocProperties(MORPH_3D *m3d) { +static int m3dAllocProperties(MORPH_3D *m3d) +{ int x, y, width, height, depth; width = m3d->width; @@ -2125,7 +2165,8 @@ static int m3dAllocProperties(MORPH_3D *m3d) { Description Allocate and initialize a 3D morph structure. ------------------------------------------------------*/ -static MORPH_3D *m3dalloc(int width, int height, int depth, float node_spacing) { +static MORPH_3D *m3dalloc(int width, int height, int depth, float node_spacing) +{ MORPH_3D *m3d; int x, y; @@ -2163,7 +2204,8 @@ static MORPH_3D *m3dalloc(int width, int height, int depth, float node_spacing) Description Allocate and initialize a 3D morph structure. ------------------------------------------------------*/ -static MORPH_3D *m3dInit(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, float node_spacing) { +static MORPH_3D *m3dInit(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, float node_spacing) +{ MORPH_3D *m3d; int width, height, depth, x, y, i, j, k; float scale; @@ -2247,7 +2289,8 @@ static MORPH_3D *m3dInit(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, float no Store the current metric properties of the m3d structure as the reference values to be used for computing distortion. ------------------------------------------------------*/ -static int m3dStoreMetricProperties(MORPH_3D *m3d) { +static int m3dStoreMetricProperties(MORPH_3D *m3d) +{ MORPH_NODE *mn; MNP *mnp; int i, j, k, width, height, depth; @@ -2341,7 +2384,8 @@ m3dinit(MORPH_3D *m3d) Description ------------------------------------------------------*/ #define MIN_3D_PYR_WIDTH 32 -MORPH_3D *MRI3Dmorph(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) { +MORPH_3D *MRI3Dmorph(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) +{ int nlevels, i, max_levels, navgs, base_avgs; MRI *mri_in_pyramid[MAX_LEVELS], *mri_ref_pyramid[MAX_LEVELS]; MORPH_3D *m3d_tmp, *m3d; @@ -2370,7 +2414,8 @@ MORPH_3D *MRI3Dmorph(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) { parms->ref_np.neck_dx = parms->ref_np.neck_dy = parms->ref_np.neck_dz = 1; parms->in_np.neck_x0 = parms->in_np.neck_y0 = parms->in_np.neck_z0 = 1000; parms->in_np.neck_dx = parms->in_np.neck_dy = parms->in_np.neck_dz = 1; - } else { + } + else { fprintf(stdout, "moving spinal estimate from (%2.0f,%2.0f,%2.0f) to ", parms->in_np.neck_x0, @@ -2654,7 +2699,8 @@ MORPH_3D *MRI3Dmorph(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) { done in unsigned char volumes which forces things to be scaled up and then back down in various places. ------------------------------------------------------*/ -MRI *MRIapply3DMorph(MRI *mri_in, MORPH_3D *m3d, MRI *mri_morphed) { +MRI *MRIapply3DMorph(MRI *mri_in, MORPH_3D *m3d, MRI *mri_morphed) +{ int width, height, depth, x, y, z, xm1, ym1, zm1, xp1, yp1, zp1; float xd, yd, zd, dx, dy, dz, thick; double weight, orig_val, val; @@ -2817,7 +2863,8 @@ MRI *MRIapply3DMorph(MRI *mri_in, MORPH_3D *m3d, MRI *mri_morphed) { simpler than the inverse mapping as the sampling is uniform in this direction. ------------------------------------------------------*/ -MRI *MRIapplyInverse3DMorph(MRI *mri_ref, MORPH_3D *m3d, MRI *mri_morphed) { +MRI *MRIapplyInverse3DMorph(MRI *mri_ref, MORPH_3D *m3d, MRI *mri_morphed) +{ int width, height, depth, x, y, z; float xd, yd, zd; double val; @@ -2861,7 +2908,8 @@ MRI *MRIapplyInverse3DMorph(MRI *mri_ref, MORPH_3D *m3d, MRI *mri_morphed) { Description ------------------------------------------------------*/ -int MRIsample3DmorphOrig(MORPH_3D *m3d, float x, float y, float z, float *pxd, float *pyd, float *pzd) { +int MRIsample3DmorphOrig(MORPH_3D *m3d, float x, float y, float z, float *pxd, float *pyd, float *pzd) +{ int xm, xp, ym, yp, zm, zp, width, height, depth; float xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ @@ -2915,7 +2963,8 @@ int MRIsample3DmorphOrig(MORPH_3D *m3d, float x, float y, float z, float *pxd, f Description ------------------------------------------------------*/ -static int MRIsample3Dmorph(MORPH_3D *m3d, float x, float y, float z, float *pxd, float *pyd, float *pzd) { +static int MRIsample3Dmorph(MORPH_3D *m3d, float x, float y, float z, float *pxd, float *pyd, float *pzd) +{ int xm, xp, ym, yp, zm, zp, width, height, depth; float xmd, ymd, zmd, xpd, ypd, zpd; /* d's are distances */ @@ -2969,7 +3018,8 @@ static int MRIsample3Dmorph(MORPH_3D *m3d, float x, float y, float z, float *pxd Description Free the properties field of a 3d morph structure ------------------------------------------------------*/ -int MRI3DmorphFreeProperties(MORPH_3D *m3d) { +int MRI3DmorphFreeProperties(MORPH_3D *m3d) +{ int x, y; if (m3d->pnodes) { @@ -2991,7 +3041,8 @@ int MRI3DmorphFreeProperties(MORPH_3D *m3d) { Description Free a 3d morph structure and set the pointer to NULL. ------------------------------------------------------*/ -int MRI3DmorphFree(MORPH_3D **pm3d) { +int MRI3DmorphFree(MORPH_3D **pm3d) +{ MORPH_3D *m3d = *pm3d; int x, y; @@ -3036,7 +3087,8 @@ static int m3dCorrelationTerm(MRI *mri_in, double zref, double *pdx, double *pdy, - double *pdz) { + double *pdz) +{ double ref_val, in_val, delta, Tdx, Tdy, Tdz, len, ref_std, mean_std; mean_std = mri_ref->mean; @@ -3048,7 +3100,8 @@ static int m3dCorrelationTerm(MRI *mri_in, MRIsampleVolume(mri_ref, xref, yref, zref, &ref_val); MRIsampleVolumeFrame(mri_ref, xref, yref, zref, 1, &ref_std); if (DZERO(ref_std)) ref_std = 1.0; - } else { + } + else { ref_std = mean_std; ref_val = 0.0; } @@ -3076,8 +3129,8 @@ static int m3dCorrelationTerm(MRI *mri_in, Compute the directional derivative of the distance term w.r.t the i,j,kth node. ------------------------------------------------------*/ -static int m3dDistanceTerm( - MORPH_3D *m3d, double l_distance, int i, int j, int k, double *pdx, double *pdy, double *pdz) { +static int m3dDistanceTerm(MORPH_3D *m3d, double l_distance, int i, int j, int k, double *pdx, double *pdy, double *pdz) +{ int n, num; double dx, dy, dz, dist, delta, xgrad, ygrad, zgrad; MORPH_NODE *mn, *mn_nbr; @@ -3171,7 +3224,8 @@ static int m3dDistanceTerm( w.r.t the i,j,kth node. ------------------------------------------------------*/ #define AREA_NEIGHBORS 8 -static int m3dAreaTerm(MORPH_3D *m3d, double l_area, int i, int j, int k, double *pdx, double *pdy, double *pdz) { +static int m3dAreaTerm(MORPH_3D *m3d, double l_area, int i, int j, int k, double *pdx, double *pdy, double *pdz) +{ MORPH_NODE *mn, *mni, *mnj, *mnk; MNP *mnp, *mnpi, *mnpj, *mnpk; float delta, node_spacing, n3 /*, odx, ody, odz*/; @@ -3211,7 +3265,8 @@ static int m3dAreaTerm(MORPH_3D *m3d, double l_area, int i, int j, int k, double v_j_x_i = VectorAlloc(3, MATRIX_REAL); v_i_x_k = VectorAlloc(3, MATRIX_REAL); v_tmp = VectorAlloc(3, MATRIX_REAL); - } else { + } + else { V3_CLEAR(v_grad); } @@ -3393,7 +3448,8 @@ static int m3dAreaTerm(MORPH_3D *m3d, double l_area, int i, int j, int k, double *pdx = l_area * V3_X(v_grad); *pdy = l_area * V3_Y(v_grad); *pdz = l_area * V3_Z(v_grad); - } else { + } + else { /* if on the border st no area term can be computed, move in a quasi-rigid fashion by applying strong distance term. */ @@ -3405,7 +3461,8 @@ static int m3dAreaTerm(MORPH_3D *m3d, double l_area, int i, int j, int k, double return (NO_ERROR); } static int m3dNonlinearAreaTerm( - MORPH_3D *m3d, double l_nlarea, int i, int j, int k, double *pdx, double *pdy, double *pdz, MORPH_PARMS *parms) { + MORPH_3D *m3d, double l_nlarea, int i, int j, int k, double *pdx, double *pdy, double *pdz, MORPH_PARMS *parms) +{ MORPH_NODE *mn, *mni, *mnj, *mnk; MNP *mnp; float delta, delta_scale, ratio, node_spacing, n3; @@ -3437,7 +3494,8 @@ static int m3dNonlinearAreaTerm( v_j_x_i = VectorAlloc(3, MATRIX_REAL); v_i_x_k = VectorAlloc(3, MATRIX_REAL); v_tmp = VectorAlloc(3, MATRIX_REAL); - } else { + } + else { V3_CLEAR(v_grad); } @@ -3586,7 +3644,8 @@ static int m3dNonlinearAreaTerm( Description ------------------------------------------------------*/ #define AVG_LEN 5 -static int m3dAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MRI *mri_ref_blur, MP *parms, MORPH_3D *m3d) { +static int m3dAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MRI *mri_ref_blur, MP *parms, MORPH_3D *m3d) +{ double dt, sse, rms, nvox, intensity_rms, distance_rms, area_rms, d, old_rms, last_avg, current_avg; int n, last_neg; @@ -3668,7 +3727,8 @@ static int m3dAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MRI *mri_ref_blur, MP last_neg = m3d->neg; last_avg = current_avg; current_avg = rms; - } else + } + else current_avg += rms; } @@ -3684,7 +3744,8 @@ static int m3dAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MRI *mri_ref_blur, MP Description ------------------------------------------------------*/ static double m3dIntegrationStep( - MRI *mri_in, MRI *mri_ref, MRI *mri_ref_blur, MORPH_PARMS *parms, MORPH_3D *m3d, double dt) { + MRI *mri_in, MRI *mri_ref, MRI *mri_ref_blur, MORPH_PARMS *parms, MORPH_3D *m3d, double dt) +{ double dx, dy, dz, xgrad, ygrad, zgrad, dot, nx, ny, nz, ndx, ndy, ndz, thick, pdx, pdy, pdz; int width, height, depth, x, y, z, xsi, ysi, zsi, *pxi, *pyi, *pzi; MORPH_NODE *mn; @@ -3794,7 +3855,8 @@ static double m3dIntegrationStep( Description ------------------------------------------------------*/ -static int m3dInitDistances(MORPH_3D *m3d) { +static int m3dInitDistances(MORPH_3D *m3d) +{ int i, j, k, width, height, depth, n, ndists; MORPH_NODE *mn; MNP *mnp, *mnp_nbr; @@ -3875,7 +3937,8 @@ static int m3dInitDistances(MORPH_3D *m3d) { Description ------------------------------------------------------*/ -static int m3dInitAreas(MORPH_3D *m3d) { +static int m3dInitAreas(MORPH_3D *m3d) +{ int i, j, k, width, height, depth, num, num_zero, total_num; MNP *mnp, *mnpi, *mnpj, *mnpk; VECTOR *v_i, *v_j, *v_k; @@ -3904,7 +3967,8 @@ static int m3dInitAreas(MORPH_3D *m3d) { MNP_SUB(mnpk, mnp, v_k); area = VectorTripleProduct(v_j, v_k, v_i); num++; - } else + } + else area = 0.0; if ((i > 0) && (j > 0) && (k > 0)) /* left hand coordinate system */ { @@ -3962,7 +4026,8 @@ static int log3DIntegration(MORPH_PARMS *parms, double rms, double intensity_rms, double distance_rms, - double area_rms) { + double area_rms) +{ if (Gdiag & DIAG_SHOW) #if USE_ITERATIVE_AVERAGING fprintf(stdout, @@ -4028,7 +4093,8 @@ static int log3DIntegration(MORPH_PARMS *parms, ------------------------------------------------------*/ #include "image.h" -static int write3DSnapshot(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MORPH_3D *m3d, int n) { +static int write3DSnapshot(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MORPH_3D *m3d, int n) +{ MRI *mri_tmp; char fname[STRLEN]; @@ -4067,7 +4133,8 @@ static int write3DSnapshot(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MORPH_ Description ------------------------------------------------------*/ -int MRIwriteImageViews(MRI *mri, char *base_name, int target_size) { +int MRIwriteImageViews(MRI *mri, char *base_name, int target_size) +{ int slice_direction = getSliceDirection(mri), x, y, z; switch (slice_direction) { @@ -4120,7 +4187,8 @@ int MRIwriteImageViews(MRI *mri, char *base_name, int target_size) { Description ------------------------------------------------------*/ -static int mriWriteImageView(MRI *mri, char *base_name, int target_size, int view, int slice) { +static int mriWriteImageView(MRI *mri, char *base_name, int target_size, int view, int slice) +{ char fname[STRLEN], *prefix; IMAGE *I; float scale; @@ -4201,7 +4269,8 @@ static int mriWriteImageView(MRI *mri, char *base_name, int target_size, int vie Description ------------------------------------------------------*/ -static int m3dComputeMetricProperties(MORPH_3D *m3d) { +static int m3dComputeMetricProperties(MORPH_3D *m3d) +{ double area; int i, j, k, width, height, depth, num; MORPH_NODE *mn, *mni, *mnj, *mnk; @@ -4230,7 +4299,8 @@ static int m3dComputeMetricProperties(MORPH_3D *m3d) { MN_SUB(mnj, mn, v_j); MN_SUB(mnk, mn, v_k); area = VectorTripleProduct(v_j, v_k, v_i); - } else + } + else area = 0; if ((i > 0) && (j > 0) && (k > 0)) /* left-hand coordinate system */ { @@ -4266,7 +4336,8 @@ static int m3dComputeMetricProperties(MORPH_3D *m3d) { Description ------------------------------------------------------*/ -static int m3dclearGradient(MORPH_3D *m3d) { +static int m3dclearGradient(MORPH_3D *m3d) +{ int i, j, k, width, height, depth; MNP *mnp; @@ -4295,7 +4366,8 @@ static int m3dclearGradient(MORPH_3D *m3d) { #define DJ 90 #define DK 104 -static int m3dapplyGradient(MORPH_3D *m3d, double dt) { +static int m3dapplyGradient(MORPH_3D *m3d, double dt) +{ int i, j, k, width, height, depth; MORPH_NODE *mn; MNP *mnp; @@ -4328,7 +4400,8 @@ static int m3dapplyGradient(MORPH_3D *m3d, double dt) { Description ------------------------------------------------------*/ -static int finitep(float f) { +static int finitep(float f) +{ return (1); if (!isfinite(f)) return (0); if (fabs(f) > 1e5) return (0); @@ -4341,7 +4414,8 @@ static int finitep(float f) { Description ------------------------------------------------------*/ -static double m3dscaleDeltaT(MORPH_3D *m3d, double dt, double max_len, MORPH_PARMS *parms) { +static double m3dscaleDeltaT(MORPH_3D *m3d, double dt, double max_len, MORPH_PARMS *parms) +{ int i, j, k, width, height, depth, maxi, maxj, maxk, mini, minj, mink; MORPH_NODE *mn; MNP *mnp; @@ -4430,7 +4504,8 @@ static double m3dscaleDeltaT(MORPH_3D *m3d, double dt, double max_len, MORPH_PAR ------------------------------------------------------*/ #define UNUSED_SPACE_SIZE 256 -int MRI3Dwrite(MORPH_3D *m3d, char *fname) { +int MRI3Dwrite(MORPH_3D *m3d, char *fname) +{ FILE *fp; int i, j, k; MORPH_NODE *mn; @@ -4472,7 +4547,8 @@ int MRI3Dwrite(MORPH_3D *m3d, char *fname) { Read a 3d morph from a file, and initialize it, not allocating the properties field to conserve memory. ------------------------------------------------------*/ -MORPH_3D *MRI3DreadSmall(char *fname) { +MORPH_3D *MRI3DreadSmall(char *fname) +{ MORPH_3D *m3d; FILE *fp; int i, j, k, width, height, depth, magic, version; @@ -4520,7 +4596,8 @@ MORPH_3D *MRI3DreadSmall(char *fname) { Description Read a 3d morph from a file, and initialize it. ------------------------------------------------------*/ -MORPH_3D *MRI3Dread(char *fname) { +MORPH_3D *MRI3Dread(char *fname) +{ MORPH_3D *m3d; m3d = MRI3DreadSmall(fname); @@ -4801,7 +4878,8 @@ MatrixCopy(v_X, v_Y) ; return(m3d_out) ; } #else -static MORPH_3D *m3dscaleUp2(MORPH_3D *m3d_in, MORPH_3D *m3d_out, MORPH_PARMS *parms) { +static MORPH_3D *m3dscaleUp2(MORPH_3D *m3d_in, MORPH_3D *m3d_out, MORPH_PARMS *parms) +{ int width, height, depth, i, j, k, alloced = 0; MORPH_NODE *mn; MNP *mnp; @@ -4983,7 +5061,8 @@ m3dComputeOrigArea(MORPH_3D *m3d, int i, int j, int k) return(area) ; } #endif -int MRIeraseBorders(MRI *mri, int width) { +int MRIeraseBorders(MRI *mri, int width) +{ int i; for (i = 0; i < width; i++) { @@ -4997,7 +5076,8 @@ int MRIeraseBorders(MRI *mri, int width) { return (NO_ERROR); } -static int mriNormalizeStds(MRI *mri) { +static int mriNormalizeStds(MRI *mri) +{ int x, y, z, width, height, depth, std, val; BUFTYPE *pstd, *pval; double mean_std; @@ -5025,7 +5105,8 @@ static int mriNormalizeStds(MRI *mri) { std = *pstd; if (std < mean_std) std = mean_std; *pstd++ = std; - } else + } + else pstd++; } } @@ -5038,7 +5119,8 @@ static int mriNormalizeStds(MRI *mri) { return (NO_ERROR); } #if USE_ITERATIVE_AVERAGING -static int m3daverageGradient(MORPH_3D *m3d, int niter) { +static int m3daverageGradient(MORPH_3D *m3d, int niter) +{ int i, j, k, width, height, depth, n, a, num; MORPH_NODE *mn; MNP *mnp, *mnp_nbr; @@ -5123,7 +5205,8 @@ static int m3daverageGradient(MORPH_3D *m3d, int niter) { return (NO_ERROR); } #else -static int m3dblurGradient(MORPH_3D *m3d, float sigma) { +static int m3dblurGradient(MORPH_3D *m3d, float sigma) +{ int i, j, k, i1, j1, k1, whalf, width, height, depth; MORPH_NODE *mn; MNP *mnp, *mnp_nbr; @@ -5222,7 +5305,8 @@ static int m3dblurGradient(MORPH_3D *m3d, float sigma) { } #endif -static int m3dCopyTempToGradient(MORPH_3D *m3d) { +static int m3dCopyTempToGradient(MORPH_3D *m3d) +{ int i, j, k, width, height, depth; MNP *mnp; @@ -5242,7 +5326,8 @@ static int m3dCopyTempToGradient(MORPH_3D *m3d) { } return (NO_ERROR); } -static int m3dcheck(MORPH_3D *m3d) { +static int m3dcheck(MORPH_3D *m3d) +{ MNP *mnp; int i, j, k; @@ -5259,7 +5344,8 @@ static int m3dcheck(MORPH_3D *m3d) { static float mriMaxRadius(MRI *mri, int low_val, int hi_val, float *px0, float *py0, float *pz0); int MRISmoveOrigin(MRI_SURFACE *mris, float x0, float y0, float z0); -static float mriMaxRadius(MRI *mri, int low_val, int hi_val, float *px0, float *py0, float *pz0) { +static float mriMaxRadius(MRI *mri, int low_val, int hi_val, float *px0, float *py0, float *pz0) +{ int x, y, z, width, depth, height, nvox; double xw, yw, zw, max_radius, radius, xd, yd, zd; float x0, y0, z0; @@ -5310,7 +5396,8 @@ static float mriMaxRadius(MRI *mri, int low_val, int hi_val, float *px0, float * return (max_radius); } -int MRISmoveOrigin(MRI_SURFACE *mris, float x0, float y0, float z0) { +int MRISmoveOrigin(MRI_SURFACE *mris, float x0, float y0, float z0) +{ int vno; VERTEX *v; float x, y, z, xlo, xhi, zlo, zhi, ylo, yhi; @@ -5347,7 +5434,8 @@ int MRISmoveOrigin(MRI_SURFACE *mris, float x0, float y0, float z0) { return (NO_ERROR); } -MRI_SURFACE *MRISshrinkWrapSkull(MRI *mri, MORPH_PARMS *parms) { +MRI_SURFACE *MRISshrinkWrapSkull(MRI *mri, MORPH_PARMS *parms) +{ MRI_SURFACE *mris; MRI *mri_smooth, *mri_kernel; float radius, max_radius, scale, x0, y0, z0, sx, sy, sz, thick; @@ -5437,7 +5525,8 @@ MRI_SURFACE *MRISshrinkWrapSkull(MRI *mri, MORPH_PARMS *parms) { w.r.t the i,j,kth node. ------------------------------------------------------*/ static int m3dCompressionTerm( - MORPH_3D *m3d, double l_compression, int i, int j, int k, double *pdx, double *pdy, double *pdz) { + MORPH_3D *m3d, double l_compression, int i, int j, int k, double *pdx, double *pdy, double *pdz) +{ int n, num; double dx, dy, dz, dist, delta, xgrad, ygrad, zgrad, expansion; MORPH_NODE *mn, *mn_nbr; @@ -5533,7 +5622,8 @@ static int m3dCompressionTerm( w.r.t the i,j,kth node. ------------------------------------------------------*/ static int m3dNonlinearDistanceTerm( - MORPH_3D *m3d, double l_nldist, int i, int j, int k, double *pdx, double *pdy, double *pdz) { + MORPH_3D *m3d, double l_nldist, int i, int j, int k, double *pdx, double *pdy, double *pdz) +{ int n, num; double dx, dy, dz, dist, delta, xgrad, ygrad, zgrad, expansion; MORPH_NODE *mn, *mn_nbr; @@ -5702,7 +5792,8 @@ m3dAverageNodeDistance(MORPH_3D *m3d, int i, int j, int k) Description ------------------------------------------------------*/ -static float m3dNodeAverageExpansion(MORPH_3D *m3d, int i, int j, int k) { +static float m3dNodeAverageExpansion(MORPH_3D *m3d, int i, int j, int k) +{ int n, num; double dx, dy, dz, dist, xgrad, ygrad, zgrad, avg_expansion; MORPH_NODE *mn, *mn_nbr; @@ -5781,7 +5872,8 @@ static float m3dNodeAverageExpansion(MORPH_3D *m3d, int i, int j, int k) { Description ------------------------------------------------------*/ -static double m3dCompressionSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) { +static double m3dCompressionSSE(MRI *mri_in, MRI *mri_ref, MORPH_3D *m3d) +{ int i, j, k, width, height, depth, n; MORPH_NODE *mn, *mn_nbr; MNP *mnp; @@ -5904,7 +5996,8 @@ m3dPutExpansionFactorInDx(MORPH_3D *m3d) Description ------------------------------------------------------*/ -int MRIeraseNeck(MRI *mri, NECK_PARMS *np) { +int MRIeraseNeck(MRI *mri, NECK_PARMS *np) +{ float dx, dy, dz, y, thick, x0, y0, z0; thick = mri->thick; @@ -5925,7 +6018,8 @@ int MRIeraseNeck(MRI *mri, NECK_PARMS *np) { Description ------------------------------------------------------*/ -static int m3dPositionBorderNodes(MORPH_3D *m3d) { +static int m3dPositionBorderNodes(MORPH_3D *m3d) +{ #if 0 int i, j, k, width, height, depth, n, num ; double dx, dy, dz, xavg, yavg, zavg ; @@ -6033,7 +6127,8 @@ static int m3dPositionBorderNodes(MORPH_3D *m3d) { return (NO_ERROR); } -static int m3dblurDx(MORPH_3D *m3d, float sigma) { +static int m3dblurDx(MORPH_3D *m3d, float sigma) +{ int i, j, k, i1, j1, k1, whalf, width, height, depth; MORPH_NODE *mn; MNP *mnp, *mnp_nbr; @@ -6125,7 +6220,8 @@ static int m3dblurDx(MORPH_3D *m3d, float sigma) { Description ------------------------------------------------------*/ -static int m3dTranslate(MORPH_3D *m3d, float dx, float dy, float dz) { +static int m3dTranslate(MORPH_3D *m3d, float dx, float dy, float dz) +{ MORPH_NODE *mn; int i, j, k, width, height, depth; @@ -6156,7 +6252,8 @@ static int m3dTranslate(MORPH_3D *m3d, float dx, float dy, float dz) { note that mri_in and mri_ref will be copied so that the neck can be erased from both without changing the caller's volumes. */ -static int m3RecomputeTranslation(MORPH_3D *m3d, MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) { +static int m3RecomputeTranslation(MORPH_3D *m3d, MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms) +{ float in_means[4], ref_means[4]; double dx, dy, dz; MRI *mri_in_xformed; @@ -6191,7 +6288,8 @@ static int m3RecomputeTranslation(MORPH_3D *m3d, MRI *mri_in, MRI *mri_ref, MORP /* transform in volume using mapping specified by mri_in_skull -> mri_ref_skull */ -static int m3dMorphSkull(MORPH_3D *m3d, MRI_SURFACE *mris_in_skull, MRI_SURFACE *mris_ref_skull, MRI *mri) { +static int m3dMorphSkull(MORPH_3D *m3d, MRI_SURFACE *mris_in_skull, MRI_SURFACE *mris_ref_skull, MRI *mri) +{ MHT *mht_in, *mht_ref; MORPH_NODE *mn; MNP *mnp; @@ -6275,7 +6373,8 @@ static int m3dMorphSkull(MORPH_3D *m3d, MRI_SURFACE *mris_in_skull, MRI_SURFACE scale = MAX_DX; else if (scale < MIN_DX) scale = MIN_DX; - } else { + } + else { scale = 1.0; #if 1 fprintf(stdout, "warning: node (%d,%d,%d) has zero in dist\n", i, j, k); @@ -6356,7 +6455,8 @@ static int m3dMorphSkull(MORPH_3D *m3d, MRI_SURFACE *mris_in_skull, MRI_SURFACE Description ------------------------------------------------------*/ -int MRIrigidAlign(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MATRIX *m_L) { +int MRIrigidAlign(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MATRIX *m_L) +{ int nlevels, i; MRI *mri_in_pyramid[MAX_LEVELS], *mri_ref_pyramid[MAX_LEVELS]; char base_name[STRLEN]; @@ -6484,7 +6584,8 @@ int MRIrigidAlign(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MATRIX *m_L) { /* for 3d vector macros */ #include "tritri.h" -static int mriOrthonormalizeTransform(MATRIX *m_L) { +static int mriOrthonormalizeTransform(MATRIX *m_L) +{ double dot, c1[3], c2[3], c3[3], len; int i; @@ -6583,7 +6684,8 @@ integration_step(float *p) static void dfp_step_func(int itno, float rms, void *vparms, float *p); static void dfp_em_step_func(int itno, float rms, void *vparms, float *p); -static void dfp_step_func(int itno, float sse, void *vparms, float *p) { +static void dfp_step_func(int itno, float sse, void *vparms, float *p) +{ MP *parms = (MP *)vparms; int i, row, col; float rms; @@ -6604,7 +6706,8 @@ static void dfp_step_func(int itno, float sse, void *vparms, float *p) { parms->m_xform_mean = m_save; intensity_rms = sqrt(intensity_rms); fprintf(stdout, "%03d: %2.3f (intensity=%2.3f)\n", parms->start_t + itno, rms, intensity_rms); - } else { + } + else { fprintf(stdout, "%03d: %2.3f\n", parms->start_t + itno, rms); } @@ -6630,7 +6733,8 @@ static void dfp_step_func(int itno, float sse, void *vparms, float *p) { fflush(stdout); } -static void dfp_em_step_func(int itno, float sse, void *vparms, float *p) { +static void dfp_em_step_func(int itno, float sse, void *vparms, float *p) +{ MP *parms = (MP *)vparms; int i, row, col; @@ -6668,7 +6772,8 @@ static void dfp_em_step_func(int itno, float sse, void *vparms, float *p) { fflush(stdout); } -static int mriQuasiNewtonLinearAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MP *parms) { +static int mriQuasiNewtonLinearAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MP *parms) +{ float p[5 * 4], fold, fnew; int row, col, i, iter, steps; MATRIX *m_L; @@ -6730,7 +6835,8 @@ static int mriQuasiNewtonLinearAlignPyramidLevel(MRI *mri_in, MRI *mri_ref, MP * Description ------------------------------------------------------*/ -static void computeRigidAlignmentGradient(float *p, float *g) { +static void computeRigidAlignmentGradient(float *p, float *g) +{ int width, height, depth, row, col, i, y1, y2, y3; VECTOR *v_X, *v_Y, *v_Yk; /* original and transformed coordinate systems */ VECTOR *v_crop; @@ -6770,7 +6876,8 @@ static void computeRigidAlignmentGradient(float *p, float *g) { m_crop = MRIvoxelXformToRasXform(mri_ref, parms->mri_crop, m_tmp, NULL); MatrixFree(&m_tmp); v_crop = VectorAlloc(4, MATRIX_REAL); - } else + } + else v_crop = m_crop = NULL; width = mri_in->width; @@ -6826,7 +6933,8 @@ static void computeRigidAlignmentGradient(float *p, float *g) { if (FZERO(in_val)) /* don't compute errors from cropping */ continue ; #endif - } else + } + else in_val = 0.0; delta = ref_wt * (ref_val - in_val) / std; @@ -6913,7 +7021,8 @@ static void computeRigidAlignmentGradient(float *p, float *g) { MatrixFree(&m_L); MatrixFree(&m_dL); } -static float computeRigidAlignmentErrorFunctional(float *p) { +static float computeRigidAlignmentErrorFunctional(float *p) +{ int y1, y2, y3, width, height, depth, row, col, i; VECTOR *v_X, *v_Y, *v_crop; /* original and transformed coordinate systems */ double ref_val, in_val, x1, x2, x3; @@ -6944,7 +7053,8 @@ static float computeRigidAlignmentErrorFunctional(float *p) { m_crop = MRIvoxelXformToRasXform(mri_ref, parms->mri_crop, m_tmp, NULL); MatrixFree(&m_tmp); v_crop = VectorAlloc(4, MATRIX_REAL); - } else + } + else v_crop = m_crop = NULL; mean_std = mri_ref->mean; @@ -6991,7 +7101,8 @@ static float computeRigidAlignmentErrorFunctional(float *p) { if (FZERO(in_val)) /* don't compute errors from cropping */ continue ; #endif - } else /* out of bounds, assume in val is 0 */ + } + else /* out of bounds, assume in val is 0 */ in_val = 0; wt = MRIsampleReferenceWeighting(mri_ref, y1, y2, y3); @@ -7045,7 +7156,8 @@ static float computeRigidAlignmentErrorFunctional(float *p) { Description ------------------------------------------------------*/ static void // in out -computeEMAlignmentGradient(float *p, float *g) { +computeEMAlignmentGradient(float *p, float *g) +{ #if 1 int width, height, depth, row, col, i, xn, yn, zn, xv, yv, zv, n, ndets = 0; VECTOR *v_X, *v_Y, *v_means, *v_X_T; /* original and transformed coordinate systems */ @@ -7120,7 +7232,8 @@ computeEMAlignmentGradient(float *p, float *g) { det = MatrixDeterminant(m_inv_cov); det_total += det; ndets++; - } else { + } + else { MatrixClear(v_means); MatrixIdentity(gca->ninputs, m_inv_cov); } @@ -7178,7 +7291,8 @@ computeEMAlignmentGradient(float *p, float *g) { VectorFree(&v_means); #endif } -static float computeEMAlignmentErrorFunctional(float *p) { +static float computeEMAlignmentErrorFunctional(float *p) +{ float log_p; LTA *lta, *old_lta; MATRIX *m_L; @@ -7387,7 +7501,8 @@ computeRigidAlignmentErrorFunctionalAndGradient(int index, float *p, #endif #define HANNING_RADIUS 100 -int MRIsampleReferenceWeightingGradient(MRI *mri, int x, int y, int z, double *pdx, double *pdy, double *pdz) { +int MRIsampleReferenceWeightingGradient(MRI *mri, int x, int y, int z, double *pdx, double *pdy, double *pdz) +{ double dx, dy, dz, vp1, vm1; vp1 = MRIsampleReferenceWeighting(mri, x + 1, y, z); @@ -7410,7 +7525,8 @@ int MRIsampleReferenceWeightingGradient(MRI *mri, int x, int y, int z, double *p #define T0_X -1 #define T0_Y -10 #define T0_Z -17 -double MRIsampleReferenceWeighting(MRI *mri, int x, int y, int z) { +double MRIsampleReferenceWeighting(MRI *mri, int x, int y, int z) +{ #if 0 double wt, dist ; double x_ras, y_ras, z_ras, dx, dy, dz ; @@ -7428,7 +7544,8 @@ double MRIsampleReferenceWeighting(MRI *mri, int x, int y, int z) { } #define MAX_CLASSES 4 -int MRIemAlign(MRI *mri_in, GCA *gca, MORPH_PARMS *parms, MATRIX *m_L) { +int MRIemAlign(MRI *mri_in, GCA *gca, MORPH_PARMS *parms, MATRIX *m_L) +{ int i; char base_name[STRLEN]; float pcurrent, pold; @@ -7501,7 +7618,8 @@ int MRIemAlign(MRI *mri_in, GCA *gca, MORPH_PARMS *parms, MATRIX *m_L) { /* mriOrthonormalizeTransform(parms->lta->xforms[0].m_L) ;*/ return (NO_ERROR); } -int MRIquasiNewtonAlignVolumes(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MATRIX *m_L) { +int MRIquasiNewtonAlignVolumes(MRI *mri_in, MRI *mri_ref, MORPH_PARMS *parms, MATRIX *m_L) +{ int i; char base_name[STRLEN]; float pcurrent, pold; @@ -7620,7 +7738,8 @@ write_snapshot(MRI *mri_source, MRI *mri_target, MATRIX *m_vox_xform, #endif /* compute mean squared error of two images with a transform */ static double compute_likelihood( - VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L, float scale_factor, int map_both_ways) { + VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L, float scale_factor, int map_both_ways) +{ int x, y, z, width, height, depth, hwidth, hheight, hdepth, i; VECTOR *v1, *v2; MRI *mri_target, *mri_source; @@ -7730,7 +7849,8 @@ MATRIX *MRIpowellAlignImages(MRI *mri_source, MATRIX *m_constraint, MRI *mri_source_mask, MRI *mri_target_mask, - int map_both_ways) { + int map_both_ways) +{ int i; float fmin, fmax; VOXEL_LIST *vl_target, *vl_source; @@ -7773,7 +7893,8 @@ static int powell_minimize(VOXEL_LIST *vl_source, MATRIX *mat, float *pscale_factor, MATRIX *m_constraint, - int map_both_ways) { + int map_both_ways) +{ float *p, **xi, fret, fstart, scale_factor, min_sse; int i, r, c, iter; p = vector(1, NPARMS + 1); @@ -7928,7 +8049,8 @@ static int powell_minimize(VOXEL_LIST *vl_source, if (pscale_factor) *pscale_factor = scale_factor; return (NO_ERROR); } -static float compute_powell_sse(float *p) { +static float compute_powell_sse(float *p) +{ static MATRIX *mat = NULL; float error, scale_factor; int i, r, c; @@ -7954,7 +8076,8 @@ static float compute_powell_sse(float *p) { extern void (*user_call_func)(float[]); -static int mriQuasiNewtonEMAlignPyramidLevel(MRI *mri_in, GCA *gca, MP *parms) { +static int mriQuasiNewtonEMAlignPyramidLevel(MRI *mri_in, GCA *gca, MP *parms) +{ float p[5 * 5], fold, fnew; int row, col, i, iter, steps, retval; MATRIX *m_L; @@ -8022,7 +8145,8 @@ static int mriQuasiNewtonEMAlignPyramidLevel(MRI *mri_in, GCA *gca, MP *parms) { return (NO_ERROR); } -MATRIX *MRIfaridAlignImages(MRI *mri_source, MRI *mri_target, MATRIX *m_L) { +MATRIX *MRIfaridAlignImages(MRI *mri_source, MRI *mri_target, MATRIX *m_L) +{ // compute linear registration using Hanry Farid's method float fmin, fmax; VOXEL_LIST *vl_target, *vl_source; @@ -8058,7 +8182,8 @@ MATRIX *MRIfaridAlignImages(MRI *mri_source, MRI *mri_target, MATRIX *m_L) { } static int ComputeStepTransform( - VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, float cx, float cy, float cz, MATRIX *Minc) { + VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, float cx, float cy, float cz, MATRIX *Minc) +{ //(cx, cy, cz) is used to translate the coordinates system to be centered at it; may help reduce numerical errors int i, j, k, width, height, depth; int x, y, z; @@ -8158,7 +8283,8 @@ static int ComputeStepTransform( Mvec[8] = 1.0; Mvec[12] = 1.0; if (NPARMS == 14) Mvec[13] = 0.0; // offset - } else { + } + else { for (i = 1; i <= NPARMS; i++) for (j = 1; j <= NPARMS; j++) Mvec[i - 1] += invCC->rptr[i][j] * VECTOR_ELT(sumCk, j); } @@ -8206,11 +8332,13 @@ static int ComputeStepTransform( else printf("final contrast scaling = %2.2f\n", Mvec[12]); return 1; // converged - } else + } + else return 0; } -static int farid_align(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L) { +static int farid_align(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L) +{ int iterations; int i; int width, height, depth, x, y, z; @@ -8314,7 +8442,8 @@ static int farid_align(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L if (iterations == 31) { // printf("Not converged yet after 30 iterations \n"); return 0; - } else + } + else return 1; } @@ -8323,7 +8452,8 @@ static float compute_powell_label_sse(float *p); static double compute_label_likelihood(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L); /* compute mean squared error of two label images with a transform */ -static double compute_label_likelihood(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L) { +static double compute_label_likelihood(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *m_L) +{ int x, y, z, width, height, depth, hwidth, hheight, hdepth, i; VECTOR *v1, *v2; MRI *mri_target, *mri_source; @@ -8382,7 +8512,8 @@ static double compute_label_likelihood(VOXEL_LIST *vl_source, VOXEL_LIST *vl_tar return (-sqrt(sse / (double)(vl_target->nvox + vl_source->nvox))); } -MATRIX *MRIpowellAlignLabels(MRI *mri_source, MRI *mri_target, MATRIX *m_L) { +MATRIX *MRIpowellAlignLabels(MRI *mri_source, MRI *mri_target, MATRIX *m_L) +{ // align two label volumes VOXEL_LIST *vl_target, *vl_source; @@ -8412,7 +8543,8 @@ MATRIX *MRIpowellAlignLabels(MRI *mri_source, MRI *mri_target, MATRIX *m_L) { #endif #define TOL 1e-5 -static int powell_minimize_label(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *mat) { +static int powell_minimize_label(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, MATRIX *mat) +{ // used for registration of two label volumes float *p, **xi, fret, fstart; int i, r, c, iter; @@ -8471,7 +8603,8 @@ static int powell_minimize_label(VOXEL_LIST *vl_source, VOXEL_LIST *vl_target, M return (NO_ERROR); } -static float compute_powell_label_sse(float *p) { +static float compute_powell_label_sse(float *p) +{ static MATRIX *mat = NULL; float error; int i, r, c; @@ -8508,7 +8641,8 @@ double MRIcomputeOptimalLinearXform(MRI *mri_source, float trans_steps, int nreductions, char *base_name, - int map_both_ways) { + int map_both_ways) +{ MATRIX *m_rot, *m_x_rot, *m_y_rot, *m_z_rot, *m_tmp, *m_L_tmp, *m_origin_inv, *m_tmp2, *m_scale, *m_trans, *m_tmp3 = NULL, *m_origin; double x_angle, y_angle, z_angle, x_max_rot; @@ -8746,7 +8880,8 @@ double MRIcomputeOptimalLinearXform(MRI *mri_source, return (max_log_p); } -static double mriIntensitySSE(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) { +static double mriIntensitySSE(MRI *mri_in, MRI *mri_ref, MATRIX *m_L) +{ int x, y, z; VECTOR *v1, *v2; double xd, yd, zd, sse, width, height, depth; diff --git a/utils/mrinorm.c b/utils/mrinorm.c index 7b4afb49d53..c474dd1f406 100644 --- a/utils/mrinorm.c +++ b/utils/mrinorm.c @@ -111,7 +111,8 @@ static char *bias_volume_fname = NULL; ------------------------------------------------------*/ #define BIAS_IMAGE_WIDTH 25 -MRI *MRIsplineNormalize(MRI *mri_src, MRI *mri_dst, MRI **pmri_field, float *inputs, float *outputs, int npoints) { +MRI *MRIsplineNormalize(MRI *mri_src, MRI *mri_dst, MRI **pmri_field, float *inputs, float *outputs, int npoints) +{ int width, height, depth, x, y, z, i; BUFTYPE *pfield = NULL; float outputs_2[MAX_SPLINE_POINTS], frac; @@ -125,7 +126,8 @@ MRI *MRIsplineNormalize(MRI *mri_src, MRI *mri_dst, MRI **pmri_field, float *inp cp = getenv("RAN"); if (cp) { d = atof(cp); - } else { + } + else { d = 0.0; } @@ -168,7 +170,8 @@ MRI *MRIsplineNormalize(MRI *mri_src, MRI *mri_dst, MRI **pmri_field, float *inp { if (dval > 255) { dval = 255; - } else if (dval < 0) { + } + else if (dval < 0) { dval = 0; } } @@ -179,7 +182,8 @@ MRI *MRIsplineNormalize(MRI *mri_src, MRI *mri_dst, MRI **pmri_field, float *inp return (mri_dst); } static MRI *mriSplineNormalizeShort( - MRI *mri_src, MRI *mri_dst, MRI **pmri_field, float *inputs, float *outputs, int npoints) { + MRI *mri_src, MRI *mri_dst, MRI **pmri_field, float *inputs, float *outputs, int npoints) +{ int width, height, depth, x, y, z, i, dval; short *psrc, *pdst, sval; char *pfield = NULL; @@ -191,7 +195,8 @@ static MRI *mriSplineNormalizeShort( cp = getenv("RAN"); if (cp) { d = atof(cp); - } else { + } + else { d = 0.0; } @@ -230,7 +235,8 @@ static MRI *mriSplineNormalizeShort( dval = nint((float)sval * frac + randomNumber(0.0, d)); if (dval > 255) { dval = 255; - } else if (dval < 0) { + } + else if (dval < 0) { dval = 0; } *pdst++ = (short)dval; @@ -250,7 +256,8 @@ static MRI *mriSplineNormalizeShort( the hsize x hsize region around it (hsize >> wsize) and around the corresponding region in mri_template, and adjust ------------------------------------------------------*/ -MRI *MRIadaptiveHistoNormalize(MRI *mri_src, MRI *mri_norm, MRI *mri_template, int wsize, int hsize, int low) { +MRI *MRIadaptiveHistoNormalize(MRI *mri_src, MRI *mri_norm, MRI *mri_template, int wsize, int hsize, int low) +{ int width, height, depth, woff; MRI_REGION wreg, h_src_reg, h_tmp_reg, h_clip_reg; @@ -323,7 +330,8 @@ MRI *MRIhistoNormalizeRegion(MRI *mri_src, int low, MRI_REGION *wreg, MRI_REGION *h_src_reg, - MRI_REGION *h_tmp_reg) { + MRI_REGION *h_tmp_reg) +{ HISTOGRAM h_fwd_eq, h_template_eq, h_norm; MRIgetEqualizeHistoRegion(mri_src, &h_fwd_eq, low, h_src_reg, 0); @@ -355,7 +363,8 @@ MRI *MRIhistoNormalizeRegion(MRI *mri_src, Description ------------------------------------------------------*/ -MRI *MRIhistoNormalize(MRI *mri_src, MRI *mri_norm, MRI *mri_template, int low, int high) { +MRI *MRIhistoNormalize(MRI *mri_src, MRI *mri_norm, MRI *mri_template, int low, int high) +{ HISTOGRAM h_fwd_eq, h_template_eq, h_norm; HISTOclear(&h_fwd_eq, &h_fwd_eq); @@ -390,13 +399,9 @@ MRI *MRIhistoNormalize(MRI *mri_src, MRI *mri_norm, MRI *mri_template, int low, ------------------------------------------------------*/ #define WINDOW_WIDTH 120 /* in millimeters */ -int MRInormInit(MRI *mri, - MNI *mni, - int windows_above_t0, - int windows_below_t0, - int wsize, - int desired_wm_value, - float smooth_sigma) { +int MRInormInit( + MRI *mri, MNI *mni, int windows_above_t0, int windows_below_t0, int wsize, int desired_wm_value, float smooth_sigma) +{ MRI_REGION *reg; int i, x, y, z, dx, dy, dz, nup, z_offset, nwindows; int x0_tal, y0_tal, z0_tal; @@ -421,7 +426,8 @@ int MRInormInit(MRI *mri, } if (FZERO(smooth_sigma)) { smooth_sigma = mni->smooth_sigma = DEFAULT_SMOOTH_SIGMA; - } else { + } + else { mni->smooth_sigma = smooth_sigma; } // look for talairach.xfm @@ -458,7 +464,8 @@ int MRInormInit(MRI *mri, if (getenv("NO_AVERAGE305")) // if this is set { fprintf(stderr, "INFO: tal dst c_(r,a,s) not modified\n"); - } else { + } + else { fprintf(stderr, "INFO: Modifying talairach volume c_(r,a,s) " "based on average_305\n"); @@ -479,7 +486,8 @@ int MRInormInit(MRI *mri, y0_tal = nint(y0); z0_tal = nint(z0); LTAfree(<a); - } else /* no Talairach information available */ + } + else /* no Talairach information available */ { MRI_REGION bbox; @@ -499,13 +507,15 @@ int MRInormInit(MRI *mri, if (windows_above_t0 > 0) { mni->windows_above_t0 = windows_above_t0; - } else { + } + else { windows_above_t0 = mni->windows_above_t0 = DEFAULT_WINDOWS_ABOVE_T0; } if (windows_below_t0 > 0) { mni->windows_below_t0 = windows_below_t0; - } else { + } + else { windows_below_t0 = mni->windows_below_t0 = DEFAULT_WINDOWS_BELOW_T0; } nwindows = mni->windows_above_t0 + mni->windows_below_t0; @@ -531,7 +541,8 @@ int MRInormInit(MRI *mri, { nup = windows_above_t0 - i; size_mod = pow(SIZE_MOD, (double)nup); - } else { + } + else { size_mod = 1.0f; } @@ -560,7 +571,8 @@ int MRInormInit(MRI *mri, Description ------------------------------------------------------*/ #define TOO_BRIGHT 225 -int MRInormFillHistograms(MRI *mri, MNI *mni) { +int MRInormFillHistograms(MRI *mri, MNI *mni) +{ int i, nwindows; nwindows = mni->windows_above_t0 + mni->windows_below_t0; @@ -578,7 +590,8 @@ int MRInormFillHistograms(MRI *mri, MNI *mni) { Description ------------------------------------------------------*/ -int MRInormFindPeaks(MNI *mni, float *inputs, float *outputs) { +int MRInormFindPeaks(MNI *mni, float *inputs, float *outputs) +{ int i, peak, deleted, nwindows, npeaks, whalf = (HISTO_WINDOW_SIZE - 1) / 2; HISTOGRAM *hsmooth = NULL; MRI_REGION *reg; @@ -590,7 +603,8 @@ int MRInormFindPeaks(MNI *mni, float *inputs, float *outputs) { peak = HISTOfindLastPeakInRegion(hsmooth, HISTO_WINDOW_SIZE, MIN_HISTO_PCT, whalf, hsmooth->nbins - whalf); if (peak < 0) { deleted++; - } else { + } + else { inputs[i - deleted] = (float)reg->y + (float)reg->dy / 2.0f; #if 0 outputs[i-deleted] = mni->desired_wm_value / (float)peak ; @@ -635,7 +649,8 @@ int MRInormFindPeaks(MNI *mni, float *inputs, float *outputs) { one is more likely to have both fwd and bkwd derivatives far from the mean). ------------------------------------------------------*/ -int MRInormCheckPeaks(MNI *mni, float *inputs, float *outputs, int npeaks) { +int MRInormCheckPeaks(MNI *mni, float *inputs, float *outputs, int npeaks) +{ int starting_slice, slice, deleted[MAX_SPLINE_POINTS], old_slice, n; float Iup, I, Idown, dI, dy, grad, max_gradient; int i; @@ -651,7 +666,8 @@ int MRInormCheckPeaks(MNI *mni, float *inputs, float *outputs, int npeaks) { if (FZERO(mni->max_gradient)) { max_gradient = MAX_GRADIENT; - } else { + } + else { max_gradient = mni->max_gradient; } @@ -685,9 +701,11 @@ int MRInormCheckPeaks(MNI *mni, float *inputs, float *outputs, int npeaks) { if ((I >= MIN(Iup, Idown)) && (I <= MAX(Iup, Idown))) { starting_slice = starting_slice; - } else if ((Iup >= MIN(I, Idown)) && (Iup <= MAX(I, Idown))) { + } + else if ((Iup >= MIN(I, Idown)) && (Iup <= MAX(I, Idown))) { starting_slice = starting_slice - SLICE_OFFSET; - } else { + } + else { starting_slice = starting_slice + SLICE_OFFSET; } @@ -706,7 +724,8 @@ int MRInormCheckPeaks(MNI *mni, float *inputs, float *outputs, int npeaks) { deleted[slice] = ((grad > max_gradient) || ((slice - old_slice) > MAX_SKIPPED)); if (!deleted[slice]) { old_slice = slice; - } else if (Gdiag & DIAG_SHOW) + } + else if (Gdiag & DIAG_SHOW) fprintf(stderr, "deleting peak[%d]=%2.0f, grad = %2.0f / %2.0f = %2.1f\n", slice, outputs[slice], dI, dy, grad); } @@ -723,7 +742,8 @@ int MRInormCheckPeaks(MNI *mni, float *inputs, float *outputs, int npeaks) { deleted[slice] = ((grad > max_gradient) || ((old_slice - slice) > MAX_SKIPPED)); if (!deleted[slice]) { old_slice = slice; - } else if (Gdiag & DIAG_SHOW) + } + else if (Gdiag & DIAG_SHOW) fprintf(stderr, "deleting peak[%d]=%2.0f, grad = %2.0f / %2.0f = %2.1f\n", slice, outputs[slice], dI, dy, grad); } @@ -751,7 +771,8 @@ int MRInormCheckPeaks(MNI *mni, float *inputs, float *outputs, int npeaks) { Description ------------------------------------------------------*/ -MRI *MRInormalize(MRI *mri_src, MRI *mri_dst, MNI *mni) { +MRI *MRInormalize(MRI *mri_src, MRI *mri_dst, MNI *mni) +{ float inputs[MAX_SPLINE_POINTS], outputs[MAX_SPLINE_POINTS]; int npeaks, dealloc = 0; @@ -806,7 +827,8 @@ MRI *MRInormFindControlPoints(MRI *mri_src, MRI *mri_ctrl, int which, int scan_type, - MRI *mri_not_control) { + MRI *mri_not_control) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi; int *pxi, *pyi, *pzi, ctrl, nctrl, nfilled, too_low, total_filled; int n, whalf, pass = 0; @@ -937,7 +959,8 @@ MRI *MRInormFindControlPoints(MRI *mri_src, } } } - } else + } + else ctrl = 0; if (ctrl) nctrl++; @@ -986,7 +1009,8 @@ MRI *MRInormFindControlPoints(MRI *mri_src, } } } - } else + } + else ctrl = 0; if (ctrl) nctrl++; @@ -1437,7 +1461,8 @@ MRI *MRInormFindControlPoints(MRI *mri_src, } MRI *MRInormGentlyFindControlPoints( - MRI *mri_src, float wm_target, float intensity_above, float intensity_below, MRI *mri_ctrl, MRI *mri_not_control) { + MRI *mri_src, float wm_target, float intensity_above, float intensity_below, MRI *mri_ctrl, MRI *mri_not_control) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi; int *pxi, *pyi, *pzi, ctrl, nctrl, val0, val, whalf = 0; BUFTYPE low_thresh, hi_thresh; @@ -1501,7 +1526,8 @@ MRI *MRInormGentlyFindControlPoints( } } } - } else { + } + else { ctrl = 0; } if (ctrl) { @@ -1556,7 +1582,8 @@ MRI *MRInormGentlyFindControlPoints( } } } - } else { + } + else { ctrl = 0; } if (ctrl) { @@ -1606,7 +1633,8 @@ MRI *MRInormFindControlPointsInWindow(MRI *mri_src, const char *debug_str, int *pnctrl, int scan_type, - MRI *mri_not_control) { + MRI *mri_not_control) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi, *pxi, *pyi; int *pzi, ctrl, nctrl, val0, val = 0, whalf; float low_thresh, hi_thresh; @@ -1654,7 +1682,8 @@ MRI *MRInormFindControlPointsInWindow(MRI *mri_src, } } } - } else + } + else ctrl = 0; if (ctrl) nctrl++; @@ -1709,7 +1738,8 @@ MRIbuildBiasImage(MRI *mri_src, MRI *mri_ctrl, MRI *mri_bias) return(mri_bias) ; } #else -MRI *MRIbuildBiasImage(MRI *mri_src, MRI *mri_ctrl, MRI *mri_bias, float sigma) { +MRI *MRIbuildBiasImage(MRI *mri_src, MRI *mri_ctrl, MRI *mri_bias, float sigma) +{ // int width, height, depth; int x, y, z; MRI *mri_kernel; @@ -1763,7 +1793,8 @@ MRI *MRI3dNormalize(MRI *mri_orig, int prune, float bias_sigma, int scan_type, - MRI *mri_not_control) { + MRI *mri_not_control) +{ int width, height, depth, x, y, z, n; float norm, src, bias; MRI *mri_bias = NULL, *mri_ctrl, *mri_tmp; @@ -1787,7 +1818,8 @@ MRI *MRI3dNormalize(MRI *mri_orig, mri_ctrl = MRInormFindControlPoints( mri_src, wm_target, intensity_above, intensity_below, NULL, n, scan_type, mri_not_control); if (mri_ctrl == NULL) ErrorExit(ERROR_UNSUPPORTED, "MRInormFindControlPoints failed"); - } else { + } + else { int nctrl; mri_ctrl = MRIalloc(mri_src->width, mri_src->height, mri_src->depth, MRI_UCHAR); @@ -1886,7 +1918,8 @@ MRI *MRI3dGentleNormalize(MRI *mri_src, float intensity_below, int only_file, float bias_sigma, - MRI *mri_not_control) { + MRI *mri_not_control) +{ int width, height, depth, x, y, z, src, bias, free_bias; float norm; @@ -1965,7 +1998,8 @@ MRI *MRI3dGentleNormalize(MRI *mri_src, pass++; } MRIfree(&mri_ctrl); - } else { + } + else { free_bias = 0; } @@ -1980,7 +2014,8 @@ MRI *MRI3dGentleNormalize(MRI *mri_src, if (!bias) /* should never happen */ { norm = (float)src; - } else { + } + else { norm = (float)src * (float)wm_target / (float)bias; } if (norm > 255.0f && mri_norm->type == MRI_UCHAR) { @@ -2004,7 +2039,8 @@ MRI *MRI3dGentleNormalize(MRI *mri_src, Description ------------------------------------------------------*/ -static MRI *mriBuildVoronoiDiagramShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) { +static MRI *mriBuildVoronoiDiagramShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi; int *pxi, *pyi, *pzi, nchanged, n, total, visited; BUFTYPE *pmarked, ctrl, mark; @@ -2041,8 +2077,9 @@ static MRI *mriBuildVoronoiDiagramShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds src = (float)*psrc++; if (!ctrl) { val = 0; - } else /* find mean in region, - and use it as bias field estimate */ + } + else /* find mean in region, + and use it as bias field estimate */ { val = src; total++; @@ -2126,7 +2163,8 @@ static MRI *mriBuildVoronoiDiagramShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds { *pdst++ = nint(mean / (float)n); nchanged++; - } else /* should never happen anymore */ + } + else /* should never happen anymore */ { pdst++; } @@ -2161,7 +2199,8 @@ static MRI *mriBuildVoronoiDiagramShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds Description ------------------------------------------------------*/ -static MRI *mriBuildVoronoiDiagramFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) { +static MRI *mriBuildVoronoiDiagramFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi; int *pxi, *pyi, *pzi, nchanged, n, total, visited; BUFTYPE ctrl, mark; @@ -2197,7 +2236,8 @@ static MRI *mriBuildVoronoiDiagramFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds src = (float)*psrc++; if (!ctrl) { val = 0; - } else // find mean in region, and use it as bias field estimate + } + else // find mean in region, and use it as bias field estimate { val = src; total++; @@ -2282,7 +2322,8 @@ static MRI *mriBuildVoronoiDiagramFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds { *pdst++ = (mean / (float)n); nchanged++; - } else /* should never happen anymore */ + } + else /* should never happen anymore */ { pdst++; } @@ -2312,7 +2353,8 @@ static MRI *mriBuildVoronoiDiagramFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds Description ------------------------------------------------------*/ -static MRI *mriBuildVoronoiDiagramUchar(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) { +static MRI *mriBuildVoronoiDiagramUchar(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi; int *pxi, *pyi, *pzi, nchanged, n, total, visited; int ctrl, mark; @@ -2355,7 +2397,8 @@ static MRI *mriBuildVoronoiDiagramUchar(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds src = (float)*psrc++; if (!ctrl) { val = 0; - } else /* find mean in region, and use it as bias field estimate */ + } + else /* find mean in region, and use it as bias field estimate */ { val = src; total++; @@ -2440,7 +2483,8 @@ static MRI *mriBuildVoronoiDiagramUchar(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds { *pdst++ = mean / (float)n; nchanged++; - } else /* should never happen anymore */ + } + else /* should never happen anymore */ { pdst++; } @@ -2472,7 +2516,8 @@ static MRI *mriBuildVoronoiDiagramUchar(MRI *mri_src, MRI *mri_ctrl, MRI *mri_ds Description ------------------------------------------------------*/ -MRI *MRIbuildVoronoiDiagram(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) { +MRI *MRIbuildVoronoiDiagram(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) +{ switch (mri_src->type) { case MRI_FLOAT: return (mriBuildVoronoiDiagramFloat(mri_src, mri_ctrl, mri_dst)); @@ -2493,14 +2538,16 @@ MRI *MRIbuildVoronoiDiagram(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIsoapBubble(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter, float min_change) { +MRI *MRIsoapBubble(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter, float min_change) +{ int width, height, depth, frames, x, y, z, f, xk, yk, zk, xi, yi, zi, i, *pxi, *pyi, *pzi, mean; BUFTYPE ctrl, *ptmp; MRI *mri_tmp; if (mri_src->type == MRI_FLOAT) { return (mriSoapBubbleFloat(mri_src, mri_ctrl, mri_dst, niter, min_change)); - } else if (mri_src->type == MRI_SHORT) { + } + else if (mri_src->type == MRI_SHORT) { return (mriSoapBubbleShort(mri_src, mri_ctrl, mri_dst, niter)); } @@ -2570,7 +2617,8 @@ MRI *MRIsoapBubble(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter, float m Description ------------------------------------------------------*/ -MRI *MRIaverageFixedPoints(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) { +MRI *MRIaverageFixedPoints(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi, i, *pxi, *pyi, *pzi, mean, num; BUFTYPE *pctrl, ctrl, *ptmp; MRI *mri_tmp; @@ -2643,7 +2691,8 @@ MRI *MRIaverageFixedPoints(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) Description ------------------------------------------------------*/ -MRI *MRIsoapBubbleExpand(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) { +MRI *MRIsoapBubbleExpand(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi, i, *pxi, *pyi, *pzi; BUFTYPE *pctrl, ctrl, *ptmp; MRI *mri_tmp; @@ -2700,7 +2749,8 @@ MRI *MRIsoapBubbleExpand(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) { if (nvox) { *ptmp++ = (BUFTYPE)nint(mean / nvox); MRIvox(mri_ctrl, x, y, z) = CONTROL_TMP; - } else { + } + else { ptmp++; } } @@ -2816,7 +2866,8 @@ mriSoapBubbleFloat(MRI *mri_src, return(mri_dst) ; } #else -static MRI *mriSoapBubbleFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter, float min_change) { +static MRI *mriSoapBubbleFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter, float min_change) +{ int width, height, depth, frames, x, y, z, f, xk, yk, zk, xi, yi, zi, i, *pxi, *pyi, *pzi, num, x1, y1, z1, x2, y2, z2; BUFTYPE *pctrl, ctrl; @@ -2969,7 +3020,8 @@ static MRI *mriSoapBubbleFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int ni Description ------------------------------------------------------*/ -static MRI *mriSoapBubbleShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) { +static MRI *mriSoapBubbleShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) +{ int width, height, depth, frames, x, y, z, f, xk, yk, zk, xi, yi, zi, i, *pxi, *pyi, *pzi, num; BUFTYPE *pctrl, ctrl; short *ptmp; @@ -3073,7 +3125,8 @@ static MRI *mriSoapBubbleShort(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int ni Description ------------------------------------------------------*/ -static MRI *mriSoapBubbleExpandFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) { +static MRI *mriSoapBubbleExpandFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, int niter) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi, i, *pxi, *pyi, *pzi; BUFTYPE *pctrl, ctrl; float *ptmp, nvox, mean; @@ -3126,7 +3179,8 @@ static MRI *mriSoapBubbleExpandFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, if (nvox) { *ptmp++ = (float)mean / nvox; MRIvox(mri_ctrl, x, y, z) = CONTROL_TMP; - } else { + } + else { ptmp++; } } @@ -3153,7 +3207,8 @@ static MRI *mriSoapBubbleExpandFloat(MRI *mri_src, MRI *mri_ctrl, MRI *mri_dst, return (mri_dst); } -static MRI *mriMarkUnmarkedNeighbors(MRI *mri_src, MRI *mri_marked, MRI *mri_dst, int mark, int nbr_mark) { +static MRI *mriMarkUnmarkedNeighbors(MRI *mri_src, MRI *mri_marked, MRI *mri_dst, int mark, int nbr_mark) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi, *pxi, *pyi, *pzi, *psrc_int = NULL, val = 0; unsigned char *psrc_uchar = NULL; @@ -3176,9 +3231,11 @@ static MRI *mriMarkUnmarkedNeighbors(MRI *mri_src, MRI *mri_marked, MRI *mri_dst for (y = 0; y < height; y++) { if (mri_src->type == MRI_UCHAR) { psrc_uchar = &MRIvox(mri_src, 0, y, z); - } else if (mri_src->type == MRI_INT) { + } + else if (mri_src->type == MRI_INT) { psrc_int = &MRIIvox(mri_src, 0, y, z); - } else { + } + else { ErrorExit(ERROR_UNSUPPORTED, "mriMarkUnmarkedNeighbors: all inputs must be " "MRI_UCHAR or MRI_INT"); @@ -3186,7 +3243,8 @@ static MRI *mriMarkUnmarkedNeighbors(MRI *mri_src, MRI *mri_marked, MRI *mri_dst for (x = 0; x < width; x++) { if (mri_src->type == MRI_UCHAR) { val = *psrc_uchar++; - } else if (mri_src->type == MRI_INT) { + } + else if (mri_src->type == MRI_INT) { val = *psrc_int++; } if (val == mark) /* mark all neighbors */ @@ -3201,11 +3259,13 @@ static MRI *mriMarkUnmarkedNeighbors(MRI *mri_src, MRI *mri_marked, MRI *mri_dst if (MRIvox(mri_marked, xi, yi, zi) == CONTROL_NONE) { MRIvox(mri_dst, xi, yi, zi) = nbr_mark; } - } else if (mri_src->type == MRI_INT) { + } + else if (mri_src->type == MRI_INT) { if (MRIIvox(mri_marked, xi, yi, zi) == CONTROL_NONE) { MRIIvox(mri_dst, xi, yi, zi) = nbr_mark; } - } else { + } + else { ErrorExit(ERROR_UNSUPPORTED, "mriMarkUnmarkedNeighbors: all inputs must be " "MRI_UCHAR or MRI_INT"); @@ -3220,7 +3280,8 @@ static MRI *mriMarkUnmarkedNeighbors(MRI *mri_src, MRI *mri_marked, MRI *mri_dst return (mri_dst); } -static int mriRemoveOutliers(MRI *mri, int min_nbrs) { +static int mriRemoveOutliers(MRI *mri, int min_nbrs) +{ int width, height, depth, x, y, z, xk, yk, zk, xi, yi, zi; int *pxi, *pyi, *pzi, marked, nbrs, deleted; BUFTYPE *pmarked; @@ -3261,7 +3322,8 @@ static int mriRemoveOutliers(MRI *mri, int min_nbrs) { if (nbrs < min_nbrs) { deleted++; *pmarked++ = 0; - } else { + } + else { pmarked++; } } @@ -3337,7 +3399,8 @@ mriDownsampleCtrl2(MRI *mri_src, MRI *mri_dst) } #endif -int MRI3dUseFileControlPoints(MRI *mri, const char *fname) { +int MRI3dUseFileControlPoints(MRI *mri, const char *fname) +{ int i = 0; double xr, yr, zr; MPoint *pArray = 0; @@ -3436,7 +3499,8 @@ int MRI3dUseFileControlPoints(MRI *mri, const char *fname) { return (NO_ERROR); } -int MRI3dUseLabelControlPoints(MRI *mri, LABEL *control_point_label) { +int MRI3dUseLabelControlPoints(MRI *mri, LABEL *control_point_label) +{ int i = 0; MPoint *pArray = 0; int count = 0; @@ -3480,17 +3544,20 @@ int MRI3dUseLabelControlPoints(MRI *mri, LABEL *control_point_label) { return (NO_ERROR); } -int MRI3dWriteControlPoints(char *t_control_volume_fname) { +int MRI3dWriteControlPoints(char *t_control_volume_fname) +{ control_volume_fname = t_control_volume_fname; return (NO_ERROR); } -int MRI3dWriteBias(char *t_bias_volume_fname) { +int MRI3dWriteBias(char *t_bias_volume_fname) +{ bias_volume_fname = t_bias_volume_fname; return (NO_ERROR); } -int MRInormAddFileControlPoints(MRI *mri_ctrl, int value, MRI *mri) { +int MRInormAddFileControlPoints(MRI *mri_ctrl, int value, MRI *mri) +{ int i, nctrl, x, y, z; long bad = 0; @@ -3508,7 +3575,8 @@ int MRInormAddFileControlPoints(MRI *mri_ctrl, int value, MRI *mri) { nctrl++; } MRIvox(mri_ctrl, x, y, z) = value; - } else { + } + else { bad++; } } @@ -3846,7 +3914,8 @@ static int remove_gray_matter_control_points(MRI *mri_ctrl, float intensity_above, float intensity_below, int scan_type, - MRI *mri_not_control) { + MRI *mri_not_control) +{ MRI *mri_ctrl_outside, *mri_ctrl_inside, *mri_tmp = NULL; int n, x, y, z, xi, yi, zi, xk, yk, zk; int nremoved, removed, num, nretained, nclose_to_csf = 0; @@ -3987,7 +4056,8 @@ static int remove_gray_matter_control_points(MRI *mri_ctrl, (float)MIN_DISTANCE_TO_CSF); MRIvox(mri_ctrl, x, y, z) = CONTROL_NONE; nclose_to_csf++; - } else { + } + else { n = removed = 0; } if (val0 > low_thresh) /* pretty certain it's wm regardless */ @@ -4026,7 +4096,8 @@ static int remove_gray_matter_control_points(MRI *mri_ctrl, xi, yi, zi); - } else { + } + else { if (x == Gx && y == Gy && z == Gz) printf( "found nbhd val %2.0f " @@ -4086,7 +4157,8 @@ static int remove_gray_matter_control_points(MRI *mri_ctrl, return (NO_ERROR); } -static float csf_in_window(MRI *mri, int x0, int y0, int z0, float max_dist, float csf) { +static float csf_in_window(MRI *mri, int x0, int y0, int z0, float max_dist, float csf) +{ int xi, yi, zi, xk, yk, zk, whalf; float val, dx, dy, dz, dist; @@ -4118,7 +4190,8 @@ static float csf_in_window(MRI *mri, int x0, int y0, int z0, float max_dist, flo } } } - } else { + } + else { for (xk = -whalf; xk <= whalf; xk++) { xi = mri->xi[x0 + xk]; dx = SQR(xi - x0); @@ -4147,7 +4220,8 @@ static float csf_in_window(MRI *mri, int x0, int y0, int z0, float max_dist, flo return (0); } -static float find_tissue_intensities(MRI *mri_src, MRI *mri_ctrl, float *pwm, float *pgm, float *pcsf) { +static float find_tissue_intensities(MRI *mri_src, MRI *mri_ctrl, float *pwm, float *pgm, float *pcsf) +{ int csf_peak, thresh_bin /*, bg_end*/, wm_peak; // int wm_valley; int gm_peak, gm_valley; @@ -4192,7 +4266,8 @@ static float find_tissue_intensities(MRI *mri_src, MRI *mri_ctrl, float *pwm, fl HISTOclearBins(h, h, 0, 5); hsmooth = HISTOsmooth(h, NULL, 2); ; - } else { + } + else { #if 0 hsmooth = HISTOsmooth(h, NULL, 2) ; // no idea how this worked @@ -4271,7 +4346,8 @@ static float find_tissue_intensities(MRI *mri_src, MRI *mri_ctrl, float *pwm, fl #define WSIZE(mri) ((((int)((7.0 / mri->thick) / 2)) * 2) + 1) /* make sure it's odd */ #define MIN_WM_SNR 20 -MRI *MRInormFindHighSignalLowStdControlPoints(MRI *mri_src, MRI *mri_ctrl) { +MRI *MRInormFindHighSignalLowStdControlPoints(MRI *mri_src, MRI *mri_ctrl) +{ MRI *mri_ratio, *mri_mean, *mri_std; /*, *mri_tmp = NULL */ ; MRI_SEGMENTATION *mriseg; @@ -4360,7 +4436,8 @@ MRI *MRInormFindHighSignalLowStdControlPoints(MRI *mri_src, MRI *mri_ctrl) { return (mri_ctrl); } -MRI *MRInormalizeHighSignalLowStd(MRI *mri_src, MRI *mri_norm, float bias_sigma, float wm_target) { +MRI *MRInormalizeHighSignalLowStd(MRI *mri_src, MRI *mri_norm, float bias_sigma, float wm_target) +{ int x, y, z, width, depth, height; // int nctrl; MRI *mri_ctrl, *mri_bias; @@ -4391,7 +4468,8 @@ MRI *MRInormalizeHighSignalLowStd(MRI *mri_src, MRI *mri_norm, float bias_sigma, if (!bias) /* should never happen */ { norm = src; - } else { + } + else { norm = src * wm_target / bias; } if (norm > 255.0f && mri_norm->type == MRI_UCHAR) { @@ -4411,7 +4489,8 @@ MRI *MRInormalizeHighSignalLowStd(MRI *mri_src, MRI *mri_norm, float bias_sigma, return (mri_norm); } -MRI *MRIapplyBiasCorrection(MRI *mri_in, MRI *mri_bias, MRI *mri_out) { +MRI *MRIapplyBiasCorrection(MRI *mri_in, MRI *mri_bias, MRI *mri_out) +{ int x, y, z; double bias, val, xd, yd, zd; MATRIX *m_in_vox2ras, *m_bias_ras2vox, *m_vox2vox; @@ -4463,7 +4542,8 @@ MRI *MRIapplyBiasCorrection(MRI *mri_in, MRI *mri_bias, MRI *mri_out) { return (mri_out); } -MRI *MRIapplyBiasCorrectionSameGeometry(MRI *mri_in, MRI *mri_bias, MRI *mri_out, float target_val) { +MRI *MRIapplyBiasCorrectionSameGeometry(MRI *mri_in, MRI *mri_bias, MRI *mri_out, float target_val) +{ int x, y, z; double bias, val; diff --git a/utils/mripolv.c b/utils/mripolv.c index 08364752a93..604a636f13c 100644 --- a/utils/mripolv.c +++ b/utils/mripolv.c @@ -93,7 +93,8 @@ static void init_basis_vectors(void); Description ------------------------------------------------------*/ -MRI *MRIpolvMean(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) { +MRI *MRIpolvMean(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) +{ int width, height, depth, x, y, z, whalf, xk, yk, n, vertex, xi, yi, zi, *pxi, *pyi, *pzi; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase, total; BUFTYPE *pdst, *pptr; @@ -159,7 +160,8 @@ MRI *MRIpolvMean(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) { Description ------------------------------------------------------*/ -MRI *MRIpolvNormalCurvature(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) { +MRI *MRIpolvNormalCurvature(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) +{ int width, height, depth, x, y, z, whalf, yk, n, vertex, xi, yi, zi, *pxi, *pyi, *pzi; float nx, ny, nz, mean, var, val, std, *pdst; BUFTYPE *pptr; @@ -225,7 +227,8 @@ MRI *MRIpolvNormalCurvature(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize Description ------------------------------------------------------*/ -MRI *MRIpolvZscore(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) { +MRI *MRIpolvZscore(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) +{ int width, height, depth, x, y, z, whalf, yk, n, vertex, xi, yi, zi, *pxi, *pyi, *pzi; float nx, ny, nz, mean, var, val, std, *pdst, xf, yf, zf; BUFTYPE *pptr; @@ -296,7 +299,8 @@ MRI *MRIpolvZscore(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) { Description ------------------------------------------------------*/ -MRI *MRIpolvMedian(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) { +MRI *MRIpolvMedian(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) +{ int width, height, depth, x, y, z, whalf, xk, yk, n, vertex, xi, yi, zi, *pxi, *pyi, *pzi; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; BUFTYPE *pdst, *pptr, plane_vals[MAXLEN], *pvals; @@ -364,7 +368,8 @@ MRI *MRIpolvMedian(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize) { Description ------------------------------------------------------*/ -MRI *MRIpolvOrder(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, int thresh) { +MRI *MRIpolvOrder(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, int thresh) +{ int width, height, depth, x, y, z, whalf, xk, yk, n, vertex, xi, yi, zi, *pxi, *pyi, *pzi, order; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; BUFTYPE *pdst, *pptr, plane_vals[MAXLEN], *pvals; @@ -437,7 +442,8 @@ MRI *MRIpolvOrder(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, int thre Description ------------------------------------------------------*/ -MRI *MRIpolvMeanRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, MRI_REGION *region) { +MRI *MRIpolvMeanRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, MRI_REGION *region) +{ int width, height, depth, x, y, z, whalf, xk, yk, n, vertex, x0, y0, z0, xi, yi, zi, *pxi, *pyi, *pzi; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase, total; BUFTYPE *pdst, *pptr; @@ -530,7 +536,8 @@ MRI *MRIpolvMeanRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, MRI Description ------------------------------------------------------*/ -MRI *MRIpolvMedianRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, MRI_REGION *region) { +MRI *MRIpolvMedianRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, MRI_REGION *region) +{ int width, height, depth, x, y, z, whalf, xk, yk, n, vertex, x0, y0, z0, xi, yi, zi, *pxi, *pyi, *pzi, median_index; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; BUFTYPE *pdst, *pptr, plane_vals[MAXLEN], *pvals; @@ -624,7 +631,8 @@ MRI *MRIpolvMedianRegion(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, M Description ------------------------------------------------------*/ -MRI *MRIextractCpolvCoords(MRI *mri_src, int *px, int *py, int *pz, MRI *mri_polv, int x, int y, int z, int wsize) { +MRI *MRIextractCpolvCoords(MRI *mri_src, int *px, int *py, int *pz, MRI *mri_polv, int x, int y, int z, int wsize) +{ float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int vertex, whalf, xk, yk, xi, yi, zi; @@ -663,7 +671,8 @@ MRI *MRIextractCpolvCoords(MRI *mri_src, int *px, int *py, int *pz, MRI *mri_pol Description ------------------------------------------------------*/ -MRI *MRIextractCpolv(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int x, int y, int z, int wsize) { +MRI *MRIextractCpolv(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int x, int y, int z, int wsize) +{ float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int vertex, whalf, xk, yk, xi, yi, zi; @@ -713,7 +722,8 @@ MRI *MRIextractCpolv(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int x, int y, in Description ------------------------------------------------------*/ -MRI *MRIextractPolvPlane(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int x, int y, int z, int wsize) { +MRI *MRIextractPolvPlane(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int x, int y, int z, int wsize) +{ float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int vertex, whalf, xk, yk, xi, yi, zi; @@ -763,7 +773,8 @@ MRI *MRIextractPolvPlane(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int x, int y Description ------------------------------------------------------*/ -int MRIcountPlanarAboveThreshold(MRI *mri_src, int vertex, int x, int y, int z, int wsize, int lo_lim, int hi_lim) { +int MRIcountPlanarAboveThreshold(MRI *mri_src, int vertex, int x, int y, int z, int wsize, int lo_lim, int hi_lim) +{ int whalf, xk, yk, n, xi, yi, zi, *pxi, *pyi, *pzi, count; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; BUFTYPE val; @@ -814,7 +825,8 @@ int MRIcountPlanarAboveThreshold(MRI *mri_src, int vertex, int x, int y, int z, Description ------------------------------------------------------*/ -MRI *MRIplaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) { +MRI *MRIplaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, vertex, xk, yk, zk, pno, mini, maxi; float min_var, max_var, a, b, c, total[MAXLEN], total_sq[MAXLEN], nv[MAXLEN], varv[MAXLEN], avgv[MAXLEN], val, total_var; @@ -908,7 +920,8 @@ MRI *MRIplaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) { Description ------------------------------------------------------*/ -MRI *MRIcentralPlaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) { +MRI *MRIcentralPlaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, vertex, xk, yk, mini, maxi, xi, yi, zi, *pxi, *pyi, *pzi, x1, y1, z1, x0, y0, z0; float min_mean, min_var, max_var, total, total_sq, nv, varv, avgv, val, background_val, fmax; @@ -961,7 +974,8 @@ MRI *MRIcentralPlaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) x1 = MIN(x0 + mri_src->roi.dx - 1, width - 1); y1 = MIN(y0 + mri_src->roi.dy - 1, height - 1); z1 = MIN(z0 + mri_src->roi.dz - 1, depth - 1); - } else { + } + else { x0 = y0 = z0 = 0; x1 = width - 1; y1 = height - 1; @@ -1061,7 +1075,8 @@ MRI *MRIcentralPlaneOfLeastVarianceNormal(MRI *mri_src, MRI *mri_dst, int wsize) Description ------------------------------------------------------*/ -MRI *MRIcentralPlaneOfLeastVarianceNormalMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize) { +MRI *MRIcentralPlaneOfLeastVarianceNormalMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, vertex, xk, yk, mini, maxi, xi, yi, zi, *pxi, *pyi, *pzi, x1, y1, z1, x0, y0, z0; float min_mean, min_var, max_var, total, total_sq, nv, varv, avgv, val; @@ -1089,7 +1104,8 @@ MRI *MRIcentralPlaneOfLeastVarianceNormalMarked(MRI *mri_src, MRI *mri_mask, MRI x1 = MIN(x0 + mri_src->roi.dx - 1, width - 1); y1 = MIN(y0 + mri_src->roi.dy - 1, height - 1); z1 = MIN(z0 + mri_src->roi.dz - 1, depth - 1); - } else { + } + else { x0 = y0 = z0 = 0; x1 = width - 1; y1 = height - 1; @@ -1178,7 +1194,8 @@ MRI *MRIcentralPlaneOfLeastVarianceNormalMarked(MRI *mri_src, MRI *mri_mask, MRI } return (mri_dst); } -static int compare_sort_farray(const void *pc1, const void *pc2) { +static int compare_sort_farray(const void *pc1, const void *pc2) +{ register float c1, c2; c1 = *(float *)pc1; @@ -1199,7 +1216,8 @@ static int compare_sort_farray(const void *pc1, const void *pc2) { Description ------------------------------------------------------*/ -static int compare_sort_array(const void *pc1, const void *pc2) { +static int compare_sort_array(const void *pc1, const void *pc2) +{ register BUFTYPE c1, c2; c1 = *(BUFTYPE *)pc1; @@ -1224,7 +1242,8 @@ static int compare_sort_array(const void *pc1, const void *pc2) { product of that vector with the normal (ez) to obtain the 2nd in-plane basis vector. ------------------------------------------------------*/ -static void init_basis_vectors(void) { +static void init_basis_vectors(void) +{ float vx, vy, vz, *px, *py, *pz, *pe1_x, *pe1_y, *pe1_z, *pe2_x, *pe2_y, *pe2_z, e3_x, e3_y, e3_z, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, len; int vertex; @@ -1324,7 +1343,8 @@ static void init_basis_vectors(void) { Description ------------------------------------------------------*/ -MRI *MRIfindThinWMStrands(MRI *mri_src, MRI *mri_dst, int wsize) { +MRI *MRIfindThinWMStrands(MRI *mri_src, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, yk, n, vertex, xi, yi, zi, *pxi, *pyi, *pzi, thin, was_white, black_white, val; float nx, ny, nz, xf, yf, zf; @@ -1372,7 +1392,8 @@ MRI *MRIfindThinWMStrands(MRI *mri_src, MRI *mri_dst, int wsize) { thin = ((yk - black_white) <= wsize); break; } - } else if (!was_white && val > 0) /* black to white transition */ + } + else if (!was_white && val > 0) /* black to white transition */ black_white = yk; was_white = val > 0; @@ -1397,7 +1418,8 @@ MRI *MRIfindThinWMStrands(MRI *mri_src, MRI *mri_dst, int wsize) { Description ------------------------------------------------------*/ #define MAX_LABELS 10000 -MRI *MRIresegmentThinWMStrands(MRI *mri_src, MRI *mri_dst, int thickness) { +MRI *MRIresegmentThinWMStrands(MRI *mri_src, MRI *mri_dst, int thickness) +{ int width, height, depth, x, y, z, vertex, thin, i; float nx, ny, nz, nd; BUFTYPE *pdst, *psrc; @@ -1644,7 +1666,8 @@ Description ------------------------------------------------------*/ #define MAX_LABELS 10000 #define TOO_THIN 2 -MRI *MRIthickenThinWMStrands(MRI *mri_T1, MRI *mri_src, MRI *mri_dst, int thickness, int nsegments, float wm_hi) { +MRI *MRIthickenThinWMStrands(MRI *mri_T1, MRI *mri_src, MRI *mri_dst, int thickness, int nsegments, float wm_hi) +{ int width, height, depth, x, y, z, thin, i, dont_fill, up_added, down_added, total_filled, nfilled, nseg, nx, ny, nz, xv, yv, zv, v; float nd; @@ -1976,7 +1999,8 @@ MRI *MRIthickenThinWMStrands(MRI *mri_T1, MRI *mri_src, MRI *mri_dst, int thickn Description ------------------------------------------------------*/ -MRI *MRIorderThreshold(MRI *mri_src, MRI *mri_dst, MRI *mri_order, int num) { +MRI *MRIorderThreshold(MRI *mri_src, MRI *mri_dst, MRI *mri_order, int num) +{ int width, height, depth, x, y, z, frame; BUFTYPE *psrc, *pdst, *porder, val; @@ -2013,7 +2037,8 @@ MRI *MRIorderThreshold(MRI *mri_src, MRI *mri_dst, MRI *mri_order, int num) { Description ------------------------------------------------------*/ -MRI *MRIpolvCount(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, int lo_lim, int hi_lim) { +MRI *MRIpolvCount(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, int lo_lim, int hi_lim) +{ int width, height, depth, x, y, z, whalf, xk, yk, n, vertex, xi, yi, zi, *pxi, *pyi, *pzi, order; float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; float val; @@ -2100,7 +2125,8 @@ MRI *MRIpolvCount(MRI *mri_src, MRI *mri_dst, MRI *mri_polv, int wsize, int lo_l #define REVERSE_THRESH (N2_SIZE * REVERSE_PCT) #define DEBUG_POINT(x, y, z) (((x) == 75) && ((y) == 96) && ((z) == 127)) -MRI *MRIwmfilter(MRI *mri_src, MRI *mri_polv, MRI *mri_dst, float nslope, float pslope) { +MRI *MRIwmfilter(MRI *mri_src, MRI *mri_polv, MRI *mri_dst, float nslope, float pslope) +{ int width, height, depth, x, y, z, whalf, vertex, xi, yi, zi, xo, yo, zo, *pxi, *pyi, *pzi, i, nwhite, nblack, count; float nx, ny, nz, dx, dy, dz, curv; BUFTYPE *pdst, *pptr, val0, /* *psrc, */ gray_hi, white_low /*,mean, *pmean*/, *plabel, *psrc, l; @@ -2193,7 +2219,8 @@ MRI *MRIwmfilter(MRI *mri_src, MRI *mri_polv, MRI *mri_dst, float nslope, float { white_low += nint(nslope * curv); gray_hi += nint(nslope * curv); - } else if (curv > 0.0f) { + } + else if (curv > 0.0f) { gray_hi += nint(pslope * curv); white_low += nint(pslope * curv); } @@ -2391,7 +2418,8 @@ MRI *MRIwmfilter(MRI *mri_src, MRI *mri_polv, MRI *mri_dst, float nslope, float MRIfree(&mri_label); return (mri_dst); } -MRI *MRIwmfilterMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize, float pct, int onoff) { +MRI *MRIwmfilterMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize, float pct, int onoff) +{ int width, height, depth, x, y, z, whalf, vertex, num_on, num_off, num, changed, low_thresh; float thresh; BUFTYPE *pdst, *pmask, *psrc, l; @@ -2441,7 +2469,8 @@ MRI *MRIwmfilterMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize, flo changed++; *pdst++ = l; psrc++; - } else + } + else *pdst++ = *psrc++; } } @@ -2459,7 +2488,8 @@ MRI *MRIwmfilterMarked(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int wsize, flo Description ------------------------------------------------------*/ -int MRIcountCpolvAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pnum, int label_to_check) { +int MRIcountCpolvAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pnum, int label_to_check) +{ int whalf, vertex, xk, yk, label, xi, yi, zi, *pxi, *pyi, *pzi, peak_vertex, max_count, num; float xbase, ybase, zbase, *pe1_x, *pe1_y, *pe1_z, *pe2_x, *pe2_y, *pe2_z, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; @@ -2530,7 +2560,8 @@ int MRIcountCpolvAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pnum Description ------------------------------------------------------*/ -int MRIcountCpolvOnAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pnum) { +int MRIcountCpolvOnAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pnum) +{ int whalf, vertex, xk, yk, label, xi, yi, zi, *pxi, *pyi, *pzi, peak_vertex, max_count, num; float xbase, ybase, zbase, *pe1_x, *pe1_y, *pe1_z, *pe2_x, *pe2_y, *pe2_z, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; @@ -2601,7 +2632,8 @@ int MRIcountCpolvOnAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pn Description ------------------------------------------------------*/ -int MRIcountCpolvOffAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pnum) { +int MRIcountCpolvOffAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *pnum) +{ int whalf, vertex, xk, yk, label, xi, yi, zi, *pxi, *pyi, *pzi, peak_vertex, max_count, num; float xbase, ybase, zbase, *pe1_x, *pe1_y, *pe1_z, *pe2_x, *pe2_y, *pe2_z, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; @@ -2672,7 +2704,8 @@ int MRIcountCpolvOffAtVoxel(MRI *mri_src, int x, int y, int z, int wsize, int *p Description ------------------------------------------------------*/ -MRI *MRIcpolvThreshold(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wm_low, int gray_hi, int wsize) { +MRI *MRIcpolvThreshold(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wm_low, int gray_hi, int wsize) +{ int width, height, depth, x, y, z, whalf, vertex, xk, yk, xi, yi, zi, *pxi, *pyi, *pzi, label, nlabeled, num_white, num_ambiguous, num_non_white; BUFTYPE *pdst, src, thresh; @@ -2761,7 +2794,8 @@ MRI *MRIcpolvThreshold(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wm_low, Description ------------------------------------------------------*/ -MRI *MRIcpolvVote(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wsize, int niter, int use_all) { +MRI *MRIcpolvVote(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wsize, int niter, int use_all) +{ int i, width, height, depth, x, y, z, whalf, vertex, xk, yk, xi, yi, zi, *pxi, *pyi, *pzi, label, nvox, nlabeled, num_white, num_ambiguous, num_non_white; BUFTYPE *pdst; @@ -2846,7 +2880,8 @@ MRI *MRIcpolvVote(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wsize, int n label = MRI_NOT_WHITE; else label = MRI_AMBIGUOUS; - } else { + } + else { if (num_white >= num_non_white) label = MRI_WHITE; else @@ -2880,7 +2915,8 @@ MRI *MRIcpolvVote(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wsize, int n Description ------------------------------------------------------*/ -MRI *MRIcpolvSmooth(MRI *mri_orig, MRI *mri_src, MRI *mri_dst, int wsize, int low_val, int hi_val, int niter) { +MRI *MRIcpolvSmooth(MRI *mri_orig, MRI *mri_src, MRI *mri_dst, int wsize, int low_val, int hi_val, int niter) +{ int width, height, depth, x, y, z, label, num_white, total_vox, white_vertex, black_vertex, x0, y0, z0, xi, yi, zi, nskipped, dst_label, num_black, nwhite_to_black, nblack_to_white, i, skip; BUFTYPE *pdst, *psrc, *porig, orig; @@ -2935,7 +2971,8 @@ MRI *MRIcpolvSmooth(MRI *mri_orig, MRI *mri_src, MRI *mri_dst, int wsize, int lo if (dst_label == MRI_WHITE) { if ((float)num_white > sthresh) skip = 1; - } else { + } + else { if ((float)num_black > sthresh) skip = 1; } } @@ -2958,7 +2995,8 @@ MRI *MRIcpolvSmooth(MRI *mri_orig, MRI *mri_src, MRI *mri_dst, int wsize, int lo dst_label = MRI_NOT_WHITE; } } - } else { + } + else { black_vertex = MRIneighborhoodBlackCpolv(mri_src, x, y, z, 3, wsize, NULL); num_black = wsize * wsize - MRIwhiteInPlane(mri_src, x, y, z, black_vertex, wsize); if (num_black < wsize * wsize / 2) { @@ -3004,7 +3042,8 @@ MRI *MRIcpolvSmooth(MRI *mri_orig, MRI *mri_src, MRI *mri_dst, int wsize, int lo Description ------------------------------------------------------*/ -MRI *MRIextractVertexCoords(MRI *mri_src, int *px, int *py, int *pz, int vertex, int x, int y, int z, int wsize) { +MRI *MRIextractVertexCoords(MRI *mri_src, int *px, int *py, int *pz, int vertex, int x, int y, int z, int wsize) +{ float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int whalf, xk, yk, xi, yi, zi; @@ -3042,7 +3081,8 @@ MRI *MRIextractVertexCoords(MRI *mri_src, int *px, int *py, int *pz, int vertex, Description ------------------------------------------------------*/ -MRI *MRIextractVertexPlane(MRI *mri_src, MRI *mri_dst, int vertex, int x0, int y0, int z0, int wsize) { +MRI *MRIextractVertexPlane(MRI *mri_src, MRI *mri_dst, int vertex, int x0, int y0, int z0, int wsize) +{ float e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase, x, y, z; int whalf, xk, yk; double val; @@ -3093,7 +3133,8 @@ MRI *MRIextractVertexPlane(MRI *mri_src, MRI *mri_dst, int vertex, int x0, int y Description ------------------------------------------------------*/ -int MRIneighborhoodBlackCpolv(MRI *mri_src, int xv, int yv, int zv, int nsize, int wsize, int *pnum_black) { +int MRIneighborhoodBlackCpolv(MRI *mri_src, int xv, int yv, int zv, int nsize, int wsize, int *pnum_black) +{ int best_plane[NVERTICES], whalf, nhalf, vertex, xk, yk, label, xi, yi, zi, *pxi, *pyi, *pzi, peak_vertex_index, max_count, x0, x1, y0, y1, z0, z1, x, y, z, num_black; float xbase, ybase, zbase, *pe1_x, *pe1_y, *pe1_z, *pe2_x, *pe2_y, *pe2_z, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; @@ -3193,7 +3234,8 @@ int MRIneighborhoodBlackCpolv(MRI *mri_src, int xv, int yv, int zv, int nsize, i Description ------------------------------------------------------*/ -int MRIneighborhoodCpolv(MRI *mri_src, int xv, int yv, int zv, int nsize, int wsize, int *pnum_white) { +int MRIneighborhoodCpolv(MRI *mri_src, int xv, int yv, int zv, int nsize, int wsize, int *pnum_white) +{ int best_plane[NVERTICES], whalf, nhalf, vertex, xk, yk, label, xi, yi, zi, *pxi, *pyi, *pzi, peak_vertex_index, max_count, x0, x1, y0, y1, z0, z1, x, y, z, num_white; float xbase, ybase, zbase, *pe1_x, *pe1_y, *pe1_z, *pe2_x, *pe2_y, *pe2_z, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; @@ -3293,7 +3335,8 @@ int MRIneighborhoodCpolv(MRI *mri_src, int xv, int yv, int zv, int nsize, int ws Description ------------------------------------------------------*/ -int MRIneighborhoodPlanarDirection(MRI *mri_src, int xv, int yv, int zv, int nsize, int wsize) { +int MRIneighborhoodPlanarDirection(MRI *mri_src, int xv, int yv, int zv, int nsize, int wsize) +{ int best_white_plane[NVERTICES], best_black_plane[NVERTICES], whalf, nhalf, vertex, xk, yk, label, src_label, max_black_count, xi, yi, zi, *pxi, *pyi, *pzi, peak_vertex_index, max_white_count, x0, x1, y0, y1, z0, z1, x, y, z, num_white, num_black, max_count; @@ -3372,7 +3415,8 @@ int MRIneighborhoodPlanarDirection(MRI *mri_src, int xv, int yv, int zv, int nsi max_black_count = num_black; } best_black_plane[vertex]++; - } else if (src_label == MRI_WHITE && (num_white && (num_white >= max_white_count))) { + } + else if (src_label == MRI_WHITE && (num_white && (num_white >= max_white_count))) { if (num_white > max_white_count) /* new best-fit */ { memset(best_white_plane, 0, sizeof(best_white_plane)); @@ -3403,7 +3447,8 @@ int MRIneighborhoodPlanarDirection(MRI *mri_src, int xv, int yv, int zv, int nsi Description ------------------------------------------------------*/ -int MRIwhiteInPlane(MRI *mri_src, int x, int y, int z, int vertex, int wsize) { +int MRIwhiteInPlane(MRI *mri_src, int x, int y, int z, int vertex, int wsize) +{ int whalf, xk, yk, label, xi, yi, zi, *pxi, *pyi, *pzi, num_white; float xbase, ybase, zbase, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; @@ -3458,7 +3503,8 @@ int MRIwhiteInPlane(MRI *mri_src, int x, int y, int z, int vertex, int wsize) { Description Remove small inconsistincies in the labeling of a volume. ------------------------------------------------------*/ -MRI *MRIremoveHoles(MRI *mri_src, MRI *mri_dst, int wsize, float pct, int use_all) { +MRI *MRIremoveHoles(MRI *mri_src, MRI *mri_dst, int wsize, float pct, int use_all) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, thresh, xi, yi, zi, num_on, num_off, in_val, nvox, nprocessed, nlabeled; BUFTYPE val, *pdst; @@ -3535,7 +3581,8 @@ MRI *MRIremoveHoles(MRI *mri_src, MRI *mri_dst, int wsize, float pct, int use_al Description Remove small inconsistincies in the labeling of a volume. ------------------------------------------------------*/ -MRI *MRImeanLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int wsize) { +MRI *MRImeanLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, xi, yi, zi, in_val, label, total; BUFTYPE val, *pdst, *plabel, *psrc; float wcubed, mean; @@ -3591,7 +3638,8 @@ MRI *MRImeanLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int wsize) { Description Remove small inconsistincies in the labeling of a volume. ------------------------------------------------------*/ -MRI *MRIintensitySegmentation(MRI *mri_src, MRI *mri_labeled, float wm_low, float wm_hi, float gray_hi) { +MRI *MRIintensitySegmentation(MRI *mri_src, MRI *mri_labeled, float wm_low, float wm_hi, float gray_hi) +{ int width, height, depth, x, y, z, nwhite, nblack, nambiguous; float val; @@ -3609,10 +3657,12 @@ MRI *MRIintensitySegmentation(MRI *mri_src, MRI *mri_labeled, float wm_low, floa if (val < wm_low || val > wm_hi) { val = MRI_NOT_WHITE; nblack++; - } else if (val <= gray_hi) { + } + else if (val <= gray_hi) { nambiguous++; val = MRI_AMBIGUOUS; - } else { + } + else { nwhite++; val = MRI_WHITE; } @@ -3644,7 +3694,8 @@ MRI *MRIintensitySegmentation(MRI *mri_src, MRI *mri_labeled, float wm_low, floa Description Remove small inconsistincies in the labeling of a volume. ------------------------------------------------------*/ -MRI *MRIthresholdLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wm_low) { +MRI *MRIthresholdLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wm_low) +{ int width, height, depth, x, y, z; BUFTYPE val, *psrc, *plabel, *pdst, label; @@ -3683,7 +3734,8 @@ MRI *MRIthresholdLabel(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int wm_low) Description Segment an MR image based on an order statistic. ------------------------------------------------------*/ -MRI *MRIorderSegment(MRI *mri_src, MRI *mri_labeled, float thresh, int wsize) { +MRI *MRIorderSegment(MRI *mri_src, MRI *mri_labeled, float thresh, int wsize) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, xi, yi, zi, in_val, thresh_index, label, nvox; BUFTYPE val, *pdst, *sptr; float wcubed; @@ -3754,7 +3806,8 @@ MRI *MRIorderSegment(MRI *mri_src, MRI *mri_labeled, float thresh, int wsize) { Description ------------------------------------------------------*/ -MRI *MRImaskLabels(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) { +MRI *MRImaskLabels(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) +{ int width, height, depth, x, y, z; float mask, src; @@ -3787,7 +3840,8 @@ MRI *MRImaskLabels(MRI *mri_src, MRI *mri_mask, MRI *mri_dst) { Description ------------------------------------------------------*/ -int MRIcentralPlaneOfLeastVarianceNormalVoxel(MRI *mri_src, int wsize, int x, int y, int z) { +int MRIcentralPlaneOfLeastVarianceNormalVoxel(MRI *mri_src, int wsize, int x, int y, int z) +{ int width, height, depth, whalf, vertex, xk, yk, min_vertex, max_vertex, xi, yi, zi, *pxi, *pyi, *pzi; float min_mean, min_var, max_var, total, total_sq, nv, varv, avgv, val; BUFTYPE max_val; @@ -3880,7 +3934,8 @@ int MRIcentralPlaneOfLeastVarianceNormalVoxel(MRI *mri_src, int wsize, int x, in Description ------------------------------------------------------*/ MRI *MRIcpolvMedianCurveSegment( - MRI *mri, MRI *mri_labeled, MRI *mri_dst, int wsize, float len, float gray_hi, float wm_low) { + MRI *mri, MRI *mri_labeled, MRI *mri_dst, int wsize, float len, float gray_hi, float wm_low) +{ int x, y, z, width, height, depth, label, nlabeled, non, noff; if (!mri_dst) mri_dst = MRIcopy(mri_labeled, NULL); @@ -3930,7 +3985,8 @@ MRI *MRIcpolvMedianCurveSegment( Description ------------------------------------------------------*/ int MRIcpolvMedianCurveVoxel( - MRI *mri, MRI *mri_labeled, int x0, int y0, int z0, int wsize, float len, float gray_hi, float wm_low) { + MRI *mri, MRI *mri_labeled, int x0, int y0, int z0, int wsize, float len, float gray_hi, float wm_low) +{ int vertex, what, i, maxi; FILE *fp = NULL; float dist, x, y, z, median, nx, ny, nz, white_dist, gray_dist, gray_val, white_val, val, white_grad, gray_grad, @@ -3966,7 +4022,8 @@ int MRIcpolvMedianCurveVoxel( if ((median >= gray_hi) && (fabs(dist) < white_dist)) { white_val = median; white_dist = fabs(dist); - } else if ((median <= wm_low) && (fabs(dist) < gray_dist)) { + } + else if ((median <= wm_low) && (fabs(dist) < gray_dist)) { gray_val = median; gray_dist = fabs(dist); } @@ -3985,7 +4042,8 @@ int MRIcpolvMedianCurveVoxel( if (median >= gray_hi) { /* fprintf(stderr, "median=%2.2f --> WHITE\n", median) ;*/ what = MRI_WHITE; - } else if (median <= wm_low) { + } + else if (median <= wm_low) { what = MRI_NOT_WHITE; /* fprintf(stderr, "median=%2.2f --> NOT WHITE\n", median) ;*/ } @@ -4071,7 +4129,8 @@ int MRIcpolvMedianCurveVoxel( what = MRI_NOT_WHITE; else what = MRI_WHITE; - } else if (gray_dist > white_dist) + } + else if (gray_dist > white_dist) what = MRI_WHITE; else what = MRI_NOT_WHITE; @@ -4086,7 +4145,8 @@ int MRIcpolvMedianCurveVoxel( Description ------------------------------------------------------*/ -float MRIcpolvMedianAtVoxel(MRI *mri_src, int vertex, float x, float y, float z, int wsize) { +float MRIcpolvMedianAtVoxel(MRI *mri_src, int vertex, float x, float y, float z, int wsize) +{ int whalf, xk, yk; float xbase, ybase, zbase, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; float plane_vals[MAXLEN], *pvals; @@ -4132,7 +4192,8 @@ float MRIcpolvMedianAtVoxel(MRI *mri_src, int vertex, float x, float y, float z, qsort(plane_vals, wsize * wsize, sizeof(float), compare_sort_farray); return (plane_vals[wsize * wsize / 2]); } -int MRIvertexToVector(int vertex, float *pdx, float *pdy, float *pdz) { +int MRIvertexToVector(int vertex, float *pdx, float *pdy, float *pdz) +{ if ((vertex < 0) || (vertex >= sizeof(ic_x_vertices) / sizeof(ic_x_vertices[0]))) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRIvertexToVector(%d): index out of range", vertex)); *pdx = ic_x_vertices[vertex]; @@ -4149,7 +4210,8 @@ int MRIvertexToVector(int vertex, float *pdx, float *pdy, float *pdz) { Description Remove small inconsistincies in the labelling of a volume. ------------------------------------------------------*/ -MRI *MRIremoveIslands(MRI *mri_src, MRI *mri_dst, int wsize, int thresh) { +MRI *MRIremoveIslands(MRI *mri_src, MRI *mri_dst, int wsize, int thresh) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, xi, yi, zi, num_on, num_off; float val, out_val; float wcubed; @@ -4192,7 +4254,8 @@ MRI *MRIremoveIslands(MRI *mri_src, MRI *mri_dst, int wsize, int thresh) { } return (mri_dst); } -MRI *MRIfillPlanarHoles(MRI *mri_src, MRI *mri_segment, MRI *mri_dst, MRI_SEGMENT *mseg) { +MRI *MRIfillPlanarHoles(MRI *mri_src, MRI *mri_segment, MRI *mri_dst, MRI_SEGMENT *mseg) +{ int width, height, depth, x, y, z, nfilled, total_filled, vertex; MRI *mri_binary_strand, *mri_strand_border; @@ -4265,7 +4328,8 @@ MRI *MRIfillPlanarHoles(MRI *mri_src, MRI *mri_segment, MRI *mri_dst, MRI_SEGMEN return (mri_dst); } -int MRIcpolvMaxWhiteAtVoxel(MRI *mri, int x, int y, int z, int wsize) { +int MRIcpolvMaxWhiteAtVoxel(MRI *mri, int x, int y, int z, int wsize) +{ int whalf, vertex, xk, yk, peak_vertex, max_count, num, xi, yi, zi; float xbase, ybase, zbase, *pe1_x, *pe1_y, *pe1_z, xf, yf, zf, *pe2_x, *pe2_y, *pe2_z, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z; @@ -4330,7 +4394,8 @@ int MRIcpolvMaxWhiteAtVoxel(MRI *mri, int x, int y, int z, int wsize) { return (peak_vertex); } -int MRIcpolvAllQuadrantsFilled(MRI *mri, int x, int y, int z, int vertex, int wsize) { +int MRIcpolvAllQuadrantsFilled(MRI *mri, int x, int y, int z, int vertex, int wsize) +{ #if 1 int whalf; float xf, yf, zf, e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, dist; diff --git a/utils/mriprob.c b/utils/mriprob.c index 6ff291bbd9c..ce78583ba22 100644 --- a/utils/mriprob.c +++ b/utils/mriprob.c @@ -37,7 +37,8 @@ #define DEBUG_POINT(x, y, z) (((x == 140) && (y == 74)) && ((z) == 174)) -MRI *MRIapplyBayesLaw(MRI *mri_priors, MRI *mri_p1, MRI *mri_p2, MRI *mri_dst) { +MRI *MRIapplyBayesLaw(MRI *mri_priors, MRI *mri_p1, MRI *mri_p2, MRI *mri_dst) +{ int x, y, z, width, height, depth; BUFTYPE *ppriors, *pdst; float p, p1, p2, prior, *pp1, *pp2; @@ -71,7 +72,8 @@ MRI *MRIapplyBayesLaw(MRI *mri_priors, MRI *mri_p1, MRI *mri_p2, MRI *mri_dst) { } return (mri_dst); } -MRI *MRIcomputeConditionalProbabilities(MRI *mri_T1, MRI *mri_mean, MRI *mri_std, MRI *mri_dst) { +MRI *MRIcomputeConditionalProbabilities(MRI *mri_T1, MRI *mri_mean, MRI *mri_std, MRI *mri_dst) +{ int x, y, z, width, height, depth; BUFTYPE *pT1, *pmean, *pstd; float p, mean, std, val, n, *pdst; @@ -111,7 +113,8 @@ MRI *MRIcomputeConditionalProbabilities(MRI *mri_T1, MRI *mri_mean, MRI *mri_std Description: ----------------------------------------------------------------------*/ -MRI *MRIprobabilityThresholdNeighborhoodOff(MRI *mri_src, MRI *mri_prob, MRI *mri_dst, float threshold, int nsize) { +MRI *MRIprobabilityThresholdNeighborhoodOff(MRI *mri_src, MRI *mri_prob, MRI *mri_dst, float threshold, int nsize) +{ BUFTYPE *pprob, out_val; int width, height, depth, x, y, z, x1, y1, z1, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, nchanged; float nvox; @@ -204,7 +207,8 @@ MRI *MRIprobabilityThresholdNeighborhoodOff(MRI *mri_src, MRI *mri_prob, MRI *mr Description: ----------------------------------------------------------------------*/ MRI *MRIprobabilityThresholdNeighborhoodOn( - MRI *mri_src, MRI *mri_prob, MRI *mri_dst, float threshold, int nsize, int out_label) { + MRI *mri_src, MRI *mri_prob, MRI *mri_dst, float threshold, int nsize, int out_label) +{ BUFTYPE *pprob, out_val; int width, height, depth, x, y, z, x1, y1, z1, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, nchanged; float nvox; @@ -288,7 +292,8 @@ MRI *MRIprobabilityThresholdNeighborhoodOn( return (mri_dst); } -MRI *MRIprobabilityThreshold(MRI *mri_src, MRI *mri_prob, MRI *mri_dst, float threshold, int out_label) { +MRI *MRIprobabilityThreshold(MRI *mri_src, MRI *mri_prob, MRI *mri_dst, float threshold, int out_label) +{ BUFTYPE *pprob, *pdst, *psrc, out_val, prob, in_val; int width, height, depth, x, y, z, nchanged, noff, non; float nvox; diff --git a/utils/mris_compVolFrac.c b/utils/mris_compVolFrac.c index d32fccbaeaa..13d12335282 100644 --- a/utils/mris_compVolFrac.c +++ b/utils/mris_compVolFrac.c @@ -39,7 +39,8 @@ #include "utils.h" #include "version.h" -MRI *MRIcomputeVolumeFractionFromSurface(MRI_SURFACE *mris, double acc, MRI *mri_src, MRI *mri_fractions) { +MRI *MRIcomputeVolumeFractionFromSurface(MRI_SURFACE *mris, double acc, MRI *mri_src, MRI *mri_fractions) +{ const int width = mri_src->width; const int height = mri_src->height; const int depth = mri_src->depth; @@ -91,14 +92,16 @@ MRI *MRIcomputeVolumeFractionFromSurface(MRI_SURFACE *mris, double acc, MRI *mri /* compute the volume fraction of this voxel */ frac = MRIcomputeVoxelFractions(V, v, acc, 1, mris); MRIsetVoxVal(mri_fractions, x, y, z, 0, frac.frac); - } else if (MRIgetVoxVal(mri_interior, x, y, z, 0) > 0.0) + } + else if (MRIgetVoxVal(mri_interior, x, y, z, 0) > 0.0) MRIsetVoxVal(mri_fractions, x, y, z, 0, 1.0); } } } return mri_fractions; } -volFraction MRIcomputeVoxelFractions(octTreeVoxel V, VERTEX *v, double acc, int current_depth, MRI_SURFACE *mris) { +volFraction MRIcomputeVoxelFractions(octTreeVoxel V, VERTEX *v, double acc, int current_depth, MRI_SURFACE *mris) +{ /* inputs: V: voxel element, which includes center, corners and the vsize v: closest vertex to this voxel @@ -137,7 +140,8 @@ volFraction MRIcomputeVoxelFractions(octTreeVoxel V, VERTEX *v, double acc, int meanNorm[2] * (V.corn[j][2] - meanVert[2]); if (dotProduct < 0.0) { allout = 0; - } else { + } + else { allin = 0; } } @@ -152,17 +156,20 @@ volFraction MRIcomputeVoxelFractions(octTreeVoxel V, VERTEX *v, double acc, int { frac.frac = relativeVolume; frac.err = 0; - } else if (allout == 1) /* all corners are out return 0 */ + } + else if (allout == 1) /* all corners are out return 0 */ { frac.frac = 0; frac.err = 0; - } else /* some in some out */ + } + else /* some in some out */ { if (relativeVolume < acc) /* the error we are making is small enough */ { frac.frac = relativeVolume / 2; frac.err = relativeVolume / 2; - } else /* the error we are making is too big we will redivide and recurse */ + } + else /* the error we are making is too big we will redivide and recurse */ { for (k = 0; k < 8; k++) { volFraction frac_new = MRIcomputeVoxelFractions(octTreeVoxelDivide(k + 1, V), v, acc, current_depth + 1, mris); @@ -173,7 +180,8 @@ volFraction MRIcomputeVoxelFractions(octTreeVoxel V, VERTEX *v, double acc, int } return frac; } -octTreeVoxel octTreeVoxelCreate(double *vox, double *vsize) { +octTreeVoxel octTreeVoxelCreate(double *vox, double *vsize) +{ octTreeVoxel v; int k; /* @@ -223,7 +231,8 @@ octTreeVoxel octTreeVoxelCreate(double *vox, double *vsize) { return v; } -octTreeVoxel octTreeVoxelDivide(int type, octTreeVoxel v) { +octTreeVoxel octTreeVoxelDivide(int type, octTreeVoxel v) +{ double vsize_new[3]; double vox_new[3] = {0, 0, 0}; vsize_new[0] = v.vsize[0] / 2.0; diff --git a/utils/mrisbiorthogonalwavelets.c b/utils/mrisbiorthogonalwavelets.c index 7ff78f27c4b..913731709bf 100644 --- a/utils/mrisbiorthogonalwavelets.c +++ b/utils/mrisbiorthogonalwavelets.c @@ -54,7 +54,8 @@ MRI_SURFACE *wavelet_analysis_vec(MRI_SURFACE *mris_out, int order); MRI_SURFACE *wavelet_synthesis_curv(MRI_SURFACE *mris_out, int order); MRI_SURFACE *wavelet_synthesis_vec(MRI_SURFACE *mris_out, int order); -MRI_SURFACE *wavelet_analysis_curv(MRI_SURFACE *mris_out, int order) { +MRI_SURFACE *wavelet_analysis_curv(MRI_SURFACE *mris_out, int order) +{ int i, number, vno, nnum, m, k, b1 = 0, b2 = 0, cno, flag = 0; MRIS *mris_high; VERTEX *vm_out, *vm_high, *v; @@ -182,7 +183,8 @@ MRI_SURFACE *wavelet_analysis_curv(MRI_SURFACE *mris_out, int order) { return (mris_out); } -MRI_SURFACE *wavelet_analysis_vec(MRI_SURFACE *mris_out, int order) { +MRI_SURFACE *wavelet_analysis_vec(MRI_SURFACE *mris_out, int order) +{ int i, number, vno, nnum, m, k, b1 = 0, b2 = 0, cno, flag = 0; MRIS *mris_high; VERTEX *vm_out, *vm_high, *v; @@ -331,7 +333,8 @@ MRI_SURFACE *wavelet_analysis_vec(MRI_SURFACE *mris_out, int order) { return (mris_out); } -MRI_SURFACE *wavelet_synthesis_curv(MRI_SURFACE *mris_out, int order) { +MRI_SURFACE *wavelet_synthesis_curv(MRI_SURFACE *mris_out, int order) +{ int i, number, vno, nnum, m, k, b1 = 0, b2 = 0, cno, flag = 0; MRIS *mris_high; VERTEX *vm_out, *vm_high, *v; @@ -454,7 +457,8 @@ MRI_SURFACE *wavelet_synthesis_curv(MRI_SURFACE *mris_out, int order) { return (mris_out); } -MRI_SURFACE *wavelet_synthesis_vec(MRI_SURFACE *mris_out, int order) { +MRI_SURFACE *wavelet_synthesis_vec(MRI_SURFACE *mris_out, int order) +{ int i, number, vno, nnum, m, k, b1 = 0, b2 = 0, cno, flag = 0; MRIS *mris_high; VERTEX *vm_out, *vm_high, *v; diff --git a/utils/mrisegment.c b/utils/mrisegment.c index 4dbfa8c9334..3a0a78d57ff 100644 --- a/utils/mrisegment.c +++ b/utils/mrisegment.c @@ -69,7 +69,8 @@ static int mriComputeSegmentStatistics(MRI_SEGMENTATION *mriseg); #define MAX_VOXELS 5 #define NBR_VOX (3 * 3 * 3) -int MRImaxSegmentArea(MRI_SEGMENTATION *mriseg) { +int MRImaxSegmentArea(MRI_SEGMENTATION *mriseg) +{ int maxarea = -1; // int max = -1; int k; @@ -84,7 +85,8 @@ int MRImaxSegmentArea(MRI_SEGMENTATION *mriseg) { // the following only cares about finding the max segments // ignoring the rest -MRI_SEGMENTATION *MRImaxsegment(MRI *mri, float low_val, float hi_val) { +MRI_SEGMENTATION *MRImaxsegment(MRI *mri, float low_val, float hi_val) +{ MRI_SEGMENTATION *mriseg; MRI_SEGMENT *mseg, *mseg2; int x, y, z, width, height, depth, xi, yi, zi, xk, yk, zk, val, border_labels[NBR_VOX], nlabels, label, nvox; @@ -313,7 +315,8 @@ MRI_SEGMENTATION *MRImaxsegment(MRI *mri, float low_val, float hi_val) { return (mriseg); } -MRI_SEGMENTATION *MRIsegment(MRI *mri, float low_val, float hi_val) { +MRI_SEGMENTATION *MRIsegment(MRI *mri, float low_val, float hi_val) +{ MRI_SEGMENTATION *mriseg; MRI_SEGMENT *mseg, *mseg2; int x, y, z, width, height, depth, xi, yi, zi, xk, yk, zk, border_labels[NBR_VOX], nlabels, label, nvox; @@ -476,7 +479,8 @@ MRI_SEGMENTATION *MRIsegment(MRI *mri, float low_val, float hi_val) { Description ------------------------------------------------------*/ -int MRIsegmentFree(MRI_SEGMENTATION **pmriseg) { +int MRIsegmentFree(MRI_SEGMENTATION **pmriseg) +{ MRI_SEGMENTATION *mriseg; int i; @@ -497,7 +501,8 @@ int MRIsegmentFree(MRI_SEGMENTATION **pmriseg) { Description ------------------------------------------------------*/ -MRI_SEGMENTATION *MRIsegmentAlloc(int max_segments, int max_voxels) { +MRI_SEGMENTATION *MRIsegmentAlloc(int max_segments, int max_voxels) +{ MRI_SEGMENTATION *mriseg; int i; @@ -526,7 +531,8 @@ MRI_SEGMENTATION *MRIsegmentAlloc(int max_segments, int max_voxels) { Description Merge segment 1 into segment 0. ------------------------------------------------------*/ -static int mriSegmentMerge(MRI_SEGMENTATION *mriseg, int s0, int s1, MRI *mri_labeled) { +static int mriSegmentMerge(MRI_SEGMENTATION *mriseg, int s0, int s1, MRI *mri_labeled) +{ MRI_SEGMENT *mseg0, *mseg1; int v, total_voxels, x, y, z; @@ -569,7 +575,8 @@ static int mriSegmentMerge(MRI_SEGMENTATION *mriseg, int s0, int s1, MRI *mri_la Description ------------------------------------------------------*/ -static int mriSegmentReallocateVoxels(MRI_SEGMENTATION *mriseg, int sno, int max_voxels) { +static int mriSegmentReallocateVoxels(MRI_SEGMENTATION *mriseg, int sno, int max_voxels) +{ MRI_SEGMENT *mseg; // MSV *old_voxels ; MSV *new_voxels; @@ -633,7 +640,8 @@ static int mriSegmentReallocateVoxels(MRI_SEGMENTATION *mriseg, int sno, int max Description ------------------------------------------------------*/ -static int mriSegmentReallocateSegments(MRI_SEGMENTATION *mriseg, int max_segments) { +static int mriSegmentReallocateSegments(MRI_SEGMENTATION *mriseg, int max_segments) +{ MRI_SEGMENT *old_segments; int s; @@ -666,7 +674,8 @@ static int mriSegmentReallocateSegments(MRI_SEGMENTATION *mriseg, int max_segmen Description ------------------------------------------------------*/ -MRI *MRIsegmentToImage(MRI *mri_src, MRI *mri_dst, MRI_SEGMENTATION *mriseg, int s) { +MRI *MRIsegmentToImage(MRI *mri_src, MRI *mri_dst, MRI_SEGMENTATION *mriseg, int s) +{ int v, x, y, z, smin, smax; MRI_SEGMENT *mseg; @@ -678,7 +687,8 @@ MRI *MRIsegmentToImage(MRI *mri_src, MRI *mri_dst, MRI_SEGMENTATION *mriseg, int { smin = 0; smax = mriseg->nsegments - 1; - } else // just do one segment + } + else // just do one segment smin = smax = s; for (s = smin; s <= smax; s++) { @@ -695,7 +705,8 @@ MRI *MRIsegmentToImage(MRI *mri_src, MRI *mri_dst, MRI_SEGMENTATION *mriseg, int return (mri_dst); } -int MRIsetSegmentValue(MRI *mri, MRI_SEGMENTATION *mriseg, int s, float val) { +int MRIsetSegmentValue(MRI *mri, MRI_SEGMENTATION *mriseg, int s, float val) +{ int v, x, y, z; MRI_SEGMENT *mseg; @@ -718,7 +729,8 @@ int MRIsetSegmentValue(MRI *mri, MRI_SEGMENTATION *mriseg, int s, float val) { Description ------------------------------------------------------*/ -static int mriSegmentNew(MRI_SEGMENTATION *mriseg) { +static int mriSegmentNew(MRI_SEGMENTATION *mriseg) +{ int s; if (mriseg->nsegments >= mriseg->max_segments) { @@ -747,7 +759,8 @@ static int mriSegmentNew(MRI_SEGMENTATION *mriseg) { Description ------------------------------------------------------*/ -int MRIcompactSegments(MRI_SEGMENTATION *mriseg) { +int MRIcompactSegments(MRI_SEGMENTATION *mriseg) +{ MRI_SEGMENT *src_segment, *dst_segment; MRI_SEGMENT *newseg; int s, s2; @@ -797,7 +810,8 @@ int MRIcompactSegments(MRI_SEGMENTATION *mriseg) { if (newseg) { mriseg->segments = newseg; if (DIAG_VERBOSE_ON && 0) fprintf(stdout, "\n segments reduced to %d\n", s); - } else { + } + else { MRI_SEGMENT *oldseg = mriseg->segments; newseg = (MRI_SEGMENT *)calloc(s, sizeof(MRI_SEGMENT)); @@ -817,7 +831,8 @@ int MRIcompactSegments(MRI_SEGMENTATION *mriseg) { Description ------------------------------------------------------*/ -int MRIsegmentDilate(MRI_SEGMENTATION *mriseg, MRI *mri) { +int MRIsegmentDilate(MRI_SEGMENTATION *mriseg, MRI *mri) +{ int x, y, z, xk, yk, zk, xi, yi, zi, segno, v, nvox; MRI_SEGMENT *mseg; MRI *mri_segments; @@ -870,7 +885,8 @@ int MRIsegmentDilate(MRI_SEGMENTATION *mriseg, MRI *mri) { return (NO_ERROR); } -int MRIremoveSmallSegments(MRI_SEGMENTATION *mriseg, int min_voxels) { +int MRIremoveSmallSegments(MRI_SEGMENTATION *mriseg, int min_voxels) +{ int s; if (DIAG_VERBOSE_ON && 0) fprintf(stdout, "compacting segments...\n"); @@ -886,7 +902,8 @@ int MRIremoveSmallSegments(MRI_SEGMENTATION *mriseg, int min_voxels) { return (MRIcompactSegments(mriseg)); } -int MRIeraseSmallSegments(MRI_SEGMENTATION *mriseg, MRI *mri_seg, int min_voxels) { +int MRIeraseSmallSegments(MRI_SEGMENTATION *mriseg, MRI *mri_seg, int min_voxels) +{ int s, v, nerased = 0, x, y, z, f; MRI_SEGMENT *mseg; @@ -909,7 +926,8 @@ int MRIeraseSmallSegments(MRI_SEGMENTATION *mriseg, MRI *mri_seg, int min_voxels return (nerased); } -static int mriComputeSegmentStatistics(MRI_SEGMENTATION *mriseg) { +static int mriComputeSegmentStatistics(MRI_SEGMENTATION *mriseg) +{ int segno; MRI_SEGMENT *mseg; int v, x, y, z; @@ -942,8 +960,8 @@ static int mriComputeSegmentStatistics(MRI_SEGMENTATION *mriseg) { return (NO_ERROR); } -int MRIsegmentDilateThreshold( - MRI_SEGMENTATION *mriseg, MRI *mri_binary, MRI *mri_thresh, int low_thresh, int hi_thresh) { +int MRIsegmentDilateThreshold(MRI_SEGMENTATION *mriseg, MRI *mri_binary, MRI *mri_thresh, int low_thresh, int hi_thresh) +{ int x, y, z, xk, yk, zk, xi, yi, zi, segno, v, nvox, val; MRI_SEGMENT *mseg; MRI *mri_segments; @@ -998,7 +1016,8 @@ int MRIsegmentDilateThreshold( return (NO_ERROR); } -int MRIsegmentMax(MRI_SEGMENTATION *mriseg) { +int MRIsegmentMax(MRI_SEGMENTATION *mriseg) +{ int segno, max_voxels, max_segno, nvox; MRI_SEGMENT *mseg; @@ -1017,7 +1036,8 @@ int MRIsegmentMax(MRI_SEGMENTATION *mriseg) { return (max_segno); } -int MRIsegmentClearIgnoreFlags(MRI_SEGMENTATION *mriseg) { +int MRIsegmentClearIgnoreFlags(MRI_SEGMENTATION *mriseg) +{ int segno; MRI_SEGMENT *mseg; @@ -1028,7 +1048,8 @@ int MRIsegmentClearIgnoreFlags(MRI_SEGMENTATION *mriseg) { return (NO_ERROR); } -int MRIfindMaxSegmentNumber(MRI_SEGMENTATION *mriseg) { +int MRIfindMaxSegmentNumber(MRI_SEGMENTATION *mriseg) +{ MRI_SEGMENT *mseg; int max_segno = 0, segno, max_voxels = 0; @@ -1042,7 +1063,8 @@ int MRIfindMaxSegmentNumber(MRI_SEGMENTATION *mriseg) { return (max_segno); } -MRI *MRIsegmentFill(MRI_SEGMENTATION *mriseg, int s, MRI *mri, float fillval) { +MRI *MRIsegmentFill(MRI_SEGMENTATION *mriseg, int s, MRI *mri, float fillval) +{ int v, x, y, z; MRI_SEGMENT *mseg; @@ -1062,7 +1084,8 @@ MRI *MRIsegmentFill(MRI_SEGMENTATION *mriseg, int s, MRI *mri, float fillval) { } #include "label.h" -LABEL *MRIsegmentToLabel(MRI_SEGMENTATION *mriseg, MRI *mri, int ind) { +LABEL *MRIsegmentToLabel(MRI_SEGMENTATION *mriseg, MRI *mri, int ind) +{ LABEL *area; int i; MRI_SEGMENT *mseg; diff --git a/utils/mriset.c b/utils/mriset.c index b2024a76a90..338262904cc 100644 --- a/utils/mriset.c +++ b/utils/mriset.c @@ -76,7 +76,8 @@ extern const char *Progname; Description: A sanity-check: make sure the volumes being operated upon are the same dimensions ------------------------------------------------------*/ -static void MRIcheckVolDims(MRI *mri1, MRI *mri2) { +static void MRIcheckVolDims(MRI *mri1, MRI *mri2) +{ if (mri1 == NULL) return; if (mri2 == NULL) return; @@ -110,7 +111,8 @@ static void MRIcheckVolDims(MRI *mri1, MRI *mri2) { Description ------------------------------------------------------*/ -MRI *MRIunion(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIunion(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z; BUFTYPE *p1, *p2, *pdst, v1, v2; @@ -143,7 +145,8 @@ MRI *MRIunion(MRI *mri1, MRI *mri2, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIintersect(MRI *mri1, MRI *mri2, MRI *mri_dst) { +MRI *MRIintersect(MRI *mri1, MRI *mri2, MRI *mri_dst) +{ int width, height, depth, x, y, z, f, v1, v2; MRIcheckVolDims(mri1, mri2); @@ -171,7 +174,8 @@ MRI *MRIintersect(MRI *mri1, MRI *mri2, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIcomplement(MRI *mri_src, MRI *mri_dst) { +MRI *MRIcomplement(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, val, f; MRIcheckVolDims(mri_src, mri_dst); @@ -202,7 +206,8 @@ MRI *MRIcomplement(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIand(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) { +MRI *MRIand(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) +{ int width, height, depth, x, y, z, f; double val1, val2; @@ -236,7 +241,8 @@ MRI *MRIand(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) { Description ------------------------------------------------------*/ -MRI *MRIor(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) { +MRI *MRIor(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) +{ int width, height, depth, x, y, z, f; double val1, val2; @@ -264,7 +270,8 @@ MRI *MRIor(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) { return (mri_dst); } -MRI *MRIorVal(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) { +MRI *MRIorVal(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) +{ int width, height, depth, x, y, z, f; double val1, val2, val; @@ -304,7 +311,8 @@ MRI *MRIorVal(MRI *mri1, MRI *mri2, MRI *mri_dst, int thresh) { Description ------------------------------------------------------*/ -MRI *MRIxor(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) { +MRI *MRIxor(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) +{ int width, height, depth, x, y, z; int v1, v2; @@ -337,7 +345,8 @@ MRI *MRIxor(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) { Description ------------------------------------------------------*/ #define KLEN 3 -MRI *MRImorph(MRI *mri_src, MRI *mri_dst, int which) { +MRI *MRImorph(MRI *mri_src, MRI *mri_dst, int which) +{ BUFTYPE kernel[KLEN][KLEN][KLEN]; switch (which) { @@ -364,7 +373,8 @@ MRI *MRImorph(MRI *mri_src, MRI *mri_dst, int which) { NEAREST_NEIGHBOR_FACE, NEAREST_NEIGHBOR_EDGE, NEAREST_NEIGHBOR_CORNER When called with CORNER, this should give the same result as MRIerode(). */ -MRI *MRIerodeNN(MRI *in, MRI *out, int NNDef) { +MRI *MRIerodeNN(MRI *in, MRI *out, int NNDef) +{ int c, r, s, dc, dr, ds; double valmin, val; @@ -413,7 +423,8 @@ MRI *MRIerodeNN(MRI *in, MRI *out, int NNDef) { } /*-----------------------------------------------------*/ -MRI *MRIerode(MRI *mri_src, MRI *mri_dst) { +MRI *MRIerode(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, z, same; MRIcheckVolDims(mri_src, mri_dst); @@ -427,7 +438,8 @@ MRI *MRIerode(MRI *mri_src, MRI *mri_dst) { if (mri_dst == mri_src) { same = 1; mri_dst = MRIclone(mri_src, NULL); - } else + } + else same = 0; if (mri_src->type != MRI_UCHAR || mri_dst->type != MRI_UCHAR) { @@ -455,7 +467,8 @@ MRI *MRIerode(MRI *mri_src, MRI *mri_dst) { } } } - } else { + } + else { #ifdef HAVE_OPENMP #pragma omp parallel for #endif @@ -500,7 +513,8 @@ Not sure if meaningful for float images, maybe add eps check? -----------------------------------------------------*/ -MRI *MRIerodeLabels(MRI *mri_src, MRI *mri_dst) { +MRI *MRIerodeLabels(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, same; BUFTYPE *pdst, neighbor; @@ -515,7 +529,8 @@ MRI *MRIerodeLabels(MRI *mri_src, MRI *mri_dst) { if (mri_dst == mri_src) { same = 1; mri_dst = MRIclone(mri_src, NULL); - } else + } + else same = 0; if (mri_src->type != MRI_UCHAR || mri_dst->type != MRI_UCHAR) { @@ -546,7 +561,8 @@ MRI *MRIerodeLabels(MRI *mri_src, MRI *mri_dst) { } } } - } else { + } + else { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { pdst = &MRIvox(mri_dst, 0, y, z); @@ -580,7 +596,8 @@ MRI *MRIerodeLabels(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } /*-----------------------------------------------------*/ -MRI *MRIerodeThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) { +MRI *MRIerodeThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, same; double min_val, val; @@ -595,7 +612,8 @@ MRI *MRIerodeThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_ds if (mri_dst == mri_src) { same = 1; mri_dst = MRIcopy(mri_src, NULL); - } else + } + else same = 0; for (z = 0; z < depth; z++) { @@ -627,7 +645,8 @@ MRI *MRIerodeThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_ds } return (mri_dst); } -MRI *MRIdilateThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) { +MRI *MRIdilateThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, same; double max_val, val; @@ -642,7 +661,8 @@ MRI *MRIdilateThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_d if (mri_dst == mri_src) { same = 1; mri_dst = MRIcopy(mri_src, NULL); - } else + } + else same = 0; for (z = 0; z < depth; z++) { @@ -674,7 +694,8 @@ MRI *MRIdilateThresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_d } return (mri_dst); } -MRI *MRIdilate6Thresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) { +MRI *MRIdilate6Thresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_dst) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, same; double max_val, val; @@ -689,7 +710,8 @@ MRI *MRIdilate6Thresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_ if (mri_dst == mri_src) { same = 1; mri_dst = MRIcopy(mri_src, NULL); - } else + } + else same = 0; for (z = 0; z < depth; z++) { @@ -723,7 +745,8 @@ MRI *MRIdilate6Thresh(MRI *mri_src, MRI *mri_intensity, double thresh, MRI *mri_ return (mri_dst); } /*-----------------------------------------------------*/ -MRI *MRIerodeZero(MRI *mri_src, MRI *mri_dst) { +MRI *MRIerodeZero(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, same; BUFTYPE *pdst, min_val, val; @@ -738,7 +761,8 @@ MRI *MRIerodeZero(MRI *mri_src, MRI *mri_dst) { if (mri_dst == mri_src) { same = 1; mri_dst = MRIclone(mri_src, NULL); - } else + } + else same = 0; if (mri_src->type != MRI_UCHAR || mri_dst->type != MRI_UCHAR) { @@ -764,7 +788,8 @@ MRI *MRIerodeZero(MRI *mri_src, MRI *mri_dst) { } } } - } else { + } + else { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { pdst = &MRIvox(mri_dst, 0, y, z); @@ -794,7 +819,8 @@ MRI *MRIerodeZero(MRI *mri_src, MRI *mri_dst) { return (mri_dst); } /*-----------------------------------------------------*/ -MRI *MRIerode2D(MRI *mri_src, MRI *mri_dst) { +MRI *MRIerode2D(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, x0, y0, xi, yi, same; double fmin_val, fval; @@ -809,7 +835,8 @@ MRI *MRIerode2D(MRI *mri_src, MRI *mri_dst) { if (mri_dst == mri_src) { same = 1; mri_dst = MRIclone(mri_src, NULL); - } else + } + else same = 0; for (z = 0; z < depth; z++) { @@ -843,7 +870,8 @@ MRI *MRIerode2D(MRI *mri_src, MRI *mri_dst) { nDiffThresh. "Nearest neighbor" is defined as the 6 nearest neighbors. If nErodes>1, then it calls itself recursively. */ -MRI *MRIerodeSegmentation(MRI *seg, MRI *out, int nErodes, int nDiffThresh) { +MRI *MRIerodeSegmentation(MRI *seg, MRI *out, int nErodes, int nDiffThresh) +{ int c, r, s, dc, dr, ds, segid0, segidD, n, nDiff; MRI *seg2 = NULL; @@ -904,7 +932,8 @@ MRI *MRIerodeSegmentation(MRI *seg, MRI *out, int nErodes, int nDiffThresh) { calls itself recursively until the output segmentation stops changing. If mask is set, then mask must be > 0.5 */ -MRI *MRIdilateSegmentation(MRI *seg, MRI *out, int nDils, MRI *mask, int maskframe, double maskthresh, int *pnchanges) { +MRI *MRIdilateSegmentation(MRI *seg, MRI *out, int nDils, MRI *mask, int maskframe, double maskthresh, int *pnchanges) +{ int c, r, s, dc, dr, ds, segid0, segidD, n; int nNbrs, NbrId[6], segidMost, nOccurances, nchanges; MRI *seg2 = NULL; @@ -1019,7 +1048,8 @@ MRI *MRIdilateSegmentation(MRI *seg, MRI *out, int nDils, MRI *mask, int maskfra Description ------------------------------------------------------*/ -MRI *MRIdilateThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, int niter, int thresh) { +MRI *MRIdilateThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, int niter, int thresh) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, i, nadded; BUFTYPE *psrc, out_val, val; MRI *mri_tmp = NULL; @@ -1106,7 +1136,8 @@ MRI *MRIdilateThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, i Description ------------------------------------------------------*/ -MRI *MRIdilate6ThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, int niter, int thresh) { +MRI *MRIdilate6ThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, int niter, int thresh) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, i, nadded; BUFTYPE *psrc, out_val, val; MRI *mri_tmp = NULL; @@ -1193,7 +1224,8 @@ MRI *MRIdilate6ThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, Description ------------------------------------------------------*/ -MRI *MRIdilateInvThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, int niter, int thresh) { +MRI *MRIdilateInvThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label, int niter, int thresh) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, i, nadded; BUFTYPE *psrc, out_val, val; MRI *mri_tmp = NULL; @@ -1280,7 +1312,8 @@ MRI *MRIdilateInvThreshLabel(MRI *mri_src, MRI *mri_val, MRI *mri_dst, int label Description ------------------------------------------------------*/ -MRI *MRIdilateLabelUchar(MRI *mri_src, MRI *mri_dst, int label, int niter) { +MRI *MRIdilateLabelUchar(MRI *mri_src, MRI *mri_dst, int label, int niter) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, i; BUFTYPE *psrc, out_val, val; MRI *mri_tmp = NULL; @@ -1357,7 +1390,8 @@ MRI *MRIdilateLabelUchar(MRI *mri_src, MRI *mri_dst, int label, int niter) { Description ------------------------------------------------------*/ -MRI *MRIdilateLabel(MRI *mri_src, MRI *mri_dst, int label, int niter) { +MRI *MRIdilateLabel(MRI *mri_src, MRI *mri_dst, int label, int niter) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, i, f; MRI *mri_tmp = NULL; double out_val, val; @@ -1445,7 +1479,8 @@ MRI *MRIdilateLabel(MRI *mri_src, MRI *mri_dst, int label, int niter) { Description ------------------------------------------------------*/ -MRI *MRIdilateUchar(MRI *mri_src, MRI *mri_dst) { +MRI *MRIdilateUchar(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, same, xmin, xmax, ymin, ymax, zmin, zmax; BUFTYPE *psrc, max_val, val; @@ -1460,7 +1495,8 @@ MRI *MRIdilateUchar(MRI *mri_src, MRI *mri_dst) { if (mri_dst == mri_src) { same = 1; mri_dst = MRIclone(mri_src, NULL); - } else + } + else same = 0; xmax = 0; @@ -1524,7 +1560,8 @@ MRI *MRIdilateUchar(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIdilate(MRI *mri_src, MRI *mri_dst) { +MRI *MRIdilate(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, same, xmin, xmax, ymin, ymax, zmin, zmax, f; double val; @@ -1541,7 +1578,8 @@ MRI *MRIdilate(MRI *mri_src, MRI *mri_dst) { if (mri_dst == mri_src) { same = 1; mri_dst = MRIclone(mri_src, NULL); - } else + } + else same = 0; #if 1 @@ -1615,7 +1653,8 @@ MRI *MRIdilate(MRI *mri_src, MRI *mri_dst) { } return (mri_dst); } -MRI *MRIopenN(MRI *mri_src, MRI *mri_dst, int order) { +MRI *MRIopenN(MRI *mri_src, MRI *mri_dst, int order) +{ MRI *mri_tmp; int i; @@ -1634,7 +1673,8 @@ MRI *MRIopenN(MRI *mri_src, MRI *mri_dst, int order) { Description ------------------------------------------------------*/ -MRI *MRIopen(MRI *mri_src, MRI *mri_dst) { +MRI *MRIopen(MRI *mri_src, MRI *mri_dst) +{ MRI *mri_tmp; mri_tmp = MRIerode(mri_src, NULL); @@ -1649,7 +1689,8 @@ MRI *MRIopen(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIclose(MRI *mri_src, MRI *mri_dst) { +MRI *MRIclose(MRI *mri_src, MRI *mri_dst) +{ MRI *mri_tmp; mri_tmp = MRIdilate(mri_src, NULL); @@ -1664,7 +1705,8 @@ MRI *MRIclose(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIerode6(MRI *mri_src, MRI *mri_dst) { +MRI *MRIerode6(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, x1, y1, z1, xi, yi, zi; float min_val, val; @@ -1716,7 +1758,8 @@ MRI *MRIerode6(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIdilate6(MRI *mri_src, MRI *mri_dst) { +MRI *MRIdilate6(MRI *mri_src, MRI *mri_dst) +{ int width, height, depth, x, y, z, x1, y1, z1, xi, yi, zi; float max_val, val; @@ -1768,7 +1811,8 @@ MRI *MRIdilate6(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIopen6(MRI *mri_src, MRI *mri_dst) { +MRI *MRIopen6(MRI *mri_src, MRI *mri_dst) +{ MRI *mri_tmp; mri_tmp = MRIerode6(mri_src, NULL); @@ -1783,7 +1827,8 @@ MRI *MRIopen6(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIclose6(MRI *mri_src, MRI *mri_dst) { +MRI *MRIclose6(MRI *mri_src, MRI *mri_dst) +{ MRI *mri_tmp; mri_tmp = MRIdilate6(mri_src, NULL); @@ -1798,7 +1843,8 @@ MRI *MRIclose6(MRI *mri_src, MRI *mri_dst) { Description ------------------------------------------------------*/ -MRI *MRIerodeRegion(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *region) { +MRI *MRIerodeRegion(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *region) +{ int width, height, depth, x, y, z, whalf, x0, y0, z0, val, xk, yk, zk, xi, yi, zi, min_val; BUFTYPE *pdst; @@ -1863,7 +1909,8 @@ MRI *MRIerodeRegion(MRI *mri_src, MRI *mri_dst, int wsize, MRI_REGION *region) { Description ------------------------------------------------------*/ -MRI *MRIcomputeResidual(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) { +MRI *MRIcomputeResidual(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) +{ int width, height, depth, x, y, z; BUFTYPE *p1, *p2, *pdst, v1, v2, out; @@ -1910,7 +1957,8 @@ MRI *MRIcomputeResidual(MRI *mri1, MRI *mri2, MRI *mri_dst, int t1, int t2) { Description ------------------------------------------------------*/ -MRI *MRIminmax(MRI *mri_src, MRI *mri_dst, MRI *mri_dir, int wsize) { +MRI *MRIminmax(MRI *mri_src, MRI *mri_dst, MRI *mri_dir, int wsize) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, whalf, offset; float max_val, val, min_val; float fmin, fmax; @@ -1963,7 +2011,8 @@ MRI *MRIminmax(MRI *mri_src, MRI *mri_dst, MRI *mri_dir, int wsize) { return (mri_dst); } // replace a range of values with a specified one -MRI *MRIreplaceValueRange(MRI *mri_src, MRI *mri_dst, float low_in_val, float hi_in_val, float out_val) { +MRI *MRIreplaceValueRange(MRI *mri_src, MRI *mri_dst, float low_in_val, float hi_in_val, float out_val) +{ int width, height, depth, x, y, z; float val; @@ -1992,7 +2041,8 @@ MRI *MRIreplaceValueRange(MRI *mri_src, MRI *mri_dst, float low_in_val, float hi in the target list. Can be done in-place. See also MRIreplaceValues(). If mask is non-null, then only replaces things in the mask. */ -MRI *MRIreplaceList(MRI *seg, int *srclist, int *targlist, int nlist, MRI *mask, MRI *out) { +MRI *MRIreplaceList(MRI *seg, int *srclist, int *targlist, int nlist, MRI *mask, MRI *out) +{ int c, m; if (!out) { @@ -2042,7 +2092,8 @@ MRI *MRIreplaceList(MRI *seg, int *srclist, int *targlist, int nlist, MRI *mask, \fn MRI *MRIreplaceValues(MRI *mri_src, MRI *mri_dst, float in_val, float out_val) \brief Replaces a single value with a specified one. See also MRIreplaceList(). */ -MRI *MRIreplaceValues(MRI *mri_src, MRI *mri_dst, float in_val, float out_val) { +MRI *MRIreplaceValues(MRI *mri_src, MRI *mri_dst, float in_val, float out_val) +{ int width, height, depth, z; MRIcheckVolDims(mri_src, mri_dst); @@ -2074,7 +2125,8 @@ MRI *MRIreplaceValues(MRI *mri_src, MRI *mri_dst, float in_val, float out_val) { } return (mri_dst); } -MRI *MRIreplaceValuesOnly(MRI *mri_src, MRI *mri_dst, float in_val, float out_val) { +MRI *MRIreplaceValuesOnly(MRI *mri_src, MRI *mri_dst, float in_val, float out_val) +{ int width, height, depth, x, y, z, frame; float val; @@ -2110,7 +2162,8 @@ MRI *MRIreplaceValuesOnly(MRI *mri_src, MRI *mri_dst, float in_val, float out_va Description ------------------------------------------------------*/ -MRI *MRIreplaceValuesUchar(MRI *mri_src, MRI *mri_dst, BUFTYPE in_val, BUFTYPE out_val) { +MRI *MRIreplaceValuesUchar(MRI *mri_src, MRI *mri_dst, BUFTYPE in_val, BUFTYPE out_val) +{ int width, height, depth, x, y, z; BUFTYPE val; BUFTYPE *psrc, *pdst; @@ -2146,7 +2199,8 @@ MRI *MRIreplaceValuesUchar(MRI *mri_src, MRI *mri_dst, BUFTYPE in_val, BUFTYPE o Description ------------------------------------------------------*/ -MRI *MRImeanMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, int wsize) { +MRI *MRImeanMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, int wsize) +{ int width, height, depth, x, y, z, mask_val; // BUFTYPE *pmask; float val; @@ -2179,7 +2233,8 @@ MRI *MRImeanMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, int wsize) } return (mri_dst); } -MRI *MRImaskDifferentGeometry(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, float out_val) { +MRI *MRImaskDifferentGeometry(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, float out_val) +{ MATRIX *m_vox2vox; VECTOR *v1, *v2; int x, y, z, xd, yd, zd, f, mask_val, val; @@ -2229,7 +2284,8 @@ MRI *MRImaskDifferentGeometry(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mas and you want to set voxels outside the mask to 0 (ie, maskmri=0), then MRImask(src,mask,dst,0,0). Handles multiple frames. --------------------------------------------------------------------------*/ -MRI *MRImask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, float out_val) { +MRI *MRImask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, float out_val) +{ int width, height, depth, nframes, x, y, z, f, mask_val; float val; @@ -2274,7 +2330,8 @@ MRI *MRImask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, int mask, float out_val) /*------------------------------------------------------------------ MRImaskInvert() - changes the 1s to 0s and vice versa. ------------------------------------------------------------------*/ -MRI *MRImaskInvert(MRI *mask, MRI *outmask) { +MRI *MRImaskInvert(MRI *mask, MRI *outmask) +{ int c, r, s, f; double v; @@ -2302,7 +2359,8 @@ MRI *MRImaskInvert(MRI *mask, MRI *outmask) { MRInMask() - count the number of voxels in the mask. "In the mask" means > 0.5. ------------------------------------------------------------------*/ -int MRInMask(MRI *mask) { +int MRInMask(MRI *mask) +{ int c, r, s, f, nmask; double v; @@ -2327,7 +2385,8 @@ int MRInMask(MRI *mask) { Description ------------------------------------------------------*/ -MRI *MRIthresholdMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, float mask_threshold, float out_val) { +MRI *MRIthresholdMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, float mask_threshold, float out_val) +{ int width, height, depth, x, y, z; BUFTYPE *pdst, *psrc, *pmask, val, mask_val; float fval, fmask; @@ -2356,7 +2415,8 @@ MRI *MRIthresholdMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, float mask_thre } } } - } else { + } + else { for (z = 0; z < depth; z++) { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { @@ -2375,7 +2435,8 @@ MRI *MRIthresholdMask(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, float mask_thre Description: ----------------------------------------------------------------------*/ -MRI *MRImaskThreshold(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, float threshold, int out_label) { +MRI *MRImaskThreshold(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, float threshold, int out_label) +{ BUFTYPE *pmask, *pdst, *psrc, out_val, mask, in_val; int width, height, depth, x, y, z, nchanged, noff, non; float nvox; @@ -2433,7 +2494,8 @@ MRI *MRImaskThreshold(MRI *mri_src, MRI *mri_mask, MRI *mri_dst, float threshold Description: ----------------------------------------------------------------------*/ -int MRIgrowLabel(MRI *mri, MRI *mri_filled, int in_label, int out_label) { +int MRIgrowLabel(MRI *mri, MRI *mri_filled, int in_label, int out_label) +{ int x, y, z, width, height, depth, xi, yi, zi, xk, yk, zk, nfilled, total_filled, xmin, xmax, ymin, ymax, zmin, zmax; MRIcheckVolDims(mri, mri_filled); @@ -2536,7 +2598,8 @@ int MRIgrowLabel(MRI *mri, MRI *mri_filled, int in_label, int out_label) { Description: ----------------------------------------------------------------------*/ -int MRIturnOnFG(MRI *mri, MRI *mri_fg, MRI *mri_bg) { +int MRIturnOnFG(MRI *mri, MRI *mri_fg, MRI *mri_bg) +{ int x, y, z, width, height, depth; MRIcheckVolDims(mri, mri_fg); @@ -2569,7 +2632,8 @@ int MRIturnOnFG(MRI *mri, MRI *mri_fg, MRI *mri_bg) { return (NO_ERROR); } static BUFTYPE findLabel(MRI *mri, int x0, int y0, int z0); -static BUFTYPE findLabel(MRI *mri, int x, int y, int z) { +static BUFTYPE findLabel(MRI *mri, int x, int y, int z) +{ int xi, yi, zi, xk, yk, zk, label, width, height, depth, counts[256], max_label, max_count, whalf = 1; if (x == 148 && y == 104 && z == 136) DiagBreak(); @@ -2613,7 +2677,8 @@ static BUFTYPE findLabel(MRI *mri, int x, int y, int z) { Description: turn off all voxels which are set in the bg image ----------------------------------------------------------------------*/ -int MRIturnOffBG(MRI *mri, MRI *mri_bg) { +int MRIturnOffBG(MRI *mri, MRI *mri_bg) +{ int x, y, z, width, height, depth; MRIcheckVolDims(mri, mri_bg); @@ -2681,7 +2746,8 @@ findLabel(MRI *mri, int x, int y, int z) MRI_RIGHT_HEMISPHERE) ; } #endif -int MRIsetFrameValues(MRI *mri, int frame, float val) { +int MRIsetFrameValues(MRI *mri, int frame, float val) +{ int width, depth, height, x, y, z; width = mri->width; @@ -2703,7 +2769,8 @@ int MRIsetFrameValues(MRI *mri, int frame, float val) { Description Set an MRI intensity values to 0 ------------------------------------------------------*/ -int MRIsetValues(MRI *mri, float val) { +int MRIsetValues(MRI *mri, float val) +{ int width, depth, height, x, y, z, frame, nframes; width = mri->width; @@ -2730,7 +2797,8 @@ int MRIsetValues(MRI *mri, float val) { Description ------------------------------------------------------*/ -MRI *MRIsoapBubbleLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int label, int niter) { +MRI *MRIsoapBubbleLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int label, int niter) +{ int width, height, depth, x, y, z, x0, y0, z0, xi, yi, zi, xmin, xmax, ymin, ymax, zmin, zmax, i, n; BUFTYPE *plabel; MRI *mri_tmp = NULL; @@ -2812,7 +2880,8 @@ MRI *MRIsoapBubbleLabel(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int label, i Description Copy the label from one volume to another ------------------------------------------------------*/ -int MRIcopyLabel(MRI *mri_src, MRI *mri_dst, int label) { +int MRIcopyLabel(MRI *mri_src, MRI *mri_dst, int label) +{ int width, height, depth, x, y, z, nvox; BUFTYPE *psrc, *pdst; @@ -2835,7 +2904,8 @@ int MRIcopyLabel(MRI *mri_src, MRI *mri_dst, int label) { } } } - } else { + } + else { for (nvox = z = 0; z < depth; z++) { for (y = 0; y < height; y++) { for (x = 0; x < width; x++, pdst++) { @@ -2878,7 +2948,8 @@ MRIlabelOverlap(MRI *mri1, MRI *mri2, int label) } return(nvox) ; }*/ -int MRIlabelOverlap(MRI *mri1, MRI *mri2, int label) { +int MRIlabelOverlap(MRI *mri1, MRI *mri2, int label) +{ int width, height, depth, x, y, z, nvox; int val1, val2; @@ -2899,7 +2970,8 @@ int MRIlabelOverlap(MRI *mri1, MRI *mri2, int label) { } return (nvox); } -int MRIlabelUnion(MRI *mri1, MRI *mri2, int label) { +int MRIlabelUnion(MRI *mri1, MRI *mri2, int label) +{ int width, height, depth, x, y, z, nvox; int val1, val2; @@ -2920,7 +2992,8 @@ int MRIlabelUnion(MRI *mri1, MRI *mri2, int label) { } return (nvox); } -int MRItotalVoxelsOn(MRI *mri, int thresh) { +int MRItotalVoxelsOn(MRI *mri, int thresh) +{ int width, height, depth, x, y, z, nvox, f; float val; @@ -2948,7 +3021,8 @@ int MRItotalVoxelsOn(MRI *mri, int thresh) { Description Count and return the # of voxels with a given label. ------------------------------------------------------*/ -int MRIvoxelsInLabel(MRI *mri, int label) { +int MRIvoxelsInLabel(MRI *mri, int label) +{ int width, height, depth, x, y, z, nvox, val; width = mri->width; @@ -2966,7 +3040,8 @@ int MRIvoxelsInLabel(MRI *mri, int label) { return (nvox); } -MRI *MRInot(MRI *mri_src, MRI *mri_dst) { +MRI *MRInot(MRI *mri_src, MRI *mri_dst) +{ int x, y, z, out; float val; @@ -2986,7 +3061,8 @@ MRI *MRInot(MRI *mri_src, MRI *mri_dst) { } return (mri_dst); } -int MRIcopyLabeledVoxels(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int label) { +int MRIcopyLabeledVoxels(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int label) +{ int width, height, depth, x, y, z, nvox; float val; @@ -3010,7 +3086,8 @@ int MRIcopyLabeledVoxels(MRI *mri_src, MRI *mri_labeled, MRI *mri_dst, int label } return (nvox); } -MRI *MRIsetLabelValues(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int label, float val) { +MRI *MRIsetLabelValues(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int label, float val) +{ int x, y, z, l; MRIcheckVolDims(mri_src, mri_label); @@ -3035,7 +3112,8 @@ MRI *MRIsetLabelValues(MRI *mri_src, MRI *mri_label, MRI *mri_dst, int label, fl will be 0. All frames will have the same mask. ---------------------------------------------------------------*/ MRI *MRIsphereMask( - int ncols, int nrows, int nslices, int nframes, int c0, int r0, int s0, double voxradius, double val, MRI *mri) { + int ncols, int nrows, int nslices, int nframes, int c0, int r0, int s0, double voxradius, double val, MRI *mri) +{ int r, c, s, f; double d2, r2, v; @@ -3057,7 +3135,8 @@ MRI *MRIsphereMask( } return (mri); } -int MRIlabelInVolume(MRI *mri_src, int label) { +int MRIlabelInVolume(MRI *mri_src, int label) +{ int x, y, z; for (x = 0; x < mri_src->width; x++) @@ -3066,7 +3145,8 @@ int MRIlabelInVolume(MRI *mri_src, int label) { if ((int)MRIgetVoxVal(mri_src, x, y, z, 0) == label) return (1); return (0); } -int MRIlabeledVoxels(MRI *mri_src, int label) { +int MRIlabeledVoxels(MRI *mri_src, int label) +{ int x, y, z, num; for (num = 0, x = 0; x < mri_src->width; x++) @@ -3083,7 +3163,8 @@ int MRIlabeledVoxels(MRI *mri_src, int label) { the values outside to be OutVal. template is a geometry template. */ -MRI *MRIsetBoundingBox(MRI *template, MRI_REGION *region, double InVal, double OutVal) { +MRI *MRIsetBoundingBox(MRI *template, MRI_REGION *region, double InVal, double OutVal) +{ MRI *mri; int x2, y2, z2; int c, r, s; @@ -3142,7 +3223,8 @@ MRI *MRIsetBoundingBox(MRI *template, MRI_REGION *region, double InVal, double O } extern char *cma_label_to_name(int label); -double MRIcomputeLabelAccuracy(MRI *mri_src, MRI *mri_ref, int which, FILE *fp) { +double MRIcomputeLabelAccuracy(MRI *mri_src, MRI *mri_ref, int which, FILE *fp) +{ double total_accuracy = 0.0, accuracy; int label, nlabels, *present, x, y, z, nvox; float min_val, max_val, vsize; @@ -3186,7 +3268,8 @@ double MRIcomputeLabelAccuracy(MRI *mri_src, MRI *mri_ref, int which, FILE *fp) return (total_accuracy); } -double MRIcomputeMeanMinLabelDistance(MRI *mri_src, MRI *mri_ref, int label) { +double MRIcomputeMeanMinLabelDistance(MRI *mri_src, MRI *mri_ref, int label) +{ MRI *mri_src_dist, *mri_ref_dist; int nvox1, nvox2, x, y, z; float xd, yd, zd; @@ -3261,7 +3344,8 @@ double MRIcomputeMeanMinLabelDistance(MRI *mri_src, MRI *mri_ref, int label) { return (mean_min_dist); } -int MRIcomputeCentroid(MRI *mri, double *pxc, double *pyc, double *pzc) { +int MRIcomputeCentroid(MRI *mri, double *pxc, double *pyc, double *pzc) +{ int x, y, z; double xc, yc, zc, val, norm; @@ -3289,7 +3373,8 @@ int MRIcomputeCentroid(MRI *mri, double *pxc, double *pyc, double *pzc) { return (NO_ERROR); } -int MRIcomputeLabelCentroid(MRI *mri_aseg, int label, double *pxc, double *pyc, double *pzc) { +int MRIcomputeLabelCentroid(MRI *mri_aseg, int label, double *pxc, double *pyc, double *pzc) +{ int l, x, y, z, num; double xc, yc, zc; @@ -3317,7 +3402,8 @@ int MRIcomputeLabelCentroid(MRI *mri_aseg, int label, double *pxc, double *pyc, return (NO_ERROR); } -MRI *MRIdivideAseg(MRI *mri_src, MRI *mri_dst, int label, int nunits) { +MRI *MRIdivideAseg(MRI *mri_src, MRI *mri_dst, int label, int nunits) +{ float evalues[3], dx, dy, dz, e1x, e1y, e1z; // float mx; MATRIX *m_obs, *m_obs_T, *m_cov, *m_eig; @@ -3408,14 +3494,16 @@ MRI *MRIdivideAseg(MRI *mri_src, MRI *mri_dst, int label, int nunits) { \fn MRI *MRIbinMaskToCol(MRI *binmask, MRI *bincol) \brief Sets the value of a voxel in the mask to its column number. */ -MRI *MRIbinMaskToCol(MRI *binmask, MRI *bincol) { +MRI *MRIbinMaskToCol(MRI *binmask, MRI *bincol) +{ int c, r, s, v; float m; if (bincol == NULL) { bincol = MRIcloneBySpace(binmask, MRI_INT, -1); if (bincol == NULL) return (NULL); - } else { + } + else { if (MRIdimMismatch(binmask, bincol, 1)) { printf("ERROR: MRIbinMaskToCol: input/output dim mismatch\n"); return (NULL); @@ -3448,7 +3536,8 @@ MRI *MRIbinMaskToCol(MRI *binmask, MRI *bincol) { and for which the corresponding voxel in mri_src is below threshold. ------------------------------------------------------*/ -MRI *MRIfloodFillRegion(MRI *mri_src, MRI *mri_dst, int threshold, int fill_val, int max_count) { +MRI *MRIfloodFillRegion(MRI *mri_src, MRI *mri_dst, int threshold, int fill_val, int max_count) +{ int width, height, depth, x, y, z, nfilled, xmin, xmax, ymin, ymax, zmin, zmax, on, x0, x1, y0, y1, z0, z1; BUFTYPE *psrc, *pdst, val; @@ -3536,7 +3625,8 @@ MRI *MRIfloodFillRegion(MRI *mri_src, MRI *mri_dst, int threshold, int fill_val, set voxels with a different value in mri1 and mri2 to a dst_val in target volume ------------------------------------------------------*/ -int MRIsetDifferentVoxelsWithValue(MRI *mri1, MRI *mri2, MRI *mri_dst, int dst_val) { +int MRIsetDifferentVoxelsWithValue(MRI *mri1, MRI *mri2, MRI *mri_dst, int dst_val) +{ int width, height, depth, x, y, z, nvox; if (mri_dst == NULL) mri_dst = MRIclone(mri1, NULL); @@ -3567,7 +3657,8 @@ int MRIsetDifferentVoxelsWithValue(MRI *mri1, MRI *mri2, MRI *mri_dst, int dst_v Description set voxels with value in src volume to a different value in target volume ------------------------------------------------------*/ -int MRIsetVoxelsWithValue(MRI *mri_src, MRI *mri_dst, int src_val, int dst_val) { +int MRIsetVoxelsWithValue(MRI *mri_src, MRI *mri_dst, int src_val, int dst_val) +{ int width, height, depth, x, y, z, nvox; if (mri_dst == NULL) mri_dst = MRIclone(mri_src, NULL); @@ -3595,7 +3686,8 @@ int MRIsetVoxelsWithValue(MRI *mri_src, MRI *mri_dst, int src_val, int dst_val) \brief Computes a threshold above which there will be pct percent of the voxels in the mask. */ -double MRIpercentThresh(MRI *mri, MRI *mask, int frame, double pct) { +double MRIpercentThresh(MRI *mri, MRI *mask, int frame, double pct) +{ double *vlist, thresh; int nlist, ntot, npct; int c, r, s; @@ -3626,7 +3718,8 @@ double MRIpercentThresh(MRI *mri, MRI *mask, int frame, double pct) { return (thresh); } -MRI *MRIminAbs(MRI *mri_src1, MRI *mri_src2, MRI *mri_dst) { +MRI *MRIminAbs(MRI *mri_src1, MRI *mri_src2, MRI *mri_dst) +{ int x, y, z, f; float val1, val2; @@ -3644,7 +3737,8 @@ MRI *MRIminAbs(MRI *mri_src1, MRI *mri_src2, MRI *mri_dst) { return (mri_dst); } -MRI *MRImin(MRI *mri1, MRI *mri2, MRI *mri_min) { +MRI *MRImin(MRI *mri1, MRI *mri2, MRI *mri_min) +{ int x, y, z, f; float val1, val2; @@ -3663,7 +3757,8 @@ MRI *MRImin(MRI *mri1, MRI *mri2, MRI *mri_min) { return (mri_min); } -int MRIcountNonzero(MRI *mri) { +int MRIcountNonzero(MRI *mri) +{ int x, y, z, nonzero, f; for (nonzero = f = 0; f < mri->nframes; f++) @@ -3674,7 +3769,8 @@ int MRIcountNonzero(MRI *mri) { return (nonzero); } -int MRIcountValInNbhd(MRI *mri, int wsize, int x, int y, int z, int val) { +int MRIcountValInNbhd(MRI *mri, int wsize, int x, int y, int z, int val) +{ int xk, yk, zk, xi, yi, zi, whalf, total; whalf = (wsize - 1) / 2; @@ -3690,7 +3786,8 @@ int MRIcountValInNbhd(MRI *mri, int wsize, int x, int y, int z, int val) { } return (total); } -int MRIkarcherMean(MRI *mri, float low_val, float hi_val, int *px, int *py, int *pz) { +int MRIkarcherMean(MRI *mri, float low_val, float hi_val, int *px, int *py, int *pz) +{ double xc, yc, zc, dist, min_dist, val; int x, y, z, num; diff --git a/utils/mrishash.c b/utils/mrishash.c index 00668a329f5..9525f1d16c2 100644 --- a/utils/mrishash.c +++ b/utils/mrishash.c @@ -82,7 +82,8 @@ #undef false typedef enum { false = 0, true = 1 } bool; -typedef struct { +typedef struct +{ int xv; int yv; int zv; @@ -95,13 +96,15 @@ typedef struct { // But better safe than sorry, I guess. //---------------------------------------------------------------------- #define MAX_VOXELS 10000 -typedef struct { +typedef struct +{ int nused; int voxels[MAX_VOXELS][3]; } VOXEL_LISTgw; // Ad hoc points -typedef struct { +typedef struct +{ double x; double y; double z; @@ -146,7 +149,8 @@ static int checkFace(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int fno1); //============================================================================= //------------------------------------ -MRIS_HASH_TABLE *MHTfillTable(MRI_SURFACE *mris, MRIS_HASH_TABLE *mht) { +MRIS_HASH_TABLE *MHTfillTable(MRI_SURFACE *mris, MRIS_HASH_TABLE *mht) +{ //------------------------------------ return (MHTfillTableAtResolution(mris, mht, CURRENT_VERTICES, VOXEL_RES)); } @@ -289,7 +293,8 @@ int MHTremoveAllFaces(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v) Adds face fno to mht. Calls mhtVoxelList_SampleFace to get a list of MHT Voxels (buckets) in which to list fno. -------------------------------------------------*/ -static int mhtFaceToMHT(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int fno, int on) { +static int mhtFaceToMHT(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int fno, int on) +{ //------------------------------------ FACE *face; VERTEX *v0, *v1, *v2; @@ -339,7 +344,8 @@ static int mhtFaceToMHT(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int fno, int on impinged upon, listing those in voxlist. -------------------------------------------------*/ static int mhtVoxelList_SampleFace( - float mhtres, Ptdbl_t *vptin0, Ptdbl_t *vptin1, Ptdbl_t *vptin2, int fno, VOXEL_LISTgw *voxlist) { + float mhtres, Ptdbl_t *vptin0, Ptdbl_t *vptin1, Ptdbl_t *vptin2, int fno, VOXEL_LISTgw *voxlist) +{ //------------------------------------ const float SamplesPerMHTRes = 2.0; double mhtres_recip; @@ -444,7 +450,8 @@ static int mhtVoxelList_SampleFace( mhtVoxelList_AddCoord(voxlist, voxco_b2a, fno); mhtVoxelList_AddCoord(voxlist, voxco_c2a, fno); changed = true; - } else { + } + else { //--------------------------------------------- // If we crossed a boundary, add that "path" to voxlist //--------------------------------------------- @@ -625,7 +632,8 @@ MRIS_HASH_TABLE *MHTfillVertexTableRes(MRI_SURFACE *mris, MRIS_HASH_TABLE *mht, Adds forvnum (Face or Vertex number) to mht, in bucket(xv,yv,zv) Coerces (xv,yv,zv) to be sane. -------------------------------------------------------------*/ -static int mhtAddFaceOrVertexAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int zv, int forvnum) { +static int mhtAddFaceOrVertexAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int zv, int forvnum) +{ //--------------------------------------- int i; MHB *bin; @@ -701,7 +709,8 @@ static int mhtAddFaceOrVertexAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int z Converts x, y, z to bucket indexes, calls mhtAddFaceOrVertexAtIndexes Adds forvnum (Face or Vertex number) to mht, in bucket(xv,yv,zv) -------------------------------------------------------------*/ -static int mhtAddFaceOrVertexAtCoords(MRIS_HASH_TABLE *mht, float x, float y, float z, int forvnum) { +static int mhtAddFaceOrVertexAtCoords(MRIS_HASH_TABLE *mht, float x, float y, float z, int forvnum) +{ //--------------------------------------- int xv, yv, zv; @@ -716,7 +725,8 @@ static int mhtAddFaceOrVertexAtCoords(MRIS_HASH_TABLE *mht, float x, float y, fl mhtRemoveFaceOrVertexAtVoxIx (was mhtRemoveFacePosition) Reverse of mhtAddFaceOrVertexAtIndexes -------------------------------------------------------------*/ -static int mhtRemoveFaceOrVertexAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int zv, int forvnum) { +static int mhtRemoveFaceOrVertexAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int zv, int forvnum) +{ //--------------------------------------- int i; MHBT *bucket; @@ -765,7 +775,8 @@ static int mhtRemoveFaceOrVertexAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, in Notes: 1. MUST be used with mht prepared for CURRENT_VERTICES ------------------------------------------------------*/ -int MHTisVectorFilled(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int vtxno, float dx, float dy, float dz) { +int MHTisVectorFilled(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int vtxno, float dx, float dy, float dz) +{ //-------------------------------------------------------------- VERTEX *vtx; float savex, savey, savez; @@ -819,7 +830,8 @@ int MHTisVectorFilled(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int vtxno, float which was previously hashed into mht using MHTfillTableXxx Returns 1 for "yes -- intersection detected", else NO_ERROR. -------------------------------------------------------------*/ -int MHTdoesFaceIntersect(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int fno) { +int MHTdoesFaceIntersect(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int fno) +{ //------------------------------------------------------------ VERTEX *v0, *v1, *v2; Ptdbl_t vpt0, vpt1, vpt2; @@ -1028,7 +1040,8 @@ static int mhtDoesFaceVoxelListIntersect(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris //================================================================= //--------------------------------------------- -void mhtFindCommonSanityCheck(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris) { +void mhtFindCommonSanityCheck(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris) +{ //--------------------------------------------- if (!mht) ErrorExit(ERROR_BADPARM, "%s: mht is NULL\n", __MYFUNCTION__); if (!mris) ErrorExit(ERROR_BADPARM, "%s: mris is NULL\n", __MYFUNCTION__); @@ -1045,7 +1058,8 @@ int FindBucketsPresent_Count; int VertexNumFoundByMHT; /* 2007-07-30 GW: Added to allow diagnostics even with fallback-to-brute-force */ -void MHTfindReportCounts(int *BucketsChecked, int *BucketsPresent, int *VtxNumByMHT) { +void MHTfindReportCounts(int *BucketsChecked, int *BucketsPresent, int *VtxNumByMHT) +{ if (BucketsChecked) *BucketsChecked = FindBucketsChecked_Count; if (BucketsPresent) *BucketsPresent = FindBucketsPresent_Count; if (VtxNumByMHT) *VtxNumByMHT = VertexNumFoundByMHT; // 2007-07-30 GW @@ -1071,7 +1085,8 @@ int mhtfindClosestVertexGenericInBucket(MRIS_HASH_TABLE *mht, //---------- in/outs ------------- VERTEX **MinDistVtx, int *MinDistVtxNum, - double *MinDistSq) { + double *MinDistSq) +{ int vtxix, rslt; VERTEX *AVtx; int AVtxNum; @@ -1140,7 +1155,8 @@ int mhtfindClosestFaceCentroidGenericInBucket(MRIS_HASH_TABLE *mht, //---------- in/outs ------------- FACE **MinDistFace, int *MinDistFaceNum, - double *MinDistSq) { + double *MinDistSq) +{ int faceix, rslt; FACE *face; int fno; @@ -1248,7 +1264,8 @@ int MHTfindClosestVertexGeneric(MRIS_HASH_TABLE *mht, //---------- outputs ------------- VERTEX **pvtx, int *vtxnum, - double *vtx_distance) { + double *vtx_distance) +{ const int max_mhts_MAX = 5; double mhtres, max_distance_mm, tempdbl; int max_mhts; @@ -1283,17 +1300,20 @@ int MHTfindClosestVertexGeneric(MRIS_HASH_TABLE *mht, max_distance_mm = in_max_distance_mm; if ((max_distance_mm * 2) <= mhtres) { max_mhts = 0; - } else { + } + else { max_mhts = ceil(max_distance_mm / mhtres); } - } else { + } + else { max_mhts = in_max_mhts; max_distance_mm = in_max_distance_mm; // How far does max_mhts cover in mm? if (max_mhts >= 1) { tempdbl = max_mhts * mhtres; - } else { + } + else { tempdbl = 0.5 * mhtres; } // Must not include points beyond the exhaustive coverage distance @@ -1547,7 +1567,8 @@ int MHTfindClosestFaceGeneric(MRIS_HASH_TABLE *mht, //---------- outputs ------------- FACE **pface, int *pfno, - double *pface_distance) { + double *pface_distance) +{ // const int max_mhts_MAX = 5; double mhtres, max_distance_mm, tempdbl; int max_mhts; @@ -1582,17 +1603,20 @@ int MHTfindClosestFaceGeneric(MRIS_HASH_TABLE *mht, max_distance_mm = in_max_distance_mm; if ((max_distance_mm * 2) <= mhtres) { max_mhts = 0; - } else { + } + else { max_mhts = ceil(max_distance_mm / mhtres); } - } else { + } + else { max_mhts = in_max_mhts; max_distance_mm = in_max_distance_mm; // How far does max_mhts cover in mm? if (max_mhts >= 1) { tempdbl = max_mhts * mhtres; - } else { + } + else { tempdbl = 0.5 * mhtres; } // Must not include points beyond the exhaustive coverage distance @@ -1793,7 +1817,8 @@ int MHTfindClosestFaceGeneric(MRIS_HASH_TABLE *mht, MHTfindClosestVertex Returns VERTEX *, closest vertex to v in mris & mht (or NULL). -----------------------------------------------------------------*/ -VERTEX *MHTfindClosestVertex(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v) { +VERTEX *MHTfindClosestVertex(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v) +{ //------------------------------------------------------ VERTEX *vtx; // int rslt; @@ -1825,7 +1850,8 @@ VERTEX *MHTfindClosestVertex(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v) MHTfindClosestVertex Returns index of face whose centroid is closest to the specified vertex -----------------------------------------------------------------*/ -FACE *MHTfindClosestFaceToVertex(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v) { +FACE *MHTfindClosestFaceToVertex(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v) +{ //------------------------------------------------------ FACE *face; // int rslt; @@ -1878,7 +1904,8 @@ FACE *MHTfindClosestFaceToVertex(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX marked [GW 2007-07-25] -----------------------------------------------------------------------*/ -VERTEX *MHTfindClosestVertexSet(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v, int which_ignored) { +VERTEX *MHTfindClosestVertexSet(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v, int which_ignored) +{ //------------------------------------------------------ VERTEX *vtx = NULL; // int rslt; @@ -1936,7 +1963,8 @@ VERTEX *MHTfindClosestVertexSet(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX Returns vertex number and distance from vertex v to closest vertex in mris & mht. --------------------------------------------------------------------*/ -int MHTfindClosestVertexNo(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v, float *min_dist) { +int MHTfindClosestVertexNo(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v, float *min_dist) +{ //------------------------------------------------------ int vtxnum, rslt; double x = 0.0, y = 0.0, z = 0.0, min_dist_dbl; @@ -1978,7 +2006,8 @@ int MHTfindClosestVertexNo(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v, f Returns vertex from mris & mht that's closest to provided coordinates. ---------------------------------------------------------------*/ VERTEX *MHTfindClosestVertexInTable( - MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, float x, float y, float z, int do_global_search) { + MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, float x, float y, float z, int do_global_search) +{ //------------------------------------------------------ VERTEX *vtx; // int rslt; @@ -2039,7 +2068,8 @@ VERTEX *MHTfindClosestVertexInTable( in all the FS source code, so I'm not bothering to implement its functionality in the generic Find function, however it would be easy to do. ------------------------------------------------------------*/ -int *MHTgetAllVerticesWithinDistance(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int vno, float max_dist, int *pvnum) { +int *MHTgetAllVerticesWithinDistance(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int vno, float max_dist, int *pvnum) +{ //------------------------------------------------------ ErrorExit(ERROR_UNSUPPORTED, "%s: not implemented.\n", __MYFUNCTION__); @@ -2057,7 +2087,8 @@ int mhtBruteForceClosestVertex(MRI_SURFACE *mris, float y, float z, int which, // which surface within mris to search - float *dmin) { + float *dmin) +{ int vno, min_v = -1; VERTEX *vtx; float dsq, min_dsq; // Work with squares, avoid square root operation @@ -2141,7 +2172,8 @@ int mhtBruteForceClosestFace(MRI_SURFACE *mris, float y, float z, int which, // which surface within mris to search - float *dmin) { + float *dmin) +{ int fno, min_f = -1; FACE *face; float dsq, min_dsq; // Work with squares, avoid square root operation @@ -2205,7 +2237,8 @@ int MHTfree(MRIS_HASH_TABLE **pmht) return (NO_ERROR); } -static void mhtFaceCentroid2xyz_float(MRI_SURFACE *mris, FACE *face, int which, float *px, float *py, float *pz) { +static void mhtFaceCentroid2xyz_float(MRI_SURFACE *mris, FACE *face, int which, float *px, float *py, float *pz) +{ #if 1 *px = face->cx; *py = face->cy; @@ -2231,7 +2264,8 @@ static void mhtFaceCentroid2xyz_float(MRI_SURFACE *mris, FACE *face, int which, } //--------------------------------------------- -static void mhtVertex2xyz_float(VERTEX *vtx, int which, float *x, float *y, float *z) { +static void mhtVertex2xyz_float(VERTEX *vtx, int which, float *x, float *y, float *z) +{ //--------------------------------------------- if (!vtx) return; @@ -2278,7 +2312,8 @@ static void mhtVertex2xyz_float(VERTEX *vtx, int which, float *x, float *y, floa return; } //--------------------------------------------- -static void mhtVertex2xyz_double(VERTEX *vtx, int which, double *x, double *y, double *z) { +static void mhtVertex2xyz_double(VERTEX *vtx, int which, double *x, double *y, double *z) +{ //--------------------------------------------- if (!vtx) return; @@ -2325,7 +2360,8 @@ static void mhtVertex2xyz_double(VERTEX *vtx, int which, double *x, double *y, d return; } //--------------------------------------------- -static void mhtVertex2Ptxyz_double(VERTEX *vtx, int which, Ptdbl_t *pt) { +static void mhtVertex2Ptxyz_double(VERTEX *vtx, int which, Ptdbl_t *pt) +{ //--------------------------------------------- if ((!vtx) || (!pt)) return; @@ -2373,7 +2409,8 @@ static void mhtVertex2Ptxyz_double(VERTEX *vtx, int which, Ptdbl_t *pt) { } //--------------------------------------------- -static void mhtVertex2array3_double(VERTEX *vtx, int which, double *array3) { +static void mhtVertex2array3_double(VERTEX *vtx, int which, double *array3) +{ //--------------------------------------------- if (!vtx) return; @@ -2421,7 +2458,8 @@ static void mhtVertex2array3_double(VERTEX *vtx, int which, double *array3) { } /*-----------------------------------------------------------------*/ -MHBT *MHTgetBucket(MRIS_HASH_TABLE *mht, float x, float y, float z) { +MHBT *MHTgetBucket(MRIS_HASH_TABLE *mht, float x, float y, float z) +{ //------------------------------------------------------------------- int xv, yv, zv; @@ -2433,7 +2471,8 @@ MHBT *MHTgetBucket(MRIS_HASH_TABLE *mht, float x, float y, float z) { } /*-----------------------------------------------------------------*/ -MHBT *MHTgetBucketAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int zv) { +MHBT *MHTgetBucketAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int zv) +{ //------------------------------------------------------------------- MHBT *bucket; @@ -2452,7 +2491,8 @@ MHBT *MHTgetBucketAtVoxIx(MRIS_HASH_TABLE *mht, int xv, int yv, int zv) { Confidence check that correct version of code is compiled in; ------------------------------------------------*/ -int MHT_gw_version(void) { +int MHT_gw_version(void) +{ //------------------------------- return GW_VERSION; // <-- change this as needed } @@ -2462,14 +2502,16 @@ int MHT_gw_version(void) { //================================================================= //-------------------------------------------------- -static int mhtVoxelList_Init(VOXEL_LISTgw *voxlist) { +static int mhtVoxelList_Init(VOXEL_LISTgw *voxlist) +{ //-------------------------------------------------- voxlist->nused = 0; return (NO_ERROR); } //-------------------------------------------------- -static int mhtVoxelList_Add(VOXEL_LISTgw *voxlist, int xv, int yv, int zv, int fno) { +static int mhtVoxelList_Add(VOXEL_LISTgw *voxlist, int xv, int yv, int zv, int fno) +{ //-------------------------------------------------- int i; @@ -2494,13 +2536,15 @@ static int mhtVoxelList_Add(VOXEL_LISTgw *voxlist, int xv, int yv, int zv, int f } //-------------------------------------------------- -static int mhtVoxelList_AddCoord(VOXEL_LISTgw *voxlist, VOXEL_COORD vc, int fno) { +static int mhtVoxelList_AddCoord(VOXEL_LISTgw *voxlist, VOXEL_COORD vc, int fno) +{ //-------------------------------------------------- return mhtVoxelList_Add(voxlist, vc.xv, vc.yv, vc.zv, fno); } //-------------------------------------------------- -static int mhtVoxelList_AddPath(VOXEL_LISTgw *voxlist, VOXEL_COORD oldvc, VOXEL_COORD newvc, int fno) { +static int mhtVoxelList_AddPath(VOXEL_LISTgw *voxlist, VOXEL_COORD oldvc, VOXEL_COORD newvc, int fno) +{ //-------------------------------------------------- int xv, yv, zv, count; int incx = -1, incy = -1, incz = -1; @@ -2702,7 +2746,8 @@ static int checkFace(MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, int fno1) } VERTEX *MHTfindClosestVertexSetInDirection( - MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v, int which, double nx, double ny, double nz) { + MRIS_HASH_TABLE *mht, MRI_SURFACE *mris, VERTEX *v, int which, double nx, double ny, double nz) +{ VERTEX *v_closest, *vn; double dx, dy, dz, dot, dist, min_dist; int vno; @@ -2769,7 +2814,8 @@ VERTEX *MHTfindClosestVertexSetInDirection( return (v_closest); } -static void mhtStoreFaceCentroids(MRI_SURFACE *mris, int which) { +static void mhtStoreFaceCentroids(MRI_SURFACE *mris, int which) +{ float x, y, z, xt, yt, zt; int n, fno; FACE *face; diff --git a/utils/mrisp.c b/utils/mrisp.c index 8e540acdbf0..7fdef9fbb95 100644 --- a/utils/mrisp.c +++ b/utils/mrisp.c @@ -389,7 +389,8 @@ MRIStoParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale,int fno) return(mrisp) ; } #else -MRI_SP *MRIStoParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, int fno) { +MRI_SP *MRIStoParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, int fno) +{ float a, b, c, phi, theta, x, y, z, uf, vf, d, total_d, **distances, *fp; int vno, u, v, unfilled, **filled, npasses, nfilled; VERTEX *vertex; @@ -590,9 +591,11 @@ MRI_SP *MRIStoParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, in *IMAGEFseq_pix(Itmp, u, v, fno) = total; filled[u][v] = FILLING_ELT; nfilled++; - } else + } + else unfilled++; - } else + } + else *IMAGEFseq_pix(Itmp, u, v, fno) = *IMAGEFseq_pix(Ip, u, v, fno); } } @@ -628,7 +631,8 @@ MRI_SP *MRIStoParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, in static double UF = 254.8, VF = 409.5; -MRI_SP *MRIScoordsToParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, int which_vertices) { +MRI_SP *MRIScoordsToParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, int which_vertices) +{ float a, b, c, phi, theta, x, y, z, uf, vf, d, total_d, **distances; int vno, u, v, unfilled, **filled, npasses, nfilled; VERTEX *vertex; @@ -826,9 +830,11 @@ MRI_SP *MRIScoordsToParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float sca *IMAGEFseq_pix(Itmp, u, v, 2) = totalz; filled[u][v] = FILLING_ELT; nfilled++; - } else + } + else unfilled++; - } else { + } + else { *IMAGEFseq_pix(Itmp, u, v, 0) = *IMAGEFseq_pix(Ip, u, v, 0); *IMAGEFseq_pix(Itmp, u, v, 1) = *IMAGEFseq_pix(Ip, u, v, 1); *IMAGEFseq_pix(Itmp, u, v, 2) = *IMAGEFseq_pix(Ip, u, v, 2); @@ -869,7 +875,8 @@ MRI_SP *MRIScoordsToParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float sca Description ------------------------------------------------------*/ -MRI_SURFACE *MRISfromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, int fno) { +MRI_SURFACE *MRISfromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, int fno) +{ float a, b, c, phi, theta, x, y, z, uf, vf, du, dv, curv, d; int vno, u0, v0, u1, v1; VERTEX *vertex; @@ -948,7 +955,8 @@ MRI_SURFACE *MRISfromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, int fno) Description ------------------------------------------------------*/ -MRI_SURFACE *MRIScoordsFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, int which_vertices) { +MRI_SURFACE *MRIScoordsFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, int which_vertices) +{ float a, b, c, phi, theta, x, y, z, uf, vf, du, dv, origx, origy, origz, d, val1, val2, val3, val4; int vno, u0, v0, u1, v1; VERTEX *vertex; @@ -1067,7 +1075,8 @@ MRI_SURFACE *MRIScoordsFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, in Description ------------------------------------------------------*/ -MRI_SURFACE *MRISnormalizeFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, int fno) { +MRI_SURFACE *MRISnormalizeFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, int fno) +{ float a, b, c, phi, theta, x, y, z, uf, vf, du, dv, curv, d, var; int vno, u0, v0, u1, v1; VERTEX *vertex; @@ -1142,7 +1151,8 @@ MRI_SURFACE *MRISnormalizeFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris, Description ------------------------------------------------------*/ -MRI_SP *MRISgradientToParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale) { +MRI_SP *MRISgradientToParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float scale) +{ float a, b, c, phi, theta, x, y, z, uf, vf, d, total_d, **distances, sigma, two_sigma_sq; int vno, u, v, unfilled, **filled; VERTEX *vertex; @@ -1310,7 +1320,8 @@ MRI_SP *MRISgradientToParameterization(MRI_SURFACE *mris, MRI_SP *mrisp, float s Description ------------------------------------------------------*/ -MRI_SURFACE *MRISgradientFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris) { +MRI_SURFACE *MRISgradientFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris) +{ float a, b, c, phi, theta, x, y, z, uf, vf, du, dv, d; int vno, u0, v0, u1, v1; VERTEX *vertex; @@ -1397,7 +1408,8 @@ MRI_SURFACE *MRISgradientFromParameterization(MRI_SP *mrisp, MRI_SURFACE *mris) Description ------------------------------------------------------*/ -double MRISPfunctionVal(MRI_SURFACE_PARAMETERIZATION *mrisp, MRI_SURFACE *mris, float x, float y, float z, int fno) { +double MRISPfunctionVal(MRI_SURFACE_PARAMETERIZATION *mrisp, MRI_SURFACE *mris, float x, float y, float z, int fno) +{ double r, r2, r4, r6, val, d, x2, y2, z2, g, h, f, dx, dy, dz; float phi, theta, uf, vf, du, dv; int u0, v0, u1, v1, u0_voff, u1_voff, u1_v0, u1_v1, u0_v0, u0_v1; @@ -1445,19 +1457,23 @@ double MRISPfunctionVal(MRI_SURFACE_PARAMETERIZATION *mrisp, MRI_SURFACE *mris, { u0_voff = V_DIM(mrisp) / 2; u0 = -u0; - } else if (u0 >= U_DIM(mrisp)) { + } + else if (u0 >= U_DIM(mrisp)) { u0_voff = V_DIM(mrisp) / 2; u0 = U_DIM(mrisp) - (u0 - U_DIM(mrisp) + 1); - } else + } + else u0_voff = 0; if (u1 < 0) /* enforce spherical topology */ { u1_voff = V_DIM(mrisp) / 2; u1 = -u1; - } else if (u1 >= U_DIM(mrisp)) { + } + else if (u1 >= U_DIM(mrisp)) { u1_voff = V_DIM(mrisp) / 2; u1 = U_DIM(mrisp) - (u1 - U_DIM(mrisp) + 1); - } else + } + else u1_voff = 0; if (v0 < 0) v0 += V_DIM(mrisp); if (v0 >= V_DIM(mrisp)) v0 -= V_DIM(mrisp); @@ -1487,7 +1503,8 @@ double MRISPfunctionVal(MRI_SURFACE_PARAMETERIZATION *mrisp, MRI_SURFACE *mris, Description ------------------------------------------------------*/ -MRI_SP *MRISPclone(MRI_SP *mrisp_src) { +MRI_SP *MRISPclone(MRI_SP *mrisp_src) +{ MRI_SP *mrisp_dst; mrisp_dst = (MRI_SP *)calloc(1, sizeof(MRI_SP)); @@ -1507,7 +1524,8 @@ MRI_SP *MRISPclone(MRI_SP *mrisp_src) { #define MAX_LEN 4 #define MAX_KLEN 50 -MRI_SP *MRISPconvolveGaussian(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, float radius, int fno) { +MRI_SP *MRISPconvolveGaussian(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, float radius, int fno) +{ int u, v, cart_klen, klen, khalf, uk, vk, u1, v1, voff, f0, f1; double d, k, total, ktotal, sigma_sq_inv, theta, phi, theta1, phi1, sin_phi, cos_phi, sin_phi1, cos_phi1; float x0, y0, z0, x1, y1, z1, circumference = 0.0f, angle, max_len = 0.0f, min_len = 10000.0f; @@ -1538,7 +1556,8 @@ MRI_SP *MRISPconvolveGaussian(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, if (fno < 0) { f0 = 0; f1 = Ip_src->num_frame - 1; - } else { + } + else { f0 = f1 = fno; } @@ -1610,10 +1629,12 @@ MRI_SP *MRISPconvolveGaussian(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, { voff = V_DIM(mrisp_src) / 2; u1 = -u1; - } else if (u1 >= U_DIM(mrisp_src)) { + } + else if (u1 >= U_DIM(mrisp_src)) { u1 = U_DIM(mrisp_src) - (u1 - U_DIM(mrisp_src) + 1); voff = V_DIM(mrisp_src) / 2; - } else + } + else voff = 0; phi1 = (double)u1 * PHI_MAX / PHI_DIM(mrisp_src); @@ -1658,7 +1679,8 @@ MRI_SP *MRISPconvolveGaussian(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, Description ------------------------------------------------------*/ -MRI_SP *MRISPblur(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int fno) { +MRI_SP *MRISPblur(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int fno) +{ int f0, f1; int no_sphere_init; int cart_klen_init; @@ -1693,7 +1715,8 @@ MRI_SP *MRISPblur(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int fno) { if (fno < 0) { f0 = 0; f1 = Ip_src->num_frame - 1; - } else { + } + else { f0 = f1 = fno; } @@ -1723,7 +1746,8 @@ MRI_SP *MRISPblur(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int fno) { k = cart_klen * cart_klen; klen = sqrt(k + k / sin_sq_u); if (klen > MAX_LEN * cart_klen) klen = MAX_LEN * cart_klen; - } else + } + else klen = MAX_LEN * cart_klen; /* arbitrary max length */ if (no_sphere) sin_sq_u = 1.0f, klen = cart_klen; if (klen >= U_DIM(mrisp_src)) klen = U_DIM(mrisp_src) - 1; @@ -1747,10 +1771,12 @@ MRI_SP *MRISPblur(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int fno) { { voff = V_DIM(mrisp_src) / 2; u1 = -u1; - } else if (u1 >= U_DIM(mrisp_src)) { + } + else if (u1 >= U_DIM(mrisp_src)) { u1 = U_DIM(mrisp_src) - (u1 - U_DIM(mrisp_src) + 1); voff = V_DIM(mrisp_src) / 2; - } else + } + else voff = 0; #if 0 @@ -1793,7 +1819,8 @@ MRI_SP *MRISPblur(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int fno) { Description ------------------------------------------------------*/ -MRI_SP *MRISPalloc(float scale, int nfuncs) { +MRI_SP *MRISPalloc(float scale, int nfuncs) +{ MRI_SP *mrisp; int u_dim, v_dim; @@ -1816,7 +1843,8 @@ MRI_SP *MRISPalloc(float scale, int nfuncs) { Description ------------------------------------------------------*/ -int MRISPfree(MRI_SP **pmrisp) { +int MRISPfree(MRI_SP **pmrisp) +{ MRI_SP *mrisp; mrisp = *pmrisp; @@ -1832,7 +1860,8 @@ int MRISPfree(MRI_SP **pmrisp) { Description ------------------------------------------------------*/ -MRI_SP *MRISPalign(MRI_SP *mrisp_orig, MRI_SP *mrisp_src, MRI_SP *mrisp_tmp, MRI_SP *mrisp_dst) { +MRI_SP *MRISPalign(MRI_SP *mrisp_orig, MRI_SP *mrisp_src, MRI_SP *mrisp_tmp, MRI_SP *mrisp_dst) +{ #if 0 IMAGE *Icorr = NULL ; int u_peak, v_peak ; @@ -1870,7 +1899,8 @@ MRI_SP *MRISPalign(MRI_SP *mrisp_orig, MRI_SP *mrisp_src, MRI_SP *mrisp_tmp, MRI Description ------------------------------------------------------*/ -MRI_SP *MRISPtranslate(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, int du, int dv) { +MRI_SP *MRISPtranslate(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, int du, int dv) +{ int u, v, udst, vdst, voff; if (!mrisp_dst) mrisp_dst = MRISPclone(mrisp_src); @@ -1882,10 +1912,12 @@ MRI_SP *MRISPtranslate(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, int du, int dv) { { voff = V_DIM(mrisp_src) / 2; udst = -udst; - } else if (udst >= U_DIM(mrisp_src)) { + } + else if (udst >= U_DIM(mrisp_src)) { voff = V_DIM(mrisp_src) / 2; udst = U_DIM(mrisp_src) - (udst - U_DIM(mrisp_src) + 1); - } else + } + else voff = 0; for (v = 0; v <= V_MAX_INDEX(mrisp_src); v++) { vdst = v + dv + voff; @@ -1910,7 +1942,8 @@ MRI_SP *MRISPtranslate(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, int du, int dv) { The 1st surface in this case represents a single surface, while the second is an average of some (unknown) number. ------------------------------------------------------*/ -MRI_SP *MRISPcombine(MRI_SP *mrisp, MRI_SP *mrisp_template, int fno) { +MRI_SP *MRISPcombine(MRI_SP *mrisp, MRI_SP *mrisp_template, int fno) +{ int u, v, nframes; float dof, mean, vart, var, val; IMAGE *Ip, *Ipt; @@ -1956,7 +1989,8 @@ MRI_SP *MRISPcombine(MRI_SP *mrisp, MRI_SP *mrisp_template, int fno) { Description ------------------------------------------------------*/ -int MRISPwrite(MRI_SP *mrisp, char *fname) { +int MRISPwrite(MRI_SP *mrisp, char *fname) +{ ImageWrite(mrisp->Ip, fname); return (NO_ERROR); } @@ -1967,7 +2001,8 @@ int MRISPwrite(MRI_SP *mrisp, char *fname) { Description ------------------------------------------------------*/ -MRI_SP *MRISPread(char *fname) { +MRI_SP *MRISPread(char *fname) +{ MRI_SP *mrisp; mrisp = (MRI_SP *)calloc(1, sizeof(MRI_SP)); @@ -1984,7 +2019,8 @@ MRI_SP *MRISPread(char *fname) { Description ------------------------------------------------------*/ -double MRISParea(MRI_SP *mrisp) { +double MRISParea(MRI_SP *mrisp) +{ double total_area = 0.0, phi0, theta0, phi1, theta1, radius, l1, l2, x0, y0, z0, x1, y1, z1, x2, y2, z2; float val, max_len = 0.0; int u, v; @@ -2025,7 +2061,8 @@ double MRISParea(MRI_SP *mrisp) { Description ------------------------------------------------------*/ -MRI_SP *MRISPorLabel(MRI_SP *mrisp, MRI_SURFACE *mris, LABEL *area) { +MRI_SP *MRISPorLabel(MRI_SP *mrisp, MRI_SURFACE *mris, LABEL *area) +{ int n, vno, u, v; float r, x, y, z, phi, theta, d, rsq; @@ -2055,7 +2092,8 @@ MRI_SP *MRISPorLabel(MRI_SP *mrisp, MRI_SURFACE *mris, LABEL *area) { Description ------------------------------------------------------*/ -MRI_SP *MRISPandLabel(MRI_SP *mrisp, MRI_SURFACE *mris, LABEL *area) { +MRI_SP *MRISPandLabel(MRI_SP *mrisp, MRI_SURFACE *mris, LABEL *area) +{ int n, vno, u, v; float r, x, y, z, phi, theta, d, rsq; @@ -2090,7 +2128,8 @@ MRI_SP *MRISPandLabel(MRI_SP *mrisp, MRI_SURFACE *mris, LABEL *area) { return (mrisp); } -int MRISPcoordinate(MRI_SP *mrisp, float x, float y, float z, int *pu, int *pv) { +int MRISPcoordinate(MRI_SP *mrisp, float x, float y, float z, int *pu, int *pv) +{ double phi, theta, uf, vf; int u, v; @@ -2109,7 +2148,8 @@ int MRISPcoordinate(MRI_SP *mrisp, float x, float y, float z, int *pu, int *pv) *pv = v; return (NO_ERROR); } -static int spherical_coordinate(double x, double y, double z, double *pphi, double *ptheta) { +static int spherical_coordinate(double x, double y, double z, double *pphi, double *ptheta) +{ double r, d; r = sqrt(x * x + y * y + z * z); @@ -2135,7 +2175,8 @@ static int spherical_coordinate(double x, double y, double z, double *pphi, doub The 1st surface in this case represents a single surface, while the second is an average of some (unknown) number. ------------------------------------------------------*/ -MRI_SP *MRISPaccumulate(MRI_SP *mrisp, MRI_SP *mrisp_template, int fno) { +MRI_SP *MRISPaccumulate(MRI_SP *mrisp, MRI_SP *mrisp_template, int fno) +{ int u, v, nframes; IMAGE *Ip, *Ipt; @@ -2171,7 +2212,8 @@ int MRISPfunctionVectorVals(MRI_SURFACE_PARAMETERIZATION *mrisp, float z, int *frames, int nframes, - double *vals) { + double *vals) +{ double r, r2, r4, r6, val, d, x2, y2, z2, g, h, f, dx, dy, dz; float phi, theta, uf, vf, du, dv; int n, fno, u0, v0, u1, v1, u0_voff, u1_voff, u1_v0, u1_v1, u0_v0, u0_v1; @@ -2219,19 +2261,23 @@ int MRISPfunctionVectorVals(MRI_SURFACE_PARAMETERIZATION *mrisp, { u0_voff = V_DIM(mrisp) / 2; u0 = -u0; - } else if (u0 >= U_DIM(mrisp)) { + } + else if (u0 >= U_DIM(mrisp)) { u0_voff = V_DIM(mrisp) / 2; u0 = U_DIM(mrisp) - (u0 - U_DIM(mrisp) + 1); - } else + } + else u0_voff = 0; if (u1 < 0) /* enforce spherical topology */ { u1_voff = V_DIM(mrisp) / 2; u1 = -u1; - } else if (u1 >= U_DIM(mrisp)) { + } + else if (u1 >= U_DIM(mrisp)) { u1_voff = V_DIM(mrisp) / 2; u1 = U_DIM(mrisp) - (u1 - U_DIM(mrisp) + 1); - } else + } + else u1_voff = 0; if (v0 < 0) v0 += V_DIM(mrisp); if (v0 >= V_DIM(mrisp)) v0 -= V_DIM(mrisp); @@ -2260,7 +2306,8 @@ int MRISPfunctionVectorVals(MRI_SURFACE_PARAMETERIZATION *mrisp, return (NO_ERROR); } -MRI_SURFACE *MRISfromParameterizations(MRI_SP *mrisp, MRI_SURFACE *mris, int *frames, int *indices, int nframes) { +MRI_SURFACE *MRISfromParameterizations(MRI_SP *mrisp, MRI_SURFACE *mris, int *frames, int *indices, int nframes) +{ float a, b, c, phi, theta, x, y, z, uf, vf, du, dv, curv, d; int n, fno, vno, u0, v0, u1, v1; VALS_VP *vp; @@ -2327,7 +2374,8 @@ MRI_SURFACE *MRISfromParameterizations(MRI_SP *mrisp, MRI_SURFACE *mris, int *fr return (mris); } -MRI_SP *MRIStoParameterizations(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, int *frames, int *indices, int nframes) { +MRI_SP *MRIStoParameterizations(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, int *frames, int *indices, int nframes) +{ float a, b, c, phi, theta, x, y, z, uf, vf, d, total_d, **distances, *total; int m, vno, u, v, unfilled, **filled, npasses, nfilled; VERTEX *vertex; @@ -2339,7 +2387,8 @@ MRI_SP *MRIStoParameterizations(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, i if (!mrisp) { ErrorExit(0, "MRIStoParameterizations: NULL mrisp\n"); - } else + } + else for (m = 0; m < nframes; m++) ImageClearArea(mrisp->Ip, -1, -1, -1, -1, 0, frames[m]); a = b = c = MRISaverageRadius(mris); @@ -2476,9 +2525,11 @@ MRI_SP *MRIStoParameterizations(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, i } filled[u][v] = FILLING_ELT; nfilled++; - } else + } + else unfilled++; - } else { + } + else { for (m = 0; m < nframes; m++) *IMAGEFseq_pix(Itmp, u, v, frames[m]) = *IMAGEFseq_pix(Ip, u, v, frames[m]); } } @@ -2511,7 +2562,8 @@ MRI_SP *MRIStoParameterizations(MRI_SURFACE *mris, MRI_SP *mrisp, float scale, i return (mrisp); } -MRI_SP *MRISPblurFrames(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int *frames, int nframes) { +MRI_SP *MRISPblurFrames(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int *frames, int nframes) +{ int n, u, v, cart_klen, klen, khalf, uk, vk, u1, v1, no_sphere, voff; double k, *total, ktotal, sigma_sq_inv, udiff, vdiff, sin_sq_u, phi; IMAGE *Ip_src, *Ip_dst; @@ -2549,7 +2601,8 @@ MRI_SP *MRISPblurFrames(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int * k = cart_klen * cart_klen; klen = sqrt(k + k / sin_sq_u); if (klen > MAX_LEN * cart_klen) klen = MAX_LEN * cart_klen; - } else + } + else klen = MAX_LEN * cart_klen; /* arbitrary max length */ if (no_sphere) sin_sq_u = 1.0f, klen = cart_klen; if (klen >= U_DIM(mrisp_src)) klen = U_DIM(mrisp_src) - 1; @@ -2569,10 +2622,12 @@ MRI_SP *MRISPblurFrames(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int * { voff = V_DIM(mrisp_src) / 2; u1 = -u1; - } else if (u1 >= U_DIM(mrisp_src)) { + } + else if (u1 >= U_DIM(mrisp_src)) { u1 = U_DIM(mrisp_src) - (u1 - U_DIM(mrisp_src) + 1); voff = V_DIM(mrisp_src) / 2; - } else + } + else voff = 0; for (vk = -khalf; vk <= khalf; vk++) { @@ -2601,7 +2656,8 @@ MRI_SP *MRISPblurFrames(MRI_SP *mrisp_src, MRI_SP *mrisp_dst, float sigma, int * return (mrisp_dst); } -int MRISPsetFrameVal(MRI_SP *mrisp, int frame, float val) { +int MRISPsetFrameVal(MRI_SP *mrisp, int frame, float val) +{ int u, v; for (u = 0; u <= U_MAX_INDEX(mrisp); u++) { @@ -2611,7 +2667,8 @@ int MRISPsetFrameVal(MRI_SP *mrisp, int frame, float val) { } return (NO_ERROR); } -float MRISPsample(MRI_SP *mrisp, float x, float y, float z, int fno) { +float MRISPsample(MRI_SP *mrisp, float x, float y, float z, int fno) +{ float retval, theta, phi, radius, d, du, dv, uf, vf; int u0, u1, v0, v1; diff --git a/utils/mrisurf.c b/utils/mrisurf.c index d2eda12eb51..eaa5b4d8b4b 100644 --- a/utils/mrisurf.c +++ b/utils/mrisurf.c @@ -573,7 +573,8 @@ static double MRIScomputeSSE_CUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *mrisc, IN #include #include #include -static int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) { +static int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) +{ /* Perform the carry for the later subtraction by updating y. */ if (x->tv_usec < y->tv_usec) { int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; @@ -657,7 +658,8 @@ const char *MRISurfSrcVersion(void) { return ("$Id: mrisurf.c,v 1.793 2017/02/16 /*----------------------------------------------------- ------------------------------------------------------*/ -MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { +MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) +{ MRI_SURFACE *mris = NULL; int nquads, nvertices, magic, version, ix, iy, iz, vno, fno, n, m; int imnr, imnr0, imnr1, type, vertices[VERTICES_PER_FACE + 1], num; @@ -681,7 +683,8 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { return (NULL); } version = -3; - } else if (type == MRIS_ICO_FILE) /* .TRI, .ICO */ + } + else if (type == MRIS_ICO_FILE) /* .TRI, .ICO */ { mris = ICOreadOverAlloc(fname, pct_over); if (!mris) { @@ -689,38 +692,44 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { } return (mris); version = -2; - } else if (type == MRIS_GEO_TRIANGLE_FILE) /* .GEO */ + } + else if (type == MRIS_GEO_TRIANGLE_FILE) /* .GEO */ { mris = mrisReadGeoFile(fname); if (!mris) { return (NULL); } version = -4; - } else if (type == MRIS_STL_FILE) /* .STL */ + } + else if (type == MRIS_STL_FILE) /* .STL */ { mris = mrisReadSTLfile(fname); if (!mris) { return (NULL); } version = -3; - } else if (type == MRIS_VTK_FILE) /* .vtk */ + } + else if (type == MRIS_VTK_FILE) /* .vtk */ { mris = MRISreadVTK(mris, fname); if (!mris) { return (NULL); } version = -3; - } else if (type == MRIS_GIFTI_FILE) /* .gii */ + } + else if (type == MRIS_GIFTI_FILE) /* .gii */ { mris = mrisReadGIFTIfile(fname, NULL); if (!mris) { return (NULL); } - version = -3; /* Not really sure what is appropriate here */ - } else if (type == MRI_MGH_FILE) /* .mgh */ + version = -3; /* Not really sure what is appropriate here */ + } + else if (type == MRI_MGH_FILE) /* .mgh */ { ErrorExit(ERROR_BADFILE, "ERROR: MRISread: cannot read surface data from file %s!\n", fname); - } else // default type MRIS_BINARY_QUADRANGLE_FILE ... use magic number + } + else // default type MRIS_BINARY_QUADRANGLE_FILE ... use magic number { fp = fopen(fname, "rb"); if (!fp) ErrorReturn(NULL, (ERROR_NOFILE, "MRISread(%s): could not open file", fname)); @@ -738,16 +747,19 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { fprintf(stdout, "new surface file format\n"); } - } else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { + } + else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { version = -2; - } else if (magic == TRIANGLE_FILE_MAGIC_NUMBER) { + } + else if (magic == TRIANGLE_FILE_MAGIC_NUMBER) { fclose(fp); mris = mrisReadTriangleFile(fname, pct_over); if (!mris) { ErrorReturn(NULL, (Gerror, "mrisReadTriangleFile failed.\n")); } version = -3; - } else /* no magic number assigned */ + } + else /* no magic number assigned */ { rewind(fp); version = 0; @@ -795,7 +807,8 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { vertex->x = ix / 100.0; vertex->y = iy / 100.0; vertex->z = iz / 100.0; - } else /* version == -2 */ /* NEW_QUAD_FILE_MAGIC_NUMBER */ + } + else /* version == -2 */ /* NEW_QUAD_FILE_MAGIC_NUMBER */ { vertex->x = freadFloat(fp); vertex->y = freadFloat(fp); @@ -823,7 +836,8 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { for (n = 0; n < vertex->num; n++) { fread3(&vertex->f[n], fp); } - } else { + } + else { vertex->num = 0; /* will figure it out */ } } @@ -860,7 +874,8 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { mris->faces[fno + 1].v[0] = vertices[2]; mris->faces[fno + 1].v[1] = vertices[3]; mris->faces[fno + 1].v[2] = vertices[1]; - } else { + } + else { mris->faces[fno].v[0] = vertices[0]; mris->faces[fno].v[1] = vertices[1]; mris->faces[fno].v[2] = vertices[2]; @@ -925,16 +940,20 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { surf_name = strrchr(fname, '/'); if (surf_name == NULL) { surf_name = fname; - } else { + } + else { surf_name++; /* past the last slash */ } if (toupper(*surf_name) == 'R') { mris->hemisphere = RIGHT_HEMISPHERE; - } else if (toupper(*surf_name) == 'L') { + } + else if (toupper(*surf_name) == 'L') { mris->hemisphere = LEFT_HEMISPHERE; - } else if (toupper(*surf_name) == 'B') { + } + else if (toupper(*surf_name) == 'B') { mris->hemisphere = BOTH_HEMISPHERES; - } else { + } + else { mris->hemisphere = NO_HEMISPHERE; } } @@ -1038,7 +1057,8 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { MRIScomputeSecondFundamentalForm(mris) ; MRISuseMeanCurvature(mris) ; #endif - } else { + } + else { #if 0 if (MRISreadBinaryCurvature(mris, fname) != NO_ERROR) { @@ -1084,7 +1104,8 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { MRIScopyMRI(mris, mri, 0, "group_avg_area"); MRIfree(&mri); mris->group_avg_vtxarea_loaded = 1; - } else { + } + else { mris->group_avg_vtxarea_loaded = 0; } if (Gdiag_no >= 0 && DIAG_VERBOSE_ON) { @@ -1100,7 +1121,8 @@ MRI_SURFACE *MRISreadOverAlloc(const char *fname, double pct_over) { Returns value: Description ------------------------------------------------------*/ -MRI_SURFACE *MRISfastRead(const char *fname) { +MRI_SURFACE *MRISfastRead(const char *fname) +{ /********* why you keep the rest ? ******************/ #if 1 return (MRISread(fname)); @@ -1122,20 +1144,23 @@ MRI_SURFACE *MRISfastRead(const char *fname) { return (NULL); } version = -3; - } else if (type == MRIS_ICO_FILE) { + } + else if (type == MRIS_ICO_FILE) { mris = ICOread(fname); if (!mris) { return (NULL); } return (mris); version = -2; - } else if (type == MRIS_GEO_TRIANGLE_FILE) { + } + else if (type == MRIS_GEO_TRIANGLE_FILE) { mris = mrisReadGeoFile(fname); if (!mris) { return (NULL); } version = -4; - } else /* custom binary file - find out which type using magic # */ + } + else /* custom binary file - find out which type using magic # */ { fp = fopen(fname, "rb"); if (!fp) ErrorReturn(NULL, (ERROR_NOFILE, "MRISread(%s): could not open file", fname)); @@ -1148,17 +1173,20 @@ MRI_SURFACE *MRISfastRead(const char *fname) { ErrorReturn(NULL, (Gerror, "mrisReadTriangleFile failed.\n")); } version = -3; - } else if (magic == QUAD_FILE_MAGIC_NUMBER) { + } + else if (magic == QUAD_FILE_MAGIC_NUMBER) { version = -1; if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { fprintf(stdout, "new surface file format\n"); } - } else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { + } + else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { version = -2; if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { fprintf(stdout, "new surface file format\n"); } - } else { + } + else { rewind(fp); version = 0; if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { @@ -1187,7 +1215,8 @@ MRI_SURFACE *MRISfastRead(const char *fname) { vertex->x = ix / 100.0; vertex->y = iy / 100.0; vertex->z = iz / 100.0; - } else /* version == -2 */ + } + else /* version == -2 */ { vertex->x = freadFloat(fp); vertex->y = freadFloat(fp); @@ -1214,7 +1243,8 @@ MRI_SURFACE *MRISfastRead(const char *fname) { for (n = 0; n < vertex->num; n++) { fread3(&vertex->f[n], fp); } - } else { + } + else { vertex->num = 0; } } @@ -1252,12 +1282,14 @@ MRI_SURFACE *MRISfastRead(const char *fname) { surf_name = strrchr(fname, '/'); if (surf_name == NULL) { surf_name = fname; - } else { + } + else { surf_name++; /* past the last slash */ } if (toupper(*surf_name) == 'R') { mris->hemisphere = RIGHT_HEMISPHERE; - } else { + } + else { mris->hemisphere = LEFT_HEMISPHERE; } } @@ -1357,7 +1389,8 @@ MRI_SURFACE *MRISfastRead(const char *fname) { MRISsetNeighborhoodSize(mris, 2); MRIScomputeSecondFundamentalForm(mris); MRISuseMeanCurvature(mris); - } else { + } + else { if (MRISreadBinaryCurvature(mris, fname) != NO_ERROR) { fprintf(stdout, "ignoring curvature file...\n"); /*return(NULL) ;*/ } @@ -1387,7 +1420,8 @@ MRI_SURFACE *MRISfastRead(const char *fname) { Description ------------------------------------------------------*/ -MRI_SURFACE *MRISread(const char *fname) { +MRI_SURFACE *MRISread(const char *fname) +{ MRI_SURFACE *mris; mris = MRISreadOverAlloc(fname, 0.0); @@ -1397,7 +1431,8 @@ MRI_SURFACE *MRISread(const char *fname) { return (mris); } -int MRISwriteVertexLocations(MRI_SURFACE *mris, char *fname, int which_vertices) { +int MRISwriteVertexLocations(MRI_SURFACE *mris, char *fname, int which_vertices) +{ int retval, i; float *coords[3]; @@ -1424,7 +1459,8 @@ int MRISwriteVertexLocations(MRI_SURFACE *mris, char *fname, int which_vertices) Description ------------------------------------------------------*/ #define USE_NEW_QUAD_FILE 1 // new style stores float instead of int -int MRISwrite(MRI_SURFACE *mris, const char *name) { +int MRISwrite(MRI_SURFACE *mris, const char *name) +{ int k, type; float x, y, z; FILE *fp; @@ -1435,15 +1471,20 @@ int MRISwrite(MRI_SURFACE *mris, const char *name) { type = MRISfileNameType(fname); if (type == MRIS_ASCII_TRIANGLE_FILE) { return (MRISwriteAscii(mris, fname)); - } else if (type == MRIS_VTK_FILE) { + } + else if (type == MRIS_VTK_FILE) { return (MRISwriteVTK(mris, fname)); - } else if (type == MRIS_GEO_TRIANGLE_FILE) { + } + else if (type == MRIS_GEO_TRIANGLE_FILE) { return (MRISwriteGeo(mris, fname)); - } else if (type == MRIS_ICO_FILE) { + } + else if (type == MRIS_ICO_FILE) { return MRISwriteICO(mris, fname); - } else if (type == MRIS_STL_FILE) { + } + else if (type == MRIS_STL_FILE) { return MRISwriteSTL(mris, fname); - } else if (type == MRIS_GIFTI_FILE) { + } + else if (type == MRIS_GIFTI_FILE) { return MRISwriteGIFTI(mris, NIFTI_INTENT_POINTSET, fname, NULL); } @@ -1494,7 +1535,8 @@ int MRISwrite(MRI_SURFACE *mris, const char *name) { fwrite3(mris->faces[k].v[1], fp); fwrite3(mris->faces[k + 1].v[0], fp); fwrite3(mris->faces[k].v[2], fp); - } else { + } + else { fwrite3(mris->faces[k].v[0], fp); fwrite3(mris->faces[k].v[1], fp); fwrite3(mris->faces[k].v[2], fp); @@ -1533,7 +1575,8 @@ int MRISwrite(MRI_SURFACE *mris, const char *name) { Description ------------------------------------------------------*/ -MRI_SURFACE *MRISoverAlloc(int max_vertices, int max_faces, int nvertices, int nfaces) { +MRI_SURFACE *MRISoverAlloc(int max_vertices, int max_faces, int nvertices, int nfaces) +{ MRI_SURFACE *mris; if (max_vertices <= 0) { @@ -1560,7 +1603,8 @@ MRI_SURFACE *MRISoverAlloc(int max_vertices, int max_faces, int nvertices, int n Description ------------------------------------------------------*/ -MRI_SURFACE *MRISalloc(int nvertices, int nfaces) { +MRI_SURFACE *MRISalloc(int nvertices, int nfaces) +{ MRI_SURFACE *mris; if (nvertices < 0) ErrorExit(ERROR_BADPARM, "ERROR: MRISalloc: nvertices=%d < 0\n", nvertices); @@ -1604,7 +1648,8 @@ MRI_SURFACE *MRISalloc(int nvertices, int nfaces) { Description ------------------------------------------------------*/ -int MRISfree(MRI_SURFACE **pmris) { +int MRISfree(MRI_SURFACE **pmris) +{ MRI_SURFACE *mris; int vno; @@ -1689,7 +1734,8 @@ int MRISfree(MRI_SURFACE **pmris) { Description ------------------------------------------------------*/ -int MRISfreeDists(MRI_SURFACE *mris) { +int MRISfreeDists(MRI_SURFACE *mris) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -1715,7 +1761,8 @@ int MRISfreeDists(MRI_SURFACE *mris) { if nsize <=0 then neighborhood size gets reset back to whatever it's max was. ------------------------------------------------------*/ -int MRISresetNeighborhoodSize(MRI_SURFACE *mris, int nsize) { +int MRISresetNeighborhoodSize(MRI_SURFACE *mris, int nsize) +{ int vno; VERTEX *v; @@ -1762,7 +1809,8 @@ int MRISresetNeighborhoodSize(MRI_SURFACE *mris, int nsize) { #define MAX_2_NEIGHBORS 20 #define MAX_1_NEIGHBORS 8 #define MAX_NEIGHBORS (10000) -int mrisFindNeighbors(MRI_SURFACE *mris) { +int mrisFindNeighbors(MRI_SURFACE *mris) +{ int n0, n1, i, k, m, n, vno, vtotal, ntotal, vtmp[MAX_NEIGHBORS]; FACE *f; VERTEX *v; @@ -1873,7 +1921,8 @@ int mrisFindNeighbors(MRI_SURFACE *mris) { nlinks distances in terms of number of edges. Each vertex->marked field will be set to the number of edges between it and the central vertex. */ -int MRISfindNeighborsAtVertex(MRI_SURFACE *mris, int vno, int nlinks, int *vlist) { +int MRISfindNeighborsAtVertex(MRI_SURFACE *mris, int vno, int nlinks, int *vlist) +{ int m, n, vtotal = 0, link_dist, ring_total; VERTEX *v, *vn; @@ -1901,7 +1950,8 @@ int MRISfindNeighborsAtVertex(MRI_SURFACE *mris, int vno, int nlinks, int *vlist ErrorExit(ERROR_BADPARM, "MRISfindNeighborsAtVertex: nlinks=%d invalid", nlinks); break; } - } else // bigger than biggest neighborhood held at each vertex + } + else // bigger than biggest neighborhood held at each vertex { v->marked = mris->nsize; link_dist = mris->nsize; @@ -1935,7 +1985,8 @@ int MRISfindNeighborsAtVertex(MRI_SURFACE *mris, int vno, int nlinks, int *vlist Description ------------------------------------------------------*/ -int MRISsampleAtEachDistance(MRI_SURFACE *mris, int nbhd_size, int nbrs_per_distance) { +int MRISsampleAtEachDistance(MRI_SURFACE *mris, int nbhd_size, int nbrs_per_distance) +{ int n, nbrs_array[MAX_NBHD_SIZE]; if (!nbhd_size) { @@ -1964,7 +2015,8 @@ int MRISsampleAtEachDistance(MRI_SURFACE *mris, int nbhd_size, int nbrs_per_dist #define TRIANGLE_DISTANCE_CORRECTION 1.09f /*1.1f*/ /*1.066f*/ /*1.12578*/ /* 1.13105f*/ /*1.1501f (1.1364f)*/ #define QUADRANGLE_DISTANCE_CORRECTION ((1 + sqrt(2)) / 2) /* 1.2071 */ -int MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) { +int MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) +{ int i, n, vno, vnum, old_vnum, total_nbrs, max_possible, max_v, vtotal; VERTEX *v, *vn, *vn2; int *vnbrs, *vall, *vnb, found, n2, vnbrs_num, vall_num, nbhd_size, done, checks = 0; @@ -1983,12 +2035,14 @@ int MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) { if ((cp = getenv("VDIAG1")) != NULL) { diag_vno1 = atoi(cp); - } else { + } + else { diag_vno1 = -1; } if ((cp = getenv("VDIAG2")) != NULL) { diag_vno2 = atoi(cp); - } else { + } + else { diag_vno2 = -1; } if (diag_vno1 >= 0) { @@ -2003,7 +2057,8 @@ int MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) { /* adjust for Manhattan distance */ if (IS_QUADRANGULAR(mris)) { dist_scale = (1.0 + sqrt(2.0)) / 2.0f; - } else { + } + else { dist_scale = TRIANGLE_DISTANCE_CORRECTION; } @@ -2049,9 +2104,11 @@ int MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) { vtotal = v->vtotal; if (v->nsize == 3) { v->vtotal = v->v3num; - } else if (v->nsize == 2) { + } + else if (v->nsize == 2) { v->vtotal = v->v2num; - } else { + } + else { v->vtotal = v->vnum; } @@ -2287,7 +2344,8 @@ int MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) { DiagBreak(); } } - } else /* randomly sample from them */ + } + else /* randomly sample from them */ { int vstart = v->vtotal; for (n = 0; n < nbrs[nbhd_size]; n++, v->vtotal++) { @@ -2399,9 +2457,11 @@ int MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) { } if (v->nsize == 3) { vtotal = v->v3num; - } else if (v->nsize == 2) { + } + else if (v->nsize == 2) { vtotal = v->v2num; - } else { + } + else { vtotal = v->vnum; } for (n = 0; n < vtotal; n++) { @@ -2890,7 +2950,8 @@ MRISsampleDistances(MRI_SURFACE *mris, int *nbrs, int max_nbhd) Expand the list of neighbors of each vertex, reallocating the v->v array to hold the expanded list. ------------------------------------------------------*/ -int MRISsetNeighborhoodSize(MRI_SURFACE *mris, int nsize) { +int MRISsetNeighborhoodSize(MRI_SURFACE *mris, int nsize) +{ int vno, niter, ntotal, vtotal; /* @@ -3088,7 +3149,8 @@ int MRISsetNeighborhoodSize(MRI_SURFACE *mris, int nsize) { Remove ripped vertices and faces from the v->v and the v->f arrays respectively. ------------------------------------------------------*/ -int MRISremoveRipped(MRI_SURFACE *mris) { +int MRISremoveRipped(MRI_SURFACE *mris) +{ int vno, n, fno, nripped, remove, vno2; VERTEX *v; FACE *face; @@ -3331,7 +3393,8 @@ int MRISremoveRipped(MRI_SURFACE *mris) { ------------------------------------------------------*/ #define RAN 0.001 /* one thousandth of a millimeter */ -int MRIScomputeNormals(MRI_SURFACE *mris) { +int MRIScomputeNormals(MRI_SURFACE *mris) +{ long seed; int k, i; @@ -3414,7 +3477,8 @@ int MRIScomputeNormals(MRI_SURFACE *mris) { v->ny = snorm[1]; v->nz = snorm[2]; i = 0; - } else { + } + else { if (i++ > 5) continue; if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) @@ -3463,7 +3527,8 @@ int MRIScomputeNormals(MRI_SURFACE *mris) { Calculate distances between each vertex and all of its neighbors. CVD. ----------------------------------------------------------------*/ -static int mrisComputeVertexDistances(MRI_SURFACE *mris) { +static int mrisComputeVertexDistances(MRI_SURFACE *mris) +{ int vno; #ifdef HAVE_OPENMP @@ -3537,7 +3602,8 @@ static int mrisComputeVertexDistances(MRI_SURFACE *mris) { Calculate distances between each vertex and all of its neighbors. CVD. ----------------------------------------------------------------*/ -static int mrisComputeOriginalVertexDistances(MRI_SURFACE *mris) { +static int mrisComputeOriginalVertexDistances(MRI_SURFACE *mris) +{ int vno, n, vtotal, *pv; VERTEX *v, *vn; float d, xd, yd, zd, circumference = 0.0f, angle; @@ -3612,7 +3678,8 @@ static int mrisComputeOriginalVertexDistances(MRI_SURFACE *mris) { it is ignored. Requires that mrisComputeVertexDistances() have been run in order to comute vertex->dist[n]. -------------------------------------------------------------*/ -static double MRISavgInterVertexDist(MRIS *Surf, double *StdDev) { +static double MRISavgInterVertexDist(MRIS *Surf, double *StdDev) +{ double Sum, Sum2; long N; @@ -3666,7 +3733,8 @@ static double MRISavgInterVertexDist(MRIS *Surf, double *StdDev) { the distance from the origin to each vertex. If StdDev is NULL, it is ignored. -------------------------------------------------------------*/ -double MRISavgVetexRadius(MRIS *Surf, double *StdDev) { +double MRISavgVetexRadius(MRIS *Surf, double *StdDev) +{ double Avg, Sum, Sum2, d; VERTEX *vtx; int VtxNo, N; @@ -3694,7 +3762,8 @@ double MRISavgVetexRadius(MRIS *Surf, double *StdDev) { /*----------------------------------------------------- ------------------------------------------------------*/ -static void mrisNormalize(float v[3]) { +static void mrisNormalize(float v[3]) +{ float d; d = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); @@ -3712,7 +3781,8 @@ static void mrisNormalize(float v[3]) { Description ------------------------------------------------------*/ -static float mrisTriangleArea(MRIS *mris, int fac, int n) { +static float mrisTriangleArea(MRIS *mris, int fac, int n) +{ int n0, n1; face_type *f; float v0[3], v1[3], d1, d2, d3; @@ -3739,7 +3809,8 @@ static float mrisTriangleArea(MRIS *mris, int fac, int n) { Description ------------------------------------------------------*/ -static int mrisComputeOrigNormal(MRIS *mris, int vno, float norm[]) { +static int mrisComputeOrigNormal(MRIS *mris, int vno, float norm[]) +{ float snorm[3]; VERTEX *v; int n, num; @@ -3769,7 +3840,8 @@ static int mrisComputeOrigNormal(MRIS *mris, int vno, float norm[]) { Description ------------------------------------------------------*/ -static int mrisComputeWhiteNormal(MRIS *mris, int vno, float norm[]) { +static int mrisComputeWhiteNormal(MRIS *mris, int vno, float norm[]) +{ float snorm[3]; VERTEX *v; int n, num; @@ -3799,7 +3871,8 @@ static int mrisComputeWhiteNormal(MRIS *mris, int vno, float norm[]) { Description ------------------------------------------------------*/ -static int mrisComputePialNormal(MRIS *mris, int vno, float norm[]) { +static int mrisComputePialNormal(MRIS *mris, int vno, float norm[]) +{ float snorm[3]; VERTEX *v; int n, num; @@ -3829,7 +3902,8 @@ static int mrisComputePialNormal(MRIS *mris, int vno, float norm[]) { Description ------------------------------------------------------*/ -static int mrisOrigNormalFace(MRIS *mris, int fac, int n, float norm[]) { +static int mrisOrigNormalFace(MRIS *mris, int fac, int n, float norm[]) +{ int n0, n1, *pv; FACE *f; float v0[3], v1[3]; @@ -3867,7 +3941,8 @@ static int mrisOrigNormalFace(MRIS *mris, int fac, int n, float norm[]) { Description ------------------------------------------------------*/ -static int mrisWhiteNormalFace(MRIS *mris, int fac, int n, float norm[]) { +static int mrisWhiteNormalFace(MRIS *mris, int fac, int n, float norm[]) +{ int n0, n1, *pv; FACE *f; float v0[3], v1[3]; @@ -3905,7 +3980,8 @@ static int mrisWhiteNormalFace(MRIS *mris, int fac, int n, float norm[]) { Description ------------------------------------------------------*/ -static int mrisPialNormalFace(MRIS *mris, int fac, int n, float norm[]) { +static int mrisPialNormalFace(MRIS *mris, int fac, int n, float norm[]) +{ int n0, n1, *pv; FACE *f; float v0[3], v1[3]; @@ -3943,7 +4019,8 @@ static int mrisPialNormalFace(MRIS *mris, int fac, int n, float norm[]) { Description ------------------------------------------------------*/ -static int mrisNormalFace(MRIS *mris, int fac, int n, float norm[]) { +static int mrisNormalFace(MRIS *mris, int fac, int n, float norm[]) +{ int n0, n1, *pv; FACE *f; float v0[3], v1[3]; @@ -3982,7 +4059,8 @@ static int mrisNormalFace(MRIS *mris, int fac, int n, float norm[]) { Description ------------------------------------------------------*/ // here reads mri/transforms/talairach.xfm (MNI style transform) -static int mrisReadTransform(MRIS *mris, const char *mris_fname) { +static int mrisReadTransform(MRIS *mris, const char *mris_fname) +{ char transform_fname[STRLEN], fpref[300]; LT *lt = 0; MRI *orig = 0; @@ -3998,7 +4076,8 @@ static int mrisReadTransform(MRIS *mris, const char *mris_fname) { if (!(mris->lta = LTAreadEx(transform_fname))) { ErrorReturn(ERROR_NO_FILE, (ERROR_NOFILE, "mrisReadTransform: could not read xform file '%s'", transform_fname)); - } else { + } + else { if (mris->lta->type != LINEAR_RAS_TO_RAS) ErrorExit(ERROR_BADPARM, "the transform is not RAS-TO-RAS. not supported."); } @@ -4014,7 +4093,8 @@ static int mrisReadTransform(MRIS *mris, const char *mris_fname) { lt->src.c_r = mris->vg.c_r; lt->src.c_a = mris->vg.c_a; lt->src.c_s = mris->vg.c_s; - } else { + } + else { // first try to get it from mri/orig sprintf(transform_fname, "%s/../mri/orig", fpref); // reuse of the buffer rStat = stat(transform_fname, &info); @@ -4033,7 +4113,8 @@ static int mrisReadTransform(MRIS *mris, const char *mris_fname) { "to get c_(ras) information for src\n"); fprintf(stderr, "INFO: added info to the surface.\n"); } - } else { + } + else { if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { fprintf(stderr, "INFO: cannot find mri/orig volume to " @@ -4053,7 +4134,8 @@ static int mrisReadTransform(MRIS *mris, const char *mris_fname) { lt->src.c_s = 0; } } - } else // lt->src.valid == 1 + } + else // lt->src.valid == 1 { // verify if (mris->vg.valid) { @@ -4130,7 +4212,8 @@ int MRISreadTransform(MRIS *mris, const char *fname) { return mrisReadTransform( Description ------------------------------------------------------*/ -int MRISreadBinaryCurvature(MRI_SURFACE *mris, const char *mris_fname) { +int MRISreadBinaryCurvature(MRI_SURFACE *mris, const char *mris_fname) +{ char fname[STRLEN], fpref[STRLEN], hemi[20]; FileNamePath(mris_fname, fpref); @@ -4146,7 +4229,8 @@ int MRISreadBinaryCurvature(MRI_SURFACE *mris, const char *mris_fname) { Description ------------------------------------------------------*/ -int MRISreadCurvatureFile(MRI_SURFACE *mris, const char *sname) { +int MRISreadCurvatureFile(MRI_SURFACE *mris, const char *sname) +{ int k, i, vnum, fnum; float curv = 0, curvmin, curvmax; FILE *fp; @@ -4160,17 +4244,20 @@ int MRISreadCurvatureFile(MRI_SURFACE *mris, const char *sname) { if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s", sname); - } else { + } + else { cp = strchr(sname, '.'); FileNamePath(mris->fname, path); if (cp && ((strncmp(cp - 2, "lh", 2) == 0) || (strncmp(cp - 2, "rh", 2) == 0))) { sprintf(fname, "%s/%s", path, sname); - } else /* no hemisphere specified */ + } + else /* no hemisphere specified */ { sprintf(fname, "%s/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", sname); } } - } else { + } + else { strcpy(fname, sname); /* path specified explicitly */ } mritype = mri_identify(sname); @@ -4178,7 +4265,8 @@ int MRISreadCurvatureFile(MRI_SURFACE *mris, const char *sname) { mris = mrisReadGIFTIfile(fname, mris); if (mris) { return (NO_ERROR); - } else { + } + else { return (ERROR_BADFILE); } } @@ -4237,11 +4325,13 @@ int MRISreadCurvatureFile(MRI_SURFACE *mris, const char *sname) { type = MRISfileNameType(fname); if (type == MRIS_ASCII_TRIANGLE_FILE) { return (mrisReadAsciiCurvatureFile(mris, fname)); - } else if (type == MRIS_GIFTI_FILE) { + } + else if (type == MRIS_GIFTI_FILE) { mris = mrisReadGIFTIfile(fname, mris); if (mris) { return (NO_ERROR); - } else { + } + else { return (ERROR_BADFILE); } } @@ -4301,7 +4391,8 @@ int MRISreadCurvatureFile(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -float *MRISreadCurvatureVector(MRI_SURFACE *mris, const char *sname) { +float *MRISreadCurvatureVector(MRI_SURFACE *mris, const char *sname) +{ char *cp, path[STRLEN], fname[STRLEN]; float *cvec = NULL; int return_code = ERROR_NONE; @@ -4313,9 +4404,11 @@ float *MRISreadCurvatureVector(MRI_SURFACE *mris, const char *sname) { FileNamePath(mris->fname, path); if (cp) { sprintf(fname, "%s/%s", path, sname); - } else /* no hemisphere specified */ + } + else /* no hemisphere specified */ sprintf(fname, "%s/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", sname); - } else { + } + else { strcpy(fname, sname); /* path specified explcitly */ } @@ -4330,7 +4423,8 @@ float *MRISreadCurvatureVector(MRI_SURFACE *mris, const char *sname) { return cvec; } -int MRISreadCurvatureIntoArray(const char *sname, int in_array_size, float **out_array) { +int MRISreadCurvatureIntoArray(const char *sname, int in_array_size, float **out_array) +{ int k, i, vnum, fnum; float *cvec; FILE *fp; @@ -4385,7 +4479,8 @@ int MRISreadCurvatureIntoArray(const char *sname, int in_array_size, float **out Description ------------------------------------------------------*/ -int MRISreadFloatFile(MRI_SURFACE *mris, const char *sname) { +int MRISreadFloatFile(MRI_SURFACE *mris, const char *sname) +{ int k, vnum, fnum; float f; FILE *fp; @@ -4398,9 +4493,11 @@ int MRISreadFloatFile(MRI_SURFACE *mris, const char *sname) { FileNamePath(mris->fname, path); if (cp) { sprintf(fname, "%s/%s", path, sname); - } else /* no hemisphere specified */ + } + else /* no hemisphere specified */ sprintf(fname, "%s/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", sname); - } else { + } + else { strcpy(fname, sname); /* path specified explcitly */ } @@ -4444,7 +4541,8 @@ int MRISreadFloatFile(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadBinaryAreas(MRI_SURFACE *mris, const char *mris_fname) { +int MRISreadBinaryAreas(MRI_SURFACE *mris, const char *mris_fname) +{ int k, vnum, fnum; float f; FILE *fp; @@ -4490,7 +4588,8 @@ int MRISreadBinaryAreas(MRI_SURFACE *mris, const char *mris_fname) { return (NO_ERROR); } -int MRISwriteMarked(MRI_SURFACE *mris, const char *sname) { +int MRISwriteMarked(MRI_SURFACE *mris, const char *sname) +{ float *curv_save; curv_save = (float *)calloc(mris->nvertices, sizeof(float)); @@ -4504,7 +4603,8 @@ int MRISwriteMarked(MRI_SURFACE *mris, const char *sname) { return (NO_ERROR); } -int MRISreadMarked(MRI_SURFACE *mris, const char *sname) { +int MRISreadMarked(MRI_SURFACE *mris, const char *sname) +{ float *curv_save; curv_save = (float *)calloc(mris->nvertices, sizeof(float)); @@ -4527,7 +4627,8 @@ int MRISreadMarked(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISwriteArea(MRI_SURFACE *mris, const char *sname) { +int MRISwriteArea(MRI_SURFACE *mris, const char *sname) +{ float *curv_save; curv_save = (float *)calloc(mris->nvertices, sizeof(float)); @@ -4664,7 +4765,8 @@ normalize_binary_curvature(MRI_SURFACE *mris) point on the cortical surface to the closest cylindrical coordinate. ------------------------------------------------------*/ -int MRISprojectOntoCylinder(MRI_SURFACE *mris, float radius) { +int MRISprojectOntoCylinder(MRI_SURFACE *mris, float radius) +{ VERTEX *v; int k; float x, y, z, x2, z2, dx, dz; @@ -4708,7 +4810,8 @@ int MRISprojectOntoCylinder(MRI_SURFACE *mris, float radius) { point on the cortical surface to the closest spherical coordinate. ------------------------------------------------------*/ -MRI_SURFACE *MRISprojectOntoSphere(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, double r) { +MRI_SURFACE *MRISprojectOntoSphere(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, double r) +{ VERTEX *v; int vno; double x, y, z, d, dx, dy, dz, dist, total_dist, x2, y2, z2; @@ -4746,7 +4849,8 @@ MRI_SURFACE *MRISprojectOntoSphere(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, dist = sqrt(x2 + y2 + z2); if (FZERO(dist)) { d = 0; - } else { + } + else { d = 1 - r / dist; } dx = d * x; @@ -4795,7 +4899,8 @@ MRI_SURFACE *MRISprojectOntoSphere(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, ------------------------------------------------------*/ extern double sqrt(double); -MRI_SURFACE *MRISprojectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float a, float b, float c) { +MRI_SURFACE *MRISprojectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float a, float b, float c) +{ VERTEX *v; int k; float x, y, z, x2, y2, z2, dx, dy, dz, a2, b2, c2, a4, b4, c4, a6, b6, c6; @@ -4908,7 +5013,8 @@ MRI_SURFACE *MRISprojectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE *mris_d MRISupdateEllipsoidSurface(mris_dst); if (FZERO(a - b) && FZERO(b - c)) { mris_dst->status = MRIS_SPHERE; - } else { + } + else { mris_dst->status = MRIS_ELLIPSOID; } return (mris_dst); @@ -4918,7 +5024,8 @@ MRI_SURFACE *MRISprojectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE *mris_d this one projects along the line from the origin to the ellipsoidal surface - not orthographic unless the ellipsoid is a sphere. */ -MRI_SURFACE *MRISradialProjectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float a, float b, float c) { +MRI_SURFACE *MRISradialProjectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float a, float b, float c) +{ int vno; VERTEX *vsrc, *vdst; float x0, y0, z0, x1, y1, z1, denom, asq_bsq, asq_csq, bsq_csq, x1sq, y1sq, z1sq, abc; @@ -4987,7 +5094,8 @@ MRI_SURFACE *MRISradialProjectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE * MRISupdateEllipsoidSurface(mris_dst); if (FZERO(a - b) && FZERO(b - c)) { mris_dst->status = MRIS_SPHERE; - } else { + } + else { mris_dst->status = MRIS_ELLIPSOID; } return (mris_dst); @@ -5000,7 +5108,8 @@ MRI_SURFACE *MRISradialProjectOntoEllipsoid(MRI_SURFACE *mris_src, MRI_SURFACE * Description ------------------------------------------------------*/ -MRI_SURFACE *MRISclone(MRI_SURFACE *mris_src) { +MRI_SURFACE *MRISclone(MRI_SURFACE *mris_src) +{ MRI_SURFACE *mris_dst; int vno, fno, n; VERTEX *vsrc, *vdst; @@ -5127,7 +5236,8 @@ MRI_SURFACE *MRISclone(MRI_SURFACE *mris_src) { Description ------------------------------------------------------*/ -MRI_SURFACE *MRIScenter(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst) { +MRI_SURFACE *MRIScenter(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst) +{ int vno; VERTEX *vdst; float x, y, z, x0, y0, z0, xlo, xhi, zlo, zhi, ylo, yhi; @@ -5242,7 +5352,8 @@ MRI_SURFACE *MRIScenter(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst) { We need to know the Csrc and Ctal values ------------------------------------------------------*/ -MRI_SURFACE *MRIStalairachTransform(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst) { +MRI_SURFACE *MRIStalairachTransform(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst) +{ int vno; VERTEX *v; double x, y, z, xt, yt, zt; @@ -5590,11 +5701,13 @@ static float *sigmas = sigmas_default; // can be changed by caller #define NSIGMAS (sizeof(sigmas_default) / sizeof(sigmas_default[0])) static double nsigmas = NSIGMAS; -int MRISsetRegistrationSigmas(float *sigmas_local, int nsigmas_local) { +int MRISsetRegistrationSigmas(float *sigmas_local, int nsigmas_local) +{ if (sigmas_local == NULL) { nsigmas = NSIGMAS; sigmas = sigmas_default; - } else { + } + else { nsigmas = nsigmas_local; sigmas = sigmas_local; } @@ -5605,7 +5718,8 @@ static char *surface_names[] = {"inflated", "smoothwm", "smoothwm"}; static char *curvature_names[] = {"inflated.H", "sulc", NULL}; -int MRISsetCurvatureName(int nth, char *name) { +int MRISsetCurvatureName(int nth, char *name) +{ if (nth > 2) { printf("ERROR: MRISsetCurvatureName() nth=%d > 2\n", nth); return (1); @@ -5613,7 +5727,8 @@ int MRISsetCurvatureName(int nth, char *name) { curvature_names[nth] = strcpyalloc(name); return (0); } -int MRISprintCurvatureNames(FILE *fp) { +int MRISprintCurvatureNames(FILE *fp) +{ int k; for (k = 0; k < sizeof(curvature_names) / sizeof(curvature_names[0]); k++) { if (curvature_names[k]) @@ -5624,7 +5739,8 @@ int MRISprintCurvatureNames(FILE *fp) { return (0); } -int MRISsetInflatedFileName(char *inflated_name) { +int MRISsetInflatedFileName(char *inflated_name) +{ char fname[STRLEN]; surface_names[0] = inflated_name; @@ -5634,13 +5750,15 @@ int MRISsetInflatedFileName(char *inflated_name) { return (NO_ERROR); } -int MRISsetSulcFileName(const char *sulc_name) { +int MRISsetSulcFileName(const char *sulc_name) +{ curvature_names[1] = (char *)calloc(strlen(sulc_name) + 1, sizeof(char)); strcpy(curvature_names[1], sulc_name); return (NO_ERROR); } -int MRISsetOriginalFileName(char *orig_name) { +int MRISsetOriginalFileName(char *orig_name) +{ surface_names[1] = surface_names[2] = orig_name; return (NO_ERROR); } @@ -5661,7 +5779,8 @@ int MRISregister(MRI_SURFACE *mris, int max_passes, float min_degrees, float max_degrees, - int nangles) { + int nangles) +{ float sigma /*, target_sigma, dof*/; int i, start_t, sno, ino, msec, min_averages = 0, nsurfaces, using_big_averages = 0; MRI_SP *mrisp; @@ -5707,7 +5826,8 @@ int MRISregister(MRI_SURFACE *mris, sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -5721,15 +5841,18 @@ int MRISregister(MRI_SURFACE *mris, fprintf(stderr, "will not rigidly align the surface\n"); first = 0; sno = 2; - } else if (parms->flags & IP_USE_INFLATED) { + } + else if (parms->flags & IP_USE_INFLATED) { sno = 0; - } else { + } + else { sno = 1; } if (parms->nsurfaces > 0) { nsurfaces = parms->nsurfaces; - } else { + } + else { nsurfaces = SURFACES; } @@ -5750,7 +5873,8 @@ int MRISregister(MRI_SURFACE *mris, if (parms->trinarize_thresh > 0) { MRIStrinarizeCurvature(mris, parms->trinarize_thresh); } - } else /* compute curvature of surface */ + } + else /* compute curvature of surface */ { sprintf(fname, "%s", surface_names[sno]); MRISsaveVertexPositions(mris, TMP_VERTICES); @@ -5773,7 +5897,8 @@ int MRISregister(MRI_SURFACE *mris, if (Gdiag & DIAG_SHOW) { if (curvature_names[sno]) { printf("reading precomputed curvature from %s\n", fname); - } else { + } + else { printf("calculating curvature of %s surface\n", fname); } } @@ -5781,7 +5906,8 @@ int MRISregister(MRI_SURFACE *mris, if (Gdiag & DIAG_WRITE) { if (curvature_names[sno]) { fprintf(parms->fp, "using precomputed curvature from %s\n", fname); - } else { + } + else { fprintf(parms->fp, "calculating curvature of %s surface\n", fname); } } @@ -5800,7 +5926,8 @@ int MRISregister(MRI_SURFACE *mris, } // if (Gdiag & DIAG_SHOW) mrisLogIntegrationParms(stderr, mris, parms); - } else if (!first) /* don't do curvature alignment */ + } + else if (!first) /* don't do curvature alignment */ { break; /* finished */ } @@ -6057,7 +6184,8 @@ int MRISregister(MRI_SURFACE *mris, return (NO_ERROR); } -void MRISsetCurvaturesToValues(MRIS *mris, int fno) { +void MRISsetCurvaturesToValues(MRIS *mris, int fno) +{ int n; VERTEX *v; for (n = 0; n < mris->nvertices; n++) { @@ -6069,7 +6197,8 @@ void MRISsetCurvaturesToValues(MRIS *mris, int fno) { } } -void MRISsetCurvaturesToOrigValues(MRIS *mris, int fno) { +void MRISsetCurvaturesToOrigValues(MRIS *mris, int fno) +{ int n; VERTEX *v; for (n = 0; n < mris->nvertices; n++) { @@ -6081,7 +6210,8 @@ void MRISsetCurvaturesToOrigValues(MRIS *mris, int fno) { } } -void MRISsetOrigValuesToCurvatures(MRIS *mris, int fno) { +void MRISsetOrigValuesToCurvatures(MRIS *mris, int fno) +{ int n; VERTEX *v; for (n = 0; n < mris->nvertices; n++) { @@ -6093,7 +6223,8 @@ void MRISsetOrigValuesToCurvatures(MRIS *mris, int fno) { } } -void MRISsetOrigValuesToValues(MRIS *mris, int fno) { +void MRISsetOrigValuesToValues(MRIS *mris, int fno) +{ int n; VERTEX *v; for (n = 0; n < mris->nvertices; n++) { @@ -6105,7 +6236,8 @@ void MRISsetOrigValuesToValues(MRIS *mris, int fno) { } } -void MRISsetValuesToCurvatures(MRIS *mris, int fno) { +void MRISsetValuesToCurvatures(MRIS *mris, int fno) +{ int n; VERTEX *v; for (n = 0; n < mris->nvertices; n++) { @@ -6117,7 +6249,8 @@ void MRISsetValuesToCurvatures(MRIS *mris, int fno) { } } -void MRISnormalizeField(MRIS *mris, int distance_field, int which_norm) { +void MRISnormalizeField(MRIS *mris, int distance_field, int which_norm) +{ int n; VERTEX *v; float max_value; @@ -6148,7 +6281,8 @@ void MRISnormalizeField(MRIS *mris, int distance_field, int which_norm) { v->curv = v->curv / max_value; } } - } else /* gaussian */ + } + else /* gaussian */ { MRISnormalizeCurvature(mris, which_norm); } @@ -6160,7 +6294,8 @@ int MRISvectorRegister(MRI_SURFACE *mris, int max_passes, float min_degrees, float max_degrees, - int nangles) { + int nangles) +{ float sigma; int i, /*steps,*/ msec; MRI_SP *mrisp; @@ -6263,7 +6398,8 @@ int MRISvectorRegister(MRI_SURFACE *mris, path, mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->fields[n].name); - } else { + } + else { sprintf(fname, "%s/../%s/%s.%s", path, @@ -6278,7 +6414,8 @@ int MRISvectorRegister(MRI_SURFACE *mris, MRISripMedialWall(mris); } MRIScopyValuesToCurvature(mris); - } else if (ReturnFieldName(parms->fields[n].field)) { + } + else if (ReturnFieldName(parms->fields[n].field)) { /* read in precomputed curvature file */ sprintf( fname, "%s.%s", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", ReturnFieldName(parms->fields[n].field)); @@ -6288,7 +6425,8 @@ int MRISvectorRegister(MRI_SURFACE *mris, parms->fields[n].l_corr = parms->fields[n].l_pcorr = 0.0; continue; } - } else { + } + else { /* compute curvature of surface */ sprintf(fname, "%s", surface_names[parms->fields[n].field]); /* if(parms->fields[n].field==0) */ @@ -6550,7 +6688,8 @@ static float dist_coefs[] = {0.1f, 1.0f, 1.0f}; #define MAX_NBHD_SIZE 200 #define NBR_COEF (M_PI * 1.0f) -MRI_SURFACE *MRISunfold(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_passes) { +MRI_SURFACE *MRISunfold(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_passes) +{ int base_averages, i, nbrs[MAX_NBHD_SIZE], niter, passno, msec, use_nl_area; double starting_sse, ending_sse, l_area, pct_error; struct timeb start; @@ -6589,7 +6728,8 @@ MRI_SURFACE *MRISunfold(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_pas if (!parms->fp) { if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } @@ -6643,7 +6783,8 @@ MRI_SURFACE *MRISunfold(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_pas MRIScomputeMetricProperties(mris); if (parms->complete_dist_mat) { MRIScomputeAllDistances(mris); - } else { + } + else { MRISsampleDistances(mris, nbrs, parms->nbhd_size); } MRISrestoreVertexPositions(mris, TMP_VERTICES); @@ -6742,7 +6883,8 @@ MRI_SURFACE *MRISunfold(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_pas parms->l_dist = dist_coefs[i]; if (use_nl_area) { parms->l_nlarea = area_coefs[i]; - } else { + } + else { parms->l_area = area_coefs[i]; } parms->l_angle = ANGLE_AREA_SCALE * parms->l_area; @@ -6756,7 +6898,8 @@ MRI_SURFACE *MRISunfold(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_pas if (use_nl_area) { parms->l_nlarea = area_coefs[NCOEFS - 1]; - } else { + } + else { parms->l_area = area_coefs[NCOEFS - 1]; } parms->l_dist = dist_coefs[NCOEFS - 1]; @@ -6860,7 +7003,8 @@ MRI_SURFACE *MRISunfold(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_pas Description ------------------------------------------------------*/ -MRI_SURFACE *MRISquickSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_passes) { +MRI_SURFACE *MRISquickSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int max_passes) +{ int niter, passno, msec, nbrs[MAX_NBHD_SIZE], i, use_dists, base_averages; double pct_error, orig_k, last_sse, sse, pct_change; struct timeb start; @@ -6887,7 +7031,8 @@ MRI_SURFACE *MRISquickSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int ma if (!parms->fp) { if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "MRISquickSphere: could not open log file %s\n", fname); @@ -7207,7 +7352,8 @@ static float neg_area_ratios[] = { 1e-1}; #define MAX_PASSES (sizeof(neg_area_ratios) / sizeof(neg_area_ratios[0])) static int mrisRemoveNegativeArea( - MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int base_averages, float min_area_pct, int max_passes) { + MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int base_averages, float min_area_pct, int max_passes) +{ int total_steps, done, steps, n_averages, old_averages, npasses, niter; float pct_neg, ratio; char *snum, *sdenom; @@ -7220,7 +7366,8 @@ static int mrisRemoveNegativeArea( sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -7258,7 +7405,8 @@ static int mrisRemoveNegativeArea( if (!FZERO(l_corr)) { sdenom = "corr"; pdenom = &parms->l_corr; /*cmod = 10.0f ;*/ - } else { + } + else { sdenom = "dist"; pdenom = &parms->l_dist; } @@ -7266,10 +7414,12 @@ static int mrisRemoveNegativeArea( if (!FZERO(l_area)) { snum = "area"; pnum = &parms->l_area; - } else if (!FZERO(l_nlarea)) { + } + else if (!FZERO(l_nlarea)) { snum = "nlarea"; pnum = &parms->l_nlarea; - } else if (!FZERO(l_parea)) + } + else if (!FZERO(l_parea)) #if 0 { snum = "parea" ; @@ -7281,7 +7431,8 @@ static int mrisRemoveNegativeArea( pnum = &parms->l_area; } #endif - else { + else + { snum = "spring"; pnum = &parms->l_spring; } @@ -7352,7 +7503,8 @@ static int mrisRemoveNegativeArea( Description ------------------------------------------------------*/ -static int mrisIntegrationEpoch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int base_averages) { +static int mrisIntegrationEpoch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int base_averages) +{ int total_steps, done, steps, n_averages, old_averages; char *snum, *sdenom; float ratio, *pdenom, *pnum; @@ -7360,7 +7512,8 @@ static int mrisIntegrationEpoch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int if (!FZERO(parms->l_corr)) { sdenom = "corr"; pdenom = &parms->l_corr; - } else { + } + else { sdenom = "dist"; pdenom = &parms->l_dist; } @@ -7368,13 +7521,16 @@ static int mrisIntegrationEpoch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int if (!FZERO(parms->l_nlarea)) { snum = "nlarea"; pnum = &parms->l_nlarea; - } else if (!FZERO(parms->l_area)) { + } + else if (!FZERO(parms->l_area)) { snum = "area"; pnum = &parms->l_area; - } else if (!FZERO(parms->l_parea)) { + } + else if (!FZERO(parms->l_parea)) { snum = "parea"; pnum = &parms->l_parea; - } else { + } + else { snum = "spring"; pnum = &parms->l_spring; } @@ -7396,7 +7552,8 @@ static int mrisIntegrationEpoch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -7470,7 +7627,8 @@ static int mrisIntegrationEpoch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int Description ------------------------------------------------------*/ -int MRISintegrate(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) { +int MRISintegrate(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) +{ int t, write_iterations, niterations, nsmall, neg; double l_dist, l_area, l_spring, sse, old_sse, delta_t, total_small = 0.0; double sse_thresh, pct_neg, pct_neg_area, total_vertices, tol; @@ -7483,7 +7641,8 @@ int MRISintegrate(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) { sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -7496,7 +7655,8 @@ int MRISintegrate(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) { niterations = parms->niterations; if (((parms->flags & IPFLAG_QUICK) == 0) && ((parms->flags & IPFLAG_NOSCALE_TOL) == 0)) { tol = parms->tol * sqrt(((double)n_averages + 1.0) / 1024.0); - } else { + } + else { tol = parms->tol; } sse_thresh = tol; @@ -7764,7 +7924,8 @@ int MRISintegrate(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) { if (++total_small > TOTAL_SMALL) { break; } - } else { + } + else { if (total_small > 0.0) /* if error increases more than 1/4 time quit */ { @@ -7826,7 +7987,8 @@ int MRISintegrate(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) { this is basically a fork of MRISIntegrate, but it shouldn't be. In future this should be merged into MRISIntegrate with the according ifdefs */ -int mrisIntegrateCUDA(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) { +int mrisIntegrateCUDA(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_averages) +{ int t, write_iterations, niterations, nsmall, neg; double l_dist, l_area, l_spring, sse, old_sse, delta_t, total_small = 0.0; double sse_thresh, pct_neg, pct_neg_area, total_vertices, tol; @@ -7857,7 +8019,8 @@ int mrisIntegrateCUDA(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_average sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -7870,7 +8033,8 @@ int mrisIntegrateCUDA(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_average niterations = parms->niterations; if (((parms->flags & IPFLAG_QUICK) == 0) && ((parms->flags & IPFLAG_NOSCALE_TOL) == 0)) { tol = parms->tol * sqrt(((double)n_averages + 1.0) / 1024.0); - } else { + } + else { tol = parms->tol; } sse_thresh = tol; @@ -8037,7 +8201,8 @@ int mrisIntegrateCUDA(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_average printf("CUDA MRISCverageGradients: %ld ms\n", result.tv_sec * 1000 + result.tv_usec / 1000); fflush(stdout); #endif // FS_CUDA_TIMINGS - } else { + } + else { #ifdef FS_CUDA_TIMINGS gettimeofday(&tv1, NULL); #endif // FS_CUDA_TIMINGS @@ -8180,7 +8345,8 @@ int mrisIntegrateCUDA(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_average if (++total_small > TOTAL_SMALL) { break; } - } else { + } + else { if (total_small > 0.0) /* if error increases more than 1/4 time quit */ { @@ -8243,7 +8409,8 @@ int mrisIntegrateCUDA(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int n_average // last and the distance vector on the GPU is outdated. if (mris->status != MRIS_PLANE) { parms->ending_sse = MRIScomputeSSE_CUDA(mris, mrisc, parms); - } else { + } + else { parms->ending_sse = MRIScomputeSSE(mris, parms); } /* mrisProjectSurface(mris) ;*/ @@ -8269,7 +8436,8 @@ static double mrisComputeError(MRI_SURFACE *mris, float *pangle_rms, float *pcurv_rms, float *pdist_rms, - float *pcorr_rms) { + float *pcorr_rms) +{ double rms, sse_area, sse_angle, sse_curv, delta, area_scale, sse_dist, sse_corr; int ano, fno, ntriangles, total_neighbors; FACE *face; @@ -8278,7 +8446,8 @@ static double mrisComputeError(MRI_SURFACE *mris, #if METRIC_SCALE if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -8305,7 +8474,8 @@ static double mrisComputeError(MRI_SURFACE *mris, sse_corr = mrisComputeCorrelationError(mris, parms, 1); if (!DZERO(parms->l_dist)) { sse_dist = mrisComputeDistanceError(mris, parms); - } else { + } + else { sse_dist = 0; } @@ -8326,7 +8496,8 @@ static double mrisComputeError(MRI_SURFACE *mris, nv = (float)MRISvalidVertices(mris); if (mris->status != MRIS_PLANE) { *pcurv_rms = (float)sqrt(sse_curv / nv); - } else { + } + else { *pcurv_rms = 0.0f; } *pdist_rms = (float)sqrt(sse_dist / (double)total_neighbors); @@ -8372,7 +8543,8 @@ static double mrisComputeError(MRI_SURFACE *mris, } static double mrisComputeSSE_MEF( - MRI_SURFACE *mris, INTEGRATION_PARMS *parms, MRI *mri30, MRI *mri5, double weight30, double weight5, MHT *mht) { + MRI_SURFACE *mris, INTEGRATION_PARMS *parms, MRI *mri30, MRI *mri5, double weight30, double weight5, MHT *mht) +{ double sse, l_intensity, rms; l_intensity = parms->l_intensity; @@ -8397,7 +8569,8 @@ static double mrisComputeSSE_MEF( As such, it must represent the exact error function being minimized (as opposed to computeError above). ------------------------------------------------------*/ -double MRIScomputeSSE(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +double MRIScomputeSSE(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double sse, sse_area, sse_angle, sse_curv, sse_spring, sse_dist, area_scale, sse_corr, sse_neg_area, l_corr, sse_val, sse_sphere, sse_thick_min, sse_thick_parallel, sse_ashburner_triangle, sse_grad, sse_nl_area, sse_nl_dist, sse_tspring, sse_repulse, sse_tsmooth, sse_loc, sse_thick_spring, sse_repulsive_ratio, sse_shrinkwrap, @@ -8409,7 +8582,8 @@ double MRIScomputeSSE(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { #if METRIC_SCALE if (mris->patch || mris->noscale) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -8572,7 +8746,8 @@ double MRIScomputeSSE(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { } #ifdef FS_CUDA -static double MRIScomputeSSE_CUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *mrisc, INTEGRATION_PARMS *parms) { +static double MRIScomputeSSE_CUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *mrisc, INTEGRATION_PARMS *parms) +{ double sse, sse_area, sse_angle, delta, sse_curv, sse_spring, sse_dist, area_scale, sse_corr, sse_neg_area, l_corr, sse_val, sse_sphere, sse_thick_min, sse_thick_parallel, sse_ashburner_triangle, sse_grad, sse_nl_area, sse_nl_dist, sse_tspring, sse_repulse, sse_tsmooth, sse_loc, sse_repulsive_ratio, sse_shrinkwrap, sse_expandwrap, @@ -8585,7 +8760,8 @@ static double MRIScomputeSSE_CUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *mrisc, IN #if METRIC_SCALE if (mris->patch || mris->noscale) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -8744,12 +8920,14 @@ static double MRIScomputeSSE_CUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *mrisc, IN As such, it must represent the exact error function being minimized (as opposed to computeError above). ------------------------------------------------------*/ -double MRIScomputeSSEExternal(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, double *ext_sse) { +double MRIScomputeSSEExternal(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, double *ext_sse) +{ double sse; if (gMRISexternalSSE) { sse = (*gMRISexternalSSE)(mris, parms); - } else { + } + else { sse = 0; } *ext_sse = sse; @@ -8766,13 +8944,15 @@ double MRIScomputeSSEExternal(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, doubl Description ------------------------------------------------------*/ -static double mrisComputeNonlinearAreaSSE(MRI_SURFACE *mris) { +static double mrisComputeNonlinearAreaSSE(MRI_SURFACE *mris) +{ double area_scale; #if METRIC_SCALE if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -8794,7 +8974,8 @@ static double mrisComputeNonlinearAreaSSE(MRI_SURFACE *mris) { #if SCALE_NONLINEAR_AREA if (!FZERO(face->orig_area)) { ratio = area_scale * face->area / face->orig_area; - } else { + } + else { ratio = 0.0f; } #else @@ -8802,7 +8983,8 @@ static double mrisComputeNonlinearAreaSSE(MRI_SURFACE *mris) { #endif if (ratio > MAX_NEG_RATIO) { ratio = MAX_NEG_RATIO; - } else if (ratio < -MAX_NEG_RATIO) { + } + else if (ratio < -MAX_NEG_RATIO) { ratio = -MAX_NEG_RATIO; } #if 0 @@ -8826,7 +9008,8 @@ static double mrisComputeNonlinearAreaSSE(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISscaleBrainArea(MRI_SURFACE *mris) { +int MRISscaleBrainArea(MRI_SURFACE *mris) +{ float scale; scale = sqrt(mris->orig_area / (mris->total_area + mris->neg_area)); @@ -8985,7 +9168,8 @@ mrisFindPoles(MRIS *mris) Description ------------------------------------------------------*/ -static int mrisOrientEllipsoid(MRI_SURFACE *mris) { +static int mrisOrientEllipsoid(MRI_SURFACE *mris) +{ int fno; #pragma omp parallel for @@ -9043,7 +9227,8 @@ static int mrisOrientEllipsoid(MRI_SURFACE *mris) { } if (face->area >= 0.0f) { total_area += face->area; - } else { + } + else { neg_area += -face->area; neg_orig_area += face->orig_area; } @@ -9064,7 +9249,8 @@ static int mrisOrientEllipsoid(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisOrientPlane(MRI_SURFACE *mris) { +static int mrisOrientPlane(MRI_SURFACE *mris) +{ int fno, ano, vno; FACE *face; VERTEX *v; @@ -9099,7 +9285,8 @@ static int mrisOrientPlane(MRI_SURFACE *mris) { } if (face->area >= 0.0f) { mris->total_area += face->area; - } else { + } + else { mris->neg_area += -face->area; mris->neg_orig_area += face->orig_area; } @@ -9114,7 +9301,8 @@ static int mrisOrientPlane(MRI_SURFACE *mris) { if (v->nz < 0) { v->nz *= -1; v->neg = 1; - } else { + } + else { v->neg = 0; } v->area = 0; @@ -9124,7 +9312,8 @@ static int mrisOrientPlane(MRI_SURFACE *mris) { } if (fix_vertex_area) { v->area /= 3.0; - } else { + } + else { v->area /= 2.0; } } @@ -9139,7 +9328,8 @@ static int mrisOrientPlane(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScountNegativeTriangles(MRI_SURFACE *mris) { +int MRIScountNegativeTriangles(MRI_SURFACE *mris) +{ int fno, negative; FACE *face; @@ -9164,7 +9354,8 @@ int MRIScountNegativeTriangles(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISupdateEllipsoidSurface(MRI_SURFACE *mris) { +int MRISupdateEllipsoidSurface(MRI_SURFACE *mris) +{ #if 0 MRIScomputeTriangleProperties(mris) ; /* recompute areas and normals */ #endif @@ -9179,7 +9370,8 @@ int MRISupdateEllipsoidSurface(MRI_SURFACE *mris) { using num_avgs nearest-neighbor averages. See also MRISaverageGradientsFast() ------------------------------------------------------*/ -int MRISaverageGradients(MRI_SURFACE *mris, int num_avgs) { +int MRISaverageGradients(MRI_SURFACE *mris, int num_avgs) +{ int i, vno; float sigma; VERTEX *v; @@ -9219,7 +9411,8 @@ int MRISaverageGradients(MRI_SURFACE *mris, int num_avgs) { MRISgradientFromParameterization(mrisp_blur, mris); MRISPfree(&mrisp); MRISPfree(&mrisp_blur); - } else + } + else for (i = 0; i < num_avgs; i++) { #ifdef HAVE_OPENMP #pragma omp parallel for @@ -9291,7 +9484,8 @@ int MRISaverageGradients(MRI_SURFACE *mris, int num_avgs) { of MRISaverageGradients(). Should be about 40% faster. It also gives identical results as can be verified with MRISaverageGradientsFastCheck(). ------------------------------------------------------*/ -int MRISaverageGradientsFast(MRI_SURFACE *mris, int num_avgs) { +int MRISaverageGradientsFast(MRI_SURFACE *mris, int num_avgs) +{ int vno, vnb, *pnb, num, nthavg; VERTEX *v, *vn; float **pdx, **pdy, **pdz, sumdx, sumdy, sumdz; @@ -9418,7 +9612,8 @@ int MRISaverageGradientsFast(MRI_SURFACE *mris, int num_avgs) { return (NO_ERROR); } /*--------------------------------------------------------*/ -int MRISaverageGradientsFastCheck(int num_avgs) { +int MRISaverageGradientsFastCheck(int num_avgs) +{ char tmpstr[2000], *UFSS; MRIS *mrisA, *mrisB; int k, msec, nerrs; @@ -9517,7 +9712,8 @@ int MRISaverageGradientsFastCheck(int num_avgs) { Description ------------------------------------------------------*/ -int MRISreadTriangleProperties(MRI_SURFACE *mris, const char *mris_fname) { +int MRISreadTriangleProperties(MRI_SURFACE *mris, const char *mris_fname) +{ int ano, vnum, fnum, fno, vno; FACE *face; VERTEX *v; @@ -9645,7 +9841,8 @@ int MRISreadTriangleProperties(MRI_SURFACE *mris, const char *mris_fname) { Description ------------------------------------------------------*/ -int MRISwriteTriangleProperties(MRI_SURFACE *mris, const char *mris_fname) { +int MRISwriteTriangleProperties(MRI_SURFACE *mris, const char *mris_fname) +{ int fno, ano, vno; FACE *face; FILE *fp; @@ -9765,7 +9962,8 @@ int MRISwriteTriangleProperties(MRI_SURFACE *mris, const char *mris_fname) { ------------------------------------------------------*/ -int MRIScomputeTriangleProperties(MRI_SURFACE *mris) { +int MRIScomputeTriangleProperties(MRI_SURFACE *mris) +{ int fno, vno, tno; double total_area; VECTOR *v_a[_MAX_FS_THREADS], *v_b[_MAX_FS_THREADS], *v_n[_MAX_FS_THREADS]; @@ -9823,9 +10021,11 @@ int MRIScomputeTriangleProperties(MRI_SURFACE *mris) { VECTOR_LOAD(v_n[tid], face->nx, face->ny, face->nz); if ((V3_X(v_n[tid]) < V3_Y(v_n[tid])) && (V3_X(v_n[tid]) < V3_Z(v_n[tid]))) { dz = fabs(V3_X(v_n[tid])); - } else if (V3_Y(v_n[tid]) < V3_Z(v_n[tid])) { + } + else if (V3_Y(v_n[tid]) < V3_Z(v_n[tid])) { dz = fabs(V3_Y(v_n[tid])); - } else { + } + else { dz = fabs(V3_Z(v_n[tid])); } for (ano = 0; ano < ANGLES_PER_TRIANGLE; ano++) { @@ -9912,7 +10112,8 @@ int MRIScomputeTriangleProperties(MRI_SURFACE *mris) { #define MAX_MOMENTUM_MM 1 #define MIN_MM 0.001 -static double mrisAdaptiveTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisAdaptiveTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double delta_t, sse, starting_sse; starting_sse = MRIScomputeSSE(mris, parms); @@ -9943,7 +10144,8 @@ static double mrisAdaptiveTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) MRISrestoreOldPositions(mris); mrisProjectSurface(mris); } - } else /* error decreased */ + } + else /* error decreased */ { parms->dt *= parms->dt_increase; } @@ -9957,7 +10159,8 @@ static double mrisAdaptiveTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) Description ------------------------------------------------------*/ -static double mrisAsynchronousTimeStep(MRI_SURFACE *mris, float momentum, float delta_t, MHT *mht, float max_mag) { +static double mrisAsynchronousTimeStep(MRI_SURFACE *mris, float momentum, float delta_t, MHT *mht, float max_mag) +{ static int direction = 1; double mag; int vno, i; @@ -9969,11 +10172,13 @@ static double mrisAsynchronousTimeStep(MRI_SURFACE *mris, float momentum, float mris->db = delta_t * mris->beta + momentum * mris->db; mris->dg = delta_t * mris->gamma + momentum * mris->dg; MRISrotate(mris, mris, mris->da, mris->db, mris->dg); - } else + } + else for (i = 0; i < mris->nvertices; i++) { if (direction < 0) { vno = mris->nvertices - i - 1; - } else { + } + else { vno = i; } v = &mris->vertices[vno]; @@ -10069,7 +10274,8 @@ static double mrisAsynchronousTimeStep(MRI_SURFACE *mris, float momentum, float Description ------------------------------------------------------*/ -static double mrisAsynchronousTimeStepNew(MRI_SURFACE *mris, float momentum, float delta_t, MHT *mht, float max_mag) { +static double mrisAsynchronousTimeStepNew(MRI_SURFACE *mris, float momentum, float delta_t, MHT *mht, float max_mag) +{ static int direction = 1; double mag; int vno, i; @@ -10081,11 +10287,13 @@ static double mrisAsynchronousTimeStepNew(MRI_SURFACE *mris, float momentum, flo mris->db = delta_t * mris->beta + momentum * mris->db; mris->dg = delta_t * mris->gamma + momentum * mris->dg; MRISrotate(mris, mris, mris->da, mris->db, mris->dg); - } else + } + else for (i = 0; i < mris->nvertices; i++) { if (direction < 0) { vno = mris->nvertices - i - 1; - } else { + } + else { vno = i; } v = &mris->vertices[vno]; @@ -10187,7 +10395,8 @@ static double mrisAsynchronousTimeStepNew(MRI_SURFACE *mris, float momentum, flo Description ------------------------------------------------------*/ -double MRISmomentumTimeStep(MRI_SURFACE *mris, float momentum, float dt, float tol, float n_averages) { +double MRISmomentumTimeStep(MRI_SURFACE *mris, float momentum, float dt, float tol, float n_averages) +{ double delta_t, mag; int vno; VERTEX *v; @@ -10234,7 +10443,8 @@ double MRISmomentumTimeStep(MRI_SURFACE *mris, float momentum, float dt, float t mris->db = delta_t * mris->beta + momentum * mris->db; mris->dg = delta_t * mris->gamma + momentum * mris->dg; MRISrotate(mris, mris, mris->da, mris->db, mris->dg); - } else if (mris->status == MRIS_SPHERICAL_PATCH) { + } + else if (mris->status == MRIS_SPHERICAL_PATCH) { for (vno = 0; vno < mris->nvertices; vno++) { v = &mris->vertices[vno]; if (v->ripflag) { @@ -10266,7 +10476,8 @@ double MRISmomentumTimeStep(MRI_SURFACE *mris, float momentum, float dt, float t if (mris->patch != 2) { mrisApplyTopologyPreservingGradient(mris, 0, 1); } - } else + } + else for (vno = 0; vno < mris->nvertices; vno++) { v = &mris->vertices[vno]; if (v->ripflag) { @@ -10341,7 +10552,8 @@ static int mrisApplyGradientPositiveAreaMaximizing(MRI_SURFACE *mris, double dt) sampled points, including the predicted one. ------------------------------------------------------*/ #define MAX_ENTRIES 100 -static double mrisLineMinimize(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisLineMinimize(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ char fname[STRLEN]; FILE *fp = NULL; double starting_sse, sse, min_sse, max_dt, min_delta, max_delta, mag, grad, delta_t, min_dt, mean_delta; @@ -10545,7 +10757,8 @@ static double mrisLineMinimize(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { sse_out[N++] = sse; } } - } else /* couldn't invert matrix */ + } + else /* couldn't invert matrix */ { fprintf(stderr, "singular matrix in quadratic form\n"); MatrixFree(&mX); @@ -10608,11 +10821,14 @@ static double mrisLineMinimize(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { if (mris->status == MRIS_SPHERICAL_PATCH && parms->flags & IPFLAG_PRESERVE_TOPOLOGY_CONVEXHULL) { mrisApplyTopologyPreservingGradient(mris, dt_in[mini], 0); - } else if (parms->flags & IPFLAG_PRESERVE_SPHERICAL_POSITIVE_AREA) { + } + else if (parms->flags & IPFLAG_PRESERVE_SPHERICAL_POSITIVE_AREA) { mrisApplyGradientPositiveAreaPreserving(mris, dt_in[mini]); - } else if (parms->flags & IPFLAG_MAXIMIZE_SPHERICAL_POSITIVE_AREA) { + } + else if (parms->flags & IPFLAG_MAXIMIZE_SPHERICAL_POSITIVE_AREA) { mrisApplyGradientPositiveAreaMaximizing(mris, dt_in[mini]); - } else { + } + else { MRISapplyGradient(mris, dt_in[mini]); } return (dt_in[mini]); @@ -10626,7 +10842,8 @@ static double mrisLineMinimize(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { integrate this into mrisLineMinimize with ifdefs */ -static double mrisLineMinimizeCUDA(MRI_CUDA_SURFACE *mrisc, MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisLineMinimizeCUDA(MRI_CUDA_SURFACE *mrisc, MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ char fname[STRLEN]; FILE *fp = NULL; double starting_sse, sse, min_sse, max_dt, min_delta, max_delta, mag, grad, delta_t, min_dt, mean_delta; @@ -10893,7 +11110,8 @@ static double mrisLineMinimizeCUDA(MRI_CUDA_SURFACE *mrisc, MRI_SURFACE *mris, I sse_out[N++] = sse; } } - } else /* couldn't invert matrix */ + } + else /* couldn't invert matrix */ { fprintf(stderr, "singular matrix in quadratic form\n"); MatrixFree(&mX); @@ -10964,11 +11182,14 @@ static double mrisLineMinimizeCUDA(MRI_CUDA_SURFACE *mrisc, MRI_SURFACE *mris, I if (mris->status == MRIS_SPHERICAL_PATCH && parms->flags & IPFLAG_PRESERVE_TOPOLOGY_CONVEXHULL) { mrisApplyTopologyPreservingGradient(mris, dt_in[mini], 0); - } else if (parms->flags & IPFLAG_PRESERVE_SPHERICAL_POSITIVE_AREA) { + } + else if (parms->flags & IPFLAG_PRESERVE_SPHERICAL_POSITIVE_AREA) { mrisApplyGradientPositiveAreaPreserving(mris, dt_in[mini]); - } else if (parms->flags & IPFLAG_MAXIMIZE_SPHERICAL_POSITIVE_AREA) { + } + else if (parms->flags & IPFLAG_MAXIMIZE_SPHERICAL_POSITIVE_AREA) { mrisApplyGradientPositiveAreaMaximizing(mris, dt_in[mini]); - } else { + } + else { MRISapplyGradient(mris, dt_in[mini]); } @@ -10993,7 +11214,8 @@ static double mrisLineMinimizeCUDA(MRI_CUDA_SURFACE *mrisc, MRI_SURFACE *mris, I Use a binary search in the gradient direction to find the location of the minimum. ------------------------------------------------------*/ -static double mrisLineMinimizeSearch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisLineMinimizeSearch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ char fname[STRLEN]; FILE *fp = NULL; double starting_sse, sse, min_sse, max_dt, total_delta, min_delta, max_delta, mag, grad, delta_t, min_dt, mean_delta; @@ -11113,7 +11335,8 @@ static double mrisLineMinimizeSearch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms } min_sse = sse; total_delta += delta_t; /* keep track of total time step */ - } else /* error increased - undo it and decrease time step */ + } + else /* error increased - undo it and decrease time step */ { if (increasing) /* went too far - reverse delta_t change */ { @@ -11129,7 +11352,8 @@ static double mrisLineMinimizeSearch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms } if (increasing) { delta_t *= 2.0; /* increase time step and search further out */ - } else /* decreasing - reduce time step */ + } + else /* decreasing - reduce time step */ { delta_t *= 0.5; } @@ -11149,7 +11373,8 @@ static double mrisLineMinimizeSearch(MRI_SURFACE *mris, INTEGRATION_PARMS *parms Description ------------------------------------------------------*/ -MRI_SURFACE *MRISscaleBrain(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float scale) { +MRI_SURFACE *MRISscaleBrain(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float scale) +{ VERTEX *v; int k; float xlo, ylo, zlo, xhi, yhi, zhi, x0, y0, z0; @@ -11259,7 +11484,8 @@ MRI_SURFACE *MRISscaleBrain(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float Description ------------------------------------------------------*/ -int MRISwriteCurvature(MRI_SURFACE *mris, const char *sname) { +int MRISwriteCurvature(MRI_SURFACE *mris, const char *sname) +{ int k, mritype; float curv; char fname[STRLEN], *cp, path[STRLEN], name[STRLEN], *hemi; @@ -11288,24 +11514,29 @@ int MRISwriteCurvature(MRI_SURFACE *mris, const char *sname) { if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s.%s", hemi, sname); - } else { + } + else { sprintf(fname, "%s/%s.%s", path, hemi, sname); } - } else { + } + else { if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s", sname); - } else { + } + else { sprintf(fname, "%s/%s", path, sname); } } - } else { + } + else { FileNamePath(sname, path); FileNameOnly(sname, name); cp = strchr(name, '.'); if (!cp || ((cp - name) != 2) || *(cp - 1) != 'h' || ((*(cp - 2) != 'l' && *(cp - 2) != 'r'))) { sprintf(fname, "%s/%s.%s", path, hemi, name); - } else { + } + else { sprintf(fname, "%s/%s", path, name); } } @@ -11336,7 +11567,8 @@ int MRISwriteCurvature(MRI_SURFACE *mris, const char *sname) { MRIwrite(TempMRI, fname); MRIfree(&TempMRI); return (NO_ERROR); - } else if (mritype == VTK_FILE) { + } + else if (mritype == VTK_FILE) { MRISwriteVTK(mris, fname); MRISwriteCurvVTK(mris, fname); return (NO_ERROR); @@ -11363,7 +11595,8 @@ int MRISwriteCurvature(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISwriteDists(MRI_SURFACE *mris, const char *sname) { +int MRISwriteDists(MRI_SURFACE *mris, const char *sname) +{ int k, i; float dist; char fname[STRLEN], *cp, path[STRLEN]; @@ -11378,8 +11611,8 @@ int MRISwriteDists(MRI_SURFACE *mris, const char *sname) { if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s.%s", mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", sname); - - } else { + } + else { // PW 2017/05/15: Legacy behaviour sprintf(fname, "%s/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", sname); } @@ -11387,12 +11620,14 @@ int MRISwriteDists(MRI_SURFACE *mris, const char *sname) { if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s", sname); - } else { + } + else { // PW 2017/05/15: Legacy behaviour sprintf(fname, "%s/%s", path, sname); } } - } else { + } + else { strcpy(fname, sname); /* path specified explcitly */ } fp = fopen(fname, "wb"); @@ -11415,7 +11650,8 @@ int MRISwriteDists(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -MRI *MRISwriteIntoVolume(MRI_SURFACE *mris, MRI *mri, int which) { +MRI *MRISwriteIntoVolume(MRI_SURFACE *mris, MRI *mri, int which) +{ int vno; VERTEX *v; float val = 0; @@ -11480,7 +11716,8 @@ MRI *MRISwriteIntoVolume(MRI_SURFACE *mris, MRI *mri, int which) { Description ------------------------------------------------------*/ -MRI_SURFACE *MRISreadFromVolume(MRI *mri, MRI_SURFACE *mris, int which) { +MRI_SURFACE *MRISreadFromVolume(MRI *mri, MRI_SURFACE *mris, int which) +{ int vno; VERTEX *v; float val; @@ -11535,7 +11772,8 @@ MRI_SURFACE *MRISreadFromVolume(MRI *mri, MRI_SURFACE *mris, int which) { Description ------------------------------------------------------*/ -MRI_SURFACE *MRISrotate(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float alpha, float beta, float gamma) { +MRI_SURFACE *MRISrotate(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float alpha, float beta, float gamma) +{ int vno; VERTEX *vertex; float x, y, z, ca, cb, cg, sa, sb, sg, xp, yp, zp; @@ -11592,7 +11830,8 @@ MRI_SURFACE *MRISrotate(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, float alph Description ------------------------------------------------------*/ -int MRISwriteAreaError(MRI_SURFACE *mris, const char *name) { +int MRISwriteAreaError(MRI_SURFACE *mris, const char *name) +{ int vno, fno, i; float area, orig_area; FACE *face; @@ -11641,7 +11880,8 @@ int MRISwriteAreaError(MRI_SURFACE *mris, const char *name) { Description ------------------------------------------------------*/ -int MRISwriteAreaErrorToValFile(MRI_SURFACE *mris, const char *name) { +int MRISwriteAreaErrorToValFile(MRI_SURFACE *mris, const char *name) +{ int vno, fno; float area, orig_area; FACE *face; @@ -11678,7 +11918,8 @@ int MRISwriteAreaErrorToValFile(MRI_SURFACE *mris, const char *name) { Description ------------------------------------------------------*/ -int MRISwriteAngleError(MRI_SURFACE *mris, const char *fname) { +int MRISwriteAngleError(MRI_SURFACE *mris, const char *fname) +{ int vno, fno, ano, i; float error; FILE *fp; @@ -11722,7 +11963,8 @@ int MRISwriteAngleError(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ #if AVERAGE_AREAS -static int mrisAverageAreas(MRI_SURFACE *mris, int num_avgs, int which) { +static int mrisAverageAreas(MRI_SURFACE *mris, int num_avgs, int which) +{ int i, vno, vnb, *pnb, fno, num, vf, nfno; float area; VERTEX *v, *vn; @@ -11800,7 +12042,8 @@ static int mrisAverageAreas(MRI_SURFACE *mris, int num_avgs, int which) { Description ------------------------------------------------------*/ #include "stats.h" -int MRISsampleStatVolume(MRI_SURFACE *mris, void *vsv, int time_point, int coords) { +int MRISsampleStatVolume(MRI_SURFACE *mris, void *vsv, int time_point, int coords) +{ VERTEX *v; int vno, xv, yv, zv, width, height, depth; double x, y, z, xt, yt, zt; @@ -11860,7 +12103,8 @@ int MRISsampleStatVolume(MRI_SURFACE *mris, void *vsv, int time_point, int coord Description ------------------------------------------------------*/ -int MRISwriteCurvatureToWFile(MRI_SURFACE *mris, const char *fname) { +int MRISwriteCurvatureToWFile(MRI_SURFACE *mris, const char *fname) +{ int k, num; /* loop counters */ float f; FILE *fp; @@ -11912,7 +12156,8 @@ int MRISwriteCurvatureToWFile(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -int MRISwriteValues(MRI_SURFACE *mris, const char *sname) { +int MRISwriteValues(MRI_SURFACE *mris, const char *sname) +{ int k, num; /* loop counters */ float f; char fname[STRLEN], *cp; @@ -11991,11 +12236,13 @@ int MRISwriteValues(MRI_SURFACE *mris, const char *sname) { sum2 = (sum2 / num - sum * sum); if (sum2 > 0) { sum2 = sqrt(sum2); - } else { + } + else { sum2 = 0; } printf("avg = %2.3f, stdev = %2.3f, min = %2.3f, max = %2.3f\n", sum, sum2, min, max); - } else { + } + else { printf("Warning: all vertex values are zero\n"); } @@ -12003,7 +12250,8 @@ int MRISwriteValues(MRI_SURFACE *mris, const char *sname) { } #if 1 -int MRISwriteD(MRI_SURFACE *mris, const char *sname) { +int MRISwriteD(MRI_SURFACE *mris, const char *sname) +{ float *curv_save; curv_save = (float *)calloc(mris->nvertices, sizeof(float)); @@ -12025,7 +12273,8 @@ int MRISwriteD(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISwriteD(MRI_SURFACE *mris, const char *sname) { +int MRISwriteD(MRI_SURFACE *mris, const char *sname) +{ int k, num; /* loop counters */ float f; char fname[STRLEN], *cp; @@ -12098,11 +12347,13 @@ int MRISwriteD(MRI_SURFACE *mris, const char *sname) { sum2 = (sum2 / num - sum * sum); if (sum2 > 0) { sum2 = sqrt(sum2); - } else { + } + else { sum2 = 0; } printf("avg = %2.3f, stdev = %2.3f, min = %2.3f, max = %2.3f\n", sum, sum2, min, max); - } else { + } + else { printf("Warning: all vertex d values are zero\n"); } @@ -12117,7 +12368,8 @@ int MRISwriteD(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadAnnotation(MRI_SURFACE *mris, const char *sname) { +int MRISreadAnnotation(MRI_SURFACE *mris, const char *sname) +{ int vno, need_hemi; int return_code; char *cp, fname[STRLEN], path[STRLEN], fname_no_path[STRLEN]; @@ -12134,7 +12386,8 @@ int MRISreadAnnotation(MRI_SURFACE *mris, const char *sname) { mris = mrisReadGIFTIfile(sname, mris); if (mris) { return (NO_ERROR); - } else { + } + else { return (ERROR_BADFILE); } } @@ -12154,9 +12407,11 @@ int MRISreadAnnotation(MRI_SURFACE *mris, const char *sname) { FileNamePath(mris->fname, path); if (!need_hemi) { sprintf(fname, "%s/../label/%s", path, fname_no_path); - } else /* no hemisphere specified */ + } + else /* no hemisphere specified */ sprintf(fname, "%s/../label/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", fname_no_path); - } else { + } + else { strcpy(fname, sname); /* full path specified */ cp = strstr(fname, ".annot"); if (!cp) { @@ -12281,7 +12536,8 @@ int MRISreadAnnotation(MRI_SURFACE *mris, const char *sname) { incorrect number of vertices in the annotation file. ------------------------------------------------------*/ -int MRISreadAnnotationIntoArray(const char *fname, int in_array_size, int **out_array) { +int MRISreadAnnotationIntoArray(const char *fname, int in_array_size, int **out_array) +{ int i, j, vno, num; FILE *fp; int *array = NULL; @@ -12333,7 +12589,8 @@ int MRISreadAnnotationIntoArray(const char *fname, int in_array_size, int **out_ "ERROR: Too many out-of-range vertex indices in " "MRISreadAnnotationIntoArray!\n"); } - } else { + } + else { array[vno] = i; } } @@ -12360,7 +12617,8 @@ int MRISreadAnnotationIntoArray(const char *fname, int in_array_size, int **out_ value, and if present, reads in a color table. */ -int MRISreadCTABFromAnnotationIfPresent(const char *fname, COLOR_TABLE **out_table) { +int MRISreadCTABFromAnnotationIfPresent(const char *fname, COLOR_TABLE **out_table) +{ int skip, j, num; FILE *fp; COLOR_TABLE *ctab = NULL; @@ -12424,7 +12682,8 @@ int MRISreadCTABFromAnnotationIfPresent(const char *fname, COLOR_TABLE **out_tab value, and if present, sets *present to 1, or 0 if not present. */ -int MRISisCTABPresentInAnnotation(const char *fname, int *present) { +int MRISisCTABPresentInAnnotation(const char *fname, int *present) +{ int skip, j, num; FILE *fp; int tag; @@ -12475,7 +12734,8 @@ int MRISisCTABPresentInAnnotation(const char *fname, int *present) { Description ------------------------------------------------------*/ -int MRISwriteAnnotation(MRI_SURFACE *mris, const char *sname) { +int MRISwriteAnnotation(MRI_SURFACE *mris, const char *sname) +{ int i, vno, need_hemi; FILE *fp; const char *cp; @@ -12498,20 +12758,24 @@ int MRISwriteAnnotation(MRI_SURFACE *mris, const char *sname) { if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s", fname_no_path); - } else { + } + else { // PW 2017/05/15: Legacy behaviour sprintf(fname, "%s/../label/%s", path, fname_no_path); } - } else { /* no hemisphere specified */ + } + else { /* no hemisphere specified */ if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s.%s", mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", fname_no_path); - } else { + } + else { // PW 2017/05/15: Legacy behaviour sprintf(fname, "%s/../label/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", fname_no_path); } } - } else { + } + else { strcpy(fname, sname); /* full path specified */ cp = strstr(fname, ".annot"); if (!cp) { @@ -12551,7 +12815,8 @@ int MRISwriteAnnotation(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadValues(MRI_SURFACE *mris, const char *sname) { +int MRISreadValues(MRI_SURFACE *mris, const char *sname) +{ float *array = NULL; int return_code = 0; int vno; @@ -12578,7 +12843,8 @@ int MRISreadValues(MRI_SURFACE *mris, const char *sname) { return (NO_ERROR); } -int MRISreadValuesIntoArray(const char *sname, int in_array_size, float **out_array) { +int MRISreadValuesIntoArray(const char *sname, int in_array_size, float **out_array) +{ int i, k, num, ilat, vno; float f = 0; float lat; @@ -12747,7 +13013,8 @@ int MRISreadValuesIntoArray(const char *sname, int in_array_size, float **out_ar Description ------------------------------------------------------*/ -int MRISreadValuesBak(MRI_SURFACE *mris, const char *fname) { +int MRISreadValuesBak(MRI_SURFACE *mris, const char *fname) +{ int i, k, num, ilat; float f; float lat; @@ -12767,7 +13034,8 @@ int MRISreadValuesBak(MRI_SURFACE *mris, const char *fname) { f = freadFloat(fp); if (k >= mris->nvertices || k < 0) { printf("MRISreadValuesBak: vertex index out of range: %d f=%f\n", k, f); - } else { + } + else { mris->vertices[k].valbak = f; } } @@ -12782,7 +13050,8 @@ int MRISreadValuesBak(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -int MRISreadImagValues(MRI_SURFACE *mris, const char *fname) { +int MRISreadImagValues(MRI_SURFACE *mris, const char *fname) +{ int i, k, num, ilat; float f; float lat; @@ -12815,7 +13084,8 @@ int MRISreadImagValues(MRI_SURFACE *mris, const char *fname) { fclose(fp); return (NO_ERROR); } -int MRIScopyMarksToAnnotation(MRI_SURFACE *mris) { +int MRIScopyMarksToAnnotation(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -12829,7 +13099,8 @@ int MRIScopyMarksToAnnotation(MRI_SURFACE *mris) { } return (NO_ERROR); } -int MRISmaxMarked(MRI_SURFACE *mris) { +int MRISmaxMarked(MRI_SURFACE *mris) +{ int vno, max_marked; VERTEX *v; @@ -12849,7 +13120,8 @@ int MRISmaxMarked(MRI_SURFACE *mris) { } return (max_marked); } -int MRIScopyAnnotationsToMarkedIndex(MRI_SURFACE *mris) { +int MRIScopyAnnotationsToMarkedIndex(MRI_SURFACE *mris) +{ int vno, index; VERTEX *v; @@ -12873,7 +13145,8 @@ int MRIScopyAnnotationsToMarkedIndex(MRI_SURFACE *mris) { } return (NO_ERROR); } -int MRIScopyStatsToValues(MRI_SURFACE *mris) { +int MRIScopyStatsToValues(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -12895,7 +13168,8 @@ int MRIScopyStatsToValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyValuesToImagValues(MRI_SURFACE *mris) { +int MRIScopyValuesToImagValues(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -12917,7 +13191,8 @@ int MRIScopyValuesToImagValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyImagValuesToValues(MRI_SURFACE *mris) { +int MRIScopyImagValuesToValues(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -12939,7 +13214,8 @@ int MRIScopyImagValuesToValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISreadInflatedCoordinates(MRI_SURFACE *mris, const char *sname) { +int MRISreadInflatedCoordinates(MRI_SURFACE *mris, const char *sname) +{ if (!sname) { sname = "inflated"; } @@ -12959,7 +13235,8 @@ int MRISreadInflatedCoordinates(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadFlattenedCoordinates(MRI_SURFACE *mris, const char *sname) { +int MRISreadFlattenedCoordinates(MRI_SURFACE *mris, const char *sname) +{ int vno, fno; VERTEX *v; FACE *f; @@ -12998,7 +13275,8 @@ int MRISreadFlattenedCoordinates(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadWhiteCoordinates(MRI_SURFACE *mris, const char *sname) { +int MRISreadWhiteCoordinates(MRI_SURFACE *mris, const char *sname) +{ if (!sname) { sname = "white"; } @@ -13018,7 +13296,8 @@ int MRISreadWhiteCoordinates(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadPialCoordinates(MRI_SURFACE *mris, const char *sname) { +int MRISreadPialCoordinates(MRI_SURFACE *mris, const char *sname) +{ if (!sname) { sname = "pial"; } @@ -13038,7 +13317,8 @@ int MRISreadPialCoordinates(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadCanonicalCoordinates(MRI_SURFACE *mris, const char *sname) { +int MRISreadCanonicalCoordinates(MRI_SURFACE *mris, const char *sname) +{ MRISsaveVertexPositions(mris, TMP_VERTICES); if (MRISreadVertexPositions(mris, sname) != NO_ERROR) { return (Gerror); @@ -13056,7 +13336,8 @@ int MRISreadCanonicalCoordinates(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) { +int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) +{ int ix, iy, iz, k, i, j, npts; double rx, ry, rz; FILE *fp = NULL; @@ -13086,7 +13367,8 @@ int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) { if (type == MRIS_GIFTI_FILE) /* .gii */ { mris = MRISread(fname); - } else if (type == MRIS_ASCII_TRIANGLE_FILE) /* .ASC */ + } + else if (type == MRIS_ASCII_TRIANGLE_FILE) /* .ASC */ { fp = fopen(fname, "r"); if (!fp) ErrorReturn(ERROR_NOFILE, (ERROR_NOFILE, "MRISreadPatch(%s): could not open file", fname)); @@ -13109,7 +13391,8 @@ int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) { // read int if ((cp = fgetl(line, 256, fp))) { sscanf(cp, "%d %*s", &i); - } else + } + else ErrorReturn(ERROR_BADPARM, (ERROR_BAD_PARM, "MRISreadPatch(%s): could not read line for point %d\n", fname, j)); // if negative, flip it @@ -13133,7 +13416,8 @@ int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) { // read 3 positions if ((cp = fgetl(line, 256, fp))) { sscanf(cp, "%lf %lf %lf", &rx, &ry, &rz); - } else + } + else ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "MRISreadPatch(%s): could not read 3 floating " @@ -13172,7 +13456,6 @@ int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) { mris->vertices[k].y, mris->vertices[k].z); } - } ///////////////////////////////////////////////////////////////////////// // here file was binary @@ -13252,7 +13535,8 @@ int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) { mris->vertices[k].y, mris->vertices[k].z); } - } else // new surface format + } + else // new surface format { // read number of vertices npts = freadInt(fp); @@ -13350,7 +13634,8 @@ int MRISreadPatchNoRemove(MRI_SURFACE *mris, const char *pname) { Description ------------------------------------------------------*/ -int MRISreadPatch(MRI_SURFACE *mris, const char *pname) { +int MRISreadPatch(MRI_SURFACE *mris, const char *pname) +{ int ret; // update the vertices in patch file @@ -13382,7 +13667,8 @@ int MRISreadPatch(MRI_SURFACE *mris, const char *pname) { Description ------------------------------------------------------*/ -int MRISripFaces(MRI_SURFACE *mris) { +int MRISripFaces(MRI_SURFACE *mris) +{ int n, k; face_type *f; @@ -13449,7 +13735,8 @@ mrisRipVertices(MRI_SURFACE *mris) Description ------------------------------------------------------*/ -int MRISwritePatch(MRI_SURFACE *mris, const char *fname) { +int MRISwritePatch(MRI_SURFACE *mris, const char *fname) +{ int k, i, npts, type; float x, y, z; FILE *fp; @@ -13458,10 +13745,12 @@ int MRISwritePatch(MRI_SURFACE *mris, const char *fname) { if (type == MRIS_ASCII_TRIANGLE_FILE) // extension is ASC { return (MRISwritePatchAscii(mris, fname)); - } else if (type == MRIS_GEO_TRIANGLE_FILE) // extension is GEO + } + else if (type == MRIS_GEO_TRIANGLE_FILE) // extension is GEO { return (MRISwriteGeo(mris, fname)); - } else if (type == MRIS_STL_FILE) { + } + else if (type == MRIS_STL_FILE) { return (MRISwriteSTL(mris, fname)); } @@ -13507,7 +13796,8 @@ int MRISwritePatch(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -int MRISsmoothSurfaceNormals(MRI_SURFACE *mris, int navgs) { +int MRISsmoothSurfaceNormals(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float nx, ny, nz, num, len; VERTEX *v, *vn; @@ -13563,7 +13853,8 @@ int MRISsmoothSurfaceNormals(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -static int mrisSmoothBoundaryNormals(MRI_SURFACE *mris, int niter) { +static int mrisSmoothBoundaryNormals(MRI_SURFACE *mris, int niter) +{ #if 0 int iter,k,m,n; vertex_type *v; @@ -13617,7 +13908,8 @@ static int mrisSmoothBoundaryNormals(MRI_SURFACE *mris, int niter) { Description ------------------------------------------------------*/ -static int mrisComputeBoundaryNormals(MRI_SURFACE *mris) { +static int mrisComputeBoundaryNormals(MRI_SURFACE *mris) +{ #if 0 int k,m,n; VERTEX *v; @@ -13685,7 +13977,8 @@ static int mrisComputeBoundaryNormals(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISflattenPatchRandomly(MRI_SURFACE *mris) { +int MRISflattenPatchRandomly(MRI_SURFACE *mris) +{ float extent; int vno; @@ -13715,7 +14008,8 @@ int MRISflattenPatchRandomly(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISflattenPatch(MRI_SURFACE *mris) { +int MRISflattenPatch(MRI_SURFACE *mris) +{ float x, y, z, d, d1, d2; float nx, ny, nz; VERTEX *v; @@ -13888,7 +14182,8 @@ int MRISflattenPatch(MRI_SURFACE *mris) { Description 2 vects ortho to summed normal ------------------------------------------------------*/ -static int transform(float *xptr, float *yptr, float *zptr, float nx, float ny, float nz, float d) { +static int transform(float *xptr, float *yptr, float *zptr, float nx, float ny, float nz, float d) +{ float x = *xptr, y = *yptr, z = *zptr; *zptr = nx * x + ny * y + nz * z; @@ -13900,7 +14195,8 @@ static int transform(float *xptr, float *yptr, float *zptr, float nx, float ny, */ return (NO_ERROR); } -static int mrisComputeLinkTerm(MRI_SURFACE *mris, double l_link, int pial) { +static int mrisComputeLinkTerm(MRI_SURFACE *mris, double l_link, int pial) +{ int vno; VERTEX *v; float dx, dy, dz, lx, ly, lz, len; @@ -13973,7 +14269,8 @@ static int mrisComputeLinkTerm(MRI_SURFACE *mris, double l_link, int pial) { Description ------------------------------------------------------*/ -static int mrisComputeTangentPlanes(MRI_SURFACE *mris) { +static int mrisComputeTangentPlanes(MRI_SURFACE *mris) +{ VECTOR *v_n, *v_e1, *v_e2, *v; int vno; VERTEX *vertex; @@ -14040,7 +14337,8 @@ static int mrisComputeTangentPlanes(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScomputeMeanCurvature(MRI_SURFACE *mris) { +int MRIScomputeMeanCurvature(MRI_SURFACE *mris) +{ VECTOR *v_n, *v_e1, *v_e2, *v_i; int vno, i, N; VERTEX *vertex, *vnb; @@ -14087,7 +14385,8 @@ int MRIScomputeMeanCurvature(MRI_SURFACE *mris) { } if (N > 0) { vertex->H = 0.5f * H / (float)N; - } else { + } + else { vertex->H = 0; } if (vertex->H > Hmax) { @@ -14131,7 +14430,8 @@ int MRIScomputeMeanCurvature(MRI_SURFACE *mris) { is from going through the central vertex). Move the vertex in the normal direction to improve the fit. ------------------------------------------------------*/ -static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) { +static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) +{ MATRIX *m_X, *m_X_inv; VECTOR *v_Y, *v_n, *v_e1, *v_e2, *v_nbr, *v_P; int vno, n; @@ -14223,7 +14523,8 @@ static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) { the square of the constant term (the distance the quadratic fit surface is from going through the central vertex) ------------------------------------------------------*/ -static double mrisComputeQuadraticCurvatureSSE(MRI_SURFACE *mris, double l_curv) { +static double mrisComputeQuadraticCurvatureSSE(MRI_SURFACE *mris, double l_curv) +{ MATRIX *m_X, *m_X_inv; VECTOR *v_Y, *v_n, *v_e1, *v_e2, *v_nbr, *v_P; int vno, n; @@ -14303,7 +14604,8 @@ static double mrisComputeQuadraticCurvatureSSE(MRI_SURFACE *mris, double l_curv) Fit a 1-d quadratic to the surface locally and move the vertex in the normal direction to improve the fit. ------------------------------------------------------*/ -static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) { +static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) +{ MATRIX *m_R, *m_R_inv; VECTOR *v_Y, *v_A, *v_n, *v_e1, *v_e2, *v_nbr; int vno, n; @@ -14391,7 +14693,8 @@ static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) { Fit a 1-d quadratic to the surface locally and move the vertex in the normal direction to improve the fit. ------------------------------------------------------*/ -static double mrisComputeQuadraticCurvatureSSE(MRI_SURFACE *mris, double l_curv) { +static double mrisComputeQuadraticCurvatureSSE(MRI_SURFACE *mris, double l_curv) +{ MATRIX *m_R, *m_R_inv; VECTOR *v_Y, *v_A, *v_n, *v_e1, *v_e2, *v_nbr; int vno, n; @@ -14466,7 +14769,8 @@ static double mrisComputeQuadraticCurvatureSSE(MRI_SURFACE *mris, double l_curv) Fit a 1-d quadratic to the surface locally and move the vertex in the normal direction to improve the fit. ------------------------------------------------------*/ -static int mrisComputeSurfaceNormalIntersectionTerm(MRI_SURFACE *mris, MHT *mht, double l_norm, double max_dist) { +static int mrisComputeSurfaceNormalIntersectionTerm(MRI_SURFACE *mris, MHT *mht, double l_norm, double max_dist) +{ int vno; double step; @@ -14877,7 +15181,8 @@ mrisComputeCurvatureGradientTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) Description ------------------------------------------------------*/ -int MRISupdateSurface(MRI_SURFACE *mris) { +int MRISupdateSurface(MRI_SURFACE *mris) +{ MRIScomputeMetricProperties(mris); MRIScomputeSecondFundamentalForm(mris); return (NO_ERROR); @@ -14889,7 +15194,8 @@ int MRISupdateSurface(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScomputeEulerNumber(MRI_SURFACE *mris, int *pnvertices, int *pnfaces, int *pnedges) { +int MRIScomputeEulerNumber(MRI_SURFACE *mris, int *pnvertices, int *pnfaces, int *pnedges) +{ int eno, nfaces, nedges, nvertices, vno, fno, vnb, i; VERTEX *v1; @@ -14929,7 +15235,8 @@ int MRIScomputeEulerNumber(MRI_SURFACE *mris, int *pnvertices, int *pnfaces, int Description ------------------------------------------------------*/ -int MRIStopologicalDefectIndex(MRI_SURFACE *mris) { +int MRIStopologicalDefectIndex(MRI_SURFACE *mris) +{ int eno, nfaces, nedges, nvertices, vno, fno, vnb, i, dno; VERTEX *v1; @@ -14970,7 +15277,8 @@ int MRIStopologicalDefectIndex(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISremoveTopologicalDefects(MRI_SURFACE *mris, float curv_thresh) { +int MRISremoveTopologicalDefects(MRI_SURFACE *mris, float curv_thresh) +{ VECTOR *v_n, *v_e1, *v_e2, *v_i; int vno, i; VERTEX *vertex, *vnb; @@ -15026,7 +15334,8 @@ int MRISremoveTopologicalDefects(MRI_SURFACE *mris, float curv_thresh) { Description ------------------------------------------------------*/ -static int mrisRemoveLink(MRI_SURFACE *mris, int vno1, int vno2) { +static int mrisRemoveLink(MRI_SURFACE *mris, int vno1, int vno2) +{ FACE *face; int vno, fno, nvalid; VERTEX *v1, *v2; @@ -15075,7 +15384,8 @@ static int mrisRemoveLink(MRI_SURFACE *mris, int vno1, int vno2) { Description ------------------------------------------------------*/ -static int mrisRemoveEdge(MRI_SURFACE *mris, int vno1, int vno2) { +static int mrisRemoveEdge(MRI_SURFACE *mris, int vno1, int vno2) +{ int i; VERTEX *v1, *v2; @@ -15101,7 +15411,8 @@ static int mrisRemoveEdge(MRI_SURFACE *mris, int vno1, int vno2) { remove this face, as well as the link two vertices if they only exist through this face. ------------------------------------------------------*/ -static int mrisRemoveFace(MRI_SURFACE *mris, int fno) { +static int mrisRemoveFace(MRI_SURFACE *mris, int fno) +{ int vno1, vno2, vno; FACE *face; @@ -15127,7 +15438,8 @@ static int mrisRemoveFace(MRI_SURFACE *mris, int fno) { Go through all the (valid) faces in vno1 and see how man valid links to vno2 exists. ------------------------------------------------------*/ -static int mrisCountValidLinks(MRI_SURFACE *mris, int vno1, int vno2) { +static int mrisCountValidLinks(MRI_SURFACE *mris, int vno1, int vno2) +{ int nvalid, fno, vno; FACE *face; VERTEX *v; @@ -15142,7 +15454,8 @@ static int mrisCountValidLinks(MRI_SURFACE *mris, int vno1, int vno2) { if (face->v[vno] == vno1) { if ((vno == VERTICES_PER_FACE - 1) && (face->v[0] == vno2)) { nvalid++; - } else if ((vno < VERTICES_PER_FACE - 1) && (face->v[vno + 1] == vno2)) { + } + else if ((vno < VERTICES_PER_FACE - 1) && (face->v[vno + 1] == vno2)) { nvalid++; } } @@ -15158,11 +15471,13 @@ static int mrisCountValidLinks(MRI_SURFACE *mris, int vno1, int vno2) { ------------------------------------------------------*/ //#define ILL_CONDITIONED 5000.0 #define ILL_CONDITIONED 500000.0 -int MRIScomputeSecondFundamentalForm(MRI_SURFACE *mris) { +int MRIScomputeSecondFundamentalForm(MRI_SURFACE *mris) +{ return (MRIScomputeSecondFundamentalFormThresholded(mris, -1)); } -int MRIScomputeSecondFundamentalFormThresholded(MRI_SURFACE *mris, double pct_thresh) { +int MRIScomputeSecondFundamentalFormThresholded(MRI_SURFACE *mris, double pct_thresh) +{ double min_k1, min_k2, max_k1, max_k2, k1_scale, k2_scale, total, thresh, orig_rsq_thresh; int bin, zbin1, zbin2, nthresh = 0; int vno, i, n, vmax, nbad = 0, niter; @@ -15182,7 +15497,8 @@ int MRIScomputeSecondFundamentalFormThresholded(MRI_SURFACE *mris, double pct_th vmean = MRIScomputeTotalVertexSpacingStats(mris, &vsigma, NULL, NULL, NULL, NULL); rsq_thresh = MIN(vmean * .25, 1.0); rsq_thresh *= rsq_thresh; - } else { + } + else { rsq_thresh = 0.0; } @@ -15283,7 +15599,8 @@ int MRIScomputeSecondFundamentalFormThresholded(MRI_SURFACE *mris, double pct_th nbad++; evalues[0] = evalues[1] = 0.0; MatrixIdentity(m_eigen->rows, m_eigen); - } else { + } + else { m_tmp1 = MatrixMultiply(m_Ut, v_z, NULL); /* Ut z */ MatrixMultiply(m_inverse, m_tmp1, v_c); /* (Ut U)^-1 Ut z */ @@ -15313,7 +15630,8 @@ int MRIScomputeSecondFundamentalFormThresholded(MRI_SURFACE *mris, double pct_th if (k1 * k2 < 0) { vertex->K = mris->Kmin; vertex->H = mris->Hmin; - } else { + } + else { vertex->K = mris->Kmax; vertex->H = mris->Hmax; } @@ -15588,7 +15906,8 @@ int MRIScomputeSecondFundamentalFormThresholded(MRI_SURFACE *mris, double pct_th max_k2); return (NO_ERROR); } -int MRIScomputeSecondFundamentalFormAtVertex(MRI_SURFACE *mris, int vno, int *vertices, int vnum) { +int MRIScomputeSecondFundamentalFormAtVertex(MRI_SURFACE *mris, int vno, int *vertices, int vnum) +{ int i, n, nbad = 0; VERTEX *vertex, *vnb; MATRIX *m_U, *m_Ut, *m_tmp1, *m_tmp2, *m_inverse; @@ -15678,7 +15997,8 @@ int MRIScomputeSecondFundamentalFormAtVertex(MRI_SURFACE *mris, int vno, int *ve { nbad++; evalues[0] = evalues[1] = 0.0; - } else { + } + else { m_tmp1 = MatrixMultiply(m_Ut, v_z, NULL); /* Ut z */ MatrixMultiply(m_inverse, m_tmp1, v_c); /* (Ut U)^-1 Ut z */ @@ -15700,7 +16020,8 @@ int MRIScomputeSecondFundamentalFormAtVertex(MRI_SURFACE *mris, int vno, int *ve if (k1 * k2 < 0) { vertex->K = mris->Kmin; vertex->H = mris->Hmin; - } else { + } + else { vertex->K = mris->Kmax; vertex->H = mris->Hmax; } @@ -15790,7 +16111,8 @@ int MRIScomputeSecondFundamentalFormAtVertex(MRI_SURFACE *mris, int vno, int *ve Description ------------------------------------------------------*/ -int MRISuseAreaErrors(MRI_SURFACE *mris) { +int MRISuseAreaErrors(MRI_SURFACE *mris) +{ int vno, fno, n; float area, orig_area; FACE *face; @@ -15824,7 +16146,8 @@ int MRISuseAreaErrors(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISuseGaussianCurvature(MRI_SURFACE *mris) { +int MRISuseGaussianCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; @@ -15844,7 +16167,8 @@ int MRISuseGaussianCurvature(MRI_SURFACE *mris) { int MRISuseMeanCurvature(MRI_SURFACE *mris) Set vertex->curv = vertex->H ; ------------------------------------------------------*/ -int MRISuseMeanCurvature(MRI_SURFACE *mris) { +int MRISuseMeanCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; @@ -15867,7 +16191,8 @@ int MRISuseMeanCurvature(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISusePrincipalCurvature(MRI_SURFACE *mris) { +int MRISusePrincipalCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; @@ -15884,7 +16209,8 @@ int MRISusePrincipalCurvature(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISuseK1Curvature(MRI_SURFACE *mris) { +int MRISuseK1Curvature(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; @@ -15910,7 +16236,8 @@ int MRISuseK1Curvature(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISuseK2Curvature(MRI_SURFACE *mris) { +int MRISuseK2Curvature(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; @@ -15936,7 +16263,8 @@ int MRISuseK2Curvature(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISusePrincipalCurvatureFunction(MRI_SURFACE *pmris, float (*f)(float k1, float k2)) { +int MRISusePrincipalCurvatureFunction(MRI_SURFACE *pmris, float (*f)(float k1, float k2)) +{ // // PRECONDITIONS // o The principal curvatures k1 and k2 for each vertex point on the @@ -15988,7 +16316,8 @@ int MRISusePrincipalCurvatureFunction(MRI_SURFACE *pmris, float (*f)(float k1, f Drury and Van Essen: ICI = 56 (lh) and 54 (rh) FI = 500 (lh) and 520 (rh) ------------------------------------------------------*/ -int MRIScomputeCurvatureIndices(MRI_SURFACE *mris, double *pici, double *pfi) { +int MRIScomputeCurvatureIndices(MRI_SURFACE *mris, double *pici, double *pfi) +{ int vno; VERTEX *vertex; double k1, k2, ici, fi, area, Kmax, Kmin; @@ -16024,7 +16353,8 @@ int MRIScomputeCurvatureIndices(MRI_SURFACE *mris, double *pici, double *pfi) { Description ------------------------------------------------------*/ -double MRISmaxRadius(MRI_SURFACE *mris) { +double MRISmaxRadius(MRI_SURFACE *mris) +{ double radius; int vno, n; VERTEX *vertex; @@ -16098,7 +16428,8 @@ double MRISmaxRadius(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisComputeSurfaceDimensions(MRI_SURFACE *mris) { +static int mrisComputeSurfaceDimensions(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; double x, y, z, xlo, ylo, zlo, xhi, yhi, zhi; @@ -16153,7 +16484,8 @@ static int mrisComputeSurfaceDimensions(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -double MRISaverageRadius(MRI_SURFACE *mris) { +double MRISaverageRadius(MRI_SURFACE *mris) +{ double radius; int vno, n; VERTEX *vertex; @@ -16222,7 +16554,8 @@ double MRISaverageRadius(MRI_SURFACE *mris) { Descripton ------------------------------------------------------*/ -double MRISaverageCanonicalRadius(MRI_SURFACE *mris) { +double MRISaverageCanonicalRadius(MRI_SURFACE *mris) +{ double radius; int vno, n; VERTEX *vertex; @@ -16288,7 +16621,8 @@ double MRISaverageCanonicalRadius(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISinflateBrain(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +int MRISinflateBrain(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int n_averages, n, write_iterations, niterations; double delta_t = 0.0, rms_height, desired_rms_height, sse, l_dist; @@ -16303,7 +16637,8 @@ int MRISinflateBrain(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { sprintf(fname, "%s.out", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -16442,7 +16777,8 @@ int MRISinflateBrain(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { Description ------------------------------------------------------*/ -int MRISinflateToSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +int MRISinflateToSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int n_averages, n, write_iterations, niterations, base_averages; double delta_t = 0.0, rms_radial_error, sse, base_dt; MHT *mht_v_current = NULL; @@ -16461,7 +16797,8 @@ int MRISinflateToSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { if (!parms->fp) { if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } @@ -16476,7 +16813,8 @@ int MRISinflateToSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { sprintf(fname, "%s.out", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -16604,7 +16942,8 @@ int MRISinflateToSphere(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { } /* project onto the sphere of radius DEFAULT_RADIUS */ -static void sphericalProjection(float xs, float ys, float zs, float *xd, float *yd, float *zd) { +static void sphericalProjection(float xs, float ys, float zs, float *xd, float *yd, float *zd) +{ double dist, lambda; dist = sqrt(SQR(xs) + SQR(ys) + SQR(zs)); @@ -16626,7 +16965,8 @@ static void sphericalProjection(float xs, float ys, float zs, float *xd, float * *zd = zs * lambda; } -int MRISsmoothOnSphere(MRIS *mris, int niters) { +int MRISsmoothOnSphere(MRIS *mris, int niters) +{ int n, p; float x, y, z; VERTEX *v, *vp; @@ -16648,7 +16988,8 @@ int MRISsmoothOnSphere(MRIS *mris, int niters) { v->ty = v->y; v->tz = v->z; DiagBreak(); - } else { + } + else { v->tx = x / v->vnum; v->ty = y / v->vnum; v->tz = z / v->vnum; @@ -16670,7 +17011,8 @@ int MRISsmoothOnSphere(MRIS *mris, int niters) { return NO_ERROR; } -static int mrisSphericalProjection(MRIS *mris) { +static int mrisSphericalProjection(MRIS *mris) +{ int n; VERTEX *v; // fprintf(stderr,"spherical projection\n"); @@ -16715,7 +17057,8 @@ static int mrisSphericalProjection(MRIS *mris) { return NO_ERROR; } -static float computeArea(MRIS *mris, int fac, int n) { +static float computeArea(MRIS *mris, int fac, int n) +{ int n0, n1; face_type *f; float v0[3], v1[3], d1, d2, d3, dot, area; @@ -16742,7 +17085,8 @@ static float computeArea(MRIS *mris, int fac, int n) { if (dot < 0.0f) /* not in same direction, area < 0 and reverse n */ { area = -sqrt(d1 * d1 + d2 * d2 + d3 * d3); - } else { + } + else { area = sqrt(d1 * d1 + d2 * d2 + d3 * d3); } @@ -16752,7 +17096,8 @@ static float computeArea(MRIS *mris, int fac, int n) { /* preserve the topology of the deformation field this constraint is too strong - useless! */ -int mrisApplyGradientPositiveAreaPreserving(MRI_SURFACE *mris, double dt) { +int mrisApplyGradientPositiveAreaPreserving(MRI_SURFACE *mris, double dt) +{ int vno, nvertices, n; VERTEX *v; float x, y, z, dx, dy, dz; @@ -16841,18 +17186,21 @@ int mrisApplyGradientPositiveAreaPreserving(MRI_SURFACE *mris, double dt) { constrain the gradient triangle by triangle but do not ensure that the final gradient is topology preserving */ -int mrisApplyGradientPositiveAreaMaximizing(MRI_SURFACE *mris, double dt) { +int mrisApplyGradientPositiveAreaMaximizing(MRI_SURFACE *mris, double dt) +{ return mrisApplyGradientPositiveAreaPreserving(mris, dt); } -int MRISapplyGradient(MRI_SURFACE *mris, double dt) { +int MRISapplyGradient(MRI_SURFACE *mris, double dt) +{ int vno, nvertices; nvertices = mris->nvertices; MRISstoreCurrentPositions(mris); if (mris->status == MRIS_RIGID_BODY) { MRISrotate(mris, mris, dt * mris->alpha, dt * mris->beta, dt * mris->gamma); - } else { + } + else { #ifdef HAVE_OPENMP #pragma omp parallel for schedule(static, 1) #endif @@ -16880,7 +17228,8 @@ int MRISapplyGradient(MRI_SURFACE *mris, double dt) { Description ------------------------------------------------------*/ -static int mrisClearDistances(MRI_SURFACE *mris) { +static int mrisClearDistances(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -16902,7 +17251,8 @@ static int mrisClearDistances(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISclearGradient(MRI_SURFACE *mris) { +int MRISclearGradient(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -16926,7 +17276,8 @@ int MRISclearGradient(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisClearExtraGradient(MRI_SURFACE *mris) { +static int mrisClearExtraGradient(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -16950,7 +17301,8 @@ static int mrisClearExtraGradient(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisClearMomentum(MRI_SURFACE *mris) { +static int mrisClearMomentum(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -16974,7 +17326,8 @@ static int mrisClearMomentum(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -double MRIStotalVariationDifference(MRI_SURFACE *mris) { +double MRIStotalVariationDifference(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; double var, delta; @@ -17000,7 +17353,8 @@ double MRIStotalVariationDifference(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -double MRIStotalVariation(MRI_SURFACE *mris) { +double MRIStotalVariation(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; double var, delta; @@ -17025,7 +17379,8 @@ double MRIStotalVariation(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -double MRIScurvatureError(MRI_SURFACE *mris, double Kd) { +double MRIScurvatureError(MRI_SURFACE *mris, double Kd) +{ int vno, nvertices, n; VERTEX *v; double Kerror, deltaK; @@ -17056,7 +17411,8 @@ double MRIScurvatureError(MRI_SURFACE *mris, double Kd) { Description ------------------------------------------------------*/ -int MRISrestoreOldPositions(MRI_SURFACE *mris) { +int MRISrestoreOldPositions(MRI_SURFACE *mris) +{ #if 1 return (MRISrestoreVertexPositions(mris, TMP_VERTICES)); #else @@ -17085,7 +17441,8 @@ int MRISrestoreOldPositions(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISstoreCurrentPositions(MRI_SURFACE *mris) { +int MRISstoreCurrentPositions(MRI_SURFACE *mris) +{ #if 1 return (MRISsaveVertexPositions(mris, TMP_VERTICES)); #else @@ -17143,7 +17500,8 @@ mrisStoreCurrentGradient(MRI_SURFACE *mris) Description ------------------------------------------------------*/ -int MRISstoreMeanCurvature(MRI_SURFACE *mris) { +int MRISstoreMeanCurvature(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -17165,7 +17523,8 @@ int MRISstoreMeanCurvature(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISstoreMetricProperties(MRI_SURFACE *mris) { +int MRISstoreMetricProperties(MRI_SURFACE *mris) +{ int vno, nvertices, fno, ano, n; VERTEX *v; FACE *f; @@ -17209,7 +17568,8 @@ int MRISstoreMetricProperties(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISrestoreMetricProperties(MRI_SURFACE *mris) { +int MRISrestoreMetricProperties(MRI_SURFACE *mris) +{ int vno, nvertices, fno, ano, n; VERTEX *v; FACE *f; @@ -17246,7 +17606,8 @@ int MRISrestoreMetricProperties(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISvalidVertices(MRI_SURFACE *mris) { +int MRISvalidVertices(MRI_SURFACE *mris) +{ int vno, nvertices, nvalid; nvertices = mris->nvertices; @@ -17264,7 +17625,8 @@ int MRISvalidVertices(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISmarkedVertices(MRI_SURFACE *mris) { +int MRISmarkedVertices(MRI_SURFACE *mris) +{ int vno, nvertices, nmarked; nvertices = mris->nvertices; @@ -17283,7 +17645,8 @@ int MRISmarkedVertices(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisValidFaces(MRI_SURFACE *mris) { +static int mrisValidFaces(MRI_SURFACE *mris) +{ int fno, nfaces, nvalid; nfaces = mris->nfaces; @@ -17305,7 +17668,8 @@ static int mrisValidFaces(MRI_SURFACE *mris) { name x y z ------------------------------------------------------*/ -int MRISreadTetherFile(MRI_SURFACE *mris, const char *fname, float radius) { +int MRISreadTetherFile(MRI_SURFACE *mris, const char *fname, float radius) +{ int l; float cx, cy, cz; FILE *fp; @@ -17348,7 +17712,8 @@ int MRISreadTetherFile(MRI_SURFACE *mris, const char *fname, float radius) { name x y z ------------------------------------------------------*/ -static int mrisLabelVertices(MRI_SURFACE *mris, float cx, float cy, float cz, int label, float radius) { +static int mrisLabelVertices(MRI_SURFACE *mris, float cx, float cy, float cz, int label, float radius) +{ VERTEX *v; float xd, yd, zd, d; int vno; @@ -17382,7 +17747,8 @@ static int mrisLabelVertices(MRI_SURFACE *mris, float cx, float cy, float cz, in ------------------------------------------------------*/ #define K_A 0.4f static float kernel[] = {K_A, 0.25f, 0.25f - K_A / 2.0f}; -int MRISsmoothCurvatures(MRI_SURFACE *mris, int niterations) { +int MRISsmoothCurvatures(MRI_SURFACE *mris, int niterations) +{ int vno, i, vn; double g, H, norm; VERTEX *vertex; @@ -17791,7 +18157,8 @@ mrisComputeCurvatureTerm(MRI_SURFACE *mris, double l_curv) name x y z ------------------------------------------------------*/ -static int mrisComputeConvexityTerm(MRI_SURFACE *mris, double l_convex) { +static int mrisComputeConvexityTerm(MRI_SURFACE *mris, double l_convex) +{ int vno; if (FZERO(l_convex)) { @@ -17863,7 +18230,8 @@ static int mrisComputeConvexityTerm(MRI_SURFACE *mris, double l_convex) { name x y z ------------------------------------------------------*/ -static int mrisComputeNormalSpringTerm(MRI_SURFACE *mris, double l_spring) { +static int mrisComputeNormalSpringTerm(MRI_SURFACE *mris, double l_spring) +{ int vno, n, m; VERTEX *vertex, *vn; float sx, sy, sz, nx, ny, nz, nc, x, y, z; @@ -17928,7 +18296,8 @@ static int mrisComputeNormalSpringTerm(MRI_SURFACE *mris, double l_spring) { name x y z ------------------------------------------------------*/ -static int mrisComputeTangentialSpringTerm(MRI_SURFACE *mris, double l_spring) { +static int mrisComputeTangentialSpringTerm(MRI_SURFACE *mris, double l_spring) +{ int vno, n, m; VERTEX *v, *vn; float sx, sy, sz, x, y, z, nc; @@ -17998,7 +18367,8 @@ static int mrisComputeTangentialSpringTerm(MRI_SURFACE *mris, double l_spring) { name x y z ------------------------------------------------------*/ -static int mrisComputeNonlinearTangentialSpringTerm(MRI_SURFACE *mris, double l_spring, double min_dist) { +static int mrisComputeNonlinearTangentialSpringTerm(MRI_SURFACE *mris, double l_spring, double min_dist) +{ int vno, m, n; VERTEX *v, *vn; float sx, sy, sz, x, y, z, dx, dy, dz; @@ -18059,7 +18429,8 @@ static int mrisComputeNonlinearTangentialSpringTerm(MRI_SURFACE *mris, double l_ return (NO_ERROR); } -static double mrisComputeDuraError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisComputeDuraError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double dura_thresh = parms->dura_thresh, sse; MRI *mri_dura = parms->mri_dura; int vno; @@ -18097,7 +18468,8 @@ static double mrisComputeDuraError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) return (sse); } -static int mrisComputeDuraTerm(MRI_SURFACE *mris, double l_dura, MRI *mri_dura, double dura_thresh) { +static int mrisComputeDuraTerm(MRI_SURFACE *mris, double l_dura, MRI *mri_dura, double dura_thresh) +{ int vno; VERTEX *v; float x, y, z, nx, ny, nz, dx, dy, dz; @@ -18213,7 +18585,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, double sigma_global, - INTEGRATION_PARMS *parms) { + INTEGRATION_PARMS *parms) +{ int vno; VERTEX *v; float x, y, z, nx, ny, nz, dx, dy, dz; @@ -18265,7 +18638,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) { MRIwrite(mri_interior, "int.mgz"); } - } else { + } + else { mri_interior = NULL; } for (vno = 0; vno < mris->nvertices; vno++) { @@ -18317,7 +18691,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, MRISsurfaceRASToVoxelCached(mris, mri_brain, xw, yw, zw, &xw, &yw, &zw); MRIsampleVolume(mri_brain, xw, yw, zw, &val); val_outside += k * val; - } else { + } + else { DiagBreak(); } @@ -18334,7 +18709,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, MRIsampleVolume(mri_brain, xw, yw, zw, &val); val_inside += k * val; ktotal_inside += k; - } else { + } + else { DiagBreak(); } } @@ -18344,7 +18720,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, if (ktotal_outside > 0) { val_outside /= (double)ktotal_outside; } - } else // don't compute gradient - assume + } + else // don't compute gradient - assume { val_outside = parms->grad_dir; val_inside = -parms->grad_dir; @@ -18355,13 +18732,15 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, if (!FZERO(delI)) { delI /= fabs(delI); - } else { + } + else { delI = -1; /* intensities tend to increase inwards */ } if (delV > 5) { delV = 5; - } else if (delV < -5) { + } + else if (delV < -5) { delV = -5; } @@ -18435,7 +18814,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, return (NO_ERROR); } -static int mrisComputeTargetLocationTerm(MRI_SURFACE *mris, double l_location, INTEGRATION_PARMS *parms) { +static int mrisComputeTargetLocationTerm(MRI_SURFACE *mris, double l_location, INTEGRATION_PARMS *parms) +{ int vno; VERTEX *v; double dx, dy, dz, norm; @@ -18501,7 +18881,8 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, double sigma_global, float weight30, float weight5, - INTEGRATION_PARMS *parms) { + INTEGRATION_PARMS *parms) +{ int vno; VERTEX *v; float x, y, z, nx, ny, nz, dx, dy, dz; @@ -18520,7 +18901,8 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) { MRIwrite(mri_interior, "int.mgz"); } - } else { + } + else { mri_interior = NULL; } for (vno = 0; vno < mris->nvertices; vno++) { @@ -18569,7 +18951,8 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, MRIsampleVolume(mri_30, xw, yw, zw, &val); val_outside += k * val; ktotal_outside += k; - } else { + } + else { DiagBreak(); } @@ -18584,7 +18967,8 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, MRIsampleVolume(mri_30, xw, yw, zw, &val); val_inside += k * val; ktotal_inside += k; - } else { + } + else { DiagBreak(); } } @@ -18594,7 +18978,8 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, if (ktotal_outside > 0) { val_outside /= (double)ktotal_outside; } - } else // don't compute gradient - assume + } + else // don't compute gradient - assume { val_outside = parms->grad_dir; val_inside = -parms->grad_dir; @@ -18605,13 +18990,15 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, if (!FZERO(delI)) { delI /= fabs(delI); - } else { + } + else { delI = -1; // intensity tends to increase inwards for flash30 } if (delV > 5) { delV = 5; - } else if (delV < -5) { + } + else if (delV < -5) { delV = -5; } @@ -18722,7 +19109,8 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, if (ktotal_outside > 0) { val_outside /= (double)ktotal_outside; } - } else // don't compute gradient - assume + } + else // don't compute gradient - assume { val_outside = parms->grad_dir; val_inside = -parms->grad_dir; @@ -18733,13 +19121,15 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, if (!FZERO(delI)) { delI /= fabs(delI); - } else { + } + else { delI = 0; } if (delV > 5) { delV = 5; - } else if (delV < -5) { + } + else if (delV < -5) { delV = -5; } @@ -18806,7 +19196,8 @@ static int mrisComputeIntensityTerm_mef(MRI_SURFACE *mris, } #if 1 -static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MRI *mri_brain, MRI *mri_smooth) { +static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MRI *mri_brain, MRI *mri_smooth) +{ int vno; VERTEX *v; float x, y, z, nx, ny, nz; @@ -18869,7 +19260,8 @@ static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MR if (mag_outside > mag_inside) /* gradients suggest edge is outwards */ { val_dist = val_outside - v->val; - } else /* gradients suggest edge is inwards */ + } + else /* gradients suggest edge is inwards */ { val_dist = val_inside - v->val; } @@ -18889,7 +19281,8 @@ static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MR if (((mag_inside < mag_outside) && dn > 0) || ((mag_inside > mag_outside) && dn < 0)) { val_dist = 0; } - } else /* current point is dimmer than target */ + } + else /* current point is dimmer than target */ { /* dn > 0 implies should move out, but gradient mag points in */ if (((mag_inside > mag_outside) && dn > 0) || ((mag_inside < mag_outside) && dn < 0)) { @@ -18929,7 +19322,8 @@ static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MR return (NO_ERROR); } #else -static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MRI *mri_brain, MRI *mri_smooth) { +static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MRI *mri_brain, MRI *mri_smooth) +{ int vno; VERTEX *v; float x, y, z, nx, ny, nz; @@ -19000,7 +19394,8 @@ static int mrisComputeIntensityGradientTerm(MRI_SURFACE *mris, double l_grad, MR Description Apply a uniform outward expansion force. ------------------------------------------------------*/ -static int mrisComputeSphereTerm(MRI_SURFACE *mris, double l_sphere, float radius) { +static int mrisComputeSphereTerm(MRI_SURFACE *mris, double l_sphere, float radius) +{ int vno; VERTEX *v; float r, x, y, z, x0, y0, z0; @@ -19134,7 +19529,8 @@ static int mrisComputeSphereTerm(MRI_SURFACE *mris, double l_sphere, float radiu Description Apply a uniform outward expansion force. ------------------------------------------------------*/ -static int mrisComputeExpansionTerm(MRI_SURFACE *mris, double l_expand) { +static int mrisComputeExpansionTerm(MRI_SURFACE *mris, double l_expand) +{ int vno; VERTEX *v; @@ -19161,7 +19557,8 @@ static int mrisComputeExpansionTerm(MRI_SURFACE *mris, double l_expand) { return (NO_ERROR); } -static int mrisComputeBorderTerm(MRI_SURFACE *mris, double l_border) { +static int mrisComputeBorderTerm(MRI_SURFACE *mris, double l_border) +{ int vno, n, m; VERTEX *v, *vn; float sx, sy, sz, x, y, z, dist_scale; @@ -19172,7 +19569,8 @@ static int mrisComputeBorderTerm(MRI_SURFACE *mris, double l_border) { if (mris->patch) { dist_scale = 1.0; - } else { + } + else { dist_scale = sqrt(mris->orig_area / mris->total_area); } @@ -19237,7 +19635,8 @@ static int mrisComputeBorderTerm(MRI_SURFACE *mris, double l_border) { MRIScopyMarked3ToMarked(mris); return (NO_ERROR); } -static int mrisComputeMaxSpringTerm(MRI_SURFACE *mris, double l_max_spring) { +static int mrisComputeMaxSpringTerm(MRI_SURFACE *mris, double l_max_spring) +{ int vno, n, m, m_max; VERTEX *v, *vn; float dx, dy, dz, x, y, z, dist_scale, dist, max_dist; @@ -19248,7 +19647,8 @@ static int mrisComputeMaxSpringTerm(MRI_SURFACE *mris, double l_max_spring) { if (mris->patch) { dist_scale = l_max_spring; - } else { + } + else { dist_scale = l_max_spring * sqrt(mris->orig_area / mris->total_area); } @@ -19315,7 +19715,8 @@ static int mrisComputeMaxSpringTerm(MRI_SURFACE *mris, double l_max_spring) { name x y z ------------------------------------------------------*/ -static int mrisComputeSpringTerm(MRI_SURFACE *mris, double l_spring) { +static int mrisComputeSpringTerm(MRI_SURFACE *mris, double l_spring) +{ int vno, n, m; VERTEX *v, *vn; float sx, sy, sz, x, y, z, dist_scale; @@ -19327,7 +19728,8 @@ static int mrisComputeSpringTerm(MRI_SURFACE *mris, double l_spring) { #if METRIC_SCALE if (mris->patch) { dist_scale = 1.0; - } else { + } + else { dist_scale = sqrt(mris->orig_area / mris->total_area); } #else @@ -19393,7 +19795,8 @@ static int mrisComputeSpringTerm(MRI_SURFACE *mris, double l_spring) { has the original (i.e. after global rotational alignment) spherical coordinates in the TMP2_VERTICES ------------------------------------------------------*/ -static int mrisComputeLaplacianTerm(MRI_SURFACE *mris, double l_lap) { +static int mrisComputeLaplacianTerm(MRI_SURFACE *mris, double l_lap) +{ int vno, n, m; VERTEX *v, *vn; float x, y, z, vx, vy, vz, vnx, vny, vnz, dx, dy, dz; @@ -19646,7 +20049,8 @@ mrisComputeNormalizedSpringTerm(MRI_SURFACE *mris, double l_spring) return(NO_ERROR) ; } #else -static int mrisComputeNormalizedSpringTerm(MRI_SURFACE *const mris, double const l_spring) { +static int mrisComputeNormalizedSpringTerm(MRI_SURFACE *const mris, double const l_spring) +{ if (FZERO(l_spring)) { return (NO_ERROR); } @@ -19655,7 +20059,8 @@ static int mrisComputeNormalizedSpringTerm(MRI_SURFACE *const mris, double const #if METRIC_SCALE if (mris->patch) { dist_scale_init = 1.0; - } else { + } + else { dist_scale_init = sqrt(mris->orig_area / mris->total_area); } #else @@ -19740,7 +20145,8 @@ static int mrisComputeNormalizedSpringTerm(MRI_SURFACE *const mris, double const Description Compute the folding of the surface. ------------------------------------------------------*/ -double MRIScomputeFolding(MRI_SURFACE *mris) { +double MRIScomputeFolding(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; double k1, k2, folding, area; @@ -19768,7 +20174,8 @@ double MRIScomputeFolding(MRI_SURFACE *mris) { Description Compute the effects of the gradient of the distance term ------------------------------------------------------*/ -static int mrisComputeDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ float l_dist, scale, max_del, norm; int vno, tno; // int max_n, max_v ; @@ -19778,12 +20185,14 @@ static int mrisComputeDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) if ((cp = getenv("VDIAG1")) != NULL) { diag_vno1 = atoi(cp); - } else { + } + else { diag_vno1 = -1; } if ((cp = getenv("VDIAG2")) != NULL) { diag_vno2 = atoi(cp); - } else { + } + else { diag_vno2 = -1; } @@ -19801,9 +20210,11 @@ static int mrisComputeDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) #if METRIC_SCALE if (mris->patch) { scale = 1.0f; - } else if (mris->status == MRIS_PARAMETERIZED_SPHERE || mris->status == MRIS_SPHERE) { + } + else if (mris->status == MRIS_PARAMETERIZED_SPHERE || mris->status == MRIS_SPHERE) { scale = sqrt(mris->orig_area / mris->total_area); - } else + } + else scale = mris->neg_area < mris->total_area ? sqrt(mris->orig_area / (mris->total_area - mris->neg_area)) : sqrt(mris->orig_area / mris->total_area); #else @@ -19963,7 +20374,8 @@ static int mrisComputeDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) Description Compute the effects of the gradient of the distance term ------------------------------------------------------*/ -static int mrisComputeNonlinearDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeNonlinearDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ VECTOR *v_y, *v_delta, *v_n; float l_dist, d0, dt, delta, nc, scale, norm, ratio; VERTEX *v, *vn; @@ -19982,9 +20394,11 @@ static int mrisComputeNonlinearDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS #if METRIC_SCALE if (mris->patch) { scale = 1.0f; - } else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { + } + else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { scale = sqrt(mris->orig_area / mris->total_area); - } else + } + else scale = mris->neg_area < mris->total_area ? sqrt(mris->orig_area / (mris->total_area - mris->neg_area)) : sqrt(mris->orig_area / mris->total_area); #else @@ -20069,7 +20483,8 @@ static int mrisComputeNonlinearDistanceTerm(MRI_SURFACE *mris, INTEGRATION_PARMS } /*-----------------------------------------------------*/ -int mrisLogIntegrationParms(FILE *fp, MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +int mrisLogIntegrationParms(FILE *fp, MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ char *cp, host_name[STRLEN]; static int first = 1; @@ -20080,7 +20495,8 @@ int mrisLogIntegrationParms(FILE *fp, MRI_SURFACE *mris, INTEGRATION_PARMS *parm cp = getenv("HOST"); if (cp) { strcpy(host_name, cp); - } else { + } + else { strcpy(host_name, "unknown"); } @@ -20273,7 +20689,8 @@ int mrisLogIntegrationParms(FILE *fp, MRI_SURFACE *mris, INTEGRATION_PARMS *parm Description ------------------------------------------------------*/ -static int mrisWriteSnapshots(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) { +static int mrisWriteSnapshots(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) +{ char base_name[STRLEN]; MRISsaveVertexPositions(mris, TMP_VERTICES); @@ -20302,7 +20719,8 @@ static int mrisWriteSnapshots(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t Description ------------------------------------------------------*/ -static int mrisWriteSnapshot(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) { +static int mrisWriteSnapshot(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) +{ char fname[STRLEN], path[STRLEN], base_name[STRLEN], *cp, *hemi; switch (mris->hemisphere) { @@ -20325,7 +20743,8 @@ static int mrisWriteSnapshot(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) *cp = 0; sprintf(fname, "%s%4.4d.geo", base_name, t); *cp = '.'; - } else { + } + else { sprintf(fname, "%s%4.4d", base_name, t); } #if 1 @@ -20334,7 +20753,8 @@ static int mrisWriteSnapshot(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) } if (mris->patch) { MRISwritePatch(mris, fname); - } else { + } + else { if (parms->l_thick_normal > 0 || parms->l_thick_parallel > 0 || parms->l_thick_min > 0 || parms->l_thick_spring) { int vno; MRI *mri_vector; @@ -20364,7 +20784,8 @@ static int mrisWriteSnapshot(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) printf("writing vector field to %s\n", fname); MRIwrite(mri_vector, fname); MRIfree(&mri_vector); - } else + } + else MRISwrite(mris, fname); } @@ -20410,7 +20831,8 @@ static int mrisWriteSnapshot(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int t) Description ------------------------------------------------------*/ -static double mrisComputeDistanceError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisComputeDistanceError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int vno, max_v, max_n, err_cnt, max_errs; double dist_scale, sse_dist, max_del; static int first = 1; @@ -20418,9 +20840,11 @@ static double mrisComputeDistanceError(MRI_SURFACE *mris, INTEGRATION_PARMS *par #if METRIC_SCALE if (mris->patch) { dist_scale = 1.0; - } else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { + } + else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { dist_scale = sqrt(mris->orig_area / mris->total_area); - } else + } + else dist_scale = mris->neg_area < mris->total_area ? sqrt(mris->orig_area / (mris->total_area - mris->neg_area)) : sqrt(mris->orig_area / mris->total_area); #else @@ -20518,15 +20942,18 @@ static double mrisComputeDistanceError(MRI_SURFACE *mris, INTEGRATION_PARMS *par } #ifdef FS_CUDA -static float mrisComputeDistanceErrorCUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *mrisc, INTEGRATION_PARMS *parms) { +static float mrisComputeDistanceErrorCUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *mrisc, INTEGRATION_PARMS *parms) +{ double dist_scale, sse_dist; #if METRIC_SCALE if (mris->patch) { dist_scale = 1.0; - } else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { + } + else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { dist_scale = sqrt(mris->orig_area / mris->total_area); - } else + } + else dist_scale = mris->neg_area < mris->total_area ? sqrt(mris->orig_area / (mris->total_area - mris->neg_area)) : sqrt(mris->orig_area / mris->total_area); #else @@ -20541,7 +20968,8 @@ static float mrisComputeDistanceErrorCUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *m if (parms->vsmoothness == NULL && parms->dist_error == NULL) { sse_dist = (double)(MRISCcomputeDistanceError(mrisc, dist_scale)); - } else { + } + else { sse_dist = mrisComputeDistanceError(mris, parms); } @@ -20560,7 +20988,8 @@ static float mrisComputeDistanceErrorCUDA(MRI_SURFACE *mris, MRI_CUDA_SURFACE *m Description ------------------------------------------------------*/ -static double mrisComputeNonlinearDistanceSSE(MRI_SURFACE *mris) { +static double mrisComputeNonlinearDistanceSSE(MRI_SURFACE *mris) +{ VERTEX *v; int vno, n, nvertices, max_v, max_n; double dist_scale, sse_dist, delta, v_sse, max_del, ratio; @@ -20568,9 +20997,11 @@ static double mrisComputeNonlinearDistanceSSE(MRI_SURFACE *mris) { #if METRIC_SCALE if (mris->patch) { dist_scale = 1.0; - } else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { + } + else if (mris->status == MRIS_PARAMETERIZED_SPHERE) { dist_scale = sqrt(mris->orig_area / mris->total_area); - } else + } + else dist_scale = mris->neg_area < mris->total_area ? sqrt(mris->orig_area / (mris->total_area - mris->neg_area)) : sqrt(mris->orig_area / mris->total_area); #else @@ -20612,7 +21043,8 @@ static double mrisComputeNonlinearDistanceSSE(MRI_SURFACE *mris) { indicate the correspondence between white and pial, and the canonical spherical ones v->c[xyz] have the ?h.sphere in them. */ -int MRISmeasureThicknessFromCorrespondence(MRI_SURFACE *mris, MHT *mht, float max_thick) { +int MRISmeasureThicknessFromCorrespondence(MRI_SURFACE *mris, MHT *mht, float max_thick) +{ int vno, alloced; VERTEX *v; float xw, yw, zw, dx, dy, dz, xp, yp, zp; @@ -20620,7 +21052,8 @@ int MRISmeasureThicknessFromCorrespondence(MRI_SURFACE *mris, MHT *mht, float ma if (mht == NULL) { mht = MHTfillTableAtResolution(mris, NULL, CANONICAL_VERTICES, 1.0); // to lookup closest face alloced = 1; - } else + } + else alloced = 0; for (vno = 0; vno < mris->nvertices; vno++) { @@ -20649,7 +21082,8 @@ int MRISmeasureThicknessFromCorrespondence(MRI_SURFACE *mris, MHT *mht, float ma Description ------------------------------------------------------*/ -static double mrisComputeThicknessSmoothnessEnergy(MRI_SURFACE *mris, double l_tsmooth, INTEGRATION_PARMS *parms) { +static double mrisComputeThicknessSmoothnessEnergy(MRI_SURFACE *mris, double l_tsmooth, INTEGRATION_PARMS *parms) +{ int vno, n; double sse_tsmooth, v_sse, dn, dx, dy, dz, d0; float xp, yp, zp; @@ -20685,7 +21119,8 @@ static double mrisComputeThicknessSmoothnessEnergy(MRI_SURFACE *mris, double l_t return (sse_tsmooth); } static float mrisSampleMinimizationEnergy( - MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) { + MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) +{ float xw, yw, zw, dx, dy, dz, thick_sq, xp, yp, zp; project_point_onto_sphere(cx, cy, cz, mris->radius, &cx, &cy, &cz); @@ -20699,7 +21134,8 @@ static float mrisSampleMinimizationEnergy( return (thick_sq); } -static int project_point_onto_sphere(float cx, float cy, float cz, float radius, float *pcx, float *pcy, float *pcz) { +static int project_point_onto_sphere(float cx, float cy, float cz, float radius, float *pcx, float *pcy, float *pcz) +{ float x2, y2, z2, d, dist, dx, dy, dz; x2 = cx * cx; @@ -20708,7 +21144,8 @@ static int project_point_onto_sphere(float cx, float cy, float cz, float radius, dist = sqrt(x2 + y2 + z2); if (FZERO(dist)) { d = 0; - } else { + } + else { d = 1 - radius / dist; } dx = d * cx; @@ -20720,7 +21157,8 @@ static int project_point_onto_sphere(float cx, float cy, float cz, float radius, return (NO_ERROR); } -static float mrisSampleParallelEnergyAtVertex(MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms) { +static float mrisSampleParallelEnergyAtVertex(MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms) +{ float xw, yw, zw, xp, yp, zp, dx, dy, dz, dxn, dyn, dzn, len, dxn_total, dyn_total, dzn_total; int n, num; double sse; @@ -20770,7 +21208,8 @@ static float mrisSampleParallelEnergyAtVertex(MRI_SURFACE *mris, VERTEX *v, INTE MRISvertexCoord2XYZ_float(vn, WHITE_VERTICES, &xw, &yw, &zw); if (vn->fno >= 0) { MRISsampleFaceCoords(mris, vn->fno, vn->x, vn->y, vn->z, PIAL_VERTICES, CANONICAL_VERTICES, &xp, &yp, &zp); - } else { + } + else { MRISsampleFaceCoordsCanonical((MHT *)(parms->mht), mris, vn->x, vn->y, vn->z, PIAL_VERTICES, &xp, &yp, &zp); } @@ -20813,7 +21252,8 @@ static float mrisSampleParallelEnergyAtVertex(MRI_SURFACE *mris, VERTEX *v, INTE return (sse); } static float mrisSampleParallelEnergy( - MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) { + MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) +{ int fno = 0, old_fno, num; double sse, fdist; FACE *face; @@ -20857,7 +21297,8 @@ static float mrisSampleParallelEnergy( } static float mrisSampleNormalEnergy( - MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) { + MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) +{ float dx, dy, dz, len, xw, yw, zw, xp, yp, zp, pnx, pny, pnz; double sse; @@ -20901,7 +21342,8 @@ static float mrisSampleNormalEnergy( } static float mrisSampleSpringEnergy( - MRI_SURFACE *mris, VERTEX *v, float cx, float cy, float cz, INTEGRATION_PARMS *parms) { + MRI_SURFACE *mris, VERTEX *v, float cx, float cy, float cz, INTEGRATION_PARMS *parms) +{ float xn, yn, zn, xp, yp, zp, xc, yc, zc; double sse, fdist, vdist = mris->avg_vertex_dist; int n, num, fno; @@ -21067,7 +21509,8 @@ ashburnerTriangleEnergy(MRI_SURFACE *mris, int fno, double lambda) #else // this version isn't working yet, not sure why -static double ashburnerTriangleEnergy(MRI_SURFACE *mris, int fno, double lambda) { +static double ashburnerTriangleEnergy(MRI_SURFACE *mris, int fno, double lambda) +{ static MATRIX *_m_x[_MAX_FS_THREADS], *_m_x_inv[_MAX_FS_THREADS], *_m_y[_MAX_FS_THREADS], *_m_J[_MAX_FS_THREADS], *_m_U[_MAX_FS_THREADS], *_m_V[_MAX_FS_THREADS], *_m_m[_MAX_FS_THREADS], *_m_evectors[_MAX_FS_THREADS]; MATRIX *m_x, *m_x_inv, *m_y, *m_J, *m_U, *m_V, *m_m, *m_evectors = NULL; @@ -21206,7 +21649,8 @@ static double ashburnerTriangleEnergy(MRI_SURFACE *mris, int fno, double lambda) } #endif static float mrisSampleAshburnerTriangleEnergy( - MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) { + MRI_SURFACE *mris, VERTEX *v, INTEGRATION_PARMS *parms, float cx, float cy, float cz) +{ double sse, ox, oy, oz, sse_total; int n; @@ -21290,7 +21734,8 @@ mrisSamplePialCoordsInTangentPlane(MRI_SURFACE *mris, VERTEX *v, float x, float Description ------------------------------------------------------*/ -static double mrisComputeThicknessMinimizationEnergy(MRI_SURFACE *mris, double l_thick_min, INTEGRATION_PARMS *parms) { +static double mrisComputeThicknessMinimizationEnergy(MRI_SURFACE *mris, double l_thick_min, INTEGRATION_PARMS *parms) +{ int vno; double sse_tmin; static int cno = 0; @@ -21341,7 +21786,8 @@ static double mrisComputeThicknessMinimizationEnergy(MRI_SURFACE *mris, double l Description ------------------------------------------------------*/ static double big_sse = 10.0; -static double mrisComputeThicknessNormalEnergy(MRI_SURFACE *mris, double l_thick_normal, INTEGRATION_PARMS *parms) { +static double mrisComputeThicknessNormalEnergy(MRI_SURFACE *mris, double l_thick_normal, INTEGRATION_PARMS *parms) +{ int vno; double sse_tnormal; static int cno = 0; @@ -21415,7 +21861,8 @@ static double mrisComputeThicknessNormalEnergy(MRI_SURFACE *mris, double l_thick Description ------------------------------------------------------*/ -static double mrisComputeThicknessSpringEnergy(MRI_SURFACE *mris, double l_thick_spring, INTEGRATION_PARMS *parms) { +static double mrisComputeThicknessSpringEnergy(MRI_SURFACE *mris, double l_thick_spring, INTEGRATION_PARMS *parms) +{ int vno; double sse_spring, sse; VERTEX *v; @@ -21467,7 +21914,8 @@ static double mrisComputeThicknessSpringEnergy(MRI_SURFACE *mris, double l_thick sse_spring /= 2; return (sse_spring); } -static int mrisAssignFaces(MRI_SURFACE *mris, MHT *mht, int which_vertices) { +static int mrisAssignFaces(MRI_SURFACE *mris, MHT *mht, int which_vertices) +{ int vno; #ifdef HAVE_OPENMP @@ -21500,7 +21948,8 @@ static int mrisAssignFaces(MRI_SURFACE *mris, MHT *mht, int which_vertices) { Description ------------------------------------------------------*/ -static double mrisComputeThicknessParallelEnergy(MRI_SURFACE *mris, double l_thick_parallel, INTEGRATION_PARMS *parms) { +static double mrisComputeThicknessParallelEnergy(MRI_SURFACE *mris, double l_thick_parallel, INTEGRATION_PARMS *parms) +{ int vno, max_vno; double sse_tparallel, max_inc; static int cno = 0; @@ -21559,7 +22008,8 @@ static double mrisComputeThicknessParallelEnergy(MRI_SURFACE *mris, double l_thi ------------------------------------------------------*/ static double mrisComputeAshburnerTriangleEnergy(MRI_SURFACE *mris, double l_ashburner_triangle, - INTEGRATION_PARMS *parms) { + INTEGRATION_PARMS *parms) +{ int vno; double sse_ashburner; @@ -21592,7 +22042,8 @@ static double mrisComputeAshburnerTriangleEnergy(MRI_SURFACE *mris, #if 1 // debugged and working, but not needed at the moment static int get_face_axes( - MRI_SURFACE *mris, FACE *face, float *pe1x, float *pe1y, float *pe1z, float *pe2x, float *pe2y, float *pe2z) { + MRI_SURFACE *mris, FACE *face, float *pe1x, float *pe1y, float *pe1z, float *pe2x, float *pe2y, float *pe2z) +{ double V0[3], V1[3], V2[3], e1[3], e2[3], tmp[3], norm, dot; V0[0] = mris->vertices[face->v[0]].x; @@ -21669,7 +22120,8 @@ static int get_face_axes( Description ------------------------------------------------------*/ -static int mrisComputeThicknessMinimizationTerm(MRI_SURFACE *mris, double l_thick_min, INTEGRATION_PARMS *parms) { +static int mrisComputeThicknessMinimizationTerm(MRI_SURFACE *mris, double l_thick_min, INTEGRATION_PARMS *parms) +{ int vno; if (FZERO(l_thick_min)) return (0.0); @@ -21732,7 +22184,8 @@ static int mrisComputeThicknessMinimizationTerm(MRI_SURFACE *mris, double l_thic dx *= -1; dy *= -1; dz *= -1; - } else { + } + else { dx = dy = dz = 0; } } @@ -21770,7 +22223,8 @@ static int mrisComputeThicknessMinimizationTerm(MRI_SURFACE *mris, double l_thic Description ------------------------------------------------------*/ -static int mrisComputeThicknessParallelTerm(MRI_SURFACE *mris, double l_thick_parallel, INTEGRATION_PARMS *parms) { +static int mrisComputeThicknessParallelTerm(MRI_SURFACE *mris, double l_thick_parallel, INTEGRATION_PARMS *parms) +{ int vno; if (FZERO(l_thick_parallel)) return (0.0); @@ -21829,7 +22283,8 @@ static int mrisComputeThicknessParallelTerm(MRI_SURFACE *mris, double l_thick_pa dx *= -1; dy *= -1; dz *= -1; - } else { + } + else { dx = dy = dz = 0; } } @@ -22008,7 +22463,8 @@ mrisComputeThicknessNormalTerm(MRI_SURFACE *mris, double l_thick_normal, INTEGRA return(NO_ERROR) ; } #else -static int mrisComputeThicknessNormalTerm(MRI_SURFACE *mris, double l_thick_normal, INTEGRATION_PARMS *parms) { +static int mrisComputeThicknessNormalTerm(MRI_SURFACE *mris, double l_thick_normal, INTEGRATION_PARMS *parms) +{ int vno; // int missed = 0 ; @@ -22070,7 +22526,8 @@ static int mrisComputeThicknessNormalTerm(MRI_SURFACE *mris, double l_thick_norm dx *= -1; dy *= -1; dz *= -1; - } else { + } + else { dx = dy = dz = 0; } } @@ -22124,7 +22581,8 @@ static int mrisComputeThicknessNormalTerm(MRI_SURFACE *mris, double l_thick_norm return (NO_ERROR); } -static int mrisComputeThicknessSpringTerm(MRI_SURFACE *mris, double l_thick_spring, INTEGRATION_PARMS *parms) { +static int mrisComputeThicknessSpringTerm(MRI_SURFACE *mris, double l_thick_spring, INTEGRATION_PARMS *parms) +{ int vno, max_vno; float dE_de1, dE_de2, e1p, e1m, e2p, e2m, cx, cy, cz; float E0, E1, dx, dy, dz; @@ -22189,28 +22647,33 @@ static int mrisComputeThicknessSpringTerm(MRI_SURFACE *mris, double l_thick_spri dx *= -1; dy *= -1; dz *= -1; - } else { + } + else { if (e1m < e2m && e1m < e1p && e1m < e2p && e1m < E0) // e1m is best { dx = -d_dist * e1x; dy = -d_dist * e1y; dz = d_dist * e1z; - } else if (e2m < e1p && e2m < e2p && e2m < E0) // e2m is best + } + else if (e2m < e1p && e2m < e2p && e2m < E0) // e2m is best { dx = -d_dist * e2x; dy = -d_dist * e2y; dz = -d_dist * e2z; - } else if (e1p < e2p && e1p < E0) // e1p is best + } + else if (e1p < e2p && e1p < E0) // e1p is best { dx = d_dist * e1x; dy = d_dist * e1y; dz = d_dist * e1z; - } else if (e2p < E0) // e2p is best + } + else if (e2p < E0) // e2p is best { dx = d_dist * e2x; dy = d_dist * e2y; dz = d_dist * e2z; - } else { + } + else { dx = dy = dz = 0; } } @@ -22265,7 +22728,8 @@ static int mrisComputeThicknessSpringTerm(MRI_SURFACE *mris, double l_thick_spri return (NO_ERROR); } #endif -static int mrisComputeAshburnerTriangleTerm(MRI_SURFACE *mris, double l_ashburner_triangle, INTEGRATION_PARMS *parms) { +static int mrisComputeAshburnerTriangleTerm(MRI_SURFACE *mris, double l_ashburner_triangle, INTEGRATION_PARMS *parms) +{ int vno; // int missed = 0 ; @@ -22334,7 +22798,8 @@ static int mrisComputeAshburnerTriangleTerm(MRI_SURFACE *mris, double l_ashburne dx *= -1; dy *= -1; dz *= -1; - } else { + } + else { dx = dy = dz = 0; } } @@ -22413,7 +22878,8 @@ mrisComputeRepulsiveEnergy(MRI_SURFACE *mris, double l_repulse) return(l_repulse * sse_repulse) ; } #else -static double mrisComputeRepulsiveEnergy(MRI_SURFACE *mris, double l_repulse, MHT *mht, MHT *mht_faces) { +static double mrisComputeRepulsiveEnergy(MRI_SURFACE *mris, double l_repulse, MHT *mht, MHT *mht_faces) +{ int vno, num, min_vno, i, n; float dist, dx, dy, dz, x, y, z, min_d; double sse_repulse, v_sse; @@ -22569,7 +23035,8 @@ static double mrisComputeRepulsiveEnergy(MRI_SURFACE *mris, double l_repulse, MH Description ------------------------------------------------------*/ -static double mrisComputeRepulsiveRatioEnergy(MRI_SURFACE *mris, double l_repulse) { +static double mrisComputeRepulsiveRatioEnergy(MRI_SURFACE *mris, double l_repulse) +{ int vno, n; double sse_repulse, v_sse, dist, dx, dy, dz, x, y, z, canon_dist, cdx, cdy, cdz; VERTEX *v, *vn; @@ -22619,7 +23086,8 @@ static double mrisComputeRepulsiveRatioEnergy(MRI_SURFACE *mris, double l_repuls Description ------------------------------------------------------*/ -static int mrisComputeThicknessSmoothnessTerm(MRI_SURFACE *mris, double l_tsmooth, INTEGRATION_PARMS *parms) { +static int mrisComputeThicknessSmoothnessTerm(MRI_SURFACE *mris, double l_tsmooth, INTEGRATION_PARMS *parms) +{ int vno, n, num; float dx, dy, dz, x, y, z, dn, d0, vx, vy, vz, delta; VERTEX *v, *vn; @@ -22677,7 +23145,8 @@ static int mrisComputeThicknessSmoothnessTerm(MRI_SURFACE *mris, double l_tsmoot Description ------------------------------------------------------*/ -static int mrisComputeRepulsiveTerm(MRI_SURFACE *mris, double l_repulse, MHT *mht, MHT *mht_faces) { +static int mrisComputeRepulsiveTerm(MRI_SURFACE *mris, double l_repulse, MHT *mht, MHT *mht_faces) +{ int vno, num, min_vno, i, n; float dist, dx, dy, dz, x, y, z, sx, sy, sz, min_d, min_scale, norm; double scale; @@ -22890,7 +23359,8 @@ static int mrisComputeRepulsiveTerm(MRI_SURFACE *mris, double l_repulse, MHT *mh Description ------------------------------------------------------*/ -static int mrisComputeRepulsiveRatioTerm(MRI_SURFACE *mris, double l_repulse, MHT *mht) { +static int mrisComputeRepulsiveRatioTerm(MRI_SURFACE *mris, double l_repulse, MHT *mht) +{ int vno, num, min_vno, i; float dist, dx, dy, dz, x, y, z, sx, sy, sz, min_d, min_scale, canon_dist, cdx, cdy, cdz; double scale; @@ -22981,7 +23451,8 @@ static int mrisComputeRepulsiveRatioTerm(MRI_SURFACE *mris, double l_repulse, MH Description ------------------------------------------------------*/ -static double mrisComputeSpringEnergy(MRI_SURFACE *mris) { +static double mrisComputeSpringEnergy(MRI_SURFACE *mris) +{ int vno, n; double area_scale, sse_spring, v_sse; VERTEX *v; @@ -22989,7 +23460,8 @@ static double mrisComputeSpringEnergy(MRI_SURFACE *mris) { #if METRIC_SCALE if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -23022,7 +23494,8 @@ static double mrisComputeSpringEnergy(MRI_SURFACE *mris) { (i.e. after global rotational alignment) spherical coordinates in the TMP2_VERTICES ------------------------------------------------------*/ -static double mrisComputeLaplacianEnergy(MRI_SURFACE *mris) { +static double mrisComputeLaplacianEnergy(MRI_SURFACE *mris) +{ int vno, n; double area_scale, sse_lap, v_sse, dx, dy, dz, vx, vy, vz, vnx, vny, vnz, error; VERTEX *v, *vn; @@ -23030,7 +23503,8 @@ static double mrisComputeLaplacianEnergy(MRI_SURFACE *mris) { #if METRIC_SCALE if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -23069,7 +23543,8 @@ static double mrisComputeLaplacianEnergy(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static double mrisComputeTangentialSpringEnergy(MRI_SURFACE *mris) { +static double mrisComputeTangentialSpringEnergy(MRI_SURFACE *mris) +{ int vno, n; double area_scale, sse_spring, v_sse; VERTEX *v, *vn; @@ -23078,7 +23553,8 @@ static double mrisComputeTangentialSpringEnergy(MRI_SURFACE *mris) { #if METRIC_SCALE if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = FZERO(mris->total_area) ? 1.0 : mris->orig_area / mris->total_area; } #else @@ -23122,7 +23598,8 @@ static double mrisComputeTangentialSpringEnergy(MRI_SURFACE *mris) { #define RMIN 1 #define RMAX 5 -static int mrisComputeNonlinearSpringTerm(MRI_SURFACE *mris, double l_nlspring, INTEGRATION_PARMS *parms) { +static int mrisComputeNonlinearSpringTerm(MRI_SURFACE *mris, double l_nlspring, INTEGRATION_PARMS *parms) +{ int vno, n; double area_scale, sse_spring, E, F, f, rmin, rmax; VERTEX *v, *vn; @@ -23135,7 +23612,8 @@ static int mrisComputeNonlinearSpringTerm(MRI_SURFACE *mris, double l_nlspring, #if METRIC_SCALE if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -23188,7 +23666,8 @@ static int mrisComputeNonlinearSpringTerm(MRI_SURFACE *mris, double l_nlspring, return (NO_ERROR); } -static double mrisComputeNonlinearSpringEnergy(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisComputeNonlinearSpringEnergy(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int vno, n; double area_scale, sse_spring, E, F, f, rmin, rmax, ftotal; VERTEX *v, *vn; @@ -23199,7 +23678,8 @@ static double mrisComputeNonlinearSpringEnergy(MRI_SURFACE *mris, INTEGRATION_PA #if METRIC_SCALE if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -23283,7 +23763,8 @@ static double mrisComputeNonlinearSpringEnergy(MRI_SURFACE *mris, INTEGRATION_PA A0 = 0.5 (a x b) . n ------------------------------------------------------*/ -static int mrisComputeAngleAreaTerms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeAngleAreaTerms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int fno, ano; VERTEX *v0, *v1, *v2, *va, *vb, *vo; VECTOR *v_a, *v_b, *v_a_x_n, *v_b_x_n, *v_n, *v_tmp, *v_sum; @@ -23293,7 +23774,8 @@ static int mrisComputeAngleAreaTerms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms #if METRIC_SCALE if (mris->patch || (mris->status != MRIS_SPHERE && mris->status != MRIS_PARAMETERIZED_SPHERE)) { area_scale = 1.0f; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -23436,7 +23918,8 @@ static int mrisComputeAngleAreaTerms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms len = V3_DOT(v_a, v_a); if (!FZERO(len)) { V3_SCALAR_MUL(v_tmp, delta / len, v_tmp); - } else { + } + else { V3_SCALAR_MUL(v_tmp, 0.0f, v_tmp); } va->dx += V3_X(v_tmp); @@ -23451,7 +23934,8 @@ static int mrisComputeAngleAreaTerms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms len = V3_DOT(v_b, v_b); if (!FZERO(len)) { V3_SCALAR_MUL(v_sum, delta / len, v_sum); - } else { + } + else { V3_SCALAR_MUL(v_sum, 0.0f, v_sum); } vb->dx += V3_X(v_sum); @@ -23491,7 +23975,8 @@ static int mrisComputeAngleAreaTerms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms Description ------------------------------------------------------*/ -static int mrisComputeNonlinearAreaTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeNonlinearAreaTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int fno; VERTEX *v0, *v1, *v2; VECTOR *v_a, *v_b, *v_a_x_n, *v_b_x_n, *v_n, *v_tmp, *v_sum; @@ -23501,7 +23986,8 @@ static int mrisComputeNonlinearAreaTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *pa #if METRIC_SCALE if (mris->patch || (mris->status != MRIS_SPHERE && mris->status != MRIS_PARAMETERIZED_SPHERE)) { area_scale = 1.0f; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } #else @@ -23546,7 +24032,8 @@ static int mrisComputeNonlinearAreaTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *pa #if SCALE_NONLINEAR_AREA if (!FZERO(orig_area)) { ratio = area / orig_area; - } else { + } + else { ratio = 0.0f; } #else @@ -23555,7 +24042,8 @@ static int mrisComputeNonlinearAreaTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *pa if (ratio > MAX_NEG_RATIO) { ratio = MAX_NEG_RATIO; - } else if (ratio < -MAX_NEG_RATIO) { + } + else if (ratio < -MAX_NEG_RATIO) { ratio = -MAX_NEG_RATIO; } #if 0 @@ -23626,7 +24114,8 @@ static int mrisComputeNonlinearAreaTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *pa Description ------------------------------------------------------*/ -static int mrisComputeSurfaceRepulsionTerm(MRI_SURFACE *mris, double l_repulse, MHT *mht) { +static int mrisComputeSurfaceRepulsionTerm(MRI_SURFACE *mris, double l_repulse, MHT *mht) +{ int vno, max_vno, i; float dx, dy, dz, x, y, z, sx, sy, sz, norm[3], dot; float max_scale, max_dot; @@ -23682,7 +24171,8 @@ static int mrisComputeSurfaceRepulsionTerm(MRI_SURFACE *mris, double l_repulse, } if (dot > MAX_NEG_RATIO) { dot = MAX_NEG_RATIO; - } else if (dot < -MAX_NEG_RATIO) { + } + else if (dot < -MAX_NEG_RATIO) { dot = -MAX_NEG_RATIO; } #if 0 @@ -23724,7 +24214,8 @@ static int mrisComputeSurfaceRepulsionTerm(MRI_SURFACE *mris, double l_repulse, Description ------------------------------------------------------*/ static int mrisComputeWhichSurfaceRepulsionTerm( - MRI_SURFACE *mris, double l_repulse, MHT *mht, int which, float dot_thresh) { + MRI_SURFACE *mris, double l_repulse, MHT *mht, int which, float dot_thresh) +{ int vno, max_vno, i; float dx, dy, dz, x, y, z, sx, sy, sz, norm[3], dot; float max_scale, max_dot; @@ -23739,7 +24230,8 @@ static int mrisComputeWhichSurfaceRepulsionTerm( if (l_repulse < 0) { sgn = -1; - } else { + } + else { sgn = 1; } for (vno = 0; vno < mris->nvertices; vno++) { @@ -23799,7 +24291,8 @@ static int mrisComputeWhichSurfaceRepulsionTerm( } if (dot > MAX_NEG_RATIO) { dot = MAX_NEG_RATIO; - } else if (dot < -MAX_NEG_RATIO) { + } + else if (dot < -MAX_NEG_RATIO) { dot = -MAX_NEG_RATIO; } #if 0 @@ -23884,7 +24377,8 @@ mrisComputeAverageHeight(MRI_SURFACE *mris) Description ------------------------------------------------------*/ -static int mrisProjectSurface(MRI_SURFACE *mris) { +static int mrisProjectSurface(MRI_SURFACE *mris) +{ /* MRISupdateSurface(mris) ;*/ switch (mris->status) { case MRIS_PLANE: @@ -23925,7 +24419,8 @@ static int mrisProjectSurface(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisOrientSurface(MRI_SURFACE *mris) { +static int mrisOrientSurface(MRI_SURFACE *mris) +{ switch (mris->status) { case MRIS_RIGID_BODY: case MRIS_PARAMETERIZED_SPHERE: @@ -23951,7 +24446,8 @@ static int mrisOrientSurface(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisLogStatus(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, FILE *fp, float dt, float old_sse) { +static int mrisLogStatus(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, FILE *fp, float dt, float old_sse) +{ float area_rms, angle_rms, curv_rms, sse, dist_rms, corr_rms; int n, negative; float nv; @@ -23984,7 +24480,8 @@ static int mrisLogStatus(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, FILE *fp, sse = MRIScomputeSSE(mris, parms); if (old_sse > 0) { pct_change = 100 * (old_sse - sse) / (old_sse); - } else { + } + else { pct_change = 0.0; } fprintf(fp, @@ -23998,7 +24495,8 @@ static int mrisLogStatus(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, FILE *fp, 100.0 * mris->neg_orig_area / (mris->orig_area), parms->n_averages, pct_change); - } else { + } + else { sse = mrisComputeError(mris, parms, &area_rms, &angle_rms, &curv_rms, &dist_rms, &corr_rms); if (fyi) { @@ -24034,7 +24532,8 @@ static int mrisLogStatus(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, FILE *fp, if (dist_rms > 20) { DiagBreak(); } - } else { + } + else { if (parms->flags & IP_USE_MULTIFRAMES) { nv = (float)MRISvalidVertices(mris); @@ -24059,7 +24558,8 @@ static int mrisLogStatus(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, FILE *fp, fprintf(stdout, " (%d: %2.3f : %2.3f)", n, parms->fields[n].sse, sqrt(parms->fields[n].sse / nv)); } fprintf(stdout, "\n"); - } else + } + else fprintf(fp, "%3.3d: dt: %2.3f, sse: %2.1f (%2.3f, %2.1f, %2.3f, %2.3f), " "neg: %d (%%%2.2f:%%%2.2f), avgs: %d\n", @@ -24087,7 +24587,8 @@ static int mrisLogStatus(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, FILE *fp, Description ------------------------------------------------------*/ -int MRISreadVertexPositions(MRI_SURFACE *mris, const char *name) { +int MRISreadVertexPositions(MRI_SURFACE *mris, const char *name) +{ char fname[STRLEN]; int vno, nvertices, nfaces, magic, version, tmp, ix, iy, iz, n, type; VERTEX *vertex; @@ -24097,7 +24598,8 @@ int MRISreadVertexPositions(MRI_SURFACE *mris, const char *name) { MRISbuildFileName(mris, name, fname); if (type == MRIS_GEO_TRIANGLE_FILE) { return (mrisReadGeoFilePositions(mris, fname)); - } else if (type == MRIS_ICO_FILE) { + } + else if (type == MRIS_ICO_FILE) { return (ICOreadVertexPositions(mris, fname, CURRENT_VERTICES)); } fp = fopen(fname, "rb"); @@ -24109,15 +24611,18 @@ int MRISreadVertexPositions(MRI_SURFACE *mris, const char *name) { if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { fprintf(stdout, "new surface file format\n"); } - } else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { + } + else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { version = -2; - } else if (magic == TRIANGLE_FILE_MAGIC_NUMBER) { + } + else if (magic == TRIANGLE_FILE_MAGIC_NUMBER) { fclose(fp); if (mrisReadTriangleFilePositions(mris, fname) != NO_ERROR) { ErrorReturn(Gerror, (Gerror, "mrisReadTriangleFile failed.\n")); } version = -3; - } else { + } + else { rewind(fp); version = 0; if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { @@ -24156,7 +24661,8 @@ int MRISreadVertexPositions(MRI_SURFACE *mris, const char *name) { vertex->x = ix / 100.0; vertex->y = iy / 100.0; vertex->z = iz / 100.0; - } else /* version == -2 */ + } + else /* version == -2 */ { vertex->x = freadFloat(fp); vertex->y = freadFloat(fp); @@ -24184,7 +24690,8 @@ int MRISreadVertexPositions(MRI_SURFACE *mris, const char *name) { Description ------------------------------------------------------*/ -int MRIScomputeMetricProperties(MRI_SURFACE *mris) { +int MRIScomputeMetricProperties(MRI_SURFACE *mris) +{ MRIScomputeNormals(mris); mrisComputeVertexDistances(mris); mrisComputeSurfaceDimensions(mris); @@ -24205,7 +24712,8 @@ int MRIScomputeMetricProperties(MRI_SURFACE *mris) { /* this is a fork of mrisComputeMetricProperties, but ultimately shouldn't be */ -int mrisComputeMetricPropertiesCUDA(MRI_CUDA_SURFACE *mrics, MRI_SURFACE *mris) { +int mrisComputeMetricPropertiesCUDA(MRI_CUDA_SURFACE *mrics, MRI_SURFACE *mris) +{ #ifdef FS_CUDA_TIMINGS struct timeval tv1, tv2, result; #endif // FS_CUDA_TIMINGS @@ -24242,7 +24750,8 @@ int mrisComputeMetricPropertiesCUDA(MRI_CUDA_SURFACE *mrics, MRI_SURFACE *mris) /* DOWNLOAD distances */ MRISCdownloadDistances(mrics, mris); - } else { + } + else { #ifdef FS_CUDA_TIMINGS gettimeofday(&tv1, NULL); #endif // FS_CUDA_TIMINGS @@ -24307,7 +24816,8 @@ int mrisComputeMetricPropertiesCUDA(MRI_CUDA_SURFACE *mrics, MRI_SURFACE *mris) MRISrescaleMetricProperties() have been run. Returns the distance scaling factor. Has no effect if surface is not a group surface. -------------------------------------------------------------------- */ -double MRISrescaleMetricProperties(MRIS *surf) { +double MRISrescaleMetricProperties(MRIS *surf) +{ int VtxNo, nthNNbr, nNNbrs, NbrVtxNo; VERTEX *vtx1, *vtx2; double scale; @@ -24344,7 +24854,8 @@ double MRISrescaleMetricProperties(MRIS *surf) { /*------------------------------------------------------ ------------------------------------------------------*/ -static int mrisCountTotalNeighbors(MRI_SURFACE *mris) { +static int mrisCountTotalNeighbors(MRI_SURFACE *mris) +{ int vno, total; VERTEX *v; @@ -24476,7 +24987,8 @@ mrisComputeNegTerm(MRI_SURFACE *mris,INTEGRATION_PARMS *parms) } #endif -static int mrisFlipPatch(MRI_SURFACE *mris) { +static int mrisFlipPatch(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -24502,7 +25014,8 @@ static int mrisFlipPatch(MRI_SURFACE *mris) { Note we must change the status of the mris as the original surface has no externally defined orientation. ------------------------------------------------------*/ -int MRISreadOriginalProperties(MRI_SURFACE *mris, const char *sname) { +int MRISreadOriginalProperties(MRI_SURFACE *mris, const char *sname) +{ int old_status; if (!sname) { @@ -24537,7 +25050,8 @@ int MRISreadOriginalProperties(MRI_SURFACE *mris, const char *sname) { Description ------------------------------------------------------*/ -int MRISsaveVertexPositions(MRI_SURFACE *mris, int which) { +int MRISsaveVertexPositions(MRI_SURFACE *mris, int which) +{ int vno, nvertices; VERTEX *v; @@ -24616,7 +25130,8 @@ int MRISsaveVertexPositions(MRI_SURFACE *mris, int which) { Description ------------------------------------------------------*/ -int MRISsaveNormals(MRI_SURFACE *mris, int which) { +int MRISsaveNormals(MRI_SURFACE *mris, int which) +{ int vno, nvertices; VERTEX *v; @@ -24663,7 +25178,8 @@ int MRISsaveNormals(MRI_SURFACE *mris, int which) { Description ------------------------------------------------------*/ -int MRISrestoreNormals(MRI_SURFACE *mris, int which) { +int MRISrestoreNormals(MRI_SURFACE *mris, int which) +{ int vno, nvertices; VERTEX *v; @@ -24706,7 +25222,8 @@ int MRISrestoreNormals(MRI_SURFACE *mris, int which) { Description ------------------------------------------------------*/ -int MRIScomputeCanonicalCoordinates(MRI_SURFACE *mris) { +int MRIScomputeCanonicalCoordinates(MRI_SURFACE *mris) +{ float theta, phi, r, d, x, y, z; VERTEX *v; int vno; @@ -24740,7 +25257,8 @@ int MRIScomputeCanonicalCoordinates(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISrestoreVertexPositions(MRI_SURFACE *mris, int which) { +int MRISrestoreVertexPositions(MRI_SURFACE *mris, int which) +{ int vno, nvertices; VERTEX *v; @@ -24869,14 +25387,16 @@ int MRISrestoreVertexPositions(MRI_SURFACE *mris, int which) { Description ------------------------------------------------------*/ -double MRISpercentDistanceError(MRI_SURFACE *mris) { +double MRISpercentDistanceError(MRI_SURFACE *mris) +{ VERTEX *v; int vno, n, nvertices; double dist_scale, pct, dist, odist, mean, mean_error; if (mris->patch) { dist_scale = 1.0; - } else { + } + else { dist_scale = sqrt(mris->orig_area / mris->total_area); } @@ -24920,7 +25440,8 @@ double MRISpercentDistanceError(MRI_SURFACE *mris) { #else if (!FZERO(mean)) { pct = mean_error / mean; - } else { + } + else { pct = 1000.0; /* should never happen */ } #endif @@ -24937,7 +25458,8 @@ double MRISpercentDistanceError(MRI_SURFACE *mris) { Description: return filetype using the extension default is MRIS_BINARY_QUADRANGLE_FILE ------------------------------------------------------*/ -int MRISfileNameType(const char *fname) { +int MRISfileNameType(const char *fname) +{ int type; char *dot, ext[STRLEN], str[STRLEN], *idext; @@ -24955,7 +25477,8 @@ int MRISfileNameType(const char *fname) { if (dot) { *dot = 0; /* remove it from file name so that fopen will work */ strcpy(ext, dot + 1); - } else /* no explicit type - check extension */ + } + else /* no explicit type - check extension */ { dot = strrchr(str, '.'); if (dot) { @@ -24965,21 +25488,29 @@ int MRISfileNameType(const char *fname) { StrUpper(ext); if (!strcmp(ext, "ASC")) { type = MRIS_ASCII_TRIANGLE_FILE; - } else if (!strcmp(ext, "GEO")) { + } + else if (!strcmp(ext, "GEO")) { type = MRIS_GEO_TRIANGLE_FILE; - } else if (!strcmp(ext, "TRI") || !strcmp(ext, "ICO")) { + } + else if (!strcmp(ext, "TRI") || !strcmp(ext, "ICO")) { type = MRIS_ICO_FILE; - } else if (!strcmp(ext, "VTK")) { + } + else if (!strcmp(ext, "VTK")) { type = MRIS_VTK_FILE; - } else if (!strcmp(ext, "STL")) { + } + else if (!strcmp(ext, "STL")) { type = MRIS_STL_FILE; - } else if (!strcmp(ext, "GII")) { + } + else if (!strcmp(ext, "GII")) { type = MRIS_GIFTI_FILE; - } else if (!strcmp(ext, "MGH")) { + } + else if (!strcmp(ext, "MGH")) { type = MRI_MGH_FILE; // surface-encoded volume - } else if (!strcmp(ext, "ANNOT")) { + } + else if (!strcmp(ext, "ANNOT")) { type = MRIS_ANNOT_FILE; - } else { + } + else { type = MRIS_BINARY_QUADRANGLE_FILE; } @@ -24993,7 +25524,8 @@ int MRISfileNameType(const char *fname) { Description ------------------------------------------------------*/ -int MRISwriteAscii(MRI_SURFACE *mris, const char *fname) { +int MRISwriteAscii(MRI_SURFACE *mris, const char *fname) +{ int vno, fno, n; VERTEX *v; FACE *face; @@ -25025,7 +25557,8 @@ int MRISwriteAscii(MRI_SURFACE *mris, const char *fname) { Description: Same as MRISwriteAscii, but write surface normals instead of ------------------------------------------------------*/ -int MRISwriteNormalsAscii(MRI_SURFACE *mris, const char *fname) { +int MRISwriteNormalsAscii(MRI_SURFACE *mris, const char *fname) +{ int vno, fno, n; VERTEX *v; FACE *face; @@ -25056,7 +25589,8 @@ int MRISwriteNormalsAscii(MRI_SURFACE *mris, const char *fname) { /*----------------------------------------------------- Description: Same write the surface normals into a .mgz volume ------------------------------------------------------*/ -int MRISwriteNormals(MRI_SURFACE *mris, const char *fname) { +int MRISwriteNormals(MRI_SURFACE *mris, const char *fname) +{ int vno; VERTEX *v; MRI *mri; @@ -25076,7 +25610,8 @@ int MRISwriteNormals(MRI_SURFACE *mris, const char *fname) { MRIfree(&mri); return (NO_ERROR); } -int MRISreadNormals(MRI_SURFACE *mris, const char *fname) { +int MRISreadNormals(MRI_SURFACE *mris, const char *fname) +{ int vno; VERTEX *v; MRI *mri; @@ -25098,7 +25633,8 @@ int MRISreadNormals(MRI_SURFACE *mris, const char *fname) { /*----------------------------------------------------- Description: Same write the white matter surface normals into a .mgz volume ------------------------------------------------------*/ -int MRISwriteWhiteNormals(MRI_SURFACE *mris, const char *fname) { +int MRISwriteWhiteNormals(MRI_SURFACE *mris, const char *fname) +{ int vno; VERTEX *v; MRI *mri; @@ -25121,7 +25657,8 @@ int MRISwriteWhiteNormals(MRI_SURFACE *mris, const char *fname) { /*----------------------------------------------------- Description: write the principal curvature directions ------------------------------------------------------*/ -int MRISwritePrincipalDirection(MRI_SURFACE *mris, int dir_index, const char *fname) { +int MRISwritePrincipalDirection(MRI_SURFACE *mris, int dir_index, const char *fname) +{ int vno; VERTEX *v; MRI *mri; @@ -25138,7 +25675,8 @@ int MRISwritePrincipalDirection(MRI_SURFACE *mris, int dir_index, const char *fn MRIsetVoxVal(mri, vno, 0, 0, 0, v->e1x); MRIsetVoxVal(mri, vno, 0, 0, 1, v->e1y); MRIsetVoxVal(mri, vno, 0, 0, 2, v->e1z); - } else { + } + else { MRIsetVoxVal(mri, vno, 0, 0, 0, v->e2x); MRIsetVoxVal(mri, vno, 0, 0, 1, v->e2y); MRIsetVoxVal(mri, vno, 0, 0, 2, v->e2z); @@ -25155,7 +25693,8 @@ int MRISwritePrincipalDirection(MRI_SURFACE *mris, int dir_index, const char *fn Description ------------------------------------------------------*/ -int MRISwriteVTK(MRI_SURFACE *mris, const char *fname) { +int MRISwriteVTK(MRI_SURFACE *mris, const char *fname) +{ int vno, fno, n; VERTEX *v; FACE *face; @@ -25195,7 +25734,8 @@ int MRISwriteVTK(MRI_SURFACE *mris, const char *fname) { is assumed to have been written with point and face data via the MRISwriteVTK routine. ------------------------------------------------------*/ -int MRISwriteCurvVTK(MRI_SURFACE *mris, const char *fname) { +int MRISwriteCurvVTK(MRI_SURFACE *mris, const char *fname) +{ FILE *fp = fopen(fname, "a"); if (!fp) ErrorReturn(ERROR_NOFILE, (ERROR_NOFILE, "MRISwriteScalarVTK: could not open file %s", fname)); @@ -25220,7 +25760,8 @@ int MRISwriteCurvVTK(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { +MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) +{ char line[STRLEN], *cp = NULL; FILE *fp = fopen(fname, "r"); @@ -25278,7 +25819,8 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { fclose(fp); ErrorReturn(NULL, (ERROR_NOFILE, "MRISreadVTK: error reading file %s, invalid nvertices=%d\n", fname, nvertices)); } - } else { + } + else { fclose(fp); ErrorReturn(NULL, (ERROR_NOFILE, "MRISreadVTK: error reading file %s, no POINTS field\n", fname)); } @@ -25289,7 +25831,8 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { mris = MRISalloc(nvertices, 0); // note: nfaces=0 for now... mris->type = MRIS_TRIANGULAR_SURFACE; newMris = 1; // flag indicating need to fill-in vertex and face data - } else { + } + else { // confirm that the mris structure we've been passed has the same // number of vertices if (mris->nvertices != nvertices) { @@ -25337,7 +25880,8 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { fclose(fp); ErrorReturn(NULL, (ERROR_NOFILE, "MRISreadVTK: error reading file %s, invalid POLYGON data\n", fname)); } - } else { + } + else { fclose(fp); ErrorReturn(NULL, (ERROR_NOFILE, "MRISreadVTK: error parsing POLYGONS in file %s", fname)); } @@ -25350,10 +25894,12 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { if (!mris->faces) { fclose(fp); ErrorExit(ERROR_NO_MEMORY, "MRISreadVTK(%d, %d): could not allocate faces", nfaces, sizeof(FACE)); - } else { + } + else { memset(mris->faces, 0, nfaces * sizeof(FACE)); } - } else { + } + else { // confirm that the mris structure passed to us has the expected num faces if (mris->nfaces != nfaces) { fclose(fp); @@ -25385,7 +25931,8 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { // fill-in the face data to our new mris struct face->v[n] = vno; mris->vertices[vno].num++; - } else { + } + else { // confirm that the mris structure passed to us has the same face num if (face->v[n] != vno) { fclose(fp); @@ -25470,7 +26017,8 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { curvmin = v->curv; } } - } else { + } + else { fclose(fp); ErrorReturn(NULL, (ERROR_NOFILE, "MRISreadVTK: error parsing %s FIELD in file %s", fieldName, fname)); } @@ -25480,7 +26028,8 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { mris->min_curv = curvmin; // printf("maxcurv=%f, mincurv=%f\n",curvmax, curvmin); } - } else { + } + else { fclose(fp); ErrorReturn(NULL, (ERROR_NOFILE, "MRISreadVTK: error parsing FIELDs in file %s", fname)); } @@ -25500,7 +26049,8 @@ MRI_SURFACE *MRISreadVTK(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -int MRISwriteGeo(MRI_SURFACE *mris, const char *fname) { +int MRISwriteGeo(MRI_SURFACE *mris, const char *fname) +{ int vno, fno, n, actual_vno, toggle, nfaces, nvertices, vnos[300000]; VERTEX *v; FACE *face; @@ -25530,7 +26080,8 @@ int MRISwriteGeo(MRI_SURFACE *mris, const char *fname) { if (toggle) { toggle = 0; fprintf(fp, "\n"); - } else { + } + else { toggle = 1; fprintf(fp, " "); } @@ -25565,7 +26116,8 @@ int MRISwriteGeo(MRI_SURFACE *mris, const char *fname) { Description: write ascii icosahedron data (vertices and face vertices info) ------------------------------------------------------*/ /* note that .tri or .ico file. numbering is 1-based output.*/ -int MRISwriteICO(MRI_SURFACE *mris, const char *fname) { +int MRISwriteICO(MRI_SURFACE *mris, const char *fname) +{ int vno, fno, nfaces, nvertices; int actual_fno, actual_vno; VERTEX *v; @@ -25615,7 +26167,8 @@ int MRISwriteICO(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -int MRISwritePatchAscii(MRI_SURFACE *mris, const char *fname) { +int MRISwritePatchAscii(MRI_SURFACE *mris, const char *fname) +{ FILE *fp; int vno, fno, n, nvertices, nfaces, type; VERTEX *v; @@ -25685,7 +26238,8 @@ int MRISwritePatchAscii(MRI_SURFACE *mris, const char *fname) { Description: write ascii STL (stereolithography) format ------------------------------------------------------*/ -int MRISwriteSTL(MRI_SURFACE *mris, const char *fname) { +int MRISwriteSTL(MRI_SURFACE *mris, const char *fname) +{ int vno, fno; VERTEX *v; FACE *face; @@ -25729,7 +26283,8 @@ int MRISwriteSTL(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -static MRI_SURFACE *mrisReadAsciiFile(const char *fname) { +static MRI_SURFACE *mrisReadAsciiFile(const char *fname) +{ MRI_SURFACE *mris; char line[STRLEN], *cp; int vno, fno, n, nvertices, nfaces, patch, rip; @@ -25791,7 +26346,8 @@ static MRI_SURFACE *mrisReadAsciiFile(const char *fname) { Description ------------------------------------------------------*/ -static MRI_SURFACE *mrisReadGeoFile(const char *fname) { +static MRI_SURFACE *mrisReadGeoFile(const char *fname) +{ MRI_SURFACE *mris; char line[202], *cp; int vno, fno, n, nvertices, nfaces, patch, vertices_per_face, nedges; @@ -25862,7 +26418,8 @@ static MRI_SURFACE *mrisReadGeoFile(const char *fname) { Description ------------------------------------------------------*/ -static int mrisReadGeoFilePositions(MRI_SURFACE *mris, const char *fname) { +static int mrisReadGeoFilePositions(MRI_SURFACE *mris, const char *fname) +{ char line[202], *cp; int vno, nvertices, nfaces, patch, vertices_per_face, nedges; VERTEX *v; @@ -25960,7 +26517,8 @@ mrisReadAsciiPatchFile(char *fname) and face normals into an MRIS_SURFACE structure. ------------------------------------------------------*/ -static MRI_SURFACE *mrisReadSTLfile(const char *fname) { +static MRI_SURFACE *mrisReadSTLfile(const char *fname) +{ MRI_SURFACE *mris; char line[STRLEN], *cp; int nfaces, fno, vno, fvno, n2; @@ -26002,7 +26560,8 @@ static MRI_SURFACE *mrisReadSTLfile(const char *fname) { mris = MRISalloc(nfaces * 3, nfaces); if (mris == NULL) { ErrorReturn(NULL, (ERROR_NOMEMORY, "MRISreadSTLfile: could not alloc memory for mris")); - } else { + } + else { mris->type = MRIS_TRIANGULAR_SURFACE; } @@ -26049,7 +26608,8 @@ static MRI_SURFACE *mrisReadSTLfile(const char *fname) { } if (!cp) { ErrorReturn(NULL, (ERROR_NOFILE, "MRISreadSTLfile: error reading file %s", fname)); - } else { + } + else { printf("Found %d faces and %d vertices in STL file\n", fno, vno); } @@ -26099,7 +26659,8 @@ static MRI_SURFACE *mrisReadSTLfile(const char *fname) { if (vnums[n] != n) { nduplicates++; vnums2[n] = -1; - } else { + } + else { vnums2[n] = n - nduplicates; } } @@ -26240,7 +26801,8 @@ static MRI_SURFACE *mrisReadSTLfile(const char *fname) { return (mris); } -double MRIScomputeCorrelationError(MRI_SURFACE *mris, MRI_SP *mrisp_template, int fno) { +double MRIScomputeCorrelationError(MRI_SURFACE *mris, MRI_SP *mrisp_template, int fno) +{ INTEGRATION_PARMS parms; float error; @@ -26263,7 +26825,8 @@ double MRIScomputeCorrelationError(MRI_SURFACE *mris, MRI_SP *mrisp_template, in Description ------------------------------------------------------*/ -double mrisComputeCorrelationError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int use_stds) { +double mrisComputeCorrelationError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int use_stds) +{ float l_corr; l_corr = parms->l_corr + parms->l_pcorr; /* only one will be nonzero */ @@ -26318,14 +26881,16 @@ double mrisComputeCorrelationError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, } if (parms->abs_norm) { sse += fabs(delta); - } else { + } + else { sse += delta * delta; } } return (sse); } -static double mrisComputeVectorCorrelationError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int use_stds) { +static double mrisComputeVectorCorrelationError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int use_stds) +{ double src, target, sse, delta, std; VERTEX *v; int n, vno, fno; @@ -26490,7 +27055,8 @@ static double mrisComputeVectorCorrelationError(MRI_SURFACE *mris, INTEGRATION_P Description ------------------------------------------------------*/ -static int mrisComputeCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double du, dv, up1, um1, vp1, vm1, delta, src, target, mag, max_mag, l_corr; VERTEX *v; int vno, fno; @@ -26604,7 +27170,8 @@ static int mrisComputeCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parm return (NO_ERROR); } -static int mrisComputeVectorCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeVectorCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double du, dv, up1, um1, vp1, vm1, delta, src, target, mag, max_mag, l_corr; VERTEX *v; int vno, fno, n; @@ -26866,7 +27433,8 @@ static int mrisComputeVectorCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS ------------------------------------------------------*/ #define D_ANGLE RADIANS(0.25) -static int mrisComputePolarCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputePolarCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double ap1, am1, da, bp1, bm1, db, gp1, gm1, dg, delta, src, target, mag, max_mag; VERTEX *v; int vno, fno; @@ -26975,7 +27543,8 @@ static int mrisComputePolarCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS return (NO_ERROR); } -static int mrisComputePolarVectorCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputePolarVectorCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double da, db, dg, delta, src, target, l_pcorr; VERTEX *v; int vno, fno, n; @@ -27254,7 +27823,8 @@ static int mrisComputePolarVectorCorrelationTerm(MRI_SURFACE *mris, INTEGRATION_ Description ------------------------------------------------------*/ -int MRISzeroMeanCurvature(MRI_SURFACE *mris) { +int MRISzeroMeanCurvature(MRI_SURFACE *mris) +{ double mean; int vno, vtotal; VERTEX *v; @@ -27292,7 +27862,8 @@ which_norm can be NORM_MEDIAN or NORM_MEAN. NORM_MEAN results in the usual stddev computation. NORM_MEDIAN uses the median instead of the mean for the stddev computation. ------------------------------------------------------*/ -int MRISnormalizeCurvature(MRI_SURFACE *mris, int which_norm) { +int MRISnormalizeCurvature(MRI_SURFACE *mris, int which_norm) +{ double mean, var, std, median; int vno, vtotal; VERTEX *v; @@ -27336,7 +27907,8 @@ int MRISnormalizeCurvature(MRI_SURFACE *mris, int which_norm) { } v->curv = (v->curv - median) / std; } - } else // normalize mean + } + else // normalize mean { for (mean = 0.0f, vtotal = vno = 0; vno < mris->nvertices; vno++) { v = &mris->vertices[vno]; @@ -27384,7 +27956,8 @@ int MRISnormalizeCurvature(MRI_SURFACE *mris, int which_norm) { Description ------------------------------------------------------*/ -int MRISnormalizeCurvatureVariance(MRI_SURFACE *mris) { +int MRISnormalizeCurvatureVariance(MRI_SURFACE *mris) +{ double mean, var, std; int vno, vtotal; VERTEX *v; @@ -27436,7 +28009,8 @@ int MRISnormalizeCurvatureVariance(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISscaleDistances(MRI_SURFACE *mris, float scale) { +int MRISscaleDistances(MRI_SURFACE *mris, float scale) +{ int vno, n; VERTEX *v; @@ -27488,7 +28062,8 @@ mrisCheck(MRI_SURFACE *mris) Description ------------------------------------------------------*/ -int MRISminFilterCurvatures(MRI_SURFACE *mris, int niter) { +int MRISminFilterCurvatures(MRI_SURFACE *mris, int niter) +{ int i, vno, vnb, *pnb, vnum; float curv; VERTEX *v, *vn; @@ -27531,7 +28106,8 @@ int MRISminFilterCurvatures(MRI_SURFACE *mris, int niter) { Description ------------------------------------------------------*/ -int MRISmaxFilterCurvatures(MRI_SURFACE *mris, int niter) { +int MRISmaxFilterCurvatures(MRI_SURFACE *mris, int niter) +{ int i, vno, vnb, *pnb, vnum; float curv; VERTEX *v, *vn; @@ -27571,7 +28147,8 @@ int MRISmaxFilterCurvatures(MRI_SURFACE *mris, int niter) { int MRISaverageCurvatures(MRI_SURFACE *mris, int navgs) Performs navgs steps of iterative spatial smoothing on curv. ------------------------------------------------------*/ -int MRISaverageCurvatures(MRI_SURFACE *mris, int navgs) { +int MRISaverageCurvatures(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float curv, num; VERTEX *v, *vn; @@ -27614,7 +28191,8 @@ int MRISaverageCurvatures(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISaverageMarkedCurvatures(MRI_SURFACE *mris, int navgs) { +int MRISaverageMarkedCurvatures(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float curv, num; VERTEX *v, *vn; @@ -27657,7 +28235,8 @@ int MRISaverageMarkedCurvatures(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISaverageMarkedVals(MRI_SURFACE *mris, int navgs) { +int MRISaverageMarkedVals(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float val, num; VERTEX *v, *vn; @@ -27699,7 +28278,8 @@ int MRISaverageMarkedVals(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISaverageVals(MRI_SURFACE *mris, int navgs) { +int MRISaverageVals(MRI_SURFACE *mris, int navgs) +{ int i, vno; for (i = 0; i < navgs; i++) { @@ -27748,7 +28328,8 @@ int MRISaverageVals(MRI_SURFACE *mris, int navgs) { Description spatially average the v->d field ------------------------------------------------------*/ -int MRISaverageD(MRI_SURFACE *mris, int navgs) { +int MRISaverageD(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float val, num; VERTEX *v, *vn; @@ -27783,7 +28364,8 @@ int MRISaverageD(MRI_SURFACE *mris, int navgs) { } return (NO_ERROR); } -static int compare_sort_vals(const void *pc1, const void *pc2) { +static int compare_sort_vals(const void *pc1, const void *pc2) +{ register float c1, c2; c1 = *(float *)pc1; @@ -27792,7 +28374,8 @@ static int compare_sort_vals(const void *pc1, const void *pc2) { /* return(c1 > c2 ? 1 : c1 == c2 ? 0 : -1) ;*/ if (c1 > c2) { return (1); - } else if (c1 < c2) { + } + else if (c1 < c2) { return (-1); } @@ -27805,7 +28388,8 @@ static int compare_sort_vals(const void *pc1, const void *pc2) { Description ------------------------------------------------------*/ -int MRISmedianFilterVals(MRI_SURFACE *mris, int nmedians) { +int MRISmedianFilterVals(MRI_SURFACE *mris, int nmedians) +{ int i, vno, vnb, *pnb, vnum, num; float val_list[MAX_NEIGHBORS]; VERTEX *v, *vn; @@ -27831,7 +28415,8 @@ int MRISmedianFilterVals(MRI_SURFACE *mris, int nmedians) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdx = val_list[(num - 1) / 2]; - } else { + } + else { v->tdx = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } } @@ -27852,7 +28437,8 @@ int MRISmedianFilterVals(MRI_SURFACE *mris, int nmedians) { Description ------------------------------------------------------*/ -int MRISmedianFilterVerexPositions(MRI_SURFACE *mris, int nmedians) { +int MRISmedianFilterVerexPositions(MRI_SURFACE *mris, int nmedians) +{ int i, vno, vnb, *pnb, vnum, num; float val_list[MAX_NEIGHBORS]; VERTEX *v, *vn; @@ -27877,7 +28463,8 @@ int MRISmedianFilterVerexPositions(MRI_SURFACE *mris, int nmedians) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdx = val_list[(num - 1) / 2]; - } else { + } + else { v->tdx = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } @@ -27895,7 +28482,8 @@ int MRISmedianFilterVerexPositions(MRI_SURFACE *mris, int nmedians) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdy = val_list[(num - 1) / 2]; - } else { + } + else { v->tdy = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } @@ -27913,7 +28501,8 @@ int MRISmedianFilterVerexPositions(MRI_SURFACE *mris, int nmedians) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdz = val_list[(num - 1) / 2]; - } else { + } + else { v->tdz = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } } @@ -27936,7 +28525,8 @@ int MRISmedianFilterVerexPositions(MRI_SURFACE *mris, int nmedians) { Description ------------------------------------------------------*/ -int MRISgaussianFilterD(MRI_SURFACE *mris, double wt) { +int MRISgaussianFilterD(MRI_SURFACE *mris, double wt) +{ int vno, vnb, *pnb, vnum; double nbr_wt, val, norm; VERTEX *v, *vn; @@ -27979,7 +28569,8 @@ int MRISgaussianFilterD(MRI_SURFACE *mris, double wt) { Description ------------------------------------------------------*/ -int MRISmedianFilterD(MRI_SURFACE *mris, int nmedians, int vtotal) { +int MRISmedianFilterD(MRI_SURFACE *mris, int nmedians, int vtotal) +{ int i, vno, vnb, *pnb, vnum, num; float val_list[MAX_NEIGHBORS]; VERTEX *v, *vn; @@ -27993,7 +28584,8 @@ int MRISmedianFilterD(MRI_SURFACE *mris, int nmedians, int vtotal) { pnb = v->v; if (vtotal) { vnum = v->vtotal; - } else { + } + else { vnum = v->vnum; } val_list[0] = v->d; @@ -28008,7 +28600,8 @@ int MRISmedianFilterD(MRI_SURFACE *mris, int nmedians, int vtotal) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdx = val_list[(num - 1) / 2]; - } else { + } + else { v->tdx = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } } @@ -28029,7 +28622,8 @@ int MRISmedianFilterD(MRI_SURFACE *mris, int nmedians, int vtotal) { Description ------------------------------------------------------*/ -int MRISmedianFilterCurvature(MRI_SURFACE *mris, int nmedians) { +int MRISmedianFilterCurvature(MRI_SURFACE *mris, int nmedians) +{ int i, vno, vnb, *pnb, vnum, num; float val_list[MAX_NEIGHBORS]; VERTEX *v, *vn; @@ -28054,7 +28648,8 @@ int MRISmedianFilterCurvature(MRI_SURFACE *mris, int nmedians) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdx = val_list[(num - 1) / 2]; - } else { + } + else { v->tdx = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } } @@ -28075,7 +28670,8 @@ int MRISmedianFilterCurvature(MRI_SURFACE *mris, int nmedians) { Description ------------------------------------------------------*/ -int MRISmedianFilterVal2s(MRI_SURFACE *mris, int nmedians) { +int MRISmedianFilterVal2s(MRI_SURFACE *mris, int nmedians) +{ int i, vno, vnb, *pnb, vnum, num; float val_list[MAX_NEIGHBORS]; VERTEX *v, *vn; @@ -28100,7 +28696,8 @@ int MRISmedianFilterVal2s(MRI_SURFACE *mris, int nmedians) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdx = val_list[(num - 1) / 2]; - } else { + } + else { v->tdx = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } } @@ -28121,7 +28718,8 @@ int MRISmedianFilterVal2s(MRI_SURFACE *mris, int nmedians) { Description ------------------------------------------------------*/ -int MRISmedianFilterVal2baks(MRI_SURFACE *mris, int nmedians) { +int MRISmedianFilterVal2baks(MRI_SURFACE *mris, int nmedians) +{ int i, vno, vnb, *pnb, vnum, num; float val_list[MAX_NEIGHBORS]; VERTEX *v, *vn; @@ -28146,7 +28744,8 @@ int MRISmedianFilterVal2baks(MRI_SURFACE *mris, int nmedians) { qsort(val_list, num, sizeof(val_list[0]), compare_sort_vals); if (ISODD(num)) { v->tdx = val_list[(num - 1) / 2]; - } else { + } + else { v->tdx = (val_list[num / 2] + val_list[num / 2 - 1]) / 2; } } @@ -28167,7 +28766,8 @@ int MRISmedianFilterVal2baks(MRI_SURFACE *mris, int nmedians) { Description ------------------------------------------------------*/ -int MRISaverageVal2s(MRI_SURFACE *mris, int navgs) { +int MRISaverageVal2s(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float val, num; VERTEX *v, *vn; @@ -28209,7 +28809,8 @@ int MRISaverageVal2s(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISaverageVal2baks(MRI_SURFACE *mris, int navgs) { +int MRISaverageVal2baks(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float val, num; VERTEX *v, *vn; @@ -28251,7 +28852,8 @@ int MRISaverageVal2baks(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISscaleCurvatures(MRI_SURFACE *mris, float min_curv, float max_curv) { +int MRISscaleCurvatures(MRI_SURFACE *mris, float min_curv, float max_curv) +{ double old_min_curv, old_max_curv, mean, scale; int vno, vtotal; VERTEX *v; @@ -28293,7 +28895,8 @@ int MRISscaleCurvatures(MRI_SURFACE *mris, float min_curv, float max_curv) { Description ------------------------------------------------------*/ -int MRISnonmaxSuppress(MRI_SURFACE *mris) { +int MRISnonmaxSuppress(MRI_SURFACE *mris) +{ double du, dv, up1, um1, vp1, vm1, src, dx, dy, dz, fp1, fm1, mag; VERTEX *v; int vno; @@ -28360,7 +28963,8 @@ int MRISnonmaxSuppress(MRI_SURFACE *mris) { if (FZERO(mag)) /* zero gradient */ { v->curv = 0; - } else { + } + else { mag *= .1; dx = dx / mag; dy = dy / mag; @@ -28372,10 +28976,12 @@ int MRISnonmaxSuppress(MRI_SURFACE *mris) { if ((src >= fp1) && (src >= fm1)) /* local max */ { v->curv = 1; - } else if ((src <= fp1) && (src <= fm1)) /* local min */ + } + else if ((src <= fp1) && (src <= fm1)) /* local min */ { v->curv = -1; - } else { + } + else { v->curv = 0; } v->curv = src; @@ -28391,7 +28997,8 @@ int MRISnonmaxSuppress(MRI_SURFACE *mris) { Description same as below, but tracks odx,ody,odz fields ------------------------------------------------------*/ -static int mrisTrackTotalDistanceNew(MRI_SURFACE *mris) { +static int mrisTrackTotalDistanceNew(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float nc; @@ -28413,7 +29020,8 @@ static int mrisTrackTotalDistanceNew(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisTrackTotalDistance(MRI_SURFACE *mris) { +static int mrisTrackTotalDistance(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float nc; @@ -28435,7 +29043,8 @@ static int mrisTrackTotalDistance(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISclearCurvature(MRI_SURFACE *mris) { +int MRISclearCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -28455,7 +29064,8 @@ int MRISclearCurvature(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISrigidBodyAlignLocal(MRI_SURFACE *mris, INTEGRATION_PARMS *old_parms) { +int MRISrigidBodyAlignLocal(MRI_SURFACE *mris, INTEGRATION_PARMS *old_parms) +{ int old_status, steps; INTEGRATION_PARMS parms; @@ -28496,7 +29106,8 @@ int MRISrigidBodyAlignLocal(MRI_SURFACE *mris, INTEGRATION_PARMS *old_parms) { return (NO_ERROR); } -int MRISrigidBodyAlignVectorLocal(MRI_SURFACE *mris, INTEGRATION_PARMS *old_parms) { +int MRISrigidBodyAlignVectorLocal(MRI_SURFACE *mris, INTEGRATION_PARMS *old_parms) +{ int n, old_status, steps; INTEGRATION_PARMS parms; @@ -28556,7 +29167,8 @@ int MRISrigidBodyAlignVectorLocal(MRI_SURFACE *mris, INTEGRATION_PARMS *old_parm #define NANGLES 8 int MRISrigidBodyAlignGlobal( - MRI_SURFACE *mris, INTEGRATION_PARMS *parms, float min_degrees, float max_degrees, int nangles) { + MRI_SURFACE *mris, INTEGRATION_PARMS *parms, float min_degrees, float max_degrees, int nangles) +{ double alpha, beta, gamma, degrees, delta, mina, minb, ming, sse, min_sse, ext_sse; int old_status = mris->status, old_norm, msec; struct timeb mytimer; @@ -28702,7 +29314,8 @@ int MRISrigidBodyAlignGlobal( } int MRISrigidBodyAlignVectorGlobal( - MRI_SURFACE *mris, INTEGRATION_PARMS *parms, float min_degrees, float max_degrees, int nangles) { + MRI_SURFACE *mris, INTEGRATION_PARMS *parms, float min_degrees, float max_degrees, int nangles) +{ double alpha, beta, gamma, degrees, delta, mina, minb, ming, sse, min_sse; int old_status = mris->status; @@ -28812,7 +29425,8 @@ int MRISrigidBodyAlignVectorGlobal( Description ------------------------------------------------------*/ -double MRISrmsTPHeight(MRI_SURFACE *mris) { +double MRISrmsTPHeight(MRI_SURFACE *mris) +{ int vno, i, total_nbrs; VERTEX *vertex, *vnb; double avg_height, dot, nx, ny, nz, x, y, z, d; @@ -28872,7 +29486,8 @@ double MRISrmsTPHeight(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISzeroNegativeAreas(MRI_SURFACE *mris) { +int MRISzeroNegativeAreas(MRI_SURFACE *mris) +{ int vno, fno; VERTEX *v; FACE *face; @@ -28904,7 +29519,8 @@ int MRISzeroNegativeAreas(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISfindClosestVertex(MRI_SURFACE *mris, float x, float y, float z, float *dmin) { +int MRISfindClosestVertex(MRI_SURFACE *mris, float x, float y, float z, float *dmin) +{ int vno, min_v = -1; VERTEX *v; float d, min_d, dx, dy, dz; @@ -28936,7 +29552,8 @@ int MRISfindClosestVertex(MRI_SURFACE *mris, float x, float y, float z, float *d Description ------------------------------------------------------*/ -int MRISfindClosestOriginalVertex(MRI_SURFACE *mris, float x, float y, float z) { +int MRISfindClosestOriginalVertex(MRI_SURFACE *mris, float x, float y, float z) +{ int vno, min_v = -1; VERTEX *v; float d, min_d, dx, dy, dz; @@ -28969,7 +29586,8 @@ int MRISfindClosestOriginalVertex(MRI_SURFACE *mris, float x, float y, float z) Description ------------------------------------------------------*/ -int MRISfindClosestCanonicalVertex(MRI_SURFACE *mris, float x, float y, float z) { +int MRISfindClosestCanonicalVertex(MRI_SURFACE *mris, float x, float y, float z) +{ int vno, min_v = -1; VERTEX *v; float d, min_d, dx, dy, dz; @@ -28999,7 +29617,8 @@ int MRISfindClosestCanonicalVertex(MRI_SURFACE *mris, float x, float y, float z) Description ------------------------------------------------------*/ -int MRISfindClosestWhiteVertex(MRI_SURFACE *mris, float x, float y, float z) { +int MRISfindClosestWhiteVertex(MRI_SURFACE *mris, float x, float y, float z) +{ int vno, min_v = -1; VERTEX *v; float d, min_d, dx, dy, dz; @@ -29029,7 +29648,8 @@ int MRISfindClosestWhiteVertex(MRI_SURFACE *mris, float x, float y, float z) { Description ------------------------------------------------------*/ -int MRISuseCurvatureDifference(MRI_SURFACE *mris) { +int MRISuseCurvatureDifference(MRI_SURFACE *mris) +{ int vno; VERTEX *vertex; float kmin, kmax; @@ -29061,7 +29681,8 @@ int MRISuseCurvatureDifference(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISuseCurvatureMax(MRI_SURFACE *mris) { +int MRISuseCurvatureMax(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float kmin, kmax; @@ -29075,7 +29696,8 @@ int MRISuseCurvatureMax(MRI_SURFACE *mris) { } if (fabs(v->k1) > fabs(v->k2)) { v->curv = v->k1; - } else { + } + else { v->curv = v->k2; } /* v->curv = MAX(fabs(v->k1), fabs(v->k2)) ;*/ @@ -29102,7 +29724,8 @@ int MRISuseCurvatureMax(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISuseCurvatureMin(MRI_SURFACE *mris) { +int MRISuseCurvatureMin(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float kmin, kmax; @@ -29116,7 +29739,8 @@ int MRISuseCurvatureMin(MRI_SURFACE *mris) { } if (fabs(v->k1) > fabs(v->k2)) { v->curv = v->k2; - } else { + } + else { v->curv = v->k1; } /* v->curv = MIN(v->k1, v->k2) ;*/ @@ -29142,7 +29766,8 @@ int MRISuseCurvatureMin(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISuseCurvatureStretch(MRI_SURFACE *mris) { +int MRISuseCurvatureStretch(MRI_SURFACE *mris) +{ int vno, n; VERTEX *v; float kmin, kmax, dist, dist_orig, curv, dist_scale, max_stretch, stretch; @@ -29187,7 +29812,8 @@ int MRISuseCurvatureStretch(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISuseNegCurvature(MRI_SURFACE *mris) { +int MRISuseNegCurvature(MRI_SURFACE *mris) +{ int vno, fno; VERTEX *v; FACE *f; @@ -29218,7 +29844,8 @@ int MRISuseNegCurvature(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ // get the vertex number -int MRIStalairachToVertex(MRI_SURFACE *mris, double xt, double yt, double zt) { +int MRIStalairachToVertex(MRI_SURFACE *mris, double xt, double yt, double zt) +{ int vno; double xw, yw, zw; @@ -29238,7 +29865,8 @@ int MRIStalairachToVertex(MRI_SURFACE *mris, double xt, double yt, double zt) { Description ------------------------------------------------------*/ -int MRIScanonicalToVertex(MRI_SURFACE *mris, double phi, double theta) { +int MRIScanonicalToVertex(MRI_SURFACE *mris, double phi, double theta) +{ int vno; double xw, yw, zw; @@ -29254,7 +29882,8 @@ int MRIScanonicalToVertex(MRI_SURFACE *mris, double phi, double theta) { Description ------------------------------------------------------*/ int MRISsurfaceRASToTalairachVoxel( - MRI_SURFACE *mris, MRI *mri, double xw, double yw, double zw, double *pxv, double *pyv, double *pzv) { + MRI_SURFACE *mris, MRI *mri, double xw, double yw, double zw, double *pxv, double *pyv, double *pzv) +{ // conformed --> SRAS // | | // | | SRASToRAS @@ -29315,7 +29944,8 @@ int MRISsurfaceRASToTalairachVoxel( Description ------------------------------------------------------*/ -int MRISvertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, double *pyv, double *pzv) { +int MRISvertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, double *pyv, double *pzv) +{ double xw, yw, zw; xw = v->x; @@ -29325,7 +29955,8 @@ int MRISvertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, doubl return (NO_ERROR); } -int MRISvertexNormalToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pnx, double *pny, double *pnz) { +int MRISvertexNormalToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pnx, double *pny, double *pnz) +{ double xw, yw, zw; double xv0, yv0, zv0, xv1, yv1, zv1; @@ -29342,7 +29973,8 @@ int MRISvertexNormalToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pnx, *pnz = zv1 - zv0; return (NO_ERROR); } -int MRISvertexNormalToVoxelScaled(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pnx, double *pny, double *pnz) { +int MRISvertexNormalToVoxelScaled(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pnx, double *pny, double *pnz) +{ double nx, ny, nz, len; MRISvertexNormalToVoxel(mris, v, mri, &nx, &ny, &nz); @@ -29360,7 +29992,8 @@ int MRISvertexNormalToVoxelScaled(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double Description ------------------------------------------------------*/ -int MRISvertexCoordToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, int coords, double *pxv, double *pyv, double *pzv) { +int MRISvertexCoordToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, int coords, double *pxv, double *pyv, double *pzv) +{ double xw = 0., yw = 0., zw = 0.; MRISgetCoords(v, coords, &xw, &yw, &zw); @@ -29374,7 +30007,8 @@ int MRISvertexCoordToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, int coords, d Description ------------------------------------------------------*/ -int MRISorigVertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, double *pyv, double *pzv) { +int MRISorigVertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, double *pyv, double *pzv) +{ double xw, yw, zw; xw = v->origx; @@ -29390,7 +30024,8 @@ int MRISorigVertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, d Description ------------------------------------------------------*/ -int MRISwhiteVertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, double *pyv, double *pzv) { +int MRISwhiteVertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, double *pyv, double *pzv) +{ double xw, yw, zw; xw = v->whitex; @@ -29406,7 +30041,8 @@ int MRISwhiteVertexToVoxel(MRI_SURFACE *mris, VERTEX *v, MRI *mri, double *pxv, Description ------------------------------------------------------*/ -int MRISaverageVertexPositions(MRI_SURFACE *mris, int navgs) { +int MRISaverageVertexPositions(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float x, y, z, num; VERTEX *v, *vn; @@ -29456,7 +30092,8 @@ int MRISaverageVertexPositions(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISaverageEveryOtherVertexPositions(MRI_SURFACE *mris, int navgs, int which) { +int MRISaverageEveryOtherVertexPositions(MRI_SURFACE *mris, int navgs, int which) +{ int i, vno, vnb, *pnb, vnum; float x, y, z, num; VERTEX *v, *vn; @@ -29500,7 +30137,8 @@ int MRISaverageEveryOtherVertexPositions(MRI_SURFACE *mris, int navgs, int which } return (NO_ERROR); } -static int mrisCountCompressed(MRI_SURFACE *mris, double min_dist) { +static int mrisCountCompressed(MRI_SURFACE *mris, double min_dist) +{ int vno, n, num; VERTEX *v, *vn; double d, dx, dy, dz; @@ -29530,7 +30168,8 @@ static int mrisCountCompressed(MRI_SURFACE *mris, double min_dist) { return (num); } -static int mrisComputePlaneTerm(MRI_SURFACE *mris, double l_plane, double l_spacing) { +static int mrisComputePlaneTerm(MRI_SURFACE *mris, double l_plane, double l_spacing) +{ int vno, n, vnum; MATRIX *M, *m_evectors; VERTEX *v, *vn; @@ -29657,7 +30296,8 @@ int mrisComputeOptimalPlane(MRI_SURFACE *mris, double *pzn, double *pxc, double *pyc, - double *pzc) { + double *pzc) +{ int vno, n, vnum; MATRIX *M, *m_evectors; VERTEX *v; @@ -29727,7 +30367,8 @@ int mrisComputeOptimalPlane(MRI_SURFACE *mris, return (NO_ERROR); } -int MRISremoveCompressedRegions(MRI_SURFACE *mris, double min_dist) { +int MRISremoveCompressedRegions(MRI_SURFACE *mris, double min_dist) +{ int compressed, iters = 0, old_compressed, n_averages, nsize; MHT *mht = NULL; double delta_t, l_spring, l_convex, l_max_spring; @@ -29766,7 +30407,8 @@ int MRISremoveCompressedRegions(MRI_SURFACE *mris, double min_dist) { MRISclearGradient(mris); if ((parms.flags & IPFLAG_NO_SELF_INT_TEST) == 0) { mht = MHTfillTable(mris, mht); - } else { + } + else { mht = NULL; } if (Gdiag_no >= 0 && DIAG_VERBOSE_ON) { @@ -29820,7 +30462,8 @@ int MRISremoveCompressedRegions(MRI_SURFACE *mris, double min_dist) { #define MAX_REDUCTIONS 2 #define REDUCTION_PCT 0.5 -int MRISpositionSurfaces(MRI_SURFACE *mris, MRI **mri_flash, int nvolumes, INTEGRATION_PARMS *parms) { +int MRISpositionSurfaces(MRI_SURFACE *mris, MRI **mri_flash, int nvolumes, INTEGRATION_PARMS *parms) +{ /* char *cp ;*/ int niterations, n, write_iterations, nreductions = 0, ripped = 0, increased = 0; double pial_sse, sse, wm_sse, delta_t = 0.0, dt, l_intensity, base_dt, last_sse, rms, mle_sse, last_mle_sse, @@ -29845,7 +30488,8 @@ int MRISpositionSurfaces(MRI_SURFACE *mris, MRI **mri_flash, int nvolumes, INTEG sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -30020,7 +30664,8 @@ int MRISpositionSurfaces(MRI_SURFACE *mris, MRI **mri_flash, int nvolumes, INTEG break; } n--; /* don't count this as a time step */ - } else { + } + else { printf( "error decreased by %2.4f%% - " "%dth time step reduction: dt=%2.3f\n", @@ -30048,7 +30693,8 @@ int MRISpositionSurfaces(MRI_SURFACE *mris, MRI **mri_flash, int nvolumes, INTEG n++; break; } - } else { + } + else { last_mle_sse = mle_sse; increased = 0; } @@ -30146,7 +30792,8 @@ int MRISpositionSurfaces(MRI_SURFACE *mris, MRI **mri_flash, int nvolumes, INTEG return (NO_ERROR); } -int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTEGRATION_PARMS *parms) { +int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTEGRATION_PARMS *parms) +{ /* char *cp ;*/ int avgs, niterations, n, write_iterations, nreductions = 0, done; double sse, delta_t = 0.0, rms, dt, l_intensity, base_dt, last_sse, last_rms, max_mm; @@ -30182,7 +30829,8 @@ int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTE parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -30210,7 +30858,8 @@ int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTE avgs = parms->n_averages; if (!FZERO(parms->l_histo)) { last_rms = rms = mrisComputeHistoNegativeLikelihood(mris, parms); - } else if (!FZERO(parms->l_map)) { + } + else if (!FZERO(parms->l_map)) { int nvox; MRISsaveVertexPositions(mris, PIAL_VERTICES); if (parms->mri_volume_fractions) MRIfree(&parms->mri_volume_fractions); @@ -30220,7 +30869,8 @@ int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTE rms = mrisComputeNegativeLogPosterior(mris, parms, &nvox); // last_rms = rms = 1-exp(-rms/nvox) ; last_rms = rms = sqrt(rms / nvox); - } else if (!FZERO(parms->l_map2d)) { + } + else if (!FZERO(parms->l_map2d)) { int nvox; MRISsaveVertexPositions(mris, PIAL_VERTICES); #if 0 @@ -30232,21 +30882,25 @@ int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTE if ((getenv("READ_VOLS") != NULL)) { parms->mri_volume_fractions = MRIread("map2d.vfrac.0000.mgz"); parms->mri_dtrans = MRIread("dtrans.mgz"); - } else + } + else parms->mri_volume_fractions = MRIcomputeLaminarVolumeFractions(mris, parms->resolution, parms->mri_brain, NULL); rms = mrisComputeNegativeLogPosterior2D(mris, parms, &nvox); // last_rms = rms = 1-exp(-rms/nvox) ; last_rms = rms = sqrt(rms / nvox); - } else if (!FZERO(parms->l_location)) { + } + else if (!FZERO(parms->l_location)) { last_rms = rms = mrisRmsDistanceError(mris); - } else { + } + else { last_rms = rms = mrisRmsValError(mris, mri_brain); } last_sse = sse = MRIScomputeSSE(mris, parms); if (DZERO(parms->l_histo) == 0) { last_rms = rms = mrisComputeHistoNegativeLikelihood(mris, parms); - } else if (DZERO(parms->l_intensity) && gMRISexternalRMS != NULL && parms->l_external > 0) { + } + else if (DZERO(parms->l_intensity) && gMRISexternalRMS != NULL && parms->l_external > 0) { last_rms = rms = (*gMRISexternalRMS)(mris, parms); } #if 0 @@ -30395,14 +31049,16 @@ int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTE MRIScomputeMetricProperties(mris); if (!FZERO(parms->l_histo)) { rms = mrisComputeHistoNegativeLikelihood(mris, parms); - } else if (!FZERO(parms->l_map)) { + } + else if (!FZERO(parms->l_map)) { int nvox; MRISsaveVertexPositions(mris, PIAL_VERTICES); if (parms->mri_volume_fractions) MRIfree(&parms->mri_volume_fractions); parms->mri_volume_fractions = MRIcomputeLaminarVolumeFractions(mris, parms->resolution, parms->mri_brain, NULL); rms = mrisComputeNegativeLogPosterior(mris, parms, &nvox); rms = sqrt(rms / nvox); - } else if (!FZERO(parms->l_map2d)) { + } + else if (!FZERO(parms->l_map2d)) { int nvox; MRISsaveVertexPositions(mris, PIAL_VERTICES); #if 0 @@ -30414,11 +31070,14 @@ int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTE parms->mri_volume_fractions = MRIcomputeLaminarVolumeFractions(mris, parms->resolution, parms->mri_brain, NULL); rms = mrisComputeNegativeLogPosterior2D(mris, parms, &nvox); rms = sqrt(rms / nvox); - } else if (!FZERO(parms->l_location)) { + } + else if (!FZERO(parms->l_location)) { rms = mrisRmsDistanceError(mris); - } else if (DZERO(parms->l_intensity) && gMRISexternalRMS != NULL && parms->l_external > 0) { + } + else if (DZERO(parms->l_intensity) && gMRISexternalRMS != NULL && parms->l_external > 0) { rms = (*gMRISexternalRMS)(mris, parms); - } else { + } + else { rms = mrisRmsValError(mris, mri_brain); } sse = MRIScomputeSSE(mris, parms); @@ -30560,7 +31219,8 @@ int MRISpositionSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTE } int MRISpositionSurface_mef( - MRI_SURFACE *mris, MRI *mri_30, MRI *mri_5, INTEGRATION_PARMS *parms, float weight30, float weight5) { + MRI_SURFACE *mris, MRI *mri_30, MRI *mri_5, INTEGRATION_PARMS *parms, float weight30, float weight5) +{ /* char *cp ;*/ int avgs, niterations, n, write_iterations, nreductions = 0, done; double delta_t = 0.0, rms, dt, l_intensity, base_dt, last_rms, max_mm, sse, last_sse, delta_rms; @@ -30593,7 +31253,8 @@ int MRISpositionSurface_mef( sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -30678,7 +31339,8 @@ int MRISpositionSurface_mef( #if 1 if (parms->check_tol) { delta_rms = parms->tol * last_rms; - } else { + } + else { delta_rms = 0.05; // don't worry about energy functional decreasing, just continue } if (parms->check_tol && (rms > last_rms - delta_rms)) // error increased - reduce step size @@ -30766,7 +31428,8 @@ int MRISpositionSurface_mef( return (NO_ERROR); } -int MRISmoveSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTEGRATION_PARMS *parms) { +int MRISmoveSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTEGRATION_PARMS *parms) +{ /* char *cp ;*/ double sse_before, sse_after, rms_before, rms_after; MHT *mht = NULL; @@ -30785,7 +31448,8 @@ int MRISmoveSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTEGRAT sprintf(fname, "%s.%s.out", mris->hemisphere == RIGHT_HEMISPHERE ? "rh" : "lh", parms->base_name); if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } if (!parms->fp) ErrorExit(ERROR_NOFILE, "%s: could not open log file %s", Progname, fname); @@ -30862,7 +31526,8 @@ int MRISmoveSurface(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, INTEGRAT Description ------------------------------------------------------*/ -MRI *MRISwriteSurfaceIntoVolume(MRI_SURFACE *mris, MRI *mri_template, MRI *mri) { +MRI *MRISwriteSurfaceIntoVolume(MRI_SURFACE *mris, MRI *mri_template, MRI *mri) +{ int fno; if (!mri) { @@ -30875,7 +31540,8 @@ MRI *MRISwriteSurfaceIntoVolume(MRI_SURFACE *mris, MRI *mri_template, MRI *mri) mri->yend = mri_template->yend; mri->zstart = mri_template->zstart; mri->zend = mri_template->zend; - } else { + } + else { MRIclear(mri); } @@ -30926,7 +31592,8 @@ static int mrisFillFace(MRI_SURFACE *mris, MRI *mri, int fno) { return (mrisHatc ------------------------------------------------------*/ #define SAMPLE_DIST 0.25 -static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { +static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) +{ double x, y, z, xa, ya, za, xc, yc, zc, t0, t1, adx, ady, adz, dx, dy, dz, cdx, cdy, cdz, alen, clen, delta_t0, delta_t1, len; int xv, yv, zv, i; @@ -30982,7 +31649,8 @@ static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { */ if (FZERO(alen) && FZERO(clen)) { delta_t0 = 0.99; - } else + } + else delta_t0 = (alen > clen) ? (SAMPLE_DIST / alen) : (SAMPLE_DIST / clen); if (FZERO(delta_t0)) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "mrisFillFace: face %d has infinite leg (%d, %d)\n", fno, alen, clen)); @@ -31007,7 +31675,8 @@ static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { len = sqrt(SQR(dx) + SQR(dy) + SQR(dz)); if (FZERO(len)) { delta_t1 = 0.99; - } else { + } + else { delta_t1 = SAMPLE_DIST / len; /* sample at SAMPLE_DIST intervals */ if (delta_t1 >= 1.0f) { delta_t1 = 0.99; @@ -31027,7 +31696,8 @@ static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { zv = nint(z); /* voxel coordinate */ if (on) { MRIset_bit(mri, xv, yv, zv); /* mark it filled */ - } else { + } + else { MRIclear_bit(mri, xv, yv, zv); /* mark it empty */ } } @@ -31042,7 +31712,8 @@ static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { zv = nint(z); /* voxel coordinate */ if (on) { MRIset_bit(mri, xv, yv, zv); /* mark it filled */ - } else { + } + else { MRIclear_bit(mri, xv, yv, zv); /* mark it empty */ } } @@ -31061,7 +31732,8 @@ static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { len = sqrt(SQR(dx) + SQR(dy) + SQR(dz)); if (FZERO(len)) { delta_t1 = 0.99; - } else { + } + else { delta_t1 = SAMPLE_DIST / len; /* sample at SAMPLE_DIST intervals */ if (delta_t1 >= 1.0f) { delta_t1 = 0.99; @@ -31081,7 +31753,8 @@ static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { zv = nint(z); /* voxel coordinate */ if (on) { MRIset_bit(mri, xv, yv, zv); /* mark it filled */ - } else { + } + else { MRIclear_bit(mri, xv, yv, zv); /* mark it empty */ } } @@ -31096,7 +31769,8 @@ static int mrisHatchFace(MRI_SURFACE *mris, MRI *mri, int fno, int on) { zv = nint(z); /* voxel coordinate */ if (on) { MRIset_bit(mri, xv, yv, zv); /* mark it filled */ - } else { + } + else { MRIclear_bit(mri, xv, yv, zv); /* mark it empty */ } } @@ -31132,7 +31806,8 @@ mrisEraseFace(MRI_SURFACE *mris, MRI *mri, int fno) ------------------------------------------------------*/ #if 1 -int MRISfindClosestOrigVertices(MRI_SURFACE *mris, int nbhd_size) { +int MRISfindClosestOrigVertices(MRI_SURFACE *mris, int nbhd_size) +{ int vno, n, vlist[100000], vtotal, ns, i, vnum, nbr_count[100], min_n, min_vno; VERTEX *v, *vn, *vn2; float dx, dy, dz, dist, min_dist, nx, ny, nz, dot; @@ -31223,7 +31898,8 @@ int MRISfindClosestOrigVertices(MRI_SURFACE *mris, int nbhd_size) { find the closest pial vertex and use it's spherical coords to initialize the thickness minimization. Put the v->c[xyz] coords of the nearest pial vertex into v->[xyz] of each vertex. */ -int MRISfindClosestPialVerticesCanonicalCoords(MRI_SURFACE *mris, int nbhd_size) { +int MRISfindClosestPialVerticesCanonicalCoords(MRI_SURFACE *mris, int nbhd_size) +{ int vno, n, vlist[100000], vtotal, ns, i, vnum, nbr_count[100], min_n, min_vno; VERTEX *v, *vn, *vn2; float dx, dy, dz, dist, min_dist, nx, ny, nz, dot; @@ -31312,7 +31988,8 @@ int MRISfindClosestPialVerticesCanonicalCoords(MRI_SURFACE *mris, int nbhd_size) } return (NO_ERROR); } -int MRISmeasureCorticalThickness(MRI_SURFACE *mris, int nbhd_size, float max_thick) { +int MRISmeasureCorticalThickness(MRI_SURFACE *mris, int nbhd_size, float max_thick) +{ int vno, n, vlist[100000], vtotal, ns, i, vnum, nbr_count[100], min_n, nwg_bad, ngw_bad; VERTEX *v, *vn, *vn2; float dx, dy, dz, dist, min_dist, nx, ny, nz, dot; @@ -31505,7 +32182,8 @@ int MRISmeasureCorticalThickness(MRI_SURFACE *mris, int nbhd_size, float max_thi } #else #define MAX_THICKNESS 6.0f -int MRISmeasureCorticalThickness(MRI_SURFACE *mris) { +int MRISmeasureCorticalThickness(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float max_out_dist; @@ -31542,7 +32220,8 @@ int MRISmeasureCorticalThickness(MRI_SURFACE *mris) { dz = v->z - v->origz; v->curv = sqrt(dx * dx + dy * dy + dz * dz); v->marked = 1; - } else { + } + else { v->curv = max_out_dist; } } @@ -31761,7 +32440,8 @@ mrisFindNormalDistance(MRI_SURFACE *mris, MHT *mht, int vno, double max_dist, in given location. ------------------------------------------------------*/ static int mrisDirectionTriangleIntersection( - MRI_SURFACE *mris, float x0, float y0, float z0, float nx, float ny, float nz, MHT *mht, double *pdist, int vno) { + MRI_SURFACE *mris, float x0, float y0, float z0, float nx, float ny, float nz, MHT *mht, double *pdist, int vno) +{ double dist, min_dist, U0[3], U1[3], U2[3], pt[3], dir[3], int_pt[3], dot; float x, y, z, dx, dy, dz; MHBT *bucket; @@ -31914,7 +32594,8 @@ mrisNormalDirectionTriangleIntersection(MRI_SURFACE *mris, VERTEX *v, given location. ------------------------------------------------------*/ static int mrisAllNormalDirectionCurrentTriangleIntersections( - MRI_SURFACE *mris, VERTEX *v, MHT *mht, double *pdist, int *flist) { + MRI_SURFACE *mris, VERTEX *v, MHT *mht, double *pdist, int *flist) +{ double dist, min_dist, U0[3], U1[3], U2[3], pt[3], dir[3], int_pt[3]; float nx, ny, nz, x, y, z, dx, dy, dz, dot; MHBT *bucket; @@ -32035,7 +32716,8 @@ mrisAllCurrentTriangleIntersections(MRI_SURFACE *mris, float x, float y, } #endif -static int load_orig_triangle_vertices(MRI_SURFACE *mris, int fno, double U0[3], double U1[3], double U2[3]) { +static int load_orig_triangle_vertices(MRI_SURFACE *mris, int fno, double U0[3], double U1[3], double U2[3]) +{ VERTEX *v; FACE *face; @@ -32054,7 +32736,8 @@ static int load_orig_triangle_vertices(MRI_SURFACE *mris, int fno, double U0[3], U2[2] = v->origz; return (NO_ERROR); } -static int load_triangle_vertices(MRI_SURFACE *mris, int fno, double U0[3], double U1[3], double U2[3], int which) { +static int load_triangle_vertices(MRI_SURFACE *mris, int fno, double U0[3], double U1[3], double U2[3], int which) +{ VERTEX *v; FACE *face; @@ -32174,7 +32857,8 @@ mrisFindClosestFilledVoxel(MRI_SURFACE *mris, MRI *mri_filled, int vno, Description ------------------------------------------------------*/ -int MRISsoapBubbleVertexPositions(MRI_SURFACE *mris, int navgs) { +int MRISsoapBubbleVertexPositions(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum, n; float x, y, z, num; VERTEX *v, *vn; @@ -32282,7 +32966,8 @@ int MRISsoapBubbleVertexPositions(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISweightedSoapBubbleVertexPositions(MRI_SURFACE *mris, int navgs) { +int MRISweightedSoapBubbleVertexPositions(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum, n; float x, y, z; VERTEX *v, *vn; @@ -32432,7 +33117,8 @@ int MRISweightedSoapBubbleVertexPositions(MRI_SURFACE *mris, int navgs) { Description ------------------------------------------------------*/ -int MRISsoapBubbleOrigVertexPositions(MRI_SURFACE *mris, int navgs) { +int MRISsoapBubbleOrigVertexPositions(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float x, y, z, num; VERTEX *v, *vn; @@ -32516,7 +33202,8 @@ int MRISsoapBubbleOrigVertexPositions(MRI_SURFACE *mris, int navgs) { } return (NO_ERROR); } -int MRISsoapBubbleTargetVertexPositions(MRI_SURFACE *mris, int navgs) { +int MRISsoapBubbleTargetVertexPositions(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float x, y, z, num; VERTEX *v, *vn; @@ -32676,7 +33363,8 @@ MRISsoapBubbleVertexPositions(MRI_SURFACE *mris, int navgs, float pct_fixed) Description ------------------------------------------------------*/ -int MRISmarkRandomVertices(MRI_SURFACE *mris, float prob_marked) { +int MRISmarkRandomVertices(MRI_SURFACE *mris, float prob_marked) +{ int vno; VERTEX *v; float r; @@ -32700,7 +33388,8 @@ int MRISmarkRandomVertices(MRI_SURFACE *mris, float prob_marked) { Description ------------------------------------------------------*/ -int MRISclearMarks(MRI_SURFACE *mris) { +int MRISclearMarks(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -32714,7 +33403,8 @@ int MRISclearMarks(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISclearFaceMarks(MRIS *mris) { +int MRISclearFaceMarks(MRIS *mris) +{ int fno; FACE *f; @@ -32732,7 +33422,8 @@ int MRISclearFaceMarks(MRIS *mris) { Description ------------------------------------------------------*/ -int MRISclearFixedValFlags(MRI_SURFACE *mris) { +int MRISclearFixedValFlags(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -32752,7 +33443,8 @@ int MRISclearFixedValFlags(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyFixedValFlagsToMarks(MRI_SURFACE *mris) { +int MRIScopyFixedValFlagsToMarks(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -32772,7 +33464,8 @@ int MRIScopyFixedValFlagsToMarks(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISclearAnnotations(MRI_SURFACE *mris) { +int MRISclearAnnotations(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -32792,7 +33485,8 @@ int MRISclearAnnotations(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISsetMarks(MRI_SURFACE *mris, int mark) { +int MRISsetMarks(MRI_SURFACE *mris, int mark) +{ int vno; VERTEX *v; @@ -32812,7 +33506,8 @@ int MRISsetMarks(MRI_SURFACE *mris, int mark) { Description ------------------------------------------------------*/ -int MRISsequentialAverageVertexPositions(MRI_SURFACE *mris, int navgs) { +int MRISsequentialAverageVertexPositions(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float x, y, z, num; VERTEX *v, *vn; @@ -32963,7 +33658,8 @@ mrisComputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, #if 1 #define MAX_CSF 55.0f #define STEP_SIZE 0.1 -int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth) { +int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth) +{ double val, x, y, z, min_val, xw, yw, zw, mag, max_mag, xw1, yw1, zw1, previous_val, next_val; int total_vertices, vno, nmissing = 0; float mean_white, dist, nx, ny, nz; @@ -33045,7 +33741,8 @@ int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_sm mean_white += min_val; total_vertices++; v->marked = 1; - } else { + } + else { nmissing++; } if (vno == Gdiag_no) fprintf(stdout, "v %d, target value = %2.1f, mag = %2.1f\n", Gdiag_no, v->val, v->mean); @@ -33066,7 +33763,8 @@ Returns value: Description ------------------------------------------------------*/ -int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_wm, float nsigma) { +int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_wm, float nsigma) +{ double val, x, y, z; int total_vertices, vno, xv, yv, zv, xo, yo, zo, xi, yi, zi, nwhite_vox, ngray_vox; float total_white, total_gray, total_sq_white, total_sq_gray, std_white, mean_white, mean_gray, total_mean_gray, @@ -33110,7 +33808,8 @@ int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_wm total_white += val; total_sq_white += val * val; nwhite_vox++; - } else /* gray matter */ + } + else /* gray matter */ { if (MRIneighborsOn(mri_wm, xi, yi, zi, WM_MIN_VAL + 1) == 0) { continue; /* not a border voxel */ @@ -33127,7 +33826,8 @@ int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_wm } if (!nwhite_vox || !ngray_vox) { v->val = 0.0f; - } else { + } + else { mean_white = total_white / (float)nwhite_vox; mean_gray = total_gray / (float)ngray_vox; std_white = sqrt(total_sq_white / (float)nwhite_vox - mean_white * mean_white); @@ -33138,7 +33838,8 @@ int MRIScomputeWhiteSurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_wm if (DIAG_VERBOSE_ON) fprintf(stdout, "mean gray (%2.1f) > mean white (%2.1f) at v %d!\n", mean_gray, mean_white, vno); v->val = mean_white; - } else + } + else v->val = (std_gray * mean_white + std_white * mean_gray) / (std_gray + std_white); total_vertices++; total_mean_white += mean_white; @@ -33194,7 +33895,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, MRI *mri_mask, double thresh, int flags, - MRI *mri_aseg) { + MRI *mri_aseg) +{ double val, x, y, z, max_mag_val, xw, yw, zw, mag, max_mag, max_mag_dist = 0.0f, previous_val, next_val, min_val, inward_dist, outward_dist, xw1, yw1, zw1, min_val_dist, orig_dist, dx, dy, dz, previous_mag, next_mag; @@ -33210,7 +33912,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, step_size = mri_brain->xsize / 2; if (mri_brain->type == MRI_UCHAR) { mri_tmp = MRIreplaceValues(mri_brain, NULL, 255, 0); - } else { + } + else { mri_tmp = MRIcopy(mri_brain, NULL); } @@ -33522,7 +34225,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, max_mag = fabs(mag); max_mag_val = val; } - } else { + } + else { /* if no local max found yet, just used largest gradient if the intensity is in the right range. @@ -33570,7 +34274,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, } if (i < len - 1 && i > 0) { dm[i] = mri[i + 1] - mri[i - 1]; - } else { + } + else { dm[i] = 0; } } @@ -33620,7 +34325,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, max_mag_val = mri[i]; max_mag = fabs(dm[i]); max_mag_dist = dists[i]; - } else if (flags & IPFLAG_FIND_FIRST_WM_PEAK) // not a local max in 1st derivative - try second */ + } + else if (flags & IPFLAG_FIND_FIRST_WM_PEAK) // not a local max in 1st derivative - try second */ { for (i = 0; i < len; i++) { if (i == Gdiag_no2) DiagBreak(); @@ -33708,14 +34414,16 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, { if (local_max_found) { ngrad_max++; - } else { + } + else { ngrad++; } if (max_mag_dist > 0) { nout++; nfound++; mean_out += max_mag_dist; - } else { + } + else { nin++; nfound++; mean_in -= max_mag_dist; @@ -33731,7 +34439,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, total_vertices++; v->d = max_mag_dist; v->marked = 1; - } else /* couldn't find the border value */ + } + else /* couldn't find the border value */ { if (min_val < 1000) { nmin++; @@ -33754,7 +34463,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, mean_border += min_val; total_vertices++; v->marked = 1; - } else { + } + else { /* don't overwrite old target intensity if it was there */ /* v->val = -1.0f ;*/ v->d = 0; @@ -33764,7 +34474,8 @@ int MRIScomputeBorderValues(MRI_SURFACE *mris, v->val = (border_low+border_hi)/2 ; #endif v->marked = 0; - } else { + } + else { v->marked = 1; } nmissing++; @@ -33854,7 +34565,8 @@ int MRIScomputeInvertedGrayWhiteBorderValues(MRI_SURFACE *mris, double outside_hi, double sigma, float max_thickness, - FILE *log_fp) { + FILE *log_fp) +{ double val, x, y, z, xw, yw, zw, dist, prev_val, next_val; int total_vertices, vno, inward_increasing, ngray, nwhite; VERTEX *v; @@ -33948,7 +34660,8 @@ int MRIScomputeMaxGradBorderValues(MRI_SURFACE *mris, float dir, FILE *log_fp, MRI *mri_wm, - int callno) { + int callno) +{ int total_vertices, vno, n, num, found; VERTEX *v, *vn; double x, y, z, xv, yv, zv, dist, grad, max_grad, max_grad_dist, sigma_vox, nx, ny, nz, sample_dist, mag, @@ -33966,7 +34679,8 @@ int MRIScomputeMaxGradBorderValues(MRI_SURFACE *mris, if (0) { // mri_median = MRImedian(mri_brain, NULL, 3, &box) ; // MRIwrite(mri_median, "median.mgz") ; - } else { + } + else { mri_median = mri_brain; } @@ -34021,10 +34735,12 @@ int MRIScomputeMaxGradBorderValues(MRI_SURFACE *mris, if (min_val > min_wm_val) { min_val = val; - } else { + } + else { DiagBreak(); } - } else { + } + else { min_val = val; } } @@ -34105,7 +34821,8 @@ int MRIScomputeMaxGradBorderValues(MRI_SURFACE *mris, { wm_hi = wm_mean + 10 * wm_std; wm_lo = wm_mean - 2 * wm_std; - } else { + } + else { wm_hi = wm_mean + 2 * wm_std; wm_lo = wm_mean - 7 * wm_std; } @@ -34175,7 +34892,8 @@ int MRIScomputeMaxGradBorderValues(MRI_SURFACE *mris, wm_hi); v->val = max_grad_val; v->marked = 1; - } else { + } + else { v->marked = 0; if (vno == Gdiag_no) { printf("v %d: could not find valid gradient maximum\n", vno); @@ -34207,7 +34925,8 @@ int MRIScomputeMaxGradBorderValuesPial(MRI_SURFACE *mris, float dir, FILE *log_fp, int callno, - MRI *mri_mask) { + MRI *mri_mask) +{ int total_vertices, vno, n, num, found; VERTEX *v, *vn; double x, y, z, xv, yv, zv, dist, grad, max_grad, max_grad_dist, sigma_vox, xm, ym, zm, nx, ny, nz, sample_dist, mag, @@ -34236,7 +34955,8 @@ int MRIScomputeMaxGradBorderValuesPial(MRI_SURFACE *mris, if (0) { // mri_median = MRImedian(mri_brain, NULL, 3, &box) ; // MRIwrite(mri_median, "median.mgz") ; - } else { + } + else { mri_median = mri_brain; } @@ -34378,7 +35098,8 @@ int MRIScomputeMaxGradBorderValuesPial(MRI_SURFACE *mris, { wm_hi = wm_mean + 10 * wm_std; wm_lo = wm_mean - 2 * wm_std; - } else { + } + else { wm_hi = wm_mean + 2 * wm_std; wm_lo = wm_mean - 7 * wm_std; } @@ -34416,7 +35137,8 @@ int MRIScomputeMaxGradBorderValuesPial(MRI_SURFACE *mris, if (callno > 0 || dist > max_thickness / 2) { break; } - } else if ((dir * grad > 0) && val < min_val) { + } + else if ((dir * grad > 0) && val < min_val) { min_val = val; found = 1; max_grad_dist = dist; @@ -34498,11 +35220,13 @@ int MRIScomputeMaxGradBorderValuesPial(MRI_SURFACE *mris, MRISsurfaceRASToVoxelCached(mris, mri_brain, v->tx, v->ty, v->tz, &xv, &yv, &zv); if (MRIindexNotInVolume(mri_targets, xv, yv, zv) == 0) { MRIsetVoxVal(mri_targets, xv, yv, zv, 0, 1.0); - } else { + } + else { DiagBreak(); } v->marked = 1; - } else { + } + else { v->marked = 0; if (vno == Gdiag_no) { printf("v %d: could not find valid gradient maximum\n", vno); @@ -34543,7 +35267,8 @@ int MRIScomputeInvertedGrayWhiteBorderValues(MRI_SURFACE *mris, double outside_hi, double sigma, float max_thickness, - FILE *log_fp) { + FILE *log_fp) +{ double val, x, y, z, xw, yw, zw; int total_vertices, vno, inward_increasing, ngray, nwhite; VERTEX *v; @@ -34624,7 +35349,8 @@ int MRIScomputeInvertedPialBorderValues(MRI_SURFACE *mris, double outside_hi, double sigma, float max_thickness, - FILE *log_fp) { + FILE *log_fp) +{ double val, x, y, z, xw, yw, zw, dist, prev_val, next_val; int total_vertices, vno, inward_increasing, ngray, ncsf; VERTEX *v; @@ -34773,7 +35499,8 @@ int MRIScomputeInvertedPialBorderValues(MRI_SURFACE *mris, Description ------------------------------------------------------*/ -int MRIScomputeGraySurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, float gray_surface) { +int MRIScomputeGraySurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smooth, float gray_surface) +{ double val, x, y, z, min_val, xw, yw, zw, dx, dy, dz, mag, max_mag; int total_vertices, vno, nmissing; float mean_gray, dist; @@ -34834,7 +35561,8 @@ int MRIScomputeGraySurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smo v->mean = max_mag; mean_gray += min_val; total_vertices++; - } else { + } + else { nmissing++; v->val = 0.0f; } @@ -34854,7 +35582,8 @@ int MRIScomputeGraySurfaceValues(MRI_SURFACE *mris, MRI *mri_brain, MRI *mri_smo \brief Reverse sign of one of the dimensions of the surface coords. If reversing X, the order of the verticies is also reversed. */ -int MRISreverseCoords(MRI_SURFACE *mris, int which_direction, int reverse_face_order, int which_coords) { +int MRISreverseCoords(MRI_SURFACE *mris, int which_direction, int reverse_face_order, int which_coords) +{ int vno; float x = 0, y = 0, z = 0; VERTEX *v; @@ -34929,7 +35658,8 @@ int MRISreverseCoords(MRI_SURFACE *mris, int which_direction, int reverse_face_o \brief Reverse sign of one of the dimensions of the surface coords. If reversing X, the order of the verticies is also reversed. */ -int MRISreverse(MRI_SURFACE *mris, int which, int reverse_face_order) { +int MRISreverse(MRI_SURFACE *mris, int which, int reverse_face_order) +{ int vno; float x, y, z; VERTEX *v; @@ -34971,7 +35701,8 @@ int MRISreverse(MRI_SURFACE *mris, int which, int reverse_face_order) { \brief Reverse order of the vertices in each face. This is needed when changing the sign of the x surface coord. */ -int MRISreverseFaceOrder(MRIS *mris) { +int MRISreverseFaceOrder(MRIS *mris) +{ int fno, vno0, vno1, vno2; FACE *f; @@ -35488,7 +36219,8 @@ mrisFindNormalDistanceLimits(MRI_SURFACE *mris, MRI *mri_filled, int vno, Description ------------------------------------------------------*/ -static int mrisLimitGradientDistance(MRI_SURFACE *mris, MHT *mht, int vno) { +static int mrisLimitGradientDistance(MRI_SURFACE *mris, MHT *mht, int vno) +{ #if 1 // NJS: else code causes mris_expand test failure Aug2012 VERTEX *v; @@ -35914,7 +36646,8 @@ mrisDebugVertex(MRI_SURFACE *mris, int vno) Description ------------------------------------------------------*/ -static double mrisRmsValError(MRI_SURFACE *mris, MRI *mri) { +static double mrisRmsValError(MRI_SURFACE *mris, MRI *mri) +{ int vno, n, xv, yv, zv; double val, total, delta, x, y, z; VERTEX *v; @@ -35933,11 +36666,14 @@ static double mrisRmsValError(MRI_SURFACE *mris, MRI *mri) { delta = (val - v->val); if (fabs(delta) > 100) { DiagBreak(); - } else if (fabs(delta) > 1000) { + } + else if (fabs(delta) > 1000) { DiagBreak(); - } else if (fabs(delta) > 10000) { + } + else if (fabs(delta) > 10000) { DiagBreak(); - } else if (fabs(delta) > 100000) { + } + else if (fabs(delta) > 100000) { DiagBreak(); } @@ -35960,7 +36696,8 @@ static double mrisRmsValError(MRI_SURFACE *mris, MRI *mri) { Description ------------------------------------------------------*/ -static double mrisRmsValError_mef(MRI_SURFACE *mris, MRI *mri_30, MRI *mri_5, float weight30, float weight5) { +static double mrisRmsValError_mef(MRI_SURFACE *mris, MRI *mri_30, MRI *mri_5, float weight30, float weight5) +{ int vno, n, max_vno; //, xv, yv, zv ; double val30, val5, total, delta, x, y, z, error, max_del; VERTEX *v; @@ -36032,7 +36769,8 @@ mrisNeighborAtVoxel(MRI_SURFACE *mris, MRI *mri, int vno, int xv,int yv,int zv) Description ------------------------------------------------------*/ -double MRIScomputeAnalyticDistanceError(MRI_SURFACE *mris, int which, FILE *fp) { +double MRIScomputeAnalyticDistanceError(MRI_SURFACE *mris, int which, FILE *fp) +{ int vno, n, vtotal, *pv, ndists; VERTEX *v, *vn; float d, xd, yd, zd, circumference = 0.0f, angle, odist; @@ -36123,7 +36861,8 @@ double MRIScomputeAnalyticDistanceError(MRI_SURFACE *mris, int which, FILE *fp) cp = getenv("FS_DISTURB_DISTANCES"); if (cp) { disturb_pct = atof(cp); - } else { + } + else { disturb_pct = 0.0; } measured_error = MRISpercentDistanceError(mris); @@ -36155,7 +36894,8 @@ double MRIScomputeAnalyticDistanceError(MRI_SURFACE *mris, int which, FILE *fp) Description ------------------------------------------------------*/ -double MRISstoreAnalyticDistances(MRI_SURFACE *mris, int which) { +double MRISstoreAnalyticDistances(MRI_SURFACE *mris, int which) +{ int vno, n, vtotal, *pv; VERTEX *v, *vn; float d, xd, yd, zd, circumference = 0.0f, angle, odist; @@ -36224,7 +36964,8 @@ double MRISstoreAnalyticDistances(MRI_SURFACE *mris, int which) { Description ------------------------------------------------------*/ -int MRISdisturbOriginalDistances(MRI_SURFACE *mris, double max_pct) { +int MRISdisturbOriginalDistances(MRI_SURFACE *mris, double max_pct) +{ int vno, n; VERTEX *v; @@ -36247,7 +36988,8 @@ int MRISdisturbOriginalDistances(MRI_SURFACE *mris, double max_pct) { Description ------------------------------------------------------*/ -int MRISnegateValues(MRI_SURFACE *mris) { +int MRISnegateValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -36267,7 +37009,8 @@ int MRISnegateValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyMeansToValues(MRI_SURFACE *mris) { +int MRIScopyMeansToValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -36287,7 +37030,8 @@ int MRIScopyMeansToValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyImaginaryMeansToValues(MRI_SURFACE *mris) { +int MRIScopyImaginaryMeansToValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -36307,7 +37051,8 @@ int MRIScopyImaginaryMeansToValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyStandardErrorsToValues(MRI_SURFACE *mris) { +int MRIScopyStandardErrorsToValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -36327,8 +37072,8 @@ int MRIScopyStandardErrorsToValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISaccumulateMeansInVolume( - MRI_SURFACE *mris, MRI *mri, int mris_dof, int mri_dof, int coordinate_system, int sno) { +int MRISaccumulateMeansInVolume(MRI_SURFACE *mris, MRI *mri, int mris_dof, int mri_dof, int coordinate_system, int sno) +{ VERTEX *vertex; double ndof, x, y, z, mean; int vno, xv, yv, zv; @@ -36371,7 +37116,8 @@ int MRISaccumulateMeansInVolume( actually these are squared standard errors ------------------------------------------------------*/ int MRISaccumulateStandardErrorsInVolume( - MRI_SURFACE *mris, MRI *mri, int mris_dof, int mri_dof, int coordinate_system, int sno) { + MRI_SURFACE *mris, MRI *mri, int mris_dof, int mri_dof, int coordinate_system, int sno) +{ VERTEX *vertex; double ndof, x, y, z, mris_sigma, mri_sigma; int vno, xv, yv, zv; @@ -36429,7 +37175,8 @@ int MRISaccumulateStandardErrorsInVolume( Description ------------------------------------------------------*/ -int MRISaccumulateMeansOnSurface(MRI_SURFACE *mris, int total_dof, int new_dof) { +int MRISaccumulateMeansOnSurface(MRI_SURFACE *mris, int total_dof, int new_dof) +{ int vno, ndof; VERTEX *v; @@ -36452,7 +37199,8 @@ int MRISaccumulateMeansOnSurface(MRI_SURFACE *mris, int total_dof, int new_dof) Description ------------------------------------------------------*/ -int MRISaccumulateImaginaryMeansOnSurface(MRI_SURFACE *mris, int total_dof, int new_dof) { +int MRISaccumulateImaginaryMeansOnSurface(MRI_SURFACE *mris, int total_dof, int new_dof) +{ int vno, ndof; VERTEX *v; @@ -36476,7 +37224,8 @@ int MRISaccumulateImaginaryMeansOnSurface(MRI_SURFACE *mris, int total_dof, int Description actually these are squared standard errors ------------------------------------------------------*/ -int MRISaccumulateStandardErrorsOnSurface(MRI_SURFACE *mris, int total_dof, int new_dof) { +int MRISaccumulateStandardErrorsOnSurface(MRI_SURFACE *mris, int total_dof, int new_dof) +{ int vno, ndof; VERTEX *v; double var; @@ -36502,7 +37251,8 @@ int MRISaccumulateStandardErrorsOnSurface(MRI_SURFACE *mris, int total_dof, int Description actually these are squared standard errors ------------------------------------------------------*/ -int MRIScomputeAverageCircularPhaseGradient(MRI_SURFACE *mris, LABEL *area, float *pdx, float *pdy, float *pdz) { +int MRIScomputeAverageCircularPhaseGradient(MRI_SURFACE *mris, LABEL *area, float *pdx, float *pdy, float *pdz) +{ int N, vno, n, i; VERTEX *v, *vn; VECTOR *vdf, *vfz; @@ -36530,7 +37280,8 @@ int MRIScomputeAverageCircularPhaseGradient(MRI_SURFACE *mris, LABEL *area, floa vdf = VectorAlloc(N, MATRIX_REAL); /* function deltas */ if (mris->patch) { mz = MatrixAlloc(N, 2, MATRIX_REAL); /* vertex spacing deltas */ - } else { + } + else { mz = MatrixAlloc(N, 3, MATRIX_REAL); /* vertex spacing deltas */ } @@ -36568,7 +37319,8 @@ int MRIScomputeAverageCircularPhaseGradient(MRI_SURFACE *mris, LABEL *area, floa v->dy = VECTOR_ELT(vfz, 2); if (!mris->patch) { v->dz = VECTOR_ELT(vfz, 3); - } else { + } + else { v->dz = 0.0f; } dx += v->dx; @@ -36599,7 +37351,8 @@ int MRIScomputeAverageCircularPhaseGradient(MRI_SURFACE *mris, LABEL *area, floa Description ------------------------------------------------------*/ -static double mrisComputeIntensityError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisComputeIntensityError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int vno; VERTEX *v; float x, y, z; @@ -36639,7 +37392,8 @@ static double mrisComputeIntensityError(MRI_SURFACE *mris, INTEGRATION_PARMS *pa Description ------------------------------------------------------*/ -static double mrisComputeTargetLocationError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisComputeTargetLocationError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int vno, max_vno; VERTEX *v; double dx, dy, dz; @@ -36686,7 +37440,8 @@ static double mrisComputeTargetLocationError(MRI_SURFACE *mris, INTEGRATION_PARM Description ------------------------------------------------------*/ -static double mrisComputeIntensityGradientError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisComputeIntensityGradientError(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int vno; VERTEX *v; float x, y, z; @@ -36734,7 +37489,8 @@ static double mrisComputeIntensityGradientError(MRI_SURFACE *mris, INTEGRATION_P Compute the ratio of the two principal curvatures and store it in the vertex->curv variable. ------------------------------------------------------*/ -int MRISuseCurvatureRatio(MRI_SURFACE *mris) { +int MRISuseCurvatureRatio(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float min_curv, max_curv, k1, k2, curv; @@ -36751,7 +37507,8 @@ int MRISuseCurvatureRatio(MRI_SURFACE *mris) { if (fabs(v->k1) > fabs(v->k2)) { k1 = v->k1; k2 = v->k2; - } else { + } + else { k1 = v->k2; k2 = v->k1; } @@ -36777,7 +37534,8 @@ int MRISuseCurvatureRatio(MRI_SURFACE *mris) { if (fabs(v->k1) > fabs(v->k2)) { k1 = v->k1; k2 = v->k2; - } else { + } + else { k1 = v->k2; k2 = v->k1; } @@ -36785,7 +37543,8 @@ int MRISuseCurvatureRatio(MRI_SURFACE *mris) { if (FZERO(k2)) { if (FZERO(k1)) { curv = 0.0; - } else { + } + else { curv = k1 < 0 ? min_curv : max_curv; } v->curv = curv; @@ -36805,7 +37564,8 @@ int MRISuseCurvatureRatio(MRI_SURFACE *mris) { Compute the contrast of the two principal curvatures and store it in the vertex->curv variable. ------------------------------------------------------*/ -int MRISuseCurvatureContrast(MRI_SURFACE *mris) { +int MRISuseCurvatureContrast(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float min_curv, max_curv, k1, k2, curv, min_k; @@ -36836,7 +37596,8 @@ int MRISuseCurvatureContrast(MRI_SURFACE *mris) { if (v->k1 > v->k2) { k1 = v->k1; k2 = v->k2; - } else { + } + else { k1 = v->k2; k2 = v->k1; } @@ -36865,7 +37626,8 @@ int MRISuseCurvatureContrast(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static double mrisComputeSphereError(MRI_SURFACE *mris, double l_sphere, double r0) { +static double mrisComputeSphereError(MRI_SURFACE *mris, double l_sphere, double r0) +{ int vno; double sse, x0, y0, z0; @@ -36922,7 +37684,8 @@ static double mrisComputeSphereError(MRI_SURFACE *mris, double l_sphere, double Description ------------------------------------------------------*/ -int MRIScanonicalToWorld(MRI_SURFACE *mris, double phi, double theta, double *pxw, double *pyw, double *pzw) { +int MRIScanonicalToWorld(MRI_SURFACE *mris, double phi, double theta, double *pxw, double *pyw, double *pzw) +{ double x, y, z, radius; radius = mris->radius; @@ -37010,7 +37773,8 @@ mrisClipMomentumGradient(MRI_SURFACE *mris, float max_len) Description ------------------------------------------------------*/ -int MRIScopyCurvatureToValues(MRI_SURFACE *mris) { +int MRIScopyCurvatureToValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37030,7 +37794,8 @@ int MRIScopyCurvatureToValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyVal2ToVal(MRI_SURFACE *mris) { +int MRIScopyVal2ToVal(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37051,7 +37816,8 @@ int MRIScopyVal2ToVal(MRI_SURFACE *mris) { Description copy the v->val2bak field into the v->val for every vertex ------------------------------------------------------*/ -int MRIScopyVal2BakToVal(MRI_SURFACE *mris) { +int MRIScopyVal2BakToVal(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37071,7 +37837,8 @@ int MRIScopyVal2BakToVal(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyCurvatureToImagValues(MRI_SURFACE *mris) { +int MRIScopyCurvatureToImagValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37091,7 +37858,8 @@ int MRIScopyCurvatureToImagValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyValuesToCurvature(MRI_SURFACE *mris) { +int MRIScopyValuesToCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37111,7 +37879,8 @@ int MRIScopyValuesToCurvature(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyImagValuesToCurvature(MRI_SURFACE *mris) { +int MRIScopyImagValuesToCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37131,7 +37900,8 @@ int MRIScopyImagValuesToCurvature(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyCurvatureFromValues(MRI_SURFACE *mris) { +int MRIScopyCurvatureFromValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37151,7 +37921,8 @@ int MRIScopyCurvatureFromValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyCurvatureFromImagValues(MRI_SURFACE *mris) { +int MRIScopyCurvatureFromImagValues(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -37171,7 +37942,8 @@ int MRIScopyCurvatureFromImagValues(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScomputeDistanceErrors(MRI_SURFACE *mris, int nbhd_size, int max_nbrs) { +int MRIScomputeDistanceErrors(MRI_SURFACE *mris, int nbhd_size, int max_nbrs) +{ VERTEX *v; int vno, n, nvertices; double dist_scale, pct, dist, odist, mean, mean_error, smean, total_mean_error, total_mean; @@ -37179,7 +37951,8 @@ int MRIScomputeDistanceErrors(MRI_SURFACE *mris, int nbhd_size, int max_nbrs) { MRIScomputeMetricProperties(mris); if (mris->patch) { dist_scale = 1.0; - } else { + } + else { dist_scale = sqrt(mris->orig_area / mris->total_area); } @@ -37245,7 +38018,8 @@ int MRIScomputeDistanceErrors(MRI_SURFACE *mris, int nbhd_size, int max_nbrs) { Description ------------------------------------------------------*/ -int MRISwriteTriangularSurface(MRI_SURFACE *mris, const char *fname) { +int MRISwriteTriangularSurface(MRI_SURFACE *mris, const char *fname) +{ int k, n; FILE *fp; time_t tt; @@ -37309,7 +38083,8 @@ int MRISwriteTriangularSurface(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -static SMALL_SURFACE *mrisReadTriangleFileVertexPositionsOnly(const char *fname) { +static SMALL_SURFACE *mrisReadTriangleFileVertexPositionsOnly(const char *fname) +{ SMALL_VERTEX *v; int nvertices, nfaces, magic, vno; char line[STRLEN]; @@ -37366,7 +38141,8 @@ static SMALL_SURFACE *mrisReadTriangleFileVertexPositionsOnly(const char *fname) Description ------------------------------------------------------*/ -static int mrisReadTriangleFilePositions(MRI_SURFACE *mris, const char *fname) { +static int mrisReadTriangleFilePositions(MRI_SURFACE *mris, const char *fname) +{ VERTEX *v; int nvertices, nfaces, magic, vno; char line[STRLEN]; @@ -37432,7 +38208,8 @@ static int mrisReadTriangleFilePositions(MRI_SURFACE *mris, const char *fname) { Description ------------------------------------------------------*/ -static MRI_SURFACE *mrisReadTriangleFile(const char *fname, double pct_over) { +static MRI_SURFACE *mrisReadTriangleFile(const char *fname, double pct_over) +{ VERTEX *v; FACE *f; int nvertices, nfaces, magic, vno, fno, n; @@ -37573,7 +38350,8 @@ mrisRemoveNormalGradientComponent(MRI_SURFACE *mris, int vno) ------------------------------------------------------*/ #define MIN_NBR_DIST (0.01) -static int mrisRemoveNeighborGradientComponent(MRI_SURFACE *mris, int vno) { +static int mrisRemoveNeighborGradientComponent(MRI_SURFACE *mris, int vno) +{ VERTEX *v, *vn; int n; float dx, dy, dz, dot, x, y, z, dist, min_nbr_dist; @@ -37622,7 +38400,8 @@ static int mrisRemoveNeighborGradientComponent(MRI_SURFACE *mris, int vno) { Description ------------------------------------------------------*/ -int MRISbuildFileName(MRI_SURFACE *mris, const char *sname, char *fname) { +int MRISbuildFileName(MRI_SURFACE *mris, const char *sname, char *fname) +{ char path[STRLEN], *slash, *dot; slash = strchr(sname, '/'); @@ -37634,18 +38413,21 @@ int MRISbuildFileName(MRI_SURFACE *mris, const char *sname, char *fname) { if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s", sname); - } else { + } + else { // PW 2017/05/15: Legacy behaviour sprintf(fname, "%s/%s", path, sname); } - } else /* no hemisphere specified */ + } + else /* no hemisphere specified */ if (getenv("FS_POSIX")) { // PW 2017/05/15: If FS_POSIX is set, write to cwd (as per POSIX:4.11) sprintf(fname, "./%s.%s", mris->hemisphere == LEFT_HEMISPHERE ? "lh" : mris->hemisphere == BOTH_HEMISPHERES ? "both" : "rh", sname); - } else { + } + else { // PW 2017/05/15: Legacy behaviour sprintf(fname, "%s/%s.%s", @@ -37653,7 +38435,8 @@ int MRISbuildFileName(MRI_SURFACE *mris, const char *sname, char *fname) { mris->hemisphere == LEFT_HEMISPHERE ? "lh" : mris->hemisphere == BOTH_HEMISPHERES ? "both" : "rh", sname); } - } else { + } + else { strcpy(fname, sname); /* path specified explicitly */ } return (NO_ERROR); @@ -37665,7 +38448,8 @@ int MRISbuildFileName(MRI_SURFACE *mris, const char *sname, char *fname) { Description ------------------------------------------------------*/ -int MRISmodeFilterVals(MRI_SURFACE *mris, int niter) { +int MRISmodeFilterVals(MRI_SURFACE *mris, int niter) +{ int *histo; int i, n, vno, ino, index, max_histo, max_index, nchanged, nzero, max_val; VERTEX *v, *vn; @@ -37720,7 +38504,8 @@ int MRISmodeFilterVals(MRI_SURFACE *mris, int niter) { if (v->val != v->valbak) { v->marked = 0; /* process it again */ nchanged++; - } else + } + else v->marked = 1; /* didn't change */ v->val = v->valbak; @@ -37751,7 +38536,8 @@ int MRISmodeFilterVals(MRI_SURFACE *mris, int niter) { Description ------------------------------------------------------*/ -int MRISmodeFilterZeroVals(MRI_SURFACE *mris) { +int MRISmodeFilterZeroVals(MRI_SURFACE *mris) +{ int *histo, i, n, vno, ino, max_val, index, max_histo, max_index, nchanged, nzero; VERTEX *v, *vn; @@ -37807,7 +38593,8 @@ int MRISmodeFilterZeroVals(MRI_SURFACE *mris) { if (v->val != v->valbak) { v->marked = 0; /* process it again */ nchanged++; - } else + } + else v->marked = 1; /* didn't change */ v->val = v->valbak; @@ -37841,7 +38628,8 @@ int MRISmodeFilterZeroVals(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISmodeFilterAnnotations(MRI_SURFACE *mris, int niter) { +int MRISmodeFilterAnnotations(MRI_SURFACE *mris, int niter) +{ int *histo, i, n, vno, ino, index, max_histo, max_index, max_annotation, *annotations, nchanged = 0; VERTEX *v, *vn; @@ -37884,7 +38672,8 @@ int MRISmodeFilterAnnotations(MRI_SURFACE *mris, int niter) { histo[index]++; max_histo = histo[index]; max_annotation = v->annotation; - } else + } + else max_histo = max_annotation = 0; for (i = 1; i <= max_index; i++) { @@ -37921,7 +38710,8 @@ int MRISmodeFilterAnnotations(MRI_SURFACE *mris, int niter) { Description ------------------------------------------------------*/ -int MRISsoapBubbleVals(MRI_SURFACE *mris, int navgs) { +int MRISsoapBubbleVals(MRI_SURFACE *mris, int navgs) +{ int vno, n, i, cmpt, nmarked; VERTEX *v, *vn; double mean; @@ -37975,7 +38765,8 @@ int MRISsoapBubbleVals(MRI_SURFACE *mris, int navgs) { apply a soap bubble to the vertex->d field (used for target distances frequently) ------------------------------------------------------*/ -int MRISsoapBubbleD(MRI_SURFACE *mris, int navgs) { +int MRISsoapBubbleD(MRI_SURFACE *mris, int navgs) +{ int vno, n, i, cmpt, nmarked; VERTEX *v, *vn; double mean; @@ -38020,7 +38811,8 @@ int MRISsoapBubbleD(MRI_SURFACE *mris, int navgs) { /* fprintf(stdout, "\n") ;*/ return (NO_ERROR); } -int MRISremoveTriangleLinks(MRI_SURFACE *mris) { +int MRISremoveTriangleLinks(MRI_SURFACE *mris) +{ int fno, which; FACE *f; @@ -38046,14 +38838,16 @@ int MRISremoveTriangleLinks(MRI_SURFACE *mris) { if (EVEN(which)) { mrisRemoveVertexLink(mris, f->v[1], f->v[2]); mrisRemoveVertexLink(mris, f->v[2], f->v[1]); - } else { + } + else { mrisRemoveVertexLink(mris, f->v[0], f->v[2]); mrisRemoveVertexLink(mris, f->v[2], f->v[0]); } } return (NO_ERROR); } -static int mrisRemoveVertexLink(MRI_SURFACE *mris, int vno1, int vno2) { +static int mrisRemoveVertexLink(MRI_SURFACE *mris, int vno1, int vno2) +{ int n; VERTEX *v; @@ -38077,7 +38871,8 @@ static int mrisRemoveVertexLink(MRI_SURFACE *mris, int vno1, int vno2) { = 3 --> divide edge in half three times, add 7 vertices */ #define MAX_SURFACE_FACES 200000 -int MRISdivideEdges(MRI_SURFACE *mris, int nsubdivisions) { +int MRISdivideEdges(MRI_SURFACE *mris, int nsubdivisions) +{ int nadded, sub, nfaces, fno, nvertices, faces[MAX_SURFACE_FACES], index; FACE *f; @@ -38143,7 +38938,8 @@ int MRISdivideEdges(MRI_SURFACE *mris, int nsubdivisions) { Description ------------------------------------------------------*/ -int MRISdivideLongEdges(MRI_SURFACE *mris, double thresh) { +int MRISdivideLongEdges(MRI_SURFACE *mris, double thresh) +{ double dist; int vno, nadded, n /*,nvertices, nfaces, nedges, eno*/; VERTEX *v, *vn; @@ -38266,7 +39062,8 @@ mrisAddVertices(MRI_SURFACE *mris, double thresh) ------------------------------------------------------*/ #define MAX_VERTEX_NEIGHBORS 50 #define MAX_FACES 50 -static int mrisDivideEdge(MRI_SURFACE *mris, int vno1, int vno2) { +static int mrisDivideEdge(MRI_SURFACE *mris, int vno1, int vno2) +{ VERTEX *v1, *v2, *vnew; int vnew_no, n, m, fno, n1, n2, flist[100]; FACE *face; @@ -38466,7 +39263,8 @@ static int mrisDivideEdge(MRI_SURFACE *mris, int vno1, int vno2) { Description ------------------------------------------------------*/ -static int mrisDivideFace(MRI_SURFACE *mris, int fno, int vno1, int vno2, int vnew_no) { +static int mrisDivideFace(MRI_SURFACE *mris, int fno, int vno1, int vno2, int vnew_no) +{ FACE *f1, *f2; VERTEX *v1, *v2, *v3, *vnew; int fnew_no, n, vno3, flist[5000], vlist[5000], nlist[5000]; @@ -38500,7 +39298,8 @@ static int mrisDivideFace(MRI_SURFACE *mris, int fno, int vno1, int vno2, int vn f1->v[n] = vnew_no; vnew->f[vnew->num] = fno; vnew->n[vnew->num++] = (uchar)n; - } else if (f1->v[n] != vno1) { + } + else if (f1->v[n] != vno1) { vno3 = f1->v[n]; } } @@ -38839,7 +39638,8 @@ VertexReplaceNeighbor(VERTEX *v, int vno_old, int vno_new) Description ------------------------------------------------------*/ -double MRIScomputeFaceAreaStats(MRI_SURFACE *mris, double *psigma, double *pmin, double *pmax) { +double MRIScomputeFaceAreaStats(MRI_SURFACE *mris, double *psigma, double *pmin, double *pmax) +{ double total_area, mean, var, nf, sigma, min_area, max_area, area, area_scale; int fno; FACE *f; @@ -38848,7 +39648,8 @@ double MRIScomputeFaceAreaStats(MRI_SURFACE *mris, double *psigma, double *pmin, if (mris->patch) { area_scale = 1.0; - } else { + } + else { area_scale = mris->orig_area / mris->total_area; } @@ -38888,7 +39689,8 @@ double MRIScomputeFaceAreaStats(MRI_SURFACE *mris, double *psigma, double *pmin, Description ------------------------------------------------------*/ double MRIScomputeVertexSpacingStats( - MRI_SURFACE *mris, double *psigma, double *pmin, double *pmax, int *pvno, int *pvno2, int which_vertices) { + MRI_SURFACE *mris, double *psigma, double *pmin, double *pmax, int *pvno, int *pvno2, int which_vertices) +{ double total_dist, mean, var, nv, dist, sigma, min_dist, max_dist, dist_scale; int vno, n; VERTEX *v, *vn; @@ -38896,7 +39698,8 @@ double MRIScomputeVertexSpacingStats( MRIScomputeMetricProperties(mris); if (mris->patch) { dist_scale = 1.0; - } else { + } + else { dist_scale = sqrt(mris->orig_area / mris->total_area); } dist_scale = 1.0f; @@ -38977,7 +39780,8 @@ double MRIScomputeVertexSpacingStats( Description ------------------------------------------------------*/ double MRIScomputeTotalVertexSpacingStats( - MRI_SURFACE *mris, double *psigma, double *pmin, double *pmax, int *pvno, int *pvno2) { + MRI_SURFACE *mris, double *psigma, double *pmin, double *pmax, int *pvno, int *pvno2) +{ double total_dist, mean, var, nv, dist, sigma, min_dist, max_dist, dist_scale; int vno, n; VERTEX *v, *vn; @@ -38985,7 +39789,8 @@ double MRIScomputeTotalVertexSpacingStats( MRIScomputeMetricProperties(mris); if (mris->patch) { dist_scale = 1.0; - } else { + } + else { dist_scale = sqrt(mris->orig_area / mris->total_area); } dist_scale = 1.0f; @@ -39039,7 +39844,8 @@ double MRIScomputeTotalVertexSpacingStats( Description ------------------------------------------------------*/ -static int mrisComputeCurvatureMinMax(MRI_SURFACE *mris) { +static int mrisComputeCurvatureMinMax(MRI_SURFACE *mris) +{ int vno, found = 0; VERTEX *v; @@ -39051,7 +39857,8 @@ static int mrisComputeCurvatureMinMax(MRI_SURFACE *mris) { if (found == 0) { mris->max_curv = mris->min_curv = v->curv; found = 1; - } else { + } + else { if (v->curv > mris->max_curv) { mris->max_curv = v->curv; } @@ -39069,7 +39876,8 @@ static int mrisComputeCurvatureMinMax(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISsetVals(MRI_SURFACE *mris, float val) { +int MRISsetVals(MRI_SURFACE *mris, float val) +{ int vno; VERTEX *v; @@ -39089,7 +39897,8 @@ int MRISsetVals(MRI_SURFACE *mris, float val) { Description ------------------------------------------------------*/ -int MRISscaleVals(MRI_SURFACE *mris, float scale) { +int MRISscaleVals(MRI_SURFACE *mris, float scale) +{ int vno; VERTEX *v; @@ -39109,7 +39918,8 @@ int MRISscaleVals(MRI_SURFACE *mris, float scale) { Description ------------------------------------------------------*/ -float MRISdistanceToSurface(MRI_SURFACE *mris, MHT *mht, float x0, float y0, float z0, float nx, float ny, float nz) { +float MRISdistanceToSurface(MRI_SURFACE *mris, MHT *mht, float x0, float y0, float z0, float nx, float ny, float nz) +{ double dist, len; #if 0 @@ -39148,7 +39958,8 @@ float MRISdistanceToSurface(MRI_SURFACE *mris, MHT *mht, float x0, float y0, flo return (0.0); } -static int mrisUpdateTargetLocations(MRI_SURFACE *mris, MRI *mri, double target_intensity) { +static int mrisUpdateTargetLocations(MRI_SURFACE *mris, MRI *mri, double target_intensity) +{ int vno; double xv, yv, zv, val, val0, xv0, yv0, zv0; VERTEX *v; @@ -39207,7 +40018,8 @@ static int mrisUpdateTargetLocations(MRI_SURFACE *mris, MRI *mri, double target_ useful for calling iteratively ------------------------------------------------------*/ #define MAX_EXP_MM 0.1 -int MRISexpandSurface(MRI_SURFACE *mris, float distance, INTEGRATION_PARMS *parms, int use_thick, int nsurfaces) { +int MRISexpandSurface(MRI_SURFACE *mris, float distance, INTEGRATION_PARMS *parms, int use_thick, int nsurfaces) +{ int vno, n, niter, avgs, nrounds, surf_no, orig_start_t = parms->start_t; VERTEX *v; double dist, dx = 0., dy = 0., dz = 0.0, dtotal, *pial_x, *pial_y, *pial_z, l_spring_orig; @@ -39261,7 +40073,8 @@ int MRISexpandSurface(MRI_SURFACE *mris, float distance, INTEGRATION_PARMS *parm v->y += distance * v->ny; v->z += distance * v->nz; } - } else { + } + else { MRISsaveVertexPositions(mris, ORIGINAL_VERTICES); if (use_thick) { memset(&thick_parms, 0, sizeof(thick_parms)); @@ -39311,7 +40124,8 @@ int MRISexpandSurface(MRI_SURFACE *mris, float distance, INTEGRATION_PARMS *parm if (use_thick) // distance is a % of the total thickness { niter = nint(fabs(distance) * 2 / (nsurfaces * parms->dt * MAX_EXP_MM)); - } else { + } + else { niter = nint(2 * fabs(distance) / (parms->l_location * nrounds * nsurfaces * parms->dt * MAX_EXP_MM)); } if (Gdiag_no >= 0) { @@ -39351,7 +40165,8 @@ int MRISexpandSurface(MRI_SURFACE *mris, float distance, INTEGRATION_PARMS *parm v->targx = v->origx + dx * dist; v->targy = v->origy + dy * dist; v->targz = v->origz + dz * dist; - } else // just move outwards along surface normal + } + else // just move outwards along surface normal { dist = distance; v->targx = v->origx + v->nx * distance; @@ -39498,7 +40313,8 @@ int MRISexpandSurface(MRI_SURFACE *mris, float distance, INTEGRATION_PARMS *parm if (parms->smooth_averages > 0) { printf("\nsmoothing vertex locations %d times\n", parms->smooth_averages); MRISaverageVertexPositions(mris, parms->smooth_averages); - } else { + } + else { printf("\n"); } sprintf(fname, "%s.%s%3.3d", hemi, parms->base_name, surf_no + 1); @@ -39517,7 +40333,8 @@ int MRISexpandSurface(MRI_SURFACE *mris, float distance, INTEGRATION_PARMS *parm free(pial_z); return (NO_ERROR); } -int MRISripZeroThicknessRegions(MRI_SURFACE *mris) { +int MRISripZeroThicknessRegions(MRI_SURFACE *mris) +{ VERTEX *v; int vno; @@ -39540,7 +40357,8 @@ int MRISripZeroThicknessRegions(MRI_SURFACE *mris) { Description Translate a surface by (dx, dy, dz) ------------------------------------------------------*/ -int MRIStranslate(MRI_SURFACE *mris, float dx, float dy, float dz) { +int MRIStranslate(MRI_SURFACE *mris, float dx, float dy, float dz) +{ int vno; VERTEX *v; @@ -39571,7 +40389,8 @@ int MRIStranslate(MRI_SURFACE *mris, float dx, float dy, float dz) { See also MRISmatrixMultiply(). ------------------------------------------------------*/ #include "gcamorph.h" -int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_dst) { +int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_dst) +{ LTA *lta; int vno; VERTEX *v; @@ -39674,7 +40493,8 @@ int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_ds if (srcNotGiven) { MRIfree(&mri); } - } else { + } + else { lta = (LTA *)(transform->xform); if (!mri_dst) { dstNotGiven = 1; @@ -39797,7 +40617,8 @@ int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_ds mri->zsize = mris->vg.zsize; mri->ras_good_flag = 1; MRIreInitCache(mri); - } else if (!mri) { + } + else if (!mri) { error = 1; strcpy(errMsg, "When mri == NULL, the transform must have the valid src info.\n"); goto mristransform_cleanup; @@ -39828,7 +40649,8 @@ int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_ds mri_dst->ysize = lt->dst.ysize; mri_dst->zsize = lt->dst.zsize; mri_dst->ras_good_flag = 1; - } else if (!mri_dst) { + } + else if (!mri_dst) { fprintf(stderr, "WARNING:*********************************************************\n"); fprintf(stderr, "WARNING: transform does not have valid destination volume. \n"); fprintf(stderr, "WARNING: The standard CORONAL volume with c_(ras) = 0 is assumed.\n"); @@ -39901,13 +40723,15 @@ int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_ds // if (mris->useRealRAS) { surfaceRASFromSurfaceRAS = MatrixCopy(lta->xforms[0].m_L, NULL); - } else { + } + else { RASFromSurfaceRAS = RASFromSurfaceRAS_(mri); // needs only c_(ras) info surfaceRASFromRAS = surfaceRASFromRAS_(mri_dst); // need only c_(ras) info m = MatrixMultiply(lta->xforms[0].m_L, RASFromSurfaceRAS, NULL); surfaceRASFromSurfaceRAS = MatrixMultiply(surfaceRASFromRAS, m, NULL); } - } else if (lta->type == LINEAR_VOX_TO_VOX) { + } + else if (lta->type == LINEAR_VOX_TO_VOX) { if (mri->width != mri_dst->width || mri->height != mri_dst->height || mri->depth != mri_dst->depth) { fprintf(stderr, "WARNING:********************************************************\n"); fprintf(stderr, "WARNING:voxel-to-voxel transform must have the same volume sizes.\n"); @@ -39975,7 +40799,8 @@ int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_ds if (error) { ErrorExit(ERROR_BADPARM, errMsg); return -1; // just to satisfy compiler - } else { + } + else { return (NO_ERROR); } } @@ -39983,7 +40808,8 @@ int MRIStransform(MRI_SURFACE *mris, MRI *mri, TRANSFORM *transform, MRI *mri_ds MRISmatrixMultiply() - simply multiplies matrix M by the vertex xyz. See also MRIStransform(). ------------------------------------------------------------------------*/ -int MRISmatrixMultiply(MRIS *mris, MATRIX *M) { +int MRISmatrixMultiply(MRIS *mris, MATRIX *M) +{ int vno; #ifdef HAVE_OPENMP @@ -40019,7 +40845,8 @@ int MRISmatrixMultiply(MRIS *mris, MATRIX *M) { Description Scale a surface anisotropically. ------------------------------------------------------*/ -int MRISanisotropicScale(MRI_SURFACE *mris, float sx, float sy, float sz) { +int MRISanisotropicScale(MRI_SURFACE *mris, float sx, float sy, float sz) +{ VERTEX *v; int k; float x0, y0, z0; @@ -40047,7 +40874,8 @@ static int mrisChooseFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v); static int mrisFindUnambiguousFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v, int *pnum); #if 1 -int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) { +int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) +{ double r; int fno, vno, num_ambiguous = 0, nfound, i, max_count; VERTEX *v; @@ -40101,7 +40929,8 @@ int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) { mrisDumpFace(mris, fno, stderr); } v->marked = 1; - } else { + } + else { if (Gdiag & DIAG_SHOW) { fprintf(stdout, "v %d maps to %d faces\n", vno, nfound); } @@ -40168,7 +40997,8 @@ int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) { note that fno refers to a face in mris and v is a vertex in mris_ico (not given), NOT mris. ------------------------------------------------------*/ -static int mrisPlaceVertexInOrigFace(MRI_SURFACE *mris, VERTEX *v, int fno) { +static int mrisPlaceVertexInOrigFace(MRI_SURFACE *mris, VERTEX *v, int fno) +{ double U0[3], U1[3], U2[3], pt[3], dir[3], int_pt[3], l1[3], l2[3], l2_len, l1_len, l_len, P[3], theta1, theta2, dot, theta_ratio, len_scale, e1[3], e2[3], etmp[3], x, y; int ret; @@ -40227,7 +41057,8 @@ static int mrisPlaceVertexInOrigFace(MRI_SURFACE *mris, VERTEX *v, int fno) { } if (!DZERO(theta2)) { theta_ratio = theta1 / theta2; - } else /* degenerate triangle */ + } + else /* degenerate triangle */ { theta_ratio = 0; } @@ -40297,7 +41128,8 @@ static int mrisPlaceVertexInOrigFace(MRI_SURFACE *mris, VERTEX *v, int fno) { Find the face in which v lies. If it lies in more than one face, return not found. ------------------------------------------------------*/ -static int mrisFindUnambiguousFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v, int *pnfound) { +static int mrisFindUnambiguousFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v, int *pnfound) +{ int nfound, flist[1000], *fptr, total_found, i, j; double dist, d; @@ -40337,7 +41169,8 @@ static int mrisFindUnambiguousFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v, int * of v. ------------------------------------------------------*/ #if 1 -static int mrisChooseFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v) { +static int mrisChooseFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v) +{ int fno, nfound, flist[1000], min_fno, i, j, total_found, *fptr; double dist, d; float dx, dy, dz, cx[1000], cy[1000], cz[1000], total_dist, max_dist; @@ -40403,7 +41236,8 @@ static int mrisChooseFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v) { return (min_fno); } #else -static int mrisChooseFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v) { +static int mrisChooseFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v) +{ int fno, nfound, flist[1000], min_fno, i, j, total_found, *fptr; float x, y, z, dx, dy, dz; double dist, min_dist, d; @@ -40453,7 +41287,8 @@ static int mrisChooseFace(MRI_SURFACE *mris, MHT *mht, VERTEX *v) { } #endif #else -int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) { +int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) +{ double r; int vno /*, fno, n, num*/; #if 0 @@ -40530,7 +41365,8 @@ int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) { mris->vertices[vno].nx,mris->vertices[vno].ny,mris->vertices[vno].nz); */ mris->vertices[vno].curv = 1; - } else { + } + else { mris->vertices[vno].curv = 0; } } @@ -40573,14 +41409,16 @@ int MRISinverseSphericalMap(MRI_SURFACE *mris, MRI_SURFACE *mris_ico) { if (mris_ico->vertices[vno].curv != 0) { mris_ico->vertices[vno].marked = 0; printf("ambiguous ico vertex %d\n", vno); - } else { + } + else { mris_ico->vertices[vno].marked = 1; } if (numvol[ix][iy][iz] > 0) { mris_ico->vertices[vno].x = xvol[ix][iy][iz]; mris_ico->vertices[vno].y = yvol[ix][iy][iz]; mris_ico->vertices[vno].z = zvol[ix][iy][iz]; - } else { + } + else { printf("### ico vertex %d missed volume\n", vno); mris_ico->vertices[vno].marked = 0; } @@ -40969,7 +41807,8 @@ mrisComputeFaceStretch(MRI_SURFACE *mris, int fno) Description Scale a surface anisotropically. ------------------------------------------------------*/ -static int mrisCalculateCanonicalFaceCentroid(MRI_SURFACE *mris, int fno, float *px, float *py, float *pz) { +static int mrisCalculateCanonicalFaceCentroid(MRI_SURFACE *mris, int fno, float *px, float *py, float *pz) +{ float x, y, z; VERTEX *v0, *v1, *v2; FACE *f; @@ -40999,7 +41838,8 @@ static int mrisCalculateCanonicalFaceCentroid(MRI_SURFACE *mris, int fno, float Description Scale a surface anisotropically. ------------------------------------------------------*/ -static int mrisCalculateOriginalFaceCentroid(MRI_SURFACE *mris, int fno, float *px, float *py, float *pz) { +static int mrisCalculateOriginalFaceCentroid(MRI_SURFACE *mris, int fno, float *px, float *py, float *pz) +{ float x, y, z; VERTEX *v0, *v1, *v2; FACE *f; @@ -41029,7 +41869,8 @@ static int mrisCalculateOriginalFaceCentroid(MRI_SURFACE *mris, int fno, float * Description Scale a surface anisotropically. ------------------------------------------------------*/ -static int mrisCalculateFaceCentroid(MRI_SURFACE *mris, int fno, float *px, float *py, float *pz) { +static int mrisCalculateFaceCentroid(MRI_SURFACE *mris, int fno, float *px, float *py, float *pz) +{ float x, y, z; VERTEX *v0, *v1, *v2; FACE *f; @@ -41059,7 +41900,8 @@ static int mrisCalculateFaceCentroid(MRI_SURFACE *mris, int fno, float *px, floa Description Scale a surface anisotropically. ------------------------------------------------------*/ -int MRISprintTessellationStats(MRI_SURFACE *mris, FILE *fp) { +int MRISprintTessellationStats(MRI_SURFACE *mris, FILE *fp) +{ double mean, dsigma, dmin, dmax; int vno = 0, vno2 = 0; @@ -41100,7 +41942,8 @@ int MRISprintTessellationStats(MRI_SURFACE *mris, FILE *fp) { Description ------------------------------------------------------*/ -static void mrisDumpFace(MRI_SURFACE *mris, int fno, FILE *fp) { +static void mrisDumpFace(MRI_SURFACE *mris, int fno, FILE *fp) +{ FACE *f; VERTEX *v; int n; @@ -41128,7 +41971,8 @@ static void mrisDumpFace(MRI_SURFACE *mris, int fno, FILE *fp) { Description ------------------------------------------------------*/ -static int mrisStoreVtotalInV3num(MRI_SURFACE *mris) { +static int mrisStoreVtotalInV3num(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -41146,7 +41990,8 @@ static int mrisStoreVtotalInV3num(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ #define MAX_INT_FACES 100000 -int MRISripDefectiveFaces(MRI_SURFACE *mris) { +int MRISripDefectiveFaces(MRI_SURFACE *mris) +{ FACE *f; int fno, flist[MAX_INT_FACES], retained_i, i, j, nfaces, nripped, n; double dist, min_face_dist, max_dist, r; @@ -41311,7 +42156,8 @@ static int edgesIntersectStable(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2); #if SPHERE_INTERSECTION /* check for intersection on the sphere */ -static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { +static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) +{ VERTEX *v1, *v2; double n0[3], n1[3], n2[3], u0[3], u1[3], u2[3], u3[3], u[3]; double a0, a1, a2, a3, a, b; @@ -41362,20 +42208,25 @@ static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { if (a > 0) { return (0); - } else if (a < 0) { + } + else if (a < 0) { // fprintf(stderr,"-"); if (b > 0) { return (0); - } else { + } + else { return (1); } - } else { + } + else { // fprintf(stderr,"+"); if (b > 0) { return (0); - } else if (b < 0) { + } + else if (b < 0) { return (1); - } else { + } + else { // special case again! The points are exactly aligned... double c0, c1, c2, c3, x1_min, x1_max, x2_min, x2_max; @@ -41421,7 +42272,8 @@ static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { /* it should be a more stable implementation but a bit slower than the previous one */ -static int edgesIntersectStable(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { +static int edgesIntersectStable(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) +{ VERTEX *v1, *v2; double n0[3], n1[3], n2[3], u0[3], u1[3], u2[3], u3[3], u[3]; double og0[3], og1[3], v_0[3], v_1[3]; @@ -41490,19 +42342,24 @@ static int edgesIntersectStable(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { if (a > 0) { return (0); - } else if (a < 0) { + } + else if (a < 0) { if (b > 0) { return (0); - } else { + } + else { return (1); } - } else { + } + else { // fprintf(stderr,"+"); if (b > 0) { return (0); - } else if (b < 0) { + } + else if (b < 0) { return (1); - } else { + } + else { // special case again! The points are exactly aligned... double c0, c1, c2, c3, x1_min, x1_max, x2_min, x2_max; @@ -41532,7 +42389,8 @@ static int edgesIntersectStable(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { #else /* original version */ -static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { +static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) +{ VERTEX *v1, *v2; double b1, b2, m1, m2, x1_start, x1_end, y1_start, y1_end, x2_start, x2_end, y2_start, y2_end, x, y, x1min, x1max, y1min, y1max, x2min, x2max, y2min, y2max, cx, cy, cz; @@ -41572,7 +42430,8 @@ static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { if (!FEQUAL(x1_start, x1_end)) { m1 = (y1_end - y1_start) / (x1_end - x1_start); b1 = y1_end - m1 * x1_end; - } else { + } + else { m1 = b1 = 0; /* will be handled differently */ } @@ -41624,7 +42483,8 @@ static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { if (y >= y1min && y <= y1max) { return (1); } - } else if (FEQUAL(x2_start, x2_end)) /* l2 is vertical */ + } + else if (FEQUAL(x2_start, x2_end)) /* l2 is vertical */ { if (FEQUAL(x1_start, x1_end)) /* both vertical */ { @@ -41634,7 +42494,8 @@ static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { if (y >= y2min && y <= y2max) { return (1); } - } else /* neither line is vertical, compute intersection point */ + } + else /* neither line is vertical, compute intersection point */ { m2 = (y2_end - y2_start) / (x2_end - x2_start); b2 = y2_end - m2 * x2_end; @@ -41663,7 +42524,8 @@ static int edgesIntersect(MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2) { Description ------------------------------------------------------*/ -static int mrisFindAllOverlappingFaces(MRI_SURFACE *mris, MHT *mht, int fno, int *flist) { +static int mrisFindAllOverlappingFaces(MRI_SURFACE *mris, MHT *mht, int fno, int *flist) +{ double x0, x1, y0, y1, z0, z1, x, y, z; int i, n, m, total_found, all_faces[1000000], nfaces; MHBT *bucket, *last_bucket; @@ -41774,7 +42636,8 @@ static int mrisFindAllOverlappingFaces(MRI_SURFACE *mris, MHT *mht, int fno, int Description restore ripflag to 0 (NOTE: Won't undo MRISremoveRipped!!) ------------------------------------------------------*/ -int MRISunrip(MRI_SURFACE *mris) { +int MRISunrip(MRI_SURFACE *mris) +{ int vno, fno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -41807,7 +42670,8 @@ int MRISunrip(MRI_SURFACE *mris) { #define ET_OVERLAP_LIST_INCOMPLETE 0x0001 -typedef struct { +typedef struct +{ int nedges; EDGE *edges; int **overlapping_edges; /* indices of all edges @@ -41817,7 +42681,8 @@ typedef struct { int use_overlap; } EDGE_TABLE; -typedef struct { +typedef struct +{ double fitness; int nedges; int *ordering; /* order of edges in EDGE_TABLE @@ -41843,7 +42708,8 @@ typedef struct { } DEFECT_PATCH, DP; -typedef struct { +typedef struct +{ int vno; /* vertex # in surface */ int vnum; /* original # of 1 neighbors */ int vtotal; @@ -41858,7 +42724,8 @@ typedef struct { } VERTEX_STATE, VS; -typedef struct { +typedef struct +{ DEFECT *defect; VERTEX_STATE *vs; int nvertices; @@ -41868,12 +42735,14 @@ typedef struct { } DEFECT_VERTEX_STATE, DVS; /* this structure is used in the VERTEX structure (*vp) */ -typedef struct { +typedef struct +{ int nedges; int *edges; } EDGE_POINTER, EP; -typedef struct { +typedef struct +{ /* edges constituting the cluster */ int *edges; int nedges; @@ -41885,7 +42754,8 @@ typedef struct { } SEGMENT; // for the clustering of overlapping edges -typedef struct { +typedef struct +{ int n; /* position of this edge in the table */ int vno1, vno2; /* vertices in the ORIGINAL tessellation */ int segment; /* cluster number */ @@ -41894,7 +42764,8 @@ typedef struct { int nxedges; } EDGE_STRUCTURE, ES; -typedef struct { +typedef struct +{ SEGMENT *segments; int nsegments; int max_segments; @@ -41904,7 +42775,8 @@ typedef struct { int nedges; } SEGMENTATION; -typedef struct { +typedef struct +{ /* save the best configuration */ int *best_ordering; float best_fitness; @@ -41915,13 +42787,15 @@ typedef struct { float *vertex_fitness; } RANDOM_PATCH, RP; -typedef struct { +typedef struct +{ float c_x, c_y, c_z; /* canonical coordinates */ float oc_x, oc_y, oc_z; /* orig coordinates in optimized configuations */ float status; /* DISCARDED VERTEX OR KEPT VERTEX */ } FS_VERTEX_INFO; -typedef struct { +typedef struct +{ int nvertices; int ninside; /* index of the first inside vertex */ FS_VERTEX_INFO *vertices; @@ -41930,7 +42804,8 @@ typedef struct { } MAPPING; /* structure which encodes the information for the optimal mapping */ -typedef struct { +typedef struct +{ MRIS *mris; /* structure encoding the original mapping */ int *vertex_trans; @@ -42293,13 +43168,15 @@ static int mrisComputePrincipalCurvatureDistributions(MRI_SURFACE *mris, MRI *mri_k1_k2); static int mrisComputeNormalDotDistribution(MRI_SURFACE *mris, HISTOGRAM *h_dot); -void MRISmapOntoSphere(MRIS *mris) { +void MRISmapOntoSphere(MRIS *mris) +{ MRISprojectOntoSphere(mris, mris, 100.0f); MRISsmoothOnSphere(mris, 10000); } -DEFECT_LIST *mrisSegmentDefects(MRI_SURFACE *mris, int mark_ambiguous, int mark_segmented) { +DEFECT_LIST *mrisSegmentDefects(MRI_SURFACE *mris, int mark_ambiguous, int mark_segmented) +{ DEFECT_LIST *dl; int vno, nadded; VERTEX *v; @@ -42335,7 +43212,8 @@ DEFECT_LIST *mrisSegmentDefects(MRI_SURFACE *mris, int mark_ambiguous, int mark_ static int mrisMarkAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int flag); -static DEFECT_LIST *mrisRemoveOverlappingDefects(MRIS *mris, DEFECT_LIST *dl) { +static DEFECT_LIST *mrisRemoveOverlappingDefects(MRIS *mris, DEFECT_LIST *dl) +{ int i, n, found, removed; DEFECT *defect, *removed_defect; DEFECT_LIST *new_dl; @@ -42420,7 +43298,8 @@ static DEFECT_LIST *mrisRemoveOverlappingDefects(MRIS *mris, DEFECT_LIST *dl) { static int mrisRipAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int ripflag); static int mrisRipDefect(MRI_SURFACE *mris, DEFECT *defect, int ripflag); -int MRISisSurfaceValid(MRIS *mris, int patch, int verbose) { +int MRISisSurfaceValid(MRIS *mris, int patch, int verbose) +{ int n, m, p, q, vnop, nfound, mark; VERTEX *vn; int euler, nedges, nvf, nffm, nffs, cf, nvc; @@ -42560,13 +43439,15 @@ int MRISisSurfaceValid(MRIS *mris, int patch, int verbose) { if (patch && (nffm || nvc)) { return 0; - } else if (nvf || nffs || nffm || nvc) { + } + else if (nvf || nffs || nffm || nvc) { return 0; } return 1; } -void MRISidentifyDefects(MRIS *mris, TOPOFIX_PARMS *parms) { +void MRISidentifyDefects(MRIS *mris, TOPOFIX_PARMS *parms) +{ int fno; FACE_DEFECT_LIST *fdl; DEFECT_LIST *dl; @@ -42598,7 +43479,8 @@ void MRISidentifyDefects(MRIS *mris, TOPOFIX_PARMS *parms) { parms->defect_list = (void *)dl; } -static int detectContrast(MRIS *mris) { +static int detectContrast(MRIS *mris) +{ int n, nv; double wm, gm; VERTEX *v; @@ -42621,13 +43503,15 @@ static int detectContrast(MRIS *mris) { if (wm > gm) { fprintf(WHICH_OUTPUT, " right direction [ GM (%3.2f) < WM (%3.2f) ]\n", gm, wm); return 1; - } else { + } + else { fprintf(WHICH_OUTPUT, " inverted [ WM (%3.2f) < GM (%3.2f) ]\n", wm, gm); return -1; } } -void MRISinitTopoFixParameters(MRIS *mris, TOPOFIX_PARMS *parms) { +void MRISinitTopoFixParameters(MRIS *mris, TOPOFIX_PARMS *parms) +{ #if MATRIX_ALLOCATION /* allocation of the transform matrix */ VoxelFromSRASmatrix = GetSurfaceRASToVoxelMatrix(parms->mri); @@ -42675,7 +43559,8 @@ void MRISinitTopoFixParameters(MRIS *mris, TOPOFIX_PARMS *parms) { mrisMarkAllDefects(mris, (DEFECT_LIST *)parms->defect_list, 0); } -MRI *mriInitDefectVolume(MRIS *mris, TOPOFIX_PARMS *parms) { +MRI *mriInitDefectVolume(MRIS *mris, TOPOFIX_PARMS *parms) +{ MRI *mri; VERTEX *v; @@ -42685,7 +43570,8 @@ MRI *mriInitDefectVolume(MRIS *mris, TOPOFIX_PARMS *parms) { if (parms->volume_resolution == -1) { scale = VOLUME_SCALE; - } else { + } + else { scale = parms->volume_resolution; } @@ -42752,7 +43638,8 @@ MRI *mriInitDefectVolume(MRIS *mris, TOPOFIX_PARMS *parms) { } // used for fs_topo_fixer -void MRISsaveLocal(MRIS *mris, TOPOFIX_PARMS *parms, char *name) { +void MRISsaveLocal(MRIS *mris, TOPOFIX_PARMS *parms, char *name) +{ int static n_br = 0; char fname[512]; int n; @@ -42808,7 +43695,8 @@ void MRISsaveLocal(MRIS *mris, TOPOFIX_PARMS *parms, char *name) { static void defectVolumeWM(MRI *mri, MRI *mri_defect, MRI *mri_wm); -void mrisInitDefectMRIParameters(MRIS *mris, TOPOFIX_PARMS *parms) { +void mrisInitDefectMRIParameters(MRIS *mris, TOPOFIX_PARMS *parms) +{ MRI *mri_defect, *mri_defect_white, *mri_defect_gray, *mri_defect_sign, *mri_defect_initial_sign, *mri_defect_wm; DP *dp; DEFECT *defect; @@ -42849,7 +43737,8 @@ void mrisInitDefectMRIParameters(MRIS *mris, TOPOFIX_PARMS *parms) { dp->mri = parms->mri; } -void MRISinitDefectParameters(MRIS *mris, TOPOFIX_PARMS *parms) { +void MRISinitDefectParameters(MRIS *mris, TOPOFIX_PARMS *parms) +{ int n, nvertices, nchull, defect_number; DEFECT *defect; DP *dp; @@ -42937,7 +43826,8 @@ void MRISinitDefectParameters(MRIS *mris, TOPOFIX_PARMS *parms) { mrisInitDefectMRIParameters(mris, parms); } -void TOPOFIXfreeDP(TOPOFIX_PARMS *parms) { +void TOPOFIXfreeDP(TOPOFIX_PARMS *parms) +{ DP *dp; dp = (DP *)parms->dp; if (dp == NULL) { @@ -42971,7 +43861,8 @@ void TOPOFIXfreeDP(TOPOFIX_PARMS *parms) { parms->dp = NULL; } -void MRISmarkPatchVertices(MRIS *mris, TOPOFIX_PARMS *parms, int ninitvertices) { +void MRISmarkPatchVertices(MRIS *mris, TOPOFIX_PARMS *parms, int ninitvertices) +{ int n; DP *dp; TP *tp; @@ -42986,7 +43877,8 @@ void MRISmarkPatchVertices(MRIS *mris, TOPOFIX_PARMS *parms, int ninitvertices) } } -void MRISmarkBorderVertices(MRIS *mris, TOPOFIX_PARMS *parms, int mark) { +void MRISmarkBorderVertices(MRIS *mris, TOPOFIX_PARMS *parms, int mark) +{ int n; DP *dp; TP *tp; @@ -42999,7 +43891,8 @@ void MRISmarkBorderVertices(MRIS *mris, TOPOFIX_PARMS *parms, int mark) { } } -void MRISinitDefectPatch(MRIS *mris, TOPOFIX_PARMS *parms) { +void MRISinitDefectPatch(MRIS *mris, TOPOFIX_PARMS *parms) +{ int n; DP *dp; TP *tp; @@ -43041,7 +43934,8 @@ void MRISinitDefectPatch(MRIS *mris, TOPOFIX_PARMS *parms) { tp->nedges = 0; } -void MRIScomputeInitialFitness(MRIS *mris, TOPOFIX_PARMS *parms) { +void MRIScomputeInitialFitness(MRIS *mris, TOPOFIX_PARMS *parms) +{ parms->mris_defect = mris; MRIScomputeFitness(mris, parms, 0); parms->initial_fitness = 0.0; @@ -43054,14 +43948,16 @@ void MRIScomputeInitialFitness(MRIS *mris, TOPOFIX_PARMS *parms) { static void MRISdefectMaximizeLikelihood(MRI *mri, MRI_SURFACE *mris, DP *dp, int niter, double alpha, int mode); -void MRISdefectMatch(MRIS *mris, TOPOFIX_PARMS *parms) { +void MRISdefectMatch(MRIS *mris, TOPOFIX_PARMS *parms) +{ // fs_topo_fixer_test // defectMatch(parms->mri,mris,(DP*)parms->dp,2,1);//parms->smooth, parms->match); MRISdefectMaximizeLikelihood(parms->mri, mris, (DP *)parms->dp, 40, 0.5, 1); MRISrestoreVertexPositions(mris, ORIGINAL_VERTICES); } -double computeSurfaceLikelihood(MRIS *mris, DP *dp, int verbose) { +double computeSurfaceLikelihood(MRIS *mris, DP *dp, int verbose) +{ int n; double Km, Hm; VERTEX *v; @@ -43083,7 +43979,8 @@ double computeSurfaceLikelihood(MRIS *mris, DP *dp, int verbose) { return -Hm; } -double computeVolumeLikelihood(DP *dp, int contrast, int verbose) { +double computeVolumeLikelihood(DP *dp, int contrast, int verbose) +{ double int_g, int_w, val, val2, dval, delta, delta_ll; int i, j, k; double white_mean, gray_mean, white_vol, gray_vol; @@ -43134,7 +44031,8 @@ double computeVolumeLikelihood(DP *dp, int contrast, int verbose) { if (val2 > val) { white_vol += dval; int_w += dval * valvox; - } else { + } + else { gray_vol += dval; int_g += dval * valvox; } @@ -43163,7 +44061,8 @@ double computeVolumeLikelihood(DP *dp, int contrast, int verbose) { if (verbose) { if (gray_vol > white_vol) { fprintf(stderr, "CUTTING HANDLE\n"); - } else { + } + else { fprintf(stderr, "FILLING HANDLE\n"); } @@ -43194,7 +44093,8 @@ static double l_vol = 1.0; static double l_surf = 1.0; static double l_wm = 1.0; -double MRIScomputeFitness(MRIS *mris, TOPOFIX_PARMS *parms, int verbose) { +double MRIScomputeFitness(MRIS *mris, TOPOFIX_PARMS *parms, int verbose) +{ static int first_time = 1; double fitness, unmri_ll, curv_ll; DP *dp; @@ -43268,7 +44168,8 @@ double MRIScomputeFitness(MRIS *mris, TOPOFIX_PARMS *parms, int verbose) { return (fitness); } -void MRISprintInfo(TOPOFIX_PARMS *parms) { +void MRISprintInfo(TOPOFIX_PARMS *parms) +{ TP *tp; tp = &((DP *)parms->dp)->tp; TPprint(tp); @@ -43276,7 +44177,8 @@ void MRISprintInfo(TOPOFIX_PARMS *parms) { // ------------ Definition of the static functions -------------------- // -static void TPprint(TP *tp) { +static void TPprint(TP *tp) +{ double mri, curv; #if DO_NOT_USE_AREA mri = (tp->face_ll + tp->vertex_ll) / 4.0; @@ -43295,13 +44197,15 @@ static void TPprint(TP *tp) { fprintf(WHICH_OUTPUT, " ( f=%2.2f , v=%2.2f , c=%2.2f , q= %2.2f ) \n", tp->fll, tp->vll, tp->cll, tp->qcll); } -static void TPinit(TP *tp) { +static void TPinit(TP *tp) +{ tp->vertices = NULL; tp->faces = NULL; tp->edges = NULL; } -static void TPfree(TP *tp) { +static void TPfree(TP *tp) +{ if (tp->vertices) { free(tp->vertices); } @@ -43314,7 +44218,8 @@ static void TPfree(TP *tp) { TPinit(tp); } -static SEGMENTATION *SEGMENTATIONalloc(int max_segments, int max_edges) { +static SEGMENTATION *SEGMENTATIONalloc(int max_segments, int max_edges) +{ int n; SEGMENTATION *seg; SEGMENT *segment; @@ -43338,7 +44243,8 @@ static SEGMENTATION *SEGMENTATIONalloc(int max_segments, int max_edges) { return seg; } -static void SEGMENTATIONfree(SEGMENTATION **segmentation) { +static void SEGMENTATIONfree(SEGMENTATION **segmentation) +{ int n; SEGMENTATION *seg; @@ -43359,7 +44265,8 @@ static void SEGMENTATIONfree(SEGMENTATION **segmentation) { free(seg); } -static int findSegment(SEGMENTATION *segmentation) { +static int findSegment(SEGMENTATION *segmentation) +{ int n; SEGMENT *tmp; @@ -43378,7 +44285,8 @@ static int findSegment(SEGMENTATION *segmentation) { return n; } -static int compatibility(SEGMENTATION *segmentation, int segment_n, int edge_n) { +static int compatibility(SEGMENTATION *segmentation, int segment_n, int edge_n) +{ SEGMENT *segment; ES *es; int n, m; @@ -43406,7 +44314,8 @@ static int compatibility(SEGMENTATION *segmentation, int segment_n, int edge_n) } /* add edge n into segment n */ -static int addEdgeToSegment(SEGMENTATION *segmentation, int segment_n, int edge_n) { +static int addEdgeToSegment(SEGMENTATION *segmentation, int segment_n, int edge_n) +{ SEGMENT *segment; int n, m, inside, val, *tmp, nedges; ES *es; @@ -43453,7 +44362,8 @@ static int addEdgeToSegment(SEGMENTATION *segmentation, int segment_n, int edge_ } /* merge segment 2 into segment 1 */ -static int mergeSegmentToSegment(SEGMENTATION *segmentation, int segment_1, int segment_2) { +static int mergeSegmentToSegment(SEGMENTATION *segmentation, int segment_1, int segment_2) +{ int n, m, val, inside, nedges, *tmp; SEGMENT *segment1, *segment2; @@ -43523,7 +44433,8 @@ static int mergeSegmentToSegment(SEGMENTATION *segmentation, int segment_1, int #define MAX_CLUSTERS 40 -static void segmentEdge(MRIS *mris, SEGMENTATION *segmentation, int edge_n) { +static void segmentEdge(MRIS *mris, SEGMENTATION *segmentation, int edge_n) +{ int n, m, vno, stop; int clusters[MAX_CLUSTERS], nclusters, segment_n; EP *ep; @@ -43601,7 +44512,8 @@ static void segmentEdge(MRIS *mris, SEGMENTATION *segmentation, int edge_n) { // fprintf(stderr," %d",segmentation->nsegments); } -static SEGMENTATION *segmentIntersectingEdges(MRIS *mris, DEFECT *defect, int *vertex_trans, ES *es, int *nedges) { +static SEGMENTATION *segmentIntersectingEdges(MRIS *mris, DEFECT *defect, int *vertex_trans, ES *es, int *nedges) +{ int n, m, vno1, vno2, ndiscarded, nes, vtn; int nsegments, *segments, *sizes, changed, tmp; EDGE e1, e2; @@ -43896,7 +44808,8 @@ static SEGMENTATION *segmentIntersectingEdges(MRIS *mris, DEFECT *defect, int *v if (nbh_size == -1) { nbh = segmentation->edges[ep->edges[m]].segment; nbh_size = segmentation->segments[nbh].nedges; - } else if (segmentation->segments[segmentation->edges[ep->edges[m]].segment].nedges < nbh_size) { + } + else if (segmentation->segments[segmentation->edges[ep->edges[m]].segment].nedges < nbh_size) { nbh = segmentation->edges[ep->edges[m]].segment; nbh_size = segmentation->segments[nbh].nedges; } @@ -43908,7 +44821,8 @@ static SEGMENTATION *segmentIntersectingEdges(MRIS *mris, DEFECT *defect, int *v if (nbh_size == -1) { nbh = segmentation->edges[ep->edges[m]].segment; nbh_size = segmentation->segments[nbh].nedges; - } else if (segmentation->segments[segmentation->edges[ep->edges[m]].segment].nedges < nbh_size) { + } + else if (segmentation->segments[segmentation->edges[ep->edges[m]].segment].nedges < nbh_size) { nbh = segmentation->edges[ep->edges[m]].segment; nbh_size = segmentation->segments[nbh].nedges; } @@ -43971,7 +44885,8 @@ static SEGMENTATION *segmentIntersectingEdges(MRIS *mris, DEFECT *defect, int *v } static void saveSegmentation( - MRIS *mris, MRIS *mris_corrected, DEFECT *defect, int *vertex_trans, ES *es, int nes, char *fname) { + MRIS *mris, MRIS *mris_corrected, DEFECT *defect, int *vertex_trans, ES *es, int nes, char *fname) +{ int n, val, v_rgb, vtn; int r, g, b, rgb[10]; char name[500]; @@ -44026,7 +44941,8 @@ static void saveSegmentation( MRISwriteAnnotation(mris, name); } -static void generateOrdering(DP *dp, SEGMENTATION *segmentation, int i) { +static void generateOrdering(DP *dp, SEGMENTATION *segmentation, int i) +{ int n, m, val, r; int *ordering, *counter, nedges; int *seg_order, nseg; @@ -44110,7 +45026,8 @@ static void generateOrdering(DP *dp, SEGMENTATION *segmentation, int i) { } } -static MRIS *extractDefect(MRIS *mris, DEFECT *defect) { +static MRIS *extractDefect(MRIS *mris, DEFECT *defect) +{ int n, vno, nvertices, nfaces, *vtrans, *vertex_trans; VERTEX *vdst, *vsrc; FACE *fdst, *fsrc; @@ -44162,7 +45079,8 @@ static MRIS *extractDefect(MRIS *mris, DEFECT *defect) { continue; } vno = vertex_trans[defect->vertices[n]]; - } else { + } + else { vno = vertex_trans[defect->chull[n - defect->nvertices]]; } @@ -44223,8 +45141,8 @@ static MRIS *extractDefect(MRIS *mris, DEFECT *defect) { #define EXTRACT_SMALL_SURFACE 0 -static void savePatch( - MRI *mri, MRIS *mris, MRIS *mris_corrected, DVS *dvs, DP *dp, char *fname, TOPOLOGY_PARMS *parms) { +static void savePatch(MRI *mri, MRIS *mris, MRIS *mris_corrected, DVS *dvs, DP *dp, char *fname, TOPOLOGY_PARMS *parms) +{ int i; VERTEX *vsrc, *vdst; MRIS *mris_small; @@ -44253,7 +45171,8 @@ static void savePatch( mris_small = extractDefect(mris_corrected, dp->defect); /* save surface */ MRISwrite(mris_small, fname); - } else + } + else /* save surface */ { MRISwrite(mris_corrected, fname); @@ -44276,7 +45195,8 @@ static void savePatch( continue; } vno = dp->defect->vertex_trans[dp->defect->vertices[i]]; - } else + } + else vno = dp->defect->vertex_trans[dp->defect->chull[i - dp->defect->nvertices]]; if (vno < 0 || vno >= mris_corrected->nvertices) { continue; @@ -44289,7 +45209,8 @@ static void savePatch( } /* save surface */ MRISwrite(mris_small, fname); - } else + } + else /* save surface */ { MRISwrite(mris_corrected, fname); @@ -44312,7 +45233,8 @@ static void savePatch( continue; } vno = dp->defect->vertex_trans[dp->defect->vertices[i]]; - } else { + } + else { vno = dp->defect->vertex_trans[dp->defect->chull[i - dp->defect->nvertices]]; } if (vno < 0 || vno >= mris_corrected->nvertices) { @@ -44326,7 +45248,8 @@ static void savePatch( } /* save surface */ MRISwrite(mris_small, fname); - } else + } + else /* save surface */ { MRISwrite(mris_corrected, fname); @@ -44360,7 +45283,8 @@ static void savePatch( MRISwriteCurvature(mris_small, fname); /* free small surface */ MRISfree(&mris_small); - } else + } + else /* save curvature */ { MRISwriteCurvature(mris_corrected, fname); @@ -44388,7 +45312,8 @@ static void savePatch( } static void updateVertexStatistics( - MRIS *mris, MRIS *mris_corrected, DVS *dvs, RP *rp, DP *dp, int *vertex_trans, float fitness) { + MRIS *mris, MRIS *mris_corrected, DVS *dvs, RP *rp, DP *dp, int *vertex_trans, float fitness) +{ DEFECT *defect; EDGE_TABLE *etable; int i, nedges; @@ -44453,7 +45378,8 @@ static void updateVertexStatistics( } } -static int deleteWorstVertices(MRIS *mris, RP *rp, DEFECT *defect, int *vertex_trans, float fraction, int count) { +static int deleteWorstVertices(MRIS *mris, RP *rp, DEFECT *defect, int *vertex_trans, float fraction, int count) +{ int i, nvoxels, niters, init, changed; float max; int max_i; @@ -44545,7 +45471,8 @@ static int deleteWorstVertices(MRIS *mris, RP *rp, DEFECT *defect, int *vertex_t /* (*k)=kVOL(mri,x); */ /* } */ -static MRI *mriDefectVolume(MRIS *mris, EDGE_TABLE *etable, TOPOLOGY_PARMS *parms) { +static MRI *mriDefectVolume(MRIS *mris, EDGE_TABLE *etable, TOPOLOGY_PARMS *parms) +{ MRI *mri; VERTEX *v; #if 0 @@ -44558,7 +45485,8 @@ static MRI *mriDefectVolume(MRIS *mris, EDGE_TABLE *etable, TOPOLOGY_PARMS *parm if (parms->volume_resolution == -1) { scale = VOLUME_SCALE; - } else { + } + else { scale = parms->volume_resolution; } @@ -44677,7 +45605,8 @@ static MRI *mriDefectVolume(MRIS *mris, EDGE_TABLE *etable, TOPOLOGY_PARMS *parm } MRIvox(mri, l, p, q) = 1; } - } else { + } + else { dx = dy = dz = 0.0f; l = iVOL(mri, x1); p = jVOL(mri, y1); @@ -44798,7 +45727,8 @@ static MRI *mriDefectVolume(MRIS *mris, EDGE_TABLE *etable, TOPOLOGY_PARMS *parm return mri; } -static void defectVolumeWM(MRI *mri, MRI *mri_defect, MRI *mri_wm) { +static void defectVolumeWM(MRI *mri, MRI *mri_defect, MRI *mri_wm) +{ int i, j, k; double x, y, z, xv, yv, zv, val; @@ -44834,7 +45764,8 @@ static void defectVolumeLikelihood(MRI *mri, float white_mean, float gray_mean, int type, - int contrast) { + int contrast) +{ int i, j, k, n; double x, y, z, xv, yv, zv, val, sigma; @@ -44861,8 +45792,8 @@ static void defectVolumeLikelihood(MRI *mri, if (type == 0) { MRIFvox(mri_white, i, j, k) = log(h_white->counts[nint(MIN(val, white_mean))]); MRIFvox(mri_gray, i, j, k) = log(h_gray->counts[nint(MAX(val, gray_mean))]); - - } else { + } + else { // topo_fixer // MRIFvox(mri_white,i,j,k) = log(1.0/(1.0+exp(-(val-mu)/sigma))); @@ -44871,26 +45802,32 @@ static void defectVolumeLikelihood(MRI *mri, if (contrast == 1) { if (val > white_mean) { MRIFvox(mri_white, i, j, k) = 0.0; - } else { + } + else { MRIFvox(mri_white, i, j, k) = SQR((val - white_mean) / sigma); } if (val < gray_mean) { MRIFvox(mri_gray, i, j, k) = 0.0; - } else { + } + else { MRIFvox(mri_gray, i, j, k) = SQR((val - gray_mean) / sigma); } - } else if (contrast == -1) { + } + else if (contrast == -1) { if (val < white_mean) { MRIFvox(mri_white, i, j, k) = 0.0; - } else { + } + else { MRIFvox(mri_white, i, j, k) = SQR((val - white_mean) / sigma); } if (val > gray_mean) { MRIFvox(mri_gray, i, j, k) = 0.0; - } else { + } + else { MRIFvox(mri_gray, i, j, k) = SQR((val - gray_mean) / sigma); } - } else { + } + else { MRIFvox(mri_white, i, j, k) = SQR((val - white_mean) / sigma); MRIFvox(mri_gray, i, j, k) = SQR((val - gray_mean) / sigma); } @@ -44908,7 +45845,8 @@ static void defectVolumeLikelihood(MRI *mri, } static void mrisComputeSurfaceStatistics( - MRIS *mris, MRI *mri, HISTOGRAM *h_k1, HISTOGRAM *h_k2, MRI *mri_k1_k2, MRI *mri_gray_white, HISTOGRAM *h_dot) { + MRIS *mris, MRI *mri, HISTOGRAM *h_k1, HISTOGRAM *h_k2, MRI *mri_k1_k2, MRI *mri_gray_white, HISTOGRAM *h_dot) +{ int n, nvertices, nfaces; TP tp; float total_ll; @@ -44974,7 +45912,8 @@ static void computeDefectStatistics(MRI *mri, HISTOGRAM *h_k1, HISTOGRAM *h_k2, MRI *mri_k1_k2, - int verbose) { + int verbose) +{ float val, mean, var, mg, mw, vw, vg, total, max, white_val, gray_val, x, y, z, cx, cy, cz, ival, k1, k2, vk1, vk2, wv, gv; double xv, yv, zv, int_val; @@ -45232,7 +46171,8 @@ static void computeDefectStatistics(MRI *mri, } /* call the right smoothing and matching functions */ -static void defectMatch(MRI *mri, MRI_SURFACE *mris, DP *dp, int smooth, int match) { +static void defectMatch(MRI *mri, MRI_SURFACE *mris, DP *dp, int smooth, int match) +{ if (smooth) { defectSmooth(mris, dp, 25, 0.1, smooth); } @@ -45242,7 +46182,8 @@ static void defectMatch(MRI *mri, MRI_SURFACE *mris, DP *dp, int smooth, int mat } /* perform a light smoothing of the defect vertices */ -static void defectSmooth(MRI_SURFACE *mris, DP *dp, int niter, double alpha, int type) { +static void defectSmooth(MRI_SURFACE *mris, DP *dp, int niter, double alpha, int type) +{ int i, n; VERTEX *v, *vn; float x, y, z; @@ -45578,7 +46519,8 @@ static void defectSmooth(MRI_SURFACE *mris, DP *dp, int niter, double alpha, int computeDefectVertexNormals(mris, dp); } -static void MRISdefectMaximizeLikelihood(MRI *mri, MRI_SURFACE *mris, DP *dp, int niter, double alpha, int mode) { +static void MRISdefectMaximizeLikelihood(MRI *mri, MRI_SURFACE *mris, DP *dp, int niter, double alpha, int mode) +{ float wm, gm, mean; int i, n, nvertices, *vertices; VERTEX *v, *vn; @@ -45696,7 +46638,8 @@ static void MRISdefectMaximizeLikelihood(MRI *mri, MRI_SURFACE *mris, DP *dp, in } } -static void defectMaximizeLikelihood(MRI *mri, MRI_SURFACE *mris, DP *dp, int niter, double alpha) { +static void defectMaximizeLikelihood(MRI *mri, MRI_SURFACE *mris, DP *dp, int niter, double alpha) +{ float wm, gm, mean; int i, n, nvertices; VERTEX *v, *vn; @@ -45792,7 +46735,8 @@ static void defectMaximizeLikelihood(MRI *mri, MRI_SURFACE *mris, DP *dp, int ni } } -static void detectDefectFaces(MRIS *mris, DEFECT_PATCH *dp) { +static void detectDefectFaces(MRIS *mris, DEFECT_PATCH *dp) +{ int i, n, m, vno, vn1, vn2, nvertices, nthings, *things, nfaces; int optimal = dp->defect->optimal_mapping; VERTEX *v; @@ -45887,7 +46831,8 @@ static void detectDefectFaces(MRIS *mris, DEFECT_PATCH *dp) { #define DEBUG_INFO 0 -static int computePatchEulerNumber(MRIS *mris, DP *dp) { +static int computePatchEulerNumber(MRIS *mris, DP *dp) +{ int nfaces, nedges, nvertices, euler; /* everything has already been computed */ @@ -45915,7 +46860,8 @@ static int computePatchEulerNumber(MRIS *mris, DP *dp) { return euler; } -static void orientDefectFaces(MRIS *mris, DP *dp) { +static void orientDefectFaces(MRIS *mris, DP *dp) +{ int n, m, vno0, vno1, fno; float dot, cx, cy, cz, a[3], b[3], norm[3]; TP *tp; @@ -45974,7 +46920,8 @@ static void orientDefectFaces(MRIS *mris, DP *dp) { } } -static void computeDefectFaceNormal(MRIS *mris, FACE *face) { +static void computeDefectFaceNormal(MRIS *mris, FACE *face) +{ VERTEX *v1, *v2, *v3; float a[3], b[3], norm[3], len, nx, ny, nz; @@ -46030,7 +46977,8 @@ static void computeDefectFaceNormal(MRIS *mris, FACE *face) { // FLO TO BE CHECKED #define TEMPORARY_RIPPED_FACE 2 -static void computeDefectFaceNormals(MRIS *mris, DP *dp) { +static void computeDefectFaceNormals(MRIS *mris, DP *dp) +{ int i, n; VERTEX *v; FACE *face; @@ -46064,7 +47012,8 @@ static void computeDefectFaceNormals(MRIS *mris, DP *dp) { } } -static void computeDefectVertexNormals(MRIS *mris, DP *dp) { +static void computeDefectVertexNormals(MRIS *mris, DP *dp) +{ int n, m; float nx, ny, nz, len; TP *tp; @@ -46103,7 +47052,8 @@ static void computeDefectVertexNormals(MRIS *mris, DP *dp) { } } -static void computeDefectTangentPlaneAtVertex(MRIS *mris, int vno) { +static void computeDefectTangentPlaneAtVertex(MRIS *mris, int vno) +{ float a[3], b[3], c[3], len; VERTEX *v; @@ -46154,7 +47104,8 @@ static void computeDefectTangentPlaneAtVertex(MRIS *mris, int vno) { v->e2z = b[2] / len; } -static void computeDefectSecondFundamentalForm(MRIS *mris, TP *tp) { +static void computeDefectSecondFundamentalForm(MRIS *mris, TP *tp) +{ int p, vno, i, n, nbad = 0; VERTEX *vertex, *vnb; MATRIX *m_U, *m_Ut, *m_tmp1, *m_tmp2, *m_inverse, *m_eigen, *m_Q; @@ -46241,7 +47192,8 @@ static void computeDefectSecondFundamentalForm(MRIS *mris, TP *tp) { /* singular matrix - must be planar?? */ nbad++; evalues[0] = evalues[1] = 0.0; - } else { + } + else { m_tmp1 = MatrixMultiply(m_Ut, v_z, NULL); /* Ut z */ MatrixMultiply(m_inverse, m_tmp1, v_c); /* (Ut U)^-1 Ut z */ @@ -46328,7 +47280,8 @@ static void computeDefectSecondFundamentalForm(MRIS *mris, TP *tp) { /* computeDefectSecondFundamentalForm(mris,tp); */ /* } */ -static void printDefectStatistics(DP *dp) { +static void printDefectStatistics(DP *dp) +{ // fprintf(WHICH_OUTPUT,"fitness=%2.4f\n",dp->fitness); fprintf(WHICH_OUTPUT, "X=%d (v=%d,e=%d,f=%d): %d vertices were discarded\n", @@ -46359,7 +47312,8 @@ static void printDefectStatistics(DP *dp) { #define BORDER_VERTEX TRIANGLE_VERTEX /* part of a triangle! */ #define USED_VERTEX 5 /* used in the final tessellation */ -static int isVertexInsideFace(MRIS *mris, int vno, int fno) { +static int isVertexInsideFace(MRIS *mris, int vno, int fno) +{ int i; VERTEX *V0, *V1, *V2, *V, *Vn; double sign, test, normal[3], orgn[3], tangent[3]; @@ -46418,7 +47372,8 @@ static int isVertexInsideFace(MRIS *mris, int vno, int fno) { } /* check if the vertex vno1 is contained in one of the faces of vno2 */ -static int isDiscarded(MRIS *mris, int vno1, int vno2) { +static int isDiscarded(MRIS *mris, int vno1, int vno2) +{ int n; VERTEX *v; @@ -46433,7 +47388,8 @@ static int isDiscarded(MRIS *mris, int vno1, int vno2) { return 0; } -static void removeVertex(MRIS *mris, int vno) { +static void removeVertex(MRIS *mris, int vno) +{ int n, m, vnum, *oldlist; VERTEX *v, *vn; @@ -46464,7 +47420,8 @@ static void removeVertex(MRIS *mris, int vno) { vn->v[vnum++] = oldlist[m]; } free(oldlist); - } else { + } + else { vn->v = NULL; } vn->vnum = vnum; @@ -46481,7 +47438,8 @@ static void removeVertex(MRIS *mris, int vno) { v->vtotal = 0; } -static int updateVertexTriangle(MRIS *mris, int vno, int fno) { +static int updateVertexTriangle(MRIS *mris, int vno, int fno) +{ int n, m, vn; VERTEX *v; @@ -46529,7 +47487,8 @@ static int updateVertexTriangle(MRIS *mris, int vno, int fno) { /* } */ /* check if the edge vno1 <--> vno2 is the edge of a triangle */ -static void findNewTriangles(MRIS *mris, int vno1, int vno2) { +static void findNewTriangles(MRIS *mris, int vno1, int vno2) +{ int n, m, vn, fno; VERTEX *v; @@ -46570,7 +47529,8 @@ static void findNewTriangles(MRIS *mris, int vno1, int vno2) { } } -static int isEdgeAdded(MRIS *mris, int vno1, int vno2, int mode) { +static int isEdgeAdded(MRIS *mris, int vno1, int vno2, int mode) +{ int mark1, mark2, tmp; VERTEX *v1, *v2; @@ -46607,14 +47567,16 @@ static int isEdgeAdded(MRIS *mris, int vno1, int vno2, int mode) { /* remove this vertex that is not connected to anyone */ v1->marked = DISCARDED_VERTEX; return 0; - } else { + } + else { /* outside the faces */ mrisAddEdge(mris, vno1, vno2); /* the first vertex becomes EDGE */ v1->marked = EDGE_VERTEX; return 1; } - } else { + } + else { /* the second vertex is either of type INSIDE or EDGE */ mrisAddEdge(mris, vno1, vno2); /* they both become EDGE */ @@ -46630,7 +47592,8 @@ static int isEdgeAdded(MRIS *mris, int vno1, int vno2, int mode) { /* look for new triangles */ findNewTriangles(mris, vno1, vno2); return 1; - } else { + } + else { /* vno2 is of type TRIANGLE_VERTEX */ /* is the first vertex inside or outside the faces of vno2 */ if (isDiscarded(mris, vno1, vno2)) { @@ -46638,7 +47601,8 @@ static int isEdgeAdded(MRIS *mris, int vno1, int vno2, int mode) { /* remove this vertex and its connexions */ removeVertex(mris, vno1); return 0; - } else { + } + else { /* outside */ mrisAddEdge(mris, vno1, vno2); /* check if some new triangles have been formed : if yes, update type*/ @@ -46659,12 +47623,14 @@ static int isEdgeAdded(MRIS *mris, int vno1, int vno2, int mode) { return 0; }; -typedef struct { +typedef struct +{ int intersected; int vno1, vno2; } INTERSECTION_TABLE, IT; -static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DVS *dvs, DP *dp) { +static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DVS *dvs, DP *dp) +{ double max_len; int i, j, max_i, max_added, nadded, index, ndiscarded; int (*intersection_function)(MRI_SURFACE * mris, DEFECT * defect, EDGE * e, int *vertex_trans, int *v1, int *v2); @@ -46737,7 +47703,8 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV for (index = 0; index < nedges; index++) { if (ordering) { i = ordering[index]; - } else { + } + else { i = index; } @@ -46789,7 +47756,8 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV } if (etable->flags[i] & ET_OVERLAP_LIST_INCOMPLETE) { intersection_function = intersectDefectEdges; - } else { + } + else { intersection_function = intersectDefectConvexHullEdges; } } @@ -46801,7 +47769,8 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV if (et[i].used) /* used in original tessellation */ { et[i].used = USED_IN_BOTH_TEMPORARY_TESSELLATION; - } else { + } + else { et[i].used = USED_IN_NEW_TEMPORARY_TESSELLATION; } /* useful only if mode = USE_ALL_VERTICES */ @@ -46817,7 +47786,8 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV } } } - } else /* intersecting edge with edge e1<-->e2 */ + } + else /* intersecting edge with edge e1<-->e2 */ { it[i].intersected = 2; } @@ -46827,7 +47797,8 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV /* keep the same order (not necessary) */ if (ordering) { i = ordering[index]; - } else { + } + else { i = index; } @@ -46858,10 +47829,12 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV mris_corrected->vertices[it[i].vno2].marked == DISCARDED_VERTEX) { modified = 1; it[i].intersected = 0; - } else { + } + else { it[i].intersected = 1; } - } else { + } + else { it[i].intersected = 1; } } @@ -46874,7 +47847,8 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV /* keep the same order (not necessary) */ if (ordering) { i = ordering[index]; - } else { + } + else { i = index; } @@ -46967,7 +47941,8 @@ static int retessellateDefect(MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, DV return (NO_ERROR); } -static void computeDisplacement(MRI_SURFACE *mris, DP *dp) { +static void computeDisplacement(MRI_SURFACE *mris, DP *dp) +{ DEFECT *defect; int p, vno; float val; @@ -47001,7 +47976,8 @@ static double mrisDefectPatchFitness(MRI_SURFACE *mris, HISTOGRAM *h_grad, MRI *mri_gray_white, HISTOGRAM *h_dot, - TOPOLOGY_PARMS *parms) { + TOPOLOGY_PARMS *parms) +{ int i, euler; VERTEX *v; DEFECT *defect = dp->defect; @@ -47114,7 +48090,8 @@ static double mrisDefectPatchFitness(MRI_SURFACE *mris, return (dp->fitness); } -static int mrisFreeDefectVertexState(DEFECT_VERTEX_STATE *dvs) { +static int mrisFreeDefectVertexState(DEFECT_VERTEX_STATE *dvs) +{ int i; for (i = 0; i < dvs->nvertices; i++) { @@ -47132,7 +48109,8 @@ static int mrisFreeDefectVertexState(DEFECT_VERTEX_STATE *dvs) { return (NO_ERROR); } -static DEFECT_VERTEX_STATE *mrisRecordVertexState(MRI_SURFACE *mris, DEFECT *defect, int *vertex_trans) { +static DEFECT_VERTEX_STATE *mrisRecordVertexState(MRI_SURFACE *mris, DEFECT *defect, int *vertex_trans) +{ DEFECT_VERTEX_STATE *dvs; int i, n, vno; VERTEX *v; @@ -47212,7 +48190,8 @@ static DEFECT_VERTEX_STATE *mrisRecordVertexState(MRI_SURFACE *mris, DEFECT *def vs->f[n] = v->f[n]; vs->n[n] = v->n[n]; } - } else { + } + else { vs->num = 0; vs->f = NULL; vs->n = NULL; @@ -47223,7 +48202,8 @@ static DEFECT_VERTEX_STATE *mrisRecordVertexState(MRI_SURFACE *mris, DEFECT *def return (dvs); } -static int mrisRestoreFaceVertexState(MRI_SURFACE *mris, DEFECT_VERTEX_STATE *dvs) { +static int mrisRestoreFaceVertexState(MRI_SURFACE *mris, DEFECT_VERTEX_STATE *dvs) +{ int i, n, vno; VERTEX *v; VERTEX_STATE *vs; @@ -47263,7 +48243,8 @@ static int mrisRestoreFaceVertexState(MRI_SURFACE *mris, DEFECT_VERTEX_STATE *dv return (NO_ERROR); } -static int mrisRestoreVertexState(MRI_SURFACE *mris, DEFECT_VERTEX_STATE *dvs) { +static int mrisRestoreVertexState(MRI_SURFACE *mris, DEFECT_VERTEX_STATE *dvs) +{ int i, n, vno; VERTEX *v; VERTEX_STATE *vs; @@ -47326,7 +48307,8 @@ static int mrisRestoreVertexState(MRI_SURFACE *mris, DEFECT_VERTEX_STATE *dvs) { return (NO_ERROR); } -static int mrisComputeNormalDotDistribution(MRI_SURFACE *mris, HISTOGRAM *h_dot) { +static int mrisComputeNormalDotDistribution(MRI_SURFACE *mris, HISTOGRAM *h_dot) +{ int vno, bin, n, num; VERTEX *v, *vn; float bin_size, min_dot, max_dot, bin_val, dot, dx, dy, dz, nx, ny, nz, x, y, z; @@ -47428,7 +48410,8 @@ static int mrisComputeNormalDotDistribution(MRI_SURFACE *mris, HISTOGRAM *h_dot) static int mrisComputePrincipalCurvatureDistributions(MRI_SURFACE *mris, HISTOGRAM *h_k1, HISTOGRAM *h_k2, - MRI *mri_k1_k2) { + MRI *mri_k1_k2) +{ int vno, bin, bink1, bink2, nvertices, x, y; VERTEX *v; float k1_bin_size, k2_bin_size, min_k1, max_k1, min_k2, max_k2, bin_val, norm; @@ -47569,7 +48552,8 @@ static void computeGradient(MRIS *mris, double cx, double cy, double cz, double /* compute the NRG associated with the center (cx,cy,cz) and the squared radius R2 NRG = sum((x-cx)^2+(y-cy)^2+(z-cz)^2-R2)^2 */ -static double estimateNRG(MRIS *mris, double cx, double cy, double cz, double R2) { +static double estimateNRG(MRIS *mris, double cx, double cy, double cz, double R2) +{ int n; double NRG; for (NRG = 0, n = 0; n < mris->nvertices; n++) { @@ -47581,7 +48565,8 @@ static double estimateNRG(MRIS *mris, double cx, double cy, double cz, double R2 /* estimate the squared radius that minimizes the energy defined above for a given center (cx,cy,cz) */ -static double estimateSquaredRadius(MRIS *mris, double cx, double cy, double cz) { +static double estimateSquaredRadius(MRIS *mris, double cx, double cy, double cz) +{ int n; double R2; @@ -47596,8 +48581,8 @@ static double estimateSquaredRadius(MRIS *mris, double cx, double cy, double cz) /* compute the gradient of the energy defined above at location (cx,cy,cz,R2) */ -static void computeGradient( - MRIS *mris, double cx, double cy, double cz, double R2, double *gx, double *gy, double *gz) { +static void computeGradient(MRIS *mris, double cx, double cy, double cz, double R2, double *gx, double *gy, double *gz) +{ int n; double tx, ty, tz; tx = 0.0; @@ -47620,7 +48605,8 @@ static void computeGradient( /* Center the surface mris at location (cx,cy,cz) with a radius r such the energy sum((x-cx)^2+(y-cy)^2+(z-cz)^2-r^2)^2 is minimized */ -int MRIScenterSphere(MRI_SURFACE *mris) { +int MRIScenterSphere(MRI_SURFACE *mris) +{ VERTEX *vertex; int n, niters; /* sphere parameters */ @@ -47744,7 +48730,8 @@ int MRIScenterSphere(MRI_SURFACE *mris) { 10000. * y, 10000. * z); #endif - } else { + } + else { NRG = estimateNRG(mris, x, y, z, R2); } } @@ -47829,7 +48816,8 @@ static float computeAngleSign(MRIS *mris, int v,int v2, int v3) } #endif -typedef struct { +typedef struct +{ EDGE *inside_edges, *border_edges; int n_inside_edges, n_border_edges; } EDGE_LIST_INFO; @@ -47840,7 +48828,8 @@ typedef struct { static int ver1 = -1, ver2 = -1, ver3 = -1, ver4 = -1; #endif -int mrisApplyTopologyPreservingGradient(MRI_SURFACE *mris, double dt, int which_gradient) { +int mrisApplyTopologyPreservingGradient(MRI_SURFACE *mris, double dt, int which_gradient) +{ int vno, nvertices, n, m; VERTEX *v, *vn; //,*vm; EDGE e1, *e2; @@ -47906,8 +48895,8 @@ int mrisApplyTopologyPreservingGradient(MRI_SURFACE *mris, double dt, int which_ dx = v->odx; dy = v->ody; dz = v->odz; - - } else { + } + else { if (!isfinite(v->dx) || !isfinite(v->dy) || !isfinite(v->dz)) { ErrorPrintf(ERROR_BADPARM, "vertex %d position is not finite!\n", vno); } @@ -48052,7 +49041,8 @@ int mrisApplyTopologyPreservingGradient(MRI_SURFACE *mris, double dt, int which_ // step=5; if (step != 0 && step != 5) { fprintf(stderr, "%d+", step); - } else { + } + else { fprintf(stderr, "."); } #endif @@ -48214,7 +49204,8 @@ int mrisApplyTopologyPreservingGradient(MRI_SURFACE *mris, double dt, int which_ // step=5; if (step != 0 && step != 5) { fprintf(stderr, "%d_", step); - } else { + } + else { fprintf(stderr, ":"); } #endif @@ -48302,7 +49293,8 @@ int mrisApplyTopologyPreservingGradient(MRI_SURFACE *mris, double dt, int which_ // step=5; if (step != 0 && step != 5) { fprintf(stderr, "%d-", step); - } else { + } + else { fprintf(stderr, ","); } #endif @@ -48395,7 +49387,8 @@ static long nkilled = 0; static DEFECT_LIST *mrisMergeNeighboringDefects(MRIS *mris, DEFECT_LIST *dl); -static DEFECT_LIST *mrisMergeNeighboringDefects(MRIS *mris, DEFECT_LIST *dl) { +static DEFECT_LIST *mrisMergeNeighboringDefects(MRIS *mris, DEFECT_LIST *dl) +{ int i, j, n, m, *nd, ndefects, merged; int vlist[MAX_DEFECT_VERTICES], nadded; float len; @@ -48587,7 +49580,8 @@ static DEFECT_LIST *mrisMergeNeighboringDefects(MRIS *mris, DEFECT_LIST *dl) { return new_dl; } -MRIS *MRISremoveRippedSurfaceElements(MRIS *mris) { +MRIS *MRISremoveRippedSurfaceElements(MRIS *mris) +{ int *vertex_trans, *face_trans; int vno, fno, i, n, nrippedfaces, nrippedvertices, kept_vertices, kept_faces; MRIS *mris_corrected; @@ -48743,7 +49737,8 @@ static int defectIdentifyDefectiveVertices(MRI_SURFACE *mris, int mark_retained, int mark_discard, MHT *mht, - int mode) { + int mode) +{ int counting, n, p; VERTEX *v, *v0, *v1, *v2; FACE *f; @@ -48789,7 +49784,8 @@ static int defectIdentifyDefectiveVertices(MRI_SURFACE *mris, if (dot < 0.0f) /* not in same direction, area < 0 and reverse n */ { f->area = -area; - } else { + } + else { f->area = area; } } @@ -48831,7 +49827,8 @@ static int defectIdentifyDefectiveVertices(MRI_SURFACE *mris, } #if ADD_EXTRA_VERTICES /* verify if some defects are not overlapping : to be implemented */ -static DEFECT_LIST *mrisDefectAnalysis(MRIS *mris, DEFECT_LIST *dl) { +static DEFECT_LIST *mrisDefectAnalysis(MRIS *mris, DEFECT_LIST *dl) +{ int i, n; DEFECT *defect; @@ -48889,7 +49886,8 @@ static DEFECT_LIST *mrisDefectAnalysis(MRIS *mris, DEFECT_LIST *dl) { #endif #if ADD_EXTRA_VERTICES -static int pushApartDefects(MRIS *mris, DEFECT_LIST *dl) { +static int pushApartDefects(MRIS *mris, DEFECT_LIST *dl) +{ int i, n, p, m, vnop, total_nadded, nadded; DEFECT *defect; VERTEX *v, *vp, *vadded; @@ -48962,7 +49960,8 @@ static int pushApartDefects(MRIS *mris, DEFECT_LIST *dl) { ////////////////////////////////////////////////////////////////////// MRI_SURFACE *MRIScorrectTopology( - MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, MRI *mri, MRI *mri_wm, int nsmooth, TOPOLOGY_PARMS *parms) { + MRI_SURFACE *mris, MRI_SURFACE *mris_corrected, MRI *mri, MRI *mri_wm, int nsmooth, TOPOLOGY_PARMS *parms) +{ FACE_DEFECT_LIST *fdl; DEFECT_LIST *dl; DEFECT *defect; @@ -49089,7 +50088,8 @@ MRI_SURFACE *MRIScorrectTopology( continue; } vno = defect->vertices[n]; - } else { + } + else { vno = defect->border[n - defect->nvertices]; } v = &mris->vertices[vno]; @@ -49099,7 +50099,8 @@ MRI_SURFACE *MRIScorrectTopology( continue; } vno2 = defect->vertices[n2]; - } else { + } + else { vno2 = defect->border[n2 - defect->nvertices]; } if (vno == vno2) { @@ -49823,7 +50824,8 @@ MRI_SURFACE *MRIScorrectTopology( #if TESTING_OPTIMAL mrisFreeDefectVertexState(dvs); #endif - } else { + } + else { // main part of the routine: retessellation of the defect mrisTessellateDefect(mris, mris_corrected, @@ -50126,7 +51128,8 @@ MRI_SURFACE *MRIScorrectTopology( return (mris_corrected_final); } -static int mrisMarkAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int flag) { +static int mrisMarkAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int flag) +{ int j; for (j = 0; j < dl->ndefects; j++) { @@ -50135,7 +51138,8 @@ static int mrisMarkAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int flag) { return (NO_ERROR); } -static int mrisRipAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int flag) { +static int mrisRipAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int flag) +{ int j; for (j = 0; j < dl->ndefects; j++) { @@ -50155,7 +51159,8 @@ static int mrisRipAllDefects(MRI_SURFACE *mris, DEFECT_LIST *dl, int flag) { regions in which the topology is broken as the spherical homeomorphism is non-invertible. ------------------------------------------------------*/ -FACE_DEFECT_LIST *MRISmarkAmbiguousVertices(MRI_SURFACE *mris, int mark) { +FACE_DEFECT_LIST *MRISmarkAmbiguousVertices(MRI_SURFACE *mris, int mark) +{ FACE *f; VERTEX *v; int fno, flist[MAX_INT_FACES], i, nfaces, nmarked, n /*, vno, neg*/; @@ -50325,7 +51330,8 @@ FACE_DEFECT_LIST *MRISmarkAmbiguousVertices(MRI_SURFACE *mris, int mark) { - curv is used to save the marked flags during divideedge. - undefval and old_undefval are used to find the enclosing loop ------------------------------------------------------*/ -DEFECT_LIST *MRISsegmentDefects(MRI_SURFACE *mris, int mark_ambiguous, int mark_segmented) { +DEFECT_LIST *MRISsegmentDefects(MRI_SURFACE *mris, int mark_ambiguous, int mark_segmented) +{ DEFECT_LIST *dl; int vno, nadded; VERTEX *v; @@ -50402,7 +51408,8 @@ DEFECT_LIST *MRISsegmentDefects(MRI_SURFACE *mris, int mark_ambiguous, int mark_ Segment the connected region of a defect, starting with vno and spreading outwards. ------------------------------------------------------*/ -static int mrisSegmentDefect(MRI_SURFACE *mris, int vno, DEFECT *defect, int mark_ambiguous, int mark_segmented) { +static int mrisSegmentDefect(MRI_SURFACE *mris, int vno, DEFECT *defect, int mark_ambiguous, int mark_segmented) +{ int vlist[MAX_DEFECT_VERTICES], i, j, n, nfilled, nadded, vno1, m; VERTEX *v, *vn, *vadded; float len, nx, ny, nz; @@ -50552,7 +51559,8 @@ static int mrisSegmentDefect(MRI_SURFACE *mris, int vno, DEFECT *defect, int mar //#if FIND_ENCLOSING_LOOP /* segment a surface into connected components using undefval to mark the different components and avoiding old_undefval */ -static int mrisSegmentConnectedComponents(MRIS *mris) { +static int mrisSegmentConnectedComponents(MRIS *mris) +{ int n, p, vno = 0, seed, found; int *vlist, nvertices; int *next_vlist, next_nvertices, total_vertices, maxn, maxv; @@ -50642,7 +51650,8 @@ static int mrisSegmentConnectedComponents(MRIS *mris) { - old_undefval are forbidden points (borders, inside) - undefval are flags for the segmentation into connected components ------------------------------------------------------*/ -static int mrisSimplyConnectedDefect(MRI_SURFACE *mris, DEFECT *defect, int mark_ambiguous, int mark_segmented) { +static int mrisSimplyConnectedDefect(MRI_SURFACE *mris, DEFECT *defect, int mark_ambiguous, int mark_segmented) +{ int n, p, l, label, j, w; int nvertices, nedges, inside_face, outside_face; int add_vertex, add_edges; @@ -50708,7 +51717,8 @@ static int mrisSimplyConnectedDefect(MRI_SURFACE *mris, DEFECT *defect, int mark if (v->undefval != label) { varray[vnb++] = n; v->undefval = 1; - } else { + } + else { v->undefval = 0; } } @@ -50858,7 +51868,8 @@ static int mrisSimplyConnectedDefect(MRI_SURFACE *mris, DEFECT *defect, int mark if (v->undefval == 3) /* good border vertex */ { barray[bnb++] = defect->border[n]; - } else /* becomes inside vertex */ + } + else /* becomes inside vertex */ { varray[vnb++] = defect->border[n]; } @@ -51040,7 +52051,8 @@ int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, int mark_retain, int mark_discard, MHT *mht, - int mode) { + int mode) +{ #if 0 int n, i, j, nfaces, fno, flist[100000], n2, vno, retain; FACE *f ; @@ -51054,7 +52066,8 @@ int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, mrisDefectRemoveDegenerateVertices(mris, MIN_SPHERE_DIST, defect); mrisDefectRemoveProximalVertices(mris, MIN_ORIG_DIST, defect); mrisDefectRemoveNegativeVertices(mris, defect); - } else { + } + else { int i; for (i = 0; i < defect->nvertices; i++) { defect->status[i] = KEEP_VERTEX; @@ -51298,7 +52311,8 @@ static int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, float area_threshold, int mark_retain, int mark_discard, - MHT *mht) { + MHT *mht) +{ #define USING_CUBE 0 #if USING_CUBE || 1 /* based on faces */ @@ -51450,7 +52464,8 @@ static int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, } if (inside) { v->val = -1.0f; - } else { + } + else { v->val = 1.0f; } defect->cx += v->x; @@ -51502,7 +52517,8 @@ static int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, defect->status[n] = KEEP_VERTEX; v->imag_val = -1.0; } - } else { + } + else { if (mrisFindNextOutwardFace(mris, mht, vno, 20.0f) >= 0) { defect->status[n] = DISCARD_VERTEX; v->imag_val = -1.0; @@ -51532,7 +52548,8 @@ static int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, continue; } v = &mris->vertices[defect->vertices[i]]; - } else { + } + else { v = &mris->vertices[defect->border[i - defect->nvertices]]; } for (j = i + 1; j < defect->nvertices; j++) { @@ -51561,7 +52578,8 @@ static int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, continue; } v = &mris->vertices[defect->vertices[i]]; - } else { + } + else { v = &mris->vertices[defect->border[i - defect->nvertices]]; } for (j = i + 1; j < defect->nvertices; j++) { @@ -51593,7 +52611,8 @@ static int mrisMarkRetainedPartOfDefect(MRI_SURFACE *mris, Description Is vno a vertex of face fno? ------------------------------------------------------*/ -static int vertexInFace(MRI_SURFACE *mris, int vno, int fno) { +static int vertexInFace(MRI_SURFACE *mris, int vno, int fno) +{ VERTEX *v; int n; @@ -51605,7 +52624,8 @@ static int vertexInFace(MRI_SURFACE *mris, int vno, int fno) { return (0); } -static int mrisRipDefect(MRI_SURFACE *mris, DEFECT *defect, int ripflag) { +static int mrisRipDefect(MRI_SURFACE *mris, DEFECT *defect, int ripflag) +{ int n; for (n = 0; n < defect->nvertices; n++) { @@ -51623,7 +52643,8 @@ static int mrisRipDefect(MRI_SURFACE *mris, DEFECT *defect, int ripflag) { Description Mark all the vertices in the given defect. ------------------------------------------------------*/ -static int mrisMarkDefect(MRI_SURFACE *mris, DEFECT *defect, int mark) { +static int mrisMarkDefect(MRI_SURFACE *mris, DEFECT *defect, int mark) +{ int n; for (n = 0; n < defect->nvertices; n++) { @@ -51640,7 +52661,8 @@ static int mrisMarkDefect(MRI_SURFACE *mris, DEFECT *defect, int mark) { Description Mark all the border vertices in the given defect. ------------------------------------------------------*/ -static int mrisMarkDefectConvexHull(MRI_SURFACE *mris, DEFECT *defect, int mark) { +static int mrisMarkDefectConvexHull(MRI_SURFACE *mris, DEFECT *defect, int mark) +{ int n; for (n = 0; n < defect->nchull; n++) { @@ -51657,7 +52679,8 @@ static int mrisMarkDefectConvexHull(MRI_SURFACE *mris, DEFECT *defect, int mark) Description Mark all the border vertices in the given defect. ------------------------------------------------------*/ -static int mrisMarkDefectBorder(MRI_SURFACE *mris, DEFECT *defect, int mark) { +static int mrisMarkDefectBorder(MRI_SURFACE *mris, DEFECT *defect, int mark) +{ int n; for (n = 0; n < defect->nborder; n++) { @@ -51715,7 +52738,8 @@ mrisScaleMaxDimension(MRI_SURFACE *mris, float maxr) Description See if any of the vertices in a triangle are marked ------------------------------------------------------*/ -static int triangleMarked(MRI_SURFACE *mris, int fno) { +static int triangleMarked(MRI_SURFACE *mris, int fno) +{ int n; FACE *f; @@ -51762,7 +52786,8 @@ triangleNeighbors(MRI_SURFACE *mris, int fno1, int fno2) ////////////////////////////////////////////////////////////// // Find inside and outside voxels of a surface mris ////////////////////////////////////////////////////////////// -MRI *MRISbinarizeVolume(MRI_SURFACE *mris, MRI_REGION *region, float resolution, float distance_from_surface) { +MRI *MRISbinarizeVolume(MRI_SURFACE *mris, MRI_REGION *region, float resolution, float distance_from_surface) +{ int k, i, j, p, width, height, depth; float x0, x1, x2, y0, y1, y2, z0, z1, z2; float x, y, z; @@ -51945,7 +52970,8 @@ MRI *MRISbinarizeVolume(MRI_SURFACE *mris, MRI_REGION *region, float resolution, valu = 1; sign = val; distance = val; /* n_f is already normalized */ - } else { + } + else { distance = NPY; sign = 0; valu = 0; @@ -51958,12 +52984,14 @@ MRI *MRISbinarizeVolume(MRI_SURFACE *mris, MRI_REGION *region, float resolution, sign = F_DOT(n_v0, vec0); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec0)); - } else if (val < SQR3(e0)) { + } + else if (val < SQR3(e0)) { /* closer to edge0 */ sign = F_DOT(n_e0, vec0); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec0) - SQR(val) / SQR3(e0)))); - } else { + } + else { /* closer to x1 */ sign = F_DOT(n_v1, vec1); valu = 2; @@ -51977,12 +53005,14 @@ MRI *MRISbinarizeVolume(MRI_SURFACE *mris, MRI_REGION *region, float resolution, sign = F_DOT(n_v1, vec1); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec1)); - } else if (val < SQR3(e1)) { + } + else if (val < SQR3(e1)) { /* closer to edge1 */ sign = F_DOT(n_e1, vec1); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec1) - SQR(val) / SQR3(e1)))); - } else { + } + else { /* closer to x2 */ sign = F_DOT(n_v2, vec2); valu = 2; @@ -51996,12 +53026,14 @@ MRI *MRISbinarizeVolume(MRI_SURFACE *mris, MRI_REGION *region, float resolution, sign = F_DOT(n_v2, vec2); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec2)); - } else if (val < SQR3(e2)) { + } + else if (val < SQR3(e2)) { /* closer to edge2 */ sign = F_DOT(n_e2, vec2); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec2) - SQR(val) / SQR3(e2)))); - } else { + } + else { /* closer to x0 */ sign = F_DOT(n_v0, vec0); valu = 2; @@ -52046,7 +53078,8 @@ static int defect_no = 0; static int compare_edge_length(const void *pe1, const void *pe2); static int edgeExists(MRI_SURFACE *mris, int vno1, int vno2); -static int edgeExists(MRI_SURFACE *mris, int vno1, int vno2) { +static int edgeExists(MRI_SURFACE *mris, int vno1, int vno2) +{ int n; VERTEX *v; @@ -52063,7 +53096,8 @@ static int edgeExists(MRI_SURFACE *mris, int vno1, int vno2) { #define V4_LOAD(v, x, y, z, r) (VECTOR_ELT(v, 1) = x, VECTOR_ELT(v, 2) = y, VECTOR_ELT(v, 3) = z, VECTOR_ELT(v, 4) = r); #endif -int mriSurfaceRASToVoxel(double xr, double yr, double zr, double *xv, double *yv, double *zv) { +int mriSurfaceRASToVoxel(double xr, double yr, double zr, double *xv, double *yv, double *zv) +{ VECTOR *sr, *vv; sr = VectorAlloc(4, MATRIX_REAL); @@ -52084,13 +53118,9 @@ int mriSurfaceRASToVoxel(double xr, double yr, double zr, double *xv, double *yv #endif -static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, - MRI *mri, - TP *tp, - HISTOGRAM *h_white, - HISTOGRAM *h_gray, - HISTOGRAM *h_grad, - MRI *mri_gray_white) { +static float mrisDefectFaceMRILogLikelihood( + MRI_SURFACE *mris, MRI *mri, TP *tp, HISTOGRAM *h_white, HISTOGRAM *h_gray, HISTOGRAM *h_grad, MRI *mri_gray_white) +{ int n, vno0, vno1, vno2; double x, y, z, nx, ny, nz, xv, yv, zv, white_val, gray_val, val; double int_w, int_g; @@ -52157,7 +53187,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, int_g /= (double)tp->nfaces; // fs_topo_fixer_test // fprintf(stderr,"face : gray = %f and white = %f\n",int_g,int_w); - } else { + } + else { tp->fll = 0.0; tp->face_ll = 0.0; } @@ -52189,7 +53220,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, */ if (FZERO(alen) && FZERO(clen)) { delta_t0 = 0.99; - } else { + } + else { delta_t0 = (alen > clen) ? (SAMPLE_DIST / alen) : (SAMPLE_DIST / clen); } if (FZERO(delta_t0)) @@ -52215,7 +53247,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, len = sqrt(SQR(dx) + SQR(dy) + SQR(dz)); if (FZERO(len)) { delta_t1 = 0.99; - } else { + } + else { delta_t1 = SAMPLE_DIST / len; /* sample at SAMPLE_DIST intervals */ if (delta_t1 >= 1.0f) { delta_t1 = 0.99; @@ -52249,7 +53282,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, bin = nint((grad - h_grad->bins[0]) / h_grad->bin_size); if (bin < 0) { bin = 0; - } else if (bin >= h_grad->nbins) { + } + else if (bin >= h_grad->nbins) { bin = h_grad->nbins - 1; } ll += log(h_grad->counts[bin]); @@ -52281,7 +53315,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, bin = nint((grad - h_grad->bins[0]) / h_grad->bin_size); if (bin < 0) { bin = 0; - } else if (bin >= h_grad->nbins) { + } + else if (bin >= h_grad->nbins) { bin = h_grad->nbins - 1; } ll += log(h_grad->counts[bin]); @@ -52304,7 +53339,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, len = sqrt(SQR(dx) + SQR(dy) + SQR(dz)); if (FZERO(len)) { delta_t1 = 0.99; - } else { + } + else { delta_t1 = SAMPLE_DIST / len; /* sample at SAMPLE_DIST intervals */ if (delta_t1 >= 1.0f) { delta_t1 = 0.99; @@ -52337,7 +53373,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, bin = nint((grad - h_grad->bins[0]) / h_grad->bin_size); if (bin < 0) { bin = 0; - } else if (bin >= h_grad->nbins) { + } + else if (bin >= h_grad->nbins) { bin = h_grad->nbins - 1; } ll += log(h_grad->counts[bin]); @@ -52369,7 +53406,8 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, bin = nint((grad - h_grad->bins[0]) / h_grad->bin_size); if (bin < 0) { bin = 0; - } else if (bin >= h_grad->nbins) { + } + else if (bin >= h_grad->nbins) { bin = h_grad->nbins - 1; } ll += log(h_grad->counts[bin]); @@ -52385,13 +53423,9 @@ static float mrisDefectFaceMRILogLikelihood(MRI_SURFACE *mris, #endif } -static float mrisDefectVertexMRILogLikelihood(MRI_SURFACE *mris, - MRI *mri, - TP *tp, - HISTOGRAM *h_white, - HISTOGRAM *h_gray, - HISTOGRAM *h_grad, - MRI *mri_gray_white) { +static float mrisDefectVertexMRILogLikelihood( + MRI_SURFACE *mris, MRI *mri, TP *tp, HISTOGRAM *h_white, HISTOGRAM *h_gray, HISTOGRAM *h_grad, MRI *mri_gray_white) +{ int n; double x, y, z, nx, ny, nz, xv, yv, zv, white_val, gray_val, val; double int_w, int_g; @@ -52446,7 +53480,8 @@ static float mrisDefectVertexMRILogLikelihood(MRI_SURFACE *mris, int_g /= (double)tp->nvertices; // fs_topo_fixer_test // fprintf(stderr,"vertex : gray = %f and white = %f\n",int_g,int_w); - } else { + } + else { tp->vll = 0.0; tp->vertex_ll = 0.0; } @@ -52454,13 +53489,9 @@ static float mrisDefectVertexMRILogLikelihood(MRI_SURFACE *mris, return tp->vertex_ll; } -static double mrisComputeDefectMRILogLikelihood(MRI_SURFACE *mris, - MRI *mri, - TP *tp, - HISTOGRAM *h_white, - HISTOGRAM *h_gray, - HISTOGRAM *h_grad, - MRI *mri_gray_white) { +static double mrisComputeDefectMRILogLikelihood( + MRI_SURFACE *mris, MRI *mri, TP *tp, HISTOGRAM *h_white, HISTOGRAM *h_gray, HISTOGRAM *h_grad, MRI *mri_gray_white) +{ double mll; mll = mrisDefectVertexMRILogLikelihood(mris, mri, tp, h_white, h_gray, h_grad, mri_gray_white); @@ -52468,7 +53499,8 @@ static double mrisComputeDefectMRILogLikelihood(MRI_SURFACE *mris, return mll; } -static int findOtherEdgeFace(MRIS *mris, int fno, int vno, int vn1) { +static int findOtherEdgeFace(MRIS *mris, int fno, int vno, int vn1) +{ int n, m; VERTEX *v1, *v2; @@ -52489,7 +53521,8 @@ static int findOtherEdgeFace(MRIS *mris, int fno, int vno, int vn1) { return fno; } -static void vertexPseudoNormal(MRIS *mris1, int vn1, MRIS *mris2, int vn2, float norm[3]) { +static void vertexPseudoNormal(MRIS *mris1, int vn1, MRIS *mris2, int vn2, float norm[3]) +{ int n, n0, n1, n2; float v1[3], v2[3], alpha; VERTEX *v; @@ -52617,7 +53650,8 @@ static void vertexPseudoNormal(MRIS *mris1, int vn1, MRIS *mris2, int vn2, float } } -static void computeVertexPseudoNormal(MRIS *mris, int vno, float norm[3], int verbose) { +static void computeVertexPseudoNormal(MRIS *mris, int vno, float norm[3], int verbose) +{ int n, n0, n1, n2; float v1[3], v2[3], alpha; VERTEX *v; @@ -52680,7 +53714,8 @@ static void computeVertexPseudoNormal(MRIS *mris, int vno, float norm[3], int ve } } -static int findNonMarkedFace(MRIS *mris, int vno, int vn1) { +static int findNonMarkedFace(MRIS *mris, int vno, int vn1) +{ int i, nf; int fn; VERTEX *v; @@ -52717,7 +53752,8 @@ static int _DY[6] = {0, 0, -1, 1, 0, 0}; static int _DZ[6] = {0, 0, 0, 0, -1, 1}; // compute a signed distance volume from two surfaces ( the original ones + a corrected defect ) -void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) { +void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) +{ int k, i, j, p; float x0, x1, x2, y0, y1, y2, z0, z1, z2; float x, y, z; @@ -52796,7 +53832,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) if (mris->faces[fno].marked) { continue; } - } else { + } + else { fno = p; mris = mris_defect; wsurf = 0; // using defect surface @@ -52865,10 +53902,12 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) fn1 = fno; } oface = &mris_defect->faces[fn1]; - } else { + } + else { oface = &mris->faces[fn1]; } - } else { + } + else { // defect surface if (fn1 == fno) { // border face @@ -52879,7 +53918,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) fn1 = fno; // sanity check } oface = &mris_source->faces[fn1]; - } else { + } + else { oface = &mris->faces[fn1]; } } @@ -52905,10 +53945,12 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) fn1 = fno; } oface = &mris_defect->faces[fn1]; - } else { + } + else { oface = &mris->faces[fn1]; } - } else { + } + else { // defect surface if (fn1 == fno) { // border face @@ -52919,7 +53961,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) fn1 = fno; // sanity check } oface = &mris_source->faces[fn1]; - } else { + } + else { oface = &mris->faces[fn1]; } } @@ -52945,10 +53988,12 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) fn1 = fno; } oface = &mris_defect->faces[fn1]; - } else { + } + else { oface = &mris->faces[fn1]; } - } else { + } + else { // defect surface if (fn1 == fno) { // border face @@ -52959,7 +54004,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) fn1 = fno; // sanity check } oface = &mris_source->faces[fn1]; - } else { + } + else { oface = &mris->faces[fn1]; } } @@ -52980,7 +54026,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) // fprintf(stderr,"to0(%d-",vn); // fprintf(stderr,"%d),",vfrom[vn]); vertexPseudoNormal(mris_source, vn, mris_defect, vfrom[vn], n_v0); - } else { + } + else { computeVertexPseudoNormal(mris, vn, n_v0, 0); } vn = face->v[1]; @@ -52993,7 +54040,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) // fprintf(stderr,"to1(%d-",vn); // fprintf(stderr,"%d),",vfrom[vn]); vertexPseudoNormal(mris_source, vn, mris_defect, vfrom[vn], n_v1); - } else { + } + else { computeVertexPseudoNormal(mris, vn, n_v1, 0); } vn = face->v[2]; @@ -53006,10 +54054,12 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) // fprintf(stderr,"to2(%d-",vn); // fprintf(stderr,"%d),",vfrom[vn]); vertexPseudoNormal(mris_source, vn, mris_defect, vfrom[vn], n_v2); - } else { + } + else { computeVertexPseudoNormal(mris, vn, n_v2, 0); } - } else { + } + else { int vn = face->v[0]; // fprintf(stderr,"we have %d and %d \n", mris->vertices[vn].vnum,mris->vertices[vn].num); if (mris->vertices[vn].vnum != mris->vertices[vn].num) { @@ -53021,7 +54071,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) // fprintf(stderr,"fo0(%d-",vn); // fprintf(stderr,"%d),",vto[vn]); vertexPseudoNormal(mris_source, vto[vn], mris_defect, vn, n_v0); - } else { + } + else { computeVertexPseudoNormal(mris, vn, n_v0, 0); } vn = face->v[1]; @@ -53034,7 +54085,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) // fprintf(stderr,"fo1(%d-",vn); // fprintf(stderr,"%d),",vto[vn]); vertexPseudoNormal(mris_source, vto[vn], mris_defect, vn, n_v1); - } else { + } + else { computeVertexPseudoNormal(mris, vn, n_v1, 0); } vn = face->v[2]; @@ -53047,7 +54099,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) // fprintf(stderr,"fo2(%d-",vn); // fprintf(stderr,"%d),",vto[vn]); vertexPseudoNormal(mris_source, vto[vn], mris_defect, vn, n_v2); - } else { + } + else { computeVertexPseudoNormal(mris, vn, n_v2, 0); } } @@ -53102,7 +54155,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) valu = 1; sign = val; distance = val; /* n_f is already normalized */ - } else { + } + else { distance = NPY; sign = 0; valu = 0; @@ -53115,12 +54169,14 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) sign = F_DOT(n_v0, vec0); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec0)); - } else if (val < SQR3(e0)) { + } + else if (val < SQR3(e0)) { /* closer to edge0 */ sign = F_DOT(n_e0, vec0); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec0) - SQR(val) / SQR3(e0)))); - } else { + } + else { /* closer to x1 */ sign = F_DOT(n_v1, vec1); valu = 2; @@ -53134,12 +54190,14 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) sign = F_DOT(n_v1, vec1); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec1)); - } else if (val < SQR3(e1)) { + } + else if (val < SQR3(e1)) { /* closer to edge1 */ sign = F_DOT(n_e1, vec1); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec1) - SQR(val) / SQR3(e1)))); - } else { + } + else { /* closer to x2 */ sign = F_DOT(n_v2, vec2); valu = 2; @@ -53153,12 +54211,14 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) sign = F_DOT(n_v2, vec2); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec2)); - } else if (val < SQR3(e2)) { + } + else if (val < SQR3(e2)) { /* closer to edge2 */ sign = F_DOT(n_e2, vec2); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec2) - SQR(val) / SQR3(e2)))); - } else { + } + else { /* closer to x0 */ sign = F_DOT(n_v0, vec0); valu = 2; @@ -53196,9 +54256,11 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) } if (fabs(distance) * scale > 1.5) { MRIFvox(mri_distance, i, j, k) = NPY; - } else if (distance > 0.0) { + } + else if (distance > 0.0) { MRIFvox(mri_distance, i, j, k) = MIN(distance * scale, 1.0f); - } else { + } + else { MRIFvox(mri_distance, i, j, k) = MAX(distance * scale, -1.0f); } } @@ -53218,7 +54280,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) if (fabs(sign) < NPY) { if (sign > 0) { MRIFvox(mri_distance, i, j, k) = 1.0f; - } else { + } + else { MRIFvox(mri_distance, i, j, k) = -1.0f; } found = 1; @@ -53234,7 +54297,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) sign = MRIFvox(mri_distance, i, j, k); if (sign > 0.0) { MRIFvox(mri_distance, i, j, k) = MIN(1.0f, sign); - } else { + } + else { MRIFvox(mri_distance, i, j, k) = MAX(-1.0f, sign); } } @@ -53242,7 +54306,8 @@ void MRIScomputeDistanceVolume(TOPOFIX_PARMS *parms, float distance_to_surface) #define DEBUG_UL 0 -static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATCH *dp, HISTOGRAM *h_border) { +static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATCH *dp, HISTOGRAM *h_border) +{ #if 0 int u,v,numu,numv; float d0,d1,d2,dmax,px,px0,px1,py,py0,py1,pz,pz0,pz1,nx,ny,nz; @@ -53445,7 +54510,8 @@ static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATC valu = 1; sign = val; distance = val; /* n_f is already normalized */ - } else { + } + else { distance = NPY; sign = 0; valu = 0; @@ -53458,12 +54524,14 @@ static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATC sign = F_DOT(n_v0, vec0); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec0)); - } else if (val < SQR3(e0)) { + } + else if (val < SQR3(e0)) { /* closer to edge0 */ sign = F_DOT(n_e0, vec0); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec0) - SQR(val) / SQR3(e0)))); - } else { + } + else { /* closer to x1 */ sign = F_DOT(n_v1, vec1); valu = 2; @@ -53477,12 +54545,14 @@ static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATC sign = F_DOT(n_v1, vec1); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec1)); - } else if (val < SQR3(e1)) { + } + else if (val < SQR3(e1)) { /* closer to edge1 */ sign = F_DOT(n_e1, vec1); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec1) - SQR(val) / SQR3(e1)))); - } else { + } + else { /* closer to x2 */ sign = F_DOT(n_v2, vec2); valu = 2; @@ -53496,12 +54566,14 @@ static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATC sign = F_DOT(n_v2, vec2); valu = 2; distance = SIGN(sign) * MIN(fabs(distance), NORM3(vec2)); - } else if (val < SQR3(e2)) { + } + else if (val < SQR3(e2)) { /* closer to edge2 */ sign = F_DOT(n_e2, vec2); valu = 3; distance = SIGN(sign) * MIN(fabs(distance), sqrt(MAX(0, SQR3(vec2) - SQR(val) / SQR3(e2)))); - } else { + } + else { /* closer to x0 */ sign = F_DOT(n_v0, vec0); valu = 2; @@ -53598,7 +54670,8 @@ static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATC if (MRIFvox(mri_distance, i, j, k) < 100) { MRIFvox(mri_debug2, i, j, k) = 4; /* outside */ } - } else if (MRIFvox(mri_distance, i, j, k) < 0) { + } + else if (MRIFvox(mri_distance, i, j, k) < 0) { MRIFvox(mri_debug2, i, j, k) = 2; /* inside */ } } @@ -53843,7 +54916,8 @@ static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATC // FLO : max_distance=MIN(2.0f, max_distance) ? if (val == NPY) { val = 1.0f; - } else { + } + else { val = fabs(val) / max_distance; } @@ -53859,7 +54933,8 @@ static double mrisComputeDefectMRILogUnlikelihood(MRI_SURFACE *mris, DEFECT_PATC } static double mrisComputeDefectCurvatureLogLikelihood( - MRI_SURFACE *mris, TP *tp, HISTOGRAM *h_k1, HISTOGRAM *h_k2, MRI *mri_k1_k2) { + MRI_SURFACE *mris, TP *tp, HISTOGRAM *h_k1, HISTOGRAM *h_k2, MRI *mri_k1_k2) +{ double v_ll, total_ll = 0.0, new_total; int i, vno, bin, bink1, bink2; VERTEX *v; @@ -53877,7 +54952,8 @@ static double mrisComputeDefectCurvatureLogLikelihood( bin = nint((v->k1 - h_k1->bins[0]) / h_k1->bin_size); if (bin < 0) { bin = 0; - } else if (bin >= h_k1->nbins) { + } + else if (bin >= h_k1->nbins) { bin = h_k1->nbins - 1; } v_ll = log(h_k1->counts[bin]); @@ -53887,7 +54963,8 @@ static double mrisComputeDefectCurvatureLogLikelihood( bin = nint((v->k2 - h_k2->bins[0]) / h_k2->bin_size); if (bin < 0) { bin = 0; - } else if (bin >= h_k2->nbins) { + } + else if (bin >= h_k2->nbins) { bin = h_k2->nbins - 1; } v_ll += log(h_k2->counts[bin]); @@ -53909,7 +54986,8 @@ static double mrisComputeDefectCurvatureLogLikelihood( if (tp->nvertices) { tp->qcurv_ll = total_ll / (double)tp->nvertices; tp->qcll = tc_area / t_area; - } else { + } + else { tp->qcll = 0.0; tp->qcurv_ll = 0.0; } @@ -53919,7 +54997,8 @@ static double mrisComputeDefectCurvatureLogLikelihood( return tp->qcurv_ll; } -static double mrisComputeDefectNormalDotLogLikelihood(MRI_SURFACE *mris, TP *tp, HISTOGRAM *h_dot) { +static double mrisComputeDefectNormalDotLogLikelihood(MRI_SURFACE *mris, TP *tp, HISTOGRAM *h_dot) +{ double v_ll, total_ll = 0.0, nx, ny, nz, x, y, z, dx, dy, dz, dot; int vno, n, i, bin; VERTEX *v, *vn; @@ -53950,7 +55029,8 @@ static double mrisComputeDefectNormalDotLogLikelihood(MRI_SURFACE *mris, TP *tp, bin = nint((dot - h_dot->bins[0]) / h_dot->bin_size); if (bin < 0) { bin = 0; - } else if (bin >= h_dot->nbins) { + } + else if (bin >= h_dot->nbins) { bin = h_dot->nbins - 1; } @@ -53964,7 +55044,8 @@ static double mrisComputeDefectNormalDotLogLikelihood(MRI_SURFACE *mris, TP *tp, if (tp->nvertices) { tp->cll = tc_area / t_area; tp->curv_ll = total_ll / (double)tp->nvertices; - } else { + } + else { tp->cll = 0.0; tp->curv_ll = 0.0; } @@ -55077,7 +56158,8 @@ mrisComputeDefectMRIEnergy } #endif -static int mrisCheckDefectFaces(MRI_SURFACE *mris, DEFECT_PATCH *dp) { +static int mrisCheckDefectFaces(MRI_SURFACE *mris, DEFECT_PATCH *dp) +{ int fno, n1, n2, vno1, vno2, fshared; VERTEX *v; @@ -55106,7 +56188,8 @@ static double mrisComputeDefectLogLikelihood(MRI_SURFACE *mris, HISTOGRAM *h_grad, MRI *mri_gray_white, HISTOGRAM *h_dot, - TOPOLOGY_PARMS *parms) { + TOPOLOGY_PARMS *parms) +{ static int first_time = 1; double ll = 0.0; @@ -55489,7 +56572,8 @@ static int generateMovie(MRIS *mris_src) static int findNumberOfClusters(MRIS *mris) { return NB_OF_CLUSTERS; } /* using orig vertices to cluster fixedval indexes the clusters */ -static int clusterDefectVertices(MRIS *mris) { +static int clusterDefectVertices(MRIS *mris) +{ int n, niters, nvertices, k; int p, q, nclusters, found; int clusters[10], ngroups; @@ -55602,7 +56686,8 @@ static int clusterDefectVertices(MRIS *mris) { } if (!nbv) { fprintf(stderr, "ERROR in clusterDefectVertices"); - } else { + } + else { x /= nbv; y /= nbv; z /= nbv; @@ -55673,7 +56758,8 @@ static int clusterDefectVertices(MRIS *mris) { return ngroups; } -static void computeInteriorGradients(MRIS *mris, int option) { +static void computeInteriorGradients(MRIS *mris, int option) +{ int n, p, count; float x, y, z; VERTEX *v, *vp; @@ -55712,7 +56798,8 @@ static void computeInteriorGradients(MRIS *mris, int option) { } /* use fixedval to exclude some random vertices */ -static void computeGradients(MRIS *mris, int option) { +static void computeGradients(MRIS *mris, int option) +{ int n; VERTEX *v; @@ -55732,7 +56819,8 @@ static void computeGradients(MRIS *mris, int option) { computeInteriorGradients(mris, option); } -static void circleProjection(float x, float y, float *xd, float *yd, float r) { +static void circleProjection(float x, float y, float *xd, float *yd, float r) +{ float dist; dist = sqrt(SQR(x) + SQR(y)); @@ -55744,7 +56832,8 @@ static void circleProjection(float x, float y, float *xd, float *yd, float r) { } /* generate a place xy mapping */ -static void generateDefectMapping(MRIS *mris, int option) { +static void generateDefectMapping(MRIS *mris, int option) +{ int n, niter = 100; double dt = 0.1; VERTEX *v; @@ -55797,7 +56886,8 @@ static void generateDefectMapping(MRIS *mris, int option) { } } -static OPTIMAL_DEFECT_MAPPING *mrisFindOptimalDefectMapping(MRIS *mris_src, DEFECT *defect) { +static OPTIMAL_DEFECT_MAPPING *mrisFindOptimalDefectMapping(MRIS *mris_src, DEFECT *defect) +{ int nvertices, nfaces, nchull; int *vertex_trans, *face_trans, *vertex_list; int vno, n, m, i, first_inside_vertex, first_border_vertex; @@ -55910,10 +57000,12 @@ static OPTIMAL_DEFECT_MAPPING *mrisFindOptimalDefectMapping(MRIS *mris_src, DEFE if (n < nchull) /* vertex in the convex hull */ { v_dst->flags = VERTEX_CHULL; - } else if (n < defect->nchull) /* vertex in the border */ + } + else if (n < defect->nchull) /* vertex in the border */ { v_dst->flags = VERTEX_BORDER; - } else /* vertex inside the defect */ + } + else /* vertex inside the defect */ { v_dst->flags = VERTEX_INTERIOR; } @@ -55961,7 +57053,8 @@ static OPTIMAL_DEFECT_MAPPING *mrisFindOptimalDefectMapping(MRIS *mris_src, DEFE i++; } } - } else { + } + else { /* neighboring vertices */ v_dst->vnum = v_src->vnum; v_dst->vtotal = v_dst->vnum; @@ -56193,7 +57286,8 @@ static int mrisTessellateDefect(MRI_SURFACE *mris, HISTOGRAM *h_grad, MRI *mri_gray_white, HISTOGRAM *h_dot, - TOPOLOGY_PARMS *parms) { + TOPOLOGY_PARMS *parms) +{ int i, j, vlist[MAX_DEFECT_VERTICES], n, nvertices, nedges, ndiscarded; VERTEX *v, *v2; EDGE *et; @@ -56449,7 +57543,8 @@ static int mrisTessellateDefect(MRI_SURFACE *mris, if (!edgeExists(mris, vlist[i], vlist[j])) { /* prioritize edges in original tessellation */ et[n].len += 100; /*ASCENDING ORDER*/ - } else { + } + else { if (et[n].used == USED_IN_TESSELLATION) { continue; } @@ -56605,7 +57700,8 @@ static int mrisTessellateDefect(MRI_SURFACE *mris, #define NUM_TO_ADD_FROM_ONE_PARENT 1 -static int mrisCrossoverDefectPatches(DEFECT_PATCH *dp1, DEFECT_PATCH *dp2, DEFECT_PATCH *dp_dst, EDGE_TABLE *etable) { +static int mrisCrossoverDefectPatches(DEFECT_PATCH *dp1, DEFECT_PATCH *dp2, DEFECT_PATCH *dp_dst, EDGE_TABLE *etable) +{ int i1, i2, *added, i, isrc, j, nadded; double p; DEFECT_PATCH *dp_src; @@ -56615,7 +57711,8 @@ static int mrisCrossoverDefectPatches(DEFECT_PATCH *dp1, DEFECT_PATCH *dp2, DEFE if (p < 0.5) /* add from first defect */ { dp_src = dp1; - } else { + } + else { dp_src = dp2; } @@ -56627,16 +57724,19 @@ static int mrisCrossoverDefectPatches(DEFECT_PATCH *dp1, DEFECT_PATCH *dp2, DEFE { dp_src = dp2; isrc = i2; - } else if (i1 < dp1->nedges) { + } + else if (i1 < dp1->nedges) { dp_src = dp1; isrc = i1; } - } else /* keep adding from the same parent */ + } + else /* keep adding from the same parent */ { nadded++; if (dp_src == dp1) { isrc = i1; - } else { + } + else { isrc = i2; } } @@ -56665,7 +57765,8 @@ static int mrisCrossoverDefectPatches(DEFECT_PATCH *dp1, DEFECT_PATCH *dp2, DEFE if (dp_src == dp1) /* update source index for next iteration */ { i1 = isrc + 1; - } else { + } + else { i2 = isrc + 1; } @@ -56700,7 +57801,8 @@ static int mrisCrossoverDefectPatches(DEFECT_PATCH *dp1, DEFECT_PATCH *dp2, DEFE } #define NTRY 0 #if 1 -static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pmutation) { +static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pmutation) +{ int i, j, eti, etj, tmp, *dp_indices, ntry; double p; EDGE *e; @@ -56727,7 +57829,8 @@ static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pm e = &etable->edges[dp->ordering[j]]; /*potential new edge */ if (e->used != USED_IN_ORIGINAL_TESSELLATION) { ntry++; - } else { + } + else { break; } j = (int)randomNumber(0.0, dp->nedges - .1); @@ -56735,8 +57838,8 @@ static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pm tmp = dp->ordering[i]; dp->ordering[i] = dp->ordering[j]; dp->ordering[j] = tmp; - - } else /* swap two edges that intersect */ + } + else /* swap two edges that intersect */ { ntry = 0; j = (int)randomNumber(0.0, etable->noverlap[eti] - 0.0001); @@ -56748,7 +57851,8 @@ static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pm e = &etable->edges[dp->ordering[j]]; /*potential new edge */ if (e->used != USED_IN_ORIGINAL_TESSELLATION) { ntry++; - } else { + } + else { break; } j = (int)randomNumber(0.0, etable->noverlap[eti] - 0.0001); @@ -56764,7 +57868,8 @@ static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pm dp_indices[dp->ordering[i]] = i; dp_indices[dp->ordering[j]] = j; } - } else { + } + else { /* swap any two */ ntry = 0; j = (int)randomNumber(0.0, dp->nedges - .1); @@ -56772,7 +57877,8 @@ static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pm e = &etable->edges[dp->ordering[j]]; /*potential new edge */ if (e->used != USED_IN_ORIGINAL_TESSELLATION) { ntry++; - } else { + } + else { break; } j = (int)randomNumber(0.0, dp->nedges - .1); @@ -56788,7 +57894,8 @@ static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pm return (NO_ERROR); } #else -static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pmutation) { +static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pmutation) +{ int i, j, eti, etj, tmp, *dp_indices; double p; @@ -56807,7 +57914,8 @@ static int mrisMutateDefectPatch(DEFECT_PATCH *dp, EDGE_TABLE *etable, double pm tmp = dp->ordering[i]; dp->ordering[i] = dp->ordering[j]; dp->ordering[j] = tmp; - } else /* swap two edges that intersect */ + } + else /* swap two edges that intersect */ { j = (int)randomNumber(0.0, etable->noverlap[eti] - 0.0001); etj = etable->overlapping_edges[eti][j]; /* index of jth @@ -56867,7 +57975,8 @@ mrisDefectPatchFitness } #endif -static int mrisCopyDefectPatch(DEFECT_PATCH *dp_src, DEFECT_PATCH *dp_dst) { +static int mrisCopyDefectPatch(DEFECT_PATCH *dp_src, DEFECT_PATCH *dp_dst) +{ int i; dp_dst->etable = dp_src->etable; @@ -56884,7 +57993,8 @@ static int mrisCopyDefectPatch(DEFECT_PATCH *dp_src, DEFECT_PATCH *dp_dst) { return (NO_ERROR); } -static int defectPatchRank(DEFECT_PATCH *dps, int index, int npatches) { +static int defectPatchRank(DEFECT_PATCH *dps, int index, int npatches) +{ int i, rank = 0; for (i = 0; i < npatches; i++) { @@ -56896,7 +58006,8 @@ static int defectPatchRank(DEFECT_PATCH *dps, int index, int npatches) { if (index > i) { rank++; } - } else if (dps[i].fitness > dps[index].fitness) { + } + else if (dps[i].fitness > dps[index].fitness) { rank++; } } @@ -56914,7 +58025,8 @@ static int tessellatePatch(MRI *mri, int nedges, int *ordering, EDGE_TABLE *etable, - TOPOLOGY_PARMS *parms) { + TOPOLOGY_PARMS *parms) +{ int i, k, vni; DVS *dvs; DP dp; @@ -56929,7 +58041,8 @@ static int tessellatePatch(MRI *mri, if (etable) { new_et = etable; - } else { + } + else { new_et = (EDGE_TABLE *)calloc(1, sizeof(EDGE_TABLE)); new_et->nedges = nedges; new_et->edges = et; @@ -56938,7 +58051,8 @@ static int tessellatePatch(MRI *mri, if (parms->retessellation_mode) { dp.retessellation_mode = USE_SOME_VERTICES; - } else { + } + else { dp.retessellation_mode = USE_ALL_VERTICES; } dp.nedges = nedges; @@ -57005,7 +58119,8 @@ static int tessellatePatch(MRI *mri, #define USE_SCALING 0 -int mrisCountIntersectingFaces(MRIS *mris, int *flist, int nfaces) { +int mrisCountIntersectingFaces(MRIS *mris, int *flist, int nfaces) +{ int n, m, i, count, intersect, j; int vn[3]; int un[3]; @@ -57171,7 +58286,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, HISTOGRAM *h_grad, MRI *mri_gray_white, HISTOGRAM *h_dot, - TOPOLOGY_PARMS *parms) { + TOPOLOGY_PARMS *parms) +{ DEFECT_VERTEX_STATE *dvs; DEFECT_PATCH dps1[MAX_PATCHES], dps2[MAX_PATCHES], *dps, *dp, *dps_next_generation; int i, best_i, j, g, nselected, nreplacements, rank, nunchanged = 0, nelite, ncrossovers, k, l, noverlap; @@ -57231,7 +58347,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, int debug_patch = atoi(getenv("FS_DEBUG_PATCH")); if (debug_patch != dno) { max_patches = 0; - } else { + } + else { if (getenv("FS_DEBUG_PATCH_N") != NULL) { debug_patch_n = atoi(getenv("FS_DEBUG_PATCH_N")); fprintf(WHICH_OUTPUT, "terminating after %dth best tessellation\n", debug_patch_n); @@ -57289,12 +58406,14 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, return (NO_ERROR); #endif - } else if (nedges > 100000) { + } + else if (nedges > 100000) { printf("L defect detected...\n"); max_unchanged = MIN(max_unchanged, 1); max_patches = MAX(MIN(max_patches, 10), 1); max_edges = MIN(max_edges, 100); - } else if (nedges > 50000) { + } + else if (nedges > 50000) { max_patches = MAX(max_patches / 2, 1); max_edges = max_edges / 5; max_unchanged = max_unchanged / 5; @@ -57340,7 +58459,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (noverlap > MAX_EDGES) { etable.noverlap[i] = MAX_EDGES; etable.flags[i] |= ET_OVERLAP_LIST_INCOMPLETE; - } else { + } + else { etable.noverlap[i] = noverlap; } @@ -57354,7 +58474,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, i, etable.noverlap[i]); memmove(etable.overlapping_edges[i], overlap, etable.noverlap[i] * sizeof(int)); - } else { + } + else { nzero++; } } @@ -57422,7 +58543,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (parms->retessellation_mode) { dp->retessellation_mode = USE_SOME_VERTICES; - } else { + } + else { dp->retessellation_mode = USE_ALL_VERTICES; } @@ -57446,7 +58568,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (parms->retessellation_mode) { dp->retessellation_mode = USE_SOME_VERTICES; - } else { + } + else { dp->retessellation_mode = USE_ALL_VERTICES; } @@ -57573,7 +58696,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (segmentation) { SEGMENTATIONfree(&segmentation); } - } else { + } + else { /* generate initial population of patches */ best_fitness = -1000000; best_i = 0; @@ -57582,7 +58706,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (parms->retessellation_mode) { dp->retessellation_mode = USE_SOME_VERTICES; - } else { + } + else { dp->retessellation_mode = USE_ALL_VERTICES; } @@ -57607,7 +58732,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (parms->retessellation_mode) { dp->retessellation_mode = USE_SOME_VERTICES; - } else { + } + else { dp->retessellation_mode = USE_ALL_VERTICES; } @@ -57770,7 +58896,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, fitness_sigma = (fitness_sigma / max_patches - (fitness_mean * fitness_mean)); if (fitness_sigma < 0) { fitness_sigma = 0; - } else { + } + else { fitness_sigma = sqrt(fitness_sigma); } @@ -57810,7 +58937,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (dps == dps1) { dps_next_generation = dps2; - } else { + } + else { dps_next_generation = dps1; } @@ -57920,7 +59048,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, fitness_sigma = (fitness_sigma / max_patches - (fitness_mean * fitness_mean)); if (fitness_sigma < 0) { fitness_sigma = 0; - } else { + } + else { fitness_sigma = sqrt(fitness_sigma); } if (!isfinite(fitness_sigma)) { @@ -57966,7 +59095,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, nadd = nint(pfitness * ncrossovers); if (nadd >= ncrossovers) { nadd = ncrossovers - 1; - } else if (nadd == 0) { + } + else if (nadd == 0) { nadd = 1; } @@ -58092,7 +59222,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, dps = dps_next_generation; goto debug_use_this_patch; } - } else /* mutate it also */ + } + else /* mutate it also */ { mrisMutateDefectPatch(dp, &etable, MUTATION_PCT); fitness = mrisDefectPatchFitness(mris, @@ -58196,7 +59327,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, if (dps == dps1) { dps = dps2; dps_next_generation = dps1; - } else { + } + else { dps = dps1; dps_next_generation = dps2; } @@ -58227,7 +59359,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, fitness_sigma); if (FEQUAL(last_best, best_fitness)) { nunchanged++; - } else { + } + else { last_euthanasia = -1; nunchanged = 0; } @@ -58270,13 +59403,15 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, break; } count++; - } else if (ngenerations >= 10 && (ngenerations % 3 == 0)) { + } + else if (ngenerations >= 10 && (ngenerations % 3 == 0)) { ndeleted = deleteWorstVertices(mris_corrected, &rp, defect, vertex_trans, 0.1, count); nremovedvertices += ndeleted; if (parms->verbose == VERBOSE_MODE_LOW) { if (ndeleted == 1) { fprintf(WHICH_OUTPUT, "Worst vertex has been deleted\n"); - } else if (ndeleted) + } + else if (ndeleted) fprintf(WHICH_OUTPUT, "Worst %d vertices have been deleted (corresponds to ~1%%)\n", ndeleted); } } @@ -58334,7 +59469,8 @@ static int mrisComputeOptimalRetessellation(MRI_SURFACE *mris, } if (defect->status[i] != DISCARD_VERTEX) { mris_corrected->vertices[vni].ripflag = 0; - } else { + } + else { mris_corrected->vertices[vni].ripflag = 1; } } @@ -58509,7 +59645,8 @@ static int mrisComputeRandomRetessellation(MRI_SURFACE *mris, HISTOGRAM *h_grad, MRI *mri_gray_white, HISTOGRAM *h_dot, - TOPOLOGY_PARMS *parms) { + TOPOLOGY_PARMS *parms) +{ DEFECT_VERTEX_STATE *dvs; DEFECT_PATCH dp; int niters, m, tmp, best_i, i, j, k, noverlap; @@ -58599,7 +59736,8 @@ static int mrisComputeRandomRetessellation(MRI_SURFACE *mris, if (noverlap > MAX_EDGES) { etable.noverlap[i] = MAX_EDGES; etable.flags[i] |= ET_OVERLAP_LIST_INCOMPLETE; - } else { + } + else { etable.noverlap[i] = noverlap; } @@ -58664,7 +59802,8 @@ static int mrisComputeRandomRetessellation(MRI_SURFACE *mris, if (parms->retessellation_mode) { dp.retessellation_mode = USE_SOME_VERTICES; - } else { + } + else { dp.retessellation_mode = USE_ALL_VERTICES; } @@ -58724,7 +59863,8 @@ static int mrisComputeRandomRetessellation(MRI_SURFACE *mris, fitness_values[niters] = fitness; if (niters) { best_values[niters] = MAX(best_values[niters - 1], fitness); - } else { + } + else { best_values[niters] = fitness; } #endif @@ -58806,7 +59946,8 @@ static int mrisComputeRandomRetessellation(MRI_SURFACE *mris, } if (defect->status[i] != DISCARD_VERTEX) { mris_corrected->vertices[vni].ripflag = 0; - } else { + } + else { mris_corrected->vertices[vni].ripflag = 1; } } @@ -58938,7 +60079,8 @@ static int mrisRetessellateDefect(MRI_SURFACE *mris, EDGE *et, int nedges, int *ordering, - EDGE_TABLE *etable) { + EDGE_TABLE *etable) +{ double max_len; int i, j, max_i, max_added, nadded, index; int (*intersection_function)(MRI_SURFACE * mris, DEFECT * defect, EDGE * e, int *vertex_trans, int *v1, int *v2); @@ -58950,7 +60092,8 @@ static int mrisRetessellateDefect(MRI_SURFACE *mris, for (index = 0; index < nedges; index++) { if (ordering) { i = ordering[index]; - } else { + } + else { i = index; } @@ -58987,7 +60130,8 @@ static int mrisRetessellateDefect(MRI_SURFACE *mris, } if (etable->flags[i] & ET_OVERLAP_LIST_INCOMPLETE) { intersection_function = intersectDefectEdges; - } else { + } + else { intersection_function = intersectDefectConvexHullEdges; } } @@ -58997,7 +60141,8 @@ static int mrisRetessellateDefect(MRI_SURFACE *mris, if (et[i].used) { et[i].used = USED_IN_BOTH_TESSELLATION; nadded++; - } else { + } + else { et[i].used = USED_IN_NEW_TESSELLATION; nadded++; } @@ -59012,7 +60157,8 @@ static int mrisRetessellateDefect(MRI_SURFACE *mris, return (NO_ERROR); } -static int compare_edge_length(const void *pe0, const void *pe1) { +static int compare_edge_length(const void *pe0, const void *pe1) +{ register EDGE *e0, *e1; e0 = (EDGE *)pe0; @@ -59021,7 +60167,8 @@ static int compare_edge_length(const void *pe0, const void *pe1) { /* return(c1 > c2 ? 1 : c1 == c2 ? 0 : -1) ;*/ if (e0->len > e1->len) { return (1); - } else if (e0->len < e1->len) { + } + else if (e0->len < e1->len) { return (-1); } @@ -59103,7 +60250,8 @@ mrisCheckDefectEdges(MRI_SURFACE *mris, DEFECT *defect, int vno, (e.g. sorting). ------------------------------------------------------*/ #if 1 -static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans, int *v1, int *v2) { +static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans, int *v1, int *v2) +{ VERTEX *v; int i, n, vno; EDGE edge2; @@ -59111,7 +60259,8 @@ static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int for (i = 0; i < defect->nvertices + defect->nchull; i++) { if (i < defect->nvertices) { vno = vertex_trans[defect->vertices[i]]; - } else { + } + else { vno = vertex_trans[defect->chull[i - defect->nvertices]]; } @@ -59155,7 +60304,8 @@ static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int } static int intersectDefectConvexHullEdges( - MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans, int *v1, int *v2) { + MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans, int *v1, int *v2) +{ VERTEX *v; int i, n, vno; EDGE edge2; @@ -59201,7 +60351,8 @@ static int intersectDefectConvexHullEdges( return (0); } #else -static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans) { +static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans) +{ VERTEX *v; int i, n, vno; FILE *fp = NULL; @@ -59214,7 +60365,8 @@ static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int for (i = 0; i < defect->nvertices + defect->nchull; i++) { if (i < defect->nvertices) { vno = vertex_trans[defect->vertices[i]]; - } else { + } + else { vno = vertex_trans[defect->chull[i - defect->nvertices]]; } @@ -59273,7 +60425,8 @@ static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int for (i = 0; i < defect->nvertices + defect->nchull; i++) { if (i < defect->nvertices) { vno = vertex_trans[defect->vertices[i]]; - } else { + } + else { vno = vertex_trans[defect->chull[i - defect->nvertices]]; } @@ -59306,8 +60459,8 @@ static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int fprintf(fp, "%2.3f %2.3f\n%2.3f %2.3f\n\n", x2_start, y2_start, x2_end, y2_end); } } - - } else { + } + else { fp = fopen(fname, "a"); } fprintf(fp, "%2.3f %2.3f\n%2.3f %2.3f\n\n", x1_start, y1_start, x1_end, y1_end); @@ -59324,7 +60477,8 @@ static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int for (i = 0; i < defect->nvertices + defect->nchull; i++) { if (i < defect->nvertices) { vno = vertex_trans[defect->vertices[i]]; - } else { + } + else { vno = vertex_trans[defect->chull[i - defect->nvertices]]; } @@ -59357,8 +60511,8 @@ static int intersectDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int fprintf(fp, "%d %d %2.3f %2.3f %2.3f %2.3f\n", vno, v->v[n], x2_start, y2_start, x2_end, y2_end); } } - - } else { + } + else { fp = fopen(fname, "a"); } fprintf(fp, "%d %d %2.3f %2.3f %2.3f %2.3f\n", e->vno1, e->vno2, x1_start, y1_start, x1_end, y1_end); @@ -59379,7 +60533,8 @@ it's border. Sorry this code is such a hatchet job. I'm sure there are far more elegant ways of doing intersection (e.g. sorting). ------------------------------------------------------*/ -static int intersectDefectConvexHullEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans) { +static int intersectDefectConvexHullEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, int *vertex_trans) +{ VERTEX *v; int i, n, vno; FILE *fp = NULL; @@ -59447,7 +60602,8 @@ static int intersectDefectConvexHullEdges(MRI_SURFACE *mris, DEFECT *defect, EDG for (i = 0; i < defect->nvertices + defect->nchull; i++) { if (i < defect->nvertices) { vno = vertex_trans[defect->vertices[i]]; - } else { + } + else { vno = vertex_trans[defect->chull[i - defect->nvertices]]; } @@ -59480,8 +60636,8 @@ static int intersectDefectConvexHullEdges(MRI_SURFACE *mris, DEFECT *defect, EDG fprintf(fp, "%2.3f %2.3f\n%2.3f %2.3f\n\n", x2_start, y2_start, x2_end, y2_end); } } - - } else { + } + else { fp = fopen(fname, "a"); } fprintf(fp, "%2.3f %2.3f\n%2.3f %2.3f\n\n", x1_start, y1_start, x1_end, y1_end); @@ -59498,7 +60654,8 @@ static int intersectDefectConvexHullEdges(MRI_SURFACE *mris, DEFECT *defect, EDG for (i = 0; i < defect->nvertices + defect->nchull; i++) { if (i < defect->nvertices) { vno = vertex_trans[defect->vertices[i]]; - } else { + } + else { vno = vertex_trans[defect->chull[i - defect->nvertices]]; } @@ -59531,8 +60688,8 @@ static int intersectDefectConvexHullEdges(MRI_SURFACE *mris, DEFECT *defect, EDG fprintf(fp, "%d %d %2.3f %2.3f %2.3f %2.3f\n", vno, v->v[n], x2_start, y2_start, x2_end, y2_end); } } - - } else { + } + else { fp = fopen(fname, "a"); } fprintf(fp, "%d %d %2.3f %2.3f %2.3f %2.3f\n", e->vno1, e->vno2, x1_start, y1_start, x1_end, y1_end); @@ -59689,7 +60846,8 @@ colinearDefectEdges(MRI_SURFACE *mris, DEFECT *defect, EDGE *e, Description Is vno1 is a neighbor of vno2 ------------------------------------------------------*/ -static int vertexNeighbor(MRI_SURFACE *mris, int vno1, int vno2) { +static int vertexNeighbor(MRI_SURFACE *mris, int vno1, int vno2) +{ VERTEX *v; int n; @@ -59709,7 +60867,8 @@ static int vertexNeighbor(MRI_SURFACE *mris, int vno1, int vno2) { Add the edge vnot <--> vno2 to the tessellation ------------------------------------------------------*/ #define MAX_VLIST 255 -static int mrisAddEdge(MRI_SURFACE *mris, int vno1, int vno2) { +static int mrisAddEdge(MRI_SURFACE *mris, int vno1, int vno2) +{ int vlist[MAX_VLIST]; VERTEX *v; @@ -59765,7 +60924,8 @@ static int mrisAddEdge(MRI_SURFACE *mris, int vno1, int vno2) { Description Add the triangle vno0 --> vno1 --> vno2 to the tessellation ------------------------------------------------------*/ -static int mrisAddFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) { +static int mrisAddFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) +{ int n, fno, ilist[1000], n0, n1; FACE *f; VERTEX *v; @@ -59848,7 +61008,8 @@ static int mrisAddFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) { Description Is the triangle vno0-->vno1-->vno2 already in the tessellation ------------------------------------------------------*/ -static int isFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) { +static int isFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) +{ VERTEX *v; FACE *f; int n, n1, vno; @@ -59876,7 +61037,8 @@ static int isFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) { Description Is the triangle vno0-->vno1-->vno2 already in the tessellation ------------------------------------------------------*/ -static int findFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) { +static int findFace(MRI_SURFACE *mris, int vno0, int vno1, int vno2) +{ VERTEX *v; FACE *f; int n, n1, vno, fno; @@ -60083,7 +61245,8 @@ mrisRestoreDefectPositions(MRI_SURFACE *mris, DEFECT *defect, int which) Search the face for vno and set the v->n[] field appropriately. ------------------------------------------------------*/ -static int mrisSetVertexFaceIndex(MRI_SURFACE *mris, int vno, int fno) { +static int mrisSetVertexFaceIndex(MRI_SURFACE *mris, int vno, int fno) +{ VERTEX *v; FACE *f; int n, i; @@ -60186,7 +61349,8 @@ mrisAddDefectFaces(MRI_SURFACE *mris, double e0[3], double e1[3], Description Add the appropriate face to the tessellation. ------------------------------------------------------*/ -static int mrisAddAllDefectFaces(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vertex_trans) { +static int mrisAddAllDefectFaces(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vertex_trans) +{ DEFECT *defect; int i, vno1, vno2, nfaces, n, m, dno; VERTEX *v; @@ -60203,7 +61367,8 @@ static int mrisAddAllDefectFaces(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vertex continue; } vno1 = vertex_trans[defect->vertices[i]]; - } else { + } + else { vno1 = vertex_trans[defect->border[i - defect->nvertices]]; } if (vno1 < 0) { @@ -60258,7 +61423,8 @@ static int mrisAddAllDefectFaces(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vertex If so, it should not be added to the tessellation. ------------------------------------------------------*/ #if SPHERE_INTERSECTION -static int containsAnotherVertexOnSphere(MRI_SURFACE *mris, int vno0, int vno1, int vno2, int mode) { +static int containsAnotherVertexOnSphere(MRI_SURFACE *mris, int vno0, int vno1, int vno2, int mode) +{ VERTEX *V0, *V1, *V2, *v, *vn; int i, n, nvertices, vertices[1000], v1, v2; double sign[3], normal[3][3], orgn[3][3], tangent[3], test; @@ -60501,7 +61667,8 @@ static int containsAnotherVertex( { break; } - } else { + } + else { m = (y1 - y0) / (x1 - x0); b = y1 - m * x1; if ((y2 - (m * x2 + b)) * (yn - (m * xn + b)) < 0) { @@ -60630,33 +61797,38 @@ static int containsAnotherVertex( #endif #endif -static int computeOrientation(MRIS *mris, int f, int v0, int v1) { +static int computeOrientation(MRIS *mris, int f, int v0, int v1) +{ FACE *face; face = &mris->faces[f]; if (face->v[0] == v0) { if (face->v[1] == v1) { return 1; - } else { + } + else { return -1; } }; if (face->v[1] == v0) { if (face->v[2] == v1) { return 1; - } else { + } + else { return -1; } }; if (face->v[0] == v1) { return 1; - } else { + } + else { return -1; } } /* extract the non-marked vertices from a surface */ -MRIS *MRISextractMarkedVertices(MRIS *mris) { +MRIS *MRISextractMarkedVertices(MRIS *mris) +{ MRIS *mris_corrected; int *face_trans, *vertex_trans; VERTEX *v, *vdst; @@ -60780,7 +61952,8 @@ MRIS *MRISextractMarkedVertices(MRIS *mris) { /* extract the main connected component from a triangulation use the v->marked to extract the surface */ -MRIS *MRISextractMainComponent(MRI_SURFACE *mris, int do_not_extract, int verbose, int *ncpts) { +MRIS *MRISextractMainComponent(MRI_SURFACE *mris, int do_not_extract, int verbose, int *ncpts) +{ MRIS *mris_out; VERTEX *v, *vp1, *vp2; int n, vn0, vn1, vn2, p, count, max_c, max_nbr, found, ncpt; @@ -60884,7 +62057,8 @@ MRIS *MRISextractMainComponent(MRI_SURFACE *mris, int do_not_extract, int verbos if (!do_not_extract && verbose) { fprintf(WHICH_OUTPUT, "\nnothing to do"); } - } else { + } + else { if (verbose) { fprintf(WHICH_OUTPUT, "\n%d components have been found", count); } @@ -60905,7 +62079,8 @@ MRIS *MRISextractMainComponent(MRI_SURFACE *mris, int do_not_extract, int verbos v = &mris->vertices[n]; if (v->marked == max_c) { v->marked = 0; - } else { + } + else { v->marked = 1; } } @@ -60919,7 +62094,8 @@ MRIS *MRISextractMainComponent(MRI_SURFACE *mris, int do_not_extract, int verbos constituting the tessellation. Writes the orientation changes in curv. Note that this function can easily be modified to check the orientation changes for any tessellations (not only triangulations) */ -int MRISmarkOrientationChanges(MRI_SURFACE *mris) { +int MRISmarkOrientationChanges(MRI_SURFACE *mris) +{ VERTEX *v; int face1, face2, vn0, p, vn1, vn2, d1, d2, count; #if 0 @@ -60967,7 +62143,8 @@ int MRISmarkOrientationChanges(MRI_SURFACE *mris) { nfaces++; if (nfaces == 1) { face1 = findFace(mris, vn0, vn1, vn2); - } else { + } + else { face2 = findFace(mris, vn0, vn1, vn2); } } @@ -61182,7 +62359,8 @@ int MRISmarkOrientationChanges(MRI_SURFACE *mris) { surface). ------------------------------------------------------*/ #if 1 -static int mrisOrientRetessellatedSurface(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vtrans) { +static int mrisOrientRetessellatedSurface(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vtrans) +{ int vno, n, fno, m, vno0, vno1; /*n0, n1;*/ VERTEX *v, *v1, *v2, *v3; FACE *f; @@ -61298,7 +62476,8 @@ static int mrisOrientRetessellatedSurface(MRI_SURFACE *mris, DEFECT_LIST *dl, in return (NO_ERROR); } #else -static int mrisOrientRetessellatedSurface(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vtrans) { +static int mrisOrientRetessellatedSurface(MRI_SURFACE *mris, DEFECT_LIST *dl, int *vtrans) +{ #if 1 int dno, fno, vno, i, n, m, vno0, vno1, n0, n1, oriented, nreversed; VERTEX *v, *vn; @@ -61829,7 +63008,8 @@ mrisComputeCanonicalBasis(MRI_SURFACE *mris, int fno, double origin[3], ------------------------------------------------------*/ #if (!SPHERE_INTERSECTION) static int mrisComputeCanonicalEdgeBasis( - MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2, double origin[3], double e0[3], double e1[3]) { + MRI_SURFACE *mris, EDGE *edge1, EDGE *edge2, double origin[3], double e0[3], double e1[3]) +{ VERTEX *v0, *v1, *v2, *v3; double len, normal[3]; float fx, fy, fz; @@ -61877,7 +63057,8 @@ static int mrisComputeCanonicalEdgeBasis( find the convex hull of the defect on the sphere (actually, just a disk, but at least it's convex....) ------------------------------------------------------*/ -static int mrisFindDefectConvexHull(MRI_SURFACE *mris, DEFECT *defect) { +static int mrisFindDefectConvexHull(MRI_SURFACE *mris, DEFECT *defect) +{ #if SMALL_CONVEX_HULL VERTEX *v, *vn; int chull[MAX_DEFECT_VERTICES], nfound, n, i, vno; @@ -61928,7 +63109,8 @@ static int mrisFindDefectConvexHull(MRI_SURFACE *mris, DEFECT *defect) { if (defect->status[i] == DISCARD_VERTEX) { continue; } - } else { + } + else { vno = defect->border[i - defect->nvertices]; } v = &mris->vertices[vno]; @@ -61998,7 +63180,8 @@ static int mrisFindDefectConvexHull(MRI_SURFACE *mris, DEFECT *defect) { Description ------------------------------------------------------*/ -static int mrisCheckSurface(MRI_SURFACE *mris) { +static int mrisCheckSurface(MRI_SURFACE *mris) +{ int vno, n, nfaces, m, vno2, nbad, flist[100]; VERTEX *v; @@ -62055,7 +63238,8 @@ static int mrisCheckSurface(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -static int mrisMarkBadEdgeVertices(MRI_SURFACE *mris, int mark) { +static int mrisMarkBadEdgeVertices(MRI_SURFACE *mris, int mark) +{ int vno, n, nfaces, m, vno2, nmarked; VERTEX *v; @@ -62097,7 +63281,8 @@ static int mrisMarkBadEdgeVertices(MRI_SURFACE *mris, int mark) { Description ------------------------------------------------------*/ -int MRISdilateMarked(MRI_SURFACE *mris, int ndil) { +int MRISdilateMarked(MRI_SURFACE *mris, int ndil) +{ int vno, i, n, mx; VERTEX *v, *vn; @@ -62139,7 +63324,8 @@ int MRISdilateMarked(MRI_SURFACE *mris, int ndil) { Description ------------------------------------------------------*/ -int MRISdilateRipped(MRI_SURFACE *mris, int ndil) { +int MRISdilateRipped(MRI_SURFACE *mris, int ndil) +{ int vno, i, n; VERTEX *v, *vn; @@ -62177,7 +63363,8 @@ int MRISdilateRipped(MRI_SURFACE *mris, int ndil) { annotation. If newid >= 0, then the surface annot field of vertices in the dilated mask is set to the annot corresponding to newid. -------------------------------------------------------------------*/ -MRI *MRISdilateConfined(MRIS *surf, MRI *mask, int annotidmask, int niters, int newid) { +MRI *MRISdilateConfined(MRIS *surf, MRI *mask, int annotidmask, int niters, int newid) +{ int vtxno, annot, annotid, nnbrs, nbrvtxno, nthnbr, nthiter, new_annot; VERTEX *vtx; MRI *mri1, *mri2; @@ -62246,7 +63433,8 @@ MRI *MRISdilateConfined(MRIS *surf, MRI *mask, int annotidmask, int niters, int MRI *MRISfbirnMask_SFG_Cing(MRIS *surf) - creates a mask in the SFG where it borders CAcing, PAcing, and RAcing. -------------------------------------------------------------*/ -MRI *MRISfbirnMask_SFG_Cing(MRIS *surf) { +MRI *MRISfbirnMask_SFG_Cing(MRIS *surf) +{ int vtxno, annot, annotid, nnbrs, nbrvtx, nthnbr, nbrannotid; VERTEX *vtx; int superiorfrontal, posteriorcingulate; @@ -62294,7 +63482,8 @@ MRI *MRISfbirnMask_SFG_Cing(MRIS *surf) { MRI *MRISfbirnMask_MOF_RACing(MRIS *surf) - creates a mask at the intersection Meidal Orbital Frontal and RA Cingulate -------------------------------------------------------------*/ -MRI *MRISfbirnMask_MOF_RACing(MRIS *surf) { +MRI *MRISfbirnMask_MOF_RACing(MRIS *surf) +{ int vtxno, annot, annotid, nnbrs, nbrvtx, nthnbr, nbrannotid; VERTEX *vtx; int medialorbitofrontal, rostralanteriorcingulate; @@ -62341,7 +63530,8 @@ MRI *MRISfbirnMask_MOF_RACing(MRIS *surf) { Returns value: Description ------------------------------------------------------*/ -int MRISerodeRipped(MRI_SURFACE *mris, int ndil) { +int MRISerodeRipped(MRI_SURFACE *mris, int ndil) +{ int vno, i, n, mn; VERTEX *v, *vn; @@ -62375,7 +63565,8 @@ int MRISerodeRipped(MRI_SURFACE *mris, int ndil) { Description ------------------------------------------------------*/ -int MRISerodeMarked(MRI_SURFACE *mris, int num) { +int MRISerodeMarked(MRI_SURFACE *mris, int num) +{ int vno, i, n, mn; VERTEX *v, *vn; @@ -62417,7 +63608,8 @@ int MRISerodeMarked(MRI_SURFACE *mris, int num) { Description ------------------------------------------------------*/ -int MRIScloseMarked(MRI_SURFACE *mris, int order) { +int MRIScloseMarked(MRI_SURFACE *mris, int order) +{ MRISdilateMarked(mris, order); MRISerodeMarked(mris, order); return (NO_ERROR); @@ -62429,7 +63621,8 @@ int MRIScloseMarked(MRI_SURFACE *mris, int order) { Description ------------------------------------------------------*/ -int MRISopenMarked(MRI_SURFACE *mris, int order) { +int MRISopenMarked(MRI_SURFACE *mris, int order) +{ MRISerodeMarked(mris, order); MRISdilateMarked(mris, order); return (NO_ERROR); @@ -62441,7 +63634,8 @@ int MRISopenMarked(MRI_SURFACE *mris, int order) { Description ------------------------------------------------------*/ -static int mrisDumpDefectiveEdge(MRI_SURFACE *mris, int vno1, int vno2) { +static int mrisDumpDefectiveEdge(MRI_SURFACE *mris, int vno1, int vno2) +{ #if 0 FILE *fp ; char fname[STRLEN] ; @@ -62567,7 +63761,8 @@ mrisDumpTriangle(MRI_SURFACE *mris, int fno) return(NO_ERROR) ; } #endif -static int mrisDefectRemoveNegativeVertices(MRI_SURFACE *mris, DEFECT *defect) { +static int mrisDefectRemoveNegativeVertices(MRI_SURFACE *mris, DEFECT *defect) +{ int i, n; VERTEX *v; @@ -62590,7 +63785,8 @@ static int mrisDefectRemoveNegativeVertices(MRI_SURFACE *mris, DEFECT *defect) { Description ------------------------------------------------------*/ -static int mrisDefectRemoveDegenerateVertices(MRI_SURFACE *mris, float min_sphere_dist, DEFECT *defect) { +static int mrisDefectRemoveDegenerateVertices(MRI_SURFACE *mris, float min_sphere_dist, DEFECT *defect) +{ float dx, dy, dz, dist; int i, j; VERTEX *v, *vn; @@ -62605,7 +63801,8 @@ static int mrisDefectRemoveDegenerateVertices(MRI_SURFACE *mris, float min_spher if (defect->vertices[i] == Gdiag_no) { DiagBreak(); } - } else { + } + else { v = &mris->vertices[defect->border[i - defect->nvertices]]; if (defect->border[i - defect->nvertices] == Gdiag_no) { DiagBreak(); @@ -62636,7 +63833,8 @@ static int mrisDefectRemoveDegenerateVertices(MRI_SURFACE *mris, float min_spher Description ------------------------------------------------------*/ -static int mrisDefectRemoveProximalVertices(MRI_SURFACE *mris, float min_orig_dist, DEFECT *defect) { +static int mrisDefectRemoveProximalVertices(MRI_SURFACE *mris, float min_orig_dist, DEFECT *defect) +{ float dx, dy, dz, dist; int i, j; VERTEX *v, *vn; @@ -62651,7 +63849,8 @@ static int mrisDefectRemoveProximalVertices(MRI_SURFACE *mris, float min_orig_di if (defect->vertices[i] == Gdiag_no) { DiagBreak(); } - } else { + } + else { v = &mris->vertices[defect->border[i - defect->nvertices]]; if (defect->border[i - defect->nvertices] == Gdiag_no) { DiagBreak(); @@ -62678,7 +63877,8 @@ static int mrisDefectRemoveProximalVertices(MRI_SURFACE *mris, float min_orig_di } /*----------------------------------------------------- ------------------------------------------------------*/ -static int mrisInitializeNeighborhood(MRI_SURFACE *mris, int vno) { +static int mrisInitializeNeighborhood(MRI_SURFACE *mris, int vno) +{ VERTEX *v, *vnb, *vnb2; int vtmp[MAX_NEIGHBORS], vnum, i, j, n, neighbors, nsize; @@ -62795,7 +63995,8 @@ static int mrisInitializeNeighborhood(MRI_SURFACE *mris, int vno) { Description ------------------------------------------------------*/ -int MRISmarkNegativeVertices(MRI_SURFACE *mris, int mark) { +int MRISmarkNegativeVertices(MRI_SURFACE *mris, int mark) +{ int fno, n; FACE *f; @@ -62815,7 +64016,8 @@ int MRISmarkNegativeVertices(MRI_SURFACE *mris, int mark) { Description ------------------------------------------------------*/ -int MRISripNegativeVertices(MRI_SURFACE *mris) { +int MRISripNegativeVertices(MRI_SURFACE *mris) +{ int fno, n; FACE *f; @@ -62837,7 +64039,8 @@ int MRISripNegativeVertices(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -double MRIScomputeAverageCurvature(MRI_SURFACE *mris, double *psigma) { +double MRIScomputeAverageCurvature(MRI_SURFACE *mris, double *psigma) +{ double mean, var, total, total_sq, nv, d; int vno; VERTEX *v; @@ -62855,7 +64058,8 @@ double MRIScomputeAverageCurvature(MRI_SURFACE *mris, double *psigma) { if (nv) { mean = total / nv; var = total_sq / nv - (mean * mean); - } else { + } + else { var = mean = 0.0; } if (psigma) { @@ -62870,7 +64074,8 @@ double MRIScomputeAverageCurvature(MRI_SURFACE *mris, double *psigma) { Description ------------------------------------------------------*/ -int MRIScopyValToVal2(MRI_SURFACE *mris) { +int MRIScopyValToVal2(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -62891,7 +64096,8 @@ int MRIScopyValToVal2(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyValuesToVal2Bak(MRI_SURFACE *mris) { +int MRIScopyValuesToVal2Bak(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -62912,7 +64118,8 @@ int MRIScopyValuesToVal2Bak(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyValToValBak(MRI_SURFACE *mris) { +int MRIScopyValToValBak(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -62933,7 +64140,8 @@ int MRIScopyValToValBak(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRIScopyValToVal2Bak(MRI_SURFACE *mris) { +int MRIScopyValToVal2Bak(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -62955,7 +64163,8 @@ Returns value: Description ------------------------------------------------------*/ -int MRISsqrtVal(MRI_SURFACE *mris) { +int MRISsqrtVal(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -62979,7 +64188,8 @@ Returns value: Description ------------------------------------------------------*/ -int MRISmulVal(MRI_SURFACE *mris, float mul) { +int MRISmulVal(MRI_SURFACE *mris, float mul) +{ int vno, nvertices; VERTEX *v; @@ -62994,7 +64204,8 @@ int MRISmulVal(MRI_SURFACE *mris, float mul) { return (NO_ERROR); } -SMALL_SURFACE *MRISreadVerticesOnly(char *fname) { +SMALL_SURFACE *MRISreadVerticesOnly(char *fname) +{ SMALL_SURFACE *mriss = NULL; int type, magic, version, ix, iy, iz, nquads, nvertices, vno; SMALL_VERTEX *vertex; @@ -63020,16 +64231,19 @@ SMALL_SURFACE *MRISreadVerticesOnly(char *fname) { if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { fprintf(stdout, "new surface file format\n"); } - } else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { + } + else if (magic == NEW_QUAD_FILE_MAGIC_NUMBER) { version = -2; - } else if (magic == TRIANGLE_FILE_MAGIC_NUMBER) { + } + else if (magic == TRIANGLE_FILE_MAGIC_NUMBER) { fclose(fp); mriss = mrisReadTriangleFileVertexPositionsOnly(fname); if (!mriss) { ErrorReturn(NULL, (Gerror, "mrisReadTriangleFile failed.\n")); } version = -3; - } else { + } + else { rewind(fp); version = 0; if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) { @@ -63062,7 +64276,8 @@ SMALL_SURFACE *MRISreadVerticesOnly(char *fname) { vertex->x = ix / 100.0; vertex->y = iy / 100.0; vertex->z = iz / 100.0; - } else /* version == -2 */ + } + else /* version == -2 */ { vertex->x = freadFloat(fp); vertex->y = freadFloat(fp); @@ -63073,7 +64288,8 @@ SMALL_SURFACE *MRISreadVerticesOnly(char *fname) { return (mriss); } -int MRISSfree(SMALL_SURFACE **pmriss) { +int MRISSfree(SMALL_SURFACE **pmriss) +{ SMALL_SURFACE *mriss; mriss = *pmriss; @@ -63082,7 +64298,8 @@ int MRISSfree(SMALL_SURFACE **pmriss) { free(mriss); return (NO_ERROR); } -int MRISextractCurvatureVector(MRI_SURFACE *mris, float *curvs) { +int MRISextractCurvatureVector(MRI_SURFACE *mris, float *curvs) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63091,7 +64308,8 @@ int MRISextractCurvatureVector(MRI_SURFACE *mris, float *curvs) { return (NO_ERROR); } -int MRISextractCurvatureVectorDouble(MRI_SURFACE *mris, double *curvs, int offset) { +int MRISextractCurvatureVectorDouble(MRI_SURFACE *mris, double *curvs, int offset) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63100,7 +64318,8 @@ int MRISextractCurvatureVectorDouble(MRI_SURFACE *mris, double *curvs, int offse return (NO_ERROR); } -int MRISextractCurvatureDoubleVector(MRI_SURFACE *mris, double *curvs) { +int MRISextractCurvatureDoubleVector(MRI_SURFACE *mris, double *curvs) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63109,7 +64328,8 @@ int MRISextractCurvatureDoubleVector(MRI_SURFACE *mris, double *curvs) { return (NO_ERROR); } -int MRISimportCurvatureVector(MRI_SURFACE *mris, float *curvs) { +int MRISimportCurvatureVector(MRI_SURFACE *mris, float *curvs) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63119,7 +64339,8 @@ int MRISimportCurvatureVector(MRI_SURFACE *mris, float *curvs) { return (NO_ERROR); } -int MRISimportValVector(MRI_SURFACE *mris, float *vals) { +int MRISimportValVector(MRI_SURFACE *mris, float *vals) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63128,7 +64349,8 @@ int MRISimportValVector(MRI_SURFACE *mris, float *vals) { return (NO_ERROR); } -int MRISimportValFromMatrixColumn(MRI_SURFACE *mris, MATRIX *m, int col) { +int MRISimportValFromMatrixColumn(MRI_SURFACE *mris, MATRIX *m, int col) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63137,7 +64359,8 @@ int MRISimportValFromMatrixColumn(MRI_SURFACE *mris, MATRIX *m, int col) { return (NO_ERROR); } -int MRISexportValVector(MRI_SURFACE *mris, float *vals) { +int MRISexportValVector(MRI_SURFACE *mris, float *vals) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63146,7 +64369,8 @@ int MRISexportValVector(MRI_SURFACE *mris, float *vals) { return (NO_ERROR); } -int MRISexportValVectorDouble(MRI_SURFACE *mris, double *vals, int offset) { +int MRISexportValVectorDouble(MRI_SURFACE *mris, double *vals, int offset) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -63155,7 +64379,8 @@ int MRISexportValVectorDouble(MRI_SURFACE *mris, double *vals, int offset) { return (NO_ERROR); } -int MRISmaskLabel(MRI_SURFACE *mris, LABEL *area) { +int MRISmaskLabel(MRI_SURFACE *mris, LABEL *area) +{ int i; VERTEX *v; @@ -63165,7 +64390,8 @@ int MRISmaskLabel(MRI_SURFACE *mris, LABEL *area) { } return (NO_ERROR); } -int MRISmaskNotLabel(MRI_SURFACE *mris, LABEL *area) { +int MRISmaskNotLabel(MRI_SURFACE *mris, LABEL *area) +{ int i, vno; VERTEX *v; @@ -63186,7 +64412,8 @@ int MRISmaskNotLabel(MRI_SURFACE *mris, LABEL *area) { } return (NO_ERROR); } -int MRISripLabel(MRI_SURFACE *mris, LABEL *area) { +int MRISripLabel(MRI_SURFACE *mris, LABEL *area) +{ int i; VERTEX *v; @@ -63196,7 +64423,8 @@ int MRISripLabel(MRI_SURFACE *mris, LABEL *area) { } return (NO_ERROR); } -int MRISripNotLabel(MRI_SURFACE *mris, LABEL *area) { +int MRISripNotLabel(MRI_SURFACE *mris, LABEL *area) +{ int i, vno; VERTEX *v; @@ -63217,7 +64445,8 @@ int MRISripNotLabel(MRI_SURFACE *mris, LABEL *area) { } return (NO_ERROR); } -int MRISinvertMarks(MRI_SURFACE *mris) { +int MRISinvertMarks(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63231,7 +64460,8 @@ int MRISinvertMarks(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISsegmentMarked(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels, float min_label_area) { +int MRISsegmentMarked(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels, float min_label_area) +{ int vno, nfound, n, nlabels, *marks; VERTEX *v; LABEL *area = NULL, **tmp, **label_array; @@ -63277,7 +64507,8 @@ int MRISsegmentMarked(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels, f } LabelFree(&area); nfound = 1; - } else { + } + else { nfound = 0; } @@ -63304,7 +64535,8 @@ int MRISsegmentMarked(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels, f return (NO_ERROR); } -int MRISsegmentAnnotated(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels, float min_label_area) { +int MRISsegmentAnnotated(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels, float min_label_area) +{ int vno, nfound, n, nlabels, last_vno; VERTEX *v; LABEL *area = NULL, **tmp, **label_array; @@ -63344,7 +64576,8 @@ int MRISsegmentAnnotated(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels LabelFree(&area); nfound = 1; last_vno = vno; - } else { + } + else { nfound = 0; } @@ -63363,7 +64596,8 @@ int MRISsegmentAnnotated(MRI_SURFACE *mris, LABEL ***plabel_array, int *pnlabels return (NO_ERROR); } -int MRISsubsampleDist(MRI_SURFACE *mris, float spacing) { +int MRISsubsampleDist(MRI_SURFACE *mris, float spacing) +{ int k, m, n, sub_num; VERTEX *v; @@ -63428,7 +64662,8 @@ int MRISsubsampleDist(MRI_SURFACE *mris, float spacing) { return (sub_num); } -int MRISwriteDecimation(MRI_SURFACE *mris, char *fname) { +int MRISwriteDecimation(MRI_SURFACE *mris, char *fname) +{ int k; FILE *fptr; @@ -63439,14 +64674,16 @@ int MRISwriteDecimation(MRI_SURFACE *mris, char *fname) { for (k = 0; k < mris->nvertices; k++) { if (mris->vertices[k].d == 0) { fputc('\1', fptr); - } else { + } + else { fputc('\0', fptr); } } fclose(fptr); return (NO_ERROR); } -int MRISreadDecimation(MRI_SURFACE *mris, char *fname) { +int MRISreadDecimation(MRI_SURFACE *mris, char *fname) +{ int k, d, ndec; char c; FILE *fptr; @@ -63473,7 +64710,8 @@ int MRISreadDecimation(MRI_SURFACE *mris, char *fname) { ndec++; } } - } else { + } + else { d = freadInt(fptr); if (d != mris->nvertices) ErrorReturn(0, (ERROR_BADFILE, "%s: decimation file %s has wrong # of vertices\n", Progname, fname, d)); @@ -63491,7 +64729,8 @@ int MRISreadDecimation(MRI_SURFACE *mris, char *fname) { return (ndec); } -int MRIScombine(MRI_SURFACE *mris_src, MRI_SURFACE *mris_total, MRIS_HASH_TABLE *mht, int which) { +int MRIScombine(MRI_SURFACE *mris_src, MRI_SURFACE *mris_total, MRIS_HASH_TABLE *mht, int which) +{ int vno; VERTEX *v, *vdst; MHT *mht_src = NULL; @@ -63633,7 +64872,8 @@ int MRIScombine(MRI_SURFACE *mris_src, MRI_SURFACE *mris_total, MRIS_HASH_TABLE } #if 1 -int MRISsphericalCopy(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRIS_HASH_TABLE *mht, int which) { +int MRISsphericalCopy(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRIS_HASH_TABLE *mht, int which) +{ int vno; VERTEX *v, *vdst; MHT *mht_src = NULL; @@ -63696,7 +64936,8 @@ int MRISsphericalCopy(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRIS_HASH_TA return (NO_ERROR); } #else -int MRISsphericalCopy(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRIS_HASH_TABLE *mht, int which) { +int MRISsphericalCopy(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRIS_HASH_TABLE *mht, int which) +{ int vno; VERTEX *v, *vdst; MHT *mht_src = NULL; @@ -63866,7 +65107,8 @@ int MRISsphericalCopy(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRIS_HASH_TA } #endif -int MRISorigAreaToCurv(MRI_SURFACE *mris) { +int MRISorigAreaToCurv(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63880,7 +65122,8 @@ int MRISorigAreaToCurv(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISareaToCurv(MRI_SURFACE *mris) { +int MRISareaToCurv(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63894,7 +65137,8 @@ int MRISareaToCurv(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISmarkedToCurv(MRI_SURFACE *mris) { +int MRISmarkedToCurv(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63908,7 +65152,8 @@ int MRISmarkedToCurv(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScurvToMarked(MRI_SURFACE *mris) { +int MRIScurvToMarked(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63922,7 +65167,8 @@ int MRIScurvToMarked(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISdToCurv(MRI_SURFACE *mris) { +int MRISdToCurv(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63936,7 +65182,8 @@ int MRISdToCurv(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScurvToD(MRI_SURFACE *mris) { +int MRIScurvToD(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63950,7 +65197,8 @@ int MRIScurvToD(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISclearOrigArea(MRI_SURFACE *mris) { +int MRISclearOrigArea(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -63964,7 +65212,8 @@ int MRISclearOrigArea(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISclearOrigDistances(MRI_SURFACE *mris) { +int MRISclearOrigDistances(MRI_SURFACE *mris) +{ int vno, n; VERTEX *v; @@ -63980,7 +65229,8 @@ int MRISclearOrigDistances(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISclear(MRI_SURFACE *mris, int which) { +int MRISclear(MRI_SURFACE *mris, int which) +{ int vno; VERTEX *v; @@ -64005,7 +65255,8 @@ int MRISclear(MRI_SURFACE *mris, int which) { } return (NO_ERROR); } -int MRISnormalize(MRI_SURFACE *mris, int dof, int which) { +int MRISnormalize(MRI_SURFACE *mris, int dof, int which) +{ int vno; VERTEX *v; float fdof = (float)dof, mean; @@ -64047,7 +65298,8 @@ static int mrisComputeGrayWhiteBorderDistributions(MRI_SURFACE *mris, HISTOGRAM *h_white, HISTOGRAM *h_gray, HISTOGRAM *h_border, - HISTOGRAM *h_grad) { + HISTOGRAM *h_grad) +{ int vno, n2, n, i, nvertices, bin; VERTEX *v, *vn, *vn2; HISTOGRAM *h_white_raw, *h_gray_raw, *h_border_raw, *h_grad_raw; @@ -64199,7 +65451,8 @@ static int mrisComputeGrayWhiteBorderDistributions(MRI_SURFACE *mris, return (NO_ERROR); } -static int mrisComputeJointGrayWhiteBorderDistributions(MRI_SURFACE *mris, MRI *mri, MRI *mri_gray_white, MRI *mri_wm) { +static int mrisComputeJointGrayWhiteBorderDistributions(MRI_SURFACE *mris, MRI *mri, MRI *mri_gray_white, MRI *mri_wm) +{ int vno, x, y; VERTEX *v; float norm; @@ -64279,7 +65532,8 @@ static int mrisComputeJointGrayWhiteBorderDistributions(MRI_SURFACE *mris, MRI * return (NO_ERROR); } -static int mrisFindGrayWhiteBorderMean(MRI_SURFACE *mris, MRI *mri) { +static int mrisFindGrayWhiteBorderMean(MRI_SURFACE *mris, MRI *mri) +{ double x, y, z, xv, yv, zv, gray_val, white_val, nx, ny, nz; int vno; VERTEX *v; @@ -64332,7 +65586,8 @@ static int mrisFindGrayWhiteBorderMean(MRI_SURFACE *mris, MRI *mri) { return (NO_ERROR); } -int MRISreadNewCurvatureFile(MRI_SURFACE *mris, const char *sname) { +int MRISreadNewCurvatureFile(MRI_SURFACE *mris, const char *sname) +{ int k, vnum, fnum, vals_per_vertex; float curv, curvmin, curvmax; FILE *fp; @@ -64345,9 +65600,11 @@ int MRISreadNewCurvatureFile(MRI_SURFACE *mris, const char *sname) { FileNamePath(mris->fname, path); if (cp) { sprintf(fname, "%s/%s", path, sname); - } else /* no hemisphere specified */ + } + else /* no hemisphere specified */ sprintf(fname, "%s/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", sname); - } else { + } + else { strcpy(fname, sname); /* path specified explcitly */ } @@ -64405,7 +65662,8 @@ int MRISreadNewCurvatureFile(MRI_SURFACE *mris, const char *sname) { fclose(fp); return (NO_ERROR); } -float *MRISreadNewCurvatureVector(MRI_SURFACE *mris, const char *sname) { +float *MRISreadNewCurvatureVector(MRI_SURFACE *mris, const char *sname) +{ char *cp, path[STRLEN], fname[STRLEN]; float *cvec = NULL; int return_code = ERROR_NONE; @@ -64417,9 +65675,11 @@ float *MRISreadNewCurvatureVector(MRI_SURFACE *mris, const char *sname) { FileNamePath(mris->fname, path); if (cp) { sprintf(fname, "%s/%s", path, sname); - } else /* no hemisphere specified */ + } + else /* no hemisphere specified */ sprintf(fname, "%s/%s.%s", path, mris->hemisphere == LEFT_HEMISPHERE ? "lh" : "rh", sname); - } else { + } + else { strcpy(fname, sname); /* path specified explcitly */ } @@ -64434,7 +65694,8 @@ float *MRISreadNewCurvatureVector(MRI_SURFACE *mris, const char *sname) { return cvec; } -int MRISreadNewCurvatureIntoArray(const char *sname, int in_array_size, float **out_array) { +int MRISreadNewCurvatureIntoArray(const char *sname, int in_array_size, float **out_array) +{ int k, vnum, fnum; float *cvec; FILE *fp; @@ -64498,7 +65759,8 @@ int MRISreadNewCurvatureIntoArray(const char *sname, int in_array_size, float ** Description ------------------------------------------------------*/ -int MRISpaintVolume(MRI_SURFACE *mris, LTA *lta, MRI *mri) { +int MRISpaintVolume(MRI_SURFACE *mris, LTA *lta, MRI *mri) +{ VERTEX *v; int vno, width, height, depth; double x, y, z, val; @@ -64554,7 +65816,8 @@ int MRISpaintVolume(MRI_SURFACE *mris, LTA *lta, MRI *mri) { MatrixFree(&m_ras_to_voxel); return (NO_ERROR); } -static int mrisComputePositioningGradients(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputePositioningGradients(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ MHT *mht_v_orig = NULL, *mht_v_current = NULL, *mht_f_current; MRI *mri_brain = parms->mri_brain; int avgs; @@ -64602,7 +65865,8 @@ static int mrisComputePositioningGradients(MRI_SURFACE *mris, INTEGRATION_PARMS } return (NO_ERROR); } -int MRISallocExtraGradients(MRI_SURFACE *mris) { +int MRISallocExtraGradients(MRI_SURFACE *mris) +{ if (mris->dx2) { return (NO_ERROR); /* already allocated */ } @@ -64615,7 +65879,8 @@ int MRISallocExtraGradients(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISrestoreExtraGradients(MRI_SURFACE *mris) { +int MRISrestoreExtraGradients(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -64633,7 +65898,8 @@ int MRISrestoreExtraGradients(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISclearDistances(MRI_SURFACE *mris) { +int MRISclearDistances(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -64670,7 +65936,8 @@ MRI *MRISloadSurfVals(const char *srcvalfile, MRI_SURFACE *Surf, const char *subject, const char *hemi, - const char *subjectsdir) { + const char *subjectsdir) +{ MRI *SrcVals, *mritmp; char fname[2000]; int srctype, reshapefactor = 0, f; @@ -64696,7 +65963,8 @@ MRI *MRISloadSurfVals(const char *srcvalfile, return (NULL); } freesurface = 1; - } else { + } + else { subject = Surf->subject_name; if (Surf->hemisphere == LEFT_HEMISPHERE) { hemi = "lh"; @@ -64727,13 +65995,15 @@ MRI *MRISloadSurfVals(const char *srcvalfile, // for(vtx = 0; vtx < Surf->nvertices; vtx++){ // MRIFseq_vox(SrcVals,vtx,0,0,0) = Surf->vertices[vtx].curv; //} - } else if (!strcmp(typestring, "paint") || !strcmp(typestring, "w")) { + } + else if (!strcmp(typestring, "paint") || !strcmp(typestring, "w")) { MRISreadValues(Surf, srcvalfile); SrcVals = MRIcopyMRIS(NULL, Surf, 0, "val"); // SrcVals = MRIallocSequence(Surf->nvertices, 1, 1,MRI_FLOAT,1); // for(vtx = 0; vtx < Surf->nvertices; vtx++) // MRIFseq_vox(SrcVals,vtx,0,0,0) = Surf->vertices[vtx].val; - } else { + } + else { /* Use MRIreadType */ srctype = string_to_type(typestring); if (srctype == MRI_VOLUME_TYPE_UNKNOWN) { @@ -64799,7 +66069,8 @@ MRI *MRISloadSurfVals(const char *srcvalfile, imag_val, curv, curvbak, fsmask, nc. Others can be easily added. If there is an error, a 1 is returned; otherwise 0. -----------------------------------------------------------------*/ -int MRIScopyMRI(MRIS *Surf, MRI *Src, int Frame, char *Field) { +int MRIScopyMRI(MRIS *Surf, MRI *Src, int Frame, char *Field) +{ int vtx, useval = 0, usecurv = 0, nvox, c, r, s; float val; @@ -64822,12 +66093,14 @@ int MRIScopyMRI(MRIS *Surf, MRI *Src, int Frame, char *Field) { /* A separate variable is used for val and curv for speed purposes */ if (!strcmp(Field, "val")) { useval = 1; - } else { + } + else { useval = 0; } if (!strcmp(Field, "curv")) { usecurv = 1; - } else { + } + else { usecurv = 0; } @@ -64841,75 +66114,110 @@ int MRIScopyMRI(MRIS *Surf, MRI *Src, int Frame, char *Field) { if (useval) { Surf->vertices[vtx].val = val; - } else if (usecurv) { + } + else if (usecurv) { Surf->vertices[vtx].curv = val; - } else if (!strcmp(Field, "stat")) { + } + else if (!strcmp(Field, "stat")) { Surf->vertices[vtx].stat = val; - } else if (!strcmp(Field, "valbak")) { + } + else if (!strcmp(Field, "valbak")) { Surf->vertices[vtx].valbak = val; - } else if (!strcmp(Field, "val2")) { + } + else if (!strcmp(Field, "val2")) { Surf->vertices[vtx].val2 = val; - } else if (!strcmp(Field, "val2bak")) { + } + else if (!strcmp(Field, "val2bak")) { Surf->vertices[vtx].val2bak = val; - } else if (!strcmp(Field, "imag_val")) { + } + else if (!strcmp(Field, "imag_val")) { Surf->vertices[vtx].imag_val = val; - } else if (!strcmp(Field, "curvbak")) { + } + else if (!strcmp(Field, "curvbak")) { Surf->vertices[vtx].curvbak = val; - } else if (!strcmp(Field, "fsmask")) { + } + else if (!strcmp(Field, "fsmask")) { Surf->vertices[vtx].fsmask = val; - } else if (!strcmp(Field, "nc")) { + } + else if (!strcmp(Field, "nc")) { Surf->vertices[vtx].nc = val; - } else if (!strcmp(Field, "undefval")) { + } + else if (!strcmp(Field, "undefval")) { Surf->vertices[vtx].undefval = val; - } else if (!strcmp(Field, "x")) { + } + else if (!strcmp(Field, "x")) { Surf->vertices[vtx].x = val; - } else if (!strcmp(Field, "y")) { + } + else if (!strcmp(Field, "y")) { Surf->vertices[vtx].y = val; - } else if (!strcmp(Field, "z")) { + } + else if (!strcmp(Field, "z")) { Surf->vertices[vtx].z = val; - } else if (!strcmp(Field, "vnum")) { + } + else if (!strcmp(Field, "vnum")) { Surf->vertices[vtx].vnum = val; - } else if (!strcmp(Field, "annotation")) { + } + else if (!strcmp(Field, "annotation")) { Surf->vertices[vtx].annotation = val; - } else if (!strcmp(Field, "ripflag")) { + } + else if (!strcmp(Field, "ripflag")) { Surf->vertices[vtx].ripflag = val; - } else if (!strcmp(Field, "area")) { + } + else if (!strcmp(Field, "area")) { Surf->vertices[vtx].area = val; - } else if (!strcmp(Field, "group_avg_area")) { + } + else if (!strcmp(Field, "group_avg_area")) { Surf->vertices[vtx].group_avg_area = val; - } else if (!strcmp(Field, "K")) { + } + else if (!strcmp(Field, "K")) { Surf->vertices[vtx].K = val; - } else if (!strcmp(Field, "H")) { + } + else if (!strcmp(Field, "H")) { Surf->vertices[vtx].H = val; - } else if (!strcmp(Field, "k1")) { + } + else if (!strcmp(Field, "k1")) { Surf->vertices[vtx].k1 = val; - } else if (!strcmp(Field, "k2")) { + } + else if (!strcmp(Field, "k2")) { Surf->vertices[vtx].k2 = val; - } else if (!strcmp(Field, "nx")) { + } + else if (!strcmp(Field, "nx")) { Surf->vertices[vtx].nx = val; - } else if (!strcmp(Field, "ny")) { + } + else if (!strcmp(Field, "ny")) { Surf->vertices[vtx].ny = val; - } else if (!strcmp(Field, "nz")) { + } + else if (!strcmp(Field, "nz")) { Surf->vertices[vtx].nz = val; - } else if (!strcmp(Field, "tx")) { + } + else if (!strcmp(Field, "tx")) { Surf->vertices[vtx].tx = val; - } else if (!strcmp(Field, "ty")) { + } + else if (!strcmp(Field, "ty")) { Surf->vertices[vtx].ty = val; - } else if (!strcmp(Field, "tz")) { + } + else if (!strcmp(Field, "tz")) { Surf->vertices[vtx].tz = val; - } else if (!strcmp(Field, "dx")) { + } + else if (!strcmp(Field, "dx")) { Surf->vertices[vtx].dx = val; - } else if (!strcmp(Field, "dy")) { + } + else if (!strcmp(Field, "dy")) { Surf->vertices[vtx].dy = val; - } else if (!strcmp(Field, "dz")) { + } + else if (!strcmp(Field, "dz")) { Surf->vertices[vtx].dz = val; - } else if (!strcmp(Field, "tdx")) { + } + else if (!strcmp(Field, "tdx")) { Surf->vertices[vtx].tdx = val; - } else if (!strcmp(Field, "tdy")) { + } + else if (!strcmp(Field, "tdy")) { Surf->vertices[vtx].tdy = val; - } else if (!strcmp(Field, "tdz")) { + } + else if (!strcmp(Field, "tdz")) { Surf->vertices[vtx].tdz = val; - } else { + } + else { printf("ERROR: MRIScopyMRI(): Field %s not supported\n", Field); return (1); } @@ -64932,7 +66240,8 @@ int MRIScopyMRI(MRIS *Surf, MRI *Src, int Frame, char *Field) { type will be MRI_FLOAT. A pointer to mri is returned. If an error occurs, NULL is returned. -----------------------------------------------------------------*/ -MRI *MRIcopyMRIS(MRI *mri, MRIS *surf, int Frame, char *Field) { +MRI *MRIcopyMRIS(MRI *mri, MRIS *surf, int Frame, char *Field) +{ int vtx, useval = 0, usecurv = 0, nvox, c, r, s; float val; @@ -64957,12 +66266,14 @@ MRI *MRIcopyMRIS(MRI *mri, MRIS *surf, int Frame, char *Field) { /* A separate variable is used for val and curv for speed purposes */ if (!strcmp(Field, "val")) { useval = 1; - } else { + } + else { useval = 0; } if (!strcmp(Field, "curv")) { usecurv = 1; - } else { + } + else { usecurv = 0; } @@ -64973,79 +66284,116 @@ MRI *MRIcopyMRIS(MRI *mri, MRIS *surf, int Frame, char *Field) { for (c = 0; c < mri->width; c++) { if (useval) { val = surf->vertices[vtx].val; - } else if (usecurv) { + } + else if (usecurv) { val = surf->vertices[vtx].curv; - } else if (!strcmp(Field, "stat")) { + } + else if (!strcmp(Field, "stat")) { val = surf->vertices[vtx].stat; - } else if (!strcmp(Field, "d")) { + } + else if (!strcmp(Field, "d")) { val = surf->vertices[vtx].d; - } else if (!strcmp(Field, "valbak")) { + } + else if (!strcmp(Field, "valbak")) { val = surf->vertices[vtx].valbak; - } else if (!strcmp(Field, "val2")) { + } + else if (!strcmp(Field, "val2")) { val = surf->vertices[vtx].val2; - } else if (!strcmp(Field, "val2bak")) { + } + else if (!strcmp(Field, "val2bak")) { val = surf->vertices[vtx].val2bak; - } else if (!strcmp(Field, "imag_val")) { + } + else if (!strcmp(Field, "imag_val")) { val = surf->vertices[vtx].imag_val; - } else if (!strcmp(Field, "curvbak")) { + } + else if (!strcmp(Field, "curvbak")) { val = surf->vertices[vtx].curvbak; - } else if (!strcmp(Field, "fsmask")) { + } + else if (!strcmp(Field, "fsmask")) { val = surf->vertices[vtx].fsmask; - } else if (!strcmp(Field, "fieldsign")) { + } + else if (!strcmp(Field, "fieldsign")) { val = surf->vertices[vtx].fieldsign; - } else if (!strcmp(Field, "nc")) { + } + else if (!strcmp(Field, "nc")) { val = surf->vertices[vtx].nc; - } else if (!strcmp(Field, "undefval")) { + } + else if (!strcmp(Field, "undefval")) { val = surf->vertices[vtx].undefval; - } else if (!strcmp(Field, "x")) { + } + else if (!strcmp(Field, "x")) { val = surf->vertices[vtx].x; - } else if (!strcmp(Field, "y")) { + } + else if (!strcmp(Field, "y")) { val = surf->vertices[vtx].y; - } else if (!strcmp(Field, "z")) { + } + else if (!strcmp(Field, "z")) { val = surf->vertices[vtx].z; - } else if (!strcmp(Field, "vnum")) { + } + else if (!strcmp(Field, "vnum")) { val = surf->vertices[vtx].vnum; - } else if (!strcmp(Field, "annotation")) { + } + else if (!strcmp(Field, "annotation")) { val = surf->vertices[vtx].annotation; - } else if (!strcmp(Field, "ripflag")) { + } + else if (!strcmp(Field, "ripflag")) { val = surf->vertices[vtx].ripflag; - } else if (!strcmp(Field, "area")) { + } + else if (!strcmp(Field, "area")) { val = surf->vertices[vtx].area; - } else if (!strcmp(Field, "group_avg_area")) { + } + else if (!strcmp(Field, "group_avg_area")) { val = surf->vertices[vtx].group_avg_area; - } else if (!strcmp(Field, "K")) { + } + else if (!strcmp(Field, "K")) { val = surf->vertices[vtx].K; - } else if (!strcmp(Field, "H")) { + } + else if (!strcmp(Field, "H")) { val = surf->vertices[vtx].H; - } else if (!strcmp(Field, "k1")) { + } + else if (!strcmp(Field, "k1")) { val = surf->vertices[vtx].k1; - } else if (!strcmp(Field, "k2")) { + } + else if (!strcmp(Field, "k2")) { val = surf->vertices[vtx].k2; - } else if (!strcmp(Field, "nx")) { + } + else if (!strcmp(Field, "nx")) { val = surf->vertices[vtx].nx; - } else if (!strcmp(Field, "ny")) { + } + else if (!strcmp(Field, "ny")) { val = surf->vertices[vtx].ny; - } else if (!strcmp(Field, "nz")) { + } + else if (!strcmp(Field, "nz")) { val = surf->vertices[vtx].nz; - } else if (!strcmp(Field, "tx")) { + } + else if (!strcmp(Field, "tx")) { val = surf->vertices[vtx].tx; - } else if (!strcmp(Field, "ty")) { + } + else if (!strcmp(Field, "ty")) { val = surf->vertices[vtx].ty; - } else if (!strcmp(Field, "tz")) { + } + else if (!strcmp(Field, "tz")) { val = surf->vertices[vtx].tz; - } else if (!strcmp(Field, "tdx")) { + } + else if (!strcmp(Field, "tdx")) { val = surf->vertices[vtx].tdx; - } else if (!strcmp(Field, "tdy")) { + } + else if (!strcmp(Field, "tdy")) { val = surf->vertices[vtx].tdy; - } else if (!strcmp(Field, "tdz")) { + } + else if (!strcmp(Field, "tdz")) { val = surf->vertices[vtx].tdz; - } else if (!strcmp(Field, "dx")) { + } + else if (!strcmp(Field, "dx")) { val = surf->vertices[vtx].dx; - } else if (!strcmp(Field, "dy")) { + } + else if (!strcmp(Field, "dy")) { val = surf->vertices[vtx].dy; - } else if (!strcmp(Field, "dz")) { + } + else if (!strcmp(Field, "dz")) { val = surf->vertices[vtx].dz; - } else { + } + else { printf("ERROR: MRIScopyMRI(): Field %s not supported\n", Field); return (NULL); } @@ -65068,7 +66416,8 @@ MRI *MRIcopyMRIS(MRI *mri, MRIS *surf, int Frame, char *Field) { (but does go the other way). Same for mask. If mask is NULL, it is ignored. See also MRISsmoothMRIFast() -------------------------------------------------------------------*/ -MRI *MRISsmoothMRI(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *BinMask, MRI *Targ) { +MRI *MRISsmoothMRI(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *BinMask, MRI *Targ) +{ int nnbrs, nthstep, frame, vtx, nbrvtx, nthnbr, **crslut, c, r, s, nvox; int nnbrs_actual; float val, m; @@ -65106,7 +66455,8 @@ MRI *MRISsmoothMRI(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *BinMask, MRI *Ta return (NULL); } MRIcopyHeader(Src, Targ); - } else { + } + else { if (Src->width != Targ->width || Src->height != Targ->height || Src->depth != Targ->depth || Src->nframes != Targ->nframes) { printf("ERROR: MRISsmooth: output dimension mismatch\n"); @@ -65194,7 +66544,8 @@ MRI *MRISsmoothMRI(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *BinMask, MRI *Ta mask=1 are included. If mask is NULL, it is ignored. Gives identical results as MRISsmoothMRI(); see MRISsmoothMRIFastCheck(). -------------------------------------------------------------------*/ -MRI *MRISsmoothMRIFast(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MRI *Targ) { +MRI *MRISsmoothMRIFast(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MRI *Targ) +{ int nnbrs, nthstep, frame, vno, nthnbr, num, nvox, nbrvno, reshape; MRI *SrcTmp, *mritmp, *IncMaskTmp = NULL; struct timeb mytimer; @@ -65225,7 +66576,8 @@ MRI *MRISsmoothMRIFast(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MRI if (Gdiag_no > 0) printf("MRISsmoothMRIFast(): reshaping\n"); SrcTmp = mri_reshape(Src, nvox, 1, 1, Src->nframes); reshape = 1; - } else { + } + else { reshape = 0; SrcTmp = MRIcopy(Src, NULL); } @@ -65327,7 +66679,8 @@ MRI *MRISsmoothMRIFast(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MRI mritmp = mri_reshape(SrcTmp, Src->width, Src->height, Src->depth, Src->nframes); Targ = MRIcopy(mritmp, Targ); MRIfree(&mritmp); - } else + } + else Targ = MRIcopy(SrcTmp, Targ); msecTime = TimerStop(&mytimer); @@ -65353,7 +66706,8 @@ MRI *MRISsmoothMRIFast(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MRI float or using double (and this function is slower than the float version). -------------------------------------------------------------------*/ -MRI *MRISsmoothMRIFastD(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MRI *Targ) { +MRI *MRISsmoothMRIFastD(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MRI *Targ) +{ int nnbrs, nthstep, frame, vno, nthnbr, num, nvox, nbrvno, c, r, s; MRI *IncMaskTmp = NULL; struct timeb mytimer; @@ -65505,7 +66859,8 @@ MRI *MRISsmoothMRIFastD(MRIS *Surf, MRI *Src, int nSmoothSteps, MRI *IncMask, MR a static data structure. Note: this will fail if Src is not nvertices x 1 x 1 x nframes. ------------------------------------------------------------------*/ -int MRISsmoothMRIFastFrame(MRIS *Surf, MRI *Src, int frame, int nSmoothSteps, MRI *IncMask) { +int MRISsmoothMRIFastFrame(MRIS *Surf, MRI *Src, int frame, int nSmoothSteps, MRI *IncMask) +{ int nnbrs, nthstep, vno, nthnbr, num, nvox, nbrvno; struct timeb mytimer; int msecTime; @@ -65629,7 +66984,8 @@ int MRISsmoothMRIFastFrame(MRIS *Surf, MRI *Src, int frame, int nSmoothSteps, MR return (0); } /*--------------------------------------------------------------*/ -int MRISsmoothMRIFastCheck(int nSmoothSteps) { +int MRISsmoothMRIFastCheck(int nSmoothSteps) +{ char tmpstr[2000], *UFSS; MRIS *mris; MRI *src, *mri1, *mri2, *mask; @@ -65700,7 +67056,8 @@ int MRISsmoothMRIFastCheck(int nSmoothSteps) { return (nerrs); } -int SetHop(int CenterVtx, MRI_SURFACE *Surf, int HopNo, int MaxHopNo) { +int SetHop(int CenterVtx, MRI_SURFACE *Surf, int HopNo, int MaxHopNo) +{ int nbr, nbr_vtx, nbr_hopno, nbr_has_been_center; if (HopNo >= MaxHopNo) return (0); @@ -65724,7 +67081,8 @@ int SetHop(int CenterVtx, MRI_SURFACE *Surf, int HopNo, int MaxHopNo) { return (0); } -SURFHOPLIST *SetSurfHopListAlloc(MRI_SURFACE *Surf, int nHops) { +SURFHOPLIST *SetSurfHopListAlloc(MRI_SURFACE *Surf, int nHops) +{ SURFHOPLIST *shl; int nthhop; shl = (SURFHOPLIST *)calloc(sizeof(SURFHOPLIST), 1); @@ -65740,7 +67098,8 @@ SURFHOPLIST *SetSurfHopListAlloc(MRI_SURFACE *Surf, int nHops) { return (shl); } -int SurfHopListFree(SURFHOPLIST **shl0) { +int SurfHopListFree(SURFHOPLIST **shl0) +{ SURFHOPLIST *shl = *shl0; int nthhop; for (nthhop = 0; nthhop < shl->nhops; nthhop++) free(shl->vtxlist[nthhop]); @@ -65760,7 +67119,8 @@ int SurfHopListFree(SURFHOPLIST **shl0) { set neighborhoods or compute the spatial autocorrelation function. */ -SURFHOPLIST *SetSurfHopList(int CenterVtx, MRI_SURFACE *Surf, int nHops) { +SURFHOPLIST *SetSurfHopList(int CenterVtx, MRI_SURFACE *Surf, int nHops) +{ SURFHOPLIST *shl; int nthhop, nhits, nthvtx, vtxno, nthnbr, nbr_vtxno; @@ -65816,7 +67176,8 @@ SURFHOPLIST *SetSurfHopList(int CenterVtx, MRI_SURFACE *Surf, int nHops) { frame 0 is always 1, frame 1 is the average AR between the vertex and the vertices 1 hop away, etc. -----------------------------------------------------------------------*/ -MRI *MRISarN(MRIS *surf, MRI *src, MRI *mask, MRI *arN, int N) { +MRI *MRISarN(MRIS *surf, MRI *src, MRI *mask, MRI *arN, int N) +{ int **crslut, nvox, vtx; nvox = src->width * src->height * src->depth; @@ -65912,7 +67273,8 @@ MRI *MRISarN(MRIS *surf, MRI *src, MRI *mask, MRI *arN, int N) { MRISsmoothKernel() - kernel = ACF^2 -----------------------------------------------------------------------*/ -MRI *MRISsmoothKernel(MRIS *surf, MRI *src, MRI *mask, MRI *mrikern, MATRIX *globkern, SURFHOPLIST ***pshl, MRI *out) { +MRI *MRISsmoothKernel(MRIS *surf, MRI *src, MRI *mask, MRI *mrikern, MATRIX *globkern, SURFHOPLIST ***pshl, MRI *out) +{ int vtx, **crslut, nvox; double *kern; int n, nhops; @@ -65937,7 +67299,8 @@ MRI *MRISsmoothKernel(MRIS *surf, MRI *src, MRI *mask, MRI *mrikern, MATRIX *glo printf("ERROR: MRISsmoothKernel(): could not alloc\n"); return (NULL); } - } else { + } + else { if (out == src) { printf("ERROR: MRISsmoothKernel(): cannot run in-place\n"); return (NULL); @@ -65969,7 +67332,8 @@ MRI *MRISsmoothKernel(MRIS *surf, MRI *src, MRI *mask, MRI *mrikern, MATRIX *glo *pshl = shl; msecTime = TimerStop(&mytimer); printf("Done allocating shl %d, %g sec\n", surf->nvertices, msecTime / 1000.0); - } else + } + else shl = *pshl; printf("Starting loop over %d vertices\n", surf->nvertices); @@ -65995,7 +67359,8 @@ MRI *MRISsmoothKernel(MRIS *surf, MRI *src, MRI *mask, MRI *mrikern, MATRIX *glo if (mrikern) { vkern = (double *)calloc(nhops, sizeof(double)); for (nthhop = 0; nthhop < nhops; nthhop++) vkern[nthhop] = MRIgetVoxVal(mrikern, vtx, 0, 0, nthhop); - } else + } + else vkern = kern; for (frame = 0; frame < src->nframes; frame++) { @@ -66049,7 +67414,8 @@ MRI *MRISsmoothKernel(MRIS *surf, MRI *src, MRI *mask, MRI *mrikern, MATRIX *glo account different distances between neighbors. Note: theoretical AR1 for one smoothing step is 4/7=0.57. -----------------------------------------------------------------------*/ -MRI *MRISar1(MRIS *surf, MRI *src, MRI *mask, MRI *ar1) { +MRI *MRISar1(MRIS *surf, MRI *src, MRI *mask, MRI *ar1) +{ int nnbrs, frame, vtx, nbrvtx, nthnbr, **crslut, c, r, s, nvox; int cnbr, rnbr, snbr, nnbrs_actual; double valvtx, valnbr, ar1sum, sumsqvtx, vtxvar, sumsqnbr, sumsqx, nbrvar; @@ -66140,7 +67506,8 @@ MRI *MRISar1(MRIS *surf, MRI *src, MRI *mask, MRI *ar1) { MRI struct has ncols*nrows*nslices = nvertices. See also MRIScrsLUTFee(). ---------------------------------------------------------------*/ -int **MRIScrsLUT(MRIS *surf, MRI *src) { +int **MRIScrsLUT(MRIS *surf, MRI *src) +{ int **crslut, c, r, s, nvox, vtx; crslut = (int **)calloc(3, sizeof(int *)); @@ -66170,7 +67537,8 @@ int **MRIScrsLUT(MRIS *surf, MRI *src) { /*---------------------------------------------------------- MRIScrsLUTFree() - frees memoary allocated by MRIScrsLUT. ----------------------------------------------------------*/ -int MRIScrsLUTFree(int **crslut) { +int MRIScrsLUTFree(int **crslut) +{ free(crslut[0]); free(crslut[1]); free(crslut[2]); @@ -66182,7 +67550,8 @@ int MRIScrsLUTFree(int **crslut) { MRISremoveRippedFromMask() - sets voxels in mask to 0 if corresponding vertex has been ripped. -------------------------------------------------------------------*/ -MRI *MRISremoveRippedFromMask(MRIS *surf, MRI *mask, MRI *outmask) { +MRI *MRISremoveRippedFromMask(MRIS *surf, MRI *mask, MRI *outmask) +{ int c, r, s, vtx; outmask = MRIcopy(mask, outmask); vtx = 0; @@ -66202,7 +67571,8 @@ MRI *MRISremoveRippedFromMask(MRIS *surf, MRI *mask, MRI *outmask) { MRISlabel2Mask() - creates a mask from the label by setting each voxel corresponding to a label point to 1 with the rest 0. ------------------------------------------------------------------*/ -MRI *MRISlabel2Mask(MRIS *surf, LABEL *lb, MRI *mask) { +MRI *MRISlabel2Mask(MRIS *surf, LABEL *lb, MRI *mask) +{ int vtxno, n; if (mask == NULL) // create mask as all 0s @@ -66223,7 +67593,8 @@ MRI *MRISlabel2Mask(MRIS *surf, LABEL *lb, MRI *mask) { } /*----------------------------------------------------------------------*/ -int MRISrectifyCurvature(MRI_SURFACE *mris) { +int MRISrectifyCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -66567,7 +67938,8 @@ markAllDistantConvex(MRI_SURFACE *mris, float min_dist) Description ------------------------------------------------------*/ -static int mrisAverageSignedGradients(MRI_SURFACE *mris, int num_avgs) { +static int mrisAverageSignedGradients(MRI_SURFACE *mris, int num_avgs) +{ int i, vno; float sigma; VERTEX *v; @@ -66615,7 +67987,8 @@ static int mrisAverageSignedGradients(MRI_SURFACE *mris, int num_avgs) { MRISgradientFromParameterization(mrisp_blur, mris); MRISPfree(&mrisp); MRISPfree(&mrisp_blur); - } else + } + else for (i = 0; i < num_avgs; i++) { #ifdef HAVE_OPENMP #pragma omp parallel for @@ -66976,7 +68349,8 @@ mrisUpdateSulcalGradients(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) } #endif -int MRISsetFlags(MRI_SURFACE *mris, int flags) { +int MRISsetFlags(MRI_SURFACE *mris, int flags) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -66985,7 +68359,8 @@ int MRISsetFlags(MRI_SURFACE *mris, int flags) { return (NO_ERROR); } -int MRISclearFlags(MRI_SURFACE *mris, int flags) { +int MRISclearFlags(MRI_SURFACE *mris, int flags) +{ int vno; for (vno = 0; vno < mris->nvertices; vno++) { @@ -66994,7 +68369,8 @@ int MRISclearFlags(MRI_SURFACE *mris, int flags) { return (NO_ERROR); } -static int mrisReadAsciiCurvatureFile(MRI_SURFACE *mris, const char *fname) { +static int mrisReadAsciiCurvatureFile(MRI_SURFACE *mris, const char *fname) +{ FILE *fp; int vno; char line[STRLEN], *cp; @@ -67027,7 +68403,8 @@ static int mrisReadAsciiCurvatureFile(MRI_SURFACE *mris, const char *fname) { // expand the surface by "h" and create a volume // which has "val" outside of this surface -unsigned long MRISeraseOutsideOfSurface(float h, MRI *mri_dst, MRIS *mris, unsigned char val) { +unsigned long MRISeraseOutsideOfSurface(float h, MRI *mri_dst, MRIS *mris, unsigned char val) +{ int i, j, k, imnr; float x0, y0, z0, x1, y1, z1, x2, y2, z2, d0, d1, d2, dmax, u, v; float px, py, pz, px0, py0, pz0, px1, py1, pz1; @@ -67135,7 +68512,8 @@ unsigned long MRISeraseOutsideOfSurface(float h, MRI *mri_dst, MRIS *mris, unsig for (i = 0; i < width; i++) { if (MRIvox(mri_buff, i, j, k) == 64) { MRIvox(mri_dst, i, j, k) = 0; - } else { + } + else { brainsize++; } } @@ -67145,7 +68523,8 @@ unsigned long MRISeraseOutsideOfSurface(float h, MRI *mri_dst, MRIS *mris, unsig for (i = 0; i < width; i++) { if (MRIvox(mri_buff, i, j, k) != 64) { MRIvox(mri_dst, i, j, k) = val; - } else { + } + else { brainsize++; } } @@ -67163,7 +68542,8 @@ unsigned long MRISeraseOutsideOfSurface(float h, MRI *mri_dst, MRIS *mris, unsig return brainsize; } -int MRISmarkedSpringTerm(MRI_SURFACE *mris, double l_spring) { +int MRISmarkedSpringTerm(MRI_SURFACE *mris, double l_spring) +{ int vno, n, m; VERTEX *vertex, *vn; float sx, sy, sz, x, y, z; @@ -67215,7 +68595,8 @@ int MRISmarkedSpringTerm(MRI_SURFACE *mris, double l_spring) { return (NO_ERROR); } -int MRISnormalSpringTermWithGaussianCurvature(MRI_SURFACE *mris, double gaussian_norm, double l_spring) { +int MRISnormalSpringTermWithGaussianCurvature(MRI_SURFACE *mris, double gaussian_norm, double l_spring) +{ int vno, n, m; VERTEX *vertex, *vn; float sx, sy, sz, x, y, z, scale, nc, nx, ny, nz; @@ -67281,7 +68662,8 @@ int MRISnormalSpringTermWithGaussianCurvature(MRI_SURFACE *mris, double gaussian return (NO_ERROR); } -int MRISspringTermWithGaussianCurvature(MRI_SURFACE *mris, double gaussian_norm, double l_spring) { +int MRISspringTermWithGaussianCurvature(MRI_SURFACE *mris, double gaussian_norm, double l_spring) +{ int vno, n, m; VERTEX *vertex, *vn; float sx, sy, sz, x, y, z, scale; @@ -67340,7 +68722,8 @@ int MRISspringTermWithGaussianCurvature(MRI_SURFACE *mris, double gaussian_norm, return (NO_ERROR); } -static int mrisGraphLaplacian(MRI_SURFACE *mris, int vno, double *pdx, double *pdy, double *pdz, int which) { +static int mrisGraphLaplacian(MRI_SURFACE *mris, int vno, double *pdx, double *pdy, double *pdz, int which) +{ VERTEX *v, *vn; double lx, ly, lz, w, norm, dx, dy, dz, wtotal; int n; @@ -67365,7 +68748,8 @@ static int mrisGraphLaplacian(MRI_SURFACE *mris, int vno, double *pdx, double *p if (!FZERO(norm)) { w = 1.0 / norm; - } else { + } + else { w = 1; } break; @@ -67392,7 +68776,8 @@ static int mrisGraphLaplacian(MRI_SURFACE *mris, int vno, double *pdx, double *p #define Lambda .3 #define Mu (1.0)/((K_bp)-1.0/Lambda) */ -int MRIStaubinSmooth(MRI_SURFACE *mris, int niters, double lambda, double mu, int which) { +int MRIStaubinSmooth(MRI_SURFACE *mris, int niters, double lambda, double mu, int which) +{ int n, vno; double dx, dy, dz; VERTEX *v; @@ -67419,7 +68804,8 @@ int MRIStaubinSmooth(MRI_SURFACE *mris, int niters, double lambda, double mu, in v->tx = v->x + lambda * dx; v->ty = v->y + lambda * dy; v->tz = v->z + lambda * dz; - } else { + } + else { v->tx = v->x + mu * dx; v->ty = v->y + mu * dy; v->tz = v->z + mu * dz; @@ -67431,7 +68817,8 @@ int MRIStaubinSmooth(MRI_SURFACE *mris, int niters, double lambda, double mu, in return (NO_ERROR); } -int MRISnormalTermWithGaussianCurvature(MRI_SURFACE *mris, double lambda) { +int MRISnormalTermWithGaussianCurvature(MRI_SURFACE *mris, double lambda) +{ int vno; VERTEX *v; @@ -67456,7 +68843,8 @@ int MRISnormalTermWithGaussianCurvature(MRI_SURFACE *mris, double lambda) { return (NO_ERROR); } -static int mrisComputeExpandwrapTerm(MRI_SURFACE *mris, MRI *mri_brain, double l_expandwrap) { +static int mrisComputeExpandwrapTerm(MRI_SURFACE *mris, MRI *mri_brain, double l_expandwrap) +{ int vno; double xw, yw, zw, x, y, z, val, dx, dy, dz; VERTEX *v; @@ -67503,7 +68891,8 @@ static int mrisComputeExpandwrapTerm(MRI_SURFACE *mris, MRI *mri_brain, double l return (NO_ERROR); } -static double mrisComputeExpandwrapError(MRI_SURFACE *mris, MRI *mri_brain, double l_expandwrap, double target_radius) { +static double mrisComputeExpandwrapError(MRI_SURFACE *mris, MRI *mri_brain, double l_expandwrap, double target_radius) +{ int vno; double xw, yw, zw, x, y, z, val, dx, dy, dz, sse, error, dist; VERTEX *v; @@ -67532,7 +68921,8 @@ static double mrisComputeExpandwrapError(MRI_SURFACE *mris, MRI *mri_brain, doub dist = sqrt(dx * dx + dy * dy + dz * dz); error = (target_radius - dist); sse += error * error; - } else { + } + else { error = 0.0; } @@ -67548,7 +68938,8 @@ static double mrisComputeExpandwrapError(MRI_SURFACE *mris, MRI *mri_brain, doub } return (sse); } -static int mrisComputeShrinkwrapTerm(MRI_SURFACE *mris, MRI *mri_brain, double l_shrinkwrap) { +static int mrisComputeShrinkwrapTerm(MRI_SURFACE *mris, MRI *mri_brain, double l_shrinkwrap) +{ int vno; double xw, yw, zw, x, y, z, val, dx, dy, dz; VERTEX *v; @@ -67597,7 +68988,8 @@ static int mrisComputeShrinkwrapTerm(MRI_SURFACE *mris, MRI *mri_brain, double l return (NO_ERROR); } -static double mrisComputeShrinkwrapError(MRI_SURFACE *mris, MRI *mri_brain, double l_shrinkwrap) { +static double mrisComputeShrinkwrapError(MRI_SURFACE *mris, MRI *mri_brain, double l_shrinkwrap) +{ #if 0 static int iter = 100 ; int vno ; @@ -67627,7 +69019,8 @@ static double mrisComputeShrinkwrapError(MRI_SURFACE *mris, MRI *mri_brain, doub at TruncFactor stddevs. Note: this will change the val2bak of all the vertices. See also MRISspatialFilter() and MRISgaussianWeights(). -------------------------------------------------------------------*/ -MRI *MRISgaussianSmooth(MRIS *Surf, MRI *Src, double GStd, MRI *Targ, double TruncFactor) { +MRI *MRISgaussianSmooth(MRIS *Surf, MRI *Src, double GStd, MRI *Targ, double TruncFactor) +{ int vtxno1, vtxno2; float val; MRI *SrcTmp, *GSum, *GSum2, *nXNbrsMRI; @@ -67649,7 +69042,8 @@ MRI *MRISgaussianSmooth(MRIS *Surf, MRI *Src, double GStd, MRI *Targ, double Tru printf("ERROR: MRISgaussianSmooth: could not alloc\n"); return (NULL); } - } else { + } + else { if (Src->width != Targ->width || Src->height != Targ->height || Src->depth != Targ->depth || Src->nframes != Targ->nframes) { printf("ERROR: MRISgaussianSmooth: output dimension mismatch\n"); @@ -67845,7 +69239,8 @@ int MRISextendedNeighbors(MRIS *SphSurf, double *XNbrDotProd, int *nXNbrs, int nXNbrsMax, - int DistType) { + int DistType) +{ static int ncalls = 0; VERTEX *vtarg, *vcur; int nNNbrs, n, NbrVtxNo, err; @@ -67883,7 +69278,8 @@ int MRISextendedNeighbors(MRIS *SphSurf, if (DotProd <= DotProdThresh) { return (0); } - } else { + } + else { // Cartesian - dist squared along sphere (so thresh should be squared) dx = vtarg->x - vcur->x; dy = vtarg->y - vcur->y; @@ -67929,7 +69325,8 @@ int MRISextendedNeighbors(MRIS *SphSurf, row. Each of the extended neighbrs is placed in a frame. The weights for a given vertex will be normalized so that the sum=1. --------------------------------------------------------------------------*/ -int MRISgaussianWeights(MRIS *surf, MRI *dist, double GStd) { +int MRISgaussianWeights(MRIS *surf, MRI *dist, double GStd) +{ int n, m, nXNbrs; double GVar2, f, gsum, d, g; @@ -67958,7 +69355,8 @@ int MRISgaussianWeights(MRIS *surf, MRI *dist, double GStd) { be as computed by MRISgaussianWeights() and MRISdistSphere(). It is assumed that the weights are already normalized. -------------------------------------------------------------------*/ -MRI *MRISspatialFilter(MRI *Src, MRI *wdist, MRI *Targ) { +MRI *MRISspatialFilter(MRI *Src, MRI *wdist, MRI *Targ) +{ int n, nXNbrs, m, vtxno, frame; float w, val; MRI *SrcCopy = NULL; @@ -68006,7 +69404,8 @@ MRI *MRISspatialFilter(MRI *Src, MRI *wdist, MRI *Targ) { extended neighborhood of a vertex includes itself. See also MRISgaussianWeights(). -------------------------------------------------------------------*/ -MRI *MRISdistSphere(MRIS *surf, double dmax) { +MRI *MRISdistSphere(MRIS *surf, double dmax) +{ int vtxno; MRI *dist; double Radius, Radius2, d, costheta, theta; @@ -68130,7 +69529,8 @@ MRI *MRISdistSphere(MRIS *surf, double dmax) { // conformed -------> surfaceRAS (c_(ras) = 0 ) // surface lives here for talairach space // -MATRIX *surfaceRASToSurfaceRAS_(MRI *src, MRI *dst, LTA *lta) { +MATRIX *surfaceRASToSurfaceRAS_(MRI *src, MRI *dst, LTA *lta) +{ MATRIX *sRASToRAS = 0; MATRIX *RASToSRAS = 0; MATRIX *tmp = 0; @@ -68148,7 +69548,8 @@ MATRIX *surfaceRASToSurfaceRAS_(MRI *src, MRI *dst, LTA *lta) { MatrixFree(&tmp); return res; - } else if (lta->type == LINEAR_VOX_TO_VOX) { + } + else if (lta->type == LINEAR_VOX_TO_VOX) { // just make sure if (!src->r_to_i__) { src->r_to_i__ = extract_r_to_i(src); @@ -68159,7 +69560,8 @@ MATRIX *surfaceRASToSurfaceRAS_(MRI *src, MRI *dst, LTA *lta) { tmp2 = extract_i_to_r(dst); AffineMatrixAlloc(&(dst->i_to_r__)); SetAffineMatrix(dst->i_to_r__, tmp); - } else { + } + else { tmp2 = MatrixAlloc(4, 4, MATRIX_REAL); GetAffineMatrix(tmp, dst->i_to_r__); } @@ -68177,12 +69579,14 @@ MATRIX *surfaceRASToSurfaceRAS_(MRI *src, MRI *dst, LTA *lta) { MatrixFree(&tmp2); return res; - } else + } + else ErrorExit(ERROR_BADPARM, "%s: xfm passed is neither of RAS-to-RAS type nor Vox-To-Vox type.", Progname); return 0; } -MATRIX *getSRASToTalSRAS(LT *lt) { +MATRIX *getSRASToTalSRAS(LT *lt) +{ MATRIX *RASFromSRAS = 0; MATRIX *sRASFromRAS = 0; MATRIX *tmpM = 0; @@ -68224,7 +69628,8 @@ MATRIX *getSRASToTalSRAS(LT *lt) { } // transform surface vertices to the dst volume surface -int MRISsurf2surf(MRIS *mris, MRI *dst, LTA *lta) { +int MRISsurf2surf(MRIS *mris, MRI *dst, LTA *lta) +{ VECTOR *sX = 0; VECTOR *dX = 0; MATRIX *surf2surf = 0; @@ -68283,7 +69688,8 @@ int MRISsurf2surf(MRIS *mris, MRI *dst, LTA *lta) { return 0; } // transform surface vertices positions (all of them) to the dst volume surface -int MRISsurf2surfAll(MRIS *mris, MRI *dst, LTA *lta) { +int MRISsurf2surfAll(MRIS *mris, MRI *dst, LTA *lta) +{ VECTOR *sX = 0; VECTOR *dX = 0; MATRIX *surf2surf = 0; @@ -68377,7 +69783,8 @@ void MRISsetReadFrame(int frame) { mris_readval_frame = frame; } MRISgetReadFrame() - gets frame to read when loading a "volume" with MRISreadValues(). --------------------------------------------------------*/ -int MRISgetReadFrame(void) { +int MRISgetReadFrame(void) +{ int frame = 0; char *envframe; if (mris_readval_frame >= 0) { @@ -68390,7 +69797,8 @@ int MRISgetReadFrame(void) { sscanf(envframe, "%d", &frame); return (frame); } -int MRISaddCommandLine(MRI_SURFACE *mris, char *cmdline) { +int MRISaddCommandLine(MRI_SURFACE *mris, char *cmdline) +{ int i; if (mris->ncmds >= MAX_CMDS) ErrorExit(ERROR_NOMEMORY, "MRISaddCommandLine: can't add cmd %s (%d)", cmdline, mris->ncmds); @@ -68400,7 +69808,8 @@ int MRISaddCommandLine(MRI_SURFACE *mris, char *cmdline) { strcpy(mris->cmdlines[i], cmdline); return (NO_ERROR); } -int MRISabsVals(MRI_SURFACE *mris) { +int MRISabsVals(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -68413,7 +69822,8 @@ int MRISabsVals(MRI_SURFACE *mris) { } return (NO_ERROR); } -int MRISabsCurvature(MRI_SURFACE *mris) { +int MRISabsCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -68426,7 +69836,8 @@ int MRISabsCurvature(MRI_SURFACE *mris) { } return (NO_ERROR); } -int MRISsmoothFrames(MRI_SURFACE *mris, MRI *mri, int navgs) { +int MRISsmoothFrames(MRI_SURFACE *mris, MRI *mri, int navgs) +{ int frame; for (frame = 0; frame < mri->nframes; frame++) { @@ -68436,7 +69847,8 @@ int MRISsmoothFrames(MRI_SURFACE *mris, MRI *mri, int navgs) { } return (NO_ERROR); } -int MRISwriteFrameToValues(MRI_SURFACE *mris, MRI *mri, int frame) { +int MRISwriteFrameToValues(MRI_SURFACE *mris, MRI *mri, int frame) +{ int vno; VERTEX *v; @@ -68453,7 +69865,8 @@ int MRISwriteFrameToValues(MRI_SURFACE *mris, MRI *mri, int frame) { } return (NO_ERROR); } -int MRISreadFrameFromValues(MRI_SURFACE *mris, MRI *mri, int frame) { +int MRISreadFrameFromValues(MRI_SURFACE *mris, MRI *mri, int frame) +{ int vno; VERTEX *v; @@ -68472,7 +69885,8 @@ int MRISreadFrameFromValues(MRI_SURFACE *mris, MRI *mri, int frame) { } static int mrisSmoothingTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms); -int MRISremoveOverlapWithSmoothing(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +int MRISremoveOverlapWithSmoothing(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int negative, old_neg, same = 0, min_neg, min_neg_iter, last_expand; parms->dt = .99; @@ -68507,11 +69921,13 @@ int MRISremoveOverlapWithSmoothing(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) if (negative < min_neg) { min_neg = negative; min_neg_iter = parms->t; - } else if ((((parms->t - min_neg_iter) % 10) == 0) && parms->t > min_neg_iter) { + } + else if ((((parms->t - min_neg_iter) % 10) == 0) && parms->t > min_neg_iter) { if (parms->dt > 0.01) { parms->dt *= 0.95; } - } else if ((parms->t > min_neg_iter + 50) && parms->t > last_expand + 25) { + } + else if ((parms->t > min_neg_iter + 50) && parms->t > last_expand + 25) { if (parms->max_nbrs < 1) { parms->dt = 0.99; parms->max_nbrs++; @@ -68534,7 +69950,8 @@ int MRISremoveOverlapWithSmoothing(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) // parms->dt /= 2 ; same = 0; } - } else { + } + else { same = 0; } #if 0 @@ -68584,7 +70001,8 @@ int MRISremoveOverlapWithSmoothing(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) return (NO_ERROR); } -static int mrisSmoothingTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisSmoothingTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int vno, n, m, fno; VERTEX *v, *vn; FACE *face; @@ -68713,7 +70131,8 @@ static int mrisSmoothingTimeStep(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { return (NO_ERROR); } -int MRISupsampleIco(MRI_SURFACE *mris, MRI_SURFACE *mris_new) { +int MRISupsampleIco(MRI_SURFACE *mris, MRI_SURFACE *mris_new) +{ int vno; VERTEX *vold, *vnew; @@ -68735,7 +70154,8 @@ int MRISupsampleIco(MRI_SURFACE *mris, MRI_SURFACE *mris_new) { return (NO_ERROR); } -int MRIScopyVolGeomFromMRI(MRI_SURFACE *mris, MRI *mri) { +int MRIScopyVolGeomFromMRI(MRI_SURFACE *mris, MRI *mri) +{ VOL_GEOM *vg = &mris->vg; vg->xsize = mri->xsize; @@ -68762,7 +70182,8 @@ int MRIScopyVolGeomFromMRI(MRI_SURFACE *mris, MRI *mri) { } #define MAX_INT_REMOVAL_NEIGHBORS 5 -int MRISremoveIntersections(MRI_SURFACE *mris) { +int MRISremoveIntersections(MRI_SURFACE *mris) +{ int n, num, writeit = 0, old_num, nbrs, min_int, no_progress = 0; n = 0; @@ -68788,14 +70209,16 @@ int MRISremoveIntersections(MRI_SURFACE *mris) { break; printf("max nbrs reached, resetting neighborhood size\n"); nbrs = 0; - } else { + } + else { // disable this code as it was causing the surface to do wacky things. Just try smoothing // vertices that are actually intersecting // nbrs++ ; // printf("expanding nbhd size to %d\n", nbrs); if (no_progress > 15) break; } - } else // num didn't get bigger + } + else // num didn't get bigger { if (num < old_num) // num actually decreased no_progress = 0; @@ -68833,7 +70256,8 @@ int MRISremoveIntersections(MRI_SURFACE *mris) { return (NO_ERROR); } -static int mrisMarkIntersections(MRI_SURFACE *mris) { +static int mrisMarkIntersections(MRI_SURFACE *mris) +{ MRIS_HASH_TABLE *mht; FACE *f; int fno, n, num = 0; @@ -68861,7 +70285,8 @@ static int mrisMarkIntersections(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISaverageMarkedVertexPositions(MRI_SURFACE *mris, int navgs) { +int MRISaverageMarkedVertexPositions(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float x, y, z, num; VERTEX *v, *vn; @@ -68957,7 +70382,8 @@ mrisSoapBubbleIntersectingDefects(MRI_SURFACE *mris) return(NO_ERROR) ; } #endif -int MRIScopyMarkedToMarked2(MRI_SURFACE *mris) { +int MRIScopyMarkedToMarked2(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -68967,7 +70393,8 @@ int MRIScopyMarkedToMarked2(MRI_SURFACE *mris) { } return (NO_ERROR); } -int MRIScopyValsToAnnotations(MRI_SURFACE *mris) { +int MRIScopyValsToAnnotations(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -68978,7 +70405,8 @@ int MRIScopyValsToAnnotations(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScopyMarked2ToMarked(MRI_SURFACE *mris) { +int MRIScopyMarked2ToMarked(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -68989,7 +70417,8 @@ int MRIScopyMarked2ToMarked(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScopyMarkedToMarked3(MRI_SURFACE *mris) { +int MRIScopyMarkedToMarked3(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -69000,7 +70429,8 @@ int MRIScopyMarkedToMarked3(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScopyMarked3ToMarked(MRI_SURFACE *mris) { +int MRIScopyMarked3ToMarked(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -69012,7 +70442,8 @@ int MRIScopyMarked3ToMarked(MRI_SURFACE *mris) { } /* assume that the mark is 1 */ -int MRISexpandMarked(MRI_SURFACE *mris) { +int MRISexpandMarked(MRI_SURFACE *mris) +{ int vno, n; VERTEX *v, *vn; @@ -69039,16 +70470,19 @@ int MRISexpandMarked(MRI_SURFACE *mris) { // the vertex area. Default is to fix, but this can be changed // by setting to 0. fix_vertex_area is defined as "static int fix_vertex_area;" // at the top of this file. -int MRISsetFixVertexAreaValue(int value) { +int MRISsetFixVertexAreaValue(int value) +{ extern int fix_vertex_area; fix_vertex_area = value; return (fix_vertex_area); } -int MRISgetFixVertexAreaValue(void) { +int MRISgetFixVertexAreaValue(void) +{ extern int fix_vertex_area; return (fix_vertex_area); } -int MRISsetCurvature(MRI_SURFACE *mris, float val) { +int MRISsetCurvature(MRI_SURFACE *mris, float val) +{ int vno; VERTEX *v; @@ -69063,7 +70497,8 @@ int MRISsetCurvature(MRI_SURFACE *mris, float val) { } int MRIScomputeClassStatistics( - MRI_SURFACE *mris, MRI *mri, float *pwhite_mean, float *pwhite_std, float *pgray_mean, float *pgray_std) { + MRI_SURFACE *mris, MRI *mri, float *pwhite_mean, float *pwhite_std, float *pgray_mean, float *pgray_std) +{ double val, x, y, z, xw, yw, zw; int total_vertices, vno; VERTEX *v; @@ -69073,7 +70508,8 @@ int MRIScomputeClassStatistics( if (Gdiag & DIAG_WRITE && DIAG_VERBOSE_ON) { fpwm = fopen("wm.dat", "w"); fpgm = fopen("gm.dat", "w"); - } else { + } + else { fpgm = fpwm = NULL; } @@ -69139,7 +70575,8 @@ int MRIScomputeClassModes(MRI_SURFACE *mris, float *pcsf_mode, float *pwhite_std, float *pgray_std, - float *pcsf_std) { + float *pcsf_std) +{ HISTOGRAM *h_white, *h_csf, *h_gray; float min_val, max_val, white_std, gray_std, csf_std = 0; int nbins, b, vno, gray_peak, white_peak, csf_peak, bin; @@ -69284,12 +70721,13 @@ int MRIScomputeClassModes(MRI_SURFACE *mris, return (NO_ERROR); } -int MRISrasToVoxel( - MRI_SURFACE *mris, MRI *mri, double xs, double ys, double zs, double *pxv, double *pyv, double *pzv) { +int MRISrasToVoxel(MRI_SURFACE *mris, MRI *mri, double xs, double ys, double zs, double *pxv, double *pyv, double *pzv) +{ return (MRISsurfaceRASToVoxelCached(mris, mri, xs, ys, zs, pxv, pyv, pzv)); } -int MRISstoreRipFlags(MRI_SURFACE *mris) { +int MRISstoreRipFlags(MRI_SURFACE *mris) +{ int vno, fno; VERTEX *v; FACE *f; @@ -69305,7 +70743,8 @@ int MRISstoreRipFlags(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISrestoreRipFlags(MRI_SURFACE *mris) { +int MRISrestoreRipFlags(MRI_SURFACE *mris) +{ int vno, fno; VERTEX *v; FACE *f; @@ -69330,7 +70769,8 @@ int MRISrestoreRipFlags(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISripMedialWall(MRI_SURFACE *mris) { +int MRISripMedialWall(MRI_SURFACE *mris) +{ int vno, med_index, unknown_index; VERTEX *v; int structure; @@ -69356,7 +70796,8 @@ int MRISripMedialWall(MRI_SURFACE *mris) { Description ------------------------------------------------------*/ -int MRISzeroMedialWallCurvature(MRI_SURFACE *mris) { +int MRISzeroMedialWallCurvature(MRI_SURFACE *mris) +{ int vno, med_index, unknown_index; VERTEX *v; int structure; @@ -69375,7 +70816,8 @@ int MRISzeroMedialWallCurvature(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISvertexNormalInVoxelCoords(MRI_SURFACE *mris, MRI *mri, int vno, double *pnx, double *pny, double *pnz) { +int MRISvertexNormalInVoxelCoords(MRI_SURFACE *mris, MRI *mri, int vno, double *pnx, double *pny, double *pnz) +{ double xv0, yv0, zv0, xv1, yv1, zv1, xw, yw, zw, norm, nx, ny, nz; VERTEX *v; @@ -69403,7 +70845,8 @@ int MRISvertexNormalInVoxelCoords(MRI_SURFACE *mris, MRI *mri, int vno, double * return (NO_ERROR); } -static int enforce_links(MRI_SURFACE *mris) { +static int enforce_links(MRI_SURFACE *mris) +{ int vno, vno2, n; VERTEX *v, *v2; VERTEX_INFO *vi; @@ -69469,7 +70912,8 @@ static int enforce_links(MRI_SURFACE *mris) { return (NO_ERROR); } -static int enforce_link_positions(MRI_SURFACE *mris) { +static int enforce_link_positions(MRI_SURFACE *mris) +{ int vno, vno2, n; VERTEX *v, *v2; VERTEX_INFO *vi; @@ -69548,7 +70992,8 @@ MRISPiterative_blur(MRI_SURFACE *mris, return(mrisp_dst) ; } #endif -int MRISripMarked(MRI_SURFACE *mris) { +int MRISripMarked(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -69560,7 +71005,8 @@ int MRISripMarked(MRI_SURFACE *mris) { } return (NO_ERROR); } -int MRISripUnmarked(MRI_SURFACE *mris) { +int MRISripUnmarked(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -69574,7 +71020,8 @@ int MRISripUnmarked(MRI_SURFACE *mris) { } // set all the marks to a user specified value INCLUDING RIPPED VERTICES! -int MRISsetAllMarks(MRI_SURFACE *mris, int mark) { +int MRISsetAllMarks(MRI_SURFACE *mris, int mark) +{ int vno; VERTEX *v; @@ -69585,7 +71032,8 @@ int MRISsetAllMarks(MRI_SURFACE *mris, int mark) { return (NO_ERROR); } #include "diag.h" -int MRISmakeDensityMap(MRI_SURFACE *mris, double resolution, double radius, int diag_no, MRI **pmri) { +int MRISmakeDensityMap(MRI_SURFACE *mris, double resolution, double radius, int diag_no, MRI **pmri) +{ MRI *mri_interior; int x, y, z, vno, num, vradius, xmin, xmax, ymin, ymax, zmin, zmax; VERTEX *v; @@ -69659,7 +71107,8 @@ int MRISmakeDensityMap(MRI_SURFACE *mris, double resolution, double radius, int \fn double MRIScomputeWhiteVolume(MRI_SURFACE *mris, MRI *mri_aseg, double resolution) \brief Computes surface-based white matter volume, excluding subcort */ -double MRIScomputeWhiteVolume(MRI_SURFACE *mris, MRI *mri_aseg, double resolution) { +double MRIScomputeWhiteVolume(MRI_SURFACE *mris, MRI *mri_aseg, double resolution) +{ MRI *mri_filled; MATRIX *m_vox2vox; double total_volume = 0.0, vox_volume; @@ -69740,7 +71189,8 @@ double MRIScomputeWhiteVolume(MRI_SURFACE *mris, MRI *mri_aseg, double resolutio return (total_volume); } MRI *MRISfillWhiteMatterInterior( - MRI_SURFACE *mris, MRI *mri_aseg, MRI *mri_filled, double resolution, int wm_val, int gm_val, int csf_val) { + MRI_SURFACE *mris, MRI *mri_aseg, MRI *mri_filled, double resolution, int wm_val, int gm_val, int csf_val) +{ MATRIX *m_vox2vox; double vox_volume; int x, y, z, label, xa, ya, za; @@ -69845,7 +71295,8 @@ MRI *MRISfillWhiteMatterInterior( MatrixFree(&v2); return (mri_filled); } -static int mrisCheckSurfaceNbrs(MRI_SURFACE *mris) { +static int mrisCheckSurfaceNbrs(MRI_SURFACE *mris) +{ int vno, n, n2, found; VERTEX *v, *vn; @@ -69870,7 +71321,8 @@ static int mrisCheckSurfaceNbrs(MRI_SURFACE *mris) { return (1); } -int MRISbinarizeCurvature(MRI_SURFACE *mris, float thresh, float low, float high, int use_abs) { +int MRISbinarizeCurvature(MRI_SURFACE *mris, float thresh, float low, float high, int use_abs) +{ int vno; VERTEX *v; float val; @@ -69883,14 +71335,16 @@ int MRISbinarizeCurvature(MRI_SURFACE *mris, float thresh, float low, float high val = (use_abs ? fabs(v->curv) : v->curv); if (val < thresh) { v->curv = low; - } else { + } + else { v->curv = v->curv < 0 ? -high : high; } } return (NO_ERROR); } -int MRISthresholdCurvature(MRI_SURFACE *mris, float thresh, int use_abs) { +int MRISthresholdCurvature(MRI_SURFACE *mris, float thresh, int use_abs) +{ int vno; VERTEX *v; float val; @@ -69909,7 +71363,8 @@ int MRISthresholdCurvature(MRI_SURFACE *mris, float thresh, int use_abs) { return (NO_ERROR); } -int MRISthresholdValIntoMarked(MRI_SURFACE *mris, float thresh) { +int MRISthresholdValIntoMarked(MRI_SURFACE *mris, float thresh) +{ int vno; VERTEX *v; @@ -69925,7 +71380,8 @@ int MRISthresholdValIntoMarked(MRI_SURFACE *mris, float thresh) { } // remove outliers in the v->curv field -int MRIShistoThresholdCurvature(MRI_SURFACE *mris, float thresh_pct) { +int MRIShistoThresholdCurvature(MRI_SURFACE *mris, float thresh_pct) +{ double min_curv, max_curv, curv_scale, total, thresh; int bin, zbin, nthresh = 0, vno; HISTOGRAM *h_curv; @@ -70030,7 +71486,8 @@ int MRIShistoThresholdCurvature(MRI_SURFACE *mris, float thresh_pct) { return (NO_ERROR); } -static int mrisComputeVariableSmoothnessCoefficients(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeVariableSmoothnessCoefficients(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ VERTEX *v; int vno; float vsmooth; @@ -70063,7 +71520,8 @@ static int mrisComputeVariableSmoothnessCoefficients(MRI_SURFACE *mris, INTEGRAT vsmooth = parms->vsmoothness[vno]; if (v->val > 0) { vsmooth += VDELTA; - } else { + } + else { vsmooth -= VDELTA; } vsmooth = MAX(0, vsmooth); @@ -70076,13 +71534,15 @@ static int mrisComputeVariableSmoothnessCoefficients(MRI_SURFACE *mris, INTEGRAT // sets the RAS for a surface // FUNDAMENTAL ASSUMPTION - all the vertices are created in voxel coordinates associated with srcMri -void MRISsetVolumeForSurface(MRI_SURFACE *mris, MRI *srcMri) { +void MRISsetVolumeForSurface(MRI_SURFACE *mris, MRI *srcMri) +{ MRIScopyVolGeomFromMRI(mris, srcMri); MATRIX *matrix = surfaceRASFromVoxel_(srcMri); MRISmatrixMultiply(mris, matrix); MatrixFree(&matrix); } -int MRISsetVal2(MRI_SURFACE *mris, float val) { +int MRISsetVal2(MRI_SURFACE *mris, float val) +{ VERTEX *v; int vno; @@ -70096,12 +71556,14 @@ int MRISsetVal2(MRI_SURFACE *mris, float val) { return (NO_ERROR); } -MRI *MRIScomputeDistanceToSurface(MRI_SURFACE *mris, MRI *mri_dist, float resolution) { +MRI *MRIScomputeDistanceToSurface(MRI_SURFACE *mris, MRI *mri_dist, float resolution) +{ MRI *mri_tmp, *mri_mask; if (mri_dist != NULL) { mri_tmp = MRIclone(mri_dist, NULL); - } else { + } + else { mri_tmp = NULL; // will get allocated by MRISfillInterior } mri_tmp = MRISfillInterior(mris, resolution, mri_tmp); @@ -70109,7 +71571,8 @@ MRI *MRIScomputeDistanceToSurface(MRI_SURFACE *mris, MRI *mri_dist, float resolu #define PAD 10 if (mri_dist == NULL) { mri_mask = MRIextractRegionAndPad(mri_tmp, NULL, NULL, PAD); - } else { + } + else { mri_mask = MRIcopy(mri_tmp, NULL); // geometry specified by caller } mri_dist = MRIdistanceTransform(mri_mask, mri_dist, 1, nint(PAD / mri_mask->xsize), DTRANS_MODE_SIGNED, NULL); @@ -70118,7 +71581,8 @@ MRI *MRIScomputeDistanceToSurface(MRI_SURFACE *mris, MRI *mri_dist, float resolu MRIfree(&mri_mask); return (mri_dist); } -int MRISclearMark2s(MRI_SURFACE *mris) { +int MRISclearMark2s(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -70134,7 +71598,8 @@ int MRISclearMark2s(MRI_SURFACE *mris) { // Discrete Principle Curvature and Related vvvvvvvvvvvvvvvvvv -int slprints(char *apch_txt) { +int slprints(char *apch_txt) +{ // // PRECONDITIONS // o String to print to stdout @@ -70166,7 +71631,8 @@ int slprints(char *apch_txt) { return strlen(pch_output); } -void cprints(char *apch_left, char *apch_right) { +void cprints(char *apch_left, char *apch_right) +{ // // PRECONDITIONS // o The length of each text string should be such that @@ -70189,7 +71655,8 @@ void cprints(char *apch_left, char *apch_right) { fflush(stderr); } -void cprintd(char *apch_left, int a_right) { +void cprintd(char *apch_left, int a_right) +{ // // PRECONDITIONS // o The length of each text string should be such that @@ -70205,14 +71672,16 @@ void cprintd(char *apch_left, int a_right) { sprintf(pch_right, " [ %d ]\n", a_right); if (strlen(apch_left)) { fprintf(stderr, "%*s", G_LC, apch_left); - } else { + } + else { fprintf(stderr, "%*s", G_LC, " "); } fprintf(stderr, "%*s", G_RC, pch_right); fflush(stderr); } -void cprintf(char *apch_left, float af_right) { +void cprintf(char *apch_left, float af_right) +{ // // PRECONDITIONS // o The length of each text string should be such that @@ -70228,14 +71697,16 @@ void cprintf(char *apch_left, float af_right) { sprintf(pch_right, " [ %f ]\n", af_right); if (strlen(apch_left)) { fprintf(stderr, "%*s", G_LC, apch_left); - } else { + } + else { fprintf(stderr, "%*s", G_LC, " "); } fprintf(stderr, "%*s", G_RC, pch_right); fflush(stderr); } -short FACE_vertexIndex_find(FACE *pFace, int avertex) { +short FACE_vertexIndex_find(FACE *pFace, int avertex) +{ // // PRECONDITIONS // o denotes a vertex number to lookup in the . @@ -70253,7 +71724,8 @@ short FACE_vertexIndex_find(FACE *pFace, int avertex) { return ret; } -short VECTOR_elementIndex_findNotEqual(VECTOR *apV, float af_searchTerm) { +short VECTOR_elementIndex_findNotEqual(VECTOR *apV, float af_searchTerm) +{ // // PRECONDITIONS // o The is a column vector. @@ -70276,7 +71748,8 @@ short VECTOR_elementIndex_findNotEqual(VECTOR *apV, float af_searchTerm) { return b_ret; } -short VECTOR_elementIndex_find(VECTOR *apV, float af_searchTerm) { +short VECTOR_elementIndex_find(VECTOR *apV, float af_searchTerm) +{ // // PRECONDITIONS // o The is a column vector. @@ -70299,7 +71772,8 @@ short VECTOR_elementIndex_find(VECTOR *apV, float af_searchTerm) { return b_ret; } -short MRIS_vertexProgress_print(MRIS *apmris, int avertex, char *apch_message) { +short MRIS_vertexProgress_print(MRIS *apmris, int avertex, char *apch_message) +{ // // PRECONDITIONS // o is the current vertex being processed in a stream. @@ -70334,7 +71808,8 @@ short MRIS_vertexProgress_print(MRIS *apmris, int avertex, char *apch_message) { return 1; } -int FACE_vertexIndexAtMask_find(FACE *apFACE_I, VECTOR *apv_verticesCommon) { +int FACE_vertexIndexAtMask_find(FACE *apFACE_I, VECTOR *apv_verticesCommon) +{ // // PRECONDITIONS // o Called after has been processed by @@ -70369,7 +71844,8 @@ int FACE_vertexIndexAtMask_find(FACE *apFACE_I, VECTOR *apv_verticesCommon) { return ret; } -short VERTICES_commonInFaces_find(FACE *apFACE_I, FACE *apFACE_J, VECTOR *apv_verticesCommon) { +short VERTICES_commonInFaces_find(FACE *apFACE_I, FACE *apFACE_J, VECTOR *apv_verticesCommon) +{ // // PRECONDITIONS // o The s must be triangles with 3 vertices each. @@ -70417,7 +71893,8 @@ short VERTICES_commonInFaces_find(FACE *apFACE_I, FACE *apFACE_J, VECTOR *apv_ve return k; } -short FACES_Hcurvature_determineSign(MRIS *apmris, FACE *apFACE_O, FACE *apFACE_I) { +short FACES_Hcurvature_determineSign(MRIS *apmris, FACE *apFACE_O, FACE *apFACE_I) +{ // // PRECONDITIONS // o Typically called from MRIS_Hcurvature_determineSign() @@ -70489,7 +71966,8 @@ short FACES_Hcurvature_determineSign(MRIS *apmris, FACE *apFACE_O, FACE *apFACE_ if (sign == 1) { f_distNormal = V3_LEN(pv_connectOI); - } else { + } + else { f_distAntiNormal = V3_LEN(pv_connectOI); } } @@ -70508,7 +71986,8 @@ short FACES_Hcurvature_determineSign(MRIS *apmris, FACE *apFACE_O, FACE *apFACE_ return ret; } -int VERTEX_faceAngles_determine(MRIS *apmris, int avertex, VECTOR *apv_angle) { +int VERTEX_faceAngles_determine(MRIS *apmris, int avertex, VECTOR *apv_angle) +{ // // PRECONDITIONS // o is a valid surface. @@ -70587,7 +72066,8 @@ int VERTEX_faceAngles_determine(MRIS *apmris, int avertex, VECTOR *apv_angle) { } int VERTEX_faceMinMaxAngles_determine( - MRIS *apmris, int avertex, int *ap_minIndex, float *apf_minAngle, int *ap_maxIndex, float *apf_maxAngle) { + MRIS *apmris, int avertex, int *ap_minIndex, float *apf_minAngle, int *ap_maxIndex, float *apf_maxAngle) +{ // // PRECONDITIONS // o is a valid surface. @@ -70640,7 +72120,8 @@ int VERTEX_faceMinMaxAngles_determine( return face; } -int signum_eval(float af) { +int signum_eval(float af) +{ // // PRECONDITIONS // o is an input float. @@ -70652,7 +72133,8 @@ int signum_eval(float af) { return af < 0 ? -1 : 1; } -int MRIS_Hcurvature_determineSign(MRIS *apmris) { +int MRIS_Hcurvature_determineSign(MRIS *apmris) +{ // // NOTE // This function is obsolete and should not be used! Mean curvature (H) @@ -70702,7 +72184,8 @@ int MRIS_Hcurvature_determineSign(MRIS *apmris) { return ret; } -int MRIS_facesAtVertices_reorder(MRIS *apmris) { +int MRIS_facesAtVertices_reorder(MRIS *apmris) +{ // // PRECONDITIONS // o is a valid surface. @@ -70760,7 +72243,8 @@ int MRIS_facesAtVertices_reorder(MRIS *apmris) { return ret; } -int MRIScomputeGeometricProperties(MRIS *apmris) { +int MRIScomputeGeometricProperties(MRIS *apmris) +{ // // PRECONDITIONS // o Needs to be called before computing discrete curvatures. @@ -70780,7 +72264,8 @@ int MRIScomputeGeometricProperties(MRIS *apmris) { return ret; } -short FACES_aroundVertex_reorder(MRIS *apmris, int avertex, VECTOR *pv_geometricOrder) { +short FACES_aroundVertex_reorder(MRIS *apmris, int avertex, VECTOR *pv_geometricOrder) +{ // // PRECONDITIONS // o is a valid vertex on the surface. @@ -70872,7 +72357,8 @@ short FACES_aroundVertex_reorder(MRIS *apmris, int avertex, VECTOR *pv_geometric return 1; } -float FACES_angleNormal_find(MRIS *apmris, FACE *apFACE_I, FACE *apFACE_J) { +float FACES_angleNormal_find(MRIS *apmris, FACE *apFACE_I, FACE *apFACE_J) +{ // // PRECONDITIONS // o The s should be triangles with 3 vertices each. @@ -70929,7 +72415,8 @@ float FACES_angleNormal_find(MRIS *apmris, FACE *apFACE_I, FACE *apFACE_J) { return f_angleNormalIJ; } -float FACES_commonEdgeLength_find(MRIS *apmris, FACE *apFACE_I, FACE *apFACE_J) { +float FACES_commonEdgeLength_find(MRIS *apmris, FACE *apFACE_I, FACE *apFACE_J) +{ // // PRECONDITIONS // o The s should be triangles with 3 vertices each. @@ -70978,7 +72465,8 @@ float FACES_commonEdgeLength_find(MRIS *apmris, FACE *apFACE_I, FACE *apFACE_J) return (f_edgeLength); } -short MRIS_discreteKH_compute(MRIS *apmris) { +short MRIS_discreteKH_compute(MRIS *apmris) +{ // // PRECONDITIONS // o A valid SURFACE with computed triangle properties. @@ -71080,7 +72568,8 @@ short MRIS_discreteKH_compute(MRIS *apmris) { return (NO_ERROR); } -short MRIS_discretek1k2_compute(MRIS *apmris, short ab_signedPrinciples) { +short MRIS_discretek1k2_compute(MRIS *apmris, short ab_signedPrinciples) +{ // // PRECONDITIONS // o A valid SURFACE with computed triangle properties. @@ -71123,7 +72612,8 @@ short MRIS_discretek1k2_compute(MRIS *apmris, short ab_signedPrinciples) { if (!ab_signedPrinciples) { f_k1 = fabs(f_A) >= fabs(f_B) ? f_A : f_B; f_k2 = fabs(f_A) <= fabs(f_B) ? f_A : f_B; - } else { + } + else { f_k1 = f_A >= f_B ? f_A : f_B; f_k2 = f_A <= f_B ? f_A : f_B; } @@ -71136,7 +72626,8 @@ short MRIS_discretek1k2_compute(MRIS *apmris, short ab_signedPrinciples) { return (NO_ERROR); } -short MRIScomputeSecondFundamentalFormDiscrete(MRIS *apmris, short ab_signedPrinciples) { +short MRIScomputeSecondFundamentalFormDiscrete(MRIS *apmris, short ab_signedPrinciples) +{ int retKH, retk1k2; retKH = 1; @@ -71149,7 +72640,8 @@ short MRIScomputeSecondFundamentalFormDiscrete(MRIS *apmris, short ab_signedPrin return (retKH | retk1k2); } -int MRISscaleCurvature(MRI_SURFACE *apmris, float af_scale) { +int MRISscaleCurvature(MRI_SURFACE *apmris, float af_scale) +{ // // POSTCONDITIONS // o Each curvature value in apmris is scaled by: @@ -71186,8 +72678,8 @@ int MRISscaleCurvature(MRI_SURFACE *apmris, float af_scale) { // Discrete Principle Curvature and Related ^^^^^^^^^^^^^^^^^^ -int MRISsurfaceRASToVoxel( - MRI_SURFACE *mris, MRI *mri, double r, double a, double s, double *px, double *py, double *pz) { +int MRISsurfaceRASToVoxel(MRI_SURFACE *mris, MRI *mri, double r, double a, double s, double *px, double *py, double *pz) +{ MATRIX *m_sras2vox = NULL; MATRIX *m_sras2ras, *m_ras2vox; MRI *mri_tmp; @@ -71214,7 +72706,8 @@ int MRISsurfaceRASToVoxel( MRIcopyVolGeomToMRI(mri_tmp, &mris->vg); m_sras2ras = RASFromSurfaceRAS_(mri_tmp); MRIfree(&mri_tmp); - } else // no valid geom - assume it came from provided volume + } + else // no valid geom - assume it came from provided volume { m_sras2ras = RASFromSurfaceRAS_(mri); } @@ -71249,7 +72742,8 @@ int MRISsurfaceRASToVoxel( \param px, py, pz - pointers to col, rowl, and slice in mri (output) */ int MRISsurfaceRASToVoxelCached( - MRI_SURFACE *mris, MRI *mri, double r, double a, double s, double *px, double *py, double *pz) { + MRI_SURFACE *mris, MRI *mri, double r, double a, double s, double *px, double *py, double *pz) +{ static VECTOR *v1[_MAX_FS_THREADS] = {NULL}; static VECTOR *v2[_MAX_FS_THREADS] = {NULL}; @@ -71294,7 +72788,8 @@ int MRISsurfaceRASToVoxelCached( MRIcopyVolGeomToMRI(mri_tmp, &mris->vg); m_sras2ras = RASFromSurfaceRAS_(mri_tmp); MRIfree(&mri_tmp); - } else { + } + else { // Use geometry from MRI struct passed with function // Function should reduce to inv(Vox2TkRegRAS)*SurfRAS m_sras2ras = RASFromSurfaceRAS_(mri); @@ -71319,7 +72814,8 @@ int MRISsurfaceRASToVoxelCached( } int MRISsurfaceRASFromVoxel( - MRI_SURFACE *mris, MRI *mri, double x, double y, double z, double *pr, double *pa, double *ps) { + MRI_SURFACE *mris, MRI *mri, double x, double y, double z, double *pr, double *pa, double *ps) +{ MATRIX *m_sras2vox = NULL; MATRIX *m_vox2sras = NULL; MATRIX *m_sras2ras, *m_ras2vox; @@ -71347,7 +72843,8 @@ int MRISsurfaceRASFromVoxel( MRIcopyVolGeomToMRI(mri_tmp, &mris->vg); m_sras2ras = RASFromSurfaceRAS_(mri_tmp); MRIfree(&mri_tmp); - } else // no valid geom - assume it came from provided volume + } + else // no valid geom - assume it came from provided volume { m_sras2ras = RASFromSurfaceRAS_(mri); } @@ -71372,7 +72869,8 @@ int MRISsurfaceRASFromVoxel( } int MRISsurfaceRASFromVoxelCached( - MRI_SURFACE *mris, MRI *mri, double x, double y, double z, double *pr, double *pa, double *ps) { + MRI_SURFACE *mris, MRI *mri, double x, double y, double z, double *pr, double *pa, double *ps) +{ static MATRIX *m_vox2sras[_MAX_FS_THREADS] = {NULL}; static VECTOR *v1[_MAX_FS_THREADS] = {NULL}; static VECTOR *v2[_MAX_FS_THREADS] = {NULL}; @@ -71394,7 +72892,8 @@ int MRISsurfaceRASFromVoxelCached( MRIcopyVolGeomToMRI(mri_tmp, &mris->vg); m_sras2ras = RASFromSurfaceRAS_(mri_tmp); MRIfree(&mri_tmp); - } else { + } + else { m_sras2ras = RASFromSurfaceRAS_(mri); } @@ -71427,7 +72926,8 @@ int MRISsurfaceRASFromVoxelCached( Description ------------------------------------------------------*/ -int MRIScomputeNormal(MRIS *mris, int which, int vno, double *pnx, double *pny, double *pnz) { +int MRIScomputeNormal(MRIS *mris, int which, int vno, double *pnx, double *pny, double *pnz) +{ float snorm[3], norm[3]; VERTEX *v; int n, num; @@ -71472,7 +72972,8 @@ int MRIScomputeNormal(MRIS *mris, int which, int vno, double *pnx, double *pny, return (NO_ERROR); } -static double mrisComputeSurfaceRepulsionEnergy(MRI_SURFACE *mris, double l_repulse, MHT *mht) { +static double mrisComputeSurfaceRepulsionEnergy(MRI_SURFACE *mris, double l_repulse, MHT *mht) +{ int vno, max_vno, i; float dx, dy, dz, x, y, z, sx, sy, sz, norm[3], dot; float max_scale, max_dot; @@ -71525,7 +73026,8 @@ static double mrisComputeSurfaceRepulsionEnergy(MRI_SURFACE *mris, double l_repu } if (dot > MAX_NEG_RATIO) { dot = MAX_NEG_RATIO; - } else if (dot < -MAX_NEG_RATIO) { + } + else if (dot < -MAX_NEG_RATIO) { dot = -MAX_NEG_RATIO; } #if 0 @@ -71551,7 +73053,8 @@ static double mrisComputeSurfaceRepulsionEnergy(MRI_SURFACE *mris, double l_repu // average the stats on the surface, and propagate marks // outwards to new non-zero locations -int MRISaverageMarkedStats(MRI_SURFACE *mris, int navgs) { +int MRISaverageMarkedStats(MRI_SURFACE *mris, int navgs) +{ int i, vno, vnb, *pnb, vnum; float val, num; VERTEX *v, *vn; @@ -71599,7 +73102,8 @@ int MRISaverageMarkedStats(MRI_SURFACE *mris, int navgs) { return (NO_ERROR); } -void UpdateMRIS(MRI_SURFACE *mris, const char *fname) { +void UpdateMRIS(MRI_SURFACE *mris, const char *fname) +{ mrisFindNeighbors(mris); mrisComputeVertexDistances(mris); if (fname) { @@ -71617,7 +73121,8 @@ void UpdateMRIS(MRI_SURFACE *mris, const char *fname) { */ #include "MARS_DT_Boundary.h" -int MRISdistanceTransform(MRI_SURFACE *mris, LABEL *area, int mode) { +int MRISdistanceTransform(MRI_SURFACE *mris, LABEL *area, int mode) +{ int *vertices, *vertNbrs, vno, max_nbrs, j, index; double *cost, *vertDists; VERTEX *v; @@ -71735,7 +73240,8 @@ int MRISdistanceTransform(MRI_SURFACE *mris, LABEL *area, int mode) { assumes v->val has the distances for label1 and v->val2 has the distances for label 2, computed using MRISdistanceTransform */ -double MRIScomputeHausdorffDistance(MRI_SURFACE *mris, int mode) { +double MRIScomputeHausdorffDistance(MRI_SURFACE *mris, int mode) +{ double hdist = 0, d, dist; int vno, n, num; VERTEX *v, *vn; @@ -71762,7 +73268,8 @@ double MRIScomputeHausdorffDistance(MRI_SURFACE *mris, int mode) { if (vn->val < 0) { dist = -vn->val / (-vn->val + v->val); // fraction of way dist = 1 - dist; // measure from v not vn - } else { + } + else { dist = -v->val / (-v->val + vn->val); // fraction of way } d = dist * fabs(v->val2) + (1 - dist) * fabs(vn->val2); // compute val2 at this point @@ -71777,7 +73284,8 @@ double MRIScomputeHausdorffDistance(MRI_SURFACE *mris, int mode) { if (vn->val2 < 0) { dist = -vn->val2 / (-vn->val2 + v->val2); // fraction of way dist = 1 - dist; // measure from v not vn - } else { + } + else { dist = -v->val2 / (-v->val2 + vn->val2); // fraction of way } num++; @@ -71793,7 +73301,8 @@ double MRIScomputeHausdorffDistance(MRI_SURFACE *mris, int mode) { return (hdist); } -int MRIScomputeAllDistances(MRI_SURFACE *mris) { +int MRIScomputeAllDistances(MRI_SURFACE *mris) +{ int vno, done = 0, nvalid; LABEL *area; @@ -71881,7 +73390,8 @@ int MRIScomputeAllDistances(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISsetValues(MRI_SURFACE *mris, float val) { +int MRISsetValues(MRI_SURFACE *mris, float val) +{ int vno; VERTEX *v; @@ -71894,7 +73404,8 @@ int MRISsetValues(MRI_SURFACE *mris, float val) { } return (NO_ERROR); } -int MRISaddToValues(MRI_SURFACE *mris, float val) { +int MRISaddToValues(MRI_SURFACE *mris, float val) +{ int vno; VERTEX *v; @@ -71908,7 +73419,8 @@ int MRISaddToValues(MRI_SURFACE *mris, float val) { return (NO_ERROR); } -LABEL *MRISannotation_to_label(MRI_SURFACE *mris, int annot_index) { +LABEL *MRISannotation_to_label(MRI_SURFACE *mris, int annot_index) +{ int vno, nv, annot; VERTEX *v; LABEL *area; @@ -71941,7 +73453,8 @@ LABEL *MRISannotation_to_label(MRI_SURFACE *mris, int annot_index) { return (area); } #include "histo.h" -HISTOGRAM *MRISgetHistogram(MRI_SURFACE *mris, int nbins, int field) { +HISTOGRAM *MRISgetHistogram(MRI_SURFACE *mris, int nbins, int field) +{ int vno, bin; VERTEX *v; double fmin, fmax, bin_size, val; @@ -71998,7 +73511,8 @@ HISTOGRAM *MRISgetHistogram(MRI_SURFACE *mris, int nbins, int field) { h = HISTOalloc(nbins); if (fmax == fmin) { bin_size = 1; - } else { + } + else { bin_size = (fmax - fmin) / ((float)h->nbins - 1); } h->bin_size = bin_size; @@ -72051,7 +73565,8 @@ HISTOGRAM *MRISgetHistogram(MRI_SURFACE *mris, int nbins, int field) { #include "mrishash.h" #define MAX_DIST 10 -int MRISmeasureDistanceBetweenSurfaces(MRI_SURFACE *mris, MRI_SURFACE *mris2, int signed_dist) { +int MRISmeasureDistanceBetweenSurfaces(MRI_SURFACE *mris, MRI_SURFACE *mris2, int signed_dist) +{ int vno; VERTEX *v1, *v2; MRIS_HASH_TABLE *mht; @@ -72087,7 +73602,8 @@ int MRISmeasureDistanceBetweenSurfaces(MRI_SURFACE *mris, MRI_SURFACE *mris2, in return (NO_ERROR); } -int MRISwriteCoordsToIco(MRI_SURFACE *mris, MRI_SURFACE *mris_ico, int which_vertices) { +int MRISwriteCoordsToIco(MRI_SURFACE *mris, MRI_SURFACE *mris_ico, int which_vertices) +{ MHT *mht; int vno, fno, debug; VERTEX *v; @@ -72131,7 +73647,8 @@ int MRISwriteCoordsToIco(MRI_SURFACE *mris, MRI_SURFACE *mris_ico, int which_ver return (NO_ERROR); } -int MRISvertexCoord2XYZ_float(VERTEX *v, int which, float *x, float *y, float *z) { +int MRISvertexCoord2XYZ_float(VERTEX *v, int which, float *x, float *y, float *z) +{ switch (which) { case ORIGINAL_VERTICES: *x = v->origx; @@ -72200,7 +73717,8 @@ int MRISvertexCoord2XYZ_float(VERTEX *v, int which, float *x, float *y, float *z } return (NO_ERROR); } -int MRISvertexCoord2XYZ_double(VERTEX *v, int which, double *x, double *y, double *z) { +int MRISvertexCoord2XYZ_double(VERTEX *v, int which, double *x, double *y, double *z) +{ switch (which) { default: case GOOD_VERTICES: @@ -72255,7 +73773,8 @@ int MRISvertexCoord2XYZ_double(VERTEX *v, int which, double *x, double *y, doubl return (NO_ERROR); } int MRISsampleFaceCoordsCanonical( - MHT *mht, MRI_SURFACE *mris, float x, float y, float z, int which, float *px, float *py, float *pz) { + MHT *mht, MRI_SURFACE *mris, float x, float y, float z, int which, float *px, float *py, float *pz) +{ float xv, yv, zv; double lambda[3], fdist, norm; int n, ret = NO_ERROR, fno; @@ -72275,7 +73794,8 @@ int MRISsampleFaceCoordsCanonical( DiagBreak(); MHTfindClosestFaceGeneric(mht, mris, x, y, z, 1000, -1, -1, &face, &fno, &fdist); lambda[0] = lambda[1] = lambda[2] = 1.0 / 3.0; - } else { + } + else { ret = face_barycentric_coords(mris, fno, CANONICAL_VERTICES, x, y, z, &lambda[0], &lambda[1], &lambda[2]); } @@ -72293,7 +73813,8 @@ int MRISsampleFaceCoordsCanonical( #if 1 static int mris_project_point_into_face( - MRI_SURFACE *mris, FACE *face, int which, double x, double y, double z, double *px, double *py, double *pz) { + MRI_SURFACE *mris, FACE *face, int which, double x, double y, double z, double *px, double *py, double *pz) +{ double point[3], V0[3], V1[3], V2[3], proj[3]; point[0] = x; @@ -72366,7 +73887,8 @@ int face_barycentric_coords(MRI_SURFACE *mris, double cz, double *pl1, double *pl2, - double *pl3) { + double *pl3) +{ double l1, l2, l3, x, y, x1, x2, x3, y1, y2, y3, e1[3], e2[3]; FACE *face = &mris->faces[fno]; double V0[3], V1[3], V2[3], point[3], proj[3], detT; @@ -72459,7 +73981,8 @@ int face_barycentric_coords(MRI_SURFACE *mris, if (l1 > 0 && l1 < 1 && l2 > 0 && l2 < 1 && l3 > 0 && l3 < 1) { ret = 1; // interior to the triangle - } else { + } + else { float l1d, l2d, l3d; l1d = MIN(l1 - 0, 1 - l1); @@ -72467,7 +73990,8 @@ int face_barycentric_coords(MRI_SURFACE *mris, l3d = MIN(l3 - 0, 1 - l3); if ((l1d < 0 && !FZERO(l1d)) || (l2d < 0 && !FZERO(l2d)) || (l3d < 0 && !FZERO(l3d))) { ret = -1; // outside triangle - } else { + } + else { ret = 0; // on boundary of triangle } } @@ -72483,7 +74007,8 @@ int MRISsampleFaceCoords(MRI_SURFACE *mris, int which_barycentric, float *px, float *py, - float *pz) { + float *pz) +{ float xv, yv, zv; double lambda[3]; int n, ret; @@ -72510,7 +74035,8 @@ int MRISsampleFaceCoords(MRI_SURFACE *mris, return (ret); } double MRISsampleFace( - MRI_SURFACE *mris, int fno, int which, double x, double y, double z, double val0, double val1, double val2) { + MRI_SURFACE *mris, int fno, int which, double x, double y, double z, double val0, double val1, double val2) +{ float xv, yv, zv; double lambda[3], val; int n, ret; @@ -72542,7 +74068,8 @@ double MRISsampleFace( return (val); } -int MRISsampleFaceNormal(MRI_SURFACE *mris, int fno, double x, double y, double z, float *px, float *py, float *pz) { +int MRISsampleFaceNormal(MRI_SURFACE *mris, int fno, double x, double y, double z, float *px, float *py, float *pz) +{ float d, dtotal, dx, dy, dz, xc, yc, zc; int n; FACE *face; @@ -72592,7 +74119,8 @@ int MRISsampleFaceNormal(MRI_SURFACE *mris, int fno, double x, double y, double will be replaced with the new ones computed by this function. */ -int MRISminimizeThicknessFunctional(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, float max_thick) { +int MRISminimizeThicknessFunctional(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, float max_thick) +{ int vno, navgs = 5; VERTEX *v; double ending_sse, vsize; @@ -72636,7 +74164,8 @@ int MRISminimizeThicknessFunctional(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, if (!parms->fp) { if (!parms->start_t) { parms->fp = fopen(fname, "w"); - } else { + } + else { parms->fp = fopen(fname, "a"); } @@ -72657,7 +74186,8 @@ int MRISminimizeThicknessFunctional(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, if (parms->start_t == 0) // && parms->remove_neg == 0 { MRISfindClosestPialVerticesCanonicalCoords(mris, mris->nsize); - } else + } + else #endif MRISrestoreVertexPositions(mris, CANONICAL_VERTICES); // start with pial coord of this vtx mris->status = MRIS_SPHERE; @@ -72708,7 +74238,8 @@ int MRISminimizeThicknessFunctional(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, return (NO_ERROR); } -MRI *MRISlaplacian(MRI_SURFACE *mris, MRI *mri_cmatrix, double inner_width, double outer_width) { +MRI *MRISlaplacian(MRI_SURFACE *mris, MRI *mri_cmatrix, double inner_width, double outer_width) +{ int vno, vno2, i, num, n; VERTEX *v, *vn; MRI *mri_laplacian; @@ -72742,7 +74273,8 @@ MRI *MRISlaplacian(MRI_SURFACE *mris, MRI *mri_cmatrix, double inner_width, doub return (mri_laplacian); } -double MRISsampleValue(MRI_SURFACE *mris, FACE *f, double xp, double yp, double zp, int which, MRI *mri_vals) { +double MRISsampleValue(MRI_SURFACE *mris, FACE *f, double xp, double yp, double zp, int which, MRI *mri_vals) +{ double val, x[VERTICES_PER_FACE], y[VERTICES_PER_FACE], dx1, dy1, dx2, dy2, e1x, e1y, e1z, e2x, e2y, e2z, x0, y0, a0, a1, a2, val0, val1, val2; int n; @@ -72797,7 +74329,8 @@ double MRISsampleValue(MRI_SURFACE *mris, FACE *f, double xp, double yp, double } #ifdef FS_CUDA -static INTEGRATION_PARMS *mrisCloneIP(INTEGRATION_PARMS *parms) { +static INTEGRATION_PARMS *mrisCloneIP(INTEGRATION_PARMS *parms) +{ /* this needs some work to check whether this is successful */ INTEGRATION_PARMS *rval = malloc(sizeof(INTEGRATION_PARMS)); @@ -72805,14 +74338,16 @@ static INTEGRATION_PARMS *mrisCloneIP(INTEGRATION_PARMS *parms) { return rval; } -static void mrisDeleteIP(INTEGRATION_PARMS *parms) { +static void mrisDeleteIP(INTEGRATION_PARMS *parms) +{ if (parms != NULL) { free(parms); } } #endif /* FS_CUDA */ -int MRIScomputeSurfaceNormals(MRI_SURFACE *mris, int which, int navgs) { +int MRIScomputeSurfaceNormals(MRI_SURFACE *mris, int which, int navgs) +{ int vno, n, i; VERTEX *v, *vn; double nx = 0.0, ny = 0.0, nz = 0.0, norm = 0.0; @@ -72957,7 +74492,8 @@ int MRIScomputeSurfaceNormals(MRI_SURFACE *mris, int which, int navgs) { return (NO_ERROR); } -static double mrisRmsDistanceError(MRI_SURFACE *mris) { +static double mrisRmsDistanceError(MRI_SURFACE *mris) +{ INTEGRATION_PARMS parms; double rms; @@ -72966,7 +74502,8 @@ static double mrisRmsDistanceError(MRI_SURFACE *mris) { rms = mrisComputeTargetLocationError(mris, &parms); return (sqrt(rms / MRISvalidVertices(mris))); } -int MRISscaleVertexCoordinates(MRI_SURFACE *mris, double scale) { +int MRISscaleVertexCoordinates(MRI_SURFACE *mris, double scale) +{ VERTEX *v; int vno; @@ -72981,7 +74518,8 @@ int MRISscaleVertexCoordinates(MRI_SURFACE *mris, double scale) { } return (NO_ERROR); } -int MRISstoreTangentPlanes(MRI_SURFACE *mris, int which_vertices) { +int MRISstoreTangentPlanes(MRI_SURFACE *mris, int which_vertices) +{ VERTEX *v; int vno; @@ -73000,7 +74538,8 @@ int MRISstoreTangentPlanes(MRI_SURFACE *mris, int which_vertices) { return (NO_ERROR); } int MRISrepositionSurface( - MRI_SURFACE *mris, MRI *mri, int *target_vnos, float *target_vals, int nv, int nsize, double sigma, int flags) { + MRI_SURFACE *mris, MRI *mri, int *target_vnos, float *target_vals, int nv, int nsize, double sigma, int flags) +{ int vno, n; INTEGRATION_PARMS parms; VERTEX *v; @@ -73026,7 +74565,8 @@ int MRISrepositionSurface( if (flags & IPFLAG_FORCE_GRADIENT_IN) { parms.grad_dir = -1; printf("forcing gradient in\n"); - } else if (flags & IPFLAG_FORCE_GRADIENT_IN) { + } + else if (flags & IPFLAG_FORCE_GRADIENT_IN) { parms.grad_dir = 1; printf("forcing gradient out\n"); } @@ -73067,7 +74607,8 @@ int MRISrepositionSurface( return (NO_ERROR); } int MRISrepositionSurfaceToCoordinate( - MRI_SURFACE *mris, MRI *mri, int target_vno, float tx, float ty, float tz, int nsize, double sigma, int flags) { + MRI_SURFACE *mris, MRI *mri, int target_vno, float tx, float ty, float tz, int nsize, double sigma, int flags) +{ int vno; INTEGRATION_PARMS parms; VERTEX *v; @@ -73154,7 +74695,8 @@ int MRISrepositionSurfaceToCoordinate( return (NO_ERROR); } -static int mrisProjectOntoSurface(MRI_SURFACE *mris, int which_vertices) { +static int mrisProjectOntoSurface(MRI_SURFACE *mris, int which_vertices) +{ int vno, fno; double px, py, pz, fdist; FACE *face; @@ -73189,7 +74731,8 @@ static int mrisProjectOntoSurface(MRI_SURFACE *mris, int which_vertices) { norm = VLEN(lambda); if (FZERO(norm)) { lambda[0] = 1.0; // arbitrary choice to handle pathological case - } else { + } + else { SCALAR_MUL(lambda, 1.0 / norm, lambda); } lambda[2] = 1 - (lambda[0] + lambda[1]); @@ -73214,7 +74757,8 @@ static int mrisProjectOntoSurface(MRI_SURFACE *mris, int which_vertices) { if (vno == Gdiag_no) { printf("v %d: lambda = (%2.2f %2.2f %2.2f)\n", vno, lambda[0], lambda[1], lambda[2]); } - } else { + } + else { mris_project_point_into_face(mris, face, which_vertices, v->x, v->y, v->z, &px, &py, &pz); } @@ -73241,7 +74785,8 @@ static int mrisProjectOntoSurface(MRI_SURFACE *mris, int which_vertices) { return (NO_ERROR); } -int MRISlogOdds(MRI_SURFACE *mris, LABEL *area, double slope) { +int MRISlogOdds(MRI_SURFACE *mris, LABEL *area, double slope) +{ int vno; VERTEX *v; double p; @@ -73264,7 +74809,8 @@ int MRISlogOdds(MRI_SURFACE *mris, LABEL *area, double slope) { } return (NO_ERROR); } -int MRISextractVertexCoords(MRI_SURFACE *mris, float *locations[3], int which) { +int MRISextractVertexCoords(MRI_SURFACE *mris, float *locations[3], int which) +{ int vno, nvertices; VERTEX *v; @@ -73335,7 +74881,8 @@ int MRISextractVertexCoords(MRI_SURFACE *mris, float *locations[3], int which) { return (NO_ERROR); } -int MRISimportVertexCoords(MRI_SURFACE *mris, float *locations[3], int which) { +int MRISimportVertexCoords(MRI_SURFACE *mris, float *locations[3], int which) +{ int vno, nvertices; VERTEX *v; @@ -73406,7 +74953,8 @@ int MRISimportVertexCoords(MRI_SURFACE *mris, float *locations[3], int which) { return (NO_ERROR); } -int MRIStrinarizeCurvature(MRI_SURFACE *mris, float trinarize_thresh) { +int MRIStrinarizeCurvature(MRI_SURFACE *mris, float trinarize_thresh) +{ int vno; VERTEX *v; @@ -73417,16 +74965,19 @@ int MRIStrinarizeCurvature(MRI_SURFACE *mris, float trinarize_thresh) { } if (v->curv < -trinarize_thresh) { v->curv = -1; - } else if (v->curv > trinarize_thresh) { + } + else if (v->curv > trinarize_thresh) { v->curv = 1; - } else { + } + else { v->curv = 0; } } return (NO_ERROR); } -int MRIScountTotalNeighbors(MRI_SURFACE *mris, int nsize) { +int MRIScountTotalNeighbors(MRI_SURFACE *mris, int nsize) +{ int vno, total_nbrs; VERTEX *v; @@ -73455,7 +75006,8 @@ int MRIScountTotalNeighbors(MRI_SURFACE *mris, int nsize) { return (total_nbrs); } -static int mrisScaleTimeStepByCurvature(MRI_SURFACE *mris) { +static int mrisScaleTimeStepByCurvature(MRI_SURFACE *mris) +{ int vno; VERTEX *v; float scale; @@ -73485,7 +75037,8 @@ static int mrisScaleTimeStepByCurvature(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScountMarked(MRI_SURFACE *mris, int mark_threshold) { +int MRIScountMarked(MRI_SURFACE *mris, int mark_threshold) +{ int vno, total_marked; VERTEX *v; @@ -73502,7 +75055,8 @@ int MRIScountMarked(MRI_SURFACE *mris, int mark_threshold) { return (total_marked); } -int MRISprintVertexStats(MRI_SURFACE *mris, int vno, FILE *fp, int which_vertices) { +int MRISprintVertexStats(MRI_SURFACE *mris, int vno, FILE *fp, int which_vertices) +{ double mn, d; int n, num; VERTEX *v, *vn; @@ -73539,7 +75093,8 @@ int MRISprintVertexStats(MRI_SURFACE *mris, int vno, FILE *fp, int which_vertice return (NO_ERROR); } -static int mrisCreateLikelihoodHistograms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisCreateLikelihoodHistograms(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int x, y, z, wlabel, plabel; VECTOR *v_brain, *v_hires; MATRIX *m_hires_to_brain; @@ -73581,7 +75136,8 @@ static int mrisCreateLikelihoodHistograms(MRI_SURFACE *mris, INTEGRATION_PARMS * zv = V3_Z(v_brain); if (MRIindexNotInVolume(parms->mri_brain, xv, yv, zv)) { val = 0; - } else { + } + else { MRIsampleVolume(parms->mri_brain, xv, yv, zv, &val); } @@ -73595,10 +75151,12 @@ static int mrisCreateLikelihoodHistograms(MRI_SURFACE *mris, INTEGRATION_PARMS * if (wlabel) { MRIsetVoxVal(parms->mri_labels, x, y, z, 0, MRI_WHITE_INTERIOR); HISTOaddSample(parms->h_wm, val, 0, 255); - } else if (plabel) { + } + else if (plabel) { MRIsetVoxVal(parms->mri_labels, x, y, z, 0, MRI_PIAL_INTERIOR); HISTOaddSample(parms->h_gm, val, 0, 255); - } else { + } + else { MRIsetVoxVal(parms->mri_labels, x, y, z, 0, MRI_NONBRAIN); HISTOaddSample(parms->h_nonbrain, val, 0, 255); } @@ -73614,7 +75172,8 @@ static int mrisCreateLikelihoodHistograms(MRI_SURFACE *mris, INTEGRATION_PARMS * MRIfree(&mri_pial); return (NO_ERROR); } -MRI_SURFACE *MRISconcat(MRI_SURFACE *mris1, MRI_SURFACE *mris2, MRI_SURFACE *mris) { +MRI_SURFACE *MRISconcat(MRI_SURFACE *mris1, MRI_SURFACE *mris2, MRI_SURFACE *mris) +{ int vno, n; int fno; VERTEX *v, *vo; @@ -73676,7 +75235,8 @@ MRI_SURFACE *MRISconcat(MRI_SURFACE *mris1, MRI_SURFACE *mris2, MRI_SURFACE *mri #define GM_VAL 2 #define CSF_VAL 3 -MRI *MRIcomputeLaminarVolumeFractions(MRI_SURFACE *mris, double resolution, MRI *mri_src, MRI *mri_fractions) { +MRI *MRIcomputeLaminarVolumeFractions(MRI_SURFACE *mris, double resolution, MRI *mri_src, MRI *mri_fractions) +{ int width, height, depth, nvox; MRI *mri_layers, *mri_interior_pial, *mri_tmp; MATRIX *m_vox2vox; @@ -73739,7 +75299,8 @@ MRI *MRIcomputeLaminarVolumeFractions(MRI_SURFACE *mris, double resolution, MRI MRIScomputeMetricProperties(mris); MRISfillInterior(mris, resolution, mri_layers); mri_interior_wm = MRIcopy(mri_layers, NULL); - } else + } + else MRIcopy(mri_interior_wm, mri_layers); MRISrestoreVertexPositions(mris, PIAL_VERTICES); @@ -73766,7 +75327,8 @@ MRI *MRIcomputeLaminarVolumeFractions(MRI_SURFACE *mris, double resolution, MRI return (mri_fractions); } -static double mrisComputeHistoNegativeLikelihood(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static double mrisComputeHistoNegativeLikelihood(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ double likelihood, entropy; int x, y, z, label; VECTOR *v_brain, *v_hires; @@ -73793,7 +75355,8 @@ static double mrisComputeHistoNegativeLikelihood(MRI_SURFACE *mris, INTEGRATION_ zv = V3_Z(v_hires); if (MRIindexNotInVolume(parms->mri_labels, xv, yv, zv)) { label = MRI_NONBRAIN; - } else { + } + else { label = MRIgetVoxVal(parms->mri_labels, nint(xv), nint(yv), nint(zv), 0); } @@ -73823,7 +75386,8 @@ static double mrisComputeHistoNegativeLikelihood(MRI_SURFACE *mris, INTEGRATION_ return (entropy); } -static int mrisComputeHistoTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputeHistoTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ int vno; VERTEX *v; double xv, yv, zv, val, p, dx, dy, dz, d, d2, x, y, z, best_d, best_p; @@ -73853,7 +75417,8 @@ static int mrisComputeHistoTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { MRIsampleVolume(parms->mri_brain, xv, yv, zv, &val); if (d2 < d) { p += HISTOgetCount(parms->h_gm, val); - } else { + } + else { p += HISTOgetCount(parms->h_nonbrain, val); } num++; @@ -73895,7 +75460,8 @@ static int mrisComputeHistoTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { return (NO_ERROR); } static double vlst_loglikelihood( - MRI_SURFACE *mris, MRI *mri, int vno, double displacement, VOXEL_LIST *vl, HISTOGRAM *hin, HISTOGRAM *hout) { + MRI_SURFACE *mris, MRI *mri, int vno, double displacement, VOXEL_LIST *vl, HISTOGRAM *hin, HISTOGRAM *hout) +{ double ll = 0.0, dot, dx, dy, dz, pval, dist, Ig, Ic, gm_frac, out_frac; int i; float val; @@ -73918,7 +75484,8 @@ static double vlst_loglikelihood( if (dot > 0) { out_frac = dist + .5; gm_frac = 1 - out_frac; - } else { + } + else { gm_frac = dist + .5; out_frac = 1 - gm_frac; } @@ -73926,7 +75493,8 @@ static double vlst_loglikelihood( Ic = (val - gm_frac * Ig) / out_frac; pval += HISTOgetCount(hout, Ic) * HISTOgetCount(hin, Ig); } - } else if (dot > 0) // outside surface + } + else if (dot > 0) // outside surface pval = HISTOgetCount(hout, val); else // inside the surface pval = HISTOgetCount(hin, val); @@ -73986,7 +75554,8 @@ vlst_loglikelihood2D(MRI_SURFACE *mris, MRI *mri, int vno, double displacement, } #else static double vlst_loglikelihood2D( - MRI_SURFACE *mris, MRI *mri, int vno, double displacement, VOXEL_LIST *vl, HISTOGRAM2D *h, FILE *fp) { + MRI_SURFACE *mris, MRI *mri, int vno, double displacement, VOXEL_LIST *vl, HISTOGRAM2D *h, FILE *fp) +{ double ll = 0.0, dot, dx, dy, dz, pval, dist; int i; float val; @@ -74016,7 +75585,8 @@ static double vlst_loglikelihood2D( return (ll); } #endif -static VOXEL_LIST **vlst_alloc(MRI_SURFACE *mris, int max_vox) { +static VOXEL_LIST **vlst_alloc(MRI_SURFACE *mris, int max_vox) +{ int vno; VOXEL_LIST **vl; @@ -74029,7 +75599,8 @@ static VOXEL_LIST **vlst_alloc(MRI_SURFACE *mris, int max_vox) { } return (vl); } -static int vlst_free(MRI_SURFACE *mris, VOXEL_LIST ***pvl) { +static int vlst_free(MRI_SURFACE *mris, VOXEL_LIST ***pvl) +{ VOXEL_LIST **vl = *pvl; int vno; @@ -74040,7 +75611,8 @@ static int vlst_free(MRI_SURFACE *mris, VOXEL_LIST ***pvl) { } #if 1 -static int vlst_enough_data(MRI_SURFACE *mris, int vno, VOXEL_LIST *vl, double displacement) { +static int vlst_enough_data(MRI_SURFACE *mris, int vno, VOXEL_LIST *vl, double displacement) +{ double dot, dx, dy, dz; int i, nin, nout; VERTEX *v; @@ -74068,7 +75640,8 @@ static int vlst_enough_data(MRI_SURFACE *mris, int vno, VOXEL_LIST *vl, double d #define MAX_DISPLACEMENT 5 #define DISPLACEMENT_DELTA .1 -static double mrisComputeNegativeLogPosterior(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int *pnvox) { +static double mrisComputeNegativeLogPosterior(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int *pnvox) +{ MRI *mri = parms->mri_brain; double sse = 0.0, ll, wm_frac, gm_frac, out_frac, Ig, Ic, pval; float vmin, vmax, val; @@ -74125,7 +75698,8 @@ static double mrisComputeNegativeLogPosterior(MRI_SURFACE *mris, INTEGRATION_PAR sprintf(fname, "hout.%s.%3.3d.plt", parms->base_name, parms->t); HISTOplot(hout, fname); } - } else // use previously computed ones + } + else // use previously computed ones { hin = parms->hgm; hout = parms->hout; @@ -74190,7 +75764,8 @@ static double mrisComputeNegativeLogPosterior(MRI_SURFACE *mris, INTEGRATION_PAR return (sse); } -static int vlst_add_to_list(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst) { +static int vlst_add_to_list(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst) +{ int i; for (i = 0; i < vl_src->nvox; i++) @@ -74198,7 +75773,8 @@ static int vlst_add_to_list(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst) { return (NO_ERROR); } -static int mrisComputePosteriorTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputePosteriorTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ MRI *mri = parms->mri_brain; static MRI *mri_white_dist; FILE *fp; @@ -74295,7 +75871,8 @@ static int mrisComputePosteriorTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) char fname[STRLEN]; sprintf(fname, "vno%d.%d.l.dat", vno, parms->t); fp = fopen(fname, "w"); - } else + } + else fp = NULL; best_ll = -1e10; best_dn = 0; @@ -74420,7 +75997,8 @@ static int mrisComputePosteriorTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) horrific. Don't blame me, I did not write it, I just copied the from mri_tessellate. */ -MRIS *MRIStessellate(MRI *mri, int value, int all_flag) { +MRIS *MRIStessellate(MRI *mri, int value, int all_flag) +{ int imnr, i, j, f_pack, v_ind, f; int xnum, ynum, numimg; int face_index, vertex_index; @@ -74984,7 +76562,8 @@ MRIS *MRIStessellate(MRI *mri, int value, int all_flag) { surf->faces[fno + 1].v[0] = vertices[2]; surf->faces[fno + 1].v[1] = vertices[3]; surf->faces[fno + 1].v[2] = vertices[1]; - } else { + } + else { surf->faces[fno].v[0] = vertices[0]; surf->faces[fno].v[1] = vertices[1]; surf->faces[fno].v[2] = vertices[2]; @@ -75034,7 +76613,8 @@ void TESSaddFace(MRI *mri, int *pface_index, tface_type *face, int *face_index_table0, - int *face_index_table1) { + int *face_index_table1) +{ int xnum, ynum, pack; xnum = mri->width; @@ -75044,7 +76624,8 @@ void TESSaddFace(MRI *mri, if (*pface_index >= MAXFACES - 1) ErrorExit(ERROR_NOMEMORY, "%s: max faces %d exceeded", Progname, MAXFACES); if (prev_flag) { face_index_table0[pack] = *pface_index; - } else { + } + else { face_index_table1[pack] = *pface_index; } face[*pface_index].imnr = imnr; // z @@ -75072,7 +76653,8 @@ void TESScheckFace(MRI *mri, int *pface_index, int *face_index_table0, int *face_index_table1, - tvertex_type *vertex) { + tvertex_type *vertex) +{ int xnum, ynum, numimg, f_pack, f_ind; int imax, imin, jmax, jmin; xnum = mri->width; @@ -75101,7 +76683,8 @@ void TESScheckFace(MRI *mri, } } -int TESSaddVertex(MRI *mri, int imnr, int i, int j, int *pvertex_index, int *vertex_index_table, tvertex_type *vertex) { +int TESSaddVertex(MRI *mri, int imnr, int i, int j, int *pvertex_index, int *vertex_index_table, tvertex_type *vertex) +{ int xnum = mri->width; int pack = i * (xnum + 1) + j; @@ -75117,7 +76700,8 @@ int TESSaddVertex(MRI *mri, int imnr, int i, int j, int *pvertex_index, int *ver return ((*pvertex_index)++); } -int TESSfacep(MRI *mri, int im0, int i0, int j0, int im1, int i1, int j1, int value, int all_flag) { +int TESSfacep(MRI *mri, int im0, int i0, int j0, int im1, int i1, int j1, int value, int all_flag) +{ int numimg, imax, imin, jmax, jmin; numimg = mri->depth; // it is so confusing this guy uses j for width and i for height @@ -75556,7 +77140,8 @@ mrisComputePosterior2DTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) return(NO_ERROR) ; } #else -static double mrisComputeNegativeLogPosterior2D(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int *pnvox) { +static double mrisComputeNegativeLogPosterior2D(MRI_SURFACE *mris, INTEGRATION_PARMS *parms, int *pnvox) +{ MRI *mri = parms->mri_brain; MHT *mht; double sse = 0.0, ll, wm_frac, pval, dist, vdist, xs, ys, zs; @@ -75709,7 +77294,8 @@ static double mrisComputeNegativeLogPosterior2D(MRI_SURFACE *mris, INTEGRATION_P DiagBreak(); } - } else // use previously computed ones + } + else // use previously computed ones { } @@ -75778,7 +77364,8 @@ static double mrisComputeNegativeLogPosterior2D(MRI_SURFACE *mris, INTEGRATION_P return (sse); } -static int mrisComputePosterior2DTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) { +static int mrisComputePosterior2DTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parms) +{ MRI *mri = parms->mri_brain; FILE *fp, *fp2; double dist, xs, ys, zs, dn, best_dn, best_ll, ll; @@ -75883,7 +77470,8 @@ static int mrisComputePosterior2DTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parm fp = fopen(fname, "w"); sprintf(fname, "vno%d.%d.l.vals.dat", vno, parms->t); fp2 = fopen(fname, "w"); - } else + } + else fp = fp2 = NULL; best_ll = -1e10; best_dn = 0; @@ -76029,7 +77617,8 @@ static int mrisComputePosterior2DTerm(MRI_SURFACE *mris, INTEGRATION_PARMS *parm } #endif -MRI *MRISmapToSurface(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRI *mri_src_features, MRI *mri_dst_features) { +MRI *MRISmapToSurface(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRI *mri_src_features, MRI *mri_dst_features) +{ int vno_src, vno_dst; MHT *mht; VERTEX *vdst, *vsrc; @@ -76052,7 +77641,8 @@ MRI *MRISmapToSurface(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, MRI *mri_src MHTfree(&mht); return (mri_dst_features); } -int MRIScountNegativeFaces(MRI_SURFACE *mris) { +int MRIScountNegativeFaces(MRI_SURFACE *mris) +{ int fno, neg; FACE *face; @@ -76063,7 +77653,8 @@ int MRIScountNegativeFaces(MRI_SURFACE *mris) { } return (neg); } -int MRISevertSurface(MRI_SURFACE *mris) { +int MRISevertSurface(MRI_SURFACE *mris) +{ int v0, fno; FACE *face; @@ -76077,7 +77668,8 @@ int MRISevertSurface(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRISsetCroppedToZero(MRI_SURFACE *mris) { +int MRISsetCroppedToZero(MRI_SURFACE *mris) +{ int vno; VERTEX *v; @@ -76089,7 +77681,8 @@ int MRISsetCroppedToZero(MRI_SURFACE *mris) { return (NO_ERROR); } -int MRIScopyFromCropped(MRI_SURFACE *mris, int which) { +int MRIScopyFromCropped(MRI_SURFACE *mris, int which) +{ int vno; VERTEX *v; @@ -76111,7 +77704,8 @@ int MRIScopyFromCropped(MRI_SURFACE *mris, int which) { return (NO_ERROR); } -int MRIScopyToCropped(MRI_SURFACE *mris, int which) { +int MRIScopyToCropped(MRI_SURFACE *mris, int which) +{ int vno; VERTEX *v; @@ -76132,7 +77726,8 @@ int MRIScopyToCropped(MRI_SURFACE *mris, int which) { } return (NO_ERROR); } -int MRISwriteCropped(MRI_SURFACE *mris, char *fname) { +int MRISwriteCropped(MRI_SURFACE *mris, char *fname) +{ float *vals; vals = (float *)calloc(mris->nvertices, sizeof(*vals)); @@ -76145,7 +77740,8 @@ int MRISwriteCropped(MRI_SURFACE *mris, char *fname) { free(vals); return (NO_ERROR); } -int IsMRISselfIntersecting(MRI_SURFACE *mris) { +int IsMRISselfIntersecting(MRI_SURFACE *mris) +{ MRIS_HASH_TABLE *mht; int fno; @@ -76162,7 +77758,8 @@ int IsMRISselfIntersecting(MRI_SURFACE *mris) { return 0; } #include "mrinorm.h" -MRI *MRISsolveLaplaceEquation(MRI_SURFACE *mris, MRI *mri, double res) { +MRI *MRISsolveLaplaceEquation(MRI_SURFACE *mris, MRI *mri, double res) +{ MRI *mri_white, *mri_pial, *mri_laplace, *mri_control, *mri_tmp = NULL; int x, y, z, ncontrol, nribbon, v, i, xm1, xp1, ym1, yp1, zm1, zp1; VOXLIST *vl; @@ -76193,12 +77790,14 @@ MRI *MRISsolveLaplaceEquation(MRI_SURFACE *mris, MRI *mri, double res) { MRIsetVoxVal(mri_control, x, y, z, 0, CONTROL_MARKED); MRIsetVoxVal(mri_laplace, x, y, z, 0, 0.0); ncontrol++; - } else if (FZERO(pval)) // outside pial surface + } + else if (FZERO(pval)) // outside pial surface { MRIsetVoxVal(mri_control, x, y, z, 0, CONTROL_MARKED); MRIsetVoxVal(mri_laplace, x, y, z, 0, 1.0); ncontrol++; - } else + } + else nribbon++; } @@ -76261,7 +77860,8 @@ MRI *MRISsolveLaplaceEquation(MRI_SURFACE *mris, MRI *mri, double res) { return (mri_laplace); } -int MRISmeasureLaplaceStreamlines(MRI_SURFACE *mris, MRI *mri_laplace, MRI *mri_intensity, MRI *mri_profiles) { +int MRISmeasureLaplaceStreamlines(MRI_SURFACE *mris, MRI *mri_laplace, MRI *mri_intensity, MRI *mri_profiles) +{ int vno, f, x, y, z, npoints, nmissing, nbr_is_diag; VERTEX *v; double dx, dy, dz, xv, yv, zv, voxsize; @@ -76426,7 +78026,8 @@ int MRISmeasureLaplaceStreamlines(MRI_SURFACE *mris, MRI *mri_laplace, MRI *mri_ MRIsetVoxVal(mri_profiles, vno, 0, 0, frame, val); frame = new_frame; if (frame >= mri_profiles->nframes) break; - } else + } + else MRIsetVoxVal(mri_profiles, vno, 0, 0, frame, val); MRIsampleVolumeFrame(mri_laplace, xv, yv, zv, 0, &val); @@ -76442,7 +78043,8 @@ int MRISmeasureLaplaceStreamlines(MRI_SURFACE *mris, MRI *mri_laplace, MRI *mri_ MRIfree(&mri_grad); return (NO_ERROR); } -int MRISnotMarked(MRI_SURFACE *mris) { +int MRISnotMarked(MRI_SURFACE *mris) +{ int vno; VERTEX *v; diff --git a/utils/mrisutils.c b/utils/mrisutils.c index 4659dac1c6f..aaa95b8a7d9 100644 --- a/utils/mrisutils.c +++ b/utils/mrisutils.c @@ -67,7 +67,8 @@ /////////////////////////////////////////////////////////////////// // smooth a surface 'niter' times with a step (should be around 0.5) -void MRISsmoothSurface(MRI_SURFACE *mris, int niter, float step) { +void MRISsmoothSurface(MRI_SURFACE *mris, int niter, float step) +{ VERTEX *v; int iter, k, m, n; float x, y, z; @@ -107,7 +108,8 @@ void MRISsmoothSurface(MRI_SURFACE *mris, int niter, float step) { void MRIScenterCOG(MRIS *mris) { MRIScenterCOG2(mris, NULL, NULL, NULL); } // translate the COG of a surface to (0,0,0) -void MRIScenterCOG2(MRI_SURFACE *mris, double *xCOG, double *yCOG, double *zCOG) { +void MRIScenterCOG2(MRI_SURFACE *mris, double *xCOG, double *yCOG, double *zCOG) +{ int k; double x, y, z; x = 0; @@ -143,7 +145,8 @@ void MRIScenterCOG2(MRI_SURFACE *mris, double *xCOG, double *yCOG, double *zCOG) // *** NbVoxels corresponds to: // - the number of kept voxels if (type>=0) // - the number of removed voxels if (type<0) -MRI *MRISpeelVolume(MRIS *mris, MRI *mri_src, MRI *mri_dst, int type, unsigned char val, unsigned long *NbVoxels) { +MRI *MRISpeelVolume(MRIS *mris, MRI *mri_src, MRI *mri_dst, int type, unsigned char val, unsigned long *NbVoxels) +{ int i, j, k, imnr; float x0, y0, z0, x1, y1, z1, x2, y2, z2, d0, d1, d2, dmax, u, v; float px, py, pz, px0, py0, pz0, px1, py1, pz1; @@ -262,7 +265,8 @@ MRI *MRISpeelVolume(MRIS *mris, MRI *mri_src, MRI *mri_dst, int type, unsigned c if (MRIvox(mri_buff, i, j, k) == 64) { tmpval = MRIvox(mri_src, i, j, k); MRIvox(mri_dst, i, j, k) = tmpval; - } else { + } + else { MRIvox(mri_dst, i, j, k) = 0; size++; } @@ -312,7 +316,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, double l_intensity, MRI * static int mrisComputeTangentialSpringTerm(MRI_SURFACE *mris, double l_spring); static int mrisComputeNormalSpringTerm(MRI_SURFACE *mris, double l_spring); -static int mrisClearMomentum(MRI_SURFACE *mris) { +static int mrisClearMomentum(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -327,7 +332,8 @@ static int mrisClearMomentum(MRI_SURFACE *mris) { return (NO_ERROR); } -static int mrisClearGradient(MRI_SURFACE *mris) { +static int mrisClearGradient(MRI_SURFACE *mris) +{ int vno, nvertices; VERTEX *v; @@ -369,7 +375,8 @@ mrisClearExtraGradient(MRI_SURFACE *mris) } #endif -static int mrisAverageSignedGradients(MRI_SURFACE *mris, int num_avgs) { +static int mrisAverageSignedGradients(MRI_SURFACE *mris, int num_avgs) +{ int i, vno, vnb, *pnb, vnum; float dx, dy, dz, num, sigma, dot; VERTEX *v, *vn; @@ -389,7 +396,8 @@ static int mrisAverageSignedGradients(MRI_SURFACE *mris, int num_avgs) { MRISgradientFromParameterization(mrisp_blur, mris); MRISPfree(&mrisp); MRISPfree(&mrisp_blur); - } else + } + else for (i = 0; i < num_avgs; i++) { for (vno = 0; vno < mris->nvertices; vno++) { v = &mris->vertices[vno]; @@ -445,7 +453,8 @@ static int mrisAverageSignedGradients(MRI_SURFACE *mris, int num_avgs) { return (NO_ERROR); } -MRI_REGION *MRIlocateRegion(MRI *mri, int label) { +MRI_REGION *MRIlocateRegion(MRI *mri, int label) +{ int i, j, k; int xmin, xmax, ymin, ymax, zmin, zmax; MRI_REGION *mri_region = (MRI_REGION *)malloc(sizeof(MRI_REGION)); @@ -475,7 +484,8 @@ MRI_REGION *MRIlocateRegion(MRI *mri, int label) { return mri_region; } -static MRI *mriIsolateLabel(MRI *mri_seg, int label, MRI_REGION *bbox) { +static MRI *mriIsolateLabel(MRI *mri_seg, int label, MRI_REGION *bbox) +{ int i, j, k; int xplusdx, yplusdy, zplusdz; MRI *mri = MRIalloc(mri_seg->width, mri_seg->height, mri_seg->depth, mri_seg->type); @@ -492,7 +502,8 @@ static MRI *mriIsolateLabel(MRI *mri_seg, int label, MRI_REGION *bbox) { return mri; } -static double mrisRmsValError(MRI_SURFACE *mris, MRI *mri) { +static double mrisRmsValError(MRI_SURFACE *mris, MRI *mri) +{ int vno, n, xv, yv, zv; double val, total, delta, x, y, z; VERTEX *v; @@ -512,14 +523,16 @@ static double mrisRmsValError(MRI_SURFACE *mris, MRI *mri) { return (sqrt(total / (double)n)); } -static void mrisSetVal(MRIS *mris, float val) { +static void mrisSetVal(MRIS *mris, float val) +{ int n; for (n = 0; n < mris->nvertices; n++) mris->vertices[n].val = val; } #define MIN_NBR_DIST (0.25) -static int mrisRemoveNormalGradientComponent(MRI_SURFACE *mris, int vno) { +static int mrisRemoveNormalGradientComponent(MRI_SURFACE *mris, int vno) +{ VERTEX *v; float dot; @@ -534,7 +547,8 @@ static int mrisRemoveNormalGradientComponent(MRI_SURFACE *mris, int vno) { return (NO_ERROR); } -static int mrisRemoveNeighborGradientComponent(MRI_SURFACE *mris, int vno) { +static int mrisRemoveNeighborGradientComponent(MRI_SURFACE *mris, int vno) +{ VERTEX *v, *vn; int n; float dx, dy, dz, dot, x, y, z, dist; @@ -569,7 +583,8 @@ static int mrisRemoveNeighborGradientComponent(MRI_SURFACE *mris, int vno) { return (NO_ERROR); } -static int mrisLimitGradientDistance(MRI_SURFACE *mris, MHT *mht, int vno) { +static int mrisLimitGradientDistance(MRI_SURFACE *mris, MHT *mht, int vno) +{ VERTEX *v; v = &mris->vertices[vno]; @@ -586,7 +601,8 @@ static int mrisLimitGradientDistance(MRI_SURFACE *mris, MHT *mht, int vno) { return (NO_ERROR); } -static double mrisAsynchronousTimeStepNew(MRI_SURFACE *mris, float momentum, float delta_t, MHT *mht, float max_mag) { +static double mrisAsynchronousTimeStepNew(MRI_SURFACE *mris, float momentum, float delta_t, MHT *mht, float max_mag) +{ static int direction = 1; double mag; int vno, i; @@ -633,7 +649,8 @@ static double mrisAsynchronousTimeStepNew(MRI_SURFACE *mris, float momentum, flo #define VERTEX_EDGE(vec, v0, v1) VECTOR_LOAD(vec, v1->x - v0->x, v1->y - v0->y, v1->z - v0->z) -static int mrisComputeTangentPlanes(MRI_SURFACE *mris) { +static int mrisComputeTangentPlanes(MRI_SURFACE *mris) +{ VECTOR *v_n, *v_e1, *v_e2, *v; int vno; VERTEX *vertex; @@ -696,7 +713,8 @@ static int mrisComputeTangentPlanes(MRI_SURFACE *mris) { Fit a 1-d quadratic to the surface locally and move the vertex in the normal direction to improve the fit. ------------------------------------------------------*/ -static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) { +static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) +{ MATRIX *m_R, *m_R_inv; VECTOR *v_Y, *v_A, *v_n, *v_e1, *v_e2, *v_nbr; int vno, n; @@ -767,7 +785,8 @@ static int mrisComputeQuadraticCurvatureTerm(MRI_SURFACE *mris, double l_curv) { return (NO_ERROR); } -static int mrisComputeIntensityTerm(MRI_SURFACE *mris, double l_intensity, MRI *mri, double sigma) { +static int mrisComputeIntensityTerm(MRI_SURFACE *mris, double l_intensity, MRI *mri, double sigma) +{ int vno; VERTEX *v; float x, y, z, nx, ny, nz, dx, dy, dz; @@ -869,7 +888,8 @@ static int mrisComputeIntensityTerm(MRI_SURFACE *mris, double l_intensity, MRI * return (NO_ERROR); } -static int mrisComputeNormalSpringTerm(MRI_SURFACE *mris, double l_spring) { +static int mrisComputeNormalSpringTerm(MRI_SURFACE *mris, double l_spring) +{ int vno, n, m; VERTEX *vertex, *vn; float sx, sy, sz, nx, ny, nz, nc, x, y, z; @@ -920,7 +940,8 @@ static int mrisComputeNormalSpringTerm(MRI_SURFACE *mris, double l_spring) { return (NO_ERROR); } -static int mrisComputeTangentialSpringTerm(MRI_SURFACE *mris, double l_spring) { +static int mrisComputeTangentialSpringTerm(MRI_SURFACE *mris, double l_spring) +{ int vno, n, m; VERTEX *v, *vn; float sx, sy, sz, x, y, z, nc; @@ -979,12 +1000,9 @@ static int mrisComputeTangentialSpringTerm(MRI_SURFACE *mris, double l_spring) { #define AVERAGES_NBR 1 #define BASE_DT_SCALE 1.0 -MRIS *MRISmatchSurfaceToLabel(MRIS *mris, - MRI *mri_seg, - int label, - MRI_REGION *mri_region, - INTEGRATION_PARMS *integration_parms, - int connectivity) { +MRIS *MRISmatchSurfaceToLabel( + MRIS *mris, MRI *mri_seg, int label, MRI_REGION *mri_region, INTEGRATION_PARMS *integration_parms, int connectivity) +{ int bbox_indicator = 0, done, niterations, n, nreductions = 0; MRI_REGION *bbox; MRI *mri; @@ -1021,7 +1039,8 @@ MRIS *MRISmatchSurfaceToLabel(MRIS *mris, parms->l_repulse = 0.0; // ; parms->sigma = 2.0f; parms->mri_brain = mri_seg; /*necessary for using MRIcomputeSSE*/ - } else + } + else parms = integration_parms; niterations = parms->niterations; @@ -1151,7 +1170,8 @@ MRIS *MRISmatchSurfaceToLabel(MRIS *mris, } // smooth a surface 'niter' times with a step (should be around 0.5) -void MRISsmoothSurface2(MRI_SURFACE *mris, int niter, float step, int avrg) { +void MRISsmoothSurface2(MRI_SURFACE *mris, int niter, float step, int avrg) +{ VERTEX *v; int iter, k, m, n; float x, y, z; @@ -1196,7 +1216,8 @@ void MRISsmoothSurface2(MRI_SURFACE *mris, int niter, float step, int avrg) { } /*--------------------------------------------------------------------*/ -MRIS *MRISloadSurfSubject(char *subj, char *hemi, char *surfid, char *SUBJECTS_DIR) { +MRIS *MRISloadSurfSubject(char *subj, char *hemi, char *surfid, char *SUBJECTS_DIR) +{ MRIS *Surf; char fname[2000]; @@ -1260,7 +1281,8 @@ MRIS *MRISloadSurfSubject(char *subj, char *hemi, char *surfid, char *SUBJECTS_D See also: fdr2vwth() in sig.c ---------------------------------------------------------------*/ -int MRISfdr2vwth(MRIS *surf, double fdr, int signid, int log10flag, int maskflag, double *vwth) { +int MRISfdr2vwth(MRIS *surf, double fdr, int signid, int log10flag, int maskflag, double *vwth) +{ double *p = NULL, val, val2null; int vtxno, np; @@ -1339,7 +1361,8 @@ int MRISfdr2vwth(MRIS *surf, double fdr, int signid, int log10flag, int maskflag /*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/ /*---------------------------------------------------------------*/ -int MRISfwhm2niters(double fwhm, MRIS *surf) { +int MRISfwhm2niters(double fwhm, MRIS *surf) +{ double avgvtxarea, gstd; int niters; @@ -1364,7 +1387,8 @@ int MRISfwhm2niters(double fwhm, MRIS *surf) { } /*----------------------------------------------------------------------*/ -double MRISniters2fwhm(int niters, MRIS *surf) { +double MRISniters2fwhm(int niters, MRIS *surf) +{ double avgvtxarea, gstd, fwhm; MRIScomputeMetricProperties(surf); @@ -1387,7 +1411,8 @@ double MRISniters2fwhm(int niters, MRIS *surf) { } /*---------------------------------------------------------------*/ -int MRISfwhm2nitersSubj(double fwhm, char *subject, char *hemi, char *surfname) { +int MRISfwhm2nitersSubj(double fwhm, char *subject, char *hemi, char *surfname) +{ char *SUBJECTS_DIR, surfpath[2000]; MRIS *surf; int niters; @@ -1414,7 +1439,8 @@ int MRISfwhm2nitersSubj(double fwhm, char *subject, char *hemi, char *surfname) /*---------------------------------------------------------------------- MRISfwhm() - estimates fwhm from global ar1 mean ----------------------------------------------------------------------*/ -double MRISfwhmFromAR1(MRIS *surf, double ar1) { +double MRISfwhmFromAR1(MRIS *surf, double ar1) +{ double fwhm, gstd, InterVertexDistAvg; MRIScomputeMetricProperties(surf); @@ -1434,7 +1460,8 @@ double MRISfwhmFromAR1(MRIS *surf, double ar1) { if (ar1 > 0.0) { gstd = InterVertexDistAvg / sqrt(-4 * log(ar1)); fwhm = gstd * sqrt(log(256.0)); - } else { + } + else { printf("WARNING: ar1 = %g <= 0. Setting fwhm to 0.\n", ar1); fwhm = 0.0; } @@ -1445,7 +1472,8 @@ double MRISfwhmFromAR1(MRIS *surf, double ar1) { /*---------------------------------------------------------------------- MRIscale() - scales vertex XYZ by scale. ----------------------------------------------------------------------*/ -int MRISscale(MRIS *mris, double scale) { +int MRISscale(MRIS *mris, double scale) +{ int vno; VERTEX *v; for (vno = 0; vno < mris->nvertices; vno++) { @@ -1462,7 +1490,8 @@ int MRISscale(MRIS *mris, double scale) { of iterations at the given vertex. Essentially it's the area of the neighborhood. -------------------------------------------------------------------------*/ -double MRISsmoothingArea(MRIS *mris, int vtxno, int niters) { +double MRISsmoothingArea(MRIS *mris, int vtxno, int niters) +{ MRI *mri; int n, nhits; double val, area; @@ -1502,7 +1531,8 @@ double MRISsmoothingArea(MRIS *mris, int vtxno, int niters) { MRI struct to an annotation in an MRIS struct. If ctab is null, it tries to use mris->ct. See also MRISannotIndex2Seg(). -------------------------------------------------------------------*/ -int MRISseg2annot(MRIS *mris, MRI *surfseg, COLOR_TABLE *ctab) { +int MRISseg2annot(MRIS *mris, MRI *surfseg, COLOR_TABLE *ctab) +{ int vtxno, segid, ano; if (ctab == NULL) { @@ -1510,7 +1540,8 @@ int MRISseg2annot(MRIS *mris, MRI *surfseg, COLOR_TABLE *ctab) { printf("ERROR: MRISseg2annot: both ctab and mris->ct are NULL\n"); return (1); } - } else + } + else mris->ct = ctab; set_atable_from_ctable(mris->ct); @@ -1531,7 +1562,8 @@ int MRISseg2annot(MRIS *mris, MRI *surfseg, COLOR_TABLE *ctab) { and 1 frame. It should not be misconstrued as a volume. See also MRISseg2annot(). ----------------------------------------------------------------*/ -MRI *MRISannotIndex2Seg(MRIS *mris) { +MRI *MRISannotIndex2Seg(MRIS *mris) +{ MRI *seg; int vno, annot, annotid; @@ -1552,7 +1584,8 @@ MRI *MRISannotIndex2Seg(MRIS *mris) { \fn double MRISvolumeInSurf(MRIS *mris) \brief Computes the volume inside a surface. (Xiao) */ -double MRISvolumeInSurf(MRIS *mris) { +double MRISvolumeInSurf(MRIS *mris) +{ int fno; double total_volume, face_area; VECTOR *v_a, *v_b, *v_n, *v_cen; @@ -1605,7 +1638,8 @@ double MRISvolumeInSurf(MRIS *mris) { srf2vol matlab script. \params w is white surface, p is pial. Output is an MRI struct of size nvertices */ -MRI *MRISvolumeTH3(MRIS *w, MRIS *p, MRI *vol, MRI *mask, double *totvol) { +MRI *MRISvolumeTH3(MRIS *w, MRIS *p, MRI *vol, MRI *mask, double *totvol) +{ MRI *facevol; int nthface, v1, v2, v3; int vno, nfacenbrs, nthfacenbr, nbrfaceno; @@ -1714,7 +1748,8 @@ MRI *MRISvolumeTH3(MRIS *w, MRIS *p, MRI *vol, MRI *mask, double *totvol) { the search for non-cortical vertices (that is, they will be labeled cortex). */ -LABEL *MRIScortexLabel(MRI_SURFACE *mris, MRI *mri_aseg, int min_vertices) { +LABEL *MRIScortexLabel(MRI_SURFACE *mris, MRI *mri_aseg, int min_vertices) +{ LABEL *lcortex; int vno, label, nvox, total_vox, adjacent, x, y, z, target_label, l, base_label, left, right; VERTEX *v; @@ -1790,7 +1825,8 @@ LABEL *MRIScortexLabel(MRI_SURFACE *mris, MRI *mri_aseg, int min_vertices) { if (vno == Gdiag_no) DiagBreak(); v->marked = 0; } - } else if (right && right >= left) // near right thalamus + } + else if (right && right >= left) // near right thalamus { if (MRIlabelsInNbhd(mri_aseg, x, y, z, 2, Right_Lateral_Ventricle) > 0) { if (vno == Gdiag_no) DiagBreak(); @@ -1894,7 +1930,8 @@ LABEL *MRIScortexLabel(MRI_SURFACE *mris, MRI *mri_aseg, int min_vertices) { Note: this is not realated to the surface-based spherical coords. */ -int MRISsphericalCoords(MRIS *surf) { +int MRISsphericalCoords(MRIS *surf) +{ int k; double x, y, z, d2, d, r, theta, phi; @@ -1921,7 +1958,8 @@ int MRISsphericalCoords(MRIS *surf) { (actually less than 1e-5). If mri is null, then uses the val field. No change to a vertex if ripflag already = 1. */ -int MRISripZeros(MRIS *surf, MRI *mri) { +int MRISripZeros(MRIS *surf, MRI *mri) +{ int k; double v; @@ -1955,7 +1993,8 @@ int MRISripZeros(MRIS *surf, MRI *mri) { \params mris - surface This was copied from tksurfer.c find_path() and modified slightly. */ -int MRISfindPath(int *vert_vno, int num_vno, int max_path_length, int *path, int *path_length, MRIS *mris) { +int MRISfindPath(int *vert_vno, int num_vno, int max_path_length, int *path, int *path_length, MRIS *mris) +{ int cur_vert_vno; int src_vno; int dest_vno; @@ -2023,7 +2062,8 @@ int MRISfindPath(int *vert_vno, int num_vno, int max_path_length, int *path, int /* if this is the dest node, we're done. */ if (closest_vno == dest_vno) { done = TRUE; - } else { + } + else { /* relax its neighbors. */ for (neighbor = 0; neighbor < v->vnum; neighbor++) { neighbor_vno = v->v[neighbor]; @@ -2086,7 +2126,8 @@ MRI *MRIScomputeFlattenedVolume(MRI_SURFACE *mris, MRI **pmri_vertices, int smooth_iters, double wm_dist, - double outside_dist) { + double outside_dist) +{ MRI *mri_flat, *mri_mask, *mri_counts, *mri_vno; int vno, width, height, u, v, w, fno, num; int uk, vk, ui, vi, whalf = 3, nv, wm_samples, outside_samples; @@ -2180,7 +2221,8 @@ MRI *MRIScomputeFlattenedVolume(MRI_SURFACE *mris, 3; norm += wm_dist + outside_dist; norm /= nsamples; // divide average thickness into this many samples - } else // use uniform spacing + } + else // use uniform spacing norm = 1.0 / nsamples; dx *= norm; @@ -2314,7 +2356,8 @@ MRI *MRIScomputeFlattenedVolume(MRI_SURFACE *mris, hemilist[0] = "rh"; hemilist[1] = "lh"; mrisp_template=MRISmakeTemplate(2, subjlist, 2, hemilist, "sphere.left_right"); */ -MRI_SP *MRISmakeTemplate(int nsubjects, char **subjlist, int nhemis, char **hemilist, char *surfregname) { +MRI_SP *MRISmakeTemplate(int nsubjects, char **subjlist, int nhemis, char **hemilist, char *surfregname) +{ static char *surface_names[] = {"inflated", "smoothwm", "smoothwm"}; static char *curvature_names[] = {"inflated.H", "sulc", NULL}; char tmpstr[2000]; @@ -2377,7 +2420,8 @@ MRI_SP *MRISmakeTemplate(int nsubjects, char **subjlist, int nhemis, char **hemi } MRISaverageCurvatures(mris, navgs); MRISnormalizeCurvature(mris, which_norm); - } else { + } + else { sprintf(tmpstr, "%s/%s/surf/%s.%s", SUBJECTS_DIR, subject, hemi, surface_names[sno]); err = MRISreadVertexPositions(mris, tmpstr); if (err) { @@ -2410,7 +2454,8 @@ MRI_SP *MRISmakeTemplate(int nsubjects, char **subjlist, int nhemis, char **hemi white or the pial must have an annotation. If both have an annotation, then white's is used. */ -int MRISsetPialUnknownToWhite(const MRIS *white, MRIS *pial) { +int MRISsetPialUnknownToWhite(const MRIS *white, MRIS *pial) +{ int vtxno, UseWhite; int annot = 0, annotid = 0; @@ -2432,7 +2477,8 @@ int MRISsetPialUnknownToWhite(const MRIS *white, MRIS *pial) { if (UseWhite) { annot = white->vertices[vtxno].annotation; CTABfindAnnotation(white->ct, annot, &annotid); - } else { + } + else { annot = pial->vertices[vtxno].annotation; CTABfindAnnotation(pial->ct, annot, &annotid); } @@ -2450,7 +2496,8 @@ int MRISsetPialUnknownToWhite(const MRIS *white, MRIS *pial) { \fn int MRISripUnknown(MRIS *surf) \brief Sets the ripflag = 1 in places where the annotation is unknown */ -int MRISripUnknown(MRIS *surf) { +int MRISripUnknown(MRIS *surf) +{ int nripped = 0, vtxno, annot, annotid; for (vtxno = 0; vtxno < surf->nvertices; vtxno++) { @@ -2473,7 +2520,8 @@ int MRISripUnknown(MRIS *surf) { MRIStkr2Scanner() or MRISscanner2Tkr() which will have the same result for non-oblique but do the right thing for oblique. */ -int MRISshiftCRAS(MRIS *mris, int shift) { +int MRISshiftCRAS(MRIS *mris, int shift) +{ double dx, dy, dz; int vno; @@ -2485,7 +2533,8 @@ int MRISshiftCRAS(MRIS *mris, int shift) { mris->xctr = mris->vg.c_r; mris->yctr = mris->vg.c_a; mris->zctr = mris->vg.c_s; - } else { + } + else { mris->useRealRAS = 0; dx = -mris->vg.c_r; dy = -mris->vg.c_a; @@ -2510,7 +2559,8 @@ int MRISshiftCRAS(MRIS *mris, int shift) { is done to make sure. Use MRISscanner2Tkr() to reverse. Sets mris->useRealRAS = 1; */ -int MRIStkr2Scanner(MRIS *mris) { +int MRIStkr2Scanner(MRIS *mris) +{ MATRIX *M, *T, *Tinv, *S; // S = VGgetVoxelToRasXform(&mris->vg,NULL,0); // this is wrong @@ -2534,7 +2584,8 @@ int MRIStkr2Scanner(MRIS *mris) { checking is done to make sure. Use MRIStkr2Scanner() to reverse. Sets mris->useRealRAS = 0; */ -int MRISscanner2Tkr(MRIS *mris) { +int MRISscanner2Tkr(MRIS *mris) +{ MATRIX *Q, *T, *Sinv, *S; // S = VGgetVoxelToRasXform(&mris->vg,NULL,0); // this is wrong @@ -2556,7 +2607,8 @@ int MRISscanner2Tkr(MRIS *mris) { \fn int ComputeMRISvolumeTH3(char *subject, char *hemi, int DoMask, char *outfile) \brief Computes and saves the vertex-wise volume of cortex using TH3. */ -int ComputeMRISvolumeTH3(char *subject, char *hemi, int DoMask, char *outfile) { +int ComputeMRISvolumeTH3(char *subject, char *hemi, int DoMask, char *outfile) +{ MRIS *w, *p; MRI *mrisvol; int err = 0; @@ -2590,7 +2642,8 @@ int ComputeMRISvolumeTH3(char *subject, char *hemi, int DoMask, char *outfile) { if (IDextensionFromName(outfile)) { // output file has a known extention err = MRIwrite(mrisvol, outfile); - } else { + } + else { // otherwise assume it is a curv file MRIScopyMRI(w, mrisvol, 0, "curv"); err = MRISwriteCurvature(w, outfile); @@ -2660,7 +2713,8 @@ int ComputeMRISvolumeTH3(char *subject, char *hemi, int DoMask, char *outfile) { L2SaddPoint(l2s, col, row, slice, 0, 0); // remove a voxel L2Sfree(&l2s); */ -int L2SaddPoint(LABEL2SURF *l2s, double col, double row, double slice, int PointType, int Operation) { +int L2SaddPoint(LABEL2SURF *l2s, double col, double row, double slice, int PointType, int Operation) +{ int n, nmin, vtxnominmin, vtxno, pointno; VERTEX v; static MATRIX *crs = NULL, *ras = NULL; @@ -2698,7 +2752,8 @@ int L2SaddPoint(LABEL2SURF *l2s, double col, double row, double slice, int Point // Incr the number of points in the label label->n_points++; return (1); - } else { // Operation != 1, Remove vertex from label + } + else { // Operation != 1, Remove vertex from label if (pointno == 0) return (0); // not already there, cant remove it lv = &(label->lv[pointno - 1]); // If it gets here, then remove the vertex @@ -2771,8 +2826,9 @@ int L2SaddPoint(LABEL2SURF *l2s, double col, double row, double slice, int Point lv->stat = 0; // Incr the number of points in the label label->n_points++; - return (1); // return=1 because point has been added - } else { // Operation != 1, Remove vertex from label + return (1); // return=1 because point has been added + } + else { // Operation != 1, Remove vertex from label if (pointno == 0) return (0); // not already there, cant remove it lv = &(label->lv[pointno - 1]); lv->deleted = 1; @@ -2856,7 +2912,8 @@ int L2SaddPoint(LABEL2SURF *l2s, double col, double row, double slice, int Point // Incr the number of points in the label label->n_points++; LabelChanged = 1; - } else { // Operation != 1, Remove vertex from label + } + else { // Operation != 1, Remove vertex from label if (pointno == 0) continue; // not already there, cant remove it lv = &(label->lv[pointno - 1]); // If it gets here, then remove the vertex @@ -2906,7 +2963,8 @@ int L2SaddPoint(LABEL2SURF *l2s, double col, double row, double slice, int Point for nhopsmax; the value is a reasonable guess based on the voxel size. */ -int L2Sinit(LABEL2SURF *l2s) { +int L2Sinit(LABEL2SURF *l2s) +{ int n; // initialize hashes @@ -2959,7 +3017,8 @@ int L2Sinit(LABEL2SURF *l2s) { return (-1); } DoInvert = 1; - } else { + } + else { // The source matches, but does the target? if (!vg_isEqual(&l2s->surfs[0]->vg, &(l2s->vol2surf->xforms[0].dst))) { printf("ERROR: L2Sinit(): registration does not match surface vg %g\n", vg_isEqual_Threshold); @@ -2973,7 +3032,8 @@ int L2Sinit(LABEL2SURF *l2s) { if (DoInvert) { if (l2s->debug) printf("L2Sinit(): inverting reg\n"); R = MatrixInverse(lta->xforms[0].m_L, NULL); - } else + } + else R = MatrixCopy(lta->xforms[0].m_L, NULL); LTAfree(<a); } @@ -3043,7 +3103,8 @@ int L2Sinit(LABEL2SURF *l2s) { alloc the surfaces. subject can be null (this info is just passed to the labels). */ -LABEL2SURF *L2Salloc(int nsurfs, char *subject) { +LABEL2SURF *L2Salloc(int nsurfs, char *subject) +{ int n; LABEL2SURF *l2s; l2s = (LABEL2SURF *)calloc(sizeof(LABEL2SURF), 1); @@ -3064,7 +3125,8 @@ LABEL2SURF *L2Salloc(int nsurfs, char *subject) { \brief Frees the relevant elements of the LABEL2SURF structure. Does not free the surfaces. */ -int L2Sfree(LABEL2SURF **pl2s) { +int L2Sfree(LABEL2SURF **pl2s) +{ int n; LABEL2SURF *l2s = *pl2s; @@ -3091,7 +3153,8 @@ int L2Sfree(LABEL2SURF **pl2s) { surface from the center vertex. L2SaddPoint() has a built-in mechanism for solving this problem, and it may be better. See L2SaddPoint() for argument descriptions. */ -int L2SaddVoxel(LABEL2SURF *l2s, double col, double row, double slice, int nsegs, int Operation) { +int L2SaddVoxel(LABEL2SURF *l2s, double col, double row, double slice, int nsegs, int Operation) +{ double c, r, s, dseg; int ret, kc, kr, ks; @@ -3131,7 +3194,8 @@ int L2SaddVoxel(LABEL2SURF *l2s, double col, double row, double slice, int nsegs convert the coordinates or check whether any of the label points might be there already. */ -int L2SimportLabel(LABEL2SURF *l2s, LABEL *label, int surfno) { +int L2SimportLabel(LABEL2SURF *l2s, LABEL *label, int surfno) +{ int n; LV *lv; @@ -3153,7 +3217,8 @@ int L2SimportLabel(LABEL2SURF *l2s, LABEL *label, int surfno) { because surf vg not set. Returns 0 if all tests passed or 1 if any test failed. */ -int L2Stest(char *subject) { +int L2Stest(char *subject) +{ char *SUBJECTS_DIR, tmpstr[2000]; SUBJECTS_DIR = getenv("SUBJECTS_DIR"); MRI *mri, *apas; diff --git a/utils/mrivoxel.c b/utils/mrivoxel.c index 9e0851f3c1d..71fb2f7f3ad 100644 --- a/utils/mrivoxel.c +++ b/utils/mrivoxel.c @@ -55,7 +55,8 @@ Description ------------------------------------------------------*/ -float MRIvoxelDx(MRI *mri, int x, int y, int z) { +float MRIvoxelDx(MRI *mri, int x, int y, int z) +{ float left, right, dx; // int width, height; int xm1, xp1, ym1, yp1; @@ -89,7 +90,8 @@ float MRIvoxelDx(MRI *mri, int x, int y, int z) { Description ------------------------------------------------------*/ -float MRIvoxelDy(MRI *mri, int x, int y, int z) { +float MRIvoxelDy(MRI *mri, int x, int y, int z) +{ float top, bottom, dy; // int width, height; int xm1, xp1, ym1, yp1; @@ -123,7 +125,8 @@ float MRIvoxelDy(MRI *mri, int x, int y, int z) { Description ------------------------------------------------------*/ -float MRIvoxelDz(MRI *mri, int x, int y, int z) { +float MRIvoxelDz(MRI *mri, int x, int y, int z) +{ float dz, top, bottom; // int width, depth; int xm1, xp1, zm1, zp1; @@ -157,7 +160,8 @@ float MRIvoxelDz(MRI *mri, int x, int y, int z) { Description ------------------------------------------------------*/ -float MRIvoxelGradient(MRI *mri, int x, int y, int z, float *pdx, float *pdy, float *pdz) { +float MRIvoxelGradient(MRI *mri, int x, int y, int z, float *pdx, float *pdy, float *pdz) +{ float mag, dx, dy, dz; *pdx = dx = MRIvoxelDx(mri, x, y, z); @@ -174,7 +178,8 @@ float MRIvoxelGradient(MRI *mri, int x, int y, int z, float *pdx, float *pdy, fl Description ------------------------------------------------------*/ -float MRIvoxelMean(const MRI *mri, int x0, int y0, int z0, int wsize, int frame) { +float MRIvoxelMean(const MRI *mri, int x0, int y0, int z0, int wsize, int frame) +{ float mean, total; int whalf, width, height, depth, x, y, z, npix, xmin, xmax, ymin, ymax, zmin, zmax; @@ -210,7 +215,8 @@ float MRIvoxelMean(const MRI *mri, int x0, int y0, int z0, int wsize, int frame) Description ------------------------------------------------------*/ -float MRIvoxelMin(MRI *mri, int x0, int y0, int z0, int wsize) { +float MRIvoxelMin(MRI *mri, int x0, int y0, int z0, int wsize) +{ float min_val, val; int whalf, width, height, depth, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax; @@ -237,7 +243,8 @@ float MRIvoxelMin(MRI *mri, int x0, int y0, int z0, int wsize) { } return (min_val); } -float MRIvoxelMax(MRI *mri, int x0, int y0, int z0, int wsize) { +float MRIvoxelMax(MRI *mri, int x0, int y0, int z0, int wsize) +{ float max_val, val; int whalf, width, height, depth, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax; @@ -271,7 +278,8 @@ float MRIvoxelMax(MRI *mri, int x0, int y0, int z0, int wsize) { Description ------------------------------------------------------*/ -float MRIvoxelStd(MRI *mri, int x0, int y0, int z0, float mean, int wsize) { +float MRIvoxelStd(MRI *mri, int x0, int y0, int z0, float mean, int wsize) +{ float std, total, var; int whalf, width, height, depth, x, y, z, npix, xmin, xmax, ymin, ymax, zmin, zmax; BUFTYPE *psrc; @@ -315,7 +323,8 @@ float MRIvoxelStd(MRI *mri, int x0, int y0, int z0, float mean, int wsize) { ------------------------------------------------------*/ #define MAX_WINDOW 7 #define MAX_LEN (MAX_WINDOW * MAX_WINDOW * MAX_WINDOW) -float MRIvoxelDirection(MRI *mri, int x0, int y0, int z0, int wsize) { +float MRIvoxelDirection(MRI *mri, int x0, int y0, int z0, int wsize) +{ int whalf, width, height, depth, x, y, z, xmax, ymax, zmax; // int npix, total, xmin, ymin, zmin; float dx_win[MAX_LEN], dy_win[MAX_LEN], dz_win[MAX_LEN], dx, dy, dz, odx, ody, odz, *pdx, *pdy, *pdz, dir; @@ -383,7 +392,8 @@ float MRIvoxelDirection(MRI *mri, int x0, int y0, int z0, int wsize) { Description ------------------------------------------------------*/ -float MRIvoxelGradientDir2ndDerivative(MRI *mri, int x0, int y0, int z0, int wsize) { +float MRIvoxelGradientDir2ndDerivative(MRI *mri, int x0, int y0, int z0, int wsize) +{ int whalf; // int width, height, depth; float odx, ody, odz, len, d2I_dg2, xf, yf, zf, d; @@ -424,7 +434,8 @@ float MRIvoxelGradientDir2ndDerivative(MRI *mri, int x0, int y0, int z0, int wsi return (d2I_dg2); } -float MRIvoxelZscore(MRI *mri, int x, int y, int z, int wsize) { +float MRIvoxelZscore(MRI *mri, int x, int y, int z, int wsize) +{ float mean, std, zscore, src; src = (float)MRIvox(mri, x, y, z); @@ -446,7 +457,8 @@ float MRIvoxelZscore(MRI *mri, int x, int y, int z, int wsize) { Description ------------------------------------------------------*/ static int compare_sort_array(const void *pc1, const void *pc2); -static int compare_sort_array(const void *pc1, const void *pc2) { +static int compare_sort_array(const void *pc1, const void *pc2) +{ register float c1, c2; c1 = *(float *)pc1; @@ -460,7 +472,8 @@ static int compare_sort_array(const void *pc1, const void *pc2) { return (0); } -float MRIvoxelMedian(MRI *mri, int x0, int y0, int z0, int wsize) { +float MRIvoxelMedian(MRI *mri, int x0, int y0, int z0, int wsize) +{ float median, val; int whalf, width, height, depth, x, y, z, xmin, xmax, median_index, ymin, ymax, zmin, zmax, wcubed; // int npix; diff --git a/utils/nifti1_io.c b/utils/nifti1_io.c index ff3d9b5f98d..b22b7a5ac80 100644 --- a/utils/nifti1_io.c +++ b/utils/nifti1_io.c @@ -432,7 +432,8 @@ static int has_ascii_header(znzFile fp); /*----------------------------------------------------------------------*/ /*! display the nifti library module history (via stdout) */ /*--------------------------------------------------------------------*/ -void nifti_disp_lib_hist(void) { +void nifti_disp_lib_hist(void) +{ int c, len = sizeof(gni_history) / sizeof(char *); for (c = 0; c < len; c++) fputs(gni_history[c], stdout); } @@ -498,7 +499,8 @@ void nifti_disp_lib_version(void) { printf("%s, compiled %s\n", gni_version, __D * \sa nifti_image_load_bricks, nifti_free_NBL, valid_nifti_brick_list, nifti_image_read */ /*----------------------------------------------------------------------*/ -nifti_image *nifti_image_read_bricks(const char *hname, int nbricks, const int *blist, nifti_brick_list *NBL) { +nifti_image *nifti_image_read_bricks(const char *hname, int nbricks, const int *blist, nifti_brick_list *NBL) +{ nifti_image *nim; if (!hname || !NBL) { @@ -533,7 +535,8 @@ nifti_image *nifti_image_read_bricks(const char *hname, int nbricks, const int * * nt, nu, nv and nw is lost. So put everything in t, and set * dim[0] = 4. *----------------------------------------------------------------------*/ -static void update_nifti_image_for_brick_list(nifti_image *nim, int nbricks) { +static void update_nifti_image_for_brick_list(nifti_image *nim, int nbricks) +{ int ndim; if (g_opts.debug > 2) { @@ -580,7 +583,8 @@ static void update_nifti_image_for_brick_list(nifti_image *nim, int nbricks) { Check for updates to pixdim[], dx,..., nx,..., nvox, ndim, dim[0]. */ /*--------------------------------------------------------------------*/ -int nifti_update_dims_from_array(nifti_image *nim) { +int nifti_update_dims_from_array(nifti_image *nim) +{ int c, ndim; if (!nim) { @@ -682,7 +686,8 @@ int nifti_update_dims_from_array(nifti_image *nim) { * out of NBL, in which case the only pointer the calling function * will want to free is NBL->bricks (not each NBL->bricks[i]). */ /*--------------------------------------------------------------------*/ -int nifti_image_load_bricks(nifti_image *nim, int nbricks, const int *blist, nifti_brick_list *NBL) { +int nifti_image_load_bricks(nifti_image *nim, int nbricks, const int *blist, nifti_brick_list *NBL) +{ int *slist = NULL, *sindex = NULL, rv; znzFile fp; @@ -750,7 +755,8 @@ int nifti_image_load_bricks(nifti_image *nim, int nbricks, const int *blist, nif * * note: this does not presume to free the structure pointer */ /*--------------------------------------------------------------------*/ -void nifti_free_NBL(nifti_brick_list *NBL) { +void nifti_free_NBL(nifti_brick_list *NBL) +{ int c; if (NBL->bricks) { @@ -768,7 +774,8 @@ void nifti_free_NBL(nifti_brick_list *NBL) { * * return 0 on success, -1 on failure *----------------------------------------------------------------------*/ -static int nifti_load_NBL_bricks(nifti_image *nim, int *slist, int *sindex, nifti_brick_list *NBL, znzFile fp) { +static int nifti_load_NBL_bricks(nifti_image *nim, int *slist, int *sindex, nifti_brick_list *NBL, znzFile fp) +{ size_t oposn, fposn; /* orig and current file positions */ size_t rv; long test; @@ -828,7 +835,8 @@ static int nifti_load_NBL_bricks(nifti_image *nim, int *slist, int *sindex, nift return -1; } fposn += NBL->bsize; - } else { + } + else { /* we have already read this sub-brick, just copy the previous one */ /* note that this works because they are sorted */ memcpy(NBL->bricks[idest], NBL->bricks[sindex[c - 1]], NBL->bsize); @@ -845,7 +853,8 @@ static int nifti_load_NBL_bricks(nifti_image *nim, int *slist, int *sindex, nift * * return 0 on success, -1 on failure *----------------------------------------------------------------------*/ -static int nifti_alloc_NBL_mem(nifti_image *nim, int nbricks, nifti_brick_list *nbl) { +static int nifti_alloc_NBL_mem(nifti_image *nim, int nbricks, nifti_brick_list *nbl) +{ int c; /* if nbricks is not specified, use the default */ @@ -898,7 +907,8 @@ static int nifti_alloc_NBL_mem(nifti_image *nim, int nbricks, nifti_brick_list * * * return 0 on success, -1 on failure *----------------------------------------------------------------------*/ -static int nifti_copynsort(int nbricks, const int *blist, int **slist, int **sindex) { +static int nifti_copynsort(int nbricks, const int *blist, int **slist, int **sindex) +{ int *stmp, *itmp; /* for ease of typing/reading */ int c1, c2, spos, tmp; @@ -977,7 +987,8 @@ static int nifti_copynsort(int nbricks, const int *blist, int **slist, int **sin * * \return 1 if valid, 0 if not */ /*--------------------------------------------------------------------*/ -int valid_nifti_brick_list(nifti_image *nim, int nbricks, const int *blist, int disp_error) { +int valid_nifti_brick_list(nifti_image *nim, int nbricks, const int *blist, int disp_error) +{ int c, nsubs; if (!nim) { @@ -1041,7 +1052,8 @@ static int int_force_positive( int * list, int nel ) * * \return -1 if results cannot be determined, 0 if okay */ /*--------------------------------------------------------------------*/ -int nifti_disp_matrix_orient(const char *mesg, mat44 mat) { +int nifti_disp_matrix_orient(const char *mesg, mat44 mat) +{ int i, j, k; if (mesg) fputs(mesg, stderr); /* use stdout? */ @@ -1065,7 +1077,8 @@ int nifti_disp_matrix_orient(const char *mesg, mat44 mat) { * * \return allocated pointer (or NULL on failure) */ /*--------------------------------------------------------------------*/ -char *nifti_strdup(const char *str) { +char *nifti_strdup(const char *str) +{ char *dup = (char *)malloc(strlen(str) + 1); if (dup) strcpy(dup, str); return dup; @@ -1083,7 +1096,8 @@ char *nifti_strdup(const char *str) { \sa NIFTI1_DATATYPES group in nifti1.h */ /*-------------------------------------------------------------------------*/ -char *nifti_datatype_string(int dt) { +char *nifti_datatype_string(int dt) +{ switch (dt) { case DT_UNKNOWN: return "UNKNOWN"; @@ -1132,7 +1146,8 @@ char *nifti_datatype_string(int dt) { \sa NIFTI1_DATATYPES group in nifti1.h */ /*--------------------------------------------------------------------*/ -int nifti_is_inttype(int dt) { +int nifti_is_inttype(int dt) +{ switch (dt) { case DT_UNKNOWN: return 0; @@ -1186,7 +1201,8 @@ int nifti_is_inttype(int dt) { \sa NIFTI1_UNITS group in nifti1.h */ /*-------------------------------------------------------------------------*/ -char *nifti_units_string(int uu) { +char *nifti_units_string(int uu) +{ switch (uu) { case NIFTI_UNITS_METER: return "m"; @@ -1222,7 +1238,8 @@ char *nifti_units_string(int uu) { \sa NIFTI1_XFORM_CODES group in nifti1.h */ /*-------------------------------------------------------------------------*/ -char *nifti_xform_string(int xx) { +char *nifti_xform_string(int xx) +{ switch (xx) { case NIFTI_XFORM_SCANNER_ANAT: return "Scanner Anat"; @@ -1248,7 +1265,8 @@ char *nifti_xform_string(int xx) { \sa NIFTI1_INTENT_CODES group in nifti1.h */ /*-------------------------------------------------------------------------*/ -char *nifti_intent_string(int ii) { +char *nifti_intent_string(int ii) +{ switch (ii) { case NIFTI_INTENT_CORREL: return "Correlation statistic"; @@ -1337,7 +1355,8 @@ char *nifti_intent_string(int ii) { \sa NIFTI1_SLICE_ORDER group in nifti1.h */ /*-------------------------------------------------------------------------*/ -char *nifti_slice_string(int ss) { +char *nifti_slice_string(int ss) +{ switch (ss) { case NIFTI_SLICE_SEQ_INC: return "sequential_increasing"; @@ -1367,7 +1386,8 @@ char *nifti_slice_string(int ss) { \sa NIFTI_L2R in nifti1_io.h */ /*-------------------------------------------------------------------------*/ -char *nifti_orientation_string(int ii) { +char *nifti_orientation_string(int ii) +{ switch (ii) { case NIFTI_L2R: return "Left-to-Right"; @@ -1398,7 +1418,8 @@ char *nifti_orientation_string(int ii) { \sa NIFTI1_DATATYPES in nifti1.h */ /*------------------------------------------------------------------------*/ -void nifti_datatype_sizes(int datatype, int *nbyper, int *swapsize) { +void nifti_datatype_sizes(int datatype, int *nbyper, int *swapsize) +{ int nb = 0, ss = 0; switch (datatype) { case DT_INT8: @@ -1483,7 +1504,8 @@ void nifti_datatype_sizes(int datatype, int *nbyper, int *swapsize) { */ /*-------------------------------------------------------------------------*/ 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) { + float qb, float qc, float qd, float qx, float qy, float qz, float dx, float dy, float dz, float qfac) +{ mat44 R; double a, b = qb, c = qc, d = qd, xd, yd, zd; @@ -1501,7 +1523,8 @@ mat44 nifti_quatern_to_mat44( c *= a; d *= a; /* normalize (b,c,d) vector */ a = 0.0l; /* a = 0 ==> 180 degree rotation */ - } else { + } + else { a = sqrt(a); /* angle = 2*arccos(a) */ } @@ -1566,7 +1589,8 @@ void nifti_mat44_to_quatern(mat44 R, float *dx, float *dy, float *dz, - float *qfac) { + float *qfac) +{ double r11, r12, r13, r21, r22, r23, r31, r32, r33; double xd, yd, zd, a, b, c, d; mat33 P, Q; @@ -1676,7 +1700,8 @@ void nifti_mat44_to_quatern(mat44 R, if (zd > 0) { /* proper */ ASSIF(qfac, 1.0); - } else { /* improper ==> flip 3rd column */ + } + else { /* improper ==> flip 3rd column */ ASSIF(qfac, -1.0); r13 = -r13; r23 = -r23; @@ -1692,7 +1717,8 @@ void nifti_mat44_to_quatern(mat44 R, b = 0.25l * (r32 - r23) / a; c = 0.25l * (r13 - r31) / a; d = 0.25l * (r21 - r12) / a; - } else { /* trickier case */ + } + else { /* trickier case */ xd = 1.0 + r11 - (r22 + r33); /* 4*b*b */ yd = 1.0 + r22 - (r11 + r33); /* 4*c*c */ zd = 1.0 + r33 - (r11 + r22); /* 4*d*d */ @@ -1701,12 +1727,14 @@ void nifti_mat44_to_quatern(mat44 R, c = 0.25l * (r12 + r21) / b; d = 0.25l * (r13 + r31) / b; a = 0.25l * (r32 - r23) / b; - } else if (yd > 1.0) { + } + else if (yd > 1.0) { c = 0.5l * sqrt(yd); b = 0.25l * (r12 + r21) / c; d = 0.25l * (r23 + r32) / c; a = 0.25l * (r13 - r31) / c; - } else { + } + else { d = 0.5l * sqrt(zd); b = 0.25l * (r13 + r31) / d; c = 0.25l * (r23 + r32) / d; @@ -1742,7 +1770,8 @@ void nifti_mat44_to_quatern(mat44 R, [ 0 0 0 1 ] */ /*-------------------------------------------------------------------------*/ -mat44 nifti_mat44_inverse(mat44 R) { +mat44 nifti_mat44_inverse(mat44 R) +{ double r11, r12, r13, r21, r22, r23, r31, r32, r33, v1, v2, v3, deti; mat44 Q; /* INPUT MATRIX IS: */ @@ -1818,7 +1847,8 @@ mat44 nifti_mat44_inverse(mat44 R) { nifti_mat44_to_orientation */ /*-------------------------------------------------------------------------*/ mat44 nifti_make_orthog_mat44( - float r11, float r12, float r13, float r21, float r22, float r23, float r31, float r32, float r33) { + float r11, float r12, float r13, float r21, float r22, float r23, float r31, float r32, float r33) +{ mat44 R; mat33 Q, P; double val; @@ -1844,7 +1874,8 @@ mat44 nifti_make_orthog_mat44( Q.m[0][0] *= val; Q.m[0][1] *= val; Q.m[0][2] *= val; - } else { + } + else { Q.m[0][0] = 1.0l; Q.m[0][1] = 0.0l; Q.m[0][2] = 0.0l; @@ -1858,7 +1889,8 @@ mat44 nifti_make_orthog_mat44( Q.m[1][0] *= val; Q.m[1][1] *= val; Q.m[1][2] *= val; - } else { + } + else { Q.m[1][0] = 0.0l; Q.m[1][1] = 1.0l; Q.m[1][2] = 0.0l; @@ -1872,7 +1904,8 @@ mat44 nifti_make_orthog_mat44( Q.m[2][0] *= val; Q.m[2][1] *= val; Q.m[2][2] *= val; - } else { + } + else { Q.m[2][0] = Q.m[0][1] * Q.m[1][2] - Q.m[0][2] * Q.m[1][1]; /* cross */ Q.m[2][1] = Q.m[0][2] * Q.m[1][0] - Q.m[0][0] * Q.m[1][2]; /* product */ Q.m[2][2] = Q.m[0][0] * Q.m[1][1] - Q.m[0][1] * Q.m[1][0]; @@ -2001,7 +2034,8 @@ mat33 nifti_mat33_mul(mat33 A, mat33 B) /* multiply 2 3x3 matrices */ Algorithm is that from NJ Higham, SIAM J Sci Stat Comput, 7:1160-1174. */ /*-------------------------------------------------------------------------*/ -mat33 nifti_mat33_polar(mat33 A) { +mat33 nifti_mat33_polar(mat33 A) +{ mat33 X, Y, Z; float alp, bet, gam, gmi, dif = 1.0; int k = 0; @@ -2026,7 +2060,8 @@ mat33 nifti_mat33_polar(mat33 A) { bet = sqrt(nifti_mat33_rownorm(Y) * nifti_mat33_colnorm(Y)); gam = sqrt(bet / alp); gmi = 1.0 / gam; - } else { + } + else { gam = gmi = 1.0; /* close to convergence */ } Z.m[0][0] = 0.5 * (gam * X.m[0][0] + gmi * Y.m[0][0]); @@ -2075,7 +2110,8 @@ mat33 nifti_mat33_polar(mat33 A) { \see nifti_quatern_to_mat44, nifti_mat44_to_quatern, nifti_make_orthog_mat44 */ /*-------------------------------------------------------------------------*/ -void nifti_mat44_to_orientation(mat44 R, int *icod, int *jcod, int *kcod) { +void nifti_mat44_to_orientation(mat44 R, int *icod, int *jcod, int *kcod) +{ float xi, xj, xk, yi, yj, yk, zi, zj, zk, val, detQ, detP; mat33 P, Q, M; int i, j, k = 0, p, q, r, ibest, jbest, kbest, pbest, qbest, rbest; @@ -2138,7 +2174,8 @@ void nifti_mat44_to_orientation(mat44 R, int *icod, int *jcod, int *kcod) { xk = yi * zj - zi * yj; yk = zi * xj - zj * xi; zk = xi * yj - yi * xj; - } else { + } + else { xk /= val; yk /= val; zk /= val; @@ -2456,7 +2493,8 @@ void nifti_swap_Nbytes(int n, int siz, void *ar) /* subsuming case */ components of the header; otherwise, only the components common to NIFTI and ANALYZE will be swapped. */ /*---------------------------------------------------------------------- */ -void swap_nifti_header(struct nifti_1_header *h, int is_nifti) { +void swap_nifti_header(struct nifti_1_header *h, int is_nifti) +{ #if 0 /* ANALYZE fields not used by this software */ swap_4(h->sizeof_hdr) ; swap_4(h->extents) ; @@ -2524,7 +2562,8 @@ void swap_nifti_header(struct nifti_1_header *h, int is_nifti) { changed to return int, -1 means no file or error 20 Dec 2004 [rickr] */ /*-------------------------------------------------------------------------*/ -int nifti_get_filesize(const char *pathname) { +int nifti_get_filesize(const char *pathname) +{ struct stat buf; int ii; @@ -2536,7 +2575,8 @@ int nifti_get_filesize(const char *pathname) { #else /*---------- non-Unix version of the above, less efficient -----------*/ -int nifti_get_filesize(const char *pathname) { +int nifti_get_filesize(const char *pathname) +{ znzFile fp; int len; @@ -2556,7 +2596,8 @@ int nifti_get_filesize(const char *pathname) { This is computed as nvox * nbyper. */ /*--------------------------------------------------------------------*/ -size_t nifti_get_volsize(const nifti_image *nim) { +size_t nifti_get_volsize(const nifti_image *nim) +{ return (size_t)(nim->nbyper) * (size_t)(nim->nvox); /* total bytes */ } @@ -2570,7 +2611,8 @@ size_t nifti_get_volsize(const nifti_image *nim) { \return 1 on existence, 0 otherwise */ /*--------------------------------------------------------------------*/ -int nifti_fileexists(const char *fname) { +int nifti_fileexists(const char *fname) +{ znzFile fp; fp = znzopen(fname, "rb", 1); if (!znz_isnull(fp)) { @@ -2595,7 +2637,8 @@ int nifti_fileexists(const char *fname) { ".myhiddenimage" | 0 | ".myhiddenimage.nii" | 1 | */ /*--------------------------------------------------------------------*/ -int nifti_is_complete_filename(const char *fname) { +int nifti_is_complete_filename(const char *fname) +{ char *ext; /* check input file(s) for sanity */ @@ -2632,7 +2675,8 @@ int nifti_is_complete_filename(const char *fname) { ".myhiddenimage" | 1 | ".myhiddenimage" ".myhiddenimage.nii | 1 | ".myhiddenimage" */ /*--------------------------------------------------------------------*/ -int nifti_validfilename(const char *fname) { +int nifti_validfilename(const char *fname) +{ char *ext; /* check input file(s) for sanity */ @@ -2660,7 +2704,8 @@ int nifti_validfilename(const char *fname) { \return a pointer to the extension (within the filename), or NULL */ /*--------------------------------------------------------------------*/ -char *nifti_find_file_extension(const char *name) { +char *nifti_find_file_extension(const char *name) +{ char *ext; int len; @@ -2693,7 +2738,8 @@ char *nifti_find_file_extension(const char *name) { /*----------------------------------------------------------------------*/ /*! return whether the filename ends in ".gz" */ /*--------------------------------------------------------------------*/ -int nifti_is_gzfile(const char *fname) { +int nifti_is_gzfile(const char *fname) +{ /* return true if the filename ends with .gz */ if (fname == NULL) { return 0; @@ -2716,7 +2762,8 @@ int nifti_is_gzfile(const char *fname) { This allocates memory for basename which should eventually be freed. */ /*--------------------------------------------------------------------*/ -char *nifti_makebasename(const char *fname) { +char *nifti_makebasename(const char *fname) +{ char *basename, *ext; basename = nifti_strdup(fname); @@ -2752,7 +2799,8 @@ void nifti_set_skip_blank_ext(int skip) { g_opts.skip_blank_ext = skip ? 1 : 0; NB: it allocates memory for hdrname which should be freed when no longer required */ /*-------------------------------------------------------------------*/ -char *nifti_findhdrname(const char *fname) { +char *nifti_findhdrname(const char *fname) +{ char *basename, *hdrname, *ext; char elist[2][5] = {".hdr", ".nii"}; int efirst; @@ -2845,7 +2893,8 @@ char *nifti_findhdrname(const char *fname) { NB: it allocates memory for the image filename, which should be freed when no longer required */ /*---------------------------------------------------------------------*/ -char *nifti_findimgname(const char *fname, int nifti_type) { +char *nifti_findimgname(const char *fname, int nifti_type) +{ char *basename, *imgname, ext[2][5] = {".nii", ".img"}; int first; /* first extension to use */ @@ -2921,7 +2970,8 @@ char *nifti_findimgname(const char *fname, int nifti_type) { \sa nifti_set_filenames */ /*-------------------------------------------------------------------*/ -char *nifti_makehdrname(const char *prefix, int nifti_type, int check, int comp) { +char *nifti_makehdrname(const char *prefix, int nifti_type, int check, int comp) +{ char *iname, *ext; if (!nifti_validfilename(prefix)) return NULL; @@ -2976,7 +3026,8 @@ char *nifti_makehdrname(const char *prefix, int nifti_type, int check, int comp) \sa nifti_set_filenames */ /*-------------------------------------------------------------------*/ -char *nifti_makeimgname(const char *prefix, int nifti_type, int check, int comp) { +char *nifti_makeimgname(const char *prefix, int nifti_type, int check, int comp) +{ char *iname, *ext; if (!nifti_validfilename(prefix)) return NULL; @@ -3033,7 +3084,8 @@ char *nifti_makeimgname(const char *prefix, int nifti_type, int check, int comp) \sa nifti_makeimgname, nifti_makehdrname, nifti_type_and_names_match */ /*--------------------------------------------------------------------*/ -int nifti_set_filenames(nifti_image *nim, const char *prefix, int check, int set_byte_order) { +int nifti_set_filenames(nifti_image *nim, const char *prefix, int check, int set_byte_order) +{ int comp = nifti_is_gzfile(prefix); if (!nim || !prefix) { @@ -3078,7 +3130,8 @@ int nifti_set_filenames(nifti_image *nim, const char *prefix, int check, int set \sa NIFTI_FTYPE_* codes in nifti1_io.h \sa nifti_set_type_from_names, is_valid_nifti_type */ /*------------------------------------------------------------------------*/ -int nifti_type_and_names_match(nifti_image *nim, int show_warn) { +int nifti_type_and_names_match(nifti_image *nim, int show_warn) +{ char func[] = "nifti_type_and_names_match"; char *ext_h, *ext_i; /* header and image filename extensions */ int errs = 0; /* error counter */ @@ -3134,8 +3187,9 @@ int nifti_type_and_names_match(nifti_image *nim, int show_warn) { fprintf(stderr, "-d NIFTI_FTYPE 1, but header and image filenames differ: %s, %s\n", nim->fname, nim->iname); errs++; } - } else if ((nim->nifti_type == NIFTI_FTYPE_NIFTI1_2) || /* .hdr/.img */ - (nim->nifti_type == NIFTI_FTYPE_ANALYZE)) { + } + else if ((nim->nifti_type == NIFTI_FTYPE_NIFTI1_2) || /* .hdr/.img */ + (nim->nifti_type == NIFTI_FTYPE_ANALYZE)) { if (strncmp(ext_h, ".hdr", 4) != 0) { if (show_warn) fprintf(stderr, "-d no '.hdr' extension, but NIFTI type is %d, %s\n", nim->nifti_type, nim->fname); errs++; @@ -3159,7 +3213,8 @@ int nifti_type_and_names_match(nifti_image *nim, int show_warn) { \return 1 if nifti_type is valid, 0 otherwise \sa NIFTI_FTYPE_* codes in nifti1_io.h */ /*------------------------------------------------------------------------*/ -int is_valid_nifti_type(int nifti_type) { +int is_valid_nifti_type(int nifti_type) +{ if (nifti_type >= NIFTI_FTYPE_ANALYZE && /* smallest type, 0 */ nifti_type <= NIFTI_MAX_FTYPE) return 1; @@ -3175,7 +3230,8 @@ int is_valid_nifti_type(int nifti_type) { \return 1 if dtype is valid, 0 otherwise \sa NIFTI_TYPE_* codes in nifti1.h */ /*------------------------------------------------------------------------*/ -int nifti_is_valid_datatype(int dtype) { +int nifti_is_valid_datatype(int dtype) +{ if (dtype == NIFTI_TYPE_UINT8 || dtype == NIFTI_TYPE_INT16 || dtype == NIFTI_TYPE_INT32 || dtype == NIFTI_TYPE_FLOAT32 || dtype == NIFTI_TYPE_COMPLEX64 || dtype == NIFTI_TYPE_FLOAT64 || dtype == NIFTI_TYPE_RGB24 || dtype == NIFTI_TYPE_RGBA32 || dtype == NIFTI_TYPE_INT8 || @@ -3196,7 +3252,8 @@ int nifti_is_valid_datatype(int dtype) { \sa is_valid_nifti_type, nifti_type_and_names_match */ /*------------------------------------------------------------------------*/ -int nifti_set_type_from_names(nifti_image *nim) { +int nifti_set_type_from_names(nifti_image *nim) +{ /* error checking first */ if (!nim) { fprintf(stderr, "** NSTFN: no nifti_image\n"); @@ -3244,7 +3301,8 @@ int nifti_set_type_from_names(nifti_image *nim) { -1 if it can't tell, file doesn't exist, etc. */ /*------------------------------------------------------------------------*/ -int is_nifti_file(const char *hname) { +int is_nifti_file(const char *hname) +{ struct nifti_1_header nhdr; znzFile fp; int ii; @@ -3290,7 +3348,8 @@ int is_nifti_file(const char *hname) { return -1; /* not good */ } -static int print_hex_vals(const char *data, int nbytes, FILE *fp) { +static int print_hex_vals(const char *data, int nbytes, FILE *fp) +{ int c; if (!data || nbytes < 1 || !fp) return -1; @@ -3307,7 +3366,8 @@ static int print_hex_vals(const char *data, int nbytes, FILE *fp) { \param info if non-NULL, print this character string \param hp pointer to nifti_1_header */ /*--------------------------------------------------------------------*/ -int disp_nifti_1_header(const char *info, const nifti_1_header *hp) { +int disp_nifti_1_header(const char *info, const nifti_1_header *hp) +{ int c; fputs("-------------------------------------------------------\n", stdout); @@ -3444,7 +3504,8 @@ int disp_nifti_1_header(const char *info, const nifti_1_header *hp) { \return an allocated nifti_image, or NULL on failure */ /*--------------------------------------------------------------------*/ -nifti_image *nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char *fname) { +nifti_image *nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char *fname) +{ int ii, doswap, ioff; int is_nifti, is_onefile; nifti_image *nim; @@ -3584,7 +3645,8 @@ nifti_image *nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char *fnam nim->qform_code = NIFTI_XFORM_UNKNOWN; if (g_opts.debug > 1) fprintf(stderr, "-d no qform provided\n"); - } else { + } + else { /**- else NIFTI: use the quaternion-specified transformation */ nim->quatern_b = FIXED_FLOAT(nhdr.quatern_b); @@ -3625,7 +3687,8 @@ nifti_image *nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char *fnam nim->sform_code = NIFTI_XFORM_UNKNOWN; if (g_opts.debug > 1) fprintf(stderr, "-d no sform provided\n"); - } else { + } + else { /**- else set the sto transformation from srow_*[] */ nim->sto_xyz.m[0][0] = nhdr.srow_x[0]; @@ -3702,7 +3765,8 @@ nifti_image *nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char *fnam if (is_onefile) { ioff = (int)nhdr.vox_offset; if (ioff < (int)sizeof(nhdr)) ioff = (int)sizeof(nhdr); - } else { + } + else { ioff = (int)nhdr.vox_offset; } nim->iname_offset = ioff; @@ -3713,7 +3777,8 @@ nifti_image *nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char *fnam if (nim->iname == NULL) { ERREX("bad filename"); } - } else { + } + else { nim->fname = NULL; nim->iname = NULL; } @@ -3755,7 +3820,8 @@ nifti_image *nifti_convert_nhdr2nim(struct nifti_1_header nhdr, const char *fnam
NULL if something fails badly. \sa nifti_image_load, nifti_image_free */ -znzFile nifti_image_open(const char *hname, char *opts, nifti_image **nim) { +znzFile nifti_image_open(const char *hname, char *opts, nifti_image **nim) +{ znzFile fptr = NULL; /* open the hdr and reading it in, but do not load the data */ *nim = nifti_image_read(hname, 0); @@ -3785,7 +3851,8 @@ znzFile nifti_image_open(const char *hname, char *opts, nifti_image **nim) { \sa nifti_image_read, nifti_image_free, nifti_image_read_bricks */ /*--------------------------------------------------------------------*/ -nifti_1_header *nifti_read_header(const char *hname, int *swapped, int check) { +nifti_1_header *nifti_read_header(const char *hname, int *swapped, int check) +{ nifti_1_header nhdr, *hptr; znzFile fp; int bytes, lswap; @@ -3797,7 +3864,8 @@ nifti_1_header *nifti_read_header(const char *hname, int *swapped, int check) { if (hfile == NULL) { if (g_opts.debug > 0) LNI_FERR(fname, "failed to find header file for", hname); return NULL; - } else if (g_opts.debug > 1) + } + else if (g_opts.debug > 1) fprintf(stderr, "-d %s: found header filename '%s'\n", fname, hfile); fp = znzopen(hfile, "rb", nifti_is_gzfile(hfile)); @@ -3871,7 +3939,8 @@ nifti_1_header *nifti_read_header(const char *hname, int *swapped, int check) { \sa nifti_nim_is_valid, valid_nifti_extensions */ /*--------------------------------------------------------------------*/ -int nifti_hdr_looks_good(const nifti_1_header *hdr) { +int nifti_hdr_looks_good(const nifti_1_header *hdr) +{ int nbyper, swapsize; int c, errs = 0; @@ -3933,7 +4002,8 @@ int nifti_hdr_looks_good(const nifti_1_header *hdr) { * 0 : does not need swap * < 0 : error condition *----------------------------------------------------------------------*/ -static int need_nhdr_swap(short dim0, int hdrsize) { +static int need_nhdr_swap(short dim0, int hdrsize) +{ short d0 = dim0; /* so we won't have to swap them on the stack */ int hsize = hdrsize; @@ -3990,7 +4060,8 @@ static int need_nhdr_swap(short dim0, int hdrsize) { \sa nifti_image_free, nifti_free_extensions, nifti_image_read_bricks */ -nifti_image *nifti_image_read(const char *hname, int read_data) { +nifti_image *nifti_image_read(const char *hname, int read_data) +{ struct nifti_1_header nhdr; nifti_image *nim; znzFile fp; @@ -4012,7 +4083,8 @@ nifti_image *nifti_image_read(const char *hname, int read_data) { if (hfile == NULL) { if (g_opts.debug > 0) LNI_FERR(fname, "failed to find header file for", hname); return NULL; /* check return */ - } else if (g_opts.debug > 1) + } + else if (g_opts.debug > 1) fprintf(stderr, "-d %s: found header filename '%s'\n", fname, hfile); if (nifti_is_gzfile(hfile)) @@ -4033,7 +4105,8 @@ nifti_image *nifti_image_read(const char *hname, int read_data) { znzclose(fp); free(hfile); return NULL; - } else if (rv == 1) /* process special file type */ + } + else if (rv == 1) /* process special file type */ return nifti_read_ascii_image(fp, hfile, filesize, read_data); /* else, just process normally */ @@ -4088,7 +4161,8 @@ nifti_image *nifti_image_read(const char *hname, int read_data) { nifti_image_free(nim); /* take ball, go home. */ return NULL; } - } else + } + else nim->data = NULL; return nim; @@ -4104,7 +4178,8 @@ nifti_image *nifti_image_read(const char *hname, int read_data) { * * NOTE: this is NOT part of the NIFTI-1 standard *----------------------------------------------------------------------*/ -static int has_ascii_header(znzFile fp) { +static int has_ascii_header(znzFile fp) +{ char buf[16]; int nread; @@ -4129,7 +4204,8 @@ static int has_ascii_header(znzFile fp) { NOTE: this is NOT part of the NIFTI-1 standard */ /*--------------------------------------------------------------------*/ -nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen, int read_data) { +nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen, int read_data) +{ nifti_image *nim; int slen, txt_size, remain, rv = 0; char *sbuf, lfunc[25] = {"nifti_read_ascii_image"}; @@ -4201,7 +4277,8 @@ nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen, int read_ * * return the number of extensions read in, or < 0 on error *----------------------------------------------------------------------*/ -static int nifti_read_extensions(nifti_image *nim, znzFile fp, int remain) { +static int nifti_read_extensions(nifti_image *nim, znzFile fp, int remain) +{ nifti1_extender extdr; /* defines extension existence */ nifti1_extension extn; /* single extension to process */ nifti1_extension *Elist; /* list of processed extensions */ @@ -4304,7 +4381,8 @@ static int nifti_read_extensions(nifti_image *nim, znzFile fp, int remain) { \return 0 on success, -1 on error (and free the entire list) */ /*--------------------------------------------------------------------*/ -int nifti_add_extension(nifti_image *nim, const char *data, int len, int ecode) { +int nifti_add_extension(nifti_image *nim, const char *data, int len, int ecode) +{ nifti1_extension ext; /* error are printed in functions */ @@ -4325,7 +4403,8 @@ int nifti_add_extension(nifti_image *nim, const char *data, int len, int ecode) return 0 on success, -1 on error (and free the entire list) */ /*--------------------------------------------------------------------*/ -static int nifti_add_exten_to_list(nifti1_extension *new_ext, nifti1_extension **list, int new_length) { +static int nifti_add_exten_to_list(nifti1_extension *new_ext, nifti1_extension **list, int new_length) +{ nifti1_extension *tmplist; tmplist = *list; @@ -4366,13 +4445,15 @@ static int nifti_add_exten_to_list(nifti1_extension *new_ext, nifti1_extension * return 0 on success, -1 on error (and free the entire list) */ /*--------------------------------------------------------------------*/ -static int nifti_fill_extension(nifti1_extension *ext, const char *data, int len, int ecode) { +static int nifti_fill_extension(nifti1_extension *ext, const char *data, int len, int ecode) +{ int esize; if (!ext || !data || len < 0) { fprintf(stderr, "** fill_ext: bad params (%p,%p,%d)\n", (void *)ext, data, len); return -1; - } else if (!nifti_is_valid_ecode(ecode)) { + } + else if (!nifti_is_valid_ecode(ecode)) { fprintf(stderr, "** fill_ext: invalid ecode %d\n", ecode); return -1; } @@ -4407,7 +4488,8 @@ static int nifti_fill_extension(nifti1_extension *ext, const char *data, int len * no extension : 0 * error : -1 *----------------------------------------------------------------------*/ -static int nifti_read_next_extension(nifti1_extension *nex, nifti_image *nim, int remain, znzFile fp) { +static int nifti_read_next_extension(nifti1_extension *nex, nifti_image *nim, int remain, znzFile fp) +{ int swap = nim->byteorder != nifti_short_order(); int count, size, code; @@ -4475,7 +4557,8 @@ static int nifti_read_next_extension(nifti1_extension *nex, nifti_image *nim, in /*----------------------------------------------------------------------*/ /*! for each extension, check code, size and data pointer */ /*--------------------------------------------------------------------*/ -int valid_nifti_extensions(const nifti_image *nim) { +int valid_nifti_extensions(const nifti_image *nim) +{ nifti1_extension *ext; int c, errs; @@ -4496,7 +4579,8 @@ int valid_nifti_extensions(const nifti_image *nim) { if (ext->esize <= 0) { if (g_opts.debug > 1) fprintf(stderr, "-d ext %d, bad size = %d\n", c, ext->esize); errs++; - } else if (ext->esize & 0xf) { + } + else if (ext->esize & 0xf) { if (g_opts.debug > 1) fprintf(stderr, "-d ext %d, size %d not multiple of 16\n", c, ext->esize); errs++; } @@ -4523,7 +4607,8 @@ int valid_nifti_extensions(const nifti_image *nim) { \return 1 if valid, 0 otherwise */ /*--------------------------------------------------------------------*/ -int nifti_is_valid_ecode(int ecode) { +int nifti_is_valid_ecode(int ecode) +{ if (ecode < NIFTI_ECODE_IGNORE || /* minimum code number (0) */ ecode > NIFTI_MAX_ECODE || /* maximum code number */ ecode & 1) /* cannot be odd */ @@ -4535,7 +4620,8 @@ int nifti_is_valid_ecode(int ecode) { /*---------------------------------------------------------------------- * check for valid size and code, as well as can be done *----------------------------------------------------------------------*/ -static int nifti_check_extension(nifti_image *nim, int size, int code, int rem) { +static int nifti_check_extension(nifti_image *nim, int size, int code, int rem) +{ /* check for bad code before bad size */ if (!nifti_is_valid_ecode(code)) { if (g_opts.debug > 2) fprintf(stderr, "-d invalid extension code %d\n", code); @@ -4573,7 +4659,8 @@ static int nifti_check_extension(nifti_image *nim, int size, int code, int rem) * * return NULL on failure *----------------------------------------------------------------------*/ -static znzFile nifti_image_load_prep(nifti_image *nim) { +static znzFile nifti_image_load_prep(nifti_image *nim) +{ /* set up data space, open data file and seek, then call nifti_read_buffer */ size_t ntot, ii, ioff; znzFile fp; @@ -4615,7 +4702,8 @@ static znzFile nifti_image_load_prep(nifti_image *nim) { return NULL; } ioff = (ii > ntot) ? ii - ntot : 0; - } else { /* non-negative offset */ + } + else { /* non-negative offset */ ioff = nim->iname_offset; /* means use it directly */ } @@ -4648,7 +4736,8 @@ static znzFile nifti_image_load_prep(nifti_image *nim) { \return 0 on success, -1 on failure \sa nifti_image_read, nifti_image_free, nifti_image_unload */ -int nifti_image_load(nifti_image *nim) { +int nifti_image_load(nifti_image *nim) +{ /* set up data space, open data file and seek, then call nifti_read_buffer */ size_t ntot, ii; znzFile fp; @@ -4704,7 +4793,8 @@ int nifti_image_load(nifti_image *nim) { This function does not allocate memory, so dataptr must be valid. */ /*--------------------------------------------------------------------*/ -size_t nifti_read_buffer(znzFile fp, void *dataptr, size_t ntot, nifti_image *nim) { +size_t nifti_read_buffer(znzFile fp, void *dataptr, size_t ntot, nifti_image *nim) +{ size_t ii; if (dataptr == NULL) { @@ -4778,7 +4868,8 @@ size_t nifti_read_buffer(znzFile fp, void *dataptr, size_t ntot, nifti_image *ni /*--------------------------------------------------------------------------*/ /*! Unload the data in a nifti_image struct, but keep the metadata. */ /*------------------------------------------------------------------------*/ -void nifti_image_unload(nifti_image *nim) { +void nifti_image_unload(nifti_image *nim) +{ if (nim != NULL && nim->data != NULL) { free(nim->data); nim->data = NULL; @@ -4796,7 +4887,8 @@ void nifti_image_unload(nifti_image *nim) { - ext_list - nim */ /*------------------------------------------------------------------------*/ -void nifti_image_free(nifti_image *nim) { +void nifti_image_free(nifti_image *nim) +{ if (nim == NULL) return; if (nim->fname != NULL) free(nim->fname); if (nim->iname != NULL) free(nim->iname); @@ -4817,7 +4909,8 @@ void nifti_image_free(nifti_image *nim) { \sa nifti_add_extension, nifti_copy_extensions */ /*------------------------------------------------------------------------*/ -int nifti_free_extensions(nifti_image *nim) { +int nifti_free_extensions(nifti_image *nim) +{ int c; if (nim == NULL) return -1; if (nim->num_ext > 0 && nim->ext_list) { @@ -4840,7 +4933,8 @@ int nifti_free_extensions(nifti_image *nim) { /*--------------------------------------------------------------------------*/ /*! Print to stdout some info about a nifti_image struct. */ /*------------------------------------------------------------------------*/ -void nifti_image_infodump(const nifti_image *nim) { +void nifti_image_infodump(const nifti_image *nim) +{ char *str = nifti_image_to_ascii(nim); /* stdout -> stderr 2 Dec 2004 [rickr] */ if (str != NULL) { @@ -4861,7 +4955,8 @@ void nifti_image_infodump(const nifti_image *nim) { \param numbytes number of bytes in buffer to write \return number of bytes successfully written */ -size_t nifti_write_buffer(znzFile fp, const void *buffer, size_t numbytes) { +size_t nifti_write_buffer(znzFile fp, const void *buffer, size_t numbytes) +{ /* Write all the image data at once (no swapping here) */ size_t ss; if (znz_isnull(fp)) { @@ -4891,7 +4986,8 @@ size_t nifti_write_buffer(znzFile fp, const void *buffer, size_t numbytes) { byte_order should match what is on disk, it should bet set to that of the current CPU whenever new filenames are assigned. */ /*--------------------------------------------------------------------*/ -int nifti_write_all_data(znzFile fp, nifti_image *nim, const nifti_brick_list *NBL) { +int nifti_write_all_data(znzFile fp, nifti_image *nim, const nifti_brick_list *NBL) +{ size_t ss; int bnum; @@ -4911,7 +5007,8 @@ int nifti_write_all_data(znzFile fp, nifti_image *nim, const nifti_brick_list *N } if (g_opts.debug > 1) fprintf(stderr, "+d wrote single image of %u bytes\n", (unsigned)ss); - } else { + } + else { if (!NBL->bricks || NBL->nbricks <= 0 || NBL->bsize <= 0) { fprintf(stderr, "** NWAD: no brick data to write (%p,%d,%u)\n", @@ -4944,7 +5041,8 @@ int nifti_write_all_data(znzFile fp, nifti_image *nim, const nifti_brick_list *N } /* return number of extensions written, or -1 on error */ -static int nifti_write_extensions(znzFile fp, nifti_image *nim) { +static int nifti_write_extensions(znzFile fp, nifti_image *nim) +{ nifti1_extension *list; char extdr[4] = {0, 0, 0, 0}; int c, size, ok = 1; @@ -5002,7 +5100,8 @@ static int nifti_write_extensions(znzFile fp, nifti_image *nim) { /*----------------------------------------------------------------------*/ /*! basic initialization of a nifti_image struct (to a 1x1x1 image) */ /*--------------------------------------------------------------------*/ -nifti_image *nifti_simple_init_nim(void) { +nifti_image *nifti_simple_init_nim(void) +{ nifti_image *nim; struct nifti_1_header nhdr; int nbyper, swapsize; @@ -5046,7 +5145,8 @@ nifti_image *nifti_simple_init_nim(void) { \return pointer to allocated nifti_1_header struct */ /*--------------------------------------------------------------------*/ -nifti_1_header *nifti_make_new_header(const int arg_dims[], int arg_dtype) { +nifti_1_header *nifti_make_new_header(const int arg_dims[], int arg_dtype) +{ nifti_1_header *nhdr; const int default_dims[8] = {3, 1, 1, 1, 0, 0, 0, 0}; const int *dim; /* either passed or default dims */ @@ -5063,7 +5163,8 @@ nifti_1_header *nifti_make_new_header(const int arg_dims[], int arg_dtype) { if (dim[0] < 1 || dim[0] > 7) { fprintf(stderr, "** nifti_simple_hdr_with_dims: bad dim[0]=%d\n", dim[0]); dim = default_dims; - } else { + } + else { for (c = 1; c <= dim[0]; c++) if (dim[c] < 1) { fprintf(stderr, "** nifti_simple_hdr_with_dims: bad dim[%d]=%d\n", c, dim[c]); @@ -5121,7 +5222,8 @@ nifti_1_header *nifti_make_new_header(const int arg_dims[], int arg_dtype) { \return pointer to allocated nifti_image struct */ /*--------------------------------------------------------------------*/ -nifti_image *nifti_make_new_nim(const int dims[], int datatype, int data_fill) { +nifti_image *nifti_make_new_nim(const int dims[], int datatype, int data_fill) +{ nifti_image *nim; nifti_1_header *nhdr; @@ -5161,7 +5263,8 @@ nifti_image *nifti_make_new_nim(const int dims[], int datatype, int data_fill) { my_header = nifti_convert_nim2nhdr(my_nim_pointer); */ /*--------------------------------------------------------------------*/ -struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image *nim) { +struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image *nim) +{ struct nifti_1_header nhdr; memset(&nhdr, 0, sizeof(nhdr)); /* zero out header, to be safe */ @@ -5288,7 +5391,8 @@ struct nifti_1_header nifti_convert_nim2nhdr(const nifti_image *nim) { \sa nifti_add_extension, nifti_free_extensions */ -int nifti_copy_extensions(nifti_image *nim_dest, const nifti_image *nim_src) { +int nifti_copy_extensions(nifti_image *nim_dest, const nifti_image *nim_src) +{ char *data; size_t bytes; int c, size, old_size; @@ -5347,7 +5451,8 @@ int nifti_copy_extensions(nifti_image *nim_dest, const nifti_image *nim_src) { and the bytes used for the data. Each esize also needs to be a multiple of 16, so it may be greater than the sum of its 3 parts. */ /*--------------------------------------------------------------------*/ -int nifti_extension_size(nifti_image *nim) { +int nifti_extension_size(nifti_image *nim) +{ int c, size = 0; if (!nim || nim->num_ext <= 0) return 0; @@ -5372,7 +5477,8 @@ int nifti_extension_size(nifti_image *nim) { 352 + total extension size, then align to 16-byte boundary - if writing an ASCII header, set offset to -1 */ /*--------------------------------------------------------------------*/ -void nifti_set_iname_offset(nifti_image *nim) { +void nifti_set_iname_offset(nifti_image *nim) +{ int offset; switch (nim->nifti_type) { @@ -5411,7 +5517,8 @@ void nifti_set_iname_offset(nifti_image *nim) { \sa nifti_image_write, nifti_image_write_hdr_img2, nifti_image_free, nifti_set_filenames */ /*--------------------------------------------------------------------*/ -znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data, const char *opts) { +znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data, const char *opts) +{ return nifti_image_write_hdr_img2(nim, write_data, opts, NULL, NULL); } @@ -5448,7 +5555,8 @@ znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data, const char * * nifti_set_filenames */ /*---------------------------------------------------------------------*/ znzFile nifti_image_write_hdr_img2( - nifti_image *nim, int write_opts, const char *opts, znzFile imgfile, const nifti_brick_list *NBL) { + nifti_image *nim, int write_opts, const char *opts, znzFile imgfile, const nifti_brick_list *NBL) +{ struct nifti_1_header nhdr; znzFile fp = NULL; size_t ss; @@ -5490,7 +5598,8 @@ znzFile nifti_image_write_hdr_img2( if (!znz_isnull(imgfile) && nim->nifti_type == NIFTI_FTYPE_NIFTI1_1) { if (g_opts.debug > 2) fprintf(stderr, "+d using passed file for hdr\n"); fp = imgfile; - } else { + } + else { if (g_opts.debug > 2) fprintf(stderr, "+d opening output file %s [%s]\n", nim->fname, opts); fp = znzopen(nim->fname, opts, nifti_is_gzfile(nim->fname)); if (znz_isnull(fp)) { @@ -5523,7 +5632,8 @@ znzFile nifti_image_write_hdr_img2( if (!znz_isnull(imgfile)) { if (g_opts.debug > 2) fprintf(stderr, "+d using passed file for img\n"); fp = imgfile; - } else { + } + else { if (g_opts.debug > 2) fprintf(stderr, "+d opening img file '%s'\n", nim->iname); fp = znzopen(nim->iname, opts, nifti_is_gzfile(nim->iname)); if (znz_isnull(fp)) ERREX("cannot open image file"); @@ -5542,7 +5652,8 @@ znzFile nifti_image_write_hdr_img2( /*! write a nifti_image to disk in ASCII format */ /*--------------------------------------------------------------------*/ znzFile nifti_write_ascii_image( - nifti_image *nim, const nifti_brick_list *NBL, const char *opts, int write_data, int leave_open) { + nifti_image *nim, const nifti_brick_list *NBL, const char *opts, int write_data, int leave_open) +{ znzFile fp; char *hstr; @@ -5597,7 +5708,8 @@ znzFile nifti_write_ascii_image( \sa nifti_image_write_bricks, nifti_image_free, nifti_set_filenames, nifti_image_write_hdr_img */ /*------------------------------------------------------------------------*/ -void nifti_image_write(nifti_image *nim) { +void nifti_image_write(nifti_image *nim) +{ znzFile fp = nifti_image_write_hdr_img(nim, 1, "wb"); if (fp) { if (g_opts.debug > 2) fprintf(stderr, "-d niw: done with znzFile\n"); @@ -5611,7 +5723,8 @@ void nifti_image_write(nifti_image *nim) { \sa nifti_image_write, nifti_image_free, nifti_set_filenames, nifti_free_NBL */ /*--------------------------------------------------------------------*/ -void nifti_image_write_bricks(nifti_image *nim, const nifti_brick_list *NBL) { +void nifti_image_write_bricks(nifti_image *nim, const nifti_brick_list *NBL) +{ znzFile fp = nifti_image_write_hdr_img2(nim, 1, "wb", NULL, NBL); if (fp) { if (g_opts.debug > 2) fprintf(stderr, "-d niwb: done with znzFile\n"); @@ -5626,7 +5739,8 @@ void nifti_image_write_bricks(nifti_image *nim, const nifti_brick_list *NBL) { Duplicate the structure, including fname, iname and extensions. Leave the data pointer as NULL. */ /*--------------------------------------------------------------------*/ -nifti_image *nifti_copy_nim_info(const nifti_image *src) { +nifti_image *nifti_copy_nim_info(const nifti_image *src) +{ nifti_image *dest; dest = (nifti_image *)calloc(1, sizeof(nifti_image)); if (!dest) { @@ -5665,7 +5779,8 @@ nifti_image *nifti_copy_nim_info(const nifti_image *src) { #define CR 0x0D #define LF 0x0A -static int unescape_string(char *str) { +static int unescape_string(char *str) +{ int ii, jj, nn, ll; if (str == NULL) return 0; /* no string? */ @@ -5746,7 +5861,8 @@ static int unescape_string(char *str) { else if (jj < ii) { str[jj] = str[ii]; } - } else if (str[ii] == CR) { /* is a carriage return */ + } + else if (str[ii] == CR) { /* is a carriage return */ if (str[ii + 1] == LF) { str[jj] = LF; @@ -5757,8 +5873,9 @@ static int unescape_string(char *str) { str[jj] = LF; ; nn++; - } /* CR only */ - } else { /* is a normal character, just copy to output */ + } /* CR only */ + } + else { /* is a normal character, just copy to output */ if (jj < ii) { str[jj] = str[ii]; @@ -5780,7 +5897,8 @@ static int unescape_string(char *str) { The result should be free()-ed when you are done with it. --------------------------------------------------------------------------*/ -static char *escapize_string(const char *str) { +static char *escapize_string(const char *str) +{ int ii, jj, lstr, lout; char *out; @@ -5875,7 +5993,8 @@ static char *escapize_string(const char *str) { The resulting string can be free()-ed when you are done with it. */ /*-------------------------------------------------------------------------*/ -char *nifti_image_to_ascii(const nifti_image *nim) { +char *nifti_image_to_ascii(const nifti_image *nim) +{ char *buf, *ebuf; int nbuf; @@ -6198,7 +6317,8 @@ int nifti_short_order(void) /* determine this CPU's byte order */ - Not a lot of error checking is done here to make sure that the input values are reasonable! */ /*-------------------------------------------------------------------------*/ -nifti_image *nifti_image_from_ascii(const char *str, int *bytes_read) { +nifti_image *nifti_image_from_ascii(const char *str, int *bytes_read) +{ char lhs[1024], rhs[1024]; int ii, spos, nn, slen; nifti_image *nim; /* will be output */ @@ -6256,7 +6376,8 @@ nifti_image *nifti_image_from_ascii(const char *str, int *bytes_read) { memcpy(rhs, str + spos + 1, nn); rhs[nn] = '\0'; spos = (str[ii] == '\'') ? ii + 1 : ii; - } else { + } + else { ii = sscanf(str + spos, "%1023s%n", rhs, &nn); spos += nn; if (ii == 0) break; /* nothing found? */ @@ -6275,11 +6396,14 @@ nifti_image *nifti_image_from_ascii(const char *str, int *bytes_read) { nim->nifti_type = NIFTI_FTYPE_NIFTI1_2; else if (strcmp(rhs, "NIFTI-1A") == 0) nim->nifti_type = NIFTI_FTYPE_ASCII; - } else if (strcmp(lhs, "header_filename") == 0) { + } + else if (strcmp(lhs, "header_filename") == 0) { nim->fname = nifti_strdup(rhs); - } else if (strcmp(lhs, "image_filename") == 0) { + } + else if (strcmp(lhs, "image_filename") == 0) { nim->iname = nifti_strdup(rhs); - } else if (strcmp(lhs, "sto_xyz_matrix") == 0) { + } + else if (strcmp(lhs, "sto_xyz_matrix") == 0) { sscanf(rhs, "%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", &(nim->sto_xyz.m[0][0]), @@ -6298,10 +6422,12 @@ nifti_image *nifti_image_from_ascii(const char *str, int *bytes_read) { &(nim->sto_xyz.m[3][1]), &(nim->sto_xyz.m[3][2]), &(nim->sto_xyz.m[3][3])); - } else if (strcmp(lhs, "byteorder") == 0) { + } + else if (strcmp(lhs, "byteorder") == 0) { if (strcmp(rhs, "MSB_FIRST") == 0) nim->byteorder = MSB_FIRST; if (strcmp(rhs, "LSB_FIRST") == 0) nim->byteorder = LSB_FIRST; - } else + } + else QQNUM(image_offset, iname_offset); else QNUM(datatype); else QNUM(ndim); @@ -6414,7 +6540,8 @@ nifti_image *nifti_image_from_ascii(const char *str, int *bytes_read) { \sa nifti_nim_has_valid_dims, nifti_hdr_looks_good */ /*-------------------------------------------------------------------------*/ -int nifti_nim_is_valid(nifti_image *nim, int complain) { +int nifti_nim_is_valid(nifti_image *nim, int complain) +{ int errs = 0; if (!nim) { @@ -6448,7 +6575,8 @@ int nifti_nim_is_valid(nifti_image *nim, int complain) { rely on dim[] as the master */ /*-------------------------------------------------------------------------*/ -int nifti_nim_has_valid_dims(nifti_image *nim, int complain) { +int nifti_nim_has_valid_dims(nifti_image *nim, int complain) +{ size_t prod; int c, errs = 0; @@ -6606,7 +6734,8 @@ int nifti_nim_has_valid_dims(nifti_image *nim, int complain) { \sa nifti_image_read, nifti_image_free, nifti_image_read_bricks nifti_image_load */ /*-------------------------------------------------------------------------*/ -int nifti_read_collapsed_image(nifti_image *nim, const int dims[8], void **data) { +int nifti_read_collapsed_image(nifti_image *nim, const int dims[8], void **data) +{ znzFile fp; int pivots[8], prods[8], nprods; /* sizes are bounded by dims[], so 8 */ int c, bytes; @@ -6671,7 +6800,8 @@ int nifti_read_collapsed_image(nifti_image *nim, const int dims[8], void **data) /* local function to find strides per dimension. assumes 7D size and ** stride array. */ -static void compute_strides(int *strides, const int *size, int nbyper) { +static void compute_strides(int *strides, const int *size, int nbyper) +{ int i; strides[0] = nbyper; for (i = 1; i < 7; i++) { @@ -6708,7 +6838,8 @@ static void compute_strides(int *strides, const int *size, int nbyper) { \sa nifti_image_read, nifti_image_free, nifti_image_read_bricks nifti_image_load, nifti_read_collapsed_image */ /*-------------------------------------------------------------------------*/ -int nifti_read_subregion_image(nifti_image *nim, int *start_index, int *region_size, void **data) { +int nifti_read_subregion_image(nifti_image *nim, int *start_index, int *region_size, void **data) +{ znzFile fp; /* file to read */ int i, j, k, l, m, n; /* indices for dims */ long int bytes = 0; /* total # bytes read */ @@ -6732,7 +6863,8 @@ int nifti_read_subregion_image(nifti_image *nim, int *start_index, int *region_s /* if you specify a single element in this dimension */ else if (region_size[i] == 1) { collapsed_dims[i + 1] = start_index[i]; - } else { + } + else { collapsed_dims[i + 1] = -2; /* sentinel value */ } } @@ -6848,14 +6980,9 @@ int nifti_read_subregion_image(nifti_image *nim, int *start_index, int *region_s return 0 on success, < 0 on failure */ -static int rci_read_data(nifti_image *nim, - int *pivots, - int *prods, - int nprods, - const int dims[], - char *data, - znzFile fp, - size_t base_offset) { +static int rci_read_data( + nifti_image *nim, int *pivots, int *prods, int nprods, const int dims[], char *data, znzFile fp, size_t base_offset) +{ size_t sublen, offset, read_size; int c; @@ -6882,7 +7009,8 @@ static int rci_read_data(nifti_image *nim, if (nread != bytes) { fprintf(stderr, "** rciRD: read only %u of %u bytes from '%s'\n", (unsigned)nread, (unsigned)bytes, nim->fname); return -1; - } else if (g_opts.debug > 3) + } + else if (g_opts.debug > 3) fprintf(stderr, "+d successful read of %u bytes at offset %u\n", (unsigned)bytes, (unsigned)base_offset); return 0; /* done with base case - return success */ @@ -6928,7 +7056,8 @@ static int rci_read_data(nifti_image *nim, return total size on success, and < 0 on failure */ -static int rci_alloc_mem(void **data, int prods[8], int nprods, int nbyper) { +static int rci_alloc_mem(void **data, int prods[8], int nprods, int nbyper) +{ int size, index; if (nbyper < 0 || nprods < 1 || nprods > 8) { @@ -6949,7 +7078,8 @@ static int rci_alloc_mem(void **data, int prods[8], int nprods, int nbyper) { fprintf(stderr, "** rci_am: failed to alloc %d bytes for data\n", size); return -1; } - } else if (g_opts.debug > 1) + } + else if (g_opts.debug > 1) fprintf(stderr, "-d rci_am: *data already set, need %d (%d x %d) bytes\n", size, size / nbyper, nbyper); return size; @@ -6961,7 +7091,8 @@ static int rci_alloc_mem(void **data, int prods[8], int nprods, int nbyper) { wants to collapse a dimension. The last pivot should always be zero (note that we have space for that in the lists). */ -static int make_pivot_list(nifti_image *nim, const int dims[], int pivots[], int prods[], int *nprods) { +static int make_pivot_list(nifti_image *nim, const int dims[], int pivots[], int prods[], int *nprods) +{ int len, index; len = 0; @@ -7025,7 +7156,8 @@ static int make_pivot_list(nifti_image *nim, const int dims[], int pivots[], int (borrowed, with permission, from thd_intlist.c) */ /*-------------------------------------------------------------------*/ -int *nifti_get_intlist(int nvals, const char *str) { +int *nifti_get_intlist(int nvals, const char *str) +{ int *subv = NULL; int ii, ipos, nout, slen; int ibot, itop, istep, nused; @@ -7058,7 +7190,8 @@ int *nifti_get_intlist(int nvals, const char *str) { if (str[ipos] == '$') { /* special case */ ibot = nvals - 1; ipos++; - } else { /* decode an integer */ + } + else { /* decode an integer */ ibot = strtol(str + ipos, &cpt, 10); if (ibot < 0) { fprintf(stderr, "** ERROR: list index %d is out of range 0..%d\n", ibot, nvals - 1); @@ -7097,10 +7230,12 @@ int *nifti_get_intlist(int nvals, const char *str) { if (str[ipos] == '-') { ipos++; - } else if (str[ipos] == '.' && str[ipos + 1] == '.') { + } + else if (str[ipos] == '.' && str[ipos + 1] == '.') { ipos++; ipos++; - } else { + } + else { fprintf(stderr, "** ERROR: index list syntax is bad: '%s'\n", str + ipos); free(subv); return NULL; @@ -7111,7 +7246,8 @@ int *nifti_get_intlist(int nvals, const char *str) { if (str[ipos] == '$') { /* special case */ itop = nvals - 1; ipos++; - } else { /* decode an integer */ + } + else { /* decode an integer */ itop = strtol(str + ipos, &cpt, 10); if (itop < 0) { fprintf(stderr, "** ERROR: index %d is out of range 0..%d\n", itop, nvals - 1); @@ -7190,7 +7326,8 @@ int *nifti_get_intlist(int nvals, const char *str) { * corresponding integral type code. The type code is the macro * value defined in nifti1.h. */ /*-------------------------------------------------------------------*/ -int nifti_datatype_from_string(const char *name) { +int nifti_datatype_from_string(const char *name) +{ int tablen = sizeof(nifti_type_list) / sizeof(nifti_type_ele); int c; @@ -7207,7 +7344,8 @@ int nifti_datatype_from_string(const char *name) { * corresponding macro label as a string. The dtype code is the * macro value defined in nifti1.h. */ /*-------------------------------------------------------------------*/ -char *nifti_datatype_to_string(int dtype) { +char *nifti_datatype_to_string(int dtype) +{ int tablen = sizeof(nifti_type_list) / sizeof(nifti_type_ele); int c; @@ -7224,7 +7362,8 @@ char *nifti_datatype_to_string(int dtype) { * * return the number of errors (so 0 is success, as usual) */ /*-------------------------------------------------------------------*/ -int nifti_test_datatype_sizes(int verb) { +int nifti_test_datatype_sizes(int verb) +{ int tablen = sizeof(nifti_type_list) / sizeof(nifti_type_ele); int nbyper, ssize; int c, errs = 0; @@ -7261,7 +7400,8 @@ int nifti_test_datatype_sizes(int verb) { * if which == 2 : display NIFTI_TYPE* * else : display all */ /*-------------------------------------------------------------------*/ -int nifti_disp_type_list(int which) { +int nifti_disp_type_list(int which) +{ char *style; int tablen = sizeof(nifti_type_list) / sizeof(nifti_type_ele); int lwhich, c; @@ -7269,10 +7409,12 @@ int nifti_disp_type_list(int which) { if (which == 1) { lwhich = 1; style = "DT_"; - } else if (which == 2) { + } + else if (which == 2) { lwhich = 2; style = "NIFTI_TYPE_"; - } else { + } + else { lwhich = 3; style = "ALL"; } diff --git a/utils/numerics.cpp b/utils/numerics.cpp index 563816c1319..276d16dd561 100644 --- a/utils/numerics.cpp +++ b/utils/numerics.cpp @@ -67,7 +67,8 @@ void (*user_call_func)(float[]) = NULL; static void ConvertFromFloatToVNLDouble(const float *iaSource, vnl_vector< double > &oDestination, - const int icSourceAndDestination) { + const int icSourceAndDestination) +{ // indexing p at 1 because of NR legacy for (int nDest = 0; nDest < icSourceAndDestination; nDest++) { oDestination(nDest) = static_cast< double >(iaSource[nDest + 1]); @@ -76,7 +77,8 @@ static void ConvertFromFloatToVNLDouble(const float *iaSource, static void ConvertFromVNLDoubleToFloat(const vnl_vector< double > iSource, float *oaDestination, - const int icSourceAndDestination) { + const int icSourceAndDestination) +{ // indexing p at 1 because of NR legacy for (int i = 0; i < icSourceAndDestination; i++) { oaDestination[i + 1] = static_cast< float >(iSource(i)); @@ -85,7 +87,8 @@ static void ConvertFromVNLDoubleToFloat(const vnl_vector< double > iSource, static void ConvertFromFloatToVNLDouble(float **iaSource, vnl_matrix< double > &oDestination, - const int icSourceAndDestination) { + const int icSourceAndDestination) +{ // indexing p at 1 because of NR legacy for (int row = 0; row < icSourceAndDestination; row++) { for (int col = 0; col < icSourceAndDestination; col++) { @@ -96,7 +99,8 @@ static void ConvertFromFloatToVNLDouble(float **iaSource, static void ConvertFromVNLDoubleToFloat(const vnl_matrix< double > iSource, float **oaDestination, - const int icSourceAndDestination) { + const int icSourceAndDestination) +{ // indexing p at 1 because of NR legacy for (int row = 0; row < icSourceAndDestination; row++) { for (int col = 0; col < icSourceAndDestination; col++) { @@ -135,7 +139,8 @@ static double d_huge() { return HUGE_VAL; } * * @return floating point round-off unit. */ -static double d_epsilon() { +static double d_epsilon() +{ double r; r = 1.0; @@ -221,7 +226,8 @@ static double d_epsilon() { * If X <= 0.0, or if overflow would occur, the program returns the * value XINF, the largest representable floating point number. */ -static double gamma_log(double x) { +static double gamma_log(double x) +{ double c[7] = {-1.910444077728E-03, 8.4171387781295E-04, -5.952379913043012E-04, @@ -302,11 +308,13 @@ static double gamma_log(double x) { if (x <= d_epsilon()) { res = -log(x); - } else if (x <= 1.5) { + } + else if (x <= 1.5) { if (x < pnt68) { corr = -log(x); xm1 = x; - } else { + } + else { corr = 0.0; xm1 = (x - 0.5) - 0.5; } @@ -321,7 +329,8 @@ static double gamma_log(double x) { } res = corr + (xm1 * (d1 + xm1 * (xnum / xden))); - } else { + } + else { xm2 = (x - 0.5) - 0.5; xden = 1.0; xnum = 0.0; @@ -332,7 +341,8 @@ static double gamma_log(double x) { res = corr + xm2 * (d2 + xm2 * (xnum / xden)); } - } else if (x <= 4.0) { + } + else if (x <= 4.0) { xm2 = x - 2.0; xden = 1.0; xnum = 0.0; @@ -342,7 +352,8 @@ static double gamma_log(double x) { } res = xm2 * (d2 + xm2 * (xnum / xden)); - } else if (x <= 12.0) { + } + else if (x <= 12.0) { xm4 = x - 4.0; xden = -1.0; xnum = 0.0; @@ -352,7 +363,8 @@ static double gamma_log(double x) { } res = d4 + xm4 * (xnum / xden); - } else { + } + else { res = 0.0; if (x <= frtbig) { @@ -397,7 +409,8 @@ static double gamma_log(double x) { * @param y Parameter that define the Beta function. Must be greater than 0. * @return Value of the Beta function. */ -static double beta(double x, double y) { +static double beta(double x, double y) +{ if (x <= 0.0 || y <= 0.0) { std::cout << "\n"; std::cout << "BETA - Fatal error!\n"; @@ -443,7 +456,8 @@ static double beta(double x, double y) { * @param x Argument of the function. Normally, 0.0 <= x <= 1.0. * @return Value of the function. */ -extern "C" float OpenBetaIncomplete(float a, float b, float x) { +extern "C" float OpenBetaIncomplete(float a, float b, float x) +{ double cx; int i; int it; @@ -477,7 +491,8 @@ extern "C" float OpenBetaIncomplete(float a, float b, float x) { if (x <= 0.0) { value = 0.0; return value; - } else if (1.0 <= x) { + } + else if (1.0 <= x) { value = 1.0; return value; } @@ -492,7 +507,8 @@ extern "C" float OpenBetaIncomplete(float a, float b, float x) { pp = b; qq = a; indx = true; - } else { + } + else { xx = x; cx = 1.0 - x; pp = a; @@ -548,7 +564,8 @@ extern "C" float OpenBetaIncomplete(float a, float b, float x) { if (ns == 0) { rx = xx; } - } else { + } + else { temp = psq; psq = psq + 1.0; } @@ -575,10 +592,12 @@ extern "C" float OpenBetaIncomplete(float a, float b, float x) { * @param y Quantity to compare. * @return Minimum of x and y. */ -static double d_min(double x, double y) { +static double d_min(double x, double y) +{ if (y < x) { return y; - } else { + } + else { return x; } } @@ -599,7 +618,8 @@ static double d_min(double x, double y) { * @param X The argument of the CDF. * @return The value of the CDF. */ -double normal_01_cdf(double x) { +double normal_01_cdf(double x) +{ double a1 = 0.398942280444; double a2 = 0.399903438504; double a3 = 5.75885480458; @@ -632,7 +652,8 @@ double normal_01_cdf(double x) { // // 1.28 < |X| <= 12.7 // - } else if (fabs(x) <= 12.7) { + } + else if (fabs(x) <= 12.7) { y = 0.5 * x * x; q = exp(-y) * b0 / @@ -641,7 +662,8 @@ double normal_01_cdf(double x) { // // 12.7 < |X| // - } else { + } + else { q = 0.0; } // @@ -649,7 +671,8 @@ double normal_01_cdf(double x) { // if (x < 0.0) { cdf = q; - } else { + } + else { cdf = 1.0 - q; } @@ -685,7 +708,8 @@ double normal_01_cdf(double x) { * GAMMA_INC is returned as 0. * @return The value of the function. */ -extern "C" float OpenGammaIncomplete(float p, float x) { +extern "C" float OpenGammaIncomplete(float p, float x) +{ double a; double arg; double b; @@ -756,7 +780,8 @@ extern "C" float OpenGammaIncomplete(float p, float x) { if (exp_arg_min <= arg) { value = exp(arg); - } else { + } + else { value = 0.0; } } @@ -789,7 +814,8 @@ extern "C" float OpenGammaIncomplete(float p, float x) { if (exp_arg_min <= arg) { value = 1.0 - exp(arg); - } else { + } + else { value = 1.0; } @@ -825,7 +851,8 @@ extern "C" int OpenDFPMin(float p[], void (*iDerivativeFunction)(float[], float[]), void (*iStepFunction)(int, float, void *, float *), void *iStepFunctionParams, - void (*iUserCallBackFunction)(float[])) { + void (*iUserCallBackFunction)(float[])) +{ int returnCode; fs_cost_function costFunction(iFunction, iDerivativeFunction, n); @@ -873,7 +900,8 @@ extern "C" int OpenDFPMin(float p[], *oFinalFunctionReturn = minimizer.get_end_error(); ConvertFromVNLDoubleToFloat(finalParameters, p, n); returnCode = 0; - } else { + } + else { returnCode = minimizer.get_failure_code(); if (returnCode == vnl_nonlinear_minimizer::ERROR_FAILURE) { @@ -881,12 +909,14 @@ extern "C" int OpenDFPMin(float p[], *oFinalFunctionReturn = minimizer.get_end_error(); ConvertFromVNLDoubleToFloat(finalParameters, p, n); - } else if (returnCode == vnl_nonlinear_minimizer::ERROR_DODGY_INPUT) { + } + else if (returnCode == vnl_nonlinear_minimizer::ERROR_DODGY_INPUT) { ErrorExit(ERROR_BADPARM, "quasi-Newton minimization (lbfsg) dodgy input"); - } else if (returnCode == vnl_nonlinear_minimizer::FAILED_TOO_MANY_ITERATIONS || - returnCode == vnl_nonlinear_minimizer::FAILED_FTOL_TOO_SMALL || - returnCode == vnl_nonlinear_minimizer::FAILED_XTOL_TOO_SMALL || - returnCode == vnl_nonlinear_minimizer::FAILED_GTOL_TOO_SMALL) { + } + else if (returnCode == vnl_nonlinear_minimizer::FAILED_TOO_MANY_ITERATIONS || + returnCode == vnl_nonlinear_minimizer::FAILED_FTOL_TOO_SMALL || + returnCode == vnl_nonlinear_minimizer::FAILED_XTOL_TOO_SMALL || + returnCode == vnl_nonlinear_minimizer::FAILED_GTOL_TOO_SMALL) { ErrorExit(ERROR_BADPARM, "quasi-Newton minimization (lbfsg) tolerances too small"); } } @@ -896,7 +926,8 @@ extern "C" int OpenDFPMin(float p[], /** * Provides the eigen values and vectors for symmetric matrices. */ -extern "C" int OpenEigenSystem(float *iaData, int icData, float *oEigenValues, float *oEigenVectors) { +extern "C" int OpenEigenSystem(float *iaData, int icData, float *oEigenValues, float *oEigenVectors) +{ vnl_matrix< float > vnlMatrix(iaData, icData, icData); vnl_symmetric_eigensystem< float > eigenSystem(vnlMatrix); @@ -913,7 +944,8 @@ extern "C" int OpenEigenSystem(float *iaData, int icData, float *oEigenValues, f /** * Provides the eigen values and vectors for symmetric matrices. */ -extern "C" int OpenNonSymmetricEigenSystem(float *iaData, int icData, float *oEigenValues, float *oEigenVectors) { +extern "C" int OpenNonSymmetricEigenSystem(float *iaData, int icData, float *oEigenValues, float *oEigenVectors) +{ // convert the data into a double double data[icData * icData]; for (int row = 0; row < icData; row++) { @@ -950,7 +982,8 @@ extern "C" void OpenPowell(float iaParams[], float iTolerance, int *oIterations, float *oFinalFunctionReturn, - float (*iFunction)(float[])) { + float (*iFunction)(float[])) +{ fs_cost_function costFunction(iFunction); fs_powell minimizer(&costFunction); @@ -970,11 +1003,13 @@ extern "C" void OpenPowell(float iaParams[], // exit if failure if (returnCode == vnl_nonlinear_minimizer::FAILED_TOO_MANY_ITERATIONS) { ErrorExit(ERROR_BADPARM, "powell exceeding maximum iterations."); - } else if (returnCode == fs_powell::ERROR_FAILURE || returnCode == fs_powell::ERROR_DODGY_INPUT || - returnCode == fs_powell::FAILED_FTOL_TOO_SMALL || returnCode == fs_powell::FAILED_XTOL_TOO_SMALL || - returnCode == fs_powell::FAILED_GTOL_TOO_SMALL) { + } + else if (returnCode == fs_powell::ERROR_FAILURE || returnCode == fs_powell::ERROR_DODGY_INPUT || + returnCode == fs_powell::FAILED_FTOL_TOO_SMALL || returnCode == fs_powell::FAILED_XTOL_TOO_SMALL || + returnCode == fs_powell::FAILED_GTOL_TOO_SMALL) { ErrorExit(ERROR_BADPARM, "powell error."); - } else { + } + else { // success *oIterations = minimizer.get_num_iterations(); *oFinalFunctionReturn = minimizer.get_end_error(); @@ -1006,7 +1041,8 @@ extern "C" int OpenPowell2(float iaParams[], int MaxIterations, int *oIterations, float *oFinalFunctionReturn, - float (*iFunction)(float[])) { + float (*iFunction)(float[])) +{ fs_cost_function costFunction(iFunction); fs_powell minimizer(&costFunction); @@ -1039,9 +1075,10 @@ extern "C" int OpenPowell2(float iaParams[], if (returnCode == vnl_nonlinear_minimizer::FAILED_TOO_MANY_ITERATIONS) { printf("powell exceeded maximum iterations\n"); return (1); - } else if (returnCode == fs_powell::ERROR_FAILURE || returnCode == fs_powell::ERROR_DODGY_INPUT || - returnCode == fs_powell::FAILED_FTOL_TOO_SMALL || returnCode == fs_powell::FAILED_XTOL_TOO_SMALL || - returnCode == fs_powell::FAILED_GTOL_TOO_SMALL) { + } + else if (returnCode == fs_powell::ERROR_FAILURE || returnCode == fs_powell::ERROR_DODGY_INPUT || + returnCode == fs_powell::FAILED_FTOL_TOO_SMALL || returnCode == fs_powell::FAILED_XTOL_TOO_SMALL || + returnCode == fs_powell::FAILED_GTOL_TOO_SMALL) { printf("powell error %d\n", returnCode); return (1); } @@ -1050,7 +1087,8 @@ extern "C" int OpenPowell2(float iaParams[], return (0); } -extern "C" int OpenLUMatrixInverse(MATRIX *iMatrix, MATRIX *oInverse) { +extern "C" int OpenLUMatrixInverse(MATRIX *iMatrix, MATRIX *oInverse) +{ // NO_ERROR from error.h int errorCode = NO_ERROR; @@ -1063,19 +1101,22 @@ extern "C" int OpenLUMatrixInverse(MATRIX *iMatrix, MATRIX *oInverse) { errorCode = ERROR_BADPARM; else oInverse->data[0] = 1.0 / vnlMatrix(0, 0); - } else if (r == 2) { + } + else if (r == 2) { vnl_matrix_fixed< float, 2, 2 > m(vnlMatrix); if (vnl_det(m) == 0.0) errorCode = ERROR_BADPARM; else vnl_inverse(m).copy_out(oInverse->data); - } else if (r == 3) { + } + else if (r == 3) { vnl_matrix_fixed< float, 3, 3 > m(vnlMatrix); if (vnl_det(m) == 0.0) errorCode = ERROR_BADPARM; else vnl_inverse(m).copy_out(oInverse->data); - } else { + } + else { vnl_matrix_fixed< float, 4, 4 > m(vnlMatrix); if (vnl_det(m) == 0.0) errorCode = ERROR_BADPARM; @@ -1094,7 +1135,8 @@ extern "C" int OpenLUMatrixInverse(MATRIX *iMatrix, MATRIX *oInverse) { if (vnlMatrixInverter.determinant() != 0.0) { vnl_matrix< float > inverse = vnlMatrixInverter.inverse(); inverse.copy_out(oInverse->data); - } else { + } + else { errorCode = ERROR_BADPARM; } } @@ -1107,7 +1149,8 @@ extern "C" int OpenLUMatrixInverse(MATRIX *iMatrix, MATRIX *oInverse) { * @param iMatrix * @return Returns 0 if the matrix is non-square. */ -extern "C" float OpenMatrixDeterminant(MATRIX *iMatrix) { +extern "C" float OpenMatrixDeterminant(MATRIX *iMatrix) +{ float determinant = 0.0; if (iMatrix->rows == iMatrix->cols) { @@ -1133,7 +1176,8 @@ extern "C" float OpenMatrixDeterminant(MATRIX *iMatrix) { * @param oW Ouput diagonal vector. * @param oV Ouput V matrix. */ -extern "C" int OpenSvdcmp(MATRIX *ioA, VECTOR *oW, MATRIX *oV) { +extern "C" int OpenSvdcmp(MATRIX *ioA, VECTOR *oW, MATRIX *oV) +{ int errorCode = NO_ERROR; if (ioA->rows >= ioA->cols) { @@ -1144,10 +1188,12 @@ extern "C" int OpenSvdcmp(MATRIX *ioA, VECTOR *oW, MATRIX *oV) { svdMatrix.U().copy_out(ioA->data); svdMatrix.W().diagonal().copy_out(oW->data); svdMatrix.V().copy_out(oV->data); - } else { + } + else { errorCode = ERROR_BADPARM; } - } else { + } + else { errorCode = ERROR_BADPARM; } @@ -1161,7 +1207,8 @@ extern "C" int OpenSvdcmp(MATRIX *ioA, VECTOR *oW, MATRIX *oV) { * different seed. The behaviour of this function is meant to mimic that of * the ran1 algorithm in numerical recipes. */ -extern "C" float OpenRan1(long *iSeed) { +extern "C" float OpenRan1(long *iSeed) +{ static const double MIN = 0.0; static const double MAX = 1.0; @@ -1184,7 +1231,8 @@ extern "C" float OpenRan1(long *iSeed) { * @param iYEndDerivative The derivative at the last point of the function. */ extern "C" void OpenSpline( - float iaX[], float iaY[], int icXY, float iYStartDerivative, float iYEndDerivative, float oaYSecondDerivatives[]) { + float iaX[], float iaY[], int icXY, float iYStartDerivative, float iYEndDerivative, float oaYSecondDerivatives[]) +{ float *secondDerivatives = SplineCubicSet( icXY, iaX, iaY, SPLINE_USE_FIRST_DERIVATIVE, iYStartDerivative, SPLINE_USE_FIRST_DERIVATIVE, iYEndDerivative); @@ -1201,7 +1249,8 @@ extern "C" void OpenSpline( * point. */ extern "C" void OpenSplint( - float iaX[], float iaY[], float iaYSecondDerivatives[], int icYSecondDerivatives, float iX, float *oY) { + float iaX[], float iaY[], float iaYSecondDerivatives[], int icYSecondDerivatives, float iX, float *oY) +{ float firstDerivative = 0.0; float secondDerivative = 0.0; @@ -1311,7 +1360,8 @@ extern "C" void OpenSplint( * * @return The second derivatives of the cubic spline, size n. */ -float *SplineCubicSet(int n, float t[], float y[], int ibcbeg, float ybcbeg, int ibcend, float ybcend) { +float *SplineCubicSet(int n, float t[], float y[], int ibcbeg, float ybcbeg, int ibcend, float ybcend) +{ float *a; float *b; int i; @@ -1347,15 +1397,18 @@ float *SplineCubicSet(int n, float t[], float y[], int ibcbeg, float ybcbeg, int b[0] = 0.0; a[1 + 0 * 3] = 1.0; a[0 + 1 * 3] = -1.0; - } else if (ibcbeg == SPLINE_USE_FIRST_DERIVATIVE) { + } + else if (ibcbeg == SPLINE_USE_FIRST_DERIVATIVE) { b[0] = (y[1] - y[0]) / (t[1] - t[0]) - ybcbeg; a[1 + 0 * 3] = (t[1] - t[0]) / 3.0; a[0 + 1 * 3] = (t[1] - t[0]) / 6.0; - } else if (ibcbeg == SPLINE_USE_SECOND_DERIVATIVE) { + } + else if (ibcbeg == SPLINE_USE_SECOND_DERIVATIVE) { b[0] = ybcbeg; a[1 + 0 * 3] = 1.0; a[0 + 1 * 3] = 0.0; - } else { + } + else { std::cout << "\n"; std::cout << "SPLINE_CUBIC_SET - Fatal error!\n"; std::cout << " IBCBEG must be 0, 1 or 2.\n"; @@ -1380,15 +1433,18 @@ float *SplineCubicSet(int n, float t[], float y[], int ibcbeg, float ybcbeg, int b[n - 1] = 0.0; a[2 + (n - 2) * 3] = -1.0; a[1 + (n - 1) * 3] = 1.0; - } else if (ibcend == SPLINE_USE_FIRST_DERIVATIVE) { + } + else if (ibcend == SPLINE_USE_FIRST_DERIVATIVE) { b[n - 1] = ybcend - (y[n - 1] - y[n - 2]) / (t[n - 1] - t[n - 2]); a[2 + (n - 2) * 3] = (t[n - 1] - t[n - 2]) / 6.0; a[1 + (n - 1) * 3] = (t[n - 1] - t[n - 2]) / 3.0; - } else if (ibcend == SPLINE_USE_SECOND_DERIVATIVE) { + } + else if (ibcend == SPLINE_USE_SECOND_DERIVATIVE) { b[n - 1] = ybcend; a[2 + (n - 2) * 3] = 0.0; a[1 + (n - 1) * 3] = 1.0; - } else { + } + else { std::cout << "\n"; std::cout << "SPLINE_CUBIC_SET - Fatal error!\n"; std::cout << " IBCEND must be 0, 1 or 2.\n"; @@ -1405,7 +1461,8 @@ float *SplineCubicSet(int n, float t[], float y[], int ibcbeg, float ybcbeg, int ypp[0] = 0.0; ypp[1] = 0.0; - } else { + } + else { ypp = d3_np_fs(n, a, b); if (!ypp) { @@ -1458,19 +1515,22 @@ float *SplineCubicSet(int n, float t[], float y[], int ibcbeg, float ybcbeg, int * @param yppval The second derivative of the spline at TVAL. * @return The value of the spline at TVAL. */ -float SplineCubicValue(int n, float t[], float tval, float y[], float ypp[], float *ypval, float *yppval) { +float SplineCubicValue(int n, float t[], float tval, float y[], float ypp[], float *ypval, float *yppval) +{ float yval; int ival = n - 2; if (tval <= t[0]) { // enforce constant function outside of domain yval = y[0]; - } else if (tval >= t[n - 1]) { + } + else if (tval >= t[n - 1]) { // enforce constant function outside of domain yval = y[n - 1]; *ypval = 0.0; *ypval = 0.0; - } else { + } + else { // we're not outside of the range, so interpolate for (int i = 0; i < n - 1; i++) { if (tval < t[i + 1]) { @@ -1531,7 +1591,8 @@ float SplineCubicValue(int n, float t[], float tval, float y[], float ypp[], flo * This is NULL if there was an error * because one of the diagonal entries was zero. Size n. */ -float *d3_np_fs(int n, float a[], float b[]) { +float *d3_np_fs(int n, float a[], float b[]) +{ int i; float *x; float xmult; @@ -1602,9 +1663,7 @@ extern "C" float **matrix(long nrl, long nrh, long ncl, long nch) } extern "C" void free_vector(float *v, long nl, long nh) -/* free a float vector allocated with vector() */ { - free((FREE_ARG)(v + nl - NR_END)); -} +/* free a float vector allocated with vector() */ { free((FREE_ARG)(v + nl - NR_END)); } void free_matrix(float **m, long nrl, long nrh, long ncl, long nch) /* free a float matrix allocated by matrix() */ @@ -1621,7 +1680,8 @@ void free_matrix(float **m, long nrl, long nrh, long ncl, long nch) Algorithm computes sqrt of 3x3 part and then adjusts the translation part Output: 4x4 sqrt of M */ -vnl_matrix_fixed< double, 4, 4 > MatrixSqrt(const vnl_matrix_fixed< double, 4, 4 > &m) { +vnl_matrix_fixed< double, 4, 4 > MatrixSqrt(const vnl_matrix_fixed< double, 4, 4 > &m) +{ // assert(m.rows() == 4 && m.cols() == 4); vnl_matrix_fixed< double, 3, 3 > R; // = m.extract(3,3,0,0); @@ -1716,7 +1776,8 @@ vnl_matrix_fixed< double, 4, 4 > MatrixSqrt(const vnl_matrix_fixed< double, 4, 4 return msqrt; } -extern "C" MATRIX *MatrixSqrt(MATRIX *m, MATRIX *sqrtm) { +extern "C" MATRIX *MatrixSqrt(MATRIX *m, MATRIX *sqrtm) +{ int i, j; vnl_matrix_fixed< double, 4, 4 > vnl_m; @@ -1785,7 +1846,8 @@ double sc_ugauss(const sc_rng *r); Returns 0 on success and nonzero otherwise (eg, when U is non-positive def). */ -extern "C" int sc_linalg_cholesky_decomp(MATRIX *U) { +extern "C" int sc_linalg_cholesky_decomp(MATRIX *U) +{ int i, j, err; vnl_matrix< double > P(U->rows, U->cols); @@ -1808,14 +1870,16 @@ extern "C" int sc_linalg_cholesky_decomp(MATRIX *U) { //######### UTILS ####################################################### -static void sc_err_msg(const char *msg) { +static void sc_err_msg(const char *msg) +{ printf("ERROR: %s", msg); exit(1); } //########################## RNG ############################### -extern "C" unsigned long int sc_inc_status(sc_status_t *status) { +extern "C" unsigned long int sc_inc_status(sc_status_t *status) +{ int i, j; long int step; @@ -1826,21 +1890,24 @@ extern "C" unsigned long int sc_inc_status(sc_status_t *status) { if (step & SC_MASK_HI) { status->carry = 1; step &= SC_MASK_LO; - } else { + } + else { status->carry = 0; } status->u[i] = step; if (i == 0) { i = 23; - } else { + } + else { i--; } status->i = i; if (j == 0) { j = 23; - } else { + } + else { j--; } status->j = j; @@ -1848,7 +1915,8 @@ extern "C" unsigned long int sc_inc_status(sc_status_t *status) { return (step); } -extern "C" unsigned long int sc_rng_get(const sc_rng *r) { +extern "C" unsigned long int sc_rng_get(const sc_rng *r) +{ sc_status_t *status; int i, skip; unsigned long int ret; @@ -1866,7 +1934,8 @@ extern "C" unsigned long int sc_rng_get(const sc_rng *r) { return (ret); } -extern "C" void sc_rng_set(sc_rng *r, unsigned long int seed_in) { +extern "C" void sc_rng_set(sc_rng *r, unsigned long int seed_in) +{ int const_lux; sc_status_t *status; int i; @@ -1878,7 +1947,8 @@ extern "C" void sc_rng_set(sc_rng *r, unsigned long int seed_in) { if (seed_in == 0) { seed = 314159265; - } else { + } + else { seed = seed_in; } @@ -1898,14 +1968,16 @@ extern "C" void sc_rng_set(sc_rng *r, unsigned long int seed_in) { if (status->u[23] & SC_MASK_HI) { status->carry = 1; - } else { + } + else { status->carry = 0; } return; } -extern "C" sc_rng *sc_rng_alloc(const sc_rng_type *T) { +extern "C" sc_rng *sc_rng_alloc(const sc_rng_type *T) +{ sc_rng *r; r = (sc_rng *)malloc(sizeof(sc_rng)); @@ -1921,7 +1993,8 @@ extern "C" sc_rng *sc_rng_alloc(const sc_rng_type *T) { return (r); } -extern "C" void sc_rng_free(sc_rng *r) { +extern "C" void sc_rng_free(sc_rng *r) +{ if (r->status != NULL) free(r->status); if (r != NULL) free(r); @@ -1929,7 +2002,8 @@ extern "C" void sc_rng_free(sc_rng *r) { return; } -extern "C" double sc_uni(const sc_rng *r) { +extern "C" double sc_uni(const sc_rng *r) +{ double u; u = (double)(sc_rng_get(r) / 16777216.0); @@ -1937,7 +2011,8 @@ extern "C" double sc_uni(const sc_rng *r) { return (u); } -extern "C" double sc_uni_pos(const sc_rng *r) { +extern "C" double sc_uni_pos(const sc_rng *r) +{ double x; do { x = (double)(sc_rng_get(r) / 16777216.0); @@ -1948,7 +2023,8 @@ extern "C" double sc_uni_pos(const sc_rng *r) { //##################### RAN ### -extern "C" double sc_ran_flat(const sc_rng *r, const double a, const double b) { +extern "C" double sc_ran_flat(const sc_rng *r, const double a, const double b) +{ double u, ret; u = sc_uni(r); @@ -1956,7 +2032,8 @@ extern "C" double sc_ran_flat(const sc_rng *r, const double a, const double b) { return (ret); } -extern "C" double sc_ran_gaussian(const sc_rng *r, const double sigma) { +extern "C" double sc_ran_gaussian(const sc_rng *r, const double sigma) +{ double x, y, r2, ret; do { @@ -1969,7 +2046,8 @@ extern "C" double sc_ran_gaussian(const sc_rng *r, const double sigma) { return (ret); } -extern "C" double sc_ugauss(const sc_rng *r) { +extern "C" double sc_ugauss(const sc_rng *r) +{ double ret; ret = sc_ran_gaussian(r, 1.0); @@ -1977,7 +2055,8 @@ extern "C" double sc_ugauss(const sc_rng *r) { return (ret); } -extern "C" double sc_gamma_int(const sc_rng *r, const unsigned int a) { +extern "C" double sc_gamma_int(const sc_rng *r, const unsigned int a) +{ unsigned int i; double prod, ret; @@ -1988,13 +2067,15 @@ extern "C" double sc_gamma_int(const sc_rng *r, const unsigned int a) { } ret = -log(prod); return (ret); - } else { + } + else { ret = sc_gamma_large(r, (double)a); return (ret); } } -extern "C" double sc_gamma_large(const sc_rng *r, const double a) { +extern "C" double sc_gamma_large(const sc_rng *r, const double a) +{ double sqa, y, v, ret; sqa = sqrt(2 * a - 1); @@ -2009,7 +2090,8 @@ extern "C" double sc_gamma_large(const sc_rng *r, const double a) { return (ret); } -extern "C" double sc_gamma_frac(const sc_rng *r, const double a) { +extern "C" double sc_gamma_frac(const sc_rng *r, const double a) +{ double p, q, u, v, ret; p = M_E / (a + M_E); do { @@ -2019,7 +2101,8 @@ extern "C" double sc_gamma_frac(const sc_rng *r, const double a) { if (u < p) { ret = exp((1 / a) * log(v)); q = exp(-ret); - } else { + } + else { ret = 1 - log(v); q = exp((a - 1) * log(ret)); } @@ -2028,7 +2111,8 @@ extern "C" double sc_gamma_frac(const sc_rng *r, const double a) { return (ret); } -extern "C" double sc_ran_gamma(const sc_rng *r, const double a, const double b) { +extern "C" double sc_ran_gamma(const sc_rng *r, const double a, const double b) +{ unsigned int na; double ret; @@ -2036,16 +2120,19 @@ extern "C" double sc_ran_gamma(const sc_rng *r, const double a, const double b) if (a == na) { ret = b * sc_gamma_int(r, na); return (ret); - } else if (na == 0) { + } + else if (na == 0) { ret = b * sc_gamma_frac(r, a); return (ret); - } else { + } + else { ret = b * (sc_gamma_int(r, na) + sc_gamma_frac(r, a - na)); return (ret); } } -extern "C" double sc_ran_fdist(const sc_rng *r, const double nu1, const double nu2) { +extern "C" double sc_ran_fdist(const sc_rng *r, const double nu1, const double nu2) +{ double Y1, Y2, ret; Y1 = sc_ran_gamma(r, nu1 / 2, 2.0); @@ -2055,14 +2142,16 @@ extern "C" double sc_ran_fdist(const sc_rng *r, const double nu1, const double n return (ret); } -extern "C" double sc_ran_chisq(const sc_rng *r, const double nu) { +extern "C" double sc_ran_chisq(const sc_rng *r, const double nu) +{ double ret; ret = 2 * sc_ran_gamma(r, nu / 2, 1.0); return (ret); } -extern "C" double sc_ran_tdist(const sc_rng *r, const double nu) { +extern "C" double sc_ran_tdist(const sc_rng *r, const double nu) +{ double Y1, Y2, Z, ret; if (nu <= 2) { @@ -2070,7 +2159,8 @@ extern "C" double sc_ran_tdist(const sc_rng *r, const double nu) { Y2 = sc_ran_chisq(r, nu); ret = Y1 / sqrt(Y2 / nu); return (ret); - } else { + } + else { do { Y1 = sc_ugauss(r); Y2 = sc_ran_exponential(r, 1 / (nu / 2 - 1)); @@ -2082,7 +2172,8 @@ extern "C" double sc_ran_tdist(const sc_rng *r, const double nu) { } } -extern "C" double sc_ran_exponential(const sc_rng *r, const double mu) { +extern "C" double sc_ran_exponential(const sc_rng *r, const double mu) +{ double u, ret; u = sc_uni_pos(r); @@ -2091,12 +2182,14 @@ extern "C" double sc_ran_exponential(const sc_rng *r, const double mu) { return (ret); } -extern "C" double sc_ran_binomial_pdf(unsigned int k, double p, unsigned int n) { +extern "C" double sc_ran_binomial_pdf(unsigned int k, double p, unsigned int n) +{ double ret; if (k == 0) { ret = bdtr(k, n, p); - } else { + } + else { ret = bdtr(k, n, p) - bdtr(k - 1, n, p); } @@ -2105,7 +2198,8 @@ extern "C" double sc_ran_binomial_pdf(unsigned int k, double p, unsigned int n) //##################### CDF ### -extern "C" double sc_cdf_flat_Q(double x, double a, double b) { +extern "C" double sc_cdf_flat_Q(double x, double a, double b) +{ double ret = 0.0; if (x <= a) ret = 0.0; @@ -2115,7 +2209,8 @@ extern "C" double sc_cdf_flat_Q(double x, double a, double b) { return (1.0 - ret); } -extern "C" double sc_cdf_flat_Qinv(double Q, double a, double b) { +extern "C" double sc_cdf_flat_Qinv(double Q, double a, double b) +{ double ret = 0.0; if (Q == 0.0) ret = b; @@ -2127,7 +2222,8 @@ extern "C" double sc_cdf_flat_Qinv(double Q, double a, double b) { return (ret); } -extern "C" double sc_cdf_fdist_Q(double x, double nu1, double nu2) { +extern "C" double sc_cdf_fdist_Q(double x, double nu1, double nu2) +{ double ret = 0.0; ret = fdtrc(nu1, nu2, x); @@ -2135,7 +2231,8 @@ extern "C" double sc_cdf_fdist_Q(double x, double nu1, double nu2) { return (ret); } -extern "C" double sc_cdf_fdist_Qinv(double Q, double nu1, double nu2) { +extern "C" double sc_cdf_fdist_Qinv(double Q, double nu1, double nu2) +{ double ret = 0.0; ret = fdtri(nu1, nu2, Q); @@ -2143,7 +2240,8 @@ extern "C" double sc_cdf_fdist_Qinv(double Q, double nu1, double nu2) { return (ret); } -extern "C" double sc_cdf_tdist_Q(double x, double nu) { +extern "C" double sc_cdf_tdist_Q(double x, double nu) +{ double ret = 0.0; ret = 1.0 - stdtr(nu, x); @@ -2151,7 +2249,8 @@ extern "C" double sc_cdf_tdist_Q(double x, double nu) { return (ret); } -extern "C" double sc_cdf_tdist_Qinv(double Q, double nu) { +extern "C" double sc_cdf_tdist_Qinv(double Q, double nu) +{ double ret = 0.0; ret = (-1) * stdtri(nu, Q); @@ -2159,7 +2258,8 @@ extern "C" double sc_cdf_tdist_Qinv(double Q, double nu) { return (ret); } -extern "C" double sc_cdf_gaussian_Q(double x, double nu) { +extern "C" double sc_cdf_gaussian_Q(double x, double nu) +{ double ret = 0.0; if (nu != 1.0) { @@ -2172,7 +2272,8 @@ extern "C" double sc_cdf_gaussian_Q(double x, double nu) { return (ret); } -extern "C" double sc_cdf_gaussian_Qinv(double Q, double nu) { +extern "C" double sc_cdf_gaussian_Qinv(double Q, double nu) +{ double ret = 0.0; if (nu != 1.0) { @@ -2185,7 +2286,8 @@ extern "C" double sc_cdf_gaussian_Qinv(double Q, double nu) { return (ret); } -extern "C" double sc_cdf_chisq_Q(double x, double nu) { +extern "C" double sc_cdf_chisq_Q(double x, double nu) +{ double ret = 0.0; ret = chdtrc(nu, x); @@ -2193,7 +2295,8 @@ extern "C" double sc_cdf_chisq_Q(double x, double nu) { return (ret); } -extern "C" double sc_cdf_chisq_Qinv(double Q, double nu) { +extern "C" double sc_cdf_chisq_Qinv(double Q, double nu) +{ double ret = 0.0; ret = chdtri(nu, Q); diff --git a/utils/offset.c b/utils/offset.c index 3639d642f17..0b5e09c272b 100644 --- a/utils/offset.c +++ b/utils/offset.c @@ -70,7 +70,8 @@ Description: ----------------------------------------------------------------------*/ #define MAX_STEPS 30 -IMAGE *ImageCalculateOffset(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Ioffset) { +IMAGE *ImageCalculateOffset(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Ioffset) +{ static IMAGE *Iorient = NULL, *Idir = NULL; struct timeb then; int msec; @@ -107,7 +108,8 @@ IMAGE *ImageCalculateOffset(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Ioffset) { ----------------------------------------------------------------------*/ #define NS_FSCALE 100000.0f /* to scale to approx. same range as new stuff */ -IMAGE *ImageCalculateNitShiOffset(IMAGE *Ix, IMAGE *Iy, int wsize, float mu, float c, IMAGE *Ioffset) { +IMAGE *ImageCalculateNitShiOffset(IMAGE *Ix, IMAGE *Iy, int wsize, float mu, float c, IMAGE *Ioffset) +{ int x0, y0, rows, cols, x, y, whalf, x_plus_off, y_plus_off; float vx, vy, vsq, c1, *g, *xpix, *ypix; static float *gaussian = NULL; @@ -227,7 +229,8 @@ IMAGE *ImageCalculateNitShiOffset(IMAGE *Ix, IMAGE *Iy, int wsize, float mu, flo surfaces in offset direction, then modifying offset distance to be the distance to the isopotential surface. ----------------------------------------------------------------------*/ -IMAGE *ImageNormalizeOffsetDistances(IMAGE *Isrc, IMAGE *Idst, int maxsteps) { +IMAGE *ImageNormalizeOffsetDistances(IMAGE *Isrc, IMAGE *Idst, int maxsteps) +{ float *src_xpix, *src_ypix, *dst_xpix, *dst_ypix, slope, xf, yf, dot; int x0, y0, rows, cols, delta, i; register int x, y; @@ -269,7 +272,8 @@ IMAGE *ImageNormalizeOffsetDistances(IMAGE *Isrc, IMAGE *Idst, int maxsteps) { } x -= delta; y = nint(yf - slope); - } else /* use unit steps in y direction */ + } + else /* use unit steps in y direction */ { delta = nint(dy / (float)fabs(dy)); slope = delta * dx / dy; @@ -311,7 +315,8 @@ static float avg[] = } ; #endif -IMAGE *ImageSmoothOffsets(IMAGE *Isrc, IMAGE *Idst, int wsize) { +IMAGE *ImageSmoothOffsets(IMAGE *Isrc, IMAGE *Idst, int wsize) +{ #if 0 ImageConvolve3x3(Isrc, avg, Idst) ; #else @@ -380,7 +385,8 @@ IMAGE *ImageSmoothOffsets(IMAGE *Isrc, IMAGE *Idst, int wsize) { wphase[i] = (float)latan2((double)dy, (double)dx); } } - } else /* use unit steps in y direction */ + } + else /* use unit steps in y direction */ { delta = nint(dy / (float)fabs(dy)); slope = delta * dx / dy; /* orthogonal slope */ @@ -496,7 +502,8 @@ neighbor's diirection is not bracketed by them, then modify it. Description: apply an offset vector to a filtered image. ----------------------------------------------------------------------*/ -IMAGE *ImageApplyOffset(IMAGE *Isrc, IMAGE *Ioffset, IMAGE *Idst) { +IMAGE *ImageApplyOffset(IMAGE *Isrc, IMAGE *Ioffset, IMAGE *Idst) +{ int x, y, rows, cols, dx, dy; float *dst, *src, *dx_pix, *dy_pix; IMAGE *Iout, *Iin; @@ -513,7 +520,8 @@ IMAGE *ImageApplyOffset(IMAGE *Isrc, IMAGE *Ioffset, IMAGE *Idst) { if (Isrc->pixel_format != PFFLOAT) { Iin = ImageAlloc(rows, cols, PFFLOAT, 1); ImageCopy(Isrc, Iin); - } else + } + else Iin = Isrc; if (!ImageCheckSize(Isrc, Idst, 0, 0, 0)) ErrorReturn(NULL, (ERROR_SIZE, "ImageApplyOffset: dst not big enough")); @@ -545,7 +553,8 @@ IMAGE *ImageApplyOffset(IMAGE *Isrc, IMAGE *Ioffset, IMAGE *Idst) { Description: use an offset vector field to specify edge locations. ----------------------------------------------------------------------*/ -IMAGE *ImageOffsetMedialAxis(IMAGE *Ioffset, IMAGE *Iedge) { +IMAGE *ImageOffsetMedialAxis(IMAGE *Ioffset, IMAGE *Iedge) +{ int x, y, rows, cols, dx, dy; float *dx_pix, *dy_pix; UCHAR *edge; @@ -592,7 +601,8 @@ IMAGE *ImageOffsetMedialAxis(IMAGE *Ioffset, IMAGE *Iedge) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageCalculateOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Ioffset) { +IMAGE *ImageCalculateOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Ioffset) +{ int x0, y0, rows, cols, x, y, whalf; float vx, vy, *g, *xpix, *ypix; static float *gaussian = NULL; @@ -696,7 +706,8 @@ IMAGE *ImageCalculateOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iof #define MEDIAN_INDEX ((3 * 3 - 1) / 2) static int compare_sort_array(const void *pf1, const void *pf2); -IMAGE *ImageOffsetScale(IMAGE *Isrc, IMAGE *Idst) { +IMAGE *ImageOffsetScale(IMAGE *Isrc, IMAGE *Idst) +{ static IMAGE *Ioffset = NULL, *Ioffset2 = NULL, *Ix = NULL, *Iy = NULL, *Ismooth = NULL; static IMAGE *Igauss = NULL; int srows, scols, drows, dcols, xs, ys; @@ -853,7 +864,8 @@ IMAGE *ImageOffsetScale(IMAGE *Isrc, IMAGE *Idst) { } x -= delta; y = nint(yf - slope); - } else /* use unit steps in y direction */ + } + else /* use unit steps in y direction */ { delta = nint(oy / (float)fabs(oy)); slope = delta * ox / oy; @@ -932,7 +944,8 @@ IMAGE *ImageOffsetScale(IMAGE *Isrc, IMAGE *Idst) { return (Idst); } -static int compare_sort_array(const void *pf1, const void *pf2) { +static int compare_sort_array(const void *pf1, const void *pf2) +{ register float f1, f2; f1 = *(float *)pf1; @@ -951,7 +964,8 @@ static int compare_sort_array(const void *pf1, const void *pf2) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageOffsetOrientation(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient) { +IMAGE *ImageOffsetOrientation(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient) +{ if (!Iorient) Iorient = ImageAlloc(Ix->rows, Ix->cols, PFFLOAT, 2); Iorient->num_frame = 1; ImageMeanFilter(Ix, 3, Iorient); @@ -967,7 +981,8 @@ IMAGE *ImageOffsetOrientation(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient) { Description: ----------------------------------------------------------------------*/ -IMAGE *ImageOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, IMAGE *Ioffset) { +IMAGE *ImageOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, IMAGE *Ioffset) +{ int x0, y0, rows, cols, x, y, whalf, xc, yc, yoff, off; float *xpix, *ypix, dx, dy, *or_xpix, *or_ypix, *oxpix, *oypix, dir, ox, oy, dot; @@ -1038,7 +1053,8 @@ IMAGE *ImageOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, IMA Description: ----------------------------------------------------------------------*/ -IMAGE *ImageOffsetDirectionMap(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, IMAGE *Idir, IMAGE *Ioffset) { +IMAGE *ImageOffsetDirectionMap(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, IMAGE *Idir, IMAGE *Ioffset) +{ int x0, y0, rows, cols, x, y, whalf, xc, yc, yoff, off; float *xpix, *ypix, dx, dy, *or_xpix, *or_ypix, *oxpix, *oypix, dir, ox, oy, dot; @@ -1119,7 +1135,8 @@ IMAGE *ImageOffsetDirectionMap(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, ----------------------------------------------------------------------*/ #define FSCALE 100.0f -IMAGE *ImageOffsetMagnitude(IMAGE *Isrc, IMAGE *Idst, int maxsteps) { +IMAGE *ImageOffsetMagnitude(IMAGE *Isrc, IMAGE *Idst, int maxsteps) +{ int rows, cols, x, y, ax, ay, sx, sy, x1, y1, dx, dy, odx, ody, d, xn, yn, steps, dot = 0, xold, yold; float *src_xpix, *src_ypix, *dst_xpix, *dst_ypix, *oxpix, *oypix; @@ -1164,7 +1181,8 @@ IMAGE *ImageOffsetMagnitude(IMAGE *Isrc, IMAGE *Idst, int maxsteps) { oxpix += (sy * cols); oypix += (sy * cols); d -= ax; - } else /* move in x direction */ + } + else /* move in x direction */ { xn = x + sx; if (xn < 0 || xn >= cols) break; @@ -1179,7 +1197,8 @@ IMAGE *ImageOffsetMagnitude(IMAGE *Isrc, IMAGE *Idst, int maxsteps) { x = xn; y = yn; } - } else /* y dominant */ + } + else /* y dominant */ { d = ax - (ay >> 1); for (steps = 0; steps < maxsteps; steps++) { @@ -1196,7 +1215,8 @@ IMAGE *ImageOffsetMagnitude(IMAGE *Isrc, IMAGE *Idst, int maxsteps) { oxpix += sx; oypix += sx; d -= ay; - } else /* only move in y direction */ + } + else /* only move in y direction */ { yn = y + sy; if (yn < 0 || yn >= rows) break; @@ -1233,7 +1253,8 @@ IMAGE *ImageOffsetMagnitude(IMAGE *Isrc, IMAGE *Idst, int maxsteps) { Description: calculate direction using Nitzberg-Shiota formula ----------------------------------------------------------------------*/ -IMAGE *ImageNitshiOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, IMAGE *Ioffset) { +IMAGE *ImageNitshiOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, IMAGE *Ioffset) +{ int x0, y0, rows, cols, x, y, whalf, xc, yc, yoff, off; float *xpix, *ypix, dx, dy, *or_xpix, *or_ypix, *oxpix, *oypix, dir, dot, ox, oy, dirx, diry; @@ -1311,7 +1332,8 @@ IMAGE *ImageNitshiOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorien ----------------------------------------------------------------------*/ static int imageOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, int x0, int y0); -static int imageOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, int x0, int y0) { +static int imageOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, int x0, int y0) +{ int rows, cols, x, y, whalf, xc, yc, yoff, off, d; float *xpix, *ypix, dx, dy, *or_xpix, *or_ypix, dir, ox, oy; @@ -1363,7 +1385,8 @@ static int imageOffsetDirection(IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Iorient, return (d); } -IMAGE *ImageOffsetDirectionMagnitude(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Idst, int maxsteps) { +IMAGE *ImageOffsetDirectionMagnitude(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsize, IMAGE *Idst, int maxsteps) +{ int rows, cols, x, y, ax, ay, sx, sy, x1, y1, dx, dy, odx, ody, d, xn, yn, steps, dir, dot; float *src_xpix, *src_ypix, *dst_xpix, *dst_ypix, *oxpix, *oypix, fdir; byte *calculated; @@ -1375,7 +1398,8 @@ IMAGE *ImageOffsetDirectionMagnitude(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsiz if (!Icalculated || (rows != Icalculated->rows || cols != Icalculated->cols)) { if (Icalculated) ImageFree(&Icalculated); Icalculated = ImageAlloc(rows, cols, PFBYTE, 1); - } else + } + else ImageClear(Icalculated); if (!Idst) Idst = ImageAlloc(Isrc->rows, Isrc->cols, Isrc->pixel_format, Isrc->num_frame); @@ -1428,7 +1452,8 @@ IMAGE *ImageOffsetDirectionMagnitude(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsiz oxpix += (sy * cols); oypix += (sy * cols); d -= ax; - } else + } + else yn = y; oxpix += sx; oypix += sx; @@ -1439,7 +1464,8 @@ IMAGE *ImageOffsetDirectionMagnitude(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsiz y = yn; d += ay; } - } else /* y dominant */ + } + else /* y dominant */ { d = ax - (ay >> 1); for (steps = 0; steps < maxsteps; steps++) { @@ -1460,7 +1486,8 @@ IMAGE *ImageOffsetDirectionMagnitude(IMAGE *Isrc, IMAGE *Ix, IMAGE *Iy, int wsiz oxpix += sx; oypix += sx; d -= ay; - } else + } + else xn = x; yn = y + sy; if (yn < 0 || yn >= rows) break; @@ -1859,7 +1886,8 @@ ImageSmoothOffsets(IMAGE *Isrc, IMAGE *Idst, int wsize) Description: apply an offset vector to a filtered image. ----------------------------------------------------------------------*/ -IMAGE *ImageFilterMinMax(IMAGE *Imin, IMAGE *Imax, IMAGE *Idir, IMAGE *Ioffset, IMAGE *Idst) { +IMAGE *ImageFilterMinMax(IMAGE *Imin, IMAGE *Imax, IMAGE *Idir, IMAGE *Ioffset, IMAGE *Idst) +{ int x, y, rows, cols, dx, dy, dir; float *dst, src, *dx_pix, *dy_pix, *dir_pix; IMAGE *Iout; diff --git a/utils/path.c b/utils/path.c index 16f854a7bb8..71079bc1000 100644 --- a/utils/path.c +++ b/utils/path.c @@ -34,7 +34,8 @@ #include "path.h" -int PathReadMany(char *fname, int *num_read, PATH ***returned_paths) { +int PathReadMany(char *fname, int *num_read, PATH ***returned_paths) +{ FILE *fp; int num_scanf; int line_number; @@ -100,7 +101,8 @@ int PathReadMany(char *fname, int *num_read, PATH ***returned_paths) { fname, version)); } - } else if (0 == strncmp(line, "BEGINPATH", 9)) { + } + else if (0 == strncmp(line, "BEGINPATH", 9)) { /* Start a new path decsription. */ if (getline(&line, &line_size, fp) == -1) { ErrorPrintf(ERROR_BAD_FILE, "Couldn't read file\n"); @@ -231,13 +233,15 @@ int PathReadMany(char *fname, int *num_read, PATH ***returned_paths) { /* Add the path to our array. */ if (NULL == paths) { paths = (PATH **)calloc(num_paths + 1, sizeof(PATH *)); - } else { + } + else { paths = (PATH **)realloc(paths, (num_paths + 1) * sizeof(PATH *)); } paths[num_paths] = path; num_paths++; path = NULL; - } else { + } + else { /* Didn't get a keyword we're looking for. */ ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, @@ -258,7 +262,8 @@ int PathReadMany(char *fname, int *num_read, PATH ***returned_paths) { return (ERROR_NONE); } -int PathWriteMany(char *fname, int num_paths, PATH **paths) { +int PathWriteMany(char *fname, int num_paths, PATH **paths) +{ FILE *fp; int path; int path_pno; @@ -300,7 +305,8 @@ int PathWriteMany(char *fname, int num_paths, PATH **paths) { return (ERROR_NONE); } -PATH *PathAlloc(int n_points, char *name) { +PATH *PathAlloc(int n_points, char *name) +{ PATH *path; if (n_points < 0) return NULL; @@ -332,7 +338,8 @@ PATH *PathAlloc(int n_points, char *name) { return path; } -int PathFree(PATH **path) { +int PathFree(PATH **path) +{ if (NULL == path || NULL == (*path)) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "No path supplied.")); /* Free the points array, then the path struct. */ @@ -343,7 +350,8 @@ int PathFree(PATH **path) { return (ERROR_NONE); } -int PathIsPathFile(char *fname) { +int PathIsPathFile(char *fname) +{ FILE *fp = NULL; int is_path_file = 0; @@ -360,7 +368,8 @@ int PathIsPathFile(char *fname) { return is_path_file; } -int PathIsPathFileStream(FILE *fp) { +int PathIsPathFileStream(FILE *fp) +{ char *line = NULL; size_t size = 1024; char *needle = NULL; @@ -393,7 +402,8 @@ int PathIsPathFileStream(FILE *fp) { return found; } -int PathConvertToLabel(PATH *path, LABEL **label) { +int PathConvertToLabel(PATH *path, LABEL **label) +{ LABEL *new_label = NULL; int pno = 0; @@ -422,7 +432,8 @@ int PathConvertToLabel(PATH *path, LABEL **label) { return (ERROR_NONE); } -int PathCreateFromLabel(LABEL *label, PATH **path) { +int PathCreateFromLabel(LABEL *label, PATH **path) +{ PATH *new_path = NULL; int pno = 0; diff --git a/utils/pdf.c b/utils/pdf.c index 2d59572aaed..abcc6c33208 100644 --- a/utils/pdf.c +++ b/utils/pdf.c @@ -40,7 +40,8 @@ double round(double x); The seed will be different from microsecond-to-microsecond. This can be used as input to srand48(). -------------------------------------------------------------------*/ -unsigned long PDFtodSeed(void) { +unsigned long PDFtodSeed(void) +{ struct timeval tv; unsigned long seed; gettimeofday(&tv, NULL); @@ -56,7 +57,8 @@ unsigned long PDFtodSeed(void) { * distribution with zero mean and std dev of 1: * pdf(x) = e^(x^2/2)/sqrt(2pi) ************************************************************/ -double PDFgaussian(void) { +double PDFgaussian(void) +{ double v1, v2, r2; do { @@ -74,7 +76,8 @@ double PDFgaussian(void) { * pdf(x) = r*((r*(x-avg+1))^(r-1)) * exp(-r*(x-avg+1)) / (r-1)! * when order=1, an exponential distribution is generated. ************************************************************/ -double PDFerlang(int order) { +double PDFerlang(int order) +{ double v, n; v = 0; @@ -89,7 +92,8 @@ double PDFerlang(int order) { is the probability that the random number will be <= xcdf[n]. See also PDFloadCDF(). -------------------------------------------------------------------*/ -double PDFsampleCDF(double *xcdf, double *cdf, int ncdf) { +double PDFsampleCDF(double *xcdf, double *cdf, int ncdf) +{ double u; int n; @@ -119,7 +123,8 @@ double PDFsampleCDF(double *xcdf, double *cdf, int ncdf) { PDFsearchOrderedTable() - returns the index in y such that y(index) is closest to u. Assumes that y is sorted from lowest to highest. ----------------------------------------------------------------*/ -int PDFsearchOrderedTable(double u, double *y, int ny) { +int PDFsearchOrderedTable(double u, double *y, int ny) +{ int n1, n2, n3; n1 = 0; @@ -130,7 +135,8 @@ int PDFsearchOrderedTable(double u, double *y, int ny) { if (y[n2] <= u) { n1 = n2; n2 = (int)round((n2 + n3) / 2); - } else { + } + else { n3 = n2; n2 = (int)round((n1 + n2) / 2); } @@ -146,7 +152,8 @@ int PDFsearchOrderedTable(double u, double *y, int ny) { two columns. The first column is the x at which the cdf is sampled, the second column is the value of the cdf. See also PDFsampleCDF(). ----------------------------------------------------------------*/ -int PDFloadCDF(char *fname, double **xcdf, double **cdf, int *ncdf) { +int PDFloadCDF(char *fname, double **xcdf, double **cdf, int *ncdf) +{ FILE *fp; int n; char tmpstring[1000]; diff --git a/utils/prime.c b/utils/prime.c index 66457fd02d0..c5ac43a307f 100644 --- a/utils/prime.c +++ b/utils/prime.c @@ -36,7 +36,8 @@ static int CompareFactors(const void *pf1, const void *pf2); or equal to Nmax. The number of primes is returned in *Nprimes; ------------------------------------------------------- */ -int *GetPrimes(int Nmax, int *Nprimes) { +int *GetPrimes(int Nmax, int *Nprimes) +{ int *numlist, n, m, k, k2, kmax; int *primes; @@ -83,7 +84,8 @@ int *GetPrimes(int Nmax, int *Nprimes) { number of prime factors is returned in *Nfactors. The factors are sorted from lowest to highest. ------------------------------------------------------- */ -int *GetPrimeFactors(int N, int *Nfactors) { +int *GetPrimeFactors(int N, int *Nfactors) +{ int *pfactors, n, m, NN; int *allprimes, nallprimes; int changed; @@ -144,7 +146,8 @@ int *GetPrimeFactors(int N, int *Nfactors) { /* -------------------------------------------------------------- CompareFactors() - only for sorting. ------------------------------------------------------------- */ -static int CompareFactors(const void *pf1, const void *pf2) { +static int CompareFactors(const void *pf1, const void *pf2) +{ int f1, f2; f1 = *((int *)pf1); @@ -157,7 +160,8 @@ static int CompareFactors(const void *pf1, const void *pf2) { /* -------------------------------------------------------------- IsPrime() - returns 1 if N is prime, zero otherwise ------------------------------------------------------------- */ -int IsPrime(int N) { +int IsPrime(int N) +{ int *primes, nprimes, r; if (N < 1) { @@ -177,7 +181,8 @@ int IsPrime(int N) { /* -------------------------------------------------------------- GetMaxPrimeFactor() - returns the maximum prime factor of N. ------------------------------------------------------------- */ -int GetMaxPrimeFactor(int N) { +int GetMaxPrimeFactor(int N) +{ int *pfactors, nfactors; int maxfactor; @@ -191,7 +196,8 @@ int GetMaxPrimeFactor(int N) { GetClosestPrimeFactor() - returns the prime factor of N closest to P. ------------------------------------------------------------- */ -int GetClosestPrimeFactor(int N, int P) { +int GetClosestPrimeFactor(int N, int P) +{ int *pfactors, nfactors; int n, d, dmin, nmin, fclosest; @@ -216,7 +222,8 @@ int GetClosestPrimeFactor(int N, int P) { GetClosestPrimeFactorLess() - returns the prime factor of N closest to and less than P. ------------------------------------------------------------- */ -int GetClosestPrimeFactorLess(int N, int P) { +int GetClosestPrimeFactorLess(int N, int P) +{ int *pfactors, nfactors; int n, d, dmin, nmin, fclosest; diff --git a/utils/queue.c b/utils/queue.c index 337b79a511d..7cb5c5d29cb 100644 --- a/utils/queue.c +++ b/utils/queue.c @@ -70,7 +70,8 @@ Return Values: nothing. ------------------------------------------------------------------------*/ -QUEUE *Qalloc(int max_elts) { +QUEUE *Qalloc(int max_elts) +{ QUEUE *q; // int i = max_elts; @@ -87,7 +88,8 @@ QUEUE *Qalloc(int max_elts) { Return Values: nothing. ------------------------------------------------------------------------*/ -void Qfree(QUEUE *q) { +void Qfree(QUEUE *q) +{ QELT *qelt; for (qelt = Qget(q, 0); qelt; qelt = Qget(q, 0)) free(qelt); @@ -102,7 +104,8 @@ void Qfree(QUEUE *q) { Return Values: nothing. ------------------------------------------------------------------------*/ -int Qput(QUEUE *q, void *data) { +int Qput(QUEUE *q, void *data) +{ QELT *qelt; qelt = (QELT *)calloc(1, sizeof(QELT)); @@ -114,7 +117,8 @@ int Qput(QUEUE *q, void *data) { { q->head = q->tail = qelt; qelt->next = qelt->prev = NULL; /* just to be explicit */ - } else /* link in at end of list */ + } + else /* link in at end of list */ { qelt->next = NULL; qelt->prev = q->tail; @@ -133,7 +137,8 @@ int Qput(QUEUE *q, void *data) { Return Values: nothing. ------------------------------------------------------------------------*/ -void *Qget(QUEUE *q, int mode) { +void *Qget(QUEUE *q, int mode) +{ QELT *qelt; void *data; diff --git a/utils/randomfields.c b/utils/randomfields.c index 9d3ab30383d..5764ad0d20b 100644 --- a/utils/randomfields.c +++ b/utils/randomfields.c @@ -46,7 +46,8 @@ const char *RFSrcVersion(void) { return ("$Id: randomfields.c,v 1.18 2016/12/06 20:25:48 greve Exp $"); } /*-------------------------------------------------------------------*/ -int RFname2Code(RFS *rfs) { +int RFname2Code(RFS *rfs) +{ int code = -1; if (!strcmp(rfs->name, "uniform")) code = RF_UNIFORM; if (!strcmp(rfs->name, "gaussian")) code = RF_GAUSSIAN; @@ -58,7 +59,8 @@ int RFname2Code(RFS *rfs) { return (code); } /*-------------------------------------------------------------------*/ -const char *RFcode2Name(RFS *rfs) { +const char *RFcode2Name(RFS *rfs) +{ switch (rfs->code) { case RF_UNIFORM: return ("uniform"); @@ -83,7 +85,8 @@ const char *RFcode2Name(RFS *rfs) { } /*-------------------------------------------------------------------*/ -RFS *RFspecInit(unsigned long int seed, sc_rng_type *rngtype) { +RFS *RFspecInit(unsigned long int seed, sc_rng_type *rngtype) +{ RFS *rfs; const sc_rng_type *sc_rng_intern_type = &intern_rng_type; @@ -99,7 +102,8 @@ RFS *RFspecInit(unsigned long int seed, sc_rng_type *rngtype) { } /*-------------------------------------------------------------------*/ -int RFspecFree(RFS **prfs) { +int RFspecFree(RFS **prfs) +{ sc_rng_free((*prfs)->rng); free((*prfs)->name); free(*prfs); @@ -108,7 +112,8 @@ int RFspecFree(RFS **prfs) { } /*-------------------------------------------------------------------*/ -int RFspecSetSeed(RFS *rfs, unsigned long int seed) { +int RFspecSetSeed(RFS *rfs, unsigned long int seed) +{ if (seed == 0) rfs->seed = PDFtodSeed(); else @@ -118,7 +123,8 @@ int RFspecSetSeed(RFS *rfs, unsigned long int seed) { } /*-------------------------------------------------------------------*/ -int RFprint(FILE *fp, RFS *rfs) { +int RFprint(FILE *fp, RFS *rfs) +{ int n; fprintf(fp, "field %s\n", rfs->name); fprintf(fp, "code %d\n", rfs->code); @@ -131,7 +137,8 @@ int RFprint(FILE *fp, RFS *rfs) { } /*-------------------------------------------------------------------*/ -int RFnparams(RFS *rfs) { +int RFnparams(RFS *rfs) +{ int nparams = -1; switch (rfs->code) { case RF_UNIFORM: @@ -158,7 +165,8 @@ int RFnparams(RFS *rfs) { } /*-------------------------------------------------------------------*/ -int RFexpectedMeanStddev(RFS *rfs) { +int RFexpectedMeanStddev(RFS *rfs) +{ if (!strcmp(rfs->name, "uniform")) return (RFexpectedMeanStddevUniform(rfs)); if (!strcmp(rfs->name, "gaussian")) return (RFexpectedMeanStddevGaussian(rfs)); if (!strcmp(rfs->name, "t")) return (RFexpectedMeanStddevt(rfs)); @@ -169,7 +177,8 @@ int RFexpectedMeanStddev(RFS *rfs) { } /*-------------------------------------------------------------------*/ -int RFsynth(MRI *rf, RFS *rfs, MRI *binmask) { +int RFsynth(MRI *rf, RFS *rfs, MRI *binmask) +{ int c, r, s, f; double v, m; @@ -196,7 +205,8 @@ int RFsynth(MRI *rf, RFS *rfs, MRI *binmask) { \brief Converts a stat to a p value. If TwoSided, then computes a p value based on an unsigned stat, but the sign is still passed to p. */ -MRI *RFstat2P(MRI *rf, RFS *rfs, MRI *binmask, int TwoSided, MRI *p) { +MRI *RFstat2P(MRI *rf, RFS *rfs, MRI *binmask, int TwoSided, MRI *p) +{ int c, r, s, f = 0, m; double v, pval; @@ -228,7 +238,8 @@ MRI *RFstat2P(MRI *rf, RFS *rfs, MRI *binmask, int TwoSided, MRI *p) { \brief Converts z to p. If TwoSided, then computes the unsigned p, but p keeps the sign of z. */ -MRI *RFz2p(MRI *z, MRI *mask, int TwoSided, MRI *p) { +MRI *RFz2p(MRI *z, MRI *mask, int TwoSided, MRI *p) +{ RFS *rfs; rfs = RFspecInit(0, NULL); rfs->name = strcpyalloc("gaussian"); @@ -239,7 +250,8 @@ MRI *RFz2p(MRI *z, MRI *mask, int TwoSided, MRI *p) { } /*-------------------------------------------------------------------*/ -MRI *RFp2Stat(MRI *p, RFS *rfs, MRI *binmask, MRI *rf) { +MRI *RFp2Stat(MRI *p, RFS *rfs, MRI *binmask, MRI *rf) +{ int c, r, s, f, m; double v, pval; @@ -269,7 +281,8 @@ MRI *RFp2Stat(MRI *p, RFS *rfs, MRI *binmask, MRI *rf) { } /*--------------------------------------------------------------------------*/ -MRI *RFstat2Stat(MRI *rfin, RFS *rfsin, RFS *rfsout, MRI *binmask, MRI *rfout) { +MRI *RFstat2Stat(MRI *rfin, RFS *rfsin, RFS *rfsout, MRI *binmask, MRI *rfout) +{ MRI *p = NULL; if (RFname2Code(rfsin) == -1) return (NULL); @@ -282,7 +295,8 @@ MRI *RFstat2Stat(MRI *rfin, RFS *rfsin, RFS *rfsout, MRI *binmask, MRI *rfout) { } /*-------------------------------------------------------------------*/ -MRI *RFrescale(MRI *rf, RFS *rfs, MRI *binmask, MRI *rfout) { +MRI *RFrescale(MRI *rf, RFS *rfs, MRI *binmask, MRI *rfout) +{ int c, r, s, f, m; double v, gmean, gstddev, gmax; @@ -311,7 +325,8 @@ MRI *RFrescale(MRI *rf, RFS *rfs, MRI *binmask, MRI *rfout) { } /*-------------------------------------------------------------------*/ -int RFglobalStats(MRI *rf, MRI *binmask, double *gmean, double *gstddev, double *max) { +int RFglobalStats(MRI *rf, MRI *binmask, double *gmean, double *gstddev, double *max) +{ int c, r, s, f, m; double v; double sum, sumsq; @@ -345,7 +360,8 @@ int RFglobalStats(MRI *rf, MRI *binmask, double *gmean, double *gstddev, double } /*-------------------------------------------------------------------*/ -double RFdrawVal(RFS *rfs) { +double RFdrawVal(RFS *rfs) +{ if (!strcmp(rfs->name, "uniform")) { // params[0] = min // params[1] = max @@ -382,7 +398,8 @@ double RFdrawVal(RFS *rfs) { or greater from a random draw from the given distribution. Note: this is a one-sided test (where sidedness makes sense). -------------------------------------------------------------------*/ -double RFstat2PVal(RFS *rfs, double stat) { +double RFstat2PVal(RFS *rfs, double stat) +{ double p = -1; if (!strcmp(rfs->name, "uniform")) { // params[0] = min @@ -422,7 +439,8 @@ double RFstat2PVal(RFS *rfs, double stat) { /*------------------------------------------------------------------- RFp2StatVal() - -------------------------------------------------------------------*/ -double RFp2StatVal(RFS *rfs, double p) { +double RFp2StatVal(RFS *rfs, double p) +{ if (!strcmp(rfs->name, "uniform")) { // params[0] = min // params[1] = max @@ -458,7 +476,8 @@ double RFp2StatVal(RFS *rfs, double p) { /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ -int RFexpectedMeanStddevUniform(RFS *rfs) { +int RFexpectedMeanStddevUniform(RFS *rfs) +{ double min, max, d; min = rfs->params[0]; max = rfs->params[1]; @@ -470,7 +489,8 @@ int RFexpectedMeanStddevUniform(RFS *rfs) { /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ -int RFexpectedMeanStddevGaussian(RFS *rfs) { +int RFexpectedMeanStddevGaussian(RFS *rfs) +{ rfs->mean = rfs->params[0]; rfs->stddev = rfs->params[1]; return (0); @@ -478,7 +498,8 @@ int RFexpectedMeanStddevGaussian(RFS *rfs) { /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ -int RFexpectedMeanStddevt(RFS *rfs) { +int RFexpectedMeanStddevt(RFS *rfs) +{ double dof; dof = rfs->params[0]; rfs->mean = 0; @@ -488,7 +509,8 @@ int RFexpectedMeanStddevt(RFS *rfs) { /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ -int RFexpectedMeanStddevF(RFS *rfs) { +int RFexpectedMeanStddevF(RFS *rfs) +{ double ndof, ddof; ndof = rfs->params[0]; // numerator dof (rows in C) ddof = rfs->params[1]; // dof @@ -498,7 +520,8 @@ int RFexpectedMeanStddevF(RFS *rfs) { } /*-------------------------------------------------------------------*/ -int RFexpectedMeanStddevChi2(RFS *rfs) { +int RFexpectedMeanStddevChi2(RFS *rfs) +{ double dof; dof = rfs->params[0]; rfs->mean = dof; @@ -513,7 +536,8 @@ int RFexpectedMeanStddevChi2(RFS *rfs) { AR1 value is measured between two voxels a distance d appart. GStd will have the same units as d. -----------------------------------------------------------------*/ -double RFar1ToGStd(double ar1, double d) { +double RFar1ToGStd(double ar1, double d) +{ double gstd; if (ar1 <= 0.0) return (0.0); gstd = d / sqrt(-4 * log(ar1)); @@ -526,7 +550,8 @@ double RFar1ToGStd(double ar1, double d) { would result in the given AR1. The AR1 value is measured between two voxels a distance d appart. FWHM will have the same units as d. ------------------------------------------------------*/ -double RFar1ToFWHM(double ar1, double d) { +double RFar1ToFWHM(double ar1, double d) +{ double gstd, fwhm; gstd = RFar1ToGStd(ar1, d); fwhm = gstd * sqrt(log(256.0)); @@ -551,7 +576,8 @@ double RFar1ToFWHM(double ar1, double d) { the FSFAST toolbox. */ -double RFprobZCluster(double clustersize, double vzthresh, double fwhm, double searchsize, int dim) { +double RFprobZCluster(double clustersize, double vzthresh, double fwhm, double searchsize, int dim) +{ double u, phiu, k, S, W, Em, beta, Pnk, pcluster, D, pi; pi = M_PI; @@ -573,7 +599,8 @@ double RFprobZCluster(double clustersize, double vzthresh, double fwhm, double s // This form appears to go back to Hasofer 1978 if (dim != 3) { Em = exp(-(u * u) / 2) * pow(u, (D - 1)) * pow(2 * pi, -(D + 1) / 2) * S / pow(W, D); - } else { + } + else { // This form with (pow(u,(D-1))-1) for D=3 found in // Worsley, et al, 1996, HBM 4:58-73, Table II. This is what // FSL and KJW's stat_threshold.m use. In simulations, it seems @@ -623,7 +650,8 @@ double RFprobZCluster(double clustersize, double vzthresh, double fwhm, double s RFprobZCluster(). Note that the cluster are the set of voxels *below* the pvthresh. */ -double RFprobZClusterPThresh(double clustersize, double vpthresh, double fwhm, double searchsize, int dim) { +double RFprobZClusterPThresh(double clustersize, double vpthresh, double fwhm, double searchsize, int dim) +{ double vzthresh, pcluster; vzthresh = sc_cdf_gaussian_Qinv(vpthresh, 1.0); pcluster = RFprobZCluster(clustersize, vzthresh, fwhm, searchsize, dim); @@ -644,7 +672,8 @@ double RFprobZClusterPThresh(double clustersize, double vpthresh, double fwhm, d z-field. This function just computes the equivalenet z-threshold and calls RFprobZCluster(). */ -double RFprobZClusterSigThresh(double clustersize, double vsigthresh, double fwhm, double searchsize, int dim) { +double RFprobZClusterSigThresh(double clustersize, double vsigthresh, double fwhm, double searchsize, int dim) +{ double vzthresh, pcluster, vpthresh; vpthresh = pow(10.0, -fabs(vsigthresh)); vzthresh = sc_cdf_gaussian_Qinv(vpthresh, 1.0); @@ -656,7 +685,8 @@ double RFprobZClusterSigThresh(double clustersize, double vsigthresh, double fwh \fn MRI *RFp2z(MRI *p, MRI *mask, MRI *z) \brief Converts a p-value to a two-sided z */ -MRI *RFp2z(MRI *p, MRI *mask, MRI *z) { +MRI *RFp2z(MRI *p, MRI *mask, MRI *z) +{ RFS *rfs; rfs = RFspecInit(0, NULL); rfs->name = strcpyalloc("gaussian"); @@ -670,7 +700,8 @@ MRI *RFp2z(MRI *p, MRI *mask, MRI *z) { \fn MRI *RFz1toz2(MRI *z1, MRI *mask, MRI *z2) \brief Converts a one-sided z-map to a two-sided z-map */ -MRI *RFz1toz2(MRI *z1, MRI *mask, MRI *z2) { +MRI *RFz1toz2(MRI *z1, MRI *mask, MRI *z2) +{ MRI *p; int TwoSidedFlag = 1; diff --git a/utils/rbf.c b/utils/rbf.c index 8b3ca51ebee..8e8d033692b 100644 --- a/utils/rbf.c +++ b/utils/rbf.c @@ -81,7 +81,8 @@ STRUCTURES -------------------------------------------------------*/ -typedef struct { +typedef struct +{ int current_class; int (*get_observation_func)(VECTOR *v, int obs_no, void *parm, int same_class, int *classno); void *parm; @@ -123,7 +124,8 @@ static int rbfAllocateTrainingParameters(RBF *rbf); Description allocate and initialize an rbf classifier. ------------------------------------------------------*/ -RBF *RBFinit(int ninputs, int noutputs, int max_clusters[], char *names[]) { +RBF *RBFinit(int ninputs, int noutputs, int max_clusters[], char *names[]) +{ RBF *rbf; int i; @@ -193,7 +195,8 @@ RBF *RBFinit(int ninputs, int noutputs, int max_clusters[], char *names[]) { int RBFtrain(RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm, - float momentum) { + float momentum) +{ int i, class, c, cno; CLUSTERING_PARM cp; CLUSTER_SET *cs; @@ -255,7 +258,8 @@ int RBFtrain(RBF *rbf, int RBFretrain(RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm, - float momentum) { + float momentum) +{ if ((momentum < 1.0f) && (momentum >= 0.0f)) rbf->base_momentum = rbf->momentum = momentum; /* must examine training set before allocating training set data, because @@ -291,7 +295,8 @@ int RBFretrain(RBF *rbf, Description free the memory allocated by an RBF structure. ------------------------------------------------------*/ -int RBFfree(RBF **prbf) { +int RBFfree(RBF **prbf) +{ RBF *rbf; int i; @@ -342,7 +347,8 @@ int RBFfree(RBF **prbf) { Description print out the contents of an RBF to a file. ------------------------------------------------------*/ -int RBFprint(RBF *rbf, FILE *fp) { +int RBFprint(RBF *rbf, FILE *fp) +{ int i, c; CLUSTER_SET *cs; CLUSTER *cluster; @@ -384,7 +390,8 @@ int RBFprint(RBF *rbf, FILE *fp) { while class_obs refers to the # of observations for the given class. ------------------------------------------------------*/ -static int rbf_get_obs_func(VECTOR *v_obs, int desired_class_obs_no, void *vcp) { +static int rbf_get_obs_func(VECTOR *v_obs, int desired_class_obs_no, void *vcp) +{ CLUSTERING_PARM *cp; int ret, classno, obs_no, class_obs_no; static int last_class = -1; @@ -399,7 +406,8 @@ static int rbf_get_obs_func(VECTOR *v_obs, int desired_class_obs_no, void *vcp) /* start at one past previous observation, not at start */ class_obs_no = last_class_obs; obs_no = last_obs + 1; - } else + } + else class_obs_no = obs_no = 0; do { @@ -411,7 +419,8 @@ static int rbf_get_obs_func(VECTOR *v_obs, int desired_class_obs_no, void *vcp) last_class = classno; last_obs = obs_no - 1; last_class_obs = desired_class_obs_no; - } else + } + else last_class = last_obs = last_class_obs = -1; return (ret); @@ -426,7 +435,8 @@ static int rbf_get_obs_func(VECTOR *v_obs, int desired_class_obs_no, void *vcp) only those inputs which have the appropriate class. ------------------------------------------------------*/ static int rbfGradientDescent( - RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm) { + RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm) +{ if (Gdiag & DIAG_SHOW) { rbfShowClusterCenters(rbf, stderr); fprintf(stderr, "calculating output weights..."); @@ -451,7 +461,8 @@ static int rbfGradientDescent( Given the observation vector v_obs, compute the activation of the hidden units (RBFs). ------------------------------------------------------*/ -static int rbfComputeHiddenActivations(RBF *rbf, VECTOR *v_obs) { +static int rbfComputeHiddenActivations(RBF *rbf, VECTOR *v_obs) +{ int c; CLUSTER *cluster; float total; @@ -479,7 +490,8 @@ static int rbfComputeHiddenActivations(RBF *rbf, VECTOR *v_obs) { Given the observation vector v_obs, compute the activation of the hidden units (RBFs). ------------------------------------------------------*/ -static int rbfShowClusterCenters(RBF *rbf, FILE *fp) { +static int rbfShowClusterCenters(RBF *rbf, FILE *fp) +{ int i, c; CLUSTER *cluster; CLUSTER_SET *cs; @@ -511,7 +523,8 @@ static int rbfShowClusterCenters(RBF *rbf, FILE *fp) { inverse covariance matrix m_sigma_inverse given the input v_obs. ------------------------------------------------------*/ -static float rbfGaussian(MATRIX *m_sigma_inverse, VECTOR *v_means, VECTOR *v_obs, VECTOR *v_z, float norm) { +static float rbfGaussian(MATRIX *m_sigma_inverse, VECTOR *v_means, VECTOR *v_obs, VECTOR *v_z, float norm) +{ float val = 0.0f; static VECTOR *v_zT = NULL; static MATRIX *m_tmp1 = NULL, *m_tmp2 = NULL; @@ -546,7 +559,8 @@ static float rbfGaussian(MATRIX *m_sigma_inverse, VECTOR *v_means, VECTOR *v_obs inverse covariance matrix m_sigma_inverse given the input v_obs. ------------------------------------------------------*/ -float RBFcomputeErrors(RBF *rbf, int class, VECTOR *v_error) { +float RBFcomputeErrors(RBF *rbf, int class, VECTOR *v_error) +{ int i; float target, error, total_error; @@ -571,7 +585,8 @@ float RBFcomputeErrors(RBF *rbf, int class, VECTOR *v_error) { Adjust the weights in the (linear) output layer using the LMS algorithm. ------------------------------------------------------*/ -static int rbfAdjustOutputWeights(RBF *rbf, VECTOR *v_error) { +static int rbfAdjustOutputWeights(RBF *rbf, VECTOR *v_error) +{ int i, j; float Gi, delta_wij, one_minus_momentum, trate, momentum; // float dE_dwi; @@ -602,7 +617,8 @@ static int rbfAdjustOutputWeights(RBF *rbf, VECTOR *v_error) { Description Print the RBF activations to a file for debugging. ------------------------------------------------------*/ -int RBFprintActivations(RBF *rbf, VECTOR *v_obs, VECTOR *v_error, int class, FILE *fp) { +int RBFprintActivations(RBF *rbf, VECTOR *v_obs, VECTOR *v_error, int class, FILE *fp) +{ int i; /* fprintf(fp, "rbf: ") ;*/ @@ -629,7 +645,8 @@ int RBFprintActivations(RBF *rbf, VECTOR *v_obs, VECTOR *v_error, int class, FIL Adjust the centers (means) of the Gaussians in the hidden layer. ------------------------------------------------------*/ -static int rbfAdjustHiddenCenters(RBF *rbf, VECTOR *v_error) { +static int rbfAdjustHiddenCenters(RBF *rbf, VECTOR *v_error) +{ int i, j; float Gi, one_minus_momentum, trate, momentum, total, delta; VECTOR *v_means, *v_delta_means, *v_z; @@ -681,7 +698,8 @@ static int rbfAdjustHiddenCenters(RBF *rbf, VECTOR *v_error) { Adjust the spreads (covariance matrices) of the Gaussians in the hidden layer. ------------------------------------------------------*/ -static int rbfAdjustHiddenSpreads(RBF *rbf, VECTOR *v_error) { +static int rbfAdjustHiddenSpreads(RBF *rbf, VECTOR *v_error) +{ int i, j; float Gi, one_minus_momentum, trate, momentum, total, delta, det; VECTOR *v_z; @@ -739,7 +757,8 @@ static int rbfAdjustHiddenSpreads(RBF *rbf, VECTOR *v_error) { Compute the outputs of the RBF (assumes rbfComputeHiddenActivations has already been called). ------------------------------------------------------*/ -static int rbfComputeOutputs(RBF *rbf) { +static int rbfComputeOutputs(RBF *rbf) +{ #if 0 int i ; float min_out, val, total ; @@ -779,7 +798,8 @@ static int rbfComputeOutputs(RBF *rbf) { Description Classify an observation vector. ------------------------------------------------------*/ -int RBFclassify(RBF *rbf, VECTOR *v_obs) { +int RBFclassify(RBF *rbf, VECTOR *v_obs) +{ int class, c; float max_val, val; @@ -814,7 +834,8 @@ static int rbfNormalizeObservation(RBF *rbf, VECTOR *v_in, VECTOR *v_out) { retu static float rbfTrain(RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm, - int which) { + int which) +{ VECTOR *v_obs, *v_error; int obs_no, class, epoch = 0, nsmall = 0, nnegative = 0, nobs, positive = 0; float error, sse = 0.0f, delta_sse, rms, old_sse; @@ -882,7 +903,8 @@ static float rbfTrain(RBF *rbf, RBFcopyWeights(rbf_save, rbf); /* restore old weights */ rbf->trate *= TRATE_DECREASE; sse = old_sse; - } else /* accept new network, error either went down or up a little */ + } + else /* accept new network, error either went down or up a little */ { rbf->momentum = rbf->base_momentum; if (sse < old_sse) /* error decreased, increase training rate */ @@ -899,7 +921,8 @@ static float rbfTrain(RBF *rbf, if (delta_sse < 0) { nnegative++; positive = 0; - } else { + } + else { nnegative = 0; if (delta_sse > 0) positive++; } @@ -914,7 +937,8 @@ static float rbfTrain(RBF *rbf, continue; break; /* too many small steps in a row, assume we have asymptoted */ } - } else + } + else nsmall = 0; if (rbf->trate < MIN_TRATE) rbf->trate = MIN_TRATE; @@ -930,7 +954,8 @@ static float rbfTrain(RBF *rbf, Description ------------------------------------------------------*/ -int RBFwrite(RBF *rbf, char *fname) { +int RBFwrite(RBF *rbf, char *fname) +{ FILE *fp; int error; @@ -948,7 +973,8 @@ int RBFwrite(RBF *rbf, char *fname) { Description ------------------------------------------------------*/ -RBF *RBFread(char *fname) { +RBF *RBFread(char *fname) +{ FILE *fp; RBF *rbf; @@ -971,7 +997,8 @@ RBF *RBFread(char *fname) { ------------------------------------------------------*/ int RBFexamineTrainingSet(RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), - void *parm) { + void *parm) +{ int obs_no = 0, class, row, c, i; VECTOR *v_obs; float *means, *stds, v, mean; @@ -1038,7 +1065,8 @@ int RBFexamineTrainingSet(RBF *rbf, Save the weights of one RBF in another, for possible restoration. ------------------------------------------------------*/ -RBF *RBFcopyWeights(RBF *rbf_src, RBF *rbf_dst) { +RBF *RBFcopyWeights(RBF *rbf_src, RBF *rbf_dst) +{ int i; if (!rbf_dst) { @@ -1095,7 +1123,8 @@ RBF *RBFcopyWeights(RBF *rbf_src, RBF *rbf_dst) { Compute the sse on the training set. ------------------------------------------------------*/ static float rbfComputeCurrentError( - RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm) { + RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm) +{ float error, sse, obs_no; // float rms; VECTOR *v_obs, *v_error; @@ -1138,7 +1167,8 @@ static float rbfComputeCurrentError( pth pattern. ------------------------------------------------------*/ static int rbfCalculateOutputWeights( - RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm) { + RBF *rbf, int (*get_observation_func)(VECTOR *v_obs, int no, void *parm, int same_class, int *pclass), void *parm) +{ VECTOR *v_obs, *v_hidden; int class, obs_no, i, k; MATRIX *m_Gt_G, *m_Gt_G_inv, *m_Gt_D; @@ -1182,7 +1212,8 @@ static int rbfCalculateOutputWeights( fprintf(stderr, "regularizing matrix...\n"); /* MatrixRegularize(m_Gt_G, m_Gt_G) ;*/ m_Gt_G_inv = MatrixSVDInverse(m_Gt_G, NULL); - } else + } + else m_Gt_G_inv = MatrixInverse(m_Gt_G, NULL); if (!m_Gt_G_inv) ErrorReturn(ERROR_BADPARM, (ERROR_BADPARM, "rbfCalculateOutputWeights: matrix is singular")); @@ -1229,7 +1260,8 @@ static int rbfCalculateOutputWeights( Description Allocate training-specific parameters. ------------------------------------------------------*/ -static int rbfAllocateTrainingParameters(RBF *rbf) { +static int rbfAllocateTrainingParameters(RBF *rbf) +{ int i; rbf->observed = (unsigned char *)calloc(rbf->nobs, sizeof(unsigned char)); @@ -1259,7 +1291,8 @@ static int rbfAllocateTrainingParameters(RBF *rbf) { Description Write a classifier into a previously opened file. ------------------------------------------------------*/ -int RBFwriteInto(RBF *rbf, FILE *fp) { +int RBFwriteInto(RBF *rbf, FILE *fp) +{ int i; fprintf(fp, "%d %d %d\n", rbf->noutputs, rbf->ninputs, rbf->nhidden); @@ -1283,7 +1316,8 @@ int RBFwriteInto(RBF *rbf, FILE *fp) { Description Read a classifier from a previously opened file ------------------------------------------------------*/ -RBF *RBFreadFrom(FILE *fp) { +RBF *RBFreadFrom(FILE *fp) +{ int i, c, cno, class, noutputs, ninputs, nhidden, max_clusters[MAX_OUTPUTS]; char *names[MAX_OUTPUTS], *cp, line[100]; RBF *rbf; diff --git a/utils/rbm.c b/utils/rbm.c index 5c71e6c9d13..09af454453f 100644 --- a/utils/rbm.c +++ b/utils/rbm.c @@ -41,7 +41,8 @@ int dump_hidden(RBM *rbm, char *fname); int dump_visible(RBM *rbm, char *fname); -static int compare_pvals(const void *v1, const void *v2) { +static int compare_pvals(const void *v1, const void *v2) +{ LABEL_PVAL *p1, *p2; p1 = (LABEL_PVAL *)v1; @@ -52,7 +53,8 @@ static int compare_pvals(const void *v1, const void *v2) { return (0); // equal } -int RBMsortLabelProbabilities(RBM *rbm) { +int RBMsortLabelProbabilities(RBM *rbm) +{ int l; for (l = 0; l < rbm->nlabels; l++) { @@ -64,7 +66,8 @@ int RBMsortLabelProbabilities(RBM *rbm) { return (NO_ERROR); } -static MRI *weights_to_mri(RBM *rbm) { +static MRI *weights_to_mri(RBM *rbm) +{ MRI *mri; int v, h, k1, k2; @@ -75,7 +78,8 @@ static MRI *weights_to_mri(RBM *rbm) { for (k2 = 0; k2 < rbm->ksize; k2++, v++) MRIsetVoxVal(mri, k1, k2, 0, h, rbm->weights[v][h]); } MRIcopyHeader(rbm->mri_inputs, mri); - } else { + } + else { mri = MRIalloc(rbm->nvisible, rbm->nhidden, 1, MRI_FLOAT); for (v = 0; v < rbm->nvisible; v++) for (h = 0; h < rbm->nhidden; h++) MRIsetVoxVal(mri, v, h, 0, 0, rbm->weights[v][h]); @@ -83,7 +87,8 @@ static MRI *weights_to_mri(RBM *rbm) { return (mri); } -static MRI *layer_weights_to_mri(DBN *dbn, int layer) { +static MRI *layer_weights_to_mri(DBN *dbn, int layer) +{ MRI *mri, *mri_previous_layer, *mri_tmp = NULL; int v, h; RBM *rbm_first = dbn->rbms[0], *rbm; @@ -109,7 +114,8 @@ static MRI *layer_weights_to_mri(DBN *dbn, int layer) { MRIfree(&mri_tmp); MRIfree(&mri_previous_layer); MRIcopyHeader(rbm->mri_inputs, mri); - } else { + } + else { rbm = dbn->rbms[layer]; mri = MRIalloc(rbm->nvisible, rbm->nhidden, 1, MRI_FLOAT); for (v = 0; v < rbm->nvisible; v++) @@ -118,7 +124,8 @@ static MRI *layer_weights_to_mri(DBN *dbn, int layer) { return (mri); } static int dump_gradients( - RBM *rbm, double *dvisible_bias, double *dvariance, double *dhidden_bias, double **dw, RBM_PARMS *parms, int step) { + RBM *rbm, double *dvisible_bias, double *dvariance, double *dhidden_bias, double **dw, RBM_PARMS *parms, int step) +{ int v, h; printf("visible state: "); @@ -178,7 +185,8 @@ visible_to_mri(RBM *rbm) return(mri) ; } #endif -double RBMfreeEnergy(RBM *rbm, double *visible) { +double RBMfreeEnergy(RBM *rbm, double *visible) +{ double free_energy[MAX_RBM_LABELS], total; int v, h, l; @@ -197,7 +205,8 @@ double RBMfreeEnergy(RBM *rbm, double *visible) { free_energy[l] -= pj * rbm->act[h]; free_energy[l] += (pj * log(pj) + (1 - pj) * log(1 - pj)); } - } else // Gaussian inputs + } + else // Gaussian inputs { double var; @@ -211,7 +220,8 @@ double RBMfreeEnergy(RBM *rbm, double *visible) { } if (DZERO(total)) total = 0.00000001; for (l = 0; l < rbm->nlabels; l++) rbm->labels[l] = exp(-free_energy[l]) / total; - } else { + } + else { free_energy[0] = 0; for (v = 0; v < rbm->nvisible; v++) free_energy[0] -= visible[v] * rbm->visible_bias[v]; for (h = 0; h < rbm->nhidden; h++) { @@ -225,7 +235,8 @@ double RBMfreeEnergy(RBM *rbm, double *visible) { return (free_energy[0]); } -int RBMwriteNetwork(RBM *rbm, int n, RBM_PARMS *parms, int layer) { +int RBMwriteNetwork(RBM *rbm, int n, RBM_PARMS *parms, int layer) +{ MRI *mri; char fname[STRLEN]; @@ -235,7 +246,8 @@ int RBMwriteNetwork(RBM *rbm, int n, RBM_PARMS *parms, int layer) { sprintf(fname, "%s.wts.mgz", parms->base_name); else sprintf(fname, "%s.%3.3d.wts.mgz", parms->base_name, n); - } else { + } + else { if (n < 0) sprintf(fname, "%s.layer%d.wts.mgz", parms->base_name, layer); else @@ -259,7 +271,8 @@ int RBMwriteNetwork(RBM *rbm, int n, RBM_PARMS *parms, int layer) { return (NO_ERROR); } -int RBMprintNetworkActivations(RBM *rbm, FILE *fp, int n, RBM_PARMS *parms) { +int RBMprintNetworkActivations(RBM *rbm, FILE *fp, int n, RBM_PARMS *parms) +{ int v, h; printf("visible state: "); @@ -272,7 +285,8 @@ int RBMprintNetworkActivations(RBM *rbm, FILE *fp, int n, RBM_PARMS *parms) { return (NO_ERROR); } -RBM *RBMcopy(RBM *rbm_src, RBM *rbm_dst) { +RBM *RBMcopy(RBM *rbm_src, RBM *rbm_dst) +{ int l, v, h; if (rbm_dst == NULL) @@ -311,7 +325,8 @@ RBM *RBMcopy(RBM *rbm_src, RBM *rbm_dst) { return (rbm_dst); } -RBM *RBMalloc(int type, int nvisible, int nhidden, int nlabels, int input_type) { +RBM *RBMalloc(int type, int nvisible, int nhidden, int nlabels, int input_type) +{ RBM *rbm; int v, h; double wt_lim; @@ -396,7 +411,8 @@ RBM *RBMalloc(int type, int nvisible, int nhidden, int nlabels, int input_type) return (rbm); } -int RBMactivateForward(RBM *rbm, double *visible) { +int RBMactivateForward(RBM *rbm, double *visible) +{ int h; if (visible) memcpy(rbm->visible, visible, rbm->nvisible * sizeof(visible[0])); @@ -441,7 +457,8 @@ int RBMactivateForward(RBM *rbm, double *visible) { return (NO_ERROR); } -int RBMactivateBackward(RBM *rbm) { +int RBMactivateBackward(RBM *rbm) +{ int v; if (rbm->type == RBM_TYPE_CONTINUOUS_INPUTS) { @@ -461,7 +478,8 @@ int RBMactivateBackward(RBM *rbm) { rbm->visible[v] = act; } - } else // inputs are binary + } + else // inputs are binary { #if 1 #ifdef HAVE_OPENMP @@ -526,7 +544,8 @@ int RBMactivateBackward(RBM *rbm) { return (NO_ERROR); } -int RBMfree(RBM **prbm) { +int RBMfree(RBM **prbm) +{ RBM *rbm; int v; @@ -558,14 +577,16 @@ int RBMfree(RBM **prbm) { int RBMwrite(RBM *rbm, char *fname) { return (NO_ERROR); } -RBM *RBMread(char *fname) { +RBM *RBMread(char *fname) +{ RBM *rbm = NULL; return (rbm); } static int Ncd = 5; -int RBMfillVisible(RBM *rbm, MRI *mri_inputs, double *visible, int x0, int y0, int z0, int f0, int ksize) { +int RBMfillVisible(RBM *rbm, MRI *mri_inputs, double *visible, int x0, int y0, int z0, int f0, int ksize) +{ int xk, yk, xi, yi, whalf, v; float val; @@ -579,7 +600,8 @@ int RBMfillVisible(RBM *rbm, MRI *mri_inputs, double *visible, int x0, int y0, i visible[v] = val; } } - } else { + } + else { int f; for (f = 0; f < mri_inputs->nframes; f++) visible[f] = MRIgetVoxVal(mri_inputs, x0, y0, z0, f); @@ -588,7 +610,8 @@ int RBMfillVisible(RBM *rbm, MRI *mri_inputs, double *visible, int x0, int y0, i return (NO_ERROR); } -int RBMmostLikelyLabel(RBM *rbm) { +int RBMmostLikelyLabel(RBM *rbm) +{ int best_label, label; double pbest; @@ -603,14 +626,16 @@ int RBMmostLikelyLabel(RBM *rbm) { return (best_label); } -int RBMsetLabel(RBM *rbm, int label) { +int RBMsetLabel(RBM *rbm, int label) +{ if (label < 0 || label >= rbm->nlabels) return (ERROR_BADPARM); memset(rbm->labels, 0, rbm->nlabels * sizeof(rbm->labels[0])); rbm->labels[label] = 1; return (NO_ERROR); } -double RBMvoxlistRMS(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num) { +double RBMvoxlistRMS(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num) +{ int i, x, y, z, f, n, ind, v, nvox, h; double rms, *visible; MRI *mri_inputs; @@ -639,7 +664,8 @@ double RBMvoxlistRMS(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms, int *indices, int } } for (h = 0; h < rbm->nhidden; h++) rbm->active[h] /= (double)num; - } else { + } + else { for (rms = 0.0, nvox = i = 0; i < vl->nvox; i++) { x = vl->xi[i]; y = vl->yi[i]; @@ -664,7 +690,8 @@ double RBMvoxlistRMS(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms, int *indices, int #define HISTO_BINS 100 #include "histo.h" static double sigma = 10; -double RBMvoxlistHistoRMS(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num) { +double RBMvoxlistHistoRMS(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num) +{ int i, x, y, z, f, n, ind, v, min_ind, max_ind; double rms, *visible; HISTOGRAM **histo_data, **histo_recon; @@ -683,7 +710,8 @@ double RBMvoxlistHistoRMS(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms, int *indices, if (indices) { min_ind = index; max_ind = index + num - 1; - } else { + } + else { min_ind = 0; max_ind = vl->nvox - 1; } @@ -743,7 +771,8 @@ int RBMcomputeGradients(RBM *rbm, double **dlabel_weights, RBM_PARMS *parms, int *indices, - int index) { + int index) +{ int i, x, y, z, f, n, v, h, ind, current_label; double *visible, Q0, Qn, V0, Vn, *hidden0, scale, *db_sparsity, *active; MRI *mri_inputs = vl->mri; @@ -886,7 +915,8 @@ int RBMcomputeGradients(RBM *rbm, return (NO_ERROR); } -int RBMtrainFromImage(RBM *rbm, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *parms) { +int RBMtrainFromImage(RBM *rbm, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *parms) +{ VOXLIST *vl; rbm->mri_inputs = mri_inputs; @@ -903,7 +933,8 @@ int RBMtrainFromImage(RBM *rbm, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *par return (NO_ERROR); } -int RBMtrainFromVoxlistImage(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms) { +int RBMtrainFromVoxlistImage(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms) +{ double training_rate, last_rms, pct_diff, rms, momentum, delta, min_rms, **dw, *dvisible_bias, *dhidden_bias, *dvariance, *last_dvariance, *dlabel_bias = NULL, **dlabel_weights = NULL, **last_dw, *last_dvisible_bias, *last_dhidden_bias, *last_dlabel_bias = NULL, **last_dlabel_weights = NULL, var; @@ -1019,13 +1050,15 @@ int RBMtrainFromVoxlistImage(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms) { // memset(last_dhidden_bias, 0, rbm->nhidden*sizeof(last_dhidden_bias[0])) ; // for (v = 0 ; v < rbm->nvisible ; v++) // memset(last_dw[v], 0, rbm->nhidden*sizeof(last_dw[v][0])) ; - } else + } + else training_rate *= 1.000; if (rms < min_rms) { min_rms = rms; nbad = 0; - } else if (nbad++ > parms->max_no_progress) { + } + else if (nbad++ > parms->max_no_progress) { printf("stopping learning due to lack of progress\n"); break; } @@ -1055,7 +1088,8 @@ int RBMtrainFromVoxlistImage(RBM *rbm, VOXLIST *vl, RBM_PARMS *parms) { free(last_dvariance); return (NO_ERROR); } -int RBMcountHiddenActive(RBM *rbm) { +int RBMcountHiddenActive(RBM *rbm) +{ int hidden_active, h; for (h = hidden_active = 0; h < rbm->nhidden; h++) { @@ -1064,8 +1098,8 @@ int RBMcountHiddenActive(RBM *rbm) { return (hidden_active); } -MRI *RBMaverageActiveHiddenReceptiveFields( - RBM *rbm, MRI *mri_receptive_fields, MRI *mri_inputs, int x0, int y0, int z0) { +MRI *RBMaverageActiveHiddenReceptiveFields(RBM *rbm, MRI *mri_receptive_fields, MRI *mri_inputs, int x0, int y0, int z0) +{ int k1, k2, xi, yi, zi, h, whalf; double val; @@ -1091,7 +1125,8 @@ MRI *RBMaverageActiveHiddenReceptiveFields( } static double threshold = 0.9; -MRI *RBMreconstruct(RBM *rbm, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmri_labeled, RBM_PARMS *parms) { +MRI *RBMreconstruct(RBM *rbm, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmri_labeled, RBM_PARMS *parms) +{ int h, x, y, z, center, n, nvox, hidden_active, *hidden_counts, whalf, f; float rms, V0, Vn; HISTOGRAM *histo; @@ -1159,7 +1194,8 @@ MRI *RBMreconstruct(RBM *rbm, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmr sprintf(fname, "%s.hidden_labels.plt", parms->base_name); printf("saving %s\n", fname); HISTO2Dplot(histo_labels, fname); - } else { + } + else { int v; for (rms = 0.0, f = 0; f < mri_inputs->nframes; f++) @@ -1191,7 +1227,8 @@ MRI *RBMreconstruct(RBM *rbm, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmr if (hidden_counts[h] > 0) { float scale = 1.0 / hidden_counts[h]; MRIscalarMulFrame(mri_receptive_fields, mri_receptive_fields, scale, h); - } else + } + else printf("hidden node %d never active\n", h); } MRIwrite(mri_receptive_fields, "rfs.mgz"); @@ -1204,7 +1241,8 @@ MRI *RBMreconstruct(RBM *rbm, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmr if (pmri_labeled) *pmri_labeled = mri_labeled; return (mri_reconstructed); } -DBN *DBNalloc(int type, int nlayers, int nvisible, int *nhidden, int nlabels, int input_type) { +DBN *DBNalloc(int type, int nlayers, int nvisible, int *nhidden, int nlabels, int input_type) +{ DBN *dbn; int itype, nl, layer; @@ -1231,7 +1269,8 @@ DBN *DBNalloc(int type, int nlayers, int nvisible, int *nhidden, int nlabels, in return (dbn); } -int DBNfree(DBN **pdbn) { +int DBNfree(DBN **pdbn) +{ DBN *dbn; int layer; @@ -1245,7 +1284,8 @@ int DBNfree(DBN **pdbn) { DBN *DBNread(char *fname) { return (NULL); } int DBNwrite(DBN *dbn, char *fname) { return (NO_ERROR); } -int DBNactivateForward(DBN *dbn, double *visible, int nlayers) { +int DBNactivateForward(DBN *dbn, double *visible, int nlayers) +{ int l; if (nlayers <= 0) nlayers = dbn->nlayers; @@ -1256,7 +1296,8 @@ int DBNactivateForward(DBN *dbn, double *visible, int nlayers) { return (NO_ERROR); } -int DBNactivateBackward(DBN *dbn, int last_layer, int first_layer) { +int DBNactivateBackward(DBN *dbn, int last_layer, int first_layer) +{ int l; if (last_layer < 0) last_layer = dbn->nlayers - 1; @@ -1272,7 +1313,8 @@ int DBNactivateBackward(DBN *dbn, int last_layer, int first_layer) { return (NO_ERROR); } -int DBNtrainFromImage(DBN *dbn, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *parms) { +int DBNtrainFromImage(DBN *dbn, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *parms) +{ VOXLIST *vl; if (parms->write_iterations > 0) { @@ -1288,7 +1330,8 @@ int DBNtrainFromImage(DBN *dbn, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *par return (NO_ERROR); } -int DBNtrainFromVoxlistImage(DBN *dbn, VOXLIST *vl, RBM_PARMS *parms) { +int DBNtrainFromVoxlistImage(DBN *dbn, VOXLIST *vl, RBM_PARMS *parms) +{ double training_rate, last_rms, pct_diff, rms, momentum, delta, min_rms, **dw, *dvisible_bias, *dhidden_bias, *dvariance, *last_dvariance, *dlabel_bias = NULL, **dlabel_weights = NULL, **last_dw, *last_dvisible_bias, *last_dhidden_bias, *last_dlabel_bias = NULL, **last_dlabel_weights = NULL, var; @@ -1413,13 +1456,15 @@ int DBNtrainFromVoxlistImage(DBN *dbn, VOXLIST *vl, RBM_PARMS *parms) { // memset(last_dhidden_bias, 0, rbm->nhidden*sizeof(last_dhidden_bias[0])) ; // for (v = 0 ; v < rbm->nvisible ; v++) // memset(last_dw[v], 0, rbm->nhidden*sizeof(last_dw[v][0])) ; - } else + } + else training_rate *= 1.000; if (rms < min_rms) { min_rms = rms; nbad = 0; - } else if (nbad++ > parms->max_no_progress) { + } + else if (nbad++ > parms->max_no_progress) { printf("stopping learning due to lack of progress\n"); break; } @@ -1450,7 +1495,8 @@ int DBNtrainFromVoxlistImage(DBN *dbn, VOXLIST *vl, RBM_PARMS *parms) { } return (NO_ERROR); } -int DBNwriteNetwork(DBN *dbn, int n, RBM_PARMS *parms) { +int DBNwriteNetwork(DBN *dbn, int n, RBM_PARMS *parms) +{ int layer; MRI *mri; char fname[STRLEN]; @@ -1480,7 +1526,8 @@ int DBNcomputeGradients(DBN *dbn, double **dlabel_weights, RBM_PARMS *parms, int *indices, - int index) { + int index) +{ int i, x, y, z, f, n, v, h, ind, current_label; double *visible, Q0, Qn, V0, Vn, *hidden0, scale, *db_sparsity, *active; MRI *mri_inputs = vl->mri; @@ -1632,7 +1679,8 @@ int DBNcomputeGradients(DBN *dbn, return (NO_ERROR); } -MRI *DBNreconstruct(DBN *dbn, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmri_labeled, RBM_PARMS *parms) { +MRI *DBNreconstruct(DBN *dbn, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmri_labeled, RBM_PARMS *parms) +{ int x, y, z, center, n, nvox, whalf, f, h, hidden_active; float rms = 0.0, V0, Vn; MRI *mri_labeled = NULL; @@ -1751,7 +1799,8 @@ MRI *DBNreconstruct(DBN *dbn, MRI *mri_inputs, MRI *mri_reconstructed, MRI **pmr if (pmri_labeled) *pmri_labeled = mri_labeled; return (mri_reconstructed); } -double DBNvoxlistRMS(DBN *dbn, int layer, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num) { +double DBNvoxlistRMS(DBN *dbn, int layer, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num) +{ int i, x, y, z, f, n, ind, v, nvox; double rms, *visible; MRI *mri_inputs; @@ -1783,7 +1832,8 @@ double DBNvoxlistRMS(DBN *dbn, int layer, VOXLIST *vl, RBM_PARMS *parms, int *in rms += SQR(visible[v] - rbm->visible[v]); } } - } else { + } + else { for (rms = 0.0, nvox = i = 0; i < vl->nvox; i++) { x = vl->xi[i]; y = vl->yi[i]; @@ -1804,7 +1854,8 @@ double DBNvoxlistRMS(DBN *dbn, int layer, VOXLIST *vl, RBM_PARMS *parms, int *in free(visible); return (rms); } -int CDBNtrainFromImage(CDBN *cdbn, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *parms) { +int CDBNtrainFromImage(CDBN *cdbn, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS *parms) +{ VOXLIST *vl; if (parms->write_iterations > 0) { @@ -1820,7 +1871,8 @@ int CDBNtrainFromImage(CDBN *cdbn, MRI *mri_inputs, MRI *mri_labels, RBM_PARMS * return (NO_ERROR); } -CDBN *CDBNalloc(int type, int nlayers, int *ksizes, int *ngroups, int nlabels, MRI *mri_inputs) { +CDBN *CDBNalloc(int type, int nlayers, int *ksizes, int *ngroups, int nlabels, MRI *mri_inputs) +{ CDBN *cdbn; int nl, layer, nvisible; @@ -1856,7 +1908,8 @@ CDBN *CDBNalloc(int type, int nlayers, int *ksizes, int *ngroups, int nlabels, M return (cdbn); } -static int reset_hidden_nodes(CDBN *cdbn, int layer, double min_active, double max_active) { +static int reset_hidden_nodes(CDBN *cdbn, int layer, double min_active, double max_active) +{ int h, num_off, num_on; #if 0 int v ; @@ -1898,7 +1951,8 @@ static int reset_hidden_nodes(CDBN *cdbn, int layer, double min_active, double m return (num_off + num_on); } -int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mri_inputs, MRI *mri_labels) { +int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mri_inputs, MRI *mri_labels) +{ double sparsity, training_rate, last_rms, pct_diff, rms, momentum, delta, min_rms, **dw, *dvisible_bias, *dhidden_bias, *dvariance, *last_dvariance, *dlabel_bias = NULL, **dlabel_weights = NULL, **last_dw, *last_dvisible_bias, *last_dhidden_bias, @@ -1940,7 +1994,8 @@ int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mr { CDBNcreateOutputs(cdbn, parms, mri_inputs, layer - 1, layer - 1, NULL); mri_layer_inputs = cdbn->mri_outputs[layer - 1]; - } else + } + else mri_layer_inputs = mri_inputs; printf( @@ -2059,7 +2114,8 @@ int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mr label_rms, label_pct_diff, new_min ? "****" : ""); - } else + } + else printf("iter %3.3d: rms = %2.5f (%2.3f%%) %s\n", step + 1, rms, pct_diff, new_min ? "****" : ""); if (step == Gdiag_no) DiagBreak(); if (last_rms < rms) { @@ -2069,7 +2125,8 @@ int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mr // memset(last_dhidden_bias, 0, rbm->nhidden*sizeof(last_dhidden_bias[0])) ; // for (v = 0 ; v < rbm->nvisible ; v++) // memset(last_dw[v], 0, rbm->nhidden*sizeof(last_dw[v][0])) ; - } else + } + else training_rate *= 1.000; if (label_rms < min_label_rms) // save best label rms and RBM @@ -2092,7 +2149,8 @@ int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mr cdbn->rbms[layer] = rbm_min; rms = CDBNvoxlistRMS(cdbn, layer, vl, parms, indices, held_out_index, parms->held_out, &label_rms); cdbn->rbms[layer] = rbm_save; - } else if (nbad++ > parms->max_no_progress) { + } + else if (nbad++ > parms->max_no_progress) { printf("stopping learning due to lack of progress\n"); break; } @@ -2185,7 +2243,8 @@ int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mr // memset(last_dhidden_bias, 0, rbm->nhidden*sizeof(last_dhidden_bias[0])) ; // for (v = 0 ; v < rbm->nvisible ; v++) // memset(last_dw[v], 0, rbm->nhidden*sizeof(last_dw[v][0])) ; - } else + } + else training_rate *= 1.000; if (label_rms < min_label_rms) { @@ -2196,7 +2255,8 @@ int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mr min_rms = rms; nbad = 0; rbm_min = RBMcopy(rbm, rbm_min); - } else if (nbad++ > parms->max_no_progress) { + } + else if (nbad++ > parms->max_no_progress) { printf("stopping learning due to lack of progress\n"); break; } @@ -2231,7 +2291,8 @@ int CDBNtrainFromVoxlistImage(CDBN *cdbn, VOXLIST *vl, RBM_PARMS *parms, MRI *mr } double CDBNvoxlistRMS( - CDBN *cdbn, int layer, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num, double *plabel_rms) { + CDBN *cdbn, int layer, VOXLIST *vl, RBM_PARMS *parms, int *indices, int index, int num, double *plabel_rms) +{ int i, x, y, z, n, ind, h, v, nvox, current_label, l; // int f; double rms, *visible, label_rms; @@ -2275,7 +2336,8 @@ double CDBNvoxlistRMS( else printf("label rms %2.3f\n", label_rms); } - } else { + } + else { for (label_rms = rms = 0.0, nvox = i = 0; i < vl->nvox; i++) { x = vl->xi[i]; y = vl->yi[i]; @@ -2315,7 +2377,8 @@ int CDBNcomputeGradients(CDBN *cdbn, double **dlabel_weights, RBM_PARMS *parms, int *indices, - int index) { + int index) +{ int i, x, y, z, n, v, h, ind, current_label; // int f; double *visible, Q0, Qn, V0, Vn, *hidden0, scale, *db_sparsity, *active; @@ -2491,7 +2554,8 @@ int CDBNcomputeDiscriminativeGradients(CDBN *cdbn, double **dlabel_weights, RBM_PARMS *parms, int *indices, - int index) { + int index) +{ int l, i, x, y, z, n, v, h, ind, current_label; // int f; double *visible, scale, var; @@ -2600,7 +2664,8 @@ int CDBNcomputeLabelGradients(CDBN *cdbn, double **dlabel_weights, RBM_PARMS *parms, int *indices, - int index) { + int index) +{ int l, i, x, y, z, n, v, h, ind, current_label; // int f; double *visible, scale, var, softmax_deriv[MAX_RBM_LABELS]; @@ -2719,7 +2784,8 @@ int CDBNcomputeLabelGradients(CDBN *cdbn, return (NO_ERROR); } #endif -int CDBNactivateForward(CDBN *cdbn, double *visible, int nlayers) { +int CDBNactivateForward(CDBN *cdbn, double *visible, int nlayers) +{ int l; if (nlayers <= 0) nlayers = cdbn->nlayers; @@ -2730,7 +2796,8 @@ int CDBNactivateForward(CDBN *cdbn, double *visible, int nlayers) { return (NO_ERROR); } -int CDBNactivateBackward(CDBN *cdbn, int last_layer, int first_layer) { +int CDBNactivateBackward(CDBN *cdbn, int last_layer, int first_layer) +{ int l; if (last_layer < 0) last_layer = cdbn->nlayers - 1; @@ -2746,7 +2813,8 @@ int CDBNactivateBackward(CDBN *cdbn, int last_layer, int first_layer) { return (NO_ERROR); } -int CDBNfillVisible(CDBN *cdbn, MRI *mri_inputs, double *visible, int x0, int y0, int z0, int ksize) { +int CDBNfillVisible(CDBN *cdbn, MRI *mri_inputs, double *visible, int x0, int y0, int z0, int ksize) +{ int xk, yk, xi, yi, whalf, v, f; float val; @@ -2764,7 +2832,8 @@ int CDBNfillVisible(CDBN *cdbn, MRI *mri_inputs, double *visible, int x0, int y0 return (NO_ERROR); } MRI *CDBNcreateOutputs( - CDBN *cdbn, RBM_PARMS *parms, MRI *mri_inputs, int first_layer, int last_layer, MRI **pmri_labeled) { + CDBN *cdbn, RBM_PARMS *parms, MRI *mri_inputs, int first_layer, int last_layer, MRI **pmri_labeled) +{ int layer, x, y, z, h, *hidden_counts; MRI *mri_layer_inputs, *mri_outputs = NULL, *mri_labeled = NULL; RBM *rbm; @@ -2851,7 +2920,8 @@ MRI *CDBNcreateOutputs( return (mri_outputs); } -MRI *cdbn_layer_weights(CDBN *cdbn, int layer) { +MRI *cdbn_layer_weights(CDBN *cdbn, int layer) +{ MRI *mri = NULL, *mri_prev, *mri_counts; int width, whalf_prev, x, y, xk, yk, v, h, count, xp, yp, hp; RBM *rbm, *rbm_prev; @@ -2913,7 +2983,8 @@ MRI *cdbn_layer_weights(CDBN *cdbn, int layer) { return (mri); } -int CDBNwriteNetwork(CDBN *cdbn, int n, RBM_PARMS *parms, int layer) { +int CDBNwriteNetwork(CDBN *cdbn, int n, RBM_PARMS *parms, int layer) +{ MRI *mri; char fname[STRLEN]; @@ -2928,7 +2999,8 @@ int CDBNwriteNetwork(CDBN *cdbn, int n, RBM_PARMS *parms, int layer) { return (NO_ERROR); } -int dump_visible(RBM *rbm, char *fname) { +int dump_visible(RBM *rbm, char *fname) +{ FILE *fp = fopen(fname, "w"); int v; @@ -2937,7 +3009,8 @@ int dump_visible(RBM *rbm, char *fname) { fclose(fp); return (NO_ERROR); } -int dump_hidden(RBM *rbm, char *fname) { +int dump_hidden(RBM *rbm, char *fname) +{ FILE *fp = fopen(fname, "w"); int v; diff --git a/utils/rec.c b/utils/rec.c index 170284fd947..1e1db4d3695 100644 --- a/utils/rec.c +++ b/utils/rec.c @@ -31,7 +31,8 @@ #include "matrix.h" #include "rec.h" -REC *RecRead(char *fname, int iop_neeg, int iop_nmeg) { +REC *RecRead(char *fname, int iop_neeg, int iop_nmeg) +{ int i, j, tnchan; float f; FILE *fp; @@ -103,7 +104,8 @@ REC *RecRead(char *fname, int iop_neeg, int iop_nmeg) { flag = 2 load only MEG channels flag = 4 don't pad with ramp */ -REC *RecReadPartially(char *fname, int iop_neeg, int iop_nmeg, int flag) { +REC *RecReadPartially(char *fname, int iop_neeg, int iop_nmeg, int flag) +{ int i, j, tnchan; float f; FILE *fp; diff --git a/utils/region.c b/utils/region.c index b829a0c7f52..b8e94882985 100644 --- a/utils/region.c +++ b/utils/region.c @@ -51,7 +51,8 @@ static int regionCornerCoords(MRI_REGION *r, int which_corner, int *px, int *py, /*----------------------------------------------------- GLOBAL FUNCTIONS -------------------------------------------------------*/ -MRI_REGION *REGIONalloc(void) { +MRI_REGION *REGIONalloc(void) +{ MRI_REGION *r; r = (MRI_REGION *)calloc(1, sizeof(MRI_REGION)); @@ -72,7 +73,8 @@ MRI_REGION *REGIONalloc(void) { finding the portion of an advancing window which is new. ------------------------------------------------------*/ -MRI_REGION *REGIONsubtract(MRI_REGION *reg1, MRI_REGION *reg2, MRI_REGION *rdst) { +MRI_REGION *REGIONsubtract(MRI_REGION *reg1, MRI_REGION *reg2, MRI_REGION *rdst) +{ int x1_start, x1_end, x2_end, y1_start, y1_end, y2_end, z1_start, z1_end, z2_end; x1_start = reg1->x; @@ -116,7 +118,8 @@ MRI_REGION *REGIONadd(MRI_REGION *reg1, MRI_REGION *reg2, MRI_REGION *rdst) { re Description ------------------------------------------------------*/ -MRI_REGION *REGIONclear(MRI_REGION *r) { +MRI_REGION *REGIONclear(MRI_REGION *r) +{ memset(r, 0, sizeof(*r)); return (r); } @@ -127,7 +130,8 @@ MRI_REGION *REGIONclear(MRI_REGION *r) { Description ------------------------------------------------------*/ -MRI_REGION *REGIONcopy(MRI_REGION *rsrc, MRI_REGION *rdst) { +MRI_REGION *REGIONcopy(MRI_REGION *rsrc, MRI_REGION *rdst) +{ if (!rdst) rdst = REGIONalloc(); memmove(rdst, rsrc, sizeof(*rsrc)); @@ -140,7 +144,8 @@ MRI_REGION *REGIONcopy(MRI_REGION *rsrc, MRI_REGION *rdst) { Description ------------------------------------------------------*/ -MRI_REGION *REGIONintersect(MRI_REGION *reg1, MRI_REGION *reg2, MRI_REGION *rdst) { +MRI_REGION *REGIONintersect(MRI_REGION *reg1, MRI_REGION *reg2, MRI_REGION *rdst) +{ int x2, y2, z2; rdst->x = MAX(reg1->x, reg2->x); @@ -170,7 +175,8 @@ MRI_REGION *REGIONunion(MRI_REGION *reg1, MRI_REGION *reg2, MRI_REGION *rdst) { Description ------------------------------------------------------*/ -int REGIONinside(MRI_REGION *reg, int x, int y, int z) { +int REGIONinside(MRI_REGION *reg, int x, int y, int z) +{ int x1, y1, z1; x1 = reg->x + reg->dx - 1; @@ -190,7 +196,8 @@ int REGIONinside(MRI_REGION *reg, int x, int y, int z) { Description ------------------------------------------------------*/ -MRI_REGION *REGIONexpand(MRI_REGION *rsrc, MRI_REGION *rdst, int n) { +MRI_REGION *REGIONexpand(MRI_REGION *rsrc, MRI_REGION *rdst, int n) +{ rdst->x = rsrc->x - n; rdst->y = rsrc->y - n; rdst->z = rsrc->z - n; @@ -206,7 +213,8 @@ MRI_REGION *REGIONexpand(MRI_REGION *rsrc, MRI_REGION *rdst, int n) { Description ------------------------------------------------------*/ -float REGIONminCornerDistance(MRI_REGION *r1, MRI_REGION *r2) { +float REGIONminCornerDistance(MRI_REGION *r1, MRI_REGION *r2) +{ float min_dist = 10000.0f, dist, dx, dy, dz; int i, j, x0 = 0, y0 = 0, z0 = 0, x1 = 0, y1 = 0, z1 = 0; MRI_REGION r3; @@ -236,7 +244,8 @@ float REGIONminCornerDistance(MRI_REGION *r1, MRI_REGION *r2) { Description ------------------------------------------------------*/ -static int regionCornerCoords(MRI_REGION *r, int which_corner, int *px, int *py, int *pz) { +static int regionCornerCoords(MRI_REGION *r, int which_corner, int *px, int *py, int *pz) +{ switch (which_corner) { case 0: *px = r->x; @@ -290,7 +299,8 @@ static int regionCornerCoords(MRI_REGION *r, int which_corner, int *px, int *py, region->{dx,dy,dz} is the size of the box such that a loop would run for(c=region->x; c < region->x+region->dx; c++) */ -MRI_REGION *REGIONgetBoundingBox(MRI *mask, int npad) { +MRI_REGION *REGIONgetBoundingBox(MRI *mask, int npad) +{ int c, r, s; int cmin, cmax, rmin, rmax, smin, smax; MRI_REGION *region; @@ -328,7 +338,8 @@ MRI_REGION *REGIONgetBoundingBox(MRI *mask, int npad) { \fn int REGIONprint(FILE *fp, MRI_REGION *r) \brief Prints REGION struct. */ -int REGIONprint(FILE *fp, MRI_REGION *r) { +int REGIONprint(FILE *fp, MRI_REGION *r) +{ fprintf(fp, "%d %d %d %d %d %d\n", r->x, r->y, r->z, r->dx, r->dy, r->dz); return (0); } diff --git a/utils/registerio.c b/utils/registerio.c index 8f9ddfb8e40..b95c82193be 100644 --- a/utils/registerio.c +++ b/utils/registerio.c @@ -56,7 +56,8 @@ int regio_read_register(const char *regfile, float *betplaneres, float *intensity, MATRIX **R, - int *float2int) { + int *float2int) +{ FILE *fp; char tmp[1000]; int r, c, n; @@ -167,13 +168,9 @@ int regio_read_register(const char *regfile, return (0); } /* -------------------------------------------------------------- */ -int regio_print_register(FILE *fp, - const char *subject, - float inplaneres, - float betplaneres, - float intensity, - const MATRIX *R, - int float2int) { +int regio_print_register( + FILE *fp, const char *subject, float inplaneres, float betplaneres, float intensity, const MATRIX *R, int float2int) +{ int r, c; char *f2imethod; @@ -223,7 +220,8 @@ int regio_write_register(const char *regfile, float betplaneres, float intensity, const MATRIX *R, - int float2int) { + int float2int) +{ FILE *fp; fp = fopen(regfile, "w"); @@ -252,7 +250,8 @@ int regio_write_register(const char *regfile, argument. If one is not going to write out the xfm, then simply set fileinfo to NULL. -------------------------------------------------------------- */ -int regio_read_mincxfm(const char *xfmfile, MATRIX **R, char **fileinfo) { +int regio_read_mincxfm(const char *xfmfile, MATRIX **R, char **fileinfo) +{ FILE *fp; char tmpstr[1000]; int r, c, n, nlines; @@ -277,7 +276,8 @@ int regio_read_mincxfm(const char *xfmfile, MATRIX **R, char **fileinfo) { if (fileinfo != NULL) { *fileinfo = strcpyalloc(tmpstr); printf("\n%s\n\n", *fileinfo); - } else + } + else printf("Not reading in xfm fileinfo\n"); // Close it and open it up again to rewind it @@ -329,7 +329,8 @@ int regio_read_mincxfm(const char *xfmfile, MATRIX **R, char **fileinfo) { like a minc xfm file. See regio_read_mincxfm() for docs on fileinfo. -------------------------------------------------------------- */ -int regio_write_mincxfm(const char *xfmfile, const MATRIX *R, const char *fileinfo) { +int regio_write_mincxfm(const char *xfmfile, const MATRIX *R, const char *fileinfo) +{ FILE *fp; int r, c; time_t time_now; @@ -364,7 +365,8 @@ int regio_write_mincxfm(const char *xfmfile, const MATRIX *R, const char *filein regio_read_xfm4() - reads a 4x4 transform as the last four lines of the xfmfile. Blank lines at the end will defeat it. -------------------------------------------------------------- */ -int regio_read_xfm4(const char *xfmfile, MATRIX **R) { +int regio_read_xfm4(const char *xfmfile, MATRIX **R) +{ FILE *fp; char tmpstr[1000]; int r, c, n, nlines; @@ -426,7 +428,8 @@ int regio_read_xfm4(const char *xfmfile, MATRIX **R) { are read. Blank lines at the end will defeat it. This should be able to read tlas properly. -------------------------------------------------------------- */ -int regio_read_xfm(const char *xfmfile, MATRIX **R) { +int regio_read_xfm(const char *xfmfile, MATRIX **R) +{ char *ext, *fileinfo; int err = 0; @@ -435,7 +438,8 @@ int regio_read_xfm(const char *xfmfile, MATRIX **R) { if (strcmp(ext, "xfm") == 0) { err = regio_read_mincxfm(xfmfile, R, &fileinfo); free(fileinfo); - } else + } + else err = regio_read_xfm4(xfmfile, R); free(ext); @@ -450,7 +454,8 @@ int regio_read_xfm(const char *xfmfile, MATRIX **R) { #include "error.h" #include "mri_circulars.h" int regio_write_surfacexform_to_register_dat( - const MATRIX *B, const char *fname, const MRI_SURFACE *mris, const MRI *mri, const char *subject, int float2int) { + const MATRIX *B, const char *fname, const MRI_SURFACE *mris, const MRI *mri, const char *subject, int float2int) +{ MATRIX *Ta, *Sa, *invTa, *A, *R, *S, *invS, *T, *m1, *m2; MRI *mri_surf = MRIallocHeader(mris->vg.width, mris->vg.height, mris->vg.depth, MRI_UCHAR, 1); @@ -485,7 +490,8 @@ int regio_write_surfacexform_to_register_dat( MATRIX *regio_read_surfacexform_from_register_dat(const char *fname, const MRI_SURFACE *mris, const MRI *mri, - char **subject) { + char **subject) +{ MATRIX *Ta, *Sa, *invT, *A, *R, *S, *invSa, *T, *m1, *m2, *B; float pres, bres, intensity; int float2int; @@ -526,7 +532,8 @@ MATRIX *regio_read_surfacexform_from_register_dat(const char *fname, Just reads in the matrix and leaves the rest of the crap in the file. */ -MATRIX *regio_read_registermat(const char *regfile) { +MATRIX *regio_read_registermat(const char *regfile) +{ char *subject; float inplaneres, betplaneres, intensity; int float2int, err; @@ -537,7 +544,8 @@ MATRIX *regio_read_registermat(const char *regfile) { return (R); } -char *regio_read_subject(const char *regfile) { +char *regio_read_subject(const char *regfile) +{ float inplaneres, betplaneres, intensity; int float2int; MATRIX *R; diff --git a/utils/resample.c b/utils/resample.c index c18780a00bf..321d96e6d33 100644 --- a/utils/resample.c +++ b/utils/resample.c @@ -90,7 +90,8 @@ double round(double); // why is this never defined?!? ASEGVOLINDEX - this structure is used with MRIaseg2vol() to help perform the mapping. Mainly used for sorting with qsort. -------------------------------------------------------------------*/ -typedef struct { +typedef struct +{ int asegindex; // index into the seg volume (instead of col,row,slice) int segid; // segmentation code int volindex; // index into the output volume @@ -111,7 +112,8 @@ int interpolation_code(char *interpolation_string) { return (MRIinterpCode(inter point to integer conversion method from a string. Returns -1 if the string is unrecoginzed. ---------------------------------------------------------*/ -int float2int_code(char *float2int_string) { +int float2int_code(char *float2int_string) +{ if (!strcasecmp(float2int_string, "round") || !strcasecmp(float2int_string, "rint")) return (FLT2INT_ROUND); if (!strcasecmp(float2int_string, "floor")) return (FLT2INT_FLOOR); @@ -143,7 +145,8 @@ int XYZAnat2CRSFunc_TkReg(int *col, float xanat, float yanat, float zanat, - MATRIX *Reg) { + MATRIX *Reg) +{ MATRIX *Qf; MATRIX *QfR; MATRIX *xyz, *crs; @@ -180,7 +183,8 @@ int XYZAnat2CRSFunc_TkReg(int *col, tkregsiter can. When volumes are coronally sliced, then col is LR (sagital), row is SI (axial), and slc is AP (cor) ----------------------------------------------------------*/ -int float2int_TkReg(int *col, int *row, int *slc, float fltcol, float fltrow, float fltslc) { +int float2int_TkReg(int *col, int *row, int *slc, float fltcol, float fltrow, float fltslc) +{ *col = (int)(fltcol); *row = (int)(ceil(fltrow)); *slc = (int)(fltslc); @@ -196,7 +200,8 @@ int float2int_TkReg(int *col, int *row, int *slc, float fltcol, float fltrow, fl nslcs = number of slices slcthick = distance between slices (mm) -----------------------------------------------------------*/ -MATRIX *FOVQuantMtx_TkReg(int npixels, float pixsize, int nslcs, float slcthick) { +MATRIX *FOVQuantMtx_TkReg(int npixels, float pixsize, int nslcs, float slcthick) +{ MATRIX *Q; Q = MatrixAlloc(4, 4, MATRIX_REAL); @@ -219,7 +224,8 @@ MATRIX *FOVQuantMtx_TkReg(int npixels, float pixsize, int nslcs, float slcthick) FOVDeQuantMatrix() -- computes the volume dequantization matrix which converts a col,row,slc into an x,y,z: xyz = deQ*crs -----------------------------------------------------------*/ -MATRIX *FOVDeQuantMatrix(int ncols, int nrows, int nslcs, float colres, float rowres, float slcres) { +MATRIX *FOVDeQuantMatrix(int ncols, int nrows, int nslcs, float colres, float rowres, float slcres) +{ MATRIX *deQ; deQ = MatrixAlloc(4, 4, MATRIX_REAL); @@ -242,7 +248,8 @@ MATRIX *FOVDeQuantMatrix(int ncols, int nrows, int nslcs, float colres, float ro FOVQuantMatrix() -- computes the volume quantization matrix which converts a x,y,z into col,row,slc : crs = Q*xyz -----------------------------------------------------------*/ -MATRIX *FOVQuantMatrix(int ncols, int nrows, int nslcs, float colres, float rowres, float slcres) { +MATRIX *FOVQuantMatrix(int ncols, int nrows, int nslcs, float colres, float rowres, float slcres) +{ MATRIX *deQ, *Q; deQ = FOVDeQuantMatrix(ncols, nrows, nslcs, colres, rowres, slcres); @@ -255,7 +262,8 @@ MATRIX *FOVQuantMatrix(int ncols, int nrows, int nslcs, float colres, float rowr ComputeQFWD() - computes the matrix product of Q, F, W, D. If any matrix is NULL, then it is treated as the idenity. ------------------------------------------------------------*/ -MATRIX *ComputeQFWD(MATRIX *Q, MATRIX *F, MATRIX *W, MATRIX *D, MATRIX *QFWD) { +MATRIX *ComputeQFWD(MATRIX *Q, MATRIX *F, MATRIX *W, MATRIX *D, MATRIX *QFWD) +{ MATRIX *QFWDtmp; if (QFWD == NULL) @@ -296,7 +304,8 @@ MRI *vol2vol_linear(MRI *SrcVol, int nslcs_trg, MATRIX *Msrc2trg, int InterpMethod, - int float2int) { + int float2int) +{ MATRIX *QFWDsrc, *QFWDtrg, *invQFWDtrg; MATRIX *Tcrs2Scrs, *invMsrc2trg; MATRIX *Scrs, *Tcrs, *Txyz; @@ -424,7 +433,8 @@ MRI *label2mask_linear(MRI *SrcVol, float rszthresh, int float2int, int *nlabelhits, - int *nfinalhits) { + int *nfinalhits) +{ MATRIX *QFWDsrc; MATRIX *Lxyz2Scrs; MATRIX *Scrs, *Lxyz, *Mlbl2src; @@ -562,7 +572,8 @@ MRI *label2mask_linear(MRI *SrcVol, value is > 0.5. For all such voxels, averages the corresponding values found in SrcVol. Returns an MRI "volume" of dimension 1X1X1Xnframes. -----------------------------------------------------------------------*/ -MRI *vol2maskavg(MRI *SrcVol, MRI *SrcMskVol, int *nhits) { +MRI *vol2maskavg(MRI *SrcVol, MRI *SrcMskVol, int *nhits) +{ int r, c, s, f; MRI *MskAvg; float mskval, val; @@ -606,7 +617,8 @@ MRI *vol2maskavg(MRI *SrcVol, MRI *SrcMskVol, int *nhits) { MRIFseq_vox(MskAvg, 0, 0, 0, f) = val / (*nhits); // printf("%2d %g %g\n",f,val,MRIFseq_vox(MskAvg,0,0,0,f)); } - } else { + } + else { printf("WARNING: there were no voxels in the input mask > 0.5\n"); } @@ -617,7 +629,8 @@ MRI *vol2maskavg(MRI *SrcVol, MRI *SrcMskVol, int *nhits) { ProjNormFracThick() - projects along the surface normal a given fraction of the thickness at that point. ----------------------------------------------------------------*/ -int ProjNormFracThick(float *x, float *y, float *z, const MRI_SURFACE *surf, int vtx, float frac) { +int ProjNormFracThick(float *x, float *y, float *z, const MRI_SURFACE *surf, int vtx, float frac) +{ float r; r = frac * surf->vertices[vtx].curv; *x = surf->vertices[vtx].x + r * surf->vertices[vtx].nx; @@ -630,7 +643,8 @@ int ProjNormFracThick(float *x, float *y, float *z, const MRI_SURFACE *surf, int the surface normals of a vertex and its neighbor. The distance along this direction is a fraction of the thickness at that point. ----------------------------------------------------------------*/ -int ProjNormFracThickNbr(float *x, float *y, float *z, MRI_SURFACE *surf, int vtxno, float frac, int nthNbr) { +int ProjNormFracThickNbr(float *x, float *y, float *z, MRI_SURFACE *surf, int vtxno, float frac, int nthNbr) +{ float r, nx, ny, nz; int nbrvtxno; @@ -648,7 +662,8 @@ int ProjNormFracThickNbr(float *x, float *y, float *z, MRI_SURFACE *surf, int vt ProjNormDist() - projects along the surface normal a given distance. ----------------------------------------------------------------*/ -int ProjNormDist(float *x, float *y, float *z, const MRI_SURFACE *surf, int vtx, float dist) { +int ProjNormDist(float *x, float *y, float *z, const MRI_SURFACE *surf, int vtx, float dist) +{ *x = surf->vertices[vtx].x + dist * surf->vertices[vtx].nx; *y = surf->vertices[vtx].y + dist * surf->vertices[vtx].ny; *z = surf->vertices[vtx].z + dist * surf->vertices[vtx].nz; @@ -659,7 +674,8 @@ int ProjNormDist(float *x, float *y, float *z, const MRI_SURFACE *surf, int vtx, the surface normals of a vertex and its neighbor. The distance along this direction is dist. ----------------------------------------------------------------*/ -int ProjNormDistNbr(float *x, float *y, float *z, MRI_SURFACE *surf, int vtxno, float dist, int nthNbr) { +int ProjNormDistNbr(float *x, float *y, float *z, MRI_SURFACE *surf, int vtxno, float dist, int nthNbr) +{ float nx, ny, nz; int nbrvtxno; @@ -695,7 +711,8 @@ MRI *vol2surf_linear(MRI *SrcVol, int float2int, MRI *SrcHitVol, int ProjDistFlag, - int nskip) { + int nskip) +{ MATRIX *QFWDsrc; MATRIX *Scrs, *Txyz; MRI *TrgVol; @@ -812,7 +829,8 @@ MRI *vol2surf_linear(MRI *SrcVol, MRIsampleSeqVolume(SrcVol, fcol_src, frow_src, fslc_src, valvect, 0, SrcVol->nframes - 1); if (Gdiag_no == vtx) printf("val = %f\n", valvect[0]); for (frm = 0; frm < SrcVol->nframes; frm++) MRIFseq_vox(TrgVol, vtx, 0, 0, frm) = valvect[frm]; - } else { + } + else { for (frm = 0; frm < SrcVol->nframes; frm++) { switch (InterpMethod) { case SAMPLE_NEAREST: @@ -857,7 +875,8 @@ trg1 and src2 are from the same anatomy. \param int DoJac - perform jacobian correction (conserves sum(SrcVals)) \param int UseHash - use hash table (no reason not to, much faster). */ -MRI *MRISapplyReg(MRI *SrcSurfVals, MRI_SURFACE **SurfReg, int nsurfs, int ReverseMapFlag, int DoJac, int UseHash) { +MRI *MRISapplyReg(MRI *SrcSurfVals, MRI_SURFACE **SurfReg, int nsurfs, int ReverseMapFlag, int DoJac, int UseHash) +{ MRI *TrgSurfVals = NULL; MRI_SURFACE *SrcSurfReg, *TrgSurfReg; int svtx = 0, tvtx, tvtxN, svtxN = 0, f, n, nrevhits, nSrcLost; @@ -974,7 +993,8 @@ MRI *MRISapplyReg(MRI *SrcSurfVals, MRI_SURFACE **SurfReg, int nsurfs, int Rever MRIFseq_vox(SrcHits, svtx, 0, 0, 0)++; MRIFseq_vox(TrgHits, tvtx, 0, 0, 0)++; nhits = 1; - } else + } + else nhits = MRIgetVoxVal(SrcHits, svtx, 0, 0, 0); /* accumulate mapped values for each frame */ @@ -1080,7 +1100,8 @@ MRI *surf2surf_nnfr(MRI *SrcSurfVals, MRI **TrgHits, MRI **TrgDist, int ReverseMapFlag, - int UseHash) { + int UseHash) +{ MRI *TrgSurfVals = NULL; int svtx, tvtx, f, n, nrevhits, nSrcLost; VERTEX *v; @@ -1267,7 +1288,8 @@ MRI *surf2surf_nnfr_jac(MRI *SrcSurfVals, MRI **TrgHits, MRI **TrgDist, int ReverseMapFlag, - int UseHash) { + int UseHash) +{ MRI *TrgSurfVals = NULL; int svtx, tvtx, f, n, nrevhits, nSrcLost, nhits; // int nunmapped; @@ -1412,7 +1434,8 @@ MRI *surf2surf_nnfr_jac(MRI *SrcSurfVals, crs2ind() -- returns linear index into a volume stored by column, row, slice. --------------------------------------------------------------------*/ -int crs2ind(int *ind, int c, int r, int s, int ncols, int nrows, int nslcs) { +int crs2ind(int *ind, int c, int r, int s, int ncols, int nrows, int nslcs) +{ if (c < 0 || c >= ncols) { fprintf(stderr, "crs2ind: col %d out of bounds (0,%d)\n", c, ncols - 1); return (1); @@ -1435,7 +1458,8 @@ int crs2ind(int *ind, int c, int r, int s, int ncols, int nrows, int nslcs) { volume given the index of the element in the volume assuming that the elements are stored by column, row, then slice. --------------------------------------------------------------------*/ -int ind2crs(int *c, int *r, int *s, int ind, int ncols, int nrows, int nslcs) { +int ind2crs(int *c, int *r, int *s, int ind, int ncols, int nrows, int nslcs) +{ int i = ind, ntot, nrowcols; nrowcols = nrows * ncols; @@ -1482,7 +1506,8 @@ int ind2crs(int *c, int *r, int *s, int ind, int ncols, int nrows, int nslcs) { overlays[1] = lh.pial.overlay. */ -MRI *MRIsurf2VolOpt(MRI *ribbon, MRIS **surfs, MRI **overlays, int nsurfs, LTA *Q, MRI *volsurf) { +MRI *MRIsurf2VolOpt(MRI *ribbon, MRIS **surfs, MRI **overlays, int nsurfs, LTA *Q, MRI *volsurf) +{ int n, c, r, s, f, nmin, vtxno, vtxnomin = 0, nframes, ribval, cR, rR, sR; MHT **hash = NULL; int UseHash = 1; @@ -1510,7 +1535,8 @@ MRI *MRIsurf2VolOpt(MRI *ribbon, MRIS **surfs, MRI **overlays, int nsurfs, LTA * if (LTAmriIsSource(Q, ribbon)) { printf("MRIsurf2VolOpt(): ribbon is source\n"); Q2 = LTAcopy(Q, NULL); - } else { + } + else { printf("MRIsurf2VolOpt(): inverting LTA\n"); Q2 = LTAinvert(Q, NULL); } @@ -1649,7 +1675,8 @@ MRI *MRIsurf2VolOpt(MRI *ribbon, MRIS **surfs, MRI **overlays, int nsurfs, LTA * MRIsurf2VolOpt() in that Opt will always fill the ribbon (by construction). Filling by projection can leave holes. ----------------------------------------------------------------*/ -int MRIsurf2Vol(MRI *surfvals, MRI *vol, MRI *map) { +int MRIsurf2Vol(MRI *surfvals, MRI *vol, MRI *map) +{ int vtx, c, r, s, f, nhits; float val; @@ -1718,7 +1745,8 @@ int MRIsurf2Vol(MRI *surfvals, MRI *vol, MRI *map) { projfrac fraction of the thickness at that point. Obviously, the thickness must have been loaded into the surface at this point. ------------------------------------------------------------------*/ -MRI *MRImapSurf2VolClosest(MRIS *surf, MRI *vol, MATRIX *Qa2v, float projfrac) { +MRI *MRImapSurf2VolClosest(MRIS *surf, MRI *vol, MATRIX *Qa2v, float projfrac) +{ MRI *map, *dist2; int vtx, vtxmin, c, r, s; float xvtx, yvtx, zvtx; @@ -1764,7 +1792,8 @@ MRI *MRImapSurf2VolClosest(MRIS *surf, MRI *vol, MATRIX *Qa2v, float projfrac) { xvtx = surf->vertices[vtx].x; yvtx = surf->vertices[vtx].y; zvtx = surf->vertices[vtx].z; - } else { + } + else { /* Get the xyz of the vertex as projected along the normal a distance equal to a fraction of the cortical thickness at that point. */ @@ -1875,7 +1904,8 @@ MRI *MRImapSurf2VolClosest(MRIS *surf, MRI *vol, MATRIX *Qa2v, float projfrac) { of the mask is set to 0. */ MRI *MRIseg2SegPVF( - MRI *seg, LTA *seg2vol, double resmm, int *segidlist, int nsegs, MRI *mask, int ReInit, COLOR_TABLE *ct, MRI *out) { + MRI *seg, LTA *seg2vol, double resmm, int *segidlist, int nsegs, MRI *mask, int ReInit, COLOR_TABLE *ct, MRI *out) +{ LTA *lta; VOL_GEOM *vg; double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34; @@ -2015,7 +2045,8 @@ MRI *MRIseg2SegPVF( if (DoSeg) { nframesout = 1; outtype = MRI_INT; - } else { + } + else { nframesout = nsegs; outtype = MRI_FLOAT; } @@ -2141,7 +2172,8 @@ MRI *MRIseg2SegPVF( if (DoSeg == 0) { for (f = 0; f < nsegs; f++) // dont compute pvf outside, becomes very slow if (nperf[f] > 0) MRIsetVoxVal(out, c, r, s, f, (float)nperf[f] / npervox); - } else { + } + else { // Get seg with highest PVF for (f = 0; f < nsegs; f++) nperf[f] = (float)nperf[f] / npervox; segid = VOXsegPVF2Seg(nperf, segidlist, nsegs, ct); @@ -2169,7 +2201,8 @@ MRI *MRIseg2SegPVF( max PVF within the tissue type with the max PVF is selected. See also VoxsegPVF2Seg(). */ -MRI *MRIsegPVF2Seg(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE *ct, MRI *mask, MRI *seg) { +MRI *MRIsegPVF2Seg(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE *ct, MRI *mask, MRI *seg) +{ int c, r, s, f, segid; float *vlist; @@ -2177,7 +2210,8 @@ MRI *MRIsegPVF2Seg(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE *ct, MRI seg = MRIallocSequence(segpvf->width, segpvf->height, segpvf->depth, MRI_INT, 1); MRIcopyHeader(segpvf, seg); MRIcopyPulseParameters(segpvf, seg); - } else + } + else MRIclear(seg); vlist = (float *)calloc(sizeof(float), nsegs); @@ -2208,7 +2242,8 @@ MRI *MRIsegPVF2Seg(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE *ct, MRI the PVF for each of the segs. segidlist is the list of segmentation ids (also length nsegs). See also MRIsegPVF2Seg(). */ -int VOXsegPVF2Seg(float *segpvfvox, int *segidlist, int nsegs, COLOR_TABLE *ct) { +int VOXsegPVF2Seg(float *segpvfvox, int *segidlist, int nsegs, COLOR_TABLE *ct) +{ int segid, f, fmax, tt, ttmax, nTT; float v, vsum, vmax, vtt[100], vttmax; @@ -2271,7 +2306,8 @@ int VOXsegPVF2Seg(float *segpvfvox, int *segidlist, int nsegs, COLOR_TABLE *ct) may be more efficient to convert a highres seg to a tissue type seg using MRIseg2TissueType(), then run MRIseg2SegPVF() to generate the TT PVF directly. */ -MRI *MRIsegPVF2TissueTypePVF(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE *ct, MRI *mask, MRI *pvf) { +MRI *MRIsegPVF2TissueTypePVF(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE *ct, MRI *mask, MRI *pvf) +{ int nTT, c, r, s, f, tt, segid; double vtt[100]; nTT = ct->ctabTissueType->nentries - 1; @@ -2284,7 +2320,8 @@ MRI *MRIsegPVF2TissueTypePVF(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE } MRIcopyHeader(segpvf, pvf); MRIcopyPulseParameters(segpvf, pvf); - } else + } + else MRIclear(pvf); for (c = 0; c < segpvf->width; c++) { @@ -2329,7 +2366,8 @@ MRI *MRIsegPVF2TissueTypePVF(MRI *segpvf, int *segidlist, int nsegs, COLOR_TABLE tkregister2 --targ aseg --mov voltemp --reg tkR -------------------------------------------------------------*/ -MRI *MRIaseg2vol(MRI *aseg, MATRIX *tkR, MRI *voltemp, double fthresh, MRI **pvolhit, COLOR_TABLE *ct) { +MRI *MRIaseg2vol(MRI *aseg, MATRIX *tkR, MRI *voltemp, double fthresh, MRI **pvolhit, COLOR_TABLE *ct) +{ int Na, inda, sa, ra, ca, cv, rv, sv, indv, n, segid, nhits, nhitsmost; int nmisses, nfilled; MATRIX *Va2v, *Ka, *Kv, *invKv, *Vv2a, *Pa, *Pv; @@ -2387,7 +2425,8 @@ MRI *MRIaseg2vol(MRI *aseg, MATRIX *tkR, MRI *voltemp, double fthresh, MRI **pvo avind[inda].cv = -1; avind[inda].rv = -1; avind[inda].sv = -1; - } else { + } + else { // save the volume crs and index indv = cv + (rv * voltemp->width) + (sv * voltemp->width * voltemp->height); avind[inda].cv = cv; @@ -2487,7 +2526,8 @@ MRI *MRIaseg2vol(MRI *aseg, MATRIX *tkR, MRI *voltemp, double fthresh, MRI **pvo if (ca < 0 || ca >= aseg->width || ra < 0 || ra >= aseg->height || sa < 0 || sa >= aseg->depth) { // out-of-bounds MRIsetVoxVal(volaseg, cv, rv, sv, 0, 0); - } else { + } + else { // in-of-bounds segid = MRIgetVoxVal(aseg, ca, ra, sa, 0); MRIsetVoxVal(volaseg, cv, rv, sv, 0, segid); @@ -2516,7 +2556,8 @@ MRI *MRIaseg2vol(MRI *aseg, MATRIX *tkR, MRI *voltemp, double fthresh, MRI **pvo matrix) is handed off to MRIaseg2vol(). The aseg2vol LTA can point in either direction. */ -MRI *MRIaseg2volMU(MRI *aseg, LTA *aseg2vol, double fthresh, MRI **pvolhit, int USF, COLOR_TABLE *ct) { +MRI *MRIaseg2volMU(MRI *aseg, LTA *aseg2vol, double fthresh, MRI **pvolhit, int USF, COLOR_TABLE *ct) +{ MRI *asegmu, *OutVol, *TempVol; LTA *aseg2asegmu, *asegmu2aseg, *asegmu2vol, *ltaArray[2]; int nPad = 2; @@ -2529,7 +2570,8 @@ MRI *MRIaseg2volMU(MRI *aseg, LTA *aseg2vol, double fthresh, MRI **pvolhit, int ltaArray[1] = aseg2vol; asegmu2vol = LTAconcat(ltaArray, 2, 1); // figures out inversions LTAfree(&aseg2asegmu); - } else { + } + else { asegmu = aseg; if (LTAmriIsSource(aseg2vol, aseg)) asegmu2vol = LTAcopy(aseg2vol, NULL); @@ -2570,7 +2612,8 @@ MRI *MRIaseg2volMU(MRI *aseg, LTA *aseg2vol, double fthresh, MRI **pvolhit, int MRIaseg2volMU() or MRIaseg2vol(). This uses MRIseg2SegPVF() and MRIaseg2vol() uses a voting scheme. I would guess that they are close. */ -MRI *MRIchangeSegRes(MRI *seg, double xsize, double ysize, double zsize, COLOR_TABLE *ct, LTA **seg2new) { +MRI *MRIchangeSegRes(MRI *seg, double xsize, double ysize, double zsize, COLOR_TABLE *ct, LTA **seg2new) +{ int *segidlist, nsegs, ReGridFactor = -2, ReInitCache = 1; MRI *newseg, *mritmp; @@ -2591,7 +2634,8 @@ MRI *MRIchangeSegRes(MRI *seg, double xsize, double ysize, double zsize, COLOR_T given volume voxel. In this case, avindsorted points to the first entry of the given voxel, and there are N entries for that voxel. -----------------------------------------------------------------------*/ -static int MostHitsInVolVox(ASEGVOLINDEX *avindsorted, int N, int *segidmost, COLOR_TABLE *ct) { +static int MostHitsInVolVox(ASEGVOLINDEX *avindsorted, int N, int *segidmost, COLOR_TABLE *ct) +{ int n, nhits = 0, nmost = 0, segid, nsegs; static int segidlist[1000], ttypelist[1000], nhitslist[1000]; static int nPerTType[100], nPerTTypeMax, TTypeMax; @@ -2658,7 +2702,8 @@ static int MostHitsInVolVox(ASEGVOLINDEX *avindsorted, int N, int *segidmost, CO will be contiguous. For a set of entries with the same volume index, all entries with the same seg id will be contiguous. -----------------------------------------------------------------------*/ -static int CompareAVIndices(const void *i1, const void *i2) { +static int CompareAVIndices(const void *i1, const void *i2) +{ ASEGVOLINDEX *avind1 = NULL, *avind2 = NULL; avind1 = (ASEGVOLINDEX *)i1; diff --git a/utils/rescale.c b/utils/rescale.c index a934eb6a176..7628af2649c 100644 --- a/utils/rescale.c +++ b/utils/rescale.c @@ -51,7 +51,8 @@ #include "rescale.h" /* y = Offset + Slope * x, y=New, x=Old ***/ -static int h_GetScaleParams(float OldMin, float OldMax, float NewMin, float NewMax, float *Offset, float *Slope) { +static int h_GetScaleParams(float OldMin, float OldMax, float NewMin, float NewMax, float *Offset, float *Slope) +{ float Del; int Warning = 1; @@ -60,7 +61,8 @@ static int h_GetScaleParams(float OldMin, float OldMax, float NewMin, float NewM *Offset = 0.0F; *Slope = 1.0F; Warning = 1; - } else { + } + else { *Slope = (NewMax - NewMin) / Del; *Offset = (NewMin - *Slope * OldMin); Warning = 0; @@ -70,7 +72,8 @@ static int h_GetScaleParams(float OldMin, float OldMax, float NewMin, float NewM } /*************************************************************/ int h_rescale( - struct header *phdSrc, float NewMin, float NewMax, int MinPoint[2], int MaxPoint[2], struct header *phdDst) { + struct header *phdSrc, float NewMin, float NewMax, int MinPoint[2], int MaxPoint[2], struct header *phdDst) +{ Pixelval Min, Max; float Offset, Slope; int err; @@ -106,7 +109,8 @@ int h_rescale( } /********************************************************/ -int h_rescale_fb(struct header *phdSrc, float Slope, float Offset, struct header *phdDst) { +int h_rescale_fb(struct header *phdSrc, float Slope, float Offset, struct header *phdDst) +{ register INT32B n; register float *pSrc; register byte *pDst; @@ -120,7 +124,8 @@ int h_rescale_fb(struct header *phdSrc, float Slope, float Offset, struct header } /********************************************************/ -int h_rescale_ff(struct header *phdSrc, float Slope, float Offset, struct header *phdDst) { +int h_rescale_ff(struct header *phdSrc, float Slope, float Offset, struct header *phdDst) +{ register INT32B n; register float *pSrc; register float *pDst; diff --git a/utils/retinotopy.c b/utils/retinotopy.c index e054e74e777..db81b81af92 100644 --- a/utils/retinotopy.c +++ b/utils/retinotopy.c @@ -46,7 +46,8 @@ double round(double x); valbak = angle for polar (-pi to +pi) val2bak = log10(p) for polar ------------------------------------------------------------*/ -void RETcompute_angles(MRIS *mris, double EccenRotAngleRad, double PolarRotAngleRad) { +void RETcompute_angles(MRIS *mris, double EccenRotAngleRad, double PolarRotAngleRad) +{ int k; float val, valbak, val2, val2bak; @@ -61,7 +62,8 @@ void RETcompute_angles(MRIS *mris, double EccenRotAngleRad, double PolarRotAngle valbak = atan2(mris->vertices[k].val2bak, mris->vertices[k].valbak); valbak += PolarRotAngleRad; val2bak = sqrt(SQR(mris->vertices[k].val2bak) + SQR(mris->vertices[k].valbak)); - } else { + } + else { val = 0.0; val2 = 0.0; valbak = 0.0; @@ -74,7 +76,8 @@ void RETcompute_angles(MRIS *mris, double EccenRotAngleRad, double PolarRotAngle } } /*------------------------------------------------------------*/ -float RETcircsubtract(float a, float b) { +float RETcircsubtract(float a, float b) +{ float h = a - b; if (h < -M_PI) h = h + 2 * M_PI; @@ -83,7 +86,8 @@ float RETcircsubtract(float a, float b) { return h; } /*------------------------------------------------------------*/ -void RETcompute_fieldsign(MRIS *mris) { +void RETcompute_fieldsign(MRIS *mris) +{ int k, m, n; VERTEX *v; float dv1, dv2, dx, dy, dv1dx, dv1dy, dv2dx, dv2dy; @@ -135,7 +139,8 @@ void RETcompute_fieldsign(MRIS *mris) { } /*--------------------------------------------------------------------------*/ -int RETlogMap(MRIS *surf, double k, double a, double xc0, double yc0) { +int RETlogMap(MRIS *surf, double k, double a, double xc0, double yc0) +{ double n, r, theta, xw, yw, r2, theta2, xc2, yc2, xc, yc; float dmin; int vno; @@ -183,7 +188,8 @@ int RETlogMap(MRIS *surf, double k, double a, double xc0, double yc0) { } /*--------------------------------------------------------------------------*/ -int RETinvLogMapFunc(double xc, double yc, double xc0, double yc0, double a, double k, double *r, double *theta) { +int RETinvLogMapFunc(double xc, double yc, double xc0, double yc0, double a, double k, double *r, double *theta) +{ double r2, theta2, xw, yw; r2 = exp((xc - xc0) / k); theta2 = (yc - yc0) / k; @@ -194,7 +200,8 @@ int RETinvLogMapFunc(double xc, double yc, double xc0, double yc0, double a, dou return (0); } /*--------------------------------------------------------------------------*/ -int RETreverseSign(MRI *mri) { +int RETreverseSign(MRI *mri) +{ int c, r, s; double v; diff --git a/utils/rfa.c b/utils/rfa.c index b141e99402d..78a8d64895f 100644 --- a/utils/rfa.c +++ b/utils/rfa.c @@ -40,7 +40,8 @@ #define MAX_LABELS_PER_NODE 10 -RFA *RFAalloc(RFA_PARMS *parms, int alloc_trees) { +RFA *RFAalloc(RFA_PARMS *parms, int alloc_trees) +{ int x, y, z; RF_NODE *node; RFA *rfa; @@ -92,12 +93,14 @@ RFA *RFAalloc(RFA_PARMS *parms, int alloc_trees) { int RFAtrain(RFA *rfa, MRI *mri_inputs, MRI *mri_labels, TRANSFORM *transform) { return (NO_ERROR); } -int RFAcompleteTraining(RFA *rfa, RFA_PARMS *parms) { +int RFAcompleteTraining(RFA *rfa, RFA_PARMS *parms) +{ RFAupdateTraining(rfa, parms); return (NO_ERROR); } -int RFAaddInput(RFA *rfa, MRI *mri_seg, MRI *mri_inputs, TRANSFORM *transform, RFA_PARMS *parms) { +int RFAaddInput(RFA *rfa, MRI *mri_seg, MRI *mri_inputs, TRANSFORM *transform, RFA_PARMS *parms) +{ int index; index = (parms->training_index % parms->training_size); @@ -121,14 +124,16 @@ int RFAaddInput(RFA *rfa, MRI *mri_seg, MRI *mri_inputs, TRANSFORM *transform, R return (NO_ERROR); } -int RFAvoxelToNode(const RFA *rfa, double xt, double yt, double zt, double *px, double *py, double *pz) { +int RFAvoxelToNode(const RFA *rfa, double xt, double yt, double zt, double *px, double *py, double *pz) +{ *px = xt / rfa->spacing; *py = yt / rfa->spacing; *pz = zt / rfa->spacing; return (NO_ERROR); } -int RFAnodeToVoxel(const RFA *rfa, double xt, double yt, double zt, double *px, double *py, double *pz) { +int RFAnodeToVoxel(const RFA *rfa, double xt, double yt, double zt, double *px, double *py, double *pz) +{ *px = xt * rfa->spacing; *py = yt * rfa->spacing; *pz = zt * rfa->spacing; @@ -136,7 +141,8 @@ int RFAnodeToVoxel(const RFA *rfa, double xt, double yt, double zt, double *px, } int RFAsourceVoxelToNode( - const RFA *rfa, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, int *px, int *py, int *pz) { + const RFA *rfa, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, int *px, int *py, int *pz) +{ float xt, yt, zt; double xrt, yrt, zrt, xd, yd, zd; // int retval; @@ -151,9 +157,11 @@ int RFAsourceVoxelToNode( yt = yrt; zt = zrt; // TransformSample(transform, xv, yv, zv, &xt, &yt, &zt) ; - } else + } + else ErrorExit(ERROR_BADPARM, "RFAsourceVoxelToNode: needs vox-to-vox transform"); - } else // morph 3d type can go directly from source to template + } + else // morph 3d type can go directly from source to template { TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); } @@ -173,7 +181,8 @@ int RFAsourceVoxelToNode( return (NO_ERROR); } int RFAsourceVoxelToAtlas( - const RFA *rfa, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, double *px, double *py, double *pz) { + const RFA *rfa, MRI *mri, TRANSFORM *transform, int xv, int yv, int zv, double *px, double *py, double *pz) +{ float xt, yt, zt; LTA *lta; @@ -183,9 +192,11 @@ int RFAsourceVoxelToAtlas( // transform point to talairach volume point TransformWithMatrix(lta->xforms[0].m_L, xv, yv, zv, px, py, pz); // TransformSample(transform, xv, yv, zv, &xt, &yt, &zt) ; - } else + } + else ErrorExit(ERROR_BADPARM, "RFAsourceVoxelToNode: needs vox-to-vox transform"); - } else // morph 3d type can go directly from source to template + } + else // morph 3d type can go directly from source to template { TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); *px = (double)xt; @@ -214,7 +225,8 @@ int RFAsourceVoxelToAtlas( return (NO_ERROR); } int RFAnodeToSourceVoxel( - RFA *rfa, MRI *mri, TRANSFORM *transform, int xn, int yn, int zn, double *pxv, double *pyv, double *pzv) { + RFA *rfa, MRI *mri, TRANSFORM *transform, int xn, int yn, int zn, double *pxv, double *pyv, double *pzv) +{ int width, height, depth; double xt, yt, zt; double xv, yv, zv; @@ -248,7 +260,8 @@ int RFAnodeToSourceVoxel( xv = xc; yv = yc; zv = zc; - } else // template to source + } + else // template to source { TransformSampleInverse(transform, xt, yt, zt, &xf, &yf, &zf); xv = (double)xf; @@ -261,7 +274,8 @@ int RFAnodeToSourceVoxel( return errCode; } -int RFAupdateTraining(RFA *rfa, RFA_PARMS *parms) { +int RFAupdateTraining(RFA *rfa, RFA_PARMS *parms) +{ int ntraining_sets, ntraining, start, x, y, z, xn, yn, zn, i, *training_classes, *wmsa_permutation; int xk, yk, zk, xi, yi, zi, tno, label, index, total_correct, total_training, n, nwmsa, max_count, wmsa_count, wmsa_label = WM_hypointensities; @@ -286,7 +300,8 @@ int RFAupdateTraining(RFA *rfa, RFA_PARMS *parms) { if (parms->transforms[0]->type == MORPH_3D_TYPE) { GCA_MORPH *gcam = (GCA_MORPH *)(parms->transforms[0]->xform); rfa->vg = *(&gcam->atlas); - } else { + } + else { LTA *lta = (LTA *)(parms->transforms[0]->xform); rfa->vg = *(<a->xforms[0].dst); } @@ -456,7 +471,8 @@ int RFAupdateTraining(RFA *rfa, RFA_PARMS *parms) { free(wmsa_data); return (NO_ERROR); } -int RFAwrite(RFA *rfa, char *fname) { +int RFAwrite(RFA *rfa, char *fname) +{ FILE *fp; int xn, yn, zn, n; RF_NODE *node; @@ -490,7 +506,8 @@ int RFAwrite(RFA *rfa, char *fname) { fclose(fp); return (NO_ERROR); } -RFA *RFAread(char *fname) { +RFA *RFAread(char *fname) +{ RFA *rfa; FILE *fp; int xn, yn, zn, n, nfeatures, total_training, first = 1; @@ -573,7 +590,8 @@ RFA *RFAread(char *fname) { } #define MAX_FEATURE_LEN 10000 -MRI *RFAlabel(MRI *mri_in, RFA *rfa, MRI *mri_labeled, TRANSFORM *transform) { +MRI *RFAlabel(MRI *mri_in, RFA *rfa, MRI *mri_labeled, TRANSFORM *transform) +{ int x, y, z, xn, yn, zn; int label; RF_NODE *node; @@ -619,7 +637,8 @@ MRI *RFAlabel(MRI *mri_in, RFA *rfa, MRI *mri_labeled, TRANSFORM *transform) { return (mri_labeled); } -int extract_feature(MRI *mri_in, int wsize, int x, int y, int z, double *feature, int xatlas, int yatlas, int zatlas) { +int extract_feature(MRI *mri_in, int wsize, int x, int y, int z, double *feature, int xatlas, int yatlas, int zatlas) +{ int xi, yi, zi, xk, yk, zk, whalf, n, f; whalf = (wsize - 1) / 2; @@ -640,7 +659,8 @@ int extract_feature(MRI *mri_in, int wsize, int x, int y, int z, double *feature } int extract_long_features( - MRI *mri_in, MRI *mri_seg, TRANSFORM *transform, GCA *gca, int wsize, int x, int y, int z, double *feature) { + MRI *mri_in, MRI *mri_seg, TRANSFORM *transform, GCA *gca, int wsize, int x, int y, int z, double *feature) +{ int xi, yi, zi, xk, yk, zk, whalf, n, f; whalf = (wsize - 1) / 2; @@ -672,7 +692,8 @@ static int csf_labels[] = {CSF, Fourth_Ventricle}; #define NCSF_LABELS (sizeof(csf_labels) / sizeof(csf_labels[0])) -int MRIcountCSFInNbhd(MRI *mri_seg, int wsize, int x, int y, int z) { +int MRIcountCSFInNbhd(MRI *mri_seg, int wsize, int x, int y, int z) +{ int total, n; for (n = total = 0; n < NCSF_LABELS; n++) total += MRIcountValInNbhd(mri_seg, wsize, x, y, z, csf_labels[n]); diff --git a/utils/rforest.c b/utils/rforest.c index 33a7185a1ea..62279151449 100644 --- a/utils/rforest.c +++ b/utils/rforest.c @@ -41,7 +41,8 @@ static double entropy(int *class_counts, int nclasses, int *Nc); static double rfFeatureInfoGain( RANDOM_FOREST *rf, TREE *tree, NODE *parent, NODE *left, NODE *right, int fno, int *ptotal_count); -RANDOM_FOREST *RFalloc(int ntrees, int nfeatures, int nclasses, int max_depth, char **class_names, int nsteps) { +RANDOM_FOREST *RFalloc(int ntrees, int nfeatures, int nclasses, int max_depth, char **class_names, int nsteps) +{ RANDOM_FOREST *rf; TREE *tree; int n, c = 0; @@ -113,7 +114,8 @@ RANDOM_FOREST *RFalloc(int ntrees, int nfeatures, int nclasses, int max_depth, c } static double compute_info_gain( - RF *rf, TREE *tree, NODE *parent, NODE *left, NODE *right, double **training_data, int fno, double thresh) { + RF *rf, TREE *tree, NODE *parent, NODE *left, NODE *right, double **training_data, int fno, double thresh) +{ double entropy_before, entropy_after, wl, wr; int i, tno, c; NODE *node; @@ -146,7 +148,8 @@ static double compute_info_gain( return (entropy_before - entropy_after); } static int adjust_optimal_threshold( - RF *rf, TREE *tree, NODE *parent, NODE *left, NODE *right, double **training_data, int fno, double *pbest_thresh) { + RF *rf, TREE *tree, NODE *parent, NODE *left, NODE *right, double **training_data, int fno, double *pbest_thresh) +{ double previous_thresh, next_thresh, info_gain, best_info_gain, step, thresh, best_thresh; best_thresh = *pbest_thresh; @@ -199,7 +202,8 @@ static double find_optimal_threshold(RF *rf, double *pinfo_gain, int nsteps, double fmin, - double fmax) { + double fmax) +{ double step, thresh, best_thresh, info_gain, best_info_gain; step = (fmax - fmin) / (nsteps - 1); @@ -226,7 +230,8 @@ static int find_optimal_feature_and_threshold(RANDOM_FOREST *rf, NODE *right, int *training_classes, double **training_data, - int ntraining) { + int ntraining) +{ double info_gain, best_info_gain, thresh, best_thresh, fmin, fmax, tdata; int f, best_f, fno, nsteps, i, tno; @@ -267,7 +272,8 @@ static int find_optimal_feature_and_threshold(RANDOM_FOREST *rf, return (1); } -static NODE *rfAllocateNode(int ntraining, int depth, int nclasses) { +static NODE *rfAllocateNode(int ntraining, int depth, int nclasses) +{ NODE *node; node = (NODE *)calloc(1, sizeof(NODE)); if (node == NULL) ErrorExit(ERROR_NOMEMORY, "rfAllocateNode: could not allocate node"); @@ -279,7 +285,8 @@ static NODE *rfAllocateNode(int ntraining, int depth, int nclasses) { return (node); } -static int rfFreeNode(NODE **pnode) { +static int rfFreeNode(NODE **pnode) +{ NODE *node; node = *pnode; @@ -291,7 +298,8 @@ static int rfFreeNode(NODE **pnode) { } static int rfTrainNode( - RANDOM_FOREST *rf, TREE *tree, NODE *node, int *training_classes, double **training_data, int ntraining) { + RANDOM_FOREST *rf, TREE *tree, NODE *node, int *training_classes, double **training_data, int ntraining) +{ if (node->left == NULL) // not trained yet { node->left = rfAllocateNode(node->total_counts, node->depth + 1, rf->nclasses); @@ -314,21 +322,24 @@ static int rfTrainNode( return (1); } -static int rfFindNodeLeaves(TREE *tree, NODE *node) { +static int rfFindNodeLeaves(TREE *tree, NODE *node) +{ if (node->left == NULL) { if (tree->leaves) { if (tree->nleaves >= tree->max_leaves && tree->max_leaves > 0) DiagBreak(); tree->leaves[tree->nleaves] = node; } tree->nleaves++; - } else { + } + else { rfFindNodeLeaves(tree, node->left); rfFindNodeLeaves(tree, node->right); } return (NO_ERROR); } -static int rfFindLeaves(TREE *tree) { +static int rfFindLeaves(TREE *tree) +{ if (tree->leaves) { free(tree->leaves); tree->leaves = NULL; @@ -343,7 +354,8 @@ static int rfFindLeaves(TREE *tree) { return (NO_ERROR); } -static int rfTrainTree(RANDOM_FOREST *rf, TREE *tree, int *training_classes, double **training_data, int ntraining) { +static int rfTrainTree(RANDOM_FOREST *rf, TREE *tree, int *training_classes, double **training_data, int ntraining) +{ int done = 0, n, iter, tno, fno, f, i; double total_entropy, last_f; @@ -386,7 +398,8 @@ int RFtrain(RANDOM_FOREST *rf, double training_fraction, int *training_classes, double **training_data, - int ntraining) { + int ntraining) +{ int n, ii, nfeatures_per_tree = 0, *feature_permutation, *training_permutation, f, index, start_no, end_no, ntraining_per_tree = 0, total_to_remove = 0; TREE *tree = NULL; @@ -559,7 +572,8 @@ int RFtrain(RANDOM_FOREST *rf, free(training_permutation); return (NO_ERROR); } -int RFtrainTree(RANDOM_FOREST *rf, int tno, int *training_classes, double **training_data, int ntraining) { +int RFtrainTree(RANDOM_FOREST *rf, int tno, int *training_classes, double **training_data, int ntraining) +{ int i, f; TREE *tree; @@ -603,7 +617,8 @@ int RFtrainTree(RANDOM_FOREST *rf, int tno, int *training_classes, double **trai return (NO_ERROR); } -static double entropy(int *class_counts, int nclasses, int *Nc) { +static double entropy(int *class_counts, int nclasses, int *Nc) +{ int c; double ent, p, total; @@ -615,7 +630,8 @@ static double entropy(int *class_counts, int nclasses, int *Nc) { if (Nc[c] > 0) { norm_class_counts[c] = (double)class_counts[c] / (double)Nc[c]; total += norm_class_counts[c]; - } else // then class_counts[c] has to be 0 also + } + else // then class_counts[c] has to be 0 also norm_class_counts[c] = 0.0; } if (FZERO(total)) // shouldn't ever happen @@ -636,7 +652,8 @@ static double entropy(int *class_counts, int nclasses, int *Nc) { return (ent); } -static int rfWriteNode(RANDOM_FOREST *rf, NODE *node, FILE *fp) { +static int rfWriteNode(RANDOM_FOREST *rf, NODE *node, FILE *fp) +{ int c; fprintf(fp, "NODE %d %d %d %lf\n", node->left == NULL, node->depth, node->feature, node->thresh); @@ -653,7 +670,8 @@ static int rfWriteNode(RANDOM_FOREST *rf, NODE *node, FILE *fp) { } return (NO_ERROR); } -static int rfWriteTree(RANDOM_FOREST *rf, TREE *tree, FILE *fp) { +static int rfWriteTree(RANDOM_FOREST *rf, TREE *tree, FILE *fp) +{ int f; fprintf(fp, "TREE %d %d %d\n", tree->depth, tree->nleaves, tree->nfeatures); @@ -662,7 +680,8 @@ static int rfWriteTree(RANDOM_FOREST *rf, TREE *tree, FILE *fp) { fprintf(fp, "TREE: END\n"); return (NO_ERROR); } -static int rfReadNode(RANDOM_FOREST *rf, NODE *node, FILE *fp) { +static int rfReadNode(RANDOM_FOREST *rf, NODE *node, FILE *fp) +{ int c, leaf; char line[MAX_LINE_LEN], *cp; @@ -699,7 +718,8 @@ static int rfReadNode(RANDOM_FOREST *rf, NODE *node, FILE *fp) { } return (NO_ERROR); } -static int rfReadTree(RANDOM_FOREST *rf, TREE *tree, FILE *fp) { +static int rfReadTree(RANDOM_FOREST *rf, TREE *tree, FILE *fp) +{ int f; char line[MAX_LINE_LEN], *cp; @@ -718,7 +738,8 @@ static int rfReadTree(RANDOM_FOREST *rf, TREE *tree, FILE *fp) { rfFindLeaves(tree); return (NO_ERROR); } -int RFwrite(RANDOM_FOREST *rf, char *fname) { +int RFwrite(RANDOM_FOREST *rf, char *fname) +{ FILE *fp; int err; @@ -728,7 +749,8 @@ int RFwrite(RANDOM_FOREST *rf, char *fname) { fclose(fp); return (err); } -int RFwriteInto(RANDOM_FOREST *rf, FILE *fp) { +int RFwriteInto(RANDOM_FOREST *rf, FILE *fp) +{ int c, f, n; fprintf(fp, @@ -756,7 +778,8 @@ int RFwriteInto(RANDOM_FOREST *rf, FILE *fp) { return (NO_ERROR); } -static NODE *rfFindLeaf(RF *rf, NODE *node, double *feature) { +static NODE *rfFindLeaf(RF *rf, NODE *node, double *feature) +{ if (DIAG_VERBOSE_ON) { if (node->left) // not a leaf { @@ -787,7 +810,8 @@ static NODE *rfFindLeaf(RF *rf, NODE *node, double *feature) { return (rfFindLeaf(rf, node->right, feature)); } -int RFcomputeOutOfBagCorrect(RANDOM_FOREST *rf, int *training_classes, double **training_data, int ntraining) { +int RFcomputeOutOfBagCorrect(RANDOM_FOREST *rf, int *training_classes, double **training_data, int ntraining) +{ int max_class = -1, n, c, max_count, i, correct, **tree_training; NODE *node; TREE *tree; @@ -890,7 +914,8 @@ int RFcomputeOutOfBagCorrect(RANDOM_FOREST *rf, int *training_classes, double ** return (correct); } -int RFclassify(RANDOM_FOREST *rf, double *feature, double *p_pval, int true_class) { +int RFclassify(RANDOM_FOREST *rf, double *feature, double *p_pval, int true_class) +{ int max_class = -1, n, c; NODE *node; double max_count, class_counts[MAX_CLASSES], total_count; @@ -953,7 +978,8 @@ int RFclassify(RANDOM_FOREST *rf, double *feature, double *p_pval, int true_clas rf->class_names[true_class], 100.0 * class_counts[true_class] / total_count); } - } else + } + else printf("%s: p = %2.2f %s\n", rf->class_names[c], 100 * (double)class_counts[c] / total_count, @@ -962,7 +988,8 @@ int RFclassify(RANDOM_FOREST *rf, double *feature, double *p_pval, int true_clas return (max_class); } -RANDOM_FOREST *RFread(char *fname) { +RANDOM_FOREST *RFread(char *fname) +{ FILE *fp; RF *rf; @@ -973,7 +1000,8 @@ RANDOM_FOREST *RFread(char *fname) { fclose(fp); return (rf); } -RANDOM_FOREST *RFreadFrom(FILE *fp) { +RANDOM_FOREST *RFreadFrom(FILE *fp) +{ RF *rf; int nfeatures, nclasses, ntrees, max_depth, ntraining, nsteps, c, n, f; char line[MAX_LINE_LEN], *cp, *class_names[MAX_CLASSES]; @@ -1019,7 +1047,8 @@ RANDOM_FOREST *RFreadFrom(FILE *fp) { return (rf); } -int RFsetNumberOfClasses(RANDOM_FOREST *rf, int nclasses) { +int RFsetNumberOfClasses(RANDOM_FOREST *rf, int nclasses) +{ int n, c; char **old_class_names; int *old_class_counts; @@ -1051,7 +1080,8 @@ int RFsetNumberOfClasses(RANDOM_FOREST *rf, int nclasses) { rf->nclasses = nclasses; return (NO_ERROR); } -int RFevaluateFeatures(RANDOM_FOREST *rf, FILE *fp) { +int RFevaluateFeatures(RANDOM_FOREST *rf, FILE *fp) +{ int fno, tree_count, total_count = 0, tno; TREE *tree; double info_gain, total_info_gain; @@ -1074,7 +1104,8 @@ int RFevaluateFeatures(RANDOM_FOREST *rf, FILE *fp) { return (NO_ERROR); } static double rfFeatureInfoGain( - RANDOM_FOREST *rf, TREE *tree, NODE *parent, NODE *left, NODE *right, int fno, int *ptotal_count) { + RANDOM_FOREST *rf, TREE *tree, NODE *parent, NODE *left, NODE *right, int fno, int *ptotal_count) +{ int c; double info_gain = 0, entropy_before, entropy_after, wr, wl; @@ -1094,7 +1125,8 @@ static double rfFeatureInfoGain( wr * entropy(right->class_counts, rf->nclasses, tree->root.class_counts); info_gain = ((double)parent->total_counts * (entropy_before - entropy_after)); *ptotal_count += parent->total_counts; - } else + } + else info_gain = 0; info_gain += rfFeatureInfoGain(rf, tree, left, left->left, left->right, fno, ptotal_count); @@ -1102,7 +1134,8 @@ static double rfFeatureInfoGain( } return (info_gain); } -static int rfFreeNodes(NODE *node) { +static int rfFreeNodes(NODE *node) +{ if (node->left) rfFreeNodes(node->left); if (node->right) rfFreeNodes(node->right); @@ -1112,7 +1145,8 @@ static int rfFreeNodes(NODE *node) { return (NO_ERROR); } -int RFfree(RANDOM_FOREST **prf) { +int RFfree(RANDOM_FOREST **prf) +{ RANDOM_FOREST *rf = *prf; int c, t; TREE *tree; @@ -1135,7 +1169,8 @@ int RFfree(RANDOM_FOREST **prf) { return (NO_ERROR); } -static int rfPruneTree(NODE *node, int min_training_samples) { +static int rfPruneTree(NODE *node, int min_training_samples) +{ int deleted; if (node == NULL) return (0); @@ -1150,7 +1185,8 @@ static int rfPruneTree(NODE *node, int min_training_samples) { return (deleted); } -int RFpruneTree(RANDOM_FOREST *rf, int min_training_samples) { +int RFpruneTree(RANDOM_FOREST *rf, int min_training_samples) +{ int t; TREE *tree; diff --git a/utils/selxavgio.c b/utils/selxavgio.c index 410712a556c..da38f1c5775 100644 --- a/utils/selxavgio.c +++ b/utils/selxavgio.c @@ -47,7 +47,8 @@ extern int errno; sv_sxadat_by_stem() - save selxavg.dat structure using volid as base. volid can be either a stem or stem.ext ---------------------------------------------------- */ -int sv_sxadat_by_stem(SXADAT *sxadat, const char *volid) { +int sv_sxadat_by_stem(SXADAT *sxadat, const char *volid) +{ char tmpstr[1000]; int err; char *stem; @@ -63,7 +64,8 @@ int sv_sxadat_by_stem(SXADAT *sxadat, const char *volid) { return (err); } /* ---------------------------------------------------- */ -SXADAT *ld_sxadat_from_stem(const char *volid) { +SXADAT *ld_sxadat_from_stem(const char *volid) +{ char tmpstr[1000]; char *stem; SXADAT *sxa; @@ -83,7 +85,8 @@ SXADAT *ld_sxadat_from_stem(const char *volid) { } /* ---------------------------------------------------- */ -float *sxa_framepower(SXADAT *sxa, int *nframes) { +float *sxa_framepower(SXADAT *sxa, int *nframes) +{ int frame; int h, statid, condition; float *framepower; @@ -105,7 +108,8 @@ float *sxa_framepower(SXADAT *sxa, int *nframes) { } /* ---------------------------------------------------- */ -int is_sxa_volume(const char *volid) { +int is_sxa_volume(const char *volid) +{ char tmpstr[1000]; FILE *fp; char *stem; @@ -127,7 +131,8 @@ int is_sxa_volume(const char *volid) { } /* ---------------------------------------------------- */ -SXADAT *ld_sxadat(const char *sxadatfile) { +SXADAT *ld_sxadat(const char *sxadatfile) +{ FILE *fp; SXADAT *sxa; int n, r, c, Nch; @@ -216,7 +221,8 @@ SXADAT *ld_sxadat(const char *sxadatfile) { } /* ---------------------------------------------------- */ -int sv_sxadat(SXADAT *sxa, const char *sxadatfile) { +int sv_sxadat(SXADAT *sxa, const char *sxadatfile) +{ FILE *fp; int n, r, c, Nch; diff --git a/utils/sig.c b/utils/sig.c index eaa07fd35c0..3c2bd650414 100644 --- a/utils/sig.c +++ b/utils/sig.c @@ -54,7 +54,8 @@ the False Discovery Rate. Christopher R. Genovese, Nicole A. Lazar, Thomas E. Nichols (2002). NeuroImage 15:870-878. ---------------------------------------------------------*/ -double fdr2vwth(double *p, int np, double fdr) { +double fdr2vwth(double *p, int np, double fdr) +{ int n; double r; r = fdr / np; @@ -81,7 +82,8 @@ double fdr2vwth(double *p, int np, double fdr) { Return: FDR between 0 and 1. Note: values in p will be changed (sorted ascending). ---------------------------------------------------------*/ -double vwth2fdr(double *p, int np, double vwth) { +double vwth2fdr(double *p, int np, double vwth) +{ double fdr = 0, r = 0; int n; @@ -102,7 +104,8 @@ double vwth2fdr(double *p, int np, double vwth) { /*--------------------------------------------------------------- doublecompar() - qsort compare function to compare two doubles --------------------------------------------------------------*/ -int doublecompar(const void *v1, const void *v2) { +int doublecompar(const void *v1, const void *v2) +{ double dv1, dv2; dv1 = *((double *)v1); dv2 = *((double *)v2); @@ -114,7 +117,8 @@ int doublecompar(const void *v1, const void *v2) { #define MAXT 30.0 #define MAXDOF 200 /* note, everything here is Doug's fault */ -double sigt(double t, int df) { +double sigt(double t, int df) +{ double sig = 0.0, sig1, sig2; if (df == 0) @@ -137,7 +141,8 @@ double sigt(double t, int df) { return sig; } -float sigchisq(double chisq, int df) { +float sigchisq(double chisq, int df) +{ float p; if (FZERO(chisq) || df == 0) return (1.0f); diff --git a/utils/signa.c b/utils/signa.c index 8cbb618d89e..d6aa7263371 100644 --- a/utils/signa.c +++ b/utils/signa.c @@ -77,14 +77,16 @@ read_signa(char *fname, char *h, float scale) /*------------------------------------------------------------*/ /* Get Header (Character) */ -char *ghc(char *destin, char *header, int offset, int byte_length) { +char *ghc(char *destin, char *header, int offset, int byte_length) +{ strncpy(destin, header + (2 * offset), byte_length); return (destin); } /*------------------------------------------------------------*/ /* Get Header (integer) */ -int ghi(char *header, int offset) { +int ghi(char *header, int offset) +{ int num; int i; int byte_length = 2; @@ -99,7 +101,8 @@ int ghi(char *header, int offset) { /*------------------------------------------------------------*/ /* Get Header (float) */ -float ghf(char *header, int offset) { +float ghf(char *header, int offset) +{ #define sign_bit 020000000000 #define dmantissa 077777777 #define dexponent 0177 @@ -149,7 +152,8 @@ float ghf(char *header, int offset) { /*------------------------------------------------------------*/ /* Get header info */ -int get_signa_header_info(char *h, HINFO *hinfo) { +int get_signa_header_info(char *h, HINFO *hinfo) +{ hinfo->plane_type = ghi(h, SEHDR_START + SEHDR_PTYPE); hinfo->x = ghi(h, IHDR_START + IHDR_X); hinfo->y = ghi(h, IHDR_START + IHDR_Y); @@ -183,7 +187,8 @@ int get_signa_header_info(char *h, HINFO *hinfo) { return (NO_ERROR); } -int is_signa(char *fname) { +int is_signa(char *fname) +{ HINFO header; char h[HLENGTH + 2]; FILE *fp; @@ -203,7 +208,8 @@ int is_signa(char *fname) { (header.ti > 0 && header.imnr1 >= 0 && devFinite(header.psiz))); } -MRI *signaRead(char *fname, int read_volume_flag) { +MRI *signaRead(char *fname, int read_volume_flag) +{ HINFO header; char h[HLENGTH + 2]; FILE *fp; @@ -215,7 +221,8 @@ MRI *signaRead(char *fname, int read_volume_flag) { if (getenv("GE_ODD")) { odd_only = 1; printf("only using odd # GE Signa files\n"); - } else if (getenv("GE_EVEN")) { + } + else if (getenv("GE_EVEN")) { even_only = 1; printf("only using even # GE Signa files\n"); } @@ -233,7 +240,8 @@ MRI *signaRead(char *fname, int read_volume_flag) { if (odd_only) { if (ISEVEN(header.imnr0)) header.imnr0--; if (ISEVEN(header.imnr1)) header.imnr1--; - } else if (even_only) { + } + else if (even_only) { if (ISODD(header.imnr0)) header.imnr0++; if (ISODD(header.imnr1)) header.imnr1++; } @@ -242,7 +250,8 @@ MRI *signaRead(char *fname, int read_volume_flag) { else if (header.num_echoes > 1) { printf("SIGNA multi-echo file detected (%d echoes)\n", header.num_echoes); mri = MRIallocSequence(header.x, header.y, (header.imnr1 - header.imnr0) / 2 + 1, MRI_SHORT, header.num_echoes); - } else + } + else mri = MRIalloc(header.x, header.y, header.imnr1 - header.imnr0 + 1, MRI_SHORT); if (!mri) ErrorReturn(NULL, @@ -302,7 +311,8 @@ MRI *signaRead(char *fname, int read_volume_flag) { fread(&MRISseq_vox(mri, 0, 0, slice, frame), sizeof(short), mri->width * mri->height, fp); orderShortBuffer(&MRISseq_vox(mri, 0, 0, slice, frame), mri->width * mri->height); if (frame == 0) slice--; // same slice, next echo - } else { + } + else { fread(&MRISvox(mri, 0, 0, slice), sizeof(short), mri->width * mri->height, fp); orderShortBuffer(&MRISvox(mri, 0, 0, slice), mri->width * mri->height); } @@ -314,7 +324,8 @@ MRI *signaRead(char *fname, int read_volume_flag) { return (mri); } -static int orderShortBuffer(short *sbuf, int nbytes) { +static int orderShortBuffer(short *sbuf, int nbytes) +{ #if (BYTE_ORDER == LITTLE_ENDIAN) int i; diff --git a/utils/sse_mathfun_test.c b/utils/sse_mathfun_test.c index bad9826e959..d9f78db7830 100644 --- a/utils/sse_mathfun_test.c +++ b/utils/sse_mathfun_test.c @@ -117,7 +117,8 @@ millions of vector evaluations/second -> 29 cycles/value on a 2000MHz computer #include /* useful when debuggin.. */ -void print4(__m128 v) { +void print4(__m128 v) +{ float *p = (float *)&v; #ifndef USE_SSE2 _mm_empty(); @@ -125,14 +126,16 @@ void print4(__m128 v) { printf("[%13.8g, %13.8g, %13.8g, %13.8g]", p[0], p[1], p[2], p[3]); } -void print2i(__m64 v) { +void print2i(__m64 v) +{ unsigned *p = (unsigned *)&v; printf("[%08x %08x]", p[0], p[1]); } #ifdef USE_SSE2 #include -void print4i(__m128i v) { +void print4i(__m128i v) +{ unsigned *p = (unsigned *)&v; printf("[%08x %08x %08x %08x]", p[0], p[1], p[2], p[3]); } @@ -167,7 +170,8 @@ typedef ALIGN16_BEG union { double frand() { return rand() / (double)RAND_MAX; } #if defined(HAVE_SYS_TIMES) -inline double uclock_sec(void) { +inline double uclock_sec(void) +{ static double ttclk = 0.; if (ttclk == 0.) ttclk = sysconf(_SC_CLK_TCK); struct tms t; @@ -185,14 +189,16 @@ inline double uclock_sec(void) { return (double)clock() / (double)CLOCKS_PER_SEC #define M_LN2 0.69314718055994530942 #endif -int bitdiff(float a, float b) { +int bitdiff(float a, float b) +{ if (a == b) return 24; else if (a == 0) { int j = -log(fabs(b)) / M_LN2; if (j > 24) j = 24; return j; - } else + } + else return log(fabs(a)) / M_LN2 - log(fabs(b - a)) / M_LN2; } @@ -202,7 +208,8 @@ float cephes_cosf(float); float cephes_logf(float); float cephes_expf(float); -int check_sincos_precision(float xmin, float xmax) { +int check_sincos_precision(float xmin, float xmax) +{ unsigned nb_trials = 100000; printf("checking sines on [%g*Pi, %g*Pi]\n", xmin, xmax); @@ -283,7 +290,8 @@ int check_sincos_precision(float xmin, float xmax) { if (max_err_sum_sqr_ref < 2e-7 && max_err_sin_ref < 2e-7 && max_err_cos_ref < 2e-7) { printf(" ->> precision OK for the sin_ps / cos_ps / sincos_ps <<-\n\n"); return 0; - } else { + } + else { printf("\n WRONG PRECISION !! there is a problem\n\n"); return 1; } @@ -294,7 +302,8 @@ union float_int_union { float f; } QNAN = {0xFFC00000}, QNAN2 = {0x7FC00000}, PINF = {0x7F800000}, MINF = {0xFF800000}; -int check_explog_precision(float xmin, float xmax) { +int check_explog_precision(float xmin, float xmax) +{ unsigned nb_trials = 100000; printf("checking exp/log [%g, %g]\n", xmin, xmax); @@ -355,13 +364,15 @@ int check_explog_precision(float xmin, float xmax) { if (max_err_logexp_test < 2e-7 && max_err_exp_ref < 2e-7 && max_err_log_ref < 2e-7) { printf(" ->> precision OK for the exp_ps / log_ps <<-\n\n"); return 0; - } else { + } + else { printf("\n WRONG PRECISION !! there is a problem\n\n"); return 1; } } -void dumb() { +void dumb() +{ V4SF x = {{0.0903333798051, 0.0903333798051, 0.0903333798051, 0.0903333798051}}; V4SF w; w.v = log_ps(x.v); @@ -375,7 +386,8 @@ void dumb() { exit(1); } -void check_special_values() { +void check_special_values() +{ V4SF vx; vx.f[0] = -1000; vx.f[1] = -100; @@ -440,7 +452,8 @@ void check_special_values() { } #define DECL_SCALAR_FN_BENCH(fn) \ - int bench_##fn() { \ + int bench_##fn() \ + { \ int niter = 10000, i, j; \ float x = 0.5f, y = 0; \ for (i = 0; i < niter; ++i) { \ @@ -454,7 +467,8 @@ void check_special_values() { } #define DECL_VECTOR_FN_BENCH(fn) \ - int bench_##fn() { \ + int bench_##fn() \ + { \ int niter = 10000, i; \ v4sf bmin = _mm_set_ps1(0.5), bmax = _mm_set_ps1(1.0); \ v4sf x = _mm_set_ps1(0.75); \ @@ -469,13 +483,15 @@ void check_special_values() { #ifdef __GNUC__ #define HAVE_SINCOS_X86_FPU -void sincos_x86_fpu(double t, double *st, double *ct) { +void sincos_x86_fpu(double t, double *st, double *ct) +{ asm("fsincos;" : "=t"(*ct), "=u"(*st) : "0"(t) : "st(7)"); //*st = sin(t); *ct = cos(t); } #elif defined(_MSC_VER) && !defined(_WIN64) #define HAVE_SINCOS_X86_FPU -void sincos_x86_fpu(double t, double *st_, double *ct_) { +void sincos_x86_fpu(double t, double *st_, double *ct_) +{ _asm { fld QWORD PTR [t] fsincos @@ -488,14 +504,16 @@ void sincos_x86_fpu(double t, double *st_, double *ct_) { #endif #ifdef HAVE_SINCOS_X86_FPU -float stupid_sincos_x86_fpu(float x) { +float stupid_sincos_x86_fpu(float x) +{ double s, c; sincos_x86_fpu(x, &s, &c); return s + c; } #endif -v4sf stupid_sincos_ps(v4sf x) { +v4sf stupid_sincos_ps(v4sf x) +{ v4sf s, c; sincos_ps(x, &s, &c); return s; @@ -530,7 +548,8 @@ DECL_VECTOR_FN_BENCH(__vrs4_expf); DECL_VECTOR_FN_BENCH(__vrs4_logf); #endif -void run_bench(const char *s, int (*fn)()) { +void run_bench(const char *s, int (*fn)()) +{ printf("benching %20s ..", s); fflush(stdout); double t0 = uclock_sec(), t1, tmax = 1.0; @@ -546,7 +565,8 @@ void run_bench(const char *s, int (*fn)()) { REF_FREQ_MHZ); } -void sanity_check() { +void sanity_check() +{ printf("doing some sanity checks...\n"); #ifndef USE_SSE2 V4SF v = {{1, 2, 3, 4}}, z = {{5, 6, 7, 8}}; @@ -616,7 +636,8 @@ void sanity_check() { #endif // USE_SSE2 } -int main() { +int main() +{ // dumb(); // sanity_check(); int err = 0; @@ -777,7 +798,8 @@ static float T24M1 = 16777215.; static float sincof[] = {-1.9515295891E-4, 8.3321608736E-3, -1.6666654611E-1}; static float coscof[] = {2.443315711809948E-005, -1.388731625493765E-003, 4.166664568298827E-002}; -float cephes_sinf(float xx) { +float cephes_sinf(float xx) +{ float *p; float x, y, z; register unsigned long j; @@ -809,7 +831,8 @@ float cephes_sinf(float xx) { if (x > lossth) { // mtherr( "sinf", PLOSS ); x = x - y * PIO4F; - } else { + } + else { /* Extended precision modular arithmetic */ x = ((x - y * DP1) - y * DP2) - y * DP3; } @@ -831,7 +854,8 @@ float cephes_sinf(float xx) { y *= z; y -= 0.5 * z; y += 1.0; - } else { + } + else { /* Theoretical relative error = 3.8e-9 in [-pi/4, +pi/4] */ /* y = ((-1.9515295891E-4 * z @@ -860,7 +884,8 @@ float cephes_sinf(float xx) { * rms relative error: 2.2e-8 */ -float cephes_cosf(float xx) { +float cephes_cosf(float xx) +{ float x, y, z; int j, sign; @@ -893,7 +918,8 @@ float cephes_cosf(float xx) { if (x > lossth) { // mtherr( "cosf", PLOSS ); x = x - y * PIO4F; - } else + } + else /* Extended precision modular arithmetic */ x = ((x - y * DP1) - y * DP2) - y * DP3; @@ -903,7 +929,8 @@ float cephes_cosf(float xx) { if ((j == 1) || (j == 2)) { y = (((-1.9515295891E-4f * z + 8.3321608736E-3f) * z - 1.6666654611E-1f) * z * x) + x; - } else { + } + else { y = ((2.443315711809948E-005f * z - 1.388731625493765E-003f) * z + 4.166664568298827E-002f) * z * z; y -= 0.5 * z; y += 1.0; @@ -988,7 +1015,8 @@ static float LOG2EF = 1.44269504088896341; static float C1 = 0.693359375; static float C2 = -2.12194440e-4; -float cephes_expf(float xx) { +float cephes_expf(float xx) +{ float x, z; int n; @@ -1090,7 +1118,8 @@ float PIF = 3.141592653589793238; float PIO2F = 1.5707963267948966192; float MACHEPF = 5.9604644775390625E-8; -float cephes_logf(float xx) { +float cephes_logf(float xx) +{ register float y; float x, z, fe; int e; @@ -1108,7 +1137,8 @@ float cephes_logf(float xx) { if (x < SQRTHF) { e -= 1; x = x + x - 1.0; /* 2x - 1 */ - } else { + } + else { x = x - 1.0; } z = x * x; diff --git a/utils/stats.c b/utils/stats.c index 8da8077a63a..16e2a082696 100644 --- a/utils/stats.c +++ b/utils/stats.c @@ -54,7 +54,8 @@ MATRIX *StatLoadTalairachXFM(const char *subjid, const char *xfmfile); /*--------------------------------------------------------------------*/ // Load output of asegstats2table or aparcstats2table. -STAT_TABLE *LoadStatTable(const char *statfile) { +STAT_TABLE *LoadStatTable(const char *statfile) +{ STAT_TABLE *st; FILE *fp; char tmpstr[100000]; @@ -139,7 +140,8 @@ STAT_TABLE *LoadStatTable(const char *statfile) { return (st); } -STAT_TABLE *AllocStatTable(int nrows, int ncols) { +STAT_TABLE *AllocStatTable(int nrows, int ncols) +{ STAT_TABLE *st; int r; @@ -156,7 +158,8 @@ STAT_TABLE *AllocStatTable(int nrows, int ncols) { } // Write output equivalant of asegstats2table or aparcstats2table. -int WriteStatTable(const char *fname, STAT_TABLE *st) { +int WriteStatTable(const char *fname, STAT_TABLE *st) +{ FILE *fp; int err; @@ -169,7 +172,8 @@ int WriteStatTable(const char *fname, STAT_TABLE *st) { return (err); } -int PrintStatTable(FILE *fp, STAT_TABLE *st) { +int PrintStatTable(FILE *fp, STAT_TABLE *st) +{ int r, c; fprintf(fp, "%-33s ", st->measure); @@ -255,7 +259,8 @@ STAT_TABLE *InitStatTableFromMRI(MRI *mri_in, const char *tablefile) /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -fMRI_REG *StatReadRegistration(const char *fname) { +fMRI_REG *StatReadRegistration(const char *fname) +{ int float2int, err; fMRI_REG *reg; char *subject; @@ -272,7 +277,8 @@ fMRI_REG *StatReadRegistration(const char *fname) { /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -int StatFreeRegistration(fMRI_REG **preg) { +int StatFreeRegistration(fMRI_REG **preg) +{ fMRI_REG *reg; reg = *preg; @@ -285,7 +291,8 @@ int StatFreeRegistration(fMRI_REG **preg) { /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -SV *StatReadVolume(const char *prefix) { +SV *StatReadVolume(const char *prefix) +{ char path[STRLEN], fname[STRLEN], line[MAX_LINE_LEN], *cp; STAT_VOLUME *sv; FILE *fp; @@ -331,13 +338,15 @@ SV *StatReadVolume(const char *prefix) { printf("SelXAvg Format TER = %g, DOF = %d\n", TER, DOF); sv->voltype = 2; fprintf(stderr, "INFO: detected volume %s as type selxavg\n", prefix); - } else { + } + else { sv->voltype = 1; fprintf(stderr, "INFO: detected volume %s as type selavg\n", prefix); } fclose(fp); which_alloc |= ALLOC_STDS; - } else { + } + else { /*fprintf(stderr,"WARNING: %s: StatReadVolume():\n",Progname); fprintf(stderr,"%s does not exist\n",fname);*/ fprintf(stderr, "INFO: detected volume %s as type raw\n", prefix); @@ -363,11 +372,13 @@ SV *StatReadVolume(const char *prefix) { sv->std_dofs[event_number] = (float)dof_sigma; } fclose(fp); - } else { + } + else { fprintf(stderr, "WARNING: %s: StatReadVolume():\n", Progname); fprintf(stderr, "%s does not exist\n", fname); } - } else { + } + else { if (sv->voltype == 0) DOF = 1; /* for raw type */ for (event_number = 0; event_number < sv->nevents; event_number++) { sv->mean_dofs[event_number] = (float)DOF + 1; @@ -430,7 +441,8 @@ SV *StatReadVolume(const char *prefix) { sprintf(fname, "%s_%3.3d.bshort", prefix, z); if (!fp) { ErrorReturn(NULL, (ERROR_NOFILE, "StatReadVolume: could not open %s", fname)); - } else + } + else fprintf(stderr, "ERROR: %s does not support bshort volumes\n", Progname); } @@ -534,7 +546,8 @@ SV *StatReadVolume(const char *prefix) { /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -SV *StatReadVolume2(const char *prefix) { +SV *StatReadVolume2(const char *prefix) +{ char path[STRLEN], fname[STRLEN], line[MAX_LINE_LEN]; STAT_VOLUME *sv; FILE *fp; @@ -652,7 +665,8 @@ SV *StatReadVolume2(const char *prefix) { /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -int StatFree(SV **psv) { +int StatFree(SV **psv) +{ SV *sv; int event, width, height, nslices; @@ -694,8 +708,8 @@ StatVolumeToTalairach(SV *sv, MRI *mri, int resolution) #endif /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -STAT_VOLUME *StatAllocVolume( - SV *sv, int nevents, int width, int height, int nslices, int time_points, int which_alloc) { +STAT_VOLUME *StatAllocVolume(SV *sv, int nevents, int width, int height, int nslices, int time_points, int which_alloc) +{ int event; if (!sv) { @@ -739,7 +753,8 @@ STAT_VOLUME *StatAllocVolume( } /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -SV *StatAllocStructuralVolume(SV *sv, float fov, float resolution, const char *name) { +SV *StatAllocStructuralVolume(SV *sv, float fov, float resolution, const char *name) +{ SV *sv_tal; int width, height, depth, event; @@ -776,7 +791,8 @@ SV *StatAllocStructuralVolume(SV *sv, float fov, float resolution, const char *n } /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -int StatAccumulateSurfaceVolume(SV *sv_surf, SV *sv, MRI_SURFACE *mris) { +int StatAccumulateSurfaceVolume(SV *sv_surf, SV *sv, MRI_SURFACE *mris) +{ int x, y, z, width, height, depth, event, t, xv, yv, zv, swidth, sheight, sdepth, vno; double xf, yf, zf, xr, yr, zr; float mean, surf_mean, std, surf_std, surf_dof, dof, xoff, yoff, zoff, sxoff, syoff, szoff, xs, ys, zs; @@ -968,7 +984,8 @@ int StatAccumulateSurfaceVolume(SV *sv_surf, SV *sv, MRI_SURFACE *mris) { } /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -int StatAccumulateTalairachVolume(SV *sv_tal, SV *sv) { +int StatAccumulateTalairachVolume(SV *sv_tal, SV *sv) +{ int x, y, z, width, height, depth, event, t, xv, yv, zv, swidth, sheight, sdepth; // double xf, yf, zf ; float mean, tal_mean, std, tal_std, tal_dof, dof, xoff, yoff, zoff, sxoff, syoff, szoff; @@ -1140,7 +1157,8 @@ int StatAccumulateTalairachVolume(SV *sv_tal, SV *sv) { } /*-------------------------------------------------------------- ----------------------------------------------------------------*/ -int StatWriteVolume(SV *sv, const char *prefix) { +int StatWriteVolume(SV *sv, const char *prefix) +{ char path[STRLEN], fname[STRLEN]; FILE *fp; int event_number, width, height, nslices, t, event, nitems, x, y, z, nframes; @@ -1317,7 +1335,8 @@ int StatWriteVolume(SV *sv, const char *prefix) { } /*------------------------------------------------------------------ -------------------------------------------------------------------*/ -int StatWriteRegistration(fMRI_REG *reg, const char *fname) { +int StatWriteRegistration(fMRI_REG *reg, const char *fname) +{ FILE *fp; int row, col; @@ -1337,7 +1356,8 @@ int StatWriteRegistration(fMRI_REG *reg, const char *fname) { } /*------------------------------------------------------------------- -------------------------------------------------------------------*/ -int StatReadTransform(STAT_VOLUME *sv, const char *name) { +int StatReadTransform(STAT_VOLUME *sv, const char *name) +{ char *sd, subjects[STRLEN], fname[STRLEN]; int event; @@ -1363,7 +1383,8 @@ int StatReadTransform(STAT_VOLUME *sv, const char *name) { } /*------------------------------------------------------------------------ ------------------------------------------------------------------------*/ -int StatVolumeExists(const char *prefix) { +int StatVolumeExists(const char *prefix) +{ char fname[STRLEN]; FILE *fp; @@ -1378,7 +1399,8 @@ int StatVolumeExists(const char *prefix) { If the transform is Vox2Vox, converts it to RAS2RAS. The file is assumed to exist in SUBJECTS_DIR/subjid/mri/transforms/xfmfile. ------------------------------------------------------------------------*/ -MATRIX *StatLoadTalairachXFM(const char *subjid, const char *xfmfile) { +MATRIX *StatLoadTalairachXFM(const char *subjid, const char *xfmfile) +{ char subjects[STRLEN], fname[STRLEN]; MATRIX *Mcor2tal; LTA *lta; @@ -1407,7 +1429,8 @@ MATRIX *StatLoadTalairachXFM(const char *subjid, const char *xfmfile) { return (Mcor2tal); } -FS_STATS *FSstatsRead(char *fname) { +FS_STATS *FSstatsRead(char *fname) +{ FS_STATS *stats; char line[MAX_LINE_LEN], *cp, name[STRLEN]; FILE *fp; @@ -1441,7 +1464,8 @@ FS_STATS *FSstatsRead(char *fname) { return (stats); } -int PrintSegStat(FILE *fp, SEGSTAT *segstat) { +int PrintSegStat(FILE *fp, SEGSTAT *segstat) +{ int n, c; char tmpstr[1000]; @@ -1463,7 +1487,8 @@ int PrintSegStat(FILE *fp, SEGSTAT *segstat) { fprintf(fp, "# TableCol 4 FieldName Volume\n"); fprintf(fp, "# TableCol 4 Units mm^3\n"); segstat->ColHeaders[3] = strcpyalloc("Volume_mm3"); - } else { + } + else { fprintf(fp, "# TableCol 3 ColHeader NVertices \n"); fprintf(fp, "# TableCol 3 FieldName Number of Vertices\n"); fprintf(fp, "# TableCol 3 Units unitless\n"); diff --git a/utils/stc.c b/utils/stc.c index 3cd017b748a..e0abd53a604 100644 --- a/utils/stc.c +++ b/utils/stc.c @@ -35,7 +35,8 @@ #include "proto.h" #include "stc.h" -int StcWrite(char *fname, MATRIX *m_data, float epoch_begin_lat, float sample_period, int *vertices, int nvertices) { +int StcWrite(char *fname, MATRIX *m_data, float epoch_begin_lat, float sample_period, int *vertices, int nvertices) +{ int vno, ntime, row, col; FILE *fp; float val; @@ -66,7 +67,8 @@ int StcWrite(char *fname, MATRIX *m_data, float epoch_begin_lat, float sample_pe return (NO_ERROR); } -STC_FILE *StcOpen(char *fstem) { +STC_FILE *StcOpen(char *fstem) +{ STC_FILE *stc_file; char fname[STRLEN]; int vno; @@ -92,7 +94,8 @@ STC_FILE *StcOpen(char *fstem) { return stc_file; } -void StcClose(STC_FILE *stc_file) { +void StcClose(STC_FILE *stc_file) +{ if (stc_file->file_handle) fclose(stc_file->file_handle); if (stc_file->vertices) { @@ -102,7 +105,8 @@ void StcClose(STC_FILE *stc_file) { } } -STC_FRAME *StcReadFrame(int fno, STC_FILE *stc_file) { +STC_FRAME *StcReadFrame(int fno, STC_FILE *stc_file) +{ STC_FRAME *stc; int baseoffset, offset; int framesize, vno; @@ -133,7 +137,8 @@ STC_FRAME *StcReadFrame(int fno, STC_FILE *stc_file) { return stc; } -STC *StcRead(char *fstem) { +STC *StcRead(char *fstem) +{ int j, vno; char fname[STRLEN]; FILE *fp; @@ -188,7 +193,8 @@ STC *StcRead(char *fstem) { return (stc); } -void StcFree(STC *stc) { +void StcFree(STC *stc) +{ if (stc->vertices) free(stc->vertices); if (stc->m_vals) MatrixFree(&stc->m_vals); diff --git a/utils/surfcluster.c b/utils/surfcluster.c index d6885420499..37e78e7cf60 100644 --- a/utils/surfcluster.c +++ b/utils/surfcluster.c @@ -60,7 +60,8 @@ const char *sculstSrcVersion(void) { return ("$Id: surfcluster.c,v 1.36 2016/11/ criteria, then undefval is set to the cluster number. ------------------------------------------------------------ */ SCS *sclustMapSurfClusters( - MRI_SURFACE *Surf, float thmin, float thmax, int thsign, float minarea, int *nClusters, MATRIX *XFM) { + MRI_SURFACE *Surf, float thmin, float thmax, int thsign, float minarea, int *nClusters, MATRIX *XFM) +{ SCS *scs, *scs_sorted; int vtx, vtx_inrange, vtx_clustno, CurrentClusterNo; float vtx_val, ClusterArea; @@ -124,7 +125,8 @@ SCS *sclustMapSurfClusters( cluster criteria, then undefval is set to the ClusterNo. The ClustNo cannot be 0. ------------------------------------------------------------ */ -int sclustGrowSurfCluster(int ClusterNo, int SeedVtx, MRI_SURFACE *Surf, float thmin, float thmax, int thsign) { +int sclustGrowSurfCluster(int ClusterNo, int SeedVtx, MRI_SURFACE *Surf, float thmin, float thmax, int thsign) +{ int nbr, nbr_vtx, nbr_inrange, nbr_clustno; float nbr_val; @@ -152,7 +154,8 @@ int sclustGrowSurfCluster(int ClusterNo, int SeedVtx, MRI_SURFACE *Surf, float t cluster. Note: MRIScomputeMetricProperties() must have been run on the surface. ----------------------------------------------------------------*/ -float sclustSurfaceArea(int ClusterNo, MRI_SURFACE *Surf, int *nvtxs) { +float sclustSurfaceArea(int ClusterNo, MRI_SURFACE *Surf, int *nvtxs) +{ int vtx, vtx_clusterno; float ClusterArea; @@ -208,7 +211,8 @@ float sclustSurfaceArea(int ClusterNo, MRI_SURFACE *Surf, int *nvtxs) { field in Surf is used. If UseArea==1, then the value at a vertex is weighted by the area at the vertex. ----------------------------------------------------------------*/ -float sclustWeight(int ClusterNo, MRI_SURFACE *Surf, MRI *mri, int UseArea) { +float sclustWeight(int ClusterNo, MRI_SURFACE *Surf, MRI *mri, int UseArea) +{ int vtx, vtx_clusterno; double ClusterWeight, h, vtxarea; @@ -238,7 +242,8 @@ float sclustWeight(int ClusterNo, MRI_SURFACE *Surf, MRI *mri, int UseArea) { sclustSurfaceMax() - returns the maximum intensity value of inside a given cluster and the vertex at which it occured. ----------------------------------------------------------------*/ -float sclustSurfaceMax(int ClusterNo, MRI_SURFACE *Surf, int *vtxmax) { +float sclustSurfaceMax(int ClusterNo, MRI_SURFACE *Surf, int *vtxmax) +{ int vtx, vtx_clusterno, first_hit; float vtx_val, vtx_val_max = 0; @@ -266,7 +271,8 @@ float sclustSurfaceMax(int ClusterNo, MRI_SURFACE *Surf, int *vtxmax) { /*---------------------------------------------------------------- sclustSurfaceCentroid() - returns the centroid of a cluster. ----------------------------------------------------------------*/ -int sclustSurfaceCentroid(const int ClusterNo, const MRI_SURFACE *Surf, double *xyz) { +int sclustSurfaceCentroid(const int ClusterNo, const MRI_SURFACE *Surf, double *xyz) +{ int vtx, vtx_clusterno, nvtx; float xsum, ysum, zsum; nvtx = 0; @@ -295,7 +301,8 @@ int sclustSurfaceCentroid(const int ClusterNo, const MRI_SURFACE *Surf, double * is good for pruning clusters that do not meet some other criteria (eg, area threshold). ----------------------------------------------------------------*/ -float sclustZeroSurfaceClusterNo(int ClusterNo, MRI_SURFACE *Surf) { +float sclustZeroSurfaceClusterNo(int ClusterNo, MRI_SURFACE *Surf) +{ int vtx, vtx_clusterno; for (vtx = 0; vtx < Surf->nvertices; vtx++) { @@ -310,7 +317,8 @@ float sclustZeroSurfaceClusterNo(int ClusterNo, MRI_SURFACE *Surf) { that are not assocated with a cluster. The cluster number is the undefval member of the surface structure. ----------------------------------------------------------------*/ -float sclustZeroSurfaceNonClusters(MRI_SURFACE *Surf) { +float sclustZeroSurfaceNonClusters(MRI_SURFACE *Surf) +{ int vtx, vtx_clusterno; for (vtx = 0; vtx < Surf->nvertices; vtx++) { @@ -325,7 +333,8 @@ float sclustZeroSurfaceNonClusters(MRI_SURFACE *Surf) { cluster number. The cluster number is the undefval member of the surface structure. ----------------------------------------------------------------*/ -float sclustSetSurfaceValToClusterNo(MRI_SURFACE *Surf) { +float sclustSetSurfaceValToClusterNo(MRI_SURFACE *Surf) +{ int vtx, vtx_clusterno; for (vtx = 0; vtx < Surf->nvertices; vtx++) { @@ -339,7 +348,8 @@ float sclustSetSurfaceValToClusterNo(MRI_SURFACE *Surf) { sclustSetSurfaceClusterToCWP() - sets the value of a vertex to -log10(cluster-wise pvalue). ----------------------------------------------------------------*/ -float sclustSetSurfaceValToCWP(MRI_SURFACE *Surf, SCS *scs) { +float sclustSetSurfaceValToCWP(MRI_SURFACE *Surf, SCS *scs) +{ int vtx, vtx_clusterno; float val; @@ -366,7 +376,8 @@ float sclustSetSurfaceValToCWP(MRI_SURFACE *Surf, SCS *scs) { just returns the largest cluster number, which will be the number of clusters if there are no holes. ----------------------------------------------------------------*/ -float sclustCountClusters(MRI_SURFACE *Surf) { +float sclustCountClusters(MRI_SURFACE *Surf) +{ int vtx, vtx_clusterno, maxclusterno; maxclusterno = 0; @@ -381,7 +392,8 @@ float sclustCountClusters(MRI_SURFACE *Surf) { SurfClusterSummaryFast() - gives identical results as SurfClusterSummary() but much, much faster. ----------------------------------------------------------------*/ -SCS *SurfClusterSummaryFast(MRI_SURFACE *Surf, MATRIX *T, int *nClusters) { +SCS *SurfClusterSummaryFast(MRI_SURFACE *Surf, MATRIX *T, int *nClusters) +{ int n, vtx, clusterno; SURFCLUSTERSUM *scs; MATRIX *xyz, *xyzxfm; @@ -483,7 +495,8 @@ SCS *SurfClusterSummaryFast(MRI_SURFACE *Surf, MATRIX *T, int *nClusters) { } /*----------------------------------------------------------------*/ -SCS *SurfClusterSummary(MRI_SURFACE *Surf, MATRIX *T, int *nClusters) { +SCS *SurfClusterSummary(MRI_SURFACE *Surf, MATRIX *T, int *nClusters) +{ int n; SURFCLUSTERSUM *scs; MATRIX *xyz, *xyzxfm; @@ -552,7 +565,8 @@ SCS *SurfClusterSummary(MRI_SURFACE *Surf, MATRIX *T, int *nClusters) { return (scs); } /*----------------------------------------------------------------*/ -int DumpSurfClusterSum(FILE *fp, SCS *scs, int nClusters) { +int DumpSurfClusterSum(FILE *fp, SCS *scs, int nClusters) +{ int n; for (n = 0; n < nClusters; n++) { @@ -575,7 +589,8 @@ int DumpSurfClusterSum(FILE *fp, SCS *scs, int nClusters) { return (0); } /*----------------------------------------------------------------*/ -SCS *SortSurfClusterSum(SCS *scs, int nClusters) { +SCS *SortSurfClusterSum(SCS *scs, int nClusters) +{ SCS *scs_sorted; int n; @@ -595,7 +610,8 @@ SCS *SortSurfClusterSum(SCS *scs, int nClusters) { (SCS). It is assumed that the scs.clusterno in the sorted SCS is the cluster id that corresponds to the original cluster id. ----------------------------------------------------------------*/ -int sclustReMap(MRI_SURFACE *Surf, int nClusters, SCS *scs_sorted) { +int sclustReMap(MRI_SURFACE *Surf, int nClusters, SCS *scs_sorted) +{ int vtx, c, cOld; int *Orig2Sorted; @@ -623,7 +639,8 @@ int sclustReMap(MRI_SURFACE *Surf, int nClusters, SCS *scs_sorted) { return (0); } /* Older, slower version of sclustReMap()*/ -int sclustReMap0(MRI_SURFACE *Surf, int nClusters, SCS *scs_sorted) { +int sclustReMap0(MRI_SURFACE *Surf, int nClusters, SCS *scs_sorted) +{ int vtx, vtx_clusterno, c; if (Gdiag_no > 1) { @@ -652,7 +669,8 @@ int sclustReMap0(MRI_SURFACE *Surf, int nClusters, SCS *scs_sorted) { sclustCompare() - compares two surface cluster summaries (for use with qsort(). ----------------------------------------------------------------*/ -static int sclustCompare(const void *a, const void *b) { +static int sclustCompare(const void *a, const void *b) +{ SCS sc1, sc2; sc1 = *((SURFCLUSTERSUM *)a); @@ -674,7 +692,8 @@ static int sclustCompare(const void *a, const void *b) { sclustMaxClusterArea() - returns the area of the cluster with the maximum area. -------------------------------------------------------------------*/ -double sclustMaxClusterArea(SURFCLUSTERSUM *scs, int nClusters) { +double sclustMaxClusterArea(SURFCLUSTERSUM *scs, int nClusters) +{ int n; double maxarea; @@ -690,7 +709,8 @@ double sclustMaxClusterArea(SURFCLUSTERSUM *scs, int nClusters) { sclustMaxClusterCount() - returns the area of the cluster with the maximum number of members (count) -------------------------------------------------------------------*/ -int sclustMaxClusterCount(SURFCLUSTERSUM *scs, int nClusters) { +int sclustMaxClusterCount(SURFCLUSTERSUM *scs, int nClusters) +{ int n; int maxcount; @@ -706,7 +726,8 @@ int sclustMaxClusterCount(SURFCLUSTERSUM *scs, int nClusters) { sclustMaxClusterWeightVtx() - returns the weightvtx of the cluster with the maximum weightvtx. -------------------------------------------------------------------*/ -float sclustMaxClusterWeightVtx(SURFCLUSTERSUM *scs, int nClusters, int thsign) { +float sclustMaxClusterWeightVtx(SURFCLUSTERSUM *scs, int nClusters, int thsign) +{ int n; float maxw, w; @@ -726,7 +747,8 @@ float sclustMaxClusterWeightVtx(SURFCLUSTERSUM *scs, int nClusters, int thsign) } /*---------------------------------------------------------------*/ -SCS *sclustPruneByCWPval(SCS *ClusterList, int nclusters, double cwpvalthresh, int *nPruned, MRIS *surf) { +SCS *sclustPruneByCWPval(SCS *ClusterList, int nclusters, double cwpvalthresh, int *nPruned, MRIS *surf) +{ int n, nth, vtxno, map[10000]; SCS *scs; @@ -753,7 +775,8 @@ SCS *sclustPruneByCWPval(SCS *ClusterList, int nclusters, double cwpvalthresh, i // Remove clusters/values from surface surf->vertices[vtxno].undefval = 0; surf->vertices[vtxno].val = 0; - } else { + } + else { // Re-number surf->vertices[vtxno].undefval = map[n - 1] + 1; } @@ -766,7 +789,8 @@ SCS *sclustPruneByCWPval(SCS *ClusterList, int nclusters, double cwpvalthresh, i int sclustAnnot(MRIS *surf, int NClusters) Convert clusters into annotation ------------------------------------------------------------*/ -int sclustAnnot(MRIS *surf, int NClusters) { +int sclustAnnot(MRIS *surf, int NClusters) +{ COLOR_TABLE *ct; int vtxno, vtx_clusterno, annot, n; @@ -801,7 +825,8 @@ int sclustAnnot(MRIS *surf, int NClusters) { is a recursive function. Recursive calls will have the the vtxno >= 0, so set vtxno = -1 when you call this function. */ -int sclustGrowByDist(MRIS *surf, int seedvtxno, double dthresh, int shape, int vtxno, int *vtxlist) { +int sclustGrowByDist(MRIS *surf, int seedvtxno, double dthresh, int shape, int vtxno, int *vtxlist) +{ static double radius = 0, radius2 = 0; static int nhits = 0, ncalls = 0; static VERTEX *v1 = NULL; @@ -843,7 +868,8 @@ int sclustGrowByDist(MRIS *surf, int seedvtxno, double dthresh, int shape, int v theta = acos(costheta); d = radius * theta; // printf("%g %g %g %g\n",costheta,theta,radius,radius2); - } else { + } + else { d = sqrt((v1->x - v2->x) * (v1->x - v2->x) + (v1->y - v2->y) * (v1->y - v2->y)); } diff --git a/utils/svm.c b/utils/svm.c index 06ccb8cc9f7..aa235d355a5 100644 --- a/utils/svm.c +++ b/utils/svm.c @@ -48,7 +48,8 @@ static double svm_linear_dot(int ninputs, float *xi, float *xj); #if !USE_SVM_LIB static double SVMlagrangian(SVM *svm, int ntraining, float **x, float *y, double **dot_matrix); #endif -SVM *SVMalloc(int ninputs, char *c1_name, char *c2_name) { +SVM *SVMalloc(int ninputs, char *c1_name, char *c2_name) +{ SVM *svm; svm = (SVM *)calloc(1, sizeof(SVM)); @@ -65,7 +66,8 @@ SVM *SVMalloc(int ninputs, char *c1_name, char *c2_name) { } #if USE_SVM_LIB -int SVMtrain(SVM *svm, float **x, float *y, int ntraining, double C, double tol, int max_iter) { +int SVMtrain(SVM *svm, float **x, float *y, int ntraining, double C, double tol, int max_iter) +{ SVMparam *svmp; SVMreal **data, *alpha; int posCount, negCount, i, j, *indices, k; @@ -165,7 +167,8 @@ int SVMtrain(SVM *svm, float **x, float *y, int ntraining, double C, double tol, } #else -int SVMtrain(SVM *svm, float **x, float *y, int ntraining, double C, double tol, int max_iter) { +int SVMtrain(SVM *svm, float **x, float *y, int ntraining, double C, double tol, int max_iter) +{ int iter, i, j, k, Nsupport, *permutation, *moved, *failed, nmoved, dir, keep_alpha; double **dot_matrix, dot, step_size, L, Lold, Lprev, *da_old, da, b, constraint, ai, aj, dai, daj, min_step_size; @@ -267,7 +270,8 @@ int SVMtrain(SVM *svm, float **x, float *y, int ntraining, double C, double tol, break; } } - } else /* search from end */ + } + else /* search from end */ { for (j = ntraining - 1; j >= 0; j--) { if (failed[j] || moved[j]) continue; @@ -400,7 +404,8 @@ int SVMtrain(SVM *svm, float **x, float *y, int ntraining, double C, double tol, return (NO_ERROR); } -static double SVMlagrangian(SVM *svm, int ntraining, float **x, float *y, double **dot_matrix) { +static double SVMlagrangian(SVM *svm, int ntraining, float **x, float *y, double **dot_matrix) +{ int i, j; double L; @@ -415,7 +420,8 @@ static double SVMlagrangian(SVM *svm, int ntraining, float **x, float *y, double } #endif -int SVMwrite(SVM *svm, char *fname) { +int SVMwrite(SVM *svm, char *fname) +{ FILE *fp; int i, j; @@ -457,7 +463,8 @@ int SVMwrite(SVM *svm, char *fname) { return (NO_ERROR); } -SVM *SVMread(char *fname) { +SVM *SVMread(char *fname) +{ FILE *fp; int i, ninputs, retval, j, ntraining; SVM *svm; @@ -482,13 +489,17 @@ SVM *SVMread(char *fname) { retval = sscanf(cp, "%s", token); if (stricmp(token, "C") == 0) { retval = sscanf(cp, "%*s\t%lf", &svm->C); - } else if (stricmp(token, "SIGMA") == 0) { + } + else if (stricmp(token, "SIGMA") == 0) { retval = sscanf(cp, "%*s\t%lf", &svm->sigma); - } else if (stricmp(token, "NTRAINING") == 0) { + } + else if (stricmp(token, "NTRAINING") == 0) { retval = sscanf(cp, "%*s\t%d", &svm->ntraining); - } else if (stricmp(token, "TYPE") == 0) { + } + else if (stricmp(token, "TYPE") == 0) { retval = sscanf(cp, "%*s\t%d", &svm->type); - } else if (stricmp(token, "ALPHA") == 0) { + } + else if (stricmp(token, "ALPHA") == 0) { svm->alpha = (double *)calloc(svm->ntraining, sizeof(double)); if (svm->alpha == NULL) ErrorExit(ERROR_NOMEMORY, "SVMread(%s) - %d calloc failed", fname, svm->ntraining); @@ -496,7 +507,8 @@ SVM *SVMread(char *fname) { cp = fgetl(line, STRLEN - 1, fp); retval = sscanf(cp, "%le\n", &svm->alpha[i]); } - } else if (stricmp(token, "NEXTRA") == 0) { + } + else if (stricmp(token, "NEXTRA") == 0) { retval = sscanf(cp, "%*s\t%d", &svm->extra_args); svm->args = (char **)calloc(svm->extra_args, sizeof(char *)); if (!svm->args) ErrorExit(ERROR_BADPARM, "SVMread(%s): could not allocate %d extra args", svm->extra_args); @@ -508,9 +520,11 @@ SVM *SVMread(char *fname) { if (!svm->args[i]) ErrorExit(ERROR_BADPARM, "SVMread(%s): could not allocate %dth extra arg", i); strcpy(svm->args[i], cp); } - } else if (stricmp(token, "THRESHOLD") == 0) { + } + else if (stricmp(token, "THRESHOLD") == 0) { retval = sscanf(cp, "%*s\t%le", &svm->threshold); - } else if (stricmp(token, "NSUPPORT") == 0) { + } + else if (stricmp(token, "NSUPPORT") == 0) { retval = sscanf(cp, "%*s\t%d", &svm->nsupport); svm->asupport = (double *)calloc(svm->nsupport, sizeof(double)); svm->ysupport = (float *)calloc(svm->nsupport, sizeof(double)); @@ -521,11 +535,13 @@ SVM *SVMread(char *fname) { svm->xsupport[i] = (float *)calloc(svm->ninputs, sizeof(float)); for (j = 0; j < svm->ninputs; j++) retval = fscanf(fp, "%f\n", &svm->xsupport[i][j]); } - } else if (stricmp(token, "WEIGHTS") == 0) { + } + else if (stricmp(token, "WEIGHTS") == 0) { for (i = 0; i < svm->ninputs; i++) { retval = fscanf(fp, "%le\n", &svm->w[i]); } - } else if (stricmp(token, "SVM") == 0) { + } + else if (stricmp(token, "SVM") == 0) { #if USE_SVM_LIB SVMreadClassifierFromFile(fp, 0); #endif @@ -535,7 +551,8 @@ SVM *SVMread(char *fname) { fclose(fp); return (svm); } -int SVMfree(SVM **psvm) { +int SVMfree(SVM **psvm) +{ SVM *svm; int i; @@ -554,7 +571,8 @@ int SVMfree(SVM **psvm) { return (NO_ERROR); } -double SVMclassify(SVM *svm, float *x) { +double SVMclassify(SVM *svm, float *x) +{ int i; double classification, dot; #if USE_SMV_LIB @@ -587,7 +605,8 @@ double SVMclassify(SVM *svm, float *x) { return (classification); } -static double svm_linear_dot(int ninputs, float *xi, float *xj) { +static double svm_linear_dot(int ninputs, float *xi, float *xj) +{ int k; double dot; @@ -598,7 +617,8 @@ static double svm_linear_dot(int ninputs, float *xi, float *xj) { return (1 + dot); } -static double svm_rbf_dot(int ninputs, float *xi, float *xj, double sigma) { +static double svm_rbf_dot(int ninputs, float *xi, float *xj, double sigma) +{ int k; double norm, two_sigma_squared, xdiff, dot; @@ -611,7 +631,8 @@ static double svm_rbf_dot(int ninputs, float *xi, float *xj, double sigma) { dot = exp(-norm / two_sigma_squared); return (dot); } -double SVMconstraint(SVM *svm, float *y, int ntraining) { +double SVMconstraint(SVM *svm, float *y, int ntraining) +{ double constraint; int i; diff --git a/utils/tags.c b/utils/tags.c index 1d1b2e6161c..a3affe56369 100644 --- a/utils/tags.c +++ b/utils/tags.c @@ -31,7 +31,8 @@ #include "machine.h" #include "tags.h" -int TAGskip(FILE *fp, int tag, long long len) { +int TAGskip(FILE *fp, int tag, long long len) +{ #if 1 unsigned char *buf; int ret; @@ -46,7 +47,8 @@ int TAGskip(FILE *fp, int tag, long long len) { #endif } -int TAGreadStart(FILE *fp, long long *plen) { +int TAGreadStart(FILE *fp, long long *plen) +{ int tag; tag = freadInt(fp); @@ -69,7 +71,8 @@ int TAGreadStart(FILE *fp, long long *plen) { return (tag); } -int TAGwriteStart(FILE *fp, int tag, long long *phere, long long len) { +int TAGwriteStart(FILE *fp, int tag, long long *phere, long long len) +{ long here; fwriteInt(tag, fp); @@ -81,7 +84,8 @@ int TAGwriteStart(FILE *fp, int tag, long long *phere, long long len) { return (NO_ERROR); } -int TAGwrite(FILE *fp, int tag, void *buf, long long len) { +int TAGwrite(FILE *fp, int tag, void *buf, long long len) +{ long long here; TAGwriteStart(fp, tag, &here, len); @@ -90,7 +94,8 @@ int TAGwrite(FILE *fp, int tag, void *buf, long long len) { return (NO_ERROR); } -int TAGwriteEnd(FILE *fp, long long there) { +int TAGwriteEnd(FILE *fp, long long there) +{ long long here; here = ftell(fp); @@ -103,7 +108,8 @@ int TAGwriteEnd(FILE *fp, long long there) { return (NO_ERROR); } -int TAGmakeCommandLineString(int argc, char **argv, char *cmd_line) { +int TAGmakeCommandLineString(int argc, char **argv, char *cmd_line) +{ int i; cmd_line[0] = 0; @@ -114,7 +120,8 @@ int TAGmakeCommandLineString(int argc, char **argv, char *cmd_line) { return (NO_ERROR); } -int TAGwriteCommandLine(FILE *fp, char *cmd_line) { +int TAGwriteCommandLine(FILE *fp, char *cmd_line) +{ long long here; TAGwriteStart(fp, TAG_CMDLINE, &here, strlen(cmd_line) + 1); @@ -123,7 +130,8 @@ int TAGwriteCommandLine(FILE *fp, char *cmd_line) { return (NO_ERROR); } -int TAGwriteAutoAlign(FILE *fp, MATRIX *M) { +int TAGwriteAutoAlign(FILE *fp, MATRIX *M) +{ long long here; char buf[16 * 100]; long long len; @@ -155,7 +163,8 @@ int TAGwriteAutoAlign(FILE *fp, MATRIX *M) { return (NO_ERROR); } -MATRIX *TAGreadAutoAlign(FILE *fp) { +MATRIX *TAGreadAutoAlign(FILE *fp) +{ int c, r; char buf[1000]; MATRIX *M; @@ -172,7 +181,8 @@ MATRIX *TAGreadAutoAlign(FILE *fp) { /* zlib support */ -int znzTAGskip(znzFile fp, int tag, long long len) { +int znzTAGskip(znzFile fp, int tag, long long len) +{ #if 1 unsigned char *buf; int ret; @@ -187,7 +197,8 @@ int znzTAGskip(znzFile fp, int tag, long long len) { #endif } -int znzTAGreadStart(znzFile fp, long long *plen) { +int znzTAGreadStart(znzFile fp, long long *plen) +{ int tag; tag = znzreadInt(fp); @@ -211,7 +222,8 @@ int znzTAGreadStart(znzFile fp, long long *plen) { return (tag); } -int znzTAGwriteStart(znzFile fp, int tag, long long *phere, long long len) { +int znzTAGwriteStart(znzFile fp, int tag, long long *phere, long long len) +{ long here; znzwriteInt(tag, fp); @@ -228,7 +240,8 @@ int znzTAGwriteStart(znzFile fp, int tag, long long *phere, long long len) { because TAGwrite() does not do a byte order swap. Use znzTAGreadFloat() instead of znzreadFloatEx(). */ -int znzTAGwrite(znzFile fp, int tag, void *buf, long long len) { +int znzTAGwrite(znzFile fp, int tag, void *buf, long long len) +{ long long here; znzTAGwriteStart(fp, tag, &here, len); znzwrite(buf, sizeof(char), len, fp); @@ -236,7 +249,8 @@ int znzTAGwrite(znzFile fp, int tag, void *buf, long long len) { return (NO_ERROR); } -int znzTAGwriteEnd(znzFile fp, long long there) { +int znzTAGwriteEnd(znzFile fp, long long there) +{ long long here; here = znztell(fp); @@ -249,7 +263,8 @@ int znzTAGwriteEnd(znzFile fp, long long there) { return (NO_ERROR); } -int znzTAGwriteCommandLine(znzFile fp, char *cmd_line) { +int znzTAGwriteCommandLine(znzFile fp, char *cmd_line) +{ long long here; znzTAGwriteStart(fp, TAG_CMDLINE, &here, strlen(cmd_line) + 1); @@ -259,7 +274,8 @@ int znzTAGwriteCommandLine(znzFile fp, char *cmd_line) { } #define MATRIX_STRLEN (4 * 4 * 100) -int znzWriteMatrix(znzFile fp, MATRIX *M) { +int znzWriteMatrix(znzFile fp, MATRIX *M) +{ long long here, len; char buf[MATRIX_STRLEN]; @@ -297,7 +313,8 @@ int znzWriteMatrix(znzFile fp, MATRIX *M) { because it performs a byte order swap. Use znzTAGreadFloat() instead of znzreadFloatEx(). */ -int znzTAGreadFloat(float *pf, znzFile fp) { +int znzTAGreadFloat(float *pf, znzFile fp) +{ int ret; ret = znzreadFloatEx(pf, fp); #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -313,7 +330,8 @@ int znzTAGreadFloat(float *pf, znzFile fp) { this function includes a znzTAGreadStart() which is not included in znzReadAutoAlignMatrix() */ -MATRIX *znzReadMatrix(znzFile fp) { +MATRIX *znzReadMatrix(znzFile fp) +{ char buf[MATRIX_STRLEN]; MATRIX *M; char ch[100]; @@ -349,7 +367,8 @@ MATRIX *znzReadMatrix(znzFile fp) { return (M); } -int znzWriteAutoAlignMatrix(znzFile fp, MATRIX *M) { +int znzWriteAutoAlignMatrix(znzFile fp, MATRIX *M) +{ // This does not appear to be used long long here; char buf[16 * 100]; @@ -386,7 +405,8 @@ int znzWriteAutoAlignMatrix(znzFile fp, MATRIX *M) { \fn MATRIX *znzReadAutoAlignMatrix(znzFile fp) Compatible with znzWriteMatrix(znzFile fp, MATRIX *M) */ -MATRIX *znzReadAutoAlignMatrix(znzFile fp) { +MATRIX *znzReadAutoAlignMatrix(znzFile fp) +{ MATRIX *M; char buf[MATRIX_STRLEN]; diff --git a/utils/talairachex.c b/utils/talairachex.c index 5455133e293..a40741d0474 100644 --- a/utils/talairachex.c +++ b/utils/talairachex.c @@ -35,7 +35,8 @@ extern const char *Progname; #define V4_LOAD(v, x, y, z, r) (VECTOR_ELT(v, 1) = x, VECTOR_ELT(v, 2) = y, VECTOR_ELT(v, 3) = z, VECTOR_ELT(v, 4) = r); -int ModifyTalairachCRAS(MRI *mri_tal, const LTA *lta) { +int ModifyTalairachCRAS(MRI *mri_tal, const LTA *lta) +{ LT *tran = 0; // if lta is given if (lta != 0) { @@ -48,7 +49,8 @@ int ModifyTalairachCRAS(MRI *mri_tal, const LTA *lta) { mri_tal->c_r = tran->dst.c_r; mri_tal->c_a = tran->dst.c_a; mri_tal->c_s = tran->dst.c_s; - } else if (getenv("NO_AVERAGE305")) // if this is set + } + else if (getenv("NO_AVERAGE305")) // if this is set fprintf(stderr, "INFO: tal c_(r,a,s) not modified\n"); else { // use average_305 value @@ -60,9 +62,11 @@ int ModifyTalairachCRAS(MRI *mri_tal, const LTA *lta) { mri_tal->c_a = -16.51; mri_tal->c_s = 9.75; } - } else + } + else ErrorExit(ERROR_BADPARM, "%s: xfm passed is not of RAS-to-RAS type", Progname); - } else + } + else ErrorExit(ERROR_BADPARM, "%s: xfm has more than one xfrm", Progname); } // lta != 0 else { @@ -109,7 +113,8 @@ int ModifyTalairachCRAS(MRI *mri_tal, const LTA *lta) { //////////////////////////////////////////////////////////////////// // Matrix routines /////////////////////////////////////////////////////////////////// -MATRIX *MtalairachFromVoxel(MRI *mri_src, const LTA *lta) { +MATRIX *MtalairachFromVoxel(MRI *mri_src, const LTA *lta) +{ MATRIX *RASfromVoxel = 0; MATRIX *talRASfromVoxel = 0; RASfromVoxel = extract_i_to_r(mri_src); @@ -118,14 +123,16 @@ MATRIX *MtalairachFromVoxel(MRI *mri_src, const LTA *lta) { if (lta->type != LINEAR_RAS_TO_RAS) ErrorExit(ERROR_BADPARM, "lta must be RAS_TO_RAS transform"); talRASfromVoxel = MatrixMultiply(lta->xforms[0].m_L, RASfromVoxel, NULL); // allocate memory - } else // no transform. just copy + } + else // no transform. just copy talRASfromVoxel = MatrixCopy(RASfromVoxel, NULL); MatrixFree(&RASfromVoxel); return talRASfromVoxel; } -MATRIX *MtalVoxelFromVoxel(MRI *mri_src, const LTA *lta) { +MATRIX *MtalVoxelFromVoxel(MRI *mri_src, const LTA *lta) +{ MATRIX *talRASFromVoxel = 0; MATRIX *talVoxelFromTalRAS = 0; MATRIX *res; @@ -145,7 +152,8 @@ MATRIX *MtalVoxelFromVoxel(MRI *mri_src, const LTA *lta) { return res; } -MATRIX *MvoxelFromTalairach(MRI *mri_dst, const LTA *lta) { +MATRIX *MvoxelFromTalairach(MRI *mri_dst, const LTA *lta) +{ MATRIX *RASFromTalairach = 0; MATRIX *voxelFromRAS = 0; MATRIX *res = 0; @@ -160,7 +168,8 @@ MATRIX *MvoxelFromTalairach(MRI *mri_dst, const LTA *lta) { return res; } -MATRIX *MvoxelFromTalVoxel(MRI *mri_dst, const LTA *lta) { +MATRIX *MvoxelFromTalVoxel(MRI *mri_dst, const LTA *lta) +{ MATRIX *talairachFromTalVol = 0; MATRIX *voxelFromTalRAS = 0; MATRIX *res = 0; @@ -179,7 +188,8 @@ MATRIX *MvoxelFromTalVoxel(MRI *mri_dst, const LTA *lta) { return res; } -MATRIX *MRASFromTalVoxel(MRI *mri, const LTA *lta) { +MATRIX *MRASFromTalVoxel(MRI *mri, const LTA *lta) +{ MRI *mriTal = 0; MATRIX *talRASfromTalVoxel = 0; MATRIX *RASfromTalRAS = 0; @@ -200,7 +210,8 @@ MATRIX *MRASFromTalVoxel(MRI *mri, const LTA *lta) { } void TransformWithMatrix( - const MATRIX *mat, const double x, const double y, const double z, double *px, double *py, double *pz) { + const MATRIX *mat, const double x, const double y, const double z, double *px, double *py, double *pz) +{ #if 0 // VECTOR *src, *dst; static VECTOR *src__ = 0; @@ -247,7 +258,8 @@ void TransformWithMatrix( // point to point routines ////////////////////////////////////////////////////////////////////////////////// int MRIvoxelToTalairachEx( - MRI *mri_src, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt, const LTA *lta) { + MRI *mri_src, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt, const LTA *lta) +{ MATRIX *talairachFromVoxel = MtalairachFromVoxel(mri_src, lta); TransformWithMatrix(talairachFromVoxel, xv, yv, zv, pxt, pyt, pzt); @@ -258,7 +270,8 @@ int MRIvoxelToTalairachEx( // voxel -> RAS -> talairach RAS -> talairachVolume // mri must be the source volume int MRIvoxelToTalairachVoxelEx( - MRI *mri_src, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt, const LTA *lta) { + MRI *mri_src, double xv, double yv, double zv, double *pxt, double *pyt, double *pzt, const LTA *lta) +{ MATRIX *talVoxelFromVoxel = MtalVoxelFromVoxel(mri_src, lta); TransformWithMatrix(talVoxelFromVoxel, xv, yv, zv, pxt, pyt, pzt); @@ -269,7 +282,8 @@ int MRIvoxelToTalairachVoxelEx( // talairachRAS -> RAS -> voxel // needs the target non-tal volume int MRItalairachToVoxelEx( - MRI *mri_dst, double xt, double yt, double zt, double *pxv, double *pyv, double *pzv, const LTA *lta) { + MRI *mri_dst, double xt, double yt, double zt, double *pxv, double *pyv, double *pzv, const LTA *lta) +{ MATRIX *voxelFromTalairach = MvoxelFromTalairach(mri_dst, lta); TransformWithMatrix(voxelFromTalairach, xt, yt, zt, pxv, pyv, pzv); @@ -280,7 +294,8 @@ int MRItalairachToVoxelEx( // talairachVolume-> talairachRAS -> RAS // dst is the non-talairach volume int MRItalairachVoxelToWorldEx( - MRI *mri_dst, double xt, double yt, double zt, double *pxw, double *pyw, double *pzw, const LTA *lta) { + MRI *mri_dst, double xt, double yt, double zt, double *pxw, double *pyw, double *pzw, const LTA *lta) +{ MATRIX *RASfromTalVoxel = MRASFromTalVoxel(mri_dst, lta); TransformWithMatrix(RASfromTalVoxel, xt, yt, zt, pxw, pyw, pzw); @@ -290,7 +305,8 @@ int MRItalairachVoxelToWorldEx( // talairachVolume-> talairach RAS -> RAS -> voxel int MRItalairachVoxelToVoxelEx( - MRI *mri_dst, double xtv, double ytv, double ztv, double *pxv, double *pyv, double *pzv, const LTA *lta) { + MRI *mri_dst, double xtv, double ytv, double ztv, double *pxv, double *pyv, double *pzv, const LTA *lta) +{ MATRIX *voxelFromTalVoxel = MvoxelFromTalVoxel(mri_dst, lta); TransformWithMatrix(voxelFromTalVoxel, xtv, ytv, ztv, pxv, pyv, pzv); @@ -301,7 +317,8 @@ int MRItalairachVoxelToVoxelEx( //////////////////////////////////////////////////////////////////////////////// // volume to volume routines //////////////////////////////////////////////////////////////////////////////// -MRI *MRItoTalairachExInterp(MRI *mri_src, MRI *mri_tal, const LTA *lta, int interp) { +MRI *MRItoTalairachExInterp(MRI *mri_src, MRI *mri_tal, const LTA *lta, int interp) +{ MATRIX *voxToTalvoxel = MtalVoxelFromVoxel(mri_src, lta); fprintf(stderr, "voxel to talairach voxel transform\n"); MatrixPrint(stderr, voxToTalvoxel); @@ -315,7 +332,8 @@ MRI *MRItoTalairachExInterp(MRI *mri_src, MRI *mri_tal, const LTA *lta, int inte return (mri_tal); } // volume -> Talairach volume -MRI *MRItoTalairachEx(MRI *mri_src, MRI *mri_tal, const LTA *lta) { +MRI *MRItoTalairachEx(MRI *mri_src, MRI *mri_tal, const LTA *lta) +{ MATRIX *voxToTalvoxel = MtalVoxelFromVoxel(mri_src, lta); fprintf(stderr, "voxel to talairach voxel transform\n"); MatrixPrint(stderr, voxToTalvoxel); @@ -331,7 +349,8 @@ MRI *MRItoTalairachEx(MRI *mri_src, MRI *mri_tal, const LTA *lta) { // assumes mri contain xform // transform talairach volume into the dst volume -MRI *MRIfromTalairachEx(MRI *mri_tal, MRI *mri_dst, const LTA *lta) { +MRI *MRIfromTalairachEx(MRI *mri_tal, MRI *mri_dst, const LTA *lta) +{ MATRIX *talVoxelToVoxel = MvoxelFromTalVoxel(mri_dst, lta); fprintf(stderr, "talairach voxel to voxel transform\n"); MatrixPrint(stderr, talVoxelToVoxel); @@ -346,7 +365,8 @@ MRI *MRIfromTalairachEx(MRI *mri_tal, MRI *mri_dst, const LTA *lta) { } // extract a talairach plane at point (x,y,z) -MRI *MRIextractTalairachPlaneEx(MRI *mri_src, MRI *mri_dst, int orientation, int x, int y, int z, int wsize, LTA *lta) { +MRI *MRIextractTalairachPlaneEx(MRI *mri_src, MRI *mri_dst, int orientation, int x, int y, int z, int wsize, LTA *lta) +{ double e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int whalf, xk, yk, xi, yi, zi; double ex, ey, ez, x0, y0, z0; @@ -455,7 +475,8 @@ MRI *MRIextractTalairachPlaneEx(MRI *mri_src, MRI *mri_dst, int orientation, int } int MRIeraseTalairachPlaneNewEx( - MRI *mri, MRI *mri_mask, int orientation, int x, int y, int z, int wsize, int fill_val, LTA *lta) { + MRI *mri, MRI *mri_mask, int orientation, int x, int y, int z, int wsize, int fill_val, LTA *lta) +{ double e1_x, e1_y, e1_z, e2_x, e2_y, e2_z, xbase, ybase, zbase; int whalf, xk, yk, xi, yi, zi, xki, yki, x0, y0; double ex, ey, ez, xt0, yt0, zt0; diff --git a/utils/thread.c b/utils/thread.c index c4926eb53a0..a0eca890907 100644 --- a/utils/thread.c +++ b/utils/thread.c @@ -59,7 +59,8 @@ STRUCTURES ------------------------------------------------------------------------*/ -typedef struct { +typedef struct +{ char *name; int iMtid; /* machine specific id of this thread */ int iSusSignal; @@ -96,7 +97,8 @@ static int iMachineId = 0; 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadInit(int mid, int iMaxThr, int stacksize, int npriorities) { +int ThreadInit(int mid, int iMaxThr, int stacksize, int npriorities) +{ THREAD *thread; int iError; @@ -125,7 +127,8 @@ int ThreadInit(int mid, int iMaxThr, int stacksize, int npriorities) { 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadEnd(int iTid) { +int ThreadEnd(int iTid) +{ int iMtid; if (iTid >= iNthreads) return (ErrorSet(ERROR_NO_MEMORY, "ThreadEnd(%d) - invalid thread #\n", iTid)); @@ -148,7 +151,8 @@ int ThreadEnd(int iTid) { 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadStart(char *name, void (*func)(int iTid, void *parm), void *parm, int priority) { +int ThreadStart(char *name, void (*func)(int iTid, void *parm), void *parm, int priority) +{ int iMtid, iTid; THREAD *pthr; @@ -188,7 +192,8 @@ int ThreadStart(char *name, void (*func)(int iTid, void *parm), void *parm, int 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadSuspend(int iTid, int iSignal) { +int ThreadSuspend(int iTid, int iSignal) +{ int iMtid; THREAD *pthr; @@ -213,7 +218,8 @@ int ThreadSuspend(int iTid, int iSignal) { 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadResume(int iTid, int iSignal) { +int ThreadResume(int iTid, int iSignal) +{ THREAD *pthr; int iMtid; @@ -223,7 +229,8 @@ int ThreadResume(int iTid, int iSignal) { for (iTid = 0; iTid < iNthreads; iTid++) ThreadResume(iTid, iSignal); return (0); - } else { + } + else { if (iTid == TID_SELF) iTid = ThreadGetTid(); pthr = &pthrTable[iTid]; @@ -245,7 +252,8 @@ int ThreadResume(int iTid, int iSignal) { 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadSleep(int iTid, long usec) { +int ThreadSleep(int iTid, long usec) +{ int iMtid; if (iTid >= iNthreads) return (ErrorSet(ERROR_NO_MEMORY, "ThreadSleep(%d) - invalid thread #\n", iTid)); @@ -269,7 +277,8 @@ int ThreadSleep(int iTid, long usec) { 1 if the thread was woken up, 0 if not. ------------------------------------------------------------------------*/ -int ThreadSignal(int iTid, int iSignal) { +int ThreadSignal(int iTid, int iSignal) +{ THREAD *pthr; if (iTid >= iNthreads) return (ErrorSet(ERROR_NO_MEMORY, "ThreadSignal(%d) - invalid thread #\n", iTid)); @@ -280,7 +289,8 @@ int ThreadSignal(int iTid, int iSignal) { if (pthr->iSusSignal & iSignal) { ThreadResume(iTid, iSignal); return (1); - } else + } + else return (0); } /*------------------------------------------------------------------------ @@ -295,7 +305,8 @@ int ThreadSignal(int iTid, int iSignal) { 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadYield(void) { +int ThreadYield(void) +{ int iMtid, iTid; /* ThreadCheckMailbox() ;*/ @@ -318,14 +329,16 @@ int ThreadYield(void) { 0 on success, < 0 otherwise. ------------------------------------------------------------------------*/ -int ThreadEnqueue(int iTid, void *msg) { +int ThreadEnqueue(int iTid, void *msg) +{ THREAD *thr; if (iTid >= iNthreads) return (ErrorSet(ERROR_NO_MEMORY, "ThreadEnqueue(%d) - invalid thread #\n", iTid)); if (iTid == TID_ALL) { for (iTid = 0; iTid < iNthreads; iTid++) ThreadEnqueue(iTid, msg); - } else { + } + else { thr = &pthrTable[iTid]; if (msg) Qput(thr->inQ, msg); if (thr->iSusSignal & SIG_Q_PENDING) ThreadResume(iTid, SIG_Q_PENDING); @@ -346,7 +359,8 @@ int ThreadEnqueue(int iTid, void *msg) { head of the Q otherwise. ------------------------------------------------------------------------*/ -void *ThreadDequeue(int mode) { +void *ThreadDequeue(int mode) +{ int iTid; THREAD *thr; @@ -375,7 +389,8 @@ void *ThreadDequeue(int mode) { the TID on success (> 0), < 0 on error. ------------------------------------------------------------------------*/ -int ThreadGetTid(void) { +int ThreadGetTid(void) +{ int iMtid, iTid; iMtid = MachThreadGetTid(); @@ -417,7 +432,8 @@ int ThreadGetMid(void) { return (iMachineId); } the number of elements processed. ------------------------------------------------------------------------*/ -int ThreadCheckMailbox(void) { +int ThreadCheckMailbox(void) +{ MSG *msg; int iNcalls = 0; diff --git a/utils/timer.c b/utils/timer.c index b71f4b1d68f..6105739888d 100644 --- a/utils/timer.c +++ b/utils/timer.c @@ -29,7 +29,8 @@ #include "sys/timeb.h" #include "timer.h" -struct timeb *TimerStart(struct timeb *then) { +struct timeb *TimerStart(struct timeb *then) +{ /* according to the header ftime() is obsolete */ #if 0 ftime(then) ; @@ -44,7 +45,8 @@ struct timeb *TimerStart(struct timeb *then) { return then; } -int TimerStop(struct timeb *then) { +int TimerStop(struct timeb *then) +{ #if 0 struct timeb now ; int msec, now_msec, then_msec ; diff --git a/utils/transform.c b/utils/transform.c index a7f5adf5c2b..fb1419f546f 100644 --- a/utils/transform.c +++ b/utils/transform.c @@ -70,7 +70,8 @@ static LTA *ltaReadFileEx(const char *fname); \brief Copys lta to ltacp. If ltacp is NULL, allocs a new lta. If ltacp is not NULL, num_xforms must match that of lta. */ -LTA *LTAcopy(LTA *lta, LTA *ltacp) { +LTA *LTAcopy(LTA *lta, LTA *ltacp) +{ int i; if (ltacp == NULL) ltacp = LTAalloc(lta->num_xforms, NULL); @@ -94,7 +95,8 @@ LTA *LTAcopy(LTA *lta, LTA *ltacp) { \fn LINEAR_TRANSFORM *LTcopy(LT *lt, LT *ltcp) \brief Copys lt to ltcp. If ltcp cannot be NULL. */ -LINEAR_TRANSFORM *LTcopy(LT *lt, LT *ltcp) { +LINEAR_TRANSFORM *LTcopy(LT *lt, LT *ltcp) +{ if (ltcp == NULL) { printf("ERROR: LTcopy() destination LT cannot be NULL\n"); return (NULL); @@ -120,7 +122,8 @@ LINEAR_TRANSFORM *LTcopy(LT *lt, LT *ltcp) { registered. Returns 1 if different, 0 if the same. Does not check the inverse transform, subject, or other parameters. */ -int LTAdiff(LTA *lta1, LTA *lta2, double thresh) { +int LTAdiff(LTA *lta1, LTA *lta2, double thresh) +{ int i, ret, c, r, CheckInverse = 0; double d; @@ -189,7 +192,8 @@ int LTAdiff(LTA *lta1, LTA *lta2, double thresh) { return (ret); } -void vg_print(const VOL_GEOM *vg) { +void vg_print(const VOL_GEOM *vg) +{ if (vg->valid == 1) { fprintf(stderr, "volume geometry:\n"); fprintf(stderr, "extent : (%d, %d, %d)\n", vg->width, vg->height, vg->depth); @@ -199,7 +203,8 @@ void vg_print(const VOL_GEOM *vg) { fprintf(stderr, "z_(ras) : (%7.4f, %7.4f, %7.4f)\n", vg->z_r, vg->z_a, vg->z_s); fprintf(stderr, "c_(ras) : (%7.4f, %7.4f, %7.4f)\n", vg->c_r, vg->c_a, vg->c_s); fprintf(stderr, "file : %s\n", vg->fname); - } else + } + else fprintf(stderr, "volume geometry info is either not contained " "or not valid.\n"); @@ -208,7 +213,8 @@ void vg_print(const VOL_GEOM *vg) { // what should be the initialized value? // I guess make it the same as COR standard. -void initVolGeom(VOL_GEOM *vg) { +void initVolGeom(VOL_GEOM *vg) +{ vg->valid = 0; vg->width = 256; vg->height = 256; @@ -235,7 +241,8 @@ void initVolGeom(VOL_GEOM *vg) { \fn void getVolGeom(const MRI *src, VOL_GEOM *dst) \brief Copy Volume Geometry from MRI */ -void getVolGeom(const MRI *src, VOL_GEOM *dst) { +void getVolGeom(const MRI *src, VOL_GEOM *dst) +{ if (!src) ErrorExit(ERROR_BADPARM, "must have a valid MRI (src)"); if (!dst) ErrorExit(ERROR_BADPARM, "must have a valid VOL_GEOM (dst)"); @@ -265,7 +272,8 @@ void getVolGeom(const MRI *src, VOL_GEOM *dst) { \fn MRI *MRIallocFromVolGeom(VOL_GEOM *vg, int type, int nframes, int HeaderOnly) \brief Creates an MRI from a VOL_GEOM, copying the geometry info */ -MRI *MRIallocFromVolGeom(VOL_GEOM *vg, int type, int nframes, int HeaderOnly) { +MRI *MRIallocFromVolGeom(VOL_GEOM *vg, int type, int nframes, int HeaderOnly) +{ MRI *mri; if (HeaderOnly) mri = MRIallocHeader(vg->width, vg->height, vg->depth, type, nframes); @@ -279,7 +287,8 @@ MRI *MRIallocFromVolGeom(VOL_GEOM *vg, int type, int nframes, int HeaderOnly) { \fn void useVolGeomToMRI(const VOL_GEOM *src, MRI *dst) \brief Copy geometry info from VOL_GEOM to an MRI structure */ -void useVolGeomToMRI(const VOL_GEOM *src, MRI *dst) { +void useVolGeomToMRI(const VOL_GEOM *src, MRI *dst) +{ if (!src) ErrorExit(ERROR_BADPARM, "must have a valid VOL_GEOM (src)"); if (!dst) ErrorExit(ERROR_BADPARM, "must have a valid MRI (dst)"); @@ -308,20 +317,23 @@ void useVolGeomToMRI(const VOL_GEOM *src, MRI *dst) { MRIreInitCache(dst); } -int TransformCopyVolGeomToMRI(TRANSFORM *transform, MRI *mri) { +int TransformCopyVolGeomToMRI(TRANSFORM *transform, MRI *mri) +{ LTA *lta; GCA_MORPH *gcam; if (transform->type == MORPH_3D_TYPE) { gcam = (GCA_MORPH *)transform->xform; - } else { + } + else { lta = (LTA *)transform->xform; MRIcopyVolGeomToMRI(mri, <a->xforms[0].dst); } return (NO_ERROR); } -void copyVolGeom(const VOL_GEOM *src, VOL_GEOM *dst) { +void copyVolGeom(const VOL_GEOM *src, VOL_GEOM *dst) +{ dst->valid = src->valid; dst->width = src->width; dst->height = src->height; @@ -344,7 +356,8 @@ void copyVolGeom(const VOL_GEOM *src, VOL_GEOM *dst) { strcpy(dst->fname, src->fname); } -void writeVolGeom(FILE *fp, const VOL_GEOM *vg) { +void writeVolGeom(FILE *fp, const VOL_GEOM *vg) +{ if (vg->valid == 0) fprintf(fp, "valid = %d # volume info invalid\n", vg->valid); else @@ -358,7 +371,8 @@ void writeVolGeom(FILE *fp, const VOL_GEOM *vg) { fprintf(fp, "cras = %.15e %.15e %.15e\n", vg->c_r, vg->c_a, vg->c_s); } -void readVolGeom(FILE *fp, VOL_GEOM *vg) { +void readVolGeom(FILE *fp, VOL_GEOM *vg) +{ char line[256]; char param[64]; char eq[2]; @@ -375,29 +389,36 @@ void readVolGeom(FILE *fp, VOL_GEOM *vg) { sscanf(line, "%s %s %d \n", param, eq, &vg->valid); vgRead = 1; counter++; - } else if (!strcmp(param, "filename")) { + } + else if (!strcmp(param, "filename")) { if (sscanf(line, "%s %s %s\n", param, eq, buf) >= 3) { strcpy(vg->fname, buf); } counter++; - } else if (!strcmp(param, "volume")) { + } + else if (!strcmp(param, "volume")) { // rescan again sscanf(line, "%s %s %d %d %d\n", param, eq, &vg->width, &vg->height, &vg->depth); counter++; - } else if (!strcmp(param, "voxelsize")) { + } + else if (!strcmp(param, "voxelsize")) { // rescan again sscanf(line, "%s %s %f %f %f\n", param, eq, &vg->xsize, &vg->ysize, &vg->zsize); counter++; - } else if (!strcmp(param, "xras")) { + } + else if (!strcmp(param, "xras")) { sscanf(line, "%s %s %f %f %f\n", param, eq, &vg->x_r, &vg->x_a, &vg->x_s); counter++; - } else if (!strcmp(param, "yras")) { + } + else if (!strcmp(param, "yras")) { sscanf(line, "%s %s %f %f %f\n", param, eq, &vg->y_r, &vg->y_a, &vg->y_s); counter++; - } else if (!strcmp(param, "zras")) { + } + else if (!strcmp(param, "zras")) { sscanf(line, "%s %s %f %f %f\n", param, eq, &vg->z_r, &vg->z_a, &vg->z_s); counter++; - } else if (!strcmp(param, "cras")) { + } + else if (!strcmp(param, "cras")) { sscanf(line, "%s %s %f %f %f\n", param, eq, &vg->c_r, &vg->c_a, &vg->c_s); counter++; } @@ -417,7 +438,8 @@ void readVolGeom(FILE *fp, VOL_GEOM *vg) { } // scanner space vox2ras from vol geom -MATRIX *vg_i_to_r(const VOL_GEOM *vg) { +MATRIX *vg_i_to_r(const VOL_GEOM *vg) +{ MATRIX *mat = 0; MRI *tmp = 0; tmp = MRIallocHeader(vg->width, vg->height, vg->depth, MRI_UCHAR, 1); @@ -426,7 +448,8 @@ MATRIX *vg_i_to_r(const VOL_GEOM *vg) { MRIfree(&tmp); return mat; } -MATRIX *vg_r_to_i(const VOL_GEOM *vg) { +MATRIX *vg_r_to_i(const VOL_GEOM *vg) +{ MATRIX *mat = 0; MRI *tmp = 0; tmp = MRIallocHeader(vg->width, vg->height, vg->depth, MRI_UCHAR, 1); @@ -436,7 +459,8 @@ MATRIX *vg_r_to_i(const VOL_GEOM *vg) { return mat; } // tkregister space vox2ras from vol geom -MATRIX *TkrVox2RASfromVolGeom(const VOL_GEOM *vg) { +MATRIX *TkrVox2RASfromVolGeom(const VOL_GEOM *vg) +{ MATRIX *mat = NULL; MRI *tmp = 0; tmp = MRIallocHeader(vg->width, vg->height, vg->depth, MRI_UCHAR, 1); @@ -446,14 +470,16 @@ MATRIX *TkrVox2RASfromVolGeom(const VOL_GEOM *vg) { return (mat); } // tkregister space ras2vox from vol geom -MATRIX *TkrRAS2VoxfromVolGeom(const VOL_GEOM *vg) { +MATRIX *TkrRAS2VoxfromVolGeom(const VOL_GEOM *vg) +{ MATRIX *mat = NULL; mat = TkrVox2RASfromVolGeom(vg); mat = MatrixInverse(mat, mat); return (mat); } -int vg_isEqual(const VOL_GEOM *vg1, const VOL_GEOM *vg2) { +int vg_isEqual(const VOL_GEOM *vg1, const VOL_GEOM *vg2) +{ int rt; extern double vg_isEqual_Threshold; // rt = vg_isEqualThresh(vg1, vg2, FLT_EPSILON); @@ -464,7 +490,8 @@ int vg_isEqual(const VOL_GEOM *vg1, const VOL_GEOM *vg2) { return (0); } -int vg_isNotEqualThresh(const VOL_GEOM *vg1, const VOL_GEOM *vg2, const double thresh) { +int vg_isNotEqualThresh(const VOL_GEOM *vg1, const VOL_GEOM *vg2, const double thresh) +{ if (vg1->valid != vg2->valid) return (1); if (vg1->width != vg2->width) return (2); if (vg1->height != vg2->height) return (3); @@ -493,7 +520,8 @@ int vg_isNotEqualThresh(const VOL_GEOM *vg1, const VOL_GEOM *vg2, const double t Description ------------------------------------------------------*/ -LINEAR_TRANSFORM_ARRAY *LTAalloc(int nxforms, MRI *mri) { +LINEAR_TRANSFORM_ARRAY *LTAalloc(int nxforms, MRI *mri) +{ int i; LINEAR_TRANSFORM_ARRAY *lta; MRI_REGION bbox; @@ -504,7 +532,8 @@ LINEAR_TRANSFORM_ARRAY *LTAalloc(int nxforms, MRI *mri) { x0 = bbox.x + bbox.dx / 2; y0 = bbox.y + bbox.dy / 2; z0 = bbox.z + bbox.dz / 2; - } else + } + else x0 = y0 = z0 = 0; lta = (LINEAR_TRANSFORM_ARRAY *)calloc(1, sizeof(LTA)); @@ -548,7 +577,8 @@ LINEAR_TRANSFORM_ARRAY *LTAalloc(int nxforms, MRI *mri) { Description ------------------------------------------------------*/ -int LTAwrite(LTA *lta, const char *fname) { +int LTAwrite(LTA *lta, const char *fname) +{ return (LTAwriteEx(lta, fname)); #if 0 @@ -603,7 +633,8 @@ int LTAwrite(LTA *lta, const char *fname) { Description ------------------------------------------------------*/ -LTA *LTAread(const char *fname) { +LTA *LTAread(const char *fname) +{ int type; LTA *lta; MATRIX *V, *W, *m_tmp; @@ -695,7 +726,8 @@ LTA *LTAread(const char *fname) { Description ------------------------------------------------------*/ -static LTA *ltaReadFile(const char *fname) { +static LTA *ltaReadFile(const char *fname) +{ FILE *fp; LINEAR_TRANSFORM *lt; int i, nxforms, type, skip = 0; @@ -726,7 +758,8 @@ static LTA *ltaReadFile(const char *fname) { { sscanf(cp, "label = %d\n", <->label); skip = 0; - } else + } + else skip = 1; } fclose(fp); @@ -739,7 +772,8 @@ static LTA *ltaReadFile(const char *fname) { Description ------------------------------------------------------*/ -int LTAfree(LTA **plta) { +int LTAfree(LTA **plta) +{ LTA *lta; int i; @@ -768,7 +802,8 @@ int LTAfree(LTA **plta) { split each transform into 8 and space them evenly. ------------------------------------------------------*/ -int LTAdivide(LTA *lta, MRI *mri) { +int LTAdivide(LTA *lta, MRI *mri) +{ MRI_REGION bbox; int oldi, i, nxforms, row_size, x, y, z; LT *new_xforms, *lt; @@ -832,11 +867,13 @@ int LTAdivide(LTA *lta, MRI *mri) { Description Apply a transform array to an image. ------------------------------------------------------*/ -MRI *LTAtransform(MRI *mri_src, MRI *mri_dst, LTA *lta) { +MRI *LTAtransform(MRI *mri_src, MRI *mri_dst, LTA *lta) +{ return LTAtransformInterp(mri_src, mri_dst, lta, SAMPLE_TRILINEAR); } -MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { +MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) +{ int y1, y2, y3, width, height, depth, xi, yi, zi, f; VECTOR *v_X, *v_Y; /* original and transformed coordinate systems */ double x1, x2, x3; @@ -908,7 +945,8 @@ MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { MRIcopyHeader(mri_src, mri_dst); // make sure the geometry is taken from the transform, not from src: useVolGeomToMRI(&tran->dst, mri_dst); - } else if (getenv("USE_AVERAGE305")) { + } + else if (getenv("USE_AVERAGE305")) { fprintf(stderr, "INFO: Environmental variable " "USE_AVERAGE305 set\n"); @@ -930,7 +968,8 @@ MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { // do the following whenever // we change direction cosines MRIreInitCache(mri_dst); - } else { + } + else { fprintf(stderr, "INFO: Transform dst volume " "info is not used (valid flag = 0).\n"); @@ -947,7 +986,8 @@ MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { if (lta->type == LINEAR_RAS_TO_RAS) { // don't need any info from dst(in lta) only from mri_dst: return (MRIapplyRASlinearTransformInterp(mri_src, mri_dst, lta->xforms[0].m_L, interp)); - } else if (lta->type == LINEAR_VOX_TO_VOX) // vox-to-vox + } + else if (lta->type == LINEAR_VOX_TO_VOX) // vox-to-vox { // convert to ras_to_ras using xforms from lta if available // this strips geometry information and allows to use the @@ -956,7 +996,8 @@ MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { // we use the geometry from the passed source and target image if (lta->xforms[0].dst.valid) { i2r = vg_i_to_r(<a->xforms[0].dst); // allocated - } else { + } + else { fprintf(stderr, "INFO: LTA dst geometry information missing!\n" " We assume that the dst volume passed is the\n" @@ -966,7 +1007,8 @@ MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { tmp = MatrixMultiply(i2r, lta->xforms[0].m_L, NULL); if (lta->xforms[0].src.valid) { r2i = vg_r_to_i(<a->xforms[0].src); // allocated - } else { + } + else { fprintf(stderr, "INFO: LTA src geometry information missing!\n" " We assume that the src volume passed is the\n" @@ -1006,11 +1048,13 @@ MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { return(MRIlinearTransformInterp(mri_src, mri_dst, lta->xforms[0].m_L, interp)) ; }*/ - } else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { + } + else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { // must have both transform src and dst geometry information LTAchangeType(lta, LINEAR_RAS_TO_RAS); return (MRIapplyRASlinearTransformInterp(mri_src, mri_dst, lta->xforms[0].m_L, interp)); - } else + } + else ErrorExit(ERROR_BADPARM, "LTAtransform: unknown linear transform\n"); } fprintf(stderr, "applying octree transform to image...\n"); @@ -1082,7 +1126,8 @@ MRI *LTAtransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { return (mri_dst); } -MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) { +MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) +{ int y1, y2, y3, width, height, depth, xi, yi, zi, f; VECTOR *v_X, *v_Y; /* original and transformed coordinate systems */ double x1, x2, x3; @@ -1149,7 +1194,8 @@ MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) // the following whenever // we change direction cosines MRIreInitCache(mri_dst); - } else if (getenv("USE_AVERAGE305")) { + } + else if (getenv("USE_AVERAGE305")) { fprintf(stderr, "INFO: Environmental variable " "USE_AVERAGE305 set\n"); @@ -1164,7 +1210,8 @@ MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) // do the following whenever // we change direction cosines MRIreInitCache(mri_dst); - } else + } + else fprintf(stderr, "INFO: Transform dst volume " "info is not used (valid flag = 0).\n"); @@ -1173,7 +1220,8 @@ MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) if (lta->type == LINEAR_RAS_TO_RAS) { // don't need any info from dst return (MRIapplyRASlinearTransformInterp(mri_src, mri_dst, lta->inv_xforms[0].m_L, interp)); - } else if (lta->type == LINEAR_VOX_TO_VOX) // vox-to-vox + } + else if (lta->type == LINEAR_VOX_TO_VOX) // vox-to-vox { // convert to ras_to_ras using xforms from lta if available // this strips geometry information and allows to use the @@ -1183,7 +1231,8 @@ MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) // WARNING: adoped from above, not tested here (using inv) if (lta->inv_xforms[0].dst.valid) { i2r = vg_i_to_r(<a->inv_xforms[0].dst); // allocated - } else { + } + else { fprintf(stderr, "INFO: LTA inv dst geometry information missing!\n" " We assume that the dst volume passed is the\n" @@ -1193,7 +1242,8 @@ MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) tmp = MatrixMultiply(i2r, lta->inv_xforms[0].m_L, NULL); if (lta->inv_xforms[0].src.valid) { r2i = vg_r_to_i(<a->inv_xforms[0].src); // allocated - } else { + } + else { fprintf(stderr, "INFO: LTA inv src geometry information missing!\n" " We assume that the src volume passed is the\n" @@ -1233,11 +1283,13 @@ MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) return(MRIlinearTransformInterp(mri_src, mri_dst, lta->inv_xforms[0].m_L, interp)) ; }*/ - } else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { + } + else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { // must have both transform src and dst geometry information LTAchangeType(lta, LINEAR_RAS_TO_RAS); return (MRIapplyRASlinearTransformInterp(mri_src, mri_dst, lta->inv_xforms[0].m_L, interp)); - } else + } + else ErrorExit(ERROR_BADPARM, "LTAtransform: unknown linear transform\n"); } fprintf(stderr, "applying octree transform to image...\n"); @@ -1314,7 +1366,8 @@ MRI *LTAinverseTransformInterp(MRI *mri_src, MRI *mri_dst, LTA *lta, int interp) Description ------------------------------------------------------*/ -MATRIX *LTAtransformAtPoint(LTA *lta, float x, float y, float z, MATRIX *m_L) { +MATRIX *LTAtransformAtPoint(LTA *lta, float x, float y, float z, MATRIX *m_L) +{ LT *lt; int i; double w_p[MAX_TRANSFORMS], wtotal, dsq, sigma, dx, dy, dz, w_k_p, wmin; @@ -1366,7 +1419,8 @@ MATRIX *LTAtransformAtPoint(LTA *lta, float x, float y, float z, MATRIX *m_L) { Description ------------------------------------------------------*/ -MATRIX *LTAinverseTransformAtPoint(LTA *lta, float x, float y, float z, MATRIX *m_L) { +MATRIX *LTAinverseTransformAtPoint(LTA *lta, float x, float y, float z, MATRIX *m_L) +{ LT *lt; int i; double w_p[MAX_TRANSFORMS], wtotal, dsq, sigma, dx, dy, dz, w_k_p, wmin; @@ -1394,7 +1448,8 @@ MATRIX *LTAinverseTransformAtPoint(LTA *lta, float x, float y, float z, MATRIX * if (lta->num_xforms == 1) { m_L = MatrixInverse(lta->xforms[0].m_L, NULL); - } else { + } + else { if (DZERO(wtotal)) /* no transforms in range??? */ MatrixIdentity(4, m_L); else /* now calculate linear combination of transforms at this point */ @@ -1423,7 +1478,8 @@ MATRIX *LTAinverseTransformAtPoint(LTA *lta, float x, float y, float z, MATRIX * Description ------------------------------------------------------*/ -VECTOR *LTAtransformPoint(LTA *lta, VECTOR *v_X, VECTOR *v_Y) { +VECTOR *LTAtransformPoint(LTA *lta, VECTOR *v_X, VECTOR *v_Y) +{ static MATRIX *m_L = NULL; m_L = LTAtransformAtPoint(lta, V3_X(v_X), V3_Y(v_X), V3_Z(v_X), m_L); @@ -1437,7 +1493,8 @@ VECTOR *LTAtransformPoint(LTA *lta, VECTOR *v_X, VECTOR *v_Y) { Description ------------------------------------------------------*/ -VECTOR *LTAinverseTransformPoint(LTA *lta, VECTOR *v_X, VECTOR *v_Y) { +VECTOR *LTAinverseTransformPoint(LTA *lta, VECTOR *v_X, VECTOR *v_Y) +{ static MATRIX *m_L = NULL; m_L = LTAinverseTransformAtPoint(lta, V3_X(v_X), V3_Y(v_X), V3_Z(v_X), m_L); @@ -1453,7 +1510,8 @@ VECTOR *LTAinverseTransformPoint(LTA *lta, VECTOR *v_X, VECTOR *v_Y) { Same as LTAtransformPoint but also return weight normalization factor. ------------------------------------------------------*/ -double LTAtransformPointAndGetWtotal(LTA *lta, VECTOR *v_X, VECTOR *v_Y) { +double LTAtransformPointAndGetWtotal(LTA *lta, VECTOR *v_X, VECTOR *v_Y) +{ LT *lt; int i; double w_p[MAX_TRANSFORMS], wtotal, dsq, sigma, dx, dy, dz, w_k_p, wmin, x, y, z; @@ -1500,7 +1558,8 @@ double LTAtransformPointAndGetWtotal(LTA *lta, VECTOR *v_X, VECTOR *v_Y) { return (wtotal); } /*-----------------------------------------------------*/ -int TransformFileNameType(const char *fname) { +int TransformFileNameType(const char *fname) +{ int file_type = TRANSFORM_ARRAY_TYPE; char *dot, buf[500], *number; @@ -1537,7 +1596,8 @@ int TransformFileNameType(const char *fname) { return (file_type); } -static int ltaFSLwrite(const LTA *lta, const char *fname) { +static int ltaFSLwrite(const LTA *lta, const char *fname) +{ FILE *fp; MATRIX *m_L; @@ -1571,7 +1631,8 @@ static int ltaFSLwrite(const LTA *lta, const char *fname) { #include "minc_volume_io.h" -static int ltaMNIwrite(const LTA *lta, const char *fname) { +static int ltaMNIwrite(const LTA *lta, const char *fname) +{ FILE *fp; int row; MATRIX *m_L; @@ -1599,7 +1660,8 @@ static int ltaMNIwrite(const LTA *lta, const char *fname) { if (row == 3) fprintf(fp, ";"); fprintf(fp, "\n"); } - } else if (lta->type == LINEAR_VOX_TO_VOX) { + } + else if (lta->type == LINEAR_VOX_TO_VOX) { // we use src and dst info to create RAS_TO_RAS xfm MATRIX *voxFromRAS = 0; MATRIX *rasFromVoxel = 0; @@ -1637,7 +1699,8 @@ static int ltaMNIwrite(const LTA *lta, const char *fname) { fclose(fp); return (NO_ERROR); } -static LTA *ltaMNIread(const char *fname) { +static LTA *ltaMNIread(const char *fname) +{ LTA *lta; LINEAR_TRANSFORM *lt; char *cp, line[1000]; @@ -1688,7 +1751,8 @@ static LTA *ltaMNIread(const char *fname) { Description ------------------------------------------------------*/ -int LTAworldToWorld(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) { +int LTAworldToWorld(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) +{ static VECTOR *v_X, *v_Y = NULL; if (v_Y == NULL) { @@ -1731,7 +1795,8 @@ int LTAworldToWorld(LTA *lta, float x, float y, float z, float *px, float *py, f This is the same as LTAworldToWorld but doesn't do the weird (and mostly incorrect) voxel conversion. ------------------------------------------------------*/ -int LTAworldToWorldEx(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) { +int LTAworldToWorldEx(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) +{ static VECTOR *v_X, *v_Y = NULL; if (v_Y == NULL) { @@ -1759,7 +1824,8 @@ int LTAworldToWorldEx(LTA *lta, float x, float y, float z, float *px, float *py, Description ------------------------------------------------------*/ -int LTAinverseWorldToWorld(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) { +int LTAinverseWorldToWorld(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) +{ static VECTOR *v_X, *v_Y = NULL; if (v_Y == NULL) { @@ -1782,7 +1848,8 @@ int LTAinverseWorldToWorld(LTA *lta, float x, float y, float z, float *px, float return (NO_ERROR); } -int LTAinverseWorldToWorldEx(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) { +int LTAinverseWorldToWorldEx(LTA *lta, float x, float y, float z, float *px, float *py, float *pz) +{ static VECTOR *v_X, *v_Y = NULL; if (v_Y == NULL) { @@ -1806,7 +1873,8 @@ int LTAinverseWorldToWorldEx(LTA *lta, float x, float y, float z, float *px, flo } // this assumes that lta was ras to ras -int LTAtoVoxelCoords(LTA *lta, MRI *mri) { +int LTAtoVoxelCoords(LTA *lta, MRI *mri) +{ MATRIX *m_L; int i; @@ -1819,7 +1887,8 @@ int LTAtoVoxelCoords(LTA *lta, MRI *mri) { return (NO_ERROR); } -int LTAvoxelToRasXform(LTA *lta, MRI *mri_src, MRI *mri_dst) { +int LTAvoxelToRasXform(LTA *lta, MRI *mri_src, MRI *mri_dst) +{ MATRIX *m_L; int i; @@ -1833,7 +1902,8 @@ int LTAvoxelToRasXform(LTA *lta, MRI *mri_src, MRI *mri_dst) { MatrixFree(&m_tmp); MatrixFree(&m_dst_v2r); MatrixFree(&m_source_r2v); - } else { + } + else { m_L = MRIvoxelXformToRasXform(mri_src, mri_dst, lta->xforms[i].m_L, NULL); } MatrixFree(<a->xforms[i].m_L); @@ -1844,7 +1914,8 @@ int LTAvoxelToRasXform(LTA *lta, MRI *mri_src, MRI *mri_dst) { return (NO_ERROR); } -int LTArasToVoxelXform(LTA *lta, MRI *mri_src, MRI *mri_dst) { +int LTArasToVoxelXform(LTA *lta, MRI *mri_src, MRI *mri_dst) +{ MATRIX *m_L; int i; @@ -1859,7 +1930,8 @@ int LTArasToVoxelXform(LTA *lta, MRI *mri_src, MRI *mri_dst) { lta->type = LINEAR_VOX_TO_VOX; return (NO_ERROR); } -int LTAvoxelTransformToCoronalRasTransform(LTA *lta) { +int LTAvoxelTransformToCoronalRasTransform(LTA *lta) +{ MATRIX *V, *W, *m_tmp; V = MatrixAlloc(4, 4, MATRIX_REAL); /* world to voxel transform */ @@ -1895,14 +1967,16 @@ int LTAvoxelTransformToCoronalRasTransform(LTA *lta) { based on Matthew Brett's 10/8/98 transform. See http://www.mrc-cbu.cam.ac.uk/Imaging/mnispace.html -----------------------------------------------------------*/ -int FixMNITal(float xmni, float ymni, float zmni, float *xtal, float *ytal, float *ztal) { +int FixMNITal(float xmni, float ymni, float zmni, float *xtal, float *ytal, float *ztal) +{ MATRIX *T, *xyzMNI, *xyzTal; T = MatrixAlloc(4, 4, MATRIX_REAL); if (zmni >= 0.0) { stuff_four_by_four( T, .9900, .0000, .0000, 0, .0000, .9688, .0460, 0, .0000, -.0485, .9189, 0, .0000, .0000, .0000, 1); - } else { + } + else { stuff_four_by_four( T, .9900, .0000, .0000, 0, .0000, .9688, .0420, 0, .0000, -.0485, .8390, 0, .0000, .0000, .0000, 1); } @@ -1937,11 +2011,13 @@ int FixMNITal(float xmni, float ymni, float zmni, float *xtal, float *ytal, floa Note: uses LTAvoxelTransformToCoronalRasTransform(). -----------------------------------------------------------------*/ -MATRIX *DevolveXFM(const char *subjid, MATRIX *XFM, const char *xfmname) { +MATRIX *DevolveXFM(const char *subjid, MATRIX *XFM, const char *xfmname) +{ return (DevolveXFMWithSubjectsDir(subjid, XFM, xfmname, NULL)); } -MATRIX *DevolveXFMWithSubjectsDir(const char *subjid, MATRIX *XFM, const char *xfmname, const char *sdir) { +MATRIX *DevolveXFMWithSubjectsDir(const char *subjid, MATRIX *XFM, const char *xfmname, const char *sdir) +{ MATRIX *Torig_tkreg, *invTorig_tkreg, *Torig_native, *Mfix; char dirname[2000], xfmpath[2000]; const char *sd; @@ -1979,14 +2055,16 @@ MATRIX *DevolveXFMWithSubjectsDir(const char *subjid, MATRIX *XFM, const char *x if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) printf("Trying %s\n", dirname); if (fio_FileExistsReadable(dirname)) { mriorig = MRIreadHeader(dirname, MRI_MGH_FILE); - } else + } + else mriorig = NULL; if (mriorig == NULL) { sprintf(dirname, "%s/%s/mri/orig", sd, subjid); if (Gdiag & DIAG_SHOW && DIAG_VERBOSE_ON) printf("Trying %s\n", dirname); if (fio_IsDirectory(dirname)) { mriorig = MRIreadHeader(dirname, MRI_CORONAL_SLICE_DIRECTORY); - } else + } + else mriorig = NULL; if (mriorig == NULL) { printf("ERROR: could not read header for %s\n", dirname); @@ -2032,7 +2110,8 @@ MATRIX *DevolveXFMWithSubjectsDir(const char *subjid, MATRIX *XFM, const char *x return (XFM); } /*----------------------------------------------------------------*/ -TRANSFORM *TransformRead(const char *fname) { +TRANSFORM *TransformRead(const char *fname) +{ TRANSFORM *trans; GCA_MORPH *gcam = NULL; char fname_no_path[STRLEN]; @@ -2082,7 +2161,8 @@ TRANSFORM *TransformRead(const char *fname) { return (trans); } -int TransformFree(TRANSFORM **ptrans) { +int TransformFree(TRANSFORM **ptrans) +{ int errCode = NO_ERROR; TRANSFORM *trans; @@ -2113,7 +2193,8 @@ int TransformFree(TRANSFORM **ptrans) { the gca/gcamorph. */ // no range check is done here. user must validate the range -int TransformSample(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) { +int TransformSample(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) +{ static VECTOR *v_input, *v_canon = NULL; float xt, yt, zt; LTA *lta; @@ -2161,7 +2242,8 @@ int TransformSample(TRANSFORM *transform, float xv, float yv, float zv, float *p xt = (float)xd * gcam->spacing; yt = (float)yd * gcam->spacing; zt = (float)zd * gcam->spacing; - } else { + } + else { lta = (LTA *)transform->xform; if (lta->type != LINEAR_VOXEL_TO_VOXEL) { int i; @@ -2199,7 +2281,8 @@ int TransformSample(TRANSFORM *transform, float xv, float yv, float zv, float *p return errCode; } -int TransformSampleReal(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) { +int TransformSampleReal(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) +{ static VECTOR *v_input, *v_canon = NULL; float xt, yt, zt; LTA *lta; @@ -2227,7 +2310,8 @@ int TransformSampleReal(TRANSFORM *transform, float xv, float yv, float zv, floa xt = MRIgetVoxVal(gcam->mri_xind, xi, yi, zi, 0) * gcam->spacing; yt = MRIgetVoxVal(gcam->mri_yind, xi, yi, zi, 0) * gcam->spacing; zt = MRIgetVoxVal(gcam->mri_zind, xi, yi, zi, 0) * gcam->spacing; - } else { + } + else { lta = (LTA *)transform->xform; if (lta->type != LINEAR_VOXEL_TO_VOXEL) { int i; @@ -2270,7 +2354,8 @@ int TransformSampleReal(TRANSFORM *transform, float xv, float yv, float zv, floa } // with interpolation -int TransformSampleReal2(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) { +int TransformSampleReal2(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) +{ static VECTOR *v_input, *v_canon = NULL; // float xt, yt, zt ; double xt, yt, zt; @@ -2306,7 +2391,8 @@ int TransformSampleReal2(TRANSFORM *transform, float xv, float yv, float zv, flo xt *= gcam->spacing; yt *= gcam->spacing; zt *= gcam->spacing; - } else { + } + else { lta = (LTA *)transform->xform; if (lta->type != LINEAR_VOXEL_TO_VOXEL) { int i; @@ -2352,7 +2438,8 @@ int TransformSampleReal2(TRANSFORM *transform, float xv, float yv, float zv, flo take a voxel in gca/gcamorph space and find the MRI voxel to which it maps */ -int TransformSampleInverse(TRANSFORM *transform, int xv, int yv, int zv, float *px, float *py, float *pz) { +int TransformSampleInverse(TRANSFORM *transform, int xv, int yv, int zv, float *px, float *py, float *pz) +{ static VECTOR *v_input, *v_canon = NULL; static MATRIX *m_L_inv; float xt, yt, zt; @@ -2381,7 +2468,8 @@ int TransformSampleInverse(TRANSFORM *transform, int xv, int yv, int zv, float * zt = gcamn->z; // if marked invalid, then return error if (gcamn->invalid) errCode = ERROR_BADPARM; - } else { + } + else { lta = (LTA *)transform->xform; if (lta->type != LINEAR_VOXEL_TO_VOXEL) { int i; @@ -2424,7 +2512,8 @@ int TransformSampleInverse(TRANSFORM *transform, int xv, int yv, int zv, float * return errCode; } -int TransformSampleInverseFloat(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) { +int TransformSampleInverseFloat(TRANSFORM *transform, float xv, float yv, float zv, float *px, float *py, float *pz) +{ static VECTOR *v_input, *v_canon = NULL; static MATRIX *m_L_inv; float xt, yt, zt; @@ -2455,7 +2544,8 @@ int TransformSampleInverseFloat(TRANSFORM *transform, float xv, float yv, float zt = gcamn->z; // if marked invalid, then return error if (gcamn->invalid) errCode = ERROR_BADPARM; - } else { + } + else { lta = (LTA *)transform->xform; if (lta->type != LINEAR_VOXEL_TO_VOXEL) { int i; @@ -2498,7 +2588,8 @@ int TransformSampleInverseFloat(TRANSFORM *transform, float xv, float yv, float return errCode; } int TransformSampleInverseVoxel( - TRANSFORM *transform, int width, int height, int depth, int xv, int yv, int zv, int *px, int *py, int *pz) { + TRANSFORM *transform, int width, int height, int depth, int xv, int yv, int zv, int *px, int *py, int *pz) +{ float xf, yf, zf; int errCode = NO_ERROR; @@ -2538,7 +2629,8 @@ int TransformSampleInverseVoxel( return errCode; } -TRANSFORM *TransformAlloc(int type, MRI *mri) { +TRANSFORM *TransformAlloc(int type, MRI *mri) +{ TRANSFORM *transform; switch (type) { @@ -2554,13 +2646,15 @@ TRANSFORM *TransformAlloc(int type, MRI *mri) { return (transform); } -int TransformSwapInverse(TRANSFORM *transform) { +int TransformSwapInverse(TRANSFORM *transform) +{ LT *lt; LTA *lta; if (transform->type == MORPH_3D_TYPE) { ErrorReturn(ERROR_UNSUPPORTED, (ERROR_UNSUPPORTED, "TransformSwapInverse: MORPH_3D_TYPE not supported")); - } else { + } + else { lta = (LTA *)(transform->xform); lt = lta->xforms; lta->xforms = lta->inv_xforms; @@ -2569,7 +2663,8 @@ int TransformSwapInverse(TRANSFORM *transform) { return (NO_ERROR); } -int TransformInvert(TRANSFORM *transform, MRI *mri) { +int TransformInvert(TRANSFORM *transform, MRI *mri) +{ LTA *lta; GCA_MORPH *gcam; @@ -2596,7 +2691,8 @@ int TransformInvert(TRANSFORM *transform, MRI *mri) { } return (NO_ERROR); } -MRI *TransformApplyType(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst, int interp_type) { +MRI *TransformApplyType(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst, int interp_type) +{ LTA *lta = 0; switch (transform->type) { case MORPH_3D_TYPE: @@ -2613,7 +2709,8 @@ MRI *TransformApplyType(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst, int in return (mri_dst); } -MRI *TransformApply(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { +MRI *TransformApply(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) +{ LTA *lta = 0; switch (transform->type) { case MORPH_3D_TYPE: @@ -2633,7 +2730,8 @@ MRI *TransformApply(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { return (mri_dst); } -MRI *TransformApplyInverse(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { +MRI *TransformApplyInverse(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) +{ LTA *lta = 0; switch (transform->type) { case MORPH_3D_TYPE: @@ -2650,7 +2748,8 @@ MRI *TransformApplyInverse(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { } return (mri_dst); } -MRI *TransformApplyInverseType(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst, int interp_type) { +MRI *TransformApplyInverseType(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst, int interp_type) +{ LTA *lta = 0; switch (transform->type) { case MORPH_3D_TYPE: @@ -2668,7 +2767,8 @@ MRI *TransformApplyInverseType(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst, } #include "stats.h" -LTA *ltaReadRegisterDat(const char *fname, const char *mov, const char *ref) { +LTA *ltaReadRegisterDat(const char *fname, const char *mov, const char *ref) +{ LTA *lta; char *tmpstr; float ipr, bpr; @@ -2697,7 +2797,8 @@ LTA *ltaReadRegisterDat(const char *fname, const char *mov, const char *ref) { if (mritmp == NULL) return (NULL); getVolGeom(mritmp, <a->xforms[0].src); MRIfree(&mritmp); - } else { + } + else { // at least set what is known lta->xforms[0].src.valid = 0; lta->xforms[0].src.xsize = ipr; @@ -2710,7 +2811,8 @@ LTA *ltaReadRegisterDat(const char *fname, const char *mov, const char *ref) { if (mritmp == NULL) return (NULL); getVolGeom(mritmp, <a->xforms[0].dst); MRIfree(&mritmp); - } else { + } + else { lta->xforms[0].dst.valid = 0; lta->xforms[0].dst.xsize = 1; lta->xforms[0].dst.ysize = 1; @@ -2728,7 +2830,8 @@ LTA *ltaReadRegisterDat(const char *fname, const char *mov, const char *ref) { // find volumes which created the transform. // if buffer == NULL, then it will allocate memory // parsing with strtok. not thread safe. -int mincFindVolume(const char *line, const char *line2, char **srcVol, char **dstVol) { +int mincFindVolume(const char *line, const char *line2, char **srcVol, char **dstVol) +{ static int count = 0; char buf[1024]; char *pch; @@ -2774,7 +2877,8 @@ int mincFindVolume(const char *line, const char *line2, char **srcVol, char **ds *srcVol = (char *)malloc(strlen(pch) + 1); strcpy(*srcVol, pch); if (DIAG_VERBOSE_ON) fprintf(stdout, "INFO: Src volume %s\n", *srcVol); - } else if (count == 1) + } + else if (count == 1) // this is the second one must be dest volume { *dstVol = (char *)malloc(strlen(pch) + 1); @@ -2786,7 +2890,8 @@ int mincFindVolume(const char *line, const char *line2, char **srcVol, char **ds } pch = strtok(NULL, " "); } - } else // let us assume MINC GUI transform + } + else // let us assume MINC GUI transform { pch = strtok((char *)line, " "); // points to %Volume pch = strtok(NULL, " "); // now points to filename @@ -2815,7 +2920,8 @@ int mincFindVolume(const char *line, const char *line2, char **srcVol, char **ds if (DIAG_VERBOSE_ON) fprintf(stdout, "INFO: Target volume %s\n", *dstVol); } } - } else { + } + else { // now MGH way line has %Generated by ... src ... dst ... pch = strtok((char *)line, " "); while (pch != NULL) { @@ -2827,7 +2933,8 @@ int mincFindVolume(const char *line, const char *line2, char **srcVol, char **ds *srcVol = (char *)malloc(strlen(pch) + 1); strcpy(*srcVol, pch); if (DIAG_VERBOSE_ON) fprintf(stdout, "INFO: Src volume %s\n", *srcVol); - } else if (strstr(buf, "dst")) { + } + else if (strstr(buf, "dst")) { // get next token pch = strtok(NULL, " "); *dstVol = (char *)malloc(strlen(pch) + 1); @@ -2844,7 +2951,8 @@ int mincFindVolume(const char *line, const char *line2, char **srcVol, char **ds } // find the volume and get the information -void mincGetVolumeInfo(const char *srcVol, VOL_GEOM *vgSrc) { +void mincGetVolumeInfo(const char *srcVol, VOL_GEOM *vgSrc) +{ MRI *mri = 0; struct stat stat_buf; int ret; @@ -2878,12 +2986,14 @@ void mincGetVolumeInfo(const char *srcVol, VOL_GEOM *vgSrc) { vgSrc->c_a = -16.5100; vgSrc->c_s = 9.7500; vgSrc->valid = 1; - } else { + } + else { // printf("INFO: Set Volume %s to the // standard COR type.\n", srcVol); initVolGeom(vgSrc); // valid = 0; so no need to give info } - } else // file exists + } + else // file exists { // note that both mri volume but also gca can be read mri = MRIreadHeader((char *)srcVol, MRI_VOLUME_TYPE_UNKNOWN); @@ -2892,7 +3002,8 @@ void mincGetVolumeInfo(const char *srcVol, VOL_GEOM *vgSrc) { else // cound not find the volume initVolGeom(vgSrc); } - } else { + } + else { initVolGeom(vgSrc); } // copy filename even if file does not exist to keep track @@ -2907,7 +3018,8 @@ void mincGetVolumeInfo(const char *srcVol, VOL_GEOM *vgSrc) { return; } -void mincGetVolInfo(const char *infoline, const char *infoline2, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) { +void mincGetVolInfo(const char *infoline, const char *infoline2, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) +{ char *psrcVol = 0; char *pdstVol = 0; int retVal; @@ -2945,7 +3057,8 @@ void mincGetVolInfo(const char *infoline, const char *infoline2, VOL_GEOM *vgSrc free(pdstVol); } -LTA *ltaMNIreadEx(const char *fname) { +LTA *ltaMNIreadEx(const char *fname) +{ LTA *lta = 0; LINEAR_TRANSFORM *lt; char *cp, line[2048], infoline[2048], infoline2[2048]; @@ -2992,7 +3105,8 @@ LTA *ltaMNIreadEx(const char *fname) { fgetl(line, 900, fp); goto get_transform; } - } else { + } + else { if (!strncmp("Transform_Type", line, 14)) { fgetl(line, 900, fp); goto get_transform; @@ -3028,7 +3142,8 @@ LTA *ltaMNIreadEx(const char *fname) { return lta; } -LTA *ltaReadFileEx(const char *fname) { +LTA *ltaReadFileEx(const char *fname) +{ FILE *fp; LINEAR_TRANSFORM *lt; int i, nxforms, type; @@ -3085,7 +3200,8 @@ LTA *ltaReadFileEx(const char *fname) { return (lta); } -LTA *LTAreadExType(const char *fname, int type) { +LTA *LTAreadExType(const char *fname, int type) +{ char fname_no_path[STRLEN]; LTA *lta = NULL; #if 0 @@ -3169,7 +3285,8 @@ LTA *LTAreadExType(const char *fname, int type) { return (lta); } -LTA *LTAreadEx(const char *fname) { +LTA *LTAreadEx(const char *fname) +{ int type; type = TransformFileNameType((char *)fname); return LTAreadExType(fname, type); @@ -3177,7 +3294,8 @@ LTA *LTAreadEx(const char *fname) { // write out the information on src and dst volume // in addition to the transform -int LTAprint(FILE *fp, const LTA *lta) { +int LTAprint(FILE *fp, const LTA *lta) +{ int i, c, r; LT *lt; @@ -3218,7 +3336,8 @@ int LTAprint(FILE *fp, const LTA *lta) { } int // (NOT TRUE ANYMORE: OK means 1, BAD means 0 ) use standard ERROR returns -LTAwriteEx(const LTA *lta, const char *fname) { +LTAwriteEx(const LTA *lta, const char *fname) +{ FILE *fp; time_t tt; char *user, *time_str; @@ -3227,8 +3346,9 @@ LTAwriteEx(const LTA *lta, const char *fname) { if (!stricmp(FileNameExtension((char *)fname, ext), "XFM") || lta->type == MNI_TRANSFORM_TYPE) { // someone defined NO_ERROR to be 0 and thus I have to change it return (ltaMNIwrite((LTA *)lta, (char *)fname)); - } else if (!stricmp(FileNameExtension((char *)fname, ext), "DAT") || - !stricmp(FileNameExtension((char *)fname, ext), "REG") || lta->type == REGISTER_DAT) { + } + else if (!stricmp(FileNameExtension((char *)fname, ext), "DAT") || + !stricmp(FileNameExtension((char *)fname, ext), "REG") || lta->type == REGISTER_DAT) { int err; err = regio_write_register((char *)fname, (char *)lta->subject, @@ -3241,7 +3361,8 @@ LTAwriteEx(const LTA *lta, const char *fname) { return (NO_ERROR); else return (ERROR_NOFILE); - } else if (!stricmp(FileNameExtension((char *)fname, ext), "FSLMAT") || lta->type == FSLREG_TYPE) { + } + else if (!stricmp(FileNameExtension((char *)fname, ext), "FSLMAT") || lta->type == FSLREG_TYPE) { return ltaFSLwrite(lta, fname); } @@ -3260,14 +3381,16 @@ LTAwriteEx(const LTA *lta, const char *fname) { } // add src and voxel information -int LTAvoxelXformToRASXform(const MRI *src, const MRI *dst, LT *voxTran, LT *rasTran) { +int LTAvoxelXformToRASXform(const MRI *src, const MRI *dst, LT *voxTran, LT *rasTran) +{ MRIvoxelXformToRasXform((MRI *)src, (MRI *)dst, voxTran->m_L, rasTran->m_L); getVolGeom(src, &voxTran->src); getVolGeom(dst, &voxTran->dst); return 1; } -static LTA *ltaFSLread(const char *fname) { +static LTA *ltaFSLread(const char *fname) +{ LTA *lta; LINEAR_TRANSFORM *lt; char *cp, line[1000]; @@ -3312,7 +3435,8 @@ static LTA *ltaFSLread(const char *fname) { \brief Same as LTAconcat() but for exactly two LTAs (which I seem to be doing a lot of). */ -LTA *LTAconcat2(LTA *lta1, LTA *lta2, int Reduce) { +LTA *LTAconcat2(LTA *lta1, LTA *lta2, int Reduce) +{ LTA *ltaArray[2], *ltaout; ltaArray[0] = lta1; ltaArray[1] = lta2; @@ -3329,7 +3453,8 @@ LTA *LTAconcat2(LTA *lta1, LTA *lta2, int Reduce) { output LTA. If Reduce=1, all the transforms are combined into a single matrix using LTAreduce(). */ -LTA *LTAconcat(LTA **ltaArray, int nLTAs, int Reduce) { +LTA *LTAconcat(LTA **ltaArray, int nLTAs, int Reduce) +{ int ntot, n, m, k, nx, DoInv = 0; LTA *lta, *lta1, *ltatmp; @@ -3375,7 +3500,8 @@ LTA *LTAconcat(LTA **ltaArray, int nLTAs, int Reduce) { LTcopy(<a1->xforms[m], <a->xforms[k]); k++; } - } else { + } + else { for (m = nx - 1; m >= 0; m--) { LTcopy(<a1->inv_xforms[m], <a->xforms[k]); k++; @@ -3398,7 +3524,8 @@ LTA *LTAconcat(LTA **ltaArray, int nLTAs, int Reduce) { correct direction (direction is figured out from the volume geometry). */ -LTA *LTAreduce(LTA *lta0) { +LTA *LTAreduce(LTA *lta0) +{ LTA *ltar, *lta; LT *lt0, *lt, *ltinv, *ltprev; int n, nx, DoInv = 0; @@ -3454,7 +3581,8 @@ LTA *LTAreduce(LTA *lta0) { without performing the inverse. That function is now (Feb 2014) called LTAfillInverse(). The passed lta is not changed. */ -LTA *LTAinvert(LTA *lta, LTA *ltainv) { +LTA *LTAinvert(LTA *lta, LTA *ltainv) +{ LINEAR_TRANSFORM *lt; ltainv = LTAcopy(lta, ltainv); if (ltainv == NULL) return (NULL); @@ -3474,7 +3602,8 @@ LTA *LTAinvert(LTA *lta, LTA *ltainv) { LTAinvert() function now (Feb 2014) actually inverts the LTA. I think the passed LTA is changed. */ -LTA *LTAfillInverse(LTA *lta) { +LTA *LTAfillInverse(LTA *lta) +{ int i; for (i = 0; i < lta->num_xforms; ++i) { @@ -3487,7 +3616,8 @@ LTA *LTAfillInverse(LTA *lta) { } // verify lta stored src and dst are the same as src and dst -int LTAmodifySrcDstGeom(LTA *lta, MRI *src, MRI *dst) { +int LTAmodifySrcDstGeom(LTA *lta, MRI *src, MRI *dst) +{ LINEAR_TRANSFORM *lt = 0; // work pointer int i; int resSrc = 0; @@ -3515,7 +3645,8 @@ int LTAmodifySrcDstGeom(LTA *lta, MRI *src, MRI *dst) { vg_print(<->src); getVolGeom(src, <->src); } - } else if (lt->src.valid == 0) // if not valid, just copy + } + else if (lt->src.valid == 0) // if not valid, just copy { getVolGeom(src, <->src); } @@ -3535,7 +3666,8 @@ int LTAmodifySrcDstGeom(LTA *lta, MRI *src, MRI *dst) { vg_print(<->dst); getVolGeom(dst, <->dst); } - } else if (lt->dst.valid == 0) // if not valid, just copy + } + else if (lt->dst.valid == 0) // if not valid, just copy { getVolGeom(dst, <->dst); } @@ -3547,7 +3679,8 @@ int LTAmodifySrcDstGeom(LTA *lta, MRI *src, MRI *dst) { // this one does not need to allocate sI2R and dR2I // compared with MRIgetRasToVoxelXform(). -static void LTAgetV2V(MATRIX *mod, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) { +static void LTAgetV2V(MATRIX *mod, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) +{ // sI2R // src -------> RAS // |? | mod (input) @@ -3570,7 +3703,8 @@ static void LTAgetV2V(MATRIX *mod, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) { // this one does not need to allocate sR2I and dI2R // compared with MRIgetVoxToRasXform(). -static void LTAgetR2R(MATRIX *mod, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) { +static void LTAgetR2R(MATRIX *mod, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) +{ // sR2I // src <------- RAS // | mod | ? @@ -3595,7 +3729,8 @@ static void LTAgetR2R(MATRIX *mod, VOL_GEOM *vgSrc, VOL_GEOM *vgDst) { \fn LTA *LTAchangeType(LTA *lta, int ltatype) \brief Changes the transform type. The LTA itself is changed. */ -LTA *LTAchangeType(LTA *lta, int ltatype) { +LTA *LTAchangeType(LTA *lta, int ltatype) +{ LINEAR_TRANSFORM *lt; // work pointer MATRIX *m_L; // work pointer MATRIX *sISize = 0; @@ -3712,7 +3847,8 @@ LTA *LTAchangeType(LTA *lta, int ltatype) { ltatype); break; } - } else if (lta->type == LINEAR_VOX_TO_VOX) { + } + else if (lta->type == LINEAR_VOX_TO_VOX) { switch (ltatype) { case LINEAR_RAS_TO_RAS: for (i = 0; i < lta->num_xforms; ++i) { @@ -3772,7 +3908,8 @@ LTA *LTAchangeType(LTA *lta, int ltatype) { ltatype); break; } - } else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { + } + else if (lta->type == LINEAR_PHYSVOX_TO_PHYSVOX) { switch (ltatype) { case LINEAR_VOX_TO_VOX: // src' (regarded as 1 mm unit voxel) @@ -3850,7 +3987,8 @@ LTA *LTAchangeType(LTA *lta, int ltatype) { ltatype); break; } - } else if (lta->type == REGISTER_DAT) { + } + else if (lta->type == REGISTER_DAT) { switch (ltatype) { case LINEAR_RAS_TO_RAS: // from REGISTER_DAT to LINEAR_RAS_TO_RAS @@ -3905,7 +4043,8 @@ LTA *LTAchangeType(LTA *lta, int ltatype) { printf("transformed matrix:\n"); MatrixPrint(Gstdout, lta->xforms[0].m_L); } - } else if (lta->type == LINEAR_CORONAL_RAS_TO_CORONAL_RAS) { + } + else if (lta->type == LINEAR_CORONAL_RAS_TO_CORONAL_RAS) { MATRIX *m_sras2ras; MRI *mri_tmp; switch (ltatype) { @@ -3941,7 +4080,8 @@ LTA *LTAchangeType(LTA *lta, int ltatype) { printf("transformed matrix:\n"); MatrixPrint(Gstdout, lta->xforms[0].m_L); } - } else if (lta->type == FSLREG_TYPE) { + } + else if (lta->type == FSLREG_TYPE) { switch (ltatype) { case LINEAR_RAS_TO_RAS: lta = LTAchangeType(lta, REGISTER_DAT); @@ -3986,7 +4126,8 @@ LTA *LTAchangeType(LTA *lta, int ltatype) { } // lta is the transform from src to dst for ras2ras or vox2vox -MATRIX *surfaceRASFromSurfaceRAS_(MRI *dst, MRI *src, LTA *lta) { +MATRIX *surfaceRASFromSurfaceRAS_(MRI *dst, MRI *src, LTA *lta) +{ MATRIX *res = 0; MATRIX *tmp = 0; MATRIX *surf2src = 0; @@ -4019,7 +4160,8 @@ MATRIX *surfaceRASFromSurfaceRAS_(MRI *dst, MRI *src, LTA *lta) { if (lta->type == LINEAR_RAS_TO_RAS) { surf2src = RASFromSurfaceRAS_(src); dst2surf = surfaceRASFromRAS_(dst); - } else if (lta->type == LINEAR_VOX_TO_VOX) { + } + else if (lta->type == LINEAR_VOX_TO_VOX) { surf2src = voxelFromSurfaceRAS_(src); dst2surf = surfaceRASFromVoxel_(dst); } @@ -4035,11 +4177,13 @@ MATRIX *surfaceRASFromSurfaceRAS_(MRI *dst, MRI *src, LTA *lta) { return res; } -MRI *TransformCreateDensityMap(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { +MRI *TransformCreateDensityMap(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) +{ if (transform->type == MORPH_3D_TYPE) { GCA_MORPH *gcam = (GCA_MORPH *)(transform->xform); mri_dst = GCAMmorphToAtlasWithDensityCorrection(mri_src, gcam, mri_dst, 0); - } else /* compute determinant of jacobian and apply it everywhere */ + } + else /* compute determinant of jacobian and apply it everywhere */ { double det; @@ -4051,7 +4195,8 @@ MRI *TransformCreateDensityMap(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) return (mri_dst); } -int TransformWrite(TRANSFORM *transform, const char *fname) { +int TransformWrite(TRANSFORM *transform, const char *fname) +{ switch (transform->type) { case MORPH_3D_TYPE: return (GCAMwrite((GCA_MORPH *)(transform->xform), fname)); @@ -4063,7 +4208,8 @@ int TransformWrite(TRANSFORM *transform, const char *fname) { return (NO_ERROR); /* will never get here */ } -TRANSFORM *TransformCopy(TRANSFORM *tsrc, TRANSFORM *tdst) { +TRANSFORM *TransformCopy(TRANSFORM *tsrc, TRANSFORM *tdst) +{ if (!tdst) tdst = TransformAlloc(tsrc->type, NULL); switch (tsrc->type) { @@ -4084,7 +4230,8 @@ TRANSFORM *TransformCopy(TRANSFORM *tsrc, TRANSFORM *tdst) { /*------------------------------------------------------------- LTAtransformTypeName() - just returns the name of the transform type -------------------------------------------------------------*/ -const char *LTAtransformTypeName(int ltatype) { +const char *LTAtransformTypeName(int ltatype) +{ switch (ltatype) { case LINEAR_VOX_TO_VOX: return ("linear_vox_to_vox"); @@ -4122,7 +4269,8 @@ const char *LTAtransformTypeName(int ltatype) { /*------------------------------------------------------------------- LTAdumpVolGeom() - prints volume geometry to a stream -------------------------------------------------------------------*/ -int LTAdumpVolGeom(FILE *fp, VG *vg) { +int LTAdumpVolGeom(FILE *fp, VG *vg) +{ fprintf(fp, "valid %d\n", vg->valid); fprintf(fp, "width %d\n", vg->width); fprintf(fp, "height %d\n", vg->height); @@ -4139,7 +4287,8 @@ int LTAdumpVolGeom(FILE *fp, VG *vg) { /*------------------------------------------------------------------- LTAdumpLinearTransform() - prints LT to stream -------------------------------------------------------------------*/ -int LTAdumpLinearTransform(FILE *fp, LT *lt) { +int LTAdumpLinearTransform(FILE *fp, LT *lt) +{ fprintf(fp, "x0 %f\n", lt->x0); fprintf(fp, "y0 %f\n", lt->y0); fprintf(fp, "z0 %f\n", lt->z0); @@ -4164,7 +4313,8 @@ int LTAdumpLinearTransform(FILE *fp, LT *lt) { /*------------------------------------------------------------------- LTAdump() - prints LTA to stream -------------------------------------------------------------------*/ -int LTAdump(FILE *fp, LTA *lta) { +int LTAdump(FILE *fp, LTA *lta) +{ int nthxform; fprintf(fp, "num_xforms %d\n", lta->num_xforms); @@ -4178,7 +4328,8 @@ int LTAdump(FILE *fp, LTA *lta) { return (0); } -int LTAsetVolGeom(LTA *lta, MRI *mri_src, MRI *mri_dst) { +int LTAsetVolGeom(LTA *lta, MRI *mri_src, MRI *mri_dst) +{ int i; for (i = 0; i < lta->num_xforms; i++) { @@ -4234,7 +4385,8 @@ int LTAsetVolGeom(LTA *lta, MRI *mri_src, MRI *mri_dst) { Note: MRIgetVoxelToRasXform is #defined to be extract_i_to_r(). ----------------------------------------------------------------*/ -MATRIX *VGgetRasToVoxelXform(VOL_GEOM *vg, MATRIX *m, int base) { +MATRIX *VGgetRasToVoxelXform(VOL_GEOM *vg, MATRIX *m, int base) +{ MATRIX *PxyzOffset, *Pcrs; if (m == NULL) m = MatrixAlloc(4, 4, MATRIX_REAL); @@ -4294,7 +4446,8 @@ MATRIX *VGgetRasToVoxelXform(VOL_GEOM *vg, MATRIX *m, int base) { return (m); } -MATRIX *VGgetVoxelToRasXform(VOL_GEOM *vg, MATRIX *m, int base) { +MATRIX *VGgetVoxelToRasXform(VOL_GEOM *vg, MATRIX *m, int base) +{ MATRIX *m_inv; m_inv = VGgetRasToVoxelXform(vg, NULL, base); @@ -4308,7 +4461,8 @@ MATRIX *VGgetVoxelToRasXform(VOL_GEOM *vg, MATRIX *m, int base) { The LTA will be LINEAR_VOX_TO_VOX that maps target vox to mov vox. If R=NULL, then computes the LTA based on header geometry. */ -LTA *TransformRegDat2LTA(MRI *targ, MRI *mov, MATRIX *R) { +LTA *TransformRegDat2LTA(MRI *targ, MRI *mov, MATRIX *R) +{ LTA *lta; MATRIX *vox2vox; // Targ->Mov MATRIX *Ttarg, *Tmov, *invTmov; @@ -4319,7 +4473,8 @@ LTA *TransformRegDat2LTA(MRI *targ, MRI *mov, MATRIX *R) { Tmov = MRIxfmCRS2XYZ(mov, 0); R = MatrixIdentity(4, NULL); freeR = 1; - } else { + } + else { Ttarg = MRIxfmCRS2XYZtkreg(targ); Tmov = MRIxfmCRS2XYZtkreg(mov); } @@ -4349,7 +4504,8 @@ LTA *TransformRegDat2LTA(MRI *targ, MRI *mov, MATRIX *R) { \brief Converts the first xform from LTA to a tkregister-style registration matrix. Assumes LTA is vox2vox. */ -MATRIX *TransformLTA2RegDat(LTA *lta) { +MATRIX *TransformLTA2RegDat(LTA *lta) +{ MATRIX *Vox2Vox = NULL; // Mov->Targ MATRIX *invVox2Vox = NULL; // Targ->Mov MATRIX *Ttarg, *Tmov, *invTtarg; // tkreg space vox2ras @@ -4423,7 +4579,8 @@ MATRIX *TransformLTA2RegDat(LTA *lta) { return (R); } -int TransformRas2Vox(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { +int TransformRas2Vox(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) +{ if (transform->type == MORPH_3D_TYPE) return (GCAMrasToVox((GCA_MORPH *)(transform->xform), mri_src)); else { @@ -4431,7 +4588,8 @@ int TransformRas2Vox(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { return (LTArasToVoxelXform((LTA *)(transform->xform), mri_src, mri_dst)); } } -int TransformVox2Ras(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) { +int TransformVox2Ras(TRANSFORM *transform, MRI *mri_src, MRI *mri_dst) +{ if (transform->type == MORPH_3D_TYPE) return (GCAMvoxToRas((GCA_MORPH *)(transform->xform))); else { @@ -4448,7 +4606,8 @@ int TransformSampleDirection(TRANSFORM *transform, float nz, float *pnx, float *pny, - float *pnz) { + float *pnz) +{ float xa0, ya0, za0, xa1, ya1, za1, mag; TransformSampleReal(transform, x0, y0, z0, &xa0, &ya0, &za0); @@ -4476,7 +4635,8 @@ int TransformSampleDirection(TRANSFORM *transform, angles[2] - roll - rotation about z or SI axis (alpha) Ref: Craig, Intro to Robotics */ -MATRIX *MRIangles2RotMat(double *angles) { +MATRIX *MRIangles2RotMat(double *angles) +{ double gamma, beta, alpha; int r, c; MATRIX *R, *R3, *Rx, *Ry, *Rz; @@ -4548,7 +4708,8 @@ MATRIX *MRIangles2RotMat(double *angles) { \param costs - 8 element array with cost measures. If NULL, it will be allocated. */ -double *SegRegCost(MRI *regseg, MRI *f, double *costs) { +double *SegRegCost(MRI *regseg, MRI *f, double *costs) +{ double wmsum, wmsum2, wmmean, wmstd; double ctxsum, ctxsum2, ctxmean, ctxstd; double vseg = 0, vf, t, cost; @@ -4651,7 +4812,8 @@ double *SegRegCost(MRI *regseg, MRI *f, double *costs) { applying R (which is a tkreg matrix). The output is a single-frame MRI with the unsigned displacment. */ -MRI *MRIaffineDisplacment(MRI *mri, MATRIX *R) { +MRI *MRIaffineDisplacment(MRI *mri, MATRIX *R) +{ MRI *disp; int c, r, s; MATRIX *Pcrs, *Pras, *Pras2, *Vox2RAS, *Vox2RAS2; @@ -4693,7 +4855,8 @@ MRI *MRIaffineDisplacment(MRI *mri, MATRIX *R) { return (disp); } -int TransformGetSrcVolGeom(TRANSFORM *transform, VOL_GEOM *vg) { +int TransformGetSrcVolGeom(TRANSFORM *transform, VOL_GEOM *vg) +{ GCAM *gcam; LTA *lta; @@ -4709,7 +4872,8 @@ int TransformGetSrcVolGeom(TRANSFORM *transform, VOL_GEOM *vg) { } return (NO_ERROR); } -int TransformGetDstVolGeom(TRANSFORM *transform, VOL_GEOM *vg) { +int TransformGetDstVolGeom(TRANSFORM *transform, VOL_GEOM *vg) +{ GCAM *gcam; LTA *lta; @@ -4725,14 +4889,16 @@ int TransformGetDstVolGeom(TRANSFORM *transform, VOL_GEOM *vg) { } return (NO_ERROR); } -int TransformSetMRIVolGeomToSrc(TRANSFORM *transform, MRI *mri) { +int TransformSetMRIVolGeomToSrc(TRANSFORM *transform, MRI *mri) +{ VOL_GEOM vg; TransformGetSrcVolGeom(transform, &vg); MRIcopyVolGeomToMRI(mri, &vg); return (NO_ERROR); } -int TransformSetMRIVolGeomToDst(TRANSFORM *transform, MRI *mri) { +int TransformSetMRIVolGeomToDst(TRANSFORM *transform, MRI *mri) +{ VOL_GEOM vg; TransformGetDstVolGeom(transform, &vg); @@ -4740,7 +4906,8 @@ int TransformSetMRIVolGeomToDst(TRANSFORM *transform, MRI *mri) { return (NO_ERROR); } -LTA *LTAcompose(LTA *lta_src, MATRIX *m_left, MATRIX *m_right, LTA *lta_dst) { +LTA *LTAcompose(LTA *lta_src, MATRIX *m_left, MATRIX *m_right, LTA *lta_dst) +{ if (lta_dst == NULL) { lta_dst = LTAalloc(1, NULL); copyVolGeom(<a_src->xforms[0].src, <a_dst->xforms[0].src); @@ -4751,7 +4918,8 @@ LTA *LTAcompose(LTA *lta_src, MATRIX *m_left, MATRIX *m_right, LTA *lta_dst) { return (lta_dst); } -TRANSFORM *TransformCompose(TRANSFORM *t_src, MATRIX *m_left, MATRIX *m_right, TRANSFORM *t_dst) { +TRANSFORM *TransformCompose(TRANSFORM *t_src, MATRIX *m_left, MATRIX *m_right, TRANSFORM *t_dst) +{ LTA *lta_src, *lta_dst; if (t_dst == NULL) t_dst = TransformAlloc(t_src->type, NULL); @@ -4770,7 +4938,8 @@ TRANSFORM *TransformCompose(TRANSFORM *t_src, MATRIX *m_left, MATRIX *m_right, T } int TransformSourceVoxelToAtlas( - TRANSFORM *transform, MRI *mri, int xv, int yv, int zv, double *px, double *py, double *pz) { + TRANSFORM *transform, MRI *mri, int xv, int yv, int zv, double *px, double *py, double *pz) +{ float xt, yt, zt; LTA *lta; @@ -4780,9 +4949,11 @@ int TransformSourceVoxelToAtlas( // transform point to talairach volume point TransformWithMatrix(lta->xforms[0].m_L, xv, yv, zv, px, py, pz); // TransformSample(transform, xv, yv, zv, &xt, &yt, &zt) ; - } else + } + else ErrorExit(ERROR_BADPARM, "RFAsourceVoxelToNode: needs vox-to-vox transform"); - } else // morph 3d type can go directly from source to template + } + else // morph 3d type can go directly from source to template { TransformSample(transform, xv, yv, zv, &xt, &yt, &zt); *px = (double)xt; @@ -4797,7 +4968,8 @@ int TransformSourceVoxelToAtlas( \brief Returns 1 if the geometry in mri matches that in lta->xforms[0].src, otherwise returns 0. */ -int LTAmriIsSource(const LTA *lta, const MRI *mri) { +int LTAmriIsSource(const LTA *lta, const MRI *mri) +{ VOL_GEOM mrivg; int IsSource; getVolGeom(mri, &mrivg); @@ -4809,7 +4981,8 @@ int LTAmriIsSource(const LTA *lta, const MRI *mri) { \brief Returns 1 if the geometry in mri matches that in lta->xforms[num_xforms-1].dst, otherwise returns 0. */ -int LTAmriIsTarget(const LTA *lta, const MRI *mri) { +int LTAmriIsTarget(const LTA *lta, const MRI *mri) +{ VOL_GEOM mrivg; int IsTarget, nxforms; getVolGeom(mri, &mrivg); @@ -4821,7 +4994,8 @@ int LTAmriIsTarget(const LTA *lta, const MRI *mri) { \fn LTA *LTAcreate(MRI *src, MRI *dst, MATRIX *T, int type) \brief Create an LTA of the given type with the given matrix */ -LTA *LTAcreate(MRI *src, MRI *dst, MATRIX *T, int type) { +LTA *LTAcreate(MRI *src, MRI *dst, MATRIX *T, int type) +{ LTA *lta; lta = LTAalloc(1, NULL); LTAsetVolGeom(lta, src, dst); @@ -4841,7 +5015,8 @@ LTA *LTAcreate(MRI *src, MRI *dst, MATRIX *T, int type) { LTAchangeType(lta2,REGISTER_DAT); rms = RMSregDiffMJ(lta1->xforms[0].m_L, lta2->xforms[0].m_L, 70); */ -double RMSregDiffMJ(MATRIX *T1, MATRIX *T2, double radius) { +double RMSregDiffMJ(MATRIX *T1, MATRIX *T2, double radius) +{ MATRIX *Q, *M, *t, *Mt, *MtM, *tt, *ttt; int c, r; double rms, MtMtrace; diff --git a/utils/tritri.c b/utils/tritri.c index 8babfc35be2..86c8d714fbf 100644 --- a/utils/tritri.c +++ b/utils/tritri.c @@ -68,17 +68,22 @@ /* here we know that D0D2<=0.0 */ \ /* that is D0, D1 are on the same side, D2 on the other or on the plane */ \ ISECT(VV2, VV0, VV1, D2, D0, D1, isect0, isect1); \ - } else if (D0D2 > 0.0f) { \ + } \ + else if (D0D2 > 0.0f) { \ /* here we know that d0d1<=0.0 */ \ ISECT(VV1, VV0, VV2, D1, D0, D2, isect0, isect1); \ - } else if (D1 * D2 > 0.0f || D0 != 0.0f) { \ + } \ + else if (D1 * D2 > 0.0f || D0 != 0.0f) { \ /* here we know that d0d1<=0.0 or that D0!=0.0 */ \ ISECT(VV0, VV1, VV2, D0, D1, D2, isect0, isect1); \ - } else if (D1 != 0.0f) { \ + } \ + else if (D1 != 0.0f) { \ ISECT(VV1, VV0, VV2, D1, D0, D2, isect0, isect1); \ - } else if (D2 != 0.0f) { \ + } \ + else if (D2 != 0.0f) { \ ISECT(VV2, VV0, VV1, D2, D0, D1, isect0, isect1); \ - } else { \ + } \ + else { \ /* triangles are coplanar */ \ return coplanar_tri_tri(N1, V0, V1, V2, U0, U1, U2); \ } @@ -97,7 +102,8 @@ e = Ax * Cy - Ay * Cx; \ if (f > 0) { \ if (e >= 0 && e <= f) return 1; \ - } else { \ + } \ + else { \ if (e <= 0 && e >= f) return 1; \ } \ } @@ -141,7 +147,8 @@ int coplanar_tri_tri(double N[3], double V0[3], double V1[3], double V2[3], double U0[3], double U1[3], double U2[3]); -int coplanar_tri_tri(double N[3], double V0[3], double V1[3], double V2[3], double U0[3], double U1[3], double U2[3]) { +int coplanar_tri_tri(double N[3], double V0[3], double V1[3], double V2[3], double U0[3], double U1[3], double U2[3]) +{ double A[3]; short i0, i1; /* first project onto an axis-aligned plane, that maximizes the area */ @@ -153,16 +160,19 @@ int coplanar_tri_tri(double N[3], double V0[3], double V1[3], double V2[3], doub if (A[0] > A[2]) { i0 = 1; /* A[0] is greatest */ i1 = 2; - } else { + } + else { i0 = 0; /* A[2] is greatest */ i1 = 1; } - } else /* A[0]<=A[1] */ + } + else /* A[0]<=A[1] */ { if (A[2] > A[1]) { i0 = 0; /* A[2] is greatest */ i1 = 1; - } else { + } + else { i0 = 0; /* A[1] is greatest */ i1 = 2; } @@ -180,7 +190,8 @@ int coplanar_tri_tri(double N[3], double V0[3], double V1[3], double V2[3], doub return 0; } -int tri_tri_intersect(double V0[3], double V1[3], double V2[3], double U0[3], double U1[3], double U2[3]) { +int tri_tri_intersect(double V0[3], double V1[3], double V2[3], double U0[3], double U1[3], double U2[3]) +{ double E1[3], E2[3]; double N1[3], N2[3], d1, d2; double du0, du1, du2, dv0, dv1, dv2, fdu0, fdu1, fdu2, fdv0, fdv1, fdv2; @@ -312,8 +323,8 @@ int tri_tri_intersect(double V0[3], double V1[3], double V2[3], double U0[3], do coordinates of the vertices, and D is the direction of the ray. */ #include "matrix.h" -int triangle_ray_intersect( - double orig_pt[3], double dir[3], double U0[3], double U1[3], double U2[3], double int_pt[3]) { +int triangle_ray_intersect(double orig_pt[3], double dir[3], double U0[3], double U1[3], double U2[3], double int_pt[3]) +{ double basis1[3], basis2[3], tmp[3], L0[3], L1[3], len, t, dot, norm_proj[3], *V0, *V1, *V2, desc[3], Point[3]; // douoble a, b; MATRIX *m_U, *m_inv; @@ -441,7 +452,8 @@ int triangle_ray_intersect( // 0 = disjoint (no intersect) // 1 = intersect in unique point I1 // 2 = are in the same plane -int intersect_RayTriangle(double ray[2][3], double V0[3], double V1[3], double V2[3], double I[3]) { +int intersect_RayTriangle(double ray[2][3], double V0[3], double V1[3], double V2[3], double I[3]) +{ double u[3], v[3], n[3]; // triangle vectors double dir[3], w0[3], w[3]; // ray vectors float r, a, b; // params to calc ray-plane intersect @@ -496,7 +508,8 @@ int intersect_RayTriangle(double ray[2][3], double V0[3], double V1[3], double V return 1; // I is in T } int project_point_to_plane( - double point[3], double V0[3], double V1[3], double V2[3], double proj[3], double pe1[3], double pe2[3]) { + double point[3], double V0[3], double V1[3], double V2[3], double proj[3], double pe1[3], double pe2[3]) +{ double e1[3], e2[3], norm, d1, d2, tmp[3]; // first basis vector diff --git a/utils/tukey.c b/utils/tukey.c index 616b053604d..394c502af70 100644 --- a/utils/tukey.c +++ b/utils/tukey.c @@ -26,7 +26,8 @@ #include "tukey.h" #include -double tukey_biweight(double residual, double C) { +double tukey_biweight(double residual, double C) +{ double p; if (abs(residual) > C) diff --git a/utils/utils.c b/utils/utils.c index 06a52883f74..3285babeb08 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -67,7 +67,8 @@ int isblank(int c); nothing. ------------------------------------------------------------------------*/ static long idum = 0L, nrgcalls = 0L; -int setRandomSeed(long seed) { +int setRandomSeed(long seed) +{ // also seed the 'standard' random number generators: rand() and random() srand(seed); srandom(seed); @@ -93,7 +94,8 @@ int setRandomSeed(long seed) { long getRandomSeed(void) { return (idum); } long getRandomCalls(void) { return (nrgcalls); } -double randomNumber(double low, double hi) { +double randomNumber(double low, double hi) +{ double val, range; if (low > hi) { @@ -123,7 +125,8 @@ double randomNumber(double low, double hi) { Return Values: nothing. ------------------------------------------------------------------------*/ -double normAngle(double angle) { +double normAngle(double angle) +{ while (angle > PI) angle -= 2.0 * PI; while (angle < -PI) angle += 2.0 * PI; @@ -139,7 +142,8 @@ double normAngle(double angle) { Return Values: nothing. ------------------------------------------------------------------------*/ -double calcDeltaPhi(double phi1, double phi2) { +double calcDeltaPhi(double phi1, double phi2) +{ double delta_phi; if (phi1 < 0.0) @@ -169,7 +173,8 @@ double calcDeltaPhi(double phi1, double phi2) { Return Values: nothing. ------------------------------------------------------------------------*/ -double latan2(double y, double x) { +double latan2(double y, double x) +{ int oerr; double val; @@ -193,7 +198,8 @@ double latan2(double y, double x) { Return Values: nothing. ------------------------------------------------------------------------*/ -int QuadEqual(double a1, double a2) { +int QuadEqual(double a1, double a2) +{ a1 = normAngle(a1); a2 = normAngle(a2); if (fabs(a1 - a2) < RADIANS(90.0)) @@ -210,7 +216,8 @@ int QuadEqual(double a1, double a2) { Return Values: nothing. ------------------------------------------------------------------------*/ -void fComplementCode(double *pdIn, double *pdOut, int iLen) { +void fComplementCode(double *pdIn, double *pdOut, int iLen) +{ int i; double d; @@ -231,7 +238,8 @@ void fComplementCode(double *pdIn, double *pdOut, int iLen) { Return Values: nothing. ------------------------------------------------------------------------*/ -char *fgetl(char *s, int n, FILE *fp) { +char *fgetl(char *s, int n, FILE *fp) +{ char *cp, *cp2; int len; @@ -258,7 +266,8 @@ char *fgetl(char *s, int n, FILE *fp) { * * Algorithm due to Isaac Newton, takes log(n)/2 iterations. */ -int IntSqrt(int n) { +int IntSqrt(int n) +{ register int approx, prev; if (n == 0) return 0; @@ -292,7 +301,8 @@ int IntSqrt(int n) { Return Values: nothing. ------------------------------------------------------------------------*/ -char *StrUpper(char *str) { +char *StrUpper(char *str) +{ char *cp; for (cp = str; *cp; cp++) *cp = (char)toupper(*cp); @@ -308,7 +318,8 @@ char *StrUpper(char *str) { Return Values: nothing. ------------------------------------------------------------------------*/ -char *StrLower(char *str) { +char *StrLower(char *str) +{ char *cp; for (cp = str; *cp; cp++) *cp = (char)tolower(*cp); @@ -326,7 +337,8 @@ char *StrLower(char *str) { Return Values: ------------------------------------------------------------------------*/ -char *StrReplace(const char *src, char *dst, char csrc, int cdst) { +char *StrReplace(const char *src, char *dst, char csrc, int cdst) +{ const char *cp_src; char *cp_dst; @@ -349,7 +361,8 @@ char *StrReplace(const char *src, char *dst, char csrc, int cdst) { Return Values: nothing. ------------------------------------------------------------------------*/ -char *FileNameOnly(const char *full_name, char *fname) { +char *FileNameOnly(const char *full_name, char *fname) +{ char *slash, *number, *at; slash = strrchr(full_name, '/'); @@ -359,7 +372,8 @@ char *FileNameOnly(const char *full_name, char *fname) { strcpy(fname, full_name); else strcpy(fname, slash + 1); - } else { + } + else { // cannot process in place due to con // // best solution: copy full_name to fname @@ -385,7 +399,8 @@ char *FileNameOnly(const char *full_name, char *fname) { Return Values: 1 if the file exists, 0 otherwise ------------------------------------------------------------------------*/ -int FileExists(const char *fname) { +int FileExists(const char *fname) +{ FILE *fp; int old_errno; @@ -409,7 +424,8 @@ int FileExists(const char *fname) { Return Values: nothing. ------------------------------------------------------------------------*/ -char *FileName(char *full_name) { +char *FileName(char *full_name) +{ char *fname, *number, *at; fname = strrchr(full_name, '/'); @@ -437,7 +453,8 @@ char *FileName(char *full_name) { Return Values: ------------------------------------------------------------------------*/ -int FileType(const char *fname) { +int FileType(const char *fname) +{ char *dot, buf[STR_LEN], *number; if (*fname == '@') return (LIST_FILE); @@ -472,7 +489,8 @@ int FileType(const char *fname) { Return Values: ------------------------------------------------------------------------*/ -int FileNumber(const char *fname) { +int FileNumber(const char *fname) +{ char buf[STR_LEN], *number; int num; @@ -494,7 +512,8 @@ int FileNumber(const char *fname) { Return Values: ------------------------------------------------------------------------*/ -int FileNumberOfEntries(const char *fname) { +int FileNumberOfEntries(const char *fname) +{ int type, num, nentries; FILE *fp; char buf[STR_LEN], line[2 * STR_LEN], *cp; @@ -539,7 +558,8 @@ int FileNumberOfEntries(const char *fname) { nentries = -1; break; } - } else + } + else nentries = 1; return (nentries); @@ -555,7 +575,8 @@ int FileNumberOfEntries(const char *fname) { Return Values: nothing. ------------------------------------------------------------------------*/ -char *FileFullName(char *full_name) { +char *FileFullName(char *full_name) +{ char *fname, *number, *at; fname = full_name; @@ -578,7 +599,8 @@ char *FileFullName(char *full_name) { Return Values: pointer to the filename ------------------------------------------------------------------------*/ -char *FileTmpName(char *basename) { +char *FileTmpName(char *basename) +{ static char fname[STR_LEN]; int i; FILE *fp; @@ -604,7 +626,8 @@ char *FileTmpName(char *basename) { Return Values: pointer to the filename ------------------------------------------------------------------------*/ -void FileRename(const char *inName, const char *outName) { +void FileRename(const char *inName, const char *outName) +{ #ifndef _MSDOS char cmd_string[200]; sprintf(cmd_string, "mv %s %s", inName, outName); @@ -626,7 +649,8 @@ void FileRename(const char *inName, const char *outName) { Return Values: the distance. ------------------------------------------------------------------------*/ -float angleDistance(float theta1, float theta2) { +float angleDistance(float theta1, float theta2) +{ float adist; adist = (float)fabs(theta1 - theta2); @@ -636,7 +660,8 @@ float angleDistance(float theta1, float theta2) { } /*#ifndef SunOS*/ #ifndef Windows_NT -int stricmp(const char *str1, const char *str2) { +int stricmp(const char *str1, const char *str2) +{ char buf1[STR_LEN], buf2[STR_LEN]; strcpy(buf1, str1); @@ -657,7 +682,8 @@ int stricmp(const char *str1, const char *str2) { Return Values: remove leading spaces from a string ------------------------------------------------------------------------*/ -char *StrRemoveSpaces(char *str) { +char *StrRemoveSpaces(char *str) +{ while (isspace((int)*str)) str++; return (str); @@ -674,13 +700,15 @@ char *StrRemoveSpaces(char *str) { extern char *getcwd(char *pathname, size_t size); #endif -char *FileNameAbsolute(const char *fname, char *absFname) { +char *FileNameAbsolute(const char *fname, char *absFname) +{ char pathname[MAXPATHLEN]; int len; if (*fname == '/') { if (absFname != fname) strcpy(absFname, fname); - } else /* not already absolute */ + } + else /* not already absolute */ { len = strlen(fname); char *fn = strcpyalloc(fname); @@ -709,7 +737,8 @@ char *FileNameAbsolute(const char *fname, char *absFname) { Return Values: ------------------------------------------------------------------------*/ -char *FileNamePath(const char *fname, char *pathName) { +char *FileNamePath(const char *fname, char *pathName) +{ char *slash; strcpy(pathName, fname); @@ -738,7 +767,8 @@ char *FileNamePath(const char *fname, char *pathName) { Return Values: ------------------------------------------------------------------------*/ -char *StrSkipNumber(char *str) { +char *StrSkipNumber(char *str) +{ while (*str && isdigit((int)*str)) str++; if (*str == '.') /* check for floating point # */ { @@ -757,7 +787,8 @@ char *StrSkipNumber(char *str) { Description ------------------------------------------------------*/ -float deltaAngle(float angle1, float angle2) { +float deltaAngle(float angle1, float angle2) +{ float delta; delta = angle1 - angle2; @@ -781,7 +812,8 @@ float deltaAngle(float angle1, float angle2) { 3. if src cannot be reallocated, then the function forces an exit. ---------------------------------------------------------*/ -char *AppendString(char *src, char *app) { +char *AppendString(char *src, char *app) +{ int sz1 = 0, sz2 = 0; char *tmp; @@ -826,7 +858,8 @@ union ieee754_float { float f; /* This is the IEEE 754 single-precision format. */ - struct { + struct + { unsigned int negative : 1; unsigned int exponent : 8; unsigned int mantissa : 23; @@ -837,7 +870,8 @@ union ieee754_float { float f; /* This is the IEEE 754 single-precision format. */ - struct { + struct + { unsigned int mantissa : 23; unsigned int exponent : 8; unsigned int negative : 1; @@ -845,7 +879,8 @@ union ieee754_float { }; #endif -int devIsinf(float value) { +int devIsinf(float value) +{ unsigned int s, e, f; union ieee754_float v; @@ -862,7 +897,8 @@ int devIsinf(float value) { } /* end devIsinf() */ /* isnan non-zero if NaN, 0 otherwise */ -int devIsnan(float value) { +int devIsnan(float value) +{ unsigned int e, f; // unsigned int s; @@ -878,13 +914,15 @@ int devIsnan(float value) { } /* end devIsnan() */ /* non-zero if neither infinite nor NaN, 0 otherwise */ -int devFinite(float value) { +int devFinite(float value) +{ if (!devIsinf(value) && !devIsnan(value)) return (1); return (0); } /* end devFinite() */ -char *FileNameRemoveExtension(const char *in_fname, char *out_fname) { +char *FileNameRemoveExtension(const char *in_fname, char *out_fname) +{ char *dot; if (out_fname != in_fname) strcpy(out_fname, in_fname); @@ -892,7 +930,8 @@ char *FileNameRemoveExtension(const char *in_fname, char *out_fname) { if (dot) *dot = 0; return (out_fname); } -char *FileNameExtension(const char *fname, char *ext) { +char *FileNameExtension(const char *fname, char *ext) +{ char *dot, buf[STR_LEN]; ext[0] = 0; @@ -905,7 +944,8 @@ char *FileNameExtension(const char *fname, char *ext) { #include -char *FileNameFromWildcard(const char *inStr, char *outStr) { +char *FileNameFromWildcard(const char *inStr, char *outStr) +{ char *cp; glob_t gbuf; @@ -919,7 +959,8 @@ char *FileNameFromWildcard(const char *inStr, char *outStr) { } // return Kbytes memory used -int getMemoryUsed() { +int getMemoryUsed() +{ #ifdef Linux FILE *fp = 0; char buf[256]; @@ -943,7 +984,8 @@ int getMemoryUsed() { if (numassigned == 1) { pclose(fp); return memused; - } else { + } + else { pclose(fp); errno = 0; fprintf(stderr, "getting memoryused failed"); @@ -969,7 +1011,8 @@ int getMemoryUsed() { void printMemoryUsed() { printf("heap used: %d Kbytes.\n", getMemoryUsed()); } // String copy will allocation. -char *strcpyalloc(const char *str) { +char *strcpyalloc(const char *str) +{ char *cpstr; cpstr = (char *)calloc(strlen(str) + 1, sizeof(char)); strcpy(cpstr, str); @@ -982,7 +1025,8 @@ char *strcpyalloc(const char *str) { are separated by white space as determined by isspace(). These include \f, \n, \r, \t and \v as well as the simple space. *-----------------------------------------------------------*/ -int ItemsInString(const char *str) { +int ItemsInString(const char *str) +{ int items, nthchar, len; len = strlen(str); @@ -1019,7 +1063,8 @@ int ItemsInString(const char *str) { \fn char *deblank(char *str) \brief removes blanks from a string. */ -char *deblank(const char *str) { +char *deblank(const char *str) +{ char *dbstr; int n, m; @@ -1041,7 +1086,8 @@ char *deblank(const char *str) { \fn int str_toupper(char *str) \brief Converts each char in str to upper case. Done in place. */ -char *str_toupper(char *str) { +char *str_toupper(char *str) +{ int n; for (n = 0; n < strlen(str); n++) str[n] = toupper(str[n]); return (0); @@ -1053,11 +1099,13 @@ char *str_toupper(char *str) { * routines are declared here (instead of trying to guess how long to quad * should be implemented)... */ -void __ltoq(void) { +void __ltoq(void) +{ printf("ERROR: Attempting usage of '__ltoq' routine!\n"); exit(1); } -void __qtol(void) { +void __qtol(void) +{ printf("ERROR: Attempting usage of '__qtol' routine!\n"); exit(1); } @@ -1070,7 +1118,8 @@ void __qtol(void) { and the number in the list (nx). This allows the computation of the stddev with only one trip through the list. */ -double sum2stddev(double xsum, double xsum2, int nx) { +double sum2stddev(double xsum, double xsum2, int nx) +{ double xmean, xstd; xmean = xsum / nx; xstd = sqrt((xsum2 - 2 * xmean * xsum + nx * xmean * xmean) / (nx - 1)); @@ -1083,7 +1132,8 @@ double sum2stddev(double xsum, double xsum2, int nx) { \fn int compare_ints(const void *v1,const void *v2) \brief Int comparison function suitable for qsort. */ -int compare_ints(const void *v1, const void *v2) { +int compare_ints(const void *v1, const void *v2) +{ int i1, i2; i1 = *((int *)v1); i2 = *((int *)v2); @@ -1096,7 +1146,8 @@ int compare_ints(const void *v1, const void *v2) { \fn int compare_ints(const void *v1,const void *v2) \brief Float comparison function suitable for qsort. */ -int compare_floats(const void *v1, const void *v2) { +int compare_floats(const void *v1, const void *v2) +{ float i1, i2; i1 = *((float *)v1); i2 = *((float *)v2); @@ -1110,7 +1161,8 @@ int compare_floats(const void *v1, const void *v2) { \brief Returns/counts the number of unique items in a list of integers. The list will be sorted. */ -int nunqiue_int_list(int *idlist, int nlist) { +int nunqiue_int_list(int *idlist, int nlist) +{ int idprev, nunique, n; qsort(idlist, nlist, sizeof(int), compare_ints); @@ -1130,7 +1182,8 @@ int nunqiue_int_list(int *idlist, int nlist) { \brief Returns the unique items in a list of integers. The list will be sorted. */ -int *unqiue_int_list(int *idlist, int nlist, int *nunique) { +int *unqiue_int_list(int *idlist, int nlist, int *nunique) +{ int n, *ulist, nthu; /* count number of unique elements in the list, @@ -1157,7 +1210,8 @@ int *unqiue_int_list(int *idlist, int nlist, int *nunique) { If there is a tie, it returns the first sorted. The list will be sorted. */ -int most_frequent_int_list(int *idlist, int nlist, int *nmax) { +int most_frequent_int_list(int *idlist, int nlist, int *nmax) +{ int n, *ulist, nthu, nthumax, nunique, *nper, mostfreq; ulist = unqiue_int_list(idlist, nlist, &nunique); @@ -1187,7 +1241,8 @@ int most_frequent_int_list(int *idlist, int nlist, int *nmax) { one or more contiguous non-blank characters. Same as gdfCountItemsInString(). --------------------------------------------------*/ -int CountItemsInString(const char *str) { +int CountItemsInString(const char *str) +{ int len, n, nhits; len = strlen(str); nhits = 0; @@ -1208,7 +1263,8 @@ int CountItemsInString(const char *str) { is -1, then it returns the last item. item is a string that must be freed by the caller. Same as gdfGetNthItemFromString(). ------------------------------------------------------------------*/ -char *GetNthItemFromString(const char *str, int nth) { +char *GetNthItemFromString(const char *str, int nth) +{ char *item; int nitems, n; static char fmt[2000], tmpstr[2000]; @@ -1253,7 +1309,8 @@ char *GetNthItemFromString(const char *str, int nth) { can be used to compute the median ---------------------------------------------------------------------------*/ -float kth_smallest(float a[], int n, int k) { +float kth_smallest(float a[], int n, int k) +{ int i, j, l, m; float x, t; int kk = k - 1; @@ -1286,7 +1343,8 @@ float kth_smallest(float a[], int n, int k) { * "Numerical recipes in C", Second Edition, * Cambridge University Press, 1992, Section 8.5, ISBN 0-521-43108-5 ---------------------------------------------------------------------------*/ -float quick_select(float arr[], int n, int k) { +float quick_select(float arr[], int n, int k) +{ int low, high; int median; int middle, ll, hh; @@ -1361,7 +1419,8 @@ float quick_select(float arr[], int n, int k) { // Input float array t[] of length n // computation in situ, t will be reordered ---------------------------------------------------------------------------*/ -float median(float t[], int n) { +float median(float t[], int n) +{ float q, q2; if (n % 2 == 1) // odd { @@ -1390,7 +1449,8 @@ float median(float t[], int n) { // computation in situ, a will be reordered // ---------------------------------------------------------------------------*/ -float mad(float a[], int n) { +float mad(float a[], int n) +{ float d, mm, medi; int i; float *t = (float *)calloc(n, sizeof(float)); @@ -1423,7 +1483,8 @@ int global_progress_range[2] = {0, 100}; // default is 0 and 100 // ---------------------------------------------------------------------------*/ -void SetProgressCallback(void (*callback)(int), int start, int end) { +void SetProgressCallback(void (*callback)(int), int start, int end) +{ progress_callback = callback; global_progress_range[0] = start; global_progress_range[1] = end; @@ -1438,12 +1499,14 @@ void SetProgressCallback(void (*callback)(int), int start, int end) { // total_frames to 1 // ---------------------------------------------------------------------------*/ -void exec_progress_callback(int slice, int total_slices, int frame, int total_frames) { +void exec_progress_callback(int slice, int total_slices, int frame, int total_frames) +{ if (progress_callback) progress_callback(global_progress_range[0] + (global_progress_range[1] - global_progress_range[0]) * (slice + total_slices * frame) / (total_slices * total_frames)); } -int *compute_permutation(int num, int *vec) { +int *compute_permutation(int num, int *vec) +{ int n, index, tmp; if (vec == NULL) vec = (int *)calloc(num, sizeof(vec[0])); @@ -1461,7 +1524,8 @@ int *compute_permutation(int num, int *vec) { } // probably better to use getrusage(). see below -int *GetMemUsage(int *u) { +int *GetMemUsage(int *u) +{ FILE *fp; static char tag[500]; int r; @@ -1489,7 +1553,8 @@ int *GetMemUsage(int *u) { return (u); } -int PrintMemUsage(FILE *fp) { +int PrintMemUsage(FILE *fp) +{ static int u[5]; GetMemUsage(u); @@ -1505,7 +1570,8 @@ int PrintMemUsage(FILE *fp) { probably want: who = RUSAGE_SELF; pre is a string that will start each line. */ -int PrintRUsage(int who, const char *pre, FILE *fp) { +int PrintRUsage(int who, const char *pre, FILE *fp) +{ int err; struct rusage u; err = getrusage(who, &u); @@ -1536,7 +1602,8 @@ int PrintRUsage(int who, const char *pre, FILE *fp) { probably want: who = RUSAGE_SELF; pre is a string that will start each line. */ -int WriteRUsage(int who, const char *pre, char *fname) { +int WriteRUsage(int who, const char *pre, char *fname) +{ int err; FILE *fp; fp = fopen(fname, "w"); diff --git a/utils/version.c b/utils/version.c index c8dc31339af..13416c86fe3 100644 --- a/utils/version.c +++ b/utils/version.c @@ -114,7 +114,8 @@ argc -= nargs; */ int make_cmd_version_string( - int argc, char **argv, const char *id_string, const char *version_string, char *return_string) { + int argc, char **argv, const char *id_string, const char *version_string, char *return_string) +{ int nnarg = 0; char stripped_version_string[1024]; int length; @@ -137,7 +138,8 @@ int make_cmd_version_string( if (length > 2) { stripped_version_string[length - 2] = '\0'; } - } else { + } + else { strcpy(stripped_version_string, version_string); } @@ -189,7 +191,8 @@ int make_cmd_version_string( // fprintf (stderr, "uname() returned %d\n", result); strcpy(machine, "UNKNOWN"); strcpy(platform_version, "UNKNOWN"); - } else { + } + else { strcpy(machine, kernel_info.nodename); strcpy(platform_version, kernel_info.release); } @@ -228,7 +231,8 @@ int make_cmd_version_string( return (NO_ERROR); } -int handle_version_option(int argc, char **argv, const char *id_string, const char *version_string) { +int handle_version_option(int argc, char **argv, const char *id_string, const char *version_string) +{ int narg = 0; int nnarg = 0; int num_processed_args = 0; @@ -276,7 +280,8 @@ int handle_version_option(int argc, char **argv, const char *id_string, const ch if (length > 2) { stripped_version_string[length - 2] = '\0'; } - } else { + } + else { strcpy(stripped_version_string, version_string); } @@ -304,7 +309,8 @@ int handle_version_option(int argc, char **argv, const char *id_string, const ch begin = strrchr(argv[0], (int)'/'); if (NULL == begin) { begin = argv[0]; - } else { + } + else { begin = begin + 1; } strcpy(program_name, begin); @@ -353,7 +359,8 @@ int handle_version_option(int argc, char **argv, const char *id_string, const ch // fprintf (stderr, "uname() returned %d\n", result); strcpy(machine, "UNKNOWN"); strcpy(platform_version, "UNKNOWN"); - } else { + } + else { strcpy(machine, kernel_info.nodename); strcpy(platform_version, kernel_info.release); } @@ -401,7 +408,8 @@ int handle_version_option(int argc, char **argv, const char *id_string, const ch /*------------------------------------------------------------------------ argv2cmdline() - converts argv into a single string. ------------------------------------------------------------------------*/ -char *argv2cmdline(int argc, char *argv[]) { +char *argv2cmdline(int argc, char *argv[]) +{ int len, n; char *cmdline; @@ -421,7 +429,8 @@ char *argv2cmdline(int argc, char *argv[]) { VERuser(void) - returns the user id (or UNKNOWN). Allocates char, so caller must free. *----------------------------------------------------------*/ -char *VERuser(void) { +char *VERuser(void) +{ char *user; struct passwd *pw; @@ -443,7 +452,8 @@ char *VERuser(void) { /*---------------------------------------------------------- VERfileTimeStamp(fname) *----------------------------------------------------------*/ -char *VERfileTimeStamp(char *fname) { +char *VERfileTimeStamp(char *fname) +{ struct stat buf; struct tm *lt = NULL; int err; @@ -472,7 +482,8 @@ char *VERfileTimeStamp(char *fname) { VERcurTimeStamp() - time stamp at the time this function is called. *----------------------------------------------------------*/ -char *VERcurTimeStamp(void) { +char *VERcurTimeStamp(void) +{ char tmpstr[2000], *current_time_stamp; time_t seconds; struct tm broken_time; diff --git a/utils/vlabels.c b/utils/vlabels.c index c5a9df89a27..6e686b89963 100644 --- a/utils/vlabels.c +++ b/utils/vlabels.c @@ -34,7 +34,8 @@ extern const char *Progname; -VOXEL_LABELS_IMAGE *VLalloc(int width, int height, int depth, float resolution) { +VOXEL_LABELS_IMAGE *VLalloc(int width, int height, int depth, float resolution) +{ VOXEL_LABELS_IMAGE *vli; VOXEL_LABELS ***vl; int x, y, z; @@ -69,7 +70,8 @@ VOXEL_LABELS_IMAGE *VLalloc(int width, int height, int depth, float resolution) return (vli); } -int VLfree(VLI **pvli) { +int VLfree(VLI **pvli) +{ VLI *vli; int x, y, z; VL ***vl; @@ -100,7 +102,8 @@ int VLfree(VLI **pvli) { return (NO_ERROR); } -int VLwrite(VLI *vli, char *fname) { +int VLwrite(VLI *vli, char *fname) +{ FILE *fp; int x, y, z, n; long here, there; @@ -138,7 +141,8 @@ int VLwrite(VLI *vli, char *fname) { fclose(fp); return (NO_ERROR); } -VLI *VLread(char *fname) { +VLI *VLread(char *fname) +{ FILE *fp; int x, y, z, n, width, height, depth, magic; float resolution; @@ -185,7 +189,8 @@ VLI *VLread(char *fname) { VL *VLreadVoxel(char *fname, int x, int y, int z, VL *vl) { return (vl); } -int VLnormalize(VLI *vli) { +int VLnormalize(VLI *vli) +{ int x, y, z, n; VL *vl; float pct, total; diff --git a/utils/volcluster.c b/utils/volcluster.c index 81c44c40b19..d4d68ab6c94 100644 --- a/utils/volcluster.c +++ b/utils/volcluster.c @@ -48,7 +48,8 @@ const char *vclustSrcVersion(void) { return ("$Id: volcluster.c,v 1.57 2016/11/0 static int ConvertCRS2XYZ(int col, int row, int slc, MATRIX *CRS2XYZ, float *x, float *y, float *z); /*----------------------------------------------------------------*/ -VOLCLUSTER *clustAllocCluster(int nmembers) { +VOLCLUSTER *clustAllocCluster(int nmembers) +{ VOLCLUSTER *vc; vc = (VOLCLUSTER *)calloc(1, sizeof(VOLCLUSTER)); @@ -67,7 +68,8 @@ VOLCLUSTER *clustAllocCluster(int nmembers) { } /*----------------------------------------------------------------*/ -VOLCLUSTER **clustAllocClusterList(int nlist) { +VOLCLUSTER **clustAllocClusterList(int nlist) +{ VOLCLUSTER **vclist; vclist = (VOLCLUSTER **)calloc(nlist, sizeof(VOLCLUSTER *)); if (vclist == NULL) { @@ -78,7 +80,8 @@ VOLCLUSTER **clustAllocClusterList(int nlist) { } /*----------------------------------------------------------------*/ -int clustFreeCluster(VOLCLUSTER **ppvc) { +int clustFreeCluster(VOLCLUSTER **ppvc) +{ VOLCLUSTER *vc; vc = *ppvc; @@ -115,7 +118,8 @@ int clustFreeCluster(VOLCLUSTER **ppvc) { } /*------------------------------------------------------------------------*/ -int clustFreeClusterList(VOLCLUSTER ***pppvclist, int nlist) { +int clustFreeClusterList(VOLCLUSTER ***pppvclist, int nlist) +{ int n; VOLCLUSTER **vclist; vclist = *pppvclist; @@ -132,7 +136,8 @@ int clustFreeClusterList(VOLCLUSTER ***pppvclist, int nlist) { } /*------------------------------------------------------------------------*/ -int clustDumpCluster(FILE *fp, VOLCLUSTER *vc, MRI *vol, int frame) { +int clustDumpCluster(FILE *fp, VOLCLUSTER *vc, MRI *vol, int frame) +{ int n; float val; @@ -142,14 +147,16 @@ int clustDumpCluster(FILE *fp, VOLCLUSTER *vc, MRI *vol, int frame) { if (vol != NULL) { val = MRIgetVoxVal(vol, vc->col[n], vc->row[n], vc->slc[n], frame); fprintf(fp, "%12.5f\n", val); - } else + } + else fprintf(fp, "\n"); } return (0); } /*------------------------------------------------------------------------*/ -int clustDumpClusterList(FILE *fp, VOLCLUSTER **vclist, int nlist, MRI *vol, int frame) { +int clustDumpClusterList(FILE *fp, VOLCLUSTER **vclist, int nlist, MRI *vol, int frame) +{ int n; for (n = 0; n < nlist; n++) { @@ -166,13 +173,15 @@ int clustDumpClusterList(FILE *fp, VOLCLUSTER **vclist, int nlist, MRI *vol, int } /*------------------------------------------------------------------------*/ -int clustValueInRange(float val, float thmin, float thmax, int thsign) { +int clustValueInRange(float val, float thmin, float thmax, int thsign) +{ if (thsign == 0) val = fabs(val); if (thsign == -1) val = -val; if (thmax > 0) { if (val >= thmin && val <= thmax) return 1; - } else { + } + else { if (val >= thmin) return 1; } @@ -190,7 +199,8 @@ MRI *clustInitHitMap(MRI *vol, int **hitrow, int **hitslc, MRI *binmask, - int maskframe) { + int maskframe) +{ MRI *HitMap; int row, col, slc; float val; @@ -278,7 +288,8 @@ MRI *clustInitHitMap(MRI *vol, hslc[nh] = slc; MRIsetVoxVal(HitMap, col, row, slc, 0, 0); nh++; - } else + } + else MRIsetVoxVal(HitMap, col, row, slc, 0, 1); } } @@ -294,7 +305,8 @@ MRI *clustInitHitMap(MRI *vol, } /*------------------------------------------------------------------------*/ -int clustAddMember(VOLCLUSTER *vc, int col, int row, int slc) { +int clustAddMember(VOLCLUSTER *vc, int col, int row, int slc) +{ int nmemb; int *tmp; float *ftmp; @@ -353,7 +365,8 @@ int clustAddMember(VOLCLUSTER *vc, int col, int row, int slc) { } /*------------------------------------------------------------------------*/ -int clustGrowOneVoxel(VOLCLUSTER *vc, int col0, int row0, int slc0, MRI *HitMap, int AllowDiag) { +int clustGrowOneVoxel(VOLCLUSTER *vc, int col0, int row0, int slc0, MRI *HitMap, int AllowDiag) +{ int col, row, slc; int dcol, drow, dslc, dsum; int nadded; @@ -391,7 +404,8 @@ int clustGrowOneVoxel(VOLCLUSTER *vc, int col0, int row0, int slc0, MRI *HitMap, } /*------------------------------------------------------------------------*/ -VOLCLUSTER *clustGrow(int col0, int row0, int slc0, MRI *HitMap, int AllowDiag) { +VOLCLUSTER *clustGrow(int col0, int row0, int slc0, MRI *HitMap, int AllowDiag) +{ VOLCLUSTER *vc; int nthmember, nmembers_now; int col, row, slc; @@ -427,7 +441,8 @@ VOLCLUSTER *clustGrow(int col0, int row0, int slc0, MRI *HitMap, int AllowDiag) } /*-------------------------------------------------------------------*/ -int clustMaxMember(VOLCLUSTER *vc, MRI *vol, int frame, int thsign) { +int clustMaxMember(VOLCLUSTER *vc, MRI *vol, int frame, int thsign) +{ int n; float val = 0.0, val0; @@ -447,7 +462,8 @@ int clustMaxMember(VOLCLUSTER *vc, MRI *vol, int frame, int thsign) { } /*------------------------------------------------------------------------*/ -VOLCLUSTER **clustPruneBySize(VOLCLUSTER **vclist, int nlist, float voxsize, float sizethresh, int *nkeep) { +VOLCLUSTER **clustPruneBySize(VOLCLUSTER **vclist, int nlist, float voxsize, float sizethresh, int *nkeep) +{ VOLCLUSTER **vcprune; int n; float clustersize; @@ -474,7 +490,8 @@ VOLCLUSTER **clustPruneBySize(VOLCLUSTER **vclist, int nlist, float voxsize, flo } /*------------------------------------------------------------------------*/ -VOLCLUSTER **clustPruneByDistance(VOLCLUSTER **vclist, int nlist, float distthresh, int *nkeep) { +VOLCLUSTER **clustPruneByDistance(VOLCLUSTER **vclist, int nlist, float distthresh, int *nkeep) +{ VOLCLUSTER **vcprune; int n1, n2, nmax1, nmax2; float max1, max2; @@ -544,7 +561,8 @@ VOLCLUSTER **clustPruneByDistance(VOLCLUSTER **vclist, int nlist, float distthre /*------------------------------------------------------------------------ Note: Prunes by pvalue so must be LESS than cwpvalthresh NOT -log10(p) ------------------------------------------------------------------------*/ -VOLCLUSTER **clustPruneByCWPval(VOLCLUSTER **vclist, int nlist, double cwpvalthresh, int *nkeep) { +VOLCLUSTER **clustPruneByCWPval(VOLCLUSTER **vclist, int nlist, double cwpvalthresh, int *nkeep) +{ VOLCLUSTER **vcprune; int n; @@ -566,7 +584,8 @@ VOLCLUSTER **clustPruneByCWPval(VOLCLUSTER **vclist, int nlist, double cwpvalthr } /*----------------------------------------------------------------*/ -VOLCLUSTER *clustCopyCluster(VOLCLUSTER *vc) { +VOLCLUSTER *clustCopyCluster(VOLCLUSTER *vc) +{ VOLCLUSTER *vc2; int ncopy; @@ -594,7 +613,8 @@ VOLCLUSTER *clustCopyCluster(VOLCLUSTER *vc) { } /*----------------------------------------------------------------*/ -VOLCLUSTER **clustCopyClusterList(VOLCLUSTER **vclist, int nlist, VOLCLUSTER **vclist2) { +VOLCLUSTER **clustCopyClusterList(VOLCLUSTER **vclist, int nlist, VOLCLUSTER **vclist2) +{ int n; if (vclist2 == NULL) vclist2 = clustAllocClusterList(nlist); @@ -607,7 +627,8 @@ VOLCLUSTER **clustCopyClusterList(VOLCLUSTER **vclist, int nlist, VOLCLUSTER **v } /*----------------------------------------------------------------*/ -int clustCompareCluster(const void *a, const void *b) { +int clustCompareCluster(const void *a, const void *b) +{ VOLCLUSTER *vc1, *vc2; vc1 = *((VOLCLUSTER **)a); @@ -629,7 +650,8 @@ int clustCompareCluster(const void *a, const void *b) { } /*----------------------------------------------------------------*/ -VOLCLUSTER **clustSortClusterList(VOLCLUSTER **vclist, int nlist, VOLCLUSTER **vcsorted) { +VOLCLUSTER **clustSortClusterList(VOLCLUSTER **vclist, int nlist, VOLCLUSTER **vcsorted) +{ if (vcsorted == NULL) vcsorted = clustAllocClusterList(nlist); if (vclist != vcsorted) clustCopyClusterList(vclist, nlist, vcsorted); @@ -644,7 +666,8 @@ VOLCLUSTER **clustSortClusterList(VOLCLUSTER **vclist, int nlist, VOLCLUSTER **v of a cluster given the 4x4 matrix that transforms the col, row, and slice into x, y, and z. ----------------------------------------------------------------*/ -int clustComputeXYZ(VOLCLUSTER *vc, MATRIX *CRS2XYZ) { +int clustComputeXYZ(VOLCLUSTER *vc, MATRIX *CRS2XYZ) +{ int n; for (n = 0; n < vc->nmembers; n++) { @@ -661,7 +684,8 @@ int clustComputeXYZ(VOLCLUSTER *vc, MATRIX *CRS2XYZ) { transformed into talairach coordinates using a piece-wise linear transformation. See FixMNITal in transforms.c. ----------------------------------------------------------------*/ -int clustComputeTal(VOLCLUSTER *vc, MATRIX *CRS2MNI) { +int clustComputeTal(VOLCLUSTER *vc, MATRIX *CRS2MNI) +{ int n; for (n = 0; n < vc->nmembers; n++) { @@ -673,7 +697,8 @@ int clustComputeTal(VOLCLUSTER *vc, MATRIX *CRS2MNI) { } /*----------------------------------------------------------------*/ -MRI *clustClusterList2Vol(VOLCLUSTER **vclist, int nlist, MRI *tvol, int frame, int ValOption) { +MRI *clustClusterList2Vol(VOLCLUSTER **vclist, int nlist, MRI *tvol, int frame, int ValOption) +{ MRI *vol; int nthvc, n, f; VOLCLUSTER *vc; @@ -696,7 +721,8 @@ MRI *clustClusterList2Vol(VOLCLUSTER **vclist, int nlist, MRI *tvol, int frame, val = MRIgetVoxVal(tvol, vc->col[n], vc->row[n], vc->slc[n], f); MRIsetVoxVal(vol, vc->col[n], vc->row[n], vc->slc[n], f, val); } - } else + } + else // Set values to the cluster number MRIsetVoxVal(vol, vc->col[n], vc->row[n], vc->slc[n], 0, nthvc + 1); } @@ -706,7 +732,8 @@ MRI *clustClusterList2Vol(VOLCLUSTER **vclist, int nlist, MRI *tvol, int frame, /*----------------------------------------------------------------*/ LABEL *clustCluster2Label( - VOLCLUSTER *vc, MRI *vol, int frame, float colres, float rowres, float sliceres, MATRIX *FSA2Func) { + VOLCLUSTER *vc, MRI *vol, int frame, float colres, float rowres, float sliceres, MATRIX *FSA2Func) +{ LABEL *label; MATRIX *CRS2Func, *Func2FSA; MATRIX *xyzFunc, *xyzFSA; @@ -763,7 +790,8 @@ VOLCLUSTER **clustGetClusters(MRI *vol, float minclustsizemm3, MRI *binmask, int *nClusters, - MATRIX *XFM) { + MATRIX *XFM) +{ int nthhit, nclusters, nhits, *hitcol = NULL, *hitrow = NULL, *hitslc = NULL; int col, row, slc, allowdiag = 0, nprunedclusters; MRI *HitMap; @@ -853,7 +881,8 @@ VOLCLUSTER **clustGetClusters(MRI *vol, with the largest count. Multiply this by the voxel size to get the max cluster volume. -------------------------------------------------------------*/ -int clustMaxClusterCount(VOLCLUSTER **VolClustList, int nClusters) { +int clustMaxClusterCount(VOLCLUSTER **VolClustList, int nClusters) +{ int n, MaxCount = 0; for (n = 0; n < nClusters; n++) @@ -862,7 +891,8 @@ int clustMaxClusterCount(VOLCLUSTER **VolClustList, int nClusters) { } /*------------------------------------------------------------------------*/ -int clustDumpSummary(FILE *fp, VOLCLUSTER **ClusterList, int nClusters) { +int clustDumpSummary(FILE *fp, VOLCLUSTER **ClusterList, int nClusters) +{ int n, col, row, slc; float x, y, z; @@ -898,7 +928,8 @@ int clustDumpSummary(FILE *fp, VOLCLUSTER **ClusterList, int nClusters) { the transform matrix. This function just hides the matrix operations. ----------------------------------------------------------------*/ -static int ConvertCRS2XYZ(int col, int row, int slc, MATRIX *CRS2XYZ, float *x, float *y, float *z) { +static int ConvertCRS2XYZ(int col, int row, int slc, MATRIX *CRS2XYZ, float *x, float *y, float *z) +{ MATRIX *crs, *xyz; crs = MatrixAlloc(4, 1, MATRIX_REAL); @@ -920,7 +951,8 @@ static int ConvertCRS2XYZ(int col, int row, int slc, MATRIX *CRS2XYZ, float *x, } /*----------------------------------------------------*/ -CHT *CHTalloc(int n_ithr, double ithr_lo, double ithr_hi, int n_sthr, double sthr_lo, double sthr_hi) { +CHT *CHTalloc(int n_ithr, double ithr_lo, double ithr_hi, int n_sthr, double sthr_lo, double sthr_hi) +{ CHT *cht; double dithr, dsthr; int i, v; @@ -954,7 +986,8 @@ CHT *CHTalloc(int n_ithr, double ithr_lo, double ithr_hi, int n_sthr, double sth } /*----------------------------------------------------*/ -int CHTfree(CHT **ppcht) { +int CHTfree(CHT **ppcht) +{ CHT *cht; int i; @@ -970,7 +1003,8 @@ int CHTfree(CHT **ppcht) { } /*----------------------------------------------------*/ -int CHTprint(FILE *fp, CHT *cht) { +int CHTprint(FILE *fp, CHT *cht) +{ int i, v; fprintf(fp, "# CHT 1\n"); @@ -1003,7 +1037,8 @@ int CHTprint(FILE *fp, CHT *cht) { } /*----------------------------------------------------*/ -int CHTwrite(char *fname, CHT *cht) { +int CHTwrite(char *fname, CHT *cht) +{ FILE *fp; fp = fopen(fname, "w"); @@ -1020,7 +1055,8 @@ int CHTwrite(char *fname, CHT *cht) { } /*----------------------------------------------------*/ -CHT *CHTread(char *fname) { +CHT *CHTread(char *fname) +{ CHT *cht; FILE *fp; char tag[1000]; @@ -1124,7 +1160,8 @@ CHT *CHTread(char *fname) { does not trigger a 1 return and allows for values to be filled in. Does not compare seeds. ----------------------------------------------------------------*/ -int CHTcompare(CHT *src, CHT *targ) { +int CHTcompare(CHT *src, CHT *targ) +{ if (targ->nvox < 0) targ->nvox = src->nvox; else if (targ->nvox != src->nvox) @@ -1188,7 +1225,8 @@ int CHTcompare(CHT *src, CHT *targ) { unrecognized, returns 1, otherwise 0. If the string is NULL, abs is used. --------------------------------------------------------------*/ -int CHTsetSignString(CHT *cht, char *ithr_sign) { +int CHTsetSignString(CHT *cht, char *ithr_sign) +{ int ithr_signid; ithr_signid = CHTsignId(ithr_sign); @@ -1208,7 +1246,8 @@ int CHTsetSignString(CHT *cht, char *ithr_sign) { CHTsignId() - converts the sign string to a numeric code. The code is set in the CHT structure and returned. --------------------------------------------------------------*/ -int CHTsignId(char *ithr_sign) { +int CHTsignId(char *ithr_sign) +{ if (ithr_sign == NULL) return (0); // abs if (!strcasecmp(ithr_sign, "pos")) return (+1); @@ -1229,7 +1268,8 @@ int CHTsignId(char *ithr_sign) { /*------------------------------------------------------------ CSDalloc() - just allocs structure and sets some initial vars ------------------------------------------------------------*/ -CLUSTER_SIM_DATA *CSDalloc(void) { +CLUSTER_SIM_DATA *CSDalloc(void) +{ CLUSTER_SIM_DATA *csd; csd = (CLUSTER_SIM_DATA *)calloc(sizeof(CLUSTER_SIM_DATA), 1); @@ -1258,7 +1298,8 @@ CLUSTER_SIM_DATA *CSDalloc(void) { CSDread() - reads a cluster simulation data file. The format of this file is currently defined by mri_glmfit. --------------------------------------------------------------*/ -CLUSTER_SIM_DATA *CSDread(char *csdfile) { +CLUSTER_SIM_DATA *CSDread(char *csdfile) +{ FILE *fp; CLUSTER_SIM_DATA *csd; char tag[1000], tmpstr[1000], c; @@ -1291,7 +1332,8 @@ CLUSTER_SIM_DATA *CSDread(char *csdfile) { fscanf(fp, "%s", csd->subject); fscanf(fp, "%s", csd->hemi); } - } else if (!strcmp(tag, "thresh")) + } + else if (!strcmp(tag, "thresh")) fscanf(fp, "%lf", &(csd->thresh)); else if (!strcmp(tag, "threshsign")) fscanf(fp, "%lf", &(csd->threshsign)); @@ -1318,14 +1360,17 @@ CLUSTER_SIM_DATA *CSDread(char *csdfile) { csd->nreps = nrepstmp; CSDallocData(csd); } - } else if (!strcmp(tag, "nrepetitions")) { + } + else if (!strcmp(tag, "nrepetitions")) { fscanf(fp, "%d", &(csd->nreps)); if (!strcmp(csd->anattype, "surface")) CSDallocData(csd); - } else if (!strcmp(tag, "FixGroupSubjectArea")) + } + else if (!strcmp(tag, "FixGroupSubjectArea")) fscanf(fp, "%d", &(csd->FixGroupSubjectArea)); else fgets(tmpstr, 1000, fp); // not an interesting line, so get past it - } else { + } + else { // ----------- Data ------------ // printf("%s \n",tag); fscanf(fp, "%d", &(csd->nClusters[nthrep])); @@ -1353,7 +1398,8 @@ CLUSTER_SIM_DATA *CSDread(char *csdfile) { same as CSDread(). The purpose is to be able to do somthing like this: csd = CSDreadMerge(csdfile, csd); --------------------------------------------------------------*/ -CLUSTER_SIM_DATA *CSDreadMerge(char *csdfile, CSD *csd) { +CLUSTER_SIM_DATA *CSDreadMerge(char *csdfile, CSD *csd) +{ CLUSTER_SIM_DATA *csd2 = NULL, *csdmerged = NULL; if (csd == NULL) { @@ -1381,7 +1427,8 @@ CLUSTER_SIM_DATA *CSDreadMerge(char *csdfile, CSD *csd) { CSDallocData() - allocates the arrays for a CSD (not the structure iteself). --------------------------------------------------------------*/ -int CSDallocData(CLUSTER_SIM_DATA *csd) { +int CSDallocData(CLUSTER_SIM_DATA *csd) +{ csd->nClusters = (int *)calloc(csd->nreps, sizeof(int)); csd->MaxClusterSize = (double *)calloc(csd->nreps, sizeof(double)); csd->MaxClusterSizeVtx = (double *)calloc(csd->nreps, sizeof(double)); @@ -1396,7 +1443,8 @@ int CSDallocData(CLUSTER_SIM_DATA *csd) { CSDfreeData() - frees the data arrays and sets their pointers to NULL. Does not try to free the structure. --------------------------------------------------------------*/ -int CSDfreeData(CLUSTER_SIM_DATA *csd) { +int CSDfreeData(CLUSTER_SIM_DATA *csd) +{ if (csd->nClusters) { free(csd->nClusters); csd->nClusters = NULL; @@ -1440,7 +1488,8 @@ int CSDfreeData(CLUSTER_SIM_DATA *csd) { allocated. If csdcopy is non-null, the data are freed and then re-allocated. --------------------------------------------------------------*/ -CSD *CSDcopy(CSD *csd, CSD *csdcopy) { +CSD *CSDcopy(CSD *csd, CSD *csdcopy) +{ int nthrep; if (csdcopy == NULL) @@ -1489,7 +1538,8 @@ CSD *CSDcopy(CSD *csd, CSD *csdcopy) { The seed from the first is copied into the merge, and the mergeflag is set to 1. --------------------------------------------------------------*/ -CSD *CSDmerge(CSD *csd1, CSD *csd2) { +CSD *CSDmerge(CSD *csd1, CSD *csd2) +{ int nthrep1, nthrep2, nthrep; CSD *csd; @@ -1584,12 +1634,14 @@ CSD *CSDmerge(CSD *csd1, CSD *csd2) { /*-------------------------------------------------------------- CSDprintHeader() - print CSD header to the given stream. --------------------------------------------------------------*/ -int CSDprintHeader(FILE *fp, CLUSTER_SIM_DATA *csd) { +int CSDprintHeader(FILE *fp, CLUSTER_SIM_DATA *csd) +{ fprintf(fp, "# simtype %s\n", csd->simtype); if (!strcmp(csd->anattype, "surface")) { fprintf(fp, "# anattype %s %s %s\n", csd->anattype, csd->subject, csd->hemi); fprintf(fp, "# FixGroupSubjectArea %d\n", csd->FixGroupSubjectArea); - } else + } + else fprintf(fp, "# anattype %s \n", csd->anattype); fprintf(fp, "# merged %d\n", csd->mergedflag); fprintf(fp, "# contrast %s\n", csd->contrast); @@ -1626,7 +1678,8 @@ int CSDprintHeader(FILE *fp, CLUSTER_SIM_DATA *csd) { fprintf(fp, "# FixSurfClusterArea %d\n", FixSurfClusterArea); // Version of surfcluster.c fprintf(fp, "# %s\n", sculstSrcVersion()); - } else { + } + else { // Volume // Use the original for volume search space fprintf(fp, "# nreps %d\n", csd->nreps); @@ -1638,7 +1691,8 @@ int CSDprintHeader(FILE *fp, CLUSTER_SIM_DATA *csd) { /*-------------------------------------------------------------- CSDprint() - prints a CSD to the given stream. --------------------------------------------------------------*/ -int CSDprint(FILE *fp, CLUSTER_SIM_DATA *csd) { +int CSDprint(FILE *fp, CLUSTER_SIM_DATA *csd) +{ int nthrep; CSDprintHeader(fp, csd); fprintf(fp, "# LoopNo nClusters MaxClustSize MaxSig MaxStat\n"); @@ -1656,7 +1710,8 @@ int CSDprint(FILE *fp, CLUSTER_SIM_DATA *csd) { /*-------------------------------------------------------------- CSDprintWeight() - prints a CSD to the given stream (with nvtx and weight) --------------------------------------------------------------*/ -int CSDprintWeight(FILE *fp, CLUSTER_SIM_DATA *csd) { +int CSDprintWeight(FILE *fp, CLUSTER_SIM_DATA *csd) +{ int nthrep; CSDprintHeader(fp, csd); fprintf(fp, "# LoopNo nClusters MaxClustSize MaxSig MaxStat "); @@ -1684,7 +1739,8 @@ int CSDprintWeight(FILE *fp, CLUSTER_SIM_DATA *csd) { no item from the simulation is larger than ClusterSize, then it is assumed that 1 item is so that things dont break. --------------------------------------------------------------*/ -double CSDpvalClustSize(CLUSTER_SIM_DATA *csd, double ClusterSize, double ciPct, double *pvalLow, double *pvalHi) { +double CSDpvalClustSize(CLUSTER_SIM_DATA *csd, double ClusterSize, double ciPct, double *pvalLow, double *pvalHi) +{ int nthrep, nover, k, nlow, nhi; double pval, psum, pcilow, pcihi; @@ -1732,7 +1788,8 @@ double CSDpvalClustSize(CLUSTER_SIM_DATA *csd, double ClusterSize, double ciPct, greater than the given value (taking into account the sign). -------------------------------------------------------------------------- */ -double CSDpvalMaxSig(double val, CSD *csd) { +double CSDpvalMaxSig(double val, CSD *csd) +{ int n, nover; double pval; @@ -1756,7 +1813,8 @@ double CSDpvalMaxSig(double val, CSD *csd) { Bonferroni correction (eg, 2 for across hemisphere or 3 for across hemis and subcortical). ------------------------------------------------------------------*/ -MRI *CSDpvalMaxSigMap(MRI *sig, CSD *csd, MRI *mask, MRI *vwsig, double *maxmaxsig, int Bonf) { +MRI *CSDpvalMaxSigMap(MRI *sig, CSD *csd, MRI *mask, MRI *vwsig, double *maxmaxsig, int Bonf) +{ int c, r, s, f, nhits, nvox; double m, val, voxsig, pval, maxvoxsig; @@ -1779,7 +1837,8 @@ MRI *CSDpvalMaxSigMap(MRI *sig, CSD *csd, MRI *mask, MRI *vwsig, double *maxmaxs pval = CSDpvalMaxSig(val, csd); if (Bonf > 0) pval = 1 - pow((1 - pval), Bonf); voxsig = -SIGN(val) * log10(pval); - } else + } + else voxsig = 0; if (fabs(voxsig) > 0) nhits++; MRIsetVoxVal(vwsig, c, r, s, f, voxsig); @@ -1802,7 +1861,8 @@ MRI *CSDpvalMaxSigMap(MRI *sig, CSD *csd, MRI *mask, MRI *vwsig, double *maxmaxs CSDcheckSimType() - checks simulation type string to make sure it is one that is recognized. Returns 0 if ok, 1 otherwise. -----------------------------------------------------------------------*/ -int CSDcheckSimType(char *simtype) { +int CSDcheckSimType(char *simtype) +{ if (!strcmp(simtype, "perm")) return (0); if (!strcmp(simtype, "mc-full")) return (0); if (!strcmp(simtype, "mc-z")) return (0); @@ -1814,7 +1874,8 @@ int CSDcheckSimType(char *simtype) { CSDpdf() - computes pdf and cdf of Maximum Cluster Size and Maximum Sig. if nbins < 1, then nbins = sqrt(csd->nreps) -------------------------------------------------------------------*/ -int CSDpdf(CSD *csd, int nbins) { +int CSDpdf(CSD *csd, int nbins) +{ int n, dim; float min, max, ClusterSize; RFS *rfs; @@ -1884,7 +1945,8 @@ int CSDpdf(CSD *csd, int nbins) { if (csd->threshsign >= 0) { for (n = 1; n < csd->ms_pdf->nbins; n++) csd->ms_cdf->counts[n] = csd->ms_cdf->counts[n - 1] + csd->ms_pdf->counts[n]; - } else { + } + else { // For neg sign, integrate from pos to neg because the tail is neg for (n = csd->ms_pdf->nbins - 2; n >= 0; n--) csd->ms_cdf->counts[n] = csd->ms_cdf->counts[n + 1] + csd->ms_pdf->counts[n]; @@ -1894,7 +1956,8 @@ int CSDpdf(CSD *csd, int nbins) { } /*------------------------------------------------------------------------*/ -int CSDprintPDF(FILE *fp, CSD *csd) { +int CSDprintPDF(FILE *fp, CSD *csd) +{ int nthbin; if (csd->mcs_pdf == NULL) { @@ -1923,7 +1986,8 @@ int CSDprintPDF(FILE *fp, CSD *csd) { } /*------------------------------------------------------------------------*/ -int CSDwritePDF(char *fname, CSD *csd) { +int CSDwritePDF(char *fname, CSD *csd) +{ FILE *fp; fp = fopen(fname, "w"); if (!fp) { @@ -1934,7 +1998,8 @@ int CSDwritePDF(char *fname, CSD *csd) { return (0); } /*------------------------------------------------------------------------*/ -int CSDwrite(char *fname, CSD *csd) { +int CSDwrite(char *fname, CSD *csd) +{ FILE *fp; fp = fopen(fname, "w"); if (!fp) { diff --git a/utils/voxlist.c b/utils/voxlist.c index d2fc3d5670e..59ee07da9f2 100644 --- a/utils/voxlist.c +++ b/utils/voxlist.c @@ -37,7 +37,8 @@ extern const char *Progname; VOXEL_LIST *VLSTcreateInRegion( - MRI *mri, float low_val, float hi_val, VOXEL_LIST *vl, int skip, int border_only, MRI_REGION *box) { + MRI *mri, float low_val, float hi_val, VOXEL_LIST *vl, int skip, int border_only, MRI_REGION *box) +{ int x, y, z, f, nvox, i, width, height, depth; double val; @@ -104,7 +105,8 @@ VOXEL_LIST *VLSTcreateInRegion( vl->mri = mri; return (vl); } -VOXEL_LIST *VLSTcreate(MRI *mri, float low_val, float hi_val, VOXEL_LIST *vl, int skip, int border_only) { +VOXEL_LIST *VLSTcreate(MRI *mri, float low_val, float hi_val, VOXEL_LIST *vl, int skip, int border_only) +{ int x, y, z, nvox, i, f; double val; @@ -175,12 +177,14 @@ VOXEL_LIST *VLSTcreate(MRI *mri, float low_val, float hi_val, VOXEL_LIST *vl, in return (vl); } -typedef struct { +typedef struct +{ float vsrc, vdst, xd, yd, zd; int xi, yi, zi; } SORT_VOXEL; -static int compare_sort(const void *psv1, const void *psv2) { +static int compare_sort(const void *psv1, const void *psv2) +{ SORT_VOXEL *sv1, *sv2; sv1 = (SORT_VOXEL *)psv1; @@ -188,22 +192,29 @@ static int compare_sort(const void *psv1, const void *psv2) { if (sv1->vsrc < sv2->vsrc) { return (1); - } else if (sv1->vsrc > sv2->vsrc) { + } + else if (sv1->vsrc > sv2->vsrc) { return (-1); - } else { + } + else { if (sv1->xi < sv2->xi) { return (1); - } else if (sv1->xi > sv2->xi) { + } + else if (sv1->xi > sv2->xi) { return (-1); - } else { + } + else { if (sv1->yi < sv2->yi) { return (1); - } else if (sv1->yi > sv2->yi) { + } + else if (sv1->yi > sv2->yi) { return (-1); - } else { + } + else { if (sv1->zi < sv2->zi) { return (1); - } else if (sv1->zi > sv2->zi) { + } + else if (sv1->zi > sv2->zi) { return (-1); } } @@ -213,7 +224,8 @@ static int compare_sort(const void *psv1, const void *psv2) { return (0); } -VOXEL_LIST *VLSTsort(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst) { +VOXEL_LIST *VLSTsort(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst) +{ SORT_VOXEL *sort_voxels; int n; @@ -249,7 +261,8 @@ VOXEL_LIST *VLSTsort(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst) { return (vl_dst); } -int VLSTfree(VOXEL_LIST **pvl) { +int VLSTfree(VOXEL_LIST **pvl) +{ VOXEL_LIST *vl = *pvl; *pvl = NULL; @@ -272,7 +285,8 @@ int VLSTfree(VOXEL_LIST **pvl) { free(vl); return (NO_ERROR); } -MRI *VLSTcreateMri(VOXEL_LIST *vl, int val) { +MRI *VLSTcreateMri(VOXEL_LIST *vl, int val) +{ int i; MRI *mri; @@ -284,7 +298,8 @@ MRI *VLSTcreateMri(VOXEL_LIST *vl, int val) { return (mri); } -MRI *VLSTaddToMri(VOXEL_LIST *vl, MRI *mri, int val) { +MRI *VLSTaddToMri(VOXEL_LIST *vl, MRI *mri, int val) +{ int i; if (mri == NULL) { @@ -296,7 +311,8 @@ MRI *VLSTaddToMri(VOXEL_LIST *vl, MRI *mri, int val) { } return (mri); } -MRI *VLSTtoMri(VOXEL_LIST *vl, MRI *mri) { +MRI *VLSTtoMri(VOXEL_LIST *vl, MRI *mri) +{ int i; double val; @@ -312,7 +328,8 @@ MRI *VLSTtoMri(VOXEL_LIST *vl, MRI *mri) { return (mri); } -MRI *VLSTvsrcToMri(VOXEL_LIST *vl, MRI *mri) { +MRI *VLSTvsrcToMri(VOXEL_LIST *vl, MRI *mri) +{ int i; double val; @@ -325,7 +342,8 @@ MRI *VLSTvsrcToMri(VOXEL_LIST *vl, MRI *mri) { return (mri); } -VOXEL_LIST *VLSTdilate(VOXEL_LIST *vl, int mode, MRI *mri_exclude) { +VOXEL_LIST *VLSTdilate(VOXEL_LIST *vl, int mode, MRI *mri_exclude) +{ MRI *mri_current, *mri_new; int i, xi, yi, zi, xk, yk, zk, nvox; VOXEL_LIST *vl_exp = NULL; @@ -370,7 +388,8 @@ VOXEL_LIST *VLSTdilate(VOXEL_LIST *vl, int mode, MRI *mri_exclude) { vl_exp->zi[i] = vl->zi[i]; } nvox = vl->nvox; - } else if (mode == VL_DILATE_REPLACE) { + } + else if (mode == VL_DILATE_REPLACE) { vl_exp = (VOXEL_LIST *)calloc(1, sizeof(VOXEL_LIST)); vl_exp->nvox = vl_exp->max_vox = nvox; vl_exp->mri = vl->mri; @@ -407,7 +426,8 @@ VOXEL_LIST *VLSTdilate(VOXEL_LIST *vl, int mode, MRI *mri_exclude) { return (vl_exp); } -void VLSTcomputeStats(VOXEL_LIST *vl) { +void VLSTcomputeStats(VOXEL_LIST *vl) +{ double mean = 0; double std = 0; int i; @@ -435,7 +455,8 @@ void VLSTcomputeStats(VOXEL_LIST *vl) { return; } -int VLSTtransform(VOXEL_LIST *vl, MATRIX *m, MRI *mri, int sample_type) { +int VLSTtransform(VOXEL_LIST *vl, MATRIX *m, MRI *mri, int sample_type) +{ double val, xd, yd, zd; int i; @@ -466,7 +487,8 @@ int VLSTtransform(VOXEL_LIST *vl, MATRIX *m, MRI *mri, int sample_type) { } return (NO_ERROR); } -int VLSTtransformCoords(VOXEL_LIST *vl, MATRIX *m, int skip) { +int VLSTtransformCoords(VOXEL_LIST *vl, MATRIX *m, int skip) +{ double xd, yd, zd, val; int i, x, y, z; static VECTOR *v1 = NULL, *v2; @@ -501,7 +523,8 @@ int VLSTtransformCoords(VOXEL_LIST *vl, MATRIX *m, int skip) { return (NO_ERROR); } -VOXEL_LIST *VLSTcreateFromDifference(MRI *mri1, MRI *mri2, VOXEL_LIST *vl, int target_label) { +VOXEL_LIST *VLSTcreateFromDifference(MRI *mri1, MRI *mri2, VOXEL_LIST *vl, int target_label) +{ int x, y, z, f, nvox, i; double val1, val2; @@ -572,7 +595,8 @@ VOXEL_LIST *VLSTcreateFromDifference(MRI *mri1, MRI *mri2, VOXEL_LIST *vl, int t vl->mri2 = mri2; return (vl); } -VOXEL_LIST *VLSTalloc(int nvox) { +VOXEL_LIST *VLSTalloc(int nvox) +{ VOXEL_LIST *vl; vl = (VOXEL_LIST *)calloc(1, sizeof(VOXEL_LIST)); @@ -593,7 +617,8 @@ VOXEL_LIST *VLSTalloc(int nvox) { ErrorExit(ERROR_NOMEMORY, "VLSTalloc(%d): could not allocate VL struct", nvox); return (vl); } -VOXEL_LIST *VLSTcopy(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst, int start_src_index, int num) { +VOXEL_LIST *VLSTcopy(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst, int start_src_index, int num) +{ int i; if (vl_dst == NULL) vl_dst = VLSTalloc(num); @@ -631,7 +656,8 @@ VOXEL_LIST *VLSTcopy(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst, int start_src_index if (vl_dst->nvox < num) vl_dst->nvox = num; return (vl_dst); } -VOXEL_LIST *VLSTcopyInto(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst, int start_dst_index, int num) { +VOXEL_LIST *VLSTcopyInto(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst, int start_dst_index, int num) +{ int i; if (vl_dst == NULL) vl_dst = VLSTalloc(start_dst_index + num); @@ -669,12 +695,14 @@ VOXEL_LIST *VLSTcopyInto(VOXEL_LIST *vl_src, VOXEL_LIST *vl_dst, int start_dst_i if (vl_dst->nvox < start_dst_index + num) vl_dst->nvox = start_dst_index + num; return (vl_dst); } -int VLSTaddUnique(VOXEL_LIST *vl, int x, int y, int z, float xd, float yd, float zd) { +int VLSTaddUnique(VOXEL_LIST *vl, int x, int y, int z, float xd, float yd, float zd) +{ if (VLSTinList(vl, x, y, z)) return (0); VLSTadd(vl, x, y, z, xd, yd, zd); return (1); } -int VLSTadd(VOXEL_LIST *vl, int x, int y, int z, float xd, float yd, float zd) { +int VLSTadd(VOXEL_LIST *vl, int x, int y, int z, float xd, float yd, float zd) +{ if (vl->nvox >= vl->max_vox) ErrorReturn(ERROR_NOMEMORY, (ERROR_NOMEMORY, "VLSTadd: too many voxels (%d)", vl->max_vox)); vl->xi[vl->nvox] = x; @@ -687,7 +715,8 @@ int VLSTadd(VOXEL_LIST *vl, int x, int y, int z, float xd, float yd, float zd) { return (NO_ERROR); } -int VLSTinList(VOXEL_LIST *vl, int x, int y, int z) { +int VLSTinList(VOXEL_LIST *vl, int x, int y, int z) +{ int n; for (n = 0; n < vl->nvox; n++) @@ -695,7 +724,8 @@ int VLSTinList(VOXEL_LIST *vl, int x, int y, int z) { return (0); } -VOXEL_LIST *VLSTsplineFit(VOXEL_LIST *vl, int num_control) { +VOXEL_LIST *VLSTsplineFit(VOXEL_LIST *vl, int num_control) +{ VOXEL_LIST *vl_spline; int k, i, km1, kp1; float len, total_len, dx, dy, dz, tx, ty, tz; @@ -776,13 +806,15 @@ VOXEL_LIST *VLSTsplineFit(VOXEL_LIST *vl, int num_control) { return (vl_spline); } -int VLSTwriteLabel(VOXEL_LIST *vl, char *fname, MRI_SURFACE *mris, MRI *mri) { +int VLSTwriteLabel(VOXEL_LIST *vl, char *fname, MRI_SURFACE *mris, MRI *mri) +{ LABEL *area = VLSTtoLabel(vl, mris, mri); LabelWrite(area, fname); LabelFree(&area); return (NO_ERROR); } -LABEL *VLSTtoLabel(VOXEL_LIST *vl, MRI_SURFACE *mris, MRI *mri) { +LABEL *VLSTtoLabel(VOXEL_LIST *vl, MRI_SURFACE *mris, MRI *mri) +{ int n; LABEL *area = LabelAlloc(vl->nvox, NULL, ""); double xs, ys, zs; @@ -795,7 +827,8 @@ LABEL *VLSTtoLabel(VOXEL_LIST *vl, MRI_SURFACE *mris, MRI *mri) { area->lv[n].z = zs; area->lv[n].stat = vl->vsrc[n]; } - } else // use scanner coords + } + else // use scanner coords { for (n = 0; n < vl->nvox; n++) { MRIvoxelToWorld(mri, (double)vl->xd[n], (double)vl->yd[n], (double)vl->zd[n], &xs, &ys, &zs); @@ -811,7 +844,8 @@ LABEL *VLSTtoLabel(VOXEL_LIST *vl, MRI_SURFACE *mris, MRI *mri) { return (area); } -VOXEL_LIST *VLSTinterpolate(VOXEL_LIST *vl, float spacing) { +VOXEL_LIST *VLSTinterpolate(VOXEL_LIST *vl, float spacing) +{ int k, nvox, km1, kp1; VOXEL_LIST *vl_interp; float x_k, y_k, z_k, x_kp1, y_kp1, z_kp1, x, y, z, t, dx, dy, dz, mx_k, my_k, mz_k, mx_kp1, my_kp1, mz_kp1, len; @@ -919,7 +953,8 @@ VOXEL_LIST *VLSTinterpolate(VOXEL_LIST *vl, float spacing) { return (vl_interp); } -MRI *VLSTwriteOrderToMRI(VOXEL_LIST *vl, MRI *mri) { +MRI *VLSTwriteOrderToMRI(VOXEL_LIST *vl, MRI *mri) +{ int n; if (mri == NULL) { @@ -933,7 +968,8 @@ MRI *VLSTwriteOrderToMRI(VOXEL_LIST *vl, MRI *mri) { return (mri); } -VOXEL_LIST *VLSTfromMRI(MRI *mri, int vno) { +VOXEL_LIST *VLSTfromMRI(MRI *mri, int vno) +{ VOXEL_LIST *vl; int n; double xd, yd, zd; @@ -949,7 +985,8 @@ VOXEL_LIST *VLSTfromMRI(MRI *mri, int vno) { return (vl); } -int VLSTinterpolateSplineIntoVolume(VOXEL_LIST *vl, MRI *mri, double spacing, VOXEL_LIST *vl_total, float val) { +int VLSTinterpolateSplineIntoVolume(VOXEL_LIST *vl, MRI *mri, double spacing, VOXEL_LIST *vl_total, float val) +{ VOXEL_LIST *vl_interp; vl_interp = VLSTinterpolate(vl, spacing); @@ -959,7 +996,8 @@ int VLSTinterpolateSplineIntoVolume(VOXEL_LIST *vl, MRI *mri, double spacing, VO VLSTfree(&vl_interp); return (NO_ERROR); } -int VLSTinterpolateIntoVolume(VOXEL_LIST *vl, MRI *mri, float val) { +int VLSTinterpolateIntoVolume(VOXEL_LIST *vl, MRI *mri, float val) +{ int n; for (n = 0; n < vl->nvox; n++) MRIinterpolateIntoVolume(mri, vl->xd[n], vl->yd[n], vl->zd[n], val); @@ -967,7 +1005,8 @@ int VLSTinterpolateIntoVolume(VOXEL_LIST *vl, MRI *mri, float val) { return (NO_ERROR); } -double VLSTcomputeEntropy(VOXEL_LIST *vl, MRI *mri, int num) { +double VLSTcomputeEntropy(VOXEL_LIST *vl, MRI *mri, int num) +{ double val, entropy, total; int n; @@ -987,7 +1026,8 @@ double VLSTcomputeEntropy(VOXEL_LIST *vl, MRI *mri, int num) { return (entropy); } -double VLSTcomputeSplineMean(VOXEL_LIST *vl_spline, MRI *mri, double step_size) { +double VLSTcomputeSplineMean(VOXEL_LIST *vl_spline, MRI *mri, double step_size) +{ VOXEL_LIST *vl = VLSTinterpolate(vl_spline, step_size); double mean, val; int n; @@ -1003,7 +1043,8 @@ double VLSTcomputeSplineMean(VOXEL_LIST *vl_spline, MRI *mri, double step_size) return (mean); } -float VLSTcomputeSplineMedian(VOXEL_LIST *vl_spline, MRI *mri, double step_size) { +float VLSTcomputeSplineMedian(VOXEL_LIST *vl_spline, MRI *mri, double step_size) +{ VOXEL_LIST *vl = VLSTinterpolate(vl_spline, step_size); float *vals, median; int n; @@ -1021,7 +1062,8 @@ float VLSTcomputeSplineMedian(VOXEL_LIST *vl_spline, MRI *mri, double step_size) return (median); } -double VLSTcomputeSplineSegmentMean(VOXEL_LIST *vl_spline, MRI *mri, double step_size, int start, int stop) { +double VLSTcomputeSplineSegmentMean(VOXEL_LIST *vl_spline, MRI *mri, double step_size, int start, int stop) +{ VOXEL_LIST *vl = VLSTinterpolate(vl_spline, step_size); double mean, val; int n; @@ -1039,7 +1081,8 @@ double VLSTcomputeSplineSegmentMean(VOXEL_LIST *vl_spline, MRI *mri, double step return (mean); } -double VLSTrmsDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, MRI **pmri_dist) { +double VLSTrmsDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, MRI **pmri_dist) +{ MRI *mri_dist; double dist, rms; int i; @@ -1052,7 +1095,8 @@ double VLSTrmsDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, MRI ** MRIbinarize(mri_tmp, mri_tmp, 1, 0, 1); *pmri_dist = mri_dist = MRIdistanceTransform(mri_tmp, NULL, 1, max_dist, DTRANS_MODE_SIGNED, NULL); MRIfree(&mri_tmp); - } else + } + else mri_dist = *pmri_dist; // already allocated and computed (hopefully!) for (rms = 0.0, i = 0; i < vl2->nvox; i++) { @@ -1064,7 +1108,8 @@ double VLSTrmsDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, MRI ** return (rms); } -double VLSThausdorffDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, MRI **pmri_dist) { +double VLSThausdorffDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, MRI **pmri_dist) +{ MRI *mri_dist; double dist, hdist; int i; @@ -1077,7 +1122,8 @@ double VLSThausdorffDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, MRIbinarize(mri_tmp, mri_tmp, 1, 0, 1); *pmri_dist = mri_dist = MRIdistanceTransform(mri_tmp, NULL, 1, max_dist, DTRANS_MODE_SIGNED, NULL); MRIfree(&mri_tmp); - } else + } + else mri_dist = *pmri_dist; // already allocated and computed (hopefully!) hdist = 0; @@ -1088,7 +1134,8 @@ double VLSThausdorffDistance(VOXEL_LIST *vl1, VOXEL_LIST *vl2, double max_dist, } return (hdist); } -double VLSTmean(VOXEL_LIST *vl, MRI *mri, double *pvar) { +double VLSTmean(VOXEL_LIST *vl, MRI *mri, double *pvar) +{ double mean, var, val; int x, y, z, f, n; @@ -1108,7 +1155,8 @@ double VLSTmean(VOXEL_LIST *vl, MRI *mri, double *pvar) { return (mean); } -int VLSTsample(VOXEL_LIST *vl, MRI *mri) { +int VLSTsample(VOXEL_LIST *vl, MRI *mri) +{ double val; int x, y, z, f, n; @@ -1126,7 +1174,8 @@ int VLSTsample(VOXEL_LIST *vl, MRI *mri) { } return (NO_ERROR); } -int VLSTsampleFloat(VOXEL_LIST *vl, MRI *mri) { +int VLSTsampleFloat(VOXEL_LIST *vl, MRI *mri) +{ double val; double x, y, z; int n, f; @@ -1143,7 +1192,8 @@ int VLSTsampleFloat(VOXEL_LIST *vl, MRI *mri) { return (NO_ERROR); } -int VLmostCommonLabel(VOXEL_LIST *vl) { +int VLmostCommonLabel(VOXEL_LIST *vl) +{ int max_label, *label_counts, n, label, max_label_count; max_label = 0; diff --git a/utils/x3DList.c b/utils/x3DList.c index a53effc4678..bd040751379 100644 --- a/utils/x3DList.c +++ b/utils/x3DList.c @@ -40,7 +40,8 @@ char *x3Lst_ksaErrorString[x3Lst_knNumErrorCodes] = {"No error.", "Invalid error code."}; /* init the space */ -x3Lst_tErr x3Lst_New(x3DListRef *op3DList, int inListSize) { +x3Lst_tErr x3Lst_New(x3DListRef *op3DList, int inListSize) +{ x3DListRef this = NULL; x3Lst_tErr eResult = x3Lst_tErr_NoErr; x3Lst_tPlane plane = 0; @@ -92,7 +93,8 @@ x3Lst_tErr x3Lst_New(x3DListRef *op3DList, int inListSize) { return eResult; } -x3Lst_tErr x3Lst_Delete(x3DListRef *iop3DList) { +x3Lst_tErr x3Lst_Delete(x3DListRef *iop3DList) +{ x3DListRef this = NULL; x3Lst_tErr eResult = x3Lst_tErr_NoErr; x3Lst_tPlane plane = 0; @@ -146,7 +148,8 @@ x3Lst_tErr x3Lst_Delete(x3DListRef *iop3DList) { return eResult; } -x3Lst_tErr x3Lst_GetPlaneSize(x3DListRef this, int *onPlaneSize) { +x3Lst_tErr x3Lst_GetPlaneSize(x3DListRef this, int *onPlaneSize) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; eResult = x3Lst_Verify(this); @@ -173,7 +176,8 @@ x3Lst_tErr x3Lst_GetPlaneSize(x3DListRef this, int *onPlaneSize) { return eResult; } -x3Lst_tErr x3Lst_AddItem(x3DListRef this, xVoxelRef iWhere, void *ipItem) { +x3Lst_tErr x3Lst_AddItem(x3DListRef this, xVoxelRef iWhere, void *ipItem) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; xList_tErr eList = xList_tErr_NoErr; @@ -217,7 +221,8 @@ x3Lst_tErr x3Lst_AddItem(x3DListRef this, xVoxelRef iWhere, void *ipItem) { return eResult; } -x3Lst_tErr x3Lst_RemoveItem(x3DListRef this, xVoxelRef iWhere, void **iopItemToRemove) { +x3Lst_tErr x3Lst_RemoveItem(x3DListRef this, xVoxelRef iWhere, void **iopItemToRemove) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; xList_tErr eList = xList_tErr_NoErr; void *pItemToRemove = NULL; @@ -261,7 +266,8 @@ x3Lst_tErr x3Lst_RemoveItem(x3DListRef this, xVoxelRef iWhere, void **iopItemToR if (xList_tErr_NoErr != eList) { if (xList_tErr_ItemNotInList == eList) { eResult = x3Lst_tErr_ItemNotInSpace; - } else { + } + else { eResult = x3Lst_tErr_ErrorAccessingList; } } @@ -275,7 +281,8 @@ x3Lst_tErr x3Lst_RemoveItem(x3DListRef this, xVoxelRef iWhere, void **iopItemToR return eResult; } -x3Lst_tErr x3Lst_Clear(x3DListRef this) { +x3Lst_tErr x3Lst_Clear(x3DListRef this) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; xList_tErr eList = xList_tErr_NoErr; x3Lst_tPlane plane = 0; @@ -309,7 +316,8 @@ x3Lst_tErr x3Lst_Clear(x3DListRef this) { return eResult; } -x3Lst_tErr x3Lst_IsInList(x3DListRef this, void *ipData, tBoolean *outIsInList) { +x3Lst_tErr x3Lst_IsInList(x3DListRef this, void *ipData, tBoolean *outIsInList) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; xList_tErr eList = xList_tErr_NoErr; x3Lst_tPlane plane = 0; @@ -350,7 +358,8 @@ x3Lst_tErr x3Lst_IsInList(x3DListRef this, void *ipData, tBoolean *outIsInList) return eResult; } -x3Lst_tErr x3Lst_GetItemsInXPlane(x3DListRef this, int inXPlane, xListRef *opList) { +x3Lst_tErr x3Lst_GetItemsInXPlane(x3DListRef this, int inXPlane, xListRef *opList) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; eResult = x3Lst_Verify(this); @@ -374,7 +383,8 @@ x3Lst_tErr x3Lst_GetItemsInXPlane(x3DListRef this, int inXPlane, xListRef *opLis return eResult; } -x3Lst_tErr x3Lst_GetItemsInYPlane(x3DListRef this, int inYPlane, xListRef *opList) { +x3Lst_tErr x3Lst_GetItemsInYPlane(x3DListRef this, int inYPlane, xListRef *opList) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; eResult = x3Lst_Verify(this); @@ -398,7 +408,8 @@ x3Lst_tErr x3Lst_GetItemsInYPlane(x3DListRef this, int inYPlane, xListRef *opLis return eResult; } -x3Lst_tErr x3Lst_GetItemsInZPlane(x3DListRef this, int inZPlane, xListRef *opList) { +x3Lst_tErr x3Lst_GetItemsInZPlane(x3DListRef this, int inZPlane, xListRef *opList) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; eResult = x3Lst_Verify(this); @@ -422,7 +433,8 @@ x3Lst_tErr x3Lst_GetItemsInZPlane(x3DListRef this, int inZPlane, xListRef *opLis return eResult; } -x3Lst_tErr x3Lst_GetItemsInPlane_(x3DListRef this, x3Lst_tPlane iPlane, int inPlaneIndex, xListRef *opList) { +x3Lst_tErr x3Lst_GetItemsInPlane_(x3DListRef this, x3Lst_tPlane iPlane, int inPlaneIndex, xListRef *opList) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; /* make sure the index is in bounds */ @@ -445,7 +457,8 @@ x3Lst_tErr x3Lst_GetItemsInPlane_(x3DListRef this, x3Lst_tPlane iPlane, int inPl return eResult; } -x3Lst_tErr x3Lst_SetComparator(x3DListRef this, xList_tCompare (*iComparator)(void *, void *)) { +x3Lst_tErr x3Lst_SetComparator(x3DListRef this, xList_tCompare (*iComparator)(void *, void *)) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; x3Lst_tPlane plane = 0; int list = 0; @@ -482,7 +495,8 @@ x3Lst_tErr x3Lst_SetComparator(x3DListRef this, xList_tCompare (*iComparator)(vo return eResult; } -x3Lst_tErr x3Lst_Verify(x3DListRef this) { +x3Lst_tErr x3Lst_Verify(x3DListRef this) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; if (NULL == this) { @@ -500,7 +514,8 @@ x3Lst_tErr x3Lst_Verify(x3DListRef this) { return eResult; } -x3Lst_tErr x3Lst_VerifyLocation(x3DListRef this, xVoxelRef iWhere) { +x3Lst_tErr x3Lst_VerifyLocation(x3DListRef this, xVoxelRef iWhere) +{ x3Lst_tErr eResult = x3Lst_tErr_NoErr; if (xVoxl_GetX(iWhere) < 0 || xVoxl_GetX(iWhere) >= this->mnPlaneSize || xVoxl_GetY(iWhere) < 0 || @@ -511,7 +526,8 @@ x3Lst_tErr x3Lst_VerifyLocation(x3DListRef this, xVoxelRef iWhere) { return eResult; } -char *x3Lst_GetErrorString(x3Lst_tErr ieCode) { +char *x3Lst_GetErrorString(x3Lst_tErr ieCode) +{ x3Lst_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= x3Lst_knNumErrorCodes) { diff --git a/utils/xDebug.c b/utils/xDebug.c index 40f8ee063e4..e192337e981 100644 --- a/utils/xDebug.c +++ b/utils/xDebug.c @@ -43,12 +43,14 @@ static char masStackNote[xDbg_knMaxStackDepth][xDbg_knMaxDescLength] = {}; static int mCurrentStackDepth = 0; static void (*mSegfaultFunction)(int) = NULL; -void xDbg_Init(char *isFileName) { +void xDbg_Init(char *isFileName) +{ char sFileName[256] = ""; if (isFileName == NULL) { strcpy(sFileName, ".xdebug"); - } else { + } + else { #ifdef IRIX sprintf(sFileName, ".xdebug_%s", isFileName); #else @@ -62,7 +64,8 @@ void xDbg_Init(char *isFileName) { xDbg_gsRequest = getenv("XDEBUG"); if (NULL == xDbg_gsRequest) { xDbg_gType = xDebug_File; - } else { + } + else { if (strcmp("file", xDbg_gsRequest) == 0) xDbg_gType = xDebug_File; else if (strcmp("stderr", xDbg_gsRequest) == 0) @@ -85,7 +88,8 @@ void xDbg_Init(char *isFileName) { if (xDebug_Print == xDbg_gType) xDbg_gStream = stderr; if (xDebug_Nothing == xDbg_gType) { xDbg_gbOutput = FALSE; - } else { + } + else { xDbg_gbOutput = TRUE; } @@ -96,12 +100,14 @@ void xDbg_Init(char *isFileName) { void xDbg_RegisterSegfaultHandler(void (*iFunction)(int)) { mSegfaultFunction = iFunction; } -void xDbg_ShutDown() { +void xDbg_ShutDown() +{ /* close file if we opened it */ if (xDebug_File == xDbg_gType && NULL != xDbg_gStream) fclose(xDbg_gStream); } -void xDbg_PrintStatus() { +void xDbg_PrintStatus() +{ fprintf(stderr, "output = %d\n", (int)xDbg_gbOutput); fprintf(stderr, "type = %s\n", @@ -117,37 +123,44 @@ void xDbg_PrintStatus() { fprintf(stderr, "stream = NULL\n"); } -void xDbg_PushStack(char *isTitle, char *isNote) { +void xDbg_PushStack(char *isTitle, char *isNote) +{ if (mCurrentStackDepth + 1 < xDbg_knMaxStackDepth) { strncpy(masStackTitle[mCurrentStackDepth], isTitle, xDbg_knMaxDescLength); strncpy(masStackNote[mCurrentStackDepth], isNote, xDbg_knMaxDescLength); ++mCurrentStackDepth; - } else { + } + else { DebugPrint(("Stack limit reached, can't store name.\n")); } } -void xDbg_PopStack() { +void xDbg_PopStack() +{ if (mCurrentStackDepth - 1 >= 0) { --mCurrentStackDepth; strncpy(xDbg_sStackDesc, masStackTitle[mCurrentStackDepth], xDbg_knMaxDescLength); strncpy(xDbg_sCurNoteDesc, masStackNote[mCurrentStackDepth], xDbg_knMaxDescLength); - } else { + } + else { DebugPrint(("ERROR: xDbg_PopStack call when stack is empty.\n")); } } -char *xDbg_GetCurrentFunction() { +char *xDbg_GetCurrentFunction() +{ if (mCurrentStackDepth > 0) { return masStackTitle[mCurrentStackDepth - 1]; - } else { + } + else { return "(No current function)"; } } -void xDbg_PrintStack() { +void xDbg_PrintStack() +{ int nCurDesc = 0; int nSpace = 0; @@ -164,7 +177,8 @@ void xDbg_PrintStack() { } } -void xDbg_SegfaultHandler(int inSignal) { +void xDbg_SegfaultHandler(int inSignal) +{ DebugPrint(("\nSegfault\n%s\n", xDbg_sCurNoteDesc)); /* Keeps us from segfaulting more than once. */ @@ -178,12 +192,14 @@ void xDbg_SegfaultHandler(int inSignal) { if (NULL != mSegfaultFunction) mSegfaultFunction(inSignal); } -void xDbg_Segfault() { +void xDbg_Segfault() +{ char *pBadPtr = 0x0; *pBadPtr = 1; } -void xDbg_Printf(const char *iFormat, ...) { +void xDbg_Printf(const char *iFormat, ...) +{ va_list args; if (xDbg_gbOutput) { @@ -195,7 +211,8 @@ void xDbg_Printf(const char *iFormat, ...) { fflush(xDbg_gStream); } -void xDbg_SetStackDesc(const char *iFormat, ...) { +void xDbg_SetStackDesc(const char *iFormat, ...) +{ #ifdef Solaris strncpy(xDbg_sStackDesc, iFormat, xDbg_knMaxDescLength); #else @@ -212,7 +229,8 @@ void xDbg_SetStackDesc(const char *iFormat, ...) { #endif } -void xDbg_SetCurrentNote(const char *iFormat, ...) { +void xDbg_SetCurrentNote(const char *iFormat, ...) +{ #ifdef Solaris strncpy(xDbg_sCurNoteDesc, iFormat, xDbg_knMaxDescLength); #else diff --git a/utils/xGLutWindow.c b/utils/xGLutWindow.c index ad307e5d20c..6e2686627a5 100644 --- a/utils/xGLutWindow.c +++ b/utils/xGLutWindow.c @@ -37,7 +37,8 @@ static char *ksErrorStrings[xGWin_knNumErrorCodes] = {"No error.", "Invalid input paramter.", "Invalid error code."}; -xGWin_tErr xGWin_New(xGLutWindowRef *oppWindow, int inWidth, int inHeight, char *isTitle) { +xGWin_tErr xGWin_New(xGLutWindowRef *oppWindow, int inWidth, int inHeight, char *isTitle) +{ xGWin_tErr eResult = xGWin_tErr_NoErr; xGLutWindowRef this = NULL; @@ -97,7 +98,8 @@ xGWin_tErr xGWin_New(xGLutWindowRef *oppWindow, int inWidth, int inHeight, char return eResult; } -xGWin_tErr xGWin_Delete(xGLutWindowRef *ioppWindow) { +xGWin_tErr xGWin_Delete(xGLutWindowRef *ioppWindow) +{ xGWin_tErr eResult = xGWin_tErr_NoErr; xGLutWindowRef this = NULL; @@ -133,7 +135,8 @@ xGWin_tErr xGWin_Delete(xGLutWindowRef *ioppWindow) { return eResult; } -xGWin_tErr xGWin_SetWindowTitle(xGLutWindowRef this, char *isTitle) { +xGWin_tErr xGWin_SetWindowTitle(xGLutWindowRef this, char *isTitle) +{ xGWin_tErr eResult = xGWin_tErr_NoErr; // verify it. @@ -156,7 +159,8 @@ xGWin_tErr xGWin_SetWindowTitle(xGLutWindowRef this, char *isTitle) { return eResult; } -xGWin_tErr xGWin_SetEventHandlerFunc(xGLutWindowRef this, xGWin_tEventHandlerFunc ipFunc, void *ipData) { +xGWin_tErr xGWin_SetEventHandlerFunc(xGLutWindowRef this, xGWin_tEventHandlerFunc ipFunc, void *ipData) +{ xGWin_tErr eResult = xGWin_tErr_NoErr; // verify it. @@ -180,7 +184,8 @@ xGWin_tErr xGWin_SetEventHandlerFunc(xGLutWindowRef this, xGWin_tEventHandlerFun return eResult; } -xGWin_tErr xGWin_ActivateIdleEvents(xGLutWindowRef this) { +xGWin_tErr xGWin_ActivateIdleEvents(xGLutWindowRef this) +{ xGWin_tErr eResult = xGWin_tErr_NoErr; int nSaveWindowID = 0; @@ -211,7 +216,8 @@ xGWin_tErr xGWin_ActivateIdleEvents(xGLutWindowRef this) { return eResult; } -xGWin_tErr xGWin_ActivatePassiveMotionEvents(xGLutWindowRef this) { +xGWin_tErr xGWin_ActivatePassiveMotionEvents(xGLutWindowRef this) +{ xGWin_tErr eResult = xGWin_tErr_NoErr; int nSaveWindowID = 0; @@ -242,7 +248,8 @@ xGWin_tErr xGWin_ActivatePassiveMotionEvents(xGLutWindowRef this) { return eResult; } -xGWin_tErr xGWin_Verify(xGLutWindowRef this) { +xGWin_tErr xGWin_Verify(xGLutWindowRef this) +{ xGWin_tErr eResult = xGWin_tErr_NoErr; // check ptr. @@ -265,7 +272,8 @@ xGWin_tErr xGWin_Verify(xGLutWindowRef this) { return eResult; } -char *xGWin_GetErrorString(xGWin_tErr ieCode) { +char *xGWin_GetErrorString(xGWin_tErr ieCode) +{ if (ieCode < 0 || ieCode >= xGWin_knNumErrorCodes) { ieCode = xGWin_tErr_InvalidErrorCode; } @@ -273,7 +281,8 @@ char *xGWin_GetErrorString(xGWin_tErr ieCode) { return ksErrorStrings[ieCode]; } -void xGWin_AddWindowIDToLookupList(int inWindowID, xGLutWindowRef ipWindow) { +void xGWin_AddWindowIDToLookupList(int inWindowID, xGLutWindowRef ipWindow) +{ /* this used to be a list of number/ptr nodes, but the glut specification says that numbers always start at 1 and increase sequentially, so i guess it's okay to use an arrray if you don't mind a fixed number @@ -289,7 +298,8 @@ void xGWin_AddWindowIDToLookupList(int inWindowID, xGLutWindowRef ipWindow) { mLookupList[inWindowID] = ipWindow; } -void xGWin_GetWindowFromID(int inWindowID, xGLutWindowRef *oppWindow) { +void xGWin_GetWindowFromID(int inWindowID, xGLutWindowRef *oppWindow) +{ // check the bounds. if (inWindowID < 0 || inWindowID >= xGWin_knMaxNumWindows) { DebugPrint(("xGWin_AddWindowIDToLookupList: invalid ID: %d\n", inWindowID)); @@ -300,7 +310,8 @@ void xGWin_GetWindowFromID(int inWindowID, xGLutWindowRef *oppWindow) { *oppWindow = mLookupList[inWindowID]; } -void xGWin_RemoveWindowIDFromLookupList(int inWindowID) { +void xGWin_RemoveWindowIDFromLookupList(int inWindowID) +{ // check the bounds. if (inWindowID < 0 || inWindowID >= xGWin_knMaxNumWindows) { DebugPrint(("xGWin_AddWindowIDToLookupList: invalid ID: %d\n", inWindowID)); @@ -311,7 +322,8 @@ void xGWin_RemoveWindowIDFromLookupList(int inWindowID) { mLookupList[inWindowID] = NULL; } -void xGWin_PassEventToCurrentWindow(xGWin_tEventRef ipEvent) { +void xGWin_PassEventToCurrentWindow(xGWin_tEventRef ipEvent) +{ int nWindowID = 0; xGLutWindowRef pWindow = NULL; @@ -325,7 +337,8 @@ void xGWin_PassEventToCurrentWindow(xGWin_tEventRef ipEvent) { // call the window's event handler with the window handler data // and this event. pWindow->mpHandlerFunc(pWindow->mpHandlerFuncData, ipEvent); - } else { + } + else { DebugPrint( ("xGWin_PassEventToCurrentWindow: Couldn't find current" "window, id is %d", @@ -333,7 +346,8 @@ void xGWin_PassEventToCurrentWindow(xGWin_tEventRef ipEvent) { } } -void xGWin_PassEventToAllWindows(xGWin_tEventRef ipEvent) { +void xGWin_PassEventToAllWindows(xGWin_tEventRef ipEvent) +{ int nSaveWindowID = 0; int nWindowID = 0; xGLutWindowRef pWindow = NULL; @@ -361,7 +375,8 @@ void xGWin_PassEventToAllWindows(xGWin_tEventRef ipEvent) { glutSetWindow(nSaveWindowID); } -void xGWin_GLutKeyboardCallback(unsigned char icKey, int inX, int inY) { +void xGWin_GLutKeyboardCallback(unsigned char icKey, int inX, int inY) +{ xGWin_tEventRef pEvent = NULL; int nState = 0; unsigned char ucModifiedKey = 0; @@ -394,7 +409,8 @@ void xGWin_GLutKeyboardCallback(unsigned char icKey, int inX, int inY) { ucModifiedKey = (unsigned char)((int)icKey + ((int)'a' - xGWin_knCtrlA)); if ((ucModifiedKey >= 'a' && ucModifiedKey <= 'z') || (ucModifiedKey >= 'A' && ucModifiedKey <= 'Z')) { pEvent->mKey = ucModifiedKey; - } else { + } + else { /* we also have special codes for the control-number keys. check those. */ switch (icKey) { @@ -435,7 +451,8 @@ void xGWin_GLutKeyboardCallback(unsigned char icKey, int inX, int inY) { xGWin_PassEventToCurrentWindow(pEvent); } -void xGWin_GLutSpecialCallback(int inKey, int inX, int inY) { +void xGWin_GLutSpecialCallback(int inKey, int inX, int inY) +{ xGWin_tEventRef pEvent = NULL; int nState = 0; @@ -500,7 +517,8 @@ static tBoolean mbShiftKey = FALSE; static tBoolean mbCtrlKey = FALSE; static tBoolean mbAltKey = FALSE; -void xGWin_GLutMouseCallback(int inButton, int inState, int inX, int inY) { +void xGWin_GLutMouseCallback(int inButton, int inState, int inX, int inY) +{ xGWin_tEventRef pEvent = NULL; int nState = 0; @@ -535,26 +553,30 @@ void xGWin_GLutMouseCallback(int inButton, int inState, int inX, int inY) { if (nState & GLUT_ACTIVE_SHIFT) { pEvent->mbShiftKey = TRUE; mbShiftKey = TRUE; - } else { + } + else { mbShiftKey = FALSE; } if (nState & GLUT_ACTIVE_CTRL) { pEvent->mbCtrlKey = TRUE; mbCtrlKey = TRUE; - } else { + } + else { mbCtrlKey = FALSE; } if (nState & GLUT_ACTIVE_ALT) { pEvent->mbAltKey = TRUE; mbAltKey = TRUE; - } else { + } + else { mbAltKey = FALSE; } xGWin_PassEventToCurrentWindow(pEvent); } -void xGWin_GLutMotionCallback(int inX, int inY) { +void xGWin_GLutMotionCallback(int inX, int inY) +{ xGWin_tEventRef pEvent = NULL; xGWin_NewEvent(&pEvent); @@ -576,7 +598,8 @@ void xGWin_GLutMotionCallback(int inX, int inY) { xGWin_PassEventToCurrentWindow(pEvent); } -void xGWin_GLutPassiveMotionCallback(int inX, int inY) { +void xGWin_GLutPassiveMotionCallback(int inX, int inY) +{ xGWin_tEventRef pEvent = NULL; xGWin_NewEvent(&pEvent); @@ -598,7 +621,8 @@ void xGWin_GLutPassiveMotionCallback(int inX, int inY) { xGWin_PassEventToCurrentWindow(pEvent); } -void xGWin_GLutResizeCallback(int inWidth, int inHeight) { +void xGWin_GLutResizeCallback(int inWidth, int inHeight) +{ xGWin_tEventRef pEvent; xGWin_NewEvent(&pEvent); @@ -610,7 +634,8 @@ void xGWin_GLutResizeCallback(int inWidth, int inHeight) { xGWin_PassEventToCurrentWindow(pEvent); } -void xGWin_GLutDrawCallback() { +void xGWin_GLutDrawCallback() +{ xGWin_tEventRef pEvent; xGWin_NewEvent(&pEvent); @@ -620,7 +645,8 @@ void xGWin_GLutDrawCallback() { xGWin_PassEventToCurrentWindow(pEvent); } -void xGWin_GLutIdleCallback() { +void xGWin_GLutIdleCallback() +{ xGWin_tEventRef pEvent; xGWin_NewEvent(&pEvent); @@ -630,7 +656,8 @@ void xGWin_GLutIdleCallback() { xGWin_PassEventToCurrentWindow(pEvent); } -void xGWin_RedrawAllWindows() { +void xGWin_RedrawAllWindows() +{ int nSaveWindowID = 0; int nWindowID = 0; xGLutWindowRef pWindow = NULL; @@ -657,7 +684,8 @@ void xGWin_RedrawAllWindows() { glutSetWindow(nSaveWindowID); } -void xGWin_NewEvent(xGWin_tEventRef *oppEvent) { +void xGWin_NewEvent(xGWin_tEventRef *oppEvent) +{ xGWin_tEventRef this = NULL; // allocate event storage. @@ -676,7 +704,8 @@ void xGWin_NewEvent(xGWin_tEventRef *oppEvent) { *oppEvent = this; } -void xGWin_DeleteEvent(xGWin_tEventRef *ioppEvent) { +void xGWin_DeleteEvent(xGWin_tEventRef *ioppEvent) +{ xGWin_tEventRef this = NULL; this = *ioppEvent; @@ -687,7 +716,8 @@ void xGWin_DeleteEvent(xGWin_tEventRef *ioppEvent) { *ioppEvent = NULL; } -void xGWin_DebugPrintEvent(xGWin_tEventRef this) { +void xGWin_DebugPrintEvent(xGWin_tEventRef this) +{ DebugPrint(("XGWin_tEvent:\n")); switch (this->mType) { diff --git a/utils/xGrowableArray.c b/utils/xGrowableArray.c index 52a573be558..aa4e2e1cbc6 100644 --- a/utils/xGrowableArray.c +++ b/utils/xGrowableArray.c @@ -31,7 +31,8 @@ char *xGArr_ksaErrorStrings[xGArr_knNumErrorCodes] = { "No error.", "Invalid object.", "Invalid signature.", "Allocation failed.", "Last item.", "Invalid error code."}; -xGArr_tErr xGArr_New(xGrowableArrayRef *opList, int inSize, int inInitialNumItems) { +xGArr_tErr xGArr_New(xGrowableArrayRef *opList, int inSize, int inInitialNumItems) +{ xGArr_tErr eResult = xGArr_tErr_NoErr; xGrowableArrayRef this = NULL; @@ -79,7 +80,8 @@ xGArr_tErr xGArr_New(xGrowableArrayRef *opList, int inSize, int inInitialNumItem return eResult; } -xGArr_tErr xGArr_Delete(xGrowableArrayRef *iopList) { +xGArr_tErr xGArr_Delete(xGrowableArrayRef *iopList) +{ xGArr_tErr eResult = xGArr_tErr_NoErr; xGrowableArrayRef this = NULL; @@ -117,7 +119,8 @@ xGArr_tErr xGArr_Delete(xGrowableArrayRef *iopList) { return eResult; } -xGArr_tErr xGArr_Add(xGrowableArrayRef this, void *ipSrc) { +xGArr_tErr xGArr_Add(xGrowableArrayRef this, void *ipSrc) +{ xGArr_tErr eResult = xGArr_tErr_NoErr; void *pNewStorage = NULL; @@ -167,7 +170,8 @@ xGArr_tErr xGArr_Add(xGrowableArrayRef this, void *ipSrc) { return eResult; } -xGArr_tErr xGArr_ResetIterator(xGrowableArrayRef this) { +xGArr_tErr xGArr_ResetIterator(xGrowableArrayRef this) +{ xGArr_tErr eResult = xGArr_tErr_NoErr; eResult = xGArr_Verify(this); @@ -190,7 +194,8 @@ xGArr_tErr xGArr_ResetIterator(xGrowableArrayRef this) { return eResult; } -xGArr_tErr xGArr_NextItem(xGrowableArrayRef this, void *opDest) { +xGArr_tErr xGArr_NextItem(xGrowableArrayRef this, void *opDest) +{ xGArr_tErr eResult = xGArr_tErr_NoErr; eResult = xGArr_Verify(this); @@ -223,7 +228,8 @@ xGArr_tErr xGArr_NextItem(xGrowableArrayRef this, void *opDest) { return eResult; } -xGArr_tErr xGArr_Clear(xGrowableArrayRef this) { +xGArr_tErr xGArr_Clear(xGrowableArrayRef this) +{ xGArr_tErr eResult = xGArr_tErr_NoErr; eResult = xGArr_Verify(this); @@ -256,7 +262,8 @@ xGArr_tErr xGArr_Clear(xGrowableArrayRef this) { return eResult; } -xGArr_tErr xGArr_Verify(xGrowableArrayRef this) { +xGArr_tErr xGArr_Verify(xGrowableArrayRef this) +{ xGArr_tErr eResult = xGArr_tErr_NoErr; /* check for null ptr */ @@ -276,7 +283,8 @@ xGArr_tErr xGArr_Verify(xGrowableArrayRef this) { return eResult; } -char *xGArr_GetErrorString(xGArr_tErr ieCode) { +char *xGArr_GetErrorString(xGArr_tErr ieCode) +{ xGArr_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= xGArr_knNumErrorCodes) { diff --git a/utils/xList.c b/utils/xList.c index e113a3a2712..ca10c85d33c 100644 --- a/utils/xList.c +++ b/utils/xList.c @@ -42,7 +42,8 @@ static char *xList_ksaError[xList_knNumErrorCodes] = { "List is empty.", "Invalid error code."}; -xList_tErr xList_New(xListRef *oppList) { +xList_tErr xList_New(xListRef *oppList) +{ xListRef this = NULL; xList_tErr eResult = xList_tErr_NoErr; @@ -75,7 +76,8 @@ xList_tErr xList_New(xListRef *oppList) { return eResult; } -xList_tErr xList_Delete(xListRef *ioppList) { +xList_tErr xList_Delete(xListRef *ioppList) +{ xListRef this = NULL; xList_tErr eResult = xList_tErr_NoErr; @@ -105,7 +107,8 @@ xList_tErr xList_Delete(xListRef *ioppList) { return eResult; } -xList_tErr xList_InsertItem(xListRef this, void *ipItemToInsert) { +xList_tErr xList_InsertItem(xListRef this, void *ipItemToInsert) +{ xList_tErr eResult = xList_tErr_NoErr; xListNodeRef pNewNode = NULL; tBoolean bIsInList = FALSE; @@ -139,7 +142,8 @@ xList_tErr xList_InsertItem(xListRef this, void *ipItemToInsert) { this->mpHead = pNewNode; this->mpNext = pNewNode; this->mpTail = pNewNode; - } else { + } + else { this->mpTail->mpNext = pNewNode; this->mpTail = pNewNode; } @@ -149,7 +153,8 @@ xList_tErr xList_InsertItem(xListRef this, void *ipItemToInsert) { return eResult; } -xList_tErr xList_RemoveItem(xListRef this, void **iopItemToRemove) { +xList_tErr xList_RemoveItem(xListRef this, void **iopItemToRemove) +{ xList_tErr eResult = xList_tErr_NoErr; xListNodeRef pCurNode = NULL; xListNodeRef pBackNode = NULL; @@ -171,7 +176,8 @@ xList_tErr xList_RemoveItem(xListRef this, void **iopItemToRemove) { // compare the nodes. if we found it exit the loop. if (xList_CompareItems_(this, pCurNode->mpData, pItemToRemove) == xList_tCompare_Match) { bFound = TRUE; - } else { + } + else { // next node. pBackNode = pCurNode; pCurNode = pCurNode->mpNext; @@ -188,7 +194,8 @@ xList_tErr xList_RemoveItem(xListRef this, void **iopItemToRemove) { if (NULL == pBackNode) { // node to be deleted is head. this->mpHead = pCurNode->mpNext; - } else { + } + else { // wrap list around it. pBackNode->mpNext = pCurNode->mpNext; @@ -209,7 +216,8 @@ xList_tErr xList_RemoveItem(xListRef this, void **iopItemToRemove) { return eResult; } -xList_tErr xList_IsInList(xListRef this, void *ipItemToFind, tBoolean *obpIsInList) { +xList_tErr xList_IsInList(xListRef this, void *ipItemToFind, tBoolean *obpIsInList) +{ xList_tErr eResult = xList_tErr_NoErr; tBoolean bFound = FALSE; @@ -230,7 +238,8 @@ xList_tErr xList_IsInList(xListRef this, void *ipItemToFind, tBoolean *obpIsInLi return eResult; } -xListNodeRef xList_FindItem_(xListRef this, void *ipItem) { +xListNodeRef xList_FindItem_(xListRef this, void *ipItem) +{ xListNodeRef pCurNode = NULL; // if no comparator, return null. @@ -244,7 +253,8 @@ xListNodeRef xList_FindItem_(xListRef this, void *ipItem) { // compare the nodes. if we found it, return it. if (xList_CompareItems_(this, pCurNode->mpData, ipItem) == xList_tCompare_Match) { return pCurNode; - } else { + } + else { // next node. pCurNode = pCurNode->mpNext; } @@ -254,7 +264,8 @@ xListNodeRef xList_FindItem_(xListRef this, void *ipItem) { return NULL; } -xList_tErr xList_Clear(xListRef this) { +xList_tErr xList_Clear(xListRef this) +{ xList_tErr eResult = xList_tErr_NoErr; xListNodeRef pCurNode = NULL; xListNodeRef pDelNode = NULL; @@ -296,7 +307,8 @@ xList_tErr xList_Clear(xListRef this) { return eResult; } -xList_tErr xList_GetCount(xListRef this, int *opnCount) { +xList_tErr xList_GetCount(xListRef this, int *opnCount) +{ xList_tErr eResult = xList_tErr_NoErr; xListNodeRef pCurNode = NULL; int nCount = 0; @@ -326,7 +338,8 @@ xList_tErr xList_GetCount(xListRef this, int *opnCount) { return eResult; } -xList_tErr xList_GetFirstItem(xListRef this, void **oppFirstItem) { +xList_tErr xList_GetFirstItem(xListRef this, void **oppFirstItem) +{ xList_tErr eResult = xList_tErr_NoErr; // verify the list. @@ -342,7 +355,8 @@ xList_tErr xList_GetFirstItem(xListRef this, void **oppFirstItem) { if (this->mpHead) { // return the data ptr. *oppFirstItem = this->mpHead->mpData; - } else { + } + else { eResult = xList_tErr_ListEmpty; } @@ -351,7 +365,8 @@ xList_tErr xList_GetFirstItem(xListRef this, void **oppFirstItem) { return eResult; } -xList_tErr xList_GetNextItem(xListRef this, void *ipCurrentItem, void **oppNextItem) { +xList_tErr xList_GetNextItem(xListRef this, void *ipCurrentItem, void **oppNextItem) +{ xList_tErr eResult = xList_tErr_NoErr; xListNodeRef pCurNode = NULL; void *pNextItem = NULL; @@ -372,11 +387,13 @@ xList_tErr xList_GetNextItem(xListRef this, void *ipCurrentItem, void **oppNextI if (NULL != pCurNode->mpNext) { // get its data. pNextItem = ((xListNodeRef)pCurNode->mpNext)->mpData; - } else { + } + else { // end of list. eResult = xList_tErr_EndOfList; } - } else { + } + else { // couldn't find item. eResult = xList_tErr_ItemNotInList; } @@ -389,7 +406,8 @@ xList_tErr xList_GetNextItem(xListRef this, void *ipCurrentItem, void **oppNextI return eResult; } -xList_tErr xList_ResetPosition(xListRef this) { +xList_tErr xList_ResetPosition(xListRef this) +{ xList_tErr eResult = xList_tErr_NoErr; // verify the list. @@ -406,7 +424,8 @@ xList_tErr xList_ResetPosition(xListRef this) { return eResult; } -xList_tErr xList_GetNextItemFromPosition(xListRef this, void **oppNextItem) { +xList_tErr xList_GetNextItemFromPosition(xListRef this, void **oppNextItem) +{ xList_tErr eResult = xList_tErr_NoErr; void *pNextItem = NULL; @@ -445,11 +464,13 @@ xList_tErr xList_GetNextItemFromPosition(xListRef this, void **oppNextItem) { return eResult; } -xList_tErr xList_NextFromPos(xListRef this, void **oppNextItem) { +xList_tErr xList_NextFromPos(xListRef this, void **oppNextItem) +{ return xList_GetNextItemFromPosition(this, oppNextItem); } -xList_tErr xList_PushItem(xListRef this, void *ipItemToInsert) { +xList_tErr xList_PushItem(xListRef this, void *ipItemToInsert) +{ xList_tErr eResult = xList_tErr_NoErr; xListNodeRef pNewNode = NULL; tBoolean bIsInList = FALSE; @@ -483,7 +504,8 @@ xList_tErr xList_PushItem(xListRef this, void *ipItemToInsert) { this->mpHead = pNewNode; this->mpNext = pNewNode; this->mpTail = pNewNode; - } else { + } + else { pNewNode->mpNext = this->mpHead; this->mpHead = pNewNode; } @@ -493,7 +515,8 @@ xList_tErr xList_PushItem(xListRef this, void *ipItemToInsert) { return eResult; } -xList_tErr xList_PopItem(xListRef this, void **oppItem) { +xList_tErr xList_PopItem(xListRef this, void **oppItem) +{ xList_tErr eResult = xList_tErr_NoErr; xListNodeRef pDelNode = NULL; void *pItem = NULL; @@ -537,7 +560,8 @@ xList_tErr xList_PopItem(xListRef this, void **oppItem) { return eResult; } -xList_tErr xList_SetComparator(xListRef this, xList_tCompare (*iComparator)(void *, void *)) { +xList_tErr xList_SetComparator(xListRef this, xList_tCompare (*iComparator)(void *, void *)) +{ xList_tErr eResult = xList_tErr_NoErr; // verify the list. @@ -556,15 +580,18 @@ xList_tErr xList_SetComparator(xListRef this, xList_tCompare (*iComparator)(void return eResult; } -xList_tCompare xList_CompareItems_(xListRef this, void *pItemA, void *pItemB) { +xList_tCompare xList_CompareItems_(xListRef this, void *pItemA, void *pItemB) +{ xList_tCompare eResult = xList_tCompare_Match; if (this->mComparator) { eResult = this->mComparator(pItemA, pItemB); - } else { + } + else { if (pItemA == pItemB) { eResult = xList_tCompare_Match; - } else { + } + else { eResult = xList_tCompare_GreaterThan; } } @@ -572,7 +599,8 @@ xList_tCompare xList_CompareItems_(xListRef this, void *pItemA, void *pItemB) { return eResult; } -xList_tErr xList_Verify(xListRef this) { +xList_tErr xList_Verify(xListRef this) +{ xList_tErr eResult = xList_tErr_NoErr; // check pointer. @@ -592,7 +620,8 @@ xList_tErr xList_Verify(xListRef this) { return eResult; } -char *xList_GetErrorString(xList_tErr ieCode) { +char *xList_GetErrorString(xList_tErr ieCode) +{ xList_tErr eCode = ieCode; if (ieCode < xList_tErr_NoErr || ieCode >= xList_knNumErrorCodes) { diff --git a/utils/xSparseVolume.c b/utils/xSparseVolume.c index 07d669a53cc..49b76e3a45c 100644 --- a/utils/xSparseVolume.c +++ b/utils/xSparseVolume.c @@ -39,7 +39,8 @@ char *xSVol_ksaErrorStrings[xSVol_knNumErrorCodes] = { "Index not allocated.", "Invalid error code."}; -xSVol_tErr xSVol_New(xSparseVolumeRef *opVolume, int inXDim, int inYDim, int inZDim) { +xSVol_tErr xSVol_New(xSparseVolumeRef *opVolume, int inXDim, int inYDim, int inZDim) +{ xSVol_tErr eResult = xSVol_tErr_NoErr; xSparseVolumeRef this = NULL; @@ -83,7 +84,8 @@ xSVol_tErr xSVol_New(xSparseVolumeRef *opVolume, int inXDim, int inYDim, int inZ return eResult; } -xSVol_tErr xSVol_Delete(xSparseVolumeRef *iopVolume, xSVol_tDeleteEntryFuncPtr ipDeleteFunc) { +xSVol_tErr xSVol_Delete(xSparseVolumeRef *iopVolume, xSVol_tDeleteEntryFuncPtr ipDeleteFunc) +{ xSVol_tErr eResult = xSVol_tErr_NoErr; xSparseVolumeRef this = NULL; @@ -124,7 +126,8 @@ xSVol_tErr xSVol_Delete(xSparseVolumeRef *iopVolume, xSVol_tDeleteEntryFuncPtr i return eResult; } -xSVol_tErr xSVol_Get(xSparseVolumeRef this, xVoxelRef iWhere, void **oppItem) { +xSVol_tErr xSVol_Get(xSparseVolumeRef this, xVoxelRef iWhere, void **oppItem) +{ xSVol_tErr eResult = xSVol_tErr_NoErr; void *pItem = NULL; @@ -145,9 +148,11 @@ xSVol_tErr xSVol_Get(xSparseVolumeRef this, xVoxelRef iWhere, void **oppItem) { if (xSVol_tErr_IndexNotAllocated == eResult) { pItem = NULL; eResult = xSVol_tErr_NoErr; - } else if (xSVol_tErr_NoErr != eResult) { + } + else if (xSVol_tErr_NoErr != eResult) { goto error; - } else { + } + else { /* find the item. */ pItem = this->mStorage[xVoxl_GetZ(iWhere)][xVoxl_GetY(iWhere)][xVoxl_GetX(iWhere)]; } @@ -166,7 +171,8 @@ xSVol_tErr xSVol_Get(xSparseVolumeRef this, xVoxelRef iWhere, void **oppItem) { return eResult; } -xSVol_tErr xSVol_Set(xSparseVolumeRef this, xVoxelRef iWhere, void *ipItem) { +xSVol_tErr xSVol_Set(xSparseVolumeRef this, xVoxelRef iWhere, void *ipItem) +{ xSVol_tErr eResult = xSVol_tErr_NoErr; eResult = xSVol_Verify(this); @@ -201,7 +207,8 @@ xSVol_tErr xSVol_Set(xSparseVolumeRef this, xVoxelRef iWhere, void *ipItem) { /* clear the error */ eResult = xSVol_tErr_NoErr; - } else if (xSVol_tErr_NoErr != eResult) { + } + else if (xSVol_tErr_NoErr != eResult) { goto error; } @@ -219,7 +226,8 @@ xSVol_tErr xSVol_Set(xSparseVolumeRef this, xVoxelRef iWhere, void *ipItem) { return eResult; } -xSVol_tErr xSVol_Purge(xSparseVolumeRef this, xSVol_tDeleteEntryFuncPtr ipDeleteFunc) { +xSVol_tErr xSVol_Purge(xSparseVolumeRef this, xSVol_tDeleteEntryFuncPtr ipDeleteFunc) +{ xSVol_tErr eResult = xSVol_tErr_NoErr; int nZ = 0; int nY = 0; @@ -265,7 +273,8 @@ xSVol_tErr xSVol_VisitAll(xSparseVolumeRef this, void (*ipVisitFunction)(void *ipItem), void (*ipXFunction)(int inIndex, tBoolean bEntering), void (*ipYFunction)(int inIndex, tBoolean bEntering), - void (*ipZFunction)(int inIndex, tBoolean bEntering)) { + void (*ipZFunction)(int inIndex, tBoolean bEntering)) +{ xSVol_tErr eResult = xSVol_tErr_NoErr; int nX = 0; int nY = 0; @@ -321,7 +330,8 @@ xSVol_tErr xSVol_VisitAll(xSparseVolumeRef this, return eResult; } -xSVol_tErr xSVol_VerifyIndex_(xSparseVolumeRef this, xVoxelRef iIndex) { +xSVol_tErr xSVol_VerifyIndex_(xSparseVolumeRef this, xVoxelRef iIndex) +{ /* check for bounds */ if (xVoxl_GetX(iIndex) < 0 || xVoxl_GetX(iIndex) >= this->mnXDim || xVoxl_GetY(iIndex) < 0 || xVoxl_GetY(iIndex) >= this->mnYDim || xVoxl_GetZ(iIndex) < 0 || xVoxl_GetZ(iIndex) >= this->mnZDim) { @@ -331,12 +341,14 @@ xSVol_tErr xSVol_VerifyIndex_(xSparseVolumeRef this, xVoxelRef iIndex) { /* check if it exists */ if (NULL != this->mStorage[xVoxl_GetZ(iIndex)] && NULL != this->mStorage[xVoxl_GetZ(iIndex)][xVoxl_GetY(iIndex)]) { return xSVol_tErr_NoErr; - } else { + } + else { return xSVol_tErr_IndexNotAllocated; } } -char *xSVol_GetErrorString(xSVol_tErr ieCode) { +char *xSVol_GetErrorString(xSVol_tErr ieCode) +{ xSVol_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= xSVol_knNumErrorCodes) { @@ -346,7 +358,8 @@ char *xSVol_GetErrorString(xSVol_tErr ieCode) { return xSVol_ksaErrorStrings[eCode]; } -xSVol_tErr xSVol_Verify(xSparseVolumeRef this) { +xSVol_tErr xSVol_Verify(xSparseVolumeRef this) +{ xSVol_tErr eResult = xSVol_tErr_NoErr; /* check for null ptr */ diff --git a/utils/xTypes.c b/utils/xTypes.c index e7d81f8f306..431c305605a 100644 --- a/utils/xTypes.c +++ b/utils/xTypes.c @@ -26,13 +26,15 @@ #define xColr_kfHilightAmt 0.3 #define xColr_kfMinHighlightDistance 0.3 -void xColr_SetFloat(xColor3fRef iColor, float ifRed, float ifGreen, float ifBlue) { +void xColr_SetFloat(xColor3fRef iColor, float ifRed, float ifGreen, float ifBlue) +{ iColor->mfRed = ifRed; iColor->mfGreen = ifGreen; iColor->mfBlue = ifBlue; } -void xColr_SetFloatComponent(xColor3fRef iColor, xColr_tComponent iComponent, float ifValue) { +void xColr_SetFloatComponent(xColor3fRef iColor, xColr_tComponent iComponent, float ifValue) +{ switch (iComponent) { case xColr_tComponent_Red: iColor->mfRed = ifValue; @@ -48,7 +50,8 @@ void xColr_SetFloatComponent(xColor3fRef iColor, xColr_tComponent iComponent, fl } } -float xColr_GetFloatComponent(xColor3fRef iColor, xColr_tComponent iComponent) { +float xColr_GetFloatComponent(xColor3fRef iColor, xColr_tComponent iComponent) +{ switch (iComponent) { case xColr_tComponent_Red: return iColor->mfRed; @@ -64,13 +67,15 @@ float xColr_GetFloatComponent(xColor3fRef iColor, xColr_tComponent iComponent) { } } -void xColr_SetInt(xColor3nRef iColor, int inRed, int inGreen, int inBlue) { +void xColr_SetInt(xColor3nRef iColor, int inRed, int inGreen, int inBlue) +{ iColor->mnRed = inRed; iColor->mnGreen = inGreen; iColor->mnBlue = inBlue; } -void xColr_SetIntComponent(xColor3nRef iColor, xColr_tComponent iComponent, int inValue) { +void xColr_SetIntComponent(xColor3nRef iColor, xColr_tComponent iComponent, int inValue) +{ switch (iComponent) { case xColr_tComponent_Red: iColor->mnRed = inValue; @@ -86,7 +91,8 @@ void xColr_SetIntComponent(xColor3nRef iColor, xColr_tComponent iComponent, int } } -int xColr_GetIntComponent(xColor3nRef iColor, xColr_tComponent iComponent) { +int xColr_GetIntComponent(xColor3nRef iColor, xColr_tComponent iComponent) +{ switch (iComponent) { case xColr_tComponent_Red: return iColor->mnRed; @@ -102,13 +108,15 @@ int xColr_GetIntComponent(xColor3nRef iColor, xColr_tComponent iComponent) { } } -void xColr_PackFloatArray(xColor3fRef iColor, float *iafColor) { +void xColr_PackFloatArray(xColor3fRef iColor, float *iafColor) +{ iafColor[0] = iColor->mfRed; iafColor[1] = iColor->mfGreen; iafColor[2] = iColor->mfBlue; } -void xColr_HilightComponent(xColor3fRef iColor, xColr_tComponent iComponent) { +void xColr_HilightComponent(xColor3fRef iColor, xColr_tComponent iComponent) +{ if (NULL == iColor) { return; } diff --git a/utils/xUndoList.c b/utils/xUndoList.c index 48cf2599db0..de68a6ef5ce 100644 --- a/utils/xUndoList.c +++ b/utils/xUndoList.c @@ -47,7 +47,8 @@ static char *xUndL_ksaError[xUndL_knNumErrorCodes] = { xUndL_tErr xUndL_New(xUndoListRef *oppList, xUndL_tSwapFuncPtr ipSwapFunction, - xUndL_tDeleteEntryFuncPtr ipDeleteFunction) { + xUndL_tDeleteEntryFuncPtr ipDeleteFunction) +{ xUndoListRef this = NULL; xUndL_tErr eResult = xUndL_tErr_NoErr; @@ -89,7 +90,8 @@ xUndL_tErr xUndL_New(xUndoListRef *oppList, return eResult; } -xUndL_tErr xUndL_NewList_(xListRef *oppList) { +xUndL_tErr xUndL_NewList_(xListRef *oppList) +{ xListRef pList = NULL; xList_tErr eListResult = xList_tErr_NoErr; xUndL_tErr eResult = xUndL_tErr_NoErr; @@ -112,7 +114,8 @@ xUndL_tErr xUndL_NewList_(xListRef *oppList) { return eResult; } -xUndL_tErr xUndL_Delete(xUndoListRef *ioppList) { +xUndL_tErr xUndL_Delete(xUndoListRef *ioppList) +{ xUndoListRef this = NULL; xUndL_tErr eResult = xUndL_tErr_NoErr; @@ -143,7 +146,8 @@ xUndL_tErr xUndL_Delete(xUndoListRef *ioppList) { return eResult; } -xUndL_tErr xUndL_DeleteList_(xUndoListRef ipUndoList, xListRef *ioppList) { +xUndL_tErr xUndL_DeleteList_(xUndoListRef ipUndoList, xListRef *ioppList) +{ xUndL_tErr eResult = xUndL_tErr_NoErr; xListRef pList = NULL; xList_tErr eListResult = xList_tErr_NoErr; @@ -179,7 +183,8 @@ xUndL_tErr xUndL_DeleteList_(xUndoListRef ipUndoList, xListRef *ioppList) { cleanup: - DebugCode if (xList_tErr_NoErr != eListResult) { + DebugCode if (xList_tErr_NoErr != eListResult) + { DebugPrint(("xUndL_DeleteInternalList(): Error in xList function %d: %s\n", eListResult, xList_GetErrorString(eListResult))); @@ -189,7 +194,8 @@ xUndL_tErr xUndL_DeleteList_(xUndoListRef ipUndoList, xListRef *ioppList) { return eResult; } -xUndL_tErr xUndL_Clear(xUndoListRef ipList) { +xUndL_tErr xUndL_Clear(xUndoListRef ipList) +{ xUndoListRef this = NULL; xUndL_tErr eResult = xUndL_tErr_NoErr; xList_tErr eListResult = xList_tErr_NoErr; @@ -219,7 +225,8 @@ xUndL_tErr xUndL_Clear(xUndoListRef ipList) { return eResult; } -xUndL_tErr xUndL_AddEntry(xUndoListRef ipList, xUndL_tEntryPtr ipEntry) { +xUndL_tErr xUndL_AddEntry(xUndoListRef ipList, xUndL_tEntryPtr ipEntry) +{ xUndoListRef this = NULL; xUndL_tErr eResult = xUndL_tErr_NoErr; xList_tErr eListResult = xList_tErr_NoErr; @@ -243,7 +250,8 @@ xUndL_tErr xUndL_AddEntry(xUndoListRef ipList, xUndL_tEntryPtr ipEntry) { cleanup: - DebugCode if (xList_tErr_NoErr != eListResult) { + DebugCode if (xList_tErr_NoErr != eListResult) + { DebugPrint(("xUndL_AddEntry(): Error in xList function %d: %s\n", eListResult, xList_GetErrorString(eListResult))); } EndDebugCode; @@ -251,7 +259,8 @@ xUndL_tErr xUndL_AddEntry(xUndoListRef ipList, xUndL_tEntryPtr ipEntry) { return eResult; } -xUndL_tErr xUndL_Restore(xUndoListRef ipList) { +xUndL_tErr xUndL_Restore(xUndoListRef ipList) +{ xUndoListRef this = NULL; xUndL_tErr eResult = xUndL_tErr_NoErr; xListRef pSwapList = NULL; @@ -303,7 +312,8 @@ xUndL_tErr xUndL_Restore(xUndoListRef ipList) { // clear the end of list flag if (xList_tErr_EndOfList == eListResult) { eListResult = xList_tErr_NoErr; - } else { + } + else { goto cleanup; } @@ -321,7 +331,8 @@ xUndL_tErr xUndL_Restore(xUndoListRef ipList) { cleanup: - DebugCode if (xList_tErr_NoErr != eListResult) { + DebugCode if (xList_tErr_NoErr != eListResult) + { DebugPrint( ("xUndL_RestoreList(): Error in xList function %d: %s\n", eListResult, xList_GetErrorString(eListResult))); } @@ -330,7 +341,8 @@ xUndL_tErr xUndL_Restore(xUndoListRef ipList) { return eResult; } -xUndL_tErr xUndL_SetPrintFunction(xUndoListRef this, xUndL_tPrintEntryFuncPtr ipPrintFunction) { +xUndL_tErr xUndL_SetPrintFunction(xUndoListRef this, xUndL_tPrintEntryFuncPtr ipPrintFunction) +{ xUndL_tErr eResult = xUndL_tErr_NoErr; // verify ourself. @@ -347,7 +359,8 @@ xUndL_tErr xUndL_SetPrintFunction(xUndoListRef this, xUndL_tPrintEntryFuncPtr ip return eResult; } -xUndL_tErr xUndL_Print(xUndoListRef this) { +xUndL_tErr xUndL_Print(xUndoListRef this) +{ xUndL_tErr eResult = xUndL_tErr_NoErr; xList_tErr eListResult = xList_tErr_NoErr; xUndL_tEntryPtr pItem = NULL; @@ -404,7 +417,8 @@ xUndL_tErr xUndL_Print(xUndoListRef this) { cleanup: - DebugCode if (xList_tErr_NoErr != eListResult) { + DebugCode if (xList_tErr_NoErr != eListResult) + { DebugPrint(("xUndL_PrintList(): Error in xList function %d: %s\n", eListResult, xList_GetErrorString(eListResult))); } EndDebugCode; @@ -412,7 +426,8 @@ xUndL_tErr xUndL_Print(xUndoListRef this) { return eResult; } -xUndL_tErr xUndL_Verify(xUndoListRef ipList) { +xUndL_tErr xUndL_Verify(xUndoListRef ipList) +{ xUndL_tErr eResult = xUndL_tErr_NoErr; // check for a null list ptr. @@ -433,7 +448,8 @@ xUndL_tErr xUndL_Verify(xUndoListRef ipList) { return eResult; } -char *xUndL_GetErrorString(xUndL_tErr ieCode) { +char *xUndL_GetErrorString(xUndL_tErr ieCode) +{ xUndL_tErr eCode = ieCode; if (ieCode < xUndL_tErr_NoErr || ieCode >= xUndL_knNumErrorCodes) { diff --git a/utils/xUtilities.c b/utils/xUtilities.c index b4ff0c4659a..f44cbf8d815 100644 --- a/utils/xUtilities.c +++ b/utils/xUtilities.c @@ -35,7 +35,8 @@ char *xUtil_ksaErrorString[xUtil_tErr_knNumErrorCodes] = {"No error.", "Invalid int xUtil_gCancelListening = 0; int xUtil_gCancelUserCanceled = 0; -xUtil_tErr xUtil_BreakStringIntoPathAndStem(char *isPathAndStem, char *osPath, char *osStem) { +xUtil_tErr xUtil_BreakStringIntoPathAndStem(char *isPathAndStem, char *osPath, char *osStem) +{ xUtil_tErr eResult = xUtil_tErr_NoError; char *sSection = ""; char sPathSection[20][60]; @@ -48,7 +49,8 @@ xUtil_tErr xUtil_BreakStringIntoPathAndStem(char *isPathAndStem, char *osPath, c strcpy(osPath, ""); strcpy(osStem, isPathAndStem); goto cleanup; - } else { + } + else { /* got the first section of the path, now get the rest. */ strcpy(sPathSection[0], sSection); nSection = 1; @@ -81,7 +83,8 @@ xUtil_tErr xUtil_BreakStringIntoPathAndStem(char *isPathAndStem, char *osPath, c return eResult; } -char *xUtil_GetErrorString(xUtil_tErr ieCode) { +char *xUtil_GetErrorString(xUtil_tErr ieCode) +{ xUtil_tErr eCode = ieCode; if (ieCode < 0 || ieCode >= xUtil_tErr_knNumErrorCodes) { @@ -96,14 +99,16 @@ struct timeval sEndTime = {}; void xUtil_StartTimer() { gettimeofday(&sStartTime, NULL); } -void xUtil_StopTimer(char *isMessage) { +void xUtil_StopTimer(char *isMessage) +{ gettimeofday(&sEndTime, NULL); if (NULL != isMessage) { DebugPrint(("%s: %lu usec\n", isMessage, (sEndTime.tv_sec * 1000000 + sEndTime.tv_usec) - (sStartTime.tv_sec * 1000000 + sStartTime.tv_usec))); - } else { + } + else { DebugPrint(("Timer stopped: %lu usec\n", (sEndTime.tv_sec * 1000000 + sEndTime.tv_usec) - (sStartTime.tv_sec * 1000000 + sStartTime.tv_usec))); } @@ -111,7 +116,8 @@ void xUtil_StopTimer(char *isMessage) { void xUtil_strcpy(char *ipDest, char *ipSrc) { strcpy(ipDest, ipSrc); } -void xUtil_strncpy(char *ipDest, char *ipSrc, int inSize) { +void xUtil_strncpy(char *ipDest, char *ipSrc, int inSize) +{ strncpy(ipDest, ipSrc, inSize); if (ipDest[inSize - 1] != '\0') { @@ -122,7 +128,8 @@ void xUtil_strncpy(char *ipDest, char *ipSrc, int inSize) { } } -void xUtil_sprintf(char *ipDest, char *isFormat, ...) { +void xUtil_sprintf(char *ipDest, char *isFormat, ...) +{ va_list args; va_start(args, isFormat); @@ -130,7 +137,8 @@ void xUtil_sprintf(char *ipDest, char *isFormat, ...) { va_end(args); } -void xUtil_snprintf(char *ipDest, int inSize, char *isFormat, ...) { +void xUtil_snprintf(char *ipDest, int inSize, char *isFormat, ...) +{ va_list args; memset(ipDest, 0, inSize); @@ -151,34 +159,40 @@ void xUtil_snprintf(char *ipDest, int inSize, char *isFormat, ...) { } } -void xUtil_InitializeUserCancel() { +void xUtil_InitializeUserCancel() +{ /* init the flags and register our handler. */ xUtil_gCancelListening = 0; xUtil_gCancelUserCanceled = 0; signal(SIGINT, xUtil_HandleUserCancelCallback); } -void xUtil_StartListeningForUserCancel() { +void xUtil_StartListeningForUserCancel() +{ /* set our listening flag. */ xUtil_gCancelListening = 1; } -void xUtil_StopListeningForUserCancel() { +void xUtil_StopListeningForUserCancel() +{ /* stop listening and reset the canceled flag. */ xUtil_gCancelListening = 0; xUtil_gCancelUserCanceled = 0; } -int xUtil_DidUserCancel() { +int xUtil_DidUserCancel() +{ /* just return the canceled flag. */ return xUtil_gCancelUserCanceled; } -void xUtil_HandleUserCancelCallback(int signal) { +void xUtil_HandleUserCancelCallback(int signal) +{ /* if we're listening, set the flag, if not, exit normally. */ if (xUtil_gCancelListening) { xUtil_gCancelUserCanceled = 1; - } else { + } + else { printf("Killed\n"); fflush(stdout); exit(1); diff --git a/utils/xVoxel.c b/utils/xVoxel.c index 80ca92e4a4a..56db43c5743 100644 --- a/utils/xVoxel.c +++ b/utils/xVoxel.c @@ -26,12 +26,14 @@ #include #include "xDebug.h" -void xVoxl_New(xVoxelRef *oppVoxel) { +void xVoxl_New(xVoxelRef *oppVoxel) +{ xVoxelRef this = (xVoxelRef)calloc(1, sizeof(xVoxel)); *oppVoxel = this; } -void xVoxl_Delete(xVoxelRef *ioppVoxel) { +void xVoxl_Delete(xVoxelRef *ioppVoxel) +{ xVoxelRef this = NULL; if (NULL == ioppVoxel) { @@ -44,25 +46,30 @@ void xVoxl_Delete(xVoxelRef *ioppVoxel) { *ioppVoxel = NULL; } -void xVoxl_Copy(xVoxelRef ipVoxDest, xVoxelRef ipVoxSrc) { +void xVoxl_Copy(xVoxelRef ipVoxDest, xVoxelRef ipVoxSrc) +{ xVoxl_SetFloat(ipVoxDest, xVoxl_GetFloatX(ipVoxSrc), xVoxl_GetFloatY(ipVoxSrc), xVoxl_GetFloatZ(ipVoxSrc)); } -char xVoxl_IsEqualInt(xVoxelRef ipVox1, xVoxelRef ipVox2) { +char xVoxl_IsEqualInt(xVoxelRef ipVox1, xVoxelRef ipVox2) +{ if (xVoxl_GetX(ipVox1) == xVoxl_GetX(ipVox2) && xVoxl_GetY(ipVox1) == xVoxl_GetY(ipVox2) && xVoxl_GetZ(ipVox1) == xVoxl_GetZ(ipVox2)) { return TRUE; - } else { + } + else { return FALSE; } } -char xVoxl_IsEqualFloat(xVoxelRef ipVox1, xVoxelRef ipVox2) { +char xVoxl_IsEqualFloat(xVoxelRef ipVox1, xVoxelRef ipVox2) +{ if (fabs(xVoxl_GetFloatX(ipVox1) - xVoxl_GetFloatX(ipVox2)) < 0.0001 && fabs(xVoxl_GetFloatY(ipVox1) - xVoxl_GetFloatY(ipVox2)) < 0.0001 && fabs(xVoxl_GetFloatZ(ipVox1) - xVoxl_GetFloatZ(ipVox2)) < 0.0001) { return TRUE; - } else { + } + else { return FALSE; } } @@ -70,7 +77,8 @@ char xVoxl_IsEqualFloat(xVoxelRef ipVox1, xVoxelRef ipVox2) { /* declare non-macro versions of this stuff. */ #ifndef XVOXL_USE_MACROS -void xVoxl_Set(xVoxelRef this, int x, int y, int z) { +void xVoxl_Set(xVoxelRef this, int x, int y, int z) +{ this->mfX = x; this->mfY = y; this->mfZ = z; @@ -88,7 +96,8 @@ int xVoxl_GetRoundY(xVoxelRef this) { return rint(this->mfY); } int xVoxl_GetRoundZ(xVoxelRef this) { return rint(this->mfZ); } -void xVoxl_SetFloat(xVoxelRef this, float x, float y, float z) { +void xVoxl_SetFloat(xVoxelRef this, float x, float y, float z) +{ this->mfX = x; this->mfY = y; this->mfZ = z; @@ -114,69 +123,84 @@ float xVoxl_GetFloatZ(xVoxelRef this) { return this->mfZ; } #endif /* XVOXL_USE_MACROS */ -tBoolean xVoxl_IncrementWithMinUntilLimit(xVoxelRef this, float inMin, float inLimit) { +tBoolean xVoxl_IncrementWithMinUntilLimit(xVoxelRef this, float inMin, float inLimit) +{ if (this->mfX < inLimit) { this->mfX += 1.0; return TRUE; - } else if (this->mfY < inLimit) { + } + else if (this->mfY < inLimit) { this->mfX = inMin; this->mfY += 1.0; return TRUE; - } else if (this->mfZ < inLimit) { + } + else if (this->mfZ < inLimit) { this->mfX = inMin; this->mfY = inMin; this->mfZ += 1.0; return TRUE; - } else { + } + else { return FALSE; } } -tBoolean xVoxl_IncrementUntilLimit(xVoxelRef this, float inLimit) { +tBoolean xVoxl_IncrementUntilLimit(xVoxelRef this, float inLimit) +{ return xVoxl_IncrementWithMinUntilLimit(this, 0, inLimit); } -tBoolean xVoxl_IncrementUntilLimits(xVoxelRef this, float inXLimit, float inYLimit, float inZLimit) { +tBoolean xVoxl_IncrementUntilLimits(xVoxelRef this, float inXLimit, float inYLimit, float inZLimit) +{ if (this->mfX < inXLimit) { this->mfX += 1.0; return TRUE; - } else if (this->mfY < inYLimit) { + } + else if (this->mfY < inYLimit) { this->mfX = 0; this->mfY += 1.0; return TRUE; - } else if (this->mfZ < inZLimit) { + } + else if (this->mfZ < inZLimit) { this->mfX = 0; this->mfY = 0; this->mfZ += 1.0; return TRUE; - } else { + } + else { return FALSE; } } tBoolean xVoxl_IncrementWithMinsUntilLimits( - xVoxelRef this, float inXMin, float inYMin, float inXLimit, float inYLimit, float inZLimit) { + xVoxelRef this, float inXMin, float inYMin, float inXLimit, float inYLimit, float inZLimit) +{ if (this->mfX < inXLimit) { this->mfX += 1.0; return TRUE; - } else if (this->mfY < inYLimit) { + } + else if (this->mfY < inYLimit) { this->mfX = inXMin; this->mfY += 1.0; return TRUE; - } else if (this->mfZ < inZLimit) { + } + else if (this->mfZ < inZLimit) { this->mfX = inXMin; this->mfY = inYMin; this->mfZ += 1.0; return TRUE; - } else { + } + else { return FALSE; } } -int xVoxl_ExpandToIndex(xVoxelRef this, int inDimensionX, int inDimensionY) { +int xVoxl_ExpandToIndex(xVoxelRef this, int inDimensionX, int inDimensionY) +{ return (this->mfZ * inDimensionX * inDimensionY) + (this->mfY * inDimensionX) + this->mfX; } -void xVoxl_PrintDebug(xVoxelRef this) { +void xVoxl_PrintDebug(xVoxelRef this) +{ DebugPrint(("Voxel: %d, %d, %d\n", xVoxl_GetX(this), xVoxl_GetY(this), xVoxl_GetZ(this))); } diff --git a/utils/xmlToHtml.c b/utils/xmlToHtml.c index 8d342bdae52..c1fa298459a 100644 --- a/utils/xmlToHtml.c +++ b/utils/xmlToHtml.c @@ -43,7 +43,8 @@ int tagNameIs(char *c, xmlNodePtr cur); int wrdLen(char *c); //------------------------------------------------------------------- -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ xmlDocPtr doc; xmlNodePtr cur; @@ -119,7 +120,8 @@ int main(int argc, char *argv[]) { fprintf(outFile, " \n"); } justArg = 0; - } else if (tagNameIs("explanation", argumentElement)) { + } + else if (tagNameIs("explanation", argumentElement)) { fprintf(outFile, "\n\n \n"); } if (tagNameIs("argument", argumentElement) || tagNameIs("output", argumentElement)) { @@ -132,7 +134,8 @@ int main(int argc, char *argv[]) { intro = malloc(strlen("\n

") + strlen(c) + 100); strcpy(intro, "\n

"); first = 0; - } else { + } + else { intro = malloc(strlen("\n\n

") + strlen(c) + 100); strcpy(intro, "\n\n

"); } @@ -161,11 +164,13 @@ int main(int argc, char *argv[]) { fprintf(outFile, "%s\n", intro); // HACK this causes crash, debug it: free(intro); justIntro = 1; - } else { + } + else { if (first) { first = 0; - } else if ((tagNameIs("argument", argumentElement) || tagNameIs("output", argumentElement)) && - !justIntro) { + } + else if ((tagNameIs("argument", argumentElement) || tagNameIs("output", argumentElement)) && + !justIntro) { fprintf(outFile, "\n"); } @@ -206,7 +211,8 @@ int main(int argc, char *argv[]) { } // Changes a string to unpper case -void toUpperCase(char *c) { +void toUpperCase(char *c) +{ int i; for (i = 0; *(c + i) != '\0'; i++) { *(c + i) = toupper(*(c + i)); @@ -214,7 +220,8 @@ void toUpperCase(char *c) { } // Prints the name of a tag in the correct format -void printName(xmlNodePtr cur, FILE *f) { +void printName(xmlNodePtr cur, FILE *f) +{ xmlChar *n; n = (xmlChar *)cur->name; toUpperCase((char *)n); @@ -223,7 +230,8 @@ void printName(xmlNodePtr cur, FILE *f) { } // Replaces the first underscore in a string with a space -void replaceUnderscore(char *c) { +void replaceUnderscore(char *c) +{ char *pos = strchr(c, '_'); if (pos != NULL) { *pos = ' '; @@ -231,7 +239,8 @@ void replaceUnderscore(char *c) { } // Prints the text of a tag in the corect format -void printContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) { +void printContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) +{ xmlChar *contents; contents = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); unsigned int i; @@ -239,13 +248,17 @@ void printContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) { for (i = 0; i < strlen((char *)contents); i++) { if (*(contents + i) == '\n') { fprintf(f, "
"); - } else if (*(contents + i) == '<') { + } + else if (*(contents + i) == '<') { fprintf(f, "<"); - } else if (*(contents + i) == '>') { + } + else if (*(contents + i) == '>') { fprintf(f, ">"); - } else if (*(contents + i) == '&') { + } + else if (*(contents + i) == '&') { fprintf(f, "&"); - } else if (*(contents + i) == '\"') + } + else if (*(contents + i) == '\"') fprintf(f, "\\\""); else { fprintf(f, "%c", *(contents + i)); @@ -256,7 +269,8 @@ void printContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) { } // Prints the text of a tag in the corect format -void printTableContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) { +void printTableContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) +{ xmlChar *contents; contents = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); unsigned int i; @@ -265,19 +279,24 @@ void printTableContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) { } if (tagNameIs("intro", cur)) { fprintf(f, "


"); - } else { + } + else { fprintf(f, ""); } for (i = 0; i < strlen((char *)contents); i++) { if (*(contents + i) == '\n') { fprintf(f, "
"); - } else if (*(contents + i) == '<') { + } + else if (*(contents + i) == '<') { fprintf(f, "<"); - } else if (*(contents + i) == '>') { + } + else if (*(contents + i) == '>') { fprintf(f, ">"); - } else if (*(contents + i) == '&') { + } + else if (*(contents + i) == '&') { fprintf(f, "&"); - } else if (*(contents + i) == '\"') + } + else if (*(contents + i) == '\"') fprintf(f, "\\\""); else { fprintf(f, "%c", *(contents + i)); @@ -291,7 +310,8 @@ void printTableContents(xmlDocPtr doc, xmlNodePtr cur, FILE *f) { } // Checks if the name of the tag is the same as the string parameter -int tagNameIs(char *c, xmlNodePtr cur) { +int tagNameIs(char *c, xmlNodePtr cur) +{ if (cur == NULL) { return 0; } @@ -301,7 +321,8 @@ int tagNameIs(char *c, xmlNodePtr cur) { // Counts the number of chars until the next space, dash, underscore, slash, // or end of the string // Used to keep a word from running on two lines -int wrdLen(char *c) { +int wrdLen(char *c) +{ int i; for (i = 0; i < strlen(c); i++) if (*(c + i) == ' ' || *(c + i) == '_' || *(c + i) == '/') { diff --git a/utils/znzlib.c b/utils/znzlib.c index 7631eb69ad8..00607ebdf36 100644 --- a/utils/znzlib.c +++ b/utils/znzlib.c @@ -48,7 +48,8 @@ use_compression!=0 uses zlib (gzip) compression */ -znzFile znzopen(const char *path, const char *mode, int use_compression) { +znzFile znzopen(const char *path, const char *mode, int use_compression) +{ znzFile file; file = (znzFile)calloc(1, sizeof(struct znzptr)); if (file == NULL) { @@ -67,7 +68,8 @@ znzFile znzopen(const char *path, const char *mode, int use_compression) { free(file); file = NULL; } - } else { + } + else { #endif file->withz = 0; @@ -83,7 +85,8 @@ znzFile znzopen(const char *path, const char *mode, int use_compression) { return file; } -znzFile znzdopen(int fd, const char *mode, int use_compression) { +znzFile znzdopen(int fd, const char *mode, int use_compression) +{ znzFile file; file = (znzFile)calloc(1, sizeof(struct znzptr)); if (file == NULL) { @@ -95,7 +98,8 @@ znzFile znzdopen(int fd, const char *mode, int use_compression) { file->withz = 1; file->zfptr = gzdopen(fd, mode); file->nzfptr = NULL; - } else { + } + else { #endif file->withz = 0; #ifdef HAVE_FDOPEN @@ -108,7 +112,8 @@ znzFile znzdopen(int fd, const char *mode, int use_compression) { return file; } -int Xznzclose(znzFile *file) { +int Xznzclose(znzFile *file) +{ int retval = 0; if (*file != NULL) { #ifdef HAVE_ZLIB @@ -126,7 +131,8 @@ int Xznzclose(znzFile *file) { return retval; } -size_t znzread(void *buf, size_t size, size_t nmemb, znzFile file) { +size_t znzread(void *buf, size_t size, size_t nmemb, znzFile file) +{ if (file == NULL) { return 0; } @@ -136,7 +142,8 @@ size_t znzread(void *buf, size_t size, size_t nmemb, znzFile file) { return fread(buf, size, nmemb, file->nzfptr); } -size_t znzwrite(void *buf, size_t size, size_t nmemb, znzFile file) { +size_t znzwrite(void *buf, size_t size, size_t nmemb, znzFile file) +{ if (file == NULL) { return 0; } @@ -146,7 +153,8 @@ size_t znzwrite(void *buf, size_t size, size_t nmemb, znzFile file) { return fwrite(buf, size, nmemb, file->nzfptr); } -long znzseek(znzFile file, long offset, int whence) { +long znzseek(znzFile file, long offset, int whence) +{ if (file == NULL) { return 0; } @@ -156,7 +164,8 @@ long znzseek(znzFile file, long offset, int whence) { return fseek(file->nzfptr, offset, whence); } -int znzrewind(znzFile stream) { +int znzrewind(znzFile stream) +{ if (stream == NULL) { return 0; } @@ -167,7 +176,8 @@ int znzrewind(znzFile stream) { return 0; } -long znztell(znzFile file) { +long znztell(znzFile file) +{ if (file == NULL) { return 0; } @@ -177,7 +187,8 @@ long znztell(znzFile file) { return ftell(file->nzfptr); } -int znzputs(char *str, znzFile file) { +int znzputs(char *str, znzFile file) +{ if (file == NULL) { return 0; } @@ -187,7 +198,8 @@ int znzputs(char *str, znzFile file) { return fputs(str, file->nzfptr); } -char *znzgets(char *str, int size, znzFile file) { +char *znzgets(char *str, int size, znzFile file) +{ if (file == NULL) { return NULL; } @@ -197,7 +209,8 @@ char *znzgets(char *str, int size, znzFile file) { return fgets(str, size, file->nzfptr); } -int znzflush(znzFile file) { +int znzflush(znzFile file) +{ if (file == NULL) { return 0; } @@ -207,7 +220,8 @@ int znzflush(znzFile file) { return fflush(file->nzfptr); } -int znzeof(znzFile file) { +int znzeof(znzFile file) +{ if (file == NULL) { return 0; } @@ -217,7 +231,8 @@ int znzeof(znzFile file) { return feof(file->nzfptr); } -int znzputc(int c, znzFile file) { +int znzputc(int c, znzFile file) +{ if (file == NULL) { return 0; } @@ -227,7 +242,8 @@ int znzputc(int c, znzFile file) { return fputc(c, file->nzfptr); } -int znzgetc(znzFile file) { +int znzgetc(znzFile file) +{ if (file == NULL) { return 0; } @@ -238,7 +254,8 @@ int znzgetc(znzFile file) { } #if !defined(WIN32) -int znzprintf(znzFile stream, const char *format, ...) { +int znzprintf(znzFile stream, const char *format, ...) +{ int retval = 0; #ifdef HAVE_ZLIB char *tmpstr = NULL; @@ -260,7 +277,8 @@ int znzprintf(znzFile stream, const char *format, ...) { vsprintf(tmpstr, format, va); retval = gzprintf(stream->zfptr, "%s", tmpstr); free(tmpstr); - } else + } + else #endif { retval = vfprintf(stream->nzfptr, format, va);