瀏覽代碼

simplex_interpolator: initializing interpolator with the samples so that it can be fully usable at creation.

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 10 年之前
父節點
當前提交
4118789a53
共有 2 個文件被更改,包括 14 次插入16 次删除
  1. +13
    -13
      src/lol/math/simplex_interpolator.h
  2. +1
    -3
      src/t/math/simplex_interpolator.cpp

+ 13
- 13
src/lol/math/simplex_interpolator.h 查看文件

@@ -20,14 +20,15 @@ class simplex_interpolator
{
public:

simplex_interpolator()
simplex_interpolator(arraynd<N, T> const & samples) :
m_samples(samples)
{
this->InitBase();
}

inline arraynd<N, T> & GetSamples()
inline arraynd<N, T> const & GetSamples()
{
return this->samples;
return this->m_samples;
}

// Single interpolation
@@ -63,14 +64,14 @@ protected:
vec_t<int, N> samples_index = floor_point;
samples_index[i] = this->Mod(samples_index[i] + sign, i);

result += decimal_point[i] * this->samples[samples_index];
result += decimal_point[i] * this->m_samples[samples_index];
floor_coeff += decimal_point[i];
divider += decimal_point[i];
}

T norm = sqrt((float)N);

result += (1 - 2 * floor_coeff / (norm * norm)) * this->samples[floor_point];
result += (1 - 2 * floor_coeff / (norm * norm)) * this->m_samples[floor_point];
divider += (1 - 2 * floor_coeff / (norm * norm));

return result / divider;
@@ -78,7 +79,7 @@ protected:

inline int Mod(int value, int index)
{
return value %= this->samples.GetSize()[index];
return value %= this->m_samples.GetSize()[index];
}

inline void GetReference(vec_t<int, N> & floor_point, vec_t<T, N> & decimal_point, int & sign)
@@ -122,7 +123,7 @@ protected:

for (int i = 0 ; i < N ; ++i)
for (int j = 0 ; j < N ; ++j)
result[i] += this->base_inverse[j][i] * position[j];
result[i] += this->m_base_inverse[j][i] * position[j];

return result;
}
@@ -133,17 +134,16 @@ protected:
{
for (int j = i ; j < N ; ++j)
{
this->base[j][i] = sqrt((i+2)/((float)(2*i+2))) / (j > i ? i+2 : 1);
this->base_inverse[j][i] = sqrt((2*j+2) / ((float)(j+2))) * (j > i ? (-1 / (float)(j+1)) : 1);
this->m_base[j][i] = sqrt((i+2)/((float)(2*i+2))) / (j > i ? i+2 : 1);
this->m_base_inverse[j][i] = sqrt((2*j+2) / ((float)(j+2))) * (j > i ? (-1 / (float)(j+1)) : 1);
}
}
}

vec_t<vec_t<T, N>, N> base;
vec_t<vec_t<T, N>, N> base_inverse;

arraynd<N, T> samples;
vec_t<vec_t<T, N>, N> m_base;
vec_t<vec_t<T, N>, N> m_base_inverse;

arraynd<N, T> m_samples;
};

}

+ 1
- 3
src/t/math/simplex_interpolator.cpp 查看文件

@@ -25,9 +25,7 @@ lolunit_declare_fixture(SimplexInterpolatorTest)

lolunit_declare_test(Interp2D9PointsTest)
{
simplex_interpolator<2> interpolator;

interpolator.GetSamples() = arraynd<2, float>({{1, 1, 2}, {1, 2, 2}, {2, 2, 2}});
simplex_interpolator<2> interpolator({{1, 1, 2}, {1, 2, 2}, {2, 2, 2}});

lolunit_assert_equal(interpolator.Interp(vec_t<float, 2>{0, 0}), 1);
lolunit_assert_equal(interpolator.Interp(vec_t<float, 2>{1, 0}), 1);


Loading…
取消
儲存