# HG changeset patch # User Robert McIntyre # Date 1329076681 25200 # Node ID 78a640e3bc556fae52392c25376f3544cd29924a # Parent 3fa49ff1649a88446e62b1b87f36a7018d119558 saving progress... touch is in an inconsistent state. diff -r 3fa49ff1649a -r 78a640e3bc55 org/touch.org --- a/org/touch.org Sun Feb 12 12:10:51 2012 -0700 +++ b/org/touch.org Sun Feb 12 12:58:01 2012 -0700 @@ -94,22 +94,45 @@ - Get the tactile profile image and scale paramaters which describe the layout of feelers along the object's surface. + =(tactile-sensor-profile)=, =(tactile-scale)= + - Get the lengths of each feeler by analyzing the color of the pixels in the tactile profile image. + NOT IMPLEMENTED YET + - Find the triangles which make up the mesh in pixel-space and in world-space. + =(triangles)= =(pixel-triangles)= + + - Find the coordinates of each pixel in pixel space. These + coordinates are used to make the touch-topology. + =(sensors-in-triangle)= + - 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. + For both of these, =(feelers)= + - Generate some sort of topology for the sensors. + =(touch-topology)= + +#+begin_src clojure + + + + +#+end_src + + #+name: kernel #+begin_src clojure (in-ns 'cortex.touch) -(declare touch-topology touch-hairs set-ray) +(declare touch-topology feelers set-ray) (defn touch-kernel "Constructs a function which will return tactile sensory data from @@ -117,7 +140,7 @@ [#^Geometry geo] (let [[ray-reference-origins ray-reference-tips - ray-lengths] (touch-hairs geo) + ray-lengths] (feelers geo) current-rays (map (fn [] (Ray.)) ray-reference-origins) topology (touch-topology geo)] (if (empty? ray-reference-origins) nil @@ -200,6 +223,17 @@ #+name: sensors #+begin_src clojure +(defn pixel-feelers + "Returns the coordinates of the feelers in pixel space in lists, one + list for each triangle, ordered in the same way as (triangles) and + (pixel-triangles)." + [#^Geometry geo image] + + + + + + (defn sensors-in-triangle "Locate the touch sensors in the triangle, returning a map of their UV and geometry-relative coordinates." @@ -297,29 +331,34 @@ #+name: triangles-1 #+begin_src clojure +(in-ns 'cortex.touch) + +(defn vector3f-seq [#^Vector3f v] + [(.getX v) (.getY v) (.getZ v)]) + +(defn triangle-seq [#^Triangle tri] + [(vector3f-seq (.get1 tri)) + (vector3f-seq (.get2 tri)) + (vector3f-seq (.get3 tri))]) + +(defn ->vector3f [[x y z]] (Vector3f. x y z)) + +(defn ->triangle [points] + (apply #(Triangle. %1 %2 %3) (map ->vector3f points))) + +(defn triangle + "Get the triangle specified by triangle-index from the mesh within + bounds." + [#^Geometry geo triangle-index] + (triangle-seq + (let [scratch (Triangle.)] + (.getTriangle (.getMesh geo) triangle-index scratch) scratch))) + (defn triangles "Return a sequence of all the Triangles which compose a given Geometry." - [#^Geometry geom] - (let - [mesh (.getMesh geom) - triangles (transient [])] - (dorun - (for [n (range (.getTriangleCount mesh))] - (let [tri (Triangle.)] - (.getTriangle mesh n tri) - ;; (.calculateNormal tri) - ;; (.calculateCenter tri) - (conj! triangles tri)))) - (persistent! triangles))) - -(defn mesh-triangle - "Get the triangle specified by triangle-index from the mesh within - bounds." - [#^Mesh mesh triangle-index] - (let [scratch (Triangle.)] - (.getTriangle mesh triangle-index scratch) - scratch)) + [#^Geometry geo] + (map (partial triangle geo) (range (.getTriangleCount (.getMesh geo))))) (defn triangle-vertex-indices "Get the triangle vertex indices of a given triangle from a given @@ -340,51 +379,20 @@ [(.get UV-buffer (* vertex-index 2)) (.get UV-buffer (+ 1 (* vertex-index 2)))])) -(defn triangle-UV-coord - "Get the UV-cooridnates of the triangle's verticies." - [#^Mesh mesh width height triangle-index] - (map (fn [[u v]] (vector (* width u) (* height v))) - (map (partial vertex-UV-coord mesh) - (triangle-vertex-indices mesh triangle-index)))) -#+end_src +(defn pixel-triangle [#^Geometry geo image index] + (let [mesh (.getMesh geo) + width (.getWidth image) + height (.getHeight image)] + (vec (map (fn [[u v]] (vector (* width u) (* height v))) + (map (partial vertex-UV-coord mesh) + (triangle-vertex-indices mesh index)))))) -* Schrapnel Conversion Functions +(defn pixel-triangles [#^Geometry geo image] + (let [height (.getHeight image) + width (.getWidth image)] + (map (partial pixel-triangle geo image) + (range (.getTriangleCount (.getMesh geo)))))) -It is convienent to treat a =Triangle= as a sequence of verticies, and -a =Vector2f= and =Vector3f= as a sequence of floats. These conversion -functions make this easy. If these classes implemented =Iterable= then -this code would not be necessary. Hopefully they will in the future. - -#+name: triangles-2 -#+begin_src clojure -(defn triangle-seq [#^Triangle tri] - [(.get1 tri) (.get2 tri) (.get3 tri)]) - -(defn vector3f-seq [#^Vector3f v] - [(.getX v) (.getY v) (.getZ v)]) - -(defn point->vector2f [[u v]] - (Vector2f. u v)) - -(defn vector2f->vector3f [v] - (Vector3f. (.getX v) (.getY v) 0)) - -(defn map-triangle [f #^Triangle tri] - (Triangle. - (f 0 (.get1 tri)) - (f 1 (.get2 tri)) - (f 2 (.get3 tri)))) - -(defn points->triangle - "Convert a list of points into a triangle." - [points] - (apply #(Triangle. %1 %2 %3) - (map (fn [point] - (let [point (vec point)] - (Vector3f. (get point 0 0) - (get point 1 0) - (get point 2 0)))) - (take 3 points)))) #+end_src * Triangle Affine Transforms @@ -425,6 +433,41 @@ (.invert (triangle->matrix4f tri-1)))) #+end_src + +* Schrapnel Conversion Functions + +It is convienent to treat a =Triangle= as a sequence of verticies, and +a =Vector2f= and =Vector3f= as a sequence of floats. These conversion +functions make this easy. If these classes implemented =Iterable= then +this code would not be necessary. Hopefully they will in the future. + +#+name: triangles-2 +#+begin_src clojure +(defn point->vector2f [[u v]] + (Vector2f. u v)) + +(defn vector2f->vector3f [v] + (Vector3f. (.getX v) (.getY v) 0)) + +(defn map-triangle [f #^Triangle tri] + (Triangle. + (f 0 (.get1 tri)) + (f 1 (.get2 tri)) + (f 2 (.get3 tri)))) + +(defn points->triangle + "Convert a list of points into a triangle." + [points] + (apply #(Triangle. %1 %2 %3) + (map (fn [point] + (let [point (vec point)] + (Vector3f. (get point 0 0) + (get point 1 0) + (get point 2 0)))) + (take 3 points)))) +#+end_src + + * Triangle Boundaries For efficiency's sake I will divide the UV-image into small squares