comparison org/test-creature.org @ 99:b7a3ba5e879b

made BufferedImage visulation more general
author Robert McIntyre <rlm@mit.edu>
date Sat, 14 Jan 2012 01:07:18 -0700
parents 5b23961433e3
children 940074adc1d5
comparison
equal deleted inserted replaced
98:5b23961433e3 99:b7a3ba5e879b
4 #+description: 4 #+description:
5 #+keywords: simulation, jMonkeyEngine3, clojure 5 #+keywords: simulation, jMonkeyEngine3, clojure
6 #+SETUPFILE: ../../aurellem/org/setup.org 6 #+SETUPFILE: ../../aurellem/org/setup.org
7 #+INCLUDE: ../../aurellem/org/level-0.org 7 #+INCLUDE: ../../aurellem/org/level-0.org
8 8
9
10 * objectives
11 - [ ] get an overall bitmap-like image for touch
12 - [ ] write code to visuliaze this bitmap
13 - [ ] directly change the UV-pixels to show touch sensor activation
14 - [ ] write an explination for why b&w bitmaps for senses is appropiate
15 - [ ] clean up touch code and write visulazation test
16 - [ ] do the same for eyes
17
9 * Intro 18 * Intro
10 So far, I've made the following senses -- 19 So far, I've made the following senses --
11 - Vision 20 - Vision
12 - Hearing 21 - Hearing
13 - Touch 22 - Touch
47 (require 'cortex.import) 56 (require 'cortex.import)
48 (cortex.import/mega-import-jme3) 57 (cortex.import/mega-import-jme3)
49 (use '(cortex world util body hearing touch vision)) 58 (use '(cortex world util body hearing touch vision))
50 59
51 (rlm.rlm-commands/help) 60 (rlm.rlm-commands/help)
52 61 (import java.awt.image.BufferedImage)
62 (import javax.swing.JPanel)
63 (import javax.swing.SwingUtilities)
64 (import java.awt.Dimension)
65 (import javax.swing.JFrame)
66 (import java.awt.Dimension)
53 (declare joint-create) 67 (declare joint-create)
68
69 (defn view-image
70 "Initailizes a JPanel on which you may draw a BufferedImage.
71 Returns a function that accepts a BufferedImage and draws it to the
72 JPanel."
73 []
74 (let [image
75 (atom
76 (BufferedImage. 1 1 BufferedImage/TYPE_4BYTE_ABGR))
77 panel
78 (proxy [JPanel] []
79 (paint
80 [graphics]
81 (proxy-super paintComponent graphics)
82 (.drawImage graphics @image 0 0 nil)))
83 frame (JFrame. "Display Image")]
84 (SwingUtilities/invokeLater
85 (fn []
86 (doto frame
87 (-> (.getContentPane) (.add panel))
88 (.pack)
89 (.setLocationRelativeTo nil)
90 (.setResizable true)
91 (.setVisible true))))
92 (fn [#^BufferedImage i]
93 (reset! image i)
94 (.setSize frame (+ 8 (.getWidth i)) (+ 28 (.getHeight i)))
95 (.repaint panel 0 0 (.getWidth i) (.getHeight i)))))
96
97
98 (defn visualize [points]
99
100
101
102 (defn collapse
103 "Take a set of pairs of integers and collapse them into a
104 contigous bitmap."
105 [points]
106 (let [center [0 0]]
107
108 )
109
110
111
112
113
114
115
116
117
54 118
55 (defn load-bullet [] 119 (defn load-bullet []
56 (let [sim (world (Node.) {} no-op no-op)] 120 (let [sim (world (Node.) {} no-op no-op)]
57 (.enqueue 121 (.enqueue
58 sim 122 sim
312 ;; (swap! timer inc) 376 ;; (swap! timer inc)
313 ;; (if (= (rem @timer 60) 0) 377 ;; (if (= (rem @timer 60) 0)
314 ;; (println-repl (float (/ @timer 60)))))) 378 ;; (println-repl (float (/ @timer 60))))))
315 ))) 379 )))
316 380
317
318 (defn colorful [] 381 (defn colorful []
319 (.getChild (worm-model) "worm-21")) 382 (.getChild (worm-model) "worm-21"))
320 383
321 (import jme3tools.converters.ImageToAwt) 384 (import jme3tools.converters.ImageToAwt)
322 385
362 (.getTextureValue texture-param) 425 (.getTextureValue texture-param)
363 im (.getImage texture)] 426 im (.getImage texture)]
364 (ImagePlus. 427 (ImagePlus.
365 "UV-map" 428 "UV-map"
366 (ImageToAwt/convert im false false 0)))))) 429 (ImageToAwt/convert im false false 0))))))
367
368
369 430
370 (import ij.process.ImageProcessor) 431 (import ij.process.ImageProcessor)
371 (import java.awt.image.BufferedImage) 432 (import java.awt.image.BufferedImage)
372 433
373 (defprotocol Frame 434 (defprotocol Frame
600 (.collideWith node ray results) 661 (.collideWith node ray results)
601 (let [touch-objects 662 (let [touch-objects
602 (set 663 (set
603 (filter #(not (= geo %)) 664 (filter #(not (= geo %))
604 (map #(.getGeometry %) results)))] 665 (map #(.getGeometry %) results)))]
605 (count touch-objects))))))))) 666 (if (> (count touch-objects) 0)
667 1 0)))))))))
606 668
607 (defn touch [#^Node pieces] 669 (defn touch [#^Node pieces]
608 (let [touch-components 670 (let [touch-components
609 (map enable-touch 671 (map enable-touch
610 (filter #(isa? (class %) Geometry) 672 (filter #(isa? (class %) Geometry)
611 (node-seq pieces)))] 673 (node-seq pieces)))]
612 (fn [node] 674 (fn [node]
613 (reduce into [] (map #(% node) touch-components))))) 675 (reduce into [] (map #(% node) touch-components)))))
614
615
616
617
618
619 676
620 (defn all-names [] 677 (defn all-names []
621 (concat 678 (concat
622 (re-split #"\n" (slurp (file-str 679 (re-split #"\n" (slurp (file-str
623 "/home/r/proj/names/dist.female.first"))) 680 "/home/r/proj/names/dist.female.first")))
982 (sphere 0.05 :color ColorRGBA/Yellow 1039 (sphere 0.05 :color ColorRGBA/Yellow
983 :physical? false :position 1040 :physical? false :position
984 (.getWorldTranslation obj-a))))) 1041 (.getWorldTranslation obj-a)))))
985 ) 1042 )
986 )) 1043 ))
987
988
989
990 #+end_src
991
992
993 * COMMENT generate source
994 #+begin_src clojure :tangle ../src/cortex/silly.clj
995 <<body-1>>
996 #+end_src
997
998
999
1000
1001 1044
1002 (defn transform-trianglesdsd 1045 (defn transform-trianglesdsd
1003 "Transform that converts each vertex in the first triangle 1046 "Transform that converts each vertex in the first triangle
1004 into the corresponding vertex in the second triangle." 1047 into the corresponding vertex in the second triangle."
1005 [#^Triangle tri-1 #^Triangle tri-2] 1048 [#^Triangle tri-1 #^Triangle tri-2]
1059 (dorun (map println in**)) 1102 (dorun (map println in**))
1060 (println) 1103 (println)
1061 (dorun (map println in***)) 1104 (dorun (map println in***))
1062 (println) 1105 (println)
1063 1106
1064 ))) 1107 ))))
1065 1108
1066 1109
1067 1110
1068 1111
1069 1112 #+end_src
1070 1113
1071 1114
1072 1115 * COMMENT generate source
1073 1116 #+begin_src clojure :tangle ../src/cortex/silly.clj
1074 1117 <<body-1>>
1075 1118 #+end_src
1076 1119
1077 1120
1078
1079
1080
1081
1082 1121
1083 ) 1122
1084
1085