Now the module for plotting graphs is functional. - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2009年11月29日 18:20:31 +0000
committerFrancesco Abbate <francesco.bbt@gmail.com>2009年11月29日 18:20:31 +0000
commit80e5324cf70c55e96f3aa405153ed1930a26abf7 (patch)
treeaf7440cd539394f5710abbcb260e51935ffda3d2
parent67e863fa3eef8e476507d58b7a21e7018ed56a28 (diff)
downloadgsl-shell-80e5324cf70c55e96f3aa405153ed1930a26abf7.tar.gz
Now the module for plotting graphs is functional.
Diffstat
-rw-r--r--Makefile 8
-rw-r--r--agg-plot/Makefile 121
-rw-r--r--agg-plot/cplot.cpp 81
-rw-r--r--agg-plot/cplot.h 64
-rw-r--r--agg-plot/lua-cplot-priv.h 19
-rw-r--r--agg-plot/lua-cplot.cpp 284
-rw-r--r--agg-plot/main.cpp 83
-rw-r--r--agg-plot/string_printf.cpp 24
-rw-r--r--agg-plot/string_printf.h 6
-rw-r--r--agg-plot/units.h 63
-rw-r--r--agg-plot/units_cplot.cpp 52
-rw-r--r--agg-plot/units_cplot.h 2
-rw-r--r--agg-plot/utils.cpp 2
-rw-r--r--agg-plot/utils.h 2
-rw-r--r--agg-plot/xwin-show.cpp 83
-rw-r--r--agg-plot/xwin-show.h 6
-rw-r--r--gsl-shell.c 2
-rw-r--r--lua-cplot.h 14
-rw-r--r--lua-gsl.c 4
19 files changed, 711 insertions, 209 deletions
diff --git a/Makefile b/Makefile
index d9e1449b..b8e40370 100644
--- a/Makefile
+++ b/Makefile
@@ -68,7 +68,7 @@ endif
COMPILE = $(CC) --std=c99 $(CFLAGS) $(LUA_CFLAGS) $(DEFS) $(INCLUDES)
-SUBDIRS = lua
+SUBDIRS = lua agg-plot
LUAGSL_OBJ_FILES := $(LUAGSL_SRC_FILES:%.c=%.o)
@@ -95,8 +95,10 @@ gsl.dll: $(LUAGSL_OBJ_FILES)
$(LUA_LIBS)
else
-gsl-shell: $(LUAGSL_OBJ_FILES) gsl-shell.o
- $(CC) -o $@ $(LUAGSL_OBJ_FILES) gsl-shell.o $(LUADIR)/src/liblua.a $(LIBS) $(GSL_LIBS) -Wl,-E -ldl -lreadline -lhistory -lncurses
+AGG_LIBS = -lagg -laggplatformX11 -lX11
+
+gsl-shell: $(LUAGSL_OBJ_FILES) gsl-shell.o agg-plot/libaggplot.a
+ $(CC) -o $@ $(LUAGSL_OBJ_FILES) gsl-shell.o $(LUADIR)/src/liblua.a agg-plot/libaggplot.a $(LIBS) $(GSL_LIBS) -Wl,-E -Wl,--allow-multiple-definition -ldl -lreadline -lhistory -lncurses $(AGG_LIBS) -lpthread -lsupc++
gsl.so: $(LUAGSL_OBJ_FILES)
$(CC) -shared -o .libs/libluagsl.so $(LUAGSL_OBJ_FILES) $(GSL_LIBS)
diff --git a/agg-plot/Makefile b/agg-plot/Makefile
index 67f32c11..545c0244 100644
--- a/agg-plot/Makefile
+++ b/agg-plot/Makefile
@@ -1,29 +1,92 @@
-
-CXX = g++
-CXXFLAGS = -g -Wall
-
-AGG_CFLAGS = -I/usr/include/agg2
-AGG_LIBS = -lagg -laggplatformX11 -lX11
-
-CXXCOMPILE = $(CXX) $(CXXFLAGS)
-
-AGG_HOME = /home/francesco/src/agg-2.5
-
-AGG_TRANS_AFFINE = $(AGG_HOME)/src/agg_trans_affine.o
-
-SRC_FILES = utils.cpp cplot.cpp units_cplot.cpp main.cpp
-
-OBJ_FILES := $(SRC_FILES:%.cpp=%.o)
-
-.PHONY: clean all
-
-all: test.exe
-
-%.o: %.cpp
- $(CXXCOMPILE) -c $< $(AGG_CFLAGS)
-
-test.exe: $(OBJ_FILES)
- $(CXX) -o $@ $(OBJ_FILES) $(AGG_TRANS_AFFINE) $(AGG_LIBS)
-
-clean:
- rm *.o *.exe
+
+# Makefile
+#
+# Copyright (C) 2009 Francesco Abbate
+#
+# This program 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 3 of the License, or (at
+# your option) any later version.
+#
+# This program 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+GSH_BASE_DIR = ..
+
+include $(GSH_BASE_DIR)/makeconfig
+
+LUADIR = $(GSH_BASE_DIR)/lua
+AR= ar rcu
+RANLIB= ranlib
+
+ifeq ($(PLATFORM), none)
+nono:
+ @echo "You haven't edited 'makeconfig' yet. Set your settings there, then run 'make' again"
+endif
+
+ifeq ($(strip $(PLATFORM)), mingw)
+# Option for Windows Platform
+ DEFS += -DWIN32
+ INCLUDES += -I/usr/include
+ LIBS += -L/usr/lib
+endif
+
+INCLUDES += -I$(LUADIR)/src -I$(LUADIR)/etc
+
+AGGPLOT_SRC_FILES = utils.cpp cplot.cpp units_cplot.cpp xwin-show.cpp lua-cplot.cpp
+
+SUBDIRS =
+
+AGGPLOT_OBJ_FILES := $(AGGPLOT_SRC_FILES:%.cpp=%.o)
+
+DEP_FILES := $(AGGPLOT_SRC_FILES:%.cpp=.deps/%.P)
+
+DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
+
+AGG_CFLAGS = -I/usr/include/agg2
+AGG_LIBS = -lagg -laggplatformX11 -lX11
+
+CXXCOMPILE = $(CXX) $(CXXFLAGS) $(DEFS) $(INCLUDES) $(AGG_CFLAGS)
+
+TARGETS = libaggplot.a
+
+all: $(SUBDIRS) $(TARGETS)
+
+libaggplot.a: $(AGGPLOT_OBJ_FILES)
+ $(AR) $@ $?
+ $(RANLIB) $@
+
+%.o: %.cpp
+ @echo $(CXXCOMPILE) -c $<
+ @$(CXXCOMPILE) -Wp,-MMD,.deps/$(*F).pp -c $<
+ @-cp .deps/$(*F).pp .deps/$(*F).P; \
+ tr ' ' '012円' < .deps/$(*F).pp \
+ | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
+ >> .deps/$(*F).P; \
+ rm .deps/$(*F).pp
+
+%.o: %.c
+ @echo $(COMPILE) -c $<
+ @$(COMPILE) -Wp,-MMD,.deps/$(*F).pp -c $<
+ @-cp .deps/$(*F).pp .deps/$(*F).P; \
+ tr ' ' '012円' < .deps/$(*F).pp \
+ | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
+ >> .deps/$(*F).P; \
+ rm .deps/$(*F).pp
+
+.PHONY: clean all $(SUBDIRS)
+
+$(SUBDIRS):
+ $(MAKE) DEFS='"$(SUBDIRS_DEFS)"' PLATFORM=$(strip $(PLATFORM)) -C $@
+
+clean:
+ $(RM) *.o *.lo *.la *.so *.dll $(TARGETS)
+
+-include $(DEP_FILES)
diff --git a/agg-plot/cplot.cpp b/agg-plot/cplot.cpp
index 7aa2e842..26b53220 100644
--- a/agg-plot/cplot.cpp
+++ b/agg-plot/cplot.cpp
@@ -3,15 +3,14 @@
#include "cplot.h"
#include "agg_conv_stroke.h"
+#include "agg_conv_dash.h"
+#include "agg_vcgen_markers_term.h"
#include "agg_bounding_rect.h"
-line&
-cplot::new_line(agg::rgba8 color)
+void
+cplot::add(drawable *d)
{
- int n = m_lines.size();
- m_lines.resize(n+1, color);
- std::list<line>::iterator ln = -- m_lines.end();
- return *ln;
+ m_lines.add(d);
}
bool
@@ -19,11 +18,12 @@ cplot::bbox_update()
{
bool updated = false;
- for (std::list<line>::iterator j = m_lines.begin(); j != m_lines.end(); j++)
+ for (unsigned j = 0; j < m_lines.size(); j++)
{
- line& ln = *j;
+ drawable* d = m_lines[j];
+
double x1, y1, x2, y2;
- bounding_rect_single(ln.path, 0, &x1, &y1, &x2, &y2);
+ d->bounding_box(&x1, &y1, &x2, &y2);
if (! m_bbox_set)
{
@@ -47,7 +47,7 @@ cplot::bbox_update()
updated = true;
}
}
-
+
return updated;
}
@@ -60,13 +60,9 @@ cplot::draw_lines(canvas &canvas)
viewport_scale(m);
canvas.scale(m);
- for (std::list<line>::iterator j = m_lines.begin(); j != m_lines.end(); j++)
+ for (unsigned j = 0; j < m_lines.size(); j++)
{
- line& ln = *j;
- path_type& p = ln.path;
- agg::conv_transform<path_type> ptr(p, m);
- agg::conv_stroke<agg::conv_transform<path_type> > ps(ptr);
- canvas.draw(ps, ln.color);
+ m_lines[j]->draw(canvas, m);
}
}
@@ -98,3 +94,56 @@ cplot::viewport_scale(agg::trans_affine& m)
static agg::trans_affine rsz(1-2*xoffs, 0.0, 0.0, 1-2*yoffs, xoffs, yoffs);
trans_affine_compose (m, rsz);
}
+
+void
+line::draw(canvas& can, agg::trans_affine& t)
+{
+ typedef agg::path_storage path_type;
+
+ path_type& p = this->path;
+ agg::conv_transform<path_type> ptr(p, t);
+ agg::conv_stroke<agg::conv_transform<path_type> > ps(ptr);
+ can.draw(ps, this->color);
+}
+
+void
+line::bounding_box(double *x1, double *y1, double *x2, double *y2)
+{
+ bounding_rect_single(this->path, 0, x1, y1, x2, y2);
+}
+
+void
+dashed_line::draw(canvas& canvas, agg::trans_affine& t)
+{
+ typedef agg::path_storage path_type;
+ typedef agg::conv_dash<agg::conv_transform<path_type>, agg::vcgen_markers_term> dash_type;
+
+ path_type& ln = this->path;
+ agg::conv_transform<path_type> lntr(ln, t);
+ dash_type lndash(lntr);
+ agg::conv_stroke<dash_type> lns(lndash);
+
+ lndash.add_dash(m_l1, m_l2);
+ canvas.draw(lns, this->color);
+}
+
+void
+polygon::draw(canvas& canvas, agg::trans_affine& t)
+{
+ agg::path_storage& p = this->path;
+ agg::conv_transform<agg::path_storage> ptr(p, t);
+ canvas.draw(ptr, this->color);
+}
+
+void
+poly_outline::draw(canvas& canvas, agg::trans_affine& t)
+{
+ typedef agg::path_storage path_type;
+
+ path_type& p = this->path;
+ agg::conv_transform<path_type> ptr(p, t);
+ canvas.draw(ptr, this->color);
+
+ agg::conv_stroke<agg::conv_transform<path_type> > ps(ptr);
+ canvas.draw(ps, this->m_outline_color);
+}
diff --git a/agg-plot/cplot.h b/agg-plot/cplot.h
index 4e81c7fb..626cb6f9 100644
--- a/agg-plot/cplot.h
+++ b/agg-plot/cplot.h
@@ -5,32 +5,76 @@
#include <stdlib.h>
#include <limits.h>
-#include <list>
-
#include "canvas.h"
#include "units.h"
#include "agg_conv_transform.h"
#include "agg_color_rgba.h"
#include "agg_path_storage.h"
+#include "agg_array.h"
-class line {
-public:
- line(agg::rgba8 c) : path(), color(c) {};
+struct drawable {
+ virtual void draw(canvas& can, agg::trans_affine& t) = 0;
+ virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) = 0;
+ virtual ~drawable() {};
+};
+struct line : public drawable {
agg::path_storage path;
agg::rgba8 color;
+
+ line(agg::rgba8 col): path(), color(col) {};
+
+ virtual void draw(canvas& can, agg::trans_affine& t);
+ virtual void bounding_box(double *x1, double *y1, double *x2, double *y2);
+};
+
+struct dashed_line : public line {
+public:
+ dashed_line(double l1, double l2, agg::rgba8 col):
+ line(col), m_l1(l1), m_l2(l2)
+ {};
+
+ virtual void draw(canvas& can, agg::trans_affine& t);
+
+private:
+ double m_l1;
+ double m_l2;
+};
+
+struct polygon : public line {
+ polygon(agg::rgba8 col): line(col) {};
+ virtual void draw(canvas& can, agg::trans_affine& t);
+};
+
+struct poly_outline : public line {
+ agg::rgba8 m_outline_color;
+
+ poly_outline(agg::rgba8 col, agg::rgba8 out_col) :
+ line(col), m_outline_color(out_col)
+ {};
+
+ virtual void draw(canvas& can, agg::trans_affine& t);
};
class cplot {
+ typedef agg::pod_bvector<drawable *> container_type;
+
public:
- line& new_line(agg::rgba8 color);
-
- const agg::trans_affine& trans() const { return m_trans; };
+
+ cplot() : m_lines(), m_trans(), m_bbox_set(false) {};
+
+ virtual ~cplot()
+ {
+ for (unsigned j = 0; j < m_lines.size(); j++)
+ delete m_lines[j];
+ };
+
+ void add(drawable *d);
virtual void draw(canvas &canvas);
- cplot() : m_lines(), m_trans(), m_bbox_set(false) {};
+ const agg::trans_affine& trans() const { return m_trans; };
protected:
void draw_lines(canvas &canvas);
@@ -39,7 +83,7 @@ protected:
static void viewport_scale(agg::trans_affine& trans);
- std::list<line> m_lines;
+ container_type m_lines;
agg::trans_affine m_trans;
// bounding box
diff --git a/agg-plot/lua-cplot-priv.h b/agg-plot/lua-cplot-priv.h
new file mode 100644
index 00000000..c55b970a
--- /dev/null
+++ b/agg-plot/lua-cplot-priv.h
@@ -0,0 +1,19 @@
+
+#include <pthread.h>
+
+extern "C" {
+
+ struct lcplot {
+ cplot *plot;
+ int lua_is_owner;
+ int is_shown;
+ pthread_mutex_t *mutex;
+
+ void *x_app;
+ };
+
+ extern void lcplot_destroy (struct lcplot *cp);
+
+ extern void update_callback (void *_app);
+
+}
diff --git a/agg-plot/lua-cplot.cpp b/agg-plot/lua-cplot.cpp
new file mode 100644
index 00000000..ce6c8054
--- /dev/null
+++ b/agg-plot/lua-cplot.cpp
@@ -0,0 +1,284 @@
+
+#include <pthread.h>
+
+#include "lua.hpp"
+#include "units_cplot.h"
+#include "cplot.h"
+#include "lua-cplot-priv.h"
+
+#include "xwin-show.h"
+
+extern int agg_main (int argc, char *argv[]);
+
+extern "C" {
+
+ extern void cplot_register (lua_State *L);
+
+ struct ldrawable {
+ line *element;
+ bool is_owner;
+ };
+
+ static const char * const cplot_mt_name = "GSL.pl.cplot";
+ static const char * const drawable_mt_name = "GSL.pl.draw";
+
+ static int drawable_new (lua_State *L);
+ static int drawable_move_to (lua_State *L);
+ static int drawable_line_to (lua_State *L);
+ static int drawable_close (lua_State *L);
+ static int drawable_free (lua_State *L);
+
+ static int cplot_new (lua_State *L);
+ static int cplot_show (lua_State *L);
+ static int cplot_add (lua_State *L);
+ static int cplot_free (lua_State *L);
+
+ struct ldrawable* check_drawable (lua_State *L, int index);
+ struct lcplot* check_cplot (lua_State *L, int index);
+}
+
+static const struct luaL_Reg cplot_functions[] = {
+ {"line", drawable_new},
+ {"cplot", cplot_new},
+ {NULL, NULL}
+};
+
+
+static const struct luaL_Reg drawable_methods[] = {
+ {"move_to", drawable_move_to},
+ {"line_to", drawable_line_to},
+ {"close", drawable_close},
+ {"__gc", drawable_free},
+ {NULL, NULL}
+};
+
+static const struct luaL_Reg cplot_methods[] = {
+ {"show", cplot_show},
+ {"add", cplot_add},
+ {"__gc", cplot_free},
+ {NULL, NULL}
+};
+
+static agg::rgba8
+color_lookup (const char *color_str)
+{
+ const char *p = color_str;
+ agg::rgba8 c;
+ int val = 180;
+
+ if (strncmp (p, "light", 5) == 0)
+ {
+ val = 255;
+ p += 5;
+ }
+ else if (strncmp (p, "dark", 4) == 0)
+ {
+ val = 80;
+ p += 4;
+ }
+
+ if (strcmp (p, "red") == 0)
+ c = agg::rgba8(val, 0, 0);
+ else if (strcmp (p, "green") == 0)
+ c = agg::rgba8(0, val, 0);
+ else if (strcmp (p, "blue") == 0)
+ c = agg::rgba8(0, 0, val);
+ else
+ c = agg::rgba8(0, 0, 0);
+
+ return c;
+}
+
+int
+drawable_new (lua_State *L)
+{
+ struct ldrawable *d = (struct ldrawable *) lua_newuserdata (L, sizeof (struct ldrawable));
+ const char *color_str = luaL_optstring (L, 1, "black");
+ agg::rgba8 color = color_lookup (color_str);
+
+ d->element = new line(color);
+ d->is_owner = true;
+
+ luaL_getmetatable (L, drawable_mt_name);
+ lua_setmetatable (L, -2);
+
+ return 1;
+}
+
+struct ldrawable *
+check_drawable (lua_State *L, int index)
+{
+ return (struct ldrawable*) luaL_checkudata (L, index, drawable_mt_name);
+}
+
+struct lcplot *
+check_cplot (lua_State *L, int index)
+{
+ return (struct lcplot *) luaL_checkudata (L, index, cplot_mt_name);
+}
+
+int
+drawable_free (lua_State *L)
+{
+ struct ldrawable *d = check_drawable (L, 1);
+ if (d->is_owner)
+ delete d->element;
+ return 0;
+}
+
+int
+drawable_move_to (lua_State *L)
+{
+ struct ldrawable *d = check_drawable (L, 1);
+ double x = luaL_checknumber (L, 2);
+ double y = luaL_checknumber (L, 3);
+ agg::path_storage& p = d->element->path;
+ p.move_to(x, y);
+ return 0;
+}
+
+int
+drawable_line_to (lua_State *L)
+{
+ struct ldrawable *d = check_drawable (L, 1);
+ double x = luaL_checknumber (L, 2);
+ double y = luaL_checknumber (L, 3);
+ agg::path_storage& p = d->element->path;
+ p.line_to(x, y);
+ return 0;
+}
+
+int
+drawable_close (lua_State *L)
+{
+ struct ldrawable *d = check_drawable (L, 1);
+ agg::path_storage& p = d->element->path;
+ p.close_polygon();
+ return 0;
+}
+
+int
+cplot_new (lua_State *L)
+{
+ lua_Integer use_units = luaL_optinteger (L, 1, 0);
+ struct lcplot *cp = (struct lcplot *) lua_newuserdata (L, sizeof (struct lcplot));
+
+ if (use_units)
+ {
+ cp->plot = new units_cplot();
+ }
+ else
+ {
+ cp->plot = new cplot();
+ }
+
+ cp->lua_is_owner = 1;
+ cp->is_shown = 0;
+ cp->x_app = NULL;
+
+ cp->mutex = new pthread_mutex_t;
+ pthread_mutex_init (cp->mutex, NULL);
+
+ luaL_getmetatable (L, cplot_mt_name);
+ lua_setmetatable (L, -2);
+
+ return 1;
+}
+
+void
+lcplot_destroy (struct lcplot *cp)
+{
+ delete cp->plot;
+ pthread_mutex_destroy (cp->mutex);
+ free (cp->mutex);
+}
+
+int
+cplot_free (lua_State *L)
+{
+ struct lcplot *cp = check_cplot (L, 1);
+ if (cp->lua_is_owner && cp->is_shown)
+ {
+ cp->lua_is_owner = 0;
+ }
+ else
+ {
+ lcplot_destroy (cp);
+ }
+}
+
+int
+cplot_add (lua_State *L)
+{
+ struct lcplot *cp = check_cplot (L, 1);
+ struct ldrawable *d = check_drawable (L, 2);
+ cplot *p = cp->plot;
+
+ pthread_mutex_lock (cp->mutex);
+
+ if (d->is_owner)
+ {
+ p->add(d->element);
+ d->is_owner = false;
+ }
+ else
+ {
+ line* ln_copy = new line(*d->element);
+ p->add(ln_copy);
+ }
+
+ pthread_mutex_unlock (cp->mutex);
+
+ if (cp->x_app)
+ update_callback (cp->x_app);
+
+ return 0;
+}
+
+int
+cplot_show (lua_State *L)
+{
+ struct lcplot *cp = check_cplot (L, 1);
+ cplot *p = cp->plot;
+ pthread_t xwin_thread[1];
+ pthread_attr_t attr[1];
+
+ pthread_attr_init (attr);
+ pthread_attr_setdetachstate (attr, PTHREAD_CREATE_DETACHED);
+
+ if (pthread_create(xwin_thread, attr, xwin_thread_function, (void*) cp))
+ {
+ pthread_attr_destroy (attr);
+ return luaL_error(L, "error creating thread.");
+ }
+
+ pthread_attr_destroy (attr);
+ return 0;
+}
+
+int
+agg_main (int argc, char *argv[])
+{
+ return 0;
+}
+
+void
+cplot_register (lua_State *L)
+{
+ /* cplot declaration */
+ luaL_newmetatable (L, cplot_mt_name);
+ lua_pushvalue (L, -1);
+ lua_setfield (L, -2, "__index");
+ luaL_register (L, NULL, cplot_methods);
+ lua_pop (L, 1);
+
+ /* drawable declaration */
+ luaL_newmetatable (L, drawable_mt_name);
+ lua_pushvalue (L, -1);
+ lua_setfield (L, -2, "__index");
+ luaL_register (L, NULL, drawable_methods);
+ lua_pop (L, 1);
+
+ /* gsl module registration */
+ luaL_register (L, NULL, cplot_functions);
+}
diff --git a/agg-plot/main.cpp b/agg-plot/main.cpp
index c0442b5e..53638235 100644
--- a/agg-plot/main.cpp
+++ b/agg-plot/main.cpp
@@ -22,6 +22,8 @@
#include "canvas.h"
#include "units_cplot.h"
+#include "my_list.h"
+
enum flip_y_e { flip_y = true };
class the_application : public agg::platform_support
@@ -31,8 +33,19 @@ public:
agg::platform_support(format, flip_y), m_plot()
{
{
- line& ln = m_plot.new_line(agg::rgba(0.7, 0, 0));
- agg::path_storage& p = ln.path;
+ poly_outline* ln = new poly_outline(agg::rgba(0.7, 0.5, 0.1), agg::rgba(0,0,0));
+ agg::path_storage& p = ln->path;
+
+ p.move_to(-3.0, -0.7);
+ p.line_to(35.0, 2.5);
+ p.line_to(5.0, 4.0);
+ p.close_polygon();
+
+ m_plot.add(ln);
+ }
+ {
+ line* ln = new line(agg::rgba(0.7, 0, 0));
+ agg::path_storage& p = ln->path;
const int npt = 512, ncycles = 12;
for (int j = 0; j < npt; j++)
{
@@ -43,11 +56,12 @@ public:
else
p.line_to(x, y);
}
+ m_plot.add(ln);
}
{
- line& ln = m_plot.new_line(agg::rgba(0, 0, 0.7));
- agg::path_storage& p = ln.path;
+ line* ln = new line(agg::rgba(0, 0, 0.7));
+ agg::path_storage& p = ln->path;
const int npt = 512, ncycles = 12;
for (int j = 0; j < npt; j++)
@@ -59,57 +73,8 @@ public:
else
p.line_to(x, y);
}
+ m_plot.add(ln);
}
-
- {
- line& ln = m_plot.new_line(agg::rgba(0, 0.7, 0));
- agg::path_storage& p = ln.path;
-
- const int npt = 2, ncycles = 12;
- for (int j = 0; j < npt; j++)
- {
- double x = j * 2 * M_PI * ncycles / npt;
- double y = 1.8;
- if (j == 0)
- p.move_to(x, y);
- else
- p.line_to(x, y);
- }
- }
- /*
-
- {
- line& ln = m_plot.new_line(agg::rgba(0, 0.7, 0));
- agg::path_storage& p = ln.path;
-
- const int npt = 1;
- for (int j = 0; j <= npt; j++)
- {
- double x = j * 1.0 / npt;
- double y = 1.0;
- if (j == 0)
- p.move_to(x, y);
- else
- p.line_to(x, y);
- }
- }
-
- {
- line& ln = m_plot.new_line(agg::rgba(0.7, 0, 0));
- agg::path_storage& p = ln.path;
-
- const int npt = 1;
- for (int j = 0; j <= npt; j++)
- {
- double x = j * 1.0 / npt;
- double y = 0.0;
- if (j == 0)
- p.move_to(x, y);
- else
- p.line_to(x, y);
- }
- }
- */
};
virtual ~the_application()
@@ -129,12 +94,12 @@ private:
int agg_main(int argc, char* argv[])
{
- the_application app(agg::pix_format_bgr24, flip_y);
- app.caption("My damn test");
+ the_application app(agg::pix_format_bgr24, flip_y);
+ app.caption("My damn test");
- if(app.init(780, 400, agg::window_resize))
+ if(app.init(780, 400, agg::window_resize))
{
- return app.run();
+ return app.run();
}
- return 0;
+ return 0;
}
diff --git a/agg-plot/string_printf.cpp b/agg-plot/string_printf.cpp
deleted file mode 100644
index 884550bd..00000000
--- a/agg-plot/string_printf.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-
-#include <string>
-#include <stdarg.h>
-
-void
-string_printf (std::string &s, const char *fmt, ...)
-{
- va_list ap;
- char *buf;
- int n;
-
- va_start (ap, fmt);
-
- n = vasprintf (&buf, fmt, ap);
- if (n <= 0)
- {
- s = "";
- return;
- }
-
- s = (const char *) buf;
- free (buf);
- va_end (ap);
-}
diff --git a/agg-plot/string_printf.h b/agg-plot/string_printf.h
deleted file mode 100644
index 6991cfee..00000000
--- a/agg-plot/string_printf.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef STRING_PRINTF_H
-#define STRING_PRINTF_H
-
-
-#endif
-
diff --git a/agg-plot/units.h b/agg-plot/units.h
index 1a0e8714..766bf1d7 100644
--- a/agg-plot/units.h
+++ b/agg-plot/units.h
@@ -1,49 +1,43 @@
-
-/*
- $Id$
-*/
-
#ifndef AGGPLOT_UNITS_H
#define AGGPLOT_UNITS_H
-#include <string>
-#include <vector>
-
#include "utils.h"
-template<class num_type>
+template<class T>
class units {
private:
int m_major;
int order;
- num_type dmajor; // equal to (m_major * 10^order)
+ T dmajor; // equal to (m_major * 10^order)
int m_inf, m_sup; // expressed in the base of (m_major * 10^order)
int nb_decimals;
- private:
- void init(num_type min, num_type max, num_type spacefact);
+ void init(T min, T max, T spacefact);
public:
units(): m_major(1), order(0), dmajor(1), m_inf(0), m_sup(1), nb_decimals(0) {};
- units (num_type min, num_type max, num_type spacefact = 5.0)
+ units (T min, T max, T spacefact = 5.0)
{ init(min, max, spacefact); };
int begin() const { return m_inf; };
int end() const { return m_sup; };
- void limits(int &start, int &fin, num_type &step)
- { start = m_inf; fin = m_sup; step = dmajor; };
+ void limits(int &start, int &fin, T &step)
+ {
+ start = m_inf;
+ fin = m_sup;
+ step = dmajor;
+ };
- void mark_label (std::string& label, int mark) const;
- num_type mark_value (int mark) const { return dmajor * mark; };
-
- num_type mark_scale(num_type x);
+ void mark_label (char *label, unsigned size, int mark) const;
+ T mark_value (int mark) const { return dmajor * mark; };
+ T mark_scale(T x);
};
-template<class num_type>
-void units<num_type>::init(num_type yinf, num_type ysup, num_type spacefact)
+template<class T>
+void units<T>::init(T yinf, T ysup, T spacefact)
{
- num_type del;
+ T del;
if (ysup == yinf)
ysup = yinf + 1.0;
@@ -52,8 +46,8 @@ void units<num_type>::init(num_type yinf, num_type ysup, num_type spacefact)
order = (int) floor(log10(del));
- num_type expf = pow(10, order);
- num_type delr = del / expf;
+ T expf = pow(10, order);
+ T delr = del / expf;
if (5 <= delr)
m_major = 5;
@@ -70,34 +64,39 @@ void units<num_type>::init(num_type yinf, num_type ysup, num_type spacefact)
dmajor = m_major * expf;
}
-template<class num_type>
-void units<num_type>::mark_label (std::string& lab, int mark) const
+template<class T>
+void units<T>::mark_label (char *lab, unsigned size, int mark) const
{
bool minus = (m_inf < 0);
int asup = (minus ? -m_inf : m_sup);
char fmt[8];
+ if (size < 16)
+ return;
+
if (nb_decimals == 0)
{
int space = (int)log10(asup * dmajor) + (minus ? 1 : 0) + 1;
sprintf (fmt, "%%%id", space);
- string_printf (lab, fmt, (int) (mark * dmajor));
+ snprintf (lab, size, fmt, int(mark * dmajor));
+ lab[size-1] = '0円';
}
else
{
int dec = (nb_decimals < 10 ? nb_decimals : 9);
- int base = floor(asup * dmajor);
+ int base = (int) floor(asup * dmajor);
int space = dec + (base > 0 ? (int)log10(base): 0) + 1 \
+ (minus ? 1 : 0) + 1;
sprintf (fmt, "%%%i.%if", space, dec);
- string_printf (lab, fmt, mark * dmajor);
+ snprintf (lab, size, fmt, mark * dmajor);
+ lab[size-1] = '0円';
}
}
-template<class num_type>
-num_type units<num_type>::mark_scale (num_type x)
+template<class T>
+T units<T>::mark_scale (T x)
{
- num_type xinf = m_inf * dmajor, xsup = m_sup * dmajor;
+ T xinf = m_inf * dmajor, xsup = m_sup * dmajor;
return (x - xinf) / (xsup - xinf);
}
diff --git a/agg-plot/units_cplot.cpp b/agg-plot/units_cplot.cpp
index d3805396..e616f464 100644
--- a/agg-plot/units_cplot.cpp
+++ b/agg-plot/units_cplot.cpp
@@ -27,20 +27,21 @@ units_cplot::draw_axis(canvas &canvas)
double y = double(j - jinf) / double(jsup - jinf);
agg::gsv_text lab;
agg::conv_stroke<agg::gsv_text> labs(lab);
- agg::conv_transform<agg::conv_stroke<agg::gsv_text> > labo(labs, m);
- std::string lab_text;
-
- labs.line_join(agg::round_join);
- labs.line_cap(agg::round_cap);
- labs.approximation_scale(m.scale());
+ char lab_text[32];
+ double xlab = 0, ylab = y;
- lab.size(0.03, 0.02);
- labs.width(1.5 * 1/max(m.sx, m.sy));
- m_uy.mark_label(lab_text, j);
- lab.text(lab_text.c_str());
+ lab.size(10.0);
+ m_uy.mark_label(lab_text, 32, j);
+ lab.text(lab_text);
+ labs.width(0.7);
- lab.start_point(-0.01 - lab.text_width(), y - 0.015);
- canvas.draw(labo, agg::rgba(0, 0, 0));
+ m.transform(&xlab, &ylab);
+
+ xlab += -lab.text_width() - 8.0;
+ ylab += -10.0/2.0;
+
+ lab.start_point(xlab, ylab);
+ canvas.draw(labs, agg::rgba(0, 0, 0));
if (j > jinf && j < jsup)
{
@@ -57,20 +58,21 @@ units_cplot::draw_axis(canvas &canvas)
double x = double(j - jinf) / double(jsup - jinf);
agg::gsv_text lab;
agg::conv_stroke<agg::gsv_text> labs(lab);
- agg::conv_transform<agg::conv_stroke<agg::gsv_text> > labo(labs, m);
- std::string lab_text;
-
- labs.line_join(agg::round_join);
- labs.line_cap(agg::round_cap);
- labs.approximation_scale(m.scale());
+ char lab_text[32];
+ double xlab = x, ylab = 0;
+
+ lab.size(10.0);
+ m_ux.mark_label(lab_text, 32, j);
+ lab.text(lab_text);
+ labs.width(0.7);
+
+ m.transform(&xlab, &ylab);
- lab.size(0.03, 0.02);
- labs.width(1.5 * 1/max(m.sx, m.sy));
- m_ux.mark_label(lab_text, j);
- lab.text(lab_text.c_str());
+ xlab += -lab.text_width()/2.0;
+ ylab += -10.0 - 10.0;
- lab.start_point(x - lab.text_width()/2.0, -0.025 - 0.03);
- canvas.draw(labo, agg::rgba(0, 0, 0));
+ lab.start_point(xlab, ylab);
+ canvas.draw(labs, agg::rgba(0, 0, 0));
if (j > jinf && j < jsup)
{
@@ -83,7 +85,7 @@ units_cplot::draw_axis(canvas &canvas)
lndash.add_dash(8.0, 4.0);
lns.width(0.25);
- canvas.draw(lns, agg::rgba8(0.8, 0.8, 0.8));
+ canvas.draw(lns, agg::rgba(0.2, 0.2, 0.2));
agg::path_storage box;
agg::conv_transform<path_type> boxtr(box, m);
diff --git a/agg-plot/units_cplot.h b/agg-plot/units_cplot.h
index d6a8ed86..4217ffc4 100644
--- a/agg-plot/units_cplot.h
+++ b/agg-plot/units_cplot.h
@@ -37,7 +37,7 @@ private:
ys = iys * yd;
double fx = 1/(xs - xi), fy = 1/(ys - yi);
- m_trans = agg::trans_affine(fx, 0.0, 0.0, fy, -xi/fx, -yi/fy);
+ m_trans = agg::trans_affine(fx, 0.0, 0.0, fy, -xi*fx, -yi*fy);
return true;
}
diff --git a/agg-plot/utils.cpp b/agg-plot/utils.cpp
index b74a4736..6f6b39ae 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;
}
+/*
void
string_printf (std::string &s, const char *fmt, ...)
{
@@ -38,3 +39,4 @@ string_printf (std::string &s, const char *fmt, ...)
free (buf);
va_end (ap);
}
+*/
diff --git a/agg-plot/utils.h b/agg-plot/utils.h
index c7245d77..1236b202 100644
--- a/agg-plot/utils.h
+++ b/agg-plot/utils.h
@@ -16,6 +16,4 @@ T min (T a, T b) {
extern void trans_affine_compose (agg::trans_affine& a, const agg::trans_affine& b);
-extern void string_printf (std::string &s, const char *fmt, ...);
-
#endif
diff --git a/agg-plot/xwin-show.cpp b/agg-plot/xwin-show.cpp
new file mode 100644
index 00000000..2ac10868
--- /dev/null
+++ b/agg-plot/xwin-show.cpp
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "platform/agg_platform_support.h"
+
+#include "xwin-show.h"
+#include "canvas.h"
+#include "cplot.h"
+#include "lua-cplot-priv.h"
+
+enum flip_y_e { flip_y = true };
+
+class the_application : public agg::platform_support
+{
+public:
+ the_application(agg::pix_format_e format, bool flip_y, cplot *plot,
+ pthread_mutex_t *mutex) :
+ agg::platform_support(format, flip_y), m_plot(plot), m_mutex(mutex)
+ {
+ };
+
+ virtual ~the_application()
+ {
+ }
+
+ virtual void on_draw()
+ {
+ pthread_mutex_lock (m_mutex);
+ canvas can(rbuf_window(), width(), height(), agg::rgba(1.0, 1.0, 1.0));
+ can.clear();
+ m_plot->draw(can);
+ pthread_mutex_unlock (m_mutex);
+ }
+
+private:
+ cplot* m_plot;
+ pthread_mutex_t *m_mutex;
+};
+
+void update_callback (void *_app)
+{
+ the_application *app = (the_application *) _app;
+ app->on_draw();
+ app->update_window();
+};
+
+void *
+xwin_thread_function (void *_cplot)
+{
+ struct lcplot *cp = (struct lcplot *) _cplot;
+
+ pthread_mutex_lock (cp->mutex);
+ cp->is_shown = 1;
+
+ the_application app(agg::pix_format_bgr24, flip_y, cp->plot, cp->mutex);
+ app.caption("GSL shell plot");
+
+ if(app.init(780, 400, agg::window_resize))
+ {
+ cp->x_app = (void *) &app;
+ pthread_mutex_unlock (cp->mutex);
+ app.run();
+ }
+ else
+ {
+ pthread_mutex_lock (cp->mutex);
+ }
+
+ pthread_mutex_lock (cp->mutex);
+ if (cp->lua_is_owner)
+ {
+ cp->is_shown = 0;
+ pthread_mutex_unlock (cp->mutex);
+ }
+ else
+ {
+ pthread_mutex_unlock (cp->mutex);
+ lcplot_destroy (cp);
+ }
+
+ return NULL;
+}
diff --git a/agg-plot/xwin-show.h b/agg-plot/xwin-show.h
new file mode 100644
index 00000000..4749a438
--- /dev/null
+++ b/agg-plot/xwin-show.h
@@ -0,0 +1,6 @@
+
+extern "C" {
+
+ extern void * xwin_thread_function (void *_cplot);
+
+}
diff --git a/gsl-shell.c b/gsl-shell.c
index 4030bdc5..391cc339 100644
--- a/gsl-shell.c
+++ b/gsl-shell.c
@@ -83,7 +83,6 @@ static const luaL_Reg gshlibs[] = {
{NULL, NULL}
};
-
static void lstop (lua_State *L, lua_Debug *ar) {
(void)ar; /* unused arg. */
lua_sethook(L, NULL, 0, 0);
@@ -489,4 +488,3 @@ int main (int argc, char **argv) {
lua_close(L);
return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
-
diff --git a/lua-cplot.h b/lua-cplot.h
new file mode 100644
index 00000000..e8ef67ef
--- /dev/null
+++ b/lua-cplot.h
@@ -0,0 +1,14 @@
+#ifndef LUA_CPLOT_H
+#define LUA_CPLOT_H
+
+#include "lua.h"
+
+#include "defs.h"
+
+__BEGIN_DECLS
+
+extern void cplot_register (lua_State *L);
+
+__END_DECLS
+
+#endif
diff --git a/lua-gsl.c b/lua-gsl.c
index e78b0f02..d4c47b4b 100644
--- a/lua-gsl.c
+++ b/lua-gsl.c
@@ -38,6 +38,8 @@
#include "pdf.h"
#include "cdf.h"
+#include "lua-cplot.h"
+
static const struct luaL_Reg gsl_methods_dummy[] = {{NULL, NULL}};
int
@@ -62,6 +64,8 @@ luaopen_gsl (lua_State *L)
pdf_register (L);
cdf_register (L);
+ cplot_register (L);
+
#ifdef LNUM_COMPLEX
lua_pushboolean (L, 1);
lua_setfield (L, -2, "have_complex");
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月16日 07:32:41 +0000

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