Referência do Arquivo /home/carolina/workspace/spvolren_cpu/reader.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "reader.h"
#include "sysconf.h"

Vá para o código-fonte deste arquivo.

Funções

void readData (char *filename, int *sizes, float *dists, void **data, DataType *type, int *numComponents)
int getDataTypeSize (DataType t)

Funções

int getDataTypeSize ( DataType  t  ) 

Definição na linha 152 do arquivo reader.c.

00153 {
00154         switch(t) {
00155                 case DATRAW_UCHAR:
00156                         return 1;
00157                         break;
00158                 case DATRAW_USHORT:
00159                         return 2;
00160                         break;
00161                 default:
00162                         fprintf(stderr, "Unsupported data type!\n");
00163                         exit(1);
00164         }
00165 }

void readData ( char *  filename,
int *  sizes,
float *  dists,
void **  data,
DataType type,
int *  numComponents 
)

Definição na linha 25 do arquivo reader.c.

00027 {
00028         char *cp, line[100], rawFilename[100];
00029         int parseError, dataTypeSize = 0;
00030         size_t size;
00031     FILE *fp;
00032 
00033     if (! (fp = fopen(filename, "rb"))) {
00034         perror("opening .dat file failed");
00035         exit(1);
00036     }
00037 
00038         parseError = 0;
00039         while (fgets(line, sizeof(line), fp)) {
00040                 if (strstr(line, "ObjectFileName")) {
00041                         if (! (cp = strchr(line, ':'))) {
00042                                 parseError = 1;
00043                                 break;
00044                         }
00045                         if (sscanf(cp + 1, "%s", rawFilename) != 1)     {
00046                                 parseError = 1;
00047                                 break;
00048                         }
00049                 } else if (strstr(line, "Resolution")) {
00050                         if (! (cp = strchr(line, ':'))) {
00051                                 parseError = 1;
00052                                 break;
00053                         }
00054                         if (sscanf(cp + 1, "%i %i %i", 
00055                                            &sizes[0], &sizes[1], &sizes[2]) != 3) {
00056                                 parseError = 1;
00057                                 break;
00058                         }
00059                 } else if (strstr(line, "SliceThickness")) {
00060                         if (! (cp = strchr(line, ':'))) {
00061                                 parseError = 1;
00062                                 break;
00063                         }
00064                         if (sscanf(cp + 1, "%f %f %f", 
00065                                            &dists[0], &dists[1], &dists[2]) != 3) {
00066                                 parseError = 1;
00067                                 break;
00068                         }
00069                 } else if (strstr(line, "Format")) {
00070                         if (strstr(line, "UCHAR")) {
00071                                 *type = DATRAW_UCHAR;
00072                                 *numComponents = 1;
00073                                 dataTypeSize = sizeof(char);
00074                         } else if (strstr(line, "USHORT")) {
00075                                 *type = DATRAW_USHORT;
00076                                 *numComponents = 1;
00077                                 dataTypeSize = sizeof(short);
00078                         } else if (strstr(line, "FLOAT")) {
00079                                 char *cp, temp[100];
00080 
00081                                 *type = DATRAW_FLOAT;
00082                                 dataTypeSize = sizeof(float);
00083 
00084                                 if (! (cp = strchr(line, ':'))) {
00085                                         parseError = 1;
00086                                         break;
00087                                 }
00088                                 if (sscanf(cp + 1, "%s", temp) != 1) {
00089                                         parseError = 1;
00090                                         break;
00091                                 }
00092 
00093                                 cp = temp;
00094                                 while (*cp && ! isdigit(*cp)) {
00095                                         cp++;
00096                                 }
00097                                 if (*cp) {
00098                                         if (sscanf(cp, "%i", numComponents) != 1) {
00099                                                 parseError = 1;
00100                                                 break;
00101                                         }
00102                                 } else {
00103                                         *numComponents = 1;
00104                                 }
00105                         } else {
00106                                 fprintf(stderr, "cannot process data other than of "
00107                                                 "UCHAR and FLOAT* format\n");
00108                                 exit(1);
00109                         }
00110                 } else {
00111                         fprintf(stderr, "skipping line %s", line);
00112                 }
00113         }
00114 
00115         if (parseError) {
00116                 fprintf(stderr, "parse error: %s\n", line);
00117                 exit(1);
00118         }
00119 
00120         fclose(fp);
00121 
00122     if (! (fp = fopen(rawFilename, "rb"))) {
00123                 char temp[100];
00124                 strcpy(temp, filename);
00125                 if (! (cp = strrchr(temp, DIR_SEP))) { 
00126                         perror("opening .raw file failed");
00127                         exit(1);
00128                 }
00129                 strcpy(cp + 1, rawFilename);
00130         if (! (fp = fopen(temp, "rb"))) {
00131                         perror("opening .raw file failed");
00132                         exit(1);
00133                 }
00134     }
00135 
00136     size = sizes[0] * sizes[1] * sizes[2];
00137 
00138         if (! (*data = malloc(size * *numComponents * dataTypeSize))) {
00139                 fprintf(stderr, "not enough memory for volume data\n");
00140                 exit(1);
00141         }
00142 
00143     if (fread(*data, dataTypeSize, size * *numComponents, fp) != 
00144                 size * *numComponents) {
00145         fprintf(stderr, "reading volume data failed");
00146         exit(1);
00147     }
00148 
00149     fclose(fp); 
00150 }

 Todos Estruturas de Dados Arquivos Funções Variáveis Definições de Tipos Enumerações Valores enumerados Definições e Macros

Gerado em Sat Dec 12 01:59:33 2009 para Carolina Simões Gomes (RA042533). Estudo de um framework para Raycasting em GPU por  doxygen 1.6.1