volmetrics

changeset 4:1fbbe10c8e08

quick backup
author Eleni Maria Stea <elene.mst@gmail.com>
date Sat, 11 Jan 2014 23:49:58 +0200
parents 927c29b93009
children 92c163c939be
files Makefile src/image.cc src/image.h src/volume.cc src/volume.h
diffstat 5 files changed, 84 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Sat Jan 11 22:55:27 2014 +0200
     1.2 +++ b/Makefile	Sat Jan 11 23:49:58 2014 +0200
     1.3 @@ -8,7 +8,7 @@
     1.4  inc = -Isrc -I/usr/local/include -I/usr/local/lib
     1.5  
     1.6  CXX = g++
     1.7 -CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc)
     1.8 +CXXFLAGS = -std=c++11 -pedantic -Wall $(dbg) $(opt) $(inc)
     1.9  LDFLAGS = -lGL -lGLU -lGLEW -lglut -limago -lm
    1.10  
    1.11  $(bin): $(obj)
     2.1 --- a/src/image.cc	Sat Jan 11 22:55:27 2014 +0200
     2.2 +++ b/src/image.cc	Sat Jan 11 23:49:58 2014 +0200
     2.3 @@ -14,6 +14,48 @@
     2.4  	delete [] pixels;
     2.5  }
     2.6  
     2.7 +//copy constructor - assignment operator
     2.8 +Image::Image(const Image &img)
     2.9 +{
    2.10 +	pixels = 0;
    2.11 +	set_pixels(img.pixels, img.width, img.height);
    2.12 +}
    2.13 +
    2.14 +Image &Image::operator = (const Image &img)
    2.15 +{
    2.16 +	if(&img != this) {
    2.17 +		set_pixels(img.pixels, img.width, img.height);
    2.18 +	}
    2.19 +	return *this;
    2.20 +}
    2.21 +
    2.22 +//move constructor - move operator c++11 R-value reference to image
    2.23 +Image::Image(Image &&img)
    2.24 +{
    2.25 +	pixels = img.pixels;
    2.26 +	width = img.width;
    2.27 +	height = img.height;
    2.28 +
    2.29 +	img.pixels = 0;
    2.30 +	img.width = 0;
    2.31 +	img.height = 0;
    2.32 +}
    2.33 +
    2.34 +Image &Image::operator = (Image &&img)
    2.35 +{
    2.36 +	if(&img != this) {
    2.37 +		pixels = img.pixels;
    2.38 +		width = img.width;
    2.39 +		height = img.height;
    2.40 +
    2.41 +		img.pixels = 0;
    2.42 +		img.width = 0;
    2.43 +		img.height = 0;
    2.44 +	}
    2.45 +
    2.46 +	return *this;
    2.47 +}
    2.48 +
    2.49  bool Image::load(const char *fname)
    2.50  {
    2.51  	int new_width, new_height;
     3.1 --- a/src/image.h	Sat Jan 11 22:55:27 2014 +0200
     3.2 +++ b/src/image.h	Sat Jan 11 23:49:58 2014 +0200
     3.3 @@ -6,10 +6,19 @@
     3.4  	float *pixels;
     3.5  	int width;
     3.6  	int height;
     3.7 +
     3.8  public:
     3.9  	Image();
    3.10  	~Image();
    3.11  
    3.12 +	//copy constructor - assignment operator
    3.13 +	Image(const Image &img);
    3.14 +	Image &operator = (const Image &img);
    3.15 +
    3.16 +	//move constructor - move operator c++11 R-value reference to image
    3.17 +	Image(Image &&img);
    3.18 +	Image &operator = (Image &&img);
    3.19 +
    3.20  	bool load(const char *fname);
    3.21  
    3.22  	float *get_pixels();
     4.1 --- a/src/volume.cc	Sat Jan 11 22:55:27 2014 +0200
     4.2 +++ b/src/volume.cc	Sat Jan 11 23:49:58 2014 +0200
     4.3 @@ -1,1 +1,30 @@
     4.4 +#include <stdio.h>
     4.5 +
     4.6  #include "volume.h"
     4.7 +
     4.8 +Volume::Volume()
     4.9 +{
    4.10 +	width = height = 0;
    4.11 +}
    4.12 +
    4.13 +bool Volume::load_volume(const char *fname)
    4.14 +{
    4.15 +	return true;
    4.16 +}
    4.17 +
    4.18 +bool Volume::push_slice(Image &&slice)
    4.19 +{
    4.20 +	if(slices.empty()) {
    4.21 +		width = slice.get_width();
    4.22 +		height = slice.get_height();
    4.23 +	}
    4.24 +	else {
    4.25 +		if(width != slice.get_width() || height != slice.get_height()) {
    4.26 +			fprintf(stderr, "failed to load slice no: %d\n", (int)slices.size() + 1);
    4.27 +			return false;
    4.28 +		}
    4.29 +	}
    4.30 +
    4.31 +	slices.push_back(slice);
    4.32 +	return true;
    4.33 +}
     5.1 --- a/src/volume.h	Sat Jan 11 22:55:27 2014 +0200
     5.2 +++ b/src/volume.h	Sat Jan 11 23:49:58 2014 +0200
     5.3 @@ -7,16 +7,14 @@
     5.4  class Volume {
     5.5  private:
     5.6  	std::vector<Image> slices;
     5.7 +	int width;
     5.8 +	int height;
     5.9  
    5.10  public:
    5.11  	Volume();
    5.12 -	~Volume();
    5.13  
    5.14  	bool load_volume(const char *fname);
    5.15 -	void push_slice(Image *slice);
    5.16 -
    5.17 -	Image *get_slice();
    5.18 -	const Image *get_slice() const;
    5.19 +	bool push_slice(Image &&slice);
    5.20  
    5.21  	void draw();
    5.22  };