Mercurial > rlm
diff src/rlm/visualize.clj @ 0:78a630e650d2
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 00:57:08 -0700 |
parents | |
children | 12d1367cf1aa |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/rlm/visualize.clj Tue Oct 18 00:57:08 2011 -0700 1.3 @@ -0,0 +1,57 @@ 1.4 +(ns rlm.visualize 1.5 + "this namespace has only one purpose -- to enable 1.6 + visual display of as many data structures as possible, 1.7 + with a focus on image processing (for example, raw integers 1.8 + will be shown as the color which they would encode in a RGBA 1.9 + BufferedImage. I want to get as many types as I can in here." 1.10 + {:author "Robert McIntyre"} 1.11 + 1.12 + (:import java.awt.image.BufferedImage 1.13 + [ij ImagePlus IJ])) 1.14 + 1.15 +(defmulti visual (fn [& args] (class (last args)))) 1.16 + 1.17 +(import '[org.scilab.forge.jlatexmath TeXConstants TeXFormula TeXIcon]) 1.18 +(import java.awt.Insets) 1.19 +(import javax.swing.JLabel) 1.20 +(import java.awt.Color) 1.21 + 1.22 + 1.23 +(defmethod visual ImagePlus 1.24 + [image] 1.25 + (.show image) 1.26 + image) 1.27 + 1.28 +(defmethod visual (class 4) 1.29 + [color] 1.30 + (let [image (BufferedImage. 200 200 BufferedImage/TYPE_INT_RGB)] 1.31 + (doall (for [y (range 200) x (range 200)] (.setRGB image x y color))) 1.32 + (visual (ImagePlus. "color display" image)))) 1.33 + 1.34 +(defmethod visual BufferedImage 1.35 + [image] 1.36 + (visual (ImagePlus. "visual" image))) 1.37 + 1.38 + 1.39 +(defmethod visual TeXFormula 1.40 + [formula] 1.41 + (let [icon 1.42 + (doto (.createTeXIcon formula TeXConstants/STYLE_DISPLAY 30) 1.43 + (.setInsets (Insets. 5 5 5 5))) 1.44 + image (BufferedImage. (.getIconWidth icon) (.getIconHeight icon) 1.45 + BufferedImage/TYPE_INT_ARGB) 1.46 + g (.createGraphics image) 1.47 + jl (JLabel.)] 1.48 + (.setForeground jl (Color. 0 0 0)) 1.49 + (.setColor g Color/white) 1.50 + (.fillRect g 0 0 (.getIconWidth icon) (.getIconHeight icon)) 1.51 + (.paintIcon icon jl g 0 0) 1.52 + (visual image))) 1.53 + 1.54 + 1.55 + 1.56 + 1.57 + 1.58 + 1.59 + 1.60 +