2, . , 2 . 4 . 1/3 , mip-maps.
, , , . , , , - .
-:
int getMax(Rect query_rect, int level, int level_x, int level_y)
{
int level_factor = 1 << level;
Rect level_rect(level_x * level_factor, level_y * level_factor,
(level_x + 1) * level_factor, (level_y + 1) * level_factor);
if(!query_rect.intersects(level_rect))
return -1;
if(query_rect.contains(level_rect))
return pyramid[level][level_x][level_y];
if(level == 0)
return -1;
int max = getMax(query_rect, level - 1, level_x * 2, level_y * 2);
max = maxValue(max, getMax(query_rect, level - 1, (level_x * 2) + 1, level_y * 2);
max = maxValue(max, getMax(query_rect, level - 1, level_x * 2, (level_y * 2) + 1);
max = maxValue(max, getMax(query_rect, level - 1, (level_x * 2) + 1, (level_y * 2) + 1);
return max;
}
( capx 1x1 ):
int max = getMax(query_rect, 10, 0, 0);
, . , .