Commit 50bb82c7 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Updating marchingsquares to complete the polygon returned. Further work on chaikins method.

parent 3d6fd6d3
Pipeline #16077 canceled with stages
in 181 minutes and 32 seconds
#include <iomanip>
#include <set>
#include <vector>
......@@ -15,19 +16,25 @@ std::vector<std::pair<data_type, data_type>> chaikins(
translate,
size_t sequence)
{
std::vector<std::pair<data_type, data_type>> result(control_polygon.size() *
(sequence));
for (size_t pi = 0; pi < control_polygon.size(); pi += 2)
std::vector<std::pair<data_type, data_type>> result(
2 * control_polygon.size() - 2);
for (size_t pi = 0; pi < control_polygon.size(); ++pi)
{
// break if this is the last point
if (pi == control_polygon.size() - 1) break;
std::pair<data_type, data_type> p1 = translate(control_polygon[pi]);
std::pair<data_type, data_type> p2 = translate(control_polygon[pi + 1]);
std::pair<data_type, data_type> qi = std::make_pair(
p1.first * .75 + p2.first * .25, p1.second * .75 + p2.second * .25);
std::pair<data_type, data_type> ri = std::make_pair(
p1.first * .25 + p2.first * .75, p1.second * .25 + p2.second * .75);
result[pi] = qi;
result[pi + 1] = ri;
// char buf[80];
// sprintf(buf, "%.2f,%.2f", qi.first, qi.second);
// radix_line("\t{" << buf << "},");
// sprintf(buf, "%.2f,%.2f", ri.first, ri.second);
// radix_line("\t{" << buf << "},");
result[2 * pi] = qi;
result[2 * pi + 1] = ri;
}
return result;
}
......
......@@ -76,7 +76,7 @@ std::vector<std::pair<int, int>> MarchingSquares<data_type>::march(
for (size_t p_i = 0; p_i < data_size; ++p_i)
{
// select data as 1 if greater than isovalue
data_type value = mData[p_i];
data_type value = mData[p_i];
if (value >= isovalue && value < wash_threshold)
{
mBit[p_i] = 1;
......@@ -122,6 +122,10 @@ std::vector<std::pair<int, int>> MarchingSquares<data_type>::march(
}
} while (row != start.first || column != start.second);
//
// Finish connecting the contour by making the last=first
out.push_back(start);
clear_connected_component(start.first, start.second,
mBit[mColumns * start.first + start.second],
wash_bit);
......@@ -137,7 +141,7 @@ bool MarchingSquares<data_type>::starting_point(
size_t data_size = mData.size();
for (size_t i = 0; i < data_size; ++i)
{
data_type value = mData[i];
data_type value = mData[i];
if (value >= isovalue && value < wash_threshold)
{
// save the row
......
......@@ -15,7 +15,7 @@ TEST(RadixChaikins, Simple)
{3, 8}, {3, 9}, {4, 9}, {4, 10}, {4, 11}, {5, 11}, {5, 12}, {5, 13},
{6, 13}, {7, 13}, {8, 13}, {8, 12}, {8, 11}, {8, 10}, {8, 9}, {8, 8},
{8, 7}, {8, 6}, {8, 5}, {8, 4}, {8, 3}, {8, 2}, {7, 2}, {6, 2},
{5, 2}, {4, 2}, {3, 2}, {2, 2}};
{5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}};
auto tranlate = [](const std::pair<int, int>& point) {
// tranlate index into 10x10m grid
......@@ -25,49 +25,42 @@ TEST(RadixChaikins, Simple)
std::vector<std::pair<float, float>> results =
chaikins<float>(control_polygon, tranlate);
size_t i = 0;
for (const auto& point : results)
std::vector<std::pair<float, float>> blessed{
{10.00, 22.50}, {10.00, 27.50}, {10.00, 32.50}, {10.00, 37.50},
{12.50, 40.00}, {17.50, 40.00}, {22.50, 40.00}, {27.50, 40.00},
{32.50, 40.00}, {37.50, 40.00}, {40.00, 37.50}, {40.00, 32.50},
{42.50, 30.00}, {47.50, 30.00}, {52.50, 30.00}, {57.50, 30.00},
{62.50, 30.00}, {67.50, 30.00}, {70.00, 32.50}, {70.00, 37.50},
{70.00, 42.50}, {70.00, 47.50}, {70.00, 52.50}, {70.00, 57.50},
{70.00, 62.50}, {70.00, 67.50}, {70.00, 72.50}, {70.00, 77.50},
{70.00, 82.50}, {70.00, 87.50}, {70.00, 92.50}, {70.00, 97.50},
{70.00, 102.50}, {70.00, 107.50}, {67.50, 110.00}, {62.50, 110.00},
{60.00, 107.50}, {60.00, 102.50}, {57.50, 100.00}, {52.50, 100.00},
{50.00, 97.50}, {50.00, 92.50}, {50.00, 87.50}, {50.00, 82.50},
{47.50, 80.00}, {42.50, 80.00}, {40.00, 77.50}, {40.00, 72.50},
{40.00, 67.50}, {40.00, 62.50}, {37.50, 60.00}, {32.50, 60.00},
{30.00, 57.50}, {30.00, 52.50}, {27.50, 50.00}, {22.50, 50.00},
{20.00, 52.50}, {20.00, 57.50}, {20.00, 62.50}, {20.00, 67.50},
{22.50, 70.00}, {27.50, 70.00}, {30.00, 72.50}, {30.00, 77.50},
{30.00, 82.50}, {30.00, 87.50}, {32.50, 90.00}, {37.50, 90.00},
{40.00, 92.50}, {40.00, 97.50}, {40.00, 102.50}, {40.00, 107.50},
{42.50, 110.00}, {47.50, 110.00}, {50.00, 112.50}, {50.00, 117.50},
{50.00, 122.50}, {50.00, 127.50}, {52.50, 130.00}, {57.50, 130.00},
{62.50, 130.00}, {67.50, 130.00}, {72.50, 130.00}, {77.50, 130.00},
{80.00, 127.50}, {80.00, 122.50}, {80.00, 117.50}, {80.00, 112.50},
{80.00, 107.50}, {80.00, 102.50}, {80.00, 97.50}, {80.00, 92.50},
{80.00, 87.50}, {80.00, 82.50}, {80.00, 77.50}, {80.00, 72.50},
{80.00, 67.50}, {80.00, 62.50}, {80.00, 57.50}, {80.00, 52.50},
{80.00, 47.50}, {80.00, 42.50}, {80.00, 37.50}, {80.00, 32.50},
{80.00, 27.50}, {80.00, 22.50}, {77.50, 20.00}, {72.50, 20.00},
{67.50, 20.00}, {62.50, 20.00}, {57.50, 20.00}, {52.50, 20.00},
{47.50, 20.00}, {42.50, 20.00}, {37.50, 20.00}, {32.50, 20.00},
{27.50, 20.00}, {22.50, 20.00}, {17.50, 20.00}, {12.50, 20.00}};
radix_tagged_line("Number of polygon points (" << results.size() << ")");
ASSERT_EQ(blessed.size(), (2 * control_polygon.size()) - 2);
ASSERT_EQ(blessed.size(), results.size());
for (size_t i = 0; i < blessed.size(); ++i)
{
std::cout << i << ". [" << point.first << "," << point.second << "]"
<< std::endl;
i++;
EXPECT_EQ(blessed[i], results[i]);
}
std::vector<std::pair<float, float>> blessed{
{10.f, 20.f}, {10.f, 30.f}, {10.f, 40.f}, {20.f, 40.f}, {30.f, 40.f},
{40.f, 40.f}, {40.f, 30.f}, {50.f, 30.f}, {60.f, 30.f}, {70.f, 30.f},
{70.f, 40.f}, {70.f, 50.f}, {70.f, 60.f}, {70.f, 70.f}, {70.f, 80.f},
{70.f, 90.f}, {70.f, 100.f}, {70.f, 110.f}, {60.f, 110.f}, {60.f, 100.f},
{50.f, 100.f}, {50.f, 90.f}, {50.f, 80.f}, {40.f, 80.f}, {40.f, 70.f},
{40.f, 60.f}, {30.f, 60.f}, {30.f, 50.f}, {20.f, 50.f}, {20.f, 60.f},
{20.f, 70.f}, {30.f, 70.f}, {30.f, 80.f}, {30.f, 90.f}, {40.f, 90.f},
{40.f, 100.f}, {40.f, 110.f}, {50.f, 110.f}, {50.f, 120.f}, {50.f, 130.f},
{60.f, 130.f}, {70.f, 130.f}, {80.f, 130.f}, {80.f, 120.f}, {80.f, 110.f},
{80.f, 100.f}, {80.f, 90.f}, {80.f, 80.f}, {80.f, 70.f}, {80.f, 60.f},
{80.f, 50.f}, {80.f, 40.f}, {80.f, 30.f}, {80.f, 20.f}, {70.f, 20.f},
{60.f, 20.f}, {50.f, 20.f}, {40.f, 20.f}, {30.f, 20.f}, {20.f, 20.f}};
}
TEST(RadixChaikins, TwoGroups)
{
std::vector<double> grid{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 2,
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 2, 2, 2,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::vector<std::pair<int, int>> first_blessed{
{1, 2}, {1, 3}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {4, 3}, {5, 3},
{6, 3}, {7, 3}, {7, 4}, {7, 5}, {7, 6}, {7, 7}, {7, 8}, {7, 9},
{7, 10}, {7, 11}, {6, 11}, {6, 10}, {5, 10}, {5, 9}, {5, 8}, {4, 8},
{4, 7}, {4, 6}, {3, 6}, {3, 5}, {2, 5}, {2, 6}, {2, 7}, {3, 7},
{3, 8}, {3, 9}, {4, 9}, {4, 10}, {4, 11}, {5, 11}, {5, 12}, {5, 13},
{6, 13}, {7, 13}, {8, 13}, {8, 12}, {8, 11}, {8, 10}, {8, 9}, {8, 8},
{8, 7}, {8, 6}, {8, 5}, {8, 4}, {8, 3}, {8, 2}, {7, 2}, {6, 2},
{5, 2}, {4, 2}, {3, 2}, {2, 2}};
}
......@@ -46,7 +46,7 @@ TEST(MarchingSquares, Simple)
{3, 8}, {3, 9}, {4, 9}, {4, 10}, {4, 11}, {5, 11}, {5, 12}, {5, 13},
{6, 13}, {7, 13}, {8, 13}, {8, 12}, {8, 11}, {8, 10}, {8, 9}, {8, 8},
{8, 7}, {8, 6}, {8, 5}, {8, 4}, {8, 3}, {8, 2}, {7, 2}, {6, 2},
{5, 2}, {4, 2}, {3, 2}, {2, 2}};
{5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}};
ASSERT_EQ(blessed.size(), contour.size());
for (size_t i = 0; i < blessed.size(); ++i)
......@@ -84,7 +84,7 @@ TEST(MarchingSquares, TwoGroups)
{3, 8}, {3, 9}, {4, 9}, {4, 10}, {4, 11}, {5, 11}, {5, 12}, {5, 13},
{6, 13}, {7, 13}, {8, 13}, {8, 12}, {8, 11}, {8, 10}, {8, 9}, {8, 8},
{8, 7}, {8, 6}, {8, 5}, {8, 4}, {8, 3}, {8, 2}, {7, 2}, {6, 2},
{5, 2}, {4, 2}, {3, 2}, {2, 2}};
{5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}};
// std::cout << "{" << std::endl;
// for (size_t i = 0; i < first_contour.size(); ++i)
// {
......@@ -119,8 +119,9 @@ TEST(MarchingSquares, TwoGroups)
// std::cout << std::endl;
// }
// std::cout << "}" << std::endl;
std::vector<std::pair<int, int>> second_blessed{
{7, 16}, {7, 17}, {7, 18}, {8, 18}, {9, 18}, {9, 17}, {9, 16}, {8, 16}};
std::vector<std::pair<int, int>> second_blessed{{7, 16}, {7, 17}, {7, 18},
{8, 18}, {9, 18}, {9, 17},
{9, 16}, {8, 16}, {7, 16}};
ASSERT_EQ(second_blessed.size(), second_contour.size());
for (size_t i = 0; i < second_blessed.size(); ++i)
{
......@@ -165,8 +166,8 @@ TEST(MarchingSquares, 4EdgeGroups)
// }
// std::cout << "}" << std::endl;
std::vector<std::pair<int, int>> blessed{
{2, 0}, {2, 1}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {6, 2}, {7, 2},
{8, 2}, {8, 1}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}};
{2, 0}, {2, 1}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {6, 2}, {7, 2}, {8, 2},
{8, 1}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}};
ASSERT_EQ(blessed.size(), contour.size());
for (size_t i = 0; i < blessed.size(); ++i)
......@@ -191,9 +192,9 @@ TEST(MarchingSquares, 4EdgeGroups)
// }
// std::cout << "}" << std::endl;
std::vector<std::pair<int, int>> blessed{
{6, 6}, {6, 7}, {6, 8}, {7, 8}, {8, 8}, {9, 8},
{10, 8}, {10, 7}, {10, 6}, {10, 5}, {10, 4}, {10, 3},
{9, 3}, {9, 4}, {9, 5}, {9, 6}, {8, 6}, {7, 6}};
{6, 6}, {6, 7}, {6, 8}, {7, 8}, {8, 8}, {9, 8}, {10, 8},
{10, 7}, {10, 6}, {10, 5}, {10, 4}, {10, 3}, {9, 3}, {9, 4},
{9, 5}, {9, 6}, {8, 6}, {7, 6}, {6, 6}};
ASSERT_EQ(blessed.size(), contour.size());
for (size_t i = 0; i < blessed.size(); ++i)
......@@ -218,9 +219,9 @@ TEST(MarchingSquares, 4EdgeGroups)
// }
// std::cout << "}" << std::endl;
std::vector<std::pair<int, int>> blessed{
{4, 18}, {4, 19}, {4, 20}, {5, 20}, {6, 20}, {6, 19},
{7, 19}, {8, 19}, {8, 20}, {9, 20}, {9, 19}, {9, 18},
{8, 18}, {8, 17}, {7, 17}, {6, 17}, {5, 17}, {5, 18}};
{4, 18}, {4, 19}, {4, 20}, {5, 20}, {6, 20}, {6, 19}, {7, 19},
{8, 19}, {8, 20}, {9, 20}, {9, 19}, {9, 18}, {8, 18}, {8, 17},
{7, 17}, {6, 17}, {5, 17}, {5, 18}, {4, 18}};
ASSERT_EQ(blessed.size(), contour.size());
for (size_t i = 0; i < blessed.size(); ++i)
......@@ -246,7 +247,7 @@ TEST(MarchingSquares, 4EdgeGroups)
// std::cout << "}" << std::endl;
std::vector<std::pair<int, int>> blessed{{0, 14}, {0, 15}, {0, 16}, {0, 17},
{1, 17}, {2, 17}, {2, 16}, {2, 15},
{2, 14}, {1, 14}};
{2, 14}, {1, 14}, {0, 14}};
ASSERT_EQ(blessed.size(), contour.size());
for (size_t i = 0; i < blessed.size(); ++i)
......
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