comparison org/touch.org @ 245:102ac596cc3f

minor formatting changes
author Robert McIntyre <rlm@mit.edu>
date Sun, 12 Feb 2012 14:33:52 -0700
parents f23217324f72
children 63da037ce1c5
comparison
equal deleted inserted replaced
244:f23217324f72 245:102ac596cc3f
40 should be on the 3D surface of the body. 40 should be on the 3D surface of the body.
41 41
42 42
43 * Defining Touch Meta-Data in Blender 43 * Defining Touch Meta-Data in Blender
44 44
45 Each geometry can have a single UV map which describes the position 45 Each geometry can have a single UV map which describes the position of
46 and length of the "hairs" which will constitute its sense of 46 the "hairs" which will constitute its sense of touch. This image path
47 touch. This image path is stored under the "touch" key. The image 47 is stored under the "touch" key. The image itself is black and white,
48 itself is grayscale, with black meaning a hair length of 0 (no hair is 48 with black meaning a hair length of 0 (no hair is present) and white
49 present) and white meaning a hair length of =scale=, which is a float 49 meaning a hair length of =scale=, which is a float stored under the
50 stored under the key "scale". If the pixel is gray then the resultant 50 key "scale". I call these "hairs" /feelers/.
51 hair length is linearly interpolated between 0 and =scale=. I call
52 these "hairs" /feelers/.
53 51
54 #+name: meta-data 52 #+name: meta-data
55 #+begin_src clojure 53 #+begin_src clojure
56 (defn tactile-sensor-profile 54 (defn tactile-sensor-profile
57 "Return the touch-sensor distribution image in BufferedImage format, 55 "Return the touch-sensor distribution image in BufferedImage format,
73 ** TODO add image showing example touch-uv map 71 ** TODO add image showing example touch-uv map
74 ** TODO add metadata display for worm 72 ** TODO add metadata display for worm
75 73
76 74
77 * Skin Creation 75 * Skin Creation
78 * TODO get the actual lengths for each feeler
79
80 76
81 =(touch-kernel)= generates the functions which implement the sense of 77 =(touch-kernel)= generates the functions which implement the sense of
82 touch for a creature. These functions must do 6 things to obtain touch 78 touch for a creature. These functions must do 6 things to obtain touch
83 data. 79 data.
84 80
85 - Get the tactile profile image and scale paramaters which describe 81 - Get the tactile profile image and scale paramaters which describe
86 the layout of feelers along the object's surface. 82 the layout of feelers along the object's surface.
87 =(tactile-sensor-profile)=, =(tactile-scale)= 83 =(tactile-sensor-profile)=, =(tactile-scale)=
88
89 - Get the lengths of each feeler by analyzing the color of the
90 pixels in the tactile profile image.
91 NOT IMPLEMENTED YET
92 84
93 - Find the triangles which make up the mesh in pixel-space and in 85 - Find the triangles which make up the mesh in pixel-space and in
94 world-space. 86 world-space.
95 =(triangles)= =(pixel-triangles)= 87 =(triangles)= =(pixel-triangles)=
96 88
111 103
112 104
113 #+name: kernel 105 #+name: kernel
114 #+begin_src clojure 106 #+begin_src clojure
115 (in-ns 'cortex.touch) 107 (in-ns 'cortex.touch)
116
117 (declare touch-topology feelers set-ray)
118 108
119 (defn set-ray [#^Ray ray #^Matrix4f transform 109 (defn set-ray [#^Ray ray #^Matrix4f transform
120 #^Vector3f origin #^Vector3f tip] 110 #^Vector3f origin #^Vector3f tip]
121 ;; Doing everything locally recduces garbage collection by enough to 111 ;; Doing everything locally recduces garbage collection by enough to
122 ;; be worth it. 112 ;; be worth it.
169 (map touch-kernel 159 (map touch-kernel
170 (filter #(isa? (class %) Geometry) 160 (filter #(isa? (class %) Geometry)
171 (node-seq creature))))) 161 (node-seq creature)))))
172 #+end_src 162 #+end_src
173 163
174 #+results: kernel
175 : #'cortex.touch/touch!
176
177 * Sensor Related Functions 164 * Sensor Related Functions
178 165
179 These functions analyze the touch-sensor-profile image convert the 166 These functions analyze the touch-sensor-profile image convert the
180 location of each touch sensor from pixel coordinates to UV-coordinates 167 location of each touch sensor from pixel coordinates to UV-coordinates
181 and XYZ-coordinates. 168 and XYZ-coordinates.
221 (map ->triangle (triangles geo)))] 208 (map ->triangle (triangles geo)))]
222 209
223 (mapcat (fn [origins normal] 210 (mapcat (fn [origins normal]
224 (map #(.add % normal) origins)) 211 (map #(.add % normal) origins))
225 world-coords normals))) 212 world-coords normals)))
226
227 213
228 (defn touch-topology [#^Geometry geo image] 214 (defn touch-topology [#^Geometry geo image]
229 (collapse (reduce concat (feeler-pixel-coords geo image)))) 215 (collapse (reduce concat (feeler-pixel-coords geo image))))
230 #+end_src 216 #+end_src
231 217
233 #+name: visualization 219 #+name: visualization
234 #+begin_src clojure 220 #+begin_src clojure
235 (in-ns 'cortex.touch) 221 (in-ns 'cortex.touch)
236 222
237 (defn touch->gray 223 (defn touch->gray
238 "Convert a pair of [distance, max-distance] into a grayscale pixel" 224 "Convert a pair of [distance, max-distance] into a grayscale pixel."
239 [distance max-distance] 225 [distance max-distance]
240 (gray 226 (gray (- 255 (rem (int (* 255 (/ distance max-distance))) 256))))
241 (- 255
242 (rem
243 (int
244 (* 255 (/ distance max-distance)))
245 256))))
246 227
247 (defn view-touch 228 (defn view-touch
248 "Creates a function which accepts a list of touch sensor-data and 229 "Creates a function which accepts a list of touch sensor-data and
249 displays each element to the screen." 230 displays each element to the screen."
250 [] 231 []
251 (view-sense 232 (view-sense
252 (fn 233 (fn
253 [[coords sensor-data]] 234 [[coords sensor-data]]
293 274
294 (defn ->triangle [points] 275 (defn ->triangle [points]
295 (apply #(Triangle. %1 %2 %3) (map ->vector3f points))) 276 (apply #(Triangle. %1 %2 %3) (map ->vector3f points)))
296 277
297 (defn triangle 278 (defn triangle
298 "Get the triangle specified by triangle-index from the mesh within 279 "Get the triangle specified by triangle-index from the mesh."
299 bounds."
300 [#^Geometry geo triangle-index] 280 [#^Geometry geo triangle-index]
301 (triangle-seq 281 (triangle-seq
302 (let [scratch (Triangle.)] 282 (let [scratch (Triangle.)]
303 (.getTriangle (.getMesh geo) triangle-index scratch) scratch))) 283 (.getTriangle (.getMesh geo) triangle-index scratch) scratch)))
304 284
368 vertices [vert-1 vert-2 vert-3 unit-normal]] 348 vertices [vert-1 vert-2 vert-3 unit-normal]]
369 (dorun 349 (dorun
370 (for [row (range 4) col (range 3)] 350 (for [row (range 4) col (range 3)]
371 (do 351 (do
372 (.set mat col row (.get (vertices row)col)) 352 (.set mat col row (.get (vertices row)col))
373 (.set mat 3 row 1)))) 353 (.set mat 3 row 1)))) mat))
374 mat))
375 354
376 (defn triangles->affine-transform 355 (defn triangles->affine-transform
377 "Returns the affine transformation that converts each vertex in the 356 "Returns the affine transformation that converts each vertex in the
378 first triangle into the corresponding vertex in the second 357 first triangle into the corresponding vertex in the second
379 triangle." 358 triangle."