home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
ISR
/
isr2pixels.lisp
< prev
next >
Wrap
Text File
|
1995-04-11
|
7KB
|
176 lines
;;;; -*- Mode:Common-Lisp; Package:ISR2; Base:10 -*-
;;;
;;; ISRPIXELS.LISP - low level pixel twiddling
;;; author: Bruce Draper
;;; revisions: John Brolio, Bob Collins
;;; Copyright 1987 by University of Massachusetts
;;; revised 7/31/88 for ISR2 by Bruce Draper
(in-package "ISR2")
;;(provide 'new-isr2-pixel-stuff)
(defmacro for-each-pixel (pixelmap &body body)
" Applies BODY for each pixel in the bitplane, with the
following variables set
USER::$PIXEL$ - 1 if pixel is set, 0 if it is off
USER::$ROW$ - the current row
USER::$COL$ - the current col"
(let ((bp (gensym))
(ext (gensym))
(y-index (gensym))
(x-index (gensym))
(minx (gensym))
(maxx (gensym))
(maxy (gensym))
(x-offset (gensym)))
`(let* ((,bp (pixelmap-bitplane ,pixelmap))
(,ext (pixelmap-extents ,pixelmap))
(,maxx (extents-maxx ,ext))
(,minx (extents-minx ,ext))
(,maxy (extents-maxy ,ext))
(,x-offset (- ,minx (extents-byte-bound ,ext))))
(do ((USER::$ROW$ (extents-miny ,ext) (1+ USER::$ROW$))
(,y-index 0 (1+ ,y-index)))
((> USER::$ROW$ ,maxy) nil)
(declare (special USER::$ROW$))
(do ((USER::$COL$ ,minx (1+ USER::$COL$))
(,x-index ,x-offset (1+ ,x-index)))
((> USER::$COL$ ,maxx) nil)
(declare (special USER::$COL$))
(let ((USER::$PIXEL$ (aref ,bp ,y-index ,x-index)))
(declare (special USER::$PIXEL$))
,@body))))))
(defmacro for-every-image-pixel ((pixelmap &rest var-image-pairs) &body body)
" Applies BODY for each pixel in the bitplane, with the
following variables set
USER::$VALUE$ - 1 if pixel is set, 0 if it is off
USER::$ROW$ - the current row
USER::$COL$ - the current col"
(let ((bp (gensym))
(ext (gensym))
(y-index (gensym))
(x-index (gensym))
(minx (gensym))
(maxx (gensym))
(maxy (gensym))
(x-offset (gensym))
(setf-expressions nil))
`(let* ((,bp (pixelmap-bitplane ,pixelmap))
(,ext (pixelmap-extents ,pixelmap))
(,maxx (extents-maxx ,ext))
(,minx (extents-minx ,ext))
(,maxy (extents-maxy ,ext))
(,x-offset (- ,minx (extents-byte-bound ,ext)))
,@(mapcar #'car var-image-pairs)
)
(do ((USER::$ROW$ (extents-miny ,ext) (1+ USER::$ROW$))
(,y-index 0 (1+ ,y-index)))
((> USER::$ROW$ ,maxy) nil)
(declare (special USER::$ROW$))
(do ((USER::$COL$ ,minx (1+ USER::$COL$))
(,x-index ,x-offset (1+ ,x-index)))
((> USER::$COL$ ,maxx) nil)
(declare (special USER::$COL$))
(when (= 1 (aref ,bp ,y-index ,x-index))
,@(dolist (pair var-image-pairs setf-expressions)
(push `(setf ,(car pair) (aref ,(cadr pair) USER::$ROW$ USER::$COL$ ))
setf-expressions))
,@body))))))
(defmacro for-every-image-pixel* ((pixelmap &rest var-image-pairs) &body body)
" Applies BODY for each pixel in the bitplane, with the
following variables set
USER::$PIX$ - the current value of the pixelmap (1 or 0)
USER::$ROW$ - the current row
USER::$COL$ - the current col
USER::Y-INDEX - the current row index into the bitplane
USER::X-INDEX - the current col index into the bitplane"
(let ((bp (gensym))
(ext (gensym))
(minx (gensym))
(maxx (gensym))
(maxy (gensym))
(x-offset (gensym))
(setf-expressions nil))
`(let* ((,bp (pixelmap-bitplane ,pixelmap))
(,ext (pixelmap-extents ,pixelmap))
(,maxx (extents-maxx ,ext))
(,minx (extents-minx ,ext))
(,maxy (extents-maxy ,ext))
(,x-offset (- ,minx (extents-byte-bound ,ext)))
,@(mapcar #'car var-image-pairs)
(USER::$PIX$ 0)
)
(declare (special USER::$PIX$))
(do ((USER::$ROW$ (extents-miny ,ext) (1+ USER::$ROW$))
(USER::Y-INDEX 0 (1+ USER::Y-INDEX)))
((> USER::$ROW$ ,maxy) nil)
(declare (special USER::$ROW$ USER::Y-INDEX))
(do ((USER::$COL$ ,minx (1+ USER::$COL$))
(USER::X-INDEX ,x-offset (1+ USER::X-INDEX)))
((> USER::$COL$ ,maxx) nil)
(declare (special USER::$COL$ USER::X-INDEX))
(setf USER::$PIX$ (aref ,bp USER::Y-INDEX USER::X-INDEX))
,@(dolist (pair var-image-pairs setf-expressions)
(push `(setf ,(car pair) (aref ,(cadr pair) USER::$ROW$ USER::$COL$ ))
setf-expressions))
,@body)))))
(defun read-label-plane (plane-array frame)
"Read a label-plane into a set of ISR tokens. For each label in the
label plane, a token with a matching index is created."
(unless (path? frame)
(create frame)
(define-feature `(,frame "<?>" extents) "Extents box to Region" :extents)
(define-feature `(,frame "<?>" bitplane) "Bitplane of Region" :bitplane)
(define-pixelmap-feature `(,frame "<?>" pixelmap) ""))
(let ((extents-array (label-plane-extents plane-array)))
(dotimes (ctr (length extents-array) frame)
(unless (< (extents-maxx (aref extents-array ctr))
(extents-minx (aref extents-array ctr)))
(let* ((bitplane (make-bitplane (aref extents-array ctr)))
(pixelmap (make-pixelmap :bitplane bitplane :extents (aref extents-array ctr))))
(for-every-image-pixel* (pixelmap (image-pixel plane-array))
(if (= ctr (aref plane-array USER::$ROW$ USER::$COL$))
(setf (aref bitplane USER::Y-INDEX USER::X-INDEX) 1)
(setf (aref bitplane USER::Y-INDEX USER::X-INDEX) 0)))
(unless (path? `(,frame ,ctr)) (create `(,frame ,ctr)))
(setf (value `(,frame ,ctr extents)) (aref extents-array ctr))
(setf (value `(,frame ,ctr bitplane)) bitplane))))))
(defun label-plane-extents (plane-array)
(let ((max-label (1+ (max-label plane-array)))
(plane-row-size (array-dimension plane-array 0))
(plane-col-size (array-dimension plane-array 1)))
(let ((minrow (make-array max-label :initial-element plane-row-size))
(mincol (make-array max-label :initial-element plane-col-size))
(maxrow (make-array max-label :initial-element 0))
(maxcol (make-array max-label :initial-element 0)))
(dotimes (row plane-row-size)
(dotimes (col plane-col-size)
(let ((val (aref plane-array row col)))
(when (> row (aref maxrow val)) (setf (aref maxrow val) row))
(when (< row (aref minrow val)) (setf (aref minrow val) row))
(when (> col (aref maxcol val)) (setf (aref maxcol val) col))
(when (< col (aref mincol val)) (setf (aref mincol val) col)))))
(dotimes (ctr max-label minrow)
(setf (aref minrow ctr)
(make-pixelmap-extents (aref mincol ctr) (aref minrow ctr)
(aref maxcol ctr) (aref maxrow ctr)))))))
(defun max-label (plane-array)
(let ((max-label 0)
(plane-row-size (array-dimension plane-array 0))
(plane-col-size (array-dimension plane-array 1)))
(dotimes (row plane-row-size max-label)
(dotimes (col plane-col-size)
(when (> (aref plane-array row col) max-label)
(setf max-label (aref plane-array row col)))))))