Commit 407e4915 by Jordan P. Lefebvre

### WIP #14. Initial MarchingSquares algorithm. Working on connected component...

`WIP #14. Initial MarchingSquares algorithm. Working on connected component labeling detect multiple groups.`
parent 0d076c9f
Pipeline #11525 passed with stages
in 4 minutes and 35 seconds
 #ifndef RADIX_RADIXALGORITHM_MARCHINGSQUARES_HH_ #define RADIX_RADIXALGORITHM_MARCHINGSQUARES_HH_ #include #include #include #include #include "radixbug/bug.hh" namespace radix { template void marching_squares(const std::vector& points, std::vector& out, size_t rows, size_t cols, data_type isovalue, sign_type negative = 0, sign_type positive = 1); template class MarchingSquares { protected: std::vector mData; std::vector mBit; std::vector mComponent; size_t mRows; size_t mColumns; enum class StepDirection { Up, Down, Right, Left, None }; StepDirection next_step; StepDirection prev_step; /** * @brief starting_point find a starting position which matches or exceeds * isovalue * @param pos std::pair aka * @return bool true if a position was found */ bool starting_point(std::pair& pos) const; /** * @brief step Performs a step in the march * @param r row aka y index * @param c column aka x index */ void step(size_t r, size_t c); bool accepts(size_t r, size_t c) const; void union_coords(size_t r1, size_t c1, size_t r2, size_t c2) { size_t first = mColumns * c1 + r1; size_t second = mColumns * c2 + r2; if (r2 < mRows && c2 < mColumns && mBit[first] && mBit[second]) do_union(int(first), int(second)); } void do_union(int a, int b) { // get the root component of a and b, and set the one's parent to the other while (mComponent[a] != a) a = mComponent[a]; while (mComponent[b] != b) b = mComponent[b]; mComponent[b] = a; } public: /** * @brief MarchingSquares * @param data const std::vector 1D representation of 2D data * @param rows number of rows, aka y size * @param columns number of columns, aka x size */ MarchingSquares(const std::vector& data, size_t rows, size_t columns) : mData(data) , mBit(data.size(), 0) , mComponent(data.size()) , mRows(rows) , mColumns(columns) { radix_line("MarchingSquares data size(" << data.size() << ")"); radix_check(data.size() == (rows * columns)); } /** * @brief march March the data on the isovalue threshold. Can be called * multiple times for multiple grouping at threshold. * @param isovalue the threshold value of the data * @param wash_bit the value that replace all data matchings isovalue * @param wash_threshold the threshold to which washing shouldn't apply. * Primary use in multi-contour requests. * @return std::vector> listing of all x,y indices, aka * a closed polygon */ std::vector> march( data_type isovalue, data_type wash_bit = {0}, data_type wash_threshold = std::numeric_limits::max()); }; // class } // namespace /** Include implementation file */ ... ...