volmetrics

changeset 5:92c163c939be

Volume::load
author Eleni Maria Stea <elene.mst@gmail.com>
date Fri, 17 Jan 2014 23:45:56 +0200
parents 1fbbe10c8e08
children e6485ef45e6e
files data/test1.vol src/volume.cc src/volume.h
diffstat 3 files changed, 95 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/data/test1.vol	Fri Jan 17 23:45:56 2014 +0200
     1.3 @@ -0,0 +1,19 @@
     1.4 +VOLUME
     1.5 +zaspect = 1
     1.6 +
     1.7 +SLICES
     1.8 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0001.png
     1.9 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0003.png
    1.10 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0004.png
    1.11 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0005.png
    1.12 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0006.png
    1.13 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0007.png
    1.14 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0008.png
    1.15 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0009.png
    1.16 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0010.png
    1.17 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0011.png
    1.18 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0012.png
    1.19 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0013.png
    1.20 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0014.png
    1.21 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0015.png
    1.22 +/home/eleni/code/med/test1/data/la_colonoscopie/IM-0001-0016.png
     2.1 --- a/src/volume.cc	Sat Jan 11 23:49:58 2014 +0200
     2.2 +++ b/src/volume.cc	Fri Jan 17 23:45:56 2014 +0200
     2.3 @@ -1,14 +1,70 @@
     2.4 +#include <ctype.h>
     2.5 +#include <errno.h>
     2.6  #include <stdio.h>
     2.7 +#include <string.h>
     2.8 +
     2.9 +#include <string>
    2.10 +#include <vector>
    2.11  
    2.12  #include "volume.h"
    2.13  
    2.14 +static char *strip_whitespaces(char *buf);
    2.15 +
    2.16  Volume::Volume()
    2.17  {
    2.18  	width = height = 0;
    2.19 +	zaspect = 1;
    2.20  }
    2.21  
    2.22  bool Volume::load_volume(const char *fname)
    2.23  {
    2.24 +	FILE *fp = fopen(fname, "r");
    2.25 +	if(!fp) {
    2.26 +		fprintf(stderr, "Failed to open file: %s: %s\n", fname, strerror(errno));
    2.27 +		return false;
    2.28 +	}
    2.29 +
    2.30 +	char buf[512];
    2.31 +	if(!fgets(buf, sizeof buf, fp)) {
    2.32 +		fprintf(stderr, "Empty file: %s.\n", fname);
    2.33 +		return false;
    2.34 +	}
    2.35 +	if(strstr(buf, "VOLUME") != buf) {
    2.36 +		fprintf(stderr, "Invalid volume file format: %s\n", fname);
    2.37 +		return false;
    2.38 +	}
    2.39 +
    2.40 +	bool reading_slices = false;
    2.41 +	std::vector<std::string> img_fnames;
    2.42 +
    2.43 +	while(fgets(buf, sizeof buf, fp)) {
    2.44 +		char *line = strip_whitespaces(buf);
    2.45 +		if(!line || *line == 0 || *line == '#')
    2.46 +			continue;
    2.47 +
    2.48 +		if(reading_slices == false) {
    2.49 +			if(strcmp(line, "SLICES") == 0)
    2.50 +				reading_slices = true;
    2.51 +
    2.52 +			sscanf(line, "zaspect = %f", &zaspect);
    2.53 +		}
    2.54 +		else {
    2.55 +			img_fnames.push_back(line);
    2.56 +		}
    2.57 +	}
    2.58 +
    2.59 +	fclose(fp);
    2.60 +
    2.61 +	for(size_t i=0; i<img_fnames.size(); i++) {
    2.62 +		Image img;
    2.63 +		if(img.load(img_fnames[i].c_str())) {
    2.64 +			push_slice(std::move(img));
    2.65 +		}
    2.66 +		else {
    2.67 +			fprintf(stderr, "Failed to load slice: %s\n", img_fnames[i].c_str());
    2.68 +		}
    2.69 +	}
    2.70 +
    2.71  	return true;
    2.72  }
    2.73  
    2.74 @@ -28,3 +84,22 @@
    2.75  	slices.push_back(slice);
    2.76  	return true;
    2.77  }
    2.78 +
    2.79 +void Volume::draw()
    2.80 +{
    2.81 +}
    2.82 +
    2.83 +static char *strip_whitespaces(char *buf)
    2.84 +{
    2.85 +	while(*buf && isspace(*buf))
    2.86 +		buf++;
    2.87 +
    2.88 +	if(!*buf)
    2.89 +		return 0;
    2.90 +
    2.91 +	char *end = buf + strlen(buf) - 1;
    2.92 +	while(end > buf && isspace(*end))
    2.93 +		end--;
    2.94 +	end[1] = 0;
    2.95 +	return buf;
    2.96 +}
     3.1 --- a/src/volume.h	Sat Jan 11 23:49:58 2014 +0200
     3.2 +++ b/src/volume.h	Fri Jan 17 23:45:56 2014 +0200
     3.3 @@ -9,6 +9,7 @@
     3.4  	std::vector<Image> slices;
     3.5  	int width;
     3.6  	int height;
     3.7 +	float zaspect;
     3.8  
     3.9  public:
    3.10  	Volume();