projects
/
synfig.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
When creating a 'SolidColor' layer, use the default background color, not foreground.
[synfig.git]
/
synfig-studio
/
trunk
/
src
/
synfigapp
/
blineconvert.cpp
diff --git
a/synfig-studio/trunk/src/synfigapp/blineconvert.cpp
b/synfig-studio/trunk/src/synfigapp/blineconvert.cpp
index
7adeca8
..
42cb57a
100644
(file)
--- a/
synfig-studio/trunk/src/synfigapp/blineconvert.cpp
+++ b/
synfig-studio/trunk/src/synfigapp/blineconvert.cpp
@@
-93,7
+93,7
@@
inline void ThreePointdt(T &df, const T &f1, const T &f2, const T &f3, int bias)
// // so only one algorithm needed for left, middle, or right
// df = (f1 -f2*2 + f3)*(1/2.0f);
// }
// // 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)
// // WARNING -- totally broken
// template < class T >
// inline void FivePointddt(T &df, const T &f1, const T &f2, const T &f3, int bias)
@@
-114,7
+114,7
@@
inline void ThreePointdt(T &df, const T &f1, const T &f2, const T &f3, int bias)
// }*/
// //side ones don't work, use 3 point
// }
// }*/
// //side ones don't work, use 3 point
// }
-//
+//
// //implement an arbitrary derivative
// //dumb algorithm
// template < class T >
// //implement an arbitrary derivative
// //dumb algorithm
// template < class T >
@@
-122,22
+122,22
@@
inline void ThreePointdt(T &df, const T &f1, const T &f2, const T &f3, int bias)
// {
// /*
// Lj(x) = PI_i!=j (x - xi) / PI_i!=j (xj - xi)
// {
// /*
// 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)
// */
// so Lj'(x) = SUM_k PI_i!=j|k (x - xi) / PI_i!=j (xj - xi)
// */
-//
+//
// unsigned int i,j,k,i0,i1;
// unsigned int i,j,k,i0,i1;
-//
+//
// Real Lpj,mult,div,tj;
// Real tval = t[indexval];
// Real Lpj,mult,div,tj;
// Real tval = t[indexval];
-//
+//
// //sum k
// for(j=0;j<npoints;++j)
// {
// Lpj = 0;
// div = 1;
// tj = t[j];
// //sum k
// for(j=0;j<npoints;++j)
// {
// Lpj = 0;
// div = 1;
// tj = t[j];
-//
+//
// for(k=0;k<npoints;++k)
// {
// if(k != j) //because there is no summand for k == j, since that term is missing from the original equation
// for(k=0;k<npoints;++k)
// {
// if(k != j) //because there is no summand for k == j, since that term is missing from the original equation
@@
-150,17
+150,17
@@
inline void ThreePointdt(T &df, const T &f1, const T &f2, const T &f3, int bias)
// mult *= tval - t[i];
// }
// }
// mult *= tval - t[i];
// }
// }
-//
+//
// Lpj += mult; //add into the summation
// Lpj += mult; //add into the summation
-//
+//
// //since the ks follow the exact pattern we need for the divisor (use that too)
// div *= tj - t[k];
// }
// }
// //since the ks follow the exact pattern we need for the divisor (use that too)
// div *= tj - t[k];
// }
// }
-//
+//
// //get the actual coefficient
// Lpj /= div;
// //get the actual coefficient
// Lpj /= div;
-//
+//
// //add it in to the equation
// df += f[j]*Lpj;
// }
// //add it in to the equation
// df += f[j]*Lpj;
// }
@@
-381,8
+381,8
@@
synfigapp::BLineConverter::clear()
width_cache.clear();
ftemp.clear();
deriv.clear();
width_cache.clear();
ftemp.clear();
deriv.clear();
- c
vt
.clear();
- br
k
.clear();
+ c
urvature
.clear();
+ br
eak_tangents
.clear();
cum_dist.clear();
this_dist.clear();
work.clear();
cum_dist.clear();
this_dist.clear();
work.clear();
@@
-401,7
+401,7
@@
synfigapp::BLineConverter::operator()(std::list<synfig::BLinePoint> &blinepoint
etl::clock_realtime timer,total;*/
//total.reset();
etl::clock_realtime timer,total;*/
//total.reset();
- if (points_in.size() <
= 1
)
+ if (points_in.size() <
2
)
return;
clear();
return;
clear();
@@
-426,9
+426,10
@@
synfigapp::BLineConverter::operator()(std::list<synfig::BLinePoint> &blinepoint
if (points_in.size() == widths_in.size())
{
if (points_in.size() == widths_in.size())
{
- for(
;
point_iter != end; ++point_iter,++width_iter)
- if
(*point_iter != c)
// eliminate duplicate points
+ for(
bool first = true;
point_iter != end; ++point_iter,++width_iter)
+ if
(first || *point_iter != c)
// eliminate duplicate points
{
{
+ first = false;
point_cache.push_back(c = *point_iter);
width_cache.push_back(*width_iter);
}
point_cache.push_back(c = *point_iter);
width_cache.push_back(*width_iter);
}
@@
-450,23
+451,21
@@
synfigapp::BLineConverter::operator()(std::list<synfig::BLinePoint> &blinepoint
//timer.reset();
{
//timer.reset();
{
- int i,i0,i1;
- synfig::Vector v1,v2;
-
- cvt.resize(point_cache.size());
+ int i_this, i_prev, i_next;
+ synfig::Vector v_prev, v_next;
- c
vt.front() = 1
;
- c
vt
.back() = 1;
+ c
urvature.resize(point_cache.size())
;
+ c
urvature.front() = curvature
.back() = 1;
- for
(i = 1; i < (int)point_cache.size()-1; ++i
)
+ for
(i_this = 1; i_this < (int)point_cache.size()-1; i_this++
)
{
{
- i
0 = std::max(0,i -
2);
- i
1 = std::min((int)(point_cache.size()-1),i +
2);
+ i
_prev = std::max(0, i_this-
2);
+ i
_next = std::min((int)(point_cache.size()-1), i_this+
2);
- v
1 = point_cache[i] - point_cache[i0
];
- v
2 = point_cache[i1] - point_cache[i
];
+ v
_prev = point_cache[i_this] - point_cache[i_prev
];
+ v
_next = point_cache[i_next] - point_cache[i_this
];
- c
vt[i] = (v1*v2)/(v1.mag()*v2
.mag());
+ c
urvature[i_this] = (v_prev*v_next) / (v_prev.mag()*v_next
.mag());
}
}
}
}
@@
-479,68
+478,75
@@
synfigapp::BLineConverter::operator()(std::list<synfig::BLinePoint> &blinepoint
//break at sharp derivative points
//TODO tolerance should be set based upon digitization resolution (length dependent index selection)
Real tol = 0; //break tolerance, for the cosine of the change in angle (really high curvature or something)
//break at sharp derivative points
//TODO tolerance should be set based upon digitization resolution (length dependent index selection)
Real tol = 0; //break tolerance, for the cosine of the change in angle (really high curvature or something)
- Real fixdistsq = 4*width*width; //the distance to ignore breaks at the end points (for fixing stuff)
unsigned int i = 0;
unsigned int i = 0;
- int maxi = -1, last=0;
- Real minc = 1;
+ int sharpest_i=-1;
+ int last=0;
+ Real sharpest_curvature = 1;
- br
k
.push_back(0);
+ br
eak_tangents
.push_back(0);
- for(i = 1; i < cvt.size()-1; ++i)
+ // loop through the curvatures; in each continuous run of
+ // curvatures that exceed the tolerence, find the one with the
+ // sharpest curvature and add its index to the list of indices
+ // at which to split tangents
+ for (i = 1; i < curvature.size()-1; ++i)
{
{
- //insert if too sharp (we need to break the tangents to insert onto the break list)
-
- if(cvt[i] < tol)
+ if (curvature[i] < tol)
{
{
- if(c
vt[i] < minc
)
+ if(c
urvature[i] < sharpest_curvature
)
{
{
-
minc = cvt
[i];
-
max
i = i;
+
sharpest_curvature = curvature
[i];
+
sharpest_
i = i;
}
}
}
}
- else if
(maxi >=
0)
+ else if
(sharpest_i >
0)
{
{
- if(maxi >= last + 8)
+ // don't have 2 corners too close to each other
+ if (sharpest_i >= last + 8) //! \todo make this configurable
{
{
- //synfig::info("break: %d-%d",
maxi+1,cvt
.size());
- br
k.push_back(max
i);
- last =
max
i;
+ //synfig::info("break: %d-%d",
sharpest_i+1,curvature
.size());
+ br
eak_tangents.push_back(sharpest_
i);
+ last =
sharpest_
i;
}
}
-
max
i = -1;
-
minc
= 1;
+
sharpest_
i = -1;
+
sharpest_curvature
= 1;
}
}
}
}
- br
k
.push_back(i);
+ br
eak_tangents
.push_back(i);
+// this section causes bug 1892566 if enabled
+#if 1
//postprocess for breaks too close to each other
//postprocess for breaks too close to each other
+ Real fixdistsq = 4*width*width; //the distance to ignore breaks at the end points (for fixing stuff)
Real d = 0;
Real d = 0;
- Point p = point_cache[br
k
.front()];
+ Point p = point_cache[br
eak_tangents
.front()];
//first set
//first set
- for
(i = 1; i < brk
.size()-1; ++i) //do not want to include end point...
+ for
(i = 1; i < break_tangents
.size()-1; ++i) //do not want to include end point...
{
{
- d = (point_cache[br
k
[i]] - p).mag_squared();
+ d = (point_cache[br
eak_tangents
[i]] - p).mag_squared();
if(d > fixdistsq) break; //don't want to group breaks if we ever get over the dist...
}
//want to erase all points before...
if(i != 1)
if(d > fixdistsq) break; //don't want to group breaks if we ever get over the dist...
}
//want to erase all points before...
if(i != 1)
- br
k.erase(brk.begin(),brk
.begin()+i-1);
+ br
eak_tangents.erase(break_tangents.begin(),break_tangents
.begin()+i-1);
//end set
//end set
- p = point_cache[br
k
.back()];
- for(i = br
k
.size()-2; i > 0; --i) //start at one in from the end
+ p = point_cache[br
eak_tangents
.back()];
+ for(i = br
eak_tangents
.size()-2; i > 0; --i) //start at one in from the end
{
{
- d = (point_cache[br
k
[i]] - p).mag_squared();
+ d = (point_cache[br
eak_tangents
[i]] - p).mag_squared();
if(d > fixdistsq) break; //don't want to group breaks if we ever get over the dist
}
if(d > fixdistsq) break; //don't want to group breaks if we ever get over the dist
}
- if(i != br
k
.size()-2)
- br
k.erase(brk.begin()+i+2,brk
.end()); //erase all points that we found... found none if i has not advanced
+ if(i != br
eak_tangents
.size()-2)
+ br
eak_tangents.erase(break_tangents.begin()+i+2,break_tangents
.end()); //erase all points that we found... found none if i has not advanced
//must not include the one we ended up on
//must not include the one we ended up on
+#endif
}
//breakeval = timer();
}
//breakeval = timer();
- //synfig::info("found break points: %d",br
k
.size());
+ //synfig::info("found break points: %d",br
eak_tangents
.size());
//get the distance calculation of the entire curve (for tangent scaling)
//get the distance calculation of the entire curve (for tangent scaling)
@@
-580,7
+586,7
@@
synfigapp::BLineConverter::operator()(std::list<synfig::BLinePoint> &blinepoint
bool done = false;
bool done = false;
- Real errortol = smoothness*pixelwidth; //???? what
the hell
should this value be
+ Real errortol = smoothness*pixelwidth; //???? what should this value be
BLinePoint a;
synfig::Vector v;
BLinePoint a;
synfig::Vector v;
@@
-594,11
+600,11
@@
synfigapp::BLineConverter::operator()(std::list<synfig::BLinePoint> &blinepoint
setwidth = (point_cache.size() == width_cache.size());
setwidth = (point_cache.size() == width_cache.size());
- for(j = 0; j < (int)br
k
.size() - 1; ++j)
+ for(j = 0; j < (int)br
eak_tangents
.size() - 1; ++j)
{
//for b[j] to b[j+1] subdivide and stuff
{
//for b[j] to b[j+1] subdivide and stuff
- i0 = br
k
[j];
- i3 = br
k
[j+1];
+ i0 = br
eak_tangents
[j];
+ i3 = br
eak_tangents
[j+1];
unsigned int size = i3-i0+1; //must include the end points
unsigned int size = i3-i0+1; //must include the end points
@@
-613,16
+619,16
@@
synfigapp::BLineConverter::operator()(std::list<synfig::BLinePoint> &blinepoint
// Wondering whether the modification of the deriv vector
// using a char* pointer and pointer arithmetric was safe,
// I looked it up...
// Wondering whether the modification of the deriv vector
// using a char* pointer and pointer arithmetric was safe,
// I looked it up...
- //
+ //
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2369.pdf tells me:
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2369.pdf tells me:
- //
+ //
// 23.2.5 Class template vector [vector]
// 23.2.5 Class template vector [vector]
- //
+ //
// [...] The elements of a vector are stored contiguously,
// meaning that if v is a vector<T,Allocator> where T is
// some type other than bool, then it obeys the identity
// &v[n] == &v[0] + n for all 0 <= n < v.size().
// [...] The elements of a vector are stored contiguously,
// meaning that if v is a vector<T,Allocator> where T is
// some type other than bool, then it obeys the identity
// &v[n] == &v[0] + n for all 0 <= n < v.size().
- //
+ //
GetFirstDerivatives(ftemp,0,size,(char*)&deriv[0],sizeof(deriv[0]));
//GetSimpleDerivatives(ftemp,0,size,deriv,0,cum_dist);
GetFirstDerivatives(ftemp,0,size,(char*)&deriv[0],sizeof(deriv[0]));
//GetSimpleDerivatives(ftemp,0,size,deriv,0,cum_dist);