1 /*! ========================================================================
4 ** $Id: region.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
31 #include <ETL/stringf>
33 #include <ETL/hermite>
35 #include <sinfg/string.h>
36 #include <sinfg/time.h>
37 #include <sinfg/context.h>
38 #include <sinfg/paramdesc.h>
39 #include <sinfg/renddesc.h>
40 #include <sinfg/surface.h>
41 #include <sinfg/value.h>
42 #include <sinfg/valuenode.h>
43 #include <sinfg/segment.h>
44 #include <sinfg/valuenode_bline.h>
50 /* === M A C R O S ========================================================= */
54 /* === G L O B A L S ======================================================= */
56 SINFG_LAYER_INIT(Region);
57 SINFG_LAYER_SET_NAME(Region,"region");
58 SINFG_LAYER_SET_LOCAL_NAME(Region,_("Region"));
59 SINFG_LAYER_SET_CATEGORY(Region,_("Geometry"));
60 SINFG_LAYER_SET_VERSION(Region,"0.1");
61 SINFG_LAYER_SET_CVS_ID(Region,"$Id: region.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
63 /* === P R O C E D U R E S ================================================= */
65 /* === M E T H O D S ======================================================= */
67 /* === E N T R Y P O I N T ================================================= */
72 vector<BLinePoint> bline_point_list;
73 bline_point_list.push_back(BLinePoint());
74 bline_point_list.push_back(BLinePoint());
75 bline_point_list.push_back(BLinePoint());
76 bline_point_list[0].set_vertex(Point(0,1));
77 bline_point_list[1].set_vertex(Point(0,-1));
78 bline_point_list[2].set_vertex(Point(1,0));
79 bline_point_list[0].set_tangent(bline_point_list[1].get_vertex()-bline_point_list[2].get_vertex()*0.5f);
80 bline_point_list[1].set_tangent(bline_point_list[2].get_vertex()-bline_point_list[0].get_vertex()*0.5f);
81 bline_point_list[2].set_tangent(bline_point_list[0].get_vertex()-bline_point_list[1].get_vertex()*0.5f);
82 bline_point_list[0].set_width(1.0f);
83 bline_point_list[1].set_width(1.0f);
84 bline_point_list[2].set_width(1.0f);
85 bline=bline_point_list;
91 if(bline.get_contained_type()==ValueBase::TYPE_BLINEPOINT)
93 segment_list=convert_bline_to_segment_list(bline);
97 sinfg::warning("Region: incorrect type on bline, layer disabled");
102 if(segment_list.empty())
104 sinfg::warning("Region: segment_list is empty, layer disabled");
109 bool looped = bline.get_loop();
111 Vector::value_type n;
112 etl::hermite<Vector> curve;
113 vector<Point> vector_list;
115 vector<Segment>::const_iterator iter=segment_list.begin();
116 //Vector last = iter->p1;
118 //make sure the shape has a clean slate for writing
121 //and start off at the first point
122 //move_to(last[0],last[1]);
124 for(;iter!=segment_list.end();++iter)
126 //connect them with a line if they aren't already joined
127 /*if(iter->p1 != last)
129 line_to(iter->p1[0],iter->p1[1]);
132 //curve to the next end point
133 curve_to(iter->p1[0] + iter->t1[0]/3.0,iter->p1[1] + iter->t1[1]/3.0,
134 iter->p2[0] - iter->t2[0]/3.0,iter->p2[1] - iter->t2[1]/3.0,
135 iter->p2[0],iter->p2[1]);
139 if(iter->t1.is_equal_to(Vector(0,0)) && iter->t2.is_equal_to(Vector(0,0)))
141 vector_list.push_back(iter->p2);
151 for(n=0.0;n<1.0;n+=1.0/SAMPLES)
152 vector_list.push_back(curve(n));
156 //add a single point onto the end so it actually fits the shape, so we can be awesome...
159 vector_list.push_back(curve.p2());
163 add_polygon(vector_list);
170 Region::set_param(const String & param, const ValueBase &value)
172 if(param=="segment_list")
174 if(dynamic_param_list().count("segment_list"))
176 connect_dynamic_param("bline",dynamic_param_list().find("segment_list")->second);
177 disconnect_dynamic_param("segment_list");
178 sinfg::warning("Region::set_param(): Updated valuenode connection to use the new \"bline\" parameter.");
181 sinfg::warning("Region::set_param(): The parameter \"segment_list\" is deprecated. Use \"bline\" instead.");
184 if( (param=="segment_list" || param=="bline") && value.get_type()==ValueBase::TYPE_LIST)
186 //if(value.get_contained_type()!=ValueBase::TYPE_BLINEPOINT)
194 /* if( param=="segment_list" && value.get_type()==ValueBase::TYPE_LIST)
196 if(value.get_contained_type()==ValueBase::TYPE_BLINEPOINT)
197 segment_list=convert_bline_to_segment_list(value);
199 if(value.get_contained_type()==ValueBase::TYPE_SEGMENT)
203 segment_list.clear();
210 return Layer_Shape::set_param(param,value);
214 Region::get_param(const String& param)const
220 return Layer_Shape::get_param(param);
224 Region::get_param_vocab()const
226 Layer::Vocab ret(Layer_Shape::get_param_vocab());
228 ret.push_back(ParamDesc("bline")
229 .set_local_name(_("Vertices"))
230 .set_origin("offset")
237 Region::set_time(Context context, Time time)const
239 const_cast<Region*>(this)->sync();
240 context.set_time(time);
244 Region::set_time(Context context, Time time, Vector pos)const
246 const_cast<Region*>(this)->sync();
247 context.set_time(time,pos);