Mercurial > cortex
changeset 99:b7a3ba5e879b
made BufferedImage visulation more general
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 14 Jan 2012 01:07:18 -0700 |
parents | 5b23961433e3 |
children | 940074adc1d5 |
files | org/eyes.org org/test-creature.org |
diffstat | 2 files changed, 92 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/eyes.org Wed Jan 11 21:30:26 2012 -0700 1.2 +++ b/org/eyes.org Sat Jan 14 01:07:18 2012 -0700 1.3 @@ -99,31 +99,32 @@ 1.4 (:import com.jme3.math.Vector3f)) 1.5 1.6 (defn view-image 1.7 - "Initailizes a JPanel on which you may draw a BufferedImage of the 1.8 - given width and height. Returns a function that accepts a 1.9 - BufferedImage and draws it to the JPanel." 1.10 - [width height] 1.11 + "Initailizes a JPanel on which you may draw a BufferedImage. 1.12 + Returns a function that accepts a BufferedImage and draws it to the 1.13 + JPanel." 1.14 + [] 1.15 (let [image 1.16 (atom 1.17 - (BufferedImage. width height BufferedImage/TYPE_4BYTE_ABGR)) 1.18 + (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR)) 1.19 panel 1.20 (proxy [JPanel] [] 1.21 (paint 1.22 [graphics] 1.23 (proxy-super paintComponent graphics) 1.24 - (.drawImage graphics @image 0 0 nil)))] 1.25 + (.drawImage graphics @image 0 0 nil))) 1.26 + frame (JFrame. "Display Image")] 1.27 (SwingUtilities/invokeLater 1.28 (fn [] 1.29 - (.setPreferredSize panel (Dimension. width height)) 1.30 - (doto (JFrame. "Eye Camera!") 1.31 + (doto frame 1.32 (-> (.getContentPane) (.add panel)) 1.33 (.pack) 1.34 (.setLocationRelativeTo nil) 1.35 - (.setResizable false) 1.36 + (.setResizable true) 1.37 (.setVisible true)))) 1.38 (fn [#^BufferedImage i] 1.39 (reset! image i) 1.40 - (.repaint panel)))) 1.41 + (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i))) 1.42 + (.repaint panel 0 0 (.getWidth i) (.getHeight i))))) 1.43 1.44 (defn test-two-eyes 1.45 "Testing vision: 1.46 @@ -143,12 +144,12 @@ 1.47 (let [cam (.clone (.getCamera world)) 1.48 width (.getWidth cam) 1.49 height (.getHeight cam)] 1.50 - (add-eye world cam (view-image width height)) 1.51 + (add-eye world cam (view-image)) 1.52 (add-eye world 1.53 (doto (.clone cam) 1.54 (.setLocation (Vector3f. -10 0 0)) 1.55 (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) 1.56 - (view-image width height)) 1.57 + (view-image)) 1.58 ;; This is here to restore the main view 1.59 ;; after the other views have completed processing 1.60 (add-eye world (.getCamera world) no-op)))
2.1 --- a/org/test-creature.org Wed Jan 11 21:30:26 2012 -0700 2.2 +++ b/org/test-creature.org Sat Jan 14 01:07:18 2012 -0700 2.3 @@ -6,6 +6,15 @@ 2.4 #+SETUPFILE: ../../aurellem/org/setup.org 2.5 #+INCLUDE: ../../aurellem/org/level-0.org 2.6 2.7 + 2.8 +* objectives 2.9 + - [ ] get an overall bitmap-like image for touch 2.10 + - [ ] write code to visuliaze this bitmap 2.11 + - [ ] directly change the UV-pixels to show touch sensor activation 2.12 + - [ ] write an explination for why b&w bitmaps for senses is appropiate 2.13 + - [ ] clean up touch code and write visulazation test 2.14 + - [ ] do the same for eyes 2.15 + 2.16 * Intro 2.17 So far, I've made the following senses -- 2.18 - Vision 2.19 @@ -49,8 +58,63 @@ 2.20 (use '(cortex world util body hearing touch vision)) 2.21 2.22 (rlm.rlm-commands/help) 2.23 +(import java.awt.image.BufferedImage) 2.24 +(import javax.swing.JPanel) 2.25 +(import javax.swing.SwingUtilities) 2.26 +(import java.awt.Dimension) 2.27 +(import javax.swing.JFrame) 2.28 +(import java.awt.Dimension) 2.29 +(declare joint-create) 2.30 2.31 -(declare joint-create) 2.32 +(defn view-image 2.33 + "Initailizes a JPanel on which you may draw a BufferedImage. 2.34 + Returns a function that accepts a BufferedImage and draws it to the 2.35 + JPanel." 2.36 + [] 2.37 + (let [image 2.38 + (atom 2.39 + (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR)) 2.40 + panel 2.41 + (proxy [JPanel] [] 2.42 + (paint 2.43 + [graphics] 2.44 + (proxy-super paintComponent graphics) 2.45 + (.drawImage graphics @image 0 0 nil))) 2.46 + frame (JFrame. "Display Image")] 2.47 + (SwingUtilities/invokeLater 2.48 + (fn [] 2.49 + (doto frame 2.50 + (-> (.getContentPane) (.add panel)) 2.51 + (.pack) 2.52 + (.setLocationRelativeTo nil) 2.53 + (.setResizable true) 2.54 + (.setVisible true)))) 2.55 + (fn [#^BufferedImage i] 2.56 + (reset! image i) 2.57 + (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i))) 2.58 + (.repaint panel 0 0 (.getWidth i) (.getHeight i))))) 2.59 + 2.60 + 2.61 +(defn visualize [points] 2.62 + 2.63 + 2.64 + 2.65 +(defn collapse 2.66 + "Take a set of pairs of integers and collapse them into a 2.67 + contigous bitmap." 2.68 + [points] 2.69 + (let [center [0 0]] 2.70 + 2.71 + ) 2.72 + 2.73 + 2.74 + 2.75 + 2.76 + 2.77 + 2.78 + 2.79 + 2.80 + 2.81 2.82 (defn load-bullet [] 2.83 (let [sim (world (Node.) {} no-op no-op)] 2.84 @@ -314,7 +378,6 @@ 2.85 ;; (println-repl (float (/ @timer 60)))))) 2.86 ))) 2.87 2.88 - 2.89 (defn colorful [] 2.90 (.getChild (worm-model) "worm-21")) 2.91 2.92 @@ -364,8 +427,6 @@ 2.93 (ImagePlus. 2.94 "UV-map" 2.95 (ImageToAwt/convert im false false 0)))))) 2.96 - 2.97 - 2.98 2.99 (import ij.process.ImageProcessor) 2.100 (import java.awt.image.BufferedImage) 2.101 @@ -602,7 +663,8 @@ 2.102 (set 2.103 (filter #(not (= geo %)) 2.104 (map #(.getGeometry %) results)))] 2.105 - (count touch-objects))))))))) 2.106 + (if (> (count touch-objects) 0) 2.107 + 1 0))))))))) 2.108 2.109 (defn touch [#^Node pieces] 2.110 (let [touch-components 2.111 @@ -612,11 +674,6 @@ 2.112 (fn [node] 2.113 (reduce into [] (map #(% node) touch-components))))) 2.114 2.115 - 2.116 - 2.117 - 2.118 - 2.119 - 2.120 (defn all-names [] 2.121 (concat 2.122 (re-split #"\n" (slurp (file-str 2.123 @@ -985,20 +1042,6 @@ 2.124 ) 2.125 )) 2.126 2.127 - 2.128 - 2.129 -#+end_src 2.130 - 2.131 - 2.132 -* COMMENT generate source 2.133 -#+begin_src clojure :tangle ../src/cortex/silly.clj 2.134 -<<body-1>> 2.135 -#+end_src 2.136 - 2.137 - 2.138 - 2.139 - 2.140 - 2.141 (defn transform-trianglesdsd 2.142 "Transform that converts each vertex in the first triangle 2.143 into the corresponding vertex in the second triangle." 2.144 @@ -1061,25 +1104,19 @@ 2.145 (dorun (map println in***)) 2.146 (println) 2.147 2.148 - ))) 2.149 - 2.150 - 2.151 - 2.152 - 2.153 - 2.154 - 2.155 - 2.156 - 2.157 - 2.158 + )))) 2.159 2.160 2.161 - 2.162 - 2.163 - 2.164 - 2.165 - 2.166 - 2.167 - 2.168 - ) 2.169 + 2.170 + 2.171 +#+end_src 2.172 + 2.173 + 2.174 +* COMMENT generate source 2.175 +#+begin_src clojure :tangle ../src/cortex/silly.clj 2.176 +<<body-1>> 2.177 +#+end_src 2.178 + 2.179 + 2.180 2.181