/** * Write a ccns_slice object to a repository. * @param h is the ccn_handle on which to write. * @param slice is a pointer to a ccns_slice object to be written. * @param name, if non-NULL, is a pointer to a charbuf which will be filled * in with the name of the slice that was written. * @returns 0 on success, -1 otherwise. */ int ccns_write_slice(struct ccn *h, struct ccns_slice *slice, struct ccn_charbuf *name) { struct ccn_charbuf *n = NULL; int res; // calculate versioned and segmented name for the slice n = ccn_charbuf_create(); if (n == NULL) return(-1); res = ccns_slice_name(n, slice); if (res < 0) goto Cleanup; res |= ccn_create_version(h, n, CCN_V_NOW, 0, 0); if (name != NULL) { ccn_charbuf_reset(name); res |= ccn_charbuf_append_charbuf(name, n); } res |= ccn_name_append_numeric(n, CCN_MARKER_SEQNUM, 0); if (res < 0) goto Cleanup; res = write_slice(h, slice, n); Cleanup: ccn_charbuf_destroy(&n); return (res); }
/** * Delete a ccns_slice object from a repository. * @param h is the ccn_handle on which to write. * @param name is a pointer to a charbuf naming the slice to be deleted. * @returns 0 on success, -1 otherwise. */ int ccns_delete_slice(struct ccn *h, struct ccn_charbuf *name) { struct ccn_charbuf *n = NULL; int res = 0; // calculate versioned and segmented name for the slice n = ccn_charbuf_create_n(32 + name->length); if (n == NULL) return(-1); res |= ccn_charbuf_append_charbuf(n, name); res |= ccn_create_version(h, n, CCN_V_NOW | CCN_V_REPLACE, 0, 0); res |= ccn_name_append_numeric(n, CCN_MARKER_SEQNUM, 0); if (res >= 0) res = write_slice(h, NULL, n); ccn_charbuf_destroy(&n); return (res); }
int main(int argc, char** argv) { if (argc < 8) { std::cout << "usage: watershed <aff_x_dir> <aff_y_dir> <aff_z_dir> <t_l> <t_h> <t_s> <ms>" << std::endl; return 1; } std::string aff_x_dir = argv[1]; std::string aff_y_dir = argv[2]; std::string aff_z_dir = argv[3]; float t_l = boost::lexical_cast<float>(argv[4]); float t_h = boost::lexical_cast<float>(argv[5]); float t_s = boost::lexical_cast<float>(argv[6]); int ms = boost::lexical_cast<float>(argv[7]); std::cout << "Performing affinity graph watershed on volumes " << aff_x_dir << ", " << aff_y_dir << ", " << aff_z_dir << std::endl; boost::filesystem::path aff_x_path(aff_x_dir); boost::filesystem::path aff_y_path(aff_y_dir); boost::filesystem::path aff_z_path(aff_z_dir); int size_z = num_files(aff_x_path); if (size_z != num_files(aff_y_dir) || size_z != num_files(aff_z_dir)) { std::cerr << "directories contain different number of files" << std::endl; return 1; } if (size_z == 0) { std::cerr << "directories contain no files" << std::endl; return 1; } std::vector<boost::filesystem::path> aff_x_files = files(aff_x_path); std::vector<boost::filesystem::path> aff_y_files = files(aff_y_path); std::vector<boost::filesystem::path> aff_z_files = files(aff_z_path); aff_x_files.resize(1); // one section only aff_y_files.resize(1); // one section only aff_z_files.resize(1); // one section only size_z = 1; std::sort(aff_x_files.begin(), aff_x_files.end()); std::sort(aff_y_files.begin(), aff_y_files.end()); std::sort(aff_z_files.begin(), aff_z_files.end()); vigra::ImageImportInfo info(aff_x_files[0].native().c_str()); int size_x = info.width(); int size_y = info.height(); std::cout << "reading affinity graph of size " << size_x << "x" << size_y << "x" << size_z << std::endl; affinity_graph_ptr<float> aff( new affinity_graph<float>( boost::extents[size_x][size_y][size_z][3], boost::fortran_storage_order())); for (int z = 0; z < size_z; z++) { auto slice = (*aff)[ boost::indices[range()][range()][z][range()] ]; read_slice(slice, aff_x_files[z], aff_y_files[z], aff_z_files[z]); } std::cout << "performing simple_watershed" << std::endl; std::vector<std::size_t> counts; auto result = simple_watershed<uint32_t>(aff, t_l, t_h, counts); auto segmentation = result.first; int num_segments = result.second; std::cout << "found " << num_segments << " segments" << std::endl; auto rg = get_region_graph<uint32_t,float>(aff, segmentation, num_segments); std::cout << "performing region merging" << std::endl; // I guess the last parameter is to discard regions smaller than that //merge_segments_with_function(result.first, rg, counts, //dynamic_size_threshold(t_s, ms), 0); for (int z = 0; z < size_z; z++) { auto slice = (*segmentation)[ boost::indices[range()][range()][z] ]; std::stringstream filename; filename << "watershed_" << std::setw(5) << std::setfill('0') << z << "_" << t_l << "_" << t_h << "_" << t_s << "_" << ms << ".tif"; write_slice(slice, filename.str()); } }