void Slices::addAll(const Slices& slices) { _slices.insert(_slices.end(), slices.begin(), slices.end()); _kdTreeDirty = true; }
void FreeSpace::printFreeSpace() { HashTable::EntryVect entries; beginToSize.getAllEntries(entries); int totalFree = 0, nSlices = 0; Slices slices; for (HashTable::Entry *itp = entries.begin(), *endp = entries.end(); itp != endp; ++itp) { slices.push_back(Slice(itp->key, itp->value)); } slices.sort(); fprintf(stderr, "free space: "); for (Slice *it = slices.begin(), *end = slices.end(); it != end; ++it) { fprintf(stderr, "<%i, %i, %i>; ", (int)it->pos, it->len, (int)(it->pos + it->len)); totalFree += (int)it->len; ++nSlices; } fprintf(stderr, "total: %i; slices %i\n", totalFree, nSlices); }
ulong binStructure(const AtomicGroup& structure, Slices& slices) { ulong oob = 0; for (AtomicGroup::const_iterator a = structure.begin(); a != structure.end(); ++a) { double z = (*a)->coords().z(); int bin = (z - zmin) * delta; if (bin < 0 || bin >= slices.size()) ++oob; else { pAtom b(*a); b->coords().z(0.0); slices[bin].append(b); } } return(oob); }
Slices PartCorresponder::computeSlices( ParticleMesh * input, const SegmentGraph & seg ) { static int MAX_SLICE_COUNT = 20; Slices curSlices; if(seg.vertices.empty()) return curSlices; // Compute range of 'z' grid values Bounds<int> zcoords; for(auto v : seg.vertices) { Vector3 pg = (input->particles[v].pos - input->grid.translation.cast<double>()) / input->grid.unitlength; zcoords.extend( (int)pg.z() ); } int total_range = 1 + zcoords.range(); int fixedNumLayers = std::min(total_range, MAX_SLICE_COUNT); int perLayer = std::floor((double)total_range / fixedNumLayers); int numLayers = std::ceil((double)total_range / perLayer); curSlices.resize( numLayers ); // Divide segment into layers for(int i = 0; i < numLayers; i++) { int bottom = zcoords.minimum + (i * perLayer); int top = bottom + perLayer; SegmentGraph layerGraph; for(auto & edge : seg.GetEdgesSet()) { Vector3 pgi = (input->particles[edge.index].pos - input->grid.translation.cast<double>()) / input->grid.unitlength; Vector3 pgj = (input->particles[edge.target].pos - input->grid.translation.cast<double>()) / input->grid.unitlength; int zi = (int)pgi.z(), zj = (int)pgj.z(); if((zi < bottom || zj < bottom) || (zi >= top || zj >= top)) continue; if(zi >= bottom && zi < top) layerGraph.AddVertex(edge.index); if(zj >= bottom && zj < top) layerGraph.AddVertex(edge.target); layerGraph.AddEdge( edge.index, edge.target, 1 ); } if( layerGraph.vertices.empty() ) continue; auto & slice = curSlices[i]; slice.chunksFromGraphs( layerGraph.toConnectedParts() ); // Compute chunks parameters for(size_t c = 0; c < slice.chunks.size(); c++) { auto & chunk = slice.chunks[c]; // Compute bounding box enclosing chunk for(auto p : input->particlesCorners(chunk.g.vertices)) chunk.box.extend(p); // Compute index of relative particle positions inside box chunk.tree = QSharedPointer<NanoKdTree>(new NanoKdTree); for(auto v : chunk.g.vertices) { input->particles[v].relativePos = (input->particles[v].pos - chunk.box.min()).array() / chunk.box.sizes().array(); chunk.tree->addPoint( input->particles[v].relativePos ); chunk.vmap.push_back( v ); } chunk.tree->build(); } } Slices goodSlices; for(auto slice : curSlices) if(!slice.chunks.empty()) goodSlices.push_back(slice); return goodSlices; }
int main(int argc, char** argv) { try { // init command line parser util::ProgramOptions::init(argc, argv); int stack_id = optionStackId.as<int>(); std::string comp_dir = optionComponentDir.as<std::string>(); std::string pg_host = optionPGHost.as<std::string>(); std::string pg_user = optionPGUser.as<std::string>(); std::string pg_pass = optionPGPassword.as<std::string>(); std::string pg_dbase = optionPGDatabase.as<std::string>(); std::cout << "Testing PostgreSQL stores with stack ID " << stack_id << std::endl; // init logger logger::LogManager::init(); logger::LogManager::setGlobalLogLevel(logger::Debug); // create new project configuration ProjectConfiguration pc; pc.setBackendType(ProjectConfiguration::PostgreSql); StackDescription stack; stack.id = stack_id; pc.setCatmaidStack(Raw, stack); pc.setComponentDirectory(comp_dir); pc.setPostgreSqlHost(pg_host); pc.setPostgreSqlUser(pg_user); pc.setPostgreSqlPassword(pg_pass); pc.setPostgreSqlDatabase(pg_dbase); PostgreSqlSliceStore sliceStore(pc, Membrane); // Add first set of slices boost::shared_ptr<Slice> slice1 = createSlice(10, 0); boost::shared_ptr<Slice> slice2 = createSlice(10, 1); boost::shared_ptr<Slice> slice3 = createSlice(10, 2); Slices slices = Slices(); slices.add(slice1); slices.add(slice2); slices.add(slice3); Block block(0, 0, 0); sliceStore.associateSlicesToBlock(slices, block); Blocks blocks; blocks.add(block); Blocks missingBlocks; boost::shared_ptr<Slices> retrievedSlices = sliceStore.getSlicesByBlocks(blocks, missingBlocks); // Create conflict set where each slice ConflictSet conflictSet1; conflictSet1.addSlice(slice1->hashValue()); conflictSet1.addSlice(slice2->hashValue()); conflictSet1.addSlice(slice3->hashValue()); ConflictSets conflictSets; conflictSets.add(conflictSet1); sliceStore.associateConflictSetsToBlock(conflictSets, block); boost::shared_ptr<ConflictSets> retrievedConflictSets = sliceStore.getConflictSetsByBlocks(blocks, missingBlocks); for (const ConflictSet& cs : *retrievedConflictSets) { std::cout << "ConflictSet hash: " << hash_value(cs); for (const SliceHash& sh : cs.getSlices()) { std::cout << " Slice hash: " << sh; } std::cout << std::endl; } PostgreSqlSegmentStore segmentStore(pc, Membrane); util::box<unsigned int, 2> segmentBounds(0, 0, 0, 0); std::vector<double> segmentFeatures; segmentFeatures.push_back(0.0); segmentFeatures.push_back(1.0); segmentFeatures.push_back(2.0); SegmentDescription segment(0, segmentBounds); segment.addLeftSlice(slice1->hashValue()); segment.addRightSlice(slice2->hashValue()); segment.setFeatures(segmentFeatures); boost::shared_ptr<SegmentDescriptions> segments = boost::make_shared<SegmentDescriptions>(); segments->add(segment); segmentStore.associateSegmentsToBlock(*segments, block); boost::shared_ptr<SegmentDescriptions> retrievedSegments = segmentStore.getSegmentsByBlocks(blocks, missingBlocks, false); } catch (boost::exception& e) { handleException(e, std::cerr); } }