changeset 114:9d0fe7f54e14

merged image viewing code to cortex.util
author Robert McIntyre <rlm@mit.edu>
date Thu, 19 Jan 2012 22:19:24 -0700
parents a980462ebe76
children 247860e25536
files org/eyes.org org/test-creature.org org/util.org
diffstat 3 files changed, 36 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/eyes.org	Thu Jan 19 22:08:46 2012 -0700
     1.2 +++ b/org/eyes.org	Thu Jan 19 22:19:24 2012 -0700
     1.3 @@ -119,34 +119,6 @@
     1.4    (:import com.jme3.scene.Node)
     1.5    (:import com.jme3.math.Vector3f))
     1.6  
     1.7 -(defn view-image
     1.8 -  "Initailizes a JPanel on which you may draw a BufferedImage.
     1.9 -   Returns a function that accepts a BufferedImage and draws it to the
    1.10 -   JPanel."
    1.11 -  []
    1.12 -  (let [image
    1.13 -        (atom
    1.14 -         (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
    1.15 -        panel 
    1.16 -        (proxy [JPanel] []
    1.17 -          (paint
    1.18 -            [graphics]
    1.19 -            (proxy-super paintComponent graphics)
    1.20 -            (.drawImage graphics @image 0 0 nil)))
    1.21 -        frame (JFrame. "Display Image")]
    1.22 -    (SwingUtilities/invokeLater
    1.23 -     (fn []
    1.24 -       (doto frame
    1.25 -         (-> (.getContentPane) (.add panel))
    1.26 -         (.pack)
    1.27 -         (.setLocationRelativeTo nil)
    1.28 -         (.setResizable true)
    1.29 -         (.setVisible true))))
    1.30 -    (fn [#^BufferedImage i]
    1.31 -      (reset! image i)
    1.32 -      (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
    1.33 -      (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
    1.34 -
    1.35  (defn test-two-eyes
    1.36    "Testing vision:
    1.37     Tests the vision system by creating two views of the same rotating
     2.1 --- a/org/test-creature.org	Thu Jan 19 22:08:46 2012 -0700
     2.2 +++ b/org/test-creature.org	Thu Jan 19 22:19:24 2012 -0700
     2.3 @@ -67,34 +67,6 @@
     2.4  (declare joint-create)
     2.5  (use 'clojure.contrib.def)
     2.6  
     2.7 -(defn view-image
     2.8 -  "Initailizes a JPanel on which you may draw a BufferedImage.
     2.9 -   Returns a function that accepts a BufferedImage and draws it to the
    2.10 -   JPanel."
    2.11 -  []
    2.12 -  (let [image
    2.13 -        (atom
    2.14 -         (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
    2.15 -        panel 
    2.16 -        (proxy [JPanel] []
    2.17 -          (paint
    2.18 -            [graphics]
    2.19 -            (proxy-super paintComponent graphics)
    2.20 -            (.drawImage graphics @image 0 0 nil)))
    2.21 -        frame (JFrame. "Display Image")]
    2.22 -    (SwingUtilities/invokeLater
    2.23 -     (fn []
    2.24 -       (doto frame
    2.25 -         (-> (.getContentPane) (.add panel))
    2.26 -         (.pack)
    2.27 -         (.setLocationRelativeTo nil)
    2.28 -         (.setResizable true)
    2.29 -         (.setVisible true))))
    2.30 -    (fn [#^BufferedImage i]
    2.31 -      (reset! image i)
    2.32 -      (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
    2.33 -      (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
    2.34 -
    2.35  (defn points->image
    2.36    "Take a sparse collection of points and visuliaze it as a
    2.37     BufferedImage."
     3.1 --- a/org/util.org	Thu Jan 19 22:08:46 2012 -0700
     3.2 +++ b/org/util.org	Thu Jan 19 22:19:24 2012 -0700
     3.3 @@ -94,19 +94,22 @@
     3.4    (:import com.jme3.scene.shape.Sphere)
     3.5    (:import com.jme3.light.AmbientLight)
     3.6    (:import com.jme3.light.DirectionalLight)
     3.7 -  (:import com.jme3.math.ColorRGBA)
     3.8 +  (:import (com.jme3.math Triangle ColorRGBA))
     3.9    (:import com.jme3.bullet.BulletAppState)
    3.10    (:import com.jme3.material.Material)
    3.11    (:import com.jme3.scene.Geometry)
    3.12 +  (:import java.awt.image.BufferedImage)
    3.13 +  (:import javax.swing.JPanel)
    3.14 +  (:import javax.swing.JFrame)
    3.15 +  (:import javax.swing.SwingUtilities)
    3.16 +  
    3.17    (:import (java.util.logging Level Logger)))
    3.18  
    3.19 -
    3.20 -
    3.21  (defvar println-repl
    3.22    (bound-fn [& args] (apply println args))
    3.23    "println called from the LWJGL thread will not go to the REPL, but
    3.24 -  instead to whatever terminal started the JVM process. This function
    3.25 -  will always output to the REPL")
    3.26 +   instead to whatever terminal started the JVM process. This function
    3.27 +   will always output to the REPL")
    3.28  
    3.29  (defn position-camera
    3.30    "Change the position of the in-world camera."
    3.31 @@ -388,6 +391,34 @@
    3.32  #+begin_src clojure :results silent
    3.33  (in-ns 'cortex.util)
    3.34  
    3.35 +(defn view-image
    3.36 +  "Initailizes a JPanel on which you may draw a BufferedImage.
    3.37 +   Returns a function that accepts a BufferedImage and draws it to the
    3.38 +   JPanel."
    3.39 +  []
    3.40 +  (let [image
    3.41 +        (atom
    3.42 +         (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
    3.43 +        panel 
    3.44 +        (proxy [JPanel] []
    3.45 +          (paint
    3.46 +            [graphics]
    3.47 +            (proxy-super paintComponent graphics)
    3.48 +            (.drawImage graphics @image 0 0 nil)))
    3.49 +        frame (JFrame. "Display Image")]
    3.50 +    (SwingUtilities/invokeLater
    3.51 +     (fn []
    3.52 +       (doto frame
    3.53 +         (-> (.getContentPane) (.add panel))
    3.54 +         (.pack)
    3.55 +         (.setLocationRelativeTo nil)
    3.56 +         (.setResizable true)
    3.57 +         (.setVisible true))))
    3.58 +    (fn [#^BufferedImage i]
    3.59 +      (reset! image i)
    3.60 +      (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
    3.61 +      (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
    3.62 +
    3.63  (defprotocol Viewable
    3.64    (view [something]))
    3.65