Esempio n. 1
0
int main(int argc, const char *argv[]) {
  const int nx = 32, ny = 32, nz = 32, dim = nx*ny*nz;
  const int dims[3] = {nx, ny, nz};
  const float mmppixr[] = { 2, 2, 2 }, centerr[] = { 0, 0, 0};
  const float blur_radius = 4.0;
  int iz, iy, ix, i;
  float *image, *mask, *roi;

  pf_log_all(1);

  image = calloc(dim, sizeof(float));
  roi = calloc(dim, sizeof(float));
  mask = malloc(dim * sizeof(float));

  if (!image || !mask || !roi) {
    fprintf(stderr, "allocation failed");
    exit(1);
  }

  /* start with a trivial mask and a gaussian image*/
  float min = INT_MAX, max = INT_MIN;
  for (i = iz = 0; iz < nz; iz++) {
    for (iy = 0; iy < ny; iy++) {
      for (ix = 0; ix < nx; ix++, i++) {
        mask[i] = 1.0;
        image[i] = gauss3d(ix-(nx/2),iy-(ny/2),iz-(ny/2),nx/4);
        if (image[i] > max) {
          max = image[i];
        }
        if (image[i] < min) {
          min = image[i];
        }
      }
    }
  }
  fprintf(stdout, "image value range: [%g, %g]\n", min, max);
    

  display(image, dims, 17, max);

  sphereblur(image, dims, mmppixr, blur_radius);

  display(image, dims, 17, max);

  find_peaks(image, dims, mmppixr, centerr,
             0, 0, 0, 0, 1,
             roi, 4, 0, 8, mask, 0, 0);

  puts("slice at peak:\n");
  display(roi, dims, 17, max);
  puts("2 slices away from peak:\n");
  display(roi, dims, 15, max);
  puts("4 slices away from peak:\n");
  display(roi, dims, 13, max);
}
Esempio n. 2
0
/**
 * Returns the pp_indent to use for this line
 */
int pf_check(struct parse_frame *frm, chunk_t *pc)
{
   int        in_ifdef = frm->in_ifdef;
   int        b4_cnt   = cpd.frame_count;
   int        pp_level = cpd.pp_level;
   const char *txt     = NULL;
   chunk_t    *next;

   if (pc->type != CT_PREPROC)
   {
      return(pp_level);
   }
   next = chunk_get_next(pc);

   if (pc->parent_type != next->type)
   {
      LOG_FMT(LNOTE, "%s: Preproc parent not set correctly on line %d: got %s expected %s\n",
              __func__, pc->orig_line, get_token_name(pc->parent_type),
              get_token_name(next->type));
      pc->parent_type = next->type;
   }

   LOG_FMT(LPFCHK, "%s: %5d] %s\n",
           __func__, pc->orig_line, get_token_name(pc->parent_type));
   pf_log_frms(LPFCHK, "TOP", frm);

   if ((pc->flags & PCF_IN_PREPROC) != 0)
   {
      LOG_FMT(LPF, " <In> ");
      pf_log(LPF, frm);

      if (pc->parent_type == CT_PP_IF)
      {
         /* An #if pushes a copy of the current frame on the stack */
         cpd.pp_level++;
         pf_push(frm);
         frm->in_ifdef = CT_PP_IF;
         txt           = "if-push";
      }
      else if (pc->parent_type == CT_PP_ELSE)
      {
         pp_level--;

         /**
          * For #else of #elif, we want to keep the #if part and throw out the
          * else parts.
          * We check to see what the top type is to see if we just push or
          * pop and then push.
          * We need to use the copy right before the if.
          */
         if (frm->in_ifdef == CT_PP_IF)
         {
            /* we have [...] [base]-[if], so push an [else] */
            pf_push(frm);
            frm->in_ifdef = CT_PP_ELSE;
         }
         /* we have [...] [base] [if]-[else], copy [base] over [else] */
         pf_copy_2nd_tos(frm);
         frm->in_ifdef = CT_PP_ELSE;
         txt           = "else-push";
      }
      else if (pc->parent_type == CT_PP_ENDIF)
      {
         /**
          * we may have [...] [base] [if]-[else] or [...] [base]-[if].
          * Throw out the [else].
          */
         cpd.pp_level--;
         pp_level--;

         if (frm->in_ifdef == CT_PP_ELSE)
         {
            /**
             * We have: [...] [base] [if]-[else]
             * We want: [...]-[if]
             */
            pf_copy_tos(frm);     /* [...] [base] [if]-[if] */
            frm->in_ifdef = cpd.frames[cpd.frame_count - 2].in_ifdef;
            pf_trash_tos();       /* [...] [base]-[if] */
            pf_trash_tos();       /* [...]-[if] */

            txt = "endif-trash/pop";
         }
         else if (frm->in_ifdef == CT_PP_IF)
         {
            /**
             * We have: [...] [base] [if]
             * We want: [...] [base]
             */
            pf_pop(frm);
            txt = "endif-pop";
         }
         else
         {
            txt = "???";
         }
      }
   }

   if (txt != NULL)
   {
      LOG_FMT(LPF, "%s: %d> %s: %s in_ifdef=%d/%d counts=%d/%d\n", __func__,
              pc->orig_line, get_token_name(pc->parent_type), txt,
              in_ifdef, frm->in_ifdef, b4_cnt, cpd.frame_count);
      pf_log_all(LPF);
      LOG_FMT(LPF, " <Out>");
      pf_log(LPF, frm);
   }

   pf_log_frms(LPFCHK, "END", frm);

   return(pp_level);
}