18 #ifndef EQFABRIC_PIXELVIEWPORT_H
19 #define EQFABRIC_PIXELVIEWPORT_H
21 #include <eq/fabric/viewport.h>
22 #include <eq/fabric/pixel.h>
23 #include <eq/fabric/zoom.h>
25 #include <lunchbox/debug.h>
44 const int32_t w_,
const int32_t h_ )
45 : x(x_), y(y_), w(w_), h(h_) {}
49 : x( pvp[0] ), y( pvp[1] ), w( pvp[2] ), h( pvp[3] ) {}
62 bool isValid()
const {
return (w>=0 && h>=0); }
69 bool hasArea()
const {
return (w>0 && h>0); }
72 uint32_t
getArea()
const {
return w * h; }
78 bool isInside(
const int32_t pX,
const int32_t pY )
const
80 if( pX < x || pY < y || pX > (x+w) || pY > (y+h) )
92 const int32_t xEnd = x +
static_cast<int32_t
>((rhs.
x+rhs.
w)*w);
93 const int32_t yEnd = y +
static_cast<int32_t
>((rhs.
y+rhs.
h)*h);
95 x +=
static_cast<int32_t
>( w * rhs.
x );
96 y +=
static_cast<int32_t
>( h * rhs.
y );
106 int32_t newWidth = w / pixel.w;
110 if( w - ( newWidth * pixel.w ) != 0 )
117 int32_t newHeight = h / pixel.h;
121 if( h - ( newHeight * pixel.h ) != 0 )
134 x =
static_cast< int32_t
>( x * zoom.x() + .5f );
135 y =
static_cast< int32_t
>( y * zoom.y() + .5f );
136 w =
static_cast< int32_t
>( w * zoom.x() + .5f );
137 h =
static_cast< int32_t
>( h * zoom.y() + .5f );
151 return Zoom( std::numeric_limits< float >::max(),
152 std::numeric_limits< float >::max( ));
154 return Zoom( w / static_cast<float>( rhs.w ),
155 h / static_cast<float>( rhs.h ));
176 x = int32_t( dims[ 0 ]);
177 w = int32_t( dims[ 1 ]);
178 y = int32_t( dims[ 2 ]);
179 h = int32_t( dims[ 3 ]);
198 return Viewport( static_cast<float>( x ),
199 static_cast<float>( y ), 0.f, 0.f );
201 return Viewport( ( x - rhs.x )/ static_cast<float>( rhs.w ),
202 ( y - rhs.y )/ static_cast<float>( rhs.h ),
203 ( w )/ static_cast<float>( rhs.w ),
204 ( h )/ static_cast<float>( rhs.h ));
234 return ( x==rhs.x && y==rhs.y && w==rhs.w && h==rhs.h );
243 return ( x!=rhs.x || y!=rhs.y || w!=rhs.w || h!=rhs.h );
252 if( *
this == rhs || !rhs.
isValid( ))
263 const int32_t sEx = x + w;
264 const int32_t sEy = y + h;
265 const int32_t dEx = rhs.x + rhs.w;
266 const int32_t dEy = rhs.y + rhs.h;
268 x = LB_MIN( x, rhs.x );
269 y = LB_MIN( y, rhs.y );
270 w = LB_MAX( sEx, dEx ) - x;
271 h = LB_MAX( sEy, dEy ) - y;
295 const int32_t sEx = x + w;
296 const int32_t sEy = y + h;
297 const int32_t dEx = rhs.x + rhs.w;
298 const int32_t dEy = rhs.y + rhs.h;
300 x = LB_MAX( x, rhs.x );
301 y = LB_MAX( y, rhs.y );
302 w = LB_MIN( sEx, dEx ) - x;
303 h = LB_MIN( sEy, dEy ) - y;
314 inline std::ostream& operator << ( std::ostream& os,
315 const PixelViewport& pvp )
317 os <<
"[ " << pvp.x <<
" " << pvp.y <<
" " << pvp.w <<
" " << pvp.h
334 #endif // EQFABRIC_PIXELVIEWPORT_H
A zoom specification with methods for manipulation.
bool operator!=(const PixelViewport &rhs) const
void invalidate()
Invalidate the pixel viewport.
const Zoom getZoom(const PixelViewport &rhs) const
PixelViewport(const int32_t pvp[4])
Construct a new pixel viewport with default values.
A fractional viewport with methods for manipulation.
const PixelViewport & operator-=(const Vector2i &offset)
void convertToPlugin(uint64_t dims[4]) const
Convert into a lunchbox::Plugin usable format.
PixelViewport(const int32_t x_, const int32_t y_, const int32_t w_, const int32_t h_)
Construct a new pixel viewport with default values.
void convertFromPlugin(const uint64_t dims[4])
Convert from a lunchbox::Plugin format.
void apply(const Zoom &zoom)
Apply a zoom to this pixel viewport.
const PixelViewport operator+(const Vector2i &offset) const
void intersect(const PixelViewport &rhs)
Create the intersection of the two pixel viewports.
void apply(const Viewport &rhs)
Apply a fractional viewport to this pixel viewport.
PixelViewport()
Construct a new, invalid pixel viewport.
Holds a pixel decomposition specification with methods for manipulation.
static EQFABRIC_API const Viewport FULL
A full viewport.
bool operator==(const PixelViewport &rhs) const
void unapply(const Pixel &pixel)
Perform the inverse operation of applying a pixel decomposition to this pixel viewport.
void apply(const Pixel &pixel)
Apply a pixel decomposition to this pixel viewport.
bool isInside(const int32_t pX, const int32_t pY) const
void merge(const PixelViewport &rhs)
Create a pixel viewport that includes both viewports (union).
Holds a 2D pixel viewport with methods for manipulation.
static EQFABRIC_API const Zoom NONE
The zoom NONE (1,1) value.