Update the changelog
[opencv] / cvaux / src / vs / blobtrackanalysisior.cpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
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.
25 //
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.
28 //
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.
39 //
40 //M*/
41
42 #include "_cvaux.h"
43
44 /*======================= FILTER LIST SHELL =====================*/
45 #define MAX_ANS 16
46 #define MAX_DESC 1024
47 class CvBlobTrackAnalysisIOR : public CvBlobTrackAnalysis
48 {
49 protected:
50     struct  DefAn
51     {
52         char*                   pName;
53         CvBlobTrackAnalysis*    pAn;
54     } m_Ans[MAX_ANS];
55     int m_AnNum;
56     char m_Desc[MAX_DESC];
57
58 public:
59     CvBlobTrackAnalysisIOR()
60     {
61         m_AnNum = 0;
62     }
63
64     ~CvBlobTrackAnalysisIOR()
65     {
66     };
67
68     virtual void    AddBlob(CvBlob* pBlob)
69     {
70         int i;
71         for(i=0; i<m_AnNum; ++i)
72         {
73             m_Ans[i].pAn->AddBlob(pBlob);
74         } /* Next analyzer. */
75     };
76
77     virtual void    Process(IplImage* pImg, IplImage* pFG)
78     {
79         int i;
80 #ifdef _OPENMP
81 #pragma omp parallel for
82 #endif
83         for(i=0; i<m_AnNum; ++i)
84         {
85             m_Ans[i].pAn->Process(pImg, pFG);
86         } /* Next analyzer. */
87     };
88
89     float GetState(int BlobID)
90     {
91         int state = 0;
92         int i;
93         for(i=0; i<m_AnNum; ++i)
94         {
95             state |= (m_Ans[i].pAn->GetState(BlobID) > 0.5);
96         } /* Next analyzer. */
97
98         return (float)state;
99     };
100
101     virtual char*   GetStateDesc(int BlobID)
102     {
103         int     rest = MAX_DESC-1;
104         int     i;
105         m_Desc[0] = 0;
106
107         for(i=0; i<m_AnNum; ++i)
108         {
109             char* str = m_Ans[i].pAn->GetStateDesc(BlobID);
110
111             if(str && strlen(m_Ans[i].pName) + strlen(str)+4 < (size_t)rest)
112             {
113                 strcat(m_Desc,m_Ans[i].pName);
114                 strcat(m_Desc,": ");
115                 strcat(m_Desc,str);
116                 strcat(m_Desc,"\n");
117                 rest = MAX_DESC - (int)strlen(m_Desc) - 1;
118             }
119         } /* Next analyzer. */
120
121         if(m_Desc[0]!=0)return m_Desc;
122
123         return NULL;
124     };
125
126     virtual void SetFileName(char* /*DataBaseName*/)
127     {
128     };
129
130     int AddAnalyzer(CvBlobTrackAnalysis* pA, char* pName)
131     {
132         if(m_AnNum<MAX_ANS)
133         {
134             //int i;
135             m_Ans[m_AnNum].pName = pName;
136             m_Ans[m_AnNum].pAn = pA;
137             TransferParamsFromChild(m_Ans[m_AnNum].pAn, pName);
138             m_AnNum++;
139             return 1;
140         }
141         else
142         {
143             printf("Can not add track analyzer %s! (not more that %d analyzers)\n",pName,MAX_ANS);
144             return 0;
145         }
146     }
147     void    Release()
148     {
149         int i;
150         for(i=0; i<m_AnNum; ++i)
151         {
152             m_Ans[i].pAn->Release();
153         } /* Next analyzer. */
154
155         delete this;
156     };
157 }; /* CvBlobTrackAnalysisIOR. */
158
159 CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR()
160 {
161     CvBlobTrackAnalysisIOR* pIOR = new CvBlobTrackAnalysisIOR();
162     CvBlobTrackAnalysis* pA = NULL;
163
164     pA = cvCreateModuleBlobTrackAnalysisHistPVS();
165     pIOR->AddAnalyzer(pA, "HIST");
166
167     //pA = (CvBlobTrackAnalysis*)cvCreateModuleBlobTrackAnalysisHeightScale();
168     //pIOR->AddAnalyzer(pA, "SCALE");
169
170     return (CvBlobTrackAnalysis*)pIOR;
171 }/* cvCreateCvBlobTrackAnalysisIOR */
172 /* ======================== Analyser modules ============================= */
173