Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
/*
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();
  }
}
Ejemplo n.º 3
0
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());
}
Ejemplo n.º 4
0
ZIntCuboid ZDvidDataSliceHelper::GetBoundBox(const QRect &viewPort, int z)
{
  ZIntCuboid box;
  box.setFirstCorner(viewPort.left(), viewPort.top(), z);
  box.setSize(viewPort.width(), viewPort.height(), 1);

  return box;
}
Ejemplo n.º 5
0
ZObject3dScan ZDvidInfo::getBlockIndex(const ZIntCuboid &box) const
{
  ZIntPoint startIndex = getBlockIndex(box.getFirstCorner());
  ZIntPoint endIndex = getBlockIndex(box.getLastCorner());


  return ZObject3dFactory::MakeObject3dScan(ZIntCuboid(startIndex, endIndex));
}
Ejemplo n.º 6
0
ZIntCuboid ZBlockGrid::getBlockBox(const ZIntPoint &blockIndex) const
{
  ZIntCuboid cuboid;
  cuboid.setFirstCorner(getBlockPosition(blockIndex));
  cuboid.setSize(m_blockSize.getX(), m_blockSize.getY(), m_blockSize.getZ());

  return cuboid;
}
Ejemplo n.º 7
0
ZIntCuboid ZDvidInfo::getBlockBox(int x, int y, int z) const
{
  x -= m_startBlockIndex.getX();
  y -= m_startBlockIndex.getY();
  z -= m_startBlockIndex.getZ();

  ZIntCuboid cuboid;

  cuboid.setFirstCorner(x * m_blockSize[0] + m_startCoordinates.getX(),
      y * m_blockSize[1] + m_startCoordinates.getY(),
      z * m_blockSize[2] + m_startCoordinates.getZ());
  cuboid.setSize(m_blockSize[0], m_blockSize[1], m_blockSize[2]);

  return cuboid;
}
Ejemplo n.º 8
0
bool ZIntCuboid::hasOverlap(const ZIntCuboid &box) const
{
  bool overlapped = false;
  for (int i = 0; i < 8; ++i) {
    if (contains(box.getCorner(i))) {
      overlapped = true;
      break;
    }

    if (box.contains(getCorner(i))) {
      overlapped = true;
      break;
    }
  }

  return overlapped;
}
Ejemplo n.º 9
0
std::string ZDvidUrl::getSupervoxelUrl(
    uint64_t bodyId, const ZIntCuboid &box) const
{
  std::string url = getSupervoxelUrl(bodyId);

  return AppendRangeQuery(url, box);
#if 0
  if (url.empty()) {
    return "";
  }

  if (!box.isEmpty()) {
    url += "?minx=";
    url.appendNumber(box.getFirstCorner().getX());
    url += "&maxx=";
    url.appendNumber(box.getLastCorner().getX());

    url += "&miny=";
    url.appendNumber(box.getFirstCorner().getY());
    url += "&maxy=";
    url.appendNumber(box.getLastCorner().getY());

    url += "&minz=";
    url.appendNumber(box.getFirstCorner().getZ());
    url += "&maxz=";
    url.appendNumber(box.getLastCorner().getZ());
  }

  return url;
#endif
}
Ejemplo n.º 10
0
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());
}
Ejemplo n.º 11
0
std::string ZDvidUrl::AppendRangeQuery(
    const std::string &url, const ZIntCuboid &box)
{
  ZString query;
  if (!url.empty() && !box.isEmpty()) {
    query += "minx=";
    query.appendNumber(box.getFirstCorner().getX());
    query += "&maxx=";
    query.appendNumber(box.getLastCorner().getX());

    query += "&miny=";
    query.appendNumber(box.getFirstCorner().getY());
    query += "&maxy=";
    query.appendNumber(box.getLastCorner().getY());

    query += "&minz=";
    query.appendNumber(box.getFirstCorner().getZ());
    query += "&maxz=";
    query.appendNumber(box.getLastCorner().getZ());
  }

  return AppendQuery(url, query);
}
Ejemplo n.º 12
0
std::string ZDvidUrl::getSynapseUrl(const ZIntCuboid &box) const
{
  return getSynapseUrl(box.getFirstCorner(), box.getWidth(), box.getHeight(),
                       box.getDepth());
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
bool ZIntCuboid::equals(const ZIntCuboid &cuboid) const
{
  return m_firstCorner.equals(cuboid.getFirstCorner()) &&
      m_lastCorner.equals(cuboid.getLastCorner());
}