;; Examples from Dan's thesis ;; code to rotate the image by a certain number of degrees about (0,0) (bulk-define rotate-manifold ((manifold 2 1) (manifold 2 1) real) unspecified (lambda (insheet outsheet degree-angle) (let* ((rad-angle (/ (* degree-angle pi) -180.0)) (sinangle (sin rad-angle)) (cosangle (cos rad-angle))) (scan (location outsheet) (let* ((point (sample->point location)) (xcoord (point-coordinate point 0)) (ycoord (point-coordinate point 1)) (value (sheet-ref insheet (- (* xcoord cosangle) (* ycoord sinangle)) (+ (* xcoord sinangle) (* ycoord cosangle))))) (sample-set! location value)))))) ;; Laplacian (bulk-define laplacian ((manifold 2 1) (manifold 2 1)) unspecified (lambda (input-manifold output-manifold) (let ((input-start-sample (focus-min-sample input-manifold)) (output-start-sample (focus-min-sample output-manifold))) (scan (output-sample output-manifold) (let* ((input-sample (shift-sample input-start-sample (sample-offset output-sample output-start-sample))) (value00 (sample-ref (shift-sample input-sample -1 -1))) (value10 (sample-ref (shift-sample input-sample 0 -1))) (value20 (sample-ref (shift-sample input-sample 1 -1))) (value01 (sample-ref (shift-sample input-sample -1 0))) (value11 (sample-ref input-sample)) (value21 (sample-ref (shift-sample input-sample 1 0))) (value02 (sample-ref (shift-sample input-sample -1 1))) (value12 (sample-ref (shift-sample input-sample 0 1))) (value22 (sample-ref (shift-sample input-sample 1 1)))) (if (or (missing? value10) (missing? value12) (missing? value01) (missing? value21)) (sample-set! output-sample 0.0) (if (< (+ (* -4.0 value11) (* -1.0 value10) (* -1.0 value12) (* -1.0 value01) (* -1.0 value21) (* 2.0 value00) (* 2.0 value20) (* 2.0 value02) (* 2.0 value22)) 0.0) (sample-set! output-sample 0.0) (sample-set! output-sample 250.0)))))))) ;;; synthetic sine-wave pattern (bulk-define sine-wave ((integer-grid 2 1) real real real) unspecified (lambda (input amp period offset) (let ((myval 0) (myloc 0.0)) (scan (ss input #f scan-right) (set! myloc (+ myloc 1)) (set! myval (inexact->exact (round (+ offset (* amp (sin (/ (* myloc 2 pi) period))))))) (scan (kk ss #f scan-up) (sample-set! kk myval)))))) These tested loops vs scanners: ;;; Set an integer-grid at all positions without a scan (bulk-define without-scan ((integer-grid 2 1) integer) unspecified (lambda (ig value) (do ((x 0 (+ x 1))) ((= x 640)) (do ((y 0 (+ y 1))) ((= y 480)) (sample-set! (nearest-sample ig x y) value))))) ;;; Set an integer-grid at all positions with a scan (bulk-define with-scan ((integer-grid 2 1) integer) unspecified (lambda (ig value) (scan (sam ig) (sample-set! sam value))))