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*/// HMMDemoDoc.cpp : implementation of the CHMMDemoDoc class
45 #include "InfoDialogs.h"
46 #include "HMMDemoDoc.h"
47 #include "ImageBaseView.h"
54 static char THIS_FILE[] = __FILE__;
57 /////////////////////////////////////////////////////////////////////////////
60 IMPLEMENT_DYNCREATE(CHMMDemoDoc, CDocument)
62 BEGIN_MESSAGE_MAP(CHMMDemoDoc, CDocument)
63 //{{AFX_MSG_MAP(CHMMDemoDoc)
67 /////////////////////////////////////////////////////////////////////////////
68 // CHMMDemoDoc construction/destruction
70 CHMMDemoDoc::CHMMDemoDoc()
74 CHMMDemoDoc::~CHMMDemoDoc()
78 BOOL CHMMDemoDoc::OnNewDocument()
80 if (!CDocument::OnNewDocument())
83 m_base.SetBaseView( GetImageBaseView() );
84 m_base.SetFileName("untitled_base.txt");
85 m_base.SetModified(false);
91 /////////////////////////////////////////////////////////////////////////////
92 // CHMMDemoDoc serialization
94 BOOL CHMMDemoDoc::OnOpenDocument(LPCTSTR path)
98 int length = strlen( path );
99 const char* tmp = path + length - 3;
101 if( _stricmp(tmp,"bmp") == 0 || _stricmp(tmp,"jpg") == 0 ||
102 _stricmp(tmp-1,"jpeg") == 0 )
104 CHMMDemoView* camera_view = GetCameraView();
105 CCamera& camera = camera_view->Camera();
107 if ( camera.IsRunning() ) camera.Stop();
109 //load image from disk
110 CImage& image = camera.GetFrame();
111 image.Load( path, 1 );
113 camera_view->Invalidate();
114 camera_view->SetSelection(0);
117 else if( _stricmp(tmp,"txt") == 0 )
120 SetModifiedFlag(); // dirty during de-serialize
122 m_base.SetBaseView( GetImageBaseView() );
126 m_base.SetFileName( path );
127 result = m_base.Load();
132 m_base.SetFileName("");
133 AfxMessageBox("Failed to open database");
137 SetModifiedFlag(FALSE); // start off with unmodified
139 //try to read appropriate config file.
140 //create cfg file name
141 CString cfg_name = path;
142 cfg_name.Replace( ".txt", "CFG.txt" );
144 //reset parameters (HMM, Sampling etc.) for whole application
145 CHMMDemoApp* app = (CHMMDemoApp*)AfxGetApp();
146 app->LoadConfig( cfg_name, true );
153 BOOL CHMMDemoDoc::OnSaveDocument(LPCTSTR path)
158 result = m_base.Save();
162 AfxMessageBox("Failed to save database");
165 SetModifiedFlag(FALSE); // start off with unmodified
170 /////////////////////////////////////////////////////////////////////////////
171 // CHMMDemoDoc commands
173 void CHMMDemoDoc::DeleteContents()
176 CDocument::DeleteContents();
180 CPerson* CHMMDemoDoc::AskPersonName()
183 CPersonName dlg( m_base );
185 if( dlg.DoModal() == IDOK )
187 CString name = dlg.GetPersonName();
188 if( name.GetLength() != 0 )
190 person = m_base.FindPersonByName( name );
193 person = m_base.AddPerson( name, 0, false );
196 AfxMessageBox("Can't create person folder\n");
205 void CHMMDemoDoc::AddObj( CImage& img, CRect roi, CStringList* otherImages )
207 CImageBaseView* view = GetImageBaseView();
211 int new_person_index = 0;
212 int index = view->GetPersonIndex();
215 if( index < 0 ) // no person selected
217 person = AskPersonName();
218 if( !person ) return;
220 new_person_index = m_base.GetPersonIndex( person );
224 person = GetFaceBase().GetPerson(index);
232 person->AddImage( 0, &img, roi );
235 POSITION pos = otherImages->GetHeadPosition();
236 //skip first image, bacause it have already beeb added
237 otherImages->GetNext( pos );
241 CString path = otherImages->GetNext(pos);
242 char drive[1024], dir[1024];
243 _splitpath( path, drive, dir, 0, 0 );
244 strcat( drive, dir );
245 if( _stricmp( drive, person->GetFolder()) == 0 )
247 person->AddImage( path, 0, CRect(0,0,0,0));
253 person->AddImage( 0, &img, CRect(0,0,0,0));
261 view->SwitchMode( new_person_index, true );
265 bool CHMMDemoDoc::RemoveObj( int person_index, int active_index )
267 bool removed = false;
269 if( person_index >= 0 )
271 CPerson* person = m_base.GetPerson( person_index );
274 POSITION pos = person->GetImgList().FindIndex( active_index );
277 int res = AfxMessageBox( "Remove image?", MB_YESNO );
280 person->RemoveImage( pos );
289 POSITION pos = m_base.GetPersonList().FindIndex( active_index );
292 int res = AfxMessageBox( "Remove person from the base?\n"
293 "(files will not be deleted physically)",
297 m_base.RemovePerson( pos );
306 void CHMMDemoDoc::ChangeBaseParams()
308 CBaseInfo dlg( m_base );
310 if( dlg.DoModal() == IDOK )
312 m_base.SetName( dlg.GetBaseName());
313 m_base.SetFileName( dlg.GetFileName());
314 m_base.SetModified();
318 void CHMMDemoDoc::DeleteHMMInfo( int person_index )
320 if( person_index >= 0 )
322 CPerson* person = m_base.GetPerson(person_index);
325 person->DeleteHMMInfo();
330 m_base.DeleteHMMInfo();