swilena_display permet d'afficher des images olena dans son viewer
favori depuis l'interpréteur python ou ruby.
Je n'ai pas retrouvé comment faire pour installer un repertoire entier
proprement avec automake :( Qqn peut m'aider ?
Index: tools/swilena/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* doc/examples/ruby/simple.rb: New example.
* doc/examples/python/simple.py: New example.
* doc/Makefile.am: Distribute examples.
* ruby/swilena_display.rb: New file.
* ruby/Makefile.am: Install swilena_display.rb
* python/swilena_display.py: New file.
* python/Makefile.am: Install swilena_display.py.
* expand.sh: Adjust.
Index: tools/swilena/doc/Makefile.am
--- tools/swilena/doc/Makefile.am Tue, 18 Feb 2003 12:56:06 +0100 raph
(oln/n/39_Makefile.a 1.2 640)
+++ tools/swilena/doc/Makefile.am Mon, 22 Sep 2003 00:41:25 +0200 burrus_n
(oln/n/39_Makefile.a 1.3 640)
@@ -1,4 +1,5 @@
-
+# FIXME: install the examples somewhere
+EXTRA_DIST = examples
dist_noinst_DATA = swilena.dvi swilena.pdf
info_TEXINFOS = swilena.texi
Index: tools/swilena/expand.sh
--- tools/swilena/expand.sh Sun, 21 Sep 2003 23:13:48 +0200 burrus_n (oln/s/25_expand.sh
1.8 750)
+++ tools/swilena/expand.sh Mon, 22 Sep 2003 00:41:25 +0200 burrus_n (oln/s/25_expand.sh
1.9 750)
@@ -79,7 +79,7 @@
ilist=`expr $ilist + 1`
done
echo; echo
- echo -n "python_PYTHON ="
+ echo -n "python_PYTHON +="
ilist=0
for mod in $MODULES; do
if [ `expr $ilist % 4` = 0 ]; then
@@ -122,8 +122,6 @@
AM_CXXFLAGS = \$(CXXFLAGS_OPTIMIZE)
AM_LDFLAGS = -shared -lswigrb \$(ZLIB_LDFLAGS)
-rubydir = \$(libdir)/ruby
-
EOF
}
@@ -139,16 +137,6 @@
ilist=`expr $ilist + 1`
done
echo; echo
- echo -n "ruby_DATA ="
- ilist=0
- for mod in $MODULES; do
- if [ `expr $ilist % 4` = 0 ]; then
- echo " \\"; echo -ne "\t"
- fi
- echo -n " swilena_$mod.rb"
- ilist=`expr $ilist + 1`
- done
- echo; echo
for mod in $MODULES; do
echo "swilena_${mod}_so_SOURCES = swilena_${mod}_wrap.cxx"
done
@@ -160,7 +148,7 @@
else
sdir=meta
fi
- echo "swilena_${mod}_wrap.cxx swilena_${mod}.rb:
\$(srcdir)/../$sdir/swilena_${mod}.i"
+ echo "swilena_${mod}_wrap.cxx: \$(srcdir)/../$sdir/swilena_${mod}.i"
echo -e "\t\$(SWIG) -c -c++ -ruby -I\$(srcdir)/../src -I\$(srcdir)/../meta
\$(CPPFLAGS) -o swilena_${mod}_wrap.cxx \$(srcdir)/../$sdir/swilena_${mod}.i"
echo
done
Index: tools/swilena/ruby/Makefile.am
--- tools/swilena/ruby/Makefile.am Sun, 21 Sep 2003 23:13:48 +0200 burrus_n
(oln/v/17_Makefile.a 1.1 600)
+++ tools/swilena/ruby/Makefile.am Mon, 22 Sep 2003 00:41:25 +0200 burrus_n
(oln/v/17_Makefile.a 1.2 600)
@@ -5,4 +5,8 @@
SUBDIRS = . tests
+rubydir = $(libdir)/ruby
+
+ruby_DATA = swilena_display.rb
+
include makefile.swig
Index: tools/swilena/python/swilena_display.py
--- tools/swilena/python/swilena_display.py Mon, 22 Sep 2003 00:59:33 +0200 burrus_n ()
+++ tools/swilena/python/swilena_display.py Mon, 22 Sep 2003 00:41:25 +0200 burrus_n
(oln/v/20_swilena_di 1.1 600)
@@ -0,0 +1,24 @@
+import string
+import commands
+from threading import Thread
+
+display_command = "display %{image_file}"
+tmpdir = "/tmp"
+threads = []
+
+def launch_image_viewer(image):
+ command = string.replace(display_command, "%{image_file}", image)
+ status, output = commands.getstatusoutput(command)
+ if status != 0:
+ print "Error while running `%s'!\n" % command
+
+def display_image(oln_image, name):
+ image_file = tmpdir + "/" + name
+ oln_image.save(image_file)
+ new_thread = Thread(target=launch_image_viewer,
+ args = (image_file,))
+ new_thread.start()
+ threads.append(new_thread)
+
+def wait_all_displays():
+ [thread.join() for thread in threads]
Index: tools/swilena/ruby/swilena_display.rb
--- tools/swilena/ruby/swilena_display.rb Mon, 22 Sep 2003 00:59:33 +0200 burrus_n ()
+++ tools/swilena/ruby/swilena_display.rb Mon, 22 Sep 2003 00:41:25 +0200 burrus_n
(oln/v/21_swilena_di 1.1 700)
@@ -0,0 +1,28 @@
+class SwilenaDisplay
+
+ attr_writer :display_command, :tmpdir
+ attr_reader :display_command, :tmpdir
+
+ def initialize
+ @threads = []
+ @display_command = "display %{image_file}"
+ @tmpdir = "/tmp"
+ end
+
+ def launch_image_viewer(image)
+ command = @display_command.gsub("%{image_file}", image)
+ `#{command}`
+ print "Error while running `#{command}'\n" if $? != 0
+ end
+
+ def display_image(oln_image, name)
+ image_file = @tmpdir + "/" + name
+ oln_image.save(image_file)
+ @threads << Thread.new { launch_image_viewer(image_file) }
+ end
+
+ def wait_all_displays
+ @threads.each { |thread| thread.join }
+ end
+
+end
Index: tools/swilena/doc/examples/ruby/simple.rb
--- tools/swilena/doc/examples/ruby/simple.rb Mon, 22 Sep 2003 00:59:33 +0200 burrus_n ()
+++ tools/swilena/doc/examples/ruby/simple.rb Mon, 22 Sep 2003 00:41:25 +0200 burrus_n
(oln/v/22_simple.rb 1.1 600)
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+
+# Set swilena_path to the location where swilena ruby modules are
+$: << ENV["SWILENA_PATH"] if ENV.has_key? "SWILENA_PATH"
+
+require "swilena_image2d"
+require "swilena_ntg_int_u"
+require "swilena_display"
+
+include Swilena_ntg_int_u
+include Swilena_image2d
+
+display = SwilenaDisplay.new
+
+display.tmpdir = "/tmp/swilena"
+display.display_command = "display %{image_file}"
+
+ima = Image2d_u8.new(5,5)
+
+0.upto(5) do |i|
+ 0.upto(5) do |j|
+ ima.set(i, j, Int_u8.new(i + j))
+ end
+end
+
+print ima
+display.display_image (ima, "image1")
+
+ima2 = Image2d_u16.new(10, 10)
+0.upto(5) do |i|
+ 0.upto(5) do |j|
+ ima2.set(i, j, Int_u16.new(1))
+ end
+end
+display.display_image (ima2, "image2")
+
+display.wait_all_displays()
Index: tools/swilena/doc/examples/python/simple.py
--- tools/swilena/doc/examples/python/simple.py Mon, 22 Sep 2003 00:59:33 +0200 burrus_n
()
+++ tools/swilena/doc/examples/python/simple.py Mon, 22 Sep 2003 00:41:25 +0200 burrus_n
(oln/v/23_simple.py 1.1 600)
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+# Add swilena modules path into the PYTHON_PATH variable
+
+from swilena_image2d import *
+from swilena_ntg_int_u import *
+import swilena_display
+from swilena_display import display_image, wait_all_displays
+
+swilena_display.tmpdir = "/tmp/swilena"
+swilena_display.display_command = "xv %{image_file}"
+
+ima = image2d_u8(5,5)
+print ima.at(5,5).value()
+
+ima.set(2,2,int_u8(2))
+print ima
+
+p = ima.ref(1,1)
+p.value(3)
+print ima
+
+lena = image2d_u8();
+lena.load("lena.pgm")
+
+display_image (ima, "lena")
+display_image (lena, "lena2")
+
+wait_all_displays()