You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
404 lines
9.8 KiB
404 lines
9.8 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgUISiteCamera.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgUISiteCamera.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgUISiteCamera.h"
|
|
#include "LgUISiteSensor.h"
|
|
#include "LgUISiteEngine.h"
|
|
#include "..\UICamera\LgUICameraVideoWnd.h"
|
|
|
|
|
|
CLgUISiteCamera::CLgUISiteCamera( HAL_OBJECT_ID nID ) :
|
|
CLgHALCamera( nID )
|
|
{
|
|
m_Position.x = (rand() % 100) / 100.0;
|
|
m_Position.y = (rand() % 100) / 100.0;
|
|
|
|
m_ptzDelta.dPan = m_ptzDelta.dTilt = m_ptzDelta.dZoom = 0;
|
|
m_ptzPosition.dPan = m_ptzPosition.dTilt = m_ptzPosition.dZoom = 0;
|
|
|
|
m_dwDirection = CAMERA_PAN_STOP | CAMERA_TILT_STOP | CAMERA_ZOOM_STOP;
|
|
|
|
m_nVideoSampleID = 0;
|
|
}
|
|
|
|
CLgUISiteCamera::~CLgUISiteCamera()
|
|
{
|
|
}
|
|
|
|
BOOL CLgUISiteCamera::OnUIMapHitTest( CLgUIMapObjectWnd*, CLgDRect *pRect )
|
|
{
|
|
if( !pRect->PtInRect( m_Position ) )
|
|
return FALSE;
|
|
|
|
CLgUISiteEngine *pEngine = *this;
|
|
if( !pEngine )
|
|
{
|
|
// critical error!
|
|
ASSERT( NULL );
|
|
return TRUE;
|
|
}
|
|
|
|
// try to activate camera
|
|
pEngine->OnActivateVideoCamera( this );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgUISiteCamera::OnUIMapDraw( CLgUIMapObjectWnd *pMap, CDC *pDC, BOOL bActive, BOOL bOddUpdate )
|
|
{
|
|
CLgDPoint dp( m_Position.x, m_Position.y );
|
|
|
|
// draw sensor representation
|
|
CPoint p = pMap->AreaToWindow( &dp );
|
|
|
|
CRect rect;
|
|
if( bActive && !bOddUpdate ) rect.SetRect( p.x - 2, p.y - 2, p.x + 2, p.y + 2 );
|
|
else rect.SetRect( p.x - 1, p.y - 1, p.x + 1, p.y + 1 );
|
|
|
|
pDC->FillSolidRect( &rect, RGB(255,255,255) );
|
|
|
|
// test
|
|
CLgDRect dr( dp.x - 0.2, dp.y - 0.2, dp.x + 0.2, dp.y + 0.2 );
|
|
|
|
// paint video frame
|
|
CRect cr = pMap->AreaToWindow( &dr );
|
|
|
|
// calculate positions
|
|
double d = 3.0 + (1.0 - m_ptzPosition.dZoom) * 21.0;
|
|
INT w = cr.Width() / 2;
|
|
INT h = cr.Height() / 2;
|
|
double r = h * ( 0.2 + m_ptzPosition.dZoom * 0.8 );
|
|
|
|
w = h = 1;
|
|
|
|
INT x1 = (INT)( ( cos( ( m_ptzPosition.dPan + d ) / 360.0 * 6.2831 ) ) * r + w ) + p.x;
|
|
INT y1 = (INT)( ( sin( ( m_ptzPosition.dPan + d ) / 360.0 * 6.2831 ) ) * r + h ) + p.y;
|
|
INT x2 = (INT)( ( cos( ( m_ptzPosition.dPan - d ) / 360.0 * 6.2831 ) ) * r + w ) + p.x;
|
|
INT y2 = (INT)( ( sin( ( m_ptzPosition.dPan - d ) / 360.0 * 6.2831 ) ) * r + h ) + p.y;
|
|
|
|
// draw
|
|
POINT pP[] = { { x1, y1 }, { x2, y2 }, { w + p.x, h + p.y } };
|
|
|
|
COLORREF color = RGB(0,255,0);
|
|
CBrush brush( color );
|
|
CPen pen( PS_SOLID, 1, color );
|
|
|
|
CBrush *pBrush = pDC->SelectObject( &brush );
|
|
CPen *pPen = pDC->SelectObject( &pen );
|
|
|
|
rect.SetRect( (INT)(w-r+p.x), (INT)(h-r+p.y), (INT)(w+r+p.x), (INT)(h+r+p.y) );
|
|
pDC->Pie( &rect, pP[0], pP[1] );
|
|
|
|
pDC->SelectObject( pBrush );
|
|
pDC->SelectObject( pPen );
|
|
}
|
|
|
|
void CLgUISiteCamera::OnUIMapDrawBackground( CLgUIMapObjectWnd *pMap, CDC *pDC )
|
|
{
|
|
|
|
}
|
|
|
|
// camera access events
|
|
void CLgUISiteCamera::OnHalCameraVideo( HAL_CAMERA_RESULT eReason )
|
|
{
|
|
// call base class
|
|
// CLgHALCamera::OnHalCameraVideo( eReason );
|
|
|
|
switch( eReason )
|
|
{
|
|
case HAL_CAMERA_VIDEO_GRANTED:
|
|
// askquare video sample
|
|
HalCameraVideoGetSample( m_nVideoSampleID );
|
|
// notify user interface
|
|
OnUICameraVideo( TRUE );
|
|
// try to access to control stream
|
|
switch( HalCameraControlGet() )
|
|
{
|
|
case HAL_CAMERA_CONTROL_PENDING:
|
|
break;
|
|
case HAL_CAMERA_CONTROL_GRANTED:
|
|
OnUICameraControl( TRUE );
|
|
break;
|
|
}
|
|
break;
|
|
|
|
case HAL_CAMERA_VIDEO_RELEASED:
|
|
case HAL_CAMERA_VIDEO_RELEASED_BY_TIMEOUT:
|
|
case HAL_CAMERA_VIDEO_RELEASED_BY_PRIORITY:
|
|
OnUICameraVideo( FALSE );
|
|
|
|
// try to release to control stream
|
|
switch( HalCameraControlRelease() )
|
|
{
|
|
case HAL_CAMERA_CONTROL_PENDING:
|
|
break;
|
|
case HAL_CAMERA_CONTROL_RELEASED:
|
|
OnUICameraControl( FALSE );
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
// video samples events
|
|
void CLgUISiteCamera::OnHalCameraVideoSample( HAL_CAMERA_RESULT eReason, CLgImageDIB* pDIB, INT nVideoSampleID )
|
|
{
|
|
// call base class
|
|
// CLgHALCamera::OnHalCameraVideoSample( eReason, pDIB );
|
|
|
|
if( eReason == HAL_CAMERA_VIDEO_SAMPLE_RECEIVED )
|
|
{
|
|
// remeber sample id for next request
|
|
m_nVideoSampleID = nVideoSampleID;
|
|
|
|
OnUICameraVideoSample( pDIB );
|
|
// get next sample
|
|
// HalCameraVideoGetSample();
|
|
}
|
|
}
|
|
|
|
// camera access events
|
|
void CLgUISiteCamera::OnHalCameraControl( HAL_CAMERA_RESULT eReason )
|
|
{
|
|
// call base class
|
|
// CLgHALCamera::OnHalCameraControl( eReason );
|
|
|
|
switch( eReason )
|
|
{
|
|
case HAL_CAMERA_CONTROL_GRANTED:
|
|
OnUICameraControl( TRUE );
|
|
break;
|
|
case HAL_CAMERA_CONTROL_RELEASED:
|
|
case HAL_CAMERA_CONTROL_RELEASED_BY_TIMEOUT:
|
|
case HAL_CAMERA_CONTROL_RELEASED_BY_PRIORITY:
|
|
OnUICameraControl( FALSE );
|
|
break;
|
|
}
|
|
}
|
|
|
|
// camera movements events
|
|
void CLgUISiteCamera::OnHalCameraControlPosition( HAL_CAMERA_RESULT eReason, double dPan, double dTilt, double dZoom )
|
|
{
|
|
// CLgHALCamera::OnHalCameraControlPosition( eReason, dPan, dTilt, dZoom );
|
|
}
|
|
|
|
// start stop camera operation
|
|
BOOL CLgUISiteCamera::CameraActivate( BOOL bActivate )
|
|
{
|
|
if( bActivate )
|
|
{
|
|
// acquare access from camera
|
|
HAL_CAMERA_RESULT eResult = HalCameraVideoGet();
|
|
|
|
// depend on result
|
|
switch( eResult )
|
|
{
|
|
// wait for access
|
|
case HAL_CAMERA_VIDEO_PENDING:
|
|
return TRUE;
|
|
|
|
// access already granted
|
|
case HAL_CAMERA_VIDEO_GRANTED:
|
|
OnUICameraVideo( bActivate );
|
|
|
|
// try to access to control stream
|
|
eResult = HalCameraControlGet();
|
|
switch( eResult )
|
|
{
|
|
case HAL_CAMERA_CONTROL_PENDING:
|
|
return TRUE;
|
|
|
|
// access already granted
|
|
case HAL_CAMERA_CONTROL_GRANTED:
|
|
OnUICameraControl( bActivate );
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// acquare access from camera
|
|
HAL_CAMERA_RESULT eResult = HalCameraVideoRelease();
|
|
|
|
// depend on result
|
|
switch( eResult )
|
|
{
|
|
// wait for access
|
|
case HAL_CAMERA_VIDEO_PENDING:
|
|
return TRUE;
|
|
|
|
// access already granted
|
|
case HAL_CAMERA_VIDEO_RELEASED:
|
|
OnUICameraVideo( bActivate );
|
|
OnUICameraControl( bActivate );
|
|
return TRUE;
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CLgUISiteCamera::UICameraMovePTZ( DWORD dwDirection )
|
|
{
|
|
if( dwDirection & CAMERA_PAN_MASK )
|
|
{
|
|
if( ( m_dwDirection & CAMERA_PAN_MASK ) != ( dwDirection & CAMERA_PAN_MASK ) )
|
|
{
|
|
m_ptzDelta.dPan = 0;
|
|
m_dwDirection = ( m_dwDirection & ~CAMERA_PAN_MASK ) | ( dwDirection & CAMERA_PAN_MASK );
|
|
}
|
|
}
|
|
|
|
if( dwDirection & CAMERA_TILT_MASK )
|
|
{
|
|
if( ( m_dwDirection & CAMERA_TILT_MASK ) != ( dwDirection & CAMERA_TILT_MASK ) )
|
|
{
|
|
m_ptzDelta.dTilt = 0;
|
|
m_dwDirection = ( m_dwDirection & ~CAMERA_TILT_MASK ) | ( dwDirection & CAMERA_TILT_MASK );
|
|
}
|
|
}
|
|
|
|
if( dwDirection & CAMERA_ZOOM_MASK )
|
|
{
|
|
if( ( m_dwDirection & CAMERA_ZOOM_MASK ) != ( dwDirection & CAMERA_ZOOM_MASK ) )
|
|
{
|
|
m_ptzDelta.dZoom = 0;
|
|
m_dwDirection = ( m_dwDirection & ~CAMERA_ZOOM_MASK ) | ( dwDirection & CAMERA_ZOOM_MASK );
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CLgUISiteCamera::UICameraSampleGet()
|
|
{
|
|
// ask for next sample
|
|
return HalCameraVideoGetSample( m_nVideoSampleID );
|
|
}
|
|
|
|
// move PTZ camera
|
|
BOOL CLgUISiteCamera::CameraMovePTZ( double dPan, double dTilt, double dZoom )
|
|
{
|
|
TRACE( "[%p]CLgUISiteCamera::CameraMovePTZ %0.2f %0.2f %0.2f\n", this, dPan, dTilt, dZoom );
|
|
|
|
// repaint itself
|
|
return CLgUIMapObject::RedrawUIMapObject();
|
|
}
|
|
|
|
BOOL CLgUISiteCamera::CameraGetPTZ( double *pPan, double *pTilt, double *pZoom )
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CLgUISiteCamera::OnUISiteClock()
|
|
{
|
|
BOOL bChange = FALSE;
|
|
|
|
// apply pan
|
|
switch( m_dwDirection & CAMERA_PAN_MASK )
|
|
{
|
|
case CAMERA_PAN_LEFT:
|
|
// perform acceleration
|
|
if( m_ptzDelta.dPan < 10 )
|
|
m_ptzDelta.dPan += 1;
|
|
|
|
// calculate new position
|
|
m_ptzPosition.dPan -= m_ptzDelta.dPan;
|
|
if( m_ptzPosition.dPan < 0.0 )
|
|
m_ptzPosition.dPan += 360.0;
|
|
|
|
// remember changes
|
|
bChange = TRUE;
|
|
break;
|
|
case CAMERA_PAN_RIGHT:
|
|
// perform acceleration
|
|
if( m_ptzDelta.dPan < 10 )
|
|
m_ptzDelta.dPan += 1;
|
|
|
|
// calculate new position
|
|
m_ptzPosition.dPan += m_ptzDelta.dPan;
|
|
if( m_ptzPosition.dPan >= 360.0 )
|
|
m_ptzPosition.dPan -= 360.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case CAMERA_PAN_STOP:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// apply tilt
|
|
switch( m_dwDirection & CAMERA_TILT_MASK )
|
|
{
|
|
case CAMERA_TILT_UP:
|
|
// perform acceleration
|
|
if( m_ptzDelta.dTilt < 10 )
|
|
m_ptzDelta.dTilt += 1;
|
|
|
|
// calculate new position
|
|
m_ptzPosition.dTilt -= m_ptzDelta.dTilt;
|
|
if( m_ptzPosition.dTilt < -30.0 )
|
|
m_ptzPosition.dTilt = -30.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case CAMERA_TILT_DOWN:
|
|
// perform acceleration
|
|
if( m_ptzDelta.dTilt < 10 )
|
|
m_ptzDelta.dTilt += 1;
|
|
|
|
// calculate new position
|
|
m_ptzPosition.dTilt += m_ptzDelta.dTilt;
|
|
if( m_ptzPosition.dTilt > 90.0 )
|
|
m_ptzPosition.dTilt = 90.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case CAMERA_TILT_STOP:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// apply zoom
|
|
switch( m_dwDirection & CAMERA_ZOOM_MASK )
|
|
{
|
|
case CAMERA_ZOOM_TELE:
|
|
// perform acceleration
|
|
if( m_ptzDelta.dZoom < 0.10 )
|
|
m_ptzDelta.dZoom += 0.01;
|
|
|
|
// calculate new position
|
|
m_ptzPosition.dZoom += m_ptzDelta.dZoom;
|
|
if( m_ptzPosition.dZoom > 1.0 )
|
|
m_ptzPosition.dZoom = 1.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case CAMERA_ZOOM_WIDE:
|
|
// perform acceleration
|
|
if( m_ptzDelta.dZoom < 0.10 )
|
|
m_ptzDelta.dZoom += 0.01;
|
|
|
|
// calculate new position
|
|
m_ptzPosition.dZoom -= m_ptzDelta.dZoom;
|
|
if( m_ptzPosition.dZoom < 0.0 )
|
|
m_ptzPosition.dZoom = 0.0;
|
|
bChange = TRUE;
|
|
break;
|
|
case CAMERA_ZOOM_STOP:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// apply changes
|
|
if( bChange )
|
|
CameraMovePTZ( m_ptzPosition.dPan, m_ptzPosition.dTilt, m_ptzPosition.dZoom );
|
|
|
|
return TRUE;
|
|
}
|