Author: Carlos Lopez <[email protected]>
Date: Sun Oct 2 21:45:19 2011 +0200
First steps of coding the procedures
---
synfig-studio/src/synfigapp/wplistconverter.cpp | 107 +++++++++++++++++++++++
synfig-studio/src/synfigapp/wplistconverter.h | 16 +++-
2 files changed, 122 insertions(+), 1 deletions(-)
diff --git a/synfig-studio/src/synfigapp/wplistconverter.cpp
b/synfig-studio/src/synfigapp/wplistconverter.cpp
index 75eb50c..af737c5 100644
--- a/synfig-studio/src/synfigapp/wplistconverter.cpp
+++ b/synfig-studio/src/synfigapp/wplistconverter.cpp
@@ -34,6 +34,7 @@
#endif
#include "wplistconverter.h"
+#include <synfig/valuenode_wplist.h>
/* === U S I N G =========================================================== */
@@ -59,6 +60,112 @@ WPListConverter::WPListConverter()
void
WPListConverter::operator()(std::list<synfig::WidthPoint> &wp_out, const
std::list<synfig::Point> &p, const std::list<synfig::Real> &w)
{
+ // number of data (points and widths)
+ unsigned int n;
+ // number of data (float format)
+ Real nf;
+ // indexes k1, k2 for the interval considered, kem where the error
+ // is maximum
+ unsigned int k1, k2, kem;
+ // return if less than two points
+ if (p.size() < 2)
+ return;
+ // Maybe this happens so for the moment we just bail
+ if(p.size()!=w.size())
+ {
+ synfig::info("sizes don't match Points size = %d , Widths size
= %d", p.size(), w.size());
+ return;
+ }
+ // Remove duplicated
+ std::list<synfig::Point>::const_iterator p_iter = p.begin(), end =
p.end();
+ std::list<synfig::Real>::const_iterator w_iter = w.begin();
+ Point c(*p_iter);
+ points.push_back(c);
+ widths.push_back(*w_iter);
+ p_iter++;
+ for(;p_iter != end; ++p_iter,++w_iter)
+ if (*p_iter != c)
+ {
+ points.push_back(c = *p_iter);
+ widths.push_back(*w_iter);
+ }
+ // once removed the duplicated then get the sizes of the work vectors
+ n=points.size();
+ nf=Real(n);
+ // Calculate the cumulative distances
+ Point p1(points[0]), p2;
+ Real d(0);
+ unsigned int i;
+ for(i=0;i<n;i++)
+ {
+ p2=points[i];
+ d+=(p2-p1).mag();
+ distances.push_back(d);
+ p1=p2;
+ }
+ synfig::info("distances size = %d", distances.size());
+ // Calculate the normalized cumulative distances
+ for(i=0;i<n;i++)
+ {
+ norm_distances.push_back(distances[i]/distances[n]);
+ }
+ // Prepare the output
+ work_out.resize(n);
+ // Prepare the errors
+
+ // Initially I insert all widthpoints with a dash set to true
+ // Why?: dash=true means that the widthpoint has to be discarded later
+ // Only setting dash to false will validate the widhtpoint based on the
+ // error rules.
+ for(i=0; i<n; i++)
+ work_out[i]=WidthPoint(widths[i], norm_distances[i],
WidthPoint::TYPE_INTERPOLATE, WidthPoint::TYPE_INTERPOLATE, true);
+ // Now let's insert the first two widthpoints:
+ work_out[0].set_dash(false);
+ work_out[n-1].set_dash(false);
+}
+
+unsigned int
+WPListConverter::calculate_ek2(unsigned int k1, unsigned int k2, Real &e)
+{
+ // remember: k2 is one more past the interval
+ unsigned int i;
+ Real g;
+ for(i=k1;i<k2;i++)
+ {
+ WidthPoint wp_prev(work_out[find_prev(i)]);
+ WidthPoint wp_next(work_out[find_next(i)]);
+ g=ek[i]=widths[i]-widthpoint_interpolate(wp_prev, wp_next,
norm_distances[i], false);
+ ek2[i]=g*g;
+ }
+ // work in progress...
+ return 0;
+}
+
+unsigned int
+WPListConverter::find_next(unsigned int k)
+{
+ // work in progress...
+ return k;
+}
+
+unsigned int
+WPListConverter::find_prev(unsigned int k)
+{
+ // work in progress...
+ return k;
+}
+
+
+void
+WPListConverter::clear()
+{
+ points.clear();
+ widths.clear();
+ distances.clear();
+ norm_distances.clear();
+ work_out.clear();
+ ek.clear();
+ ek2.clear();
}
/* === E N T R Y P O I N T ================================================= */
diff --git a/synfig-studio/src/synfigapp/wplistconverter.h
b/synfig-studio/src/synfigapp/wplistconverter.h
index 9ae3b0b..64732bb 100644
--- a/synfig-studio/src/synfigapp/wplistconverter.h
+++ b/synfig-studio/src/synfigapp/wplistconverter.h
@@ -47,12 +47,26 @@ class WPListConverter
private:
//! Cache of points ready to be processed after remove duplicated
std::vector<synfig::Point> points;
- //! Cache of widthd ready to be processed after remove duplicated
+ //! Cache of widths ready to be processed after remove duplicated
std::vector<synfig::Real> widths;
+ //! The processed result of the widthpoints
+ std::vector<synfig::WidthPoint> work_out;
//! Calculated cummulated distances to origin
std::vector<synfig::Real> distances;
//! Calculated cummulated distances to origin normalized
std::vector<synfig::Real> norm_distances;
+ //! The error value at each position: ek[k]=w[k]-wp_out.width[k]
+ std::vector<synfig::Real> ek;
+ //! The error value at each position: ek2=ek[k]*ek[k]
+ std::vector<synfig::Real> ek2;
+
+ //! This updates: ek, ek2 at the interval k1, k2, and returns the index
where
+ //! ek2 is maximum. If 'e' (squared error) is passed (>=0) then it
returns
+ //! the new squared error at 'e'
+ unsigned int calculate_ek2(unsigned int k1, unsigned int k2,
synfig::Real &e);
+ //! Finds next/previous widthpoint with dash=false. Don't consider k
itself.
+ unsigned int find_next(unsigned int k);
+ unsigned int find_prev(unsigned int k);
void clear();
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl