UBC Theses and Dissertations

UBC Theses Logo

UBC Theses and Dissertations

Interactive polygon filling on a raster graphic display Stoch, Stephen Leonard 1981

Your browser doesn't seem to have a PDF viewer, please download the PDF to view this item.

Notice for Google Chrome users:
If you are having trouble viewing or searching the PDF with Google Chrome, please download it here instead.

Item Metadata

Download

Media
831-UBC_1981_A6_7 S86.pdf [ 7.92MB ]
Metadata
JSON: 831-1.0051840.json
JSON-LD: 831-1.0051840-ld.json
RDF/XML (Pretty): 831-1.0051840-rdf.xml
RDF/JSON: 831-1.0051840-rdf.json
Turtle: 831-1.0051840-turtle.txt
N-Triples: 831-1.0051840-rdf-ntriples.txt
Original Record: 831-1.0051840-source.json
Full Text
831-1.0051840-fulltext.txt
Citation
831-1.0051840.ris

Full Text

I N T E R A C T I V E POLYGON F I L L I N G ON A RASTER GRAPHIC D I S P L A Y by STEPHEN LEONARD STOCH B.A., The U n i v e r s i t y o f C a p e Town, 1974 B . S c , The U n i v e r s i t y o f C a p e Town, 1978 A T H E S I S SUBMITTED IN P A R T I A L F U L F I L M E N T OF THE REQUIREMENTS FOR THE DEGREE OF MASTER OF S C I E N C E i n THE F A C U L T Y OF GRADUATE ST U D I E S ( C o m p u t e r S c i e n c e ) We a c c e p t t h i s t h e s i s a s c o n f o r m i n g t o t h e r e q u i r e d s t a n d a r d . THE U N I V E R S I T Y OF B R I T I S H COLUMBIA M a r c h , 1981 ( c ) S t e p h e n L e o n a r d S t o c h , 1981 In p r e s e n t i n g t h i s t h e s i s i n p a r t i a l f u l f i l m e n t of the requirements f o r an advanced degree a t the U n i v e r s i t y o f B r i t i s h Columbia, I agree t h a t the L i b r a r y s h a l l make i t f r e e l y a v a i l a b l e f o r r e f e r e n c e and study. I f u r t h e r agree t h a t p e r m i s s i o n f o r e x t e n s i v e copying o f t h i s t h e s i s f o r s c h o l a r l y purposes may be granted by the head o f my department o r by h i s o r her r e p r e s e n t a t i v e s . I t i s understood t h a t c o p y i n g or p u b l i c a t i o n o f t h i s t h e s i s f o r f i n a n c i a l g a i n s h a l l not be a llowed without my w r i t t e n p e r m i s s i o n . Department of fQtAPuTEfc StClgYJCE. The U n i v e r s i t y of B r i t i s h Columbia 2075 Wesbrook P l a c e Vancouver, Canada V6T 1W5 Date / i n \ i i A b s t r a c t T h i s t h e s i s d e s c r i b e s P o l y g o n F i l l i n g S y s t e m , an i n t e r a c t i v e g r a p h i c s s y s t e m , w h i c h f i l l s u s e r d e f i n e d a r e a s on a r a s t e r s c a n g r a p h i c s d i s p l a y d e v i c e . T h e a r e a s may be c o n c a v e o r c o n v e x a n d may be n e s t e d w i t h i n e a c h o t h e r . I s s u e s r e l a t e d t o t h e u n d e r l y i n g g r i d m o d e l , h e x a g o n a l o r s q u a r e t e s s e l a t i o n , a r e d i s c u s s e d . A f o r m a l a p p r o a c h t o p o l y g o n f i l l i n g i s c o m p a r e d t o a ' h e u r i s t i c d o m a i n d e p e n d e n t a p p r o a c h . C o n n e c t i v i t y p r o b l e m s a r i s e i n p r o c e s s i n g b o u n d a r i e s . Two u s e r r u l e s a r e d e f i n e d . A d h e r e n c e t o t h e s e r u l e s e n s u r e s c o r r e c t p r o c e s s i n g o f d a t a . T h e s e r u l e s a r e a p p r o p r i a t e f o r c a r t o g r a p h i c a n d r e m o t e s e n s i n g a p p l i c a t i o n s . T h e i m p l e m e n t a t i o n o f t h e s y s t e m a n d i t s k e y d a t a s t r u c t u r e s a r e d e s c r i b e d . T a b l e o f C o n t e n t s C h a p t e r I : I n t r o d u c t i o n • 1 A. M o t i v a t i o n 3 B. An E x a m p l e 4 C. I s s u e s 9 C h a p t e r I I : U n d e r l y i n g I s s u e s 10 A. T h e U n d e r l y i n g G r i d M o d e l 10 B. R a t i o n a l e o f an H e u r i s t i c A p p r o a c h 15 C h a p t e r I I I : B o u n d a r y D e f i n i t i o n : A F u n c t i o n a l O v e r v i e w 16 A. U s e r C o n s i d e r a t i o n s 16 B. B o u n d a r y P r o c e s s i n g 21 C h a p t e r I V : I m p l e m e n t a t i o n 24 A. C u r v e S m o o t h i n g 25 1. E x p a n s i o n a n d C o n t r a c t i o n 26 B. E s t a b l i s h D a t a 28 C. P r o c e s s B o u n d a r y 33 1. Smudge P r o c e s s i n g 34 1.1 E l i m i n a t i o n o f I n t e r m e d i a t e B i t s 38 1.2 E l i m i n a t i o n o f Smudge R e m a i n i n g 40 2. C l o s e s t P o i n t 47 3. F i n d t h e F i r s t P o i n t o f B o u n d a r y 49 4. P r o t e c t i o n o f U s e r s I n p u t 50 D. P o l y g o n C l o s u r e 51 E . P o l y g o n F i l l i n g 52 F . T a i l D e t e c t i o n 57 G. D e l e t i o n o f T a i l s 61 i v H. I m p r o v e m e n t s : 2-D V e r s u s 3-D M a t r i c e s 63 C h a p t e r V: P r o b l e m s , D i f f i c u l t i e s a n d F e a t u r e s 65 A. S a m p l e Run 65 B. S y s t e m D e p e n d e n c e ...76 C h a p t e r V I : C o n c l u s i o n 77 B i b l i o g r a p h y 80 A p p e n d i x A: P r o g r a m l i s t i n g f o r P o l y g o n F i l l i n g S y s t e m 82 A p p e n d i x B: R e c u r s i v e A l g o r i t h m 132 L i s t o f F i g u r e s 1.1 V a l i d s e t o f u s e r d e f i n e d a r e a s 1 1.2 B o u n d a r i e s a s d e f i n e d by t h e u s e r 4 1.3 C l o s e d p o l y g o n s a s p r e s e n t e d t o t h e u s e r 7 1.4 A r e a s f i l l e d by PFS 8 2.1 S q u a r e g r i d s h o w i n g o b j e c t a m b i g u i t i e s 10 2.2 H e x a g o n a l g r i d s h o w i n g s i n g l e o b j e c t 12 2.3 S q u a r e g r i d w i t h a l t e n a t e rows s h i f t e d a d i s t a n c e o f h a l f a p i x e l 13 3.1a S p a c i a l d i s t r i b u t i o n o f p i x e l s c o n f o r m s t o t e m p o r a l r u l e s 16 3.1b S p a c i a l d i s t r i b u t i o n o f p i x e l s d o e s n o t c o n f o r m t o t e m p o r a l r u l e s 17 3.2 S p a c i a l d i s t r i b u t i o n o f p i x e l s d o e s n o t c o n f o r m t o t e m p o r a l r u l e s 18 3.3a C o r r e c t c l o s u r e o f b o u n d a r y 19 3.3b I n c o r r e c t c l o s u r e o f b o u n d a r y 20 3.4 D e l e t i o n o f c o l i n e a r p i x e l s 22 3.5 D e l e t i o n o f smudge p o i n t s 23 4.1 F l o w o f c o n t r o l i n PFS 24 4.2 E l e m e n t s i n a s q u a r e g r i d h a v e e i g h t n e i g h b o u r s ..25 4.3 P a s c a l d e c l a r a t i o n s 29 4.4 D a t a s t r u c t u r e f o r t h e m a t i x i n d e x 30 4.5 F l o w o f c o n t r o l i n p r o c e s s i n g an a r e a 33 4.6 D i r e c t i o n s i n w h i c h t h e n e x t p o i n t may l i e 35 4.7 T r a v e r s a l o f a n a c t a g o n 36 4.8 Smudge w h i c h c o m p r i s e s a t h i c k l i n e w i t h s t r a i g h t o u t e r e d g e i n l i n e w i t h a c a r t e s i a n a x i s 37 4.9 Smudge w h i c h c o m p r i s e s a g r o u p o f a d j a c e n t p i x e l s on t h e i n s i d e o f a r e f l e x v e r t e x 37 4.10 C o m p l e t e smudge 38 4.11a P r o c e s s i n g o f a s e q u e n c e o f p i x e l s 39 4.11b A p i x e l on t h e o u t s i d e o f a s e q u e n c e o f p i x e l s h a l t s p r o c e s s i n g o f t h a t s e q u e n c e 40 4.12a I l l u s t r a t i o n o f smudge a c c u r a c y 41 4.12b I l l u s t r a t i o n o f smudge a c c u r a c y 42 4.13 Smudge p r o c e s s i n g 45 4.14 U p p e r a n d l o w e r p o l y g o n a r c s 53 4.15 U p p e r p o l y g o n a r c 54 4.16 C o n t i n u o u s e d g e s t r i n g s 55 4.17 F o u r e x a m p l e s o f g e n e r a l e d g e c o n d i t i o n s 55 4.18 T r a c e d b o u n d a r y a n d t h e r e s u l t i n g c l o s e d p o l y g o n .58 4.19 C o n f u s i o n r e s u l t i n g f r o m t h r e e c h a n g e s i n s t a t e o f beam 59 4.20 A r r o w s h i g h l i g h t i n g p o t e n t i a l t a i l s 60 4.21 T a i l s j o i n i n g p o l y g o n s a t a r c s a n d a n e d g e 61 5.1 B o u n d a r i e s t r a c e d b y t h e u s e r 66 5.2 C l o s e d p o l y g o n g e n e r a t e d i n p r o c e s s i n g b o u n d a r y ..67 5.3 P r o b l e m p i x e l s e r a s e d f r o m s c r e e n 68 5.4 E r a s e d b o u n d a r y l i n e s r e t r a c e d 69 5.5 C o r r e c t e d c l o s e d p o l y g o n 70 v i i 5.6 A r r o w s h i g h l i g h t e x i s t a n c e o f a t a i l 71 5.7 C l o s e d p o l y g o n g e n e r a t e d i n p r o c e s s i n g b o u n d a r y ..72 5.8 Two new b o u n d a r i e s a r e a d d e d 73 5.9 T h e two new b o u n d a r i e s a r e v e r i f i e d 74 5.10 P o l y g o n s f i l l e d by PFS 75 V I 1 1 L i s t o f T a b l e s 4.1 R e l a t i o n s h i p b e t w e e n d i r e c t i o n o f t r a v e r s a l a n d smudge o u t e r e d g e t o be t r a v e r s e d ..36 4.2 R e l a t i o n s h i p b e t w e e n d i r e c t i o n o f t r a v e r s a l a n d t h e n e i g h b o u r f o r a d j a c e n c y c h e c k i n t h e f i r s t l e v e l o f r e c u r s i v e smudge p r o c e s s i n g 43 4.3 R e l a t i o n s h i p b e t w e e n d i r e c t i o n o f t r a v e r s a l a n d t h e n e i g h b o u r f o r a d j a c e n c y c h e c k i n t h e s e c o n d l e v e l o f r e c u r s i v e smudge p r o c e s s i n g 44 i x A c k n o w l e d g e m e n t s I w o u l d s i n c e r e l y l i k e t o t h a n k my s u p e r v i s o r , Bob Woodham, f o r t h e p a t i e n c e , s u p p o r t , a n d p e r c e p t i v e c r i t i c i s m t h a t he h a s g i v e n t h r o u g h o u t t h e i m p l e m e n t a t i o n o f t h i s t h e s i s . I w o u l d a l s o l i k e t o t h a n k N o u 2 D a d o u n , J a y G l i c k s m a n , I h o r Gowda, M a r c M a j k a , a n d C a r l P o t t l e who a c t e d a s s o u n d i n g b o a r d s w h i l e I p o s t u l a t e d v a r i o u s a l g o r i t h m s . T h a n k s t o M a r c f o r p r o o f r e a d i n g t h e t h e s i s , J a y f o r t h e u s e o f h i s FORTRAN s u b r o u t i n e s , D a v e B r e n t f o r h i s s u p p o r t on t h e COMTAL, a n d N e d e n i a H o l m f o r a s s i s t a n c e w i t h d i a g r a m s . A f i n a l t h a n k s t o o f f i c e m a t e s Norm a n d Wendy f o r t o l e r a t i n g b o t h my u p s a n d downs. 1 C h a p t e r I n t r o d u c t i o n T h i s t h e s i s d e s c r i b e s P o l y g o n F i l l i n g S y s t e m ( P F S ) , an i n t e r a c t i v e g r a p h i c s s y s t e m w h i c h a l l o w s t h e u s e r t o d e f i n e g e n e r a l a r e a s on a r a s t e r g r a p h i c d i s p l a y d e v i c e . T h e b o u n d a r i e s o f t h e s e a r e a s , h e r e a f t e r r e f e r e d t o s i m p l y a s b o u n d a r i e s , a r e i n p u t u s i n g a t r a c k - b a l l o r some e q u i v a l e n t g r a p h i c a l i n p u t d e v i c e . T h e a r e a s may be c o n v e x o r c o n c a v e . Th e a r e a s may be n e s t e d w i t h i n e a c h o t h e r . T h e o u t e r most a r e a h a s a n e s t i n g d e p t h o f o n e . E a c h e n c l o s e d a r e a h a s a n e s t i n g d e p t h e q u a l t o o n e p l u s t h a t o f i t s i m m e d i a t e l y e n c l o s i n g a r e a . T h e r e may be more t h a n one a r e a o f a n y p a r t i c u l a r n e s t i n g d e p t h . F i g 1.1 An e x a m p l e o f a v a l i d s e t o f u s e r d e f i n e d a r e a s . T h e number w i t h i n e a c h a r e a i n d i c a t e s t h e n e s t i n g d e p t h f o r t h a t a r e a . 2 When t h e u s e r i s s a t i s f i e d w i t h t h e d e f i n e d a r e a s , t h e s y s t e m w i l l f i l l a l l a r e a s whose n e s t i n g d e p t h i s o d d . A r e a s w i t h e v e n n e s t i n g d e p t h a r e l e f t u n f i l l e d . 3 A. M o t i v a t i o n T h e s y s t e m d e s c r i b e d i n t h i s t h e s i s was m o t i v a t e d by t h e l a c k o f a n y f a c i l i t y , e i t h e r i n h a r d w a r e o r s o f t w a r e , t o p e r f o r m p o l y g o n / a r e a f i l l i n g on t h e UBC r e m o t e s e n s i n g i m a g e a n a l y s i s s y s t e m . I t was d e s i r e d t h a t a s y s t e m be d e v e l o p e d w h i c h w o u l d a l l o w t h e u s e r t o o u t l i n e a r e a s a p p e a r i n g on L a n d s a t i m a g e s ( l a k e s , m o u n t a i n s , s h a d o w s , e t c . ) By t r a c i n g t h e b o u n d a r i e s o f t h e s e a r e a s on t h e GRAPHIC o v e r l a y s w h i c h f o r m p a r t o f t h e COMTAL V i s i o n One a r c h i t e c t u r e . I t was f u r t h e r d e s i r e d t h a t t h e s e a r e a s be f i l l e d a u t o m a t i c a l l y . T h e h a r d w a r e c o m p r i s e s a COMTAL V i s i o n One i m a g e p r o c e s s i n g s y s t e m , a h i g h s p e e d b i - d i r e c t i o n a l c o m m u n i c a t i o n l i n k t o t h e UBC M i c h i g a n T e r m i n a l S y s t e m (MTS) f a c i l i t y a n d t h e MTS s y s t e m i t s e l f . T h e d a t a w h i c h i s s e n t f r o m t h e COMTAL t o t h e PFS c a n be t h o u g h t o f a s a two d i m e n s i o n a l m a t r i x o f b i t s . E a c h e l e m e n t o f t h i s m a t r i x c a n t a k e one o f two s t a t e s , one o r z e r o ( o n o r o f f ) . T h e i n f o r m a t i o n i s t h u s s p a t i a l i n n a t u r e . No o t h e r i n f o r m a t i o n r e g a r d i n g t h e d a t a e n t e r e d by t h e u s e r on t h e COMTAL's r a s t e r s c r e e n i s a v a i l a b l e t o t h e p r o g r a m . I t i s n o t known, f o r e x a m p l e , t h e o r d e r ( i n t i m e ) i n w h i c h t h e p i x e l s on t h e s c r e e n w e r e t u r n e d on o r o f f . T h i s l a c k o f k n o w l e d g e a b o u t t h e o r d e r i n g o f t h e b i t s c r e a t e s many o f t h e p r o b l e m s a d d r e s s e d i n t h i s t h e s i s a s w i l l now be shown. 4 B. An e x a m p l e Th e b o u n d a r i e s a s t r a c e d on t h e d i s p l a y d e v i c e by t h e u s e r a r e shown i n f i g u r e 1.2. T h e s e b o u n d a r i e s a r e i n p u t w i t h a t r a c k - b a l l o r some s i m i l a r g r a p h i c a l i n p u t d e v i c e . F i g u r e 1.2 i l l u s t r a t e s t h r e e p o t e n t i a l p r o b l e m s w h i c h a r i s e i n u s e r d e f i n e d b o u n d a r i e s : ( i ) Box ( a ) i n t h e a b o v e f i g u r e e n c l o s e s a p o r t i o n o f t h e b o u n d a r y c u r v e , t h e t h i c k n e s s o f w h i c h i s g r e a t e r t h a n one p i x e l . T h i s i s a n o c c u r r e n c e o f a smudge. Smudges a n d t h e p r o c e s s i n g t h e r e o f a r e d i s c u s s e d i n c h a p t e r s I I I a n d I V b e l o w . T h e p r o b l e m w i t h s m udges i s t o d e c i d e w h i c h p i x e l s t o r e t a i n a n d w h i c h t o d i s c a r d a s b e i n g n o i s e . PFS f o l l o w s t h e o u t e r e d g e F i g u r e 1.2 A r e a b o u n d a r i e s a s d e f i n e d b y t h e u s e r . 5 o f t h e smudge ( s e e c h a p t e r I V s e c t i o n C . l ) . ( i i ) B e c a u s e o f t h e i n h e r e n t i n a c c u r a c i e s i n t h e t r a c k b a l l , g a p s a n d s m a l l h o l e s a p p e a r i n u s e r d e f i n e d i n p u t . T h e s e i n a c c u r a c i e s , a n d t h e m a n n e r i n w h i c h t h e y a r e d e a l t , a r e d e s c r i b e d i n c h a p t e r s I I I a n d I V . I n f i g u r e 1.2, b o x e s (d) a n d ( e ) i l l u s t r a t e e x a m p l e s o f a g a p a n d a h o l e r e s p e c t i v e l y . ( i i i ) T o d e c i d e w h i c h p i x e l s a r e c o n n e c t e d , t h e s y s t e m h a s t o r e s o l v e a p p a r e n t a m b i g u i t i e s r e s u l t i n g f r o m t h e r e l a t i v e d i s t a n c e s b e t w e e n p i x e l s . T h i s a m b i g u i t y may e x i s t b e t w e e n p i x e l s f r o m t h e same b o u n d a r y o r b e t w e e n p i x e l s f r o m d i f f e r e n t b o u n d a r i e s . E x a m p l e s o f t h e s e two f o r m s o f a m b i g u i t y a r e shown i n t h e b o x e s l a b e l e d (b) a n d ( c ) i n f i g u r e 1.2. Two r u l e s a r e g i v e n i n c h a p t e r I I I w h i c h s e r v e a s a g u i d e t o t h e u s e r i n d e f i n i n g t h e a r e a b o u n d a r i e s . P F S p r o c e s s e s t h e u s e r d e f i n e d a r e a b o u n d a r i e s . I n p r o c e s s i n g t h e s e b o u n d a r i e s , t h e s y s t e m p e r f o r m s two p r i n c i p l e t a s k s . T h e s e a r e : ( i ) S m o o t h t h e u s e r d e f i n e d c u r v e s ( i i ) D i s c a r d r e d u n d a n t o r u n n e c e s s a r y p i x e l s , r e t a i n i n g o n l y t h o s e whose r e t e n t i o n i s v i t a l t o t h e p r e s e r v a t i o n o f t h e o r i g i n a l s h a p e o f t h e b o u n d a r y . B e c a u s e s m u d g e s a r e t r a v e r s e d a l o n g t h e i r o u t e r e d g e s , t h e i r p r o c e s s i n g i s d i r e c t i o n a l l y s e n s i t i v e . T h e a l g o r i t h m f o r p r o c e s s i n g s m u d g e s i s g i v e n i n c h a p t e r I V . T h e t r a v e r s a l o f t h e b o u n d a r y a l o n g i t s o u t e r e d g e p r e s e r v e s t h e e x a c t s h a p e o f t h e 6 b o u n d a r y a n d a l l o w s t h e u s e r t o p r e d i c t , w h i l e t r a c i n g t h e b o u n d a r y , t h e s h a p e o f t h e s y s t e m g e n e r a t e d b o u n d a r y . N e i t h e r o f t h e s e two b e n e f i t s w o u l d be d e r i v e d i f a smudge was p r o c e s s e d by p a s s i n g a n a v e r a g e c u r v e t h r o u g h i t . T h e s e q u e n c e o f p i x e l s w h i c h a r e r e t a i n e d f o r m a p o l y g o n , w h i c h p r e s e r v e s t h e s h a p e o f t h e e n t e r e d b o u n d a r y . A t t h i s s t a g e t h e p o l y g o n i s c l o s e d by p a s s i n g t h e p r e s e r v e d p o i n t s i n p a i r s t o a d i g i t a l d i f f e r e n t i a l a n a l y s e r (DDA) w h i c h s e t s p i x e l s i n a s t r a i g h t l i n e ( s e e c h a p t e r I V , s e c t i o n D) b e t w e e n t h e two p o i n t s p a s s e d t o i t . T h a t i s , i t c l o s e s o f f t h e p o l y g o n by j o i n i n g t h e p o i n t s a l o n g i t s p e r i m e t e r . T h e c l o s e d p o l y g o n i s p r e s e n t e d t o t h e u s e r f o r i n s p e c t i o n a n d i n t e r a c t i v e c o r r e c t i o n / m o d i f i c a t i o n . I n t h e e x a m p l e o f f i g u r e 1.2, no c o r r e c t i o n / m o d i f i c a t i o n o f t h e c l o s e d p o l y g o n s i s n e c e s s a r y . T h e a b o v e p r o c e s s i s e x e c u t e d f o r e a c h o f t h e u s e r d e f i n e d a r e a s . F i g u r e s 1.3 ( a - d ) show t h e c l o s e d p o l y g o n s i n t h i s r u n p r e s e n t e d one a t a t i m e t o t h e u s e r . A t t h i s s t a g e t h e u s e r i s i n v i t e d t o m o d i f y t h e p o l y g o n s a n d h a s t h e o p p o r t u n i t y t o l a b e l t h e m . I n t h i s r u n , a l a b e l was a d d e d f o r t h e o u t e r m o s t a r e a o n l y . ( a ) ( U CO Cd) F i g u r e 1.3 F i g u r e s ( a ) t h r o u g h ( d ) show t h e d i f f e r e n t c l o s e d p o l y g o n s a s p r e s e n t e d t o t h e u s e r f o r c o r r e c t i o n / m o d i f i c a t i o n . O n c e t h e u s e r d e f i n e d b o u n d a r i e s a r e p r o c e s s e d , t h e u s e r i s i n v i t e d t o e n t e r more a r e a b o u n d a r i e s . I n t h i s r u n t h e u s e r d e c l i n e d . 8 A t t h i s s t a g e P F S p r o c e e d s t o f i l l t h e b o u n d a r i e s . T h e a r e a s whose n e s t i n g d e p t h i s o d d a r e f i l l e d . T h e a r e a s whose n e s t i n g d e p t h i s e v e n a r e l e f t u n f i l l e d . F i g u r e 1.4 shows t h e f i l l e d a r e a s . OUTER FILLED F i g u r e 1.4 T h e a r e a s f i l l e d by P F S . O t h e r v a r i a t i o n s o f a r e a f i l l i n g c a n e a s i l y be i m p l e m e n t e d . E x a m p l e s o f s u c h v a r i a t i o n s a r e : f i l l a r e a s whose n e s t i n g d e p t h i s e v e n , f i l l t h e e n t i r e o u t e r a r e a . T h e a l g o r i t h m w h i c h f i l l s t h e c l o s e d p o l y g o n s i s d e s c r i b e d i n c h a p t e r I V . I n f i l l i n g a r e a s , p r o b l e m s a r i s e i f a c l o s e d p o l y g o n c o n t a i n s a s i n g l e c o l u m n o f p i x e l s . A c o l u m n o f t h i s s o r t i s r e f e r e d t o a s a t a i l . I f a t a i l i s l e f t u n c h e c k e d , t h e f i l l i n g a l g o r i t h m w i l l t u r n t h e p o l y g o n i n s i d e o u t . A d i s c u s s i o n o f t a i l s a p p e a r s i n c h a p t e r I V . 9 C. I s s u e s T h i s t h e s i s a d d r e s s e s t h r e e m a j o r t e c h n i c a l i s s u e s . T h e s e a r e : ( i ) t h e c o n n e c t i v i t y o f b o u n d a r i e s r e s u l t i n g f r o m u n e v e n d a t a e n t r y ( s e e f i g u r e 1.2 a b o v e ) . T h i s i n v o l v e s t h e f o l l o w i n g t h r e e t a s k s : ( a ) d i f f e r e n t i a t i n g b e t w e e n b o u n d a r i e s (b) t h e r e t e n t i o n o f t h o s e p o i n t s w h i c h a r e v i t a l i n m a i n t a i n i n g t h e o r i g i n a l s h a p e o f t h e b o u n d a r y ( c ) t h e s e a r c h i n g o f a two d i m e n s i o n a l m a t r i x f o r a p i x e l ' s n e a r e s t n e i g h b o u r . ( i i ) t h e c l o s u r e o f t h e p o l y g o n s w h i c h r e s u l t f r o m t h e r e t e n t i o n o f t h o s e p i x e l s r e t a i n e d by ( i ) ( b ) a b o v e ( i i i ) t h e f i l l i n g o f t h e c l o s e d p o l y g o n s r e s u l t i n g f r o m s t e p ( i i ) a b o v e . 10 Chapter I I ; Underlying Issues A. The Underlying Grid Model Two g r i d systems were considered for storage and manipulation of the screen data: (i) The square gri d i s a square array of elements. Each element has four adjacent or primary neighbours at a distance of unity from the element, as well as four vertex or secondary neighbours at a distance of 2 . The distances between a p i x e l and i t s eight neighbours are thus d i r e c t i o n a l l y s e n s i t i v e . Such a matrix creates l o g i c a l d i f f i c u l t i e s for the analysis of connectivity between pix e l s [DUDA73] (pp 284-285). Figure 2.1 Square gri d showing Assume, for example, represent set p i x e l s , set and unset p i x e l s . that the dots in figure 2.1 while those squares which are 11 l e f t b l a n k , r e p r e s e n t u n s e t p i x e l s . I f we l e t c o n n e c t i v i t y d e p e n d on f u l l a d j a c e n c y ( c o n n e c t e d p r i m a r y n e i g h b o u r s ) , t h e n t h e f i g u r e r e p r e s e n t s f o u r u n c o n n e c t e d o b j e c t s w h i c h e n c l o s e a h o l e . I f on t h e o t h e r h a n d , c o n n e c t i v i t y i s d e f i n e d by t h e a d j a c e n c y o f s e c o n d a r y n e i g h b o u r s , t h e n t h e f i g u r e r e p r e s e n t s o n e o b j e c t , b u t t h e h o l e i n t h e o b j e c t i s c o n n e c t e d t o t h e b a c k g r o u n d , ( i i ) I n t h e h e x a g o n a l g r i d , e a c h e l e m e n t h a s s i x n e i g h b o u r s , e a c h o f w h i c h i s t h e same d i s t a n c e f r o m t h e e l e m e n t . D i s t a n c e s b e t w e e n a p i x e l a n d i t s s i x i m m e d i a t e n e i g h b o u r s a r e t h u s n o t d i r e c t i o n a l l y s e n s i t i v e . A l l n e i g h b o u r s f a l l i n t o a s i n g l e c l a s s , t h a t o f p r i m a r y a d j a c e n c y . B e c a u s e o f t h i s c o n d i t i o n , no a m b i g u i t i e s a r i s e w i t h r e s p e c t t o t h e c o n c e p t o f c o n n e c t i v i t y . Two p i x e l s a r e c o n n e c t e d i f a n d o n l y i f t h e y s h a r e a common e d g e . F i g u r e 2.2 shows a s i n g l e o b j e c t w h i c h e n c l o s e s a h o l e . T h e h o l e i s n o t c o n n e c t e d t o t h e b a c k g r o u n d . Figure 2.2 Hexagonal g r i d showing single object enclosing a hole. A comparison between the square and hexagonal g r i d systems shows that with a square g r i d , connectivity i s inherently ambiguous, while connectivity presents no such ambiguity in a hexagonal system. The hexagonal g r i d i s more suited to connectivity related problems. However, i f the available hardware i s inherently square in nature, then preprocessing i s required to massage the data in order that the hexagonal system might be simulated. If alternate rows of a square g r i d are of f s e t by a distance of half a p i x e l , then the grid layout resembles, p i c t o r i a l l y , a brick wall. Each element of t h i s g r i d has exactly six equidistant neighbours, where a l l neighbours are f u l l y adjacent. This gr i d representation i s thus analagous to the hexagonal g r i d system. Figure 2.3 shows t h i s a l t e r e d representation of a square g r i d . 13 6 1 5 • 2 4 3 Figure 2.3 Square g r i d with alternate rows sh i f t e d half a p i x e l . The g r i d system shown in figure 2.3 i s an enticing approximation to the hexagonal g r i d . However, i f alternate rows of an e x i s t i n g square grid are simply o f f s e t by half a p i x e l , connectivity in the o r i g i n a l figure may not be retained. Additional preprocessing i s required to maintain t h i s connectivity. PFS i s highly i n t e r a c t i v e . This implies that t r a n s i t i o n s between g r i d systems would have to be done r e l a t i v e l y often. Therefore, despite a hexagonal gri d system's benefit with respect to connectivity, i t was decided that PFS be implemented using the square g r i d system because the COMTAL Vision One system's architecture i s inherently square in nature. This decision avoids the overheads- involved in converting the data back and forth between g r i d systems. Certain hardware has been designed that i s based on the hexagonal gri d system [GOLA69], 14 b u t b e c a u s e t h e a l g o r i t h m s i m p l e m e n t e d i n PFS a r e b a s e d on t h e s q u a r e g r i d , t h e y c o u l d n o t be e a s i l y t r a n s p o r t e d . 15 B. R a t i o n a l e o f a n H e u r i s t i c A p p r o a c h Two a p p r o a c h e s w e r e p o s s i b l e i n d e s i g n i n g P F S : ( i ) t h e s y s t e m c o u l d h a v e b e e n f o r m a l l y d e f i n e d i n m a t h e m a t i c a l t e r m s , a n d ( i i ) t h e s y s t e m c o u l d h a v e b e e n d e f i n e d h e u r i s t i c a l l y i n t e r m s o f c e r t a i n a s s u m p t i o n s a b o u t t h e a p p l i c a t i o n s f o r w h i c h t h e s y s t e m w o u l d be u s e d . B e c a u s e o f i m p e r f e c t i o n s i n t h e i n p u t d a t a t r a c e d by t h e u s e r , a s i n t r o d u c e d i n c h a p t e r I a n d e x p l a i n e d i n c h a p t e r I I I , i t i s n o t p o s s i b l e t o s t a t e t h e p r o b l e m ( m o d e l o f c o m p u t a t i o n ) i n f o r m a l t e r m s s u c h t h a t t h e r e w i l l a l w a y s e x i s t a s o l u t i o n w h i c h h a s t h e d e s i r e d r e s u l t . F o r t h i s r e a s o n , t h e s e c o n d a l t e r n a t i v e was c h o s e n . C e r t a i n a s s u m p t i o n s h a v e b e e n made a b o u t t h e t y p e s o f a p p l i c a t i o n s w h i c h m o t i v a t e d t h e d e v e l o p m e n t o f t h e s y s t e m . I t i s a s s u m e d t h a t t h e s y s t e m w i l l be u s e d f o r c a r t o g r a p h i c ( c o n t o u r f i l l i n g ) a n d image p r o c e s s i n g ( l a k e s , m o u n t a i n s , s h a d o w s ) a p p l i c a t i o n s . T he a s s u m p t i o n s made a b o u t t h e d a t a t r a c e d by t h e u s e r a r e e n u m e r a t e d i n c h a p t e r s I a n d I I I . T h e s e a s s u m p t i o n s g u a r a n t e e a h i g h d e g r e e o f a c c u r a c y a n d p r e d i c t a b i l i t y f o r t h e a b o v e m e n t i o n e d a p p l i c a t i o n s . T h i s t a i l o r i n g o f t h e s y s t e m t o w a r d s s p e c i f i c a p p l i c a t i o n s h o w e v e r , c a u s e s a l o s s o f g e n e r a l i t y . C e r t a i n a p p l i c a t i o n s , c h a r a c t e r r e c o g n i t i o n f o r e x a m p l e , a r e n o t c a t e r e d t o . C h a r a c t e r r e c o g n i t i o n o f t e n r e q u i r e s a n a v e r a g i n g o f smudge l i n e s [ S T E F 7 1 ] , r a t h e r t h a n t h e t r a v e r s a l o f smudges a l o n g t h e i r o u t e r e d g e s , a s a p r o c e s s i n g s t e p . 16 C h a p t e r I I I ; B o u n d a r y D e f i n i t i o n : A F u n c t i o n a l O v e r v i e w A. U s e r C o n s i d e r a t i o n s T h e a l g o r i t h m w h i c h p r o c e s s e s t h e b o u n d a r i e s makes u s e o f s p a t i a l k n o w l e d g e i n d e t e r m i n i n g t h e c o n n e c t i v i t y o f t h e b o u n d a r y . I n o r d e r t o a c h i e v e t h e d e s i r e d r e s u l t , t h e u s e r must f o l l o w two r u l e s d i s c u s s e d b e l o w . I n t h e d i s c u s s i o n o f u s e r r u l e s , r e f e r e n c e t o t h e o r d e r i n g o f p i x e l s r e f e r s t o t h e o r d e r i n w h i c h t h e p i x e l s were s e t i n t i m e . R u l e 1: On a n y g i v e n b o u n d a r y , t h e ( n + l ) s t p i x e l must be c l o s e r ( i n s p a c e ) t o t h e n t h p i x e l t h a n i s t h e ( n + k ) t h p i x e l , f o r k>=2. F a i l u r e t o c o m p l y w i t h t h i s r u l e w i l l r e s u l t i n t h e i n c o r r e c t b o u n d a r y b e i n g g e n e r a t e d . F i g u r e s 3.1 ( a ) a n d ( b ) i l l u s t r a t e a n e x a m p l e o f what m i g h t o c c u r . H ( n + l ) s t p i x e l ( n + k ) t h p i x e l F i g u r e 3.1a T h e ( n + l ) s t p i x e l i s c l o s e r ( i n s p a c e ) t o t h e n t h p i x e l t h a n i s t h e ( n + k ) t h f o r k>=2. T h e d o t s 17 r e p r e s e n t t h e p i x e l s s e t by t h e movement o f t h e t r a c k b a l l . T h e s o l i d l i n e i n d i c a t e s t h e d e s i r e d b o u n d a r y , w h i l e t h e d a s h e d l i n e r e p r e s e n t s t h e b o u n d a r y g e n e r a t e d b y P F S . I n t h i s f i g u r e t h e c o r r e c t b o u n d a r y i s g e n e r a t e d . < / N ( n + k ) t h p i x e l F i g u r e 3.1b T h e r e e x i s t s a k f o r w h i c h t h e ( n + k ) t h p i x e l i s c l o s e r ( i n s p a c e ) t o t h e n t h p i x e l t h a n i s t h e ( n + l ) s t a n d k>=2. T h e d o t s r e p r e s e n t t h e p i x e l s s e t by t h e movement o f t h e t r a c k b a l l . T h e s o l i d l i n e i n d i c a t e s t h e d e s i r e d b o u n d a r y , w h i l e t h e d a s h e d l i n e r e p r e s e n t s t h e b o u n d a r y g e n e r a t e d by P F S . I n t h i s f i g u r e i n c o r r e c t b o u n d a r i e s a r e g e n e r a t e d . F i g u r e 3 . 1 a , w h i c h a d h e r e s t o r u l e 1 s t i p u l a t e d a b o v e , a c h i e v e s t h e d e s i r e d r e s u l t , w h i l e f i g u r e 3.1b, w h i c h b r e a k s t h i s r u l e , r e s u l t s i n t h e g e n e r a t i o n o f two b o u n d a r i e s a n d h e n c e two a r e a s i n s t e a d o f o n e . I n f i g u r e 3.1b s p a c i a l c o n n e c t i v i t y 18 d o e s n o t c o r r e s p o n d t o t e m p o r a l c o n n e c t i v i t y . R u l e 2: A n y p i x e l b e l o n g i n g t o a b o u n d a r y must be c l o s e r t o n e i g h b o u r s on i t s c u r v e t h a n t o a n y p i x e l f r o m a n e i g h b o u r i n g c u r v e . T h i s r u l e i s c o n s i s t e n t w i t h r u l e 1. I t s t i p u l a t e s t h a t r u l e 1 a p p l i e s t o p i x e l s f r o m d i f f e r e n t c u r v e s a s w e l l a s t o t h o s e a l o n g t h e same c u r v e . A b r e a c h o f r u l e 2 h a s s l i g h t l y d i f f e r e n t r e s u l t s f r o m t h o s e shown i n f i g u r e s 3.1 ( a ) a n d ( b ) . I n t h e c a s e o f a s i n g l e b o u n d a r y c u r v e , t h e t e n d e n c y i s t o g e n e r a t e more t h a n o n e a r e a , w h e r e a s d i s o b e y i n g r u l e 2 t e n d s t o d e c r e a s e t h e number o f a r e a s , a s i n d i c a t e d i n f i g u r e 3.2. n t h p i x e l F i g u r e 3.2 T h i s f i g u r e i n d i c a t e s a b r e a c h o f r u l e 2. T h e d o t s r e p r e s e n t t h e p i x e l s w h i c h h a v e b e e n s e t . T h e s o l i d l i n e s show t h e two d e s i r e d b o u n d a r i e s , w h i l e t h e d a s h e d l i n e i n d i c a t e s t h e s i n g l e b o u n d a r y w h i c h h a s b e e n g e n e r a t e d . 19 I f t e m p o r a l k n o w l e d g e was a v a i l a b l e t o t h e s y s t e m , t h e p r o b l e m s h i g h l i g h t e d i n f i g u r e s 3.1 ( a ) a n d (b) a n d 3.2 w o u l d be e a s i e r t o r e s o l v e . T h e s o l u t i o n t o o t h e r p r o b l e m s , s u c h a s s m u d g e s , w o u l d n o t , h o w e v e r , be f a c i l i t a t e d by k n o w l e d g e o f t h e t e m p o r a l o r d e r o f c u r v e g e n e r a t i o n . PFS c l o s e s a l l b o u n d a r i e s i n a s t r a i g h t l i n e f r o m t h e l a s t p i x e l o f t h e p a r t i c u l a r b o u n d a r y t o t h e f i r s t p i x e l o f t h a t b o u n d a r y . F i g u r e s 3.3 ( a ) a n d (b) i l l u s t r a t e a n e x a g g e r a t e d c a s e . F i g u r e 3.3a I l l u s t r a t i o n o f a b o u n d a r y b e i n g c l o s e d f r o m i t s l a s t t o i t s f i r s t p o i n t s . 20 F i g u r e 3.3b I l l u s t r a t i o n o f what w o u l d o c c u r i f a p i x e l on b o u n d a r y B w e r e c l o s e r t o t h e l a s t p i x e l f r o m b o u n d a r y A t h a n was t h e f i r s t . I n f i g u r e 3.3a, t h e b o u n d a r y f o r a r e a A was s u c c e s s f u l l y c l o s e d b e c a u s e t h e l a s t p i x e l f o r t h i s a r e a was c l o s e r t o i t s f i r s t p i x e l t h a n i t was t o t h e c l o s e s t p i x e l i n b o u n d a r y B. F i g u r e 3.3b shows what w o u l d h a v e r e s u l t e d i f t h i s w e r e n o t t h e c a s e . I f t h e u s e r o b e y s r u l e 2, t h e n b o u n d a r y d i s t i n c t n e s s w i l l be p r e s e r v e d . A t a s u b s e q u e n t s t a g e o f t h e p r o c e s s i n g , a n y a r e a whose s i z e i s z e r o , a s t r a i g h t l i n e f o r e x a m p l e , w i l l be d e l e t e d f r o m t h e s y s t e m . S u c h a n a r e a w o u l d r e s u l t i f t h e u s e r i n p u t a s e r i e s o f p o i n t s w h i c h w e r e c o l i n e a r , t h e f i r s t p o i n t o f w h i c h was c l o s e r t o t h e l a s t t h a n t h a t f r o m a n y o t h e r b o u n d a r y . 21 B. B o u n d a r y P r o c e s s i n g T h e i n i t i a l t a s k o f t h e s y s t e m i s t o d i s t i n g u i s h b e t w e e n t h e d i f f e r e n t a r e a b o u n d a r i e s i n p u t by t h e u s e r . E a c h b o u n d a r y i s p r o c e s s e d s e p a r a t e l y . T h e o r d e r i n w h i c h t h i s p r o c e s s i n g i s e x e c u t e d i s e s t a b l i s h e d by t h e p o s i t i o n s o f t h e h i g h e s t ( o n t h e d i s p l a y s c r e e n ) p i x e l o f e a c h b o u n d a r y . T h e b o u n d a r y whose h i g h e s t p i x e l i s h i g h e s t on t h e s c r e e n w i l l be p r o c e s s e d f i r s t . T h a t whose h i g h e s t p i x e l i s s e c o n d h i g h e s t on t h e s c r e e n w i l l be p r o c e s s e d s e c o n d a n d s o o n . I n t h e e v e n t o f a t i e , t h e l e f t m o s t b o u n d a r y w i l l be p r o c e s s e d f i r s t . B o u n d a r i e s a r e p r o c e s s e d i n a c l o c k w i s e d i r e c t i o n . PFS a s s u m e s t h a t t h e h i g h e s t p i x e l f o r a p a r t i c u l a r b o u n d a r y i s t h e f i r s t p i x e l f o r t h a t b o u n d a r y . T h e n e x t p i x e l i n t h e c l o c k w i s e d i r e c t i o n i s r e g a r d e d a s t h e s e c o n d p i x e l i n t i m e . T h e a r e a ' s b o u n d a r y i s t r a v e r s e d i n a c l o c k w i s e d i r e c t i o n . T h e r e i s , o f c o u r s e , no r e q u i r e m e n t t h a t t h e u s e r a c t u a l l y t r a c e t h e b o u n d a r y i n a c l o c k w i s e d i r e c t i o n . T h e s y s t e m w i l l o p e r a t e , h o w e v e r , a s i f t h e u s e r h a s t r a c e d t h e b o u n d a r y i n a c l o c k w i s e d i r e c t i o n , i n a c c o r d a n c e w i t h r u l e 1 a b o v e , s t a r t i n g a t t h e h i g h e s t p o i n t . I n d e r i v i n g t h e i n d i v i d u a l b o u n d a r y , i t i s e s s e n t i a l t h a t t h e b a s i c s h a p e i n p u t by t h e u s e r be r e t a i n e d . I n s o d o i n g , i t i s a l s o d e s i r e a b l e t o r e t a i n o n l y e s s e n t i a l p o i n t s a l o n g t h e b o u n d a r y . T h i s s e l e c t i o n o f e s s e n t i a l p o i n t s i s c o n d u c t e d a c c o r d i n g t o two r u l e s : ( i ) F o r a n y s e q u e n c e o f n>2 c o l i n e a r p o i n t s i n t h e d i r e c t i o n o f e i t h e r o f t h e c a r t e s i a n a x e s , a l l p o i n t s 22 e x c e p t t h e 1st a n d t h e n t h a r e d i s c a r d e d . T h e 1st a n d n t h a r e r e t a i n e d a s b e i n g e s s e n t i a l i n p r e s e r v i n g t h e d e s i r e d s h a p e o f t h e b o u n d a r y . F o r a n e x a m p l e s e e f i g u r e 3.4. ++ + + + b l a n k s F i g u r e 3.4 I n t h i s e x a m p l e , t h e p i x e l s m a r k e d w i t h a p l u s s i g n a r e r e t a i n e d , w h i l e t h o s e i n d i c a t e d by a d o t a r e d i s c a r d e d . B e c a u s e no e r r o r m a r g i n i s a l l o w e d by t h e s y s t e m , t h e p o i n t s m u s t be s t r i c t l y c o l i n e a r . D i r e c t i o n s o t h e r t h a n t h o s e o f t h e c a r t e s i a n a x e s h a v e n o t b e e n c o n s i d e r e d . L i n e s i n t h e d i a g o n a l d i r e c t i o n s a r e d i f f i c u l t t o g e n e r a t e w i t h t h e a v a i l a b l e i n p u t d e v i c e . A t r a c k b a l l i s s e n s i t i v e b o t h t o t h e s h a k i n g o f t h e u s e r s h a n d a n d t o t h e s l i p p i n g a n d s t i c k i n g c a u s e d by i t s own i n t e r n a l f r i c t i o n . A s a r e s u l t , i t i s a l m o s t i m p o s s i b l e f o r t h e u s e r t o t r a c e a n e n t i r e b o u n d a r y w h i c h i s t h i n . A t h i n l i n e i s o n e whose w i d t h i s a t m o s t on e p i x e l . Any l i n e w h i c h i s n o t t h i n i s 23 r e g a r d e d a s a smudge. ( i i ) A smudge i s p r o c e s s e d b y t r a v e r s i n g a l o n g i t s o u t e r e d g e a n d d i s c a r d i n g a l l t h e o t h e r p i x e l s w h i c h make u p t h e smudge. An e x a m p l e o f smudge p r o c e s s i n g i s g i v e n i n f i g u r e 3.5. + • • + d i r e c t i o n o f t r a v e r s a l + + + • • + + F i g u r e 3.5 I n t h e a b o v e f i g u r e , t h e p i x e l s shown w i t h a p l u s a r e r e t a i n e d w h i l e t h o s e shown w i t h a d o t a r e d i s c a r d e d . 24 Chapter IV: Implementation Figure 4.1 indicates the o v e r a l l flow of control in PFS. This chapter describes the data structures used and the algorithms implemented at each stage in PFS. Enter areas on display device Program reads data from display device l Smooth curve * Es t a b l i s h data in data structure Find next boundary Close boundary Check for t a i l s Display polygon NO f l s polygon d i s t i n c t ? ^ YES^ Redefine appropriate section If any t a i l s , get r i d of t a i l s E NO f^More boundaries?^ YES I' i ... i. . ,.,[ Define new boundaries on screen YES fEnter more boundaries?^ NO F i l l picture * Display picture Stop Figure 4.1 Diagram showing o v e r a l l flow of control in PFS. 25 A. Curve Smoothing Curve smoothing i s performed by a simple expansion and contraction of the p i x e l matrix representing the display screen. The system does not prevent user defined boundaries from accidently being joined together. It i s the user's r e s p o n s i b i l i t y to ensure that the pixels from each boundary are at least three pi x e l s distant from the pi x e l s of any other boundary. This distance allows for one expansion of the matrix. Implicit in t h i s single expansion and contraction of the matrix i s that holes or gaps, two pixels wide w i l l be closed. In examining the algorithms which perform expansion and contraction, i t should be born in mind that the system operates on a square g r i d system. Each gri d position i s considered to have exactly eight neighbours, as shown in figure 4.2. 8 1 2 7 • 3 6 5 4 Figure 4.2 Each element in a square g r i d has eight neighbours. In order that no special cases a r i s e , the matrix has a border of 26 e x t r a p i x e l s ( w h i c h a r e i n i t i a l i z e d t o z e r o ) a r o u n d i t . The a l g o r i t h m s f o r e x p a n s i o n a n d c o n t r a c t i o n a r e d i s c u s s e d b e l o w : 1. E x p a n s i o n a n d C o n t r a c t i o n : E x p a n s i o n i s a c h i e v e d by s e t t i n g e a c h p i x e l w h i c h h a s one o r more o f i t s e i g h t n e i g h b o u r s s e t . Any p i x e l w h i c h was o r i g i n a l l y s e t r e m a i n s s e t . E x p a n s i o n i s e q u i v a l e n t t o t h e l o g i c a l i n c l u s i v e OR o f e a c h p i x e l a n d i t s e i g h t n e i g h b o u r s [ G O L A 6 9 ] . C o n t r a c t i o n i s a c h i e v e d by s e t t i n g e a c h p i x e l , w h i c h i s a l r e a d y s e t a n d w h i c h h a s a l l e i g h t n e i g h b o u r s s e t . C o n t r a c t i o n i s e q u i v a l e n t t o t h e l o g i c a l AND o f e a c h p i x e l a n d i t s e i g h t n e i g h b o u r s [ G O L A 6 9 ] . E x p a n s i o n a n d c o n t r a c t i o n c a n be e x e c u t e d e i t h e r i n s e q u e n c e o r i n p a r a l l e l . A s e q u e n t i a l i m p l e m e n t a t i o n , w i t h o u t c o p y i n g , w o u l d c a u s e t h e r e s u l t s a t s t e p n t o i n f l u e n c e t h e r e s u l t s a t s t e p n+1. A p a r a l l e l i m p l e m e n t a t i o n o f t h e a l g o r i t h m w o u l d r e q u i r e e v e r y p o s i t i o n i n t h e m a t r i x t o be e x a m i n e d s i m u l t a n e o u s l y a n d a n y m o d i f i c a t i o n s t o t h e m a t r i x t o be made s i m u l t a n e o u s l y . I n a p a r a l l e l i m p l e m e n t a t i o n , t h e p r o b l e m s e n c o u n t e r e d i n s e q u e n t i a l p r o c e s s i n g do n o t a r i s e , b u t t h e s i m u l t a n e o u s p r o c e s s i n g o f a m a t r i x o f a l a r g e s i z e c a n n o t be a c h i e v e d s i m p l y o r c h e a p l y on h a r d w a r e t h a t i s e s s e n t i a l l y s e q u e n t i a l i n n a t u r e . 27 T r u e p a r a l l e l i s m c a n be i m p l e m e n t e d i n t h r e e w a y s : ( i ) T h e h a r d w a r e i s t r u l y p a r a l l e l . T r u e p a r a l l e l i s m i n h a r d w a r e means t h a t a l l p i x e l s i n t h e m a t r i x a r e e x a m i n e d a n d m o d i f i e d s i m u l t a n e o u s l y . ( i i ) T r u e p a r a l l e l i s m c a n be s i m u l a t e d by p r o c e s s i n g t h e m a t r i x r e c u r s i v e l y ( s e e A p p e n d i x B ) . B u t , a m a t r i x o f r e s o l u t i o n N x N p i x e l s w o u l d r e q u i r e t h a t t h e s y s t e m r e c u r s e t o a d e p t h o f N 2 . T h i s r e q u i r e s an e x c e s s i v e amount o f s t a c k memory. Few o p e r a t i n g s y s t e m s w o u l d make t h i s m e t h o d p r a c t i c a l l y f e a s i b l e . ( i i i ) T r u e p a r a l l e l i s m c a n be s i m u l a t e d by c r e a t i n g a s e c o n d ( t e m p o r a r y ) m a t r i x , e q u a l i n e v e r y r e s p e c t t o t h e m a t r i x c u r r e n t l y b e i n g p r o c e s s e d . T h i s s e c o n d m a t r i x i s i n i t i a l i z e d t o z e r o p r i o r t o t h e commencement o f t h e p r o c e s s i n g . T h i s m e t h o d l e a v e s t h e o r i g i n a l m a t r i x i n t a c t a n d s i m p l y s e t s t h e r e l e v a n t p i x e l s i n t h e s e c o n d m a t r i x . H e n c e , t h e p r o b l e m s o f s e q u e n t i a l p r o c e s s i n g do n o t a r i s e . I n P F S , m e t h o d ( i i i ) a b o v e i s i m p l e m e n t e d . T h e c o s t o f t h i s m e t h o d i s t h e e x t r a memory r e q u i r e d f o r t h e new m a t r i x . T h e two r e q u i r e d t w o - d i m e n s i o n a l m a t r i c e s a r e r e p r e s e n t e d a s a s i n g l e t h r e e - d i m e n s i o n a l m a t r i x w h i c h h a s a f r o n t a n d b a c k p l a n e . E a c h p l a n e c o n t a i n s a s i n g l e t w o - d i m e n s i o n m a t r i x . T h e number o f e x p a n s i o n s / c o n t r a c t i o n s i s c o n t r o l l e d by t h e c o n s t a n t C a t t h e h e a d o f t h e p r o g r a m ( s e e A p p e n d i x A ) . T h i s p a r a m e t e r a l s o c o n t r o l s t h e s i z e o f t h e b o r d e r a r o u n d t h e m a t r i c e s . 28 B. E s t a b l i s h d a t a A f t e r t h e raw d a t a h a s b e e n s m o o t h e d , t h e p i x e l m a t r i x i s r e p r e s e n t e d by a new d a t a s t r u c t u r e , w h i c h s e r v e s a s an o r d e r e d i n d e x t o t h e p i x e l m a t r i x . T h e p u r p o s e o f t h i s i n d e x i s t o f a c i l i t a t e t h e s e a r c h i n g o f t h e m a t r i x f o r a p i x e l ' s c l o s e s t n e i g h b o u r ( n o t n e c e s s a r i l y i m m e d i a t e ) . An e f f i c i e n t s e a r c h r e q u i r e s o n l y s e t p i x e l s t o be e x a m i n e d . T h e i n d e x , t h u s s e r v e s a s a n o r d e r e d p o i n t e r t o s e t p i x e l s i n t h e m a t r i x . T h e p o s i t i o n s o f t h e p i x e l s p o i n t e d t o by t h e i n d e x a r e s o r t e d b o t h i n t h e x d i r e c t i o n ( b y c o l u m n ) a n d i n t h e y d i r e c t i o n ( b y r o w ) . B e c a u s e t h e l o c a t i o n s a r e s o r t e d , t h e y c a n be e f f i c i e n t l y l o c a t e d u s i n g b i n a r y s e a r c h . T h i s d a t a s t r u c t u r e w i l l h e n c e f o r t h be r e f e r e d t o a s t h e ' i n d e x ' . T h e i n d e x i s a n a r r a y o f r e c o r d s , t h e number o f w h i c h i s e q u a l t o t h e x r e s o l u t i o n o f t h e COMTAL s c r e e n . T h e i n d e x t h u s h a s one e l e m e n t f o r e a c h c o l u m n o f t h e s c r e e n . E a c h e l e m e n t o f t h e i n d e x i s a r e c o r d whose c o n t e n t s a r e l i s t e d b e l o w : ( i ) t h e number o f p i x e l s i n t h a t c o l u m n ( i i ) t h e h i g h e s t row i n t h a t c o l u m n i n w h i c h a p i x e l a p p e a r s ( i i i ) t h e l o w e s t row i n t h a t c o l u m n i n w h i c h a p i x e l a p p e a r s ( i v ) an a r r a y o f p o i n t e r s e a c h o f w h i c h p o i n t s t o an a r r a y o f i n t e g e r s . [ t h e s i z e o f b o t h o f t h e s e a r r a y s i s d e t e r m i n e d by t h e y r e s o l u t i o n o f t h e s c r e e n . T h e e x p r e s s i o n ( ( y r e s o l u t i o n ) D I V 16) y i e l d s t h e s i z e o f 29 t h e a r r a y s . T h i s a s s u m e s t h a t t h e y r e s o l u t i o n i s a m u l t i p l e o f 16. I f i t i s n o t , t h e n o n e e x t r a p o i n t e r must be a d d e d t o t h e p o i n t e r s a r r a y ] . T h e P a s c a l d e c l a r a t i o n s w h i c h y i e l d t h i s d a t a s t r u c t u r e a r e g i v e n i n f i g u r e 4.3. CONST p t r s _ l i m i t = y _ r e s o l u t i o n D I V 16; y _ r e s _ d i v _ 1 6 = y _ r e s o l u t i o n D I V 16; T Y P E y _ b l o c k = A R R A Y ( . 1 . . y _ r e s _ d i v _ 1 6 . ) OF i n t e g e r ; { Y _ b l o c k c o n t a i n s t h e ro w s w h i c h c o n t a i n p i x i e s } p t r = @ y _ b l o c k ; i n d e x _ e l e m e n t = RECORD no, {no o f p i x e l s i n c o l } y _ m i n , { h i g h e s t p i x e l i n c o l } y_max : i n t e g e r ; { l o w e s t p i x e l i n c o l } p t r s : A R R A Y ( . 1 . . p t r s _ l i m i t . ) OF p t r ; END; VAR i n d e x : A R R A Y ( . 1 . . x _ r e s o l u t i o n . ) OF i n d e x _ e l e m e n t ; F i g u r e 4.3 T h e P a s c a l d e c l a r a t i o n s y i e l d i n g t h e i n d e x ' s d a t a s t r u c t u r e . 3 0 The graphical representation of the index_element record i s given in figure 4.4. number y_ max y_ mm Figure 4.4 The physical representation of the index_element record. The values entered into the y_block, pointed to by the index_element record, are the row positions of the pix e l s within each column of the matrix. A new array i s created dynamically when the previous array created for that column i s f u l l , or i f the point being processed i s the f i r s t point encountered in that column. The maximum number of wasted integer storage locations for any single column i s thus ((y resolution) DIV 16) - 1. If the integer arrays were not created dynamically, the maximum number of wasted integer storage locations for any one column would be equal to the y resolution of the display screen. This s i t u a t i o n would occur i f there were no pix e l s in that p a r t i c u l a r column. 31 P r i o r t o d a t a b e i n g e n t e r e d i n t o t h e y _ b l o c k , e a c h i n d e x _ e l e m e n t r e c o r d i s i n i t i a l i z e d a s f o l l o w s : ( i ) t h e number o f p i x e l s i n t h e c o l u m n i s s e t t o z e r o ( i i ) t h e h i g h e s t p i x e l i n t h e c o l u m n i s s e t t o t h e s y s t e m s maximum i n t e g e r v a l u e ( m a x i n t ) ( i i i ) t h e l o w e s t p i x e l i n t h e c o l u m n i s s e t t o t h e s y s t e m s minimum i n t e g e r v a l u e ( - m a x i n t ) ( i v ) a l l p o i n t e r s i n t h e ' p t r s ' a r r a y a r e s e t t o n i l . T h e d a t a i s e n t e r e d i n t o t h e i n d e x i n a c c o r d a n c e w i t h t h e f o l l o w i n g a l g o r i t h m : T h e p i x e l m a t r i x i s s c a n n e d i n row o r d e r . T h i s i s e q u i v a l e n t t o s c a n n i n g t h e r o w s o f t h e d i s p l a y s c r e e n f r o m t h e t o p l e f t h a n d c o r n e r t o t h e b o t t o m r i g h t h a n d c o r n e r . When a p i x e l i s e n c o u n t e r e d , t h e r e c o r d , w i t h i n t h e i n d e x a r r a y , p e r t a i n i n g t o t h e c o l u m n i n w h i c h t h e p i x e l was f o u n d , i s a c c e s s e d . T h e c o u n t o f p i x e l s f o r t h a t c o l u m n i s i n c r e m e n t e d . T h e row number i n w h i c h t h e p i x e l i s l o c a t e d i s c o m p a r e d w i t h t h e y _ m i n ( h i g h e s t row f o r a p i x e l ) a n d y_max ( l o w e s t row f o r a p i x e l ) , a n d i f n e c e s s a r y , one o f t h e s e v a r i a b l e s i s m o d i f i e d . T h e s e maximum a n d minimum v a l u e s a r e u s e d i n c o m p u t i n g a p i x e l ' s c l o s e s t n e i g h b o u r . T h e row number i s t h e n e n t e r e d i n t o t h e n e x t a v a i l a b l e s p a c e i n t h e y _ b l o c k . I f no s p a c e i s a v a i l a b l e , o r t h i s i s t h e f i r s t p i x e l e n c o u n t e r e d i n t h i s c o l u m n , t h e n a new y _ b l o c k i s d y n a m i c a l l y c r e a t e d , t h e n e x t a v a i l a b l e p o i n t e r i n t h e ' p t r s ' a r r a y i s s e t t o p o i n t t o t h e new y _ b l o c k a n d 3 2 t h e row number i s e n t e r e d i n t o t h i s new y _ b l o c k . B e c a u s e t h e m a t r i x i s s c a n n e d i n row o r d e r , t h e row v a l u e s s t o r e d i n t h e y _ b l o c k s p e r t a i n i n g t o e a c h c o l u m n a r e s o r t e d i n a s c e n d i n g row o r d e r . When t h e w h o l e p i x e l m a t r i x h a s b e e n s c a n n e d , t h e f i e l d y i e l d i n g t h e number o f p i x e l s p e r c o l u m n o f t h e i n d e x a r r a y i s s c a n n e d a n d two v a r i a b l e s a r e s e t e q u a l t o t h e f i r s t a n d l a s t c o l u m n s i n w h i c h a s e t p i x e l o c c u r s . C. P r o c e s s boundary The b a s i c a l g o r i t h m f o r p r o c e s s i n g the boundary i s g i v e n f i g u r e 4 . 5 . F i n d f i r s t p o i n t C u r r e n t p o i n t := f i r s t p o i n t C l e a r the smudge F i n d c l o s e s t p o i n t t o c u r r e n t p o i n t Make next p o i n t e q u a l t o t h i s p o i n t I C l e a r the smudge YES £ I s the next point equalN to the f i r s t point? NO D e l e t e next p o i n t from system R e t a i n next p o i n t C l e a r up remainder of smudges u s i n g back p l a n e of p i x e l m a t r i x D e l e t e c u r r e n t p o i n t from system C o n t i n u e C u r r e n t p o i n t := next p o i n t F i g u r e 4 . 5 T h i s f i g u r e shows the f l o w of c o n t r o l p r o c e s s i n g a boundary. 34 T h e a l g o r i t h m s f o r p r o c e s s i n g a b o u n d a r y a r e d e s c r i b e d b e l o w : 1. Smudge P r o c e s s i n g A smudge i s d e f i n e d t o be a c o n t i g u o u s r e g i o n o f p i x e l s w h i c h i s g r e a t e r t h a n one p i x e l i n w i d t h . Smudges a r e p r o c e s s e d by t r a v e r s i n g t h e i r o u t e r e d g e s a n d d i s c a r d i n g a l l i n t e r n a l p i x e l s . T h e o u t e r e d g e i s d e t e r m i n e d by t h e d i r e c t i o n i n w h i c h t h e t r a v e r s a l i s p r o g r e s s i n g . B e c a u s e t h e b o u n d a r y a s a w h o l e i s t r a v e r s e d i n a c l o c k w i s e d i r e c t i o n , t h e o u t e r e d g e i s t o t h e l e f t o f t h e l i n e o f t r a v e r s a l . I n p r o c e s s i n g s m u d g e s , t h e s y s t e m n o t o n l y c l e a r s t h e s m u d g e s , b u t a l s o d e t e r m i n e s a n d p r o c e s s e s s t r a i g h t l i n e s e g m e n t s w h i c h l i e i n a d i r e c t i o n o f one o f t h e c a r t e s i a n a x e s . T h e p r o c e d u r e w h i c h p r o c e s s e s smudges i s p a s s e d two p a r a m e t e r s . T h e f i r s t i s t h e l a s t p o i n t w h i c h t h e s y s t e m r e t a i n e d a s b e i n g v i t a l t o t h e p r e s e r v a t i o n o f t h e s h a p e o f t h e b o u n d a r y . T h i s p o i n t i s r e f e r e d t o a s t h e c u r r e n t p o i n t . T h e s e c o n d p a r a m e t e r i s t h e p o i n t w h i c h h a s b e e n f o u n d t o be t h e c l o s e s t p o i n t t o t h e c u r r e n t p o i n t . T h i s p o i n t i s r e f e r e d t o a s t h e n e x t p o i n t . T h e n e x t p o i n t may be c h a n g e d by t h i s p r o c e d u r e i f i t i s d e c i d e d t h a t i t s r e t e n t i o n w o u l d be r e d u n d a n t i n p r e s e r v i n g t h e s h a p e o f t h e b o u n d a r y c u r v e . B e c a u s e t h e s y s t e m u s e s a s q u a r e g r i d s y s t e m , t h e n e x t p o i n t c a n l i e a l o n g a n y one o f e i g h t d i r e c t i o n s t o t h e c u r r e n t p o i n t . T h e n e x t p o i n t n e e d n o t be a n e i g h b o u r o f t h e c u r r e n t p o i n t . T h e s e d i r e c t i o n s a r e 35 shown i n f i g u r e 4.6. N t S F i g u r e 4.6 The p o s s i b l e d i r e c t i o n s i n which the next p o i n t may l i e r e l a t i v e t o t h e c u r r e n t p o i n t . I f the next p o i n t l i e s i n one of the q u a d r a n t s , r a t h e r than i n the d i r e c t i o n of a c a r t e s i a n a x i s , then the d i r e c t i o n of the next p o i n t , r e l a t i v e t o the c u r r e n t p o i n t , i s t h a t of the d i a g o n a l a s s o c i a t e d w i t h the q u a d r a n t . The r e l a t i o n s h i p between d i r e c t i o n of t r a v e r s a l and the t r a v e r s e d o u t e r edge of t h e smudge i s d i c t a t e d by t h e o v e r a l l c l o c k w i s e d i r e c t i o n of t r a v e r s a l of the boundary. T a b l e 4.1 g i v e s t h i s r e l a t i o n s h i p i n t a b l e form. 36 D i r e c t i o n Smudge o u t e r e d g e t o be t r a v e r s e d N o r t h N o r t h e a s t N o r t h w e s t S o u t h S o u t h e a s t S o u t h w e s t E a s t West L e f t - m o s t ( w e s t ) L e f t - m o s t ( w e s t ) L e f t - m o s t ( w e s t ) R i g h t - m o s t ( e a s t ) R i g h t - m o s t ( e a s t ) R i g h t - m o s t ( e a s t ) T o p - m o s t ( n o r t h ) B o t t o m - m o s t ( s o u t h ) T a b l e 4.1 T a b l e g i v i n g r e l a t i o n s h i p b e t w e e n d i r e c t i o n o f t r a v e r s a l a n d t h e smudge o u t e r e d g e t o be t r a v e r s e d . F i g u r e 4.7 shows a n o c t a g o n , - a l l o f whose e d g e s a r e smudges. T h e f i g u r e i l l u s t r a t e s t h e e d g e t r a v e r s a l i n a c c o r d a n c e w i t h t h e r e l a t i o n s h i p s e s t a b l i s h e d i n t a b l e 4.1. \^ c l o c k w i s e t r a v e r s a l ^ e d g e t r a v e r s e d e d g e n o t t r a v e r s e d F i g u r e 4.7 T r a v e r s a l o f a n o c t a g o n , a l l o f whose e d g e s a r e s m u d g e s . A smudge may t a k e one o f t h r e e f o r m s : ( i ) T h e smudge i s a t h i c k ( w i d t h i s g r e a t e r t h a n o n e p i x e l ) l i n e , t h e o u t e r e d g e o f w h i c h i s s t r a i g h t a n d i n t h e d i r e c t i o n o f one o f t h e c a r t e s i a n a x e s . 3 7 F i g u r e 4.8 i l l u s t r a t e s s u c h a smudge. d i r e c t i o n o f t r a v e r s a l 4> o u t e r e d g e 4< F i g u r e 4.8 Smudge w h i c h c o m p r i s e s a t h i c k l i n e w i t h s t r a i g h t o u t e r e d g e i n l i n e w i t h a c a r t e s i a n a x i s . ( i i ) T h e smudge i s a g r o u p o f a d j a c e n t p i x e l s o n e o f w h i c h i s a d j a c e n t t o a n d on t h e i n s i d e o f a r e f l e x v e r t e x ( s e e ( a ) i n f i g u r e 4 . 9 ) . A smudge o f t h i s t y p e i s i l l u s t r a t e d i n f i g u r e 4.9. d i r e c t i o n o f t r a v e r s a l N smudge - c u r r e n t p o i n t - n e x t p o i n t a) r e f l e x v e r t e x \ \ F i g u r e 4.9 Smudge w h i c h c o m p r i s e s a g r o u p o f a d j a c e n t p i x e l s on t h e i n s i d e o f a r e f l e x v e r t e x . 38 ( i i i ) T h e smudge c o m p r i s e s a c o m b i n a t i o n o f b o t h ( i ) a n d ( i i ) a b o v e a s shown i n f i g u r e 4.10. c u r r e n t p o i n t n e x t p o i n t t y p e ( i i ) d i r e c t i o n o f t r a v e r s a l t y p e ( i ) \ \ F i g u r e 4.10 C o m p l e t e smudge. A smudge i s ' p r o c e s s e d a s i f i t i s o f t y p e ( i i i ) a b o v e . B e c a u s e s u c h a smudge c o n t a i n s two c o n c e p t u a l l y d i f f e r e n t s m udges, i t i s p r o c e s s e d i n two s t a g e s : 1.1 T h e e l i m i n a t i o n o f i n t e r m e d i a t e p i x e l s : T h i s s t a g e e l i m i n a t e s t h e i n t e r m e d i a t e p i x e l s i n a s e q u e n c e o f a d j o i n i n g p i x e l s a l o n g t h e d i r e c t i o n o f e i t h e r o f t h e c a r t e s i a n a x e s . T h i s i s e q u i v a l e n t t o p r o c e s s i n g t h e p a r t o f t h e smudge t h a t c o r r e s p o n d s t o t y p e ( i ) a b o v e . T h i s t a s k i s p e r f o r m e d by t h e p r o c e d u r e ' n s e w _ c h e c k ' i n t h e p r o g r a m l i s t e d i n A p p e n d i x A. T h i s p r o c e s s i n v o l v e s t r a v e r s i n g i n t h e c u r r e n t d i r e c t i o n ( d e t e r m i n e d a s t h e d i r e c t i o n f r o m t h e c u r r e n t p o i n t t o t h e n e x t p o i n t ) , d i s c a r d i n g t h e p i x e l s b e i n g e x a m i n e d a s w e l l a s t h e 3 9 i n t e r n a l p i x e l s a d j a c e n t t o t h e e x a m i n e d p i x e l s a s l o n g a s t h e r e e x i s t s a n e x t p i x e l i n t h e s e q u e n c e a n d t h a t n e x t p i x e l d o e s n o t h a v e an i m m e d i a t e s e t n e i g h b o u r o n t h e o u t s i d e a s d e f i n e d i n t a b l e 4.1. F i g u r e s 4.11 ( a ) a n d (b) show t h e two s i t u a t i o n s w h i c h c a u s e t h i s d i s c a r d i n g o f p i x e l s i n s e q u e n c e t o t e r m i n a t e . c u r r e n t p o i n t —> + i d i r e c t i o n o f t r a v e r s a l n e x t p o i n t +-t+. . l a s t row p i x e l b e i n g p r o c e s s e d F i g u r e 4.11a T h i s f i g u r e shows t h a t t h e d i s c a r d i n g o f p i x e l s , s e q u e n t i a l l y a r r a n g e d i n t h e d i r e c t i o n o f one o f t h e c a r t e s i a n a x e s , t e r m i n a t e s a t t h e n e x t t o l a s t p i x e l i n t h e s e q u e n c e . O n l y p i x e l s m a r k e d w i t h a p l u s s i g n a r e r e t a i n e d . 40 c u r r e n t p o i n t > + d i r e c t i o n o f t r a v e r s a l +++ ++++ p i x e l b e i n g p r o c e s s e d o u t s i d e p i x e l F i g u r e 4.11b T h i s f i g u r e shows t h a t a p i x e l on t h e o u t s i d e o f a s e q u e n t i a l l i n e o f p i x e l s ( i n t h e d i r e c t i o n o f e i t h e r o f t h e c a r t e s i a n a x e s ) , w i l l t e r m i n a t e t h e d i s c a r d i n g o f i n t e r m e d i a t e p i x e l s . 1.2 T h e e l i m i n a t i o n o f smudge r e m a i n i n g : T h e e l i m i n a t i o n o f t h e r e m a i n i n g smudge ( t y p e ( i i ) a b o v e ) i s a c c o m p l i s h e d v i a a r e c u r s i v e p r o c e s s . T h i s p r o c e s s i s p e r f o r m e d by t h e ' c l e a r _ u p ' p r o c e d u r e i n t h e p r o g r a m l i s t i n g i n A p p e n d i x A. T h i s p r o c e s s n e e d o n l y be i n v o k e d i f i n d e e d t h e r e i s a p i x e l ( o n t h e o u t s i d e ) a d j a c e n t t o t h e p i x e l c u r r e n t l y b e i n g p r o c e s s e d . T h e d e p t h t o w h i c h t h e a l g o r i t h m a c t u a l l y d e l e t e s p i x e l s b e l o n g i n g t o t h e smudge i s d e t e r m i n e d by t h e v a l u e o f a v a r i a b l e known a s t h e smudge f a c t o r ( a c c _ s m u d g e , i n t h e p r o g r a m ) . I d e a l l y , t h e o n l y p i x e l s w h i c h s h o u l d be r e m o v e d f r o m 41 t h e s y s t e m a t t h i s s t a g e a r e t h o s e , w h i c h when r e m o v e d , w i l l g u a r a n t e e t h a t t h e n e x t p i x e l t o be p r o c e s s e d w i l l be t h a t o n e w h i c h i s i m m e d i a t e l y a d j a c e n t a n d e x t e r i o r t o t h e one c u r r e n t l y b e i n g p r o c e s s e d . A l l p i x e l s w h i c h b e l o n g t o t h e i n w a r d s i d e o f t h e smudge w h i c h a r e n o t d e l e t e d a r e 'remembered' a s h a v i n g b e l o n g e d t o a smudge. T h i s i s d o n e by m a r k i n g t h e i r p o s i t i o n s on t h e b a c k p l a n e o f t h e m a t r i x b e i n g p r o c e s s e d . T h e r e t e n t i o n o f some o f t h e p i x e l s w h i c h f o r m t h e smudge a l l o w s f o r a p o t e n t i a l h i g h e r d e g r e e o f a c c u r a c y i n t h e t r a v e r s a l o f t h e y e t u n t r a v e r s e d s e c t i o n o f t h e b o u n d a r y . F i g u r e s 4.12 ( a ) a n d (b) i l l u s t r a t e t h i s p o i n t . F i g u r e 4.12a A l l p i x e l s i n t h e e n c l o s i n g box a r e d e l e t e d . S u b s e q u e n t p r o c e s s i n g o f t h e b o u n d a r y w i l l t e r m i n a t e a t B. C l o s i n g o f f t h e p o l y g o n f r o m B t o A w i l l d e l e t e w a n t e d a r e a s . 42 A \.*- - c u r r e n t p o i n t • • • • • I * * | • • • • : : : : : ILL3 \ • • • • • F i g u r e 4.12b O n l y t h o s e p i x e l s i n t h e e n c l o s i n g box a r e d e l e t e d w h i l e p r o c e s s i n g t h e smudge a t p o s i t i o n A. A l l o t h e r p i x e l s b e l o n g i n g t o t h i s smudge, a r e n o t d e l e t e d , b u t w i l l h a v e t h e i r p o s i t i o n s m a r k e d on t h e b a c k p l a n e o f t h e m a t r i x b e i n g p r o c e s s e d . S u b s e q u e n t p r o c e s s i n g o f t h e b o u n d a r y w i l l n o t t e r m i n a t e a t B. T h e r e s u l t i n g p o l y g o n i n f i g u r e 4.12a w o u l d be c l o s e d o f f by a s t r a i g h t l i n e j o i n i n g B t o A. F i g u r e 4.12b, h o w e v e r , w o u l d r e s u l t i n t h e p o l y g o n b e i n g c l o s e d by h a v i n g t h e l e f t h a n d s i d e o f t h e smudge t a v e r s e d i n t h e u s u a l m a n n e r . When a b o u n d a r y h a s b e e n c o m p l e t e l y t r a v e r s e d , t h e b a c k p l a n e o f t h e m a t r i x i s s c a n n e d , w i t h i n t h e a r e a o f t h e s m a l l e s t r e c t a n g l e t h a t w i l l e n c l o s e t h e t r a v e r s e d b o u n d a r y , a n d a l l p o s i t i o n s w h i c h a r e m a r k e d by a p i x e l a r e u n s e t , a n d t h e c o r r e s p o n d i n g p i x e l on t h e f r o n t p l a n e o f t h e m a t r i x i s d e l e t e d f r o m t h e s y s t e m . T h i s e n s u r e s t h a t a n y p i x e l s on t h e f r o n t 43 p l a n e , b e l o n g i n g t o an e n c l o s e d a r e a w i t h a h i g h e r n e s t i n g d e p t h t h a n t h a t j u s t p r o c e s s e d , w i l l be l e f t i n t a c t . When p r o c e s s i n g p o s i t i o n A, s a y , t h e p i x e l s t o be c o n s i d e r e d a s p a r t o f t h e smudge f o r i m m e d i a t e p r o c e s s i n g a r e d e f i n e d r e c u r s i v e l y i n t h e f o l l o w i n g s t e p o r d e r : . ( i ) T h e p o i n t a d j a c e n t t o t h e c u r r e n t smudge p o i n t b e i n g p r o c e s s e d , a n d l y i n g i n t h e c a r t e s i a n a x i s d i r e c t i o n d i c t a t e d by t h e r e l a t i o n s e x p r e s s e d i n t a b l e 4.2. D i r e c t i o n C a r t e s i a n a x i s d i r e c t i o n N o r t h N o r t h N o r t h e a s t N o r t h N o r t h w e s t N o r t h S o u t h S o u t h S o u t h e a s t S o u t h S o u t h w e s t S o u t h E a s t E a s t W e s t West T a b l e 4.2 T h e r e l a t i o n s h i p s b e t w e e n d i r e c t i o n o f t r a v e r s a l a n d t h e n e i g h b o u r f o r a d j a c e n c y c h e c k i n t h e f i r s t l e v e l o f r e c u r s i v e smudge p r o c e s s i n g , ( i i ) T h e p o i n t a d j a c e n t t o t h e smudge p o i n t c u r r e n t l y b e i n g c o n s i d e r e d a n d l y i n g i n t h e c a r t e s i a n a x i s d i r e c t i o n d i c t a t e d by t h e r e l a t i o n s e x p r e s s e d i n t a b l e 4.3 44 D i r e c t i o n C a r t e s i a n a x i s d i r e c t i o n N o r t h E a s t N o r t h e a s t E a s t N o r t h w e s t E a s t S o u t h West S o u t h e a s t W e s t S o u t h w e s t West E a s t S o u t h West N o r t h T a b l e 4.3 T h e r e l a t i o n s h i p s b e t w e e n d i r e c t i o n o f t r a v e r s a l a n d t h e n e i g h b o u r f o r a d j a c e n c y c h e c k i n t h e s e c o n d l e v e l o f r e c u r s i v e smudge p r o c e s s i n g . An e x a m p l e o f smudge p r o c e s s i n g i s g i v e n i n f i g u r e 4.1.3. T h e number a s o c i a t e d w i t h e a c h p i x e l , w h i c h i s e x a m i n e d i n a c c o r d a n c e w i t h t h e r e c u r s i v e a l g o r i t h m a b o v e , i s t h e o r d e r i n w h i c h t h a t p i x e l i s e x a m i n e d i n t h e p r o c e s s i n g o f t h e smudge. 45 direction of • • 16 • 15 1 • • • • 14 * 2 • + • • + • • 13 • 12 • 11 * 3 • + • + • • 10 • 9 * 4 • • 7 • 6 * 5 • • 8 Figure 4.13 This figure i l l u s t r a t e s both the pix e l s and the order in which they are examined while processing a smudge. In figure 4.13 above, those pixels marked with a plus sign are not processed as part of the smudge when point A i s being considered as the next point. These points are deleted when the l i n e of contiguous points from point A to point B (see figure 4.13) i s being processed as per 1.1 above. In the example depicted in figure 4.13, the next point (point A) w i l l be retained as a point v i t a l in preserving the exact shape of the boundary as defined by the user. Only those points 46 whose d i s t a n c e a l o n g a c a r t e s i a n a x i s d i r e c t i o n f r o m A ( a n d on t h e i n s i d e o f A a s d e f i n e d a b o v e ) i s g r e a t e r t h a n o r e q u a l t o t h e smudge f a c t o r w i l l be m a r k e d on t h e b a c k p l a n e o f t h e m a t r i x . T h e s e p o i n t s w i l l n o t i m m e d i a t e l y be d e l e t e d f r o m t h e smudge o r t h e i n d e x . Any p o i n t d e l e t e d f r o m t h e m a t r i x m ust a l s o be d e l e t e d f r o m t h e i n d e x d a t a s t r u c t u r e d e s c r i b e d i n s e c t i o n B a b o v e . 47 2. C l o s e s t p o i n t In d e t e r m i n i n g the c l o s e s t p o i n t ( i e . , the next p o i n t d e f i n e d i n s e c t i o n 1 above) t o the c u r r e n t p o i n t , the next p o i n t i s s e t e q u a l t o the c l o s e r of the c u r r e n t p o i n t ' s two neighbour p o i n t s i n t he y _ b l o c k of the index d a t a s t r u c t u r e . I f t h e r e i s o n l y one n e i g h b o u r , then the next p o i n t i s s e t e q u a l t o t h i s p o i n t . I f t h e r e a r e no n e i g h b o u r s (the p o i n t i s the o n l y one i n the column), then the next p o i n t ' s c o o r d i n a t e s a r e s e t e q u a l t o the systems maximum i n t e g e r v a l u e ( m a x i n t ) . I f t h e r e i s a t l e a s t one n e i g h b o u r , then the next p o i n t w i l l be the c l o s e s t p o i n t t o the c u r r e n t p o i n t i n the same column as the c u r r e n t p o i n t . T h i s i s g u a r a n t e e d because the row numbers i n the y _ b l o c k a r e s o r t e d i n a s c e n d i n g o r d e r . The d i s t a n c e , D, i s computed as the a b s o l u t e v a l u e of the d i f f e r e n c e between the row v a l u e s of the c u r r e n t and next p o i n t s . The columns t o the l e f t and r i g h t of t h a t i n which the c u r r e n t p o i n t r e s i d e s a r e now s e a r c h e d , a l t e r n a t i v e l y t o the l e f t and r i g h t and t o a column d i s t a n c e , D, r from the c u r r e n t p o i n t ' s column, f o r a p o i n t which l i e s c l o s e r t o the c u r r e n t p o i n t than does the next p o i n t . I f such a p o i n t i s found, the next p o i n t becomes s e t t o t h i s next p o i n t , and D i s recomputed t o be e q u a l t o the maximum of the a b s o l u t e of the column d i f f e r e n c e ( the x d i f f e r e n c e ) and the a b s o l u t e of the row d i f f e r e n c e (y d i f f e r e n c e ) , between the c u r r e n t p o i n t and the new next p o i n t . 48 I f a c o l u m n c o m p r i s e s more t h a n s i x t e e n p o i n t s , a b i n a r y s e a r c h i s p e r f o r m e d on t h e l o c a t i o n s s t o r e d i n t h e y _ b l o c k s . I f n o t , t h e n a l i n e a r s e a r c h i s e x e c u t e d . I n t h e c a s e o f a l i n e a r s e a r c h , t h e l o w e s t a n d h i g h e s t p o i n t s o f t h e c o l u m n t o be s e a r c h e d a r e c o m p a r e d w i t h t h e c u r r e n t p o i n t a n d t h e s e a r c h b e g i n s a t t h e e n d o f t h e l i s t whose e n d p o i n t l i e s c l o s e r t o t h e c u r r e n t p o i n t . T h e y _ b l o c k c o n t a i n s r e f e r e n c e s t o o n l y t h o s e p i x e l s w h i c h a r e s e t i n t h e p i x e l m a t r i x . I t t h u s s e r v e s a s a n o r d e r e d p o i n t e r t o s e t p i x e l s i n t h e m a t r i x . W i t h o u t t h e Y _ b l o c k s , t h e n e a r e s t n e i g h b o u r s e a r c h w o u l d r e q u i r e e x a m i n a t i o n o f a n e l e m e n t ' s n e i g h b o u r s i r r e s p e c t i v e o f w h e t h e r t h e y a r e s e t o r n o t . T h e number o f u n s e t p i x e l s r e q u i r i n g e x a m i n a t i o n i n c r e a s e s a s t h e d i s t a n c e b e t w e e n t h e e l e m e n t a n d i t s c l o s e s t n e i g h b o u r i n c r e a s e s . 49 3 . F i n d t h e f i r s t p o i n t o f a b o u n d a r y T h e f i r s t p o i n t o f t h e n e x t b o u n d a r y t o be p r o c e s s e d i s f o u n d by s c a n n i n g t h e i n d e x ( s e e s e c t i o n B a b o v e ) f o r t h e l e a s t y _ m i n v a l u e . T h i s v a l u e r e p r e s e n t s t h e h i g h e s t row, i n t h e p i c t u r e , i n w h i c h a p i x e l i s s e t . B e c a u s e e a c h e l e m e n t o f t h e i n d e x a r r a y s t o r e s t h e i n f o r m a t i o n p e r t a i n i n g t o a c o l u m n o f t h e d i s p l a y , t h e l e f t t o r i g h t ( o r l o w e s t t o h i g h e s t ) s c a n n i n g o f t h e i n d e x a r r a y w i l l y i e l d t h e l e f t m o s t p i x e l i n t h e e v e n t o f more t h a n one c o l u m n h a v i n g a p i x e l s e t i n t h e h i g h e s t row. 5 0 4. P r o t e c t i o n o f u s e r ' s i n p u t T h e d a t a , a s t r a c e d by t h e u s e r , i s r e a d by PFS i n t o a p i x e l m a t r i x . I n o r d e r t h a t t h e i n t e g r i t y o f t h i s d a t a be m a i n t a i n e d , t h e c o n t e n t s o f t h i s m a t r i x a r e c o p i e d t o t h e f r o n t p l a n e o f a n o t h e r m a t r i x , c a l l e d t h e ' s a v e _ m a t r i x ' . A b o u n d a r y i s o n l y d e l e t e d f r o m t h i s s e c o n d m a t r i x when t h e u s e r c o n f i r m s t h a t t h e c l o s e d p o l y g o n , g e n e r a t e d f r o m t h e o r i g i n a l o f t h e b o u n d a r y , i s s a t i s f a c t o r y . I n o r d e r t h a t o n l y t h o s e p i x e l s b e l o n g i n g t o t h e c u r r e n t b o u n d a r y a r e d e l e t e d f r o m t h e s a v e _ m a t r i x , t h e p o s i t i o n s o f a l l p i x e l s , d e l e t e d d u r i n g t h e p r o c e s s i n g o f t h e b o u n d a r y , a r e s t o r e d i n a l i n k e d l i s t a s s o c i a t e d w i t h t h e b o u n d a r y . O n l y t h o s e p i x e l s whose p o s i t i o n s a r e s t o r e d i n t h i s l i s t , a r e d e l e t e d f r o m t h e s a v e _ m a t r i x . T h u s , t h e b o u n d a r i e s t h a t h a v e n o t y e t b e e n p r o c e s s e d a r e l e f t i n t a c t i n t h e s a v e _ m a t r i x . A s e a c h c l o s e d p o l y g o n i s d e t e r m i n e d t o be s a t i s f a c t o r y , i t i s c o p i e d o n t o t h e b a c k p l a n e o f t h e s a v e _ m a t r i x . When a l l b o u n d a r i e s h a v e b e e n p r o c e s s e d , t h e c l o s e d p o l y g o n s r e p r e s e n t i n g t h e s e b o u n d a r i e s w i l l h a v e b e e n c o p i e d t o t h e s a v e _ m a t i x ' s b a c k p l a n e . I t i s t h i s m a t r i x w h i c h i s f i l l e d by t h e s y s t e m f o r s u b s e q u e n t d i s p l a y on t h e s c r e e n . 51 D. P o l y g o n c l o s u r e : T h e s e q u e n c e o f p i x e l s w h i c h a r e r e t a i n e d f o r m a m i n i m a l p o l y g o n ( i . e . , a l l v e r t e x p o i n t s a r e r e t a i n e d ) w h i c h p r e s e r v e s t h e s h a p e o f t h e e n t e r e d b o u n d a r y . A t t h i s s t a g e t h e p o l y g o n i s c l o s e d b y p a s s i n g t h e p r e s e r v e d p o i n t s i n p a i r s ( P 1 , P 2 ) , ( P 2 , P 3 ) , . . . , ( P n , P l ) t o a d i g i t a l d i f f e r e n t i a l a n a l y s e r (DDA) w h i c h s e t s i n t e r m e d i a t e p i x e l s i n t h e s t r a i g h t l i n e b e t w e e n t h e two p o i n t s p a s s e d t o i t . T h a t i s , i t c l o s e s o f f t h e p o l y g o n by j o i n i n g t h e p o i n t s a l o n g i t s p e r i m e t e r . L i n e s on a r a s t e r g r a p h i c s d i s p l a y c a n n o t be p e r f e c t l y s t r a i g h t . Any p i x e l on t h e l i n e w i l l , h o w e v e r , r e s i d e w i t h i n one h a l f o f a g r i d i n t e r v a l o f i t s t r u e p o s i t i o n . The DDA i m p l e m e n t e d by t h i s s y s t e m i s t h e s i m p l e DDA a s d e s c r i b e d i n [NEWM79]. T h e DDA i m p l e m e n t e d i n t h i s s y s t e m i s t h e p r o c e d u r e 'dda' i n t h e p r o g r a m i n A p p e n d i x A. T h i s p r o c e d u r e was t a k e n d i r e c t l y f r o m [NEWM79] p p (20 - 2 7 ) . 52 E . P o l y g o n f i l l i n g T h e m a t r i x w h i c h c o n t a i n s t h e c l o s e d p o l y g o n s t o be f i l l e d h a s a l l b a c k g r o u n d a n d i n t e r i o r p i x e l s s e t t o z e r o , w h i l e t h e p i x e l s r e p r e s e n t i n g t h e c l o s e d p o l y g o n s ' b o u n d a r i e s a r e s e t t o o n e . T h e b a s i c a l g o r i t h m w h i c h f i l l s t h e s e t o f c l o s e d p o l y g o n b o u n d a r i e s i s a s f o l l o w s : S c a n t h e l i n e s o f t h e m a t r i x o n e a t a t i m e . A t t h e b e g i n n i n g o f e a c h s c a n l i n e , s e t t h e beam t o o f f . On e n c o u n t e r i n g t h e f i r s t s t r i n g o f p i x e l s , s e t t h e beam t o on ( a ' s t r i n g ' o f p i x e l s r e f e r s t o a c o n t i g u o u s l i n e o f s e t p i x e l s a l o n g t h e c u r r e n t s c a n l i n e ) . A t t h e n e x t s t r i n g o f p i x e l s , t u r n t h e beam t o o f f . A t e a c h s t r i n g o f p i x e l s , c h a n g e t h e s t a t e o f t h e beam a s d e s c r i b e d a b o v e . I f t h e beam i s o n , t h e n t h e p i x e l s b e i n g s c a n n e d must e i t h e r be l e f t s e t ( i f c u r r e n t l y s e t ) o r s e t ( i f c u r r e n t l y u n s e t ) . I f t h e beam i s o f f , a l l p i x e l s s c a n n e d must be l e f t i n t h e i r c u r r e n t s t a t e . C e r t a i n s p e c i a l c a s e s e x i s t u n d e r w h i c h t h e s t a t e o f t h e beam d o e s n o t c h a n g e . T h e beam d o e s n o t c h a n g e s t a t e i f t h e s t r i n g o f p i x e l s b e i n g p r o c e s s e d f o r m s a n u p p e r o r l o w e r a r c o f a p o l y g o n . F i g u r e 4.14 shows a n e x a m p l e o f b o t h u p p e r a n d l o w e r p o l y g o n a r c s . 53 ++ ++++ ++ ++ ++ ++ +++ ++ +++ ++++++ F i g u r e 4.14 An i l l u s t r a t i o n o f u p p e r a n d l o w e r p o l y g o n a r c s . T h e f o r m a l d e f i n i t i o n o f an u p p e r o r l o w e r p o l y g o n a r c i s a s f o l l o w s : A ssume t h a t t h e p i x e l s k t o r o f row i a r e s e t , w h e r e k , r 6 { 1 , . . . , x _ r e s o l u t i o n } , i 6 { 1 , . . . , y _ r e s o l u t i o n } a n d ( r - k ) > = 0 . T h e n , t h i s s t r i n g o f ( r - k ) p i x e l s i s an u p p e r  a r c i f t h e r e e x i s t s on row i + 1 two c o n t i g u o u s s t r i n g s o f p i x e l s m t o n a n d p t o q , whe r e m,n,p,q 6 { ( k - 1 ) , . . . , ( r + 1 ) } , (n-m)>=0, (q-p)>=0 a n d ( p - n ) > l . S i m i l a r l y , t h i s s t r i n g o f ( r - k ) p i x e l s i s a l o w e r a r c i f t h e r e e x i s t s on row i - 1 two c o n t i g u o u s s t r i n g s o f p i x e l s m t o n a n d p t o q , wh e r e m,n,p,q 6 { ( k - 1 ) , . . . , ( r + 1 ) } , (n-m)>=0, (q-p)>=0 a n d ( p - n ) > l . 54 F i g u r e 4.15 i l l u s t r a t e s an e x a m p l e o f an u p p e r a r c . F i g u r e 4.15 An e x a m p l e o f a n u p p e r a r c . No p r o b l e m o c c u r s i f r h a s t h e v a l u e 1 o r k h a s t h e v a l u e x _ r e s o l u t i o n b e c a u s e t h e m a t r i x i s s u r r o u n d e d by a b o r d e r o f z e r o s . U p p e r a n d l o w e r a r c s a r e d i r e c t i o n a l l y d e p e n d a n t . T h e i r t a n g e n t s a r e i n t h e d i r e c t i o n o f t h e h o r i z o n t a l c a r t e s i a n a x i s . C o n v e r s e l y , a n y s t r i n g o f c o n t i g u o u s p i x e l s w h i c h i s n o t a n u p p e r o r l o w e r a r c f o r m p a r t o f t h e l e f t o r r i g h t e d g e o f a p o l y g o n a n d w i l l t h u s c a u s e a c h a n g e o f s t a t e i n t h e beam. F i g u r e 4.16 i l l u s t r a t e s c o n t i g u o u s e d g e s t r i n g s . 5 5 .... . . + ++ + + + + + + + • • + + ++ + + + +++ + ++ ++ ++ +++ +++ + ++ ++ ++ + •• +++ + + ++ ++ + + + ++ ... + + .. + + ++ + + +++ + + + ++ F i g u r e 4.16 P i x e l s r e p r e s e n t e d by a p l u s s i g n a r e e l e m e n t s o f c o n t i g u o u s e d g e s t r i n g s . P i x e l s r e p r e s e n t e d by d o t s a r e u p p e r o r l o w e r a r c s . E d g e p i x e l s t r i n g s c h a n g e t h e s t a t e o f t h e beam. F i g u r e 4.17 shows t h r e e e x a m p l e s o f g e n e r a l e d g e c o n d i t i o n s . (a) (b) (c) (d) F i g u r e 4.17 F o u r g e n e r a l e d g e c o n d i t i o n s a r e shown. T h e g e n e r a l s h a p e o f t h e e d g e c o n d i t i o n o v e r t h r e e s c a n l i n e s i s a n 'S'. F i g u r e s ( a ) a n d ( b ) 56 i l l u s t r a t e t h i s g e n e r a l s h a p e . T h i s ' S ' s h a p e m a y , h o w e v e r , be s t r e t c h e d o u t i n t o a ' s t r a i g h t ' l i n e a s i s shown i n ( c ) a n d ( d ) . 57 F . T a i 1 d e t e c t i o n T h e p o l y g o n f i l l i n g a l g o r i t h m d e s c r i b e d i n s e c t i o n E a b o v e d e p e n d s on t h e beam b e i n g t u r n e d on a n d o f f a n e v e n number o f t i m e s . I f t h i s d i d n o t h a p p e n , p o l y g o n s w o u l d e f f e c t i v e l y be t u r n e d i n s i d e o u t , r e s u l t i n g i n p a r t s o f t h e b a c k g r o u n d b e i n g s h a d e d w h i l e i n n e r a r e a s o f p o l y g o n s w o u l d be l e f t u n s h a d e d . T h e c o u n t o f t h e number o f s t r i n g s o f c o n t i g u o u s p i x e l s w h i c h c a u s e t h e beam t o c h a n g e s t a t e m ust be e v e n . An e v e n c o u n t o f beam s t a t e c h a n g e s d o e s n o t , h o w e v e r , g u a r a n t e e t h a t no t a i l s e x i s t . I t i s p o s s i b l e t h a t a n e v e n number o f t a i l s e x i s t on a s i n g l e s c a n l i n e . S u c h an o c c u r e n c e o f t a i l s w i l l r e m a i n u n d e t e c t e d . A p r o b l e m o c c u r s i f ' t a i l s ' a r e g e n e r a t e d by t h e b o u n d a r y d e t e c t i o n a n d p o l y g o n c l o s i n g a l g o r i t h m s . A t a i l i s , a s t h e name i m p l i e s , a c o l u m n o f p i x e l s a t t a c h e d t o a c l o s e d p o l y g o n . T h e c o l u m n must be a t l e a s t o n e p i x e l w i d e . T a i l s j o i n t h e p o l y g o n a t an u p p e r o r l o w e r a r c o r on a n e d g e . T h e y a r e d i r e c t i o n a l l y d e p e n d e n t a n d o c c u r i n t h e d i r e c t i o n o f t h e v e r t i c a l c a r t e s i a n a x i s . F i g u r e 4.18 shows a n e x a m p l e o f a u s e r i n p u t b o u n d a r y t h a t r e s u l t s i n a t a i l , a n d t h e r e s u l t i n g c l o s e d p o l y g o n . 58 blank. t a i l F i g u r e 4.18 I l l u s t r a t i o n o f u s e r i n p u t b o u n d a r y a n d t h e r e s u l t i n g c l o s e d p o l y g o n . I f a t a i l i s d e t e c t e d , t h e c o u n t o f h o r i z o n t a l p i x e l s t r i n g s f a l l s i n t o o n e o f two c a t e g o r i e s : ( i ) t h e c o u n t o f s e t p i x e l s t r i n g s i s e q u a l t o 1 ( i i ) t h e c o u n t o f s e t p i x e l s t r i n g s i s >=3, a n d o d d . C a s e ( i ) a b o v e i s h a n d l e d t r i v i a l l y by d e l e t i n g t h e t h e s e q u e n c e o f p i x e l s . C a s e ( i i ) a b o v e , h o w e v e r , p r e s e n t s a p r o b l e m . T h e s i m p l e s t i n s t a n c e o f t h i s c a s e i s w h e r e t h e c o u n t o f b e a m - s t a t e c h a n g e s i s t h r e e a n d t h e l e n g t h o f e a c h o f t h e t h r e e c o r r e s p o n d i n g p i x e l s t r i n g s i s o n e . I n t h i s i n s t a n c e i t i s n o t p o s s i b l e f o r t h e s y s t e m t o l o c a l l y d i s c e r n w h i c h o f t h e t h r e e p i x e l s t r i n g s i s t h e member o f t h e t a i l . T h e p r o b l e m t h a t e x i s t s i n c a s e ( i i ) i s one o f c o n n e c t i v i t y [ M I N S 6 9 ] , F i g u r e 4.19 i l l u s t r a t e s t h e c o n f u s i o n t h a t a r i s e s . 59 state changes tail polygon edges Figure 4.19 I l l u s t r a t i o n of the confusion caused by three changes of the beam's state. This figure i s a l o g i c a l fragment of an entire family of polygons. Obviously, the problem i s compounded as the count of the beam's state changes increases. Case ( i i ) i s handled by allowing the user to i n t e r a c t i v e l y a i d the system by i d e n t i f y i n g the p i x e l s which belong to the t a i l . The closed polygon i s stored on the back plane of a p i x e l matrix. On the front plane of the same matrix, arrows are drawn (pixels are set so as to form arrows), h i g h l i g h t i n g each of the pi x e l strings which contribute to the odd count, as potential t a i l s . The start position of each of these strings i s stored in a linked l i s t of 'problem points'. When the search for t a i l s i s completed, the closed polygon w i l l be displayed on the f i r s t graphic plane of the COMTAL, while the arrows ( i f indeed any exist) w i l l be displayed on the second graphic plane of the COMTAL. It i s then up to the user to recognise the offending 60 t a i l a n d i d e n t i f y t h e a p p r o p r i a t e a r r o w t o t h e s y s t e m . F o r e a c h p o t e n t i a l t a i l , a r r o w s n e e d o n l y be d r a w n o n c e . S u b s e q u e n t p r o c e s s i n g w h i c h d e l e t e s t h e t a i l w i l l p r o c e s s t h e e n t i r e t a i l , k n o w i n g t h e s t a r t i n g p o s i t i o n s t o r e d i n t h e l i n k e d l i s t . F i g u r e 4.20 shows a n e x a m p l e o f a r r o w s h i g h l i g h t i n g a s e t o f p r o b l e m p o i n t s . F i g u r e 4.20 A r r o w s h i g h l i g h t i n g a s e r i e s o f p r o b l e m p o i n t s . T h e t a i l a p p e a r s i n t h e f i g u r e on t h e l e f t . 61 G. D e l e t i o n o f t a i l s T h e s t a r t p o s i t i o n ( i n t h e p i x e l m a t r i x ) o f p o t e n t i a l t a i l s i s s t o r e d i n a l i n k e d l i s t . When t h e t a i l i s i n t e r a c t i v e l y i d e n t i f i e d by t h e u s e r ( v i a t h e t a r g e t on t h e d i s p l a y s c r e e n ) , t h e l i n k e d l i s t i s s e a r c h e d f o r t h e c l o s e s t s t a r t i n g p o s i t i o n t o t h e ' h i t ' p o i n t . T h i s i m p l i e s t h a t t h e h i t d o e s n o t h a v e t o l a n d e x a c t l y on t h e t o p l e f t m o s t p o i n t o f t h e t a i l . T h r e e t y p e s o f t a i l s e x i s t . T h o s e w h i c h j o i n t h e p o l y g o n a t o n e o f i t s u p p e r a r c s , t h o s e w h i c h j o i n t h e p o l y g o n a t one o f i t s l o w e r a r c s a n d t h o s e w h i c h j o i n t h e p o l y g o n a t o n e o f i t s e d g e s . F i g u r e 4.21 i l l u s t r a t e s t h e s e t h r e e c a s e s . + + + ++ ++ ++ + ++ + + + (a) (b) (c) F i g u r e 4.21 F i g u r e ( a ) i l l u s t r a t e s a t a i l j o i n i n g a p o l y g o n a t a n u p p e r a r c , ( b ) i l l u s t r a t e s a t a i l j o i n i n g a p o l y g o n a t a l o w e r a r c a n d ( c ) shows a t a i l w h i c h j o i n s t h e p o l y g o n a t a n e d g e . P i x e l s r e p r e s e n t e d by p l u s s i g n s b e l o n g t o t a i l s . 62 B e c a u s e t a i l s a r e p r o c e s s e d f r o m t o p t o b o t t o m , t h e t e r m i n a t i n g c o n d i t i o n s f o r t h e p r o c e s s i n g o f a t a i l a r e : ( i ) t h e d e t e c t i o n o f a n u p p e r a r c , ( i i ) t h e d e t e c t i o n o f an e d g e , a n d ( i i i ) t h e d i s a p p e a r a n c e o f t h e t a i l ( i e . , t h e e n d o f t h e t a i l ) . T h e t a i l i s d e l e t e d by d e l e t i n g t h e s t r i n g o f p i x e l s s t a r t i n g a t t h e p o s i t i o n e x t r a c t e d f r o m t h e l i n k e d l i s t . T h e row c o u n t i s t h e n i n c r e m e n t e d a n d i f t h e r e a r e a n y p i x e l s s e t d i r e c t l y b e l o w t h o s e d e l e t e d a b o v e ( a n d t o e a c h e d g e , w i t h i n a l i m i t ) t h e s e a r e d e l e t e d . T h e a b o v e p r o c e s s i s r e p e a t e d u n t i l no p i x e l s i n t h e r e g i o n o f t h e t a i l w i d t h e x i s t o r a n u p p e r a r c i s d e t e c t e d o r an e d g e i s d e t e c t e d , a t w h i c h s t a g e t h e p r o c e s s i s h a l t e d a n d t h e n e x t t a i l , i f a n y more e x i s t , i s d e l e t e d i n t h e same way. I n t h i s i m p l e m e n t a t i o n t a i l s m u s t be r e m o v e d , e i t h e r by t h e s y s t e m d i r e c t l y o r by t h e s y s t e m w i t h t h e a i d o f t h e u s e r . T h e s y s t e m c o u l d be t r i v i a l l y m o d i f i e d t o make t h e r e m o v a l o f t a i l s o p t i o n a l . 63 H. I m p r o v e m e n t s : 2-D V e r s u s 3-D M a t r i c e s T h e p i x e l m a t r i c e s a r e c u r r e n t l y t h r e e d i m e n s i o n a l . I f t h e m a t r i x i s d e f i n e d a s h a v i n g d i m e n s i o n s q , r a n d s, t h e n t o f i n d t h e M ( i , j , k ) t h e l e m e n t , t h e f o l l o w i n g c a l c u l a t i o n i s made by t h e c o d e g e n e r a t e d by t h e c o m p i l e r : M ( i , j , k ) = B a s e A d d r e s s + r . s . ( i - l ) + s . ( j - l ) + ( k - 1 ) = ( B a s e A d d r e s s + r . s - s - 1) + r . s . i + s . j l e t t i n g a = ( B a s e A d d r e s s + r . s - s - 1 ) a n d b = r . s , we h a v e : M ( i , j , k ) = a + b . i + s . j . T h i s r e p r e s e n t s two a d d i t i o n s a n d two m u l t i p l i c a t i o n s . A two d i m e n s i o n a l m a t r i x o f d i m e n s i o n s , r a n d s, h a s a n e l e m e n t ' s p o s i t i o n c a l c u l a t e d by t h e f o l l o w i n g : M ( i , j ) = B a s e A d d r e s s + r . s . ( i - l ) + s . ( j - l ) + ( k - 1 ) = ( B a s e A d d r e s s - s - l ) + s . i + j l e t t i n g a = ( B a s e A d d r e s s - s - 1 ) , we h a v e : M ( i , j ) = a + s . i + j . T h i s r e p r e s e n t s two a d d i t i o n s a n d o n e m u l t i p l i c a t i o n . T h e c u r r e n t t h r e e d i m e n s i o n a l m a t r i x , b e c a u s e i t h a s two p l a n e s , c a n be c o n v e r t e d t o a two d i m e n s i o n a l m a t r i x w i t h a l t e r n a t e e l e m e n t s r e p r e s e n t i n g e l e m e n t s f r o m t h e two p l a n e s i n t h e t h r e e d i m e n s i o n a l m a t r i x . I f t h i s w e r e d o n e , t h e n w i t h a n 64 e x t r a a d d i t i o n , t o a c c o u n t f o r t h e o f f s e t , t h e new two d i m e n s i o n a l m a t r i x w o u l d h a v e i t s e l e m e n t s a c c e s s e d w i t h one m u l t i p l i c a t i o n a n d t h r e e a d d i t i o n s . W h e t h e r o r n o t t h i s m o d i f i c a t i o n i s i m p l e m e n t e d i n t h e f u t u r e s h o u l d d e p e n d on t h e h a r d w a r e a v a i l a b l e . I f a f a s t h a r d w a r e m u l t i p l y i s a v a i l a b l e , t h e n t h e m o d i f i c a t i o n w i l l p r o b a b l y n o t be w o r t h t h e e f f o r t . H o w e v e r , i f m u l t i p l i c a t i o n i s s l o w , t h e n t h e m o d i f i c a t i o n s h o u l d r e s u l t i n a m a j o r i m p r o v e m e n t i n e f f i c i e n c y . 65 C h a p t e r V: P r o b l e m s , d i f f i c u l t i e s a n d f e a t u r e s T h i s c h a p t e r shows, by e x a m p l e , some o f t h e p r o b l e m s , d i f f i c u l t i e s a n d f e a t u r e s a u s e r e n c o u n t e r s i n e x e c u t i n g P F S . Some o f t h e s e p r o b l e m s h a v e b e e n a l l u d e d t o i n c h a p t e r I . O t h e r s r e s u l t f r o m t h e u s e r d i s o b e y i n g t h e two u s e r ' s r u l e s d e s c r i b e d i n c h a p t e r I I I . T h e e x a m p l e a l s o shows how t h e u s e r c a n c o p e w i t h t h e s e p r o b l e m s on an i n t e r a c t i v e b a s i s . F i n a l l y , t h i s c h a p t e r d i s c u s s e s t h e e x t e n t t o w h i c h PFS i s b o u n d t o t h e h a r d w a r e a n d s o f t w a r e e n v i r o n m e n t i n w h i c h i t h a s b e e n i m p l e m e n t e d . A. S a m p l e r u n A r u n o f PFS c o m p r i s e s a number o f i n t e r a c t i v e s t e p s . D e p e n d i n g on t h e s t a g e o f p r o c e s s i n g , t h e u s e r may be i n s t r u c t e d by t h e s y s t e m t o t r a c e on t h e d i s p l a y s c r e e n , v e r i f y a t a s k p e r f o r m e d by t h e s y s t e m o r a i d t h e s y s t e m i n m a k i n g some d e c i s i o n ( t a i l p r o c e s s i n g ) . T h e s e q u e n c e o f i n t e r a c t i v e s t e p s w h i c h g e n e r a t e d t h e s a m p l e r u n i s g i v e n b e l o w : ( i ) T h e u s e r t r a c e s t h e d e s i r e d b o u n d a r i e s on t h e g r a p h i c d i s p l a y s c r e e n . T h e b o u n d a r i e s e n t e r e d by t h e u s e r a r e shown i n f i g u r e 5.1. 66 F i g u r e 5.1 B o u n d a r i e s t r a c e d by t h e u s e r , ( i i ) Two b o u n d a r i e s , l a b e l e d A a n d B i n f i g u r e 5.1, h a v e b e e n t r a c e d . B o u n d a r y A e n c l o s e s b o u n d a r y B a n d h e n c e t h e i r n e s t i n g d e p t h s a r e o n e a n d two r e s p e c t i v e l y . I n t h e d i s c u s s i o n w h i c h f o l l o w s , t h e b o u n d a r i e s w i l l be r e f e r e d t o s i m p l y a s A a n d B. F i g u r e 5.2 i l l u s t r a t e s t h e c l o s e d p o l y g o n g e n e r a t e d i n p r o c e s s i n g A. 67 F i g u r e 5.2 C l o s e d p o l y g o n g e n e r a t e d i n p r o c e s s i n g b o u n d a r y A. A s c a n be s e e n i n t h e f i g u r e , b o t h A a n d B were a c t u a l l y p r o c e s s e d a l t h o u g h o n l y A was meant t o h a v e b e e n p r o c e s s e d a t t h i s s t a g e . T h i s h a s r e s u l t e d b e c a u s e t h e b o u n d a r i e s w e r e t r a c e d , by t h e u s e r , i n s u c h a manner t h a t a p i x e l f r o m B i s t h e c l o s e s t n e i g h b o u r t o a p i x e l f r o m A. T h i s i s a b r e a c h o f u s e r - r u l e ( i i ) i n c h a p t e r I I I ( s e e f i g u r e 3 . 2 ) . When f i g u r e 5.2 i s d i s p l a y e d on t h e s c r e e n , t h e u s e r i s a s k e d by t h e s y s t e m w h e t h e r t h e p o l y g o n i s d i s t i n c t . I n t h i s c a s e , t h e u s e r ' s a n s w e r i s n e g a t i v e . I n o r d e r t h a t t h e p r o b l e m o f 6 8 d i s t i n c t n e s s be r e s o l v e d , the user i s i n s t r u c t e d by the system to p i c k ( i d e n t i f y the p o s i t i o n on the screen with the a i d of the screen's t a r g e t ) the top l e f t and bottom r i g h t hand c o r n e r s of the box (imaginary) that encloses the problem a r e a . In the f i g u r e , t h i s box i s drawn with a dashed l i n e . ( i i i ) A l l p i x e l s w i t h i n the c o n f i n e s of the box, i d e n t i f i e d i n the p r e v i o u s step, are erased from the f r o n t plane of the save_matrix (see chapter IV s e c t i o n C.4). T h i s m o d i f i e d matrix i s then c o p i e d to the d i s p l a y screen. F i g u r e 5.3 shows the r e s u l t of t h i s copy. The user i s now i n s t r u c t e d by the system to c o r r e c t l y r e t r a c e the boundaries where they have F i g u r e 5.3 Problem p i x e l s erased from the s c r e e n . 69 been erased. F i g u r e 5.4 shows what such a r e t r a c e might look l i k e . F i g u r e 5.4 Erased boundary l i n e s have been r e t r a c e d . I t should be noted that i f any boundaries had a l r e a d y been s u c c e s s f u l l y processed, they would have been d i s p l a y e d on another g r a p h i c plane f o r t h i s step i n order that the user does not o v e r t r a c e a p r e v i o u s l y processed boundary l i n e . A l l boundaries a l r e a d y processed are not e f f e c t e d by t h i s step. ( i v ) Boundary A i s now reprocessed. The new c l o s e d polygon r e p r e s e n t i n g A i s shown i n f i g u r e 5.5. 70 F i g u r e 5.5 C o r r e c t c l o s e d polygon r e p r e s e n t i n g boundary A. The unambiguous t a i l at the top of the boundary has been a u t o m a t i c a l l y removed by the system. On t h i s o c c a s i o n when the user i s asked whether the polygon i s d i s t i n c t the answer i s i n the a f f i r m a t i v e . 71 F i g u r e 5.6 A r r o w s a r e a d d e d t o h i g h l i g h t t h e e x i s t a n c e o f a t a i l . A r r o w s a r e now a d d e d t o t h e s e c o n d g r a p h i c p l a n e t o i n d i c a t e t h a t a m b i g u o u s t a i l s e x i s t . F i g u r e 5.6 shows t h e s e t a i l s , w h i c h a r e d i s p l a y e d i n a c o l o u r d i f f e r e n t t o t h a t i n w h i c h t h e p o l y g o n i s d i s p l a y e d . T h e s y s t e m knows t h a t a t a i l e x i s t s , b u t i t d o e s n o t know w h i c h o f t h e c o l u m n s o f p i x e l s , p o i n t e d t o by t h e a r r o w s , r e p r e s e n t s t h e t a i l . T h e u s e r i s i n s t r u c t e d by t h e s y s t e m t o i d e n t i f y ( p i c k ) t h e a p p r o p r i a t e t a i l w i t h t h e s c r e e n ' s c u r s o r . T he m i d d l e c o l u m n o f p i x e l s i s i d e n t i f i e d a n d t h e s y s t e m a u t o m a t i c a l l y r e m o v e s t h e t a i l . T he c o r r e c t e d c l o s e d p o l y g o n i s now c o p i e d 72 t o t h e r e a r p l a n e o f t h e s a v e _ m a t r i x . ( v ) F i g u r e 5.7 shows t h e c l o s e d p o l y g o n r e p r e s e n t i n g b o u n d a r y B a s i t i s d i s p l a y e d on t h e s c r e e n f o r v e r i f i c a t i o n by t h e u s e r . T h i s p o l y g o n p r e s e n t s no p r o b l e m s a n d i s c o p i e d t o t h e r e a r p l a n e o f t h e s a v e m a t r i x . F i g u r e 5.7 C l o s e d p o l y g o n r e p r e s e n t i n g b o u n d a r y B. ( v i ) A t t h i s s t a g e a l l b o u n d a r i e s , t r a c e d by t h e u s e r , h a v e b e e n p r o c e s s e d by t h e s y s t e m . T h e u s e r i s now i n v i t e d t o t r a c e more b o u n d a r i e s . I n t h i s r u n , t h e u s e r i n d i c a t e s t h a t more b o u n d a r i e s a r e d e s i r e d , a n d i n r e s p o n s e , t h e s y s t e m d i s p l a y s t h e a l r e a d y p r o c e s s e d b o u n d a r i e s on t h e s e c o n d g r a p h i c p l a n e , i n o r d e r t h a t t h e u s e r d o e s n o t o v e r t r a c e t h e s e b o u n d a r i e s . T h e s e a l r e a d y - p r o c e s s e d b o u n d a r i e s a r e 73 d i s p l a y e d i n a d i f f e r e n t c o l o u r t o t h o s e w h i c h a r e now t r a c e d . F i g u r e 5.8 shows two new b o u n d a r i e s C a n d D t r a c e d on t h e f i r s t g r a p h i c p l a n e . T h e p r o c e s s e d b o u n d a r i e s a r e shown, a s t h e y a r e d i s p l a y e d on t h e s e c o n d g r a p h i c p l a n e . F i g u r e 5.8 Two new b o u n d a r i e s , C a n d D, t r a c e d by t h e u s e r . B o u n d a r i e s C a n d D h a v e n e s t i n g d e p t h s two a n d one r e s p e c t i v e l y . ( v i i ) F i g u r e 5.9 i l l u s t r a t e s t h e two d i s p l a y s i n w h i c h t h e two new b o u n d a r i e s a r e v e r i f i e d . 74 o F i g u r e 5.9 ( a ) shows t h e c l o s e d p o l y g o n r e p r e s e n t i n g b o u n d a r y C, w h i l e ( b) shows t h e p o l y g o n w h i c h r e p r e s e n t s b o u n d a r y D. F i g u r e 5.9 i l l u s t r a t e s two s t e p s o f u s e r i n t e r a c t i o n . B o t h o f t h e c l o s e d p o l y g o n s , g e n e r a t e d by t h e s y s t e m , a r e a c c e p t a b l e t o t h e u s e r a n d a r e c o p i e d i n t u r n t o t h e r e a r p l a n e o f t h e s a v e _ m a t r i x . ( v i i i ) A g a i n , a l l b o u n d a r i e s h a v e b e e n p r o c e s s e d by t h e s y s t e m . T h i s t i m e t h e u s e r d e c l i n e s t h e o p t i o n t o t r a c e more b o u n d a r i e s . T h e s y s t e m now f i l l s t h e c l o s e d p o l y g o n s w h i c h h a v e b e e n c o p i e d t o t h e r e a r p l a n e o f t h e s a v e _ m a t r i x . F i g u r e 5.10 shows t h e f i l l e d p o l y g o n s . 7 5 F i g u r e 5.10 P o l y g o n s f i l l e d by P F S . T h i s e x a m p l e i s n o t e x h a u s t i v e , b u t t h e t e c h n i q u e s u s e d t o r e s o l v e t h e p r o b l e m s w h i c h d i d a r i s e a r e u s e d t o r e s o l v e o t h e r s i m i l a r p r o b l e m s . A b r e a c h o f u s e r - r u l e 1 i n c h a p t e r I I I ( s e e f i g u r e 3.1b) c a n , f o r e x a m p l e , be r e s o l v e d by t r e a t i n g t h e c l o s e d p o l y g o n g e n e r a t e d a s b e i n g n o t d i s t i n c t a n d t h e n r e t r a c i n g t h e o f f e n d i n g p o r t i o n o f t h e b o u n d a r y . 76 B. S y s t e m D e p e n d e n c e PFS i s b o u n d t o t h e h a r d w a r e c o n f i g u r a t i o n d e s c r i b e d i n c h a p t e r I s e c t i o n A i n a s much a s c o m m u n i c a t i o n b e t w e e n PFS a n d COMTAL V i s i o n One i s d o n e v i a a FORTRAN s u b r o u t i n e p a c k a g e w h i c h r u n s u n d e r MTS. Any c h a n g e i n r a s t e r d i s p l a y s y s t e m w o u l d n e c e s s i t a t e m o d i f i c a t i o n s t o t h e FORTRAN s u b r o u t i n e p a c k a g e , i f t h a t s y s t e m w e r e n o t f u l l y c o m p a t i b l e w i t h t h e COMTAL V i s i o n One s y s t e m . PFS i t s e l f i s i m p l e m e n t e d i n UBC P a s c a l , w h i c h i s a s u p e r s e t o f W i r t h ' s p a s c a l a s d e s c r i b e d i n [ J E N S 7 5 ] . T h e two m a i n e x t e n s i o n s t o s t a n d a r d P a s c a l w h i c h h a v e b e e n u t i l i z e d a r e : ( i ) t h e u s e o f M c C a r t h y p r e c e d e n c e i n t h e e v a l u a t i o n o f b o o l e a n e x p r e s s i o n s , a n d ( i i ) t h a t f u n c t i o n s a r e o c c a s i o n a l l y o f non s c a l a r t y p e . I f PFS w e r e t o be r u n u n d e r a n o p e r a t i n g s y s t e m w h i c h d i d n o t s u p p o r t UBC P a s c a l , t h e a p p r o p r i a t e c h a n g e s w i t h r e s p e c t t o t h e a b o v e two p o i n t s , w o u l d h a v e t o be made t o t h e p r o g r a m . A number o f t h e a l g o r i t h m s i m p l e m e n t e d s u g g e s t t h a t a r a s t e r s c a n d e v i c e be u s e d . I f a v e c t o r t y p e d i s p l a y d e v i c e was d e s i r e d , t h e n a number o f c h a n g e s , b o t h i n t h e p h i l o s o p h y o f some o f t h e a l g o r i t h m s a n d i n t h e i m p l e m e n t a t i o n o f o t h e r s , f i l l i n g f o r e x a m p l e , w o u l d be r e q u i r e d . 77 C h a p t e r V I : C o n c l u s i o n T h i s t h e s i s h a s d e s c r i b e d t h e P o l y g o n F i l l i n g S y s t e m , a s i m p l e m e n t e d on t h e COMTAL V i s i o n One h a r d w a r e . L i m i t a t i o n s e x i s t i n t h e s y s t e m w i t h r e s p e c t t o t h e i n p u t d a t a t h a t i t w i l l p r o c e s s c o r r e c t l y . T h e l i m i t a t i o n s t h a t e x i s t r e s u l t d i r e c t l y f r o m b r e a c h e s o f u s e r ' s r u l e s ( i ) a n d ( i i ) d e s c r i b e d i n c h a p t e r I I I . No o t h e r c l a s s o f i n p u t h a s b e e n f o u n d , t h u s f a r , w h i c h t h e s y s t e m w i l l n o t p r o c e s s c o r r e c t l y . C h a p t e r I s e r v e d a s a g e n e r a l i n t r o d u c t i o n t o t h e s y s t e m . I t c o n t a i n e d a s a m p l e r u n o f P F S t o s e r v e a s a g e n e r a l g u i d e t o t h e u s e r a s t o what t h e s y s t e m d o e s . C h a p t e r I I d i s c u s s e d t h e r a t i o n a l e o f t h e p r o b l e m d e f i n i t i o n . I t a l s o d i s c u s s e d t h e u n d e r l y i n g g r i d m o d e l , w h i c h i n v o l v e d d e s c r i b i n g h e x a g o n a l a n d s q u a r e t e s s e l a t i o n s , a n d a n e x p l a n a t i o n a s t o why a s q u a r e g r i d s y s t e m was c h o s e n . C h a p t e r I I I d e s c r i b e d p r o b l e m s t h a t e x i s t i n p r o c e s s i n g t h e u s e r d e f i n e d b o u n d a r i e s . C e r t a i n o f t h e s e p r o b l e m s may be i n t e r p r e t e d a s b e i n g l i m i t a t i o n s o f t h e s y s t e m . Two u s e r r u l e s w e r e e n u m e r a t e d . B r e a c h e s o f t h e s e r u l e s w i l l r e s u l t i n t h e i n c o r r e c t p r o c e s s i n g o f t h e b o u n d a r i e s . A d h e r e n c e t o t h e s e r u l e s w i l l r e s u l t i n c o r r e c t p r o c e s s i n g o f t h e b o u n d a r i e s . C h a p t e r I V d e s c r i b e d t h e i m p l e m e n t a t i o n o f t h e s y s t e m . I n c l u d e d i n t h i s c h a p t e r was a d e s c r i p t i o n o f t h e k e y d a t a s t r u c t u r e s u s e d by t h e s y s t e m a n d d e s c r i p t i o n s o f t h e m a i n a l g o r i t h m s w h i c h h a v e b e e n i m p l e m e n t e d . C h a p t e r V d i s c u s s e d p r o b l e m s , d i f f i c u l t i e s a n d f e a t u r e s o f 78 PFS by way o f a d e t a i l e d e x a m p l e . P r o b l e m s w h i c h c a n a r i s e w h i l e r u n n i n g t h e s y s t e m a r e i l l u s t r a t e d i n t h i s e x a m p l e . A t t h e o u t s e t o f d e v e l o p m e n t o f P F S , i t was t h o u g h t , by t h e a u t h o r , t h a t t h e e n t i r e s y s t e m w o u l d be a u t o m a t i c . H o w e v e r , a s d e s c r i b e d i n c h a p t e r I V , s e c t i o n s F a n d G, a n d i l l u s t r a t e d i n t h e e x a m p l e i n c h a p t e r V, t h e o c c u r e n c e o f t a i l s may f o r c e t h e s y s t e m t o s e e k a s s i s t a n c e f r o m t h e u s e r . To a c e r t a i n e x t e n t t h i s l o s s o f a u t o m a t i s m c a n be s e e n a s a f a i l i n g o f t h e s y s t e m . T h e a u t h o r f e e l s t h a t t h e p r o b l e m o f t a i l s i s t h e o r e t i c a l l y c o m p u t a b l e a n d c a n t h u s be r e s o l v e d a u t o m a t i c a l l y . T h e r e a r e , h o w e v e r , c l e a r d i f f i c u l t i e s i n r e s o l v i n g i t l o c a l l y . T h e s y s t e m i t s e l f , h a s b e e n t e s t e d on r e l a t i v e l y few e x a m p l e s a n d a p p l i c a t i o n s . W i t h c o n t i n u e d u s e , f u r t h e r a s s u m p t i o n s a b o u t i n p u t d a t a m i g h t h a v e t o be made i n o r d e r f o r t h e s y s t e m t o f u l l y meet t h e r e q u i r e m e n t s o f t h e a p p l i c a t i o n s f o r w h i c h i t was d e s i g n e d . On t h e o t h e r h a n d , new a p p l i c a t i o n s m i g h t be f o u n d f o r w h i c h t h e s y s t e m c a n be u s e d . Two s u g g e s t i o n s a r e o f f e r e d f o r f u t u r e work r e l a t e d d i r e c t l y t o t h i s t h e s i s : ( i ) e f f o r t be a p p l i e d t o r e s o l v i n g t h e p r o b l e m o f i d e n t i f y i n g t a i l s , when an a m b i g u i t y e x i s t s , a n d ( i i ) t h e s y s t e m be e x t e n d e d t o a l l o w t h e u s e r t o d e f i n e a n a r e a by s p e c i f y i n g t h e v e r t i c e s o f t h a t a r e a . T h i s w o u l d r e q u i r e t h a t t h e u s e r ' s i n p u t be m o n i t o r e d v i a a p i c k command [ G S P C 7 8 ] . M o n i t o r e d i n p u t p r o v i d e s 79 t e m p o r a l k n o w l e d g e o f t h e v e r t i c e s , a n d h e n c e , a d i f f e r e n t , more t r i v i a l a l g o r i t h m c a n be i m p l e m e n t e d t o c l o s e o f f p o l y g o n s d e f i n e d i n t h i s way. 8 0 B i b l i o g r a p h y [ G S P C 7 8 ] G r a p h i c s S t a n d a r d s P l a n n i n g C o m m i t t e e , S t a t e o f t h e A r t S u b c o m m i t t e e . GSPC C o r e S y s t e m . C o m p u t e r G r a p h i c s , V o l . 1 2 , No. 1-2, J u n e 1 9 7 8 . [DEUT72] D e u t s c h E . S . T h i n n i n g A l g o r i t h m s on R e c t a n g u l a r , H e x a g o n a l , a n d T r i a n g u l a r A r r a y s . C o m m u n i c a t i o n s o f t h e ACM, V o l . 15, No. 9, S e p t e m b e r 1 9 7 2 . [DUDA73] Du d a R.O. A n d H a r t P.E. P a t t e r n C l a s s i f i c a t i o n  a n d S c e n e A n a l y s i s . J o h n W i l e y a n d S o n s , 1 9 7 3 . [ F R E E 7 4 ] F r e e m a n H e r b e r t . C o m p u t e r P r o c e s s i n g o f L i n e  D r a w i n g I m a g e s . C o m p u t i n g S u r v e y s , V o l . 6, No. 1, M a r c h 1974. [GOLA69] G o l a y M a r c e l J . E . H e x a g o n a l P a r a l l e l P a t t e r n  T r a n s f o r m a t i o n s . I E E E T r a n s a c t i o n s on C o m p u t e r s , V o l . C-18, No. 8, A u g u s t 1 9 6 9 . [GRAY71] G r a y S t e p h e n B. L o c a l P r o p e r t i e s o f B i n a r y  I m a g e s i n Two D i m e n s i o n s . I E E E T r a n s a c t i o n s on C o m p u t e r s , V o l . C-20, No. 5, May 1 9 7 1 . [KEND71] K e n d a l l P r e s t o n , J r . F e a t u r e E x t r a c t i o n by G o l a y  H e x a g o n a l P a t t e r n T r a n s f o r m s . I E E E T r a n s a c t i o n s on C o m p u t e r s , V o l . C-20, No. 9, S e p t 1 9 7 1 . [ L E V I 7 2 ] L e v i a l s i S. On S h r i n k i n g B i n a r y P i c t u r e  P a t t e r n s . C o m m u n i c a t i o n s o f t h e ACM, V o l . 15, No. 1, J a n 1 9 7 2 . [ L I E B 7 8 ] L i e b e r m a n H e n r y . How t o C o l o r i n a C o l o r i n g  B o o k . C o m p u t e r G r a p h i c s , V o l . 12, No. 3, A u g u s t 1 9 7 8 . [MINS69] M i n s k y M., a n d P a p e r t S. P e r c e p t r o n , An  I n t r o d u c t i o n t o C o m p u t a t i o n a l G e o m e t r y . T h e MIT P r e s s , C a m b r i d g e , M a s s . , 1 9 6 9 . 81 [NEWM79] Newman, W i l l i a m M., a n d R o b e r t F . S p r o u l l . P r i n c i p l e s o f I n t e r a c t i v e C o m p u t e r G r a p h i c s , s e c o n d e d i t i o n . M c G r a w - H i l l I n c . , New Y o r k , 1 9 7 9 . [ N E U F 8 0 ] N e u f e l d G. T h e UBC Remote S e n s i n g Image A n a l y s i s  S y s t e m . UBC T.M. - 0 1 , J u n e 1 9 8 0 . [ P A G E 7 5 ] P a g e , E . S . , a n d W i l s o n L . B . I n f o r m a t i o n  R e p r e s e n t a t i o n a n d M a n i p u l a t i o n i n a C o m p u t e r . C a m b r i d g e U n i v e r s i t y P r e s s , 1 9 7 5 . [ P A V L 7 8 ] P a v l i d i s T h e o d o s i o s . F i l l i n g A l g o r i t h m s f o r R a s t e r G r a p h i c s C o m p u t e r G r a p h i c s , V o l . 12, No. 3, A u g u s t 1 9 7 8 . [ S T E F 7 1 ] S t e f a n e l l i R. A n d R o s e n f e l d A. Some P a r a l l e l T h i n n i n g A l g o r i t h m s f o r D i g i t a l P i c t u r e s . J o u r n a l o f t h e A s s o c i a t i o n f o r C o m p u t i n g M a c h i n e r y , V o l . 1 8 , No. 2, A p r i l 1 9 7 1 . [WALK75] W a l k e r B.S., G u r d J.R., a n d D r a w n e e k E.A. I n t e r a c t i v e C o m p u t e r G r a p h i c s . C r a n e , R u s s a k & Company, I n c . , 1 9 7 5 . [ J E N S 7 5 ] J e n s e n K a t h l e e n a n d W i r t h N i k l a u s . P a s c a l User- M a n u a l a n d R e p o r t . ( s e c o n d e d i t i o n ) S p r i n g e r - V e r l a g , 1 9 7 5 . 82 Appendix A: Program l i s t i n g f o r Polygon F i l l i n g System $ L I S T T . W H O L E . B U * S I N K * 1 P R O G R A M p o l y g o n ( 1 n p u t , o u t p u t ) ; 2 3 C O N S T 4 5 C = 1 ; { s i z e o f g a p 1 n p r e - p r o c e s s i n g } 6 n u l = c h r ( 2 5 5 ) ; { v a l u e t o w h i c h ' d e s e r i p t ' 1 s i n i t } 7 t r a i 1 e r s = 2 ; { l e n g t h o f t r a i l e r s t o b e r e m o v e d } 8 f r o n t = 1; { f r o n t p a n n e l o f m a t r i x } 9 b a c k = 2 ; { b a c k p a n n e l o f m a t r i x } 1 0 x _ r e s o l u t i o n = 7 4 ; { x r e s . o f s c r e e n } 1 1 y _ r e s o l u t i o n = 7 4 ; { y r e s . o f s c r e e n } 1 2 x _ r e s _ p l u s _ C = x _ r e s o l u t i o n + C ; { a l l o w b o r d e r o f C } 1 3 y r e s p l u s C = y r e s o l u t i o n + C ; { a l l o w b o r d e r o f C } 1 4 S t = 1; { s t a r t c o l / r o w f o r m a t r i x m a n i p } 1 5 y _ d i v _ 1 6 = 1 6 ; { s i z e o f ' i n d e x ' a r r a y } 1 6 p t r s _ l i m 1 t = 1 6 ; { s i z e o f ' p t r s ' a r r a y l i m i t > 1 7 b u f f _ s i z e = 8 ; { s i z e o f b u f f e r t o r e a d g r a p h i c s } 1 8 1 e n g _ b u f f = 3 2 ; { l e n g t h o f b u f f e r i n b y t e s } 1 9 n o _ g r a p h i c s 5 4 ; { no. o f g r a p h i c s p l a n e s o n C O M T A L } 2 0 u n i t n o = 0 ; { C O M T A L u n i t no } 2 1 w o r d _ s 1 z e = 3 2 { A M D A H L w o r d s i z e - i n b i t s } 2 2 w o r d _ s i z e _ 1 = 3 1 2 3 d e b u g = 2 0 { l e v e l s o f d e b u g g i n g } 2 4 1 1 n e _ l e n g t h = 8 0 { max i n p u t l i n e l e n g t h } 2 5 b a s e = 1 0 { b a s e f o r a l p h a / n u m e r i c c o n v e r s i o n s } 2 6 b l a n k = ' 2 7 z e r o = 0 R D ( ' 0 ' ) ; 2 8 s t r _ l e n g t h = 8 0 ; { max l e n g t h f o r p a r a m e t e r s t r i n g s } 2 9 max smudge = = 1 0 0 ; { max. s i z e f o r s m u d g e s } 3 0 r d = 1; 3 1 wr t = = 0 ; 3 2 d s c r i p t _ l e n g t h = = 8 0 ; { l e n g t h f o r p o l y g o n d e s e r i p t } 3 3 m a x _ p o l y s = = 5 0 ; { max number o f p o l y g o n s a l l o w e d } 3 4 3 5 T Y P E 3 6 3 7 s t r i n g = A R R A Y ( . 0 . . s t r _ l e n g t h . ) O F c h a r ; 3 8 3 9 t x t _ s t r = A R R A Y ( . 1 . . s t r _ l e n g t h . ) O F c h a r ; 4 0 4 1 p o i n t = R E C O R D 4 2 x, 4 3 y : i n t e g e r 4 4 E N D ; 4 5 4 6 p o l y _ e l t = R E C O R D 4 7 p o l y _ x , 4 8 p o l y _ y : i n t e g e r ; 4 9 p o l y _ p t r : @ p o l y _ e l t 5 0 E N D ; 5 1 5 2 p o l y _ a r r a y _ e l t = R E C O R D 5 3 p o l y _ d e s c r i p t : A R R A Y ( . 1 . . d s c r i p t _ l e n g t h . ) O F c h a r ; 5 4 d e s c r i p t _ p o s n : p o i n t ; g-, 5 5 b a s e _ p t r : @ p o l y _ e l t ; oo 5 6 s i z e i n t e g e r ; 5 7 E N D ; 5 8 59 p o l y _ a r r a y = ARRAY(.- 1..max_polys.) OF p o l y _ a r r a y _ e l t ; { Oth e l t f o r keeping t r a c k GO of d e l e t e d p o i n t s 61 -1st e l t f o r keeping t r a c k 62 of t a i l s } 63 64 mat_core = ARRAY(.1. .((2+2*C+x_resolut i on) d i v word_size + 1),1..2.) OF i n t e g e r ; 65 boo1_matr i x = ARRAY(.st-C-1..y_res_plus_C+1.) OF mat_core; 66 67 c h a r s e t = SET OF char; 68 69 y_b1ock = ARRAY(.1..y_div_16.) OF i n t e g e r ; 70 71 b u f f _ a r r a y = ARRAY(. 1 . . b u f f _ s i z e . ) OF i n t e g e r ; 72 73 p t r = @y_block; 74 75 p t r _ t y p e = @>po 1 y_e I t ; 76 77 i ndex_element = RECORD 78 no, 79 y_m1n, 80 y_max : i n t e g e r ; 81 p t r s : ARRAY(.st..ptrs l i m i t . ) OF p t r 82 END; 83 84 1ocat i on = RECORD 85 i nd, 86 o f f i n t e g e r ; 87 found : boolean 88 END; 89 90 91 po1nt_found = RECORD 92 x, 93 y i n t e g e r ; 94 found : boolean 95 END; 96 97 compla 1nt = (bad_data,1imi t _ e r r o r , i o _ e r r o r , c a n c e l 1ed,bad_comnd); 98 99 VAR 100 101 1 ndex ARRAY(.st. . x _ r e s o l u t i o n . ) OF index_element; { index to m a t r i x } 102 f r s t _ p t p o i n t _ f o u n d ; { f i r s t p o i n t f o r any a r e a } 103 f r s t l o c a t i o n ; { l o c a t i o n i n 'index' of f i r s t p o i n t } 104 c u r r _ x , c u r r _ y i n t e g e r ; { co-ords of c u r r e n t p o i n t ) 105 next_x, next_y i n t e g e r ; . { co-ords of next p o i n t } 106 d i s p l a c e i n t e g e r ; { min d i s t t w i x t c u r r pt & nxt pt a l o n g row/col 107 m1n_x, { min x i n m a t r i x } 108 max_x, { max x i n m a t r i x } 109 p t _ s e t _ n o i n t e g e r ; { polygon number } 1 10 debugging ARRAY(.1..debug.) OF boolean; { debugging c o n t r o l a r r a y ) 1 1 1 g r a p h i c s i n t e g e r ; { code f o r c a l l t o c o n t r o l _ c o m t a l ) 1 12 graph i n t e g e r ; { c o n t r o l on COMTAL f o r r e a d } 113 b u f f e r b u f f _ a r r a y ; { b u f f e r f o r r e a d i n g COMTAL } 1 14 matr1x b o o l _ m a t r i x ; { main ma t r i x f o r m a n i p u l a t i n g } 1 15 work_matr i x b o o l _ m a t r i x ; { temp mat r i x } 1 16 save_matr1x b o o l _ m a t r i x ; < keep a r e c o r d of i n p u t t e d p o i n t s 1 17 and 'good' p o l y g o n s } 1 18 uni t_no, { COMTAL u n i t number } 119 l e n g t h , { l e n g t h of comtal read } 120 r e t _ c o d e : Integer; { CMTRD parameters } 121 1nput_1ndex i n t e g e r ; { index f o r input b u f f e r } 122 1 n p u t _ b u f f e r : ARRAY(.1..11ne_length+1.) OF char; { read b u f f e r f o r l i b r a r y } 123 s l g n o f f : bool e a n ; { f l a g f o r n u l l e n t r y } 124 b u f f e r _ l e n g t h : i n t e g e r ; { l e n g t h of input s t r i n g } 125 e r r o r _ i n d e x i n t e g e r ; { type of read e r r o r > 126 d i g i t s : c h a r s e t ; 127 negative_num : boolean; { c o n t r o l f o r n e g a t i v e input > 128 max_smudge_x, { max x f o r c u r r e n t polygon } 129 max_smudge_y, { max x f o r c u r r e n t p o l y g o n } 130 min_smudge_x, { min x f o r c u r r e n t polygon } 131 min_smudge_y : i n t e g e r ; { min x f o r c u r r e n t polygon } 132 acc_smudge i n t e g e r ; { user s i z e f o r 'smudge' } 133 gen_pts : ARRAY(.-1..max_polys.) OF p t r _ t y p e ; 134 poo1_ptr, 135 g e n _ p t r : p t r _ t y p e ; 136 p o l y g o n : p o l y _ a r r a y ; 137 1 i n t e g e r ; 138 a l r e a d y _ a c t i v e , 139 more_to_come : boolean; 140 t o p _ r o w , t o p _ c o l , 141 b o t _ r o w , b o t _ c o l , 142 dummy,row,col, 143 no_arrows i n t e g e r ; 144 evens : boolean; 145 arrow,j : i n t e g e r ; 146 147 PROCEDURE p r i m a r y _ i n i t i a l i z e ; forward; 148 PROCEDURE s e c o n d a r y _ i n i t i a 1 i z e ; forward; 149 PROCEDURE t e r t i a r y _ i n i t i a 1 i z e ; forward; 150 PROCEDURE wr1t e _ i n d e x ( x , y : i n t e g e r ) ; forward; 151 PROCEDURE d e l e t e _ i n d e x ( x , y , s u b s c r i p t , o f f s e t : i n t e g e r ) ; forward; 152 PROCEDURE e s t a b _ i n d e x ; forward; 153 PROCEDURE f 1nd_c1osest ( x , y , 154 c u r r _ c o l i n t e g e r ; 155 VAR 156 d i s p l a c e , 157 s u b s c r i p t , 158 o f f s e t i n t e g e r ; 159 VAR 160 next_x, 161 next_y i n t e g e r ) ; forward; 162 PROCEDURE f i n d _ a r e a ; forward; 163 PROCEDURE smudge(curr_x,curr_y : i n t e g e r ; VAR next_x,next_y : i n t e g e r ) ; forward; 164 PROCEDURE nse w _ c h e c k ( x _ i n o , y _ i n c : i n t e g e r ) ; forward; 165 PROCEDURE clear_up(temp_x,temp_y : i n t e g e r ) ; forward; 166 PROCEDURE mat_init(VAR mat : b o o l _ m a t r i x ; p l a n e : i n t e g e r ) ; forward; 167 PROCEDURE copy_mat(VAR mat1,mat2 : b o o l _ m a t r i x ; p l a t e : i n t e g e r ) ; forward; 168 PROCEDURE c o n t r a c t ; forward; 169 PROCEDURE expand; forward; 170 PROCEDURE f i n d _ l i n e a r ( x , y : i n t e g e r ; VAR i n d . o f f : i n t e g e r ) ; forward; 171 PROCEDURE p r e _ p r o c e s s ; forward; 172 PROCEDURE read_comtal(VAR u n i t _ n o : i n t e g e r ; 173 VAR b u f f e r : b u f f _ a r r a y ; 174 VAR l e n g t h , oo 175 r e t _ c o d e : i n t e g e r ) ; f o r t r a n 'CMTRD'; (-n 176 PROCEDURE wr1te_comta1(VAR u n i t _ n o : Integer: 177 VAR b u f f e r : b u f f _ a r r a y ; 178 VAR l e n g t h . 179 r e t _ c o d e : I n t e g e r ) ; f o r t r a n 'CMTWT'; 180 PROCEDURE d i s p _ p o l y ( V A R mat : b o o l _ m a t r 1 x ; p l a n e : i n t e g e r ) ; f o r w a r d ; 181 PROCEDURE c m t _ i n 1 t 1 a l i z e ( u n i t _ n o : i n t e g e r ; VAR r e t _ c o d e : i n t e g e r ) ; f o r t r a n 'CMTINT'; 182 PROCEDURE t e r m _ c o m t a 1 ( u n i t _ n o : i n t e g e r ; VAR r e t _ c o d e : I n t e g e r ) ; s 1 i n k a g e 'CMTTRM'; 183 PROCEDURE c o n t r o 1 _ c o m t a 1 ( u n 1 t _ n o , c o d e : 1 n t e g e r ; c m d : 1 n t e g e r ; V A R r e t _ c o d e : i n t e g e r ) ; f o r t r a n 'CMTCTL'; 184 PROCEDURE r e a d _ m a t r i x ; f o r w a r d ; 185 PROCEDURE d e b u g _ d a t a ; f o r w a r d ; 186 PROCEDURE s k i p _ c h a r ( s k i p c h a r s : c h a r s e t ) ; f o r w a r d ; 187 PROCEDURE r e a d _ i n t (min,max : i n t e g e r ; q u e r y : s t r i n g ; VAR v a l u : i n t e g e r ) ; f o r w a r d ; 188 PROCEDURE r e a d _ r e a l ( m i n , m a x : r e a l ; q u e r y : s t r i n g ; VAR v a l u : r e a l ) ; f o r w a r d ; 189 PROCEDURE p a c k ( V A R t o _ s t r i n g : s t r i n g ; f r o m _ s t r i n g : s t r i n g ; VAR s t a r t ; i n t e g e r ) ; f o r w a r d ; 190 PROCEDURE r e a d _ b u f f e r ; f o r w a r d ; 191 PROCEDURE c o m p l a i n ( m e s s a g e : c o m p l a i n t ) ; f o r w a r d ; 192 PROCEDURE r e a d _ t e x t ( q u e r y : s t r i n g ; VAR r e t u r n _ t e x t : t x t _ s t r ) ; f o r w a r d ; 193 PROCEDURE s e t _ b i t ( V A R mat : b o o l _ m a t r 1 x ; 1 , j , k : i n t e g e r ) ; f o r w a r d ; 194 PROCEDURE u n s e t _ b i t ( V A R mat : b o o l _ m a t r i x ; i , j , k : i n t e g e r ) ; f o r w a r d ; 195 PROCEDURE 1 i n k _ t o _ l i s t ( 1 : i n t e g e r ) ; f o r w a r d ; 196 PROCEDURE r e t u r n _ t o _ p o o l ( 1 i n t e g e r ) ; f o r w a r d ; 197 PROCEDURE 1 n s e r t _ p o 1 n t ( i , x , y : i n t e g e r ) ; f o r w a r d ; 198 PROCEDURE c 1 o s e _ p o 1 y g o n ( 1 i n t e g e r ) ; f o r w a r d ; 199 PROCEDURE s e t _ p 1 x e 1 ( y , x : i n t e g e r ) ; f o r w a r d ; 2 0 0 PROCEDURE d d a ( x 1 , y 1 , x 2 , y 2 : i n t e g e r ) ; f o r w a r d ; 201 PROCEDURE r e m o v e _ t r a i 1 e r s ( V A R mat : b o o l _ m a t r i x ) ; f o r w a r d ; 2 0 2 PROCEDURE f i 1 l _ p o l y g o n ( m i n _ x , m a x _ x , m i n _ y , m a x _ y : I n t e g e r ; mat : b o o l _ m a t r 1 x ) ; f o r w a r d ; 2 0 3 PROCEDURE b l a n k _ o u t (VAR mat : b o o l _ m a t r i x ; y 1 , x 1 , y 2 , x 2 , p i a n e : i n t e g e r ) ; f o r w a r d ; 204 PROCEDURE d r w _ a r r o w s ( V A R m a t : b o o l _ m a t r 1 x ; V A R m a r k e d : b o o l e a n ; r o w , x _ m 1 n , x _ m a x , p i a n e : i n t e g e r ) ; f o r w a r d ; 2 0 5 PROCEDURE d e l _ t a i l ( V A R work : b o o l _ m a t r i x ; i , p o s n , 1 a s t , p i a n e : i n t e g e r ) ; f o r w a r d ; 2 0 6 PROCEDURE d e l _ b i t s ( V A R work : b o o l _ m a t r i x ; r o w , p o s n , p i a n e : i n t e g e r ) ; f o r w a r d ; 2 0 7 PROCEDURE b e s t _ a r r o w ( V A R r o w , c o l : i n t e g e r ) ; f o r w a r d ; 2 0 8 PROCEDURE k i 1 1 _ p o l y _ i n _ s a v e ; f o r w a r d ; 2 0 9 PROCEDURE c o p y _ p o l y _ t o _ s a v e ; f o r w a r d ; 2 1 0 PROCEDURE g e t _ l a b e l ; f o r w a r d ; 211 PROCEDURE t a 1 l _ a n d _ d i s t 1 n c t n e s s _ c h e c k ; f o r w a r d ; 2 1 2 PROCEDURE r e a d _ a n d _ p r o c e s s ; f o r w a r d ; 2 1 3 PROCEDURE b a c k g r o u n d ( V A R mat : b o o l _ m a t r i x ; p l a n e , d i s p l : i n t e g e r ) ; f o r w a r d ; 214 PROCEDURE T R A N S ( a , b : t x t _ s t r ; c : i n t e g e r ) ; f o r t r a n ; 2 1 5 PROCEDURE p r i n t _ t e x t ( t x t : t x t _ s t r ; 1 e n , g n u m , s i z e , r i , c i , r f , c f : i n t e g e r ) ; f o r t r a n 'TXTOUT'; 216 PROCEDURE t a r g e t _ i n ( V A R r o w , c o l : i n t e g e r ) ; FORTRAN ' TARGIN'; 217 PROCEDURE c m t l _ c o m m a n d ( a : t x t _ s t r ; b : i n t e g e r ) ; f o r t r a n 'CMTLCM'; 218 2 1 9 2 2 0 F U N C T I O N f i r s t _ p t : p o i n t _ f o u n d ; f o r w a r d ; 221 F U N C T I O N s u b _ c o n v e r t ( x : i n t e g e r ) : i n t e g e r ; f o r w a r d ; 2 2 2 F U N CTION o f f _ c o n v e r t ( x : i n t e g e r ) i n t e g e r ; f o r w a r d ; 2 2 3 F U N CTION f i n d _ b i n a r y ( x , y , n e w _ x : i n t e g e r ; VAR n e x t _ x , n e x t _ y , d i s p l a c e : i n t e g e r ) : l o c a t i o n ; f o r w a r d ; 224 F U N C T I O N s a m e _ c o 1 ( x , y , 225 i n d . o f f i n t e g e r ; 226 VAR 227 s u b s c r i p t , 2 2 8 o f f s e t , 2 2 9 d i s p l a c e i n t e g e r ) : p o i n t _ f o u n d ; f o r w a r d ; 2 3 0 F U N CTION o t h e r _ c o l s ( x , y , 231 1 n d , o f f : I n t e g e r ; 2 3 2 VAR 23 3 s u b s c r i p t , 234 o f f s e t , 00 235 d i s p l a c e , CM 236 n e x t _ x , 237 n e x t _ y i n t e g e r ) : p o i n t _ f o u n d ; f o r w a r d ; 2 3 8 F U N CTION c h e c k _ c o n t r a c t ( i , j : i n t e g e r ) : b o o l e a n ; f o r w a r d ; 2 3 9 F U N CTION c h e c k _ e x p a n d ( i , j : I n t e g e r ) : b o o l e a n ; f o r w a r d ; 2 4 0 F U N C T I O N b a n d ( i , j : i n t e g e r ) : i n t e g e r ; e x t e r n a l 'BAND$$$$'; 241 F U NCTION s h i f t ( 1 , j : i n t e g e r ) : i n t e g e r ; e x t e r n a l ' S H I F T $ $ $ ' ; 2 4 2 F U N C T I O N b o r ( 1 , j : i n t e g e r ) : i n t e g e r ; e x t e r n a l 'BOR$$$$$'; 2 4 3 F U N C T I O N r o t a t e ( i , j : i n t e g e r ) : i n t e g e r ; e x t e r n a l 'ROTATE$$' ; 2 4 4 F U N C T I O N b x o r ( i , j : I n t e g e r ) : i n t e g e r ; e x t e r n a l 'BXOR$$$$'; 245 F U N C T I O N s h i f t r ( i , j i n t e g e r ) : i n t e g e r ; f o r w a r d ; 246 F U N C T I O N i n i t _ c o m t a 1 ( i _ o , g r a p h i c _ p 1 n : i n t e g e r ) : b o o l e a n ; f o r w a r d ; 2 4 7 F U N CTION g r a p h i c _ p l a n e ( 1 _ o , g r a p h i c _ p l n : i n t e g e r ) : i n t e g e r ; f o r w a r d ; 2 4 8 F U N C T I O N r e a d _ n u m : i n t e g e r ; f o r w a r d ; 2 4 9 F U N CTION r e a d _ d e c 1 ma 1 : r e a l ; f o r w a r d ; 2 5 0 F U N C T I O N c h r r ( v a l u : i n t e g e r ) : s t r i n g ; f o r w a r d ; 251 F U N C T I O N c ( s t r 1 , s t r 2 , s t r 3 , s t r 4 , s t r 5 : s t r i n g ) : s t r i n g ; f o r w a r d ; 2 5 2 F U N C T I O N q u e s t i o n ( q u e r y : s t r i n g ) : b o o l e a n ; f o r w a r d ; 2 5 3 F U N C T I O N t e s t ( v A R mat : b o o l _ m a t r i x ; i . j . k : i n t e g e r ) : b o o l e a n ; f o r w a r d ; 2 5 4 FUNCTION m a s k _ b i t ( b 1 t : i n t e g e r ) : i n t e g e r ; f o r w a r d ; 2 5 5 F U N CTION m a s k _ c o m p ( b 1 t : i n t e g e r ) : i n t e g e r ; f o r w a r d ; 2 5 6 F U N C T I O N e n d _ c h e c k ( V A R mat : b o o l _ m a t r i x ; r o w , k , t e m p , j , p l a n e : I n t e g e r ) : b o o l e a n ; f o r w a r d ; 2 5 7 F U N C T I O N t o p _ b o t _ c h e c k ( V A R mat : b o o l _ m a t r i x ; t e m p , i , r o w , j , p l a n e : i n t e g e r ) : b o o l e a n ; f o r w a r d ; 258 F U N C T I O N e v e n s _ c h e c k ( V A R w o r k : b o o l _ m a t r i x;y_mi n , y _ m a x , x _ m i n , x _ m a x , p l a n e : i n t e g e r ) : b o o l e a n ; f o r w a r d ; 2 5 9 2 6 0 261 PROCEDURE d e b u g _ d a t a ; 2 6 2 2 6 3 VAR 264 n u m b e r , i i n t e g e r ; 2 6 5 266 B E G I N 26 7 r e a d _ 1 n t ( 1 . d e b u g , ' S D e b u g l e v e l = ? ' , n u m b e r ) ; 26 8 FOR 1 := 1 TO d e b u g DO 2 6 9 I F i<=number THEN d e b u g g i n g ( . 1 . ) := t r u e 2 7 0 E L S E d e b u g g i n g ( . i . ) := f a l s e ; 271 w r i t e l n ( ' * * D e b u g g i n g t u r n e d o n **') 2 7 2 END; 2 7 3 2 7 4 2 7 5 PROCEDURE s k i p _ c h a r ( s k i p c h a r s : c h a r s e t ) ; 2 7 6 277 { T o s k i p o v e r c h a r a c t e r s i n i n p u t _ b u f f e r . } 278 279 B E G I N 2 8 0 WHILE i n p u t _ b u f f e r ( . i n p u t _ 1 n d e x . ) IN s k i p c h a r s AND 281 1 n p u t _ i n d e x <= b u f f e r _ l e n g t h DO 2 8 2 i n c r ( i n p u t _ 1 n d e x ) 2 8 3 END; 284 285 286 F U N CTION r e a d _ n u m : i n t e g e r ; 2 8 7 2 8 8 { R e a d s a n i n t e g e r o u t o f i n p u t _ b u f f e r s t a r t i n g a t t h e } 2 8 9 { l o c a t i o n 1 n p u t _ i n d e x . I f t h e r e i s no v a l i d number, i t } 2 9 0 { w i l l r e t u r n 0. } 291 292 CONST 293 n e g _ s i g n = '-'; 294 00 295 VAR 29 6 v a l i n t e g e r ; 297 298 B E G I N 299 n e g a t i v e _ n u m := f a l s e ; 3 0 0 v a l := 0; 301 3 0 2 I F i n p u t _ b u f f e r ( . 1 n p u t _ 1 n d e x . ) = n e g _ s 1 g n AND 303 1 n p u t _ i n d e x <= b u f f e r _ l e n g t h THEN 304 B E G I N 3 0 5 n e g a t 1 v e _ n u m := t r u e ; 306 i n c r ( 1 n p u t _ i n d e x ) 307 END; 308 309 WHILE i n p u t _ b u f f e r ( . 1 n p u t _ 1 n d e x . ) IN d i g i t s AND 3 1 0 i n p u t _ i n d e x <= b u f f e r _ l e n g t h DO 311 B E G I N 312 v a l := v a l * b a s e + o r d ( i n p u t _ b u f f e r ( . 1 n p u t _ i n d e x . ) ) - z e r o ; 3 1 3 1 n c r ( 1 n p u t _ 1 n d e x ) 314 END; 315 316 I F n e g a t 1 v e _ n u m THEN 317 v a l := - v a l ; 318 3 1 9 I F d e b u g g 1 n g ( . 3 . ) THEN w r i t e l n ( ' r e a d _ n u m r e t u r n i n g : ' . v a l ) ; 3 2 0 r e a d _ n u m := v a l 321 END; 322 323 324 FUNCTION r e a d _ d e d m a l : r e a l ; 3 25 326 { R e a d s a f r a c t i o n o u t o f i n p u t _ b u f f e r s t a r t i n g a t t h e ) 327 { l o c a t i o n i n p u t _ i n d e x . I f t h e r e i s no d e c i m a l p o i n t o r } 328 { v a l i d number i t w i l l r e t u r n 0. ) 329 3 3 0 VAR 331 v a l : r e a l ; 332 d i v i s o r i n t e g e r ; 333 334 B E G I N 335 v a l := O; 336 d i v i s o r := b a s e ; 337 338 I F i n p u t _ b u f f e r ( . i n p u t _ i n d e x . ) = '.' THEN 3 3 9 B E G I N 3 4 0 1 n c r ( 1 n p u t _ i n d e x ) ; 341 342 WHILE 1 n p u t _ b u f f e r ( . 1 n p u t _ i n d e x . ) IN d i g i t s AND 343 1 n p u t _ 1 n d e x <= b u f f e r _ l e n g t h DO 344 B E G I N 345 v a l := va'l + 3 4 6 ( o r d ( i n p u t _ b u f f e r ( . 1 n p u t _ 1 n d e x . ) ) - z e r o ) / 347 d i v i s o r ; 348 d i v i s o r := d i v i s o r * b a s e ; 349 1 n c r ( 1 n p u t _ 1 n d e x ) 3 5 0 END 351 END; 352 3 5 3 I F n e g a t i v e _ n u m THEN 354 v a l := - v a l ; 00 355 oo 356 I F d e b u g g i n g ( . 3 . ) THEN w r i t e l n ( ' r e a d _ d e c r e t u r n i n g : ', v a l ) ; 357 3 5 8 r e a d d e c i m a l := v a l 3 5 9 END; 3 6 0 361 362 PROCEDURE r e a d _ 1 n t ( m i n , m a x : I n t e g e r ; q u e r y : s t r i n g ; VAR v a l u : i n t e g e r ) ; 3 6 3 364 { T h i s p r o c e d u r e e x t r a c t s a n i n t e g e r number f r o m t h e I n p u t b u f f e r } 3 6 5 3 6 6 VAR o _ k : b o o l e a n ; 3 67 368 B E G I N 369 s i g n o f f := f a l s e ; 3 7 0 o _ k : = F A L S E ; 371 3 7 2 WHILE NOT o_k DO 3 7 3 B E G I N 374 W R I T E L N ( q u e r y ) ; 375 r e a d _ b u f f e r ; 3 76 I F b u f f e r _ l e n g t h < > 0 3 77 THEN 378 B E G I N 379 v a l u : = r e a d _ n u m ; 3 8 0 I F i n p u t _ b u f f e r ( . i n p u t _ 1 n d e x . ) = '' 381 THEN 382 IF ( m i n < = v a l u ) AND ( v a l u < = m a x ) 3 8 3 THEN o_k:=TRUE 384 E L S E c o m p l a i n ( 1 i m i t _ e r r o r ) { o u t s i d e v a l i d r a n g e ) 3 8 5 EL S E c o m p l a i n ( b a d _ d a t a ) { i n v a l i d i n p u t d a t a } 386 END 387 E L S E 388 B E G I N 389 s i g n o f f := t r u e ; 3 9 0 o_k:=TRUE 391 END 3 9 2 END 3 9 3 END; 394 3 9 5 3 9 6 PROCEDURE r e a d _ r l ( m i n , m a x : r e a l ; q u e r y : s t r i n g ; VAR v a l u : r e a l ) ; 3 9 7 398 { T h i s p r o c e d u r e e x t r a c t s a r e a l number f r o m t h e i n p u t b u f f e r } 3 9 9 4 0 0 VAR o_k : b o o l e a n ; 401 4 0 2 B E G I N 4 0 3 o _ k : = F A L S E ; 404 s i g n o f f := f a l s e ; 4 0 5 406 WHILE NOT o_k DO 4 0 7 B E G I N 4 0 8 W R I T E L N ( q u e r y ) ; 4 0 9 r e a d _ b u f f e r ; 4 1 0 I F b u f f e r _ l e n g t h o O 411 THEN 4 1 2 B E G I N 4 1 3 v a l u : = r e a d _ n u m + r e a d _ d e c i m a l ; 414 I F 1 n p u t _ b u f f e r ( . i n p u t _ 1 n d e x . ) =, ' ' oo 4 1 5 THEN <D 4 1 6 IF ( m i n < = v a l u ) AND ( v a l u < = m a x ) 4 1 7 THEN o_k:=TRUE 418 E L S E c o m p l a i n ( 1 i m i t _ e r r o r ) { o u t s i d e v a l i d r a n g e } 4 1 9 E L S E c o m p l a i n ( b a d _ d a t a ) ( i n v a l i d i n p u t d a t a } 4 2 0 END 421 E L S E 4 2 2 B E G I N 4 2 3 s i g n o f f := t r u e ; 424 o_k:=TRUE 4 2 5 END 4 2 6 END 4 2 7 END; 4 2 8 4 2 9 4 3 0 F U N C T I O N c h r r ( v a l u : i n t e g e r ) : s t r i n g ; 431 4 3 2 VAR t e m p . i . j : i n t e g e r ; 4 3 3 434 B E G I N 4 3 5 c h r r : = ' ' ; 436 1:=0; 437 t e m p : = v a l u ; 4 3 8 R E P E A T 4 3 9 temp:=temp DIV b a s e ; 4 4 0 i : = i + 1 441 U N T I L temp=0; 442 FOR j:=1 DOWNTO 1 DO 4 4 3 B E G I N 444 t e m p : = v a l u MOD b a s e ; 4 4 5 v a l u : = v a l u DIV b a s e ; 4 4 6 c h r r ( . j . ) := C H R ( t e m p + z e r o ) ; 4 4 7 END 448 END; 4 4 9 4 5 0 451 PROCEDURE p a c k ( V A R t o _ s t r 1 n g : s t r i n g ; f r o m _ s t r i n g : s t r i n g ; VAR s t a r t : i n t e g e r ) ; 452 4 5 3 VAR 454 1 e n _ t e m p _ s t r , p o s : i n t e g e r ; 4 5 5 456 B E G I N 4 5 7 1 e n _ t e m p _ s t r : = 1 i n e _ l e n g t h - 1 ; 458 WHILE ( f r o m _ s t r i n g ( . 1 e n _ t e m p _ s t r . ) = ' ') AND ( 1 e n _ t e m p _ s t r > = 1 ) DO 1 e n _ t e m p _ s t r : = 1 e n _ t e m p _ s t r - 1 ; 459 p o s : = 0 ; 4 6 0 WHILE ( ( s t a r t + p o s ) < = l i n e _ l e n g t h - 1 ) AND ( p o s < = 1 e n _ t e m p _ s t r ) DO 461 B E G I N 462 t o _ s t r i n g ( . s t a r t + p o s . ) := f r o m _ s t r i n g ( . p o s . ) ; 4 6 3 p o s : = p o s + 1 464 END; 4 6 5 I F ( s t a r t + p o s ) < = l i n e _ l e n g t h THEN t o _ s t r 1 n g ( . s t a r t + p o s . ) : = ' '; 4 6 6 s t a r t : = s t a r t + 1 e n _ t e m p _ s t r + 2 4 6 7 END; 4 6 8 4 6 9 4 7 0 F U NCTION c ( s t r 1 , s t r 2 , s t r 3 , s t r 4 , s t r 5 : s t r i n g ) : s t r i n g ; 471 4 7 2 CONST 4 7 3 U = ' ? X ? X ? X ? X ? X ' ; 474 4 7 5 ° 4 7 6 VAR w o r k s t r i n g : s t r i n g ; 4 7 7 s t a r t : I n t e g e r ; 4 7 8 4 7 9 B E G I N 4 8 0 s t a r t : = 0 ; 481 w o r k s t r 1 n g : = ' '; 4 8 2 I F s t r l o U THEN p a c k ( w o r k s t r 1 n g , s t r 1 , s t a r t ) ; 4 8 3 I F s t r 2 < > U THEN p a c k ( w o r k s t r 1 n g , s t r 2 , s t a r t ) ; 4 8 4 I F s t r 3 < > U THEN p a c k ( w o r k s t r i n g , s t r 3 , s t a r t ) ; 4 8 5 I F s t r 4 < > U THEN p a c k ( w o r k s t r i n g , s t r 4 , s t a r t ) ; 4 8 6 I F s t r 5 < > U THEN p a c k ( w o r k s t r i n g , s t r 5 , s t a r t ) ; 4 8 7 c : = w o r k s t r i n g 4 8 8 END; 4 8 9 4 9 0 491 PROCEDURE r e a d _ b u f f e r ; 492 4 9 3 { T h i s p r o c e d u r e r e a d s t h e n e x t l i n e o f i n p u t f r o m t h e 494 4 9 5 VAR 4 9 6 c h : c h a r ; 4 9 7 o_k : b o o l e a n ; 4 9 8 4 9 9 B E G I N 5 0 0 o_k := f a 1 s e ; 501 i n p u t _ b u f f e r := b l a n k ; 5 0 2 5 0 3 WHILE NOT o k DO 504 B E G I N 5 0 5 I F e o l n THEN r e a d ( c h ) ; 5 0 6 507 i n p u t _ b u f f e r := ''; 508 i n p u t _ i n d e x := 1; 5 0 9 e r r o r _ i n d e x := 1 ; 5 1 0 b u f f e r _ l e n g t h := 0; 51 1 51 2 WHILE b u f f e r l e n g t h < l i n e l e n g t h AND 5 1 3 NOT e o l n AND 514 NOT e o f DO 5 1 5 B E G I N 5 1 6 i n c r ( b u f f e r _ l e n g t h ) ; 5 17 r e a d ( i n p u t b u f f e r ( . b u f f e r l e n g t h . ) ) 5 1 8 END; 5 1 9 5 2 0 I F 1 n p u t _ b u f f e r = b l a n k THEN 521 b u f f e r _ l e n g t h := 0; 522 5 2 3 I F b u f f e r l e n g t h = l i n e l e n g t h AND 524 NOT e o l n THEN 5 2 5 B E G I N 5 2 6 o_k := f a l s e ; 5 2 7 r e a d l n ; 528 w r i t e l n ( ' & I n p u t l i n e e x c e e d s a l l o w a b l e l e n g t h 5 2 9 w r i t e l n ( ' 0 ' , i n p u t b u f f e r ) 5 3 0 END 531 E L S E 532 o k := t r u e 5 3 3 END; 534 5 3 5 I F d e b u g g i n g * . 1 0 . ) THEN 5 3 6 B E G I N 537 w r i t e l n ( ' === f r o m r e a d b u f f e r ==='); 538 w r i t e l n ( ' i n p u t _ 1 n d e x ', i n p u t _ i n d e x ) ; n a l } 1i n e _ l e n g t h ) 5 3 9 w r i t e l n ( ' e r r o r _ i n d e x : ', e r r o r _ 1 n d e x ) ; 5 4 0 w r i t e l n ( ' b u f f e r _ l e n g t h ', b u f f e r _ l e n g t h ) ; 541 w r i t e l n ( ' ok ? ', o _ k ) 5 4 2 END 5 4 3 END; 544 5 4 5 5 4 6 F U N CTION q u e s t i o n ( q u e r y : s t r i n g ) : b o o l e a n ; 547 548 { A s k a q u e s t i o n a n d g e t a y e s o r no a n s w e r . ) 5 4 9 5 5 0 VAR 551 o_k : b o o l e a n ; 552 5 5 3 B E G I N 554 o_k := f a l s e ; 5 5 5 5 5 6 WHILE NOT o_k DO 5 5 7 B E G I N 558 WRITELN; 55 9 w r i t e l n ( q u e r y ) ; 5 6 0 r e a d _ b u f f e r ; 561 5 6 2 I F b u f f e r _ l e n g t h = O OR 5 6 3 i n p u t _ b u f f e r = 'N' OR 564 i n p u t _ b u f f e r = 'n' OR 5 6 5 i n p u t _ b u f f e r = 'NO' OR 5 6 6 i n p u t _ b u f f e r = 'no' THEN 567 B E G I N 568 o_k := t r u e ; 5 6 9 q u e s t i o n := f a l s e 5 7 0 END 571 E L S E 572 I F i n p u t _ b u f f e r = 'Y' OR 5 7 3 1 n p u t _ b u f f e r = 'y' OR 574 i n p u t _ b u f f e r = 'YE' OR 5 7 5 i n p u t _ b u f f e r = ' y e ' OR 5 7 6 i n p u t _ b u f f e r = 'YES' OR 5 7 7 i n p u t _ b u f f e r = ' y e s ' THEN 578 B E G I N 5 7 9 o_k := t r u e ; 5 8 0 q u e s t i o n := t r u e 581 END 5 8 2 E L S E 5 8 3 c o m p l a i n ( b a d _ d a t a ) 584 END; 5 8 5 WRITELN 586 END; 587 5 8 8 5 8 9 PROCEDURE c o m p l a i n ( m e s s a g e : c o m p l a i n t ) ; 5 9 0 591 { T h i s p r o c e d u r e i s s u e s e r r o r m e s s a g e s } 59 2 5 9 3 B E G I N 594 w r i t e l n ; ^ 5 9 5 w r 1 t e ( ' * * * * ' ) ; N) 5 9 6 597 C ASE m e s s a g e OF 598 b a d _ d a t a : W R I T E ( ' I N V A L I D INPUT D A T A ' ) ; 5 9 9 l i m i t _ e r r o r : W R I T E ( ' I N P U T L I M I T S E X C E E D E D ' ) ; 6 0 0 i o _ e r r o r : W R I T E ( ' I / 0 e r r o r i n p r o c e s s i n g f i l e ' ) ; 6 0 1 c a n c e l l e d : WRITE('Command c a n c e l l e d ' ) ; 6 0 2 b a d _ c o m n d : W R I T E ( ' I n v a 1 i d COMMAND'); 6 0 3 END; 604 6 0 5 w r i t e l n ( ' * * * * ' ) ; 6 0 6 w r i t e l n 6 0 7 END; 6 0 8 6 0 9 PROCEDURE r e a d _ t e x t ( q u e r y : s t r i n g ; VAR r e t u r n _ t e x t : t x t _ s t r ) ; 6 1 0 611 VAR 6 1 2 j , i i n t e g e r ; 6 1 3 6 1 4 B E G I N 6 1 5 w r i t e l n ( q u e r y ) ; 6 1 6 r e a d _ b u f f e r ; 6 1 7 I F i n p u t _ b u f f e r <> ' ' THEN 6 1 8 B E G I N 6 1 9 j ;= s t r _ l e n g t h ; 6 2 0 I F i n p u t _ b u f f e r ( . j . ) = " THEN REPEAT 621 j := j - 1 6 2 2 U N T I L i n p u t _ b u f f e r ( . j . ) <> ''; 6 2 3 FOR i := 1 TO j DO r e t u r n _ t e x t ( . i . ) := i n p u t _ b u f f e r ( . 1 . ) ; 6 2 4 END 6 2 5 END; 6 2 6 6 2 7 6 2 8 6 2 9 6 3 0 PROCEDURE 1 i n k _ t o _ 1 i S t ( i : i n t e g e r ) ; 631 6 3 2 { T h i s p r o c e d u r e l i n k s a new p o l y g o n e l e m e n t t o t h e l i s t o f p o l y g o n v e r t i c e s . } 6 3 3 634 VAR 6 3 5 x : @ > p o l y _ e l t ; 6 3 6 6 3 7 B E G I N 6 3 8 WITH p o l y g o n ( . i . ) DO 6 3 9 B E G I N 6 4 0 I F p o o l _ p t r <> n i l 641 THEN 6 4 2 B E G I N 6 4 3 x := p o o l _ p t r ; 6 4 4 p o o l _ p t r := x @ . p o l y _ p t r 6 4 5 END 6 4 6 E L S E n e w ( x ) ; 6 4 7 6 4 8 I F p o l y g o n ( . i . ) . b a s e _ p t r = n i l 6 4 9 THEN 6 5 0 B E G I N 651 x @ . p o l y _ p t r := n i l ; 6 5 2 b a s e _ p t r := x; 6 5 3 g e n _ p t s ( . i . ) := x; 6 5 4 END 6 5 5 E L S E W 6 5 6 B E G I N 6 5 7 x @ . p o l y _ p t r := n i l ; 6 5 8 g e n _ p t s ( . i . ) @ . p o l y _ p t r := x; 6 5 9 g e n _ p t s ( . 1 . ) := x 6 6 0 END 661 . END 662 END; 6 6 3 664 PROCEDURE r e t u r n _ t o _ p o o 1 ( i : I n t e g e r ) ; 6 6 5 6 6 6 { T h i s p r o c e d u r e r e t u r n s a l i n k e d l i s t t o t h e g e n e r a l p o o l o f s t o r a g e . } 6 6 7 6 6 8 VAR 6 6 9 x : @ p o l y _ e l t ; 6 7 0 j : i n t e g e r ; 671 6 7 2 B E G I N 6 7 3 WITH p o l y g o n ( . 1 . ) DO 6 7 4 B E G I N 6 7 5 WHILE b a s e _ p t r <> n i l DO 6 7 6 B E G I N 677 x := b a s e _ p t r ; 6 7 8 b a s e _ p t r := b a s e _ p t r @ . p o l y _ p t r ; 6 7 9 x @ . p o l y _ p t r := p o o l _ p t r ; 6 8 0 p o o l _ p t r := x 681 END; 682 6 8 3 p o l y g o n ( . i . ) . d e s c r i p t _ p o s n . y := 0; 684 p o l y g o n ( . i . ) . d e s c r i p t _ p o s n . x := 0; 6 8 5 p o l y g o n ( . 1 . ) . s i z e := 0; 6 8 6 FOR j := 1 TO s t r _ l e n g t h DO p o l y g o n ( . 1 . ) . p o l y _ d e s c r i p t ( . j . ) := n u l ; 6 8 7 END 6 8 8 END; 6 8 9 6 9 0 691 PROCEDURE 1 n s e r t _ p o i n t ( i , x , y : i n t e g e r ) ; 6 9 2 6 9 3 B E G I N 694 1 i n k _ t o _ l i s t ( 1 ) ; 6 9 5 6 9 6 g e n _ p t s ( . i . ) @ . p o l y _ x :=x; 6 9 7 g e n _ p t s ( . i . ) @ . p o l y _ y :=y; 6 9 8 END; 6 9 9 7 0 0 701 PROCEDURE c 1 o s e _ p o 1 y g o n ( 1 : i n t e g e r ) ; 702 703 { T h i s p r o c e d u r e c l o s e s a m i n i m a l p o l y g o n by p a s s i n g i t s v e r t i c e s i n p a i r s 704 t o a DDA. } 7 0 5 7 0 6 VAR 707 x 1 , y 1 , 7 0 8 x 2 , y 2 : i n t e g e r ; 7 0 9 7 1 0 B E G I N 711 WITH p o l y g o n ( . 1 . ) DO 712 B E G I N 713 g e n _ p t r := b a s e _ p t r ; 714 U> 715 I F g e n _ p t r @ > . p o l y _ p t r <> n i l THEN 7 1 6 REPEAT 7 1 7 x1 := gen_ptr@>. p o l y _ x ; 71 8 y1 := g e n _ p t r @ . p o l y _ y ; 7 1 9 7 2 0 g e n _ p t r := g e n _ p t r @ . p o l y _ p t r ; 721 722 x2 := g e n _ p t r @ . p o l y _ x ; 7 2 3 y 2 := g e n _ p t r @ . p o 1 y _ y ; 724 7 2 5 726 d d a ( x 1 , y 1 , x 2 , y 2 ) 7 2 7 U N T I L g e n _ p t r @ . p o l y _ p t r = n i l 7 2 8 END; 7 2 9 7 3 0 I F d e b u g g i n g * . 2 . ) THEN 731 B E G I N 732 w r i t e l n ; 7 3 3 w r i t e l n ( ' F o r p o l y g o n # : ' , 1 : 0 ) ; 734 w r i t e l n ; 7 3 5 c o p y _ m a t ( w o r k _ m a t r i x , w o r k _ m a t r i x , b a c k ) 7 3 6 END 737 END; 738 739 7 4 0 PROCEDURE s e t _ p i x e l ( y , x : i n t e g e r ) ; 741 742 B E G I N 743 s e t _ b i t ( s a v e _ m a t r i x , y , x, f r o n t ) 744 END; 745 7 4 6 7 4 7 ' PROCEDURE d d a ( x 1 , y 1 , x 2 , y 2 : i n t e g e r ) ; 748 7 4 9 { T h i s p r o c e d u r e i m p l e m e n t s t h e s i m p l e ' d i g i t a l d i f f e r e n t i a l a n a l y s e r ' a s 7 5 0 d e s c r i b e d b y Newman a n d S p r o u l 1 i n t h e i r b o o k ' P r i n c i p l e s o f I n t e r a c t i v e 751 G r a p h i c s ' . T h i s a l g o r i t h m a c h i e v e s t h e same a c c u r a c y a s t h e ' s y m m e t r i c a l ' 752 a l g o r i t h m d e s c r i b e d i n t h e same b o o k , b u t i s more s u i t e d t o s o f t w a r e 7 5 3 i m p l e m e n t a t i o n , e a c h i t e r a t i o n r e q u i r i n g o n l y two a d d i t i o n s . } 754 755 VAR 7 5 6 l e n g t h , 757 1 : i n t e g e r ; 7 5 8 x , y , 7 5 9 x _ i n c r , 7 6 0 y _ i n c r : r e a l ; 761 7 6 2 B E G I N 7 6 3 I F ( x K > x 2 ) OR ( y K > y 2 ) THEN 764 B E G I N 7 6 5 l e n g t h := m a x ( a b s ( x 2 - x 1 ) , a b s ( y 2 - y 1 ) ) ; 766 767 x _ i n c r := ( x 2 - x 1 ) / 1 e n g t h ; 7 6 8 y _ 1 n c r := ( y 2 - y 1 ) / 1 e n g t h ; 7 6 9 7 7 0 x := x1 + 0.5; 771 y := y1 + 0.5; 7 7 2 7 7 3 FOR i := 1 TO l e n g t h DO 774 B E G I N 7 7 5 s e t _ b i t ( w o r k _ m a t r i x, t r u n c ( y ) , t r u n c ( x ) , b a c k ) ; (- n 7 7 6 7 7 7 x := x + x _ i n c r ; 7 7 8 y := y + y _ i n c r 779 END ; 7 8 0 END; 781 782 I F d e b u g g i n g ( . 2 . ) THEN w r i t e l n ( y 1 : 4 , x 1 : 4 , ' ' , y 2 : 4 , x 2 : 4 ) 783 END; 784 785 PROCEDURE r e m o v e _ t r a i 1 e r s ( V A R mat : b o o 1 _ m a t r 1 x ) ; 7 8 6 787 VAR 788 i . j . k : i n t e g e r ; 7 8 9 c o u n t : I n t e g e r ; . 7 9 0 791 B E G I N 792 FOR k := 1 TO t r a i l e r s DO 793 B E G I N 794 m a t _ 1 n i t ( m a t r i x , b a c k ) ; 795 796 FOR 1 := s t TO y _ r e s o l u t i o n DO 797 B E G I N 798 FOR j := s t TO x _ r e s o l u t i o n DO 7 9 9 B E G I N 8 0 0 I F t e s t ( m a t , 1 , j . b a c k ) THEN 801 B E G I N 802 c o u n t := 0; 8 0 3 I F t e s t ( m a t , i - 1 , j - 1 , b a c k ) THEN c o u n t := c o u n t + 1 ; 804 I F t e s t ( m a t , 1 + 1 , j + 1 . b a c k ) THEN c o u n t := c o u n t + 1 ; 8 0 5 I F t e s t ( m a t , 1 - 1,j . b a c k ) AND ( c o u n t < 2 ) THEN c o u n t := c o u n t + 1 ; 8 0 6 I F t e s t ( m a t , 1 + 1 , j , b a c k ) AND ( c o u n t < 2 ) THEN c o u n t := c o u n t + 1 ; 807 I F t e s t ( m a t , i - 1,j + 1 , b a c k ) AND ( c o u n t < 2 ) THEN c o u n t := c o u n t + 1 ; 8 0 8 I F t e s t ( m a t , i + 1 , j - 1 . b a c k ) AND ( c o u n t < 2 ) THEN c o u n t := c o u n t + 1 ; 8 0 9 . IF t e s t ( m a t , i , j - 1 , b a c k ) AND ( c o u n t < 2 ) THEN c o u n t := c o u n t + 1 ; 8 1 0 I F t e s t ( m a t , i , j + 1 , b a c k ) AND ( c o u n t < 2 ) THEN c o u n t := c o u n t + 1 ; 811 I F c o u n t > 1 THEN s e t _ b i t ( m a t r i x , i , j , b a c k ) 8 1 2 END 8 1 3 END 814 END; 8 1 5 c o p y _ m a t ( m a t , m a t r i x , b a c k ) 8 1 6 END 817 END; 8 1 8 8 1 9 8 2 0 FUNCTION e n d _ c h e c k ( V A R mat : b o o l _ m a t r i x ; r o w , k , t e m p , j , p i a n e : i n t e g e r ) : b o o l e a n ; 821 8 2 2 { T h i s f u n c t i o n i s s e t t o t r u e i f t h e c u r r e n t p i x e l - s t r i n g i s p a r t o f a 8 2 3 p o l y g o n e d g e , i e . , i t c o n t i n u e s i n t h e d i r e c t i o n b e i n g c h e c k e d . } 824 8 2 5 B E G I N 8 2 6 e n d _ c h e c k := f a l s e ; 8 2 7 8 2 8 I F temp = j { o n l y o n e p o i n t i n a row > 8 2 9 THEN 8 3 0 I F ( t e s t ( m a t , r o w + k , j - 1 , p i a n e ) OR t e s t ( m a t , r o w + k , j , p i a n e ) OR 831 t e s t ( m a t , r o w + k , j + 1 , p i a n e ) ) 832 THEN e n d _ c h e c k := t r u e 8 3 3 E L S E ; 834 E L S E ^ 8 3 5 I F ( t e s t ( m a t , r o w + k , t e m p - 1 , p i a n e ) OR t e s t ( m a t , r o w + k , t e m p , p i a n e ) OR CM 8 3 6 t e s t ( m a t , r o w + k , t e m p + 1 , p i a n e ) OR 8 3 7 t e s t ( m a t , r o w + k , j - 1 , p i a n e ) OR t e s t ( m a t , r o w + k , j , p i a n e ) OR 83 8 t e s t ( m a t , r o w + k , j + 1 . p l a n e ) ) 8 3 9 THEN e n d _ c h e c k := t r u e 8 4 0 END; 841 842 FUNCTION t o p _ b o t _ c h e c k ( V A R mat : b o o l _ m a t r i x ; t e m p , i , r o w , j , p l a n e : I n t e g e r ) : b o o l e a n ; 8 4 3 844 { T h i s f u n c t i o n i s s e t t o t r u e i f t h e p i x e l s b e i n g c h e c k e d d o n o t b e l o n g 8 4 5 t o a n u p p e r o r l o w e r a r c - d e p e n d i n g o n w h i c h d i r e c t i o n i s b e i n g c h e c k e d . 846 I f t h e c u r r e n t s t r i n o f p i x e l s d o e s b e l o n g t o a n a r c , t h e n t h e f u n c t i o n i s 847 s e t t o f a l s e . } 8 4 8 8 4 9 VAR 8 5 0 f o u n d , 851 b r e a k : b o o l e a n ; 852 k, 853 c o u n t : i n t e g e r ; 854 8 5 5 B E G I N 8 5 6 f o u n d := f a l s e ; 8 5 7 b r e a k := f a l s e ; 8 58 c o u n t := 0; 8 5 9 8 6 0 k := temp - 2; 861 862 REPEAT 8 6 3 k := k+1; 864 I F t e s t ( m a t , i + r o w , k , p l a n e ) AND NOT f o u n d 8 6 5 THEN 8 6 6 B E G I N 867 f o u n d := t r u e ; 8 6 8 c o u n t := c o u n t + 1 8 6 9 END : 8 7 0 E L S E 871 I F NOT t e s t ( m a t , i + r o w , k , p l a n e ) AND f o u n d 872 THEN 873 B E G I N 874 b r e a k := t r u e ; 8 7 5 f o u n d := f a l s e 8 76 END 877 U N T I L ( b r e a k AND ( c o u n t = . 2 ) ) OR ( k = J + 1 ) ; 8 7 8 8 7 9 I F b r e a k AND ( c o u n t = 2 ) THEN t o p _ b o t _ c h e c k := f a l s e 8 8 0 E L S E t o p _ b o t _ c h e c k := t r u e 881 END; 882 883 884 PROCEDURE f i 1 l _ p o l y g o n ( m i n _ x , m a x _ x , m i n _ y , m a x _ y : i n t e g e r ; mat : b o o l _ m a t r i x ) ; 8 8 5 8 8 6 CONST 887 a b o v e = - 1 ; 888 b e l o w = +1; 8 8 9 8 9 0 VAR 891 beam : b o o l e a n ; 892 1 , j 1 n t e g e r ; 8 9 3 c o u n t : i n t e g e r ; 8 9 4 temp i n t e g e r ; 8 9 5 s : i n t e g e r ; 8 9 6 c h a n g e : b o o l e a n ; 8 97 B E G I N 898 r e m o v e _ t r a i l e r s ( m a t ) ; 8 9 9 m a t _ 1 n i t ( m a t , f r o n t ) ; 9 0 0 901 FOR 1 := m1n_y TO max_y DO 9 0 2 B E G I N 9 0 3 beam := f a l s e ; 9 0 4 c o u n t := 0; 9 0 5 9 0 6 I F d e b u g g i n g * .5. ) THEN w r i t e . l n ; 9 0 7 9 0 8 j := m i n _ x - 1 ; 9 0 9 9 1 0 WHILE j < max_x DO 911 B E G I N 912 j : = j + 1; 9 1 3 914 I F t e s t ( m a t , i , j , b a c k ) THEN 9 1 5 B E G I N 91 6 temp := j ; 9 1 7 WHILE t e s t ( m a t , i , j + 1 , b a c k ) DO 9 1 8 B E G I N 9 1 9 s e t _ p i x e l ( i , j ) ; 9 2 0 j := j + 1 921 END; 9 2 2 9 2 3 I F e n d _ c h e c k ( m a t , 1 , a b o v e , t e m p , j , b a c k ) AND e n d _ c h e c k ( m a t , i , b e i o w , t e m p , j , b a c k ) 924 THEN . 9 2 5 B E G I N 92 6 c h a n g e := t o p _ b o t _ c h e c k ( m a t , t e m p , i , a b o v e , j , b a c k ) ; 9 2 7 9 2 8 I F c h a n g e THEN c h a n g e := t o p _ b o t _ c h e c k ( m a t , t e m p , 1 , b e 1 o w , j , b a c k ) ; 9 2 9 9 3 0 I F c h a n g e THEN beam := NOT beam 931 END 9 3 2 END; 9 3 3 9 3 4 I F beam THEN s e t _ p i x e l ( 1 , j ) 9 3 5 E L S E I F t e s t ( m a t , i , j , b a c k ) THEN s e t _ p i x e l ( i , j ) 9 3 6 END 9 3 7 END; 9 3 8 I F d e b u g g i n g ( . 5 . ) THEN w r i t e l n 9 3 9 END; 9 4 0 941 F U NCTION t e s t ( V A R mat : b o o l _ m a t r 1 x ; i , j , k : i n t e g e r ) : b o o l e a n ; 9 4 2 9 4 3 { T h i s f u n c t i o n t e s t s w h e t h e r t h e i , j , k t h b i t o f t h e b i t - m a t r i x i s o n } 944 9 4 5 VAR 9 4 6 mask, 947 w o r d , 9 4 8 b i t : i n t e g e r ; 9 4 9 temp : b o o l e a n ; 9 5 0 951 B E G I N 952 j := j+C+1; 9 5 3 w o r d := ( j + w o r d _ s i z e _ 1 ) d i v w o r d _ s i z e ; 954 b i t := ( j + w o r d _ s i z e _ 1 ) mod w o r d _ s i z e ; ^ 9 5 5 co 9 5 6 mask := m a s k _ b i t ( b 1 t ) ; 9 5 7 9 5 8 I F b a n d ( m a t ( . i , w o r d , k . ) , m a s k ) < > 0 9 5 9 THEN temp := t r u e 9 6 0 E L S E temp := f a l s e ; 961 9 6 2 t e s t := temp; 9 6 3 964 I F d e b u g g i n g * . 7 . ) THEN 9 6 5 B E G I N 96 6 w r i t e l n ; 9 6 7 w r 1 t e l n ( ' * * * * D e b u g g i n g t e s t * * * * ' ) ; 9 6 8 w r i t e l n ( ' 1 , j , k = ' , i : 4 , j : 4 , k : 4 ) ; 9 6 9 w r i t e l n ( ' w o r d = ' . w o r d ) ; 9 7 0 w r i t e l n ( ' b 1 t = ' , b i t ) ; 971 w r 1 t e 1 n ( ' m a s k = ' . m a s k ) ; 972 w r i t e l n 9 7 3 END 974 END; 9 7 5 9 7 6 PROCEDURE s e t _ b i t ( V A R mat : b o o l _ m a t r i x ; i . j . k : i n t e g e r ) ; 9 7 7 9 7 8 { T h i s p r o c e d u r e s e t s a b i t i n t h e b i t - m a t r i x } 9 7 9 9 8 0 VAR 981 mask, 982 w o r d , 9 8 3 b i t : i n t e g e r ; 984 9 8 5 B E G I N 9 8 6 j := j+C+1; 98 7 w o r d := ( j + w o r d _ s i z e _ 1 ) d i v w o r d _ s i z e ; 9 8 8 b i t := ( j + w o r d _ s 1 z e _ 1 ) mod w o r d _ s i z e ; 9 8 9 9 9 0 mask := m a s k _ b i t ( b i t ) ; 991 9 9 2 m a t ( . i . w o r d . k . ) := b o r ( m a t ( . i , w o r d , k . ) , m a s k ) ; 9 9 3 994 I F d e b u g g i n g ( . 7 . ) THEN 9 9 5 B E G I N 99 6 w r i t e l n ; 9 9 7 w r i t e l n ( ' * * * * D e b u g g i n g s e t b i t * * * * ' ) ; 9 9 8 w r i t e l n ( ' m a t ( 1 , j , k ) = ' , m a t ( . 1 , w o r d , k . ) ) ; 9 9 9 w r i t e l n 1000 END 1001 END; 1002 1003 PROCEDURE u n s e t _ b i t ( V A R mat : b o o l _ m a t r i x ; i , j , k : i n t e g e r ) ; 1004 1005 { T h i s p r o c e d u r e s e t s a b i t i n t h e b i t - m a t r i x > 1006 1007 VAR 1008 mask, 1009 w o r d , 1010 b i t : I n t e g e r ; 1011 1012 B E G I N 1013 j := j+C+1; 1014 w o r d := ( j + w o r d _ s i z e _ 1 ) d i v w o r d _ s i z e ; vo 1015 b i t := ( j + w o r d _ s i z e _ 1 ) mod w o r d _ s i z e ; ^° 1016 1017 mask := m a s k _ c o m p ( b i t ) ; 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 m a t ( . i , w o r d , k . ) := b a n d ( m a t ( . 1 , w o r d , k . ) , m a s k ) ; I F d e b u g g i n g * . 7 . ) THEN B E G I N w r 1 t e l n ; w r i t e l n ( ' * * * * D e b u g g i n g s e t b i t * * * * ' ) ; w r 1 t e l n ( ' m a t ( i , j , k ) = ',mat (. 1 , w o r d , k . ) ) ; w r i t e l n END END; F U N C T I O N m a s k _ b i t ( b i t : i n t e g e r ) ; i n t e g e r ; { T h i s f u n c t i o n s e t s t h e a p p r o p r i a t e mask f o r a n y b i t s e t t i n g ( 0 - 3 1 ) B E G I N CASE 0 1 2 3 4 5 6 7 8 9 10 1 1 12 13 14 15 16 17 18 19 2 0 21 22 23 24 25 26 27 28 29 3 0 31 END END; b i t OF : mask : mask : mask : mask : mask : mask_ : mask : mask : mask : mask : mask_ : mask_ : mask : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ : mask_ { c a s e } b i t " b i t " b i t " b i t " b i t " b i t " b i t b i t " b i t ' b i t " b i t " b i t " b i t " b i t " b i t " b i t " b i t " b i t " b i t " b i t " b i t " b i t ' b i t b i t ' b i t b i t b i t b i t b i t b i t " b i t b i t 2 1 4 7 4 8 3 6 4 8 1 0 7 3 7 4 1 8 2 4 5 3 6 8 7 0 9 1 2 2 6 8 4 3 5 4 5 6 1 3 4 2 1 7 7 2 8 6 7 1 0 8 8 6 4 3 3 5 5 4 4 3 2 16777216 8 3 8 8 6 0 8 4 1 9 4 3 0 4 2 0 9 7 1 5 2 1048576 5 2 4 2 8 8 2 6 2 1 4 4 131072 6 5 5 3 6 3 2 7 6 8 16384 8192 4 096 2048 1024 512 256 128 64 32 16 8 4 2 1 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 1 1 10 9 8 7 6 5 4 3 2 1 0 FUNCTION m a s k _ c o m p ( b i t : i n t e g e r ) i n t e g e r ; { T h i s f u n c t i o n s e t s t h e a p p r o p r i a t e mask f o r a n y b i t s e t t i n g ( 0 - 3 1 ) O O B E G I N C A S E b i t OF 0 : mask_comp 2 1 4 7 4 8 3 6 4 7 ; { 2 31 } 1079 1 : mask_comp = - 1 0 7 3 7 4 1 8 2 5 ; { 2 30 1080 2 : mask_comp = - 5 3 6 8 7 0 9 1 3 ; { 2 29 1081 3 : mask_comp = - 2 6 8 4 3 5 4 5 7 ; { 2 28 1082 4 : mask_comp = - 1 3 4 2 1 7 7 2 9 ; { 2 27 1083 5 : mask_comp = - 6 7 1 0 8 8 6 5 ; { 2 26 1084 6 : mask_comp = - 3 3 5 5 4 4 3 3 ; { 2 25 1085 7 : mask_comp = - 1 6 7 7 7 2 1 7 ; { 2 24 1086 8 : mask_comp = - 8 3 8 8 6 0 9 ; { 2 23 1087 9 : mask_comp = - 4 1 9 4 3 0 5 ; { 2 22 1088 10 : mask_comp = - 2 0 9 7 1 5 3 ; { 2 21 1089 1 1 : mask_comp = - 1 0 4 8 5 7 7 ; { 2 20 1090 12 : mask_comp = - 5 2 4 2 8 9 ; { 2 19 1091 13 : mask_comp = - 2 6 2 1 4 5 ; { 2 18 1092 14 : mask_comp = - 1 3 1 0 7 3 ; { 2 17 1093 15 : mask_comp = - 6 5 5 3 7 ; { 2 16 1094 16 : mask_comp = - 3 2 7 6 9 ; { 2 15 1095 17 : mask_comp = - 1 6 3 8 5 ; { 2 14 1096 18 : mask_comp = - 8 1 9 3 ; { 2 13 1097 19 : mask_comp = - 4 0 9 7 ; { 2 12 1098 20 : mask_comp = - 2 0 4 9 ; { 2 1 1 1099 21 : mask_comp = - 1 0 2 5 ; { 2 10 1 100 22 : mask_comp = - 5 1 3 ; { 2 9 1 101 23 : mask_comp = - 2 5 7 ; I 2 8 1 102 24 : mask_comp = - 1 2 9 ; { 2 7 1 103 25 : mask_comp = - 6 5 ; [ 2 6 1 104 26 : mask_comp = -33; [ 2 5 1 105 27 : mask_comp = " 1 7 ; { 2 4 1 106 28 : mask_comp = - 9 ; I 2 3 1 107 29 : mask_comp = - 5 ; { 2 2 1 108 30 : mask_comp = " 3 ; { 2 1 1 109 31 : mask_comp = -2; { 2 0 1 1 10 END { c a s e } 1111 END; 1112 1113 1114 1115 PROCEDURE p r i m a r y i n i t i a l i z e ; 1 1 16 1117 VAR 1 1 18 i . j i n t e g e r ; 1 1 19 1 120 B E G I N 1121 a l r e a d y _ a c t i v e := f a l s e ; 1 122 m o r e t o come := t r u e ; 1 123 p t s e t no := 0; 1 124 d i g i t s := (.'0'. . '9' . ); 1 125 p o o l p t r := n i l ; 1 126 g r a p h := 1; 1 127 u n i t n o := u n i t n o ; 1 128 T R A N S ( ' E B C D I C TO A S C I I NONE:',' ' , 0 ) ; 1 129 1 130 cmt n i t l a l 1 z e ( u n i t n o , r e t c o d e ) ; 1131 w r i t e l n ; 1 132 C A S E r e t c o d e OF 1 133 0 w r i t e l n ( ' C o n n e c t i o n w i t h COMTAL 0 • K . ' ) ; 1 134 2 w r 1 t e l n ( ' E r r o r i n c o n e c t i o n w i t h COMTAL ); 1 135 3 w r 1 t e l n ( ' C O M T A L n o t o p e r a t i o n a l ' ) ; 1 136 <> w r 1 t e l n ( ' A n u n s p e c i f i e d e r r o r h a s o c c u r e d i n 1 i r 1 137 END; { c a s e } 1 138 w r i t e l n ; l i n k i n g MTS t o THE COMTAL') 1 139 1140 s e c o n d a r y _ i n i t i a l i z e ; 1141 t e r t i a r y _ i n i t i a l i z e ; 1 142 1143 m a t _ i n i t ( s a v e _ m a t r i x , b a c k ) ; 1144 m a t _ i n i t ( s a v e _ m a t r 1 x , f r o n t ) ; 1 145 1146 FOR i : = -1 TO m a x _ p o l y s DO 1147 B E G I N 1148 p o l y g o n ( . 1 . ) . b a s e _ p t r := n i l ; 1149 p o l y g o n * . 1 . ) . d e s c r i p t _ p o s n . y := 0; 1150 p o l y g o n * . 1 . ) . d e s c r i p t _ p o s n . x := 0; 1151 FOR j := 1 TO s t r _ l e n g t h DO p o l y g o n * . 1 . ) . p o l y _ d e s c r i p t ( . j . ) := n u 1 ; 1152 p o l y g o n * . i . ) . s 1 z e := 0; 1153 END; 1 154 1155 I F q u e s t i o n * ' & D e b u g d a t a ? ( Y / N ) ' ) THEN d e b u g _ d a t a ; 1156 r e a d _ 1 n t ( 1 , 1 0 , ' & M a x s i z e f o r smudges = ? ' , a c c _ s m u d g e ) ; 1157 END; 1 158 1 159 1160 PROCEDURE s e c o n d a r y _ i n i t i a 1 i z e ; 1 161 1162 VAR 1163 c h : c h a r ; 1 164 1,j i n t e g e r ; 1165 1166 B E G I N 1 167 1168 { i n i t i a l i z e b o r d e r o f ' m a t r i x ' } 1 169 1170 FOR j : = 1 TO C+1 DO 1171 B E G I N 1172 FOR i := s t - C - 1 TO x _ r e s o l u t 1 o n + C + 1 DO u n s e t _ b i t ( m a t r i x , s t - j , i , f r o n t ) ; 1173 FOR i := s t - C - 1 TO x _ r e s o l u t i o n + C + 1 DO u n s e t _ b 1 t ( m a t r i x , y _ r e s o l u t i o n + j , i , f r o n t ) ; 1174 FOR i := s t - C - 1 TO y _ r e s o l u t i o n + C + 1 DO u n s e t _ b 1 t ( m a t r i x , i , s t - j , f r o n t ) ; 1175 FOR 1 := s t - C - 1 TO y _ r e s o l u t i o n + C + 1 DO u n s e t _ b 1 t ( m a t r 1 x , i , x _ r e s o l u t i o n + j , f r o n t ) ; 1 176 1177 FOR i := s t - C - 1 TO x _ r e s o l u t i o n + C + 1 DO u n s e t _ b i t ( m a t r i x , s t - j , i , b a c k ) ; 1178 FOR 1 := s t - C - 1 TO x _ r e s o l u t 1 o n + C + 1 DO u n s e t _ b i t ( m a t r i x , y _ r e s o l u t i o n + j , i , b a c k ) ; 1 179 FOR 1 := s t - C - 1 TO y _ r e s o l u t i o n + C + 1 DO u n s e t _ b i t ( m a t r 1 x , i . s t - j , b a c k ) ; 1 1 8 0 FOR 1 := s t - C - 1 TO y _ r e s o l u t i o n + C + 1 DO u n s e t _ b 1 t ( m a t r i x , i , x _ r e s o l u t i o n + j , b a c k ) ; 1181 END; 1 182 1 183 1184 { i n i t i a l i z e ' i n d e x ' a r r a y } 1 185 1186 FOR 1 := s t TO x _ r e s o 1 u t i o n DO 1187 B E G I N 1188 1 n d e x ( . i . ) . n o := 0; 1189 i n d e x * . 1 . ) . y _ m i n := m a x i n t ; 1 190 i n d e x ( . 1 . ) . y _ m a x := - m a x i n t ; 1 191 1192 FOR j := s t TO p t r s _ l 1 m i t DO I n d e x * . 1 . ) . p t r s ( . j . ) := n i l 1193 END; M 1194 END; O 1 195 1 0 1196 PROCEDURE t e r t i a r y _ 1 n i t i a l 1 z e ; 1 197 1198 B E G I N 1199 m a t _ 1 n i t ( w o r k _ m a t r i x , b a c k ) ; 1200 n o _ a r r o w s := 0; 1201 END; 1202 1203 1204 1205 1206 FUNCTION f i r s t _ p t : p o i n t _ f o u n d ; 1207 1208 { T h i s f u n c t i o n r e t u r n s t h e t o p l e f t - m o s t c o - o r d i n a t e s i n t h e ' m a t r i x ' w h i c h 1209 r e p r e s e n t a ' t r u e ' v a l u e , i e . t h e f i r s t p o i n t . } 1210 1211 VAR 1212 y . x : i n t e g e r ; 1213 f o u n d : b o o l e a n ; 1214 i : i n t e g e r ; 1215 1216 B E G I N 1217 y := m a x i n t ; 1218 1219 FOR i := 1 TO x _ r e s o l u t i o n DO 1220 I F i n d e x ( . i . ) . n o > 0 1221 THEN I F i n d e x ( . i . ) . y _ m 1 n < y 1222 THEN 1223 B E G I N 1224 y ;= i n d e x ( . 1 . ) . y _ m i n ; 1225 x := i 1226 END; 1227 1228 I F y = m a x i n t THEN f o u n d := f a l s e 1229 E L S E f o u n d := t r u e ; 1230 1231 f i r s t _ p t . f o u n d := f o u n d ; 1232 f i r s t _ p t . x := x; 1233 f i r s t _ p t . y := y ; 1234 1235 I F d e b u g g i n g ( . 4 . ) 1236 THEN 1237 B E G I N 1238 w r i t e l n ; 1239 w r i t e l n ( ' * * * * D e b u g g i n g f i n d f i r s t p o i n t * * * * ' ) ; 1 2 4 0 w r i t e l n ( ' f i r s t _ p t . f o u n d = ' . f o u n d ) ; 1241 w r i t e l n ! , ' f i r s t _ p t . x = ' , x ) ; 1242 w r i t e l n ( ' f i r s t _ p t . y = ' , y ) ; 1243 w r i t e l n 1244 END 1245 END; 1246 1247 F U N CTION s u b _ c o n v e r t ( x : i n t e g e r ) : I n t e g e r ; 1248 1249 { T h i s f u n c t i o n r e t u r n s t h e s u b s c r i p t i n t h e ' p t r s ' a r r a y f o r t h e n ' t h p o i n t } 1250 B E G I N 1251 s u b _ c o n v e r t := ( x + y _ d i v _ 1 6 - 1) d i v y _ d i v _ 1 6 ; 1252 END; 1253 1254 F U N CTION o f f _ c o n v e r t ( x : i n t e g e r ) : i n t e g e r ; O 1255 w 1256 { T h i s f u n c t i o n r e t u r n s t h e o f f s e t i n t h e ' y _ b l o c k ' f o r t h e n ' t h p o i n t . } 1257 B E G I N 1258 o f f _ c o n v e r t := ( x + y _ d i v _ 1 6 - 1) mod y _ d i v _ 1 6 + 1; 1259 END; 1260 1261 F U N C T I O N f i n d _ b i n a r y ( x , y , n e w _ x : I n t e g e r ; VAR n e x t _ x , n e x t _ y , d i s p l a c e : i n t e g e r ) l o c a t i o n ; 1262 1263 { T h i s f u n c t i o n i s c a l l e d b y t h e p r o c e d u r e ' f i n d _ c l o s e s t ' a n d r e t u r n s t h e • 1264 c l o s e s t p o i n t t o t h e c u r r e n t p o i n t a s d e t e r m i n e d b y a b i n a r y s e a r c h . > 1265 1266 VAR 1267 new_y, 1268 m i d _ p t , 1269 i , 1270 j : i n t e g e r ; 1271 f o u n d : b o o l e a n ; 1272 s u b s c r i p t , 1273 o f f s e t i n t e g e r ; 1274 t e m p _ d s t i n t e g e r ; 1275 1276 B E G I N 1277 WITH i n d e x ( . n e w _ x . ) DO 1278 B E G I N 1279 1 := 1; 1280 j := n o ; 1281 f o u n d := f a l s e ; 1282 1283 R E P E A T 1284 1285 m i d _ p t := ( i + j ) d i v 2; 1286 s u b s c r i p t := s u b _ c o n v e r t ( m i d _ p t ) ; 1287 o f f s e t := o f f _ c o n v e r t ( m i d _ p t ) ; 1288 1289 new_y := p t r s ( . s u b s c r i p t . ) @ ( . o f f s e t . ) ; 1290 1291 t e m p _ d s t := ( ( x - n e x t _ x ) * ( x - n e x t _ x ) + ( y - n e x t _ y ) * ( y - n e x t _ y ) ) ; 1292 I F ( n e x t _ x = f r s t _ p t . x ) AND ( n e x t _ y = f r s t _ p t . y ) THEN t e m p _ d s t := t e m p _ d s t + 1 ; 1293 1294 I F ( ( x - n e w _ x ) * ( x - n e w _ x ) + ( y - n e w _ y ) * ( y - n e w _ y ) ) < t e m p _ d s t 1295 THEN 1296 B E G I N 1297 f o u n d := t r u e ; 1298 n e x t _ x := new_x; 1299 n e x t _ y := new_y; 1300 f 1 n d _ b i n a r y . i n d := s u b s c r i p t ; 1301 f i n d _ b i n a r y . o f f := o f f s e t ; 1302 f 1 n d _ b 1 n a r y . f o u n d := f o u n d ; 1303 1304 I F m a x ( a b s ( x - n e w _ x ) , a b s ( y - n e w _ y ) ) < d i s p l a c e 1305 THEN d i s p l a c e := m a x ( a b s ( x - n e w _ x ) , a b s ( y - n e w _ y ) ) 1306 END; 1307 1308 I F y > p t r s ( . s u b s c r i p t . ) p ( . o f f s e t . ) 1309 THEN 1 := m i d _ p t + 1 1310 E L S E j := m1d_pt-1 1311 1312 U N T I L ( ( p t r s ( . s u b s c r i p t . ) @ ( . o f f s e t . ) = y ) OR ( i > j)); 1313 1314 I F d e b u g g i n g * . 4 . ) O 1315 THEN ^ 1316 B E G I N 1317 w r i t e l n ; 1318 w r i t e 1 n ( ' * * * * D e b u g g i n g f i n d b i n a r y * * * * ' ) ; 1319 w r i t e l n ( ' f i n d _ b 1 n a r y . f o u n d = ' . f o u n d ) ; 1320 w r 1 t e l n ( ' f i n d _ b i n a r y . i n d = ' . s u b s c r i p t ) ; 1321 w r i t e l n ( ' f i n d _ b 1 n a r y . o f f = ' . o f f s e t ) ; 1322 w r 1 t e l n ( ' n e x t _ x = ' , n e x t _ x ) ; 1323 w r i t e l n ( ' n e x t _ y = ' , n e x t _ y ) ; ' 1324 w r i t e l n 1325 END 1326 END 1327 END; 1328 1329 PROCEDURE w r i t e _ 1 n d e x ( x , y : i n t e g e r ) ; 1330 1331 { T h i s p r o c e d u r e w r i t e s t h e y o r d i n a t e o f t h e p o i n t t o t h e y _ b l o c k p o i n t e d t o 1332 b y t h e p t r s a r r a y . I t a l s o i n c r e m e n t s t h e c o u n t o f t h e number o f p o i n t s 1333 • i n t h e r e l e v a n t c o l u m n o f t h e m a t r i x & c h e c k s a g a i n s t min/max f o r t h a t c o l } 1334 1335 VAR 1336 s u b s c r i p t , 1337 o f f s e t i n t e g e r ; 1338 b e e n _ n e w : b o o l e a n ; 1339 1340 B E G I N 1341 WITH i n d e x ( . x . ) DO 1342 B E G I N 1343 b e e n _ n e w := f a l s e ; 1344 no := no+1; 1345 s u b s c r i p t := s u b _ c o n v e r t ( n o ) ; 1346 o f f s e t := o f f _ c o n v e r t ( n o ) ; 1347 1348 I F y < y_m1n THEN y_m1n ;= y; 1349 I F y > y_max THEN y_max := y; 1350 1351 I F p t r s ( . s u b s c r i p t . ) = n i l 1352 THEN 1353 B E G I N 1354 n e w ( p t r s ( . s u b s c r i p t . ) ) ; 1355 b een_new := t r u e 1356 END; 1357 1358 p t r s ( . s u b s c r i p t . ) @ ( . o f f s e t . ) := y; 1359 END; 1 3 6 0 1361 I F d e b u g g i n g * . 1 0 . ) 1362 THEN 1363 B E G I N 1364 w r i t e l n ; 1365 w r i t e l n ( ' * * * * D e b u g g i n g w r i t e i n d e x * * * * ' ) ; 1366 w r 1 t e l n ( ' s u b s c r i p t = ' . s u b s c r i p t ) ; 1367 w r i t e l n ( ' o f f s e t = ' . o f f s e t ) ; 1368 w r i t e l n ( ' x = ' , x ) ; 1369 w r i t e l n ( ' y = ' , y ) ; 1370 w r i t e 1 n ( ' b e e n _ n e w = ' , b e e n _ n e w ) ; 1371 w r i t e l n 1372 END 1373 END; ,_, 1374 O 1375 PROCEDURE d e 1 e t e _ i n d e x ( x , y, s u b s c r i p t , o f f s e t : i n t e g e r ) ; (- n 1376 1377 { T h i s p r o c e d u r e d e l e t e s a p o i n t ' s y o r d i n a t e f r o m t h e y _ b l o c k p o i n t e d t o b y 1378 t h e p t r s a r r a y . I t d e c r e m e n t s t h e c o l ' s p o i n t c o u n t a n d may m o d i f y t h a t 1379 c o l s m a x / m i n . I t a l s o r e m o v e s t h e p o i n t f r o m t h e 'matr i x 1380 1381 VAR 1382 I . J . 1383 s u b 1 , s u b2 , 1384 o f f 1 , o f f 2 : i n t e g e r ; 1385 1386 B E G I N 1387 WITH 1 n d e x ( . x . ) DO 1388 B E G I N 1389 no := n o - 1 ; 1390 j := ( ( s u b s c r i p t - 1 ) * y _ d i v _ 1 6 ) + o f f s e t ; 1391 u n s e t _ b i t ( m a t r i x , y , x , f r o n t ) ; 1392 1393 1 n s e r t _ p o i n t ( 0 , x , y ) ; { e s t a b l i s h a r e c o r d o f p o i n t s 1394 1395 1396 FOR i : = j TO no DO 1397 B E G I N 1398 s u b l := s u b _ c o n v e r t ( 1 ) ; 1399 s u b 2 := s u b _ c o n v e r t ( i + 1 ) ; 1400 o f f 1 := o f f _ c o n v e r t ( i ) ; 1401 o f f 2 := o f f _ c o n v e r t ( i + 1 ) ; 1402 1403 p t r s ( . s u b l . ) @ ( . o f f 1.) := p t r s ( . s u b 2 . ) @ ( . o f f 2 ) 1404 END; 1405 1406 s u b l := s u b _ c o n v e r t ( n o + 1 ) ; 1407 o f f 1 := o f f _ c o n v e r t ( n o + 1 ) ; 1408 p t r s ( . s u b l . ) @ ( . o f f 1 . ) := 0; 1409 I F ( o f f s e t - 1 = 0 ) AND ( j = ( n o + 1 ) ) THEN p t r s ( s u b s c r i p t 1410 141 1 I F no > 0 1412 THEN 1413 B E G I N 1414 I F ( s u b s c r i p t = s t ) AND ( o f f s e t = s t ) 1415 THEN 1416 y m i n := p t r s ( . 1 . ) @ ( . 1 . ) 1417 E L S E 1418 IF j = ( n o + 1 ) 1419 THEN 1420 B E G I N 1421 s u b l := s u b _ c o n v e r t ( n o ) ; 1422 o f f 1 := o f f c o n v e r t ( n o ) ; 1423 y max := p t r s ( . s u b l . ) @ ( . o f f 1 . ) 1424 END 1425 END 1426 END; 1427 1428 I F d e b u g g i n g ( . 4 . ) 1429 THEN 1430 B E G I N 1431 w r 1 t e l n ; 1432 w r i t e l n ( ' * * * * D e b u g g i n g d e l e t e i n d e x * * * * ' ) ; 1433 w r i t e l n ( ' s u b s c r 1 p t = ' . s u b s c r i p t ) ; 1434 w r i t e l n ( ' o f f s e t = ' . o f f s e t ) ; 1435 wr i t e l n ( ' x = ' , x ) ; 1436 w r 1 t e l n ( ' y ' , y ) ; 1437 w r i t e l n 1438 END > d e l e t e d i n s a v e m a t r i x } n i l O 1439 END; 1440 1441 PROCEDURE e s t a b _ 1 n d e x ; 1442 1443 { T h i s p r o c e d u r e c o n t r o l s t h e s c a n s t h e m a t r i x a n d c a u s e s t h e i n v o c a t i o n o f 1444 t h e w r i t e _ i n d e x p r o c e d u r e i n o r d e r t o p l a c e t h e p o i n t s i n t h e ' m a t r i x ' i n t o 1445 t h e ' i n d e x ' } 1446 1447 VAR 1448 1 , j 1 n t e g e r ; 1449 p o i n t _ c o u n t : i n t e g e r ; 1450 t _ m i n _ x , 1451 t_max_x : i n t e g e r ; { temp v a l s f o r m i n & max i f 'a 1 r e a d y _ a c t i v e ' } 1452 1453 B E G I N 1454 p o i n t _ c o u n t := 0; 1455 1456 FOR i := s t TO y _ r e s o l u t i o n DO 1457 FOR j := s t TO x _ r e s o l u t i o n DO 1458 I F t e s t ( m a t r i x , 1 , j . f r o n t ) 1459 THEN 1460 B E G I N 1461 w r i t e _ i n d e x ( j , i ) ; 1462 p o i n t _ c o u n t := p o 1 n t _ c o u n t + 1 1463 END; 1464 1465 I F p t _ s e t _ n o <= 1 AND NOT a 1 r e a d y _ a c t 1 v e THEN 1466 B E G I N 1467 m i n _ x := s t ; 1468 I F 1 n d e x ( . m i n _ x . ) . n o = 0 1469 THEN WHILE i n d e x ( . m i n _ x + 1 . ) . n o = 0 DO m i n _ x := min_x+1; 1470 1471 max_x := x _ r e s o l u t i o n ; 1472 I F i n d e x ( . m i n _ x . ) . n o = 0 1473 THEN WHILE i n d e x ( . m a x _ x - 1 . ) . n o = 0 00 max_x := max_x-1; 1474 END; 1475 1476 I F a l r e a d y _ a c t 1 v e THEN 1477 B E G I N 1478 t _ m i n _ x := s t ; 1479 I F i n d e x ( . t _ m 1 n _ x . ) . n o = 0 1 480 THEN WHILE i n d e x ( . t_m i n_x+1 . ) . no=0 DO t _ m i n _ x := t _ m i n _ x + 1 ; 1481 1482 t_max_x := x _ r e s o l u t i o n ; 1483 I F i n d e x ( . t _ m i n _ x . ) . n o = 0 1484 THEN WHILE 1 n d e x ( . t _ m a x _ x - 1 . ) . n o = 0 DO t_max_x := t_max_x-1; 1485 1486 m i n _ x := m i n ( m 1 n _ x , t _ m i n _ x ) ; 1487 max_x := m a x ( m a x _ x , t _ m a x _ x ) ; 1488 END; 1489 1490 I F d e b u g g l n g ( . 4 . ) 1491 THEN 1492 B E G I N 1493 w r i t e l n ; !_, 1494 w r i t e l n ( ' * * * * D e b u g g i n g e s t a b l i s h i n d e x * * * * ' ) ; O 1495 w r i t e l n ( ' p o i n t _ c o u n t = ' , p o i n t _ c o u n t ) ; ~^ 1496 w r i t e l n ( ' m i n _ x = ' , m i n _ x ) ; 1497 w r i t e l n ( ' m a x _ x = ',max_x); 1498 w r i t e l n 1499 END 1500 END; 1501 1502 FUNCTION s a m e _ c o 1 ( x , y , 1503 i n d . o f f : i n t e g e r ; 1504 VAR 1505 s u b s c r i p t , 1506 o f f s e t , 1507 d i s p l a c e i n t e g e r ) : p o i n t _ f o u n d ; 1508 1509 { T h i s f u n c t i o n r e t u r n s the c l o s e s t p o i n t i n the same column to the c u r r e n t 1510 p o i n t . A c l o s e s t p o i n t may or may not be found. > 1511 1512 VAR 1513 temp_posn, 1514 posn, 1515 y i , y 2 , 1516 c o l _ x , c o l _ y , 1517 sub1,sub2, 1518 O f f 1 , o f f 2 : i n t e g e r ; 1519 found : b o o l e a n ; 1520 1521 BEGIN 1522 y1 := maxint; 1523 y2 :- maxint; 1524 posn := ( y _ d i v _ 1 6 * ( i n d - 1 ) ) + o f f ; 1525 1526 IF (posn-1 ) > 0 1527 THEN 1528 BEGIN 1529 temp_posn := posn-1; 1530 s u b l := sub_convert(temp_posn); 1531 o f f 1 := o f f _ c o n v e r t ( t e m p _ p o s n ) ; 1532 1533 y1 := i n d e x ( . x . ) . p t r s ( . s u b 1.)@(.off1.) 1534- END; 1535 IF (posn+1) <= i n d e x ( . x . ) . n o 1536 THEN 1537 BEGIN 1538 temp_posn := posn+1; 1539 sub2 := sub_convert(temp_posn); 1540 o f f 2 := o f f _ c o n v e r t ( t e m p _ p o s n ) ; 1541 1542 y2 := i n d e x ( . x . ) . p t r s ( . s u b 2 . ) @ ( . o f f 2 . ) 1543 END; 1544 1545 IF (y1 = maxint) AND (y2 = maxint) 1546 THEN 1547 BEGIN 1548 found := f a l s e ; 1549 c o l _ x := m a x ( x _ r e s _ p l u s _ C , y _ r e s _ p l u s _ C ) ; 1550 c o l _ y := m a x ( x _ r e s _ p l u s _ C , y _ r e s _ p l u s _ C ) ; 1551 s u b s c r i p t s m a x ( x _ r e s _ p l u s _ C , y _ r e s _ p l u s _ C ) ; 1552 o f f s e t := m a x ( x _ r e s _ p l u s _ C , y _ r e s _ p l u s _ C ) ; 1553 END 1554 ELSE O 1555 BEGIN 00 1556 IF a b s ( y l - y ) <= abs(y2-y) 1557 -THEN 1558 BEGIN 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 found co1_x col_y subscript offset END ELSE BEGIN found co1_x col_y subscript of f s e t END true; x; y l : subl ; of f 1 true; x; y2; sub2; of f 2 END; same_col.found same_col.x same_col.y = found; = col_x; = col_y; IF found .THEN displace := abs(col_y - y) ELSE displace := x_resolution: IF debugging(.4.) THEN BEGIN writeln; writeln('**** Debugging same column * * * * ' ) ; wr1teln('found wrlteln('col_x = wr i t e ln('col_y = wr i teln('subscrpt = writeln('offset writeln('dlspl wr i t e l n END , found); , CO 1_x); , co1_y); , subscr i p t ) ; . offset); , di splace); END; PROCEDURE find_closest(x,y, curr_col : integer; VAR displace, subscript, of f s e t : integer; VAR next_x, next_y integer); { This procedure finds the closest point ( i n 'other' cols to the current point. A previous 'closest' point may or may not exist. CONST 1 1 near li m i t = 16; VAR bin posn, new_sub,new_off, 1ocat i on; 1619 new_x,new_y1,new_y2, 1620 s t a r t , 1621 f i n , 1622 i n c r : i n t e g e r ; 1623 r e s t _ t o o _ f a r : boolean; 1624 temp_dst : Integer; 1625 1626 BEGIN 1627 WITH i n d e x ( . c u r r _ c o l . ) DO 1628 BEGIN 1629 IF no > 0 1630 THEN 1631 IF no > l i n e a r _ l i m 1 t 1632 THEN 1633 BEGIN 1634 b i n := f i n d _ b i n a r y ( x , y , c u r r _ c o l , n e x t _ x , n e x t _ y , d i s p l a c e ) ; 1635 IF b i n . f o u n d 1636 THEN 1637 BEGIN 1638 s u b s c r i p t := b i n . i n d ; 1639 o f f s e t := b i n . o f f 1640 END 1641 END 1642 ELSE 1643 BEGIN 1644 IF abs(y_max - y) < abs(y_min - y) 1645 THEN 1646 BEGIN 1647 s t a r t := no; 1648 f i n := 1; 1649 i n c r := -1 1650 END 1651 ELSE 1652 BEGIN 1653 s t a r t := 1; 1654 f i n := no; 1655 i n c r := 1 1656 END; 1657 1658 r e s t _ t o o _ f a r := f a l s e ; 1659 posn := s t a r t - i n c r ; 1660 new_x := c u r r _ c o l ; 1661 new_y2 := maxint; 1662 1663 REPEAT 1664 posn := posn+incr; 1665 new_sub:= s u b _ c o n v e r t ( p o s n ) ; 1666 new_off:= o f f _ c o n v e r t ( p o s n ) ; 1667 1668 new_y1 := ptrs(.new_sub.)@(.new_off.); 1669 1670 temp_dst := ( ( x - n e x t _ x ) * ( x - n e x t _ x ) + ( y - n e x t _ y ) * ( y - n e x t _ y ) ) ; 1671 IF ( n e x t _ x = f r s t _ p t . x ) AND ( n e x t _ y = f r s t _ p t . y ) THEN temp_dst := temp_dst+1; 1672 1673 IF ((x-new_x)*(x-new_x)+(y-new_y1)*(y-new_y1)) < temp_dst 1674 THEN £ 1675 BEGIN O 1676 next_x := new_x; 1677 next_y := new_y1; 1678 s u b s c r i p t := new_sub; 1G79 o f f s e t := new_off; 1680 1681 IF max(abs(x-new_x),abs(y-new_y1)) < displace 1682 THEN displace := max(abs(x-new_x),abs(y-new_y1 )) 1683 END; 1684 1685 IF abs(y-new_y1) > abs(y-new_y2) 1686 THEN rest_too_far := true 1687 ELSE new_y2 := new_y1; 1688 1689 UNTIL rest_too_far OR (posn = f i n ) ; 1690 1691 END 1692 END; 1693 IF debugging(.4.) 1694 THEN 1695 BEGIN 1696 writeln; 1697 w r i t e l n ( ' * * * * Debugging f i n d closest point * * * * ' ) ; 1698 writeln('next_x = ',next_x); 1699 writeln('next_y = ',next_y); 1700 writeln('subscript = '.subscript); 1701 writeln('offset = ' . o f f s e t ) ; 1702 writeln; 1703 wr1teln('curr_col = ',curr_col); 1704 writeln('no = ',index(.curr_col.).no); 1705 writeln 1706 END 1707 END; 1708 1709 FUNCTION other_col s(x,y, 1710 ind.off Integer; 1711 VAR 1712 subscript, 1713 o f f s e t , 1714 displace, 1715 next_x,next_y : integer) : point_found; 1716 1717 { This function controls the procedure 'find_c1osest' and returns the closest 1718 point to the current point as determined by checkin the 'other' c o l s . } 1719 1720 VAR 1721 posn, 1722 i , 1723 new_sub, 1724 new_off, 1725 new_x, 1726 new_y, 1727 x_disp,' 1728 curr_col : integer; 1729 1730 BEGIN 1731 x_disp := 1; 1732 1733 WHILE x_disp <= displace DO 1734 BEGIN 1735 FOR i := 1 TO 2 DO 1736 BEGIN 1737 x_d1sp := -x_disp; 1738 curr_col := curr_x+x_disp; 1739 IF (curr_col>=min_x) AND (curr_col<=max_x) 1740 THEN find_closest(x,y,curr_col.displace, 174 1 subscript.offset,next_x,next_y); 1742 IF (1=2) THEN x_disp := x_disp+1 1743 END 1744 END 1745 END; 1746 1747 PROCEDURE find_area; 1748 1749 { This procedure controls the search for points belonging to one polygon ) 1750 1751 VAR 1752 curr_pt : location; 1753 next_pt location; 1754 subscript, 1755 o f f s e t : integer; 1756 1 , j : 1 nteger ; 1757 this_pt : point_found; 1758 1759 BEGIN 1760 curr_pt.ind := 1; 1761 curr_pt.off := 1; 1762 1763 next_x := max(x_res_p1us_C,y_res_plus_C) ; 1764 next_y := max(x_res_plus_C,y_res_plus_C); 1765 1766 max_smudge_x := st; 1767 max_smudge_y := st; 1768 min_smudge_x := x_resolution; 1769 m1n_smudge_y := y_resolut1 on; 1770 1771 IF debugging(.2.) THEN mat_1nit(work_matrix,front); 1772 1773 insert_po1nt(pt_set_no,curr_x,curr_y); 1774 1775 REPEAT 1776 1777 IF (curr_x = frst_pt.x) AND (curr_y = frst_pt.y) 1778 THEN IF test(matr1x,curr_y,curr_x+1,front) 1779 THEN smudge(curr_x,curr_y-1,curr_x,curr_y); 1780 1781 th1s_pt := same_col(curr_x,curr_y,curr_pt.ind,curr_pt.off, 1782 next_pt.ind,next_pt.off,displace); 1783 IF this_pt.found 1784 THEN 1785 BEGIN 1786 next_x := this_pt.x; 1787 next_y := this_pt.y; 1788 END 1789 ELSE 1790 BEGIN 1791 next_x := max(x_res_plus_C,y_res_p1us_C); 1792 next_y := max(x_res_plus_C,y_res_plus_C); 1793 END; ,, 1794 |—' 1795 this_pt := other_cols(curr_x,curr_y,curr_pt.1nd,curr_pt.off, 1796 next_pt. 1nd, next_pt. of f , di spl ace, next_x, next_y); 1797 1798 smudge(curr_x,curr_y,next_x,next_y); 1799 1800 IF debugg1ng(.2.) THEN set_b1t(work_matr1x,next_y,next_x,front); 1801 IF debugging*.2.) THEN wr1teln(next_x,next_y,next_pt.1nd,next_pt.off); 1802 insert_po1nt(pt_set_no,next_x,next_y); 1803 1804 IF next_x > max_smudge_x THEN max_smudge_x := next_x 1805 ELSE IF next_x < mln_smudge_x THEN min_smudge_x := next_x; 1806 IF next_y < m1n_smudge_y THEN min_smudge_y := next_y 1807 ELSE IF next_y > max_smudge_y THEN max_smudge_y := next_y; 1808 1809 IF N0T((curr_x = frst_pt.x) AND (curr_y = fr s t _ p t . y ) ) 1810 THEN 1811 BEGIN 1812 f i nd_l1 near(curr_x,curr_y,curr_pt.ind,curr_pt.off); 1813 delete_index(curr_x,curr_y,curr_pt.i nd,curr_pt.off); 1814 IF test(matrix,curr_y,curr_x,back) 1815 THEN unset_bit(matrix,curr_y,curr_x,back) 1816 END; 1817 1818 f i n d_li near(next_x,next_y,next_pt.1nd,next_pt.off); 1819 1820 curr_x := next_x; 1821 curr_y ;= next_y; 1822 curr_pt.ind := next_pt.ind; 1823 curr_pt.off := next_pt.off 1824 1825 UNTIL (next_x = frst_pt.x) AND (next_y = f r s t _ p t . y ) ; 1826 1827 FOR i := min_smudge_y TO max_smudge_y DO 1828 FOR j := min_smudge_x TO max_smudge_x DO 1829 IF test(matrix,i,j.back) THEN 1830 BEGIN 1831 f1nd_li near(j,i,next_pt.i nd,next_pt.off); 1832 IF NOT((j=frst_pt.x) AND (1=frst_pt.y)) THEN 1833 delete_i ndex(j,1,next_pt.1nd,next_pt.off); 1834 unset_bit(matrix,i,j,back) 1835 END; 1836 1837 close_polygon(pt_set_no); 1838 1839 IF debugging(.2.) THEN 1840 BEGIN 1841 FOR 1:= st TO y_resolution DO 1842 BEGIN 1843 w r i t e C ' ) ; 1844 FOR j:= st TO x_resolut1on DO 1845 BEGIN 1846 IF test(work_matrix,i,j.front) THEN wr1te('1') 1847 ELSE wr1te('O'); 1848 IF (j mod 80) = 0 1849 THEN 1850 BEGIN 1851 writeln; 1852 IF 1<>x_resolution THEN write(' ') 1853 END M 1854 END; |-i 1855 writeln W 1856 END; 1857 . writeln 1858 END 1859 END; 18G0 1861 PROCEDURE smudge(curr_x,curr_y : integer; VAR next_x,next_y : integer); 1862 1863 { This procedure controls the elimination of smudges to a depth s p e c i f i e d 1864 by the user (acc_smudge). This variable controls the broader accuracy of 1865 the polygon determination. } 1866 1867 TYPE 1868 d i r = (north,south,east,west,southeast,southwest,northeast,northwest); 1869 1870 VAR 1871 d i r e c t i o n : d i r ; 1872 1873 PROCEDURE nsew_check(x_1nc,y_inc : integer); 1874 1875 { This procedure checks the d i r e c t i o n between curr and next points and 1876 establishes the control variables for the procedure 'clear_up' } 1877 1878 VAR 1879 temp_x, 1880 temp_y, 1881 temp_ind, 1882 temp_off, 1883 x_incr, 1884 y_1ncr ; integer; 1885 1886 PROCEDURE clear_up(temp_x,temp_y : integer); 1887 1888 { This procedure actually removes the smudges. The algorithm is recursive 1889 and deletes a l l 'internal f u l l y bounded points', where internal means on 1890 the inside of the polygon, and f u l l y bounded implies complete adjacency 1891 ie. no diagonal touches. } 1892 1893 BEGIN { clear_up } 1894 IF debugging*.4.) 1895 THEN 1896 BEGIN 1897 writeln; 1898 writeln('**** Debugging clear_up * * * * ' ) ; 1899 writeln('temp_x = ',temp_x:0); 1900 writeln('temp_y = ',temp_y:0); 1901 writeln 1902 END; 1903 1904 IF test(matr1x,temp_y+x_incr,temp_x+y_incr,front) THEN clear_up(temp_x+y_1ncr,temp_y+x_1ncr); 1905 1906 IF test(matrix,temp_y-y_inc,temp_x-x_inc,front) THEN clear_up(temp_x-x_1nc,temp_y-y_inc); 1907 1908 IF (temp_xonext_x) OR (temp_y<>next_y) THEN 1909 BEGIN 1910 IF debugging(.4.) THEN wr1teln('**** Debugging - from clear_up * * * * ' ) ; 191 1 1912 IF (abs(temp_x-next_x) < acc_smudge) AND (abs(temp_y-next_y) < acc_smudge) 1913 THEN 1914 BEGIN P 1915 find_linear(temp_x,temp_y,temp_ind,temp_off); t t > 1916 IF N0T((temp_x = frst_pt.x) AND (temp_y = frst_pt.y)) THEN 1917 BEGIN 1918 delete_1ndex(temp_x,temp_y,temp_i nd,temp_off); 1919 IF test(matrix, temp_y,temp_x,back) THEN unset_bit(matr1x,temp_y,temp_x,back) 1920 END 1921 END 1922 ELSE set_bit(matrix,temp_y,temp_x,back) 1923 END 1924 END; 1925 1926 BEGIN { nsew check > 1927 CASE d i r e c t i o n OF 1928 south, north : BEGIN 1929 x_incr := x_inc; 1930 y_incr := y_inc 1931 END; 1932 east, west : BEGIN 1933 x_1ncr := -x_inc; 1934 y_incr := -y_inc 1935 END; 1936 southeast, 1937 southwest, 1938 northeast, 1939 northwest : BEGIN 1940 x_incr := x_inc; 1941 y_incr := y_inc 1942 END 1943 END; 1944 1945 IF (direction=north) OR (direct1on=south) OR (direct1on=east) OR (direction=west) AND 1946 NOT ((next_x = frst_pt.x) AND (next_y = frst_pt.y)) 1947 THEN 1948 BEGIN 1949 WHILE test(matrix,next_y+x_1ncr,next_x+y_incr,front) AND 1950 NOT test(matrix,next_y+y_1nc,next_x+x_1nc,front) DO 1951 BEGIN 1952 temp_x := next_x; 1953 temp_y := next_y; 1954 1955 WHILE test(matrix,temp_y,temp_x,front) DO 1956 BEGIN 1957 IF debugging(.4.) THEN writeln('**** Debugging - from nsew * * * * ' ) ; 1958 f1nd_linear(temp_x,temp_y,temp_1nd,temp_off); 1959 IF NOT((temp_x = frst_pt.x) AND (temp_y = frst_pt.y)) THEN 1960 BEGIN 1961 del ete_index( temp_x , temp_y, temp_i nd, temp_of f ); 1962 IF test(matrix,temp_y,temp_x,back) THEN unset_bit(matrix,temp_y,temp_x,back) 1963 END; 1964 temp_x := temp_x - x_inc; 1965 temp_y := temp_y - y_inc 1966 END; 1967 1968 next_x := next_x + y_incr; 1969 next_y := next_y + x_incr 1970 END 1971 END 1972 ELSE 1973 BEGIN 1974 IF test(matrix,next_y+x_incr,next_x+y_1ncr,front) THEN {Zl 1975 BEGIN Ln 1976 temp_x := next_x-x_1nc; 1977 temp_y := next_y-y_inc; 1978 1979 1980 1981 1982 1983 1984 1985 198G 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 201 1 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 WHILE test(matrix,temp_y,temp_x,front) DO BEGIN IF debugging(.4.) THEN wr1teln('**** Debugging - from nsew * * * * ' ) ; f i nd_I i near(temp_x,temp_y,temp_i nd,temp_off ); IF NOT((temp_x = frst_pt.x) AND (temp_y = fr s t _ p t . y ) ) THEN BEGIN delete_i ndex(temp_x,temp_y,temp_i nd,temp_off); IF test(matr1x,temp_y,temp_x,back) THEN unset_bit(matrix,temp_y,temp_x,back) END; temp_x := temp_x - x_inc; temp_y := temp_y - y_inc END END END; IF direction=south OR direction=north OR direction=east OR direction=west THEN BEGIN IF test(matr1x,next_y + y_inc,next_x + x_inc,front) THEN c1ear_up(next_x,next_y); END; IF debugg1ng(.4.) THEN BEGIN wr1teln; writeln('**** Debugging nsew check * * * * ' ) ; write1n('x_incr = ',x_incr:0); writeln('y_1ncr = ',y_incr:0); wr i t e l n END END; BEGIN { smudge ) IF (curr_x = next_x) AND (curr_y > next_y) THEN d i r e c t i o n := north ELSE IF (curr_x = next_x) AND (curr_y < next_y) THEN di r e c t i o n := south ELSE IF (curr_x < next_x) AND (curr_y = next_y) THEN d i r e c t i o n := east ELSE IF (curr_x > next_x) AND (curr_y = next_y) THEN d i r e c t i o n := west ELSE IF (curr_x < next_x) AND (curr_y < next_y) THEN d i r e c t i o n := southeast ELSE IF (curr_x > next_x) AND (curr_y > next_y) THEN d i r e c t i o n := northwest ELSE IF (curr_x > next_x) AND (curr_y < next_y) THEN d i r e c t i o n := southwest ELSE IF (curr_x < next_x) AND (curr_y > next_y) THEN d i r e c t i o n := northeast; CASE d i r e c t i o n OF north : nsew_ check(-1,0); south nsew_ _check(+1,0); east nsew_ _check(0,- 1); west nsew_ ~check(0,+1); southeast, southwest nsew_ _check(+1,0); northeast, northwest : nsew _check(-1,0) END; (* end case *) END; FUNCTION check_contract(i,j : integer) : boolean; h- 1 { This function determines whether a point should be l e f t ' l i t ' or should be CM turned 'off'. For a point to remain l i t a l l i t s 8 neighbours must be l i t . } VAR 2039 temp : boolean; 2040 2041 . BEGIN 2042 IF test(matr1x,1-1,j-1.front) AND test(matr1x,i- 1,j,front) AND tes t ( m a t r i x , i - 1,j + 1,front) AND 2043 test(matr1x,1,j-1.front) AND test(matrix,i,j+1,front) AND 2044 test(matr1x.1 + 1,J-1,front) AND test(matr1x,i +1,j,front) AND test(matrix,i + 1,j + 1,front) 2045 THEN temp := true 2046 ELSE temp := f a l s e ; 2047 2048 check_contract := temp; 2049 2050 IF debugging(.8.) AND test(matrix,1,j,front) 2051 THEN 2052 BEGIN 2053 writeln; 2054 wr1teln('**** Debugging check contract * * * * ' ) ; 2055 w r i t e l n ( ' i = ' . i ) ; 2056 writeln('j = ' , j ) ; 2057 writeln 2058 END 2059 END; 2060 2061 PROCEDURE copy_mat(VAR mat1,mat2 : bool_matrix; plate : integer); 2062 2063 { This procedure copies matrix 2 to matrix 1 } 2064 2065 VAR 2066 i,j,word : integer; 2067 2068 BEGIN 2069 FOR 1 := (st-C) TO y_res_plus_C DO 2070 2071 FOR j := 1 TO ((x_res_plus_C+C+2) div word_size) + 1 DO 2072 BEGIN 2073 mat1(.i,j,plate.) := mat2(.i, j,plate.) 2074 END; 2075 2076 IF debugging(.3.) THEN 2077 BEGIN 2078 FOR 1:= st TO y_resolution DO 2079 BEGIN 2080 w r i t e C ' ) ; 2081 FOR J:= st TO x_resolut1on DO 2082 BEGIN 2083 IF test(mat1,1,j.plate) THEN write('1') 2084 ELSE wr1te('0'): 2085 IF (j mod 80) = 0 2086 THEN 2087 BEGIN 2088 writeln; 2089 IF j o x _ r e s o l u t i o n THEN write(' ') 2090 END 2091 END; 2092 writeln 2093 END J_J 2094 writeln f—1 2095 END ^ 2096 END; 2097 2098 PROCEDURE mat_1nit(VAR mat : bool_matrix; plane : integer); 2099 2100 { This procedure i n i t i a l i z e s matrix 'mat' to false } 2101 2102 VAR 2103 i , j 1nteger; 2104 2105 BEGIN 2106 FOR 1:= (st-C) TO y_res_plus_C DO 2107 FOR j := 1 TO ((x_res_plus_C+C+2) div word_size + 1) DO 2108 BEGIN 2109 mat(i,j.plane) := O; 2110 END; 2111 2112 IF debugging*.10.) 2113 THEN 2114 BEGIN 2115 writeln; 2116 writeln*'**** Debugging mat i n i t - done * * * * ' ) ; 2117 writeln 2118 END 2119 END; 2120 2121 PROCEDURE contract; 2122 2123 { This procedure contracts the matrix in order to eliminate 'pockets'. } 2124 2125 VAR 2126 1,j,k : integer ; 2127 2128 BEGIN 2129 mat_init(work_matr ix,front) ; 2130 FOR i := (st-C) TO y_res_plus_C DO 2131 FOR j := (st-C) TO x_res_plus_C DO 2132 IF te s t ( m a t r i x , i , j , f r o n t ) 2133 THEN 2134 BEGIN 2135 IF NOT check_contract(i , j ) 2136 THEN 2137 BEGIN 2138 IF debugging(.10.) THEN wr1teln('matrix(',i:0,',',j:O,') = 0') 2139 END 2140 ELSE 2141 BEGIN 2142 set_bi t(work_matr1x,1,j,front); 2143 IF debugging(.10.) THEN w r 1 t e l n ( ' m a t r i x ( ' , i : 0 , J : O , ' ) = 1') 2144 END 2145 END 2146 ELSE unset_bit(work_matrix,i , j , front) ; 2147 copy_mat(matr ix,work_matr ix,front) 2148 END; 2149 2150 2151 FUNCTION check_expand(i,j integer) : boolean; 2152 2153 { This function determines whether a point should become ' l i t ' or l e f t 'off'. 2154 Any point which has at least one of i t s neighbours l i t must i t s e l f be l i t . ) I—i 2155 0 0 2156 VAR 2157 temp : boolean; 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 221 1 2212 2213 2214 2215 2216 2217 2218 BEGIN IF t e s t ( m a t r i x , i - 1,j- 1,front) OR test(matrix,i- 1,j,front) OR tes t ( m a t r i x , i - 1,j +1,front) THEN temp := true ELSE IF test(matr1x,i,j- 1,front) OR test(matr1x,i,j + 1,front) THEN temp := true ELSE IF test(matr1x,1+1,j-1.front) OR test(matr1x,i+1,j,front) OR test(matr1x,i+1,j+1,front) THEN temp := true ELSE temp := fal s e ; check_expand := temp; IF debugging(.10.) AND temp THEN BEGIN wr i t eln; w r i t e l n ( ' * * * * Debugging check matrix ****<); writeln!['1 = ' , 1 ); wr1teln('j = ' ,j ); writeln('mat chck = '.temp); wr1teln END END; PROCEDURE expand; { This procedure expands the matrix in order to eliminate 'pockets'. } VAR i , j , k : i nteger; BEGIN mat_i ni t(work_matr i x,front); FOR i := (st-C) TO y_res_plus_C DO FOR j := (st-C) TO x_res_plus_C DO IF NOT tes t ( m a t r i x , i , j , f r o n t ) THEN BEGIN IF check_expand(1,j) THEN BEGIN set_b i t(work_matr1x,i,j,front); IF debugg1ng(.10.) THEN writeln('matr1x(',i:0,',',j:0,') = 1') END END ELSE set_bi t(work_matr1x,1,j,front); copy_mat(matr i x,work_mat r1x,front) END; PROCEDURE find_linear(x,y : integer; VAR 1nd,off : integer); { This procedure performs a linear search of the 'index' array 1n order to locate the location in that array of the specif i e d point. } VAR M i , ^ subscript, o f f s e t integer; found : boolean; 2219 val u, 2220 count : integer; 2221 2222 BEGIN 2223 valu := -maxint; 2224 count := 0; 2225 found := f a l s e ; 2226 2227 WITH index(.x.) DO 2228 IF no <> 0 2229 THEN 2230 REPEAT 2231 count := count+1; 2232 subscript := sub_convert(count); 2233 offse t := off_convert(count); 2234 valu := ptrs(.subscript.)@(.offset 2235 2236 IF valu = y THEN found := true 2237 2238 UNTIL (valu>=y) OR found OR (count=no); 2239 2240 IF found 2241 THEN 2242 BEGIN 2243 ind := subscript; 2244 off := offs e t 2245 END 2246 ELSE 2247 BEGIN 2248 ind := maxint; 2249 off := maxint 2250 END; 2251 2252 IF debugging*.4.) 2253 THEN 2254 BEGIN 2255 wr i teln; 2256 writeln('**** Debugging fin d linear ****' 2257 writeln('ind = ',subscript:0); 2258 writeln('off = ',offset:0); 2259 wr i teln('x = ',x:0); 2260 wr i teln('y = ',y:0); 2261 wr i t e l n 2262 END 2263 END; 2264 2265 2266 FUNCTION s h i f t r ( i , j : integer) : integer; 2267 2268 { This function s h i f t s the b i t s to the right. 2269 2270 VAR 2271 k : integer; 2272 2273 BEGIN 2274 FOR k := 1 TO j DO i := i div 2; 2275 s h i f t r := i 2276 END; 2277 2278 PROCEDURE pre_process; > to o 2279 2280 { This procedure controls the expansion and contraction of the 'matrix' } 2281 2282 VAR 2283 i integer; 2284 2285 BEGIN 2286 FOR i := 1 TO C DO expand; 2287 FOR i : = 1 TO C DO contract; 2288 END; 2289 2290 PROCEDURE read_matrix; 2291 2292 { This procedure reads the COMTAL screen and sets the relevant positions of 2293 the 'matrix' to true. } 2294 2295 VAR 2296 1,j,k : 1nteger; 2297 word, 2298 b i t , 2299 work 1 , 2300 work2 integer; 2301 2302 BEGIN 2303 mat_init(matrix,front); 2304 mat_init(matrix,back); 2305 FOR 1 := st TO y_resolution DO 2306 BEGIN 2307 unit_no := unitno; 2308 read_comtal(uni t_no,buffer,1ength,ret_code); 2309 IF debugging*.10.) 2310 THEN 2311 BEGIN 2312 writeln; 2313 writeln*'**** Debugging read matrix * * * * ' ) ; 2314 writeln('length = '.length); 2315 writeln*'ret_code = ',ret_code); 2316 FOR j := 1 TO 8 DO writeln*' ',j:0,' ',buffer( . j . ) ) ; 2317 j := 80 2318 END; 2319 2320 IF debugging*.6.) THEN write*' ' ) ; 2321- FOR k := st TO x_reso1ut1on DO 2322 BEGIN 2323 word := (k + word_s1ze_1) div word_size; 2324 b i t := (k + word_size_1) mod word_size + 1; 2325 2326 workl := 1; 2327 workl := shift(work 1,word_size - b i t ) ; 2328 work2 := band*work 1,buffer*.word.)) ; 2329 work2 := shiftr(work2,word_size - b i t ) ; 2330 2331 IF abs(work2) = 1 2332 THEN 2333 BEGIN 2334 set_b1t(matr1x,i,k,front); to 2335 IF debugging*.6.) THEN write*'1') I-1 2336 END 2337 ELSE 2338 BEGIN 2339 IF debugging*.6.) THEN write*'0') 2340 END; 2341 2342 IF debugging*.6.) THEN 2343 IF (k mod j) = 0 THEN 2344 BEGIN 2345 writeln; 2346 write*' ') 2347 • END 2348 END; 2349 IF debugging*.6.) THEN writeln 2350 END; 2351 2352 w r i t e l n 2353 END; 2354 2355 FUNCTION graphic_plane*i_o,graph1c_pln : integer) : integer; 2356 2357 { This function calculates the control variable for the c a l l to the read_comtal 2358 routine. } 2359 2360 VAR 2361 work1,work2 : integer; 2362 temp : integer; 2363 2364 BEGIN 2365 workl := O; {set location to transfer graphic to top of display} 2366 work2 := 1; 2367 temp := 9; 2368 work2 := shift(work2,temp); {set b i t 9 to 1} 2369 workl := workl + work2; 2370 2371 work2 := graph1c_pln; 2372 work2 := work2 - 1; 2373 temp := 11; 2374 work2 := shift(work2,temp); {set b i t s 11&12 to graphic plane} 2375 workl := workl + work2; 2376 2377 work2 ;= 1_o; 2378 temp := 15; 2379 work2 := sh1ft(work2,temp); 2380 workl := bor(work 1,work2); 2381 2382 IF debugging*.10.) 2383 THEN 2384 BEGIN 2385 <• writeln; 2386 writeln*'**** Debugging graphic plane * * * * ' ) ; 2387 writeln*'graphic plane = ',work1:0); 2388 wr1teln('graph = ',graph:0); 2389 writeln 2390 END; 2391 graphic_plane := workl 2392 END; 2393 2394 FUNCTION init_comtal(i_o,graph 1c_pln : integer) : boolean; M 2395 M 2396 { This function i n i t i a l i z e s the COMTAL for use by the program. } 2397 2398 BEGIN 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 241 1 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 graphics := graphic_plane(i_o,graphic_pl n); control_comtal(uni t_no,graph,graphics,ret_code); wr1teln; CASE ret_cpde OF 0 : wr1teln('COMTAL connection OK'); 2 : writeln('COMTAL connection error'); 3 : wr1teln('Invalid command value'); 4 : wr1teln('Invalid control code value'); 5 : writeln('COMTAL not operational'); <>: writeln('Unspecified connection error') END; wr i te1n; IF ret_code = 0 THEN 1nit_comtal := true ELSE init_comtal := f a l s e END; PROCEDURE disp_poly(VAR mat : bool_matrix; plane : integer); VAR 1,j,k, word, b i t , mask integer; BEGIN uni t_no 1ength FOR 1 := BEGIN FOR j := un1tno; := leng_buff; st to y_resolut1on DO := 1 TO buf f _ s i z e DO buffer ( . j . ) := 0; FOR j : = st TO x_resolution DO IF test(mat,i,j.plane) THEN BEGIN k := j+C+1; word := (j + word_s1ze_1) div word_size; b i t := (k + word_size_1) mod word_size; mask := mask_b1t(bit); mask := rotate(mask,C+1); buffer(.word.) := bor(buffer(.word.),mask) END; wr 1 te_comtal(uni t_no,buffer,1ength,ret_code) END END; FUNCTION evens_check(VAR work : bool_matrix; y_m1n,y_max,x_min,x_max,plane : integer) : boolean; { This function is set to true If the number of beam changes associated with any s i n g l e scan l i n e is even. It is set to fa l s e otherwise. It also controls the deletion of a single unambiguous t a i l . } CONST above = - 1 ; beiow = +1; 2459 2460 2461 VAR 2462 i , j integer; { counters } 2463 count, { no of on/off changes } 2464 posn integer; { start posn of last change } 2465 change : boolean; { change on/off of beam } 2466 marked : boolean; { has an arrow been drawn } 2467 temp integer; 2468 2469 BEGIN 2470 mat_1nit(work,(3 - plane)); { i n i t i a l i z e for arrows } 2471 marked := fal s e ; 2472 evens_check := true; 2473 2474 FOR 1 :=• y_min TO y_max DO 2475 BEGIN 2476 count := 0; 2477 j := x_min - 1; 2478 2479 WHILE j < x_max DO 2480 BEGIN 2481 j := j + 1; 2482 IF test(work,1,j.plane) THEN 2483 BEGIN 2484 temp := j ; 2485 WHILE test(work,1.j +1,piane) DO j : = j + 1 ; 2486 2487 change := top_bot_check(work,temp,i,above,j,piane); 2488 IF change THEN change := top_bot_check(work,temp,i,below,j,piane); 2489 IF change THEN 2490 BEGIN 2491 count := count + 1; 2492 posn := temp 2493 END 2494 END 2495 END; 2496 2497 IF count = 1 THEN 2498 BEGIN 2499 count := count - 1; 2500 de!_b1ts(work,i,posn,plane) 2501 END; 2502 2503 IF odd(count) AND NOT marked THEN drw_arrows(work,marked,i,x_min,x_max,(3 - plane)); 2504 IF marked THEN evens_check := fal s e ; 2505 2506 IF NOT odd(count) THEN marked := fal s e ; { reset 'marked' once arrow is drawn } 2507 IF debugging*.2.) THEN 2508 IF odd(count) THEN 2509 BEGIN 2510 writeln; 2511 writeln('**** Debugging evens check * * * * ' ) ; 2512 wr1teln('row = ' , i : 0 ) ; 2513 writeln('cnt = ', count: 0); 2514 writeln to 2515 END; 2516 2517 END 2518 END; 2519 2520 PROCEDURE biank_out(VAR mat : bOOl_matrix; y 1 ,x 1 ,y2,x2,plane : integer); 2521 2522 { This procedure blanks out a portion of the user's input in the event 2523 of two boundaries not being d i s t i n c t } 2524 2525 VAR 2526 1,j integer; 2527 2528 BEGIN 2529 FOR 1 := y1 TO y2 DO 2530 FOR j := x1 TO x2 DO unset_bit(mat,i,j,plane) 2531 END; 2532 2533 PROCEDURE drw_arrows(VAR mat : bool_matrix; VAR marked : boolean; row,x_min,x_max,plane : integer); 2534 2535 { This procedure draws arrows to highlight potential t a i l s } 2536 2537 CONST 2538 len_arrow =6; 2539 len_t1p = 3; 2540 tip_w1dth = 3; 2541 above = -1 ; 2542 below = +1; 2543 2544 VAR 2545 l,k,j,m, 2546 t.temp, 2547 posn, { position of last change in beam } 2548 side : Integer; { l e f t or right of l i n e depending on available space ) 2549 change : boolean; 2550 2551 BEGIN 2552 j := x_min - 1; 2553 posn := st; 2554 side := -1; 2555 2556 marked := true; 2557 no_arrows := no_arrows + 1; 2558 2559 WHILE j < x_max DO 2560 BEGIN 2561 j := j + 1; 2562 IF test(mat,row,j,3-plane) THEN 2563 BEGIN 2564 t := j ; 2565 temp := t; 2566 2567 WHILE test(mat,row,t+1,3-plane) DO t := t + 1 ; 2568 2569 change := top_bot_check(mat,temp,row,above,t,3-plane); 2570 IF change THEN change := top_bot_check(mat,temp,row,beiow,t,3-plane); 2571 2572 IF change THEN 2573 BEGIN M 2574 insert_point (-1 , j , row) ; tvj 2575 2576 IF j-posn < len_arrow THEN 2577 BEGIN 2578 side := -side; ° 2579 WHILE test(mat,row,j+1,3-p1ane) DO j := j + 1 2580 END; 2581 2582 2583 { draw the arrow } 2584 2585 FOR 1 := 1 TO tip_w1dth DO 2586 BEGIN 2587 IF 1=1 THEN m := len_arrow 2588 ELSE m := len_t1p; 2589 2590 FOR k := 1 TO m DO set_b11(mat,row-(1 - 1),j + (1+k)*side,piane); 2591 IF 1<>1 THEN FOR k := 1 TO m DO set_bit(mat,row+(1 - 1),j+ (1+k)*side,piane) 2592 END 2593 END 2594 END; 2595 2596 IF test(mat,row,j,3-plane) THEN 2597 BEGIN 2598 WHILE test(mat,row,j+1,3-plane) DO j := j+1; 2599 posn := j 2600 END 2601 END; 2602 2603 IF debugging*.2.) THEN 2604 BEGIN 2605 writeln; 2606 wr i t e l n ( ' * * * * Debugging draw arrows * * * * ' ) ; 2607 writeln('row = ',row:0); 2608 writeln 2609 END 2610 END; 261 1 2612 PROCEDURE del_tail(VAR work : bool_matr1x; i,posn,1ast,piane : integer); 2613 2614 { This procedure deletes t a i l s i d e n t i f i e d by the user ) 2615 2616 CONST 2617 below = 1; 2618 above = -1; 2619 2620 VAR 2621 j , { posn of last on b i t in sequence } 2622 1, { posn of f i r s t on b i t in sequence } 2623 row : integer; { row being processed in deleting the t a i l } 2624 bit s _ d e l e t e d : boolean; { f l a g to indicate whether bi t s on a row were deleted ) 2625 2626 BEGIN 2627 del_bits(work,i,posn,piane); 2628 2629 row := i ; 2630 2631 REPEAT 2632 row := row + 1 ; 2633 1 := posn - 1 ; 2634 b1ts_deleted := fal s e ; £ 2635 CM 2636 IF test(work,row,1.plane) THEN WHILE test(work,row,1 -1,piane) DO 1 := 1 - 1; 2637 . 2638 IF NOT test(work,row,1,piane) 2639 THEN 2640 REPEAT 2641 1 := 1 + 1 2642 UNTIL test(work,row,1,p1ane) OR (1 > l a s t ) ; 2643 2644 j : = 1 ; 2645 posn := 1; 2646 2647 WHILE test(work,row,j+1,piane) DO j := j + 1; 2648 2649 IF test(work,row,1.plane) 2650 THEN 2651 IF top_bot_check(work,1,row,below,j,piane) AND 2652 (NOT end_check(work,row,above,1,j,plane) OR row=i) THEN 2653 BEGIN 2654 del_b1ts(work,row,1,pi ane) ; 2655 b1ts_deleted : = true 2656 END 2657 2658 UNTIL NOT b1ts_deleted; 2659 2660 IF debugging*.2.) THEN 2661 BEGIN 2662 writeln; 2663 wr1teln('**** Debugging delete t a i l * * * * ' ) : 2664 wr1teln('posn = ',posn:0); 2665 writeln('row = ',1:0); 2666 writeln 2667 END 2668 END; 2669 2670 PROCEDURE de1_bits(VAR work : bool_matrix; row,posn,piane : integer); 2671 2672 { This procedure deletes a contiguous st r i n g of b i t s } 2673 2674 VAR 2675 col : integer; 2676 2677 BEGIN 2678 col := posn; 2679 2680 WHILE test(work,row,col,piane) DO 2681 BEGIN 2682 unset_bi t(work,row,col,piane); 2683 col := col + 1 2684 END 2685 END; 2686 2687 PROCEDURE best_arrow(VAR row,col : integer); 2688 2689 { This procedure matches the arrow h i t with the t a i l associated with 1t ) 2690 2691 VAR 2692 d i s t : r e a l ; { d1st from h i t point to t a i l } 2693 rw.cl, { temp values for t a i l ordinates} 2694 x,y integer; { ordinate values of t a i l s } 2695 2696 BEGIN 2697 d i s t := maxint; 2698 gen_ptr := polygon(.- 1.).base_ptr; 2699 2700 WHILE gen_ptr <> n i l DO 2701 BEGIN 2702 x := gen_ptr@.poly_x; 2703 y := gen_ptr@.poly_y; 2704. 2705 IF sqrt(sqr(row-y)+sqr(col-x)) < d1st 2706 THEN 2707 BEGIN 2708 d i s t := sqrt(sqr(row-y) + sqr(col-x)); 2709 rw := y; 2710 c l := x 2711 END; 2712 2713 gen_ptr := gen_ptr@.poly_ptr 2714 END; 2715 2716 row := rw; { set row & col to those nearest the ' h i t ' point } 2717 col := cl ; 2718 2719 IF debugg1ng(.2.) THEN 2720 BEGIN 2721 writeln; 2722 writel n ( ' * * * * Debugging best arrow * * * * ' ) ; 2723 writeln('row = ',row:0); 2724 wr1teln('col = ',col:0); 2725 writeln 2726 END 2727 END; 2728 2729 PROCEDURE k11l_poly_1n_save; 2730 2731 BEGIN 2732 gen_ptr := polygon(.0.).base_ptr; 2733 2734 IF gen_ptr <> n i l THEN 2735 REPEAT 2736 unset_bi t (save_mat r 1 x, gen_pt r@. po 1 y_y, gen_ptr<a. pol y_x, front); 2737 gen_ptr := gen_ptr@.poly_ptr 2738 UNTIL gen_ptr = n i l 2739 END; 2740 2741 PROCEDURE copy_poly_to_save; 2742 2743 VAR 2744 1,j Integer; 2745 2746 BEGIN 2747 FOR 1 := m1n_smudge_y TO max_smudge_y DO 2748 FOR j := m 1 n_stnudge_x TO max_smudge_x DO 2749 IF test(work_matrix,i,j.back) THEN set_bit(save_matrix,i,j,back); 2750 IF debugging(.1.) THEN copy_mat(save_matrix,save_matr1x,back) 2751 END; 2752 2753 PROCEDURE get_label; 2754 NJ 2755 VAR 0 0 2756 dummy : Integer; 2757 2758 BEGIN 2759 read_text('&Enter label for area ( <0 - 20> characters )',polygon(.pt_set_no.).po1y_descr1pt); 2760 IF polygon(.pt_set_no.).poly_descript(.1.) <> nul THEN 2761 BEGIN 2762 read_1nt(1,10,'SSize for label = ? ' ,polygon(.pt_set_no.) . s1ze); 2763 2764 cmt_1n1t1al1ze(un1t_no,ret_code) ; 2765 read_int(0,1,'&P1 ace cursor at position for label & RETURN',dummy); 2766 target_in(polygon(.pt_set_no.).descript_posn.y, 2767 polygon(.pt_set_no.).descript_posn.x); 2768 END 2769 END; 2770 2771 PROCEDURE background*VAR mat : bool_matrix; plane,displ integer); 2772 2773 BEGIN 2774 cmtl_command(' CLEAR GRAPHIC 1 ;',0); 2775 cmtl_command(' CLEAR GRAPHIC 2 ;',0); 2776 cmtl_command(' ADD GRAPHIC 2 ;',0); 2777 2778 IF init_comtal(wrt,displ) THEN 2779 BEGIN 2780 disp_poly(mat,plane) 2781 END 2782 END; 2783 2784 PROCEDURE tai1_and_d1st1nctness_check; 2785 2786 BEGIN 2787 IF debugging*.8.) THEN 2788 BEGIN 2789 copy_mat(matr i x,matr i x,front); 2790 w r l t e ( ' l ' ) ; 2791 copy_mat(matrix,matrix,back); 2792 w r l t e ( ' l ' ) ; 2793 copy_mat(work_matr1x,work_matr i x,front); 2794 w r i t e ( ' l ' ) ; 2795 copy_mat(work_matr1x,work_matr ix,back); 2796 END; 2797 2798 evens := evens_check(work_matr1x,min_smudge_y,max_smudge_y,m1n_smudge_x,max_smudge_x,back); 2799 2800 cmtl_command(' CLEAR GRAPHIC 1 ;',0); 2801 cmtl_command(' DISPLAY GRAPHIC 1 ;',0); 2802 2803 IF 1nit_comtal(wrt,1) THEN 2804 BEGIN 2805 disp_poly(work_matrix,back); 2806 END; 2807 2808 IF debugging(.8.) THEN 2809 BEGIN 2810 copy_mat(matr1x,matr1x , front); 2811 w r i t e ( ' l ' ) ; 28 12 copy_mat(matr1x,matr i x,back); 2813 w r i t e ( ' l ' ) ; 2814 copy_mat(work_matrix,work_matr1x,front); ^ 2815 w r i t e ( ' l ' ) ; 2816 copy_mat(work_matr ix,work_matr ix,back); 2817 snap; 2818 END; 2819 2820 IF quest1on('&CHECK : Is the polygon d i s t i n c t ? (Y/N)') 2821 THEN 2822 BEGIN 2823 cmtl_command(' ADD GRAPHIC 2 ;',0); 2824 IF NOT evens AND (no_arrows > O) THEN 2825 BEGIN 2826 IF 1nit_comtal(wrt,2) THEN 2827 BEGIN 2828 d1sp_poly(work_matr1x,front); 2829 END; 2830 2831 FOR arrow := 1 TO no_arrows DO 2832 BEGIN 2833 cmt_ini t ial1ze(un1t_no,ret_code); 2834 read_1nt(0,1,'SPlace cursor at correct arrow & RETURN'.dummy); 2835 target_in(row,col); 2836 2837 best_arrow(row,col); 2838 2839 j : = c o l ; 2840 WHILE test(work_matr1x,row,j,back) DO j := j + 1; 2841 2842 del_ta11(work_matr1x,row,col,j,back) 2843 END 2844 END 2845 ELSE ; 2846 k1 1 l_poly_in_save; 2847 copy_poly_to_save; 2848 2849 get_label; 2850 END 2851 ELSE 2852 BEGIN 2853 read_1nt(0,1,'SPlace cursor at top l e f t hand corner for blank out & RETURN',dummy); 2854 target_1n(top_row,top_col); 2855 read_int(0,1,'SPlace cursor at bot right hand corner for blank out & RETURN',dummy) ; 2856 target_in(bot_row,bot_col ); 2857 2858 bl ank_out(save_matr1x,top_row,top_col,bot_row,bot_col,front); 2859 2860 background(save_matrix,back,2); 2861 2862 IF 1nit_comtal(wrt,1) THEN 2863 BEGIN 2864 disp_poly(save_matrix,front); 2865 cmtl_command(' TRACE GRAPHIC 1 ;',0); 2866 read_1nt(0,1,'SRetrace blanked area & RETURN'.dummy); 2867 IF 1n1t_comtal(rd,1) THEN 2868 BEGIN 2869 secondary_1nitialize; 2870 read_matrix; 2871 copy_mat(save_matrix,matrix,front); 2872 2873 pre_process; 2874 estab_index; 2875 2876 return_to_pool(pt_set_no); 2877 2878 pt_set_no := pt_set_no - 1 ; 2879 2880 END 2881 END 2882 END; 2883 2884 IF debugging*.8.) THEN 2885 IF 1nit_comtal (wrt,1) THEN 2886 BEGIN 2887 d1sp_po1y(work_matr1x,back); 2888 END 2889 END; 2890 2891 PROCEDURE read_and_process; 2892 2893 VAR 2894 count : Integer; 2895 2896 BEGIN 2897 IF init_comtal(rd,1) 2898 THEN 2899 WHILE more_to_come DO 2900 BEGIN 2901 read_matr1x; 2902 copy_mat(save_matr1x,matr1x,front) ; 2903 2904 pre_process; 2905 estab_1ndex; 2906 2907 f r s t _ p t := f1rst_pt; 2908 2909 WHILE frst_pt.found DO 2910 BEGIN 2911 curr_x := frst_pt.x; 2912 curr_y := fr s t _ p t . y ; 2913 2914 pt_set_no := pt_set_no + 1; 2915 2916 cmtl_command(' CLEAR GRAPHIC 1 ;',0); 2917 cmtl_command(' CLEAR GRAPHIC 2 ;',0); 2918 2919 t e r t 1 a r y _ i n i t 1 a l i z e ; 2920 2921 f1nd_area; 2922 2923 f1nd_linear(frst_pt.x,frst_pt.y,frst.1nd, f r s t . o f f ) ; 2924 del e t e _ i n d e x ( f r s t _ p t . x , f r s t _ p t . y , f r s t . 1 n d , f r s t . o f f ) ; 2925 2926 ta11_and_d1st i nctness_check; 2927 2928 f r s t _ p t := f i r s t _ p t 2929 END; 2930 2931 IF quest1on('&More polygons ? (Y/N)') 2932 THEN 2933 BEGIN 2934 more_to_come := true; 2935 background(save_matr1x,back, 2); 2936 2937 IF 1n1t_comta1(wrt,1) THEN 2938 BEGIN 2939 mat_ini t(save_matr i x,front); 2940 mat_init(matr1x,front); 2941 2942 cmtl_command(' TRACE GRAPHIC 1 ;',0); 2943 read_1nt(0,1,'STrace desired area(s) & RETURN',dummy); 2944 2945 IF init_comta1(rd,1) THEN 2946 BEGIN 2947 secondary_initia 1ize; 2948 already_active := true 2949 END 2950 END 2951 END 2952 ELSE more_to_come := fal s e ; 2953 END; 2954 2955 IF 1nit_comtal(wrt,1) THEN 2956 BEGIN 2957 f11l_polygon(mi n_x,max_x,st,y_resolut ion,save_matr ix); 2958 d1sp_poly(save_matr1x,front); 2959 2960 FOR 1 := 1 TO pt_set_no DO 2961 IF polygon(.1.).poly_descript(.1.) <> nul THEN 2962 BEGIN 2963 count := O; 2964 2965 FOR j := 1 TO str_length DO 2966 IF polygon(.1.).poly_descript(.j.) <> nul THEN count := count + 1; 2967 2968 pr i nt_text(polygon(.i.).poly_descr ipt,count.graph,polygon(.i.).s ize, 2969 polygon(.1.).descript_posn.y,polygon(.i.).descr1pt_posn.x, 2970 top_row,top_col) 2971 END; 2972 2973 term_comtal(uni t_no,ret_code); 2974 writeln; 2975 CASE ret_code OF 2976 0 : wr1teln('Termination of COMTAL O.K.'); 2977 2 : wr1teln('Connection error'); 2978 5 : writeln('COMTAL not operational') 2979 END 2980 END 2981 2982 END; 2983 2984 BEGIN { Main program } 2985 primary_1nitialize; 2986 read_and_process 2987 END. 2988 End of F i l e $2.88, $2.98T $SIG 133 A p p e n d i x B : R e c u r s i v e A l g o r i t h m f o r E x p a n s i o n PROCEDURE e x p a n d ( n : i n t e g e r ; VAR mat : b o o l _ m a t r i x ) ; VAR r o w , { row f o r p i x e l } c o l : i n t e g e r { c o l f o r p i x e l } B E G I N I F n >= 1 THEN B E G I N row := g e t _ r o w ( n ) ; c o l := g e t _ c o l ( n ) ; I F NOT p i x e l _ s e t ( r o w , c o l ) THEN I F c h e c k _ e x p a n d ( r o w , c o l ) T H E N B E G I N e x p a n d ( n - l , m a t ) ; s e t _ p i x e l ( r o w , c o l , m a t ) END E L S E e x p a n d ( n - l , m a t ) E L S E e x p a n d ( n - l , m a t ) END E N D ; W h e r e : n : i s t h e number o f e l e m e n t s o f t h e m a t r i x w h i c h r e m a i n t o be p r o c e s s e d . T h e number n s e r v e s b o t h a s a c o u n t e r o f t h e u n p r o c e s s e d m a t r i x e l e m e n t s a n d a s a p o i n t e r t o t h e e l e m e n t t o be p r o c e s s e d . B o t h g e t _ r o w a n d g e t _ c o l d e r i v e t h e i r v a l u e s f r o m n . g e t _ r o w : r e t u r n s t h e row f o r t h e n t h p i x e l , g e t _ c o l : r e t u r n s t h e c o l u m n f o r t h e n t h p i x e l , p i x e l _ s e t : i s a b o o l e a n f u n c t i o n w h i c h d e t e r m i n e s w h e t h e r p i x e l ( r o w , c o l ) i s s e t o r n o t , s e t _ p i x e l : s e t s t h e ( r o w , c o l ) t h p i x e l a n d c h e c k _ e x p a n d : i s a b o o l e a n f u n c t i o n w h i c h c h e c k s i f a p i x e l s h o u l d be e x p a n d e d o r n o t . T h e f i r s t c a l l t o e x p a n d i s a s f o l l o w s : e x p a n d ( ( x r e s o l u t i o n * y r e s o l u t i o n ) , m a t r i x ) 

Cite

Citation Scheme:

        

Citations by CSL (citeproc-js)

Usage Statistics

Share

Embed

Customize your widget with the following options, then copy and paste the code below into the HTML of your page to embed this item in your website.
                        
                            <div id="ubcOpenCollectionsWidgetDisplay">
                            <script id="ubcOpenCollectionsWidget"
                            src="{[{embed.src}]}"
                            data-item="{[{embed.item}]}"
                            data-collection="{[{embed.collection}]}"
                            data-metadata="{[{embed.showMetadata}]}"
                            data-width="{[{embed.width}]}"
                            data-media="{[{embed.selectedMedia}]}"
                            async >
                            </script>
                            </div>
                        
                    
IIIF logo Our image viewer uses the IIIF 2.0 standard. To load this item in other compatible viewers, use this url:
https://iiif.library.ubc.ca/presentation/dsp.831.1-0051840/manifest

Comment

Related Items