#include #include #include #include "VectorField3D.h" #include "Mask3D.h" const float tiny = 10E-10; //Creates a VectorField with size baesd on the input arguments VectorField3D::VectorField3D(int thisNx, int thisNy, int thisNz) { assert(thisNx == 2*(thisNx/2) + 1 && thisNy == 2*(thisNy/2) + 1 && thisNz == 2*(thisNz/2) + 1); sizeX = thisNx; sizeY = thisNy; sizeZ = thisNz; centerX = sizeX/2; centerY = sizeY/2; centerZ = sizeZ/2; f = new float[sizeX * sizeY * sizeZ * 3]; assert(f); memset(f, 0, sizeX * sizeY * sizeZ * 3 * sizeof(float)); } //Creates a 1x1x1 VectorField with unit x vector VectorField3D::VectorField3D() { f = new float[3]; f[0] = 1; f[1] = 0; f[2] = 0; sizeX = sizeY = sizeZ = 1; centerX = centerY = centerZ = 0; } //Frees allocated space VectorField3D::~VectorField3D() { delete f; } //Resizes the VectorField based on the arguements and zeros out the memory void VectorField3D::reset(int thisNx, int thisNy, int thisNz) { int oldSize = sizeX * sizeY * sizeZ; assert(thisNx == 2*(thisNx/2) + 1 && thisNy == 2*(thisNy/2) + 1 && thisNz == 2*(thisNz/2) + 1); sizeX = thisNx; sizeY = thisNy; sizeZ = thisNz; centerX = sizeX/2; centerY = sizeY/2; centerZ = sizeZ/2; if (oldSize < sizeX * sizeY * sizeZ) { delete [] f; f = new float[sizeX * sizeY * sizeZ * 3]; } memset(f, 0, sizeX * sizeY * sizeZ * 3 * sizeof(float)); } //Trims the field accordingly so that we are left with the center (2n-1)^3 block //Puts the new block in the space provided by result void VectorField3D::trimField(int x, int y, int z, VectorField3D& result) { assert(x <= nx() && y <= ny() && z <= nz()); result.reset(2*x+1, 2*y+1, 2*z+1); for (int k = -x; k <= x; k++) for (int l = -y; l <= y; l++) for (int m = -z; m <= z; m++) { result.valXRef(k,l,m) = valX(k,l,m); result.valYRef(k,l,m) = valY(k,l,m); result.valZRef(k,l,m) = valZ(k,l,m); } }