Toshihiro Shimizu 890ddd
#include <iostream></iostream>
Toshihiro Shimizu 890ddd
#include <iomanip></iomanip>
Toshihiro Shimizu 890ddd
#include <algorithm> /* std::copy() */</algorithm>
Toshihiro Shimizu 890ddd
#include "igs_maxmin_slrender.h"
Toshihiro Shimizu 890ddd
#include "igs_maxmin_lens_matrix.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void igs::maxmin::slrender::resize(const int odd_diameter, const int width,
Shinya Kitaoka 120a6e
                                   const bool alpha_ref_sw,
Shinya Kitaoka 120a6e
                                   std::vector<std::vector<double>> &tracks,</std::vector<double>
Shinya Kitaoka 120a6e
                                   std::vector<double> &alpha_ref,</double>
Shinya Kitaoka 120a6e
                                   std::vector<double> &result) {</double>
Shinya Kitaoka 120a6e
  tracks.resize(odd_diameter);
Shinya Kitaoka 120a6e
  for (int yy = 0; yy < odd_diameter; ++yy) {
Shinya Kitaoka 120a6e
    tracks.at(yy).resize(width + odd_diameter - 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (alpha_ref_sw) {
Shinya Kitaoka 120a6e
    alpha_ref.resize(width);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  result.resize(width);
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void igs::maxmin::slrender::clear(std::vector<std::vector<double>> &tracks,</std::vector<double>
Shinya Kitaoka 120a6e
                                  std::vector<double> &alpha_ref,</double>
Shinya Kitaoka 120a6e
                                  std::vector<double> &result) {</double>
Shinya Kitaoka 120a6e
  result.clear();
Shinya Kitaoka 120a6e
  alpha_ref.clear();
Shinya Kitaoka 120a6e
  tracks.clear();
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void igs::maxmin::slrender::shift(std::vector<std::vector<double>> &tracks) {</std::vector<double>
Shinya Kitaoka 120a6e
  /* 先頭からtracks.end()-1番目の要素が先頭にくるように回転 */
Shinya Kitaoka 120a6e
  std::rotate(tracks.begin(), tracks.end() - 1, tracks.end());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
double maxmin_(const double src, const bool min_sw,
Shinya Kitaoka 120a6e
               const std::vector<const *="" double=""> &begin_ptr,</const>
Shinya Kitaoka 120a6e
               const std::vector<int> &lens_sizes,</int>
Shinya Kitaoka 120a6e
               const std::vector<std::vector<double>> &lens_ratio) {</std::vector<double>
Shinya Kitaoka 120a6e
  if (min_sw) {
Shinya Kitaoka 120a6e
    /* 暗を広げる場合、反転して判断し、結果は反転して戻す */
Shinya Kitaoka 120a6e
    double val           = 1.0 - src; /* 反転して判断 */
Shinya Kitaoka 120a6e
    const double rev_src = 1.0 - src; /* 反転して判断 */
Shinya Kitaoka 120a6e
    for (unsigned yy = 0; yy < begin_ptr.size(); ++yy) {
Shinya Kitaoka 120a6e
      const int sz = lens_sizes.at(yy);
Shinya Kitaoka 120a6e
      if (sz <= 0) {
Shinya Kitaoka 120a6e
        continue;
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      const double *xptr = begin_ptr.at(yy);
Shinya Kitaoka 120a6e
      const double *rptr = &lens_ratio.at(yy).at(0);
Shinya Kitaoka 120a6e
      for (int xx = 0; xx < sz; ++xx, ++xptr, ++rptr) {
Shinya Kitaoka 120a6e
        double crnt = 1.0 - (*xptr); /* 反転して判断 */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        /* 元値と同じか(反転してるので)小さい値は不要 */
Shinya Kitaoka 120a6e
        if (crnt <= rev_src) {
Shinya Kitaoka 120a6e
          continue;
Shinya Kitaoka 120a6e
        }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        /* 元値との差に比率を掛けて結果値を出す */
Shinya Kitaoka 120a6e
        crnt = rev_src + (crnt - rev_src) * (*rptr);
Shinya Kitaoka 120a6e
        /* 今までの中で(反転してるので)より大きいなら代入 */
Shinya Kitaoka 120a6e
        if (val < crnt) {
Shinya Kitaoka 120a6e
          val = crnt;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return 1.0 - val; /* 結果は反転して戻す */
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* Max */
Shinya Kitaoka 120a6e
  double val = src;
Shinya Kitaoka 120a6e
  for (unsigned yy = 0; yy < begin_ptr.size(); ++yy) {
Shinya Kitaoka 120a6e
    const int sz = lens_sizes.at(yy);
Shinya Kitaoka 120a6e
    if (sz <= 0) {
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    const double *xptr = begin_ptr.at(yy);
Shinya Kitaoka 120a6e
    const double *rptr = &lens_ratio.at(yy).at(0);
Shinya Kitaoka 120a6e
    for (int xx = 0; xx < sz; ++xx, ++xptr, ++rptr) {
Shinya Kitaoka 120a6e
      /* 元値と同じか小さい値は不要 */
Shinya Kitaoka 120a6e
      if ((*xptr) <= src) {
Shinya Kitaoka 120a6e
        continue;
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      /* 元値との差に比率を掛けて結果値を出す */
Shinya Kitaoka 120a6e
      const double crnt = src + ((*xptr) - src) * (*rptr);
Shinya Kitaoka 120a6e
      /* 今までの中でより大きいなら代入 */
Shinya Kitaoka 120a6e
      if (val < crnt) {
Shinya Kitaoka 120a6e
        val = crnt;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return val;
Toshihiro Shimizu 890ddd
}
Shinya Kitaoka 120a6e
void set_begin_ptr_(const std::vector<std::vector<double>> &tracks,</std::vector<double>
Shinya Kitaoka 120a6e
                    const std::vector<int> &lens_offsets, const int offset,</int>
Shinya Kitaoka 120a6e
                    std::vector<const *="" double=""> &begin_ptr) {</const>
Shinya Kitaoka 120a6e
  for (unsigned ii = 0; ii < lens_offsets.size(); ++ii) {
Shinya Kitaoka 120a6e
    begin_ptr.at(ii) = (0 <= lens_offsets.at(ii))
Shinya Kitaoka 120a6e
                           ? &tracks.at(ii).at(offset + lens_offsets.at(ii))
Shinya Kitaoka 120a6e
                           : 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/* --- tracksをレンダリングする --------------------------------------*/
Toshihiro Shimizu 890ddd
void igs::maxmin::slrender::render(
Shinya Kitaoka 120a6e
    const double radius, const double smooth_outer_range,
Shinya Kitaoka 120a6e
    const int polygon_number, const double roll_degree
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const bool min_sw
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    std::vector<int> &lens_offsets, std::vector<int> &lens_sizes,</int></int>
Shinya Kitaoka 120a6e
    std::vector<std::vector<double>> &lens_ratio</std::vector<double>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const std::vector<std::vector<double>> &tracks /* RGBのどれか */</std::vector<double>
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    const std::vector<double> &alpha_ref /* alpha値で影響度合を決める */</double>
Shinya Kitaoka 120a6e
    ,
Shinya Kitaoka 120a6e
    std::vector<double> &result /* 計算結果 */</double>
Shinya Kitaoka 120a6e
    ) {
Shinya Kitaoka 120a6e
  /* 初期位置 */
Shinya Kitaoka 120a6e
  std::vector<const *="" double=""> begin_ptr(lens_offsets.size());</const>
Shinya Kitaoka 120a6e
  set_begin_ptr_(tracks, lens_offsets, 0, begin_ptr);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /* 効果半径に変化がある場合 */
Shinya Kitaoka 120a6e
  if (0 < alpha_ref.size()) {
Shinya Kitaoka 120a6e
    double before_radius = 0.0;
Shinya Kitaoka 120a6e
    for (unsigned xx = 0; xx < result.size(); ++xx) {
Shinya Kitaoka 120a6e
      /* 次の処理の半径 */
Shinya Kitaoka 120a6e
      const double radius2 = alpha_ref.at(xx) * radius;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      /* ゼロ以上なら処理する */
Shinya Kitaoka 120a6e
      if (0.0 < alpha_ref.at(xx)) {
Shinya Kitaoka 120a6e
        /* 前のPixelと違う大きさならreshapeする */
Shinya Kitaoka 120a6e
        if (radius2 != before_radius) {
Shinya Kitaoka 120a6e
          igs::maxmin::reshape_lens_matrix(
Shinya Kitaoka 120a6e
              radius2, igs::maxmin::outer_radius_from_radius(
Shinya Kitaoka 120a6e
                           radius2, smooth_outer_range),
Shinya Kitaoka 120a6e
              igs::maxmin::diameter_from_outer_radius(radius +
Shinya Kitaoka 120a6e
                                                      smooth_outer_range),
Shinya Kitaoka 120a6e
              polygon_number, roll_degree, lens_offsets, lens_sizes,
Shinya Kitaoka 120a6e
              lens_ratio);
Shinya Kitaoka 120a6e
          set_begin_ptr_(tracks, lens_offsets, xx, begin_ptr);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
        /* 各ピクセルの処理 */
Shinya Kitaoka 120a6e
        result.at(xx) =
Shinya Kitaoka 120a6e
            maxmin_(result.at(xx), min_sw, begin_ptr, lens_sizes, lens_ratio);
Shinya Kitaoka 120a6e
      } /* alpha_refがゼロなら変化なし */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      /* 次の位置へ移動 */
Shinya Kitaoka 120a6e
      for (unsigned ii = 0; ii < begin_ptr.size(); ++ii) {
Shinya Kitaoka 120a6e
        if (begin_ptr.at(ii) != 0) {
Shinya Kitaoka 120a6e
          ++begin_ptr.at(ii);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (radius2 != before_radius) {
Shinya Kitaoka 120a6e
        before_radius = radius2;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* 効果半径が変わらない場合 */
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    for (unsigned xx = 0; xx < result.size(); ++xx) {
Shinya Kitaoka 120a6e
      /* 各ピクセルの処理 */
Shinya Kitaoka 120a6e
      result.at(xx) =
Shinya Kitaoka 120a6e
          maxmin_(result.at(xx), min_sw, begin_ptr, lens_sizes, lens_ratio);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      /* 次の位置へ移動 */
Shinya Kitaoka 120a6e
      for (unsigned ii = 0; ii < begin_ptr.size(); ++ii) {
Shinya Kitaoka 120a6e
        if (begin_ptr.at(ii) != 0) {
Shinya Kitaoka 120a6e
          ++begin_ptr.at(ii);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}