/*==========================================================*/ * * MODULE: * anim balls color * * DESCRIPTION: * Animates a number of particles in three dimensions. * * AUTHOR: * Salim Alam, University of Colorado, Boulder. * * MODIFICATION LOG: * 92.06.04 S.A. - added individually selectable particles * 92.06.03 S.A. - all numbers now read in as floating point. * added debugging statements. * /*==========================================================*/ #include <stdio.h> #include <avs/avs.h> #include <avs/geom.h> typedef float FLOAT3[3]; #define MAX_BALLS 250 /* #define DEBUG */ /* ======================== module function ==================== */ /* module description function */ int anim_balls_desc() { int parm; char *cwd; char *getcwd(); AVSset_module_name("anim balls color", MODULE_DATA); AVScreate_output_port("output geom", "geom"); if ((cwd=getcwd((char *)NULL, 80)) == NULL) { perror("pwd"); exit(1); } cwd[strlen(cwd)]='/'; parm = AVSadd_parameter("Filename", "string", cwd, NULL, NULL); AVSconnect_widget(parm, "browser"); free(cwd); AVSadd_parameter("Speed", "integer", 0, 0, 500); AVSadd_parameter("Pause", "boolean", 1, 0, 1); parm = AVSadd_float_parameter("Radius", 0.3, 0.0, 1.0); AVSconnect_widget(parm, "dial"); } /* =================== main program =========================== */ main(argc, argv) int argc; char *argv[]; { int sleep = 1; int speed = 0; float *pradius; char *filename; int i; int num_verts; int num_frames; int curr_frame = 1; FLOAT3 verts[MAX_BALLS]; float radii[MAX_BALLS]; FILE *fp = NULL; GEOMobj *obj = NULL; GEOMedit_list output = NULL; char obj_name[100]; int color; unsigned long colors[MAX_BALLS]; /*unsigned long ball_colors[]={ 804000000,1004000000,1000,1900000000, 130000,9900000};*/ /* AVS initialization */ AVScorout_init(argc, argv, anim_balls_desc); /* main loop */ while (1) { /* wait for a parameter, if appropriate */ if (!sleep) AVScorout_mark_changed(); AVScorout_wait(); /* check for modified parameters */ AVScorout_input(&filename, &speed, &sleep, &pradius); if (AVSparameter_changed("Filename")) { if (fp) fclose(fp); fp = fopen(filename, "r"); fscanf(fp, "%d",&num_verts); fscanf(fp, "%d",&num_frames); for (i=0; i < num_verts; i++) { fscanf(fp, "%d",&color); colors[i] = ball_colors[color]; } curr_frame = 1; #ifdef DEBUG fprintf(stderr, "n_verts = %d, n_frames = %d\n", num_verts, num_frames); #endif } if (curr_frame >= num_frames) { sleep = 1; AVSmodify_parameter("Pause",AVS_VALUE, 1, 0, 1); continue; } /* read a frame */ fscanf(fp, "%*f %*f %*f %*f %*f"); /* skip energy */ #ifdef DEBUG fprintf(stderr, "-- frame # %d\n", curr_frame); #endif for (i=0; i < num_verts; i++) { fscanf(fp,"%*f %*f %f %f %f",&verts[i][0],&verts[i][1], &verts[i][2]); fscanf(fp, "%*f %*f %*f %*f %*f"); /* skip direction vectors */ radii[i] = *pradius; #ifdef DEBUG fprintf(stderr, "%f %f %f\n", verts[i][0],verts[i][1],verts[i][2]); #endif } curr_frame++; /* generate new frame */ output = GEOMinit_edit_list(output); for (i=0; i < num_verts; i++) { if (obj) GEOMdestroy_obj(obj); obj = GEOMcreate_sphere(GEOM_NULL,&(verts[i]),radii,GEOM_NULL, &colors[i], 1 ,GE OM_DONT_COPY_DATA); /* modify edit list */ GEOMset_pickable(obj, 1); sprintf(obj_name, "frame%d", i); GEOMedit_geometry(output,obj_name,obj); } /* give frame to AVS */ AVScorout_output(output); #ifdef NEVER /* check speed */ if (speed > 0) usleep(2500*speed); #endif #ifdef NEVER /* wait for flow executive */ AVScorout_exec(); #endif } /* while */ } /* main */