void fillRegion(Grid<bool> &pixels, int row, int col) {
	if (!pixels[row][col]) {
		pixels[row][col] = true;
		fillRegion(pixels, row - 1, col);
		fillRegion(pixels, row + 1, col);
		fillRegion(pixels, row, col - 1);
		fillRegion(pixels, row, col + 1);
	}
}
Esempio n. 2
0
void GoalManager::calcRegions (void) {

	//----------------------------------------------------------------------
	// This is the same method used in GlobalMap::calcAreas, so see notes...
	for (long r = 0; r < GameMap->height; r++)
		for (long c = 0; c < GameMap->width; c++)
			if (regionMap[r][c] == -1) {
				recurseCount = 0;
				#ifdef USE_OVERLAYS
				long overlay = GameMap->getOverlay(r, c);
				if (overlay == OVERLAY_WATER_BRIDGE_NS) {
					if (fillNorthSouthBridgeArea(r, c, numAreas))
						numAreas++;
					}
				else if (overlay == OVERLAY_WATER_BRIDGE_EW) {
					if (fillEastWestBridgeArea(r, c, numAreas))
						numAreas++;
					}
				#endif
				if (GameMap->getWall(r, c) || GameMap->getGate(r, c)) {
					if (fillWallGateRegion(r, c, numRegions))
						numRegions++;
					}
				else if (fillRegion(r, c, numRegions))
					numRegions++;
			}
}
Esempio n. 3
0
 void fillRegion(size_t col, size_t row, char new_color, char orig_color)
 {
     if (pixels_[row][col] == orig_color) {
         pixels_[row][col] = new_color;
         if (col >= 1) {
             fillRegion(col - 1, row, new_color, orig_color);
         }
         if (col <= M_ - 2) {
             fillRegion(col + 1, row, new_color, orig_color);
         }
         if (row >= 1) {
             fillRegion(col, row - 1, new_color, orig_color);
         }
         if (row <= N_ - 2) {
             fillRegion(col, row + 1, new_color, orig_color);
         }
     }
 }
Esempio n. 4
0
void Graphics::fillAreaBetweenRects(gfx::Color color,
  const gfx::Rect& outer, const gfx::Rect& inner)
{
  if (!outer.intersects(inner))
    fillRect(color, outer);
  else {
    gfx::Region rgn(outer);
    rgn.createSubtraction(rgn, gfx::Region(inner));
    fillRegion(color, rgn);
  }
}
Esempio n. 5
0
void FETurbulence::apply()
{
    if (hasResult())
        return;
    ByteArray* pixelArray = createUnmultipliedImageResult();
    if (!pixelArray)
        return;

    if (absolutePaintRect().isEmpty())
        return;

    PaintingData paintingData(m_seed, roundedIntSize(filterPrimitiveSubregion().size()));
    initPaint(paintingData);

#if ENABLE(PARALLEL_JOBS)

    int optimalThreadNumber = (absolutePaintRect().width() * absolutePaintRect().height()) / s_minimalRectDimension;
    if (optimalThreadNumber > 1) {
        // Initialize parallel jobs
        ParallelJobs<FillRegionParameters> parallelJobs(&WebCore::FETurbulence::fillRegionWorker, optimalThreadNumber);

        // Fill the parameter array
        int i = parallelJobs.numberOfJobs();
        if (i > 1) {
            int startY = 0;
            int stepY = absolutePaintRect().height() / i;
            for (; i > 0; --i) {
                FillRegionParameters& params = parallelJobs.parameter(i-1);
                params.filter = this;
                params.pixelArray = pixelArray;
                params.paintingData = &paintingData;
                params.startY = startY;
                if (i != 1) {
                    params.endY = startY + stepY;
                    startY = startY + stepY;
                } else
                    params.endY = absolutePaintRect().height();
            }

            // Execute parallel jobs
            parallelJobs.execute();

            return;
        }
    }
    // Fallback to sequential mode if there is no room for a new thread or the paint area is too small

#endif // ENABLE(PARALLEL_JOBS)

    fillRegion(pixelArray, paintingData, 0, absolutePaintRect().height());
}
Esempio n. 6
0
void FETurbulence::applySoftware()
{
    Uint8ClampedArray* pixelArray = createUnmultipliedImageResult();
    if (!pixelArray)
        return;

    if (absolutePaintRect().isEmpty()) {
        pixelArray->zeroFill();
        return;
    }

    PaintingData paintingData(m_seed, roundedIntSize(filterPrimitiveSubregion().size()));
    initPaint(paintingData);

    int optimalThreadNumber = (absolutePaintRect().width() * absolutePaintRect().height()) / s_minimalRectDimension;
    if (optimalThreadNumber > 1) {
        // Initialize parallel jobs
        ParallelJobs<FillRegionParameters> parallelJobs(&WebCore::FETurbulence::fillRegionWorker, optimalThreadNumber);

        // Fill the parameter array
        int i = parallelJobs.numberOfJobs();
        if (i > 1) {
            // Split the job into "stepY"-sized jobs but there a few jobs that need to be slightly larger since
            // stepY * jobs < total size. These extras are handled by the remainder "jobsWithExtra".
            const int stepY = absolutePaintRect().height() / i;
            const int jobsWithExtra = absolutePaintRect().height() % i;

            int startY = 0;
            for (; i > 0; --i) {
                FillRegionParameters& params = parallelJobs.parameter(i-1);
                params.filter = this;
                params.pixelArray = pixelArray;
                params.paintingData = &paintingData;
                params.startY = startY;
                startY += i < jobsWithExtra ? stepY + 1 : stepY;
                params.endY = startY;
                params.baseFrequencyX = m_baseFrequencyX;
                params.baseFrequencyY = m_baseFrequencyY;
            }

            // Execute parallel jobs
            parallelJobs.execute();
            return;
        }
    }

    // Fallback to single threaded mode if there is no room for a new thread or the paint area is too small.
    fillRegion(pixelArray, paintingData, 0, absolutePaintRect().height(), m_baseFrequencyX, m_baseFrequencyY);
}
Esempio n. 7
0
bool GoalManager::fillRegion (long row, long col, long region) {

#if 1

//	long overlay = GameMap->getOverlay(row, col);
//	if ((overlay == OVERLAY_WATER_BRIDGE_EW) || (overlay == OVERLAY_WATER_BRIDGE_NS))
//		return(false);
		
	if (GameMap->getWall(row, col) || GameMap->getGate(row, col))
		return(false);
		
	if (!GameMap->getPassable(row, col)) {
		regionMap[row][col] = -2;
		return(false);
	}

	fillStack[fillStackIndex++] = row;
	fillStack[fillStackIndex++] = col;

	while (fillStackIndex > 0) {
		//--------------------------------
		// Pop 'em in the reverse order...
		long col = fillStack[--fillStackIndex];
		long row = fillStack[--fillStackIndex];

		bool filling = true;
		
		if ((row < 0) || (row >= GameMap->height) || (col < 0) || (col >= GameMap->width))
			filling = false;
		
//		long overlay = GameMap->getOverlay(row, col);
//		if ((overlay == OVERLAY_WATER_BRIDGE_EW) || (overlay == OVERLAY_WATER_BRIDGE_NS))
//			filling = false;
		
		if (GameMap->getWall(row, col) || GameMap->getGate(row, col))
			filling = false;
		
		if (!GameMap->getPassable(row, col)) {
			regionMap[row][col] = -2;
			filling = false;
		}
		
		if (filling) {
			regionMap[row][col] = region;
			for (long dir = 0; dir < 4; dir ++) {
				long adjR = row + adjCell[dir][0];
				long adjC = col + adjCell[dir][1];
				if ((adjR >= 0) && (adjR < GameMap->height) && (adjC >= 0) && (adjC < GameMap->width))
					if (regionMap[adjR][adjC] == -1) {
						//--------------------------------------------
						// Cell hasn't been visited yet, so push it...
						fillStack[fillStackIndex++] = adjR;
						fillStack[fillStackIndex++] = adjC;
						//----------------------------------------------------------------
						// Mark the cell as on the stack (so we do not push it again if we
						// hit it before popping it)...
						regionMap[adjR][adjC] = -3;
					}
			}
		}
	}
	return(true);
#else
	if ((row < 0) || (row >= GameMap->height) || (col < 0) || (col >= GameMap->width))
		return(false);

	//----------------------------------------------------------------------
	// If we hit a bridge cell, politely stop expanding this area into it...
	long overlay = GameMap->getOverlay(row, col);
	if ((overlay == OVERLAY_WATER_BRIDGE_EW) || (overlay == OVERLAY_WATER_BRIDGE_NS))
		return(false);

	if (GameMap->getWall(row, col) || GameMap->getGate(row, col))
		return(false);

	if (!GameMap->getPassable(row, col)) {
		regionMap[row][col] = -2;
		return(false);
	}

	regionMap[row][col] = region;
	for (long dir = 0; dir < 4; dir ++) {
		long adjR = row + adjCell[dir][0];
		long adjC = col + adjCell[dir][1];
		if ((adjR >= 0) && (adjR < GameMap->height) && (adjC >= 0) && (adjC < GameMap->width))
			if (regionMap[adjR][adjC] == -1)
				fillRegion(adjR, adjC, region);
	}
	
	return(true);
#endif
}
Esempio n. 8
0
 void fillRegion(size_t col, size_t row, char new_color)
 {
     if (pixels_[row - 1][col - 1] != new_color) {
         fillRegion(col - 1, row - 1, new_color, pixels_[row - 1][col - 1]);
     }
 }
// deal with unmatched region
void dealUnMatchedRegion(const Mat& srcImg, const vector<vector<Point2f>>& srcPointsTab, const vector<vector<Point2f>>& srcFeaturesTab, const vector<int>& srcLabels, vector<int>& isMatched, vector<Mat>& transforms )
{
	int regionum = transforms.size();
	int width = srcImg.size().width;
	int height = srcImg.size().height;

	vector<Scalar> means(regionum);
	computeMeans(srcImg, srcPointsTab, means);
	vector<Point2f> centers(regionum);
	computeCenters(srcPointsTab, centers);

	vector<vector<int>> colorNeighbors(regionum);
	buildColorNeighbors(means, colorNeighbors);
		
	//处理未匹配的区域
	for (int i = 0; i < regionum; ++ i)
	{
		if (isMatched[i] != 0) continue;
		
		//集合颜色相近的特征点
		int reIdx = i;
		vector<Point2f> nearFeatures(0);
		for (int j = 0; j < colorNeighbors[i].size(); ++j)
		{
			int nearIdx = colorNeighbors[i][j];
			
			const vector<Point2f>& nearReFts = srcFeaturesTab[nearIdx];
			copy(nearReFts.begin(), nearReFts.end(), std::back_inserter(nearFeatures));
		}

		//颜色相近的特征点找最近的点
		Point2f nearest;
		bool isFind = findNearestPoint(nearFeatures, centers[reIdx], nearest);
		if (isFind == true)
		{
			int nearIdx = srcLabels[(int)nearest.y * width + (int)nearest.x];
			transforms[reIdx] = transforms[nearIdx].clone();
			isMatched[reIdx] =  isMatched[nearIdx];

			// debug : 显示最近区域
			cout << i << "-th unmatched region: the nearest one is " << nearIdx << endl;
			
			Mat test = Mat::zeros(height, width, CV_8UC3);
			fillRegion(srcPointsTab[i], means[i], test);
			circle(test, centers[i], 5, cv::Scalar(255,255,255));
			
			for (int j = 0; j < colorNeighbors[i].size(); ++ j)
			{
				int nearIdx = colorNeighbors[i][j];
				fillRegion(srcPointsTab[nearIdx], means[nearIdx], test);
			}			
			circle(test, centers[nearIdx], 5, cv::Scalar(255, 255, 255));
			
			string savefn = "output/near_regions_" + type2string(i) + ".png";
			imwrite(savefn, test);
			//显示结束
		}
		else
		{
			cout << i << "-th unmatched region: no similar colored region." << endl;
		}		
	}
}
void GBufferedImage::fillRegion(double x, double y, double width, double height, std::string rgb) {
    fillRegion(x, y, width, height, convertColorToRGB(rgb));
}