shun_iwasawa 4d2acf
#pragma once
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
/*------------------------------------
shun_iwasawa 4d2acf
Iwa_SoapBubbleFx
shun_iwasawa 4d2acf
Generates thin film interference colors from two reference images;
shun_iwasawa 4d2acf
one is for thickness and the other one is for shape or normal vector
shun_iwasawa 4d2acf
distribution of the film.
shun_iwasawa 4d2acf
Inherits Iwa_SpectrumFx.
shun_iwasawa 4d2acf
------------------------------------*/
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
#ifndef IWA_SOAPBUBBLE_H
shun_iwasawa 4d2acf
#define IWA_SOAPBUBBLE_H
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
#include "iwa_spectrumfx.h"
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
class Iwa_SoapBubbleFx final : public Iwa_SpectrumFx {
shun_iwasawa 4d2acf
  FX_PLUGIN_DECLARATION(Iwa_SoapBubbleFx)
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
protected:
shun_iwasawa 4d2acf
  /* target shape, used to create a pseudo normal vector */
shun_iwasawa 4d2acf
  TRasterFxPort m_shape;
shun_iwasawa 4d2acf
  /* another option, to input a depth map directly */
shun_iwasawa 4d2acf
  TRasterFxPort m_depth;
shun-iwasawa 9d0856
  // rendering mode
shun-iwasawa 9d0856
  TIntEnumParamP m_renderMode;
shun_iwasawa 4d2acf
  // shape parameters
shun_iwasawa 4d2acf
  TDoubleParamP m_binarize_threshold;
shun_iwasawa 4d2acf
  TDoubleParamP m_shape_aspect_ratio;
shun_iwasawa 4d2acf
  TDoubleParamP m_blur_radius;
shun_iwasawa 4d2acf
  TDoubleParamP m_blur_power;
shun-iwasawa a1471c
  TBoolParamP m_multi_source;
shun-iwasawa 9d0856
  TDoubleParamP m_center_opacity;
shun-iwasawa 9d0856
  TBoolParamP m_fit_thickness;
shun-iwasawa 9d0856
shun-iwasawa 9d0856
  // obsolete parameter. to be conerted to m_center_opacity
shun-iwasawa a1471c
  TBoolParamP m_mask_center;
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  // noise parameters
shun_iwasawa 4d2acf
  TIntParamP m_normal_sample_distance;
shun_iwasawa 4d2acf
  TIntParamP m_noise_sub_depth;
shun_iwasawa 4d2acf
  TDoubleParamP m_noise_resolution_s;
shun_iwasawa 4d2acf
  TDoubleParamP m_noise_resolution_t;
shun_iwasawa 4d2acf
  TDoubleParamP m_noise_sub_composite_ratio;
shun_iwasawa 4d2acf
  TDoubleParamP m_noise_evolution;
shun_iwasawa 4d2acf
  TDoubleParamP m_noise_depth_mix_ratio;
shun_iwasawa 4d2acf
  TDoubleParamP m_noise_thickness_mix_ratio;
shun_iwasawa 4d2acf
shun-iwasawa 9d0856
  enum { RENDER_MODE_BUBBLE, RENDER_MODE_THICKNESS, RENDER_MODE_DEPTH };
shun-iwasawa 9d0856
shun_iwasawa 4d2acf
  template <typename pixel="" raster,="" typename=""></typename>
shun-iwasawa a1471c
  void convertToBrightness(const RASTER srcRas, float* dst, float* alpha,
shun-iwasawa a1471c
                           TDimensionI dim);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  template <typename pixel="" raster,="" typename=""></typename>
shun_iwasawa 4d2acf
  void convertToRaster(const RASTER ras, float* thickness_map_p,
shun-iwasawa a1471c
                       float* depth_map_p, float* alpha_map_p, TDimensionI dim,
shun_iwasawa 4d2acf
                       float3* bubbleColor_p);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void processShape(double frame, TTile& shape_tile, float* depth_map_p,
shun-iwasawa 9d0856
                    float* alpha_map_p, USHORT* regionIds_p,
shun-iwasawa 9d0856
                    QList<qrect>& regionBoundingRects, TDimensionI dim,</qrect>
shun-iwasawa a1471c
                    const TRenderSettings& settings);
shun_iwasawa 4d2acf
shun-iwasawa a1471c
  int do_binarize(TRaster32P srcRas, USHORT* dst_p, float thres,
shun-iwasawa 9d0856
                  float* distance_p, float* alpha_map_p,
shun-iwasawa 9d0856
                  QList<qrect>& regionBoundingRects, TDimensionI dim);</qrect>
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void do_createBlurFilter(float* dst_p, int size, float radius);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void do_applyFilter(float* depth_map_p, TDimensionI dim, float* distace_p,
shun-iwasawa a1471c
                      USHORT* binarized_p, float* blur_filter_p,
shun-iwasawa a1471c
                      int blur_filter_size, double frame,
shun-iwasawa a1471c
                      const TRenderSettings& settings);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void processNoise(float* thickness_map_p, float* depth_map_p, TDimensionI dim,
shun_iwasawa 4d2acf
                    double frame, const TRenderSettings& settings);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void calc_norm_angle(float* norm_angle_p, float* depth_map_p, TDimensionI dim,
shun_iwasawa 4d2acf
                       int shrink);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void make_noise_map(float* noise_map_p, float* depth_map_p,
shun_iwasawa 4d2acf
                      float* norm_angle_p, TDimensionI dim,
shun_iwasawa 4d2acf
                      const QList<int>& noise_amount,</int>
shun_iwasawa 4d2acf
                      const QList<qsize>& noise_base_resolution,</qsize>
shun_iwasawa 4d2acf
                      int noise_sub_depth, float* noise_base);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  float noise_interp(int left, int right, int bottom, int top, float ratio_s,
shun_iwasawa 4d2acf
                     float ratio_t, float* noise_layer_base, int noise_dim_x);
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void add_noise(float* thickness_map_p, float* depth_map_p, TDimensionI dim,
shun_iwasawa 4d2acf
                 float* noise_map_p, float noise_thickness_mix_ratio,
shun_iwasawa 4d2acf
                 float noise_depth_mix_ratio);
shun_iwasawa 4d2acf
shun-iwasawa a1471c
  void do_distance_transform(float* dst_p, USHORT* binarized_p, int regionCount,
shun-iwasawa a1471c
                             TDimensionI dim, double frame);
shun-iwasawa a1471c
shun-iwasawa a1471c
  // if the rendering process is canceled, release raster and return TRUE
shun-iwasawa a1471c
  bool checkCancelAndReleaseRaster(const QList<trastergr8p>&, TTile&,</trastergr8p>
shun-iwasawa a1471c
                                   const TRenderSettings&);
shun-iwasawa a1471c
shun-iwasawa a1471c
  void applyDistanceToAlpha(float* distance_p, float* alpha_map_p,
shun-iwasawa 9d0856
                            TDimensionI dim, float center_opacity);
shun-iwasawa 9d0856
shun-iwasawa 9d0856
  void fitThicknessPatches(TRasterP thickRas, TDimensionI thickDim,
shun-iwasawa 9d0856
                           float* thickness_map_p, TDimensionI dim,
shun-iwasawa 9d0856
                           USHORT* regionIds_p,
shun-iwasawa 9d0856
                           QList<qrect>& regionBoundingRects);</qrect>
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
public:
shun_iwasawa 4d2acf
  Iwa_SoapBubbleFx();
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
  void doCompute(TTile& tile, double frame,
shun_iwasawa 4d2acf
                 const TRenderSettings& settings) override;
shun-iwasawa 9d0856
shun-iwasawa 9d0856
  // This will be called in TFx::loadData when obsolete "mask center" value is
shun-iwasawa 9d0856
  // loaded
shun-iwasawa 9d0856
  void onObsoleteParamLoaded(const std::string& paramName) override;
shun_iwasawa 4d2acf
};
shun_iwasawa 4d2acf
shun_iwasawa 4d2acf
#endif