Ejemplo n.º 1
0
ZSwcPath ZNeuronTracer::trace(double x, double y, double z)
{
  if (m_traceWorkspace->trace_mask == NULL) {
    m_traceWorkspace->trace_mask =
        C_Stack::make(GREY, C_Stack::width(m_stack), C_Stack::height(m_stack),
                      C_Stack::depth(m_stack));
    Zero_Stack(m_traceWorkspace->trace_mask);
  }

  double pos[3];
  pos[0] = x;
  pos[1] = y;
  pos[2] = z;

  Local_Neuroseg *locseg = New_Local_Neuroseg();
  Set_Neuroseg(&(locseg->seg), 3.0, 0.0, 11.0, TZ_PI_4, 0.0, 0.0, 0.0, 1.0);

  Set_Neuroseg_Position(locseg, pos, NEUROSEG_CENTER);

  Locseg_Fit_Workspace *ws =
      (Locseg_Fit_Workspace*) m_traceWorkspace->fit_workspace;
  Local_Neuroseg_Optimize_W(locseg, m_stack, 1.0, 1, ws);

  Trace_Record *tr = New_Trace_Record();
  tr->mask = ZERO_BIT_MASK;
  Trace_Record_Set_Fix_Point(tr, 0.0);
  Trace_Record_Set_Direction(tr, DL_BOTHDIR);
  Locseg_Node *p = Make_Locseg_Node(locseg, tr);
  Locseg_Chain *locseg_chain = Make_Locseg_Chain(p);

  Trace_Workspace_Set_Trace_Status(m_traceWorkspace, TRACE_NORMAL,
                                   TRACE_NORMAL);
  Trace_Locseg(m_stack, 1.0, locseg_chain, m_traceWorkspace);
  Locseg_Chain_Remove_Overlap_Ends(locseg_chain);
  Locseg_Chain_Remove_Turn_Ends(locseg_chain, 1.0);

  int n;
  Geo3d_Circle *circles =
      Locseg_Chain_To_Geo3d_Circle_Array(locseg_chain, NULL, &n);

  ZSwcPath path;
  for (int i = 0; i < n; ++i) {
    Swc_Tree_Node *tn = SwcTreeNode::makePointer(circles[i].center[0],
        circles[i].center[1], circles[i].center[2], circles[i].radius);
    if (!path.empty()) {
      SwcTreeNode::setParent(tn, path.back());
    }
    path.push_back(tn);
  }

  return path;
}
Ejemplo n.º 2
0
ZSwcPath ZNeuronTracer::trace(double x, double y, double z)
{
  setTraceScoreThreshold(TRACING_INTERACTIVE);

  if (m_traceWorkspace->trace_mask == NULL) {
    m_traceWorkspace->trace_mask =
        C_Stack::make(GREY, getStack()->width(), getStack()->height(),
                      getStack()->depth());
    Zero_Stack(m_traceWorkspace->trace_mask);
  }

  Stack *stackData = getIntensityData();

  ZIntPoint stackOffset = getStack()->getOffset();

  double pos[3];
  pos[0] = x - stackOffset.getX();
  pos[1] = y - stackOffset.getY();
  pos[2] = z - stackOffset.getZ();

  /* alloc <locseg> */
  Local_Neuroseg *locseg = New_Local_Neuroseg();
  Set_Neuroseg(&(locseg->seg), 3.0, 0.0, 11.0, TZ_PI_4, 0.0, 0.0, 0.0, 1.0);

  Set_Neuroseg_Position(locseg, pos, NEUROSEG_CENTER);

  Locseg_Fit_Workspace *ws =
      (Locseg_Fit_Workspace*) m_traceWorkspace->fit_workspace;
  Local_Neuroseg_Optimize_W(locseg, stackData, 1.0, 1, ws);

  Trace_Record *tr = New_Trace_Record();
  tr->mask = ZERO_BIT_MASK;
  Trace_Record_Set_Fix_Point(tr, 0.0);
  Trace_Record_Set_Direction(tr, DL_BOTHDIR);
  /* consume <locseg> */
  Locseg_Node *p = Make_Locseg_Node(locseg, tr);

  /* alloc <locseg_chain> */
  Locseg_Chain *locseg_chain = Make_Locseg_Chain(p);

  Trace_Workspace_Set_Trace_Status(m_traceWorkspace, TRACE_NORMAL,
                                   TRACE_NORMAL);
  Trace_Locseg(stackData, 1.0, locseg_chain, m_traceWorkspace);
  Locseg_Chain_Remove_Overlap_Ends(locseg_chain);
  Locseg_Chain_Remove_Turn_Ends(locseg_chain, 1.0);

  int n;
  /* alloc <circles> */
  Geo3d_Circle *circles =
      Locseg_Chain_To_Geo3d_Circle_Array(locseg_chain, NULL, &n);

  /* free <locseg_chain> */
  Kill_Locseg_Chain(locseg_chain);

  ZSwcPath path;
  if (n > 0) {
//    bool hit = false;
    int start = 0;
    int end = n;
    if (Trace_Workspace_Mask_Value(m_traceWorkspace, circles[0].center) > 0) {
      for (int i = 1; i < n; ++i) {
        start = i - 1;
        if (Trace_Workspace_Mask_Value(m_traceWorkspace, circles[i].center) == 0) {
          break;
        }
      }
    }

    if (n > 1) {
      if (Trace_Workspace_Mask_Value(m_traceWorkspace, circles[n - 1].center) > 0) {
        for (int i = n - 2; i >= 0; --i) {
          end = i + 2;
          if (Trace_Workspace_Mask_Value(m_traceWorkspace, circles[i].center) == 0) {
            break;
          }
        }
      }
    }

    for (int i = start; i < end; ++i) {
      Swc_Tree_Node *tn = SwcTreeNode::makePointer(circles[i].center[0],
          circles[i].center[1], circles[i].center[2], circles[i].radius);
      if (!path.empty()) {
        SwcTreeNode::setParent(tn, path.back());
      }
      SwcTreeNode::translate(tn, stackOffset);
      path.push_back(tn);
    }
  }

  /* free <circles> */
  if (circles != NULL) {
    free(circles);
  }

  return path;
}