/ *   
 
   *   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[^j|0t`^j|x0	YcY000000g0Y00
 
           *   ^j|0	YcY000000h00	Yc_j0cOW0~0Y00
 
           * / 
 
         p u b l i c   c l a s s   N y A R O b s e r v 2 I d e a l M a p 
 
         { 
 
                 / * *   0000LS__00n0000pe* / 
 
                 p r o t e c t e d   i n t   _ s t r i d e ; 
 
                 / * *   X ^jn0	Yc0000* / 
 
                 p r o t e c t e d   d o u b l e [ ]   _ m a p x ; 
 
                 / * *   Y ^jn0	Yc0000* / 
 
                 p r o t e c t e d   d o u b l e [ ]   _ m a p y ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   eQRW0_0{ @ l i n k   N y A R C a m e r a D i s t o r t i o n F a c t o r } h0]0n0000K00000000\ObW0~0Y00
 
                   *   d0n000000o0teT'`L0S0f0D0j0Q00p0j00~0[000
 
                   *   ( 8^o00{ @ l i n k   N y A R P a r a m } n0{ @ l i n k   N y A R P a r a m # g e t D i s t o r t i o n F a c t o r ( ) } , { @ l i n k   N y A R P a r a m # g e t S c r e e n S i z e ( ) } K00_00_0
 
                   *   000000eQRW0~0Y00) 
 
                   *   @ p a r a m   i _ d i s t f a c t o r 
 
                   *   =jWjk000000n00000000
 
                   *   @ p a r a m   i _ s c r e e n _ s i z e 
 
                   *   00000000
 
                   * / 
 
                 p u b l i c   N y A R O b s e r v 2 I d e a l M a p ( I N y A R C a m e r a D i s t o r t i o n F a c t o r   i _ d i s t f a c t o r ,   N y A R I n t S i z e   i _ s c r e e n _ s i z e ) 
 
                 { 
 
                         N y A R D o u b l e P o i n t 2 d   o p o i n t   =   n e w   N y A R D o u b l e P o i n t 2 d ( ) ; 
 
                         t h i s . _ m a p x   =   n e w   d o u b l e [ i _ s c r e e n _ s i z e . w   *   i _ s c r e e n _ s i z e . h ] ; 
 
                         t h i s . _ m a p y   =   n e w   d o u b l e [ i _ s c r e e n _ s i z e . w   *   i _ s c r e e n _ s i z e . h ] ; 
 
                         t h i s . _ s t r i d e   =   i _ s c r e e n _ s i z e . w ; 
 
                         i n t   p t r   =   i _ s c r e e n _ s i z e . h   *   i _ s c r e e n _ s i z e . w   -   1 ; 
 
                         / / jk00000i{
 
                         f o r   ( i n t   i   =   i _ s c r e e n _ s i z e . h   -   1 ;   i   > =   0 ;   i - - ) 
 
                         { 
 
                                 f o r   ( i n t   i 2   =   i _ s c r e e n _ s i z e . w   -   1 ;   i 2   > =   0 ;   i 2 - - ) 
 
                                 { 
 
                                         i _ d i s t f a c t o r . o b s e r v 2 I d e a l ( i 2 ,   i ,   o p o i n t ) ; 
 
                                         t h i s . _ m a p x [ p t r ]   =   o p o i n t . x ; 
 
                                         t h i s . _ m a p y [ p t r ]   =   o p o i n t . y ; 
 
                                         p t r - - ; 
 
                                 } 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00[^j0t`^jx0	YcW0~0Y00
 
                   *   eQRg0M00$P{Vo000000000k0-[W0_000000000n0{VQg0Y00
 
                   *   @ p a r a m   i x 
 
                   *   [^jn0$P
 
                   *   @ p a r a m   i y 
 
                   *   [^jn0$P
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   t`^j0SQ0S00000000
 
                   * / 
 
                 p u b l i c   v o i d   o b s e r v 2 I d e a l ( i n t   i x ,   i n t   i y ,   N y A R I n t P o i n t 2 d   o _ p o i n t ) 
 
                 { 
 
                         i n t   i d x   =   i x   +   i y   *   t h i s . _ s t r i d e ; 
 
                         o _ p o i n t . x   =   ( i n t ) t h i s . _ m a p x [ i d x ] ; 
 
                         o _ p o i n t . y   =   ( i n t ) t h i s . _ m a p y [ i d x ] ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00[^j0t`^jx0	YcW0~0Y00
 
                   *   eQRg0M00$P{Vo000000000k0-[W0_000000000n0{VQg0Y00
 
                   *   @ p a r a m   i x 
 
                   *   [^jn0$P
 
                   *   @ p a r a m   i y 
 
                   *   [^jn0$P
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   t`^j0SQ0S00000000
 
                   * / 
 
                 p u b l i c   v o i d   o b s e r v 2 I d e a l ( i n t   i x ,   i n t   i y ,   N y A R D o u b l e P o i n t 2 d   o _ p o i n t ) 
 
                 { 
 
                         i n t   i d x   =   i x   +   i y   *   t h i s . _ s t r i d e ; 
 
                         o _ p o i n t . x   =   t h i s . _ m a p x [ i d x ] ; 
 
                         o _ p o i n t . y   =   t h i s . _ m a p y [ i d x ] ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00 NbW0f0[^j0t`^jx0	YcW0~0Y00
 
                   *   eQRg0M00$P{Vo000000000k0-[W0_000000000n0{VQg0Y00
 
                   *   @ p a r a m   i _ c o o r d 
 
                   *   [^jn0MR
 
                   *   @ p a r a m   i _ s t a r t 
 
                   *   	Yc[ak0Y00MRn0Y000000
 
                   *   @ p a r a m   i _ n u m 
 
                   *   	Yc[ak0Y00 }n0pe0
 
                   *   i _ s t a r t K000i _ s t a r t + i _ n u m - 1 ~0g0n0 }0	YcW0~0Y00
 
                   *   @ p a r a m   o _ x _ c o o r d 
 
                   *   	YcW0_0X ^j0SQ0S0MR0
 
                   *   @ p a r a m   o _ y _ c o o r d 
 
                   *   	YcW0_0Y ^j0SQ0S0MR0
 
                   *   @ p a r a m   i _ o u t _ s t a r t _ i n d e x 
 
                   *   QRHQMRn0Y000000c[W0_0MOnK00HQk0P}g0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   v o i d   o b s e r v 2 I d e a l B a t c h ( N y A R I n t P o i n t 2 d [ ]   i _ c o o r d ,   i n t   i _ s t a r t ,   i n t   i _ n u m ,   d o u b l e [ ]   o _ x _ c o o r d ,   d o u b l e [ ]   o _ y _ c o o r d ,   i n t   i _ o u t _ s t a r t _ i n d e x ) 
 
                 { 
 
                         i n t   i d x ; 
 
                         i n t   p t r   =   i _ o u t _ s t a r t _ i n d e x ; 
 
                         d o u b l e [ ]   m a p x   =   t h i s . _ m a p x ; 
 
                         d o u b l e [ ]   m a p y   =   t h i s . _ m a p y ; 
 
                         i n t   s t r i d e   =   t h i s . _ s t r i d e ; 
 
                         f o r   ( i n t   j   =   0 ;   j   <   i _ n u m ;   j + + ) 
 
                         { 
 
                                 i d x   =   i _ c o o r d [ i _ s t a r t   +   j ] . x   +   i _ c o o r d [ i _ s t a r t   +   j ] . y   *   s t r i d e ; 
 
                                 o _ x _ c o o r d [ p t r ]   =   m a p x [ i d x ] ; 
 
                                 o _ y _ c o o r d [ p t r ]   =   m a p y [ i d x ] ; 
 
                                 p t r + + ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
         } 
 
 } 
 
 