X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Fvaluenode_bline.cpp;h=fe68bfe2ce80291d8f6918da9f3f40ef1f5cba24;hb=188d044b0046861cbdf33514819dae0720405fb2;hp=c8259fcaafbeeca7f93865a3d714b010e85ee1d2;hpb=e3acc0b267b14fda5db3c7bbb2f218b993ef84b3;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/valuenode_bline.cpp b/synfig-core/trunk/src/synfig/valuenode_bline.cpp index c8259fc..fe68bfe 100644 --- a/synfig-core/trunk/src/synfig/valuenode_bline.cpp +++ b/synfig-core/trunk/src/synfig/valuenode_bline.cpp @@ -1,20 +1,21 @@ -/* === S I N F G =========================================================== */ +/* === S Y N F I G ========================================================= */ /*! \file valuenode_bline.cpp ** \brief Template File ** ** $Id: valuenode_bline.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** \endlegal */ /* ========================================================================= */ @@ -47,7 +48,7 @@ using namespace std; using namespace etl; -using namespace sinfg; +using namespace synfig; /* === M A C R O S ========================================================= */ @@ -64,32 +65,32 @@ radial_interpolation(const Vector& a, const Vector& b, float c) { affine_combo mag_combo; affine_combo ang_combo; - + Real mag(mag_combo(a.mag(),b.mag(),c)); Angle ang(ang_combo(Angle::tan(a[1],a[0]),Angle::tan(b[1],b[0]),c)); - + return Point( mag*Angle::cos(ang).get(),mag*Angle::sin(ang).get() ); } ValueBase -sinfg::convert_bline_to_segment_list(const ValueBase& bline) +synfig::convert_bline_to_segment_list(const ValueBase& bline) { std::vector ret; - + // std::vector list(bline.operator std::vector()); //std::vector list(bline); std::vector list(bline.get_list().begin(),bline.get_list().end()); std::vector::const_iterator iter; BLinePoint prev,first; - + //start with prev = first and iter on the second... - + if(list.empty()) return ValueBase(ret,bline.get_loop()); first = prev = list.front(); - + for(iter=++list.begin();iter!=list.end();++iter) { ret.push_back( @@ -101,7 +102,7 @@ sinfg::convert_bline_to_segment_list(const ValueBase& bline) ) ); prev=*iter; - } + } if(bline.get_loop()) { ret.push_back( @@ -117,17 +118,17 @@ sinfg::convert_bline_to_segment_list(const ValueBase& bline) } ValueBase -sinfg::convert_bline_to_width_list(const ValueBase& bline) +synfig::convert_bline_to_width_list(const ValueBase& bline) { std::vector ret; // std::vector list(bline.operator std::vector()); //std::vector list(bline); std::vector list(bline.get_list().begin(),bline.get_list().end()); std::vector::const_iterator iter; - + if(bline.empty()) return ValueBase(ValueBase::TYPE_LIST); - + for(iter=list.begin();iter!=list.end();++iter) ret.push_back(iter->get_width()); @@ -155,7 +156,7 @@ ValueNode_BLine::create(const ValueBase &value) { if(value.get_type()!=ValueBase::TYPE_LIST) return 0; - + ValueNode_BLine* value_node(new ValueNode_BLine()); if(!value.empty()) @@ -170,7 +171,7 @@ ValueNode_BLine::create(const ValueBase &value) std::vector::const_iterator iter; for(iter=bline_points.begin();iter!=bline_points.end();iter++) - { + { value_node->add(ValueNode::Handle(ValueNode_Composite::create(*iter))); } value_node->set_loop(value.get_loop()); @@ -182,7 +183,7 @@ ValueNode_BLine::create(const ValueBase &value) // into a list of BLinePoints. We make an assumption // that the segment list is continuous(sp), but not necessarily // smooth. - + value_node->set_loop(false); // std::vector segments(value.operator std::vector()); // std::vector segments(value); @@ -190,9 +191,9 @@ ValueNode_BLine::create(const ValueBase &value) std::vector::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(BLinePoint()) #define FIRST_POINT first->get_value().get(BLinePoint()) #define CURR_POINT curr->get_value().get(BLinePoint()) @@ -201,7 +202,7 @@ ValueNode_BLine::create(const ValueBase &value) prev=ValueNode_Const::create(ValueBase::TYPE_BLINEPOINT); { BLinePoint prev_point(PREV_POINT); - prev_point.set_vertex(iter->p1); + prev_point.set_vertex(iter->p1); prev_point.set_tangent1(iter->t1); prev_point.set_width(0.01); prev_point.set_origin(0.5); @@ -210,7 +211,7 @@ ValueNode_BLine::create(const ValueBase &value) } first=prev; value_node->add(ValueNode::Handle(prev)); - + } if(iter==last && iter->p2.is_equal_to(FIRST_POINT.get_vertex())) { @@ -223,12 +224,12 @@ ValueNode_BLine::create(const ValueBase &value) } continue; } - + ValueNode_Const::Handle curr; curr=ValueNode_Const::create(ValueBase::TYPE_BLINEPOINT); { BLinePoint curr_point(CURR_POINT); - curr_point.set_vertex(iter->p2); + curr_point.set_vertex(iter->p2); curr_point.set_tangent1(iter->t2); curr_point.set_width(0.01); curr_point.set_origin(0.5); @@ -245,7 +246,7 @@ ValueNode_BLine::create(const ValueBase &value) value_node->add(ValueNode::Handle(curr)); prev=curr; } - + } break; default: @@ -255,8 +256,8 @@ ValueNode_BLine::create(const ValueBase &value) break; } } - - + + return value_node; } @@ -265,8 +266,8 @@ ValueNode_BLine::create_list_entry(int index, Time time, Real origin) { ValueNode_BLine::ListEntry ret; - - sinfg::BLinePoint prev,next; + + synfig::BLinePoint prev,next; int prev_i,next_i; @@ -281,25 +282,25 @@ ValueNode_BLine::create_list_entry(int index, Time time, Real origin) else next_i=index; prev_i=find_prev_valid_entry(index,time); - - sinfg::info("index=%d, next_i=%d, prev_i=%d",index,next_i,prev_i); - + + synfig::info("index=%d, next_i=%d, prev_i=%d",index,next_i,prev_i); + next=(*list[next_i].value_node)(time); prev=(*list[prev_i].value_node)(time); - + etl::hermite curve(prev.get_vertex(),next.get_vertex(),prev.get_tangent2(),next.get_tangent1()); etl::derivative< etl::hermite > deriv(curve); - sinfg::BLinePoint bline_point; + synfig::BLinePoint bline_point; bline_point.set_vertex(curve(origin)); bline_point.set_width((next.get_width()-prev.get_width())*origin+prev.get_width()); bline_point.set_tangent1(deriv(origin)*min(1.0-origin,origin)); bline_point.set_tangent2(bline_point.get_tangent1()); bline_point.set_split_tangent_flag(false); bline_point.set_origin(origin); - + ret.value_node=ValueNode_Composite::create(bline_point); - + return ret; } @@ -307,23 +308,23 @@ ValueBase ValueNode_BLine::operator()(Time t)const { std::vector ret_list; - + std::vector::const_iterator iter,first_iter; bool first_flag(true); bool rising; int index(0); float next_scale(1.0f); - + BLinePoint prev,first; first.set_origin(100.0f); - + for(iter=list.begin();iter!=list.end();++iter,index++) { float amount(iter->amount_at_time(t,&rising)); - + assert(amount>=0.0f); assert(amount<=1.0f); - + if(amount==1.0f) { if(first_flag) @@ -334,10 +335,10 @@ ValueNode_BLine::operator()(Time t)const ret_list.push_back(first); continue; } - + BLinePoint curr; curr=(*iter->value_node)(t).get(prev); - + if(next_scale!=1.0f) { ret_list.back().set_split_tangent_flag(true); @@ -356,28 +357,28 @@ ValueNode_BLine::operator()(Time t)const ret_list.push_back(curr); } - + prev=curr; } else if(amount>0.0f) { std::vector::const_iterator begin_iter,end_iter; - + // This is where the interesting stuff happens // We need to seek forward in the list to see what the next // active point is - + BLinePoint curr; BLinePoint begin; // begin of dynamic group BLinePoint end; // End of dynamic group Time blend_time; int dist_from_begin(0), dist_from_end(0); BLinePoint ret; - + Time begin_time; Time end_time; - + if(!rising) { try{ end_time=iter->find_prev(t)->get_time(); } @@ -393,10 +394,10 @@ ValueNode_BLine::operator()(Time t)const catch(...) { end_time=Time::end(); } } blend_time=begin_time; - curr=(*iter->value_node)(end_time).get(curr); + curr=(*iter->value_node)(end_time).get(curr); // curr=(*iter->value_node)(t).get(curr); - + // Find "end" of dynamic group end_iter=iter; // for(++end_iter;begin_iter!=list.end();++end_iter) @@ -406,7 +407,7 @@ ValueNode_BLine::operator()(Time t)const end=(*end_iter->value_node)(blend_time).get(prev); break; } - + // If we did not find an end of the dynamic group... if(end_iter==list.end()) { @@ -437,10 +438,10 @@ ValueNode_BLine::operator()(Time t)const else break; } - + --begin_iter; dist_from_begin++; - + if(begin_iter==iter) break; @@ -450,7 +451,7 @@ ValueNode_BLine::operator()(Time t)const break; } }while(begin_iter!=iter); - + // If we did not find a begin if(begin.get_origin()==100.0f) { @@ -468,23 +469,23 @@ ValueNode_BLine::operator()(Time t)const // begin=first; } } - + etl::hermite curve(begin.get_vertex(),end.get_vertex(),begin.get_tangent2(),end.get_tangent1()); etl::derivative< etl::hermite > deriv(curve); - + ret.set_vertex(curve(curr.get_origin())); ret.set_width((end.get_width()-begin.get_width())*curr.get_origin()+begin.get_width()); ret.set_tangent1(deriv(curr.get_origin())); ret.set_tangent2(deriv(curr.get_origin())); - + float prev_tangent_scalar(1.0f); float next_tangent_scalar(1.0f); - - //sinfg::info("index_%d:dist_from_begin=%d",index,dist_from_begin); - //sinfg::info("index_%d:dist_from_end=%d",index,dist_from_end); - + + //synfig::info("index_%d:dist_from_begin=%d",index,dist_from_begin); + //synfig::info("index_%d:dist_from_end=%d",index,dist_from_end); + // If we are the next to the begin if(begin_iter==--std::vector::const_iterator(iter) || dist_from_begin==1) { @@ -493,7 +494,7 @@ ValueNode_BLine::operator()(Time t)const else { float origin=curr.get_origin()-prev.get_origin(); - prev_tangent_scalar=(1.0f-origin)*amount+origin; + prev_tangent_scalar=(1.0f-origin)*amount+origin; } // If we are the next to the end @@ -508,10 +509,10 @@ ValueNode_BLine::operator()(Time t)const BLinePoint next; next=((*(++std::vector::const_iterator(iter))->value_node)(t).get(prev)); float origin=next.get_origin()-curr.get_origin(); - next_tangent_scalar=(1.0f-origin)*amount+origin; + next_tangent_scalar=(1.0f-origin)*amount+origin; } next_scale=next_tangent_scalar; - + //ret.set_vertex((curr.get_vertex()-ret.get_vertex())*amount+ret.get_vertex()); if(false) { @@ -551,7 +552,7 @@ ValueNode_BLine::operator()(Time t)const Point begin_cord_sys[2], begin_cord_origin; Point end_cord_sys[2], end_cord_origin; Point curr_cord_sys[2], curr_cord_origin; - + { const Point a((*end_iter->value_node)(begin_time).get(prev).get_vertex()); const Point b((*begin_iter->value_node)(begin_time).get(prev).get_vertex()); @@ -573,7 +574,7 @@ ValueNode_BLine::operator()(Time t)const curr_cord_sys[0]=( b - a ).norm(); curr_cord_sys[1]=curr_cord_sys[0].perp(); } - + /* end_cord_origin=(*end_iter->value_node)(end_time).get(prev).get_vertex(); end_cord_sys[0]=( @@ -581,7 +582,7 @@ ValueNode_BLine::operator()(Time t)const end_cord_origin ).norm(); end_cord_sys[1]=end_cord_sys[0].perp(); - + curr_cord_origin=(*end_iter->value_node)(t).get(prev).get_vertex(); curr_cord_sys[0]=( (*begin_iter->value_node)(t).get(prev).get_vertex() - @@ -589,7 +590,7 @@ ValueNode_BLine::operator()(Time t)const ).norm(); curr_cord_sys[1]=curr_cord_sys[0].perp(); */ - + // Convert start point Point a; Vector at1,at2; @@ -598,12 +599,12 @@ ValueNode_BLine::operator()(Time t)const a[0]=tmp*begin_cord_sys[0]; a[1]=tmp*begin_cord_sys[1]; #define COORD_SYS_RADIAL_TAN_INTERP 1 - + #ifdef COORD_SYS_RADIAL_TAN_INTERP tmp=ret.get_tangent1()+ret.get_vertex()-begin_cord_origin; at1[0]=tmp*begin_cord_sys[0]; at1[1]=tmp*begin_cord_sys[1]; - + if(curr.get_split_tangent_flag()) { tmp=ret.get_tangent2()+ret.get_vertex()-begin_cord_origin; @@ -612,7 +613,7 @@ ValueNode_BLine::operator()(Time t)const } #endif } - + // Convert finish point Point b; Vector bt1,bt2; @@ -620,7 +621,7 @@ ValueNode_BLine::operator()(Time t)const Point tmp(curr.get_vertex()-end_cord_origin); b[0]=tmp*end_cord_sys[0]; b[1]=tmp*end_cord_sys[1]; - + #ifdef COORD_SYS_RADIAL_TAN_INTERP tmp=curr.get_tangent1()+curr.get_vertex()-end_cord_origin; bt1[0]=tmp*end_cord_sys[0]; @@ -634,7 +635,7 @@ ValueNode_BLine::operator()(Time t)const } #endif } - + // Convert current point Point c; Vector ct1,ct2; @@ -649,14 +650,14 @@ ValueNode_BLine::operator()(Time t)const #define INTERP_FUNCTION radial_interpolation //#define INTERP_FUNCTION linear_interpolation - + #ifdef COORD_SYS_RADIAL_TAN_INTERP tmp=INTERP_FUNCTION(at1,bt1,amount); ct1[0]=tmp*curr_cord_sys[0]; ct1[1]=tmp*curr_cord_sys[1]; ct1+=curr_cord_origin; ct1-=c; - + if(curr.get_split_tangent_flag()) { tmp=INTERP_FUNCTION(at2,bt2,amount); @@ -674,17 +675,17 @@ ValueNode_BLine::operator()(Time t)const ret.set_split_tangent_flag(curr.get_split_tangent_flag()); if(ret.get_split_tangent_flag()) ret.set_tangent2(radial_interpolation(ret.get_tangent2(),curr.get_tangent2(),amount)); -#else +#else ret.set_tangent1(ct1); ret.set_split_tangent_flag(curr.get_split_tangent_flag()); if(ret.get_split_tangent_flag()) ret.set_tangent2(ct2); #endif } - + ret.set_origin(curr.get_origin()); ret.set_width((curr.get_width()-ret.get_width())*amount+ret.get_width()); - + // Handle the case where we are the first vertex if(first_flag) @@ -707,7 +708,7 @@ ValueNode_BLine::operator()(Time t)const prev=ret; } } - + if(next_scale!=1.0f) { ret_list.back().set_split_tangent_flag(true); @@ -727,12 +728,12 @@ ValueNode_BLine::operator()(Time t)const ); } */ - + if(list.empty()) - sinfg::warning(string("ValueNode_BLine::operator()():")+_("No entries in list")); + synfig::warning(string("ValueNode_BLine::operator()():")+_("No entries in list")); else if(ret_list.empty()) - sinfg::warning(string("ValueNode_BLine::operator()():")+_("No entries in ret_list")); + synfig::warning(string("ValueNode_BLine::operator()():")+_("No entries in ret_list")); return ValueBase(ret_list,get_loop()); } @@ -742,7 +743,7 @@ ValueNode_BLine::link_local_name(int i)const { assert(i>=0 && (unsigned)iset_guid(get_guid()^deriv_guid); - + std::vector::const_iterator iter; for(iter=list.begin();iter!=list.end();++iter) @@ -769,7 +770,7 @@ ValueNode_BLine::clone(const GUID& deriv_guid)const } } ret->set_loop(get_loop()); - + return ret; }