Ejemplo n.º 1
0
int
main(int argc, char *argv[]) {
  char         **av ;
  int          ac, nargs, nsize ;
  MRI_SURFACE  *mris ;
  MRI          *mri ;

  nargs = handle_version_option (argc, argv, "$Id: mris_nudge.c,v 1.2 2011/03/02 00:04:31 nicks Exp $", "$Name: stable5 $");
  if (nargs && argc - nargs == 1)
    exit (0);
  argc -= nargs;

  Gx = Gy = Gz = -1 ;
  Progname = argv[0] ;
  ErrorInit(NULL, NULL, NULL) ;
  DiagInit(NULL, NULL, NULL) ;

  ac = argc ;
  av = argv ;
  for ( ; argc > 1 && ISOPTION(*argv[1]) ; argc--, argv++) {
    nargs = get_option(argc, argv) ;
    argc -= nargs ;
    argv += nargs ;
  }

  if (argc < 7)
    usage_exit(1) ;

  mris = MRISread(argv[1]) ;
  if (mris == NULL)
    ErrorExit(ERROR_NOFILE, "%s: could not read surface from %s", Progname, argv[1]) ;
  MRIScomputeMetricProperties(mris) ;
  MRISstoreMetricProperties(mris) ;

  mri = MRIread(argv[2]) ;
  if (mri == NULL)
    ErrorExit(ERROR_NOFILE, "%s: could not read volume from %s", Progname, argv[2]) ;

  target_vnos[nvertices] = atoi(argv[3]) ;
  target_vals[nvertices] = atof(argv[4]) ;
  nsize = atoi(argv[5]) ;

  printf("nudging %d vertex region around vertex %d to target val %2.1f\n", 
         nsize, target_vnos[nvertices], target_vals[nvertices]) ;
  nvertices++ ;

  MRISerodeRipped(mris, nsize) ;
  MRISrepositionSurface(mris, mri, target_vnos, target_vals, nvertices, nsize, sigma) ;

  MRISunrip(mris) ;
  printf("writing repositioned surface to %s\n", argv[6]) ;
  MRISwrite(mris, argv[6]) ;
  return(0) ;
}
Ejemplo n.º 2
0
static int
initialize_cluster_centers_with_ico(MRI_SURFACE *mris, MRI *mri_profiles, CLUSTER *ct, MRI_SURFACE *mris_ico) {
  int             i, j, vno, nsamples, vnos[MAX_CLUSTERS], k ;
  double          r1, r2, res ;
  float           fmin ;
  MRIS_HASH_TABLE *mht ;
  VERTEX          *vico ;

  k = mris_ico->nvertices ;
  MRISstoreRipFlags(mris) ;
  MRISunrip(mris) ;
  r1 = MRISaverageRadius(mris) ;
  r2 = MRISaverageRadius(mris_ico) ;
  MRISscaleBrain(mris_ico,mris_ico, r1/r2);

  res = sqrt(mris->total_area/mris->nvertices) ;
  mht = MHTfillVertexTableRes(mris, NULL, CURRENT_VERTICES, 2*res) ;
  nsamples = mri_profiles->nframes ;
  for (i = 0 ; i < mris_ico->nvertices ; i++) {
    vico = &mris_ico->vertices[i] ;
    vno = MRISfindClosestVertex(mris, vico->x, vico->y, vico->z, &fmin) ;
    if (vno < 0)
      continue ;
    vnos[i] = vno ;
    for (j = 0 ; j < nsamples ; j++)
      VECTOR_ELT(ct[i].v_mean, j+1) = MRIgetVoxVal(mri_profiles, vno, 0, 0, j) ;
  }
  mris->ct = CTABalloc(k) ;
  for (i = 0 ; i < k ; i++) {
    mris->vertices[vnos[i]].curv = i ;
    ct[i].npoints++ ;
    ct[i].vno = vnos[i] ;
    CTABannotationAtIndex(mris->ct, i, &mris->vertices[vnos[i]].annotation) ;
  }
  MRISrestoreRipFlags(mris) ;
  return(NO_ERROR) ;
}
Ejemplo n.º 3
0
/*
  expects the two surfaces to have the CANONICAL_VERTICES field set to the 
  sphere.reg positions.
*/
int
MRISmapCuts(MRI_SURFACE *mris_in, MRI_SURFACE *mris_out)
{
  MHT    *mht_in, *mht_out ;
  int    vno_out /*, vno_in, fno_in, fno_out, n, ripflag*/ ;
  VERTEX *v_out, *v_in ;
#if 0
  FACE   *f_in, *f_out ;
#endif

  MRISstoreRipFlags(mris_in) ;
  MRISunrip(mris_in) ;

  mht_in = MHTfillVertexTable(mris_in, NULL, CANONICAL_VERTICES) ;
  mht_out = MHTfillVertexTable(mris_out, NULL, CANONICAL_VERTICES) ;

#if 0
  for (vno_in = 0 ; vno_in < mris_in->nvertices ; vno_in++)
  {
    if (vno_in == Gdiag_no)
      DiagBreak() ;
    v_in = &mris_in->vertices[vno_in] ;
    if (v_in->oripflag == 0)
      continue ;
    v_out = MHTfindClosestVertexInTable(mht_out, mris_out, v_in->cx, v_in->cy, v_in->cz, 1) ;
    if (v_out == NULL)
      DiagBreak() ;
    else
      v_out->ripflag = 1 ;
  }

  for (vno_out = 0 ; vno_out < mris_out->nvertices ; vno_out++)
  {
    if (vno_out == Gdiag_no)
      DiagBreak() ;
    v_out = &mris_out->vertices[vno_out] ;
    v_in = MHTfindClosestVertexInTable(mht_in, mris_in, v_out->cx, v_out->cy, v_out->cz, 1) ;
    if (v_in == NULL)
      DiagBreak() ;
    else if (v_in->oripflag)
      v_out->ripflag = 1 ;
  }

  for (fno_in = 0 ; fno_in < mris_in->nfaces ; fno_in++)
  {
    f_in = &mris_in->faces[fno_in] ;
    if (f_in->ripflag == 0)
      continue ;
    for (n = 0 ; n < VERTICES_PER_FACE ; n++)
    {
      vno_in = f_in->v[n] ;
      if (vno_in == Gdiag_no)
        DiagBreak() ;
      v_in = &mris_in->vertices[vno_in] ;
      v_out = MHTfindClosestVertexInTable(mht_out, mris_out, v_in->cx, v_in->cy, v_in->cz, 1) ;
      if (v_out == NULL)
        DiagBreak() ;
      else
        v_out->ripflag = 1 ;
    }
  }

  for (fno_out = 0 ; fno_out < mris_out->nfaces ; fno_out++)
  {
    f_out = &mris_out->faces[fno_out] ;
    ripflag = 0 ;
    for (n = 0 ; n < VERTICES_PER_FACE ; n++)
    {
      vno_out = f_out->v[n] ;
      if (vno_out == Gdiag_no)
        DiagBreak() ;
      v_out = &mris_out->vertices[vno_out] ;
      v_in = MHTfindClosestVertexInTable(mht_in, mris_in, v_out->cx, v_out->cy, v_out->cz, 1) ;
      if (v_in == NULL)
        DiagBreak() ;
      else
        if (v_in->ripflag)
          ripflag = 1 ;
    }
    f_out->ripflag = ripflag ;
  }

  for (fno_out = 0 ; fno_out < mris_out->nfaces ; fno_out++)
  {
    double cx, cy, cz ;
    int    n ;

    f_out = &mris_out->faces[fno_out] ;
    ripflag = 0 ;
    
    cx = cy = cz = 0.0 ;
    for (n = 0 ; n < VERTICES_PER_FACE ; n++)
    {
      vno_out = f_out->v[n] ;
      if (vno_out == Gdiag_no)
        DiagBreak() ;
      v_out = &mris_out->vertices[vno_out] ;
      cx += v_out->cx ; cy += v_out->cy ; cz += v_out->cz ;

    }
    cx /= VERTICES_PER_FACE ;
    cy /= VERTICES_PER_FACE ;
    cz /= VERTICES_PER_FACE ;
    v_in = MHTfindClosestVertexInTable(mht_in, mris_in, cx, cy, cz, 1) ;
    if (v_in == NULL)
      DiagBreak() ;
    else
      if (v_in->ripflag)
      {
        f_out->ripflag = 1 ;
        for (n = 0 ; n < VERTICES_PER_FACE ; n++)
          mris_out->vertices[f_out->v[n]].ripflag = 1 ;
      }
  }
#endif

#define STEP_SIZE 0.05
  for (vno_out = 0 ; vno_out < mris_out->nvertices ; vno_out++)
  {
    double d, dx, dy, dz ;
    int    n ;
    VERTEX *vn ;

    v_out = &mris_out->vertices[vno_out] ;
    for (n = 0 ; n < v_out->vnum ; n++)
    {
      vn = &mris_out->vertices[v_out->v[n]] ;
      dx = vn->cx - v_out->cx ; 
      dy = vn->cy - v_out->cy ; 
      dz = vn->cz - v_out->cz ; 
      for (d = 0.0 ; d <= 1.0 ; d+= STEP_SIZE)
      {
        v_in = MHTfindClosestVertexInTable(mht_in, mris_in, 
                                           v_out->cx+dx*d, 
                                           v_out->cy+dy*d, 
                                           v_out->cz+dz*d, 
                                           1) ;
        if (v_in == NULL)
          DiagBreak() ;
        else if (v_in->oripflag)
        {
          v_out->ripflag = 1 ;
          break ;
        }
      }
    }
  }

  MRISripFaces(mris_out) ;
  MRISrestoreRipFlags(mris_in) ;

  MHTfree(&mht_in) ; MHTfree(&mht_out) ;
  return(NO_ERROR) ;
}