The main function defines a GeoWin geow and a list<point>
LP . The points are generated using an input scene sc_points
of geow . The convex hull is represented by a result
scene sc_hull using convex_hull as the
update object, sc_points as input scene, and "Convex
Hull" as the name of the scene. geo_scene is a
typedef for GeoScene* .
The boundary drawing color for sc_hull is set to blue
and the scene is made visible.
Finally, geow is opened in interactive
mode with edit scene sc_points . (See also Create
and Open GeoWin.)
On the right there is a screenshot of the program after adding
some points interactively. Clicking on the picture shows the GeoWin
in original
size.
|
 |
#include <LEDA/geowin.h>
#include <LEDA/float_geo_alg.h>
using namespace leda;
class geo_bezier : public geowin_update<list<point>,list<polygon> >,
public geowin_redraw_container<list<polygon> >
{
list<point> act;
public:
virtual ~geo_bezier() { }
void update(const list<point>& L, list<polygon>& LP)
{
act = L;
LP.clear();
LP.append(CONVEX_HULL_POLY(L));
}
bool draw(const list<polygon>& L,window& W,color c1,color c2,
double x1,double y1,double x2,double y2)
{
// draw the hull polygon and the bezier curve ...
if (! L.empty() ) W << L.head();
else return false;
W.draw_bezier(act,100,red);
return false;
}
};
geo_bezier CHULL;
int main()
{
GeoWin gw("Bezier curve");
list<point> LP;
geo_scene sc0 = gw.new_scene(LP, "Control points");
gw.set_point_style(sc0, disc_point);
geo_scene res = gw.new_scene(CHULL, CHULL, sc0, "Bezier curve");
gw.set_line_width(res, 2);
gw.set_color(res, blue);
gw.set_all_visible(true);
gw.message("We show the convex hull of the control points \
and the bezier curve defined by them");
gw.edit(sc0);
return 0;
}
|