#include #include #include "Mask3D.h" #include //Creates a 1x1x1 mask Mask3D::Mask3D() { c = new float[1]; c[0] = 1; sizeX = sizeY = sizeZ = 1; centerX = centerY = centerZ = 0; } //Reads a mask file and creates a Mask3D object based on the input data Mask3D::Mask3D(const char* file) { ifstream in(file); assert(in); in >> sizeX >> sizeY >> sizeZ; assert( sizeX==2*(sizeX/2)+1 && sizeY==2*(sizeY/2)+1 && sizeZ==2*(sizeZ/2)+1); c = new float[sizeX*sizeY*sizeZ]; centerX = sizeX/2; centerY = sizeY/2; centerZ = sizeZ/2; for (int i=0; i> val; c[index(i,j,k)] = val; } assert(in); } //Destructor to delete the allocated space Mask3D::~Mask3D() { delete [] c; } //Frees the previously allocated space for the mask, then recreates the mask based on //the data in the argument input file void Mask3D::recreate(const char* file) { delete [] c; ifstream in(file); assert(in); in >> sizeX >> sizeY >> sizeZ; assert( sizeX==2*(sizeX/2)+1 && sizeY==2*(sizeY/2)+1 && sizeZ==2*(sizeZ/2)+1); c = new float[sizeX*sizeY*sizeZ]; centerX = sizeX/2; centerY = sizeY/2; centerZ = sizeZ/2; for (int i=0; i> val; c[index(i,j,k)] = val; } assert(in); } //Given input i, j, k from the coordinate (i,j,k) in three-space, index() returns the //integer valued index of that coordinate in the one-dimensional array int Mask3D::index(int i, int j, int k) const { assert( 0 <= i && i <= 2*sizeX && 0 <= j && j <= 2*sizeY && 0 <= k && k <= 2*sizeZ); return k + sizeZ * (j + sizeY * i); } //Returns the value at the coordinate point (i,j,k) float Mask3D::val(int i, int j, int k) const { assert( -centerX <= i && i <= centerX && -centerY <= j && j <= centerY && -centerZ <= k && k <= centerZ); return c[index(i+centerX, j+centerY, k+centerZ)]; } //centerX is defined as sizeX/2, likewise for Y and Z int Mask3D::mx() const { return centerX; } int Mask3D::my() const { return centerY; } int Mask3D::mz() const { return centerZ; }