Mercurial > cortex
diff 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 |
line wrap: on
line diff
1.1 --- a/org/touch.org Sun Feb 12 10:45:38 2012 -0700 1.2 +++ b/org/touch.org Sun Feb 12 12:10:51 2012 -0700 1.3 @@ -50,7 +50,8 @@ 1.4 itself is grayscale, with black meaning a hair length of 0 (no hair is 1.5 present) and white meaning a hair length of =scale=, which is a float 1.6 stored under the key "scale". If the pixel is gray then the resultant 1.7 -hair length is linearly interpolated between 0 and =scale=. 1.8 +hair length is linearly interpolated between 0 and =scale=. I call 1.9 +these "hairs" /feelers/. 1.10 1.11 #+name: meta-data 1.12 #+begin_src clojure 1.13 @@ -86,6 +87,24 @@ 1.14 1.15 #+end_src 1.16 1.17 + 1.18 +=(touch-kernel)= generates the functions which implement the sense of 1.19 +touch for a creature. These functions must do 6 things to obtain touch 1.20 +data. 1.21 + 1.22 + - Get the tactile profile image and scale paramaters which describe 1.23 + the layout of feelers along the object's surface. 1.24 + - Get the lengths of each feeler by analyzing the color of the 1.25 + pixels in the tactile profile image. 1.26 + - Find the triangles which make up the mesh in pixel-space and in 1.27 + world-space. 1.28 + - Find the coordinates of each pixel in world-space. These 1.29 + coordinates are the origins of the feelers. 1.30 + - Calculate the normals of the triangles in world space, and add 1.31 + them to each of the origins of the feelers. These are the 1.32 + normalized coordinates of the tips of the feelers. 1.33 + - Generate some sort of topology for the sensors. 1.34 + 1.35 #+name: kernel 1.36 #+begin_src clojure 1.37 (in-ns 'cortex.touch) 1.38 @@ -173,6 +192,64 @@ 1.39 (node-seq creature))))) 1.40 #+end_src 1.41 1.42 +* Sensor Related Functions 1.43 + 1.44 +These functions analyze the touch-sensor-profile image convert the 1.45 +location of each touch sensor from pixel coordinates to UV-coordinates 1.46 +and XYZ-coordinates. 1.47 + 1.48 +#+name: sensors 1.49 +#+begin_src clojure 1.50 +(defn sensors-in-triangle 1.51 + "Locate the touch sensors in the triangle, returning a map of their 1.52 + UV and geometry-relative coordinates." 1.53 + [image mesh tri-index] 1.54 + (let [width (.getWidth image) 1.55 + height (.getHeight image) 1.56 + UV-vertex-coords (triangle-UV-coord mesh width height tri-index) 1.57 + bounds (convex-bounds UV-vertex-coords) 1.58 + 1.59 + cutout-triangle (points->triangle UV-vertex-coords) 1.60 + UV-sensor-coords 1.61 + (filter (comp (partial inside-triangle? cutout-triangle) 1.62 + (fn [[u v]] (Vector3f. u v 0))) 1.63 + (white-coordinates image bounds)) 1.64 + UV->geometry (triangle-transformation 1.65 + cutout-triangle 1.66 + (mesh-triangle mesh tri-index)) 1.67 + geometry-sensor-coords 1.68 + (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) 1.69 + UV-sensor-coords)] 1.70 + {:UV UV-sensor-coords :geometry geometry-sensor-coords})) 1.71 + 1.72 +(defn-memo locate-feelers 1.73 + "Search the geometry's tactile UV profile for touch sensors, 1.74 + returning their positions in geometry-relative coordinates." 1.75 + [#^Geometry geo] 1.76 + (let [mesh (.getMesh geo) 1.77 + num-triangles (.getTriangleCount mesh)] 1.78 + (if-let [image (tactile-sensor-profile geo)] 1.79 + (map 1.80 + (partial sensors-in-triangle image mesh) 1.81 + (range num-triangles)) 1.82 + (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) 1.83 + 1.84 +(defn-memo touch-topology 1.85 + "Return a sequence of vectors of the form [x y] describing the 1.86 + \"topology\" of the tactile sensors. Points that are close together 1.87 + in the touch-topology are generally close together in the simulation." 1.88 + [#^Gemoetry geo] 1.89 + (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) 1.90 + 1.91 +(defn-memo feeler-coordinates 1.92 + "The location of the touch sensors in world-space coordinates." 1.93 + [#^Geometry geo] 1.94 + (vec (map :geometry (locate-feelers geo)))) 1.95 +#+end_src 1.96 + 1.97 + 1.98 + 1.99 + 1.100 * Visualizing Touch 1.101 #+name: visualization 1.102 #+begin_src clojure 1.103 @@ -393,61 +470,6 @@ 1.104 #+end_src 1.105 1.106 1.107 -* Sensor Related Functions 1.108 - 1.109 -These functions analyze the touch-sensor-profile image convert the 1.110 -location of each touch sensor from pixel coordinates to UV-coordinates 1.111 -and XYZ-coordinates. 1.112 - 1.113 -#+name: sensors 1.114 -#+begin_src clojure 1.115 -(defn sensors-in-triangle 1.116 - "Locate the touch sensors in the triangle, returning a map of their 1.117 - UV and geometry-relative coordinates." 1.118 - [image mesh tri-index] 1.119 - (let [width (.getWidth image) 1.120 - height (.getHeight image) 1.121 - UV-vertex-coords (triangle-UV-coord mesh width height tri-index) 1.122 - bounds (convex-bounds UV-vertex-coords) 1.123 - 1.124 - cutout-triangle (points->triangle UV-vertex-coords) 1.125 - UV-sensor-coords 1.126 - (filter (comp (partial inside-triangle? cutout-triangle) 1.127 - (fn [[u v]] (Vector3f. u v 0))) 1.128 - (white-coordinates image bounds)) 1.129 - UV->geometry (triangle-transformation 1.130 - cutout-triangle 1.131 - (mesh-triangle mesh tri-index)) 1.132 - geometry-sensor-coords 1.133 - (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) 1.134 - UV-sensor-coords)] 1.135 - {:UV UV-sensor-coords :geometry geometry-sensor-coords})) 1.136 - 1.137 -(defn-memo locate-feelers 1.138 - "Search the geometry's tactile UV profile for touch sensors, 1.139 - returning their positions in geometry-relative coordinates." 1.140 - [#^Geometry geo] 1.141 - (let [mesh (.getMesh geo) 1.142 - num-triangles (.getTriangleCount mesh)] 1.143 - (if-let [image (tactile-sensor-profile geo)] 1.144 - (map 1.145 - (partial sensors-in-triangle image mesh) 1.146 - (range num-triangles)) 1.147 - (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) 1.148 - 1.149 -(defn-memo touch-topology 1.150 - "Return a sequence of vectors of the form [x y] describing the 1.151 - \"topology\" of the tactile sensors. Points that are close together 1.152 - in the touch-topology are generally close together in the simulation." 1.153 - [#^Gemoetry geo] 1.154 - (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) 1.155 - 1.156 -(defn-memo feeler-coordinates 1.157 - "The location of the touch sensors in world-space coordinates." 1.158 - [#^Geometry geo] 1.159 - (vec (map :geometry (locate-feelers geo)))) 1.160 -#+end_src 1.161 - 1.162 * Physics Collision Objects 1.163 1.164 The "hairs" are actually =Rays= which extend from a point on a