| 55 | } |
| 56 | |
| 57 | Imath::Box2i LensModel::bounds( int mode, const Imath::Box2i &input, int width, int height ) |
| 58 | { |
| 59 | Imath::Box2i out( input ); |
| 60 | bool init( false ); |
| 61 | |
| 62 | for( int i = input.min.x; i <= input.max.x; ++i ) |
| 63 | { |
| 64 | for( int pass = 0; pass < 2; ++pass ) |
| 65 | { |
| 66 | double x = ( double(i) + 0.5 ) / width; |
| 67 | double y = ( double( pass == 0 ? input.min.y : input.max.y ) + 0.5 ) / height; |
| 68 | |
| 69 | Imath::V2d pIn( x, y ); |
| 70 | Imath::V2d pOut( 0, 0 ); |
| 71 | |
| 72 | if( mode == Distort ) |
| 73 | { |
| 74 | pOut = distort( pIn ); |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | pOut = undistort( pIn ); |
| 79 | } |
| 80 | |
| 81 | if( !std::isinf( pOut.x ) && !std::isinf( pOut.y ) && !std::isnan( pOut.x ) && !std::isnan( pOut.y ) ) |
| 82 | { |
| 83 | pOut.x = pOut.x*width-0.5; |
| 84 | pOut.y = pOut.y*height-0.5; |
| 85 | if( !init ) |
| 86 | { |
| 87 | out.min.x = int( floor( pOut.x ) ); |
| 88 | out.min.y = int( floor( pOut.y ) ); |
| 89 | out.max.x = int( floor( pOut.x ) ); |
| 90 | out.max.y = int( floor( pOut.y ) ); |
| 91 | init = true; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | out.min.x = std::min( int( floor( pOut.x ) ), out.min.x ); |
| 96 | out.min.y = std::min( int( floor( pOut.y ) ), out.min.y ); |
| 97 | out.max.x = std::max( int( floor( pOut.x ) ), out.max.x ); |
| 98 | out.max.y = std::max( int( floor( pOut.y ) ), out.max.y ); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if ( !init ) return Imath::Box2i( Imath::V2i(0,0), Imath::V2i(0,0) ); |
| 105 | |
| 106 | for( int j = input.min.y; j <= input.max.y; j++ ) |
| 107 | { |
| 108 | for( int pass = 0; pass < 2; pass++ ) |
| 109 | { |
| 110 | double x = ( double( pass == 0 ? input.min.x : input.max.x ) + 0.5 ) / width; |
| 111 | double y = ( double(j) + 0.5 ) / height; |
| 112 | |
| 113 | Imath::V2d pIn( x, y ); |
| 114 | Imath::V2d pOut( 0, 0 ); |
no outgoing calls