Mercurial > cortex
changeset 239:78a640e3bc55
saving progress... touch is in an inconsistent state.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 12 Feb 2012 12:58:01 -0700 |
parents | 3fa49ff1649a |
children | 6961377c4554 |
files | org/touch.org |
diffstat | 1 files changed, 108 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/touch.org Sun Feb 12 12:10:51 2012 -0700 1.2 +++ b/org/touch.org Sun Feb 12 12:58:01 2012 -0700 1.3 @@ -94,22 +94,45 @@ 1.4 1.5 - Get the tactile profile image and scale paramaters which describe 1.6 the layout of feelers along the object's surface. 1.7 + =(tactile-sensor-profile)=, =(tactile-scale)= 1.8 + 1.9 - Get the lengths of each feeler by analyzing the color of the 1.10 pixels in the tactile profile image. 1.11 + NOT IMPLEMENTED YET 1.12 + 1.13 - Find the triangles which make up the mesh in pixel-space and in 1.14 world-space. 1.15 + =(triangles)= =(pixel-triangles)= 1.16 + 1.17 + - Find the coordinates of each pixel in pixel space. These 1.18 + coordinates are used to make the touch-topology. 1.19 + =(sensors-in-triangle)= 1.20 + 1.21 - Find the coordinates of each pixel in world-space. These 1.22 coordinates are the origins of the feelers. 1.23 + 1.24 - Calculate the normals of the triangles in world space, and add 1.25 them to each of the origins of the feelers. These are the 1.26 normalized coordinates of the tips of the feelers. 1.27 + For both of these, =(feelers)= 1.28 + 1.29 - Generate some sort of topology for the sensors. 1.30 + =(touch-topology)= 1.31 + 1.32 +#+begin_src clojure 1.33 + 1.34 + 1.35 + 1.36 + 1.37 +#+end_src 1.38 + 1.39 + 1.40 1.41 #+name: kernel 1.42 #+begin_src clojure 1.43 (in-ns 'cortex.touch) 1.44 1.45 -(declare touch-topology touch-hairs set-ray) 1.46 +(declare touch-topology feelers set-ray) 1.47 1.48 (defn touch-kernel 1.49 "Constructs a function which will return tactile sensory data from 1.50 @@ -117,7 +140,7 @@ 1.51 [#^Geometry geo] 1.52 (let [[ray-reference-origins 1.53 ray-reference-tips 1.54 - ray-lengths] (touch-hairs geo) 1.55 + ray-lengths] (feelers geo) 1.56 current-rays (map (fn [] (Ray.)) ray-reference-origins) 1.57 topology (touch-topology geo)] 1.58 (if (empty? ray-reference-origins) nil 1.59 @@ -200,6 +223,17 @@ 1.60 1.61 #+name: sensors 1.62 #+begin_src clojure 1.63 +(defn pixel-feelers 1.64 + "Returns the coordinates of the feelers in pixel space in lists, one 1.65 + list for each triangle, ordered in the same way as (triangles) and 1.66 + (pixel-triangles)." 1.67 + [#^Geometry geo image] 1.68 + 1.69 + 1.70 + 1.71 + 1.72 + 1.73 + 1.74 (defn sensors-in-triangle 1.75 "Locate the touch sensors in the triangle, returning a map of their 1.76 UV and geometry-relative coordinates." 1.77 @@ -297,29 +331,34 @@ 1.78 1.79 #+name: triangles-1 1.80 #+begin_src clojure 1.81 +(in-ns 'cortex.touch) 1.82 + 1.83 +(defn vector3f-seq [#^Vector3f v] 1.84 + [(.getX v) (.getY v) (.getZ v)]) 1.85 + 1.86 +(defn triangle-seq [#^Triangle tri] 1.87 + [(vector3f-seq (.get1 tri)) 1.88 + (vector3f-seq (.get2 tri)) 1.89 + (vector3f-seq (.get3 tri))]) 1.90 + 1.91 +(defn ->vector3f [[x y z]] (Vector3f. x y z)) 1.92 + 1.93 +(defn ->triangle [points] 1.94 + (apply #(Triangle. %1 %2 %3) (map ->vector3f points))) 1.95 + 1.96 +(defn triangle 1.97 + "Get the triangle specified by triangle-index from the mesh within 1.98 + bounds." 1.99 + [#^Geometry geo triangle-index] 1.100 + (triangle-seq 1.101 + (let [scratch (Triangle.)] 1.102 + (.getTriangle (.getMesh geo) triangle-index scratch) scratch))) 1.103 + 1.104 (defn triangles 1.105 "Return a sequence of all the Triangles which compose a given 1.106 Geometry." 1.107 - [#^Geometry geom] 1.108 - (let 1.109 - [mesh (.getMesh geom) 1.110 - triangles (transient [])] 1.111 - (dorun 1.112 - (for [n (range (.getTriangleCount mesh))] 1.113 - (let [tri (Triangle.)] 1.114 - (.getTriangle mesh n tri) 1.115 - ;; (.calculateNormal tri) 1.116 - ;; (.calculateCenter tri) 1.117 - (conj! triangles tri)))) 1.118 - (persistent! triangles))) 1.119 - 1.120 -(defn mesh-triangle 1.121 - "Get the triangle specified by triangle-index from the mesh within 1.122 - bounds." 1.123 - [#^Mesh mesh triangle-index] 1.124 - (let [scratch (Triangle.)] 1.125 - (.getTriangle mesh triangle-index scratch) 1.126 - scratch)) 1.127 + [#^Geometry geo] 1.128 + (map (partial triangle geo) (range (.getTriangleCount (.getMesh geo))))) 1.129 1.130 (defn triangle-vertex-indices 1.131 "Get the triangle vertex indices of a given triangle from a given 1.132 @@ -340,51 +379,20 @@ 1.133 [(.get UV-buffer (* vertex-index 2)) 1.134 (.get UV-buffer (+ 1 (* vertex-index 2)))])) 1.135 1.136 -(defn triangle-UV-coord 1.137 - "Get the UV-cooridnates of the triangle's verticies." 1.138 - [#^Mesh mesh width height triangle-index] 1.139 - (map (fn [[u v]] (vector (* width u) (* height v))) 1.140 - (map (partial vertex-UV-coord mesh) 1.141 - (triangle-vertex-indices mesh triangle-index)))) 1.142 -#+end_src 1.143 +(defn pixel-triangle [#^Geometry geo image index] 1.144 + (let [mesh (.getMesh geo) 1.145 + width (.getWidth image) 1.146 + height (.getHeight image)] 1.147 + (vec (map (fn [[u v]] (vector (* width u) (* height v))) 1.148 + (map (partial vertex-UV-coord mesh) 1.149 + (triangle-vertex-indices mesh index)))))) 1.150 1.151 -* Schrapnel Conversion Functions 1.152 +(defn pixel-triangles [#^Geometry geo image] 1.153 + (let [height (.getHeight image) 1.154 + width (.getWidth image)] 1.155 + (map (partial pixel-triangle geo image) 1.156 + (range (.getTriangleCount (.getMesh geo)))))) 1.157 1.158 -It is convienent to treat a =Triangle= as a sequence of verticies, and 1.159 -a =Vector2f= and =Vector3f= as a sequence of floats. These conversion 1.160 -functions make this easy. If these classes implemented =Iterable= then 1.161 -this code would not be necessary. Hopefully they will in the future. 1.162 - 1.163 -#+name: triangles-2 1.164 -#+begin_src clojure 1.165 -(defn triangle-seq [#^Triangle tri] 1.166 - [(.get1 tri) (.get2 tri) (.get3 tri)]) 1.167 - 1.168 -(defn vector3f-seq [#^Vector3f v] 1.169 - [(.getX v) (.getY v) (.getZ v)]) 1.170 - 1.171 -(defn point->vector2f [[u v]] 1.172 - (Vector2f. u v)) 1.173 - 1.174 -(defn vector2f->vector3f [v] 1.175 - (Vector3f. (.getX v) (.getY v) 0)) 1.176 - 1.177 -(defn map-triangle [f #^Triangle tri] 1.178 - (Triangle. 1.179 - (f 0 (.get1 tri)) 1.180 - (f 1 (.get2 tri)) 1.181 - (f 2 (.get3 tri)))) 1.182 - 1.183 -(defn points->triangle 1.184 - "Convert a list of points into a triangle." 1.185 - [points] 1.186 - (apply #(Triangle. %1 %2 %3) 1.187 - (map (fn [point] 1.188 - (let [point (vec point)] 1.189 - (Vector3f. (get point 0 0) 1.190 - (get point 1 0) 1.191 - (get point 2 0)))) 1.192 - (take 3 points)))) 1.193 #+end_src 1.194 1.195 * Triangle Affine Transforms 1.196 @@ -425,6 +433,41 @@ 1.197 (.invert (triangle->matrix4f tri-1)))) 1.198 #+end_src 1.199 1.200 + 1.201 +* Schrapnel Conversion Functions 1.202 + 1.203 +It is convienent to treat a =Triangle= as a sequence of verticies, and 1.204 +a =Vector2f= and =Vector3f= as a sequence of floats. These conversion 1.205 +functions make this easy. If these classes implemented =Iterable= then 1.206 +this code would not be necessary. Hopefully they will in the future. 1.207 + 1.208 +#+name: triangles-2 1.209 +#+begin_src clojure 1.210 +(defn point->vector2f [[u v]] 1.211 + (Vector2f. u v)) 1.212 + 1.213 +(defn vector2f->vector3f [v] 1.214 + (Vector3f. (.getX v) (.getY v) 0)) 1.215 + 1.216 +(defn map-triangle [f #^Triangle tri] 1.217 + (Triangle. 1.218 + (f 0 (.get1 tri)) 1.219 + (f 1 (.get2 tri)) 1.220 + (f 2 (.get3 tri)))) 1.221 + 1.222 +(defn points->triangle 1.223 + "Convert a list of points into a triangle." 1.224 + [points] 1.225 + (apply #(Triangle. %1 %2 %3) 1.226 + (map (fn [point] 1.227 + (let [point (vec point)] 1.228 + (Vector3f. (get point 0 0) 1.229 + (get point 1 0) 1.230 + (get point 2 0)))) 1.231 + (take 3 points)))) 1.232 +#+end_src 1.233 + 1.234 + 1.235 * Triangle Boundaries 1.236 1.237 For efficiency's sake I will divide the UV-image into small squares