#!/bin/sh
exec lush2 "$0" "$@"
!#

;; Plot an object's surface composed of several meshes.
;; 
;; Based on demo file "multimsh.dem" in the gnuplot distribution
;; See subdirectory 'gnuplot' for relevant files and Copyright
;; statement.

(libload "gnuplot/oldplot")   ; plot-image
(libload "gnuplot/test-plot") ; read-xyz-data
(libload "libimage/image-io")

(ogre)

(let ((gp (new Gnuplot 'interactive ()))
      (title "Digitized Blue Whale")
      (meshes (read-xyz-data "gnuplot/whale.dat")) )
  
  (defparameter *gnuplot* gp)
  ;(printf "gnuplot instance bound to symbol *gnuplot*\n")

  ;; preamble
  (gp "set parametric; set hidden3d; unset key"
      "set xrange [0:8]; set yrange [-4:4]; set zrange [-2:2]"
      "set style data line"
      (sprintf "set title '%s'" title))
  
  ;; plot the meshes
  (apply gp "splot '-'" meshes)
  
  (wait (new AutoWindowObject 10 10 100 100 ""
          (new StdButton "next demo" (lambda (c) (==> thiswindowobject delete))) ))
  
  (gp "reset")
  (let ((img (image-read "lena.jpg"))
        (plotter gp))
      (plot-image img) )

  (wait (new AutoWindowObject 10 10 100 100 ""
          (new StdButton "end demo" (lambda (c) 
                                      (delete gp)
                                      (==> thiswindowobject delete))) )) )
