1 /* === S Y N F I G ========================================================= */
2 /*!	\file wplistconverter.h
3 **	\brief Header for a converter between widths and positions
4 **	form a extended device and a equivalent ValueNode_WPList
5 **
6 **	$Id$
7 **
8 **	\legal
9 **	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 **	Copyright (c) 2011 Carlos López
11 **
12 **	This package is free software; you can redistribute it and/or
13 **	modify it under the terms of the GNU General Public License as
14 **	published by the Free Software Foundation; either version 2 of
15 **	the License, or (at your option) any later version.
16 **
17 **	This package is distributed in the hope that it will be useful,
18 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **	General Public License for more details.
21 **	\endlegal
22 */
23 /* ========================================================================= */
24 
25 /* === S T A R T =========================================================== */
26 
27 #ifndef __SYNFIG_WPLISTCONVERTER_H
28 #define __SYNFIG_WPLISTCONVERTER_H
29 
30 /* === H E A D E R S ======================================================= */
31 
32 #include <list>
33 #include <vector>
34 
35 #include <synfig/widthpoint.h>
36 
37 /* === M A C R O S ========================================================= */
38 
39 /* === T Y P E D E F S ===================================================== */
40 
41 /* === C L A S S E S & S T R U C T S ======================================= */
42 
43 namespace synfigapp {
44 
45 class WPListConverter
46 {
47 private:
48 	//! Cache of points ready to be processed after remove duplicated
49 	std::vector<synfig::Point> points;
50 	//! Cache of widths ready to be processed after remove duplicated
51 	std::vector<synfig::Real> widths;
52 	//! The processed result of the widthpoints
53 	std::vector<synfig::WidthPoint> work_out;
54 	//! Calculated cummulated distances to origin
55 	std::vector<synfig::Real> distances;
56 	//! Calculated cummulated distances to origin normalized
57 	std::vector<synfig::Real> norm_distances;
58 	//! The error value at each position: ek[k]=w[k]-wp_out.width[k]
59 	std::vector<synfig::Real> ek;
60 	//! The error value at each position: ek2=ek[k]*ek[k]
61 	std::vector<synfig::Real> ek2;
62 	//! The number of valid widths and points
63 	unsigned int n;
64 	//! The current squared error
65 	synfig::Real se;
66 
67 	//! This updates: ek, ek2 at the interval k1, k2, and returns the index where
68 	//! ek2 is maximum. If 'e' (squared error) is >=0 then it returns
69 	//! the new squared error at 'e' if not it just fills the error vectors for the first time
70 	unsigned int calculate_ek2(unsigned int k1, unsigned int k2, bool first_time=false);
71 	//! Finds next/previous widthpoint with dash=false. Don't consider k itself.
72 	unsigned int find_next(unsigned int k);
73 	unsigned int find_prev(unsigned int k);
74 
75 	void clear();
76 
77 public:
78 	synfig::Real err2max;
79 	WPListConverter();
80 	static void EnforceMinWidth(std::list<synfig::WidthPoint> &wplist, synfig::Real min_pressure);
81 	void operator()(std::list<synfig::WidthPoint> &wp_out, const std::list<synfig::Point> &p, const std::list<synfig::Real> &w);
82 };
83 
84 }; // END of namespace synfigapp
85 
86 /* === E N D =============================================================== */
87 
88 #endif
89