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) 2002, 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 // * Redistributions of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistributions 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.
44 #include "cvstreams.h"
46 #include "autorelease.h"
47 #include "ITracker3dFilter.h"
48 #include "IBlobTracker.h"
49 #include "BlobTrackerPropertyPage.h"
55 // Used by the DirectShow base classes to create instances
57 CUnknown *BlobTrackerPropertyPage::CreateInstance(IUnknown *outer, HRESULT *phr)
59 CUnknown *punk = new BlobTrackerPropertyPage(outer, phr);
70 BlobTrackerPropertyPage::BlobTrackerPropertyPage(IUnknown *outer, HRESULT *phr) :
71 CBasePropertyPage(NAME("Blob Tracker Property Page"), outer, IDD_BlobTrackerPropertyPage, IDS_TITLE),
73 m_output_options(IBlobTracker::OUTPUT_CROSSHAIRS),
78 BlobTrackerPropertyPage::~BlobTrackerPropertyPage()
80 for (int i = 0; i < m_trackers.size(); i++)
81 SAFE_RELEASE(m_trackers[i]);
87 // Handles the messages for our property window
89 BOOL BlobTrackerPropertyPage::OnReceiveMessage(HWND hwnd, UINT msg, WPARAM w, LPARAM l)
92 if (msg == WM_COMMAND)
99 case IDC_COLOR_CLASSIFIED_PIXELS:
100 case IDC_BOUNDING_BOX:
112 GetWindowText(GetDlgItem(m_Dlg, LOWORD(w)), text, sizeof(text));
117 case IDC_NUMBER_OF_OBJECTS:
118 if (n != m_num_objects)
122 for (int i = 0; i < m_trackers.size(); i++)
123 m_trackers[i]->SetNumberOfObjects(m_num_objects);
128 for (i = 0; i < m_trackers.size(); i++)
129 m_trackers[i]->SetSizeThreshold(n);
133 for (i = 0; i < m_trackers.size(); i++)
134 m_trackers[i]->SetPixelThreshold(n);
144 return CBasePropertyPage::OnReceiveMessage(hwnd, msg, w, l);
149 void BlobTrackerPropertyPage::SetOutputOptions()
151 m_output_options = IBlobTracker::OUTPUT_CROSSHAIRS;
153 if (IsDlgButtonChecked(m_Dlg, IDC_COLOR_CLASSIFIED_PIXELS))
154 m_output_options |= IBlobTracker::OUTPUT_COLOR_PIXELS;
156 if (IsDlgButtonChecked(m_Dlg, IDC_BOUNDING_BOX))
157 m_output_options |= IBlobTracker::OUTPUT_BOUNDING_BOX;
159 for (int i = 0; i < m_trackers.size(); i++)
160 m_trackers[i]->SetOutputOptions(m_output_options);
166 // Called when we connect to the filter
168 HRESULT BlobTrackerPropertyPage::OnConnect(IUnknown *pUnknown)
170 ITracker3dFilter *tracker_filter;
172 HRESULT hr = pUnknown->QueryInterface(IID_ITracker3dFilter, (void **) &tracker_filter);
176 std::vector<ITracker *> trackers;
177 tracker_filter->GetTrackers(trackers);
178 m_trackers.resize(0);
179 m_trackers.reserve(trackers.size());
180 for (int i = 0; i < trackers.size(); i++)
182 // Ensure that we are the correct property page for each filter
183 // Ignore any that request a different page
184 GUID page = GUID_NULL;
185 trackers[i]->GetPropertyPage(&page);
186 if (page == CLSID_BlobTrackerPropertyPage)
189 trackers[i]->QueryInterface(IID_IBlobTracker, (void **)&p);
190 m_trackers.push_back(p);
192 trackers[i]->Release();
195 tracker_filter->Release();
204 // Called when we disconnect from the filter
206 HRESULT BlobTrackerPropertyPage::OnDisconnect()
208 for (int i = 0; i < m_trackers.size(); i++)
209 SAFE_RELEASE(m_trackers[i]);
218 // We are being activated
220 HRESULT BlobTrackerPropertyPage::OnActivate()
222 SetWindowText(GetDlgItem(m_Dlg, IDC_NUMBER_OF_OBJECTS), "1");
225 if (m_trackers.size() > 0 && m_trackers[0] != NULL)
230 m_trackers[0]->GetPixelThreshold(i);
231 SetDlgItemInt(m_Dlg, IDC_THRESHOLD, i, false);
233 m_trackers[0]->GetSizeThreshold(i);
234 SetDlgItemInt(m_Dlg, IDC_MIN_SIZE, i, false);
245 // We are being deactivated
247 HRESULT BlobTrackerPropertyPage::OnDeactivate(void)
255 // Apply any changes so far made
257 HRESULT BlobTrackerPropertyPage::OnApplyChanges()