//091212 RZC
void neuron_branch_tip_count(V3DLONG &n_branch, V3DLONG &n_tip, const V_NeuronSWC & in_swc)
{
	// map swc's index --> vector's index & in/out link
	Link_Map link_map = get_link_map(in_swc);
	//qDebug("link_map created.");

	n_branch = 0;
	n_tip = 0;

    V3DLONG n_path=0, n_single=0; //for test

	Link_Map_Iter it;
	for (it=link_map.begin(); it!=link_map.end(); it++)
	{
//		const V_NeuronSWC_unit & cur_node = in_swc.row.at(i);
//		Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];
		Node_Link & nodelink = (*it).second;

        if(nodelink.nlink == 0) n_single++;

		if (nodelink.nlink == 1)
			n_tip ++;

        if (nodelink.nlink == 2) n_path++;// path point

		if (nodelink.nlink >= 3)
		{
			n_branch ++;
			//qDebug("branch #%d (%g %g %g) %d", V3DLONG(cur_node.n),cur_node.x,cur_node.y,cur_node.z, nodelink.nlink);
		}
	}

    qDebug("cojoc: all:%d/link:%d/0:%d/1:%d/2:%d/3+:%d",in_swc.row.size(),link_map.size(),n_single,n_tip,n_path,n_branch);
}
//091212 RZC
void neuron_branch_tip_count(V3DLONG &n_branch, V3DLONG &n_tip, const V_NeuronSWC & in_swc)
{
	// map swc's index --> vector's index & in/out link
	Link_Map link_map = get_link_map(in_swc);
	//qDebug("link_map created.");

	n_branch = 0;
	n_tip = 0;

	Link_Map_Iter it;
	for (it=link_map.begin(); it!=link_map.end(); it++)
	{
//		const V_NeuronSWC_unit & cur_node = in_swc.row.at(i);
//		Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];
		Node_Link & nodelink = (*it).second;

		if (nodelink.nlink == 1)
			n_tip ++;

		//if (nodelink.nlink == 2) // path point

		if (nodelink.nlink >= 3)
		{
			n_branch ++;
			//qDebug("branch #%d (%g %g %g) %d", V3DLONG(cur_node.n),cur_node.x,cur_node.y,cur_node.z, nodelink.nlink);
		}
	}
}
Example #3
0
static const struct link_map* link_map_entry_for_library(const char* library)
{
    for (const struct link_map* map = get_link_map(); map != NULL; map = map->l_next)
    {
        if (map->l_name && strcmp(basename(map->l_name), basename(library)) == 0)
        {
            return map;
        }
    }

    fprintf(stderr, "failed to locate link-map-entry for library %s\n", library);
    return NULL;
}
Example #4
0
//091212 RZC
vector <V_NeuronSWC> decompose_V_NeuronSWC(V_NeuronSWC & in_swc)
{
    // map swc's index --> vector's index & in/out link
    Link_Map link_map = get_link_map(in_swc);
    qDebug("link_map is created.");

    vector <V_NeuronSWC> out_swc_segs;
    out_swc_segs.clear();

    // nchild as processed counter
    for (V3DLONG i=0; i<in_swc.row.size(); i++)
    {
        V_NeuronSWC_unit & cur_node = in_swc.row[i];
        Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];
        cur_node.nchild = nodelink.nlink;
        //qDebug("#%d nlink = %d, in %d, out %d", V3DLONG(cur_node.n), nodelink.nlink, nodelink.in_link.size(), nodelink.out_link.size());
    }

    for (;;)
    {
        // check is all nodes processed
        V3DLONG n_removed = 0;
        for (V3DLONG i=0; i<in_swc.row.size(); i++)
        {
            V_NeuronSWC_unit & cur_node = in_swc.row[i];
            if (cur_node.nchild <=0) // is removed node ////// count down to 0
                n_removed ++;
        }
        if (n_removed >= in_swc.row.size())
        {
            //qDebug("split_V_NeuronSWC_segs is done.");
            break; //over, all nodes have been labeled to remove
        }

        // find a tip/out-branch/pure-out point as start point
        V3DLONG istart = -1;
        V3DLONG n_left = 0;
        V3DLONG i_left = -1;
        for (V3DLONG i=0; i<in_swc.row.size(); i++)
        {
            V_NeuronSWC_unit & cur_node = in_swc.row[i];
            Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];

            if (cur_node.nchild <=0)
                continue; //skip removed point

            n_left++; //left valid point
            i_left = i;

            if ((nodelink.nlink ==1 && nodelink.in_link.size()==0) // tip point (include single point)
                    || (nodelink.nlink >2 && nodelink.out_link.size() >0) // out-branch point
                    || (nodelink.nlink ==2 && nodelink.in_link.size()==0)) // pure-out point
            {
                istart = i;
                if (0)
                    qDebug("start from #%d", V3DLONG(cur_node.n));
                break; //find a start point
            }
        }
        if (istart <0) //not find a start point
        {
            if (n_left)
            {
                qDebug("split_V_NeuronSWC_segs cann't find start point (left %d points)", n_left);
                istart = i_left;
            }
            else
            {
                qDebug("split_V_NeuronSWC_segs finished.");
                break;
            }
        }

        // extract a simple segment
        V_NeuronSWC new_seg;
        new_seg.clear();
        //qDebug("decompose_V_NeuronSWC_segs: segment from node #%d", j);

        V3DLONG inext = istart;
        for (V3DLONG n=1; inext>=0; n++)
        {
            V_NeuronSWC_unit & cur_node = in_swc.row[inext];
            Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];
            //qDebug("	link #%d", V3DLONG(cur_node.n));

            V_NeuronSWC_unit new_node = cur_node;
            new_node.n = n;
            new_node.parent = n+1; // link order as original order
            new_seg.row.push_back(new_node);

            if(cur_node.parent <0)    // root point ////////////////////////////
            {
                //qDebug("decompose_V_NeuronSWC_segs: segment end at root #%d", V3DLONG(cur_node.n));
                cur_node.nchild --;
                break; //over, a simple segment
            }
            else if (n>1 && nodelink.nlink >2)  // branch point (in link_map) ///////////
            {
                //qDebug("decompose_V_NeuronSWC_segs: segment end at branch #%d", V3DLONG(cur_node.n));
                cur_node.nchild --;
                break; //over, a simple segment
            }
            else if (n>1 && inext==istart)  // i_left point (a loop) ///////////
            {
                //qDebug("decompose_V_NeuronSWC_segs: segment end at branch #%d", V3DLONG(cur_node.n));
                cur_node.nchild --;
                break; //over, a simple segment
            }
            else  //(nodelink.nlink==2)   // path node ///////////////////////////////////////////////
            {
                //qDebug("decompose_V_NeuronSWC_segs: node #%d", j);
                V3DLONG parent = cur_node.parent;
                inext = link_map[parent].i; //// next point in seg
                cur_node.nchild = -1;  // label to remove
            }
        }

        if (new_seg.row.size()>0)//>=2)//? single point
        {
            new_seg.row[new_seg.row.size()-1].parent = -1; // set segment end
            char buf[10];
            new_seg.name = sprintf(buf,"%d", out_swc_segs.size()+1);
            new_seg.b_linegraph=true; //donot forget to do this //####################
            out_swc_segs.push_back(new_seg);
        }
    }

    return out_swc_segs;
}
Example #5
0
V_NeuronSWC segmentPruning(V_NeuronSWC in_swc)
{
    // map swc's index --> vector's index & in/out link

    // code from function of "decompose_V_NeuronSWC" by RZC
    // construct link map,
    Link_Map link_map = get_link_map(in_swc);
    /*qDebug*/("link_map is created.");

              vector <V_NeuronSWC> out_swc_segs;
              out_swc_segs.clear();

              // nchild as processed counter
              for (V3DLONG i=0; i<in_swc.row.size(); i++)
              {
                  V_NeuronSWC_unit & cur_node = in_swc.row[i];
                  Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];
                  cur_node.nchild = nodelink.nlink;
                  //qDebug("#%d nlink = %d, in %d, out %d", V3DLONG(cur_node.n), nodelink.nlink, nodelink.in_link.size(), nodelink.out_link.size());
              }

              for (;;)
              {
                  // check is all nodes processed
                  V3DLONG n_removed = 0;
                  for (V3DLONG i=0; i<in_swc.row.size(); i++)
                  {
                      V_NeuronSWC_unit & cur_node = in_swc.row[i];
                      if (cur_node.nchild <=0) // is removed node ////// count down to 0
                          n_removed ++;
                  }
                  if (n_removed >= in_swc.row.size())
                  {
                      //qDebug("split_V_NeuronSWC_segs is done.");
                      break; //over, all nodes have been labeled to remove
                  }

                  // find a tip/out-branch/pure-out point as start point
                  V3DLONG istart = -1;
                  V3DLONG n_left = 0;
                  V3DLONG i_left = -1;
                  for (V3DLONG i=0; i<in_swc.row.size(); i++)
                  {
                      V_NeuronSWC_unit & cur_node = in_swc.row[i];
                      Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];

                      if (cur_node.nchild <=0)
                          continue; //skip removed point

                      n_left++; //left valid point
                      i_left = i;

                      if ((nodelink.nlink ==1 && nodelink.in_link.size()==0) // tip point (include single point)
                          || (nodelink.nlink >2 && nodelink.out_link.size() >0) // out-branch point
                          || (nodelink.nlink ==2 && nodelink.in_link.size()==0)) // pure-out point
                          {
                          istart = i;
                          qDebug("start from #%d", V3DLONG(cur_node.n));
                          break; //find a start point
                      }
                  }
                  if (istart <0) //not find a start point
                  {
                      if (n_left)
                      {
                          qDebug("split_V_NeuronSWC_segs cann't find start point (left %d points)", n_left);
                          istart = i_left;
                      }
                      else
                      {
                          qDebug("split_V_NeuronSWC_segs finished.");
                          break;
                      }
                  }

                  // extract a simple segment
                  V_NeuronSWC new_seg;
                  new_seg.clear();
                  //qDebug("decompose_V_NeuronSWC_segs: segment from node #%d", j);
                  float segLen = 0;
                  bool isTip = false;
                  V3DLONG inext = istart;
                  for (V3DLONG n=1; inext>=0; n++)
                  {
                      V_NeuronSWC_unit & cur_node = in_swc.row[inext];
                      Node_Link & nodelink = link_map[V3DLONG(cur_node.n)];
                      //qDebug("	link #%d", V3DLONG(cur_node.n));

                      V_NeuronSWC_unit new_node = cur_node;
                      new_node.n = n;
                      new_node.parent = n+1; // link order as original order
                      new_seg.row.push_back(new_node);

                      if (nodelink.nlink ==1 && nodelink.in_link.size()==0)
                      {   // tip point
                          isTip = true;
                          cur_node.nchild --;
                          break;
                      }

                      if(cur_node.parent < 0 )    // root point ////////////////////////////
                      {
                          //qDebug("decompose_V_NeuronSWC_segs: segment end at root #%d", V3DLONG(cur_node.n));
                          cur_node.nchild --;
                          break; //over, a simple segment
                      }
                      else if (n>1 && nodelink.nlink >2)  // branch point (in link_map) ///////////
                      {
                          //qDebug("decompose_V_NeuronSWC_segs: segment end at branch #%d", V3DLONG(cur_node.n));
                          cur_node.nchild --;
                          break; //over, a simple segment
                      }
                      else if (n>1 && inext==istart)  // i_left point (a loop) ///////////
                      {
                          //qDebug("decompose_V_NeuronSWC_segs: segment end at branch #%d", V3DLONG(cur_node.n));
                          cur_node.nchild --;
                          break; //over, a simple segment
                      }
                      else  //(nodelink.nlink==2)   // path node ///////////////////////////////////////////////
                      {
                          //qDebug("decompose_V_NeuronSWC_segs: node #%d", j);
                          V3DLONG parent = cur_node.parent;
                          inext = link_map[parent].i; //// next point in seg
                          cur_node.nchild = -1;  // label to remove
                      }
                  }

                  if ( isTip )
                  {   // measure length
                      segLen = 0;
                      float preX = new_seg.row.at(0).x;
                      float preY = new_seg.row.at(0).y;
                      float preZ = new_seg.row.at(0).z;

                      for (int i = 1; i < new_seg.row.size(); i++ )
                      {
                          float curX = new_seg.row.at(i).x;
                          float curY = new_seg.row.at(i).y;
                          float curZ = new_seg.row.at(i).z;
                          segLen += sqrt( (preX - curX)*(preX - curX) + (preY - curY)*(preY - curY) +(preZ - curZ)*(preZ - curZ) );
                      }

                      // compare the length and radius of parent branch point
                      if ( segLen < 2 * in_swc.row[istart].r )
                      {
                          continue;
                      }
                  }

                  if (new_seg.row.size()>0 )//>=2)//? single point
                  {
                      new_seg.row[new_seg.row.size()-1].parent = -1; // set segment end
                      char buf[10];
                      new_seg.name = sprintf(buf,"%d", out_swc_segs.size()+1);
                      new_seg.b_linegraph=true; //donot forget to do this //####################
                      out_swc_segs.push_back(new_seg);
                  }
              }

              // merge the segments
              V_NeuronSWC_list swcList;
              swcList.seg = out_swc_segs;
              V_NeuronSWC out_swc = merge_V_NeuronSWC_list (swcList);
              return out_swc;
          }