예제 #1
0
void readtarget(const char *file, int ifile, int flag, int *errorcode){
  FILE *stream;
  float ttargmin, ttargmax;
  char buffer[255];
  int n,colorindex;
  float time_local;
  int exitloop = 0;
  float *t, *x, *y, *z, *x2, *y2, *z2;
  float xt, yt, zt;
  float xt2, yt2, zt2;
  int i;
  float r, g, b;
  int nsteps;

  CheckMemory;
  *errorcode=0;
  if(targinfo[ifile].type==2){
    readtarget2(file,ifile,flag,errorcode);
    return;
  }
  if(target_positions != NULL){
    for(n=0;n<ntargets;n++){
      FREEMEMORY(target_positions[n].x);
      FREEMEMORY(target_positions[n].y);
      FREEMEMORY(target_positions[n].z);
      FREEMEMORY(target_positions[n].x2);
      FREEMEMORY(target_positions[n].y2);
      FREEMEMORY(target_positions[n].z2);
      FREEMEMORY(target_positions[n].t);
    }
    FREEMEMORY(target_positions);
  }
  FREEMEMORY(targtimes);
  targfilenum = ifile;
  if(flag == UNLOAD){
    targinfo[ifile].loaded=0;
    targinfo[ifile].display=0;
    plotstate=getplotstate(DYNAMIC_PLOTS);
    visTarg = 0;
    ReadTargFile=0;
    ntargets=0;
    Update_Times();
    updatemenu=1;
    return;
  }

  if( (stream=fopen(file,"r"))==NULL)return;

  fgets(buffer,255,stream);
  sscanf(buffer,"%i",&ntargets);
  FREEMEMORY(target_positions);
  NewMemory((void **)&target_positions,ntargets*sizeof(targpos));
  NewMemory((void **)&targtimes,NTARGTIMES*sizeof(float));
  CheckMemory;

  /* read target colors */

  for(n=0;n<ntargets;n++){
    fgets(buffer,255,stream);
    sscanf(buffer,"%i %f %f %f",&colorindex,&r,&g,&b);
    sscanf(buffer,"%i ",&colorindex);
    if(colorindex<0){
      if(r<0.0)r=0.0;
      if(r>1.0)r=1.0;
      if(g<0.0)g=0.0;
      if(g>1.0)g=1.0;
      if(b<0.0)b=0.0;
      if(b>1.0)b=1.0;
      target_positions[n].rgb[0]=r;
      target_positions[n].rgb[1]=g;
      target_positions[n].rgb[2]=b;
    }
    else{
      if(colorindex>=0&&colorindex<nrgb2){
        target_positions[n].rgb[0]=rgb2[colorindex][0];
        target_positions[n].rgb[1]=rgb2[colorindex][1];
        target_positions[n].rgb[2]=rgb2[colorindex][2];
      }
      else{
        target_positions[n].rgb[0]=rgb2[1][0];
        target_positions[n].rgb[1]=rgb2[1][1];
        target_positions[n].rgb[2]=rgb2[1][2];
      }
    }
  }

  for(n=0;n<ntargets;n++){
    if(fgets(buffer,255,stream)==NULL)break;
    sscanf(buffer,"%i ",&nsteps);
    if(nsteps<=0)break;
    target_positions[n].nsteps=nsteps;
    t=NULL;
    x=NULL;
    y=NULL;
    z=NULL;
    x2=NULL;
    y2=NULL;
    z2=NULL;
    CheckMemory;
    NewMemory((void **)&t,nsteps*sizeof(float));
    NewMemory((void **)&x,nsteps*sizeof(float));
    NewMemory((void **)&y,nsteps*sizeof(float));
    NewMemory((void **)&z,nsteps*sizeof(float));
    NewMemory((void **)&x2,nsteps*sizeof(float));
    NewMemory((void **)&y2,nsteps*sizeof(float));
    NewMemory((void **)&z2,nsteps*sizeof(float));
    target_positions[n].t=t;
    target_positions[n].x=x;
    target_positions[n].y=y;
    target_positions[n].z=z;
    target_positions[n].x2=x2;
    target_positions[n].y2=y2;
    target_positions[n].z2=z2;
    for(i=0;i<nsteps;i++){
      if(fgets(buffer,255,stream)!=NULL){
        sscanf(buffer,"%f %f %f %f %f %f %f",&time_local,&xt,&yt,&zt,&xt2,&yt2,&zt2);
        target_positions[n].t[i]=time_local;
        target_positions[n].x[i]=xt;
        target_positions[n].y[i]=yt;
        target_positions[n].z[i]=zt;
        target_positions[n].x2[i]=xt2;
        target_positions[n].y2[i]=yt2;
        target_positions[n].z2[i]=zt2;
      }
      else{exitloop=1;}
    }
    if(exitloop==1)break;
  }
  if(ntargets>0){
    ttargmin=1000000.;
    ttargmax=-1000000.;
    for(n=0;n<ntargets;n++){
      nsteps = target_positions[n].nsteps;
      if(nsteps>0){
        if(target_positions[n].t[nsteps-1]<ttargmin)ttargmin=target_positions[n].t[0];
        if(target_positions[n].t[nsteps-1]>ttargmax)ttargmax=target_positions[n].t[nsteps-1];
      }
    }
    if(ttargmax>ttargmin){
      for(n=0;n<NTARGTIMES;n++){
        targtimes[n]=ttargmin+n*(ttargmax-ttargmin)/(NTARGTIMES-1);
      }
    }
  }
  PRINTF("min=%f max=%f\n",ttargmin,ttargmax);
  ReadTargFile=1;
  visTarg=1;
  targinfo[ifile].loaded=1;
  targinfo[ifile].display=1;
  plotstate=getplotstate(DYNAMIC_PLOTS);
  Update_Times();
  fclose(stream);
  Idle_CB();

}
예제 #2
0
void readtarget2(const char *file, int ifile, int flag, int *errorcode){
  FILE *stream;
  char buffer[255];
  int n;
  float time_local;
  float *t, *x, *y, *z;
  float xt, yt, zt;
  int i;
  int nsteps;
  float vals_local[6];
  float *vals,valmin,valmax,val;
  unsigned char *color;

  CheckMemory;
  *errorcode=0;
  if(target_positions != NULL){
    for(n=0;n<ntargets;n++){
      FREEMEMORY(target_positions[n].x);
      FREEMEMORY(target_positions[n].y);
      FREEMEMORY(target_positions[n].z);
      FREEMEMORY(target_positions[n].t);
      FREEMEMORY(target_positions[n].vals);
    }
    FREEMEMORY(target_positions);
  }
  FREEMEMORY(targtimes);
  targfilenum = ifile;
  if(flag == UNLOAD){
    targinfo[ifile].loaded=0;
    targinfo[ifile].display=0;
    plotstate=getplotstate(DYNAMIC_PLOTS);
    visTarg = 0;
    ReadTargFile=0;
    ntargets=0;
    Update_Times();
    updatemenu=1;
    return;
  }

  stream=fopen(file,"r");
  if(stream==NULL)return;

  fgets(buffer,255,stream);
  fgets(buffer,255,stream);
  fgets(buffer,255,stream);
  ntargtimes=0;
  while(fgets(buffer,255,stream)!=NULL){
    ntargtimes++;
  }
  rewind(stream);

  fgets(buffer,255,stream);
  fgets(buffer,255,stream);
  fgets(buffer,255,stream);
  ntargets=1;
  FREEMEMORY(target_positions);
  NewMemory((void **)&target_positions,ntargets*sizeof(targpos));
  NewMemory((void **)&targtimes,ntargtimes*sizeof(float));
  CheckMemory;

  n=0;
  if(fgets(buffer,255,stream)==NULL){
    fclose(stream);
    readtarget2("", ifile, UNLOAD, errorcode);
    return;
  }
  sscanf(buffer,"%i ",&nsteps);
  if(nsteps<=0){
    fclose(stream);
    readtarget2("", ifile, UNLOAD, errorcode);
    return;
  }
  target_positions[n].nsteps=nsteps;
  t=NULL;
  x=NULL;
  y=NULL;
  z=NULL;
  CheckMemory;
  NewMemory((void **)&t,ntargtimes*sizeof(float));
  NewMemory((void **)&x,ntargtimes*sizeof(float));
  NewMemory((void **)&y,ntargtimes*sizeof(float));
  NewMemory((void **)&z,ntargtimes*sizeof(float));
  NewMemory((void **)&vals,6*ntargtimes*sizeof(float));
  NewMemory((void **)&color,6*ntargtimes*sizeof(unsigned char));
  target_positions[n].t=t;
  target_positions[n].x=x;
  target_positions[n].y=y;
  target_positions[n].z=z;
  target_positions[n].color=color;
  target_positions[n].vals=vals;
  for(i=0;i<ntargtimes;i++){
    if(fgets(buffer,255,stream)!=NULL){
      sscanf(buffer,"%f %f %f %f %f %f %f %f %f %f",
        &time_local,&xt,&yt,&zt,
        vals_local,vals_local+1,vals_local+2,vals_local+3,vals_local+4,vals_local+5
        );
      target_positions[n].t[i]=time_local;
      targtimes[i]=time_local;
      target_positions[n].x[i]=xt;
      target_positions[n].y[i]=yt;
      target_positions[n].z[i]=zt;
      target_positions[n].vals[6*i]=vals_local[0];
      target_positions[n].vals[6*i+1]=vals_local[1];
      target_positions[n].vals[6*i+2]=vals_local[2];
      target_positions[n].vals[6*i+3]=vals_local[3];
      target_positions[n].vals[6*i+4]=vals_local[4];
      target_positions[n].vals[6*i+5]=vals_local[5];
    }
    else{
      break;
    }
  }

  vals = target_positions[n].vals;
  valmin=vals[0];
  valmax=valmin;
  for(i=1;i<6*ntargtimes;i++){
    if(vals[i]<valmin)valmin=vals[i];
    if(vals[i]>valmax)valmax=vals[i];
  }
  PRINTF("data bounds: min=%f max=%f\n",valmin,valmax);
  if(settargetmin==1)valmin=targetmin;
  if(settargetmax==1)valmax=targetmax;
  PRINTF("applied bounds: min=%f max=%f\n",valmin,valmax);

  target_positions[n].valmin=valmin;
  target_positions[n].valmax=valmax;
  for(i=0;i<6*ntargtimes;i++){
    if(valmax>valmin){
      val = (vals[i]-valmin)/(valmax-valmin);
    }
    else{
      val = 0.5;
    }
    if(val<0.0)val=0.0;
    if(val>1.0)val=1.0;
    color[i]=(unsigned char)(val*255);
  }
  ReadTargFile=1;
  visTarg=1;
  targinfo[ifile].loaded=1;
  targinfo[ifile].display=1;
  plotstate=getplotstate(DYNAMIC_PLOTS);
  Update_Times();
  fclose(stream);
  Idle_CB();

}
예제 #3
0
extern "C" void Smoke3d_CB(int var) {
    int i;
    char *tour_label;
    char *vol_prefixptr;

    updatemenu=1;
    switch(var) {
        float temp_min, temp_max;

    case VOL_UNLOAD_ALL:
        UnLoadVolSmoke3DMenu(-1);
        break;
    case VOL_PREFIX:
        break;
    case VOL_TOUR_LIST:
        TOUR_CB(TOUR_LIST);
        break;
    case START_FRAME:
        if(vol_startframe0<0) {
            vol_startframe0=0;
            SPINNER_startframe->set_int_val(vol_startframe0);
        }
        break;
    case SKIP_FRAME:
        if(vol_skipframe0<1) {
            vol_skipframe0=1;
            SPINNER_skipframe->set_int_val(vol_skipframe0);
        }
        break;
    case CANCEL_GENERATE_IMAGES:
        Script_CB(SCRIPT_CANCEL_NOW);
        break;
    case GENERATE_IMAGES:
        if(selected_tour==NULL) {
            tour_label=NULL;
        }
        else {
            tour_label=selected_tour->label;
        }
        trim(vol_prefix);
        vol_prefixptr=trim_front(vol_prefix);
        if(strlen(vol_prefixptr)==0)vol_prefixptr=fdsprefix;
        init_volrender_script(vol_prefixptr, tour_label, vol_startframe0, vol_skipframe0);
        break;
    case NONGPU_VOL_FACTOR:
        init_volrender_surface(NOT_FIRSTCALL);
        break;
    case GPU_VOL_FACTOR:
        break;
    case COMBINE_MESHES:
        define_volsmoke_textures();
        break;
    case SHOW_FIRECOLORMAP:
        Update_Smokecolormap(smoke_render_option);
        if(show_firecolormap==1) {
            show_glui_colorbar();
        }
        else {
            hide_glui_colorbar();
        }
        break;
    case TEMP_MIN:
        temp_min = 20.0;
        temp_max = (float)(10.0*(int)(temperature_cutoff/10.0)-10.0);
        SPINNER_temperature_min->set_float_limits(temp_min,temp_max);
        Update_Smokecolormap(smoke_render_option);
        break;
    case TEMP_CUTOFF:
        temp_min = (float)(10*(int)(temperature_min/10.0) + 10.0);
        temp_max = (float)(10*(int)(temperature_max/10.0) - 10.0);
        SPINNER_temperature_cutoff->set_float_limits(temp_min,temp_max);
        Update_Smokecolormap(smoke_render_option);
        break;
    case TEMP_MAX:
        temp_min = (float)(10*(int)(temperature_cutoff/10.0)+10.0);
        temp_max = 1800.0;
        SPINNER_temperature_max->set_float_limits(temp_min,temp_max);
        Update_Smokecolormap(smoke_render_option);
        break;
    case LOAD_COMPRESSED_DATA:
        if(load_volcompressed==1) {
            CHECKBOX_compress_volsmoke->disable();
        }
        else {
            CHECKBOX_compress_volsmoke->enable();
        }
        break;
    case SMOKE_OPTIONS:
        if(firecolormap_type!=FIRECOLORMAP_NOCONSTRAINT&&smoke_render_option==RENDER_SLICE) {
            PANEL_colormap2b->enable();
            SPINNER_hrrpuv_cutoff->enable();
            PANEL_colormap2b->open();
        }
        else {
            PANEL_colormap2b->disable();
            PANEL_colormap2b->close();
        }
        if(smoke_render_option==RENDER_SLICE) {
            if(PANEL_colormap2a!=NULL) {
                PANEL_colormap2a->disable();
                PANEL_colormap2a->close();
            }
            if(PANEL_absorption!=NULL)PANEL_absorption->enable();
            firecolormap_type=firecolormap_type_save;
            RADIO_use_colormap->set_int_val(firecolormap_type);
            RADIOBUTTON_direct->enable();
            SPINNER_smoke3d_fire_halfdepth->enable();
        }
        else {
            if(PANEL_colormap2a!=NULL) {
                PANEL_colormap2a->enable();
                PANEL_colormap2a->open();
            }
            if(PANEL_absorption!=NULL)PANEL_absorption->disable();
            firecolormap_type_save=firecolormap_type;
            firecolormap_type=FIRECOLORMAP_CONSTRAINT;
            RADIO_use_colormap->set_int_val(firecolormap_type);
            RADIOBUTTON_direct->disable();
            SPINNER_smoke3d_fire_halfdepth->disable();
        }
        Smoke3d_CB(FIRECOLORMAP_TYPE);
        Update_Smoke_Type();
        break;
    case FIRECOLORMAP_TYPE:
        if(firecolormap_type==FIRECOLORMAP_CONSTRAINT&&smoke_render_option==RENDER_VOLUME) {
            PANEL_colormap2a->open();
            PANEL_colormap2a->enable();
        }
        else {
            PANEL_colormap2a->close();
            PANEL_colormap2a->disable();
        }
        if(firecolormap_type!=FIRECOLORMAP_NOCONSTRAINT&&smoke_render_option==RENDER_SLICE) {
            PANEL_colormap2b->enable();
            SPINNER_hrrpuv_cutoff->enable();
            PANEL_colormap2b->open();
        }
        else {
            PANEL_colormap2b->disable();
            PANEL_colormap2b->close();
        }
        if(firecolormap_type!=FIRECOLORMAP_DIRECT) {
            LISTBOX_smoke_colorbar->enable();
            ROLLOUT_colormap3->disable();
            ROLLOUT_colormap3->close();
            if(fire_colorbar_index_save!=-1) {
                SmokeColorBarMenu(fire_colorbar_index_save);
            }
            else {
                SmokeColorBarMenu(fire_colorbar_index);
            }
        }
        else {
            LISTBOX_smoke_colorbar->disable();
            ROLLOUT_colormap3->enable();
            ROLLOUT_colormap3->open();
            SPINNER_smoke3d_smoke_albedo->enable();
            SPINNER_smoke3d_fire_red->enable();
            SPINNER_smoke3d_fire_green->enable();
            SPINNER_smoke3d_fire_blue->enable();
            SPINNER_smoke3d_fire_halfdepth->enable();

            fire_colorbar_index_save=fire_colorbar_index;
        }
        if(LISTBOX_smoke_colorbar->get_int_val()!=fire_colorbar_index) {
            LISTBOX_smoke_colorbar->set_int_val(fire_colorbar_index);
        }
        Update_Smokecolormap(smoke_render_option);
        break;
    case SMOKE_COLORBAR_LIST:
        SmokeColorBarMenu(fire_colorbar_index);
        Update_Smokecolormap(smoke_render_option);
        updatemenu=1;
        break;
    case SMOKETEST:
        update_alpha();
        break;
    case FRAMELOADING:
        smoke3dframestep = smoke3dframeskip+1;
        updatemenu=1;
        break;
    case SAVE_SETTINGS:
        writeini(LOCAL_INI,NULL);
        break;
    case GLOBAL_FIRE_CUTOFF:
        glutPostRedisplay();
        force_redisplay=1;
        Idle_CB();
        Update_Smokecolormap(smoke_render_option);
        break;
    case FIRE_RED:
    case FIRE_GREEN:
    case FIRE_BLUE:
    case SMOKE_SHADE:
        glutPostRedisplay();
        force_redisplay=1;
        Update_Smokecolormap(smoke_render_option);
        Idle_CB();
        break;
    case FIRE_HALFDEPTH:
        for(i=0; i<nmeshes; i++) {
            mesh *meshi;

            meshi = meshinfo + i;
            meshi->update_firehalfdepth=1;
        }
        glutPostRedisplay();
        force_redisplay=1;
        Update_Smokecolormap(smoke_render_option);
        Idle_CB();
        break;
#ifdef pp_GPU
    case SMOKE_RTHICK:

        smoke3d_thick = log_base2(smoke3d_rthick);
        glutPostRedisplay();
        force_redisplay=1;
        Idle_CB();
        break;
#else
    case SMOKE_THICK:
        glutPostRedisplay();
        force_redisplay=1;
        Idle_CB();
        break;
#endif
#ifdef pp_CULL
    case CULL_PORTSIZE:
        initcull(cullsmoke);
        break;
    case CULL_SMOKE:
        initcull(cullsmoke);
        break;
#endif
    case VOL_NGRID:
        glutPostRedisplay();
        break;
    case VOL_SMOKE:
    {
        volrenderdata *vr;

        vr = &meshinfo->volrenderinfo;
        if(vr!=NULL&&vr->smokeslice!=NULL&&vr->smokeslice->slicetype==SLICE_CENTER) {
            if(usegpu==1&&combine_meshes==1) {
                combine_meshes=0;
                update_combine_meshes();
                Smoke3d_CB(COMBINE_MESHES);
            }
            if(usegpu==0&&combine_meshes==0) {
                combine_meshes=1;
                update_combine_meshes();
                Smoke3d_CB(COMBINE_MESHES);
            }
        }
    }
    if(smoke_render_option==RENDER_SLICE) {
#ifdef pp_GPU
        if(usegpu==1) {
            RADIO_skipframes->set_int_val(0);
            RADIO_skipframes->disable();
#ifdef pp_CULL
            if(cullactive==1) {
                CHECKBOX_smokecullflag->enable();
            }
            SPINNER_cull_portsize->enable();
            CHECKBOX_show_cullports->enable();
#endif
        }
        else {
            RADIO_skipframes->enable();
#ifdef pp_CULL
            CHECKBOX_smokecullflag->disable();
            SPINNER_cull_portsize->disable();
            CHECKBOX_show_cullports->disable();
#endif
        }
#else
        RADIO_skipframes->enable();
#endif
    }
    break;
    default:
#ifdef _DEBUG
        abort();
#endif
        break;
    }
}