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
/
isr2defs.lisp
< prev
next >
Wrap
Lisp/Scheme
|
1995-04-11
|
21KB
|
578 lines
;;; -*- Mode:Common-Lisp; Package:ISR2; Base:10 -*-
;;;
;;; isrdefs.lisp
;;; author: Bruce Draper
;;; revisions: John Brolio, Bob Collins, Robert Heller (ISR2)
;;; Copyright 1987 by University of Massachusetts
;;;
;; Modifications
;; Changed DEFMACROS to #-:allegro defsubst #+:allegro defun !
;; Only use defmacros where extreme need for speed exists.
;; The new compiler is pretty decent.
;; if you call some of these like funs.
;;
;; 1/12/88 16:04:32 Bob Collins - changed defvars of *block-area* and
;; *bitplane-area* to cdefvars
;; 6/19/91 Ross Beveridge - a copy of cdefvar is now defined for ISR2
;;
;; 04/11/88 10:10:58 Robert Heller - ISR2 rewrite
;;
(in-package "ISR2")
(export '(extents extents-p byte-bound-of byte-width-of pixel-count-od minx-of miny-of
maxx-of maxy-of))
;; These constants are not really arbitrary. *real-undefined* and
;; *int-undefined* are the same bit pattern--
;; just interpreted differently. This allows the undefined-value bit to work
;; in the overlay plains. Additionally,
;; the *real-undefined* has a #xA in front, to match the tag bits for integer.
;; The same is true of undefinable values.
(eval-when (load eval compile)
(defconstant *undefined-datatype* 12)
(defconstant *undefinable-datatype* 13)
(defconstant *default-2index-vector-size* 256
"Initial size given to a 2index vector")
(defconstant *default-2index-vector-vector-size* 100
"Initial size given to a 2index vector vector")
;(defconstant *real-undefined* 3.437125223e10)
(defconstant *real-undefined* 2.420126136572157e-32)
;(defconstant *int-undefined* 16470528)
(defconstant *int-undefined* 16470525)
(defconstant *ptr-undefined* '|()|)
(defconstant *old-ptr-undefined* '*undefined*)
;;(defconstant *real-undefinable* 1.374850089e11)
(defconstant *real-undefinable* 2.4201640462649711E-32)
(defconstant *int-undefinable* 16470784)
(defconstant *ptr-undefinable* '|)(|)
(defconstant *old-ptr-undefinable* '*undefinable*)
(defconstant *boolean-dt 0)
(DEFCONSTANT *boolean* 0)
(defconstant *pointer-dt 1)
(DEFCONSTANT *POINTER* 1)
(defconstant *bitplane-dt 2)
(DEFCONSTANT *BITPLANE* 2)
(defconstant *extents-dt 3)
(DEFCONSTANT *EXTENTS* 3)
(defconstant *int-dt 4)
(DEFCONSTANT *INTEGER* 4)
(DEFCONSTANT *INT* 4)
(defconstant *fixnum* 4)
(defconstant *real-dt 5)
(DEFCONSTANT *REAL* 5)
(defconstant *float* 5)
(defconstant *single-float* 5)
;; RPH - added these three data types
(defconstant *array-dt 6)
(DEFCONSTANT *ARRAY* 6)
(defconstant *handle-dt 7)
(DEFCONSTANT *HANDLE* 7)
(defconstant *string-dt 8)
(DEFCONSTANT *string* 8)
(defconstant FIRST-DT *BOOLEAN* "First data type")
(defconstant LAST-DT *STRING* "Last data type")
(defconstant *type-names*
(make-array
9
:initial-contents '("Boolean/Existence" "Pointer" "Bitplane"
"Extents" "Int" "Real" "Array"
"Handle" "String")))
(defconstant *type-keywords*
(make-array
9
:initial-contents '(:Boolean :Pointer :Bitplane
:Extents :Integer :Real :Array
:Handle :String)))
)
(defun dt-from-keyword (keyword)
(dotimes (idt 9)
(when (eq (aref *type-keywords* idt) keyword) (return-from dt-from-keyword idt)))
nil)
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun keyword-from-dt (idt)
(if (and (>= idt FIRST-DT) (<= idt LAST-DT))
(aref *type-keywords* idt)
nil))
;;;;
;; RPH - this structure replaces the xxx-blocks of ISR V1.
;; All Feature value vectors (including the existence vectors) will consist of a
;; vector of these critters.
;;
;; 2index-vector is the generic structure. The actual feature value vectors
;; will contain a "specialized" version - it will be the same structure, but
;; will have a different type name - just does an :include of this structure and
;; adds no slots of its own. ** Note: this is tricky - I'm using the generic
;; structure's accessors on structures which are named different, but have the
;; same actual structure **
;;
(defstruct (2index-vector (:print-function print-2index-vector)
(:constructor %make-2index-vector))
"Basic 2-index vector structure. Existence vectors and data vectors consist
of a vector of these things."
(start-index 0 :type integer)
(end-index *default-2index-vector-size* :type integer)
(data-vector (make-array *default-2index-vector-size*
:initial-element *ptr-undefined*)
:type (array * (*)))
)
;;;;
;; specialized 2index-vectors:
(defstruct (2index-bin-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-bin-vector))
)
(defstruct (2index-ptr-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-ptr-vector))
)
(defstruct (2index-int-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-int-vector))
)
(defstruct (2index-real-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-real-vector))
)
(defstruct (2index-ary-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-ary-vector))
)
(defstruct (2index-bp-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-bp-vector))
)
(defstruct (2index-extents-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-extents-vector))
)
(defstruct (2index-handle-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-handle-vector))
)
(defstruct (2index-string-vector (:include 2index-vector)
(:print-function print-2index-vector)
(:constructor %make-2index-string-vector))
)
;;;;
;; generic print function - used by all of the above.
(defun print-2index-vector (vector-struct stream level)
(if (or (null *print-array*)
(and *print-level* (> level *print-level*)))
(format stream "#<~A (~d..~d) #>"
(type-of vector-struct)
(2index-vector-start-index vector-struct)
(2index-vector-end-index vector-struct))
(format stream "#<~A (~d..~d) ~s>"
(type-of vector-struct)
(2index-vector-start-index vector-struct)
(2index-vector-end-index vector-struct)
(2index-vector-data-vector vector-struct))
)
)
;; magic LISPM storage management hackery: reserve space outside of the GCer's
;; access
#+:EXPLORER
(cdefvar *2index-area* (make-area :name '2index-area :gc :static :room t))
#+:EXPLORER
(cdefvar *bitplane-area* (make-area :name 'bitplane-area
:gc :temporary :room t))
;;;;
;; generic 2index-vector constructor. Calls the specialized versions by casing on
;; the element-data-type.
(defun make-2index-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0) (element-data-type *pointer*)
&aux #+:EXPLORER (default-cons-area *2index-area*))
#+:EXPLORER (declare (special default-cons-area))
(funcall (ecase element-data-type
(#.*pointer* #'%make-2index-ptr-vector)
(#.*array* #'%make-2index-ary-vector)
(#.*extents* #'%make-2index-extents-vector)
(#.*bitplane* #'%make-2index-bp-vector)
(#.*int* #'%make-2index-int-vector)
(#.*real* #'%make-2index-real-vector)
(#.*handle* #'%make-2index-handle-vector)
(#.*string* #'%make-2index-string-vector)
(#.*BOOLEAN* #'%make-2index-bin-vector)
)
:start-index start-index
:end-index (+ start-index vector-size)
:data-vector (make-array vector-size
:element-type (ecase element-data-type
((#.*pointer*
#.*array*
#.*extents*
#.*handle* #.*string*
#.*bitplane*) t)
(#.*real* 'single-float)
(#.*int* #+:explorer 'fixnum
#+user::vax '(signed-byte 32)
#-:EXPLORER '(signed-byte 32)
)
(#.*BOOLEAN* 'bit))
:initial-element (ecase element-data-type
((#.*pointer*
#.*array*
#.*extents*
#.*handle* #.*string*
#.*bitplane*) *ptr-undefined*)
(#.*real* *real-undefined*)
(#.*int* *int-undefined*)
(#.*BOOLEAN* 0))
)
)
)
;;;;
;; specialized versions. These call back the main generic version, which calls
;; the defstruct generated constructors
(defun make-2index-bin-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *BOOLEAN*))
(defun make-2index-int-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *int*))
(defun make-2index-real-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *real*))
(defun make-2index-ptr-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *pointer*))
(defun make-2index-ary-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *array*))
(defun make-2index-bp-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *bitplane*))
(defun make-2index-extents-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *extents*))
(defun make-2index-handle-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *handle*))
(defun make-2index-string-vector (&key (vector-size *default-2index-vector-size*)
(start-index 0))
(make-2index-vector :vector-size vector-size :start-index start-index
:element-data-type *string*))
;;;;
;; generic 2index-vector initializer. Called by allocate-resource.
;;
(defun initialize-2index-vector (object initial-element start-index end-index)
(setf (2index-vector-start-index object) start-index)
(setf (2index-vector-end-index object) end-index)
(fill (2index-vector-data-vector object) initial-element))
;; here are the defresource's
#+:EXPLORER
(defresource 2index-int-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-int-vector)
:initializer (initialize-2index-vector object *int-undefined* start-index end-index))
#+:EXPLORER
(defresource 2index-real-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-real-vector)
:initializer (initialize-2index-vector object *real-undefined*
start-index end-index))
#+:EXPLORER
(defresource 2index-bin-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-bin-vector)
:initializer (initialize-2index-vector object 0 start-index end-index))
#+:EXPLORER
(defresource 2index-ptr-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-ptr-vector)
:initializer (initialize-2index-vector object *ptr-undefined* start-index end-index))
#+:EXPLORER
(defresource 2index-bp-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-bp-vector)
:initializer (initialize-2index-vector object *ptr-undefined* start-index end-index))
#+:EXPLORER
(defresource 2index-extents-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-extents-vector)
:initializer (initialize-2index-vector object *ptr-undefined* start-index end-index))
#+:EXPLORER
(defresource 2index-handle-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-handle-vector)
:initializer (initialize-2index-vector object *ptr-undefined* start-index end-index))
#+:EXPLORER
(defresource 2index-ary-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-ary-vector)
:initializer (initialize-2index-vector object *ptr-undefined* start-index end-index))
#+:EXPLORER
(defresource 2index-string-vector
(&optional (start-index 0)
(end-index (+ start-index *default-2index-vector-size*)))
:constructor (make-2index-string-vector)
:initializer (initialize-2index-vector object *ptr-undefined* start-index end-index))
;;;;
;; This structure is the vector-vector used for token value "vectors". This is
;; just an adjustable, fill-pointer array with a lock, resource-type, and a slot
;; to hold the undefined value (saves time during lookups on undefined slots).
;;
(defstruct (2index-vector-vector (:constructor %make-2index-vector-vector))
"Double index vector structure - used for all magic vectors."
(lock)
(resource-type)
(undefined-value)
(data (make-array *default-2index-vector-vector-size*
:fill-pointer 0
:adjustable t)))
#-:EXPLORER
(defun allocate-resource (type &optional (start-index 0))
(case type
(2index-int-vector
(make-2index-int-vector :start-index start-index))
(2index-real-vector
(make-2index-real-vector :start-index start-index))
(2index-bin-vector
(make-2index-bin-vector :start-index start-index))
(2index-ptr-vector
(make-2index-ptr-vector :start-index start-index))
(2index-bp-vector
(make-2index-bp-vector :start-index start-index))
(2index-extents-vector
(make-2index-extents-vector :start-index start-index))
(2index-ary-vector
(make-2index-ary-vector :start-index start-index))
(2index-handle-vector
(make-2index-handle-vector :start-index start-index))
(2index-string-vector
(make-2index-string-vector :start-index start-index))
)
)
#-:EXPLORER
(defun DEALLOCATE-RESOURCE (type object) (declare (ignore type object)) t)
;;;;
;; function to add a new chunk of memory to a vector-vector.
;;
(defun add-2index-vector (vector-vector &optional ov)
"This function allocates new memory for a double index vector. Only memory
for the OV'th block is allocated - VECTOR-VECTOR is grown to be long enough,
with NIL filler is needed."
(with-lock ((2index-vector-vector-lock vector-vector))
(let* ((vec (2index-vector-vector-data vector-vector))
(fill-ptr (fill-pointer vec))
(start-index 0)
)
(unless ov (setf ov fill-ptr))
(setf start-index (* ov *default-2index-vector-size*))
(do () ((< ov fill-ptr))
(vector-push-extend
nil
(2index-vector-vector-data vector-vector))
(incf fill-ptr))
(setf (aref vec ov)
(allocate-resource
(2index-vector-vector-resource-type vector-vector)
start-index))
(values vector-vector (aref vec ov))
)
)
)
(defun make-2index-vector-vector (vector-type)
"This function make a fresh 2-index vector structure. Only the header
structure and base vector are allocated."
(%make-2index-vector-vector
:resource-type (ecase vector-type
(#.*BOOLEAN* '2index-bin-vector)
(#.*pointer* '2index-ptr-vector)
(#.*bitplane* '2index-bp-vector)
(#.*extents* '2index-extents-vector)
(#.*int* '2index-int-vector)
(#.*real* '2index-real-vector)
(#.*array* '2index-ary-vector)
(#.*handle* '2index-handle-vector)
(#.*string* '2index-string-vector)
)
:undefined-value (ecase vector-type
(#.*BOOLEAN* 0)
((#.*pointer* #.*bitplane* #.*extents* #.*array*
#.*string* #.*handle*) *ptr-undefined*)
(#.*int* *int-undefined*)
(#.*real* *real-undefined*)
)
)
)
(defun vvref (vv i)
"VVREF VV I - return the I'th element of double index vector VV.
If the I'th element does not exist, the UNDEFINED magic value is returned.
(No index out-of-range error is raised or even defined - the vector is
presumed to be of indefinate length)."
(let* ((outer-vec (2index-vector-vector-data vv))
(undefined (2index-vector-vector-undefined-value vv))
(ov-size (fill-pointer outer-vec))
iv ov inner-vec
)
(multiple-value-setq (ov iv)
(truncate i *default-2index-vector-size*))
(if (< ov ov-size)
(progn
(setf inner-vec (aref outer-vec ov))
(if inner-vec
(aref (2index-vector-data-vector inner-vec) iv)
undefined))
undefined)
)
)
(defun set-vvref (vv i new-value)
"This is the set function for VVREF. Like VVREF, there is no index-out-of-range
condition. Instead, the vector is grown and memory is allocated when needed."
(let* ((outer-vec (2index-vector-vector-data vv))
(ov-size (fill-pointer outer-vec))
iv ov inner-vec unused
)
(multiple-value-setq (ov iv)
(truncate i *default-2index-vector-size*))
(if (< ov ov-size)
(progn (setf inner-vec (aref outer-vec ov))
(if inner-vec
(setf (aref (2index-vector-data-vector inner-vec) iv) new-value)
(progn
(multiple-value-setq (unused inner-vec)
(add-2index-vector vv ov))
(setf (aref (2index-vector-data-vector inner-vec) iv) new-value))))
(progn
(multiple-value-setq (unused inner-vec)
(add-2index-vector vv ov))
(setf (aref (2index-vector-data-vector inner-vec) iv) new-value)))
)
)
(defsetf vvref set-vvref "SETF form for VVREF.")
(defstruct fdescr
"FDESCR (Feature descriptor) Structure. Contains information relating to
a feature (either a frame or token feature)."
type
featurename
value
docstring
if-needed
if-setting
if-getting
(lock))
;; quick access function
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun get-feature-descr-type (fdescr) (fdescr-type fdescr))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun get-feature-descr-value (fdescr) (fdescr-value fdescr))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun get-feature-descr-featurename (fdescr) (fdescr-featurename fdescr))
(defstruct (extents (:constructor make-extents-struct))
"EXTENTS Structure. Contains region extents info."
(byte-bound 0 :type integer)
(byte-width 0 :type integer)
(pixel-count 0 :type integer)
(minx 0 :type integer)
(miny 0 :type integer)
(maxx 0 :type integer)
(maxy 0 :type integer)
)
;; quick access functions
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun byte-bound-of (ext) (extents-byte-bound ext))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun byte-width-of (ext) (extents-byte-width ext))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun pixel-count-of (ext) (extents-pixel-count ext))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun minx-of (ext) (extents-minx ext))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun miny-of (ext) (extents-miny ext))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun maxx-of (ext) (extents-maxx ext))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun maxy-of (ext) (extents-maxy ext))
;; error checking functions
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun check-frame (frame)
(unless (frame-p frame)
(error "Argument is not a frame - ~S" frame)))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun check-handle (handle)
(unless (handle-p handle)
(error "Argument is not a handle ~S" handle)))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun check-index (index)
(unless (and (numberp index)(not (minusp index)))
(error "Argument is not a permissible token index, ~S" index)))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun check-fdescr (fdescr)
(unless (fdescr-p fdescr)
(error "Argument is not an fdescr, ~S" fdescr)))
(#-(or :allegro :lispworks) defsubst #+(or :allegro :lispworks) defun token-exists-p (tok-handle)
(= (vvref (frame-token-set-existence-vector (handle-frame tok-handle))
(handle-token tok-handle))
1))