Move the sources to trunk
[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 public:
58     CvBlobTrackAnalysisIOR()
59     {
60         m_AnNum = 0;
61     }
62     ~CvBlobTrackAnalysisIOR()
63     {
64     };
65     virtual void    AddBlob(CvBlob* pBlob)
66     {
67         int i;
68         for(i=0;i<m_AnNum;++i)
69         {
70             m_Ans[i].pAn->AddBlob(pBlob);
71         }/* next analizer */
72     };
73     virtual void    Process(IplImage* pImg, IplImage* pFG)
74     {
75         int i;
76 #ifdef _OPENMP
77 #pragma omp parallel for
78 #endif
79         for(i=0;i<m_AnNum;++i)
80         {
81             m_Ans[i].pAn->Process(pImg, pFG);
82         }/* next analizer */
83     };
84     float GetState(int BlobID)
85     {
86         int state = 0;
87         int i;
88         for(i=0;i<m_AnNum;++i)
89         {
90             state |= (m_Ans[i].pAn->GetState(BlobID) > 0.5);
91         }/* next analizer */
92         return (float)state;
93     };
94
95     virtual char*   GetStateDesc(int BlobID)
96     {
97         int     rest = MAX_DESC-1;
98         int     i;
99         m_Desc[0] = 0;
100         for(i=0;i<m_AnNum;++i)
101         {
102             char* str = m_Ans[i].pAn->GetStateDesc(BlobID);
103             if(str && strlen(m_Ans[i].pName) + strlen(str)+4 < (size_t)rest)
104             {
105                 strcat(m_Desc,m_Ans[i].pName);
106                 strcat(m_Desc,": ");
107                 strcat(m_Desc,str);
108                 strcat(m_Desc,"\n");
109                 rest = MAX_DESC - (int)strlen(m_Desc) - 1;
110             }
111         }/* next analizer */
112         if(m_Desc[0]!=0)return m_Desc;
113         return NULL;
114     };
115     virtual void SetFileName(char* /*DataBaseName*/)
116     {
117     };
118
119     int AddAnalizer(CvBlobTrackAnalysis* pA, char* pName)
120     {
121         if(m_AnNum<MAX_ANS)
122         {
123             //int i;
124             m_Ans[m_AnNum].pName = pName;
125             m_Ans[m_AnNum].pAn = pA;
126             TransferParamsFromChild(m_Ans[m_AnNum].pAn, pName);
127             m_AnNum++;
128             return 1;
129         }
130         else
131         {
132             printf("Can not add track analizer %s! (not more that %d analizers)\n",pName,MAX_ANS);
133             return 0;
134         }
135     }
136     void    Release()
137     {
138         int i;
139         for(i=0;i<m_AnNum;++i)
140         {
141             m_Ans[i].pAn->Release();
142         }/* next analizer */
143         delete this;
144     };
145 }; /* CvBlobTrackAnalysisIOR */
146
147 CvBlobTrackAnalysis* cvCreateModuleBlobTrackAnalysisIOR()
148 {
149     CvBlobTrackAnalysisIOR* pIOR = new CvBlobTrackAnalysisIOR();
150     CvBlobTrackAnalysis* pA = NULL;
151
152     pA = cvCreateModuleBlobTrackAnalysisHistPVS();
153     pIOR->AddAnalizer(pA, "HIST");
154
155     //pA = (CvBlobTrackAnalysis*)cvCreateModuleBlobTrackAnalysisHeightScale();
156     //pIOR->AddAnalizer(pA, "SCALE");
157
158     return (CvBlobTrackAnalysis*)pIOR;
159 }/* cvCreateCvBlobTrackAnalysisIOR */
160 /* ======================== Analyser modules ============================= */
161