Skip to content

Commit

Permalink
mrisurf, mris_convert #NF. Added function to copy coords from one sur…
Browse files Browse the repository at this point in the history
…face to another (good for patches). Added function to mris_convert with --to-surf
  • Loading branch information
Douglas Greve committed Apr 16, 2021
1 parent fe0ae16 commit b1d3b65
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/mrisurf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,7 @@ static bool mrisVerticesAreNeighbors(MRIS const * const mris, int const vno1, in
int MRISripMidline(MRI_SURFACE *mris, MRI *mri_aseg, MRI *mri_brain, const char *hemi, int which, int fix_mtl);
int MRIcomputeLabelNormal(MRI *mri_aseg, int x0, int y0, int z0,int label, int whalf, double *pnx, double *pny,
double *pnz, int use_abs);
int MRIScopyCoords(MRIS *surf, MRIS *surfcoords);
int MRISfindExpansionRegions(MRI_SURFACE *mris);
int MRISwriteField(MRIS *surf, const char **fields, int nfields, const char *outname);

Expand Down
14 changes: 14 additions & 0 deletions mris_convert/mris_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ static int cras_add = 0;
static int cras_subtract = 0;
static int ToScanner = 0;
static int ToTkr = 0;
static int ToSurfCoords = 0;
MRIS *SurfCoords = NULL;
int WriteArea = 0;

int DeleteCommands = 0;
Expand Down Expand Up @@ -323,6 +325,11 @@ main(int argc, char *argv[])
printf("Subtracting scanner CRAS from surface xyz\n");
MRISshiftCRAS(mris, -1);
}
if(ToSurfCoords){
printf("Converting to coords of --to-surf surface\n");
int err = MRIScopyCoords(mris,SurfCoords);
if(err) exit(1);
}
if(ToScanner){
printf("Converting from tkr to scanner coordinates\n");
MRIStkr2Scanner(mris);
Expand Down Expand Up @@ -797,6 +804,12 @@ get_option(int argc, char *argv[])
cras_add = 0;
cras_subtract = 0;
}
else if (!stricmp(option, "-to-surf")) {
ToSurfCoords = 1;
SurfCoords = MRISread(argv[2]);
if(SurfCoords == NULL) exit (1);
nargs = 1 ;
}
else if (!stricmp(option, "-vol-geom"))
{
VolGeomMRI = MRIreadHeader(argv[2],MRI_VOLUME_TYPE_UNKNOWN);
Expand Down Expand Up @@ -921,6 +934,7 @@ print_help(void)
printf( " --userealras : set the useRealRAS flag in the surface file to 1 \n") ;
printf( " --usesurfras : set the useRealRAS flag in the surface file to 0 \n") ;
printf( " --vol-geom MRIVol : use MRIVol to set the volume geometry\n") ;
printf( " --to-surf surfcoords : copy coordinates from surfcoords to output (good for patches)\n") ;
printf( " --to-scanner : convert coordinates from native FS (tkr) coords to scanner coords\n") ;
printf( " --to-tkr : convert coordinates from scanner coords to native FS (tkr) coords \n") ;
printf( " --volume ?h.white ?h.pial ?h.volume : compute vertex-wise volume, no other args needed (uses th3)\n") ;
Expand Down
31 changes: 31 additions & 0 deletions utils/mrisurf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,34 @@ int MRIcomputeLabelNormal(MRI *mri_aseg, int x0, int y0, int z0,
*pnz = nz ;
return(NO_ERROR) ;
}

/*!
\fn int MRIScopyCoords(MRIS *surf, MRIS *surfcoords)
\brief Transfers the xyz coords from surfcoords to the given surface.
*/
int MRIScopyCoords(MRIS *surf, MRIS *surfcoords)
{
int k;

if(surf == NULL){
printf("ERROR: MRIScopyCoordsCoords(): surf is null\n");
return(1);
}
if(surfcoords == NULL){
printf("ERROR: MRIScopyCoordsCoords(): surfcoords is null\n");
return(1);
}
if(surf->nvertices != surfcoords->nvertices){
printf("ERROR: MRIScopyCoordsCoords(): surf and surfcoords have diff no of vetices\n");
return(1);
}

for(k=0; k < surf->nvertices; k++){
VERTEX *v = &surf->vertices[k];
//if(v->ripflag) continue;
v->x = surfcoords->vertices[k].x;
v->y = surfcoords->vertices[k].y;
v->z = surfcoords->vertices[k].z;
}
return(0);
}

0 comments on commit b1d3b65

Please sign in to comment.