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

Starting work on the Chaikins method for curve creation.

parent cc970dac
......@@ -4,6 +4,8 @@ SET(SOURCE
ordering.cc
)
SET(HEADERS
chaikins.hh
chaikins.i.hh
ordering.hh
marchingsquares.hh
marchingsquares.i.hh
......
#ifndef RADIX_RADIXALGORITHM_CHAIKINS_HH_
#define RADIX_RADIXALGORITHM_CHAIKINS_HH_
#include <array>
#include <functional>
#include <iomanip>
#include <limits>
#include <memory>
#include <numeric>
#include <ostream>
#include <vector>
#include "radixbug/bug.hh"
namespace radix
{
template <typename data_type>
std::vector<std::pair<data_type, data_type>> chaikins(
const std::vector<std::pair<int, int>>& control_polygon,
std::function<
std::pair<data_type, data_type>(const std::pair<int, int>& point)>
translate =
[](const std::pair<int, int>& point) {
return std::make_pair(data_type(point.first),
data_type(point.second));
},
size_t sequence = 1);
} // namespace radix
/** Include implementation file */
#include "radixalgorithm/chaikins.i.hh"
#endif /** RADIX_RADIXALGORITHM_CHAIKINS_HH_ */
#include <set>
#include <vector>
#include "radixalgorithm/chaikins.hh"
#include "radixbug/bug.hh"
namespace radix
{
template <typename data_type>
std::vector<std::pair<data_type, data_type>> chaikins(
const std::vector<std::pair<int, int>>& control_polygon,
std::function<
std::pair<data_type, data_type>(const std::pair<int, int>& point)>
translate,
size_t sequence)
{
std::vector<std::pair<data_type, data_type>> result(control_polygon.size() *
(sequence + 1));
for (size_t si = 0; si < sequence; ++si)
{
}
return result;
}
} // namespace radix
#ifndef RADIX_RADIXALGORITHM_MARCHINGSQUARES_HH_
#define RADIX_RADIXALGORITHM_MARCHINGSQUARES_HH_
#include <array>
#include <iomanip>
#include <limits>
#include <memory>
......@@ -16,8 +17,8 @@ template <typename data_type>
class MarchingSquares
{
private:
std::vector<int> dx;
std::vector<int> dy;
std::array<int, 4> dx;
std::array<int, 4> dy;
protected:
std::vector<data_type> mData;
......
......@@ -2,3 +2,4 @@ INCLUDE(GoogleTest)
ADD_GOOGLE_TEST(tstOrdering.cc NP 1)
ADD_GOOGLE_TEST(tstMarchingSquares.cc NP 1)
ADD_GOOGLE_TEST(tstChaikins.cc NP 1)
#include <iostream>
#include "gtest/gtest.h"
#include "radixalgorithm/chaikins.hh"
#include "radixbug/bug.hh"
using namespace radix;
TEST(RadixChaikins, Simple)
{
std::vector<std::pair<int, int>> control_polygon{
{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}};
auto tranlate = [](const std::pair<int, int>& point) {
// tranlate index into 10x10m grid
return std::make_pair(10.f * float(point.first),
10.f * float(point.second));
};
std::vector<std::pair<float, float>> result =
chaikins<float>(control_polygon, tranlate);
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}};
}
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