/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h i s   w o r k   i s   b a s e d   o n   t h e   o r i g i n a l   A R T o o l K i t   d e v e l o p e d   b y 
 
   *       H i r o k a z u   K a t o 
 
   *       M a r k   B i l l i n g h u r s t 
 
   *       H I T L a b ,   U n i v e r s i t y   o f   W a s h i n g t o n ,   S e a t t l e 
 
   *   h t t p : / / w w w . h i t l . w a s h i n g t o n . e d u / a r t o o l k i t / 
 
   * 
 
   *   T h e   N y A R T o o l k i t C S   i s   J a v a   e d i t i o n   A R T o o l K i t   c l a s s   l i b r a r y . 
 
   *   C o p y r i g h t   ( C ) 2 0 0 8 - 2 0 0 9   R y o   I i z u k a 
 
   * 
 
   *   T h i s   p r o g r a m   i s   f r e e   s o f t w a r e :   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
   *   i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
   *   t h e   F r e e   S o f t w a r e   F o u n d a t i o n ,   e i t h e r   v e r s i o n   3   o f   t h e   L i c e n s e ,   o r 
 
   *   ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
   *   
 
   *   T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
   *   b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
   *   M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
   *   G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
   * 
 
   *   Y o u   s h o u l d   h a v e   r e c e i v e d   a   c o p y   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e 
 
   *   a l o n g   w i t h   t h i s   p r o g r a m .     I f   n o t ,   s e e   < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > . 
 
   *   
 
   *   F o r   f u r t h e r   i n f o r m a t i o n   p l e a s e   c o n t a c t . 
 
   * 	 h t t p : / / n y a t l a . j p / n y a t o o l k i t / 
 
   * 	 < a i r m a i l ( a t ) e b o n y . p l a l a . o r . j p >   o r   < n y a t l a ( a t ) n y a t l a . j p > 
 
   *   
 
   * / 
 
 n a m e s p a c e   j p . n y a t l a . n y a r t o o l k i t . c s . c o r e 
 
 { 
 
 
 
 
 
         / * * 
 
           *   S0n0000o00{ @ l i n k   N y A R L a b e l i n g _ A R T o o l K i t } 0000(uD0_0wb_iQhVg0Y00
 
           *   iQW0_0wb_00]000000pe{ @ l i n k   # o n S q u a r e D e t e c t } x0wW0~0Y00
 
           *   }b000g0]000000pe{ @ l i n k   # o n S q u a r e D e t e c t } 0[ňY00_L0B00~0Y00
 
           * / 
 
         p u b l i c   a b s t r a c t   c l a s s   N y A R S q u a r e C o n t o u r D e t e c t o r _ A R T o o l K i t   :   N y A R S q u a r e C o n t o u r D e t e c t o r 
 
         { 
 
                 p r i v a t e   c o n s t   i n t   A R _ A R E A _ M A X   =   1 0 0 0 0 0 ; / /   # d e f i n e   A R _ A R E A _ M A X   1 0 0 0 0 0 
 
                 p r i v a t e   c o n s t   i n t   A R _ A R E A _ M I N   =   7 0 ; / /   # d e f i n e   A R _ A R E A _ M I N   7 0 
 
                 p r i v a t e   r e a d o n l y   i n t   _ w i d t h ; 
 
                 p r i v a t e   r e a d o n l y   i n t   _ h e i g h t ; 
 
 
 
                 p r i v a t e   r e a d o n l y   N y A R L a b e l i n g _ A R T o o l K i t   _ l a b e l i n g ; 
 
 
 
                 p r i v a t e   r e a d o n l y   N y A R L a b e l i n g I m a g e   _ l i m a g e ; 
 
 
 
                 p r i v a t e   r e a d o n l y   N y A R L a b e l O v e r l a p C h e c k e r < N y A R L a b e l i n g L a b e l >   _ o v e r l a p _ c h e c k e r   =   n e w   N y A R L a b e l O v e r l a p C h e c k e r < N y A R L a b e l i n g L a b e l > ( 3 2 ) ; 
 
                 p r i v a t e   r e a d o n l y   N y A R C o n t o u r P i c k u p _ A R T o o l K i t   _ c p i c k u p   =   n e w   N y A R C o n t o u r P i c k u p _ A R T o o l K i t ( ) ; 
 
                 p r i v a t e   r e a d o n l y   N y A R C o o r d 2 S q u a r e V e r t e x I n d e x e s   _ c o o r d 2 v e r t e x   =   n e w   N y A R C o o r d 2 S q u a r e V e r t e x I n d e x e s ( ) ; 
 
 
 
                 p r i v a t e   r e a d o n l y   N y A R I n t C o o r d i n a t e s   _ c o o r d ; 
 
                 p r i v a t e   r e a d o n l y   i n t [ ]   _ _ d e t e c t M a r k e r _ m k v e r t e x   =   n e w   i n t [ 4 ] ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   eQR;uPn00000c[W0f000000000ubW0~0Y00
 
                   *   @ p a r a m   i _ s i z e 
 
                   *   eQR;uPn0000
 
                   * / 
 
                 p u b l i c   N y A R S q u a r e C o n t o u r D e t e c t o r _ A R T o o l K i t ( N y A R I n t S i z e   i _ s i z e ) 
 
                 { 
 
                         t h i s . _ w i d t h   =   i _ s i z e . w ; 
 
                         t h i s . _ h e i g h t   =   i _ s i z e . h ; 
 
                         t h i s . _ l a b e l i n g   =   n e w   N y A R L a b e l i n g _ A R T o o l K i t ( ) ; 
 
                         t h i s . _ l i m a g e   =   n e w   N y A R L a b e l i n g I m a g e ( t h i s . _ w i d t h ,   t h i s . _ h e i g h t ) ; 
 
 
 
                         / /   *n0 g'Ywo0;ubk0 f0F00 g'Yn0web_0000
 
                         i n t   n u m b e r _ o f _ c o o r d   =   ( t h i s . _ w i d t h   +   t h i s . _ h e i g h t )   *   2 ; 
 
 
 
                         / /   *0000o0p	Yc0Y00n0g00*0000n0
PS00
 
                         t h i s . _ c o o r d   =   n e w   N y A R I n t C o o r d i n a t e s ( n u m b e r _ o f _ c o o r d ) ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00000K00wb_0iQW0f00]000000pe{ @ l i n k   # o n S q u a r e D e t e c t } g0wW0~0Y00
 
                   *   [ň000g0o00wb_iQQt0W0f00P}g0wY00Qt0[ňW0f0O0`0U0D00
 
                   *   @ p a r a m   i _ r a s t e r 
 
                   *   iQCQn0000;uP
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   v o i d   d e t e c t M a r k e r ( N y A R B i n R a s t e r   i _ r a s t e r ,   N y A R S q u a r e C o n t o u r D e t e c t o r . C b H a n d l e r   i _ c b ) 
 
                 { 
 
                         N y A R L a b e l i n g I m a g e   l i m a g e   =   t h i s . _ l i m a g e ; 
 
 
 
                         / /   000peL00 j00S0S0~0g0
 
                         i n t   l a b e l _ n u m   =   t h i s . _ l a b e l i n g . l a b e l i n g ( i _ r a s t e r ,   t h i s . _ l i m a g e ) ; 
 
                         i f   ( l a b e l _ n u m   <   1 ) 
 
                         { 
 
                                 r e t u r n ; 
 
                         } 
 
 
 
                         N y A R L a b e l i n g L a b e l S t a c k   s t a c k   =   l i m a g e . g e t L a b e l S t a c k ( ) ; 
 
                         / / 0000000W0f0J0O0
 
                         s t a c k . s o r t B y A r e a ( ) ; 
 
                         / / 
 
                         N y A R L a b e l i n g L a b e l [ ]   l a b e l s   =   s t a c k . g e t A r r a y ( ) ; 
 
 
 
                         / /   00D000000ۘp0W0
 
                         i n t   i ; 
 
                         f o r   ( i   =   0 ;   i   <   l a b e l _ n u m ;   i + + ) 
 
                         { 
 
                                 / /   ig[aQn0000000k0j00~0g0!q
 
                                 i f   ( l a b e l s [ i ] . a r e a   < =   A R _ A R E A _ M A X ) 
 
                                 { 
 
                                         b r e a k ; 
 
                                 } 
 
                         } 
 
                         i n t   x s i z e   =   t h i s . _ w i d t h ; 
 
                         i n t   y s i z e   =   t h i s . _ h e i g h t ; 
 
                         N y A R I n t C o o r d i n a t e s   c o o r d   =   t h i s . _ c o o r d ; 
 
                         i n t [ ]   m k v e r t e x   =   t h i s . _ _ d e t e c t M a r k e r _ m k v e r t e x ; 
 
 
 
                         N y A R L a b e l O v e r l a p C h e c k e r < N y A R L a b e l i n g L a b e l >   o v e r l a p   =   t h i s . _ o v e r l a p _ c h e c k e r ; 
 
 
 
                         / / ͑j000000n0 g'Ype0-[
 
                         o v e r l a p . s e t M a x L a b e l s ( l a b e l _ n u m ) ; 
 
                         f o r   ( ;   i   <   l a b e l _ n u m ;   i + + ) 
 
                         { 
 
                                 N y A R L a b e l i n g L a b e l   l a b e l _ p t   =   l a b e l s [ i ] ; 
 
                                 i n t   l a b e l _ a r e a   =   l a b e l _ p t . a r e a ; 
 
                                 / /   ig[a000000\U0O0j0c0_00B}N
 
                                 i f   ( l a b e l _ a r e a   <   A R _ A R E A _ M I N ) 
 
                                 { 
 
                                         b r e a k ; 
 
                                 } 
 
                                 / /   0000WL0;ubn0gk0cW0f0D00p0dY
 
                                 i f   ( l a b e l _ p t . c l i p _ l   = =   1   | |   l a b e l _ p t . c l i p _ r   = =   x s i z e   -   2 ) 
 
                                 { / /   i f ( w c l i p [ i * 4 + 0 ]   = =   1   | |   w c l i p [ i * 4 + 1 ]   = = x s i z e - 2 ) { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 i f   ( l a b e l _ p t . c l i p _ t   = =   1   | |   l a b e l _ p t . c l i p _ b   = =   y s i z e   -   2 ) 
 
                                 { / /   i f (   w c l i p [ i * 4 + 2 ]   = =   1   | |   w c l i p [ i * 4 + 3 ]   = = y s i z e - 2 ) { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / /   ek0iQU00_0wb_h0n0͑j000x
 
                                 i f   ( ! o v e r l a p . c h e c k ( l a b e l _ p t ) ) 
 
                                 { 
 
                                         / /   ͑j0c0f0D000F0`00
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / /   *퐒0S_
 
                                 i f   ( ! t h i s . _ c p i c k u p . g e t C o n t o u r ( l i m a g e ,   l i m a g e . g e t T o p C l i p T a n g e n t X ( l a b e l _ p t ) ,   l a b e l _ p t . c l i p _ t ,   c o o r d ) ) 
 
                                 { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / / *}00000W0f00wb_K0i0F0K00$R[0wb_j00p0m k v e r t e x k0S_
 
                                 i f   ( ! t h i s . _ c o o r d 2 v e r t e x . g e t V e r t e x I n d e x e s ( c o o r d ,   l a b e l _ a r e a ,   m k v e r t e x ) ) 
 
                                 { 
 
                                         / /   pn0S_L0Qegj0K0c0_0
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / / wb_0zvW0_0S0h00000000peg0w
 
                                 i _ c b . d e t e c t M a r k e r C a l l b a c k ( c o o r d ,   m k v e r t e x ) ; 
 
 
 
                                 / /   iQnn0wb_n0^\W0_00000͑j000000k0RY000
 
                                 o v e r l a p . p u s h ( l a b e l _ p t ) ; 
 
 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
 
 
         } 
 
 } 
 
 
 
 
 
 