Mercurial > cortex
comparison org/touch.org @ 238:3fa49ff1649a
going to recode touch.org to make it look better
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 12 Feb 2012 12:10:51 -0700 |
parents | 712bd7e5b148 |
children | 78a640e3bc55 |
comparison
equal
deleted
inserted
replaced
237:02b2e6f3fb43 | 238:3fa49ff1649a |
---|---|
48 and length of the "hairs" which will constitute its sense of | 48 and length of the "hairs" which will constitute its sense of |
49 touch. This image path is stored under the "touch" key. The image | 49 touch. This image path is stored under the "touch" key. The image |
50 itself is grayscale, with black meaning a hair length of 0 (no hair is | 50 itself is grayscale, with black meaning a hair length of 0 (no hair is |
51 present) and white meaning a hair length of =scale=, which is a float | 51 present) and white meaning a hair length of =scale=, which is a float |
52 stored under the key "scale". If the pixel is gray then the resultant | 52 stored under the key "scale". If the pixel is gray then the resultant |
53 hair length is linearly interpolated between 0 and =scale=. | 53 hair length is linearly interpolated between 0 and =scale=. I call |
54 these "hairs" /feelers/. | |
54 | 55 |
55 #+name: meta-data | 56 #+name: meta-data |
56 #+begin_src clojure | 57 #+begin_src clojure |
57 (defn tactile-sensor-profile | 58 (defn tactile-sensor-profile |
58 "Return the touch-sensor distribution image in BufferedImage format, | 59 "Return the touch-sensor distribution image in BufferedImage format, |
83 xyz-triangles | 84 xyz-triangles |
84 conversions (map triangles->affine-transform pixel-triangles | 85 conversions (map triangles->affine-transform pixel-triangles |
85 xyz-triangles) | 86 xyz-triangles) |
86 | 87 |
87 #+end_src | 88 #+end_src |
89 | |
90 | |
91 =(touch-kernel)= generates the functions which implement the sense of | |
92 touch for a creature. These functions must do 6 things to obtain touch | |
93 data. | |
94 | |
95 - Get the tactile profile image and scale paramaters which describe | |
96 the layout of feelers along the object's surface. | |
97 - Get the lengths of each feeler by analyzing the color of the | |
98 pixels in the tactile profile image. | |
99 - Find the triangles which make up the mesh in pixel-space and in | |
100 world-space. | |
101 - Find the coordinates of each pixel in world-space. These | |
102 coordinates are the origins of the feelers. | |
103 - Calculate the normals of the triangles in world space, and add | |
104 them to each of the origins of the feelers. These are the | |
105 normalized coordinates of the tips of the feelers. | |
106 - Generate some sort of topology for the sensors. | |
88 | 107 |
89 #+name: kernel | 108 #+name: kernel |
90 #+begin_src clojure | 109 #+begin_src clojure |
91 (in-ns 'cortex.touch) | 110 (in-ns 'cortex.touch) |
92 | 111 |
171 (map touch-kernel | 190 (map touch-kernel |
172 (filter #(isa? (class %) Geometry) | 191 (filter #(isa? (class %) Geometry) |
173 (node-seq creature))))) | 192 (node-seq creature))))) |
174 #+end_src | 193 #+end_src |
175 | 194 |
195 * Sensor Related Functions | |
196 | |
197 These functions analyze the touch-sensor-profile image convert the | |
198 location of each touch sensor from pixel coordinates to UV-coordinates | |
199 and XYZ-coordinates. | |
200 | |
201 #+name: sensors | |
202 #+begin_src clojure | |
203 (defn sensors-in-triangle | |
204 "Locate the touch sensors in the triangle, returning a map of their | |
205 UV and geometry-relative coordinates." | |
206 [image mesh tri-index] | |
207 (let [width (.getWidth image) | |
208 height (.getHeight image) | |
209 UV-vertex-coords (triangle-UV-coord mesh width height tri-index) | |
210 bounds (convex-bounds UV-vertex-coords) | |
211 | |
212 cutout-triangle (points->triangle UV-vertex-coords) | |
213 UV-sensor-coords | |
214 (filter (comp (partial inside-triangle? cutout-triangle) | |
215 (fn [[u v]] (Vector3f. u v 0))) | |
216 (white-coordinates image bounds)) | |
217 UV->geometry (triangle-transformation | |
218 cutout-triangle | |
219 (mesh-triangle mesh tri-index)) | |
220 geometry-sensor-coords | |
221 (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) | |
222 UV-sensor-coords)] | |
223 {:UV UV-sensor-coords :geometry geometry-sensor-coords})) | |
224 | |
225 (defn-memo locate-feelers | |
226 "Search the geometry's tactile UV profile for touch sensors, | |
227 returning their positions in geometry-relative coordinates." | |
228 [#^Geometry geo] | |
229 (let [mesh (.getMesh geo) | |
230 num-triangles (.getTriangleCount mesh)] | |
231 (if-let [image (tactile-sensor-profile geo)] | |
232 (map | |
233 (partial sensors-in-triangle image mesh) | |
234 (range num-triangles)) | |
235 (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) | |
236 | |
237 (defn-memo touch-topology | |
238 "Return a sequence of vectors of the form [x y] describing the | |
239 \"topology\" of the tactile sensors. Points that are close together | |
240 in the touch-topology are generally close together in the simulation." | |
241 [#^Gemoetry geo] | |
242 (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) | |
243 | |
244 (defn-memo feeler-coordinates | |
245 "The location of the touch sensors in world-space coordinates." | |
246 [#^Geometry geo] | |
247 (vec (map :geometry (locate-feelers geo)))) | |
248 #+end_src | |
249 | |
250 | |
251 | |
252 | |
176 * Visualizing Touch | 253 * Visualizing Touch |
177 #+name: visualization | 254 #+name: visualization |
178 #+begin_src clojure | 255 #+begin_src clojure |
179 (in-ns 'cortex.touch) | 256 (in-ns 'cortex.touch) |
180 | 257 |
391 (same-side? vert-2 vert-3 vert-1 p) | 468 (same-side? vert-2 vert-3 vert-1 p) |
392 (same-side? vert-3 vert-1 vert-2 p)))) | 469 (same-side? vert-3 vert-1 vert-2 p)))) |
393 #+end_src | 470 #+end_src |
394 | 471 |
395 | 472 |
396 * Sensor Related Functions | |
397 | |
398 These functions analyze the touch-sensor-profile image convert the | |
399 location of each touch sensor from pixel coordinates to UV-coordinates | |
400 and XYZ-coordinates. | |
401 | |
402 #+name: sensors | |
403 #+begin_src clojure | |
404 (defn sensors-in-triangle | |
405 "Locate the touch sensors in the triangle, returning a map of their | |
406 UV and geometry-relative coordinates." | |
407 [image mesh tri-index] | |
408 (let [width (.getWidth image) | |
409 height (.getHeight image) | |
410 UV-vertex-coords (triangle-UV-coord mesh width height tri-index) | |
411 bounds (convex-bounds UV-vertex-coords) | |
412 | |
413 cutout-triangle (points->triangle UV-vertex-coords) | |
414 UV-sensor-coords | |
415 (filter (comp (partial inside-triangle? cutout-triangle) | |
416 (fn [[u v]] (Vector3f. u v 0))) | |
417 (white-coordinates image bounds)) | |
418 UV->geometry (triangle-transformation | |
419 cutout-triangle | |
420 (mesh-triangle mesh tri-index)) | |
421 geometry-sensor-coords | |
422 (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) | |
423 UV-sensor-coords)] | |
424 {:UV UV-sensor-coords :geometry geometry-sensor-coords})) | |
425 | |
426 (defn-memo locate-feelers | |
427 "Search the geometry's tactile UV profile for touch sensors, | |
428 returning their positions in geometry-relative coordinates." | |
429 [#^Geometry geo] | |
430 (let [mesh (.getMesh geo) | |
431 num-triangles (.getTriangleCount mesh)] | |
432 (if-let [image (tactile-sensor-profile geo)] | |
433 (map | |
434 (partial sensors-in-triangle image mesh) | |
435 (range num-triangles)) | |
436 (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) | |
437 | |
438 (defn-memo touch-topology | |
439 "Return a sequence of vectors of the form [x y] describing the | |
440 \"topology\" of the tactile sensors. Points that are close together | |
441 in the touch-topology are generally close together in the simulation." | |
442 [#^Gemoetry geo] | |
443 (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) | |
444 | |
445 (defn-memo feeler-coordinates | |
446 "The location of the touch sensors in world-space coordinates." | |
447 [#^Geometry geo] | |
448 (vec (map :geometry (locate-feelers geo)))) | |
449 #+end_src | |
450 | |
451 * Physics Collision Objects | 473 * Physics Collision Objects |
452 | 474 |
453 The "hairs" are actually =Rays= which extend from a point on a | 475 The "hairs" are actually =Rays= which extend from a point on a |
454 =Triangle= in the =Mesh= normal to the =Triangle's= surface. | 476 =Triangle= in the =Mesh= normal to the =Triangle's= surface. |
455 | 477 |