volmetrics

changeset 3:927c29b93009

added image.cc
author Eleni Maria Stea <elene.mst@gmail.com>
date Sat, 11 Jan 2014 22:55:27 +0200
parents 46a24c493efd
children 1fbbe10c8e08
files src/image.cc src/volume.cc src/volume.h
diffstat 3 files changed, 81 insertions(+), 65 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/image.cc	Sat Jan 11 22:55:27 2014 +0200
     1.3 @@ -0,0 +1,65 @@
     1.4 +#include <imago2.h>
     1.5 +
     1.6 +#include "image.h"
     1.7 +
     1.8 +Image::Image()
     1.9 +{
    1.10 +	pixels = 0;
    1.11 +	width = 0;
    1.12 +	height = 0;
    1.13 +}
    1.14 +
    1.15 +Image::~Image()
    1.16 +{
    1.17 +	delete [] pixels;
    1.18 +}
    1.19 +
    1.20 +bool Image::load(const char *fname)
    1.21 +{
    1.22 +	int new_width, new_height;
    1.23 +	float *new_pixels = (float*)img_load_pixels(fname, &new_width, &new_height, IMG_FMT_GREYF);
    1.24 +
    1.25 +	if(!new_pixels) {
    1.26 +		fprintf(stderr, "Failed to load image: %s\n", fname);
    1.27 +		return false;
    1.28 +	}
    1.29 +
    1.30 +	set_pixels(new_pixels, new_width, new_height);
    1.31 +	img_free_pixels(new_pixels);
    1.32 +	return true;
    1.33 +}
    1.34 +
    1.35 +float *Image::get_pixels()
    1.36 +{
    1.37 +	return pixels;
    1.38 +}
    1.39 +
    1.40 +const float *Image::get_pixels() const
    1.41 +{
    1.42 +	return pixels;
    1.43 +}
    1.44 +
    1.45 +void Image::set_pixels(const float *pixels, int width, int height)
    1.46 +{
    1.47 +	if(!pixels)
    1.48 +		return;
    1.49 +
    1.50 +	delete [] this->pixels;
    1.51 +
    1.52 +	this->pixels = new float[width * height];
    1.53 +	for(int i=0; i<width * height; i++) {
    1.54 +		this->pixels[i] = pixels[i];
    1.55 +	}
    1.56 +	this->width = width;
    1.57 +	this->height = height;
    1.58 +}
    1.59 +
    1.60 +int Image::get_width() const
    1.61 +{
    1.62 +	return width;
    1.63 +}
    1.64 +
    1.65 +int Image::get_height() const
    1.66 +{
    1.67 +	return height;
    1.68 +}
     2.1 --- a/src/volume.cc	Sat Jan 11 18:00:02 2014 +0200
     2.2 +++ b/src/volume.cc	Sat Jan 11 22:55:27 2014 +0200
     2.3 @@ -1,65 +1,1 @@
     2.4 -#include <imago2.h>
     2.5 -
     2.6 -#include "image.h"
     2.7 -
     2.8 -Image::Image()
     2.9 -{
    2.10 -	pixels = 0;
    2.11 -	width = 0;
    2.12 -	height = 0;
    2.13 -}
    2.14 -
    2.15 -Image::~Image()
    2.16 -{
    2.17 -	delete [] pixels;
    2.18 -}
    2.19 -
    2.20 -bool Image::load(const char *fname)
    2.21 -{
    2.22 -	int new_width, new_height;
    2.23 -	float *new_pixels = (float*)img_load_pixels(fname, &new_width, &new_height, IMG_FMT_GREYF);
    2.24 -
    2.25 -	if(!new_pixels) {
    2.26 -		fprintf(stderr, "Failed to load image: %s\n", fname);
    2.27 -		return false;
    2.28 -	}
    2.29 -
    2.30 -	set_pixels(new_pixels, new_width, new_height);
    2.31 -	img_free_pixels(new_pixels);
    2.32 -	return true;
    2.33 -}
    2.34 -
    2.35 -float *Image::get_pixels()
    2.36 -{
    2.37 -	return pixels;
    2.38 -}
    2.39 -
    2.40 -const float *Image::get_pixels() const
    2.41 -{
    2.42 -	return pixels;
    2.43 -}
    2.44 -
    2.45 -void Image::set_pixels(const float *pixels, int width, int height)
    2.46 -{
    2.47 -	if(!pixels)
    2.48 -		return;
    2.49 -
    2.50 -	delete [] this->pixels;
    2.51 -
    2.52 -	this->pixels = new float[width * height];
    2.53 -	for(int i=0; i<width * height; i++) {
    2.54 -		this->pixels[i] = pixels[i];
    2.55 -	}
    2.56 -	this->width = width;
    2.57 -	this->height = height;
    2.58 -}
    2.59 -
    2.60 -int Image::get_width() const
    2.61 -{
    2.62 -	return width;
    2.63 -}
    2.64 -
    2.65 -int Image::get_height() const
    2.66 -{
    2.67 -	return height;
    2.68 -}
    2.69 +#include "volume.h"
     3.1 --- a/src/volume.h	Sat Jan 11 18:00:02 2014 +0200
     3.2 +++ b/src/volume.h	Sat Jan 11 22:55:27 2014 +0200
     3.3 @@ -1,9 +1,24 @@
     3.4  #ifndef VOLUME_H_
     3.5  #define VOLUME_H_
     3.6  
     3.7 +#include <vector>
     3.8 +#include "image.h"
     3.9 +
    3.10  class Volume {
    3.11  private:
    3.12 +	std::vector<Image> slices;
    3.13  
    3.14 +public:
    3.15 +	Volume();
    3.16 +	~Volume();
    3.17 +
    3.18 +	bool load_volume(const char *fname);
    3.19 +	void push_slice(Image *slice);
    3.20 +
    3.21 +	Image *get_slice();
    3.22 +	const Image *get_slice() const;
    3.23 +
    3.24 +	void draw();
    3.25  };
    3.26  
    3.27  #endif // VOLUME_H_