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