elene@5: #include elene@5: #include elene@4: #include elene@5: #include elene@5: elene@5: #include elene@5: #include elene@4: elene@3: #include "volume.h" elene@4: elene@5: static char *strip_whitespaces(char *buf); elene@5: elene@4: Volume::Volume() elene@4: { elene@4: width = height = 0; elene@5: zaspect = 1; elene@4: } elene@4: elene@4: bool Volume::load_volume(const char *fname) elene@4: { elene@5: FILE *fp = fopen(fname, "r"); elene@5: if(!fp) { elene@5: fprintf(stderr, "Failed to open file: %s: %s\n", fname, strerror(errno)); elene@5: return false; elene@5: } elene@5: elene@5: char buf[512]; elene@5: if(!fgets(buf, sizeof buf, fp)) { elene@5: fprintf(stderr, "Empty file: %s.\n", fname); elene@5: return false; elene@5: } elene@5: if(strstr(buf, "VOLUME") != buf) { elene@5: fprintf(stderr, "Invalid volume file format: %s\n", fname); elene@5: return false; elene@5: } elene@5: elene@5: bool reading_slices = false; elene@5: std::vector img_fnames; elene@5: elene@5: while(fgets(buf, sizeof buf, fp)) { elene@5: char *line = strip_whitespaces(buf); elene@5: if(!line || *line == 0 || *line == '#') elene@5: continue; elene@5: elene@5: if(reading_slices == false) { elene@5: if(strcmp(line, "SLICES") == 0) elene@5: reading_slices = true; elene@5: elene@5: sscanf(line, "zaspect = %f", &zaspect); elene@5: } elene@5: else { elene@5: img_fnames.push_back(line); elene@5: } elene@5: } elene@5: elene@5: fclose(fp); elene@5: elene@5: for(size_t i=0; i buf && isspace(*end)) elene@5: end--; elene@5: end[1] = 0; elene@5: return buf; elene@5: }