# HG changeset patch # User Eleni Maria Stea # Date 1389473727 -7200 # Node ID 927c29b9300959044d9659540c4d1320cbe68818 # Parent 46a24c493efdb645a1a4a14805adec9e6454c9cd added image.cc diff -r 46a24c493efd -r 927c29b93009 src/image.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/image.cc Sat Jan 11 22:55:27 2014 +0200 @@ -0,0 +1,65 @@ +#include + +#include "image.h" + +Image::Image() +{ + pixels = 0; + width = 0; + height = 0; +} + +Image::~Image() +{ + delete [] pixels; +} + +bool Image::load(const char *fname) +{ + int new_width, new_height; + float *new_pixels = (float*)img_load_pixels(fname, &new_width, &new_height, IMG_FMT_GREYF); + + if(!new_pixels) { + fprintf(stderr, "Failed to load image: %s\n", fname); + return false; + } + + set_pixels(new_pixels, new_width, new_height); + img_free_pixels(new_pixels); + return true; +} + +float *Image::get_pixels() +{ + return pixels; +} + +const float *Image::get_pixels() const +{ + return pixels; +} + +void Image::set_pixels(const float *pixels, int width, int height) +{ + if(!pixels) + return; + + delete [] this->pixels; + + this->pixels = new float[width * height]; + for(int i=0; ipixels[i] = pixels[i]; + } + this->width = width; + this->height = height; +} + +int Image::get_width() const +{ + return width; +} + +int Image::get_height() const +{ + return height; +} diff -r 46a24c493efd -r 927c29b93009 src/volume.cc --- a/src/volume.cc Sat Jan 11 18:00:02 2014 +0200 +++ b/src/volume.cc Sat Jan 11 22:55:27 2014 +0200 @@ -1,65 +1,1 @@ -#include - -#include "image.h" - -Image::Image() -{ - pixels = 0; - width = 0; - height = 0; -} - -Image::~Image() -{ - delete [] pixels; -} - -bool Image::load(const char *fname) -{ - int new_width, new_height; - float *new_pixels = (float*)img_load_pixels(fname, &new_width, &new_height, IMG_FMT_GREYF); - - if(!new_pixels) { - fprintf(stderr, "Failed to load image: %s\n", fname); - return false; - } - - set_pixels(new_pixels, new_width, new_height); - img_free_pixels(new_pixels); - return true; -} - -float *Image::get_pixels() -{ - return pixels; -} - -const float *Image::get_pixels() const -{ - return pixels; -} - -void Image::set_pixels(const float *pixels, int width, int height) -{ - if(!pixels) - return; - - delete [] this->pixels; - - this->pixels = new float[width * height]; - for(int i=0; ipixels[i] = pixels[i]; - } - this->width = width; - this->height = height; -} - -int Image::get_width() const -{ - return width; -} - -int Image::get_height() const -{ - return height; -} +#include "volume.h" diff -r 46a24c493efd -r 927c29b93009 src/volume.h --- a/src/volume.h Sat Jan 11 18:00:02 2014 +0200 +++ b/src/volume.h Sat Jan 11 22:55:27 2014 +0200 @@ -1,9 +1,24 @@ #ifndef VOLUME_H_ #define VOLUME_H_ +#include +#include "image.h" + class Volume { private: + std::vector slices; +public: + Volume(); + ~Volume(); + + bool load_volume(const char *fname); + void push_slice(Image *slice); + + Image *get_slice(); + const Image *get_slice() const; + + void draw(); }; #endif // VOLUME_H_