Module: synfig
Branch: genete_width_points
Commit: 4fb07ad8b17b2c101a48cdee4aaa7ec684789c7a
URL:    
http://synfig.git.sourceforge.net/git/gitweb.cgi?p=synfig;a=commit;h=4fb07ad8b17b2c101a48cdee4aaa7ec684789c7a

Author: Carlos Lopez <car...@pcnuevo.(none)>
Date:   Mon Jul 27 00:44:19 2009 +0200

Fix constructor, create_list_entry and create in valuenode_wline.cpp.
Make dynamic list beware on VaLueNode_WLine existence

---

 .../trunk/src/synfig/valuenode_dynamiclist.h       |    2 +
 synfig-core/trunk/src/synfig/valuenode_wline.cpp   |  118 +++++---------------
 synfig-core/trunk/src/synfig/valuenode_wline.h     |    2 +-
 synfig-core/trunk/src/synfig/wlinepoint.cpp        |   14 ++-
 synfig-core/trunk/src/synfig/wlinepoint.h          |   12 ++
 5 files changed, 54 insertions(+), 94 deletions(-)

diff --git a/synfig-core/trunk/src/synfig/valuenode_dynamiclist.h 
b/synfig-core/trunk/src/synfig/valuenode_dynamiclist.h
index e73afd9..7bd1a92 100644
--- a/synfig-core/trunk/src/synfig/valuenode_dynamiclist.h
+++ b/synfig-core/trunk/src/synfig/valuenode_dynamiclist.h
@@ -41,6 +41,7 @@
 
 namespace synfig {
 class ValueNode_BLine;
+class ValueNode_WLine;
 class Canvas;
 
 /*! \class ValueNode_DynamicList
@@ -89,6 +90,7 @@ public:
        {
                friend class ValueNode_DynamicList;
                friend class ValueNode_BLine;
+               friend class ValueNode_WLine;
        public:
                typedef synfig::Activepoint Activepoint;
 
diff --git a/synfig-core/trunk/src/synfig/valuenode_wline.cpp 
b/synfig-core/trunk/src/synfig/valuenode_wline.cpp
index f2aa154..0d02685 100644
--- a/synfig-core/trunk/src/synfig/valuenode_wline.cpp
+++ b/synfig-core/trunk/src/synfig/valuenode_wline.cpp
@@ -185,7 +185,7 @@ synfig::interpolate_width(const float &orig_, const 
ValueBase &wline, const bool
 
 
 ValueNode_WLine::ValueNode_WLine():
-       ValueNode_DynamicList(ValueBase::TYPE_WLinePOINT)
+       ValueNode_DynamicList(ValueBase::TYPE_WLINEPOINT)
 {
 }
 
@@ -205,92 +205,18 @@ ValueNode_WLine::create(const ValueBase &value)
        {
                switch(value.get_contained_type())
                {
-               case ValueBase::TYPE_WLinePOINT:
+               case ValueBase::TYPE_WLINEPOINT:
                {
-//                     std::vector<WLinePoint> WLine_points(value.operator 
std::vector<WLinePoint>());
-                       //std::vector<WLinePoint> WLine_points(value);
-                       std::vector<WLinePoint> 
WLine_points(value.get_list().begin(),value.get_list().end());
+                       std::vector<WLinePoint> 
wline_points(value.get_list().begin(),value.get_list().end());
                        std::vector<WLinePoint>::const_iterator iter;
 
-                       
for(iter=WLine_points.begin();iter!=WLine_points.end();iter++)
+                       
for(iter=wline_points.begin();iter!=wline_points.end();iter++)
                        {
                                
value_node->add(ValueNode::Handle(ValueNode_Composite::create(*iter)));
                        }
                        value_node->set_loop(value.get_loop());
                }
                        break;
-               case ValueBase::TYPE_SEGMENT:
-               {
-                       // Here, we want to convert a list of segments
-                       // into a list of WLinePoints. We make an assumption
-                       // that the segment list is continuous(sp), but not 
necessarily
-                       // smooth.
-
-                       value_node->set_loop(false);
-//                     std::vector<Segment> segments(value.operator 
std::vector<Segment>());
-//                     std::vector<Segment> segments(value);
-                       std::vector<Segment> 
segments(value.get_list().begin(),value.get_list().end());
-                       std::vector<Segment>::const_iterator 
iter,last(segments.end());
-                       --last;
-                       ValueNode_Const::Handle prev,first;
-
-                       for(iter=segments.begin();iter!=segments.end();iter++)
-                       {
-#define PREV_POINT     prev->get_value().get(WLinePoint())
-#define FIRST_POINT    first->get_value().get(WLinePoint())
-#define CURR_POINT     curr->get_value().get(WLinePoint())
-                               if(iter==segments.begin())
-                               {
-                                       
prev=ValueNode_Const::create(ValueBase::TYPE_WLinePOINT);
-                                       {
-                                               WLinePoint 
prev_point(PREV_POINT);
-                                               prev_point.set_vertex(iter->p1);
-                                               
prev_point.set_tangent1(iter->t1);
-                                               prev_point.set_width(0.01);
-                                               prev_point.set_origin(0.5);
-                                               
prev_point.set_split_tangent_flag(false);
-                                               prev->set_value(prev_point);
-                                       }
-                                       first=prev;
-                                       
value_node->add(ValueNode::Handle(prev));
-
-                               }
-                               if(iter==last && 
iter->p2.is_equal_to(FIRST_POINT.get_vertex()))
-                               {
-                                       value_node->set_loop(true);
-                                       
if(!iter->t2.is_equal_to(FIRST_POINT.get_tangent1()))
-                                       {
-                                               WLinePoint 
first_point(FIRST_POINT);
-                                               
first_point.set_tangent1(iter->t2);
-                                               first->set_value(first_point);
-                                       }
-                                       continue;
-                               }
-
-                               ValueNode_Const::Handle curr;
-                               
curr=ValueNode_Const::create(ValueBase::TYPE_WLinePOINT);
-                               {
-                                       WLinePoint curr_point(CURR_POINT);
-                                       curr_point.set_vertex(iter->p2);
-                                       curr_point.set_tangent1(iter->t2);
-                                       curr_point.set_width(0.01);
-                                       curr_point.set_origin(0.5);
-                                       
curr_point.set_split_tangent_flag(false);
-                                       curr->set_value(curr_point);
-                               }
-                               
if(!PREV_POINT.get_tangent1().is_equal_to(iter->t1))
-                               {
-                                       WLinePoint prev_point(PREV_POINT);
-                                       prev_point.set_split_tangent_flag(true);
-                                       prev_point.set_tangent2(iter->t1);
-                                       prev->set_value(prev_point);
-                               }
-                               value_node->add(ValueNode::Handle(curr));
-                               prev=curr;
-                       }
-
-               }
-                       break;
                default:
                        // We got a list of who-knows-what. We don't have any 
idea
                        // what to do with it.
@@ -298,53 +224,61 @@ ValueNode_WLine::create(const ValueBase &value)
                        break;
                }
        }
-
        return value_node;
 }
 
 ValueNode_WLine::ListEntry
 ValueNode_WLine::create_list_entry(int index, Time time, Real origin)
 {
+       // The return value
        ValueNode_WLine::ListEntry ret;
 
+       //The previous and next WLinePoints
        synfig::WLinePoint prev,next;
 
+       //The previous and next indexes od the list (vector)
        int prev_i,next_i;
 
+       //Clamp the index to a valid value
        index=index%link_count();
 
+       //Be sure that index is valid for vectors
        assert(index>=0);
+       //Set the List Entry index
        ret.index=index;
+       //Set the parent Value Node to be this class
        ret.set_parent_value_node(this);
 
+       //If the current index WLinePoint is not "on"
+       // Find a valid entry. The call for the DynamicList member is not
+       // valid since the List is not ordered.
+       //Options:
+       //              1) Sort the list and call the method
+       //              2) Do not sort the list and perform the search manually.
+/****************FIX THIS!!!!***************************************
        if(!list[index].status_at_time(time))
                next_i=find_next_valid_entry(index,time);
        else
                next_i=index;
        prev_i=find_prev_valid_entry(index,time);
-
+********************************************************************/
        //synfig::info("index=%d, next_i=%d, prev_i=%d",index,next_i,prev_i);
 
+       // Get the previous and next WLinePoints
        next=(*list[next_i].value_node)(time);
        prev=(*list[prev_i].value_node)(time);
 
-       etl::hermite<Vector> 
curve(prev.get_vertex(),next.get_vertex(),prev.get_tangent2(),next.get_tangent1());
-       etl::derivative< etl::hermite<Vector> > deriv(curve);
-
-       synfig::WLinePoint WLine_point;
-       WLine_point.set_vertex(curve(origin));
-       
WLine_point.set_width((next.get_width()-prev.get_width())*origin+prev.get_width());
-       WLine_point.set_tangent1(deriv(origin)*min(1.0-origin,origin));
-       WLine_point.set_tangent2(WLine_point.get_tangent1());
-       WLine_point.set_split_tangent_flag(false);
-       WLine_point.set_origin(origin);
+       //Linear interpolation
+       synfig::WLinePoint wline_point;
+       
wline_point.set_pos((next.get_pos()-prev.get_pos())*origin+prev.get_pos());
+       
wline_point.set_width((next.get_width()-prev.get_width())*origin+prev.get_width());
+       wline_point.set_origin(origin);
 
-       ret.value_node=ValueNode_Composite::create(WLine_point);
+       ret.value_node=ValueNode_Composite::create(wline_point);
 
        return ret;
 }
 
-static int instance_count;
 
 ValueBase
 ValueNode_WLine::operator()(Time t)const
diff --git a/synfig-core/trunk/src/synfig/valuenode_wline.h 
b/synfig-core/trunk/src/synfig/valuenode_wline.h
index a166323..9173de1 100644
--- a/synfig-core/trunk/src/synfig/valuenode_wline.h
+++ b/synfig-core/trunk/src/synfig/valuenode_wline.h
@@ -84,7 +84,7 @@ public:
        //! index parameter and the previous valid one.
        //! @param index: The index where the Insert item action was performed
        //! @param time: The time to insert the item
-       virtual ListEntry create_list_entry(int index, Time time=0);
+       virtual ListEntry create_list_entry(int index, Time time=0, Real 
origin=0.5);
 
 protected:
 
diff --git a/synfig-core/trunk/src/synfig/wlinepoint.cpp 
b/synfig-core/trunk/src/synfig/wlinepoint.cpp
index 9f213be..9ae8c96 100644
--- a/synfig-core/trunk/src/synfig/wlinepoint.cpp
+++ b/synfig-core/trunk/src/synfig/wlinepoint.cpp
@@ -48,10 +48,22 @@ using namespace synfig;
 /* === M E T H O D S ======================================================= */
 
 WLinePoint::WLinePoint():
+       pos(0.0),
        width_(0.01),
-       origin_(0.0)
+       origin_(0.5),
        { };
 
+const float&
+WLinePoint::get_pos()const
+{
+       return pos_;
+}
+
+void
+WLinePoint::set_pos(float x)
+{
+       pos_=x;
+}
 
 const float&
 WLinePoint::get_width()const
diff --git a/synfig-core/trunk/src/synfig/wlinepoint.h 
b/synfig-core/trunk/src/synfig/wlinepoint.h
index 730eddf..c9c52ef 100644
--- a/synfig-core/trunk/src/synfig/wlinepoint.h
+++ b/synfig-core/trunk/src/synfig/wlinepoint.h
@@ -43,12 +43,24 @@ namespace synfig {
 class WLinePoint : public UniqueID
 {
 private:
+       //!The position of the WLinePoint in the [0,1] space
+       float   pos_;
+       //!The width of the WLinePoint
        float   width_;
+       //!The origin of the WLinePoint [0,1]
+       //! When set to 0 means that when the WLinePoint is "off"
+       //! and is rising to "on" it is interpolated from the previus
+       //! WLinePoint (closest small position). When it is set to 1
+       //! measn that when the WLinePoint is "off" and it is rising to
+       //! "on" it is interpolated from the next WLinePoint (closest
+       //! big position. 0.5 means averaged.
        float   origin_;
 
 public:
 
        WLinePoint();
+       const float& get_pos()const;
+       void set_pos(float x);
 
        const float& get_width()const;
        void set_width(float x);


------------------------------------------------------------------------------
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to