import Formatter from '../../util/Formatter' ; import Codeword from './Codeword' ; import BoundingBox from './BoundingBox' ; import { int } from '../../../customTypings' ; author Guenther Grau
  export default class DetectionResultColumn { private static MAX_NEARBY_DISTANCE : int = 5 ; private boundingBox : BoundingBox ; private codewords : Codeword [ ] ; constructor ( boundingBox ) { this . boundingBox = new BoundingBox ( boundingBox ) ; this . codewords = new Array < Codeword > ( boundingBox . getMaxY ( ) - boundingBox . getMinY ( ) + 1 ) ; } getCodewordNearby ( imageRow ) { let codeword = this . getCodeword ( imageRow ) ; if ( codeword != null ) { return codeword ; } for ( let i = 1 ; i < DetectionResultColumn . MAX_NEARBY_DISTANCE ; i ++ ) { let nearImageRow = this . imageRowToCodewordIndex ( imageRow ) - i ; if ( nearImageRow >= 0 ) { codeword = this . codewords [ nearImageRow ] ; if ( codeword != null ) { return codeword ; } } nearImageRow = this . imageRowToCodewordIndex ( imageRow ) + i ; if ( nearImageRow < this . codewords . length ) { codeword = this . codewords [ nearImageRow ] ; if ( codeword != null ) { return codeword ; } } } return null ; } imageRowToCodewordIndex ( imageRow ) { return imageRow - this . boundingBox . getMinY ( ) ; } setCodeword ( imageRow , codeword ) { this . codewords [ this . imageRowToCodewordIndex ( imageRow ) ] = codeword ; } getCodeword ( imageRow ) { return this . codewords [ this . imageRowToCodewordIndex ( imageRow ) ] ; } getBoundingBox ( ) { return this . boundingBox ; } getCodewords ( ) { return this . codewords ; } public toString ( ) { const formatter = new Formatter ( ) ; let row = 0 ; for ( const codeword of this . codewords ) { if ( codeword == null ) { formatter . format ( '%3d:    |   %n' , row ++ ) ; continue ; } formatter . format ( '%3d: %3d|%3d%n' , row ++ , codeword . getRowNumber ( ) , codeword . getValue ( ) ) ; } return formatter . toString ( ) ; } }