Blame toonz/sources/stdfx/igs_gauss_distribution.cpp
|
Toshihiro Shimizu |
890ddd |
#include <cmath></cmath>
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Shinya Kitaoka |
120a6e |
center
|
|
Shinya Kitaoka |
120a6e |
V
|
|
Shinya Kitaoka |
120a6e |
sequence
|
|
Shinya Kitaoka |
120a6e |
0 1 2 ... int_diameter-1
|
|
Shinya Kitaoka |
120a6e |
v v v ... v
|
|
Shinya Kitaoka |
120a6e |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|
|
Shinya Kitaoka |
120a6e |
|<------------------- int_diameter(pixel) ----------------->|
|
|
Shinya Kitaoka |
120a6e |
|<--- int_radius(pixel) --->|
|
|
Shinya Kitaoka |
120a6e |
|<------ real_radius ----->|
|
|
Shinya Kitaoka |
120a6e |
|<- int_radius(pixel) ->|
|
|
Shinya Kitaoka |
120a6e |
|<---- real_radius --->|
|
|
Shinya Kitaoka |
120a6e |
|<-int_radius(pi) ->|
|
|
Shinya Kitaoka |
120a6e |
|<- real_radius -->|
|
|
Shinya Kitaoka |
120a6e |
|<-int_radius ->|
|
|
Shinya Kitaoka |
120a6e |
|<- real_rad ->|
|
|
Shinya Kitaoka |
120a6e |
|<- int ->|
|
|
Shinya Kitaoka |
120a6e |
|<- real ->|
|
|
Shinya Kitaoka |
120a6e |
|<- ->|
|
|
Shinya Kitaoka |
120a6e |
|<- ->|
|
|
Shinya Kitaoka |
120a6e |
|<->|
|
|
Shinya Kitaoka |
120a6e |
|<>|
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
void gauss_distribution_1d_(double *sequence,
|
|
Shinya Kitaoka |
120a6e |
const int int_diameter /* sequence配列の長さ */
|
|
Shinya Kitaoka |
120a6e |
,
|
|
Shinya Kitaoka |
120a6e |
const int int_radius, const double real_radius,
|
|
Shinya Kitaoka |
120a6e |
const double sigma /* = 0.25 : 適当な値... */
|
|
Shinya Kitaoka |
120a6e |
) {
|
|
Shinya Kitaoka |
120a6e |
/* メモリクリア */
|
|
Shinya Kitaoka |
120a6e |
for (int ii = 0; ii < int_diameter; ++ii) {
|
|
Shinya Kitaoka |
120a6e |
sequence[ii] = 0.0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* 半径がゼロでも計算を可能にする、強引に... */
|
|
Shinya Kitaoka |
120a6e |
const int int_radius2 = (0 < int_radius) ? int_radius : 1;
|
|
Shinya Kitaoka |
120a6e |
const double real_radius2 =
|
|
Shinya Kitaoka |
120a6e |
(0. < real_radius) ? real_radius : 0.000000000000001;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* 1pixel以下の調整
|
|
Shinya Kitaoka |
120a6e |
* -1.0の位置を(real_radius2)の位置とする */
|
|
Shinya Kitaoka |
120a6e |
double dd = -1.0 * int_radius2 / real_radius2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* 1pixel幅の差分 */
|
|
Shinya Kitaoka |
120a6e |
const double delta = -dd / int_radius2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* 開始位置 */
|
|
Shinya Kitaoka |
120a6e |
const int start_pos = (int_diameter - (int_radius2 * 2 + 1)) / 2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* 終了位置 */
|
|
Shinya Kitaoka |
120a6e |
const int end_pos = int_diameter - start_pos;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
/* ガウス分布 */
|
|
Shinya Kitaoka |
120a6e |
for (int ii = start_pos; ii < end_pos; ++ii) {
|
|
Shinya Kitaoka |
120a6e |
sequence[ii] = exp(-(dd * dd) / (2.0 * sigma * sigma));
|
|
Shinya Kitaoka |
120a6e |
dd += delta;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/* 積算 */
|
|
Shinya Kitaoka |
120a6e |
dd = 0.0;
|
|
Shinya Kitaoka |
120a6e |
for (int ii = start_pos; ii < end_pos; ++ii) {
|
|
Shinya Kitaoka |
120a6e |
dd += sequence[ii];
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
/* 正規化(積算結果が1となるように割算する) */
|
|
Shinya Kitaoka |
120a6e |
for (int ii = start_pos; ii < end_pos; ++ii) {
|
|
Shinya Kitaoka |
120a6e |
sequence[ii] /= dd;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|