author | Francesco Abbate <francesco.bbt@gmail.com> | 2009年12月20日 17:05:43 +0000 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2009年12月20日 17:05:43 +0000 |
commit | 696960ab4ebee6f21c40247f8b726f2774f6fbc4 (patch) | |
tree | 12a0d2ce46235967acd504cb898f8006abab1bb9 /agg-plot | |
parent | 753f88ab670324e853028d98064691468d069e21 (diff) | |
download | gsl-shell-696960ab4ebee6f21c40247f8b726f2774f6fbc4.tar.gz |
-rw-r--r-- | agg-plot/c-drawables.cpp | 3 | ||||
-rw-r--r-- | agg-plot/lua-plot-priv.h | 9 | ||||
-rw-r--r-- | agg-plot/my_conv_simple_marker.h | 103 | ||||
-rw-r--r-- | agg-plot/plot.h | 1 | ||||
-rw-r--r-- | agg-plot/trans.h | 43 | ||||
-rw-r--r-- | agg-plot/xwin-show.cpp | 16 |
diff --git a/agg-plot/c-drawables.cpp b/agg-plot/c-drawables.cpp index 471a4c3f..7c724a7d 100644 --- a/agg-plot/c-drawables.cpp +++ b/agg-plot/c-drawables.cpp @@ -107,6 +107,9 @@ build_pipeline (vertex_source* in, struct trans_spec *base) stroke->line_join((agg::line_join_e) spec->content.stroke.line_join);
curr = stroke;
break;
+ case trans_marker:
+ curr = new trans::marker(in, spec->content.marker.size);
+ break;
case trans_curve:
curr = new trans::curve(in);
break;
diff --git a/agg-plot/lua-plot-priv.h b/agg-plot/lua-plot-priv.h index 915d94bb..aaa07a24 100644 --- a/agg-plot/lua-plot-priv.h +++ b/agg-plot/lua-plot-priv.h @@ -25,7 +25,6 @@ struct cmd_call_stack { struct agg_plot { CPLOT *plot; - pthread_mutex_t mutex[1]; int lua_is_owner; int is_shown; void *window; @@ -36,6 +35,7 @@ enum trans_type { trans_stroke = 0, trans_curve, trans_dash, + trans_marker, }; struct property_reg { @@ -53,11 +53,16 @@ struct dash_spec { double len[2]; }; +struct marker_spec { + double size; +}; + struct trans_spec { enum trans_type tag; union { struct stroke_spec stroke; struct dash_spec dash; + struct marker_spec marker; } content; }; @@ -67,6 +72,8 @@ extern struct property_reg line_join_properties[]; extern void agg_plot_destroy (struct agg_plot *cp); extern void update_callback (void *_app); +extern pthread_mutex_t agg_mutex[1]; + __END_DECLS #endif diff --git a/agg-plot/my_conv_simple_marker.h b/agg-plot/my_conv_simple_marker.h new file mode 100644 index 00000000..1e6011da --- /dev/null +++ b/agg-plot/my_conv_simple_marker.h @@ -0,0 +1,103 @@ +#ifndef MY_CONV_SIMPLE_MARKER_H +#define MY_CONV_SIMPLE_MARKER_H + +#include "agg_basics.h" +#include "agg_trans_affine.h" + +using namespace agg; + +namespace my { + //-------------------------------------------------------------conv_simple_marker + template<class MarkerLocator, class MarkerShapes> + class conv_simple_marker + { + public: + conv_simple_marker(MarkerLocator& ml, MarkerShapes& ms); + + void rewind(unsigned path_id); + unsigned vertex(double* x, double* y); + + private: + conv_simple_marker(const conv_simple_marker<MarkerLocator, MarkerShapes>&); + const conv_simple_marker<MarkerLocator, MarkerShapes>& + operator = (const conv_simple_marker<MarkerLocator, MarkerShapes>&); + + enum status_e + { + initial, + markers, + polygon, + stop + }; + + MarkerLocator* m_marker_locator; + MarkerShapes* m_marker_shapes; + status_e m_status; + double m_x1, m_y1; + }; + + + //------------------------------------------------------------------------ + template<class MarkerLocator, class MarkerShapes> + conv_simple_marker<MarkerLocator, MarkerShapes>::conv_simple_marker(MarkerLocator& ml, MarkerShapes& ms) : + m_marker_locator(&ml), + m_marker_shapes(&ms), + m_status(initial) + { + } + + + //------------------------------------------------------------------------ + template<class MarkerLocator, class MarkerShapes> + void conv_simple_marker<MarkerLocator, MarkerShapes>::rewind(unsigned) + { + m_status = initial; + } + + + //------------------------------------------------------------------------ + template<class MarkerLocator, class MarkerShapes> + unsigned conv_simple_marker<MarkerLocator, MarkerShapes>::vertex(double* x, double* y) + { + unsigned cmd = path_cmd_move_to; + + while(!is_stop(cmd)) + { + switch(m_status) + { + case initial: + m_marker_locator->rewind(0); + m_status = markers; + + case markers: + if(is_stop(m_marker_locator->vertex(&m_x1, &m_y1))) + { + cmd = path_cmd_stop; + m_status = stop; + break; + } + m_marker_shapes->rewind(0); + m_status = polygon; + + case polygon: + cmd = m_marker_shapes->vertex(x, y); + if(is_stop(cmd)) + { + cmd = path_cmd_move_to; + m_status = markers; + break; + } + *x += m_x1; + *y += m_y1; + return cmd; + + case stop: + cmd = path_cmd_stop; + break; + } + } + return cmd; + } +} + +#endif diff --git a/agg-plot/plot.h b/agg-plot/plot.h index 718843bd..f6f0bf09 100644 --- a/agg-plot/plot.h +++ b/agg-plot/plot.h @@ -56,7 +56,6 @@ public: container d(vs, color); m_elements.add(d); m_bbox_updated = false; - resource_manager::acquire(vs); }; virtual void draw(canvas &canvas) diff --git a/agg-plot/trans.h b/agg-plot/trans.h index 47eb5902..16bd7dfc 100644 --- a/agg-plot/trans.h +++ b/agg-plot/trans.h @@ -7,6 +7,9 @@ #include "agg_conv_dash.h"
#include "agg_conv_transform.h"
#include "agg_vcgen_markers_term.h"
+#include "agg_arrowhead.h"
+
+#include "my_conv_simple_marker.h"
#include "utils.h"
#include "vertex-source.h"
@@ -107,12 +110,11 @@ namespace trans { class line_base {
agg::trans_affine m_mtx;
-
agg::conv_transform<vertex_source> m_trans;
agg::conv_stroke<agg::conv_transform<vertex_source> > m_stroke;
public:
- line_base(vertex_source& src): m_mtx(), m_trans(src, m_mtx), m_stroke(m_trans)
+ line_base(vertex_source& src): m_trans(src, m_mtx), m_stroke(m_trans)
{};
void width(double w) { m_stroke.width(w); };
@@ -140,6 +142,43 @@ namespace trans { m_source->apply_transform(m, as);
};
};
+#if 0
+ template <class MarkerLocator, class MarkerShapes>
+ class marker_curve_base {
+ my::conv_simple_marker<MarkerLocator, MarkerShapes> m_marker;
+ agg::conv_curve<my::conv_simple_marker<MarkerLocator, MarkerShapes> > m_curve;
+ public:
+ marker_curve_base(MarkerLocator& src, MarkerShapes& ms):
+ m_marker(src, ms), m_curve(m_marker)
+ {};
+
+ void approximation_scale(double as)
+ {
+ m_curve.approximation_scale(as);
+ };
+
+ void rewind(unsigned path_id) { m_curve.rewind(path_id); };
+ unsigned vertex(double* x, double* y) { return m_curve.vertex(x, y); };
+ };
+#endif
+
+ typedef vs_trans_proxy<my::conv_simple_marker<vertex_source, agg::ellipse> > vs_marker_ellipse;
+
+ class marker : public vs_marker_ellipse {
+ agg::ellipse m_ellipse;
+
+ public:
+ marker(vertex_source* src, double size): vs_marker_ellipse(src, m_ellipse)
+ {
+ m_ellipse.init(0.0, 0.0, size/2, size/2);
+ };
+
+ virtual void apply_transform(agg::trans_affine& m, double as)
+ {
+ m_ellipse.approximation_scale(as);
+ m_source->apply_transform(m, as);
+ };
+ };
class resize : public vs_transform {
agg::trans_affine m_matrix;
diff --git a/agg-plot/xwin-show.cpp b/agg-plot/xwin-show.cpp index 60fe108d..494a112c 100644 --- a/agg-plot/xwin-show.cpp +++ b/agg-plot/xwin-show.cpp @@ -36,9 +36,9 @@ public: virtual void on_draw() { - pthread_mutex_lock (m_plot->mutex); + pthread_mutex_lock (agg_mutex); on_draw_unprotected(); - pthread_mutex_unlock (m_plot->mutex); + pthread_mutex_unlock (agg_mutex); } private: @@ -59,7 +59,7 @@ xwin_thread_function (void *_plot) platform_support_prepare(); - pthread_mutex_lock (p->mutex); + pthread_mutex_lock (agg_mutex); the_application app(agg::pix_format_bgr24, flip_y, p); app.caption("GSL shell plot"); @@ -67,24 +67,24 @@ xwin_thread_function (void *_plot) if(app.init(780, 400, agg::window_resize)) { p->window = (void *) &app; - pthread_mutex_unlock (p->mutex); + pthread_mutex_unlock (agg_mutex); app.run(); } else { - pthread_mutex_unlock (p->mutex); + pthread_mutex_unlock (agg_mutex); } - pthread_mutex_lock (p->mutex); + pthread_mutex_lock (agg_mutex); p->window = NULL; if (p->lua_is_owner) { p->is_shown = 0; - pthread_mutex_unlock (p->mutex); + pthread_mutex_unlock (agg_mutex); } else { - pthread_mutex_unlock (p->mutex); + pthread_mutex_unlock (agg_mutex); agg_plot_destroy (p); } |