diff org/touch.org @ 253:e23717fefc7f

added video and source listing to touch
author Robert McIntyre <rlm@mit.edu>
date Mon, 13 Feb 2012 22:52:00 -0700
parents f1a74d23e7e4
children 91654978c8e0
line wrap: on
line diff
     1.1 --- a/org/touch.org	Mon Feb 13 20:19:34 2012 -0700
     1.2 +++ b/org/touch.org	Mon Feb 13 22:52:00 2012 -0700
     1.3 @@ -497,6 +497,7 @@
     1.4  I'll use a new creature --- a simple cube which has touch sensors
     1.5  evenly distributed along each of its sides.
     1.6  
     1.7 +#+name: test-touch-0
     1.8  #+begin_src clojure
     1.9  (in-ns 'cortex.test.touch)
    1.10  
    1.11 @@ -504,10 +505,7 @@
    1.12    (load-blender-model "Models/test-touch/touch-cube.blend"))
    1.13  #+end_src
    1.14  
    1.15 -#+begin_html
    1.16 -<br>
    1.17 -#+end_html
    1.18 -
    1.19 +** The Touch Cube
    1.20  #+begin_html
    1.21  <div class="figure">
    1.22  <center>
    1.23 @@ -527,12 +525,10 @@
    1.24  #+caption: The distribution of feelers along the touch-cube. The colors of the faces are irrelevant; only the white pixels specify feelers.
    1.25  [[../images/touch-profile.png]]
    1.26  
    1.27 +#+name: test-touch-1
    1.28  #+begin_src clojure
    1.29  (in-ns 'cortex.test.touch)
    1.30  
    1.31 -(import com.aurellem.capture.Capture)
    1.32 -(import java.io.File)
    1.33 -
    1.34  (defn test-basic-touch
    1.35    ([] (test-basic-touch false))
    1.36    ([record?]
    1.37 @@ -576,6 +572,7 @@
    1.38  #+end_html
    1.39  
    1.40  ** Generating the Basic Touch Video
    1.41 +#+name: magick4
    1.42  #+begin_src clojure
    1.43  (ns cortex.video.magick4
    1.44    (:import java.io.File)
    1.45 @@ -622,42 +619,82 @@
    1.46  
    1.47  * Adding Touch to the Worm
    1.48  
    1.49 -#+name: test-touch
    1.50 +#+name: test-touch-2
    1.51  #+begin_src clojure
    1.52 -(ns cortex.test.touch
    1.53 -  (:use (cortex world util sense body touch))
    1.54 -  (:use cortex.test.body))
    1.55 -
    1.56 -(cortex.import/mega-import-jme3)
    1.57 +(in-ns 'cortex.test.touch)
    1.58  
    1.59  (defn test-touch 
    1.60    ([] (test-touch false))
    1.61 -([record?]
    1.62 -  (let [the-worm (doto (worm) (body!))
    1.63 -        touch (touch! the-worm)
    1.64 -        touch-display (view-touch)]
    1.65 -    (world (nodify [the-worm (floor)])
    1.66 -           standard-debug-controls
    1.67 -           
    1.68 -           (fn [world]
    1.69 -             (if record? 
    1.70 -               (Capture/captureVideo 
    1.71 -                 world
    1.72 -                 (File. "/home/r/proj/cortex/render/worm-touch/main-view/")))
    1.73 -             (speed-up world)
    1.74 -             (light-up-everything world))
    1.75 +  ([record?]
    1.76 +     (let [the-worm (doto (worm) (body!))
    1.77 +           touch (touch! the-worm)
    1.78 +           touch-display (view-touch)]
    1.79 +       (world
    1.80 +        (nodify [the-worm (floor)])
    1.81 +        standard-debug-controls
    1.82 +        
    1.83 +        (fn [world]
    1.84 +          (if record? 
    1.85 +            (Capture/captureVideo 
    1.86 +             world
    1.87 +             (File. "/home/r/proj/cortex/render/worm-touch/main-view/")))
    1.88 +          (speed-up world)
    1.89 +          (light-up-everything world))
    1.90  
    1.91 -           (fn [world tpf]
    1.92 -             (touch-display 
    1.93 -              (map #(% (.getRootNode world)) touch)
    1.94 -(if record? 
    1.95 -(File. "/home/r/proj/cortex/render/worm-touch/touch/"))
    1.96 -
    1.97 -)))))
    1.98 +        (fn [world tpf]
    1.99 +          (touch-display 
   1.100 +           (map #(% (.getRootNode world)) touch)
   1.101 +           (if record? 
   1.102 +             (File. "/home/r/proj/cortex/render/worm-touch/touch/"))))))))
   1.103  #+end_src
   1.104  
   1.105 +** Worm Touch Demonstration 
   1.106 +#+begin_html
   1.107 +<div class="figure">
   1.108 +<center>
   1.109 +<video controls="controls" width="550">
   1.110 +  <source src="../video/worm-touch.ogg" type="video/ogg"
   1.111 +	  preload="none" poster="../images/aurellem-1280x480.png" />
   1.112 +</video>
   1.113 +</center>
   1.114 +<p>The worm responds to touch.</p>
   1.115 +</div>
   1.116 +#+end_html
   1.117  
   1.118  
   1.119 +** Generating the Worm Touch Video
   1.120 +#+name: magick5
   1.121 +#+begin_src clojure
   1.122 +(ns cortex.video.magick5
   1.123 +  (:import java.io.File)
   1.124 +  (:use clojure.contrib.shell-out))
   1.125 +
   1.126 +(defn images [path]
   1.127 +  (sort (rest (file-seq (File. path)))))
   1.128 +
   1.129 +(def base "/home/r/proj/cortex/render/worm-touch/")
   1.130 +
   1.131 +(defn pics [file]
   1.132 +  (images (str base file)))
   1.133 +
   1.134 +(defn combine-images []
   1.135 +  (let [main-view (pics "main-view")
   1.136 +        touch (pics "touch/0")
   1.137 +        targets (map
   1.138 +                 #(File. (str base "out/" (format "%07d.png" %)))
   1.139 +                 (range 0 (count main-view)))]
   1.140 +    (dorun
   1.141 +     (pmap
   1.142 +      (comp
   1.143 +       (fn [[ main-view touch target]]
   1.144 +         (println target)
   1.145 +         (sh "convert"
   1.146 +             main-view 
   1.147 +             touch     "-geometry" "+0+0" "-composite"
   1.148 +             target))
   1.149 +       (fn [& args] (map #(.getCanonicalPath %) args)))
   1.150 +       main-view touch targets))))
   1.151 +#+end_src
   1.152  
   1.153  * Headers 
   1.154  
   1.155 @@ -678,7 +715,25 @@
   1.156    (:import (com.jme3.math Triangle Vector3f Vector2f Ray Matrix4f)))
   1.157  #+end_src   
   1.158  
   1.159 +#+name: test-touch-header
   1.160 +#+begin_src clojure
   1.161 +(ns cortex.test.touch
   1.162 +  (:use (cortex world util sense body touch))
   1.163 +  (:use cortex.test.body)
   1.164 +  (:import com.aurellem.capture.Capture)
   1.165 +  (:import java.io.File)
   1.166 +  (:import (com.jme3.math Vector3f ColorRGBA)))
   1.167 +#+end_src
   1.168 +
   1.169  * Source Listing
   1.170 +  - [[../src/cortex/touch.clj][cortex.touch]]
   1.171 +  - [[../src/cortex/test/touch.clj][cortex.test.touch]]
   1.172 +  - [[../src/cortex/video/magick4.clj][cortex.video.magick4]]
   1.173 +  - [[../src/cortex/video/magick5.clj][cortex.video.magick5]]
   1.174 +#+html: <ul> <li> <a href="../org/touch.org">This org file</a> </li> </ul>
   1.175 +  - [[http://hg.bortreb.com ][source-repository]]
   1.176 +
   1.177 +
   1.178  * Next
   1.179  
   1.180  
   1.181 @@ -695,11 +750,22 @@
   1.182  <<visualization>>
   1.183  #+end_src
   1.184  
   1.185 +#+begin_src clojure :tangle ../src/cortex/test/touch.clj 
   1.186 +<<test-touch-header>>
   1.187 +<<test-touch-0>>
   1.188 +<<test-touch-1>>
   1.189 +<<test-touch-2>>
   1.190 +#+end_src
   1.191  
   1.192 -#+begin_src clojure :tangle ../src/cortex/test/touch.clj 
   1.193 -<<test-touch>>
   1.194 +#+begin_src clojure :tangle ../src/cortex/video/magick4.clj
   1.195 +<<magick4>>
   1.196  #+end_src
   1.197  
   1.198 +#+begin_src clojure :tangle ../src/cortex/video/magick5.clj
   1.199 +<<magick5>>
   1.200 +#+end_src
   1.201 +
   1.202 +
   1.203  
   1.204  
   1.205