comparison org/touch.org @ 231:e29dd0024a9e

reorganized touch
author Robert McIntyre <rlm@mit.edu>
date Sat, 11 Feb 2012 19:32:21 -0700
parents f9b7d674aed8
children b7762699eeb5
comparison
equal deleted inserted replaced
230:f9b7d674aed8 231:e29dd0024a9e
50 itself is grayscale, with black meaning a hair length of 0 (no hair is 50 itself is grayscale, with black meaning a hair length of 0 (no hair is
51 present) and white meaning a hair length of =scale=, which is a float 51 present) and white meaning a hair length of =scale=, which is a float
52 stored under the key "scale". If the pixel is gray then the resultant 52 stored under the key "scale". If the pixel is gray then the resultant
53 hair length is linearly interpolated between 0 and =scale=. 53 hair length is linearly interpolated between 0 and =scale=.
54 54
55 #+name: meta-data
55 #+begin_src clojure 56 #+begin_src clojure
56 (defn tactile-sensor-profile 57 (defn tactile-sensor-profile
57 "Return the touch-sensor distribution image in BufferedImage format, 58 "Return the touch-sensor distribution image in BufferedImage format,
58 or nil if it does not exist." 59 or nil if it does not exist."
59 [#^Geometry obj] 60 [#^Geometry obj]
76 77
77 Here, =(triangles)= gets all the triangles which compose a mesh, and 78 Here, =(triangles)= gets all the triangles which compose a mesh, and
78 =(triangle-UV-coord)= returns the the UV coordinates of the verticies 79 =(triangle-UV-coord)= returns the the UV coordinates of the verticies
79 of a triangle. 80 of a triangle.
80 81
82 #+name: triangles-1
81 #+begin_src clojure 83 #+begin_src clojure
82 (defn triangles 84 (defn triangles
83 "Return a sequence of all the Triangles which compose a given 85 "Return a sequence of all the Triangles which compose a given
84 Geometry." 86 Geometry."
85 [#^Geometry geom] 87 [#^Geometry geom]
135 It is convienent to treat a =Triangle= as a sequence of verticies, and 137 It is convienent to treat a =Triangle= as a sequence of verticies, and
136 a =Vector2f= and =Vector3f= as a sequence of floats. These conversion 138 a =Vector2f= and =Vector3f= as a sequence of floats. These conversion
137 functions make this easy. If these classes implemented =Iterable= then 139 functions make this easy. If these classes implemented =Iterable= then
138 this code would not be necessary. Hopefully they will in the future. 140 this code would not be necessary. Hopefully they will in the future.
139 141
142 #+name: triangles-2
140 #+begin_src clojure 143 #+begin_src clojure
141 (defn triangle-seq [#^Triangle tri] 144 (defn triangle-seq [#^Triangle tri]
142 [(.get1 tri) (.get2 tri) (.get3 tri)]) 145 [(.get1 tri) (.get2 tri) (.get3 tri)])
143 146
144 (defn vector3f-seq [#^Vector3f v] 147 (defn vector3f-seq [#^Vector3f v]
175 coordinates to XYZ coordinates. Each =Triangle= has coordinates in 178 coordinates to XYZ coordinates. Each =Triangle= has coordinates in
176 both UV-space and XYZ-space, which defines a unique [[http://mathworld.wolfram.com/AffineTransformation.html ][Affine Transform]] 179 both UV-space and XYZ-space, which defines a unique [[http://mathworld.wolfram.com/AffineTransformation.html ][Affine Transform]]
177 for translating any coordinate within the UV triangle to the 180 for translating any coordinate within the UV triangle to the
178 cooresponding coordinate in the XYZ triangle. 181 cooresponding coordinate in the XYZ triangle.
179 182
183 #+name: triangles-3
180 #+begin_src clojure 184 #+begin_src clojure
181 (defn triangle->matrix4f 185 (defn triangle->matrix4f
182 "Converts the triangle into a 4x4 matrix: The first three columns 186 "Converts the triangle into a 4x4 matrix: The first three columns
183 contain the vertices of the triangle; the last contains the unit 187 contain the vertices of the triangle; the last contains the unit
184 normal of the triangle. The bottom row is filled with 1s." 188 normal of the triangle. The bottom row is filled with 1s."
212 inside the triangle and map them to 3D-space using 216 inside the triangle and map them to 3D-space using
213 =(triangle-transform)= above. To do this I need a function, 217 =(triangle-transform)= above. To do this I need a function,
214 =(inside-triangle?)=, which determines whether a point is inside a 218 =(inside-triangle?)=, which determines whether a point is inside a
215 triangle in 2D UV-space. 219 triangle in 2D UV-space.
216 220
221 #+name: triangles-4
217 #+begin_src clojure 222 #+begin_src clojure
218 (defn convex-bounds 223 (defn convex-bounds
219 "Returns the smallest square containing the given vertices, as a 224 "Returns the smallest square containing the given vertices, as a
220 vector of integers [left top width height]." 225 vector of integers [left top width height]."
221 [uv-verts] 226 [uv-verts]
254 259
255 These functions analyze the touch-sensor-profile image convert the 260 These functions analyze the touch-sensor-profile image convert the
256 location of each touch sensor from pixel coordinates to UV-coordinates 261 location of each touch sensor from pixel coordinates to UV-coordinates
257 and XYZ-coordinates. 262 and XYZ-coordinates.
258 263
264 #+name: sensors
259 #+begin_src clojure 265 #+begin_src clojure
260 (defn sensors-in-triangle 266 (defn sensors-in-triangle
261 "Locate the touch sensors in the triangle, returning a map of their 267 "Locate the touch sensors in the triangle, returning a map of their
262 UV and geometry-relative coordinates." 268 UV and geometry-relative coordinates."
263 [image mesh tri-index] 269 [image mesh tri-index]
307 * Physics Collision Objects 313 * Physics Collision Objects
308 314
309 The "hairs" are actually rays which extend from a point on a 315 The "hairs" are actually rays which extend from a point on a
310 =Triangle= in the =Mesh= normal to the =Triangle's= surface. 316 =Triangle= in the =Mesh= normal to the =Triangle's= surface.
311 317
318 #+name: rays
312 #+begin_src clojure 319 #+begin_src clojure
313 (defn get-ray-origin 320 (defn get-ray-origin
314 "Return the origin which a Ray would have to have to be in the exact 321 "Return the origin which a Ray would have to have to be in the exact
315 center of a particular Triangle in the Geometry in World 322 center of a particular Triangle in the Geometry in World
316 Coordinates." 323 Coordinates."
333 (.subtract n+c (get-ray-origin geom tri)))) 340 (.subtract n+c (get-ray-origin geom tri))))
334 #+end_src 341 #+end_src
335 342
336 343
337 * Skin Creation 344 * Skin Creation
338 345 #+name: kernel
339 #+begin_src clojure 346 #+begin_src clojure
340 (defn touch-fn 347 (defn touch-fn
341 "Returns a function which returns tactile sensory data when called 348 "Returns a function which returns tactile sensory data when called
342 inside a running simulation." 349 inside a running simulation."
343 [#^Geometry geo] 350 [#^Geometry geo]
391 (filter #(isa? (class %) Geometry) 398 (filter #(isa? (class %) Geometry)
392 (node-seq creature))))) 399 (node-seq creature)))))
393 #+end_src 400 #+end_src
394 401
395 * Visualizing Touch 402 * Visualizing Touch
396 403 #+name: visualization
397 #+begin_src clojure 404 #+begin_src clojure
398 (defn view-touch 405 (defn view-touch
399 "Creates a function which accepts a list of touch sensor-data and 406 "Creates a function which accepts a list of touch sensor-data and
400 displays each element to the screen." 407 displays each element to the screen."
401 [] 408 []
409 (gray (sensor-data i))))) 416 (gray (sensor-data i)))))
410 image)))) 417 image))))
411 #+end_src 418 #+end_src
412 419
413 * Headers 420 * Headers
421
422 #+name: touch-header
414 #+begin_src clojure 423 #+begin_src clojure
415 (ns cortex.touch 424 (ns cortex.touch
416 "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry 425 "Simulate the sense of touch in jMonkeyEngine3. Enables any Geometry
417 to be outfitted with touch sensors with density determined by a UV 426 to be outfitted with touch sensors with density determined by a UV
418 image. In this way a Geometry can know what parts of itself are 427 image. In this way a Geometry can know what parts of itself are
432 * Next 441 * Next
433 442
434 443
435 * COMMENT Code Generation 444 * COMMENT Code Generation
436 #+begin_src clojure :tangle ../src/cortex/touch.clj 445 #+begin_src clojure :tangle ../src/cortex/touch.clj
437 <<skin-main>> 446 <<touch-header>>
447 <<meta-data>>
448 <<triangles-1>>
449 <<triangles-2>>
450 <<triangles-3>>
451 <<triangles-4>>
452 <<sensors>>
453 <<rays>>
454 <<kernel>>
455 <<visualization>>
438 #+end_src 456 #+end_src
439 457
440 #+begin_src clojure :tangle ../src/cortex/test/touch.clj 458 #+begin_src clojure :tangle ../src/cortex/test/touch.clj
441 #+end_src 459 #+end_src
442 460