1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
40 //M*/// HMMDemoView.cpp : implementation of the CHMMDemoView class
46 #include "HMMDemoDoc.h"
47 #include "HMMDemoView.h"
52 static char THIS_FILE[] = __FILE__;
55 /////////////////////////////////////////////////////////////////////////////
58 IMPLEMENT_DYNCREATE(CHMMDemoView, CView)
60 BEGIN_MESSAGE_MAP(CHMMDemoView, CView)
61 //{{AFX_MSG_MAP(CHMMDemoView)
70 /////////////////////////////////////////////////////////////////////////////
71 // CHMMDemoView construction/destruction
73 CHMMDemoView::CHMMDemoView()
75 m_sel = m_tmp_sel = CRect(0,0,0,0);
80 CHMMDemoView::~CHMMDemoView()
85 BOOL CHMMDemoView::PreCreateWindow(CREATESTRUCT& cs)
87 return CView::PreCreateWindow(cs);
90 /////////////////////////////////////////////////////////////////////////////
91 // CHMMDemoView drawing
93 void CHMMDemoView::OnDraw(CDC* pDC)
95 CHMMDemoDoc* pDoc = GetDocument();
98 HDC dstDC = pDC->m_hDC;
99 CImage& frame = m_camera.GetFrame();
102 GetClipBox( dstDC, &r );
104 if( m_imageList && m_imageList->GetCount() > 1 ) //several images was selected
106 pDC->Draw3dRect(0,0,frame.Width(),frame.Height(),RGB(0,0,0),RGB(128,128,128));
109 //force image to be top-left
110 IplImage* img = frame.GetImage();
111 if( img ) img->origin = IPL_ORIGIN_TL;
112 frame.Show( dstDC, r.left, r.top, r.Width(), r.Height(), r.left, r.top );
114 if( m_sel.Width() != 0 && m_sel.Height() != 0 )
116 HGDIOBJ old = SelectObject( dstDC, GetStockObject( WHITE_PEN ));
118 { m_sel.left - r.left, m_sel.top - r.top },
119 { m_sel.right - r.left - 1, m_sel.top - r.top },
120 { m_sel.right - r.left - 1, m_sel.bottom - r.top - 1},
121 { m_sel.left - r.left, m_sel.bottom - r.top - 1},
122 { m_sel.left - r.left, m_sel.top - r.top }
125 Polyline( dstDC, pt, 5 );
126 SelectObject( dstDC, old );
129 //::ReleaseDC( m_hWnd, dstDC );
132 /////////////////////////////////////////////////////////////////////////////
133 // CHMMDemoView message handlers
135 void CHMMDemoView::OnInitialUpdate()
137 CView::OnInitialUpdate();
139 if( m_camera.Initialize( 320, 240, -1, m_hWnd ) == 0 )
141 MessageBox("Can't initialize camera. Try to change format","Error", MB_OK|MB_ICONERROR );
146 void CHMMDemoView::OnDestroy()
148 m_camera.Uninitialize();
152 void CHMMDemoView::OnLButtonDown(UINT nFlags, CPoint point)
154 CView::OnLButtonDown(nFlags, point);
155 /*(CPoint&)m_sel = */(CPoint&)m_tmp_sel.left = (CPoint&)m_tmp_sel.right = point;
159 void CHMMDemoView::OnLButtonUp(UINT nFlags, CPoint point)
161 CView::OnLButtonUp(nFlags, point);
162 (CPoint&)m_tmp_sel.right = point;
166 void CHMMDemoView::OnMouseMove(UINT nFlags, CPoint point)
168 CView::OnMouseMove(nFlags, point);
169 if( nFlags & MK_LBUTTON )
171 (CPoint&)m_tmp_sel.right = point;
177 void CHMMDemoView::CheckUpdate()
179 m_sel = NormalizeRect( m_tmp_sel );
180 if( !Camera().IsRunning() )
182 CImage& img = Camera().GetFrame();
183 CRect ir( 0, 0, img.Width(), img.Height() );
185 InvalidateRect(&ir, FALSE);
190 BOOL CHMMDemoView::OnEraseBkgnd(CDC* pDC)
192 CImage& img = Camera().GetFrame();
193 CRect ir( 0, 0, img.Width(), img.Height() );
195 pDC->GetClipBox( &r );
197 if( ir.PtInRect( r.TopLeft()) && ir.PtInRect( r.BottomRight()))
200 return CView::OnEraseBkgnd(pDC);
203 void CHMMDemoView::SetSelection( RECT* sel )
207 m_tmp_sel = NormalizeRect( *sel );
211 CImage& img = Camera().GetFrame();
212 m_tmp_sel = CRect( 0, 0, img.Width(), img.Height() );
217 void CHMMDemoView::SetImageList( CStringList* imageList )
219 if( m_imageList ) delete m_imageList;
220 m_imageList = imageList;
224 BOOL CHMMDemoView::SetTestPath(char* path)