/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S ( E x t e n s i o n ) 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h e   N y A R T o o l k i t C S   i s   C #   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 ; 
 
 u s i n g   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 ; 
 
 u s i n g   j p . n y a t l a . n y a r t o o l k i t . c s . n y i d m a r k e r ; 
 
 
 
 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 . r p f 
 
 { 
 
         / * * 
 
           *   !|fj0TgWN y I d 000I D 0000g0Y00
 
           *   S0n0000o00R a w B i t 0000000000n0N y I d 000n0I d h00000000000000[W0~0Y00
 
           *   S e r i a l I D o00R a w B i t 000n0000000000[ 0 ] [ 1 ] . . . [ n ] n0k0&Ny0f006 4 b i t n0tepe$Pk0	YcW0_0$Pg0Y00
 
           *   $R%Rg0M00I d 000o00d o m a i n = 0 ( r a w b i t ) , m o d e l & l t ; 5 , m a s k = 0 n00n0n00g0Y00
 
           *   < p > 
 
           *   S0n0000o00N y R e a l i t y T a r g e t 0R a w B i t 0000000000n0S e r i a l N u m b e r 000k000000Y00
 
           *   _j0cOW0~0Y00
 
           *   OD0eo00000o00S0n0000k0I D 000n0S e r i a l N u m b e r h0]0n00000{v2W0~0Y00]0n0_k00
 
           *   N y R e a l i t y T a r g e t 000k00{v2W0_0000K00]0n0S e r i a l N u m b e r 00000_0S0h0L0g0M0~0Y00
 
           *   < / p > 
 
           *   
 
           *   N y I d R a w B i t S e r i a l N u m b e r T a b l e 
 
           * / 
 
         p u b l i c   c l a s s   R a w b i t S e r i a l I d T a b l e 
 
         { 
 
 	         / * * 
 
 	           *   s e l e c t T a r g e t pen0;b0$P0<h
}W0~0Y00
 
 	           *   eQ0P[000n0\O0j0D0Qt|g0o00R a w b i t S e r i a l I d T a b l e _ I d e n t i f y I d R e s u l t h0W0f0[ W0f0O0`0U0D00
 
 	           * / 
 
 	         p u b l i c   c l a s s   I d e n t i f y I d R e s u l t 
 
 	         { 
 
 	 	         / * *   I D juSg0Y00* / 
 
 	 	         p u b l i c   l o n g   i d ; 
 
 	 	         / * *   
TMRg0Y00* / 
 
 	 	         p u b l i c   S t r i n g   n a m e ; 
 
 	 	         / * *   {v2Bfk0-[W0_0000000g0Y00* / 
 
 	 	         p u b l i c   d o u b l e   m a r k e r _ w i d t h ; 
 
 	 	         / * *   A R T o o l K i t nbn00000n0eMO$Pg0Y00* / 
 
 	 	         p u b l i c   i n t   a r t k _ d i r e c t i o n ; 
 
 	         } 
 
         	 
 
 
 
 	         p r i v a t e   c l a s s   S e r i a l T a b l e   :   N y A R O b j e c t S t a c k < S e r i a l T a b l e . S e r i a l T a b l e R o w > 
 
 	         { 
 
 	 	         p u b l i c   c l a s s   S e r i a l T a b l e R o w 
 
 	 	         { 
 
 	 	 	         p u b l i c   l o n g   i d _ s t ; 
 
 	 	 	         p u b l i c   l o n g   i d _ e d ; 
 
 	 	 	         p u b l i c   d o u b l e   m a r k e r _ w i d t h ; 
 
 	 	 	         p u b l i c   S t r i n g   n a m e ; 
 
 	 	 	         p u b l i c   v o i d   s e t V a l u e ( S t r i n g   i _ n a m e , l o n g   i _ s t , l o n g   i _ e d , d o u b l e   i _ w i d t h ) 
 
 	 	 	         { 
 
 	 	 	 	         t h i s . i d _ e d = i _ e d ; 
 
 	 	 	 	         t h i s . i d _ s t = i _ s t ; 
 
 	 	 	 	         t h i s . m a r k e r _ w i d t h = i _ w i d t h ; 
 
 	 	 	 	         t h i s . n a m e = i _ n a m e ; 
 
 	 	 	         } 
 
 	 	         } 	 	 
 
 	 	         p u b l i c   S e r i a l T a b l e ( i n t   i _ l e n g t h ) 
 
 	 	         { 
 
 	 	 	         b a s e . i n i t I n s t a n c e ( i _ l e n g t h ) ; 
 
 	 	         } 
 
 	 	         p r o t e c t e d   o v e r r i d e   S e r i a l T a b l e R o w   c r e a t e E l e m e n t ( ) 
 
 	 	         { 
 
 	 	 	         r e t u r n   n e w   S e r i a l T a b l e R o w ( ) ; 
 
 	 	         } 
 
 	 	         p u b l i c   S e r i a l T a b l e R o w   g e t I t e m b y S e r i a l I d ( l o n g   i _ s e r i a l ) 
 
 	 	         { 
 
 	 	 	         f o r ( i n t   i = t h i s . _ l e n g t h - 1 ; i > = 0 ; i - - ) 
 
 	 	 	         { 
 
 	 	 	 	         S e r i a l T a b l e R o w   s = t h i s . _ i t e m s [ i ] ; 
 
 	 	 	 	         i f ( i _ s e r i a l < s . i d _ s t   | |   i _ s e r i a l > s . i d _ e d ) { 
 
 	 	 	 	 	         c o n t i n u e ; 
 
 	 	 	 	         } 
 
 	 	 	 	         r e t u r n   s ; 
 
 	 	 	         } 
 
 	 	 	         r e t u r n   n u l l ; 
 
 	 	         } 
 
 	         } 
 
 
 
 	         p r i v a t e   S e r i a l T a b l e   _ t a b l e ; 
 
 	         p r i v a t e   r e a d o n l y   N y I d M a r k e r P i c k u p   _ i d _ p i c k u p ; 
 
 	         p r i v a t e   N y I d M a r k e r P a t t e r n   _ t e m p _ n y i d _ i n f o = n e w   N y I d M a r k e r P a t t e r n ( ) ; 
 
 	         p r i v a t e   N y I d M a r k e r P a r a m   _ t e m p _ n y i d _ p a r a m = n e w   N y I d M a r k e r P a r a m ( ) ; 
 
         	 
 
 	         p r i v a t e   N y I d M a r k e r D a t a E n c o d e r _ R a w B i t I d   _ r b = n e w   N y I d M a r k e r D a t a E n c o d e r _ R a w B i t I d ( ) ; 
 
 	         p r i v a t e   N y I d M a r k e r D a t a _ R a w B i t I d   _ r b _ d e s t = n e w   N y I d M a r k e r D a t a _ R a w B i t I d ( ) ; 
 
 
 
 
 
 	         / * * 
 
 	           *   0000000g0Y00
 
 	           *   @ p a r a m   i _ m a x 
 
 	           *   {v2Y000000n0 g'Ypeg0Y00
 
 	           *   @ t h r o w s   N y A R E x c e p t i o n   
 
 	           * / 
 
 	         p u b l i c   R a w b i t S e r i a l I d T a b l e ( i n t   i _ m a x ) 
 
 	         { 
 
                         t h i s . _ i d _ p i c k u p   =   n e w   N y I d M a r k e r P i c k u p ( ) ; 
 
 	 	         t h i s . _ t a b l e = n e w   S e r i a l T a b l e ( i _ m a x ) ; 
 
 	         } 
 
 	         / * * 
 
 	           *   I D n0{Vk0[Y0000000000000000k0RW0~0Y00
 
 	           *   S0n0 }k0000Y00{Vo0, i _ s t & l t ; = n & l t ; = i _ e d k0j00~0Y00
 
 	           *   @ p a r a m   i _ n a m e 
 
 	           *   S0n0I D {Vn0
TMR0c[W0~0Y00
Nj04XTo0n u l l 0c[W0~0Y00
 
 	           *   @ p a r a m   i _ s t 
 
 	           *   000{Vn0Y$Pg0Y00
 
 	           *   @ p a r a m   i _ e d 
 
 	           *   000{Vn0B}N$Pg0Y00
 
 	           *   @ p a r a m  0i _ w i d t h 
 
 	           *   000W0_0000n0000$P0c[W0~0Y00
 
 	           * / 
 
                 p u b l i c   b o o l   a d d S e r i a l I d R a n g e I t e m ( S t r i n g   i _ n a m e ,   l o n g   i _ s t ,   l o n g   i _ e d ,   d o u b l e   i _ w i d t h ) 
 
 	         { 
 
 	 	         S e r i a l T a b l e . S e r i a l T a b l e R o w   d = t h i s . _ t a b l e . p r e P u s h ( ) ; 
 
 	 	         i f ( d = = n u l l ) { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         d . s e t V a l u e ( i _ n a m e , i _ s t , i _ e d , i _ w i d t h ) ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
 	         / * * 
 
 	           *   S e r i a l I D k0[Y0000000000000000k0RW0~0Y00
 
 	           *   @ p a r a m   i _ s e r i a l 
 
 	           *   000U0[000000i d g0Y00
 
 	           *   @ p a r a m   i _ w i d t h 
 
 	           *   000W0_0000n0000$Pg0Y00
 
 	           *   @ r e t u r n 
 
 	           *   {v2k0bRY00h0t r u e 0ԏW0~0Y00
 
 	           * / 
 
                 p u b l i c   b o o l   a d d S e r i a l I d I t e m ( S t r i n g   i _ n a m e ,   l o n g   i _ s e r i a l ,   d o u b l e   i _ w i d t h ) 
 
 	         { 
 
 	 	         S e r i a l T a b l e . S e r i a l T a b l e R o w   d = t h i s . _ t a b l e . p r e P u s h ( ) ; 
 
 	 	         i f ( d = = n u l l ) { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         d . s e t V a l u e ( i _ n a m e , i _ s e r i a l , i _ s e r i a l , i _ w i d t h ) ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
 	         / * * 
 
 	           *   hQf0n0S e r i a l I D k0000Y0000000000000000k0RW0~0Y00
 
 	           *   @ p a r a m   i _ w i d t h 
 
 	           *   000W0_0000n0000$Pg0Y00
 
 	           *   @ r e t u r n 
 
 	           *   {v2k0bRY00h0t r u e g0Y00
 
 	           * / 
 
                 p u b l i c   b o o l   a d d A n y I t e m ( S t r i n g   i _ n a m e ,   d o u b l e   i _ w i d t h ) 
 
 	         { 
 
 	 	         S e r i a l T a b l e . S e r i a l T a b l e R o w   d = t h i s . _ t a b l e . p r e P u s h ( ) ; 
 
 	 	         i f ( d = = n u l l ) { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         d . s e t V a l u e ( i _ n a m e , 0 , l o n g . M a x V a l u e , i _ w i d t h ) ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
                 p r i v a t e   I N y A R R a s t e r   _ l a s t _ l a s t e r   =   n u l l ; 
 
                 p r i v a t e   I N y A R G s P i x e l D r i v e r   _ g s _ p i x _ r e a d e r ; 
 
 	 
 
 	         / * * 
 
 	           *   i _ r a s t e r 
Nk0B00i _ v e r t e x n0pg0[U000V҉b_n00000K000 NY00I D $P0yr[W0~0Y00
 
 	           *   @ p a r a m   i _ v e r t e x 
 
 	           *   4 pn0^j
 
 	           *   @ p a r a m   i _ r a s t e r 
 
 	           *   @ p a r a m   o _ r e s u l t 
 
 	           *   @ r e t u r n 
 
 	           *   @ t h r o w s   N y A R E x c e p t i o n 
 
 	           * / 
 
 	         p u b l i c   b o o l   i d e n t i f y I d ( N y A R D o u b l e P o i n t 2 d [ ]   i _ v e r t e x , I N y A R R g b R a s t e r   i _ r a s t e r , I d e n t i f y I d R e s u l t   o _ r e s u l t ) 
 
 	         { 
 
                         i f   ( t h i s . _ l a s t _ l a s t e r   ! =   i _ r a s t e r ) 
 
                         { 
 
                                 t h i s . _ g s _ p i x _ r e a d e r   =   N y A R G s P i x e l D r i v e r F a c t o r y . c r e a t e D r i v e r ( i _ r a s t e r ) ; 
 
                                 t h i s . _ l a s t _ l a s t e r   =   i _ r a s t e r ; 
 
                         } 
 
                         i f   ( ! t h i s . _ i d _ p i c k u p . p i c k F r o m R a s t e r ( t h i s . _ g s _ p i x _ r e a d e r ,   i _ v e r t e x ,   t h i s . _ t e m p _ n y i d _ i n f o ,   t h i s . _ t e m p _ n y i d _ p a r a m ) ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         i f   ( ! t h i s . _ r b . e n c o d e ( t h i s . _ t e m p _ n y i d _ i n f o ,   t h i s . _ r b _ d e s t ) ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         / / S e r i a l I D _M0Y000
 
                         S e r i a l T a b l e . S e r i a l T a b l e R o w   d   =   t h i s . _ t a b l e . g e t I t e m b y S e r i a l I d ( t h i s . _ r b _ d e s t . m a r k e r _ i d ) ; 
 
                         i f   ( d   = =   n u l l ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         / / ;b0$P0-[
 
                         o _ r e s u l t . m a r k e r _ w i d t h   =   d . m a r k e r _ w i d t h ; 
 
                         o _ r e s u l t . i d   =   t h i s . _ r b _ d e s t . m a r k e r _ i d ; 
 
                         o _ r e s u l t . a r t k _ d i r e c t i o n   =   t h i s . _ t e m p _ n y i d _ p a r a m . d i r e c t i o n ; 
 
                         o _ r e s u l t . n a m e   =   d . n a m e ; 
 
                         r e t u r n   t r u e ; 	 
 
 	         } 
 
 	         / * * 
 
 	           *   R e a l i t y T a r g e t k0 NY00I D $P0yr[W0~0Y00
 
 	           *   pen00000k0000W0_0h0M0o00 NjuR0k0000W0_0v0ԏW0~0Y00
 
 	           *   @ p a r a m   i _ t a r g e t 
 
 	           *   R e a l i t y L0iQW0_0000000
 
 	           *   U n k n o w n 000000c[Y00S0h00
 
 	           *   @ p a r a m   i _ r t s o r c e 
 
 	           *   i _ t a r g e t 0iQW0_0R e a l i t y S o u r c e 0000000
 
 	           *   @ p a r a m   o _ r e s u l t 
 
 	           *   ԏtS$P0<h
}Y000000000-[W0~0Y00
 
 	           *   ԏtS$PL0t r u e n04XTn000Q[L0feU00f0D0~0Y00
 
 	           *   @ r e t u r n 
 
 	           *   yr[k0bRY00h00t r u e 0ԏW0~0Y00
 
 	           *   @ t h r o w s   N y A R E x c e p t i o n   
 
 	           * / 
 
 	         p u b l i c   b o o l   i d e n t i f y I d ( N y A R R e a l i t y T a r g e t   i _ t a r g e t , N y A R R e a l i t y S o u r c e   i _ r t s o r c e , I d e n t i f y I d R e s u l t   o _ r e s u l t ) 
 
 	         { 
 
 	 	         / / N y A R D o u b l e P o i n t 2 d [ ]   i _ v e r t e x , N y A R R g b R a s t e r   i _ r a s t e r , S e l e c t R e s u l t   o _ r e s u l t 
 
 	 	         r e t u r n   t h i s . i d e n t i f y I d ( 
 
 	 	 	         ( ( N y A R R e c t T a r g e t S t a t u s ) ( i _ t a r g e t . _ r e f _ t r a c k t a r g e t . _ r e f _ s t a t u s ) ) . v e r t e x , 
 
 	 	 	         i _ r t s o r c e . r e f R g b S o u r c e ( ) , 
 
 	 	 	         o _ r e s u l t ) ; 
 
 	         } 
 
 	         / / c[W0_0I D h00000L0 NY00K0xY00A P I 0(uaY00K0
 
         } 
 
 } 