Example #1
0
/**
 * for each contig owned by the current compute core,
 * search on its left and on its right in the distributed de
 * Bruijn graph.
 *
 * send items to master.
 *
 * each item is (leftContig	strand	rightContig	strand	verticesInGap)
 *
 * to do so, do a depth first search with a maximum depth
 *
 *
 * message used and what is needed:
 *
 *    - get the edges of a vertex
 *    RAY_MPI_TAG_GET_VERTEX_EDGES_COMPACT
 *      period: registered via RayPlatform, fetch it for there
 *      input: a k-mer
 *      output: edges (1 element), coverage (1 element)
 *      multiplexing: supported
 *
 *
 * used tags for paths: 
 *
 *	RAY_MPI_TAG_ASK_VERTEX_PATHS_SIZE
 *	RAY_MPI_TAG_ASK_VERTEX_PATH
 *	RAY_MPI_TAG_GET_PATH_LENGTH
 *
 *    - get the path length for a path
 *    RAY_MPI_TAG_GET_PATH_LENGTH
 *      period: 1
 *      input: path unique identifier (usually the the contig name)
 *      output: the length of the path, measured in k-mers
 *
 *
 * prototype 1: don't use Message Multiplexing, because the thing may be fast without it
 *              like scaffolding.
 */
void GenomeNeighbourhood::call_RAY_SLAVE_MODE_NEIGHBOURHOOD(){

	if(!m_pluginIsEnabled){

		cout<<"Rank "<<m_rank<<": the CorePlugin GenomeNeighbourhood is disabled..."<<endl;

		m_core->getSwitchMan()->closeSlaveModeLocally(m_core->getOutbox(),m_core->getRank());

		return; /* . */
	}

	/* force flush everything ! */
	m_virtualCommunicator->forceFlush();
	m_virtualCommunicator->processInbox(&m_activeWorkers);
	m_activeWorkers.clear();


	if(!m_slaveStarted){

		m_contigIndex=0;

		m_doneLeftSide=false;
		m_startedLeft=false;
		m_doneRightSide=false;
		m_startedRight=false;
	
		m_slaveStarted=true;

		m_virtualCommunicator->resetCounters();

	}else if(m_contigIndex<(int)m_contigs->size()){ /* there is still work to do */

/*
		PathHandle contigName=m_contigNames->at(m_contigIndex);
		Strand contigStrand='F';
		int contigLength=m_contigs->at(m_contigIndex).size();
*/

		// left side
		if(!m_doneLeftSide){
	
			if(!m_startedLeft){

				cout<<"Rank "<<m_rank<<" is fetching contig path neighbours ["<<m_contigIndex<<"/"<<m_contigs->size()<<"]"<<endl;

				m_startedLeft=true;
				m_startedSide=false;
				m_doneSide=false;


				m_leftNeighbours.clear();
				m_rightNeighbours.clear();

			}else if(!m_doneSide){
				processSide(FETCH_PARENTS);
			}else{
				m_doneLeftSide=true;
			}

		// right side
		}else if(!m_doneRightSide){
		
			if(!m_startedRight){
				m_startedRight=true;
				m_startedSide=false;
				m_doneSide=false;
			}else if(!m_doneSide){

				processSide(FETCH_CHILDREN);
			}else{
				m_doneRightSide=true;
				m_selectedHits=false;
			}


		}else if(!m_selectedHits){

			selectHits();

			m_selectedHits=true;
			m_sentLeftNeighbours=false;
			m_neighbourIndex=0;
			m_sentEntry=false;
			m_receivedReply=false;

		}else if(!m_sentLeftNeighbours){

			sendLeftNeighbours();

		}else if(!m_sentRightNeighbours){

			sendRightNeighbours();

		}else{

			/* continue the work */
			m_contigIndex++;

			m_doneLeftSide=false;
			m_startedLeft=false;
			m_doneRightSide=false;
			m_startedRight=false;
		}
	}else{

		cout<<"Rank "<<m_rank<<" is fetching contig path neighbours ["<<m_contigIndex<<"/"<<m_contigs->size()<<"]"<<endl;

		#ifdef ASSERT
		assert(m_contigIndex == (int)m_contigs->size());
		#endif

		m_virtualCommunicator->printStatistics();

		m_core->getSwitchMan()->closeSlaveModeLocally(m_core->getOutbox(),m_core->getRank());
	}
}
Example #2
0
//void processLanes(CvSeq *lines, IplImage* edges, IplImage *temp_frame)
static void processLanes(CvSeq *lines, IplImage* edges, IplImage *temp_frame, IplImage *org_frame)
{
  /* classify lines to left/right side */
  std::vector<Lane> left, right;

  for (int i=0; i<lines->total; i++)
    {
      CvPoint *line = (CvPoint *)cvGetSeqElem(lines, i);
      int dx = line[1].x - line[0].x;
      int dy = line[1].y - line[0].y;
      float angle = atan2f(dy, dx) * 180/CV_PI;

      if (fabs(angle) <= LINE_REJECT_DEGREES) // reject near horizontal lines
        {
          continue;
        }

      /* assume that vanishing point is close to the image horizontal center
         calculate line parameters: y = kx + b; */
      dx = (dx == 0) ? 1 : dx;  // prevent DIV/0!
      float k = dy/(float)dx;
      float b = line[0].y - k*line[0].x;

      /* assign lane's side based by its midpoint position */
      int midx = (line[0].x + line[1].x) / 2;
      if (midx < temp_frame->width/2)
        {
          left.push_back(Lane(line[0], line[1], angle, k, b));
        }
      else if (midx > temp_frame->width/2)
        {
          right.push_back(Lane(line[0], line[1], angle, k, b));
        }
    }

  /* show Hough lines */
  int org_offset = temp_frame->height;
  for (std::size_t i = 0; i < right.size(); ++i)
    {
      CvPoint org_p0 = right[i].p0;
      org_p0.y += org_offset;
      CvPoint org_p1 = right[i].p1;
      org_p1.y += org_offset;
#ifdef USE_POSIX_SHARED_MEMORY
#ifdef SHOW_DETAIL
      cvLine(temp_frame, right[i].p0, right[i].p1, BLUE, 2);
#endif
      cvLine(org_frame, org_p0, org_p1, BLUE, 2);
#endif
    }
  for (std::size_t i = 0; i < left.size(); ++i)
    {
      CvPoint org_p0 = left[i].p0;
      org_p0.y += org_offset;
      CvPoint org_p1 = left[i].p1;
      org_p1.y += org_offset;
#ifdef USE_POSIX_SHARED_MEMORY
#ifdef SHOW_DETAIL
      cvLine(temp_frame, left[i].p0, left[i].p1, RED, 2);
#endif
      cvLine(org_frame, org_p0, org_p1, RED, 2);
#endif
    }

  processSide(left, edges, false);
  processSide(right, edges, true);

  /* show computed lanes */
  int x = temp_frame->width * 0.55f;
  int x2 = temp_frame->width;
#if defined(USE_POSIX_SHARED_MEMORY)
#ifdef SHOW_DETAIL
  cvLine(temp_frame, cvPoint(x, laneR.k.get()*x + laneR.b.get()),
         cvPoint(x2, laneR.k.get()*x2 + laneR.b.get()), PURPLE, 2);
#endif

  cvLine(org_frame, cvPoint(x, laneR.k.get()*x + laneR.b.get() + org_offset),
         cvPoint(x2, laneR.k.get()*x2 + laneR.b.get() + org_offset), PURPLE, 2);
#else
  lane_detector::ImageLaneObjects lane_msg;
  lane_msg.lane_r_x1 = x;
  lane_msg.lane_r_y1 = laneR.k.get()*x + laneR.b.get() + org_offset;
  lane_msg.lane_r_x2 = x2;
  lane_msg.lane_r_y2 = laneR.k.get()*x2 + laneR.b.get() + org_offset;
#endif

  x = temp_frame->width * 0;
  x2 = temp_frame->width * 0.45f;
#if defined(USE_POSIX_SHARED_MEMORY)
#ifdef SHOW_DETAIL
  cvLine(temp_frame, cvPoint(x, laneL.k.get()*x + laneL.b.get()),
         cvPoint(x2, laneL.k.get()*x2 + laneL.b.get()), PURPLE, 2);
#endif

  cvLine(org_frame, cvPoint(x, laneL.k.get()*x + laneL.b.get() + org_offset),
         cvPoint(x2, laneL.k.get()*x2 + laneL.b.get() + org_offset), PURPLE, 2);
#else
  lane_msg.lane_l_x1 = x;
  lane_msg.lane_l_y1 = laneL.k.get()*x + laneL.b.get() + org_offset;
  lane_msg.lane_l_x2 = x2;
  lane_msg.lane_l_y2 = laneL.k.get()*x2 + laneL.b.get() + org_offset;

  image_lane_objects.publish(lane_msg);
#endif
  // cvLine(org_frame, cvPoint(lane_msg.lane_l_x1, lane_msg.lane_l_y1), cvPoint(lane_msg.lane_l_x2, lane_msg.lane_l_y2), RED, 5);
  // cvLine(org_frame, cvPoint(lane_msg.lane_r_x1, lane_msg.lane_r_y1), cvPoint(lane_msg.lane_r_x2, lane_msg.lane_r_y2), RED, 5);
}