Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "tspectrumparam.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class Test_BoxFx : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(Test_BoxFx)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TDoubleParamP m_h;
Shinya Kitaoka 120a6e
  TDoubleParamP m_v;
Shinya Kitaoka 120a6e
  TPixelParamP m_color;
Shinya Kitaoka 120a6e
  TPointParamP m_point;
Shinya Kitaoka 120a6e
  TSpectrumParamP m_colors;
Shinya Kitaoka 120a6e
  TIntParamP m_int;
Shinya Kitaoka 120a6e
  TIntEnumParamP m_enum;
Shinya Kitaoka 120a6e
  TRangeParamP m_range;
Shinya Kitaoka 120a6e
  TBoolParamP m_bool;
Shinya Kitaoka 120a6e
  TStringParamP m_string;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Test_BoxFx()
Shinya Kitaoka 120a6e
      : m_h(30.0)
Shinya Kitaoka 120a6e
      , m_v(30.0)
Shinya Kitaoka 120a6e
      , m_color(TPixel32::Blue)
Shinya Kitaoka 120a6e
      , m_range(DoublePair(100., 100.))
Shinya Kitaoka 120a6e
      , m_int(12)
Shinya Kitaoka 120a6e
      , m_enum(new TIntEnumParam(0, "Color"))
Shinya Kitaoka 120a6e
      , m_point(TPointD(0.0, 0.0))
Shinya Kitaoka 120a6e
      , m_bool(true)
Shinya Kitaoka 120a6e
      , m_string(L"urka") {
Shinya Kitaoka 120a6e
    m_h->setValueRange(0, 100);
Shinya Kitaoka 120a6e
    m_enum->addItem(1, "Uno");
Shinya Kitaoka 120a6e
    m_enum->addItem(2, "Due");
Shinya Kitaoka 120a6e
    m_enum->addItem(3, "Tre");
Shinya Kitaoka 120a6e
    bindParam(this, "h", m_h);
Shinya Kitaoka 120a6e
    bindParam(this, "v", m_v);
Shinya Kitaoka 120a6e
    bindParam(this, "color", m_color);
Shinya Kitaoka 120a6e
    bindParam(this, "Point", m_point);
Shinya Kitaoka 120a6e
    bindParam(this, "enum", m_enum);
Shinya Kitaoka 120a6e
    m_enum->addItem(1, "Spectrum");
Shinya Kitaoka 120a6e
    bindParam(this, "int", m_int);
Shinya Kitaoka 120a6e
    bindParam(this, "range", m_range);
Shinya Kitaoka 120a6e
    bindParam(this, "bool", m_bool);
Tact Yoshida 1d7cf9
    std::vector<tspectrum::colorkey> colors = {</tspectrum::colorkey>
Tact Yoshida 1d7cf9
        TSpectrum::ColorKey(0, TPixel32::White),
Tact Yoshida 1d7cf9
        TSpectrum::ColorKey(0.5, TPixel32::Yellow),
Tact Yoshida 1d7cf9
        TSpectrum::ColorKey(1, TPixel32::Red)};
Tact Yoshida 1d7cf9
    m_colors = TSpectrumParamP(colors);
Shinya Kitaoka 120a6e
    bindParam(this, "spectrum", m_colors);
Shinya Kitaoka 120a6e
    bindParam(this, "string", m_string);
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~Test_BoxFx(){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool canHandle(const TRenderSettings &info, double frame) { return false; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info) {
Shinya Kitaoka 120a6e
    if (!m_input.isConnected()) {
Shinya Kitaoka 120a6e
      bBox = TRectD();
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return m_input->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void doCompute(TTile &tile, double frame, const TRenderSettings &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class class="" pix,="" ras=""></class>
Shinya Kitaoka 120a6e
void doTest_Box(RAS ras, double h, double v, TPointD pos, TPixel32 &color32,
Shinya Kitaoka 120a6e
                int my_enum, int my_int, const TSpectrumT<pix> spectrum,</pix>
Shinya Kitaoka 120a6e
                TPointD point, DoublePair range, bool my_bool) {
Shinya Kitaoka 120a6e
  int lx = ras->getLx();
Shinya Kitaoka 120a6e
  int ly = ras->getLy();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TPointD tmp = pos;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  const PIX color = PixelConverter<ras::pixel>::from(color32);</ras::pixel>
Shinya Kitaoka 120a6e
  int j, i;
Shinya Kitaoka 120a6e
  for (j = 0; j < ly; j++) {
Shinya Kitaoka 120a6e
    PIX *pix = ras->pixels(j);
Shinya Kitaoka 120a6e
    tmp.y++;
Shinya Kitaoka 120a6e
    tmp.x = pos.x;
Shinya Kitaoka 120a6e
    for (i = 0; i < lx; i++) {
Shinya Kitaoka 120a6e
      if (tmp.x > 0 && tmp.x < h && tmp.y > 0 && tmp.y < v) {
Shinya Kitaoka 120a6e
        if (my_enum && my_bool) {
Shinya Kitaoka 120a6e
          if (tmp.x > range.first && tmp.x < range.second)
Shinya Kitaoka 120a6e
            *pix = spectrum.getPremultipliedValue(
Shinya Kitaoka 120a6e
                sqrt((tmp.x - point.x) * (tmp.x - point.x) / (h * h) +
Shinya Kitaoka 120a6e
                     (tmp.y - point.y) * (tmp.y - point.y) / (v * v)));
Shinya Kitaoka 120a6e
          else
Shinya Kitaoka 120a6e
            *pix = color;
Shinya Kitaoka 120a6e
        } else
Shinya Kitaoka 120a6e
          *pix = color;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      tmp.x++;
Shinya Kitaoka 120a6e
      pix++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void Test_BoxFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                           const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  if (!m_input.isConnected()) return;
Shinya Kitaoka 120a6e
  wstring text = m_string->getValue();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_input->compute(tile, frame, ri);
Shinya Kitaoka 120a6e
  TPixel32 color = m_color->getValue(frame);
Shinya Kitaoka 120a6e
  double h       = m_h->getValue(frame);
Shinya Kitaoka 120a6e
  double v       = m_v->getValue(frame);
Shinya Kitaoka 120a6e
  int my_enum    = m_enum->getValue();
Shinya Kitaoka 120a6e
  // TSpectrum spectrum = m_colors->getValue(frame);
Shinya Kitaoka 120a6e
  int my_int       = m_int->getValue();
Shinya Kitaoka 120a6e
  TPointD point    = m_point->getValue(frame);
Shinya Kitaoka 120a6e
  DoublePair range = m_range->getValue(frame);
Shinya Kitaoka 120a6e
  bool my_bool     = m_bool->getValue();
Shinya Kitaoka 120a6e
  if (TRaster32P raster32 = tile.getRaster())
Shinya Kitaoka 120a6e
    doTest_Box<tpixel32, traster32p="">(raster32, h, v, tile.m_pos, color, my_enum,</tpixel32,>
Shinya Kitaoka 120a6e
                                     my_int, m_colors->getValue(frame), point,
Shinya Kitaoka 120a6e
                                     range, my_bool);
Shinya Kitaoka 120a6e
  else if (TRaster64P raster64 = tile.getRaster())
Shinya Kitaoka 120a6e
    doTest_Box<tpixel64, traster64p="">(raster64, h, v, tile.m_pos, color, my_enum,</tpixel64,>
Shinya Kitaoka 120a6e
                                     my_int, m_colors->getValue64(frame), point,
Shinya Kitaoka 120a6e
                                     range, my_bool);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    throw TException("Test_BoxFx: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(Test_BoxFx, "test_BoxFx")
Toshihiro Shimizu 890ddd
#endif