/* void ZStackDocReader::addLocsegChain(ZLocsegChain *chain) { if (chain != NULL) { m_chainList.append(chain); } } */ void ZStackDocReader::loadStack(const QString &filePath) { ZFileType::EFileType type = ZFileType::fileType(filePath.toStdString()); if (type == ZFileType::OBJECT_SCAN_FILE || type == ZFileType::DVID_OBJECT_FILE) { ZSparseObject *sobj = new ZSparseObject; if (type == ZFileType::DVID_OBJECT_FILE) { sobj->importDvidObject(filePath.toStdString()); } else { sobj->load(filePath.toStdString().c_str()); } if (!sobj->isEmpty()) { addObject(sobj); sobj->setColor(255, 255, 255, 255); //addSparseObject(sobj); // sobj->setColor(128, 0, 0, 255); ZIntCuboid cuboid = sobj->getBoundBox(); m_stack = ZStackFactory::makeVirtualStack( cuboid.getWidth(), cuboid.getHeight(), cuboid.getDepth()); m_stack->setOffset(cuboid.getFirstCorner()); } } else { m_stackSource.import(filePath.toStdString()); m_stack = m_stackSource.readStack(); } }
ZIntCuboid ZDvidInfo::getBlockBox(int x0, int x1, int y, int z) const { ZIntCuboid cuboid = getBlockBox(x0, y, z); cuboid.setWidth(cuboid.getWidth() * (x1 - x0 + 1)); return cuboid; }
std::string ZDvidUrl::getTodoListUrl(const ZIntCuboid &cuboid) const { return getTodoListUrl(cuboid.getFirstCorner().getX(), cuboid.getFirstCorner().getY(), cuboid.getFirstCorner().getZ(), cuboid.getWidth(), cuboid.getHeight(), cuboid.getDepth()); }
std::string ZDvidUrl::getAnnotationUrl( const std::string &dataName, const ZIntCuboid &box) const { return getAnnotationUrl( dataName, box.getFirstCorner().getX(), box.getFirstCorner().getY(), box.getFirstCorner().getZ(), box.getWidth(), box.getHeight(), box.getDepth()); }
std::string ZDvidUrl::getSynapseUrl(const ZIntCuboid &box) const { return getSynapseUrl(box.getFirstCorner(), box.getWidth(), box.getHeight(), box.getDepth()); }
Swc_Tree* ZNeuronTracer::trace(double x1, double y1, double z1, double r1, double x2, double y2, double z2, double r2) { setTraceScoreThreshold(TRACING_INTERACTIVE); ZIntPoint stackOffset = getStack()->getOffset(); ZPoint targetPos(x2, y2, z2); x1 = iround(x1); y1 = iround(y1); z1 = iround(z1); x2 = iround(x2); y2 = iround(y2); z2 = iround(z2); x1 -= stackOffset.getX(); y1 -= stackOffset.getY(); z1 -= stackOffset.getZ(); x2 -= stackOffset.getX(); y2 -= stackOffset.getY(); z2 -= stackOffset.getZ(); if (x1 < 0 || y1 < 0 || z1 < 0 || x1 >= getStack()->width() || y1 >= getStack()->height() || z1 >= getStack()->depth()) { return NULL; } ZStackGraph stackGraph; if (m_resolution[2] / m_resolution[0] > 3.0) { stackGraph.setZMargin(2); } stackGraph.updateRange( x1, y1, z1, x2, y2, z2, getStack()->width(), getStack()->height(), getStack()->depth()); if (stackGraph.getRoiVolume() > MAX_P2P_TRACE_VOLUME) { return NULL; } stackGraph.setResolution(m_resolution); if (m_vertexOption == ZStackGraph::VO_SURFACE) { stackGraph.setWeightFunction(Stack_Voxel_Weight_I); } else { if (m_usingEdgePath) { stackGraph.setWeightFunction(Stack_Voxel_Weight_S); } else { if (m_backgroundType == NeuTube::IMAGE_BACKGROUND_BRIGHT) { stackGraph.setWeightFunction(Stack_Voxel_Weight_Sr); } else { stackGraph.setWeightFunction(Stack_Voxel_Weight_S); } } } ZIntCuboid box = stackGraph.getRange(); // if (m_usingEdgePath) { // box.setFirstCorner(imin2(x1, x2), imin2(y1, y2), imin2(z1, z2)); // box.setLastCorner(imax2(x1, x2), imax2(y1, y2), imax2(z1, z2)); // } Stack *partial = C_Stack::crop( getIntensityData(), box.getFirstCorner().getX(), box.getFirstCorner().getY(), box.getFirstCorner().getZ(), box.getWidth(), box.getHeight(), box.getDepth(), NULL); /* if (m_bcAdjust) { Stack_Scale(partial, 0, m_greyFactor, m_greyOffset); } */ if (m_usingEdgePath) { Stack *partialEdge = C_Stack::computeGradient(partial); C_Stack::kill(partial); partial = partialEdge; #ifdef _DEBUG_2 C_Stack::write(GET_TEST_DATA_DIR + "/test.tif", partial); #endif } stackGraph.inferWeightParameter(partial); ZVoxelArray voxelArray; std::vector<int> path; if (m_usingEdgePath) { int x0 = box.getFirstCorner().getX(); int y0 = box.getFirstCorner().getY(); int z0 = box.getFirstCorner().getZ(); int startIndex = C_Stack::indexFromCoord( x1 - x0, y1 - y0 , z1 - z0, C_Stack::width(partial), C_Stack::height(partial), C_Stack::depth(partial)); int endIndex = C_Stack::indexFromCoord( x2 - x0, y2 - y0, z2 - z0, C_Stack::width(partial), C_Stack::height(partial), C_Stack::depth(partial)); stackGraph.setRange(0, 0, 0, C_Stack::width(partial) - 1, C_Stack::height(partial) - 1, C_Stack::depth(partial) - 1); path = stackGraph.computeShortestPath( partial, startIndex, endIndex, m_vertexOption); for (size_t i = path.size(); i > 0; --i) { int x, y, z; C_Stack::indexToCoord(path[i - 1], C_Stack::width(partial), C_Stack::height(partial), &x, &y, &z); voxelArray.append(ZVoxel(x + x0, y + y0, z + z0)); } } else { int width = getStack()->width(); int height = getStack()->height(); int depth = getStack()->depth(); int startIndex = C_Stack::indexFromCoord( x1, y1, z1, width, height, depth); int endIndex = C_Stack::indexFromCoord( x2, y2, z2, width, height, depth); path = stackGraph.computeShortestPath( getIntensityData(), startIndex, endIndex, m_vertexOption); // C_Stack::kill(stackField); for (size_t i = path.size(); i > 0; --i) { int x, y, z; C_Stack::indexToCoord(path[i - 1], width, height, &x, &y, &z); voxelArray.append(ZVoxel(x, y, z)); } } C_Stack::kill(partial); double length = voxelArray.getCurveLength(); double dist = 0.0; const std::vector<ZVoxel> &voxelData = voxelArray.getInternalData(); for (size_t i = 0; i < path.size(); ++i) { double ratio = dist / length; double r = r1 * ratio + r2 * (1 - ratio); voxelArray.setValue(i, r); if (i < path.size() - 1) { dist += voxelData[i].distanceTo(voxelData[i+1]); } } Swc_Tree *tree = voxelArray.toSwcTree(); if (tree != NULL) { Swc_Tree_Translate( tree, stackOffset.getX(), stackOffset.getY(), stackOffset.getZ()); ZSwcSignalFitter fitter; fitter.setBackground(m_backgroundType); fitter.setFixingTerminal(true); fitter.fitSignal(tree, getStack(), getSignalChannel()); Swc_Tree_Node *leaf = tree->root; while (SwcTreeNode::firstChild(leaf) != NULL) { leaf = SwcTreeNode::firstChild(leaf); } SwcTreeNode::setPos(leaf, targetPos); } return tree; }