comparison org/vision.org @ 172:04a39e6bb695

removed mega-import from cortex.vision
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 05:08:35 -0700
parents 15bde60217aa
children 22548d48cc85
comparison
equal deleted inserted replaced
171:15bde60217aa 172:04a39e6bb695
51 #+name: eyes 51 #+name: eyes
52 #+begin_src clojure 52 #+begin_src clojure
53 (ns cortex.vision 53 (ns cortex.vision
54 "Simulate the sense of vision in jMonkeyEngine3. Enables multiple 54 "Simulate the sense of vision in jMonkeyEngine3. Enables multiple
55 eyes from different positions to observe the same world, and pass 55 eyes from different positions to observe the same world, and pass
56 the observed data to any arbitray function." 56 the observed data to any arbitray function. Automatically reads
57 eye-nodes from specially prepared blender files and instanttiates
58 them in the world as actual eyes."
57 {:author "Robert McIntyre"} 59 {:author "Robert McIntyre"}
58 (:use (cortex world sense util)) 60 (:use (cortex world sense util))
59 (:use clojure.contrib.def) 61 (:use clojure.contrib.def)
60 (:import com.jme3.post.SceneProcessor) 62 (:import com.jme3.post.SceneProcessor)
61 (:import (com.jme3.util BufferUtils Screenshots)) 63 (:import (com.jme3.util BufferUtils Screenshots))
62 (:import java.nio.ByteBuffer) 64 (:import java.nio.ByteBuffer)
63 (:import java.awt.image.BufferedImage) 65 (:import java.awt.image.BufferedImage)
64 (:import com.jme3.renderer.ViewPort) 66 (:import (com.jme3.renderer ViewPort Camera))
65 (:import com.jme3.math.ColorRGBA) 67 (:import com.jme3.math.ColorRGBA)
66 (:import com.jme3.renderer.Renderer) 68 (:import com.jme3.renderer.Renderer)
67 (:import com.jme3.scene.Node)) 69 (:import com.jme3.app.Application)
68 70 (:import com.jme3.texture.FrameBuffer)
69 (cortex.import/mega-import-jme3) 71 (:import (com.jme3.scene Node Spatial)))
70
71 72
72 (defn vision-pipeline 73 (defn vision-pipeline
73 "Create a SceneProcessor object which wraps a vision processing 74 "Create a SceneProcessor object which wraps a vision processing
74 continuation function. The continuation is a function that takes 75 continuation function. The continuation is a function that takes
75 [#^Renderer r #^FrameBuffer fb #^ByteBuffer b #^BufferedImage bi], 76 [#^Renderer r #^FrameBuffer fb #^ByteBuffer b #^BufferedImage bi],
176 cam 45 (/ (.getWidth cam) (.getHeight cam)) 177 cam 45 (/ (.getWidth cam) (.getHeight cam))
177 1 1000) 178 1 1000)
178 (bind-sense target cam) 179 (bind-sense target cam)
179 cam)) 180 cam))
180 181
181 (def presets 182 (defvar color-channel-presets
182 {:all 0xFFFFFF 183 {:all 0xFFFFFF
183 :red 0xFF0000 184 :red 0xFF0000
184 :blue 0x0000FF 185 :blue 0x0000FF
185 :green 0x00FF00}) 186 :green 0x00FF00}
187 "Bitmasks for common RGB color channels")
186 188
187 (defn vision-fn 189 (defn vision-fn
188 "Returns a list of functions, each of which will return a color 190 "Returns a list of functions, each of which will return a color
189 channel's worth of visual information when called inside a running 191 channel's worth of visual information when called inside a running
190 simulation." 192 simulation."
209 (vec 211 (vec
210 (map 212 (map
211 (fn [[key image]] 213 (fn [[key image]]
212 (let [whites (white-coordinates image) 214 (let [whites (white-coordinates image)
213 topology (vec (collapse whites)) 215 topology (vec (collapse whites))
214 mask (presets key)] 216 mask (color-channel-presets key)]
215 (fn [world] 217 (fn [world]
216 (register-eye! world) 218 (register-eye! world)
217 (vector 219 (vector
218 topology 220 topology
219 (vec 221 (vec