xp_comm_proj/build3d_2/build3d_2.c
/*----------------------------------------------------------------------
 * builds the specified images into a volume by reading each one
 * and placing it into a single slice of a volume field.
 */
builds the specified images into a volume by reading each one
and placing it into a single slice of a volume field.
builds the specified images into a volume by reading each one and placing it into a single slice of a volume field .
static int FUNCread_volume(char* filename, int format, int start, int end, int out_format, OMobj_id elem_id)
{
  char filename_buf[AVS_PATH_MAX];
  char info[128];
  int i,  width, height, num_slices, nnodes, image_size;
  OMobj_id out_id, info_id;
  unsigned char *node_data_b;
  float *node_data_f;
  num_slices = end - start + 1;  
  node_data = NULL;              
  for (i = 0; i < sizeof(FUNCread_map) / sizeof(read_map); i++)
  {
    if (format == FUNCread_map[i].dv_val)
    {
      if (!FUNCget_image_funcs((void *)FUNCread_map[i].info))
        return(0);
      else
        break;
    }
  }
  sprintf(filename_buf, filename, start);
  if (!FUNCread_image_dims(filename_buf, &width, &height))
    return(0);
  nnodes = width*height*num_slices;
  image_size = width*height;
  if (out_format==ARGB_OUT_FORMAT) {
    node_data_b = (unsigned char *)ARRalloc(NULL, DTYPE_BYTE, 4*nnodes, NULL);
    node_data = node_data_b;
    image_size = image_size * 4;
  }
  else if (out_format==RGB_OUT_FORMAT) {
    node_data_f = (float *)ARRalloc(NULL, DTYPE_FLOAT, 3*nnodes, NULL);
    node_data = node_data_f;
    image_size = image_size * 3;
  }
  else if (out_format==LUMI_OUT_FORMAT) {
    node_data_f = (float *)ARRalloc(NULL, DTYPE_FLOAT, nnodes, NULL);
    node_data = node_data_f;
  }
  else {
    node_data_b = (unsigned char *)ARRalloc(NULL, DTYPE_BYTE, nnodes, NULL);
    node_data = node_data_b;
  }
  OMpush_status_range(10, 100);
  for (i=start; i<=end; i++) {
    OMstatus_check((i-start)*100/num_slices, "Reading Image files", NULL);
    sprintf(filename_buf, filename, i);
    if ((out_format==LUMI_OUT_FORMAT) || (out_format==RGB_OUT_FORMAT)) {
      if (!FUNCread_image(filename_buf, width, height, out_format, node_data_f)) {
        OMpop_status_range();
        return(0);
      }
      node_data_f += image_size;
    }
    else {
      if (!FUNCread_image(filename_buf, width, height, out_format, node_data_b)) {
        OMpop_status_range();
        return(0);
      }
      node_data_b += image_size;
    }
  }
  OMstatus_check(100, "Reading Image files", NULL);
  OMpop_status_range();
  out_id = OMfind_subobj(elem_id, OMstr_to_name("out"), OM_OBJ_RW);
  if (!FUNCset_volume_field(width, height, num_slices, out_format, out_id))
    return(0);
#ifndef NO_DL_LOAD
  if (handle)
    DL_CLOSE(handle);
#endif
  info_id = OMfind_subobj(elem_id, OMstr_to_name("info"), OM_OBJ_RW);
  FUNCget_image_format_name(format, info);
  sprintf(info, "%s %dx%dx%d", info, width, height, num_slices);
  OMset_str_val(info_id, info);
  return(1);
}
static int FUNCread_volume ( char * filename , int format , int start , int end , int out_format , OMobj_id elem_id ) { char filename_buf [ AVS_PATH_MAX ] ; char info [ 128 ] ; int i , width , height , num_slices , nnodes , image_size ; OMobj_id out_id , info_id ; unsigned char * node_data_b ; float * node_data_f ; num_slices = end - start + 1 ; node_data = NULL ; for ( i = 0 ; i < sizeof ( FUNCread_map ) / sizeof ( read_map ) ; i ++ ) { if ( format == FUNCread_map [ i ] . dv_val ) { if ( ! FUNCget_image_funcs ( ( void * ) FUNCread_map [ i ] . info ) ) return ( 0 ) ; else break ; } } sprintf ( filename_buf , filename , start ) ; if ( ! FUNCread_image_dims ( filename_buf , & width , & height ) ) return ( 0 ) ; nnodes = width * height * num_slices ; image_size = width * height ; if ( out_format == ARGB_OUT_FORMAT ) { node_data_b = ( unsigned char * ) ARRalloc ( NULL , DTYPE_BYTE , 4 * nnodes , NULL ) ; node_data = node_data_b ; image_size = image_size * 4 ; } else if ( out_format == RGB_OUT_FORMAT ) { node_data_f = ( float * ) ARRalloc ( NULL , DTYPE_FLOAT , 3 * nnodes , NULL ) ; node_data = node_data_f ; image_size = image_size * 3 ; } else if ( out_format == LUMI_OUT_FORMAT ) { node_data_f = ( float * ) ARRalloc ( NULL , DTYPE_FLOAT , nnodes , NULL ) ; node_data = node_data_f ; } else { node_data_b = ( unsigned char * ) ARRalloc ( NULL , DTYPE_BYTE , nnodes , NULL ) ; node_data = node_data_b ; } OMpush_status_range ( 10 , 100 ) ; for ( i = start ; i <= end ; i ++ ) { OMstatus_check ( ( i - start ) * 100 / num_slices , " " , NULL ) ; sprintf ( filename_buf , filename , i ) ; if ( ( out_format == LUMI_OUT_FORMAT ) || ( out_format == RGB_OUT_FORMAT ) ) { if ( ! FUNCread_image ( filename_buf , width , height , out_format , node_data_f ) ) { OMpop_status_range ( ) ; return ( 0 ) ; } node_data_f += image_size ; } else { if ( ! FUNCread_image ( filename_buf , width , height , out_format , node_data_b ) ) { OMpop_status_range ( ) ; return ( 0 ) ; } node_data_b += image_size ; } } OMstatus_check ( 100 , " " , NULL ) ; OMpop_status_range ( ) ; out_id = OMfind_subobj ( elem_id , OMstr_to_name ( " " ) , OM_OBJ_RW ) ; if ( ! FUNCset_volume_field ( width , height , num_slices , out_format , out_id ) ) return ( 0 ) ; #ifndef NO_DL_LOAD if ( handle ) DL_CLOSE ( handle ) ; #endif info_id = OMfind_subobj ( elem_id , OMstr_to_name ( " " ) , OM_OBJ_RW ) ; FUNCget_image_format_name ( format , info ) ; sprintf ( info , " " , info , width , height , num_slices ) ; OMset_str_val ( info_id , info ) ; return ( 1 ) ; }
builds the specified images into a volume by reading each one
 and placing it into a single slice of a volume field.
builds the specified images into a volume by reading each one and placing it into a single slice of a volume field .
/*curr,*/ /* Calculate number of slices in volume */ /* Ensure old node data variable is cleared */ /* find the functions that correspond to the format number */ /* get dims of first image */ /* Allocate memory to store volume data. Amount needed depends upon selected output format. */ /* read images into volume field */ /* get volume data output reference */ /* set the output volume field */ /* close the library */ /* give some info about what was read */