rlm@0
|
1 (ns rlm.visualize
|
rlm@0
|
2 "this namespace has only one purpose -- to enable
|
rlm@0
|
3 visual display of as many data structures as possible,
|
rlm@0
|
4 with a focus on image processing (for example, raw integers
|
rlm@0
|
5 will be shown as the color which they would encode in a RGBA
|
rlm@0
|
6 BufferedImage. I want to get as many types as I can in here."
|
rlm@0
|
7 {:author "Robert McIntyre"}
|
rlm@0
|
8
|
rlm@0
|
9 (:import java.awt.image.BufferedImage
|
rlm@0
|
10 [ij ImagePlus IJ]))
|
rlm@0
|
11
|
rlm@0
|
12 (defmulti visual (fn [& args] (class (last args))))
|
rlm@0
|
13
|
rlm@0
|
14 (import '[org.scilab.forge.jlatexmath TeXConstants TeXFormula TeXIcon])
|
rlm@0
|
15 (import java.awt.Insets)
|
rlm@0
|
16 (import javax.swing.JLabel)
|
rlm@0
|
17 (import java.awt.Color)
|
rlm@0
|
18
|
rlm@0
|
19
|
rlm@0
|
20 (defmethod visual ImagePlus
|
rlm@0
|
21 [image]
|
rlm@4
|
22 (.show image) image)
|
rlm@0
|
23
|
rlm@0
|
24 (defmethod visual (class 4)
|
rlm@0
|
25 [color]
|
rlm@0
|
26 (let [image (BufferedImage. 200 200 BufferedImage/TYPE_INT_RGB)]
|
rlm@0
|
27 (doall (for [y (range 200) x (range 200)] (.setRGB image x y color)))
|
rlm@0
|
28 (visual (ImagePlus. "color display" image))))
|
rlm@0
|
29
|
rlm@0
|
30 (defmethod visual BufferedImage
|
rlm@0
|
31 [image]
|
rlm@0
|
32 (visual (ImagePlus. "visual" image)))
|
rlm@0
|
33
|
rlm@0
|
34
|
rlm@0
|
35 (defmethod visual TeXFormula
|
rlm@0
|
36 [formula]
|
rlm@0
|
37 (let [icon
|
rlm@0
|
38 (doto (.createTeXIcon formula TeXConstants/STYLE_DISPLAY 30)
|
rlm@0
|
39 (.setInsets (Insets. 5 5 5 5)))
|
rlm@0
|
40 image (BufferedImage. (.getIconWidth icon) (.getIconHeight icon)
|
rlm@0
|
41 BufferedImage/TYPE_INT_ARGB)
|
rlm@0
|
42 g (.createGraphics image)
|
rlm@0
|
43 jl (JLabel.)]
|
rlm@0
|
44 (.setForeground jl (Color. 0 0 0))
|
rlm@0
|
45 (.setColor g Color/white)
|
rlm@0
|
46 (.fillRect g 0 0 (.getIconWidth icon) (.getIconHeight icon))
|
rlm@0
|
47 (.paintIcon icon jl g 0 0)
|
rlm@0
|
48 (visual image)))
|
rlm@0
|
49
|
rlm@0
|
50
|
rlm@0
|
51
|
rlm@0
|
52
|
rlm@0
|
53
|
rlm@0
|
54
|
rlm@0
|
55
|
rlm@0
|
56
|