//------------------------------------------------------------------------------------ // DSt_cube<T>::clear // Description - sets all of cubes locations to '0', faster than setall() // WARNING - has not been tested with all data types //------------------------------------------------------------------------------------ template <class T> void DSt_cube<T>::clear() { // If file cache is used, we will use entire RAM cache set to 0 and write it out to file unsigned int write_len = sizeof(T) * (( cache_state == CACHE_DISABLED ) ? (slices_per_block*wX*wY) : (memory_total_used)); for (unsigned short i = 0; i < memory_num_of_blocks; i++) { if (i == (memory_num_of_blocks-1) ) { // Last block might have different number of slices if ( cache_state == CACHE_DISABLED ) { write_len = sizeof(T)*slices_per_block_last*wX*wY; } memset( memory_block_ptrs[i], 0, write_len ); } else { memset( memory_block_ptrs[i], 0, write_len ); } } // Sync with cache if used writeBufferToEntireCacheFile(memory_block_ptrs[0], write_len); }; //------------------------------------------------------------------------------------ // DSt_cube<T>::setall // Description - sets all of cubes locations to 'val' //------------------------------------------------------------------------------------ template <class T> void DSt_cube<T>::setall(T val) { unsigned int write_len = sizeof(T) * (( cache_state == CACHE_DISABLED ) ? (slices_per_block*wX*wY) : (memory_total_used)); if (sizeof(T) == 1) { for (unsigned short i = 0; i < memory_num_of_blocks; i++) { if (i == (memory_num_of_blocks-1) ) { // Last block might have different number of slices if ( cache_state == CACHE_DISABLED ) { write_len = sizeof(T)*slices_per_block_last*wX*wY; } memset( memory_block_ptrs[i], val, write_len ); } else { memset( memory_block_ptrs[i], val, write_len ); } } } // If cube type is not a byte size, we need to set each spot individually else { for (unsigned short i = 0; i < memory_num_of_blocks; i++) { // Last block might have different number of slices for (unsigned short j = 0; j < ( (i==(memory_num_of_blocks-1)) ? (slices_per_block_last*dim_y*dim_x) : (slices_per_block*dim_y*dim_x)); j++) { memory_block_ptrs[i][j] = val; } } } // Sync with cache if used writeBufferToEntireCacheFile(memory_block_ptrs[0], write_len); }; //------------------------------------------------------------------------------------ // DSt_cube<T>::floodWithNewValue // Description - starting from specified location, will find all attached // voxels with same value, and change them all to 'new_val' // WARNING - currently can cause a stack overflow if area to flood is to large //------------------------------------------------------------------------------------ template <class T> void DSt_cube<T>::floodWithNewValue(unsigned short z, unsigned short y, unsigned short x, T &new_val) { char dz, dy, dx, xl=-1, xg=1, yl=-1, yg=1, zl=-1, zg=1; //grab current code unsigned short spot_val = this->datac(z, y, x); //mark current spot with new Val this->datac(z, y, x, new_val); //bound check if (x < 1) xl = 0; if (y < 1) yl = 0; if (z < 1) zl = 0; if (x > wX-2) xg = 0; if (y > wY-2) yg = 0; if (z > wZ-2) zg = 0; //flood ID to neighs for (dz = zl; dz <= zg; dz++) for (dy = yl; dy <= yg; dy++) for (dx = xl; dx <= xg; dx++) { if ( this->datac(z+dz, y+dy, x+dx) == spot_val ) flood_with_new_val(z+dz, y+dy, x+dx, new_val); } };