# HG changeset patch # User Robert McIntyre # Date 1329073851 25200 # Node ID 3fa49ff1649a88446e62b1b87f36a7018d119558 # Parent 02b2e6f3fb43ac07b1d938e847e7ef6b0145c1d3 going to recode touch.org to make it look better diff -r 02b2e6f3fb43 -r 3fa49ff1649a org/ideas.org --- a/org/ideas.org Sun Feb 12 10:45:38 2012 -0700 +++ b/org/ideas.org Sun Feb 12 12:10:51 2012 -0700 @@ -74,6 +74,7 @@ - [ ] send package to friends for critiques -- 2 days - [ ] fix videos that were encoded wrong, test on InterNet Explorer. - [ ] redo videos vision with new collapse code + - [ ] find a topology that looks good. (maybe nil topology?) - [ ] write summary of project for Winston \ - [ ] project proposals for Winston \ - [ ] additional senses to be implemented for Winston | -- 2 days diff -r 02b2e6f3fb43 -r 3fa49ff1649a org/touch.org --- a/org/touch.org Sun Feb 12 10:45:38 2012 -0700 +++ b/org/touch.org Sun Feb 12 12:10:51 2012 -0700 @@ -50,7 +50,8 @@ itself is grayscale, with black meaning a hair length of 0 (no hair is present) and white meaning a hair length of =scale=, which is a float stored under the key "scale". If the pixel is gray then the resultant -hair length is linearly interpolated between 0 and =scale=. +hair length is linearly interpolated between 0 and =scale=. I call +these "hairs" /feelers/. #+name: meta-data #+begin_src clojure @@ -86,6 +87,24 @@ #+end_src + +=(touch-kernel)= generates the functions which implement the sense of +touch for a creature. These functions must do 6 things to obtain touch +data. + + - Get the tactile profile image and scale paramaters which describe + the layout of feelers along the object's surface. + - Get the lengths of each feeler by analyzing the color of the + pixels in the tactile profile image. + - Find the triangles which make up the mesh in pixel-space and in + world-space. + - Find the coordinates of each pixel in world-space. These + coordinates are the origins of the feelers. + - Calculate the normals of the triangles in world space, and add + them to each of the origins of the feelers. These are the + normalized coordinates of the tips of the feelers. + - Generate some sort of topology for the sensors. + #+name: kernel #+begin_src clojure (in-ns 'cortex.touch) @@ -173,6 +192,64 @@ (node-seq creature))))) #+end_src +* Sensor Related Functions + +These functions analyze the touch-sensor-profile image convert the +location of each touch sensor from pixel coordinates to UV-coordinates +and XYZ-coordinates. + +#+name: sensors +#+begin_src clojure +(defn sensors-in-triangle + "Locate the touch sensors in the triangle, returning a map of their + UV and geometry-relative coordinates." + [image mesh tri-index] + (let [width (.getWidth image) + height (.getHeight image) + UV-vertex-coords (triangle-UV-coord mesh width height tri-index) + bounds (convex-bounds UV-vertex-coords) + + cutout-triangle (points->triangle UV-vertex-coords) + UV-sensor-coords + (filter (comp (partial inside-triangle? cutout-triangle) + (fn [[u v]] (Vector3f. u v 0))) + (white-coordinates image bounds)) + UV->geometry (triangle-transformation + cutout-triangle + (mesh-triangle mesh tri-index)) + geometry-sensor-coords + (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) + UV-sensor-coords)] + {:UV UV-sensor-coords :geometry geometry-sensor-coords})) + +(defn-memo locate-feelers + "Search the geometry's tactile UV profile for touch sensors, + returning their positions in geometry-relative coordinates." + [#^Geometry geo] + (let [mesh (.getMesh geo) + num-triangles (.getTriangleCount mesh)] + (if-let [image (tactile-sensor-profile geo)] + (map + (partial sensors-in-triangle image mesh) + (range num-triangles)) + (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) + +(defn-memo touch-topology + "Return a sequence of vectors of the form [x y] describing the + \"topology\" of the tactile sensors. Points that are close together + in the touch-topology are generally close together in the simulation." + [#^Gemoetry geo] + (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) + +(defn-memo feeler-coordinates + "The location of the touch sensors in world-space coordinates." + [#^Geometry geo] + (vec (map :geometry (locate-feelers geo)))) +#+end_src + + + + * Visualizing Touch #+name: visualization #+begin_src clojure @@ -393,61 +470,6 @@ #+end_src -* Sensor Related Functions - -These functions analyze the touch-sensor-profile image convert the -location of each touch sensor from pixel coordinates to UV-coordinates -and XYZ-coordinates. - -#+name: sensors -#+begin_src clojure -(defn sensors-in-triangle - "Locate the touch sensors in the triangle, returning a map of their - UV and geometry-relative coordinates." - [image mesh tri-index] - (let [width (.getWidth image) - height (.getHeight image) - UV-vertex-coords (triangle-UV-coord mesh width height tri-index) - bounds (convex-bounds UV-vertex-coords) - - cutout-triangle (points->triangle UV-vertex-coords) - UV-sensor-coords - (filter (comp (partial inside-triangle? cutout-triangle) - (fn [[u v]] (Vector3f. u v 0))) - (white-coordinates image bounds)) - UV->geometry (triangle-transformation - cutout-triangle - (mesh-triangle mesh tri-index)) - geometry-sensor-coords - (map (fn [[u v]] (.mult UV->geometry (Vector3f. u v 0))) - UV-sensor-coords)] - {:UV UV-sensor-coords :geometry geometry-sensor-coords})) - -(defn-memo locate-feelers - "Search the geometry's tactile UV profile for touch sensors, - returning their positions in geometry-relative coordinates." - [#^Geometry geo] - (let [mesh (.getMesh geo) - num-triangles (.getTriangleCount mesh)] - (if-let [image (tactile-sensor-profile geo)] - (map - (partial sensors-in-triangle image mesh) - (range num-triangles)) - (repeat (.getTriangleCount mesh) {:UV nil :geometry nil})))) - -(defn-memo touch-topology - "Return a sequence of vectors of the form [x y] describing the - \"topology\" of the tactile sensors. Points that are close together - in the touch-topology are generally close together in the simulation." - [#^Gemoetry geo] - (vec (collapse (reduce concat (map :UV (locate-feelers geo)))))) - -(defn-memo feeler-coordinates - "The location of the touch sensors in world-space coordinates." - [#^Geometry geo] - (vec (map :geometry (locate-feelers geo)))) -#+end_src - * Physics Collision Objects The "hairs" are actually =Rays= which extend from a point on a