comparison 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
comparison
equal deleted inserted replaced
92:e70ec4bba96b 93:7b739503836a
293 (light-up-everything world) 293 (light-up-everything world)
294 (enable-debug world) 294 (enable-debug world)
295 ;;(com.aurellem.capture.Capture/captureVideo 295 ;;(com.aurellem.capture.Capture/captureVideo
296 ;; world (file-str "/home/r/proj/ai-videos/hand")) 296 ;; world (file-str "/home/r/proj/ai-videos/hand"))
297 (.setTimer world (NanoTimer.)) 297 (.setTimer world (NanoTimer.))
298 ;;(set-gravity world (Vector3f. 0 0 0)) 298 (set-gravity world (Vector3f. 0 0 0))
299 (speed-up world) 299 (speed-up world)
300 ) 300 )
301 no-op 301 no-op
302 ;;(let [timer (atom 0)] 302 ;;(let [timer (atom 0)]
303 ;; (fn [_ _] 303 ;; (fn [_ _]
331 mesh 331 mesh
332 VertexBuffer$Type/TexCoord))] 332 VertexBuffer$Type/TexCoord))]
333 (Vector2f. 333 (Vector2f.
334 (.get UV-buffer (* vertex-index 2)) 334 (.get UV-buffer (* vertex-index 2))
335 (.get UV-buffer (+ 1 (* vertex-index 2)))))) 335 (.get UV-buffer (+ 1 (* vertex-index 2))))))
336
337 (defn tri-uv-coord
338 "Get the uv-cooridnates of the triangle's verticies."
339 [#^Mesh mesh #^Triangle triangle]
340 (map (partial uv-coord mesh)
341 (triangle-indices mesh (.getIndex triangle))))
336 342
337 (defn touch-receptor-image 343 (defn touch-receptor-image
338 "Return the touch-sensor distribution image in ImagePlus format." 344 "Return the touch-sensor distribution image in ImagePlus format."
339 [#^Geometry obj] 345 [#^Geometry obj]
340 (let 346 (let
414 (same-side? vert-1 vert-2 vert-3 p) 420 (same-side? vert-1 vert-2 vert-3 p)
415 (same-side? vert-2 vert-3 vert-1 p) 421 (same-side? vert-2 vert-3 vert-1 p)
416 (same-side? vert-3 vert-1 vert-2 p))) 422 (same-side? vert-3 vert-1 vert-2 p)))
417 423
418 424
419 (defn white? [color] 425 (defn analyze-triangle [#^Geometry obj #^Triangle tri]
420 (and 426 ;; first, calculate the transformation matrix that will take us
421 (= (:r color) 255) 427 ;; from uv-coordinates to the real world coordinates
422 (= (:b color) 255) 428 (let [mesh (.getMesh obj)
423 (= (:g color) 255))) 429 world [(.get1 tri) (.get2 tri) (.get3 tri)]
424 430 uv (tri-uv-coord mesh tri)
431
432
433
434
435 (println-repl world uv)))
436
437
438
439
440
441 (defn tactile-coords*
442 [#^Geometry obj]
443 (let
444 [tris (triangles obj)
445 mesh (.getMesh obj)
446
447
448 )
449
450
425 451
426 ;; for each triangle in the mesh, 452 ;; for each triangle in the mesh,
427 ;; get the normal to the triangle, 453 ;; get the normal to the triangle,
428 ;; look at the UV touch map, restricted to that triangle, 454 ;; look at the UV touch map, restricted to that triangle,
429 ;; get the positions of those touch sensors in geometry-relative 455 ;; get the positions of those touch sensors in geometry-relative
433 num-triangles (.getTriangleCount mesh) 459 num-triangles (.getTriangleCount mesh)
434 num-verticies (.getVertexCount mesh) 460 num-verticies (.getVertexCount mesh)
435 uv-coord (partial uv-coord mesh) 461 uv-coord (partial uv-coord mesh)
436 triangle-indices (partial triangle-indices mesh) 462 triangle-indices (partial triangle-indices mesh)
437 receptors (touch-receptor-image obj) 463 receptors (touch-receptor-image obj)
464 tris (triangles obj)
438 ] 465 ]
439 (map 466 (map
440 (fn [[tri-1 tri-2 tri-3]] 467 (fn [[tri-1 tri-2 tri-3]]
441 (let [width (.getWidth receptors) 468 (let [width (.getWidth receptors)
442 height (.getHeight receptors) 469 height (.getHeight receptors)
460 (Vector2f. min-x min-y) 487 (Vector2f. min-x min-y)
461 488
462 ] 489 ]
463 490
464 (.setRoi receptors min-x min-y (- max-x min-x) (- max-y min-y)) 491 (.setRoi receptors min-x min-y (- max-x min-x) (- max-y min-y))
465 (let [processor (.crop (.getProcessor receptors)) 492 (let [processor (.crop (.getProcessor receptors))]
466 image (frame (.getBufferedImage processor))] 493 (map
467 (with-meta 494 #(.add left-corner %)
468 (filter-keys 495
469 (fn [[x y]] 496 (filter
470 (inside-triangle? 497 (partial
471 (.subtract image-1 left-corner) 498 inside-triangle?
472 (.subtract image-2 left-corner) 499 (.subtract image-1 left-corner)
473 (.subtract image-3 left-corner) 500 (.subtract image-2 left-corner)
474 (Vector2f. x y))) 501 (.subtract image-3 left-corner))
475 502 (white-coordinates processor))))
476
477 (filter-vals white? image))
478 {:image
479 (comment
480 (.getBufferedImage
481 (doto processor
482 (.flipVertical))))
483 }
484 ))
485 )) (map triangle-indices (range num-triangles))))) 503 )) (map triangle-indices (range num-triangles)))))
486 504
487 505
488 506
489 507
490 508
491 509