Commit 1d33c019 authored by mjg226's avatar mjg226
Browse files

bug fix asciigrid

added simple upscaling to CellBuff
parent a3e53b6a
......@@ -375,23 +375,74 @@ namespace CA {
// Check that the given memory location is big enough to contain
// the data of the region.
if(box.w() > mem_x_size || box.h() > mem_y_size)
if(box.w() < mem_x_size || box.h() < mem_y_size)
return;
// Cycle through the region of cells to read. i_reg and j_reg are
// the region indices. i_mem and j_mem are the memory indices. The
// _border value is used to avoid reading the border.
for(Unsigned j_reg=box.y()+_cagrid.cb_border, j_mem=0;
j_reg<box.h()+box.y()+_cagrid.cb_border; ++j_reg, ++j_mem)
if (box.w() > mem_x_size || box.h() > mem_y_size)
{
for(Unsigned i_reg=box.x()+_cagrid.cb_border, i_mem=0;
i_reg<box.w()+box.x()+_cagrid.cb_border; ++i_reg, ++i_mem)
{
_buff[j_reg *_cagrid.cb_x_size + i_reg] = mem[j_mem * mem_x_size + i_mem];
}
}
}
// upsample, assuming it is a clean upsampling
int x_scale = box.w() / mem_x_size;
int y_scale = box.h() / mem_y_size;
double x_scale_check = box.w() / mem_x_size;
double y_scale_check = box.h() / mem_y_size;
if (x_scale != x_scale_check)
return;
if (y_scale != y_scale_check)
return;
//std::cout << "x_scale: " << x_scale << std::endl;
//std::cout << "y_scale: " << y_scale << std::endl;
// Cycle through the region of cells to read. i_reg and j_reg are
// the region indices. i_mem and j_mem are the memory indices. The
// _border value is used to avoid reading the border.
// i_box and j_box, are the region indicies within the box locally
for (Unsigned j_reg = box.y() + _cagrid.cb_border, j_mem = 0,j_box=0;
j_reg < box.h() + box.y() + _cagrid.cb_border; ++j_reg,++j_box)
{
if (j_box % y_scale == 0 && j_box != 0)
++j_mem;
for (Unsigned i_reg = box.x() + _cagrid.cb_border, i_mem = 0,i_box=0;
i_reg < box.w() + box.x() + _cagrid.cb_border; ++i_reg,++i_box)
{
if (i_box % x_scale == 0 && i_box != 0)
++i_mem;
_buff[j_reg * _cagrid.cb_x_size + i_reg] = mem[j_mem * mem_x_size + i_mem];
}
}
}
else {
// Cycle through the region of cells to read. i_reg and j_reg are
// the region indices. i_mem and j_mem are the memory indices. The
// _border value is used to avoid reading the border.
for (Unsigned j_reg = box.y() + _cagrid.cb_border, j_mem = 0;
j_reg < box.h() + box.y() + _cagrid.cb_border; ++j_reg, ++j_mem)
{
for (Unsigned i_reg = box.x() + _cagrid.cb_border, i_mem = 0;
i_reg < box.w() + box.x() + _cagrid.cb_border; ++i_reg, ++i_mem)
{
_buff[j_reg * _cagrid.cb_x_size + i_reg] = mem[j_mem * mem_x_size + i_mem];
}
}
}
}// end of insertData
template<typename T>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment