I use QGraphicsView and QGraphicsScene to display a map - a lot of object (lines, images, polygons, etc). I implemented zooming the view this way:
...
void MapView::wheelEvent( QWheelEvent *pEvent )
{
if ( pEvent->modifiers() & Qt::ControlModifier )
{
if ( pEvent->delta() > 0 )
zoomIn();
else
zoomOut();
pEvent->accept();
}
else
{
QGraphicsView::wheelEvent( pEvent );
}
}
...
void MapView::zoomIn( int nValue )
{
m_dZoom = ( nValue == -1 ) ? qMin( ( m_dZoom + m_dZoomStep ), m_dZoomMax ) : qMin( ( m_dZoom + qreal( nValue ) ), m_dZoomMax );
setupTransform();
}
void MapView::zoomOut( int nValue )
{
m_dZoom = ( nValue == -1 ) ? qMax( ( m_dZoom - m_dZoomStep ), m_dZoomMin ) : qMax( ( m_dZoom - qreal( nValue ) ), m_dZoomMin );
setupTransform();
}
...
void MapView::setupTransform()
{
QTransform t = transform();
t.reset();
qreal dScale = qPow( qreal( 2 ), ( m_dZoom - ( m_dZoomMax / 4 ) ) / qreal( 50 ) );
t.scale( dScale, dScale );
setTransform( t );
emit onZoomChanged( m_dZoom );
}
...
When I run application on Linux (CentOS 6.3, Qt 4.8) - zooming the view runs very good (smoothly). But when I run it on Windows (Windows 7 32bit, Qt 5.4) zoomig the view freezes - I constanly rotate the mouse wheel with no effect (no zooming, the view is not responding), and after a second or two later the view starts responding again. When this happens current zoom position turned out to be correctly set - it seems like the view were zooming but not updating the picture. The problem occurs with different zoom values and scroll positions, but always when the view is going to crop map objects (paths).
Do you have any ideas how to fix that problem, or am I doing something wrong?
Thank you very much in advance.
Related
I capture images using BitBlt / StretchBlt API's on windows 10, depending upon the necessity for scaling the screen or not. Whenever I capture the 2nd monitor that is not being configured as primary, there seems to be a strange behaviour that the captured screen's first half is the replica of the second half of the screen. This occurs randomly once for every 10 images on an average.
I could not find any documents over the internet related to this kind of strange problems. I'm not even doing any multi-threading. Might there be a problem with the capturing frequency?, But that doesn't even look sense, as there is no issue with screen capture whenever I set the monitor as primary.
Here is the original image
captured image
monitor alignment
Note: I have been able to reproduce the issue only when the forground window is Notepad++ as of now. I'm not sure whether the issue happens for other applications as well., I could not go for directX based approach as the program must run on WindowsXP as well.
Here is an excerpt of the code:
HDC memDC = CreateCompatibleDC ( hDC ) ;
HBITMAP previousImage = ( HBITMAP ) SelectObject ( memDC , curImage )
if ( ( previousImage ) == NULL )
{
return -1;
}
BOOL blitok ;
if ( lf_ImageScalingFactor != (double)1.0 )
{
SetStretchBltMode ( memDC , HALFTONE ) ;
if ( capture_all )
{
blitok = StretchBlt ( memDC , 0 , 0 , (int)(clientwindow.Width () ) , (int) (clientwindow.Height () ),
hDC , clientwindow.left - (physicalscreenrect.left * lf_ImageScalingFactor), clientwindow.top - (physicalscreenrect.top * lf_ImageScalingFactor), physicalscreenrect.Width(), physicalscreenrect.Height(), SRCCOPY | CAPTUREBLT ) ;
}
else
{
blitok = StretchBlt ( memDC , 0 , 0 , (int)(clientwindow.Width ()) , (int)(clientwindow.Height ()),
hDC , clientwindow.left - (physicalscreenrect.left * lf_ImageScalingFactor), clientwindow.top - (physicalscreenrect.top * lf_ImageScalingFactor),physicalscreenrect.Width(), physicalscreenrect.Height(), SRCCOPY ) ;
}
}
else
{
if ( capture_all )
{
blitok = BitBlt ( memDC , 0 , 0 , clientwindow.Width (), clientwindow.Height (),
hDC , clientwindow.left - physicalscreenrect.left , clientwindow.top - physicalscreenrect.top , SRCCOPY | CAPTUREBLT ) ;
}
else
{
blitok = BitBlt ( memDC , 0 , 0 , clientwindow.Width (), clientwindow.Height (),
hDC , clientwindow.left - physicalscreenrect.left , clientwindow.top - physicalscreenrect.top , SRCCOPY ) ;
}
}
SelectObject ( memDC , previousImage ) ;
DeleteDC ( memDC ) ;
DeleteDC ( hDC ) ;
Am I doing something wrong over here?.
Any help is appreciable, Thanks in advance.
I use below code for #1 screenshot.
int _objfnd = ObjectFind( name );
if ( _objfnd == -1 )
{
ObjectCreate ( _vlineName, OBJ_VLINE, 0, Time[i], 0 );
...
}
and I use below code for #2 screenshot.
int _objfnd = ObjectFind( name );
if ( _objfnd == -1 )
{
datetime _dayTime = Time[i] ;
int _dayNext = PeriodSeconds( _Session_Breaks_Day_Prd ) ;
_dayTime = _dayTime - ( _dayTime % _dayNext ) + _dayNext ;
ObjectCreate ( _vlineName, OBJ_VLINE, 0, _dayTime, 0 ) ;
}
If you figure out my concern,please give me good advice, much appreciate.
A: the code has not handled Daylight Saving Time Shift 2016, Nov-06
I'm trying to use texture compression with TexImage3D in WebGL2 using Firefox 47 (nightly) but I cannot find a valid format. The error is:
Error: WebGL: compressedTexImage3D: Format COMPRESSED_RGB_S3TC_DXT1_EXT cannot be used with TEXTURE_3D.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script>
function compressedTexImage3D()
{
let canvas = document.createElement( 'canvas' )
let gl = canvas.getContext( 'webgl2' )
if( gl == null ) { alert( 'requires Firefox 47' ) }
let etc = gl.getExtension( 'WEBGL_compressed_texture_etc1' )
let s3tc = gl.getExtension( 'WEBGL_compressed_texture_s3tc' )
// let atc = gl.getExtension( 'WEBGL_compressed_texture_atc' )
// let es3 = gl.getExtension( 'WEBGL_compressed_texture_es3' )
// let pvrtc = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' )
let size = 64
let data = new Uint8Array( size * size * size )
let texture3D = gl.createTexture()
gl.bindTexture( gl.TEXTURE_3D, texture3D )
let formatsTexture3D =
[ etc .COMPRESSED_RGB_ETC1_WEBGL
, s3tc.COMPRESSED_RGB_S3TC_DXT1_EXT
, s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT
, s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT
, s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
]
formatsTexture3D.forEach( function( format )
{
gl.compressedTexImage3D
( gl.TEXTURE_3D // target
, 0 // level
, format // internal format
, size // width
, size // height
, size // depth
, 0 // border
, data // data
)
})
let texture2DArray = gl.createTexture()
gl.bindTexture( gl.TEXTURE_2D_ARRAY, texture2DArray )
let formatsTexture2DArray =
[ [etc .COMPRESSED_RGB_ETC1_WEBGL , new Uint8Array( size * size * size )]
//, [s3tc.COMPRESSED_RGB_S3TC_DXT1_EXT , new Uint8Array( size * size * size / 2 )] // crash
//, [s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT, new Uint8Array( size * size * size / 2 )] // crash
//, [s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT, new Uint8Array( size * size * size / 2 )] // crash
//, [s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT, new Uint8Array( size * size * size )] // crash
]
formatsTexture2DArray.forEach( function( formatData )
{
let format = formatData[0]
let data = formatData[1]
gl.compressedTexImage3D
( gl.TEXTURE_2D_ARRAY // target
, 0 // level
, format // internal format
, size // width
, size // height
, size // depth
, 0 // border
, data // data
)
})
}
</script>
</head>
<body onload="compressedTexImage3D()">
</body>
</html>
Which format can I use?
TEXTURE_ARRAY_2Ds SHOULD work like so:
let s3tc = gl.getExtension( 'WEBGL_compressed_texture_s3tc' )
let size = 64
let format = s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT
let data = new Uint8Array( size * size * size )
let texture2DArray = gl.createTexture()
gl.bindTexture ( gl.TEXTURE_2D_ARRAY, texture2DArray )
gl.texStorage3D( gl.TEXTURE_2D_ARRAY, 1, format, size, size, size )
gl.compressedTexSubImage3D
( gl.TEXTURE_2D_ARRAY // target
, 0 // level
, 0 // xoffset
, 0 // yoffset
, 0 // zoffset
, size // width
, size // height
, size // depth
, format // format
//, size * size * size // imageSize: omitted in WebGL?
, pixels // data
)
but this snippet crashes Firefox 48.0a1 (nightly)
Update: about:config -> webl.disable-angle: true. Wow!
Corresponding to Firefox WebGLTextureUpload.cpp the following formats are specifically excluded for TEXTURE_3D.
// TEXTURE_2D_ARRAY but not TEXTURE_3D:
// D and DS formats
case webgl::EffectiveFormat::DEPTH_COMPONENT16:
case webgl::EffectiveFormat::DEPTH_COMPONENT24:
case webgl::EffectiveFormat::DEPTH_COMPONENT32F:
case webgl::EffectiveFormat::DEPTH24_STENCIL8:
case webgl::EffectiveFormat::DEPTH32F_STENCIL8:
// CompressionFamily::ES3
case webgl::EffectiveFormat::COMPRESSED_R11_EAC:
case webgl::EffectiveFormat::COMPRESSED_SIGNED_R11_EAC:
case webgl::EffectiveFormat::COMPRESSED_RG11_EAC:
case webgl::EffectiveFormat::COMPRESSED_SIGNED_RG11_EAC:
case webgl::EffectiveFormat::COMPRESSED_RGB8_ETC2:
case webgl::EffectiveFormat::COMPRESSED_SRGB8_ETC2:
case webgl::EffectiveFormat::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
case webgl::EffectiveFormat::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
case webgl::EffectiveFormat::COMPRESSED_RGBA8_ETC2_EAC:
case webgl::EffectiveFormat::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
// CompressionFamily::S3TC
case webgl::EffectiveFormat::COMPRESSED_RGB_S3TC_DXT1_EXT:
case webgl::EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT1_EXT:
case webgl::EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT3_EXT:
case webgl::EffectiveFormat::COMPRESSED_RGBA_S3TC_DXT5_EXT:
if (target == LOCAL_GL_TEXTURE_3D) {
webgl->ErrorInvalidOperation("%s: Format %s cannot be used with TEXTURE_3D.",
funcName, format->name);
return false;
}
break;
// No 3D targets:
// CompressionFamily::ATC
case webgl::EffectiveFormat::ATC_RGB_AMD:
case webgl::EffectiveFormat::ATC_RGBA_EXPLICIT_ALPHA_AMD:
case webgl::EffectiveFormat::ATC_RGBA_INTERPOLATED_ALPHA_AMD:
// CompressionFamily::PVRTC
case webgl::EffectiveFormat::COMPRESSED_RGB_PVRTC_4BPPV1:
case webgl::EffectiveFormat::COMPRESSED_RGBA_PVRTC_4BPPV1:
case webgl::EffectiveFormat::COMPRESSED_RGB_PVRTC_2BPPV1:
case webgl::EffectiveFormat::COMPRESSED_RGBA_PVRTC_2BPPV1:
// CompressionFamily::ETC1
case webgl::EffectiveFormat::ETC1_RGB8_OES:
if (target == LOCAL_GL_TEXTURE_3D ||
target == LOCAL_GL_TEXTURE_2D_ARRAY)
{
webgl->ErrorInvalidOperation("%s: Format %s cannot be used with TEXTURE_3D or"
" TEXTURE_2D_ARRAY.",
funcName, format->name);
return false;
}
break;
I'm using XInput for a project and I'm having a problem using the xbox controller. When I use the B button to return to a previous state, its registering the button press so fast that it continues to push back multiple states that use the B button to exit.
if( ( player1.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) || ( player2.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) ) {
return ESC_BUTTON;
}
I've tried resetting the buffer by adding an & 1 but than the input never registers. Is there an easy way to fix this problem?
UPDATE:
current = (DWORD)( ( start - GetTickCount() ) / 1000.f );
if( current > 0.005f )
{
if( ( player1.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) || ( player2.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) )
{
start = GetTickCount();
return ESC_BUTTON;
}
}
Still having issues with resetting. Sometimes it works, sometimes it doesn't...thoughts?
Not able to capture Image, works in other laptop, my webcam is not able to open.But it works in other laptop.The output is "Error:Capture is Null"
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main() {
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while ( 1 ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if ( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
}
cvShowImage( "mywindow", frame );
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if ( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
You may try different numbers in the place of CV_CAP_ANY.
It is also possible that your OpenCV is not installed appropriately, then you should reinstall it with libv4l as it is suggested here.
There is a slight chance that your camera is not compatible with OpenCV.
Try passing -1 instead of CV_CAP_ANY.