我的想法,有两个决策选项:
我用某种伪代码写的..
基本上,对于第一个选项,您决定您的区域必须遵守的百分比以满足最小脏像素数。
对于第二个选项,如果您扩展以包含该像素,则您决定该因子或每个区域的脏像素的差异是否变化太大。
struct DirtyPixelArea
{
Vec2 topLeft;
Vec2 size;
list<Vec2> dirtyPixels;
void AddPixelToArea();
int Area();
int DirtyPixelsArea(); // sums all dirty pixels in area
};
list<DirtyPixelArea> dirtyPixelsAreaList
void add_dirty_pixel(Vec2 dirtyPixel)
{
closest_area = find_closest_area_to_pixel(dirtyPixel).copy();
//option 1 - begin
closest_area.add_dirty_pixel(dirtyPixel);
if (closest_area.DirtyPixelsArea() > (closest_area.Area() * 0.25)) // you can experiment on choosing your own dirty pixel factor
{
update_area_in_list(closest_area);
}
else
{
new_area = new DirtyPixelArea();
new_area.AddPixelToArea(dirtyPixel);
add_area_in_list(new_area);
}
//option 1 - end
// option 2 - begin
original_area = find_closest_area_to_pixel(dirtyPixel);
closest_area.add_dirty_pixel(dirtyPixel)
original_area_factor = original_area.DirtyPixelsArea() / original_area.Area();
closest_area_factor = closest_area.DirtyPixelArea() / closest_area.Area();
if ( closest_area_factor / original_area_factor > 0.5)
{
update_area_in_list(closest_area);
}
else
{
new_area = new DirtyPixelArea();
new_area.AddPixelToArea(dirtyPixel);
add_area_in_list(new_area);
}
// option 2 - end
}