Example #1
0
float Example2DWake::
potential(float x, float y) const
{
   // begin with background laminary flow (adjusted so zero level goes through centre of disc)
   float p=-background_flow_speed*(y-disc_centre[1]);
   // modify for disc
   float d=solid_distance(x,y);
   if(d<disc_influence){
      p*=ramp(d/disc_influence);
   }
   // add turbulent wake that respects disc
   float wake_x=smooth_step(1-(x-disc_centre[0])/disc_radius);
   if(wake_x>0){
      float wake_y=smooth_step(1-std::fabs(y-disc_centre[1])/(1.5f*disc_radius+wake_expansion*(disc_centre[0]-x)));
      if(wake_y>0){
         float wake=wake_x*wake_y;
         float s=0;
         for(unsigned int i=0; i<noise_lengthscale.size(); ++i){
            s+=ramp(d/noise_lengthscale[i])*noise_gain[i]*noise((x-background_flow_speed*t)/noise_lengthscale[i], y/noise_lengthscale[i]);
         }
         p+=wake*s;
      }
   }
   return p;
}
Example #2
0
void //fills in one row of the inverse_R function
Halftone_TX::compute_inverse_R(
   uint i_lod,
   uint sample_count,
   uint* histogram_array,
   Image* image
   )
{
   double old_R = 0.0;
   double old_f_tone = 0.0;

   for (int i_tone=0; i_tone<CORR_RES; i_tone++) {

      double f_tone = double(i_tone) / double(CORR_RES-1); // 0.0~1.0

      //computes the R first
      //in order to take the smooth step into account
      //the procedure steps trough all heigths found in the
      //pattern, than it does the smooth step on each bucket
      //and multiplies by the total count of pixels in that bucket

      double R = 0.0;
      for (int h=0; h< 256; h++) {
         double tested_h = double(h)/double(255); //0~1

         R+= double (histogram_array[256 * i_lod + int(tested_h * 255.0)]) *
            smooth_step(-0.1,0.1, f_tone - tested_h) ;
      }

      R =  R / double (sample_count);

      //function inversion
      //this part is still a little iffy in my opinion

      bool filled = false;
      for (int i =  int (old_R * CORR_RES); i < int(R * CORR_RES); i++) {
         double f_i =
            double(i - int(old_R * CORR_RES))/double(int(R * CORR_RES)-1);
         image->set_grey(min(CORR_RES - 1, i),
                         i_lod,
                         int((interp(old_f_tone, f_tone, f_i)*255.0) + 0.5));
         filled = true;
      }

      if (filled) {
         old_f_tone = f_tone;
         old_R = R;
      }
   }

   //fixing the end, this hack puts a white pixel at the end
   image->set_grey( CORR_RES-1, i_lod, 255);
}
Example #3
0
void
Halftone_TX::compute_forward_R(
   uint sample_count,
   uint* histogram_array,
   Image* image
   )
{
   stop_watch r_timer;

   for (int i_tone=0; i_tone<CORR_RES; i_tone++) {

      double f_tone = double(i_tone) / double(CORR_RES-1); // 0.0~1.0

      //computes the R
      //in order to take the smooth step into account
      //the procedure steps trough all heigths found in the
      //pattern, than it does the smooth step on each bucket
      //and multiplies by the total count of pixels in that bucket

      double R = 0.0;
      for (int h=0; h< 256; h++) {
         double tested_h = double(h)/double(255); //0~1

         R+= double (histogram_array[ int(tested_h * 255.0)]) *
            smooth_step(-0.1,0.1, f_tone - tested_h) ;

      }

      R =  R / double (sample_count);

      image->set_grey(i_tone,0, int (R*255.0));
   }

   image->set_grey(0,0,0);
   image->set_grey(CORR_RES,0,255);

   if (debug) {
      cerr << " R build time : "
           << r_timer.elapsed_time() << endl;
   }
}
Example #4
0
float Example2DFancy::
potential(float x, float y) const
{
   Vec2f px(x,y);
   float numer=(1/sqr(envelope))*cross(px,wind_velocity);
   float denom=1/sqr(envelope);
   float minphi=1e36;
   for(unsigned int r=0; r<rigid.size(); ++r){
      Vec2f dx=px-rigid[r].centre;
      float psi=cross(px,rigid[r].velocity) + (sqr(envelope)-mag2(dx))/2*rigid[r].angular_velocity;
      float phi=rigid[r].distance(px);
      if(phi<minphi) minphi=phi;
      float m=1/(sqr(phi)+1e-18);
      numer+=m*psi;
      denom+=m;
   }
   float base_psi=numer/denom;

   float d=minphi/noise_lengthscale;
   float g=smooth_step(1.1-x);
   float turb=g*ramp(d)*noise_gain*noise((px-t*wind_velocity)/noise_lengthscale);

   return base_psi+turb;
}
Example #5
0
double smooth_pulse(double e0, double e1, double e2, double e3, double x) 
{
	return (smooth_step (e0, e1, x) - smooth_step (e2, e3, x));
}