Mercurial > cortex
comparison org/vision.org @ 170:1a00b4918529
removed vision-init-fns requirement; changed names
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 04 Feb 2012 05:00:10 -0700 |
parents | 94b79c191fc7 |
children | 15bde60217aa |
comparison
equal
deleted
inserted
replaced
169:94b79c191fc7 | 170:1a00b4918529 |
---|---|
5 #+keywords: computer vision, jMonkeyEngine3, clojure | 5 #+keywords: computer vision, jMonkeyEngine3, clojure |
6 #+SETUPFILE: ../../aurellem/org/setup.org | 6 #+SETUPFILE: ../../aurellem/org/setup.org |
7 #+INCLUDE: ../../aurellem/org/level-0.org | 7 #+INCLUDE: ../../aurellem/org/level-0.org |
8 #+babel: :mkdirp yes :noweb yes :exports both | 8 #+babel: :mkdirp yes :noweb yes :exports both |
9 | 9 |
10 * Vision | 10 * COMMENT Vision |
11 | 11 |
12 I want to make creatures with eyes. Each eye can be independely moved | 12 I want to make creatures with eyes. Each eye can be independely moved |
13 and should see its own version of the world depending on where it is. | 13 and should see its own version of the world depending on where it is. |
14 | 14 |
15 Here's how vision will work. | 15 Here's how vision will work. |
191 camera (add-eye! creature eye) | 191 camera (add-eye! creature eye) |
192 vision-image | 192 vision-image |
193 (atom | 193 (atom |
194 (BufferedImage. (.getWidth camera) | 194 (BufferedImage. (.getWidth camera) |
195 (.getHeight camera) | 195 (.getHeight camera) |
196 BufferedImage/TYPE_BYTE_BINARY))] | 196 BufferedImage/TYPE_BYTE_BINARY)) |
197 [(fn [world] | 197 register-eye! |
198 (add-camera! | 198 (runonce |
199 world camera | 199 (fn [world] |
200 (let [counter (atom 0)] | 200 (add-camera! |
201 (fn [r fb bb bi] | 201 world camera |
202 (if (zero? (rem (swap! counter inc) (inc skip))) | 202 (let [counter (atom 0)] |
203 (reset! vision-image (BufferedImage! r fb bb bi))))))) | 203 (fn [r fb bb bi] |
204 (if (zero? (rem (swap! counter inc) (inc skip))) | |
205 (reset! vision-image | |
206 (BufferedImage! r fb bb bi))))))))] | |
204 (vec | 207 (vec |
205 (map | 208 (map |
206 (fn [[key image]] | 209 (fn [[key image]] |
207 (let [whites (white-coordinates image) | 210 (let [whites (white-coordinates image) |
208 topology (vec (collapse whites)) | 211 topology (vec (collapse whites)) |
209 mask (presets key)] | 212 mask (presets key)] |
210 (fn [] | 213 (fn [world] |
214 (register-eye! world) | |
211 (vector | 215 (vector |
212 topology | 216 topology |
213 (vec | 217 (vec |
214 (for [[x y] whites] | 218 (for [[x y] whites] |
215 (bit-and | 219 (bit-and |
216 mask (.getRGB @vision-image x y)))))))) | 220 mask (.getRGB @vision-image x y)))))))) |
217 retinal-map))])) | 221 retinal-map)))) |
218 | 222 |
219 (defn vision | 223 |
224 ;; TODO maybe should add a viewport-manipulation function to | |
225 ;; automatically change viewport settings, attach shadow filters, etc. | |
226 | |
227 (defn vision! | |
228 "Returns a function which returns visual sensory data when called | |
229 inside a running simulation" | |
220 [#^Node creature & {skip :skip :or {skip 0}}] | 230 [#^Node creature & {skip :skip :or {skip 0}}] |
221 (reduce | 231 (reduce |
222 (fn [[init-a senses-a] | 232 concat |
223 [init-b senses-b]] | |
224 [(conj init-a init-b) | |
225 (into senses-a senses-b)]) | |
226 [[][]] | |
227 (for [eye (eyes creature)] | 233 (for [eye (eyes creature)] |
228 (vision-fn creature eye)))) | 234 (vision-fn creature eye)))) |
229 | 235 |
230 | 236 |
231 #+end_src | 237 #+end_src |