X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=synfig-studio%2Ftrunk%2Fsrc%2Fsynfigapp%2Fblineconvert.cpp;h=770f42c6a99eca8d2390faf7cb1c5c92813db296;hb=f7610390c22c2908cb58f5abdb80edb018ad4fef;hp=e8849e09380168f18b00de3e906090dfdde89d8e;hpb=50cd69a8ee306a98e5c7a435796f77400f2d5fd1;p=synfig.git diff --git a/synfig-studio/trunk/src/synfigapp/blineconvert.cpp b/synfig-studio/trunk/src/synfigapp/blineconvert.cpp index e8849e0..770f42c 100644 --- a/synfig-studio/trunk/src/synfigapp/blineconvert.cpp +++ b/synfig-studio/trunk/src/synfigapp/blineconvert.cpp @@ -39,8 +39,6 @@ #include #include - - #endif /* === U S I N G =========================================================== */ @@ -66,127 +64,114 @@ using namespace synfig; template < class T > inline void FivePointdt(T &df, const T &f1, const T &f2, const T &f3, const T &f4, const T &f5, int bias) { - if(bias == 0) - { - //middle + if (bias == 0) // middle df = (f1 - f2*8 + f4*8 - f5)*(1/12.0f); - }else if(bias < 0) - { - //left + else if (bias < 0) // left df = (-f1*25 + f2*48 - f3*36 + f4*16 - f5*3)*(1/12.0f); - }else - { - //right + else // right df = (f1*3 - f2*16 + f3*36 - f4*48 + f5*25)*(1/12.0f); - } } template < class T > inline void ThreePointdt(T &df, const T &f1, const T &f2, const T &f3, int bias) { - if(bias == 0) - { - //middle + if (bias == 0) // middle df = (-f1 + f3)*(1/2.0f); - }else if(bias < 0) - { - //left + else if (bias < 0) // left df = (-f1*3 + f2*4 - f3)*(1/2.0f); - }else - { - //right + else // right df = (f1 - f2*4 + f3*3)*(1/2.0f); - } -} - -template < class T > -inline void ThreePointddt(T &df, const T &f1, const T &f2, const T &f3, int bias) -{ - //a 3 point approximation pretends to have constant acceleration, so only one algorithm needed for left, middle, or right - df = (f1 -f2*2 + f3)*(1/2.0f); } -// WARNING -- totally broken -template < class T > -inline void FivePointddt(T &df, const T &f1, const T &f2, const T &f3, int bias) -{ - if(bias == 0) - { - assert(0); // !? - //middle - //df = (- f1 + f2*16 - f3*30 + f4*16 - f5)*(1/12.0f); - }/*else if(bias < 0) - { - //left - df = (f1*7 - f2*26*4 + f3*19*6 - f4*14*4 + f5*11)*(1/12.0f); - }else - { - //right - df = (f1*3 - f2*16 + f3*36 - f4*48 + f5*25)*(1/12.0f); - }*/ - //side ones don't work, use 3 point -} - -//implement an arbitrary derivative -//dumb algorithm -template < class T > -void DerivativeApprox(T &df, const T f[], const Real t[], int npoints, int indexval) -{ - /* - Lj(x) = PI_i!=j (x - xi) / PI_i!=j (xj - xi) - - so Lj'(x) = SUM_k PI_i!=j|k (x - xi) / PI_i!=j (xj - xi) - */ - - unsigned int i,j,k,i0,i1; - - Real Lpj,mult,div,tj; - Real tval = t[indexval]; - - //sum k - for(j=0;j +// inline void ThreePointddt(T &df, const T &f1, const T &f2, const T &f3, int bias) +// { +// // a 3 point approximation pretends to have constant acceleration, +// // so only one algorithm needed for left, middle, or right +// df = (f1 -f2*2 + f3)*(1/2.0f); +// } +// +// // WARNING -- totally broken +// template < class T > +// inline void FivePointddt(T &df, const T &f1, const T &f2, const T &f3, int bias) +// { +// if(bias == 0) +// { +// assert(0); // !? +// //middle +// //df = (- f1 + f2*16 - f3*30 + f4*16 - f5)*(1/12.0f); +// }/*else if(bias < 0) +// { +// //left +// df = (f1*7 - f2*26*4 + f3*19*6 - f4*14*4 + f5*11)*(1/12.0f); +// }else +// { +// //right +// df = (f1*3 - f2*16 + f3*36 - f4*48 + f5*25)*(1/12.0f); +// }*/ +// //side ones don't work, use 3 point +// } +// +// //implement an arbitrary derivative +// //dumb algorithm +// template < class T > +// void DerivativeApprox(T &df, const T f[], const Real t[], int npoints, int indexval) +// { +// /* +// Lj(x) = PI_i!=j (x - xi) / PI_i!=j (xj - xi) +// +// so Lj'(x) = SUM_k PI_i!=j|k (x - xi) / PI_i!=j (xj - xi) +// */ +// +// unsigned int i,j,k,i0,i1; +// +// Real Lpj,mult,div,tj; +// Real tval = t[indexval]; +// +// //sum k +// for(j=0;j -inline int sign(T f, T tol) -{ - if(f < -tol) return -1; - if(f > tol) return 1; - return 0; -} +// template < class T > +// inline int sign(T f, T tol) +// { +// if(f < -tol) return -1; +// if(f > tol) return 1; +// return 0; +// } void GetFirstDerivatives(const std::vector &f, unsigned int left, unsigned int right, char *out, unsigned int dfstride) { @@ -194,7 +179,7 @@ void GetFirstDerivatives(const std::vector &f, unsigned int left, if(right - left < 2) return; - else if(right - left < 3) + else if(right - left == 2) { synfig::Vector v = f[left+1] - f[left]; @@ -208,13 +193,11 @@ void GetFirstDerivatives(const std::vector &f, unsigned int left, { //left then middle then right ThreePointdt(*(synfig::Vector*)out,f[left+0], f[left+1], f[left+2], -1); - current += 1; + current++; out += dfstride; for(;current < right-1; current++, out += dfstride) - { ThreePointdt(*(synfig::Vector*)out,f[current-1], f[current], f[current+1], 0); - } ThreePointdt(*(synfig::Vector*)out,f[right-3], f[right-2], f[right-1], 1); current++; @@ -232,14 +215,12 @@ void GetFirstDerivatives(const std::vector &f, unsigned int left, current += 2; for(;current < right-2; current++, out += dfstride) - { FivePointdt(*(synfig::Vector*)out,f[current-2], f[current-1], f[current], f[current+1], f[current+2], 0); - } - FivePointdt(*(synfig::Vector*)out,f[right-5], f[right-4], f[right-3], f[right-2], f[right-1], 1); - out += dfstride; FivePointdt(*(synfig::Vector*)out,f[right-6], f[right-5], f[right-4], f[right-3], f[right-2], 2); out += dfstride; + FivePointdt(*(synfig::Vector*)out,f[right-5], f[right-4], f[right-3], f[right-2], f[right-1], 1); + out += dfstride; current += 2; } } @@ -361,8 +342,12 @@ int tessellate_curves(const std::vector &inds, const std::vector //build hermite curve, it's easier curve.p1() = f[i0]; curve.p2() = f[i3]; - curve.t1() = df[i0]*(df[i0].mag_squared() > 1e-4 ? j2->tangentscale/df[i0].mag() : j2->tangentscale); - curve.t2() = df[i3]*(df[i3].mag_squared() > 1e-4 ? j->tangentscale/df[i3].mag() : j->tangentscale); + curve.t1() = df[i0-ibase] * (df[i0-ibase].mag_squared() > 1e-4 + ? j2->tangentscale/df[i0-ibase].mag() + : j2->tangentscale); + curve.t2() = df[i3-ibase] * (df[i3-ibase].mag_squared() > 1e-4 + ? j->tangentscale/df[i3-ibase].mag() + : j->tangentscale); curve.sync(); //MUST include the end point (since we are ignoring left one) @@ -529,7 +514,7 @@ synfigapp::BLineConverter::operator () (std::list &out, cons brk.push_back(i); - //postprocess for breaks too close to eachother + //postprocess for breaks too close to each other Real d = 0; Point p = f[brk.front()]; @@ -625,11 +610,11 @@ synfigapp::BLineConverter::operator () (std::list &out, cons df.resize(size); GetFirstDerivatives(ftemp,0,size,(char*)&df[0],sizeof(df[0])); //GetSimpleDerivatives(ftemp,0,size,df,0,di); - //< don't have to worry about indexing stuff as it is all being taken car of right now + //< don't have to worry about indexing stuff as it is all being taken care of right now //preproceval += timer(); //numpre++; - work.resize(size*2-1); //guarantee that all points will be tessellated correctly (one point inbetween every 2 adjacent points) + work.resize(size*2-1); //guarantee that all points will be tessellated correctly (one point in between every 2 adjacent points) //if size of work is size*2-1, the step size should be 1/(size*2 - 2) //Real step = 1/(Real)(size*2 - 1);