home *** CD-ROM | disk | FTP | other *** search
-
- /*
-
- dxf2v -- strip 3d faces out of a .dfx file
-
- Copyright 1991 Stephen B. Coy
- modified by Tom Barber april 3 1992 added path recognition
- added layer extraction
-
- modified by Mike Daigle july 3 1992 small fix to layer
- extraction
- added surface color
- extraction
- modified by Adam Shiffman july 30 1992 removed surface color
- code, added RAW output
- */
-
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- main(int argc, char *argv[])
- {
- char str[80];
- int key, npnts,layer,l;
- double x1, x2, x3, x4,
- y1, y2, y3, y4,
- z1, z2, z3, z4;
- FILE *dxf_in_file,*raw_out_file;
-
-
- if(argc < 3) {
- printf("\nDXF2RAW2 Version 1.0 - Adapted from Stephen Coy's DXF2V\n");
- printf("Converts 3DFACEs in DXF files to RAW files of X,Y,Z points.\n");
- printf("Extracts by Layers (if desired)\n");
- printf("Added code by Tom Barber 4/92 Mike Daigle 7/92\n");
- printf("Modified code to output RAW triangles 7/92 Adam Shiffman\n\n");
- printf("Usage: dxf2raw2 file.dxf file.raw [Layer Number]\n\n");
- printf("Where:\n");
- printf(" file.dxf = name of dxf file with extension\n");
- printf(" file.raw = name of RAW file with extension\n");
- printf(" [Layer #]= Layer to be converted. Must be specified,\n");
- printf(" Typical: DXF2RAW2 art.dxf art.raw -1\n");
- printf(" convert art.dxf to art.raw all layers\n");
- exit(1);
- }
-
- //Open the files
- if (!(dxf_in_file = fopen(argv[1],"rb")))
- { puts("Can not open DXF file!");
- exit(1);
- }
-
- if (!(raw_out_file = fopen(argv[2],"w")))
- { puts("Can not open RAW file for output!");
- fclose(dxf_in_file);
- exit(1);
- }
-
- layer = -1;
-
- if (argc > 3) layer = atoi(argv[3]);
-
- while(fgets(str, 80, dxf_in_file)) {
- //Wait until we find a 3DFACE...
- if(strncmp(str, "3DFACE", 6) != 0) {continue;}
- fgets(str,80,dxf_in_file);
- if (atoi(str) != 8) {printf("WARNING...LAYER...MISSED\n");}
- fgets(str,80,dxf_in_file);
-
- if (layer != atoi(str) && layer != -1) {continue;}
-
- x1 = x2 = x3 = x4 = y1 = y2 = y3 = y4 = z1 = z2 = z3 = z4 = 0.0;
- do {
- fgets(str, 80, dxf_in_file);
- key = atoi(str);
- fgets(str, 80, dxf_in_file);
- switch(key) {
- case 10 : x1 = atof(str); break;
- case 20 : y1 = atof(str); break;
- case 30 : z1 = atof(str); break;
- case 11 : x2 = atof(str); break;
- case 21 : y2 = atof(str); break;
- case 31 : z2 = atof(str); break;
- case 12 : x3 = atof(str); break;
- case 22 : y3 = atof(str); break;
- case 32 : z3 = atof(str); break;
- case 13 : x4 = atof(str); break;
- case 23 : y4 = atof(str); break;
- case 33 : z4 = atof(str); break;
- default : break;
- }
- } while(key != 33);
-
- /* check for non-unique points */
-
- npnts = 4;
- if(x1==x2 && y1==y2 && z1==z2) {
- x2 = x3; x3 = x4;
- y2 = y3; y3 = y4;
- z2 = z3; z3 = z4;
- npnts--;
- }
- if(npnts < 3) continue;
- if(x1==x2 && y1==y2 && z1==z2) {
- continue;
- }
- if(x1==x3 && y1==y3 && z1==z3) {
- x3 = x4;
- y3 = y4;
- z3 = z4;
- npnts--;
- }
- if(npnts < 3) continue;
- if(x2==x3 && y2==y3 && z2==z3) {
- x3 = x4;
- y3 = y4;
- z3 = z4;
- npnts--;
- }
- if(npnts < 3) continue;
- if(npnts==4 && x4==x3 && y4==y3 && z4==z3) {
- npnts--;
- }
- if(npnts < 3) continue;
-
- /* got the poly, output it */
-
- if(npnts == 4) {
- fprintf(raw_out_file,"%.4f %.4f %.4f\n", x1, y1, z1);
- fprintf(raw_out_file,"%.4f %.4f %.4f\n", x2, y2, z2);
- fprintf(raw_out_file,"%.4f %.4f %.4f\n}\n", x3, y3, z3);
- fprintf(raw_out_file,"%.4f %.4f %.4f\n", x1, y1, z1);
- fprintf(raw_out_file,"%.4f %.4f %.4f\n", x3, y3, z3);
- fprintf(raw_out_file,"%.4f %.4f %.4f\n}\n", x4, y4, z4);
- } else {
- fprintf(raw_out_file,"%.4f %.4f %.4f\n", x1, y1, z1);
- fprintf(raw_out_file,"%.4f %.4f %.4f\n", x2, y2, z2);
- fprintf(raw_out_file,"%.4f %.4f %.4f\n}\n", x3, y3, z3);
- } /* END WHILE */
-
- }
-
- fclose(raw_out_file);
- fclose(dxf_in_file);
- } /* end of main() */
-