/ *   
 
   *   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 > 
 
   *   
 
   * / 
 
 u s i n g   S y s t e m ; 
 
 u s i n g   S y s t e m . D i a g n o s t i c s ; 
 
 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 
 
 { 
 
 
 
         / * * 
 
           *  0S0n0000o0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 } n0QRY000y0000;uP0<h
}Y00000g0Y00
 
           *  0000k0000000SW0_00y0000;uPh00000n0MR0;uPn000000n0MR0ca0~0Y00
 
           *   < p > 000;uP- 
 
           *   0y0000;uPo00000n000000$P0<h
}W0~0Y0000000$Po00{ @ l i n k   # g e t I n d e x A r r a y } g0
 
           *   _00000000MR0Oc0f00000juSk0	Ycg0M0~0Y00
 
           *   OH0p0000000juSn n0;u }o00000juSL [ n ] k0j00~0Y00
 
           *   < / p > 
 
           * / 
 
         p u b l i c   c l a s s   N y A R L a b e l i n g I m a g e   :   N y A R R a s t e r _ B a s i c C l a s s 
 
         { 
 
                 p r i v a t e   c o n s t   i n t   M A X _ L A B E L S   =   1 0 2 4   *   3 2 ; 
 
                 / * *   ;uP0000* / 
 
                 p r o t e c t e d   i n t [ ]   _ b u f ; 
 
                 / * *   000MRn00000* / 
 
                 p r o t e c t e d   N y A R L a b e l i n g L a b e l S t a c k   _ l a b e l _ l i s t ; 
 
                 / * *   000000000* / 
 
                 p r o t e c t e d   i n t [ ]   _ i n d e x _ t a b l e ; 
 
                 / * *   000000000L0	gRg0B00K00:yY0$P* / 
 
                 p r o t e c t e d   b o o l   _ i s _ i n d e x _ t a b l e _ e n a b l e ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   0y0000;uPn00000c[W0f000000000ubW0~0Y00
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   000n0E^0c[W0~0Y00
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   000n0ؚU00c[W0~0Y00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   N y A R L a b e l i n g I m a g e ( i n t   i _ w i d t h ,   i n t   i _ h e i g h t ) 
 
                         :   b a s e ( i _ w i d t h ,   i _ h e i g h t ,   N y A R B u f f e r T y p e . I N T 1 D ) 
 
                 { 
 
                         t h i s . _ b u f   =   n e w   i n t [ i _ h e i g h t   *   i _ w i d t h ] ; 
 
                         t h i s . _ l a b e l _ l i s t   =   n e w   N y A R L a b e l i n g L a b e l S t a c k ( M A X _ L A B E L S ) ; 
 
                         t h i s . _ i n d e x _ t a b l e   =   n e w   i n t [ M A X _ L A B E L S ] ; 
 
                         t h i s . _ i s _ i n d e x _ t a b l e _ e n a b l e   =   f a l s e ; 
 
                         / / ubBfk0g0fM0~0Y00
 
                         d r a w F r a m e E d g e ( ) ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   ;uP00000ԏW0~0Y000000n0b__o00{ @ l i n k   N y A R B u f f e r T y p e # I N T 1 D } ( i n t [ ] ) g0Y00
 
                   * / 
 
                 p u b l i c   o v e r r i d e   o b j e c t   g e t B u f f e r ( ) 
 
                 { 
 
                         r e t u r n   t h i s . _ b u f ; 
 
                 } 
 
                 p u b l i c   o v e r r i d e   b o o l   h a s B u f f e r ( ) 
 
                 { 
 
                         r e t u r n   t h i s . _ b u f   ! =   n u l l ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0000g0o00peo0_jW0~0[000
 
                   * / 
 
                 p u b l i c   o v e r r i d e   v o i d   w r a p B u f f e r ( o b j e c t   i _ r e f _ b u f ) 
 
                 { 
 
                         N y A R E x c e p t i o n . n o t I m p l e m e n t ( ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00wb_000;uP0V0g	0fM0~0Y00
 
                   *   A R T o o l K i t Ncn00000iQn0MRQtk0_j0_000[ňW0f0D0~0Y00
 
                   * / 
 
                 p u b l i c   v o i d   d r a w F r a m e E d g e ( ) 
 
                 { 
 
                         i n t   w   =   t h i s . _ s i z e . w ; 
 
                         i n t   h   =   t h i s . _ s i z e . h ; 
 
                         / /   N y L a b e l i n g I m a g e n00000RgS( gfM0) 
 
                         i n t [ ]   i m g   =   ( i n t [ ] ) t h i s . _ b u f ; 
 
                         i n t   b o t t o m _ p t r   =   ( h   -   1 )   *   w ; 
 
                         f o r   ( i n t   i   =   0 ;   i   <   w ;   i + + ) 
 
                         { 
 
                                 i m g [ i ]   =   0 ; 
 
                                 i m g [ b o t t o m _ p t r   +   i ]   =   0 ; 
 
                         } 
 
                         f o r   ( i n t   i   =   0 ;   i   <   h ;   i + + ) 
 
                         { 
 
                                 i m g [ i   *   w ]   =   0 ; 
 
                                 i m g [ ( i   +   1 )   *   w   -   1 ]   =   0 ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
 
 
                 / * * 
 
                   *   S0n0peo00000n00000000000ԏW0~0Y00
 
                   *   < p > <h
}$P  -   
 
                   *   $PL0n u l l n0Bfo0000juS]0n00n0L0000k0<h
}U00f0D0~0Y0L00
 
                   *   n u l l NYn0Bfo0000k0<h
}U00f0D00n0o000000juSg0Y00
 
                   *   00000juSh0000juSn0Oo00NNn0_g0hU00~0Y00
 
                   *   000juSn , 00000juSi :   n = i n d e x t a b l e [ i ] 
 
                   *   < / p > 
 
                   *   @ r e t u r n 
 
                   *   00000P}gL000000000000cd04XT0]0n0MR0ԏW0~0Y00
 
                   *   c_0j0D04XT0n u l l 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   i n t [ ]   g e t I n d e x A r r a y ( ) 
 
                 { 
 
                         r e t u r n   t h i s . _ i s _ i n d e x _ t a b l e _ e n a b l e   ?   t h i s . _ i n d e x _ t a b l e   :   n u l l ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00000`1X0<h
}W0_000000000000ԏW0~0Y00
 
                   *   @ r e t u r n 
 
                   *   s(Wn0;uPk0[Y00000n00000
 
                   * / 
 
                 p u b l i c   N y A R L a b e l i n g L a b e l S t a c k   g e t L a b e l S t a c k ( ) 
 
                 { 
 
                         r e t u r n   t h i s . _ l a b e l _ l i s t ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00000000n0rKa00000W0~0Y00
 
                   *   0000_k0000000n00000000o0000U00~0Y0L00;uP`1Xo0*g[$Pk0j00~0Y00
 
                   *   @ p a r a m   i _ l a b e l _ i n d e x _ e n a b l e 
 
                   *   000$P0s(Wc[g0M00n0o00t r u e n00g0Y00
 
                   * / 
 
                 p u b l i c   v o i d   r e s e t ( b o o l   i _ l a b e l _ i n d e x _ e n a b l e ) 
 
                 { 
 
                         D e b u g . A s s e r t ( i _ l a b e l _ i n d e x _ e n a b l e   = =   t r u e ) ; / / ^000000o0*g[ň
 
                         t h i s . _ l a b e l _ l i s t . c l e a r ( ) ; 
 
                         t h i s . _ i s _ i n d e x _ t a b l e _ e n a b l e   =   i _ l a b e l _ i n d e x _ e n a b l e ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00i _ l a b e l n0000n00000WL0
Nk0cW0f0D00pn00x ^j0ԏW0~0Y00
 
                   *   N y A R T o o l k i t g0o00000n0*퐒00000Y00h0M0k00]0n0Yp0c"}Y00_00k0OD0~0Y00
 
                   *   @ p a r a m   i _ l a b e l 
 
                   *   c"}Y00000
 
                   *   @ r e t u r n 
 
                   *   000n0
N0000h0n0cph0j000x MOn
 
                   * / 
 
                 p u b l i c   i n t   g e t T o p C l i p T a n g e n t X ( N y A R L a b e l i n g L a b e l   i _ l a b e l ) 
 
                 { 
 
                         i n t   p i x ; 
 
                         i n t   i _ l a b e l _ i d   =   i _ l a b e l . i d ; 
 
                         i n t [ ]   i n d e x _ t a b l e   =   t h i s . _ i n d e x _ t a b l e ; 
 
                         i n t [ ]   l i m a g e   =   t h i s . _ b u f ; 
 
                         i n t   l i m a g e _ p t r   =   i _ l a b e l . c l i p _ t   *   t h i s . _ s i z e . w ; 
 
                         i n t   c l i p 1   =   i _ l a b e l . c l i p _ r ; 
 
                         / /   p 1 = S h o r t P o i n t e r . w r a p ( l i m a g e , j * x s i z e + c l i p . g e t ( ) ) ; / / p 1   = & ( l i m a g e [ j * x s i z e + c l i p [ 0 ] ] ) ; 
 
                         f o r   ( i n t   i   =   i _ l a b e l . c l i p _ l ;   i   < =   c l i p 1 ;   i + + ) 
 
                         { / /   f o r (   i   =   c l i p [ 0 ] ;   i   < = c l i p [ 1 ] ;   i + + ,   p 1 + +   )   { 
 
                                 p i x   =   l i m a g e [ l i m a g e _ p t r   +   i ] ; 
 
                                 i f   ( p i x   >   0   & &   i n d e x _ t a b l e [ p i x   -   1 ]   = =   i _ l a b e l _ i d ) 
 
                                 { 
 
                                         r e t u r n   i ; 
 
                                 } 
 
                         } 
 
                         / / B00d0K00j0D00
 
                         t h r o w   n e w   N y A R E x c e p t i o n ( ) ; 
 
                 } 
 
                 p u b l i c   o v e r r i d e   o b j e c t   c r e a t e I n t e r f a c e ( T y p e   i I i d ) 
 
                 { 
 
                         t h r o w   n e w   N y A R E x c e p t i o n ( ) ; 
 
                 } 
 
 
 
         } 
 
 } 
 
 