[37] | 1 | /* |
---|
| 2 | * Name : mcfile.c |
---|
| 3 | * |
---|
| 4 | * Coded : Paul Ning 9/18/89 |
---|
| 5 | * |
---|
| 6 | * Comment : Library routines for Marching Cubes File Package |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include <stdlib.h> |
---|
| 10 | #include <stdio.h> |
---|
| 11 | #include "mcfile.h" |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | /* |
---|
| 15 | * GENERAL |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | static void Fatal(message) |
---|
| 19 | char *message; |
---|
| 20 | { |
---|
| 21 | printf("MCFILE : %s\n",message); |
---|
| 22 | fflush(stdout); |
---|
| 23 | exit(-1); |
---|
| 24 | } /* Fatal */ |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | /* |
---|
| 28 | * HEADER STUFF |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | Boolean IsMCFile(fp) |
---|
| 32 | FILE *fp; |
---|
| 33 | { |
---|
| 34 | int magic; |
---|
| 35 | |
---|
| 36 | rewind(fp); |
---|
| 37 | if ((fread(&magic,sizeof(int),1,fp) != 1) || (magic != MC_MAGIC)) |
---|
| 38 | return(FALSE); |
---|
| 39 | else |
---|
| 40 | return(TRUE); |
---|
| 41 | } /* IsMCFile */ |
---|
| 42 | |
---|
| 43 | void MC_InitHeader(fp) |
---|
| 44 | FILE *fp; |
---|
| 45 | { |
---|
| 46 | mcfile header; |
---|
| 47 | |
---|
| 48 | /* These lines inserted so that this compiles. |
---|
| 49 | I don't understand what this function really does, other than |
---|
| 50 | write out an unitialized header. (Brian Curless, June 5, 2006) */ |
---|
| 51 | |
---|
| 52 | header.mc_length = 0; |
---|
| 53 | header.mc_tmaptype = 0; |
---|
| 54 | header.mc_type = 0; |
---|
| 55 | header.mc_magic = 0; |
---|
| 56 | |
---|
| 57 | MC_WriteHeader(fp,header); |
---|
| 58 | } /* MC_InitHeader */ |
---|
| 59 | |
---|
| 60 | void MC_WriteHeader(fp,header) |
---|
| 61 | FILE *fp; |
---|
| 62 | mcfile header; |
---|
| 63 | { |
---|
| 64 | rewind(fp); |
---|
| 65 | if (fwrite(&header,sizeof(mcfile),1,fp) != 1) |
---|
| 66 | Fatal("Error in writing MC header"); |
---|
| 67 | } /* MC_WriteHeader */ |
---|
| 68 | |
---|
| 69 | mcfile MC_ReadHeader(fp) |
---|
| 70 | FILE *fp; |
---|
| 71 | { |
---|
| 72 | mcfile header; |
---|
| 73 | |
---|
| 74 | rewind(fp); |
---|
| 75 | if (fread(&header,sizeof(mcfile),1,fp) != 1) |
---|
| 76 | Fatal("Error in reading MC header"); |
---|
| 77 | return(header); |
---|
| 78 | } /* MC_ReadHeader */ |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | /* |
---|
| 82 | * SURFACE DATA STUFF |
---|
| 83 | */ |
---|
| 84 | |
---|
| 85 | void MC_WriteTriangleVertex(fp,vertex) |
---|
| 86 | FILE *fp; |
---|
| 87 | TriangleVertex vertex; |
---|
| 88 | { |
---|
| 89 | if (fwrite(&vertex,sizeof(TriangleVertex),1,fp) != 1) |
---|
| 90 | Fatal("Error in writing vertex data"); |
---|
| 91 | } /* MC_WriteTriangleVertex */ |
---|
| 92 | |
---|
| 93 | TriangleVertex MC_ReadTriangleVertex(fp) |
---|
| 94 | FILE *fp; |
---|
| 95 | { |
---|
| 96 | TriangleVertex vertex; |
---|
| 97 | |
---|
| 98 | if (fread(&vertex,sizeof(TriangleVertex),1,fp) != 1) |
---|
| 99 | Fatal("Error in reading vertex data"); |
---|
| 100 | return(vertex); |
---|
| 101 | } /* MC_ReadTriangleVertex */ |
---|
| 102 | |
---|
| 103 | |
---|