# HG changeset patch # User Robert McIntyre # Date 1328354612 25200 # Node ID 94b79c191fc7f001386c25ac40422d939c4b3a00 # Parent 1c8e9d389ea443cac4425fda0b84bfeecd0e5e09 renamed some functions in vision.org diff -r 1c8e9d389ea4 -r 94b79c191fc7 org/hearing.org --- a/org/hearing.org Sat Feb 04 04:08:08 2012 -0700 +++ b/org/hearing.org Sat Feb 04 04:23:32 2012 -0700 @@ -809,7 +809,7 @@ (reset! old-position new-position))) (controlRender [_ _]))))) -(defn create-listener! +(defn add-ear! "Create a Listener centered on the current position of 'ear which follows the closest physical node in 'creature and sends sound data to 'continuation." @@ -833,7 +833,7 @@ register-listener! (runonce (fn [#^Application world] - (create-listener! + (add-ear! world creature ear (fn [data] (reset! hearing-data (vec data))))))] diff -r 1c8e9d389ea4 -r 94b79c191fc7 org/test-creature.org --- a/org/test-creature.org Sat Feb 04 04:08:08 2012 -0700 +++ b/org/test-creature.org Sat Feb 04 04:23:32 2012 -0700 @@ -233,11 +233,11 @@ (dorun (map #(% world) init-vision-fns)) ;;(dorun (map #(% world) init-hearing-fns)) - (add-eye! world - (attach-eye creature (test-eye)) + (add-camera! world + (add-eye! creature (test-eye)) (comp (view-image) BufferedImage!)) - (add-eye! world (.getCamera world) no-op) + (add-camera! world (.getCamera world) no-op) ;;(set-gravity world (Vector3f. 0 0 0)) ;;(com.aurellem.capture.Capture/captureVideo ;; world (file-str "/home/r/proj/ai-videos/hand")) @@ -308,8 +308,8 @@ (bind-sense rock cam) (.setTimer world (RatchetTimer. 60)) - (add-eye! world cam (comp (view-image) BufferedImage!)) - (add-eye! world (.getCamera world) no-op)) + (add-camera! world cam (comp (view-image) BufferedImage!)) + (add-camera! world (.getCamera world) no-op)) ) (fn [_ _] (println-repl rot))))) diff -r 1c8e9d389ea4 -r 94b79c191fc7 org/vision.org --- a/org/vision.org Sat Feb 04 04:08:08 2012 -0700 +++ b/org/vision.org Sat Feb 04 04:23:32 2012 -0700 @@ -120,8 +120,8 @@ (byteBuffer->bufferedImage! (frameBuffer->byteBuffer! r fb bb) bi)) -(defn add-eye! - "Add an eye to the world, calling continuation on every frame +(defn add-camera! + "Add a camera to the world, calling continuation on every frame produced." [#^Application world camera continuation] (let [width (.getWidth camera) @@ -134,12 +134,12 @@ (.addProcessor (vision-pipeline continuation)) (.attachScene (.getRootNode world))))) -(defn retina-sensor-image +(defn retina-sensor-profile "Return a map of pixel selection functions to BufferedImages - describing the distribution of light-sensitive components on this - geometry's surface. Each function creates an integer from the rgb - values found in the pixel. :red, :green, :blue, :gray are already - defined as extracting the red green blue and average components + describing the distribution of light-sensitive components of this + eye. Each function creates an integer from the rgb values found in + the pixel. :red, :green, :blue, :gray are already defined as + extracting the red, green, blue, and average components respectively." [#^Spatial eye] (if-let [eye-map (meta-data eye "eye")] @@ -148,11 +148,11 @@ (eval (read-string eye-map))))) (defn eye-dimensions - "returns the width and height specified in the metadata of the eye" + "Returns [width, height] specified in the metadata of the eye" [#^Spatial eye] (let [dimensions (map #(vector (.getWidth %) (.getHeight %)) - (vals (retina-sensor-image eye)))] + (vals (retina-sensor-profile eye)))] [(apply max (map first dimensions)) (apply max (map second dimensions))])) @@ -162,8 +162,10 @@ (sense-nodes "eyes") "Return the children of the creature's \"eyes\" node.") -(defn attach-eye - "Attach a Camera to the appropiate area and return the Camera." +(defn add-eye! + "Create a Camera centered on the current position of 'eye which + follows the closest physical node in 'creature and sends visual + data to 'continuation." [#^Node creature #^Spatial eye] (let [target (closest-node creature eye) [cam-width cam-height] (eye-dimensions eye) @@ -182,18 +184,18 @@ :blue 0x0000FF :green 0x00FF00}) -(defn enable-vision +(defn vision-fn "return [init-function sensor-functions] for a particular eye" [#^Node creature #^Spatial eye & {skip :skip :or {skip 0}}] - (let [retinal-map (retina-sensor-image eye) - camera (attach-eye creature eye) + (let [retinal-map (retina-sensor-profile eye) + camera (add-eye! creature eye) vision-image (atom (BufferedImage. (.getWidth camera) (.getHeight camera) BufferedImage/TYPE_BYTE_BINARY))] [(fn [world] - (add-eye! + (add-camera! world camera (let [counter (atom 0)] (fn [r fb bb bi] @@ -223,7 +225,7 @@ (into senses-a senses-b)]) [[][]] (for [eye (eyes creature)] - (enable-vision creature eye)))) + (vision-fn creature eye)))) #+end_src @@ -270,11 +272,11 @@ (let [cam (.clone (.getCamera world)) width (.getWidth cam) height (.getHeight cam)] - (add-eye! world cam + (add-camera! world cam ;;no-op (comp (view-image) BufferedImage!) ) - (add-eye! world + (add-camera! world (doto (.clone cam) (.setLocation (Vector3f. -10 0 0)) (.lookAt Vector3f/ZERO Vector3f/UNIT_Y)) @@ -282,7 +284,7 @@ (comp (view-image) BufferedImage!)) ;; This is here to restore the main view ;; after the other views have completed processing - (add-eye! world (.getCamera world) no-op))) + (add-camera! world (.getCamera world) no-op))) (fn [world tpf] (.rotate candy (* tpf 0.2) 0 0))))) #+end_src