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.
hasArea() )
261 const int32_t sEx = x + w;
262 const int32_t sEy = y + h;
263 const int32_t dEx = rhs.x + rhs.w;
264 const int32_t dEy = rhs.y + rhs.h;
266 x = LB_MIN( x, rhs.x );
267 y = LB_MIN( y, rhs.y );
268 w = LB_MAX( sEx, dEx ) - x;
269 h = LB_MAX( sEy, dEy ) - y;
293 const int32_t sEx = x + w;
294 const int32_t sEy = y + h;
295 const int32_t dEx = rhs.x + rhs.w;
296 const int32_t dEy = rhs.y + rhs.h;
298 x = LB_MAX( x, rhs.x );
299 y = LB_MAX( y, rhs.y );
300 w = LB_MIN( sEx, dEx ) - x;
301 h = LB_MIN( sEy, dEy ) - y;
312 inline std::ostream& operator << ( std::ostream& os,
313 const PixelViewport& pvp )
315 os <<
"[ " << pvp.x <<
" " << pvp.y <<
" " << pvp.w <<
" " << pvp.h
332 #endif // EQFABRIC_PIXELVIEWPORT_H
void apply(const Zoom &zoom)
Apply a zoom to this pixel viewport.
const Zoom getZoom(const PixelViewport &rhs) const
static const Viewport FULL
A full viewport.
bool isInside(const int32_t pX, const int32_t pY) const
bool operator==(const PixelViewport &rhs) const
Holds a pixel decomposition specification with methods for manipulation.
PixelViewport()
Construct a new, invalid pixel viewport.
void apply(const Pixel &pixel)
Apply a pixel decomposition to this pixel viewport.
const PixelViewport operator+(const Vector2i &offset) const
void convertToPlugin(uint64_t dims[4]) const
Convert into a lunchbox::Plugin usable format.
Holds a 2D pixel viewport with methods for manipulation.
PixelViewport(const int32_t pvp[4])
Construct a new pixel viewport with default values.
bool operator!=(const PixelViewport &rhs) const
void apply(const Viewport &rhs)
Apply a fractional viewport to this pixel viewport.
void merge(const PixelViewport &rhs)
Create a pixel viewport that includes both viewports (union).
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 unapply(const Pixel &pixel)
Perform the inverse operation of applying a pixel decomposition to this pixel viewport.
static const Zoom NONE
The zoom NONE (1,1) value.
A zoom specification with methods for manipulation.
void convertFromPlugin(const uint64_t dims[4])
Convert from a lunchbox::Plugin format.
const PixelViewport & operator-=(const Vector2i &offset)
A fractional viewport with methods for manipulation.
void invalidate()
Invalidate the pixel viewport.
void intersect(const PixelViewport &rhs)
Create the intersection of the two pixel viewports.
vmml::vector< 2, int > Vector2i
A two-component integer vector.