/* This program is used to transform the Deneb Robotics part format to to VRML2 file. The text, texture, curve and surface are not translated. Usage: part2vrml2 deneb_file vrml_file To compile, cc -o part2vrml2 part2vrml2.c Qiming Wang Visualization and Virtual Reality Group Information Technology Lab NIST */ #include #include #define NUMBER_COLOR 32 typedef struct { char name[20]; int old_c; float new_c[3]; } table; table table_data[] = { {"white", 4, {1., 1., 1.}}, {"grey", 5, {0.5, 0.5, 0.5}}, {"black", 6, {0.1,0.1,0.1}}, {"red", 7, {1., 0., 0.}}, {"green", 8, {0.,0.,0.}}, {"blue", 9, {0., 0., 1.}}, {"yellow", 10, {1., 1., 0.}}, {"cyan", 11, {0., 1., 1.}}, {"purple", 12, {0.53, 0.12, 0.47}}, {"orange", 13, {1., 0.5, 0.}}, {"magenta", 14, {1., 0., 1.}}, {"cherry", 15, {0.74, 0.56, 0.56}}, {"light blue", 16, {0., 0., 0.75}}, {"brown", 17, {0.65, 0.16, 0.16}}, {"lime", 18, {0.20, 0.8, 0.2}}, {"tan", 19, {0.85, 0.58, 0.44}}, {"all black", 20, {0.,0.,0}}, {"grey-75", 21, {0.75,0.75,0.75}}, {"slate grey", 22, {0.18, 0.31, 0.31}}, {"teal", 23, {0.2, 0.2, 0.8}}, {"dodger blue", 24, {0.26, 0.43, 0.26}}, {"cobalt", 25, {0.14, 0.14, 0.56}}, {"dark plum", 26, {0.92, 0.68, 0.92}}, {"brass", 27, {0.71, 0.65, 0.25}}, {"color25", 28, {0.85, 0.58,0.44}}, {"color26", 29, {0.20,0.20, 0.8}}, {"color27", 30, {1.,1.,1.}}, {"color28", 31, {0.20,0.20,0.8}}, {"color29", 32, {0.74, 0.56, 0.56}}, {"color30", 33, {0.92, 0.68, 0.92}}, {"color31", 34, {1.,1.,1.}}, {"color32", 35, {0.,0.,0.}}, }; void t_color(); void trans_text(FILE *inp_file, FILE *out_file) { char string[100]; float x, y, z, width; float rx, ry, rz, rr; float size, slant, aspect, unkown; int color, i1, i2, i; float rgb[3]; fgets(string, 100, inp_file); for (i=0; i<100; i++) if (string[i]=='\n') string[i]='\0'; fscanf(inp_file, "%f %f %f\n", &x, &y, &z); fscanf(inp_file, "%f %f %f %f\n", &rx, &ry, &rz, &rr); fscanf(inp_file, "%f %f %f %f\n", &size, &slant, &aspect, &unkown); fscanf(inp_file, "%d %d %d\n", &color, &i1, &i2); t_color(color, rgb); width = strlen(string)*size*aspect*0.7; fprintf(out_file, " Separator {\n"); fprintf(out_file, " Material {\n"); fprintf(out_file, " diffuseColor %f %f %f\n", rgb[0], rgb[1], rgb[2]); fprintf(out_file, " }\n"); fprintf(out_file, " Translation {\n"); fprintf(out_file, " translation %f %f %f\n",x,y,z); fprintf(out_file, " }\n"); /* fprintf(out_file, " Rotation {\n"); fprintf(out_file, " rotation %f %f %f\n",rx,ry,rz); fprintf(out_file, " }\n");*/ fprintf(out_file, " FontStyle {\n"); fprintf(out_file, " size %f\n", size); fprintf(out_file, " }\n"); fprintf(out_file, " AsciiText {\n"); fprintf(out_file, " string \"%s\"\n", string); fprintf(out_file, " width %f\n", width); fprintf(out_file, " }\n }\n"); } main( int argc, char **argv) { FILE *file, *out_file; int version, n_coorsys, n_curve, n_surface, n_obj; int color_index, n_point, n_line, n_poly, n_seg, n_text, n_texture, i,j,k; int *n_index, *nn_index; float coor[4][3], color[3]; float **points; int **lines, **segs; int **polys, **nn_polys; char s[100], out_filename[50],star[1]; int zero, number, number1, number2, nn_line; file = fopen(argv[1], "r"); out_file = fopen(argv[2], "w"); fprintf(out_file, "#VRML V2.0 utf8\n\n"); fprintf(out_file, "Transform {\n"); fprintf(out_file, " scale 0.001 0.001 0.001\n"); fprintf(out_file, " rotation 1 0 0 -1.57\n"); fprintf(out_file, " children [\n"); /* read version and number of coordinate system */ fscanf(file, "%d\n", &version); /* if (version > 11) { printf("This is not version 11, exit\n"); exit(); } */ fscanf(file, "%d\n", &n_coorsys); for( i=0; i 0, stop\n"); exit(); } /* surface */ fscanf(file, "%d\n", &n_surface); if (n_surface != 0) { printf("number of surface > 0, stop\n"); exit(); } fscanf(file, "%d\n", &n_obj); for (i=0; i 0) { printf("number of text > 0, text information lost\n"); } */ if (version >= 11) { fscanf(file, "%d\n", &n_texture); for (j=0; j 0) printf("texture information lost\n"); } /* now to output object */ fprintf(out_file, " Transform {\n"); fprintf(out_file, " children [\n"); fprintf(out_file, " Shape {\n"); /* get color from table */ t_color(color_index, color); fprintf(out_file, " appearance Appearance {\n"); fprintf(out_file, " material Material { \n"); fprintf(out_file, " diffuseColor %f %f %f\n", color[0],color[1],color[2]); fprintf(out_file, " }\n"); fprintf(out_file, " }\n"); if (n_poly > 0 ) { fprintf(out_file, " geometry IndexedFaceSet {\n"); fprintf(out_file, " coord Coordinate {\n"); fprintf(out_file, " point [\n"); for (j=0; j 0) { fprintf(out_file, " geometry IndexedLineSet {\n"); fprintf(out_file, " coord Coordinate {\n"); fprintf(out_file, " point [\n"); for (j=0; j