diff org/touch.org @ 266:bee5145ce463

Merged Robert's proprioception with Dylan's vision.
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 13 Feb 2012 21:53:54 -0600
parents e6e0bb3057b2
children c39b8b29a79e
line wrap: on
line diff
     1.1 --- a/org/touch.org	Mon Feb 13 21:53:28 2012 -0600
     1.2 +++ b/org/touch.org	Mon Feb 13 21:53:54 2012 -0600
     1.3 @@ -122,7 +122,7 @@
     1.4  #+end_src
     1.5  
     1.6  It is convienent to treat a =Triangle= as a vector of vectors, and a
     1.7 -=Vector2f= and =Vector3f= as vectors of floats. (->vector3f) and
     1.8 +=Vector2f= or =Vector3f= as vectors of floats. (->vector3f) and
     1.9  (->triangle) undo the operations of =(vector3f-seq)= and
    1.10  =(triangle-seq)=. If these classes implemented =Iterable= then =(seq)=
    1.11  would work on them automitacally.
    1.12 @@ -497,6 +497,7 @@
    1.13  I'll use a new creature --- a simple cube which has touch sensors
    1.14  evenly distributed along each of its sides.
    1.15  
    1.16 +#+name: test-touch-0
    1.17  #+begin_src clojure
    1.18  (in-ns 'cortex.test.touch)
    1.19  
    1.20 @@ -504,10 +505,7 @@
    1.21    (load-blender-model "Models/test-touch/touch-cube.blend"))
    1.22  #+end_src
    1.23  
    1.24 -#+begin_html
    1.25 -<br>
    1.26 -#+end_html
    1.27 -
    1.28 +** The Touch Cube
    1.29  #+begin_html
    1.30  <div class="figure">
    1.31  <center>
    1.32 @@ -527,12 +525,10 @@
    1.33  #+caption: The distribution of feelers along the touch-cube. The colors of the faces are irrelevant; only the white pixels specify feelers.
    1.34  [[../images/touch-profile.png]]
    1.35  
    1.36 +#+name: test-touch-1
    1.37  #+begin_src clojure
    1.38  (in-ns 'cortex.test.touch)
    1.39  
    1.40 -(import com.aurellem.capture.Capture)
    1.41 -(import java.io.File)
    1.42 -
    1.43  (defn test-basic-touch
    1.44    ([] (test-basic-touch false))
    1.45    ([record?]
    1.46 @@ -576,6 +572,7 @@
    1.47  #+end_html
    1.48  
    1.49  ** Generating the Basic Touch Video
    1.50 +#+name: magick4
    1.51  #+begin_src clojure
    1.52  (ns cortex.video.magick4
    1.53    (:import java.io.File)
    1.54 @@ -615,31 +612,88 @@
    1.55        background main-view touch targets))))
    1.56  #+end_src
    1.57  
    1.58 +#+begin_src sh :results silent
    1.59 +cd /home/r/proj/cortex/render/touch-cube/
    1.60 +ffmpeg -r 60 -i out/%07d.png -b:v 9000k -c:v libtheora basic-touch.ogg
    1.61 +#+end_src
    1.62  
    1.63  * Adding Touch to the Worm
    1.64  
    1.65 -#+name: test-touch
    1.66 +#+name: test-touch-2
    1.67  #+begin_src clojure
    1.68 -(ns cortex.test.touch
    1.69 -  (:use (cortex world util sense body touch))
    1.70 -  (:use cortex.test.body))
    1.71 +(in-ns 'cortex.test.touch)
    1.72  
    1.73 -(cortex.import/mega-import-jme3)
    1.74 +(defn test-touch 
    1.75 +  ([] (test-touch false))
    1.76 +  ([record?]
    1.77 +     (let [the-worm (doto (worm) (body!))
    1.78 +           touch (touch! the-worm)
    1.79 +           touch-display (view-touch)]
    1.80 +       (world
    1.81 +        (nodify [the-worm (floor)])
    1.82 +        standard-debug-controls
    1.83 +        
    1.84 +        (fn [world]
    1.85 +          (if record? 
    1.86 +            (Capture/captureVideo 
    1.87 +             world
    1.88 +             (File. "/home/r/proj/cortex/render/worm-touch/main-view/")))
    1.89 +          (speed-up world)
    1.90 +          (light-up-everything world))
    1.91  
    1.92 -(defn test-touch []
    1.93 -  (let [the-worm (doto (worm) (body!))
    1.94 -        touch (touch! the-worm)
    1.95 -        touch-display (view-touch)]
    1.96 -    (world (nodify [the-worm (floor)])
    1.97 -           standard-debug-controls
    1.98 -           
    1.99 -           (fn [world]
   1.100 -             (speed-up world)
   1.101 -             (light-up-everything world))
   1.102 +        (fn [world tpf]
   1.103 +          (touch-display 
   1.104 +           (map #(% (.getRootNode world)) touch)
   1.105 +           (if record? 
   1.106 +             (File. "/home/r/proj/cortex/render/worm-touch/touch/"))))))))
   1.107 +#+end_src
   1.108  
   1.109 -           (fn [world tpf]
   1.110 -             (touch-display 
   1.111 -              (map #(% (.getRootNode world)) touch))))))
   1.112 +** Worm Touch Demonstration 
   1.113 +#+begin_html
   1.114 +<div class="figure">
   1.115 +<center>
   1.116 +<video controls="controls" width="550">
   1.117 +  <source src="../video/worm-touch.ogg" type="video/ogg"
   1.118 +	  preload="none" poster="../images/aurellem-1280x480.png" />
   1.119 +</video>
   1.120 +</center>
   1.121 +<p>The worm responds to touch.</p>
   1.122 +</div>
   1.123 +#+end_html
   1.124 +
   1.125 +
   1.126 +** Generating the Worm Touch Video
   1.127 +#+name: magick5
   1.128 +#+begin_src clojure
   1.129 +(ns cortex.video.magick5
   1.130 +  (:import java.io.File)
   1.131 +  (:use clojure.contrib.shell-out))
   1.132 +
   1.133 +(defn images [path]
   1.134 +  (sort (rest (file-seq (File. path)))))
   1.135 +
   1.136 +(def base "/home/r/proj/cortex/render/worm-touch/")
   1.137 +
   1.138 +(defn pics [file]
   1.139 +  (images (str base file)))
   1.140 +
   1.141 +(defn combine-images []
   1.142 +  (let [main-view (pics "main-view")
   1.143 +        touch (pics "touch/0")
   1.144 +        targets (map
   1.145 +                 #(File. (str base "out/" (format "%07d.png" %)))
   1.146 +                 (range 0 (count main-view)))]
   1.147 +    (dorun
   1.148 +     (pmap
   1.149 +      (comp
   1.150 +       (fn [[ main-view touch target]]
   1.151 +         (println target)
   1.152 +         (sh "convert"
   1.153 +             main-view 
   1.154 +             touch     "-geometry" "+0+0" "-composite"
   1.155 +             target))
   1.156 +       (fn [& args] (map #(.getCanonicalPath %) args)))
   1.157 +       main-view touch targets))))
   1.158  #+end_src
   1.159  
   1.160  * Headers 
   1.161 @@ -661,9 +715,44 @@
   1.162    (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
   1.163  #+end_src   
   1.164  
   1.165 +#+name: test-touch-header
   1.166 +#+begin_src clojure
   1.167 +(ns cortex.test.touch
   1.168 +  (:use (cortex world util sense body touch))
   1.169 +  (:use cortex.test.body)
   1.170 +  (:import com.aurellem.capture.Capture)
   1.171 +  (:import java.io.File)
   1.172 +  (:import (com.jme3.math Vector3f ColorRGBA)))
   1.173 +#+end_src
   1.174 +
   1.175  * Source Listing
   1.176 +  - [[../src/cortex/touch.clj][cortex.touch]]
   1.177 +  - [[../src/cortex/test/touch.clj][cortex.test.touch]]
   1.178 +  - [[../src/cortex/video/magick4.clj][cortex.video.magick4]]
   1.179 +  - [[../src/cortex/video/magick5.clj][cortex.video.magick5]]
   1.180 +#+html: <ul> <li> <a href="../org/touch.org">This org file</a> </li> </ul>
   1.181 +  - [[http://hg.bortreb.com ][source-repository]]
   1.182 +
   1.183  * Next
   1.184 +So far I've implemented simulated Vision, Hearing, and Touch, the most
   1.185 +obvious and promiment senses that humans have.  Smell and Taste shall
   1.186 +remain unimplemented for now. This accounts for the "five senses" that
   1.187 +feature so prominently in our lives. But humans have far more than the
   1.188 +five main senses. There are internal chemical senses, pain (which is
   1.189 +*not* the same as touch), heat sensitivity, and our sense of balance,
   1.190 +among others. One extra sense is so important that I must implement it
   1.191 +to have a hope of making creatures that can gracefully control their
   1.192 +own bodies.  It is Proprioception, which is the sense of the location
   1.193 +of each body part in relation to the other body parts.
   1.194  
   1.195 +Close your eyes, and touch your nose with your right index finger. How
   1.196 +did you do it? You could not see your hand, and neither your hand nor
   1.197 +your nose could use the sense of touch to guide the path of your hand.
   1.198 +There are no sound cues, and Taste and Smell certainly don't provide
   1.199 +any help. You know where your hand is without your other senses
   1.200 +because of Proprioception.
   1.201 +
   1.202 +Onward to [[./proprioception.org][proprioception]]!
   1.203  
   1.204  * COMMENT Code Generation
   1.205  #+begin_src clojure :tangle ../src/cortex/touch.clj
   1.206 @@ -678,11 +767,22 @@
   1.207  <<visualization>>
   1.208  #+end_src
   1.209  
   1.210 +#+begin_src clojure :tangle ../src/cortex/test/touch.clj 
   1.211 +<<test-touch-header>>
   1.212 +<<test-touch-0>>
   1.213 +<<test-touch-1>>
   1.214 +<<test-touch-2>>
   1.215 +#+end_src
   1.216  
   1.217 -#+begin_src clojure :tangle ../src/cortex/test/touch.clj 
   1.218 -<<test-touch>>
   1.219 +#+begin_src clojure :tangle ../src/cortex/video/magick4.clj
   1.220 +<<magick4>>
   1.221  #+end_src
   1.222  
   1.223 +#+begin_src clojure :tangle ../src/cortex/video/magick5.clj
   1.224 +<<magick5>>
   1.225 +#+end_src
   1.226 +
   1.227 +
   1.228  
   1.229  
   1.230