Toshihiro Shimizu 890ddd
#include <sstream> /* std::ostringstream */</sstream>
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ino_common.h"
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
class ino_motion_wind : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(ino_motion_wind)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TRasterFxPort m_refer;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIntEnumParamP m_direction;
Shinya Kitaoka 120a6e
  TBoolParamP m_dark;
Shinya Kitaoka 120a6e
  TBoolParamP m_alpha_rendering;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParamP m_length_min;
Shinya Kitaoka 120a6e
  TDoubleParamP m_length_max;
Shinya Kitaoka 120a6e
  TDoubleParamP m_length_bias;
Shinya Kitaoka 120a6e
  TDoubleParamP m_length_seed;
Shinya Kitaoka 120a6e
  TBoolParamP m_length_ref;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParamP m_force_min;
Shinya Kitaoka 120a6e
  TDoubleParamP m_force_max;
Shinya Kitaoka 120a6e
  TDoubleParamP m_force_bias;
Shinya Kitaoka 120a6e
  TDoubleParamP m_force_seed;
Shinya Kitaoka 120a6e
  TBoolParamP m_force_ref;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDoubleParamP m_density_min;
Shinya Kitaoka 120a6e
  TDoubleParamP m_density_max;
Shinya Kitaoka 120a6e
  TDoubleParamP m_density_bias;
Shinya Kitaoka 120a6e
  TDoubleParamP m_density_seed;
Shinya Kitaoka 120a6e
  TBoolParamP m_density_ref;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // TBoolParamP m_spread;
Shinya Kitaoka 120a6e
  TIntEnumParamP m_ref_mode;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ino_motion_wind()
Shinya Kitaoka 120a6e
      : m_direction(new TIntEnumParam(0, "Right"))
Shinya Kitaoka 120a6e
      , m_dark(false)
Shinya Kitaoka 120a6e
      , m_alpha_rendering(true)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      , m_length_min(0.0)
Shinya Kitaoka 120a6e
      , m_length_max(18.0)
Shinya Kitaoka 120a6e
      , m_length_bias(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_length_seed(1.0)
Shinya Kitaoka 120a6e
      , m_length_ref(false)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      , m_force_min(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_force_max(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_force_bias(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_force_seed(1.0)
Shinya Kitaoka 120a6e
      , m_force_ref(false)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      , m_density_min(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_density_max(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_density_bias(1.0 * ino::param_range())
Shinya Kitaoka 120a6e
      , m_density_seed(1.0)
Shinya Kitaoka 120a6e
      , m_density_ref(false)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // , m_spread(true)
Shinya Kitaoka 120a6e
      , m_ref_mode(new TIntEnumParam(0, "Red")) {
Shinya Kitaoka 120a6e
    this->m_length_min->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
    this->m_length_max->setMeasureName("fxLength");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    addInputPort("Source", this->m_input);
Shinya Kitaoka 120a6e
    addInputPort("Reference", this->m_refer);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bindParam(this, "direction", this->m_direction);
Shinya Kitaoka 120a6e
    bindParam(this, "dark", this->m_dark);
Shinya Kitaoka 120a6e
    bindParam(this, "alpha_rendering", this->m_alpha_rendering);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bindParam(this, "length_min", this->m_length_min);
Shinya Kitaoka 120a6e
    bindParam(this, "length_max", this->m_length_max);
Shinya Kitaoka 120a6e
    bindParam(this, "length_bias", this->m_length_bias);
Shinya Kitaoka 120a6e
    bindParam(this, "length_seed", this->m_length_seed);
Shinya Kitaoka 120a6e
    bindParam(this, "length_ref", this->m_length_ref);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bindParam(this, "force_min", this->m_force_min);
Shinya Kitaoka 120a6e
    bindParam(this, "force_max", this->m_force_max);
Shinya Kitaoka 120a6e
    bindParam(this, "force_bias", this->m_force_bias);
Shinya Kitaoka 120a6e
    bindParam(this, "force_seed", this->m_force_seed);
Shinya Kitaoka 120a6e
    bindParam(this, "force_ref", this->m_force_ref);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bindParam(this, "density_min", this->m_density_min);
Shinya Kitaoka 120a6e
    bindParam(this, "density_max", this->m_density_max);
Shinya Kitaoka 120a6e
    bindParam(this, "density_bias", this->m_density_bias);
Shinya Kitaoka 120a6e
    bindParam(this, "density_seed", this->m_density_seed);
Shinya Kitaoka 120a6e
    bindParam(this, "density_ref", this->m_density_ref);
Shinya Kitaoka 120a6e
    // bindParam(this,"spread", this->m_spread);
Shinya Kitaoka 120a6e
    bindParam(this, "reference", this->m_ref_mode);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    this->m_direction->addItem(1, "Up");
Shinya Kitaoka 120a6e
    this->m_direction->addItem(2, "Left");
Shinya Kitaoka 120a6e
    this->m_direction->addItem(3, "Down");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    this->m_length_min->setValueRange(0.0, 1000.0);
Shinya Kitaoka 120a6e
    this->m_length_max->setValueRange(0.0, 1000.0);
Shinya Kitaoka 120a6e
    this->m_length_bias->setValueRange(0.1 * ino::param_range(),
Shinya Kitaoka 120a6e
                                       10.0 * ino::param_range()); /* gamma値 */
Shinya Kitaoka 120a6e
    this->m_length_seed->setValueRange(
Shinya Kitaoka 120a6e
        0, std::numeric_limits<unsigned long="">::max());</unsigned>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    this->m_force_min->setValueRange(0.1 * ino::param_range(),
Shinya Kitaoka 120a6e
                                     10.0 * ino::param_range()); /* gamma値 */
Shinya Kitaoka 120a6e
    this->m_force_max->setValueRange(0.1 * ino::param_range(),
Shinya Kitaoka 120a6e
                                     10.0 * ino::param_range()); /* gamma値 */
Shinya Kitaoka 120a6e
    this->m_force_bias->setValueRange(0.1 * ino::param_range(),
Shinya Kitaoka 120a6e
                                      10.0 * ino::param_range()); /* gamma値 */
Shinya Kitaoka 120a6e
    this->m_force_seed->setValueRange(
Shinya Kitaoka 120a6e
        0, std::numeric_limits<unsigned long="">::max());</unsigned>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    this->m_density_min->setValueRange(0.0 * ino::param_range(),
Shinya Kitaoka 120a6e
                                       100.0 * ino::param_range());
Shinya Kitaoka 120a6e
    this->m_density_max->setValueRange(0.0 * ino::param_range(),
Shinya Kitaoka 120a6e
                                       100.0 * ino::param_range());
Shinya Kitaoka 120a6e
    this->m_density_bias->setValueRange(
Shinya Kitaoka 120a6e
        0.1 * ino::param_range(), 10.0 * ino::param_range()); /* gamma値 */
Shinya Kitaoka 120a6e
    this->m_density_seed->setValueRange(
Shinya Kitaoka 120a6e
        0, std::numeric_limits<unsigned long="">::max());</unsigned>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(1, "Green");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(2, "Blue");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(3, "Alpha");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(4, "Luminance");
Shinya Kitaoka 120a6e
    this->m_ref_mode->addItem(-1, "Nothing");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    if (this->m_input.isConnected()) {
Shinya Kitaoka 120a6e
      const bool ret = this->m_input->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
      // if ( this->m_spread->getValue() ) {
Shinya Kitaoka 120a6e
      const double min = this->m_length_min->getValue(frame);
Shinya Kitaoka 120a6e
      const double max = this->m_length_max->getValue(frame);
Shinya Kitaoka 120a6e
      const double margin =
Shinya Kitaoka 120a6e
          ceil(ino::pixel_per_mm() * ((min < max) ? max : min));
Shinya Kitaoka 120a6e
      if (0.0 < margin) {
Shinya Kitaoka 120a6e
        bBox = bBox.enlarge(margin);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      // }
Shinya Kitaoka 120a6e
      return ret;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      bBox = TRectD();
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 120a6e
    // return true;
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int getMemoryRequirement(const TRectD &rect, double frame,
Shinya Kitaoka 473e70
                           const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    const double mm2scale_shrink_pixel =
Shinya Kitaoka 120a6e
        ino::pixel_per_mm() * sqrt(fabs(info.m_affine.det())) /
Shinya Kitaoka 120a6e
        ((info.m_shrinkX + info.m_shrinkY) / 2.0);
Shinya Kitaoka 120a6e
    const double length_min =
Shinya Kitaoka 120a6e
        this->m_length_min->getValue(frame) * mm2scale_shrink_pixel;
Shinya Kitaoka 120a6e
    const double length_max =
Shinya Kitaoka 120a6e
        this->m_length_max->getValue(frame) * mm2scale_shrink_pixel;
Shinya Kitaoka 120a6e
    const int enlarge_pixel =
Shinya Kitaoka 120a6e
        (int)(ceil((length_min < length_max) ? length_max : length_min) + 0.5);
Shinya Kitaoka 120a6e
    return TRasterFx::memorySize(rect.enlarge(enlarge_pixel), info.m_bpp);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &rend_sets) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(ino_motion_wind, "inoMotionWindFx");
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
#include "igs_motion_wind.h"
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
void fx_(const TRasterP in_ras  // with margin
Shinya Kitaoka 120a6e
         ,
Shinya Kitaoka 120a6e
         const TRasterP refer_ras  // with margin
Shinya Kitaoka 120a6e
         ,
Shinya Kitaoka 120a6e
         const int ref_mode, const int margin, TRasterP out_ras  // no margin
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
         ,
Shinya Kitaoka 120a6e
         const int direction, const bool dark_sw, const bool alpha_rendering_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
         ,
Shinya Kitaoka 120a6e
         const double length_min, const double length_max,
Shinya Kitaoka 120a6e
         const double length_bias, const unsigned long length_seed,
Shinya Kitaoka 120a6e
         const bool length_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
         ,
Shinya Kitaoka 120a6e
         const double force_min, const double force_max,
Shinya Kitaoka 120a6e
         const double force_bias, const unsigned long force_seed,
Shinya Kitaoka 120a6e
         const bool force_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
         ,
Shinya Kitaoka 120a6e
         const double density_min, const double density_max,
Shinya Kitaoka 120a6e
         const double density_bias, const unsigned long density_seed,
Shinya Kitaoka 120a6e
         const bool density_ref_sw) {
Shinya Kitaoka 120a6e
  /***std::vector<unsigned char=""> in_vec;</unsigned>
Shinya Kitaoka 120a6e
  ino::ras_to_vec( in_ras, ino::channels(), in_vec );
Shinya Kitaoka 120a6e
  std::vector<unsigned char=""> refer_vec;</unsigned>
Shinya Kitaoka 120a6e
  ino::ras_to_vec( refer_ras, ino::channels(), refer_vec );***/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterGR8P in_gr8(in_ras->getLy(),
Shinya Kitaoka 120a6e
                     in_ras->getLx() * ino::channels() *
Shinya Kitaoka 120a6e
                         ((TRaster64P)in_ras ? sizeof(unsigned short)
Shinya Kitaoka 120a6e
                                             : sizeof(unsigned char)));
Shinya Kitaoka 120a6e
  in_gr8->lock();
Shinya Kitaoka 120a6e
  ino::ras_to_arr(in_ras, ino::channels(), in_gr8->getRawData());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (0 != refer_ras) {
Shinya Kitaoka 120a6e
    TRasterGR8P refer_gr8(refer_ras->getLy(),
Shinya Kitaoka 120a6e
                          refer_ras->getLx() * ino::channels() *
Shinya Kitaoka 120a6e
                              ((TRaster64P)refer_ras ? sizeof(unsigned short)
Shinya Kitaoka 120a6e
                                                     : sizeof(unsigned char)));
Shinya Kitaoka 120a6e
    refer_gr8->lock();
Shinya Kitaoka 120a6e
    ino::ras_to_arr(refer_ras, ino::channels(), refer_gr8->getRawData());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    igs::motion_wind::change(
Shinya Kitaoka 120a6e
        // in_ras->getRawData() // BGRA
Shinya Kitaoka 120a6e
        //&in_vec.at(0) // RGBA
Shinya Kitaoka 120a6e
        in_gr8->getRawData()  // BGRA
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        in_ras->getLy(), in_ras->getLx(), ino::channels(), ino::bits(in_ras)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                                                               ,
Shinya Kitaoka 120a6e
        refer_gr8->getRawData()
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
            ,
Shinya Kitaoka 120a6e
        refer_ras->getLy(), refer_ras->getLx(), ino::channels(),
Shinya Kitaoka 120a6e
        ino::bits(refer_ras)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
            ,
Shinya Kitaoka 120a6e
        ref_mode
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        direction, dark_sw, alpha_rendering_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        length_seed, length_min, length_max, length_bias, length_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        force_seed, force_min, force_max, force_bias, force_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        density_seed, density_min, density_max, density_bias, density_ref_sw);
Shinya Kitaoka 120a6e
    /***ino::vec_to_ras( refer_vec, 0, 0 );
Shinya Kitaoka 120a6e
ino::vec_to_ras( in_vec, ino::channels(), out_ras, margin );***/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ino::arr_to_ras(in_gr8->getRawData(), ino::channels(), out_ras, margin);
Shinya Kitaoka 120a6e
    refer_gr8->unlock();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    igs::motion_wind::change(
Shinya Kitaoka 120a6e
        // in_ras->getRawData() // BGRA
Shinya Kitaoka 120a6e
        //&in_vec.at(0) // RGBA
Shinya Kitaoka 120a6e
        in_gr8->getRawData()  // BGRA
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        in_ras->getLy(), in_ras->getLx(), ino::channels(), ino::bits(in_ras)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
                                                               ,
Shinya Kitaoka 120a6e
        0
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        0, 0, 0, 0
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        0
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        direction, dark_sw, alpha_rendering_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        length_seed, length_min, length_max, length_bias, length_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        force_seed, force_min, force_max, force_bias, force_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        density_seed, density_min, density_max, density_bias, density_ref_sw);
Shinya Kitaoka 120a6e
    /***ino::vec_to_ras( refer_vec, 0, 0 );
Shinya Kitaoka 120a6e
ino::vec_to_ras( in_vec, ino::channels(), out_ras, margin );***/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    ino::arr_to_ras(in_gr8->getRawData(), ino::channels(), out_ras, margin);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  in_gr8->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Shinya Kitaoka 120a6e
void ino_motion_wind::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                                const TRenderSettings &rend_sets) {
Shinya Kitaoka 120a6e
  /* ------ 接続していなければ処理しない -------------------- */
Shinya Kitaoka 120a6e
  if (!this->m_input.isConnected()) {
Shinya Kitaoka 120a6e
    tile.getRaster()->clear(); /* 塗りつぶしクリア */
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ サポートしていないPixelタイプはエラーを投げる --- */
Shinya Kitaoka 120a6e
  if (!((TRaster32P)tile.getRaster()) && !((TRaster64P)tile.getRaster())) {
Shinya Kitaoka 120a6e
    throw TRopException("unsupported input pixel type");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ Pixel単位で動作パラメータを得る ----------------- */
Shinya Kitaoka 120a6e
  /* 単位変換用スケーリング
Shinya Kitaoka 120a6e
  外積(面積)
Shinya Kitaoka 120a6e
          rend_sets.m_affine.det() = a11*a22-a12*a21 // double
Shinya Kitaoka 120a6e
  シュリンク値
Shinya Kitaoka 120a6e
          rend_sets.m_shrinkX // int
Shinya Kitaoka 120a6e
          rend_sets.m_shrinkY // int
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  const double mm2scale_shrink_pixel =
Shinya Kitaoka 120a6e
      ino::pixel_per_mm() * sqrt(fabs(rend_sets.m_affine.det())) /
Shinya Kitaoka 120a6e
      ((rend_sets.m_shrinkX + rend_sets.m_shrinkY) / 2.0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* 動作パラメータを得る */
Shinya Kitaoka 120a6e
  const int direction    = this->m_direction->getValue();
Shinya Kitaoka 120a6e
  const bool dark_sw     = this->m_dark->getValue();
Shinya Kitaoka 120a6e
  const bool alp_rend_sw = this->m_alpha_rendering->getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const double length_min =
Shinya Kitaoka 120a6e
      this->m_length_min->getValue(frame) * mm2scale_shrink_pixel;
Shinya Kitaoka 120a6e
  const double length_max =
Shinya Kitaoka 120a6e
      this->m_length_max->getValue(frame) * mm2scale_shrink_pixel;
Shinya Kitaoka 120a6e
  const double length_bias =
Shinya Kitaoka 120a6e
      this->m_length_bias->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const unsigned long length_seed = this->m_length_seed->getValue(frame);
Shinya Kitaoka 120a6e
  const bool length_ref_sw        = this->m_length_ref->getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const double force_min =
Shinya Kitaoka 120a6e
      this->m_force_min->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double force_max =
Shinya Kitaoka 120a6e
      this->m_force_max->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double force_bias =
Shinya Kitaoka 120a6e
      this->m_force_bias->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const unsigned long force_seed = this->m_force_seed->getValue(frame);
Shinya Kitaoka 120a6e
  const bool force_ref_sw        = this->m_force_ref->getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const double density_min =
Shinya Kitaoka 120a6e
      this->m_density_min->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double density_max =
Shinya Kitaoka 120a6e
      this->m_density_max->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const double density_bias =
Shinya Kitaoka 120a6e
      this->m_density_bias->getValue(frame) / ino::param_range();
Shinya Kitaoka 120a6e
  const unsigned long density_seed = this->m_density_seed->getValue(frame);
Shinya Kitaoka 120a6e
  const bool density_ref_sw        = this->m_density_ref->getValue();
Shinya Kitaoka 120a6e
  const int ref_mode               = this->m_ref_mode->getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ 参照マージン含めた画像生成 ---------------------- */
Shinya Kitaoka 120a6e
  /* Rendering画像のBBox値 --> Pixel単位のdouble値 */
Shinya Kitaoka 120a6e
  /*	typedef TRectT<double> TRectD;</double>
Shinya Kitaoka 120a6e
          inline TRectT<double>::TRectT(</double>
Shinya Kitaoka 120a6e
                  const TPointT<double> &bottomLeft</double>
Shinya Kitaoka 120a6e
                  , const TDimensionT<double> &d</double>
Shinya Kitaoka 120a6e
          )	: x0(bottomLeft.x)
Shinya Kitaoka 120a6e
                  , y0(bottomLeft.y)
Shinya Kitaoka 120a6e
                  , x1(bottomLeft.x+d.lx)
Shinya Kitaoka 120a6e
                  , y1(bottomLeft.y+d.ly)
Shinya Kitaoka 120a6e
          {}
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TRectD enlarge_rect =
Shinya Kitaoka 120a6e
      TRectD(tile.m_pos /* TPointD */
Shinya Kitaoka 120a6e
             ,
Shinya Kitaoka 120a6e
             TDimensionD(/* int --> doubleにしてセット */
Shinya Kitaoka 120a6e
                         tile.getRaster()->getLx(), tile.getRaster()->getLy()));
Shinya Kitaoka 120a6e
  /* BBoxの拡大 Pixel単位 */
Shinya Kitaoka 120a6e
  const int enlarge_pixel =
Shinya Kitaoka 120a6e
      (int)(ceil((length_min < length_max) ? length_max : length_min) + 0.5);
Shinya Kitaoka 120a6e
  enlarge_rect = enlarge_rect.enlarge(enlarge_pixel);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*	void TRasterFx::allocateAndCompute(
Shinya Kitaoka 120a6e
                  TTile &tile,
Shinya Kitaoka 120a6e
                  const TPointD &pos, const TDimension &size,
Shinya Kitaoka 120a6e
                  const TRasterP &templateRas, double frame,
Shinya Kitaoka 120a6e
                  const TRenderSettings &info
Shinya Kitaoka 120a6e
          ) {
Shinya Kitaoka 120a6e
                  if (templateRas) {
Shinya Kitaoka 120a6e
          tile.getRaster() = templateRas->create(size.lx, size.ly);
Shinya Kitaoka 120a6e
                  } else {
Shinya Kitaoka 120a6e
          tile.getRaster() = TRaster32P(size.lx, size.ly);
Shinya Kitaoka 120a6e
                  }
Shinya Kitaoka 120a6e
          tile.m_pos = pos;
Shinya Kitaoka 120a6e
                  compute(tile, frame, info);
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  TTile enlarge_tile;
Shinya Kitaoka 120a6e
  this->m_input->allocateAndCompute(
Shinya Kitaoka 120a6e
      enlarge_tile, enlarge_rect.getP00(),
Shinya Kitaoka 120a6e
      TDimensionI(/* Pixel単位のdouble -> intにしてセット */
Shinya Kitaoka 120a6e
                  (int)(enlarge_rect.getLx() + 0.5),
Shinya Kitaoka 120a6e
                  (int)(enlarge_rect.getLy() + 0.5)),
Shinya Kitaoka 120a6e
      tile.getRaster(), frame, rend_sets);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ 保存すべき画像メモリを塗りつぶしクリア ---------- */
Shinya Kitaoka 120a6e
  tile.getRaster()->clear(); /* 塗りつぶしクリア */
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ 参照画像生成 ------------------------------------ */
Shinya Kitaoka 120a6e
  TTile refer_tile;
Shinya Kitaoka 120a6e
  const bool refer_cn_is = this->m_refer.isConnected();
Shinya Kitaoka 120a6e
  if (refer_cn_is) {
Shinya Kitaoka 120a6e
    this->m_refer->allocateAndCompute(
Shinya Kitaoka 120a6e
        refer_tile
Shinya Kitaoka 120a6e
        // tile.m_pos,
Shinya Kitaoka 120a6e
        // tile.getRaster()->getSize(),
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        enlarge_rect.getP00(),
Shinya Kitaoka 120a6e
        TDimensionI(/* Pixel単位のdouble -> intにしてセット */
Shinya Kitaoka 120a6e
                    (int)(enlarge_rect.getLx() + 0.5),
Shinya Kitaoka 120a6e
                    (int)(enlarge_rect.getLy() + 0.5)),
Shinya Kitaoka 120a6e
        tile.getRaster(), frame, rend_sets);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* ------ (app_begin)log記憶 ------------------------------ */
Shinya Kitaoka 120a6e
  const bool log_sw = ino::log_enable_sw();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (log_sw) {
Shinya Kitaoka 120a6e
    std::ostringstream os;
Shinya Kitaoka 120a6e
    os << "params"
Shinya Kitaoka 120a6e
       << "  dir " << direction << "  dark_sw " << dark_sw << "  alp_rend_sw "
Shinya Kitaoka 120a6e
       << alp_rend_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
       << "  len_min " << length_min << "  len_max " << length_max
Shinya Kitaoka 120a6e
       << "  len_bias " << length_bias << "  len_seed " << length_seed
Shinya Kitaoka 120a6e
       << "  len_ref_sw " << length_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
       << "  for_min " << force_min << "  for_max " << force_max
Shinya Kitaoka 120a6e
       << "  for_bias " << force_bias << "  for_seed " << force_seed
Shinya Kitaoka 120a6e
       << "  for_ref_sw " << force_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
       << "  den_min " << density_min << "  den_max " << density_max
Shinya Kitaoka 120a6e
       << "  den_bias " << density_bias << "  den_seed " << density_seed
Shinya Kitaoka 120a6e
       << "  den_ref_sw " << density_ref_sw << "  reference " << ref_mode
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
       << "   tile w " << tile.getRaster()->getLx() << "  h "
Shinya Kitaoka 120a6e
       << tile.getRaster()->getLy() << "  pixbits "
Shinya Kitaoka 120a6e
       << ino::pixel_bits(tile.getRaster());
Shinya Kitaoka 120a6e
    if (refer_cn_is) {
Shinya Kitaoka 120a6e
      os << "   rtile w " << refer_tile.getRaster()->getLx() << "  h "
Shinya Kitaoka 120a6e
         << refer_tile.getRaster()->getLy();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    os << "   frame " << frame << "   rand_sets affine_det "
Shinya Kitaoka 120a6e
       << rend_sets.m_affine.det() << "  shrink x " << rend_sets.m_shrinkX
Shinya Kitaoka 120a6e
       << "  y " << rend_sets.m_shrinkY;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* ------ fx処理 ------------------------------------------ */
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    tile.getRaster()->lock();
Shinya Kitaoka 120a6e
    if (refer_cn_is) {
Shinya Kitaoka 120a6e
      refer_tile.getRaster()->lock();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    fx_(enlarge_tile.getRaster()  // in with margin
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        (refer_cn_is ? refer_tile.getRaster() : nullptr)  // with margin
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        ref_mode, enlarge_pixel  // margin
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        tile.getRaster()  // out with no margin
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        direction, dark_sw, alp_rend_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        length_min, length_max, length_bias, length_seed, length_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        force_min, force_max, force_bias, force_seed, force_ref_sw
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        ,
Shinya Kitaoka 120a6e
        density_min, density_max, density_bias, density_seed, density_ref_sw);
Shinya Kitaoka 120a6e
    if (refer_cn_is) {
Shinya Kitaoka 120a6e
      refer_tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* ------ error処理 --------------------------------------- */
Shinya Kitaoka 120a6e
  catch (std::bad_alloc &e) {
Shinya Kitaoka 120a6e
    if (refer_cn_is) {
Shinya Kitaoka 120a6e
      refer_tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    if (log_sw) {
Shinya Kitaoka 120a6e
      std::string str("std::bad_alloc <");
Shinya Kitaoka 120a6e
      str += e.what();
Shinya Kitaoka 120a6e
      str += '>';
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    throw;
Shinya Kitaoka 120a6e
  } catch (std::exception &e) {
Shinya Kitaoka 120a6e
    if (refer_cn_is) {
Shinya Kitaoka 120a6e
      refer_tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    if (log_sw) {
Shinya Kitaoka 120a6e
      std::string str("exception <");
Shinya Kitaoka 120a6e
      str += e.what();
Shinya Kitaoka 120a6e
      str += '>';
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    throw;
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
    if (refer_cn_is) {
Shinya Kitaoka 120a6e
      refer_tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    tile.getRaster()->unlock();
Shinya Kitaoka 120a6e
    if (log_sw) {
Shinya Kitaoka 120a6e
      std::string str("other exception");
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    throw;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}