Mercurial > cortex
changeset 335:5dcd44576cbc
add BufferedImage to Viewable Protocol
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 20 Jul 2012 13:02:58 -0500 |
parents | c264ebf683b4 |
children | 70469ff8eb56 |
files | org/util.org org/vision.org |
diffstat | 2 files changed, 50 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/util.org Fri Jul 20 11:22:21 2012 -0500 1.2 +++ b/org/util.org Fri Jul 20 13:02:58 2012 -0500 1.3 @@ -100,6 +100,7 @@ 1.4 (:import java.awt.image.BufferedImage) 1.5 (:import javax.swing.JPanel) 1.6 (:import javax.swing.JFrame) 1.7 + (:import ij.ImagePlus) 1.8 (:import javax.swing.SwingUtilities) 1.9 (:import com.jme3.scene.plugins.blender.BlenderModelLoader) 1.10 (:import (java.util.logging Level Logger))) 1.11 @@ -532,6 +533,12 @@ 1.12 (view (doto (Node.) 1.13 (.attachChild (box 1 1 1 :color color)))))) 1.14 1.15 +(extend-type java.awt.image.BufferedImage 1.16 + Viewable 1.17 + (view 1.18 + [image] 1.19 + (.show (ImagePlus. "view-buffered-image" image)))) 1.20 + 1.21 (defprotocol Textual 1.22 (text [something] 1.23 "Display a detailed textual analysis of the given object."))
2.1 --- a/org/vision.org Fri Jul 20 11:22:21 2012 -0500 2.2 +++ b/org/vision.org Fri Jul 20 13:02:58 2012 -0500 2.3 @@ -576,45 +576,51 @@ 2.4 :position (Vector3f. 0 -5 0)) 2.5 timer (RatchetTimer. 60)] 2.6 2.7 - (world (nodify [(floor) the-worm x-axis y-axis z-axis me]) 2.8 - (assoc standard-debug-controls 2.9 - "key-r" (colored-cannon-ball ColorRGBA/Red) 2.10 - "key-b" (colored-cannon-ball ColorRGBA/Blue) 2.11 - "key-g" (colored-cannon-ball ColorRGBA/Green)) 2.12 - (fn [world] 2.13 - (light-up-everything world) 2.14 - (speed-up world) 2.15 - (.setTimer world timer) 2.16 - (display-dilated-time world timer) 2.17 - ;; add a view from the worm's perspective 2.18 - (if record? 2.19 - (Capture/captureVideo 2.20 - world 2.21 - (File. 2.22 - "/home/r/proj/cortex/render/worm-vision/main-view"))) 2.23 - 2.24 - (add-camera! 2.25 - world 2.26 - (add-eye! the-worm 2.27 - (.getChild 2.28 - (.getChild the-worm "eyes") "eye")) 2.29 - (comp 2.30 - (view-image 2.31 - (if record? 2.32 - (File. 2.33 - "/home/r/proj/cortex/render/worm-vision/worm-view"))) 2.34 - BufferedImage!)) 2.35 - 2.36 - (set-gravity world Vector3f/ZERO)) 2.37 - 2.38 - (fn [world _ ] 2.39 - (.setLocalTranslation me (.getLocation (.getCamera world))) 2.40 - (vision-display 2.41 - (map #(% world) vision) 2.42 - (if record? (File. "/home/r/proj/cortex/render/worm-vision"))) 2.43 - (fix-display world)))))) 2.44 + (world 2.45 + (nodify [(floor) the-worm x-axis y-axis z-axis me]) 2.46 + (assoc standard-debug-controls 2.47 + "key-r" (colored-cannon-ball ColorRGBA/Red) 2.48 + "key-b" (colored-cannon-ball ColorRGBA/Blue) 2.49 + "key-g" (colored-cannon-ball ColorRGBA/Green)) 2.50 + (fn [world] 2.51 + (light-up-everything world) 2.52 + (speed-up world) 2.53 + (.setTimer world timer) 2.54 + (display-dilated-time world timer) 2.55 + ;; add a view from the worm's perspective 2.56 + (if record? 2.57 + (Capture/captureVideo 2.58 + world 2.59 + (File. 2.60 + "/home/r/proj/cortex/render/worm-vision/main-view"))) 2.61 + 2.62 + (add-camera! 2.63 + world 2.64 + (add-eye! the-worm 2.65 + (.getChild 2.66 + (.getChild the-worm "eyes") "eye")) 2.67 + (comp 2.68 + (view-image 2.69 + (if record? 2.70 + (File. 2.71 + "/home/r/proj/cortex/render/worm-vision/worm-view"))) 2.72 + BufferedImage!)) 2.73 + (set-gravity world Vector3f/ZERO)) 2.74 + 2.75 + (fn [world _ ] 2.76 + (.setLocalTranslation me (.getLocation (.getCamera world))) 2.77 + (vision-display 2.78 + (map #(% world) vision) 2.79 + (if record? 2.80 + (File. "/home/r/proj/cortex/render/worm-vision"))) 2.81 + (fix-display world) 2.82 + ))))) 2.83 #+end_src 2.84 2.85 +#+RESULTS: test-2 2.86 +| | #'cortex.test.vision/test-worm-vision | 2.87 + 2.88 + 2.89 The world consists of the worm and a flat gray floor. I can shoot red, 2.90 green, blue and white cannonballs at the worm. The worm is initially 2.91 looking down at the floor, and there is no gravity. My perspective