Commit d51c1dec authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

#19. reducing clear_connected_component arguments to avoid stack overflow.

parent fb54bef4
Pipeline #13796 passed with stages
in 21 minutes
......@@ -24,6 +24,9 @@ class MarchingSquares
std::vector<short> mBit;
size_t mRows;
size_t mColumns;
size_t depth;
size_t mLabel;
data_type mWashBit;
enum class StepDirection
{
......@@ -50,8 +53,7 @@ class MarchingSquares
*/
void step(size_t r, size_t c);
bool accepts(size_t r, size_t c) const;
void clear_connected_component(int x, int y, size_t label,
data_type wash_bit);
void clear_connected_component(int x, int y);
public:
/**
......
......@@ -9,22 +9,25 @@
namespace radix
{
template <typename data_type>
void MarchingSquares<data_type>::clear_connected_component(int x, int y,
size_t label,
data_type wash_bit)
void MarchingSquares<data_type>::clear_connected_component(int x, int y)
{
if (x < 0 || x == mColumns) return; // out of bounds
if (y < 0 || y == mRows) return; // out of bounds
depth++;
size_t c_i = mColumns * y + x;
if (mBit[c_i] == label)
if (mBit[c_i] == mLabel)
{
// clear the data
mBit[c_i] = 0;
mData[c_i] = wash_bit;
mData[c_i] = mWashBit;
for (int direction = 0; direction < 4; ++direction)
clear_connected_component(x + dx[direction], y + dy[direction], label,
wash_bit);
{
size_t nx = x + dx[direction];
size_t ny = y + dy[direction];
clear_connected_component(nx, ny);
}
}
depth--;
}
template <typename data_type>
......@@ -60,6 +63,8 @@ std::vector<std::pair<int, int>> MarchingSquares<data_type>::march(
mBit[p_i] = 2;
}
}
mWashBit = wash_bit;
mLabel = mBit[mColumns * start.first + start.second];
//
// Walk the perimeter
......@@ -93,9 +98,8 @@ std::vector<std::pair<int, int>> MarchingSquares<data_type>::march(
}
} while (row != start.first || column != start.second);
clear_connected_component(start.second, start.first,
mBit[mColumns * start.first + start.second],
wash_bit);
depth = 0;
clear_connected_component(start.second, start.first);
return out;
} // march
......
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