bool tAoi::overlap( tAoi const& area_ )const { int s0 = area(); int s1 = area_.area(); if( s0 > s1 ) { int xend = area_.px() + area_.sx(); int yend = area_.py() + area_.sy(); for( int y = area_.py(); y < yend; y++ ) { for( int x = area_.px(); x < xend; x++ ) { if( inside( int32_xy( x, y ) ) != false ) { return true; } } } } else { int xend = px() + sx(); int yend = py() + sy(); for( int y = py(); y < yend; y++ ) { for( int x = px(); x < xend; x++ ) { if( area_.inside( int32_xy( x, y ) ) != false ) { return true; } } } } return false; }
void tBlob::calculateMidpnt() { calculateSize(); double mx = _min.x() + _max.x(); uint32_t xmid = roundToInt( mx / 2.0 ); double my = ( _min.y() + _max.y() ); uint32_t ymid = roundToInt( my / 2.0 ); _midpoint = int32_xy( xmid, ymid ); }
void tBlob::calculateSize() { struct csize { int32_t xmin; int32_t xmax; int32_t ymin; int32_t ymax; csize(): xmin( INT32_MAX ), xmax( 0 ), ymin( INT32_MAX ), ymax( 0 ) {} void operator()( tStreak const& s ) { int32_t lxmin = s.x(); int32_t lxmax = s.last(); if( lxmax > xmax ) { xmax = lxmax; } if( lxmin < xmin ) { xmin = lxmin; } // y int32_t y = s.y(); if( y > ymax ) { ymax = y ; } if( y < ymin ) { ymin = y ; } } }; csize const& s = for_each( _streaks.begin(), _streaks.end(), csize() ); _min = int32_xy( s.xmin, s.ymin ); _max = int32_xy( s.xmax, s.ymax ); }
bool rimginterface::Insert( const tImgViewPlanar& aoi, tImgPlanar& target, int32_xy xy ) { assert( target.equals_size_mask( aoi ) ); // test if target position is in img if( xy.x() > static_cast<int>(target.sx()) - 1 || xy.y() > static_cast<int>(target.sy()) - 1 ) { return false; } uint32_xy xxyy( xy.x(), xy.y() ); uint32_xy aoi_ = aoi.size(); uint32_xy result = aoi_ + xxyy; int32_xy aoimax = int32_xy( result.x(), result.y() ); if( aoimax.x() <= 0 && aoimax.y() <= 0 ) { return false; } if( aoimax.x() > static_cast<int>(target.sx()) && aoimax.y() > static_cast<int>(target.sy()) ) { return false; } uint32_xy saoi = aoi.size(); uint32_xy so = target.size(); auto maoibegin = aoi.begin(); auto maoiend = aoi.end(); auto out = target.begin(); uint32_xy size( aoi.size() ); while( maoibegin != maoiend ) { insert::Insert( maoibegin->plane, out->plane, xy, size ); ++maoibegin; ++out; } return true; }
tAoi::tAoi( int32_t ix, int32_t iy, uint32_t sx_, uint32_t sy_ ):_pos(), _size( ) { _pos = int32_xy( ix, iy ); _size = uint32_xy( sx_, sy_ ); }
int32_xy tAoi::lower_left() const { return int32_xy( _pos.x(), _pos.y() + _size.y() - 1 ); }
int32_xy tAoi::upper_right() const { return int32_xy( _pos.x() + _size.x() - 1, _pos.y() ); }