/ *   
 
   *   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   S y s t e m . I O ; 
 
 
 
 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 
 
 { 
 
 
 
         / * * 
 
           *   !|fj0A R T o o l K i t 00000000g0Y00
 
           *   S0n0000o00A R T o o l K i t 0000n000000000h0I d h00000000000000[W0~0Y00
 
           * / 
 
         p u b l i c   c l a s s   A R T K M a r k e r 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0A R T K M a r k e r T a b l e _ G e t B e s t M a t c h T a r g e t R e s u l t h0W0f0[ W0f0O0`0U0D00
 
 	           * / 
 
 	         p u b l i c   c l a s s   G e t B e s t M a t c h T a r g e t R e s u l t 
 
 	         { 
 
 	 	         / * *   {v2Bfk0-[W0_0I D g0Y00* / 
 
 	 	         p u b l i c   i n t   i d t a g ; 
 
 	 	         / * *   {v2Bfk0-[W0_0
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 ; 
 
 	 	         / * *   {v2Bfk0-[W0_0000000g0Y00* / 
 
 	 	         p u b l i c   d o u b l e   m a r k e r _ h e i g h t ; 
 
 	 	         / * *   A R T o o l K i t nbn00000n0eMO$P* / 
 
 	 	         p u b l i c   i n t   a r t k _ d i r e c t i o n ; 
 
 	 	         / * *    Ns* / 
 
 	 	         p u b l i c   d o u b l e   c o n f i d e n c e ; 
 
 	         } 
 
         	 
 
 
 
 	         p r i v a t e   c l a s s   M a r k e r T a b l e   :   N y A R O b j e c t S t a c k < M a r k e r 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   i n t   i d t a g ; 
 
 	 	 	         p u b l i c   S t r i n g   n a m e ; 
 
 	 	 	         p u b l i c   N y A R C o d e   c o d e ; 
 
 	 	 	         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   d o u b l e   m a r k e r _ h e i g h t ; 
 
 	 	 	         p u b l i c   v o i d   s e t V a l u e ( N y A R C o d e   i _ c o d e , i n t   i _ i d t a g , S t r i n g   i _ n a m e , d o u b l e   i _ w i d t h , d o u b l e   i _ h e i g h t ) 
 
 	 	 	         { 
 
 	 	 	 	         t h i s . c o d e = i _ c o d e ; 
 
 	 	 	 	         t h i s . m a r k e r _ h e i g h t = i _ h e i g h 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 ; 
 
 	 	 	 	         t h i s . i d t a g = i _ i d t a g ; 
 
 	 	 	         } 
 
 	 	         } 	 	 
 
 	 	         p u b l i c   M a r k e r 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 r i v a t e   i n t   _ r e s o l u t i o n _ w i d t h ; 
 
 	         p r i v a t e   i n t   _ r e s o l u t i o n _ h e i g h t ; 
 
 	         p r i v a t e   i n t   _ e d g e _ x ; 
 
 	         p r i v a t e   i n t   _ e d g e _ y ; 
 
 	         p r i v a t e   i n t   _ s a m p l e _ p e r _ p i x ; 
 
 	         p r i v a t e   N y A R R g b R a s t e r   _ t m p _ r a s t e r ; 
 
 	         p r i v a t e   N y A R M a t c h P a t t _ C o l o r _ W I T H O U T _ P C A   _ m a t c h _ p a t t ; 
 
 	         p r i v a t e   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a   _ d e v i a t i o n _ d a t a ; 
 
 	         p r i v a t e   M a r k e r T a b l e   _ t a b l e ; 
 
 	         / * * 
 
 	           *   0000000g0Y00
 
 	           *   @ p a r a m   i _ m a x 
 
 	           *   {v2Y000000n0 g'Ypeg0Y00
 
 	           *   @ p a r a m   i _ r e s o l u t i o n _ x 
 
 	           *   {v2Y000000n0P^g0Y00
 
 	           *   A R T o o l K i t Ncn0jn$Po01 6 g0Y00
 
 	           *   @ p a r a m   i _ r e s o l u t i o n _ y 
 
 	           *   {v2Y000000n0P^g0Y00
 
 	           *   A R T o o l K i t Ncn0jn$Po01 6 g0Y00
 
 	           *   @ p a r a m   i _ e d g e _ x 
 
 	           *   000Rn0rRTg0Y00A R T o o l K i t Ncn0jn$Po02 5 g0Y00
 
 	           *   @ p a r a m   i _ e d g e _ y 
 
 	           *   000Rn0rRTg0Y00A R T o o l K i t Ncn0jn$Po02 5 g0Y00
 
 	           *   @ p a r a m   i _ s a m p l e _ p e r _ p i x 
 
 	           *   0000S_n01 0000B0_00n0000000peg0Y001 j001 P i x e l = 1 , 2 j001 P i x e l = 4 n00000000W0~0Y00
 
 	           *   A R T o o l K i t Ncn0jn$Po04 g0Y00
 
 	           *   ؚP^( 6 4 N
N) n000000(uD00h0M0o00000000pe0NOO0-[W0f0O0`0U0D0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   A R T K M a r k e r T a b l e ( i n t   i _ m a x , i n t   i _ r e s o l u t i o n _ x , i n t   i _ r e s o l u t i o n _ y , i n t   i _ e d g e _ x , i n t   i _ e d g e _ y , i n t   i _ s a m p l e _ p e r _ p i x ) 
 
 	         { 
 
 	 	         t h i s . _ r e s o l u t i o n _ w i d t h = i _ r e s o l u t i o n _ x ; 
 
 	 	         t h i s . _ r e s o l u t i o n _ h e i g h t = i _ r e s o l u t i o n _ y ; 
 
 	 	         t h i s . _ e d g e _ x = i _ e d g e _ x ; 
 
 	 	         t h i s . _ e d g e _ y = i _ e d g e _ y ; 
 
 	 	         t h i s . _ s a m p l e _ p e r _ p i x = i _ s a m p l e _ p e r _ p i x ; 
 
 	 	         t h i s . _ t m p _ r a s t e r = n e w   N y A R R g b R a s t e r ( i _ r e s o l u t i o n _ x , i _ r e s o l u t i o n _ y , N y A R B u f f e r T y p e . I N T 1 D _ X 8 R 8 G 8 B 8 _ 3 2 ) ; 
 
 	 	         t h i s . _ t a b l e = n e w   M a r k e r T a b l e ( i _ m a x ) ; 
 
 	 	         t h i s . _ d e v i a t i o n _ d a t a = n e w   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a ( i _ r e s o l u t i o n _ x , i _ r e s o l u t i o n _ y ) ; 	 	 
 
 	 	         t h i s . _ m a t c h _ p a t t = n e w   N y A R M a t c h P a t t _ C o l o r _ W I T H O U T _ P C A ( i _ r e s o l u t i o n _ x , i _ r e s o l u t i o n _ y ) ; 
 
 	         } 
 
 	         / * * 
 
 	           *   A R T K 0000000000000k0RW0~0Y00S0n00000000n000000h0W0f00I D h0
TMR0c[g0M0~0Y00
 
 	           *   @ p a r a m   i _ c o d e 
 
 	           *   A R T o o l K i t b__n000000000<h
}W0_00000000S0n0000000o00pebR_o0000000k0@b	gU00~0Y00
 
 	           *   0000000n0P^o000000000k0c[W0_0ؚU0h0E^g0B00_L0B00~0Y00
 
 	           *   @ p a r a m   i _ i d 
 
 	           *   S0n00000X%RY00000[n0I D $Pg0Y00Nan0$P0c[g0M0~0Y00
Nj04XTo00 0c[W0f0O0`0U0D00
 
 	           *   @ p a r a m   i _ n a m e 
 
 	           *   000[n0
TMRg0Y00Nan0$P0c[g0M0~0Y00
Nj04XTo0n u l l 0c[W0f0NU0D00
 
 	           *   @ p a r a m   i _ w i d t h 
 
 	           *   000n0ؚU0[ 8^m m XSMO] 
 
 	           *   @ p a r a m   i _ h e i g h t 
 
 	           *   000n0E^[ 8^m m XSMO] 
 
 	           *   @ r e t u r n 
 
 	           * / 
 
                 p u b l i c   b o o l   a d d M a r k e r ( N y A R C o d e   i _ c o d e ,   i n t   i _ i d ,   S t r i n g   i _ n a m e ,   d o u b l e   i _ w i d t h ,   d o u b l e   i _ h e i g h t ) 
 
 	         { 
 
 	 	         D e b u g . A s s e r t ( i _ c o d e . g e t H e i g h t ( ) = =   t h i s . _ r e s o l u t i o n _ h e i g h t   & &   i _ c o d e . g e t H e i g h t ( ) = =   t h i s . _ r e s o l u t i o n _ w i d t h ) ; 
 
 	 	         M a r k e r 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 _ c o d e , i _ i d , i _ n a m e , i _ w i d t h , i _ h e i g h t ) ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
 	         / * * 
 
 	           *   i _ r a s t e r K0000000000ubW0f000000x0RW0~0Y00
 
 	           *   @ p a r a m   i _ r a s t e r 
 
 	           *   @ p a r a m   i _ i d 
 
 	           *   S0n00000X%RY00000[n0I D $Pg0Y00Nan0$P0c[g0M0~0Y00
Nj04XTo00 0c[W0f0O0`0U0D00
 
 	           *   @ p a r a m   i _ n a m e 
 
 	           *   000[n0
TMRg0Y00Nan0$P0c[g0M0~0Y00
Nj04XTo0n u l l 0c[W0f0NU0D00
 
 	           *   @ p a r a m   i _ w i d t h 
 
 	           *   000n0ؚU0[ 8^m m XSMO] 
 
 	           *   @ p a r a m   i _ h e i g h t 
 
 	           *   000n0E^[ 8^m m XSMO] 
 
 	           *   @ 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   a d d M a r k e r ( N y A R R g b R a s t e r   i _ r a s t e r ,   i n t   i _ i d ,   S t r i n g   i _ n a m e ,   d o u b l e   i _ w i d t h ,   d o u b l e   i _ h e i g h t ) 
 
 	         { 
 
 	 	         M a r k e r 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 ; 
 
 	 	         } 
 
                         N y A R C o d e   c   =   n e w   N y A R C o d e ( t h i s . _ r e s o l u t i o n _ w i d t h ,   t h i s . _ r e s o l u t i o n _ h e i g h t ) ; 
 
 	 	         c . s e t R a s t e r ( i _ r a s t e r ) ; 
 
 	 	         d . s e t V a l u e ( c , i _ i d , i _ n a m e , i _ w i d t h , i _ h e i g h t ) ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
 	         / * * 
 
 	           *   A R T o o l k i t nbn000000000K0000000000ubW0f000000x0RW0~0Y00
 
 	           *   @ p a r a m   i _ f i l e n a m e 
 
 	           *   @ p a r a m   i _ i d 
 
 	           *   S0n00000X%RY00000[n0I D $Pg0Y00Nan0$P0c[g0M0~0Y00
Nj04XTo00 0c[W0f0O0`0U0D00
 
 	           *   @ p a r a m   i _ n a m e 
 
 	           *   000[n0
TMRg0Y00Nan0$P0c[g0M0~0Y00
Nj04XTo0n u l l 0c[W0f0NU0D00
 
 	           *   @ p a r a m   i _ w i d t h 
 
 	           *   000n0ؚU0[ 8^m m XSMO] 
 
 	           *   @ p a r a m   i _ h e i g h t 
 
 	           *   000n0E^[ 8^m m XSMO] 
 
 	           *   @ 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   a d d M a r k e r F r o m A R P a t t ( S t r e a m R e a d e r   i _ s t r e a m , i n t   i _ i d , S t r i n g   i _ n a m e , d o u b l e   i _ w i d t h , d o u b l e   i _ h e i g h t ) 
 
 	         { 
 
 	 	         M a r k e r 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 ; 
 
 	 	         } 
 
                         N y A R C o d e   c   =   N y A R C o d e . c r e a t e F r o m A R P a t t F i l e ( i _ s t r e a m ,   t h i s . _ r e s o l u t i o n _ w i d t h ,   t h i s . _ r e s o l u t i o n _ h e i g h t ) ; 
 
 	 	         d . s e t V a l u e ( c , i _ i d , i _ n a m e , i _ w i d t h , i _ h e i g h t ) ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 	 
 
         	 
 
 	         p r i v a t e   N y A R M a t c h P a t t R e s u l t   _ _ t m p _ p a t t _ r e s u l t = n e w   N y A R M a t c h P a t t R e s u l t ( ) ; 
 
 	         / * * 
 
 	           *   R e a l i t y T a r g e t k0 g0 NY00000000000K00i"}W0f00000000ԏ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   g e t B e s t M a t c h T a r g e t ( 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 ,   G e t B e s t M a t c h T a r g e t R e s u l t   o _ r e s u l t ) 
 
 	         { 
 
 	 	         / / 0000bQ
 
 	 	         N y A R M a t c h P a t t R e s u l t   t m p _ p a t t _ r e s u l t = t h i s . _ _ t m p _ p a t t _ r e s u l t ; 
 
                         I N y A R P e r s p e c t i v e C o p y   r   =   i _ r t s o r c e . r e f P e r s p e c t i v e R a s t e r R e a d e r ( ) ; 
 
                         r . c o p y P a t t ( i _ t a r g e t . r e f T a r g e t V e r t e x ( ) ,   t h i s . _ e d g e _ x ,   t h i s . _ e d g e _ y ,   t h i s . _ s a m p l e _ p e r _ p i x ,   t h i s . _ t m p _ r a s t e r ) ; 
 
                         / / k0000ub
 
 	 	         t h i s . _ d e v i a t i o n _ d a t a . s e t R a s t e r ( t h i s . _ t m p _ r a s t e r ) ; 
 
 	 	         i n t   r e t = - 1 ; 
 
 	 	         i n t   d i r = - 1 ; 
 
 	 	         d o u b l e   c f = D o u b l e . M i n V a l u e ; 
 
 	 	         f o r ( i n t   i = t h i s . _ t a b l e . g e t L e n g t h ( ) - 1 ; i > = 0 ; i - - ) { 
 
 	 	 	         t h i s . _ m a t c h _ p a t t . s e t A R C o d e ( t h i s . _ t a b l e . g e t I t e m ( i ) . c o d e ) ; 
 
 	 	 	         t h i s . _ m a t c h _ p a t t . e v a l u a t e ( t h i s . _ d e v i a t i o n _ d a t a ,   t m p _ p a t t _ r e s u l t ) ; 
 
 	 	 	         i f ( c f < t m p _ p a t t _ r e s u l t . c o n f i d e n c e ) { 
 
 	 	 	 	         r e t = i ; 
 
 	 	 	 	         c f = t m p _ p a t t _ r e s u l t . c o n f i d e n c e ; 
 
 	 	 	 	         d i r = t m p _ p a t t _ r e s u l t . d i r e c t i o n ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         i f ( r e t < 0 ) { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         / / ;b0$P0-[
 
 	 	         M a r k e r T a b l e . S e r i a l T a b l e R o w   r o w = t h i s . _ t a b l e . g e t I t e m ( r e t ) ; 
 
 	 	         o _ r e s u l t . a r t k _ d i r e c t i o n = d i r ; 
 
 	 	         o _ r e s u l t . c o n f i d e n c e = c f ; 
 
 	 	         o _ r e s u l t . i d t a g = r o w . i d t a g ; 
 
 	 	         o _ r e s u l t . m a r k e r _ h e i g h t = r o w . m a r k e r _ h e i g h t ; 
 
 	 	         o _ r e s u l t . m a r k e r _ w i d t h = r o w . m a r k e r _ w i d t h ; 
 
 	 	         o _ r e s u l t . n a m e = r o w . n a m e ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
         } 
 
 } 