예제 #1
0
/*
static double local_neuroseg_zscore(const Local_Neuroseg *locseg)
{
  double pos[3];
  Local_Neuroseg_Bottom(locseg, pos);
  double zbottom = pos[2];
  Local_Neuroseg_Top(locseg, pos);
  double ztop = pos[2];

  return fabs(zbottom - ztop) / locseg->seg.h;
}
*/
static void kill_locseg_chain_array(Locseg_Chain **chain, int n)
{
  int i;
  for (i = 0; i < n; i++) {
    Kill_Locseg_Chain(chain[i]);
  }
  free(chain);
}
예제 #2
0
void Kill_Neuron_Component(Neuron_Component *nc)
{
  switch (nc->type) {
  case NEUROCOMP_TYPE_LOCSEG_CHAIN:
    Kill_Locseg_Chain(NEUROCOMP_LOCSEG_CHAIN(nc));
    break;
  case NEUROCOMP_TYPE_LOCAL_NEUROSEG:
    Delete_Local_Neuroseg(NEUROCOMP_LOCAL_NEUROSEG(nc));
    break;
  case NEUROCOMP_TYPE_GEO3D_CIRCLE:
    break;
  default:
    TZ_ERROR(ERROR_DATA_TYPE);
  }  
  free(nc);
}
예제 #3
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;
}