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.
41 // This class implements the property page for the CamShift filter
43 // This class implements the property page for the CCondens filter
45 #include <cvstreams.h>
50 #include "iCamShift.h"
51 #include "CamShiftF.h"
52 #include "CamShiftProp.h"
53 #include "CamShiftUIDs.h"
58 // This goes in the factory template table to create new filter instances
64 // This goes in the factory template table to create new filter instances
66 CUnknown * WINAPI CCamShiftProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr)
68 CUnknown *punk = new CCamShiftProperties(lpunk, phr);
77 void CCamShiftProperties::InitSlider( int id, int lower, int upper, int tic_freq )
79 HWND slider = GetDlgItem( m_hWnd, id );
82 SendMessage( slider, TBM_SETRANGE, TRUE, MAKELONG(lower, upper) );
86 SendMessage( slider, TBM_SETTICFREQ, tic_freq, 0 );
92 void CCamShiftProperties::SetSliderPos( int id, int pos )
94 HWND slider = GetDlgItem( m_hWnd, id );
97 SendMessage( slider, TBM_SETPOS, TRUE, pos );
102 int CCamShiftProperties::GetSliderPos( int id )
104 HWND slider = GetDlgItem( m_hWnd, id );
109 pos = SendMessage( slider, TBM_GETPOS, 0, 0 );
116 void CCamShiftProperties::ReadParamsFromControls()
118 m_params.x = ((float)GetSliderPos( IDC_WIN_LEFT ))/SLIDER_MAX;
119 m_params.y = ((float)GetSliderPos( IDC_WIN_TOP ))/SLIDER_MAX;
120 m_params.width = ((float)GetSliderPos( IDC_WIN_WIDTH ))/SLIDER_MAX;
121 m_params.height = ((float)GetSliderPos( IDC_WIN_HEIGHT ))/SLIDER_MAX;
123 m_params.Smin = GetSliderPos( IDC_S_MIN );
124 m_params.Vmin = GetSliderPos( IDC_V_MIN );
126 //m_params.nSamples = GetSliderPos( IDC_SLIDERS_NUM );
128 m_params.view = IsDlgButtonChecked( m_hWnd, IDC_BACKPR );
132 void CCamShiftProperties::WriteParamsToControls()
134 SetSliderPos( IDC_WIN_LEFT, cvRound( m_params.x * SLIDER_MAX ));
135 SetSliderPos( IDC_WIN_TOP, cvRound( m_params.y * SLIDER_MAX ));
136 SetSliderPos( IDC_WIN_WIDTH, cvRound( m_params.width * SLIDER_MAX ));
137 SetSliderPos( IDC_WIN_HEIGHT, cvRound( m_params.height * SLIDER_MAX ));
139 SetSliderPos( IDC_S_MIN, m_params.Smin );
140 SetSliderPos( IDC_V_MIN, m_params.Vmin );
142 //SetSliderPos( IDC_SAMPLES_NUM, m_params.nSamples );
144 CheckRadioButton( m_hWnd, IDC_NORMAL, IDC_BACKPR, m_params.view + IDC_NORMAL );
150 CCamShiftProperties::CCamShiftProperties(LPUNKNOWN pUnk, HRESULT *phr) :
151 CBasePropertyPage(NAME("CamShift Property Page"),pUnk,
163 // Sets m_bDirty and notifies the property page site of the change
165 void CCamShiftProperties::SetDirty()
169 m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
178 // Virtual method called by base class with Window messages
180 BOOL CCamShiftProperties::OnReceiveMessage( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
187 InitSlider( IDC_WIN_LEFT, 0, 1000, 0 );
188 InitSlider( IDC_WIN_TOP, 0, 1000, 0 );
189 InitSlider( IDC_WIN_WIDTH, 0, 1000, 0 );
190 InitSlider( IDC_WIN_HEIGHT, 0, 1000, 0 );
192 InitSlider( IDC_S_MIN, 0, 255, 5 );
193 InitSlider( IDC_V_MIN, 0, 255, 5 );
195 //InitSlider( IDC_SAMPLES_NUM, 16, 256, 16 );
197 WriteParamsToControls();
207 if(LOWORD(wParam) == IDC_START)
209 m_pCamShift->StartTracking();
211 else if (LOWORD(wParam) == IDC_STOP)
213 m_pCamShift->StopTracking();
217 return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
218 } // OnReceiveMessage
224 // Called when the property page connects to a filter
226 HRESULT CCamShiftProperties::OnConnect(IUnknown *pUnknown)
228 ASSERT(m_pCamShift == NULL);
230 HRESULT hr = pUnknown->QueryInterface(IID_ICamShift, (void **) &m_pCamShift);
232 return E_NOINTERFACE;
236 m_pCamShift->GetParams(&m_params);
246 // Called when we're disconnected from a filter
248 HRESULT CCamShiftProperties::OnDisconnect()
250 // Release of Interface after setting the appropriate contrast value
252 if (m_pCamShift == NULL) {
256 m_pCamShift->Release();
266 // We are being deactivated
268 HRESULT CCamShiftProperties::OnDeactivate(void)
278 // Changes made should be kept. Change the variable
280 HRESULT CCamShiftProperties::OnApplyChanges()
282 ReadParamsFromControls();
283 m_pCamShift->SetParams(&m_params);