diff src/laser/rasterize.clj @ 21:e72220627685 tip

0.002 inch discrepancy with target. going to test anyway
author Robert McIntyre <rlm@mit.edu>
date Mon, 30 Aug 2010 01:19:21 -0400
parents 6bed8ceb51a9
children
line wrap: on
line diff
     1.1 --- a/src/laser/rasterize.clj	Mon Aug 30 01:01:35 2010 -0400
     1.2 +++ b/src/laser/rasterize.clj	Mon Aug 30 01:19:21 2010 -0400
     1.3 @@ -16,7 +16,7 @@
     1.4  (set! *print-length* 20)
     1.5  (def feed 120)
     1.6  (def  dpi [500, 500])
     1.7 -(def paramaters {:x-dpi 500 :y-dpi 500 :margin 0 :x-offset 1 :y-offset 1})
     1.8 +(def paramaters {:x-dpi 500 :y-dpi 500 :margin 0.501 :x-offset 1.001 :y-offset 1})
     1.9  
    1.10  ;;; this process is divided into two tasks,
    1.11  ;;; creating the raster g-code, which sweeps back and forth
    1.12 @@ -70,20 +70,22 @@
    1.13    (import 'org.im4java.core.ConvertCmd)
    1.14    (import 'org.im4java.core.IMOperation)
    1.15    (import 'org.im4java.core.Stream2BufferedImage)			
    1.16 -
    1.17 +  
    1.18    (def target (.getBufferedImage (ImagePlus. sing)))
    1.19 - (def shiv (IMOperation.))
    1.20 -(.addImage shiv)
    1.21 -(.addImage shiv (into-array String ["png:-"]))
    1.22 -(def conv-shiv (ConvertCmd.))
    1.23 -(def s2b (Stream2BufferedImage.))
    1.24 -(.setOutputConsumer conv-shiv s2b)
    1.25 -(.run conv-shiv shiv (into-array Object [target]))
    1.26 -(def result (.getImage s2b ))
    1.27 +  (def shiv (IMOperation.))
    1.28 +  (.addImage shiv)
    1.29 +  (.addImage shiv (into-array String ["png:-"]))
    1.30 +  (def conv-shiv (ConvertCmd.))
    1.31 +  (def s2b (Stream2BufferedImage.))
    1.32 +  (.setOutputConsumer conv-shiv s2b)
    1.33 +  (.run conv-shiv shiv (into-array Object [target]))
    1.34 +  (def result (.getImage s2b ))
    1.35  
    1.36    )
    1.37  
    1.38 -(defn mirror [#^ImagePlus img]
    1.39 +(defn mirror
    1.40 +  "ImagePlus to ImagePlus via imageMagick through im4java!" 
    1.41 +  [#^ImagePlus img]
    1.42    (let [title (.getTitle img)
    1.43  	target (.getBufferedImage img)
    1.44  	s2b (Stream2BufferedImage.)
    1.45 @@ -115,6 +117,11 @@
    1.46  	  y1 (+ y1 y-offset)
    1.47  	  y2 (+ y2 y-offset)]
    1.48  
    1.49 +      (let [margin (if forward? margin (- margin))]
    1.50 +
    1.51 +	(let [x1 (+ x1 margin)
    1.52 +	      x2 (- x2 margin)]
    1.53 +
    1.54        
    1.55            
    1.56        (str (format "G0 X%.3f Y%.3f\n"
    1.57 @@ -123,7 +130,7 @@
    1.58  	   
    1.59  	   (format "G1 X%.3f Y%.3f\n"
    1.60  		   (float x2)
    1.61 -		   (float y2)))))))
    1.62 +		   (float y2)))))))))
    1.63    
    1.64  (defn generate-gcode [pic]
    1.65    (str (raster-preamble)
    1.66 @@ -177,10 +184,12 @@
    1.67  
    1.68  
    1.69  
    1.70 -(defn row->gmask [[x-dpi y-dpi] forward? row]
    1.71 +(defn row->gmask [{:keys [x-dpi y-dpi margin x-offset y-offset]} forward? row]
    1.72    (let [start (float (* (/ x-dpi) (first (first
    1.73  					  (if forward?
    1.74 -					  (reverse row) row)))))]
    1.75 +					    (reverse row) row)))))
    1.76 +	start (+ start x-offset)
    1.77 +	]
    1.78      (let [preamble (if-not forward?
    1.79  		     (format "0 0 0 %.3f\n" start)
    1.80  		     (format "0 0 1 %.3f\n" start))
    1.81 @@ -190,8 +199,16 @@
    1.82  		  (reverse (gather-row row))
    1.83  		  (gather-row row))]
    1.84  	    (let [x (float (* x (/ x-dpi)))
    1.85 -		  y (float (* y (/ x-dpi)))]
    1.86 -;;		  x (+ x 0.159)];; shift by a small margin.
    1.87 +		  y (float (* y (/ x-dpi)))
    1.88 +		  x (+ x x-offset)
    1.89 +		  y (+ y y-offset)
    1.90 +
    1.91 +
    1.92 +
    1.93 +
    1.94 +		  ]
    1.95 +	      
    1.96 +     
    1.97  	      (if-not forward?
    1.98  		(str (format "0 0 1 %.3f\n" x)
    1.99  		     (format "0 1 1 %.3f\n" y))
   1.100 @@ -205,7 +222,7 @@
   1.101  (defn generate-gmask [pic]
   1.102    (str "1 0 0 0\n"
   1.103         (str-join "" (map (fn [[index row]]
   1.104 -			   (row->gmask dpi (even? index) row))
   1.105 +			   (row->gmask paramaters (even? index) row))
   1.106  			 (indexed (make-rows pic))))))
   1.107  
   1.108