Mercurial > cortex
diff org/test-creature.org @ 93:7b739503836a
saving work
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 09 Jan 2012 19:14:47 -0700 |
parents | e70ec4bba96b |
children | 69174ed0f9f6 |
line wrap: on
line diff
1.1 --- a/org/test-creature.org Mon Jan 09 06:05:29 2012 -0700 1.2 +++ b/org/test-creature.org Mon Jan 09 19:14:47 2012 -0700 1.3 @@ -295,7 +295,7 @@ 1.4 ;;(com.aurellem.capture.Capture/captureVideo 1.5 ;; world (file-str "/home/r/proj/ai-videos/hand")) 1.6 (.setTimer world (NanoTimer.)) 1.7 - ;;(set-gravity world (Vector3f. 0 0 0)) 1.8 + (set-gravity world (Vector3f. 0 0 0)) 1.9 (speed-up world) 1.10 ) 1.11 no-op 1.12 @@ -334,6 +334,12 @@ 1.13 (.get UV-buffer (* vertex-index 2)) 1.14 (.get UV-buffer (+ 1 (* vertex-index 2)))))) 1.15 1.16 +(defn tri-uv-coord 1.17 + "Get the uv-cooridnates of the triangle's verticies." 1.18 + [#^Mesh mesh #^Triangle triangle] 1.19 + (map (partial uv-coord mesh) 1.20 + (triangle-indices mesh (.getIndex triangle)))) 1.21 + 1.22 (defn touch-receptor-image 1.23 "Return the touch-sensor distribution image in ImagePlus format." 1.24 [#^Geometry obj] 1.25 @@ -416,12 +422,32 @@ 1.26 (same-side? vert-3 vert-1 vert-2 p))) 1.27 1.28 1.29 -(defn white? [color] 1.30 - (and 1.31 - (= (:r color) 255) 1.32 - (= (:b color) 255) 1.33 - (= (:g color) 255))) 1.34 - 1.35 +(defn analyze-triangle [#^Geometry obj #^Triangle tri] 1.36 + ;; first, calculate the transformation matrix that will take us 1.37 + ;; from uv-coordinates to the real world coordinates 1.38 + (let [mesh (.getMesh obj) 1.39 + world [(.get1 tri) (.get2 tri) (.get3 tri)] 1.40 + uv (tri-uv-coord mesh tri) 1.41 + 1.42 + 1.43 + 1.44 + 1.45 + (println-repl world uv))) 1.46 + 1.47 + 1.48 + 1.49 + 1.50 + 1.51 +(defn tactile-coords* 1.52 + [#^Geometry obj] 1.53 + (let 1.54 + [tris (triangles obj) 1.55 + mesh (.getMesh obj) 1.56 + 1.57 + 1.58 + ) 1.59 + 1.60 + 1.61 1.62 ;; for each triangle in the mesh, 1.63 ;; get the normal to the triangle, 1.64 @@ -435,6 +461,7 @@ 1.65 uv-coord (partial uv-coord mesh) 1.66 triangle-indices (partial triangle-indices mesh) 1.67 receptors (touch-receptor-image obj) 1.68 + tris (triangles obj) 1.69 ] 1.70 (map 1.71 (fn [[tri-1 tri-2 tri-3]] 1.72 @@ -462,28 +489,19 @@ 1.73 ] 1.74 1.75 (.setRoi receptors min-x min-y (- max-x min-x) (- max-y min-y)) 1.76 - (let [processor (.crop (.getProcessor receptors)) 1.77 - image (frame (.getBufferedImage processor))] 1.78 - (with-meta 1.79 - (filter-keys 1.80 - (fn [[x y]] 1.81 - (inside-triangle? 1.82 - (.subtract image-1 left-corner) 1.83 - (.subtract image-2 left-corner) 1.84 - (.subtract image-3 left-corner) 1.85 - (Vector2f. x y))) 1.86 - 1.87 - 1.88 - (filter-vals white? image)) 1.89 - {:image 1.90 - (comment 1.91 - (.getBufferedImage 1.92 - (doto processor 1.93 - (.flipVertical)))) 1.94 - } 1.95 - )) 1.96 + (let [processor (.crop (.getProcessor receptors))] 1.97 + (map 1.98 + #(.add left-corner %) 1.99 + 1.100 + (filter 1.101 + (partial 1.102 + inside-triangle? 1.103 + (.subtract image-1 left-corner) 1.104 + (.subtract image-2 left-corner) 1.105 + (.subtract image-3 left-corner)) 1.106 + (white-coordinates processor)))) 1.107 )) (map triangle-indices (range num-triangles))))) 1.108 - 1.109 + 1.110 1.111 1.112