X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fsynfigapp%2Fblineconvert.cpp;h=ec69a2e4750935d5e596b6f6a96dfea959493817;hb=e68d9f9f75956ecfee805a674f139033ded6bec6;hp=eb5e9dc5f78027f5f941dedb0cb5586e56887752;hpb=bbf05c1d5f53f61ec5b033c5c305a497d8389d46;p=synfig.git diff --git a/synfig-studio/trunk/src/synfigapp/blineconvert.cpp b/synfig-studio/trunk/src/synfigapp/blineconvert.cpp index eb5e9dc..ec69a2e 100644 --- a/synfig-studio/trunk/src/synfigapp/blineconvert.cpp +++ b/synfig-studio/trunk/src/synfigapp/blineconvert.cpp @@ -99,94 +99,95 @@ inline void ThreePointdt(T &df, const T &f1, const T &f2, const T &f3, int bias) } } -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 -- totaly 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) { @@ -246,7 +247,7 @@ void GetFirstDerivatives(const std::vector &f, unsigned int left, void GetSimpleDerivatives(const std::vector &f, int left, int right, std::vector &df, int outleft, - const std::vector &di) + const std::vector &/*di*/) { int i1,i2,i; int offset = 2; //df = 1/2 (f[i+o]-f[i-o]) @@ -326,7 +327,7 @@ Real CurveError(const synfig::Point *pts, unsigned int n, std::vector &inds, const std::vector &f, const std::vector &df, std::vector &work) +int tessellate_curves(const std::vector &inds, const std::vector &f, const std::vector &df, std::vector &work) { if(inds.size() < 2) return 0; @@ -341,7 +342,7 @@ int tesselate_curves(const std::vector &inds, const std::vector j2 = j++; for(; j != end; j2 = j++) { - //if this curve has invalid error (in j) then retesselate its work points (requires reparametrization, etc.) + //if this curve has invalid error (in j) then retessellate its work points (requires reparametrization, etc.) if(j->error < 0) { //get the stepsize etc. for the number of points in here @@ -361,8 +362,12 @@ int tesselate_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 +534,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()]; @@ -629,7 +634,7 @@ synfigapp::BLineConverter::operator () (std::list &out, cons //preproceval += timer(); //numpre++; - work.resize(size*2-1); //guarantee that all points will be tesselated 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); @@ -645,18 +650,18 @@ synfigapp::BLineConverter::operator () (std::list &out, cons //while there are still enough points between us, and the error is too high subdivide (and invalidate neighbors that share tangents) while(!done) { - //tesselate all curves with invalid error values + //tessellate all curves with invalid error values work[0] = f[i0]; //timer.reset(); - /*numtess += */tesselate_curves(curind,f,df,work); + /*numtess += */tessellate_curves(curind,f,df,work); //tesseval += timer(); //now get all error values //timer.reset(); for(i = 1; i < (int)curind.size(); ++i) { - if(curind[i].error < 0) //must have been retesselated, so now recalculate error value + if(curind[i].error < 0) //must have been retessellated, so now recalculate error value { //evaluate error from points (starting at current index) int size = curind[i].curind - curind[i-1].curind + 1; @@ -667,7 +672,7 @@ synfigapp::BLineConverter::operator () (std::list &out, cons { synfig::info("Holy crap %d-%d error %f",curind[i-1].curind,curind[i].curind,curind[i].error); curind[i].error = -1; - numtess += tesselate_curves(curind,f,df,work); + numtess += tessellate_curves(curind,f,df,work); curind[i].error = CurveError(&f[curind[i-1].curind], size, work,0,work.size());//(curind[i-1].curind - i0)*2,(curind[i].curind - i0)*2+1); }*/ @@ -807,7 +812,7 @@ synfigapp::BLineConverter::operator () (std::list &out, cons "\tDistance Calculation: %f\n" " Algorithm: (numtimes,totaltime)\n" "\tPreprocess step: (%d,%f)\n" - "\tTesselation step: (%d,%f)\n" + "\tTessellation step: (%d,%f)\n" "\tError step: (%d,%f)\n" "\tSplit step: (%d,%f)\n" " Num Input: %d, Num Output: %d\n"