my log
[synfig.git] / synfig-studio / trunk / src / synfigapp / blineconvert.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file blineconvert.h
3 **      \brief Template Header
4 **
5 **      $Id: blineconvert.h,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === S T A R T =========================================================== */
23
24 #ifndef __SYNFIG_BLINE_CONVERT_H
25 #define __SYNFIG_BLINE_CONVERT_H
26
27 /* === H E A D E R S ======================================================= */
28
29 #include <synfig/general.h>
30 #include <synfig/blinepoint.h>
31 #include <list>
32 #include <vector>
33
34 /* === M A C R O S ========================================================= */
35
36 /* === T Y P E D E F S ===================================================== */
37
38 /* === C L A S S E S & S T R U C T S ======================================= */
39
40 namespace synfigapp {
41         
42 class BLineConverter
43 {
44 public:
45         struct cpindex
46         {
47                 int             curind;
48                 synfig::Real    tangentscale;
49                 synfig::Real    error;  //negative error will indicate invalid;
50                 
51                 cpindex(int ci, synfig::Real s=0, synfig::Real e=-1) 
52                 :curind(ci), tangentscale(s), error(e) 
53                 {}
54                 
55                 cpindex(const cpindex & o)
56                 :curind(o.curind), tangentscale(o.tangentscale), error(o.error) 
57                 {}
58                 
59                 const cpindex & operator = (const cpindex & rhs)
60                 {
61                         curind = rhs.curind;
62                         tangentscale = rhs.tangentscale;
63                         error = rhs.error;
64                         return *this;
65                 }
66                 
67                 bool operator < (const cpindex &rhs) const
68                 {
69                         return curind < rhs.curind;             
70                 }
71                 
72                 //point is obviously in[curind]
73                 //tangent scale will get reset to the smallest (or something else depending on experimentation)
74         };
75
76 private:
77         //cached data
78         std::vector<synfig::Point>      f;      //the preprocessed input cache
79         std::vector<synfig::Real>       f_w;
80
81         //temporary point storage for vector calc
82         std::vector<synfig::Point>      ftemp;
83         
84         std::vector<synfig::Vector>     df; //the derivative cache      
85         std::vector<synfig::Real>       cvt; //the curvature cache
86         
87         std::vector<int>                        brk; //the break point cache
88         
89         std::vector<synfig::Real>       di,     //cumulative distance
90                                                                 d_i; //distance between adjacent segments
91         
92         std::vector<synfig::Point>      work; //the working point cache for the entire curve
93         std::vector<cpindex>            curind;
94         
95         //function parameters
96         void clear();
97
98 public:
99         synfig::Real width;
100
101         //Converter properties
102         synfig::Real pixelwidth;
103         synfig::Real smoothness; //actual error will be smoothness*pixelwidth (for global set pixelwidth = 1)
104
105         BLineConverter();
106
107         static void EnforceMinWidth(std::list<synfig::BLinePoint> &bline, synfig::Real min_pressure);
108         void operator ()(std::list<synfig::BLinePoint> &out, const std::list<synfig::Point> &in,const std::list<synfig::Real> &in_w);
109 };
110         
111 }; // END of namespace synfigapp
112
113 /* === E N D =============================================================== */
114
115 #endif