@@ -15,8 +15,7 @@ | |||
namespace lol | |||
{ | |||
template<int N, /* Dimension of the space */ | |||
typename T = float> /* Interpolated type */ | |||
template<int N> | |||
class simplex_interpolator | |||
{ | |||
public: | |||
@@ -38,7 +37,7 @@ public: | |||
} | |||
// Single interpolation | |||
inline T Interp(vec_t<float, N> position) const | |||
inline float Interp(vec_t<float, N> position) const | |||
{ | |||
// Computing position in simplex referential | |||
vec_t<float, N> simplex_position = m_base_inverse * position; | |||
@@ -49,7 +48,7 @@ public: | |||
this->ExtractFloorDecimal(simplex_position, floor_point, decimal_point); | |||
vec_t<float, N> index_order = this->GetIndexOrder(decimal_point); | |||
vec_t<int, N> index_order = this->GetIndexOrder(decimal_point); | |||
// Resetting decimal point in regular orthonormal coordinates | |||
decimal_point = m_base * decimal_point; | |||
@@ -59,9 +58,9 @@ public: | |||
protected: | |||
inline T LastInterp(vec_t<int, N> const & floor_point, | |||
inline float LastInterp(vec_t<int, N> & floor_point, | |||
vec_t<float, N> const & decimal_point, | |||
vec_t<float, N> index_order) const | |||
vec_t<int, N> index_order) const | |||
{ | |||
vec_t<float, N> point_of_interest; | |||
float result = 0; | |||
@@ -83,7 +82,7 @@ protected: | |||
return result; | |||
} | |||
inline vec_t<int, N> GetIndexOrder(vec_t<float, N> const & decimal_point) | |||
inline vec_t<int, N> GetIndexOrder(vec_t<float, N> const & decimal_point) const | |||
{ | |||
vec_t<int, N> result; | |||
for (int i = 0 ; i < N ; ++i) | |||
@@ -19,13 +19,13 @@ | |||
namespace lol | |||
{ | |||
template<int N, typename T = float> | |||
class test_interpolator : public simplex_interpolator<N, T> | |||
template<int N> | |||
class test_interpolator : public simplex_interpolator<N> | |||
{ | |||
public: | |||
test_interpolator() : | |||
simplex_interpolator<N, T>() | |||
simplex_interpolator<N>() | |||
{ | |||
} | |||
@@ -86,7 +86,7 @@ public: | |||
vec_t<int, N> GetIndexOrder(vec_t<float, N> const & decimal_point) | |||
{ | |||
return simplex_interpolator<N, T>::GetIndexOrder(decimal_point); | |||
return simplex_interpolator<N>::GetIndexOrder(decimal_point); | |||
} | |||
}; | |||
@@ -96,12 +96,6 @@ lolunit_declare_fixture(SimplexInterpolatorTest) | |||
void TearDown() {} | |||
// lolunit_declare_test(CompoundVariable) | |||
// { | |||
// test_interpolator<2, real> b({{ real(0) }}); | |||
// test_interpolator<2, vec2> c({{ vec2(0) }}); | |||
// } | |||
template<int N> | |||
void check_base_matrix() | |||
{ | |||
@@ -210,6 +204,28 @@ lolunit_declare_fixture(SimplexInterpolatorTest) | |||
check_index_ordering<10>(); | |||
} | |||
void check_sample_creation_order2() | |||
{ | |||
static int gen = 12345678; | |||
arraynd<2, vec_t<float, 2> > gradients(vec_t<ptrdiff_t, 2>({10, 10})); | |||
for (int i = 0 ; i < 10 ; ++i) | |||
{ | |||
for (int j = 0 ; j < 10 ; ++j) | |||
{ | |||
float x1 = (gen = gen * gen + gen) % 255; | |||
float x2 = (gen = gen * gen + gen) % 255; | |||
vec_t<float, 2> v = {x1, x2}; | |||
gradients[i][j] = v; | |||
} | |||
} | |||
simplex_interpolator<2> s; | |||
s.SetGradients(gradients); | |||
} | |||
#if 0 | |||
lolunit_declare_test(FloatGridPoints2D1x1) | |||
{ | |||