# HG changeset patch # User Robert McIntyre # Date 1342807378 18000 # Node ID 5dcd44576cbc00308af2903957ec70895ba22de2 # Parent c264ebf683b4dbdc37b508726b20f2a36df0c4cf add BufferedImage to Viewable Protocol diff -r c264ebf683b4 -r 5dcd44576cbc org/util.org --- a/org/util.org Fri Jul 20 11:22:21 2012 -0500 +++ b/org/util.org Fri Jul 20 13:02:58 2012 -0500 @@ -100,6 +100,7 @@ (:import java.awt.image.BufferedImage) (:import javax.swing.JPanel) (:import javax.swing.JFrame) + (:import ij.ImagePlus) (:import javax.swing.SwingUtilities) (:import com.jme3.scene.plugins.blender.BlenderModelLoader) (:import (java.util.logging Level Logger))) @@ -532,6 +533,12 @@ (view (doto (Node.) (.attachChild (box 1 1 1 :color color)))))) +(extend-type java.awt.image.BufferedImage + Viewable + (view + [image] + (.show (ImagePlus. "view-buffered-image" image)))) + (defprotocol Textual (text [something] "Display a detailed textual analysis of the given object.")) diff -r c264ebf683b4 -r 5dcd44576cbc org/vision.org --- a/org/vision.org Fri Jul 20 11:22:21 2012 -0500 +++ b/org/vision.org Fri Jul 20 13:02:58 2012 -0500 @@ -576,45 +576,51 @@ :position (Vector3f. 0 -5 0)) timer (RatchetTimer. 60)] - (world (nodify [(floor) the-worm x-axis y-axis z-axis me]) - (assoc standard-debug-controls - "key-r" (colored-cannon-ball ColorRGBA/Red) - "key-b" (colored-cannon-ball ColorRGBA/Blue) - "key-g" (colored-cannon-ball ColorRGBA/Green)) - (fn [world] - (light-up-everything world) - (speed-up world) - (.setTimer world timer) - (display-dilated-time world timer) - ;; add a view from the worm's perspective - (if record? - (Capture/captureVideo - world - (File. - "/home/r/proj/cortex/render/worm-vision/main-view"))) - - (add-camera! - world - (add-eye! the-worm - (.getChild - (.getChild the-worm "eyes") "eye")) - (comp - (view-image - (if record? - (File. - "/home/r/proj/cortex/render/worm-vision/worm-view"))) - BufferedImage!)) - - (set-gravity world Vector3f/ZERO)) - - (fn [world _ ] - (.setLocalTranslation me (.getLocation (.getCamera world))) - (vision-display - (map #(% world) vision) - (if record? (File. "/home/r/proj/cortex/render/worm-vision"))) - (fix-display world)))))) + (world + (nodify [(floor) the-worm x-axis y-axis z-axis me]) + (assoc standard-debug-controls + "key-r" (colored-cannon-ball ColorRGBA/Red) + "key-b" (colored-cannon-ball ColorRGBA/Blue) + "key-g" (colored-cannon-ball ColorRGBA/Green)) + (fn [world] + (light-up-everything world) + (speed-up world) + (.setTimer world timer) + (display-dilated-time world timer) + ;; add a view from the worm's perspective + (if record? + (Capture/captureVideo + world + (File. + "/home/r/proj/cortex/render/worm-vision/main-view"))) + + (add-camera! + world + (add-eye! the-worm + (.getChild + (.getChild the-worm "eyes") "eye")) + (comp + (view-image + (if record? + (File. + "/home/r/proj/cortex/render/worm-vision/worm-view"))) + BufferedImage!)) + (set-gravity world Vector3f/ZERO)) + + (fn [world _ ] + (.setLocalTranslation me (.getLocation (.getCamera world))) + (vision-display + (map #(% world) vision) + (if record? + (File. "/home/r/proj/cortex/render/worm-vision"))) + (fix-display world) + ))))) #+end_src +#+RESULTS: test-2 +| | #'cortex.test.vision/test-worm-vision | + + The world consists of the worm and a flat gray floor. I can shoot red, green, blue and white cannonballs at the worm. The worm is initially looking down at the floor, and there is no gravity. My perspective