diff org/vision.org @ 169:94b79c191fc7

renamed some functions in vision.org
author Robert McIntyre <rlm@mit.edu>
date Sat, 04 Feb 2012 04:23:32 -0700
parents 1c8e9d389ea4
children 1a00b4918529
line wrap: on
line diff
     1.1 --- a/org/vision.org	Sat Feb 04 04:08:08 2012 -0700
     1.2 +++ b/org/vision.org	Sat Feb 04 04:23:32 2012 -0700
     1.3 @@ -120,8 +120,8 @@
     1.4    (byteBuffer->bufferedImage!
     1.5     (frameBuffer->byteBuffer! r fb bb) bi))
     1.6  
     1.7 -(defn add-eye!
     1.8 -  "Add an eye to the world, calling continuation on every frame
     1.9 +(defn add-camera!
    1.10 +  "Add a camera to the world, calling continuation on every frame
    1.11    produced." 
    1.12    [#^Application world camera continuation]
    1.13    (let [width (.getWidth camera)
    1.14 @@ -134,12 +134,12 @@
    1.15        (.addProcessor (vision-pipeline continuation))
    1.16        (.attachScene (.getRootNode world)))))
    1.17  
    1.18 -(defn retina-sensor-image
    1.19 +(defn retina-sensor-profile
    1.20    "Return a map of pixel selection functions to BufferedImages
    1.21 -   describing the distribution of light-sensitive components on this
    1.22 -   geometry's surface. Each function creates an integer from the rgb
    1.23 -   values found in the pixel. :red, :green, :blue, :gray are already
    1.24 -   defined as extracting the red green blue and average components
    1.25 +   describing the distribution of light-sensitive components of this
    1.26 +   eye. Each function creates an integer from the rgb values found in
    1.27 +   the pixel. :red, :green, :blue, :gray are already defined as
    1.28 +   extracting the red, green, blue, and average components
    1.29     respectively."
    1.30     [#^Spatial eye]
    1.31     (if-let [eye-map (meta-data eye "eye")]
    1.32 @@ -148,11 +148,11 @@
    1.33        (eval (read-string eye-map)))))
    1.34  
    1.35  (defn eye-dimensions
    1.36 -  "returns the width and height specified in the metadata of the eye"
    1.37 +  "Returns [width, height] specified in the metadata of the eye"
    1.38    [#^Spatial eye]
    1.39    (let [dimensions
    1.40            (map #(vector (.getWidth %) (.getHeight %))
    1.41 -               (vals (retina-sensor-image eye)))]
    1.42 +               (vals (retina-sensor-profile eye)))]
    1.43      [(apply max (map first dimensions))
    1.44       (apply max (map second dimensions))]))
    1.45  
    1.46 @@ -162,8 +162,10 @@
    1.47    (sense-nodes "eyes")
    1.48    "Return the children of the creature's \"eyes\" node.")
    1.49  
    1.50 -(defn attach-eye
    1.51 -  "Attach a Camera to the appropiate area and return the Camera."
    1.52 +(defn add-eye!
    1.53 +  "Create a Camera centered on the current position of 'eye which
    1.54 +   follows the closest physical node in 'creature and sends visual
    1.55 +   data to 'continuation."
    1.56    [#^Node creature #^Spatial eye]
    1.57    (let [target (closest-node creature eye)
    1.58          [cam-width cam-height] (eye-dimensions eye)
    1.59 @@ -182,18 +184,18 @@
    1.60     :blue   0x0000FF
    1.61     :green  0x00FF00})
    1.62  
    1.63 -(defn enable-vision
    1.64 +(defn vision-fn
    1.65    "return [init-function sensor-functions] for a particular eye"
    1.66    [#^Node creature #^Spatial eye & {skip :skip :or {skip 0}}]
    1.67 -  (let [retinal-map (retina-sensor-image eye)
    1.68 -        camera (attach-eye creature eye)
    1.69 +  (let [retinal-map (retina-sensor-profile eye)
    1.70 +        camera (add-eye! creature eye)
    1.71          vision-image
    1.72          (atom
    1.73           (BufferedImage. (.getWidth camera)
    1.74                           (.getHeight camera)
    1.75                           BufferedImage/TYPE_BYTE_BINARY))]
    1.76      [(fn [world]
    1.77 -       (add-eye!
    1.78 +       (add-camera!
    1.79          world camera
    1.80          (let [counter  (atom 0)]
    1.81            (fn [r fb bb bi]
    1.82 @@ -223,7 +225,7 @@
    1.83        (into senses-a senses-b)])
    1.84     [[][]]      
    1.85     (for [eye (eyes creature)]
    1.86 -     (enable-vision creature eye))))
    1.87 +     (vision-fn creature eye))))
    1.88  
    1.89  
    1.90  #+end_src
    1.91 @@ -270,11 +272,11 @@
    1.92         (let [cam (.clone (.getCamera world))
    1.93               width (.getWidth cam)
    1.94               height (.getHeight cam)]
    1.95 -         (add-eye! world cam 
    1.96 +         (add-camera! world cam 
    1.97                    ;;no-op
    1.98                    (comp (view-image) BufferedImage!)
    1.99                    )
   1.100 -         (add-eye! world
   1.101 +         (add-camera! world
   1.102                    (doto (.clone cam)
   1.103                      (.setLocation (Vector3f. -10 0 0))
   1.104                      (.lookAt Vector3f/ZERO Vector3f/UNIT_Y))
   1.105 @@ -282,7 +284,7 @@
   1.106                    (comp (view-image) BufferedImage!))
   1.107           ;; This is here to restore the main view
   1.108           ;; after the other views have completed processing
   1.109 -         (add-eye! world (.getCamera world) no-op)))
   1.110 +         (add-camera! world (.getCamera world) no-op)))
   1.111       (fn [world tpf]
   1.112         (.rotate candy (* tpf 0.2) 0 0)))))
   1.113  #+end_src