/*---------------------------------------------------------------------- Parameters: Description: ----------------------------------------------------------------------*/ MRI_SURFACE * center_brain(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst) { int fno, vno ; FACE *face ; VERTEX *vdst; float x, y, z, x0, y0, z0 ; if (!mris_dst) mris_dst = MRISclone(mris_src) ; x0 = y0 = z0 = 0 ; /* silly compiler warning */ for (fno = 0 ; fno < mris_src->nfaces ; fno++) { face = &mris_dst->faces[fno] ; if (face->ripflag) continue ; x = mris_dst->vertices[face->v[0]].x; y = mris_dst->vertices[face->v[0]].y; z = mris_dst->vertices[face->v[0]].z; x += mris_dst->vertices[face->v[1]].x; y += mris_dst->vertices[face->v[1]].y; z += mris_dst->vertices[face->v[1]].z; x += mris_dst->vertices[face->v[2]].x; y += mris_dst->vertices[face->v[2]].y; z += mris_dst->vertices[face->v[2]].z; x /= face->area; y/= face->area; z/= face->area; x0 += x; y0 += y; z0 += z; } x0 /= mris_dst->total_area ; y0 /= mris_dst->total_area ; z0 /= mris_dst->total_area ; for (vno = 0 ; vno < mris_src->nvertices ; vno++) { vdst = &mris_dst->vertices[vno] ; if (vdst->ripflag) continue ; vdst->x -= x0 ; vdst->y -= y0 ; vdst->z -= z0 ; } mris_dst->xctr = mris_dst->yctr = mris_dst->zctr = 0 ; return(mris_dst) ; }
MRI_SURFACE * MRISprojectOntoTranslatedSphere(MRI_SURFACE *mris_src, MRI_SURFACE *mris_dst, double r, double x0, double y0, double z0) { VERTEX *v; int vno ; double x, y, z, d, dx, dy, dz, dist, total_dist, x2, y2, z2 ; if (FZERO(r)) r = DEFAULT_RADIUS ; if (!mris_dst) mris_dst = MRISclone(mris_src) ; if ((mris_dst->status != MRIS_SPHERE) && (mris_dst->status != MRIS_PARAMETERIZED_SPHERE)) MRIScenter(mris_dst, mris_dst) ; mris_dst->radius = r ; for (total_dist = vno = 0 ; vno < mris_dst->nvertices ; vno++) { v = &mris_dst->vertices[vno]; if (v->ripflag) /* shouldn't happen */ continue ; if (vno == 118009) { DiagBreak() ; } x = ((double)v->x); y = ((double)v->y); z = ((double)v->z); x2 = x*x ; y2 = y*y ; z2 = z*z ; dist = sqrt(x2+y2+z2) ; if (FZERO(dist)) d = 0 ; else d = 1 - r / dist ; dx = d*x ; dy = d*y; dz = d*z; v->x = x-dx ; v->y = y-dy; v->z = z-dz; if (!finite(v->x) || !finite(v->y) || !finite(v->z)) DiagBreak() ; /* if ((Gdiag & DIAG_SHOW) && DIAG_VERBOSE_ON)*/ { dist = sqrt((double)(dx*dx+dy*dy+dz*dz)); total_dist += dist; } #if 1 x = (double)v->x; y = (double)v->y; z = (double)v->z; x2 = x*x ; y2 = y*y ; z2 = z*z ; dist = sqrt(x2+y2+z2) ; #endif } for (total_dist = vno = 0 ; vno < mris_dst->nvertices ; vno++) { v = &mris_dst->vertices[vno]; if (v->ripflag) /* shouldn't happen */ continue ; v->x += x0 ; v->y += y0 ; v->z += z0 ; } if ((Gdiag & DIAG_SHOW) && DIAG_VERBOSE_ON) fprintf(stdout, "sphere_project: total dist = %f\n",total_dist); MRISupdateEllipsoidSurface(mris_dst) ; mris_dst->status = mris_src->status == MRIS_PARAMETERIZED_SPHERE ? MRIS_PARAMETERIZED_SPHERE : MRIS_SPHERE ; return(mris_dst) ; }
/*-------------------------------------------------------------*/ int main(int argc, char *argv[]) { int nargs; int source_is_label = 0; int source_is_path = 0; int err = 0; FILE* fp = NULL; nargs = handle_version_option (argc, argv, "$Id: mri_path2label.c,v 1.23 2011/03/02 00:04:23 nicks Exp $", "$Name: $"); if(nargs && argc - nargs == 1) exit (0); argc -= nargs; Progname = argv[0] ; argc --; argv++; ErrorInit(NULL, NULL, NULL) ; DiagInit(NULL, NULL, NULL) ; if (argc == 0) usage_exit(); parse_commandline(argc, argv); check_options(); if (checkoptsonly) return(0); if(!label_to_path && !path_to_label) { err = guess_file_type (source_file, &source_is_path, &source_is_label); if (err) { printf ("ERROR: Couldn't determine source file type.\n"); exit (1); } if(source_is_path) path_to_label = 1; if(source_is_label) label_to_path = 1; } if (dest_file) { fp = fopen (dest_file, "w"); if (NULL == fp) { printf ("ERROR: Couldn't open dest file for writing.\n"); exit (1); } fclose (fp); } if(connect){ // Still under construction printf("Connecting vertices in path\n"); int stat=connect_path(source_file, dest_file, subject, hemi) ; exit(stat); } if(fill){ // Still under construction printf("Filling vertices in path\n"); int stat=fill_path(source_file, dest_file, subject, hemi, fillseed) ; exit(stat); } if(con_and_fill){ // Still under construction printf("Connecting and Filling vertices in path\n"); int stat= con_and_fill_path(source_file, dest_file, subject, hemi, fillseed) ; exit(stat); } if(con_and_fillx){ int stat=1; if (con_and_fillx_fname) { // open file containing the list of fillseeds and path/label files FILE* fp2 = fopen (con_and_fillx_fname, "r"); if (NULL == fp2) { printf ("ERROR: Couldn't open file %s for reading.\n", con_and_fillx_fname); exit (1); } printf("Reading %s\n",surfacefname); MRIS* mris = MRISread(surfacefname); if(mris == NULL) exit(1); size_t n=2000; char tmpstr[2000]; char* tmps = &tmpstr[0]; while (0 < getline(&tmps,&n,fp2)) { char srcfn[2000]; char dstfn[2000]; //printf("%s\n",tmpstr); if (sscanf(tmpstr,"%d %s %s",&fillseed,srcfn,dstfn) > 0) { printf("Connecting and filling vertices in path at fillseed %d\n", fillseed); MRIS* mrisclone = MRISclone(mris); stat = con_and_fill_pathy (srcfn, dstfn, mrisclone, fillseed) ; if (stat) break; } } } else { printf("Connecting and filling vertices in path at fillseed %d\n", fillseed); stat=con_and_fill_pathx (source_file, dest_file, surfacefname, fillseed) ; } exit(stat); } printf ("INFO: Converting %s\n", source_file); printf ("INFO: to %s\n", dest_file); if(path_to_label) printf ("INFO: Path to label\n"); else printf ("INFO: Label to path\n"); printf ("\n"); if (single_path) printf ("INFO: Converting a single path\n"); if (single_path) { if(path_to_label) convert_single_path_to_label(source_file, dest_file); else if (label_to_path) convert_single_label_to_path (source_file, dest_file); } else { if (path_to_label) convert_path_to_label (source_file, dest_file); else if (label_to_path) convert_label_to_path (source_file, dest_file); } return 0; }