gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年07月30日 14:04:37 +0200
committerfrancesco-ST <francesco.abbate@st.com>2010年07月30日 14:04:37 +0200
commit975bbb0229edfb8ca2be826994f5422a0c8d6c38 (patch)
treee9e9c6403e321597a276d7288d4c449d12d5d2c9 /agg-plot
parentd28a8f579f2e902f5bced91cbb726f7eca32b3a1 (diff)
downloadgsl-shell-975bbb0229edfb8ca2be826994f5422a0c8d6c38.tar.gz
modified transformation hierarchy to use templates
Now trans is a parametrised class that gives uniform acess to drawable and scalable objects.
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/Makefile 2
-rw-r--r--agg-plot/drawable.cpp 3
-rw-r--r--agg-plot/drawable.h 21
-rw-r--r--agg-plot/markers.cpp 62
-rw-r--r--agg-plot/markers.h 13
-rw-r--r--agg-plot/path.h 4
-rw-r--r--agg-plot/plot.h 10
-rw-r--r--agg-plot/scalable.h 41
-rw-r--r--agg-plot/trans.cpp 0
-rw-r--r--agg-plot/trans.h 155
-rw-r--r--agg-plot/utils.cpp 11
-rw-r--r--agg-plot/utils.h 7
-rw-r--r--agg-plot/window-trans.h 48
-rw-r--r--agg-plot/wtest.cpp 11
14 files changed, 303 insertions, 85 deletions
diff --git a/agg-plot/Makefile b/agg-plot/Makefile
index 0f431a9d..196eb2d2 100644
--- a/agg-plot/Makefile
+++ b/agg-plot/Makefile
@@ -44,7 +44,7 @@ endif
INCLUDES += $(AGG_INCLUDES) -I$(GSH_BASE_DIR) -I$(LUADIR)/src
-AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp trans.cpp lua-draw.cpp agg-parse-trans.cpp canvas-window.cpp plot-window.cpp
+AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp trans.cpp markers.cpp lua-draw.cpp agg-parse-trans.cpp canvas-window.cpp plot-window.cpp
AGGPLOT_OBJ_FILES := $(AGGPLOT_SRC_FILES:%.cpp=%.o)
diff --git a/agg-plot/drawable.cpp b/agg-plot/drawable.cpp
index 9bc80293..d2d18354 100644
--- a/agg-plot/drawable.cpp
+++ b/agg-plot/drawable.cpp
@@ -10,8 +10,7 @@ void
window_scalable::apply_transform(const agg::trans_affine& m)
{
m_trans.transformer(m);
- double as = trans_affine_max_norm (m);
- m_source->approximation_scale (as);
+ m_source->approximation_scale (m.scale());
}
void
diff --git a/agg-plot/drawable.h b/agg-plot/drawable.h
index a8b4abb9..67304ba1 100644
--- a/agg-plot/drawable.h
+++ b/agg-plot/drawable.h
@@ -54,4 +54,25 @@ public:
virtual bool dispose();
};
+template<class conv_type>
+class drawable_adapter : public vs_adapter<conv_type, drawable> {
+ typedef vs_adapter<conv_type, drawable> root_type;
+
+public:
+ drawable_adapter(drawable *src) : root_type(src) { };
+
+ template <class init_type>
+ drawable_adapter(scalable* src, init_type& val): root_type(src, val) {};
+
+ virtual void apply_transform(const agg::trans_affine& m)
+ {
+ this->m_source->apply_transform(m);
+ };
+
+ virtual void bounding_box(double *x1, double *y1, double *x2, double *y2)
+ {
+ this->m_source->bounding_box(x1, y1, x2, y2);
+ }
+};
+
#endif
diff --git a/agg-plot/markers.cpp b/agg-plot/markers.cpp
new file mode 100644
index 00000000..72289e6b
--- /dev/null
+++ b/agg-plot/markers.cpp
@@ -0,0 +1,62 @@
+
+#include <math.h>
+
+#include "markers.h"
+#include "scalable.h"
+
+#include "agg_path_storage.h"
+#include "agg_ellipse.h"
+
+struct symbol_reg {
+ const char *name;
+ scalable *path;
+};
+
+static vs_proxy<agg::ellipse, false> s_circle;
+static vs_proxy<agg::path_storage, false> s_square, s_triangle;
+
+static struct symbol_reg symbol_table[] = {
+ {"circle", &s_circle},
+ {"square", &s_square},
+ {"triangle", &s_triangle},
+ {NULL, NULL}
+};
+
+static scalable& s_default = s_circle;
+
+namespace markers {
+
+ void init()
+ {
+ agg::ellipse& ellipse = s_circle.self();
+ ellipse.init(0.0, 0.0, 0.5, 0.5);
+
+ agg::path_storage& square = s_square.self();
+
+ square.move_to(-0.5, -0.5);
+ square.line_to( 0.5, -0.5);
+ square.line_to( 0.5, 0.5);
+ square.line_to(-0.5, 0.5);
+ square.close_polygon();
+
+ agg::path_storage& triangle = s_triangle.self();
+
+ double ht = 0.86602540378444;
+ triangle.move_to(-0.5, -ht/3);
+ triangle.line_to( 0.5, -ht/3);
+ triangle.line_to( 0.0, 2*ht/3);
+ triangle.close_polygon();
+ }
+
+ scalable& get (const char *req_name)
+ {
+ struct symbol_reg *reg;
+ for (reg = symbol_table; reg->name != NULL; reg++)
+ {
+ if (strcmp (reg->name, req_name) == 0)
+ return *reg->path;
+ }
+ return s_default;
+ }
+
+}
diff --git a/agg-plot/markers.h b/agg-plot/markers.h
new file mode 100644
index 00000000..f7ffd2a1
--- /dev/null
+++ b/agg-plot/markers.h
@@ -0,0 +1,13 @@
+#ifndef AGGPLOT_MARKERS_H
+#define AGGPLOT_MARKERS_H
+
+#include "scalable.h"
+
+namespace markers {
+
+ extern void init();
+
+ extern scalable& get(const char *name);
+}
+
+#endif
diff --git a/agg-plot/path.h b/agg-plot/path.h
index 28b3c151..c16a8cef 100644
--- a/agg-plot/path.h
+++ b/agg-plot/path.h
@@ -1,5 +1,5 @@
-#ifndef AGGPLOT_DRAWABLES_H
-#define AGGPLOT_DRAWABLES_H
+#ifndef AGGPLOT_PATH_H
+#define AGGPLOT_PATH_H
#include "scalable.h"
diff --git a/agg-plot/plot.h b/agg-plot/plot.h
index caa9ec7c..8754360c 100644
--- a/agg-plot/plot.h
+++ b/agg-plot/plot.h
@@ -23,6 +23,16 @@
#include "agg_gsv_text.h"
+static void
+bbox_enlarge(double *x1, double* y1, double* x2, double* y2,
+ double x, double y)
+{
+ if (x < *x1) *x1 = x;
+ if (y < *y1) *y1 = y;
+ if (x > *x2) *x2 = x;
+ if (y > *y2) *y2 = y;
+}
+
template<class VertexSource, class resource_manager = no_management>
class plot {
diff --git a/agg-plot/scalable.h b/agg-plot/scalable.h
index 30ee655d..2f0188ee 100644
--- a/agg-plot/scalable.h
+++ b/agg-plot/scalable.h
@@ -28,8 +28,8 @@ public:
virtual ~scalable() { };
};
-/* This class is basically a wrapper around a native AGG vertex_source object
- that implements the "scalable" interface. */
+/* This class is basically a wrapper around a native AGG vertex_source object.
+ The wrapper implements the "scalable" interface. */
template <class T, bool system_managed>
class vs_proxy : public scalable {
T m_base;
@@ -43,7 +43,7 @@ public:
virtual void approximation_scale(double as) { };
virtual bool dispose() { return (system_managed ? false : true); };
- T& get_base() { return m_base; };
+ T& self() { return m_base; };
};
/* this class does work does permit to perform an AGG transformation
@@ -56,6 +56,8 @@ protected:
base_type* m_source;
public:
+ typedef conv_type self_type;
+
vs_adapter(base_type* src): m_output(*src), m_source(src)
{
};
@@ -85,4 +87,37 @@ public:
conv_type& self() { return m_output; };
};
+template<class conv_type>
+class scalable_adapter : public vs_adapter<conv_type, scalable> {
+ typedef vs_adapter<conv_type, scalable> root_type;
+
+public:
+ scalable_adapter(scalable *src) : root_type(src) { };
+
+ template <class init_type>
+ scalable_adapter(scalable* src, init_type& val): root_type(src, val) {};
+
+ virtual void approximation_scale(double as)
+ {
+ this->m_source->approximation_scale(as);
+ };
+};
+
+template<class conv_type>
+class scalable_adapter_approx : public vs_adapter<conv_type, scalable> {
+ typedef vs_adapter<conv_type, scalable> root_type;
+
+public:
+ scalable_adapter_approx(scalable *src) : root_type(src) { };
+
+ template <class init_type>
+ scalable_adapter_approx(scalable* src, init_type& val): root_type(src, val) {};
+
+ virtual void approximation_scale(double as)
+ {
+ this->m_output.approximation_scale(as);
+ this->m_source->approximation_scale(as);
+ };
+};
+
#endif
diff --git a/agg-plot/trans.cpp b/agg-plot/trans.cpp
deleted file mode 100644
index e69de29b..00000000
--- a/agg-plot/trans.cpp
+++ /dev/null
diff --git a/agg-plot/trans.h b/agg-plot/trans.h
index 069d9489..9d5a1dbf 100644
--- a/agg-plot/trans.h
+++ b/agg-plot/trans.h
@@ -2,17 +2,20 @@
#define AGGPLOT_TRANS_H
#include "scalable.h"
+#include "drawable.h"
+#include "markers.h"
#include "utils.h"
+#include "agg_trans_affine.h"
+#include "agg_path_storage.h"
+
#include "agg_conv_stroke.h"
#include "agg_conv_curve.h"
#include "agg_conv_dash.h"
-#include "agg_trans_affine.h"
#include "agg_conv_transform.h"
+#include "agg_conv_contour.h"
-#include "my_conv_simple_marker.h"
-#include "agg_ellipse.h"
-
+/*
template <class conv_type>
class scalable_adapter : public vs_adapter<conv_type, scalable>
{
@@ -52,17 +55,111 @@ public:
this->m_source->approximation_scale(as);
};
};
+*/
-typedef scalable_adapter<agg::conv_transform<scalable> > vs_affine;
+struct scalable_context {
-namespace trans {
+ template <class conv_type>
+ class simple : public scalable_adapter<conv_type> {
+ typedef scalable_adapter<conv_type> root_type;
+ public:
+ simple(scalable *src) : root_type(src) {};
+
+ template <class init_type>
+ simple(scalable* src, init_type& val): root_type(src, val) {};
+ };
+
+ template <class conv_type>
+ class approx : public scalable_adapter_approx<conv_type> {
+ typedef scalable_adapter_approx<conv_type> root_type;
+ public:
+ approx(scalable *src) : root_type(src) {};
+ };
+
+ typedef scalable base_type;
+};
+
+
+struct drawable_context {
+
+ template <class conv_type>
+ class simple : public drawable_adapter<conv_type> {
+ typedef drawable_adapter<conv_type> root_type;
+ public:
+ simple(drawable *src) : root_type(src) {};
+
+ template <class init_type>
+ simple(drawable* src, init_type& val): root_type(src, val) {};
+ };
+
+ template <class conv_type>
+ class approx : public drawable_adapter<conv_type> {
+ typedef drawable_adapter<conv_type> root_type;
+ public:
+ approx(drawable *src) : root_type(src) {};
+ };
+
+ typedef drawable base_type;
+
+};
+
+template <class context>
+struct trans {
+
+ typedef typename context::base_type base_type;
+
+ typedef typename context::template approx<agg::conv_stroke<base_type> > stroke;
+ typedef typename context::template approx<agg::conv_curve<base_type> > curve;
+ typedef typename context::template simple<agg::conv_dash<base_type> > dash;
+ typedef typename context::template approx<agg::conv_contour<base_type> > extend;
+
+ typedef typename context::template simple<agg::conv_transform<base_type> > vs_affine;
+
+ class affine : public vs_affine {
+ agg::trans_affine m_matrix;
+ double m_norm;
+
+ public:
+ affine(base_type *src, const agg::trans_affine& mtx) :
+ vs_affine(src, m_matrix), m_matrix(mtx)
+ {
+ m_norm = m_matrix.scale();
+ };
+
+ virtual void approximation_scale(double as)
+ {
+ this->m_source->approximation_scale(m_norm * as);
+ };
+ };
+
+ typedef agg::conv_transform<scalable> symbol_type;
+ typedef my::conv_simple_marker<base_type, symbol_type> conv_marker;
+ typedef typename context::template simple<conv_marker> vs_marker;
+
+ class marker : public vs_marker {
+ scalable& m_symbol;
+ agg::trans_affine m_matrix;
+ agg::conv_transform<scalable> m_trans;
+
+ public:
+ marker(base_type* src, double size, const char *sym):
+ vs_marker(src, m_trans),
+ m_symbol(markers::get(sym)), m_matrix(), m_trans(m_symbol, m_matrix)
+ {
+ m_matrix.scale(size);
+ };
+ };
+};
+
+#if 0
+struct trans {
typedef scalable_adapter_approx<agg::conv_stroke<scalable> > stroke;
typedef scalable_adapter_approx<agg::conv_curve<scalable> > curve;
typedef scalable_adapter<agg::conv_dash<scalable> > dash;
+ typedef scalable_adapter_approx<agg::conv_curve<scalable> > extend;
- typedef my::conv_simple_marker<scalable, agg::ellipse> conv_ellipse;
- typedef scalable_adapter<conv_ellipse> marker;
+ typedef scalable_adapter<agg::conv_transform<scalable> > vs_affine;
class affine : public vs_affine {
agg::trans_affine m_matrix;
@@ -81,7 +178,47 @@ namespace trans {
};
};
-}
+ typedef my::conv_simple_marker<scalable, agg::conv_transform<agg::path_storage> > conv_marker;
+ typedef scalable_adapter<conv_marker> vs_marker;
+
+ class marker : public vs_marker {
+ agg::path_storage& m_symbol;
+ agg::trans_affine m_matrix;
+ agg::conv_transform<agg::path_storage> m_trans;
+
+ public:
+ marker(scalable* src, double size, const char *sym):
+ vs_marker(src, m_trans),
+ m_symbol(markers::get(sym)), m_matrix(), m_trans(m_symbol, m_matrix)
+ {
+ m_matrix.scale(size);
+ };
+ };
+
+ /*
+ template <class symbol_type>
+ class marker_gen : public my::conv_simple_marker<scalable, symbol_type> {
+ typedef my::conv_simple_marker<scalable, symbol_type> base_type;
+
+ symbol_type m_symbol;
+ agg::trans_affine m_matrix;
+ agg::conv_transform<symbol_type> m_trans;
+
+ public:
+ marker_gen(scalable* src, double size):
+ base_type(src, m_trans), m_symbol(), m_matrix(), m_trans(m_symbol, m_matrix)
+ { };
+
+ virtual void approximation_scale(double as)
+ {
+ m_symbol.approximation_scale(as);
+ m_source->approximation_scale(as);
+ };
+
+ };
+ */
+};
+#endif
#if 0
namespace trans {
diff --git a/agg-plot/utils.cpp b/agg-plot/utils.cpp
index 145c27e1..bd4784d3 100644
--- a/agg-plot/utils.cpp
+++ b/agg-plot/utils.cpp
@@ -18,6 +18,7 @@ trans_affine_compose (agg::trans_affine& a, const agg::trans_affine& b)
a.ty = b.shy * a_tx + b.sy * a_ty + b.ty;
}
+/*
double
trans_affine_max_norm (const agg::trans_affine& m)
{
@@ -25,12 +26,4 @@ trans_affine_max_norm (const agg::trans_affine& m)
double c2 = sqrt(m.shy*m.shy + m.sy*m.sy);
return max(c1, c2);
}
-
-void bbox_enlarge(double *x1, double* y1, double* x2, double* y2,
- double x, double y)
-{
- if (x < *x1) *x1 = x;
- if (y < *y1) *y1 = y;
- if (x > *x2) *x2 = x;
- if (y > *y2) *y2 = y;
-}
+*/
diff --git a/agg-plot/utils.h b/agg-plot/utils.h
index 67e667bb..f70bcf04 100644
--- a/agg-plot/utils.h
+++ b/agg-plot/utils.h
@@ -14,10 +14,7 @@ T min (T a, T b) {
return (b > a) ? a : b;
}
-extern void trans_affine_compose (agg::trans_affine& a, const agg::trans_affine& b);
-extern double trans_affine_max_norm (const agg::trans_affine& m);
-
-extern void bbox_enlarge(double *x1, double* y1, double* x2, double* y2,
- double x, double y);
+extern void trans_affine_compose (agg::trans_affine& a,
+ const agg::trans_affine& b);
#endif
diff --git a/agg-plot/window-trans.h b/agg-plot/window-trans.h
deleted file mode 100644
index 4ca61ea1..00000000
--- a/agg-plot/window-trans.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef AGGPLOT_WINDOW_TRANS_H
-#define AGGPLOT_WINDOW_TRANS_H
-
-#include "drawable.h"
-
-#include "agg_conv_stroke.h"
-#include "agg_conv_curve.h"
-#include "agg_conv_dash.h"
-
-#include "my_conv_simple_marker.h"
-#include "agg_ellipse.h"
-
-template <class conv_type>
-class window_adapter : public vs_adapter<conv_type, drawable>
-{
- typedef vs_adapter<conv_type, drawable> root_type;
-
-public:
- window_adapter(drawable *src) : root_type(src) { };
-
- template <class init_type>
- window_adapter(drawable* src, init_type& val) :
- root_type(src, val)
- { };
-
- virtual void apply_transform(const agg::trans_affine& m)
- {
- this->m_source->apply_transform(m);
- };
-
- virtual void bounding_box(double *x1, double *y1, double *x2, double *y2)
- {
- this->m_source->bounding_box(x1, y1, x2, y2);
- }
-};
-
-typedef my::conv_simple_marker<drawable, agg::ellipse> conv_ellipse;
-
-namespace window {
-
- typedef window_adapter<agg::conv_stroke<drawable> > stroke;
- typedef window_adapter<agg::conv_curve<drawable> > curve;
- typedef window_adapter<agg::conv_dash<drawable> > dash;
- typedef window_adapter<conv_ellipse> marker;
-
-}
-
-#endif
diff --git a/agg-plot/wtest.cpp b/agg-plot/wtest.cpp
index 7b8e75df..2631b625 100644
--- a/agg-plot/wtest.cpp
+++ b/agg-plot/wtest.cpp
@@ -1,6 +1,5 @@
#include "trans.h"
-#include "window-trans.h"
#include "path.h"
#include "text.h"
@@ -9,24 +8,24 @@ main()
{
draw::path *p = new draw::path();
- agg::path_storage& pc = p->get_base();
+ agg::path_storage& pc = p->self();
pc.move_to(0.0, 0.0);
pc.line_to(20.0, 0.0);
pc.line_to(20.0, 20.0);
pc.line_to(0.0, 20.0);
pc.close_polygon();
- trans::stroke *s1 = new trans::stroke(p);
+ trans<scalable_context>::stroke *s1 = new trans<scalable_context>::stroke(p);
s1->self().width(4.0);
s1->self().line_cap(agg::round_cap);
double c = 0.707, s= 0.707;
agg::trans_affine rmat(c, s, -s, c, 0.0, 0.0);
- trans::affine *rs1 = new trans::affine(s1, rmat);
+ trans<scalable_context>::affine *rs1 = new trans<scalable_context>::affine(s1, rmat);
window_scalable *ws1 = new window_scalable(rs1);
- window::stroke *s2 = new window::stroke(ws1);
+ trans<drawable_context>::stroke *s2 = new trans<drawable_context>::stroke(ws1);
s2->self().width(1.0);
s2->self().line_cap(agg::round_cap);
@@ -40,7 +39,7 @@ main()
txt->self().text("Hello world!");
txt->self().start_point(4.0, 5.0);
- window::dash *d2 = new window::dash(txt);
+ trans<drawable_context>::dash *d2 = new trans<drawable_context>::dash(txt);
d2->self().add_dash(2.0, 2.0);
if (s2->dispose())
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月17日 01:43:13 +0000

AltStyle によって変換されたページ (->オリジナル) /