From 470efd06824232321e3d34f01adcfd94512c4aea Mon Sep 17 00:00:00 2001 From: dooglus Date: Wed, 26 Nov 2008 18:33:15 +0000 Subject: [PATCH] Rename the Random class in the mod_noise module to RandomNoise to stop it clashing with the Random class in mod_particle. Also rename the files random.h and random.cpp. git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2286 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-core/trunk/po/POTFILES.in | 4 +- synfig-core/trunk/src/modules/Makefile.am | 2 +- .../trunk/src/modules/mod_noise/Makefile.am | 2 +- .../trunk/src/modules/mod_noise/distort.cpp | 18 +- synfig-core/trunk/src/modules/mod_noise/distort.h | 6 +- synfig-core/trunk/src/modules/mod_noise/main.cpp | 4 +- synfig-core/trunk/src/modules/mod_noise/noise.cpp | 16 +- synfig-core/trunk/src/modules/mod_noise/noise.h | 6 +- synfig-core/trunk/src/modules/mod_noise/random.cpp | 304 --------------------- synfig-core/trunk/src/modules/mod_noise/random.h | 63 ----- .../trunk/src/modules/mod_noise/random_noise.cpp | 304 +++++++++++++++++++++ .../trunk/src/modules/mod_noise/random_noise.h | 63 +++++ .../src/modules/mod_noise/valuenode_random.cpp | 6 +- .../trunk/src/modules/mod_noise/valuenode_random.h | 6 +- 14 files changed, 402 insertions(+), 402 deletions(-) delete mode 100644 synfig-core/trunk/src/modules/mod_noise/random.cpp delete mode 100644 synfig-core/trunk/src/modules/mod_noise/random.h create mode 100644 synfig-core/trunk/src/modules/mod_noise/random_noise.cpp create mode 100644 synfig-core/trunk/src/modules/mod_noise/random_noise.h diff --git a/synfig-core/trunk/po/POTFILES.in b/synfig-core/trunk/po/POTFILES.in index 57ac37e..c37c4cf 100644 --- a/synfig-core/trunk/po/POTFILES.in +++ b/synfig-core/trunk/po/POTFILES.in @@ -129,8 +129,8 @@ src/modules/mod_noise/distort.h src/modules/mod_noise/main.cpp src/modules/mod_noise/noise.cpp src/modules/mod_noise/noise.h -src/modules/mod_noise/random.cpp -src/modules/mod_noise/random.h +src/modules/mod_noise/random_noise.cpp +src/modules/mod_noise/random_noise.h src/modules/mod_noise/valuenode_random.cpp src/modules/mod_noise/valuenode_random.h src/modules/mod_openexr/main.cpp diff --git a/synfig-core/trunk/src/modules/Makefile.am b/synfig-core/trunk/src/modules/Makefile.am index 11cb997..5cd0e01 100644 --- a/synfig-core/trunk/src/modules/Makefile.am +++ b/synfig-core/trunk/src/modules/Makefile.am @@ -3,7 +3,7 @@ synfiglibdir=@SYNFIGLIB_DIR@ MAINTAINERCLEANFILES=Makefile.in -SUBDIRS=mod_particle mod_filter mod_yuv420p mod_gif mod_gradient mod_geometry mod_noise mod_libavcodec mod_jpeg mod_openexr mod_bmp mod_ppm mod_png mod_dv mod_imagemagick mod_ffmpeg lyr_freetype lyr_std mod_mng mod_magickpp example +SUBDIRS=mod_particle mod_filter mod_yuv420p mod_gif mod_gradient mod_geometry mod_noise mod_jpeg mod_openexr mod_bmp mod_ppm mod_png mod_dv mod_imagemagick mod_ffmpeg lyr_freetype lyr_std mod_mng mod_magickpp example EXTRA_DIST=untemplate.nsh template.nsh example/simplecircle.h example/simplecircle.cpp example/filledrect.h example/main.cpp example/Makefile.am example/filledrect.cpp example/metaballs.cpp example/metaballs.h mod_mng/trgt_mng.h mod_mng/unmod_mng.nsh mod_mng/main.cpp mod_mng/Makefile.am mod_mng/mod_mng.nsh mod_mng/trgt_mng.cpp mptr_mplayer/main.cpp mptr_mplayer/mptr_mplayer.h mptr_mplayer/Makefile.am mptr_mplayer/mptr_mplayer.cpp mod_magickpp/trgt_magickpp.h mod_magickpp/unmod_magickpp.nsh mod_magickpp/main.cpp mod_magickpp/Makefile.am mod_magickpp/mod_magickpp.nsh mod_magickpp/trgt_magickpp.cpp sysconf_DATA = synfig_modules.cfg diff --git a/synfig-core/trunk/src/modules/mod_noise/Makefile.am b/synfig-core/trunk/src/modules/mod_noise/Makefile.am index 33717b7..2a766c5 100644 --- a/synfig-core/trunk/src/modules/mod_noise/Makefile.am +++ b/synfig-core/trunk/src/modules/mod_noise/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(top_builddir) -I$(top_srcdir)/src moduledir=@MODULE_DIR@ module_LTLIBRARIES = libmod_noise.la -libmod_noise_la_SOURCES = random.cpp random.h distort.cpp distort.h noise.cpp noise.h valuenode_random.cpp valuenode_random.h main.cpp +libmod_noise_la_SOURCES = random_noise.cpp random_noise.h distort.cpp distort.h noise.cpp noise.h valuenode_random.cpp valuenode_random.h main.cpp libmod_noise_la_CXXFLAGS = @SYNFIG_CFLAGS@ libmod_noise_la_LIBADD = ../../synfig/libsynfig.la @SYNFIG_LIBS@ libmod_noise_la_LDFLAGS = -module -no-undefined -avoid-version diff --git a/synfig-core/trunk/src/modules/mod_noise/distort.cpp b/synfig-core/trunk/src/modules/mod_noise/distort.cpp index 1dc1af4..1660c7d 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=Random::SMOOTH_COSINE; + smooth=RandomNoise::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; - Random::SmoothType temp_smooth(smooth); - Random::SmoothType smooth((!speed && temp_smooth == Random::SMOOTH_SPLINE) ? Random::SMOOTH_FAST_SPLINE : temp_smooth); + RandomNoise::SmoothType temp_smooth(smooth); + RandomNoise::SmoothType smooth((!speed && temp_smooth == RandomNoise::SMOOTH_SPLINE) ? RandomNoise::SMOOTH_FAST_SPLINE : temp_smooth); { Vector vect(0,0); @@ -201,17 +201,17 @@ NoiseDistort::get_param_vocab()const .set_local_name(_("Size")) ); ret.push_back(ParamDesc("seed") - .set_local_name(_("Random Seed")) + .set_local_name(_("RandomNoise Seed")) ); ret.push_back(ParamDesc("smooth") .set_local_name(_("Interpolation")) .set_description(_("What type of interpolation to use")) .set_hint("enum") - .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")) + .add_enum_value(RandomNoise::SMOOTH_DEFAULT, "nearest", _("Nearest Neighbor")) + .add_enum_value(RandomNoise::SMOOTH_LINEAR, "linear", _("Linear")) + .add_enum_value(RandomNoise::SMOOTH_COSINE, "cosine", _("Cosine")) + .add_enum_value(RandomNoise::SMOOTH_SPLINE, "spline", _("Spline")) + .add_enum_value(RandomNoise::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 a89a2a1..cecb157 100644 --- a/synfig-core/trunk/src/modules/mod_noise/distort.h +++ b/synfig-core/trunk/src/modules/mod_noise/distort.h @@ -33,7 +33,7 @@ #include #include #include -#include "random.h" +#include "random_noise.h" /* === M A C R O S ========================================================= */ @@ -49,8 +49,8 @@ private: synfig::Vector size; - Random random; - Random::SmoothType smooth; + RandomNoise random; + RandomNoise::SmoothType smooth; int detail; synfig::Real speed; bool turbulent; diff --git a/synfig-core/trunk/src/modules/mod_noise/main.cpp b/synfig-core/trunk/src/modules/mod_noise/main.cpp index 70c9bde..3c06179 100644 --- a/synfig-core/trunk/src/modules/mod_noise/main.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/main.cpp @@ -41,7 +41,7 @@ #include "noise.h" #include "distort.h" -#include "random.h" +#include "random_noise.h" #include "valuenode_random.h" #endif @@ -63,6 +63,6 @@ MODULE_INVENTORY_BEGIN(libmod_noise) END_LAYERS BEGIN_VALUENODES - VALUENODE(synfig::ValueNode_Random, "random", _("Random"), synfig::RELEASE_VERSION_0_61_08) // SVN r907 + VALUENODE(synfig::ValueNode_Random, "random", _("RandomNoise"), synfig::RELEASE_VERSION_0_61_08) // SVN r907 END_VALUENODES MODULE_INVENTORY_END diff --git a/synfig-core/trunk/src/modules/mod_noise/noise.cpp b/synfig-core/trunk/src/modules/mod_noise/noise.cpp index 4558624..4257a6c 100644 --- a/synfig-core/trunk/src/modules/mod_noise/noise.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/noise.cpp @@ -66,7 +66,7 @@ Noise::Noise(): size(1,1), gradient(Color::black(), Color::white()) { - smooth=Random::SMOOTH_COSINE; + smooth=RandomNoise::SMOOTH_COSINE; detail=4; speed=0; do_alpha=false; @@ -97,7 +97,7 @@ Noise::color_func(const Point &point, float pixel_size,Context /*context*/)const int i; Time time; time=speed*curr_time; - Random::SmoothType smooth((!speed && Noise::smooth == Random::SMOOTH_SPLINE) ? Random::SMOOTH_FAST_SPLINE : Noise::smooth); + RandomNoise::SmoothType smooth((!speed && Noise::smooth == RandomNoise::SMOOTH_SPLINE) ? RandomNoise::SMOOTH_FAST_SPLINE : Noise::smooth); float ftime(time); @@ -250,7 +250,7 @@ Noise::get_param_vocab()const .set_local_name(_("Gradient")) ); ret.push_back(ParamDesc("seed") - .set_local_name(_("Random Seed")) + .set_local_name(_("RandomNoise Seed")) ); ret.push_back(ParamDesc("size") .set_local_name(_("Size")) @@ -259,11 +259,11 @@ Noise::get_param_vocab()const .set_local_name(_("Interpolation")) .set_description(_("What type of interpolation to use")) .set_hint("enum") - .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")) + .add_enum_value(RandomNoise::SMOOTH_DEFAULT, "nearest", _("Nearest Neighbor")) + .add_enum_value(RandomNoise::SMOOTH_LINEAR, "linear", _("Linear")) + .add_enum_value(RandomNoise::SMOOTH_COSINE, "cosine", _("Cosine")) + .add_enum_value(RandomNoise::SMOOTH_SPLINE, "spline", _("Spline")) + .add_enum_value(RandomNoise::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 283702c..1ea78d6 100644 --- a/synfig-core/trunk/src/modules/mod_noise/noise.h +++ b/synfig-core/trunk/src/modules/mod_noise/noise.h @@ -34,7 +34,7 @@ #include #include #include -#include "random.h" +#include "random_noise.h" /* === M A C R O S ========================================================= */ @@ -50,8 +50,8 @@ private: synfig::Vector size; - Random random; - Random::SmoothType smooth; + RandomNoise random; + RandomNoise::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 deleted file mode 100644 index 7bc87e5..0000000 --- a/synfig-core/trunk/src/modules/mod_noise/random.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file mod_noise/random.cpp -** \brief blehh -** -** $Id$ -** -** \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 -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "random.h" -#include -#include -#include -#endif - -/* === M A C R O S ========================================================= */ - -#define PI (3.1415927) - -/* === G L O B A L S ======================================================= */ - -/* === P R O C E D U R E S ================================================= */ - -/* === M E T H O D S ======================================================= */ - -void -Random::set_seed(int x) -{ - seed_=x; -} - -float -Random::operator()(const int salt,const int x,const int y,const int t)const -{ - static const unsigned int a(21870); - static const unsigned int b(11213); - static const unsigned int c(36979); - static const unsigned int d(31337); - - quick_rng rng( - ( static_cast(x+y) * a ) ^ - ( static_cast(y+t) * b ) ^ - ( static_cast(t+x) * c ) ^ - ( static_cast(seed_+salt) * d ) - ); - - return rng.f() * 2.0f - 1.0f; -} - -float -Random::operator()(SmoothType smooth,int subseed,float xf,float yf,float tf)const -{ - int x((int)floor(xf)); - int y((int)floor(yf)); - int t((int)floor(tf)); - - switch(smooth) - { - 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]; - - //precalculate indices (all clamped) and offset - const int xa[] = {x-1,x,x+1,x+2}; - const int ya[] = {y-1,y,y+1,y+2}; - const int ta[] = {t-1,t,t+1,t+2}; - - const float dx(xf-x); - const float dy(yf-y); - const float dt(tf-t); - - //figure polynomials for each point - const float txf[] = - { - 0.5*dx*(dx*(dx*(-1) + 2) - 1), //-t + 2t^2 -t^3 - 0.5*(dx*(dx*(3*dx - 5)) + 2), //2 - 5t^2 + 3t^3 - 0.5*dx*(dx*(-3*dx + 4) + 1), //t + 4t^2 - 3t^3 - 0.5*dx*dx*(dx-1) //-t^2 + t^3 - }; - - const float tyf[] = - { - 0.5*dy*(dy*(dy*(-1) + 2) - 1), //-t + 2t^2 -t^3 - 0.5*(dy*(dy*(3*dy - 5)) + 2), //2 - 5t^2 + 3t^3 - 0.5*dy*(dy*(-3*dy + 4) + 1), //t + 4t^2 - 3t^3 - 0.5*dy*dy*(dy-1) //-t^2 + t^3 - }; - - const float ttf[] = - { - 0.5*dt*(dt*(dt*(-1) + 2) - 1), //-t + 2t^2 -t^3 - 0.5*(dt*(dt*(3*dt - 5)) + 2), //2 - 5t^2 + 3t^3 - 0.5*dt*(dt*(-3*dt + 4) + 1), //t + 4t^2 - 3t^3 - 0.5*dt*dt*(dt-1) //-t^2 + t^3 - }; - - //evaluate polynomial for each row - for(int i = 0; i < 4; ++i) - { - for(int j = 0; j < 4; ++j) - { - tfa[j] = f(ya[i],xa[j],ta[0])*ttf[0] + f(ya[i],xa[j],ta[1])*ttf[1] + f(ya[i],xa[j],ta[2])*ttf[2] + f(ya[i],xa[j],ta[3])*ttf[3]; - } - xfa[i] = tfa[0]*txf[0] + tfa[1]*txf[1] + tfa[2]*txf[2] + tfa[3]*txf[3]; - } - - //return the cumulative column evaluation - return xfa[0]*tyf[0] + xfa[1]*tyf[1] + xfa[2]*tyf[2] + xfa[3]*tyf[3]; -#undef f - } - break; - - - 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) -#define F(i,j) ((*this)(subseed,i+x,j+y)*(R((i)-a)*R(b-(j)))) -#define FT(i,j,k) ((*this)(subseed,i+x,j+y,k+t)*(R((i)-a)*R(b-(j))*R((k)-c))) -#define Z(i,j) ret+=F(i,j) -#define ZT(i,j,k) ret+=FT(i,j,k) -#define X(i,j) // placeholder... To make box more symmetric -#define XT(i,j,k) // placeholder... To make box more symmetric - - float a(xf-x), b(yf-y); - - // Interpolate - float ret(F(0,0)); - Z(-1,-1); Z(-1, 0); Z(-1, 1); Z(-1, 2); - Z( 0,-1); X( 0, 0); Z( 0, 1); Z( 0, 2); - Z( 1,-1); Z( 1, 0); Z( 1, 1); Z( 1, 2); - Z( 2,-1); Z( 2, 0); Z( 2, 1); Z( 2, 2); - - return ret; - } - - case SMOOTH_SPLINE: // Spline (animated) - { - float a(xf-x), b(yf-y), c(tf-t); - - // Interpolate - float ret(FT(0,0,0)); - ZT(-1,-1,-1); ZT(-1, 0,-1); ZT(-1, 1,-1); ZT(-1, 2,-1); - ZT( 0,-1,-1); ZT( 0, 0,-1); ZT( 0, 1,-1); ZT( 0, 2,-1); - ZT( 1,-1,-1); ZT( 1, 0,-1); ZT( 1, 1,-1); ZT( 1, 2,-1); - ZT( 2,-1,-1); ZT( 2, 0,-1); ZT( 2, 1,-1); ZT( 2, 2,-1); - - ZT(-1,-1, 0); ZT(-1, 0, 0); ZT(-1, 1, 0); ZT(-1, 2, 0); - ZT( 0,-1, 0); XT( 0, 0, 0); ZT( 0, 1, 0); ZT( 0, 2, 0); - ZT( 1,-1, 0); ZT( 1, 0, 0); ZT( 1, 1, 0); ZT( 1, 2, 0); - ZT( 2,-1, 0); ZT( 2, 0, 0); ZT( 2, 1, 0); ZT( 2, 2, 0); - - ZT(-1,-1, 1); ZT(-1, 0, 1); ZT(-1, 1, 1); ZT(-1, 2, 1); - ZT( 0,-1, 1); ZT( 0, 0, 1); ZT( 0, 1, 1); ZT( 0, 2, 1); - ZT( 1,-1, 1); ZT( 1, 0, 1); ZT( 1, 1, 1); ZT( 1, 2, 1); - ZT( 2,-1, 1); ZT( 2, 0, 1); ZT( 2, 1, 1); ZT( 2, 2, 1); - - ZT(-1,-1, 2); ZT(-1, 0, 2); ZT(-1, 1, 2); ZT(-1, 2, 2); - ZT( 0,-1, 2); ZT( 0, 0, 2); ZT( 0, 1, 2); ZT( 0, 2, 2); - ZT( 1,-1, 2); ZT( 1, 0, 2); ZT( 1, 1, 2); ZT( 1, 2, 2); - ZT( 2,-1, 2); ZT( 2, 0, 2); ZT( 2, 1, 2); ZT( 2, 2, 2); - - return ret; - -/* - - float dx=xf-x; - float dy=yf-y; - float dt=tf-t; - - float ret=0; - int i,j,h; - for(h=-1;h<=2;h++) - for(i=-1;i<=2;i++) - for(j=-1;j<=2;j++) - ret+=(*this)(subseed,i+x,j+y,h+t)*(R(i-dx)*R(j-dy)*R(h-dt)); - return ret; -*/ - } - break; -#undef X -#undef Z -#undef F -#undef P -#undef R - - case SMOOTH_COSINE: - if((float)t==tf) - { - int x((int)floor(xf)); - int y((int)floor(yf)); - float a=xf-x; - float b=yf-y; - a=(1.0f-cos(a*PI))*0.5f; - b=(1.0f-cos(b*PI))*0.5f; - float c=1.0-a; - float d=1.0-b; - int x2=x+1,y2=y+1; - return - (*this)(subseed,x,y,t)*(c*d)+ - (*this)(subseed,x2,y,t)*(a*d)+ - (*this)(subseed,x,y2,t)*(c*b)+ - (*this)(subseed,x2,y2,t)*(a*b); - } - else - { - float a=xf-x; - float b=yf-y; - float c=tf-t; - - 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*PI))*0.5f; - - float d=1.0-a; - float e=1.0-b; - float f=1.0-c; - - int x2=x+1,y2=y+1,t2=t+1; - - return - (*this)(subseed,x,y,t)*(d*e*f)+ - (*this)(subseed,x2,y,t)*(a*e*f)+ - (*this)(subseed,x,y2,t)*(d*b*f)+ - (*this)(subseed,x2,y2,t)*(a*b*f)+ - (*this)(subseed,x,y,t2)*(d*e*c)+ - (*this)(subseed,x2,y,t2)*(a*e*c)+ - (*this)(subseed,x,y2,t2)*(d*b*c)+ - (*this)(subseed,x2,y2,t2)*(a*b*c); - } - case SMOOTH_LINEAR: - if((float)t==tf) - { - int x((int)floor(xf)); - int y((int)floor(yf)); - float a=xf-x; - float b=yf-y; - float c=1.0-a; - float d=1.0-b; - int x2=x+1,y2=y+1; - return - (*this)(subseed,x,y,t)*(c*d)+ - (*this)(subseed,x2,y,t)*(a*d)+ - (*this)(subseed,x,y2,t)*(c*b)+ - (*this)(subseed,x2,y2,t)*(a*b); - } - else - { - - float a=xf-x; - float b=yf-y; - float c=tf-t; - - float d=1.0-a; - float e=1.0-b; - float f=1.0-c; - - int x2=x+1,y2=y+1,t2=t+1; - - return - (*this)(subseed,x,y,t)*(d*e*f)+ - (*this)(subseed,x2,y,t)*(a*e*f)+ - (*this)(subseed,x,y2,t)*(d*b*f)+ - (*this)(subseed,x2,y2,t)*(a*b*f)+ - (*this)(subseed,x,y,t2)*(d*e*c)+ - (*this)(subseed,x2,y,t2)*(a*e*c)+ - (*this)(subseed,x,y2,t2)*(d*b*c)+ - (*this)(subseed,x2,y2,t2)*(a*b*c); - } - default: - 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 deleted file mode 100644 index 767d1e6..0000000 --- a/synfig-core/trunk/src/modules/mod_noise/random.h +++ /dev/null @@ -1,63 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file mod_noise/random.h -** \brief Template Header -** -** $Id$ -** -** \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 -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_RANDOM_H -#define __SYNFIG_RANDOM_H - -/* === H E A D E R S ======================================================= */ - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - - -#define POOL_SIZE (256) -class Random -{ - int seed_; -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()(SmoothType smooth,int subseed,float x,float y=0, float t=0)const; -}; - -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-core/trunk/src/modules/mod_noise/random_noise.cpp b/synfig-core/trunk/src/modules/mod_noise/random_noise.cpp new file mode 100644 index 0000000..3d0e58c --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_noise/random_noise.cpp @@ -0,0 +1,304 @@ +/* === S Y N F I G ========================================================= */ +/*! \file mod_noise/random_noise.cpp +** \brief blehh +** +** $Id$ +** +** \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 +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "random_noise.h" +#include +#include +#include +#endif + +/* === M A C R O S ========================================================= */ + +#define PI (3.1415927) + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === M E T H O D S ======================================================= */ + +void +RandomNoise::set_seed(int x) +{ + seed_=x; +} + +float +RandomNoise::operator()(const int salt,const int x,const int y,const int t)const +{ + static const unsigned int a(21870); + static const unsigned int b(11213); + static const unsigned int c(36979); + static const unsigned int d(31337); + + quick_rng rng( + ( static_cast(x+y) * a ) ^ + ( static_cast(y+t) * b ) ^ + ( static_cast(t+x) * c ) ^ + ( static_cast(seed_+salt) * d ) + ); + + return rng.f() * 2.0f - 1.0f; +} + +float +RandomNoise::operator()(SmoothType smooth,int subseed,float xf,float yf,float tf)const +{ + int x((int)floor(xf)); + int y((int)floor(yf)); + int t((int)floor(tf)); + + switch(smooth) + { + 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]; + + //precalculate indices (all clamped) and offset + const int xa[] = {x-1,x,x+1,x+2}; + const int ya[] = {y-1,y,y+1,y+2}; + const int ta[] = {t-1,t,t+1,t+2}; + + const float dx(xf-x); + const float dy(yf-y); + const float dt(tf-t); + + //figure polynomials for each point + const float txf[] = + { + 0.5*dx*(dx*(dx*(-1) + 2) - 1), //-t + 2t^2 -t^3 + 0.5*(dx*(dx*(3*dx - 5)) + 2), //2 - 5t^2 + 3t^3 + 0.5*dx*(dx*(-3*dx + 4) + 1), //t + 4t^2 - 3t^3 + 0.5*dx*dx*(dx-1) //-t^2 + t^3 + }; + + const float tyf[] = + { + 0.5*dy*(dy*(dy*(-1) + 2) - 1), //-t + 2t^2 -t^3 + 0.5*(dy*(dy*(3*dy - 5)) + 2), //2 - 5t^2 + 3t^3 + 0.5*dy*(dy*(-3*dy + 4) + 1), //t + 4t^2 - 3t^3 + 0.5*dy*dy*(dy-1) //-t^2 + t^3 + }; + + const float ttf[] = + { + 0.5*dt*(dt*(dt*(-1) + 2) - 1), //-t + 2t^2 -t^3 + 0.5*(dt*(dt*(3*dt - 5)) + 2), //2 - 5t^2 + 3t^3 + 0.5*dt*(dt*(-3*dt + 4) + 1), //t + 4t^2 - 3t^3 + 0.5*dt*dt*(dt-1) //-t^2 + t^3 + }; + + //evaluate polynomial for each row + for(int i = 0; i < 4; ++i) + { + for(int j = 0; j < 4; ++j) + { + tfa[j] = f(ya[i],xa[j],ta[0])*ttf[0] + f(ya[i],xa[j],ta[1])*ttf[1] + f(ya[i],xa[j],ta[2])*ttf[2] + f(ya[i],xa[j],ta[3])*ttf[3]; + } + xfa[i] = tfa[0]*txf[0] + tfa[1]*txf[1] + tfa[2]*txf[2] + tfa[3]*txf[3]; + } + + //return the cumulative column evaluation + return xfa[0]*tyf[0] + xfa[1]*tyf[1] + xfa[2]*tyf[2] + xfa[3]*tyf[3]; +#undef f + } + break; + + + 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) +#define F(i,j) ((*this)(subseed,i+x,j+y)*(R((i)-a)*R(b-(j)))) +#define FT(i,j,k) ((*this)(subseed,i+x,j+y,k+t)*(R((i)-a)*R(b-(j))*R((k)-c))) +#define Z(i,j) ret+=F(i,j) +#define ZT(i,j,k) ret+=FT(i,j,k) +#define X(i,j) // placeholder... To make box more symmetric +#define XT(i,j,k) // placeholder... To make box more symmetric + + float a(xf-x), b(yf-y); + + // Interpolate + float ret(F(0,0)); + Z(-1,-1); Z(-1, 0); Z(-1, 1); Z(-1, 2); + Z( 0,-1); X( 0, 0); Z( 0, 1); Z( 0, 2); + Z( 1,-1); Z( 1, 0); Z( 1, 1); Z( 1, 2); + Z( 2,-1); Z( 2, 0); Z( 2, 1); Z( 2, 2); + + return ret; + } + + case SMOOTH_SPLINE: // Spline (animated) + { + float a(xf-x), b(yf-y), c(tf-t); + + // Interpolate + float ret(FT(0,0,0)); + ZT(-1,-1,-1); ZT(-1, 0,-1); ZT(-1, 1,-1); ZT(-1, 2,-1); + ZT( 0,-1,-1); ZT( 0, 0,-1); ZT( 0, 1,-1); ZT( 0, 2,-1); + ZT( 1,-1,-1); ZT( 1, 0,-1); ZT( 1, 1,-1); ZT( 1, 2,-1); + ZT( 2,-1,-1); ZT( 2, 0,-1); ZT( 2, 1,-1); ZT( 2, 2,-1); + + ZT(-1,-1, 0); ZT(-1, 0, 0); ZT(-1, 1, 0); ZT(-1, 2, 0); + ZT( 0,-1, 0); XT( 0, 0, 0); ZT( 0, 1, 0); ZT( 0, 2, 0); + ZT( 1,-1, 0); ZT( 1, 0, 0); ZT( 1, 1, 0); ZT( 1, 2, 0); + ZT( 2,-1, 0); ZT( 2, 0, 0); ZT( 2, 1, 0); ZT( 2, 2, 0); + + ZT(-1,-1, 1); ZT(-1, 0, 1); ZT(-1, 1, 1); ZT(-1, 2, 1); + ZT( 0,-1, 1); ZT( 0, 0, 1); ZT( 0, 1, 1); ZT( 0, 2, 1); + ZT( 1,-1, 1); ZT( 1, 0, 1); ZT( 1, 1, 1); ZT( 1, 2, 1); + ZT( 2,-1, 1); ZT( 2, 0, 1); ZT( 2, 1, 1); ZT( 2, 2, 1); + + ZT(-1,-1, 2); ZT(-1, 0, 2); ZT(-1, 1, 2); ZT(-1, 2, 2); + ZT( 0,-1, 2); ZT( 0, 0, 2); ZT( 0, 1, 2); ZT( 0, 2, 2); + ZT( 1,-1, 2); ZT( 1, 0, 2); ZT( 1, 1, 2); ZT( 1, 2, 2); + ZT( 2,-1, 2); ZT( 2, 0, 2); ZT( 2, 1, 2); ZT( 2, 2, 2); + + return ret; + +/* + + float dx=xf-x; + float dy=yf-y; + float dt=tf-t; + + float ret=0; + int i,j,h; + for(h=-1;h<=2;h++) + for(i=-1;i<=2;i++) + for(j=-1;j<=2;j++) + ret+=(*this)(subseed,i+x,j+y,h+t)*(R(i-dx)*R(j-dy)*R(h-dt)); + return ret; +*/ + } + break; +#undef X +#undef Z +#undef F +#undef P +#undef R + + case SMOOTH_COSINE: + if((float)t==tf) + { + int x((int)floor(xf)); + int y((int)floor(yf)); + float a=xf-x; + float b=yf-y; + a=(1.0f-cos(a*PI))*0.5f; + b=(1.0f-cos(b*PI))*0.5f; + float c=1.0-a; + float d=1.0-b; + int x2=x+1,y2=y+1; + return + (*this)(subseed,x,y,t)*(c*d)+ + (*this)(subseed,x2,y,t)*(a*d)+ + (*this)(subseed,x,y2,t)*(c*b)+ + (*this)(subseed,x2,y2,t)*(a*b); + } + else + { + float a=xf-x; + float b=yf-y; + float c=tf-t; + + 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*PI))*0.5f; + + float d=1.0-a; + float e=1.0-b; + float f=1.0-c; + + int x2=x+1,y2=y+1,t2=t+1; + + return + (*this)(subseed,x,y,t)*(d*e*f)+ + (*this)(subseed,x2,y,t)*(a*e*f)+ + (*this)(subseed,x,y2,t)*(d*b*f)+ + (*this)(subseed,x2,y2,t)*(a*b*f)+ + (*this)(subseed,x,y,t2)*(d*e*c)+ + (*this)(subseed,x2,y,t2)*(a*e*c)+ + (*this)(subseed,x,y2,t2)*(d*b*c)+ + (*this)(subseed,x2,y2,t2)*(a*b*c); + } + case SMOOTH_LINEAR: + if((float)t==tf) + { + int x((int)floor(xf)); + int y((int)floor(yf)); + float a=xf-x; + float b=yf-y; + float c=1.0-a; + float d=1.0-b; + int x2=x+1,y2=y+1; + return + (*this)(subseed,x,y,t)*(c*d)+ + (*this)(subseed,x2,y,t)*(a*d)+ + (*this)(subseed,x,y2,t)*(c*b)+ + (*this)(subseed,x2,y2,t)*(a*b); + } + else + { + + float a=xf-x; + float b=yf-y; + float c=tf-t; + + float d=1.0-a; + float e=1.0-b; + float f=1.0-c; + + int x2=x+1,y2=y+1,t2=t+1; + + return + (*this)(subseed,x,y,t)*(d*e*f)+ + (*this)(subseed,x2,y,t)*(a*e*f)+ + (*this)(subseed,x,y2,t)*(d*b*f)+ + (*this)(subseed,x2,y2,t)*(a*b*f)+ + (*this)(subseed,x,y,t2)*(d*e*c)+ + (*this)(subseed,x2,y,t2)*(a*e*c)+ + (*this)(subseed,x,y2,t2)*(d*b*c)+ + (*this)(subseed,x2,y2,t2)*(a*b*c); + } + default: + case SMOOTH_DEFAULT: + return (*this)(subseed,x,y,t); + } +} diff --git a/synfig-core/trunk/src/modules/mod_noise/random_noise.h b/synfig-core/trunk/src/modules/mod_noise/random_noise.h new file mode 100644 index 0000000..a95dc60 --- /dev/null +++ b/synfig-core/trunk/src/modules/mod_noise/random_noise.h @@ -0,0 +1,63 @@ +/* === S Y N F I G ========================================================= */ +/*! \file mod_noise/random_noise.h +** \brief Template Header +** +** $Id$ +** +** \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 +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_RANDOM_H +#define __SYNFIG_RANDOM_H + +/* === H E A D E R S ======================================================= */ + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + + +#define POOL_SIZE (256) +class RandomNoise +{ + int seed_; +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()(SmoothType smooth,int subseed,float x,float y=0, float t=0)const; +}; + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp index fdfa331..2f2157b 100644 --- a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp +++ b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.cpp @@ -60,7 +60,7 @@ ValueNode_Random::ValueNode_Random(const ValueBase &value): set_link("radius",ValueNode_Const::create(Real(1))); set_link("seed",ValueNode_Const::create(random.get_seed())); set_link("speed",ValueNode_Const::create(Real(1))); - set_link("smooth",ValueNode_Const::create(int(Random::SMOOTH_CUBIC))); + set_link("smooth",ValueNode_Const::create(int(RandomNoise::SMOOTH_CUBIC))); switch(get_type()) { @@ -112,7 +112,7 @@ ValueNode_Random::~ValueNode_Random() ValueBase ValueNode_Random::operator()(Time t)const { - typedef const Random::SmoothType Smooth; + typedef const RandomNoise::SmoothType Smooth; Real radius = (*radius_)(t).get(Real()); int seed = (*seed_)(t).get(int()); @@ -176,7 +176,7 @@ ValueNode_Random::get_name()const String ValueNode_Random::get_local_name()const { - return _("Random"); + return _("RandomNoise"); } bool diff --git a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h index d1818d1..f29d0e4 100644 --- a/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h +++ b/synfig-core/trunk/src/modules/mod_noise/valuenode_random.h @@ -29,7 +29,7 @@ /* === H E A D E R S ======================================================= */ #include "synfig/valuenode.h" -#include "random.h" +#include "random_noise.h" /* === M A C R O S ========================================================= */ @@ -45,8 +45,8 @@ class ValueNode_Random : public LinkableValueNode ValueNode::RHandle speed_; ValueNode::RHandle smooth_; - mutable Random random; - Random::SmoothType smooth; + mutable RandomNoise random; + RandomNoise::SmoothType smooth; ValueNode_Random(const ValueBase &value); public: -- 2.7.4