Skip to content

Commit

Permalink
moves sparse volume and grayscale volume extraction functions to node…
Browse files Browse the repository at this point in the history
… service
  • Loading branch information
Stephen Plaza committed Nov 1, 2017
1 parent 3adbaf6 commit 10e7349
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 336 deletions.
26 changes: 26 additions & 0 deletions libdvid/DVIDNodeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,32 @@ class DVIDNodeService {
*/
void prefetch_specificblocks3D(std::string datatype_instance, std::vector<int>& blockcoords);

/*!
* Fetches sparse label volume as a series of block masks using labelarray interface.
* Note: The user can specify the scale level.
* \param bodyid body label id
* \param labelname name of labelarray datatype
* \param maskblocks libdvid blocks encoding 0/255 byte mask for body
* \param maxsize the maximum size body size allowed to trigger downsampling (0 = no limit)
* \param erosion shrink body size erosion (0 = no erosion)
* \param scale resolution to use to fetch body (-1 = use default 0 or determined by maxsize)
* \return scale resolution of mask
*/
int get_sparselabelmask(std::uint64_t bodyid, std::string labelname, std::vector<DVIDCompressedBlock>& maskblocks, unsigned long long maxsize=0, int scale=-1);

/*!
* Fetches sparse label volume as a series of block masks using labelarray interface.
* Note: The user must specify whether instance using jpeg encoding. Fetching jpeg data
* from a non-jpeg encoded data instance will throw an error.
* TODO: automatically extract encoding from data instance meta data.
* \param grayname name of uint8blk datatype
* \param maskblocks libdvid blocks encoding 0/1 mask for body
* \param grayblocks libdvid blocks encoding grayscale in uncompressed grayscale
* \param scale resolution to use to fetch body (returned by get_sparselabelmask)
* \param isjpeg specfies whether datatype support jpeg encoding
*/
void get_sparsegraymask(std::string dataname, const std::vector<DVIDCompressedBlock>& maskblocks, std::vector<DVIDCompressedBlock>& grayblocks, int scale, bool usejpeg=false);

private:
//! HTTP connection with DVID
DVIDConnection connection;
Expand Down
73 changes: 0 additions & 73 deletions libdvid/DVIDThreadedFetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,6 @@ namespace libdvid {

#define MINPOOLSIZE 16

/*!
* Helper function to extract data from buffer.
*/
template <typename T>
T extractval(const unsigned char*& head, int& buffer_size)
{
T val = (*(T*)(head));
head += sizeof(T);
buffer_size -= sizeof(T);

return val;
}

//
// Utility function to avoid writing triple-nested loops throughout this file.
// Simply iterate over the given z/y/x index ranges (in that order),
// and call the given function for each iteration.
//
void for_indiceszyx ( size_t Z, size_t Y, size_t X,
std::function<void(size_t z, size_t y, size_t x)> func );
/*!
* Helper function to write a subvolume into a larger block.
*/
template <typename T>
void write_subblock(T* block, T* subblock_flat, int gz, int gy, int gx, const unsigned int BLOCK_WIDTH, const unsigned int SBW)
{
size_t subblock_index = 0;
for_indiceszyx(SBW, SBW, SBW, [&](size_t z, size_t y, size_t x) {
int z_slice = gz * SBW + z;
int y_row = gy * SBW + y;
int x_col = gx * SBW + x;

int z_offset = z_slice * BLOCK_WIDTH * BLOCK_WIDTH;
int y_offset = y_row * BLOCK_WIDTH;
int x_offset = x_col;

block[z_offset + y_offset + x_offset] = subblock_flat[subblock_index];
subblock_index += 1;
});
}





/*!
* Thread pool singleton for threading resources.
*/
Expand Down Expand Up @@ -182,41 +137,13 @@ std::vector<BinaryDataPtr> get_tile_array_binary(DVIDNodeService& service,
std::string datatype_instance, Slice2D orientation, unsigned int scaling,
const std::vector<std::vector<int> >& tile_locs_array, int num_threads=0);

/*!
* Fetches sparse label volume as a series of block masks using labelarray interface.
* Note: The user can specify the scale level.
* \param service name of dvid node service
* \param bodyid body label id
* \param labelname name of labelarray datatype
* \param maskblocks libdvid blocks encoding 0/255 byte mask for body
* \param maxsize the maximum size body size allowed to trigger downsampling (0 = no limit)
* \param erosion shrink body size erosion (0 = no erosion)
* \param scale resolution to use to fetch body (-1 = use default 0 or determined by maxsize)
* \return scale resolution of mask
*/
int get_sparselabelmask(DVIDNodeService& service, std::uint64_t bodyid, std::string labelname, std::vector<DVIDCompressedBlock>& maskblocks, unsigned long long maxsize=0, int scale=-1);

/*!
* Erodes the foreground (non-zero) label encoded in list of blocks.
* Note: currently unimplemented.
* \param erosion shrink body size erosion (0 = no erosion).
*/
void erode_sparselabelmask(std::vector<DVIDCompressedBlock>& maskblocks, unsigned int erosion);

/*!
* Fetches sparse label volume as a series of block masks using labelarray interface.
* Note: The user must specify whether instance using jpeg encoding. Fetching jpeg data
* from a non-jpeg encoded data instance will throw an error.
* TODO: automatically extract encoding from data instance meta data.
* \param service name of dvid node service
* \param grayname name of uint8blk datatype
* \param maskblocks libdvid blocks encoding 0/1 mask for body
* \param grayblocks libdvid blocks encoding grayscale in uncompressed grayscale
* \param scale resolution to use to fetch body (returned by get_sparselabelmask)
* \param isjpeg specfies whether datatype support jpeg encoding
*/
void get_sparsegraymask(DVIDNodeService& service, std::string dataname, const std::vector<DVIDCompressedBlock>& maskblocks, std::vector<DVIDCompressedBlock>& grayblocks, int scale, bool usejpeg=false);

}


Expand Down
4 changes: 2 additions & 2 deletions load_tests/extract_sparse_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int main(int argc, char** argv)
cout << "fetch labels" << endl;
{
ScopeTime overall_time;
scale = libdvid::get_sparselabelmask(dvid_node, atoi(argv[7]), argv[3], maskblocks, 0, atoi(argv[8]));
scale = dvid_node.get_sparselabelmask(atoi(argv[7]), argv[3], maskblocks, 0, atoi(argv[8]));
}
cout << "num blocks: " << maskblocks.size() << endl;

Expand All @@ -118,7 +118,7 @@ int main(int argc, char** argv)
// extract grayscale
{
ScopeTime overall_time;
libdvid::get_sparsegraymask(dvid_node2, argv[6], maskblocks, grayblocks, scale, false);
dvid_node2.get_sparsegraymask(argv[6], maskblocks, grayblocks, scale, false);
}

// debug count
Expand Down
Loading

0 comments on commit 10e7349

Please sign in to comment.