From ee42de12e3d9ba6c7105ab7b2344c9ec1fcef620 Mon Sep 17 00:00:00 2001 From: dooglus Date: Wed, 10 Oct 2007 03:20:35 +0000 Subject: [PATCH] Use an enumeration type rather than unnamed integers to specify the different types of random numbers. Just like r636, but for mod_noise's random numbers. Should we merge the two and move them into synfig-core proper? git-svn-id: http://svn.voria.com/code@880 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/src/modules/mod_noise/distort.cpp | 16 ++++++++-------- synfig-core/trunk/src/modules/mod_noise/distort.h | 2 +- synfig-core/trunk/src/modules/mod_noise/noise.cpp | 14 +++++++------- synfig-core/trunk/src/modules/mod_noise/noise.h | 2 +- synfig-core/trunk/src/modules/mod_noise/random.cpp | 21 +++++++++++---------- synfig-core/trunk/src/modules/mod_noise/random.h | 13 ++++++++++++- 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/synfig-core/trunk/src/modules/mod_noise/distort.cpp b/synfig-core/trunk/src/modules/mod_noise/distort.cpp index 6322dc4..950e7cc 100644 --- a/synfig-core/trunk/src/modules/mod_noise/distort.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/distort.cpp @@ -66,7 +66,7 @@ NoiseDistort::NoiseDistort(): size(1,1) { set_blend_method(Color::BLEND_STRAIGHT); - smooth=2; + smooth=Random::SMOOTH_COSINE; detail=4; speed=0; random.set_seed(time(NULL)); @@ -85,8 +85,8 @@ NoiseDistort::color_func(const Point &point, float /*supersample*/,Context conte int i; Time time; time=speed*curr_time; - int temp_smooth(smooth); - int smooth((!speed && temp_smooth==3)?5:temp_smooth); + Random::SmoothType temp_smooth(smooth); + Random::SmoothType smooth((!speed && temp_smooth == Random::SMOOTH_SPLINE) ? Random::SMOOTH_FAST_SPLINE : temp_smooth); { Vector vect(0,0); @@ -207,11 +207,11 @@ NoiseDistort::get_param_vocab()const .set_local_name(_("Interpolation")) .set_description(_("What type of interpolation to use")) .set_hint("enum") - .add_enum_value(0,"nearest",_("Nearest Neighbor")) - .add_enum_value(1,"linear",_("Linear")) - .add_enum_value(2,"cosine",_("Cosine")) - .add_enum_value(3,"spline",_("Spline")) - .add_enum_value(4,"cubic",_("Cubic")) + .add_enum_value(Random::SMOOTH_DEFAULT, "nearest", _("Nearest Neighbor")) + .add_enum_value(Random::SMOOTH_LINEAR, "linear", _("Linear")) + .add_enum_value(Random::SMOOTH_COSINE, "cosine", _("Cosine")) + .add_enum_value(Random::SMOOTH_SPLINE, "spline", _("Spline")) + .add_enum_value(Random::SMOOTH_CUBIC, "cubic", _("Cubic")) ); ret.push_back(ParamDesc("detail") .set_local_name(_("Detail")) diff --git a/synfig-core/trunk/src/modules/mod_noise/distort.h b/synfig-core/trunk/src/modules/mod_noise/distort.h index 7777138..e7bc5e1 100644 --- a/synfig-core/trunk/src/modules/mod_noise/distort.h +++ b/synfig-core/trunk/src/modules/mod_noise/distort.h @@ -49,7 +49,7 @@ private: synfig::Vector size; Random random; - int smooth; + Random::SmoothType smooth; int detail; synfig::Real speed; bool turbulent; diff --git a/synfig-core/trunk/src/modules/mod_noise/noise.cpp b/synfig-core/trunk/src/modules/mod_noise/noise.cpp index 797c430..1bfa73c 100644 --- a/synfig-core/trunk/src/modules/mod_noise/noise.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/noise.cpp @@ -65,7 +65,7 @@ Noise::Noise(): size(1,1), gradient(Color::black(), Color::white()) { - smooth=2; + smooth=Random::SMOOTH_COSINE; detail=4; speed=0; do_alpha=false; @@ -96,7 +96,7 @@ Noise::color_func(const Point &point, float pixel_size,Context /*context*/)const int i; Time time; time=speed*curr_time; - int smooth((!speed && Noise::smooth==3)?5:Noise::smooth); + Random::SmoothType smooth((!speed && Noise::smooth == Random::SMOOTH_SPLINE) ? Random::SMOOTH_FAST_SPLINE : Noise::smooth); float t(time); @@ -258,11 +258,11 @@ Noise::get_param_vocab()const .set_local_name(_("Interpolation")) .set_description(_("What type of interpolation to use")) .set_hint("enum") - .add_enum_value(0,"nearest",_("Nearest Neighbor")) - .add_enum_value(1,"linear",_("Linear")) - .add_enum_value(2,"cosine",_("Cosine")) - .add_enum_value(3,"spline",_("Spline")) - .add_enum_value(4,"cubic",_("Cubic")) + .add_enum_value(Random::SMOOTH_DEFAULT, "nearest", _("Nearest Neighbor")) + .add_enum_value(Random::SMOOTH_LINEAR, "linear", _("Linear")) + .add_enum_value(Random::SMOOTH_COSINE, "cosine", _("Cosine")) + .add_enum_value(Random::SMOOTH_SPLINE, "spline", _("Spline")) + .add_enum_value(Random::SMOOTH_CUBIC, "cubic", _("Cubic")) ); ret.push_back(ParamDesc("detail") .set_local_name(_("Detail")) diff --git a/synfig-core/trunk/src/modules/mod_noise/noise.h b/synfig-core/trunk/src/modules/mod_noise/noise.h index 8cb24b7..d4540d8 100644 --- a/synfig-core/trunk/src/modules/mod_noise/noise.h +++ b/synfig-core/trunk/src/modules/mod_noise/noise.h @@ -50,7 +50,7 @@ private: synfig::Vector size; Random random; - int smooth; + Random::SmoothType smooth; int detail; bool do_alpha; synfig::Gradient gradient; diff --git a/synfig-core/trunk/src/modules/mod_noise/random.cpp b/synfig-core/trunk/src/modules/mod_noise/random.cpp index a77de36..bd3cca8 100644 --- a/synfig-core/trunk/src/modules/mod_noise/random.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/random.cpp @@ -71,7 +71,7 @@ Random::operator()(const int salt,const int x,const int y,const int t)const } float -Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const +Random::operator()(SmoothType smooth,int subseed,float xf,float yf,float tf)const { int x((int)floor(xf)); int y((int)floor(yf)); @@ -79,10 +79,11 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const switch(smooth) { - case 4: // cubic + case SMOOTH_CUBIC: // cubic { #define f(j,i,k) ((*this)(subseed,i,j,k)) //Using catmull rom interpolation because it doesn't blur at all + // ( http://www.gamedev.net/reference/articles/article1497.asp ) //bezier curve with intermediate ctrl pts: 0.5/3(p(i+1) - p(i-1)) and similar float xfa [4], tfa[4]; @@ -139,7 +140,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const break; - case 5: // Fast Spline (non-animated) + case SMOOTH_FAST_SPLINE: // Fast Spline (non-animated) { #define P(x) (((x)>0)?((x)*(x)*(x)):0.0f) #define R(x) ( P(x+2) - 4.0f*P(x+1) + 6.0f*P(x) - 4.0f*P(x-1) )*(1.0f/6.0f) @@ -162,7 +163,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const return ret; } - case 3: // Spline (animated) + case SMOOTH_SPLINE: // Spline (animated) { float a(xf-x), b(yf-y), c(tf-t); @@ -212,7 +213,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const #undef P #undef R - case 2: // Cosine + case SMOOTH_COSINE: if((float)t==tf) { int x((int)floor(xf)); @@ -236,12 +237,12 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const float b=yf-y; float c=tf-t; - a=(1.0f-cos(a*3.1415927))*0.5f; - b=(1.0f-cos(b*3.1415927))*0.5f; + a=(1.0f-cos(a*PI))*0.5f; + b=(1.0f-cos(b*PI))*0.5f; // We don't perform this on the time axis, otherwise we won't // get smooth motion - //c=(1.0f-cos(c*3.1415927))*0.5f; + //c=(1.0f-cos(c*PI))*0.5f; float d=1.0-a; float e=1.0-b; @@ -259,7 +260,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const (*this)(subseed,x,y2,t2)*(d*b*c)+ (*this)(subseed,x2,y2,t2)*(a*b*c); } - case 1: // Linear + case SMOOTH_LINEAR: if((float)t==tf) { int x((int)floor(xf)); @@ -299,7 +300,7 @@ Random::operator()(int smooth,int subseed,float xf,float yf,float tf)const (*this)(subseed,x2,y2,t2)*(a*b*c); } default: - case 0: + case SMOOTH_DEFAULT: return (*this)(subseed,x,y,t); } } diff --git a/synfig-core/trunk/src/modules/mod_noise/random.h b/synfig-core/trunk/src/modules/mod_noise/random.h index 3a2d0ed..767d1e6 100644 --- a/synfig-core/trunk/src/modules/mod_noise/random.h +++ b/synfig-core/trunk/src/modules/mod_noise/random.h @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -43,8 +44,18 @@ public: void set_seed(int x); int get_seed()const { return seed_; } + enum SmoothType + { + SMOOTH_DEFAULT = 0, + SMOOTH_LINEAR = 1, + SMOOTH_COSINE = 2, + SMOOTH_SPLINE = 3, + SMOOTH_CUBIC = 4, + SMOOTH_FAST_SPLINE = 5, + }; + float operator()(int subseed,int x,int y=0, int t=0)const; - float operator()(int smooth,int subseed,float x,float y=0, float t=0)const; + float operator()(SmoothType smooth,int subseed,float x,float y=0, float t=0)const; }; /* === E N D =============================================================== */ -- 2.7.4