示例#1
0
Scanner::Scanner (char* file_name)
{
	file.open(file_name);
	Filling("keywords.txt" , keyword);
	Filling("operations.txt" , operation);
	Filling("separators.txt", separator);
	xy.first=xy.second=1;
}
void DoRegionFillingByEdgeTracing(int* image, int x, int y,
                                  int image_width, int image_height,
                                  int filling_colour) {
  int index_cen = y * image_width + x;
  int index[8];
  index[0] = std::max(y - 1, 0) * image_width + std::min(x + 1, image_width);
  index[1] = std::max(y - 1, 0) * image_width + x;
  index[2] = std::max(y - 1, 0) * image_width + std::max(x - 1, 0);
  index[3] = y * image_width + std::max(x - 1, 0);
  index[4] = y * image_width + std::min(x + 1, image_width);
  index[5] = std::min(y + 1, image_height) * image_width + std::min(x + 1, image_width);
  index[6] = std::min(y + 1, image_height) * image_width + x;
  index[7] = std::min(y + 1, image_height) * image_width + std::max(x - 1, 0);

  int firstPoint = 0;
  if (image[index_cen] == WHITE) {
    firstPoint = index_cen;
    int previous_index_cen = 0;
    int next_index_cen = 0;
    for (int i = 0; i < 8; i++) {
      if (image[index[i]] == WHITE) {
        previous_index_cen = index[i];
        break;
      }
    }

    std::vector<int> start_points;
    std::vector<int> end_points;
    int delt_angle = 0;
    int clockwise = 0;
    int* tmp_array = new int[image_width * image_height];
    while (previous_index_cen != 0) {
      int findPoint = FindNextPoint(image, previous_index_cen,
                                    index_cen, image_width,
                                    &next_index_cen, &delt_angle);
      if (findPoint == 1) {
        if (index_cen == firstPoint && image[next_index_cen] != WHITE) {

          Filling(image, start_points, end_points, clockwise, filling_colour);
          
          start_points.clear();
          end_points.clear();
          delt_angle = 0;
          delete [] tmp_array;
          return;
        }
        SetColourForPoints(image, tmp_array, previous_index_cen,
                           index_cen, next_index_cen, image_width,
                           &start_points, &end_points);
      } else {
        delete [] tmp_array;
        return;
      }
      previous_index_cen = index_cen;
      index_cen = next_index_cen;
    }
    delete [] tmp_array;
  }
}
示例#3
0
int Func(Coor &size, Figures figures, Coor start)
{
	if (figures.empty())
		return 0;

	Mat board;
	for (int i = 0; i < size.ln; i++)
		for (int j = 0; j < size.col; j++)
			if (i == 0 || j == 0 || i == size.ln - 1 || j == size.col - 1)
				board[i][j] = -4;
			else
				board[i][j] = 0;
	Filling(board, size, figures);

	std::queue<Coor> kill;
	std::queue<Coor> wave;
	wave.push(start);
	while (!wave.empty())
	{
		start = wave.front();
		wave.pop();
		kingStep(kill, wave, board, start, Coor(-1, -1));
		kingStep(kill, wave, board, start, Coor(-1, 0));
		kingStep(kill, wave, board, start, Coor(-1, 1));
		kingStep(kill, wave, board, start, Coor(0, 1));
		kingStep(kill, wave, board, start, Coor(1, 1));
		kingStep(kill, wave, board, start, Coor(1, 0));
		kingStep(kill, wave, board, start, Coor(1, -1));
		kingStep(kill, wave, board, start, Coor(0, -1));
	}

	int min = -1;
	while (!kill.empty())
	{
		Coor tempKill = kill.front();
		kill.pop();
		Figures tempFigures = figures;
		for (Figures::iterator it = tempFigures.begin(); it != tempFigures.end(); it++)
		{
			if (it->ln == tempKill.ln && it->col == tempKill.col)
			{
				tempFigures.erase(it);
				break;
			}
		}
		int temp = Func(size, tempFigures, tempKill);
		if (temp >= 0)
		{
			if (min < 0 || temp + board[tempKill.ln][tempKill.col] < min)
				min = temp + board[tempKill.ln][tempKill.col];
		}
	}
	return min;
}
void algorithm::skinning::Filling(shape::DiscreteShape<2>::Ptr shape, const skeleton::CompContProjSkel::Ptr contskl, const OptionsFilling &options)
{
	std::vector<unsigned int> edge(0);
	contskl->getAllEdges(edge);
	
	for(unsigned int i=0;i<edge.size();i++)
	{
		std::pair<unsigned int,unsigned int> ext = contskl->getExtremities(edge[i]);
		
		Filling(shape,contskl->getBranch(ext.first,ext.second),options);
	}
}
示例#5
0
void CTestRangeMap::TestRangeMap(void) const
{
    Filling("CRangeMap");

    typedef CRangeMultimap<CConstRef<CObject> > TMap;
    typedef TMap::const_iterator TMapCI;

    TMap m;

    // fill
    for ( int count = 0; count < m_RangeNumber; ) {
        TRange range = RandomRange();
        m.insert(TMap::value_type(range, CConstRef<CObject>(0)));
        ++count;
        Added(range);
    }
    
    if ( m_PrintSize ) {
        Filled(m.size());
        // Stat(m.stat());
    }

    for ( TMapCI i = m.begin(); i; ++i ) {
        FromAll(i.GetInterval());
    }

    size_t scannedCount = 0;
    for ( int count = 0; count < m_ScanCount; ++count ) {
        for ( int pos = 0; pos <= m_Length + 2*m_RangeLength;
              pos += m_ScanStep ) {
            TRange range;
            range.Set(pos, pos + m_ScanLength - 1);
            
            StartFrom(range);
            
            for ( TMapCI i = m.begin(range); i; ++i ) {
                From(range, i.GetInterval());
                ++scannedCount;
            }
        }
    }
    PrintTotalScannedNumber(scannedCount);

    End();
}
示例#6
0
void CTestRangeMap::TestIntervalTree(void) const
{
    Filling("CIntervalTree");

    typedef CIntervalTree TMap;
    typedef TMap::const_iterator TMapCI;

    TMap m;

    // fill
    for ( int count = 0; count < m_RangeNumber; ) {
        TRange range = RandomRange();
        m.Insert(range, CConstRef<CObject>(0));
        ++count;
        Added(range);
    }
    
    if ( m_PrintSize ) {
        Filled(m.Size());
        Stat(m.Stat());
    }

    for ( TMapCI i = m.AllIntervals(); i; ++i ) {
        FromAll(i.GetInterval());
    }

    size_t scannedCount = 0;
    for ( int count = 0; count < m_ScanCount; ++count ) {
        for ( int pos = 0; pos <= m_Length + 2*m_RangeLength;
              pos += m_ScanStep ) {
            TRange range(pos, pos + m_ScanLength - 1);
            
            StartFrom(range);
            
            for ( TMapCI i = m.IntervalsOverlapping(range); i; ++i ) {
                From(range, i.GetInterval());
                ++scannedCount;
            }
        }
    }
    PrintTotalScannedNumber(scannedCount);

    End();
}