Mercurial > cortex
changeset 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 | 02b2e6f3fb43 |
children | 78a640e3bc55 |
files | org/ideas.org org/touch.org |
diffstat | 2 files changed, 79 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/ideas.org Sun Feb 12 10:45:38 2012 -0700 1.2 +++ b/org/ideas.org Sun Feb 12 12:10:51 2012 -0700 1.3 @@ -74,6 +74,7 @@ 1.4 - [ ] send package to friends for critiques -- 2 days 1.5 - [ ] fix videos that were encoded wrong, test on InterNet Explorer. 1.6 - [ ] redo videos vision with new collapse code 1.7 + - [ ] find a topology that looks good. (maybe nil topology?) 1.8 - [ ] write summary of project for Winston \ 1.9 - [ ] project proposals for Winston \ 1.10 - [ ] additional senses to be implemented for Winston | -- 2 days
2.1 --- a/org/touch.org Sun Feb 12 10:45:38 2012 -0700 2.2 +++ b/org/touch.org Sun Feb 12 12:10:51 2012 -0700 2.3 @@ -50,7 +50,8 @@ 2.4 itself is grayscale, with black meaning a hair length of 0 (no hair is 2.5 present) and white meaning a hair length of =scale=, which is a float 2.6 stored under the key "scale". If the pixel is gray then the resultant 2.7 -hair length is linearly interpolated between 0 and =scale=. 2.8 +hair length is linearly interpolated between 0 and =scale=. I call 2.9 +these "hairs" /feelers/. 2.10 2.11 #+name: meta-data 2.12 #+begin_src clojure 2.13 @@ -86,6 +87,24 @@ 2.14 2.15 #+end_src 2.16 2.17 + 2.18 +=(touch-kernel)= generates the functions which implement the sense of 2.19 +touch for a creature. These functions must do 6 things to obtain touch 2.20 +data. 2.21 + 2.22 + - Get the tactile profile image and scale paramaters which describe 2.23 + the layout of feelers along the object's surface. 2.24 + - Get the lengths of each feeler by analyzing the color of the 2.25 + pixels in the tactile profile image. 2.26 + - Find the triangles which make up the mesh in pixel-space and in 2.27 + world-space. 2.28 + - Find the coordinates of each pixel in world-space. These 2.29 + coordinates are the origins of the feelers. 2.30 + - Calculate the normals of the triangles in world space, and add 2.31 + them to each of the origins of the feelers. These are the 2.32 + normalized coordinates of the tips of the feelers. 2.33 + - Generate some sort of topology for the sensors. 2.34 + 2.35 #+name: kernel 2.36 #+begin_src clojure 2.37 (in-ns 'cortex.touch) 2.38 @@ -173,6 +192,64 @@ 2.39 (node-seq creature))))) 2.40 #+end_src 2.41 2.42 +* Sensor Related Functions 2.43 + 2.44 +These functions analyze the touch-sensor-profile image convert the 2.45 +location of each touch sensor from pixel coordinates to UV-coordinates 2.46 +and XYZ-coordinates. 2.47 + 2.48 +#+name: sensors 2.49 +#+begin_src clojure 2.50 +(defn sensors-in-triangle 2.51 + "Locate the touch sensors in the triangle, returning a map of their 2.52 + UV and geometry-relative coordinates." 2.53 + [image mesh tri-index] 2.54 + (let [width (.getWidth image) 2.55 + height (.getHeight image) 2.56 + UV-vertex-coords (triangle-UV-coord mesh width height tri-index) 2.57 + bounds (convex-bounds UV-vertex-coords) 2.58 + 2.59 + cutout-triangle (points->triangle UV-vertex-coords) 2.60 + UV-sensor-coords 2.61 + (filter (comp (partial inside-triangle? cutout-triangle) 2.62 + (fn [[u v]] (Vector3f. u v 0))) 2.63 + (white-coordinates image bounds)) 2.64 + UV->geometry (triangle-transformation 2.65 + cutout-triangle 2.66 + (mesh-triangle mesh tri-index)) 2.67 + geometry-sensor-coords 2.68 + (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) 2.69 + UV-sensor-coords)] 2.70 + {:UV UV-sensor-coords :geometry geometry-sensor-coords})) 2.71 + 2.72 +(defn-memo locate-feelers 2.73 + "Search the geometry's tactile UV profile for touch sensors, 2.74 + returning their positions in geometry-relative coordinates." 2.75 + [#^Geometry geo] 2.76 + (let [mesh (.getMesh geo) 2.77 + num-triangles (.getTriangleCount mesh)] 2.78 + (if-let [image (tactile-sensor-profile geo)] 2.79 + (map 2.80 + (partial sensors-in-triangle image mesh) 2.81 + (range num-triangles)) 2.82 + (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) 2.83 + 2.84 +(defn-memo touch-topology 2.85 + "Return a sequence of vectors of the form [x y] describing the 2.86 + \"topology\" of the tactile sensors. Points that are close together 2.87 + in the touch-topology are generally close together in the simulation." 2.88 + [#^Gemoetry geo] 2.89 + (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) 2.90 + 2.91 +(defn-memo feeler-coordinates 2.92 + "The location of the touch sensors in world-space coordinates." 2.93 + [#^Geometry geo] 2.94 + (vec (map :geometry (locate-feelers geo)))) 2.95 +#+end_src 2.96 + 2.97 + 2.98 + 2.99 + 2.100 * Visualizing Touch 2.101 #+name: visualization 2.102 #+begin_src clojure 2.103 @@ -393,61 +470,6 @@ 2.104 #+end_src 2.105 2.106 2.107 -* Sensor Related Functions 2.108 - 2.109 -These functions analyze the touch-sensor-profile image convert the 2.110 -location of each touch sensor from pixel coordinates to UV-coordinates 2.111 -and XYZ-coordinates. 2.112 - 2.113 -#+name: sensors 2.114 -#+begin_src clojure 2.115 -(defn sensors-in-triangle 2.116 - "Locate the touch sensors in the triangle, returning a map of their 2.117 - UV and geometry-relative coordinates." 2.118 - [image mesh tri-index] 2.119 - (let [width (.getWidth image) 2.120 - height (.getHeight image) 2.121 - UV-vertex-coords (triangle-UV-coord mesh width height tri-index) 2.122 - bounds (convex-bounds UV-vertex-coords) 2.123 - 2.124 - cutout-triangle (points->triangle UV-vertex-coords) 2.125 - UV-sensor-coords 2.126 - (filter (comp (partial inside-triangle? cutout-triangle) 2.127 - (fn [[u v]] (Vector3f. u v 0))) 2.128 - (white-coordinates image bounds)) 2.129 - UV->geometry (triangle-transformation 2.130 - cutout-triangle 2.131 - (mesh-triangle mesh tri-index)) 2.132 - geometry-sensor-coords 2.133 - (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) 2.134 - UV-sensor-coords)] 2.135 - {:UV UV-sensor-coords :geometry geometry-sensor-coords})) 2.136 - 2.137 -(defn-memo locate-feelers 2.138 - "Search the geometry's tactile UV profile for touch sensors, 2.139 - returning their positions in geometry-relative coordinates." 2.140 - [#^Geometry geo] 2.141 - (let [mesh (.getMesh geo) 2.142 - num-triangles (.getTriangleCount mesh)] 2.143 - (if-let [image (tactile-sensor-profile geo)] 2.144 - (map 2.145 - (partial sensors-in-triangle image mesh) 2.146 - (range num-triangles)) 2.147 - (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) 2.148 - 2.149 -(defn-memo touch-topology 2.150 - "Return a sequence of vectors of the form [x y] describing the 2.151 - \"topology\" of the tactile sensors. Points that are close together 2.152 - in the touch-topology are generally close together in the simulation." 2.153 - [#^Gemoetry geo] 2.154 - (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) 2.155 - 2.156 -(defn-memo feeler-coordinates 2.157 - "The location of the touch sensors in world-space coordinates." 2.158 - [#^Geometry geo] 2.159 - (vec (map :geometry (locate-feelers geo)))) 2.160 -#+end_src 2.161 - 2.162 * Physics Collision Objects 2.163 2.164 The "hairs" are actually =Rays= which extend from a point on a