comparison org/eyes.org @ 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 aaacf087504c
comparison
equal deleted inserted replaced
113:a980462ebe76 114:9d0fe7f54e14
117 (:import javax.swing.JFrame) 117 (:import javax.swing.JFrame)
118 (:import com.jme3.math.ColorRGBA) 118 (:import com.jme3.math.ColorRGBA)
119 (:import com.jme3.scene.Node) 119 (:import com.jme3.scene.Node)
120 (:import com.jme3.math.Vector3f)) 120 (:import com.jme3.math.Vector3f))
121 121
122 (defn view-image
123 "Initailizes a JPanel on which you may draw a BufferedImage.
124 Returns a function that accepts a BufferedImage and draws it to the
125 JPanel."
126 []
127 (let [image
128 (atom
129 (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
130 panel
131 (proxy [JPanel] []
132 (paint
133 [graphics]
134 (proxy-super paintComponent graphics)
135 (.drawImage graphics @image 0 0 nil)))
136 frame (JFrame. "Display Image")]
137 (SwingUtilities/invokeLater
138 (fn []
139 (doto frame
140 (-> (.getContentPane) (.add panel))
141 (.pack)
142 (.setLocationRelativeTo nil)
143 (.setResizable true)
144 (.setVisible true))))
145 (fn [#^BufferedImage i]
146 (reset! image i)
147 (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
148 (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
149
150 (defn test-two-eyes 122 (defn test-two-eyes
151 "Testing vision: 123 "Testing vision:
152 Tests the vision system by creating two views of the same rotating 124 Tests the vision system by creating two views of the same rotating
153 object from different angles and displaying both of those views in 125 object from different angles and displaying both of those views in
154 JFrames. 126 JFrames.